aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/tty
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/Kconfig52
-rw-r--r--drivers/tty/Makefile1
-rw-r--r--drivers/tty/amiserial.c778
-rw-r--r--drivers/tty/bfin_jtag_comm.c48
-rw-r--r--drivers/tty/cyclades.c151
-rw-r--r--drivers/tty/ehv_bytechan.c883
-rw-r--r--drivers/tty/hvc/Kconfig25
-rw-r--r--drivers/tty/hvc/Makefile2
-rw-r--r--drivers/tty/hvc/hvc_beat.c2
-rw-r--r--drivers/tty/hvc/hvc_console.c168
-rw-r--r--drivers/tty/hvc/hvc_console.h4
-rw-r--r--drivers/tty/hvc/hvc_irq.c2
-rw-r--r--drivers/tty/hvc/hvc_opal.c425
-rw-r--r--drivers/tty/hvc/hvc_rtas.c2
-rw-r--r--drivers/tty/hvc/hvc_udbg.c10
-rw-r--r--drivers/tty/hvc/hvc_vio.c143
-rw-r--r--drivers/tty/hvc/hvc_xen.c470
-rw-r--r--drivers/tty/hvc/hvcs.c209
-rw-r--r--drivers/tty/hvc/hvsi.c143
-rw-r--r--drivers/tty/hvc/hvsi_lib.c8
-rw-r--r--drivers/tty/ipwireless/hardware.c2
-rw-r--r--drivers/tty/ipwireless/network.c18
-rw-r--r--drivers/tty/ipwireless/setup_protocol.h2
-rw-r--r--drivers/tty/ipwireless/tty.c119
-rw-r--r--drivers/tty/isicom.c52
-rw-r--r--drivers/tty/moxa.c55
-rw-r--r--drivers/tty/mxser.c119
-rw-r--r--drivers/tty/n_gsm.c238
-rw-r--r--drivers/tty/n_hdlc.c7
-rw-r--r--drivers/tty/n_r3964.c10
-rw-r--r--drivers/tty/n_tty.c775
-rw-r--r--drivers/tty/nozomi.c36
-rw-r--r--drivers/tty/pty.c388
-rw-r--r--drivers/tty/rocket.c35
-rw-r--r--drivers/tty/serial/21285.c5
-rw-r--r--drivers/tty/serial/68328serial.c453
-rw-r--r--drivers/tty/serial/8250/8250.c3421
-rw-r--r--drivers/tty/serial/8250/8250.h144
-rw-r--r--drivers/tty/serial/8250/8250_accent.c45
-rw-r--r--drivers/tty/serial/8250/8250_acorn.c141
-rw-r--r--drivers/tty/serial/8250/8250_boca.c59
-rw-r--r--drivers/tty/serial/8250/8250_dw.c209
-rw-r--r--drivers/tty/serial/8250/8250_early.c287
-rw-r--r--drivers/tty/serial/8250/8250_em.c186
-rw-r--r--drivers/tty/serial/8250/8250_exar_st16c554.c50
-rw-r--r--drivers/tty/serial/8250/8250_fourport.c51
-rw-r--r--drivers/tty/serial/8250/8250_fsl.c63
-rw-r--r--drivers/tty/serial/8250/8250_gsc.c122
-rw-r--r--drivers/tty/serial/8250/8250_hp300.c327
-rw-r--r--drivers/tty/serial/8250/8250_hub6.c56
-rw-r--r--drivers/tty/serial/8250/8250_pci.c4604
-rw-r--r--drivers/tty/serial/8250/8250_pnp.c529
-rw-r--r--drivers/tty/serial/8250/Kconfig279
-rw-r--r--drivers/tty/serial/8250/Makefile21
-rw-r--r--drivers/tty/serial/8250/serial_cs.c869
-rw-r--r--drivers/tty/serial/Kconfig543
-rw-r--r--drivers/tty/serial/Makefile39
-rw-r--r--drivers/tty/serial/altera_jtaguart.c13
-rw-r--r--drivers/tty/serial/altera_uart.c69
-rw-r--r--drivers/tty/serial/amba-pl010.c13
-rw-r--r--drivers/tty/serial/amba-pl011.c417
-rw-r--r--drivers/tty/serial/apbuart.c7
-rw-r--r--drivers/tty/serial/ar933x_uart.c768
-rw-r--r--drivers/tty/serial/arc_uart.c746
-rw-r--r--drivers/tty/serial/atmel_serial.c174
-rw-r--r--drivers/tty/serial/bcm63xx_uart.c6
-rw-r--r--drivers/tty/serial/bfin_sport_uart.c30
-rw-r--r--drivers/tty/serial/bfin_sport_uart.h5
-rw-r--r--drivers/tty/serial/bfin_uart.c1592
-rw-r--r--drivers/tty/serial/clps711x.c590
-rw-r--r--drivers/tty/serial/cpm_uart/cpm_uart_core.c28
-rw-r--r--drivers/tty/serial/crisv10.c130
-rw-r--r--drivers/tty/serial/dz.c2
-rw-r--r--drivers/tty/serial/efm32-uart.c830
-rw-r--r--drivers/tty/serial/icom.c19
-rw-r--r--drivers/tty/serial/ifx6x60.c178
-rw-r--r--drivers/tty/serial/ifx6x60.h2
-rw-r--r--drivers/tty/serial/imx.c261
-rw-r--r--drivers/tty/serial/ioc3_serial.c6
-rw-r--r--drivers/tty/serial/ioc4_serial.c9
-rw-r--r--drivers/tty/serial/jsm/jsm.h11
-rw-r--r--drivers/tty/serial/jsm/jsm_driver.c31
-rw-r--r--drivers/tty/serial/jsm/jsm_neo.c116
-rw-r--r--drivers/tty/serial/jsm/jsm_tty.c112
-rw-r--r--drivers/tty/serial/kgdb_nmi.c404
-rw-r--r--drivers/tty/serial/kgdboc.c15
-rw-r--r--drivers/tty/serial/lantiq.c89
-rw-r--r--drivers/tty/serial/lpc32xx_hs.c823
-rw-r--r--drivers/tty/serial/m32r_sio.c56
-rw-r--r--drivers/tty/serial/m32r_sio.h1
-rw-r--r--drivers/tty/serial/max3100.c36
-rw-r--r--drivers/tty/serial/max310x.c1262
-rw-r--r--drivers/tty/serial/mcf.c8
-rw-r--r--drivers/tty/serial/mfd.c85
-rw-r--r--drivers/tty/serial/mpc52xx_uart.c24
-rw-r--r--drivers/tty/serial/mrst_max3110.c124
-rw-r--r--drivers/tty/serial/mrst_max3110.h1
-rw-r--r--drivers/tty/serial/msm_serial.c36
-rw-r--r--drivers/tty/serial/msm_serial_hs.c34
-rw-r--r--drivers/tty/serial/msm_smd_tty.c9
-rw-r--r--drivers/tty/serial/mux.c11
-rw-r--r--drivers/tty/serial/mxs-auart.c449
-rw-r--r--drivers/tty/serial/nwpserial.c2
-rw-r--r--drivers/tty/serial/of_serial.c90
-rw-r--r--drivers/tty/serial/omap-serial.c1362
-rw-r--r--drivers/tty/serial/pch_uart.c452
-rw-r--r--drivers/tty/serial/pmac_zilog.c437
-rw-r--r--drivers/tty/serial/pmac_zilog.h19
-rw-r--r--drivers/tty/serial/pxa.c126
-rw-r--r--drivers/tty/serial/sa1100.c5
-rw-r--r--drivers/tty/serial/samsung.c868
-rw-r--r--drivers/tty/serial/samsung.h33
-rw-r--r--drivers/tty/serial/sb1250-duart.c2
-rw-r--r--drivers/tty/serial/sc26xx.c24
-rw-r--r--drivers/tty/serial/sccnxp.c991
-rw-r--r--drivers/tty/serial/serial_core.c857
-rw-r--r--drivers/tty/serial/serial_ks8695.c13
-rw-r--r--drivers/tty/serial/serial_txx9.c20
-rw-r--r--drivers/tty/serial/sh-sci.c591
-rw-r--r--drivers/tty/serial/sh-sci.h12
-rw-r--r--drivers/tty/serial/sirfsoc_uart.c773
-rw-r--r--drivers/tty/serial/sirfsoc_uart.h185
-rw-r--r--drivers/tty/serial/sn_console.c8
-rw-r--r--drivers/tty/serial/suncore.c2
-rw-r--r--drivers/tty/serial/sunhv.c10
-rw-r--r--drivers/tty/serial/sunsab.c11
-rw-r--r--drivers/tty/serial/sunsu.c22
-rw-r--r--drivers/tty/serial/sunzilog.c27
-rw-r--r--drivers/tty/serial/timbuart.c24
-rw-r--r--drivers/tty/serial/uartlite.c22
-rw-r--r--drivers/tty/serial/ucc_uart.c9
-rw-r--r--drivers/tty/serial/vr41xx_siu.c25
-rw-r--r--drivers/tty/serial/vt8500_serial.c62
-rw-r--r--drivers/tty/serial/xilinx_uartps.c20
-rw-r--r--drivers/tty/serial/zs.c3
-rw-r--r--drivers/tty/synclink.c98
-rw-r--r--drivers/tty/synclink_gt.c54
-rw-r--r--drivers/tty/synclinkmp.c81
-rw-r--r--drivers/tty/sysrq.c23
-rw-r--r--drivers/tty/tty_audit.c32
-rw-r--r--drivers/tty/tty_buffer.c265
-rw-r--r--drivers/tty/tty_io.c793
-rw-r--r--drivers/tty/tty_ioctl.c139
-rw-r--r--drivers/tty/tty_ldisc.c161
-rw-r--r--drivers/tty/tty_mutex.c79
-rw-r--r--drivers/tty/tty_port.c114
-rw-r--r--drivers/tty/vt/consolemap.c178
-rw-r--r--drivers/tty/vt/keyboard.c848
-rw-r--r--drivers/tty/vt/selection.c65
-rw-r--r--drivers/tty/vt/vc_screen.c5
-rw-r--r--drivers/tty/vt/vt.c299
-rw-r--r--drivers/tty/vt/vt_ioctl.c523
152 files changed, 7077 insertions, 31304 deletions
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 0ecf22b6a38..bd7cc052799 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -1,6 +1,6 @@
1config VT 1config VT
2 bool "Virtual terminal" if EXPERT 2 bool "Virtual terminal" if EXPERT
3 depends on !S390 && !UML 3 depends on !S390
4 select INPUT 4 select INPUT
5 default y 5 default y
6 ---help--- 6 ---help---
@@ -60,13 +60,9 @@ config VT_CONSOLE
60 60
61 If unsure, say Y. 61 If unsure, say Y.
62 62
63config VT_CONSOLE_SLEEP
64 def_bool y
65 depends on VT_CONSOLE && PM_SLEEP
66
67config HW_CONSOLE 63config HW_CONSOLE
68 bool 64 bool
69 depends on VT && !UML 65 depends on VT && !S390 && !UML
70 default y 66 default y
71 67
72config VT_HW_CONSOLE_BINDING 68config VT_HW_CONSOLE_BINDING
@@ -214,8 +210,8 @@ config CYCLADES
214 If you haven't heard about it, it's safe to say N. 210 If you haven't heard about it, it's safe to say N.
215 211
216config CYZ_INTR 212config CYZ_INTR
217 bool "Cyclades-Z interrupt mode operation" 213 bool "Cyclades-Z interrupt mode operation (EXPERIMENTAL)"
218 depends on CYCLADES 214 depends on EXPERIMENTAL && CYCLADES
219 help 215 help
220 The Cyclades-Z family of multiport cards allows 2 (two) driver op 216 The Cyclades-Z family of multiport cards allows 2 (two) driver op
221 modes: polling and interrupt. In polling mode, the driver will check 217 modes: polling and interrupt. In polling mode, the driver will check
@@ -285,7 +281,7 @@ config SYNCLINK_GT
285 281
286config NOZOMI 282config NOZOMI
287 tristate "HSDPA Broadband Wireless Data Card - Globe Trotter" 283 tristate "HSDPA Broadband Wireless Data Card - Globe Trotter"
288 depends on PCI 284 depends on PCI && EXPERIMENTAL
289 help 285 help
290 If you have a HSDPA driver Broadband Wireless Data Card - 286 If you have a HSDPA driver Broadband Wireless Data Card -
291 Globe Trotter PCMCIA card, say Y here. 287 Globe Trotter PCMCIA card, say Y here.
@@ -294,7 +290,7 @@ config NOZOMI
294 will be called nozomi. 290 will be called nozomi.
295 291
296config ISI 292config ISI
297 tristate "Multi-Tech multiport card support" 293 tristate "Multi-Tech multiport card support (EXPERIMENTAL)"
298 depends on SERIAL_NONSTANDARD && PCI 294 depends on SERIAL_NONSTANDARD && PCI
299 select FW_LOADER 295 select FW_LOADER
300 help 296 help
@@ -317,6 +313,7 @@ config N_HDLC
317 313
318config N_GSM 314config N_GSM
319 tristate "GSM MUX line discipline support (EXPERIMENTAL)" 315 tristate "GSM MUX line discipline support (EXPERIMENTAL)"
316 depends on EXPERIMENTAL
320 depends on NET 317 depends on NET
321 help 318 help
322 This line discipline provides support for the GSM MUX protocol and 319 This line discipline provides support for the GSM MUX protocol and
@@ -353,38 +350,3 @@ config TRACE_SINK
353 350
354 If you select this option, you need to select 351 If you select this option, you need to select
355 "Trace data router for MIPI P1149.7 cJTAG standard". 352 "Trace data router for MIPI P1149.7 cJTAG standard".
356
357config PPC_EPAPR_HV_BYTECHAN
358 tristate "ePAPR hypervisor byte channel driver"
359 depends on PPC
360 select EPAPR_PARAVIRT
361 help
362 This driver creates /dev entries for each ePAPR hypervisor byte
363 channel, thereby allowing applications to communicate with byte
364 channels as if they were serial ports.
365
366config PPC_EARLY_DEBUG_EHV_BC
367 bool "Early console (udbg) support for ePAPR hypervisors"
368 depends on PPC_EPAPR_HV_BYTECHAN=y
369 help
370 Select this option to enable early console (a.k.a. "udbg") support
371 via an ePAPR byte channel. You also need to choose the byte channel
372 handle below.
373
374config PPC_EARLY_DEBUG_EHV_BC_HANDLE
375 int "Byte channel handle for early console (udbg)"
376 depends on PPC_EARLY_DEBUG_EHV_BC
377 default 0
378 help
379 If you want early console (udbg) output through a byte channel,
380 specify the handle of the byte channel to use.
381
382 For this to work, the byte channel driver must be compiled
383 in-kernel, not as a module.
384
385 Note that only one early console driver can be enabled, so don't
386 enable any others if you enable this one.
387
388 If the number you specify is not a valid byte channel handle, then
389 there simply will be no early console output. This is true also
390 if you don't boot under a hypervisor at all.
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 2953059530e..ea89b0bd15f 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -26,6 +26,5 @@ obj-$(CONFIG_ROCKETPORT) += rocket.o
26obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o 26obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o
27obj-$(CONFIG_SYNCLINKMP) += synclinkmp.o 27obj-$(CONFIG_SYNCLINKMP) += synclinkmp.o
28obj-$(CONFIG_SYNCLINK) += synclink.o 28obj-$(CONFIG_SYNCLINK) += synclink.o
29obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o
30 29
31obj-y += ipwireless/ 30obj-y += ipwireless/
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 9d7d00cdfec..220579592c2 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -45,7 +45,7 @@
45 45
46#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT) 46#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
47#define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \ 47#define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
48 tty->name, (info->tport.flags), serial_driver->refcount,info->count,tty->count,s) 48 tty->name, (info->flags), serial_driver->refcount,info->count,tty->count,s)
49#else 49#else
50#define DBG_CNT(s) 50#define DBG_CNT(s)
51#endif 51#endif
@@ -58,6 +58,7 @@
58 58
59#include <linux/types.h> 59#include <linux/types.h>
60#include <linux/serial.h> 60#include <linux/serial.h>
61#include <linux/serialP.h>
61#include <linux/serial_reg.h> 62#include <linux/serial_reg.h>
62static char *serial_version = "4.30"; 63static char *serial_version = "4.30";
63 64
@@ -69,7 +70,6 @@ static char *serial_version = "4.30";
69#include <linux/interrupt.h> 70#include <linux/interrupt.h>
70#include <linux/tty.h> 71#include <linux/tty.h>
71#include <linux/tty_flip.h> 72#include <linux/tty_flip.h>
72#include <linux/circ_buf.h>
73#include <linux/console.h> 73#include <linux/console.h>
74#include <linux/major.h> 74#include <linux/major.h>
75#include <linux/string.h> 75#include <linux/string.h>
@@ -85,30 +85,13 @@ static char *serial_version = "4.30";
85 85
86#include <asm/setup.h> 86#include <asm/setup.h>
87 87
88#include <asm/system.h>
88 89
89#include <asm/irq.h> 90#include <asm/irq.h>
90 91
91#include <asm/amigahw.h> 92#include <asm/amigahw.h>
92#include <asm/amigaints.h> 93#include <asm/amigaints.h>
93 94
94struct serial_state {
95 struct tty_port tport;
96 struct circ_buf xmit;
97 struct async_icount icount;
98
99 unsigned long port;
100 int baud_base;
101 int xmit_fifo_size;
102 int custom_divisor;
103 int read_status_mask;
104 int ignore_status_mask;
105 int timeout;
106 int quot;
107 int IER; /* Interrupt Enable Register */
108 int MCR; /* Modem control register */
109 int x_char; /* xon/xoff character */
110};
111
112#define custom amiga_custom 95#define custom amiga_custom
113static char *serial_name = "Amiga-builtin serial driver"; 96static char *serial_name = "Amiga-builtin serial driver";
114 97
@@ -117,10 +100,11 @@ static struct tty_driver *serial_driver;
117/* number of characters left in xmit buffer before we ask for more */ 100/* number of characters left in xmit buffer before we ask for more */
118#define WAKEUP_CHARS 256 101#define WAKEUP_CHARS 256
119 102
103static struct async_struct *IRQ_ports;
104
120static unsigned char current_ctl_bits; 105static unsigned char current_ctl_bits;
121 106
122static void change_speed(struct tty_struct *tty, struct serial_state *info, 107static void change_speed(struct async_struct *info, struct ktermios *old);
123 struct ktermios *old);
124static void rs_wait_until_sent(struct tty_struct *tty, int timeout); 108static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
125 109
126 110
@@ -133,7 +117,7 @@ static struct serial_state rs_table[1];
133#define serial_isroot() (capable(CAP_SYS_ADMIN)) 117#define serial_isroot() (capable(CAP_SYS_ADMIN))
134 118
135 119
136static inline int serial_paranoia_check(struct serial_state *info, 120static inline int serial_paranoia_check(struct async_struct *info,
137 char *name, const char *routine) 121 char *name, const char *routine)
138{ 122{
139#ifdef SERIAL_PARANOIA_CHECK 123#ifdef SERIAL_PARANOIA_CHECK
@@ -186,7 +170,7 @@ static __inline__ void rtsdtr_ctrl(int bits)
186 */ 170 */
187static void rs_stop(struct tty_struct *tty) 171static void rs_stop(struct tty_struct *tty)
188{ 172{
189 struct serial_state *info = tty->driver_data; 173 struct async_struct *info = tty->driver_data;
190 unsigned long flags; 174 unsigned long flags;
191 175
192 if (serial_paranoia_check(info, tty->name, "rs_stop")) 176 if (serial_paranoia_check(info, tty->name, "rs_stop"))
@@ -206,7 +190,7 @@ static void rs_stop(struct tty_struct *tty)
206 190
207static void rs_start(struct tty_struct *tty) 191static void rs_start(struct tty_struct *tty)
208{ 192{
209 struct serial_state *info = tty->driver_data; 193 struct async_struct *info = tty->driver_data;
210 unsigned long flags; 194 unsigned long flags;
211 195
212 if (serial_paranoia_check(info, tty->name, "rs_start")) 196 if (serial_paranoia_check(info, tty->name, "rs_start"))
@@ -247,16 +231,27 @@ static void rs_start(struct tty_struct *tty)
247 * ----------------------------------------------------------------------- 231 * -----------------------------------------------------------------------
248 */ 232 */
249 233
250static void receive_chars(struct serial_state *info) 234/*
235 * This routine is used by the interrupt handler to schedule
236 * processing in the software interrupt portion of the driver.
237 */
238static void rs_sched_event(struct async_struct *info,
239 int event)
240{
241 info->event |= 1 << event;
242 tasklet_schedule(&info->tlet);
243}
244
245static void receive_chars(struct async_struct *info)
251{ 246{
252 int status; 247 int status;
253 int serdatr; 248 int serdatr;
254 struct tty_struct *tty = info->tport.tty; 249 struct tty_struct *tty = info->tty;
255 unsigned char ch, flag; 250 unsigned char ch, flag;
256 struct async_icount *icount; 251 struct async_icount *icount;
257 int oe = 0; 252 int oe = 0;
258 253
259 icount = &info->icount; 254 icount = &info->state->icount;
260 255
261 status = UART_LSR_DR; /* We obviously have a character! */ 256 status = UART_LSR_DR; /* We obviously have a character! */
262 serdatr = custom.serdatr; 257 serdatr = custom.serdatr;
@@ -313,7 +308,7 @@ static void receive_chars(struct serial_state *info)
313 printk("handling break...."); 308 printk("handling break....");
314#endif 309#endif
315 flag = TTY_BREAK; 310 flag = TTY_BREAK;
316 if (info->tport.flags & ASYNC_SAK) 311 if (info->flags & ASYNC_SAK)
317 do_SAK(tty); 312 do_SAK(tty);
318 } else if (status & UART_LSR_PE) 313 } else if (status & UART_LSR_PE)
319 flag = TTY_PARITY; 314 flag = TTY_PARITY;
@@ -336,20 +331,20 @@ out:
336 return; 331 return;
337} 332}
338 333
339static void transmit_chars(struct serial_state *info) 334static void transmit_chars(struct async_struct *info)
340{ 335{
341 custom.intreq = IF_TBE; 336 custom.intreq = IF_TBE;
342 mb(); 337 mb();
343 if (info->x_char) { 338 if (info->x_char) {
344 custom.serdat = info->x_char | 0x100; 339 custom.serdat = info->x_char | 0x100;
345 mb(); 340 mb();
346 info->icount.tx++; 341 info->state->icount.tx++;
347 info->x_char = 0; 342 info->x_char = 0;
348 return; 343 return;
349 } 344 }
350 if (info->xmit.head == info->xmit.tail 345 if (info->xmit.head == info->xmit.tail
351 || info->tport.tty->stopped 346 || info->tty->stopped
352 || info->tport.tty->hw_stopped) { 347 || info->tty->hw_stopped) {
353 info->IER &= ~UART_IER_THRI; 348 info->IER &= ~UART_IER_THRI;
354 custom.intena = IF_TBE; 349 custom.intena = IF_TBE;
355 mb(); 350 mb();
@@ -359,12 +354,12 @@ static void transmit_chars(struct serial_state *info)
359 custom.serdat = info->xmit.buf[info->xmit.tail++] | 0x100; 354 custom.serdat = info->xmit.buf[info->xmit.tail++] | 0x100;
360 mb(); 355 mb();
361 info->xmit.tail = info->xmit.tail & (SERIAL_XMIT_SIZE-1); 356 info->xmit.tail = info->xmit.tail & (SERIAL_XMIT_SIZE-1);
362 info->icount.tx++; 357 info->state->icount.tx++;
363 358
364 if (CIRC_CNT(info->xmit.head, 359 if (CIRC_CNT(info->xmit.head,
365 info->xmit.tail, 360 info->xmit.tail,
366 SERIAL_XMIT_SIZE) < WAKEUP_CHARS) 361 SERIAL_XMIT_SIZE) < WAKEUP_CHARS)
367 tty_wakeup(info->tport.tty); 362 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
368 363
369#ifdef SERIAL_DEBUG_INTR 364#ifdef SERIAL_DEBUG_INTR
370 printk("THRE..."); 365 printk("THRE...");
@@ -376,9 +371,8 @@ static void transmit_chars(struct serial_state *info)
376 } 371 }
377} 372}
378 373
379static void check_modem_status(struct serial_state *info) 374static void check_modem_status(struct async_struct *info)
380{ 375{
381 struct tty_port *port = &info->tport;
382 unsigned char status = ciab.pra & (SER_DCD | SER_CTS | SER_DSR); 376 unsigned char status = ciab.pra & (SER_DCD | SER_CTS | SER_DSR);
383 unsigned char dstatus; 377 unsigned char dstatus;
384 struct async_icount *icount; 378 struct async_icount *icount;
@@ -388,52 +382,52 @@ static void check_modem_status(struct serial_state *info)
388 current_ctl_bits = status; 382 current_ctl_bits = status;
389 383
390 if (dstatus) { 384 if (dstatus) {
391 icount = &info->icount; 385 icount = &info->state->icount;
392 /* update input line counters */ 386 /* update input line counters */
393 if (dstatus & SER_DSR) 387 if (dstatus & SER_DSR)
394 icount->dsr++; 388 icount->dsr++;
395 if (dstatus & SER_DCD) { 389 if (dstatus & SER_DCD) {
396 icount->dcd++; 390 icount->dcd++;
397#ifdef CONFIG_HARD_PPS 391#ifdef CONFIG_HARD_PPS
398 if ((port->flags & ASYNC_HARDPPS_CD) && 392 if ((info->flags & ASYNC_HARDPPS_CD) &&
399 !(status & SER_DCD)) 393 !(status & SER_DCD))
400 hardpps(); 394 hardpps();
401#endif 395#endif
402 } 396 }
403 if (dstatus & SER_CTS) 397 if (dstatus & SER_CTS)
404 icount->cts++; 398 icount->cts++;
405 wake_up_interruptible(&port->delta_msr_wait); 399 wake_up_interruptible(&info->delta_msr_wait);
406 } 400 }
407 401
408 if ((port->flags & ASYNC_CHECK_CD) && (dstatus & SER_DCD)) { 402 if ((info->flags & ASYNC_CHECK_CD) && (dstatus & SER_DCD)) {
409#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR)) 403#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
410 printk("ttyS%d CD now %s...", info->line, 404 printk("ttyS%d CD now %s...", info->line,
411 (!(status & SER_DCD)) ? "on" : "off"); 405 (!(status & SER_DCD)) ? "on" : "off");
412#endif 406#endif
413 if (!(status & SER_DCD)) 407 if (!(status & SER_DCD))
414 wake_up_interruptible(&port->open_wait); 408 wake_up_interruptible(&info->open_wait);
415 else { 409 else {
416#ifdef SERIAL_DEBUG_OPEN 410#ifdef SERIAL_DEBUG_OPEN
417 printk("doing serial hangup..."); 411 printk("doing serial hangup...");
418#endif 412#endif
419 if (port->tty) 413 if (info->tty)
420 tty_hangup(port->tty); 414 tty_hangup(info->tty);
421 } 415 }
422 } 416 }
423 if (tty_port_cts_enabled(port)) { 417 if (info->flags & ASYNC_CTS_FLOW) {
424 if (port->tty->hw_stopped) { 418 if (info->tty->hw_stopped) {
425 if (!(status & SER_CTS)) { 419 if (!(status & SER_CTS)) {
426#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW)) 420#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
427 printk("CTS tx start..."); 421 printk("CTS tx start...");
428#endif 422#endif
429 port->tty->hw_stopped = 0; 423 info->tty->hw_stopped = 0;
430 info->IER |= UART_IER_THRI; 424 info->IER |= UART_IER_THRI;
431 custom.intena = IF_SETCLR | IF_TBE; 425 custom.intena = IF_SETCLR | IF_TBE;
432 mb(); 426 mb();
433 /* set a pending Tx Interrupt, transmitter should restart now */ 427 /* set a pending Tx Interrupt, transmitter should restart now */
434 custom.intreq = IF_SETCLR | IF_TBE; 428 custom.intreq = IF_SETCLR | IF_TBE;
435 mb(); 429 mb();
436 tty_wakeup(port->tty); 430 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
437 return; 431 return;
438 } 432 }
439 } else { 433 } else {
@@ -441,7 +435,7 @@ static void check_modem_status(struct serial_state *info)
441#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW)) 435#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
442 printk("CTS tx stop..."); 436 printk("CTS tx stop...");
443#endif 437#endif
444 port->tty->hw_stopped = 1; 438 info->tty->hw_stopped = 1;
445 info->IER &= ~UART_IER_THRI; 439 info->IER &= ~UART_IER_THRI;
446 /* disable Tx interrupt and remove any pending interrupts */ 440 /* disable Tx interrupt and remove any pending interrupts */
447 custom.intena = IF_TBE; 441 custom.intena = IF_TBE;
@@ -456,7 +450,7 @@ static void check_modem_status(struct serial_state *info)
456static irqreturn_t ser_vbl_int( int irq, void *data) 450static irqreturn_t ser_vbl_int( int irq, void *data)
457{ 451{
458 /* vbl is just a periodic interrupt we tie into to update modem status */ 452 /* vbl is just a periodic interrupt we tie into to update modem status */
459 struct serial_state *info = data; 453 struct async_struct * info = IRQ_ports;
460 /* 454 /*
461 * TBD - is it better to unregister from this interrupt or to 455 * TBD - is it better to unregister from this interrupt or to
462 * ignore it if MSI is clear ? 456 * ignore it if MSI is clear ?
@@ -468,16 +462,18 @@ static irqreturn_t ser_vbl_int( int irq, void *data)
468 462
469static irqreturn_t ser_rx_int(int irq, void *dev_id) 463static irqreturn_t ser_rx_int(int irq, void *dev_id)
470{ 464{
471 struct serial_state *info = dev_id; 465 struct async_struct * info;
472 466
473#ifdef SERIAL_DEBUG_INTR 467#ifdef SERIAL_DEBUG_INTR
474 printk("ser_rx_int..."); 468 printk("ser_rx_int...");
475#endif 469#endif
476 470
477 if (!info->tport.tty) 471 info = IRQ_ports;
472 if (!info || !info->tty)
478 return IRQ_NONE; 473 return IRQ_NONE;
479 474
480 receive_chars(info); 475 receive_chars(info);
476 info->last_active = jiffies;
481#ifdef SERIAL_DEBUG_INTR 477#ifdef SERIAL_DEBUG_INTR
482 printk("end.\n"); 478 printk("end.\n");
483#endif 479#endif
@@ -486,17 +482,19 @@ static irqreturn_t ser_rx_int(int irq, void *dev_id)
486 482
487static irqreturn_t ser_tx_int(int irq, void *dev_id) 483static irqreturn_t ser_tx_int(int irq, void *dev_id)
488{ 484{
489 struct serial_state *info = dev_id; 485 struct async_struct * info;
490 486
491 if (custom.serdatr & SDR_TBE) { 487 if (custom.serdatr & SDR_TBE) {
492#ifdef SERIAL_DEBUG_INTR 488#ifdef SERIAL_DEBUG_INTR
493 printk("ser_tx_int..."); 489 printk("ser_tx_int...");
494#endif 490#endif
495 491
496 if (!info->tport.tty) 492 info = IRQ_ports;
493 if (!info || !info->tty)
497 return IRQ_NONE; 494 return IRQ_NONE;
498 495
499 transmit_chars(info); 496 transmit_chars(info);
497 info->last_active = jiffies;
500#ifdef SERIAL_DEBUG_INTR 498#ifdef SERIAL_DEBUG_INTR
501 printk("end.\n"); 499 printk("end.\n");
502#endif 500#endif
@@ -511,6 +509,29 @@ static irqreturn_t ser_tx_int(int irq, void *dev_id)
511 */ 509 */
512 510
513/* 511/*
512 * This routine is used to handle the "bottom half" processing for the
513 * serial driver, known also the "software interrupt" processing.
514 * This processing is done at the kernel interrupt level, after the
515 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
516 * is where time-consuming activities which can not be done in the
517 * interrupt driver proper are done; the interrupt driver schedules
518 * them using rs_sched_event(), and they get done here.
519 */
520
521static void do_softint(unsigned long private_)
522{
523 struct async_struct *info = (struct async_struct *) private_;
524 struct tty_struct *tty;
525
526 tty = info->tty;
527 if (!tty)
528 return;
529
530 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
531 tty_wakeup(tty);
532}
533
534/*
514 * --------------------------------------------------------------- 535 * ---------------------------------------------------------------
515 * Low level utility subroutines for the serial driver: routines to 536 * Low level utility subroutines for the serial driver: routines to
516 * figure out the appropriate timeout for an interrupt chain, routines 537 * figure out the appropriate timeout for an interrupt chain, routines
@@ -519,9 +540,8 @@ static irqreturn_t ser_tx_int(int irq, void *dev_id)
519 * --------------------------------------------------------------- 540 * ---------------------------------------------------------------
520 */ 541 */
521 542
522static int startup(struct tty_struct *tty, struct serial_state *info) 543static int startup(struct async_struct * info)
523{ 544{
524 struct tty_port *port = &info->tport;
525 unsigned long flags; 545 unsigned long flags;
526 int retval=0; 546 int retval=0;
527 unsigned long page; 547 unsigned long page;
@@ -532,7 +552,7 @@ static int startup(struct tty_struct *tty, struct serial_state *info)
532 552
533 local_irq_save(flags); 553 local_irq_save(flags);
534 554
535 if (port->flags & ASYNC_INITIALIZED) { 555 if (info->flags & ASYNC_INITIALIZED) {
536 free_page(page); 556 free_page(page);
537 goto errout; 557 goto errout;
538 } 558 }
@@ -554,7 +574,9 @@ static int startup(struct tty_struct *tty, struct serial_state *info)
554 retval = request_irq(IRQ_AMIGA_VERTB, ser_vbl_int, 0, "serial status", info); 574 retval = request_irq(IRQ_AMIGA_VERTB, ser_vbl_int, 0, "serial status", info);
555 if (retval) { 575 if (retval) {
556 if (serial_isroot()) { 576 if (serial_isroot()) {
557 set_bit(TTY_IO_ERROR, &tty->flags); 577 if (info->tty)
578 set_bit(TTY_IO_ERROR,
579 &info->tty->flags);
558 retval = 0; 580 retval = 0;
559 } 581 }
560 goto errout; 582 goto errout;
@@ -568,32 +590,37 @@ static int startup(struct tty_struct *tty, struct serial_state *info)
568 /* remember current state of the DCD and CTS bits */ 590 /* remember current state of the DCD and CTS bits */
569 current_ctl_bits = ciab.pra & (SER_DCD | SER_CTS | SER_DSR); 591 current_ctl_bits = ciab.pra & (SER_DCD | SER_CTS | SER_DSR);
570 592
593 IRQ_ports = info;
594
571 info->MCR = 0; 595 info->MCR = 0;
572 if (C_BAUD(tty)) 596 if (info->tty->termios->c_cflag & CBAUD)
573 info->MCR = SER_DTR | SER_RTS; 597 info->MCR = SER_DTR | SER_RTS;
574 rtsdtr_ctrl(info->MCR); 598 rtsdtr_ctrl(info->MCR);
575 599
576 clear_bit(TTY_IO_ERROR, &tty->flags); 600 if (info->tty)
601 clear_bit(TTY_IO_ERROR, &info->tty->flags);
577 info->xmit.head = info->xmit.tail = 0; 602 info->xmit.head = info->xmit.tail = 0;
578 603
579 /* 604 /*
580 * Set up the tty->alt_speed kludge 605 * Set up the tty->alt_speed kludge
581 */ 606 */
582 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 607 if (info->tty) {
583 tty->alt_speed = 57600; 608 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
584 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 609 info->tty->alt_speed = 57600;
585 tty->alt_speed = 115200; 610 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
586 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 611 info->tty->alt_speed = 115200;
587 tty->alt_speed = 230400; 612 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
588 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 613 info->tty->alt_speed = 230400;
589 tty->alt_speed = 460800; 614 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
615 info->tty->alt_speed = 460800;
616 }
590 617
591 /* 618 /*
592 * and set the speed of the serial port 619 * and set the speed of the serial port
593 */ 620 */
594 change_speed(tty, info, NULL); 621 change_speed(info, NULL);
595 622
596 port->flags |= ASYNC_INITIALIZED; 623 info->flags |= ASYNC_INITIALIZED;
597 local_irq_restore(flags); 624 local_irq_restore(flags);
598 return 0; 625 return 0;
599 626
@@ -606,15 +633,15 @@ errout:
606 * This routine will shutdown a serial port; interrupts are disabled, and 633 * This routine will shutdown a serial port; interrupts are disabled, and
607 * DTR is dropped if the hangup on close termio flag is on. 634 * DTR is dropped if the hangup on close termio flag is on.
608 */ 635 */
609static void shutdown(struct tty_struct *tty, struct serial_state *info) 636static void shutdown(struct async_struct * info)
610{ 637{
611 unsigned long flags; 638 unsigned long flags;
612 struct serial_state *state; 639 struct serial_state *state;
613 640
614 if (!(info->tport.flags & ASYNC_INITIALIZED)) 641 if (!(info->flags & ASYNC_INITIALIZED))
615 return; 642 return;
616 643
617 state = info; 644 state = info->state;
618 645
619#ifdef SERIAL_DEBUG_OPEN 646#ifdef SERIAL_DEBUG_OPEN
620 printk("Shutting down serial port %d ....\n", info->line); 647 printk("Shutting down serial port %d ....\n", info->line);
@@ -626,7 +653,9 @@ static void shutdown(struct tty_struct *tty, struct serial_state *info)
626 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq 653 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
627 * here so the queue might never be waken up 654 * here so the queue might never be waken up
628 */ 655 */
629 wake_up_interruptible(&info->tport.delta_msr_wait); 656 wake_up_interruptible(&info->delta_msr_wait);
657
658 IRQ_ports = NULL;
630 659
631 /* 660 /*
632 * Free the IRQ, if necessary 661 * Free the IRQ, if necessary
@@ -646,13 +675,14 @@ static void shutdown(struct tty_struct *tty, struct serial_state *info)
646 custom.adkcon = AC_UARTBRK; 675 custom.adkcon = AC_UARTBRK;
647 mb(); 676 mb();
648 677
649 if (tty->termios.c_cflag & HUPCL) 678 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
650 info->MCR &= ~(SER_DTR|SER_RTS); 679 info->MCR &= ~(SER_DTR|SER_RTS);
651 rtsdtr_ctrl(info->MCR); 680 rtsdtr_ctrl(info->MCR);
652 681
653 set_bit(TTY_IO_ERROR, &tty->flags); 682 if (info->tty)
683 set_bit(TTY_IO_ERROR, &info->tty->flags);
654 684
655 info->tport.flags &= ~ASYNC_INITIALIZED; 685 info->flags &= ~ASYNC_INITIALIZED;
656 local_irq_restore(flags); 686 local_irq_restore(flags);
657} 687}
658 688
@@ -661,16 +691,17 @@ static void shutdown(struct tty_struct *tty, struct serial_state *info)
661 * This routine is called to set the UART divisor registers to match 691 * This routine is called to set the UART divisor registers to match
662 * the specified baud rate for a serial port. 692 * the specified baud rate for a serial port.
663 */ 693 */
664static void change_speed(struct tty_struct *tty, struct serial_state *info, 694static void change_speed(struct async_struct *info,
665 struct ktermios *old_termios) 695 struct ktermios *old_termios)
666{ 696{
667 struct tty_port *port = &info->tport;
668 int quot = 0, baud_base, baud; 697 int quot = 0, baud_base, baud;
669 unsigned cflag, cval = 0; 698 unsigned cflag, cval = 0;
670 int bits; 699 int bits;
671 unsigned long flags; 700 unsigned long flags;
672 701
673 cflag = tty->termios.c_cflag; 702 if (!info->tty || !info->tty->termios)
703 return;
704 cflag = info->tty->termios->c_cflag;
674 705
675 /* Byte size is always 8 bits plus parity bit if requested */ 706 /* Byte size is always 8 bits plus parity bit if requested */
676 707
@@ -691,12 +722,13 @@ static void change_speed(struct tty_struct *tty, struct serial_state *info,
691#endif 722#endif
692 723
693 /* Determine divisor based on baud rate */ 724 /* Determine divisor based on baud rate */
694 baud = tty_get_baud_rate(tty); 725 baud = tty_get_baud_rate(info->tty);
695 if (!baud) 726 if (!baud)
696 baud = 9600; /* B0 transition handled in rs_set_termios */ 727 baud = 9600; /* B0 transition handled in rs_set_termios */
697 baud_base = info->baud_base; 728 baud_base = info->state->baud_base;
698 if (baud == 38400 && (port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) 729 if (baud == 38400 &&
699 quot = info->custom_divisor; 730 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
731 quot = info->state->custom_divisor;
700 else { 732 else {
701 if (baud == 134) 733 if (baud == 134)
702 /* Special case since 134 is really 134.5 */ 734 /* Special case since 134 is really 134.5 */
@@ -707,14 +739,14 @@ static void change_speed(struct tty_struct *tty, struct serial_state *info,
707 /* If the quotient is zero refuse the change */ 739 /* If the quotient is zero refuse the change */
708 if (!quot && old_termios) { 740 if (!quot && old_termios) {
709 /* FIXME: Will need updating for new tty in the end */ 741 /* FIXME: Will need updating for new tty in the end */
710 tty->termios.c_cflag &= ~CBAUD; 742 info->tty->termios->c_cflag &= ~CBAUD;
711 tty->termios.c_cflag |= (old_termios->c_cflag & CBAUD); 743 info->tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD);
712 baud = tty_get_baud_rate(tty); 744 baud = tty_get_baud_rate(info->tty);
713 if (!baud) 745 if (!baud)
714 baud = 9600; 746 baud = 9600;
715 if (baud == 38400 && 747 if (baud == 38400 &&
716 (port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) 748 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
717 quot = info->custom_divisor; 749 quot = info->state->custom_divisor;
718 else { 750 else {
719 if (baud == 134) 751 if (baud == 134)
720 /* Special case since 134 is really 134.5 */ 752 /* Special case since 134 is really 134.5 */
@@ -732,17 +764,17 @@ static void change_speed(struct tty_struct *tty, struct serial_state *info,
732 764
733 /* CTS flow control flag and modem status interrupts */ 765 /* CTS flow control flag and modem status interrupts */
734 info->IER &= ~UART_IER_MSI; 766 info->IER &= ~UART_IER_MSI;
735 if (port->flags & ASYNC_HARDPPS_CD) 767 if (info->flags & ASYNC_HARDPPS_CD)
736 info->IER |= UART_IER_MSI; 768 info->IER |= UART_IER_MSI;
737 if (cflag & CRTSCTS) { 769 if (cflag & CRTSCTS) {
738 port->flags |= ASYNC_CTS_FLOW; 770 info->flags |= ASYNC_CTS_FLOW;
739 info->IER |= UART_IER_MSI; 771 info->IER |= UART_IER_MSI;
740 } else 772 } else
741 port->flags &= ~ASYNC_CTS_FLOW; 773 info->flags &= ~ASYNC_CTS_FLOW;
742 if (cflag & CLOCAL) 774 if (cflag & CLOCAL)
743 port->flags &= ~ASYNC_CHECK_CD; 775 info->flags &= ~ASYNC_CHECK_CD;
744 else { 776 else {
745 port->flags |= ASYNC_CHECK_CD; 777 info->flags |= ASYNC_CHECK_CD;
746 info->IER |= UART_IER_MSI; 778 info->IER |= UART_IER_MSI;
747 } 779 }
748 /* TBD: 780 /* TBD:
@@ -754,24 +786,24 @@ static void change_speed(struct tty_struct *tty, struct serial_state *info,
754 */ 786 */
755 787
756 info->read_status_mask = UART_LSR_OE | UART_LSR_DR; 788 info->read_status_mask = UART_LSR_OE | UART_LSR_DR;
757 if (I_INPCK(tty)) 789 if (I_INPCK(info->tty))
758 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 790 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
759 if (I_BRKINT(tty) || I_PARMRK(tty)) 791 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
760 info->read_status_mask |= UART_LSR_BI; 792 info->read_status_mask |= UART_LSR_BI;
761 793
762 /* 794 /*
763 * Characters to ignore 795 * Characters to ignore
764 */ 796 */
765 info->ignore_status_mask = 0; 797 info->ignore_status_mask = 0;
766 if (I_IGNPAR(tty)) 798 if (I_IGNPAR(info->tty))
767 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 799 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
768 if (I_IGNBRK(tty)) { 800 if (I_IGNBRK(info->tty)) {
769 info->ignore_status_mask |= UART_LSR_BI; 801 info->ignore_status_mask |= UART_LSR_BI;
770 /* 802 /*
771 * If we're ignore parity and break indicators, ignore 803 * If we're ignore parity and break indicators, ignore
772 * overruns too. (For real raw support). 804 * overruns too. (For real raw support).
773 */ 805 */
774 if (I_IGNPAR(tty)) 806 if (I_IGNPAR(info->tty))
775 info->ignore_status_mask |= UART_LSR_OE; 807 info->ignore_status_mask |= UART_LSR_OE;
776 } 808 }
777 /* 809 /*
@@ -796,12 +828,13 @@ static void change_speed(struct tty_struct *tty, struct serial_state *info,
796 mb(); 828 mb();
797 } 829 }
798 830
831 info->LCR = cval; /* Save LCR */
799 local_irq_restore(flags); 832 local_irq_restore(flags);
800} 833}
801 834
802static int rs_put_char(struct tty_struct *tty, unsigned char ch) 835static int rs_put_char(struct tty_struct *tty, unsigned char ch)
803{ 836{
804 struct serial_state *info; 837 struct async_struct *info;
805 unsigned long flags; 838 unsigned long flags;
806 839
807 info = tty->driver_data; 840 info = tty->driver_data;
@@ -828,7 +861,7 @@ static int rs_put_char(struct tty_struct *tty, unsigned char ch)
828 861
829static void rs_flush_chars(struct tty_struct *tty) 862static void rs_flush_chars(struct tty_struct *tty)
830{ 863{
831 struct serial_state *info = tty->driver_data; 864 struct async_struct *info = tty->driver_data;
832 unsigned long flags; 865 unsigned long flags;
833 866
834 if (serial_paranoia_check(info, tty->name, "rs_flush_chars")) 867 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
@@ -853,9 +886,11 @@ static void rs_flush_chars(struct tty_struct *tty)
853static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count) 886static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count)
854{ 887{
855 int c, ret = 0; 888 int c, ret = 0;
856 struct serial_state *info = tty->driver_data; 889 struct async_struct *info;
857 unsigned long flags; 890 unsigned long flags;
858 891
892 info = tty->driver_data;
893
859 if (serial_paranoia_check(info, tty->name, "rs_write")) 894 if (serial_paranoia_check(info, tty->name, "rs_write"))
860 return 0; 895 return 0;
861 896
@@ -899,7 +934,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
899 934
900static int rs_write_room(struct tty_struct *tty) 935static int rs_write_room(struct tty_struct *tty)
901{ 936{
902 struct serial_state *info = tty->driver_data; 937 struct async_struct *info = tty->driver_data;
903 938
904 if (serial_paranoia_check(info, tty->name, "rs_write_room")) 939 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
905 return 0; 940 return 0;
@@ -908,7 +943,7 @@ static int rs_write_room(struct tty_struct *tty)
908 943
909static int rs_chars_in_buffer(struct tty_struct *tty) 944static int rs_chars_in_buffer(struct tty_struct *tty)
910{ 945{
911 struct serial_state *info = tty->driver_data; 946 struct async_struct *info = tty->driver_data;
912 947
913 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer")) 948 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
914 return 0; 949 return 0;
@@ -917,7 +952,7 @@ static int rs_chars_in_buffer(struct tty_struct *tty)
917 952
918static void rs_flush_buffer(struct tty_struct *tty) 953static void rs_flush_buffer(struct tty_struct *tty)
919{ 954{
920 struct serial_state *info = tty->driver_data; 955 struct async_struct *info = tty->driver_data;
921 unsigned long flags; 956 unsigned long flags;
922 957
923 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer")) 958 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
@@ -934,7 +969,7 @@ static void rs_flush_buffer(struct tty_struct *tty)
934 */ 969 */
935static void rs_send_xchar(struct tty_struct *tty, char ch) 970static void rs_send_xchar(struct tty_struct *tty, char ch)
936{ 971{
937 struct serial_state *info = tty->driver_data; 972 struct async_struct *info = tty->driver_data;
938 unsigned long flags; 973 unsigned long flags;
939 974
940 if (serial_paranoia_check(info, tty->name, "rs_send_char")) 975 if (serial_paranoia_check(info, tty->name, "rs_send_char"))
@@ -969,7 +1004,7 @@ static void rs_send_xchar(struct tty_struct *tty, char ch)
969 */ 1004 */
970static void rs_throttle(struct tty_struct * tty) 1005static void rs_throttle(struct tty_struct * tty)
971{ 1006{
972 struct serial_state *info = tty->driver_data; 1007 struct async_struct *info = tty->driver_data;
973 unsigned long flags; 1008 unsigned long flags;
974#ifdef SERIAL_DEBUG_THROTTLE 1009#ifdef SERIAL_DEBUG_THROTTLE
975 char buf[64]; 1010 char buf[64];
@@ -984,7 +1019,7 @@ static void rs_throttle(struct tty_struct * tty)
984 if (I_IXOFF(tty)) 1019 if (I_IXOFF(tty))
985 rs_send_xchar(tty, STOP_CHAR(tty)); 1020 rs_send_xchar(tty, STOP_CHAR(tty));
986 1021
987 if (tty->termios.c_cflag & CRTSCTS) 1022 if (tty->termios->c_cflag & CRTSCTS)
988 info->MCR &= ~SER_RTS; 1023 info->MCR &= ~SER_RTS;
989 1024
990 local_irq_save(flags); 1025 local_irq_save(flags);
@@ -994,7 +1029,7 @@ static void rs_throttle(struct tty_struct * tty)
994 1029
995static void rs_unthrottle(struct tty_struct * tty) 1030static void rs_unthrottle(struct tty_struct * tty)
996{ 1031{
997 struct serial_state *info = tty->driver_data; 1032 struct async_struct *info = tty->driver_data;
998 unsigned long flags; 1033 unsigned long flags;
999#ifdef SERIAL_DEBUG_THROTTLE 1034#ifdef SERIAL_DEBUG_THROTTLE
1000 char buf[64]; 1035 char buf[64];
@@ -1012,7 +1047,7 @@ static void rs_unthrottle(struct tty_struct * tty)
1012 else 1047 else
1013 rs_send_xchar(tty, START_CHAR(tty)); 1048 rs_send_xchar(tty, START_CHAR(tty));
1014 } 1049 }
1015 if (tty->termios.c_cflag & CRTSCTS) 1050 if (tty->termios->c_cflag & CRTSCTS)
1016 info->MCR |= SER_RTS; 1051 info->MCR |= SER_RTS;
1017 local_irq_save(flags); 1052 local_irq_save(flags);
1018 rtsdtr_ctrl(info->MCR); 1053 rtsdtr_ctrl(info->MCR);
@@ -1025,66 +1060,71 @@ static void rs_unthrottle(struct tty_struct * tty)
1025 * ------------------------------------------------------------ 1060 * ------------------------------------------------------------
1026 */ 1061 */
1027 1062
1028static int get_serial_info(struct tty_struct *tty, struct serial_state *state, 1063static int get_serial_info(struct async_struct * info,
1029 struct serial_struct __user * retinfo) 1064 struct serial_struct __user * retinfo)
1030{ 1065{
1031 struct serial_struct tmp; 1066 struct serial_struct tmp;
1067 struct serial_state *state = info->state;
1032 1068
1033 if (!retinfo) 1069 if (!retinfo)
1034 return -EFAULT; 1070 return -EFAULT;
1035 memset(&tmp, 0, sizeof(tmp)); 1071 memset(&tmp, 0, sizeof(tmp));
1036 tty_lock(tty); 1072 tty_lock();
1037 tmp.line = tty->index; 1073 tmp.type = state->type;
1074 tmp.line = state->line;
1038 tmp.port = state->port; 1075 tmp.port = state->port;
1039 tmp.flags = state->tport.flags; 1076 tmp.irq = state->irq;
1077 tmp.flags = state->flags;
1040 tmp.xmit_fifo_size = state->xmit_fifo_size; 1078 tmp.xmit_fifo_size = state->xmit_fifo_size;
1041 tmp.baud_base = state->baud_base; 1079 tmp.baud_base = state->baud_base;
1042 tmp.close_delay = state->tport.close_delay; 1080 tmp.close_delay = state->close_delay;
1043 tmp.closing_wait = state->tport.closing_wait; 1081 tmp.closing_wait = state->closing_wait;
1044 tmp.custom_divisor = state->custom_divisor; 1082 tmp.custom_divisor = state->custom_divisor;
1045 tty_unlock(tty); 1083 tty_unlock();
1046 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) 1084 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
1047 return -EFAULT; 1085 return -EFAULT;
1048 return 0; 1086 return 0;
1049} 1087}
1050 1088
1051static int set_serial_info(struct tty_struct *tty, struct serial_state *state, 1089static int set_serial_info(struct async_struct * info,
1052 struct serial_struct __user * new_info) 1090 struct serial_struct __user * new_info)
1053{ 1091{
1054 struct tty_port *port = &state->tport;
1055 struct serial_struct new_serial; 1092 struct serial_struct new_serial;
1056 bool change_spd; 1093 struct serial_state old_state, *state;
1094 unsigned int change_irq,change_port;
1057 int retval = 0; 1095 int retval = 0;
1058 1096
1059 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1097 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1060 return -EFAULT; 1098 return -EFAULT;
1061 1099
1062 tty_lock(tty); 1100 tty_lock();
1063 change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || 1101 state = info->state;
1064 new_serial.custom_divisor != state->custom_divisor; 1102 old_state = *state;
1065 if (new_serial.irq || new_serial.port != state->port || 1103
1066 new_serial.xmit_fifo_size != state->xmit_fifo_size) { 1104 change_irq = new_serial.irq != state->irq;
1067 tty_unlock(tty); 1105 change_port = (new_serial.port != state->port);
1068 return -EINVAL; 1106 if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) {
1107 tty_unlock();
1108 return -EINVAL;
1069 } 1109 }
1070 1110
1071 if (!serial_isroot()) { 1111 if (!serial_isroot()) {
1072 if ((new_serial.baud_base != state->baud_base) || 1112 if ((new_serial.baud_base != state->baud_base) ||
1073 (new_serial.close_delay != port->close_delay) || 1113 (new_serial.close_delay != state->close_delay) ||
1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) || 1114 (new_serial.xmit_fifo_size != state->xmit_fifo_size) ||
1075 ((new_serial.flags & ~ASYNC_USR_MASK) != 1115 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1076 (port->flags & ~ASYNC_USR_MASK))) { 1116 (state->flags & ~ASYNC_USR_MASK)))
1077 tty_unlock(tty);
1078 return -EPERM; 1117 return -EPERM;
1079 } 1118 state->flags = ((state->flags & ~ASYNC_USR_MASK) |
1080 port->flags = ((port->flags & ~ASYNC_USR_MASK) | 1119 (new_serial.flags & ASYNC_USR_MASK));
1120 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1081 (new_serial.flags & ASYNC_USR_MASK)); 1121 (new_serial.flags & ASYNC_USR_MASK));
1082 state->custom_divisor = new_serial.custom_divisor; 1122 state->custom_divisor = new_serial.custom_divisor;
1083 goto check_and_exit; 1123 goto check_and_exit;
1084 } 1124 }
1085 1125
1086 if (new_serial.baud_base < 9600) { 1126 if (new_serial.baud_base < 9600) {
1087 tty_unlock(tty); 1127 tty_unlock();
1088 return -EINVAL; 1128 return -EINVAL;
1089 } 1129 }
1090 1130
@@ -1094,29 +1134,33 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
1094 */ 1134 */
1095 1135
1096 state->baud_base = new_serial.baud_base; 1136 state->baud_base = new_serial.baud_base;
1097 port->flags = ((port->flags & ~ASYNC_FLAGS) | 1137 state->flags = ((state->flags & ~ASYNC_FLAGS) |
1098 (new_serial.flags & ASYNC_FLAGS)); 1138 (new_serial.flags & ASYNC_FLAGS));
1139 info->flags = ((state->flags & ~ASYNC_INTERNAL_FLAGS) |
1140 (info->flags & ASYNC_INTERNAL_FLAGS));
1099 state->custom_divisor = new_serial.custom_divisor; 1141 state->custom_divisor = new_serial.custom_divisor;
1100 port->close_delay = new_serial.close_delay * HZ/100; 1142 state->close_delay = new_serial.close_delay * HZ/100;
1101 port->closing_wait = new_serial.closing_wait * HZ/100; 1143 state->closing_wait = new_serial.closing_wait * HZ/100;
1102 tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1144 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1103 1145
1104check_and_exit: 1146check_and_exit:
1105 if (port->flags & ASYNC_INITIALIZED) { 1147 if (info->flags & ASYNC_INITIALIZED) {
1106 if (change_spd) { 1148 if (((old_state.flags & ASYNC_SPD_MASK) !=
1107 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 1149 (state->flags & ASYNC_SPD_MASK)) ||
1108 tty->alt_speed = 57600; 1150 (old_state.custom_divisor != state->custom_divisor)) {
1109 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1151 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1110 tty->alt_speed = 115200; 1152 info->tty->alt_speed = 57600;
1111 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 1153 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1112 tty->alt_speed = 230400; 1154 info->tty->alt_speed = 115200;
1113 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 1155 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
1114 tty->alt_speed = 460800; 1156 info->tty->alt_speed = 230400;
1115 change_speed(tty, state, NULL); 1157 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
1158 info->tty->alt_speed = 460800;
1159 change_speed(info, NULL);
1116 } 1160 }
1117 } else 1161 } else
1118 retval = startup(tty, state); 1162 retval = startup(info);
1119 tty_unlock(tty); 1163 tty_unlock();
1120 return retval; 1164 return retval;
1121} 1165}
1122 1166
@@ -1131,7 +1175,7 @@ check_and_exit:
1131 * transmit holding register is empty. This functionality 1175 * transmit holding register is empty. This functionality
1132 * allows an RS485 driver to be written in user space. 1176 * allows an RS485 driver to be written in user space.
1133 */ 1177 */
1134static int get_lsr_info(struct serial_state *info, unsigned int __user *value) 1178static int get_lsr_info(struct async_struct * info, unsigned int __user *value)
1135{ 1179{
1136 unsigned char status; 1180 unsigned char status;
1137 unsigned int result; 1181 unsigned int result;
@@ -1150,7 +1194,7 @@ static int get_lsr_info(struct serial_state *info, unsigned int __user *value)
1150 1194
1151static int rs_tiocmget(struct tty_struct *tty) 1195static int rs_tiocmget(struct tty_struct *tty)
1152{ 1196{
1153 struct serial_state *info = tty->driver_data; 1197 struct async_struct * info = tty->driver_data;
1154 unsigned char control, status; 1198 unsigned char control, status;
1155 unsigned long flags; 1199 unsigned long flags;
1156 1200
@@ -1173,7 +1217,7 @@ static int rs_tiocmget(struct tty_struct *tty)
1173static int rs_tiocmset(struct tty_struct *tty, unsigned int set, 1217static int rs_tiocmset(struct tty_struct *tty, unsigned int set,
1174 unsigned int clear) 1218 unsigned int clear)
1175{ 1219{
1176 struct serial_state *info = tty->driver_data; 1220 struct async_struct * info = tty->driver_data;
1177 unsigned long flags; 1221 unsigned long flags;
1178 1222
1179 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) 1223 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
@@ -1200,7 +1244,7 @@ static int rs_tiocmset(struct tty_struct *tty, unsigned int set,
1200 */ 1244 */
1201static int rs_break(struct tty_struct *tty, int break_state) 1245static int rs_break(struct tty_struct *tty, int break_state)
1202{ 1246{
1203 struct serial_state *info = tty->driver_data; 1247 struct async_struct * info = tty->driver_data;
1204 unsigned long flags; 1248 unsigned long flags;
1205 1249
1206 if (serial_paranoia_check(info, tty->name, "rs_break")) 1250 if (serial_paranoia_check(info, tty->name, "rs_break"))
@@ -1225,12 +1269,12 @@ static int rs_break(struct tty_struct *tty, int break_state)
1225static int rs_get_icount(struct tty_struct *tty, 1269static int rs_get_icount(struct tty_struct *tty,
1226 struct serial_icounter_struct *icount) 1270 struct serial_icounter_struct *icount)
1227{ 1271{
1228 struct serial_state *info = tty->driver_data; 1272 struct async_struct *info = tty->driver_data;
1229 struct async_icount cnow; 1273 struct async_icount cnow;
1230 unsigned long flags; 1274 unsigned long flags;
1231 1275
1232 local_irq_save(flags); 1276 local_irq_save(flags);
1233 cnow = info->icount; 1277 cnow = info->state->icount;
1234 local_irq_restore(flags); 1278 local_irq_restore(flags);
1235 icount->cts = cnow.cts; 1279 icount->cts = cnow.cts;
1236 icount->dsr = cnow.dsr; 1280 icount->dsr = cnow.dsr;
@@ -1250,7 +1294,7 @@ static int rs_get_icount(struct tty_struct *tty,
1250static int rs_ioctl(struct tty_struct *tty, 1294static int rs_ioctl(struct tty_struct *tty,
1251 unsigned int cmd, unsigned long arg) 1295 unsigned int cmd, unsigned long arg)
1252{ 1296{
1253 struct serial_state *info = tty->driver_data; 1297 struct async_struct * info = tty->driver_data;
1254 struct async_icount cprev, cnow; /* kernel counter temps */ 1298 struct async_icount cprev, cnow; /* kernel counter temps */
1255 void __user *argp = (void __user *)arg; 1299 void __user *argp = (void __user *)arg;
1256 unsigned long flags; 1300 unsigned long flags;
@@ -1267,9 +1311,9 @@ static int rs_ioctl(struct tty_struct *tty,
1267 1311
1268 switch (cmd) { 1312 switch (cmd) {
1269 case TIOCGSERIAL: 1313 case TIOCGSERIAL:
1270 return get_serial_info(tty, info, argp); 1314 return get_serial_info(info, argp);
1271 case TIOCSSERIAL: 1315 case TIOCSSERIAL:
1272 return set_serial_info(tty, info, argp); 1316 return set_serial_info(info, argp);
1273 case TIOCSERCONFIG: 1317 case TIOCSERCONFIG:
1274 return 0; 1318 return 0;
1275 1319
@@ -1278,7 +1322,7 @@ static int rs_ioctl(struct tty_struct *tty,
1278 1322
1279 case TIOCSERGSTRUCT: 1323 case TIOCSERGSTRUCT:
1280 if (copy_to_user(argp, 1324 if (copy_to_user(argp,
1281 info, sizeof(struct serial_state))) 1325 info, sizeof(struct async_struct)))
1282 return -EFAULT; 1326 return -EFAULT;
1283 return 0; 1327 return 0;
1284 1328
@@ -1291,15 +1335,15 @@ static int rs_ioctl(struct tty_struct *tty,
1291 case TIOCMIWAIT: 1335 case TIOCMIWAIT:
1292 local_irq_save(flags); 1336 local_irq_save(flags);
1293 /* note the counters on entry */ 1337 /* note the counters on entry */
1294 cprev = info->icount; 1338 cprev = info->state->icount;
1295 local_irq_restore(flags); 1339 local_irq_restore(flags);
1296 while (1) { 1340 while (1) {
1297 interruptible_sleep_on(&info->tport.delta_msr_wait); 1341 interruptible_sleep_on(&info->delta_msr_wait);
1298 /* see if a signal did it */ 1342 /* see if a signal did it */
1299 if (signal_pending(current)) 1343 if (signal_pending(current))
1300 return -ERESTARTSYS; 1344 return -ERESTARTSYS;
1301 local_irq_save(flags); 1345 local_irq_save(flags);
1302 cnow = info->icount; /* atomic copy */ 1346 cnow = info->state->icount; /* atomic copy */
1303 local_irq_restore(flags); 1347 local_irq_restore(flags);
1304 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 1348 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1305 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) 1349 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
@@ -1328,11 +1372,11 @@ static int rs_ioctl(struct tty_struct *tty,
1328 1372
1329static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 1373static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1330{ 1374{
1331 struct serial_state *info = tty->driver_data; 1375 struct async_struct *info = tty->driver_data;
1332 unsigned long flags; 1376 unsigned long flags;
1333 unsigned int cflag = tty->termios.c_cflag; 1377 unsigned int cflag = tty->termios->c_cflag;
1334 1378
1335 change_speed(tty, info, old_termios); 1379 change_speed(info, old_termios);
1336 1380
1337 /* Handle transition to B0 status */ 1381 /* Handle transition to B0 status */
1338 if ((old_termios->c_cflag & CBAUD) && 1382 if ((old_termios->c_cflag & CBAUD) &&
@@ -1347,7 +1391,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1347 if (!(old_termios->c_cflag & CBAUD) && 1391 if (!(old_termios->c_cflag & CBAUD) &&
1348 (cflag & CBAUD)) { 1392 (cflag & CBAUD)) {
1349 info->MCR |= SER_DTR; 1393 info->MCR |= SER_DTR;
1350 if (!(tty->termios.c_cflag & CRTSCTS) || 1394 if (!(tty->termios->c_cflag & CRTSCTS) ||
1351 !test_bit(TTY_THROTTLED, &tty->flags)) { 1395 !test_bit(TTY_THROTTLED, &tty->flags)) {
1352 info->MCR |= SER_RTS; 1396 info->MCR |= SER_RTS;
1353 } 1397 }
@@ -1358,7 +1402,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1358 1402
1359 /* Handle turning off CRTSCTS */ 1403 /* Handle turning off CRTSCTS */
1360 if ((old_termios->c_cflag & CRTSCTS) && 1404 if ((old_termios->c_cflag & CRTSCTS) &&
1361 !(tty->termios.c_cflag & CRTSCTS)) { 1405 !(tty->termios->c_cflag & CRTSCTS)) {
1362 tty->hw_stopped = 0; 1406 tty->hw_stopped = 0;
1363 rs_start(tty); 1407 rs_start(tty);
1364 } 1408 }
@@ -1371,7 +1415,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1371 * or not. Hence, this may change..... 1415 * or not. Hence, this may change.....
1372 */ 1416 */
1373 if (!(old_termios->c_cflag & CLOCAL) && 1417 if (!(old_termios->c_cflag & CLOCAL) &&
1374 (tty->termios.c_cflag & CLOCAL)) 1418 (tty->termios->c_cflag & CLOCAL))
1375 wake_up_interruptible(&info->open_wait); 1419 wake_up_interruptible(&info->open_wait);
1376#endif 1420#endif
1377} 1421}
@@ -1388,23 +1432,64 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1388 */ 1432 */
1389static void rs_close(struct tty_struct *tty, struct file * filp) 1433static void rs_close(struct tty_struct *tty, struct file * filp)
1390{ 1434{
1391 struct serial_state *state = tty->driver_data; 1435 struct async_struct * info = tty->driver_data;
1392 struct tty_port *port = &state->tport; 1436 struct serial_state *state;
1437 unsigned long flags;
1393 1438
1394 if (serial_paranoia_check(state, tty->name, "rs_close")) 1439 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1395 return; 1440 return;
1396 1441
1397 if (tty_port_close_start(port, tty, filp) == 0) 1442 state = info->state;
1443
1444 local_irq_save(flags);
1445
1446 if (tty_hung_up_p(filp)) {
1447 DBG_CNT("before DEC-hung");
1448 local_irq_restore(flags);
1398 return; 1449 return;
1450 }
1399 1451
1452#ifdef SERIAL_DEBUG_OPEN
1453 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
1454#endif
1455 if ((tty->count == 1) && (state->count != 1)) {
1456 /*
1457 * Uh, oh. tty->count is 1, which means that the tty
1458 * structure will be freed. state->count should always
1459 * be one in these conditions. If it's greater than
1460 * one, we've got real problems, since it means the
1461 * serial port won't be shutdown.
1462 */
1463 printk("rs_close: bad serial port count; tty->count is 1, "
1464 "state->count is %d\n", state->count);
1465 state->count = 1;
1466 }
1467 if (--state->count < 0) {
1468 printk("rs_close: bad serial port count for ttys%d: %d\n",
1469 info->line, state->count);
1470 state->count = 0;
1471 }
1472 if (state->count) {
1473 DBG_CNT("before DEC-2");
1474 local_irq_restore(flags);
1475 return;
1476 }
1477 info->flags |= ASYNC_CLOSING;
1478 /*
1479 * Now we wait for the transmit buffer to clear; and we notify
1480 * the line discipline to only process XON/XOFF characters.
1481 */
1482 tty->closing = 1;
1483 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1484 tty_wait_until_sent(tty, info->closing_wait);
1400 /* 1485 /*
1401 * At this point we stop accepting input. To do this, we 1486 * At this point we stop accepting input. To do this, we
1402 * disable the receive line status interrupts, and tell the 1487 * disable the receive line status interrupts, and tell the
1403 * interrupt driver to stop checking the data ready bit in the 1488 * interrupt driver to stop checking the data ready bit in the
1404 * line status register. 1489 * line status register.
1405 */ 1490 */
1406 state->read_status_mask &= ~UART_LSR_DR; 1491 info->read_status_mask &= ~UART_LSR_DR;
1407 if (port->flags & ASYNC_INITIALIZED) { 1492 if (info->flags & ASYNC_INITIALIZED) {
1408 /* disable receive interrupts */ 1493 /* disable receive interrupts */
1409 custom.intena = IF_RBF; 1494 custom.intena = IF_RBF;
1410 mb(); 1495 mb();
@@ -1417,15 +1502,24 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1417 * has completely drained; this is especially 1502 * has completely drained; this is especially
1418 * important if there is a transmit FIFO! 1503 * important if there is a transmit FIFO!
1419 */ 1504 */
1420 rs_wait_until_sent(tty, state->timeout); 1505 rs_wait_until_sent(tty, info->timeout);
1421 } 1506 }
1422 shutdown(tty, state); 1507 shutdown(info);
1423 rs_flush_buffer(tty); 1508 rs_flush_buffer(tty);
1424 1509
1425 tty_ldisc_flush(tty); 1510 tty_ldisc_flush(tty);
1426 port->tty = NULL; 1511 tty->closing = 0;
1427 1512 info->event = 0;
1428 tty_port_close_end(port, tty); 1513 info->tty = NULL;
1514 if (info->blocked_open) {
1515 if (info->close_delay) {
1516 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1517 }
1518 wake_up_interruptible(&info->open_wait);
1519 }
1520 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1521 wake_up_interruptible(&info->close_wait);
1522 local_irq_restore(flags);
1429} 1523}
1430 1524
1431/* 1525/*
@@ -1433,8 +1527,9 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1433 */ 1527 */
1434static void rs_wait_until_sent(struct tty_struct *tty, int timeout) 1528static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1435{ 1529{
1436 struct serial_state *info = tty->driver_data; 1530 struct async_struct * info = tty->driver_data;
1437 unsigned long orig_jiffies, char_time; 1531 unsigned long orig_jiffies, char_time;
1532 int tty_was_locked = tty_locked();
1438 int lsr; 1533 int lsr;
1439 1534
1440 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent")) 1535 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
@@ -1446,6 +1541,12 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1446 orig_jiffies = jiffies; 1541 orig_jiffies = jiffies;
1447 1542
1448 /* 1543 /*
1544 * tty_wait_until_sent is called from lots of places,
1545 * with or without the BTM.
1546 */
1547 if (!tty_was_locked)
1548 tty_lock();
1549 /*
1449 * Set the check interval to be 1/5 of the estimated time to 1550 * Set the check interval to be 1/5 of the estimated time to
1450 * send a single character, and make it at least 1. The check 1551 * send a single character, and make it at least 1. The check
1451 * interval should also be less than the timeout. 1552 * interval should also be less than the timeout.
@@ -1485,7 +1586,8 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1485 break; 1586 break;
1486 } 1587 }
1487 __set_current_state(TASK_RUNNING); 1588 __set_current_state(TASK_RUNNING);
1488 1589 if (!tty_was_locked)
1590 tty_unlock();
1489#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 1591#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1490 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 1592 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1491#endif 1593#endif
@@ -1496,17 +1598,173 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1496 */ 1598 */
1497static void rs_hangup(struct tty_struct *tty) 1599static void rs_hangup(struct tty_struct *tty)
1498{ 1600{
1499 struct serial_state *info = tty->driver_data; 1601 struct async_struct * info = tty->driver_data;
1602 struct serial_state *state = info->state;
1500 1603
1501 if (serial_paranoia_check(info, tty->name, "rs_hangup")) 1604 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
1502 return; 1605 return;
1503 1606
1607 state = info->state;
1608
1504 rs_flush_buffer(tty); 1609 rs_flush_buffer(tty);
1505 shutdown(tty, info); 1610 shutdown(info);
1506 info->tport.count = 0; 1611 info->event = 0;
1507 info->tport.flags &= ~ASYNC_NORMAL_ACTIVE; 1612 state->count = 0;
1508 info->tport.tty = NULL; 1613 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1509 wake_up_interruptible(&info->tport.open_wait); 1614 info->tty = NULL;
1615 wake_up_interruptible(&info->open_wait);
1616}
1617
1618/*
1619 * ------------------------------------------------------------
1620 * rs_open() and friends
1621 * ------------------------------------------------------------
1622 */
1623static int block_til_ready(struct tty_struct *tty, struct file * filp,
1624 struct async_struct *info)
1625{
1626#ifdef DECLARE_WAITQUEUE
1627 DECLARE_WAITQUEUE(wait, current);
1628#else
1629 struct wait_queue wait = { current, NULL };
1630#endif
1631 struct serial_state *state = info->state;
1632 int retval;
1633 int do_clocal = 0, extra_count = 0;
1634 unsigned long flags;
1635
1636 /*
1637 * If the device is in the middle of being closed, then block
1638 * until it's done, and then try again.
1639 */
1640 if (tty_hung_up_p(filp) ||
1641 (info->flags & ASYNC_CLOSING)) {
1642 if (info->flags & ASYNC_CLOSING)
1643 interruptible_sleep_on(&info->close_wait);
1644#ifdef SERIAL_DO_RESTART
1645 return ((info->flags & ASYNC_HUP_NOTIFY) ?
1646 -EAGAIN : -ERESTARTSYS);
1647#else
1648 return -EAGAIN;
1649#endif
1650 }
1651
1652 /*
1653 * If non-blocking mode is set, or the port is not enabled,
1654 * then make the check up front and then exit.
1655 */
1656 if ((filp->f_flags & O_NONBLOCK) ||
1657 (tty->flags & (1 << TTY_IO_ERROR))) {
1658 info->flags |= ASYNC_NORMAL_ACTIVE;
1659 return 0;
1660 }
1661
1662 if (tty->termios->c_cflag & CLOCAL)
1663 do_clocal = 1;
1664
1665 /*
1666 * Block waiting for the carrier detect and the line to become
1667 * free (i.e., not in use by the callout). While we are in
1668 * this loop, state->count is dropped by one, so that
1669 * rs_close() knows when to free things. We restore it upon
1670 * exit, either normal or abnormal.
1671 */
1672 retval = 0;
1673 add_wait_queue(&info->open_wait, &wait);
1674#ifdef SERIAL_DEBUG_OPEN
1675 printk("block_til_ready before block: ttys%d, count = %d\n",
1676 state->line, state->count);
1677#endif
1678 local_irq_save(flags);
1679 if (!tty_hung_up_p(filp)) {
1680 extra_count = 1;
1681 state->count--;
1682 }
1683 local_irq_restore(flags);
1684 info->blocked_open++;
1685 while (1) {
1686 local_irq_save(flags);
1687 if (tty->termios->c_cflag & CBAUD)
1688 rtsdtr_ctrl(SER_DTR|SER_RTS);
1689 local_irq_restore(flags);
1690 set_current_state(TASK_INTERRUPTIBLE);
1691 if (tty_hung_up_p(filp) ||
1692 !(info->flags & ASYNC_INITIALIZED)) {
1693#ifdef SERIAL_DO_RESTART
1694 if (info->flags & ASYNC_HUP_NOTIFY)
1695 retval = -EAGAIN;
1696 else
1697 retval = -ERESTARTSYS;
1698#else
1699 retval = -EAGAIN;
1700#endif
1701 break;
1702 }
1703 if (!(info->flags & ASYNC_CLOSING) &&
1704 (do_clocal || (!(ciab.pra & SER_DCD)) ))
1705 break;
1706 if (signal_pending(current)) {
1707 retval = -ERESTARTSYS;
1708 break;
1709 }
1710#ifdef SERIAL_DEBUG_OPEN
1711 printk("block_til_ready blocking: ttys%d, count = %d\n",
1712 info->line, state->count);
1713#endif
1714 tty_unlock();
1715 schedule();
1716 tty_lock();
1717 }
1718 __set_current_state(TASK_RUNNING);
1719 remove_wait_queue(&info->open_wait, &wait);
1720 if (extra_count)
1721 state->count++;
1722 info->blocked_open--;
1723#ifdef SERIAL_DEBUG_OPEN
1724 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1725 info->line, state->count);
1726#endif
1727 if (retval)
1728 return retval;
1729 info->flags |= ASYNC_NORMAL_ACTIVE;
1730 return 0;
1731}
1732
1733static int get_async_struct(int line, struct async_struct **ret_info)
1734{
1735 struct async_struct *info;
1736 struct serial_state *sstate;
1737
1738 sstate = rs_table + line;
1739 sstate->count++;
1740 if (sstate->info) {
1741 *ret_info = sstate->info;
1742 return 0;
1743 }
1744 info = kzalloc(sizeof(struct async_struct), GFP_KERNEL);
1745 if (!info) {
1746 sstate->count--;
1747 return -ENOMEM;
1748 }
1749#ifdef DECLARE_WAITQUEUE
1750 init_waitqueue_head(&info->open_wait);
1751 init_waitqueue_head(&info->close_wait);
1752 init_waitqueue_head(&info->delta_msr_wait);
1753#endif
1754 info->magic = SERIAL_MAGIC;
1755 info->port = sstate->port;
1756 info->flags = sstate->flags;
1757 info->xmit_fifo_size = sstate->xmit_fifo_size;
1758 info->line = line;
1759 tasklet_init(&info->tlet, do_softint, (unsigned long)info);
1760 info->state = sstate;
1761 if (sstate->info) {
1762 kfree(info);
1763 *ret_info = sstate->info;
1764 return 0;
1765 }
1766 *ret_info = sstate->info = info;
1767 return 0;
1510} 1768}
1511 1769
1512/* 1770/*
@@ -1517,42 +1775,91 @@ static void rs_hangup(struct tty_struct *tty)
1517 */ 1775 */
1518static int rs_open(struct tty_struct *tty, struct file * filp) 1776static int rs_open(struct tty_struct *tty, struct file * filp)
1519{ 1777{
1520 struct serial_state *info = rs_table + tty->index; 1778 struct async_struct *info;
1521 struct tty_port *port = &info->tport; 1779 int retval, line;
1522 int retval;
1523 1780
1524 port->count++; 1781 line = tty->index;
1525 port->tty = tty; 1782 if ((line < 0) || (line >= NR_PORTS)) {
1783 return -ENODEV;
1784 }
1785 retval = get_async_struct(line, &info);
1786 if (retval) {
1787 return retval;
1788 }
1526 tty->driver_data = info; 1789 tty->driver_data = info;
1527 tty->port = port; 1790 info->tty = tty;
1528 if (serial_paranoia_check(info, tty->name, "rs_open")) 1791 if (serial_paranoia_check(info, tty->name, "rs_open"))
1529 return -ENODEV; 1792 return -ENODEV;
1530 1793
1531 tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1794#ifdef SERIAL_DEBUG_OPEN
1795 printk("rs_open %s, count = %d\n", tty->name, info->state->count);
1796#endif
1797 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1798
1799 /*
1800 * If the port is the middle of closing, bail out now
1801 */
1802 if (tty_hung_up_p(filp) ||
1803 (info->flags & ASYNC_CLOSING)) {
1804 if (info->flags & ASYNC_CLOSING)
1805 interruptible_sleep_on(&info->close_wait);
1806#ifdef SERIAL_DO_RESTART
1807 return ((info->flags & ASYNC_HUP_NOTIFY) ?
1808 -EAGAIN : -ERESTARTSYS);
1809#else
1810 return -EAGAIN;
1811#endif
1812 }
1813
1814 /*
1815 * Start up serial port
1816 */
1817 retval = startup(info);
1818 if (retval) {
1819 return retval;
1820 }
1532 1821
1533 retval = startup(tty, info); 1822 retval = block_til_ready(tty, filp, info);
1534 if (retval) { 1823 if (retval) {
1824#ifdef SERIAL_DEBUG_OPEN
1825 printk("rs_open returning after block_til_ready with %d\n",
1826 retval);
1827#endif
1535 return retval; 1828 return retval;
1536 } 1829 }
1537 1830
1538 return tty_port_block_til_ready(port, tty, filp); 1831#ifdef SERIAL_DEBUG_OPEN
1832 printk("rs_open %s successful...", tty->name);
1833#endif
1834 return 0;
1539} 1835}
1540 1836
1541/* 1837/*
1542 * /proc fs routines.... 1838 * /proc fs routines....
1543 */ 1839 */
1544 1840
1545static inline void line_info(struct seq_file *m, int line, 1841static inline void line_info(struct seq_file *m, struct serial_state *state)
1546 struct serial_state *state)
1547{ 1842{
1843 struct async_struct *info = state->info, scr_info;
1548 char stat_buf[30], control, status; 1844 char stat_buf[30], control, status;
1549 unsigned long flags; 1845 unsigned long flags;
1550 1846
1551 seq_printf(m, "%d: uart:amiga_builtin", line); 1847 seq_printf(m, "%d: uart:amiga_builtin",state->line);
1848
1849 /*
1850 * Figure out the current RS-232 lines
1851 */
1852 if (!info) {
1853 info = &scr_info; /* This is just for serial_{in,out} */
1552 1854
1855 info->magic = SERIAL_MAGIC;
1856 info->flags = state->flags;
1857 info->quot = 0;
1858 info->tty = NULL;
1859 }
1553 local_irq_save(flags); 1860 local_irq_save(flags);
1554 status = ciab.pra; 1861 status = ciab.pra;
1555 control = (state->tport.flags & ASYNC_INITIALIZED) ? state->MCR : status; 1862 control = info ? info->MCR : status;
1556 local_irq_restore(flags); 1863 local_irq_restore(flags);
1557 1864
1558 stat_buf[0] = 0; 1865 stat_buf[0] = 0;
@@ -1568,8 +1875,9 @@ static inline void line_info(struct seq_file *m, int line,
1568 if(!(status & SER_DCD)) 1875 if(!(status & SER_DCD))
1569 strcat(stat_buf, "|CD"); 1876 strcat(stat_buf, "|CD");
1570 1877
1571 if (state->quot) 1878 if (info->quot) {
1572 seq_printf(m, " baud:%d", state->baud_base / state->quot); 1879 seq_printf(m, " baud:%d", state->baud_base / info->quot);
1880 }
1573 1881
1574 seq_printf(m, " tx:%d rx:%d", state->icount.tx, state->icount.rx); 1882 seq_printf(m, " tx:%d rx:%d", state->icount.tx, state->icount.rx);
1575 1883
@@ -1594,7 +1902,7 @@ static inline void line_info(struct seq_file *m, int line,
1594static int rs_proc_show(struct seq_file *m, void *v) 1902static int rs_proc_show(struct seq_file *m, void *v)
1595{ 1903{
1596 seq_printf(m, "serinfo:1.0 driver:%s\n", serial_version); 1904 seq_printf(m, "serinfo:1.0 driver:%s\n", serial_version);
1597 line_info(m, 0, &rs_table[0]); 1905 line_info(m, &rs_table[0]);
1598 return 0; 1906 return 0;
1599} 1907}
1600 1908
@@ -1655,32 +1963,6 @@ static const struct tty_operations serial_ops = {
1655 .proc_fops = &rs_proc_fops, 1963 .proc_fops = &rs_proc_fops,
1656}; 1964};
1657 1965
1658static int amiga_carrier_raised(struct tty_port *port)
1659{
1660 return !(ciab.pra & SER_DCD);
1661}
1662
1663static void amiga_dtr_rts(struct tty_port *port, int raise)
1664{
1665 struct serial_state *info = container_of(port, struct serial_state,
1666 tport);
1667 unsigned long flags;
1668
1669 if (raise)
1670 info->MCR |= SER_DTR|SER_RTS;
1671 else
1672 info->MCR &= ~(SER_DTR|SER_RTS);
1673
1674 local_irq_save(flags);
1675 rtsdtr_ctrl(info->MCR);
1676 local_irq_restore(flags);
1677}
1678
1679static const struct tty_port_operations amiga_port_ops = {
1680 .carrier_raised = amiga_carrier_raised,
1681 .dtr_rts = amiga_dtr_rts,
1682};
1683
1684/* 1966/*
1685 * The serial driver boot-time initialization code! 1967 * The serial driver boot-time initialization code!
1686 */ 1968 */
@@ -1690,14 +1972,17 @@ static int __init amiga_serial_probe(struct platform_device *pdev)
1690 struct serial_state * state; 1972 struct serial_state * state;
1691 int error; 1973 int error;
1692 1974
1693 serial_driver = alloc_tty_driver(NR_PORTS); 1975 serial_driver = alloc_tty_driver(1);
1694 if (!serial_driver) 1976 if (!serial_driver)
1695 return -ENOMEM; 1977 return -ENOMEM;
1696 1978
1979 IRQ_ports = NULL;
1980
1697 show_serial_version(); 1981 show_serial_version();
1698 1982
1699 /* Initialize the tty_driver structure */ 1983 /* Initialize the tty_driver structure */
1700 1984
1985 serial_driver->owner = THIS_MODULE;
1701 serial_driver->driver_name = "amiserial"; 1986 serial_driver->driver_name = "amiserial";
1702 serial_driver->name = "ttyS"; 1987 serial_driver->name = "ttyS";
1703 serial_driver->major = TTY_MAJOR; 1988 serial_driver->major = TTY_MAJOR;
@@ -1710,23 +1995,25 @@ static int __init amiga_serial_probe(struct platform_device *pdev)
1710 serial_driver->flags = TTY_DRIVER_REAL_RAW; 1995 serial_driver->flags = TTY_DRIVER_REAL_RAW;
1711 tty_set_operations(serial_driver, &serial_ops); 1996 tty_set_operations(serial_driver, &serial_ops);
1712 1997
1998 error = tty_register_driver(serial_driver);
1999 if (error)
2000 goto fail_put_tty_driver;
2001
1713 state = rs_table; 2002 state = rs_table;
2003 state->magic = SSTATE_MAGIC;
1714 state->port = (int)&custom.serdatr; /* Just to give it a value */ 2004 state->port = (int)&custom.serdatr; /* Just to give it a value */
2005 state->line = 0;
1715 state->custom_divisor = 0; 2006 state->custom_divisor = 0;
2007 state->close_delay = 5*HZ/10;
2008 state->closing_wait = 30*HZ;
1716 state->icount.cts = state->icount.dsr = 2009 state->icount.cts = state->icount.dsr =
1717 state->icount.rng = state->icount.dcd = 0; 2010 state->icount.rng = state->icount.dcd = 0;
1718 state->icount.rx = state->icount.tx = 0; 2011 state->icount.rx = state->icount.tx = 0;
1719 state->icount.frame = state->icount.parity = 0; 2012 state->icount.frame = state->icount.parity = 0;
1720 state->icount.overrun = state->icount.brk = 0; 2013 state->icount.overrun = state->icount.brk = 0;
1721 tty_port_init(&state->tport);
1722 state->tport.ops = &amiga_port_ops;
1723 tty_port_link_device(&state->tport, serial_driver, 0);
1724
1725 error = tty_register_driver(serial_driver);
1726 if (error)
1727 goto fail_put_tty_driver;
1728 2014
1729 printk(KERN_INFO "ttyS0 is the amiga builtin serial port\n"); 2015 printk(KERN_INFO "ttyS%d is the amiga builtin serial port\n",
2016 state->line);
1730 2017
1731 /* Hardware set up */ 2018 /* Hardware set up */
1732 2019
@@ -1738,7 +2025,7 @@ static int __init amiga_serial_probe(struct platform_device *pdev)
1738 if (error) 2025 if (error)
1739 goto fail_unregister; 2026 goto fail_unregister;
1740 2027
1741 error = request_irq(IRQ_AMIGA_RBF, ser_rx_int, 0, 2028 error = request_irq(IRQ_AMIGA_RBF, ser_rx_int, IRQF_DISABLED,
1742 "serial RX", state); 2029 "serial RX", state);
1743 if (error) 2030 if (error)
1744 goto fail_free_irq; 2031 goto fail_free_irq;
@@ -1771,7 +2058,6 @@ fail_free_irq:
1771fail_unregister: 2058fail_unregister:
1772 tty_unregister_driver(serial_driver); 2059 tty_unregister_driver(serial_driver);
1773fail_put_tty_driver: 2060fail_put_tty_driver:
1774 tty_port_destroy(&state->tport);
1775 put_tty_driver(serial_driver); 2061 put_tty_driver(serial_driver);
1776 return error; 2062 return error;
1777} 2063}
@@ -1780,16 +2066,20 @@ static int __exit amiga_serial_remove(struct platform_device *pdev)
1780{ 2066{
1781 int error; 2067 int error;
1782 struct serial_state *state = platform_get_drvdata(pdev); 2068 struct serial_state *state = platform_get_drvdata(pdev);
2069 struct async_struct *info = state->info;
1783 2070
1784 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */ 2071 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
2072 tasklet_kill(&info->tlet);
1785 if ((error = tty_unregister_driver(serial_driver))) 2073 if ((error = tty_unregister_driver(serial_driver)))
1786 printk("SERIAL: failed to unregister serial driver (%d)\n", 2074 printk("SERIAL: failed to unregister serial driver (%d)\n",
1787 error); 2075 error);
1788 put_tty_driver(serial_driver); 2076 put_tty_driver(serial_driver);
1789 tty_port_destroy(&state->tport);
1790 2077
1791 free_irq(IRQ_AMIGA_TBE, state); 2078 rs_table[0].info = NULL;
1792 free_irq(IRQ_AMIGA_RBF, state); 2079 kfree(info);
2080
2081 free_irq(IRQ_AMIGA_TBE, rs_table);
2082 free_irq(IRQ_AMIGA_RBF, rs_table);
1793 2083
1794 platform_set_drvdata(pdev, NULL); 2084 platform_set_drvdata(pdev, NULL);
1795 2085
diff --git a/drivers/tty/bfin_jtag_comm.c b/drivers/tty/bfin_jtag_comm.c
index 1cfcdbf1d0c..3a997760ec3 100644
--- a/drivers/tty/bfin_jtag_comm.c
+++ b/drivers/tty/bfin_jtag_comm.c
@@ -62,7 +62,9 @@ static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d)
62 62
63static struct tty_driver *bfin_jc_driver; 63static struct tty_driver *bfin_jc_driver;
64static struct task_struct *bfin_jc_kthread; 64static struct task_struct *bfin_jc_kthread;
65static struct tty_port port; 65static struct tty_struct * volatile bfin_jc_tty;
66static unsigned long bfin_jc_count;
67static DEFINE_MUTEX(bfin_jc_tty_mutex);
66static volatile struct circ_buf bfin_jc_write_buf; 68static volatile struct circ_buf bfin_jc_write_buf;
67 69
68static int 70static int
@@ -71,21 +73,18 @@ bfin_jc_emudat_manager(void *arg)
71 uint32_t inbound_len = 0, outbound_len = 0; 73 uint32_t inbound_len = 0, outbound_len = 0;
72 74
73 while (!kthread_should_stop()) { 75 while (!kthread_should_stop()) {
74 struct tty_struct *tty = tty_port_tty_get(&port);
75 /* no one left to give data to, so sleep */ 76 /* no one left to give data to, so sleep */
76 if (tty == NULL && circ_empty(&bfin_jc_write_buf)) { 77 if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) {
77 pr_debug("waiting for readers\n"); 78 pr_debug("waiting for readers\n");
78 __set_current_state(TASK_UNINTERRUPTIBLE); 79 __set_current_state(TASK_UNINTERRUPTIBLE);
79 schedule(); 80 schedule();
80 __set_current_state(TASK_RUNNING); 81 __set_current_state(TASK_RUNNING);
81 continue;
82 } 82 }
83 83
84 /* no data available, so just chill */ 84 /* no data available, so just chill */
85 if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { 85 if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) {
86 pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n", 86 pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n",
87 inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); 87 inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head);
88 tty_kref_put(tty);
89 if (inbound_len) 88 if (inbound_len)
90 schedule(); 89 schedule();
91 else 90 else
@@ -95,6 +94,9 @@ bfin_jc_emudat_manager(void *arg)
95 94
96 /* if incoming data is ready, eat it */ 95 /* if incoming data is ready, eat it */
97 if (bfin_read_DBGSTAT() & EMUDIF) { 96 if (bfin_read_DBGSTAT() & EMUDIF) {
97 struct tty_struct *tty;
98 mutex_lock(&bfin_jc_tty_mutex);
99 tty = (struct tty_struct *)bfin_jc_tty;
98 if (tty != NULL) { 100 if (tty != NULL) {
99 uint32_t emudat = bfin_read_emudat(); 101 uint32_t emudat = bfin_read_emudat();
100 if (inbound_len == 0) { 102 if (inbound_len == 0) {
@@ -108,6 +110,7 @@ bfin_jc_emudat_manager(void *arg)
108 tty_flip_buffer_push(tty); 110 tty_flip_buffer_push(tty);
109 } 111 }
110 } 112 }
113 mutex_unlock(&bfin_jc_tty_mutex);
111 } 114 }
112 115
113 /* if outgoing data is ready, post it */ 116 /* if outgoing data is ready, post it */
@@ -117,6 +120,7 @@ bfin_jc_emudat_manager(void *arg)
117 bfin_write_emudat(outbound_len); 120 bfin_write_emudat(outbound_len);
118 pr_debug("outgoing length: 0x%08x\n", outbound_len); 121 pr_debug("outgoing length: 0x%08x\n", outbound_len);
119 } else { 122 } else {
123 struct tty_struct *tty;
120 int tail = bfin_jc_write_buf.tail; 124 int tail = bfin_jc_write_buf.tail;
121 size_t ate = (4 <= outbound_len ? 4 : outbound_len); 125 size_t ate = (4 <= outbound_len ? 4 : outbound_len);
122 uint32_t emudat = 126 uint32_t emudat =
@@ -128,12 +132,14 @@ bfin_jc_emudat_manager(void *arg)
128 ); 132 );
129 bfin_jc_write_buf.tail += ate; 133 bfin_jc_write_buf.tail += ate;
130 outbound_len -= ate; 134 outbound_len -= ate;
135 mutex_lock(&bfin_jc_tty_mutex);
136 tty = (struct tty_struct *)bfin_jc_tty;
131 if (tty) 137 if (tty)
132 tty_wakeup(tty); 138 tty_wakeup(tty);
139 mutex_unlock(&bfin_jc_tty_mutex);
133 pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); 140 pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate);
134 } 141 }
135 } 142 }
136 tty_kref_put(tty);
137 } 143 }
138 144
139 __set_current_state(TASK_RUNNING); 145 __set_current_state(TASK_RUNNING);
@@ -143,28 +149,24 @@ bfin_jc_emudat_manager(void *arg)
143static int 149static int
144bfin_jc_open(struct tty_struct *tty, struct file *filp) 150bfin_jc_open(struct tty_struct *tty, struct file *filp)
145{ 151{
146 unsigned long flags; 152 mutex_lock(&bfin_jc_tty_mutex);
147 153 pr_debug("open %lu\n", bfin_jc_count);
148 spin_lock_irqsave(&port.lock, flags); 154 ++bfin_jc_count;
149 port.count++; 155 bfin_jc_tty = tty;
150 spin_unlock_irqrestore(&port.lock, flags);
151 tty_port_tty_set(&port, tty);
152 wake_up_process(bfin_jc_kthread); 156 wake_up_process(bfin_jc_kthread);
157 mutex_unlock(&bfin_jc_tty_mutex);
153 return 0; 158 return 0;
154} 159}
155 160
156static void 161static void
157bfin_jc_close(struct tty_struct *tty, struct file *filp) 162bfin_jc_close(struct tty_struct *tty, struct file *filp)
158{ 163{
159 unsigned long flags; 164 mutex_lock(&bfin_jc_tty_mutex);
160 bool last; 165 pr_debug("close %lu\n", bfin_jc_count);
161 166 if (--bfin_jc_count == 0)
162 spin_lock_irqsave(&port.lock, flags); 167 bfin_jc_tty = NULL;
163 last = --port.count == 0;
164 spin_unlock_irqrestore(&port.lock, flags);
165 if (last)
166 tty_port_tty_set(&port, NULL);
167 wake_up_process(bfin_jc_kthread); 168 wake_up_process(bfin_jc_kthread);
169 mutex_unlock(&bfin_jc_tty_mutex);
168} 170}
169 171
170/* XXX: we dont handle the put_char() case where we must handle count = 1 */ 172/* XXX: we dont handle the put_char() case where we must handle count = 1 */
@@ -255,15 +257,13 @@ static int __init bfin_jc_init(void)
255 if (!bfin_jc_driver) 257 if (!bfin_jc_driver)
256 goto err_driver; 258 goto err_driver;
257 259
258 tty_port_init(&port); 260 bfin_jc_driver->owner = THIS_MODULE;
259
260 bfin_jc_driver->driver_name = DRV_NAME; 261 bfin_jc_driver->driver_name = DRV_NAME;
261 bfin_jc_driver->name = DEV_NAME; 262 bfin_jc_driver->name = DEV_NAME;
262 bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL; 263 bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL;
263 bfin_jc_driver->subtype = SERIAL_TYPE_NORMAL; 264 bfin_jc_driver->subtype = SERIAL_TYPE_NORMAL;
264 bfin_jc_driver->init_termios = tty_std_termios; 265 bfin_jc_driver->init_termios = tty_std_termios;
265 tty_set_operations(bfin_jc_driver, &bfin_jc_ops); 266 tty_set_operations(bfin_jc_driver, &bfin_jc_ops);
266 tty_port_link_device(&port, bfin_jc_driver, 0);
267 267
268 ret = tty_register_driver(bfin_jc_driver); 268 ret = tty_register_driver(bfin_jc_driver);
269 if (ret) 269 if (ret)
@@ -274,7 +274,6 @@ static int __init bfin_jc_init(void)
274 return 0; 274 return 0;
275 275
276 err: 276 err:
277 tty_port_destroy(&port);
278 put_tty_driver(bfin_jc_driver); 277 put_tty_driver(bfin_jc_driver);
279 err_driver: 278 err_driver:
280 kfree(bfin_jc_write_buf.buf); 279 kfree(bfin_jc_write_buf.buf);
@@ -290,7 +289,6 @@ static void __exit bfin_jc_exit(void)
290 kfree(bfin_jc_write_buf.buf); 289 kfree(bfin_jc_write_buf.buf);
291 tty_unregister_driver(bfin_jc_driver); 290 tty_unregister_driver(bfin_jc_driver);
292 put_tty_driver(bfin_jc_driver); 291 put_tty_driver(bfin_jc_driver);
293 tty_port_destroy(&port);
294} 292}
295module_exit(bfin_jc_exit); 293module_exit(bfin_jc_exit);
296 294
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index b09c8d1f9a6..c0e8f2eeb88 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -45,6 +45,7 @@
45#undef CY_DEBUG_IO 45#undef CY_DEBUG_IO
46#undef CY_DEBUG_COUNT 46#undef CY_DEBUG_COUNT
47#undef CY_DEBUG_DTR 47#undef CY_DEBUG_DTR
48#undef CY_DEBUG_WAIT_UNTIL_SENT
48#undef CY_DEBUG_INTERRUPTS 49#undef CY_DEBUG_INTERRUPTS
49#undef CY_16Y_HACK 50#undef CY_16Y_HACK
50#undef CY_ENABLE_MONITORING 51#undef CY_ENABLE_MONITORING
@@ -727,7 +728,7 @@ static void cyy_chip_modem(struct cyclades_card *cinfo, int chip,
727 else 728 else
728 tty_hangup(tty); 729 tty_hangup(tty);
729 } 730 }
730 if ((mdm_change & CyCTS) && tty_port_cts_enabled(&info->port)) { 731 if ((mdm_change & CyCTS) && (info->port.flags & ASYNC_CTS_FLOW)) {
731 if (tty->hw_stopped) { 732 if (tty->hw_stopped) {
732 if (mdm_status & CyCTS) { 733 if (mdm_status & CyCTS) {
733 /* cy_start isn't used 734 /* cy_start isn't used
@@ -1459,7 +1460,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
1459 info->port.xmit_buf = NULL; 1460 info->port.xmit_buf = NULL;
1460 free_page((unsigned long)temp); 1461 free_page((unsigned long)temp);
1461 } 1462 }
1462 if (tty->termios.c_cflag & HUPCL) 1463 if (tty->termios->c_cflag & HUPCL)
1463 cyy_change_rts_dtr(info, 0, TIOCM_RTS | TIOCM_DTR); 1464 cyy_change_rts_dtr(info, 0, TIOCM_RTS | TIOCM_DTR);
1464 1465
1465 cyy_issue_cmd(info, CyCHAN_CTL | CyDIS_RCVR); 1466 cyy_issue_cmd(info, CyCHAN_CTL | CyDIS_RCVR);
@@ -1488,7 +1489,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
1488 free_page((unsigned long)temp); 1489 free_page((unsigned long)temp);
1489 } 1490 }
1490 1491
1491 if (tty->termios.c_cflag & HUPCL) 1492 if (tty->termios->c_cflag & HUPCL)
1492 tty_port_lower_dtr_rts(&info->port); 1493 tty_port_lower_dtr_rts(&info->port);
1493 1494
1494 set_bit(TTY_IO_ERROR, &tty->flags); 1495 set_bit(TTY_IO_ERROR, &tty->flags);
@@ -1515,9 +1516,13 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
1515static int cy_open(struct tty_struct *tty, struct file *filp) 1516static int cy_open(struct tty_struct *tty, struct file *filp)
1516{ 1517{
1517 struct cyclades_port *info; 1518 struct cyclades_port *info;
1518 unsigned int i, line = tty->index; 1519 unsigned int i, line;
1519 int retval; 1520 int retval;
1520 1521
1522 line = tty->index;
1523 if (tty->index < 0 || NR_PORTS <= line)
1524 return -ENODEV;
1525
1521 for (i = 0; i < NR_CARDS; i++) 1526 for (i = 0; i < NR_CARDS; i++)
1522 if (line < cy_card[i].first_line + cy_card[i].nports && 1527 if (line < cy_card[i].first_line + cy_card[i].nports &&
1523 line >= cy_card[i].first_line) 1528 line >= cy_card[i].first_line)
@@ -1599,7 +1604,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
1599 * If the port is the middle of closing, bail out now 1604 * If the port is the middle of closing, bail out now
1600 */ 1605 */
1601 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) { 1606 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) {
1602 wait_event_interruptible_tty(tty, info->port.close_wait, 1607 wait_event_interruptible_tty(info->port.close_wait,
1603 !(info->port.flags & ASYNC_CLOSING)); 1608 !(info->port.flags & ASYNC_CLOSING));
1604 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; 1609 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
1605 } 1610 }
@@ -1673,10 +1678,16 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
1673 */ 1678 */
1674 if (!timeout || timeout > 2 * info->timeout) 1679 if (!timeout || timeout > 2 * info->timeout)
1675 timeout = 2 * info->timeout; 1680 timeout = 2 * info->timeout;
1676 1681#ifdef CY_DEBUG_WAIT_UNTIL_SENT
1682 printk(KERN_DEBUG "In cy_wait_until_sent(%d) check=%d, jiff=%lu...",
1683 timeout, char_time, jiffies);
1684#endif
1677 card = info->card; 1685 card = info->card;
1678 if (!cy_is_Z(card)) { 1686 if (!cy_is_Z(card)) {
1679 while (cyy_readb(info, CySRER) & CyTxRdy) { 1687 while (cyy_readb(info, CySRER) & CyTxRdy) {
1688#ifdef CY_DEBUG_WAIT_UNTIL_SENT
1689 printk(KERN_DEBUG "Not clean (jiff=%lu)...", jiffies);
1690#endif
1680 if (msleep_interruptible(jiffies_to_msecs(char_time))) 1691 if (msleep_interruptible(jiffies_to_msecs(char_time)))
1681 break; 1692 break;
1682 if (timeout && time_after(jiffies, orig_jiffies + 1693 if (timeout && time_after(jiffies, orig_jiffies +
@@ -1686,6 +1697,9 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
1686 } 1697 }
1687 /* Run one more char cycle */ 1698 /* Run one more char cycle */
1688 msleep_interruptible(jiffies_to_msecs(char_time * 5)); 1699 msleep_interruptible(jiffies_to_msecs(char_time * 5));
1700#ifdef CY_DEBUG_WAIT_UNTIL_SENT
1701 printk(KERN_DEBUG "Clean (jiff=%lu)...done\n", jiffies);
1702#endif
1689} 1703}
1690 1704
1691static void cy_flush_buffer(struct tty_struct *tty) 1705static void cy_flush_buffer(struct tty_struct *tty)
@@ -1999,11 +2013,14 @@ static void cy_set_line_char(struct cyclades_port *info, struct tty_struct *tty)
1999 int baud, baud_rate = 0; 2013 int baud, baud_rate = 0;
2000 int i; 2014 int i;
2001 2015
2016 if (!tty->termios) /* XXX can this happen at all? */
2017 return;
2018
2002 if (info->line == -1) 2019 if (info->line == -1)
2003 return; 2020 return;
2004 2021
2005 cflag = tty->termios.c_cflag; 2022 cflag = tty->termios->c_cflag;
2006 iflag = tty->termios.c_iflag; 2023 iflag = tty->termios->c_iflag;
2007 2024
2008 /* 2025 /*
2009 * Set up the tty->alt_speed kludge 2026 * Set up the tty->alt_speed kludge
@@ -2406,7 +2423,7 @@ static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value)
2406 /* Not supported yet */ 2423 /* Not supported yet */
2407 return -EINVAL; 2424 return -EINVAL;
2408 } 2425 }
2409 return put_user(result, value); 2426 return put_user(result, (unsigned long __user *)value);
2410} 2427}
2411 2428
2412static int cy_tiocmget(struct tty_struct *tty) 2429static int cy_tiocmget(struct tty_struct *tty)
@@ -2822,7 +2839,7 @@ static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2822 cy_set_line_char(info, tty); 2839 cy_set_line_char(info, tty);
2823 2840
2824 if ((old_termios->c_cflag & CRTSCTS) && 2841 if ((old_termios->c_cflag & CRTSCTS) &&
2825 !(tty->termios.c_cflag & CRTSCTS)) { 2842 !(tty->termios->c_cflag & CRTSCTS)) {
2826 tty->hw_stopped = 0; 2843 tty->hw_stopped = 0;
2827 cy_start(tty); 2844 cy_start(tty);
2828 } 2845 }
@@ -2834,7 +2851,7 @@ static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2834 * or not. Hence, this may change..... 2851 * or not. Hence, this may change.....
2835 */ 2852 */
2836 if (!(old_termios->c_cflag & CLOCAL) && 2853 if (!(old_termios->c_cflag & CLOCAL) &&
2837 (tty->termios.c_cflag & CLOCAL)) 2854 (tty->termios->c_cflag & CLOCAL))
2838 wake_up_interruptible(&info->port.open_wait); 2855 wake_up_interruptible(&info->port.open_wait);
2839#endif 2856#endif
2840} /* cy_set_termios */ 2857} /* cy_set_termios */
@@ -2896,7 +2913,7 @@ static void cy_throttle(struct tty_struct *tty)
2896 info->throttle = 1; 2913 info->throttle = 1;
2897 } 2914 }
2898 2915
2899 if (tty->termios.c_cflag & CRTSCTS) { 2916 if (tty->termios->c_cflag & CRTSCTS) {
2900 if (!cy_is_Z(card)) { 2917 if (!cy_is_Z(card)) {
2901 spin_lock_irqsave(&card->card_lock, flags); 2918 spin_lock_irqsave(&card->card_lock, flags);
2902 cyy_change_rts_dtr(info, 0, TIOCM_RTS); 2919 cyy_change_rts_dtr(info, 0, TIOCM_RTS);
@@ -2935,7 +2952,7 @@ static void cy_unthrottle(struct tty_struct *tty)
2935 cy_send_xchar(tty, START_CHAR(tty)); 2952 cy_send_xchar(tty, START_CHAR(tty));
2936 } 2953 }
2937 2954
2938 if (tty->termios.c_cflag & CRTSCTS) { 2955 if (tty->termios->c_cflag & CRTSCTS) {
2939 card = info->card; 2956 card = info->card;
2940 if (!cy_is_Z(card)) { 2957 if (!cy_is_Z(card)) {
2941 spin_lock_irqsave(&card->card_lock, flags); 2958 spin_lock_irqsave(&card->card_lock, flags);
@@ -3099,7 +3116,7 @@ static const struct tty_port_operations cyz_port_ops = {
3099 * --------------------------------------------------------------------- 3116 * ---------------------------------------------------------------------
3100 */ 3117 */
3101 3118
3102static int cy_init_card(struct cyclades_card *cinfo) 3119static int __devinit cy_init_card(struct cyclades_card *cinfo)
3103{ 3120{
3104 struct cyclades_port *info; 3121 struct cyclades_port *info;
3105 unsigned int channel, port; 3122 unsigned int channel, port;
@@ -3196,7 +3213,7 @@ static int cy_init_card(struct cyclades_card *cinfo)
3196 3213
3197/* initialize chips on Cyclom-Y card -- return number of valid 3214/* initialize chips on Cyclom-Y card -- return number of valid
3198 chips (which is number of ports/4) */ 3215 chips (which is number of ports/4) */
3199static unsigned short cyy_init_card(void __iomem *true_base_addr, 3216static unsigned short __devinit cyy_init_card(void __iomem *true_base_addr,
3200 int index) 3217 int index)
3201{ 3218{
3202 unsigned int chip_number; 3219 unsigned int chip_number;
@@ -3286,10 +3303,9 @@ static unsigned short cyy_init_card(void __iomem *true_base_addr,
3286static int __init cy_detect_isa(void) 3303static int __init cy_detect_isa(void)
3287{ 3304{
3288#ifdef CONFIG_ISA 3305#ifdef CONFIG_ISA
3289 struct cyclades_card *card;
3290 unsigned short cy_isa_irq, nboard; 3306 unsigned short cy_isa_irq, nboard;
3291 void __iomem *cy_isa_address; 3307 void __iomem *cy_isa_address;
3292 unsigned short i, j, k, cy_isa_nchan; 3308 unsigned short i, j, cy_isa_nchan;
3293 int isparam = 0; 3309 int isparam = 0;
3294 3310
3295 nboard = 0; 3311 nboard = 0;
@@ -3347,8 +3363,7 @@ static int __init cy_detect_isa(void)
3347 } 3363 }
3348 /* fill the next cy_card structure available */ 3364 /* fill the next cy_card structure available */
3349 for (j = 0; j < NR_CARDS; j++) { 3365 for (j = 0; j < NR_CARDS; j++) {
3350 card = &cy_card[j]; 3366 if (cy_card[j].base_addr == NULL)
3351 if (card->base_addr == NULL)
3352 break; 3367 break;
3353 } 3368 }
3354 if (j == NR_CARDS) { /* no more cy_cards available */ 3369 if (j == NR_CARDS) { /* no more cy_cards available */
@@ -3362,7 +3377,7 @@ static int __init cy_detect_isa(void)
3362 3377
3363 /* allocate IRQ */ 3378 /* allocate IRQ */
3364 if (request_irq(cy_isa_irq, cyy_interrupt, 3379 if (request_irq(cy_isa_irq, cyy_interrupt,
3365 0, "Cyclom-Y", card)) { 3380 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) {
3366 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but " 3381 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but "
3367 "could not allocate IRQ#%d.\n", 3382 "could not allocate IRQ#%d.\n",
3368 (unsigned long)cy_isa_address, cy_isa_irq); 3383 (unsigned long)cy_isa_address, cy_isa_irq);
@@ -3371,16 +3386,16 @@ static int __init cy_detect_isa(void)
3371 } 3386 }
3372 3387
3373 /* set cy_card */ 3388 /* set cy_card */
3374 card->base_addr = cy_isa_address; 3389 cy_card[j].base_addr = cy_isa_address;
3375 card->ctl_addr.p9050 = NULL; 3390 cy_card[j].ctl_addr.p9050 = NULL;
3376 card->irq = (int)cy_isa_irq; 3391 cy_card[j].irq = (int)cy_isa_irq;
3377 card->bus_index = 0; 3392 cy_card[j].bus_index = 0;
3378 card->first_line = cy_next_channel; 3393 cy_card[j].first_line = cy_next_channel;
3379 card->num_chips = cy_isa_nchan / CyPORTS_PER_CHIP; 3394 cy_card[j].num_chips = cy_isa_nchan / CyPORTS_PER_CHIP;
3380 card->nports = cy_isa_nchan; 3395 cy_card[j].nports = cy_isa_nchan;
3381 if (cy_init_card(card)) { 3396 if (cy_init_card(&cy_card[j])) {
3382 card->base_addr = NULL; 3397 cy_card[j].base_addr = NULL;
3383 free_irq(cy_isa_irq, card); 3398 free_irq(cy_isa_irq, &cy_card[j]);
3384 iounmap(cy_isa_address); 3399 iounmap(cy_isa_address);
3385 continue; 3400 continue;
3386 } 3401 }
@@ -3392,10 +3407,9 @@ static int __init cy_detect_isa(void)
3392 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)), 3407 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
3393 cy_isa_irq, cy_isa_nchan, cy_next_channel); 3408 cy_isa_irq, cy_isa_nchan, cy_next_channel);
3394 3409
3395 for (k = 0, j = cy_next_channel; 3410 for (j = cy_next_channel;
3396 j < cy_next_channel + cy_isa_nchan; j++, k++) 3411 j < cy_next_channel + cy_isa_nchan; j++)
3397 tty_port_register_device(&card->ports[k].port, 3412 tty_register_device(cy_serial_driver, j, NULL);
3398 cy_serial_driver, j, NULL);
3399 cy_next_channel += cy_isa_nchan; 3413 cy_next_channel += cy_isa_nchan;
3400 } 3414 }
3401 return nboard; 3415 return nboard;
@@ -3405,7 +3419,7 @@ static int __init cy_detect_isa(void)
3405} /* cy_detect_isa */ 3419} /* cy_detect_isa */
3406 3420
3407#ifdef CONFIG_PCI 3421#ifdef CONFIG_PCI
3408static inline int cyc_isfwstr(const char *str, unsigned int size) 3422static inline int __devinit cyc_isfwstr(const char *str, unsigned int size)
3409{ 3423{
3410 unsigned int a; 3424 unsigned int a;
3411 3425
@@ -3420,7 +3434,7 @@ static inline int cyc_isfwstr(const char *str, unsigned int size)
3420 return 0; 3434 return 0;
3421} 3435}
3422 3436
3423static inline void cyz_fpga_copy(void __iomem *fpga, const u8 *data, 3437static inline void __devinit cyz_fpga_copy(void __iomem *fpga, const u8 *data,
3424 unsigned int size) 3438 unsigned int size)
3425{ 3439{
3426 for (; size > 0; size--) { 3440 for (; size > 0; size--) {
@@ -3429,7 +3443,7 @@ static inline void cyz_fpga_copy(void __iomem *fpga, const u8 *data,
3429 } 3443 }
3430} 3444}
3431 3445
3432static void plx_init(struct pci_dev *pdev, int irq, 3446static void __devinit plx_init(struct pci_dev *pdev, int irq,
3433 struct RUNTIME_9060 __iomem *addr) 3447 struct RUNTIME_9060 __iomem *addr)
3434{ 3448{
3435 /* Reset PLX */ 3449 /* Reset PLX */
@@ -3449,7 +3463,7 @@ static void plx_init(struct pci_dev *pdev, int irq,
3449 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, irq); 3463 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, irq);
3450} 3464}
3451 3465
3452static int __cyz_load_fw(const struct firmware *fw, 3466static int __devinit __cyz_load_fw(const struct firmware *fw,
3453 const char *name, const u32 mailbox, void __iomem *base, 3467 const char *name, const u32 mailbox, void __iomem *base,
3454 void __iomem *fpga) 3468 void __iomem *fpga)
3455{ 3469{
@@ -3526,7 +3540,7 @@ static int __cyz_load_fw(const struct firmware *fw,
3526 return 0; 3540 return 0;
3527} 3541}
3528 3542
3529static int cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr, 3543static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
3530 struct RUNTIME_9060 __iomem *ctl_addr, int irq) 3544 struct RUNTIME_9060 __iomem *ctl_addr, int irq)
3531{ 3545{
3532 const struct firmware *fw; 3546 const struct firmware *fw;
@@ -3692,14 +3706,13 @@ err:
3692 return retval; 3706 return retval;
3693} 3707}
3694 3708
3695static int cy_pci_probe(struct pci_dev *pdev, 3709static int __devinit cy_pci_probe(struct pci_dev *pdev,
3696 const struct pci_device_id *ent) 3710 const struct pci_device_id *ent)
3697{ 3711{
3698 struct cyclades_card *card;
3699 void __iomem *addr0 = NULL, *addr2 = NULL; 3712 void __iomem *addr0 = NULL, *addr2 = NULL;
3700 char *card_name = NULL; 3713 char *card_name = NULL;
3701 u32 uninitialized_var(mailbox); 3714 u32 uninitialized_var(mailbox);
3702 unsigned int device_id, nchan = 0, card_no, i, j; 3715 unsigned int device_id, nchan = 0, card_no, i;
3703 unsigned char plx_ver; 3716 unsigned char plx_ver;
3704 int retval, irq; 3717 int retval, irq;
3705 3718
@@ -3830,8 +3843,7 @@ static int cy_pci_probe(struct pci_dev *pdev,
3830 } 3843 }
3831 /* fill the next cy_card structure available */ 3844 /* fill the next cy_card structure available */
3832 for (card_no = 0; card_no < NR_CARDS; card_no++) { 3845 for (card_no = 0; card_no < NR_CARDS; card_no++) {
3833 card = &cy_card[card_no]; 3846 if (cy_card[card_no].base_addr == NULL)
3834 if (card->base_addr == NULL)
3835 break; 3847 break;
3836 } 3848 }
3837 if (card_no == NR_CARDS) { /* no more cy_cards available */ 3849 if (card_no == NR_CARDS) { /* no more cy_cards available */
@@ -3845,26 +3857,27 @@ static int cy_pci_probe(struct pci_dev *pdev,
3845 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) { 3857 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
3846 /* allocate IRQ */ 3858 /* allocate IRQ */
3847 retval = request_irq(irq, cyy_interrupt, 3859 retval = request_irq(irq, cyy_interrupt,
3848 IRQF_SHARED, "Cyclom-Y", card); 3860 IRQF_SHARED, "Cyclom-Y", &cy_card[card_no]);
3849 if (retval) { 3861 if (retval) {
3850 dev_err(&pdev->dev, "could not allocate IRQ\n"); 3862 dev_err(&pdev->dev, "could not allocate IRQ\n");
3851 goto err_unmap; 3863 goto err_unmap;
3852 } 3864 }
3853 card->num_chips = nchan / CyPORTS_PER_CHIP; 3865 cy_card[card_no].num_chips = nchan / CyPORTS_PER_CHIP;
3854 } else { 3866 } else {
3855 struct FIRM_ID __iomem *firm_id = addr2 + ID_ADDRESS; 3867 struct FIRM_ID __iomem *firm_id = addr2 + ID_ADDRESS;
3856 struct ZFW_CTRL __iomem *zfw_ctrl; 3868 struct ZFW_CTRL __iomem *zfw_ctrl;
3857 3869
3858 zfw_ctrl = addr2 + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3870 zfw_ctrl = addr2 + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3859 3871
3860 card->hw_ver = mailbox; 3872 cy_card[card_no].hw_ver = mailbox;
3861 card->num_chips = (unsigned int)-1; 3873 cy_card[card_no].num_chips = (unsigned int)-1;
3862 card->board_ctrl = &zfw_ctrl->board_ctrl; 3874 cy_card[card_no].board_ctrl = &zfw_ctrl->board_ctrl;
3863#ifdef CONFIG_CYZ_INTR 3875#ifdef CONFIG_CYZ_INTR
3864 /* allocate IRQ only if board has an IRQ */ 3876 /* allocate IRQ only if board has an IRQ */
3865 if (irq != 0 && irq != 255) { 3877 if (irq != 0 && irq != 255) {
3866 retval = request_irq(irq, cyz_interrupt, 3878 retval = request_irq(irq, cyz_interrupt,
3867 IRQF_SHARED, "Cyclades-Z", card); 3879 IRQF_SHARED, "Cyclades-Z",
3880 &cy_card[card_no]);
3868 if (retval) { 3881 if (retval) {
3869 dev_err(&pdev->dev, "could not allocate IRQ\n"); 3882 dev_err(&pdev->dev, "could not allocate IRQ\n");
3870 goto err_unmap; 3883 goto err_unmap;
@@ -3874,17 +3887,17 @@ static int cy_pci_probe(struct pci_dev *pdev,
3874 } 3887 }
3875 3888
3876 /* set cy_card */ 3889 /* set cy_card */
3877 card->base_addr = addr2; 3890 cy_card[card_no].base_addr = addr2;
3878 card->ctl_addr.p9050 = addr0; 3891 cy_card[card_no].ctl_addr.p9050 = addr0;
3879 card->irq = irq; 3892 cy_card[card_no].irq = irq;
3880 card->bus_index = 1; 3893 cy_card[card_no].bus_index = 1;
3881 card->first_line = cy_next_channel; 3894 cy_card[card_no].first_line = cy_next_channel;
3882 card->nports = nchan; 3895 cy_card[card_no].nports = nchan;
3883 retval = cy_init_card(card); 3896 retval = cy_init_card(&cy_card[card_no]);
3884 if (retval) 3897 if (retval)
3885 goto err_null; 3898 goto err_null;
3886 3899
3887 pci_set_drvdata(pdev, card); 3900 pci_set_drvdata(pdev, &cy_card[card_no]);
3888 3901
3889 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo || 3902 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
3890 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) { 3903 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
@@ -3910,15 +3923,14 @@ static int cy_pci_probe(struct pci_dev *pdev,
3910 3923
3911 dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from " 3924 dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from "
3912 "port %d.\n", card_name, card_no + 1, nchan, cy_next_channel); 3925 "port %d.\n", card_name, card_no + 1, nchan, cy_next_channel);
3913 for (j = 0, i = cy_next_channel; i < cy_next_channel + nchan; i++, j++) 3926 for (i = cy_next_channel; i < cy_next_channel + nchan; i++)
3914 tty_port_register_device(&card->ports[j].port, 3927 tty_register_device(cy_serial_driver, i, &pdev->dev);
3915 cy_serial_driver, i, &pdev->dev);
3916 cy_next_channel += nchan; 3928 cy_next_channel += nchan;
3917 3929
3918 return 0; 3930 return 0;
3919err_null: 3931err_null:
3920 card->base_addr = NULL; 3932 cy_card[card_no].base_addr = NULL;
3921 free_irq(irq, card); 3933 free_irq(irq, &cy_card[card_no]);
3922err_unmap: 3934err_unmap:
3923 iounmap(addr0); 3935 iounmap(addr0);
3924 if (addr2) 3936 if (addr2)
@@ -3931,10 +3943,10 @@ err:
3931 return retval; 3943 return retval;
3932} 3944}
3933 3945
3934static void cy_pci_remove(struct pci_dev *pdev) 3946static void __devexit cy_pci_remove(struct pci_dev *pdev)
3935{ 3947{
3936 struct cyclades_card *cinfo = pci_get_drvdata(pdev); 3948 struct cyclades_card *cinfo = pci_get_drvdata(pdev);
3937 unsigned int i, channel; 3949 unsigned int i;
3938 3950
3939 /* non-Z with old PLX */ 3951 /* non-Z with old PLX */
3940 if (!cy_is_Z(cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) == 3952 if (!cy_is_Z(cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) ==
@@ -3960,11 +3972,9 @@ static void cy_pci_remove(struct pci_dev *pdev)
3960 pci_release_regions(pdev); 3972 pci_release_regions(pdev);
3961 3973
3962 cinfo->base_addr = NULL; 3974 cinfo->base_addr = NULL;
3963 for (channel = 0, i = cinfo->first_line; i < cinfo->first_line + 3975 for (i = cinfo->first_line; i < cinfo->first_line +
3964 cinfo->nports; i++, channel++) { 3976 cinfo->nports; i++)
3965 tty_unregister_device(cy_serial_driver, i); 3977 tty_unregister_device(cy_serial_driver, i);
3966 tty_port_destroy(&cinfo->ports[channel].port);
3967 }
3968 cinfo->nports = 0; 3978 cinfo->nports = 0;
3969 kfree(cinfo->ports); 3979 kfree(cinfo->ports);
3970} 3980}
@@ -3973,7 +3983,7 @@ static struct pci_driver cy_pci_driver = {
3973 .name = "cyclades", 3983 .name = "cyclades",
3974 .id_table = cy_pci_dev_id, 3984 .id_table = cy_pci_dev_id,
3975 .probe = cy_pci_probe, 3985 .probe = cy_pci_probe,
3976 .remove = cy_pci_remove 3986 .remove = __devexit_p(cy_pci_remove)
3977}; 3987};
3978#endif 3988#endif
3979 3989
@@ -4090,6 +4100,7 @@ static int __init cy_init(void)
4090 4100
4091 /* Initialize the tty_driver structure */ 4101 /* Initialize the tty_driver structure */
4092 4102
4103 cy_serial_driver->owner = THIS_MODULE;
4093 cy_serial_driver->driver_name = "cyclades"; 4104 cy_serial_driver->driver_name = "cyclades";
4094 cy_serial_driver->name = "ttyC"; 4105 cy_serial_driver->name = "ttyC";
4095 cy_serial_driver->major = CYCLADES_MAJOR; 4106 cy_serial_driver->major = CYCLADES_MAJOR;
diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
deleted file mode 100644
index c117d775a22..00000000000
--- a/drivers/tty/ehv_bytechan.c
+++ /dev/null
@@ -1,883 +0,0 @@
1/* ePAPR hypervisor byte channel device driver
2 *
3 * Copyright 2009-2011 Freescale Semiconductor, Inc.
4 *
5 * Author: Timur Tabi <timur@freescale.com>
6 *
7 * This file is licensed under the terms of the GNU General Public License
8 * version 2. This program is licensed "as is" without any warranty of any
9 * kind, whether express or implied.
10 *
11 * This driver support three distinct interfaces, all of which are related to
12 * ePAPR hypervisor byte channels.
13 *
14 * 1) An early-console (udbg) driver. This provides early console output
15 * through a byte channel. The byte channel handle must be specified in a
16 * Kconfig option.
17 *
18 * 2) A normal console driver. Output is sent to the byte channel designated
19 * for stdout in the device tree. The console driver is for handling kernel
20 * printk calls.
21 *
22 * 3) A tty driver, which is used to handle user-space input and output. The
23 * byte channel used for the console is designated as the default tty.
24 */
25
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/err.h>
30#include <linux/interrupt.h>
31#include <linux/fs.h>
32#include <linux/poll.h>
33#include <asm/epapr_hcalls.h>
34#include <linux/of.h>
35#include <linux/platform_device.h>
36#include <linux/cdev.h>
37#include <linux/console.h>
38#include <linux/tty.h>
39#include <linux/tty_flip.h>
40#include <linux/circ_buf.h>
41#include <asm/udbg.h>
42
43/* The size of the transmit circular buffer. This must be a power of two. */
44#define BUF_SIZE 2048
45
46/* Per-byte channel private data */
47struct ehv_bc_data {
48 struct device *dev;
49 struct tty_port port;
50 uint32_t handle;
51 unsigned int rx_irq;
52 unsigned int tx_irq;
53
54 spinlock_t lock; /* lock for transmit buffer */
55 unsigned char buf[BUF_SIZE]; /* transmit circular buffer */
56 unsigned int head; /* circular buffer head */
57 unsigned int tail; /* circular buffer tail */
58
59 int tx_irq_enabled; /* true == TX interrupt is enabled */
60};
61
62/* Array of byte channel objects */
63static struct ehv_bc_data *bcs;
64
65/* Byte channel handle for stdout (and stdin), taken from device tree */
66static unsigned int stdout_bc;
67
68/* Virtual IRQ for the byte channel handle for stdin, taken from device tree */
69static unsigned int stdout_irq;
70
71/**************************** SUPPORT FUNCTIONS ****************************/
72
73/*
74 * Enable the transmit interrupt
75 *
76 * Unlike a serial device, byte channels have no mechanism for disabling their
77 * own receive or transmit interrupts. To emulate that feature, we toggle
78 * the IRQ in the kernel.
79 *
80 * We cannot just blindly call enable_irq() or disable_irq(), because these
81 * calls are reference counted. This means that we cannot call enable_irq()
82 * if interrupts are already enabled. This can happen in two situations:
83 *
84 * 1. The tty layer makes two back-to-back calls to ehv_bc_tty_write()
85 * 2. A transmit interrupt occurs while executing ehv_bc_tx_dequeue()
86 *
87 * To work around this, we keep a flag to tell us if the IRQ is enabled or not.
88 */
89static void enable_tx_interrupt(struct ehv_bc_data *bc)
90{
91 if (!bc->tx_irq_enabled) {
92 enable_irq(bc->tx_irq);
93 bc->tx_irq_enabled = 1;
94 }
95}
96
97static void disable_tx_interrupt(struct ehv_bc_data *bc)
98{
99 if (bc->tx_irq_enabled) {
100 disable_irq_nosync(bc->tx_irq);
101 bc->tx_irq_enabled = 0;
102 }
103}
104
105/*
106 * find the byte channel handle to use for the console
107 *
108 * The byte channel to be used for the console is specified via a "stdout"
109 * property in the /chosen node.
110 *
111 * For compatible with legacy device trees, we also look for a "stdout" alias.
112 */
113static int find_console_handle(void)
114{
115 struct device_node *np, *np2;
116 const char *sprop = NULL;
117 const uint32_t *iprop;
118
119 np = of_find_node_by_path("/chosen");
120 if (np)
121 sprop = of_get_property(np, "stdout-path", NULL);
122
123 if (!np || !sprop) {
124 of_node_put(np);
125 np = of_find_node_by_name(NULL, "aliases");
126 if (np)
127 sprop = of_get_property(np, "stdout", NULL);
128 }
129
130 if (!sprop) {
131 of_node_put(np);
132 return 0;
133 }
134
135 /* We don't care what the aliased node is actually called. We only
136 * care if it's compatible with "epapr,hv-byte-channel", because that
137 * indicates that it's a byte channel node. We use a temporary
138 * variable, 'np2', because we can't release 'np' until we're done with
139 * 'sprop'.
140 */
141 np2 = of_find_node_by_path(sprop);
142 of_node_put(np);
143 np = np2;
144 if (!np) {
145 pr_warning("ehv-bc: stdout node '%s' does not exist\n", sprop);
146 return 0;
147 }
148
149 /* Is it a byte channel? */
150 if (!of_device_is_compatible(np, "epapr,hv-byte-channel")) {
151 of_node_put(np);
152 return 0;
153 }
154
155 stdout_irq = irq_of_parse_and_map(np, 0);
156 if (stdout_irq == NO_IRQ) {
157 pr_err("ehv-bc: no 'interrupts' property in %s node\n", sprop);
158 of_node_put(np);
159 return 0;
160 }
161
162 /*
163 * The 'hv-handle' property contains the handle for this byte channel.
164 */
165 iprop = of_get_property(np, "hv-handle", NULL);
166 if (!iprop) {
167 pr_err("ehv-bc: no 'hv-handle' property in %s node\n",
168 np->name);
169 of_node_put(np);
170 return 0;
171 }
172 stdout_bc = be32_to_cpu(*iprop);
173
174 of_node_put(np);
175 return 1;
176}
177
178/*************************** EARLY CONSOLE DRIVER ***************************/
179
180#ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC
181
182/*
183 * send a byte to a byte channel, wait if necessary
184 *
185 * This function sends a byte to a byte channel, and it waits and
186 * retries if the byte channel is full. It returns if the character
187 * has been sent, or if some error has occurred.
188 *
189 */
190static void byte_channel_spin_send(const char data)
191{
192 int ret, count;
193
194 do {
195 count = 1;
196 ret = ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE,
197 &count, &data);
198 } while (ret == EV_EAGAIN);
199}
200
201/*
202 * The udbg subsystem calls this function to display a single character.
203 * We convert CR to a CR/LF.
204 */
205static void ehv_bc_udbg_putc(char c)
206{
207 if (c == '\n')
208 byte_channel_spin_send('\r');
209
210 byte_channel_spin_send(c);
211}
212
213/*
214 * early console initialization
215 *
216 * PowerPC kernels support an early printk console, also known as udbg.
217 * This function must be called via the ppc_md.init_early function pointer.
218 * At this point, the device tree has been unflattened, so we can obtain the
219 * byte channel handle for stdout.
220 *
221 * We only support displaying of characters (putc). We do not support
222 * keyboard input.
223 */
224void __init udbg_init_ehv_bc(void)
225{
226 unsigned int rx_count, tx_count;
227 unsigned int ret;
228
229 /* Verify the byte channel handle */
230 ret = ev_byte_channel_poll(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE,
231 &rx_count, &tx_count);
232 if (ret)
233 return;
234
235 udbg_putc = ehv_bc_udbg_putc;
236 register_early_udbg_console();
237
238 udbg_printf("ehv-bc: early console using byte channel handle %u\n",
239 CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE);
240}
241
242#endif
243
244/****************************** CONSOLE DRIVER ******************************/
245
246static struct tty_driver *ehv_bc_driver;
247
248/*
249 * Byte channel console sending worker function.
250 *
251 * For consoles, if the output buffer is full, we should just spin until it
252 * clears.
253 */
254static int ehv_bc_console_byte_channel_send(unsigned int handle, const char *s,
255 unsigned int count)
256{
257 unsigned int len;
258 int ret = 0;
259
260 while (count) {
261 len = min_t(unsigned int, count, EV_BYTE_CHANNEL_MAX_BYTES);
262 do {
263 ret = ev_byte_channel_send(handle, &len, s);
264 } while (ret == EV_EAGAIN);
265 count -= len;
266 s += len;
267 }
268
269 return ret;
270}
271
272/*
273 * write a string to the console
274 *
275 * This function gets called to write a string from the kernel, typically from
276 * a printk(). This function spins until all data is written.
277 *
278 * We copy the data to a temporary buffer because we need to insert a \r in
279 * front of every \n. It's more efficient to copy the data to the buffer than
280 * it is to make multiple hcalls for each character or each newline.
281 */
282static void ehv_bc_console_write(struct console *co, const char *s,
283 unsigned int count)
284{
285 char s2[EV_BYTE_CHANNEL_MAX_BYTES];
286 unsigned int i, j = 0;
287 char c;
288
289 for (i = 0; i < count; i++) {
290 c = *s++;
291
292 if (c == '\n')
293 s2[j++] = '\r';
294
295 s2[j++] = c;
296 if (j >= (EV_BYTE_CHANNEL_MAX_BYTES - 1)) {
297 if (ehv_bc_console_byte_channel_send(stdout_bc, s2, j))
298 return;
299 j = 0;
300 }
301 }
302
303 if (j)
304 ehv_bc_console_byte_channel_send(stdout_bc, s2, j);
305}
306
307/*
308 * When /dev/console is opened, the kernel iterates the console list looking
309 * for one with ->device and then calls that method. On success, it expects
310 * the passed-in int* to contain the minor number to use.
311 */
312static struct tty_driver *ehv_bc_console_device(struct console *co, int *index)
313{
314 *index = co->index;
315
316 return ehv_bc_driver;
317}
318
319static struct console ehv_bc_console = {
320 .name = "ttyEHV",
321 .write = ehv_bc_console_write,
322 .device = ehv_bc_console_device,
323 .flags = CON_PRINTBUFFER | CON_ENABLED,
324};
325
326/*
327 * Console initialization
328 *
329 * This is the first function that is called after the device tree is
330 * available, so here is where we determine the byte channel handle and IRQ for
331 * stdout/stdin, even though that information is used by the tty and character
332 * drivers.
333 */
334static int __init ehv_bc_console_init(void)
335{
336 if (!find_console_handle()) {
337 pr_debug("ehv-bc: stdout is not a byte channel\n");
338 return -ENODEV;
339 }
340
341#ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC
342 /* Print a friendly warning if the user chose the wrong byte channel
343 * handle for udbg.
344 */
345 if (stdout_bc != CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE)
346 pr_warning("ehv-bc: udbg handle %u is not the stdout handle\n",
347 CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE);
348#endif
349
350 /* add_preferred_console() must be called before register_console(),
351 otherwise it won't work. However, we don't want to enumerate all the
352 byte channels here, either, since we only care about one. */
353
354 add_preferred_console(ehv_bc_console.name, ehv_bc_console.index, NULL);
355 register_console(&ehv_bc_console);
356
357 pr_info("ehv-bc: registered console driver for byte channel %u\n",
358 stdout_bc);
359
360 return 0;
361}
362console_initcall(ehv_bc_console_init);
363
364/******************************** TTY DRIVER ********************************/
365
366/*
367 * byte channel receive interupt handler
368 *
369 * This ISR is called whenever data is available on a byte channel.
370 */
371static irqreturn_t ehv_bc_tty_rx_isr(int irq, void *data)
372{
373 struct ehv_bc_data *bc = data;
374 struct tty_struct *ttys = tty_port_tty_get(&bc->port);
375 unsigned int rx_count, tx_count, len;
376 int count;
377 char buffer[EV_BYTE_CHANNEL_MAX_BYTES];
378 int ret;
379
380 /* ttys could be NULL during a hangup */
381 if (!ttys)
382 return IRQ_HANDLED;
383
384 /* Find out how much data needs to be read, and then ask the TTY layer
385 * if it can handle that much. We want to ensure that every byte we
386 * read from the byte channel will be accepted by the TTY layer.
387 */
388 ev_byte_channel_poll(bc->handle, &rx_count, &tx_count);
389 count = tty_buffer_request_room(ttys, rx_count);
390
391 /* 'count' is the maximum amount of data the TTY layer can accept at
392 * this time. However, during testing, I was never able to get 'count'
393 * to be less than 'rx_count'. I'm not sure whether I'm calling it
394 * correctly.
395 */
396
397 while (count > 0) {
398 len = min_t(unsigned int, count, sizeof(buffer));
399
400 /* Read some data from the byte channel. This function will
401 * never return more than EV_BYTE_CHANNEL_MAX_BYTES bytes.
402 */
403 ev_byte_channel_receive(bc->handle, &len, buffer);
404
405 /* 'len' is now the amount of data that's been received. 'len'
406 * can't be zero, and most likely it's equal to one.
407 */
408
409 /* Pass the received data to the tty layer. */
410 ret = tty_insert_flip_string(ttys, buffer, len);
411
412 /* 'ret' is the number of bytes that the TTY layer accepted.
413 * If it's not equal to 'len', then it means the buffer is
414 * full, which should never happen. If it does happen, we can
415 * exit gracefully, but we drop the last 'len - ret' characters
416 * that we read from the byte channel.
417 */
418 if (ret != len)
419 break;
420
421 count -= len;
422 }
423
424 /* Tell the tty layer that we're done. */
425 tty_flip_buffer_push(ttys);
426
427 tty_kref_put(ttys);
428
429 return IRQ_HANDLED;
430}
431
432/*
433 * dequeue the transmit buffer to the hypervisor
434 *
435 * This function, which can be called in interrupt context, dequeues as much
436 * data as possible from the transmit buffer to the byte channel.
437 */
438static void ehv_bc_tx_dequeue(struct ehv_bc_data *bc)
439{
440 unsigned int count;
441 unsigned int len, ret;
442 unsigned long flags;
443
444 do {
445 spin_lock_irqsave(&bc->lock, flags);
446 len = min_t(unsigned int,
447 CIRC_CNT_TO_END(bc->head, bc->tail, BUF_SIZE),
448 EV_BYTE_CHANNEL_MAX_BYTES);
449
450 ret = ev_byte_channel_send(bc->handle, &len, bc->buf + bc->tail);
451
452 /* 'len' is valid only if the return code is 0 or EV_EAGAIN */
453 if (!ret || (ret == EV_EAGAIN))
454 bc->tail = (bc->tail + len) & (BUF_SIZE - 1);
455
456 count = CIRC_CNT(bc->head, bc->tail, BUF_SIZE);
457 spin_unlock_irqrestore(&bc->lock, flags);
458 } while (count && !ret);
459
460 spin_lock_irqsave(&bc->lock, flags);
461 if (CIRC_CNT(bc->head, bc->tail, BUF_SIZE))
462 /*
463 * If we haven't emptied the buffer, then enable the TX IRQ.
464 * We'll get an interrupt when there's more room in the
465 * hypervisor's output buffer.
466 */
467 enable_tx_interrupt(bc);
468 else
469 disable_tx_interrupt(bc);
470 spin_unlock_irqrestore(&bc->lock, flags);
471}
472
473/*
474 * byte channel transmit interupt handler
475 *
476 * This ISR is called whenever space becomes available for transmitting
477 * characters on a byte channel.
478 */
479static irqreturn_t ehv_bc_tty_tx_isr(int irq, void *data)
480{
481 struct ehv_bc_data *bc = data;
482 struct tty_struct *ttys = tty_port_tty_get(&bc->port);
483
484 ehv_bc_tx_dequeue(bc);
485 if (ttys) {
486 tty_wakeup(ttys);
487 tty_kref_put(ttys);
488 }
489
490 return IRQ_HANDLED;
491}
492
493/*
494 * This function is called when the tty layer has data for us send. We store
495 * the data first in a circular buffer, and then dequeue as much of that data
496 * as possible.
497 *
498 * We don't need to worry about whether there is enough room in the buffer for
499 * all the data. The purpose of ehv_bc_tty_write_room() is to tell the tty
500 * layer how much data it can safely send to us. We guarantee that
501 * ehv_bc_tty_write_room() will never lie, so the tty layer will never send us
502 * too much data.
503 */
504static int ehv_bc_tty_write(struct tty_struct *ttys, const unsigned char *s,
505 int count)
506{
507 struct ehv_bc_data *bc = ttys->driver_data;
508 unsigned long flags;
509 unsigned int len;
510 unsigned int written = 0;
511
512 while (1) {
513 spin_lock_irqsave(&bc->lock, flags);
514 len = CIRC_SPACE_TO_END(bc->head, bc->tail, BUF_SIZE);
515 if (count < len)
516 len = count;
517 if (len) {
518 memcpy(bc->buf + bc->head, s, len);
519 bc->head = (bc->head + len) & (BUF_SIZE - 1);
520 }
521 spin_unlock_irqrestore(&bc->lock, flags);
522 if (!len)
523 break;
524
525 s += len;
526 count -= len;
527 written += len;
528 }
529
530 ehv_bc_tx_dequeue(bc);
531
532 return written;
533}
534
535/*
536 * This function can be called multiple times for a given tty_struct, which is
537 * why we initialize bc->ttys in ehv_bc_tty_port_activate() instead.
538 *
539 * The tty layer will still call this function even if the device was not
540 * registered (i.e. tty_register_device() was not called). This happens
541 * because tty_register_device() is optional and some legacy drivers don't
542 * use it. So we need to check for that.
543 */
544static int ehv_bc_tty_open(struct tty_struct *ttys, struct file *filp)
545{
546 struct ehv_bc_data *bc = &bcs[ttys->index];
547
548 if (!bc->dev)
549 return -ENODEV;
550
551 return tty_port_open(&bc->port, ttys, filp);
552}
553
554/*
555 * Amazingly, if ehv_bc_tty_open() returns an error code, the tty layer will
556 * still call this function to close the tty device. So we can't assume that
557 * the tty port has been initialized.
558 */
559static void ehv_bc_tty_close(struct tty_struct *ttys, struct file *filp)
560{
561 struct ehv_bc_data *bc = &bcs[ttys->index];
562
563 if (bc->dev)
564 tty_port_close(&bc->port, ttys, filp);
565}
566
567/*
568 * Return the amount of space in the output buffer
569 *
570 * This is actually a contract between the driver and the tty layer outlining
571 * how much write room the driver can guarantee will be sent OR BUFFERED. This
572 * driver MUST honor the return value.
573 */
574static int ehv_bc_tty_write_room(struct tty_struct *ttys)
575{
576 struct ehv_bc_data *bc = ttys->driver_data;
577 unsigned long flags;
578 int count;
579
580 spin_lock_irqsave(&bc->lock, flags);
581 count = CIRC_SPACE(bc->head, bc->tail, BUF_SIZE);
582 spin_unlock_irqrestore(&bc->lock, flags);
583
584 return count;
585}
586
587/*
588 * Stop sending data to the tty layer
589 *
590 * This function is called when the tty layer's input buffers are getting full,
591 * so the driver should stop sending it data. The easiest way to do this is to
592 * disable the RX IRQ, which will prevent ehv_bc_tty_rx_isr() from being
593 * called.
594 *
595 * The hypervisor will continue to queue up any incoming data. If there is any
596 * data in the queue when the RX interrupt is enabled, we'll immediately get an
597 * RX interrupt.
598 */
599static void ehv_bc_tty_throttle(struct tty_struct *ttys)
600{
601 struct ehv_bc_data *bc = ttys->driver_data;
602
603 disable_irq(bc->rx_irq);
604}
605
606/*
607 * Resume sending data to the tty layer
608 *
609 * This function is called after previously calling ehv_bc_tty_throttle(). The
610 * tty layer's input buffers now have more room, so the driver can resume
611 * sending it data.
612 */
613static void ehv_bc_tty_unthrottle(struct tty_struct *ttys)
614{
615 struct ehv_bc_data *bc = ttys->driver_data;
616
617 /* If there is any data in the queue when the RX interrupt is enabled,
618 * we'll immediately get an RX interrupt.
619 */
620 enable_irq(bc->rx_irq);
621}
622
623static void ehv_bc_tty_hangup(struct tty_struct *ttys)
624{
625 struct ehv_bc_data *bc = ttys->driver_data;
626
627 ehv_bc_tx_dequeue(bc);
628 tty_port_hangup(&bc->port);
629}
630
631/*
632 * TTY driver operations
633 *
634 * If we could ask the hypervisor how much data is still in the TX buffer, or
635 * at least how big the TX buffers are, then we could implement the
636 * .wait_until_sent and .chars_in_buffer functions.
637 */
638static const struct tty_operations ehv_bc_ops = {
639 .open = ehv_bc_tty_open,
640 .close = ehv_bc_tty_close,
641 .write = ehv_bc_tty_write,
642 .write_room = ehv_bc_tty_write_room,
643 .throttle = ehv_bc_tty_throttle,
644 .unthrottle = ehv_bc_tty_unthrottle,
645 .hangup = ehv_bc_tty_hangup,
646};
647
648/*
649 * initialize the TTY port
650 *
651 * This function will only be called once, no matter how many times
652 * ehv_bc_tty_open() is called. That's why we register the ISR here, and also
653 * why we initialize tty_struct-related variables here.
654 */
655static int ehv_bc_tty_port_activate(struct tty_port *port,
656 struct tty_struct *ttys)
657{
658 struct ehv_bc_data *bc = container_of(port, struct ehv_bc_data, port);
659 int ret;
660
661 ttys->driver_data = bc;
662
663 ret = request_irq(bc->rx_irq, ehv_bc_tty_rx_isr, 0, "ehv-bc", bc);
664 if (ret < 0) {
665 dev_err(bc->dev, "could not request rx irq %u (ret=%i)\n",
666 bc->rx_irq, ret);
667 return ret;
668 }
669
670 /* request_irq also enables the IRQ */
671 bc->tx_irq_enabled = 1;
672
673 ret = request_irq(bc->tx_irq, ehv_bc_tty_tx_isr, 0, "ehv-bc", bc);
674 if (ret < 0) {
675 dev_err(bc->dev, "could not request tx irq %u (ret=%i)\n",
676 bc->tx_irq, ret);
677 free_irq(bc->rx_irq, bc);
678 return ret;
679 }
680
681 /* The TX IRQ is enabled only when we can't write all the data to the
682 * byte channel at once, so by default it's disabled.
683 */
684 disable_tx_interrupt(bc);
685
686 return 0;
687}
688
689static void ehv_bc_tty_port_shutdown(struct tty_port *port)
690{
691 struct ehv_bc_data *bc = container_of(port, struct ehv_bc_data, port);
692
693 free_irq(bc->tx_irq, bc);
694 free_irq(bc->rx_irq, bc);
695}
696
697static const struct tty_port_operations ehv_bc_tty_port_ops = {
698 .activate = ehv_bc_tty_port_activate,
699 .shutdown = ehv_bc_tty_port_shutdown,
700};
701
702static int ehv_bc_tty_probe(struct platform_device *pdev)
703{
704 struct device_node *np = pdev->dev.of_node;
705 struct ehv_bc_data *bc;
706 const uint32_t *iprop;
707 unsigned int handle;
708 int ret;
709 static unsigned int index = 1;
710 unsigned int i;
711
712 iprop = of_get_property(np, "hv-handle", NULL);
713 if (!iprop) {
714 dev_err(&pdev->dev, "no 'hv-handle' property in %s node\n",
715 np->name);
716 return -ENODEV;
717 }
718
719 /* We already told the console layer that the index for the console
720 * device is zero, so we need to make sure that we use that index when
721 * we probe the console byte channel node.
722 */
723 handle = be32_to_cpu(*iprop);
724 i = (handle == stdout_bc) ? 0 : index++;
725 bc = &bcs[i];
726
727 bc->handle = handle;
728 bc->head = 0;
729 bc->tail = 0;
730 spin_lock_init(&bc->lock);
731
732 bc->rx_irq = irq_of_parse_and_map(np, 0);
733 bc->tx_irq = irq_of_parse_and_map(np, 1);
734 if ((bc->rx_irq == NO_IRQ) || (bc->tx_irq == NO_IRQ)) {
735 dev_err(&pdev->dev, "no 'interrupts' property in %s node\n",
736 np->name);
737 ret = -ENODEV;
738 goto error;
739 }
740
741 tty_port_init(&bc->port);
742 bc->port.ops = &ehv_bc_tty_port_ops;
743
744 bc->dev = tty_port_register_device(&bc->port, ehv_bc_driver, i,
745 &pdev->dev);
746 if (IS_ERR(bc->dev)) {
747 ret = PTR_ERR(bc->dev);
748 dev_err(&pdev->dev, "could not register tty (ret=%i)\n", ret);
749 goto error;
750 }
751
752 dev_set_drvdata(&pdev->dev, bc);
753
754 dev_info(&pdev->dev, "registered /dev/%s%u for byte channel %u\n",
755 ehv_bc_driver->name, i, bc->handle);
756
757 return 0;
758
759error:
760 tty_port_destroy(&bc->port);
761 irq_dispose_mapping(bc->tx_irq);
762 irq_dispose_mapping(bc->rx_irq);
763
764 memset(bc, 0, sizeof(struct ehv_bc_data));
765 return ret;
766}
767
768static int ehv_bc_tty_remove(struct platform_device *pdev)
769{
770 struct ehv_bc_data *bc = dev_get_drvdata(&pdev->dev);
771
772 tty_unregister_device(ehv_bc_driver, bc - bcs);
773
774 tty_port_destroy(&bc->port);
775 irq_dispose_mapping(bc->tx_irq);
776 irq_dispose_mapping(bc->rx_irq);
777
778 return 0;
779}
780
781static const struct of_device_id ehv_bc_tty_of_ids[] = {
782 { .compatible = "epapr,hv-byte-channel" },
783 {}
784};
785
786static struct platform_driver ehv_bc_tty_driver = {
787 .driver = {
788 .owner = THIS_MODULE,
789 .name = "ehv-bc",
790 .of_match_table = ehv_bc_tty_of_ids,
791 },
792 .probe = ehv_bc_tty_probe,
793 .remove = ehv_bc_tty_remove,
794};
795
796/**
797 * ehv_bc_init - ePAPR hypervisor byte channel driver initialization
798 *
799 * This function is called when this module is loaded.
800 */
801static int __init ehv_bc_init(void)
802{
803 struct device_node *np;
804 unsigned int count = 0; /* Number of elements in bcs[] */
805 int ret;
806
807 pr_info("ePAPR hypervisor byte channel driver\n");
808
809 /* Count the number of byte channels */
810 for_each_compatible_node(np, NULL, "epapr,hv-byte-channel")
811 count++;
812
813 if (!count)
814 return -ENODEV;
815
816 /* The array index of an element in bcs[] is the same as the tty index
817 * for that element. If you know the address of an element in the
818 * array, then you can use pointer math (e.g. "bc - bcs") to get its
819 * tty index.
820 */
821 bcs = kzalloc(count * sizeof(struct ehv_bc_data), GFP_KERNEL);
822 if (!bcs)
823 return -ENOMEM;
824
825 ehv_bc_driver = alloc_tty_driver(count);
826 if (!ehv_bc_driver) {
827 ret = -ENOMEM;
828 goto error;
829 }
830
831 ehv_bc_driver->driver_name = "ehv-bc";
832 ehv_bc_driver->name = ehv_bc_console.name;
833 ehv_bc_driver->type = TTY_DRIVER_TYPE_CONSOLE;
834 ehv_bc_driver->subtype = SYSTEM_TYPE_CONSOLE;
835 ehv_bc_driver->init_termios = tty_std_termios;
836 ehv_bc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
837 tty_set_operations(ehv_bc_driver, &ehv_bc_ops);
838
839 ret = tty_register_driver(ehv_bc_driver);
840 if (ret) {
841 pr_err("ehv-bc: could not register tty driver (ret=%i)\n", ret);
842 goto error;
843 }
844
845 ret = platform_driver_register(&ehv_bc_tty_driver);
846 if (ret) {
847 pr_err("ehv-bc: could not register platform driver (ret=%i)\n",
848 ret);
849 goto error;
850 }
851
852 return 0;
853
854error:
855 if (ehv_bc_driver) {
856 tty_unregister_driver(ehv_bc_driver);
857 put_tty_driver(ehv_bc_driver);
858 }
859
860 kfree(bcs);
861
862 return ret;
863}
864
865
866/**
867 * ehv_bc_exit - ePAPR hypervisor byte channel driver termination
868 *
869 * This function is called when this driver is unloaded.
870 */
871static void __exit ehv_bc_exit(void)
872{
873 tty_unregister_driver(ehv_bc_driver);
874 put_tty_driver(ehv_bc_driver);
875 kfree(bcs);
876}
877
878module_init(ehv_bc_init);
879module_exit(ehv_bc_exit);
880
881MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
882MODULE_DESCRIPTION("ePAPR hypervisor byte channel driver");
883MODULE_LICENSE("GPL v2");
diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index f47b734c6a7..e371753ba92 100644
--- a/drivers/tty/hvc/Kconfig
+++ b/drivers/tty/hvc/Kconfig
@@ -24,14 +24,15 @@ config HVC_OLD_HVSI
24 depends on HVC_CONSOLE 24 depends on HVC_CONSOLE
25 default n 25 default n
26 26
27config HVC_OPAL 27config HVC_ISERIES
28 bool "OPAL Console support" 28 bool "iSeries Hypervisor Virtual Console support"
29 depends on PPC_POWERNV 29 depends on PPC_ISERIES
30 default y
30 select HVC_DRIVER 31 select HVC_DRIVER
31 select HVC_IRQ 32 select HVC_IRQ
32 default y 33 select VIOPATH
33 help 34 help
34 PowerNV machines running under OPAL need that driver to get a console 35 iSeries machines support a hypervisor virtual console.
35 36
36config HVC_RTAS 37config HVC_RTAS
37 bool "IBM RTAS Console support" 38 bool "IBM RTAS Console support"
@@ -66,23 +67,11 @@ config HVC_XEN
66 help 67 help
67 Xen virtual console device driver 68 Xen virtual console device driver
68 69
69config HVC_XEN_FRONTEND
70 bool "Xen Hypervisor Multiple Consoles support"
71 depends on HVC_XEN
72 select XEN_XENBUS_FRONTEND
73 default y
74 help
75 Xen driver for secondary virtual consoles
76
77config HVC_UDBG 70config HVC_UDBG
78 bool "udbg based fake hypervisor console" 71 bool "udbg based fake hypervisor console"
79 depends on PPC 72 depends on PPC && EXPERIMENTAL
80 select HVC_DRIVER 73 select HVC_DRIVER
81 default n 74 default n
82 help
83 This is meant to be used during HW bring up or debugging when
84 no other console mechanism exist but udbg, to get you a quick
85 console for userspace. Do NOT enable in production kernels.
86 75
87config HVC_DCC 76config HVC_DCC
88 bool "ARM JTAG DCC console" 77 bool "ARM JTAG DCC console"
diff --git a/drivers/tty/hvc/Makefile b/drivers/tty/hvc/Makefile
index 4ca3723b0a3..e2920531637 100644
--- a/drivers/tty/hvc/Makefile
+++ b/drivers/tty/hvc/Makefile
@@ -1,6 +1,6 @@
1obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi_lib.o 1obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi_lib.o
2obj-$(CONFIG_HVC_OPAL) += hvc_opal.o hvsi_lib.o
3obj-$(CONFIG_HVC_OLD_HVSI) += hvsi.o 2obj-$(CONFIG_HVC_OLD_HVSI) += hvsi.o
3obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o
4obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o 4obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
5obj-$(CONFIG_HVC_TILE) += hvc_tile.o 5obj-$(CONFIG_HVC_TILE) += hvc_tile.o
6obj-$(CONFIG_HVC_DCC) += hvc_dcc.o 6obj-$(CONFIG_HVC_DCC) += hvc_dcc.o
diff --git a/drivers/tty/hvc/hvc_beat.c b/drivers/tty/hvc/hvc_beat.c
index 1560d235449..5fe4631e2a6 100644
--- a/drivers/tty/hvc/hvc_beat.c
+++ b/drivers/tty/hvc/hvc_beat.c
@@ -113,7 +113,7 @@ static int __init hvc_beat_init(void)
113 if (!firmware_has_feature(FW_FEATURE_BEAT)) 113 if (!firmware_has_feature(FW_FEATURE_BEAT))
114 return -ENODEV; 114 return -ENODEV;
115 115
116 hp = hvc_alloc(0, 0, &hvc_beat_get_put_ops, 16); 116 hp = hvc_alloc(0, NO_IRQ, &hvc_beat_get_put_ops, 16);
117 if (IS_ERR(hp)) 117 if (IS_ERR(hp))
118 return PTR_ERR(hp); 118 return PTR_ERR(hp);
119 hvc_beat_dev = hp; 119 hvc_beat_dev = hp;
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index 13ee53bd0bf..e1aaf4f309b 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -107,7 +107,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
107 list_for_each_entry(hp, &hvc_structs, next) { 107 list_for_each_entry(hp, &hvc_structs, next) {
108 spin_lock_irqsave(&hp->lock, flags); 108 spin_lock_irqsave(&hp->lock, flags);
109 if (hp->index == index) { 109 if (hp->index == index) {
110 tty_port_get(&hp->port); 110 kref_get(&hp->kref);
111 spin_unlock_irqrestore(&hp->lock, flags); 111 spin_unlock_irqrestore(&hp->lock, flags);
112 spin_unlock(&hvc_structs_lock); 112 spin_unlock(&hvc_structs_lock);
113 return hp; 113 return hp;
@@ -229,9 +229,9 @@ static int __init hvc_console_init(void)
229console_initcall(hvc_console_init); 229console_initcall(hvc_console_init);
230 230
231/* callback when the kboject ref count reaches zero. */ 231/* callback when the kboject ref count reaches zero. */
232static void hvc_port_destruct(struct tty_port *port) 232static void destroy_hvc_struct(struct kref *kref)
233{ 233{
234 struct hvc_struct *hp = container_of(port, struct hvc_struct, port); 234 struct hvc_struct *hp = container_of(kref, struct hvc_struct, kref);
235 unsigned long flags; 235 unsigned long flags;
236 236
237 spin_lock(&hvc_structs_lock); 237 spin_lock(&hvc_structs_lock);
@@ -245,20 +245,6 @@ static void hvc_port_destruct(struct tty_port *port)
245 kfree(hp); 245 kfree(hp);
246} 246}
247 247
248static void hvc_check_console(int index)
249{
250 /* Already enabled, bail out */
251 if (hvc_console.flags & CON_ENABLED)
252 return;
253
254 /* If this index is what the user requested, then register
255 * now (setup won't fail at this point). It's ok to just
256 * call register again if previously .setup failed.
257 */
258 if (index == hvc_console.index)
259 register_console(&hvc_console);
260}
261
262/* 248/*
263 * hvc_instantiate() is an early console discovery method which locates 249 * hvc_instantiate() is an early console discovery method which locates
264 * consoles * prior to the vio subsystem discovering them. Hotplugged 250 * consoles * prior to the vio subsystem discovering them. Hotplugged
@@ -278,7 +264,7 @@ int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
278 /* make sure no no tty has been registered in this index */ 264 /* make sure no no tty has been registered in this index */
279 hp = hvc_get_by_index(index); 265 hp = hvc_get_by_index(index);
280 if (hp) { 266 if (hp) {
281 tty_port_put(&hp->port); 267 kref_put(&hp->kref, destroy_hvc_struct);
282 return -1; 268 return -1;
283 } 269 }
284 270
@@ -289,8 +275,12 @@ int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
289 if (last_hvc < index) 275 if (last_hvc < index)
290 last_hvc = index; 276 last_hvc = index;
291 277
292 /* check if we need to re-register the kernel console */ 278 /* if this index is what the user requested, then register
293 hvc_check_console(index); 279 * now (setup won't fail at this point). It's ok to just
280 * call register again if previously .setup failed.
281 */
282 if (index == hvc_console.index)
283 register_console(&hvc_console);
294 284
295 return 0; 285 return 0;
296} 286}
@@ -309,43 +299,34 @@ static void hvc_unthrottle(struct tty_struct *tty)
309 hvc_kick(); 299 hvc_kick();
310} 300}
311 301
312static int hvc_install(struct tty_driver *driver, struct tty_struct *tty)
313{
314 struct hvc_struct *hp;
315 int rc;
316
317 /* Auto increments kref reference if found. */
318 if (!(hp = hvc_get_by_index(tty->index)))
319 return -ENODEV;
320
321 tty->driver_data = hp;
322
323 rc = tty_port_install(&hp->port, driver, tty);
324 if (rc)
325 tty_port_put(&hp->port);
326 return rc;
327}
328
329/* 302/*
330 * The TTY interface won't be used until after the vio layer has exposed the vty 303 * The TTY interface won't be used until after the vio layer has exposed the vty
331 * adapter to the kernel. 304 * adapter to the kernel.
332 */ 305 */
333static int hvc_open(struct tty_struct *tty, struct file * filp) 306static int hvc_open(struct tty_struct *tty, struct file * filp)
334{ 307{
335 struct hvc_struct *hp = tty->driver_data; 308 struct hvc_struct *hp;
336 unsigned long flags; 309 unsigned long flags;
337 int rc = 0; 310 int rc = 0;
338 311
339 spin_lock_irqsave(&hp->port.lock, flags); 312 /* Auto increments kref reference if found. */
313 if (!(hp = hvc_get_by_index(tty->index)))
314 return -ENODEV;
315
316 spin_lock_irqsave(&hp->lock, flags);
340 /* Check and then increment for fast path open. */ 317 /* Check and then increment for fast path open. */
341 if (hp->port.count++ > 0) { 318 if (hp->count++ > 0) {
342 spin_unlock_irqrestore(&hp->port.lock, flags); 319 tty_kref_get(tty);
320 spin_unlock_irqrestore(&hp->lock, flags);
343 hvc_kick(); 321 hvc_kick();
344 return 0; 322 return 0;
345 } /* else count == 0 */ 323 } /* else count == 0 */
346 spin_unlock_irqrestore(&hp->port.lock, flags);
347 324
348 tty_port_tty_set(&hp->port, tty); 325 tty->driver_data = hp;
326
327 hp->tty = tty_kref_get(tty);
328
329 spin_unlock_irqrestore(&hp->lock, flags);
349 330
350 if (hp->ops->notifier_add) 331 if (hp->ops->notifier_add)
351 rc = hp->ops->notifier_add(hp, hp->data); 332 rc = hp->ops->notifier_add(hp, hp->data);
@@ -357,9 +338,12 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
357 * tty fields and return the kref reference. 338 * tty fields and return the kref reference.
358 */ 339 */
359 if (rc) { 340 if (rc) {
360 tty_port_tty_set(&hp->port, NULL); 341 spin_lock_irqsave(&hp->lock, flags);
342 hp->tty = NULL;
343 spin_unlock_irqrestore(&hp->lock, flags);
344 tty_kref_put(tty);
361 tty->driver_data = NULL; 345 tty->driver_data = NULL;
362 tty_port_put(&hp->port); 346 kref_put(&hp->kref, destroy_hvc_struct);
363 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); 347 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc);
364 } 348 }
365 /* Force wakeup of the polling thread */ 349 /* Force wakeup of the polling thread */
@@ -386,12 +370,12 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
386 370
387 hp = tty->driver_data; 371 hp = tty->driver_data;
388 372
389 spin_lock_irqsave(&hp->port.lock, flags); 373 spin_lock_irqsave(&hp->lock, flags);
390 374
391 if (--hp->port.count == 0) { 375 if (--hp->count == 0) {
392 spin_unlock_irqrestore(&hp->port.lock, flags);
393 /* We are done with the tty pointer now. */ 376 /* We are done with the tty pointer now. */
394 tty_port_tty_set(&hp->port, NULL); 377 hp->tty = NULL;
378 spin_unlock_irqrestore(&hp->lock, flags);
395 379
396 if (hp->ops->notifier_del) 380 if (hp->ops->notifier_del)
397 hp->ops->notifier_del(hp, hp->data); 381 hp->ops->notifier_del(hp, hp->data);
@@ -404,26 +388,23 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
404 * there is no buffered data otherwise sleeps on a wait queue 388 * there is no buffered data otherwise sleeps on a wait queue
405 * waking periodically to check chars_in_buffer(). 389 * waking periodically to check chars_in_buffer().
406 */ 390 */
407 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT); 391 tty_wait_until_sent(tty, HVC_CLOSE_WAIT);
408 } else { 392 } else {
409 if (hp->port.count < 0) 393 if (hp->count < 0)
410 printk(KERN_ERR "hvc_close %X: oops, count is %d\n", 394 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
411 hp->vtermno, hp->port.count); 395 hp->vtermno, hp->count);
412 spin_unlock_irqrestore(&hp->port.lock, flags); 396 spin_unlock_irqrestore(&hp->lock, flags);
413 } 397 }
414}
415 398
416static void hvc_cleanup(struct tty_struct *tty) 399 tty_kref_put(tty);
417{ 400 kref_put(&hp->kref, destroy_hvc_struct);
418 struct hvc_struct *hp = tty->driver_data;
419
420 tty_port_put(&hp->port);
421} 401}
422 402
423static void hvc_hangup(struct tty_struct *tty) 403static void hvc_hangup(struct tty_struct *tty)
424{ 404{
425 struct hvc_struct *hp = tty->driver_data; 405 struct hvc_struct *hp = tty->driver_data;
426 unsigned long flags; 406 unsigned long flags;
407 int temp_open_count;
427 408
428 if (!hp) 409 if (!hp)
429 return; 410 return;
@@ -431,26 +412,33 @@ static void hvc_hangup(struct tty_struct *tty)
431 /* cancel pending tty resize work */ 412 /* cancel pending tty resize work */
432 cancel_work_sync(&hp->tty_resize); 413 cancel_work_sync(&hp->tty_resize);
433 414
434 spin_lock_irqsave(&hp->port.lock, flags); 415 spin_lock_irqsave(&hp->lock, flags);
435 416
436 /* 417 /*
437 * The N_TTY line discipline has problems such that in a close vs 418 * The N_TTY line discipline has problems such that in a close vs
438 * open->hangup case this can be called after the final close so prevent 419 * open->hangup case this can be called after the final close so prevent
439 * that from happening for now. 420 * that from happening for now.
440 */ 421 */
441 if (hp->port.count <= 0) { 422 if (hp->count <= 0) {
442 spin_unlock_irqrestore(&hp->port.lock, flags); 423 spin_unlock_irqrestore(&hp->lock, flags);
443 return; 424 return;
444 } 425 }
445 426
446 hp->port.count = 0; 427 temp_open_count = hp->count;
447 spin_unlock_irqrestore(&hp->port.lock, flags); 428 hp->count = 0;
448 tty_port_tty_set(&hp->port, NULL);
449
450 hp->n_outbuf = 0; 429 hp->n_outbuf = 0;
430 hp->tty = NULL;
431
432 spin_unlock_irqrestore(&hp->lock, flags);
451 433
452 if (hp->ops->notifier_hangup) 434 if (hp->ops->notifier_hangup)
453 hp->ops->notifier_hangup(hp, hp->data); 435 hp->ops->notifier_hangup(hp, hp->data);
436
437 while(temp_open_count) {
438 --temp_open_count;
439 tty_kref_put(tty);
440 kref_put(&hp->kref, destroy_hvc_struct);
441 }
454} 442}
455 443
456/* 444/*
@@ -490,8 +478,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
490 if (!hp) 478 if (!hp)
491 return -EPIPE; 479 return -EPIPE;
492 480
493 /* FIXME what's this (unprotected) check for? */ 481 if (hp->count <= 0)
494 if (hp->port.count <= 0)
495 return -EIO; 482 return -EIO;
496 483
497 spin_lock_irqsave(&hp->lock, flags); 484 spin_lock_irqsave(&hp->lock, flags);
@@ -539,12 +526,13 @@ static void hvc_set_winsz(struct work_struct *work)
539 526
540 hp = container_of(work, struct hvc_struct, tty_resize); 527 hp = container_of(work, struct hvc_struct, tty_resize);
541 528
542 tty = tty_port_tty_get(&hp->port);
543 if (!tty)
544 return;
545
546 spin_lock_irqsave(&hp->lock, hvc_flags); 529 spin_lock_irqsave(&hp->lock, hvc_flags);
547 ws = hp->ws; 530 if (!hp->tty) {
531 spin_unlock_irqrestore(&hp->lock, hvc_flags);
532 return;
533 }
534 ws = hp->ws;
535 tty = tty_kref_get(hp->tty);
548 spin_unlock_irqrestore(&hp->lock, hvc_flags); 536 spin_unlock_irqrestore(&hp->lock, hvc_flags);
549 537
550 tty_do_resize(tty, &ws); 538 tty_do_resize(tty, &ws);
@@ -561,7 +549,7 @@ static int hvc_write_room(struct tty_struct *tty)
561 struct hvc_struct *hp = tty->driver_data; 549 struct hvc_struct *hp = tty->driver_data;
562 550
563 if (!hp) 551 if (!hp)
564 return 0; 552 return -1;
565 553
566 return hp->outbuf_size - hp->n_outbuf; 554 return hp->outbuf_size - hp->n_outbuf;
567} 555}
@@ -613,7 +601,7 @@ int hvc_poll(struct hvc_struct *hp)
613 } 601 }
614 602
615 /* No tty attached, just skip */ 603 /* No tty attached, just skip */
616 tty = tty_port_tty_get(&hp->port); 604 tty = tty_kref_get(hp->tty);
617 if (tty == NULL) 605 if (tty == NULL)
618 goto bail; 606 goto bail;
619 607
@@ -693,7 +681,8 @@ int hvc_poll(struct hvc_struct *hp)
693 681
694 tty_flip_buffer_push(tty); 682 tty_flip_buffer_push(tty);
695 } 683 }
696 tty_kref_put(tty); 684 if (tty)
685 tty_kref_put(tty);
697 686
698 return poll_mask; 687 return poll_mask;
699} 688}
@@ -812,10 +801,8 @@ static void hvc_poll_put_char(struct tty_driver *driver, int line, char ch)
812#endif 801#endif
813 802
814static const struct tty_operations hvc_ops = { 803static const struct tty_operations hvc_ops = {
815 .install = hvc_install,
816 .open = hvc_open, 804 .open = hvc_open,
817 .close = hvc_close, 805 .close = hvc_close,
818 .cleanup = hvc_cleanup,
819 .write = hvc_write, 806 .write = hvc_write,
820 .hangup = hvc_hangup, 807 .hangup = hvc_hangup,
821 .unthrottle = hvc_unthrottle, 808 .unthrottle = hvc_unthrottle,
@@ -830,10 +817,6 @@ static const struct tty_operations hvc_ops = {
830#endif 817#endif
831}; 818};
832 819
833static const struct tty_port_operations hvc_port_ops = {
834 .destruct = hvc_port_destruct,
835};
836
837struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, 820struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
838 const struct hv_ops *ops, 821 const struct hv_ops *ops,
839 int outbuf_size) 822 int outbuf_size)
@@ -859,8 +842,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
859 hp->outbuf_size = outbuf_size; 842 hp->outbuf_size = outbuf_size;
860 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; 843 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))];
861 844
862 tty_port_init(&hp->port); 845 kref_init(&hp->kref);
863 hp->port.ops = &hvc_port_ops;
864 846
865 INIT_WORK(&hp->tty_resize, hvc_set_winsz); 847 INIT_WORK(&hp->tty_resize, hvc_set_winsz);
866 spin_lock_init(&hp->lock); 848 spin_lock_init(&hp->lock);
@@ -880,15 +862,10 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
880 i = ++last_hvc; 862 i = ++last_hvc;
881 863
882 hp->index = i; 864 hp->index = i;
883 cons_ops[i] = ops;
884 vtermnos[i] = vtermno;
885 865
886 list_add_tail(&(hp->next), &hvc_structs); 866 list_add_tail(&(hp->next), &hvc_structs);
887 spin_unlock(&hvc_structs_lock); 867 spin_unlock(&hvc_structs_lock);
888 868
889 /* check if we need to re-register the kernel console */
890 hvc_check_console(i);
891
892 return hp; 869 return hp;
893} 870}
894EXPORT_SYMBOL_GPL(hvc_alloc); 871EXPORT_SYMBOL_GPL(hvc_alloc);
@@ -898,15 +875,11 @@ int hvc_remove(struct hvc_struct *hp)
898 unsigned long flags; 875 unsigned long flags;
899 struct tty_struct *tty; 876 struct tty_struct *tty;
900 877
901 tty = tty_port_tty_get(&hp->port);
902
903 spin_lock_irqsave(&hp->lock, flags); 878 spin_lock_irqsave(&hp->lock, flags);
904 if (hp->index < MAX_NR_HVC_CONSOLES) { 879 tty = tty_kref_get(hp->tty);
905 console_lock(); 880
881 if (hp->index < MAX_NR_HVC_CONSOLES)
906 vtermnos[hp->index] = -1; 882 vtermnos[hp->index] = -1;
907 cons_ops[hp->index] = NULL;
908 console_unlock();
909 }
910 883
911 /* Don't whack hp->irq because tty_hangup() will need to free the irq. */ 884 /* Don't whack hp->irq because tty_hangup() will need to free the irq. */
912 885
@@ -918,7 +891,7 @@ int hvc_remove(struct hvc_struct *hp)
918 * kref cause it to be removed, which will probably be the tty_vhangup 891 * kref cause it to be removed, which will probably be the tty_vhangup
919 * below. 892 * below.
920 */ 893 */
921 tty_port_put(&hp->port); 894 kref_put(&hp->kref, destroy_hvc_struct);
922 895
923 /* 896 /*
924 * This function call will auto chain call hvc_hangup. 897 * This function call will auto chain call hvc_hangup.
@@ -944,6 +917,7 @@ static int hvc_init(void)
944 goto out; 917 goto out;
945 } 918 }
946 919
920 drv->owner = THIS_MODULE;
947 drv->driver_name = "hvc"; 921 drv->driver_name = "hvc";
948 drv->name = "hvc"; 922 drv->name = "hvc";
949 drv->major = HVC_MAJOR; 923 drv->major = HVC_MAJOR;
diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h
index 674d23cb919..c335a1492a5 100644
--- a/drivers/tty/hvc/hvc_console.h
+++ b/drivers/tty/hvc/hvc_console.h
@@ -46,9 +46,10 @@
46#define HVC_ALLOC_TTY_ADAPTERS 8 46#define HVC_ALLOC_TTY_ADAPTERS 8
47 47
48struct hvc_struct { 48struct hvc_struct {
49 struct tty_port port;
50 spinlock_t lock; 49 spinlock_t lock;
51 int index; 50 int index;
51 struct tty_struct *tty;
52 int count;
52 int do_wakeup; 53 int do_wakeup;
53 char *outbuf; 54 char *outbuf;
54 int outbuf_size; 55 int outbuf_size;
@@ -60,6 +61,7 @@ struct hvc_struct {
60 struct winsize ws; 61 struct winsize ws;
61 struct work_struct tty_resize; 62 struct work_struct tty_resize;
62 struct list_head next; 63 struct list_head next;
64 struct kref kref; /* ref count & hvc_struct lifetime */
63}; 65};
64 66
65/* implemented by a low level driver */ 67/* implemented by a low level driver */
diff --git a/drivers/tty/hvc/hvc_irq.c b/drivers/tty/hvc/hvc_irq.c
index c9adb0559f6..2623e177e8d 100644
--- a/drivers/tty/hvc/hvc_irq.c
+++ b/drivers/tty/hvc/hvc_irq.c
@@ -28,7 +28,7 @@ int notifier_add_irq(struct hvc_struct *hp, int irq)
28 hp->irq_requested = 0; 28 hp->irq_requested = 0;
29 return 0; 29 return 0;
30 } 30 }
31 rc = request_irq(irq, hvc_handle_interrupt, 0, 31 rc = request_irq(irq, hvc_handle_interrupt, IRQF_DISABLED,
32 "hvc_console", hp); 32 "hvc_console", hp);
33 if (!rc) 33 if (!rc)
34 hp->irq_requested = 1; 34 hp->irq_requested = 1;
diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
deleted file mode 100644
index cd69b48f6df..00000000000
--- a/drivers/tty/hvc/hvc_opal.c
+++ /dev/null
@@ -1,425 +0,0 @@
1/*
2 * opal driver interface to hvc_console.c
3 *
4 * Copyright 2011 Benjamin Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
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 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#undef DEBUG
23
24#include <linux/types.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/slab.h>
28#include <linux/console.h>
29#include <linux/of.h>
30#include <linux/of_platform.h>
31#include <linux/export.h>
32
33#include <asm/hvconsole.h>
34#include <asm/prom.h>
35#include <asm/firmware.h>
36#include <asm/hvsi.h>
37#include <asm/udbg.h>
38#include <asm/opal.h>
39
40#include "hvc_console.h"
41
42static const char hvc_opal_name[] = "hvc_opal";
43
44static struct of_device_id hvc_opal_match[] = {
45 { .name = "serial", .compatible = "ibm,opal-console-raw" },
46 { .name = "serial", .compatible = "ibm,opal-console-hvsi" },
47 { },
48};
49
50typedef enum hv_protocol {
51 HV_PROTOCOL_RAW,
52 HV_PROTOCOL_HVSI
53} hv_protocol_t;
54
55struct hvc_opal_priv {
56 hv_protocol_t proto; /* Raw data or HVSI packets */
57 struct hvsi_priv hvsi; /* HVSI specific data */
58};
59static struct hvc_opal_priv *hvc_opal_privs[MAX_NR_HVC_CONSOLES];
60
61/* For early boot console */
62static struct hvc_opal_priv hvc_opal_boot_priv;
63static u32 hvc_opal_boot_termno;
64
65static const struct hv_ops hvc_opal_raw_ops = {
66 .get_chars = opal_get_chars,
67 .put_chars = opal_put_chars,
68 .notifier_add = notifier_add_irq,
69 .notifier_del = notifier_del_irq,
70 .notifier_hangup = notifier_hangup_irq,
71};
72
73static int hvc_opal_hvsi_get_chars(uint32_t vtermno, char *buf, int count)
74{
75 struct hvc_opal_priv *pv = hvc_opal_privs[vtermno];
76
77 if (WARN_ON(!pv))
78 return -ENODEV;
79
80 return hvsilib_get_chars(&pv->hvsi, buf, count);
81}
82
83static int hvc_opal_hvsi_put_chars(uint32_t vtermno, const char *buf, int count)
84{
85 struct hvc_opal_priv *pv = hvc_opal_privs[vtermno];
86
87 if (WARN_ON(!pv))
88 return -ENODEV;
89
90 return hvsilib_put_chars(&pv->hvsi, buf, count);
91}
92
93static int hvc_opal_hvsi_open(struct hvc_struct *hp, int data)
94{
95 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
96 int rc;
97
98 pr_devel("HVSI@%x: do open !\n", hp->vtermno);
99
100 rc = notifier_add_irq(hp, data);
101 if (rc)
102 return rc;
103
104 return hvsilib_open(&pv->hvsi, hp);
105}
106
107static void hvc_opal_hvsi_close(struct hvc_struct *hp, int data)
108{
109 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
110
111 pr_devel("HVSI@%x: do close !\n", hp->vtermno);
112
113 hvsilib_close(&pv->hvsi, hp);
114
115 notifier_del_irq(hp, data);
116}
117
118void hvc_opal_hvsi_hangup(struct hvc_struct *hp, int data)
119{
120 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
121
122 pr_devel("HVSI@%x: do hangup !\n", hp->vtermno);
123
124 hvsilib_close(&pv->hvsi, hp);
125
126 notifier_hangup_irq(hp, data);
127}
128
129static int hvc_opal_hvsi_tiocmget(struct hvc_struct *hp)
130{
131 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
132
133 if (!pv)
134 return -EINVAL;
135 return pv->hvsi.mctrl;
136}
137
138static int hvc_opal_hvsi_tiocmset(struct hvc_struct *hp, unsigned int set,
139 unsigned int clear)
140{
141 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
142
143 pr_devel("HVSI@%x: Set modem control, set=%x,clr=%x\n",
144 hp->vtermno, set, clear);
145
146 if (set & TIOCM_DTR)
147 hvsilib_write_mctrl(&pv->hvsi, 1);
148 else if (clear & TIOCM_DTR)
149 hvsilib_write_mctrl(&pv->hvsi, 0);
150
151 return 0;
152}
153
154static const struct hv_ops hvc_opal_hvsi_ops = {
155 .get_chars = hvc_opal_hvsi_get_chars,
156 .put_chars = hvc_opal_hvsi_put_chars,
157 .notifier_add = hvc_opal_hvsi_open,
158 .notifier_del = hvc_opal_hvsi_close,
159 .notifier_hangup = hvc_opal_hvsi_hangup,
160 .tiocmget = hvc_opal_hvsi_tiocmget,
161 .tiocmset = hvc_opal_hvsi_tiocmset,
162};
163
164static int hvc_opal_probe(struct platform_device *dev)
165{
166 const struct hv_ops *ops;
167 struct hvc_struct *hp;
168 struct hvc_opal_priv *pv;
169 hv_protocol_t proto;
170 unsigned int termno, boot = 0;
171 const __be32 *reg;
172
173 if (of_device_is_compatible(dev->dev.of_node, "ibm,opal-console-raw")) {
174 proto = HV_PROTOCOL_RAW;
175 ops = &hvc_opal_raw_ops;
176 } else if (of_device_is_compatible(dev->dev.of_node,
177 "ibm,opal-console-hvsi")) {
178 proto = HV_PROTOCOL_HVSI;
179 ops = &hvc_opal_hvsi_ops;
180 } else {
181 pr_err("hvc_opal: Unknown protocol for %s\n",
182 dev->dev.of_node->full_name);
183 return -ENXIO;
184 }
185
186 reg = of_get_property(dev->dev.of_node, "reg", NULL);
187 termno = reg ? be32_to_cpup(reg) : 0;
188
189 /* Is it our boot one ? */
190 if (hvc_opal_privs[termno] == &hvc_opal_boot_priv) {
191 pv = hvc_opal_privs[termno];
192 boot = 1;
193 } else if (hvc_opal_privs[termno] == NULL) {
194 pv = kzalloc(sizeof(struct hvc_opal_priv), GFP_KERNEL);
195 if (!pv)
196 return -ENOMEM;
197 pv->proto = proto;
198 hvc_opal_privs[termno] = pv;
199 if (proto == HV_PROTOCOL_HVSI)
200 hvsilib_init(&pv->hvsi, opal_get_chars, opal_put_chars,
201 termno, 0);
202
203 /* Instanciate now to establish a mapping index==vtermno */
204 hvc_instantiate(termno, termno, ops);
205 } else {
206 pr_err("hvc_opal: Device %s has duplicate terminal number #%d\n",
207 dev->dev.of_node->full_name, termno);
208 return -ENXIO;
209 }
210
211 pr_info("hvc%d: %s protocol on %s%s\n", termno,
212 proto == HV_PROTOCOL_RAW ? "raw" : "hvsi",
213 dev->dev.of_node->full_name,
214 boot ? " (boot console)" : "");
215
216 /* We don't do IRQ yet */
217 hp = hvc_alloc(termno, 0, ops, MAX_VIO_PUT_CHARS);
218 if (IS_ERR(hp))
219 return PTR_ERR(hp);
220 dev_set_drvdata(&dev->dev, hp);
221
222 return 0;
223}
224
225static int hvc_opal_remove(struct platform_device *dev)
226{
227 struct hvc_struct *hp = dev_get_drvdata(&dev->dev);
228 int rc, termno;
229
230 termno = hp->vtermno;
231 rc = hvc_remove(hp);
232 if (rc == 0) {
233 if (hvc_opal_privs[termno] != &hvc_opal_boot_priv)
234 kfree(hvc_opal_privs[termno]);
235 hvc_opal_privs[termno] = NULL;
236 }
237 return rc;
238}
239
240static struct platform_driver hvc_opal_driver = {
241 .probe = hvc_opal_probe,
242 .remove = hvc_opal_remove,
243 .driver = {
244 .name = hvc_opal_name,
245 .owner = THIS_MODULE,
246 .of_match_table = hvc_opal_match,
247 }
248};
249
250static int __init hvc_opal_init(void)
251{
252 if (!firmware_has_feature(FW_FEATURE_OPAL))
253 return -ENODEV;
254
255 /* Register as a vio device to receive callbacks */
256 return platform_driver_register(&hvc_opal_driver);
257}
258module_init(hvc_opal_init);
259
260static void __exit hvc_opal_exit(void)
261{
262 platform_driver_unregister(&hvc_opal_driver);
263}
264module_exit(hvc_opal_exit);
265
266static void udbg_opal_putc(char c)
267{
268 unsigned int termno = hvc_opal_boot_termno;
269 int count = -1;
270
271 if (c == '\n')
272 udbg_opal_putc('\r');
273
274 do {
275 switch(hvc_opal_boot_priv.proto) {
276 case HV_PROTOCOL_RAW:
277 count = opal_put_chars(termno, &c, 1);
278 break;
279 case HV_PROTOCOL_HVSI:
280 count = hvc_opal_hvsi_put_chars(termno, &c, 1);
281 break;
282 }
283 } while(count == 0 || count == -EAGAIN);
284}
285
286static int udbg_opal_getc_poll(void)
287{
288 unsigned int termno = hvc_opal_boot_termno;
289 int rc = 0;
290 char c;
291
292 switch(hvc_opal_boot_priv.proto) {
293 case HV_PROTOCOL_RAW:
294 rc = opal_get_chars(termno, &c, 1);
295 break;
296 case HV_PROTOCOL_HVSI:
297 rc = hvc_opal_hvsi_get_chars(termno, &c, 1);
298 break;
299 }
300 if (!rc)
301 return -1;
302 return c;
303}
304
305static int udbg_opal_getc(void)
306{
307 int ch;
308 for (;;) {
309 ch = udbg_opal_getc_poll();
310 if (ch == -1) {
311 /* This shouldn't be needed...but... */
312 volatile unsigned long delay;
313 for (delay=0; delay < 2000000; delay++)
314 ;
315 } else {
316 return ch;
317 }
318 }
319}
320
321static void udbg_init_opal_common(void)
322{
323 udbg_putc = udbg_opal_putc;
324 udbg_getc = udbg_opal_getc;
325 udbg_getc_poll = udbg_opal_getc_poll;
326 tb_ticks_per_usec = 0x200; /* Make udelay not suck */
327}
328
329void __init hvc_opal_init_early(void)
330{
331 struct device_node *stdout_node = NULL;
332 const u32 *termno;
333 const char *name = NULL;
334 const struct hv_ops *ops;
335 u32 index;
336
337 /* find the boot console from /chosen/stdout */
338 if (of_chosen)
339 name = of_get_property(of_chosen, "linux,stdout-path", NULL);
340 if (name) {
341 stdout_node = of_find_node_by_path(name);
342 if (!stdout_node) {
343 pr_err("hvc_opal: Failed to locate default console!\n");
344 return;
345 }
346 } else {
347 struct device_node *opal, *np;
348
349 /* Current OPAL takeover doesn't provide the stdout
350 * path, so we hard wire it
351 */
352 opal = of_find_node_by_path("/ibm,opal/consoles");
353 if (opal)
354 pr_devel("hvc_opal: Found consoles in new location\n");
355 if (!opal) {
356 opal = of_find_node_by_path("/ibm,opal");
357 if (opal)
358 pr_devel("hvc_opal: "
359 "Found consoles in old location\n");
360 }
361 if (!opal)
362 return;
363 for_each_child_of_node(opal, np) {
364 if (!strcmp(np->name, "serial")) {
365 stdout_node = np;
366 break;
367 }
368 }
369 of_node_put(opal);
370 }
371 if (!stdout_node)
372 return;
373 termno = of_get_property(stdout_node, "reg", NULL);
374 index = termno ? *termno : 0;
375 if (index >= MAX_NR_HVC_CONSOLES)
376 return;
377 hvc_opal_privs[index] = &hvc_opal_boot_priv;
378
379 /* Check the protocol */
380 if (of_device_is_compatible(stdout_node, "ibm,opal-console-raw")) {
381 hvc_opal_boot_priv.proto = HV_PROTOCOL_RAW;
382 ops = &hvc_opal_raw_ops;
383 pr_devel("hvc_opal: Found RAW console\n");
384 }
385 else if (of_device_is_compatible(stdout_node,"ibm,opal-console-hvsi")) {
386 hvc_opal_boot_priv.proto = HV_PROTOCOL_HVSI;
387 ops = &hvc_opal_hvsi_ops;
388 hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars,
389 opal_put_chars, index, 1);
390 /* HVSI, perform the handshake now */
391 hvsilib_establish(&hvc_opal_boot_priv.hvsi);
392 pr_devel("hvc_opal: Found HVSI console\n");
393 } else
394 goto out;
395 hvc_opal_boot_termno = index;
396 udbg_init_opal_common();
397 add_preferred_console("hvc", index, NULL);
398 hvc_instantiate(index, index, ops);
399out:
400 of_node_put(stdout_node);
401}
402
403#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_RAW
404void __init udbg_init_debug_opal_raw(void)
405{
406 u32 index = CONFIG_PPC_EARLY_DEBUG_OPAL_VTERMNO;
407 hvc_opal_privs[index] = &hvc_opal_boot_priv;
408 hvc_opal_boot_priv.proto = HV_PROTOCOL_RAW;
409 hvc_opal_boot_termno = index;
410 udbg_init_opal_common();
411}
412#endif /* CONFIG_PPC_EARLY_DEBUG_OPAL_RAW */
413
414#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI
415void __init udbg_init_debug_opal_hvsi(void)
416{
417 u32 index = CONFIG_PPC_EARLY_DEBUG_OPAL_VTERMNO;
418 hvc_opal_privs[index] = &hvc_opal_boot_priv;
419 hvc_opal_boot_termno = index;
420 udbg_init_opal_common();
421 hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, opal_put_chars,
422 index, 1);
423 hvsilib_establish(&hvc_opal_boot_priv.hvsi);
424}
425#endif /* CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI */
diff --git a/drivers/tty/hvc/hvc_rtas.c b/drivers/tty/hvc/hvc_rtas.c
index 0069bb86ba4..61c4a61558d 100644
--- a/drivers/tty/hvc/hvc_rtas.c
+++ b/drivers/tty/hvc/hvc_rtas.c
@@ -94,7 +94,7 @@ static int __init hvc_rtas_init(void)
94 94
95 /* Allocate an hvc_struct for the console device we instantiated 95 /* Allocate an hvc_struct for the console device we instantiated
96 * earlier. Save off hp so that we can return it on exit */ 96 * earlier. Save off hp so that we can return it on exit */
97 hp = hvc_alloc(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops, 16); 97 hp = hvc_alloc(hvc_rtas_cookie, NO_IRQ, &hvc_rtas_get_put_ops, 16);
98 if (IS_ERR(hp)) 98 if (IS_ERR(hp))
99 return PTR_ERR(hp); 99 return PTR_ERR(hp);
100 100
diff --git a/drivers/tty/hvc/hvc_udbg.c b/drivers/tty/hvc/hvc_udbg.c
index 72228276fe3..b0957e61a7b 100644
--- a/drivers/tty/hvc/hvc_udbg.c
+++ b/drivers/tty/hvc/hvc_udbg.c
@@ -36,7 +36,7 @@ static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count)
36{ 36{
37 int i; 37 int i;
38 38
39 for (i = 0; i < count && udbg_putc; i++) 39 for (i = 0; i < count; i++)
40 udbg_putc(buf[i]); 40 udbg_putc(buf[i]);
41 41
42 return i; 42 return i;
@@ -67,12 +67,9 @@ static int __init hvc_udbg_init(void)
67{ 67{
68 struct hvc_struct *hp; 68 struct hvc_struct *hp;
69 69
70 if (!udbg_putc)
71 return -ENODEV;
72
73 BUG_ON(hvc_udbg_dev); 70 BUG_ON(hvc_udbg_dev);
74 71
75 hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16); 72 hp = hvc_alloc(0, NO_IRQ, &hvc_udbg_ops, 16);
76 if (IS_ERR(hp)) 73 if (IS_ERR(hp))
77 return PTR_ERR(hp); 74 return PTR_ERR(hp);
78 75
@@ -91,9 +88,6 @@ module_exit(hvc_udbg_exit);
91 88
92static int __init hvc_udbg_console_init(void) 89static int __init hvc_udbg_console_init(void)
93{ 90{
94 if (!udbg_putc)
95 return -ENODEV;
96
97 hvc_instantiate(0, 0, &hvc_udbg_ops); 91 hvc_instantiate(0, 0, &hvc_udbg_ops);
98 add_preferred_console("hvc", 0, NULL); 92 add_preferred_console("hvc", 0, NULL);
99 93
diff --git a/drivers/tty/hvc/hvc_vio.c b/drivers/tty/hvc/hvc_vio.c
index 0c629807610..130aace67f3 100644
--- a/drivers/tty/hvc/hvc_vio.c
+++ b/drivers/tty/hvc/hvc_vio.c
@@ -41,11 +41,11 @@
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/console.h> 43#include <linux/console.h>
44#include <linux/module.h>
45 44
46#include <asm/hvconsole.h> 45#include <asm/hvconsole.h>
47#include <asm/vio.h> 46#include <asm/vio.h>
48#include <asm/prom.h> 47#include <asm/prom.h>
48#include <asm/firmware.h>
49#include <asm/hvsi.h> 49#include <asm/hvsi.h>
50#include <asm/udbg.h> 50#include <asm/udbg.h>
51 51
@@ -53,7 +53,7 @@
53 53
54static const char hvc_driver_name[] = "hvc_console"; 54static const char hvc_driver_name[] = "hvc_console";
55 55
56static struct vio_device_id hvc_driver_table[] = { 56static struct vio_device_id hvc_driver_table[] __devinitdata = {
57 {"serial", "hvterm1"}, 57 {"serial", "hvterm1"},
58#ifndef HVC_OLD_HVSI 58#ifndef HVC_OLD_HVSI
59 {"serial", "hvterm-protocol"}, 59 {"serial", "hvterm-protocol"},
@@ -230,70 +230,7 @@ static const struct hv_ops hvterm_hvsi_ops = {
230 .tiocmset = hvterm_hvsi_tiocmset, 230 .tiocmset = hvterm_hvsi_tiocmset,
231}; 231};
232 232
233static void udbg_hvc_putc(char c) 233static int __devinit hvc_vio_probe(struct vio_dev *vdev,
234{
235 int count = -1;
236
237 if (!hvterm_privs[0])
238 return;
239
240 if (c == '\n')
241 udbg_hvc_putc('\r');
242
243 do {
244 switch(hvterm_privs[0]->proto) {
245 case HV_PROTOCOL_RAW:
246 count = hvterm_raw_put_chars(0, &c, 1);
247 break;
248 case HV_PROTOCOL_HVSI:
249 count = hvterm_hvsi_put_chars(0, &c, 1);
250 break;
251 }
252 } while(count == 0);
253}
254
255static int udbg_hvc_getc_poll(void)
256{
257 int rc = 0;
258 char c;
259
260 if (!hvterm_privs[0])
261 return -1;
262
263 switch(hvterm_privs[0]->proto) {
264 case HV_PROTOCOL_RAW:
265 rc = hvterm_raw_get_chars(0, &c, 1);
266 break;
267 case HV_PROTOCOL_HVSI:
268 rc = hvterm_hvsi_get_chars(0, &c, 1);
269 break;
270 }
271 if (!rc)
272 return -1;
273 return c;
274}
275
276static int udbg_hvc_getc(void)
277{
278 int ch;
279
280 if (!hvterm_privs[0])
281 return -1;
282
283 for (;;) {
284 ch = udbg_hvc_getc_poll();
285 if (ch == -1) {
286 /* This shouldn't be needed...but... */
287 volatile unsigned long delay;
288 for (delay=0; delay < 2000000; delay++)
289 ;
290 } else {
291 return ch;
292 }
293 }
294}
295
296static int hvc_vio_probe(struct vio_dev *vdev,
297 const struct vio_device_id *id) 234 const struct vio_device_id *id)
298{ 235{
299 const struct hv_ops *ops; 236 const struct hv_ops *ops;
@@ -313,7 +250,7 @@ static int hvc_vio_probe(struct vio_dev *vdev,
313 proto = HV_PROTOCOL_HVSI; 250 proto = HV_PROTOCOL_HVSI;
314 ops = &hvterm_hvsi_ops; 251 ops = &hvterm_hvsi_ops;
315 } else { 252 } else {
316 pr_err("hvc_vio: Unknown protocol for %s\n", vdev->dev.of_node->full_name); 253 pr_err("hvc_vio: Unkown protocol for %s\n", vdev->dev.of_node->full_name);
317 return -ENXIO; 254 return -ENXIO;
318 } 255 }
319 256
@@ -352,17 +289,10 @@ static int hvc_vio_probe(struct vio_dev *vdev,
352 return PTR_ERR(hp); 289 return PTR_ERR(hp);
353 dev_set_drvdata(&vdev->dev, hp); 290 dev_set_drvdata(&vdev->dev, hp);
354 291
355 /* register udbg if it's not there already for console 0 */
356 if (hp->index == 0 && !udbg_putc) {
357 udbg_putc = udbg_hvc_putc;
358 udbg_getc = udbg_hvc_getc;
359 udbg_getc_poll = udbg_hvc_getc_poll;
360 }
361
362 return 0; 292 return 0;
363} 293}
364 294
365static int hvc_vio_remove(struct vio_dev *vdev) 295static int __devexit hvc_vio_remove(struct vio_dev *vdev)
366{ 296{
367 struct hvc_struct *hp = dev_get_drvdata(&vdev->dev); 297 struct hvc_struct *hp = dev_get_drvdata(&vdev->dev);
368 int rc, termno; 298 int rc, termno;
@@ -380,14 +310,20 @@ static int hvc_vio_remove(struct vio_dev *vdev)
380static struct vio_driver hvc_vio_driver = { 310static struct vio_driver hvc_vio_driver = {
381 .id_table = hvc_driver_table, 311 .id_table = hvc_driver_table,
382 .probe = hvc_vio_probe, 312 .probe = hvc_vio_probe,
383 .remove = hvc_vio_remove, 313 .remove = __devexit_p(hvc_vio_remove),
384 .name = hvc_driver_name, 314 .driver = {
315 .name = hvc_driver_name,
316 .owner = THIS_MODULE,
317 }
385}; 318};
386 319
387static int __init hvc_vio_init(void) 320static int __init hvc_vio_init(void)
388{ 321{
389 int rc; 322 int rc;
390 323
324 if (firmware_has_feature(FW_FEATURE_ISERIES))
325 return -EIO;
326
391 /* Register as a vio device to receive callbacks */ 327 /* Register as a vio device to receive callbacks */
392 rc = vio_register_driver(&hvc_vio_driver); 328 rc = vio_register_driver(&hvc_vio_driver);
393 329
@@ -401,6 +337,59 @@ static void __exit hvc_vio_exit(void)
401} 337}
402module_exit(hvc_vio_exit); 338module_exit(hvc_vio_exit);
403 339
340static void udbg_hvc_putc(char c)
341{
342 int count = -1;
343
344 if (c == '\n')
345 udbg_hvc_putc('\r');
346
347 do {
348 switch(hvterm_priv0.proto) {
349 case HV_PROTOCOL_RAW:
350 count = hvterm_raw_put_chars(0, &c, 1);
351 break;
352 case HV_PROTOCOL_HVSI:
353 count = hvterm_hvsi_put_chars(0, &c, 1);
354 break;
355 }
356 } while(count == 0);
357}
358
359static int udbg_hvc_getc_poll(void)
360{
361 int rc = 0;
362 char c;
363
364 switch(hvterm_priv0.proto) {
365 case HV_PROTOCOL_RAW:
366 rc = hvterm_raw_get_chars(0, &c, 1);
367 break;
368 case HV_PROTOCOL_HVSI:
369 rc = hvterm_hvsi_get_chars(0, &c, 1);
370 break;
371 }
372 if (!rc)
373 return -1;
374 return c;
375}
376
377static int udbg_hvc_getc(void)
378{
379 int ch;
380 for (;;) {
381 ch = udbg_hvc_getc_poll();
382 if (ch == -1) {
383 /* This shouldn't be needed...but... */
384 volatile unsigned long delay;
385 for (delay=0; delay < 2000000; delay++)
386 ;
387 } else {
388 return ch;
389 }
390 }
391}
392
404void __init hvc_vio_init_early(void) 393void __init hvc_vio_init_early(void)
405{ 394{
406 struct device_node *stdout_node; 395 struct device_node *stdout_node;
diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c
index 19843ec3f80..52fdf60bdbe 100644
--- a/drivers/tty/hvc/hvc_xen.c
+++ b/drivers/tty/hvc/hvc_xen.c
@@ -21,78 +21,46 @@
21#include <linux/console.h> 21#include <linux/console.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/err.h> 23#include <linux/err.h>
24#include <linux/irq.h>
25#include <linux/init.h> 24#include <linux/init.h>
26#include <linux/types.h> 25#include <linux/types.h>
27#include <linux/list.h>
28 26
29#include <asm/io.h>
30#include <asm/xen/hypervisor.h> 27#include <asm/xen/hypervisor.h>
31 28
32#include <xen/xen.h> 29#include <xen/xen.h>
33#include <xen/interface/xen.h>
34#include <xen/hvm.h>
35#include <xen/grant_table.h>
36#include <xen/page.h> 30#include <xen/page.h>
37#include <xen/events.h> 31#include <xen/events.h>
38#include <xen/interface/io/console.h> 32#include <xen/interface/io/console.h>
39#include <xen/interface/sched.h>
40#include <xen/hvc-console.h> 33#include <xen/hvc-console.h>
41#include <xen/xenbus.h>
42 34
43#include "hvc_console.h" 35#include "hvc_console.h"
44 36
45#define HVC_COOKIE 0x58656e /* "Xen" in hex */ 37#define HVC_COOKIE 0x58656e /* "Xen" in hex */
46 38
47struct xencons_info { 39static struct hvc_struct *hvc;
48 struct list_head list; 40static int xencons_irq;
49 struct xenbus_device *xbdev;
50 struct xencons_interface *intf;
51 unsigned int evtchn;
52 struct hvc_struct *hvc;
53 int irq;
54 int vtermno;
55 grant_ref_t gntref;
56};
57
58static LIST_HEAD(xenconsoles);
59static DEFINE_SPINLOCK(xencons_lock);
60 41
61/* ------------------------------------------------------------------ */ 42/* ------------------------------------------------------------------ */
62 43
63static struct xencons_info *vtermno_to_xencons(int vtermno) 44static unsigned long console_pfn = ~0ul;
64{
65 struct xencons_info *entry, *n, *ret = NULL;
66
67 if (list_empty(&xenconsoles))
68 return NULL;
69 45
70 list_for_each_entry_safe(entry, n, &xenconsoles, list) { 46static inline struct xencons_interface *xencons_interface(void)
71 if (entry->vtermno == vtermno) {
72 ret = entry;
73 break;
74 }
75 }
76
77 return ret;
78}
79
80static inline int xenbus_devid_to_vtermno(int devid)
81{ 47{
82 return devid + HVC_COOKIE; 48 if (console_pfn == ~0ul)
49 return mfn_to_virt(xen_start_info->console.domU.mfn);
50 else
51 return __va(console_pfn << PAGE_SHIFT);
83} 52}
84 53
85static inline void notify_daemon(struct xencons_info *cons) 54static inline void notify_daemon(void)
86{ 55{
87 /* Use evtchn: this is called early, before irq is set up. */ 56 /* Use evtchn: this is called early, before irq is set up. */
88 notify_remote_via_evtchn(cons->evtchn); 57 notify_remote_via_evtchn(xen_start_info->console.domU.evtchn);
89} 58}
90 59
91static int __write_console(struct xencons_info *xencons, 60static int __write_console(const char *data, int len)
92 const char *data, int len)
93{ 61{
62 struct xencons_interface *intf = xencons_interface();
94 XENCONS_RING_IDX cons, prod; 63 XENCONS_RING_IDX cons, prod;
95 struct xencons_interface *intf = xencons->intf;
96 int sent = 0; 64 int sent = 0;
97 65
98 cons = intf->out_cons; 66 cons = intf->out_cons;
@@ -107,16 +75,13 @@ static int __write_console(struct xencons_info *xencons,
107 intf->out_prod = prod; 75 intf->out_prod = prod;
108 76
109 if (sent) 77 if (sent)
110 notify_daemon(xencons); 78 notify_daemon();
111 return sent; 79 return sent;
112} 80}
113 81
114static int domU_write_console(uint32_t vtermno, const char *data, int len) 82static int domU_write_console(uint32_t vtermno, const char *data, int len)
115{ 83{
116 int ret = len; 84 int ret = len;
117 struct xencons_info *cons = vtermno_to_xencons(vtermno);
118 if (cons == NULL)
119 return -EINVAL;
120 85
121 /* 86 /*
122 * Make sure the whole buffer is emitted, polling if 87 * Make sure the whole buffer is emitted, polling if
@@ -125,7 +90,7 @@ static int domU_write_console(uint32_t vtermno, const char *data, int len)
125 * kernel is crippled. 90 * kernel is crippled.
126 */ 91 */
127 while (len) { 92 while (len) {
128 int sent = __write_console(cons, data, len); 93 int sent = __write_console(data, len);
129 94
130 data += sent; 95 data += sent;
131 len -= sent; 96 len -= sent;
@@ -139,13 +104,9 @@ static int domU_write_console(uint32_t vtermno, const char *data, int len)
139 104
140static int domU_read_console(uint32_t vtermno, char *buf, int len) 105static int domU_read_console(uint32_t vtermno, char *buf, int len)
141{ 106{
142 struct xencons_interface *intf; 107 struct xencons_interface *intf = xencons_interface();
143 XENCONS_RING_IDX cons, prod; 108 XENCONS_RING_IDX cons, prod;
144 int recv = 0; 109 int recv = 0;
145 struct xencons_info *xencons = vtermno_to_xencons(vtermno);
146 if (xencons == NULL)
147 return -EINVAL;
148 intf = xencons->intf;
149 110
150 cons = intf->in_cons; 111 cons = intf->in_cons;
151 prod = intf->in_prod; 112 prod = intf->in_prod;
@@ -158,7 +119,7 @@ static int domU_read_console(uint32_t vtermno, char *buf, int len)
158 mb(); /* read ring before consuming */ 119 mb(); /* read ring before consuming */
159 intf->in_cons = cons; 120 intf->in_cons = cons;
160 121
161 notify_daemon(xencons); 122 notify_daemon();
162 return recv; 123 return recv;
163} 124}
164 125
@@ -196,410 +157,68 @@ static struct hv_ops dom0_hvc_ops = {
196 .notifier_hangup = notifier_hangup_irq, 157 .notifier_hangup = notifier_hangup_irq,
197}; 158};
198 159
199static int xen_hvm_console_init(void) 160static int __init xen_hvc_init(void)
200{
201 int r;
202 uint64_t v = 0;
203 unsigned long mfn;
204 struct xencons_info *info;
205
206 if (!xen_hvm_domain())
207 return -ENODEV;
208
209 info = vtermno_to_xencons(HVC_COOKIE);
210 if (!info) {
211 info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL | __GFP_ZERO);
212 if (!info)
213 return -ENOMEM;
214 } else if (info->intf != NULL) {
215 /* already configured */
216 return 0;
217 }
218 /*
219 * If the toolstack (or the hypervisor) hasn't set these values, the
220 * default value is 0. Even though mfn = 0 and evtchn = 0 are
221 * theoretically correct values, in practice they never are and they
222 * mean that a legacy toolstack hasn't initialized the pv console correctly.
223 */
224 r = hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v);
225 if (r < 0 || v == 0)
226 goto err;
227 info->evtchn = v;
228 v = 0;
229 r = hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
230 if (r < 0 || v == 0)
231 goto err;
232 mfn = v;
233 info->intf = ioremap(mfn << PAGE_SHIFT, PAGE_SIZE);
234 if (info->intf == NULL)
235 goto err;
236 info->vtermno = HVC_COOKIE;
237
238 spin_lock(&xencons_lock);
239 list_add_tail(&info->list, &xenconsoles);
240 spin_unlock(&xencons_lock);
241
242 return 0;
243err:
244 kfree(info);
245 return -ENODEV;
246}
247
248static int xen_pv_console_init(void)
249{ 161{
250 struct xencons_info *info; 162 struct hvc_struct *hp;
163 struct hv_ops *ops;
251 164
252 if (!xen_pv_domain()) 165 if (!xen_pv_domain())
253 return -ENODEV; 166 return -ENODEV;
254 167
255 if (!xen_start_info->console.domU.evtchn) 168 if (xen_initial_domain()) {
256 return -ENODEV; 169 ops = &dom0_hvc_ops;
257 170 xencons_irq = bind_virq_to_irq(VIRQ_CONSOLE, 0);
258 info = vtermno_to_xencons(HVC_COOKIE); 171 } else {
259 if (!info) { 172 if (!xen_start_info->console.domU.evtchn)
260 info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL | __GFP_ZERO); 173 return -ENODEV;
261 if (!info)
262 return -ENOMEM;
263 } else if (info->intf != NULL) {
264 /* already configured */
265 return 0;
266 }
267 info->evtchn = xen_start_info->console.domU.evtchn;
268 info->intf = mfn_to_virt(xen_start_info->console.domU.mfn);
269 info->vtermno = HVC_COOKIE;
270
271 spin_lock(&xencons_lock);
272 list_add_tail(&info->list, &xenconsoles);
273 spin_unlock(&xencons_lock);
274
275 return 0;
276}
277
278static int xen_initial_domain_console_init(void)
279{
280 struct xencons_info *info;
281
282 if (!xen_initial_domain())
283 return -ENODEV;
284
285 info = vtermno_to_xencons(HVC_COOKIE);
286 if (!info) {
287 info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL | __GFP_ZERO);
288 if (!info)
289 return -ENOMEM;
290 }
291
292 info->irq = bind_virq_to_irq(VIRQ_CONSOLE, 0);
293 info->vtermno = HVC_COOKIE;
294
295 spin_lock(&xencons_lock);
296 list_add_tail(&info->list, &xenconsoles);
297 spin_unlock(&xencons_lock);
298
299 return 0;
300}
301
302void xen_console_resume(void)
303{
304 struct xencons_info *info = vtermno_to_xencons(HVC_COOKIE);
305 if (info != NULL && info->irq)
306 rebind_evtchn_irq(info->evtchn, info->irq);
307}
308
309static void xencons_disconnect_backend(struct xencons_info *info)
310{
311 if (info->irq > 0)
312 unbind_from_irqhandler(info->irq, NULL);
313 info->irq = 0;
314 if (info->evtchn > 0)
315 xenbus_free_evtchn(info->xbdev, info->evtchn);
316 info->evtchn = 0;
317 if (info->gntref > 0)
318 gnttab_free_grant_references(info->gntref);
319 info->gntref = 0;
320 if (info->hvc != NULL)
321 hvc_remove(info->hvc);
322 info->hvc = NULL;
323}
324
325static void xencons_free(struct xencons_info *info)
326{
327 free_page((unsigned long)info->intf);
328 info->intf = NULL;
329 info->vtermno = 0;
330 kfree(info);
331}
332 174
333static int xen_console_remove(struct xencons_info *info) 175 ops = &domU_hvc_ops;
334{ 176 xencons_irq = bind_evtchn_to_irq(xen_start_info->console.domU.evtchn);
335 xencons_disconnect_backend(info);
336 spin_lock(&xencons_lock);
337 list_del(&info->list);
338 spin_unlock(&xencons_lock);
339 if (info->xbdev != NULL)
340 xencons_free(info);
341 else {
342 if (xen_hvm_domain())
343 iounmap(info->intf);
344 kfree(info);
345 } 177 }
346 return 0; 178 if (xencons_irq < 0)
347} 179 xencons_irq = 0; /* NO_IRQ */
348
349#ifdef CONFIG_HVC_XEN_FRONTEND
350static struct xenbus_driver xencons_driver;
351
352static int xencons_remove(struct xenbus_device *dev)
353{
354 return xen_console_remove(dev_get_drvdata(&dev->dev));
355}
356
357static int xencons_connect_backend(struct xenbus_device *dev,
358 struct xencons_info *info)
359{
360 int ret, evtchn, devid, ref, irq;
361 struct xenbus_transaction xbt;
362 grant_ref_t gref_head;
363 unsigned long mfn;
364
365 ret = xenbus_alloc_evtchn(dev, &evtchn);
366 if (ret)
367 return ret;
368 info->evtchn = evtchn;
369 irq = bind_evtchn_to_irq(evtchn);
370 if (irq < 0)
371 return irq;
372 info->irq = irq;
373 devid = dev->nodename[strlen(dev->nodename) - 1] - '0';
374 info->hvc = hvc_alloc(xenbus_devid_to_vtermno(devid),
375 irq, &domU_hvc_ops, 256);
376 if (IS_ERR(info->hvc))
377 return PTR_ERR(info->hvc);
378 if (xen_pv_domain())
379 mfn = virt_to_mfn(info->intf);
380 else 180 else
381 mfn = __pa(info->intf) >> PAGE_SHIFT; 181 irq_set_noprobe(xencons_irq);
382 ret = gnttab_alloc_grant_references(1, &gref_head);
383 if (ret < 0)
384 return ret;
385 info->gntref = gref_head;
386 ref = gnttab_claim_grant_reference(&gref_head);
387 if (ref < 0)
388 return ref;
389 gnttab_grant_foreign_access_ref(ref, info->xbdev->otherend_id,
390 mfn, 0);
391
392 again:
393 ret = xenbus_transaction_start(&xbt);
394 if (ret) {
395 xenbus_dev_fatal(dev, ret, "starting transaction");
396 return ret;
397 }
398 ret = xenbus_printf(xbt, dev->nodename, "ring-ref", "%d", ref);
399 if (ret)
400 goto error_xenbus;
401 ret = xenbus_printf(xbt, dev->nodename, "port", "%u",
402 evtchn);
403 if (ret)
404 goto error_xenbus;
405 ret = xenbus_printf(xbt, dev->nodename, "type", "ioemu");
406 if (ret)
407 goto error_xenbus;
408 ret = xenbus_transaction_end(xbt, 0);
409 if (ret) {
410 if (ret == -EAGAIN)
411 goto again;
412 xenbus_dev_fatal(dev, ret, "completing transaction");
413 return ret;
414 }
415 182
416 xenbus_switch_state(dev, XenbusStateInitialised); 183 hp = hvc_alloc(HVC_COOKIE, xencons_irq, ops, 256);
417 return 0; 184 if (IS_ERR(hp))
185 return PTR_ERR(hp);
418 186
419 error_xenbus: 187 hvc = hp;
420 xenbus_transaction_end(xbt, 1);
421 xenbus_dev_fatal(dev, ret, "writing xenstore");
422 return ret;
423}
424 188
425static int xencons_probe(struct xenbus_device *dev, 189 console_pfn = mfn_to_pfn(xen_start_info->console.domU.mfn);
426 const struct xenbus_device_id *id)
427{
428 int ret, devid;
429 struct xencons_info *info;
430
431 devid = dev->nodename[strlen(dev->nodename) - 1] - '0';
432 if (devid == 0)
433 return -ENODEV;
434
435 info = kzalloc(sizeof(struct xencons_info), GFP_KERNEL);
436 if (!info)
437 return -ENOMEM;
438 dev_set_drvdata(&dev->dev, info);
439 info->xbdev = dev;
440 info->vtermno = xenbus_devid_to_vtermno(devid);
441 info->intf = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
442 if (!info->intf)
443 goto error_nomem;
444
445 ret = xencons_connect_backend(dev, info);
446 if (ret < 0)
447 goto error;
448 spin_lock(&xencons_lock);
449 list_add_tail(&info->list, &xenconsoles);
450 spin_unlock(&xencons_lock);
451 190
452 return 0; 191 return 0;
453
454 error_nomem:
455 ret = -ENOMEM;
456 xenbus_dev_fatal(dev, ret, "allocating device memory");
457 error:
458 xencons_disconnect_backend(info);
459 xencons_free(info);
460 return ret;
461}
462
463static int xencons_resume(struct xenbus_device *dev)
464{
465 struct xencons_info *info = dev_get_drvdata(&dev->dev);
466
467 xencons_disconnect_backend(info);
468 memset(info->intf, 0, PAGE_SIZE);
469 return xencons_connect_backend(dev, info);
470}
471
472static void xencons_backend_changed(struct xenbus_device *dev,
473 enum xenbus_state backend_state)
474{
475 switch (backend_state) {
476 case XenbusStateReconfiguring:
477 case XenbusStateReconfigured:
478 case XenbusStateInitialising:
479 case XenbusStateInitialised:
480 case XenbusStateUnknown:
481 break;
482
483 case XenbusStateInitWait:
484 break;
485
486 case XenbusStateConnected:
487 xenbus_switch_state(dev, XenbusStateConnected);
488 break;
489
490 case XenbusStateClosed:
491 if (dev->state == XenbusStateClosed)
492 break;
493 /* Missed the backend's CLOSING state -- fallthrough */
494 case XenbusStateClosing:
495 xenbus_frontend_closed(dev);
496 break;
497 }
498} 192}
499 193
500static const struct xenbus_device_id xencons_ids[] = { 194void xen_console_resume(void)
501 { "console" },
502 { "" }
503};
504
505
506static DEFINE_XENBUS_DRIVER(xencons, "xenconsole",
507 .probe = xencons_probe,
508 .remove = xencons_remove,
509 .resume = xencons_resume,
510 .otherend_changed = xencons_backend_changed,
511);
512#endif /* CONFIG_HVC_XEN_FRONTEND */
513
514static int __init xen_hvc_init(void)
515{ 195{
516 int r; 196 if (xencons_irq)
517 struct xencons_info *info; 197 rebind_evtchn_irq(xen_start_info->console.domU.evtchn, xencons_irq);
518 const struct hv_ops *ops;
519
520 if (!xen_domain())
521 return -ENODEV;
522
523 if (xen_initial_domain()) {
524 ops = &dom0_hvc_ops;
525 r = xen_initial_domain_console_init();
526 if (r < 0)
527 return r;
528 info = vtermno_to_xencons(HVC_COOKIE);
529 } else {
530 ops = &domU_hvc_ops;
531 if (xen_hvm_domain())
532 r = xen_hvm_console_init();
533 else
534 r = xen_pv_console_init();
535 if (r < 0)
536 return r;
537
538 info = vtermno_to_xencons(HVC_COOKIE);
539 info->irq = bind_evtchn_to_irq(info->evtchn);
540 }
541 if (info->irq < 0)
542 info->irq = 0; /* NO_IRQ */
543 else
544 irq_set_noprobe(info->irq);
545
546 info->hvc = hvc_alloc(HVC_COOKIE, info->irq, ops, 256);
547 if (IS_ERR(info->hvc)) {
548 r = PTR_ERR(info->hvc);
549 spin_lock(&xencons_lock);
550 list_del(&info->list);
551 spin_unlock(&xencons_lock);
552 if (info->irq)
553 unbind_from_irqhandler(info->irq, NULL);
554 kfree(info);
555 return r;
556 }
557
558 r = 0;
559#ifdef CONFIG_HVC_XEN_FRONTEND
560 r = xenbus_register_frontend(&xencons_driver);
561#endif
562 return r;
563} 198}
564 199
565static void __exit xen_hvc_fini(void) 200static void __exit xen_hvc_fini(void)
566{ 201{
567 struct xencons_info *entry, *next; 202 if (hvc)
568 203 hvc_remove(hvc);
569 if (list_empty(&xenconsoles))
570 return;
571
572 list_for_each_entry_safe(entry, next, &xenconsoles, list) {
573 xen_console_remove(entry);
574 }
575} 204}
576 205
577static int xen_cons_init(void) 206static int xen_cons_init(void)
578{ 207{
579 const struct hv_ops *ops; 208 struct hv_ops *ops;
580 209
581 if (!xen_domain()) 210 if (!xen_pv_domain())
582 return 0; 211 return 0;
583 212
584 if (xen_initial_domain()) 213 if (xen_initial_domain())
585 ops = &dom0_hvc_ops; 214 ops = &dom0_hvc_ops;
586 else { 215 else
587 int r;
588 ops = &domU_hvc_ops; 216 ops = &domU_hvc_ops;
589 217
590 if (xen_hvm_domain())
591 r = xen_hvm_console_init();
592 else
593 r = xen_pv_console_init();
594 if (r < 0)
595 return r;
596 }
597
598 hvc_instantiate(HVC_COOKIE, 0, ops); 218 hvc_instantiate(HVC_COOKIE, 0, ops);
599 return 0; 219 return 0;
600} 220}
601 221
602
603module_init(xen_hvc_init); 222module_init(xen_hvc_init);
604module_exit(xen_hvc_fini); 223module_exit(xen_hvc_fini);
605console_initcall(xen_cons_init); 224console_initcall(xen_cons_init);
@@ -611,9 +230,6 @@ static void xenboot_write_console(struct console *console, const char *string,
611 unsigned int linelen, off = 0; 230 unsigned int linelen, off = 0;
612 const char *pos; 231 const char *pos;
613 232
614 if (!xen_pv_domain())
615 return;
616
617 dom0_write_console(0, string, len); 233 dom0_write_console(0, string, len);
618 234
619 if (xen_initial_domain()) 235 if (xen_initial_domain())
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 87763573395..4c8b6654693 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -261,7 +261,6 @@ static DEFINE_SPINLOCK(hvcs_pi_lock);
261 261
262/* One vty-server per hvcs_struct */ 262/* One vty-server per hvcs_struct */
263struct hvcs_struct { 263struct hvcs_struct {
264 struct tty_port port;
265 spinlock_t lock; 264 spinlock_t lock;
266 265
267 /* 266 /*
@@ -270,6 +269,9 @@ struct hvcs_struct {
270 */ 269 */
271 unsigned int index; 270 unsigned int index;
272 271
272 struct tty_struct *tty;
273 int open_count;
274
273 /* 275 /*
274 * Used to tell the driver kernel_thread what operations need to take 276 * Used to tell the driver kernel_thread what operations need to take
275 * place upon this hvcs_struct instance. 277 * place upon this hvcs_struct instance.
@@ -288,11 +290,12 @@ struct hvcs_struct {
288 int chars_in_buffer; 290 int chars_in_buffer;
289 291
290 /* 292 /*
291 * Any variable below is valid before a tty is connected and 293 * Any variable below the kref is valid before a tty is connected and
292 * stays valid after the tty is disconnected. These shouldn't be 294 * stays valid after the tty is disconnected. These shouldn't be
293 * whacked until the kobject refcount reaches zero though some entries 295 * whacked until the kobject refcount reaches zero though some entries
294 * may be changed via sysfs initiatives. 296 * may be changed via sysfs initiatives.
295 */ 297 */
298 struct kref kref; /* ref count & hvcs_struct lifetime */
296 int connected; /* is the vty-server currently connected to a vty? */ 299 int connected; /* is the vty-server currently connected to a vty? */
297 uint32_t p_unit_address; /* partner unit address */ 300 uint32_t p_unit_address; /* partner unit address */
298 uint32_t p_partition_ID; /* partner partition ID */ 301 uint32_t p_partition_ID; /* partner partition ID */
@@ -301,6 +304,9 @@ struct hvcs_struct {
301 struct vio_dev *vdev; 304 struct vio_dev *vdev;
302}; 305};
303 306
307/* Required to back map a kref to its containing object */
308#define from_kref(k) container_of(k, struct hvcs_struct, kref)
309
304static LIST_HEAD(hvcs_structs); 310static LIST_HEAD(hvcs_structs);
305static DEFINE_SPINLOCK(hvcs_structs_lock); 311static DEFINE_SPINLOCK(hvcs_structs_lock);
306static DEFINE_MUTEX(hvcs_init_mutex); 312static DEFINE_MUTEX(hvcs_init_mutex);
@@ -330,12 +336,12 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp);
330static void hvcs_close(struct tty_struct *tty, struct file *filp); 336static void hvcs_close(struct tty_struct *tty, struct file *filp);
331static void hvcs_hangup(struct tty_struct * tty); 337static void hvcs_hangup(struct tty_struct * tty);
332 338
333static int hvcs_probe(struct vio_dev *dev, 339static int __devinit hvcs_probe(struct vio_dev *dev,
334 const struct vio_device_id *id); 340 const struct vio_device_id *id);
335static int hvcs_remove(struct vio_dev *dev); 341static int __devexit hvcs_remove(struct vio_dev *dev);
336static int __init hvcs_module_init(void); 342static int __init hvcs_module_init(void);
337static void __exit hvcs_module_exit(void); 343static void __exit hvcs_module_exit(void);
338static int hvcs_initialize(void); 344static int __devinit hvcs_initialize(void);
339 345
340#define HVCS_SCHED_READ 0x00000001 346#define HVCS_SCHED_READ 0x00000001
341#define HVCS_QUICK_READ 0x00000002 347#define HVCS_QUICK_READ 0x00000002
@@ -416,7 +422,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
416 422
417 spin_lock_irqsave(&hvcsd->lock, flags); 423 spin_lock_irqsave(&hvcsd->lock, flags);
418 424
419 if (hvcsd->port.count > 0) { 425 if (hvcsd->open_count > 0) {
420 spin_unlock_irqrestore(&hvcsd->lock, flags); 426 spin_unlock_irqrestore(&hvcsd->lock, flags);
421 printk(KERN_INFO "HVCS: vterm state unchanged. " 427 printk(KERN_INFO "HVCS: vterm state unchanged. "
422 "The hvcs device node is still in use.\n"); 428 "The hvcs device node is still in use.\n");
@@ -558,7 +564,7 @@ static irqreturn_t hvcs_handle_interrupt(int irq, void *dev_instance)
558static void hvcs_try_write(struct hvcs_struct *hvcsd) 564static void hvcs_try_write(struct hvcs_struct *hvcsd)
559{ 565{
560 uint32_t unit_address = hvcsd->vdev->unit_address; 566 uint32_t unit_address = hvcsd->vdev->unit_address;
561 struct tty_struct *tty = hvcsd->port.tty; 567 struct tty_struct *tty = hvcsd->tty;
562 int sent; 568 int sent;
563 569
564 if (hvcsd->todo_mask & HVCS_TRY_WRITE) { 570 if (hvcsd->todo_mask & HVCS_TRY_WRITE) {
@@ -596,7 +602,7 @@ static int hvcs_io(struct hvcs_struct *hvcsd)
596 spin_lock_irqsave(&hvcsd->lock, flags); 602 spin_lock_irqsave(&hvcsd->lock, flags);
597 603
598 unit_address = hvcsd->vdev->unit_address; 604 unit_address = hvcsd->vdev->unit_address;
599 tty = hvcsd->port.tty; 605 tty = hvcsd->tty;
600 606
601 hvcs_try_write(hvcsd); 607 hvcs_try_write(hvcsd);
602 608
@@ -676,7 +682,7 @@ static int khvcsd(void *unused)
676 return 0; 682 return 0;
677} 683}
678 684
679static struct vio_device_id hvcs_driver_table[] = { 685static struct vio_device_id hvcs_driver_table[] __devinitdata= {
680 {"serial-server", "hvterm2"}, 686 {"serial-server", "hvterm2"},
681 { "", "" } 687 { "", "" }
682}; 688};
@@ -695,9 +701,10 @@ static void hvcs_return_index(int index)
695 hvcs_index_list[index] = -1; 701 hvcs_index_list[index] = -1;
696} 702}
697 703
698static void hvcs_destruct_port(struct tty_port *p) 704/* callback when the kref ref count reaches zero */
705static void destroy_hvcs_struct(struct kref *kref)
699{ 706{
700 struct hvcs_struct *hvcsd = container_of(p, struct hvcs_struct, port); 707 struct hvcs_struct *hvcsd = from_kref(kref);
701 struct vio_dev *vdev; 708 struct vio_dev *vdev;
702 unsigned long flags; 709 unsigned long flags;
703 710
@@ -734,10 +741,6 @@ static void hvcs_destruct_port(struct tty_port *p)
734 kfree(hvcsd); 741 kfree(hvcsd);
735} 742}
736 743
737static const struct tty_port_operations hvcs_port_ops = {
738 .destruct = hvcs_destruct_port,
739};
740
741static int hvcs_get_index(void) 744static int hvcs_get_index(void)
742{ 745{
743 int i; 746 int i;
@@ -756,7 +759,7 @@ static int hvcs_get_index(void)
756 return -1; 759 return -1;
757} 760}
758 761
759static int hvcs_probe( 762static int __devinit hvcs_probe(
760 struct vio_dev *dev, 763 struct vio_dev *dev,
761 const struct vio_device_id *id) 764 const struct vio_device_id *id)
762{ 765{
@@ -786,9 +789,10 @@ static int hvcs_probe(
786 if (!hvcsd) 789 if (!hvcsd)
787 return -ENODEV; 790 return -ENODEV;
788 791
789 tty_port_init(&hvcsd->port); 792
790 hvcsd->port.ops = &hvcs_port_ops;
791 spin_lock_init(&hvcsd->lock); 793 spin_lock_init(&hvcsd->lock);
794 /* Automatically incs the refcount the first time */
795 kref_init(&hvcsd->kref);
792 796
793 hvcsd->vdev = dev; 797 hvcsd->vdev = dev;
794 dev_set_drvdata(&dev->dev, hvcsd); 798 dev_set_drvdata(&dev->dev, hvcsd);
@@ -835,7 +839,7 @@ static int hvcs_probe(
835 return 0; 839 return 0;
836} 840}
837 841
838static int hvcs_remove(struct vio_dev *dev) 842static int __devexit hvcs_remove(struct vio_dev *dev)
839{ 843{
840 struct hvcs_struct *hvcsd = dev_get_drvdata(&dev->dev); 844 struct hvcs_struct *hvcsd = dev_get_drvdata(&dev->dev);
841 unsigned long flags; 845 unsigned long flags;
@@ -848,7 +852,7 @@ static int hvcs_remove(struct vio_dev *dev)
848 852
849 spin_lock_irqsave(&hvcsd->lock, flags); 853 spin_lock_irqsave(&hvcsd->lock, flags);
850 854
851 tty = hvcsd->port.tty; 855 tty = hvcsd->tty;
852 856
853 spin_unlock_irqrestore(&hvcsd->lock, flags); 857 spin_unlock_irqrestore(&hvcsd->lock, flags);
854 858
@@ -856,7 +860,7 @@ static int hvcs_remove(struct vio_dev *dev)
856 * Let the last holder of this object cause it to be removed, which 860 * Let the last holder of this object cause it to be removed, which
857 * would probably be tty_hangup below. 861 * would probably be tty_hangup below.
858 */ 862 */
859 tty_port_put(&hvcsd->port); 863 kref_put(&hvcsd->kref, destroy_hvcs_struct);
860 864
861 /* 865 /*
862 * The hangup is a scheduled function which will auto chain call 866 * The hangup is a scheduled function which will auto chain call
@@ -874,8 +878,11 @@ static int hvcs_remove(struct vio_dev *dev)
874static struct vio_driver hvcs_vio_driver = { 878static struct vio_driver hvcs_vio_driver = {
875 .id_table = hvcs_driver_table, 879 .id_table = hvcs_driver_table,
876 .probe = hvcs_probe, 880 .probe = hvcs_probe,
877 .remove = hvcs_remove, 881 .remove = __devexit_p(hvcs_remove),
878 .name = hvcs_driver_name, 882 .driver = {
883 .name = hvcs_driver_name,
884 .owner = THIS_MODULE,
885 }
879}; 886};
880 887
881/* Only called from hvcs_get_pi please */ 888/* Only called from hvcs_get_pi please */
@@ -1050,7 +1057,7 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
1050 * the conn was registered and now. 1057 * the conn was registered and now.
1051 */ 1058 */
1052 if (!(rc = request_irq(irq, &hvcs_handle_interrupt, 1059 if (!(rc = request_irq(irq, &hvcs_handle_interrupt,
1053 0, "ibmhvcs", hvcsd))) { 1060 IRQF_DISABLED, "ibmhvcs", hvcsd))) {
1054 /* 1061 /*
1055 * It is possible the vty-server was removed after the irq was 1062 * It is possible the vty-server was removed after the irq was
1056 * requested but before we have time to enable interrupts. 1063 * requested but before we have time to enable interrupts.
@@ -1083,39 +1090,50 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
1083 */ 1090 */
1084static struct hvcs_struct *hvcs_get_by_index(int index) 1091static struct hvcs_struct *hvcs_get_by_index(int index)
1085{ 1092{
1086 struct hvcs_struct *hvcsd; 1093 struct hvcs_struct *hvcsd = NULL;
1087 unsigned long flags; 1094 unsigned long flags;
1088 1095
1089 spin_lock(&hvcs_structs_lock); 1096 spin_lock(&hvcs_structs_lock);
1090 list_for_each_entry(hvcsd, &hvcs_structs, next) { 1097 /* We can immediately discard OOB requests */
1091 spin_lock_irqsave(&hvcsd->lock, flags); 1098 if (index >= 0 && index < HVCS_MAX_SERVER_ADAPTERS) {
1092 if (hvcsd->index == index) { 1099 list_for_each_entry(hvcsd, &hvcs_structs, next) {
1093 tty_port_get(&hvcsd->port); 1100 spin_lock_irqsave(&hvcsd->lock, flags);
1101 if (hvcsd->index == index) {
1102 kref_get(&hvcsd->kref);
1103 spin_unlock_irqrestore(&hvcsd->lock, flags);
1104 spin_unlock(&hvcs_structs_lock);
1105 return hvcsd;
1106 }
1094 spin_unlock_irqrestore(&hvcsd->lock, flags); 1107 spin_unlock_irqrestore(&hvcsd->lock, flags);
1095 spin_unlock(&hvcs_structs_lock);
1096 return hvcsd;
1097 } 1108 }
1098 spin_unlock_irqrestore(&hvcsd->lock, flags); 1109 hvcsd = NULL;
1099 } 1110 }
1100 spin_unlock(&hvcs_structs_lock);
1101 1111
1102 return NULL; 1112 spin_unlock(&hvcs_structs_lock);
1113 return hvcsd;
1103} 1114}
1104 1115
1105static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty) 1116/*
1117 * This is invoked via the tty_open interface when a user app connects to the
1118 * /dev node.
1119 */
1120static int hvcs_open(struct tty_struct *tty, struct file *filp)
1106{ 1121{
1107 struct hvcs_struct *hvcsd; 1122 struct hvcs_struct *hvcsd;
1108 struct vio_dev *vdev; 1123 int rc, retval = 0;
1109 unsigned long unit_address, flags; 1124 unsigned long flags;
1110 unsigned int irq; 1125 unsigned int irq;
1111 int retval; 1126 struct vio_dev *vdev;
1127 unsigned long unit_address;
1128
1129 if (tty->driver_data)
1130 goto fast_open;
1112 1131
1113 /* 1132 /*
1114 * Is there a vty-server that shares the same index? 1133 * Is there a vty-server that shares the same index?
1115 * This function increments the kref index. 1134 * This function increments the kref index.
1116 */ 1135 */
1117 hvcsd = hvcs_get_by_index(tty->index); 1136 if (!(hvcsd = hvcs_get_by_index(tty->index))) {
1118 if (!hvcsd) {
1119 printk(KERN_WARNING "HVCS: open failed, no device associated" 1137 printk(KERN_WARNING "HVCS: open failed, no device associated"
1120 " with tty->index %d.\n", tty->index); 1138 " with tty->index %d.\n", tty->index);
1121 return -ENODEV; 1139 return -ENODEV;
@@ -1123,17 +1141,12 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
1123 1141
1124 spin_lock_irqsave(&hvcsd->lock, flags); 1142 spin_lock_irqsave(&hvcsd->lock, flags);
1125 1143
1126 if (hvcsd->connected == 0) { 1144 if (hvcsd->connected == 0)
1127 retval = hvcs_partner_connect(hvcsd); 1145 if ((retval = hvcs_partner_connect(hvcsd)))
1128 if (retval) { 1146 goto error_release;
1129 spin_unlock_irqrestore(&hvcsd->lock, flags);
1130 printk(KERN_WARNING "HVCS: partner connect failed.\n");
1131 goto err_put;
1132 }
1133 }
1134 1147
1135 hvcsd->port.count = 0; 1148 hvcsd->open_count = 1;
1136 hvcsd->port.tty = tty; 1149 hvcsd->tty = tty;
1137 tty->driver_data = hvcsd; 1150 tty->driver_data = hvcsd;
1138 1151
1139 memset(&hvcsd->buffer[0], 0x00, HVCS_BUFF_LEN); 1152 memset(&hvcsd->buffer[0], 0x00, HVCS_BUFF_LEN);
@@ -1153,55 +1166,44 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
1153 * This must be done outside of the spinlock because it requests irqs 1166 * This must be done outside of the spinlock because it requests irqs
1154 * and will grab the spinlock and free the connection if it fails. 1167 * and will grab the spinlock and free the connection if it fails.
1155 */ 1168 */
1156 retval = hvcs_enable_device(hvcsd, unit_address, irq, vdev); 1169 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) {
1157 if (retval) { 1170 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1158 printk(KERN_WARNING "HVCS: enable device failed.\n"); 1171 printk(KERN_WARNING "HVCS: enable device failed.\n");
1159 goto err_put; 1172 return rc;
1160 } 1173 }
1161 1174
1162 retval = tty_port_install(&hvcsd->port, driver, tty); 1175 goto open_success;
1163 if (retval)
1164 goto err_irq;
1165 1176
1166 return 0; 1177fast_open:
1167err_irq: 1178 hvcsd = tty->driver_data;
1168 spin_lock_irqsave(&hvcsd->lock, flags);
1169 vio_disable_interrupts(hvcsd->vdev);
1170 spin_unlock_irqrestore(&hvcsd->lock, flags);
1171 free_irq(irq, hvcsd);
1172err_put:
1173 tty_port_put(&hvcsd->port);
1174
1175 return retval;
1176}
1177
1178/*
1179 * This is invoked via the tty_open interface when a user app connects to the
1180 * /dev node.
1181 */
1182static int hvcs_open(struct tty_struct *tty, struct file *filp)
1183{
1184 struct hvcs_struct *hvcsd = tty->driver_data;
1185 unsigned long flags;
1186 1179
1187 spin_lock_irqsave(&hvcsd->lock, flags); 1180 spin_lock_irqsave(&hvcsd->lock, flags);
1188 hvcsd->port.count++; 1181 kref_get(&hvcsd->kref);
1182 hvcsd->open_count++;
1189 hvcsd->todo_mask |= HVCS_SCHED_READ; 1183 hvcsd->todo_mask |= HVCS_SCHED_READ;
1190 spin_unlock_irqrestore(&hvcsd->lock, flags); 1184 spin_unlock_irqrestore(&hvcsd->lock, flags);
1191 1185
1186open_success:
1192 hvcs_kick(); 1187 hvcs_kick();
1193 1188
1194 printk(KERN_INFO "HVCS: vty-server@%X connection opened.\n", 1189 printk(KERN_INFO "HVCS: vty-server@%X connection opened.\n",
1195 hvcsd->vdev->unit_address ); 1190 hvcsd->vdev->unit_address );
1196 1191
1197 return 0; 1192 return 0;
1193
1194error_release:
1195 spin_unlock_irqrestore(&hvcsd->lock, flags);
1196 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1197
1198 printk(KERN_WARNING "HVCS: partner connect failed.\n");
1199 return retval;
1198} 1200}
1199 1201
1200static void hvcs_close(struct tty_struct *tty, struct file *filp) 1202static void hvcs_close(struct tty_struct *tty, struct file *filp)
1201{ 1203{
1202 struct hvcs_struct *hvcsd; 1204 struct hvcs_struct *hvcsd;
1203 unsigned long flags; 1205 unsigned long flags;
1204 int irq; 1206 int irq = NO_IRQ;
1205 1207
1206 /* 1208 /*
1207 * Is someone trying to close the file associated with this device after 1209 * Is someone trying to close the file associated with this device after
@@ -1221,7 +1223,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1221 hvcsd = tty->driver_data; 1223 hvcsd = tty->driver_data;
1222 1224
1223 spin_lock_irqsave(&hvcsd->lock, flags); 1225 spin_lock_irqsave(&hvcsd->lock, flags);
1224 if (--hvcsd->port.count == 0) { 1226 if (--hvcsd->open_count == 0) {
1225 1227
1226 vio_disable_interrupts(hvcsd->vdev); 1228 vio_disable_interrupts(hvcsd->vdev);
1227 1229
@@ -1230,12 +1232,12 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1230 * execute any operations on the TTY even though it is obligated 1232 * execute any operations on the TTY even though it is obligated
1231 * to deliver any pending I/O to the hypervisor. 1233 * to deliver any pending I/O to the hypervisor.
1232 */ 1234 */
1233 hvcsd->port.tty = NULL; 1235 hvcsd->tty = NULL;
1234 1236
1235 irq = hvcsd->vdev->irq; 1237 irq = hvcsd->vdev->irq;
1236 spin_unlock_irqrestore(&hvcsd->lock, flags); 1238 spin_unlock_irqrestore(&hvcsd->lock, flags);
1237 1239
1238 tty_wait_until_sent_from_close(tty, HVCS_CLOSE_WAIT); 1240 tty_wait_until_sent(tty, HVCS_CLOSE_WAIT);
1239 1241
1240 /* 1242 /*
1241 * This line is important because it tells hvcs_open that this 1243 * This line is important because it tells hvcs_open that this
@@ -1245,21 +1247,16 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1245 tty->driver_data = NULL; 1247 tty->driver_data = NULL;
1246 1248
1247 free_irq(irq, hvcsd); 1249 free_irq(irq, hvcsd);
1250 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1248 return; 1251 return;
1249 } else if (hvcsd->port.count < 0) { 1252 } else if (hvcsd->open_count < 0) {
1250 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d" 1253 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
1251 " is missmanaged.\n", 1254 " is missmanaged.\n",
1252 hvcsd->vdev->unit_address, hvcsd->port.count); 1255 hvcsd->vdev->unit_address, hvcsd->open_count);
1253 } 1256 }
1254 1257
1255 spin_unlock_irqrestore(&hvcsd->lock, flags); 1258 spin_unlock_irqrestore(&hvcsd->lock, flags);
1256} 1259 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1257
1258static void hvcs_cleanup(struct tty_struct * tty)
1259{
1260 struct hvcs_struct *hvcsd = tty->driver_data;
1261
1262 tty_port_put(&hvcsd->port);
1263} 1260}
1264 1261
1265static void hvcs_hangup(struct tty_struct * tty) 1262static void hvcs_hangup(struct tty_struct * tty)
@@ -1267,11 +1264,11 @@ static void hvcs_hangup(struct tty_struct * tty)
1267 struct hvcs_struct *hvcsd = tty->driver_data; 1264 struct hvcs_struct *hvcsd = tty->driver_data;
1268 unsigned long flags; 1265 unsigned long flags;
1269 int temp_open_count; 1266 int temp_open_count;
1270 int irq; 1267 int irq = NO_IRQ;
1271 1268
1272 spin_lock_irqsave(&hvcsd->lock, flags); 1269 spin_lock_irqsave(&hvcsd->lock, flags);
1273 /* Preserve this so that we know how many kref refs to put */ 1270 /* Preserve this so that we know how many kref refs to put */
1274 temp_open_count = hvcsd->port.count; 1271 temp_open_count = hvcsd->open_count;
1275 1272
1276 /* 1273 /*
1277 * Don't kref put inside the spinlock because the destruction 1274 * Don't kref put inside the spinlock because the destruction
@@ -1283,10 +1280,10 @@ static void hvcs_hangup(struct tty_struct * tty)
1283 hvcsd->todo_mask = 0; 1280 hvcsd->todo_mask = 0;
1284 1281
1285 /* I don't think the tty needs the hvcs_struct pointer after a hangup */ 1282 /* I don't think the tty needs the hvcs_struct pointer after a hangup */
1286 tty->driver_data = NULL; 1283 hvcsd->tty->driver_data = NULL;
1287 hvcsd->port.tty = NULL; 1284 hvcsd->tty = NULL;
1288 1285
1289 hvcsd->port.count = 0; 1286 hvcsd->open_count = 0;
1290 1287
1291 /* This will drop any buffered data on the floor which is OK in a hangup 1288 /* This will drop any buffered data on the floor which is OK in a hangup
1292 * scenario. */ 1289 * scenario. */
@@ -1311,7 +1308,7 @@ static void hvcs_hangup(struct tty_struct * tty)
1311 * NOTE: If this hangup was signaled from user space then the 1308 * NOTE: If this hangup was signaled from user space then the
1312 * final put will never happen. 1309 * final put will never happen.
1313 */ 1310 */
1314 tty_port_put(&hvcsd->port); 1311 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1315 } 1312 }
1316} 1313}
1317 1314
@@ -1357,7 +1354,7 @@ static int hvcs_write(struct tty_struct *tty,
1357 * the middle of a write operation? This is a crummy place to do this 1354 * the middle of a write operation? This is a crummy place to do this
1358 * but we want to keep it all in the spinlock. 1355 * but we want to keep it all in the spinlock.
1359 */ 1356 */
1360 if (hvcsd->port.count <= 0) { 1357 if (hvcsd->open_count <= 0) {
1361 spin_unlock_irqrestore(&hvcsd->lock, flags); 1358 spin_unlock_irqrestore(&hvcsd->lock, flags);
1362 return -ENODEV; 1359 return -ENODEV;
1363 } 1360 }
@@ -1431,7 +1428,7 @@ static int hvcs_write_room(struct tty_struct *tty)
1431{ 1428{
1432 struct hvcs_struct *hvcsd = tty->driver_data; 1429 struct hvcs_struct *hvcsd = tty->driver_data;
1433 1430
1434 if (!hvcsd || hvcsd->port.count <= 0) 1431 if (!hvcsd || hvcsd->open_count <= 0)
1435 return 0; 1432 return 0;
1436 1433
1437 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer; 1434 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
@@ -1445,10 +1442,8 @@ static int hvcs_chars_in_buffer(struct tty_struct *tty)
1445} 1442}
1446 1443
1447static const struct tty_operations hvcs_ops = { 1444static const struct tty_operations hvcs_ops = {
1448 .install = hvcs_install,
1449 .open = hvcs_open, 1445 .open = hvcs_open,
1450 .close = hvcs_close, 1446 .close = hvcs_close,
1451 .cleanup = hvcs_cleanup,
1452 .hangup = hvcs_hangup, 1447 .hangup = hvcs_hangup,
1453 .write = hvcs_write, 1448 .write = hvcs_write,
1454 .write_room = hvcs_write_room, 1449 .write_room = hvcs_write_room,
@@ -1478,7 +1473,7 @@ static void hvcs_free_index_list(void)
1478 hvcs_index_count = 0; 1473 hvcs_index_count = 0;
1479} 1474}
1480 1475
1481static int hvcs_initialize(void) 1476static int __devinit hvcs_initialize(void)
1482{ 1477{
1483 int rc, num_ttys_to_alloc; 1478 int rc, num_ttys_to_alloc;
1484 1479
@@ -1496,16 +1491,16 @@ static int hvcs_initialize(void)
1496 num_ttys_to_alloc = hvcs_parm_num_devs; 1491 num_ttys_to_alloc = hvcs_parm_num_devs;
1497 1492
1498 hvcs_tty_driver = alloc_tty_driver(num_ttys_to_alloc); 1493 hvcs_tty_driver = alloc_tty_driver(num_ttys_to_alloc);
1499 if (!hvcs_tty_driver) { 1494 if (!hvcs_tty_driver)
1500 mutex_unlock(&hvcs_init_mutex);
1501 return -ENOMEM; 1495 return -ENOMEM;
1502 }
1503 1496
1504 if (hvcs_alloc_index_list(num_ttys_to_alloc)) { 1497 if (hvcs_alloc_index_list(num_ttys_to_alloc)) {
1505 rc = -ENOMEM; 1498 rc = -ENOMEM;
1506 goto index_fail; 1499 goto index_fail;
1507 } 1500 }
1508 1501
1502 hvcs_tty_driver->owner = THIS_MODULE;
1503
1509 hvcs_tty_driver->driver_name = hvcs_driver_name; 1504 hvcs_tty_driver->driver_name = hvcs_driver_name;
1510 hvcs_tty_driver->name = hvcs_device_node; 1505 hvcs_tty_driver->name = hvcs_device_node;
1511 1506
@@ -1537,7 +1532,7 @@ static int hvcs_initialize(void)
1537 goto register_fail; 1532 goto register_fail;
1538 } 1533 }
1539 1534
1540 hvcs_pi_buff = (unsigned long *) __get_free_page(GFP_KERNEL); 1535 hvcs_pi_buff = kmalloc(PAGE_SIZE, GFP_KERNEL);
1541 if (!hvcs_pi_buff) { 1536 if (!hvcs_pi_buff) {
1542 rc = -ENOMEM; 1537 rc = -ENOMEM;
1543 goto buff_alloc_fail; 1538 goto buff_alloc_fail;
@@ -1553,7 +1548,7 @@ static int hvcs_initialize(void)
1553 return 0; 1548 return 0;
1554 1549
1555kthread_fail: 1550kthread_fail:
1556 free_page((unsigned long)hvcs_pi_buff); 1551 kfree(hvcs_pi_buff);
1557buff_alloc_fail: 1552buff_alloc_fail:
1558 tty_unregister_driver(hvcs_tty_driver); 1553 tty_unregister_driver(hvcs_tty_driver);
1559register_fail: 1554register_fail:
@@ -1602,7 +1597,7 @@ static void __exit hvcs_module_exit(void)
1602 kthread_stop(hvcs_task); 1597 kthread_stop(hvcs_task);
1603 1598
1604 spin_lock(&hvcs_pi_lock); 1599 spin_lock(&hvcs_pi_lock);
1605 free_page((unsigned long)hvcs_pi_buff); 1600 kfree(hvcs_pi_buff);
1606 hvcs_pi_buff = NULL; 1601 hvcs_pi_buff = NULL;
1607 spin_unlock(&hvcs_pi_lock); 1602 spin_unlock(&hvcs_pi_lock);
1608 1603
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index 68357a6e4de..c94e2f5853d 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -69,13 +69,14 @@
69#define __ALIGNED__ __attribute__((__aligned__(sizeof(long)))) 69#define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
70 70
71struct hvsi_struct { 71struct hvsi_struct {
72 struct tty_port port;
73 struct delayed_work writer; 72 struct delayed_work writer;
74 struct work_struct handshaker; 73 struct work_struct handshaker;
75 wait_queue_head_t emptyq; /* woken when outbuf is emptied */ 74 wait_queue_head_t emptyq; /* woken when outbuf is emptied */
76 wait_queue_head_t stateq; /* woken when HVSI state changes */ 75 wait_queue_head_t stateq; /* woken when HVSI state changes */
77 spinlock_t lock; 76 spinlock_t lock;
78 int index; 77 int index;
78 struct tty_struct *tty;
79 int count;
79 uint8_t throttle_buf[128]; 80 uint8_t throttle_buf[128];
80 uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */ 81 uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */
81 /* inbuf is for packet reassembly. leave a little room for leftovers. */ 82 /* inbuf is for packet reassembly. leave a little room for leftovers. */
@@ -236,7 +237,7 @@ static int hvsi_read(struct hvsi_struct *hp, char *buf, int count)
236} 237}
237 238
238static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet, 239static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
239 struct tty_struct *tty, struct hvsi_struct **to_handshake) 240 struct tty_struct **to_hangup, struct hvsi_struct **to_handshake)
240{ 241{
241 struct hvsi_control *header = (struct hvsi_control *)packet; 242 struct hvsi_control *header = (struct hvsi_control *)packet;
242 243
@@ -246,8 +247,9 @@ static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
246 /* CD went away; no more connection */ 247 /* CD went away; no more connection */
247 pr_debug("hvsi%i: CD dropped\n", hp->index); 248 pr_debug("hvsi%i: CD dropped\n", hp->index);
248 hp->mctrl &= TIOCM_CD; 249 hp->mctrl &= TIOCM_CD;
249 if (tty && !C_CLOCAL(tty)) 250 /* If userland hasn't done an open(2) yet, hp->tty is NULL. */
250 tty_hangup(tty); 251 if (hp->tty && !(hp->tty->flags & CLOCAL))
252 *to_hangup = hp->tty;
251 } 253 }
252 break; 254 break;
253 case VSV_CLOSE_PROTOCOL: 255 case VSV_CLOSE_PROTOCOL:
@@ -329,8 +331,7 @@ static void hvsi_recv_query(struct hvsi_struct *hp, uint8_t *packet)
329 } 331 }
330} 332}
331 333
332static void hvsi_insert_chars(struct hvsi_struct *hp, struct tty_struct *tty, 334static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)
333 const char *buf, int len)
334{ 335{
335 int i; 336 int i;
336 337
@@ -346,7 +347,7 @@ static void hvsi_insert_chars(struct hvsi_struct *hp, struct tty_struct *tty,
346 continue; 347 continue;
347 } 348 }
348#endif /* CONFIG_MAGIC_SYSRQ */ 349#endif /* CONFIG_MAGIC_SYSRQ */
349 tty_insert_flip_char(tty, c, 0); 350 tty_insert_flip_char(hp->tty, c, 0);
350 } 351 }
351} 352}
352 353
@@ -359,7 +360,7 @@ static void hvsi_insert_chars(struct hvsi_struct *hp, struct tty_struct *tty,
359 * revisited. 360 * revisited.
360 */ 361 */
361#define TTY_THRESHOLD_THROTTLE 128 362#define TTY_THRESHOLD_THROTTLE 128
362static bool hvsi_recv_data(struct hvsi_struct *hp, struct tty_struct *tty, 363static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
363 const uint8_t *packet) 364 const uint8_t *packet)
364{ 365{
365 const struct hvsi_header *header = (const struct hvsi_header *)packet; 366 const struct hvsi_header *header = (const struct hvsi_header *)packet;
@@ -370,14 +371,14 @@ static bool hvsi_recv_data(struct hvsi_struct *hp, struct tty_struct *tty,
370 pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data); 371 pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data);
371 372
372 if (datalen == 0) 373 if (datalen == 0)
373 return false; 374 return NULL;
374 375
375 if (overflow > 0) { 376 if (overflow > 0) {
376 pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__); 377 pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__);
377 datalen = TTY_THRESHOLD_THROTTLE; 378 datalen = TTY_THRESHOLD_THROTTLE;
378 } 379 }
379 380
380 hvsi_insert_chars(hp, tty, data, datalen); 381 hvsi_insert_chars(hp, data, datalen);
381 382
382 if (overflow > 0) { 383 if (overflow > 0) {
383 /* 384 /*
@@ -389,7 +390,7 @@ static bool hvsi_recv_data(struct hvsi_struct *hp, struct tty_struct *tty,
389 hp->n_throttle = overflow; 390 hp->n_throttle = overflow;
390 } 391 }
391 392
392 return true; 393 return hp->tty;
393} 394}
394 395
395/* 396/*
@@ -398,13 +399,14 @@ static bool hvsi_recv_data(struct hvsi_struct *hp, struct tty_struct *tty,
398 * machine during console handshaking (in which case tty = NULL and we ignore 399 * machine during console handshaking (in which case tty = NULL and we ignore
399 * incoming data). 400 * incoming data).
400 */ 401 */
401static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct *tty, 402static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
402 struct hvsi_struct **handshake) 403 struct tty_struct **hangup, struct hvsi_struct **handshake)
403{ 404{
404 uint8_t *packet = hp->inbuf; 405 uint8_t *packet = hp->inbuf;
405 int chunklen; 406 int chunklen;
406 bool flip = false;
407 407
408 *flip = NULL;
409 *hangup = NULL;
408 *handshake = NULL; 410 *handshake = NULL;
409 411
410 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ); 412 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ);
@@ -438,12 +440,12 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct *tty,
438 case VS_DATA_PACKET_HEADER: 440 case VS_DATA_PACKET_HEADER:
439 if (!is_open(hp)) 441 if (!is_open(hp))
440 break; 442 break;
441 if (tty == NULL) 443 if (hp->tty == NULL)
442 break; /* no tty buffer to put data in */ 444 break; /* no tty buffer to put data in */
443 flip = hvsi_recv_data(hp, tty, packet); 445 *flip = hvsi_recv_data(hp, packet);
444 break; 446 break;
445 case VS_CONTROL_PACKET_HEADER: 447 case VS_CONTROL_PACKET_HEADER:
446 hvsi_recv_control(hp, packet, tty, handshake); 448 hvsi_recv_control(hp, packet, hangup, handshake);
447 break; 449 break;
448 case VS_QUERY_RESPONSE_PACKET_HEADER: 450 case VS_QUERY_RESPONSE_PACKET_HEADER:
449 hvsi_recv_response(hp, packet); 451 hvsi_recv_response(hp, packet);
@@ -460,26 +462,28 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct *tty,
460 462
461 packet += len_packet(packet); 463 packet += len_packet(packet);
462 464
463 if (*handshake) { 465 if (*hangup || *handshake) {
464 pr_debug("%s: handshake\n", __func__); 466 pr_debug("%s: hangup or handshake\n", __func__);
467 /*
468 * we need to send the hangup now before receiving any more data.
469 * If we get "data, hangup, data", we can't deliver the second
470 * data before the hangup.
471 */
465 break; 472 break;
466 } 473 }
467 } 474 }
468 475
469 compact_inbuf(hp, packet); 476 compact_inbuf(hp, packet);
470 477
471 if (flip)
472 tty_flip_buffer_push(tty);
473
474 return 1; 478 return 1;
475} 479}
476 480
477static void hvsi_send_overflow(struct hvsi_struct *hp, struct tty_struct *tty) 481static void hvsi_send_overflow(struct hvsi_struct *hp)
478{ 482{
479 pr_debug("%s: delivering %i bytes overflow\n", __func__, 483 pr_debug("%s: delivering %i bytes overflow\n", __func__,
480 hp->n_throttle); 484 hp->n_throttle);
481 485
482 hvsi_insert_chars(hp, tty, hp->throttle_buf, hp->n_throttle); 486 hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle);
483 hp->n_throttle = 0; 487 hp->n_throttle = 0;
484} 488}
485 489
@@ -490,20 +494,35 @@ static void hvsi_send_overflow(struct hvsi_struct *hp, struct tty_struct *tty)
490static irqreturn_t hvsi_interrupt(int irq, void *arg) 494static irqreturn_t hvsi_interrupt(int irq, void *arg)
491{ 495{
492 struct hvsi_struct *hp = (struct hvsi_struct *)arg; 496 struct hvsi_struct *hp = (struct hvsi_struct *)arg;
497 struct tty_struct *flip;
498 struct tty_struct *hangup;
493 struct hvsi_struct *handshake; 499 struct hvsi_struct *handshake;
494 struct tty_struct *tty;
495 unsigned long flags; 500 unsigned long flags;
496 int again = 1; 501 int again = 1;
497 502
498 pr_debug("%s\n", __func__); 503 pr_debug("%s\n", __func__);
499 504
500 tty = tty_port_tty_get(&hp->port);
501
502 while (again) { 505 while (again) {
503 spin_lock_irqsave(&hp->lock, flags); 506 spin_lock_irqsave(&hp->lock, flags);
504 again = hvsi_load_chunk(hp, tty, &handshake); 507 again = hvsi_load_chunk(hp, &flip, &hangup, &handshake);
505 spin_unlock_irqrestore(&hp->lock, flags); 508 spin_unlock_irqrestore(&hp->lock, flags);
506 509
510 /*
511 * we have to call tty_flip_buffer_push() and tty_hangup() outside our
512 * spinlock. But we also have to keep going until we've read all the
513 * available data.
514 */
515
516 if (flip) {
517 /* there was data put in the tty flip buffer */
518 tty_flip_buffer_push(flip);
519 flip = NULL;
520 }
521
522 if (hangup) {
523 tty_hangup(hangup);
524 }
525
507 if (handshake) { 526 if (handshake) {
508 pr_debug("hvsi%i: attempting re-handshake\n", handshake->index); 527 pr_debug("hvsi%i: attempting re-handshake\n", handshake->index);
509 schedule_work(&handshake->handshaker); 528 schedule_work(&handshake->handshaker);
@@ -511,15 +530,18 @@ static irqreturn_t hvsi_interrupt(int irq, void *arg)
511 } 530 }
512 531
513 spin_lock_irqsave(&hp->lock, flags); 532 spin_lock_irqsave(&hp->lock, flags);
514 if (tty && hp->n_throttle && !test_bit(TTY_THROTTLED, &tty->flags)) { 533 if (hp->tty && hp->n_throttle
515 /* we weren't hung up and we weren't throttled, so we can 534 && (!test_bit(TTY_THROTTLED, &hp->tty->flags))) {
516 * deliver the rest now */ 535 /* we weren't hung up and we weren't throttled, so we can deliver the
517 hvsi_send_overflow(hp, tty); 536 * rest now */
518 tty_flip_buffer_push(tty); 537 flip = hp->tty;
538 hvsi_send_overflow(hp);
519 } 539 }
520 spin_unlock_irqrestore(&hp->lock, flags); 540 spin_unlock_irqrestore(&hp->lock, flags);
521 541
522 tty_kref_put(tty); 542 if (flip) {
543 tty_flip_buffer_push(flip);
544 }
523 545
524 return IRQ_HANDLED; 546 return IRQ_HANDLED;
525} 547}
@@ -715,11 +737,14 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
715{ 737{
716 struct hvsi_struct *hp; 738 struct hvsi_struct *hp;
717 unsigned long flags; 739 unsigned long flags;
740 int line = tty->index;
718 int ret; 741 int ret;
719 742
720 pr_debug("%s\n", __func__); 743 pr_debug("%s\n", __func__);
721 744
722 hp = &hvsi_ports[tty->index]; 745 if (line < 0 || line >= hvsi_count)
746 return -ENODEV;
747 hp = &hvsi_ports[line];
723 748
724 tty->driver_data = hp; 749 tty->driver_data = hp;
725 750
@@ -727,9 +752,9 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
727 if (hp->state == HVSI_FSP_DIED) 752 if (hp->state == HVSI_FSP_DIED)
728 return -EIO; 753 return -EIO;
729 754
730 tty_port_tty_set(&hp->port, tty);
731 spin_lock_irqsave(&hp->lock, flags); 755 spin_lock_irqsave(&hp->lock, flags);
732 hp->port.count++; 756 hp->tty = tty;
757 hp->count++;
733 atomic_set(&hp->seqno, 0); 758 atomic_set(&hp->seqno, 0);
734 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); 759 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
735 spin_unlock_irqrestore(&hp->lock, flags); 760 spin_unlock_irqrestore(&hp->lock, flags);
@@ -765,7 +790,7 @@ static void hvsi_flush_output(struct hvsi_struct *hp)
765 790
766 /* 'writer' could still be pending if it didn't see n_outbuf = 0 yet */ 791 /* 'writer' could still be pending if it didn't see n_outbuf = 0 yet */
767 cancel_delayed_work_sync(&hp->writer); 792 cancel_delayed_work_sync(&hp->writer);
768 flush_work(&hp->handshaker); 793 flush_work_sync(&hp->handshaker);
769 794
770 /* 795 /*
771 * it's also possible that our timeout expired and hvsi_write_worker 796 * it's also possible that our timeout expired and hvsi_write_worker
@@ -786,8 +811,8 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
786 811
787 spin_lock_irqsave(&hp->lock, flags); 812 spin_lock_irqsave(&hp->lock, flags);
788 813
789 if (--hp->port.count == 0) { 814 if (--hp->count == 0) {
790 tty_port_tty_set(&hp->port, NULL); 815 hp->tty = NULL;
791 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */ 816 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
792 817
793 /* only close down connection if it is not the console */ 818 /* only close down connection if it is not the console */
@@ -819,9 +844,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
819 844
820 spin_lock_irqsave(&hp->lock, flags); 845 spin_lock_irqsave(&hp->lock, flags);
821 } 846 }
822 } else if (hp->port.count < 0) 847 } else if (hp->count < 0)
823 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n", 848 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
824 hp - hvsi_ports, hp->port.count); 849 hp - hvsi_ports, hp->count);
825 850
826 spin_unlock_irqrestore(&hp->lock, flags); 851 spin_unlock_irqrestore(&hp->lock, flags);
827} 852}
@@ -833,11 +858,12 @@ static void hvsi_hangup(struct tty_struct *tty)
833 858
834 pr_debug("%s\n", __func__); 859 pr_debug("%s\n", __func__);
835 860
836 tty_port_tty_set(&hp->port, NULL);
837
838 spin_lock_irqsave(&hp->lock, flags); 861 spin_lock_irqsave(&hp->lock, flags);
839 hp->port.count = 0; 862
863 hp->count = 0;
840 hp->n_outbuf = 0; 864 hp->n_outbuf = 0;
865 hp->tty = NULL;
866
841 spin_unlock_irqrestore(&hp->lock, flags); 867 spin_unlock_irqrestore(&hp->lock, flags);
842} 868}
843 869
@@ -865,7 +891,6 @@ static void hvsi_write_worker(struct work_struct *work)
865{ 891{
866 struct hvsi_struct *hp = 892 struct hvsi_struct *hp =
867 container_of(work, struct hvsi_struct, writer.work); 893 container_of(work, struct hvsi_struct, writer.work);
868 struct tty_struct *tty;
869 unsigned long flags; 894 unsigned long flags;
870#ifdef DEBUG 895#ifdef DEBUG
871 static long start_j = 0; 896 static long start_j = 0;
@@ -899,11 +924,7 @@ static void hvsi_write_worker(struct work_struct *work)
899 start_j = 0; 924 start_j = 0;
900#endif /* DEBUG */ 925#endif /* DEBUG */
901 wake_up_all(&hp->emptyq); 926 wake_up_all(&hp->emptyq);
902 tty = tty_port_tty_get(&hp->port); 927 tty_wakeup(hp->tty);
903 if (tty) {
904 tty_wakeup(tty);
905 tty_kref_put(tty);
906 }
907 } 928 }
908 929
909out: 930out:
@@ -948,8 +969,8 @@ static int hvsi_write(struct tty_struct *tty,
948 * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls 969 * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls
949 * will see there is no room in outbuf and return. 970 * will see there is no room in outbuf and return.
950 */ 971 */
951 while ((count > 0) && (hvsi_write_room(tty) > 0)) { 972 while ((count > 0) && (hvsi_write_room(hp->tty) > 0)) {
952 int chunksize = min(count, hvsi_write_room(tty)); 973 int chunksize = min(count, hvsi_write_room(hp->tty));
953 974
954 BUG_ON(hp->n_outbuf < 0); 975 BUG_ON(hp->n_outbuf < 0);
955 memcpy(hp->outbuf + hp->n_outbuf, source, chunksize); 976 memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
@@ -996,16 +1017,19 @@ static void hvsi_unthrottle(struct tty_struct *tty)
996{ 1017{
997 struct hvsi_struct *hp = tty->driver_data; 1018 struct hvsi_struct *hp = tty->driver_data;
998 unsigned long flags; 1019 unsigned long flags;
1020 int shouldflip = 0;
999 1021
1000 pr_debug("%s\n", __func__); 1022 pr_debug("%s\n", __func__);
1001 1023
1002 spin_lock_irqsave(&hp->lock, flags); 1024 spin_lock_irqsave(&hp->lock, flags);
1003 if (hp->n_throttle) { 1025 if (hp->n_throttle) {
1004 hvsi_send_overflow(hp, tty); 1026 hvsi_send_overflow(hp);
1005 tty_flip_buffer_push(tty); 1027 shouldflip = 1;
1006 } 1028 }
1007 spin_unlock_irqrestore(&hp->lock, flags); 1029 spin_unlock_irqrestore(&hp->lock, flags);
1008 1030
1031 if (shouldflip)
1032 tty_flip_buffer_push(hp->tty);
1009 1033
1010 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); 1034 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
1011} 1035}
@@ -1064,6 +1088,7 @@ static int __init hvsi_init(void)
1064 if (!hvsi_driver) 1088 if (!hvsi_driver)
1065 return -ENOMEM; 1089 return -ENOMEM;
1066 1090
1091 hvsi_driver->owner = THIS_MODULE;
1067 hvsi_driver->driver_name = "hvsi"; 1092 hvsi_driver->driver_name = "hvsi";
1068 hvsi_driver->name = "hvsi"; 1093 hvsi_driver->name = "hvsi";
1069 hvsi_driver->major = HVSI_MAJOR; 1094 hvsi_driver->major = HVSI_MAJOR;
@@ -1080,9 +1105,7 @@ static int __init hvsi_init(void)
1080 struct hvsi_struct *hp = &hvsi_ports[i]; 1105 struct hvsi_struct *hp = &hvsi_ports[i];
1081 int ret = 1; 1106 int ret = 1;
1082 1107
1083 tty_port_link_device(&hp->port, hvsi_driver, i); 1108 ret = request_irq(hp->virq, hvsi_interrupt, IRQF_DISABLED, "hvsi", hp);
1084
1085 ret = request_irq(hp->virq, hvsi_interrupt, 0, "hvsi", hp);
1086 if (ret) 1109 if (ret)
1087 printk(KERN_ERR "HVSI: couldn't reserve irq 0x%x (error %i)\n", 1110 printk(KERN_ERR "HVSI: couldn't reserve irq 0x%x (error %i)\n",
1088 hp->virq, ret); 1111 hp->virq, ret);
@@ -1209,16 +1232,14 @@ static int __init hvsi_console_init(void)
1209 init_waitqueue_head(&hp->emptyq); 1232 init_waitqueue_head(&hp->emptyq);
1210 init_waitqueue_head(&hp->stateq); 1233 init_waitqueue_head(&hp->stateq);
1211 spin_lock_init(&hp->lock); 1234 spin_lock_init(&hp->lock);
1212 tty_port_init(&hp->port);
1213 hp->index = hvsi_count; 1235 hp->index = hvsi_count;
1214 hp->inbuf_end = hp->inbuf; 1236 hp->inbuf_end = hp->inbuf;
1215 hp->state = HVSI_CLOSED; 1237 hp->state = HVSI_CLOSED;
1216 hp->vtermno = *vtermno; 1238 hp->vtermno = *vtermno;
1217 hp->virq = irq_create_mapping(NULL, irq[0]); 1239 hp->virq = irq_create_mapping(NULL, irq[0]);
1218 if (hp->virq == 0) { 1240 if (hp->virq == NO_IRQ) {
1219 printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n", 1241 printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n",
1220 __func__, irq[0]); 1242 __func__, irq[0]);
1221 tty_port_destroy(&hp->port);
1222 continue; 1243 continue;
1223 } 1244 }
1224 1245
diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
index 3396eb9d57a..bd9b09827b2 100644
--- a/drivers/tty/hvc/hvsi_lib.c
+++ b/drivers/tty/hvc/hvsi_lib.c
@@ -183,7 +183,7 @@ int hvsilib_get_chars(struct hvsi_priv *pv, char *buf, int count)
183 unsigned int tries, read = 0; 183 unsigned int tries, read = 0;
184 184
185 if (WARN_ON(!pv)) 185 if (WARN_ON(!pv))
186 return -ENXIO; 186 return 0;
187 187
188 /* If we aren't open, don't do anything in order to avoid races 188 /* If we aren't open, don't do anything in order to avoid races
189 * with connection establishment. The hvc core will call this 189 * with connection establishment. The hvc core will call this
@@ -234,7 +234,7 @@ int hvsilib_put_chars(struct hvsi_priv *pv, const char *buf, int count)
234 int rc, adjcount = min(count, HVSI_MAX_OUTGOING_DATA); 234 int rc, adjcount = min(count, HVSI_MAX_OUTGOING_DATA);
235 235
236 if (WARN_ON(!pv)) 236 if (WARN_ON(!pv))
237 return -ENODEV; 237 return 0;
238 238
239 dp.hdr.type = VS_DATA_PACKET_HEADER; 239 dp.hdr.type = VS_DATA_PACKET_HEADER;
240 dp.hdr.len = adjcount + sizeof(struct hvsi_header); 240 dp.hdr.len = adjcount + sizeof(struct hvsi_header);
@@ -377,7 +377,7 @@ int hvsilib_open(struct hvsi_priv *pv, struct hvc_struct *hp)
377 pr_devel("HVSI@%x: open !\n", pv->termno); 377 pr_devel("HVSI@%x: open !\n", pv->termno);
378 378
379 /* Keep track of the tty data structure */ 379 /* Keep track of the tty data structure */
380 pv->tty = tty_port_tty_get(&hp->port); 380 pv->tty = tty_kref_get(hp->tty);
381 381
382 hvsilib_establish(pv); 382 hvsilib_establish(pv);
383 383
@@ -400,7 +400,7 @@ void hvsilib_close(struct hvsi_priv *pv, struct hvc_struct *hp)
400 spin_unlock_irqrestore(&hp->lock, flags); 400 spin_unlock_irqrestore(&hp->lock, flags);
401 401
402 /* Clear our own DTR */ 402 /* Clear our own DTR */
403 if (!pv->tty || (pv->tty->termios.c_cflag & HUPCL)) 403 if (!pv->tty || (pv->tty->termios->c_cflag & HUPCL))
404 hvsilib_write_mctrl(pv, 0); 404 hvsilib_write_mctrl(pv, 0);
405 405
406 /* Tear down the connection */ 406 /* Tear down the connection */
diff --git a/drivers/tty/ipwireless/hardware.c b/drivers/tty/ipwireless/hardware.c
index b4ba0670dc5..0aeb5a38d29 100644
--- a/drivers/tty/ipwireless/hardware.c
+++ b/drivers/tty/ipwireless/hardware.c
@@ -1729,7 +1729,7 @@ void ipwireless_hardware_free(struct ipw_hardware *hw)
1729 1729
1730 ipwireless_stop_interrupts(hw); 1730 ipwireless_stop_interrupts(hw);
1731 1731
1732 flush_work(&hw->work_rx); 1732 flush_work_sync(&hw->work_rx);
1733 1733
1734 for (i = 0; i < NL_NUM_OF_ADDRESSES; i++) 1734 for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
1735 if (hw->packet_assembler[i] != NULL) 1735 if (hw->packet_assembler[i] != NULL)
diff --git a/drivers/tty/ipwireless/network.c b/drivers/tty/ipwireless/network.c
index c0dfb642383..f7daeea598e 100644
--- a/drivers/tty/ipwireless/network.c
+++ b/drivers/tty/ipwireless/network.c
@@ -22,7 +22,7 @@
22#include <linux/ppp_channel.h> 22#include <linux/ppp_channel.h>
23#include <linux/ppp_defs.h> 23#include <linux/ppp_defs.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/ppp-ioctl.h> 25#include <linux/if_ppp.h>
26#include <linux/skbuff.h> 26#include <linux/skbuff.h>
27 27
28#include "network.h" 28#include "network.h"
@@ -274,12 +274,7 @@ static void do_go_online(struct work_struct *work_go_online)
274 network->xaccm[0] = ~0U; 274 network->xaccm[0] = ~0U;
275 network->xaccm[3] = 0x60000000U; 275 network->xaccm[3] = 0x60000000U;
276 network->raccm = ~0U; 276 network->raccm = ~0U;
277 if (ppp_register_channel(channel) < 0) { 277 ppp_register_channel(channel);
278 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
279 ": unable to register PPP channel\n");
280 kfree(channel);
281 return;
282 }
283 spin_lock_irqsave(&network->lock, flags); 278 spin_lock_irqsave(&network->lock, flags);
284 network->ppp_channel = channel; 279 network->ppp_channel = channel;
285 } 280 }
@@ -352,8 +347,6 @@ static struct sk_buff *ipw_packet_received_skb(unsigned char *data,
352 } 347 }
353 348
354 skb = dev_alloc_skb(length + 4); 349 skb = dev_alloc_skb(length + 4);
355 if (skb == NULL)
356 return NULL;
357 skb_reserve(skb, 2); 350 skb_reserve(skb, 2);
358 memcpy(skb_put(skb, length), data, length); 351 memcpy(skb_put(skb, length), data, length);
359 352
@@ -399,8 +392,7 @@ void ipwireless_network_packet_received(struct ipw_network *network,
399 392
400 /* Send the data to the ppp_generic module. */ 393 /* Send the data to the ppp_generic module. */
401 skb = ipw_packet_received_skb(data, length); 394 skb = ipw_packet_received_skb(data, length);
402 if (skb) 395 ppp_input(network->ppp_channel, skb);
403 ppp_input(network->ppp_channel, skb);
404 } else 396 } else
405 spin_unlock_irqrestore(&network->lock, 397 spin_unlock_irqrestore(&network->lock,
406 flags); 398 flags);
@@ -438,8 +430,8 @@ void ipwireless_network_free(struct ipw_network *network)
438 network->shutting_down = 1; 430 network->shutting_down = 1;
439 431
440 ipwireless_ppp_close(network); 432 ipwireless_ppp_close(network);
441 flush_work(&network->work_go_online); 433 flush_work_sync(&network->work_go_online);
442 flush_work(&network->work_go_offline); 434 flush_work_sync(&network->work_go_offline);
443 435
444 ipwireless_stop_interrupts(network->hardware); 436 ipwireless_stop_interrupts(network->hardware);
445 ipwireless_associate_network(network->hardware, NULL); 437 ipwireless_associate_network(network->hardware, NULL);
diff --git a/drivers/tty/ipwireless/setup_protocol.h b/drivers/tty/ipwireless/setup_protocol.h
index 002c34e7252..9d6bcc77c73 100644
--- a/drivers/tty/ipwireless/setup_protocol.h
+++ b/drivers/tty/ipwireless/setup_protocol.h
@@ -59,7 +59,7 @@ struct tl_setup_config_done_msg {
59 unsigned char sig_no; /* TL_SETUP_SIGNO_CONFIG_DONE_MSG */ 59 unsigned char sig_no; /* TL_SETUP_SIGNO_CONFIG_DONE_MSG */
60} __attribute__ ((__packed__)); 60} __attribute__ ((__packed__));
61 61
62/* Asynchronous messages */ 62/* Asyncronous messages */
63struct tl_setup_open_msg { 63struct tl_setup_open_msg {
64 unsigned char sig_no; /* TL_SETUP_SIGNO_OPEN_MSG */ 64 unsigned char sig_no; /* TL_SETUP_SIGNO_OPEN_MSG */
65 unsigned char port_no; 65 unsigned char port_no;
diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
index 2cde13ddf9f..ef92869502a 100644
--- a/drivers/tty/ipwireless/tty.c
+++ b/drivers/tty/ipwireless/tty.c
@@ -21,7 +21,7 @@
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/ppp_defs.h> 22#include <linux/ppp_defs.h>
23#include <linux/if.h> 23#include <linux/if.h>
24#include <linux/ppp-ioctl.h> 24#include <linux/if_ppp.h>
25#include <linux/sched.h> 25#include <linux/sched.h>
26#include <linux/serial.h> 26#include <linux/serial.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
@@ -44,13 +44,14 @@
44#define TTYTYPE_RAS_RAW (2) 44#define TTYTYPE_RAS_RAW (2)
45 45
46struct ipw_tty { 46struct ipw_tty {
47 struct tty_port port;
48 int index; 47 int index;
49 struct ipw_hardware *hardware; 48 struct ipw_hardware *hardware;
50 unsigned int channel_idx; 49 unsigned int channel_idx;
51 unsigned int secondary_channel_idx; 50 unsigned int secondary_channel_idx;
52 int tty_type; 51 int tty_type;
53 struct ipw_network *network; 52 struct ipw_network *network;
53 struct tty_struct *linux_tty;
54 int open_count;
54 unsigned int control_lines; 55 unsigned int control_lines;
55 struct mutex ipw_tty_mutex; 56 struct mutex ipw_tty_mutex;
56 int tx_bytes_queued; 57 int tx_bytes_queued;
@@ -72,23 +73,50 @@ static char *tty_type_name(int tty_type)
72 return channel_names[tty_type]; 73 return channel_names[tty_type];
73} 74}
74 75
75static struct ipw_tty *get_tty(int index) 76static void report_registering(struct ipw_tty *tty)
76{ 77{
77 /* 78 char *iftype = tty_type_name(tty->tty_type);
78 * The 'ras_raw' channel is only available when 'loopback' mode 79
79 * is enabled. 80 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
80 * Number of minor starts with 16 (_RANGE * _RAS_RAW). 81 ": registering %s device ttyIPWp%d\n", iftype, tty->index);
81 */ 82}
82 if (!ipwireless_loopback && index >= 83
83 IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW) 84static void report_deregistering(struct ipw_tty *tty)
84 return NULL; 85{
86 char *iftype = tty_type_name(tty->tty_type);
85 87
86 return ttys[index]; 88 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
89 ": deregistering %s device ttyIPWp%d\n", iftype,
90 tty->index);
91}
92
93static struct ipw_tty *get_tty(int minor)
94{
95 if (minor < ipw_tty_driver->minor_start
96 || minor >= ipw_tty_driver->minor_start +
97 IPWIRELESS_PCMCIA_MINORS)
98 return NULL;
99 else {
100 int minor_offset = minor - ipw_tty_driver->minor_start;
101
102 /*
103 * The 'ras_raw' channel is only available when 'loopback' mode
104 * is enabled.
105 * Number of minor starts with 16 (_RANGE * _RAS_RAW).
106 */
107 if (!ipwireless_loopback &&
108 minor_offset >=
109 IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW)
110 return NULL;
111
112 return ttys[minor_offset];
113 }
87} 114}
88 115
89static int ipw_open(struct tty_struct *linux_tty, struct file *filp) 116static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
90{ 117{
91 struct ipw_tty *tty = get_tty(linux_tty->index); 118 int minor = linux_tty->index;
119 struct ipw_tty *tty = get_tty(minor);
92 120
93 if (!tty) 121 if (!tty)
94 return -ENODEV; 122 return -ENODEV;
@@ -99,12 +127,12 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
99 mutex_unlock(&tty->ipw_tty_mutex); 127 mutex_unlock(&tty->ipw_tty_mutex);
100 return -ENODEV; 128 return -ENODEV;
101 } 129 }
102 if (tty->port.count == 0) 130 if (tty->open_count == 0)
103 tty->tx_bytes_queued = 0; 131 tty->tx_bytes_queued = 0;
104 132
105 tty->port.count++; 133 tty->open_count++;
106 134
107 tty->port.tty = linux_tty; 135 tty->linux_tty = linux_tty;
108 linux_tty->driver_data = tty; 136 linux_tty->driver_data = tty;
109 linux_tty->low_latency = 1; 137 linux_tty->low_latency = 1;
110 138
@@ -118,13 +146,13 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
118 146
119static void do_ipw_close(struct ipw_tty *tty) 147static void do_ipw_close(struct ipw_tty *tty)
120{ 148{
121 tty->port.count--; 149 tty->open_count--;
122 150
123 if (tty->port.count == 0) { 151 if (tty->open_count == 0) {
124 struct tty_struct *linux_tty = tty->port.tty; 152 struct tty_struct *linux_tty = tty->linux_tty;
125 153
126 if (linux_tty != NULL) { 154 if (linux_tty != NULL) {
127 tty->port.tty = NULL; 155 tty->linux_tty = NULL;
128 linux_tty->driver_data = NULL; 156 linux_tty->driver_data = NULL;
129 157
130 if (tty->tty_type == TTYTYPE_MODEM) 158 if (tty->tty_type == TTYTYPE_MODEM)
@@ -141,7 +169,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
141 return; 169 return;
142 170
143 mutex_lock(&tty->ipw_tty_mutex); 171 mutex_lock(&tty->ipw_tty_mutex);
144 if (tty->port.count == 0) { 172 if (tty->open_count == 0) {
145 mutex_unlock(&tty->ipw_tty_mutex); 173 mutex_unlock(&tty->ipw_tty_mutex);
146 return; 174 return;
147 } 175 }
@@ -164,13 +192,13 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
164 int work = 0; 192 int work = 0;
165 193
166 mutex_lock(&tty->ipw_tty_mutex); 194 mutex_lock(&tty->ipw_tty_mutex);
167 linux_tty = tty->port.tty; 195 linux_tty = tty->linux_tty;
168 if (linux_tty == NULL) { 196 if (linux_tty == NULL) {
169 mutex_unlock(&tty->ipw_tty_mutex); 197 mutex_unlock(&tty->ipw_tty_mutex);
170 return; 198 return;
171 } 199 }
172 200
173 if (!tty->port.count) { 201 if (!tty->open_count) {
174 mutex_unlock(&tty->ipw_tty_mutex); 202 mutex_unlock(&tty->ipw_tty_mutex);
175 return; 203 return;
176 } 204 }
@@ -212,7 +240,7 @@ static int ipw_write(struct tty_struct *linux_tty,
212 return -ENODEV; 240 return -ENODEV;
213 241
214 mutex_lock(&tty->ipw_tty_mutex); 242 mutex_lock(&tty->ipw_tty_mutex);
215 if (!tty->port.count) { 243 if (!tty->open_count) {
216 mutex_unlock(&tty->ipw_tty_mutex); 244 mutex_unlock(&tty->ipw_tty_mutex);
217 return -EINVAL; 245 return -EINVAL;
218 } 246 }
@@ -252,7 +280,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
252 if (!tty) 280 if (!tty)
253 return -ENODEV; 281 return -ENODEV;
254 282
255 if (!tty->port.count) 283 if (!tty->open_count)
256 return -EINVAL; 284 return -EINVAL;
257 285
258 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued; 286 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
@@ -294,7 +322,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
294 if (!tty) 322 if (!tty)
295 return 0; 323 return 0;
296 324
297 if (!tty->port.count) 325 if (!tty->open_count)
298 return 0; 326 return 0;
299 327
300 return tty->tx_bytes_queued; 328 return tty->tx_bytes_queued;
@@ -375,7 +403,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
375 if (!tty) 403 if (!tty)
376 return -ENODEV; 404 return -ENODEV;
377 405
378 if (!tty->port.count) 406 if (!tty->open_count)
379 return -EINVAL; 407 return -EINVAL;
380 408
381 return get_control_lines(tty); 409 return get_control_lines(tty);
@@ -391,7 +419,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
391 if (!tty) 419 if (!tty)
392 return -ENODEV; 420 return -ENODEV;
393 421
394 if (!tty->port.count) 422 if (!tty->open_count)
395 return -EINVAL; 423 return -EINVAL;
396 424
397 return set_control_lines(tty, set, clear); 425 return set_control_lines(tty, set, clear);
@@ -405,7 +433,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
405 if (!tty) 433 if (!tty)
406 return -ENODEV; 434 return -ENODEV;
407 435
408 if (!tty->port.count) 436 if (!tty->open_count)
409 return -EINVAL; 437 return -EINVAL;
410 438
411 /* FIXME: Exactly how is the tty object locked here .. */ 439 /* FIXME: Exactly how is the tty object locked here .. */
@@ -474,21 +502,16 @@ static int add_tty(int j,
474 ttys[j]->network = network; 502 ttys[j]->network = network;
475 ttys[j]->tty_type = tty_type; 503 ttys[j]->tty_type = tty_type;
476 mutex_init(&ttys[j]->ipw_tty_mutex); 504 mutex_init(&ttys[j]->ipw_tty_mutex);
477 tty_port_init(&ttys[j]->port);
478 505
479 tty_port_register_device(&ttys[j]->port, ipw_tty_driver, j, NULL); 506 tty_register_device(ipw_tty_driver, j, NULL);
480 ipwireless_associate_network_tty(network, channel_idx, ttys[j]); 507 ipwireless_associate_network_tty(network, channel_idx, ttys[j]);
481 508
482 if (secondary_channel_idx != -1) 509 if (secondary_channel_idx != -1)
483 ipwireless_associate_network_tty(network, 510 ipwireless_associate_network_tty(network,
484 secondary_channel_idx, 511 secondary_channel_idx,
485 ttys[j]); 512 ttys[j]);
486 /* check if we provide raw device (if loopback is enabled) */ 513 if (get_tty(j + ipw_tty_driver->minor_start) == ttys[j])
487 if (get_tty(j)) 514 report_registering(ttys[j]);
488 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
489 ": registering %s device ttyIPWp%d\n",
490 tty_type_name(tty_type), j);
491
492 return 0; 515 return 0;
493} 516}
494 517
@@ -547,26 +570,23 @@ void ipwireless_tty_free(struct ipw_tty *tty)
547 570
548 if (ttyj) { 571 if (ttyj) {
549 mutex_lock(&ttyj->ipw_tty_mutex); 572 mutex_lock(&ttyj->ipw_tty_mutex);
550 if (get_tty(j)) 573 if (get_tty(j + ipw_tty_driver->minor_start) == ttyj)
551 printk(KERN_INFO IPWIRELESS_PCCARD_NAME 574 report_deregistering(ttyj);
552 ": deregistering %s device ttyIPWp%d\n",
553 tty_type_name(ttyj->tty_type), j);
554 ttyj->closing = 1; 575 ttyj->closing = 1;
555 if (ttyj->port.tty != NULL) { 576 if (ttyj->linux_tty != NULL) {
556 mutex_unlock(&ttyj->ipw_tty_mutex); 577 mutex_unlock(&ttyj->ipw_tty_mutex);
557 tty_vhangup(ttyj->port.tty); 578 tty_hangup(ttyj->linux_tty);
579 /* Wait till the tty_hangup has completed */
580 flush_work_sync(&ttyj->linux_tty->hangup_work);
558 /* FIXME: Exactly how is the tty object locked here 581 /* FIXME: Exactly how is the tty object locked here
559 against a parallel ioctl etc */ 582 against a parallel ioctl etc */
560 /* FIXME2: hangup does not mean all processes
561 * are gone */
562 mutex_lock(&ttyj->ipw_tty_mutex); 583 mutex_lock(&ttyj->ipw_tty_mutex);
563 } 584 }
564 while (ttyj->port.count) 585 while (ttyj->open_count)
565 do_ipw_close(ttyj); 586 do_ipw_close(ttyj);
566 ipwireless_disassociate_network_ttys(network, 587 ipwireless_disassociate_network_ttys(network,
567 ttyj->channel_idx); 588 ttyj->channel_idx);
568 tty_unregister_device(ipw_tty_driver, j); 589 tty_unregister_device(ipw_tty_driver, j);
569 tty_port_destroy(&ttyj->port);
570 ttys[j] = NULL; 590 ttys[j] = NULL;
571 mutex_unlock(&ttyj->ipw_tty_mutex); 591 mutex_unlock(&ttyj->ipw_tty_mutex);
572 kfree(ttyj); 592 kfree(ttyj);
@@ -594,6 +614,7 @@ int ipwireless_tty_init(void)
594 if (!ipw_tty_driver) 614 if (!ipw_tty_driver)
595 return -ENOMEM; 615 return -ENOMEM;
596 616
617 ipw_tty_driver->owner = THIS_MODULE;
597 ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME; 618 ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME;
598 ipw_tty_driver->name = "ttyIPWp"; 619 ipw_tty_driver->name = "ttyIPWp";
599 ipw_tty_driver->major = 0; 620 ipw_tty_driver->major = 0;
@@ -651,8 +672,8 @@ ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
651 */ 672 */
652 if ((old_control_lines & IPW_CONTROL_LINE_DCD) 673 if ((old_control_lines & IPW_CONTROL_LINE_DCD)
653 && !(tty->control_lines & IPW_CONTROL_LINE_DCD) 674 && !(tty->control_lines & IPW_CONTROL_LINE_DCD)
654 && tty->port.tty) { 675 && tty->linux_tty) {
655 tty_hangup(tty->port.tty); 676 tty_hangup(tty->linux_tty);
656 } 677 }
657} 678}
658 679
diff --git a/drivers/tty/isicom.c b/drivers/tty/isicom.c
index 3205b2e9090..db1cf9c328d 100644
--- a/drivers/tty/isicom.c
+++ b/drivers/tty/isicom.c
@@ -102,7 +102,7 @@
102 * You can find the original tools for this direct from Multitech 102 * You can find the original tools for this direct from Multitech
103 * ftp://ftp.multitech.com/ISI-Cards/ 103 * ftp://ftp.multitech.com/ISI-Cards/
104 * 104 *
105 * Having installed the cards the module options (/etc/modprobe.d/) 105 * Having installed the cards the module options (/etc/modprobe.conf)
106 * 106 *
107 * options isicom io=card1,card2,card3,card4 irq=card1,card2,card3,card4 107 * options isicom io=card1,card2,card3,card4 irq=card1,card2,card3,card4
108 * 108 *
@@ -133,6 +133,7 @@
133 133
134#include <linux/uaccess.h> 134#include <linux/uaccess.h>
135#include <linux/io.h> 135#include <linux/io.h>
136#include <asm/system.h>
136 137
137#include <linux/pci.h> 138#include <linux/pci.h>
138 139
@@ -148,7 +149,7 @@
148#endif 149#endif
149 150
150static int isicom_probe(struct pci_dev *, const struct pci_device_id *); 151static int isicom_probe(struct pci_dev *, const struct pci_device_id *);
151static void isicom_remove(struct pci_dev *); 152static void __devexit isicom_remove(struct pci_dev *);
152 153
153static struct pci_device_id isicom_pci_tbl[] = { 154static struct pci_device_id isicom_pci_tbl[] = {
154 { PCI_DEVICE(VENDOR_ID, 0x2028) }, 155 { PCI_DEVICE(VENDOR_ID, 0x2028) },
@@ -168,7 +169,7 @@ static struct pci_driver isicom_driver = {
168 .name = "isicom", 169 .name = "isicom",
169 .id_table = isicom_pci_tbl, 170 .id_table = isicom_pci_tbl,
170 .probe = isicom_probe, 171 .probe = isicom_probe,
171 .remove = isicom_remove 172 .remove = __devexit_p(isicom_remove)
172}; 173};
173 174
174static int prev_card = 3; /* start servicing isi_card[0] */ 175static int prev_card = 3; /* start servicing isi_card[0] */
@@ -600,10 +601,10 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
600 port->status &= ~ISI_DCD; 601 port->status &= ~ISI_DCD;
601 } 602 }
602 603
603 if (tty_port_cts_enabled(&port->port)) { 604 if (port->port.flags & ASYNC_CTS_FLOW) {
604 if (tty->hw_stopped) { 605 if (tty->hw_stopped) {
605 if (header & ISI_CTS) { 606 if (header & ISI_CTS) {
606 tty->hw_stopped = 0; 607 port->port.tty->hw_stopped = 0;
607 /* start tx ing */ 608 /* start tx ing */
608 port->status |= (ISI_TXOK 609 port->status |= (ISI_TXOK
609 | ISI_CTS); 610 | ISI_CTS);
@@ -702,7 +703,7 @@ static void isicom_config_port(struct tty_struct *tty)
702 703
703 /* 1,2,3,4 => 57.6, 115.2, 230, 460 kbps resp. */ 704 /* 1,2,3,4 => 57.6, 115.2, 230, 460 kbps resp. */
704 if (baud < 1 || baud > 4) 705 if (baud < 1 || baud > 4)
705 tty->termios.c_cflag &= ~CBAUDEX; 706 tty->termios->c_cflag &= ~CBAUDEX;
706 else 707 else
707 baud += 15; 708 baud += 15;
708 } 709 }
@@ -848,6 +849,8 @@ static struct tty_port *isicom_find_port(struct tty_struct *tty)
848 unsigned int board; 849 unsigned int board;
849 int line = tty->index; 850 int line = tty->index;
850 851
852 if (line < 0 || line > PORT_COUNT-1)
853 return NULL;
851 board = BOARD(line); 854 board = BOARD(line);
852 card = &isi_card[board]; 855 card = &isi_card[board];
853 856
@@ -1196,8 +1199,8 @@ static void isicom_set_termios(struct tty_struct *tty,
1196 if (isicom_paranoia_check(port, tty->name, "isicom_set_termios")) 1199 if (isicom_paranoia_check(port, tty->name, "isicom_set_termios"))
1197 return; 1200 return;
1198 1201
1199 if (tty->termios.c_cflag == old_termios->c_cflag && 1202 if (tty->termios->c_cflag == old_termios->c_cflag &&
1200 tty->termios.c_iflag == old_termios->c_iflag) 1203 tty->termios->c_iflag == old_termios->c_iflag)
1201 return; 1204 return;
1202 1205
1203 spin_lock_irqsave(&port->card->card_lock, flags); 1206 spin_lock_irqsave(&port->card->card_lock, flags);
@@ -1205,7 +1208,7 @@ static void isicom_set_termios(struct tty_struct *tty,
1205 spin_unlock_irqrestore(&port->card->card_lock, flags); 1208 spin_unlock_irqrestore(&port->card->card_lock, flags);
1206 1209
1207 if ((old_termios->c_cflag & CRTSCTS) && 1210 if ((old_termios->c_cflag & CRTSCTS) &&
1208 !(tty->termios.c_cflag & CRTSCTS)) { 1211 !(tty->termios->c_cflag & CRTSCTS)) {
1209 tty->hw_stopped = 0; 1212 tty->hw_stopped = 0;
1210 isicom_start(tty); 1213 isicom_start(tty);
1211 } 1214 }
@@ -1307,7 +1310,7 @@ static const struct tty_port_operations isicom_port_ops = {
1307 .shutdown = isicom_shutdown, 1310 .shutdown = isicom_shutdown,
1308}; 1311};
1309 1312
1310static int reset_card(struct pci_dev *pdev, 1313static int __devinit reset_card(struct pci_dev *pdev,
1311 const unsigned int card, unsigned int *signature) 1314 const unsigned int card, unsigned int *signature)
1312{ 1315{
1313 struct isi_board *board = pci_get_drvdata(pdev); 1316 struct isi_board *board = pci_get_drvdata(pdev);
@@ -1368,7 +1371,7 @@ end:
1368 return retval; 1371 return retval;
1369} 1372}
1370 1373
1371static int load_firmware(struct pci_dev *pdev, 1374static int __devinit load_firmware(struct pci_dev *pdev,
1372 const unsigned int index, const unsigned int signature) 1375 const unsigned int index, const unsigned int signature)
1373{ 1376{
1374 struct isi_board *board = pci_get_drvdata(pdev); 1377 struct isi_board *board = pci_get_drvdata(pdev);
@@ -1548,7 +1551,7 @@ end:
1548 */ 1551 */
1549static unsigned int card_count; 1552static unsigned int card_count;
1550 1553
1551static int isicom_probe(struct pci_dev *pdev, 1554static int __devinit isicom_probe(struct pci_dev *pdev,
1552 const struct pci_device_id *ent) 1555 const struct pci_device_id *ent)
1553{ 1556{
1554 unsigned int uninitialized_var(signature), index; 1557 unsigned int uninitialized_var(signature), index;
@@ -1595,7 +1598,7 @@ static int isicom_probe(struct pci_dev *pdev,
1595 } 1598 }
1596 1599
1597 retval = request_irq(board->irq, isicom_interrupt, 1600 retval = request_irq(board->irq, isicom_interrupt,
1598 IRQF_SHARED, ISICOM_NAME, board); 1601 IRQF_SHARED | IRQF_DISABLED, ISICOM_NAME, board);
1599 if (retval < 0) { 1602 if (retval < 0) {
1600 dev_err(&pdev->dev, "Could not install handler at Irq %d. " 1603 dev_err(&pdev->dev, "Could not install handler at Irq %d. "
1601 "Card%d will be disabled.\n", board->irq, index + 1); 1604 "Card%d will be disabled.\n", board->irq, index + 1);
@@ -1610,15 +1613,9 @@ static int isicom_probe(struct pci_dev *pdev,
1610 if (retval < 0) 1613 if (retval < 0)
1611 goto errunri; 1614 goto errunri;
1612 1615
1613 for (index = 0; index < board->port_count; index++) { 1616 for (index = 0; index < board->port_count; index++)
1614 struct tty_port *tport = &board->ports[index].port; 1617 tty_register_device(isicom_normal, board->index * 16 + index,
1615 tty_port_init(tport); 1618 &pdev->dev);
1616 tport->ops = &isicom_port_ops;
1617 tport->close_delay = 50 * HZ/100;
1618 tport->closing_wait = 3000 * HZ/100;
1619 tty_port_register_device(tport, isicom_normal,
1620 board->index * 16 + index, &pdev->dev);
1621 }
1622 1619
1623 return 0; 1620 return 0;
1624 1621
@@ -1635,15 +1632,13 @@ err:
1635 return retval; 1632 return retval;
1636} 1633}
1637 1634
1638static void isicom_remove(struct pci_dev *pdev) 1635static void __devexit isicom_remove(struct pci_dev *pdev)
1639{ 1636{
1640 struct isi_board *board = pci_get_drvdata(pdev); 1637 struct isi_board *board = pci_get_drvdata(pdev);
1641 unsigned int i; 1638 unsigned int i;
1642 1639
1643 for (i = 0; i < board->port_count; i++) { 1640 for (i = 0; i < board->port_count; i++)
1644 tty_unregister_device(isicom_normal, board->index * 16 + i); 1641 tty_unregister_device(isicom_normal, board->index * 16 + i);
1645 tty_port_destroy(&board->ports[i].port);
1646 }
1647 1642
1648 free_irq(board->irq, board); 1643 free_irq(board->irq, board);
1649 pci_release_region(pdev, 3); 1644 pci_release_region(pdev, 3);
@@ -1662,9 +1657,13 @@ static int __init isicom_init(void)
1662 isi_card[idx].ports = port; 1657 isi_card[idx].ports = port;
1663 spin_lock_init(&isi_card[idx].card_lock); 1658 spin_lock_init(&isi_card[idx].card_lock);
1664 for (channel = 0; channel < 16; channel++, port++) { 1659 for (channel = 0; channel < 16; channel++, port++) {
1660 tty_port_init(&port->port);
1661 port->port.ops = &isicom_port_ops;
1665 port->magic = ISICOM_MAGIC; 1662 port->magic = ISICOM_MAGIC;
1666 port->card = &isi_card[idx]; 1663 port->card = &isi_card[idx];
1667 port->channel = channel; 1664 port->channel = channel;
1665 port->port.close_delay = 50 * HZ/100;
1666 port->port.closing_wait = 3000 * HZ/100;
1668 port->status = 0; 1667 port->status = 0;
1669 /* . . . */ 1668 /* . . . */
1670 } 1669 }
@@ -1679,6 +1678,7 @@ static int __init isicom_init(void)
1679 goto error; 1678 goto error;
1680 } 1679 }
1681 1680
1681 isicom_normal->owner = THIS_MODULE;
1682 isicom_normal->name = "ttyM"; 1682 isicom_normal->name = "ttyM";
1683 isicom_normal->major = ISICOM_NMAJOR; 1683 isicom_normal->major = ISICOM_NMAJOR;
1684 isicom_normal->minor_start = 0; 1684 isicom_normal->minor_start = 0;
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index f9d28503bde..d15a071b1a5 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -46,6 +46,7 @@
46#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/ratelimit.h> 47#include <linux/ratelimit.h>
48 48
49#include <asm/system.h>
49#include <asm/io.h> 50#include <asm/io.h>
50#include <asm/uaccess.h> 51#include <asm/uaccess.h>
51 52
@@ -169,7 +170,6 @@ static DEFINE_SPINLOCK(moxa_lock);
169static unsigned long baseaddr[MAX_BOARDS]; 170static unsigned long baseaddr[MAX_BOARDS];
170static unsigned int type[MAX_BOARDS]; 171static unsigned int type[MAX_BOARDS];
171static unsigned int numports[MAX_BOARDS]; 172static unsigned int numports[MAX_BOARDS];
172static struct tty_port moxa_service_port;
173 173
174MODULE_AUTHOR("William Chen"); 174MODULE_AUTHOR("William Chen");
175MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); 175MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
@@ -368,10 +368,10 @@ static int moxa_ioctl(struct tty_struct *tty,
368 tmp.dcd = 1; 368 tmp.dcd = 1;
369 369
370 ttyp = tty_port_tty_get(&p->port); 370 ttyp = tty_port_tty_get(&p->port);
371 if (!ttyp) 371 if (!ttyp || !ttyp->termios)
372 tmp.cflag = p->cflag; 372 tmp.cflag = p->cflag;
373 else 373 else
374 tmp.cflag = ttyp->termios.c_cflag; 374 tmp.cflag = ttyp->termios->c_cflag;
375 tty_kref_put(ttyp); 375 tty_kref_put(ttyp);
376copy: 376copy:
377 if (copy_to_user(argm, &tmp, sizeof(tmp))) 377 if (copy_to_user(argm, &tmp, sizeof(tmp)))
@@ -835,7 +835,7 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
835 const struct firmware *fw; 835 const struct firmware *fw;
836 const char *file; 836 const char *file;
837 struct moxa_port *p; 837 struct moxa_port *p;
838 unsigned int i, first_idx; 838 unsigned int i;
839 int ret; 839 int ret;
840 840
841 brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports), 841 brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports),
@@ -888,15 +888,8 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
888 mod_timer(&moxaTimer, jiffies + HZ / 50); 888 mod_timer(&moxaTimer, jiffies + HZ / 50);
889 spin_unlock_bh(&moxa_lock); 889 spin_unlock_bh(&moxa_lock);
890 890
891 first_idx = (brd - moxa_boards) * MAX_PORTS_PER_BOARD;
892 for (i = 0; i < brd->numPorts; i++)
893 tty_port_register_device(&brd->ports[i].port, moxaDriver,
894 first_idx + i, dev);
895
896 return 0; 891 return 0;
897err_free: 892err_free:
898 for (i = 0; i < MAX_PORTS_PER_BOARD; i++)
899 tty_port_destroy(&brd->ports[i].port);
900 kfree(brd->ports); 893 kfree(brd->ports);
901err: 894err:
902 return ret; 895 return ret;
@@ -904,7 +897,7 @@ err:
904 897
905static void moxa_board_deinit(struct moxa_board_conf *brd) 898static void moxa_board_deinit(struct moxa_board_conf *brd)
906{ 899{
907 unsigned int a, opened, first_idx; 900 unsigned int a, opened;
908 901
909 mutex_lock(&moxa_openlock); 902 mutex_lock(&moxa_openlock);
910 spin_lock_bh(&moxa_lock); 903 spin_lock_bh(&moxa_lock);
@@ -921,8 +914,6 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
921 tty_kref_put(tty); 914 tty_kref_put(tty);
922 } 915 }
923 } 916 }
924 for (a = 0; a < MAX_PORTS_PER_BOARD; a++)
925 tty_port_destroy(&brd->ports[a].port);
926 while (1) { 917 while (1) {
927 opened = 0; 918 opened = 0;
928 for (a = 0; a < brd->numPorts; a++) 919 for (a = 0; a < brd->numPorts; a++)
@@ -935,17 +926,13 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
935 mutex_lock(&moxa_openlock); 926 mutex_lock(&moxa_openlock);
936 } 927 }
937 928
938 first_idx = (brd - moxa_boards) * MAX_PORTS_PER_BOARD;
939 for (a = 0; a < brd->numPorts; a++)
940 tty_unregister_device(moxaDriver, first_idx + a);
941
942 iounmap(brd->basemem); 929 iounmap(brd->basemem);
943 brd->basemem = NULL; 930 brd->basemem = NULL;
944 kfree(brd->ports); 931 kfree(brd->ports);
945} 932}
946 933
947#ifdef CONFIG_PCI 934#ifdef CONFIG_PCI
948static int moxa_pci_probe(struct pci_dev *pdev, 935static int __devinit moxa_pci_probe(struct pci_dev *pdev,
949 const struct pci_device_id *ent) 936 const struct pci_device_id *ent)
950{ 937{
951 struct moxa_board_conf *board; 938 struct moxa_board_conf *board;
@@ -981,7 +968,6 @@ static int moxa_pci_probe(struct pci_dev *pdev,
981 board->basemem = ioremap_nocache(pci_resource_start(pdev, 2), 0x4000); 968 board->basemem = ioremap_nocache(pci_resource_start(pdev, 2), 0x4000);
982 if (board->basemem == NULL) { 969 if (board->basemem == NULL) {
983 dev_err(&pdev->dev, "can't remap io space 2\n"); 970 dev_err(&pdev->dev, "can't remap io space 2\n");
984 retval = -ENOMEM;
985 goto err_reg; 971 goto err_reg;
986 } 972 }
987 973
@@ -1020,7 +1006,7 @@ err:
1020 return retval; 1006 return retval;
1021} 1007}
1022 1008
1023static void moxa_pci_remove(struct pci_dev *pdev) 1009static void __devexit moxa_pci_remove(struct pci_dev *pdev)
1024{ 1010{
1025 struct moxa_board_conf *brd = pci_get_drvdata(pdev); 1011 struct moxa_board_conf *brd = pci_get_drvdata(pdev);
1026 1012
@@ -1033,7 +1019,7 @@ static struct pci_driver moxa_pci_driver = {
1033 .name = "moxa", 1019 .name = "moxa",
1034 .id_table = moxa_pcibrds, 1020 .id_table = moxa_pcibrds,
1035 .probe = moxa_pci_probe, 1021 .probe = moxa_pci_probe,
1036 .remove = moxa_pci_remove 1022 .remove = __devexit_p(moxa_pci_remove)
1037}; 1023};
1038#endif /* CONFIG_PCI */ 1024#endif /* CONFIG_PCI */
1039 1025
@@ -1046,15 +1032,11 @@ static int __init moxa_init(void)
1046 1032
1047 printk(KERN_INFO "MOXA Intellio family driver version %s\n", 1033 printk(KERN_INFO "MOXA Intellio family driver version %s\n",
1048 MOXA_VERSION); 1034 MOXA_VERSION);
1035 moxaDriver = alloc_tty_driver(MAX_PORTS + 1);
1036 if (!moxaDriver)
1037 return -ENOMEM;
1049 1038
1050 tty_port_init(&moxa_service_port); 1039 moxaDriver->owner = THIS_MODULE;
1051
1052 moxaDriver = tty_alloc_driver(MAX_PORTS + 1,
1053 TTY_DRIVER_REAL_RAW |
1054 TTY_DRIVER_DYNAMIC_DEV);
1055 if (IS_ERR(moxaDriver))
1056 return PTR_ERR(moxaDriver);
1057
1058 moxaDriver->name = "ttyMX"; 1040 moxaDriver->name = "ttyMX";
1059 moxaDriver->major = ttymajor; 1041 moxaDriver->major = ttymajor;
1060 moxaDriver->minor_start = 0; 1042 moxaDriver->minor_start = 0;
@@ -1064,9 +1046,8 @@ static int __init moxa_init(void)
1064 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 1046 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1065 moxaDriver->init_termios.c_ispeed = 9600; 1047 moxaDriver->init_termios.c_ispeed = 9600;
1066 moxaDriver->init_termios.c_ospeed = 9600; 1048 moxaDriver->init_termios.c_ospeed = 9600;
1049 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
1067 tty_set_operations(moxaDriver, &moxa_ops); 1050 tty_set_operations(moxaDriver, &moxa_ops);
1068 /* Having one more port only for ioctls is ugly */
1069 tty_port_link_device(&moxa_service_port, moxaDriver, MAX_PORTS);
1070 1051
1071 if (tty_register_driver(moxaDriver)) { 1052 if (tty_register_driver(moxaDriver)) {
1072 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n"); 1053 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");
@@ -1199,7 +1180,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1199 mutex_lock(&ch->port.mutex); 1180 mutex_lock(&ch->port.mutex);
1200 if (!(ch->port.flags & ASYNC_INITIALIZED)) { 1181 if (!(ch->port.flags & ASYNC_INITIALIZED)) {
1201 ch->statusflags = 0; 1182 ch->statusflags = 0;
1202 moxa_set_tty_param(tty, &tty->termios); 1183 moxa_set_tty_param(tty, tty->termios);
1203 MoxaPortLineCtrl(ch, 1, 1); 1184 MoxaPortLineCtrl(ch, 1, 1);
1204 MoxaPortEnable(ch); 1185 MoxaPortEnable(ch);
1205 MoxaSetFifo(ch, ch->type == PORT_16550A); 1186 MoxaSetFifo(ch, ch->type == PORT_16550A);
@@ -1214,7 +1195,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1214static void moxa_close(struct tty_struct *tty, struct file *filp) 1195static void moxa_close(struct tty_struct *tty, struct file *filp)
1215{ 1196{
1216 struct moxa_port *ch = tty->driver_data; 1197 struct moxa_port *ch = tty->driver_data;
1217 ch->cflag = tty->termios.c_cflag; 1198 ch->cflag = tty->termios->c_cflag;
1218 tty_port_close(&ch->port, tty, filp); 1199 tty_port_close(&ch->port, tty, filp);
1219} 1200}
1220 1201
@@ -1350,7 +1331,7 @@ static void moxa_start(struct tty_struct *tty)
1350 if (ch == NULL) 1331 if (ch == NULL)
1351 return; 1332 return;
1352 1333
1353 if (!test_bit(TXSTOPPED, &ch->statusflags)) 1334 if (!(ch->statusflags & TXSTOPPED))
1354 return; 1335 return;
1355 1336
1356 MoxaPortTxEnable(ch); 1337 MoxaPortTxEnable(ch);
@@ -1374,7 +1355,7 @@ static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1374 p->DCDState = dcd; 1355 p->DCDState = dcd;
1375 spin_unlock_irqrestore(&p->port.lock, flags); 1356 spin_unlock_irqrestore(&p->port.lock, flags);
1376 tty = tty_port_tty_get(&p->port); 1357 tty = tty_port_tty_get(&p->port);
1377 if (tty && !C_CLOCAL(tty) && !dcd) 1358 if (tty && C_CLOCAL(tty) && !dcd)
1378 tty_hangup(tty); 1359 tty_hangup(tty);
1379 tty_kref_put(tty); 1360 tty_kref_put(tty);
1380 } 1361 }
@@ -1485,7 +1466,7 @@ static void moxa_poll(unsigned long ignored)
1485 1466
1486static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios) 1467static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios)
1487{ 1468{
1488 register struct ktermios *ts = &tty->termios; 1469 register struct ktermios *ts = tty->termios;
1489 struct moxa_port *ch = tty->driver_data; 1470 struct moxa_port *ch = tty->driver_data;
1490 int rts, cts, txflow, rxflow, xany, baud; 1471 int rts, cts, txflow, rxflow, xany, baud;
1491 1472
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 40113868bec..7fc8c02fea6 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -41,6 +41,7 @@
41#include <linux/slab.h> 41#include <linux/slab.h>
42#include <linux/ratelimit.h> 42#include <linux/ratelimit.h>
43 43
44#include <asm/system.h>
44#include <asm/io.h> 45#include <asm/io.h>
45#include <asm/irq.h> 46#include <asm/irq.h>
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
@@ -487,7 +488,7 @@ static void mxser_disable_must_rx_software_flow_control(unsigned long baseio)
487} 488}
488 489
489#ifdef CONFIG_PCI 490#ifdef CONFIG_PCI
490static int CheckIsMoxaMust(unsigned long io) 491static int __devinit CheckIsMoxaMust(unsigned long io)
491{ 492{
492 u8 oldmcr, hwid; 493 u8 oldmcr, hwid;
493 int i; 494 int i;
@@ -643,7 +644,7 @@ static int mxser_change_speed(struct tty_struct *tty,
643 int ret = 0; 644 int ret = 0;
644 unsigned char status; 645 unsigned char status;
645 646
646 cflag = tty->termios.c_cflag; 647 cflag = tty->termios->c_cflag;
647 if (!info->ioaddr) 648 if (!info->ioaddr)
648 return ret; 649 return ret;
649 650
@@ -830,7 +831,7 @@ static void mxser_check_modem_status(struct tty_struct *tty,
830 wake_up_interruptible(&port->port.open_wait); 831 wake_up_interruptible(&port->port.open_wait);
831 } 832 }
832 833
833 if (tty_port_cts_enabled(&port->port)) { 834 if (port->port.flags & ASYNC_CTS_FLOW) {
834 if (tty->hw_stopped) { 835 if (tty->hw_stopped) {
835 if (status & UART_MSR_CTS) { 836 if (status & UART_MSR_CTS) {
836 tty->hw_stopped = 0; 837 tty->hw_stopped = 0;
@@ -1009,6 +1010,8 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
1009 line = tty->index; 1010 line = tty->index;
1010 if (line == MXSER_PORTS) 1011 if (line == MXSER_PORTS)
1011 return 0; 1012 return 0;
1013 if (line < 0 || line > MXSER_PORTS)
1014 return -ENODEV;
1012 info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD]; 1015 info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD];
1013 if (!info->ioaddr) 1016 if (!info->ioaddr)
1014 return -ENODEV; 1017 return -ENODEV;
@@ -1520,10 +1523,10 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1520 1523
1521 tty = tty_port_tty_get(port); 1524 tty = tty_port_tty_get(port);
1522 1525
1523 if (!tty) 1526 if (!tty || !tty->termios)
1524 ms.cflag = ip->normal_termios.c_cflag; 1527 ms.cflag = ip->normal_termios.c_cflag;
1525 else 1528 else
1526 ms.cflag = tty->termios.c_cflag; 1529 ms.cflag = tty->termios->c_cflag;
1527 tty_kref_put(tty); 1530 tty_kref_put(tty);
1528 spin_lock_irq(&ip->slock); 1531 spin_lock_irq(&ip->slock);
1529 status = inb(ip->ioaddr + UART_MSR); 1532 status = inb(ip->ioaddr + UART_MSR);
@@ -1589,13 +1592,13 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1589 1592
1590 tty = tty_port_tty_get(&ip->port); 1593 tty = tty_port_tty_get(&ip->port);
1591 1594
1592 if (!tty) { 1595 if (!tty || !tty->termios) {
1593 cflag = ip->normal_termios.c_cflag; 1596 cflag = ip->normal_termios.c_cflag;
1594 iflag = ip->normal_termios.c_iflag; 1597 iflag = ip->normal_termios.c_iflag;
1595 me->baudrate[p] = tty_termios_baud_rate(&ip->normal_termios); 1598 me->baudrate[p] = tty_termios_baud_rate(&ip->normal_termios);
1596 } else { 1599 } else {
1597 cflag = tty->termios.c_cflag; 1600 cflag = tty->termios->c_cflag;
1598 iflag = tty->termios.c_iflag; 1601 iflag = tty->termios->c_iflag;
1599 me->baudrate[p] = tty_get_baud_rate(tty); 1602 me->baudrate[p] = tty_get_baud_rate(tty);
1600 } 1603 }
1601 tty_kref_put(tty); 1604 tty_kref_put(tty);
@@ -1853,7 +1856,7 @@ static void mxser_stoprx(struct tty_struct *tty)
1853 } 1856 }
1854 } 1857 }
1855 1858
1856 if (tty->termios.c_cflag & CRTSCTS) { 1859 if (tty->termios->c_cflag & CRTSCTS) {
1857 info->MCR &= ~UART_MCR_RTS; 1860 info->MCR &= ~UART_MCR_RTS;
1858 outb(info->MCR, info->ioaddr + UART_MCR); 1861 outb(info->MCR, info->ioaddr + UART_MCR);
1859 } 1862 }
@@ -1890,7 +1893,7 @@ static void mxser_unthrottle(struct tty_struct *tty)
1890 } 1893 }
1891 } 1894 }
1892 1895
1893 if (tty->termios.c_cflag & CRTSCTS) { 1896 if (tty->termios->c_cflag & CRTSCTS) {
1894 info->MCR |= UART_MCR_RTS; 1897 info->MCR |= UART_MCR_RTS;
1895 outb(info->MCR, info->ioaddr + UART_MCR); 1898 outb(info->MCR, info->ioaddr + UART_MCR);
1896 } 1899 }
@@ -1939,14 +1942,14 @@ static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termi
1939 spin_unlock_irqrestore(&info->slock, flags); 1942 spin_unlock_irqrestore(&info->slock, flags);
1940 1943
1941 if ((old_termios->c_cflag & CRTSCTS) && 1944 if ((old_termios->c_cflag & CRTSCTS) &&
1942 !(tty->termios.c_cflag & CRTSCTS)) { 1945 !(tty->termios->c_cflag & CRTSCTS)) {
1943 tty->hw_stopped = 0; 1946 tty->hw_stopped = 0;
1944 mxser_start(tty); 1947 mxser_start(tty);
1945 } 1948 }
1946 1949
1947 /* Handle sw stopped */ 1950 /* Handle sw stopped */
1948 if ((old_termios->c_iflag & IXON) && 1951 if ((old_termios->c_iflag & IXON) &&
1949 !(tty->termios.c_iflag & IXON)) { 1952 !(tty->termios->c_iflag & IXON)) {
1950 tty->stopped = 0; 1953 tty->stopped = 0;
1951 1954
1952 if (info->board->chip_flag) { 1955 if (info->board->chip_flag) {
@@ -2002,9 +2005,16 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
2002 */ 2005 */
2003 if (!timeout || timeout > 2 * info->timeout) 2006 if (!timeout || timeout > 2 * info->timeout)
2004 timeout = 2 * info->timeout; 2007 timeout = 2 * info->timeout;
2005 2008#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2009 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
2010 timeout, char_time);
2011 printk("jiff=%lu...", jiffies);
2012#endif
2006 spin_lock_irqsave(&info->slock, flags); 2013 spin_lock_irqsave(&info->slock, flags);
2007 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) { 2014 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
2015#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2016 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
2017#endif
2008 spin_unlock_irqrestore(&info->slock, flags); 2018 spin_unlock_irqrestore(&info->slock, flags);
2009 schedule_timeout_interruptible(char_time); 2019 schedule_timeout_interruptible(char_time);
2010 spin_lock_irqsave(&info->slock, flags); 2020 spin_lock_irqsave(&info->slock, flags);
@@ -2015,6 +2025,10 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
2015 } 2025 }
2016 spin_unlock_irqrestore(&info->slock, flags); 2026 spin_unlock_irqrestore(&info->slock, flags);
2017 set_current_state(TASK_RUNNING); 2027 set_current_state(TASK_RUNNING);
2028
2029#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2030 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
2031#endif
2018} 2032}
2019 2033
2020/* 2034/*
@@ -2326,7 +2340,7 @@ static const struct tty_operations mxser_ops = {
2326 .get_icount = mxser_get_icount, 2340 .get_icount = mxser_get_icount,
2327}; 2341};
2328 2342
2329static struct tty_port_operations mxser_port_ops = { 2343struct tty_port_operations mxser_port_ops = {
2330 .carrier_raised = mxser_carrier_raised, 2344 .carrier_raised = mxser_carrier_raised,
2331 .dtr_rts = mxser_dtr_rts, 2345 .dtr_rts = mxser_dtr_rts,
2332 .activate = mxser_activate, 2346 .activate = mxser_activate,
@@ -2337,39 +2351,14 @@ static struct tty_port_operations mxser_port_ops = {
2337 * The MOXA Smartio/Industio serial driver boot-time initialization code! 2351 * The MOXA Smartio/Industio serial driver boot-time initialization code!
2338 */ 2352 */
2339 2353
2340static bool allow_overlapping_vector;
2341module_param(allow_overlapping_vector, bool, S_IRUGO);
2342MODULE_PARM_DESC(allow_overlapping_vector, "whether we allow ISA cards to be configured such that vector overlabs IO ports (default=no)");
2343
2344static bool mxser_overlapping_vector(struct mxser_board *brd)
2345{
2346 return allow_overlapping_vector &&
2347 brd->vector >= brd->ports[0].ioaddr &&
2348 brd->vector < brd->ports[0].ioaddr + 8 * brd->info->nports;
2349}
2350
2351static int mxser_request_vector(struct mxser_board *brd)
2352{
2353 if (mxser_overlapping_vector(brd))
2354 return 0;
2355 return request_region(brd->vector, 1, "mxser(vector)") ? 0 : -EIO;
2356}
2357
2358static void mxser_release_vector(struct mxser_board *brd)
2359{
2360 if (mxser_overlapping_vector(brd))
2361 return;
2362 release_region(brd->vector, 1);
2363}
2364
2365static void mxser_release_ISA_res(struct mxser_board *brd) 2354static void mxser_release_ISA_res(struct mxser_board *brd)
2366{ 2355{
2367 free_irq(brd->irq, brd); 2356 free_irq(brd->irq, brd);
2368 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports); 2357 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2369 mxser_release_vector(brd); 2358 release_region(brd->vector, 1);
2370} 2359}
2371 2360
2372static int mxser_initbrd(struct mxser_board *brd, 2361static int __devinit mxser_initbrd(struct mxser_board *brd,
2373 struct pci_dev *pdev) 2362 struct pci_dev *pdev)
2374{ 2363{
2375 struct mxser_port *info; 2364 struct mxser_port *info;
@@ -2411,30 +2400,17 @@ static int mxser_initbrd(struct mxser_board *brd,
2411 2400
2412 retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser", 2401 retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser",
2413 brd); 2402 brd);
2414 if (retval) { 2403 if (retval)
2415 for (i = 0; i < brd->info->nports; i++)
2416 tty_port_destroy(&brd->ports[i].port);
2417 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may " 2404 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may "
2418 "conflict with another device.\n", 2405 "conflict with another device.\n",
2419 brd->info->name, brd->irq); 2406 brd->info->name, brd->irq);
2420 }
2421 2407
2422 return retval; 2408 return retval;
2423} 2409}
2424 2410
2425static void mxser_board_remove(struct mxser_board *brd)
2426{
2427 unsigned int i;
2428
2429 for (i = 0; i < brd->info->nports; i++) {
2430 tty_unregister_device(mxvar_sdriver, brd->idx + i);
2431 tty_port_destroy(&brd->ports[i].port);
2432 }
2433}
2434
2435static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd) 2411static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd)
2436{ 2412{
2437 int id, i, bits, ret; 2413 int id, i, bits;
2438 unsigned short regs[16], irq; 2414 unsigned short regs[16], irq;
2439 unsigned char scratch, scratch2; 2415 unsigned char scratch, scratch2;
2440 2416
@@ -2530,15 +2506,13 @@ static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd)
2530 8 * brd->info->nports - 1); 2506 8 * brd->info->nports - 1);
2531 return -EIO; 2507 return -EIO;
2532 } 2508 }
2533 2509 if (!request_region(brd->vector, 1, "mxser(vector)")) {
2534 ret = mxser_request_vector(brd);
2535 if (ret) {
2536 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports); 2510 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2537 printk(KERN_ERR "mxser: can't request interrupt vector region: " 2511 printk(KERN_ERR "mxser: can't request interrupt vector region: "
2538 "0x%.8lx-0x%.8lx\n", 2512 "0x%.8lx-0x%.8lx\n",
2539 brd->ports[0].ioaddr, brd->ports[0].ioaddr + 2513 brd->ports[0].ioaddr, brd->ports[0].ioaddr +
2540 8 * brd->info->nports - 1); 2514 8 * brd->info->nports - 1);
2541 return ret; 2515 return -EIO;
2542 } 2516 }
2543 return brd->info->nports; 2517 return brd->info->nports;
2544 2518
@@ -2547,7 +2521,7 @@ err_irqconflict:
2547 return -EIO; 2521 return -EIO;
2548} 2522}
2549 2523
2550static int mxser_probe(struct pci_dev *pdev, 2524static int __devinit mxser_probe(struct pci_dev *pdev,
2551 const struct pci_device_id *ent) 2525 const struct pci_device_id *ent)
2552{ 2526{
2553#ifdef CONFIG_PCI 2527#ifdef CONFIG_PCI
@@ -2638,8 +2612,7 @@ static int mxser_probe(struct pci_dev *pdev,
2638 goto err_rel3; 2612 goto err_rel3;
2639 2613
2640 for (i = 0; i < brd->info->nports; i++) 2614 for (i = 0; i < brd->info->nports; i++)
2641 tty_port_register_device(&brd->ports[i].port, mxvar_sdriver, 2615 tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev);
2642 brd->idx + i, &pdev->dev);
2643 2616
2644 pci_set_drvdata(pdev, brd); 2617 pci_set_drvdata(pdev, brd);
2645 2618
@@ -2658,12 +2631,14 @@ err:
2658#endif 2631#endif
2659} 2632}
2660 2633
2661static void mxser_remove(struct pci_dev *pdev) 2634static void __devexit mxser_remove(struct pci_dev *pdev)
2662{ 2635{
2663#ifdef CONFIG_PCI 2636#ifdef CONFIG_PCI
2664 struct mxser_board *brd = pci_get_drvdata(pdev); 2637 struct mxser_board *brd = pci_get_drvdata(pdev);
2638 unsigned int i;
2665 2639
2666 mxser_board_remove(brd); 2640 for (i = 0; i < brd->info->nports; i++)
2641 tty_unregister_device(mxvar_sdriver, brd->idx + i);
2667 2642
2668 free_irq(pdev->irq, brd); 2643 free_irq(pdev->irq, brd);
2669 pci_release_region(pdev, 2); 2644 pci_release_region(pdev, 2);
@@ -2677,7 +2652,7 @@ static struct pci_driver mxser_driver = {
2677 .name = "mxser", 2652 .name = "mxser",
2678 .id_table = mxser_pcibrds, 2653 .id_table = mxser_pcibrds,
2679 .probe = mxser_probe, 2654 .probe = mxser_probe,
2680 .remove = mxser_remove 2655 .remove = __devexit_p(mxser_remove)
2681}; 2656};
2682 2657
2683static int __init mxser_module_init(void) 2658static int __init mxser_module_init(void)
@@ -2694,9 +2669,12 @@ static int __init mxser_module_init(void)
2694 MXSER_VERSION); 2669 MXSER_VERSION);
2695 2670
2696 /* Initialize the tty_driver structure */ 2671 /* Initialize the tty_driver structure */
2672 mxvar_sdriver->owner = THIS_MODULE;
2673 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
2697 mxvar_sdriver->name = "ttyMI"; 2674 mxvar_sdriver->name = "ttyMI";
2698 mxvar_sdriver->major = ttymajor; 2675 mxvar_sdriver->major = ttymajor;
2699 mxvar_sdriver->minor_start = 0; 2676 mxvar_sdriver->minor_start = 0;
2677 mxvar_sdriver->num = MXSER_PORTS + 1;
2700 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL; 2678 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
2701 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL; 2679 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
2702 mxvar_sdriver->init_termios = tty_std_termios; 2680 mxvar_sdriver->init_termios = tty_std_termios;
@@ -2734,8 +2712,7 @@ static int __init mxser_module_init(void)
2734 2712
2735 brd->idx = m * MXSER_PORTS_PER_BOARD; 2713 brd->idx = m * MXSER_PORTS_PER_BOARD;
2736 for (i = 0; i < brd->info->nports; i++) 2714 for (i = 0; i < brd->info->nports; i++)
2737 tty_port_register_device(&brd->ports[i].port, 2715 tty_register_device(mxvar_sdriver, brd->idx + i, NULL);
2738 mxvar_sdriver, brd->idx + i, NULL);
2739 2716
2740 m++; 2717 m++;
2741 } 2718 }
@@ -2759,13 +2736,15 @@ err_put:
2759 2736
2760static void __exit mxser_module_exit(void) 2737static void __exit mxser_module_exit(void)
2761{ 2738{
2762 unsigned int i; 2739 unsigned int i, j;
2763 2740
2764 pci_unregister_driver(&mxser_driver); 2741 pci_unregister_driver(&mxser_driver);
2765 2742
2766 for (i = 0; i < MXSER_BOARDS; i++) /* ISA remains */ 2743 for (i = 0; i < MXSER_BOARDS; i++) /* ISA remains */
2767 if (mxser_boards[i].info != NULL) 2744 if (mxser_boards[i].info != NULL)
2768 mxser_board_remove(&mxser_boards[i]); 2745 for (j = 0; j < mxser_boards[i].info->nports; j++)
2746 tty_unregister_device(mxvar_sdriver,
2747 mxser_boards[i].idx + j);
2769 tty_unregister_driver(mxvar_sdriver); 2748 tty_unregister_driver(mxvar_sdriver);
2770 put_tty_driver(mxvar_sdriver); 2749 put_tty_driver(mxvar_sdriver);
2771 2750
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index dcc0430a49c..8a50e4eebf1 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -21,6 +21,7 @@
21 * Mostly done: ioctls for setting modes/timing 21 * Mostly done: ioctls for setting modes/timing
22 * Partly done: hooks so you can pull off frames to non tty devs 22 * Partly done: hooks so you can pull off frames to non tty devs
23 * Restart DLCI 0 when it closes ? 23 * Restart DLCI 0 when it closes ?
24 * Test basic encoding
24 * Improve the tx engine 25 * Improve the tx engine
25 * Resolve tx side locking by adding a queue_head and routing 26 * Resolve tx side locking by adding a queue_head and routing
26 * all control traffic via it 27 * all control traffic via it
@@ -66,16 +67,14 @@
66static int debug; 67static int debug;
67module_param(debug, int, 0600); 68module_param(debug, int, 0600);
68 69
69/* Defaults: these are from the specification */ 70#define T1 (HZ/10)
70 71#define T2 (HZ/3)
71#define T1 10 /* 100mS */ 72#define N2 3
72#define T2 34 /* 333mS */
73#define N2 3 /* Retry 3 times */
74 73
75/* Use long timers for testing at low speed with debug on */ 74/* Use long timers for testing at low speed with debug on */
76#ifdef DEBUG_TIMING 75#ifdef DEBUG_TIMING
77#define T1 100 76#define T1 HZ
78#define T2 200 77#define T2 (2 * HZ)
79#endif 78#endif
80 79
81/* 80/*
@@ -108,7 +107,7 @@ struct gsm_mux_net {
108 */ 107 */
109 108
110struct gsm_msg { 109struct gsm_msg {
111 struct list_head list; 110 struct gsm_msg *next;
112 u8 addr; /* DLCI address + flags */ 111 u8 addr; /* DLCI address + flags */
113 u8 ctrl; /* Control byte + flags */ 112 u8 ctrl; /* Control byte + flags */
114 unsigned int len; /* Length of data block (can be zero) */ 113 unsigned int len; /* Length of data block (can be zero) */
@@ -134,6 +133,7 @@ struct gsm_dlci {
134#define DLCI_OPENING 1 /* Sending SABM not seen UA */ 133#define DLCI_OPENING 1 /* Sending SABM not seen UA */
135#define DLCI_OPEN 2 /* SABM/UA complete */ 134#define DLCI_OPEN 2 /* SABM/UA complete */
136#define DLCI_CLOSING 3 /* Sending DISC not seen UA/DM */ 135#define DLCI_CLOSING 3 /* Sending DISC not seen UA/DM */
136 struct kref ref; /* freed from port or mux close */
137 struct mutex mutex; 137 struct mutex mutex;
138 138
139 /* Link layer */ 139 /* Link layer */
@@ -244,7 +244,8 @@ struct gsm_mux {
244 unsigned int tx_bytes; /* TX data outstanding */ 244 unsigned int tx_bytes; /* TX data outstanding */
245#define TX_THRESH_HI 8192 245#define TX_THRESH_HI 8192
246#define TX_THRESH_LO 2048 246#define TX_THRESH_LO 2048
247 struct list_head tx_list; /* Pending data packets */ 247 struct gsm_msg *tx_head; /* Pending data packets */
248 struct gsm_msg *tx_tail;
248 249
249 /* Control messages */ 250 /* Control messages */
250 struct timer_list t2_timer; /* Retransmit timer for commands */ 251 struct timer_list t2_timer; /* Retransmit timer for commands */
@@ -487,7 +488,7 @@ static void gsm_print_packet(const char *hdr, int addr, int cr,
487 default: 488 default:
488 if (!(control & 0x01)) { 489 if (!(control & 0x01)) {
489 pr_cont("I N(S)%d N(R)%d", 490 pr_cont("I N(S)%d N(R)%d",
490 (control & 0x0E) >> 1, (control & 0xE0) >> 5); 491 (control & 0x0E) >> 1, (control & 0xE) >> 5);
491 } else switch (control & 0x0F) { 492 } else switch (control & 0x0F) {
492 case RR: 493 case RR:
493 pr_cont("RR(%d)", (control & 0xE0) >> 5); 494 pr_cont("RR(%d)", (control & 0xE0) >> 5);
@@ -661,7 +662,7 @@ static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,
661 m->len = len; 662 m->len = len;
662 m->addr = addr; 663 m->addr = addr;
663 m->ctrl = ctrl; 664 m->ctrl = ctrl;
664 INIT_LIST_HEAD(&m->list); 665 m->next = NULL;
665 return m; 666 return m;
666} 667}
667 668
@@ -671,21 +672,22 @@ static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,
671 * 672 *
672 * The tty device has called us to indicate that room has appeared in 673 * The tty device has called us to indicate that room has appeared in
673 * the transmit queue. Ram more data into the pipe if we have any 674 * the transmit queue. Ram more data into the pipe if we have any
674 * If we have been flow-stopped by a CMD_FCOFF, then we can only
675 * send messages on DLCI0 until CMD_FCON
676 * 675 *
677 * FIXME: lock against link layer control transmissions 676 * FIXME: lock against link layer control transmissions
678 */ 677 */
679 678
680static void gsm_data_kick(struct gsm_mux *gsm) 679static void gsm_data_kick(struct gsm_mux *gsm)
681{ 680{
682 struct gsm_msg *msg, *nmsg; 681 struct gsm_msg *msg = gsm->tx_head;
683 int len; 682 int len;
684 int skip_sof = 0; 683 int skip_sof = 0;
685 684
686 list_for_each_entry_safe(msg, nmsg, &gsm->tx_list, list) { 685 /* FIXME: We need to apply this solely to data messages */
687 if (gsm->constipated && msg->addr) 686 if (gsm->constipated)
688 continue; 687 return;
688
689 while (gsm->tx_head != NULL) {
690 msg = gsm->tx_head;
689 if (gsm->encoding != 0) { 691 if (gsm->encoding != 0) {
690 gsm->txframe[0] = GSM1_SOF; 692 gsm->txframe[0] = GSM1_SOF;
691 len = gsm_stuff_frame(msg->data, 693 len = gsm_stuff_frame(msg->data,
@@ -708,13 +710,14 @@ static void gsm_data_kick(struct gsm_mux *gsm)
708 len - skip_sof) < 0) 710 len - skip_sof) < 0)
709 break; 711 break;
710 /* FIXME: Can eliminate one SOF in many more cases */ 712 /* FIXME: Can eliminate one SOF in many more cases */
713 gsm->tx_head = msg->next;
714 if (gsm->tx_head == NULL)
715 gsm->tx_tail = NULL;
711 gsm->tx_bytes -= msg->len; 716 gsm->tx_bytes -= msg->len;
717 kfree(msg);
712 /* For a burst of frames skip the extra SOF within the 718 /* For a burst of frames skip the extra SOF within the
713 burst */ 719 burst */
714 skip_sof = 1; 720 skip_sof = 1;
715
716 list_del(&msg->list);
717 kfree(msg);
718 } 721 }
719} 722}
720 723
@@ -764,7 +767,11 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
764 msg->data = dp; 767 msg->data = dp;
765 768
766 /* Add to the actual output queue */ 769 /* Add to the actual output queue */
767 list_add_tail(&msg->list, &gsm->tx_list); 770 if (gsm->tx_tail)
771 gsm->tx_tail->next = msg;
772 else
773 gsm->tx_head = msg;
774 gsm->tx_tail = msg;
768 gsm->tx_bytes += msg->len; 775 gsm->tx_bytes += msg->len;
769 gsm_data_kick(gsm); 776 gsm_data_kick(gsm);
770} 777}
@@ -803,41 +810,38 @@ static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci)
803{ 810{
804 struct gsm_msg *msg; 811 struct gsm_msg *msg;
805 u8 *dp; 812 u8 *dp;
806 int len, total_size, size; 813 int len, size;
807 int h = dlci->adaption - 1; 814 int h = dlci->adaption - 1;
808 815
809 total_size = 0; 816 len = kfifo_len(dlci->fifo);
810 while(1) { 817 if (len == 0)
811 len = kfifo_len(dlci->fifo); 818 return 0;
812 if (len == 0) 819
813 return total_size; 820 /* MTU/MRU count only the data bits */
814 821 if (len > gsm->mtu)
815 /* MTU/MRU count only the data bits */ 822 len = gsm->mtu;
816 if (len > gsm->mtu) 823
817 len = gsm->mtu; 824 size = len + h;
818 825
819 size = len + h; 826 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
820 827 /* FIXME: need a timer or something to kick this so it can't
821 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); 828 get stuck with no work outstanding and no buffer free */
822 /* FIXME: need a timer or something to kick this so it can't 829 if (msg == NULL)
823 get stuck with no work outstanding and no buffer free */ 830 return -ENOMEM;
824 if (msg == NULL) 831 dp = msg->data;
825 return -ENOMEM; 832 switch (dlci->adaption) {
826 dp = msg->data; 833 case 1: /* Unstructured */
827 switch (dlci->adaption) { 834 break;
828 case 1: /* Unstructured */ 835 case 2: /* Unstructed with modem bits. Always one byte as we never
829 break; 836 send inline break data */
830 case 2: /* Unstructed with modem bits. Always one byte as we never 837 *dp += gsm_encode_modem(dlci);
831 send inline break data */ 838 len--;
832 *dp++ = gsm_encode_modem(dlci); 839 break;
833 break;
834 }
835 WARN_ON(kfifo_out_locked(dlci->fifo, dp , len, &dlci->lock) != len);
836 __gsm_data_queue(dlci, msg);
837 total_size += size;
838 } 840 }
841 WARN_ON(kfifo_out_locked(dlci->fifo, dp , len, &dlci->lock) != len);
842 __gsm_data_queue(dlci, msg);
839 /* Bytes of data we used up */ 843 /* Bytes of data we used up */
840 return total_size; 844 return size;
841} 845}
842 846
843/** 847/**
@@ -867,7 +871,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
867 871
868 /* dlci->skb is locked by tx_lock */ 872 /* dlci->skb is locked by tx_lock */
869 if (dlci->skb == NULL) { 873 if (dlci->skb == NULL) {
870 dlci->skb = skb_dequeue_tail(&dlci->skb_list); 874 dlci->skb = skb_dequeue(&dlci->skb_list);
871 if (dlci->skb == NULL) 875 if (dlci->skb == NULL)
872 return 0; 876 return 0;
873 first = 1; 877 first = 1;
@@ -878,7 +882,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
878 if (len > gsm->mtu) { 882 if (len > gsm->mtu) {
879 if (dlci->adaption == 3) { 883 if (dlci->adaption == 3) {
880 /* Over long frame, bin it */ 884 /* Over long frame, bin it */
881 dev_kfree_skb_any(dlci->skb); 885 kfree_skb(dlci->skb);
882 dlci->skb = NULL; 886 dlci->skb = NULL;
883 return 0; 887 return 0;
884 } 888 }
@@ -891,11 +895,8 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
891 895
892 /* FIXME: need a timer or something to kick this so it can't 896 /* FIXME: need a timer or something to kick this so it can't
893 get stuck with no work outstanding and no buffer free */ 897 get stuck with no work outstanding and no buffer free */
894 if (msg == NULL) { 898 if (msg == NULL)
895 skb_queue_tail(&dlci->skb_list, dlci->skb);
896 dlci->skb = NULL;
897 return -ENOMEM; 899 return -ENOMEM;
898 }
899 dp = msg->data; 900 dp = msg->data;
900 901
901 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ 902 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */
@@ -907,7 +908,7 @@ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
907 skb_pull(dlci->skb, len); 908 skb_pull(dlci->skb, len);
908 __gsm_data_queue(dlci, msg); 909 __gsm_data_queue(dlci, msg);
909 if (last) { 910 if (last) {
910 dev_kfree_skb_any(dlci->skb); 911 kfree_skb(dlci->skb);
911 dlci->skb = NULL; 912 dlci->skb = NULL;
912 } 913 }
913 return size; 914 return size;
@@ -966,22 +967,16 @@ static void gsm_dlci_data_sweep(struct gsm_mux *gsm)
966static void gsm_dlci_data_kick(struct gsm_dlci *dlci) 967static void gsm_dlci_data_kick(struct gsm_dlci *dlci)
967{ 968{
968 unsigned long flags; 969 unsigned long flags;
969 int sweep;
970
971 if (dlci->constipated)
972 return;
973 970
974 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); 971 spin_lock_irqsave(&dlci->gsm->tx_lock, flags);
975 /* If we have nothing running then we need to fire up */ 972 /* If we have nothing running then we need to fire up */
976 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO);
977 if (dlci->gsm->tx_bytes == 0) { 973 if (dlci->gsm->tx_bytes == 0) {
978 if (dlci->net) 974 if (dlci->net)
979 gsm_dlci_data_output_framed(dlci->gsm, dlci); 975 gsm_dlci_data_output_framed(dlci->gsm, dlci);
980 else 976 else
981 gsm_dlci_data_output(dlci->gsm, dlci); 977 gsm_dlci_data_output(dlci->gsm, dlci);
982 } 978 } else if (dlci->gsm->tx_bytes < TX_THRESH_LO)
983 if (sweep) 979 gsm_dlci_data_sweep(dlci->gsm);
984 gsm_dlci_data_sweep(dlci->gsm);
985 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); 980 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags);
986} 981}
987 982
@@ -1028,7 +1023,6 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci,
1028{ 1023{
1029 int mlines = 0; 1024 int mlines = 0;
1030 u8 brk = 0; 1025 u8 brk = 0;
1031 int fc;
1032 1026
1033 /* The modem status command can either contain one octet (v.24 signals) 1027 /* The modem status command can either contain one octet (v.24 signals)
1034 or two octets (v.24 signals + break signals). The length field will 1028 or two octets (v.24 signals + break signals). The length field will
@@ -1040,21 +1034,19 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci,
1040 else { 1034 else {
1041 brk = modem & 0x7f; 1035 brk = modem & 0x7f;
1042 modem = (modem >> 7) & 0x7f; 1036 modem = (modem >> 7) & 0x7f;
1043 } 1037 };
1044 1038
1045 /* Flow control/ready to communicate */ 1039 /* Flow control/ready to communicate */
1046 fc = (modem & MDM_FC) || !(modem & MDM_RTR); 1040 if (modem & MDM_FC) {
1047 if (fc && !dlci->constipated) {
1048 /* Need to throttle our output on this device */ 1041 /* Need to throttle our output on this device */
1049 dlci->constipated = 1; 1042 dlci->constipated = 1;
1050 } else if (!fc && dlci->constipated) { 1043 }
1044 if (modem & MDM_RTC) {
1045 mlines |= TIOCM_DSR | TIOCM_DTR;
1051 dlci->constipated = 0; 1046 dlci->constipated = 0;
1052 gsm_dlci_data_kick(dlci); 1047 gsm_dlci_data_kick(dlci);
1053 } 1048 }
1054
1055 /* Map modem bits */ 1049 /* Map modem bits */
1056 if (modem & MDM_RTC)
1057 mlines |= TIOCM_DSR | TIOCM_DTR;
1058 if (modem & MDM_RTR) 1050 if (modem & MDM_RTR)
1059 mlines |= TIOCM_RTS | TIOCM_CTS; 1051 mlines |= TIOCM_RTS | TIOCM_CTS;
1060 if (modem & MDM_IC) 1052 if (modem & MDM_IC)
@@ -1065,7 +1057,7 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci,
1065 /* Carrier drop -> hangup */ 1057 /* Carrier drop -> hangup */
1066 if (tty) { 1058 if (tty) {
1067 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) 1059 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD))
1068 if (!(tty->termios.c_cflag & CLOCAL)) 1060 if (!(tty->termios->c_cflag & CLOCAL))
1069 tty_hangup(tty); 1061 tty_hangup(tty);
1070 if (brk & 0x01) 1062 if (brk & 0x01)
1071 tty_insert_flip_char(tty, 0, TTY_BREAK); 1063 tty_insert_flip_char(tty, 0, TTY_BREAK);
@@ -1194,8 +1186,6 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command,
1194 u8 *data, int clen) 1186 u8 *data, int clen)
1195{ 1187{
1196 u8 buf[1]; 1188 u8 buf[1];
1197 unsigned long flags;
1198
1199 switch (command) { 1189 switch (command) {
1200 case CMD_CLD: { 1190 case CMD_CLD: {
1201 struct gsm_dlci *dlci = gsm->dlci[0]; 1191 struct gsm_dlci *dlci = gsm->dlci[0];
@@ -1212,18 +1202,16 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command,
1212 gsm_control_reply(gsm, CMD_TEST, data, clen); 1202 gsm_control_reply(gsm, CMD_TEST, data, clen);
1213 break; 1203 break;
1214 case CMD_FCON: 1204 case CMD_FCON:
1215 /* Modem can accept data again */ 1205 /* Modem wants us to STFU */
1216 gsm->constipated = 0; 1206 gsm->constipated = 1;
1217 gsm_control_reply(gsm, CMD_FCON, NULL, 0); 1207 gsm_control_reply(gsm, CMD_FCON, NULL, 0);
1218 /* Kick the link in case it is idling */
1219 spin_lock_irqsave(&gsm->tx_lock, flags);
1220 gsm_data_kick(gsm);
1221 spin_unlock_irqrestore(&gsm->tx_lock, flags);
1222 break; 1208 break;
1223 case CMD_FCOFF: 1209 case CMD_FCOFF:
1224 /* Modem wants us to STFU */ 1210 /* Modem can accept data again */
1225 gsm->constipated = 1; 1211 gsm->constipated = 0;
1226 gsm_control_reply(gsm, CMD_FCOFF, NULL, 0); 1212 gsm_control_reply(gsm, CMD_FCOFF, NULL, 0);
1213 /* Kick the link in case it is idling */
1214 gsm_data_kick(gsm);
1227 break; 1215 break;
1228 case CMD_MSC: 1216 case CMD_MSC:
1229 /* Out of band modem line change indicator for a DLCI */ 1217 /* Out of band modem line change indicator for a DLCI */
@@ -1634,6 +1622,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
1634 if (dlci == NULL) 1622 if (dlci == NULL)
1635 return NULL; 1623 return NULL;
1636 spin_lock_init(&dlci->lock); 1624 spin_lock_init(&dlci->lock);
1625 kref_init(&dlci->ref);
1637 mutex_init(&dlci->mutex); 1626 mutex_init(&dlci->mutex);
1638 dlci->fifo = &dlci->_fifo; 1627 dlci->fifo = &dlci->_fifo;
1639 if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) { 1628 if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
@@ -1667,26 +1656,26 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
1667 * 1656 *
1668 * Can sleep. 1657 * Can sleep.
1669 */ 1658 */
1670static void gsm_dlci_free(struct tty_port *port) 1659static void gsm_dlci_free(struct kref *ref)
1671{ 1660{
1672 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); 1661 struct gsm_dlci *dlci = container_of(ref, struct gsm_dlci, ref);
1673 1662
1674 del_timer_sync(&dlci->t1); 1663 del_timer_sync(&dlci->t1);
1675 dlci->gsm->dlci[dlci->addr] = NULL; 1664 dlci->gsm->dlci[dlci->addr] = NULL;
1676 kfifo_free(dlci->fifo); 1665 kfifo_free(dlci->fifo);
1677 while ((dlci->skb = skb_dequeue(&dlci->skb_list))) 1666 while ((dlci->skb = skb_dequeue(&dlci->skb_list)))
1678 dev_kfree_skb(dlci->skb); 1667 kfree_skb(dlci->skb);
1679 kfree(dlci); 1668 kfree(dlci);
1680} 1669}
1681 1670
1682static inline void dlci_get(struct gsm_dlci *dlci) 1671static inline void dlci_get(struct gsm_dlci *dlci)
1683{ 1672{
1684 tty_port_get(&dlci->port); 1673 kref_get(&dlci->ref);
1685} 1674}
1686 1675
1687static inline void dlci_put(struct gsm_dlci *dlci) 1676static inline void dlci_put(struct gsm_dlci *dlci)
1688{ 1677{
1689 tty_port_put(&dlci->port); 1678 kref_put(&dlci->ref, gsm_dlci_free);
1690} 1679}
1691 1680
1692/** 1681/**
@@ -2014,8 +2003,7 @@ void gsm_cleanup_mux(struct gsm_mux *gsm)
2014{ 2003{
2015 int i; 2004 int i;
2016 struct gsm_dlci *dlci = gsm->dlci[0]; 2005 struct gsm_dlci *dlci = gsm->dlci[0];
2017 struct gsm_msg *txq, *ntxq; 2006 struct gsm_msg *txq;
2018 struct gsm_control *gc;
2019 2007
2020 gsm->dead = 1; 2008 gsm->dead = 1;
2021 2009
@@ -2029,13 +2017,6 @@ void gsm_cleanup_mux(struct gsm_mux *gsm)
2029 spin_unlock(&gsm_mux_lock); 2017 spin_unlock(&gsm_mux_lock);
2030 WARN_ON(i == MAX_MUX); 2018 WARN_ON(i == MAX_MUX);
2031 2019
2032 /* In theory disconnecting DLCI 0 is sufficient but for some
2033 modems this is apparently not the case. */
2034 if (dlci) {
2035 gc = gsm_control_send(gsm, CMD_CLD, NULL, 0);
2036 if (gc)
2037 gsm_control_wait(gsm, gc);
2038 }
2039 del_timer_sync(&gsm->t2_timer); 2020 del_timer_sync(&gsm->t2_timer);
2040 /* Now we are sure T2 has stopped */ 2021 /* Now we are sure T2 has stopped */
2041 if (dlci) { 2022 if (dlci) {
@@ -2049,9 +2030,11 @@ void gsm_cleanup_mux(struct gsm_mux *gsm)
2049 if (gsm->dlci[i]) 2030 if (gsm->dlci[i])
2050 gsm_dlci_release(gsm->dlci[i]); 2031 gsm_dlci_release(gsm->dlci[i]);
2051 /* Now wipe the queues */ 2032 /* Now wipe the queues */
2052 list_for_each_entry_safe(txq, ntxq, &gsm->tx_list, list) 2033 for (txq = gsm->tx_head; txq != NULL; txq = gsm->tx_head) {
2034 gsm->tx_head = txq->next;
2053 kfree(txq); 2035 kfree(txq);
2054 INIT_LIST_HEAD(&gsm->tx_list); 2036 }
2037 gsm->tx_tail = NULL;
2055} 2038}
2056EXPORT_SYMBOL_GPL(gsm_cleanup_mux); 2039EXPORT_SYMBOL_GPL(gsm_cleanup_mux);
2057 2040
@@ -2162,7 +2145,6 @@ struct gsm_mux *gsm_alloc_mux(void)
2162 } 2145 }
2163 spin_lock_init(&gsm->lock); 2146 spin_lock_init(&gsm->lock);
2164 kref_init(&gsm->ref); 2147 kref_init(&gsm->ref);
2165 INIT_LIST_HEAD(&gsm->tx_list);
2166 2148
2167 gsm->t1 = T1; 2149 gsm->t1 = T1;
2168 gsm->t2 = T2; 2150 gsm->t2 = T2;
@@ -2279,7 +2261,7 @@ static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
2279 gsm->error(gsm, *dp, flags); 2261 gsm->error(gsm, *dp, flags);
2280 break; 2262 break;
2281 default: 2263 default:
2282 WARN_ONCE(1, "%s: unknown flag %d\n", 2264 WARN_ONCE("%s: unknown flag %d\n",
2283 tty_name(tty, buf), flags); 2265 tty_name(tty, buf), flags);
2284 break; 2266 break;
2285 } 2267 }
@@ -2383,12 +2365,12 @@ static void gsmld_write_wakeup(struct tty_struct *tty)
2383 2365
2384 /* Queue poll */ 2366 /* Queue poll */
2385 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 2367 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
2386 spin_lock_irqsave(&gsm->tx_lock, flags);
2387 gsm_data_kick(gsm); 2368 gsm_data_kick(gsm);
2388 if (gsm->tx_bytes < TX_THRESH_LO) { 2369 if (gsm->tx_bytes < TX_THRESH_LO) {
2370 spin_lock_irqsave(&gsm->tx_lock, flags);
2389 gsm_dlci_data_sweep(gsm); 2371 gsm_dlci_data_sweep(gsm);
2372 spin_unlock_irqrestore(&gsm->tx_lock, flags);
2390 } 2373 }
2391 spin_unlock_irqrestore(&gsm->tx_lock, flags);
2392} 2374}
2393 2375
2394/** 2376/**
@@ -2872,17 +2854,16 @@ static void gsm_dtr_rts(struct tty_port *port, int onoff)
2872static const struct tty_port_operations gsm_port_ops = { 2854static const struct tty_port_operations gsm_port_ops = {
2873 .carrier_raised = gsm_carrier_raised, 2855 .carrier_raised = gsm_carrier_raised,
2874 .dtr_rts = gsm_dtr_rts, 2856 .dtr_rts = gsm_dtr_rts,
2875 .destruct = gsm_dlci_free,
2876}; 2857};
2877 2858
2878static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty) 2859
2860static int gsmtty_open(struct tty_struct *tty, struct file *filp)
2879{ 2861{
2880 struct gsm_mux *gsm; 2862 struct gsm_mux *gsm;
2881 struct gsm_dlci *dlci; 2863 struct gsm_dlci *dlci;
2864 struct tty_port *port;
2882 unsigned int line = tty->index; 2865 unsigned int line = tty->index;
2883 unsigned int mux = line >> 6; 2866 unsigned int mux = line >> 6;
2884 bool alloc = false;
2885 int ret;
2886 2867
2887 line = line & 0x3F; 2868 line = line & 0x3F;
2888 2869
@@ -2896,35 +2877,14 @@ static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty)
2896 gsm = gsm_mux[mux]; 2877 gsm = gsm_mux[mux];
2897 if (gsm->dead) 2878 if (gsm->dead)
2898 return -EL2HLT; 2879 return -EL2HLT;
2899 /* If DLCI 0 is not yet fully open return an error. This is ok from a locking
2900 perspective as we don't have to worry about this if DLCI0 is lost */
2901 if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN)
2902 return -EL2NSYNC;
2903 dlci = gsm->dlci[line]; 2880 dlci = gsm->dlci[line];
2904 if (dlci == NULL) { 2881 if (dlci == NULL)
2905 alloc = true;
2906 dlci = gsm_dlci_alloc(gsm, line); 2882 dlci = gsm_dlci_alloc(gsm, line);
2907 }
2908 if (dlci == NULL) 2883 if (dlci == NULL)
2909 return -ENOMEM; 2884 return -ENOMEM;
2910 ret = tty_port_install(&dlci->port, driver, tty); 2885 port = &dlci->port;
2911 if (ret) {
2912 if (alloc)
2913 dlci_put(dlci);
2914 return ret;
2915 }
2916
2917 tty->driver_data = dlci;
2918
2919 return 0;
2920}
2921
2922static int gsmtty_open(struct tty_struct *tty, struct file *filp)
2923{
2924 struct gsm_dlci *dlci = tty->driver_data;
2925 struct tty_port *port = &dlci->port;
2926
2927 port->count++; 2886 port->count++;
2887 tty->driver_data = dlci;
2928 dlci_get(dlci); 2888 dlci_get(dlci);
2929 dlci_get(dlci->gsm->dlci[0]); 2889 dlci_get(dlci->gsm->dlci[0]);
2930 mux_get(dlci->gsm); 2890 mux_get(dlci->gsm);
@@ -3022,7 +2982,7 @@ static int gsmtty_tiocmset(struct tty_struct *tty,
3022 struct gsm_dlci *dlci = tty->driver_data; 2982 struct gsm_dlci *dlci = tty->driver_data;
3023 unsigned int modem_tx = dlci->modem_tx; 2983 unsigned int modem_tx = dlci->modem_tx;
3024 2984
3025 modem_tx &= ~clear; 2985 modem_tx &= clear;
3026 modem_tx |= set; 2986 modem_tx |= set;
3027 2987
3028 if (modem_tx != dlci->modem_tx) { 2988 if (modem_tx != dlci->modem_tx) {
@@ -3071,13 +3031,13 @@ static void gsmtty_set_termios(struct tty_struct *tty, struct ktermios *old)
3071 the RPN control message. This however rapidly gets nasty as we 3031 the RPN control message. This however rapidly gets nasty as we
3072 then have to remap modem signals each way according to whether 3032 then have to remap modem signals each way according to whether
3073 our virtual cable is null modem etc .. */ 3033 our virtual cable is null modem etc .. */
3074 tty_termios_copy_hw(&tty->termios, old); 3034 tty_termios_copy_hw(tty->termios, old);
3075} 3035}
3076 3036
3077static void gsmtty_throttle(struct tty_struct *tty) 3037static void gsmtty_throttle(struct tty_struct *tty)
3078{ 3038{
3079 struct gsm_dlci *dlci = tty->driver_data; 3039 struct gsm_dlci *dlci = tty->driver_data;
3080 if (tty->termios.c_cflag & CRTSCTS) 3040 if (tty->termios->c_cflag & CRTSCTS)
3081 dlci->modem_tx &= ~TIOCM_DTR; 3041 dlci->modem_tx &= ~TIOCM_DTR;
3082 dlci->throttled = 1; 3042 dlci->throttled = 1;
3083 /* Send an MSC with DTR cleared */ 3043 /* Send an MSC with DTR cleared */
@@ -3087,7 +3047,7 @@ static void gsmtty_throttle(struct tty_struct *tty)
3087static void gsmtty_unthrottle(struct tty_struct *tty) 3047static void gsmtty_unthrottle(struct tty_struct *tty)
3088{ 3048{
3089 struct gsm_dlci *dlci = tty->driver_data; 3049 struct gsm_dlci *dlci = tty->driver_data;
3090 if (tty->termios.c_cflag & CRTSCTS) 3050 if (tty->termios->c_cflag & CRTSCTS)
3091 dlci->modem_tx |= TIOCM_DTR; 3051 dlci->modem_tx |= TIOCM_DTR;
3092 dlci->throttled = 0; 3052 dlci->throttled = 0;
3093 /* Send an MSC with DTR set */ 3053 /* Send an MSC with DTR set */
@@ -3113,7 +3073,6 @@ static int gsmtty_break_ctl(struct tty_struct *tty, int state)
3113 3073
3114/* Virtual ttys for the demux */ 3074/* Virtual ttys for the demux */
3115static const struct tty_operations gsmtty_ops = { 3075static const struct tty_operations gsmtty_ops = {
3116 .install = gsmtty_install,
3117 .open = gsmtty_open, 3076 .open = gsmtty_open,
3118 .close = gsmtty_close, 3077 .close = gsmtty_close,
3119 .write = gsmtty_write, 3078 .write = gsmtty_write,
@@ -3149,6 +3108,7 @@ static int __init gsm_init(void)
3149 pr_err("gsm_init: tty allocation failed.\n"); 3108 pr_err("gsm_init: tty allocation failed.\n");
3150 return -EINVAL; 3109 return -EINVAL;
3151 } 3110 }
3111 gsm_tty_driver->owner = THIS_MODULE;
3152 gsm_tty_driver->driver_name = "gsmtty"; 3112 gsm_tty_driver->driver_name = "gsmtty";
3153 gsm_tty_driver->name = "gsmtty"; 3113 gsm_tty_driver->name = "gsmtty";
3154 gsm_tty_driver->major = 0; /* Dynamic */ 3114 gsm_tty_driver->major = 0; /* Dynamic */
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 1b2db9a3038..cea56033b34 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -102,6 +102,7 @@
102#include <linux/if.h> 102#include <linux/if.h>
103#include <linux/bitops.h> 103#include <linux/bitops.h>
104 104
105#include <asm/system.h>
105#include <asm/termios.h> 106#include <asm/termios.h>
106#include <asm/uaccess.h> 107#include <asm/uaccess.h>
107 108
@@ -416,7 +417,7 @@ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty)
416 __FILE__,__LINE__,tbuf,tbuf->count); 417 __FILE__,__LINE__,tbuf,tbuf->count);
417 418
418 /* Send the next block of data to device */ 419 /* Send the next block of data to device */
419 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 420 tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
420 actual = tty->ops->write(tty, tbuf->buf, tbuf->count); 421 actual = tty->ops->write(tty, tbuf->buf, tbuf->count);
421 422
422 /* rollback was possible and has been done */ 423 /* rollback was possible and has been done */
@@ -458,7 +459,7 @@ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty)
458 } 459 }
459 460
460 if (!tbuf) 461 if (!tbuf)
461 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 462 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
462 463
463 /* Clear the re-entry flag */ 464 /* Clear the re-entry flag */
464 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); 465 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags);
@@ -490,7 +491,7 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty)
490 return; 491 return;
491 492
492 if (tty != n_hdlc->tty) { 493 if (tty != n_hdlc->tty) {
493 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 494 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
494 return; 495 return;
495 } 496 }
496 497
diff --git a/drivers/tty/n_r3964.c b/drivers/tty/n_r3964.c
index 1e6405070ce..5c6c31459a2 100644
--- a/drivers/tty/n_r3964.c
+++ b/drivers/tty/n_r3964.c
@@ -1065,7 +1065,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1065 1065
1066 TRACE_L("read()"); 1066 TRACE_L("read()");
1067 1067
1068 tty_lock(tty); 1068 tty_lock();
1069 1069
1070 pClient = findClient(pInfo, task_pid(current)); 1070 pClient = findClient(pInfo, task_pid(current));
1071 if (pClient) { 1071 if (pClient) {
@@ -1077,7 +1077,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1077 goto unlock; 1077 goto unlock;
1078 } 1078 }
1079 /* block until there is a message: */ 1079 /* block until there is a message: */
1080 wait_event_interruptible_tty(tty, pInfo->read_wait, 1080 wait_event_interruptible_tty(pInfo->read_wait,
1081 (pMsg = remove_msg(pInfo, pClient))); 1081 (pMsg = remove_msg(pInfo, pClient)));
1082 } 1082 }
1083 1083
@@ -1107,7 +1107,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1107 } 1107 }
1108 ret = -EPERM; 1108 ret = -EPERM;
1109unlock: 1109unlock:
1110 tty_unlock(tty); 1110 tty_unlock();
1111 return ret; 1111 return ret;
1112} 1112}
1113 1113
@@ -1156,7 +1156,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1156 pHeader->locks = 0; 1156 pHeader->locks = 0;
1157 pHeader->owner = NULL; 1157 pHeader->owner = NULL;
1158 1158
1159 tty_lock(tty); 1159 tty_lock();
1160 1160
1161 pClient = findClient(pInfo, task_pid(current)); 1161 pClient = findClient(pInfo, task_pid(current));
1162 if (pClient) { 1162 if (pClient) {
@@ -1175,7 +1175,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1175 add_tx_queue(pInfo, pHeader); 1175 add_tx_queue(pInfo, pHeader);
1176 trigger_transmit(pInfo); 1176 trigger_transmit(pInfo);
1177 1177
1178 tty_unlock(tty); 1178 tty_unlock();
1179 1179
1180 return 0; 1180 return 0;
1181} 1181}
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 19083efa231..39d6ab6551e 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -50,6 +50,7 @@
50#include <linux/uaccess.h> 50#include <linux/uaccess.h>
51#include <linux/module.h> 51#include <linux/module.h>
52 52
53#include <asm/system.h>
53 54
54/* number of characters left in xmit buffer before select has we have room */ 55/* number of characters left in xmit buffer before select has we have room */
55#define WAKEUP_CHARS 256 56#define WAKEUP_CHARS 256
@@ -60,7 +61,7 @@
60 * controlling the space in the read buffer. 61 * controlling the space in the read buffer.
61 */ 62 */
62#define TTY_THRESHOLD_THROTTLE 128 /* now based on remaining room */ 63#define TTY_THRESHOLD_THROTTLE 128 /* now based on remaining room */
63#define TTY_THRESHOLD_UNTHROTTLE 128 64#define TTY_THRESHOLD_UNTHROTTLE 128
64 65
65/* 66/*
66 * Special byte codes used in the echo buffer to represent operations 67 * Special byte codes used in the echo buffer to represent operations
@@ -73,42 +74,10 @@
73#define ECHO_OP_SET_CANON_COL 0x81 74#define ECHO_OP_SET_CANON_COL 0x81
74#define ECHO_OP_ERASE_TAB 0x82 75#define ECHO_OP_ERASE_TAB 0x82
75 76
76struct n_tty_data {
77 unsigned int column;
78 unsigned long overrun_time;
79 int num_overrun;
80
81 unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
82 unsigned char echo_overrun:1;
83
84 DECLARE_BITMAP(process_char_map, 256);
85 DECLARE_BITMAP(read_flags, N_TTY_BUF_SIZE);
86
87 char *read_buf;
88 int read_head;
89 int read_tail;
90 int read_cnt;
91
92 unsigned char *echo_buf;
93 unsigned int echo_pos;
94 unsigned int echo_cnt;
95
96 int canon_data;
97 unsigned long canon_head;
98 unsigned int canon_column;
99
100 struct mutex atomic_read_lock;
101 struct mutex output_lock;
102 struct mutex echo_lock;
103 spinlock_t read_lock;
104};
105
106static inline int tty_put_user(struct tty_struct *tty, unsigned char x, 77static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
107 unsigned char __user *ptr) 78 unsigned char __user *ptr)
108{ 79{
109 struct n_tty_data *ldata = tty->disc_data; 80 tty_audit_add_data(tty, &x, 1);
110
111 tty_audit_add_data(tty, &x, 1, ldata->icanon);
112 return put_user(x, ptr); 81 return put_user(x, ptr);
113} 82}
114 83
@@ -124,19 +93,10 @@ static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
124 93
125static void n_tty_set_room(struct tty_struct *tty) 94static void n_tty_set_room(struct tty_struct *tty)
126{ 95{
127 struct n_tty_data *ldata = tty->disc_data; 96 /* tty->read_cnt is not read locked ? */
128 int left; 97 int left = N_TTY_BUF_SIZE - tty->read_cnt - 1;
129 int old_left; 98 int old_left;
130 99
131 /* ldata->read_cnt is not read locked ? */
132 if (I_PARMRK(tty)) {
133 /* Multiply read_cnt by 3, since each byte might take up to
134 * three times as many spaces when PARMRK is set (depending on
135 * its flags, e.g. parity error). */
136 left = N_TTY_BUF_SIZE - ldata->read_cnt * 3 - 1;
137 } else
138 left = N_TTY_BUF_SIZE - ldata->read_cnt - 1;
139
140 /* 100 /*
141 * If we are doing input canonicalization, and there are no 101 * If we are doing input canonicalization, and there are no
142 * pending newlines, let characters through without limit, so 102 * pending newlines, let characters through without limit, so
@@ -144,47 +104,44 @@ static void n_tty_set_room(struct tty_struct *tty)
144 * characters will be beeped. 104 * characters will be beeped.
145 */ 105 */
146 if (left <= 0) 106 if (left <= 0)
147 left = ldata->icanon && !ldata->canon_data; 107 left = tty->icanon && !tty->canon_data;
148 old_left = tty->receive_room; 108 old_left = tty->receive_room;
149 tty->receive_room = left; 109 tty->receive_room = left;
150 110
151 /* Did this open up the receive buffer? We may need to flip */ 111 /* Did this open up the receive buffer? We may need to flip */
152 if (left && !old_left) { 112 if (left && !old_left)
153 WARN_RATELIMIT(tty->port->itty == NULL, 113 schedule_work(&tty->buf.work);
154 "scheduling with invalid itty\n");
155 schedule_work(&tty->port->buf.work);
156 }
157} 114}
158 115
159static void put_tty_queue_nolock(unsigned char c, struct n_tty_data *ldata) 116static void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty)
160{ 117{
161 if (ldata->read_cnt < N_TTY_BUF_SIZE) { 118 if (tty->read_cnt < N_TTY_BUF_SIZE) {
162 ldata->read_buf[ldata->read_head] = c; 119 tty->read_buf[tty->read_head] = c;
163 ldata->read_head = (ldata->read_head + 1) & (N_TTY_BUF_SIZE-1); 120 tty->read_head = (tty->read_head + 1) & (N_TTY_BUF_SIZE-1);
164 ldata->read_cnt++; 121 tty->read_cnt++;
165 } 122 }
166} 123}
167 124
168/** 125/**
169 * put_tty_queue - add character to tty 126 * put_tty_queue - add character to tty
170 * @c: character 127 * @c: character
171 * @ldata: n_tty data 128 * @tty: tty device
172 * 129 *
173 * Add a character to the tty read_buf queue. This is done under the 130 * Add a character to the tty read_buf queue. This is done under the
174 * read_lock to serialize character addition and also to protect us 131 * read_lock to serialize character addition and also to protect us
175 * against parallel reads or flushes 132 * against parallel reads or flushes
176 */ 133 */
177 134
178static void put_tty_queue(unsigned char c, struct n_tty_data *ldata) 135static void put_tty_queue(unsigned char c, struct tty_struct *tty)
179{ 136{
180 unsigned long flags; 137 unsigned long flags;
181 /* 138 /*
182 * The problem of stomping on the buffers ends here. 139 * The problem of stomping on the buffers ends here.
183 * Why didn't anyone see this one coming? --AJK 140 * Why didn't anyone see this one coming? --AJK
184 */ 141 */
185 spin_lock_irqsave(&ldata->read_lock, flags); 142 spin_lock_irqsave(&tty->read_lock, flags);
186 put_tty_queue_nolock(c, ldata); 143 put_tty_queue_nolock(c, tty);
187 spin_unlock_irqrestore(&ldata->read_lock, flags); 144 spin_unlock_irqrestore(&tty->read_lock, flags);
188} 145}
189 146
190/** 147/**
@@ -215,19 +172,18 @@ static void check_unthrottle(struct tty_struct *tty)
215 172
216static void reset_buffer_flags(struct tty_struct *tty) 173static void reset_buffer_flags(struct tty_struct *tty)
217{ 174{
218 struct n_tty_data *ldata = tty->disc_data;
219 unsigned long flags; 175 unsigned long flags;
220 176
221 spin_lock_irqsave(&ldata->read_lock, flags); 177 spin_lock_irqsave(&tty->read_lock, flags);
222 ldata->read_head = ldata->read_tail = ldata->read_cnt = 0; 178 tty->read_head = tty->read_tail = tty->read_cnt = 0;
223 spin_unlock_irqrestore(&ldata->read_lock, flags); 179 spin_unlock_irqrestore(&tty->read_lock, flags);
224 180
225 mutex_lock(&ldata->echo_lock); 181 mutex_lock(&tty->echo_lock);
226 ldata->echo_pos = ldata->echo_cnt = ldata->echo_overrun = 0; 182 tty->echo_pos = tty->echo_cnt = tty->echo_overrun = 0;
227 mutex_unlock(&ldata->echo_lock); 183 mutex_unlock(&tty->echo_lock);
228 184
229 ldata->canon_head = ldata->canon_data = ldata->erasing = 0; 185 tty->canon_head = tty->canon_data = tty->erasing = 0;
230 bitmap_zero(ldata->read_flags, N_TTY_BUF_SIZE); 186 memset(&tty->read_flags, 0, sizeof tty->read_flags);
231 n_tty_set_room(tty); 187 n_tty_set_room(tty);
232} 188}
233 189
@@ -272,19 +228,18 @@ static void n_tty_flush_buffer(struct tty_struct *tty)
272 228
273static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty) 229static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty)
274{ 230{
275 struct n_tty_data *ldata = tty->disc_data;
276 unsigned long flags; 231 unsigned long flags;
277 ssize_t n = 0; 232 ssize_t n = 0;
278 233
279 spin_lock_irqsave(&ldata->read_lock, flags); 234 spin_lock_irqsave(&tty->read_lock, flags);
280 if (!ldata->icanon) { 235 if (!tty->icanon) {
281 n = ldata->read_cnt; 236 n = tty->read_cnt;
282 } else if (ldata->canon_data) { 237 } else if (tty->canon_data) {
283 n = (ldata->canon_head > ldata->read_tail) ? 238 n = (tty->canon_head > tty->read_tail) ?
284 ldata->canon_head - ldata->read_tail : 239 tty->canon_head - tty->read_tail :
285 ldata->canon_head + (N_TTY_BUF_SIZE - ldata->read_tail); 240 tty->canon_head + (N_TTY_BUF_SIZE - tty->read_tail);
286 } 241 }
287 spin_unlock_irqrestore(&ldata->read_lock, flags); 242 spin_unlock_irqrestore(&tty->read_lock, flags);
288 return n; 243 return n;
289} 244}
290 245
@@ -339,7 +294,6 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty)
339 294
340static int do_output_char(unsigned char c, struct tty_struct *tty, int space) 295static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
341{ 296{
342 struct n_tty_data *ldata = tty->disc_data;
343 int spaces; 297 int spaces;
344 298
345 if (!space) 299 if (!space)
@@ -348,48 +302,48 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
348 switch (c) { 302 switch (c) {
349 case '\n': 303 case '\n':
350 if (O_ONLRET(tty)) 304 if (O_ONLRET(tty))
351 ldata->column = 0; 305 tty->column = 0;
352 if (O_ONLCR(tty)) { 306 if (O_ONLCR(tty)) {
353 if (space < 2) 307 if (space < 2)
354 return -1; 308 return -1;
355 ldata->canon_column = ldata->column = 0; 309 tty->canon_column = tty->column = 0;
356 tty->ops->write(tty, "\r\n", 2); 310 tty->ops->write(tty, "\r\n", 2);
357 return 2; 311 return 2;
358 } 312 }
359 ldata->canon_column = ldata->column; 313 tty->canon_column = tty->column;
360 break; 314 break;
361 case '\r': 315 case '\r':
362 if (O_ONOCR(tty) && ldata->column == 0) 316 if (O_ONOCR(tty) && tty->column == 0)
363 return 0; 317 return 0;
364 if (O_OCRNL(tty)) { 318 if (O_OCRNL(tty)) {
365 c = '\n'; 319 c = '\n';
366 if (O_ONLRET(tty)) 320 if (O_ONLRET(tty))
367 ldata->canon_column = ldata->column = 0; 321 tty->canon_column = tty->column = 0;
368 break; 322 break;
369 } 323 }
370 ldata->canon_column = ldata->column = 0; 324 tty->canon_column = tty->column = 0;
371 break; 325 break;
372 case '\t': 326 case '\t':
373 spaces = 8 - (ldata->column & 7); 327 spaces = 8 - (tty->column & 7);
374 if (O_TABDLY(tty) == XTABS) { 328 if (O_TABDLY(tty) == XTABS) {
375 if (space < spaces) 329 if (space < spaces)
376 return -1; 330 return -1;
377 ldata->column += spaces; 331 tty->column += spaces;
378 tty->ops->write(tty, " ", spaces); 332 tty->ops->write(tty, " ", spaces);
379 return spaces; 333 return spaces;
380 } 334 }
381 ldata->column += spaces; 335 tty->column += spaces;
382 break; 336 break;
383 case '\b': 337 case '\b':
384 if (ldata->column > 0) 338 if (tty->column > 0)
385 ldata->column--; 339 tty->column--;
386 break; 340 break;
387 default: 341 default:
388 if (!iscntrl(c)) { 342 if (!iscntrl(c)) {
389 if (O_OLCUC(tty)) 343 if (O_OLCUC(tty))
390 c = toupper(c); 344 c = toupper(c);
391 if (!is_continuation(c, tty)) 345 if (!is_continuation(c, tty))
392 ldata->column++; 346 tty->column++;
393 } 347 }
394 break; 348 break;
395 } 349 }
@@ -414,15 +368,14 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
414 368
415static int process_output(unsigned char c, struct tty_struct *tty) 369static int process_output(unsigned char c, struct tty_struct *tty)
416{ 370{
417 struct n_tty_data *ldata = tty->disc_data;
418 int space, retval; 371 int space, retval;
419 372
420 mutex_lock(&ldata->output_lock); 373 mutex_lock(&tty->output_lock);
421 374
422 space = tty_write_room(tty); 375 space = tty_write_room(tty);
423 retval = do_output_char(c, tty, space); 376 retval = do_output_char(c, tty, space);
424 377
425 mutex_unlock(&ldata->output_lock); 378 mutex_unlock(&tty->output_lock);
426 if (retval < 0) 379 if (retval < 0)
427 return -1; 380 return -1;
428 else 381 else
@@ -451,16 +404,15 @@ static int process_output(unsigned char c, struct tty_struct *tty)
451static ssize_t process_output_block(struct tty_struct *tty, 404static ssize_t process_output_block(struct tty_struct *tty,
452 const unsigned char *buf, unsigned int nr) 405 const unsigned char *buf, unsigned int nr)
453{ 406{
454 struct n_tty_data *ldata = tty->disc_data;
455 int space; 407 int space;
456 int i; 408 int i;
457 const unsigned char *cp; 409 const unsigned char *cp;
458 410
459 mutex_lock(&ldata->output_lock); 411 mutex_lock(&tty->output_lock);
460 412
461 space = tty_write_room(tty); 413 space = tty_write_room(tty);
462 if (!space) { 414 if (!space) {
463 mutex_unlock(&ldata->output_lock); 415 mutex_unlock(&tty->output_lock);
464 return 0; 416 return 0;
465 } 417 }
466 if (nr > space) 418 if (nr > space)
@@ -472,30 +424,30 @@ static ssize_t process_output_block(struct tty_struct *tty,
472 switch (c) { 424 switch (c) {
473 case '\n': 425 case '\n':
474 if (O_ONLRET(tty)) 426 if (O_ONLRET(tty))
475 ldata->column = 0; 427 tty->column = 0;
476 if (O_ONLCR(tty)) 428 if (O_ONLCR(tty))
477 goto break_out; 429 goto break_out;
478 ldata->canon_column = ldata->column; 430 tty->canon_column = tty->column;
479 break; 431 break;
480 case '\r': 432 case '\r':
481 if (O_ONOCR(tty) && ldata->column == 0) 433 if (O_ONOCR(tty) && tty->column == 0)
482 goto break_out; 434 goto break_out;
483 if (O_OCRNL(tty)) 435 if (O_OCRNL(tty))
484 goto break_out; 436 goto break_out;
485 ldata->canon_column = ldata->column = 0; 437 tty->canon_column = tty->column = 0;
486 break; 438 break;
487 case '\t': 439 case '\t':
488 goto break_out; 440 goto break_out;
489 case '\b': 441 case '\b':
490 if (ldata->column > 0) 442 if (tty->column > 0)
491 ldata->column--; 443 tty->column--;
492 break; 444 break;
493 default: 445 default:
494 if (!iscntrl(c)) { 446 if (!iscntrl(c)) {
495 if (O_OLCUC(tty)) 447 if (O_OLCUC(tty))
496 goto break_out; 448 goto break_out;
497 if (!is_continuation(c, tty)) 449 if (!is_continuation(c, tty))
498 ldata->column++; 450 tty->column++;
499 } 451 }
500 break; 452 break;
501 } 453 }
@@ -503,7 +455,7 @@ static ssize_t process_output_block(struct tty_struct *tty,
503break_out: 455break_out:
504 i = tty->ops->write(tty, buf, i); 456 i = tty->ops->write(tty, buf, i);
505 457
506 mutex_unlock(&ldata->output_lock); 458 mutex_unlock(&tty->output_lock);
507 return i; 459 return i;
508} 460}
509 461
@@ -535,22 +487,21 @@ break_out:
535 487
536static void process_echoes(struct tty_struct *tty) 488static void process_echoes(struct tty_struct *tty)
537{ 489{
538 struct n_tty_data *ldata = tty->disc_data;
539 int space, nr; 490 int space, nr;
540 unsigned char c; 491 unsigned char c;
541 unsigned char *cp, *buf_end; 492 unsigned char *cp, *buf_end;
542 493
543 if (!ldata->echo_cnt) 494 if (!tty->echo_cnt)
544 return; 495 return;
545 496
546 mutex_lock(&ldata->output_lock); 497 mutex_lock(&tty->output_lock);
547 mutex_lock(&ldata->echo_lock); 498 mutex_lock(&tty->echo_lock);
548 499
549 space = tty_write_room(tty); 500 space = tty_write_room(tty);
550 501
551 buf_end = ldata->echo_buf + N_TTY_BUF_SIZE; 502 buf_end = tty->echo_buf + N_TTY_BUF_SIZE;
552 cp = ldata->echo_buf + ldata->echo_pos; 503 cp = tty->echo_buf + tty->echo_pos;
553 nr = ldata->echo_cnt; 504 nr = tty->echo_cnt;
554 while (nr > 0) { 505 while (nr > 0) {
555 c = *cp; 506 c = *cp;
556 if (c == ECHO_OP_START) { 507 if (c == ECHO_OP_START) {
@@ -587,7 +538,7 @@ static void process_echoes(struct tty_struct *tty)
587 * Otherwise, tab spacing is normal. 538 * Otherwise, tab spacing is normal.
588 */ 539 */
589 if (!(num_chars & 0x80)) 540 if (!(num_chars & 0x80))
590 num_chars += ldata->canon_column; 541 num_chars += tty->canon_column;
591 num_bs = 8 - (num_chars & 7); 542 num_bs = 8 - (num_chars & 7);
592 543
593 if (num_bs > space) { 544 if (num_bs > space) {
@@ -597,22 +548,22 @@ static void process_echoes(struct tty_struct *tty)
597 space -= num_bs; 548 space -= num_bs;
598 while (num_bs--) { 549 while (num_bs--) {
599 tty_put_char(tty, '\b'); 550 tty_put_char(tty, '\b');
600 if (ldata->column > 0) 551 if (tty->column > 0)
601 ldata->column--; 552 tty->column--;
602 } 553 }
603 cp += 3; 554 cp += 3;
604 nr -= 3; 555 nr -= 3;
605 break; 556 break;
606 557
607 case ECHO_OP_SET_CANON_COL: 558 case ECHO_OP_SET_CANON_COL:
608 ldata->canon_column = ldata->column; 559 tty->canon_column = tty->column;
609 cp += 2; 560 cp += 2;
610 nr -= 2; 561 nr -= 2;
611 break; 562 break;
612 563
613 case ECHO_OP_MOVE_BACK_COL: 564 case ECHO_OP_MOVE_BACK_COL:
614 if (ldata->column > 0) 565 if (tty->column > 0)
615 ldata->column--; 566 tty->column--;
616 cp += 2; 567 cp += 2;
617 nr -= 2; 568 nr -= 2;
618 break; 569 break;
@@ -624,7 +575,7 @@ static void process_echoes(struct tty_struct *tty)
624 break; 575 break;
625 } 576 }
626 tty_put_char(tty, ECHO_OP_START); 577 tty_put_char(tty, ECHO_OP_START);
627 ldata->column++; 578 tty->column++;
628 space--; 579 space--;
629 cp += 2; 580 cp += 2;
630 nr -= 2; 581 nr -= 2;
@@ -646,7 +597,7 @@ static void process_echoes(struct tty_struct *tty)
646 } 597 }
647 tty_put_char(tty, '^'); 598 tty_put_char(tty, '^');
648 tty_put_char(tty, op ^ 0100); 599 tty_put_char(tty, op ^ 0100);
649 ldata->column += 2; 600 tty->column += 2;
650 space -= 2; 601 space -= 2;
651 cp += 2; 602 cp += 2;
652 nr -= 2; 603 nr -= 2;
@@ -677,20 +628,20 @@ static void process_echoes(struct tty_struct *tty)
677 } 628 }
678 629
679 if (nr == 0) { 630 if (nr == 0) {
680 ldata->echo_pos = 0; 631 tty->echo_pos = 0;
681 ldata->echo_cnt = 0; 632 tty->echo_cnt = 0;
682 ldata->echo_overrun = 0; 633 tty->echo_overrun = 0;
683 } else { 634 } else {
684 int num_processed = ldata->echo_cnt - nr; 635 int num_processed = tty->echo_cnt - nr;
685 ldata->echo_pos += num_processed; 636 tty->echo_pos += num_processed;
686 ldata->echo_pos &= N_TTY_BUF_SIZE - 1; 637 tty->echo_pos &= N_TTY_BUF_SIZE - 1;
687 ldata->echo_cnt = nr; 638 tty->echo_cnt = nr;
688 if (num_processed > 0) 639 if (num_processed > 0)
689 ldata->echo_overrun = 0; 640 tty->echo_overrun = 0;
690 } 641 }
691 642
692 mutex_unlock(&ldata->echo_lock); 643 mutex_unlock(&tty->echo_lock);
693 mutex_unlock(&ldata->output_lock); 644 mutex_unlock(&tty->output_lock);
694 645
695 if (tty->ops->flush_chars) 646 if (tty->ops->flush_chars)
696 tty->ops->flush_chars(tty); 647 tty->ops->flush_chars(tty);
@@ -699,70 +650,72 @@ static void process_echoes(struct tty_struct *tty)
699/** 650/**
700 * add_echo_byte - add a byte to the echo buffer 651 * add_echo_byte - add a byte to the echo buffer
701 * @c: unicode byte to echo 652 * @c: unicode byte to echo
702 * @ldata: n_tty data 653 * @tty: terminal device
703 * 654 *
704 * Add a character or operation byte to the echo buffer. 655 * Add a character or operation byte to the echo buffer.
705 * 656 *
706 * Should be called under the echo lock to protect the echo buffer. 657 * Should be called under the echo lock to protect the echo buffer.
707 */ 658 */
708 659
709static void add_echo_byte(unsigned char c, struct n_tty_data *ldata) 660static void add_echo_byte(unsigned char c, struct tty_struct *tty)
710{ 661{
711 int new_byte_pos; 662 int new_byte_pos;
712 663
713 if (ldata->echo_cnt == N_TTY_BUF_SIZE) { 664 if (tty->echo_cnt == N_TTY_BUF_SIZE) {
714 /* Circular buffer is already at capacity */ 665 /* Circular buffer is already at capacity */
715 new_byte_pos = ldata->echo_pos; 666 new_byte_pos = tty->echo_pos;
716 667
717 /* 668 /*
718 * Since the buffer start position needs to be advanced, 669 * Since the buffer start position needs to be advanced,
719 * be sure to step by a whole operation byte group. 670 * be sure to step by a whole operation byte group.
720 */ 671 */
721 if (ldata->echo_buf[ldata->echo_pos] == ECHO_OP_START) { 672 if (tty->echo_buf[tty->echo_pos] == ECHO_OP_START) {
722 if (ldata->echo_buf[(ldata->echo_pos + 1) & 673 if (tty->echo_buf[(tty->echo_pos + 1) &
723 (N_TTY_BUF_SIZE - 1)] == 674 (N_TTY_BUF_SIZE - 1)] ==
724 ECHO_OP_ERASE_TAB) { 675 ECHO_OP_ERASE_TAB) {
725 ldata->echo_pos += 3; 676 tty->echo_pos += 3;
726 ldata->echo_cnt -= 2; 677 tty->echo_cnt -= 2;
727 } else { 678 } else {
728 ldata->echo_pos += 2; 679 tty->echo_pos += 2;
729 ldata->echo_cnt -= 1; 680 tty->echo_cnt -= 1;
730 } 681 }
731 } else { 682 } else {
732 ldata->echo_pos++; 683 tty->echo_pos++;
733 } 684 }
734 ldata->echo_pos &= N_TTY_BUF_SIZE - 1; 685 tty->echo_pos &= N_TTY_BUF_SIZE - 1;
735 686
736 ldata->echo_overrun = 1; 687 tty->echo_overrun = 1;
737 } else { 688 } else {
738 new_byte_pos = ldata->echo_pos + ldata->echo_cnt; 689 new_byte_pos = tty->echo_pos + tty->echo_cnt;
739 new_byte_pos &= N_TTY_BUF_SIZE - 1; 690 new_byte_pos &= N_TTY_BUF_SIZE - 1;
740 ldata->echo_cnt++; 691 tty->echo_cnt++;
741 } 692 }
742 693
743 ldata->echo_buf[new_byte_pos] = c; 694 tty->echo_buf[new_byte_pos] = c;
744} 695}
745 696
746/** 697/**
747 * echo_move_back_col - add operation to move back a column 698 * echo_move_back_col - add operation to move back a column
748 * @ldata: n_tty data 699 * @tty: terminal device
749 * 700 *
750 * Add an operation to the echo buffer to move back one column. 701 * Add an operation to the echo buffer to move back one column.
751 * 702 *
752 * Locking: echo_lock to protect the echo buffer 703 * Locking: echo_lock to protect the echo buffer
753 */ 704 */
754 705
755static void echo_move_back_col(struct n_tty_data *ldata) 706static void echo_move_back_col(struct tty_struct *tty)
756{ 707{
757 mutex_lock(&ldata->echo_lock); 708 mutex_lock(&tty->echo_lock);
758 add_echo_byte(ECHO_OP_START, ldata); 709
759 add_echo_byte(ECHO_OP_MOVE_BACK_COL, ldata); 710 add_echo_byte(ECHO_OP_START, tty);
760 mutex_unlock(&ldata->echo_lock); 711 add_echo_byte(ECHO_OP_MOVE_BACK_COL, tty);
712
713 mutex_unlock(&tty->echo_lock);
761} 714}
762 715
763/** 716/**
764 * echo_set_canon_col - add operation to set the canon column 717 * echo_set_canon_col - add operation to set the canon column
765 * @ldata: n_tty data 718 * @tty: terminal device
766 * 719 *
767 * Add an operation to the echo buffer to set the canon column 720 * Add an operation to the echo buffer to set the canon column
768 * to the current column. 721 * to the current column.
@@ -770,19 +723,21 @@ static void echo_move_back_col(struct n_tty_data *ldata)
770 * Locking: echo_lock to protect the echo buffer 723 * Locking: echo_lock to protect the echo buffer
771 */ 724 */
772 725
773static void echo_set_canon_col(struct n_tty_data *ldata) 726static void echo_set_canon_col(struct tty_struct *tty)
774{ 727{
775 mutex_lock(&ldata->echo_lock); 728 mutex_lock(&tty->echo_lock);
776 add_echo_byte(ECHO_OP_START, ldata); 729
777 add_echo_byte(ECHO_OP_SET_CANON_COL, ldata); 730 add_echo_byte(ECHO_OP_START, tty);
778 mutex_unlock(&ldata->echo_lock); 731 add_echo_byte(ECHO_OP_SET_CANON_COL, tty);
732
733 mutex_unlock(&tty->echo_lock);
779} 734}
780 735
781/** 736/**
782 * echo_erase_tab - add operation to erase a tab 737 * echo_erase_tab - add operation to erase a tab
783 * @num_chars: number of character columns already used 738 * @num_chars: number of character columns already used
784 * @after_tab: true if num_chars starts after a previous tab 739 * @after_tab: true if num_chars starts after a previous tab
785 * @ldata: n_tty data 740 * @tty: terminal device
786 * 741 *
787 * Add an operation to the echo buffer to erase a tab. 742 * Add an operation to the echo buffer to erase a tab.
788 * 743 *
@@ -796,12 +751,12 @@ static void echo_set_canon_col(struct n_tty_data *ldata)
796 */ 751 */
797 752
798static void echo_erase_tab(unsigned int num_chars, int after_tab, 753static void echo_erase_tab(unsigned int num_chars, int after_tab,
799 struct n_tty_data *ldata) 754 struct tty_struct *tty)
800{ 755{
801 mutex_lock(&ldata->echo_lock); 756 mutex_lock(&tty->echo_lock);
802 757
803 add_echo_byte(ECHO_OP_START, ldata); 758 add_echo_byte(ECHO_OP_START, tty);
804 add_echo_byte(ECHO_OP_ERASE_TAB, ldata); 759 add_echo_byte(ECHO_OP_ERASE_TAB, tty);
805 760
806 /* We only need to know this modulo 8 (tab spacing) */ 761 /* We only need to know this modulo 8 (tab spacing) */
807 num_chars &= 7; 762 num_chars &= 7;
@@ -810,9 +765,9 @@ static void echo_erase_tab(unsigned int num_chars, int after_tab,
810 if (after_tab) 765 if (after_tab)
811 num_chars |= 0x80; 766 num_chars |= 0x80;
812 767
813 add_echo_byte(num_chars, ldata); 768 add_echo_byte(num_chars, tty);
814 769
815 mutex_unlock(&ldata->echo_lock); 770 mutex_unlock(&tty->echo_lock);
816} 771}
817 772
818/** 773/**
@@ -828,16 +783,18 @@ static void echo_erase_tab(unsigned int num_chars, int after_tab,
828 * Locking: echo_lock to protect the echo buffer 783 * Locking: echo_lock to protect the echo buffer
829 */ 784 */
830 785
831static void echo_char_raw(unsigned char c, struct n_tty_data *ldata) 786static void echo_char_raw(unsigned char c, struct tty_struct *tty)
832{ 787{
833 mutex_lock(&ldata->echo_lock); 788 mutex_lock(&tty->echo_lock);
789
834 if (c == ECHO_OP_START) { 790 if (c == ECHO_OP_START) {
835 add_echo_byte(ECHO_OP_START, ldata); 791 add_echo_byte(ECHO_OP_START, tty);
836 add_echo_byte(ECHO_OP_START, ldata); 792 add_echo_byte(ECHO_OP_START, tty);
837 } else { 793 } else {
838 add_echo_byte(c, ldata); 794 add_echo_byte(c, tty);
839 } 795 }
840 mutex_unlock(&ldata->echo_lock); 796
797 mutex_unlock(&tty->echo_lock);
841} 798}
842 799
843/** 800/**
@@ -856,32 +813,30 @@ static void echo_char_raw(unsigned char c, struct n_tty_data *ldata)
856 813
857static void echo_char(unsigned char c, struct tty_struct *tty) 814static void echo_char(unsigned char c, struct tty_struct *tty)
858{ 815{
859 struct n_tty_data *ldata = tty->disc_data; 816 mutex_lock(&tty->echo_lock);
860
861 mutex_lock(&ldata->echo_lock);
862 817
863 if (c == ECHO_OP_START) { 818 if (c == ECHO_OP_START) {
864 add_echo_byte(ECHO_OP_START, ldata); 819 add_echo_byte(ECHO_OP_START, tty);
865 add_echo_byte(ECHO_OP_START, ldata); 820 add_echo_byte(ECHO_OP_START, tty);
866 } else { 821 } else {
867 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') 822 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t')
868 add_echo_byte(ECHO_OP_START, ldata); 823 add_echo_byte(ECHO_OP_START, tty);
869 add_echo_byte(c, ldata); 824 add_echo_byte(c, tty);
870 } 825 }
871 826
872 mutex_unlock(&ldata->echo_lock); 827 mutex_unlock(&tty->echo_lock);
873} 828}
874 829
875/** 830/**
876 * finish_erasing - complete erase 831 * finish_erasing - complete erase
877 * @ldata: n_tty data 832 * @tty: tty doing the erase
878 */ 833 */
879 834
880static inline void finish_erasing(struct n_tty_data *ldata) 835static inline void finish_erasing(struct tty_struct *tty)
881{ 836{
882 if (ldata->erasing) { 837 if (tty->erasing) {
883 echo_char_raw('/', ldata); 838 echo_char_raw('/', tty);
884 ldata->erasing = 0; 839 tty->erasing = 0;
885 } 840 }
886} 841}
887 842
@@ -899,13 +854,12 @@ static inline void finish_erasing(struct n_tty_data *ldata)
899 854
900static void eraser(unsigned char c, struct tty_struct *tty) 855static void eraser(unsigned char c, struct tty_struct *tty)
901{ 856{
902 struct n_tty_data *ldata = tty->disc_data;
903 enum { ERASE, WERASE, KILL } kill_type; 857 enum { ERASE, WERASE, KILL } kill_type;
904 int head, seen_alnums, cnt; 858 int head, seen_alnums, cnt;
905 unsigned long flags; 859 unsigned long flags;
906 860
907 /* FIXME: locking needed ? */ 861 /* FIXME: locking needed ? */
908 if (ldata->read_head == ldata->canon_head) { 862 if (tty->read_head == tty->canon_head) {
909 /* process_output('\a', tty); */ /* what do you think? */ 863 /* process_output('\a', tty); */ /* what do you think? */
910 return; 864 return;
911 } 865 }
@@ -915,24 +869,24 @@ static void eraser(unsigned char c, struct tty_struct *tty)
915 kill_type = WERASE; 869 kill_type = WERASE;
916 else { 870 else {
917 if (!L_ECHO(tty)) { 871 if (!L_ECHO(tty)) {
918 spin_lock_irqsave(&ldata->read_lock, flags); 872 spin_lock_irqsave(&tty->read_lock, flags);
919 ldata->read_cnt -= ((ldata->read_head - ldata->canon_head) & 873 tty->read_cnt -= ((tty->read_head - tty->canon_head) &
920 (N_TTY_BUF_SIZE - 1)); 874 (N_TTY_BUF_SIZE - 1));
921 ldata->read_head = ldata->canon_head; 875 tty->read_head = tty->canon_head;
922 spin_unlock_irqrestore(&ldata->read_lock, flags); 876 spin_unlock_irqrestore(&tty->read_lock, flags);
923 return; 877 return;
924 } 878 }
925 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { 879 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) {
926 spin_lock_irqsave(&ldata->read_lock, flags); 880 spin_lock_irqsave(&tty->read_lock, flags);
927 ldata->read_cnt -= ((ldata->read_head - ldata->canon_head) & 881 tty->read_cnt -= ((tty->read_head - tty->canon_head) &
928 (N_TTY_BUF_SIZE - 1)); 882 (N_TTY_BUF_SIZE - 1));
929 ldata->read_head = ldata->canon_head; 883 tty->read_head = tty->canon_head;
930 spin_unlock_irqrestore(&ldata->read_lock, flags); 884 spin_unlock_irqrestore(&tty->read_lock, flags);
931 finish_erasing(ldata); 885 finish_erasing(tty);
932 echo_char(KILL_CHAR(tty), tty); 886 echo_char(KILL_CHAR(tty), tty);
933 /* Add a newline if ECHOK is on and ECHOKE is off. */ 887 /* Add a newline if ECHOK is on and ECHOKE is off. */
934 if (L_ECHOK(tty)) 888 if (L_ECHOK(tty))
935 echo_char_raw('\n', ldata); 889 echo_char_raw('\n', tty);
936 return; 890 return;
937 } 891 }
938 kill_type = KILL; 892 kill_type = KILL;
@@ -940,14 +894,14 @@ static void eraser(unsigned char c, struct tty_struct *tty)
940 894
941 seen_alnums = 0; 895 seen_alnums = 0;
942 /* FIXME: Locking ?? */ 896 /* FIXME: Locking ?? */
943 while (ldata->read_head != ldata->canon_head) { 897 while (tty->read_head != tty->canon_head) {
944 head = ldata->read_head; 898 head = tty->read_head;
945 899
946 /* erase a single possibly multibyte character */ 900 /* erase a single possibly multibyte character */
947 do { 901 do {
948 head = (head - 1) & (N_TTY_BUF_SIZE-1); 902 head = (head - 1) & (N_TTY_BUF_SIZE-1);
949 c = ldata->read_buf[head]; 903 c = tty->read_buf[head];
950 } while (is_continuation(c, tty) && head != ldata->canon_head); 904 } while (is_continuation(c, tty) && head != tty->canon_head);
951 905
952 /* do not partially erase */ 906 /* do not partially erase */
953 if (is_continuation(c, tty)) 907 if (is_continuation(c, tty))
@@ -960,31 +914,30 @@ static void eraser(unsigned char c, struct tty_struct *tty)
960 else if (seen_alnums) 914 else if (seen_alnums)
961 break; 915 break;
962 } 916 }
963 cnt = (ldata->read_head - head) & (N_TTY_BUF_SIZE-1); 917 cnt = (tty->read_head - head) & (N_TTY_BUF_SIZE-1);
964 spin_lock_irqsave(&ldata->read_lock, flags); 918 spin_lock_irqsave(&tty->read_lock, flags);
965 ldata->read_head = head; 919 tty->read_head = head;
966 ldata->read_cnt -= cnt; 920 tty->read_cnt -= cnt;
967 spin_unlock_irqrestore(&ldata->read_lock, flags); 921 spin_unlock_irqrestore(&tty->read_lock, flags);
968 if (L_ECHO(tty)) { 922 if (L_ECHO(tty)) {
969 if (L_ECHOPRT(tty)) { 923 if (L_ECHOPRT(tty)) {
970 if (!ldata->erasing) { 924 if (!tty->erasing) {
971 echo_char_raw('\\', ldata); 925 echo_char_raw('\\', tty);
972 ldata->erasing = 1; 926 tty->erasing = 1;
973 } 927 }
974 /* if cnt > 1, output a multi-byte character */ 928 /* if cnt > 1, output a multi-byte character */
975 echo_char(c, tty); 929 echo_char(c, tty);
976 while (--cnt > 0) { 930 while (--cnt > 0) {
977 head = (head+1) & (N_TTY_BUF_SIZE-1); 931 head = (head+1) & (N_TTY_BUF_SIZE-1);
978 echo_char_raw(ldata->read_buf[head], 932 echo_char_raw(tty->read_buf[head], tty);
979 ldata); 933 echo_move_back_col(tty);
980 echo_move_back_col(ldata);
981 } 934 }
982 } else if (kill_type == ERASE && !L_ECHOE(tty)) { 935 } else if (kill_type == ERASE && !L_ECHOE(tty)) {
983 echo_char(ERASE_CHAR(tty), tty); 936 echo_char(ERASE_CHAR(tty), tty);
984 } else if (c == '\t') { 937 } else if (c == '\t') {
985 unsigned int num_chars = 0; 938 unsigned int num_chars = 0;
986 int after_tab = 0; 939 int after_tab = 0;
987 unsigned long tail = ldata->read_head; 940 unsigned long tail = tty->read_head;
988 941
989 /* 942 /*
990 * Count the columns used for characters 943 * Count the columns used for characters
@@ -993,9 +946,9 @@ static void eraser(unsigned char c, struct tty_struct *tty)
993 * This info is used to go back the correct 946 * This info is used to go back the correct
994 * number of columns. 947 * number of columns.
995 */ 948 */
996 while (tail != ldata->canon_head) { 949 while (tail != tty->canon_head) {
997 tail = (tail-1) & (N_TTY_BUF_SIZE-1); 950 tail = (tail-1) & (N_TTY_BUF_SIZE-1);
998 c = ldata->read_buf[tail]; 951 c = tty->read_buf[tail];
999 if (c == '\t') { 952 if (c == '\t') {
1000 after_tab = 1; 953 after_tab = 1;
1001 break; 954 break;
@@ -1006,25 +959,25 @@ static void eraser(unsigned char c, struct tty_struct *tty)
1006 num_chars++; 959 num_chars++;
1007 } 960 }
1008 } 961 }
1009 echo_erase_tab(num_chars, after_tab, ldata); 962 echo_erase_tab(num_chars, after_tab, tty);
1010 } else { 963 } else {
1011 if (iscntrl(c) && L_ECHOCTL(tty)) { 964 if (iscntrl(c) && L_ECHOCTL(tty)) {
1012 echo_char_raw('\b', ldata); 965 echo_char_raw('\b', tty);
1013 echo_char_raw(' ', ldata); 966 echo_char_raw(' ', tty);
1014 echo_char_raw('\b', ldata); 967 echo_char_raw('\b', tty);
1015 } 968 }
1016 if (!iscntrl(c) || L_ECHOCTL(tty)) { 969 if (!iscntrl(c) || L_ECHOCTL(tty)) {
1017 echo_char_raw('\b', ldata); 970 echo_char_raw('\b', tty);
1018 echo_char_raw(' ', ldata); 971 echo_char_raw(' ', tty);
1019 echo_char_raw('\b', ldata); 972 echo_char_raw('\b', tty);
1020 } 973 }
1021 } 974 }
1022 } 975 }
1023 if (kill_type == ERASE) 976 if (kill_type == ERASE)
1024 break; 977 break;
1025 } 978 }
1026 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) 979 if (tty->read_head == tty->canon_head && L_ECHO(tty))
1027 finish_erasing(ldata); 980 finish_erasing(tty);
1028} 981}
1029 982
1030/** 983/**
@@ -1063,8 +1016,6 @@ static inline void isig(int sig, struct tty_struct *tty, int flush)
1063 1016
1064static inline void n_tty_receive_break(struct tty_struct *tty) 1017static inline void n_tty_receive_break(struct tty_struct *tty)
1065{ 1018{
1066 struct n_tty_data *ldata = tty->disc_data;
1067
1068 if (I_IGNBRK(tty)) 1019 if (I_IGNBRK(tty))
1069 return; 1020 return;
1070 if (I_BRKINT(tty)) { 1021 if (I_BRKINT(tty)) {
@@ -1072,10 +1023,10 @@ static inline void n_tty_receive_break(struct tty_struct *tty)
1072 return; 1023 return;
1073 } 1024 }
1074 if (I_PARMRK(tty)) { 1025 if (I_PARMRK(tty)) {
1075 put_tty_queue('\377', ldata); 1026 put_tty_queue('\377', tty);
1076 put_tty_queue('\0', ldata); 1027 put_tty_queue('\0', tty);
1077 } 1028 }
1078 put_tty_queue('\0', ldata); 1029 put_tty_queue('\0', tty);
1079 wake_up_interruptible(&tty->read_wait); 1030 wake_up_interruptible(&tty->read_wait);
1080} 1031}
1081 1032
@@ -1094,17 +1045,16 @@ static inline void n_tty_receive_break(struct tty_struct *tty)
1094 1045
1095static inline void n_tty_receive_overrun(struct tty_struct *tty) 1046static inline void n_tty_receive_overrun(struct tty_struct *tty)
1096{ 1047{
1097 struct n_tty_data *ldata = tty->disc_data;
1098 char buf[64]; 1048 char buf[64];
1099 1049
1100 ldata->num_overrun++; 1050 tty->num_overrun++;
1101 if (time_after(jiffies, ldata->overrun_time + HZ) || 1051 if (time_before(tty->overrun_time, jiffies - HZ) ||
1102 time_after(ldata->overrun_time, jiffies)) { 1052 time_after(tty->overrun_time, jiffies)) {
1103 printk(KERN_WARNING "%s: %d input overrun(s)\n", 1053 printk(KERN_WARNING "%s: %d input overrun(s)\n",
1104 tty_name(tty, buf), 1054 tty_name(tty, buf),
1105 ldata->num_overrun); 1055 tty->num_overrun);
1106 ldata->overrun_time = jiffies; 1056 tty->overrun_time = jiffies;
1107 ldata->num_overrun = 0; 1057 tty->num_overrun = 0;
1108 } 1058 }
1109} 1059}
1110 1060
@@ -1119,18 +1069,16 @@ static inline void n_tty_receive_overrun(struct tty_struct *tty)
1119static inline void n_tty_receive_parity_error(struct tty_struct *tty, 1069static inline void n_tty_receive_parity_error(struct tty_struct *tty,
1120 unsigned char c) 1070 unsigned char c)
1121{ 1071{
1122 struct n_tty_data *ldata = tty->disc_data;
1123
1124 if (I_IGNPAR(tty)) 1072 if (I_IGNPAR(tty))
1125 return; 1073 return;
1126 if (I_PARMRK(tty)) { 1074 if (I_PARMRK(tty)) {
1127 put_tty_queue('\377', ldata); 1075 put_tty_queue('\377', tty);
1128 put_tty_queue('\0', ldata); 1076 put_tty_queue('\0', tty);
1129 put_tty_queue(c, ldata); 1077 put_tty_queue(c, tty);
1130 } else if (I_INPCK(tty)) 1078 } else if (I_INPCK(tty))
1131 put_tty_queue('\0', ldata); 1079 put_tty_queue('\0', tty);
1132 else 1080 else
1133 put_tty_queue(c, ldata); 1081 put_tty_queue(c, tty);
1134 wake_up_interruptible(&tty->read_wait); 1082 wake_up_interruptible(&tty->read_wait);
1135} 1083}
1136 1084
@@ -1146,12 +1094,11 @@ static inline void n_tty_receive_parity_error(struct tty_struct *tty,
1146 1094
1147static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) 1095static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1148{ 1096{
1149 struct n_tty_data *ldata = tty->disc_data;
1150 unsigned long flags; 1097 unsigned long flags;
1151 int parmrk; 1098 int parmrk;
1152 1099
1153 if (ldata->raw) { 1100 if (tty->raw) {
1154 put_tty_queue(c, ldata); 1101 put_tty_queue(c, tty);
1155 return; 1102 return;
1156 } 1103 }
1157 1104
@@ -1161,7 +1108,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1161 c = tolower(c); 1108 c = tolower(c);
1162 1109
1163 if (L_EXTPROC(tty)) { 1110 if (L_EXTPROC(tty)) {
1164 put_tty_queue(c, ldata); 1111 put_tty_queue(c, tty);
1165 return; 1112 return;
1166 } 1113 }
1167 1114
@@ -1189,26 +1136,26 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1189 * handle specially, do shortcut processing to speed things 1136 * handle specially, do shortcut processing to speed things
1190 * up. 1137 * up.
1191 */ 1138 */
1192 if (!test_bit(c, ldata->process_char_map) || ldata->lnext) { 1139 if (!test_bit(c, tty->process_char_map) || tty->lnext) {
1193 ldata->lnext = 0; 1140 tty->lnext = 0;
1194 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; 1141 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1195 if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { 1142 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1196 /* beep if no space */ 1143 /* beep if no space */
1197 if (L_ECHO(tty)) 1144 if (L_ECHO(tty))
1198 process_output('\a', tty); 1145 process_output('\a', tty);
1199 return; 1146 return;
1200 } 1147 }
1201 if (L_ECHO(tty)) { 1148 if (L_ECHO(tty)) {
1202 finish_erasing(ldata); 1149 finish_erasing(tty);
1203 /* Record the column of first canon char. */ 1150 /* Record the column of first canon char. */
1204 if (ldata->canon_head == ldata->read_head) 1151 if (tty->canon_head == tty->read_head)
1205 echo_set_canon_col(ldata); 1152 echo_set_canon_col(tty);
1206 echo_char(c, tty); 1153 echo_char(c, tty);
1207 process_echoes(tty); 1154 process_echoes(tty);
1208 } 1155 }
1209 if (parmrk) 1156 if (parmrk)
1210 put_tty_queue(c, ldata); 1157 put_tty_queue(c, tty);
1211 put_tty_queue(c, ldata); 1158 put_tty_queue(c, tty);
1212 return; 1159 return;
1213 } 1160 }
1214 1161
@@ -1264,7 +1211,7 @@ send_signal:
1264 } else if (c == '\n' && I_INLCR(tty)) 1211 } else if (c == '\n' && I_INLCR(tty))
1265 c = '\r'; 1212 c = '\r';
1266 1213
1267 if (ldata->icanon) { 1214 if (tty->icanon) {
1268 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || 1215 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) ||
1269 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { 1216 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) {
1270 eraser(c, tty); 1217 eraser(c, tty);
@@ -1272,12 +1219,12 @@ send_signal:
1272 return; 1219 return;
1273 } 1220 }
1274 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { 1221 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) {
1275 ldata->lnext = 1; 1222 tty->lnext = 1;
1276 if (L_ECHO(tty)) { 1223 if (L_ECHO(tty)) {
1277 finish_erasing(ldata); 1224 finish_erasing(tty);
1278 if (L_ECHOCTL(tty)) { 1225 if (L_ECHOCTL(tty)) {
1279 echo_char_raw('^', ldata); 1226 echo_char_raw('^', tty);
1280 echo_char_raw('\b', ldata); 1227 echo_char_raw('\b', tty);
1281 process_echoes(tty); 1228 process_echoes(tty);
1282 } 1229 }
1283 } 1230 }
@@ -1285,34 +1232,34 @@ send_signal:
1285 } 1232 }
1286 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && 1233 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) &&
1287 L_IEXTEN(tty)) { 1234 L_IEXTEN(tty)) {
1288 unsigned long tail = ldata->canon_head; 1235 unsigned long tail = tty->canon_head;
1289 1236
1290 finish_erasing(ldata); 1237 finish_erasing(tty);
1291 echo_char(c, tty); 1238 echo_char(c, tty);
1292 echo_char_raw('\n', ldata); 1239 echo_char_raw('\n', tty);
1293 while (tail != ldata->read_head) { 1240 while (tail != tty->read_head) {
1294 echo_char(ldata->read_buf[tail], tty); 1241 echo_char(tty->read_buf[tail], tty);
1295 tail = (tail+1) & (N_TTY_BUF_SIZE-1); 1242 tail = (tail+1) & (N_TTY_BUF_SIZE-1);
1296 } 1243 }
1297 process_echoes(tty); 1244 process_echoes(tty);
1298 return; 1245 return;
1299 } 1246 }
1300 if (c == '\n') { 1247 if (c == '\n') {
1301 if (ldata->read_cnt >= N_TTY_BUF_SIZE) { 1248 if (tty->read_cnt >= N_TTY_BUF_SIZE) {
1302 if (L_ECHO(tty)) 1249 if (L_ECHO(tty))
1303 process_output('\a', tty); 1250 process_output('\a', tty);
1304 return; 1251 return;
1305 } 1252 }
1306 if (L_ECHO(tty) || L_ECHONL(tty)) { 1253 if (L_ECHO(tty) || L_ECHONL(tty)) {
1307 echo_char_raw('\n', ldata); 1254 echo_char_raw('\n', tty);
1308 process_echoes(tty); 1255 process_echoes(tty);
1309 } 1256 }
1310 goto handle_newline; 1257 goto handle_newline;
1311 } 1258 }
1312 if (c == EOF_CHAR(tty)) { 1259 if (c == EOF_CHAR(tty)) {
1313 if (ldata->read_cnt >= N_TTY_BUF_SIZE) 1260 if (tty->read_cnt >= N_TTY_BUF_SIZE)
1314 return; 1261 return;
1315 if (ldata->canon_head != ldata->read_head) 1262 if (tty->canon_head != tty->read_head)
1316 set_bit(TTY_PUSH, &tty->flags); 1263 set_bit(TTY_PUSH, &tty->flags);
1317 c = __DISABLED_CHAR; 1264 c = __DISABLED_CHAR;
1318 goto handle_newline; 1265 goto handle_newline;
@@ -1321,7 +1268,7 @@ send_signal:
1321 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { 1268 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) {
1322 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) 1269 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty))
1323 ? 1 : 0; 1270 ? 1 : 0;
1324 if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) { 1271 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) {
1325 if (L_ECHO(tty)) 1272 if (L_ECHO(tty))
1326 process_output('\a', tty); 1273 process_output('\a', tty);
1327 return; 1274 return;
@@ -1331,8 +1278,8 @@ send_signal:
1331 */ 1278 */
1332 if (L_ECHO(tty)) { 1279 if (L_ECHO(tty)) {
1333 /* Record the column of first canon char. */ 1280 /* Record the column of first canon char. */
1334 if (ldata->canon_head == ldata->read_head) 1281 if (tty->canon_head == tty->read_head)
1335 echo_set_canon_col(ldata); 1282 echo_set_canon_col(tty);
1336 echo_char(c, tty); 1283 echo_char(c, tty);
1337 process_echoes(tty); 1284 process_echoes(tty);
1338 } 1285 }
@@ -1341,15 +1288,15 @@ send_signal:
1341 * EOL_CHAR and EOL2_CHAR? 1288 * EOL_CHAR and EOL2_CHAR?
1342 */ 1289 */
1343 if (parmrk) 1290 if (parmrk)
1344 put_tty_queue(c, ldata); 1291 put_tty_queue(c, tty);
1345 1292
1346handle_newline: 1293handle_newline:
1347 spin_lock_irqsave(&ldata->read_lock, flags); 1294 spin_lock_irqsave(&tty->read_lock, flags);
1348 set_bit(ldata->read_head, ldata->read_flags); 1295 set_bit(tty->read_head, tty->read_flags);
1349 put_tty_queue_nolock(c, ldata); 1296 put_tty_queue_nolock(c, tty);
1350 ldata->canon_head = ldata->read_head; 1297 tty->canon_head = tty->read_head;
1351 ldata->canon_data++; 1298 tty->canon_data++;
1352 spin_unlock_irqrestore(&ldata->read_lock, flags); 1299 spin_unlock_irqrestore(&tty->read_lock, flags);
1353 kill_fasync(&tty->fasync, SIGIO, POLL_IN); 1300 kill_fasync(&tty->fasync, SIGIO, POLL_IN);
1354 if (waitqueue_active(&tty->read_wait)) 1301 if (waitqueue_active(&tty->read_wait))
1355 wake_up_interruptible(&tty->read_wait); 1302 wake_up_interruptible(&tty->read_wait);
@@ -1358,29 +1305,29 @@ handle_newline:
1358 } 1305 }
1359 1306
1360 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0; 1307 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1361 if (ldata->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) { 1308 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1362 /* beep if no space */ 1309 /* beep if no space */
1363 if (L_ECHO(tty)) 1310 if (L_ECHO(tty))
1364 process_output('\a', tty); 1311 process_output('\a', tty);
1365 return; 1312 return;
1366 } 1313 }
1367 if (L_ECHO(tty)) { 1314 if (L_ECHO(tty)) {
1368 finish_erasing(ldata); 1315 finish_erasing(tty);
1369 if (c == '\n') 1316 if (c == '\n')
1370 echo_char_raw('\n', ldata); 1317 echo_char_raw('\n', tty);
1371 else { 1318 else {
1372 /* Record the column of first canon char. */ 1319 /* Record the column of first canon char. */
1373 if (ldata->canon_head == ldata->read_head) 1320 if (tty->canon_head == tty->read_head)
1374 echo_set_canon_col(ldata); 1321 echo_set_canon_col(tty);
1375 echo_char(c, tty); 1322 echo_char(c, tty);
1376 } 1323 }
1377 process_echoes(tty); 1324 process_echoes(tty);
1378 } 1325 }
1379 1326
1380 if (parmrk) 1327 if (parmrk)
1381 put_tty_queue(c, ldata); 1328 put_tty_queue(c, tty);
1382 1329
1383 put_tty_queue(c, ldata); 1330 put_tty_queue(c, tty);
1384} 1331}
1385 1332
1386 1333
@@ -1415,31 +1362,33 @@ static void n_tty_write_wakeup(struct tty_struct *tty)
1415static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, 1362static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1416 char *fp, int count) 1363 char *fp, int count)
1417{ 1364{
1418 struct n_tty_data *ldata = tty->disc_data;
1419 const unsigned char *p; 1365 const unsigned char *p;
1420 char *f, flags = TTY_NORMAL; 1366 char *f, flags = TTY_NORMAL;
1421 int i; 1367 int i;
1422 char buf[64]; 1368 char buf[64];
1423 unsigned long cpuflags; 1369 unsigned long cpuflags;
1424 1370
1425 if (ldata->real_raw) { 1371 if (!tty->read_buf)
1426 spin_lock_irqsave(&ldata->read_lock, cpuflags); 1372 return;
1427 i = min(N_TTY_BUF_SIZE - ldata->read_cnt, 1373
1428 N_TTY_BUF_SIZE - ldata->read_head); 1374 if (tty->real_raw) {
1375 spin_lock_irqsave(&tty->read_lock, cpuflags);
1376 i = min(N_TTY_BUF_SIZE - tty->read_cnt,
1377 N_TTY_BUF_SIZE - tty->read_head);
1429 i = min(count, i); 1378 i = min(count, i);
1430 memcpy(ldata->read_buf + ldata->read_head, cp, i); 1379 memcpy(tty->read_buf + tty->read_head, cp, i);
1431 ldata->read_head = (ldata->read_head + i) & (N_TTY_BUF_SIZE-1); 1380 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1);
1432 ldata->read_cnt += i; 1381 tty->read_cnt += i;
1433 cp += i; 1382 cp += i;
1434 count -= i; 1383 count -= i;
1435 1384
1436 i = min(N_TTY_BUF_SIZE - ldata->read_cnt, 1385 i = min(N_TTY_BUF_SIZE - tty->read_cnt,
1437 N_TTY_BUF_SIZE - ldata->read_head); 1386 N_TTY_BUF_SIZE - tty->read_head);
1438 i = min(count, i); 1387 i = min(count, i);
1439 memcpy(ldata->read_buf + ldata->read_head, cp, i); 1388 memcpy(tty->read_buf + tty->read_head, cp, i);
1440 ldata->read_head = (ldata->read_head + i) & (N_TTY_BUF_SIZE-1); 1389 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1);
1441 ldata->read_cnt += i; 1390 tty->read_cnt += i;
1442 spin_unlock_irqrestore(&ldata->read_lock, cpuflags); 1391 spin_unlock_irqrestore(&tty->read_lock, cpuflags);
1443 } else { 1392 } else {
1444 for (i = count, p = cp, f = fp; i; i--, p++) { 1393 for (i = count, p = cp, f = fp; i; i--, p++) {
1445 if (f) 1394 if (f)
@@ -1470,7 +1419,7 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1470 1419
1471 n_tty_set_room(tty); 1420 n_tty_set_room(tty);
1472 1421
1473 if ((!ldata->icanon && (ldata->read_cnt >= tty->minimum_to_wake)) || 1422 if ((!tty->icanon && (tty->read_cnt >= tty->minimum_to_wake)) ||
1474 L_EXTPROC(tty)) { 1423 L_EXTPROC(tty)) {
1475 kill_fasync(&tty->fasync, SIGIO, POLL_IN); 1424 kill_fasync(&tty->fasync, SIGIO, POLL_IN);
1476 if (waitqueue_active(&tty->read_wait)) 1425 if (waitqueue_active(&tty->read_wait))
@@ -1484,12 +1433,6 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1484 */ 1433 */
1485 if (tty->receive_room < TTY_THRESHOLD_THROTTLE) 1434 if (tty->receive_room < TTY_THRESHOLD_THROTTLE)
1486 tty_throttle(tty); 1435 tty_throttle(tty);
1487
1488 /* FIXME: there is a tiny race here if the receive room check runs
1489 before the other work executes and empties the buffer (upping
1490 the receiving room and unthrottling. We then throttle and get
1491 stuck. This has been observed and traced down by Vincent Pillet/
1492 We need to address this when we sort out out the rx path locking */
1493} 1436}
1494 1437
1495int is_ignored(int sig) 1438int is_ignored(int sig)
@@ -1514,25 +1457,25 @@ int is_ignored(int sig)
1514 1457
1515static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) 1458static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1516{ 1459{
1517 struct n_tty_data *ldata = tty->disc_data;
1518 int canon_change = 1; 1460 int canon_change = 1;
1461 BUG_ON(!tty);
1519 1462
1520 if (old) 1463 if (old)
1521 canon_change = (old->c_lflag ^ tty->termios.c_lflag) & ICANON; 1464 canon_change = (old->c_lflag ^ tty->termios->c_lflag) & ICANON;
1522 if (canon_change) { 1465 if (canon_change) {
1523 bitmap_zero(ldata->read_flags, N_TTY_BUF_SIZE); 1466 memset(&tty->read_flags, 0, sizeof tty->read_flags);
1524 ldata->canon_head = ldata->read_tail; 1467 tty->canon_head = tty->read_tail;
1525 ldata->canon_data = 0; 1468 tty->canon_data = 0;
1526 ldata->erasing = 0; 1469 tty->erasing = 0;
1527 } 1470 }
1528 1471
1529 if (canon_change && !L_ICANON(tty) && ldata->read_cnt) 1472 if (canon_change && !L_ICANON(tty) && tty->read_cnt)
1530 wake_up_interruptible(&tty->read_wait); 1473 wake_up_interruptible(&tty->read_wait);
1531 1474
1532 ldata->icanon = (L_ICANON(tty) != 0); 1475 tty->icanon = (L_ICANON(tty) != 0);
1533 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) { 1476 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) {
1534 ldata->raw = 1; 1477 tty->raw = 1;
1535 ldata->real_raw = 1; 1478 tty->real_raw = 1;
1536 n_tty_set_room(tty); 1479 n_tty_set_room(tty);
1537 return; 1480 return;
1538 } 1481 }
@@ -1540,51 +1483,51 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1540 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || 1483 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) ||
1541 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || 1484 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) ||
1542 I_PARMRK(tty)) { 1485 I_PARMRK(tty)) {
1543 bitmap_zero(ldata->process_char_map, 256); 1486 memset(tty->process_char_map, 0, 256/8);
1544 1487
1545 if (I_IGNCR(tty) || I_ICRNL(tty)) 1488 if (I_IGNCR(tty) || I_ICRNL(tty))
1546 set_bit('\r', ldata->process_char_map); 1489 set_bit('\r', tty->process_char_map);
1547 if (I_INLCR(tty)) 1490 if (I_INLCR(tty))
1548 set_bit('\n', ldata->process_char_map); 1491 set_bit('\n', tty->process_char_map);
1549 1492
1550 if (L_ICANON(tty)) { 1493 if (L_ICANON(tty)) {
1551 set_bit(ERASE_CHAR(tty), ldata->process_char_map); 1494 set_bit(ERASE_CHAR(tty), tty->process_char_map);
1552 set_bit(KILL_CHAR(tty), ldata->process_char_map); 1495 set_bit(KILL_CHAR(tty), tty->process_char_map);
1553 set_bit(EOF_CHAR(tty), ldata->process_char_map); 1496 set_bit(EOF_CHAR(tty), tty->process_char_map);
1554 set_bit('\n', ldata->process_char_map); 1497 set_bit('\n', tty->process_char_map);
1555 set_bit(EOL_CHAR(tty), ldata->process_char_map); 1498 set_bit(EOL_CHAR(tty), tty->process_char_map);
1556 if (L_IEXTEN(tty)) { 1499 if (L_IEXTEN(tty)) {
1557 set_bit(WERASE_CHAR(tty), 1500 set_bit(WERASE_CHAR(tty),
1558 ldata->process_char_map); 1501 tty->process_char_map);
1559 set_bit(LNEXT_CHAR(tty), 1502 set_bit(LNEXT_CHAR(tty),
1560 ldata->process_char_map); 1503 tty->process_char_map);
1561 set_bit(EOL2_CHAR(tty), 1504 set_bit(EOL2_CHAR(tty),
1562 ldata->process_char_map); 1505 tty->process_char_map);
1563 if (L_ECHO(tty)) 1506 if (L_ECHO(tty))
1564 set_bit(REPRINT_CHAR(tty), 1507 set_bit(REPRINT_CHAR(tty),
1565 ldata->process_char_map); 1508 tty->process_char_map);
1566 } 1509 }
1567 } 1510 }
1568 if (I_IXON(tty)) { 1511 if (I_IXON(tty)) {
1569 set_bit(START_CHAR(tty), ldata->process_char_map); 1512 set_bit(START_CHAR(tty), tty->process_char_map);
1570 set_bit(STOP_CHAR(tty), ldata->process_char_map); 1513 set_bit(STOP_CHAR(tty), tty->process_char_map);
1571 } 1514 }
1572 if (L_ISIG(tty)) { 1515 if (L_ISIG(tty)) {
1573 set_bit(INTR_CHAR(tty), ldata->process_char_map); 1516 set_bit(INTR_CHAR(tty), tty->process_char_map);
1574 set_bit(QUIT_CHAR(tty), ldata->process_char_map); 1517 set_bit(QUIT_CHAR(tty), tty->process_char_map);
1575 set_bit(SUSP_CHAR(tty), ldata->process_char_map); 1518 set_bit(SUSP_CHAR(tty), tty->process_char_map);
1576 } 1519 }
1577 clear_bit(__DISABLED_CHAR, ldata->process_char_map); 1520 clear_bit(__DISABLED_CHAR, tty->process_char_map);
1578 ldata->raw = 0; 1521 tty->raw = 0;
1579 ldata->real_raw = 0; 1522 tty->real_raw = 0;
1580 } else { 1523 } else {
1581 ldata->raw = 1; 1524 tty->raw = 1;
1582 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && 1525 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) &&
1583 (I_IGNPAR(tty) || !I_INPCK(tty)) && 1526 (I_IGNPAR(tty) || !I_INPCK(tty)) &&
1584 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) 1527 (tty->driver->flags & TTY_DRIVER_REAL_RAW))
1585 ldata->real_raw = 1; 1528 tty->real_raw = 1;
1586 else 1529 else
1587 ldata->real_raw = 0; 1530 tty->real_raw = 0;
1588 } 1531 }
1589 n_tty_set_room(tty); 1532 n_tty_set_room(tty);
1590 /* The termios change make the tty ready for I/O */ 1533 /* The termios change make the tty ready for I/O */
@@ -1604,13 +1547,15 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1604 1547
1605static void n_tty_close(struct tty_struct *tty) 1548static void n_tty_close(struct tty_struct *tty)
1606{ 1549{
1607 struct n_tty_data *ldata = tty->disc_data;
1608
1609 n_tty_flush_buffer(tty); 1550 n_tty_flush_buffer(tty);
1610 kfree(ldata->read_buf); 1551 if (tty->read_buf) {
1611 kfree(ldata->echo_buf); 1552 kfree(tty->read_buf);
1612 kfree(ldata); 1553 tty->read_buf = NULL;
1613 tty->disc_data = NULL; 1554 }
1555 if (tty->echo_buf) {
1556 kfree(tty->echo_buf);
1557 tty->echo_buf = NULL;
1558 }
1614} 1559}
1615 1560
1616/** 1561/**
@@ -1625,57 +1570,44 @@ static void n_tty_close(struct tty_struct *tty)
1625 1570
1626static int n_tty_open(struct tty_struct *tty) 1571static int n_tty_open(struct tty_struct *tty)
1627{ 1572{
1628 struct n_tty_data *ldata; 1573 if (!tty)
1629 1574 return -EINVAL;
1630 ldata = kzalloc(sizeof(*ldata), GFP_KERNEL);
1631 if (!ldata)
1632 goto err;
1633
1634 ldata->overrun_time = jiffies;
1635 mutex_init(&ldata->atomic_read_lock);
1636 mutex_init(&ldata->output_lock);
1637 mutex_init(&ldata->echo_lock);
1638 spin_lock_init(&ldata->read_lock);
1639 1575
1640 /* These are ugly. Currently a malloc failure here can panic */ 1576 /* These are ugly. Currently a malloc failure here can panic */
1641 ldata->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL); 1577 if (!tty->read_buf) {
1642 ldata->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL); 1578 tty->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1643 if (!ldata->read_buf || !ldata->echo_buf) 1579 if (!tty->read_buf)
1644 goto err_free_bufs; 1580 return -ENOMEM;
1581 }
1582 if (!tty->echo_buf) {
1583 tty->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1645 1584
1646 tty->disc_data = ldata; 1585 if (!tty->echo_buf)
1586 return -ENOMEM;
1587 }
1647 reset_buffer_flags(tty); 1588 reset_buffer_flags(tty);
1648 tty_unthrottle(tty); 1589 tty_unthrottle(tty);
1649 ldata->column = 0; 1590 tty->column = 0;
1650 n_tty_set_termios(tty, NULL); 1591 n_tty_set_termios(tty, NULL);
1651 tty->minimum_to_wake = 1; 1592 tty->minimum_to_wake = 1;
1652 tty->closing = 0; 1593 tty->closing = 0;
1653
1654 return 0; 1594 return 0;
1655err_free_bufs:
1656 kfree(ldata->read_buf);
1657 kfree(ldata->echo_buf);
1658 kfree(ldata);
1659err:
1660 return -ENOMEM;
1661} 1595}
1662 1596
1663static inline int input_available_p(struct tty_struct *tty, int amt) 1597static inline int input_available_p(struct tty_struct *tty, int amt)
1664{ 1598{
1665 struct n_tty_data *ldata = tty->disc_data;
1666
1667 tty_flush_to_ldisc(tty); 1599 tty_flush_to_ldisc(tty);
1668 if (ldata->icanon && !L_EXTPROC(tty)) { 1600 if (tty->icanon && !L_EXTPROC(tty)) {
1669 if (ldata->canon_data) 1601 if (tty->canon_data)
1670 return 1; 1602 return 1;
1671 } else if (ldata->read_cnt >= (amt ? amt : 1)) 1603 } else if (tty->read_cnt >= (amt ? amt : 1))
1672 return 1; 1604 return 1;
1673 1605
1674 return 0; 1606 return 0;
1675} 1607}
1676 1608
1677/** 1609/**
1678 * copy_from_read_buf - copy read data directly 1610 * copy_from_read_buf - copy read data directly
1679 * @tty: terminal device 1611 * @tty: terminal device
1680 * @b: user data 1612 * @b: user data
1681 * @nr: size of data 1613 * @nr: size of data
@@ -1687,7 +1619,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt)
1687 * buffer, and once to drain the space from the (physical) beginning of 1619 * buffer, and once to drain the space from the (physical) beginning of
1688 * the buffer to head pointer. 1620 * the buffer to head pointer.
1689 * 1621 *
1690 * Called under the ldata->atomic_read_lock sem 1622 * Called under the tty->atomic_read_lock sem
1691 * 1623 *
1692 */ 1624 */
1693 1625
@@ -1696,31 +1628,28 @@ static int copy_from_read_buf(struct tty_struct *tty,
1696 size_t *nr) 1628 size_t *nr)
1697 1629
1698{ 1630{
1699 struct n_tty_data *ldata = tty->disc_data;
1700 int retval; 1631 int retval;
1701 size_t n; 1632 size_t n;
1702 unsigned long flags; 1633 unsigned long flags;
1703 bool is_eof;
1704 1634
1705 retval = 0; 1635 retval = 0;
1706 spin_lock_irqsave(&ldata->read_lock, flags); 1636 spin_lock_irqsave(&tty->read_lock, flags);
1707 n = min(ldata->read_cnt, N_TTY_BUF_SIZE - ldata->read_tail); 1637 n = min(tty->read_cnt, N_TTY_BUF_SIZE - tty->read_tail);
1708 n = min(*nr, n); 1638 n = min(*nr, n);
1709 spin_unlock_irqrestore(&ldata->read_lock, flags); 1639 spin_unlock_irqrestore(&tty->read_lock, flags);
1710 if (n) { 1640 if (n) {
1711 retval = copy_to_user(*b, &ldata->read_buf[ldata->read_tail], n); 1641 retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n);
1712 n -= retval; 1642 n -= retval;
1713 is_eof = n == 1 && 1643 tty_audit_add_data(tty, &tty->read_buf[tty->read_tail], n);
1714 ldata->read_buf[ldata->read_tail] == EOF_CHAR(tty); 1644 spin_lock_irqsave(&tty->read_lock, flags);
1715 tty_audit_add_data(tty, &ldata->read_buf[ldata->read_tail], n, 1645 tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1);
1716 ldata->icanon); 1646 tty->read_cnt -= n;
1717 spin_lock_irqsave(&ldata->read_lock, flags);
1718 ldata->read_tail = (ldata->read_tail + n) & (N_TTY_BUF_SIZE-1);
1719 ldata->read_cnt -= n;
1720 /* Turn single EOF into zero-length read */ 1647 /* Turn single EOF into zero-length read */
1721 if (L_EXTPROC(tty) && ldata->icanon && is_eof && !ldata->read_cnt) 1648 if (L_EXTPROC(tty) && tty->icanon && n == 1) {
1722 n = 0; 1649 if (!tty->read_cnt && (*b)[n-1] == EOF_CHAR(tty))
1723 spin_unlock_irqrestore(&ldata->read_lock, flags); 1650 n--;
1651 }
1652 spin_unlock_irqrestore(&tty->read_lock, flags);
1724 *b += n; 1653 *b += n;
1725 *nr -= n; 1654 *nr -= n;
1726 } 1655 }
@@ -1787,7 +1716,6 @@ static int job_control(struct tty_struct *tty, struct file *file)
1787static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, 1716static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
1788 unsigned char __user *buf, size_t nr) 1717 unsigned char __user *buf, size_t nr)
1789{ 1718{
1790 struct n_tty_data *ldata = tty->disc_data;
1791 unsigned char __user *b = buf; 1719 unsigned char __user *b = buf;
1792 DECLARE_WAITQUEUE(wait, current); 1720 DECLARE_WAITQUEUE(wait, current);
1793 int c; 1721 int c;
@@ -1799,13 +1727,16 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
1799 int packet; 1727 int packet;
1800 1728
1801do_it_again: 1729do_it_again:
1730
1731 BUG_ON(!tty->read_buf);
1732
1802 c = job_control(tty, file); 1733 c = job_control(tty, file);
1803 if (c < 0) 1734 if (c < 0)
1804 return c; 1735 return c;
1805 1736
1806 minimum = time = 0; 1737 minimum = time = 0;
1807 timeout = MAX_SCHEDULE_TIMEOUT; 1738 timeout = MAX_SCHEDULE_TIMEOUT;
1808 if (!ldata->icanon) { 1739 if (!tty->icanon) {
1809 time = (HZ / 10) * TIME_CHAR(tty); 1740 time = (HZ / 10) * TIME_CHAR(tty);
1810 minimum = MIN_CHAR(tty); 1741 minimum = MIN_CHAR(tty);
1811 if (minimum) { 1742 if (minimum) {
@@ -1828,10 +1759,10 @@ do_it_again:
1828 * Internal serialization of reads. 1759 * Internal serialization of reads.
1829 */ 1760 */
1830 if (file->f_flags & O_NONBLOCK) { 1761 if (file->f_flags & O_NONBLOCK) {
1831 if (!mutex_trylock(&ldata->atomic_read_lock)) 1762 if (!mutex_trylock(&tty->atomic_read_lock))
1832 return -EAGAIN; 1763 return -EAGAIN;
1833 } else { 1764 } else {
1834 if (mutex_lock_interruptible(&ldata->atomic_read_lock)) 1765 if (mutex_lock_interruptible(&tty->atomic_read_lock))
1835 return -ERESTARTSYS; 1766 return -ERESTARTSYS;
1836 } 1767 }
1837 packet = tty->packet; 1768 packet = tty->packet;
@@ -1884,6 +1815,7 @@ do_it_again:
1884 /* FIXME: does n_tty_set_room need locking ? */ 1815 /* FIXME: does n_tty_set_room need locking ? */
1885 n_tty_set_room(tty); 1816 n_tty_set_room(tty);
1886 timeout = schedule_timeout(timeout); 1817 timeout = schedule_timeout(timeout);
1818 BUG_ON(!tty->read_buf);
1887 continue; 1819 continue;
1888 } 1820 }
1889 __set_current_state(TASK_RUNNING); 1821 __set_current_state(TASK_RUNNING);
@@ -1898,45 +1830,41 @@ do_it_again:
1898 nr--; 1830 nr--;
1899 } 1831 }
1900 1832
1901 if (ldata->icanon && !L_EXTPROC(tty)) { 1833 if (tty->icanon && !L_EXTPROC(tty)) {
1902 /* N.B. avoid overrun if nr == 0 */ 1834 /* N.B. avoid overrun if nr == 0 */
1903 spin_lock_irqsave(&ldata->read_lock, flags); 1835 while (nr && tty->read_cnt) {
1904 while (nr && ldata->read_cnt) {
1905 int eol; 1836 int eol;
1906 1837
1907 eol = test_and_clear_bit(ldata->read_tail, 1838 eol = test_and_clear_bit(tty->read_tail,
1908 ldata->read_flags); 1839 tty->read_flags);
1909 c = ldata->read_buf[ldata->read_tail]; 1840 c = tty->read_buf[tty->read_tail];
1910 ldata->read_tail = ((ldata->read_tail+1) & 1841 spin_lock_irqsave(&tty->read_lock, flags);
1842 tty->read_tail = ((tty->read_tail+1) &
1911 (N_TTY_BUF_SIZE-1)); 1843 (N_TTY_BUF_SIZE-1));
1912 ldata->read_cnt--; 1844 tty->read_cnt--;
1913 if (eol) { 1845 if (eol) {
1914 /* this test should be redundant: 1846 /* this test should be redundant:
1915 * we shouldn't be reading data if 1847 * we shouldn't be reading data if
1916 * canon_data is 0 1848 * canon_data is 0
1917 */ 1849 */
1918 if (--ldata->canon_data < 0) 1850 if (--tty->canon_data < 0)
1919 ldata->canon_data = 0; 1851 tty->canon_data = 0;
1920 } 1852 }
1921 spin_unlock_irqrestore(&ldata->read_lock, flags); 1853 spin_unlock_irqrestore(&tty->read_lock, flags);
1922 1854
1923 if (!eol || (c != __DISABLED_CHAR)) { 1855 if (!eol || (c != __DISABLED_CHAR)) {
1924 if (tty_put_user(tty, c, b++)) { 1856 if (tty_put_user(tty, c, b++)) {
1925 retval = -EFAULT; 1857 retval = -EFAULT;
1926 b--; 1858 b--;
1927 spin_lock_irqsave(&ldata->read_lock, flags);
1928 break; 1859 break;
1929 } 1860 }
1930 nr--; 1861 nr--;
1931 } 1862 }
1932 if (eol) { 1863 if (eol) {
1933 tty_audit_push(tty); 1864 tty_audit_push(tty);
1934 spin_lock_irqsave(&ldata->read_lock, flags);
1935 break; 1865 break;
1936 } 1866 }
1937 spin_lock_irqsave(&ldata->read_lock, flags);
1938 } 1867 }
1939 spin_unlock_irqrestore(&ldata->read_lock, flags);
1940 if (retval) 1868 if (retval)
1941 break; 1869 break;
1942 } else { 1870 } else {
@@ -1968,7 +1896,7 @@ do_it_again:
1968 if (time) 1896 if (time)
1969 timeout = time; 1897 timeout = time;
1970 } 1898 }
1971 mutex_unlock(&ldata->atomic_read_lock); 1899 mutex_unlock(&tty->atomic_read_lock);
1972 remove_wait_queue(&tty->read_wait, &wait); 1900 remove_wait_queue(&tty->read_wait, &wait);
1973 1901
1974 if (!waitqueue_active(&tty->read_wait)) 1902 if (!waitqueue_active(&tty->read_wait))
@@ -1981,7 +1909,7 @@ do_it_again:
1981 if (nr) 1909 if (nr)
1982 clear_bit(TTY_PUSH, &tty->flags); 1910 clear_bit(TTY_PUSH, &tty->flags);
1983 } else if (test_and_clear_bit(TTY_PUSH, &tty->flags)) 1911 } else if (test_and_clear_bit(TTY_PUSH, &tty->flags))
1984 goto do_it_again; 1912 goto do_it_again;
1985 1913
1986 n_tty_set_room(tty); 1914 n_tty_set_room(tty);
1987 return retval; 1915 return retval;
@@ -2129,19 +2057,19 @@ static unsigned int n_tty_poll(struct tty_struct *tty, struct file *file,
2129 return mask; 2057 return mask;
2130} 2058}
2131 2059
2132static unsigned long inq_canon(struct n_tty_data *ldata) 2060static unsigned long inq_canon(struct tty_struct *tty)
2133{ 2061{
2134 int nr, head, tail; 2062 int nr, head, tail;
2135 2063
2136 if (!ldata->canon_data) 2064 if (!tty->canon_data)
2137 return 0; 2065 return 0;
2138 head = ldata->canon_head; 2066 head = tty->canon_head;
2139 tail = ldata->read_tail; 2067 tail = tty->read_tail;
2140 nr = (head - tail) & (N_TTY_BUF_SIZE-1); 2068 nr = (head - tail) & (N_TTY_BUF_SIZE-1);
2141 /* Skip EOF-chars.. */ 2069 /* Skip EOF-chars.. */
2142 while (head != tail) { 2070 while (head != tail) {
2143 if (test_bit(tail, ldata->read_flags) && 2071 if (test_bit(tail, tty->read_flags) &&
2144 ldata->read_buf[tail] == __DISABLED_CHAR) 2072 tty->read_buf[tail] == __DISABLED_CHAR)
2145 nr--; 2073 nr--;
2146 tail = (tail+1) & (N_TTY_BUF_SIZE-1); 2074 tail = (tail+1) & (N_TTY_BUF_SIZE-1);
2147 } 2075 }
@@ -2151,7 +2079,6 @@ static unsigned long inq_canon(struct n_tty_data *ldata)
2151static int n_tty_ioctl(struct tty_struct *tty, struct file *file, 2079static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
2152 unsigned int cmd, unsigned long arg) 2080 unsigned int cmd, unsigned long arg)
2153{ 2081{
2154 struct n_tty_data *ldata = tty->disc_data;
2155 int retval; 2082 int retval;
2156 2083
2157 switch (cmd) { 2084 switch (cmd) {
@@ -2159,9 +2086,9 @@ static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
2159 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); 2086 return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
2160 case TIOCINQ: 2087 case TIOCINQ:
2161 /* FIXME: Locking */ 2088 /* FIXME: Locking */
2162 retval = ldata->read_cnt; 2089 retval = tty->read_cnt;
2163 if (L_ICANON(tty)) 2090 if (L_ICANON(tty))
2164 retval = inq_canon(ldata); 2091 retval = inq_canon(tty);
2165 return put_user(retval, (unsigned int __user *) arg); 2092 return put_user(retval, (unsigned int __user *) arg);
2166 default: 2093 default:
2167 return n_tty_ioctl_helper(tty, file, cmd, arg); 2094 return n_tty_ioctl_helper(tty, file, cmd, arg);
diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index a0c69ab0439..fd347ff34d0 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -400,7 +400,7 @@ struct buffer {
400} __attribute__ ((packed)); 400} __attribute__ ((packed));
401 401
402/* Global variables */ 402/* Global variables */
403static const struct pci_device_id nozomi_pci_tbl[] = { 403static const struct pci_device_id nozomi_pci_tbl[] __devinitconst = {
404 {PCI_DEVICE(0x1931, 0x000c)}, /* Nozomi HSDPA */ 404 {PCI_DEVICE(0x1931, 0x000c)}, /* Nozomi HSDPA */
405 {}, 405 {},
406}; 406};
@@ -1360,7 +1360,7 @@ static void remove_sysfs_files(struct nozomi *dc)
1360} 1360}
1361 1361
1362/* Allocate memory for one device */ 1362/* Allocate memory for one device */
1363static int nozomi_card_init(struct pci_dev *pdev, 1363static int __devinit nozomi_card_init(struct pci_dev *pdev,
1364 const struct pci_device_id *ent) 1364 const struct pci_device_id *ent)
1365{ 1365{
1366 resource_size_t start; 1366 resource_size_t start;
@@ -1473,13 +1473,12 @@ static int nozomi_card_init(struct pci_dev *pdev,
1473 port->dc = dc; 1473 port->dc = dc;
1474 tty_port_init(&port->port); 1474 tty_port_init(&port->port);
1475 port->port.ops = &noz_tty_port_ops; 1475 port->port.ops = &noz_tty_port_ops;
1476 tty_dev = tty_port_register_device(&port->port, ntty_driver, 1476 tty_dev = tty_register_device(ntty_driver, dc->index_start + i,
1477 dc->index_start + i, &pdev->dev); 1477 &pdev->dev);
1478 1478
1479 if (IS_ERR(tty_dev)) { 1479 if (IS_ERR(tty_dev)) {
1480 ret = PTR_ERR(tty_dev); 1480 ret = PTR_ERR(tty_dev);
1481 dev_err(&pdev->dev, "Could not allocate tty?\n"); 1481 dev_err(&pdev->dev, "Could not allocate tty?\n");
1482 tty_port_destroy(&port->port);
1483 goto err_free_tty; 1482 goto err_free_tty;
1484 } 1483 }
1485 } 1484 }
@@ -1487,10 +1486,8 @@ static int nozomi_card_init(struct pci_dev *pdev,
1487 return 0; 1486 return 0;
1488 1487
1489err_free_tty: 1488err_free_tty:
1490 for (i = 0; i < MAX_PORT; ++i) { 1489 for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i)
1491 tty_unregister_device(ntty_driver, dc->index_start + i); 1490 tty_unregister_device(ntty_driver, i);
1492 tty_port_destroy(&dc->port[i].port);
1493 }
1494err_free_kfifo: 1491err_free_kfifo:
1495 for (i = 0; i < MAX_PORT; i++) 1492 for (i = 0; i < MAX_PORT; i++)
1496 kfifo_free(&dc->port[i].fifo_ul); 1493 kfifo_free(&dc->port[i].fifo_ul);
@@ -1507,7 +1504,7 @@ err:
1507 return ret; 1504 return ret;
1508} 1505}
1509 1506
1510static void tty_exit(struct nozomi *dc) 1507static void __devexit tty_exit(struct nozomi *dc)
1511{ 1508{
1512 unsigned int i; 1509 unsigned int i;
1513 1510
@@ -1523,14 +1520,12 @@ static void tty_exit(struct nozomi *dc)
1523 complete off a hangup method ? */ 1520 complete off a hangup method ? */
1524 while (dc->open_ttys) 1521 while (dc->open_ttys)
1525 msleep(1); 1522 msleep(1);
1526 for (i = 0; i < MAX_PORT; ++i) { 1523 for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i)
1527 tty_unregister_device(ntty_driver, dc->index_start + i); 1524 tty_unregister_device(ntty_driver, i);
1528 tty_port_destroy(&dc->port[i].port);
1529 }
1530} 1525}
1531 1526
1532/* Deallocate memory for one device */ 1527/* Deallocate memory for one device */
1533static void nozomi_card_exit(struct pci_dev *pdev) 1528static void __devexit nozomi_card_exit(struct pci_dev *pdev)
1534{ 1529{
1535 int i; 1530 int i;
1536 struct ctrl_ul ctrl; 1531 struct ctrl_ul ctrl;
@@ -1607,9 +1602,13 @@ static int ntty_install(struct tty_driver *driver, struct tty_struct *tty)
1607 int ret; 1602 int ret;
1608 if (!port || !dc || dc->state != NOZOMI_STATE_READY) 1603 if (!port || !dc || dc->state != NOZOMI_STATE_READY)
1609 return -ENODEV; 1604 return -ENODEV;
1610 ret = tty_standard_install(driver, tty); 1605 ret = tty_init_termios(tty);
1611 if (ret == 0) 1606 if (ret == 0) {
1607 tty_driver_kref_get(driver);
1608 tty->count++;
1612 tty->driver_data = port; 1609 tty->driver_data = port;
1610 driver->ttys[tty->index] = tty;
1611 }
1613 return ret; 1612 return ret;
1614} 1613}
1615 1614
@@ -1908,7 +1907,7 @@ static struct pci_driver nozomi_driver = {
1908 .name = NOZOMI_NAME, 1907 .name = NOZOMI_NAME,
1909 .id_table = nozomi_pci_tbl, 1908 .id_table = nozomi_pci_tbl,
1910 .probe = nozomi_card_init, 1909 .probe = nozomi_card_init,
1911 .remove = nozomi_card_exit, 1910 .remove = __devexit_p(nozomi_card_exit),
1912}; 1911};
1913 1912
1914static __init int nozomi_init(void) 1913static __init int nozomi_init(void)
@@ -1921,6 +1920,7 @@ static __init int nozomi_init(void)
1921 if (!ntty_driver) 1920 if (!ntty_driver)
1922 return -ENOMEM; 1921 return -ENOMEM;
1923 1922
1923 ntty_driver->owner = THIS_MODULE;
1924 ntty_driver->driver_name = NOZOMI_NAME_TTY; 1924 ntty_driver->driver_name = NOZOMI_NAME_TTY;
1925 ntty_driver->name = "noz"; 1925 ntty_driver->name = "noz";
1926 ntty_driver->major = 0; 1926 ntty_driver->major = 0;
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index be6a373601b..e18604b3fc7 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -4,6 +4,9 @@
4 * Added support for a Unix98-style ptmx device. 4 * Added support for a Unix98-style ptmx device.
5 * -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998 5 * -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998
6 * 6 *
7 * When reading this code see also fs/devpts. In particular note that the
8 * driver_data field is used by the devpts side as a binding to the devpts
9 * inode.
7 */ 10 */
8 11
9#include <linux/module.h> 12#include <linux/module.h>
@@ -18,18 +21,18 @@
18#include <linux/major.h> 21#include <linux/major.h>
19#include <linux/mm.h> 22#include <linux/mm.h>
20#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/sysctl.h>
21#include <linux/device.h> 25#include <linux/device.h>
22#include <linux/uaccess.h> 26#include <linux/uaccess.h>
23#include <linux/bitops.h> 27#include <linux/bitops.h>
24#include <linux/devpts_fs.h> 28#include <linux/devpts_fs.h>
25#include <linux/slab.h> 29#include <linux/slab.h>
26#include <linux/mutex.h>
27 30
31#include <asm/system.h>
28 32
29#ifdef CONFIG_UNIX98_PTYS 33#ifdef CONFIG_UNIX98_PTYS
30static struct tty_driver *ptm_driver; 34static struct tty_driver *ptm_driver;
31static struct tty_driver *pts_driver; 35static struct tty_driver *pts_driver;
32static DEFINE_MUTEX(devpts_mutex);
33#endif 36#endif
34 37
35static void pty_close(struct tty_struct *tty, struct file *filp) 38static void pty_close(struct tty_struct *tty, struct file *filp)
@@ -44,7 +47,6 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
44 wake_up_interruptible(&tty->read_wait); 47 wake_up_interruptible(&tty->read_wait);
45 wake_up_interruptible(&tty->write_wait); 48 wake_up_interruptible(&tty->write_wait);
46 tty->packet = 0; 49 tty->packet = 0;
47 /* Review - krefs on tty_link ?? */
48 if (!tty->link) 50 if (!tty->link)
49 return; 51 return;
50 tty->link->packet = 0; 52 tty->link->packet = 0;
@@ -54,15 +56,12 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
54 if (tty->driver->subtype == PTY_TYPE_MASTER) { 56 if (tty->driver->subtype == PTY_TYPE_MASTER) {
55 set_bit(TTY_OTHER_CLOSED, &tty->flags); 57 set_bit(TTY_OTHER_CLOSED, &tty->flags);
56#ifdef CONFIG_UNIX98_PTYS 58#ifdef CONFIG_UNIX98_PTYS
57 if (tty->driver == ptm_driver) { 59 if (tty->driver == ptm_driver)
58 mutex_lock(&devpts_mutex); 60 devpts_pty_kill(tty->link);
59 devpts_pty_kill(tty->link->driver_data);
60 mutex_unlock(&devpts_mutex);
61 }
62#endif 61#endif
63 tty_unlock(tty); 62 tty_unlock();
64 tty_vhangup(tty->link); 63 tty_vhangup(tty->link);
65 tty_lock(tty); 64 tty_lock();
66 } 65 }
67} 66}
68 67
@@ -93,7 +92,7 @@ static void pty_unthrottle(struct tty_struct *tty)
93 92
94static int pty_space(struct tty_struct *to) 93static int pty_space(struct tty_struct *to)
95{ 94{
96 int n = 8192 - to->port->buf.memory_used; 95 int n = 8192 - to->buf.memory_used;
97 if (n < 0) 96 if (n < 0)
98 return 0; 97 return 0;
99 return n; 98 return n;
@@ -171,41 +170,6 @@ static int pty_set_lock(struct tty_struct *tty, int __user *arg)
171 return 0; 170 return 0;
172} 171}
173 172
174static int pty_get_lock(struct tty_struct *tty, int __user *arg)
175{
176 int locked = test_bit(TTY_PTY_LOCK, &tty->flags);
177 return put_user(locked, arg);
178}
179
180/* Set the packet mode on a pty */
181static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
182{
183 unsigned long flags;
184 int pktmode;
185
186 if (get_user(pktmode, arg))
187 return -EFAULT;
188
189 spin_lock_irqsave(&tty->ctrl_lock, flags);
190 if (pktmode) {
191 if (!tty->packet) {
192 tty->packet = 1;
193 tty->link->ctrl_status = 0;
194 }
195 } else
196 tty->packet = 0;
197 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
198
199 return 0;
200}
201
202/* Get the packet mode of a pty */
203static int pty_get_pktmode(struct tty_struct *tty, int __user *arg)
204{
205 int pktmode = tty->packet;
206 return put_user(pktmode, arg);
207}
208
209/* Send a signal to the slave */ 173/* Send a signal to the slave */
210static int pty_signal(struct tty_struct *tty, int sig) 174static int pty_signal(struct tty_struct *tty, int sig)
211{ 175{
@@ -264,8 +228,8 @@ out:
264static void pty_set_termios(struct tty_struct *tty, 228static void pty_set_termios(struct tty_struct *tty,
265 struct ktermios *old_termios) 229 struct ktermios *old_termios)
266{ 230{
267 tty->termios.c_cflag &= ~(CSIZE | PARENB); 231 tty->termios->c_cflag &= ~(CSIZE | PARENB);
268 tty->termios.c_cflag |= (CS8 | CREAD); 232 tty->termios->c_cflag |= (CS8 | CREAD);
269} 233}
270 234
271/** 235/**
@@ -277,7 +241,7 @@ static void pty_set_termios(struct tty_struct *tty,
277 * peform a terminal resize correctly 241 * peform a terminal resize correctly
278 */ 242 */
279 243
280static int pty_resize(struct tty_struct *tty, struct winsize *ws) 244int pty_resize(struct tty_struct *tty, struct winsize *ws)
281{ 245{
282 struct pid *pgrp, *rpgrp; 246 struct pid *pgrp, *rpgrp;
283 unsigned long flags; 247 unsigned long flags;
@@ -315,130 +279,66 @@ done:
315 return 0; 279 return 0;
316} 280}
317 281
318/** 282/* Traditional BSD devices */
319 * pty_common_install - set up the pty pair 283#ifdef CONFIG_LEGACY_PTYS
320 * @driver: the pty driver 284
321 * @tty: the tty being instantiated 285static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
322 * @bool: legacy, true if this is BSD style
323 *
324 * Perform the initial set up for the tty/pty pair. Called from the
325 * tty layer when the port is first opened.
326 *
327 * Locking: the caller must hold the tty_mutex
328 */
329static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
330 bool legacy)
331{ 286{
332 struct tty_struct *o_tty; 287 struct tty_struct *o_tty;
333 struct tty_port *ports[2];
334 int idx = tty->index; 288 int idx = tty->index;
335 int retval = -ENOMEM; 289 int retval;
336 290
337 o_tty = alloc_tty_struct(); 291 o_tty = alloc_tty_struct();
338 if (!o_tty) 292 if (!o_tty)
339 goto err; 293 return -ENOMEM;
340 ports[0] = kmalloc(sizeof **ports, GFP_KERNEL);
341 ports[1] = kmalloc(sizeof **ports, GFP_KERNEL);
342 if (!ports[0] || !ports[1])
343 goto err_free_tty;
344 if (!try_module_get(driver->other->owner)) { 294 if (!try_module_get(driver->other->owner)) {
345 /* This cannot in fact currently happen */ 295 /* This cannot in fact currently happen */
296 retval = -ENOMEM;
346 goto err_free_tty; 297 goto err_free_tty;
347 } 298 }
348 initialize_tty_struct(o_tty, driver->other, idx); 299 initialize_tty_struct(o_tty, driver->other, idx);
349 300
350 if (legacy) { 301 /* We always use new tty termios data so we can do this
351 /* We always use new tty termios data so we can do this 302 the easy way .. */
352 the easy way .. */ 303 retval = tty_init_termios(tty);
353 retval = tty_init_termios(tty); 304 if (retval)
354 if (retval) 305 goto err_deinit_tty;
355 goto err_deinit_tty; 306
356 307 retval = tty_init_termios(o_tty);
357 retval = tty_init_termios(o_tty); 308 if (retval)
358 if (retval) 309 goto err_free_termios;
359 goto err_free_termios;
360
361 driver->other->ttys[idx] = o_tty;
362 driver->ttys[idx] = tty;
363 } else {
364 memset(&tty->termios_locked, 0, sizeof(tty->termios_locked));
365 tty->termios = driver->init_termios;
366 memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked));
367 o_tty->termios = driver->other->init_termios;
368 }
369 310
370 /* 311 /*
371 * Everything allocated ... set up the o_tty structure. 312 * Everything allocated ... set up the o_tty structure.
372 */ 313 */
314 driver->other->ttys[idx] = o_tty;
373 tty_driver_kref_get(driver->other); 315 tty_driver_kref_get(driver->other);
374 if (driver->subtype == PTY_TYPE_MASTER) 316 if (driver->subtype == PTY_TYPE_MASTER)
375 o_tty->count++; 317 o_tty->count++;
376 /* Establish the links in both directions */ 318 /* Establish the links in both directions */
377 tty->link = o_tty; 319 tty->link = o_tty;
378 o_tty->link = tty; 320 o_tty->link = tty;
379 tty_port_init(ports[0]);
380 tty_port_init(ports[1]);
381 o_tty->port = ports[0];
382 tty->port = ports[1];
383 o_tty->port->itty = o_tty;
384 321
385 tty_driver_kref_get(driver); 322 tty_driver_kref_get(driver);
386 tty->count++; 323 tty->count++;
324 driver->ttys[idx] = tty;
387 return 0; 325 return 0;
388err_free_termios: 326err_free_termios:
389 if (legacy) 327 tty_free_termios(tty);
390 tty_free_termios(tty);
391err_deinit_tty: 328err_deinit_tty:
392 deinitialize_tty_struct(o_tty); 329 deinitialize_tty_struct(o_tty);
393 module_put(o_tty->driver->owner); 330 module_put(o_tty->driver->owner);
394err_free_tty: 331err_free_tty:
395 kfree(ports[0]);
396 kfree(ports[1]);
397 free_tty_struct(o_tty); 332 free_tty_struct(o_tty);
398err:
399 return retval; 333 return retval;
400} 334}
401 335
402/* this is called once with whichever end is closed last */
403static void pty_unix98_shutdown(struct tty_struct *tty)
404{
405 devpts_kill_index(tty->driver_data, tty->index);
406}
407
408static void pty_cleanup(struct tty_struct *tty)
409{
410 tty->port->itty = NULL;
411 tty_port_put(tty->port);
412}
413
414/* Traditional BSD devices */
415#ifdef CONFIG_LEGACY_PTYS
416
417static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
418{
419 return pty_common_install(driver, tty, true);
420}
421
422static void pty_remove(struct tty_driver *driver, struct tty_struct *tty)
423{
424 struct tty_struct *pair = tty->link;
425 driver->ttys[tty->index] = NULL;
426 if (pair)
427 pair->driver->ttys[pair->index] = NULL;
428}
429
430static int pty_bsd_ioctl(struct tty_struct *tty, 336static int pty_bsd_ioctl(struct tty_struct *tty,
431 unsigned int cmd, unsigned long arg) 337 unsigned int cmd, unsigned long arg)
432{ 338{
433 switch (cmd) { 339 switch (cmd) {
434 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */ 340 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
435 return pty_set_lock(tty, (int __user *) arg); 341 return pty_set_lock(tty, (int __user *) arg);
436 case TIOCGPTLCK: /* Get PT Lock status */
437 return pty_get_lock(tty, (int __user *)arg);
438 case TIOCPKT: /* Set PT packet mode */
439 return pty_set_pktmode(tty, (int __user *)arg);
440 case TIOCGPKT: /* Get PT packet mode */
441 return pty_get_pktmode(tty, (int __user *)arg);
442 case TIOCSIG: /* Send signal to other side of pty */ 342 case TIOCSIG: /* Send signal to other side of pty */
443 return pty_signal(tty, (int) arg); 343 return pty_signal(tty, (int) arg);
444 } 344 }
@@ -463,9 +363,7 @@ static const struct tty_operations master_pty_ops_bsd = {
463 .unthrottle = pty_unthrottle, 363 .unthrottle = pty_unthrottle,
464 .set_termios = pty_set_termios, 364 .set_termios = pty_set_termios,
465 .ioctl = pty_bsd_ioctl, 365 .ioctl = pty_bsd_ioctl,
466 .cleanup = pty_cleanup, 366 .resize = pty_resize
467 .resize = pty_resize,
468 .remove = pty_remove
469}; 367};
470 368
471static const struct tty_operations slave_pty_ops_bsd = { 369static const struct tty_operations slave_pty_ops_bsd = {
@@ -478,9 +376,7 @@ static const struct tty_operations slave_pty_ops_bsd = {
478 .chars_in_buffer = pty_chars_in_buffer, 376 .chars_in_buffer = pty_chars_in_buffer,
479 .unthrottle = pty_unthrottle, 377 .unthrottle = pty_unthrottle,
480 .set_termios = pty_set_termios, 378 .set_termios = pty_set_termios,
481 .cleanup = pty_cleanup, 379 .resize = pty_resize
482 .resize = pty_resize,
483 .remove = pty_remove
484}; 380};
485 381
486static void __init legacy_pty_init(void) 382static void __init legacy_pty_init(void)
@@ -490,20 +386,15 @@ static void __init legacy_pty_init(void)
490 if (legacy_count <= 0) 386 if (legacy_count <= 0)
491 return; 387 return;
492 388
493 pty_driver = tty_alloc_driver(legacy_count, 389 pty_driver = alloc_tty_driver(legacy_count);
494 TTY_DRIVER_RESET_TERMIOS | 390 if (!pty_driver)
495 TTY_DRIVER_REAL_RAW |
496 TTY_DRIVER_DYNAMIC_ALLOC);
497 if (IS_ERR(pty_driver))
498 panic("Couldn't allocate pty driver"); 391 panic("Couldn't allocate pty driver");
499 392
500 pty_slave_driver = tty_alloc_driver(legacy_count, 393 pty_slave_driver = alloc_tty_driver(legacy_count);
501 TTY_DRIVER_RESET_TERMIOS | 394 if (!pty_slave_driver)
502 TTY_DRIVER_REAL_RAW |
503 TTY_DRIVER_DYNAMIC_ALLOC);
504 if (IS_ERR(pty_slave_driver))
505 panic("Couldn't allocate pty slave driver"); 395 panic("Couldn't allocate pty slave driver");
506 396
397 pty_driver->owner = THIS_MODULE;
507 pty_driver->driver_name = "pty_master"; 398 pty_driver->driver_name = "pty_master";
508 pty_driver->name = "pty"; 399 pty_driver->name = "pty";
509 pty_driver->major = PTY_MASTER_MAJOR; 400 pty_driver->major = PTY_MASTER_MAJOR;
@@ -517,9 +408,11 @@ static void __init legacy_pty_init(void)
517 pty_driver->init_termios.c_lflag = 0; 408 pty_driver->init_termios.c_lflag = 0;
518 pty_driver->init_termios.c_ispeed = 38400; 409 pty_driver->init_termios.c_ispeed = 38400;
519 pty_driver->init_termios.c_ospeed = 38400; 410 pty_driver->init_termios.c_ospeed = 38400;
411 pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW;
520 pty_driver->other = pty_slave_driver; 412 pty_driver->other = pty_slave_driver;
521 tty_set_operations(pty_driver, &master_pty_ops_bsd); 413 tty_set_operations(pty_driver, &master_pty_ops_bsd);
522 414
415 pty_slave_driver->owner = THIS_MODULE;
523 pty_slave_driver->driver_name = "pty_slave"; 416 pty_slave_driver->driver_name = "pty_slave";
524 pty_slave_driver->name = "ttyp"; 417 pty_slave_driver->name = "ttyp";
525 pty_slave_driver->major = PTY_SLAVE_MAJOR; 418 pty_slave_driver->major = PTY_SLAVE_MAJOR;
@@ -530,6 +423,8 @@ static void __init legacy_pty_init(void)
530 pty_slave_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 423 pty_slave_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
531 pty_slave_driver->init_termios.c_ispeed = 38400; 424 pty_slave_driver->init_termios.c_ispeed = 38400;
532 pty_slave_driver->init_termios.c_ospeed = 38400; 425 pty_slave_driver->init_termios.c_ospeed = 38400;
426 pty_slave_driver->flags = TTY_DRIVER_RESET_TERMIOS |
427 TTY_DRIVER_REAL_RAW;
533 pty_slave_driver->other = pty_driver; 428 pty_slave_driver->other = pty_driver;
534 tty_set_operations(pty_slave_driver, &slave_pty_ops_bsd); 429 tty_set_operations(pty_slave_driver, &slave_pty_ops_bsd);
535 430
@@ -544,21 +439,72 @@ static inline void legacy_pty_init(void) { }
544 439
545/* Unix98 devices */ 440/* Unix98 devices */
546#ifdef CONFIG_UNIX98_PTYS 441#ifdef CONFIG_UNIX98_PTYS
442/*
443 * sysctl support for setting limits on the number of Unix98 ptys allocated.
444 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
445 */
446int pty_limit = NR_UNIX98_PTY_DEFAULT;
447static int pty_limit_min;
448static int pty_limit_max = NR_UNIX98_PTY_MAX;
449static int tty_count;
450static int pty_count;
451
452static inline void pty_inc_count(void)
453{
454 pty_count = (++tty_count) / 2;
455}
456
457static inline void pty_dec_count(void)
458{
459 pty_count = (--tty_count) / 2;
460}
547 461
548static struct cdev ptmx_cdev; 462static struct cdev ptmx_cdev;
549 463
464static struct ctl_table pty_table[] = {
465 {
466 .procname = "max",
467 .maxlen = sizeof(int),
468 .mode = 0644,
469 .data = &pty_limit,
470 .proc_handler = proc_dointvec_minmax,
471 .extra1 = &pty_limit_min,
472 .extra2 = &pty_limit_max,
473 }, {
474 .procname = "nr",
475 .maxlen = sizeof(int),
476 .mode = 0444,
477 .data = &pty_count,
478 .proc_handler = proc_dointvec,
479 },
480 {}
481};
482
483static struct ctl_table pty_kern_table[] = {
484 {
485 .procname = "pty",
486 .mode = 0555,
487 .child = pty_table,
488 },
489 {}
490};
491
492static struct ctl_table pty_root_table[] = {
493 {
494 .procname = "kernel",
495 .mode = 0555,
496 .child = pty_kern_table,
497 },
498 {}
499};
500
501
550static int pty_unix98_ioctl(struct tty_struct *tty, 502static int pty_unix98_ioctl(struct tty_struct *tty,
551 unsigned int cmd, unsigned long arg) 503 unsigned int cmd, unsigned long arg)
552{ 504{
553 switch (cmd) { 505 switch (cmd) {
554 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */ 506 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
555 return pty_set_lock(tty, (int __user *)arg); 507 return pty_set_lock(tty, (int __user *)arg);
556 case TIOCGPTLCK: /* Get PT Lock status */
557 return pty_get_lock(tty, (int __user *)arg);
558 case TIOCPKT: /* Set PT packet mode */
559 return pty_set_pktmode(tty, (int __user *)arg);
560 case TIOCGPKT: /* Get PT packet mode */
561 return pty_get_pktmode(tty, (int __user *)arg);
562 case TIOCGPTN: /* Get PT Number */ 508 case TIOCGPTN: /* Get PT Number */
563 return put_user(tty->index, (unsigned int __user *)arg); 509 return put_user(tty->index, (unsigned int __user *)arg);
564 case TIOCSIG: /* Send signal to other side of pty */ 510 case TIOCSIG: /* Send signal to other side of pty */
@@ -580,8 +526,10 @@ static int pty_unix98_ioctl(struct tty_struct *tty,
580static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, 526static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
581 struct inode *ptm_inode, int idx) 527 struct inode *ptm_inode, int idx)
582{ 528{
583 /* Master must be open via /dev/ptmx */ 529 struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
584 return ERR_PTR(-EIO); 530 if (tty)
531 tty = tty->link;
532 return tty;
585} 533}
586 534
587/** 535/**
@@ -590,33 +538,84 @@ static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
590 * @idx: tty index 538 * @idx: tty index
591 * 539 *
592 * Look up a pty master device. Called under the tty_mutex for now. 540 * Look up a pty master device. Called under the tty_mutex for now.
593 * This provides our locking for the tty pointer. 541 * This provides our locking.
594 */ 542 */
595 543
596static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, 544static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
597 struct inode *pts_inode, int idx) 545 struct inode *pts_inode, int idx)
598{ 546{
599 struct tty_struct *tty; 547 struct tty_struct *tty = devpts_get_tty(pts_inode, idx);
600
601 mutex_lock(&devpts_mutex);
602 tty = devpts_get_priv(pts_inode);
603 mutex_unlock(&devpts_mutex);
604 /* Master must be open before slave */ 548 /* Master must be open before slave */
605 if (!tty) 549 if (!tty)
606 return ERR_PTR(-EIO); 550 return ERR_PTR(-EIO);
607 return tty; 551 return tty;
608} 552}
609 553
554static void pty_unix98_shutdown(struct tty_struct *tty)
555{
556 tty_driver_remove_tty(tty->driver, tty);
557 /* We have our own method as we don't use the tty index */
558 kfree(tty->termios);
559}
560
610/* We have no need to install and remove our tty objects as devpts does all 561/* We have no need to install and remove our tty objects as devpts does all
611 the work for us */ 562 the work for us */
612 563
613static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) 564static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
614{ 565{
615 return pty_common_install(driver, tty, false); 566 struct tty_struct *o_tty;
567 int idx = tty->index;
568
569 o_tty = alloc_tty_struct();
570 if (!o_tty)
571 return -ENOMEM;
572 if (!try_module_get(driver->other->owner)) {
573 /* This cannot in fact currently happen */
574 goto err_free_tty;
575 }
576 initialize_tty_struct(o_tty, driver->other, idx);
577
578 tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
579 if (tty->termios == NULL)
580 goto err_free_mem;
581 *tty->termios = driver->init_termios;
582 tty->termios_locked = tty->termios + 1;
583
584 o_tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
585 if (o_tty->termios == NULL)
586 goto err_free_mem;
587 *o_tty->termios = driver->other->init_termios;
588 o_tty->termios_locked = o_tty->termios + 1;
589
590 tty_driver_kref_get(driver->other);
591 if (driver->subtype == PTY_TYPE_MASTER)
592 o_tty->count++;
593 /* Establish the links in both directions */
594 tty->link = o_tty;
595 o_tty->link = tty;
596 /*
597 * All structures have been allocated, so now we install them.
598 * Failures after this point use release_tty to clean up, so
599 * there's no need to null out the local pointers.
600 */
601 tty_driver_kref_get(driver);
602 tty->count++;
603 pty_inc_count(); /* tty */
604 pty_inc_count(); /* tty->link */
605 return 0;
606err_free_mem:
607 deinitialize_tty_struct(o_tty);
608 kfree(o_tty->termios);
609 kfree(tty->termios);
610 module_put(o_tty->driver->owner);
611err_free_tty:
612 free_tty_struct(o_tty);
613 return -ENOMEM;
616} 614}
617 615
618static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) 616static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
619{ 617{
618 pty_dec_count();
620} 619}
621 620
622static const struct tty_operations ptm_unix98_ops = { 621static const struct tty_operations ptm_unix98_ops = {
@@ -632,9 +631,8 @@ static const struct tty_operations ptm_unix98_ops = {
632 .unthrottle = pty_unthrottle, 631 .unthrottle = pty_unthrottle,
633 .set_termios = pty_set_termios, 632 .set_termios = pty_set_termios,
634 .ioctl = pty_unix98_ioctl, 633 .ioctl = pty_unix98_ioctl,
635 .resize = pty_resize,
636 .shutdown = pty_unix98_shutdown, 634 .shutdown = pty_unix98_shutdown,
637 .cleanup = pty_cleanup 635 .resize = pty_resize
638}; 636};
639 637
640static const struct tty_operations pty_unix98_ops = { 638static const struct tty_operations pty_unix98_ops = {
@@ -649,8 +647,7 @@ static const struct tty_operations pty_unix98_ops = {
649 .chars_in_buffer = pty_chars_in_buffer, 647 .chars_in_buffer = pty_chars_in_buffer,
650 .unthrottle = pty_unthrottle, 648 .unthrottle = pty_unthrottle,
651 .set_termios = pty_set_termios, 649 .set_termios = pty_set_termios,
652 .shutdown = pty_unix98_shutdown, 650 .shutdown = pty_unix98_shutdown
653 .cleanup = pty_cleanup,
654}; 651};
655 652
656/** 653/**
@@ -668,7 +665,6 @@ static const struct tty_operations pty_unix98_ops = {
668static int ptmx_open(struct inode *inode, struct file *filp) 665static int ptmx_open(struct inode *inode, struct file *filp)
669{ 666{
670 struct tty_struct *tty; 667 struct tty_struct *tty;
671 struct inode *slave_inode;
672 int retval; 668 int retval;
673 int index; 669 int index;
674 670
@@ -679,55 +675,45 @@ static int ptmx_open(struct inode *inode, struct file *filp)
679 return retval; 675 return retval;
680 676
681 /* find a device that is not in use. */ 677 /* find a device that is not in use. */
682 mutex_lock(&devpts_mutex); 678 tty_lock();
683 index = devpts_new_index(inode); 679 index = devpts_new_index(inode);
680 tty_unlock();
684 if (index < 0) { 681 if (index < 0) {
685 retval = index; 682 retval = index;
686 mutex_unlock(&devpts_mutex);
687 goto err_file; 683 goto err_file;
688 } 684 }
689 685
690 mutex_unlock(&devpts_mutex);
691
692 mutex_lock(&tty_mutex); 686 mutex_lock(&tty_mutex);
693 tty = tty_init_dev(ptm_driver, index); 687 tty_lock();
688 tty = tty_init_dev(ptm_driver, index, 1);
689 mutex_unlock(&tty_mutex);
694 690
695 if (IS_ERR(tty)) { 691 if (IS_ERR(tty)) {
696 retval = PTR_ERR(tty); 692 retval = PTR_ERR(tty);
697 goto out; 693 goto out;
698 } 694 }
699 695
700 /* The tty returned here is locked so we can safely
701 drop the mutex */
702 mutex_unlock(&tty_mutex);
703
704 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 696 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
705 697
706 tty_add_file(tty, filp); 698 tty_add_file(tty, filp);
707 699
708 slave_inode = devpts_pty_new(inode, 700 retval = devpts_pty_new(inode, tty->link);
709 MKDEV(UNIX98_PTY_SLAVE_MAJOR, index), index, 701 if (retval)
710 tty->link);
711 if (IS_ERR(slave_inode)) {
712 retval = PTR_ERR(slave_inode);
713 goto err_release; 702 goto err_release;
714 }
715 703
716 retval = ptm_driver->ops->open(tty, filp); 704 retval = ptm_driver->ops->open(tty, filp);
717 if (retval) 705 if (retval)
718 goto err_release; 706 goto err_release;
719 707
720 tty_unlock(tty); 708 tty_unlock();
721 tty->driver_data = inode;
722 tty->link->driver_data = slave_inode;
723 return 0; 709 return 0;
724err_release: 710err_release:
725 tty_unlock(tty); 711 tty_unlock();
726 tty_release(inode, filp); 712 tty_release(inode, filp);
727 return retval; 713 return retval;
728out: 714out:
729 mutex_unlock(&tty_mutex);
730 devpts_kill_index(inode, index); 715 devpts_kill_index(inode, index);
716 tty_unlock();
731err_file: 717err_file:
732 tty_free_file(filp); 718 tty_free_file(filp);
733 return retval; 719 return retval;
@@ -737,23 +723,14 @@ static struct file_operations ptmx_fops;
737 723
738static void __init unix98_pty_init(void) 724static void __init unix98_pty_init(void)
739{ 725{
740 ptm_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX, 726 ptm_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX);
741 TTY_DRIVER_RESET_TERMIOS | 727 if (!ptm_driver)
742 TTY_DRIVER_REAL_RAW |
743 TTY_DRIVER_DYNAMIC_DEV |
744 TTY_DRIVER_DEVPTS_MEM |
745 TTY_DRIVER_DYNAMIC_ALLOC);
746 if (IS_ERR(ptm_driver))
747 panic("Couldn't allocate Unix98 ptm driver"); 728 panic("Couldn't allocate Unix98 ptm driver");
748 pts_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX, 729 pts_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX);
749 TTY_DRIVER_RESET_TERMIOS | 730 if (!pts_driver)
750 TTY_DRIVER_REAL_RAW |
751 TTY_DRIVER_DYNAMIC_DEV |
752 TTY_DRIVER_DEVPTS_MEM |
753 TTY_DRIVER_DYNAMIC_ALLOC);
754 if (IS_ERR(pts_driver))
755 panic("Couldn't allocate Unix98 pts driver"); 731 panic("Couldn't allocate Unix98 pts driver");
756 732
733 ptm_driver->owner = THIS_MODULE;
757 ptm_driver->driver_name = "pty_master"; 734 ptm_driver->driver_name = "pty_master";
758 ptm_driver->name = "ptm"; 735 ptm_driver->name = "ptm";
759 ptm_driver->major = UNIX98_PTY_MASTER_MAJOR; 736 ptm_driver->major = UNIX98_PTY_MASTER_MAJOR;
@@ -767,9 +744,12 @@ static void __init unix98_pty_init(void)
767 ptm_driver->init_termios.c_lflag = 0; 744 ptm_driver->init_termios.c_lflag = 0;
768 ptm_driver->init_termios.c_ispeed = 38400; 745 ptm_driver->init_termios.c_ispeed = 38400;
769 ptm_driver->init_termios.c_ospeed = 38400; 746 ptm_driver->init_termios.c_ospeed = 38400;
747 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
748 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
770 ptm_driver->other = pts_driver; 749 ptm_driver->other = pts_driver;
771 tty_set_operations(ptm_driver, &ptm_unix98_ops); 750 tty_set_operations(ptm_driver, &ptm_unix98_ops);
772 751
752 pts_driver->owner = THIS_MODULE;
773 pts_driver->driver_name = "pty_slave"; 753 pts_driver->driver_name = "pty_slave";
774 pts_driver->name = "pts"; 754 pts_driver->name = "pts";
775 pts_driver->major = UNIX98_PTY_SLAVE_MAJOR; 755 pts_driver->major = UNIX98_PTY_SLAVE_MAJOR;
@@ -780,6 +760,8 @@ static void __init unix98_pty_init(void)
780 pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 760 pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
781 pts_driver->init_termios.c_ispeed = 38400; 761 pts_driver->init_termios.c_ispeed = 38400;
782 pts_driver->init_termios.c_ospeed = 38400; 762 pts_driver->init_termios.c_ospeed = 38400;
763 pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
764 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
783 pts_driver->other = ptm_driver; 765 pts_driver->other = ptm_driver;
784 tty_set_operations(pts_driver, &pty_unix98_ops); 766 tty_set_operations(pts_driver, &pty_unix98_ops);
785 767
@@ -788,6 +770,8 @@ static void __init unix98_pty_init(void)
788 if (tty_register_driver(pts_driver)) 770 if (tty_register_driver(pts_driver))
789 panic("Couldn't register Unix98 pts driver"); 771 panic("Couldn't register Unix98 pts driver");
790 772
773 register_sysctl_table(pty_root_table);
774
791 /* Now create the /dev/ptmx special device */ 775 /* Now create the /dev/ptmx special device */
792 tty_default_fops(&ptmx_fops); 776 tty_default_fops(&ptmx_fops);
793 ptmx_fops.open = ptmx_open; 777 ptmx_fops.open = ptmx_open;
diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
index e42009a0052..6a1241c7f84 100644
--- a/drivers/tty/rocket.c
+++ b/drivers/tty/rocket.c
@@ -118,7 +118,7 @@ static unsigned long board2;
118static unsigned long board3; 118static unsigned long board3;
119static unsigned long board4; 119static unsigned long board4;
120static unsigned long controller; 120static unsigned long controller;
121static bool support_low_speed; 121static int support_low_speed;
122static unsigned long modem1; 122static unsigned long modem1;
123static unsigned long modem2; 123static unsigned long modem2;
124static unsigned long modem3; 124static unsigned long modem3;
@@ -673,7 +673,6 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
673 if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) { 673 if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) {
674 printk(KERN_ERR "RocketPort sInitChan(%d, %d, %d) failed!\n", 674 printk(KERN_ERR "RocketPort sInitChan(%d, %d, %d) failed!\n",
675 board, aiop, chan); 675 board, aiop, chan);
676 tty_port_destroy(&info->port);
677 kfree(info); 676 kfree(info);
678 return; 677 return;
679 } 678 }
@@ -705,8 +704,8 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
705 spin_lock_init(&info->slock); 704 spin_lock_init(&info->slock);
706 mutex_init(&info->write_mtx); 705 mutex_init(&info->write_mtx);
707 rp_table[line] = info; 706 rp_table[line] = info;
708 tty_port_register_device(&info->port, rocket_driver, line, 707 tty_register_device(rocket_driver, line, pci_dev ? &pci_dev->dev :
709 pci_dev ? &pci_dev->dev : NULL); 708 NULL);
710} 709}
711 710
712/* 711/*
@@ -721,7 +720,7 @@ static void configure_r_port(struct tty_struct *tty, struct r_port *info,
721 unsigned rocketMode; 720 unsigned rocketMode;
722 int bits, baud, divisor; 721 int bits, baud, divisor;
723 CHANNEL_t *cp; 722 CHANNEL_t *cp;
724 struct ktermios *t = &tty->termios; 723 struct ktermios *t = tty->termios;
725 724
726 cp = &info->channel; 725 cp = &info->channel;
727 cflag = t->c_cflag; 726 cflag = t->c_cflag;
@@ -893,12 +892,12 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
893{ 892{
894 struct r_port *info; 893 struct r_port *info;
895 struct tty_port *port; 894 struct tty_port *port;
896 int retval; 895 int line = 0, retval;
897 CHANNEL_t *cp; 896 CHANNEL_t *cp;
898 unsigned long page; 897 unsigned long page;
899 898
900 info = rp_table[tty->index]; 899 line = tty->index;
901 if (info == NULL) 900 if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL))
902 return -ENXIO; 901 return -ENXIO;
903 port = &info->port; 902 port = &info->port;
904 903
@@ -979,7 +978,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
979 tty->alt_speed = 460800; 978 tty->alt_speed = 460800;
980 979
981 configure_r_port(tty, info, NULL); 980 configure_r_port(tty, info, NULL);
982 if (tty->termios.c_cflag & CBAUD) { 981 if (tty->termios->c_cflag & CBAUD) {
983 sSetDTR(cp); 982 sSetDTR(cp);
984 sSetRTS(cp); 983 sSetRTS(cp);
985 } 984 }
@@ -1090,35 +1089,35 @@ static void rp_set_termios(struct tty_struct *tty,
1090 if (rocket_paranoia_check(info, "rp_set_termios")) 1089 if (rocket_paranoia_check(info, "rp_set_termios"))
1091 return; 1090 return;
1092 1091
1093 cflag = tty->termios.c_cflag; 1092 cflag = tty->termios->c_cflag;
1094 1093
1095 /* 1094 /*
1096 * This driver doesn't support CS5 or CS6 1095 * This driver doesn't support CS5 or CS6
1097 */ 1096 */
1098 if (((cflag & CSIZE) == CS5) || ((cflag & CSIZE) == CS6)) 1097 if (((cflag & CSIZE) == CS5) || ((cflag & CSIZE) == CS6))
1099 tty->termios.c_cflag = 1098 tty->termios->c_cflag =
1100 ((cflag & ~CSIZE) | (old_termios->c_cflag & CSIZE)); 1099 ((cflag & ~CSIZE) | (old_termios->c_cflag & CSIZE));
1101 /* Or CMSPAR */ 1100 /* Or CMSPAR */
1102 tty->termios.c_cflag &= ~CMSPAR; 1101 tty->termios->c_cflag &= ~CMSPAR;
1103 1102
1104 configure_r_port(tty, info, old_termios); 1103 configure_r_port(tty, info, old_termios);
1105 1104
1106 cp = &info->channel; 1105 cp = &info->channel;
1107 1106
1108 /* Handle transition to B0 status */ 1107 /* Handle transition to B0 status */
1109 if ((old_termios->c_cflag & CBAUD) && !(tty->termios.c_cflag & CBAUD)) { 1108 if ((old_termios->c_cflag & CBAUD) && !(tty->termios->c_cflag & CBAUD)) {
1110 sClrDTR(cp); 1109 sClrDTR(cp);
1111 sClrRTS(cp); 1110 sClrRTS(cp);
1112 } 1111 }
1113 1112
1114 /* Handle transition away from B0 status */ 1113 /* Handle transition away from B0 status */
1115 if (!(old_termios->c_cflag & CBAUD) && (tty->termios.c_cflag & CBAUD)) { 1114 if (!(old_termios->c_cflag & CBAUD) && (tty->termios->c_cflag & CBAUD)) {
1116 if (!tty->hw_stopped || !(tty->termios.c_cflag & CRTSCTS)) 1115 if (!tty->hw_stopped || !(tty->termios->c_cflag & CRTSCTS))
1117 sSetRTS(cp); 1116 sSetRTS(cp);
1118 sSetDTR(cp); 1117 sSetDTR(cp);
1119 } 1118 }
1120 1119
1121 if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios.c_cflag & CRTSCTS)) { 1120 if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
1122 tty->hw_stopped = 0; 1121 tty->hw_stopped = 0;
1123 rp_start(tty); 1122 rp_start(tty);
1124 } 1123 }
@@ -1758,7 +1757,7 @@ static void rp_flush_buffer(struct tty_struct *tty)
1758 1757
1759#ifdef CONFIG_PCI 1758#ifdef CONFIG_PCI
1760 1759
1761static struct pci_device_id __used rocket_pci_ids[] = { 1760static struct pci_device_id __devinitdata __used rocket_pci_ids[] = {
1762 { PCI_DEVICE(PCI_VENDOR_ID_RP, PCI_ANY_ID) }, 1761 { PCI_DEVICE(PCI_VENDOR_ID_RP, PCI_ANY_ID) },
1763 { } 1762 { }
1764}; 1763};
@@ -2278,6 +2277,7 @@ static int __init rp_init(void)
2278 * driver with the tty layer. 2277 * driver with the tty layer.
2279 */ 2278 */
2280 2279
2280 rocket_driver->owner = THIS_MODULE;
2281 rocket_driver->flags = TTY_DRIVER_DYNAMIC_DEV; 2281 rocket_driver->flags = TTY_DRIVER_DYNAMIC_DEV;
2282 rocket_driver->name = "ttyR"; 2282 rocket_driver->name = "ttyR";
2283 rocket_driver->driver_name = "Comtrol RocketPort"; 2283 rocket_driver->driver_name = "Comtrol RocketPort";
@@ -2358,7 +2358,6 @@ static void rp_cleanup_module(void)
2358 for (i = 0; i < MAX_RP_PORTS; i++) 2358 for (i = 0; i < MAX_RP_PORTS; i++)
2359 if (rp_table[i]) { 2359 if (rp_table[i]) {
2360 tty_unregister_device(rocket_driver, i); 2360 tty_unregister_device(rocket_driver, i);
2361 tty_port_destroy(&rp_table[i]->port);
2362 kfree(rp_table[i]); 2361 kfree(rp_table[i]);
2363 } 2362 }
2364 2363
diff --git a/drivers/tty/serial/21285.c b/drivers/tty/serial/21285.c
index a44345a2dbb..1b37626e8f1 100644
--- a/drivers/tty/serial/21285.c
+++ b/drivers/tty/serial/21285.c
@@ -16,7 +16,6 @@
16 16
17#include <asm/irq.h> 17#include <asm/irq.h>
18#include <asm/mach-types.h> 18#include <asm/mach-types.h>
19#include <asm/system_info.h>
20#include <asm/hardware/dec21285.h> 19#include <asm/hardware/dec21285.h>
21#include <mach/hardware.h> 20#include <mach/hardware.h>
22 21
@@ -332,7 +331,7 @@ static int serial21285_verify_port(struct uart_port *port, struct serial_struct
332 int ret = 0; 331 int ret = 0;
333 if (ser->type != PORT_UNKNOWN && ser->type != PORT_21285) 332 if (ser->type != PORT_UNKNOWN && ser->type != PORT_21285)
334 ret = -EINVAL; 333 ret = -EINVAL;
335 if (ser->irq <= 0) 334 if (ser->irq != NO_IRQ)
336 ret = -EINVAL; 335 ret = -EINVAL;
337 if (ser->baud_base != port->uartclk / 16) 336 if (ser->baud_base != port->uartclk / 16)
338 ret = -EINVAL; 337 ret = -EINVAL;
@@ -361,7 +360,7 @@ static struct uart_ops serial21285_ops = {
361static struct uart_port serial21285_port = { 360static struct uart_port serial21285_port = {
362 .mapbase = 0x42000160, 361 .mapbase = 0x42000160,
363 .iotype = UPIO_MEM, 362 .iotype = UPIO_MEM,
364 .irq = 0, 363 .irq = NO_IRQ,
365 .fifosize = 16, 364 .fifosize = 16,
366 .ops = &serial21285_ops, 365 .ops = &serial21285_ops,
367 .flags = UPF_BOOT_AUTOCONF, 366 .flags = UPF_BOOT_AUTOCONF,
diff --git a/drivers/tty/serial/68328serial.c b/drivers/tty/serial/68328serial.c
index f99a84526f8..e0a77540b8c 100644
--- a/drivers/tty/serial/68328serial.c
+++ b/drivers/tty/serial/68328serial.c
@@ -17,7 +17,6 @@
17#include <asm/dbg.h> 17#include <asm/dbg.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/serial.h>
21#include <linux/signal.h> 20#include <linux/signal.h>
22#include <linux/sched.h> 21#include <linux/sched.h>
23#include <linux/timer.h> 22#include <linux/timer.h>
@@ -40,6 +39,7 @@
40 39
41#include <asm/io.h> 40#include <asm/io.h>
42#include <asm/irq.h> 41#include <asm/irq.h>
42#include <asm/system.h>
43#include <asm/delay.h> 43#include <asm/delay.h>
44#include <asm/uaccess.h> 44#include <asm/uaccess.h>
45 45
@@ -57,6 +57,8 @@
57#endif /* CONFIG_M68VZ328 */ 57#endif /* CONFIG_M68VZ328 */
58#endif /* CONFIG_M68EZ328 */ 58#endif /* CONFIG_M68EZ328 */
59 59
60#include "68328serial.h"
61
60/* Turn off usage of real serial interrupt code, to "support" Copilot */ 62/* Turn off usage of real serial interrupt code, to "support" Copilot */
61#ifdef CONFIG_XCOPILOT_BUGS 63#ifdef CONFIG_XCOPILOT_BUGS
62#undef USE_INTS 64#undef USE_INTS
@@ -64,82 +66,33 @@
64#define USE_INTS 66#define USE_INTS
65#endif 67#endif
66 68
67/* 69static struct m68k_serial m68k_soft[NR_PORTS];
68 * I believe this is the optimal setting that reduces the number of interrupts.
69 * At high speeds the output might become a little "bursted" (use USTCNT_TXHE
70 * if that bothers you), but in most cases it will not, since we try to
71 * transmit characters every time rs_interrupt is called. Thus, quite often
72 * you'll see that a receive interrupt occures before the transmit one.
73 * -- Vladimir Gurevich
74 */
75#define USTCNT_TX_INTR_MASK (USTCNT_TXEE)
76
77/*
78 * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special
79 * "Old data interrupt" which occures whenever the data stay in the FIFO
80 * longer than 30 bits time. This allows us to use FIFO without compromising
81 * latency. '328 does not have this feature and without the real 328-based
82 * board I would assume that RXRE is the safest setting.
83 *
84 * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of
85 * interrupts. RXFE (receive queue full) causes the system to lose data
86 * at least at 115200 baud
87 *
88 * If your board is busy doing other stuff, you might consider to use
89 * RXRE (data ready intrrupt) instead.
90 *
91 * The other option is to make these INTR masks run-time configurable, so
92 * that people can dynamically adapt them according to the current usage.
93 * -- Vladimir Gurevich
94 */
95 70
96/* (es) */ 71static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS;
97#if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)
98#define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)
99#elif defined(CONFIG_M68328)
100#define USTCNT_RX_INTR_MASK (USTCNT_RXRE)
101#else
102#error Please, define the Rx interrupt events for your CPU
103#endif
104/* (/es) */
105 72
106/* 73/* multiple ports are contiguous in memory */
107 * This is our internal structure for each serial port's state. 74m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR;
108 */
109struct m68k_serial {
110 struct tty_port tport;
111 char is_cons; /* Is this our console. */
112 int magic;
113 int baud_base;
114 int port;
115 int irq;
116 int type; /* UART type */
117 int custom_divisor;
118 int x_char; /* xon/xoff character */
119 int line;
120 unsigned char *xmit_buf;
121 int xmit_head;
122 int xmit_tail;
123 int xmit_cnt;
124};
125 75
126#define SERIAL_MAGIC 0x5301 76struct tty_struct m68k_ttys;
77struct m68k_serial *m68k_consinfo = 0;
127 78
128/* 79#define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */
129 * Define the number of ports supported and their irqs.
130 */
131#define NR_PORTS 1
132 80
133static struct m68k_serial m68k_soft[NR_PORTS]; 81struct tty_driver *serial_driver;
134 82
135static unsigned int uart_irqs[NR_PORTS] = { UART_IRQ_NUM }; 83/* number of characters left in xmit buffer before we ask for more */
84#define WAKEUP_CHARS 256
136 85
137/* multiple ports are contiguous in memory */ 86/* Debugging... DEBUG_INTR is bad to use when one of the zs
138m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR; 87 * lines is your console ;(
88 */
89#undef SERIAL_DEBUG_INTR
90#undef SERIAL_DEBUG_OPEN
91#undef SERIAL_DEBUG_FLOW
139 92
140struct tty_driver *serial_driver; 93#define RS_ISR_PASS_LIMIT 256
141 94
142static void change_speed(struct m68k_serial *info, struct tty_struct *tty); 95static void change_speed(struct m68k_serial *info);
143 96
144/* 97/*
145 * Setup for console. Argument comes from the boot command line. 98 * Setup for console. Argument comes from the boot command line.
@@ -191,6 +144,17 @@ static int baud_table[] = {
191 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 144 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
192 9600, 19200, 38400, 57600, 115200, 0 }; 145 9600, 19200, 38400, 57600, 115200, 0 };
193 146
147/* Sets or clears DTR/RTS on the requested line */
148static inline void m68k_rtsdtr(struct m68k_serial *ss, int set)
149{
150 if (set) {
151 /* set the RTS/CTS line */
152 } else {
153 /* clear it */
154 }
155 return;
156}
157
194/* Utility routines */ 158/* Utility routines */
195static inline int get_baud(struct m68k_serial *ss) 159static inline int get_baud(struct m68k_serial *ss)
196{ 160{
@@ -226,8 +190,7 @@ static void rs_stop(struct tty_struct *tty)
226 190
227static int rs_put_char(char ch) 191static int rs_put_char(char ch)
228{ 192{
229 unsigned long flags; 193 int flags, loops = 0;
230 int loops = 0;
231 194
232 local_irq_save(flags); 195 local_irq_save(flags);
233 196
@@ -262,9 +225,44 @@ static void rs_start(struct tty_struct *tty)
262 local_irq_restore(flags); 225 local_irq_restore(flags);
263} 226}
264 227
265static void receive_chars(struct m68k_serial *info, struct tty_struct *tty, 228/* Drop into either the boot monitor or kadb upon receiving a break
266 unsigned short rx) 229 * from keyboard/console input.
230 */
231static void batten_down_hatches(void)
232{
233 /* Drop into the debugger */
234}
235
236static void status_handle(struct m68k_serial *info, unsigned short status)
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
255 * 'break asserted' status change interrupt
256 * see if we can drop into the debugger
257 */
258 if((status & URX_BREAK) && info->break_abort)
259 batten_down_hatches();
260 return;
261}
262
263static void receive_chars(struct m68k_serial *info, unsigned short rx)
267{ 264{
265 struct tty_struct *tty = info->tty;
268 m68328_uart *uart = &uart_addr[info->line]; 266 m68328_uart *uart = &uart_addr[info->line];
269 unsigned char ch, flag; 267 unsigned char ch, flag;
270 268
@@ -278,6 +276,7 @@ static void receive_chars(struct m68k_serial *info, struct tty_struct *tty,
278 276
279 if(info->is_cons) { 277 if(info->is_cons) {
280 if(URX_BREAK & rx) { /* whee, break received */ 278 if(URX_BREAK & rx) { /* whee, break received */
279 status_handle(info, rx);
281 return; 280 return;
282#ifdef CONFIG_MAGIC_SYSRQ 281#ifdef CONFIG_MAGIC_SYSRQ
283 } else if (ch == 0x10) { /* ^P */ 282 } else if (ch == 0x10) { /* ^P */
@@ -298,13 +297,16 @@ static void receive_chars(struct m68k_serial *info, struct tty_struct *tty,
298 297
299 flag = TTY_NORMAL; 298 flag = TTY_NORMAL;
300 299
301 if (rx & URX_PARITY_ERROR) 300 if(rx & URX_PARITY_ERROR) {
302 flag = TTY_PARITY; 301 flag = TTY_PARITY;
303 else if (rx & URX_OVRUN) 302 status_handle(info, rx);
303 } else if(rx & URX_OVRUN) {
304 flag = TTY_OVERRUN; 304 flag = TTY_OVERRUN;
305 else if (rx & URX_FRAME_ERROR) 305 status_handle(info, rx);
306 } else if(rx & URX_FRAME_ERROR) {
306 flag = TTY_FRAME; 307 flag = TTY_FRAME;
307 308 status_handle(info, rx);
309 }
308 tty_insert_flip_char(tty, ch, flag); 310 tty_insert_flip_char(tty, ch, flag);
309#ifndef CONFIG_XCOPILOT_BUGS 311#ifndef CONFIG_XCOPILOT_BUGS
310 } while((rx = uart->urx.w) & URX_DATA_READY); 312 } while((rx = uart->urx.w) & URX_DATA_READY);
@@ -316,7 +318,7 @@ clear_and_exit:
316 return; 318 return;
317} 319}
318 320
319static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty) 321static void transmit_chars(struct m68k_serial *info)
320{ 322{
321 m68328_uart *uart = &uart_addr[info->line]; 323 m68328_uart *uart = &uart_addr[info->line];
322 324
@@ -327,7 +329,7 @@ static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty)
327 goto clear_and_return; 329 goto clear_and_return;
328 } 330 }
329 331
330 if ((info->xmit_cnt <= 0) || !tty || tty->stopped) { 332 if((info->xmit_cnt <= 0) || info->tty->stopped) {
331 /* That's peculiar... TX ints off */ 333 /* That's peculiar... TX ints off */
332 uart->ustcnt &= ~USTCNT_TX_INTR_MASK; 334 uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
333 goto clear_and_return; 335 goto clear_and_return;
@@ -338,6 +340,9 @@ static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty)
338 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1); 340 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
339 info->xmit_cnt--; 341 info->xmit_cnt--;
340 342
343 if (info->xmit_cnt < WAKEUP_CHARS)
344 schedule_work(&info->tqueue);
345
341 if(info->xmit_cnt <= 0) { 346 if(info->xmit_cnt <= 0) {
342 /* All done for now... TX ints off */ 347 /* All done for now... TX ints off */
343 uart->ustcnt &= ~USTCNT_TX_INTR_MASK; 348 uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
@@ -355,7 +360,6 @@ clear_and_return:
355irqreturn_t rs_interrupt(int irq, void *dev_id) 360irqreturn_t rs_interrupt(int irq, void *dev_id)
356{ 361{
357 struct m68k_serial *info = dev_id; 362 struct m68k_serial *info = dev_id;
358 struct tty_struct *tty = tty_port_tty_get(&info->tport);
359 m68328_uart *uart; 363 m68328_uart *uart;
360 unsigned short rx; 364 unsigned short rx;
361 unsigned short tx; 365 unsigned short tx;
@@ -366,24 +370,35 @@ irqreturn_t rs_interrupt(int irq, void *dev_id)
366#ifdef USE_INTS 370#ifdef USE_INTS
367 tx = uart->utx.w; 371 tx = uart->utx.w;
368 372
369 if (rx & URX_DATA_READY) 373 if (rx & URX_DATA_READY) receive_chars(info, rx);
370 receive_chars(info, tty, rx); 374 if (tx & UTX_TX_AVAIL) transmit_chars(info);
371 if (tx & UTX_TX_AVAIL)
372 transmit_chars(info, tty);
373#else 375#else
374 receive_chars(info, tty, rx); 376 receive_chars(info, rx);
375#endif 377#endif
376 tty_kref_put(tty);
377
378 return IRQ_HANDLED; 378 return IRQ_HANDLED;
379} 379}
380 380
381static int startup(struct m68k_serial *info, struct tty_struct *tty) 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)
382{ 397{
383 m68328_uart *uart = &uart_addr[info->line]; 398 m68328_uart *uart = &uart_addr[info->line];
384 unsigned long flags; 399 unsigned long flags;
385 400
386 if (info->tport.flags & ASYNC_INITIALIZED) 401 if (info->flags & S_INITIALIZED)
387 return 0; 402 return 0;
388 403
389 if (!info->xmit_buf) { 404 if (!info->xmit_buf) {
@@ -400,6 +415,7 @@ static int startup(struct m68k_serial *info, struct tty_struct *tty)
400 */ 415 */
401 416
402 uart->ustcnt = USTCNT_UEN; 417 uart->ustcnt = USTCNT_UEN;
418 info->xmit_fifo_size = 1;
403 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN; 419 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN;
404 (void)uart->urx.w; 420 (void)uart->urx.w;
405 421
@@ -413,17 +429,17 @@ static int startup(struct m68k_serial *info, struct tty_struct *tty)
413 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK; 429 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK;
414#endif 430#endif
415 431
416 if (tty) 432 if (info->tty)
417 clear_bit(TTY_IO_ERROR, &tty->flags); 433 clear_bit(TTY_IO_ERROR, &info->tty->flags);
418 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 434 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
419 435
420 /* 436 /*
421 * and set the speed of the serial port 437 * and set the speed of the serial port
422 */ 438 */
423 439
424 change_speed(info, tty); 440 change_speed(info);
425 441
426 info->tport.flags |= ASYNC_INITIALIZED; 442 info->flags |= S_INITIALIZED;
427 local_irq_restore(flags); 443 local_irq_restore(flags);
428 return 0; 444 return 0;
429} 445}
@@ -432,13 +448,13 @@ static int startup(struct m68k_serial *info, struct tty_struct *tty)
432 * This routine will shutdown a serial port; interrupts are disabled, and 448 * This routine will shutdown a serial port; interrupts are disabled, and
433 * DTR is dropped if the hangup on close termio flag is on. 449 * DTR is dropped if the hangup on close termio flag is on.
434 */ 450 */
435static void shutdown(struct m68k_serial *info, struct tty_struct *tty) 451static void shutdown(struct m68k_serial * info)
436{ 452{
437 m68328_uart *uart = &uart_addr[info->line]; 453 m68328_uart *uart = &uart_addr[info->line];
438 unsigned long flags; 454 unsigned long flags;
439 455
440 uart->ustcnt = 0; /* All off! */ 456 uart->ustcnt = 0; /* All off! */
441 if (!(info->tport.flags & ASYNC_INITIALIZED)) 457 if (!(info->flags & S_INITIALIZED))
442 return; 458 return;
443 459
444 local_irq_save(flags); 460 local_irq_save(flags);
@@ -448,10 +464,10 @@ static void shutdown(struct m68k_serial *info, struct tty_struct *tty)
448 info->xmit_buf = 0; 464 info->xmit_buf = 0;
449 } 465 }
450 466
451 if (tty) 467 if (info->tty)
452 set_bit(TTY_IO_ERROR, &tty->flags); 468 set_bit(TTY_IO_ERROR, &info->tty->flags);
453 469
454 info->tport.flags &= ~ASYNC_INITIALIZED; 470 info->flags &= ~S_INITIALIZED;
455 local_irq_restore(flags); 471 local_irq_restore(flags);
456} 472}
457 473
@@ -507,7 +523,7 @@ struct {
507 * This routine is called to set the UART divisor registers to match 523 * This routine is called to set the UART divisor registers to match
508 * the specified baud rate for a serial port. 524 * the specified baud rate for a serial port.
509 */ 525 */
510static void change_speed(struct m68k_serial *info, struct tty_struct *tty) 526static void change_speed(struct m68k_serial *info)
511{ 527{
512 m68328_uart *uart = &uart_addr[info->line]; 528 m68328_uart *uart = &uart_addr[info->line];
513 unsigned short port; 529 unsigned short port;
@@ -515,7 +531,9 @@ static void change_speed(struct m68k_serial *info, struct tty_struct *tty)
515 unsigned cflag; 531 unsigned cflag;
516 int i; 532 int i;
517 533
518 cflag = tty->termios.c_cflag; 534 if (!info->tty || !info->tty->termios)
535 return;
536 cflag = info->tty->termios->c_cflag;
519 if (!(port = info->port)) 537 if (!(port = info->port))
520 return; 538 return;
521 539
@@ -527,6 +545,7 @@ static void change_speed(struct m68k_serial *info, struct tty_struct *tty)
527 i = (i & ~CBAUDEX) + B38400; 545 i = (i & ~CBAUDEX) + B38400;
528 } 546 }
529 547
548 info->baud = baud_table[i];
530 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | 549 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
531 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale); 550 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
532 551
@@ -617,7 +636,7 @@ static void rs_set_ldisc(struct tty_struct *tty)
617 if (serial_paranoia_check(info, tty->name, "rs_set_ldisc")) 636 if (serial_paranoia_check(info, tty->name, "rs_set_ldisc"))
618 return; 637 return;
619 638
620 info->is_cons = (tty->termios.c_line == N_TTY); 639 info->is_cons = (tty->termios->c_line == N_TTY);
621 640
622 printk("ttyS%d console mode %s\n", info->line, info->is_cons ? "on" : "off"); 641 printk("ttyS%d console mode %s\n", info->line, info->is_cons ? "on" : "off");
623} 642}
@@ -823,10 +842,10 @@ static int get_serial_info(struct m68k_serial * info,
823 tmp.line = info->line; 842 tmp.line = info->line;
824 tmp.port = info->port; 843 tmp.port = info->port;
825 tmp.irq = info->irq; 844 tmp.irq = info->irq;
826 tmp.flags = info->tport.flags; 845 tmp.flags = info->flags;
827 tmp.baud_base = info->baud_base; 846 tmp.baud_base = info->baud_base;
828 tmp.close_delay = info->tport.close_delay; 847 tmp.close_delay = info->close_delay;
829 tmp.closing_wait = info->tport.closing_wait; 848 tmp.closing_wait = info->closing_wait;
830 tmp.custom_divisor = info->custom_divisor; 849 tmp.custom_divisor = info->custom_divisor;
831 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 850 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
832 return -EFAULT; 851 return -EFAULT;
@@ -834,10 +853,9 @@ static int get_serial_info(struct m68k_serial * info,
834 return 0; 853 return 0;
835} 854}
836 855
837static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty, 856static int set_serial_info(struct m68k_serial * info,
838 struct serial_struct * new_info) 857 struct serial_struct * new_info)
839{ 858{
840 struct tty_port *port = &info->tport;
841 struct serial_struct new_serial; 859 struct serial_struct new_serial;
842 struct m68k_serial old_info; 860 struct m68k_serial old_info;
843 int retval = 0; 861 int retval = 0;
@@ -851,17 +869,17 @@ static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty,
851 if (!capable(CAP_SYS_ADMIN)) { 869 if (!capable(CAP_SYS_ADMIN)) {
852 if ((new_serial.baud_base != info->baud_base) || 870 if ((new_serial.baud_base != info->baud_base) ||
853 (new_serial.type != info->type) || 871 (new_serial.type != info->type) ||
854 (new_serial.close_delay != port->close_delay) || 872 (new_serial.close_delay != info->close_delay) ||
855 ((new_serial.flags & ~ASYNC_USR_MASK) != 873 ((new_serial.flags & ~S_USR_MASK) !=
856 (port->flags & ~ASYNC_USR_MASK))) 874 (info->flags & ~S_USR_MASK)))
857 return -EPERM; 875 return -EPERM;
858 port->flags = ((port->flags & ~ASYNC_USR_MASK) | 876 info->flags = ((info->flags & ~S_USR_MASK) |
859 (new_serial.flags & ASYNC_USR_MASK)); 877 (new_serial.flags & S_USR_MASK));
860 info->custom_divisor = new_serial.custom_divisor; 878 info->custom_divisor = new_serial.custom_divisor;
861 goto check_and_exit; 879 goto check_and_exit;
862 } 880 }
863 881
864 if (port->count > 1) 882 if (info->count > 1)
865 return -EBUSY; 883 return -EBUSY;
866 884
867 /* 885 /*
@@ -870,14 +888,14 @@ static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty,
870 */ 888 */
871 889
872 info->baud_base = new_serial.baud_base; 890 info->baud_base = new_serial.baud_base;
873 port->flags = ((port->flags & ~ASYNC_FLAGS) | 891 info->flags = ((info->flags & ~S_FLAGS) |
874 (new_serial.flags & ASYNC_FLAGS)); 892 (new_serial.flags & S_FLAGS));
875 info->type = new_serial.type; 893 info->type = new_serial.type;
876 port->close_delay = new_serial.close_delay; 894 info->close_delay = new_serial.close_delay;
877 port->closing_wait = new_serial.closing_wait; 895 info->closing_wait = new_serial.closing_wait;
878 896
879check_and_exit: 897check_and_exit:
880 retval = startup(info, tty); 898 retval = startup(info);
881 return retval; 899 return retval;
882} 900}
883 901
@@ -963,7 +981,7 @@ static int rs_ioctl(struct tty_struct *tty,
963 return get_serial_info(info, 981 return get_serial_info(info,
964 (struct serial_struct *) arg); 982 (struct serial_struct *) arg);
965 case TIOCSSERIAL: 983 case TIOCSSERIAL:
966 return set_serial_info(info, tty, 984 return set_serial_info(info,
967 (struct serial_struct *) arg); 985 (struct serial_struct *) arg);
968 case TIOCSERGETLSR: /* Get line status register */ 986 case TIOCSERGETLSR: /* Get line status register */
969 return get_lsr_info(info, (unsigned int *) arg); 987 return get_lsr_info(info, (unsigned int *) arg);
@@ -982,10 +1000,10 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
982{ 1000{
983 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 1001 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
984 1002
985 change_speed(info, tty); 1003 change_speed(info);
986 1004
987 if ((old_termios->c_cflag & CRTSCTS) && 1005 if ((old_termios->c_cflag & CRTSCTS) &&
988 !(tty->termios.c_cflag & CRTSCTS)) { 1006 !(tty->termios->c_cflag & CRTSCTS)) {
989 tty->hw_stopped = 0; 1007 tty->hw_stopped = 0;
990 rs_start(tty); 1008 rs_start(tty);
991 } 1009 }
@@ -1005,7 +1023,6 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1005static void rs_close(struct tty_struct *tty, struct file * filp) 1023static void rs_close(struct tty_struct *tty, struct file * filp)
1006{ 1024{
1007 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; 1025 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
1008 struct tty_port *port = &info->tport;
1009 m68328_uart *uart = &uart_addr[info->line]; 1026 m68328_uart *uart = &uart_addr[info->line];
1010 unsigned long flags; 1027 unsigned long flags;
1011 1028
@@ -1019,7 +1036,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1019 return; 1036 return;
1020 } 1037 }
1021 1038
1022 if ((tty->count == 1) && (port->count != 1)) { 1039 if ((tty->count == 1) && (info->count != 1)) {
1023 /* 1040 /*
1024 * Uh, oh. tty->count is 1, which means that the tty 1041 * Uh, oh. tty->count is 1, which means that the tty
1025 * structure will be freed. Info->count should always 1042 * structure will be freed. Info->count should always
@@ -1028,26 +1045,26 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1028 * serial port won't be shutdown. 1045 * serial port won't be shutdown.
1029 */ 1046 */
1030 printk("rs_close: bad serial port count; tty->count is 1, " 1047 printk("rs_close: bad serial port count; tty->count is 1, "
1031 "port->count is %d\n", port->count); 1048 "info->count is %d\n", info->count);
1032 port->count = 1; 1049 info->count = 1;
1033 } 1050 }
1034 if (--port->count < 0) { 1051 if (--info->count < 0) {
1035 printk("rs_close: bad serial port count for ttyS%d: %d\n", 1052 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1036 info->line, port->count); 1053 info->line, info->count);
1037 port->count = 0; 1054 info->count = 0;
1038 } 1055 }
1039 if (port->count) { 1056 if (info->count) {
1040 local_irq_restore(flags); 1057 local_irq_restore(flags);
1041 return; 1058 return;
1042 } 1059 }
1043 port->flags |= ASYNC_CLOSING; 1060 info->flags |= S_CLOSING;
1044 /* 1061 /*
1045 * Now we wait for the transmit buffer to clear; and we notify 1062 * Now we wait for the transmit buffer to clear; and we notify
1046 * the line discipline to only process XON/XOFF characters. 1063 * the line discipline to only process XON/XOFF characters.
1047 */ 1064 */
1048 tty->closing = 1; 1065 tty->closing = 1;
1049 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1066 if (info->closing_wait != S_CLOSING_WAIT_NONE)
1050 tty_wait_until_sent(tty, port->closing_wait); 1067 tty_wait_until_sent(tty, info->closing_wait);
1051 /* 1068 /*
1052 * At this point we stop accepting input. To do this, we 1069 * At this point we stop accepting input. To do this, we
1053 * disable the receive line status interrupts, and tell the 1070 * disable the receive line status interrupts, and tell the
@@ -1058,30 +1075,32 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1058 uart->ustcnt &= ~USTCNT_RXEN; 1075 uart->ustcnt &= ~USTCNT_RXEN;
1059 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK); 1076 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);
1060 1077
1061 shutdown(info, tty); 1078 shutdown(info);
1062 rs_flush_buffer(tty); 1079 rs_flush_buffer(tty);
1063 1080
1064 tty_ldisc_flush(tty); 1081 tty_ldisc_flush(tty);
1065 tty->closing = 0; 1082 tty->closing = 0;
1066 tty_port_tty_set(&info->tport, NULL); 1083 info->event = 0;
1084 info->tty = NULL;
1067#warning "This is not and has never been valid so fix it" 1085#warning "This is not and has never been valid so fix it"
1068#if 0 1086#if 0
1069 if (tty->ldisc.num != ldiscs[N_TTY].num) { 1087 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1070 if (tty->ldisc.close) 1088 if (tty->ldisc.close)
1071 (tty->ldisc.close)(tty); 1089 (tty->ldisc.close)(tty);
1072 tty->ldisc = ldiscs[N_TTY]; 1090 tty->ldisc = ldiscs[N_TTY];
1073 tty->termios.c_line = N_TTY; 1091 tty->termios->c_line = N_TTY;
1074 if (tty->ldisc.open) 1092 if (tty->ldisc.open)
1075 (tty->ldisc.open)(tty); 1093 (tty->ldisc.open)(tty);
1076 } 1094 }
1077#endif 1095#endif
1078 if (port->blocked_open) { 1096 if (info->blocked_open) {
1079 if (port->close_delay) 1097 if (info->close_delay) {
1080 msleep_interruptible(jiffies_to_msecs(port->close_delay)); 1098 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1081 wake_up_interruptible(&port->open_wait); 1099 }
1100 wake_up_interruptible(&info->open_wait);
1082 } 1101 }
1083 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1102 info->flags &= ~(S_NORMAL_ACTIVE|S_CLOSING);
1084 wake_up_interruptible(&port->close_wait); 1103 wake_up_interruptible(&info->close_wait);
1085 local_irq_restore(flags); 1104 local_irq_restore(flags);
1086} 1105}
1087 1106
@@ -1096,14 +1115,107 @@ void rs_hangup(struct tty_struct *tty)
1096 return; 1115 return;
1097 1116
1098 rs_flush_buffer(tty); 1117 rs_flush_buffer(tty);
1099 shutdown(info, tty); 1118 shutdown(info);
1100 info->tport.count = 0; 1119 info->event = 0;
1101 info->tport.flags &= ~ASYNC_NORMAL_ACTIVE; 1120 info->count = 0;
1102 tty_port_tty_set(&info->tport, NULL); 1121 info->flags &= ~S_NORMAL_ACTIVE;
1103 wake_up_interruptible(&info->tport.open_wait); 1122 info->tty = NULL;
1123 wake_up_interruptible(&info->open_wait);
1104} 1124}
1105 1125
1106/* 1126/*
1127 * ------------------------------------------------------------
1128 * rs_open() and friends
1129 * ------------------------------------------------------------
1130 */
1131static int block_til_ready(struct tty_struct *tty, struct file * filp,
1132 struct m68k_serial *info)
1133{
1134 DECLARE_WAITQUEUE(wait, current);
1135 int retval;
1136 int do_clocal = 0;
1137
1138 /*
1139 * If the device is in the middle of being closed, then block
1140 * until it's done, and then try again.
1141 */
1142 if (info->flags & S_CLOSING) {
1143 interruptible_sleep_on(&info->close_wait);
1144#ifdef SERIAL_DO_RESTART
1145 if (info->flags & S_HUP_NOTIFY)
1146 return -EAGAIN;
1147 else
1148 return -ERESTARTSYS;
1149#else
1150 return -EAGAIN;
1151#endif
1152 }
1153
1154 /*
1155 * If non-blocking mode is set, or the port is not enabled,
1156 * then make the check up front and then exit.
1157 */
1158 if ((filp->f_flags & O_NONBLOCK) ||
1159 (tty->flags & (1 << TTY_IO_ERROR))) {
1160 info->flags |= S_NORMAL_ACTIVE;
1161 return 0;
1162 }
1163
1164 if (tty->termios->c_cflag & CLOCAL)
1165 do_clocal = 1;
1166
1167 /*
1168 * Block waiting for the carrier detect and the line to become
1169 * free (i.e., not in use by the callout). While we are in
1170 * this loop, info->count is dropped by one, so that
1171 * rs_close() knows when to free things. We restore it upon
1172 * exit, either normal or abnormal.
1173 */
1174 retval = 0;
1175 add_wait_queue(&info->open_wait, &wait);
1176
1177 info->count--;
1178 info->blocked_open++;
1179 while (1) {
1180 local_irq_disable();
1181 m68k_rtsdtr(info, 1);
1182 local_irq_enable();
1183 current->state = TASK_INTERRUPTIBLE;
1184 if (tty_hung_up_p(filp) ||
1185 !(info->flags & S_INITIALIZED)) {
1186#ifdef SERIAL_DO_RESTART
1187 if (info->flags & S_HUP_NOTIFY)
1188 retval = -EAGAIN;
1189 else
1190 retval = -ERESTARTSYS;
1191#else
1192 retval = -EAGAIN;
1193#endif
1194 break;
1195 }
1196 if (!(info->flags & S_CLOSING) && do_clocal)
1197 break;
1198 if (signal_pending(current)) {
1199 retval = -ERESTARTSYS;
1200 break;
1201 }
1202 tty_unlock();
1203 schedule();
1204 tty_lock();
1205 }
1206 current->state = TASK_RUNNING;
1207 remove_wait_queue(&info->open_wait, &wait);
1208 if (!tty_hung_up_p(filp))
1209 info->count++;
1210 info->blocked_open--;
1211
1212 if (retval)
1213 return retval;
1214 info->flags |= S_NORMAL_ACTIVE;
1215 return 0;
1216}
1217
1218/*
1107 * This routine is called whenever a serial port is opened. It 1219 * This routine is called whenever a serial port is opened. It
1108 * enables interrupts for a serial port, linking in its S structure into 1220 * enables interrupts for a serial port, linking in its S structure into
1109 * the IRQ chain. It also performs the serial-specific 1221 * the IRQ chain. It also performs the serial-specific
@@ -1112,25 +1224,30 @@ void rs_hangup(struct tty_struct *tty)
1112int rs_open(struct tty_struct *tty, struct file * filp) 1224int rs_open(struct tty_struct *tty, struct file * filp)
1113{ 1225{
1114 struct m68k_serial *info; 1226 struct m68k_serial *info;
1115 int retval; 1227 int retval, line;
1228
1229 line = tty->index;
1230
1231 if (line >= NR_PORTS || line < 0) /* we have exactly one */
1232 return -ENODEV;
1116 1233
1117 info = &m68k_soft[tty->index]; 1234 info = &m68k_soft[line];
1118 1235
1119 if (serial_paranoia_check(info, tty->name, "rs_open")) 1236 if (serial_paranoia_check(info, tty->name, "rs_open"))
1120 return -ENODEV; 1237 return -ENODEV;
1121 1238
1122 info->tport.count++; 1239 info->count++;
1123 tty->driver_data = info; 1240 tty->driver_data = info;
1124 tty_port_tty_set(&info->tport, tty); 1241 info->tty = tty;
1125 1242
1126 /* 1243 /*
1127 * Start up serial port 1244 * Start up serial port
1128 */ 1245 */
1129 retval = startup(info, tty); 1246 retval = startup(info);
1130 if (retval) 1247 if (retval)
1131 return retval; 1248 return retval;
1132 1249
1133 return tty_port_block_til_ready(&info->tport, tty, filp); 1250 return block_til_ready(tty, filp, info);
1134} 1251}
1135 1252
1136/* Finally, routines used to initialize the serial driver. */ 1253/* Finally, routines used to initialize the serial driver. */
@@ -1158,15 +1275,11 @@ static const struct tty_operations rs_ops = {
1158 .set_ldisc = rs_set_ldisc, 1275 .set_ldisc = rs_set_ldisc,
1159}; 1276};
1160 1277
1161static const struct tty_port_operations rs_port_ops = {
1162};
1163
1164/* rs_init inits the driver */ 1278/* rs_init inits the driver */
1165static int __init 1279static int __init
1166rs68328_init(void) 1280rs68328_init(void)
1167{ 1281{
1168 unsigned long flags; 1282 int flags, i;
1169 int i;
1170 struct m68k_serial *info; 1283 struct m68k_serial *info;
1171 1284
1172 serial_driver = alloc_tty_driver(NR_PORTS); 1285 serial_driver = alloc_tty_driver(NR_PORTS);
@@ -1189,18 +1302,31 @@ rs68328_init(void)
1189 serial_driver->flags = TTY_DRIVER_REAL_RAW; 1302 serial_driver->flags = TTY_DRIVER_REAL_RAW;
1190 tty_set_operations(serial_driver, &rs_ops); 1303 tty_set_operations(serial_driver, &rs_ops);
1191 1304
1305 if (tty_register_driver(serial_driver)) {
1306 put_tty_driver(serial_driver);
1307 printk(KERN_ERR "Couldn't register serial driver\n");
1308 return -ENOMEM;
1309 }
1310
1192 local_irq_save(flags); 1311 local_irq_save(flags);
1193 1312
1194 for(i=0;i<NR_PORTS;i++) { 1313 for(i=0;i<NR_PORTS;i++) {
1195 1314
1196 info = &m68k_soft[i]; 1315 info = &m68k_soft[i];
1197 tty_port_init(&info->tport);
1198 info->tport.ops = &rs_port_ops;
1199 info->magic = SERIAL_MAGIC; 1316 info->magic = SERIAL_MAGIC;
1200 info->port = (int) &uart_addr[i]; 1317 info->port = (int) &uart_addr[i];
1318 info->tty = NULL;
1201 info->irq = uart_irqs[i]; 1319 info->irq = uart_irqs[i];
1202 info->custom_divisor = 16; 1320 info->custom_divisor = 16;
1321 info->close_delay = 50;
1322 info->closing_wait = 3000;
1203 info->x_char = 0; 1323 info->x_char = 0;
1324 info->event = 0;
1325 info->count = 0;
1326 info->blocked_open = 0;
1327 INIT_WORK(&info->tqueue, do_softint);
1328 init_waitqueue_head(&info->open_wait);
1329 init_waitqueue_head(&info->close_wait);
1204 info->line = i; 1330 info->line = i;
1205 info->is_cons = 1; /* Means shortcuts work */ 1331 info->is_cons = 1; /* Means shortcuts work */
1206 1332
@@ -1215,22 +1341,11 @@ rs68328_init(void)
1215 1341
1216 if (request_irq(uart_irqs[i], 1342 if (request_irq(uart_irqs[i],
1217 rs_interrupt, 1343 rs_interrupt,
1218 0, 1344 IRQF_DISABLED,
1219 "M68328_UART", info)) 1345 "M68328_UART", info))
1220 panic("Unable to attach 68328 serial interrupt\n"); 1346 panic("Unable to attach 68328 serial interrupt\n");
1221
1222 tty_port_link_device(&info->tport, serial_driver, i);
1223 } 1347 }
1224 local_irq_restore(flags); 1348 local_irq_restore(flags);
1225
1226 if (tty_register_driver(serial_driver)) {
1227 put_tty_driver(serial_driver);
1228 for (i = 0; i < NR_PORTS; i++)
1229 tty_port_destroy(&m68k_soft[i].tport);
1230 printk(KERN_ERR "Couldn't register serial driver\n");
1231 return -ENOMEM;
1232 }
1233
1234 return 0; 1349 return 0;
1235} 1350}
1236 1351
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250.c
deleted file mode 100644
index d085e3a8ec0..00000000000
--- a/drivers/tty/serial/8250/8250.c
+++ /dev/null
@@ -1,3421 +0,0 @@
1/*
2 * Driver for 8250/16550-type serial ports
3 *
4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5 *
6 * Copyright (C) 2001 Russell King.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * A note about mapbase / membase
14 *
15 * mapbase is the physical address of the IO port.
16 * membase is an 'ioremapped' cookie.
17 */
18
19#if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
20#define SUPPORT_SYSRQ
21#endif
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/ioport.h>
26#include <linux/init.h>
27#include <linux/console.h>
28#include <linux/sysrq.h>
29#include <linux/delay.h>
30#include <linux/platform_device.h>
31#include <linux/tty.h>
32#include <linux/ratelimit.h>
33#include <linux/tty_flip.h>
34#include <linux/serial_reg.h>
35#include <linux/serial_core.h>
36#include <linux/serial.h>
37#include <linux/serial_8250.h>
38#include <linux/nmi.h>
39#include <linux/mutex.h>
40#include <linux/slab.h>
41#ifdef CONFIG_SPARC
42#include <linux/sunserialcore.h>
43#endif
44
45#include <asm/io.h>
46#include <asm/irq.h>
47
48#include "8250.h"
49
50/*
51 * Configuration:
52 * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option
53 * is unsafe when used on edge-triggered interrupts.
54 */
55static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
56
57static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS;
58
59static struct uart_driver serial8250_reg;
60
61static int serial_index(struct uart_port *port)
62{
63 return (serial8250_reg.minor - 64) + port->line;
64}
65
66static unsigned int skip_txen_test; /* force skip of txen test at init time */
67
68/*
69 * Debugging.
70 */
71#if 0
72#define DEBUG_AUTOCONF(fmt...) printk(fmt)
73#else
74#define DEBUG_AUTOCONF(fmt...) do { } while (0)
75#endif
76
77#if 0
78#define DEBUG_INTR(fmt...) printk(fmt)
79#else
80#define DEBUG_INTR(fmt...) do { } while (0)
81#endif
82
83#define PASS_LIMIT 512
84
85#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
86
87
88#ifdef CONFIG_SERIAL_8250_DETECT_IRQ
89#define CONFIG_SERIAL_DETECT_IRQ 1
90#endif
91#ifdef CONFIG_SERIAL_8250_MANY_PORTS
92#define CONFIG_SERIAL_MANY_PORTS 1
93#endif
94
95/*
96 * HUB6 is always on. This will be removed once the header
97 * files have been cleaned.
98 */
99#define CONFIG_HUB6 1
100
101#include <asm/serial.h>
102/*
103 * SERIAL_PORT_DFNS tells us about built-in ports that have no
104 * standard enumeration mechanism. Platforms that can find all
105 * serial ports via mechanisms like ACPI or PCI need not supply it.
106 */
107#ifndef SERIAL_PORT_DFNS
108#define SERIAL_PORT_DFNS
109#endif
110
111static const struct old_serial_port old_serial_port[] = {
112 SERIAL_PORT_DFNS /* defined in asm/serial.h */
113};
114
115#define UART_NR CONFIG_SERIAL_8250_NR_UARTS
116
117#ifdef CONFIG_SERIAL_8250_RSA
118
119#define PORT_RSA_MAX 4
120static unsigned long probe_rsa[PORT_RSA_MAX];
121static unsigned int probe_rsa_count;
122#endif /* CONFIG_SERIAL_8250_RSA */
123
124struct irq_info {
125 struct hlist_node node;
126 int irq;
127 spinlock_t lock; /* Protects list not the hash */
128 struct list_head *head;
129};
130
131#define NR_IRQ_HASH 32 /* Can be adjusted later */
132static struct hlist_head irq_lists[NR_IRQ_HASH];
133static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */
134
135/*
136 * Here we define the default xmit fifo size used for each type of UART.
137 */
138static const struct serial8250_config uart_config[] = {
139 [PORT_UNKNOWN] = {
140 .name = "unknown",
141 .fifo_size = 1,
142 .tx_loadsz = 1,
143 },
144 [PORT_8250] = {
145 .name = "8250",
146 .fifo_size = 1,
147 .tx_loadsz = 1,
148 },
149 [PORT_16450] = {
150 .name = "16450",
151 .fifo_size = 1,
152 .tx_loadsz = 1,
153 },
154 [PORT_16550] = {
155 .name = "16550",
156 .fifo_size = 1,
157 .tx_loadsz = 1,
158 },
159 [PORT_16550A] = {
160 .name = "16550A",
161 .fifo_size = 16,
162 .tx_loadsz = 16,
163 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
164 .flags = UART_CAP_FIFO,
165 },
166 [PORT_CIRRUS] = {
167 .name = "Cirrus",
168 .fifo_size = 1,
169 .tx_loadsz = 1,
170 },
171 [PORT_16650] = {
172 .name = "ST16650",
173 .fifo_size = 1,
174 .tx_loadsz = 1,
175 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
176 },
177 [PORT_16650V2] = {
178 .name = "ST16650V2",
179 .fifo_size = 32,
180 .tx_loadsz = 16,
181 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
182 UART_FCR_T_TRIG_00,
183 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
184 },
185 [PORT_16750] = {
186 .name = "TI16750",
187 .fifo_size = 64,
188 .tx_loadsz = 64,
189 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
190 UART_FCR7_64BYTE,
191 .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE,
192 },
193 [PORT_STARTECH] = {
194 .name = "Startech",
195 .fifo_size = 1,
196 .tx_loadsz = 1,
197 },
198 [PORT_16C950] = {
199 .name = "16C950/954",
200 .fifo_size = 128,
201 .tx_loadsz = 128,
202 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
203 /* UART_CAP_EFR breaks billionon CF bluetooth card. */
204 .flags = UART_CAP_FIFO | UART_CAP_SLEEP,
205 },
206 [PORT_16654] = {
207 .name = "ST16654",
208 .fifo_size = 64,
209 .tx_loadsz = 32,
210 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
211 UART_FCR_T_TRIG_10,
212 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
213 },
214 [PORT_16850] = {
215 .name = "XR16850",
216 .fifo_size = 128,
217 .tx_loadsz = 128,
218 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
219 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
220 },
221 [PORT_RSA] = {
222 .name = "RSA",
223 .fifo_size = 2048,
224 .tx_loadsz = 2048,
225 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11,
226 .flags = UART_CAP_FIFO,
227 },
228 [PORT_NS16550A] = {
229 .name = "NS16550A",
230 .fifo_size = 16,
231 .tx_loadsz = 16,
232 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
233 .flags = UART_CAP_FIFO | UART_NATSEMI,
234 },
235 [PORT_XSCALE] = {
236 .name = "XScale",
237 .fifo_size = 32,
238 .tx_loadsz = 32,
239 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
240 .flags = UART_CAP_FIFO | UART_CAP_UUE | UART_CAP_RTOIE,
241 },
242 [PORT_RM9000] = {
243 .name = "RM9000",
244 .fifo_size = 16,
245 .tx_loadsz = 16,
246 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
247 .flags = UART_CAP_FIFO,
248 },
249 [PORT_OCTEON] = {
250 .name = "OCTEON",
251 .fifo_size = 64,
252 .tx_loadsz = 64,
253 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
254 .flags = UART_CAP_FIFO,
255 },
256 [PORT_AR7] = {
257 .name = "AR7",
258 .fifo_size = 16,
259 .tx_loadsz = 16,
260 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
261 .flags = UART_CAP_FIFO | UART_CAP_AFE,
262 },
263 [PORT_U6_16550A] = {
264 .name = "U6_16550A",
265 .fifo_size = 64,
266 .tx_loadsz = 64,
267 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
268 .flags = UART_CAP_FIFO | UART_CAP_AFE,
269 },
270 [PORT_TEGRA] = {
271 .name = "Tegra",
272 .fifo_size = 32,
273 .tx_loadsz = 8,
274 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
275 UART_FCR_T_TRIG_01,
276 .flags = UART_CAP_FIFO | UART_CAP_RTOIE,
277 },
278 [PORT_XR17D15X] = {
279 .name = "XR17D15X",
280 .fifo_size = 64,
281 .tx_loadsz = 64,
282 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
283 .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR |
284 UART_CAP_SLEEP,
285 },
286 [PORT_XR17V35X] = {
287 .name = "XR17V35X",
288 .fifo_size = 256,
289 .tx_loadsz = 256,
290 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11 |
291 UART_FCR_T_TRIG_11,
292 .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR |
293 UART_CAP_SLEEP,
294 },
295 [PORT_LPC3220] = {
296 .name = "LPC3220",
297 .fifo_size = 64,
298 .tx_loadsz = 32,
299 .fcr = UART_FCR_DMA_SELECT | UART_FCR_ENABLE_FIFO |
300 UART_FCR_R_TRIG_00 | UART_FCR_T_TRIG_00,
301 .flags = UART_CAP_FIFO,
302 },
303 [PORT_8250_CIR] = {
304 .name = "CIR port"
305 }
306};
307
308/* Uart divisor latch read */
309static int default_serial_dl_read(struct uart_8250_port *up)
310{
311 return serial_in(up, UART_DLL) | serial_in(up, UART_DLM) << 8;
312}
313
314/* Uart divisor latch write */
315static void default_serial_dl_write(struct uart_8250_port *up, int value)
316{
317 serial_out(up, UART_DLL, value & 0xff);
318 serial_out(up, UART_DLM, value >> 8 & 0xff);
319}
320
321#ifdef CONFIG_MIPS_ALCHEMY
322
323/* Au1x00 UART hardware has a weird register layout */
324static const u8 au_io_in_map[] = {
325 [UART_RX] = 0,
326 [UART_IER] = 2,
327 [UART_IIR] = 3,
328 [UART_LCR] = 5,
329 [UART_MCR] = 6,
330 [UART_LSR] = 7,
331 [UART_MSR] = 8,
332};
333
334static const u8 au_io_out_map[] = {
335 [UART_TX] = 1,
336 [UART_IER] = 2,
337 [UART_FCR] = 4,
338 [UART_LCR] = 5,
339 [UART_MCR] = 6,
340};
341
342static unsigned int au_serial_in(struct uart_port *p, int offset)
343{
344 offset = au_io_in_map[offset] << p->regshift;
345 return __raw_readl(p->membase + offset);
346}
347
348static void au_serial_out(struct uart_port *p, int offset, int value)
349{
350 offset = au_io_out_map[offset] << p->regshift;
351 __raw_writel(value, p->membase + offset);
352}
353
354/* Au1x00 haven't got a standard divisor latch */
355static int au_serial_dl_read(struct uart_8250_port *up)
356{
357 return __raw_readl(up->port.membase + 0x28);
358}
359
360static void au_serial_dl_write(struct uart_8250_port *up, int value)
361{
362 __raw_writel(value, up->port.membase + 0x28);
363}
364
365#endif
366
367#ifdef CONFIG_SERIAL_8250_RM9K
368
369static const u8
370 regmap_in[8] = {
371 [UART_RX] = 0x00,
372 [UART_IER] = 0x0c,
373 [UART_IIR] = 0x14,
374 [UART_LCR] = 0x1c,
375 [UART_MCR] = 0x20,
376 [UART_LSR] = 0x24,
377 [UART_MSR] = 0x28,
378 [UART_SCR] = 0x2c
379 },
380 regmap_out[8] = {
381 [UART_TX] = 0x04,
382 [UART_IER] = 0x0c,
383 [UART_FCR] = 0x18,
384 [UART_LCR] = 0x1c,
385 [UART_MCR] = 0x20,
386 [UART_LSR] = 0x24,
387 [UART_MSR] = 0x28,
388 [UART_SCR] = 0x2c
389 };
390
391static unsigned int rm9k_serial_in(struct uart_port *p, int offset)
392{
393 offset = regmap_in[offset] << p->regshift;
394 return readl(p->membase + offset);
395}
396
397static void rm9k_serial_out(struct uart_port *p, int offset, int value)
398{
399 offset = regmap_out[offset] << p->regshift;
400 writel(value, p->membase + offset);
401}
402
403static int rm9k_serial_dl_read(struct uart_8250_port *up)
404{
405 return ((__raw_readl(up->port.membase + 0x10) << 8) |
406 (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff;
407}
408
409static void rm9k_serial_dl_write(struct uart_8250_port *up, int value)
410{
411 __raw_writel(value, up->port.membase + 0x08);
412 __raw_writel(value >> 8, up->port.membase + 0x10);
413}
414
415#endif
416
417static unsigned int hub6_serial_in(struct uart_port *p, int offset)
418{
419 offset = offset << p->regshift;
420 outb(p->hub6 - 1 + offset, p->iobase);
421 return inb(p->iobase + 1);
422}
423
424static void hub6_serial_out(struct uart_port *p, int offset, int value)
425{
426 offset = offset << p->regshift;
427 outb(p->hub6 - 1 + offset, p->iobase);
428 outb(value, p->iobase + 1);
429}
430
431static unsigned int mem_serial_in(struct uart_port *p, int offset)
432{
433 offset = offset << p->regshift;
434 return readb(p->membase + offset);
435}
436
437static void mem_serial_out(struct uart_port *p, int offset, int value)
438{
439 offset = offset << p->regshift;
440 writeb(value, p->membase + offset);
441}
442
443static void mem32_serial_out(struct uart_port *p, int offset, int value)
444{
445 offset = offset << p->regshift;
446 writel(value, p->membase + offset);
447}
448
449static unsigned int mem32_serial_in(struct uart_port *p, int offset)
450{
451 offset = offset << p->regshift;
452 return readl(p->membase + offset);
453}
454
455static unsigned int io_serial_in(struct uart_port *p, int offset)
456{
457 offset = offset << p->regshift;
458 return inb(p->iobase + offset);
459}
460
461static void io_serial_out(struct uart_port *p, int offset, int value)
462{
463 offset = offset << p->regshift;
464 outb(value, p->iobase + offset);
465}
466
467static int serial8250_default_handle_irq(struct uart_port *port);
468static int exar_handle_irq(struct uart_port *port);
469
470static void set_io_from_upio(struct uart_port *p)
471{
472 struct uart_8250_port *up =
473 container_of(p, struct uart_8250_port, port);
474
475 up->dl_read = default_serial_dl_read;
476 up->dl_write = default_serial_dl_write;
477
478 switch (p->iotype) {
479 case UPIO_HUB6:
480 p->serial_in = hub6_serial_in;
481 p->serial_out = hub6_serial_out;
482 break;
483
484 case UPIO_MEM:
485 p->serial_in = mem_serial_in;
486 p->serial_out = mem_serial_out;
487 break;
488
489 case UPIO_MEM32:
490 p->serial_in = mem32_serial_in;
491 p->serial_out = mem32_serial_out;
492 break;
493
494#ifdef CONFIG_SERIAL_8250_RM9K
495 case UPIO_RM9000:
496 p->serial_in = rm9k_serial_in;
497 p->serial_out = rm9k_serial_out;
498 up->dl_read = rm9k_serial_dl_read;
499 up->dl_write = rm9k_serial_dl_write;
500 break;
501#endif
502
503#ifdef CONFIG_MIPS_ALCHEMY
504 case UPIO_AU:
505 p->serial_in = au_serial_in;
506 p->serial_out = au_serial_out;
507 up->dl_read = au_serial_dl_read;
508 up->dl_write = au_serial_dl_write;
509 break;
510#endif
511
512 default:
513 p->serial_in = io_serial_in;
514 p->serial_out = io_serial_out;
515 break;
516 }
517 /* Remember loaded iotype */
518 up->cur_iotype = p->iotype;
519 p->handle_irq = serial8250_default_handle_irq;
520}
521
522static void
523serial_port_out_sync(struct uart_port *p, int offset, int value)
524{
525 switch (p->iotype) {
526 case UPIO_MEM:
527 case UPIO_MEM32:
528 case UPIO_AU:
529 p->serial_out(p, offset, value);
530 p->serial_in(p, UART_LCR); /* safe, no side-effects */
531 break;
532 default:
533 p->serial_out(p, offset, value);
534 }
535}
536
537/*
538 * For the 16C950
539 */
540static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
541{
542 serial_out(up, UART_SCR, offset);
543 serial_out(up, UART_ICR, value);
544}
545
546static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
547{
548 unsigned int value;
549
550 serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
551 serial_out(up, UART_SCR, offset);
552 value = serial_in(up, UART_ICR);
553 serial_icr_write(up, UART_ACR, up->acr);
554
555 return value;
556}
557
558/*
559 * FIFO support.
560 */
561static void serial8250_clear_fifos(struct uart_8250_port *p)
562{
563 if (p->capabilities & UART_CAP_FIFO) {
564 serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO);
565 serial_out(p, UART_FCR, UART_FCR_ENABLE_FIFO |
566 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
567 serial_out(p, UART_FCR, 0);
568 }
569}
570
571void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p)
572{
573 unsigned char fcr;
574
575 serial8250_clear_fifos(p);
576 fcr = uart_config[p->port.type].fcr;
577 serial_out(p, UART_FCR, fcr);
578}
579EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos);
580
581/*
582 * IER sleep support. UARTs which have EFRs need the "extended
583 * capability" bit enabled. Note that on XR16C850s, we need to
584 * reset LCR to write to IER.
585 */
586static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
587{
588 /*
589 * Exar UARTs have a SLEEP register that enables or disables
590 * each UART to enter sleep mode separately. On the XR17V35x the
591 * register is accessible to each UART at the UART_EXAR_SLEEP
592 * offset but the UART channel may only write to the corresponding
593 * bit.
594 */
595 if ((p->port.type == PORT_XR17V35X) ||
596 (p->port.type == PORT_XR17D15X)) {
597 serial_out(p, UART_EXAR_SLEEP, 0xff);
598 return;
599 }
600
601 if (p->capabilities & UART_CAP_SLEEP) {
602 if (p->capabilities & UART_CAP_EFR) {
603 serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B);
604 serial_out(p, UART_EFR, UART_EFR_ECB);
605 serial_out(p, UART_LCR, 0);
606 }
607 serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0);
608 if (p->capabilities & UART_CAP_EFR) {
609 serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B);
610 serial_out(p, UART_EFR, 0);
611 serial_out(p, UART_LCR, 0);
612 }
613 }
614}
615
616#ifdef CONFIG_SERIAL_8250_RSA
617/*
618 * Attempts to turn on the RSA FIFO. Returns zero on failure.
619 * We set the port uart clock rate if we succeed.
620 */
621static int __enable_rsa(struct uart_8250_port *up)
622{
623 unsigned char mode;
624 int result;
625
626 mode = serial_in(up, UART_RSA_MSR);
627 result = mode & UART_RSA_MSR_FIFO;
628
629 if (!result) {
630 serial_out(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
631 mode = serial_in(up, UART_RSA_MSR);
632 result = mode & UART_RSA_MSR_FIFO;
633 }
634
635 if (result)
636 up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
637
638 return result;
639}
640
641static void enable_rsa(struct uart_8250_port *up)
642{
643 if (up->port.type == PORT_RSA) {
644 if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
645 spin_lock_irq(&up->port.lock);
646 __enable_rsa(up);
647 spin_unlock_irq(&up->port.lock);
648 }
649 if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
650 serial_out(up, UART_RSA_FRR, 0);
651 }
652}
653
654/*
655 * Attempts to turn off the RSA FIFO. Returns zero on failure.
656 * It is unknown why interrupts were disabled in here. However,
657 * the caller is expected to preserve this behaviour by grabbing
658 * the spinlock before calling this function.
659 */
660static void disable_rsa(struct uart_8250_port *up)
661{
662 unsigned char mode;
663 int result;
664
665 if (up->port.type == PORT_RSA &&
666 up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
667 spin_lock_irq(&up->port.lock);
668
669 mode = serial_in(up, UART_RSA_MSR);
670 result = !(mode & UART_RSA_MSR_FIFO);
671
672 if (!result) {
673 serial_out(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
674 mode = serial_in(up, UART_RSA_MSR);
675 result = !(mode & UART_RSA_MSR_FIFO);
676 }
677
678 if (result)
679 up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
680 spin_unlock_irq(&up->port.lock);
681 }
682}
683#endif /* CONFIG_SERIAL_8250_RSA */
684
685/*
686 * This is a quickie test to see how big the FIFO is.
687 * It doesn't work at all the time, more's the pity.
688 */
689static int size_fifo(struct uart_8250_port *up)
690{
691 unsigned char old_fcr, old_mcr, old_lcr;
692 unsigned short old_dl;
693 int count;
694
695 old_lcr = serial_in(up, UART_LCR);
696 serial_out(up, UART_LCR, 0);
697 old_fcr = serial_in(up, UART_FCR);
698 old_mcr = serial_in(up, UART_MCR);
699 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
700 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
701 serial_out(up, UART_MCR, UART_MCR_LOOP);
702 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
703 old_dl = serial_dl_read(up);
704 serial_dl_write(up, 0x0001);
705 serial_out(up, UART_LCR, 0x03);
706 for (count = 0; count < 256; count++)
707 serial_out(up, UART_TX, count);
708 mdelay(20);/* FIXME - schedule_timeout */
709 for (count = 0; (serial_in(up, UART_LSR) & UART_LSR_DR) &&
710 (count < 256); count++)
711 serial_in(up, UART_RX);
712 serial_out(up, UART_FCR, old_fcr);
713 serial_out(up, UART_MCR, old_mcr);
714 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
715 serial_dl_write(up, old_dl);
716 serial_out(up, UART_LCR, old_lcr);
717
718 return count;
719}
720
721/*
722 * Read UART ID using the divisor method - set DLL and DLM to zero
723 * and the revision will be in DLL and device type in DLM. We
724 * preserve the device state across this.
725 */
726static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p)
727{
728 unsigned char old_dll, old_dlm, old_lcr;
729 unsigned int id;
730
731 old_lcr = serial_in(p, UART_LCR);
732 serial_out(p, UART_LCR, UART_LCR_CONF_MODE_A);
733
734 old_dll = serial_in(p, UART_DLL);
735 old_dlm = serial_in(p, UART_DLM);
736
737 serial_out(p, UART_DLL, 0);
738 serial_out(p, UART_DLM, 0);
739
740 id = serial_in(p, UART_DLL) | serial_in(p, UART_DLM) << 8;
741
742 serial_out(p, UART_DLL, old_dll);
743 serial_out(p, UART_DLM, old_dlm);
744 serial_out(p, UART_LCR, old_lcr);
745
746 return id;
747}
748
749/*
750 * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
751 * When this function is called we know it is at least a StarTech
752 * 16650 V2, but it might be one of several StarTech UARTs, or one of
753 * its clones. (We treat the broken original StarTech 16650 V1 as a
754 * 16550, and why not? Startech doesn't seem to even acknowledge its
755 * existence.)
756 *
757 * What evil have men's minds wrought...
758 */
759static void autoconfig_has_efr(struct uart_8250_port *up)
760{
761 unsigned int id1, id2, id3, rev;
762
763 /*
764 * Everything with an EFR has SLEEP
765 */
766 up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
767
768 /*
769 * First we check to see if it's an Oxford Semiconductor UART.
770 *
771 * If we have to do this here because some non-National
772 * Semiconductor clone chips lock up if you try writing to the
773 * LSR register (which serial_icr_read does)
774 */
775
776 /*
777 * Check for Oxford Semiconductor 16C950.
778 *
779 * EFR [4] must be set else this test fails.
780 *
781 * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca)
782 * claims that it's needed for 952 dual UART's (which are not
783 * recommended for new designs).
784 */
785 up->acr = 0;
786 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
787 serial_out(up, UART_EFR, UART_EFR_ECB);
788 serial_out(up, UART_LCR, 0x00);
789 id1 = serial_icr_read(up, UART_ID1);
790 id2 = serial_icr_read(up, UART_ID2);
791 id3 = serial_icr_read(up, UART_ID3);
792 rev = serial_icr_read(up, UART_REV);
793
794 DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev);
795
796 if (id1 == 0x16 && id2 == 0xC9 &&
797 (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) {
798 up->port.type = PORT_16C950;
799
800 /*
801 * Enable work around for the Oxford Semiconductor 952 rev B
802 * chip which causes it to seriously miscalculate baud rates
803 * when DLL is 0.
804 */
805 if (id3 == 0x52 && rev == 0x01)
806 up->bugs |= UART_BUG_QUOT;
807 return;
808 }
809
810 /*
811 * We check for a XR16C850 by setting DLL and DLM to 0, and then
812 * reading back DLL and DLM. The chip type depends on the DLM
813 * value read back:
814 * 0x10 - XR16C850 and the DLL contains the chip revision.
815 * 0x12 - XR16C2850.
816 * 0x14 - XR16C854.
817 */
818 id1 = autoconfig_read_divisor_id(up);
819 DEBUG_AUTOCONF("850id=%04x ", id1);
820
821 id2 = id1 >> 8;
822 if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) {
823 up->port.type = PORT_16850;
824 return;
825 }
826
827 /*
828 * It wasn't an XR16C850.
829 *
830 * We distinguish between the '654 and the '650 by counting
831 * how many bytes are in the FIFO. I'm using this for now,
832 * since that's the technique that was sent to me in the
833 * serial driver update, but I'm not convinced this works.
834 * I've had problems doing this in the past. -TYT
835 */
836 if (size_fifo(up) == 64)
837 up->port.type = PORT_16654;
838 else
839 up->port.type = PORT_16650V2;
840}
841
842/*
843 * We detected a chip without a FIFO. Only two fall into
844 * this category - the original 8250 and the 16450. The
845 * 16450 has a scratch register (accessible with LCR=0)
846 */
847static void autoconfig_8250(struct uart_8250_port *up)
848{
849 unsigned char scratch, status1, status2;
850
851 up->port.type = PORT_8250;
852
853 scratch = serial_in(up, UART_SCR);
854 serial_out(up, UART_SCR, 0xa5);
855 status1 = serial_in(up, UART_SCR);
856 serial_out(up, UART_SCR, 0x5a);
857 status2 = serial_in(up, UART_SCR);
858 serial_out(up, UART_SCR, scratch);
859
860 if (status1 == 0xa5 && status2 == 0x5a)
861 up->port.type = PORT_16450;
862}
863
864static int broken_efr(struct uart_8250_port *up)
865{
866 /*
867 * Exar ST16C2550 "A2" devices incorrectly detect as
868 * having an EFR, and report an ID of 0x0201. See
869 * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html
870 */
871 if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16)
872 return 1;
873
874 return 0;
875}
876
877static inline int ns16550a_goto_highspeed(struct uart_8250_port *up)
878{
879 unsigned char status;
880
881 status = serial_in(up, 0x04); /* EXCR2 */
882#define PRESL(x) ((x) & 0x30)
883 if (PRESL(status) == 0x10) {
884 /* already in high speed mode */
885 return 0;
886 } else {
887 status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
888 status |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
889 serial_out(up, 0x04, status);
890 }
891 return 1;
892}
893
894/*
895 * We know that the chip has FIFOs. Does it have an EFR? The
896 * EFR is located in the same register position as the IIR and
897 * we know the top two bits of the IIR are currently set. The
898 * EFR should contain zero. Try to read the EFR.
899 */
900static void autoconfig_16550a(struct uart_8250_port *up)
901{
902 unsigned char status1, status2;
903 unsigned int iersave;
904
905 up->port.type = PORT_16550A;
906 up->capabilities |= UART_CAP_FIFO;
907
908 /*
909 * XR17V35x UARTs have an extra divisor register, DLD
910 * that gets enabled with when DLAB is set which will
911 * cause the device to incorrectly match and assign
912 * port type to PORT_16650. The EFR for this UART is
913 * found at offset 0x09. Instead check the Deice ID (DVID)
914 * register for a 2, 4 or 8 port UART.
915 */
916 if (up->port.flags & UPF_EXAR_EFR) {
917 status1 = serial_in(up, UART_EXAR_DVID);
918 if (status1 == 0x82 || status1 == 0x84 || status1 == 0x88) {
919 DEBUG_AUTOCONF("Exar XR17V35x ");
920 up->port.type = PORT_XR17V35X;
921 up->capabilities |= UART_CAP_AFE | UART_CAP_EFR |
922 UART_CAP_SLEEP;
923
924 return;
925 }
926
927 }
928
929 /*
930 * Check for presence of the EFR when DLAB is set.
931 * Only ST16C650V1 UARTs pass this test.
932 */
933 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
934 if (serial_in(up, UART_EFR) == 0) {
935 serial_out(up, UART_EFR, 0xA8);
936 if (serial_in(up, UART_EFR) != 0) {
937 DEBUG_AUTOCONF("EFRv1 ");
938 up->port.type = PORT_16650;
939 up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
940 } else {
941 DEBUG_AUTOCONF("Motorola 8xxx DUART ");
942 }
943 serial_out(up, UART_EFR, 0);
944 return;
945 }
946
947 /*
948 * Maybe it requires 0xbf to be written to the LCR.
949 * (other ST16C650V2 UARTs, TI16C752A, etc)
950 */
951 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
952 if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) {
953 DEBUG_AUTOCONF("EFRv2 ");
954 autoconfig_has_efr(up);
955 return;
956 }
957
958 /*
959 * Check for a National Semiconductor SuperIO chip.
960 * Attempt to switch to bank 2, read the value of the LOOP bit
961 * from EXCR1. Switch back to bank 0, change it in MCR. Then
962 * switch back to bank 2, read it from EXCR1 again and check
963 * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2
964 */
965 serial_out(up, UART_LCR, 0);
966 status1 = serial_in(up, UART_MCR);
967 serial_out(up, UART_LCR, 0xE0);
968 status2 = serial_in(up, 0x02); /* EXCR1 */
969
970 if (!((status2 ^ status1) & UART_MCR_LOOP)) {
971 serial_out(up, UART_LCR, 0);
972 serial_out(up, UART_MCR, status1 ^ UART_MCR_LOOP);
973 serial_out(up, UART_LCR, 0xE0);
974 status2 = serial_in(up, 0x02); /* EXCR1 */
975 serial_out(up, UART_LCR, 0);
976 serial_out(up, UART_MCR, status1);
977
978 if ((status2 ^ status1) & UART_MCR_LOOP) {
979 unsigned short quot;
980
981 serial_out(up, UART_LCR, 0xE0);
982
983 quot = serial_dl_read(up);
984 quot <<= 3;
985
986 if (ns16550a_goto_highspeed(up))
987 serial_dl_write(up, quot);
988
989 serial_out(up, UART_LCR, 0);
990
991 up->port.uartclk = 921600*16;
992 up->port.type = PORT_NS16550A;
993 up->capabilities |= UART_NATSEMI;
994 return;
995 }
996 }
997
998 /*
999 * No EFR. Try to detect a TI16750, which only sets bit 5 of
1000 * the IIR when 64 byte FIFO mode is enabled when DLAB is set.
1001 * Try setting it with and without DLAB set. Cheap clones
1002 * set bit 5 without DLAB set.
1003 */
1004 serial_out(up, UART_LCR, 0);
1005 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
1006 status1 = serial_in(up, UART_IIR) >> 5;
1007 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
1008 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
1009 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
1010 status2 = serial_in(up, UART_IIR) >> 5;
1011 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
1012 serial_out(up, UART_LCR, 0);
1013
1014 DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);
1015
1016 if (status1 == 6 && status2 == 7) {
1017 up->port.type = PORT_16750;
1018 up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP;
1019 return;
1020 }
1021
1022 /*
1023 * Try writing and reading the UART_IER_UUE bit (b6).
1024 * If it works, this is probably one of the Xscale platform's
1025 * internal UARTs.
1026 * We're going to explicitly set the UUE bit to 0 before
1027 * trying to write and read a 1 just to make sure it's not
1028 * already a 1 and maybe locked there before we even start start.
1029 */
1030 iersave = serial_in(up, UART_IER);
1031 serial_out(up, UART_IER, iersave & ~UART_IER_UUE);
1032 if (!(serial_in(up, UART_IER) & UART_IER_UUE)) {
1033 /*
1034 * OK it's in a known zero state, try writing and reading
1035 * without disturbing the current state of the other bits.
1036 */
1037 serial_out(up, UART_IER, iersave | UART_IER_UUE);
1038 if (serial_in(up, UART_IER) & UART_IER_UUE) {
1039 /*
1040 * It's an Xscale.
1041 * We'll leave the UART_IER_UUE bit set to 1 (enabled).
1042 */
1043 DEBUG_AUTOCONF("Xscale ");
1044 up->port.type = PORT_XSCALE;
1045 up->capabilities |= UART_CAP_UUE | UART_CAP_RTOIE;
1046 return;
1047 }
1048 } else {
1049 /*
1050 * If we got here we couldn't force the IER_UUE bit to 0.
1051 * Log it and continue.
1052 */
1053 DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
1054 }
1055 serial_out(up, UART_IER, iersave);
1056
1057 /*
1058 * Exar uarts have EFR in a weird location
1059 */
1060 if (up->port.flags & UPF_EXAR_EFR) {
1061 DEBUG_AUTOCONF("Exar XR17D15x ");
1062 up->port.type = PORT_XR17D15X;
1063 up->capabilities |= UART_CAP_AFE | UART_CAP_EFR |
1064 UART_CAP_SLEEP;
1065
1066 return;
1067 }
1068
1069 /*
1070 * We distinguish between 16550A and U6 16550A by counting
1071 * how many bytes are in the FIFO.
1072 */
1073 if (up->port.type == PORT_16550A && size_fifo(up) == 64) {
1074 up->port.type = PORT_U6_16550A;
1075 up->capabilities |= UART_CAP_AFE;
1076 }
1077}
1078
1079/*
1080 * This routine is called by rs_init() to initialize a specific serial
1081 * port. It determines what type of UART chip this serial port is
1082 * using: 8250, 16450, 16550, 16550A. The important question is
1083 * whether or not this UART is a 16550A or not, since this will
1084 * determine whether or not we can use its FIFO features or not.
1085 */
1086static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
1087{
1088 unsigned char status1, scratch, scratch2, scratch3;
1089 unsigned char save_lcr, save_mcr;
1090 struct uart_port *port = &up->port;
1091 unsigned long flags;
1092 unsigned int old_capabilities;
1093
1094 if (!port->iobase && !port->mapbase && !port->membase)
1095 return;
1096
1097 DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ",
1098 serial_index(port), port->iobase, port->membase);
1099
1100 /*
1101 * We really do need global IRQs disabled here - we're going to
1102 * be frobbing the chips IRQ enable register to see if it exists.
1103 */
1104 spin_lock_irqsave(&port->lock, flags);
1105
1106 up->capabilities = 0;
1107 up->bugs = 0;
1108
1109 if (!(port->flags & UPF_BUGGY_UART)) {
1110 /*
1111 * Do a simple existence test first; if we fail this,
1112 * there's no point trying anything else.
1113 *
1114 * 0x80 is used as a nonsense port to prevent against
1115 * false positives due to ISA bus float. The
1116 * assumption is that 0x80 is a non-existent port;
1117 * which should be safe since include/asm/io.h also
1118 * makes this assumption.
1119 *
1120 * Note: this is safe as long as MCR bit 4 is clear
1121 * and the device is in "PC" mode.
1122 */
1123 scratch = serial_in(up, UART_IER);
1124 serial_out(up, UART_IER, 0);
1125#ifdef __i386__
1126 outb(0xff, 0x080);
1127#endif
1128 /*
1129 * Mask out IER[7:4] bits for test as some UARTs (e.g. TL
1130 * 16C754B) allow only to modify them if an EFR bit is set.
1131 */
1132 scratch2 = serial_in(up, UART_IER) & 0x0f;
1133 serial_out(up, UART_IER, 0x0F);
1134#ifdef __i386__
1135 outb(0, 0x080);
1136#endif
1137 scratch3 = serial_in(up, UART_IER) & 0x0f;
1138 serial_out(up, UART_IER, scratch);
1139 if (scratch2 != 0 || scratch3 != 0x0F) {
1140 /*
1141 * We failed; there's nothing here
1142 */
1143 spin_unlock_irqrestore(&port->lock, flags);
1144 DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
1145 scratch2, scratch3);
1146 goto out;
1147 }
1148 }
1149
1150 save_mcr = serial_in(up, UART_MCR);
1151 save_lcr = serial_in(up, UART_LCR);
1152
1153 /*
1154 * Check to see if a UART is really there. Certain broken
1155 * internal modems based on the Rockwell chipset fail this
1156 * test, because they apparently don't implement the loopback
1157 * test mode. So this test is skipped on the COM 1 through
1158 * COM 4 ports. This *should* be safe, since no board
1159 * manufacturer would be stupid enough to design a board
1160 * that conflicts with COM 1-4 --- we hope!
1161 */
1162 if (!(port->flags & UPF_SKIP_TEST)) {
1163 serial_out(up, UART_MCR, UART_MCR_LOOP | 0x0A);
1164 status1 = serial_in(up, UART_MSR) & 0xF0;
1165 serial_out(up, UART_MCR, save_mcr);
1166 if (status1 != 0x90) {
1167 spin_unlock_irqrestore(&port->lock, flags);
1168 DEBUG_AUTOCONF("LOOP test failed (%02x) ",
1169 status1);
1170 goto out;
1171 }
1172 }
1173
1174 /*
1175 * We're pretty sure there's a port here. Lets find out what
1176 * type of port it is. The IIR top two bits allows us to find
1177 * out if it's 8250 or 16450, 16550, 16550A or later. This
1178 * determines what we test for next.
1179 *
1180 * We also initialise the EFR (if any) to zero for later. The
1181 * EFR occupies the same register location as the FCR and IIR.
1182 */
1183 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
1184 serial_out(up, UART_EFR, 0);
1185 serial_out(up, UART_LCR, 0);
1186
1187 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
1188 scratch = serial_in(up, UART_IIR) >> 6;
1189
1190 switch (scratch) {
1191 case 0:
1192 autoconfig_8250(up);
1193 break;
1194 case 1:
1195 port->type = PORT_UNKNOWN;
1196 break;
1197 case 2:
1198 port->type = PORT_16550;
1199 break;
1200 case 3:
1201 autoconfig_16550a(up);
1202 break;
1203 }
1204
1205#ifdef CONFIG_SERIAL_8250_RSA
1206 /*
1207 * Only probe for RSA ports if we got the region.
1208 */
1209 if (port->type == PORT_16550A && probeflags & PROBE_RSA) {
1210 int i;
1211
1212 for (i = 0 ; i < probe_rsa_count; ++i) {
1213 if (probe_rsa[i] == port->iobase && __enable_rsa(up)) {
1214 port->type = PORT_RSA;
1215 break;
1216 }
1217 }
1218 }
1219#endif
1220
1221 serial_out(up, UART_LCR, save_lcr);
1222
1223 port->fifosize = uart_config[up->port.type].fifo_size;
1224 old_capabilities = up->capabilities;
1225 up->capabilities = uart_config[port->type].flags;
1226 up->tx_loadsz = uart_config[port->type].tx_loadsz;
1227
1228 if (port->type == PORT_UNKNOWN)
1229 goto out_lock;
1230
1231 /*
1232 * Reset the UART.
1233 */
1234#ifdef CONFIG_SERIAL_8250_RSA
1235 if (port->type == PORT_RSA)
1236 serial_out(up, UART_RSA_FRR, 0);
1237#endif
1238 serial_out(up, UART_MCR, save_mcr);
1239 serial8250_clear_fifos(up);
1240 serial_in(up, UART_RX);
1241 if (up->capabilities & UART_CAP_UUE)
1242 serial_out(up, UART_IER, UART_IER_UUE);
1243 else
1244 serial_out(up, UART_IER, 0);
1245
1246out_lock:
1247 spin_unlock_irqrestore(&port->lock, flags);
1248 if (up->capabilities != old_capabilities) {
1249 printk(KERN_WARNING
1250 "ttyS%d: detected caps %08x should be %08x\n",
1251 serial_index(port), old_capabilities,
1252 up->capabilities);
1253 }
1254out:
1255 DEBUG_AUTOCONF("iir=%d ", scratch);
1256 DEBUG_AUTOCONF("type=%s\n", uart_config[port->type].name);
1257}
1258
1259static void autoconfig_irq(struct uart_8250_port *up)
1260{
1261 struct uart_port *port = &up->port;
1262 unsigned char save_mcr, save_ier;
1263 unsigned char save_ICP = 0;
1264 unsigned int ICP = 0;
1265 unsigned long irqs;
1266 int irq;
1267
1268 if (port->flags & UPF_FOURPORT) {
1269 ICP = (port->iobase & 0xfe0) | 0x1f;
1270 save_ICP = inb_p(ICP);
1271 outb_p(0x80, ICP);
1272 inb_p(ICP);
1273 }
1274
1275 /* forget possible initially masked and pending IRQ */
1276 probe_irq_off(probe_irq_on());
1277 save_mcr = serial_in(up, UART_MCR);
1278 save_ier = serial_in(up, UART_IER);
1279 serial_out(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);
1280
1281 irqs = probe_irq_on();
1282 serial_out(up, UART_MCR, 0);
1283 udelay(10);
1284 if (port->flags & UPF_FOURPORT) {
1285 serial_out(up, UART_MCR,
1286 UART_MCR_DTR | UART_MCR_RTS);
1287 } else {
1288 serial_out(up, UART_MCR,
1289 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
1290 }
1291 serial_out(up, UART_IER, 0x0f); /* enable all intrs */
1292 serial_in(up, UART_LSR);
1293 serial_in(up, UART_RX);
1294 serial_in(up, UART_IIR);
1295 serial_in(up, UART_MSR);
1296 serial_out(up, UART_TX, 0xFF);
1297 udelay(20);
1298 irq = probe_irq_off(irqs);
1299
1300 serial_out(up, UART_MCR, save_mcr);
1301 serial_out(up, UART_IER, save_ier);
1302
1303 if (port->flags & UPF_FOURPORT)
1304 outb_p(save_ICP, ICP);
1305
1306 port->irq = (irq > 0) ? irq : 0;
1307}
1308
1309static inline void __stop_tx(struct uart_8250_port *p)
1310{
1311 if (p->ier & UART_IER_THRI) {
1312 p->ier &= ~UART_IER_THRI;
1313 serial_out(p, UART_IER, p->ier);
1314 }
1315}
1316
1317static void serial8250_stop_tx(struct uart_port *port)
1318{
1319 struct uart_8250_port *up =
1320 container_of(port, struct uart_8250_port, port);
1321
1322 __stop_tx(up);
1323
1324 /*
1325 * We really want to stop the transmitter from sending.
1326 */
1327 if (port->type == PORT_16C950) {
1328 up->acr |= UART_ACR_TXDIS;
1329 serial_icr_write(up, UART_ACR, up->acr);
1330 }
1331}
1332
1333static void serial8250_start_tx(struct uart_port *port)
1334{
1335 struct uart_8250_port *up =
1336 container_of(port, struct uart_8250_port, port);
1337
1338 if (!(up->ier & UART_IER_THRI)) {
1339 up->ier |= UART_IER_THRI;
1340 serial_port_out(port, UART_IER, up->ier);
1341
1342 if (up->bugs & UART_BUG_TXEN) {
1343 unsigned char lsr;
1344 lsr = serial_in(up, UART_LSR);
1345 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
1346 if ((port->type == PORT_RM9000) ?
1347 (lsr & UART_LSR_THRE) :
1348 (lsr & UART_LSR_TEMT))
1349 serial8250_tx_chars(up);
1350 }
1351 }
1352
1353 /*
1354 * Re-enable the transmitter if we disabled it.
1355 */
1356 if (port->type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
1357 up->acr &= ~UART_ACR_TXDIS;
1358 serial_icr_write(up, UART_ACR, up->acr);
1359 }
1360}
1361
1362static void serial8250_stop_rx(struct uart_port *port)
1363{
1364 struct uart_8250_port *up =
1365 container_of(port, struct uart_8250_port, port);
1366
1367 up->ier &= ~UART_IER_RLSI;
1368 up->port.read_status_mask &= ~UART_LSR_DR;
1369 serial_port_out(port, UART_IER, up->ier);
1370}
1371
1372static void serial8250_enable_ms(struct uart_port *port)
1373{
1374 struct uart_8250_port *up =
1375 container_of(port, struct uart_8250_port, port);
1376
1377 /* no MSR capabilities */
1378 if (up->bugs & UART_BUG_NOMSR)
1379 return;
1380
1381 up->ier |= UART_IER_MSI;
1382 serial_port_out(port, UART_IER, up->ier);
1383}
1384
1385/*
1386 * serial8250_rx_chars: processes according to the passed in LSR
1387 * value, and returns the remaining LSR bits not handled
1388 * by this Rx routine.
1389 */
1390unsigned char
1391serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr)
1392{
1393 struct uart_port *port = &up->port;
1394 struct tty_struct *tty = port->state->port.tty;
1395 unsigned char ch;
1396 int max_count = 256;
1397 char flag;
1398
1399 do {
1400 if (likely(lsr & UART_LSR_DR))
1401 ch = serial_in(up, UART_RX);
1402 else
1403 /*
1404 * Intel 82571 has a Serial Over Lan device that will
1405 * set UART_LSR_BI without setting UART_LSR_DR when
1406 * it receives a break. To avoid reading from the
1407 * receive buffer without UART_LSR_DR bit set, we
1408 * just force the read character to be 0
1409 */
1410 ch = 0;
1411
1412 flag = TTY_NORMAL;
1413 port->icount.rx++;
1414
1415 lsr |= up->lsr_saved_flags;
1416 up->lsr_saved_flags = 0;
1417
1418 if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
1419 if (lsr & UART_LSR_BI) {
1420 lsr &= ~(UART_LSR_FE | UART_LSR_PE);
1421 port->icount.brk++;
1422 /*
1423 * We do the SysRQ and SAK checking
1424 * here because otherwise the break
1425 * may get masked by ignore_status_mask
1426 * or read_status_mask.
1427 */
1428 if (uart_handle_break(port))
1429 goto ignore_char;
1430 } else if (lsr & UART_LSR_PE)
1431 port->icount.parity++;
1432 else if (lsr & UART_LSR_FE)
1433 port->icount.frame++;
1434 if (lsr & UART_LSR_OE)
1435 port->icount.overrun++;
1436
1437 /*
1438 * Mask off conditions which should be ignored.
1439 */
1440 lsr &= port->read_status_mask;
1441
1442 if (lsr & UART_LSR_BI) {
1443 DEBUG_INTR("handling break....");
1444 flag = TTY_BREAK;
1445 } else if (lsr & UART_LSR_PE)
1446 flag = TTY_PARITY;
1447 else if (lsr & UART_LSR_FE)
1448 flag = TTY_FRAME;
1449 }
1450 if (uart_handle_sysrq_char(port, ch))
1451 goto ignore_char;
1452
1453 uart_insert_char(port, lsr, UART_LSR_OE, ch, flag);
1454
1455ignore_char:
1456 lsr = serial_in(up, UART_LSR);
1457 } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
1458 spin_unlock(&port->lock);
1459 tty_flip_buffer_push(tty);
1460 spin_lock(&port->lock);
1461 return lsr;
1462}
1463EXPORT_SYMBOL_GPL(serial8250_rx_chars);
1464
1465void serial8250_tx_chars(struct uart_8250_port *up)
1466{
1467 struct uart_port *port = &up->port;
1468 struct circ_buf *xmit = &port->state->xmit;
1469 int count;
1470
1471 if (port->x_char) {
1472 serial_out(up, UART_TX, port->x_char);
1473 port->icount.tx++;
1474 port->x_char = 0;
1475 return;
1476 }
1477 if (uart_tx_stopped(port)) {
1478 serial8250_stop_tx(port);
1479 return;
1480 }
1481 if (uart_circ_empty(xmit)) {
1482 __stop_tx(up);
1483 return;
1484 }
1485
1486 count = up->tx_loadsz;
1487 do {
1488 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
1489 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
1490 port->icount.tx++;
1491 if (uart_circ_empty(xmit))
1492 break;
1493 } while (--count > 0);
1494
1495 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
1496 uart_write_wakeup(port);
1497
1498 DEBUG_INTR("THRE...");
1499
1500 if (uart_circ_empty(xmit))
1501 __stop_tx(up);
1502}
1503EXPORT_SYMBOL_GPL(serial8250_tx_chars);
1504
1505unsigned int serial8250_modem_status(struct uart_8250_port *up)
1506{
1507 struct uart_port *port = &up->port;
1508 unsigned int status = serial_in(up, UART_MSR);
1509
1510 status |= up->msr_saved_flags;
1511 up->msr_saved_flags = 0;
1512 if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI &&
1513 port->state != NULL) {
1514 if (status & UART_MSR_TERI)
1515 port->icount.rng++;
1516 if (status & UART_MSR_DDSR)
1517 port->icount.dsr++;
1518 if (status & UART_MSR_DDCD)
1519 uart_handle_dcd_change(port, status & UART_MSR_DCD);
1520 if (status & UART_MSR_DCTS)
1521 uart_handle_cts_change(port, status & UART_MSR_CTS);
1522
1523 wake_up_interruptible(&port->state->port.delta_msr_wait);
1524 }
1525
1526 return status;
1527}
1528EXPORT_SYMBOL_GPL(serial8250_modem_status);
1529
1530/*
1531 * This handles the interrupt from one port.
1532 */
1533int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
1534{
1535 unsigned char status;
1536 unsigned long flags;
1537 struct uart_8250_port *up =
1538 container_of(port, struct uart_8250_port, port);
1539
1540 if (iir & UART_IIR_NO_INT)
1541 return 0;
1542
1543 spin_lock_irqsave(&port->lock, flags);
1544
1545 status = serial_port_in(port, UART_LSR);
1546
1547 DEBUG_INTR("status = %x...", status);
1548
1549 if (status & (UART_LSR_DR | UART_LSR_BI))
1550 status = serial8250_rx_chars(up, status);
1551 serial8250_modem_status(up);
1552 if (status & UART_LSR_THRE)
1553 serial8250_tx_chars(up);
1554
1555 spin_unlock_irqrestore(&port->lock, flags);
1556 return 1;
1557}
1558EXPORT_SYMBOL_GPL(serial8250_handle_irq);
1559
1560static int serial8250_default_handle_irq(struct uart_port *port)
1561{
1562 unsigned int iir = serial_port_in(port, UART_IIR);
1563
1564 return serial8250_handle_irq(port, iir);
1565}
1566
1567/*
1568 * These Exar UARTs have an extra interrupt indicator that could
1569 * fire for a few unimplemented interrupts. One of which is a
1570 * wakeup event when coming out of sleep. Put this here just
1571 * to be on the safe side that these interrupts don't go unhandled.
1572 */
1573static int exar_handle_irq(struct uart_port *port)
1574{
1575 unsigned char int0, int1, int2, int3;
1576 unsigned int iir = serial_port_in(port, UART_IIR);
1577 int ret;
1578
1579 ret = serial8250_handle_irq(port, iir);
1580
1581 if ((port->type == PORT_XR17V35X) ||
1582 (port->type == PORT_XR17D15X)) {
1583 int0 = serial_port_in(port, 0x80);
1584 int1 = serial_port_in(port, 0x81);
1585 int2 = serial_port_in(port, 0x82);
1586 int3 = serial_port_in(port, 0x83);
1587 }
1588
1589 return ret;
1590}
1591
1592/*
1593 * This is the serial driver's interrupt routine.
1594 *
1595 * Arjan thinks the old way was overly complex, so it got simplified.
1596 * Alan disagrees, saying that need the complexity to handle the weird
1597 * nature of ISA shared interrupts. (This is a special exception.)
1598 *
1599 * In order to handle ISA shared interrupts properly, we need to check
1600 * that all ports have been serviced, and therefore the ISA interrupt
1601 * line has been de-asserted.
1602 *
1603 * This means we need to loop through all ports. checking that they
1604 * don't have an interrupt pending.
1605 */
1606static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
1607{
1608 struct irq_info *i = dev_id;
1609 struct list_head *l, *end = NULL;
1610 int pass_counter = 0, handled = 0;
1611
1612 DEBUG_INTR("serial8250_interrupt(%d)...", irq);
1613
1614 spin_lock(&i->lock);
1615
1616 l = i->head;
1617 do {
1618 struct uart_8250_port *up;
1619 struct uart_port *port;
1620
1621 up = list_entry(l, struct uart_8250_port, list);
1622 port = &up->port;
1623
1624 if (port->handle_irq(port)) {
1625 handled = 1;
1626 end = NULL;
1627 } else if (end == NULL)
1628 end = l;
1629
1630 l = l->next;
1631
1632 if (l == i->head && pass_counter++ > PASS_LIMIT) {
1633 /* If we hit this, we're dead. */
1634 printk_ratelimited(KERN_ERR
1635 "serial8250: too much work for irq%d\n", irq);
1636 break;
1637 }
1638 } while (l != end);
1639
1640 spin_unlock(&i->lock);
1641
1642 DEBUG_INTR("end.\n");
1643
1644 return IRQ_RETVAL(handled);
1645}
1646
1647/*
1648 * To support ISA shared interrupts, we need to have one interrupt
1649 * handler that ensures that the IRQ line has been deasserted
1650 * before returning. Failing to do this will result in the IRQ
1651 * line being stuck active, and, since ISA irqs are edge triggered,
1652 * no more IRQs will be seen.
1653 */
1654static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
1655{
1656 spin_lock_irq(&i->lock);
1657
1658 if (!list_empty(i->head)) {
1659 if (i->head == &up->list)
1660 i->head = i->head->next;
1661 list_del(&up->list);
1662 } else {
1663 BUG_ON(i->head != &up->list);
1664 i->head = NULL;
1665 }
1666 spin_unlock_irq(&i->lock);
1667 /* List empty so throw away the hash node */
1668 if (i->head == NULL) {
1669 hlist_del(&i->node);
1670 kfree(i);
1671 }
1672}
1673
1674static int serial_link_irq_chain(struct uart_8250_port *up)
1675{
1676 struct hlist_head *h;
1677 struct hlist_node *n;
1678 struct irq_info *i;
1679 int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0;
1680
1681 mutex_lock(&hash_mutex);
1682
1683 h = &irq_lists[up->port.irq % NR_IRQ_HASH];
1684
1685 hlist_for_each(n, h) {
1686 i = hlist_entry(n, struct irq_info, node);
1687 if (i->irq == up->port.irq)
1688 break;
1689 }
1690
1691 if (n == NULL) {
1692 i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
1693 if (i == NULL) {
1694 mutex_unlock(&hash_mutex);
1695 return -ENOMEM;
1696 }
1697 spin_lock_init(&i->lock);
1698 i->irq = up->port.irq;
1699 hlist_add_head(&i->node, h);
1700 }
1701 mutex_unlock(&hash_mutex);
1702
1703 spin_lock_irq(&i->lock);
1704
1705 if (i->head) {
1706 list_add(&up->list, i->head);
1707 spin_unlock_irq(&i->lock);
1708
1709 ret = 0;
1710 } else {
1711 INIT_LIST_HEAD(&up->list);
1712 i->head = &up->list;
1713 spin_unlock_irq(&i->lock);
1714 irq_flags |= up->port.irqflags;
1715 ret = request_irq(up->port.irq, serial8250_interrupt,
1716 irq_flags, "serial", i);
1717 if (ret < 0)
1718 serial_do_unlink(i, up);
1719 }
1720
1721 return ret;
1722}
1723
1724static void serial_unlink_irq_chain(struct uart_8250_port *up)
1725{
1726 struct irq_info *i;
1727 struct hlist_node *n;
1728 struct hlist_head *h;
1729
1730 mutex_lock(&hash_mutex);
1731
1732 h = &irq_lists[up->port.irq % NR_IRQ_HASH];
1733
1734 hlist_for_each(n, h) {
1735 i = hlist_entry(n, struct irq_info, node);
1736 if (i->irq == up->port.irq)
1737 break;
1738 }
1739
1740 BUG_ON(n == NULL);
1741 BUG_ON(i->head == NULL);
1742
1743 if (list_empty(i->head))
1744 free_irq(up->port.irq, i);
1745
1746 serial_do_unlink(i, up);
1747 mutex_unlock(&hash_mutex);
1748}
1749
1750/*
1751 * This function is used to handle ports that do not have an
1752 * interrupt. This doesn't work very well for 16450's, but gives
1753 * barely passable results for a 16550A. (Although at the expense
1754 * of much CPU overhead).
1755 */
1756static void serial8250_timeout(unsigned long data)
1757{
1758 struct uart_8250_port *up = (struct uart_8250_port *)data;
1759
1760 up->port.handle_irq(&up->port);
1761 mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port));
1762}
1763
1764static void serial8250_backup_timeout(unsigned long data)
1765{
1766 struct uart_8250_port *up = (struct uart_8250_port *)data;
1767 unsigned int iir, ier = 0, lsr;
1768 unsigned long flags;
1769
1770 spin_lock_irqsave(&up->port.lock, flags);
1771
1772 /*
1773 * Must disable interrupts or else we risk racing with the interrupt
1774 * based handler.
1775 */
1776 if (up->port.irq) {
1777 ier = serial_in(up, UART_IER);
1778 serial_out(up, UART_IER, 0);
1779 }
1780
1781 iir = serial_in(up, UART_IIR);
1782
1783 /*
1784 * This should be a safe test for anyone who doesn't trust the
1785 * IIR bits on their UART, but it's specifically designed for
1786 * the "Diva" UART used on the management processor on many HP
1787 * ia64 and parisc boxes.
1788 */
1789 lsr = serial_in(up, UART_LSR);
1790 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
1791 if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) &&
1792 (!uart_circ_empty(&up->port.state->xmit) || up->port.x_char) &&
1793 (lsr & UART_LSR_THRE)) {
1794 iir &= ~(UART_IIR_ID | UART_IIR_NO_INT);
1795 iir |= UART_IIR_THRI;
1796 }
1797
1798 if (!(iir & UART_IIR_NO_INT))
1799 serial8250_tx_chars(up);
1800
1801 if (up->port.irq)
1802 serial_out(up, UART_IER, ier);
1803
1804 spin_unlock_irqrestore(&up->port.lock, flags);
1805
1806 /* Standard timer interval plus 0.2s to keep the port running */
1807 mod_timer(&up->timer,
1808 jiffies + uart_poll_timeout(&up->port) + HZ / 5);
1809}
1810
1811static unsigned int serial8250_tx_empty(struct uart_port *port)
1812{
1813 struct uart_8250_port *up =
1814 container_of(port, struct uart_8250_port, port);
1815 unsigned long flags;
1816 unsigned int lsr;
1817
1818 spin_lock_irqsave(&port->lock, flags);
1819 lsr = serial_port_in(port, UART_LSR);
1820 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
1821 spin_unlock_irqrestore(&port->lock, flags);
1822
1823 return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0;
1824}
1825
1826static unsigned int serial8250_get_mctrl(struct uart_port *port)
1827{
1828 struct uart_8250_port *up =
1829 container_of(port, struct uart_8250_port, port);
1830 unsigned int status;
1831 unsigned int ret;
1832
1833 status = serial8250_modem_status(up);
1834
1835 ret = 0;
1836 if (status & UART_MSR_DCD)
1837 ret |= TIOCM_CAR;
1838 if (status & UART_MSR_RI)
1839 ret |= TIOCM_RNG;
1840 if (status & UART_MSR_DSR)
1841 ret |= TIOCM_DSR;
1842 if (status & UART_MSR_CTS)
1843 ret |= TIOCM_CTS;
1844 return ret;
1845}
1846
1847static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
1848{
1849 struct uart_8250_port *up =
1850 container_of(port, struct uart_8250_port, port);
1851 unsigned char mcr = 0;
1852
1853 if (mctrl & TIOCM_RTS)
1854 mcr |= UART_MCR_RTS;
1855 if (mctrl & TIOCM_DTR)
1856 mcr |= UART_MCR_DTR;
1857 if (mctrl & TIOCM_OUT1)
1858 mcr |= UART_MCR_OUT1;
1859 if (mctrl & TIOCM_OUT2)
1860 mcr |= UART_MCR_OUT2;
1861 if (mctrl & TIOCM_LOOP)
1862 mcr |= UART_MCR_LOOP;
1863
1864 mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr;
1865
1866 serial_port_out(port, UART_MCR, mcr);
1867}
1868
1869static void serial8250_break_ctl(struct uart_port *port, int break_state)
1870{
1871 struct uart_8250_port *up =
1872 container_of(port, struct uart_8250_port, port);
1873 unsigned long flags;
1874
1875 spin_lock_irqsave(&port->lock, flags);
1876 if (break_state == -1)
1877 up->lcr |= UART_LCR_SBC;
1878 else
1879 up->lcr &= ~UART_LCR_SBC;
1880 serial_port_out(port, UART_LCR, up->lcr);
1881 spin_unlock_irqrestore(&port->lock, flags);
1882}
1883
1884/*
1885 * Wait for transmitter & holding register to empty
1886 */
1887static void wait_for_xmitr(struct uart_8250_port *up, int bits)
1888{
1889 unsigned int status, tmout = 10000;
1890
1891 /* Wait up to 10ms for the character(s) to be sent. */
1892 for (;;) {
1893 status = serial_in(up, UART_LSR);
1894
1895 up->lsr_saved_flags |= status & LSR_SAVE_FLAGS;
1896
1897 if ((status & bits) == bits)
1898 break;
1899 if (--tmout == 0)
1900 break;
1901 udelay(1);
1902 }
1903
1904 /* Wait up to 1s for flow control if necessary */
1905 if (up->port.flags & UPF_CONS_FLOW) {
1906 unsigned int tmout;
1907 for (tmout = 1000000; tmout; tmout--) {
1908 unsigned int msr = serial_in(up, UART_MSR);
1909 up->msr_saved_flags |= msr & MSR_SAVE_FLAGS;
1910 if (msr & UART_MSR_CTS)
1911 break;
1912 udelay(1);
1913 touch_nmi_watchdog();
1914 }
1915 }
1916}
1917
1918#ifdef CONFIG_CONSOLE_POLL
1919/*
1920 * Console polling routines for writing and reading from the uart while
1921 * in an interrupt or debug context.
1922 */
1923
1924static int serial8250_get_poll_char(struct uart_port *port)
1925{
1926 unsigned char lsr = serial_port_in(port, UART_LSR);
1927
1928 if (!(lsr & UART_LSR_DR))
1929 return NO_POLL_CHAR;
1930
1931 return serial_port_in(port, UART_RX);
1932}
1933
1934
1935static void serial8250_put_poll_char(struct uart_port *port,
1936 unsigned char c)
1937{
1938 unsigned int ier;
1939 struct uart_8250_port *up =
1940 container_of(port, struct uart_8250_port, port);
1941
1942 /*
1943 * First save the IER then disable the interrupts
1944 */
1945 ier = serial_port_in(port, UART_IER);
1946 if (up->capabilities & UART_CAP_UUE)
1947 serial_port_out(port, UART_IER, UART_IER_UUE);
1948 else
1949 serial_port_out(port, UART_IER, 0);
1950
1951 wait_for_xmitr(up, BOTH_EMPTY);
1952 /*
1953 * Send the character out.
1954 * If a LF, also do CR...
1955 */
1956 serial_port_out(port, UART_TX, c);
1957 if (c == 10) {
1958 wait_for_xmitr(up, BOTH_EMPTY);
1959 serial_port_out(port, UART_TX, 13);
1960 }
1961
1962 /*
1963 * Finally, wait for transmitter to become empty
1964 * and restore the IER
1965 */
1966 wait_for_xmitr(up, BOTH_EMPTY);
1967 serial_port_out(port, UART_IER, ier);
1968}
1969
1970#endif /* CONFIG_CONSOLE_POLL */
1971
1972static int serial8250_startup(struct uart_port *port)
1973{
1974 struct uart_8250_port *up =
1975 container_of(port, struct uart_8250_port, port);
1976 unsigned long flags;
1977 unsigned char lsr, iir;
1978 int retval;
1979
1980 if (port->type == PORT_8250_CIR)
1981 return -ENODEV;
1982
1983 port->fifosize = uart_config[up->port.type].fifo_size;
1984 up->tx_loadsz = uart_config[up->port.type].tx_loadsz;
1985 up->capabilities = uart_config[up->port.type].flags;
1986 up->mcr = 0;
1987
1988 if (port->iotype != up->cur_iotype)
1989 set_io_from_upio(port);
1990
1991 if (port->type == PORT_16C950) {
1992 /* Wake up and initialize UART */
1993 up->acr = 0;
1994 serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
1995 serial_port_out(port, UART_EFR, UART_EFR_ECB);
1996 serial_port_out(port, UART_IER, 0);
1997 serial_port_out(port, UART_LCR, 0);
1998 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
1999 serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
2000 serial_port_out(port, UART_EFR, UART_EFR_ECB);
2001 serial_port_out(port, UART_LCR, 0);
2002 }
2003
2004#ifdef CONFIG_SERIAL_8250_RSA
2005 /*
2006 * If this is an RSA port, see if we can kick it up to the
2007 * higher speed clock.
2008 */
2009 enable_rsa(up);
2010#endif
2011
2012 /*
2013 * Clear the FIFO buffers and disable them.
2014 * (they will be reenabled in set_termios())
2015 */
2016 serial8250_clear_fifos(up);
2017
2018 /*
2019 * Clear the interrupt registers.
2020 */
2021 serial_port_in(port, UART_LSR);
2022 serial_port_in(port, UART_RX);
2023 serial_port_in(port, UART_IIR);
2024 serial_port_in(port, UART_MSR);
2025
2026 /*
2027 * At this point, there's no way the LSR could still be 0xff;
2028 * if it is, then bail out, because there's likely no UART
2029 * here.
2030 */
2031 if (!(port->flags & UPF_BUGGY_UART) &&
2032 (serial_port_in(port, UART_LSR) == 0xff)) {
2033 printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n",
2034 serial_index(port));
2035 return -ENODEV;
2036 }
2037
2038 /*
2039 * For a XR16C850, we need to set the trigger levels
2040 */
2041 if (port->type == PORT_16850) {
2042 unsigned char fctr;
2043
2044 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
2045
2046 fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
2047 serial_port_out(port, UART_FCTR,
2048 fctr | UART_FCTR_TRGD | UART_FCTR_RX);
2049 serial_port_out(port, UART_TRG, UART_TRG_96);
2050 serial_port_out(port, UART_FCTR,
2051 fctr | UART_FCTR_TRGD | UART_FCTR_TX);
2052 serial_port_out(port, UART_TRG, UART_TRG_96);
2053
2054 serial_port_out(port, UART_LCR, 0);
2055 }
2056
2057 if (port->irq) {
2058 unsigned char iir1;
2059 /*
2060 * Test for UARTs that do not reassert THRE when the
2061 * transmitter is idle and the interrupt has already
2062 * been cleared. Real 16550s should always reassert
2063 * this interrupt whenever the transmitter is idle and
2064 * the interrupt is enabled. Delays are necessary to
2065 * allow register changes to become visible.
2066 */
2067 spin_lock_irqsave(&port->lock, flags);
2068 if (up->port.irqflags & IRQF_SHARED)
2069 disable_irq_nosync(port->irq);
2070
2071 wait_for_xmitr(up, UART_LSR_THRE);
2072 serial_port_out_sync(port, UART_IER, UART_IER_THRI);
2073 udelay(1); /* allow THRE to set */
2074 iir1 = serial_port_in(port, UART_IIR);
2075 serial_port_out(port, UART_IER, 0);
2076 serial_port_out_sync(port, UART_IER, UART_IER_THRI);
2077 udelay(1); /* allow a working UART time to re-assert THRE */
2078 iir = serial_port_in(port, UART_IIR);
2079 serial_port_out(port, UART_IER, 0);
2080
2081 if (port->irqflags & IRQF_SHARED)
2082 enable_irq(port->irq);
2083 spin_unlock_irqrestore(&port->lock, flags);
2084
2085 /*
2086 * If the interrupt is not reasserted, or we otherwise
2087 * don't trust the iir, setup a timer to kick the UART
2088 * on a regular basis.
2089 */
2090 if ((!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) ||
2091 up->port.flags & UPF_BUG_THRE) {
2092 up->bugs |= UART_BUG_THRE;
2093 pr_debug("ttyS%d - using backup timer\n",
2094 serial_index(port));
2095 }
2096 }
2097
2098 /*
2099 * The above check will only give an accurate result the first time
2100 * the port is opened so this value needs to be preserved.
2101 */
2102 if (up->bugs & UART_BUG_THRE) {
2103 up->timer.function = serial8250_backup_timeout;
2104 up->timer.data = (unsigned long)up;
2105 mod_timer(&up->timer, jiffies +
2106 uart_poll_timeout(port) + HZ / 5);
2107 }
2108
2109 /*
2110 * If the "interrupt" for this port doesn't correspond with any
2111 * hardware interrupt, we use a timer-based system. The original
2112 * driver used to do this with IRQ0.
2113 */
2114 if (!port->irq) {
2115 up->timer.data = (unsigned long)up;
2116 mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
2117 } else {
2118 retval = serial_link_irq_chain(up);
2119 if (retval)
2120 return retval;
2121 }
2122
2123 /*
2124 * Now, initialize the UART
2125 */
2126 serial_port_out(port, UART_LCR, UART_LCR_WLEN8);
2127
2128 spin_lock_irqsave(&port->lock, flags);
2129 if (up->port.flags & UPF_FOURPORT) {
2130 if (!up->port.irq)
2131 up->port.mctrl |= TIOCM_OUT1;
2132 } else
2133 /*
2134 * Most PC uarts need OUT2 raised to enable interrupts.
2135 */
2136 if (port->irq)
2137 up->port.mctrl |= TIOCM_OUT2;
2138
2139 serial8250_set_mctrl(port, port->mctrl);
2140
2141 /* Serial over Lan (SoL) hack:
2142 Intel 8257x Gigabit ethernet chips have a
2143 16550 emulation, to be used for Serial Over Lan.
2144 Those chips take a longer time than a normal
2145 serial device to signalize that a transmission
2146 data was queued. Due to that, the above test generally
2147 fails. One solution would be to delay the reading of
2148 iir. However, this is not reliable, since the timeout
2149 is variable. So, let's just don't test if we receive
2150 TX irq. This way, we'll never enable UART_BUG_TXEN.
2151 */
2152 if (skip_txen_test || up->port.flags & UPF_NO_TXEN_TEST)
2153 goto dont_test_tx_en;
2154
2155 /*
2156 * Do a quick test to see if we receive an
2157 * interrupt when we enable the TX irq.
2158 */
2159 serial_port_out(port, UART_IER, UART_IER_THRI);
2160 lsr = serial_port_in(port, UART_LSR);
2161 iir = serial_port_in(port, UART_IIR);
2162 serial_port_out(port, UART_IER, 0);
2163
2164 if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
2165 if (!(up->bugs & UART_BUG_TXEN)) {
2166 up->bugs |= UART_BUG_TXEN;
2167 pr_debug("ttyS%d - enabling bad tx status workarounds\n",
2168 serial_index(port));
2169 }
2170 } else {
2171 up->bugs &= ~UART_BUG_TXEN;
2172 }
2173
2174dont_test_tx_en:
2175 spin_unlock_irqrestore(&port->lock, flags);
2176
2177 /*
2178 * Clear the interrupt registers again for luck, and clear the
2179 * saved flags to avoid getting false values from polling
2180 * routines or the previous session.
2181 */
2182 serial_port_in(port, UART_LSR);
2183 serial_port_in(port, UART_RX);
2184 serial_port_in(port, UART_IIR);
2185 serial_port_in(port, UART_MSR);
2186 up->lsr_saved_flags = 0;
2187 up->msr_saved_flags = 0;
2188
2189 /*
2190 * Finally, enable interrupts. Note: Modem status interrupts
2191 * are set via set_termios(), which will be occurring imminently
2192 * anyway, so we don't enable them here.
2193 */
2194 up->ier = UART_IER_RLSI | UART_IER_RDI;
2195 serial_port_out(port, UART_IER, up->ier);
2196
2197 if (port->flags & UPF_FOURPORT) {
2198 unsigned int icp;
2199 /*
2200 * Enable interrupts on the AST Fourport board
2201 */
2202 icp = (port->iobase & 0xfe0) | 0x01f;
2203 outb_p(0x80, icp);
2204 inb_p(icp);
2205 }
2206
2207 return 0;
2208}
2209
2210static void serial8250_shutdown(struct uart_port *port)
2211{
2212 struct uart_8250_port *up =
2213 container_of(port, struct uart_8250_port, port);
2214 unsigned long flags;
2215
2216 /*
2217 * Disable interrupts from this port
2218 */
2219 up->ier = 0;
2220 serial_port_out(port, UART_IER, 0);
2221
2222 spin_lock_irqsave(&port->lock, flags);
2223 if (port->flags & UPF_FOURPORT) {
2224 /* reset interrupts on the AST Fourport board */
2225 inb((port->iobase & 0xfe0) | 0x1f);
2226 port->mctrl |= TIOCM_OUT1;
2227 } else
2228 port->mctrl &= ~TIOCM_OUT2;
2229
2230 serial8250_set_mctrl(port, port->mctrl);
2231 spin_unlock_irqrestore(&port->lock, flags);
2232
2233 /*
2234 * Disable break condition and FIFOs
2235 */
2236 serial_port_out(port, UART_LCR,
2237 serial_port_in(port, UART_LCR) & ~UART_LCR_SBC);
2238 serial8250_clear_fifos(up);
2239
2240#ifdef CONFIG_SERIAL_8250_RSA
2241 /*
2242 * Reset the RSA board back to 115kbps compat mode.
2243 */
2244 disable_rsa(up);
2245#endif
2246
2247 /*
2248 * Read data port to reset things, and then unlink from
2249 * the IRQ chain.
2250 */
2251 serial_port_in(port, UART_RX);
2252
2253 del_timer_sync(&up->timer);
2254 up->timer.function = serial8250_timeout;
2255 if (port->irq)
2256 serial_unlink_irq_chain(up);
2257}
2258
2259static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud)
2260{
2261 unsigned int quot;
2262
2263 /*
2264 * Handle magic divisors for baud rates above baud_base on
2265 * SMSC SuperIO chips.
2266 */
2267 if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
2268 baud == (port->uartclk/4))
2269 quot = 0x8001;
2270 else if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
2271 baud == (port->uartclk/8))
2272 quot = 0x8002;
2273 else
2274 quot = uart_get_divisor(port, baud);
2275
2276 return quot;
2277}
2278
2279void
2280serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2281 struct ktermios *old)
2282{
2283 struct uart_8250_port *up =
2284 container_of(port, struct uart_8250_port, port);
2285 unsigned char cval, fcr = 0;
2286 unsigned long flags;
2287 unsigned int baud, quot;
2288 int fifo_bug = 0;
2289
2290 switch (termios->c_cflag & CSIZE) {
2291 case CS5:
2292 cval = UART_LCR_WLEN5;
2293 break;
2294 case CS6:
2295 cval = UART_LCR_WLEN6;
2296 break;
2297 case CS7:
2298 cval = UART_LCR_WLEN7;
2299 break;
2300 default:
2301 case CS8:
2302 cval = UART_LCR_WLEN8;
2303 break;
2304 }
2305
2306 if (termios->c_cflag & CSTOPB)
2307 cval |= UART_LCR_STOP;
2308 if (termios->c_cflag & PARENB) {
2309 cval |= UART_LCR_PARITY;
2310 if (up->bugs & UART_BUG_PARITY)
2311 fifo_bug = 1;
2312 }
2313 if (!(termios->c_cflag & PARODD))
2314 cval |= UART_LCR_EPAR;
2315#ifdef CMSPAR
2316 if (termios->c_cflag & CMSPAR)
2317 cval |= UART_LCR_SPAR;
2318#endif
2319
2320 /*
2321 * Ask the core to calculate the divisor for us.
2322 */
2323 baud = uart_get_baud_rate(port, termios, old,
2324 port->uartclk / 16 / 0xffff,
2325 port->uartclk / 16);
2326 quot = serial8250_get_divisor(port, baud);
2327
2328 /*
2329 * Oxford Semi 952 rev B workaround
2330 */
2331 if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0)
2332 quot++;
2333
2334 if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) {
2335 fcr = uart_config[port->type].fcr;
2336 if (baud < 2400 || fifo_bug) {
2337 fcr &= ~UART_FCR_TRIGGER_MASK;
2338 fcr |= UART_FCR_TRIGGER_1;
2339 }
2340 }
2341
2342 /*
2343 * MCR-based auto flow control. When AFE is enabled, RTS will be
2344 * deasserted when the receive FIFO contains more characters than
2345 * the trigger, or the MCR RTS bit is cleared. In the case where
2346 * the remote UART is not using CTS auto flow control, we must
2347 * have sufficient FIFO entries for the latency of the remote
2348 * UART to respond. IOW, at least 32 bytes of FIFO.
2349 */
2350 if (up->capabilities & UART_CAP_AFE && port->fifosize >= 32) {
2351 up->mcr &= ~UART_MCR_AFE;
2352 if (termios->c_cflag & CRTSCTS)
2353 up->mcr |= UART_MCR_AFE;
2354 }
2355
2356 /*
2357 * Ok, we're now changing the port state. Do it with
2358 * interrupts disabled.
2359 */
2360 spin_lock_irqsave(&port->lock, flags);
2361
2362 /*
2363 * Update the per-port timeout.
2364 */
2365 uart_update_timeout(port, termios->c_cflag, baud);
2366
2367 port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2368 if (termios->c_iflag & INPCK)
2369 port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2370 if (termios->c_iflag & (BRKINT | PARMRK))
2371 port->read_status_mask |= UART_LSR_BI;
2372
2373 /*
2374 * Characteres to ignore
2375 */
2376 port->ignore_status_mask = 0;
2377 if (termios->c_iflag & IGNPAR)
2378 port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
2379 if (termios->c_iflag & IGNBRK) {
2380 port->ignore_status_mask |= UART_LSR_BI;
2381 /*
2382 * If we're ignoring parity and break indicators,
2383 * ignore overruns too (for real raw support).
2384 */
2385 if (termios->c_iflag & IGNPAR)
2386 port->ignore_status_mask |= UART_LSR_OE;
2387 }
2388
2389 /*
2390 * ignore all characters if CREAD is not set
2391 */
2392 if ((termios->c_cflag & CREAD) == 0)
2393 port->ignore_status_mask |= UART_LSR_DR;
2394
2395 /*
2396 * CTS flow control flag and modem status interrupts
2397 */
2398 up->ier &= ~UART_IER_MSI;
2399 if (!(up->bugs & UART_BUG_NOMSR) &&
2400 UART_ENABLE_MS(&up->port, termios->c_cflag))
2401 up->ier |= UART_IER_MSI;
2402 if (up->capabilities & UART_CAP_UUE)
2403 up->ier |= UART_IER_UUE;
2404 if (up->capabilities & UART_CAP_RTOIE)
2405 up->ier |= UART_IER_RTOIE;
2406
2407 serial_port_out(port, UART_IER, up->ier);
2408
2409 if (up->capabilities & UART_CAP_EFR) {
2410 unsigned char efr = 0;
2411 /*
2412 * TI16C752/Startech hardware flow control. FIXME:
2413 * - TI16C752 requires control thresholds to be set.
2414 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
2415 */
2416 if (termios->c_cflag & CRTSCTS)
2417 efr |= UART_EFR_CTS;
2418
2419 serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B);
2420 if (port->flags & UPF_EXAR_EFR)
2421 serial_port_out(port, UART_XR_EFR, efr);
2422 else
2423 serial_port_out(port, UART_EFR, efr);
2424 }
2425
2426 /* Workaround to enable 115200 baud on OMAP1510 internal ports */
2427 if (is_omap1510_8250(up)) {
2428 if (baud == 115200) {
2429 quot = 1;
2430 serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1);
2431 } else
2432 serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0);
2433 }
2434
2435 /*
2436 * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2,
2437 * otherwise just set DLAB
2438 */
2439 if (up->capabilities & UART_NATSEMI)
2440 serial_port_out(port, UART_LCR, 0xe0);
2441 else
2442 serial_port_out(port, UART_LCR, cval | UART_LCR_DLAB);
2443
2444 serial_dl_write(up, quot);
2445
2446 /*
2447 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
2448 * is written without DLAB set, this mode will be disabled.
2449 */
2450 if (port->type == PORT_16750)
2451 serial_port_out(port, UART_FCR, fcr);
2452
2453 serial_port_out(port, UART_LCR, cval); /* reset DLAB */
2454 up->lcr = cval; /* Save LCR */
2455 if (port->type != PORT_16750) {
2456 /* emulated UARTs (Lucent Venus 167x) need two steps */
2457 if (fcr & UART_FCR_ENABLE_FIFO)
2458 serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
2459 serial_port_out(port, UART_FCR, fcr); /* set fcr */
2460 }
2461 serial8250_set_mctrl(port, port->mctrl);
2462 spin_unlock_irqrestore(&port->lock, flags);
2463 /* Don't rewrite B0 */
2464 if (tty_termios_baud_rate(termios))
2465 tty_termios_encode_baud_rate(termios, baud, baud);
2466}
2467EXPORT_SYMBOL(serial8250_do_set_termios);
2468
2469static void
2470serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
2471 struct ktermios *old)
2472{
2473 if (port->set_termios)
2474 port->set_termios(port, termios, old);
2475 else
2476 serial8250_do_set_termios(port, termios, old);
2477}
2478
2479static void
2480serial8250_set_ldisc(struct uart_port *port, int new)
2481{
2482 if (new == N_PPS) {
2483 port->flags |= UPF_HARDPPS_CD;
2484 serial8250_enable_ms(port);
2485 } else
2486 port->flags &= ~UPF_HARDPPS_CD;
2487}
2488
2489
2490void serial8250_do_pm(struct uart_port *port, unsigned int state,
2491 unsigned int oldstate)
2492{
2493 struct uart_8250_port *p =
2494 container_of(port, struct uart_8250_port, port);
2495
2496 serial8250_set_sleep(p, state != 0);
2497}
2498EXPORT_SYMBOL(serial8250_do_pm);
2499
2500static void
2501serial8250_pm(struct uart_port *port, unsigned int state,
2502 unsigned int oldstate)
2503{
2504 if (port->pm)
2505 port->pm(port, state, oldstate);
2506 else
2507 serial8250_do_pm(port, state, oldstate);
2508}
2509
2510static unsigned int serial8250_port_size(struct uart_8250_port *pt)
2511{
2512 if (pt->port.iotype == UPIO_AU)
2513 return 0x1000;
2514 if (is_omap1_8250(pt))
2515 return 0x16 << pt->port.regshift;
2516
2517 return 8 << pt->port.regshift;
2518}
2519
2520/*
2521 * Resource handling.
2522 */
2523static int serial8250_request_std_resource(struct uart_8250_port *up)
2524{
2525 unsigned int size = serial8250_port_size(up);
2526 struct uart_port *port = &up->port;
2527 int ret = 0;
2528
2529 switch (port->iotype) {
2530 case UPIO_AU:
2531 case UPIO_TSI:
2532 case UPIO_MEM32:
2533 case UPIO_MEM:
2534 if (!port->mapbase)
2535 break;
2536
2537 if (!request_mem_region(port->mapbase, size, "serial")) {
2538 ret = -EBUSY;
2539 break;
2540 }
2541
2542 if (port->flags & UPF_IOREMAP) {
2543 port->membase = ioremap_nocache(port->mapbase, size);
2544 if (!port->membase) {
2545 release_mem_region(port->mapbase, size);
2546 ret = -ENOMEM;
2547 }
2548 }
2549 break;
2550
2551 case UPIO_HUB6:
2552 case UPIO_PORT:
2553 if (!request_region(port->iobase, size, "serial"))
2554 ret = -EBUSY;
2555 break;
2556 }
2557 return ret;
2558}
2559
2560static void serial8250_release_std_resource(struct uart_8250_port *up)
2561{
2562 unsigned int size = serial8250_port_size(up);
2563 struct uart_port *port = &up->port;
2564
2565 switch (port->iotype) {
2566 case UPIO_AU:
2567 case UPIO_TSI:
2568 case UPIO_MEM32:
2569 case UPIO_MEM:
2570 if (!port->mapbase)
2571 break;
2572
2573 if (port->flags & UPF_IOREMAP) {
2574 iounmap(port->membase);
2575 port->membase = NULL;
2576 }
2577
2578 release_mem_region(port->mapbase, size);
2579 break;
2580
2581 case UPIO_HUB6:
2582 case UPIO_PORT:
2583 release_region(port->iobase, size);
2584 break;
2585 }
2586}
2587
2588static int serial8250_request_rsa_resource(struct uart_8250_port *up)
2589{
2590 unsigned long start = UART_RSA_BASE << up->port.regshift;
2591 unsigned int size = 8 << up->port.regshift;
2592 struct uart_port *port = &up->port;
2593 int ret = -EINVAL;
2594
2595 switch (port->iotype) {
2596 case UPIO_HUB6:
2597 case UPIO_PORT:
2598 start += port->iobase;
2599 if (request_region(start, size, "serial-rsa"))
2600 ret = 0;
2601 else
2602 ret = -EBUSY;
2603 break;
2604 }
2605
2606 return ret;
2607}
2608
2609static void serial8250_release_rsa_resource(struct uart_8250_port *up)
2610{
2611 unsigned long offset = UART_RSA_BASE << up->port.regshift;
2612 unsigned int size = 8 << up->port.regshift;
2613 struct uart_port *port = &up->port;
2614
2615 switch (port->iotype) {
2616 case UPIO_HUB6:
2617 case UPIO_PORT:
2618 release_region(port->iobase + offset, size);
2619 break;
2620 }
2621}
2622
2623static void serial8250_release_port(struct uart_port *port)
2624{
2625 struct uart_8250_port *up =
2626 container_of(port, struct uart_8250_port, port);
2627
2628 serial8250_release_std_resource(up);
2629 if (port->type == PORT_RSA)
2630 serial8250_release_rsa_resource(up);
2631}
2632
2633static int serial8250_request_port(struct uart_port *port)
2634{
2635 struct uart_8250_port *up =
2636 container_of(port, struct uart_8250_port, port);
2637 int ret;
2638
2639 if (port->type == PORT_8250_CIR)
2640 return -ENODEV;
2641
2642 ret = serial8250_request_std_resource(up);
2643 if (ret == 0 && port->type == PORT_RSA) {
2644 ret = serial8250_request_rsa_resource(up);
2645 if (ret < 0)
2646 serial8250_release_std_resource(up);
2647 }
2648
2649 return ret;
2650}
2651
2652static void serial8250_config_port(struct uart_port *port, int flags)
2653{
2654 struct uart_8250_port *up =
2655 container_of(port, struct uart_8250_port, port);
2656 int probeflags = PROBE_ANY;
2657 int ret;
2658
2659 if (port->type == PORT_8250_CIR)
2660 return;
2661
2662 /*
2663 * Find the region that we can probe for. This in turn
2664 * tells us whether we can probe for the type of port.
2665 */
2666 ret = serial8250_request_std_resource(up);
2667 if (ret < 0)
2668 return;
2669
2670 ret = serial8250_request_rsa_resource(up);
2671 if (ret < 0)
2672 probeflags &= ~PROBE_RSA;
2673
2674 if (port->iotype != up->cur_iotype)
2675 set_io_from_upio(port);
2676
2677 if (flags & UART_CONFIG_TYPE)
2678 autoconfig(up, probeflags);
2679
2680 /* if access method is AU, it is a 16550 with a quirk */
2681 if (port->type == PORT_16550A && port->iotype == UPIO_AU)
2682 up->bugs |= UART_BUG_NOMSR;
2683
2684 if (port->type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
2685 autoconfig_irq(up);
2686
2687 if (port->type != PORT_RSA && probeflags & PROBE_RSA)
2688 serial8250_release_rsa_resource(up);
2689 if (port->type == PORT_UNKNOWN)
2690 serial8250_release_std_resource(up);
2691
2692 /* Fixme: probably not the best place for this */
2693 if ((port->type == PORT_XR17V35X) ||
2694 (port->type == PORT_XR17D15X))
2695 port->handle_irq = exar_handle_irq;
2696}
2697
2698static int
2699serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
2700{
2701 if (ser->irq >= nr_irqs || ser->irq < 0 ||
2702 ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
2703 ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS ||
2704 ser->type == PORT_STARTECH)
2705 return -EINVAL;
2706 return 0;
2707}
2708
2709static const char *
2710serial8250_type(struct uart_port *port)
2711{
2712 int type = port->type;
2713
2714 if (type >= ARRAY_SIZE(uart_config))
2715 type = 0;
2716 return uart_config[type].name;
2717}
2718
2719static struct uart_ops serial8250_pops = {
2720 .tx_empty = serial8250_tx_empty,
2721 .set_mctrl = serial8250_set_mctrl,
2722 .get_mctrl = serial8250_get_mctrl,
2723 .stop_tx = serial8250_stop_tx,
2724 .start_tx = serial8250_start_tx,
2725 .stop_rx = serial8250_stop_rx,
2726 .enable_ms = serial8250_enable_ms,
2727 .break_ctl = serial8250_break_ctl,
2728 .startup = serial8250_startup,
2729 .shutdown = serial8250_shutdown,
2730 .set_termios = serial8250_set_termios,
2731 .set_ldisc = serial8250_set_ldisc,
2732 .pm = serial8250_pm,
2733 .type = serial8250_type,
2734 .release_port = serial8250_release_port,
2735 .request_port = serial8250_request_port,
2736 .config_port = serial8250_config_port,
2737 .verify_port = serial8250_verify_port,
2738#ifdef CONFIG_CONSOLE_POLL
2739 .poll_get_char = serial8250_get_poll_char,
2740 .poll_put_char = serial8250_put_poll_char,
2741#endif
2742};
2743
2744static struct uart_8250_port serial8250_ports[UART_NR];
2745
2746static void (*serial8250_isa_config)(int port, struct uart_port *up,
2747 unsigned short *capabilities);
2748
2749void serial8250_set_isa_configurator(
2750 void (*v)(int port, struct uart_port *up, unsigned short *capabilities))
2751{
2752 serial8250_isa_config = v;
2753}
2754EXPORT_SYMBOL(serial8250_set_isa_configurator);
2755
2756static void __init serial8250_isa_init_ports(void)
2757{
2758 struct uart_8250_port *up;
2759 static int first = 1;
2760 int i, irqflag = 0;
2761
2762 if (!first)
2763 return;
2764 first = 0;
2765
2766 if (nr_uarts > UART_NR)
2767 nr_uarts = UART_NR;
2768
2769 for (i = 0; i < nr_uarts; i++) {
2770 struct uart_8250_port *up = &serial8250_ports[i];
2771 struct uart_port *port = &up->port;
2772
2773 port->line = i;
2774 spin_lock_init(&port->lock);
2775
2776 init_timer(&up->timer);
2777 up->timer.function = serial8250_timeout;
2778 up->cur_iotype = 0xFF;
2779
2780 /*
2781 * ALPHA_KLUDGE_MCR needs to be killed.
2782 */
2783 up->mcr_mask = ~ALPHA_KLUDGE_MCR;
2784 up->mcr_force = ALPHA_KLUDGE_MCR;
2785
2786 port->ops = &serial8250_pops;
2787 }
2788
2789 if (share_irqs)
2790 irqflag = IRQF_SHARED;
2791
2792 for (i = 0, up = serial8250_ports;
2793 i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
2794 i++, up++) {
2795 struct uart_port *port = &up->port;
2796
2797 port->iobase = old_serial_port[i].port;
2798 port->irq = irq_canonicalize(old_serial_port[i].irq);
2799 port->irqflags = old_serial_port[i].irqflags;
2800 port->uartclk = old_serial_port[i].baud_base * 16;
2801 port->flags = old_serial_port[i].flags;
2802 port->hub6 = old_serial_port[i].hub6;
2803 port->membase = old_serial_port[i].iomem_base;
2804 port->iotype = old_serial_port[i].io_type;
2805 port->regshift = old_serial_port[i].iomem_reg_shift;
2806 set_io_from_upio(port);
2807 port->irqflags |= irqflag;
2808 if (serial8250_isa_config != NULL)
2809 serial8250_isa_config(i, &up->port, &up->capabilities);
2810
2811 }
2812}
2813
2814static void
2815serial8250_init_fixed_type_port(struct uart_8250_port *up, unsigned int type)
2816{
2817 up->port.type = type;
2818 up->port.fifosize = uart_config[type].fifo_size;
2819 up->capabilities = uart_config[type].flags;
2820 up->tx_loadsz = uart_config[type].tx_loadsz;
2821}
2822
2823static void __init
2824serial8250_register_ports(struct uart_driver *drv, struct device *dev)
2825{
2826 int i;
2827
2828 for (i = 0; i < nr_uarts; i++) {
2829 struct uart_8250_port *up = &serial8250_ports[i];
2830
2831 if (up->port.dev)
2832 continue;
2833
2834 up->port.dev = dev;
2835
2836 if (up->port.flags & UPF_FIXED_TYPE)
2837 serial8250_init_fixed_type_port(up, up->port.type);
2838
2839 uart_add_one_port(drv, &up->port);
2840 }
2841}
2842
2843#ifdef CONFIG_SERIAL_8250_CONSOLE
2844
2845static void serial8250_console_putchar(struct uart_port *port, int ch)
2846{
2847 struct uart_8250_port *up =
2848 container_of(port, struct uart_8250_port, port);
2849
2850 wait_for_xmitr(up, UART_LSR_THRE);
2851 serial_port_out(port, UART_TX, ch);
2852}
2853
2854/*
2855 * Print a string to the serial port trying not to disturb
2856 * any possible real use of the port...
2857 *
2858 * The console_lock must be held when we get here.
2859 */
2860static void
2861serial8250_console_write(struct console *co, const char *s, unsigned int count)
2862{
2863 struct uart_8250_port *up = &serial8250_ports[co->index];
2864 struct uart_port *port = &up->port;
2865 unsigned long flags;
2866 unsigned int ier;
2867 int locked = 1;
2868
2869 touch_nmi_watchdog();
2870
2871 local_irq_save(flags);
2872 if (port->sysrq) {
2873 /* serial8250_handle_irq() already took the lock */
2874 locked = 0;
2875 } else if (oops_in_progress) {
2876 locked = spin_trylock(&port->lock);
2877 } else
2878 spin_lock(&port->lock);
2879
2880 /*
2881 * First save the IER then disable the interrupts
2882 */
2883 ier = serial_port_in(port, UART_IER);
2884
2885 if (up->capabilities & UART_CAP_UUE)
2886 serial_port_out(port, UART_IER, UART_IER_UUE);
2887 else
2888 serial_port_out(port, UART_IER, 0);
2889
2890 uart_console_write(port, s, count, serial8250_console_putchar);
2891
2892 /*
2893 * Finally, wait for transmitter to become empty
2894 * and restore the IER
2895 */
2896 wait_for_xmitr(up, BOTH_EMPTY);
2897 serial_port_out(port, UART_IER, ier);
2898
2899 /*
2900 * The receive handling will happen properly because the
2901 * receive ready bit will still be set; it is not cleared
2902 * on read. However, modem control will not, we must
2903 * call it if we have saved something in the saved flags
2904 * while processing with interrupts off.
2905 */
2906 if (up->msr_saved_flags)
2907 serial8250_modem_status(up);
2908
2909 if (locked)
2910 spin_unlock(&port->lock);
2911 local_irq_restore(flags);
2912}
2913
2914static int __init serial8250_console_setup(struct console *co, char *options)
2915{
2916 struct uart_port *port;
2917 int baud = 9600;
2918 int bits = 8;
2919 int parity = 'n';
2920 int flow = 'n';
2921
2922 /*
2923 * Check whether an invalid uart number has been specified, and
2924 * if so, search for the first available port that does have
2925 * console support.
2926 */
2927 if (co->index >= nr_uarts)
2928 co->index = 0;
2929 port = &serial8250_ports[co->index].port;
2930 if (!port->iobase && !port->membase)
2931 return -ENODEV;
2932
2933 if (options)
2934 uart_parse_options(options, &baud, &parity, &bits, &flow);
2935
2936 return uart_set_options(port, co, baud, parity, bits, flow);
2937}
2938
2939static int serial8250_console_early_setup(void)
2940{
2941 return serial8250_find_port_for_earlycon();
2942}
2943
2944static struct console serial8250_console = {
2945 .name = "ttyS",
2946 .write = serial8250_console_write,
2947 .device = uart_console_device,
2948 .setup = serial8250_console_setup,
2949 .early_setup = serial8250_console_early_setup,
2950 .flags = CON_PRINTBUFFER | CON_ANYTIME,
2951 .index = -1,
2952 .data = &serial8250_reg,
2953};
2954
2955static int __init serial8250_console_init(void)
2956{
2957 serial8250_isa_init_ports();
2958 register_console(&serial8250_console);
2959 return 0;
2960}
2961console_initcall(serial8250_console_init);
2962
2963int serial8250_find_port(struct uart_port *p)
2964{
2965 int line;
2966 struct uart_port *port;
2967
2968 for (line = 0; line < nr_uarts; line++) {
2969 port = &serial8250_ports[line].port;
2970 if (uart_match_port(p, port))
2971 return line;
2972 }
2973 return -ENODEV;
2974}
2975
2976#define SERIAL8250_CONSOLE &serial8250_console
2977#else
2978#define SERIAL8250_CONSOLE NULL
2979#endif
2980
2981static struct uart_driver serial8250_reg = {
2982 .owner = THIS_MODULE,
2983 .driver_name = "serial",
2984 .dev_name = "ttyS",
2985 .major = TTY_MAJOR,
2986 .minor = 64,
2987 .cons = SERIAL8250_CONSOLE,
2988};
2989
2990/*
2991 * early_serial_setup - early registration for 8250 ports
2992 *
2993 * Setup an 8250 port structure prior to console initialisation. Use
2994 * after console initialisation will cause undefined behaviour.
2995 */
2996int __init early_serial_setup(struct uart_port *port)
2997{
2998 struct uart_port *p;
2999
3000 if (port->line >= ARRAY_SIZE(serial8250_ports))
3001 return -ENODEV;
3002
3003 serial8250_isa_init_ports();
3004 p = &serial8250_ports[port->line].port;
3005 p->iobase = port->iobase;
3006 p->membase = port->membase;
3007 p->irq = port->irq;
3008 p->irqflags = port->irqflags;
3009 p->uartclk = port->uartclk;
3010 p->fifosize = port->fifosize;
3011 p->regshift = port->regshift;
3012 p->iotype = port->iotype;
3013 p->flags = port->flags;
3014 p->mapbase = port->mapbase;
3015 p->private_data = port->private_data;
3016 p->type = port->type;
3017 p->line = port->line;
3018
3019 set_io_from_upio(p);
3020 if (port->serial_in)
3021 p->serial_in = port->serial_in;
3022 if (port->serial_out)
3023 p->serial_out = port->serial_out;
3024 if (port->handle_irq)
3025 p->handle_irq = port->handle_irq;
3026 else
3027 p->handle_irq = serial8250_default_handle_irq;
3028
3029 return 0;
3030}
3031
3032/**
3033 * serial8250_suspend_port - suspend one serial port
3034 * @line: serial line number
3035 *
3036 * Suspend one serial port.
3037 */
3038void serial8250_suspend_port(int line)
3039{
3040 uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port);
3041}
3042
3043/**
3044 * serial8250_resume_port - resume one serial port
3045 * @line: serial line number
3046 *
3047 * Resume one serial port.
3048 */
3049void serial8250_resume_port(int line)
3050{
3051 struct uart_8250_port *up = &serial8250_ports[line];
3052 struct uart_port *port = &up->port;
3053
3054 if (up->capabilities & UART_NATSEMI) {
3055 /* Ensure it's still in high speed mode */
3056 serial_port_out(port, UART_LCR, 0xE0);
3057
3058 ns16550a_goto_highspeed(up);
3059
3060 serial_port_out(port, UART_LCR, 0);
3061 port->uartclk = 921600*16;
3062 }
3063 uart_resume_port(&serial8250_reg, port);
3064}
3065
3066/*
3067 * Register a set of serial devices attached to a platform device. The
3068 * list is terminated with a zero flags entry, which means we expect
3069 * all entries to have at least UPF_BOOT_AUTOCONF set.
3070 */
3071static int serial8250_probe(struct platform_device *dev)
3072{
3073 struct plat_serial8250_port *p = dev->dev.platform_data;
3074 struct uart_8250_port uart;
3075 int ret, i, irqflag = 0;
3076
3077 memset(&uart, 0, sizeof(uart));
3078
3079 if (share_irqs)
3080 irqflag = IRQF_SHARED;
3081
3082 for (i = 0; p && p->flags != 0; p++, i++) {
3083 uart.port.iobase = p->iobase;
3084 uart.port.membase = p->membase;
3085 uart.port.irq = p->irq;
3086 uart.port.irqflags = p->irqflags;
3087 uart.port.uartclk = p->uartclk;
3088 uart.port.regshift = p->regshift;
3089 uart.port.iotype = p->iotype;
3090 uart.port.flags = p->flags;
3091 uart.port.mapbase = p->mapbase;
3092 uart.port.hub6 = p->hub6;
3093 uart.port.private_data = p->private_data;
3094 uart.port.type = p->type;
3095 uart.port.serial_in = p->serial_in;
3096 uart.port.serial_out = p->serial_out;
3097 uart.port.handle_irq = p->handle_irq;
3098 uart.port.handle_break = p->handle_break;
3099 uart.port.set_termios = p->set_termios;
3100 uart.port.pm = p->pm;
3101 uart.port.dev = &dev->dev;
3102 uart.port.irqflags |= irqflag;
3103 ret = serial8250_register_8250_port(&uart);
3104 if (ret < 0) {
3105 dev_err(&dev->dev, "unable to register port at index %d "
3106 "(IO%lx MEM%llx IRQ%d): %d\n", i,
3107 p->iobase, (unsigned long long)p->mapbase,
3108 p->irq, ret);
3109 }
3110 }
3111 return 0;
3112}
3113
3114/*
3115 * Remove serial ports registered against a platform device.
3116 */
3117static int serial8250_remove(struct platform_device *dev)
3118{
3119 int i;
3120
3121 for (i = 0; i < nr_uarts; i++) {
3122 struct uart_8250_port *up = &serial8250_ports[i];
3123
3124 if (up->port.dev == &dev->dev)
3125 serial8250_unregister_port(i);
3126 }
3127 return 0;
3128}
3129
3130static int serial8250_suspend(struct platform_device *dev, pm_message_t state)
3131{
3132 int i;
3133
3134 for (i = 0; i < UART_NR; i++) {
3135 struct uart_8250_port *up = &serial8250_ports[i];
3136
3137 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
3138 uart_suspend_port(&serial8250_reg, &up->port);
3139 }
3140
3141 return 0;
3142}
3143
3144static int serial8250_resume(struct platform_device *dev)
3145{
3146 int i;
3147
3148 for (i = 0; i < UART_NR; i++) {
3149 struct uart_8250_port *up = &serial8250_ports[i];
3150
3151 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
3152 serial8250_resume_port(i);
3153 }
3154
3155 return 0;
3156}
3157
3158static struct platform_driver serial8250_isa_driver = {
3159 .probe = serial8250_probe,
3160 .remove = serial8250_remove,
3161 .suspend = serial8250_suspend,
3162 .resume = serial8250_resume,
3163 .driver = {
3164 .name = "serial8250",
3165 .owner = THIS_MODULE,
3166 },
3167};
3168
3169/*
3170 * This "device" covers _all_ ISA 8250-compatible serial devices listed
3171 * in the table in include/asm/serial.h
3172 */
3173static struct platform_device *serial8250_isa_devs;
3174
3175/*
3176 * serial8250_register_8250_port and serial8250_unregister_port allows for
3177 * 16x50 serial ports to be configured at run-time, to support PCMCIA
3178 * modems and PCI multiport cards.
3179 */
3180static DEFINE_MUTEX(serial_mutex);
3181
3182static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
3183{
3184 int i;
3185
3186 /*
3187 * First, find a port entry which matches.
3188 */
3189 for (i = 0; i < nr_uarts; i++)
3190 if (uart_match_port(&serial8250_ports[i].port, port))
3191 return &serial8250_ports[i];
3192
3193 /*
3194 * We didn't find a matching entry, so look for the first
3195 * free entry. We look for one which hasn't been previously
3196 * used (indicated by zero iobase).
3197 */
3198 for (i = 0; i < nr_uarts; i++)
3199 if (serial8250_ports[i].port.type == PORT_UNKNOWN &&
3200 serial8250_ports[i].port.iobase == 0)
3201 return &serial8250_ports[i];
3202
3203 /*
3204 * That also failed. Last resort is to find any entry which
3205 * doesn't have a real port associated with it.
3206 */
3207 for (i = 0; i < nr_uarts; i++)
3208 if (serial8250_ports[i].port.type == PORT_UNKNOWN)
3209 return &serial8250_ports[i];
3210
3211 return NULL;
3212}
3213
3214/**
3215 * serial8250_register_8250_port - register a serial port
3216 * @up: serial port template
3217 *
3218 * Configure the serial port specified by the request. If the
3219 * port exists and is in use, it is hung up and unregistered
3220 * first.
3221 *
3222 * The port is then probed and if necessary the IRQ is autodetected
3223 * If this fails an error is returned.
3224 *
3225 * On success the port is ready to use and the line number is returned.
3226 */
3227int serial8250_register_8250_port(struct uart_8250_port *up)
3228{
3229 struct uart_8250_port *uart;
3230 int ret = -ENOSPC;
3231
3232 if (up->port.uartclk == 0)
3233 return -EINVAL;
3234
3235 mutex_lock(&serial_mutex);
3236
3237 uart = serial8250_find_match_or_unused(&up->port);
3238 if (uart && uart->port.type != PORT_8250_CIR) {
3239 if (uart->port.dev)
3240 uart_remove_one_port(&serial8250_reg, &uart->port);
3241
3242 uart->port.iobase = up->port.iobase;
3243 uart->port.membase = up->port.membase;
3244 uart->port.irq = up->port.irq;
3245 uart->port.irqflags = up->port.irqflags;
3246 uart->port.uartclk = up->port.uartclk;
3247 uart->port.fifosize = up->port.fifosize;
3248 uart->port.regshift = up->port.regshift;
3249 uart->port.iotype = up->port.iotype;
3250 uart->port.flags = up->port.flags | UPF_BOOT_AUTOCONF;
3251 uart->bugs = up->bugs;
3252 uart->port.mapbase = up->port.mapbase;
3253 uart->port.private_data = up->port.private_data;
3254 if (up->port.dev)
3255 uart->port.dev = up->port.dev;
3256
3257 if (up->port.flags & UPF_FIXED_TYPE)
3258 serial8250_init_fixed_type_port(uart, up->port.type);
3259
3260 set_io_from_upio(&uart->port);
3261 /* Possibly override default I/O functions. */
3262 if (up->port.serial_in)
3263 uart->port.serial_in = up->port.serial_in;
3264 if (up->port.serial_out)
3265 uart->port.serial_out = up->port.serial_out;
3266 if (up->port.handle_irq)
3267 uart->port.handle_irq = up->port.handle_irq;
3268 /* Possibly override set_termios call */
3269 if (up->port.set_termios)
3270 uart->port.set_termios = up->port.set_termios;
3271 if (up->port.pm)
3272 uart->port.pm = up->port.pm;
3273 if (up->port.handle_break)
3274 uart->port.handle_break = up->port.handle_break;
3275 if (up->dl_read)
3276 uart->dl_read = up->dl_read;
3277 if (up->dl_write)
3278 uart->dl_write = up->dl_write;
3279
3280 if (serial8250_isa_config != NULL)
3281 serial8250_isa_config(0, &uart->port,
3282 &uart->capabilities);
3283
3284 ret = uart_add_one_port(&serial8250_reg, &uart->port);
3285 if (ret == 0)
3286 ret = uart->port.line;
3287 }
3288 mutex_unlock(&serial_mutex);
3289
3290 return ret;
3291}
3292EXPORT_SYMBOL(serial8250_register_8250_port);
3293
3294/**
3295 * serial8250_unregister_port - remove a 16x50 serial port at runtime
3296 * @line: serial line number
3297 *
3298 * Remove one serial port. This may not be called from interrupt
3299 * context. We hand the port back to the our control.
3300 */
3301void serial8250_unregister_port(int line)
3302{
3303 struct uart_8250_port *uart = &serial8250_ports[line];
3304
3305 mutex_lock(&serial_mutex);
3306 uart_remove_one_port(&serial8250_reg, &uart->port);
3307 if (serial8250_isa_devs) {
3308 uart->port.flags &= ~UPF_BOOT_AUTOCONF;
3309 uart->port.type = PORT_UNKNOWN;
3310 uart->port.dev = &serial8250_isa_devs->dev;
3311 uart->capabilities = uart_config[uart->port.type].flags;
3312 uart_add_one_port(&serial8250_reg, &uart->port);
3313 } else {
3314 uart->port.dev = NULL;
3315 }
3316 mutex_unlock(&serial_mutex);
3317}
3318EXPORT_SYMBOL(serial8250_unregister_port);
3319
3320static int __init serial8250_init(void)
3321{
3322 int ret;
3323
3324 serial8250_isa_init_ports();
3325
3326 printk(KERN_INFO "Serial: 8250/16550 driver, "
3327 "%d ports, IRQ sharing %sabled\n", nr_uarts,
3328 share_irqs ? "en" : "dis");
3329
3330#ifdef CONFIG_SPARC
3331 ret = sunserial_register_minors(&serial8250_reg, UART_NR);
3332#else
3333 serial8250_reg.nr = UART_NR;
3334 ret = uart_register_driver(&serial8250_reg);
3335#endif
3336 if (ret)
3337 goto out;
3338
3339 ret = serial8250_pnp_init();
3340 if (ret)
3341 goto unreg_uart_drv;
3342
3343 serial8250_isa_devs = platform_device_alloc("serial8250",
3344 PLAT8250_DEV_LEGACY);
3345 if (!serial8250_isa_devs) {
3346 ret = -ENOMEM;
3347 goto unreg_pnp;
3348 }
3349
3350 ret = platform_device_add(serial8250_isa_devs);
3351 if (ret)
3352 goto put_dev;
3353
3354 serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev);
3355
3356 ret = platform_driver_register(&serial8250_isa_driver);
3357 if (ret == 0)
3358 goto out;
3359
3360 platform_device_del(serial8250_isa_devs);
3361put_dev:
3362 platform_device_put(serial8250_isa_devs);
3363unreg_pnp:
3364 serial8250_pnp_exit();
3365unreg_uart_drv:
3366#ifdef CONFIG_SPARC
3367 sunserial_unregister_minors(&serial8250_reg, UART_NR);
3368#else
3369 uart_unregister_driver(&serial8250_reg);
3370#endif
3371out:
3372 return ret;
3373}
3374
3375static void __exit serial8250_exit(void)
3376{
3377 struct platform_device *isa_dev = serial8250_isa_devs;
3378
3379 /*
3380 * This tells serial8250_unregister_port() not to re-register
3381 * the ports (thereby making serial8250_isa_driver permanently
3382 * in use.)
3383 */
3384 serial8250_isa_devs = NULL;
3385
3386 platform_driver_unregister(&serial8250_isa_driver);
3387 platform_device_unregister(isa_dev);
3388
3389 serial8250_pnp_exit();
3390
3391#ifdef CONFIG_SPARC
3392 sunserial_unregister_minors(&serial8250_reg, UART_NR);
3393#else
3394 uart_unregister_driver(&serial8250_reg);
3395#endif
3396}
3397
3398module_init(serial8250_init);
3399module_exit(serial8250_exit);
3400
3401EXPORT_SYMBOL(serial8250_suspend_port);
3402EXPORT_SYMBOL(serial8250_resume_port);
3403
3404MODULE_LICENSE("GPL");
3405MODULE_DESCRIPTION("Generic 8250/16x50 serial driver");
3406
3407module_param(share_irqs, uint, 0644);
3408MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices"
3409 " (unsafe)");
3410
3411module_param(nr_uarts, uint, 0644);
3412MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");
3413
3414module_param(skip_txen_test, uint, 0644);
3415MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time");
3416
3417#ifdef CONFIG_SERIAL_8250_RSA
3418module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444);
3419MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
3420#endif
3421MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);
diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
deleted file mode 100644
index 3b4ea84898c..00000000000
--- a/drivers/tty/serial/8250/8250.h
+++ /dev/null
@@ -1,144 +0,0 @@
1/*
2 * Driver for 8250/16550-type serial ports
3 *
4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5 *
6 * Copyright (C) 2001 Russell King.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/serial_8250.h>
15
16struct old_serial_port {
17 unsigned int uart;
18 unsigned int baud_base;
19 unsigned int port;
20 unsigned int irq;
21 unsigned int flags;
22 unsigned char hub6;
23 unsigned char io_type;
24 unsigned char *iomem_base;
25 unsigned short iomem_reg_shift;
26 unsigned long irqflags;
27};
28
29struct serial8250_config {
30 const char *name;
31 unsigned short fifo_size;
32 unsigned short tx_loadsz;
33 unsigned char fcr;
34 unsigned int flags;
35};
36
37#define UART_CAP_FIFO (1 << 8) /* UART has FIFO */
38#define UART_CAP_EFR (1 << 9) /* UART has EFR */
39#define UART_CAP_SLEEP (1 << 10) /* UART has IER sleep */
40#define UART_CAP_AFE (1 << 11) /* MCR-based hw flow control */
41#define UART_CAP_UUE (1 << 12) /* UART needs IER bit 6 set (Xscale) */
42#define UART_CAP_RTOIE (1 << 13) /* UART needs IER bit 4 set (Xscale, Tegra) */
43
44#define UART_BUG_QUOT (1 << 0) /* UART has buggy quot LSB */
45#define UART_BUG_TXEN (1 << 1) /* UART has buggy TX IIR status */
46#define UART_BUG_NOMSR (1 << 2) /* UART has buggy MSR status bits (Au1x00) */
47#define UART_BUG_THRE (1 << 3) /* UART has buggy THRE reassertion */
48#define UART_BUG_PARITY (1 << 4) /* UART mishandles parity if FIFO enabled */
49
50#define PROBE_RSA (1 << 0)
51#define PROBE_ANY (~0)
52
53#define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
54
55#ifdef CONFIG_SERIAL_8250_SHARE_IRQ
56#define SERIAL8250_SHARE_IRQS 1
57#else
58#define SERIAL8250_SHARE_IRQS 0
59#endif
60
61static inline int serial_in(struct uart_8250_port *up, int offset)
62{
63 return up->port.serial_in(&up->port, offset);
64}
65
66static inline void serial_out(struct uart_8250_port *up, int offset, int value)
67{
68 up->port.serial_out(&up->port, offset, value);
69}
70
71void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);
72
73static inline int serial_dl_read(struct uart_8250_port *up)
74{
75 return up->dl_read(up);
76}
77
78static inline void serial_dl_write(struct uart_8250_port *up, int value)
79{
80 up->dl_write(up, value);
81}
82
83#if defined(__alpha__) && !defined(CONFIG_PCI)
84/*
85 * Digital did something really horribly wrong with the OUT1 and OUT2
86 * lines on at least some ALPHA's. The failure mode is that if either
87 * is cleared, the machine locks up with endless interrupts.
88 */
89#define ALPHA_KLUDGE_MCR (UART_MCR_OUT2 | UART_MCR_OUT1)
90#elif defined(CONFIG_SBC8560)
91/*
92 * WindRiver did something similarly broken on their SBC8560 board. The
93 * UART tristates its IRQ output while OUT2 is clear, but they pulled
94 * the interrupt line _up_ instead of down, so if we register the IRQ
95 * while the UART is in that state, we die in an IRQ storm. */
96#define ALPHA_KLUDGE_MCR (UART_MCR_OUT2)
97#else
98#define ALPHA_KLUDGE_MCR 0
99#endif
100
101#ifdef CONFIG_SERIAL_8250_PNP
102int serial8250_pnp_init(void);
103void serial8250_pnp_exit(void);
104#else
105static inline int serial8250_pnp_init(void) { return 0; }
106static inline void serial8250_pnp_exit(void) { }
107#endif
108
109#ifdef CONFIG_ARCH_OMAP1
110static inline int is_omap1_8250(struct uart_8250_port *pt)
111{
112 int res;
113
114 switch (pt->port.mapbase) {
115 case OMAP1_UART1_BASE:
116 case OMAP1_UART2_BASE:
117 case OMAP1_UART3_BASE:
118 res = 1;
119 break;
120 default:
121 res = 0;
122 break;
123 }
124
125 return res;
126}
127
128static inline int is_omap1510_8250(struct uart_8250_port *pt)
129{
130 if (!cpu_is_omap1510())
131 return 0;
132
133 return is_omap1_8250(pt);
134}
135#else
136static inline int is_omap1_8250(struct uart_8250_port *pt)
137{
138 return 0;
139}
140static inline int is_omap1510_8250(struct uart_8250_port *pt)
141{
142 return 0;
143}
144#endif
diff --git a/drivers/tty/serial/8250/8250_accent.c b/drivers/tty/serial/8250/8250_accent.c
deleted file mode 100644
index 34b51c65119..00000000000
--- a/drivers/tty/serial/8250/8250_accent.c
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * Copyright (C) 2005 Russell King.
3 * Data taken from include/asm-i386/serial.h
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/serial_8250.h>
12
13#define PORT(_base,_irq) \
14 { \
15 .iobase = _base, \
16 .irq = _irq, \
17 .uartclk = 1843200, \
18 .iotype = UPIO_PORT, \
19 .flags = UPF_BOOT_AUTOCONF, \
20 }
21
22static struct plat_serial8250_port accent_data[] = {
23 PORT(0x330, 4),
24 PORT(0x338, 4),
25 { },
26};
27
28static struct platform_device accent_device = {
29 .name = "serial8250",
30 .id = PLAT8250_DEV_ACCENT,
31 .dev = {
32 .platform_data = accent_data,
33 },
34};
35
36static int __init accent_init(void)
37{
38 return platform_device_register(&accent_device);
39}
40
41module_init(accent_init);
42
43MODULE_AUTHOR("Russell King");
44MODULE_DESCRIPTION("8250 serial probe module for Accent Async cards");
45MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/8250/8250_acorn.c b/drivers/tty/serial/8250/8250_acorn.c
deleted file mode 100644
index 549aa07c0d2..00000000000
--- a/drivers/tty/serial/8250/8250_acorn.c
+++ /dev/null
@@ -1,141 +0,0 @@
1/*
2 * linux/drivers/serial/acorn.c
3 *
4 * Copyright (C) 1996-2003 Russell King.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/tty.h>
13#include <linux/serial_core.h>
14#include <linux/errno.h>
15#include <linux/ioport.h>
16#include <linux/slab.h>
17#include <linux/device.h>
18#include <linux/init.h>
19
20#include <asm/io.h>
21#include <asm/ecard.h>
22#include <asm/string.h>
23
24#include "8250.h"
25
26#define MAX_PORTS 3
27
28struct serial_card_type {
29 unsigned int num_ports;
30 unsigned int uartclk;
31 unsigned int type;
32 unsigned int offset[MAX_PORTS];
33};
34
35struct serial_card_info {
36 unsigned int num_ports;
37 int ports[MAX_PORTS];
38 void __iomem *vaddr;
39};
40
41static int
42serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
43{
44 struct serial_card_info *info;
45 struct serial_card_type *type = id->data;
46 struct uart_8250_port uart;
47 unsigned long bus_addr;
48 unsigned int i;
49
50 info = kzalloc(sizeof(struct serial_card_info), GFP_KERNEL);
51 if (!info)
52 return -ENOMEM;
53
54 info->num_ports = type->num_ports;
55
56 bus_addr = ecard_resource_start(ec, type->type);
57 info->vaddr = ecardm_iomap(ec, type->type, 0, 0);
58 if (!info->vaddr) {
59 kfree(info);
60 return -ENOMEM;
61 }
62
63 ecard_set_drvdata(ec, info);
64
65 memset(&uart, 0, sizeof(struct uart_8250_port));
66 uart.port.irq = ec->irq;
67 uart.port.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
68 uart.port.uartclk = type->uartclk;
69 uart.port.iotype = UPIO_MEM;
70 uart.port.regshift = 2;
71 uart.port.dev = &ec->dev;
72
73 for (i = 0; i < info->num_ports; i ++) {
74 uart.port.membase = info->vaddr + type->offset[i];
75 uart.port.mapbase = bus_addr + type->offset[i];
76
77 info->ports[i] = serial8250_register_8250_port(&uart);
78 }
79
80 return 0;
81}
82
83static void serial_card_remove(struct expansion_card *ec)
84{
85 struct serial_card_info *info = ecard_get_drvdata(ec);
86 int i;
87
88 ecard_set_drvdata(ec, NULL);
89
90 for (i = 0; i < info->num_ports; i++)
91 if (info->ports[i] > 0)
92 serial8250_unregister_port(info->ports[i]);
93
94 kfree(info);
95}
96
97static struct serial_card_type atomwide_type = {
98 .num_ports = 3,
99 .uartclk = 7372800,
100 .type = ECARD_RES_IOCSLOW,
101 .offset = { 0x2800, 0x2400, 0x2000 },
102};
103
104static struct serial_card_type serport_type = {
105 .num_ports = 2,
106 .uartclk = 3686400,
107 .type = ECARD_RES_IOCSLOW,
108 .offset = { 0x2000, 0x2020 },
109};
110
111static const struct ecard_id serial_cids[] = {
112 { MANU_ATOMWIDE, PROD_ATOMWIDE_3PSERIAL, &atomwide_type },
113 { MANU_SERPORT, PROD_SERPORT_DSPORT, &serport_type },
114 { 0xffff, 0xffff }
115};
116
117static struct ecard_driver serial_card_driver = {
118 .probe = serial_card_probe,
119 .remove = serial_card_remove,
120 .id_table = serial_cids,
121 .drv = {
122 .name = "8250_acorn",
123 },
124};
125
126static int __init serial_card_init(void)
127{
128 return ecard_register_driver(&serial_card_driver);
129}
130
131static void __exit serial_card_exit(void)
132{
133 ecard_remove_driver(&serial_card_driver);
134}
135
136MODULE_AUTHOR("Russell King");
137MODULE_DESCRIPTION("Acorn 8250-compatible serial port expansion card driver");
138MODULE_LICENSE("GPL");
139
140module_init(serial_card_init);
141module_exit(serial_card_exit);
diff --git a/drivers/tty/serial/8250/8250_boca.c b/drivers/tty/serial/8250/8250_boca.c
deleted file mode 100644
index d125dc10798..00000000000
--- a/drivers/tty/serial/8250/8250_boca.c
+++ /dev/null
@@ -1,59 +0,0 @@
1/*
2 * Copyright (C) 2005 Russell King.
3 * Data taken from include/asm-i386/serial.h
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/serial_8250.h>
12
13#define PORT(_base,_irq) \
14 { \
15 .iobase = _base, \
16 .irq = _irq, \
17 .uartclk = 1843200, \
18 .iotype = UPIO_PORT, \
19 .flags = UPF_BOOT_AUTOCONF, \
20 }
21
22static struct plat_serial8250_port boca_data[] = {
23 PORT(0x100, 12),
24 PORT(0x108, 12),
25 PORT(0x110, 12),
26 PORT(0x118, 12),
27 PORT(0x120, 12),
28 PORT(0x128, 12),
29 PORT(0x130, 12),
30 PORT(0x138, 12),
31 PORT(0x140, 12),
32 PORT(0x148, 12),
33 PORT(0x150, 12),
34 PORT(0x158, 12),
35 PORT(0x160, 12),
36 PORT(0x168, 12),
37 PORT(0x170, 12),
38 PORT(0x178, 12),
39 { },
40};
41
42static struct platform_device boca_device = {
43 .name = "serial8250",
44 .id = PLAT8250_DEV_BOCA,
45 .dev = {
46 .platform_data = boca_data,
47 },
48};
49
50static int __init boca_init(void)
51{
52 return platform_device_register(&boca_device);
53}
54
55module_init(boca_init);
56
57MODULE_AUTHOR("Russell King");
58MODULE_DESCRIPTION("8250 serial probe module for Boca cards");
59MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
deleted file mode 100644
index 1d0dba2d562..00000000000
--- a/drivers/tty/serial/8250/8250_dw.c
+++ /dev/null
@@ -1,209 +0,0 @@
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 dw8250_probe(struct platform_device *pdev)
91{
92 struct uart_8250_port uart = {};
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 uart.port.private_data = data;
108
109 spin_lock_init(&uart.port.lock);
110 uart.port.mapbase = regs->start;
111 uart.port.irq = irq->start;
112 uart.port.handle_irq = dw8250_handle_irq;
113 uart.port.type = PORT_8250;
114 uart.port.flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP |
115 UPF_FIXED_PORT | UPF_FIXED_TYPE;
116 uart.port.dev = &pdev->dev;
117
118 uart.port.iotype = UPIO_MEM;
119 uart.port.serial_in = dw8250_serial_in;
120 uart.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 uart.port.iotype = UPIO_MEM32;
127 uart.port.serial_in = dw8250_serial_in32;
128 uart.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 uart.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 uart.port.uartclk = val;
145
146 data->line = serial8250_register_8250_port(&uart);
147 if (data->line < 0)
148 return data->line;
149
150 platform_set_drvdata(pdev, data);
151
152 return 0;
153}
154
155static int 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
164#ifdef CONFIG_PM
165static int dw8250_suspend(struct platform_device *pdev, pm_message_t state)
166{
167 struct dw8250_data *data = platform_get_drvdata(pdev);
168
169 serial8250_suspend_port(data->line);
170
171 return 0;
172}
173
174static int dw8250_resume(struct platform_device *pdev)
175{
176 struct dw8250_data *data = platform_get_drvdata(pdev);
177
178 serial8250_resume_port(data->line);
179
180 return 0;
181}
182#else
183#define dw8250_suspend NULL
184#define dw8250_resume NULL
185#endif /* CONFIG_PM */
186
187static const struct of_device_id dw8250_match[] = {
188 { .compatible = "snps,dw-apb-uart" },
189 { /* Sentinel */ }
190};
191MODULE_DEVICE_TABLE(of, dw8250_match);
192
193static struct platform_driver dw8250_platform_driver = {
194 .driver = {
195 .name = "dw-apb-uart",
196 .owner = THIS_MODULE,
197 .of_match_table = dw8250_match,
198 },
199 .probe = dw8250_probe,
200 .remove = dw8250_remove,
201 .suspend = dw8250_suspend,
202 .resume = dw8250_resume,
203};
204
205module_platform_driver(dw8250_platform_driver);
206
207MODULE_AUTHOR("Jamie Iles");
208MODULE_LICENSE("GPL");
209MODULE_DESCRIPTION("Synopsys DesignWare 8250 serial port driver");
diff --git a/drivers/tty/serial/8250/8250_early.c b/drivers/tty/serial/8250/8250_early.c
deleted file mode 100644
index f53a7db4350..00000000000
--- a/drivers/tty/serial/8250/8250_early.c
+++ /dev/null
@@ -1,287 +0,0 @@
1/*
2 * Early serial console for 8250/16550 devices
3 *
4 * (c) Copyright 2004 Hewlett-Packard Development Company, L.P.
5 * Bjorn Helgaas <bjorn.helgaas@hp.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Based on the 8250.c serial driver, Copyright (C) 2001 Russell King,
12 * and on early_printk.c by Andi Kleen.
13 *
14 * This is for use before the serial driver has initialized, in
15 * particular, before the UARTs have been discovered and named.
16 * Instead of specifying the console device as, e.g., "ttyS0",
17 * we locate the device directly by its MMIO or I/O port address.
18 *
19 * The user can specify the device directly, e.g.,
20 * earlycon=uart8250,io,0x3f8,9600n8
21 * earlycon=uart8250,mmio,0xff5e0000,115200n8
22 * earlycon=uart8250,mmio32,0xff5e0000,115200n8
23 * or
24 * console=uart8250,io,0x3f8,9600n8
25 * console=uart8250,mmio,0xff5e0000,115200n8
26 * console=uart8250,mmio32,0xff5e0000,115200n8
27 */
28
29#include <linux/tty.h>
30#include <linux/init.h>
31#include <linux/console.h>
32#include <linux/serial_core.h>
33#include <linux/serial_reg.h>
34#include <linux/serial.h>
35#include <linux/serial_8250.h>
36#include <asm/io.h>
37#include <asm/serial.h>
38#ifdef CONFIG_FIX_EARLYCON_MEM
39#include <asm/pgtable.h>
40#include <asm/fixmap.h>
41#endif
42
43struct early_serial8250_device {
44 struct uart_port port;
45 char options[16]; /* e.g., 115200n8 */
46 unsigned int baud;
47};
48
49static struct early_serial8250_device early_device;
50
51unsigned int __weak __init serial8250_early_in(struct uart_port *port, int offset)
52{
53 switch (port->iotype) {
54 case UPIO_MEM:
55 return readb(port->membase + offset);
56 case UPIO_MEM32:
57 return readl(port->membase + (offset << 2));
58 case UPIO_PORT:
59 return inb(port->iobase + offset);
60 default:
61 return 0;
62 }
63}
64
65void __weak __init serial8250_early_out(struct uart_port *port, int offset, int value)
66{
67 switch (port->iotype) {
68 case UPIO_MEM:
69 writeb(value, port->membase + offset);
70 break;
71 case UPIO_MEM32:
72 writel(value, port->membase + (offset << 2));
73 break;
74 case UPIO_PORT:
75 outb(value, port->iobase + offset);
76 break;
77 }
78}
79
80#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
81
82static void __init wait_for_xmitr(struct uart_port *port)
83{
84 unsigned int status;
85
86 for (;;) {
87 status = serial8250_early_in(port, UART_LSR);
88 if ((status & BOTH_EMPTY) == BOTH_EMPTY)
89 return;
90 cpu_relax();
91 }
92}
93
94static void __init serial_putc(struct uart_port *port, int c)
95{
96 wait_for_xmitr(port);
97 serial8250_early_out(port, UART_TX, c);
98}
99
100static void __init early_serial8250_write(struct console *console,
101 const char *s, unsigned int count)
102{
103 struct uart_port *port = &early_device.port;
104 unsigned int ier;
105
106 /* Save the IER and disable interrupts */
107 ier = serial8250_early_in(port, UART_IER);
108 serial8250_early_out(port, UART_IER, 0);
109
110 uart_console_write(port, s, count, serial_putc);
111
112 /* Wait for transmitter to become empty and restore the IER */
113 wait_for_xmitr(port);
114 serial8250_early_out(port, UART_IER, ier);
115}
116
117static unsigned int __init probe_baud(struct uart_port *port)
118{
119 unsigned char lcr, dll, dlm;
120 unsigned int quot;
121
122 lcr = serial8250_early_in(port, UART_LCR);
123 serial8250_early_out(port, UART_LCR, lcr | UART_LCR_DLAB);
124 dll = serial8250_early_in(port, UART_DLL);
125 dlm = serial8250_early_in(port, UART_DLM);
126 serial8250_early_out(port, UART_LCR, lcr);
127
128 quot = (dlm << 8) | dll;
129 return (port->uartclk / 16) / quot;
130}
131
132static void __init init_port(struct early_serial8250_device *device)
133{
134 struct uart_port *port = &device->port;
135 unsigned int divisor;
136 unsigned char c;
137
138 serial8250_early_out(port, UART_LCR, 0x3); /* 8n1 */
139 serial8250_early_out(port, UART_IER, 0); /* no interrupt */
140 serial8250_early_out(port, UART_FCR, 0); /* no fifo */
141 serial8250_early_out(port, UART_MCR, 0x3); /* DTR + RTS */
142
143 divisor = DIV_ROUND_CLOSEST(port->uartclk, 16 * device->baud);
144 c = serial8250_early_in(port, UART_LCR);
145 serial8250_early_out(port, UART_LCR, c | UART_LCR_DLAB);
146 serial8250_early_out(port, UART_DLL, divisor & 0xff);
147 serial8250_early_out(port, UART_DLM, (divisor >> 8) & 0xff);
148 serial8250_early_out(port, UART_LCR, c & ~UART_LCR_DLAB);
149}
150
151static int __init parse_options(struct early_serial8250_device *device,
152 char *options)
153{
154 struct uart_port *port = &device->port;
155 int mmio, mmio32, length;
156
157 if (!options)
158 return -ENODEV;
159
160 port->uartclk = BASE_BAUD * 16;
161
162 mmio = !strncmp(options, "mmio,", 5);
163 mmio32 = !strncmp(options, "mmio32,", 7);
164 if (mmio || mmio32) {
165 port->iotype = (mmio ? UPIO_MEM : UPIO_MEM32);
166 port->mapbase = simple_strtoul(options + (mmio ? 5 : 7),
167 &options, 0);
168 if (mmio32)
169 port->regshift = 2;
170#ifdef CONFIG_FIX_EARLYCON_MEM
171 set_fixmap_nocache(FIX_EARLYCON_MEM_BASE,
172 port->mapbase & PAGE_MASK);
173 port->membase =
174 (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
175 port->membase += port->mapbase & ~PAGE_MASK;
176#else
177 port->membase = ioremap_nocache(port->mapbase, 64);
178 if (!port->membase) {
179 printk(KERN_ERR "%s: Couldn't ioremap 0x%llx\n",
180 __func__,
181 (unsigned long long) port->mapbase);
182 return -ENOMEM;
183 }
184#endif
185 } else if (!strncmp(options, "io,", 3)) {
186 port->iotype = UPIO_PORT;
187 port->iobase = simple_strtoul(options + 3, &options, 0);
188 mmio = 0;
189 } else
190 return -EINVAL;
191
192 options = strchr(options, ',');
193 if (options) {
194 options++;
195 device->baud = simple_strtoul(options, NULL, 0);
196 length = min(strcspn(options, " "), sizeof(device->options));
197 strncpy(device->options, options, length);
198 } else {
199 device->baud = probe_baud(port);
200 snprintf(device->options, sizeof(device->options), "%u",
201 device->baud);
202 }
203
204 if (mmio || mmio32)
205 printk(KERN_INFO
206 "Early serial console at MMIO%s 0x%llx (options '%s')\n",
207 mmio32 ? "32" : "",
208 (unsigned long long)port->mapbase,
209 device->options);
210 else
211 printk(KERN_INFO
212 "Early serial console at I/O port 0x%lx (options '%s')\n",
213 port->iobase,
214 device->options);
215
216 return 0;
217}
218
219static struct console early_serial8250_console __initdata = {
220 .name = "uart",
221 .write = early_serial8250_write,
222 .flags = CON_PRINTBUFFER | CON_BOOT,
223 .index = -1,
224};
225
226static int __init early_serial8250_setup(char *options)
227{
228 struct early_serial8250_device *device = &early_device;
229 int err;
230
231 if (device->port.membase || device->port.iobase)
232 return 0;
233
234 err = parse_options(device, options);
235 if (err < 0)
236 return err;
237
238 init_port(device);
239 return 0;
240}
241
242int __init setup_early_serial8250_console(char *cmdline)
243{
244 char *options;
245 int err;
246
247 options = strstr(cmdline, "uart8250,");
248 if (!options) {
249 options = strstr(cmdline, "uart,");
250 if (!options)
251 return 0;
252 }
253
254 options = strchr(cmdline, ',') + 1;
255 err = early_serial8250_setup(options);
256 if (err < 0)
257 return err;
258
259 register_console(&early_serial8250_console);
260
261 return 0;
262}
263
264int serial8250_find_port_for_earlycon(void)
265{
266 struct early_serial8250_device *device = &early_device;
267 struct uart_port *port = &device->port;
268 int line;
269 int ret;
270
271 if (!device->port.membase && !device->port.iobase)
272 return -ENODEV;
273
274 line = serial8250_find_port(port);
275 if (line < 0)
276 return -ENODEV;
277
278 ret = update_console_cmdline("uart", 8250,
279 "ttyS", line, device->options);
280 if (ret < 0)
281 ret = update_console_cmdline("uart", 0,
282 "ttyS", line, device->options);
283
284 return ret;
285}
286
287early_param("earlycon", setup_early_serial8250_console);
diff --git a/drivers/tty/serial/8250/8250_em.c b/drivers/tty/serial/8250/8250_em.c
deleted file mode 100644
index 916cc19fbbd..00000000000
--- a/drivers/tty/serial/8250/8250_em.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/*
2 * Renesas Emma Mobile 8250 driver
3 *
4 * Copyright (C) 2012 Magnus Damm
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
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/device.h>
21#include <linux/init.h>
22#include <linux/io.h>
23#include <linux/module.h>
24#include <linux/serial_8250.h>
25#include <linux/serial_core.h>
26#include <linux/serial_reg.h>
27#include <linux/platform_device.h>
28#include <linux/clk.h>
29#include <linux/slab.h>
30
31#include "8250.h"
32
33#define UART_DLL_EM 9
34#define UART_DLM_EM 10
35
36struct serial8250_em_priv {
37 struct clk *sclk;
38 int line;
39};
40
41static void serial8250_em_serial_out(struct uart_port *p, int offset, int value)
42{
43 switch (offset) {
44 case UART_TX: /* TX @ 0x00 */
45 writeb(value, p->membase);
46 break;
47 case UART_FCR: /* FCR @ 0x0c (+1) */
48 case UART_LCR: /* LCR @ 0x10 (+1) */
49 case UART_MCR: /* MCR @ 0x14 (+1) */
50 case UART_SCR: /* SCR @ 0x20 (+1) */
51 writel(value, p->membase + ((offset + 1) << 2));
52 break;
53 case UART_IER: /* IER @ 0x04 */
54 value &= 0x0f; /* only 4 valid bits - not Xscale */
55 /* fall-through */
56 case UART_DLL_EM: /* DLL @ 0x24 (+9) */
57 case UART_DLM_EM: /* DLM @ 0x28 (+9) */
58 writel(value, p->membase + (offset << 2));
59 }
60}
61
62static unsigned int serial8250_em_serial_in(struct uart_port *p, int offset)
63{
64 switch (offset) {
65 case UART_RX: /* RX @ 0x00 */
66 return readb(p->membase);
67 case UART_MCR: /* MCR @ 0x14 (+1) */
68 case UART_LSR: /* LSR @ 0x18 (+1) */
69 case UART_MSR: /* MSR @ 0x1c (+1) */
70 case UART_SCR: /* SCR @ 0x20 (+1) */
71 return readl(p->membase + ((offset + 1) << 2));
72 case UART_IER: /* IER @ 0x04 */
73 case UART_IIR: /* IIR @ 0x08 */
74 case UART_DLL_EM: /* DLL @ 0x24 (+9) */
75 case UART_DLM_EM: /* DLM @ 0x28 (+9) */
76 return readl(p->membase + (offset << 2));
77 }
78 return 0;
79}
80
81static int serial8250_em_serial_dl_read(struct uart_8250_port *up)
82{
83 return serial_in(up, UART_DLL_EM) | serial_in(up, UART_DLM_EM) << 8;
84}
85
86static void serial8250_em_serial_dl_write(struct uart_8250_port *up, int value)
87{
88 serial_out(up, UART_DLL_EM, value & 0xff);
89 serial_out(up, UART_DLM_EM, value >> 8 & 0xff);
90}
91
92static int serial8250_em_probe(struct platform_device *pdev)
93{
94 struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
95 struct resource *irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
96 struct serial8250_em_priv *priv;
97 struct uart_8250_port up;
98 int ret = -EINVAL;
99
100 if (!regs || !irq) {
101 dev_err(&pdev->dev, "missing registers or irq\n");
102 goto err0;
103 }
104
105 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
106 if (!priv) {
107 dev_err(&pdev->dev, "unable to allocate private data\n");
108 ret = -ENOMEM;
109 goto err0;
110 }
111
112 priv->sclk = clk_get(&pdev->dev, "sclk");
113 if (IS_ERR(priv->sclk)) {
114 dev_err(&pdev->dev, "unable to get clock\n");
115 ret = PTR_ERR(priv->sclk);
116 goto err1;
117 }
118
119 memset(&up, 0, sizeof(up));
120 up.port.mapbase = regs->start;
121 up.port.irq = irq->start;
122 up.port.type = PORT_UNKNOWN;
123 up.port.flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_IOREMAP;
124 up.port.dev = &pdev->dev;
125 up.port.private_data = priv;
126
127 clk_enable(priv->sclk);
128 up.port.uartclk = clk_get_rate(priv->sclk);
129
130 up.port.iotype = UPIO_MEM32;
131 up.port.serial_in = serial8250_em_serial_in;
132 up.port.serial_out = serial8250_em_serial_out;
133 up.dl_read = serial8250_em_serial_dl_read;
134 up.dl_write = serial8250_em_serial_dl_write;
135
136 ret = serial8250_register_8250_port(&up);
137 if (ret < 0) {
138 dev_err(&pdev->dev, "unable to register 8250 port\n");
139 goto err2;
140 }
141
142 priv->line = ret;
143 platform_set_drvdata(pdev, priv);
144 return 0;
145
146 err2:
147 clk_disable(priv->sclk);
148 clk_put(priv->sclk);
149 err1:
150 kfree(priv);
151 err0:
152 return ret;
153}
154
155static int serial8250_em_remove(struct platform_device *pdev)
156{
157 struct serial8250_em_priv *priv = platform_get_drvdata(pdev);
158
159 serial8250_unregister_port(priv->line);
160 clk_disable(priv->sclk);
161 clk_put(priv->sclk);
162 kfree(priv);
163 return 0;
164}
165
166static const struct of_device_id serial8250_em_dt_ids[] = {
167 { .compatible = "renesas,em-uart", },
168 {},
169};
170MODULE_DEVICE_TABLE(of, serial8250_em_dt_ids);
171
172static struct platform_driver serial8250_em_platform_driver = {
173 .driver = {
174 .name = "serial8250-em",
175 .of_match_table = serial8250_em_dt_ids,
176 .owner = THIS_MODULE,
177 },
178 .probe = serial8250_em_probe,
179 .remove = serial8250_em_remove,
180};
181
182module_platform_driver(serial8250_em_platform_driver);
183
184MODULE_AUTHOR("Magnus Damm");
185MODULE_DESCRIPTION("Renesas Emma Mobile 8250 Driver");
186MODULE_LICENSE("GPL v2");
diff --git a/drivers/tty/serial/8250/8250_exar_st16c554.c b/drivers/tty/serial/8250/8250_exar_st16c554.c
deleted file mode 100644
index bf53aabf9b5..00000000000
--- a/drivers/tty/serial/8250/8250_exar_st16c554.c
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 * Written by Paul B Schroeder < pschroeder "at" uplogix "dot" com >
3 * Based on 8250_boca.
4 *
5 * Copyright (C) 2005 Russell King.
6 * Data taken from include/asm-i386/serial.h
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/serial_8250.h>
15
16#define PORT(_base,_irq) \
17 { \
18 .iobase = _base, \
19 .irq = _irq, \
20 .uartclk = 1843200, \
21 .iotype = UPIO_PORT, \
22 .flags = UPF_BOOT_AUTOCONF, \
23 }
24
25static struct plat_serial8250_port exar_data[] = {
26 PORT(0x100, 5),
27 PORT(0x108, 5),
28 PORT(0x110, 5),
29 PORT(0x118, 5),
30 { },
31};
32
33static struct platform_device exar_device = {
34 .name = "serial8250",
35 .id = PLAT8250_DEV_EXAR_ST16C554,
36 .dev = {
37 .platform_data = exar_data,
38 },
39};
40
41static int __init exar_init(void)
42{
43 return platform_device_register(&exar_device);
44}
45
46module_init(exar_init);
47
48MODULE_AUTHOR("Paul B Schroeder");
49MODULE_DESCRIPTION("8250 serial probe module for Exar cards");
50MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/8250/8250_fourport.c b/drivers/tty/serial/8250/8250_fourport.c
deleted file mode 100644
index be158260962..00000000000
--- a/drivers/tty/serial/8250/8250_fourport.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * Copyright (C) 2005 Russell King.
3 * Data taken from include/asm-i386/serial.h
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/serial_8250.h>
12
13#define PORT(_base,_irq) \
14 { \
15 .iobase = _base, \
16 .irq = _irq, \
17 .uartclk = 1843200, \
18 .iotype = UPIO_PORT, \
19 .flags = UPF_BOOT_AUTOCONF | UPF_FOURPORT, \
20 }
21
22static struct plat_serial8250_port fourport_data[] = {
23 PORT(0x1a0, 9),
24 PORT(0x1a8, 9),
25 PORT(0x1b0, 9),
26 PORT(0x1b8, 9),
27 PORT(0x2a0, 5),
28 PORT(0x2a8, 5),
29 PORT(0x2b0, 5),
30 PORT(0x2b8, 5),
31 { },
32};
33
34static struct platform_device fourport_device = {
35 .name = "serial8250",
36 .id = PLAT8250_DEV_FOURPORT,
37 .dev = {
38 .platform_data = fourport_data,
39 },
40};
41
42static int __init fourport_init(void)
43{
44 return platform_device_register(&fourport_device);
45}
46
47module_init(fourport_init);
48
49MODULE_AUTHOR("Russell King");
50MODULE_DESCRIPTION("8250 serial probe module for AST Fourport cards");
51MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/8250/8250_fsl.c b/drivers/tty/serial/8250/8250_fsl.c
deleted file mode 100644
index f4d3c47b88e..00000000000
--- a/drivers/tty/serial/8250/8250_fsl.c
+++ /dev/null
@@ -1,63 +0,0 @@
1#include <linux/serial_reg.h>
2#include <linux/serial_8250.h>
3
4#include "8250.h"
5
6/*
7 * Freescale 16550 UART "driver", Copyright (C) 2011 Paul Gortmaker.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This isn't a full driver; it just provides an alternate IRQ
14 * handler to deal with an errata. Everything else is just
15 * using the bog standard 8250 support.
16 *
17 * We follow code flow of serial8250_default_handle_irq() but add
18 * a check for a break and insert a dummy read on the Rx for the
19 * immediately following IRQ event.
20 *
21 * We re-use the already existing "bug handling" lsr_saved_flags
22 * field to carry the "what we just did" information from the one
23 * IRQ event to the next one.
24 */
25
26int fsl8250_handle_irq(struct uart_port *port)
27{
28 unsigned char lsr, orig_lsr;
29 unsigned long flags;
30 unsigned int iir;
31 struct uart_8250_port *up =
32 container_of(port, struct uart_8250_port, port);
33
34 spin_lock_irqsave(&up->port.lock, flags);
35
36 iir = port->serial_in(port, UART_IIR);
37 if (iir & UART_IIR_NO_INT) {
38 spin_unlock_irqrestore(&up->port.lock, flags);
39 return 0;
40 }
41
42 /* This is the WAR; if last event was BRK, then read and return */
43 if (unlikely(up->lsr_saved_flags & UART_LSR_BI)) {
44 up->lsr_saved_flags &= ~UART_LSR_BI;
45 port->serial_in(port, UART_RX);
46 spin_unlock_irqrestore(&up->port.lock, flags);
47 return 1;
48 }
49
50 lsr = orig_lsr = up->port.serial_in(&up->port, UART_LSR);
51
52 if (lsr & (UART_LSR_DR | UART_LSR_BI))
53 lsr = serial8250_rx_chars(up, lsr);
54
55 serial8250_modem_status(up);
56
57 if (lsr & UART_LSR_THRE)
58 serial8250_tx_chars(up);
59
60 up->lsr_saved_flags = orig_lsr;
61 spin_unlock_irqrestore(&up->port.lock, flags);
62 return 1;
63}
diff --git a/drivers/tty/serial/8250/8250_gsc.c b/drivers/tty/serial/8250/8250_gsc.c
deleted file mode 100644
index 097dff9c08a..00000000000
--- a/drivers/tty/serial/8250/8250_gsc.c
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 * Serial Device Initialisation for Lasi/Asp/Wax/Dino
3 *
4 * (c) Copyright Matthew Wilcox <willy@debian.org> 2001-2002
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
12#include <linux/errno.h>
13#include <linux/init.h>
14#include <linux/interrupt.h>
15#include <linux/ioport.h>
16#include <linux/module.h>
17#include <linux/serial_core.h>
18#include <linux/signal.h>
19#include <linux/types.h>
20
21#include <asm/hardware.h>
22#include <asm/parisc-device.h>
23#include <asm/io.h>
24
25#include "8250.h"
26
27static int __init serial_init_chip(struct parisc_device *dev)
28{
29 struct uart_8250_port uart;
30 unsigned long address;
31 int err;
32
33 if (!dev->irq) {
34 /* We find some unattached serial ports by walking native
35 * busses. These should be silently ignored. Otherwise,
36 * what we have here is a missing parent device, so tell
37 * the user what they're missing.
38 */
39 if (parisc_parent(dev)->id.hw_type != HPHW_IOA)
40 printk(KERN_INFO
41 "Serial: device 0x%llx not configured.\n"
42 "Enable support for Wax, Lasi, Asp or Dino.\n",
43 (unsigned long long)dev->hpa.start);
44 return -ENODEV;
45 }
46
47 address = dev->hpa.start;
48 if (dev->id.sversion != 0x8d)
49 address += 0x800;
50
51 memset(&uart, 0, sizeof(uart));
52 uart.port.iotype = UPIO_MEM;
53 /* 7.272727MHz on Lasi. Assumed the same for Dino, Wax and Timi. */
54 uart.port.uartclk = 7272727;
55 uart.port.mapbase = address;
56 uart.port.membase = ioremap_nocache(address, 16);
57 uart.port.irq = dev->irq;
58 uart.port.flags = UPF_BOOT_AUTOCONF;
59 uart.port.dev = &dev->dev;
60
61 err = serial8250_register_8250_port(&uart);
62 if (err < 0) {
63 printk(KERN_WARNING
64 "serial8250_register_8250_port returned error %d\n", err);
65 iounmap(uart.port.membase);
66 return err;
67 }
68
69 return 0;
70}
71
72static struct parisc_device_id serial_tbl[] = {
73 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00075 },
74 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008c },
75 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0008d },
76 { 0 }
77};
78
79/* Hack. Some machines have SERIAL_0 attached to Lasi and SERIAL_1
80 * attached to Dino. Unfortunately, Dino appears before Lasi in the device
81 * tree. To ensure that ttyS0 == SERIAL_0, we register two drivers; one
82 * which only knows about Lasi and then a second which will find all the
83 * other serial ports. HPUX ignores this problem.
84 */
85static struct parisc_device_id lasi_tbl[] = {
86 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03B, 0x0008C }, /* C1xx/C1xxL */
87 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03C, 0x0008C }, /* B132L */
88 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03D, 0x0008C }, /* B160L */
89 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03E, 0x0008C }, /* B132L+ */
90 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x03F, 0x0008C }, /* B180L+ */
91 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x046, 0x0008C }, /* Rocky2 120 */
92 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x047, 0x0008C }, /* Rocky2 150 */
93 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x04E, 0x0008C }, /* Kiji L2 132 */
94 { HPHW_FIO, HVERSION_REV_ANY_ID, 0x056, 0x0008C }, /* Raven+ */
95 { 0 }
96};
97
98
99MODULE_DEVICE_TABLE(parisc, serial_tbl);
100
101static struct parisc_driver lasi_driver = {
102 .name = "serial_1",
103 .id_table = lasi_tbl,
104 .probe = serial_init_chip,
105};
106
107static struct parisc_driver serial_driver = {
108 .name = "serial",
109 .id_table = serial_tbl,
110 .probe = serial_init_chip,
111};
112
113static int __init probe_serial_gsc(void)
114{
115 register_parisc_driver(&lasi_driver);
116 register_parisc_driver(&serial_driver);
117 return 0;
118}
119
120module_init(probe_serial_gsc);
121
122MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/8250/8250_hp300.c b/drivers/tty/serial/8250/8250_hp300.c
deleted file mode 100644
index 5bdaf271d39..00000000000
--- a/drivers/tty/serial/8250/8250_hp300.c
+++ /dev/null
@@ -1,327 +0,0 @@
1/*
2 * Driver for the 98626/98644/internal serial interface on hp300/hp400
3 * (based on the National Semiconductor INS8250/NS16550AF/WD16C552 UARTs)
4 *
5 * Ported from 2.2 and modified to use the normal 8250 driver
6 * by Kars de Jong <jongk@linux-m68k.org>, May 2004.
7 */
8#include <linux/module.h>
9#include <linux/init.h>
10#include <linux/string.h>
11#include <linux/kernel.h>
12#include <linux/serial.h>
13#include <linux/serial_core.h>
14#include <linux/serial_8250.h>
15#include <linux/delay.h>
16#include <linux/dio.h>
17#include <linux/console.h>
18#include <linux/slab.h>
19#include <asm/io.h>
20
21#include "8250.h"
22
23#if !defined(CONFIG_HPDCA) && !defined(CONFIG_HPAPCI)
24#warning CONFIG_8250 defined but neither CONFIG_HPDCA nor CONFIG_HPAPCI defined, are you sure?
25#endif
26
27#ifdef CONFIG_HPAPCI
28struct hp300_port
29{
30 struct hp300_port *next; /* next port */
31 int line; /* line (tty) number */
32};
33
34static struct hp300_port *hp300_ports;
35#endif
36
37#ifdef CONFIG_HPDCA
38
39static int hpdca_init_one(struct dio_dev *d,
40 const struct dio_device_id *ent);
41static void hpdca_remove_one(struct dio_dev *d);
42
43static struct dio_device_id hpdca_dio_tbl[] = {
44 { DIO_ID_DCA0 },
45 { DIO_ID_DCA0REM },
46 { DIO_ID_DCA1 },
47 { DIO_ID_DCA1REM },
48 { 0 }
49};
50
51static struct dio_driver hpdca_driver = {
52 .name = "hpdca",
53 .id_table = hpdca_dio_tbl,
54 .probe = hpdca_init_one,
55 .remove = hpdca_remove_one,
56};
57
58#endif
59
60static unsigned int num_ports;
61
62extern int hp300_uart_scode;
63
64/* Offset to UART registers from base of DCA */
65#define UART_OFFSET 17
66
67#define DCA_ID 0x01 /* ID (read), reset (write) */
68#define DCA_IC 0x03 /* Interrupt control */
69
70/* Interrupt control */
71#define DCA_IC_IE 0x80 /* Master interrupt enable */
72
73#define HPDCA_BAUD_BASE 153600
74
75/* Base address of the Frodo part */
76#define FRODO_BASE (0x41c000)
77
78/*
79 * Where we find the 8250-like APCI ports, and how far apart they are.
80 */
81#define FRODO_APCIBASE 0x0
82#define FRODO_APCISPACE 0x20
83#define FRODO_APCI_OFFSET(x) (FRODO_APCIBASE + ((x) * FRODO_APCISPACE))
84
85#define HPAPCI_BAUD_BASE 500400
86
87#ifdef CONFIG_SERIAL_8250_CONSOLE
88/*
89 * Parse the bootinfo to find descriptions for headless console and
90 * debug serial ports and register them with the 8250 driver.
91 * This function should be called before serial_console_init() is called
92 * to make sure the serial console will be available for use. IA-64 kernel
93 * calls this function from setup_arch() after the EFI and ACPI tables have
94 * been parsed.
95 */
96int __init hp300_setup_serial_console(void)
97{
98 int scode;
99 struct uart_port port;
100
101 memset(&port, 0, sizeof(port));
102
103 if (hp300_uart_scode < 0 || hp300_uart_scode > DIO_SCMAX)
104 return 0;
105
106 if (DIO_SCINHOLE(hp300_uart_scode))
107 return 0;
108
109 scode = hp300_uart_scode;
110
111 /* Memory mapped I/O */
112 port.iotype = UPIO_MEM;
113 port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
114 port.type = PORT_UNKNOWN;
115
116 /* Check for APCI console */
117 if (scode == 256) {
118#ifdef CONFIG_HPAPCI
119 printk(KERN_INFO "Serial console is HP APCI 1\n");
120
121 port.uartclk = HPAPCI_BAUD_BASE * 16;
122 port.mapbase = (FRODO_BASE + FRODO_APCI_OFFSET(1));
123 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
124 port.regshift = 2;
125 add_preferred_console("ttyS", port.line, "9600n8");
126#else
127 printk(KERN_WARNING "Serial console is APCI but support is disabled (CONFIG_HPAPCI)!\n");
128 return 0;
129#endif
130 } else {
131#ifdef CONFIG_HPDCA
132 unsigned long pa = dio_scodetophysaddr(scode);
133 if (!pa)
134 return 0;
135
136 printk(KERN_INFO "Serial console is HP DCA at select code %d\n", scode);
137
138 port.uartclk = HPDCA_BAUD_BASE * 16;
139 port.mapbase = (pa + UART_OFFSET);
140 port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE);
141 port.regshift = 1;
142 port.irq = DIO_IPL(pa + DIO_VIRADDRBASE);
143
144 /* Enable board-interrupts */
145 out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
146
147 if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80)
148 add_preferred_console("ttyS", port.line, "9600n8");
149#else
150 printk(KERN_WARNING "Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
151 return 0;
152#endif
153 }
154
155 if (early_serial_setup(&port) < 0)
156 printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n");
157 return 0;
158}
159#endif /* CONFIG_SERIAL_8250_CONSOLE */
160
161#ifdef CONFIG_HPDCA
162static int hpdca_init_one(struct dio_dev *d,
163 const struct dio_device_id *ent)
164{
165 struct uart_8250_port uart;
166 int line;
167
168#ifdef CONFIG_SERIAL_8250_CONSOLE
169 if (hp300_uart_scode == d->scode) {
170 /* Already got it. */
171 return 0;
172 }
173#endif
174 memset(&uart, 0, sizeof(uart));
175
176 /* Memory mapped I/O */
177 uart.port.iotype = UPIO_MEM;
178 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
179 uart.port.irq = d->ipl;
180 uart.port.uartclk = HPDCA_BAUD_BASE * 16;
181 uart.port.mapbase = (d->resource.start + UART_OFFSET);
182 uart.port.membase = (char *)(uart.port.mapbase + DIO_VIRADDRBASE);
183 uart.port.regshift = 1;
184 uart.port.dev = &d->dev;
185 line = serial8250_register_8250_port(&uart);
186
187 if (line < 0) {
188 printk(KERN_NOTICE "8250_hp300: register_serial() DCA scode %d"
189 " irq %d failed\n", d->scode, uart.port.irq);
190 return -ENOMEM;
191 }
192
193 /* Enable board-interrupts */
194 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
195 dio_set_drvdata(d, (void *)line);
196
197 /* Reset the DCA */
198 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_ID, 0xff);
199 udelay(100);
200
201 num_ports++;
202
203 return 0;
204}
205#endif
206
207static int __init hp300_8250_init(void)
208{
209 static int called;
210#ifdef CONFIG_HPAPCI
211 int line;
212 unsigned long base;
213 struct uart_8250_port uart;
214 struct hp300_port *port;
215 int i;
216#endif
217 if (called)
218 return -ENODEV;
219 called = 1;
220
221 if (!MACH_IS_HP300)
222 return -ENODEV;
223
224#ifdef CONFIG_HPDCA
225 dio_register_driver(&hpdca_driver);
226#endif
227#ifdef CONFIG_HPAPCI
228 if (hp300_model < HP_400) {
229 if (!num_ports)
230 return -ENODEV;
231 return 0;
232 }
233 /* These models have the Frodo chip.
234 * Port 0 is reserved for the Apollo Domain keyboard.
235 * Port 1 is either the console or the DCA.
236 */
237 for (i = 1; i < 4; i++) {
238 /* Port 1 is the console on a 425e, on other machines it's
239 * mapped to DCA.
240 */
241#ifdef CONFIG_SERIAL_8250_CONSOLE
242 if (i == 1)
243 continue;
244#endif
245
246 /* Create new serial device */
247 port = kmalloc(sizeof(struct hp300_port), GFP_KERNEL);
248 if (!port)
249 return -ENOMEM;
250
251 memset(&uart, 0, sizeof(uart));
252
253 base = (FRODO_BASE + FRODO_APCI_OFFSET(i));
254
255 /* Memory mapped I/O */
256 uart.port.iotype = UPIO_MEM;
257 uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ \
258 | UPF_BOOT_AUTOCONF;
259 /* XXX - no interrupt support yet */
260 uart.port.irq = 0;
261 uart.port.uartclk = HPAPCI_BAUD_BASE * 16;
262 uart.port.mapbase = base;
263 uart.port.membase = (char *)(base + DIO_VIRADDRBASE);
264 uart.port.regshift = 2;
265
266 line = serial8250_register_8250_port(&uart);
267
268 if (line < 0) {
269 printk(KERN_NOTICE "8250_hp300: register_serial() APCI"
270 " %d irq %d failed\n", i, uart.port.irq);
271 kfree(port);
272 continue;
273 }
274
275 port->line = line;
276 port->next = hp300_ports;
277 hp300_ports = port;
278
279 num_ports++;
280 }
281#endif
282
283 /* Any boards found? */
284 if (!num_ports)
285 return -ENODEV;
286
287 return 0;
288}
289
290#ifdef CONFIG_HPDCA
291static void hpdca_remove_one(struct dio_dev *d)
292{
293 int line;
294
295 line = (int) dio_get_drvdata(d);
296 if (d->resource.start) {
297 /* Disable board-interrupts */
298 out_8(d->resource.start + DIO_VIRADDRBASE + DCA_IC, 0);
299 }
300 serial8250_unregister_port(line);
301}
302#endif
303
304static void __exit hp300_8250_exit(void)
305{
306#ifdef CONFIG_HPAPCI
307 struct hp300_port *port, *to_free;
308
309 for (port = hp300_ports; port; ) {
310 serial8250_unregister_port(port->line);
311 to_free = port;
312 port = port->next;
313 kfree(to_free);
314 }
315
316 hp300_ports = NULL;
317#endif
318#ifdef CONFIG_HPDCA
319 dio_unregister_driver(&hpdca_driver);
320#endif
321}
322
323module_init(hp300_8250_init);
324module_exit(hp300_8250_exit);
325MODULE_DESCRIPTION("HP DCA/APCI serial driver");
326MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
327MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/8250/8250_hub6.c b/drivers/tty/serial/8250/8250_hub6.c
deleted file mode 100644
index a5c778e83de..00000000000
--- a/drivers/tty/serial/8250/8250_hub6.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 * Copyright (C) 2005 Russell King.
3 * Data taken from include/asm-i386/serial.h
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/serial_8250.h>
12
13#define HUB6(card,port) \
14 { \
15 .iobase = 0x302, \
16 .irq = 3, \
17 .uartclk = 1843200, \
18 .iotype = UPIO_HUB6, \
19 .flags = UPF_BOOT_AUTOCONF, \
20 .hub6 = (card) << 6 | (port) << 3 | 1, \
21 }
22
23static struct plat_serial8250_port hub6_data[] = {
24 HUB6(0, 0),
25 HUB6(0, 1),
26 HUB6(0, 2),
27 HUB6(0, 3),
28 HUB6(0, 4),
29 HUB6(0, 5),
30 HUB6(1, 0),
31 HUB6(1, 1),
32 HUB6(1, 2),
33 HUB6(1, 3),
34 HUB6(1, 4),
35 HUB6(1, 5),
36 { },
37};
38
39static struct platform_device hub6_device = {
40 .name = "serial8250",
41 .id = PLAT8250_DEV_HUB6,
42 .dev = {
43 .platform_data = hub6_data,
44 },
45};
46
47static int __init hub6_init(void)
48{
49 return platform_device_register(&hub6_device);
50}
51
52module_init(hub6_init);
53
54MODULE_AUTHOR("Russell King");
55MODULE_DESCRIPTION("8250 serial probe module for Hub6 cards");
56MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
deleted file mode 100644
index 26b9dc012ed..00000000000
--- a/drivers/tty/serial/8250/8250_pci.c
+++ /dev/null
@@ -1,4604 +0,0 @@
1/*
2 * Probe module for 8250/16550-type PCI serial ports.
3 *
4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5 *
6 * Copyright (C) 2001 Russell King, All Rights Reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License.
11 */
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/pci.h>
15#include <linux/string.h>
16#include <linux/kernel.h>
17#include <linux/slab.h>
18#include <linux/delay.h>
19#include <linux/tty.h>
20#include <linux/serial_reg.h>
21#include <linux/serial_core.h>
22#include <linux/8250_pci.h>
23#include <linux/bitops.h>
24
25#include <asm/byteorder.h>
26#include <asm/io.h>
27
28#include "8250.h"
29
30#undef SERIAL_DEBUG_PCI
31
32/*
33 * init function returns:
34 * > 0 - number of ports
35 * = 0 - use board->num_ports
36 * < 0 - error
37 */
38struct pci_serial_quirk {
39 u32 vendor;
40 u32 device;
41 u32 subvendor;
42 u32 subdevice;
43 int (*probe)(struct pci_dev *dev);
44 int (*init)(struct pci_dev *dev);
45 int (*setup)(struct serial_private *,
46 const struct pciserial_board *,
47 struct uart_8250_port *, int);
48 void (*exit)(struct pci_dev *dev);
49};
50
51#define PCI_NUM_BAR_RESOURCES 6
52
53struct serial_private {
54 struct pci_dev *dev;
55 unsigned int nr;
56 void __iomem *remapped_bar[PCI_NUM_BAR_RESOURCES];
57 struct pci_serial_quirk *quirk;
58 int line[0];
59};
60
61static int pci_default_setup(struct serial_private*,
62 const struct pciserial_board*, struct uart_8250_port *, int);
63
64static void moan_device(const char *str, struct pci_dev *dev)
65{
66 printk(KERN_WARNING
67 "%s: %s\n"
68 "Please send the output of lspci -vv, this\n"
69 "message (0x%04x,0x%04x,0x%04x,0x%04x), the\n"
70 "manufacturer and name of serial board or\n"
71 "modem board to rmk+serial@arm.linux.org.uk.\n",
72 pci_name(dev), str, dev->vendor, dev->device,
73 dev->subsystem_vendor, dev->subsystem_device);
74}
75
76static int
77setup_port(struct serial_private *priv, struct uart_8250_port *port,
78 int bar, int offset, int regshift)
79{
80 struct pci_dev *dev = priv->dev;
81 unsigned long base, len;
82
83 if (bar >= PCI_NUM_BAR_RESOURCES)
84 return -EINVAL;
85
86 base = pci_resource_start(dev, bar);
87
88 if (pci_resource_flags(dev, bar) & IORESOURCE_MEM) {
89 len = pci_resource_len(dev, bar);
90
91 if (!priv->remapped_bar[bar])
92 priv->remapped_bar[bar] = ioremap_nocache(base, len);
93 if (!priv->remapped_bar[bar])
94 return -ENOMEM;
95
96 port->port.iotype = UPIO_MEM;
97 port->port.iobase = 0;
98 port->port.mapbase = base + offset;
99 port->port.membase = priv->remapped_bar[bar] + offset;
100 port->port.regshift = regshift;
101 } else {
102 port->port.iotype = UPIO_PORT;
103 port->port.iobase = base + offset;
104 port->port.mapbase = 0;
105 port->port.membase = NULL;
106 port->port.regshift = 0;
107 }
108 return 0;
109}
110
111/*
112 * ADDI-DATA GmbH communication cards <info@addi-data.com>
113 */
114static int addidata_apci7800_setup(struct serial_private *priv,
115 const struct pciserial_board *board,
116 struct uart_8250_port *port, int idx)
117{
118 unsigned int bar = 0, offset = board->first_offset;
119 bar = FL_GET_BASE(board->flags);
120
121 if (idx < 2) {
122 offset += idx * board->uart_offset;
123 } else if ((idx >= 2) && (idx < 4)) {
124 bar += 1;
125 offset += ((idx - 2) * board->uart_offset);
126 } else if ((idx >= 4) && (idx < 6)) {
127 bar += 2;
128 offset += ((idx - 4) * board->uart_offset);
129 } else if (idx >= 6) {
130 bar += 3;
131 offset += ((idx - 6) * board->uart_offset);
132 }
133
134 return setup_port(priv, port, bar, offset, board->reg_shift);
135}
136
137/*
138 * AFAVLAB uses a different mixture of BARs and offsets
139 * Not that ugly ;) -- HW
140 */
141static int
142afavlab_setup(struct serial_private *priv, const struct pciserial_board *board,
143 struct uart_8250_port *port, int idx)
144{
145 unsigned int bar, offset = board->first_offset;
146
147 bar = FL_GET_BASE(board->flags);
148 if (idx < 4)
149 bar += idx;
150 else {
151 bar = 4;
152 offset += (idx - 4) * board->uart_offset;
153 }
154
155 return setup_port(priv, port, bar, offset, board->reg_shift);
156}
157
158/*
159 * HP's Remote Management Console. The Diva chip came in several
160 * different versions. N-class, L2000 and A500 have two Diva chips, each
161 * with 3 UARTs (the third UART on the second chip is unused). Superdome
162 * and Keystone have one Diva chip with 3 UARTs. Some later machines have
163 * one Diva chip, but it has been expanded to 5 UARTs.
164 */
165static int pci_hp_diva_init(struct pci_dev *dev)
166{
167 int rc = 0;
168
169 switch (dev->subsystem_device) {
170 case PCI_DEVICE_ID_HP_DIVA_TOSCA1:
171 case PCI_DEVICE_ID_HP_DIVA_HALFDOME:
172 case PCI_DEVICE_ID_HP_DIVA_KEYSTONE:
173 case PCI_DEVICE_ID_HP_DIVA_EVEREST:
174 rc = 3;
175 break;
176 case PCI_DEVICE_ID_HP_DIVA_TOSCA2:
177 rc = 2;
178 break;
179 case PCI_DEVICE_ID_HP_DIVA_MAESTRO:
180 rc = 4;
181 break;
182 case PCI_DEVICE_ID_HP_DIVA_POWERBAR:
183 case PCI_DEVICE_ID_HP_DIVA_HURRICANE:
184 rc = 1;
185 break;
186 }
187
188 return rc;
189}
190
191/*
192 * HP's Diva chip puts the 4th/5th serial port further out, and
193 * some serial ports are supposed to be hidden on certain models.
194 */
195static int
196pci_hp_diva_setup(struct serial_private *priv,
197 const struct pciserial_board *board,
198 struct uart_8250_port *port, int idx)
199{
200 unsigned int offset = board->first_offset;
201 unsigned int bar = FL_GET_BASE(board->flags);
202
203 switch (priv->dev->subsystem_device) {
204 case PCI_DEVICE_ID_HP_DIVA_MAESTRO:
205 if (idx == 3)
206 idx++;
207 break;
208 case PCI_DEVICE_ID_HP_DIVA_EVEREST:
209 if (idx > 0)
210 idx++;
211 if (idx > 2)
212 idx++;
213 break;
214 }
215 if (idx > 2)
216 offset = 0x18;
217
218 offset += idx * board->uart_offset;
219
220 return setup_port(priv, port, bar, offset, board->reg_shift);
221}
222
223/*
224 * Added for EKF Intel i960 serial boards
225 */
226static int pci_inteli960ni_init(struct pci_dev *dev)
227{
228 unsigned long oldval;
229
230 if (!(dev->subsystem_device & 0x1000))
231 return -ENODEV;
232
233 /* is firmware started? */
234 pci_read_config_dword(dev, 0x44, (void *)&oldval);
235 if (oldval == 0x00001000L) { /* RESET value */
236 printk(KERN_DEBUG "Local i960 firmware missing");
237 return -ENODEV;
238 }
239 return 0;
240}
241
242/*
243 * Some PCI serial cards using the PLX 9050 PCI interface chip require
244 * that the card interrupt be explicitly enabled or disabled. This
245 * seems to be mainly needed on card using the PLX which also use I/O
246 * mapped memory.
247 */
248static int pci_plx9050_init(struct pci_dev *dev)
249{
250 u8 irq_config;
251 void __iomem *p;
252
253 if ((pci_resource_flags(dev, 0) & IORESOURCE_MEM) == 0) {
254 moan_device("no memory in bar 0", dev);
255 return 0;
256 }
257
258 irq_config = 0x41;
259 if (dev->vendor == PCI_VENDOR_ID_PANACOM ||
260 dev->subsystem_vendor == PCI_SUBVENDOR_ID_EXSYS)
261 irq_config = 0x43;
262
263 if ((dev->vendor == PCI_VENDOR_ID_PLX) &&
264 (dev->device == PCI_DEVICE_ID_PLX_ROMULUS))
265 /*
266 * As the megawolf cards have the int pins active
267 * high, and have 2 UART chips, both ints must be
268 * enabled on the 9050. Also, the UARTS are set in
269 * 16450 mode by default, so we have to enable the
270 * 16C950 'enhanced' mode so that we can use the
271 * deep FIFOs
272 */
273 irq_config = 0x5b;
274 /*
275 * enable/disable interrupts
276 */
277 p = ioremap_nocache(pci_resource_start(dev, 0), 0x80);
278 if (p == NULL)
279 return -ENOMEM;
280 writel(irq_config, p + 0x4c);
281
282 /*
283 * Read the register back to ensure that it took effect.
284 */
285 readl(p + 0x4c);
286 iounmap(p);
287
288 return 0;
289}
290
291static void pci_plx9050_exit(struct pci_dev *dev)
292{
293 u8 __iomem *p;
294
295 if ((pci_resource_flags(dev, 0) & IORESOURCE_MEM) == 0)
296 return;
297
298 /*
299 * disable interrupts
300 */
301 p = ioremap_nocache(pci_resource_start(dev, 0), 0x80);
302 if (p != NULL) {
303 writel(0, p + 0x4c);
304
305 /*
306 * Read the register back to ensure that it took effect.
307 */
308 readl(p + 0x4c);
309 iounmap(p);
310 }
311}
312
313#define NI8420_INT_ENABLE_REG 0x38
314#define NI8420_INT_ENABLE_BIT 0x2000
315
316static void pci_ni8420_exit(struct pci_dev *dev)
317{
318 void __iomem *p;
319 unsigned long base, len;
320 unsigned int bar = 0;
321
322 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) {
323 moan_device("no memory in bar", dev);
324 return;
325 }
326
327 base = pci_resource_start(dev, bar);
328 len = pci_resource_len(dev, bar);
329 p = ioremap_nocache(base, len);
330 if (p == NULL)
331 return;
332
333 /* Disable the CPU Interrupt */
334 writel(readl(p + NI8420_INT_ENABLE_REG) & ~(NI8420_INT_ENABLE_BIT),
335 p + NI8420_INT_ENABLE_REG);
336 iounmap(p);
337}
338
339
340/* MITE registers */
341#define MITE_IOWBSR1 0xc4
342#define MITE_IOWCR1 0xf4
343#define MITE_LCIMR1 0x08
344#define MITE_LCIMR2 0x10
345
346#define MITE_LCIMR2_CLR_CPU_IE (1 << 30)
347
348static void pci_ni8430_exit(struct pci_dev *dev)
349{
350 void __iomem *p;
351 unsigned long base, len;
352 unsigned int bar = 0;
353
354 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) {
355 moan_device("no memory in bar", dev);
356 return;
357 }
358
359 base = pci_resource_start(dev, bar);
360 len = pci_resource_len(dev, bar);
361 p = ioremap_nocache(base, len);
362 if (p == NULL)
363 return;
364
365 /* Disable the CPU Interrupt */
366 writel(MITE_LCIMR2_CLR_CPU_IE, p + MITE_LCIMR2);
367 iounmap(p);
368}
369
370/* SBS Technologies Inc. PMC-OCTPRO and P-OCTAL cards */
371static int
372sbs_setup(struct serial_private *priv, const struct pciserial_board *board,
373 struct uart_8250_port *port, int idx)
374{
375 unsigned int bar, offset = board->first_offset;
376
377 bar = 0;
378
379 if (idx < 4) {
380 /* first four channels map to 0, 0x100, 0x200, 0x300 */
381 offset += idx * board->uart_offset;
382 } else if (idx < 8) {
383 /* last four channels map to 0x1000, 0x1100, 0x1200, 0x1300 */
384 offset += idx * board->uart_offset + 0xC00;
385 } else /* we have only 8 ports on PMC-OCTALPRO */
386 return 1;
387
388 return setup_port(priv, port, bar, offset, board->reg_shift);
389}
390
391/*
392* This does initialization for PMC OCTALPRO cards:
393* maps the device memory, resets the UARTs (needed, bc
394* if the module is removed and inserted again, the card
395* is in the sleep mode) and enables global interrupt.
396*/
397
398/* global control register offset for SBS PMC-OctalPro */
399#define OCT_REG_CR_OFF 0x500
400
401static int sbs_init(struct pci_dev *dev)
402{
403 u8 __iomem *p;
404
405 p = pci_ioremap_bar(dev, 0);
406
407 if (p == NULL)
408 return -ENOMEM;
409 /* Set bit-4 Control Register (UART RESET) in to reset the uarts */
410 writeb(0x10, p + OCT_REG_CR_OFF);
411 udelay(50);
412 writeb(0x0, p + OCT_REG_CR_OFF);
413
414 /* Set bit-2 (INTENABLE) of Control Register */
415 writeb(0x4, p + OCT_REG_CR_OFF);
416 iounmap(p);
417
418 return 0;
419}
420
421/*
422 * Disables the global interrupt of PMC-OctalPro
423 */
424
425static void sbs_exit(struct pci_dev *dev)
426{
427 u8 __iomem *p;
428
429 p = pci_ioremap_bar(dev, 0);
430 /* FIXME: What if resource_len < OCT_REG_CR_OFF */
431 if (p != NULL)
432 writeb(0, p + OCT_REG_CR_OFF);
433 iounmap(p);
434}
435
436/*
437 * SIIG serial cards have an PCI interface chip which also controls
438 * the UART clocking frequency. Each UART can be clocked independently
439 * (except cards equipped with 4 UARTs) and initial clocking settings
440 * are stored in the EEPROM chip. It can cause problems because this
441 * version of serial driver doesn't support differently clocked UART's
442 * on single PCI card. To prevent this, initialization functions set
443 * high frequency clocking for all UART's on given card. It is safe (I
444 * hope) because it doesn't touch EEPROM settings to prevent conflicts
445 * with other OSes (like M$ DOS).
446 *
447 * SIIG support added by Andrey Panin <pazke@donpac.ru>, 10/1999
448 *
449 * There is two family of SIIG serial cards with different PCI
450 * interface chip and different configuration methods:
451 * - 10x cards have control registers in IO and/or memory space;
452 * - 20x cards have control registers in standard PCI configuration space.
453 *
454 * Note: all 10x cards have PCI device ids 0x10..
455 * all 20x cards have PCI device ids 0x20..
456 *
457 * There are also Quartet Serial cards which use Oxford Semiconductor
458 * 16954 quad UART PCI chip clocked by 18.432 MHz quartz.
459 *
460 * Note: some SIIG cards are probed by the parport_serial object.
461 */
462
463#define PCI_DEVICE_ID_SIIG_1S_10x (PCI_DEVICE_ID_SIIG_1S_10x_550 & 0xfffc)
464#define PCI_DEVICE_ID_SIIG_2S_10x (PCI_DEVICE_ID_SIIG_2S_10x_550 & 0xfff8)
465
466static int pci_siig10x_init(struct pci_dev *dev)
467{
468 u16 data;
469 void __iomem *p;
470
471 switch (dev->device & 0xfff8) {
472 case PCI_DEVICE_ID_SIIG_1S_10x: /* 1S */
473 data = 0xffdf;
474 break;
475 case PCI_DEVICE_ID_SIIG_2S_10x: /* 2S, 2S1P */
476 data = 0xf7ff;
477 break;
478 default: /* 1S1P, 4S */
479 data = 0xfffb;
480 break;
481 }
482
483 p = ioremap_nocache(pci_resource_start(dev, 0), 0x80);
484 if (p == NULL)
485 return -ENOMEM;
486
487 writew(readw(p + 0x28) & data, p + 0x28);
488 readw(p + 0x28);
489 iounmap(p);
490 return 0;
491}
492
493#define PCI_DEVICE_ID_SIIG_2S_20x (PCI_DEVICE_ID_SIIG_2S_20x_550 & 0xfffc)
494#define PCI_DEVICE_ID_SIIG_2S1P_20x (PCI_DEVICE_ID_SIIG_2S1P_20x_550 & 0xfffc)
495
496static int pci_siig20x_init(struct pci_dev *dev)
497{
498 u8 data;
499
500 /* Change clock frequency for the first UART. */
501 pci_read_config_byte(dev, 0x6f, &data);
502 pci_write_config_byte(dev, 0x6f, data & 0xef);
503
504 /* If this card has 2 UART, we have to do the same with second UART. */
505 if (((dev->device & 0xfffc) == PCI_DEVICE_ID_SIIG_2S_20x) ||
506 ((dev->device & 0xfffc) == PCI_DEVICE_ID_SIIG_2S1P_20x)) {
507 pci_read_config_byte(dev, 0x73, &data);
508 pci_write_config_byte(dev, 0x73, data & 0xef);
509 }
510 return 0;
511}
512
513static int pci_siig_init(struct pci_dev *dev)
514{
515 unsigned int type = dev->device & 0xff00;
516
517 if (type == 0x1000)
518 return pci_siig10x_init(dev);
519 else if (type == 0x2000)
520 return pci_siig20x_init(dev);
521
522 moan_device("Unknown SIIG card", dev);
523 return -ENODEV;
524}
525
526static int pci_siig_setup(struct serial_private *priv,
527 const struct pciserial_board *board,
528 struct uart_8250_port *port, int idx)
529{
530 unsigned int bar = FL_GET_BASE(board->flags) + idx, offset = 0;
531
532 if (idx > 3) {
533 bar = 4;
534 offset = (idx - 4) * 8;
535 }
536
537 return setup_port(priv, port, bar, offset, 0);
538}
539
540/*
541 * Timedia has an explosion of boards, and to avoid the PCI table from
542 * growing *huge*, we use this function to collapse some 70 entries
543 * in the PCI table into one, for sanity's and compactness's sake.
544 */
545static const unsigned short timedia_single_port[] = {
546 0x4025, 0x4027, 0x4028, 0x5025, 0x5027, 0
547};
548
549static const unsigned short timedia_dual_port[] = {
550 0x0002, 0x4036, 0x4037, 0x4038, 0x4078, 0x4079, 0x4085,
551 0x4088, 0x4089, 0x5037, 0x5078, 0x5079, 0x5085, 0x6079,
552 0x7079, 0x8079, 0x8137, 0x8138, 0x8237, 0x8238, 0x9079,
553 0x9137, 0x9138, 0x9237, 0x9238, 0xA079, 0xB079, 0xC079,
554 0xD079, 0
555};
556
557static const unsigned short timedia_quad_port[] = {
558 0x4055, 0x4056, 0x4095, 0x4096, 0x5056, 0x8156, 0x8157,
559 0x8256, 0x8257, 0x9056, 0x9156, 0x9157, 0x9158, 0x9159,
560 0x9256, 0x9257, 0xA056, 0xA157, 0xA158, 0xA159, 0xB056,
561 0xB157, 0
562};
563
564static const unsigned short timedia_eight_port[] = {
565 0x4065, 0x4066, 0x5065, 0x5066, 0x8166, 0x9066, 0x9166,
566 0x9167, 0x9168, 0xA066, 0xA167, 0xA168, 0
567};
568
569static const struct timedia_struct {
570 int num;
571 const unsigned short *ids;
572} timedia_data[] = {
573 { 1, timedia_single_port },
574 { 2, timedia_dual_port },
575 { 4, timedia_quad_port },
576 { 8, timedia_eight_port }
577};
578
579/*
580 * There are nearly 70 different Timedia/SUNIX PCI serial devices. Instead of
581 * listing them individually, this driver merely grabs them all with
582 * PCI_ANY_ID. Some of these devices, however, also feature a parallel port,
583 * and should be left free to be claimed by parport_serial instead.
584 */
585static int pci_timedia_probe(struct pci_dev *dev)
586{
587 /*
588 * Check the third digit of the subdevice ID
589 * (0,2,3,5,6: serial only -- 7,8,9: serial + parallel)
590 */
591 if ((dev->subsystem_device & 0x00f0) >= 0x70) {
592 dev_info(&dev->dev,
593 "ignoring Timedia subdevice %04x for parport_serial\n",
594 dev->subsystem_device);
595 return -ENODEV;
596 }
597
598 return 0;
599}
600
601static int pci_timedia_init(struct pci_dev *dev)
602{
603 const unsigned short *ids;
604 int i, j;
605
606 for (i = 0; i < ARRAY_SIZE(timedia_data); i++) {
607 ids = timedia_data[i].ids;
608 for (j = 0; ids[j]; j++)
609 if (dev->subsystem_device == ids[j])
610 return timedia_data[i].num;
611 }
612 return 0;
613}
614
615/*
616 * Timedia/SUNIX uses a mixture of BARs and offsets
617 * Ugh, this is ugly as all hell --- TYT
618 */
619static int
620pci_timedia_setup(struct serial_private *priv,
621 const struct pciserial_board *board,
622 struct uart_8250_port *port, int idx)
623{
624 unsigned int bar = 0, offset = board->first_offset;
625
626 switch (idx) {
627 case 0:
628 bar = 0;
629 break;
630 case 1:
631 offset = board->uart_offset;
632 bar = 0;
633 break;
634 case 2:
635 bar = 1;
636 break;
637 case 3:
638 offset = board->uart_offset;
639 /* FALLTHROUGH */
640 case 4: /* BAR 2 */
641 case 5: /* BAR 3 */
642 case 6: /* BAR 4 */
643 case 7: /* BAR 5 */
644 bar = idx - 2;
645 }
646
647 return setup_port(priv, port, bar, offset, board->reg_shift);
648}
649
650/*
651 * Some Titan cards are also a little weird
652 */
653static int
654titan_400l_800l_setup(struct serial_private *priv,
655 const struct pciserial_board *board,
656 struct uart_8250_port *port, int idx)
657{
658 unsigned int bar, offset = board->first_offset;
659
660 switch (idx) {
661 case 0:
662 bar = 1;
663 break;
664 case 1:
665 bar = 2;
666 break;
667 default:
668 bar = 4;
669 offset = (idx - 2) * board->uart_offset;
670 }
671
672 return setup_port(priv, port, bar, offset, board->reg_shift);
673}
674
675static int pci_xircom_init(struct pci_dev *dev)
676{
677 msleep(100);
678 return 0;
679}
680
681static int pci_ni8420_init(struct pci_dev *dev)
682{
683 void __iomem *p;
684 unsigned long base, len;
685 unsigned int bar = 0;
686
687 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) {
688 moan_device("no memory in bar", dev);
689 return 0;
690 }
691
692 base = pci_resource_start(dev, bar);
693 len = pci_resource_len(dev, bar);
694 p = ioremap_nocache(base, len);
695 if (p == NULL)
696 return -ENOMEM;
697
698 /* Enable CPU Interrupt */
699 writel(readl(p + NI8420_INT_ENABLE_REG) | NI8420_INT_ENABLE_BIT,
700 p + NI8420_INT_ENABLE_REG);
701
702 iounmap(p);
703 return 0;
704}
705
706#define MITE_IOWBSR1_WSIZE 0xa
707#define MITE_IOWBSR1_WIN_OFFSET 0x800
708#define MITE_IOWBSR1_WENAB (1 << 7)
709#define MITE_LCIMR1_IO_IE_0 (1 << 24)
710#define MITE_LCIMR2_SET_CPU_IE (1 << 31)
711#define MITE_IOWCR1_RAMSEL_MASK 0xfffffffe
712
713static int pci_ni8430_init(struct pci_dev *dev)
714{
715 void __iomem *p;
716 unsigned long base, len;
717 u32 device_window;
718 unsigned int bar = 0;
719
720 if ((pci_resource_flags(dev, bar) & IORESOURCE_MEM) == 0) {
721 moan_device("no memory in bar", dev);
722 return 0;
723 }
724
725 base = pci_resource_start(dev, bar);
726 len = pci_resource_len(dev, bar);
727 p = ioremap_nocache(base, len);
728 if (p == NULL)
729 return -ENOMEM;
730
731 /* Set device window address and size in BAR0 */
732 device_window = ((base + MITE_IOWBSR1_WIN_OFFSET) & 0xffffff00)
733 | MITE_IOWBSR1_WENAB | MITE_IOWBSR1_WSIZE;
734 writel(device_window, p + MITE_IOWBSR1);
735
736 /* Set window access to go to RAMSEL IO address space */
737 writel((readl(p + MITE_IOWCR1) & MITE_IOWCR1_RAMSEL_MASK),
738 p + MITE_IOWCR1);
739
740 /* Enable IO Bus Interrupt 0 */
741 writel(MITE_LCIMR1_IO_IE_0, p + MITE_LCIMR1);
742
743 /* Enable CPU Interrupt */
744 writel(MITE_LCIMR2_SET_CPU_IE, p + MITE_LCIMR2);
745
746 iounmap(p);
747 return 0;
748}
749
750/* UART Port Control Register */
751#define NI8430_PORTCON 0x0f
752#define NI8430_PORTCON_TXVR_ENABLE (1 << 3)
753
754static int
755pci_ni8430_setup(struct serial_private *priv,
756 const struct pciserial_board *board,
757 struct uart_8250_port *port, int idx)
758{
759 void __iomem *p;
760 unsigned long base, len;
761 unsigned int bar, offset = board->first_offset;
762
763 if (idx >= board->num_ports)
764 return 1;
765
766 bar = FL_GET_BASE(board->flags);
767 offset += idx * board->uart_offset;
768
769 base = pci_resource_start(priv->dev, bar);
770 len = pci_resource_len(priv->dev, bar);
771 p = ioremap_nocache(base, len);
772
773 /* enable the transceiver */
774 writeb(readb(p + offset + NI8430_PORTCON) | NI8430_PORTCON_TXVR_ENABLE,
775 p + offset + NI8430_PORTCON);
776
777 iounmap(p);
778
779 return setup_port(priv, port, bar, offset, board->reg_shift);
780}
781
782static int pci_netmos_9900_setup(struct serial_private *priv,
783 const struct pciserial_board *board,
784 struct uart_8250_port *port, int idx)
785{
786 unsigned int bar;
787
788 if ((priv->dev->subsystem_device & 0xff00) == 0x3000) {
789 /* netmos apparently orders BARs by datasheet layout, so serial
790 * ports get BARs 0 and 3 (or 1 and 4 for memmapped)
791 */
792 bar = 3 * idx;
793
794 return setup_port(priv, port, bar, 0, board->reg_shift);
795 } else {
796 return pci_default_setup(priv, board, port, idx);
797 }
798}
799
800/* the 99xx series comes with a range of device IDs and a variety
801 * of capabilities:
802 *
803 * 9900 has varying capabilities and can cascade to sub-controllers
804 * (cascading should be purely internal)
805 * 9904 is hardwired with 4 serial ports
806 * 9912 and 9922 are hardwired with 2 serial ports
807 */
808static int pci_netmos_9900_numports(struct pci_dev *dev)
809{
810 unsigned int c = dev->class;
811 unsigned int pi;
812 unsigned short sub_serports;
813
814 pi = (c & 0xff);
815
816 if (pi == 2) {
817 return 1;
818 } else if ((pi == 0) &&
819 (dev->device == PCI_DEVICE_ID_NETMOS_9900)) {
820 /* two possibilities: 0x30ps encodes number of parallel and
821 * serial ports, or 0x1000 indicates *something*. This is not
822 * immediately obvious, since the 2s1p+4s configuration seems
823 * to offer all functionality on functions 0..2, while still
824 * advertising the same function 3 as the 4s+2s1p config.
825 */
826 sub_serports = dev->subsystem_device & 0xf;
827 if (sub_serports > 0) {
828 return sub_serports;
829 } else {
830 printk(KERN_NOTICE "NetMos/Mostech serial driver ignoring port on ambiguous config.\n");
831 return 0;
832 }
833 }
834
835 moan_device("unknown NetMos/Mostech program interface", dev);
836 return 0;
837}
838
839static int pci_netmos_init(struct pci_dev *dev)
840{
841 /* subdevice 0x00PS means <P> parallel, <S> serial */
842 unsigned int num_serial = dev->subsystem_device & 0xf;
843
844 if ((dev->device == PCI_DEVICE_ID_NETMOS_9901) ||
845 (dev->device == PCI_DEVICE_ID_NETMOS_9865))
846 return 0;
847
848 if (dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
849 dev->subsystem_device == 0x0299)
850 return 0;
851
852 switch (dev->device) { /* FALLTHROUGH on all */
853 case PCI_DEVICE_ID_NETMOS_9904:
854 case PCI_DEVICE_ID_NETMOS_9912:
855 case PCI_DEVICE_ID_NETMOS_9922:
856 case PCI_DEVICE_ID_NETMOS_9900:
857 num_serial = pci_netmos_9900_numports(dev);
858 break;
859
860 default:
861 if (num_serial == 0 ) {
862 moan_device("unknown NetMos/Mostech device", dev);
863 }
864 }
865
866 if (num_serial == 0)
867 return -ENODEV;
868
869 return num_serial;
870}
871
872/*
873 * These chips are available with optionally one parallel port and up to
874 * two serial ports. Unfortunately they all have the same product id.
875 *
876 * Basic configuration is done over a region of 32 I/O ports. The base
877 * ioport is called INTA or INTC, depending on docs/other drivers.
878 *
879 * The region of the 32 I/O ports is configured in POSIO0R...
880 */
881
882/* registers */
883#define ITE_887x_MISCR 0x9c
884#define ITE_887x_INTCBAR 0x78
885#define ITE_887x_UARTBAR 0x7c
886#define ITE_887x_PS0BAR 0x10
887#define ITE_887x_POSIO0 0x60
888
889/* I/O space size */
890#define ITE_887x_IOSIZE 32
891/* I/O space size (bits 26-24; 8 bytes = 011b) */
892#define ITE_887x_POSIO_IOSIZE_8 (3 << 24)
893/* I/O space size (bits 26-24; 32 bytes = 101b) */
894#define ITE_887x_POSIO_IOSIZE_32 (5 << 24)
895/* Decoding speed (1 = slow, 2 = medium, 3 = fast) */
896#define ITE_887x_POSIO_SPEED (3 << 29)
897/* enable IO_Space bit */
898#define ITE_887x_POSIO_ENABLE (1 << 31)
899
900static int pci_ite887x_init(struct pci_dev *dev)
901{
902 /* inta_addr are the configuration addresses of the ITE */
903 static const short inta_addr[] = { 0x2a0, 0x2c0, 0x220, 0x240, 0x1e0,
904 0x200, 0x280, 0 };
905 int ret, i, type;
906 struct resource *iobase = NULL;
907 u32 miscr, uartbar, ioport;
908
909 /* search for the base-ioport */
910 i = 0;
911 while (inta_addr[i] && iobase == NULL) {
912 iobase = request_region(inta_addr[i], ITE_887x_IOSIZE,
913 "ite887x");
914 if (iobase != NULL) {
915 /* write POSIO0R - speed | size | ioport */
916 pci_write_config_dword(dev, ITE_887x_POSIO0,
917 ITE_887x_POSIO_ENABLE | ITE_887x_POSIO_SPEED |
918 ITE_887x_POSIO_IOSIZE_32 | inta_addr[i]);
919 /* write INTCBAR - ioport */
920 pci_write_config_dword(dev, ITE_887x_INTCBAR,
921 inta_addr[i]);
922 ret = inb(inta_addr[i]);
923 if (ret != 0xff) {
924 /* ioport connected */
925 break;
926 }
927 release_region(iobase->start, ITE_887x_IOSIZE);
928 iobase = NULL;
929 }
930 i++;
931 }
932
933 if (!inta_addr[i]) {
934 printk(KERN_ERR "ite887x: could not find iobase\n");
935 return -ENODEV;
936 }
937
938 /* start of undocumented type checking (see parport_pc.c) */
939 type = inb(iobase->start + 0x18) & 0x0f;
940
941 switch (type) {
942 case 0x2: /* ITE8871 (1P) */
943 case 0xa: /* ITE8875 (1P) */
944 ret = 0;
945 break;
946 case 0xe: /* ITE8872 (2S1P) */
947 ret = 2;
948 break;
949 case 0x6: /* ITE8873 (1S) */
950 ret = 1;
951 break;
952 case 0x8: /* ITE8874 (2S) */
953 ret = 2;
954 break;
955 default:
956 moan_device("Unknown ITE887x", dev);
957 ret = -ENODEV;
958 }
959
960 /* configure all serial ports */
961 for (i = 0; i < ret; i++) {
962 /* read the I/O port from the device */
963 pci_read_config_dword(dev, ITE_887x_PS0BAR + (0x4 * (i + 1)),
964 &ioport);
965 ioport &= 0x0000FF00; /* the actual base address */
966 pci_write_config_dword(dev, ITE_887x_POSIO0 + (0x4 * (i + 1)),
967 ITE_887x_POSIO_ENABLE | ITE_887x_POSIO_SPEED |
968 ITE_887x_POSIO_IOSIZE_8 | ioport);
969
970 /* write the ioport to the UARTBAR */
971 pci_read_config_dword(dev, ITE_887x_UARTBAR, &uartbar);
972 uartbar &= ~(0xffff << (16 * i)); /* clear half the reg */
973 uartbar |= (ioport << (16 * i)); /* set the ioport */
974 pci_write_config_dword(dev, ITE_887x_UARTBAR, uartbar);
975
976 /* get current config */
977 pci_read_config_dword(dev, ITE_887x_MISCR, &miscr);
978 /* disable interrupts (UARTx_Routing[3:0]) */
979 miscr &= ~(0xf << (12 - 4 * i));
980 /* activate the UART (UARTx_En) */
981 miscr |= 1 << (23 - i);
982 /* write new config with activated UART */
983 pci_write_config_dword(dev, ITE_887x_MISCR, miscr);
984 }
985
986 if (ret <= 0) {
987 /* the device has no UARTs if we get here */
988 release_region(iobase->start, ITE_887x_IOSIZE);
989 }
990
991 return ret;
992}
993
994static void pci_ite887x_exit(struct pci_dev *dev)
995{
996 u32 ioport;
997 /* the ioport is bit 0-15 in POSIO0R */
998 pci_read_config_dword(dev, ITE_887x_POSIO0, &ioport);
999 ioport &= 0xffff;
1000 release_region(ioport, ITE_887x_IOSIZE);
1001}
1002
1003/*
1004 * Oxford Semiconductor Inc.
1005 * Check that device is part of the Tornado range of devices, then determine
1006 * the number of ports available on the device.
1007 */
1008static int pci_oxsemi_tornado_init(struct pci_dev *dev)
1009{
1010 u8 __iomem *p;
1011 unsigned long deviceID;
1012 unsigned int number_uarts = 0;
1013
1014 /* OxSemi Tornado devices are all 0xCxxx */
1015 if (dev->vendor == PCI_VENDOR_ID_OXSEMI &&
1016 (dev->device & 0xF000) != 0xC000)
1017 return 0;
1018
1019 p = pci_iomap(dev, 0, 5);
1020 if (p == NULL)
1021 return -ENOMEM;
1022
1023 deviceID = ioread32(p);
1024 /* Tornado device */
1025 if (deviceID == 0x07000200) {
1026 number_uarts = ioread8(p + 4);
1027 printk(KERN_DEBUG
1028 "%d ports detected on Oxford PCI Express device\n",
1029 number_uarts);
1030 }
1031 pci_iounmap(dev, p);
1032 return number_uarts;
1033}
1034
1035static int pci_asix_setup(struct serial_private *priv,
1036 const struct pciserial_board *board,
1037 struct uart_8250_port *port, int idx)
1038{
1039 port->bugs |= UART_BUG_PARITY;
1040 return pci_default_setup(priv, board, port, idx);
1041}
1042
1043static int pci_default_setup(struct serial_private *priv,
1044 const struct pciserial_board *board,
1045 struct uart_8250_port *port, int idx)
1046{
1047 unsigned int bar, offset = board->first_offset, maxnr;
1048
1049 bar = FL_GET_BASE(board->flags);
1050 if (board->flags & FL_BASE_BARS)
1051 bar += idx;
1052 else
1053 offset += idx * board->uart_offset;
1054
1055 maxnr = (pci_resource_len(priv->dev, bar) - board->first_offset) >>
1056 (board->reg_shift + 3);
1057
1058 if (board->flags & FL_REGION_SZ_CAP && idx >= maxnr)
1059 return 1;
1060
1061 return setup_port(priv, port, bar, offset, board->reg_shift);
1062}
1063
1064static int
1065ce4100_serial_setup(struct serial_private *priv,
1066 const struct pciserial_board *board,
1067 struct uart_8250_port *port, int idx)
1068{
1069 int ret;
1070
1071 ret = setup_port(priv, port, idx, 0, board->reg_shift);
1072 port->port.iotype = UPIO_MEM32;
1073 port->port.type = PORT_XSCALE;
1074 port->port.flags = (port->port.flags | UPF_FIXED_PORT | UPF_FIXED_TYPE);
1075 port->port.regshift = 2;
1076
1077 return ret;
1078}
1079
1080static int
1081pci_omegapci_setup(struct serial_private *priv,
1082 const struct pciserial_board *board,
1083 struct uart_8250_port *port, int idx)
1084{
1085 return setup_port(priv, port, 2, idx * 8, 0);
1086}
1087
1088static int skip_tx_en_setup(struct serial_private *priv,
1089 const struct pciserial_board *board,
1090 struct uart_8250_port *port, int idx)
1091{
1092 port->port.flags |= UPF_NO_TXEN_TEST;
1093 printk(KERN_DEBUG "serial8250: skipping TxEn test for device "
1094 "[%04x:%04x] subsystem [%04x:%04x]\n",
1095 priv->dev->vendor,
1096 priv->dev->device,
1097 priv->dev->subsystem_vendor,
1098 priv->dev->subsystem_device);
1099
1100 return pci_default_setup(priv, board, port, idx);
1101}
1102
1103static void kt_handle_break(struct uart_port *p)
1104{
1105 struct uart_8250_port *up =
1106 container_of(p, struct uart_8250_port, port);
1107 /*
1108 * On receipt of a BI, serial device in Intel ME (Intel
1109 * management engine) needs to have its fifos cleared for sane
1110 * SOL (Serial Over Lan) output.
1111 */
1112 serial8250_clear_and_reinit_fifos(up);
1113}
1114
1115static unsigned int kt_serial_in(struct uart_port *p, int offset)
1116{
1117 struct uart_8250_port *up =
1118 container_of(p, struct uart_8250_port, port);
1119 unsigned int val;
1120
1121 /*
1122 * When the Intel ME (management engine) gets reset its serial
1123 * port registers could return 0 momentarily. Functions like
1124 * serial8250_console_write, read and save the IER, perform
1125 * some operation and then restore it. In order to avoid
1126 * setting IER register inadvertently to 0, if the value read
1127 * is 0, double check with ier value in uart_8250_port and use
1128 * that instead. up->ier should be the same value as what is
1129 * currently configured.
1130 */
1131 val = inb(p->iobase + offset);
1132 if (offset == UART_IER) {
1133 if (val == 0)
1134 val = up->ier;
1135 }
1136 return val;
1137}
1138
1139static int kt_serial_setup(struct serial_private *priv,
1140 const struct pciserial_board *board,
1141 struct uart_8250_port *port, int idx)
1142{
1143 port->port.flags |= UPF_BUG_THRE;
1144 port->port.serial_in = kt_serial_in;
1145 port->port.handle_break = kt_handle_break;
1146 return skip_tx_en_setup(priv, board, port, idx);
1147}
1148
1149static int pci_eg20t_init(struct pci_dev *dev)
1150{
1151#if defined(CONFIG_SERIAL_PCH_UART) || defined(CONFIG_SERIAL_PCH_UART_MODULE)
1152 return -ENODEV;
1153#else
1154 return 0;
1155#endif
1156}
1157
1158static int
1159pci_xr17c154_setup(struct serial_private *priv,
1160 const struct pciserial_board *board,
1161 struct uart_8250_port *port, int idx)
1162{
1163 port->port.flags |= UPF_EXAR_EFR;
1164 return pci_default_setup(priv, board, port, idx);
1165}
1166
1167static int
1168pci_xr17v35x_setup(struct serial_private *priv,
1169 const struct pciserial_board *board,
1170 struct uart_8250_port *port, int idx)
1171{
1172 u8 __iomem *p;
1173
1174 p = pci_ioremap_bar(priv->dev, 0);
1175 if (p == NULL)
1176 return -ENOMEM;
1177
1178 port->port.flags |= UPF_EXAR_EFR;
1179
1180 /*
1181 * Setup Multipurpose Input/Output pins.
1182 */
1183 if (idx == 0) {
1184 writeb(0x00, p + 0x8f); /*MPIOINT[7:0]*/
1185 writeb(0x00, p + 0x90); /*MPIOLVL[7:0]*/
1186 writeb(0x00, p + 0x91); /*MPIO3T[7:0]*/
1187 writeb(0x00, p + 0x92); /*MPIOINV[7:0]*/
1188 writeb(0x00, p + 0x93); /*MPIOSEL[7:0]*/
1189 writeb(0x00, p + 0x94); /*MPIOOD[7:0]*/
1190 writeb(0x00, p + 0x95); /*MPIOINT[15:8]*/
1191 writeb(0x00, p + 0x96); /*MPIOLVL[15:8]*/
1192 writeb(0x00, p + 0x97); /*MPIO3T[15:8]*/
1193 writeb(0x00, p + 0x98); /*MPIOINV[15:8]*/
1194 writeb(0x00, p + 0x99); /*MPIOSEL[15:8]*/
1195 writeb(0x00, p + 0x9a); /*MPIOOD[15:8]*/
1196 }
1197 writeb(0x00, p + UART_EXAR_8XMODE);
1198 writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR);
1199 writeb(128, p + UART_EXAR_TXTRG);
1200 writeb(128, p + UART_EXAR_RXTRG);
1201 iounmap(p);
1202
1203 return pci_default_setup(priv, board, port, idx);
1204}
1205
1206#define PCI_DEVICE_ID_COMMTECH_4222PCI335 0x0004
1207#define PCI_DEVICE_ID_COMMTECH_4224PCI335 0x0002
1208#define PCI_DEVICE_ID_COMMTECH_2324PCI335 0x000a
1209#define PCI_DEVICE_ID_COMMTECH_2328PCI335 0x000b
1210
1211static int
1212pci_fastcom335_setup(struct serial_private *priv,
1213 const struct pciserial_board *board,
1214 struct uart_8250_port *port, int idx)
1215{
1216 u8 __iomem *p;
1217
1218 p = pci_ioremap_bar(priv->dev, 0);
1219 if (p == NULL)
1220 return -ENOMEM;
1221
1222 port->port.flags |= UPF_EXAR_EFR;
1223
1224 /*
1225 * Setup Multipurpose Input/Output pins.
1226 */
1227 if (idx == 0) {
1228 switch (priv->dev->device) {
1229 case PCI_DEVICE_ID_COMMTECH_4222PCI335:
1230 case PCI_DEVICE_ID_COMMTECH_4224PCI335:
1231 writeb(0x78, p + 0x90); /* MPIOLVL[7:0] */
1232 writeb(0x00, p + 0x92); /* MPIOINV[7:0] */
1233 writeb(0x00, p + 0x93); /* MPIOSEL[7:0] */
1234 break;
1235 case PCI_DEVICE_ID_COMMTECH_2324PCI335:
1236 case PCI_DEVICE_ID_COMMTECH_2328PCI335:
1237 writeb(0x00, p + 0x90); /* MPIOLVL[7:0] */
1238 writeb(0xc0, p + 0x92); /* MPIOINV[7:0] */
1239 writeb(0xc0, p + 0x93); /* MPIOSEL[7:0] */
1240 break;
1241 }
1242 writeb(0x00, p + 0x8f); /* MPIOINT[7:0] */
1243 writeb(0x00, p + 0x91); /* MPIO3T[7:0] */
1244 writeb(0x00, p + 0x94); /* MPIOOD[7:0] */
1245 }
1246 writeb(0x00, p + UART_EXAR_8XMODE);
1247 writeb(UART_FCTR_EXAR_TRGD, p + UART_EXAR_FCTR);
1248 writeb(32, p + UART_EXAR_TXTRG);
1249 writeb(32, p + UART_EXAR_RXTRG);
1250 iounmap(p);
1251
1252 return pci_default_setup(priv, board, port, idx);
1253}
1254
1255static int
1256pci_wch_ch353_setup(struct serial_private *priv,
1257 const struct pciserial_board *board,
1258 struct uart_8250_port *port, int idx)
1259{
1260 port->port.flags |= UPF_FIXED_TYPE;
1261 port->port.type = PORT_16550A;
1262 return pci_default_setup(priv, board, port, idx);
1263}
1264
1265#define PCI_VENDOR_ID_SBSMODULARIO 0x124B
1266#define PCI_SUBVENDOR_ID_SBSMODULARIO 0x124B
1267#define PCI_DEVICE_ID_OCTPRO 0x0001
1268#define PCI_SUBDEVICE_ID_OCTPRO232 0x0108
1269#define PCI_SUBDEVICE_ID_OCTPRO422 0x0208
1270#define PCI_SUBDEVICE_ID_POCTAL232 0x0308
1271#define PCI_SUBDEVICE_ID_POCTAL422 0x0408
1272#define PCI_SUBDEVICE_ID_SIIG_DUAL_00 0x2500
1273#define PCI_SUBDEVICE_ID_SIIG_DUAL_30 0x2530
1274#define PCI_VENDOR_ID_ADVANTECH 0x13fe
1275#define PCI_DEVICE_ID_INTEL_CE4100_UART 0x2e66
1276#define PCI_DEVICE_ID_ADVANTECH_PCI3620 0x3620
1277#define PCI_DEVICE_ID_TITAN_200I 0x8028
1278#define PCI_DEVICE_ID_TITAN_400I 0x8048
1279#define PCI_DEVICE_ID_TITAN_800I 0x8088
1280#define PCI_DEVICE_ID_TITAN_800EH 0xA007
1281#define PCI_DEVICE_ID_TITAN_800EHB 0xA008
1282#define PCI_DEVICE_ID_TITAN_400EH 0xA009
1283#define PCI_DEVICE_ID_TITAN_100E 0xA010
1284#define PCI_DEVICE_ID_TITAN_200E 0xA012
1285#define PCI_DEVICE_ID_TITAN_400E 0xA013
1286#define PCI_DEVICE_ID_TITAN_800E 0xA014
1287#define PCI_DEVICE_ID_TITAN_200EI 0xA016
1288#define PCI_DEVICE_ID_TITAN_200EISI 0xA017
1289#define PCI_DEVICE_ID_TITAN_400V3 0xA310
1290#define PCI_DEVICE_ID_TITAN_410V3 0xA312
1291#define PCI_DEVICE_ID_TITAN_800V3 0xA314
1292#define PCI_DEVICE_ID_TITAN_800V3B 0xA315
1293#define PCI_DEVICE_ID_OXSEMI_16PCI958 0x9538
1294#define PCIE_DEVICE_ID_NEO_2_OX_IBM 0x00F6
1295#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA 0xc001
1296#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d
1297#define PCI_VENDOR_ID_WCH 0x4348
1298#define PCI_DEVICE_ID_WCH_CH353_4S 0x3453
1299#define PCI_DEVICE_ID_WCH_CH353_2S1PF 0x5046
1300#define PCI_DEVICE_ID_WCH_CH353_2S1P 0x7053
1301#define PCI_VENDOR_ID_AGESTAR 0x5372
1302#define PCI_DEVICE_ID_AGESTAR_9375 0x6872
1303#define PCI_VENDOR_ID_ASIX 0x9710
1304#define PCI_DEVICE_ID_COMMTECH_4222PCIE 0x0019
1305#define PCI_DEVICE_ID_COMMTECH_4224PCIE 0x0020
1306#define PCI_DEVICE_ID_COMMTECH_4228PCIE 0x0021
1307
1308
1309/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
1310#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584
1311
1312/*
1313 * Master list of serial port init/setup/exit quirks.
1314 * This does not describe the general nature of the port.
1315 * (ie, baud base, number and location of ports, etc)
1316 *
1317 * This list is ordered alphabetically by vendor then device.
1318 * Specific entries must come before more generic entries.
1319 */
1320static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
1321 /*
1322 * ADDI-DATA GmbH communication cards <info@addi-data.com>
1323 */
1324 {
1325 .vendor = PCI_VENDOR_ID_ADDIDATA_OLD,
1326 .device = PCI_DEVICE_ID_ADDIDATA_APCI7800,
1327 .subvendor = PCI_ANY_ID,
1328 .subdevice = PCI_ANY_ID,
1329 .setup = addidata_apci7800_setup,
1330 },
1331 /*
1332 * AFAVLAB cards - these may be called via parport_serial
1333 * It is not clear whether this applies to all products.
1334 */
1335 {
1336 .vendor = PCI_VENDOR_ID_AFAVLAB,
1337 .device = PCI_ANY_ID,
1338 .subvendor = PCI_ANY_ID,
1339 .subdevice = PCI_ANY_ID,
1340 .setup = afavlab_setup,
1341 },
1342 /*
1343 * HP Diva
1344 */
1345 {
1346 .vendor = PCI_VENDOR_ID_HP,
1347 .device = PCI_DEVICE_ID_HP_DIVA,
1348 .subvendor = PCI_ANY_ID,
1349 .subdevice = PCI_ANY_ID,
1350 .init = pci_hp_diva_init,
1351 .setup = pci_hp_diva_setup,
1352 },
1353 /*
1354 * Intel
1355 */
1356 {
1357 .vendor = PCI_VENDOR_ID_INTEL,
1358 .device = PCI_DEVICE_ID_INTEL_80960_RP,
1359 .subvendor = 0xe4bf,
1360 .subdevice = PCI_ANY_ID,
1361 .init = pci_inteli960ni_init,
1362 .setup = pci_default_setup,
1363 },
1364 {
1365 .vendor = PCI_VENDOR_ID_INTEL,
1366 .device = PCI_DEVICE_ID_INTEL_8257X_SOL,
1367 .subvendor = PCI_ANY_ID,
1368 .subdevice = PCI_ANY_ID,
1369 .setup = skip_tx_en_setup,
1370 },
1371 {
1372 .vendor = PCI_VENDOR_ID_INTEL,
1373 .device = PCI_DEVICE_ID_INTEL_82573L_SOL,
1374 .subvendor = PCI_ANY_ID,
1375 .subdevice = PCI_ANY_ID,
1376 .setup = skip_tx_en_setup,
1377 },
1378 {
1379 .vendor = PCI_VENDOR_ID_INTEL,
1380 .device = PCI_DEVICE_ID_INTEL_82573E_SOL,
1381 .subvendor = PCI_ANY_ID,
1382 .subdevice = PCI_ANY_ID,
1383 .setup = skip_tx_en_setup,
1384 },
1385 {
1386 .vendor = PCI_VENDOR_ID_INTEL,
1387 .device = PCI_DEVICE_ID_INTEL_CE4100_UART,
1388 .subvendor = PCI_ANY_ID,
1389 .subdevice = PCI_ANY_ID,
1390 .setup = ce4100_serial_setup,
1391 },
1392 {
1393 .vendor = PCI_VENDOR_ID_INTEL,
1394 .device = PCI_DEVICE_ID_INTEL_PATSBURG_KT,
1395 .subvendor = PCI_ANY_ID,
1396 .subdevice = PCI_ANY_ID,
1397 .setup = kt_serial_setup,
1398 },
1399 /*
1400 * ITE
1401 */
1402 {
1403 .vendor = PCI_VENDOR_ID_ITE,
1404 .device = PCI_DEVICE_ID_ITE_8872,
1405 .subvendor = PCI_ANY_ID,
1406 .subdevice = PCI_ANY_ID,
1407 .init = pci_ite887x_init,
1408 .setup = pci_default_setup,
1409 .exit = pci_ite887x_exit,
1410 },
1411 /*
1412 * National Instruments
1413 */
1414 {
1415 .vendor = PCI_VENDOR_ID_NI,
1416 .device = PCI_DEVICE_ID_NI_PCI23216,
1417 .subvendor = PCI_ANY_ID,
1418 .subdevice = PCI_ANY_ID,
1419 .init = pci_ni8420_init,
1420 .setup = pci_default_setup,
1421 .exit = pci_ni8420_exit,
1422 },
1423 {
1424 .vendor = PCI_VENDOR_ID_NI,
1425 .device = PCI_DEVICE_ID_NI_PCI2328,
1426 .subvendor = PCI_ANY_ID,
1427 .subdevice = PCI_ANY_ID,
1428 .init = pci_ni8420_init,
1429 .setup = pci_default_setup,
1430 .exit = pci_ni8420_exit,
1431 },
1432 {
1433 .vendor = PCI_VENDOR_ID_NI,
1434 .device = PCI_DEVICE_ID_NI_PCI2324,
1435 .subvendor = PCI_ANY_ID,
1436 .subdevice = PCI_ANY_ID,
1437 .init = pci_ni8420_init,
1438 .setup = pci_default_setup,
1439 .exit = pci_ni8420_exit,
1440 },
1441 {
1442 .vendor = PCI_VENDOR_ID_NI,
1443 .device = PCI_DEVICE_ID_NI_PCI2322,
1444 .subvendor = PCI_ANY_ID,
1445 .subdevice = PCI_ANY_ID,
1446 .init = pci_ni8420_init,
1447 .setup = pci_default_setup,
1448 .exit = pci_ni8420_exit,
1449 },
1450 {
1451 .vendor = PCI_VENDOR_ID_NI,
1452 .device = PCI_DEVICE_ID_NI_PCI2324I,
1453 .subvendor = PCI_ANY_ID,
1454 .subdevice = PCI_ANY_ID,
1455 .init = pci_ni8420_init,
1456 .setup = pci_default_setup,
1457 .exit = pci_ni8420_exit,
1458 },
1459 {
1460 .vendor = PCI_VENDOR_ID_NI,
1461 .device = PCI_DEVICE_ID_NI_PCI2322I,
1462 .subvendor = PCI_ANY_ID,
1463 .subdevice = PCI_ANY_ID,
1464 .init = pci_ni8420_init,
1465 .setup = pci_default_setup,
1466 .exit = pci_ni8420_exit,
1467 },
1468 {
1469 .vendor = PCI_VENDOR_ID_NI,
1470 .device = PCI_DEVICE_ID_NI_PXI8420_23216,
1471 .subvendor = PCI_ANY_ID,
1472 .subdevice = PCI_ANY_ID,
1473 .init = pci_ni8420_init,
1474 .setup = pci_default_setup,
1475 .exit = pci_ni8420_exit,
1476 },
1477 {
1478 .vendor = PCI_VENDOR_ID_NI,
1479 .device = PCI_DEVICE_ID_NI_PXI8420_2328,
1480 .subvendor = PCI_ANY_ID,
1481 .subdevice = PCI_ANY_ID,
1482 .init = pci_ni8420_init,
1483 .setup = pci_default_setup,
1484 .exit = pci_ni8420_exit,
1485 },
1486 {
1487 .vendor = PCI_VENDOR_ID_NI,
1488 .device = PCI_DEVICE_ID_NI_PXI8420_2324,
1489 .subvendor = PCI_ANY_ID,
1490 .subdevice = PCI_ANY_ID,
1491 .init = pci_ni8420_init,
1492 .setup = pci_default_setup,
1493 .exit = pci_ni8420_exit,
1494 },
1495 {
1496 .vendor = PCI_VENDOR_ID_NI,
1497 .device = PCI_DEVICE_ID_NI_PXI8420_2322,
1498 .subvendor = PCI_ANY_ID,
1499 .subdevice = PCI_ANY_ID,
1500 .init = pci_ni8420_init,
1501 .setup = pci_default_setup,
1502 .exit = pci_ni8420_exit,
1503 },
1504 {
1505 .vendor = PCI_VENDOR_ID_NI,
1506 .device = PCI_DEVICE_ID_NI_PXI8422_2324,
1507 .subvendor = PCI_ANY_ID,
1508 .subdevice = PCI_ANY_ID,
1509 .init = pci_ni8420_init,
1510 .setup = pci_default_setup,
1511 .exit = pci_ni8420_exit,
1512 },
1513 {
1514 .vendor = PCI_VENDOR_ID_NI,
1515 .device = PCI_DEVICE_ID_NI_PXI8422_2322,
1516 .subvendor = PCI_ANY_ID,
1517 .subdevice = PCI_ANY_ID,
1518 .init = pci_ni8420_init,
1519 .setup = pci_default_setup,
1520 .exit = pci_ni8420_exit,
1521 },
1522 {
1523 .vendor = PCI_VENDOR_ID_NI,
1524 .device = PCI_ANY_ID,
1525 .subvendor = PCI_ANY_ID,
1526 .subdevice = PCI_ANY_ID,
1527 .init = pci_ni8430_init,
1528 .setup = pci_ni8430_setup,
1529 .exit = pci_ni8430_exit,
1530 },
1531 /*
1532 * Panacom
1533 */
1534 {
1535 .vendor = PCI_VENDOR_ID_PANACOM,
1536 .device = PCI_DEVICE_ID_PANACOM_QUADMODEM,
1537 .subvendor = PCI_ANY_ID,
1538 .subdevice = PCI_ANY_ID,
1539 .init = pci_plx9050_init,
1540 .setup = pci_default_setup,
1541 .exit = pci_plx9050_exit,
1542 },
1543 {
1544 .vendor = PCI_VENDOR_ID_PANACOM,
1545 .device = PCI_DEVICE_ID_PANACOM_DUALMODEM,
1546 .subvendor = PCI_ANY_ID,
1547 .subdevice = PCI_ANY_ID,
1548 .init = pci_plx9050_init,
1549 .setup = pci_default_setup,
1550 .exit = pci_plx9050_exit,
1551 },
1552 /*
1553 * PLX
1554 */
1555 {
1556 .vendor = PCI_VENDOR_ID_PLX,
1557 .device = PCI_DEVICE_ID_PLX_9030,
1558 .subvendor = PCI_SUBVENDOR_ID_PERLE,
1559 .subdevice = PCI_ANY_ID,
1560 .setup = pci_default_setup,
1561 },
1562 {
1563 .vendor = PCI_VENDOR_ID_PLX,
1564 .device = PCI_DEVICE_ID_PLX_9050,
1565 .subvendor = PCI_SUBVENDOR_ID_EXSYS,
1566 .subdevice = PCI_SUBDEVICE_ID_EXSYS_4055,
1567 .init = pci_plx9050_init,
1568 .setup = pci_default_setup,
1569 .exit = pci_plx9050_exit,
1570 },
1571 {
1572 .vendor = PCI_VENDOR_ID_PLX,
1573 .device = PCI_DEVICE_ID_PLX_9050,
1574 .subvendor = PCI_SUBVENDOR_ID_KEYSPAN,
1575 .subdevice = PCI_SUBDEVICE_ID_KEYSPAN_SX2,
1576 .init = pci_plx9050_init,
1577 .setup = pci_default_setup,
1578 .exit = pci_plx9050_exit,
1579 },
1580 {
1581 .vendor = PCI_VENDOR_ID_PLX,
1582 .device = PCI_DEVICE_ID_PLX_9050,
1583 .subvendor = PCI_VENDOR_ID_PLX,
1584 .subdevice = PCI_SUBDEVICE_ID_UNKNOWN_0x1584,
1585 .init = pci_plx9050_init,
1586 .setup = pci_default_setup,
1587 .exit = pci_plx9050_exit,
1588 },
1589 {
1590 .vendor = PCI_VENDOR_ID_PLX,
1591 .device = PCI_DEVICE_ID_PLX_ROMULUS,
1592 .subvendor = PCI_VENDOR_ID_PLX,
1593 .subdevice = PCI_DEVICE_ID_PLX_ROMULUS,
1594 .init = pci_plx9050_init,
1595 .setup = pci_default_setup,
1596 .exit = pci_plx9050_exit,
1597 },
1598 /*
1599 * SBS Technologies, Inc., PMC-OCTALPRO 232
1600 */
1601 {
1602 .vendor = PCI_VENDOR_ID_SBSMODULARIO,
1603 .device = PCI_DEVICE_ID_OCTPRO,
1604 .subvendor = PCI_SUBVENDOR_ID_SBSMODULARIO,
1605 .subdevice = PCI_SUBDEVICE_ID_OCTPRO232,
1606 .init = sbs_init,
1607 .setup = sbs_setup,
1608 .exit = sbs_exit,
1609 },
1610 /*
1611 * SBS Technologies, Inc., PMC-OCTALPRO 422
1612 */
1613 {
1614 .vendor = PCI_VENDOR_ID_SBSMODULARIO,
1615 .device = PCI_DEVICE_ID_OCTPRO,
1616 .subvendor = PCI_SUBVENDOR_ID_SBSMODULARIO,
1617 .subdevice = PCI_SUBDEVICE_ID_OCTPRO422,
1618 .init = sbs_init,
1619 .setup = sbs_setup,
1620 .exit = sbs_exit,
1621 },
1622 /*
1623 * SBS Technologies, Inc., P-Octal 232
1624 */
1625 {
1626 .vendor = PCI_VENDOR_ID_SBSMODULARIO,
1627 .device = PCI_DEVICE_ID_OCTPRO,
1628 .subvendor = PCI_SUBVENDOR_ID_SBSMODULARIO,
1629 .subdevice = PCI_SUBDEVICE_ID_POCTAL232,
1630 .init = sbs_init,
1631 .setup = sbs_setup,
1632 .exit = sbs_exit,
1633 },
1634 /*
1635 * SBS Technologies, Inc., P-Octal 422
1636 */
1637 {
1638 .vendor = PCI_VENDOR_ID_SBSMODULARIO,
1639 .device = PCI_DEVICE_ID_OCTPRO,
1640 .subvendor = PCI_SUBVENDOR_ID_SBSMODULARIO,
1641 .subdevice = PCI_SUBDEVICE_ID_POCTAL422,
1642 .init = sbs_init,
1643 .setup = sbs_setup,
1644 .exit = sbs_exit,
1645 },
1646 /*
1647 * SIIG cards - these may be called via parport_serial
1648 */
1649 {
1650 .vendor = PCI_VENDOR_ID_SIIG,
1651 .device = PCI_ANY_ID,
1652 .subvendor = PCI_ANY_ID,
1653 .subdevice = PCI_ANY_ID,
1654 .init = pci_siig_init,
1655 .setup = pci_siig_setup,
1656 },
1657 /*
1658 * Titan cards
1659 */
1660 {
1661 .vendor = PCI_VENDOR_ID_TITAN,
1662 .device = PCI_DEVICE_ID_TITAN_400L,
1663 .subvendor = PCI_ANY_ID,
1664 .subdevice = PCI_ANY_ID,
1665 .setup = titan_400l_800l_setup,
1666 },
1667 {
1668 .vendor = PCI_VENDOR_ID_TITAN,
1669 .device = PCI_DEVICE_ID_TITAN_800L,
1670 .subvendor = PCI_ANY_ID,
1671 .subdevice = PCI_ANY_ID,
1672 .setup = titan_400l_800l_setup,
1673 },
1674 /*
1675 * Timedia cards
1676 */
1677 {
1678 .vendor = PCI_VENDOR_ID_TIMEDIA,
1679 .device = PCI_DEVICE_ID_TIMEDIA_1889,
1680 .subvendor = PCI_VENDOR_ID_TIMEDIA,
1681 .subdevice = PCI_ANY_ID,
1682 .probe = pci_timedia_probe,
1683 .init = pci_timedia_init,
1684 .setup = pci_timedia_setup,
1685 },
1686 {
1687 .vendor = PCI_VENDOR_ID_TIMEDIA,
1688 .device = PCI_ANY_ID,
1689 .subvendor = PCI_ANY_ID,
1690 .subdevice = PCI_ANY_ID,
1691 .setup = pci_timedia_setup,
1692 },
1693 /*
1694 * Exar cards
1695 */
1696 {
1697 .vendor = PCI_VENDOR_ID_EXAR,
1698 .device = PCI_DEVICE_ID_EXAR_XR17C152,
1699 .subvendor = PCI_ANY_ID,
1700 .subdevice = PCI_ANY_ID,
1701 .setup = pci_xr17c154_setup,
1702 },
1703 {
1704 .vendor = PCI_VENDOR_ID_EXAR,
1705 .device = PCI_DEVICE_ID_EXAR_XR17C154,
1706 .subvendor = PCI_ANY_ID,
1707 .subdevice = PCI_ANY_ID,
1708 .setup = pci_xr17c154_setup,
1709 },
1710 {
1711 .vendor = PCI_VENDOR_ID_EXAR,
1712 .device = PCI_DEVICE_ID_EXAR_XR17C158,
1713 .subvendor = PCI_ANY_ID,
1714 .subdevice = PCI_ANY_ID,
1715 .setup = pci_xr17c154_setup,
1716 },
1717 {
1718 .vendor = PCI_VENDOR_ID_EXAR,
1719 .device = PCI_DEVICE_ID_EXAR_XR17V352,
1720 .subvendor = PCI_ANY_ID,
1721 .subdevice = PCI_ANY_ID,
1722 .setup = pci_xr17v35x_setup,
1723 },
1724 {
1725 .vendor = PCI_VENDOR_ID_EXAR,
1726 .device = PCI_DEVICE_ID_EXAR_XR17V354,
1727 .subvendor = PCI_ANY_ID,
1728 .subdevice = PCI_ANY_ID,
1729 .setup = pci_xr17v35x_setup,
1730 },
1731 {
1732 .vendor = PCI_VENDOR_ID_EXAR,
1733 .device = PCI_DEVICE_ID_EXAR_XR17V358,
1734 .subvendor = PCI_ANY_ID,
1735 .subdevice = PCI_ANY_ID,
1736 .setup = pci_xr17v35x_setup,
1737 },
1738 /*
1739 * Xircom cards
1740 */
1741 {
1742 .vendor = PCI_VENDOR_ID_XIRCOM,
1743 .device = PCI_DEVICE_ID_XIRCOM_X3201_MDM,
1744 .subvendor = PCI_ANY_ID,
1745 .subdevice = PCI_ANY_ID,
1746 .init = pci_xircom_init,
1747 .setup = pci_default_setup,
1748 },
1749 /*
1750 * Netmos cards - these may be called via parport_serial
1751 */
1752 {
1753 .vendor = PCI_VENDOR_ID_NETMOS,
1754 .device = PCI_ANY_ID,
1755 .subvendor = PCI_ANY_ID,
1756 .subdevice = PCI_ANY_ID,
1757 .init = pci_netmos_init,
1758 .setup = pci_netmos_9900_setup,
1759 },
1760 /*
1761 * For Oxford Semiconductor Tornado based devices
1762 */
1763 {
1764 .vendor = PCI_VENDOR_ID_OXSEMI,
1765 .device = PCI_ANY_ID,
1766 .subvendor = PCI_ANY_ID,
1767 .subdevice = PCI_ANY_ID,
1768 .init = pci_oxsemi_tornado_init,
1769 .setup = pci_default_setup,
1770 },
1771 {
1772 .vendor = PCI_VENDOR_ID_MAINPINE,
1773 .device = PCI_ANY_ID,
1774 .subvendor = PCI_ANY_ID,
1775 .subdevice = PCI_ANY_ID,
1776 .init = pci_oxsemi_tornado_init,
1777 .setup = pci_default_setup,
1778 },
1779 {
1780 .vendor = PCI_VENDOR_ID_DIGI,
1781 .device = PCIE_DEVICE_ID_NEO_2_OX_IBM,
1782 .subvendor = PCI_SUBVENDOR_ID_IBM,
1783 .subdevice = PCI_ANY_ID,
1784 .init = pci_oxsemi_tornado_init,
1785 .setup = pci_default_setup,
1786 },
1787 {
1788 .vendor = PCI_VENDOR_ID_INTEL,
1789 .device = 0x8811,
1790 .subvendor = PCI_ANY_ID,
1791 .subdevice = PCI_ANY_ID,
1792 .init = pci_eg20t_init,
1793 .setup = pci_default_setup,
1794 },
1795 {
1796 .vendor = PCI_VENDOR_ID_INTEL,
1797 .device = 0x8812,
1798 .subvendor = PCI_ANY_ID,
1799 .subdevice = PCI_ANY_ID,
1800 .init = pci_eg20t_init,
1801 .setup = pci_default_setup,
1802 },
1803 {
1804 .vendor = PCI_VENDOR_ID_INTEL,
1805 .device = 0x8813,
1806 .subvendor = PCI_ANY_ID,
1807 .subdevice = PCI_ANY_ID,
1808 .init = pci_eg20t_init,
1809 .setup = pci_default_setup,
1810 },
1811 {
1812 .vendor = PCI_VENDOR_ID_INTEL,
1813 .device = 0x8814,
1814 .subvendor = PCI_ANY_ID,
1815 .subdevice = PCI_ANY_ID,
1816 .init = pci_eg20t_init,
1817 .setup = pci_default_setup,
1818 },
1819 {
1820 .vendor = 0x10DB,
1821 .device = 0x8027,
1822 .subvendor = PCI_ANY_ID,
1823 .subdevice = PCI_ANY_ID,
1824 .init = pci_eg20t_init,
1825 .setup = pci_default_setup,
1826 },
1827 {
1828 .vendor = 0x10DB,
1829 .device = 0x8028,
1830 .subvendor = PCI_ANY_ID,
1831 .subdevice = PCI_ANY_ID,
1832 .init = pci_eg20t_init,
1833 .setup = pci_default_setup,
1834 },
1835 {
1836 .vendor = 0x10DB,
1837 .device = 0x8029,
1838 .subvendor = PCI_ANY_ID,
1839 .subdevice = PCI_ANY_ID,
1840 .init = pci_eg20t_init,
1841 .setup = pci_default_setup,
1842 },
1843 {
1844 .vendor = 0x10DB,
1845 .device = 0x800C,
1846 .subvendor = PCI_ANY_ID,
1847 .subdevice = PCI_ANY_ID,
1848 .init = pci_eg20t_init,
1849 .setup = pci_default_setup,
1850 },
1851 {
1852 .vendor = 0x10DB,
1853 .device = 0x800D,
1854 .subvendor = PCI_ANY_ID,
1855 .subdevice = PCI_ANY_ID,
1856 .init = pci_eg20t_init,
1857 .setup = pci_default_setup,
1858 },
1859 /*
1860 * Cronyx Omega PCI (PLX-chip based)
1861 */
1862 {
1863 .vendor = PCI_VENDOR_ID_PLX,
1864 .device = PCI_DEVICE_ID_PLX_CRONYX_OMEGA,
1865 .subvendor = PCI_ANY_ID,
1866 .subdevice = PCI_ANY_ID,
1867 .setup = pci_omegapci_setup,
1868 },
1869 /* WCH CH353 2S1P card (16550 clone) */
1870 {
1871 .vendor = PCI_VENDOR_ID_WCH,
1872 .device = PCI_DEVICE_ID_WCH_CH353_2S1P,
1873 .subvendor = PCI_ANY_ID,
1874 .subdevice = PCI_ANY_ID,
1875 .setup = pci_wch_ch353_setup,
1876 },
1877 /* WCH CH353 4S card (16550 clone) */
1878 {
1879 .vendor = PCI_VENDOR_ID_WCH,
1880 .device = PCI_DEVICE_ID_WCH_CH353_4S,
1881 .subvendor = PCI_ANY_ID,
1882 .subdevice = PCI_ANY_ID,
1883 .setup = pci_wch_ch353_setup,
1884 },
1885 /* WCH CH353 2S1PF card (16550 clone) */
1886 {
1887 .vendor = PCI_VENDOR_ID_WCH,
1888 .device = PCI_DEVICE_ID_WCH_CH353_2S1PF,
1889 .subvendor = PCI_ANY_ID,
1890 .subdevice = PCI_ANY_ID,
1891 .setup = pci_wch_ch353_setup,
1892 },
1893 /*
1894 * ASIX devices with FIFO bug
1895 */
1896 {
1897 .vendor = PCI_VENDOR_ID_ASIX,
1898 .device = PCI_ANY_ID,
1899 .subvendor = PCI_ANY_ID,
1900 .subdevice = PCI_ANY_ID,
1901 .setup = pci_asix_setup,
1902 },
1903 /*
1904 * Commtech, Inc. Fastcom adapters
1905 *
1906 */
1907 {
1908 .vendor = PCI_VENDOR_ID_COMMTECH,
1909 .device = PCI_DEVICE_ID_COMMTECH_4222PCI335,
1910 .subvendor = PCI_ANY_ID,
1911 .subdevice = PCI_ANY_ID,
1912 .setup = pci_fastcom335_setup,
1913 },
1914 {
1915 .vendor = PCI_VENDOR_ID_COMMTECH,
1916 .device = PCI_DEVICE_ID_COMMTECH_4224PCI335,
1917 .subvendor = PCI_ANY_ID,
1918 .subdevice = PCI_ANY_ID,
1919 .setup = pci_fastcom335_setup,
1920 },
1921 {
1922 .vendor = PCI_VENDOR_ID_COMMTECH,
1923 .device = PCI_DEVICE_ID_COMMTECH_2324PCI335,
1924 .subvendor = PCI_ANY_ID,
1925 .subdevice = PCI_ANY_ID,
1926 .setup = pci_fastcom335_setup,
1927 },
1928 {
1929 .vendor = PCI_VENDOR_ID_COMMTECH,
1930 .device = PCI_DEVICE_ID_COMMTECH_2328PCI335,
1931 .subvendor = PCI_ANY_ID,
1932 .subdevice = PCI_ANY_ID,
1933 .setup = pci_fastcom335_setup,
1934 },
1935 {
1936 .vendor = PCI_VENDOR_ID_COMMTECH,
1937 .device = PCI_DEVICE_ID_COMMTECH_4222PCIE,
1938 .subvendor = PCI_ANY_ID,
1939 .subdevice = PCI_ANY_ID,
1940 .setup = pci_xr17v35x_setup,
1941 },
1942 {
1943 .vendor = PCI_VENDOR_ID_COMMTECH,
1944 .device = PCI_DEVICE_ID_COMMTECH_4224PCIE,
1945 .subvendor = PCI_ANY_ID,
1946 .subdevice = PCI_ANY_ID,
1947 .setup = pci_xr17v35x_setup,
1948 },
1949 {
1950 .vendor = PCI_VENDOR_ID_COMMTECH,
1951 .device = PCI_DEVICE_ID_COMMTECH_4228PCIE,
1952 .subvendor = PCI_ANY_ID,
1953 .subdevice = PCI_ANY_ID,
1954 .setup = pci_xr17v35x_setup,
1955 },
1956 /*
1957 * Default "match everything" terminator entry
1958 */
1959 {
1960 .vendor = PCI_ANY_ID,
1961 .device = PCI_ANY_ID,
1962 .subvendor = PCI_ANY_ID,
1963 .subdevice = PCI_ANY_ID,
1964 .setup = pci_default_setup,
1965 }
1966};
1967
1968static inline int quirk_id_matches(u32 quirk_id, u32 dev_id)
1969{
1970 return quirk_id == PCI_ANY_ID || quirk_id == dev_id;
1971}
1972
1973static struct pci_serial_quirk *find_quirk(struct pci_dev *dev)
1974{
1975 struct pci_serial_quirk *quirk;
1976
1977 for (quirk = pci_serial_quirks; ; quirk++)
1978 if (quirk_id_matches(quirk->vendor, dev->vendor) &&
1979 quirk_id_matches(quirk->device, dev->device) &&
1980 quirk_id_matches(quirk->subvendor, dev->subsystem_vendor) &&
1981 quirk_id_matches(quirk->subdevice, dev->subsystem_device))
1982 break;
1983 return quirk;
1984}
1985
1986static inline int get_pci_irq(struct pci_dev *dev,
1987 const struct pciserial_board *board)
1988{
1989 if (board->flags & FL_NOIRQ)
1990 return 0;
1991 else
1992 return dev->irq;
1993}
1994
1995/*
1996 * This is the configuration table for all of the PCI serial boards
1997 * which we support. It is directly indexed by the pci_board_num_t enum
1998 * value, which is encoded in the pci_device_id PCI probe table's
1999 * driver_data member.
2000 *
2001 * The makeup of these names are:
2002 * pbn_bn{_bt}_n_baud{_offsetinhex}
2003 *
2004 * bn = PCI BAR number
2005 * bt = Index using PCI BARs
2006 * n = number of serial ports
2007 * baud = baud rate
2008 * offsetinhex = offset for each sequential port (in hex)
2009 *
2010 * This table is sorted by (in order): bn, bt, baud, offsetindex, n.
2011 *
2012 * Please note: in theory if n = 1, _bt infix should make no difference.
2013 * ie, pbn_b0_1_115200 is the same as pbn_b0_bt_1_115200
2014 */
2015enum pci_board_num_t {
2016 pbn_default = 0,
2017
2018 pbn_b0_1_115200,
2019 pbn_b0_2_115200,
2020 pbn_b0_4_115200,
2021 pbn_b0_5_115200,
2022 pbn_b0_8_115200,
2023
2024 pbn_b0_1_921600,
2025 pbn_b0_2_921600,
2026 pbn_b0_4_921600,
2027
2028 pbn_b0_2_1130000,
2029
2030 pbn_b0_4_1152000,
2031
2032 pbn_b0_2_1152000_200,
2033 pbn_b0_4_1152000_200,
2034 pbn_b0_8_1152000_200,
2035
2036 pbn_b0_2_1843200,
2037 pbn_b0_4_1843200,
2038
2039 pbn_b0_2_1843200_200,
2040 pbn_b0_4_1843200_200,
2041 pbn_b0_8_1843200_200,
2042
2043 pbn_b0_1_4000000,
2044
2045 pbn_b0_bt_1_115200,
2046 pbn_b0_bt_2_115200,
2047 pbn_b0_bt_4_115200,
2048 pbn_b0_bt_8_115200,
2049
2050 pbn_b0_bt_1_460800,
2051 pbn_b0_bt_2_460800,
2052 pbn_b0_bt_4_460800,
2053
2054 pbn_b0_bt_1_921600,
2055 pbn_b0_bt_2_921600,
2056 pbn_b0_bt_4_921600,
2057 pbn_b0_bt_8_921600,
2058
2059 pbn_b1_1_115200,
2060 pbn_b1_2_115200,
2061 pbn_b1_4_115200,
2062 pbn_b1_8_115200,
2063 pbn_b1_16_115200,
2064
2065 pbn_b1_1_921600,
2066 pbn_b1_2_921600,
2067 pbn_b1_4_921600,
2068 pbn_b1_8_921600,
2069
2070 pbn_b1_2_1250000,
2071
2072 pbn_b1_bt_1_115200,
2073 pbn_b1_bt_2_115200,
2074 pbn_b1_bt_4_115200,
2075
2076 pbn_b1_bt_2_921600,
2077
2078 pbn_b1_1_1382400,
2079 pbn_b1_2_1382400,
2080 pbn_b1_4_1382400,
2081 pbn_b1_8_1382400,
2082
2083 pbn_b2_1_115200,
2084 pbn_b2_2_115200,
2085 pbn_b2_4_115200,
2086 pbn_b2_8_115200,
2087
2088 pbn_b2_1_460800,
2089 pbn_b2_4_460800,
2090 pbn_b2_8_460800,
2091 pbn_b2_16_460800,
2092
2093 pbn_b2_1_921600,
2094 pbn_b2_4_921600,
2095 pbn_b2_8_921600,
2096
2097 pbn_b2_8_1152000,
2098
2099 pbn_b2_bt_1_115200,
2100 pbn_b2_bt_2_115200,
2101 pbn_b2_bt_4_115200,
2102
2103 pbn_b2_bt_2_921600,
2104 pbn_b2_bt_4_921600,
2105
2106 pbn_b3_2_115200,
2107 pbn_b3_4_115200,
2108 pbn_b3_8_115200,
2109
2110 pbn_b4_bt_2_921600,
2111 pbn_b4_bt_4_921600,
2112 pbn_b4_bt_8_921600,
2113
2114 /*
2115 * Board-specific versions.
2116 */
2117 pbn_panacom,
2118 pbn_panacom2,
2119 pbn_panacom4,
2120 pbn_plx_romulus,
2121 pbn_oxsemi,
2122 pbn_oxsemi_1_4000000,
2123 pbn_oxsemi_2_4000000,
2124 pbn_oxsemi_4_4000000,
2125 pbn_oxsemi_8_4000000,
2126 pbn_intel_i960,
2127 pbn_sgi_ioc3,
2128 pbn_computone_4,
2129 pbn_computone_6,
2130 pbn_computone_8,
2131 pbn_sbsxrsio,
2132 pbn_exar_XR17C152,
2133 pbn_exar_XR17C154,
2134 pbn_exar_XR17C158,
2135 pbn_exar_XR17V352,
2136 pbn_exar_XR17V354,
2137 pbn_exar_XR17V358,
2138 pbn_exar_ibm_saturn,
2139 pbn_pasemi_1682M,
2140 pbn_ni8430_2,
2141 pbn_ni8430_4,
2142 pbn_ni8430_8,
2143 pbn_ni8430_16,
2144 pbn_ADDIDATA_PCIe_1_3906250,
2145 pbn_ADDIDATA_PCIe_2_3906250,
2146 pbn_ADDIDATA_PCIe_4_3906250,
2147 pbn_ADDIDATA_PCIe_8_3906250,
2148 pbn_ce4100_1_115200,
2149 pbn_omegapci,
2150 pbn_NETMOS9900_2s_115200,
2151};
2152
2153/*
2154 * uart_offset - the space between channels
2155 * reg_shift - describes how the UART registers are mapped
2156 * to PCI memory by the card.
2157 * For example IER register on SBS, Inc. PMC-OctPro is located at
2158 * offset 0x10 from the UART base, while UART_IER is defined as 1
2159 * in include/linux/serial_reg.h,
2160 * see first lines of serial_in() and serial_out() in 8250.c
2161*/
2162
2163static struct pciserial_board pci_boards[] = {
2164 [pbn_default] = {
2165 .flags = FL_BASE0,
2166 .num_ports = 1,
2167 .base_baud = 115200,
2168 .uart_offset = 8,
2169 },
2170 [pbn_b0_1_115200] = {
2171 .flags = FL_BASE0,
2172 .num_ports = 1,
2173 .base_baud = 115200,
2174 .uart_offset = 8,
2175 },
2176 [pbn_b0_2_115200] = {
2177 .flags = FL_BASE0,
2178 .num_ports = 2,
2179 .base_baud = 115200,
2180 .uart_offset = 8,
2181 },
2182 [pbn_b0_4_115200] = {
2183 .flags = FL_BASE0,
2184 .num_ports = 4,
2185 .base_baud = 115200,
2186 .uart_offset = 8,
2187 },
2188 [pbn_b0_5_115200] = {
2189 .flags = FL_BASE0,
2190 .num_ports = 5,
2191 .base_baud = 115200,
2192 .uart_offset = 8,
2193 },
2194 [pbn_b0_8_115200] = {
2195 .flags = FL_BASE0,
2196 .num_ports = 8,
2197 .base_baud = 115200,
2198 .uart_offset = 8,
2199 },
2200 [pbn_b0_1_921600] = {
2201 .flags = FL_BASE0,
2202 .num_ports = 1,
2203 .base_baud = 921600,
2204 .uart_offset = 8,
2205 },
2206 [pbn_b0_2_921600] = {
2207 .flags = FL_BASE0,
2208 .num_ports = 2,
2209 .base_baud = 921600,
2210 .uart_offset = 8,
2211 },
2212 [pbn_b0_4_921600] = {
2213 .flags = FL_BASE0,
2214 .num_ports = 4,
2215 .base_baud = 921600,
2216 .uart_offset = 8,
2217 },
2218
2219 [pbn_b0_2_1130000] = {
2220 .flags = FL_BASE0,
2221 .num_ports = 2,
2222 .base_baud = 1130000,
2223 .uart_offset = 8,
2224 },
2225
2226 [pbn_b0_4_1152000] = {
2227 .flags = FL_BASE0,
2228 .num_ports = 4,
2229 .base_baud = 1152000,
2230 .uart_offset = 8,
2231 },
2232
2233 [pbn_b0_2_1152000_200] = {
2234 .flags = FL_BASE0,
2235 .num_ports = 2,
2236 .base_baud = 1152000,
2237 .uart_offset = 0x200,
2238 },
2239
2240 [pbn_b0_4_1152000_200] = {
2241 .flags = FL_BASE0,
2242 .num_ports = 4,
2243 .base_baud = 1152000,
2244 .uart_offset = 0x200,
2245 },
2246
2247 [pbn_b0_8_1152000_200] = {
2248 .flags = FL_BASE0,
2249 .num_ports = 2,
2250 .base_baud = 1152000,
2251 .uart_offset = 0x200,
2252 },
2253
2254 [pbn_b0_2_1843200] = {
2255 .flags = FL_BASE0,
2256 .num_ports = 2,
2257 .base_baud = 1843200,
2258 .uart_offset = 8,
2259 },
2260 [pbn_b0_4_1843200] = {
2261 .flags = FL_BASE0,
2262 .num_ports = 4,
2263 .base_baud = 1843200,
2264 .uart_offset = 8,
2265 },
2266
2267 [pbn_b0_2_1843200_200] = {
2268 .flags = FL_BASE0,
2269 .num_ports = 2,
2270 .base_baud = 1843200,
2271 .uart_offset = 0x200,
2272 },
2273 [pbn_b0_4_1843200_200] = {
2274 .flags = FL_BASE0,
2275 .num_ports = 4,
2276 .base_baud = 1843200,
2277 .uart_offset = 0x200,
2278 },
2279 [pbn_b0_8_1843200_200] = {
2280 .flags = FL_BASE0,
2281 .num_ports = 8,
2282 .base_baud = 1843200,
2283 .uart_offset = 0x200,
2284 },
2285 [pbn_b0_1_4000000] = {
2286 .flags = FL_BASE0,
2287 .num_ports = 1,
2288 .base_baud = 4000000,
2289 .uart_offset = 8,
2290 },
2291
2292 [pbn_b0_bt_1_115200] = {
2293 .flags = FL_BASE0|FL_BASE_BARS,
2294 .num_ports = 1,
2295 .base_baud = 115200,
2296 .uart_offset = 8,
2297 },
2298 [pbn_b0_bt_2_115200] = {
2299 .flags = FL_BASE0|FL_BASE_BARS,
2300 .num_ports = 2,
2301 .base_baud = 115200,
2302 .uart_offset = 8,
2303 },
2304 [pbn_b0_bt_4_115200] = {
2305 .flags = FL_BASE0|FL_BASE_BARS,
2306 .num_ports = 4,
2307 .base_baud = 115200,
2308 .uart_offset = 8,
2309 },
2310 [pbn_b0_bt_8_115200] = {
2311 .flags = FL_BASE0|FL_BASE_BARS,
2312 .num_ports = 8,
2313 .base_baud = 115200,
2314 .uart_offset = 8,
2315 },
2316
2317 [pbn_b0_bt_1_460800] = {
2318 .flags = FL_BASE0|FL_BASE_BARS,
2319 .num_ports = 1,
2320 .base_baud = 460800,
2321 .uart_offset = 8,
2322 },
2323 [pbn_b0_bt_2_460800] = {
2324 .flags = FL_BASE0|FL_BASE_BARS,
2325 .num_ports = 2,
2326 .base_baud = 460800,
2327 .uart_offset = 8,
2328 },
2329 [pbn_b0_bt_4_460800] = {
2330 .flags = FL_BASE0|FL_BASE_BARS,
2331 .num_ports = 4,
2332 .base_baud = 460800,
2333 .uart_offset = 8,
2334 },
2335
2336 [pbn_b0_bt_1_921600] = {
2337 .flags = FL_BASE0|FL_BASE_BARS,
2338 .num_ports = 1,
2339 .base_baud = 921600,
2340 .uart_offset = 8,
2341 },
2342 [pbn_b0_bt_2_921600] = {
2343 .flags = FL_BASE0|FL_BASE_BARS,
2344 .num_ports = 2,
2345 .base_baud = 921600,
2346 .uart_offset = 8,
2347 },
2348 [pbn_b0_bt_4_921600] = {
2349 .flags = FL_BASE0|FL_BASE_BARS,
2350 .num_ports = 4,
2351 .base_baud = 921600,
2352 .uart_offset = 8,
2353 },
2354 [pbn_b0_bt_8_921600] = {
2355 .flags = FL_BASE0|FL_BASE_BARS,
2356 .num_ports = 8,
2357 .base_baud = 921600,
2358 .uart_offset = 8,
2359 },
2360
2361 [pbn_b1_1_115200] = {
2362 .flags = FL_BASE1,
2363 .num_ports = 1,
2364 .base_baud = 115200,
2365 .uart_offset = 8,
2366 },
2367 [pbn_b1_2_115200] = {
2368 .flags = FL_BASE1,
2369 .num_ports = 2,
2370 .base_baud = 115200,
2371 .uart_offset = 8,
2372 },
2373 [pbn_b1_4_115200] = {
2374 .flags = FL_BASE1,
2375 .num_ports = 4,
2376 .base_baud = 115200,
2377 .uart_offset = 8,
2378 },
2379 [pbn_b1_8_115200] = {
2380 .flags = FL_BASE1,
2381 .num_ports = 8,
2382 .base_baud = 115200,
2383 .uart_offset = 8,
2384 },
2385 [pbn_b1_16_115200] = {
2386 .flags = FL_BASE1,
2387 .num_ports = 16,
2388 .base_baud = 115200,
2389 .uart_offset = 8,
2390 },
2391
2392 [pbn_b1_1_921600] = {
2393 .flags = FL_BASE1,
2394 .num_ports = 1,
2395 .base_baud = 921600,
2396 .uart_offset = 8,
2397 },
2398 [pbn_b1_2_921600] = {
2399 .flags = FL_BASE1,
2400 .num_ports = 2,
2401 .base_baud = 921600,
2402 .uart_offset = 8,
2403 },
2404 [pbn_b1_4_921600] = {
2405 .flags = FL_BASE1,
2406 .num_ports = 4,
2407 .base_baud = 921600,
2408 .uart_offset = 8,
2409 },
2410 [pbn_b1_8_921600] = {
2411 .flags = FL_BASE1,
2412 .num_ports = 8,
2413 .base_baud = 921600,
2414 .uart_offset = 8,
2415 },
2416 [pbn_b1_2_1250000] = {
2417 .flags = FL_BASE1,
2418 .num_ports = 2,
2419 .base_baud = 1250000,
2420 .uart_offset = 8,
2421 },
2422
2423 [pbn_b1_bt_1_115200] = {
2424 .flags = FL_BASE1|FL_BASE_BARS,
2425 .num_ports = 1,
2426 .base_baud = 115200,
2427 .uart_offset = 8,
2428 },
2429 [pbn_b1_bt_2_115200] = {
2430 .flags = FL_BASE1|FL_BASE_BARS,
2431 .num_ports = 2,
2432 .base_baud = 115200,
2433 .uart_offset = 8,
2434 },
2435 [pbn_b1_bt_4_115200] = {
2436 .flags = FL_BASE1|FL_BASE_BARS,
2437 .num_ports = 4,
2438 .base_baud = 115200,
2439 .uart_offset = 8,
2440 },
2441
2442 [pbn_b1_bt_2_921600] = {
2443 .flags = FL_BASE1|FL_BASE_BARS,
2444 .num_ports = 2,
2445 .base_baud = 921600,
2446 .uart_offset = 8,
2447 },
2448
2449 [pbn_b1_1_1382400] = {
2450 .flags = FL_BASE1,
2451 .num_ports = 1,
2452 .base_baud = 1382400,
2453 .uart_offset = 8,
2454 },
2455 [pbn_b1_2_1382400] = {
2456 .flags = FL_BASE1,
2457 .num_ports = 2,
2458 .base_baud = 1382400,
2459 .uart_offset = 8,
2460 },
2461 [pbn_b1_4_1382400] = {
2462 .flags = FL_BASE1,
2463 .num_ports = 4,
2464 .base_baud = 1382400,
2465 .uart_offset = 8,
2466 },
2467 [pbn_b1_8_1382400] = {
2468 .flags = FL_BASE1,
2469 .num_ports = 8,
2470 .base_baud = 1382400,
2471 .uart_offset = 8,
2472 },
2473
2474 [pbn_b2_1_115200] = {
2475 .flags = FL_BASE2,
2476 .num_ports = 1,
2477 .base_baud = 115200,
2478 .uart_offset = 8,
2479 },
2480 [pbn_b2_2_115200] = {
2481 .flags = FL_BASE2,
2482 .num_ports = 2,
2483 .base_baud = 115200,
2484 .uart_offset = 8,
2485 },
2486 [pbn_b2_4_115200] = {
2487 .flags = FL_BASE2,
2488 .num_ports = 4,
2489 .base_baud = 115200,
2490 .uart_offset = 8,
2491 },
2492 [pbn_b2_8_115200] = {
2493 .flags = FL_BASE2,
2494 .num_ports = 8,
2495 .base_baud = 115200,
2496 .uart_offset = 8,
2497 },
2498
2499 [pbn_b2_1_460800] = {
2500 .flags = FL_BASE2,
2501 .num_ports = 1,
2502 .base_baud = 460800,
2503 .uart_offset = 8,
2504 },
2505 [pbn_b2_4_460800] = {
2506 .flags = FL_BASE2,
2507 .num_ports = 4,
2508 .base_baud = 460800,
2509 .uart_offset = 8,
2510 },
2511 [pbn_b2_8_460800] = {
2512 .flags = FL_BASE2,
2513 .num_ports = 8,
2514 .base_baud = 460800,
2515 .uart_offset = 8,
2516 },
2517 [pbn_b2_16_460800] = {
2518 .flags = FL_BASE2,
2519 .num_ports = 16,
2520 .base_baud = 460800,
2521 .uart_offset = 8,
2522 },
2523
2524 [pbn_b2_1_921600] = {
2525 .flags = FL_BASE2,
2526 .num_ports = 1,
2527 .base_baud = 921600,
2528 .uart_offset = 8,
2529 },
2530 [pbn_b2_4_921600] = {
2531 .flags = FL_BASE2,
2532 .num_ports = 4,
2533 .base_baud = 921600,
2534 .uart_offset = 8,
2535 },
2536 [pbn_b2_8_921600] = {
2537 .flags = FL_BASE2,
2538 .num_ports = 8,
2539 .base_baud = 921600,
2540 .uart_offset = 8,
2541 },
2542
2543 [pbn_b2_8_1152000] = {
2544 .flags = FL_BASE2,
2545 .num_ports = 8,
2546 .base_baud = 1152000,
2547 .uart_offset = 8,
2548 },
2549
2550 [pbn_b2_bt_1_115200] = {
2551 .flags = FL_BASE2|FL_BASE_BARS,
2552 .num_ports = 1,
2553 .base_baud = 115200,
2554 .uart_offset = 8,
2555 },
2556 [pbn_b2_bt_2_115200] = {
2557 .flags = FL_BASE2|FL_BASE_BARS,
2558 .num_ports = 2,
2559 .base_baud = 115200,
2560 .uart_offset = 8,
2561 },
2562 [pbn_b2_bt_4_115200] = {
2563 .flags = FL_BASE2|FL_BASE_BARS,
2564 .num_ports = 4,
2565 .base_baud = 115200,
2566 .uart_offset = 8,
2567 },
2568
2569 [pbn_b2_bt_2_921600] = {
2570 .flags = FL_BASE2|FL_BASE_BARS,
2571 .num_ports = 2,
2572 .base_baud = 921600,
2573 .uart_offset = 8,
2574 },
2575 [pbn_b2_bt_4_921600] = {
2576 .flags = FL_BASE2|FL_BASE_BARS,
2577 .num_ports = 4,
2578 .base_baud = 921600,
2579 .uart_offset = 8,
2580 },
2581
2582 [pbn_b3_2_115200] = {
2583 .flags = FL_BASE3,
2584 .num_ports = 2,
2585 .base_baud = 115200,
2586 .uart_offset = 8,
2587 },
2588 [pbn_b3_4_115200] = {
2589 .flags = FL_BASE3,
2590 .num_ports = 4,
2591 .base_baud = 115200,
2592 .uart_offset = 8,
2593 },
2594 [pbn_b3_8_115200] = {
2595 .flags = FL_BASE3,
2596 .num_ports = 8,
2597 .base_baud = 115200,
2598 .uart_offset = 8,
2599 },
2600
2601 [pbn_b4_bt_2_921600] = {
2602 .flags = FL_BASE4,
2603 .num_ports = 2,
2604 .base_baud = 921600,
2605 .uart_offset = 8,
2606 },
2607 [pbn_b4_bt_4_921600] = {
2608 .flags = FL_BASE4,
2609 .num_ports = 4,
2610 .base_baud = 921600,
2611 .uart_offset = 8,
2612 },
2613 [pbn_b4_bt_8_921600] = {
2614 .flags = FL_BASE4,
2615 .num_ports = 8,
2616 .base_baud = 921600,
2617 .uart_offset = 8,
2618 },
2619
2620 /*
2621 * Entries following this are board-specific.
2622 */
2623
2624 /*
2625 * Panacom - IOMEM
2626 */
2627 [pbn_panacom] = {
2628 .flags = FL_BASE2,
2629 .num_ports = 2,
2630 .base_baud = 921600,
2631 .uart_offset = 0x400,
2632 .reg_shift = 7,
2633 },
2634 [pbn_panacom2] = {
2635 .flags = FL_BASE2|FL_BASE_BARS,
2636 .num_ports = 2,
2637 .base_baud = 921600,
2638 .uart_offset = 0x400,
2639 .reg_shift = 7,
2640 },
2641 [pbn_panacom4] = {
2642 .flags = FL_BASE2|FL_BASE_BARS,
2643 .num_ports = 4,
2644 .base_baud = 921600,
2645 .uart_offset = 0x400,
2646 .reg_shift = 7,
2647 },
2648
2649 /* I think this entry is broken - the first_offset looks wrong --rmk */
2650 [pbn_plx_romulus] = {
2651 .flags = FL_BASE2,
2652 .num_ports = 4,
2653 .base_baud = 921600,
2654 .uart_offset = 8 << 2,
2655 .reg_shift = 2,
2656 .first_offset = 0x03,
2657 },
2658
2659 /*
2660 * This board uses the size of PCI Base region 0 to
2661 * signal now many ports are available
2662 */
2663 [pbn_oxsemi] = {
2664 .flags = FL_BASE0|FL_REGION_SZ_CAP,
2665 .num_ports = 32,
2666 .base_baud = 115200,
2667 .uart_offset = 8,
2668 },
2669 [pbn_oxsemi_1_4000000] = {
2670 .flags = FL_BASE0,
2671 .num_ports = 1,
2672 .base_baud = 4000000,
2673 .uart_offset = 0x200,
2674 .first_offset = 0x1000,
2675 },
2676 [pbn_oxsemi_2_4000000] = {
2677 .flags = FL_BASE0,
2678 .num_ports = 2,
2679 .base_baud = 4000000,
2680 .uart_offset = 0x200,
2681 .first_offset = 0x1000,
2682 },
2683 [pbn_oxsemi_4_4000000] = {
2684 .flags = FL_BASE0,
2685 .num_ports = 4,
2686 .base_baud = 4000000,
2687 .uart_offset = 0x200,
2688 .first_offset = 0x1000,
2689 },
2690 [pbn_oxsemi_8_4000000] = {
2691 .flags = FL_BASE0,
2692 .num_ports = 8,
2693 .base_baud = 4000000,
2694 .uart_offset = 0x200,
2695 .first_offset = 0x1000,
2696 },
2697
2698
2699 /*
2700 * EKF addition for i960 Boards form EKF with serial port.
2701 * Max 256 ports.
2702 */
2703 [pbn_intel_i960] = {
2704 .flags = FL_BASE0,
2705 .num_ports = 32,
2706 .base_baud = 921600,
2707 .uart_offset = 8 << 2,
2708 .reg_shift = 2,
2709 .first_offset = 0x10000,
2710 },
2711 [pbn_sgi_ioc3] = {
2712 .flags = FL_BASE0|FL_NOIRQ,
2713 .num_ports = 1,
2714 .base_baud = 458333,
2715 .uart_offset = 8,
2716 .reg_shift = 0,
2717 .first_offset = 0x20178,
2718 },
2719
2720 /*
2721 * Computone - uses IOMEM.
2722 */
2723 [pbn_computone_4] = {
2724 .flags = FL_BASE0,
2725 .num_ports = 4,
2726 .base_baud = 921600,
2727 .uart_offset = 0x40,
2728 .reg_shift = 2,
2729 .first_offset = 0x200,
2730 },
2731 [pbn_computone_6] = {
2732 .flags = FL_BASE0,
2733 .num_ports = 6,
2734 .base_baud = 921600,
2735 .uart_offset = 0x40,
2736 .reg_shift = 2,
2737 .first_offset = 0x200,
2738 },
2739 [pbn_computone_8] = {
2740 .flags = FL_BASE0,
2741 .num_ports = 8,
2742 .base_baud = 921600,
2743 .uart_offset = 0x40,
2744 .reg_shift = 2,
2745 .first_offset = 0x200,
2746 },
2747 [pbn_sbsxrsio] = {
2748 .flags = FL_BASE0,
2749 .num_ports = 8,
2750 .base_baud = 460800,
2751 .uart_offset = 256,
2752 .reg_shift = 4,
2753 },
2754 /*
2755 * Exar Corp. XR17C15[248] Dual/Quad/Octal UART
2756 * Only basic 16550A support.
2757 * XR17C15[24] are not tested, but they should work.
2758 */
2759 [pbn_exar_XR17C152] = {
2760 .flags = FL_BASE0,
2761 .num_ports = 2,
2762 .base_baud = 921600,
2763 .uart_offset = 0x200,
2764 },
2765 [pbn_exar_XR17C154] = {
2766 .flags = FL_BASE0,
2767 .num_ports = 4,
2768 .base_baud = 921600,
2769 .uart_offset = 0x200,
2770 },
2771 [pbn_exar_XR17C158] = {
2772 .flags = FL_BASE0,
2773 .num_ports = 8,
2774 .base_baud = 921600,
2775 .uart_offset = 0x200,
2776 },
2777 [pbn_exar_XR17V352] = {
2778 .flags = FL_BASE0,
2779 .num_ports = 2,
2780 .base_baud = 7812500,
2781 .uart_offset = 0x400,
2782 .reg_shift = 0,
2783 .first_offset = 0,
2784 },
2785 [pbn_exar_XR17V354] = {
2786 .flags = FL_BASE0,
2787 .num_ports = 4,
2788 .base_baud = 7812500,
2789 .uart_offset = 0x400,
2790 .reg_shift = 0,
2791 .first_offset = 0,
2792 },
2793 [pbn_exar_XR17V358] = {
2794 .flags = FL_BASE0,
2795 .num_ports = 8,
2796 .base_baud = 7812500,
2797 .uart_offset = 0x400,
2798 .reg_shift = 0,
2799 .first_offset = 0,
2800 },
2801 [pbn_exar_ibm_saturn] = {
2802 .flags = FL_BASE0,
2803 .num_ports = 1,
2804 .base_baud = 921600,
2805 .uart_offset = 0x200,
2806 },
2807
2808 /*
2809 * PA Semi PWRficient PA6T-1682M on-chip UART
2810 */
2811 [pbn_pasemi_1682M] = {
2812 .flags = FL_BASE0,
2813 .num_ports = 1,
2814 .base_baud = 8333333,
2815 },
2816 /*
2817 * National Instruments 843x
2818 */
2819 [pbn_ni8430_16] = {
2820 .flags = FL_BASE0,
2821 .num_ports = 16,
2822 .base_baud = 3686400,
2823 .uart_offset = 0x10,
2824 .first_offset = 0x800,
2825 },
2826 [pbn_ni8430_8] = {
2827 .flags = FL_BASE0,
2828 .num_ports = 8,
2829 .base_baud = 3686400,
2830 .uart_offset = 0x10,
2831 .first_offset = 0x800,
2832 },
2833 [pbn_ni8430_4] = {
2834 .flags = FL_BASE0,
2835 .num_ports = 4,
2836 .base_baud = 3686400,
2837 .uart_offset = 0x10,
2838 .first_offset = 0x800,
2839 },
2840 [pbn_ni8430_2] = {
2841 .flags = FL_BASE0,
2842 .num_ports = 2,
2843 .base_baud = 3686400,
2844 .uart_offset = 0x10,
2845 .first_offset = 0x800,
2846 },
2847 /*
2848 * ADDI-DATA GmbH PCI-Express communication cards <info@addi-data.com>
2849 */
2850 [pbn_ADDIDATA_PCIe_1_3906250] = {
2851 .flags = FL_BASE0,
2852 .num_ports = 1,
2853 .base_baud = 3906250,
2854 .uart_offset = 0x200,
2855 .first_offset = 0x1000,
2856 },
2857 [pbn_ADDIDATA_PCIe_2_3906250] = {
2858 .flags = FL_BASE0,
2859 .num_ports = 2,
2860 .base_baud = 3906250,
2861 .uart_offset = 0x200,
2862 .first_offset = 0x1000,
2863 },
2864 [pbn_ADDIDATA_PCIe_4_3906250] = {
2865 .flags = FL_BASE0,
2866 .num_ports = 4,
2867 .base_baud = 3906250,
2868 .uart_offset = 0x200,
2869 .first_offset = 0x1000,
2870 },
2871 [pbn_ADDIDATA_PCIe_8_3906250] = {
2872 .flags = FL_BASE0,
2873 .num_ports = 8,
2874 .base_baud = 3906250,
2875 .uart_offset = 0x200,
2876 .first_offset = 0x1000,
2877 },
2878 [pbn_ce4100_1_115200] = {
2879 .flags = FL_BASE_BARS,
2880 .num_ports = 2,
2881 .base_baud = 921600,
2882 .reg_shift = 2,
2883 },
2884 [pbn_omegapci] = {
2885 .flags = FL_BASE0,
2886 .num_ports = 8,
2887 .base_baud = 115200,
2888 .uart_offset = 0x200,
2889 },
2890 [pbn_NETMOS9900_2s_115200] = {
2891 .flags = FL_BASE0,
2892 .num_ports = 2,
2893 .base_baud = 115200,
2894 },
2895};
2896
2897static const struct pci_device_id blacklist[] = {
2898 /* softmodems */
2899 { PCI_VDEVICE(AL, 0x5457), }, /* ALi Corporation M5457 AC'97 Modem */
2900 { PCI_VDEVICE(MOTOROLA, 0x3052), }, /* Motorola Si3052-based modem */
2901 { PCI_DEVICE(0x1543, 0x3052), }, /* Si3052-based modem, default IDs */
2902
2903 /* multi-io cards handled by parport_serial */
2904 { PCI_DEVICE(0x4348, 0x7053), }, /* WCH CH353 2S1P */
2905};
2906
2907/*
2908 * Given a complete unknown PCI device, try to use some heuristics to
2909 * guess what the configuration might be, based on the pitiful PCI
2910 * serial specs. Returns 0 on success, 1 on failure.
2911 */
2912static int
2913serial_pci_guess_board(struct pci_dev *dev, struct pciserial_board *board)
2914{
2915 const struct pci_device_id *bldev;
2916 int num_iomem, num_port, first_port = -1, i;
2917
2918 /*
2919 * If it is not a communications device or the programming
2920 * interface is greater than 6, give up.
2921 *
2922 * (Should we try to make guesses for multiport serial devices
2923 * later?)
2924 */
2925 if ((((dev->class >> 8) != PCI_CLASS_COMMUNICATION_SERIAL) &&
2926 ((dev->class >> 8) != PCI_CLASS_COMMUNICATION_MODEM)) ||
2927 (dev->class & 0xff) > 6)
2928 return -ENODEV;
2929
2930 /*
2931 * Do not access blacklisted devices that are known not to
2932 * feature serial ports or are handled by other modules.
2933 */
2934 for (bldev = blacklist;
2935 bldev < blacklist + ARRAY_SIZE(blacklist);
2936 bldev++) {
2937 if (dev->vendor == bldev->vendor &&
2938 dev->device == bldev->device)
2939 return -ENODEV;
2940 }
2941
2942 num_iomem = num_port = 0;
2943 for (i = 0; i < PCI_NUM_BAR_RESOURCES; i++) {
2944 if (pci_resource_flags(dev, i) & IORESOURCE_IO) {
2945 num_port++;
2946 if (first_port == -1)
2947 first_port = i;
2948 }
2949 if (pci_resource_flags(dev, i) & IORESOURCE_MEM)
2950 num_iomem++;
2951 }
2952
2953 /*
2954 * If there is 1 or 0 iomem regions, and exactly one port,
2955 * use it. We guess the number of ports based on the IO
2956 * region size.
2957 */
2958 if (num_iomem <= 1 && num_port == 1) {
2959 board->flags = first_port;
2960 board->num_ports = pci_resource_len(dev, first_port) / 8;
2961 return 0;
2962 }
2963
2964 /*
2965 * Now guess if we've got a board which indexes by BARs.
2966 * Each IO BAR should be 8 bytes, and they should follow
2967 * consecutively.
2968 */
2969 first_port = -1;
2970 num_port = 0;
2971 for (i = 0; i < PCI_NUM_BAR_RESOURCES; i++) {
2972 if (pci_resource_flags(dev, i) & IORESOURCE_IO &&
2973 pci_resource_len(dev, i) == 8 &&
2974 (first_port == -1 || (first_port + num_port) == i)) {
2975 num_port++;
2976 if (first_port == -1)
2977 first_port = i;
2978 }
2979 }
2980
2981 if (num_port > 1) {
2982 board->flags = first_port | FL_BASE_BARS;
2983 board->num_ports = num_port;
2984 return 0;
2985 }
2986
2987 return -ENODEV;
2988}
2989
2990static inline int
2991serial_pci_matches(const struct pciserial_board *board,
2992 const struct pciserial_board *guessed)
2993{
2994 return
2995 board->num_ports == guessed->num_ports &&
2996 board->base_baud == guessed->base_baud &&
2997 board->uart_offset == guessed->uart_offset &&
2998 board->reg_shift == guessed->reg_shift &&
2999 board->first_offset == guessed->first_offset;
3000}
3001
3002struct serial_private *
3003pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board)
3004{
3005 struct uart_8250_port uart;
3006 struct serial_private *priv;
3007 struct pci_serial_quirk *quirk;
3008 int rc, nr_ports, i;
3009
3010 nr_ports = board->num_ports;
3011
3012 /*
3013 * Find an init and setup quirks.
3014 */
3015 quirk = find_quirk(dev);
3016
3017 /*
3018 * Run the new-style initialization function.
3019 * The initialization function returns:
3020 * <0 - error
3021 * 0 - use board->num_ports
3022 * >0 - number of ports
3023 */
3024 if (quirk->init) {
3025 rc = quirk->init(dev);
3026 if (rc < 0) {
3027 priv = ERR_PTR(rc);
3028 goto err_out;
3029 }
3030 if (rc)
3031 nr_ports = rc;
3032 }
3033
3034 priv = kzalloc(sizeof(struct serial_private) +
3035 sizeof(unsigned int) * nr_ports,
3036 GFP_KERNEL);
3037 if (!priv) {
3038 priv = ERR_PTR(-ENOMEM);
3039 goto err_deinit;
3040 }
3041
3042 priv->dev = dev;
3043 priv->quirk = quirk;
3044
3045 memset(&uart, 0, sizeof(uart));
3046 uart.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
3047 uart.port.uartclk = board->base_baud * 16;
3048 uart.port.irq = get_pci_irq(dev, board);
3049 uart.port.dev = &dev->dev;
3050
3051 for (i = 0; i < nr_ports; i++) {
3052 if (quirk->setup(priv, board, &uart, i))
3053 break;
3054
3055#ifdef SERIAL_DEBUG_PCI
3056 printk(KERN_DEBUG "Setup PCI port: port %lx, irq %d, type %d\n",
3057 uart.port.iobase, uart.port.irq, uart.port.iotype);
3058#endif
3059
3060 priv->line[i] = serial8250_register_8250_port(&uart);
3061 if (priv->line[i] < 0) {
3062 printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), priv->line[i]);
3063 break;
3064 }
3065 }
3066 priv->nr = i;
3067 return priv;
3068
3069err_deinit:
3070 if (quirk->exit)
3071 quirk->exit(dev);
3072err_out:
3073 return priv;
3074}
3075EXPORT_SYMBOL_GPL(pciserial_init_ports);
3076
3077void pciserial_remove_ports(struct serial_private *priv)
3078{
3079 struct pci_serial_quirk *quirk;
3080 int i;
3081
3082 for (i = 0; i < priv->nr; i++)
3083 serial8250_unregister_port(priv->line[i]);
3084
3085 for (i = 0; i < PCI_NUM_BAR_RESOURCES; i++) {
3086 if (priv->remapped_bar[i])
3087 iounmap(priv->remapped_bar[i]);
3088 priv->remapped_bar[i] = NULL;
3089 }
3090
3091 /*
3092 * Find the exit quirks.
3093 */
3094 quirk = find_quirk(priv->dev);
3095 if (quirk->exit)
3096 quirk->exit(priv->dev);
3097
3098 kfree(priv);
3099}
3100EXPORT_SYMBOL_GPL(pciserial_remove_ports);
3101
3102void pciserial_suspend_ports(struct serial_private *priv)
3103{
3104 int i;
3105
3106 for (i = 0; i < priv->nr; i++)
3107 if (priv->line[i] >= 0)
3108 serial8250_suspend_port(priv->line[i]);
3109
3110 /*
3111 * Ensure that every init quirk is properly torn down
3112 */
3113 if (priv->quirk->exit)
3114 priv->quirk->exit(priv->dev);
3115}
3116EXPORT_SYMBOL_GPL(pciserial_suspend_ports);
3117
3118void pciserial_resume_ports(struct serial_private *priv)
3119{
3120 int i;
3121
3122 /*
3123 * Ensure that the board is correctly configured.
3124 */
3125 if (priv->quirk->init)
3126 priv->quirk->init(priv->dev);
3127
3128 for (i = 0; i < priv->nr; i++)
3129 if (priv->line[i] >= 0)
3130 serial8250_resume_port(priv->line[i]);
3131}
3132EXPORT_SYMBOL_GPL(pciserial_resume_ports);
3133
3134/*
3135 * Probe one serial board. Unfortunately, there is no rhyme nor reason
3136 * to the arrangement of serial ports on a PCI card.
3137 */
3138static int
3139pciserial_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
3140{
3141 struct pci_serial_quirk *quirk;
3142 struct serial_private *priv;
3143 const struct pciserial_board *board;
3144 struct pciserial_board tmp;
3145 int rc;
3146
3147 quirk = find_quirk(dev);
3148 if (quirk->probe) {
3149 rc = quirk->probe(dev);
3150 if (rc)
3151 return rc;
3152 }
3153
3154 if (ent->driver_data >= ARRAY_SIZE(pci_boards)) {
3155 printk(KERN_ERR "pci_init_one: invalid driver_data: %ld\n",
3156 ent->driver_data);
3157 return -EINVAL;
3158 }
3159
3160 board = &pci_boards[ent->driver_data];
3161
3162 rc = pci_enable_device(dev);
3163 pci_save_state(dev);
3164 if (rc)
3165 return rc;
3166
3167 if (ent->driver_data == pbn_default) {
3168 /*
3169 * Use a copy of the pci_board entry for this;
3170 * avoid changing entries in the table.
3171 */
3172 memcpy(&tmp, board, sizeof(struct pciserial_board));
3173 board = &tmp;
3174
3175 /*
3176 * We matched one of our class entries. Try to
3177 * determine the parameters of this board.
3178 */
3179 rc = serial_pci_guess_board(dev, &tmp);
3180 if (rc)
3181 goto disable;
3182 } else {
3183 /*
3184 * We matched an explicit entry. If we are able to
3185 * detect this boards settings with our heuristic,
3186 * then we no longer need this entry.
3187 */
3188 memcpy(&tmp, &pci_boards[pbn_default],
3189 sizeof(struct pciserial_board));
3190 rc = serial_pci_guess_board(dev, &tmp);
3191 if (rc == 0 && serial_pci_matches(board, &tmp))
3192 moan_device("Redundant entry in serial pci_table.",
3193 dev);
3194 }
3195
3196 priv = pciserial_init_ports(dev, board);
3197 if (!IS_ERR(priv)) {
3198 pci_set_drvdata(dev, priv);
3199 return 0;
3200 }
3201
3202 rc = PTR_ERR(priv);
3203
3204 disable:
3205 pci_disable_device(dev);
3206 return rc;
3207}
3208
3209static void pciserial_remove_one(struct pci_dev *dev)
3210{
3211 struct serial_private *priv = pci_get_drvdata(dev);
3212
3213 pci_set_drvdata(dev, NULL);
3214
3215 pciserial_remove_ports(priv);
3216
3217 pci_disable_device(dev);
3218}
3219
3220#ifdef CONFIG_PM
3221static int pciserial_suspend_one(struct pci_dev *dev, pm_message_t state)
3222{
3223 struct serial_private *priv = pci_get_drvdata(dev);
3224
3225 if (priv)
3226 pciserial_suspend_ports(priv);
3227
3228 pci_save_state(dev);
3229 pci_set_power_state(dev, pci_choose_state(dev, state));
3230 return 0;
3231}
3232
3233static int pciserial_resume_one(struct pci_dev *dev)
3234{
3235 int err;
3236 struct serial_private *priv = pci_get_drvdata(dev);
3237
3238 pci_set_power_state(dev, PCI_D0);
3239 pci_restore_state(dev);
3240
3241 if (priv) {
3242 /*
3243 * The device may have been disabled. Re-enable it.
3244 */
3245 err = pci_enable_device(dev);
3246 /* FIXME: We cannot simply error out here */
3247 if (err)
3248 printk(KERN_ERR "pciserial: Unable to re-enable ports, trying to continue.\n");
3249 pciserial_resume_ports(priv);
3250 }
3251 return 0;
3252}
3253#endif
3254
3255static struct pci_device_id serial_pci_tbl[] = {
3256 /* Advantech use PCI_DEVICE_ID_ADVANTECH_PCI3620 (0x3620) as 'PCI_SUBVENDOR_ID' */
3257 { PCI_VENDOR_ID_ADVANTECH, PCI_DEVICE_ID_ADVANTECH_PCI3620,
3258 PCI_DEVICE_ID_ADVANTECH_PCI3620, 0x0001, 0, 0,
3259 pbn_b2_8_921600 },
3260 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
3261 PCI_SUBVENDOR_ID_CONNECT_TECH,
3262 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232, 0, 0,
3263 pbn_b1_8_1382400 },
3264 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
3265 PCI_SUBVENDOR_ID_CONNECT_TECH,
3266 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232, 0, 0,
3267 pbn_b1_4_1382400 },
3268 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
3269 PCI_SUBVENDOR_ID_CONNECT_TECH,
3270 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232, 0, 0,
3271 pbn_b1_2_1382400 },
3272 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3273 PCI_SUBVENDOR_ID_CONNECT_TECH,
3274 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232, 0, 0,
3275 pbn_b1_8_1382400 },
3276 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3277 PCI_SUBVENDOR_ID_CONNECT_TECH,
3278 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232, 0, 0,
3279 pbn_b1_4_1382400 },
3280 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3281 PCI_SUBVENDOR_ID_CONNECT_TECH,
3282 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232, 0, 0,
3283 pbn_b1_2_1382400 },
3284 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3285 PCI_SUBVENDOR_ID_CONNECT_TECH,
3286 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485, 0, 0,
3287 pbn_b1_8_921600 },
3288 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3289 PCI_SUBVENDOR_ID_CONNECT_TECH,
3290 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_4_4, 0, 0,
3291 pbn_b1_8_921600 },
3292 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3293 PCI_SUBVENDOR_ID_CONNECT_TECH,
3294 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485, 0, 0,
3295 pbn_b1_4_921600 },
3296 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3297 PCI_SUBVENDOR_ID_CONNECT_TECH,
3298 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485_2_2, 0, 0,
3299 pbn_b1_4_921600 },
3300 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3301 PCI_SUBVENDOR_ID_CONNECT_TECH,
3302 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_485, 0, 0,
3303 pbn_b1_2_921600 },
3304 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3305 PCI_SUBVENDOR_ID_CONNECT_TECH,
3306 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_2_6, 0, 0,
3307 pbn_b1_8_921600 },
3308 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3309 PCI_SUBVENDOR_ID_CONNECT_TECH,
3310 PCI_SUBDEVICE_ID_CONNECT_TECH_BH081101V1, 0, 0,
3311 pbn_b1_8_921600 },
3312 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3313 PCI_SUBVENDOR_ID_CONNECT_TECH,
3314 PCI_SUBDEVICE_ID_CONNECT_TECH_BH041101V1, 0, 0,
3315 pbn_b1_4_921600 },
3316 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V351,
3317 PCI_SUBVENDOR_ID_CONNECT_TECH,
3318 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_20MHZ, 0, 0,
3319 pbn_b1_2_1250000 },
3320 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
3321 PCI_SUBVENDOR_ID_CONNECT_TECH,
3322 PCI_SUBDEVICE_ID_CONNECT_TECH_TITAN_2, 0, 0,
3323 pbn_b0_2_1843200 },
3324 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
3325 PCI_SUBVENDOR_ID_CONNECT_TECH,
3326 PCI_SUBDEVICE_ID_CONNECT_TECH_TITAN_4, 0, 0,
3327 pbn_b0_4_1843200 },
3328 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
3329 PCI_VENDOR_ID_AFAVLAB,
3330 PCI_SUBDEVICE_ID_AFAVLAB_P061, 0, 0,
3331 pbn_b0_4_1152000 },
3332 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C152,
3333 PCI_SUBVENDOR_ID_CONNECT_TECH,
3334 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_232, 0, 0,
3335 pbn_b0_2_1843200_200 },
3336 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C154,
3337 PCI_SUBVENDOR_ID_CONNECT_TECH,
3338 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_232, 0, 0,
3339 pbn_b0_4_1843200_200 },
3340 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C158,
3341 PCI_SUBVENDOR_ID_CONNECT_TECH,
3342 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_232, 0, 0,
3343 pbn_b0_8_1843200_200 },
3344 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C152,
3345 PCI_SUBVENDOR_ID_CONNECT_TECH,
3346 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_1_1, 0, 0,
3347 pbn_b0_2_1843200_200 },
3348 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C154,
3349 PCI_SUBVENDOR_ID_CONNECT_TECH,
3350 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_2, 0, 0,
3351 pbn_b0_4_1843200_200 },
3352 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C158,
3353 PCI_SUBVENDOR_ID_CONNECT_TECH,
3354 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_4, 0, 0,
3355 pbn_b0_8_1843200_200 },
3356 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C152,
3357 PCI_SUBVENDOR_ID_CONNECT_TECH,
3358 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2, 0, 0,
3359 pbn_b0_2_1843200_200 },
3360 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C154,
3361 PCI_SUBVENDOR_ID_CONNECT_TECH,
3362 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4, 0, 0,
3363 pbn_b0_4_1843200_200 },
3364 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C158,
3365 PCI_SUBVENDOR_ID_CONNECT_TECH,
3366 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8, 0, 0,
3367 pbn_b0_8_1843200_200 },
3368 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C152,
3369 PCI_SUBVENDOR_ID_CONNECT_TECH,
3370 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_2_485, 0, 0,
3371 pbn_b0_2_1843200_200 },
3372 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C154,
3373 PCI_SUBVENDOR_ID_CONNECT_TECH,
3374 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_4_485, 0, 0,
3375 pbn_b0_4_1843200_200 },
3376 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C158,
3377 PCI_SUBVENDOR_ID_CONNECT_TECH,
3378 PCI_SUBDEVICE_ID_CONNECT_TECH_PCI_UART_8_485, 0, 0,
3379 pbn_b0_8_1843200_200 },
3380 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C152,
3381 PCI_VENDOR_ID_IBM, PCI_SUBDEVICE_ID_IBM_SATURN_SERIAL_ONE_PORT,
3382 0, 0, pbn_exar_ibm_saturn },
3383
3384 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_U530,
3385 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3386 pbn_b2_bt_1_115200 },
3387 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM2,
3388 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3389 pbn_b2_bt_2_115200 },
3390 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM422,
3391 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3392 pbn_b2_bt_4_115200 },
3393 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM232,
3394 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3395 pbn_b2_bt_2_115200 },
3396 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM4,
3397 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3398 pbn_b2_bt_4_115200 },
3399 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM8,
3400 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3401 pbn_b2_8_115200 },
3402 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_7803,
3403 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3404 pbn_b2_8_460800 },
3405 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM8,
3406 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3407 pbn_b2_8_115200 },
3408
3409 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_GTEK_SERIAL2,
3410 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3411 pbn_b2_bt_2_115200 },
3412 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_SPCOM200,
3413 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3414 pbn_b2_bt_2_921600 },
3415 /*
3416 * VScom SPCOM800, from sl@s.pl
3417 */
3418 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_SPCOM800,
3419 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3420 pbn_b2_8_921600 },
3421 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_1077,
3422 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3423 pbn_b2_4_921600 },
3424 /* Unknown card - subdevice 0x1584 */
3425 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3426 PCI_VENDOR_ID_PLX,
3427 PCI_SUBDEVICE_ID_UNKNOWN_0x1584, 0, 0,
3428 pbn_b0_4_115200 },
3429 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3430 PCI_SUBVENDOR_ID_KEYSPAN,
3431 PCI_SUBDEVICE_ID_KEYSPAN_SX2, 0, 0,
3432 pbn_panacom },
3433 { PCI_VENDOR_ID_PANACOM, PCI_DEVICE_ID_PANACOM_QUADMODEM,
3434 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3435 pbn_panacom4 },
3436 { PCI_VENDOR_ID_PANACOM, PCI_DEVICE_ID_PANACOM_DUALMODEM,
3437 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3438 pbn_panacom2 },
3439 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
3440 PCI_VENDOR_ID_ESDGMBH,
3441 PCI_DEVICE_ID_ESDGMBH_CPCIASIO4, 0, 0,
3442 pbn_b2_4_115200 },
3443 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3444 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
3445 PCI_SUBDEVICE_ID_CHASE_PCIFAST4, 0, 0,
3446 pbn_b2_4_460800 },
3447 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3448 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
3449 PCI_SUBDEVICE_ID_CHASE_PCIFAST8, 0, 0,
3450 pbn_b2_8_460800 },
3451 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3452 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
3453 PCI_SUBDEVICE_ID_CHASE_PCIFAST16, 0, 0,
3454 pbn_b2_16_460800 },
3455 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3456 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
3457 PCI_SUBDEVICE_ID_CHASE_PCIFAST16FMC, 0, 0,
3458 pbn_b2_16_460800 },
3459 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3460 PCI_SUBVENDOR_ID_CHASE_PCIRAS,
3461 PCI_SUBDEVICE_ID_CHASE_PCIRAS4, 0, 0,
3462 pbn_b2_4_460800 },
3463 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3464 PCI_SUBVENDOR_ID_CHASE_PCIRAS,
3465 PCI_SUBDEVICE_ID_CHASE_PCIRAS8, 0, 0,
3466 pbn_b2_8_460800 },
3467 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3468 PCI_SUBVENDOR_ID_EXSYS,
3469 PCI_SUBDEVICE_ID_EXSYS_4055, 0, 0,
3470 pbn_b2_4_115200 },
3471 /*
3472 * Megawolf Romulus PCI Serial Card, from Mike Hudson
3473 * (Exoray@isys.ca)
3474 */
3475 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_ROMULUS,
3476 0x10b5, 0x106a, 0, 0,
3477 pbn_plx_romulus },
3478 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_QSC100,
3479 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3480 pbn_b1_4_115200 },
3481 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_DSC100,
3482 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3483 pbn_b1_2_115200 },
3484 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_ESC100D,
3485 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3486 pbn_b1_8_115200 },
3487 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_ESC100M,
3488 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3489 pbn_b1_8_115200 },
3490 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_OXSEMI_16PCI954,
3491 PCI_VENDOR_ID_SPECIALIX, PCI_SUBDEVICE_ID_SPECIALIX_SPEED4,
3492 0, 0,
3493 pbn_b0_4_921600 },
3494 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
3495 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL,
3496 0, 0,
3497 pbn_b0_4_1152000 },
3498 { PCI_VENDOR_ID_OXSEMI, 0x9505,
3499 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3500 pbn_b0_bt_2_921600 },
3501
3502 /*
3503 * The below card is a little controversial since it is the
3504 * subject of a PCI vendor/device ID clash. (See
3505 * www.ussg.iu.edu/hypermail/linux/kernel/0303.1/0516.html).
3506 * For now just used the hex ID 0x950a.
3507 */
3508 { PCI_VENDOR_ID_OXSEMI, 0x950a,
3509 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_DUAL_00,
3510 0, 0, pbn_b0_2_115200 },
3511 { PCI_VENDOR_ID_OXSEMI, 0x950a,
3512 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_DUAL_30,
3513 0, 0, pbn_b0_2_115200 },
3514 { PCI_VENDOR_ID_OXSEMI, 0x950a,
3515 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3516 pbn_b0_2_1130000 },
3517 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_C950,
3518 PCI_VENDOR_ID_OXSEMI, PCI_SUBDEVICE_ID_OXSEMI_C950, 0, 0,
3519 pbn_b0_1_921600 },
3520 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
3521 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3522 pbn_b0_4_115200 },
3523 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952,
3524 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3525 pbn_b0_bt_2_921600 },
3526 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI958,
3527 PCI_ANY_ID , PCI_ANY_ID, 0, 0,
3528 pbn_b2_8_1152000 },
3529
3530 /*
3531 * Oxford Semiconductor Inc. Tornado PCI express device range.
3532 */
3533 { PCI_VENDOR_ID_OXSEMI, 0xc101, /* OXPCIe952 1 Legacy UART */
3534 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3535 pbn_b0_1_4000000 },
3536 { PCI_VENDOR_ID_OXSEMI, 0xc105, /* OXPCIe952 1 Legacy UART */
3537 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3538 pbn_b0_1_4000000 },
3539 { PCI_VENDOR_ID_OXSEMI, 0xc11b, /* OXPCIe952 1 Native UART */
3540 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3541 pbn_oxsemi_1_4000000 },
3542 { PCI_VENDOR_ID_OXSEMI, 0xc11f, /* OXPCIe952 1 Native UART */
3543 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3544 pbn_oxsemi_1_4000000 },
3545 { PCI_VENDOR_ID_OXSEMI, 0xc120, /* OXPCIe952 1 Legacy UART */
3546 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3547 pbn_b0_1_4000000 },
3548 { PCI_VENDOR_ID_OXSEMI, 0xc124, /* OXPCIe952 1 Legacy UART */
3549 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3550 pbn_b0_1_4000000 },
3551 { PCI_VENDOR_ID_OXSEMI, 0xc138, /* OXPCIe952 1 Native UART */
3552 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3553 pbn_oxsemi_1_4000000 },
3554 { PCI_VENDOR_ID_OXSEMI, 0xc13d, /* OXPCIe952 1 Native UART */
3555 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3556 pbn_oxsemi_1_4000000 },
3557 { PCI_VENDOR_ID_OXSEMI, 0xc140, /* OXPCIe952 1 Legacy UART */
3558 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3559 pbn_b0_1_4000000 },
3560 { PCI_VENDOR_ID_OXSEMI, 0xc141, /* OXPCIe952 1 Legacy UART */
3561 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3562 pbn_b0_1_4000000 },
3563 { PCI_VENDOR_ID_OXSEMI, 0xc144, /* OXPCIe952 1 Legacy UART */
3564 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3565 pbn_b0_1_4000000 },
3566 { PCI_VENDOR_ID_OXSEMI, 0xc145, /* OXPCIe952 1 Legacy UART */
3567 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3568 pbn_b0_1_4000000 },
3569 { PCI_VENDOR_ID_OXSEMI, 0xc158, /* OXPCIe952 2 Native UART */
3570 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3571 pbn_oxsemi_2_4000000 },
3572 { PCI_VENDOR_ID_OXSEMI, 0xc15d, /* OXPCIe952 2 Native UART */
3573 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3574 pbn_oxsemi_2_4000000 },
3575 { PCI_VENDOR_ID_OXSEMI, 0xc208, /* OXPCIe954 4 Native UART */
3576 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3577 pbn_oxsemi_4_4000000 },
3578 { PCI_VENDOR_ID_OXSEMI, 0xc20d, /* OXPCIe954 4 Native UART */
3579 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3580 pbn_oxsemi_4_4000000 },
3581 { PCI_VENDOR_ID_OXSEMI, 0xc308, /* OXPCIe958 8 Native UART */
3582 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3583 pbn_oxsemi_8_4000000 },
3584 { PCI_VENDOR_ID_OXSEMI, 0xc30d, /* OXPCIe958 8 Native UART */
3585 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3586 pbn_oxsemi_8_4000000 },
3587 { PCI_VENDOR_ID_OXSEMI, 0xc40b, /* OXPCIe200 1 Native UART */
3588 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3589 pbn_oxsemi_1_4000000 },
3590 { PCI_VENDOR_ID_OXSEMI, 0xc40f, /* OXPCIe200 1 Native UART */
3591 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3592 pbn_oxsemi_1_4000000 },
3593 { PCI_VENDOR_ID_OXSEMI, 0xc41b, /* OXPCIe200 1 Native UART */
3594 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3595 pbn_oxsemi_1_4000000 },
3596 { PCI_VENDOR_ID_OXSEMI, 0xc41f, /* OXPCIe200 1 Native UART */
3597 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3598 pbn_oxsemi_1_4000000 },
3599 { PCI_VENDOR_ID_OXSEMI, 0xc42b, /* OXPCIe200 1 Native UART */
3600 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3601 pbn_oxsemi_1_4000000 },
3602 { PCI_VENDOR_ID_OXSEMI, 0xc42f, /* OXPCIe200 1 Native UART */
3603 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3604 pbn_oxsemi_1_4000000 },
3605 { PCI_VENDOR_ID_OXSEMI, 0xc43b, /* OXPCIe200 1 Native UART */
3606 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3607 pbn_oxsemi_1_4000000 },
3608 { PCI_VENDOR_ID_OXSEMI, 0xc43f, /* OXPCIe200 1 Native UART */
3609 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3610 pbn_oxsemi_1_4000000 },
3611 { PCI_VENDOR_ID_OXSEMI, 0xc44b, /* OXPCIe200 1 Native UART */
3612 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3613 pbn_oxsemi_1_4000000 },
3614 { PCI_VENDOR_ID_OXSEMI, 0xc44f, /* OXPCIe200 1 Native UART */
3615 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3616 pbn_oxsemi_1_4000000 },
3617 { PCI_VENDOR_ID_OXSEMI, 0xc45b, /* OXPCIe200 1 Native UART */
3618 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3619 pbn_oxsemi_1_4000000 },
3620 { PCI_VENDOR_ID_OXSEMI, 0xc45f, /* OXPCIe200 1 Native UART */
3621 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3622 pbn_oxsemi_1_4000000 },
3623 { PCI_VENDOR_ID_OXSEMI, 0xc46b, /* OXPCIe200 1 Native UART */
3624 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3625 pbn_oxsemi_1_4000000 },
3626 { PCI_VENDOR_ID_OXSEMI, 0xc46f, /* OXPCIe200 1 Native UART */
3627 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3628 pbn_oxsemi_1_4000000 },
3629 { PCI_VENDOR_ID_OXSEMI, 0xc47b, /* OXPCIe200 1 Native UART */
3630 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3631 pbn_oxsemi_1_4000000 },
3632 { PCI_VENDOR_ID_OXSEMI, 0xc47f, /* OXPCIe200 1 Native UART */
3633 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3634 pbn_oxsemi_1_4000000 },
3635 { PCI_VENDOR_ID_OXSEMI, 0xc48b, /* OXPCIe200 1 Native UART */
3636 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3637 pbn_oxsemi_1_4000000 },
3638 { PCI_VENDOR_ID_OXSEMI, 0xc48f, /* OXPCIe200 1 Native UART */
3639 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3640 pbn_oxsemi_1_4000000 },
3641 { PCI_VENDOR_ID_OXSEMI, 0xc49b, /* OXPCIe200 1 Native UART */
3642 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3643 pbn_oxsemi_1_4000000 },
3644 { PCI_VENDOR_ID_OXSEMI, 0xc49f, /* OXPCIe200 1 Native UART */
3645 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3646 pbn_oxsemi_1_4000000 },
3647 { PCI_VENDOR_ID_OXSEMI, 0xc4ab, /* OXPCIe200 1 Native UART */
3648 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3649 pbn_oxsemi_1_4000000 },
3650 { PCI_VENDOR_ID_OXSEMI, 0xc4af, /* OXPCIe200 1 Native UART */
3651 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3652 pbn_oxsemi_1_4000000 },
3653 { PCI_VENDOR_ID_OXSEMI, 0xc4bb, /* OXPCIe200 1 Native UART */
3654 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3655 pbn_oxsemi_1_4000000 },
3656 { PCI_VENDOR_ID_OXSEMI, 0xc4bf, /* OXPCIe200 1 Native UART */
3657 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3658 pbn_oxsemi_1_4000000 },
3659 { PCI_VENDOR_ID_OXSEMI, 0xc4cb, /* OXPCIe200 1 Native UART */
3660 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3661 pbn_oxsemi_1_4000000 },
3662 { PCI_VENDOR_ID_OXSEMI, 0xc4cf, /* OXPCIe200 1 Native UART */
3663 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3664 pbn_oxsemi_1_4000000 },
3665 /*
3666 * Mainpine Inc. IQ Express "Rev3" utilizing OxSemi Tornado
3667 */
3668 { PCI_VENDOR_ID_MAINPINE, 0x4000, /* IQ Express 1 Port V.34 Super-G3 Fax */
3669 PCI_VENDOR_ID_MAINPINE, 0x4001, 0, 0,
3670 pbn_oxsemi_1_4000000 },
3671 { PCI_VENDOR_ID_MAINPINE, 0x4000, /* IQ Express 2 Port V.34 Super-G3 Fax */
3672 PCI_VENDOR_ID_MAINPINE, 0x4002, 0, 0,
3673 pbn_oxsemi_2_4000000 },
3674 { PCI_VENDOR_ID_MAINPINE, 0x4000, /* IQ Express 4 Port V.34 Super-G3 Fax */
3675 PCI_VENDOR_ID_MAINPINE, 0x4004, 0, 0,
3676 pbn_oxsemi_4_4000000 },
3677 { PCI_VENDOR_ID_MAINPINE, 0x4000, /* IQ Express 8 Port V.34 Super-G3 Fax */
3678 PCI_VENDOR_ID_MAINPINE, 0x4008, 0, 0,
3679 pbn_oxsemi_8_4000000 },
3680
3681 /*
3682 * Digi/IBM PCIe 2-port Async EIA-232 Adapter utilizing OxSemi Tornado
3683 */
3684 { PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_2_OX_IBM,
3685 PCI_SUBVENDOR_ID_IBM, PCI_ANY_ID, 0, 0,
3686 pbn_oxsemi_2_4000000 },
3687
3688 /*
3689 * SBS Technologies, Inc. P-Octal and PMC-OCTPRO cards,
3690 * from skokodyn@yahoo.com
3691 */
3692 { PCI_VENDOR_ID_SBSMODULARIO, PCI_DEVICE_ID_OCTPRO,
3693 PCI_SUBVENDOR_ID_SBSMODULARIO, PCI_SUBDEVICE_ID_OCTPRO232, 0, 0,
3694 pbn_sbsxrsio },
3695 { PCI_VENDOR_ID_SBSMODULARIO, PCI_DEVICE_ID_OCTPRO,
3696 PCI_SUBVENDOR_ID_SBSMODULARIO, PCI_SUBDEVICE_ID_OCTPRO422, 0, 0,
3697 pbn_sbsxrsio },
3698 { PCI_VENDOR_ID_SBSMODULARIO, PCI_DEVICE_ID_OCTPRO,
3699 PCI_SUBVENDOR_ID_SBSMODULARIO, PCI_SUBDEVICE_ID_POCTAL232, 0, 0,
3700 pbn_sbsxrsio },
3701 { PCI_VENDOR_ID_SBSMODULARIO, PCI_DEVICE_ID_OCTPRO,
3702 PCI_SUBVENDOR_ID_SBSMODULARIO, PCI_SUBDEVICE_ID_POCTAL422, 0, 0,
3703 pbn_sbsxrsio },
3704
3705 /*
3706 * Digitan DS560-558, from jimd@esoft.com
3707 */
3708 { PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_ATT_VENUS_MODEM,
3709 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3710 pbn_b1_1_115200 },
3711
3712 /*
3713 * Titan Electronic cards
3714 * The 400L and 800L have a custom setup quirk.
3715 */
3716 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_100,
3717 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3718 pbn_b0_1_921600 },
3719 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200,
3720 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3721 pbn_b0_2_921600 },
3722 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400,
3723 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3724 pbn_b0_4_921600 },
3725 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800B,
3726 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3727 pbn_b0_4_921600 },
3728 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_100L,
3729 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3730 pbn_b1_1_921600 },
3731 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200L,
3732 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3733 pbn_b1_bt_2_921600 },
3734 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400L,
3735 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3736 pbn_b0_bt_4_921600 },
3737 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800L,
3738 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3739 pbn_b0_bt_8_921600 },
3740 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200I,
3741 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3742 pbn_b4_bt_2_921600 },
3743 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400I,
3744 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3745 pbn_b4_bt_4_921600 },
3746 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800I,
3747 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3748 pbn_b4_bt_8_921600 },
3749 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400EH,
3750 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3751 pbn_b0_4_921600 },
3752 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800EH,
3753 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3754 pbn_b0_4_921600 },
3755 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800EHB,
3756 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3757 pbn_b0_4_921600 },
3758 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_100E,
3759 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3760 pbn_oxsemi_1_4000000 },
3761 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200E,
3762 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3763 pbn_oxsemi_2_4000000 },
3764 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400E,
3765 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3766 pbn_oxsemi_4_4000000 },
3767 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800E,
3768 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3769 pbn_oxsemi_8_4000000 },
3770 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200EI,
3771 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3772 pbn_oxsemi_2_4000000 },
3773 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200EISI,
3774 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3775 pbn_oxsemi_2_4000000 },
3776 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400V3,
3777 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3778 pbn_b0_4_921600 },
3779 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_410V3,
3780 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3781 pbn_b0_4_921600 },
3782 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800V3,
3783 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3784 pbn_b0_4_921600 },
3785 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800V3B,
3786 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3787 pbn_b0_4_921600 },
3788
3789 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_550,
3790 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3791 pbn_b2_1_460800 },
3792 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_650,
3793 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3794 pbn_b2_1_460800 },
3795 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_850,
3796 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3797 pbn_b2_1_460800 },
3798 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_550,
3799 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3800 pbn_b2_bt_2_921600 },
3801 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_650,
3802 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3803 pbn_b2_bt_2_921600 },
3804 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_850,
3805 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3806 pbn_b2_bt_2_921600 },
3807 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_550,
3808 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3809 pbn_b2_bt_4_921600 },
3810 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_650,
3811 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3812 pbn_b2_bt_4_921600 },
3813 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_850,
3814 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3815 pbn_b2_bt_4_921600 },
3816 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_550,
3817 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3818 pbn_b0_1_921600 },
3819 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_650,
3820 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3821 pbn_b0_1_921600 },
3822 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_850,
3823 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3824 pbn_b0_1_921600 },
3825 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_550,
3826 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3827 pbn_b0_bt_2_921600 },
3828 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_650,
3829 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3830 pbn_b0_bt_2_921600 },
3831 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_850,
3832 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3833 pbn_b0_bt_2_921600 },
3834 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_550,
3835 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3836 pbn_b0_bt_4_921600 },
3837 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_650,
3838 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3839 pbn_b0_bt_4_921600 },
3840 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_850,
3841 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3842 pbn_b0_bt_4_921600 },
3843 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_8S_20x_550,
3844 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3845 pbn_b0_bt_8_921600 },
3846 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_8S_20x_650,
3847 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3848 pbn_b0_bt_8_921600 },
3849 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_8S_20x_850,
3850 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3851 pbn_b0_bt_8_921600 },
3852
3853 /*
3854 * Computone devices submitted by Doug McNash dmcnash@computone.com
3855 */
3856 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
3857 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG4,
3858 0, 0, pbn_computone_4 },
3859 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
3860 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG8,
3861 0, 0, pbn_computone_8 },
3862 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
3863 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG6,
3864 0, 0, pbn_computone_6 },
3865
3866 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI95N,
3867 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3868 pbn_oxsemi },
3869 { PCI_VENDOR_ID_TIMEDIA, PCI_DEVICE_ID_TIMEDIA_1889,
3870 PCI_VENDOR_ID_TIMEDIA, PCI_ANY_ID, 0, 0,
3871 pbn_b0_bt_1_921600 },
3872
3873 /*
3874 * AFAVLAB serial card, from Harald Welte <laforge@gnumonks.org>
3875 */
3876 { PCI_VENDOR_ID_AFAVLAB, PCI_DEVICE_ID_AFAVLAB_P028,
3877 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3878 pbn_b0_bt_8_115200 },
3879 { PCI_VENDOR_ID_AFAVLAB, PCI_DEVICE_ID_AFAVLAB_P030,
3880 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3881 pbn_b0_bt_8_115200 },
3882
3883 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DSERIAL,
3884 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3885 pbn_b0_bt_2_115200 },
3886 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUATRO_A,
3887 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3888 pbn_b0_bt_2_115200 },
3889 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUATRO_B,
3890 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3891 pbn_b0_bt_2_115200 },
3892 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUATTRO_A,
3893 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3894 pbn_b0_bt_2_115200 },
3895 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUATTRO_B,
3896 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3897 pbn_b0_bt_2_115200 },
3898 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_OCTO_A,
3899 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3900 pbn_b0_bt_4_460800 },
3901 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_OCTO_B,
3902 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3903 pbn_b0_bt_4_460800 },
3904 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PORT_PLUS,
3905 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3906 pbn_b0_bt_2_460800 },
3907 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUAD_A,
3908 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3909 pbn_b0_bt_2_460800 },
3910 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUAD_B,
3911 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3912 pbn_b0_bt_2_460800 },
3913 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_SSERIAL,
3914 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3915 pbn_b0_bt_1_115200 },
3916 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PORT_650,
3917 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3918 pbn_b0_bt_1_460800 },
3919
3920 /*
3921 * Korenix Jetcard F0/F1 cards (JC1204, JC1208, JC1404, JC1408).
3922 * Cards are identified by their subsystem vendor IDs, which
3923 * (in hex) match the model number.
3924 *
3925 * Note that JC140x are RS422/485 cards which require ox950
3926 * ACR = 0x10, and as such are not currently fully supported.
3927 */
3928 { PCI_VENDOR_ID_KORENIX, PCI_DEVICE_ID_KORENIX_JETCARDF0,
3929 0x1204, 0x0004, 0, 0,
3930 pbn_b0_4_921600 },
3931 { PCI_VENDOR_ID_KORENIX, PCI_DEVICE_ID_KORENIX_JETCARDF0,
3932 0x1208, 0x0004, 0, 0,
3933 pbn_b0_4_921600 },
3934/* { PCI_VENDOR_ID_KORENIX, PCI_DEVICE_ID_KORENIX_JETCARDF0,
3935 0x1402, 0x0002, 0, 0,
3936 pbn_b0_2_921600 }, */
3937/* { PCI_VENDOR_ID_KORENIX, PCI_DEVICE_ID_KORENIX_JETCARDF0,
3938 0x1404, 0x0004, 0, 0,
3939 pbn_b0_4_921600 }, */
3940 { PCI_VENDOR_ID_KORENIX, PCI_DEVICE_ID_KORENIX_JETCARDF1,
3941 0x1208, 0x0004, 0, 0,
3942 pbn_b0_4_921600 },
3943
3944 { PCI_VENDOR_ID_KORENIX, PCI_DEVICE_ID_KORENIX_JETCARDF2,
3945 0x1204, 0x0004, 0, 0,
3946 pbn_b0_4_921600 },
3947 { PCI_VENDOR_ID_KORENIX, PCI_DEVICE_ID_KORENIX_JETCARDF2,
3948 0x1208, 0x0004, 0, 0,
3949 pbn_b0_4_921600 },
3950 { PCI_VENDOR_ID_KORENIX, PCI_DEVICE_ID_KORENIX_JETCARDF3,
3951 0x1208, 0x0004, 0, 0,
3952 pbn_b0_4_921600 },
3953 /*
3954 * Dell Remote Access Card 4 - Tim_T_Murphy@Dell.com
3955 */
3956 { PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_RAC4,
3957 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3958 pbn_b1_1_1382400 },
3959
3960 /*
3961 * Dell Remote Access Card III - Tim_T_Murphy@Dell.com
3962 */
3963 { PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_RACIII,
3964 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3965 pbn_b1_1_1382400 },
3966
3967 /*
3968 * RAStel 2 port modem, gerg@moreton.com.au
3969 */
3970 { PCI_VENDOR_ID_MORETON, PCI_DEVICE_ID_RASTEL_2PORT,
3971 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3972 pbn_b2_bt_2_115200 },
3973
3974 /*
3975 * EKF addition for i960 Boards form EKF with serial port
3976 */
3977 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80960_RP,
3978 0xE4BF, PCI_ANY_ID, 0, 0,
3979 pbn_intel_i960 },
3980
3981 /*
3982 * Xircom Cardbus/Ethernet combos
3983 */
3984 { PCI_VENDOR_ID_XIRCOM, PCI_DEVICE_ID_XIRCOM_X3201_MDM,
3985 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3986 pbn_b0_1_115200 },
3987 /*
3988 * Xircom RBM56G cardbus modem - Dirk Arnold (temp entry)
3989 */
3990 { PCI_VENDOR_ID_XIRCOM, PCI_DEVICE_ID_XIRCOM_RBM56G,
3991 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
3992 pbn_b0_1_115200 },
3993
3994 /*
3995 * Untested PCI modems, sent in from various folks...
3996 */
3997
3998 /*
3999 * Elsa Model 56K PCI Modem, from Andreas Rath <arh@01019freenet.de>
4000 */
4001 { PCI_VENDOR_ID_ROCKWELL, 0x1004,
4002 0x1048, 0x1500, 0, 0,
4003 pbn_b1_1_115200 },
4004
4005 { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3,
4006 0xFF00, 0, 0, 0,
4007 pbn_sgi_ioc3 },
4008
4009 /*
4010 * HP Diva card
4011 */
4012 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_DIVA,
4013 PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_DIVA_RMP3, 0, 0,
4014 pbn_b1_1_115200 },
4015 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_DIVA,
4016 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4017 pbn_b0_5_115200 },
4018 { PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_DIVA_AUX,
4019 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4020 pbn_b2_1_115200 },
4021
4022 { PCI_VENDOR_ID_DCI, PCI_DEVICE_ID_DCI_PCCOM2,
4023 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4024 pbn_b3_2_115200 },
4025 { PCI_VENDOR_ID_DCI, PCI_DEVICE_ID_DCI_PCCOM4,
4026 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4027 pbn_b3_4_115200 },
4028 { PCI_VENDOR_ID_DCI, PCI_DEVICE_ID_DCI_PCCOM8,
4029 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4030 pbn_b3_8_115200 },
4031
4032 /*
4033 * Exar Corp. XR17C15[248] Dual/Quad/Octal UART
4034 */
4035 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C152,
4036 PCI_ANY_ID, PCI_ANY_ID,
4037 0,
4038 0, pbn_exar_XR17C152 },
4039 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C154,
4040 PCI_ANY_ID, PCI_ANY_ID,
4041 0,
4042 0, pbn_exar_XR17C154 },
4043 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17C158,
4044 PCI_ANY_ID, PCI_ANY_ID,
4045 0,
4046 0, pbn_exar_XR17C158 },
4047 /*
4048 * Exar Corp. XR17V35[248] Dual/Quad/Octal PCIe UARTs
4049 */
4050 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V352,
4051 PCI_ANY_ID, PCI_ANY_ID,
4052 0,
4053 0, pbn_exar_XR17V352 },
4054 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V354,
4055 PCI_ANY_ID, PCI_ANY_ID,
4056 0,
4057 0, pbn_exar_XR17V354 },
4058 { PCI_VENDOR_ID_EXAR, PCI_DEVICE_ID_EXAR_XR17V358,
4059 PCI_ANY_ID, PCI_ANY_ID,
4060 0,
4061 0, pbn_exar_XR17V358 },
4062
4063 /*
4064 * Topic TP560 Data/Fax/Voice 56k modem (reported by Evan Clarke)
4065 */
4066 { PCI_VENDOR_ID_TOPIC, PCI_DEVICE_ID_TOPIC_TP560,
4067 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4068 pbn_b0_1_115200 },
4069 /*
4070 * ITE
4071 */
4072 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872,
4073 PCI_ANY_ID, PCI_ANY_ID,
4074 0, 0,
4075 pbn_b1_bt_1_115200 },
4076
4077 /*
4078 * IntaShield IS-200
4079 */
4080 { PCI_VENDOR_ID_INTASHIELD, PCI_DEVICE_ID_INTASHIELD_IS200,
4081 PCI_ANY_ID, PCI_ANY_ID, 0, 0, /* 135a.0811 */
4082 pbn_b2_2_115200 },
4083 /*
4084 * IntaShield IS-400
4085 */
4086 { PCI_VENDOR_ID_INTASHIELD, PCI_DEVICE_ID_INTASHIELD_IS400,
4087 PCI_ANY_ID, PCI_ANY_ID, 0, 0, /* 135a.0dc0 */
4088 pbn_b2_4_115200 },
4089 /*
4090 * Perle PCI-RAS cards
4091 */
4092 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
4093 PCI_SUBVENDOR_ID_PERLE, PCI_SUBDEVICE_ID_PCI_RAS4,
4094 0, 0, pbn_b2_4_921600 },
4095 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
4096 PCI_SUBVENDOR_ID_PERLE, PCI_SUBDEVICE_ID_PCI_RAS8,
4097 0, 0, pbn_b2_8_921600 },
4098
4099 /*
4100 * Mainpine series cards: Fairly standard layout but fools
4101 * parts of the autodetect in some cases and uses otherwise
4102 * unmatched communications subclasses in the PCI Express case
4103 */
4104
4105 { /* RockForceDUO */
4106 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4107 PCI_VENDOR_ID_MAINPINE, 0x0200,
4108 0, 0, pbn_b0_2_115200 },
4109 { /* RockForceQUATRO */
4110 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4111 PCI_VENDOR_ID_MAINPINE, 0x0300,
4112 0, 0, pbn_b0_4_115200 },
4113 { /* RockForceDUO+ */
4114 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4115 PCI_VENDOR_ID_MAINPINE, 0x0400,
4116 0, 0, pbn_b0_2_115200 },
4117 { /* RockForceQUATRO+ */
4118 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4119 PCI_VENDOR_ID_MAINPINE, 0x0500,
4120 0, 0, pbn_b0_4_115200 },
4121 { /* RockForce+ */
4122 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4123 PCI_VENDOR_ID_MAINPINE, 0x0600,
4124 0, 0, pbn_b0_2_115200 },
4125 { /* RockForce+ */
4126 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4127 PCI_VENDOR_ID_MAINPINE, 0x0700,
4128 0, 0, pbn_b0_4_115200 },
4129 { /* RockForceOCTO+ */
4130 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4131 PCI_VENDOR_ID_MAINPINE, 0x0800,
4132 0, 0, pbn_b0_8_115200 },
4133 { /* RockForceDUO+ */
4134 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4135 PCI_VENDOR_ID_MAINPINE, 0x0C00,
4136 0, 0, pbn_b0_2_115200 },
4137 { /* RockForceQUARTRO+ */
4138 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4139 PCI_VENDOR_ID_MAINPINE, 0x0D00,
4140 0, 0, pbn_b0_4_115200 },
4141 { /* RockForceOCTO+ */
4142 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4143 PCI_VENDOR_ID_MAINPINE, 0x1D00,
4144 0, 0, pbn_b0_8_115200 },
4145 { /* RockForceD1 */
4146 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4147 PCI_VENDOR_ID_MAINPINE, 0x2000,
4148 0, 0, pbn_b0_1_115200 },
4149 { /* RockForceF1 */
4150 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4151 PCI_VENDOR_ID_MAINPINE, 0x2100,
4152 0, 0, pbn_b0_1_115200 },
4153 { /* RockForceD2 */
4154 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4155 PCI_VENDOR_ID_MAINPINE, 0x2200,
4156 0, 0, pbn_b0_2_115200 },
4157 { /* RockForceF2 */
4158 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4159 PCI_VENDOR_ID_MAINPINE, 0x2300,
4160 0, 0, pbn_b0_2_115200 },
4161 { /* RockForceD4 */
4162 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4163 PCI_VENDOR_ID_MAINPINE, 0x2400,
4164 0, 0, pbn_b0_4_115200 },
4165 { /* RockForceF4 */
4166 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4167 PCI_VENDOR_ID_MAINPINE, 0x2500,
4168 0, 0, pbn_b0_4_115200 },
4169 { /* RockForceD8 */
4170 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4171 PCI_VENDOR_ID_MAINPINE, 0x2600,
4172 0, 0, pbn_b0_8_115200 },
4173 { /* RockForceF8 */
4174 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4175 PCI_VENDOR_ID_MAINPINE, 0x2700,
4176 0, 0, pbn_b0_8_115200 },
4177 { /* IQ Express D1 */
4178 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4179 PCI_VENDOR_ID_MAINPINE, 0x3000,
4180 0, 0, pbn_b0_1_115200 },
4181 { /* IQ Express F1 */
4182 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4183 PCI_VENDOR_ID_MAINPINE, 0x3100,
4184 0, 0, pbn_b0_1_115200 },
4185 { /* IQ Express D2 */
4186 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4187 PCI_VENDOR_ID_MAINPINE, 0x3200,
4188 0, 0, pbn_b0_2_115200 },
4189 { /* IQ Express F2 */
4190 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4191 PCI_VENDOR_ID_MAINPINE, 0x3300,
4192 0, 0, pbn_b0_2_115200 },
4193 { /* IQ Express D4 */
4194 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4195 PCI_VENDOR_ID_MAINPINE, 0x3400,
4196 0, 0, pbn_b0_4_115200 },
4197 { /* IQ Express F4 */
4198 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4199 PCI_VENDOR_ID_MAINPINE, 0x3500,
4200 0, 0, pbn_b0_4_115200 },
4201 { /* IQ Express D8 */
4202 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4203 PCI_VENDOR_ID_MAINPINE, 0x3C00,
4204 0, 0, pbn_b0_8_115200 },
4205 { /* IQ Express F8 */
4206 PCI_VENDOR_ID_MAINPINE, PCI_DEVICE_ID_MAINPINE_PBRIDGE,
4207 PCI_VENDOR_ID_MAINPINE, 0x3D00,
4208 0, 0, pbn_b0_8_115200 },
4209
4210
4211 /*
4212 * PA Semi PA6T-1682M on-chip UART
4213 */
4214 { PCI_VENDOR_ID_PASEMI, 0xa004,
4215 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4216 pbn_pasemi_1682M },
4217
4218 /*
4219 * National Instruments
4220 */
4221 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI23216,
4222 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4223 pbn_b1_16_115200 },
4224 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI2328,
4225 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4226 pbn_b1_8_115200 },
4227 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI2324,
4228 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4229 pbn_b1_bt_4_115200 },
4230 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI2322,
4231 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4232 pbn_b1_bt_2_115200 },
4233 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI2324I,
4234 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4235 pbn_b1_bt_4_115200 },
4236 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI2322I,
4237 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4238 pbn_b1_bt_2_115200 },
4239 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8420_23216,
4240 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4241 pbn_b1_16_115200 },
4242 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8420_2328,
4243 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4244 pbn_b1_8_115200 },
4245 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8420_2324,
4246 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4247 pbn_b1_bt_4_115200 },
4248 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8420_2322,
4249 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4250 pbn_b1_bt_2_115200 },
4251 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8422_2324,
4252 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4253 pbn_b1_bt_4_115200 },
4254 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8422_2322,
4255 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4256 pbn_b1_bt_2_115200 },
4257 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8430_2322,
4258 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4259 pbn_ni8430_2 },
4260 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI8430_2322,
4261 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4262 pbn_ni8430_2 },
4263 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8430_2324,
4264 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4265 pbn_ni8430_4 },
4266 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI8430_2324,
4267 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4268 pbn_ni8430_4 },
4269 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8430_2328,
4270 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4271 pbn_ni8430_8 },
4272 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI8430_2328,
4273 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4274 pbn_ni8430_8 },
4275 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8430_23216,
4276 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4277 pbn_ni8430_16 },
4278 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI8430_23216,
4279 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4280 pbn_ni8430_16 },
4281 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8432_2322,
4282 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4283 pbn_ni8430_2 },
4284 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI8432_2322,
4285 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4286 pbn_ni8430_2 },
4287 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI8432_2324,
4288 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4289 pbn_ni8430_4 },
4290 { PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI8432_2324,
4291 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4292 pbn_ni8430_4 },
4293
4294 /*
4295 * ADDI-DATA GmbH communication cards <info@addi-data.com>
4296 */
4297 { PCI_VENDOR_ID_ADDIDATA,
4298 PCI_DEVICE_ID_ADDIDATA_APCI7500,
4299 PCI_ANY_ID,
4300 PCI_ANY_ID,
4301 0,
4302 0,
4303 pbn_b0_4_115200 },
4304
4305 { PCI_VENDOR_ID_ADDIDATA,
4306 PCI_DEVICE_ID_ADDIDATA_APCI7420,
4307 PCI_ANY_ID,
4308 PCI_ANY_ID,
4309 0,
4310 0,
4311 pbn_b0_2_115200 },
4312
4313 { PCI_VENDOR_ID_ADDIDATA,
4314 PCI_DEVICE_ID_ADDIDATA_APCI7300,
4315 PCI_ANY_ID,
4316 PCI_ANY_ID,
4317 0,
4318 0,
4319 pbn_b0_1_115200 },
4320
4321 { PCI_VENDOR_ID_ADDIDATA_OLD,
4322 PCI_DEVICE_ID_ADDIDATA_APCI7800,
4323 PCI_ANY_ID,
4324 PCI_ANY_ID,
4325 0,
4326 0,
4327 pbn_b1_8_115200 },
4328
4329 { PCI_VENDOR_ID_ADDIDATA,
4330 PCI_DEVICE_ID_ADDIDATA_APCI7500_2,
4331 PCI_ANY_ID,
4332 PCI_ANY_ID,
4333 0,
4334 0,
4335 pbn_b0_4_115200 },
4336
4337 { PCI_VENDOR_ID_ADDIDATA,
4338 PCI_DEVICE_ID_ADDIDATA_APCI7420_2,
4339 PCI_ANY_ID,
4340 PCI_ANY_ID,
4341 0,
4342 0,
4343 pbn_b0_2_115200 },
4344
4345 { PCI_VENDOR_ID_ADDIDATA,
4346 PCI_DEVICE_ID_ADDIDATA_APCI7300_2,
4347 PCI_ANY_ID,
4348 PCI_ANY_ID,
4349 0,
4350 0,
4351 pbn_b0_1_115200 },
4352
4353 { PCI_VENDOR_ID_ADDIDATA,
4354 PCI_DEVICE_ID_ADDIDATA_APCI7500_3,
4355 PCI_ANY_ID,
4356 PCI_ANY_ID,
4357 0,
4358 0,
4359 pbn_b0_4_115200 },
4360
4361 { PCI_VENDOR_ID_ADDIDATA,
4362 PCI_DEVICE_ID_ADDIDATA_APCI7420_3,
4363 PCI_ANY_ID,
4364 PCI_ANY_ID,
4365 0,
4366 0,
4367 pbn_b0_2_115200 },
4368
4369 { PCI_VENDOR_ID_ADDIDATA,
4370 PCI_DEVICE_ID_ADDIDATA_APCI7300_3,
4371 PCI_ANY_ID,
4372 PCI_ANY_ID,
4373 0,
4374 0,
4375 pbn_b0_1_115200 },
4376
4377 { PCI_VENDOR_ID_ADDIDATA,
4378 PCI_DEVICE_ID_ADDIDATA_APCI7800_3,
4379 PCI_ANY_ID,
4380 PCI_ANY_ID,
4381 0,
4382 0,
4383 pbn_b0_8_115200 },
4384
4385 { PCI_VENDOR_ID_ADDIDATA,
4386 PCI_DEVICE_ID_ADDIDATA_APCIe7500,
4387 PCI_ANY_ID,
4388 PCI_ANY_ID,
4389 0,
4390 0,
4391 pbn_ADDIDATA_PCIe_4_3906250 },
4392
4393 { PCI_VENDOR_ID_ADDIDATA,
4394 PCI_DEVICE_ID_ADDIDATA_APCIe7420,
4395 PCI_ANY_ID,
4396 PCI_ANY_ID,
4397 0,
4398 0,
4399 pbn_ADDIDATA_PCIe_2_3906250 },
4400
4401 { PCI_VENDOR_ID_ADDIDATA,
4402 PCI_DEVICE_ID_ADDIDATA_APCIe7300,
4403 PCI_ANY_ID,
4404 PCI_ANY_ID,
4405 0,
4406 0,
4407 pbn_ADDIDATA_PCIe_1_3906250 },
4408
4409 { PCI_VENDOR_ID_ADDIDATA,
4410 PCI_DEVICE_ID_ADDIDATA_APCIe7800,
4411 PCI_ANY_ID,
4412 PCI_ANY_ID,
4413 0,
4414 0,
4415 pbn_ADDIDATA_PCIe_8_3906250 },
4416
4417 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
4418 PCI_VENDOR_ID_IBM, 0x0299,
4419 0, 0, pbn_b0_bt_2_115200 },
4420
4421 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9901,
4422 0xA000, 0x1000,
4423 0, 0, pbn_b0_1_115200 },
4424
4425 /* the 9901 is a rebranded 9912 */
4426 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9912,
4427 0xA000, 0x1000,
4428 0, 0, pbn_b0_1_115200 },
4429
4430 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9922,
4431 0xA000, 0x1000,
4432 0, 0, pbn_b0_1_115200 },
4433
4434 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9904,
4435 0xA000, 0x1000,
4436 0, 0, pbn_b0_1_115200 },
4437
4438 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
4439 0xA000, 0x1000,
4440 0, 0, pbn_b0_1_115200 },
4441
4442 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9900,
4443 0xA000, 0x3002,
4444 0, 0, pbn_NETMOS9900_2s_115200 },
4445
4446 /*
4447 * Best Connectivity and Rosewill PCI Multi I/O cards
4448 */
4449
4450 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9865,
4451 0xA000, 0x1000,
4452 0, 0, pbn_b0_1_115200 },
4453
4454 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9865,
4455 0xA000, 0x3002,
4456 0, 0, pbn_b0_bt_2_115200 },
4457
4458 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9865,
4459 0xA000, 0x3004,
4460 0, 0, pbn_b0_bt_4_115200 },
4461 /* Intel CE4100 */
4462 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CE4100_UART,
4463 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4464 pbn_ce4100_1_115200 },
4465
4466 /*
4467 * Cronyx Omega PCI
4468 */
4469 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_CRONYX_OMEGA,
4470 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
4471 pbn_omegapci },
4472
4473 /*
4474 * AgeStar as-prs2-009
4475 */
4476 { PCI_VENDOR_ID_AGESTAR, PCI_DEVICE_ID_AGESTAR_9375,
4477 PCI_ANY_ID, PCI_ANY_ID,
4478 0, 0, pbn_b0_bt_2_115200 },
4479
4480 /*
4481 * WCH CH353 series devices: The 2S1P is handled by parport_serial
4482 * so not listed here.
4483 */
4484 { PCI_VENDOR_ID_WCH, PCI_DEVICE_ID_WCH_CH353_4S,
4485 PCI_ANY_ID, PCI_ANY_ID,
4486 0, 0, pbn_b0_bt_4_115200 },
4487
4488 { PCI_VENDOR_ID_WCH, PCI_DEVICE_ID_WCH_CH353_2S1PF,
4489 PCI_ANY_ID, PCI_ANY_ID,
4490 0, 0, pbn_b0_bt_2_115200 },
4491
4492 /*
4493 * Commtech, Inc. Fastcom adapters
4494 */
4495 { PCI_VENDOR_ID_COMMTECH, PCI_DEVICE_ID_COMMTECH_4222PCI335,
4496 PCI_ANY_ID, PCI_ANY_ID,
4497 0,
4498 0, pbn_b0_2_1152000_200 },
4499 { PCI_VENDOR_ID_COMMTECH, PCI_DEVICE_ID_COMMTECH_4224PCI335,
4500 PCI_ANY_ID, PCI_ANY_ID,
4501 0,
4502 0, pbn_b0_4_1152000_200 },
4503 { PCI_VENDOR_ID_COMMTECH, PCI_DEVICE_ID_COMMTECH_2324PCI335,
4504 PCI_ANY_ID, PCI_ANY_ID,
4505 0,
4506 0, pbn_b0_4_1152000_200 },
4507 { PCI_VENDOR_ID_COMMTECH, PCI_DEVICE_ID_COMMTECH_2328PCI335,
4508 PCI_ANY_ID, PCI_ANY_ID,
4509 0,
4510 0, pbn_b0_8_1152000_200 },
4511 { PCI_VENDOR_ID_COMMTECH, PCI_DEVICE_ID_COMMTECH_4222PCIE,
4512 PCI_ANY_ID, PCI_ANY_ID,
4513 0,
4514 0, pbn_exar_XR17V352 },
4515 { PCI_VENDOR_ID_COMMTECH, PCI_DEVICE_ID_COMMTECH_4224PCIE,
4516 PCI_ANY_ID, PCI_ANY_ID,
4517 0,
4518 0, pbn_exar_XR17V354 },
4519 { PCI_VENDOR_ID_COMMTECH, PCI_DEVICE_ID_COMMTECH_4228PCIE,
4520 PCI_ANY_ID, PCI_ANY_ID,
4521 0,
4522 0, pbn_exar_XR17V358 },
4523
4524 /*
4525 * These entries match devices with class COMMUNICATION_SERIAL,
4526 * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL
4527 */
4528 { PCI_ANY_ID, PCI_ANY_ID,
4529 PCI_ANY_ID, PCI_ANY_ID,
4530 PCI_CLASS_COMMUNICATION_SERIAL << 8,
4531 0xffff00, pbn_default },
4532 { PCI_ANY_ID, PCI_ANY_ID,
4533 PCI_ANY_ID, PCI_ANY_ID,
4534 PCI_CLASS_COMMUNICATION_MODEM << 8,
4535 0xffff00, pbn_default },
4536 { PCI_ANY_ID, PCI_ANY_ID,
4537 PCI_ANY_ID, PCI_ANY_ID,
4538 PCI_CLASS_COMMUNICATION_MULTISERIAL << 8,
4539 0xffff00, pbn_default },
4540 { 0, }
4541};
4542
4543static pci_ers_result_t serial8250_io_error_detected(struct pci_dev *dev,
4544 pci_channel_state_t state)
4545{
4546 struct serial_private *priv = pci_get_drvdata(dev);
4547
4548 if (state == pci_channel_io_perm_failure)
4549 return PCI_ERS_RESULT_DISCONNECT;
4550
4551 if (priv)
4552 pciserial_suspend_ports(priv);
4553
4554 pci_disable_device(dev);
4555
4556 return PCI_ERS_RESULT_NEED_RESET;
4557}
4558
4559static pci_ers_result_t serial8250_io_slot_reset(struct pci_dev *dev)
4560{
4561 int rc;
4562
4563 rc = pci_enable_device(dev);
4564
4565 if (rc)
4566 return PCI_ERS_RESULT_DISCONNECT;
4567
4568 pci_restore_state(dev);
4569 pci_save_state(dev);
4570
4571 return PCI_ERS_RESULT_RECOVERED;
4572}
4573
4574static void serial8250_io_resume(struct pci_dev *dev)
4575{
4576 struct serial_private *priv = pci_get_drvdata(dev);
4577
4578 if (priv)
4579 pciserial_resume_ports(priv);
4580}
4581
4582static const struct pci_error_handlers serial8250_err_handler = {
4583 .error_detected = serial8250_io_error_detected,
4584 .slot_reset = serial8250_io_slot_reset,
4585 .resume = serial8250_io_resume,
4586};
4587
4588static struct pci_driver serial_pci_driver = {
4589 .name = "serial",
4590 .probe = pciserial_init_one,
4591 .remove = pciserial_remove_one,
4592#ifdef CONFIG_PM
4593 .suspend = pciserial_suspend_one,
4594 .resume = pciserial_resume_one,
4595#endif
4596 .id_table = serial_pci_tbl,
4597 .err_handler = &serial8250_err_handler,
4598};
4599
4600module_pci_driver(serial_pci_driver);
4601
4602MODULE_LICENSE("GPL");
4603MODULE_DESCRIPTION("Generic 8250/16x50 PCI serial probe module");
4604MODULE_DEVICE_TABLE(pci, serial_pci_tbl);
diff --git a/drivers/tty/serial/8250/8250_pnp.c b/drivers/tty/serial/8250/8250_pnp.c
deleted file mode 100644
index 35d9ab95c5c..00000000000
--- a/drivers/tty/serial/8250/8250_pnp.c
+++ /dev/null
@@ -1,529 +0,0 @@
1/*
2 * Probe for 8250/16550-type ISAPNP serial ports.
3 *
4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
5 *
6 * Copyright (C) 2001 Russell King, All Rights Reserved.
7 *
8 * Ported to the Linux PnP Layer - (C) Adam Belay.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License.
13 */
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/pci.h>
17#include <linux/pnp.h>
18#include <linux/string.h>
19#include <linux/kernel.h>
20#include <linux/serial_core.h>
21#include <linux/bitops.h>
22
23#include <asm/byteorder.h>
24
25#include "8250.h"
26
27#define UNKNOWN_DEV 0x3000
28#define CIR_PORT 0x0800
29
30static const struct pnp_device_id pnp_dev_table[] = {
31 /* Archtek America Corp. */
32 /* Archtek SmartLink Modem 3334BT Plug & Play */
33 { "AAC000F", 0 },
34 /* Anchor Datacomm BV */
35 /* SXPro 144 External Data Fax Modem Plug & Play */
36 { "ADC0001", 0 },
37 /* SXPro 288 External Data Fax Modem Plug & Play */
38 { "ADC0002", 0 },
39 /* PROLiNK 1456VH ISA PnP K56flex Fax Modem */
40 { "AEI0250", 0 },
41 /* Actiontec ISA PNP 56K X2 Fax Modem */
42 { "AEI1240", 0 },
43 /* Rockwell 56K ACF II Fax+Data+Voice Modem */
44 { "AKY1021", 0 /*SPCI_FL_NO_SHIRQ*/ },
45 /* AZT3005 PnP SOUND DEVICE */
46 { "AZT4001", 0 },
47 /* Best Data Products Inc. Smart One 336F PnP Modem */
48 { "BDP3336", 0 },
49 /* Boca Research */
50 /* Boca Complete Ofc Communicator 14.4 Data-FAX */
51 { "BRI0A49", 0 },
52 /* Boca Research 33,600 ACF Modem */
53 { "BRI1400", 0 },
54 /* Boca 33.6 Kbps Internal FD34FSVD */
55 { "BRI3400", 0 },
56 /* Boca 33.6 Kbps Internal FD34FSVD */
57 { "BRI0A49", 0 },
58 /* Best Data Products Inc. Smart One 336F PnP Modem */
59 { "BDP3336", 0 },
60 /* Computer Peripherals Inc */
61 /* EuroViVa CommCenter-33.6 SP PnP */
62 { "CPI4050", 0 },
63 /* Creative Labs */
64 /* Creative Labs Phone Blaster 28.8 DSVD PnP Voice */
65 { "CTL3001", 0 },
66 /* Creative Labs Modem Blaster 28.8 DSVD PnP Voice */
67 { "CTL3011", 0 },
68 /* Davicom ISA 33.6K Modem */
69 { "DAV0336", 0 },
70 /* Creative */
71 /* Creative Modem Blaster Flash56 DI5601-1 */
72 { "DMB1032", 0 },
73 /* Creative Modem Blaster V.90 DI5660 */
74 { "DMB2001", 0 },
75 /* E-Tech */
76 /* E-Tech CyberBULLET PC56RVP */
77 { "ETT0002", 0 },
78 /* FUJITSU */
79 /* Fujitsu 33600 PnP-I2 R Plug & Play */
80 { "FUJ0202", 0 },
81 /* Fujitsu FMV-FX431 Plug & Play */
82 { "FUJ0205", 0 },
83 /* Fujitsu 33600 PnP-I4 R Plug & Play */
84 { "FUJ0206", 0 },
85 /* Fujitsu Fax Voice 33600 PNP-I5 R Plug & Play */
86 { "FUJ0209", 0 },
87 /* Archtek America Corp. */
88 /* Archtek SmartLink Modem 3334BT Plug & Play */
89 { "GVC000F", 0 },
90 /* Archtek SmartLink Modem 3334BRV 33.6K Data Fax Voice */
91 { "GVC0303", 0 },
92 /* Hayes */
93 /* Hayes Optima 288 V.34-V.FC + FAX + Voice Plug & Play */
94 { "HAY0001", 0 },
95 /* Hayes Optima 336 V.34 + FAX + Voice PnP */
96 { "HAY000C", 0 },
97 /* Hayes Optima 336B V.34 + FAX + Voice PnP */
98 { "HAY000D", 0 },
99 /* Hayes Accura 56K Ext Fax Modem PnP */
100 { "HAY5670", 0 },
101 /* Hayes Accura 56K Ext Fax Modem PnP */
102 { "HAY5674", 0 },
103 /* Hayes Accura 56K Fax Modem PnP */
104 { "HAY5675", 0 },
105 /* Hayes 288, V.34 + FAX */
106 { "HAYF000", 0 },
107 /* Hayes Optima 288 V.34 + FAX + Voice, Plug & Play */
108 { "HAYF001", 0 },
109 /* IBM */
110 /* IBM Thinkpad 701 Internal Modem Voice */
111 { "IBM0033", 0 },
112 /* Intermec */
113 /* Intermec CV60 touchscreen port */
114 { "PNP4972", 0 },
115 /* Intertex */
116 /* Intertex 28k8 33k6 Voice EXT PnP */
117 { "IXDC801", 0 },
118 /* Intertex 33k6 56k Voice EXT PnP */
119 { "IXDC901", 0 },
120 /* Intertex 28k8 33k6 Voice SP EXT PnP */
121 { "IXDD801", 0 },
122 /* Intertex 33k6 56k Voice SP EXT PnP */
123 { "IXDD901", 0 },
124 /* Intertex 28k8 33k6 Voice SP INT PnP */
125 { "IXDF401", 0 },
126 /* Intertex 28k8 33k6 Voice SP EXT PnP */
127 { "IXDF801", 0 },
128 /* Intertex 33k6 56k Voice SP EXT PnP */
129 { "IXDF901", 0 },
130 /* Kortex International */
131 /* KORTEX 28800 Externe PnP */
132 { "KOR4522", 0 },
133 /* KXPro 33.6 Vocal ASVD PnP */
134 { "KORF661", 0 },
135 /* Lasat */
136 /* LASAT Internet 33600 PnP */
137 { "LAS4040", 0 },
138 /* Lasat Safire 560 PnP */
139 { "LAS4540", 0 },
140 /* Lasat Safire 336 PnP */
141 { "LAS5440", 0 },
142 /* Microcom, Inc. */
143 /* Microcom TravelPorte FAST V.34 Plug & Play */
144 { "MNP0281", 0 },
145 /* Microcom DeskPorte V.34 FAST or FAST+ Plug & Play */
146 { "MNP0336", 0 },
147 /* Microcom DeskPorte FAST EP 28.8 Plug & Play */
148 { "MNP0339", 0 },
149 /* Microcom DeskPorte 28.8P Plug & Play */
150 { "MNP0342", 0 },
151 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
152 { "MNP0500", 0 },
153 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
154 { "MNP0501", 0 },
155 /* Microcom DeskPorte 28.8S Internal Plug & Play */
156 { "MNP0502", 0 },
157 /* Motorola */
158 /* Motorola BitSURFR Plug & Play */
159 { "MOT1105", 0 },
160 /* Motorola TA210 Plug & Play */
161 { "MOT1111", 0 },
162 /* Motorola HMTA 200 (ISDN) Plug & Play */
163 { "MOT1114", 0 },
164 /* Motorola BitSURFR Plug & Play */
165 { "MOT1115", 0 },
166 /* Motorola Lifestyle 28.8 Internal */
167 { "MOT1190", 0 },
168 /* Motorola V.3400 Plug & Play */
169 { "MOT1501", 0 },
170 /* Motorola Lifestyle 28.8 V.34 Plug & Play */
171 { "MOT1502", 0 },
172 /* Motorola Power 28.8 V.34 Plug & Play */
173 { "MOT1505", 0 },
174 /* Motorola ModemSURFR External 28.8 Plug & Play */
175 { "MOT1509", 0 },
176 /* Motorola Premier 33.6 Desktop Plug & Play */
177 { "MOT150A", 0 },
178 /* Motorola VoiceSURFR 56K External PnP */
179 { "MOT150F", 0 },
180 /* Motorola ModemSURFR 56K External PnP */
181 { "MOT1510", 0 },
182 /* Motorola ModemSURFR 56K Internal PnP */
183 { "MOT1550", 0 },
184 /* Motorola ModemSURFR Internal 28.8 Plug & Play */
185 { "MOT1560", 0 },
186 /* Motorola Premier 33.6 Internal Plug & Play */
187 { "MOT1580", 0 },
188 /* Motorola OnlineSURFR 28.8 Internal Plug & Play */
189 { "MOT15B0", 0 },
190 /* Motorola VoiceSURFR 56K Internal PnP */
191 { "MOT15F0", 0 },
192 /* Com 1 */
193 /* Deskline K56 Phone System PnP */
194 { "MVX00A1", 0 },
195 /* PC Rider K56 Phone System PnP */
196 { "MVX00F2", 0 },
197 /* NEC 98NOTE SPEAKER PHONE FAX MODEM(33600bps) */
198 { "nEC8241", 0 },
199 /* Pace 56 Voice Internal Plug & Play Modem */
200 { "PMC2430", 0 },
201 /* Generic */
202 /* Generic standard PC COM port */
203 { "PNP0500", 0 },
204 /* Generic 16550A-compatible COM port */
205 { "PNP0501", 0 },
206 /* Compaq 14400 Modem */
207 { "PNPC000", 0 },
208 /* Compaq 2400/9600 Modem */
209 { "PNPC001", 0 },
210 /* Dial-Up Networking Serial Cable between 2 PCs */
211 { "PNPC031", 0 },
212 /* Dial-Up Networking Parallel Cable between 2 PCs */
213 { "PNPC032", 0 },
214 /* Standard 9600 bps Modem */
215 { "PNPC100", 0 },
216 /* Standard 14400 bps Modem */
217 { "PNPC101", 0 },
218 /* Standard 28800 bps Modem*/
219 { "PNPC102", 0 },
220 /* Standard Modem*/
221 { "PNPC103", 0 },
222 /* Standard 9600 bps Modem*/
223 { "PNPC104", 0 },
224 /* Standard 14400 bps Modem*/
225 { "PNPC105", 0 },
226 /* Standard 28800 bps Modem*/
227 { "PNPC106", 0 },
228 /* Standard Modem */
229 { "PNPC107", 0 },
230 /* Standard 9600 bps Modem */
231 { "PNPC108", 0 },
232 /* Standard 14400 bps Modem */
233 { "PNPC109", 0 },
234 /* Standard 28800 bps Modem */
235 { "PNPC10A", 0 },
236 /* Standard Modem */
237 { "PNPC10B", 0 },
238 /* Standard 9600 bps Modem */
239 { "PNPC10C", 0 },
240 /* Standard 14400 bps Modem */
241 { "PNPC10D", 0 },
242 /* Standard 28800 bps Modem */
243 { "PNPC10E", 0 },
244 /* Standard Modem */
245 { "PNPC10F", 0 },
246 /* Standard PCMCIA Card Modem */
247 { "PNP2000", 0 },
248 /* Rockwell */
249 /* Modular Technology */
250 /* Rockwell 33.6 DPF Internal PnP */
251 /* Modular Technology 33.6 Internal PnP */
252 { "ROK0030", 0 },
253 /* Kortex International */
254 /* KORTEX 14400 Externe PnP */
255 { "ROK0100", 0 },
256 /* Rockwell 28.8 */
257 { "ROK4120", 0 },
258 /* Viking Components, Inc */
259 /* Viking 28.8 INTERNAL Fax+Data+Voice PnP */
260 { "ROK4920", 0 },
261 /* Rockwell */
262 /* British Telecom */
263 /* Modular Technology */
264 /* Rockwell 33.6 DPF External PnP */
265 /* BT Prologue 33.6 External PnP */
266 /* Modular Technology 33.6 External PnP */
267 { "RSS00A0", 0 },
268 /* Viking 56K FAX INT */
269 { "RSS0262", 0 },
270 /* K56 par,VV,Voice,Speakphone,AudioSpan,PnP */
271 { "RSS0250", 0 },
272 /* SupraExpress 28.8 Data/Fax PnP modem */
273 { "SUP1310", 0 },
274 /* SupraExpress 336i PnP Voice Modem */
275 { "SUP1381", 0 },
276 /* SupraExpress 33.6 Data/Fax PnP modem */
277 { "SUP1421", 0 },
278 /* SupraExpress 33.6 Data/Fax PnP modem */
279 { "SUP1590", 0 },
280 /* SupraExpress 336i Sp ASVD */
281 { "SUP1620", 0 },
282 /* SupraExpress 33.6 Data/Fax PnP modem */
283 { "SUP1760", 0 },
284 /* SupraExpress 56i Sp Intl */
285 { "SUP2171", 0 },
286 /* Phoebe Micro */
287 /* Phoebe Micro 33.6 Data Fax 1433VQH Plug & Play */
288 { "TEX0011", 0 },
289 /* Archtek America Corp. */
290 /* Archtek SmartLink Modem 3334BT Plug & Play */
291 { "UAC000F", 0 },
292 /* 3Com Corp. */
293 /* Gateway Telepath IIvi 33.6 */
294 { "USR0000", 0 },
295 /* U.S. Robotics Sporster 33.6K Fax INT PnP */
296 { "USR0002", 0 },
297 /* Sportster Vi 14.4 PnP FAX Voicemail */
298 { "USR0004", 0 },
299 /* U.S. Robotics 33.6K Voice INT PnP */
300 { "USR0006", 0 },
301 /* U.S. Robotics 33.6K Voice EXT PnP */
302 { "USR0007", 0 },
303 /* U.S. Robotics Courier V.Everything INT PnP */
304 { "USR0009", 0 },
305 /* U.S. Robotics 33.6K Voice INT PnP */
306 { "USR2002", 0 },
307 /* U.S. Robotics 56K Voice INT PnP */
308 { "USR2070", 0 },
309 /* U.S. Robotics 56K Voice EXT PnP */
310 { "USR2080", 0 },
311 /* U.S. Robotics 56K FAX INT */
312 { "USR3031", 0 },
313 /* U.S. Robotics 56K FAX INT */
314 { "USR3050", 0 },
315 /* U.S. Robotics 56K Voice INT PnP */
316 { "USR3070", 0 },
317 /* U.S. Robotics 56K Voice EXT PnP */
318 { "USR3080", 0 },
319 /* U.S. Robotics 56K Voice INT PnP */
320 { "USR3090", 0 },
321 /* U.S. Robotics 56K Message */
322 { "USR9100", 0 },
323 /* U.S. Robotics 56K FAX EXT PnP*/
324 { "USR9160", 0 },
325 /* U.S. Robotics 56K FAX INT PnP*/
326 { "USR9170", 0 },
327 /* U.S. Robotics 56K Voice EXT PnP*/
328 { "USR9180", 0 },
329 /* U.S. Robotics 56K Voice INT PnP*/
330 { "USR9190", 0 },
331 /* Wacom tablets */
332 { "WACFXXX", 0 },
333 /* Compaq touchscreen */
334 { "FPI2002", 0 },
335 /* Fujitsu Stylistic touchscreens */
336 { "FUJ02B2", 0 },
337 { "FUJ02B3", 0 },
338 /* Fujitsu Stylistic LT touchscreens */
339 { "FUJ02B4", 0 },
340 /* Passive Fujitsu Stylistic touchscreens */
341 { "FUJ02B6", 0 },
342 { "FUJ02B7", 0 },
343 { "FUJ02B8", 0 },
344 { "FUJ02B9", 0 },
345 { "FUJ02BC", 0 },
346 /* Fujitsu Wacom Tablet PC device */
347 { "FUJ02E5", 0 },
348 /* Fujitsu P-series tablet PC device */
349 { "FUJ02E6", 0 },
350 /* Fujitsu Wacom 2FGT Tablet PC device */
351 { "FUJ02E7", 0 },
352 /* Fujitsu Wacom 1FGT Tablet PC device */
353 { "FUJ02E9", 0 },
354 /*
355 * LG C1 EXPRESS DUAL (C1-PB11A3) touch screen (actually a FUJ02E6 in
356 * disguise)
357 */
358 { "LTS0001", 0 },
359 /* Rockwell's (PORALiNK) 33600 INT PNP */
360 { "WCI0003", 0 },
361 /* Unknown PnP modems */
362 { "PNPCXXX", UNKNOWN_DEV },
363 /* More unknown PnP modems */
364 { "PNPDXXX", UNKNOWN_DEV },
365 /* Winbond CIR port, should not be probed. We should keep track
366 of it to prevent the legacy serial driver from probing it */
367 { "WEC1022", CIR_PORT },
368 { "", 0 }
369};
370
371MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
372
373static char *modem_names[] = {
374 "MODEM", "Modem", "modem", "FAX", "Fax", "fax",
375 "56K", "56k", "K56", "33.6", "28.8", "14.4",
376 "33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
377 "33600", "28800", "14400", "V.90", "V.34", "V.32", NULL
378};
379
380static int check_name(char *name)
381{
382 char **tmp;
383
384 for (tmp = modem_names; *tmp; tmp++)
385 if (strstr(name, *tmp))
386 return 1;
387
388 return 0;
389}
390
391static int check_resources(struct pnp_dev *dev)
392{
393 resource_size_t base[] = {0x2f8, 0x3f8, 0x2e8, 0x3e8};
394 int i;
395
396 for (i = 0; i < ARRAY_SIZE(base); i++) {
397 if (pnp_possible_config(dev, IORESOURCE_IO, base[i], 8))
398 return 1;
399 }
400
401 return 0;
402}
403
404/*
405 * Given a complete unknown PnP device, try to use some heuristics to
406 * detect modems. Currently use such heuristic set:
407 * - dev->name or dev->bus->name must contain "modem" substring;
408 * - device must have only one IO region (8 byte long) with base address
409 * 0x2e8, 0x3e8, 0x2f8 or 0x3f8.
410 *
411 * Such detection looks very ugly, but can detect at least some of numerous
412 * PnP modems, alternatively we must hardcode all modems in pnp_devices[]
413 * table.
414 */
415static int serial_pnp_guess_board(struct pnp_dev *dev)
416{
417 if (!(check_name(pnp_dev_name(dev)) ||
418 (dev->card && check_name(dev->card->name))))
419 return -ENODEV;
420
421 if (check_resources(dev))
422 return 0;
423
424 return -ENODEV;
425}
426
427static int
428serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
429{
430 struct uart_8250_port uart;
431 int ret, line, flags = dev_id->driver_data;
432
433 if (flags & UNKNOWN_DEV) {
434 ret = serial_pnp_guess_board(dev);
435 if (ret < 0)
436 return ret;
437 }
438
439 memset(&uart, 0, sizeof(uart));
440 if (pnp_irq_valid(dev, 0))
441 uart.port.irq = pnp_irq(dev, 0);
442 if ((flags & CIR_PORT) && pnp_port_valid(dev, 2)) {
443 uart.port.iobase = pnp_port_start(dev, 2);
444 uart.port.iotype = UPIO_PORT;
445 } else if (pnp_port_valid(dev, 0)) {
446 uart.port.iobase = pnp_port_start(dev, 0);
447 uart.port.iotype = UPIO_PORT;
448 } else if (pnp_mem_valid(dev, 0)) {
449 uart.port.mapbase = pnp_mem_start(dev, 0);
450 uart.port.iotype = UPIO_MEM;
451 uart.port.flags = UPF_IOREMAP;
452 } else
453 return -ENODEV;
454
455#ifdef SERIAL_DEBUG_PNP
456 printk(KERN_DEBUG
457 "Setup PNP port: port %x, mem 0x%lx, irq %d, type %d\n",
458 uart.port.iobase, uart.port.mapbase, uart.port.irq, uart.port.iotype);
459#endif
460 if (flags & CIR_PORT) {
461 uart.port.flags |= UPF_FIXED_PORT | UPF_FIXED_TYPE;
462 uart.port.type = PORT_8250_CIR;
463 }
464
465 uart.port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
466 if (pnp_irq_flags(dev, 0) & IORESOURCE_IRQ_SHAREABLE)
467 uart.port.flags |= UPF_SHARE_IRQ;
468 uart.port.uartclk = 1843200;
469 uart.port.dev = &dev->dev;
470
471 line = serial8250_register_8250_port(&uart);
472 if (line < 0 || (flags & CIR_PORT))
473 return -ENODEV;
474
475 pnp_set_drvdata(dev, (void *)((long)line + 1));
476 return 0;
477}
478
479static void serial_pnp_remove(struct pnp_dev *dev)
480{
481 long line = (long)pnp_get_drvdata(dev);
482 if (line)
483 serial8250_unregister_port(line - 1);
484}
485
486#ifdef CONFIG_PM
487static int serial_pnp_suspend(struct pnp_dev *dev, pm_message_t state)
488{
489 long line = (long)pnp_get_drvdata(dev);
490
491 if (!line)
492 return -ENODEV;
493 serial8250_suspend_port(line - 1);
494 return 0;
495}
496
497static int serial_pnp_resume(struct pnp_dev *dev)
498{
499 long line = (long)pnp_get_drvdata(dev);
500
501 if (!line)
502 return -ENODEV;
503 serial8250_resume_port(line - 1);
504 return 0;
505}
506#else
507#define serial_pnp_suspend NULL
508#define serial_pnp_resume NULL
509#endif /* CONFIG_PM */
510
511static struct pnp_driver serial_pnp_driver = {
512 .name = "serial",
513 .probe = serial_pnp_probe,
514 .remove = serial_pnp_remove,
515 .suspend = serial_pnp_suspend,
516 .resume = serial_pnp_resume,
517 .id_table = pnp_dev_table,
518};
519
520int serial8250_pnp_init(void)
521{
522 return pnp_register_driver(&serial_pnp_driver);
523}
524
525void serial8250_pnp_exit(void)
526{
527 pnp_unregister_driver(&serial_pnp_driver);
528}
529
diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
deleted file mode 100644
index c31133a6ea8..00000000000
--- a/drivers/tty/serial/8250/Kconfig
+++ /dev/null
@@ -1,279 +0,0 @@
1#
2# The 8250/16550 serial drivers. You shouldn't be in this list unless
3# you somehow have an implicit or explicit dependency on SERIAL_8250.
4#
5
6config SERIAL_8250
7 tristate "8250/16550 and compatible serial support"
8 select SERIAL_CORE
9 ---help---
10 This selects whether you want to include the driver for the standard
11 serial ports. The standard answer is Y. People who might say N
12 here are those that are setting up dedicated Ethernet WWW/FTP
13 servers, or users that have one of the various bus mice instead of a
14 serial mouse and don't intend to use their machine's standard serial
15 port for anything. (Note that the Cyclades and Stallion multi
16 serial port drivers do not need this driver built in for them to
17 work.)
18
19 To compile this driver as a module, choose M here: the
20 module will be called 8250.
21 [WARNING: Do not compile this driver as a module if you are using
22 non-standard serial ports, since the configuration information will
23 be lost when the driver is unloaded. This limitation may be lifted
24 in the future.]
25
26 BTW1: If you have a mouseman serial mouse which is not recognized by
27 the X window system, try running gpm first.
28
29 BTW2: If you intend to use a software modem (also called Winmodem)
30 under Linux, forget it. These modems are crippled and require
31 proprietary drivers which are only available under Windows.
32
33 Most people will say Y or M here, so that they can use serial mice,
34 modems and similar devices connecting to the standard serial ports.
35
36config SERIAL_8250_PNP
37 bool "8250/16550 PNP device support" if EXPERT
38 depends on SERIAL_8250 && PNP
39 default y
40 ---help---
41 This builds standard PNP serial support. You may be able to
42 disable this feature if you only need legacy serial support.
43
44config SERIAL_8250_CONSOLE
45 bool "Console on 8250/16550 and compatible serial port"
46 depends on SERIAL_8250=y
47 select SERIAL_CORE_CONSOLE
48 ---help---
49 If you say Y here, it will be possible to use a serial port as the
50 system console (the system console is the device which receives all
51 kernel messages and warnings and which allows logins in single user
52 mode). This could be useful if some terminal or printer is connected
53 to that serial port.
54
55 Even if you say Y here, the currently visible virtual console
56 (/dev/tty0) will still be used as the system console by default, but
57 you can alter that using a kernel command line option such as
58 "console=ttyS1". (Try "man bootparam" or see the documentation of
59 your boot loader (grub or lilo or loadlin) about how to pass options
60 to the kernel at boot time.)
61
62 If you don't have a VGA card installed and you say Y here, the
63 kernel will automatically use the first serial line, /dev/ttyS0, as
64 system console.
65
66 You can set that using a kernel command line option such as
67 "console=uart8250,io,0x3f8,9600n8"
68 "console=uart8250,mmio,0xff5e0000,115200n8".
69 and it will switch to normal serial console when the corresponding
70 port is ready.
71 "earlycon=uart8250,io,0x3f8,9600n8"
72 "earlycon=uart8250,mmio,0xff5e0000,115200n8".
73 it will not only setup early console.
74
75 If unsure, say N.
76
77config FIX_EARLYCON_MEM
78 bool
79 depends on X86
80 default y
81
82config SERIAL_8250_GSC
83 tristate
84 depends on SERIAL_8250 && GSC
85 default SERIAL_8250
86
87config SERIAL_8250_PCI
88 tristate "8250/16550 PCI device support" if EXPERT
89 depends on SERIAL_8250 && PCI
90 default SERIAL_8250
91 help
92 This builds standard PCI serial support. You may be able to
93 disable this feature if you only need legacy serial support.
94 Saves about 9K.
95
96config SERIAL_8250_HP300
97 tristate
98 depends on SERIAL_8250 && HP300
99 default SERIAL_8250
100
101config SERIAL_8250_CS
102 tristate "8250/16550 PCMCIA device support"
103 depends on PCMCIA && SERIAL_8250
104 ---help---
105 Say Y here to enable support for 16-bit PCMCIA serial devices,
106 including serial port cards, modems, and the modem functions of
107 multi-function Ethernet/modem cards. (PCMCIA- or PC-cards are
108 credit-card size devices often used with laptops.)
109
110 To compile this driver as a module, choose M here: the
111 module will be called serial_cs.
112
113 If unsure, say N.
114
115config SERIAL_8250_NR_UARTS
116 int "Maximum number of 8250/16550 serial ports"
117 depends on SERIAL_8250
118 default "4"
119 help
120 Set this to the number of serial ports you want the driver
121 to support. This includes any ports discovered via ACPI or
122 PCI enumeration and any ports that may be added at run-time
123 via hot-plug, or any ISA multi-port serial cards.
124
125config SERIAL_8250_RUNTIME_UARTS
126 int "Number of 8250/16550 serial ports to register at runtime"
127 depends on SERIAL_8250
128 range 0 SERIAL_8250_NR_UARTS
129 default "4"
130 help
131 Set this to the maximum number of serial ports you want
132 the kernel to register at boot time. This can be overridden
133 with the module parameter "nr_uarts", or boot-time parameter
134 8250.nr_uarts
135
136config SERIAL_8250_EXTENDED
137 bool "Extended 8250/16550 serial driver options"
138 depends on SERIAL_8250
139 help
140 If you wish to use any non-standard features of the standard "dumb"
141 driver, say Y here. This includes HUB6 support, shared serial
142 interrupts, special multiport support, support for more than the
143 four COM 1/2/3/4 boards, etc.
144
145 Note that the answer to this question won't directly affect the
146 kernel: saying N will just cause the configurator to skip all
147 the questions about serial driver options. If unsure, say N.
148
149config SERIAL_8250_MANY_PORTS
150 bool "Support more than 4 legacy serial ports"
151 depends on SERIAL_8250_EXTENDED && !IA64
152 help
153 Say Y here if you have dumb serial boards other than the four
154 standard COM 1/2/3/4 ports. This may happen if you have an AST
155 FourPort, Accent Async, Boca (read the Boca mini-HOWTO, available
156 from <http://www.tldp.org/docs.html#howto>), or other custom
157 serial port hardware which acts similar to standard serial port
158 hardware. If you only use the standard COM 1/2/3/4 ports, you can
159 say N here to save some memory. You can also say Y if you have an
160 "intelligent" multiport card such as Cyclades, Digiboards, etc.
161
162#
163# Multi-port serial cards
164#
165
166config SERIAL_8250_FOURPORT
167 tristate "Support Fourport cards"
168 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
169 help
170 Say Y here if you have an AST FourPort serial board.
171
172 To compile this driver as a module, choose M here: the module
173 will be called 8250_fourport.
174
175config SERIAL_8250_ACCENT
176 tristate "Support Accent cards"
177 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
178 help
179 Say Y here if you have an Accent Async serial board.
180
181 To compile this driver as a module, choose M here: the module
182 will be called 8250_accent.
183
184config SERIAL_8250_BOCA
185 tristate "Support Boca cards"
186 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
187 help
188 Say Y here if you have a Boca serial board. Please read the Boca
189 mini-HOWTO, available from <http://www.tldp.org/docs.html#howto>
190
191 To compile this driver as a module, choose M here: the module
192 will be called 8250_boca.
193
194config SERIAL_8250_EXAR_ST16C554
195 tristate "Support Exar ST16C554/554D Quad UART"
196 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
197 help
198 The Uplogix Envoy TU301 uses this Exar Quad UART. If you are
199 tinkering with your Envoy TU301, or have a machine with this UART,
200 say Y here.
201
202 To compile this driver as a module, choose M here: the module
203 will be called 8250_exar_st16c554.
204
205config SERIAL_8250_HUB6
206 tristate "Support Hub6 cards"
207 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
208 help
209 Say Y here if you have a HUB6 serial board.
210
211 To compile this driver as a module, choose M here: the module
212 will be called 8250_hub6.
213
214#
215# Misc. options/drivers.
216#
217
218config SERIAL_8250_SHARE_IRQ
219 bool "Support for sharing serial interrupts"
220 depends on SERIAL_8250_EXTENDED
221 help
222 Some serial boards have hardware support which allows multiple dumb
223 serial ports on the same board to share a single IRQ. To enable
224 support for this in the serial driver, say Y here.
225
226config SERIAL_8250_DETECT_IRQ
227 bool "Autodetect IRQ on standard ports (unsafe)"
228 depends on SERIAL_8250_EXTENDED
229 help
230 Say Y here if you want the kernel to try to guess which IRQ
231 to use for your serial port.
232
233 This is considered unsafe; it is far better to configure the IRQ in
234 a boot script using the setserial command.
235
236 If unsure, say N.
237
238config SERIAL_8250_RSA
239 bool "Support RSA serial ports"
240 depends on SERIAL_8250_EXTENDED
241 help
242 ::: To be written :::
243
244config SERIAL_8250_ACORN
245 tristate "Acorn expansion card serial port support"
246 depends on ARCH_ACORN && SERIAL_8250
247 help
248 If you have an Atomwide Serial card or Serial Port card for an Acorn
249 system, say Y to this option. The driver can handle 1, 2, or 3 port
250 cards. If unsure, say N.
251
252config SERIAL_8250_RM9K
253 bool "Support for MIPS RM9xxx integrated serial port"
254 depends on SERIAL_8250 != n && SERIAL_RM9000
255 select SERIAL_8250_SHARE_IRQ
256 help
257 Selecting this option will add support for the integrated serial
258 port hardware found on MIPS RM9122 and similar processors.
259 If unsure, say N.
260
261config SERIAL_8250_FSL
262 bool
263 depends on SERIAL_8250_CONSOLE && PPC_UDBG_16550
264 default PPC
265
266config SERIAL_8250_DW
267 tristate "Support for Synopsys DesignWare 8250 quirks"
268 depends on SERIAL_8250 && OF
269 help
270 Selecting this option will enable handling of the extra features
271 present in the Synopsys DesignWare APB UART.
272
273config SERIAL_8250_EM
274 tristate "Support for Emma Mobile integrated serial port"
275 depends on SERIAL_8250 && ARM && HAVE_CLK
276 help
277 Selecting this option will add support for the integrated serial
278 port hardware found on the Emma Mobile line of processors.
279 If unsure, say N.
diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile
deleted file mode 100644
index 108fe7fe13e..00000000000
--- a/drivers/tty/serial/8250/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
1#
2# Makefile for the 8250 serial device drivers.
3#
4
5obj-$(CONFIG_SERIAL_8250) += 8250_core.o
68250_core-y := 8250.o
78250_core-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o
8obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o
9obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o
10obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o
11obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o
12obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o
13obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o
14obj-$(CONFIG_SERIAL_8250_FOURPORT) += 8250_fourport.o
15obj-$(CONFIG_SERIAL_8250_ACCENT) += 8250_accent.o
16obj-$(CONFIG_SERIAL_8250_BOCA) += 8250_boca.o
17obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o
18obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o
19obj-$(CONFIG_SERIAL_8250_FSL) += 8250_fsl.o
20obj-$(CONFIG_SERIAL_8250_DW) += 8250_dw.o
21obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o
diff --git a/drivers/tty/serial/8250/serial_cs.c b/drivers/tty/serial/8250/serial_cs.c
deleted file mode 100644
index b7d48b34639..00000000000
--- a/drivers/tty/serial/8250/serial_cs.c
+++ /dev/null
@@ -1,869 +0,0 @@
1/*======================================================================
2
3 A driver for PCMCIA serial devices
4
5 serial_cs.c 1.134 2002/05/04 05:48:53
6
7 The contents of this file are subject to the Mozilla Public
8 License Version 1.1 (the "License"); you may not use this file
9 except in compliance with the License. You may obtain a copy of
10 the License at http://www.mozilla.org/MPL/
11
12 Software distributed under the License is distributed on an "AS
13 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 implied. See the License for the specific language governing
15 rights and limitations under the License.
16
17 The initial developer of the original code is David A. Hinds
18 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
19 are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
20
21 Alternatively, the contents of this file may be used under the
22 terms of the GNU General Public License version 2 (the "GPL"), in which
23 case the provisions of the GPL are applicable instead of the
24 above. If you wish to allow the use of your version of this file
25 only under the terms of the GPL and not to allow others to use
26 your version of this file under the MPL, indicate your decision
27 by deleting the provisions above and replace them with the notice
28 and other provisions required by the GPL. If you do not delete
29 the provisions above, a recipient may use your version of this
30 file under either the MPL or the GPL.
31
32======================================================================*/
33
34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/kernel.h>
37#include <linux/init.h>
38#include <linux/ptrace.h>
39#include <linux/slab.h>
40#include <linux/string.h>
41#include <linux/timer.h>
42#include <linux/serial_core.h>
43#include <linux/delay.h>
44#include <linux/major.h>
45#include <asm/io.h>
46
47#include <pcmcia/cistpl.h>
48#include <pcmcia/ciscode.h>
49#include <pcmcia/ds.h>
50#include <pcmcia/cisreg.h>
51
52#include "8250.h"
53
54
55/*====================================================================*/
56
57/* Parameters that can be set with 'insmod' */
58
59/* Enable the speaker? */
60static int do_sound = 1;
61/* Skip strict UART tests? */
62static int buggy_uart;
63
64module_param(do_sound, int, 0444);
65module_param(buggy_uart, int, 0444);
66
67/*====================================================================*/
68
69/* Table of multi-port card ID's */
70
71struct serial_quirk {
72 unsigned int manfid;
73 unsigned int prodid;
74 int multi; /* 1 = multifunction, > 1 = # ports */
75 void (*config)(struct pcmcia_device *);
76 void (*setup)(struct pcmcia_device *, struct uart_8250_port *);
77 void (*wakeup)(struct pcmcia_device *);
78 int (*post)(struct pcmcia_device *);
79};
80
81struct serial_info {
82 struct pcmcia_device *p_dev;
83 int ndev;
84 int multi;
85 int slave;
86 int manfid;
87 int prodid;
88 int c950ctrl;
89 int line[4];
90 const struct serial_quirk *quirk;
91};
92
93struct serial_cfg_mem {
94 tuple_t tuple;
95 cisparse_t parse;
96 u_char buf[256];
97};
98
99/*
100 * vers_1 5.0, "Brain Boxes", "2-Port RS232 card", "r6"
101 * manfid 0x0160, 0x0104
102 * This card appears to have a 14.7456MHz clock.
103 */
104/* Generic Modem: MD55x (GPRS/EDGE) have
105 * Elan VPU16551 UART with 14.7456MHz oscillator
106 * manfid 0x015D, 0x4C45
107 */
108static void quirk_setup_brainboxes_0104(struct pcmcia_device *link, struct uart_8250_port *uart)
109{
110 uart->port.uartclk = 14745600;
111}
112
113static int quirk_post_ibm(struct pcmcia_device *link)
114{
115 u8 val;
116 int ret;
117
118 ret = pcmcia_read_config_byte(link, 0x800, &val);
119 if (ret)
120 goto failed;
121
122 ret = pcmcia_write_config_byte(link, 0x800, val | 1);
123 if (ret)
124 goto failed;
125 return 0;
126
127 failed:
128 return -ENODEV;
129}
130
131/*
132 * Nokia cards are not really multiport cards. Shouldn't this
133 * be handled by setting the quirk entry .multi = 0 | 1 ?
134 */
135static void quirk_config_nokia(struct pcmcia_device *link)
136{
137 struct serial_info *info = link->priv;
138
139 if (info->multi > 1)
140 info->multi = 1;
141}
142
143static void quirk_wakeup_oxsemi(struct pcmcia_device *link)
144{
145 struct serial_info *info = link->priv;
146
147 if (info->c950ctrl)
148 outb(12, info->c950ctrl + 1);
149}
150
151/* request_region? oxsemi branch does no request_region too... */
152/*
153 * This sequence is needed to properly initialize MC45 attached to OXCF950.
154 * I tried decreasing these msleep()s, but it worked properly (survived
155 * 1000 stop/start operations) with these timeouts (or bigger).
156 */
157static void quirk_wakeup_possio_gcc(struct pcmcia_device *link)
158{
159 struct serial_info *info = link->priv;
160 unsigned int ctrl = info->c950ctrl;
161
162 outb(0xA, ctrl + 1);
163 msleep(100);
164 outb(0xE, ctrl + 1);
165 msleep(300);
166 outb(0xC, ctrl + 1);
167 msleep(100);
168 outb(0xE, ctrl + 1);
169 msleep(200);
170 outb(0xF, ctrl + 1);
171 msleep(100);
172 outb(0xE, ctrl + 1);
173 msleep(100);
174 outb(0xC, ctrl + 1);
175}
176
177/*
178 * Socket Dual IO: this enables irq's for second port
179 */
180static void quirk_config_socket(struct pcmcia_device *link)
181{
182 struct serial_info *info = link->priv;
183
184 if (info->multi)
185 link->config_flags |= CONF_ENABLE_ESR;
186}
187
188static const struct serial_quirk quirks[] = {
189 {
190 .manfid = 0x0160,
191 .prodid = 0x0104,
192 .multi = -1,
193 .setup = quirk_setup_brainboxes_0104,
194 }, {
195 .manfid = 0x015D,
196 .prodid = 0x4C45,
197 .multi = -1,
198 .setup = quirk_setup_brainboxes_0104,
199 }, {
200 .manfid = MANFID_IBM,
201 .prodid = ~0,
202 .multi = -1,
203 .post = quirk_post_ibm,
204 }, {
205 .manfid = MANFID_INTEL,
206 .prodid = PRODID_INTEL_DUAL_RS232,
207 .multi = 2,
208 }, {
209 .manfid = MANFID_NATINST,
210 .prodid = PRODID_NATINST_QUAD_RS232,
211 .multi = 4,
212 }, {
213 .manfid = MANFID_NOKIA,
214 .prodid = ~0,
215 .multi = -1,
216 .config = quirk_config_nokia,
217 }, {
218 .manfid = MANFID_OMEGA,
219 .prodid = PRODID_OMEGA_QSP_100,
220 .multi = 4,
221 }, {
222 .manfid = MANFID_OXSEMI,
223 .prodid = ~0,
224 .multi = -1,
225 .wakeup = quirk_wakeup_oxsemi,
226 }, {
227 .manfid = MANFID_POSSIO,
228 .prodid = PRODID_POSSIO_GCC,
229 .multi = -1,
230 .wakeup = quirk_wakeup_possio_gcc,
231 }, {
232 .manfid = MANFID_QUATECH,
233 .prodid = PRODID_QUATECH_DUAL_RS232,
234 .multi = 2,
235 }, {
236 .manfid = MANFID_QUATECH,
237 .prodid = PRODID_QUATECH_DUAL_RS232_D1,
238 .multi = 2,
239 }, {
240 .manfid = MANFID_QUATECH,
241 .prodid = PRODID_QUATECH_DUAL_RS232_G,
242 .multi = 2,
243 }, {
244 .manfid = MANFID_QUATECH,
245 .prodid = PRODID_QUATECH_QUAD_RS232,
246 .multi = 4,
247 }, {
248 .manfid = MANFID_SOCKET,
249 .prodid = PRODID_SOCKET_DUAL_RS232,
250 .multi = 2,
251 .config = quirk_config_socket,
252 }, {
253 .manfid = MANFID_SOCKET,
254 .prodid = ~0,
255 .multi = -1,
256 .config = quirk_config_socket,
257 }
258};
259
260
261static int serial_config(struct pcmcia_device * link);
262
263
264static void serial_remove(struct pcmcia_device *link)
265{
266 struct serial_info *info = link->priv;
267 int i;
268
269 dev_dbg(&link->dev, "serial_release\n");
270
271 /*
272 * Recheck to see if the device is still configured.
273 */
274 for (i = 0; i < info->ndev; i++)
275 serial8250_unregister_port(info->line[i]);
276
277 if (!info->slave)
278 pcmcia_disable_device(link);
279}
280
281static int serial_suspend(struct pcmcia_device *link)
282{
283 struct serial_info *info = link->priv;
284 int i;
285
286 for (i = 0; i < info->ndev; i++)
287 serial8250_suspend_port(info->line[i]);
288
289 return 0;
290}
291
292static int serial_resume(struct pcmcia_device *link)
293{
294 struct serial_info *info = link->priv;
295 int i;
296
297 for (i = 0; i < info->ndev; i++)
298 serial8250_resume_port(info->line[i]);
299
300 if (info->quirk && info->quirk->wakeup)
301 info->quirk->wakeup(link);
302
303 return 0;
304}
305
306static int serial_probe(struct pcmcia_device *link)
307{
308 struct serial_info *info;
309
310 dev_dbg(&link->dev, "serial_attach()\n");
311
312 /* Create new serial device */
313 info = kzalloc(sizeof (*info), GFP_KERNEL);
314 if (!info)
315 return -ENOMEM;
316 info->p_dev = link;
317 link->priv = info;
318
319 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
320 if (do_sound)
321 link->config_flags |= CONF_ENABLE_SPKR;
322
323 return serial_config(link);
324}
325
326static void serial_detach(struct pcmcia_device *link)
327{
328 struct serial_info *info = link->priv;
329
330 dev_dbg(&link->dev, "serial_detach\n");
331
332 /*
333 * Ensure that the ports have been released.
334 */
335 serial_remove(link);
336
337 /* free bits */
338 kfree(info);
339}
340
341/*====================================================================*/
342
343static int setup_serial(struct pcmcia_device *handle, struct serial_info * info,
344 unsigned int iobase, int irq)
345{
346 struct uart_8250_port uart;
347 int line;
348
349 memset(&uart, 0, sizeof(uart));
350 uart.port.iobase = iobase;
351 uart.port.irq = irq;
352 uart.port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ;
353 uart.port.uartclk = 1843200;
354 uart.port.dev = &handle->dev;
355 if (buggy_uart)
356 uart.port.flags |= UPF_BUGGY_UART;
357
358 if (info->quirk && info->quirk->setup)
359 info->quirk->setup(handle, &uart);
360
361 line = serial8250_register_8250_port(&uart);
362 if (line < 0) {
363 pr_err("serial_cs: serial8250_register_8250_port() at 0x%04lx, irq %d failed\n",
364 (unsigned long)iobase, irq);
365 return -EINVAL;
366 }
367
368 info->line[info->ndev] = line;
369 info->ndev++;
370
371 return 0;
372}
373
374/*====================================================================*/
375
376static int pfc_config(struct pcmcia_device *p_dev)
377{
378 unsigned int port = 0;
379 struct serial_info *info = p_dev->priv;
380
381 if ((p_dev->resource[1]->end != 0) &&
382 (resource_size(p_dev->resource[1]) == 8)) {
383 port = p_dev->resource[1]->start;
384 info->slave = 1;
385 } else if ((info->manfid == MANFID_OSITECH) &&
386 (resource_size(p_dev->resource[0]) == 0x40)) {
387 port = p_dev->resource[0]->start + 0x28;
388 info->slave = 1;
389 }
390 if (info->slave)
391 return setup_serial(p_dev, info, port, p_dev->irq);
392
393 dev_warn(&p_dev->dev, "no usable port range found, giving up\n");
394 return -ENODEV;
395}
396
397static int simple_config_check(struct pcmcia_device *p_dev, void *priv_data)
398{
399 static const int size_table[2] = { 8, 16 };
400 int *try = priv_data;
401
402 if (p_dev->resource[0]->start == 0)
403 return -ENODEV;
404
405 if ((*try & 0x1) == 0)
406 p_dev->io_lines = 16;
407
408 if (p_dev->resource[0]->end != size_table[(*try >> 1)])
409 return -ENODEV;
410
411 p_dev->resource[0]->end = 8;
412 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
413 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
414
415 return pcmcia_request_io(p_dev);
416}
417
418static int simple_config_check_notpicky(struct pcmcia_device *p_dev,
419 void *priv_data)
420{
421 static const unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
422 int j;
423
424 if (p_dev->io_lines > 3)
425 return -ENODEV;
426
427 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
428 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
429 p_dev->resource[0]->end = 8;
430
431 for (j = 0; j < 5; j++) {
432 p_dev->resource[0]->start = base[j];
433 p_dev->io_lines = base[j] ? 16 : 3;
434 if (!pcmcia_request_io(p_dev))
435 return 0;
436 }
437 return -ENODEV;
438}
439
440static int simple_config(struct pcmcia_device *link)
441{
442 struct serial_info *info = link->priv;
443 int i = -ENODEV, try;
444
445 /* First pass: look for a config entry that looks normal.
446 * Two tries: without IO aliases, then with aliases */
447 link->config_flags |= CONF_AUTO_SET_VPP;
448 for (try = 0; try < 4; try++)
449 if (!pcmcia_loop_config(link, simple_config_check, &try))
450 goto found_port;
451
452 /* Second pass: try to find an entry that isn't picky about
453 its base address, then try to grab any standard serial port
454 address, and finally try to get any free port. */
455 if (!pcmcia_loop_config(link, simple_config_check_notpicky, NULL))
456 goto found_port;
457
458 dev_warn(&link->dev, "no usable port range found, giving up\n");
459 return -1;
460
461found_port:
462 if (info->multi && (info->manfid == MANFID_3COM))
463 link->config_index &= ~(0x08);
464
465 /*
466 * Apply any configuration quirks.
467 */
468 if (info->quirk && info->quirk->config)
469 info->quirk->config(link);
470
471 i = pcmcia_enable_device(link);
472 if (i != 0)
473 return -1;
474 return setup_serial(link, info, link->resource[0]->start, link->irq);
475}
476
477static int multi_config_check(struct pcmcia_device *p_dev, void *priv_data)
478{
479 int *multi = priv_data;
480
481 if (p_dev->resource[1]->end)
482 return -EINVAL;
483
484 /* The quad port cards have bad CIS's, so just look for a
485 window larger than 8 ports and assume it will be right */
486 if (p_dev->resource[0]->end <= 8)
487 return -EINVAL;
488
489 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
490 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
491 p_dev->resource[0]->end = *multi * 8;
492
493 if (pcmcia_request_io(p_dev))
494 return -ENODEV;
495 return 0;
496}
497
498static int multi_config_check_notpicky(struct pcmcia_device *p_dev,
499 void *priv_data)
500{
501 int *base2 = priv_data;
502
503 if (!p_dev->resource[0]->end || !p_dev->resource[1]->end ||
504 p_dev->resource[0]->start + 8 != p_dev->resource[1]->start)
505 return -ENODEV;
506
507 p_dev->resource[0]->end = p_dev->resource[1]->end = 8;
508 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
509 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
510
511 if (pcmcia_request_io(p_dev))
512 return -ENODEV;
513
514 *base2 = p_dev->resource[0]->start + 8;
515 return 0;
516}
517
518static int multi_config(struct pcmcia_device *link)
519{
520 struct serial_info *info = link->priv;
521 int i, base2 = 0;
522
523 /* First, look for a generic full-sized window */
524 if (!pcmcia_loop_config(link, multi_config_check, &info->multi))
525 base2 = link->resource[0]->start + 8;
526 else {
527 /* If that didn't work, look for two windows */
528 info->multi = 2;
529 if (pcmcia_loop_config(link, multi_config_check_notpicky,
530 &base2)) {
531 dev_warn(&link->dev, "no usable port range "
532 "found, giving up\n");
533 return -ENODEV;
534 }
535 }
536
537 if (!link->irq)
538 dev_warn(&link->dev, "no usable IRQ found, continuing...\n");
539
540 /*
541 * Apply any configuration quirks.
542 */
543 if (info->quirk && info->quirk->config)
544 info->quirk->config(link);
545
546 i = pcmcia_enable_device(link);
547 if (i != 0)
548 return -ENODEV;
549
550 /* The Oxford Semiconductor OXCF950 cards are in fact single-port:
551 * 8 registers are for the UART, the others are extra registers.
552 * Siemen's MC45 PCMCIA (Possio's GCC) is OXCF950 based too.
553 */
554 if (info->manfid == MANFID_OXSEMI || (info->manfid == MANFID_POSSIO &&
555 info->prodid == PRODID_POSSIO_GCC)) {
556 int err;
557
558 if (link->config_index == 1 ||
559 link->config_index == 3) {
560 err = setup_serial(link, info, base2,
561 link->irq);
562 base2 = link->resource[0]->start;
563 } else {
564 err = setup_serial(link, info, link->resource[0]->start,
565 link->irq);
566 }
567 info->c950ctrl = base2;
568
569 /*
570 * FIXME: We really should wake up the port prior to
571 * handing it over to the serial layer.
572 */
573 if (info->quirk && info->quirk->wakeup)
574 info->quirk->wakeup(link);
575
576 return 0;
577 }
578
579 setup_serial(link, info, link->resource[0]->start, link->irq);
580 for (i = 0; i < info->multi - 1; i++)
581 setup_serial(link, info, base2 + (8 * i),
582 link->irq);
583 return 0;
584}
585
586static int serial_check_for_multi(struct pcmcia_device *p_dev, void *priv_data)
587{
588 struct serial_info *info = p_dev->priv;
589
590 if (!p_dev->resource[0]->end)
591 return -EINVAL;
592
593 if ((!p_dev->resource[1]->end) && (p_dev->resource[0]->end % 8 == 0))
594 info->multi = p_dev->resource[0]->end >> 3;
595
596 if ((p_dev->resource[1]->end) && (p_dev->resource[0]->end == 8)
597 && (p_dev->resource[1]->end == 8))
598 info->multi = 2;
599
600 return 0; /* break */
601}
602
603
604static int serial_config(struct pcmcia_device * link)
605{
606 struct serial_info *info = link->priv;
607 int i;
608
609 dev_dbg(&link->dev, "serial_config\n");
610
611 /* Is this a compliant multifunction card? */
612 info->multi = (link->socket->functions > 1);
613
614 /* Is this a multiport card? */
615 info->manfid = link->manf_id;
616 info->prodid = link->card_id;
617
618 for (i = 0; i < ARRAY_SIZE(quirks); i++)
619 if ((quirks[i].manfid == ~0 ||
620 quirks[i].manfid == info->manfid) &&
621 (quirks[i].prodid == ~0 ||
622 quirks[i].prodid == info->prodid)) {
623 info->quirk = &quirks[i];
624 break;
625 }
626
627 /* Another check for dual-serial cards: look for either serial or
628 multifunction cards that ask for appropriate IO port ranges */
629 if ((info->multi == 0) &&
630 (link->has_func_id) &&
631 (link->socket->pcmcia_pfc == 0) &&
632 ((link->func_id == CISTPL_FUNCID_MULTI) ||
633 (link->func_id == CISTPL_FUNCID_SERIAL)))
634 pcmcia_loop_config(link, serial_check_for_multi, info);
635
636 /*
637 * Apply any multi-port quirk.
638 */
639 if (info->quirk && info->quirk->multi != -1)
640 info->multi = info->quirk->multi;
641
642 dev_info(&link->dev,
643 "trying to set up [0x%04x:0x%04x] (pfc: %d, multi: %d, quirk: %p)\n",
644 link->manf_id, link->card_id,
645 link->socket->pcmcia_pfc, info->multi, info->quirk);
646 if (link->socket->pcmcia_pfc)
647 i = pfc_config(link);
648 else if (info->multi > 1)
649 i = multi_config(link);
650 else
651 i = simple_config(link);
652
653 if (i || info->ndev == 0)
654 goto failed;
655
656 /*
657 * Apply any post-init quirk. FIXME: This should really happen
658 * before we register the port, since it might already be in use.
659 */
660 if (info->quirk && info->quirk->post)
661 if (info->quirk->post(link))
662 goto failed;
663
664 return 0;
665
666failed:
667 dev_warn(&link->dev, "failed to initialize\n");
668 serial_remove(link);
669 return -ENODEV;
670}
671
672static const struct pcmcia_device_id serial_ids[] = {
673 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0057, 0x0021),
674 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0089, 0x110a),
675 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0104, 0x000a),
676 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0x0d0a),
677 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0x0e0a),
678 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0105, 0xea15),
679 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0109, 0x0501),
680 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0138, 0x110a),
681 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0140, 0x000a),
682 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0143, 0x3341),
683 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0143, 0xc0ab),
684 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x016c, 0x0081),
685 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x021b, 0x0101),
686 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x08a1, 0xc0ab),
687 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "CC/XJEM3288", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x04cd2988, 0x46a52d63),
688 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "CC/XJEM3336", "DATA/FAX/CELL ETHERNET MODEM", 0xf510db04, 0x0143b773, 0x46a52d63),
689 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "EM1144T", "PCMCIA MODEM", 0xf510db04, 0x856d66c8, 0xbd6c43ef),
690 PCMCIA_PFC_DEVICE_PROD_ID123(1, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
691 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM28", 0x2e3ee845, 0x0ea978ea),
692 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM33", 0x2e3ee845, 0x80609023),
693 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
694 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
695 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
696 PCMCIA_PFC_DEVICE_PROD_ID12(1, "AnyCom", "Fast Ethernet + 56K COMBO", 0x578ba6e7, 0xb0ac62c4),
697 PCMCIA_PFC_DEVICE_PROD_ID12(1, "ATKK", "LM33-PCM-T", 0xba9eb7e2, 0x077c174e),
698 PCMCIA_PFC_DEVICE_PROD_ID12(1, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
699 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
700 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
701 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
702 PCMCIA_PFC_DEVICE_PROD_ID12(1, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58),
703 PCMCIA_PFC_DEVICE_PROD_ID12(1, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
704 PCMCIA_PFC_DEVICE_PROD_ID12(1, "MICRO RESEARCH", "COMBO-L/M-336", 0xb2ced065, 0x3ced0555),
705 PCMCIA_PFC_DEVICE_PROD_ID12(1, "NEC", "PK-UG-J001" ,0x18df0ba0 ,0x831b1064),
706 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
707 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
708 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
709 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f),
710 PCMCIA_PFC_DEVICE_PROD_ID12(1, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
711 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
712 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0032, 0x0e01),
713 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0032, 0x0a05),
714 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0032, 0x0b05),
715 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0032, 0x1101),
716 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0104, 0x0070),
717 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0101, 0x0562),
718 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0104, 0x0070),
719 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x016c, 0x0020),
720 PCMCIA_MFC_DEVICE_PROD_ID123(1, "APEX DATA", "MULTICARD", "ETHERNET-MODEM", 0x11c2da09, 0x7289dc5d, 0xaad95e1f),
721 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "Home and Away 28.8 PC Card ", 0xb569a6e5, 0x5bd4ff2c),
722 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "Home and Away Credit Card Adapter", 0xb569a6e5, 0x4bdf15c3),
723 PCMCIA_MFC_DEVICE_PROD_ID12(1, "IBM", "w95 Home and Away Credit Card ", 0xb569a6e5, 0xae911c15),
724 PCMCIA_MFC_DEVICE_PROD_ID1(1, "Motorola MARQUIS", 0xf03e4e77),
725 PCMCIA_MFC_DEVICE_PROD_ID2(1, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
726 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0301),
727 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x0276),
728 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0039),
729 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0006),
730 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x0101), /* TDK DF2814 */
731 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x100a), /* Xircom CM-56G */
732 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x3e0a), /* TDK DF5660 */
733 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x410a),
734 PCMCIA_DEVICE_MANF_CARD(0x0107, 0x0002), /* USRobotics 14,400 */
735 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d50),
736 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d51),
737 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d52),
738 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0d53),
739 PCMCIA_DEVICE_MANF_CARD(0x010b, 0xd180),
740 PCMCIA_DEVICE_MANF_CARD(0x0115, 0x3330), /* USRobotics/SUN 14,400 */
741 PCMCIA_DEVICE_MANF_CARD(0x0124, 0x0100), /* Nokia DTP-2 ver II */
742 PCMCIA_DEVICE_MANF_CARD(0x0134, 0x5600), /* LASAT COMMUNICATIONS A/S */
743 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x000e),
744 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x001b),
745 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0025),
746 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0045),
747 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0052),
748 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0006), /* Psion 56K+Fax */
749 PCMCIA_DEVICE_MANF_CARD(0x0200, 0x0001), /* MultiMobile */
750 PCMCIA_DEVICE_PROD_ID134("ADV", "TECH", "COMpad-32/85", 0x67459937, 0x916d02ba, 0x8fbe92ae),
751 PCMCIA_DEVICE_PROD_ID124("GATEWAY2000", "CC3144", "PCMCIA MODEM", 0x506bccae, 0xcb3685f1, 0xbd6c43ef),
752 PCMCIA_DEVICE_PROD_ID14("MEGAHERTZ", "PCMCIA MODEM", 0xf510db04, 0xbd6c43ef),
753 PCMCIA_DEVICE_PROD_ID124("TOSHIBA", "T144PF", "PCMCIA MODEM", 0xb4585a1a, 0x7271409c, 0xbd6c43ef),
754 PCMCIA_DEVICE_PROD_ID123("FUJITSU", "FC14F ", "MBH10213", 0x6ee5a3d8, 0x30ead12b, 0xb00f05a0),
755 PCMCIA_DEVICE_PROD_ID123("Novatel Wireless", "Merlin UMTS Modem", "U630", 0x32607776, 0xd9e73b13, 0xe87332e),
756 PCMCIA_DEVICE_PROD_ID13("MEGAHERTZ", "V.34 PCMCIA MODEM", 0xf510db04, 0xbb2cce4a),
757 PCMCIA_DEVICE_PROD_ID12("Brain Boxes", "Bluetooth PC Card", 0xee138382, 0xd4ce9b02),
758 PCMCIA_DEVICE_PROD_ID12("CIRRUS LOGIC", "FAX MODEM", 0xe625f451, 0xcecd6dfa),
759 PCMCIA_DEVICE_PROD_ID12("COMPAQ", "PCMCIA 28800 FAX/DATA MODEM", 0xa3a3062c, 0x8cbd7c76),
760 PCMCIA_DEVICE_PROD_ID12("COMPAQ", "PCMCIA 33600 FAX/DATA MODEM", 0xa3a3062c, 0x5a00ce95),
761 PCMCIA_DEVICE_PROD_ID12("Computerboards, Inc.", "PCM-COM422", 0xd0b78f51, 0x7e2d49ed),
762 PCMCIA_DEVICE_PROD_ID12("Dr. Neuhaus", "FURY CARD 14K4", 0x76942813, 0x8b96ce65),
763 PCMCIA_DEVICE_PROD_ID12("IBM", "ISDN/56K/GSM", 0xb569a6e5, 0xfee5297b),
764 PCMCIA_DEVICE_PROD_ID12("Intelligent", "ANGIA FAX/MODEM", 0xb496e65e, 0xf31602a6),
765 PCMCIA_DEVICE_PROD_ID12("Intel", "MODEM 2400+", 0x816cc815, 0x412729fb),
766 PCMCIA_DEVICE_PROD_ID12("Intertex", "IX34-PCMCIA", 0xf8a097e3, 0x97880447),
767 PCMCIA_DEVICE_PROD_ID12("IOTech Inc ", "PCMCIA Dual RS-232 Serial Port Card", 0x3bd2d898, 0x92abc92f),
768 PCMCIA_DEVICE_PROD_ID12("MACRONIX", "FAX/MODEM", 0x668388b3, 0x3f9bdf2f),
769 PCMCIA_DEVICE_PROD_ID12("Multi-Tech", "MT1432LT", 0x5f73be51, 0x0b3e2383),
770 PCMCIA_DEVICE_PROD_ID12("Multi-Tech", "MT2834LT", 0x5f73be51, 0x4cd7c09e),
771 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a),
772 PCMCIA_DEVICE_PROD_ID12("Option International", "V34bis GSM/PSTN Data/Fax Modem", 0x9d7cd6f5, 0x5cb8bf41),
773 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab),
774 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f),
775 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "Dual RS-232 Serial Port PC Card", 0xc4420b35, 0x031a380d),
776 PCMCIA_DEVICE_PROD_ID12("Telia", "SurfinBird 560P/A+", 0xe2cdd5e, 0xc9314b38),
777 PCMCIA_DEVICE_PROD_ID1("Smart Serial Port", 0x2d8ce292),
778 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "cis/PCMLM28.cis"),
779 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "cis/PCMLM28.cis"),
780 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "cis/PCMLM28.cis"),
781 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet GSM", 0xf5f025c2, 0x4ae85d35, "cis/PCMLM28.cis"),
782 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "LINKSYS", "PCMLM28", 0xf7cb0b07, 0x66881874, "cis/PCMLM28.cis"),
783 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "TOSHIBA", "Modem/LAN Card", 0xb4585a1a, 0x53f922f8, "cis/PCMLM28.cis"),
784 PCMCIA_MFC_DEVICE_CIS_PROD_ID12(1, "DAYNA COMMUNICATIONS", "LAN AND MODEM MULTIFUNCTION", 0x8fdf8f89, 0xdd5ed9e8, "cis/DP83903.cis"),
785 PCMCIA_MFC_DEVICE_CIS_PROD_ID4(1, "NSC MF LAN/Modem", 0x58fc6056, "cis/DP83903.cis"),
786 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x0556, "cis/3CCFEM556.cis"),
787 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0175, 0x0000, "cis/DP83903.cis"),
788 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x0035, "cis/3CXEM556.cis"),
789 PCMCIA_MFC_DEVICE_CIS_MANF_CARD(1, 0x0101, 0x003d, "cis/3CXEM556.cis"),
790 PCMCIA_DEVICE_CIS_PROD_ID12("Sierra Wireless", "AC850", 0xd85f6206, 0x42a2c018, "cis/SW_8xx_SER.cis"), /* Sierra Wireless AC850 3G Network Adapter R1 */
791 PCMCIA_DEVICE_CIS_PROD_ID12("Sierra Wireless", "AC860", 0xd85f6206, 0x698f93db, "cis/SW_8xx_SER.cis"), /* Sierra Wireless AC860 3G Network Adapter R1 */
792 PCMCIA_DEVICE_CIS_PROD_ID12("Sierra Wireless", "AC710/AC750", 0xd85f6206, 0x761b11e0, "cis/SW_7xx_SER.cis"), /* Sierra Wireless AC710/AC750 GPRS Network Adapter R1 */
793 PCMCIA_DEVICE_CIS_MANF_CARD(0x0192, 0xa555, "cis/SW_555_SER.cis"), /* Sierra Aircard 555 CDMA 1xrtt Modem -- pre update */
794 PCMCIA_DEVICE_CIS_MANF_CARD(0x013f, 0xa555, "cis/SW_555_SER.cis"), /* Sierra Aircard 555 CDMA 1xrtt Modem -- post update */
795 PCMCIA_DEVICE_CIS_PROD_ID12("MultiTech", "PCMCIA 56K DataFax", 0x842047ee, 0xc2efcf03, "cis/MT5634ZLX.cis"),
796 PCMCIA_DEVICE_CIS_PROD_ID12("ADVANTECH", "COMpad-32/85B-2", 0x96913a85, 0x27ab5437, "cis/COMpad2.cis"),
797 PCMCIA_DEVICE_CIS_PROD_ID12("ADVANTECH", "COMpad-32/85B-4", 0x96913a85, 0xcec8f102, "cis/COMpad4.cis"),
798 PCMCIA_DEVICE_CIS_PROD_ID123("ADVANTECH", "COMpad-32/85", "1.0", 0x96913a85, 0x8fbe92ae, 0x0877b627, "cis/COMpad2.cis"),
799 PCMCIA_DEVICE_CIS_PROD_ID2("RS-COM 2P", 0xad20b156, "cis/RS-COM-2P.cis"),
800 PCMCIA_DEVICE_CIS_MANF_CARD(0x0013, 0x0000, "cis/GLOBETROTTER.cis"),
801 PCMCIA_DEVICE_PROD_ID12("ELAN DIGITAL SYSTEMS LTD, c1997.","SERIAL CARD: SL100 1.00.",0x19ca78af,0xf964f42b),
802 PCMCIA_DEVICE_PROD_ID12("ELAN DIGITAL SYSTEMS LTD, c1997.","SERIAL CARD: SL100",0x19ca78af,0x71d98e83),
803 PCMCIA_DEVICE_PROD_ID12("ELAN DIGITAL SYSTEMS LTD, c1997.","SERIAL CARD: SL232 1.00.",0x19ca78af,0x69fb7490),
804 PCMCIA_DEVICE_PROD_ID12("ELAN DIGITAL SYSTEMS LTD, c1997.","SERIAL CARD: SL232",0x19ca78af,0xb6bc0235),
805 PCMCIA_DEVICE_PROD_ID12("ELAN DIGITAL SYSTEMS LTD, c2000.","SERIAL CARD: CF232",0x63f2e0bd,0xb9e175d3),
806 PCMCIA_DEVICE_PROD_ID12("ELAN DIGITAL SYSTEMS LTD, c2000.","SERIAL CARD: CF232-5",0x63f2e0bd,0xfce33442),
807 PCMCIA_DEVICE_PROD_ID12("Elan","Serial Port: CF232",0x3beb8cf2,0x171e7190),
808 PCMCIA_DEVICE_PROD_ID12("Elan","Serial Port: CF232-5",0x3beb8cf2,0x20da4262),
809 PCMCIA_DEVICE_PROD_ID12("Elan","Serial Port: CF428",0x3beb8cf2,0xea5dd57d),
810 PCMCIA_DEVICE_PROD_ID12("Elan","Serial Port: CF500",0x3beb8cf2,0xd77255fa),
811 PCMCIA_DEVICE_PROD_ID12("Elan","Serial Port: IC232",0x3beb8cf2,0x6a709903),
812 PCMCIA_DEVICE_PROD_ID12("Elan","Serial Port: SL232",0x3beb8cf2,0x18430676),
813 PCMCIA_DEVICE_PROD_ID12("Elan","Serial Port: XL232",0x3beb8cf2,0x6f933767),
814 PCMCIA_MFC_DEVICE_PROD_ID12(0,"Elan","Serial Port: CF332",0x3beb8cf2,0x16dc1ba7),
815 PCMCIA_MFC_DEVICE_PROD_ID12(0,"Elan","Serial Port: SL332",0x3beb8cf2,0x19816c41),
816 PCMCIA_MFC_DEVICE_PROD_ID12(0,"Elan","Serial Port: SL385",0x3beb8cf2,0x64112029),
817 PCMCIA_MFC_DEVICE_PROD_ID12(0,"Elan","Serial Port: SL432",0x3beb8cf2,0x1cce7ac4),
818 PCMCIA_MFC_DEVICE_PROD_ID12(0,"Elan","Serial+Parallel Port: SP230",0x3beb8cf2,0xdb9e58bc),
819 PCMCIA_MFC_DEVICE_PROD_ID12(1,"Elan","Serial Port: CF332",0x3beb8cf2,0x16dc1ba7),
820 PCMCIA_MFC_DEVICE_PROD_ID12(1,"Elan","Serial Port: SL332",0x3beb8cf2,0x19816c41),
821 PCMCIA_MFC_DEVICE_PROD_ID12(1,"Elan","Serial Port: SL385",0x3beb8cf2,0x64112029),
822 PCMCIA_MFC_DEVICE_PROD_ID12(1,"Elan","Serial Port: SL432",0x3beb8cf2,0x1cce7ac4),
823 PCMCIA_MFC_DEVICE_PROD_ID12(2,"Elan","Serial Port: SL432",0x3beb8cf2,0x1cce7ac4),
824 PCMCIA_MFC_DEVICE_PROD_ID12(3,"Elan","Serial Port: SL432",0x3beb8cf2,0x1cce7ac4),
825 PCMCIA_DEVICE_MANF_CARD(0x0279, 0x950b),
826 /* too generic */
827 /* PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0160, 0x0002), */
828 /* PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0160, 0x0002), */
829 PCMCIA_DEVICE_FUNC_ID(2),
830 PCMCIA_DEVICE_NULL,
831};
832MODULE_DEVICE_TABLE(pcmcia, serial_ids);
833
834MODULE_FIRMWARE("cis/PCMLM28.cis");
835MODULE_FIRMWARE("cis/DP83903.cis");
836MODULE_FIRMWARE("cis/3CCFEM556.cis");
837MODULE_FIRMWARE("cis/3CXEM556.cis");
838MODULE_FIRMWARE("cis/SW_8xx_SER.cis");
839MODULE_FIRMWARE("cis/SW_7xx_SER.cis");
840MODULE_FIRMWARE("cis/SW_555_SER.cis");
841MODULE_FIRMWARE("cis/MT5634ZLX.cis");
842MODULE_FIRMWARE("cis/COMpad2.cis");
843MODULE_FIRMWARE("cis/COMpad4.cis");
844MODULE_FIRMWARE("cis/RS-COM-2P.cis");
845
846static struct pcmcia_driver serial_cs_driver = {
847 .owner = THIS_MODULE,
848 .name = "serial_cs",
849 .probe = serial_probe,
850 .remove = serial_detach,
851 .id_table = serial_ids,
852 .suspend = serial_suspend,
853 .resume = serial_resume,
854};
855
856static int __init init_serial_cs(void)
857{
858 return pcmcia_register_driver(&serial_cs_driver);
859}
860
861static void __exit exit_serial_cs(void)
862{
863 pcmcia_unregister_driver(&serial_cs_driver);
864}
865
866module_init(init_serial_cs);
867module_exit(exit_serial_cs);
868
869MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 59c23d03810..5c9d9890c9a 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -5,7 +5,267 @@
5menu "Serial drivers" 5menu "Serial drivers"
6 depends on HAS_IOMEM 6 depends on HAS_IOMEM
7 7
8source "drivers/tty/serial/8250/Kconfig" 8#
9# The new 8250/16550 serial drivers
10config SERIAL_8250
11 tristate "8250/16550 and compatible serial support"
12 select SERIAL_CORE
13 ---help---
14 This selects whether you want to include the driver for the standard
15 serial ports. The standard answer is Y. People who might say N
16 here are those that are setting up dedicated Ethernet WWW/FTP
17 servers, or users that have one of the various bus mice instead of a
18 serial mouse and don't intend to use their machine's standard serial
19 port for anything. (Note that the Cyclades and Stallion multi
20 serial port drivers do not need this driver built in for them to
21 work.)
22
23 To compile this driver as a module, choose M here: the
24 module will be called 8250.
25 [WARNING: Do not compile this driver as a module if you are using
26 non-standard serial ports, since the configuration information will
27 be lost when the driver is unloaded. This limitation may be lifted
28 in the future.]
29
30 BTW1: If you have a mouseman serial mouse which is not recognized by
31 the X window system, try running gpm first.
32
33 BTW2: If you intend to use a software modem (also called Winmodem)
34 under Linux, forget it. These modems are crippled and require
35 proprietary drivers which are only available under Windows.
36
37 Most people will say Y or M here, so that they can use serial mice,
38 modems and similar devices connecting to the standard serial ports.
39
40config SERIAL_8250_CONSOLE
41 bool "Console on 8250/16550 and compatible serial port"
42 depends on SERIAL_8250=y
43 select SERIAL_CORE_CONSOLE
44 ---help---
45 If you say Y here, it will be possible to use a serial port as the
46 system console (the system console is the device which receives all
47 kernel messages and warnings and which allows logins in single user
48 mode). This could be useful if some terminal or printer is connected
49 to that serial port.
50
51 Even if you say Y here, the currently visible virtual console
52 (/dev/tty0) will still be used as the system console by default, but
53 you can alter that using a kernel command line option such as
54 "console=ttyS1". (Try "man bootparam" or see the documentation of
55 your boot loader (grub or lilo or loadlin) about how to pass options
56 to the kernel at boot time.)
57
58 If you don't have a VGA card installed and you say Y here, the
59 kernel will automatically use the first serial line, /dev/ttyS0, as
60 system console.
61
62 You can set that using a kernel command line option such as
63 "console=uart8250,io,0x3f8,9600n8"
64 "console=uart8250,mmio,0xff5e0000,115200n8".
65 and it will switch to normal serial console when the corresponding
66 port is ready.
67 "earlycon=uart8250,io,0x3f8,9600n8"
68 "earlycon=uart8250,mmio,0xff5e0000,115200n8".
69 it will not only setup early console.
70
71 If unsure, say N.
72
73config FIX_EARLYCON_MEM
74 bool
75 depends on X86
76 default y
77
78config SERIAL_8250_GSC
79 tristate
80 depends on SERIAL_8250 && GSC
81 default SERIAL_8250
82
83config SERIAL_8250_PCI
84 tristate "8250/16550 PCI device support" if EXPERT
85 depends on SERIAL_8250 && PCI
86 default SERIAL_8250
87 help
88 This builds standard PCI serial support. You may be able to
89 disable this feature if you only need legacy serial support.
90 Saves about 9K.
91
92config SERIAL_8250_PNP
93 tristate "8250/16550 PNP device support" if EXPERT
94 depends on SERIAL_8250 && PNP
95 default SERIAL_8250
96 help
97 This builds standard PNP serial support. You may be able to
98 disable this feature if you only need legacy serial support.
99
100config SERIAL_8250_HP300
101 tristate
102 depends on SERIAL_8250 && HP300
103 default SERIAL_8250
104
105config SERIAL_8250_CS
106 tristate "8250/16550 PCMCIA device support"
107 depends on PCMCIA && SERIAL_8250
108 ---help---
109 Say Y here to enable support for 16-bit PCMCIA serial devices,
110 including serial port cards, modems, and the modem functions of
111 multi-function Ethernet/modem cards. (PCMCIA- or PC-cards are
112 credit-card size devices often used with laptops.)
113
114 To compile this driver as a module, choose M here: the
115 module will be called serial_cs.
116
117 If unsure, say N.
118
119config SERIAL_8250_NR_UARTS
120 int "Maximum number of 8250/16550 serial ports"
121 depends on SERIAL_8250
122 default "4"
123 help
124 Set this to the number of serial ports you want the driver
125 to support. This includes any ports discovered via ACPI or
126 PCI enumeration and any ports that may be added at run-time
127 via hot-plug, or any ISA multi-port serial cards.
128
129config SERIAL_8250_RUNTIME_UARTS
130 int "Number of 8250/16550 serial ports to register at runtime"
131 depends on SERIAL_8250
132 range 0 SERIAL_8250_NR_UARTS
133 default "4"
134 help
135 Set this to the maximum number of serial ports you want
136 the kernel to register at boot time. This can be overridden
137 with the module parameter "nr_uarts", or boot-time parameter
138 8250.nr_uarts
139
140config SERIAL_8250_EXTENDED
141 bool "Extended 8250/16550 serial driver options"
142 depends on SERIAL_8250
143 help
144 If you wish to use any non-standard features of the standard "dumb"
145 driver, say Y here. This includes HUB6 support, shared serial
146 interrupts, special multiport support, support for more than the
147 four COM 1/2/3/4 boards, etc.
148
149 Note that the answer to this question won't directly affect the
150 kernel: saying N will just cause the configurator to skip all
151 the questions about serial driver options. If unsure, say N.
152
153config SERIAL_8250_MANY_PORTS
154 bool "Support more than 4 legacy serial ports"
155 depends on SERIAL_8250_EXTENDED && !IA64
156 help
157 Say Y here if you have dumb serial boards other than the four
158 standard COM 1/2/3/4 ports. This may happen if you have an AST
159 FourPort, Accent Async, Boca (read the Boca mini-HOWTO, available
160 from <http://www.tldp.org/docs.html#howto>), or other custom
161 serial port hardware which acts similar to standard serial port
162 hardware. If you only use the standard COM 1/2/3/4 ports, you can
163 say N here to save some memory. You can also say Y if you have an
164 "intelligent" multiport card such as Cyclades, Digiboards, etc.
165
166#
167# Multi-port serial cards
168#
169
170config SERIAL_8250_FOURPORT
171 tristate "Support Fourport cards"
172 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
173 help
174 Say Y here if you have an AST FourPort serial board.
175
176 To compile this driver as a module, choose M here: the module
177 will be called 8250_fourport.
178
179config SERIAL_8250_ACCENT
180 tristate "Support Accent cards"
181 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
182 help
183 Say Y here if you have an Accent Async serial board.
184
185 To compile this driver as a module, choose M here: the module
186 will be called 8250_accent.
187
188config SERIAL_8250_BOCA
189 tristate "Support Boca cards"
190 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
191 help
192 Say Y here if you have a Boca serial board. Please read the Boca
193 mini-HOWTO, available from <http://www.tldp.org/docs.html#howto>
194
195 To compile this driver as a module, choose M here: the module
196 will be called 8250_boca.
197
198config SERIAL_8250_EXAR_ST16C554
199 tristate "Support Exar ST16C554/554D Quad UART"
200 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
201 help
202 The Uplogix Envoy TU301 uses this Exar Quad UART. If you are
203 tinkering with your Envoy TU301, or have a machine with this UART,
204 say Y here.
205
206 To compile this driver as a module, choose M here: the module
207 will be called 8250_exar_st16c554.
208
209config SERIAL_8250_HUB6
210 tristate "Support Hub6 cards"
211 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
212 help
213 Say Y here if you have a HUB6 serial board.
214
215 To compile this driver as a module, choose M here: the module
216 will be called 8250_hub6.
217
218config SERIAL_8250_SHARE_IRQ
219 bool "Support for sharing serial interrupts"
220 depends on SERIAL_8250_EXTENDED
221 help
222 Some serial boards have hardware support which allows multiple dumb
223 serial ports on the same board to share a single IRQ. To enable
224 support for this in the serial driver, say Y here.
225
226config SERIAL_8250_DETECT_IRQ
227 bool "Autodetect IRQ on standard ports (unsafe)"
228 depends on SERIAL_8250_EXTENDED
229 help
230 Say Y here if you want the kernel to try to guess which IRQ
231 to use for your serial port.
232
233 This is considered unsafe; it is far better to configure the IRQ in
234 a boot script using the setserial command.
235
236 If unsure, say N.
237
238config SERIAL_8250_RSA
239 bool "Support RSA serial ports"
240 depends on SERIAL_8250_EXTENDED
241 help
242 ::: To be written :::
243
244config SERIAL_8250_MCA
245 tristate "Support 8250-type ports on MCA buses"
246 depends on SERIAL_8250 != n && MCA
247 help
248 Say Y here if you have a MCA serial ports.
249
250 To compile this driver as a module, choose M here: the module
251 will be called 8250_mca.
252
253config SERIAL_8250_ACORN
254 tristate "Acorn expansion card serial port support"
255 depends on ARCH_ACORN && SERIAL_8250
256 help
257 If you have an Atomwide Serial card or Serial Port card for an Acorn
258 system, say Y to this option. The driver can handle 1, 2, or 3 port
259 cards. If unsure, say N.
260
261config SERIAL_8250_RM9K
262 bool "Support for MIPS RM9xxx integrated serial port"
263 depends on SERIAL_8250 != n && SERIAL_RM9000
264 select SERIAL_8250_SHARE_IRQ
265 help
266 Selecting this option will add support for the integrated serial
267 port hardware found on MIPS RM9122 and similar processors.
268 If unsure, say N.
9 269
10comment "Non-8250 serial port support" 270comment "Non-8250 serial port support"
11 271
@@ -93,7 +353,7 @@ config SERIAL_SB1250_DUART_CONSOLE
93 353
94config SERIAL_ATMEL 354config SERIAL_ATMEL
95 bool "AT91 / AT32 on-chip serial port support" 355 bool "AT91 / AT32 on-chip serial port support"
96 depends on ARCH_AT91 || AVR32 356 depends on (ARM && ARCH_AT91) || AVR32
97 select SERIAL_CORE 357 select SERIAL_CORE
98 help 358 help
99 This enables the driver for the on-chip UARTs of the Atmel 359 This enables the driver for the on-chip UARTs of the Atmel
@@ -141,25 +401,6 @@ config SERIAL_ATMEL_TTYAT
141 401
142 Say Y if you have an external 8250/16C550 UART. If unsure, say N. 402 Say Y if you have an external 8250/16C550 UART. If unsure, say N.
143 403
144config SERIAL_KGDB_NMI
145 bool "Serial console over KGDB NMI debugger port"
146 depends on KGDB_SERIAL_CONSOLE
147 help
148 This special driver allows you to temporary use NMI debugger port
149 as a normal console (assuming that the port is attached to KGDB).
150
151 Unlike KDB's disable_nmi command, with this driver you are always
152 able to go back to the debugger using KGDB escape sequence ($3#33).
153 This is because this console driver processes the input in NMI
154 context, and thus is able to intercept the magic sequence.
155
156 Note that since the console interprets input and uses polling
157 communication methods, for things like PPP you still must fully
158 detach debugger port from the KGDB NMI (i.e. disable_nmi), and
159 use raw console.
160
161 If unsure, say N.
162
163config SERIAL_KS8695 404config SERIAL_KS8695
164 bool "Micrel KS8695 (Centaur) serial port support" 405 bool "Micrel KS8695 (Centaur) serial port support"
165 depends on ARCH_KS8695 406 depends on ARCH_KS8695
@@ -179,12 +420,10 @@ config SERIAL_KS8695_CONSOLE
179 420
180config SERIAL_CLPS711X 421config SERIAL_CLPS711X
181 tristate "CLPS711X serial port support" 422 tristate "CLPS711X serial port support"
182 depends on ARCH_CLPS711X 423 depends on ARM && ARCH_CLPS711X
183 select SERIAL_CORE 424 select SERIAL_CORE
184 default y
185 help 425 help
186 This enables the driver for the on-chip UARTs of the Cirrus 426 ::: To be written :::
187 Logic EP711x/EP721x/EP731x processors.
188 427
189config SERIAL_CLPS711X_CONSOLE 428config SERIAL_CLPS711X_CONSOLE
190 bool "Support for console on CLPS711X serial port" 429 bool "Support for console on CLPS711X serial port"
@@ -194,11 +433,13 @@ config SERIAL_CLPS711X_CONSOLE
194 Even if you say Y here, the currently visible virtual console 433 Even if you say Y here, the currently visible virtual console
195 (/dev/tty0) will still be used as the system console by default, but 434 (/dev/tty0) will still be used as the system console by default, but
196 you can alter that using a kernel command line option such as 435 you can alter that using a kernel command line option such as
197 "console=ttyCL1". 436 "console=ttyCL1". (Try "man bootparam" or see the documentation of
437 your boot loader (lilo or loadlin) about how to pass options to the
438 kernel at boot time.)
198 439
199config SERIAL_SAMSUNG 440config SERIAL_SAMSUNG
200 tristate "Samsung SoC serial support" 441 tristate "Samsung SoC serial support"
201 depends on PLAT_SAMSUNG 442 depends on ARM && PLAT_SAMSUNG
202 select SERIAL_CORE 443 select SERIAL_CORE
203 help 444 help
204 Support for the on-chip UARTs on the Samsung S3C24XX series CPUs, 445 Support for the on-chip UARTs on the Samsung S3C24XX series CPUs,
@@ -208,16 +449,16 @@ config SERIAL_SAMSUNG
208 449
209config SERIAL_SAMSUNG_UARTS_4 450config SERIAL_SAMSUNG_UARTS_4
210 bool 451 bool
211 depends on PLAT_SAMSUNG 452 depends on ARM && PLAT_SAMSUNG
212 default y if !(CPU_S3C2410 || SERIAL_S3C2412 || CPU_S3C2440 || CPU_S3C2442) 453 default y if CPU_S3C2443
213 help 454 help
214 Internal node for the common case of 4 Samsung compatible UARTs 455 Internal node for the common case of 4 Samsung compatible UARTs
215 456
216config SERIAL_SAMSUNG_UARTS 457config SERIAL_SAMSUNG_UARTS
217 int 458 int
218 depends on PLAT_SAMSUNG 459 depends on ARM && PLAT_SAMSUNG
219 default 6 if ARCH_S5P6450 460 default 6 if ARCH_S5P6450
220 default 4 if SERIAL_SAMSUNG_UARTS_4 || CPU_S3C2416 461 default 4 if SERIAL_SAMSUNG_UARTS_4
221 default 3 462 default 3
222 help 463 help
223 Select the number of available UART ports for the Samsung S3C 464 Select the number of available UART ports for the Samsung S3C
@@ -247,27 +488,54 @@ config SERIAL_SAMSUNG_CONSOLE
247 your boot loader about how to pass options to the kernel at 488 your boot loader about how to pass options to the kernel at
248 boot time.) 489 boot time.)
249 490
250config SERIAL_SIRFSOC 491config SERIAL_S3C2410
251 tristate "SiRF SoC Platform Serial port support" 492 tristate "Samsung S3C2410 Serial port support"
252 depends on ARCH_PRIMA2 493 depends on SERIAL_SAMSUNG && CPU_S3C2410
253 select SERIAL_CORE 494 default y if CPU_S3C2410
254 help 495 help
255 Support for the on-chip UART on the CSR SiRFprimaII series, 496 Serial port support for the Samsung S3C2410 SoC
256 providing /dev/ttySiRF0, 1 and 2 (note, some machines may not 497
257 provide all of these ports, depending on how the serial port 498config SERIAL_S3C2412
258 pins are configured). 499 tristate "Samsung S3C2412/S3C2413 Serial port support"
259 500 depends on SERIAL_SAMSUNG && CPU_S3C2412
260config SERIAL_SIRFSOC_CONSOLE 501 default y if CPU_S3C2412
261 bool "Support for console on SiRF SoC serial port" 502 help
262 depends on SERIAL_SIRFSOC=y 503 Serial port support for the Samsung S3C2412 and S3C2413 SoC
263 select SERIAL_CORE_CONSOLE 504
264 help 505config SERIAL_S3C2440
265 Even if you say Y here, the currently visible virtual console 506 tristate "Samsung S3C2440/S3C2442/S3C2416 Serial port support"
266 (/dev/tty0) will still be used as the system console by default, but 507 depends on SERIAL_SAMSUNG && (CPU_S3C2440 || CPU_S3C2442 || CPU_S3C2416)
267 you can alter that using a kernel command line option such as 508 default y if CPU_S3C2440
268 "console=ttySiRFx". (Try "man bootparam" or see the documentation of 509 default y if CPU_S3C2442
269 your boot loader about how to pass options to the kernel at 510 select SERIAL_SAMSUNG_UARTS_4 if CPU_S3C2416
270 boot time.) 511 help
512 Serial port support for the Samsung S3C2440, S3C2416 and S3C2442 SoC
513
514config SERIAL_S3C6400
515 tristate "Samsung S3C6400/S3C6410/S5P6440/S5P6450/S5PC100 Serial port support"
516 depends on SERIAL_SAMSUNG && (CPU_S3C6400 || CPU_S3C6410 || CPU_S5P6440 || CPU_S5P6450 || CPU_S5PC100)
517 select SERIAL_SAMSUNG_UARTS_4
518 default y
519 help
520 Serial port support for the Samsung S3C6400, S3C6410, S5P6440, S5P6450
521 and S5PC100 SoCs
522
523config SERIAL_S5PV210
524 tristate "Samsung S5PV210 Serial port support"
525 depends on SERIAL_SAMSUNG && (CPU_S5PV210 || CPU_EXYNOS4210)
526 select SERIAL_SAMSUNG_UARTS_4 if (CPU_S5PV210 || CPU_EXYNOS4210)
527 default y
528 help
529 Serial port support for Samsung's S5P Family of SoC's
530
531config SERIAL_TEGRA
532 boolean "High speed serial support for NVIDIA Tegra SoCs"
533 depends on ARCH_TEGRA && TEGRA_SYSTEM_DMA
534 select SERIAL_CORE
535 help
536 Support for the on-chip UARTs on NVIDIA Tegra SoC, providing
537 /dev/ttyHSx, where x is determined by the number of UARTs on the
538 platform
271 539
272config SERIAL_MAX3100 540config SERIAL_MAX3100
273 tristate "MAX3100 support" 541 tristate "MAX3100 support"
@@ -276,19 +544,21 @@ config SERIAL_MAX3100
276 help 544 help
277 MAX3100 chip support 545 MAX3100 chip support
278 546
279config SERIAL_MAX310X 547config SERIAL_MAX3107
280 bool "MAX310X support" 548 tristate "MAX3107 support"
281 depends on SPI 549 depends on SPI
282 select SERIAL_CORE 550 select SERIAL_CORE
283 select REGMAP_SPI if SPI
284 default n
285 help 551 help
286 This selects support for an advanced UART from Maxim (Dallas). 552 MAX3107 chip support
287 Supported ICs are MAX3107, MAX3108.
288 Each IC contains 128 words each of receive and transmit FIFO
289 that can be controlled through I2C or high-speed SPI.
290 553
291 Say Y here if you want to support this ICs. 554config SERIAL_MAX3107_AAVA
555 tristate "MAX3107 AAVA platform support"
556 depends on X86_MRST && SERIAL_MAX3107 && GPIOLIB
557 select SERIAL_CORE
558 help
559 Support for the MAX3107 chip configuration found on the AAVA
560 platform. Includes the extra initialisation and GPIO support
561 neded for this device.
292 562
293config SERIAL_DZ 563config SERIAL_DZ
294 bool "DECstation DZ serial driver" 564 bool "DECstation DZ serial driver"
@@ -347,7 +617,7 @@ config SERIAL_ZS_CONSOLE
347 617
348config SERIAL_21285 618config SERIAL_21285
349 tristate "DC21285 serial port support" 619 tristate "DC21285 serial port support"
350 depends on FOOTBRIDGE 620 depends on ARM && FOOTBRIDGE
351 select SERIAL_CORE 621 select SERIAL_CORE
352 help 622 help
353 If you have a machine based on a 21285 (Footbridge) StrongARM(R)/ 623 If you have a machine based on a 21285 (Footbridge) StrongARM(R)/
@@ -371,7 +641,7 @@ config SERIAL_21285_CONSOLE
371 641
372config SERIAL_MPSC 642config SERIAL_MPSC
373 bool "Marvell MPSC serial port support" 643 bool "Marvell MPSC serial port support"
374 depends on MV64X60 644 depends on PPC32 && MV64X60
375 select SERIAL_CORE 645 select SERIAL_CORE
376 help 646 help
377 Say Y here if you want to use the Marvell MPSC serial controller. 647 Say Y here if you want to use the Marvell MPSC serial controller.
@@ -408,7 +678,7 @@ config SERIAL_PXA_CONSOLE
408 678
409config SERIAL_SA1100 679config SERIAL_SA1100
410 bool "SA1100 serial port support" 680 bool "SA1100 serial port support"
411 depends on ARCH_SA1100 681 depends on ARM && ARCH_SA1100
412 select SERIAL_CORE 682 select SERIAL_CORE
413 help 683 help
414 If you have a machine based on a SA1100/SA1110 StrongARM(R) CPU you 684 If you have a machine based on a SA1100/SA1110 StrongARM(R) CPU you
@@ -460,7 +730,7 @@ config SERIAL_BFIN
460 Add support for the built-in UARTs on the Blackfin. 730 Add support for the built-in UARTs on the Blackfin.
461 731
462 To compile this driver as a module, choose M here: the 732 To compile this driver as a module, choose M here: the
463 module is named bfin_uart.ko. 733 module will be called bfin_5xx.
464 734
465config SERIAL_BFIN_CONSOLE 735config SERIAL_BFIN_CONSOLE
466 bool "Console on Blackfin serial port" 736 bool "Console on Blackfin serial port"
@@ -539,7 +809,7 @@ config BFIN_UART3_CTSRTS
539 809
540config SERIAL_IMX 810config SERIAL_IMX
541 bool "IMX serial port support" 811 bool "IMX serial port support"
542 depends on ARCH_MXC 812 depends on ARM && (ARCH_IMX || ARCH_MXC)
543 select SERIAL_CORE 813 select SERIAL_CORE
544 select RATIONAL 814 select RATIONAL
545 help 815 help
@@ -712,11 +982,11 @@ config SERIAL_SH_SCI_CONSOLE
712 982
713config SERIAL_SH_SCI_DMA 983config SERIAL_SH_SCI_DMA
714 bool "DMA support" 984 bool "DMA support"
715 depends on SERIAL_SH_SCI && SH_DMAE 985 depends on SERIAL_SH_SCI && SH_DMAE && EXPERIMENTAL
716 986
717config SERIAL_PNX8XXX 987config SERIAL_PNX8XXX
718 bool "Enable PNX8XXX SoCs' UART Support" 988 bool "Enable PNX8XXX SoCs' UART Support"
719 depends on SOC_PNX8550 || SOC_PNX833X 989 depends on MIPS && (SOC_PNX8550 || SOC_PNX833X)
720 select SERIAL_CORE 990 select SERIAL_CORE
721 help 991 help
722 If you have a MIPS-based Philips SoC such as PNX8550 or PNX8330 992 If you have a MIPS-based Philips SoC such as PNX8550 or PNX8330
@@ -730,25 +1000,6 @@ config SERIAL_PNX8XXX_CONSOLE
730 If you have a MIPS-based Philips SoC such as PNX8550 or PNX8330 1000 If you have a MIPS-based Philips SoC such as PNX8550 or PNX8330
731 and you want to use serial console, say Y. Otherwise, say N. 1001 and you want to use serial console, say Y. Otherwise, say N.
732 1002
733config SERIAL_HS_LPC32XX
734 tristate "LPC32XX high speed serial port support"
735 depends on ARCH_LPC32XX && OF
736 select SERIAL_CORE
737 help
738 Support for the LPC32XX high speed serial ports (up to 900kbps).
739 Those are UARTs completely different from the Standard UARTs on the
740 LPC32XX SoC.
741 Choose M or Y here to build this driver.
742
743config SERIAL_HS_LPC32XX_CONSOLE
744 bool "Enable LPC32XX high speed UART serial console"
745 depends on SERIAL_HS_LPC32XX
746 select SERIAL_CORE_CONSOLE
747 help
748 If you would like to be able to use one of the high speed serial
749 ports on the LPC32XX as the console, you can do so by answering
750 Y to this option.
751
752config SERIAL_CORE 1003config SERIAL_CORE
753 tristate 1004 tristate
754 1005
@@ -792,6 +1043,23 @@ config SERIAL_MCF_CONSOLE
792 help 1043 help
793 Enable a ColdFire internal serial port to be the system console. 1044 Enable a ColdFire internal serial port to be the system console.
794 1045
1046config SERIAL_68360_SMC
1047 bool "68360 SMC uart support"
1048 depends on M68360
1049 help
1050 This driver supports the SMC serial ports of the Motorola 68360 CPU.
1051
1052config SERIAL_68360_SCC
1053 bool "68360 SCC uart support"
1054 depends on M68360
1055 help
1056 This driver supports the SCC serial ports of the Motorola 68360 CPU.
1057
1058config SERIAL_68360
1059 bool
1060 depends on SERIAL_68360_SMC || SERIAL_68360_SCC
1061 default y
1062
795config SERIAL_PMACZILOG 1063config SERIAL_PMACZILOG
796 tristate "Mac or PowerMac z85c30 ESCC support" 1064 tristate "Mac or PowerMac z85c30 ESCC support"
797 depends on (M68K && MAC) || (PPC_OF && PPC_PMAC) 1065 depends on (M68K && MAC) || (PPC_OF && PPC_PMAC)
@@ -898,7 +1166,7 @@ config SERIAL_MPC52xx_CONSOLE_BAUD
898 1166
899config SERIAL_ICOM 1167config SERIAL_ICOM
900 tristate "IBM Multiport Serial Adapter" 1168 tristate "IBM Multiport Serial Adapter"
901 depends on PCI && PPC_PSERIES 1169 depends on PCI && (PPC_ISERIES || PPC_PSERIES)
902 select SERIAL_CORE 1170 select SERIAL_CORE
903 select FW_LOADER 1171 select FW_LOADER
904 help 1172 help
@@ -1013,7 +1281,7 @@ config SERIAL_SGI_IOC3
1013 1281
1014config SERIAL_MSM 1282config SERIAL_MSM
1015 bool "MSM on-chip serial port support" 1283 bool "MSM on-chip serial port support"
1016 depends on ARCH_MSM 1284 depends on ARM && ARCH_MSM
1017 select SERIAL_CORE 1285 select SERIAL_CORE
1018 1286
1019config SERIAL_MSM_CONSOLE 1287config SERIAL_MSM_CONSOLE
@@ -1035,7 +1303,7 @@ config SERIAL_MSM_HS
1035 1303
1036config SERIAL_VT8500 1304config SERIAL_VT8500
1037 bool "VIA VT8500 on-chip serial port support" 1305 bool "VIA VT8500 on-chip serial port support"
1038 depends on ARCH_VT8500 1306 depends on ARM && ARCH_VT8500
1039 select SERIAL_CORE 1307 select SERIAL_CORE
1040 1308
1041config SERIAL_VT8500_CONSOLE 1309config SERIAL_VT8500_CONSOLE
@@ -1045,7 +1313,7 @@ config SERIAL_VT8500_CONSOLE
1045 1313
1046config SERIAL_NETX 1314config SERIAL_NETX
1047 tristate "NetX serial port support" 1315 tristate "NetX serial port support"
1048 depends on ARCH_NETX 1316 depends on ARM && ARCH_NETX
1049 select SERIAL_CORE 1317 select SERIAL_CORE
1050 help 1318 help
1051 If you have a machine based on a Hilscher NetX SoC you 1319 If you have a machine based on a Hilscher NetX SoC you
@@ -1074,7 +1342,7 @@ config SERIAL_OF_PLATFORM
1074 1342
1075config SERIAL_OMAP 1343config SERIAL_OMAP
1076 tristate "OMAP serial port support" 1344 tristate "OMAP serial port support"
1077 depends on ARCH_OMAP2PLUS 1345 depends on ARCH_OMAP2 || ARCH_OMAP3 || ARCH_OMAP4
1078 select SERIAL_CORE 1346 select SERIAL_CORE
1079 help 1347 help
1080 If you have a machine based on an Texas Instruments OMAP CPU you 1348 If you have a machine based on an Texas Instruments OMAP CPU you
@@ -1086,7 +1354,7 @@ config SERIAL_OMAP
1086 1354
1087config SERIAL_OMAP_CONSOLE 1355config SERIAL_OMAP_CONSOLE
1088 bool "Console on OMAP serial port" 1356 bool "Console on OMAP serial port"
1089 depends on SERIAL_OMAP=y 1357 depends on SERIAL_OMAP
1090 select SERIAL_CORE_CONSOLE 1358 select SERIAL_CORE_CONSOLE
1091 help 1359 help
1092 Select this option if you would like to use omap serial port as 1360 Select this option if you would like to use omap serial port as
@@ -1149,24 +1417,6 @@ config SERIAL_SC26XX_CONSOLE
1149 help 1417 help
1150 Support for Console on SC2681/SC2692 serial ports. 1418 Support for Console on SC2681/SC2692 serial ports.
1151 1419
1152config SERIAL_SCCNXP
1153 tristate "SCCNXP serial port support"
1154 depends on !SERIAL_SC26XX
1155 select SERIAL_CORE
1156 default n
1157 help
1158 This selects support for an advanced UART from NXP (Philips).
1159 Supported ICs are SCC2681, SCC2691, SCC2692, SC28L91, SC28L92,
1160 SC28L202, SCC68681 and SCC68692.
1161 Positioned as a replacement for the driver SC26XX.
1162
1163config SERIAL_SCCNXP_CONSOLE
1164 bool "Console on SCCNXP serial port"
1165 depends on SERIAL_SCCNXP=y
1166 select SERIAL_CORE_CONSOLE
1167 help
1168 Support for console on SCCNXP serial ports.
1169
1170config SERIAL_BFIN_SPORT 1420config SERIAL_BFIN_SPORT
1171 tristate "Blackfin SPORT emulate UART" 1421 tristate "Blackfin SPORT emulate UART"
1172 depends on BLACKFIN 1422 depends on BLACKFIN
@@ -1323,7 +1573,7 @@ config SERIAL_ALTERA_UART_CONSOLE
1323 1573
1324config SERIAL_IFX6X60 1574config SERIAL_IFX6X60
1325 tristate "SPI protocol driver for Infineon 6x60 modem (EXPERIMENTAL)" 1575 tristate "SPI protocol driver for Infineon 6x60 modem (EXPERIMENTAL)"
1326 depends on GPIOLIB && SPI 1576 depends on GPIOLIB && SPI && EXPERIMENTAL
1327 help 1577 help
1328 Support for the IFX6x60 modem devices on Intel MID platforms. 1578 Support for the IFX6x60 modem devices on Intel MID platforms.
1329 1579
@@ -1343,15 +1593,6 @@ config SERIAL_PCH_UART
1343 ML7213/ML7223/ML7831 is companion chip for Intel Atom E6xx series. 1593 ML7213/ML7223/ML7831 is companion chip for Intel Atom E6xx series.
1344 ML7213/ML7223/ML7831 is completely compatible for Intel EG20T PCH. 1594 ML7213/ML7223/ML7831 is completely compatible for Intel EG20T PCH.
1345 1595
1346config SERIAL_PCH_UART_CONSOLE
1347 bool "Support for console on Intel EG20T PCH UART/OKI SEMICONDUCTOR ML7213 IOH"
1348 depends on SERIAL_PCH_UART=y
1349 select SERIAL_CORE_CONSOLE
1350 help
1351 Say Y here if you wish to use the PCH UART as the system console
1352 (the system console is the device which receives all kernel messages and
1353 warnings and which allows logins in single user mode).
1354
1355config SERIAL_MSM_SMD 1596config SERIAL_MSM_SMD
1356 bool "Enable tty device interface for some SMD ports" 1597 bool "Enable tty device interface for some SMD ports"
1357 default n 1598 default n
@@ -1376,7 +1617,6 @@ config SERIAL_MXS_AUART_CONSOLE
1376 1617
1377config SERIAL_XILINX_PS_UART 1618config SERIAL_XILINX_PS_UART
1378 tristate "Xilinx PS UART support" 1619 tristate "Xilinx PS UART support"
1379 depends on OF
1380 select SERIAL_CORE 1620 select SERIAL_CORE
1381 help 1621 help
1382 This driver supports the Xilinx PS UART port. 1622 This driver supports the Xilinx PS UART port.
@@ -1388,63 +1628,4 @@ config SERIAL_XILINX_PS_UART_CONSOLE
1388 help 1628 help
1389 Enable a Xilinx PS UART port to be the system console. 1629 Enable a Xilinx PS UART port to be the system console.
1390 1630
1391config SERIAL_AR933X
1392 bool "AR933X serial port support"
1393 depends on SOC_AR933X
1394 select SERIAL_CORE
1395 help
1396 If you have an Atheros AR933X SOC based board and want to use the
1397 built-in UART of the SoC, say Y to this option.
1398
1399config SERIAL_AR933X_CONSOLE
1400 bool "Console on AR933X serial port"
1401 depends on SERIAL_AR933X=y
1402 select SERIAL_CORE_CONSOLE
1403 help
1404 Enable a built-in UART port of the AR933X to be the system console.
1405
1406config SERIAL_AR933X_NR_UARTS
1407 int "Maximum number of AR933X serial ports"
1408 depends on SERIAL_AR933X
1409 default "2"
1410 help
1411 Set this to the number of serial ports you want the driver
1412 to support.
1413
1414config SERIAL_EFM32_UART
1415 tristate "EFM32 UART/USART port."
1416 depends on ARCH_EFM32
1417 select SERIAL_CORE
1418 help
1419 This driver support the USART and UART ports on
1420 Energy Micro's efm32 SoCs.
1421
1422config SERIAL_EFM32_UART_CONSOLE
1423 bool "EFM32 UART/USART console support"
1424 depends on SERIAL_EFM32_UART=y
1425 select SERIAL_CORE_CONSOLE
1426
1427config SERIAL_ARC
1428 tristate "ARC UART driver support"
1429 select SERIAL_CORE
1430 help
1431 Driver for on-chip UART for ARC(Synopsys) for the legacy
1432 FPGA Boards (ML50x/ARCAngel4)
1433
1434config SERIAL_ARC_CONSOLE
1435 bool "Console on ARC UART"
1436 depends on SERIAL_ARC=y
1437 select SERIAL_CORE_CONSOLE
1438 help
1439 Enable system Console on ARC UART
1440
1441config SERIAL_ARC_NR_PORTS
1442 int "Number of ARC UART ports"
1443 depends on SERIAL_ARC
1444 range 1 3
1445 default "1"
1446 help
1447 Set this to the number of serial ports you want the driver
1448 to support.
1449
1450endmenu 1631endmenu
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
index df1b998c436..438af89db55 100644
--- a/drivers/tty/serial/Makefile
+++ b/drivers/tty/serial/Makefile
@@ -1,6 +1,7 @@
1# 1#
2# Makefile for the kernel serial device drivers. 2# Makefile for the kernel serial device drivers.
3# 3#
4GCOV_PROFILE_tegra_hsuart.o := y
4 5
5obj-$(CONFIG_SERIAL_CORE) += serial_core.o 6obj-$(CONFIG_SERIAL_CORE) += serial_core.o
6obj-$(CONFIG_SERIAL_21285) += 21285.o 7obj-$(CONFIG_SERIAL_21285) += 21285.o
@@ -14,9 +15,20 @@ obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
14obj-$(CONFIG_SERIAL_SUNSU) += sunsu.o 15obj-$(CONFIG_SERIAL_SUNSU) += sunsu.o
15obj-$(CONFIG_SERIAL_SUNSAB) += sunsab.o 16obj-$(CONFIG_SERIAL_SUNSAB) += sunsab.o
16 17
17# Now bring in any enabled 8250/16450/16550 type drivers. 18obj-$(CONFIG_SERIAL_8250) += 8250.o
18obj-$(CONFIG_SERIAL_8250) += 8250/ 19obj-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o
19 20obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o
21obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o
22obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o
23obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o
24obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o
25obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o
26obj-$(CONFIG_SERIAL_8250_FOURPORT) += 8250_fourport.o
27obj-$(CONFIG_SERIAL_8250_ACCENT) += 8250_accent.o
28obj-$(CONFIG_SERIAL_8250_BOCA) += 8250_boca.o
29obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554) += 8250_exar_st16c554.o
30obj-$(CONFIG_SERIAL_8250_HUB6) += 8250_hub6.o
31obj-$(CONFIG_SERIAL_8250_MCA) += 8250_mca.o
20obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o 32obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o
21obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o 33obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o
22obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o 34obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
@@ -24,17 +36,24 @@ obj-$(CONFIG_SERIAL_PXA) += pxa.o
24obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o 36obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
25obj-$(CONFIG_SERIAL_SA1100) += sa1100.o 37obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
26obj-$(CONFIG_SERIAL_BCM63XX) += bcm63xx_uart.o 38obj-$(CONFIG_SERIAL_BCM63XX) += bcm63xx_uart.o
27obj-$(CONFIG_SERIAL_BFIN) += bfin_uart.o 39obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
28obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o 40obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o
29obj-$(CONFIG_SERIAL_SAMSUNG) += samsung.o 41obj-$(CONFIG_SERIAL_SAMSUNG) += samsung.o
42obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
43obj-$(CONFIG_SERIAL_S3C2412) += s3c2412.o
44obj-$(CONFIG_SERIAL_S3C2440) += s3c2440.o
45obj-$(CONFIG_SERIAL_S3C6400) += s3c6400.o
46obj-$(CONFIG_SERIAL_S5PV210) += s5pv210.o
47obj-$(CONFIG_SERIAL_TEGRA) += tegra_hsuart.o
30obj-$(CONFIG_SERIAL_MAX3100) += max3100.o 48obj-$(CONFIG_SERIAL_MAX3100) += max3100.o
31obj-$(CONFIG_SERIAL_MAX310X) += max310x.o 49obj-$(CONFIG_SERIAL_MAX3107) += max3107.o
50obj-$(CONFIG_SERIAL_MAX3107_AAVA) += max3107-aava.o
32obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o 51obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o
33obj-$(CONFIG_SERIAL_MUX) += mux.o 52obj-$(CONFIG_SERIAL_MUX) += mux.o
34obj-$(CONFIG_SERIAL_68328) += 68328serial.o 53obj-$(CONFIG_SERIAL_68328) += 68328serial.o
54obj-$(CONFIG_SERIAL_68360) += 68360serial.o
35obj-$(CONFIG_SERIAL_MCF) += mcf.o 55obj-$(CONFIG_SERIAL_MCF) += mcf.o
36obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o 56obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o
37obj-$(CONFIG_SERIAL_HS_LPC32XX) += lpc32xx_hs.o
38obj-$(CONFIG_SERIAL_DZ) += dz.o 57obj-$(CONFIG_SERIAL_DZ) += dz.o
39obj-$(CONFIG_SERIAL_ZS) += zs.o 58obj-$(CONFIG_SERIAL_ZS) += zs.o
40obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o 59obj-$(CONFIG_SERIAL_SH_SCI) += sh-sci.o
@@ -48,7 +67,6 @@ obj-$(CONFIG_SERIAL_MPSC) += mpsc.o
48obj-$(CONFIG_SERIAL_SB1250_DUART) += sb1250-duart.o 67obj-$(CONFIG_SERIAL_SB1250_DUART) += sb1250-duart.o
49obj-$(CONFIG_ETRAX_SERIAL) += crisv10.o 68obj-$(CONFIG_ETRAX_SERIAL) += crisv10.o
50obj-$(CONFIG_SERIAL_SC26XX) += sc26xx.o 69obj-$(CONFIG_SERIAL_SC26XX) += sc26xx.o
51obj-$(CONFIG_SERIAL_SCCNXP) += sccnxp.o
52obj-$(CONFIG_SERIAL_JSM) += jsm/ 70obj-$(CONFIG_SERIAL_JSM) += jsm/
53obj-$(CONFIG_SERIAL_TXX9) += serial_txx9.o 71obj-$(CONFIG_SERIAL_TXX9) += serial_txx9.o
54obj-$(CONFIG_SERIAL_VR41XX) += vr41xx_siu.o 72obj-$(CONFIG_SERIAL_VR41XX) += vr41xx_siu.o
@@ -61,15 +79,14 @@ obj-$(CONFIG_SERIAL_MSM_HS) += msm_serial_hs.o
61obj-$(CONFIG_SERIAL_NETX) += netx-serial.o 79obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
62obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o 80obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o
63obj-$(CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL) += nwpserial.o 81obj-$(CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL) += nwpserial.o
64obj-$(CONFIG_SERIAL_KGDB_NMI) += kgdb_nmi.o
65obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o 82obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
66obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o 83obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o
67obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o
68obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o 84obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
69obj-$(CONFIG_SERIAL_QE) += ucc_uart.o 85obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
70obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o 86obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o
71obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o 87obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o
72obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o 88obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o
89obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o
73obj-$(CONFIG_SERIAL_VT8500) += vt8500_serial.o 90obj-$(CONFIG_SERIAL_VT8500) += vt8500_serial.o
74obj-$(CONFIG_SERIAL_MRST_MAX3110) += mrst_max3110.o 91obj-$(CONFIG_SERIAL_MRST_MAX3110) += mrst_max3110.o
75obj-$(CONFIG_SERIAL_MFD_HSU) += mfd.o 92obj-$(CONFIG_SERIAL_MFD_HSU) += mfd.o
@@ -79,7 +96,3 @@ obj-$(CONFIG_SERIAL_MSM_SMD) += msm_smd_tty.o
79obj-$(CONFIG_SERIAL_MXS_AUART) += mxs-auart.o 96obj-$(CONFIG_SERIAL_MXS_AUART) += mxs-auart.o
80obj-$(CONFIG_SERIAL_LANTIQ) += lantiq.o 97obj-$(CONFIG_SERIAL_LANTIQ) += lantiq.o
81obj-$(CONFIG_SERIAL_XILINX_PS_UART) += xilinx_uartps.o 98obj-$(CONFIG_SERIAL_XILINX_PS_UART) += xilinx_uartps.o
82obj-$(CONFIG_SERIAL_SIRFSOC) += sirfsoc_uart.o
83obj-$(CONFIG_SERIAL_AR933X) += ar933x_uart.o
84obj-$(CONFIG_SERIAL_EFM32_UART) += efm32-uart.o
85obj-$(CONFIG_SERIAL_ARC) += arc_uart.o
diff --git a/drivers/tty/serial/altera_jtaguart.c b/drivers/tty/serial/altera_jtaguart.c
index 872f14ae43d..60e049b041a 100644
--- a/drivers/tty/serial/altera_jtaguart.c
+++ b/drivers/tty/serial/altera_jtaguart.c
@@ -18,7 +18,6 @@
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>
22#include <linux/tty.h> 21#include <linux/tty.h>
23#include <linux/tty_flip.h> 22#include <linux/tty_flip.h>
24#include <linux/serial.h> 23#include <linux/serial.h>
@@ -219,7 +218,7 @@ static int altera_jtaguart_startup(struct uart_port *port)
219 unsigned long flags; 218 unsigned long flags;
220 int ret; 219 int ret;
221 220
222 ret = request_irq(port->irq, altera_jtaguart_interrupt, 0, 221 ret = request_irq(port->irq, altera_jtaguart_interrupt, IRQF_DISABLED,
223 DRV_NAME, port); 222 DRV_NAME, port);
224 if (ret) { 223 if (ret) {
225 pr_err(DRV_NAME ": unable to attach Altera JTAG UART %d " 224 pr_err(DRV_NAME ": unable to attach Altera JTAG UART %d "
@@ -406,7 +405,7 @@ static struct uart_driver altera_jtaguart_driver = {
406 .cons = ALTERA_JTAGUART_CONSOLE, 405 .cons = ALTERA_JTAGUART_CONSOLE,
407}; 406};
408 407
409static int altera_jtaguart_probe(struct platform_device *pdev) 408static int __devinit altera_jtaguart_probe(struct platform_device *pdev)
410{ 409{
411 struct altera_jtaguart_platform_uart *platp = pdev->dev.platform_data; 410 struct altera_jtaguart_platform_uart *platp = pdev->dev.platform_data;
412 struct uart_port *port; 411 struct uart_port *port;
@@ -453,7 +452,7 @@ static int altera_jtaguart_probe(struct platform_device *pdev)
453 return 0; 452 return 0;
454} 453}
455 454
456static int altera_jtaguart_remove(struct platform_device *pdev) 455static int __devexit altera_jtaguart_remove(struct platform_device *pdev)
457{ 456{
458 struct uart_port *port; 457 struct uart_port *port;
459 int i = pdev->id; 458 int i = pdev->id;
@@ -473,15 +472,17 @@ static struct of_device_id altera_jtaguart_match[] = {
473 {}, 472 {},
474}; 473};
475MODULE_DEVICE_TABLE(of, altera_jtaguart_match); 474MODULE_DEVICE_TABLE(of, altera_jtaguart_match);
475#else
476#define altera_jtaguart_match NULL
476#endif /* CONFIG_OF */ 477#endif /* CONFIG_OF */
477 478
478static struct platform_driver altera_jtaguart_platform_driver = { 479static struct platform_driver altera_jtaguart_platform_driver = {
479 .probe = altera_jtaguart_probe, 480 .probe = altera_jtaguart_probe,
480 .remove = altera_jtaguart_remove, 481 .remove = __devexit_p(altera_jtaguart_remove),
481 .driver = { 482 .driver = {
482 .name = DRV_NAME, 483 .name = DRV_NAME,
483 .owner = THIS_MODULE, 484 .owner = THIS_MODULE,
484 .of_match_table = of_match_ptr(altera_jtaguart_match), 485 .of_match_table = altera_jtaguart_match,
485 }, 486 },
486}; 487};
487 488
diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_uart.c
index 684a0808e1c..50bc5a5ac65 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, 0, 318 ret = request_irq(port->irq, altera_uart_interrupt, IRQF_DISABLED,
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 "
@@ -377,26 +377,6 @@ static int altera_uart_verify_port(struct uart_port *port,
377 return 0; 377 return 0;
378} 378}
379 379
380#ifdef CONFIG_CONSOLE_POLL
381static int altera_uart_poll_get_char(struct uart_port *port)
382{
383 while (!(altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
384 ALTERA_UART_STATUS_RRDY_MSK))
385 cpu_relax();
386
387 return altera_uart_readl(port, ALTERA_UART_RXDATA_REG);
388}
389
390static void altera_uart_poll_put_char(struct uart_port *port, unsigned char c)
391{
392 while (!(altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
393 ALTERA_UART_STATUS_TRDY_MSK))
394 cpu_relax();
395
396 altera_uart_writel(port, c, ALTERA_UART_TXDATA_REG);
397}
398#endif
399
400/* 380/*
401 * Define the basic serial functions we support. 381 * Define the basic serial functions we support.
402 */ 382 */
@@ -417,16 +397,35 @@ static struct uart_ops altera_uart_ops = {
417 .release_port = altera_uart_release_port, 397 .release_port = altera_uart_release_port,
418 .config_port = altera_uart_config_port, 398 .config_port = altera_uart_config_port,
419 .verify_port = altera_uart_verify_port, 399 .verify_port = altera_uart_verify_port,
420#ifdef CONFIG_CONSOLE_POLL
421 .poll_get_char = altera_uart_poll_get_char,
422 .poll_put_char = altera_uart_poll_put_char,
423#endif
424}; 400};
425 401
426static struct altera_uart altera_uart_ports[CONFIG_SERIAL_ALTERA_UART_MAXPORTS]; 402static struct altera_uart altera_uart_ports[CONFIG_SERIAL_ALTERA_UART_MAXPORTS];
427 403
428#if defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE) 404#if defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE)
429 405
406int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp)
407{
408 struct uart_port *port;
409 int i;
410
411 for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS && platp[i].mapbase; i++) {
412 port = &altera_uart_ports[i].port;
413
414 port->line = i;
415 port->type = PORT_ALTERA_UART;
416 port->mapbase = platp[i].mapbase;
417 port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE);
418 port->iotype = SERIAL_IO_MEM;
419 port->irq = platp[i].irq;
420 port->uartclk = platp[i].uartclk;
421 port->flags = UPF_BOOT_AUTOCONF;
422 port->ops = &altera_uart_ops;
423 port->private_data = platp;
424 }
425
426 return 0;
427}
428
430static void altera_uart_console_putc(struct uart_port *port, const char c) 429static void altera_uart_console_putc(struct uart_port *port, const char c)
431{ 430{
432 while (!(altera_uart_readl(port, ALTERA_UART_STATUS_REG) & 431 while (!(altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
@@ -532,7 +531,7 @@ static int altera_uart_get_of_uartclk(struct platform_device *pdev,
532} 531}
533#endif /* CONFIG_OF */ 532#endif /* CONFIG_OF */
534 533
535static int altera_uart_probe(struct platform_device *pdev) 534static int __devinit altera_uart_probe(struct platform_device *pdev)
536{ 535{
537 struct altera_uart_platform_uart *platp = pdev->dev.platform_data; 536 struct altera_uart_platform_uart *platp = pdev->dev.platform_data;
538 struct uart_port *port; 537 struct uart_port *port;
@@ -556,7 +555,7 @@ static int altera_uart_probe(struct platform_device *pdev)
556 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 555 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
557 if (res_mem) 556 if (res_mem)
558 port->mapbase = res_mem->start; 557 port->mapbase = res_mem->start;
559 else if (platp) 558 else if (platp->mapbase)
560 port->mapbase = platp->mapbase; 559 port->mapbase = platp->mapbase;
561 else 560 else
562 return -EINVAL; 561 return -EINVAL;
@@ -564,7 +563,7 @@ static int altera_uart_probe(struct platform_device *pdev)
564 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 563 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
565 if (res_irq) 564 if (res_irq)
566 port->irq = res_irq->start; 565 port->irq = res_irq->start;
567 else if (platp) 566 else if (platp->irq)
568 port->irq = platp->irq; 567 port->irq = platp->irq;
569 568
570 /* Check platform data first so we can override device node data */ 569 /* Check platform data first so we can override device node data */
@@ -591,20 +590,20 @@ static int altera_uart_probe(struct platform_device *pdev)
591 port->ops = &altera_uart_ops; 590 port->ops = &altera_uart_ops;
592 port->flags = UPF_BOOT_AUTOCONF; 591 port->flags = UPF_BOOT_AUTOCONF;
593 592
594 platform_set_drvdata(pdev, port); 593 dev_set_drvdata(&pdev->dev, port);
595 594
596 uart_add_one_port(&altera_uart_driver, port); 595 uart_add_one_port(&altera_uart_driver, port);
597 596
598 return 0; 597 return 0;
599} 598}
600 599
601static int altera_uart_remove(struct platform_device *pdev) 600static int __devexit altera_uart_remove(struct platform_device *pdev)
602{ 601{
603 struct uart_port *port = platform_get_drvdata(pdev); 602 struct uart_port *port = dev_get_drvdata(&pdev->dev);
604 603
605 if (port) { 604 if (port) {
606 uart_remove_one_port(&altera_uart_driver, port); 605 uart_remove_one_port(&altera_uart_driver, port);
607 platform_set_drvdata(pdev, NULL); 606 dev_set_drvdata(&pdev->dev, NULL);
608 port->mapbase = 0; 607 port->mapbase = 0;
609 } 608 }
610 609
@@ -617,15 +616,17 @@ static struct of_device_id altera_uart_match[] = {
617 {}, 616 {},
618}; 617};
619MODULE_DEVICE_TABLE(of, altera_uart_match); 618MODULE_DEVICE_TABLE(of, altera_uart_match);
619#else
620#define altera_uart_match NULL
620#endif /* CONFIG_OF */ 621#endif /* CONFIG_OF */
621 622
622static struct platform_driver altera_uart_platform_driver = { 623static struct platform_driver altera_uart_platform_driver = {
623 .probe = altera_uart_probe, 624 .probe = altera_uart_probe,
624 .remove = altera_uart_remove, 625 .remove = __devexit_p(altera_uart_remove),
625 .driver = { 626 .driver = {
626 .name = DRV_NAME, 627 .name = DRV_NAME,
627 .owner = THIS_MODULE, 628 .owner = THIS_MODULE,
628 .of_match_table = of_match_ptr(altera_uart_match), 629 .of_match_table = altera_uart_match,
629 }, 630 },
630}; 631};
631 632
diff --git a/drivers/tty/serial/amba-pl010.c b/drivers/tty/serial/amba-pl010.c
index 22317dd1647..c0d10c4ddb7 100644
--- a/drivers/tty/serial/amba-pl010.c
+++ b/drivers/tty/serial/amba-pl010.c
@@ -315,7 +315,7 @@ static int pl010_startup(struct uart_port *port)
315 /* 315 /*
316 * Try to enable the clock producer. 316 * Try to enable the clock producer.
317 */ 317 */
318 retval = clk_prepare_enable(uap->clk); 318 retval = clk_enable(uap->clk);
319 if (retval) 319 if (retval)
320 goto out; 320 goto out;
321 321
@@ -342,7 +342,7 @@ static int pl010_startup(struct uart_port *port)
342 return 0; 342 return 0;
343 343
344 clk_dis: 344 clk_dis:
345 clk_disable_unprepare(uap->clk); 345 clk_disable(uap->clk);
346 out: 346 out:
347 return retval; 347 return retval;
348} 348}
@@ -369,7 +369,7 @@ static void pl010_shutdown(struct uart_port *port)
369 /* 369 /*
370 * Shut down the clock producer 370 * Shut down the clock producer
371 */ 371 */
372 clk_disable_unprepare(uap->clk); 372 clk_disable(uap->clk);
373} 373}
374 374
375static void 375static void
@@ -626,7 +626,6 @@ static int __init pl010_console_setup(struct console *co, char *options)
626 int bits = 8; 626 int bits = 8;
627 int parity = 'n'; 627 int parity = 'n';
628 int flow = 'n'; 628 int flow = 'n';
629 int ret;
630 629
631 /* 630 /*
632 * Check whether an invalid uart number has been specified, and 631 * Check whether an invalid uart number has been specified, and
@@ -639,10 +638,6 @@ static int __init pl010_console_setup(struct console *co, char *options)
639 if (!uap) 638 if (!uap)
640 return -ENODEV; 639 return -ENODEV;
641 640
642 ret = clk_prepare(uap->clk);
643 if (ret)
644 return ret;
645
646 uap->port.uartclk = clk_get_rate(uap->clk); 641 uap->port.uartclk = clk_get_rate(uap->clk);
647 642
648 if (options) 643 if (options)
@@ -788,8 +783,6 @@ static struct amba_id pl010_ids[] = {
788 { 0, 0 }, 783 { 0, 0 },
789}; 784};
790 785
791MODULE_DEVICE_TABLE(amba, pl010_ids);
792
793static struct amba_driver pl010_driver = { 786static struct amba_driver pl010_driver = {
794 .drv = { 787 .drv = {
795 .name = "uart-pl010", 788 .name = "uart-pl010",
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 7fca4022a8b..4a4733e601d 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -51,12 +51,9 @@
51#include <linux/dma-mapping.h> 51#include <linux/dma-mapping.h>
52#include <linux/scatterlist.h> 52#include <linux/scatterlist.h>
53#include <linux/delay.h> 53#include <linux/delay.h>
54#include <linux/types.h> 54
55#include <linux/of.h> 55#include <asm/io.h>
56#include <linux/of_device.h> 56#include <asm/sizes.h>
57#include <linux/pinctrl/consumer.h>
58#include <linux/sizes.h>
59#include <linux/io.h>
60 57
61#define UART_NR 14 58#define UART_NR 14
62 59
@@ -69,6 +66,30 @@
69#define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE) 66#define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE)
70#define UART_DUMMY_DR_RX (1 << 16) 67#define UART_DUMMY_DR_RX (1 << 16)
71 68
69
70#define UART_WA_SAVE_NR 14
71
72static void pl011_lockup_wa(unsigned long data);
73static const u32 uart_wa_reg[UART_WA_SAVE_NR] = {
74 ST_UART011_DMAWM,
75 ST_UART011_TIMEOUT,
76 ST_UART011_LCRH_RX,
77 UART011_IBRD,
78 UART011_FBRD,
79 ST_UART011_LCRH_TX,
80 UART011_IFLS,
81 ST_UART011_XFCR,
82 ST_UART011_XON1,
83 ST_UART011_XON2,
84 ST_UART011_XOFF1,
85 ST_UART011_XOFF2,
86 UART011_CR,
87 UART011_IMSC
88};
89
90static u32 uart_wa_regdata[UART_WA_SAVE_NR];
91static DECLARE_TASKLET(pl011_lockup_tlet, pl011_lockup_wa, 0);
92
72/* There is by now at least one vendor with differing details, so handle it */ 93/* There is by now at least one vendor with differing details, so handle it */
73struct vendor_data { 94struct vendor_data {
74 unsigned int ifls; 95 unsigned int ifls;
@@ -76,8 +97,8 @@ struct vendor_data {
76 unsigned int lcrh_tx; 97 unsigned int lcrh_tx;
77 unsigned int lcrh_rx; 98 unsigned int lcrh_rx;
78 bool oversampling; 99 bool oversampling;
100 bool interrupt_may_hang; /* vendor-specific */
79 bool dma_threshold; 101 bool dma_threshold;
80 bool cts_event_workaround;
81}; 102};
82 103
83static struct vendor_data vendor_arm = { 104static struct vendor_data vendor_arm = {
@@ -87,7 +108,6 @@ static struct vendor_data vendor_arm = {
87 .lcrh_rx = UART011_LCRH, 108 .lcrh_rx = UART011_LCRH,
88 .oversampling = false, 109 .oversampling = false,
89 .dma_threshold = false, 110 .dma_threshold = false,
90 .cts_event_workaround = false,
91}; 111};
92 112
93static struct vendor_data vendor_st = { 113static struct vendor_data vendor_st = {
@@ -96,8 +116,8 @@ static struct vendor_data vendor_st = {
96 .lcrh_tx = ST_UART011_LCRH_TX, 116 .lcrh_tx = ST_UART011_LCRH_TX,
97 .lcrh_rx = ST_UART011_LCRH_RX, 117 .lcrh_rx = ST_UART011_LCRH_RX,
98 .oversampling = true, 118 .oversampling = true,
119 .interrupt_may_hang = true,
99 .dma_threshold = true, 120 .dma_threshold = true,
100 .cts_event_workaround = true,
101}; 121};
102 122
103static struct uart_amba_port *amba_ports[UART_NR]; 123static struct uart_amba_port *amba_ports[UART_NR];
@@ -132,10 +152,6 @@ struct pl011_dmatx_data {
132struct uart_amba_port { 152struct uart_amba_port {
133 struct uart_port port; 153 struct uart_port port;
134 struct clk *clk; 154 struct clk *clk;
135 /* Two optional pin states - default & sleep */
136 struct pinctrl *pinctrl;
137 struct pinctrl_state *pins_default;
138 struct pinctrl_state *pins_sleep;
139 const struct vendor_data *vendor; 155 const struct vendor_data *vendor;
140 unsigned int dmacr; /* dma control reg */ 156 unsigned int dmacr; /* dma control reg */
141 unsigned int im; /* interrupt mask */ 157 unsigned int im; /* interrupt mask */
@@ -143,9 +159,9 @@ struct uart_amba_port {
143 unsigned int fifosize; /* vendor-specific */ 159 unsigned int fifosize; /* vendor-specific */
144 unsigned int lcrh_tx; /* vendor-specific */ 160 unsigned int lcrh_tx; /* vendor-specific */
145 unsigned int lcrh_rx; /* vendor-specific */ 161 unsigned int lcrh_rx; /* vendor-specific */
146 unsigned int old_cr; /* state during shutdown */
147 bool autorts; 162 bool autorts;
148 char type[12]; 163 char type[12];
164 bool interrupt_may_hang; /* vendor-specific */
149#ifdef CONFIG_DMA_ENGINE 165#ifdef CONFIG_DMA_ENGINE
150 /* DMA stuff */ 166 /* DMA stuff */
151 bool using_tx_dma; 167 bool using_tx_dma;
@@ -252,9 +268,8 @@ static void pl011_dma_probe_initcall(struct uart_amba_port *uap)
252 struct dma_slave_config tx_conf = { 268 struct dma_slave_config tx_conf = {
253 .dst_addr = uap->port.mapbase + UART01x_DR, 269 .dst_addr = uap->port.mapbase + UART01x_DR,
254 .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 270 .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE,
255 .direction = DMA_MEM_TO_DEV, 271 .direction = DMA_TO_DEVICE,
256 .dst_maxburst = uap->fifosize >> 1, 272 .dst_maxburst = uap->fifosize >> 1,
257 .device_fc = false,
258 }; 273 };
259 struct dma_chan *chan; 274 struct dma_chan *chan;
260 dma_cap_mask_t mask; 275 dma_cap_mask_t mask;
@@ -286,9 +301,8 @@ static void pl011_dma_probe_initcall(struct uart_amba_port *uap)
286 struct dma_slave_config rx_conf = { 301 struct dma_slave_config rx_conf = {
287 .src_addr = uap->port.mapbase + UART01x_DR, 302 .src_addr = uap->port.mapbase + UART01x_DR,
288 .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 303 .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE,
289 .direction = DMA_DEV_TO_MEM, 304 .direction = DMA_FROM_DEVICE,
290 .src_maxburst = uap->fifosize >> 1, 305 .src_maxburst = uap->fifosize >> 1,
291 .device_fc = false,
292 }; 306 };
293 307
294 chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param); 308 chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param);
@@ -466,7 +480,7 @@ static int pl011_dma_tx_refill(struct uart_amba_port *uap)
466 return -EBUSY; 480 return -EBUSY;
467 } 481 }
468 482
469 desc = dmaengine_prep_slave_sg(chan, &dmatx->sg, 1, DMA_MEM_TO_DEV, 483 desc = dma_dev->device_prep_slave_sg(chan, &dmatx->sg, 1, DMA_TO_DEVICE,
470 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 484 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
471 if (!desc) { 485 if (!desc) {
472 dma_unmap_sg(dma_dev->dev, &dmatx->sg, 1, DMA_TO_DEVICE); 486 dma_unmap_sg(dma_dev->dev, &dmatx->sg, 1, DMA_TO_DEVICE);
@@ -649,6 +663,7 @@ static void pl011_dma_rx_callback(void *data);
649static int pl011_dma_rx_trigger_dma(struct uart_amba_port *uap) 663static int pl011_dma_rx_trigger_dma(struct uart_amba_port *uap)
650{ 664{
651 struct dma_chan *rxchan = uap->dmarx.chan; 665 struct dma_chan *rxchan = uap->dmarx.chan;
666 struct dma_device *dma_dev;
652 struct pl011_dmarx_data *dmarx = &uap->dmarx; 667 struct pl011_dmarx_data *dmarx = &uap->dmarx;
653 struct dma_async_tx_descriptor *desc; 668 struct dma_async_tx_descriptor *desc;
654 struct pl011_sgbuf *sgbuf; 669 struct pl011_sgbuf *sgbuf;
@@ -659,8 +674,9 @@ static int pl011_dma_rx_trigger_dma(struct uart_amba_port *uap)
659 /* Start the RX DMA job */ 674 /* Start the RX DMA job */
660 sgbuf = uap->dmarx.use_buf_b ? 675 sgbuf = uap->dmarx.use_buf_b ?
661 &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a; 676 &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a;
662 desc = dmaengine_prep_slave_sg(rxchan, &sgbuf->sg, 1, 677 dma_dev = rxchan->device;
663 DMA_DEV_TO_MEM, 678 desc = rxchan->device->device_prep_slave_sg(rxchan, &sgbuf->sg, 1,
679 DMA_FROM_DEVICE,
664 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 680 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
665 /* 681 /*
666 * If the DMA engine is busy and cannot prepare a 682 * If the DMA engine is busy and cannot prepare a
@@ -810,12 +826,7 @@ static void pl011_dma_rx_callback(void *data)
810{ 826{
811 struct uart_amba_port *uap = data; 827 struct uart_amba_port *uap = data;
812 struct pl011_dmarx_data *dmarx = &uap->dmarx; 828 struct pl011_dmarx_data *dmarx = &uap->dmarx;
813 struct dma_chan *rxchan = dmarx->chan;
814 bool lastbuf = dmarx->use_buf_b; 829 bool lastbuf = dmarx->use_buf_b;
815 struct pl011_sgbuf *sgbuf = dmarx->use_buf_b ?
816 &dmarx->sgbuf_b : &dmarx->sgbuf_a;
817 size_t pending;
818 struct dma_tx_state state;
819 int ret; 830 int ret;
820 831
821 /* 832 /*
@@ -826,21 +837,11 @@ static void pl011_dma_rx_callback(void *data)
826 * we immediately trigger the next DMA job. 837 * we immediately trigger the next DMA job.
827 */ 838 */
828 spin_lock_irq(&uap->port.lock); 839 spin_lock_irq(&uap->port.lock);
829 /*
830 * Rx data can be taken by the UART interrupts during
831 * the DMA irq handler. So we check the residue here.
832 */
833 rxchan->device->device_tx_status(rxchan, dmarx->cookie, &state);
834 pending = sgbuf->sg.length - state.residue;
835 BUG_ON(pending > PL011_DMA_BUFFER_SIZE);
836 /* Then we terminate the transfer - we now know our residue */
837 dmaengine_terminate_all(rxchan);
838
839 uap->dmarx.running = false; 840 uap->dmarx.running = false;
840 dmarx->use_buf_b = !lastbuf; 841 dmarx->use_buf_b = !lastbuf;
841 ret = pl011_dma_rx_trigger_dma(uap); 842 ret = pl011_dma_rx_trigger_dma(uap);
842 843
843 pl011_dma_rx_chars(uap, pending, lastbuf, false); 844 pl011_dma_rx_chars(uap, PL011_DMA_BUFFER_SIZE, lastbuf, false);
844 spin_unlock_irq(&uap->port.lock); 845 spin_unlock_irq(&uap->port.lock);
845 /* 846 /*
846 * Do this check after we picked the DMA chars so we don't 847 * Do this check after we picked the DMA chars so we don't
@@ -1036,6 +1037,69 @@ static inline bool pl011_dma_rx_running(struct uart_amba_port *uap)
1036#define pl011_dma_flush_buffer NULL 1037#define pl011_dma_flush_buffer NULL
1037#endif 1038#endif
1038 1039
1040
1041/*
1042 * pl011_lockup_wa
1043 * This workaround aims to break the deadlock situation
1044 * when after long transfer over uart in hardware flow
1045 * control, uart interrupt registers cannot be cleared.
1046 * Hence uart transfer gets blocked.
1047 *
1048 * It is seen that during such deadlock condition ICR
1049 * don't get cleared even on multiple write. This leads
1050 * pass_counter to decrease and finally reach zero. This
1051 * can be taken as trigger point to run this UART_BT_WA.
1052 *
1053 */
1054static void pl011_lockup_wa(unsigned long data)
1055{
1056 struct uart_amba_port *uap = amba_ports[0];
1057 void __iomem *base = uap->port.membase;
1058 struct circ_buf *xmit = &uap->port.state->xmit;
1059 struct tty_struct *tty = uap->port.state->port.tty;
1060 int buf_empty_retries = 200;
1061 int loop;
1062
1063 /* Stop HCI layer from submitting data for tx */
1064 tty->hw_stopped = 1;
1065 while (!uart_circ_empty(xmit)) {
1066 if (buf_empty_retries-- == 0)
1067 break;
1068 udelay(100);
1069 }
1070
1071 /* Backup registers */
1072 for (loop = 0; loop < UART_WA_SAVE_NR; loop++)
1073 uart_wa_regdata[loop] = readl(base + uart_wa_reg[loop]);
1074
1075 /* Disable UART so that FIFO data is flushed out */
1076 writew(0x00, uap->port.membase + UART011_CR);
1077
1078 /* Soft reset UART module */
1079 if (uap->port.dev->platform_data) {
1080 struct amba_pl011_data *plat;
1081
1082 plat = uap->port.dev->platform_data;
1083 if (plat->reset)
1084 plat->reset();
1085 }
1086
1087 /* Restore registers */
1088 for (loop = 0; loop < UART_WA_SAVE_NR; loop++)
1089 writew(uart_wa_regdata[loop] ,
1090 uap->port.membase + uart_wa_reg[loop]);
1091
1092 /* Initialise the old status of the modem signals */
1093 uap->old_status = readw(uap->port.membase + UART01x_FR) &
1094 UART01x_FR_MODEM_ANY;
1095
1096 if (readl(base + UART011_MIS) & 0x2)
1097 printk(KERN_EMERG "UART_BT_WA: ***FAILED***\n");
1098
1099 /* Start Tx/Rx */
1100 tty->hw_stopped = 0;
1101}
1102
1039static void pl011_stop_tx(struct uart_port *port) 1103static void pl011_stop_tx(struct uart_port *port)
1040{ 1104{
1041 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1105 struct uart_amba_port *uap = (struct uart_amba_port *)port;
@@ -1164,26 +1228,12 @@ static irqreturn_t pl011_int(int irq, void *dev_id)
1164 unsigned long flags; 1228 unsigned long flags;
1165 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; 1229 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT;
1166 int handled = 0; 1230 int handled = 0;
1167 unsigned int dummy_read;
1168 1231
1169 spin_lock_irqsave(&uap->port.lock, flags); 1232 spin_lock_irqsave(&uap->port.lock, flags);
1170 1233
1171 status = readw(uap->port.membase + UART011_MIS); 1234 status = readw(uap->port.membase + UART011_MIS);
1172 if (status) { 1235 if (status) {
1173 do { 1236 do {
1174 if (uap->vendor->cts_event_workaround) {
1175 /* workaround to make sure that all bits are unlocked.. */
1176 writew(0x00, uap->port.membase + UART011_ICR);
1177
1178 /*
1179 * WA: introduce 26ns(1 uart clk) delay before W1C;
1180 * single apb access will incur 2 pclk(133.12Mhz) delay,
1181 * so add 2 dummy reads
1182 */
1183 dummy_read = readw(uap->port.membase + UART011_ICR);
1184 dummy_read = readw(uap->port.membase + UART011_ICR);
1185 }
1186
1187 writew(status & ~(UART011_TXIS|UART011_RTIS| 1237 writew(status & ~(UART011_TXIS|UART011_RTIS|
1188 UART011_RXIS), 1238 UART011_RXIS),
1189 uap->port.membase + UART011_ICR); 1239 uap->port.membase + UART011_ICR);
@@ -1200,8 +1250,11 @@ static irqreturn_t pl011_int(int irq, void *dev_id)
1200 if (status & UART011_TXIS) 1250 if (status & UART011_TXIS)
1201 pl011_tx_chars(uap); 1251 pl011_tx_chars(uap);
1202 1252
1203 if (pass_counter-- == 0) 1253 if (pass_counter-- == 0) {
1254 if (uap->interrupt_may_hang)
1255 tasklet_schedule(&pl011_lockup_tlet);
1204 break; 1256 break;
1257 }
1205 1258
1206 status = readw(uap->port.membase + UART011_MIS); 1259 status = readw(uap->port.membase + UART011_MIS);
1207 } while (status != 0); 1260 } while (status != 0);
@@ -1213,14 +1266,14 @@ static irqreturn_t pl011_int(int irq, void *dev_id)
1213 return IRQ_RETVAL(handled); 1266 return IRQ_RETVAL(handled);
1214} 1267}
1215 1268
1216static unsigned int pl011_tx_empty(struct uart_port *port) 1269static unsigned int pl01x_tx_empty(struct uart_port *port)
1217{ 1270{
1218 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1271 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1219 unsigned int status = readw(uap->port.membase + UART01x_FR); 1272 unsigned int status = readw(uap->port.membase + UART01x_FR);
1220 return status & (UART01x_FR_BUSY|UART01x_FR_TXFF) ? 0 : TIOCSER_TEMT; 1273 return status & (UART01x_FR_BUSY|UART01x_FR_TXFF) ? 0 : TIOCSER_TEMT;
1221} 1274}
1222 1275
1223static unsigned int pl011_get_mctrl(struct uart_port *port) 1276static unsigned int pl01x_get_mctrl(struct uart_port *port)
1224{ 1277{
1225 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1278 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1226 unsigned int result = 0; 1279 unsigned int result = 0;
@@ -1283,40 +1336,11 @@ static void pl011_break_ctl(struct uart_port *port, int break_state)
1283} 1336}
1284 1337
1285#ifdef CONFIG_CONSOLE_POLL 1338#ifdef CONFIG_CONSOLE_POLL
1286 1339static int pl010_get_poll_char(struct uart_port *port)
1287static void pl011_quiesce_irqs(struct uart_port *port)
1288{
1289 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1290 unsigned char __iomem *regs = uap->port.membase;
1291
1292 writew(readw(regs + UART011_MIS), regs + UART011_ICR);
1293 /*
1294 * There is no way to clear TXIM as this is "ready to transmit IRQ", so
1295 * we simply mask it. start_tx() will unmask it.
1296 *
1297 * Note we can race with start_tx(), and if the race happens, the
1298 * polling user might get another interrupt just after we clear it.
1299 * But it should be OK and can happen even w/o the race, e.g.
1300 * controller immediately got some new data and raised the IRQ.
1301 *
1302 * And whoever uses polling routines assumes that it manages the device
1303 * (including tx queue), so we're also fine with start_tx()'s caller
1304 * side.
1305 */
1306 writew(readw(regs + UART011_IMSC) & ~UART011_TXIM, regs + UART011_IMSC);
1307}
1308
1309static int pl011_get_poll_char(struct uart_port *port)
1310{ 1340{
1311 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1341 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1312 unsigned int status; 1342 unsigned int status;
1313 1343
1314 /*
1315 * The caller might need IRQs lowered, e.g. if used with KDB NMI
1316 * debugger.
1317 */
1318 pl011_quiesce_irqs(port);
1319
1320 status = readw(uap->port.membase + UART01x_FR); 1344 status = readw(uap->port.membase + UART01x_FR);
1321 if (status & UART01x_FR_RXFE) 1345 if (status & UART01x_FR_RXFE)
1322 return NO_POLL_CHAR; 1346 return NO_POLL_CHAR;
@@ -1324,7 +1348,7 @@ static int pl011_get_poll_char(struct uart_port *port)
1324 return readw(uap->port.membase + UART01x_DR); 1348 return readw(uap->port.membase + UART01x_DR);
1325} 1349}
1326 1350
1327static void pl011_put_poll_char(struct uart_port *port, 1351static void pl010_put_poll_char(struct uart_port *port,
1328 unsigned char ch) 1352 unsigned char ch)
1329{ 1353{
1330 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1354 struct uart_amba_port *uap = (struct uart_amba_port *)port;
@@ -1337,63 +1361,21 @@ static void pl011_put_poll_char(struct uart_port *port,
1337 1361
1338#endif /* CONFIG_CONSOLE_POLL */ 1362#endif /* CONFIG_CONSOLE_POLL */
1339 1363
1340static int pl011_hwinit(struct uart_port *port) 1364static int pl011_startup(struct uart_port *port)
1341{ 1365{
1342 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1366 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1367 unsigned int cr;
1343 int retval; 1368 int retval;
1344 1369
1345 /* Optionaly enable pins to be muxed in and configured */
1346 if (!IS_ERR(uap->pins_default)) {
1347 retval = pinctrl_select_state(uap->pinctrl, uap->pins_default);
1348 if (retval)
1349 dev_err(port->dev,
1350 "could not set default pins\n");
1351 }
1352
1353 /* 1370 /*
1354 * Try to enable the clock producer. 1371 * Try to enable the clock producer.
1355 */ 1372 */
1356 retval = clk_prepare_enable(uap->clk); 1373 retval = clk_enable(uap->clk);
1357 if (retval) 1374 if (retval)
1358 goto out; 1375 goto out;
1359 1376
1360 uap->port.uartclk = clk_get_rate(uap->clk); 1377 uap->port.uartclk = clk_get_rate(uap->clk);
1361 1378
1362 /* Clear pending error and receive interrupts */
1363 writew(UART011_OEIS | UART011_BEIS | UART011_PEIS | UART011_FEIS |
1364 UART011_RTIS | UART011_RXIS, uap->port.membase + UART011_ICR);
1365
1366 /*
1367 * Save interrupts enable mask, and enable RX interrupts in case if
1368 * the interrupt is used for NMI entry.
1369 */
1370 uap->im = readw(uap->port.membase + UART011_IMSC);
1371 writew(UART011_RTIM | UART011_RXIM, uap->port.membase + UART011_IMSC);
1372
1373 if (uap->port.dev->platform_data) {
1374 struct amba_pl011_data *plat;
1375
1376 plat = uap->port.dev->platform_data;
1377 if (plat->init)
1378 plat->init();
1379 }
1380 return 0;
1381 out:
1382 return retval;
1383}
1384
1385static int pl011_startup(struct uart_port *port)
1386{
1387 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1388 unsigned int cr;
1389 int retval;
1390
1391 retval = pl011_hwinit(port);
1392 if (retval)
1393 goto clk_dis;
1394
1395 writew(uap->im, uap->port.membase + UART011_IMSC);
1396
1397 /* 1379 /*
1398 * Allocate the IRQ 1380 * Allocate the IRQ
1399 */ 1381 */
@@ -1425,11 +1407,13 @@ static int pl011_startup(struct uart_port *port)
1425 while (readw(uap->port.membase + UART01x_FR) & UART01x_FR_BUSY) 1407 while (readw(uap->port.membase + UART01x_FR) & UART01x_FR_BUSY)
1426 barrier(); 1408 barrier();
1427 1409
1428 /* restore RTS and DTR */ 1410 cr = UART01x_CR_UARTEN | UART011_CR_RXE | UART011_CR_TXE;
1429 cr = uap->old_cr & (UART011_CR_RTS | UART011_CR_DTR);
1430 cr |= UART01x_CR_UARTEN | UART011_CR_RXE | UART011_CR_TXE;
1431 writew(cr, uap->port.membase + UART011_CR); 1411 writew(cr, uap->port.membase + UART011_CR);
1432 1412
1413 /* Clear pending error interrupts */
1414 writew(UART011_OEIS | UART011_BEIS | UART011_PEIS | UART011_FEIS,
1415 uap->port.membase + UART011_ICR);
1416
1433 /* 1417 /*
1434 * initialise the old status of the modem signals 1418 * initialise the old status of the modem signals
1435 */ 1419 */
@@ -1444,19 +1428,25 @@ static int pl011_startup(struct uart_port *port)
1444 * as well. 1428 * as well.
1445 */ 1429 */
1446 spin_lock_irq(&uap->port.lock); 1430 spin_lock_irq(&uap->port.lock);
1447 /* Clear out any spuriously appearing RX interrupts */
1448 writew(UART011_RTIS | UART011_RXIS,
1449 uap->port.membase + UART011_ICR);
1450 uap->im = UART011_RTIM; 1431 uap->im = UART011_RTIM;
1451 if (!pl011_dma_rx_running(uap)) 1432 if (!pl011_dma_rx_running(uap))
1452 uap->im |= UART011_RXIM; 1433 uap->im |= UART011_RXIM;
1453 writew(uap->im, uap->port.membase + UART011_IMSC); 1434 writew(uap->im, uap->port.membase + UART011_IMSC);
1454 spin_unlock_irq(&uap->port.lock); 1435 spin_unlock_irq(&uap->port.lock);
1455 1436
1437 if (uap->port.dev->platform_data) {
1438 struct amba_pl011_data *plat;
1439
1440 plat = uap->port.dev->platform_data;
1441 if (plat->init)
1442 plat->init();
1443 }
1444
1456 return 0; 1445 return 0;
1457 1446
1458 clk_dis: 1447 clk_dis:
1459 clk_disable_unprepare(uap->clk); 1448 clk_disable(uap->clk);
1449 out:
1460 return retval; 1450 return retval;
1461} 1451}
1462 1452
@@ -1473,8 +1463,6 @@ static void pl011_shutdown_channel(struct uart_amba_port *uap,
1473static void pl011_shutdown(struct uart_port *port) 1463static void pl011_shutdown(struct uart_port *port)
1474{ 1464{
1475 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1465 struct uart_amba_port *uap = (struct uart_amba_port *)port;
1476 unsigned int cr;
1477 int retval;
1478 1466
1479 /* 1467 /*
1480 * disable all interrupts 1468 * disable all interrupts
@@ -1494,16 +1482,9 @@ static void pl011_shutdown(struct uart_port *port)
1494 1482
1495 /* 1483 /*
1496 * disable the port 1484 * disable the port
1497 * disable the port. It should not disable RTS and DTR.
1498 * Also RTS and DTR state should be preserved to restore
1499 * it during startup().
1500 */ 1485 */
1501 uap->autorts = false; 1486 uap->autorts = false;
1502 cr = readw(uap->port.membase + UART011_CR); 1487 writew(UART01x_CR_UARTEN | UART011_CR_TXE, uap->port.membase + UART011_CR);
1503 uap->old_cr = cr;
1504 cr &= UART011_CR_RTS | UART011_CR_DTR;
1505 cr |= UART01x_CR_UARTEN | UART011_CR_TXE;
1506 writew(cr, uap->port.membase + UART011_CR);
1507 1488
1508 /* 1489 /*
1509 * disable break condition and fifos 1490 * disable break condition and fifos
@@ -1515,15 +1496,7 @@ static void pl011_shutdown(struct uart_port *port)
1515 /* 1496 /*
1516 * Shut down the clock producer 1497 * Shut down the clock producer
1517 */ 1498 */
1518 clk_disable_unprepare(uap->clk); 1499 clk_disable(uap->clk);
1519 /* Optionally let pins go into sleep states */
1520 if (!IS_ERR(uap->pins_sleep)) {
1521 retval = pinctrl_select_state(uap->pinctrl, uap->pins_sleep);
1522 if (retval)
1523 dev_err(port->dev,
1524 "could not set pins to sleep state\n");
1525 }
1526
1527 1500
1528 if (uap->port.dev->platform_data) { 1501 if (uap->port.dev->platform_data) {
1529 struct amba_pl011_data *plat; 1502 struct amba_pl011_data *plat;
@@ -1644,26 +1617,13 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios,
1644 old_cr &= ~ST_UART011_CR_OVSFACT; 1617 old_cr &= ~ST_UART011_CR_OVSFACT;
1645 } 1618 }
1646 1619
1647 /*
1648 * Workaround for the ST Micro oversampling variants to
1649 * increase the bitrate slightly, by lowering the divisor,
1650 * to avoid delayed sampling of start bit at high speeds,
1651 * else we see data corruption.
1652 */
1653 if (uap->vendor->oversampling) {
1654 if ((baud >= 3000000) && (baud < 3250000) && (quot > 1))
1655 quot -= 1;
1656 else if ((baud > 3250000) && (quot > 2))
1657 quot -= 2;
1658 }
1659 /* Set baud rate */ 1620 /* Set baud rate */
1660 writew(quot & 0x3f, port->membase + UART011_FBRD); 1621 writew(quot & 0x3f, port->membase + UART011_FBRD);
1661 writew(quot >> 6, port->membase + UART011_IBRD); 1622 writew(quot >> 6, port->membase + UART011_IBRD);
1662 1623
1663 /* 1624 /*
1664 * ----------v----------v----------v----------v----- 1625 * ----------v----------v----------v----------v-----
1665 * NOTE: lcrh_tx and lcrh_rx MUST BE WRITTEN AFTER 1626 * NOTE: MUST BE WRITTEN AFTER UARTLCR_M & UARTLCR_L
1666 * UART011_FBRD & UART011_IBRD.
1667 * ----------^----------^----------^----------^----- 1627 * ----------^----------^----------^----------^-----
1668 */ 1628 */
1669 writew(lcr_h, port->membase + uap->lcrh_rx); 1629 writew(lcr_h, port->membase + uap->lcrh_rx);
@@ -1691,7 +1651,7 @@ static const char *pl011_type(struct uart_port *port)
1691/* 1651/*
1692 * Release the memory region(s) being used by 'port' 1652 * Release the memory region(s) being used by 'port'
1693 */ 1653 */
1694static void pl011_release_port(struct uart_port *port) 1654static void pl010_release_port(struct uart_port *port)
1695{ 1655{
1696 release_mem_region(port->mapbase, SZ_4K); 1656 release_mem_region(port->mapbase, SZ_4K);
1697} 1657}
@@ -1699,7 +1659,7 @@ static void pl011_release_port(struct uart_port *port)
1699/* 1659/*
1700 * Request the memory region(s) being used by 'port' 1660 * Request the memory region(s) being used by 'port'
1701 */ 1661 */
1702static int pl011_request_port(struct uart_port *port) 1662static int pl010_request_port(struct uart_port *port)
1703{ 1663{
1704 return request_mem_region(port->mapbase, SZ_4K, "uart-pl011") 1664 return request_mem_region(port->mapbase, SZ_4K, "uart-pl011")
1705 != NULL ? 0 : -EBUSY; 1665 != NULL ? 0 : -EBUSY;
@@ -1708,18 +1668,18 @@ static int pl011_request_port(struct uart_port *port)
1708/* 1668/*
1709 * Configure/autoconfigure the port. 1669 * Configure/autoconfigure the port.
1710 */ 1670 */
1711static void pl011_config_port(struct uart_port *port, int flags) 1671static void pl010_config_port(struct uart_port *port, int flags)
1712{ 1672{
1713 if (flags & UART_CONFIG_TYPE) { 1673 if (flags & UART_CONFIG_TYPE) {
1714 port->type = PORT_AMBA; 1674 port->type = PORT_AMBA;
1715 pl011_request_port(port); 1675 pl010_request_port(port);
1716 } 1676 }
1717} 1677}
1718 1678
1719/* 1679/*
1720 * verify the new serial_struct (for TIOCSSERIAL). 1680 * verify the new serial_struct (for TIOCSSERIAL).
1721 */ 1681 */
1722static int pl011_verify_port(struct uart_port *port, struct serial_struct *ser) 1682static int pl010_verify_port(struct uart_port *port, struct serial_struct *ser)
1723{ 1683{
1724 int ret = 0; 1684 int ret = 0;
1725 if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMBA) 1685 if (ser->type != PORT_UNKNOWN && ser->type != PORT_AMBA)
@@ -1732,9 +1692,9 @@ static int pl011_verify_port(struct uart_port *port, struct serial_struct *ser)
1732} 1692}
1733 1693
1734static struct uart_ops amba_pl011_pops = { 1694static struct uart_ops amba_pl011_pops = {
1735 .tx_empty = pl011_tx_empty, 1695 .tx_empty = pl01x_tx_empty,
1736 .set_mctrl = pl011_set_mctrl, 1696 .set_mctrl = pl011_set_mctrl,
1737 .get_mctrl = pl011_get_mctrl, 1697 .get_mctrl = pl01x_get_mctrl,
1738 .stop_tx = pl011_stop_tx, 1698 .stop_tx = pl011_stop_tx,
1739 .start_tx = pl011_start_tx, 1699 .start_tx = pl011_start_tx,
1740 .stop_rx = pl011_stop_rx, 1700 .stop_rx = pl011_stop_rx,
@@ -1745,14 +1705,13 @@ static struct uart_ops amba_pl011_pops = {
1745 .flush_buffer = pl011_dma_flush_buffer, 1705 .flush_buffer = pl011_dma_flush_buffer,
1746 .set_termios = pl011_set_termios, 1706 .set_termios = pl011_set_termios,
1747 .type = pl011_type, 1707 .type = pl011_type,
1748 .release_port = pl011_release_port, 1708 .release_port = pl010_release_port,
1749 .request_port = pl011_request_port, 1709 .request_port = pl010_request_port,
1750 .config_port = pl011_config_port, 1710 .config_port = pl010_config_port,
1751 .verify_port = pl011_verify_port, 1711 .verify_port = pl010_verify_port,
1752#ifdef CONFIG_CONSOLE_POLL 1712#ifdef CONFIG_CONSOLE_POLL
1753 .poll_init = pl011_hwinit, 1713 .poll_get_char = pl010_get_poll_char,
1754 .poll_get_char = pl011_get_poll_char, 1714 .poll_put_char = pl010_put_poll_char,
1755 .poll_put_char = pl011_put_poll_char,
1756#endif 1715#endif
1757}; 1716};
1758 1717
@@ -1855,7 +1814,6 @@ static int __init pl011_console_setup(struct console *co, char *options)
1855 int bits = 8; 1814 int bits = 8;
1856 int parity = 'n'; 1815 int parity = 'n';
1857 int flow = 'n'; 1816 int flow = 'n';
1858 int ret;
1859 1817
1860 /* 1818 /*
1861 * Check whether an invalid uart number has been specified, and 1819 * Check whether an invalid uart number has been specified, and
@@ -1868,18 +1826,6 @@ static int __init pl011_console_setup(struct console *co, char *options)
1868 if (!uap) 1826 if (!uap)
1869 return -ENODEV; 1827 return -ENODEV;
1870 1828
1871 /* Allow pins to be muxed in and configured */
1872 if (!IS_ERR(uap->pins_default)) {
1873 ret = pinctrl_select_state(uap->pinctrl, uap->pins_default);
1874 if (ret)
1875 dev_err(uap->port.dev,
1876 "could not set default pins\n");
1877 }
1878
1879 ret = clk_prepare(uap->clk);
1880 if (ret)
1881 return ret;
1882
1883 if (uap->port.dev->platform_data) { 1829 if (uap->port.dev->platform_data) {
1884 struct amba_pl011_data *plat; 1830 struct amba_pl011_data *plat;
1885 1831
@@ -1924,38 +1870,6 @@ static struct uart_driver amba_reg = {
1924 .cons = AMBA_CONSOLE, 1870 .cons = AMBA_CONSOLE,
1925}; 1871};
1926 1872
1927static int pl011_probe_dt_alias(int index, struct device *dev)
1928{
1929 struct device_node *np;
1930 static bool seen_dev_with_alias = false;
1931 static bool seen_dev_without_alias = false;
1932 int ret = index;
1933
1934 if (!IS_ENABLED(CONFIG_OF))
1935 return ret;
1936
1937 np = dev->of_node;
1938 if (!np)
1939 return ret;
1940
1941 ret = of_alias_get_id(np, "serial");
1942 if (IS_ERR_VALUE(ret)) {
1943 seen_dev_without_alias = true;
1944 ret = index;
1945 } else {
1946 seen_dev_with_alias = true;
1947 if (ret >= ARRAY_SIZE(amba_ports) || amba_ports[ret] != NULL) {
1948 dev_warn(dev, "requested serial port %d not available.\n", ret);
1949 ret = index;
1950 }
1951 }
1952
1953 if (seen_dev_with_alias && seen_dev_without_alias)
1954 dev_warn(dev, "aliased and non-aliased serial devices found in device tree. Serial port enumeration may be unpredictable.\n");
1955
1956 return ret;
1957}
1958
1959static int pl011_probe(struct amba_device *dev, const struct amba_id *id) 1873static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
1960{ 1874{
1961 struct uart_amba_port *uap; 1875 struct uart_amba_port *uap;
@@ -1972,48 +1886,29 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
1972 goto out; 1886 goto out;
1973 } 1887 }
1974 1888
1975 uap = devm_kzalloc(&dev->dev, sizeof(struct uart_amba_port), 1889 uap = kzalloc(sizeof(struct uart_amba_port), GFP_KERNEL);
1976 GFP_KERNEL);
1977 if (uap == NULL) { 1890 if (uap == NULL) {
1978 ret = -ENOMEM; 1891 ret = -ENOMEM;
1979 goto out; 1892 goto out;
1980 } 1893 }
1981 1894
1982 i = pl011_probe_dt_alias(i, &dev->dev); 1895 base = ioremap(dev->res.start, resource_size(&dev->res));
1983
1984 base = devm_ioremap(&dev->dev, dev->res.start,
1985 resource_size(&dev->res));
1986 if (!base) { 1896 if (!base) {
1987 ret = -ENOMEM; 1897 ret = -ENOMEM;
1988 goto out; 1898 goto free;
1989 } 1899 }
1990 1900
1991 uap->pinctrl = devm_pinctrl_get(&dev->dev); 1901 uap->clk = clk_get(&dev->dev, NULL);
1992 if (IS_ERR(uap->pinctrl)) {
1993 ret = PTR_ERR(uap->pinctrl);
1994 goto out;
1995 }
1996 uap->pins_default = pinctrl_lookup_state(uap->pinctrl,
1997 PINCTRL_STATE_DEFAULT);
1998 if (IS_ERR(uap->pins_default))
1999 dev_err(&dev->dev, "could not get default pinstate\n");
2000
2001 uap->pins_sleep = pinctrl_lookup_state(uap->pinctrl,
2002 PINCTRL_STATE_SLEEP);
2003 if (IS_ERR(uap->pins_sleep))
2004 dev_dbg(&dev->dev, "could not get sleep pinstate\n");
2005
2006 uap->clk = devm_clk_get(&dev->dev, NULL);
2007 if (IS_ERR(uap->clk)) { 1902 if (IS_ERR(uap->clk)) {
2008 ret = PTR_ERR(uap->clk); 1903 ret = PTR_ERR(uap->clk);
2009 goto out; 1904 goto unmap;
2010 } 1905 }
2011 1906
2012 uap->vendor = vendor; 1907 uap->vendor = vendor;
2013 uap->lcrh_rx = vendor->lcrh_rx; 1908 uap->lcrh_rx = vendor->lcrh_rx;
2014 uap->lcrh_tx = vendor->lcrh_tx; 1909 uap->lcrh_tx = vendor->lcrh_tx;
2015 uap->old_cr = 0;
2016 uap->fifosize = vendor->fifosize; 1910 uap->fifosize = vendor->fifosize;
1911 uap->interrupt_may_hang = vendor->interrupt_may_hang;
2017 uap->port.dev = &dev->dev; 1912 uap->port.dev = &dev->dev;
2018 uap->port.mapbase = dev->res.start; 1913 uap->port.mapbase = dev->res.start;
2019 uap->port.membase = base; 1914 uap->port.membase = base;
@@ -2025,10 +1920,6 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
2025 uap->port.line = i; 1920 uap->port.line = i;
2026 pl011_dma_probe(uap); 1921 pl011_dma_probe(uap);
2027 1922
2028 /* Ensure interrupts from this UART are masked and cleared */
2029 writew(0, uap->port.membase + UART011_IMSC);
2030 writew(0xffff, uap->port.membase + UART011_ICR);
2031
2032 snprintf(uap->type, sizeof(uap->type), "PL011 rev%u", amba_rev(dev)); 1923 snprintf(uap->type, sizeof(uap->type), "PL011 rev%u", amba_rev(dev));
2033 1924
2034 amba_ports[i] = uap; 1925 amba_ports[i] = uap;
@@ -2039,6 +1930,11 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
2039 amba_set_drvdata(dev, NULL); 1930 amba_set_drvdata(dev, NULL);
2040 amba_ports[i] = NULL; 1931 amba_ports[i] = NULL;
2041 pl011_dma_remove(uap); 1932 pl011_dma_remove(uap);
1933 clk_put(uap->clk);
1934 unmap:
1935 iounmap(base);
1936 free:
1937 kfree(uap);
2042 } 1938 }
2043 out: 1939 out:
2044 return ret; 1940 return ret;
@@ -2058,6 +1954,9 @@ static int pl011_remove(struct amba_device *dev)
2058 amba_ports[i] = NULL; 1954 amba_ports[i] = NULL;
2059 1955
2060 pl011_dma_remove(uap); 1956 pl011_dma_remove(uap);
1957 iounmap(uap->port.membase);
1958 clk_put(uap->clk);
1959 kfree(uap);
2061 return 0; 1960 return 0;
2062} 1961}
2063 1962
@@ -2097,8 +1996,6 @@ static struct amba_id pl011_ids[] = {
2097 { 0, 0 }, 1996 { 0, 0 },
2098}; 1997};
2099 1998
2100MODULE_DEVICE_TABLE(amba, pl011_ids);
2101
2102static struct amba_driver pl011_driver = { 1999static struct amba_driver pl011_driver = {
2103 .drv = { 2000 .drv = {
2104 .name = "uart-pl011", 2001 .name = "uart-pl011",
diff --git a/drivers/tty/serial/apbuart.c b/drivers/tty/serial/apbuart.c
index 59ae2b53e76..19a943693e4 100644
--- a/drivers/tty/serial/apbuart.c
+++ b/drivers/tty/serial/apbuart.c
@@ -16,7 +16,6 @@
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>
20#include <linux/ioport.h> 19#include <linux/ioport.h>
21#include <linux/init.h> 20#include <linux/init.h>
22#include <linux/serial.h> 21#include <linux/serial.h>
@@ -554,7 +553,7 @@ static struct uart_driver grlib_apbuart_driver = {
554/* OF Platform Driver */ 553/* OF Platform Driver */
555/* ======================================================================== */ 554/* ======================================================================== */
556 555
557static int apbuart_probe(struct platform_device *op) 556static int __devinit apbuart_probe(struct platform_device *op)
558{ 557{
559 int i; 558 int i;
560 struct uart_port *port = NULL; 559 struct uart_port *port = NULL;
@@ -577,7 +576,7 @@ static int apbuart_probe(struct platform_device *op)
577 return 0; 576 return 0;
578} 577}
579 578
580static struct of_device_id apbuart_match[] = { 579static struct of_device_id __initdata apbuart_match[] = {
581 { 580 {
582 .name = "GAISLER_APBUART", 581 .name = "GAISLER_APBUART",
583 }, 582 },
@@ -597,7 +596,7 @@ static struct platform_driver grlib_apbuart_of_driver = {
597}; 596};
598 597
599 598
600static int __init grlib_apbuart_configure(void) 599static int grlib_apbuart_configure(void)
601{ 600{
602 struct device_node *np; 601 struct device_node *np;
603 int line = 0; 602 int line = 0;
diff --git a/drivers/tty/serial/ar933x_uart.c b/drivers/tty/serial/ar933x_uart.c
deleted file mode 100644
index 505c490c0b4..00000000000
--- a/drivers/tty/serial/ar933x_uart.c
+++ /dev/null
@@ -1,768 +0,0 @@
1/*
2 * Atheros AR933X SoC built-in UART driver
3 *
4 * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/ioport.h>
15#include <linux/init.h>
16#include <linux/console.h>
17#include <linux/sysrq.h>
18#include <linux/delay.h>
19#include <linux/platform_device.h>
20#include <linux/tty.h>
21#include <linux/tty_flip.h>
22#include <linux/serial_core.h>
23#include <linux/serial.h>
24#include <linux/slab.h>
25#include <linux/io.h>
26#include <linux/irq.h>
27
28#include <asm/div64.h>
29
30#include <asm/mach-ath79/ar933x_uart.h>
31#include <asm/mach-ath79/ar933x_uart_platform.h>
32
33#define DRIVER_NAME "ar933x-uart"
34
35#define AR933X_UART_MAX_SCALE 0xff
36#define AR933X_UART_MAX_STEP 0xffff
37
38#define AR933X_UART_MIN_BAUD 300
39#define AR933X_UART_MAX_BAUD 3000000
40
41#define AR933X_DUMMY_STATUS_RD 0x01
42
43static struct uart_driver ar933x_uart_driver;
44
45struct ar933x_uart_port {
46 struct uart_port port;
47 unsigned int ier; /* shadow Interrupt Enable Register */
48 unsigned int min_baud;
49 unsigned int max_baud;
50};
51
52static inline unsigned int ar933x_uart_read(struct ar933x_uart_port *up,
53 int offset)
54{
55 return readl(up->port.membase + offset);
56}
57
58static inline void ar933x_uart_write(struct ar933x_uart_port *up,
59 int offset, unsigned int value)
60{
61 writel(value, up->port.membase + offset);
62}
63
64static inline void ar933x_uart_rmw(struct ar933x_uart_port *up,
65 unsigned int offset,
66 unsigned int mask,
67 unsigned int val)
68{
69 unsigned int t;
70
71 t = ar933x_uart_read(up, offset);
72 t &= ~mask;
73 t |= val;
74 ar933x_uart_write(up, offset, t);
75}
76
77static inline void ar933x_uart_rmw_set(struct ar933x_uart_port *up,
78 unsigned int offset,
79 unsigned int val)
80{
81 ar933x_uart_rmw(up, offset, 0, val);
82}
83
84static inline void ar933x_uart_rmw_clear(struct ar933x_uart_port *up,
85 unsigned int offset,
86 unsigned int val)
87{
88 ar933x_uart_rmw(up, offset, val, 0);
89}
90
91static inline void ar933x_uart_start_tx_interrupt(struct ar933x_uart_port *up)
92{
93 up->ier |= AR933X_UART_INT_TX_EMPTY;
94 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
95}
96
97static inline void ar933x_uart_stop_tx_interrupt(struct ar933x_uart_port *up)
98{
99 up->ier &= ~AR933X_UART_INT_TX_EMPTY;
100 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
101}
102
103static inline void ar933x_uart_putc(struct ar933x_uart_port *up, int ch)
104{
105 unsigned int rdata;
106
107 rdata = ch & AR933X_UART_DATA_TX_RX_MASK;
108 rdata |= AR933X_UART_DATA_TX_CSR;
109 ar933x_uart_write(up, AR933X_UART_DATA_REG, rdata);
110}
111
112static unsigned int ar933x_uart_tx_empty(struct uart_port *port)
113{
114 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
115 unsigned long flags;
116 unsigned int rdata;
117
118 spin_lock_irqsave(&up->port.lock, flags);
119 rdata = ar933x_uart_read(up, AR933X_UART_DATA_REG);
120 spin_unlock_irqrestore(&up->port.lock, flags);
121
122 return (rdata & AR933X_UART_DATA_TX_CSR) ? 0 : TIOCSER_TEMT;
123}
124
125static unsigned int ar933x_uart_get_mctrl(struct uart_port *port)
126{
127 return TIOCM_CAR;
128}
129
130static void ar933x_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
131{
132}
133
134static void ar933x_uart_start_tx(struct uart_port *port)
135{
136 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
137
138 ar933x_uart_start_tx_interrupt(up);
139}
140
141static void ar933x_uart_stop_tx(struct uart_port *port)
142{
143 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
144
145 ar933x_uart_stop_tx_interrupt(up);
146}
147
148static void ar933x_uart_stop_rx(struct uart_port *port)
149{
150 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
151
152 up->ier &= ~AR933X_UART_INT_RX_VALID;
153 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
154}
155
156static void ar933x_uart_break_ctl(struct uart_port *port, int break_state)
157{
158 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
159 unsigned long flags;
160
161 spin_lock_irqsave(&up->port.lock, flags);
162 if (break_state == -1)
163 ar933x_uart_rmw_set(up, AR933X_UART_CS_REG,
164 AR933X_UART_CS_TX_BREAK);
165 else
166 ar933x_uart_rmw_clear(up, AR933X_UART_CS_REG,
167 AR933X_UART_CS_TX_BREAK);
168 spin_unlock_irqrestore(&up->port.lock, flags);
169}
170
171static void ar933x_uart_enable_ms(struct uart_port *port)
172{
173}
174
175/*
176 * baudrate = (clk / (scale + 1)) * (step * (1 / 2^17))
177 */
178static unsigned long ar933x_uart_get_baud(unsigned int clk,
179 unsigned int scale,
180 unsigned int step)
181{
182 u64 t;
183 u32 div;
184
185 div = (2 << 16) * (scale + 1);
186 t = clk;
187 t *= step;
188 t += (div / 2);
189 do_div(t, div);
190
191 return t;
192}
193
194static void ar933x_uart_get_scale_step(unsigned int clk,
195 unsigned int baud,
196 unsigned int *scale,
197 unsigned int *step)
198{
199 unsigned int tscale;
200 long min_diff;
201
202 *scale = 0;
203 *step = 0;
204
205 min_diff = baud;
206 for (tscale = 0; tscale < AR933X_UART_MAX_SCALE; tscale++) {
207 u64 tstep;
208 int diff;
209
210 tstep = baud * (tscale + 1);
211 tstep *= (2 << 16);
212 do_div(tstep, clk);
213
214 if (tstep > AR933X_UART_MAX_STEP)
215 break;
216
217 diff = abs(ar933x_uart_get_baud(clk, tscale, tstep) - baud);
218 if (diff < min_diff) {
219 min_diff = diff;
220 *scale = tscale;
221 *step = tstep;
222 }
223 }
224}
225
226static void ar933x_uart_set_termios(struct uart_port *port,
227 struct ktermios *new,
228 struct ktermios *old)
229{
230 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
231 unsigned int cs;
232 unsigned long flags;
233 unsigned int baud, scale, step;
234
235 /* Only CS8 is supported */
236 new->c_cflag &= ~CSIZE;
237 new->c_cflag |= CS8;
238
239 /* Only one stop bit is supported */
240 new->c_cflag &= ~CSTOPB;
241
242 cs = 0;
243 if (new->c_cflag & PARENB) {
244 if (!(new->c_cflag & PARODD))
245 cs |= AR933X_UART_CS_PARITY_EVEN;
246 else
247 cs |= AR933X_UART_CS_PARITY_ODD;
248 } else {
249 cs |= AR933X_UART_CS_PARITY_NONE;
250 }
251
252 /* Mark/space parity is not supported */
253 new->c_cflag &= ~CMSPAR;
254
255 baud = uart_get_baud_rate(port, new, old, up->min_baud, up->max_baud);
256 ar933x_uart_get_scale_step(port->uartclk, baud, &scale, &step);
257
258 /*
259 * Ok, we're now changing the port state. Do it with
260 * interrupts disabled.
261 */
262 spin_lock_irqsave(&up->port.lock, flags);
263
264 /* disable the UART */
265 ar933x_uart_rmw_clear(up, AR933X_UART_CS_REG,
266 AR933X_UART_CS_IF_MODE_M << AR933X_UART_CS_IF_MODE_S);
267
268 /* Update the per-port timeout. */
269 uart_update_timeout(port, new->c_cflag, baud);
270
271 up->port.ignore_status_mask = 0;
272
273 /* ignore all characters if CREAD is not set */
274 if ((new->c_cflag & CREAD) == 0)
275 up->port.ignore_status_mask |= AR933X_DUMMY_STATUS_RD;
276
277 ar933x_uart_write(up, AR933X_UART_CLOCK_REG,
278 scale << AR933X_UART_CLOCK_SCALE_S | step);
279
280 /* setup configuration register */
281 ar933x_uart_rmw(up, AR933X_UART_CS_REG, AR933X_UART_CS_PARITY_M, cs);
282
283 /* enable host interrupt */
284 ar933x_uart_rmw_set(up, AR933X_UART_CS_REG,
285 AR933X_UART_CS_HOST_INT_EN);
286
287 /* reenable the UART */
288 ar933x_uart_rmw(up, AR933X_UART_CS_REG,
289 AR933X_UART_CS_IF_MODE_M << AR933X_UART_CS_IF_MODE_S,
290 AR933X_UART_CS_IF_MODE_DCE << AR933X_UART_CS_IF_MODE_S);
291
292 spin_unlock_irqrestore(&up->port.lock, flags);
293
294 if (tty_termios_baud_rate(new))
295 tty_termios_encode_baud_rate(new, baud, baud);
296}
297
298static void ar933x_uart_rx_chars(struct ar933x_uart_port *up)
299{
300 struct tty_struct *tty;
301 int max_count = 256;
302
303 tty = tty_port_tty_get(&up->port.state->port);
304 do {
305 unsigned int rdata;
306 unsigned char ch;
307
308 rdata = ar933x_uart_read(up, AR933X_UART_DATA_REG);
309 if ((rdata & AR933X_UART_DATA_RX_CSR) == 0)
310 break;
311
312 /* remove the character from the FIFO */
313 ar933x_uart_write(up, AR933X_UART_DATA_REG,
314 AR933X_UART_DATA_RX_CSR);
315
316 if (!tty) {
317 /* discard the data if no tty available */
318 continue;
319 }
320
321 up->port.icount.rx++;
322 ch = rdata & AR933X_UART_DATA_TX_RX_MASK;
323
324 if (uart_handle_sysrq_char(&up->port, ch))
325 continue;
326
327 if ((up->port.ignore_status_mask & AR933X_DUMMY_STATUS_RD) == 0)
328 tty_insert_flip_char(tty, ch, TTY_NORMAL);
329 } while (max_count-- > 0);
330
331 if (tty) {
332 tty_flip_buffer_push(tty);
333 tty_kref_put(tty);
334 }
335}
336
337static void ar933x_uart_tx_chars(struct ar933x_uart_port *up)
338{
339 struct circ_buf *xmit = &up->port.state->xmit;
340 int count;
341
342 if (uart_tx_stopped(&up->port))
343 return;
344
345 count = up->port.fifosize;
346 do {
347 unsigned int rdata;
348
349 rdata = ar933x_uart_read(up, AR933X_UART_DATA_REG);
350 if ((rdata & AR933X_UART_DATA_TX_CSR) == 0)
351 break;
352
353 if (up->port.x_char) {
354 ar933x_uart_putc(up, up->port.x_char);
355 up->port.icount.tx++;
356 up->port.x_char = 0;
357 continue;
358 }
359
360 if (uart_circ_empty(xmit))
361 break;
362
363 ar933x_uart_putc(up, xmit->buf[xmit->tail]);
364
365 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
366 up->port.icount.tx++;
367 } while (--count > 0);
368
369 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
370 uart_write_wakeup(&up->port);
371
372 if (!uart_circ_empty(xmit))
373 ar933x_uart_start_tx_interrupt(up);
374}
375
376static irqreturn_t ar933x_uart_interrupt(int irq, void *dev_id)
377{
378 struct ar933x_uart_port *up = dev_id;
379 unsigned int status;
380
381 status = ar933x_uart_read(up, AR933X_UART_CS_REG);
382 if ((status & AR933X_UART_CS_HOST_INT) == 0)
383 return IRQ_NONE;
384
385 spin_lock(&up->port.lock);
386
387 status = ar933x_uart_read(up, AR933X_UART_INT_REG);
388 status &= ar933x_uart_read(up, AR933X_UART_INT_EN_REG);
389
390 if (status & AR933X_UART_INT_RX_VALID) {
391 ar933x_uart_write(up, AR933X_UART_INT_REG,
392 AR933X_UART_INT_RX_VALID);
393 ar933x_uart_rx_chars(up);
394 }
395
396 if (status & AR933X_UART_INT_TX_EMPTY) {
397 ar933x_uart_write(up, AR933X_UART_INT_REG,
398 AR933X_UART_INT_TX_EMPTY);
399 ar933x_uart_stop_tx_interrupt(up);
400 ar933x_uart_tx_chars(up);
401 }
402
403 spin_unlock(&up->port.lock);
404
405 return IRQ_HANDLED;
406}
407
408static int ar933x_uart_startup(struct uart_port *port)
409{
410 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
411 unsigned long flags;
412 int ret;
413
414 ret = request_irq(up->port.irq, ar933x_uart_interrupt,
415 up->port.irqflags, dev_name(up->port.dev), up);
416 if (ret)
417 return ret;
418
419 spin_lock_irqsave(&up->port.lock, flags);
420
421 /* Enable HOST interrupts */
422 ar933x_uart_rmw_set(up, AR933X_UART_CS_REG,
423 AR933X_UART_CS_HOST_INT_EN);
424
425 /* Enable RX interrupts */
426 up->ier = AR933X_UART_INT_RX_VALID;
427 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
428
429 spin_unlock_irqrestore(&up->port.lock, flags);
430
431 return 0;
432}
433
434static void ar933x_uart_shutdown(struct uart_port *port)
435{
436 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
437
438 /* Disable all interrupts */
439 up->ier = 0;
440 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
441
442 /* Disable break condition */
443 ar933x_uart_rmw_clear(up, AR933X_UART_CS_REG,
444 AR933X_UART_CS_TX_BREAK);
445
446 free_irq(up->port.irq, up);
447}
448
449static const char *ar933x_uart_type(struct uart_port *port)
450{
451 return (port->type == PORT_AR933X) ? "AR933X UART" : NULL;
452}
453
454static void ar933x_uart_release_port(struct uart_port *port)
455{
456 /* Nothing to release ... */
457}
458
459static int ar933x_uart_request_port(struct uart_port *port)
460{
461 /* UARTs always present */
462 return 0;
463}
464
465static void ar933x_uart_config_port(struct uart_port *port, int flags)
466{
467 if (flags & UART_CONFIG_TYPE)
468 port->type = PORT_AR933X;
469}
470
471static int ar933x_uart_verify_port(struct uart_port *port,
472 struct serial_struct *ser)
473{
474 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
475
476 if (ser->type != PORT_UNKNOWN &&
477 ser->type != PORT_AR933X)
478 return -EINVAL;
479
480 if (ser->irq < 0 || ser->irq >= NR_IRQS)
481 return -EINVAL;
482
483 if (ser->baud_base < up->min_baud ||
484 ser->baud_base > up->max_baud)
485 return -EINVAL;
486
487 return 0;
488}
489
490static struct uart_ops ar933x_uart_ops = {
491 .tx_empty = ar933x_uart_tx_empty,
492 .set_mctrl = ar933x_uart_set_mctrl,
493 .get_mctrl = ar933x_uart_get_mctrl,
494 .stop_tx = ar933x_uart_stop_tx,
495 .start_tx = ar933x_uart_start_tx,
496 .stop_rx = ar933x_uart_stop_rx,
497 .enable_ms = ar933x_uart_enable_ms,
498 .break_ctl = ar933x_uart_break_ctl,
499 .startup = ar933x_uart_startup,
500 .shutdown = ar933x_uart_shutdown,
501 .set_termios = ar933x_uart_set_termios,
502 .type = ar933x_uart_type,
503 .release_port = ar933x_uart_release_port,
504 .request_port = ar933x_uart_request_port,
505 .config_port = ar933x_uart_config_port,
506 .verify_port = ar933x_uart_verify_port,
507};
508
509#ifdef CONFIG_SERIAL_AR933X_CONSOLE
510
511static struct ar933x_uart_port *
512ar933x_console_ports[CONFIG_SERIAL_AR933X_NR_UARTS];
513
514static void ar933x_uart_wait_xmitr(struct ar933x_uart_port *up)
515{
516 unsigned int status;
517 unsigned int timeout = 60000;
518
519 /* Wait up to 60ms for the character(s) to be sent. */
520 do {
521 status = ar933x_uart_read(up, AR933X_UART_DATA_REG);
522 if (--timeout == 0)
523 break;
524 udelay(1);
525 } while ((status & AR933X_UART_DATA_TX_CSR) == 0);
526}
527
528static void ar933x_uart_console_putchar(struct uart_port *port, int ch)
529{
530 struct ar933x_uart_port *up = (struct ar933x_uart_port *) port;
531
532 ar933x_uart_wait_xmitr(up);
533 ar933x_uart_putc(up, ch);
534}
535
536static void ar933x_uart_console_write(struct console *co, const char *s,
537 unsigned int count)
538{
539 struct ar933x_uart_port *up = ar933x_console_ports[co->index];
540 unsigned long flags;
541 unsigned int int_en;
542 int locked = 1;
543
544 local_irq_save(flags);
545
546 if (up->port.sysrq)
547 locked = 0;
548 else if (oops_in_progress)
549 locked = spin_trylock(&up->port.lock);
550 else
551 spin_lock(&up->port.lock);
552
553 /*
554 * First save the IER then disable the interrupts
555 */
556 int_en = ar933x_uart_read(up, AR933X_UART_INT_EN_REG);
557 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, 0);
558
559 uart_console_write(&up->port, s, count, ar933x_uart_console_putchar);
560
561 /*
562 * Finally, wait for transmitter to become empty
563 * and restore the IER
564 */
565 ar933x_uart_wait_xmitr(up);
566 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, int_en);
567
568 ar933x_uart_write(up, AR933X_UART_INT_REG, AR933X_UART_INT_ALLINTS);
569
570 if (locked)
571 spin_unlock(&up->port.lock);
572
573 local_irq_restore(flags);
574}
575
576static int ar933x_uart_console_setup(struct console *co, char *options)
577{
578 struct ar933x_uart_port *up;
579 int baud = 115200;
580 int bits = 8;
581 int parity = 'n';
582 int flow = 'n';
583
584 if (co->index < 0 || co->index >= CONFIG_SERIAL_AR933X_NR_UARTS)
585 return -EINVAL;
586
587 up = ar933x_console_ports[co->index];
588 if (!up)
589 return -ENODEV;
590
591 if (options)
592 uart_parse_options(options, &baud, &parity, &bits, &flow);
593
594 return uart_set_options(&up->port, co, baud, parity, bits, flow);
595}
596
597static struct console ar933x_uart_console = {
598 .name = "ttyATH",
599 .write = ar933x_uart_console_write,
600 .device = uart_console_device,
601 .setup = ar933x_uart_console_setup,
602 .flags = CON_PRINTBUFFER,
603 .index = -1,
604 .data = &ar933x_uart_driver,
605};
606
607static void ar933x_uart_add_console_port(struct ar933x_uart_port *up)
608{
609 ar933x_console_ports[up->port.line] = up;
610}
611
612#define AR933X_SERIAL_CONSOLE (&ar933x_uart_console)
613
614#else
615
616static inline void ar933x_uart_add_console_port(struct ar933x_uart_port *up) {}
617
618#define AR933X_SERIAL_CONSOLE NULL
619
620#endif /* CONFIG_SERIAL_AR933X_CONSOLE */
621
622static struct uart_driver ar933x_uart_driver = {
623 .owner = THIS_MODULE,
624 .driver_name = DRIVER_NAME,
625 .dev_name = "ttyATH",
626 .nr = CONFIG_SERIAL_AR933X_NR_UARTS,
627 .cons = AR933X_SERIAL_CONSOLE,
628};
629
630static int ar933x_uart_probe(struct platform_device *pdev)
631{
632 struct ar933x_uart_platform_data *pdata;
633 struct ar933x_uart_port *up;
634 struct uart_port *port;
635 struct resource *mem_res;
636 struct resource *irq_res;
637 unsigned int baud;
638 int id;
639 int ret;
640
641 pdata = pdev->dev.platform_data;
642 if (!pdata)
643 return -EINVAL;
644
645 id = pdev->id;
646 if (id == -1)
647 id = 0;
648
649 if (id > CONFIG_SERIAL_AR933X_NR_UARTS)
650 return -EINVAL;
651
652 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
653 if (!mem_res) {
654 dev_err(&pdev->dev, "no MEM resource\n");
655 return -EINVAL;
656 }
657
658 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
659 if (!irq_res) {
660 dev_err(&pdev->dev, "no IRQ resource\n");
661 return -EINVAL;
662 }
663
664 up = kzalloc(sizeof(struct ar933x_uart_port), GFP_KERNEL);
665 if (!up)
666 return -ENOMEM;
667
668 port = &up->port;
669 port->mapbase = mem_res->start;
670
671 port->membase = ioremap(mem_res->start, AR933X_UART_REGS_SIZE);
672 if (!port->membase) {
673 ret = -ENOMEM;
674 goto err_free_up;
675 }
676
677 port->line = id;
678 port->irq = irq_res->start;
679 port->dev = &pdev->dev;
680 port->type = PORT_AR933X;
681 port->iotype = UPIO_MEM32;
682 port->uartclk = pdata->uartclk;
683
684 port->regshift = 2;
685 port->fifosize = AR933X_UART_FIFO_SIZE;
686 port->ops = &ar933x_uart_ops;
687
688 baud = ar933x_uart_get_baud(port->uartclk, AR933X_UART_MAX_SCALE, 1);
689 up->min_baud = max_t(unsigned int, baud, AR933X_UART_MIN_BAUD);
690
691 baud = ar933x_uart_get_baud(port->uartclk, 0, AR933X_UART_MAX_STEP);
692 up->max_baud = min_t(unsigned int, baud, AR933X_UART_MAX_BAUD);
693
694 ar933x_uart_add_console_port(up);
695
696 ret = uart_add_one_port(&ar933x_uart_driver, &up->port);
697 if (ret)
698 goto err_unmap;
699
700 platform_set_drvdata(pdev, up);
701 return 0;
702
703err_unmap:
704 iounmap(up->port.membase);
705err_free_up:
706 kfree(up);
707 return ret;
708}
709
710static int ar933x_uart_remove(struct platform_device *pdev)
711{
712 struct ar933x_uart_port *up;
713
714 up = platform_get_drvdata(pdev);
715 platform_set_drvdata(pdev, NULL);
716
717 if (up) {
718 uart_remove_one_port(&ar933x_uart_driver, &up->port);
719 iounmap(up->port.membase);
720 kfree(up);
721 }
722
723 return 0;
724}
725
726static struct platform_driver ar933x_uart_platform_driver = {
727 .probe = ar933x_uart_probe,
728 .remove = ar933x_uart_remove,
729 .driver = {
730 .name = DRIVER_NAME,
731 .owner = THIS_MODULE,
732 },
733};
734
735static int __init ar933x_uart_init(void)
736{
737 int ret;
738
739 ar933x_uart_driver.nr = CONFIG_SERIAL_AR933X_NR_UARTS;
740 ret = uart_register_driver(&ar933x_uart_driver);
741 if (ret)
742 goto err_out;
743
744 ret = platform_driver_register(&ar933x_uart_platform_driver);
745 if (ret)
746 goto err_unregister_uart_driver;
747
748 return 0;
749
750err_unregister_uart_driver:
751 uart_unregister_driver(&ar933x_uart_driver);
752err_out:
753 return ret;
754}
755
756static void __exit ar933x_uart_exit(void)
757{
758 platform_driver_unregister(&ar933x_uart_platform_driver);
759 uart_unregister_driver(&ar933x_uart_driver);
760}
761
762module_init(ar933x_uart_init);
763module_exit(ar933x_uart_exit);
764
765MODULE_DESCRIPTION("Atheros AR933X UART driver");
766MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
767MODULE_LICENSE("GPL v2");
768MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c
deleted file mode 100644
index 3e0b3fac6a0..00000000000
--- a/drivers/tty/serial/arc_uart.c
+++ /dev/null
@@ -1,746 +0,0 @@
1/*
2 * ARC On-Chip(fpga) UART Driver
3 *
4 * Copyright (C) 2010-2012 Synopsys, Inc. (www.synopsys.com)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * vineetg: July 10th 2012
11 * -Decoupled the driver from arch/arc
12 * +Using platform_get_resource() for irq/membase (thx to bfin_uart.c)
13 * +Using early_platform_xxx() for early console (thx to mach-shmobile/xxx)
14 *
15 * Vineetg: Aug 21st 2010
16 * -Is uart_tx_stopped() not done in tty write path as it has already been
17 * taken care of, in serial core
18 *
19 * Vineetg: Aug 18th 2010
20 * -New Serial Core based ARC UART driver
21 * -Derived largely from blackfin driver albiet with some major tweaks
22 *
23 * TODO:
24 * -check if sysreq works
25 */
26
27#if defined(CONFIG_SERIAL_ARC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
28#define SUPPORT_SYSRQ
29#endif
30
31#include <linux/module.h>
32#include <linux/serial.h>
33#include <linux/console.h>
34#include <linux/sysrq.h>
35#include <linux/platform_device.h>
36#include <linux/tty.h>
37#include <linux/tty_flip.h>
38#include <linux/serial_core.h>
39#include <linux/io.h>
40
41/*************************************
42 * ARC UART Hardware Specs
43 ************************************/
44#define ARC_UART_TX_FIFO_SIZE 1
45
46/*
47 * UART Register set (this is not a Standards Compliant IP)
48 * Also each reg is Word aligned, but only 8 bits wide
49 */
50#define R_ID0 0
51#define R_ID1 4
52#define R_ID2 8
53#define R_ID3 12
54#define R_DATA 16
55#define R_STS 20
56#define R_BAUDL 24
57#define R_BAUDH 28
58
59/* Bits for UART Status Reg (R/W) */
60#define RXIENB 0x04 /* Receive Interrupt Enable */
61#define TXIENB 0x40 /* Transmit Interrupt Enable */
62
63#define RXEMPTY 0x20 /* Receive FIFO Empty: No char receivede */
64#define TXEMPTY 0x80 /* Transmit FIFO Empty, thus char can be written into */
65
66#define RXFULL 0x08 /* Receive FIFO full */
67#define RXFULL1 0x10 /* Receive FIFO has space for 1 char (tot space=4) */
68
69#define RXFERR 0x01 /* Frame Error: Stop Bit not detected */
70#define RXOERR 0x02 /* OverFlow Err: Char recv but RXFULL still set */
71
72/* Uart bit fiddling helpers: lowest level */
73#define RBASE(uart, reg) (uart->port.membase + reg)
74#define UART_REG_SET(u, r, v) writeb((v), RBASE(u, r))
75#define UART_REG_GET(u, r) readb(RBASE(u, r))
76
77#define UART_REG_OR(u, r, v) UART_REG_SET(u, r, UART_REG_GET(u, r) | (v))
78#define UART_REG_CLR(u, r, v) UART_REG_SET(u, r, UART_REG_GET(u, r) & ~(v))
79
80/* Uart bit fiddling helpers: API level */
81#define UART_SET_DATA(uart, val) UART_REG_SET(uart, R_DATA, val)
82#define UART_GET_DATA(uart) UART_REG_GET(uart, R_DATA)
83
84#define UART_SET_BAUDH(uart, val) UART_REG_SET(uart, R_BAUDH, val)
85#define UART_SET_BAUDL(uart, val) UART_REG_SET(uart, R_BAUDL, val)
86
87#define UART_CLR_STATUS(uart, val) UART_REG_CLR(uart, R_STS, val)
88#define UART_GET_STATUS(uart) UART_REG_GET(uart, R_STS)
89
90#define UART_ALL_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, RXIENB|TXIENB)
91#define UART_RX_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, RXIENB)
92#define UART_TX_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, TXIENB)
93
94#define UART_ALL_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, RXIENB|TXIENB)
95#define UART_RX_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, RXIENB)
96#define UART_TX_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, TXIENB)
97
98#define ARC_SERIAL_DEV_NAME "ttyARC"
99
100struct arc_uart_port {
101 struct uart_port port;
102 unsigned long baud;
103 int is_emulated; /* H/w vs. Instruction Set Simulator */
104};
105
106#define to_arc_port(uport) container_of(uport, struct arc_uart_port, port)
107
108static struct arc_uart_port arc_uart_ports[CONFIG_SERIAL_ARC_NR_PORTS];
109
110#ifdef CONFIG_SERIAL_ARC_CONSOLE
111static struct console arc_console;
112#endif
113
114#define DRIVER_NAME "arc-uart"
115
116static struct uart_driver arc_uart_driver = {
117 .owner = THIS_MODULE,
118 .driver_name = DRIVER_NAME,
119 .dev_name = ARC_SERIAL_DEV_NAME,
120 .major = 0,
121 .minor = 0,
122 .nr = CONFIG_SERIAL_ARC_NR_PORTS,
123#ifdef CONFIG_SERIAL_ARC_CONSOLE
124 .cons = &arc_console,
125#endif
126};
127
128static void arc_serial_stop_rx(struct uart_port *port)
129{
130 struct arc_uart_port *uart = to_arc_port(port);
131
132 UART_RX_IRQ_DISABLE(uart);
133}
134
135static void arc_serial_stop_tx(struct uart_port *port)
136{
137 struct arc_uart_port *uart = to_arc_port(port);
138
139 while (!(UART_GET_STATUS(uart) & TXEMPTY))
140 cpu_relax();
141
142 UART_TX_IRQ_DISABLE(uart);
143}
144
145/*
146 * Return TIOCSER_TEMT when transmitter is not busy.
147 */
148static unsigned int arc_serial_tx_empty(struct uart_port *port)
149{
150 struct arc_uart_port *uart = to_arc_port(port);
151 unsigned int stat;
152
153 stat = UART_GET_STATUS(uart);
154 if (stat & TXEMPTY)
155 return TIOCSER_TEMT;
156
157 return 0;
158}
159
160/*
161 * Driver internal routine, used by both tty(serial core) as well as tx-isr
162 * -Called under spinlock in either cases
163 * -also tty->stopped / tty->hw_stopped has already been checked
164 * = by uart_start( ) before calling us
165 * = tx_ist checks that too before calling
166 */
167static void arc_serial_tx_chars(struct arc_uart_port *uart)
168{
169 struct circ_buf *xmit = &uart->port.state->xmit;
170 int sent = 0;
171 unsigned char ch;
172
173 if (unlikely(uart->port.x_char)) {
174 UART_SET_DATA(uart, uart->port.x_char);
175 uart->port.icount.tx++;
176 uart->port.x_char = 0;
177 sent = 1;
178 } else if (xmit->tail != xmit->head) { /* TODO: uart_circ_empty */
179 ch = xmit->buf[xmit->tail];
180 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
181 uart->port.icount.tx++;
182 while (!(UART_GET_STATUS(uart) & TXEMPTY))
183 cpu_relax();
184 UART_SET_DATA(uart, ch);
185 sent = 1;
186 }
187
188 /*
189 * If num chars in xmit buffer are too few, ask tty layer for more.
190 * By Hard ISR to schedule processing in software interrupt part
191 */
192 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
193 uart_write_wakeup(&uart->port);
194
195 if (sent)
196 UART_TX_IRQ_ENABLE(uart);
197}
198
199/*
200 * port is locked and interrupts are disabled
201 * uart_start( ) calls us under the port spinlock irqsave
202 */
203static void arc_serial_start_tx(struct uart_port *port)
204{
205 struct arc_uart_port *uart = to_arc_port(port);
206
207 arc_serial_tx_chars(uart);
208}
209
210static void arc_serial_rx_chars(struct arc_uart_port *uart)
211{
212 struct tty_struct *tty = tty_port_tty_get(&uart->port.state->port);
213 unsigned int status, ch, flg = 0;
214
215 if (!tty)
216 return;
217
218 /*
219 * UART has 4 deep RX-FIFO. Driver's recongnition of this fact
220 * is very subtle. Here's how ...
221 * Upon getting a RX-Intr, such that RX-EMPTY=0, meaning data available,
222 * driver reads the DATA Reg and keeps doing that in a loop, until
223 * RX-EMPTY=1. Multiple chars being avail, with a single Interrupt,
224 * before RX-EMPTY=0, implies some sort of buffering going on in the
225 * controller, which is indeed the Rx-FIFO.
226 */
227 while (!((status = UART_GET_STATUS(uart)) & RXEMPTY)) {
228
229 ch = UART_GET_DATA(uart);
230 uart->port.icount.rx++;
231
232 if (unlikely(status & (RXOERR | RXFERR))) {
233 if (status & RXOERR) {
234 uart->port.icount.overrun++;
235 flg = TTY_OVERRUN;
236 UART_CLR_STATUS(uart, RXOERR);
237 }
238
239 if (status & RXFERR) {
240 uart->port.icount.frame++;
241 flg = TTY_FRAME;
242 UART_CLR_STATUS(uart, RXFERR);
243 }
244 } else
245 flg = TTY_NORMAL;
246
247 if (unlikely(uart_handle_sysrq_char(&uart->port, ch)))
248 goto done;
249
250 uart_insert_char(&uart->port, status, RXOERR, ch, flg);
251
252done:
253 tty_flip_buffer_push(tty);
254 }
255
256 tty_kref_put(tty);
257}
258
259/*
260 * A note on the Interrupt handling state machine of this driver
261 *
262 * kernel printk writes funnel thru the console driver framework and in order
263 * to keep things simple as well as efficient, it writes to UART in polled
264 * mode, in one shot, and exits.
265 *
266 * OTOH, Userland output (via tty layer), uses interrupt based writes as there
267 * can be undeterministic delay between char writes.
268 *
269 * Thus Rx-interrupts are always enabled, while tx-interrupts are by default
270 * disabled.
271 *
272 * When tty has some data to send out, serial core calls driver's start_tx
273 * which
274 * -checks-if-tty-buffer-has-char-to-send
275 * -writes-data-to-uart
276 * -enable-tx-intr
277 *
278 * Once data bits are pushed out, controller raises the Tx-room-avail-Interrupt.
279 * The first thing Tx ISR does is disable further Tx interrupts (as this could
280 * be the last char to send, before settling down into the quiet polled mode).
281 * It then calls the exact routine used by tty layer write to send out any
282 * more char in tty buffer. In case of sending, it re-enables Tx-intr. In case
283 * of no data, it remains disabled.
284 * This is how the transmit state machine is dynamically switched on/off
285 */
286
287static irqreturn_t arc_serial_isr(int irq, void *dev_id)
288{
289 struct arc_uart_port *uart = dev_id;
290 unsigned int status;
291
292 status = UART_GET_STATUS(uart);
293
294 /*
295 * Single IRQ for both Rx (data available) Tx (room available) Interrupt
296 * notifications from the UART Controller.
297 * To demultiplex between the two, we check the relevant bits
298 */
299 if ((status & RXIENB) && !(status & RXEMPTY)) {
300
301 /* already in ISR, no need of xx_irqsave */
302 spin_lock(&uart->port.lock);
303 arc_serial_rx_chars(uart);
304 spin_unlock(&uart->port.lock);
305 }
306
307 if ((status & TXIENB) && (status & TXEMPTY)) {
308
309 /* Unconditionally disable further Tx-Interrupts.
310 * will be enabled by tx_chars() if needed.
311 */
312 UART_TX_IRQ_DISABLE(uart);
313
314 spin_lock(&uart->port.lock);
315
316 if (!uart_tx_stopped(&uart->port))
317 arc_serial_tx_chars(uart);
318
319 spin_unlock(&uart->port.lock);
320 }
321
322 return IRQ_HANDLED;
323}
324
325static unsigned int arc_serial_get_mctrl(struct uart_port *port)
326{
327 /*
328 * Pretend we have a Modem status reg and following bits are
329 * always set, to satify the serial core state machine
330 * (DSR) Data Set Ready
331 * (CTS) Clear To Send
332 * (CAR) Carrier Detect
333 */
334 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
335}
336
337static void arc_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
338{
339 /* MCR not present */
340}
341
342/* Enable Modem Status Interrupts */
343
344static void arc_serial_enable_ms(struct uart_port *port)
345{
346 /* MSR not present */
347}
348
349static void arc_serial_break_ctl(struct uart_port *port, int break_state)
350{
351 /* ARC UART doesn't support sending Break signal */
352}
353
354static int arc_serial_startup(struct uart_port *port)
355{
356 struct arc_uart_port *uart = to_arc_port(port);
357
358 /* Before we hook up the ISR, Disable all UART Interrupts */
359 UART_ALL_IRQ_DISABLE(uart);
360
361 if (request_irq(uart->port.irq, arc_serial_isr, 0, "arc uart rx-tx",
362 uart)) {
363 dev_warn(uart->port.dev, "Unable to attach ARC UART intr\n");
364 return -EBUSY;
365 }
366
367 UART_RX_IRQ_ENABLE(uart); /* Only Rx IRQ enabled to begin with */
368
369 return 0;
370}
371
372/* This is not really needed */
373static void arc_serial_shutdown(struct uart_port *port)
374{
375 struct arc_uart_port *uart = to_arc_port(port);
376 free_irq(uart->port.irq, uart);
377}
378
379static void
380arc_serial_set_termios(struct uart_port *port, struct ktermios *new,
381 struct ktermios *old)
382{
383 struct arc_uart_port *uart = to_arc_port(port);
384 unsigned int baud, uartl, uarth, hw_val;
385 unsigned long flags;
386
387 /*
388 * Use the generic handler so that any specially encoded baud rates
389 * such as SPD_xx flags or "%B0" can be handled
390 * Max Baud I suppose will not be more than current 115K * 4
391 * Formula for ARC UART is: hw-val = ((CLK/(BAUD*4)) -1)
392 * spread over two 8-bit registers
393 */
394 baud = uart_get_baud_rate(port, new, old, 0, 460800);
395
396 hw_val = port->uartclk / (uart->baud * 4) - 1;
397 uartl = hw_val & 0xFF;
398 uarth = (hw_val >> 8) & 0xFF;
399
400 /*
401 * UART ISS(Instruction Set simulator) emulation has a subtle bug:
402 * A existing value of Baudh = 0 is used as a indication to startup
403 * it's internal state machine.
404 * Thus if baudh is set to 0, 2 times, it chokes.
405 * This happens with BAUD=115200 and the formaula above
406 * Until that is fixed, when running on ISS, we will set baudh to !0
407 */
408 if (uart->is_emulated)
409 uarth = 1;
410
411 spin_lock_irqsave(&port->lock, flags);
412
413 UART_ALL_IRQ_DISABLE(uart);
414
415 UART_SET_BAUDL(uart, uartl);
416 UART_SET_BAUDH(uart, uarth);
417
418 UART_RX_IRQ_ENABLE(uart);
419
420 /*
421 * UART doesn't support Parity/Hardware Flow Control;
422 * Only supports 8N1 character size
423 */
424 new->c_cflag &= ~(CMSPAR|CRTSCTS|CSIZE);
425 new->c_cflag |= CS8;
426
427 if (old)
428 tty_termios_copy_hw(new, old);
429
430 /* Don't rewrite B0 */
431 if (tty_termios_baud_rate(new))
432 tty_termios_encode_baud_rate(new, baud, baud);
433
434 uart_update_timeout(port, new->c_cflag, baud);
435
436 spin_unlock_irqrestore(&port->lock, flags);
437}
438
439static const char *arc_serial_type(struct uart_port *port)
440{
441 struct arc_uart_port *uart = to_arc_port(port);
442
443 return uart->port.type == PORT_ARC ? DRIVER_NAME : NULL;
444}
445
446static void arc_serial_release_port(struct uart_port *port)
447{
448}
449
450static int arc_serial_request_port(struct uart_port *port)
451{
452 return 0;
453}
454
455/*
456 * Verify the new serial_struct (for TIOCSSERIAL).
457 */
458static int
459arc_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
460{
461 if (port->type != PORT_UNKNOWN && ser->type != PORT_ARC)
462 return -EINVAL;
463
464 return 0;
465}
466
467/*
468 * Configure/autoconfigure the port.
469 */
470static void arc_serial_config_port(struct uart_port *port, int flags)
471{
472 struct arc_uart_port *uart = to_arc_port(port);
473
474 if (flags & UART_CONFIG_TYPE)
475 uart->port.type = PORT_ARC;
476}
477
478#if defined(CONFIG_CONSOLE_POLL) || defined(CONFIG_SERIAL_ARC_CONSOLE)
479
480static void arc_serial_poll_putchar(struct uart_port *port, unsigned char chr)
481{
482 struct arc_uart_port *uart = to_arc_port(port);
483
484 while (!(UART_GET_STATUS(uart) & TXEMPTY))
485 cpu_relax();
486
487 UART_SET_DATA(uart, chr);
488}
489#endif
490
491#ifdef CONFIG_CONSOLE_POLL
492static int arc_serial_poll_getchar(struct uart_port *port)
493{
494 struct arc_uart_port *uart = to_arc_port(port);
495 unsigned char chr;
496
497 while (!(UART_GET_STATUS(uart) & RXEMPTY))
498 cpu_relax();
499
500 chr = UART_GET_DATA(uart);
501 return chr;
502}
503#endif
504
505static struct uart_ops arc_serial_pops = {
506 .tx_empty = arc_serial_tx_empty,
507 .set_mctrl = arc_serial_set_mctrl,
508 .get_mctrl = arc_serial_get_mctrl,
509 .stop_tx = arc_serial_stop_tx,
510 .start_tx = arc_serial_start_tx,
511 .stop_rx = arc_serial_stop_rx,
512 .enable_ms = arc_serial_enable_ms,
513 .break_ctl = arc_serial_break_ctl,
514 .startup = arc_serial_startup,
515 .shutdown = arc_serial_shutdown,
516 .set_termios = arc_serial_set_termios,
517 .type = arc_serial_type,
518 .release_port = arc_serial_release_port,
519 .request_port = arc_serial_request_port,
520 .config_port = arc_serial_config_port,
521 .verify_port = arc_serial_verify_port,
522#ifdef CONFIG_CONSOLE_POLL
523 .poll_put_char = arc_serial_poll_putchar,
524 .poll_get_char = arc_serial_poll_getchar,
525#endif
526};
527
528static int
529arc_uart_init_one(struct platform_device *pdev, struct arc_uart_port *uart)
530{
531 struct resource *res, *res2;
532 unsigned long *plat_data;
533
534 if (pdev->id < 0 || pdev->id >= CONFIG_SERIAL_ARC_NR_PORTS) {
535 dev_err(&pdev->dev, "Wrong uart platform device id.\n");
536 return -ENOENT;
537 }
538
539 plat_data = ((unsigned long *)(pdev->dev.platform_data));
540 uart->baud = plat_data[0];
541
542 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
543 if (!res)
544 return -ENODEV;
545
546 res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
547 if (!res2)
548 return -ENODEV;
549
550 uart->port.mapbase = res->start;
551 uart->port.membase = ioremap_nocache(res->start, resource_size(res));
552 if (!uart->port.membase)
553 /* No point of dev_err since UART itself is hosed here */
554 return -ENXIO;
555
556 uart->port.irq = res2->start;
557 uart->port.dev = &pdev->dev;
558 uart->port.iotype = UPIO_MEM;
559 uart->port.flags = UPF_BOOT_AUTOCONF;
560 uart->port.line = pdev->id;
561 uart->port.ops = &arc_serial_pops;
562
563 uart->port.uartclk = plat_data[1];
564 uart->port.fifosize = ARC_UART_TX_FIFO_SIZE;
565
566 /*
567 * uart_insert_char( ) uses it in decideding whether to ignore a
568 * char or not. Explicitly setting it here, removes the subtelty
569 */
570 uart->port.ignore_status_mask = 0;
571
572 /* Real Hardware vs. emulated to work around a bug */
573 uart->is_emulated = !!plat_data[2];
574
575 return 0;
576}
577
578#ifdef CONFIG_SERIAL_ARC_CONSOLE
579
580static int arc_serial_console_setup(struct console *co, char *options)
581{
582 struct uart_port *port;
583 int baud = 115200;
584 int bits = 8;
585 int parity = 'n';
586 int flow = 'n';
587
588 if (co->index < 0 || co->index >= CONFIG_SERIAL_ARC_NR_PORTS)
589 return -ENODEV;
590
591 /*
592 * The uart port backing the console (e.g. ttyARC1) might not have been
593 * init yet. If so, defer the console setup to after the port.
594 */
595 port = &arc_uart_ports[co->index].port;
596 if (!port->membase)
597 return -ENODEV;
598
599 if (options)
600 uart_parse_options(options, &baud, &parity, &bits, &flow);
601
602 /*
603 * Serial core will call port->ops->set_termios( )
604 * which will set the baud reg
605 */
606 return uart_set_options(port, co, baud, parity, bits, flow);
607}
608
609static void arc_serial_console_putchar(struct uart_port *port, int ch)
610{
611 arc_serial_poll_putchar(port, (unsigned char)ch);
612}
613
614/*
615 * Interrupts are disabled on entering
616 */
617static void arc_serial_console_write(struct console *co, const char *s,
618 unsigned int count)
619{
620 struct uart_port *port = &arc_uart_ports[co->index].port;
621 unsigned long flags;
622
623 spin_lock_irqsave(&port->lock, flags);
624 uart_console_write(port, s, count, arc_serial_console_putchar);
625 spin_unlock_irqrestore(&port->lock, flags);
626}
627
628static struct console arc_console = {
629 .name = ARC_SERIAL_DEV_NAME,
630 .write = arc_serial_console_write,
631 .device = uart_console_device,
632 .setup = arc_serial_console_setup,
633 .flags = CON_PRINTBUFFER,
634 .index = -1,
635 .data = &arc_uart_driver
636};
637
638static __init void early_serial_write(struct console *con, const char *s,
639 unsigned int n)
640{
641 struct uart_port *port = &arc_uart_ports[con->index].port;
642 unsigned int i;
643
644 for (i = 0; i < n; i++, s++) {
645 if (*s == '\n')
646 arc_serial_poll_putchar(port, '\r');
647 arc_serial_poll_putchar(port, *s);
648 }
649}
650
651static struct __initdata console arc_early_serial_console = {
652 .name = "early_ARCuart",
653 .write = early_serial_write,
654 .flags = CON_PRINTBUFFER | CON_BOOT,
655 .index = -1
656};
657
658static int arc_serial_probe_earlyprintk(struct platform_device *pdev)
659{
660 arc_early_serial_console.index = pdev->id;
661
662 arc_uart_init_one(pdev, &arc_uart_ports[pdev->id]);
663
664 arc_serial_console_setup(&arc_early_serial_console, NULL);
665
666 register_console(&arc_early_serial_console);
667 return 0;
668}
669#else
670static int arc_serial_probe_earlyprintk(struct platform_device *pdev)
671{
672 return -ENODEV;
673}
674#endif /* CONFIG_SERIAL_ARC_CONSOLE */
675
676static int arc_serial_probe(struct platform_device *pdev)
677{
678 struct arc_uart_port *uart;
679 int rc;
680
681 if (is_early_platform_device(pdev))
682 return arc_serial_probe_earlyprintk(pdev);
683
684 uart = &arc_uart_ports[pdev->id];
685 rc = arc_uart_init_one(pdev, uart);
686 if (rc)
687 return rc;
688
689 return uart_add_one_port(&arc_uart_driver, &uart->port);
690}
691
692static int arc_serial_remove(struct platform_device *pdev)
693{
694 /* This will never be called */
695 return 0;
696}
697
698static struct platform_driver arc_platform_driver = {
699 .probe = arc_serial_probe,
700 .remove = arc_serial_remove,
701 .driver = {
702 .name = DRIVER_NAME,
703 .owner = THIS_MODULE,
704 },
705};
706
707#ifdef CONFIG_SERIAL_ARC_CONSOLE
708/*
709 * Register an early platform driver of "earlyprintk" class.
710 * ARCH platform code installs the driver and probes the early devices
711 * The installation could rely on user specifying earlyprintk=xyx in cmd line
712 * or it could be done independently, for all "earlyprintk" class drivers.
713 * [see arch/arc/plat-arcfpga/platform.c]
714 */
715early_platform_init("earlyprintk", &arc_platform_driver);
716
717#endif /* CONFIG_SERIAL_ARC_CONSOLE */
718
719static int __init arc_serial_init(void)
720{
721 int ret;
722
723 ret = uart_register_driver(&arc_uart_driver);
724 if (ret)
725 return ret;
726
727 ret = platform_driver_register(&arc_platform_driver);
728 if (ret)
729 uart_unregister_driver(&arc_uart_driver);
730
731 return ret;
732}
733
734static void __exit arc_serial_exit(void)
735{
736 platform_driver_unregister(&arc_platform_driver);
737 uart_unregister_driver(&arc_uart_driver);
738}
739
740module_init(arc_serial_init);
741module_exit(arc_serial_exit);
742
743MODULE_LICENSE("GPL");
744MODULE_ALIAS("plat-arcfpga/uart");
745MODULE_AUTHOR("Vineet Gupta");
746MODULE_DESCRIPTION("ARC(Synopsys) On-Chip(fpga) serial driver");
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 922e85aeb63..948fc77b647 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -33,21 +33,20 @@
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>
38#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
39#include <linux/atmel_pdc.h> 37#include <linux/atmel_pdc.h>
40#include <linux/atmel_serial.h> 38#include <linux/atmel_serial.h>
41#include <linux/uaccess.h> 39#include <linux/uaccess.h>
42#include <linux/pinctrl/consumer.h>
43#include <linux/platform_data/atmel.h>
44 40
45#include <asm/io.h> 41#include <asm/io.h>
46#include <asm/ioctls.h> 42#include <asm/ioctls.h>
47 43
44#include <asm/mach/serial_at91.h>
45#include <mach/board.h>
46
48#ifdef CONFIG_ARM 47#ifdef CONFIG_ARM
49#include <mach/cpu.h> 48#include <mach/cpu.h>
50#include <asm/gpio.h> 49#include <mach/gpio.h>
51#endif 50#endif
52 51
53#define PDC_BUFFER_SIZE 512 52#define PDC_BUFFER_SIZE 512
@@ -158,22 +157,11 @@ struct atmel_uart_port {
158}; 157};
159 158
160static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART]; 159static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
161static unsigned long atmel_ports_in_use;
162 160
163#ifdef SUPPORT_SYSRQ 161#ifdef SUPPORT_SYSRQ
164static struct console atmel_console; 162static struct console atmel_console;
165#endif 163#endif
166 164
167#if defined(CONFIG_OF)
168static const struct of_device_id atmel_serial_dt_ids[] = {
169 { .compatible = "atmel,at91rm9200-usart" },
170 { .compatible = "atmel,at91sam9260-usart" },
171 { /* sentinel */ }
172};
173
174MODULE_DEVICE_TABLE(of, atmel_serial_dt_ids);
175#endif
176
177static inline struct atmel_uart_port * 165static inline struct atmel_uart_port *
178to_atmel_uart_port(struct uart_port *uart) 166to_atmel_uart_port(struct uart_port *uart)
179{ 167{
@@ -228,7 +216,7 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
228 if (rs485conf->flags & SER_RS485_ENABLED) { 216 if (rs485conf->flags & SER_RS485_ENABLED) {
229 dev_dbg(port->dev, "Setting UART to RS485\n"); 217 dev_dbg(port->dev, "Setting UART to RS485\n");
230 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; 218 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
231 if ((rs485conf->delay_rts_after_send) > 0) 219 if (rs485conf->flags & SER_RS485_RTS_AFTER_SEND)
232 UART_PUT_TTGR(port, rs485conf->delay_rts_after_send); 220 UART_PUT_TTGR(port, rs485conf->delay_rts_after_send);
233 mode |= ATMEL_US_USMODE_RS485; 221 mode |= ATMEL_US_USMODE_RS485;
234 } else { 222 } else {
@@ -304,7 +292,7 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
304 292
305 if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 293 if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
306 dev_dbg(port->dev, "Setting UART to RS485\n"); 294 dev_dbg(port->dev, "Setting UART to RS485\n");
307 if ((atmel_port->rs485.delay_rts_after_send) > 0) 295 if (atmel_port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
308 UART_PUT_TTGR(port, 296 UART_PUT_TTGR(port,
309 atmel_port->rs485.delay_rts_after_send); 297 atmel_port->rs485.delay_rts_after_send);
310 mode |= ATMEL_US_USMODE_RS485; 298 mode |= ATMEL_US_USMODE_RS485;
@@ -352,8 +340,7 @@ static void atmel_stop_tx(struct uart_port *port)
352 /* Disable interrupts */ 340 /* Disable interrupts */
353 UART_PUT_IDR(port, atmel_port->tx_done_mask); 341 UART_PUT_IDR(port, atmel_port->tx_done_mask);
354 342
355 if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && 343 if (atmel_port->rs485.flags & SER_RS485_ENABLED)
356 !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX))
357 atmel_start_rx(port); 344 atmel_start_rx(port);
358} 345}
359 346
@@ -370,8 +357,7 @@ static void atmel_start_tx(struct uart_port *port)
370 really need this.*/ 357 really need this.*/
371 return; 358 return;
372 359
373 if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && 360 if (atmel_port->rs485.flags & SER_RS485_ENABLED)
374 !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX))
375 atmel_stop_rx(port); 361 atmel_stop_rx(port);
376 362
377 /* re-enable PDC transmit */ 363 /* re-enable PDC transmit */
@@ -388,8 +374,6 @@ static void atmel_start_rx(struct uart_port *port)
388{ 374{
389 UART_PUT_CR(port, ATMEL_US_RSTSTA); /* reset status and receiver */ 375 UART_PUT_CR(port, ATMEL_US_RSTSTA); /* reset status and receiver */
390 376
391 UART_PUT_CR(port, ATMEL_US_RXEN);
392
393 if (atmel_use_dma_rx(port)) { 377 if (atmel_use_dma_rx(port)) {
394 /* enable PDC controller */ 378 /* enable PDC controller */
395 UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT | 379 UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT |
@@ -405,8 +389,6 @@ static void atmel_start_rx(struct uart_port *port)
405 */ 389 */
406static void atmel_stop_rx(struct uart_port *port) 390static void atmel_stop_rx(struct uart_port *port)
407{ 391{
408 UART_PUT_CR(port, ATMEL_US_RXDIS);
409
410 if (atmel_use_dma_rx(port)) { 392 if (atmel_use_dma_rx(port)) {
411 /* disable PDC receive */ 393 /* disable PDC receive */
412 UART_PUT_PTCR(port, ATMEL_PDC_RXTDIS); 394 UART_PUT_PTCR(port, ATMEL_PDC_RXTDIS);
@@ -699,8 +681,7 @@ static void atmel_tx_dma(struct uart_port *port)
699 /* Enable interrupts */ 681 /* Enable interrupts */
700 UART_PUT_IER(port, atmel_port->tx_done_mask); 682 UART_PUT_IER(port, atmel_port->tx_done_mask);
701 } else { 683 } else {
702 if ((atmel_port->rs485.flags & SER_RS485_ENABLED) && 684 if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
703 !(atmel_port->rs485.flags & SER_RS485_RX_DURING_TX)) {
704 /* DMA done, stop TX, start RX for RS485 */ 685 /* DMA done, stop TX, start RX for RS485 */
705 atmel_start_rx(port); 686 atmel_start_rx(port);
706 } 687 }
@@ -1232,7 +1213,7 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
1232 1213
1233 if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 1214 if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
1234 dev_dbg(port->dev, "Setting UART to RS485\n"); 1215 dev_dbg(port->dev, "Setting UART to RS485\n");
1235 if ((atmel_port->rs485.delay_rts_after_send) > 0) 1216 if (atmel_port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
1236 UART_PUT_TTGR(port, 1217 UART_PUT_TTGR(port,
1237 atmel_port->rs485.delay_rts_after_send); 1218 atmel_port->rs485.delay_rts_after_send);
1238 mode |= ATMEL_US_USMODE_RS485; 1219 mode |= ATMEL_US_USMODE_RS485;
@@ -1260,7 +1241,12 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
1260 1241
1261static void atmel_set_ldisc(struct uart_port *port, int new) 1242static void atmel_set_ldisc(struct uart_port *port, int new)
1262{ 1243{
1263 if (new == N_PPS) { 1244 int line = port->line;
1245
1246 if (line >= port->state->port.tty->driver->num)
1247 return;
1248
1249 if (port->state->port.tty->ldisc->ops->num == N_PPS) {
1264 port->flags |= UPF_HARDPPS_CD; 1250 port->flags |= UPF_HARDPPS_CD;
1265 atmel_enable_ms(port); 1251 atmel_enable_ms(port);
1266 } else { 1252 } else {
@@ -1422,59 +1408,20 @@ static struct uart_ops atmel_pops = {
1422#endif 1408#endif
1423}; 1409};
1424 1410
1425static void atmel_of_init_port(struct atmel_uart_port *atmel_port,
1426 struct device_node *np)
1427{
1428 u32 rs485_delay[2];
1429
1430 /* DMA/PDC usage specification */
1431 if (of_get_property(np, "atmel,use-dma-rx", NULL))
1432 atmel_port->use_dma_rx = 1;
1433 else
1434 atmel_port->use_dma_rx = 0;
1435 if (of_get_property(np, "atmel,use-dma-tx", NULL))
1436 atmel_port->use_dma_tx = 1;
1437 else
1438 atmel_port->use_dma_tx = 0;
1439
1440 /* rs485 properties */
1441 if (of_property_read_u32_array(np, "rs485-rts-delay",
1442 rs485_delay, 2) == 0) {
1443 struct serial_rs485 *rs485conf = &atmel_port->rs485;
1444
1445 rs485conf->delay_rts_before_send = rs485_delay[0];
1446 rs485conf->delay_rts_after_send = rs485_delay[1];
1447 rs485conf->flags = 0;
1448
1449 if (of_get_property(np, "rs485-rx-during-tx", NULL))
1450 rs485conf->flags |= SER_RS485_RX_DURING_TX;
1451
1452 if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL))
1453 rs485conf->flags |= SER_RS485_ENABLED;
1454 }
1455}
1456
1457/* 1411/*
1458 * Configure the port from the platform device resource info. 1412 * Configure the port from the platform device resource info.
1459 */ 1413 */
1460static void atmel_init_port(struct atmel_uart_port *atmel_port, 1414static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
1461 struct platform_device *pdev) 1415 struct platform_device *pdev)
1462{ 1416{
1463 struct uart_port *port = &atmel_port->uart; 1417 struct uart_port *port = &atmel_port->uart;
1464 struct atmel_uart_data *pdata = pdev->dev.platform_data; 1418 struct atmel_uart_data *data = pdev->dev.platform_data;
1465
1466 if (pdev->dev.of_node) {
1467 atmel_of_init_port(atmel_port, pdev->dev.of_node);
1468 } else {
1469 atmel_port->use_dma_rx = pdata->use_dma_rx;
1470 atmel_port->use_dma_tx = pdata->use_dma_tx;
1471 atmel_port->rs485 = pdata->rs485;
1472 }
1473 1419
1474 port->iotype = UPIO_MEM; 1420 port->iotype = UPIO_MEM;
1475 port->flags = UPF_BOOT_AUTOCONF; 1421 port->flags = UPF_BOOT_AUTOCONF;
1476 port->ops = &atmel_pops; 1422 port->ops = &atmel_pops;
1477 port->fifosize = 1; 1423 port->fifosize = 1;
1424 port->line = data->num;
1478 port->dev = &pdev->dev; 1425 port->dev = &pdev->dev;
1479 port->mapbase = pdev->resource[0].start; 1426 port->mapbase = pdev->resource[0].start;
1480 port->irq = pdev->resource[1].start; 1427 port->irq = pdev->resource[1].start;
@@ -1484,10 +1431,10 @@ static void atmel_init_port(struct atmel_uart_port *atmel_port,
1484 1431
1485 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring)); 1432 memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
1486 1433
1487 if (pdata && pdata->regs) { 1434 if (data->regs)
1488 /* Already mapped by setup code */ 1435 /* Already mapped by setup code */
1489 port->membase = pdata->regs; 1436 port->membase = data->regs;
1490 } else { 1437 else {
1491 port->flags |= UPF_IOREMAP; 1438 port->flags |= UPF_IOREMAP;
1492 port->membase = NULL; 1439 port->membase = NULL;
1493 } 1440 }
@@ -1501,6 +1448,9 @@ static void atmel_init_port(struct atmel_uart_port *atmel_port,
1501 /* only enable clock when USART is in use */ 1448 /* only enable clock when USART is in use */
1502 } 1449 }
1503 1450
1451 atmel_port->use_dma_rx = data->use_dma_rx;
1452 atmel_port->use_dma_tx = data->use_dma_tx;
1453 atmel_port->rs485 = data->rs485;
1504 /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */ 1454 /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
1505 if (atmel_port->rs485.flags & SER_RS485_ENABLED) 1455 if (atmel_port->rs485.flags & SER_RS485_ENABLED)
1506 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; 1456 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
@@ -1512,7 +1462,22 @@ static void atmel_init_port(struct atmel_uart_port *atmel_port,
1512 } 1462 }
1513} 1463}
1514 1464
1515struct platform_device *atmel_default_console_device; /* the serial console device */ 1465/*
1466 * Register board-specific modem-control line handlers.
1467 */
1468void __init atmel_register_uart_fns(struct atmel_port_fns *fns)
1469{
1470 if (fns->enable_ms)
1471 atmel_pops.enable_ms = fns->enable_ms;
1472 if (fns->get_mctrl)
1473 atmel_pops.get_mctrl = fns->get_mctrl;
1474 if (fns->set_mctrl)
1475 atmel_pops.set_mctrl = fns->set_mctrl;
1476 atmel_open_hook = fns->open;
1477 atmel_close_hook = fns->close;
1478 atmel_pops.pm = fns->pm;
1479 atmel_pops.set_wake = fns->set_wake;
1480}
1516 1481
1517#ifdef CONFIG_SERIAL_ATMEL_CONSOLE 1482#ifdef CONFIG_SERIAL_ATMEL_CONSOLE
1518static void atmel_console_putchar(struct uart_port *port, int ch) 1483static void atmel_console_putchar(struct uart_port *port, int ch)
@@ -1647,14 +1612,10 @@ static int __init atmel_console_init(void)
1647 if (atmel_default_console_device) { 1612 if (atmel_default_console_device) {
1648 struct atmel_uart_data *pdata = 1613 struct atmel_uart_data *pdata =
1649 atmel_default_console_device->dev.platform_data; 1614 atmel_default_console_device->dev.platform_data;
1650 int id = pdata->num;
1651 struct atmel_uart_port *port = &atmel_ports[id];
1652
1653 port->backup_imr = 0;
1654 port->uart.line = id;
1655 1615
1656 add_preferred_console(ATMEL_DEVICENAME, id, NULL); 1616 add_preferred_console(ATMEL_DEVICENAME, pdata->num, NULL);
1657 atmel_init_port(port, atmel_default_console_device); 1617 atmel_init_port(&atmel_ports[pdata->num],
1618 atmel_default_console_device);
1658 register_console(&atmel_console); 1619 register_console(&atmel_console);
1659 } 1620 }
1660 1621
@@ -1748,52 +1709,20 @@ static int atmel_serial_resume(struct platform_device *pdev)
1748#define atmel_serial_resume NULL 1709#define atmel_serial_resume NULL
1749#endif 1710#endif
1750 1711
1751static int atmel_serial_probe(struct platform_device *pdev) 1712static int __devinit atmel_serial_probe(struct platform_device *pdev)
1752{ 1713{
1753 struct atmel_uart_port *port; 1714 struct atmel_uart_port *port;
1754 struct device_node *np = pdev->dev.of_node;
1755 struct atmel_uart_data *pdata = pdev->dev.platform_data; 1715 struct atmel_uart_data *pdata = pdev->dev.platform_data;
1756 void *data; 1716 void *data;
1757 int ret = -ENODEV; 1717 int ret;
1758 struct pinctrl *pinctrl;
1759 1718
1760 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1)); 1719 BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));
1761 1720
1762 if (np) 1721 port = &atmel_ports[pdata->num];
1763 ret = of_alias_get_id(np, "serial");
1764 else
1765 if (pdata)
1766 ret = pdata->num;
1767
1768 if (ret < 0)
1769 /* port id not found in platform data nor device-tree aliases:
1770 * auto-enumerate it */
1771 ret = find_first_zero_bit(&atmel_ports_in_use,
1772 sizeof(atmel_ports_in_use));
1773
1774 if (ret > ATMEL_MAX_UART) {
1775 ret = -ENODEV;
1776 goto err;
1777 }
1778
1779 if (test_and_set_bit(ret, &atmel_ports_in_use)) {
1780 /* port already in use */
1781 ret = -EBUSY;
1782 goto err;
1783 }
1784
1785 port = &atmel_ports[ret];
1786 port->backup_imr = 0; 1722 port->backup_imr = 0;
1787 port->uart.line = ret;
1788 1723
1789 atmel_init_port(port, pdev); 1724 atmel_init_port(port, pdev);
1790 1725
1791 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
1792 if (IS_ERR(pinctrl)) {
1793 ret = PTR_ERR(pinctrl);
1794 goto err;
1795 }
1796
1797 if (!atmel_use_dma_rx(&port->uart)) { 1726 if (!atmel_use_dma_rx(&port->uart)) {
1798 ret = -ENOMEM; 1727 ret = -ENOMEM;
1799 data = kmalloc(sizeof(struct atmel_uart_char) 1728 data = kmalloc(sizeof(struct atmel_uart_char)
@@ -1836,11 +1765,11 @@ err_alloc_ring:
1836 clk_put(port->clk); 1765 clk_put(port->clk);
1837 port->clk = NULL; 1766 port->clk = NULL;
1838 } 1767 }
1839err: 1768
1840 return ret; 1769 return ret;
1841} 1770}
1842 1771
1843static int atmel_serial_remove(struct platform_device *pdev) 1772static int __devexit atmel_serial_remove(struct platform_device *pdev)
1844{ 1773{
1845 struct uart_port *port = platform_get_drvdata(pdev); 1774 struct uart_port *port = platform_get_drvdata(pdev);
1846 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1775 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
@@ -1856,8 +1785,6 @@ static int atmel_serial_remove(struct platform_device *pdev)
1856 1785
1857 /* "port" is allocated statically, so we shouldn't free it */ 1786 /* "port" is allocated statically, so we shouldn't free it */
1858 1787
1859 clear_bit(port->line, &atmel_ports_in_use);
1860
1861 clk_put(atmel_port->clk); 1788 clk_put(atmel_port->clk);
1862 1789
1863 return ret; 1790 return ret;
@@ -1865,13 +1792,12 @@ static int atmel_serial_remove(struct platform_device *pdev)
1865 1792
1866static struct platform_driver atmel_serial_driver = { 1793static struct platform_driver atmel_serial_driver = {
1867 .probe = atmel_serial_probe, 1794 .probe = atmel_serial_probe,
1868 .remove = atmel_serial_remove, 1795 .remove = __devexit_p(atmel_serial_remove),
1869 .suspend = atmel_serial_suspend, 1796 .suspend = atmel_serial_suspend,
1870 .resume = atmel_serial_resume, 1797 .resume = atmel_serial_resume,
1871 .driver = { 1798 .driver = {
1872 .name = "atmel_usart", 1799 .name = "atmel_usart",
1873 .owner = THIS_MODULE, 1800 .owner = THIS_MODULE,
1874 .of_match_table = of_match_ptr(atmel_serial_dt_ids),
1875 }, 1801 },
1876}; 1802};
1877 1803
diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx_uart.c
index c76a226080f..c0b68b9cad9 100644
--- a/drivers/tty/serial/bcm63xx_uart.c
+++ b/drivers/tty/serial/bcm63xx_uart.c
@@ -801,7 +801,7 @@ static struct uart_driver bcm_uart_driver = {
801/* 801/*
802 * platform driver probe/remove callback 802 * platform driver probe/remove callback
803 */ 803 */
804static int bcm_uart_probe(struct platform_device *pdev) 804static int __devinit bcm_uart_probe(struct platform_device *pdev)
805{ 805{
806 struct resource *res_mem, *res_irq; 806 struct resource *res_mem, *res_irq;
807 struct uart_port *port; 807 struct uart_port *port;
@@ -848,7 +848,7 @@ static int bcm_uart_probe(struct platform_device *pdev)
848 return 0; 848 return 0;
849} 849}
850 850
851static int bcm_uart_remove(struct platform_device *pdev) 851static int __devexit bcm_uart_remove(struct platform_device *pdev)
852{ 852{
853 struct uart_port *port; 853 struct uart_port *port;
854 854
@@ -865,7 +865,7 @@ static int bcm_uart_remove(struct platform_device *pdev)
865 */ 865 */
866static struct platform_driver bcm_uart_platform_driver = { 866static struct platform_driver bcm_uart_platform_driver = {
867 .probe = bcm_uart_probe, 867 .probe = bcm_uart_probe,
868 .remove = bcm_uart_remove, 868 .remove = __devexit_p(bcm_uart_remove),
869 .driver = { 869 .driver = {
870 .owner = THIS_MODULE, 870 .owner = THIS_MODULE,
871 .name = "bcm63xx_uart", 871 .name = "bcm63xx_uart",
diff --git a/drivers/tty/serial/bfin_sport_uart.c b/drivers/tty/serial/bfin_sport_uart.c
index f5d117379b6..891d194ae75 100644
--- a/drivers/tty/serial/bfin_sport_uart.c
+++ b/drivers/tty/serial/bfin_sport_uart.c
@@ -294,18 +294,13 @@ 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 0, "BFIN_SPORT_UART_CTS", up)) { 297 IRQF_DISABLED, "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 }
301 } 301 }
302 if (up->rts_pin >= 0) { 302 if (up->rts_pin >= 0)
303 if (gpio_request(up->rts_pin, DRV_NAME)) { 303 gpio_direction_output(up->rts_pin, 0);
304 dev_info(port->dev, "fail to request RTS PIN at GPIO_%d\n", up->rts_pin);
305 up->rts_pin = -1;
306 } else
307 gpio_direction_output(up->rts_pin, 0);
308 }
309#endif 304#endif
310 305
311 return 0; 306 return 0;
@@ -450,8 +445,6 @@ static void sport_shutdown(struct uart_port *port)
450#ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS 445#ifdef CONFIG_SERIAL_BFIN_SPORT_CTSRTS
451 if (up->cts_pin >= 0) 446 if (up->cts_pin >= 0)
452 free_irq(gpio_to_irq(up->cts_pin), up); 447 free_irq(gpio_to_irq(up->cts_pin), up);
453 if (up->rts_pin >= 0)
454 gpio_free(up->rts_pin);
455#endif 448#endif
456} 449}
457 450
@@ -740,7 +733,7 @@ static struct dev_pm_ops bfin_sport_uart_dev_pm_ops = {
740}; 733};
741#endif 734#endif
742 735
743static int sport_uart_probe(struct platform_device *pdev) 736static int __devinit sport_uart_probe(struct platform_device *pdev)
744{ 737{
745 struct resource *res; 738 struct resource *res;
746 struct sport_uart_port *sport; 739 struct sport_uart_port *sport;
@@ -810,16 +803,17 @@ static int sport_uart_probe(struct platform_device *pdev)
810 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 803 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
811 if (res == NULL) 804 if (res == NULL)
812 sport->cts_pin = -1; 805 sport->cts_pin = -1;
813 else { 806 else
814 sport->cts_pin = res->start; 807 sport->cts_pin = res->start;
815 sport->port.flags |= ASYNC_CTS_FLOW;
816 }
817 808
818 res = platform_get_resource(pdev, IORESOURCE_IO, 1); 809 res = platform_get_resource(pdev, IORESOURCE_IO, 1);
819 if (res == NULL) 810 if (res == NULL)
820 sport->rts_pin = -1; 811 sport->rts_pin = -1;
821 else 812 else
822 sport->rts_pin = res->start; 813 sport->rts_pin = res->start;
814
815 if (sport->rts_pin >= 0)
816 gpio_request(sport->rts_pin, DRV_NAME);
823#endif 817#endif
824 } 818 }
825 819
@@ -850,7 +844,7 @@ out_error_free_mem:
850 return ret; 844 return ret;
851} 845}
852 846
853static int sport_uart_remove(struct platform_device *pdev) 847static int __devexit sport_uart_remove(struct platform_device *pdev)
854{ 848{
855 struct sport_uart_port *sport = platform_get_drvdata(pdev); 849 struct sport_uart_port *sport = platform_get_drvdata(pdev);
856 850
@@ -859,6 +853,10 @@ static int sport_uart_remove(struct platform_device *pdev)
859 853
860 if (sport) { 854 if (sport) {
861 uart_remove_one_port(&sport_uart_reg, &sport->port); 855 uart_remove_one_port(&sport_uart_reg, &sport->port);
856#ifdef CONFIG_SERIAL_BFIN_CTSRTS
857 if (sport->rts_pin >= 0)
858 gpio_free(sport->rts_pin);
859#endif
862 iounmap(sport->port.membase); 860 iounmap(sport->port.membase);
863 peripheral_free_list( 861 peripheral_free_list(
864 (unsigned short *)pdev->dev.platform_data); 862 (unsigned short *)pdev->dev.platform_data);
@@ -871,7 +869,7 @@ static int sport_uart_remove(struct platform_device *pdev)
871 869
872static struct platform_driver sport_uart_driver = { 870static struct platform_driver sport_uart_driver = {
873 .probe = sport_uart_probe, 871 .probe = sport_uart_probe,
874 .remove = sport_uart_remove, 872 .remove = __devexit_p(sport_uart_remove),
875 .driver = { 873 .driver = {
876 .name = DRV_NAME, 874 .name = DRV_NAME,
877#ifdef CONFIG_PM 875#ifdef CONFIG_PM
diff --git a/drivers/tty/serial/bfin_sport_uart.h b/drivers/tty/serial/bfin_sport_uart.h
index e4510ea135c..6d06ce1d567 100644
--- a/drivers/tty/serial/bfin_sport_uart.h
+++ b/drivers/tty/serial/bfin_sport_uart.h
@@ -45,12 +45,11 @@
45#define SPORT_GET_RX32(sport) \ 45#define SPORT_GET_RX32(sport) \
46({ \ 46({ \
47 unsigned int __ret; \ 47 unsigned int __ret; \
48 unsigned long flags; \
49 if (ANOMALY_05000473) \ 48 if (ANOMALY_05000473) \
50 local_irq_save(flags); \ 49 local_irq_disable(); \
51 __ret = bfin_read32((sport)->port.membase + OFFSET_RX); \ 50 __ret = bfin_read32((sport)->port.membase + OFFSET_RX); \
52 if (ANOMALY_05000473) \ 51 if (ANOMALY_05000473) \
53 local_irq_restore(flags); \ 52 local_irq_enable(); \
54 __ret; \ 53 __ret; \
55}) 54})
56#define SPORT_GET_RCR1(sport) bfin_read16(((sport)->port.membase + OFFSET_RCR1)) 55#define SPORT_GET_RCR1(sport) bfin_read16(((sport)->port.membase + OFFSET_RCR1))
diff --git a/drivers/tty/serial/bfin_uart.c b/drivers/tty/serial/bfin_uart.c
deleted file mode 100644
index 2e2b2c1cb72..00000000000
--- a/drivers/tty/serial/bfin_uart.c
+++ /dev/null
@@ -1,1592 +0,0 @@
1/*
2 * Blackfin On-Chip Serial Driver
3 *
4 * Copyright 2006-2011 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 */
10
11#if defined(CONFIG_SERIAL_BFIN_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
12#define SUPPORT_SYSRQ
13#endif
14
15#define DRIVER_NAME "bfin-uart"
16#define pr_fmt(fmt) DRIVER_NAME ": " fmt
17
18#include <linux/module.h>
19#include <linux/ioport.h>
20#include <linux/gfp.h>
21#include <linux/io.h>
22#include <linux/init.h>
23#include <linux/console.h>
24#include <linux/sysrq.h>
25#include <linux/platform_device.h>
26#include <linux/tty.h>
27#include <linux/tty_flip.h>
28#include <linux/serial_core.h>
29#include <linux/gpio.h>
30#include <linux/irq.h>
31#include <linux/kgdb.h>
32#include <linux/slab.h>
33#include <linux/dma-mapping.h>
34
35#include <asm/portmux.h>
36#include <asm/cacheflush.h>
37#include <asm/dma.h>
38#include <asm/bfin_serial.h>
39
40#ifdef CONFIG_SERIAL_BFIN_MODULE
41# undef CONFIG_EARLY_PRINTK
42#endif
43
44#ifdef CONFIG_SERIAL_BFIN_MODULE
45# undef CONFIG_EARLY_PRINTK
46#endif
47
48/* UART name and device definitions */
49#define BFIN_SERIAL_DEV_NAME "ttyBF"
50#define BFIN_SERIAL_MAJOR 204
51#define BFIN_SERIAL_MINOR 64
52
53static struct bfin_serial_port *bfin_serial_ports[BFIN_UART_NR_PORTS];
54
55#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
56 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
57
58# ifndef CONFIG_SERIAL_BFIN_PIO
59# error KGDB only support UART in PIO mode.
60# endif
61
62static int kgdboc_port_line;
63static int kgdboc_break_enabled;
64#endif
65/*
66 * Setup for console. Argument comes from the menuconfig
67 */
68#define DMA_RX_XCOUNT 512
69#define DMA_RX_YCOUNT (PAGE_SIZE / DMA_RX_XCOUNT)
70
71#define DMA_RX_FLUSH_JIFFIES (HZ / 50)
72
73#ifdef CONFIG_SERIAL_BFIN_DMA
74static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart);
75#else
76static void bfin_serial_tx_chars(struct bfin_serial_port *uart);
77#endif
78
79static void bfin_serial_reset_irda(struct uart_port *port);
80
81#if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
82 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
83static unsigned int bfin_serial_get_mctrl(struct uart_port *port)
84{
85 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
86 if (uart->cts_pin < 0)
87 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
88
89 /* CTS PIN is negative assertive. */
90 if (UART_GET_CTS(uart))
91 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
92 else
93 return TIOCM_DSR | TIOCM_CAR;
94}
95
96static void bfin_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
97{
98 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
99 if (uart->rts_pin < 0)
100 return;
101
102 /* RTS PIN is negative assertive. */
103 if (mctrl & TIOCM_RTS)
104 UART_ENABLE_RTS(uart);
105 else
106 UART_DISABLE_RTS(uart);
107}
108
109/*
110 * Handle any change of modem status signal.
111 */
112static irqreturn_t bfin_serial_mctrl_cts_int(int irq, void *dev_id)
113{
114 struct bfin_serial_port *uart = dev_id;
115 unsigned int status = bfin_serial_get_mctrl(&uart->port);
116#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
117 struct tty_struct *tty = uart->port.state->port.tty;
118
119 UART_CLEAR_SCTS(uart);
120 if (tty->hw_stopped) {
121 if (status) {
122 tty->hw_stopped = 0;
123 uart_write_wakeup(&uart->port);
124 }
125 } else {
126 if (!status)
127 tty->hw_stopped = 1;
128 }
129#endif
130 uart_handle_cts_change(&uart->port, status & TIOCM_CTS);
131
132 return IRQ_HANDLED;
133}
134#else
135static unsigned int bfin_serial_get_mctrl(struct uart_port *port)
136{
137 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
138}
139
140static void bfin_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
141{
142}
143#endif
144
145/*
146 * interrupts are disabled on entry
147 */
148static void bfin_serial_stop_tx(struct uart_port *port)
149{
150 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
151#ifdef CONFIG_SERIAL_BFIN_DMA
152 struct circ_buf *xmit = &uart->port.state->xmit;
153#endif
154
155 while (!(UART_GET_LSR(uart) & TEMT))
156 cpu_relax();
157
158#ifdef CONFIG_SERIAL_BFIN_DMA
159 disable_dma(uart->tx_dma_channel);
160 xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1);
161 uart->port.icount.tx += uart->tx_count;
162 uart->tx_count = 0;
163 uart->tx_done = 1;
164#else
165#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
166 /* Clear TFI bit */
167 UART_PUT_LSR(uart, TFI);
168#endif
169 UART_CLEAR_IER(uart, ETBEI);
170#endif
171}
172
173/*
174 * port is locked and interrupts are disabled
175 */
176static void bfin_serial_start_tx(struct uart_port *port)
177{
178 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
179 struct tty_struct *tty = uart->port.state->port.tty;
180
181 /*
182 * To avoid losting RX interrupt, we reset IR function
183 * before sending data.
184 */
185 if (tty->termios.c_line == N_IRDA)
186 bfin_serial_reset_irda(port);
187
188#ifdef CONFIG_SERIAL_BFIN_DMA
189 if (uart->tx_done)
190 bfin_serial_dma_tx_chars(uart);
191#else
192 UART_SET_IER(uart, ETBEI);
193 bfin_serial_tx_chars(uart);
194#endif
195}
196
197/*
198 * Interrupts are enabled
199 */
200static void bfin_serial_stop_rx(struct uart_port *port)
201{
202 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
203
204 UART_CLEAR_IER(uart, ERBFI);
205}
206
207/*
208 * Set the modem control timer to fire immediately.
209 */
210static void bfin_serial_enable_ms(struct uart_port *port)
211{
212}
213
214
215#if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
216# define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold)
217# define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v))
218#else
219# define UART_GET_ANOMALY_THRESHOLD(uart) 0
220# define UART_SET_ANOMALY_THRESHOLD(uart, v)
221#endif
222
223#ifdef CONFIG_SERIAL_BFIN_PIO
224static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
225{
226 struct tty_struct *tty = NULL;
227 unsigned int status, ch, flg;
228 static struct timeval anomaly_start = { .tv_sec = 0 };
229
230 status = UART_GET_LSR(uart);
231 UART_CLEAR_LSR(uart);
232
233 ch = UART_GET_CHAR(uart);
234 uart->port.icount.rx++;
235
236#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
237 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
238 if (kgdb_connected && kgdboc_port_line == uart->port.line
239 && kgdboc_break_enabled)
240 if (ch == 0x3) {/* Ctrl + C */
241 kgdb_breakpoint();
242 return;
243 }
244
245 if (!uart->port.state || !uart->port.state->port.tty)
246 return;
247#endif
248 tty = uart->port.state->port.tty;
249
250 if (ANOMALY_05000363) {
251 /* The BF533 (and BF561) family of processors have a nice anomaly
252 * where they continuously generate characters for a "single" break.
253 * We have to basically ignore this flood until the "next" valid
254 * character comes across. Due to the nature of the flood, it is
255 * not possible to reliably catch bytes that are sent too quickly
256 * after this break. So application code talking to the Blackfin
257 * which sends a break signal must allow at least 1.5 character
258 * times after the end of the break for things to stabilize. This
259 * timeout was picked as it must absolutely be larger than 1
260 * character time +/- some percent. So 1.5 sounds good. All other
261 * Blackfin families operate properly. Woo.
262 */
263 if (anomaly_start.tv_sec) {
264 struct timeval curr;
265 suseconds_t usecs;
266
267 if ((~ch & (~ch + 1)) & 0xff)
268 goto known_good_char;
269
270 do_gettimeofday(&curr);
271 if (curr.tv_sec - anomaly_start.tv_sec > 1)
272 goto known_good_char;
273
274 usecs = 0;
275 if (curr.tv_sec != anomaly_start.tv_sec)
276 usecs += USEC_PER_SEC;
277 usecs += curr.tv_usec - anomaly_start.tv_usec;
278
279 if (usecs > UART_GET_ANOMALY_THRESHOLD(uart))
280 goto known_good_char;
281
282 if (ch)
283 anomaly_start.tv_sec = 0;
284 else
285 anomaly_start = curr;
286
287 return;
288
289 known_good_char:
290 status &= ~BI;
291 anomaly_start.tv_sec = 0;
292 }
293 }
294
295 if (status & BI) {
296 if (ANOMALY_05000363)
297 if (bfin_revid() < 5)
298 do_gettimeofday(&anomaly_start);
299 uart->port.icount.brk++;
300 if (uart_handle_break(&uart->port))
301 goto ignore_char;
302 status &= ~(PE | FE);
303 }
304 if (status & PE)
305 uart->port.icount.parity++;
306 if (status & OE)
307 uart->port.icount.overrun++;
308 if (status & FE)
309 uart->port.icount.frame++;
310
311 status &= uart->port.read_status_mask;
312
313 if (status & BI)
314 flg = TTY_BREAK;
315 else if (status & PE)
316 flg = TTY_PARITY;
317 else if (status & FE)
318 flg = TTY_FRAME;
319 else
320 flg = TTY_NORMAL;
321
322 if (uart_handle_sysrq_char(&uart->port, ch))
323 goto ignore_char;
324
325 uart_insert_char(&uart->port, status, OE, ch, flg);
326
327 ignore_char:
328 tty_flip_buffer_push(tty);
329}
330
331static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
332{
333 struct circ_buf *xmit = &uart->port.state->xmit;
334
335 if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
336#if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
337 /* Clear TFI bit */
338 UART_PUT_LSR(uart, TFI);
339#endif
340 /* Anomaly notes:
341 * 05000215 - we always clear ETBEI within last UART TX
342 * interrupt to end a string. It is always set
343 * when start a new tx.
344 */
345 UART_CLEAR_IER(uart, ETBEI);
346 return;
347 }
348
349 if (uart->port.x_char) {
350 UART_PUT_CHAR(uart, uart->port.x_char);
351 uart->port.icount.tx++;
352 uart->port.x_char = 0;
353 }
354
355 while ((UART_GET_LSR(uart) & THRE) && xmit->tail != xmit->head) {
356 UART_PUT_CHAR(uart, xmit->buf[xmit->tail]);
357 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
358 uart->port.icount.tx++;
359 }
360
361 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
362 uart_write_wakeup(&uart->port);
363}
364
365static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id)
366{
367 struct bfin_serial_port *uart = dev_id;
368
369 while (UART_GET_LSR(uart) & DR)
370 bfin_serial_rx_chars(uart);
371
372 return IRQ_HANDLED;
373}
374
375static irqreturn_t bfin_serial_tx_int(int irq, void *dev_id)
376{
377 struct bfin_serial_port *uart = dev_id;
378
379 spin_lock(&uart->port.lock);
380 if (UART_GET_LSR(uart) & THRE)
381 bfin_serial_tx_chars(uart);
382 spin_unlock(&uart->port.lock);
383
384 return IRQ_HANDLED;
385}
386#endif
387
388#ifdef CONFIG_SERIAL_BFIN_DMA
389static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
390{
391 struct circ_buf *xmit = &uart->port.state->xmit;
392
393 uart->tx_done = 0;
394
395 if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
396 uart->tx_count = 0;
397 uart->tx_done = 1;
398 return;
399 }
400
401 if (uart->port.x_char) {
402 UART_PUT_CHAR(uart, uart->port.x_char);
403 uart->port.icount.tx++;
404 uart->port.x_char = 0;
405 }
406
407 uart->tx_count = CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE);
408 if (uart->tx_count > (UART_XMIT_SIZE - xmit->tail))
409 uart->tx_count = UART_XMIT_SIZE - xmit->tail;
410 blackfin_dcache_flush_range((unsigned long)(xmit->buf+xmit->tail),
411 (unsigned long)(xmit->buf+xmit->tail+uart->tx_count));
412 set_dma_config(uart->tx_dma_channel,
413 set_bfin_dma_config(DIR_READ, DMA_FLOW_STOP,
414 INTR_ON_BUF,
415 DIMENSION_LINEAR,
416 DATA_SIZE_8,
417 DMA_SYNC_RESTART));
418 set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail));
419 set_dma_x_count(uart->tx_dma_channel, uart->tx_count);
420 set_dma_x_modify(uart->tx_dma_channel, 1);
421 SSYNC();
422 enable_dma(uart->tx_dma_channel);
423
424 UART_SET_IER(uart, ETBEI);
425}
426
427static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
428{
429 struct tty_struct *tty = uart->port.state->port.tty;
430 int i, flg, status;
431
432 status = UART_GET_LSR(uart);
433 UART_CLEAR_LSR(uart);
434
435 uart->port.icount.rx +=
436 CIRC_CNT(uart->rx_dma_buf.head, uart->rx_dma_buf.tail,
437 UART_XMIT_SIZE);
438
439 if (status & BI) {
440 uart->port.icount.brk++;
441 if (uart_handle_break(&uart->port))
442 goto dma_ignore_char;
443 status &= ~(PE | FE);
444 }
445 if (status & PE)
446 uart->port.icount.parity++;
447 if (status & OE)
448 uart->port.icount.overrun++;
449 if (status & FE)
450 uart->port.icount.frame++;
451
452 status &= uart->port.read_status_mask;
453
454 if (status & BI)
455 flg = TTY_BREAK;
456 else if (status & PE)
457 flg = TTY_PARITY;
458 else if (status & FE)
459 flg = TTY_FRAME;
460 else
461 flg = TTY_NORMAL;
462
463 for (i = uart->rx_dma_buf.tail; ; i++) {
464 if (i >= UART_XMIT_SIZE)
465 i = 0;
466 if (i == uart->rx_dma_buf.head)
467 break;
468 if (!uart_handle_sysrq_char(&uart->port, uart->rx_dma_buf.buf[i]))
469 uart_insert_char(&uart->port, status, OE,
470 uart->rx_dma_buf.buf[i], flg);
471 }
472
473 dma_ignore_char:
474 tty_flip_buffer_push(tty);
475}
476
477void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
478{
479 int x_pos, pos;
480 unsigned long flags;
481
482 spin_lock_irqsave(&uart->rx_lock, flags);
483
484 /* 2D DMA RX buffer ring is used. Because curr_y_count and
485 * curr_x_count can't be read as an atomic operation,
486 * curr_y_count should be read before curr_x_count. When
487 * curr_x_count is read, curr_y_count may already indicate
488 * next buffer line. But, the position calculated here is
489 * still indicate the old line. The wrong position data may
490 * be smaller than current buffer tail, which cause garbages
491 * are received if it is not prohibit.
492 */
493 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
494 x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
495 uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows;
496 if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0)
497 uart->rx_dma_nrows = 0;
498 x_pos = DMA_RX_XCOUNT - x_pos;
499 if (x_pos == DMA_RX_XCOUNT)
500 x_pos = 0;
501
502 pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos;
503 /* Ignore receiving data if new position is in the same line of
504 * current buffer tail and small.
505 */
506 if (pos > uart->rx_dma_buf.tail ||
507 uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) {
508 uart->rx_dma_buf.head = pos;
509 bfin_serial_dma_rx_chars(uart);
510 uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
511 }
512
513 spin_unlock_irqrestore(&uart->rx_lock, flags);
514
515 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES);
516}
517
518static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
519{
520 struct bfin_serial_port *uart = dev_id;
521 struct circ_buf *xmit = &uart->port.state->xmit;
522
523 spin_lock(&uart->port.lock);
524 if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) {
525 disable_dma(uart->tx_dma_channel);
526 clear_dma_irqstat(uart->tx_dma_channel);
527 /* Anomaly notes:
528 * 05000215 - we always clear ETBEI within last UART TX
529 * interrupt to end a string. It is always set
530 * when start a new tx.
531 */
532 UART_CLEAR_IER(uart, ETBEI);
533 uart->port.icount.tx += uart->tx_count;
534 if (!(xmit->tail == 0 && xmit->head == 0)) {
535 xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1);
536
537 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
538 uart_write_wakeup(&uart->port);
539 }
540
541 bfin_serial_dma_tx_chars(uart);
542 }
543
544 spin_unlock(&uart->port.lock);
545 return IRQ_HANDLED;
546}
547
548static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id)
549{
550 struct bfin_serial_port *uart = dev_id;
551 unsigned int irqstat;
552 int x_pos, pos;
553
554 spin_lock(&uart->rx_lock);
555 irqstat = get_dma_curr_irqstat(uart->rx_dma_channel);
556 clear_dma_irqstat(uart->rx_dma_channel);
557
558 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
559 x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
560 uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows;
561 if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0)
562 uart->rx_dma_nrows = 0;
563
564 pos = uart->rx_dma_nrows * DMA_RX_XCOUNT;
565 if (pos > uart->rx_dma_buf.tail ||
566 uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) {
567 uart->rx_dma_buf.head = pos;
568 bfin_serial_dma_rx_chars(uart);
569 uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
570 }
571
572 spin_unlock(&uart->rx_lock);
573
574 return IRQ_HANDLED;
575}
576#endif
577
578/*
579 * Return TIOCSER_TEMT when transmitter is not busy.
580 */
581static unsigned int bfin_serial_tx_empty(struct uart_port *port)
582{
583 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
584 unsigned int lsr;
585
586 lsr = UART_GET_LSR(uart);
587 if (lsr & TEMT)
588 return TIOCSER_TEMT;
589 else
590 return 0;
591}
592
593static void bfin_serial_break_ctl(struct uart_port *port, int break_state)
594{
595 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
596 u32 lcr = UART_GET_LCR(uart);
597 if (break_state)
598 lcr |= SB;
599 else
600 lcr &= ~SB;
601 UART_PUT_LCR(uart, lcr);
602 SSYNC();
603}
604
605static int bfin_serial_startup(struct uart_port *port)
606{
607 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
608
609#ifdef CONFIG_SERIAL_BFIN_DMA
610 dma_addr_t dma_handle;
611
612 if (request_dma(uart->rx_dma_channel, "BFIN_UART_RX") < 0) {
613 printk(KERN_NOTICE "Unable to attach Blackfin UART RX DMA channel\n");
614 return -EBUSY;
615 }
616
617 if (request_dma(uart->tx_dma_channel, "BFIN_UART_TX") < 0) {
618 printk(KERN_NOTICE "Unable to attach Blackfin UART TX DMA channel\n");
619 free_dma(uart->rx_dma_channel);
620 return -EBUSY;
621 }
622
623 set_dma_callback(uart->rx_dma_channel, bfin_serial_dma_rx_int, uart);
624 set_dma_callback(uart->tx_dma_channel, bfin_serial_dma_tx_int, uart);
625
626 uart->rx_dma_buf.buf = (unsigned char *)dma_alloc_coherent(NULL, PAGE_SIZE, &dma_handle, GFP_DMA);
627 uart->rx_dma_buf.head = 0;
628 uart->rx_dma_buf.tail = 0;
629 uart->rx_dma_nrows = 0;
630
631 set_dma_config(uart->rx_dma_channel,
632 set_bfin_dma_config(DIR_WRITE, DMA_FLOW_AUTO,
633 INTR_ON_ROW, DIMENSION_2D,
634 DATA_SIZE_8,
635 DMA_SYNC_RESTART));
636 set_dma_x_count(uart->rx_dma_channel, DMA_RX_XCOUNT);
637 set_dma_x_modify(uart->rx_dma_channel, 1);
638 set_dma_y_count(uart->rx_dma_channel, DMA_RX_YCOUNT);
639 set_dma_y_modify(uart->rx_dma_channel, 1);
640 set_dma_start_addr(uart->rx_dma_channel, (unsigned long)uart->rx_dma_buf.buf);
641 enable_dma(uart->rx_dma_channel);
642
643 uart->rx_dma_timer.data = (unsigned long)(uart);
644 uart->rx_dma_timer.function = (void *)bfin_serial_rx_dma_timeout;
645 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
646 add_timer(&(uart->rx_dma_timer));
647#else
648# if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
649 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
650 if (kgdboc_port_line == uart->port.line && kgdboc_break_enabled)
651 kgdboc_break_enabled = 0;
652 else {
653# endif
654 if (request_irq(uart->rx_irq, bfin_serial_rx_int, 0,
655 "BFIN_UART_RX", uart)) {
656 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
657 return -EBUSY;
658 }
659
660 if (request_irq
661 (uart->tx_irq, bfin_serial_tx_int, 0,
662 "BFIN_UART_TX", uart)) {
663 printk(KERN_NOTICE "Unable to attach BlackFin UART TX interrupt\n");
664 free_irq(uart->rx_irq, uart);
665 return -EBUSY;
666 }
667
668# ifdef CONFIG_BF54x
669 {
670 /*
671 * UART2 and UART3 on BF548 share interrupt PINs and DMA
672 * controllers with SPORT2 and SPORT3. UART rx and tx
673 * interrupts are generated in PIO mode only when configure
674 * their peripheral mapping registers properly, which means
675 * request corresponding DMA channels in PIO mode as well.
676 */
677 unsigned uart_dma_ch_rx, uart_dma_ch_tx;
678
679 switch (uart->rx_irq) {
680 case IRQ_UART3_RX:
681 uart_dma_ch_rx = CH_UART3_RX;
682 uart_dma_ch_tx = CH_UART3_TX;
683 break;
684 case IRQ_UART2_RX:
685 uart_dma_ch_rx = CH_UART2_RX;
686 uart_dma_ch_tx = CH_UART2_TX;
687 break;
688 default:
689 uart_dma_ch_rx = uart_dma_ch_tx = 0;
690 break;
691 };
692
693 if (uart_dma_ch_rx &&
694 request_dma(uart_dma_ch_rx, "BFIN_UART_RX") < 0) {
695 printk(KERN_NOTICE"Fail to attach UART interrupt\n");
696 free_irq(uart->rx_irq, uart);
697 free_irq(uart->tx_irq, uart);
698 return -EBUSY;
699 }
700 if (uart_dma_ch_tx &&
701 request_dma(uart_dma_ch_tx, "BFIN_UART_TX") < 0) {
702 printk(KERN_NOTICE "Fail to attach UART interrupt\n");
703 free_dma(uart_dma_ch_rx);
704 free_irq(uart->rx_irq, uart);
705 free_irq(uart->tx_irq, uart);
706 return -EBUSY;
707 }
708 }
709# endif
710# if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
711 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
712 }
713# endif
714#endif
715
716#ifdef CONFIG_SERIAL_BFIN_CTSRTS
717 if (uart->cts_pin >= 0) {
718 if (request_irq(gpio_to_irq(uart->cts_pin),
719 bfin_serial_mctrl_cts_int,
720 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
721 0, "BFIN_UART_CTS", uart)) {
722 uart->cts_pin = -1;
723 pr_info("Unable to attach BlackFin UART CTS interrupt. So, disable it.\n");
724 }
725 }
726 if (uart->rts_pin >= 0) {
727 if (gpio_request(uart->rts_pin, DRIVER_NAME)) {
728 pr_info("fail to request RTS PIN at GPIO_%d\n", uart->rts_pin);
729 uart->rts_pin = -1;
730 } else
731 gpio_direction_output(uart->rts_pin, 0);
732 }
733#endif
734#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
735 if (uart->cts_pin >= 0) {
736 if (request_irq(uart->status_irq, bfin_serial_mctrl_cts_int,
737 IRQF_DISABLED, "BFIN_UART_MODEM_STATUS", uart)) {
738 uart->cts_pin = -1;
739 dev_info(port->dev, "Unable to attach BlackFin UART Modem Status interrupt.\n");
740 }
741
742 /* CTS RTS PINs are negative assertive. */
743 UART_PUT_MCR(uart, UART_GET_MCR(uart) | ACTS);
744 UART_SET_IER(uart, EDSSI);
745 }
746#endif
747
748 UART_SET_IER(uart, ERBFI);
749 return 0;
750}
751
752static void bfin_serial_shutdown(struct uart_port *port)
753{
754 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
755
756#ifdef CONFIG_SERIAL_BFIN_DMA
757 disable_dma(uart->tx_dma_channel);
758 free_dma(uart->tx_dma_channel);
759 disable_dma(uart->rx_dma_channel);
760 free_dma(uart->rx_dma_channel);
761 del_timer(&(uart->rx_dma_timer));
762 dma_free_coherent(NULL, PAGE_SIZE, uart->rx_dma_buf.buf, 0);
763#else
764#ifdef CONFIG_BF54x
765 switch (uart->port.irq) {
766 case IRQ_UART3_RX:
767 free_dma(CH_UART3_RX);
768 free_dma(CH_UART3_TX);
769 break;
770 case IRQ_UART2_RX:
771 free_dma(CH_UART2_RX);
772 free_dma(CH_UART2_TX);
773 break;
774 default:
775 break;
776 };
777#endif
778 free_irq(uart->rx_irq, uart);
779 free_irq(uart->tx_irq, uart);
780#endif
781
782#ifdef CONFIG_SERIAL_BFIN_CTSRTS
783 if (uart->cts_pin >= 0)
784 free_irq(gpio_to_irq(uart->cts_pin), uart);
785 if (uart->rts_pin >= 0)
786 gpio_free(uart->rts_pin);
787#endif
788#ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
789 if (uart->cts_pin >= 0)
790 free_irq(uart->status_irq, uart);
791#endif
792}
793
794static void
795bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
796 struct ktermios *old)
797{
798 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
799 unsigned long flags;
800 unsigned int baud, quot;
801 unsigned int ier, lcr = 0;
802 unsigned long timeout;
803
804 switch (termios->c_cflag & CSIZE) {
805 case CS8:
806 lcr = WLS(8);
807 break;
808 case CS7:
809 lcr = WLS(7);
810 break;
811 case CS6:
812 lcr = WLS(6);
813 break;
814 case CS5:
815 lcr = WLS(5);
816 break;
817 default:
818 printk(KERN_ERR "%s: word length not supported\n",
819 __func__);
820 }
821
822 /* Anomaly notes:
823 * 05000231 - STOP bit is always set to 1 whatever the user is set.
824 */
825 if (termios->c_cflag & CSTOPB) {
826 if (ANOMALY_05000231)
827 printk(KERN_WARNING "STOP bits other than 1 is not "
828 "supported in case of anomaly 05000231.\n");
829 else
830 lcr |= STB;
831 }
832 if (termios->c_cflag & PARENB)
833 lcr |= PEN;
834 if (!(termios->c_cflag & PARODD))
835 lcr |= EPS;
836 if (termios->c_cflag & CMSPAR)
837 lcr |= STP;
838
839 spin_lock_irqsave(&uart->port.lock, flags);
840
841 port->read_status_mask = OE;
842 if (termios->c_iflag & INPCK)
843 port->read_status_mask |= (FE | PE);
844 if (termios->c_iflag & (BRKINT | PARMRK))
845 port->read_status_mask |= BI;
846
847 /*
848 * Characters to ignore
849 */
850 port->ignore_status_mask = 0;
851 if (termios->c_iflag & IGNPAR)
852 port->ignore_status_mask |= FE | PE;
853 if (termios->c_iflag & IGNBRK) {
854 port->ignore_status_mask |= BI;
855 /*
856 * If we're ignoring parity and break indicators,
857 * ignore overruns too (for real raw support).
858 */
859 if (termios->c_iflag & IGNPAR)
860 port->ignore_status_mask |= OE;
861 }
862
863 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
864 quot = uart_get_divisor(port, baud);
865
866 /* If discipline is not IRDA, apply ANOMALY_05000230 */
867 if (termios->c_line != N_IRDA)
868 quot -= ANOMALY_05000230;
869
870 UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15);
871
872 /* Wait till the transfer buffer is empty */
873 timeout = jiffies + msecs_to_jiffies(10);
874 while (UART_GET_GCTL(uart) & UCEN && !(UART_GET_LSR(uart) & TEMT))
875 if (time_after(jiffies, timeout)) {
876 dev_warn(port->dev, "timeout waiting for TX buffer empty\n");
877 break;
878 }
879
880 /* Disable UART */
881 ier = UART_GET_IER(uart);
882 UART_PUT_GCTL(uart, UART_GET_GCTL(uart) & ~UCEN);
883 UART_DISABLE_INTS(uart);
884
885 /* Set DLAB in LCR to Access CLK */
886 UART_SET_DLAB(uart);
887
888 UART_PUT_CLK(uart, quot);
889 SSYNC();
890
891 /* Clear DLAB in LCR to Access THR RBR IER */
892 UART_CLEAR_DLAB(uart);
893
894 UART_PUT_LCR(uart, (UART_GET_LCR(uart) & ~LCR_MASK) | lcr);
895
896 /* Enable UART */
897 UART_ENABLE_INTS(uart, ier);
898 UART_PUT_GCTL(uart, UART_GET_GCTL(uart) | UCEN);
899
900 /* Port speed changed, update the per-port timeout. */
901 uart_update_timeout(port, termios->c_cflag, baud);
902
903 spin_unlock_irqrestore(&uart->port.lock, flags);
904}
905
906static const char *bfin_serial_type(struct uart_port *port)
907{
908 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
909
910 return uart->port.type == PORT_BFIN ? "BFIN-UART" : NULL;
911}
912
913/*
914 * Release the memory region(s) being used by 'port'.
915 */
916static void bfin_serial_release_port(struct uart_port *port)
917{
918}
919
920/*
921 * Request the memory region(s) being used by 'port'.
922 */
923static int bfin_serial_request_port(struct uart_port *port)
924{
925 return 0;
926}
927
928/*
929 * Configure/autoconfigure the port.
930 */
931static void bfin_serial_config_port(struct uart_port *port, int flags)
932{
933 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
934
935 if (flags & UART_CONFIG_TYPE &&
936 bfin_serial_request_port(&uart->port) == 0)
937 uart->port.type = PORT_BFIN;
938}
939
940/*
941 * Verify the new serial_struct (for TIOCSSERIAL).
942 * The only change we allow are to the flags and type, and
943 * even then only between PORT_BFIN and PORT_UNKNOWN
944 */
945static int
946bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
947{
948 return 0;
949}
950
951/*
952 * Enable the IrDA function if tty->ldisc.num is N_IRDA.
953 * In other cases, disable IrDA function.
954 */
955static void bfin_serial_set_ldisc(struct uart_port *port, int ld)
956{
957 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
958 unsigned int val;
959
960 switch (ld) {
961 case N_IRDA:
962 val = UART_GET_GCTL(uart);
963 val |= (UMOD_IRDA | RPOLC);
964 UART_PUT_GCTL(uart, val);
965 break;
966 default:
967 val = UART_GET_GCTL(uart);
968 val &= ~(UMOD_MASK | RPOLC);
969 UART_PUT_GCTL(uart, val);
970 }
971}
972
973static void bfin_serial_reset_irda(struct uart_port *port)
974{
975 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
976 unsigned int val;
977
978 val = UART_GET_GCTL(uart);
979 val &= ~(UMOD_MASK | RPOLC);
980 UART_PUT_GCTL(uart, val);
981 SSYNC();
982 val |= (UMOD_IRDA | RPOLC);
983 UART_PUT_GCTL(uart, val);
984 SSYNC();
985}
986
987#ifdef CONFIG_CONSOLE_POLL
988/* Anomaly notes:
989 * 05000099 - Because we only use THRE in poll_put and DR in poll_get,
990 * losing other bits of UART_LSR is not a problem here.
991 */
992static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr)
993{
994 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
995
996 while (!(UART_GET_LSR(uart) & THRE))
997 cpu_relax();
998
999 UART_CLEAR_DLAB(uart);
1000 UART_PUT_CHAR(uart, (unsigned char)chr);
1001}
1002
1003static int bfin_serial_poll_get_char(struct uart_port *port)
1004{
1005 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
1006 unsigned char chr;
1007
1008 while (!(UART_GET_LSR(uart) & DR))
1009 cpu_relax();
1010
1011 UART_CLEAR_DLAB(uart);
1012 chr = UART_GET_CHAR(uart);
1013
1014 return chr;
1015}
1016#endif
1017
1018#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
1019 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
1020static void bfin_kgdboc_port_shutdown(struct uart_port *port)
1021{
1022 if (kgdboc_break_enabled) {
1023 kgdboc_break_enabled = 0;
1024 bfin_serial_shutdown(port);
1025 }
1026}
1027
1028static int bfin_kgdboc_port_startup(struct uart_port *port)
1029{
1030 kgdboc_port_line = port->line;
1031 kgdboc_break_enabled = !bfin_serial_startup(port);
1032 return 0;
1033}
1034#endif
1035
1036static struct uart_ops bfin_serial_pops = {
1037 .tx_empty = bfin_serial_tx_empty,
1038 .set_mctrl = bfin_serial_set_mctrl,
1039 .get_mctrl = bfin_serial_get_mctrl,
1040 .stop_tx = bfin_serial_stop_tx,
1041 .start_tx = bfin_serial_start_tx,
1042 .stop_rx = bfin_serial_stop_rx,
1043 .enable_ms = bfin_serial_enable_ms,
1044 .break_ctl = bfin_serial_break_ctl,
1045 .startup = bfin_serial_startup,
1046 .shutdown = bfin_serial_shutdown,
1047 .set_termios = bfin_serial_set_termios,
1048 .set_ldisc = bfin_serial_set_ldisc,
1049 .type = bfin_serial_type,
1050 .release_port = bfin_serial_release_port,
1051 .request_port = bfin_serial_request_port,
1052 .config_port = bfin_serial_config_port,
1053 .verify_port = bfin_serial_verify_port,
1054#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
1055 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
1056 .kgdboc_port_startup = bfin_kgdboc_port_startup,
1057 .kgdboc_port_shutdown = bfin_kgdboc_port_shutdown,
1058#endif
1059#ifdef CONFIG_CONSOLE_POLL
1060 .poll_put_char = bfin_serial_poll_put_char,
1061 .poll_get_char = bfin_serial_poll_get_char,
1062#endif
1063};
1064
1065#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
1066/*
1067 * If the port was already initialised (eg, by a boot loader),
1068 * try to determine the current setup.
1069 */
1070static void __init
1071bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
1072 int *parity, int *bits)
1073{
1074 unsigned int status;
1075
1076 status = UART_GET_IER(uart) & (ERBFI | ETBEI);
1077 if (status == (ERBFI | ETBEI)) {
1078 /* ok, the port was enabled */
1079 u32 lcr, clk;
1080
1081 lcr = UART_GET_LCR(uart);
1082
1083 *parity = 'n';
1084 if (lcr & PEN) {
1085 if (lcr & EPS)
1086 *parity = 'e';
1087 else
1088 *parity = 'o';
1089 }
1090 *bits = ((lcr & WLS_MASK) >> WLS_OFFSET) + 5;
1091
1092 /* Set DLAB in LCR to Access CLK */
1093 UART_SET_DLAB(uart);
1094
1095 clk = UART_GET_CLK(uart);
1096
1097 /* Clear DLAB in LCR to Access THR RBR IER */
1098 UART_CLEAR_DLAB(uart);
1099
1100 *baud = get_sclk() / (16*clk);
1101 }
1102 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits);
1103}
1104
1105static struct uart_driver bfin_serial_reg;
1106
1107static void bfin_serial_console_putchar(struct uart_port *port, int ch)
1108{
1109 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
1110 while (!(UART_GET_LSR(uart) & THRE))
1111 barrier();
1112 UART_PUT_CHAR(uart, ch);
1113}
1114
1115#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
1116 defined (CONFIG_EARLY_PRINTK) */
1117
1118#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1119#define CLASS_BFIN_CONSOLE "bfin-console"
1120/*
1121 * Interrupts are disabled on entering
1122 */
1123static void
1124bfin_serial_console_write(struct console *co, const char *s, unsigned int count)
1125{
1126 struct bfin_serial_port *uart = bfin_serial_ports[co->index];
1127 unsigned long flags;
1128
1129 spin_lock_irqsave(&uart->port.lock, flags);
1130 uart_console_write(&uart->port, s, count, bfin_serial_console_putchar);
1131 spin_unlock_irqrestore(&uart->port.lock, flags);
1132
1133}
1134
1135static int __init
1136bfin_serial_console_setup(struct console *co, char *options)
1137{
1138 struct bfin_serial_port *uart;
1139 int baud = 57600;
1140 int bits = 8;
1141 int parity = 'n';
1142# if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
1143 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
1144 int flow = 'r';
1145# else
1146 int flow = 'n';
1147# endif
1148
1149 /*
1150 * Check whether an invalid uart number has been specified, and
1151 * if so, search for the first available port that does have
1152 * console support.
1153 */
1154 if (co->index < 0 || co->index >= BFIN_UART_NR_PORTS)
1155 return -ENODEV;
1156
1157 uart = bfin_serial_ports[co->index];
1158 if (!uart)
1159 return -ENODEV;
1160
1161 if (options)
1162 uart_parse_options(options, &baud, &parity, &bits, &flow);
1163 else
1164 bfin_serial_console_get_options(uart, &baud, &parity, &bits);
1165
1166 return uart_set_options(&uart->port, co, baud, parity, bits, flow);
1167}
1168
1169static struct console bfin_serial_console = {
1170 .name = BFIN_SERIAL_DEV_NAME,
1171 .write = bfin_serial_console_write,
1172 .device = uart_console_device,
1173 .setup = bfin_serial_console_setup,
1174 .flags = CON_PRINTBUFFER,
1175 .index = -1,
1176 .data = &bfin_serial_reg,
1177};
1178#define BFIN_SERIAL_CONSOLE (&bfin_serial_console)
1179#else
1180#define BFIN_SERIAL_CONSOLE NULL
1181#endif /* CONFIG_SERIAL_BFIN_CONSOLE */
1182
1183#ifdef CONFIG_EARLY_PRINTK
1184static struct bfin_serial_port bfin_earlyprintk_port;
1185#define CLASS_BFIN_EARLYPRINTK "bfin-earlyprintk"
1186
1187/*
1188 * Interrupts are disabled on entering
1189 */
1190static void
1191bfin_earlyprintk_console_write(struct console *co, const char *s, unsigned int count)
1192{
1193 unsigned long flags;
1194
1195 if (bfin_earlyprintk_port.port.line != co->index)
1196 return;
1197
1198 spin_lock_irqsave(&bfin_earlyprintk_port.port.lock, flags);
1199 uart_console_write(&bfin_earlyprintk_port.port, s, count,
1200 bfin_serial_console_putchar);
1201 spin_unlock_irqrestore(&bfin_earlyprintk_port.port.lock, flags);
1202}
1203
1204/*
1205 * This should have a .setup or .early_setup in it, but then things get called
1206 * without the command line options, and the baud rate gets messed up - so
1207 * don't let the common infrastructure play with things. (see calls to setup
1208 * & earlysetup in ./kernel/printk.c:register_console()
1209 */
1210static struct __initdata console bfin_early_serial_console = {
1211 .name = "early_BFuart",
1212 .write = bfin_earlyprintk_console_write,
1213 .device = uart_console_device,
1214 .flags = CON_PRINTBUFFER,
1215 .index = -1,
1216 .data = &bfin_serial_reg,
1217};
1218#endif
1219
1220static struct uart_driver bfin_serial_reg = {
1221 .owner = THIS_MODULE,
1222 .driver_name = DRIVER_NAME,
1223 .dev_name = BFIN_SERIAL_DEV_NAME,
1224 .major = BFIN_SERIAL_MAJOR,
1225 .minor = BFIN_SERIAL_MINOR,
1226 .nr = BFIN_UART_NR_PORTS,
1227 .cons = BFIN_SERIAL_CONSOLE,
1228};
1229
1230static int bfin_serial_suspend(struct platform_device *pdev, pm_message_t state)
1231{
1232 struct bfin_serial_port *uart = platform_get_drvdata(pdev);
1233
1234 return uart_suspend_port(&bfin_serial_reg, &uart->port);
1235}
1236
1237static int bfin_serial_resume(struct platform_device *pdev)
1238{
1239 struct bfin_serial_port *uart = platform_get_drvdata(pdev);
1240
1241 return uart_resume_port(&bfin_serial_reg, &uart->port);
1242}
1243
1244static int bfin_serial_probe(struct platform_device *pdev)
1245{
1246 struct resource *res;
1247 struct bfin_serial_port *uart = NULL;
1248 int ret = 0;
1249
1250 if (pdev->id < 0 || pdev->id >= BFIN_UART_NR_PORTS) {
1251 dev_err(&pdev->dev, "Wrong bfin uart platform device id.\n");
1252 return -ENOENT;
1253 }
1254
1255 if (bfin_serial_ports[pdev->id] == NULL) {
1256
1257 uart = kzalloc(sizeof(*uart), GFP_KERNEL);
1258 if (!uart) {
1259 dev_err(&pdev->dev,
1260 "fail to malloc bfin_serial_port\n");
1261 return -ENOMEM;
1262 }
1263 bfin_serial_ports[pdev->id] = uart;
1264
1265#ifdef CONFIG_EARLY_PRINTK
1266 if (!(bfin_earlyprintk_port.port.membase
1267 && bfin_earlyprintk_port.port.line == pdev->id)) {
1268 /*
1269 * If the peripheral PINs of current port is allocated
1270 * in earlyprintk probe stage, don't do it again.
1271 */
1272#endif
1273 ret = peripheral_request_list(
1274 (unsigned short *)pdev->dev.platform_data, DRIVER_NAME);
1275 if (ret) {
1276 dev_err(&pdev->dev,
1277 "fail to request bfin serial peripherals\n");
1278 goto out_error_free_mem;
1279 }
1280#ifdef CONFIG_EARLY_PRINTK
1281 }
1282#endif
1283
1284 spin_lock_init(&uart->port.lock);
1285 uart->port.uartclk = get_sclk();
1286 uart->port.fifosize = BFIN_UART_TX_FIFO_SIZE;
1287 uart->port.ops = &bfin_serial_pops;
1288 uart->port.line = pdev->id;
1289 uart->port.iotype = UPIO_MEM;
1290 uart->port.flags = UPF_BOOT_AUTOCONF;
1291
1292 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1293 if (res == NULL) {
1294 dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
1295 ret = -ENOENT;
1296 goto out_error_free_peripherals;
1297 }
1298
1299 uart->port.membase = ioremap(res->start, resource_size(res));
1300 if (!uart->port.membase) {
1301 dev_err(&pdev->dev, "Cannot map uart IO\n");
1302 ret = -ENXIO;
1303 goto out_error_free_peripherals;
1304 }
1305 uart->port.mapbase = res->start;
1306
1307 uart->tx_irq = platform_get_irq(pdev, 0);
1308 if (uart->tx_irq < 0) {
1309 dev_err(&pdev->dev, "No uart TX IRQ specified\n");
1310 ret = -ENOENT;
1311 goto out_error_unmap;
1312 }
1313
1314 uart->rx_irq = platform_get_irq(pdev, 1);
1315 if (uart->rx_irq < 0) {
1316 dev_err(&pdev->dev, "No uart RX IRQ specified\n");
1317 ret = -ENOENT;
1318 goto out_error_unmap;
1319 }
1320 uart->port.irq = uart->rx_irq;
1321
1322 uart->status_irq = platform_get_irq(pdev, 2);
1323 if (uart->status_irq < 0) {
1324 dev_err(&pdev->dev, "No uart status IRQ specified\n");
1325 ret = -ENOENT;
1326 goto out_error_unmap;
1327 }
1328
1329#ifdef CONFIG_SERIAL_BFIN_DMA
1330 spin_lock_init(&uart->rx_lock);
1331 uart->tx_done = 1;
1332 uart->tx_count = 0;
1333
1334 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1335 if (res == NULL) {
1336 dev_err(&pdev->dev, "No uart TX DMA channel specified\n");
1337 ret = -ENOENT;
1338 goto out_error_unmap;
1339 }
1340 uart->tx_dma_channel = res->start;
1341
1342 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1343 if (res == NULL) {
1344 dev_err(&pdev->dev, "No uart RX DMA channel specified\n");
1345 ret = -ENOENT;
1346 goto out_error_unmap;
1347 }
1348 uart->rx_dma_channel = res->start;
1349
1350 init_timer(&(uart->rx_dma_timer));
1351#endif
1352
1353#if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
1354 defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
1355 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1356 if (res == NULL)
1357 uart->cts_pin = -1;
1358 else {
1359 uart->cts_pin = res->start;
1360#ifdef CONFIG_SERIAL_BFIN_CTSRTS
1361 uart->port.flags |= ASYNC_CTS_FLOW;
1362#endif
1363 }
1364
1365 res = platform_get_resource(pdev, IORESOURCE_IO, 1);
1366 if (res == NULL)
1367 uart->rts_pin = -1;
1368 else
1369 uart->rts_pin = res->start;
1370#endif
1371 }
1372
1373#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1374 if (!is_early_platform_device(pdev)) {
1375#endif
1376 uart = bfin_serial_ports[pdev->id];
1377 uart->port.dev = &pdev->dev;
1378 dev_set_drvdata(&pdev->dev, uart);
1379 ret = uart_add_one_port(&bfin_serial_reg, &uart->port);
1380#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1381 }
1382#endif
1383
1384 if (!ret)
1385 return 0;
1386
1387 if (uart) {
1388out_error_unmap:
1389 iounmap(uart->port.membase);
1390out_error_free_peripherals:
1391 peripheral_free_list(
1392 (unsigned short *)pdev->dev.platform_data);
1393out_error_free_mem:
1394 kfree(uart);
1395 bfin_serial_ports[pdev->id] = NULL;
1396 }
1397
1398 return ret;
1399}
1400
1401static int bfin_serial_remove(struct platform_device *pdev)
1402{
1403 struct bfin_serial_port *uart = platform_get_drvdata(pdev);
1404
1405 dev_set_drvdata(&pdev->dev, NULL);
1406
1407 if (uart) {
1408 uart_remove_one_port(&bfin_serial_reg, &uart->port);
1409 iounmap(uart->port.membase);
1410 peripheral_free_list(
1411 (unsigned short *)pdev->dev.platform_data);
1412 kfree(uart);
1413 bfin_serial_ports[pdev->id] = NULL;
1414 }
1415
1416 return 0;
1417}
1418
1419static struct platform_driver bfin_serial_driver = {
1420 .probe = bfin_serial_probe,
1421 .remove = bfin_serial_remove,
1422 .suspend = bfin_serial_suspend,
1423 .resume = bfin_serial_resume,
1424 .driver = {
1425 .name = DRIVER_NAME,
1426 .owner = THIS_MODULE,
1427 },
1428};
1429
1430#if defined(CONFIG_SERIAL_BFIN_CONSOLE)
1431static __initdata struct early_platform_driver early_bfin_serial_driver = {
1432 .class_str = CLASS_BFIN_CONSOLE,
1433 .pdrv = &bfin_serial_driver,
1434 .requested_id = EARLY_PLATFORM_ID_UNSET,
1435};
1436
1437static int __init bfin_serial_rs_console_init(void)
1438{
1439 early_platform_driver_register(&early_bfin_serial_driver, DRIVER_NAME);
1440
1441 early_platform_driver_probe(CLASS_BFIN_CONSOLE, BFIN_UART_NR_PORTS, 0);
1442
1443 register_console(&bfin_serial_console);
1444
1445 return 0;
1446}
1447console_initcall(bfin_serial_rs_console_init);
1448#endif
1449
1450#ifdef CONFIG_EARLY_PRINTK
1451/*
1452 * Memory can't be allocated dynamically during earlyprink init stage.
1453 * So, do individual probe for earlyprink with a static uart port variable.
1454 */
1455static int bfin_earlyprintk_probe(struct platform_device *pdev)
1456{
1457 struct resource *res;
1458 int ret;
1459
1460 if (pdev->id < 0 || pdev->id >= BFIN_UART_NR_PORTS) {
1461 dev_err(&pdev->dev, "Wrong earlyprintk platform device id.\n");
1462 return -ENOENT;
1463 }
1464
1465 ret = peripheral_request_list(
1466 (unsigned short *)pdev->dev.platform_data, DRIVER_NAME);
1467 if (ret) {
1468 dev_err(&pdev->dev,
1469 "fail to request bfin serial peripherals\n");
1470 return ret;
1471 }
1472
1473 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1474 if (res == NULL) {
1475 dev_err(&pdev->dev, "Cannot get IORESOURCE_MEM\n");
1476 ret = -ENOENT;
1477 goto out_error_free_peripherals;
1478 }
1479
1480 bfin_earlyprintk_port.port.membase = ioremap(res->start,
1481 resource_size(res));
1482 if (!bfin_earlyprintk_port.port.membase) {
1483 dev_err(&pdev->dev, "Cannot map uart IO\n");
1484 ret = -ENXIO;
1485 goto out_error_free_peripherals;
1486 }
1487 bfin_earlyprintk_port.port.mapbase = res->start;
1488 bfin_earlyprintk_port.port.line = pdev->id;
1489 bfin_earlyprintk_port.port.uartclk = get_sclk();
1490 bfin_earlyprintk_port.port.fifosize = BFIN_UART_TX_FIFO_SIZE;
1491 spin_lock_init(&bfin_earlyprintk_port.port.lock);
1492
1493 return 0;
1494
1495out_error_free_peripherals:
1496 peripheral_free_list(
1497 (unsigned short *)pdev->dev.platform_data);
1498
1499 return ret;
1500}
1501
1502static struct platform_driver bfin_earlyprintk_driver = {
1503 .probe = bfin_earlyprintk_probe,
1504 .driver = {
1505 .name = DRIVER_NAME,
1506 .owner = THIS_MODULE,
1507 },
1508};
1509
1510static __initdata struct early_platform_driver early_bfin_earlyprintk_driver = {
1511 .class_str = CLASS_BFIN_EARLYPRINTK,
1512 .pdrv = &bfin_earlyprintk_driver,
1513 .requested_id = EARLY_PLATFORM_ID_UNSET,
1514};
1515
1516struct console __init *bfin_earlyserial_init(unsigned int port,
1517 unsigned int cflag)
1518{
1519 struct ktermios t;
1520 char port_name[20];
1521
1522 if (port < 0 || port >= BFIN_UART_NR_PORTS)
1523 return NULL;
1524
1525 /*
1526 * Only probe resource of the given port in earlyprintk boot arg.
1527 * The expected port id should be indicated in port name string.
1528 */
1529 snprintf(port_name, 20, DRIVER_NAME ".%d", port);
1530 early_platform_driver_register(&early_bfin_earlyprintk_driver,
1531 port_name);
1532 early_platform_driver_probe(CLASS_BFIN_EARLYPRINTK, 1, 0);
1533
1534 if (!bfin_earlyprintk_port.port.membase)
1535 return NULL;
1536
1537#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1538 /*
1539 * If we are using early serial, don't let the normal console rewind
1540 * log buffer, since that causes things to be printed multiple times
1541 */
1542 bfin_serial_console.flags &= ~CON_PRINTBUFFER;
1543#endif
1544
1545 bfin_early_serial_console.index = port;
1546 t.c_cflag = cflag;
1547 t.c_iflag = 0;
1548 t.c_oflag = 0;
1549 t.c_lflag = ICANON;
1550 t.c_line = port;
1551 bfin_serial_set_termios(&bfin_earlyprintk_port.port, &t, &t);
1552
1553 return &bfin_early_serial_console;
1554}
1555#endif /* CONFIG_EARLY_PRINTK */
1556
1557static int __init bfin_serial_init(void)
1558{
1559 int ret;
1560
1561 pr_info("Blackfin serial driver\n");
1562
1563 ret = uart_register_driver(&bfin_serial_reg);
1564 if (ret) {
1565 pr_err("failed to register %s:%d\n",
1566 bfin_serial_reg.driver_name, ret);
1567 }
1568
1569 ret = platform_driver_register(&bfin_serial_driver);
1570 if (ret) {
1571 pr_err("fail to register bfin uart\n");
1572 uart_unregister_driver(&bfin_serial_reg);
1573 }
1574
1575 return ret;
1576}
1577
1578static void __exit bfin_serial_exit(void)
1579{
1580 platform_driver_unregister(&bfin_serial_driver);
1581 uart_unregister_driver(&bfin_serial_reg);
1582}
1583
1584
1585module_init(bfin_serial_init);
1586module_exit(bfin_serial_exit);
1587
1588MODULE_AUTHOR("Sonic Zhang, Aubrey Li");
1589MODULE_DESCRIPTION("Blackfin generic serial port driver");
1590MODULE_LICENSE("GPL");
1591MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR);
1592MODULE_ALIAS("platform:bfin-uart");
diff --git a/drivers/tty/serial/clps711x.c b/drivers/tty/serial/clps711x.c
index 3fd2526d121..e6c3dbd781d 100644
--- a/drivers/tty/serial/clps711x.c
+++ b/drivers/tty/serial/clps711x.c
@@ -10,6 +10,15 @@
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. 12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 */ 22 */
14 23
15#if defined(CONFIG_SERIAL_CLPS711X_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 24#if defined(CONFIG_SERIAL_CLPS711X_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
@@ -17,169 +26,171 @@
17#endif 26#endif
18 27
19#include <linux/module.h> 28#include <linux/module.h>
20#include <linux/device.h> 29#include <linux/ioport.h>
30#include <linux/init.h>
21#include <linux/console.h> 31#include <linux/console.h>
32#include <linux/sysrq.h>
33#include <linux/spinlock.h>
34#include <linux/device.h>
35#include <linux/tty.h>
36#include <linux/tty_flip.h>
22#include <linux/serial_core.h> 37#include <linux/serial_core.h>
23#include <linux/serial.h> 38#include <linux/serial.h>
24#include <linux/io.h> 39#include <linux/io.h>
25#include <linux/clk.h>
26#include <linux/tty.h>
27#include <linux/tty_flip.h>
28#include <linux/ioport.h>
29#include <linux/platform_device.h>
30 40
31#include <mach/hardware.h> 41#include <mach/hardware.h>
42#include <asm/irq.h>
43#include <asm/hardware/clps7111.h>
32 44
33#define UART_CLPS711X_NAME "uart-clps711x" 45#define UART_NR 2
34#define UART_CLPS711X_NR 2
35#define UART_CLPS711X_MAJOR 204
36#define UART_CLPS711X_MINOR 40
37
38#define UBRLCR(port) ((port)->line ? UBRLCR2 : UBRLCR1)
39#define UARTDR(port) ((port)->line ? UARTDR2 : UARTDR1)
40#define SYSFLG(port) ((port)->line ? SYSFLG2 : SYSFLG1)
41#define SYSCON(port) ((port)->line ? SYSCON2 : SYSCON1)
42#define TX_IRQ(port) ((port)->line ? IRQ_UTXINT2 : IRQ_UTXINT1)
43#define RX_IRQ(port) ((port)->line ? IRQ_URXINT2 : IRQ_URXINT1)
44
45struct clps711x_port {
46 struct uart_driver uart;
47 struct clk *uart_clk;
48 struct uart_port port[UART_CLPS711X_NR];
49 int tx_enabled[UART_CLPS711X_NR];
50#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
51 struct console console;
52#endif
53};
54 46
55static void uart_clps711x_stop_tx(struct uart_port *port) 47#define SERIAL_CLPS711X_MAJOR 204
56{ 48#define SERIAL_CLPS711X_MINOR 40
57 struct clps711x_port *s = dev_get_drvdata(port->dev); 49#define SERIAL_CLPS711X_NR UART_NR
58 50
59 if (s->tx_enabled[port->line]) { 51/*
52 * We use the relevant SYSCON register as a base address for these ports.
53 */
54#define UBRLCR(port) ((port)->iobase + UBRLCR1 - SYSCON1)
55#define UARTDR(port) ((port)->iobase + UARTDR1 - SYSCON1)
56#define SYSFLG(port) ((port)->iobase + SYSFLG1 - SYSCON1)
57#define SYSCON(port) ((port)->iobase + SYSCON1 - SYSCON1)
58
59#define TX_IRQ(port) ((port)->irq)
60#define RX_IRQ(port) ((port)->irq + 1)
61
62#define UART_ANY_ERR (UARTDR_FRMERR | UARTDR_PARERR | UARTDR_OVERR)
63
64#define tx_enabled(port) ((port)->unused[0])
65
66static void clps711xuart_stop_tx(struct uart_port *port)
67{
68 if (tx_enabled(port)) {
60 disable_irq(TX_IRQ(port)); 69 disable_irq(TX_IRQ(port));
61 s->tx_enabled[port->line] = 0; 70 tx_enabled(port) = 0;
62 } 71 }
63} 72}
64 73
65static void uart_clps711x_start_tx(struct uart_port *port) 74static void clps711xuart_start_tx(struct uart_port *port)
66{ 75{
67 struct clps711x_port *s = dev_get_drvdata(port->dev); 76 if (!tx_enabled(port)) {
68
69 if (!s->tx_enabled[port->line]) {
70 enable_irq(TX_IRQ(port)); 77 enable_irq(TX_IRQ(port));
71 s->tx_enabled[port->line] = 1; 78 tx_enabled(port) = 1;
72 } 79 }
73} 80}
74 81
75static void uart_clps711x_stop_rx(struct uart_port *port) 82static void clps711xuart_stop_rx(struct uart_port *port)
76{ 83{
77 disable_irq(RX_IRQ(port)); 84 disable_irq(RX_IRQ(port));
78} 85}
79 86
80static void uart_clps711x_enable_ms(struct uart_port *port) 87static void clps711xuart_enable_ms(struct uart_port *port)
81{ 88{
82 /* Do nothing */
83} 89}
84 90
85static irqreturn_t uart_clps711x_int_rx(int irq, void *dev_id) 91static irqreturn_t clps711xuart_int_rx(int irq, void *dev_id)
86{ 92{
87 struct uart_port *port = dev_id; 93 struct uart_port *port = dev_id;
88 struct tty_struct *tty = tty_port_tty_get(&port->state->port); 94 struct tty_struct *tty = port->state->port.tty;
89 unsigned int status, ch, flg; 95 unsigned int status, ch, flg;
90 96
91 if (!tty) 97 status = clps_readl(SYSFLG(port));
92 return IRQ_HANDLED; 98 while (!(status & SYSFLG_URXFE)) {
93 99 ch = clps_readl(UARTDR(port));
94 for (;;) {
95 status = clps_readl(SYSFLG(port));
96 if (status & SYSFLG_URXFE)
97 break;
98
99 ch = clps_readw(UARTDR(port));
100 status = ch & (UARTDR_FRMERR | UARTDR_PARERR | UARTDR_OVERR);
101 ch &= 0xff;
102 100
103 port->icount.rx++; 101 port->icount.rx++;
102
104 flg = TTY_NORMAL; 103 flg = TTY_NORMAL;
105 104
106 if (unlikely(status)) { 105 /*
107 if (status & UARTDR_PARERR) 106 * Note that the error handling code is
107 * out of the main execution path
108 */
109 if (unlikely(ch & UART_ANY_ERR)) {
110 if (ch & UARTDR_PARERR)
108 port->icount.parity++; 111 port->icount.parity++;
109 else if (status & UARTDR_FRMERR) 112 else if (ch & UARTDR_FRMERR)
110 port->icount.frame++; 113 port->icount.frame++;
111 else if (status & UARTDR_OVERR) 114 if (ch & UARTDR_OVERR)
112 port->icount.overrun++; 115 port->icount.overrun++;
113 116
114 status &= port->read_status_mask; 117 ch &= port->read_status_mask;
115 118
116 if (status & UARTDR_PARERR) 119 if (ch & UARTDR_PARERR)
117 flg = TTY_PARITY; 120 flg = TTY_PARITY;
118 else if (status & UARTDR_FRMERR) 121 else if (ch & UARTDR_FRMERR)
119 flg = TTY_FRAME; 122 flg = TTY_FRAME;
120 else if (status & UARTDR_OVERR) 123
121 flg = TTY_OVERRUN; 124#ifdef SUPPORT_SYSRQ
125 port->sysrq = 0;
126#endif
122 } 127 }
123 128
124 if (uart_handle_sysrq_char(port, ch)) 129 if (uart_handle_sysrq_char(port, ch))
125 continue; 130 goto ignore_char;
126 131
127 if (status & port->ignore_status_mask) 132 /*
128 continue; 133 * CHECK: does overrun affect the current character?
134 * ASSUMPTION: it does not.
135 */
136 uart_insert_char(port, ch, UARTDR_OVERR, ch, flg);
129 137
130 uart_insert_char(port, status, UARTDR_OVERR, ch, flg); 138 ignore_char:
139 status = clps_readl(SYSFLG(port));
131 } 140 }
132
133 tty_flip_buffer_push(tty); 141 tty_flip_buffer_push(tty);
134
135 tty_kref_put(tty);
136
137 return IRQ_HANDLED; 142 return IRQ_HANDLED;
138} 143}
139 144
140static irqreturn_t uart_clps711x_int_tx(int irq, void *dev_id) 145static irqreturn_t clps711xuart_int_tx(int irq, void *dev_id)
141{ 146{
142 struct uart_port *port = dev_id; 147 struct uart_port *port = dev_id;
143 struct clps711x_port *s = dev_get_drvdata(port->dev);
144 struct circ_buf *xmit = &port->state->xmit; 148 struct circ_buf *xmit = &port->state->xmit;
149 int count;
145 150
146 if (port->x_char) { 151 if (port->x_char) {
147 clps_writew(port->x_char, UARTDR(port)); 152 clps_writel(port->x_char, UARTDR(port));
148 port->icount.tx++; 153 port->icount.tx++;
149 port->x_char = 0; 154 port->x_char = 0;
150 return IRQ_HANDLED; 155 return IRQ_HANDLED;
151 } 156 }
152
153 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { 157 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
154 disable_irq_nosync(TX_IRQ(port)); 158 clps711xuart_stop_tx(port);
155 s->tx_enabled[port->line] = 0;
156 return IRQ_HANDLED; 159 return IRQ_HANDLED;
157 } 160 }
158 161
159 while (!uart_circ_empty(xmit)) { 162 count = port->fifosize >> 1;
160 clps_writew(xmit->buf[xmit->tail], UARTDR(port)); 163 do {
164 clps_writel(xmit->buf[xmit->tail], UARTDR(port));
161 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 165 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
162 port->icount.tx++; 166 port->icount.tx++;
163 if (clps_readl(SYSFLG(port) & SYSFLG_UTXFF)) 167 if (uart_circ_empty(xmit))
164 break; 168 break;
165 } 169 } while (--count > 0);
166 170
167 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 171 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
168 uart_write_wakeup(port); 172 uart_write_wakeup(port);
169 173
174 if (uart_circ_empty(xmit))
175 clps711xuart_stop_tx(port);
176
170 return IRQ_HANDLED; 177 return IRQ_HANDLED;
171} 178}
172 179
173static unsigned int uart_clps711x_tx_empty(struct uart_port *port) 180static unsigned int clps711xuart_tx_empty(struct uart_port *port)
174{ 181{
175 return (clps_readl(SYSFLG(port) & SYSFLG_UBUSY)) ? 0 : TIOCSER_TEMT; 182 unsigned int status = clps_readl(SYSFLG(port));
183 return status & SYSFLG_UBUSY ? 0 : TIOCSER_TEMT;
176} 184}
177 185
178static unsigned int uart_clps711x_get_mctrl(struct uart_port *port) 186static unsigned int clps711xuart_get_mctrl(struct uart_port *port)
179{ 187{
180 unsigned int status, result = 0; 188 unsigned int port_addr;
189 unsigned int result = 0;
190 unsigned int status;
181 191
182 if (port->line == 0) { 192 port_addr = SYSFLG(port);
193 if (port_addr == SYSFLG1) {
183 status = clps_readl(SYSFLG1); 194 status = clps_readl(SYSFLG1);
184 if (status & SYSFLG1_DCD) 195 if (status & SYSFLG1_DCD)
185 result |= TIOCM_CAR; 196 result |= TIOCM_CAR;
@@ -187,86 +198,104 @@ static unsigned int uart_clps711x_get_mctrl(struct uart_port *port)
187 result |= TIOCM_DSR; 198 result |= TIOCM_DSR;
188 if (status & SYSFLG1_CTS) 199 if (status & SYSFLG1_CTS)
189 result |= TIOCM_CTS; 200 result |= TIOCM_CTS;
190 } else 201 }
191 result = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR;
192 202
193 return result; 203 return result;
194} 204}
195 205
196static void uart_clps711x_set_mctrl(struct uart_port *port, unsigned int mctrl) 206static void
207clps711xuart_set_mctrl_null(struct uart_port *port, unsigned int mctrl)
197{ 208{
198 /* Do nothing */
199} 209}
200 210
201static void uart_clps711x_break_ctl(struct uart_port *port, int break_state) 211static void clps711xuart_break_ctl(struct uart_port *port, int break_state)
202{ 212{
203 unsigned long flags; 213 unsigned long flags;
204 unsigned int ubrlcr; 214 unsigned int ubrlcr;
205 215
206 spin_lock_irqsave(&port->lock, flags); 216 spin_lock_irqsave(&port->lock, flags);
207
208 ubrlcr = clps_readl(UBRLCR(port)); 217 ubrlcr = clps_readl(UBRLCR(port));
209 if (break_state) 218 if (break_state == -1)
210 ubrlcr |= UBRLCR_BREAK; 219 ubrlcr |= UBRLCR_BREAK;
211 else 220 else
212 ubrlcr &= ~UBRLCR_BREAK; 221 ubrlcr &= ~UBRLCR_BREAK;
213 clps_writel(ubrlcr, UBRLCR(port)); 222 clps_writel(ubrlcr, UBRLCR(port));
214
215 spin_unlock_irqrestore(&port->lock, flags); 223 spin_unlock_irqrestore(&port->lock, flags);
216} 224}
217 225
218static int uart_clps711x_startup(struct uart_port *port) 226static int clps711xuart_startup(struct uart_port *port)
219{ 227{
220 struct clps711x_port *s = dev_get_drvdata(port->dev); 228 unsigned int syscon;
221 int ret; 229 int retval;
222 230
223 s->tx_enabled[port->line] = 1; 231 tx_enabled(port) = 1;
224 /* Allocate the IRQs */ 232
225 ret = devm_request_irq(port->dev, TX_IRQ(port), uart_clps711x_int_tx, 233 /*
226 0, UART_CLPS711X_NAME " TX", port); 234 * Allocate the IRQs
227 if (ret) 235 */
228 return ret; 236 retval = request_irq(TX_IRQ(port), clps711xuart_int_tx, 0,
229 237 "clps711xuart_tx", port);
230 ret = devm_request_irq(port->dev, RX_IRQ(port), uart_clps711x_int_rx, 238 if (retval)
231 0, UART_CLPS711X_NAME " RX", port); 239 return retval;
232 if (ret) { 240
233 devm_free_irq(port->dev, TX_IRQ(port), port); 241 retval = request_irq(RX_IRQ(port), clps711xuart_int_rx, 0,
234 return ret; 242 "clps711xuart_rx", port);
243 if (retval) {
244 free_irq(TX_IRQ(port), port);
245 return retval;
235 } 246 }
236 247
237 /* Disable break */ 248 /*
238 clps_writel(clps_readl(UBRLCR(port)) & ~UBRLCR_BREAK, UBRLCR(port)); 249 * enable the port
239 250 */
240 /* Enable the port */ 251 syscon = clps_readl(SYSCON(port));
241 clps_writel(clps_readl(SYSCON(port)) | SYSCON_UARTEN, SYSCON(port)); 252 syscon |= SYSCON_UARTEN;
253 clps_writel(syscon, SYSCON(port));
242 254
243 return 0; 255 return 0;
244} 256}
245 257
246static void uart_clps711x_shutdown(struct uart_port *port) 258static void clps711xuart_shutdown(struct uart_port *port)
247{ 259{
248 /* Free the interrupts */ 260 unsigned int ubrlcr, syscon;
249 devm_free_irq(port->dev, TX_IRQ(port), port); 261
250 devm_free_irq(port->dev, RX_IRQ(port), port); 262 /*
263 * Free the interrupt
264 */
265 free_irq(TX_IRQ(port), port); /* TX interrupt */
266 free_irq(RX_IRQ(port), port); /* RX interrupt */
267
268 /*
269 * disable the port
270 */
271 syscon = clps_readl(SYSCON(port));
272 syscon &= ~SYSCON_UARTEN;
273 clps_writel(syscon, SYSCON(port));
251 274
252 /* Disable the port */ 275 /*
253 clps_writel(clps_readl(SYSCON(port)) & ~SYSCON_UARTEN, SYSCON(port)); 276 * disable break condition and fifos
277 */
278 ubrlcr = clps_readl(UBRLCR(port));
279 ubrlcr &= ~(UBRLCR_FIFOEN | UBRLCR_BREAK);
280 clps_writel(ubrlcr, UBRLCR(port));
254} 281}
255 282
256static void uart_clps711x_set_termios(struct uart_port *port, 283static void
257 struct ktermios *termios, 284clps711xuart_set_termios(struct uart_port *port, struct ktermios *termios,
258 struct ktermios *old) 285 struct ktermios *old)
259{ 286{
260 unsigned int ubrlcr, baud, quot; 287 unsigned int ubrlcr, baud, quot;
261 unsigned long flags; 288 unsigned long flags;
262 289
263 /* Mask termios capabilities we don't support */ 290 /*
264 termios->c_cflag &= ~CMSPAR; 291 * We don't implement CREAD.
265 termios->c_iflag &= ~(BRKINT | IGNBRK); 292 */
293 termios->c_cflag |= CREAD;
266 294
267 /* Ask the core to calculate the divisor for us */ 295 /*
268 baud = uart_get_baud_rate(port, termios, old, port->uartclk / 4096, 296 * Ask the core to calculate the divisor for us.
269 port->uartclk / 16); 297 */
298 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
270 quot = uart_get_divisor(port, baud); 299 quot = uart_get_divisor(port, baud);
271 300
272 switch (termios->c_cflag & CSIZE) { 301 switch (termios->c_cflag & CSIZE) {
@@ -279,117 +308,160 @@ static void uart_clps711x_set_termios(struct uart_port *port,
279 case CS7: 308 case CS7:
280 ubrlcr = UBRLCR_WRDLEN7; 309 ubrlcr = UBRLCR_WRDLEN7;
281 break; 310 break;
282 case CS8: 311 default: // CS8
283 default:
284 ubrlcr = UBRLCR_WRDLEN8; 312 ubrlcr = UBRLCR_WRDLEN8;
285 break; 313 break;
286 } 314 }
287
288 if (termios->c_cflag & CSTOPB) 315 if (termios->c_cflag & CSTOPB)
289 ubrlcr |= UBRLCR_XSTOP; 316 ubrlcr |= UBRLCR_XSTOP;
290
291 if (termios->c_cflag & PARENB) { 317 if (termios->c_cflag & PARENB) {
292 ubrlcr |= UBRLCR_PRTEN; 318 ubrlcr |= UBRLCR_PRTEN;
293 if (!(termios->c_cflag & PARODD)) 319 if (!(termios->c_cflag & PARODD))
294 ubrlcr |= UBRLCR_EVENPRT; 320 ubrlcr |= UBRLCR_EVENPRT;
295 } 321 }
296 322 if (port->fifosize > 1)
297 /* Enable FIFO */ 323 ubrlcr |= UBRLCR_FIFOEN;
298 ubrlcr |= UBRLCR_FIFOEN;
299 324
300 spin_lock_irqsave(&port->lock, flags); 325 spin_lock_irqsave(&port->lock, flags);
301 326
302 /* Set read status mask */ 327 /*
328 * Update the per-port timeout.
329 */
330 uart_update_timeout(port, termios->c_cflag, baud);
331
303 port->read_status_mask = UARTDR_OVERR; 332 port->read_status_mask = UARTDR_OVERR;
304 if (termios->c_iflag & INPCK) 333 if (termios->c_iflag & INPCK)
305 port->read_status_mask |= UARTDR_PARERR | UARTDR_FRMERR; 334 port->read_status_mask |= UARTDR_PARERR | UARTDR_FRMERR;
306 335
307 /* Set status ignore mask */ 336 /*
337 * Characters to ignore
338 */
308 port->ignore_status_mask = 0; 339 port->ignore_status_mask = 0;
309 if (!(termios->c_cflag & CREAD)) 340 if (termios->c_iflag & IGNPAR)
310 port->ignore_status_mask |= UARTDR_OVERR | UARTDR_PARERR | 341 port->ignore_status_mask |= UARTDR_FRMERR | UARTDR_PARERR;
311 UARTDR_FRMERR; 342 if (termios->c_iflag & IGNBRK) {
343 /*
344 * If we're ignoring parity and break indicators,
345 * ignore overruns to (for real raw support).
346 */
347 if (termios->c_iflag & IGNPAR)
348 port->ignore_status_mask |= UARTDR_OVERR;
349 }
312 350
313 uart_update_timeout(port, termios->c_cflag, baud); 351 quot -= 1;
314 352
315 clps_writel(ubrlcr | (quot - 1), UBRLCR(port)); 353 clps_writel(ubrlcr | quot, UBRLCR(port));
316 354
317 spin_unlock_irqrestore(&port->lock, flags); 355 spin_unlock_irqrestore(&port->lock, flags);
318} 356}
319 357
320static const char *uart_clps711x_type(struct uart_port *port) 358static const char *clps711xuart_type(struct uart_port *port)
321{ 359{
322 return (port->type == PORT_CLPS711X) ? "CLPS711X" : NULL; 360 return port->type == PORT_CLPS711X ? "CLPS711x" : NULL;
323} 361}
324 362
325static void uart_clps711x_config_port(struct uart_port *port, int flags) 363/*
364 * Configure/autoconfigure the port.
365 */
366static void clps711xuart_config_port(struct uart_port *port, int flags)
326{ 367{
327 if (flags & UART_CONFIG_TYPE) 368 if (flags & UART_CONFIG_TYPE)
328 port->type = PORT_CLPS711X; 369 port->type = PORT_CLPS711X;
329} 370}
330 371
331static void uart_clps711x_release_port(struct uart_port *port) 372static void clps711xuart_release_port(struct uart_port *port)
332{ 373{
333 /* Do nothing */
334} 374}
335 375
336static int uart_clps711x_request_port(struct uart_port *port) 376static int clps711xuart_request_port(struct uart_port *port)
337{ 377{
338 /* Do nothing */
339 return 0; 378 return 0;
340} 379}
341 380
342static const struct uart_ops uart_clps711x_ops = { 381static struct uart_ops clps711x_pops = {
343 .tx_empty = uart_clps711x_tx_empty, 382 .tx_empty = clps711xuart_tx_empty,
344 .set_mctrl = uart_clps711x_set_mctrl, 383 .set_mctrl = clps711xuart_set_mctrl_null,
345 .get_mctrl = uart_clps711x_get_mctrl, 384 .get_mctrl = clps711xuart_get_mctrl,
346 .stop_tx = uart_clps711x_stop_tx, 385 .stop_tx = clps711xuart_stop_tx,
347 .start_tx = uart_clps711x_start_tx, 386 .start_tx = clps711xuart_start_tx,
348 .stop_rx = uart_clps711x_stop_rx, 387 .stop_rx = clps711xuart_stop_rx,
349 .enable_ms = uart_clps711x_enable_ms, 388 .enable_ms = clps711xuart_enable_ms,
350 .break_ctl = uart_clps711x_break_ctl, 389 .break_ctl = clps711xuart_break_ctl,
351 .startup = uart_clps711x_startup, 390 .startup = clps711xuart_startup,
352 .shutdown = uart_clps711x_shutdown, 391 .shutdown = clps711xuart_shutdown,
353 .set_termios = uart_clps711x_set_termios, 392 .set_termios = clps711xuart_set_termios,
354 .type = uart_clps711x_type, 393 .type = clps711xuart_type,
355 .config_port = uart_clps711x_config_port, 394 .config_port = clps711xuart_config_port,
356 .release_port = uart_clps711x_release_port, 395 .release_port = clps711xuart_release_port,
357 .request_port = uart_clps711x_request_port, 396 .request_port = clps711xuart_request_port,
397};
398
399static struct uart_port clps711x_ports[UART_NR] = {
400 {
401 .iobase = SYSCON1,
402 .irq = IRQ_UTXINT1, /* IRQ_URXINT1, IRQ_UMSINT */
403 .uartclk = 3686400,
404 .fifosize = 16,
405 .ops = &clps711x_pops,
406 .line = 0,
407 .flags = UPF_BOOT_AUTOCONF,
408 },
409 {
410 .iobase = SYSCON2,
411 .irq = IRQ_UTXINT2, /* IRQ_URXINT2 */
412 .uartclk = 3686400,
413 .fifosize = 16,
414 .ops = &clps711x_pops,
415 .line = 1,
416 .flags = UPF_BOOT_AUTOCONF,
417 }
358}; 418};
359 419
360#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE 420#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
361static void uart_clps711x_console_putchar(struct uart_port *port, int ch) 421static void clps711xuart_console_putchar(struct uart_port *port, int ch)
362{ 422{
363 while (clps_readl(SYSFLG(port)) & SYSFLG_UTXFF) 423 while (clps_readl(SYSFLG(port)) & SYSFLG_UTXFF)
364 barrier(); 424 barrier();
365 425 clps_writel(ch, UARTDR(port));
366 clps_writew(ch, UARTDR(port));
367} 426}
368 427
369static void uart_clps711x_console_write(struct console *co, const char *c, 428/*
370 unsigned n) 429 * Print a string to the serial port trying not to disturb
430 * any possible real use of the port...
431 *
432 * The console_lock must be held when we get here.
433 *
434 * Note that this is called with interrupts already disabled
435 */
436static void
437clps711xuart_console_write(struct console *co, const char *s,
438 unsigned int count)
371{ 439{
372 struct clps711x_port *s = (struct clps711x_port *)co->data; 440 struct uart_port *port = clps711x_ports + co->index;
373 struct uart_port *port = &s->port[co->index]; 441 unsigned int status, syscon;
374 u32 syscon;
375 442
376 /* Ensure that the port is enabled */ 443 /*
444 * Ensure that the port is enabled.
445 */
377 syscon = clps_readl(SYSCON(port)); 446 syscon = clps_readl(SYSCON(port));
378 clps_writel(syscon | SYSCON_UARTEN, SYSCON(port)); 447 clps_writel(syscon | SYSCON_UARTEN, SYSCON(port));
379 448
380 uart_console_write(port, c, n, uart_clps711x_console_putchar); 449 uart_console_write(port, s, count, clps711xuart_console_putchar);
381 450
382 /* Wait for transmitter to become empty */ 451 /*
383 while (clps_readl(SYSFLG(port)) & SYSFLG_UBUSY) 452 * Finally, wait for transmitter to become empty
384 barrier(); 453 * and restore the uart state.
454 */
455 do {
456 status = clps_readl(SYSFLG(port));
457 } while (status & SYSFLG_UBUSY);
385 458
386 /* Restore the uart state */
387 clps_writel(syscon, SYSCON(port)); 459 clps_writel(syscon, SYSCON(port));
388} 460}
389 461
390static void uart_clps711x_console_get_options(struct uart_port *port, 462static void __init
391 int *baud, int *parity, 463clps711xuart_console_get_options(struct uart_port *port, int *baud,
392 int *bits) 464 int *parity, int *bits)
393{ 465{
394 if (clps_readl(SYSCON(port)) & SYSCON_UARTEN) { 466 if (clps_readl(SYSCON(port)) & SYSCON_UARTEN) {
395 unsigned int ubrlcr, quot; 467 unsigned int ubrlcr, quot;
@@ -414,124 +486,92 @@ static void uart_clps711x_console_get_options(struct uart_port *port,
414 } 486 }
415} 487}
416 488
417static int uart_clps711x_console_setup(struct console *co, char *options) 489static int __init clps711xuart_console_setup(struct console *co, char *options)
418{ 490{
419 int baud = 38400, bits = 8, parity = 'n', flow = 'n'; 491 struct uart_port *port;
420 struct clps711x_port *s = (struct clps711x_port *)co->data; 492 int baud = 38400;
421 struct uart_port *port = &s->port[(co->index > 0) ? co->index : 0]; 493 int bits = 8;
494 int parity = 'n';
495 int flow = 'n';
496
497 /*
498 * Check whether an invalid uart number has been specified, and
499 * if so, search for the first available port that does have
500 * console support.
501 */
502 port = uart_get_console(clps711x_ports, UART_NR, co);
422 503
423 if (options) 504 if (options)
424 uart_parse_options(options, &baud, &parity, &bits, &flow); 505 uart_parse_options(options, &baud, &parity, &bits, &flow);
425 else 506 else
426 uart_clps711x_console_get_options(port, &baud, &parity, &bits); 507 clps711xuart_console_get_options(port, &baud, &parity, &bits);
427 508
428 return uart_set_options(port, co, baud, parity, bits, flow); 509 return uart_set_options(port, co, baud, parity, bits, flow);
429} 510}
430#endif
431
432static int uart_clps711x_probe(struct platform_device *pdev)
433{
434 struct clps711x_port *s;
435 int ret, i;
436 511
437 s = devm_kzalloc(&pdev->dev, sizeof(struct clps711x_port), GFP_KERNEL); 512static struct uart_driver clps711x_reg;
438 if (!s) { 513static struct console clps711x_console = {
439 dev_err(&pdev->dev, "Error allocating port structure\n"); 514 .name = "ttyCL",
440 return -ENOMEM; 515 .write = clps711xuart_console_write,
441 } 516 .device = uart_console_device,
442 platform_set_drvdata(pdev, s); 517 .setup = clps711xuart_console_setup,
518 .flags = CON_PRINTBUFFER,
519 .index = -1,
520 .data = &clps711x_reg,
521};
443 522
444 s->uart_clk = devm_clk_get(&pdev->dev, "uart"); 523static int __init clps711xuart_console_init(void)
445 if (IS_ERR(s->uart_clk)) { 524{
446 dev_err(&pdev->dev, "Can't get UART clocks\n"); 525 register_console(&clps711x_console);
447 ret = PTR_ERR(s->uart_clk); 526 return 0;
448 goto err_out; 527}
449 } 528console_initcall(clps711xuart_console_init);
450 529
451 s->uart.owner = THIS_MODULE; 530#define CLPS711X_CONSOLE &clps711x_console
452 s->uart.dev_name = "ttyCL"; 531#else
453 s->uart.major = UART_CLPS711X_MAJOR; 532#define CLPS711X_CONSOLE NULL
454 s->uart.minor = UART_CLPS711X_MINOR;
455 s->uart.nr = UART_CLPS711X_NR;
456#ifdef CONFIG_SERIAL_CLPS711X_CONSOLE
457 s->uart.cons = &s->console;
458 s->uart.cons->device = uart_console_device;
459 s->uart.cons->write = uart_clps711x_console_write;
460 s->uart.cons->setup = uart_clps711x_console_setup;
461 s->uart.cons->flags = CON_PRINTBUFFER;
462 s->uart.cons->index = -1;
463 s->uart.cons->data = s;
464 strcpy(s->uart.cons->name, "ttyCL");
465#endif 533#endif
466 ret = uart_register_driver(&s->uart);
467 if (ret) {
468 dev_err(&pdev->dev, "Registering UART driver failed\n");
469 devm_clk_put(&pdev->dev, s->uart_clk);
470 goto err_out;
471 }
472 534
473 for (i = 0; i < UART_CLPS711X_NR; i++) { 535static struct uart_driver clps711x_reg = {
474 s->port[i].line = i; 536 .driver_name = "ttyCL",
475 s->port[i].dev = &pdev->dev; 537 .dev_name = "ttyCL",
476 s->port[i].irq = TX_IRQ(&s->port[i]); 538 .major = SERIAL_CLPS711X_MAJOR,
477 s->port[i].iobase = SYSCON(&s->port[i]); 539 .minor = SERIAL_CLPS711X_MINOR,
478 s->port[i].type = PORT_CLPS711X; 540 .nr = UART_NR,
479 s->port[i].fifosize = 16;
480 s->port[i].flags = UPF_SKIP_TEST | UPF_FIXED_TYPE;
481 s->port[i].uartclk = clk_get_rate(s->uart_clk);
482 s->port[i].ops = &uart_clps711x_ops;
483 WARN_ON(uart_add_one_port(&s->uart, &s->port[i]));
484 }
485
486 return 0;
487 541
488err_out: 542 .cons = CLPS711X_CONSOLE,
489 platform_set_drvdata(pdev, NULL); 543};
490
491 return ret;
492}
493 544
494static int uart_clps711x_remove(struct platform_device *pdev) 545static int __init clps711xuart_init(void)
495{ 546{
496 struct clps711x_port *s = platform_get_drvdata(pdev); 547 int ret, i;
497 int i;
498 548
499 for (i = 0; i < UART_CLPS711X_NR; i++) 549 printk(KERN_INFO "Serial: CLPS711x driver\n");
500 uart_remove_one_port(&s->uart, &s->port[i]);
501 550
502 devm_clk_put(&pdev->dev, s->uart_clk); 551 ret = uart_register_driver(&clps711x_reg);
503 uart_unregister_driver(&s->uart); 552 if (ret)
504 platform_set_drvdata(pdev, NULL); 553 return ret;
554
555 for (i = 0; i < UART_NR; i++)
556 uart_add_one_port(&clps711x_reg, &clps711x_ports[i]);
505 557
506 return 0; 558 return 0;
507} 559}
508 560
509static struct platform_driver clps711x_uart_driver = { 561static void __exit clps711xuart_exit(void)
510 .driver = { 562{
511 .name = UART_CLPS711X_NAME, 563 int i;
512 .owner = THIS_MODULE,
513 },
514 .probe = uart_clps711x_probe,
515 .remove = uart_clps711x_remove,
516};
517module_platform_driver(clps711x_uart_driver);
518 564
519static struct platform_device clps711x_uart_device = { 565 for (i = 0; i < UART_NR; i++)
520 .name = UART_CLPS711X_NAME, 566 uart_remove_one_port(&clps711x_reg, &clps711x_ports[i]);
521};
522 567
523static int __init uart_clps711x_init(void) 568 uart_unregister_driver(&clps711x_reg);
524{
525 return platform_device_register(&clps711x_uart_device);
526} 569}
527module_init(uart_clps711x_init);
528 570
529static void __exit uart_clps711x_exit(void) 571module_init(clps711xuart_init);
530{ 572module_exit(clps711xuart_exit);
531 platform_device_unregister(&clps711x_uart_device);
532}
533module_exit(uart_clps711x_exit);
534 573
535MODULE_AUTHOR("Deep Blue Solutions Ltd"); 574MODULE_AUTHOR("Deep Blue Solutions Ltd");
536MODULE_DESCRIPTION("CLPS711X serial driver"); 575MODULE_DESCRIPTION("CLPS-711x generic serial driver");
537MODULE_LICENSE("GPL"); 576MODULE_LICENSE("GPL");
577MODULE_ALIAS_CHARDEV(SERIAL_CLPS711X_MAJOR, SERIAL_CLPS711X_MINOR);
diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
index ad0caf17680..9488da74d4f 100644
--- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
@@ -31,7 +31,6 @@
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>
35#include <linux/ioport.h> 34#include <linux/ioport.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/serial.h> 36#include <linux/serial.h>
@@ -71,7 +70,7 @@ static void cpm_uart_initbd(struct uart_cpm_port *pinfo);
71 70
72/**************************************************************/ 71/**************************************************************/
73 72
74#define HW_BUF_SPD_THRESHOLD 2400 73#define HW_BUF_SPD_THRESHOLD 9600
75 74
76/* 75/*
77 * Check, if transmit buffers are processed 76 * Check, if transmit buffers are processed
@@ -417,7 +416,6 @@ static int cpm_uart_startup(struct uart_port *port)
417 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR); 416 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR);
418 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX); 417 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX);
419 } 418 }
420 cpm_uart_initbd(pinfo);
421 cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX); 419 cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
422 } 420 }
423 /* Install interrupt handler. */ 421 /* Install interrupt handler. */
@@ -501,28 +499,16 @@ static void cpm_uart_set_termios(struct uart_port *port,
501 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port; 499 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
502 smc_t __iomem *smcp = pinfo->smcp; 500 smc_t __iomem *smcp = pinfo->smcp;
503 scc_t __iomem *sccp = pinfo->sccp; 501 scc_t __iomem *sccp = pinfo->sccp;
504 int maxidl;
505 502
506 pr_debug("CPM uart[%d]:set_termios\n", port->line); 503 pr_debug("CPM uart[%d]:set_termios\n", port->line);
507 504
508 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); 505 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
509 if (baud < HW_BUF_SPD_THRESHOLD || 506 if (baud <= HW_BUF_SPD_THRESHOLD ||
510 (pinfo->port.state && pinfo->port.state->port.tty->low_latency)) 507 (pinfo->port.state && pinfo->port.state->port.tty->low_latency))
511 pinfo->rx_fifosize = 1; 508 pinfo->rx_fifosize = 1;
512 else 509 else
513 pinfo->rx_fifosize = RX_BUF_SIZE; 510 pinfo->rx_fifosize = RX_BUF_SIZE;
514 511
515 /* MAXIDL is the timeout after which a receive buffer is closed
516 * when not full if no more characters are received.
517 * We calculate it from the baudrate so that the duration is
518 * always the same at standard rates: about 4ms.
519 */
520 maxidl = baud / 2400;
521 if (maxidl < 1)
522 maxidl = 1;
523 if (maxidl > 0x10)
524 maxidl = 0x10;
525
526 /* Character length programmed into the mode register is the 512 /* Character length programmed into the mode register is the
527 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit, 513 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
528 * 1 or 2 stop bits, minus 1. 514 * 1 or 2 stop bits, minus 1.
@@ -623,7 +609,6 @@ static void cpm_uart_set_termios(struct uart_port *port,
623 * SMC/SCC receiver is disabled. 609 * SMC/SCC receiver is disabled.
624 */ 610 */
625 out_be16(&pinfo->smcup->smc_mrblr, pinfo->rx_fifosize); 611 out_be16(&pinfo->smcup->smc_mrblr, pinfo->rx_fifosize);
626 out_be16(&pinfo->smcup->smc_maxidl, maxidl);
627 612
628 /* Set the mode register. We want to keep a copy of the 613 /* Set the mode register. We want to keep a copy of the
629 * enables, because we want to put them back if they were 614 * enables, because we want to put them back if they were
@@ -636,7 +621,6 @@ static void cpm_uart_set_termios(struct uart_port *port,
636 SMCMR_SM_UART | prev_mode); 621 SMCMR_SM_UART | prev_mode);
637 } else { 622 } else {
638 out_be16(&pinfo->sccup->scc_genscc.scc_mrblr, pinfo->rx_fifosize); 623 out_be16(&pinfo->sccup->scc_genscc.scc_mrblr, pinfo->rx_fifosize);
639 out_be16(&pinfo->sccup->scc_maxidl, maxidl);
640 out_be16(&sccp->scc_psmr, (sbits << 12) | scval); 624 out_be16(&sccp->scc_psmr, (sbits << 12) | scval);
641 } 625 }
642 626
@@ -813,7 +797,7 @@ static void cpm_uart_init_scc(struct uart_cpm_port *pinfo)
813 cpm_set_scc_fcr(sup); 797 cpm_set_scc_fcr(sup);
814 798
815 out_be16(&sup->scc_genscc.scc_mrblr, pinfo->rx_fifosize); 799 out_be16(&sup->scc_genscc.scc_mrblr, pinfo->rx_fifosize);
816 out_be16(&sup->scc_maxidl, 0x10); 800 out_be16(&sup->scc_maxidl, pinfo->rx_fifosize);
817 out_be16(&sup->scc_brkcr, 1); 801 out_be16(&sup->scc_brkcr, 1);
818 out_be16(&sup->scc_parec, 0); 802 out_be16(&sup->scc_parec, 0);
819 out_be16(&sup->scc_frmec, 0); 803 out_be16(&sup->scc_frmec, 0);
@@ -887,7 +871,7 @@ static void cpm_uart_init_smc(struct uart_cpm_port *pinfo)
887 871
888 /* Using idle character time requires some additional tuning. */ 872 /* Using idle character time requires some additional tuning. */
889 out_be16(&up->smc_mrblr, pinfo->rx_fifosize); 873 out_be16(&up->smc_mrblr, pinfo->rx_fifosize);
890 out_be16(&up->smc_maxidl, 0x10); 874 out_be16(&up->smc_maxidl, pinfo->rx_fifosize);
891 out_be16(&up->smc_brklen, 0); 875 out_be16(&up->smc_brklen, 0);
892 out_be16(&up->smc_brkec, 0); 876 out_be16(&up->smc_brkec, 0);
893 out_be16(&up->smc_brkcr, 1); 877 out_be16(&up->smc_brkcr, 1);
@@ -1373,7 +1357,7 @@ static struct uart_driver cpm_reg = {
1373 1357
1374static int probe_index; 1358static int probe_index;
1375 1359
1376static int cpm_uart_probe(struct platform_device *ofdev) 1360static int __devinit cpm_uart_probe(struct platform_device *ofdev)
1377{ 1361{
1378 int index = probe_index++; 1362 int index = probe_index++;
1379 struct uart_cpm_port *pinfo = &cpm_uart_ports[index]; 1363 struct uart_cpm_port *pinfo = &cpm_uart_ports[index];
@@ -1396,7 +1380,7 @@ static int cpm_uart_probe(struct platform_device *ofdev)
1396 return uart_add_one_port(&cpm_reg, &pinfo->port); 1380 return uart_add_one_port(&cpm_reg, &pinfo->port);
1397} 1381}
1398 1382
1399static int cpm_uart_remove(struct platform_device *ofdev) 1383static int __devexit cpm_uart_remove(struct platform_device *ofdev)
1400{ 1384{
1401 struct uart_cpm_port *pinfo = dev_get_drvdata(&ofdev->dev); 1385 struct uart_cpm_port *pinfo = dev_get_drvdata(&ofdev->dev);
1402 return uart_remove_one_port(&cpm_reg, &pinfo->port); 1386 return uart_remove_one_port(&cpm_reg, &pinfo->port);
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index 35ee6a2c687..58be715913c 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -34,9 +34,9 @@ static char *serial_version = "$Revision: 1.25 $";
34 34
35#include <asm/irq.h> 35#include <asm/irq.h>
36#include <asm/dma.h> 36#include <asm/dma.h>
37#include <asm/system.h>
37 38
38#include <arch/svinto.h> 39#include <arch/svinto.h>
39#include <arch/system.h>
40 40
41/* non-arch dependent serial structures are in linux/serial.h */ 41/* non-arch dependent serial structures are in linux/serial.h */
42#include <linux/serial.h> 42#include <linux/serial.h>
@@ -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 = 0, 261 .dma_out_irq_flags = IRQF_DISABLED,
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 = 0, 274 .dma_in_irq_flags = IRQF_DISABLED,
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 = 0, 316 .dma_out_irq_flags = IRQF_DISABLED,
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 = 0, 329 .dma_in_irq_flags = IRQF_DISABLED,
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 = 0, 372 .dma_out_irq_flags = IRQF_DISABLED,
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 = 0, 385 .dma_in_irq_flags = IRQF_DISABLED,
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 = 0, 426 .dma_out_irq_flags = IRQF_DISABLED,
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 = 0, 439 .dma_in_irq_flags = IRQF_DISABLED,
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,
@@ -952,10 +952,23 @@ static const struct control_pins e100_modem_pins[NR_PORTS] =
952/* Input */ 952/* Input */
953#define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask) 953#define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask)
954 954
955
956/*
957 * tmp_buf is used as a temporary buffer by serial_write. We need to
958 * lock it in case the memcpy_fromfs blocks while swapping in a page,
959 * and some other program tries to do a serial write at the same time.
960 * Since the lock will only come under contention when the system is
961 * swapping and available memory is low, it makes sense to share one
962 * buffer across all the serial ports, since it significantly saves
963 * memory if large numbers of serial ports are open.
964 */
965static unsigned char *tmp_buf;
966static DEFINE_MUTEX(tmp_buf_mutex);
967
955/* Calculate the chartime depending on baudrate, numbor of bits etc. */ 968/* Calculate the chartime depending on baudrate, numbor of bits etc. */
956static void update_char_time(struct e100_serial * info) 969static void update_char_time(struct e100_serial * info)
957{ 970{
958 tcflag_t cflags = info->port.tty->termios.c_cflag; 971 tcflag_t cflags = info->port.tty->termios->c_cflag;
959 int bits; 972 int bits;
960 973
961 /* calc. number of bits / data byte */ 974 /* calc. number of bits / data byte */
@@ -1473,7 +1486,7 @@ rs_stop(struct tty_struct *tty)
1473 xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, 1486 xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char,
1474 STOP_CHAR(info->port.tty)); 1487 STOP_CHAR(info->port.tty));
1475 xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, stop); 1488 xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, stop);
1476 if (tty->termios.c_iflag & IXON ) { 1489 if (tty->termios->c_iflag & IXON ) {
1477 xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable); 1490 xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable);
1478 } 1491 }
1479 1492
@@ -1496,7 +1509,7 @@ rs_start(struct tty_struct *tty)
1496 info->xmit.tail,SERIAL_XMIT_SIZE))); 1509 info->xmit.tail,SERIAL_XMIT_SIZE)));
1497 xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(tty)); 1510 xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(tty));
1498 xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, enable); 1511 xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, enable);
1499 if (tty->termios.c_iflag & IXON ) { 1512 if (tty->termios->c_iflag & IXON ) {
1500 xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable); 1513 xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable);
1501 } 1514 }
1502 1515
@@ -1775,7 +1788,7 @@ static unsigned int handle_descr_data(struct e100_serial *info,
1775 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;
1776 1789
1777 if (info->recv_cnt + recvl > 65536) { 1790 if (info->recv_cnt + recvl > 65536) {
1778 printk(KERN_WARNING 1791 printk(KERN_CRIT
1779 "%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);
1780 return 0; 1793 return 0;
1781 } 1794 }
@@ -2929,7 +2942,7 @@ shutdown(struct e100_serial * info)
2929 descr[i].buf = 0; 2942 descr[i].buf = 0;
2930 } 2943 }
2931 2944
2932 if (!info->port.tty || (info->port.tty->termios.c_cflag & HUPCL)) { 2945 if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) {
2933 /* hang up DTR and RTS if HUPCL is enabled */ 2946 /* hang up DTR and RTS if HUPCL is enabled */
2934 e100_dtr(info, 0); 2947 e100_dtr(info, 0);
2935 e100_rts(info, 0); /* could check CRTSCTS before doing this */ 2948 e100_rts(info, 0); /* could check CRTSCTS before doing this */
@@ -2953,12 +2966,12 @@ change_speed(struct e100_serial *info)
2953 unsigned long flags; 2966 unsigned long flags;
2954 /* first some safety checks */ 2967 /* first some safety checks */
2955 2968
2956 if (!info->port.tty) 2969 if (!info->port.tty || !info->port.tty->termios)
2957 return; 2970 return;
2958 if (!info->ioport) 2971 if (!info->ioport)
2959 return; 2972 return;
2960 2973
2961 cflag = info->port.tty->termios.c_cflag; 2974 cflag = info->port.tty->termios->c_cflag;
2962 2975
2963 /* possibly, the tx/rx should be disabled first to do this safely */ 2976 /* possibly, the tx/rx should be disabled first to do this safely */
2964 2977
@@ -3088,7 +3101,7 @@ change_speed(struct e100_serial *info)
3088 info->ioport[REG_REC_CTRL] = info->rx_ctrl; 3101 info->ioport[REG_REC_CTRL] = info->rx_ctrl;
3089 xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(info->port.tty)); 3102 xoff = IO_FIELD(R_SERIAL0_XOFF, xoff_char, STOP_CHAR(info->port.tty));
3090 xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, enable); 3103 xoff |= IO_STATE(R_SERIAL0_XOFF, tx_stop, enable);
3091 if (info->port.tty->termios.c_iflag & IXON ) { 3104 if (info->port.tty->termios->c_iflag & IXON ) {
3092 DFLOW(DEBUG_LOG(info->line, "FLOW XOFF enabled 0x%02X\n", 3105 DFLOW(DEBUG_LOG(info->line, "FLOW XOFF enabled 0x%02X\n",
3093 STOP_CHAR(info->port.tty))); 3106 STOP_CHAR(info->port.tty)));
3094 xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable); 3107 xoff |= IO_STATE(R_SERIAL0_XOFF, auto_xoff, enable);
@@ -3137,7 +3150,7 @@ static int rs_raw_write(struct tty_struct *tty,
3137 3150
3138 /* first some sanity checks */ 3151 /* first some sanity checks */
3139 3152
3140 if (!tty || !info->xmit.buf) 3153 if (!tty || !info->xmit.buf || !tmp_buf)
3141 return 0; 3154 return 0;
3142 3155
3143#ifdef SERIAL_DEBUG_DATA 3156#ifdef SERIAL_DEBUG_DATA
@@ -3221,8 +3234,9 @@ rs_write(struct tty_struct *tty,
3221 e100_disable_rx(info); 3234 e100_disable_rx(info);
3222 e100_enable_rx_irq(info); 3235 e100_enable_rx_irq(info);
3223#endif 3236#endif
3224 if (info->rs485.delay_rts_before_send > 0) 3237 if ((info->rs485.flags & SER_RS485_RTS_BEFORE_SEND) &&
3225 msleep(info->rs485.delay_rts_before_send); 3238 (info->rs485.delay_rts_before_send > 0))
3239 msleep(info->rs485.delay_rts_before_send);
3226 } 3240 }
3227#endif /* CONFIG_ETRAX_RS485 */ 3241#endif /* CONFIG_ETRAX_RS485 */
3228 3242
@@ -3355,7 +3369,7 @@ rs_throttle(struct tty_struct * tty)
3355 DFLOW(DEBUG_LOG(info->line,"rs_throttle %lu\n", tty->ldisc.chars_in_buffer(tty))); 3369 DFLOW(DEBUG_LOG(info->line,"rs_throttle %lu\n", tty->ldisc.chars_in_buffer(tty)));
3356 3370
3357 /* Do RTS before XOFF since XOFF might take some time */ 3371 /* Do RTS before XOFF since XOFF might take some time */
3358 if (tty->termios.c_cflag & CRTSCTS) { 3372 if (tty->termios->c_cflag & CRTSCTS) {
3359 /* Turn off RTS line */ 3373 /* Turn off RTS line */
3360 e100_rts(info, 0); 3374 e100_rts(info, 0);
3361 } 3375 }
@@ -3377,7 +3391,7 @@ rs_unthrottle(struct tty_struct * tty)
3377 DFLOW(DEBUG_LOG(info->line,"rs_unthrottle ldisc %d\n", tty->ldisc.chars_in_buffer(tty))); 3391 DFLOW(DEBUG_LOG(info->line,"rs_unthrottle ldisc %d\n", tty->ldisc.chars_in_buffer(tty)));
3378 DFLOW(DEBUG_LOG(info->line,"rs_unthrottle flip.count: %i\n", tty->flip.count)); 3392 DFLOW(DEBUG_LOG(info->line,"rs_unthrottle flip.count: %i\n", tty->flip.count));
3379 /* Do RTS before XOFF since XOFF might take some time */ 3393 /* Do RTS before XOFF since XOFF might take some time */
3380 if (tty->termios.c_cflag & CRTSCTS) { 3394 if (tty->termios->c_cflag & CRTSCTS) {
3381 /* Assert RTS line */ 3395 /* Assert RTS line */
3382 e100_rts(info, 1); 3396 e100_rts(info, 1);
3383 } 3397 }
@@ -3679,6 +3693,10 @@ rs_ioctl(struct tty_struct *tty,
3679 3693
3680 rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send; 3694 rs485data.delay_rts_before_send = rs485ctrl.delay_rts_before_send;
3681 rs485data.flags = 0; 3695 rs485data.flags = 0;
3696 if (rs485data.delay_rts_before_send != 0)
3697 rs485data.flags |= SER_RS485_RTS_BEFORE_SEND;
3698 else
3699 rs485data.flags &= ~(SER_RS485_RTS_BEFORE_SEND);
3682 3700
3683 if (rs485ctrl.enabled) 3701 if (rs485ctrl.enabled)
3684 rs485data.flags |= SER_RS485_ENABLED; 3702 rs485data.flags |= SER_RS485_ENABLED;
@@ -3748,7 +3766,7 @@ rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3748 3766
3749 /* Handle turning off CRTSCTS */ 3767 /* Handle turning off CRTSCTS */
3750 if ((old_termios->c_cflag & CRTSCTS) && 3768 if ((old_termios->c_cflag & CRTSCTS) &&
3751 !(tty->termios.c_cflag & CRTSCTS)) { 3769 !(tty->termios->c_cflag & CRTSCTS)) {
3752 tty->hw_stopped = 0; 3770 tty->hw_stopped = 0;
3753 rs_start(tty); 3771 rs_start(tty);
3754 } 3772 }
@@ -3795,13 +3813,13 @@ rs_close(struct tty_struct *tty, struct file * filp)
3795 * one, we've got real problems, since it means the 3813 * one, we've got real problems, since it means the
3796 * serial port won't be shutdown. 3814 * serial port won't be shutdown.
3797 */ 3815 */
3798 printk(KERN_ERR 3816 printk(KERN_CRIT
3799 "rs_close: bad serial port count; tty->count is 1, " 3817 "rs_close: bad serial port count; tty->count is 1, "
3800 "info->count is %d\n", info->count); 3818 "info->count is %d\n", info->count);
3801 info->count = 1; 3819 info->count = 1;
3802 } 3820 }
3803 if (--info->count < 0) { 3821 if (--info->count < 0) {
3804 printk(KERN_ERR "rs_close: bad serial port count for ttyS%d: %d\n", 3822 printk(KERN_CRIT "rs_close: bad serial port count for ttyS%d: %d\n",
3805 info->line, info->count); 3823 info->line, info->count);
3806 info->count = 0; 3824 info->count = 0;
3807 } 3825 }
@@ -3815,7 +3833,7 @@ rs_close(struct tty_struct *tty, struct file * filp)
3815 * separate termios for callout and dialin. 3833 * separate termios for callout and dialin.
3816 */ 3834 */
3817 if (info->flags & ASYNC_NORMAL_ACTIVE) 3835 if (info->flags & ASYNC_NORMAL_ACTIVE)
3818 info->normal_termios = tty->termios; 3836 info->normal_termios = *tty->termios;
3819 /* 3837 /*
3820 * Now we wait for the transmit buffer to clear; and we notify 3838 * Now we wait for the transmit buffer to clear; and we notify
3821 * the line discipline to only process XON/XOFF characters. 3839 * the line discipline to only process XON/XOFF characters.
@@ -3976,7 +3994,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
3976 */ 3994 */
3977 if (tty_hung_up_p(filp) || 3995 if (tty_hung_up_p(filp) ||
3978 (info->flags & ASYNC_CLOSING)) { 3996 (info->flags & ASYNC_CLOSING)) {
3979 wait_event_interruptible_tty(tty, info->close_wait, 3997 wait_event_interruptible_tty(info->close_wait,
3980 !(info->flags & ASYNC_CLOSING)); 3998 !(info->flags & ASYNC_CLOSING));
3981#ifdef SERIAL_DO_RESTART 3999#ifdef SERIAL_DO_RESTART
3982 if (info->flags & ASYNC_HUP_NOTIFY) 4000 if (info->flags & ASYNC_HUP_NOTIFY)
@@ -3998,7 +4016,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
3998 return 0; 4016 return 0;
3999 } 4017 }
4000 4018
4001 if (tty->termios.c_cflag & CLOCAL) { 4019 if (tty->termios->c_cflag & CLOCAL) {
4002 do_clocal = 1; 4020 do_clocal = 1;
4003 } 4021 }
4004 4022
@@ -4052,9 +4070,9 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
4052 printk("block_til_ready blocking: ttyS%d, count = %d\n", 4070 printk("block_til_ready blocking: ttyS%d, count = %d\n",
4053 info->line, info->count); 4071 info->line, info->count);
4054#endif 4072#endif
4055 tty_unlock(tty); 4073 tty_unlock();
4056 schedule(); 4074 schedule();
4057 tty_lock(tty); 4075 tty_lock();
4058 } 4076 }
4059 set_current_state(TASK_RUNNING); 4077 set_current_state(TASK_RUNNING);
4060 remove_wait_queue(&info->open_wait, &wait); 4078 remove_wait_queue(&info->open_wait, &wait);
@@ -4092,10 +4110,20 @@ static int
4092rs_open(struct tty_struct *tty, struct file * filp) 4110rs_open(struct tty_struct *tty, struct file * filp)
4093{ 4111{
4094 struct e100_serial *info; 4112 struct e100_serial *info;
4095 int retval; 4113 int retval, line;
4114 unsigned long page;
4096 int allocated_resources = 0; 4115 int allocated_resources = 0;
4097 4116
4098 info = rs_table + tty->index; 4117 /* find which port we want to open */
4118 line = tty->index;
4119
4120 if (line < 0 || line >= NR_PORTS)
4121 return -ENODEV;
4122
4123 /* find the corresponding e100_serial struct in the table */
4124 info = rs_table + line;
4125
4126 /* don't allow the opening of ports that are not enabled in the HW config */
4099 if (!info->enabled) 4127 if (!info->enabled)
4100 return -ENODEV; 4128 return -ENODEV;
4101 4129
@@ -4108,14 +4136,25 @@ rs_open(struct tty_struct *tty, struct file * filp)
4108 tty->driver_data = info; 4136 tty->driver_data = info;
4109 info->port.tty = tty; 4137 info->port.tty = tty;
4110 4138
4111 tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY); 4139 info->port.tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
4140
4141 if (!tmp_buf) {
4142 page = get_zeroed_page(GFP_KERNEL);
4143 if (!page) {
4144 return -ENOMEM;
4145 }
4146 if (tmp_buf)
4147 free_page(page);
4148 else
4149 tmp_buf = (unsigned char *) page;
4150 }
4112 4151
4113 /* 4152 /*
4114 * If the port is in the middle of closing, bail out now 4153 * If the port is in the middle of closing, bail out now
4115 */ 4154 */
4116 if (tty_hung_up_p(filp) || 4155 if (tty_hung_up_p(filp) ||
4117 (info->flags & ASYNC_CLOSING)) { 4156 (info->flags & ASYNC_CLOSING)) {
4118 wait_event_interruptible_tty(tty, info->close_wait, 4157 wait_event_interruptible_tty(info->close_wait,
4119 !(info->flags & ASYNC_CLOSING)); 4158 !(info->flags & ASYNC_CLOSING));
4120#ifdef SERIAL_DO_RESTART 4159#ifdef SERIAL_DO_RESTART
4121 return ((info->flags & ASYNC_HUP_NOTIFY) ? 4160 return ((info->flags & ASYNC_HUP_NOTIFY) ?
@@ -4219,7 +4258,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4219 } 4258 }
4220 4259
4221 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) { 4260 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
4222 tty->termios = info->normal_termios; 4261 *tty->termios = info->normal_termios;
4223 change_speed(info); 4262 change_speed(info);
4224 } 4263 }
4225 4264
@@ -4413,7 +4452,7 @@ static int __init rs_init(void)
4413#if defined(CONFIG_ETRAX_RS485_ON_PA) 4452#if defined(CONFIG_ETRAX_RS485_ON_PA)
4414 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,
4415 rs485_pa_bit)) { 4454 rs485_pa_bit)) {
4416 printk(KERN_ERR "ETRAX100LX serial: Could not allocate " 4455 printk(KERN_CRIT "ETRAX100LX serial: Could not allocate "
4417 "RS485 pin\n"); 4456 "RS485 pin\n");
4418 put_tty_driver(driver); 4457 put_tty_driver(driver);
4419 return -EBUSY; 4458 return -EBUSY;
@@ -4422,7 +4461,7 @@ static int __init rs_init(void)
4422#if defined(CONFIG_ETRAX_RS485_ON_PORT_G) 4461#if defined(CONFIG_ETRAX_RS485_ON_PORT_G)
4423 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,
4424 rs485_port_g_bit)) { 4463 rs485_port_g_bit)) {
4425 printk(KERN_ERR "ETRAX100LX serial: Could not allocate " 4464 printk(KERN_CRIT "ETRAX100LX serial: Could not allocate "
4426 "RS485 pin\n"); 4465 "RS485 pin\n");
4427 put_tty_driver(driver); 4466 put_tty_driver(driver);
4428 return -EBUSY; 4467 return -EBUSY;
@@ -4443,24 +4482,25 @@ static int __init rs_init(void)
4443 B115200 | CS8 | CREAD | HUPCL | CLOCAL; /* is normally B9600 default... */ 4482 B115200 | CS8 | CREAD | HUPCL | CLOCAL; /* is normally B9600 default... */
4444 driver->init_termios.c_ispeed = 115200; 4483 driver->init_termios.c_ispeed = 115200;
4445 driver->init_termios.c_ospeed = 115200; 4484 driver->init_termios.c_ospeed = 115200;
4446 driver->flags = TTY_DRIVER_REAL_RAW; 4485 driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4447 4486
4448 tty_set_operations(driver, &rs_ops); 4487 tty_set_operations(driver, &rs_ops);
4449 serial_driver = driver; 4488 serial_driver = driver;
4450 4489 if (tty_register_driver(driver))
4490 panic("Couldn't register serial driver\n");
4451 /* do some initializing for the separate ports */ 4491 /* do some initializing for the separate ports */
4492
4452 for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) { 4493 for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) {
4453 if (info->enabled) { 4494 if (info->enabled) {
4454 if (cris_request_io_interface(info->io_if, 4495 if (cris_request_io_interface(info->io_if,
4455 info->io_if_description)) { 4496 info->io_if_description)) {
4456 printk(KERN_ERR "ETRAX100LX async serial: " 4497 printk(KERN_CRIT "ETRAX100LX async serial: "
4457 "Could not allocate IO pins for " 4498 "Could not allocate IO pins for "
4458 "%s, port %d\n", 4499 "%s, port %d\n",
4459 info->io_if_description, i); 4500 info->io_if_description, i);
4460 info->enabled = 0; 4501 info->enabled = 0;
4461 } 4502 }
4462 } 4503 }
4463 tty_port_init(&info->port);
4464 info->uses_dma_in = 0; 4504 info->uses_dma_in = 0;
4465 info->uses_dma_out = 0; 4505 info->uses_dma_out = 0;
4466 info->line = i; 4506 info->line = i;
@@ -4491,6 +4531,7 @@ static int __init rs_init(void)
4491 /* Set sane defaults */ 4531 /* Set sane defaults */
4492 info->rs485.flags &= ~(SER_RS485_RTS_ON_SEND); 4532 info->rs485.flags &= ~(SER_RS485_RTS_ON_SEND);
4493 info->rs485.flags |= SER_RS485_RTS_AFTER_SEND; 4533 info->rs485.flags |= SER_RS485_RTS_AFTER_SEND;
4534 info->rs485.flags &= ~(SER_RS485_RTS_BEFORE_SEND);
4494 info->rs485.delay_rts_before_send = 0; 4535 info->rs485.delay_rts_before_send = 0;
4495 info->rs485.flags &= ~(SER_RS485_ENABLED); 4536 info->rs485.flags &= ~(SER_RS485_ENABLED);
4496#endif 4537#endif
@@ -4500,12 +4541,7 @@ static int __init rs_init(void)
4500 printk(KERN_INFO "%s%d at %p is a builtin UART with DMA\n", 4541 printk(KERN_INFO "%s%d at %p is a builtin UART with DMA\n",
4501 serial_driver->name, info->line, info->ioport); 4542 serial_driver->name, info->line, info->ioport);
4502 } 4543 }
4503 tty_port_link_device(&info->port, driver, i);
4504 } 4544 }
4505
4506 if (tty_register_driver(driver))
4507 panic("Couldn't register serial driver\n");
4508
4509#ifdef CONFIG_ETRAX_FAST_TIMER 4545#ifdef CONFIG_ETRAX_FAST_TIMER
4510#ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER 4546#ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
4511 memset(fast_timers, 0, sizeof(fast_timers)); 4547 memset(fast_timers, 0, sizeof(fast_timers));
@@ -4522,7 +4558,7 @@ static int __init rs_init(void)
4522 /* 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... */
4523 4559
4524 if (request_irq(SERIAL_IRQ_NBR, ser_interrupt, 4560 if (request_irq(SERIAL_IRQ_NBR, ser_interrupt,
4525 IRQF_SHARED, "serial ", driver)) 4561 IRQF_SHARED | IRQF_DISABLED, "serial ", driver))
4526 panic("%s: Failed to request irq8", __func__); 4562 panic("%s: Failed to request irq8", __func__);
4527 4563
4528#endif 4564#endif
diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c
index 6491b8644a7..ddc487a2d42 100644
--- a/drivers/tty/serial/dz.c
+++ b/drivers/tty/serial/dz.c
@@ -47,11 +47,11 @@
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>
51 50
52#include <linux/atomic.h> 51#include <linux/atomic.h>
53#include <asm/bootinfo.h> 52#include <asm/bootinfo.h>
54#include <asm/io.h> 53#include <asm/io.h>
54#include <asm/system.h>
55 55
56#include <asm/dec/interrupts.h> 56#include <asm/dec/interrupts.h>
57#include <asm/dec/kn01.h> 57#include <asm/dec/kn01.h>
diff --git a/drivers/tty/serial/efm32-uart.c b/drivers/tty/serial/efm32-uart.c
deleted file mode 100644
index a8cbb267052..00000000000
--- a/drivers/tty/serial/efm32-uart.c
+++ /dev/null
@@ -1,830 +0,0 @@
1#if defined(CONFIG_SERIAL_EFM32_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
2#define SUPPORT_SYSRQ
3#endif
4
5#include <linux/kernel.h>
6#include <linux/module.h>
7#include <linux/io.h>
8#include <linux/platform_device.h>
9#include <linux/console.h>
10#include <linux/sysrq.h>
11#include <linux/serial_core.h>
12#include <linux/tty_flip.h>
13#include <linux/slab.h>
14#include <linux/clk.h>
15#include <linux/of.h>
16#include <linux/of_device.h>
17
18#include <linux/platform_data/efm32-uart.h>
19
20#define DRIVER_NAME "efm32-uart"
21#define DEV_NAME "ttyefm"
22
23#define UARTn_CTRL 0x00
24#define UARTn_CTRL_SYNC 0x0001
25#define UARTn_CTRL_TXBIL 0x1000
26
27#define UARTn_FRAME 0x04
28#define UARTn_FRAME_DATABITS__MASK 0x000f
29#define UARTn_FRAME_DATABITS(n) ((n) - 3)
30#define UARTn_FRAME_PARITY_NONE 0x0000
31#define UARTn_FRAME_PARITY_EVEN 0x0200
32#define UARTn_FRAME_PARITY_ODD 0x0300
33#define UARTn_FRAME_STOPBITS_HALF 0x0000
34#define UARTn_FRAME_STOPBITS_ONE 0x1000
35#define UARTn_FRAME_STOPBITS_TWO 0x3000
36
37#define UARTn_CMD 0x0c
38#define UARTn_CMD_RXEN 0x0001
39#define UARTn_CMD_RXDIS 0x0002
40#define UARTn_CMD_TXEN 0x0004
41#define UARTn_CMD_TXDIS 0x0008
42
43#define UARTn_STATUS 0x10
44#define UARTn_STATUS_TXENS 0x0002
45#define UARTn_STATUS_TXC 0x0020
46#define UARTn_STATUS_TXBL 0x0040
47#define UARTn_STATUS_RXDATAV 0x0080
48
49#define UARTn_CLKDIV 0x14
50
51#define UARTn_RXDATAX 0x18
52#define UARTn_RXDATAX_RXDATA__MASK 0x01ff
53#define UARTn_RXDATAX_PERR 0x4000
54#define UARTn_RXDATAX_FERR 0x8000
55/*
56 * This is a software only flag used for ignore_status_mask and
57 * read_status_mask! It's used for breaks that the hardware doesn't report
58 * explicitly.
59 */
60#define SW_UARTn_RXDATAX_BERR 0x2000
61
62#define UARTn_TXDATA 0x34
63
64#define UARTn_IF 0x40
65#define UARTn_IF_TXC 0x0001
66#define UARTn_IF_TXBL 0x0002
67#define UARTn_IF_RXDATAV 0x0004
68#define UARTn_IF_RXOF 0x0010
69
70#define UARTn_IFS 0x44
71#define UARTn_IFC 0x48
72#define UARTn_IEN 0x4c
73
74#define UARTn_ROUTE 0x54
75#define UARTn_ROUTE_LOCATION__MASK 0x0700
76#define UARTn_ROUTE_LOCATION(n) (((n) << 8) & UARTn_ROUTE_LOCATION__MASK)
77#define UARTn_ROUTE_RXPEN 0x0001
78#define UARTn_ROUTE_TXPEN 0x0002
79
80struct efm32_uart_port {
81 struct uart_port port;
82 unsigned int txirq;
83 struct clk *clk;
84};
85#define to_efm_port(_port) container_of(_port, struct efm32_uart_port, port)
86#define efm_debug(efm_port, format, arg...) \
87 dev_dbg(efm_port->port.dev, format, ##arg)
88
89static void efm32_uart_write32(struct efm32_uart_port *efm_port,
90 u32 value, unsigned offset)
91{
92 writel_relaxed(value, efm_port->port.membase + offset);
93}
94
95static u32 efm32_uart_read32(struct efm32_uart_port *efm_port,
96 unsigned offset)
97{
98 return readl_relaxed(efm_port->port.membase + offset);
99}
100
101static unsigned int efm32_uart_tx_empty(struct uart_port *port)
102{
103 struct efm32_uart_port *efm_port = to_efm_port(port);
104 u32 status = efm32_uart_read32(efm_port, UARTn_STATUS);
105
106 if (status & UARTn_STATUS_TXC)
107 return TIOCSER_TEMT;
108 else
109 return 0;
110}
111
112static void efm32_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
113{
114 /* sorry, neither handshaking lines nor loop functionallity */
115}
116
117static unsigned int efm32_uart_get_mctrl(struct uart_port *port)
118{
119 /* sorry, no handshaking lines available */
120 return TIOCM_CAR | TIOCM_CTS | TIOCM_DSR;
121}
122
123static void efm32_uart_stop_tx(struct uart_port *port)
124{
125 struct efm32_uart_port *efm_port = to_efm_port(port);
126 u32 ien = efm32_uart_read32(efm_port, UARTn_IEN);
127
128 efm32_uart_write32(efm_port, UARTn_CMD_TXDIS, UARTn_CMD);
129 ien &= ~(UARTn_IF_TXC | UARTn_IF_TXBL);
130 efm32_uart_write32(efm_port, ien, UARTn_IEN);
131}
132
133static void efm32_uart_tx_chars(struct efm32_uart_port *efm_port)
134{
135 struct uart_port *port = &efm_port->port;
136 struct circ_buf *xmit = &port->state->xmit;
137
138 while (efm32_uart_read32(efm_port, UARTn_STATUS) &
139 UARTn_STATUS_TXBL) {
140 if (port->x_char) {
141 port->icount.tx++;
142 efm32_uart_write32(efm_port, port->x_char,
143 UARTn_TXDATA);
144 port->x_char = 0;
145 continue;
146 }
147 if (!uart_circ_empty(xmit) && !uart_tx_stopped(port)) {
148 port->icount.tx++;
149 efm32_uart_write32(efm_port, xmit->buf[xmit->tail],
150 UARTn_TXDATA);
151 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
152 } else
153 break;
154 }
155
156 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
157 uart_write_wakeup(port);
158
159 if (!port->x_char && uart_circ_empty(xmit) &&
160 efm32_uart_read32(efm_port, UARTn_STATUS) &
161 UARTn_STATUS_TXC)
162 efm32_uart_stop_tx(port);
163}
164
165static void efm32_uart_start_tx(struct uart_port *port)
166{
167 struct efm32_uart_port *efm_port = to_efm_port(port);
168 u32 ien;
169
170 efm32_uart_write32(efm_port,
171 UARTn_IF_TXBL | UARTn_IF_TXC, UARTn_IFC);
172 ien = efm32_uart_read32(efm_port, UARTn_IEN);
173 efm32_uart_write32(efm_port,
174 ien | UARTn_IF_TXBL | UARTn_IF_TXC, UARTn_IEN);
175 efm32_uart_write32(efm_port, UARTn_CMD_TXEN, UARTn_CMD);
176
177 efm32_uart_tx_chars(efm_port);
178}
179
180static void efm32_uart_stop_rx(struct uart_port *port)
181{
182 struct efm32_uart_port *efm_port = to_efm_port(port);
183
184 efm32_uart_write32(efm_port, UARTn_CMD_RXDIS, UARTn_CMD);
185}
186
187static void efm32_uart_enable_ms(struct uart_port *port)
188{
189 /* no handshake lines, no modem status interrupts */
190}
191
192static void efm32_uart_break_ctl(struct uart_port *port, int ctl)
193{
194 /* not possible without fiddling with gpios */
195}
196
197static void efm32_uart_rx_chars(struct efm32_uart_port *efm_port,
198 struct tty_struct *tty)
199{
200 struct uart_port *port = &efm_port->port;
201
202 while (efm32_uart_read32(efm_port, UARTn_STATUS) &
203 UARTn_STATUS_RXDATAV) {
204 u32 rxdata = efm32_uart_read32(efm_port, UARTn_RXDATAX);
205 int flag = 0;
206
207 /*
208 * This is a reserved bit and I only saw it read as 0. But to be
209 * sure not to be confused too much by new devices adhere to the
210 * warning in the reference manual that reserverd bits might
211 * read as 1 in the future.
212 */
213 rxdata &= ~SW_UARTn_RXDATAX_BERR;
214
215 port->icount.rx++;
216
217 if ((rxdata & UARTn_RXDATAX_FERR) &&
218 !(rxdata & UARTn_RXDATAX_RXDATA__MASK)) {
219 rxdata |= SW_UARTn_RXDATAX_BERR;
220 port->icount.brk++;
221 if (uart_handle_break(port))
222 continue;
223 } else if (rxdata & UARTn_RXDATAX_PERR)
224 port->icount.parity++;
225 else if (rxdata & UARTn_RXDATAX_FERR)
226 port->icount.frame++;
227
228 rxdata &= port->read_status_mask;
229
230 if (rxdata & SW_UARTn_RXDATAX_BERR)
231 flag = TTY_BREAK;
232 else if (rxdata & UARTn_RXDATAX_PERR)
233 flag = TTY_PARITY;
234 else if (rxdata & UARTn_RXDATAX_FERR)
235 flag = TTY_FRAME;
236 else if (uart_handle_sysrq_char(port,
237 rxdata & UARTn_RXDATAX_RXDATA__MASK))
238 continue;
239
240 if (tty && (rxdata & port->ignore_status_mask) == 0)
241 tty_insert_flip_char(tty,
242 rxdata & UARTn_RXDATAX_RXDATA__MASK, flag);
243 }
244}
245
246static irqreturn_t efm32_uart_rxirq(int irq, void *data)
247{
248 struct efm32_uart_port *efm_port = data;
249 u32 irqflag = efm32_uart_read32(efm_port, UARTn_IF);
250 int handled = IRQ_NONE;
251 struct uart_port *port = &efm_port->port;
252 struct tty_struct *tty;
253
254 spin_lock(&port->lock);
255
256 tty = tty_kref_get(port->state->port.tty);
257
258 if (irqflag & UARTn_IF_RXDATAV) {
259 efm32_uart_write32(efm_port, UARTn_IF_RXDATAV, UARTn_IFC);
260 efm32_uart_rx_chars(efm_port, tty);
261
262 handled = IRQ_HANDLED;
263 }
264
265 if (irqflag & UARTn_IF_RXOF) {
266 efm32_uart_write32(efm_port, UARTn_IF_RXOF, UARTn_IFC);
267 port->icount.overrun++;
268 if (tty)
269 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
270
271 handled = IRQ_HANDLED;
272 }
273
274 if (tty) {
275 tty_flip_buffer_push(tty);
276 tty_kref_put(tty);
277 }
278
279 spin_unlock(&port->lock);
280
281 return handled;
282}
283
284static irqreturn_t efm32_uart_txirq(int irq, void *data)
285{
286 struct efm32_uart_port *efm_port = data;
287 u32 irqflag = efm32_uart_read32(efm_port, UARTn_IF);
288
289 /* TXBL doesn't need to be cleared */
290 if (irqflag & UARTn_IF_TXC)
291 efm32_uart_write32(efm_port, UARTn_IF_TXC, UARTn_IFC);
292
293 if (irqflag & (UARTn_IF_TXC | UARTn_IF_TXBL)) {
294 efm32_uart_tx_chars(efm_port);
295 return IRQ_HANDLED;
296 } else
297 return IRQ_NONE;
298}
299
300static int efm32_uart_startup(struct uart_port *port)
301{
302 struct efm32_uart_port *efm_port = to_efm_port(port);
303 u32 location = 0;
304 struct efm32_uart_pdata *pdata = dev_get_platdata(port->dev);
305 int ret;
306
307 if (pdata)
308 location = UARTn_ROUTE_LOCATION(pdata->location);
309
310 ret = clk_enable(efm_port->clk);
311 if (ret) {
312 efm_debug(efm_port, "failed to enable clk\n");
313 goto err_clk_enable;
314 }
315 port->uartclk = clk_get_rate(efm_port->clk);
316
317 /* Enable pins at configured location */
318 efm32_uart_write32(efm_port, location | UARTn_ROUTE_RXPEN | UARTn_ROUTE_TXPEN,
319 UARTn_ROUTE);
320
321 ret = request_irq(port->irq, efm32_uart_rxirq, 0,
322 DRIVER_NAME, efm_port);
323 if (ret) {
324 efm_debug(efm_port, "failed to register rxirq\n");
325 goto err_request_irq_rx;
326 }
327
328 /* disable all irqs */
329 efm32_uart_write32(efm_port, 0, UARTn_IEN);
330
331 ret = request_irq(efm_port->txirq, efm32_uart_txirq, 0,
332 DRIVER_NAME, efm_port);
333 if (ret) {
334 efm_debug(efm_port, "failed to register txirq\n");
335 free_irq(port->irq, efm_port);
336err_request_irq_rx:
337
338 clk_disable(efm_port->clk);
339 } else {
340 efm32_uart_write32(efm_port,
341 UARTn_IF_RXDATAV | UARTn_IF_RXOF, UARTn_IEN);
342 efm32_uart_write32(efm_port, UARTn_CMD_RXEN, UARTn_CMD);
343 }
344
345err_clk_enable:
346 return ret;
347}
348
349static void efm32_uart_shutdown(struct uart_port *port)
350{
351 struct efm32_uart_port *efm_port = to_efm_port(port);
352
353 efm32_uart_write32(efm_port, 0, UARTn_IEN);
354 free_irq(port->irq, efm_port);
355
356 clk_disable(efm_port->clk);
357}
358
359static void efm32_uart_set_termios(struct uart_port *port,
360 struct ktermios *new, struct ktermios *old)
361{
362 struct efm32_uart_port *efm_port = to_efm_port(port);
363 unsigned long flags;
364 unsigned baud;
365 u32 clkdiv;
366 u32 frame = 0;
367
368 /* no modem control lines */
369 new->c_cflag &= ~(CRTSCTS | CMSPAR);
370
371 baud = uart_get_baud_rate(port, new, old,
372 DIV_ROUND_CLOSEST(port->uartclk, 16 * 8192),
373 DIV_ROUND_CLOSEST(port->uartclk, 16));
374
375 switch (new->c_cflag & CSIZE) {
376 case CS5:
377 frame |= UARTn_FRAME_DATABITS(5);
378 break;
379 case CS6:
380 frame |= UARTn_FRAME_DATABITS(6);
381 break;
382 case CS7:
383 frame |= UARTn_FRAME_DATABITS(7);
384 break;
385 case CS8:
386 frame |= UARTn_FRAME_DATABITS(8);
387 break;
388 }
389
390 if (new->c_cflag & CSTOPB)
391 /* the receiver only verifies the first stop bit */
392 frame |= UARTn_FRAME_STOPBITS_TWO;
393 else
394 frame |= UARTn_FRAME_STOPBITS_ONE;
395
396 if (new->c_cflag & PARENB) {
397 if (new->c_cflag & PARODD)
398 frame |= UARTn_FRAME_PARITY_ODD;
399 else
400 frame |= UARTn_FRAME_PARITY_EVEN;
401 } else
402 frame |= UARTn_FRAME_PARITY_NONE;
403
404 /*
405 * the 6 lowest bits of CLKDIV are dc, bit 6 has value 0.25.
406 * port->uartclk <= 14e6, so 4 * port->uartclk doesn't overflow.
407 */
408 clkdiv = (DIV_ROUND_CLOSEST(4 * port->uartclk, 16 * baud) - 4) << 6;
409
410 spin_lock_irqsave(&port->lock, flags);
411
412 efm32_uart_write32(efm_port,
413 UARTn_CMD_TXDIS | UARTn_CMD_RXDIS, UARTn_CMD);
414
415 port->read_status_mask = UARTn_RXDATAX_RXDATA__MASK;
416 if (new->c_iflag & INPCK)
417 port->read_status_mask |=
418 UARTn_RXDATAX_FERR | UARTn_RXDATAX_PERR;
419 if (new->c_iflag & (BRKINT | PARMRK))
420 port->read_status_mask |= SW_UARTn_RXDATAX_BERR;
421
422 port->ignore_status_mask = 0;
423 if (new->c_iflag & IGNPAR)
424 port->ignore_status_mask |=
425 UARTn_RXDATAX_FERR | UARTn_RXDATAX_PERR;
426 if (new->c_iflag & IGNBRK)
427 port->ignore_status_mask |= SW_UARTn_RXDATAX_BERR;
428
429 uart_update_timeout(port, new->c_cflag, baud);
430
431 efm32_uart_write32(efm_port, UARTn_CTRL_TXBIL, UARTn_CTRL);
432 efm32_uart_write32(efm_port, frame, UARTn_FRAME);
433 efm32_uart_write32(efm_port, clkdiv, UARTn_CLKDIV);
434
435 efm32_uart_write32(efm_port, UARTn_CMD_TXEN | UARTn_CMD_RXEN,
436 UARTn_CMD);
437
438 spin_unlock_irqrestore(&port->lock, flags);
439}
440
441static const char *efm32_uart_type(struct uart_port *port)
442{
443 return port->type == PORT_EFMUART ? "efm32-uart" : NULL;
444}
445
446static void efm32_uart_release_port(struct uart_port *port)
447{
448 struct efm32_uart_port *efm_port = to_efm_port(port);
449
450 clk_unprepare(efm_port->clk);
451 clk_put(efm_port->clk);
452 iounmap(port->membase);
453}
454
455static int efm32_uart_request_port(struct uart_port *port)
456{
457 struct efm32_uart_port *efm_port = to_efm_port(port);
458 int ret;
459
460 port->membase = ioremap(port->mapbase, 60);
461 if (!efm_port->port.membase) {
462 ret = -ENOMEM;
463 efm_debug(efm_port, "failed to remap\n");
464 goto err_ioremap;
465 }
466
467 efm_port->clk = clk_get(port->dev, NULL);
468 if (IS_ERR(efm_port->clk)) {
469 ret = PTR_ERR(efm_port->clk);
470 efm_debug(efm_port, "failed to get clock\n");
471 goto err_clk_get;
472 }
473
474 ret = clk_prepare(efm_port->clk);
475 if (ret) {
476 clk_put(efm_port->clk);
477err_clk_get:
478
479 iounmap(port->membase);
480err_ioremap:
481 return ret;
482 }
483 return 0;
484}
485
486static void efm32_uart_config_port(struct uart_port *port, int type)
487{
488 if (type & UART_CONFIG_TYPE &&
489 !efm32_uart_request_port(port))
490 port->type = PORT_EFMUART;
491}
492
493static int efm32_uart_verify_port(struct uart_port *port,
494 struct serial_struct *serinfo)
495{
496 int ret = 0;
497
498 if (serinfo->type != PORT_UNKNOWN && serinfo->type != PORT_EFMUART)
499 ret = -EINVAL;
500
501 return ret;
502}
503
504static struct uart_ops efm32_uart_pops = {
505 .tx_empty = efm32_uart_tx_empty,
506 .set_mctrl = efm32_uart_set_mctrl,
507 .get_mctrl = efm32_uart_get_mctrl,
508 .stop_tx = efm32_uart_stop_tx,
509 .start_tx = efm32_uart_start_tx,
510 .stop_rx = efm32_uart_stop_rx,
511 .enable_ms = efm32_uart_enable_ms,
512 .break_ctl = efm32_uart_break_ctl,
513 .startup = efm32_uart_startup,
514 .shutdown = efm32_uart_shutdown,
515 .set_termios = efm32_uart_set_termios,
516 .type = efm32_uart_type,
517 .release_port = efm32_uart_release_port,
518 .request_port = efm32_uart_request_port,
519 .config_port = efm32_uart_config_port,
520 .verify_port = efm32_uart_verify_port,
521};
522
523static struct efm32_uart_port *efm32_uart_ports[5];
524
525#ifdef CONFIG_SERIAL_EFM32_UART_CONSOLE
526static void efm32_uart_console_putchar(struct uart_port *port, int ch)
527{
528 struct efm32_uart_port *efm_port = to_efm_port(port);
529 unsigned int timeout = 0x400;
530 u32 status;
531
532 while (1) {
533 status = efm32_uart_read32(efm_port, UARTn_STATUS);
534
535 if (status & UARTn_STATUS_TXBL)
536 break;
537 if (!timeout--)
538 return;
539 }
540 efm32_uart_write32(efm_port, ch, UARTn_TXDATA);
541}
542
543static void efm32_uart_console_write(struct console *co, const char *s,
544 unsigned int count)
545{
546 struct efm32_uart_port *efm_port = efm32_uart_ports[co->index];
547 u32 status = efm32_uart_read32(efm_port, UARTn_STATUS);
548 unsigned int timeout = 0x400;
549
550 if (!(status & UARTn_STATUS_TXENS))
551 efm32_uart_write32(efm_port, UARTn_CMD_TXEN, UARTn_CMD);
552
553 uart_console_write(&efm_port->port, s, count,
554 efm32_uart_console_putchar);
555
556 /* Wait for the transmitter to become empty */
557 while (1) {
558 u32 status = efm32_uart_read32(efm_port, UARTn_STATUS);
559 if (status & UARTn_STATUS_TXC)
560 break;
561 if (!timeout--)
562 break;
563 }
564
565 if (!(status & UARTn_STATUS_TXENS))
566 efm32_uart_write32(efm_port, UARTn_CMD_TXDIS, UARTn_CMD);
567}
568
569static void efm32_uart_console_get_options(struct efm32_uart_port *efm_port,
570 int *baud, int *parity, int *bits)
571{
572 u32 ctrl = efm32_uart_read32(efm_port, UARTn_CTRL);
573 u32 route, clkdiv, frame;
574
575 if (ctrl & UARTn_CTRL_SYNC)
576 /* not operating in async mode */
577 return;
578
579 route = efm32_uart_read32(efm_port, UARTn_ROUTE);
580 if (!(route & UARTn_ROUTE_TXPEN))
581 /* tx pin not routed */
582 return;
583
584 clkdiv = efm32_uart_read32(efm_port, UARTn_CLKDIV);
585
586 *baud = DIV_ROUND_CLOSEST(4 * efm_port->port.uartclk,
587 16 * (4 + (clkdiv >> 6)));
588
589 frame = efm32_uart_read32(efm_port, UARTn_FRAME);
590 if (frame & UARTn_FRAME_PARITY_ODD)
591 *parity = 'o';
592 else if (frame & UARTn_FRAME_PARITY_EVEN)
593 *parity = 'e';
594 else
595 *parity = 'n';
596
597 *bits = (frame & UARTn_FRAME_DATABITS__MASK) -
598 UARTn_FRAME_DATABITS(4) + 4;
599
600 efm_debug(efm_port, "get_opts: options=%d%c%d\n",
601 *baud, *parity, *bits);
602}
603
604static int efm32_uart_console_setup(struct console *co, char *options)
605{
606 struct efm32_uart_port *efm_port;
607 int baud = 115200;
608 int bits = 8;
609 int parity = 'n';
610 int flow = 'n';
611 int ret;
612
613 if (co->index < 0 || co->index >= ARRAY_SIZE(efm32_uart_ports)) {
614 unsigned i;
615 for (i = 0; i < ARRAY_SIZE(efm32_uart_ports); ++i) {
616 if (efm32_uart_ports[i]) {
617 pr_warn("efm32-console: fall back to console index %u (from %hhi)\n",
618 i, co->index);
619 co->index = i;
620 break;
621 }
622 }
623 }
624
625 efm_port = efm32_uart_ports[co->index];
626 if (!efm_port) {
627 pr_warn("efm32-console: No port at %d\n", co->index);
628 return -ENODEV;
629 }
630
631 ret = clk_prepare(efm_port->clk);
632 if (ret) {
633 dev_warn(efm_port->port.dev,
634 "console: clk_prepare failed: %d\n", ret);
635 return ret;
636 }
637
638 efm_port->port.uartclk = clk_get_rate(efm_port->clk);
639
640 if (options)
641 uart_parse_options(options, &baud, &parity, &bits, &flow);
642 else
643 efm32_uart_console_get_options(efm_port,
644 &baud, &parity, &bits);
645
646 return uart_set_options(&efm_port->port, co, baud, parity, bits, flow);
647}
648
649static struct uart_driver efm32_uart_reg;
650
651static struct console efm32_uart_console = {
652 .name = DEV_NAME,
653 .write = efm32_uart_console_write,
654 .device = uart_console_device,
655 .setup = efm32_uart_console_setup,
656 .flags = CON_PRINTBUFFER,
657 .index = -1,
658 .data = &efm32_uart_reg,
659};
660
661#else
662#define efm32_uart_console (*(struct console *)NULL)
663#endif /* ifdef CONFIG_SERIAL_EFM32_UART_CONSOLE / else */
664
665static struct uart_driver efm32_uart_reg = {
666 .owner = THIS_MODULE,
667 .driver_name = DRIVER_NAME,
668 .dev_name = DEV_NAME,
669 .nr = ARRAY_SIZE(efm32_uart_ports),
670 .cons = &efm32_uart_console,
671};
672
673static int efm32_uart_probe_dt(struct platform_device *pdev,
674 struct efm32_uart_port *efm_port)
675{
676 struct device_node *np = pdev->dev.of_node;
677 int ret;
678
679 if (!np)
680 return 1;
681
682 ret = of_alias_get_id(np, "serial");
683 if (ret < 0) {
684 dev_err(&pdev->dev, "failed to get alias id: %d\n", ret);
685 return ret;
686 } else {
687 efm_port->port.line = ret;
688 return 0;
689 }
690
691}
692
693static int efm32_uart_probe(struct platform_device *pdev)
694{
695 struct efm32_uart_port *efm_port;
696 struct resource *res;
697 int ret;
698
699 efm_port = kzalloc(sizeof(*efm_port), GFP_KERNEL);
700 if (!efm_port) {
701 dev_dbg(&pdev->dev, "failed to allocate private data\n");
702 return -ENOMEM;
703 }
704
705 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
706 if (!res) {
707 ret = -ENODEV;
708 dev_dbg(&pdev->dev, "failed to determine base address\n");
709 goto err_get_base;
710 }
711
712 if (resource_size(res) < 60) {
713 ret = -EINVAL;
714 dev_dbg(&pdev->dev, "memory resource too small\n");
715 goto err_too_small;
716 }
717
718 ret = platform_get_irq(pdev, 0);
719 if (ret <= 0) {
720 dev_dbg(&pdev->dev, "failed to get rx irq\n");
721 goto err_get_rxirq;
722 }
723
724 efm_port->port.irq = ret;
725
726 ret = platform_get_irq(pdev, 1);
727 if (ret <= 0)
728 ret = efm_port->port.irq + 1;
729
730 efm_port->txirq = ret;
731
732 efm_port->port.dev = &pdev->dev;
733 efm_port->port.mapbase = res->start;
734 efm_port->port.type = PORT_EFMUART;
735 efm_port->port.iotype = UPIO_MEM32;
736 efm_port->port.fifosize = 2;
737 efm_port->port.ops = &efm32_uart_pops;
738 efm_port->port.flags = UPF_BOOT_AUTOCONF;
739
740 ret = efm32_uart_probe_dt(pdev, efm_port);
741 if (ret > 0)
742 /* not created by device tree */
743 efm_port->port.line = pdev->id;
744
745 if (efm_port->port.line >= 0 &&
746 efm_port->port.line < ARRAY_SIZE(efm32_uart_ports))
747 efm32_uart_ports[efm_port->port.line] = efm_port;
748
749 ret = uart_add_one_port(&efm32_uart_reg, &efm_port->port);
750 if (ret) {
751 dev_dbg(&pdev->dev, "failed to add port: %d\n", ret);
752
753 if (pdev->id >= 0 && pdev->id < ARRAY_SIZE(efm32_uart_ports))
754 efm32_uart_ports[pdev->id] = NULL;
755err_get_rxirq:
756err_too_small:
757err_get_base:
758 kfree(efm_port);
759 } else {
760 platform_set_drvdata(pdev, efm_port);
761 dev_dbg(&pdev->dev, "\\o/\n");
762 }
763
764 return ret;
765}
766
767static int efm32_uart_remove(struct platform_device *pdev)
768{
769 struct efm32_uart_port *efm_port = platform_get_drvdata(pdev);
770
771 platform_set_drvdata(pdev, NULL);
772
773 uart_remove_one_port(&efm32_uart_reg, &efm_port->port);
774
775 if (pdev->id >= 0 && pdev->id < ARRAY_SIZE(efm32_uart_ports))
776 efm32_uart_ports[pdev->id] = NULL;
777
778 kfree(efm_port);
779
780 return 0;
781}
782
783static struct of_device_id efm32_uart_dt_ids[] = {
784 {
785 .compatible = "efm32,uart",
786 }, {
787 /* sentinel */
788 }
789};
790MODULE_DEVICE_TABLE(of, efm32_uart_dt_ids);
791
792static struct platform_driver efm32_uart_driver = {
793 .probe = efm32_uart_probe,
794 .remove = efm32_uart_remove,
795
796 .driver = {
797 .name = DRIVER_NAME,
798 .owner = THIS_MODULE,
799 .of_match_table = efm32_uart_dt_ids,
800 },
801};
802
803static int __init efm32_uart_init(void)
804{
805 int ret;
806
807 ret = uart_register_driver(&efm32_uart_reg);
808 if (ret)
809 return ret;
810
811 ret = platform_driver_register(&efm32_uart_driver);
812 if (ret)
813 uart_unregister_driver(&efm32_uart_reg);
814
815 pr_info("EFM32 UART/USART driver\n");
816
817 return ret;
818}
819module_init(efm32_uart_init);
820
821static void __exit efm32_uart_exit(void)
822{
823 platform_driver_unregister(&efm32_uart_driver);
824 uart_unregister_driver(&efm32_uart_reg);
825}
826
827MODULE_AUTHOR("Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>");
828MODULE_DESCRIPTION("EFM32 UART/USART driver");
829MODULE_LICENSE("GPL v2");
830MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/tty/serial/icom.c b/drivers/tty/serial/icom.c
index 72b6334bcf1..8a869e58f6d 100644
--- a/drivers/tty/serial/icom.c
+++ b/drivers/tty/serial/icom.c
@@ -52,6 +52,7 @@
52#include <linux/firmware.h> 52#include <linux/firmware.h>
53#include <linux/bitops.h> 53#include <linux/bitops.h>
54 54
55#include <asm/system.h>
55#include <asm/io.h> 56#include <asm/io.h>
56#include <asm/irq.h> 57#include <asm/irq.h>
57#include <asm/uaccess.h> 58#include <asm/uaccess.h>
@@ -175,7 +176,7 @@ static void free_port_memory(struct icom_port *icom_port)
175 } 176 }
176} 177}
177 178
178static int get_port_memory(struct icom_port *icom_port) 179static int __devinit get_port_memory(struct icom_port *icom_port)
179{ 180{
180 int index; 181 int index;
181 unsigned long stgAddr; 182 unsigned long stgAddr;
@@ -505,7 +506,7 @@ static void load_code(struct icom_port *icom_port)
505 /* Stop processor */ 506 /* Stop processor */
506 stop_processor(icom_port); 507 stop_processor(icom_port);
507 508
508 dev_err(&icom_port->adapter->pci_dev->dev,"Port not operational\n"); 509 dev_err(&icom_port->adapter->pci_dev->dev,"Port not opertional\n");
509 } 510 }
510 511
511 if (new_page != NULL) 512 if (new_page != NULL)
@@ -1314,7 +1315,7 @@ static struct uart_driver icom_uart_driver = {
1314 .cons = ICOM_CONSOLE, 1315 .cons = ICOM_CONSOLE,
1315}; 1316};
1316 1317
1317static int icom_init_ports(struct icom_adapter *icom_adapter) 1318static int __devinit icom_init_ports(struct icom_adapter *icom_adapter)
1318{ 1319{
1319 u32 subsystem_id = icom_adapter->subsystem_id; 1320 u32 subsystem_id = icom_adapter->subsystem_id;
1320 int i; 1321 int i;
@@ -1381,7 +1382,7 @@ static void icom_port_active(struct icom_port *icom_port, struct icom_adapter *i
1381 0x8024 + 2 - 2 * (icom_port->port - 2); 1382 0x8024 + 2 - 2 * (icom_port->port - 2);
1382 } 1383 }
1383} 1384}
1384static int icom_load_ports(struct icom_adapter *icom_adapter) 1385static int __devinit icom_load_ports(struct icom_adapter *icom_adapter)
1385{ 1386{
1386 struct icom_port *icom_port; 1387 struct icom_port *icom_port;
1387 int port_num; 1388 int port_num;
@@ -1407,7 +1408,7 @@ static int icom_load_ports(struct icom_adapter *icom_adapter)
1407 return 0; 1408 return 0;
1408} 1409}
1409 1410
1410static int icom_alloc_adapter(struct icom_adapter 1411static int __devinit icom_alloc_adapter(struct icom_adapter
1411 **icom_adapter_ref) 1412 **icom_adapter_ref)
1412{ 1413{
1413 int adapter_count = 0; 1414 int adapter_count = 0;
@@ -1487,7 +1488,7 @@ static void icom_kref_release(struct kref *kref)
1487 icom_remove_adapter(icom_adapter); 1488 icom_remove_adapter(icom_adapter);
1488} 1489}
1489 1490
1490static int icom_probe(struct pci_dev *dev, 1491static int __devinit icom_probe(struct pci_dev *dev,
1491 const struct pci_device_id *ent) 1492 const struct pci_device_id *ent)
1492{ 1493{
1493 int index; 1494 int index;
@@ -1553,7 +1554,7 @@ static int icom_probe(struct pci_dev *dev,
1553 1554
1554 /* save off irq and request irq line */ 1555 /* save off irq and request irq line */
1555 if ( (retval = request_irq(dev->irq, icom_interrupt, 1556 if ( (retval = request_irq(dev->irq, icom_interrupt,
1556 IRQF_SHARED, ICOM_DRIVER_NAME, 1557 IRQF_DISABLED | IRQF_SHARED, ICOM_DRIVER_NAME,
1557 (void *) icom_adapter))) { 1558 (void *) icom_adapter))) {
1558 goto probe_exit2; 1559 goto probe_exit2;
1559 } 1560 }
@@ -1596,7 +1597,7 @@ probe_exit0:
1596 return retval; 1597 return retval;
1597} 1598}
1598 1599
1599static void icom_remove(struct pci_dev *dev) 1600static void __devexit icom_remove(struct pci_dev *dev)
1600{ 1601{
1601 struct icom_adapter *icom_adapter; 1602 struct icom_adapter *icom_adapter;
1602 struct list_head *tmp; 1603 struct list_head *tmp;
@@ -1617,7 +1618,7 @@ static struct pci_driver icom_pci_driver = {
1617 .name = ICOM_DRIVER_NAME, 1618 .name = ICOM_DRIVER_NAME,
1618 .id_table = icom_pci_table, 1619 .id_table = icom_pci_table,
1619 .probe = icom_probe, 1620 .probe = icom_probe,
1620 .remove = icom_remove, 1621 .remove = __devexit_p(icom_remove),
1621}; 1622};
1622 1623
1623static int __init icom_init(void) 1624static int __init icom_init(void)
diff --git a/drivers/tty/serial/ifx6x60.c b/drivers/tty/serial/ifx6x60.c
index 675d94ab0af..426434e5eb7 100644
--- a/drivers/tty/serial/ifx6x60.c
+++ b/drivers/tty/serial/ifx6x60.c
@@ -60,27 +60,20 @@
60#include <linux/pm_runtime.h> 60#include <linux/pm_runtime.h>
61#include <linux/spi/ifx_modem.h> 61#include <linux/spi/ifx_modem.h>
62#include <linux/delay.h> 62#include <linux/delay.h>
63#include <linux/reboot.h>
64 63
65#include "ifx6x60.h" 64#include "ifx6x60.h"
66 65
67#define IFX_SPI_MORE_MASK 0x10 66#define IFX_SPI_MORE_MASK 0x10
68#define IFX_SPI_MORE_BIT 4 /* bit position in u8 */ 67#define IFX_SPI_MORE_BIT 12 /* bit position in u16 */
69#define IFX_SPI_CTS_BIT 6 /* bit position in u8 */ 68#define IFX_SPI_CTS_BIT 13 /* bit position in u16 */
70#define IFX_SPI_MODE SPI_MODE_1 69#define IFX_SPI_MODE SPI_MODE_1
71#define IFX_SPI_TTY_ID 0 70#define IFX_SPI_TTY_ID 0
72#define IFX_SPI_TIMEOUT_SEC 2 71#define IFX_SPI_TIMEOUT_SEC 2
73#define IFX_SPI_HEADER_0 (-1) 72#define IFX_SPI_HEADER_0 (-1)
74#define IFX_SPI_HEADER_F (-2) 73#define IFX_SPI_HEADER_F (-2)
75 74
76#define PO_POST_DELAY 200
77#define IFX_MDM_RST_PMU 4
78
79/* forward reference */ 75/* forward reference */
80static void ifx_spi_handle_srdy(struct ifx_spi_device *ifx_dev); 76static void ifx_spi_handle_srdy(struct ifx_spi_device *ifx_dev);
81static int ifx_modem_reboot_callback(struct notifier_block *nfb,
82 unsigned long event, void *data);
83static int ifx_modem_power_off(struct ifx_spi_device *ifx_dev);
84 77
85/* local variables */ 78/* local variables */
86static int spi_bpw = 16; /* 8, 16 or 32 bit word length */ 79static int spi_bpw = 16; /* 8, 16 or 32 bit word length */
@@ -88,29 +81,6 @@ static struct tty_driver *tty_drv;
88static struct ifx_spi_device *saved_ifx_dev; 81static struct ifx_spi_device *saved_ifx_dev;
89static struct lock_class_key ifx_spi_key; 82static struct lock_class_key ifx_spi_key;
90 83
91static struct notifier_block ifx_modem_reboot_notifier_block = {
92 .notifier_call = ifx_modem_reboot_callback,
93};
94
95static int ifx_modem_power_off(struct ifx_spi_device *ifx_dev)
96{
97 gpio_set_value(IFX_MDM_RST_PMU, 1);
98 msleep(PO_POST_DELAY);
99
100 return 0;
101}
102
103static int ifx_modem_reboot_callback(struct notifier_block *nfb,
104 unsigned long event, void *data)
105{
106 if (saved_ifx_dev)
107 ifx_modem_power_off(saved_ifx_dev);
108 else
109 pr_warn("no ifx modem active;\n");
110
111 return NOTIFY_OK;
112}
113
114/* GPIO/GPE settings */ 84/* GPIO/GPE settings */
115 85
116/** 86/**
@@ -182,67 +152,26 @@ ifx_spi_power_state_clear(struct ifx_spi_device *ifx_dev, unsigned char val)
182} 152}
183 153
184/** 154/**
185 * swap_buf_8 155 * swap_buf
186 * @buf: our buffer 156 * @buf: our buffer
187 * @len : number of bytes (not words) in the buffer 157 * @len : number of bytes (not words) in the buffer
188 * @end: end of buffer 158 * @end: end of buffer
189 * 159 *
190 * Swap the contents of a buffer into big endian format 160 * Swap the contents of a buffer into big endian format
191 */ 161 */
192static inline void swap_buf_8(unsigned char *buf, int len, void *end) 162static inline void swap_buf(u16 *buf, int len, void *end)
193{
194 /* don't swap buffer if SPI word width is 8 bits */
195 return;
196}
197
198/**
199 * swap_buf_16
200 * @buf: our buffer
201 * @len : number of bytes (not words) in the buffer
202 * @end: end of buffer
203 *
204 * Swap the contents of a buffer into big endian format
205 */
206static inline void swap_buf_16(unsigned char *buf, int len, void *end)
207{ 163{
208 int n; 164 int n;
209 165
210 u16 *buf_16 = (u16 *)buf;
211 len = ((len + 1) >> 1); 166 len = ((len + 1) >> 1);
212 if ((void *)&buf_16[len] > end) { 167 if ((void *)&buf[len] > end) {
213 pr_err("swap_buf_16: swap exceeds boundary (%p > %p)!", 168 pr_err("swap_buf: swap exceeds boundary (%p > %p)!",
214 &buf_16[len], end); 169 &buf[len], end);
215 return;
216 }
217 for (n = 0; n < len; n++) {
218 *buf_16 = cpu_to_be16(*buf_16);
219 buf_16++;
220 }
221}
222
223/**
224 * swap_buf_32
225 * @buf: our buffer
226 * @len : number of bytes (not words) in the buffer
227 * @end: end of buffer
228 *
229 * Swap the contents of a buffer into big endian format
230 */
231static inline void swap_buf_32(unsigned char *buf, int len, void *end)
232{
233 int n;
234
235 u32 *buf_32 = (u32 *)buf;
236 len = (len + 3) >> 2;
237
238 if ((void *)&buf_32[len] > end) {
239 pr_err("swap_buf_32: swap exceeds boundary (%p > %p)!\n",
240 &buf_32[len], end);
241 return; 170 return;
242 } 171 }
243 for (n = 0; n < len; n++) { 172 for (n = 0; n < len; n++) {
244 *buf_32 = cpu_to_be32(*buf_32); 173 *buf = cpu_to_be16(*buf);
245 buf_32++; 174 buf++;
246 } 175 }
247} 176}
248 177
@@ -261,7 +190,9 @@ static void mrdy_assert(struct ifx_spi_device *ifx_dev)
261 if (!val) { 190 if (!val) {
262 if (!test_and_set_bit(IFX_SPI_STATE_TIMER_PENDING, 191 if (!test_and_set_bit(IFX_SPI_STATE_TIMER_PENDING,
263 &ifx_dev->flags)) { 192 &ifx_dev->flags)) {
264 mod_timer(&ifx_dev->spi_timer,jiffies + IFX_SPI_TIMEOUT_SEC*HZ); 193 ifx_dev->spi_timer.expires =
194 jiffies + IFX_SPI_TIMEOUT_SEC*HZ;
195 add_timer(&ifx_dev->spi_timer);
265 196
266 } 197 }
267 } 198 }
@@ -518,7 +449,7 @@ static int ifx_spi_prepare_tx_buffer(struct ifx_spi_device *ifx_dev)
518 tx_count-IFX_SPI_HEADER_OVERHEAD, 449 tx_count-IFX_SPI_HEADER_OVERHEAD,
519 ifx_dev->spi_more); 450 ifx_dev->spi_more);
520 /* swap actual data in the buffer */ 451 /* swap actual data in the buffer */
521 ifx_dev->swap_buf((ifx_dev->tx_buffer), tx_count, 452 swap_buf((u16 *)(ifx_dev->tx_buffer), tx_count,
522 &ifx_dev->tx_buffer[IFX_SPI_TRANSFER_SIZE]); 453 &ifx_dev->tx_buffer[IFX_SPI_TRANSFER_SIZE]);
523 return tx_count; 454 return tx_count;
524} 455}
@@ -538,17 +469,9 @@ static int ifx_spi_write(struct tty_struct *tty, const unsigned char *buf,
538{ 469{
539 struct ifx_spi_device *ifx_dev = tty->driver_data; 470 struct ifx_spi_device *ifx_dev = tty->driver_data;
540 unsigned char *tmp_buf = (unsigned char *)buf; 471 unsigned char *tmp_buf = (unsigned char *)buf;
541 unsigned long flags; 472 int tx_count = kfifo_in_locked(&ifx_dev->tx_fifo, tmp_buf, count,
542 bool is_fifo_empty; 473 &ifx_dev->fifo_lock);
543 int tx_count; 474 mrdy_assert(ifx_dev);
544
545 spin_lock_irqsave(&ifx_dev->fifo_lock, flags);
546 is_fifo_empty = kfifo_is_empty(&ifx_dev->tx_fifo);
547 tx_count = kfifo_in(&ifx_dev->tx_fifo, tmp_buf, count);
548 spin_unlock_irqrestore(&ifx_dev->fifo_lock, flags);
549 if (is_fifo_empty)
550 mrdy_assert(ifx_dev);
551
552 return tx_count; 475 return tx_count;
553} 476}
554 477
@@ -607,19 +530,12 @@ static int ifx_port_activate(struct tty_port *port, struct tty_struct *tty)
607 /* clear any old data; can't do this in 'close' */ 530 /* clear any old data; can't do this in 'close' */
608 kfifo_reset(&ifx_dev->tx_fifo); 531 kfifo_reset(&ifx_dev->tx_fifo);
609 532
610 /* clear any flag which may be set in port shutdown procedure */
611 clear_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags);
612 clear_bit(IFX_SPI_STATE_IO_READY, &ifx_dev->flags);
613
614 /* put port data into this tty */ 533 /* put port data into this tty */
615 tty->driver_data = ifx_dev; 534 tty->driver_data = ifx_dev;
616 535
617 /* allows flip string push from int context */ 536 /* allows flip string push from int context */
618 tty->low_latency = 1; 537 tty->low_latency = 1;
619 538
620 /* set flag to allows data transfer */
621 set_bit(IFX_SPI_STATE_IO_AVAILABLE, &ifx_dev->flags);
622
623 return 0; 539 return 0;
624} 540}
625 541
@@ -635,7 +551,6 @@ static void ifx_port_shutdown(struct tty_port *port)
635 struct ifx_spi_device *ifx_dev = 551 struct ifx_spi_device *ifx_dev =
636 container_of(port, struct ifx_spi_device, tty_port); 552 container_of(port, struct ifx_spi_device, tty_port);
637 553
638 clear_bit(IFX_SPI_STATE_IO_AVAILABLE, &ifx_dev->flags);
639 mrdy_set_low(ifx_dev); 554 mrdy_set_low(ifx_dev);
640 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); 555 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags);
641 tasklet_kill(&ifx_dev->io_work_tasklet); 556 tasklet_kill(&ifx_dev->io_work_tasklet);
@@ -702,7 +617,7 @@ static void ifx_spi_complete(void *ctx)
702 617
703 if (!ifx_dev->spi_msg.status) { 618 if (!ifx_dev->spi_msg.status) {
704 /* check header validity, get comm flags */ 619 /* check header validity, get comm flags */
705 ifx_dev->swap_buf(ifx_dev->rx_buffer, IFX_SPI_HEADER_OVERHEAD, 620 swap_buf((u16 *)ifx_dev->rx_buffer, IFX_SPI_HEADER_OVERHEAD,
706 &ifx_dev->rx_buffer[IFX_SPI_HEADER_OVERHEAD]); 621 &ifx_dev->rx_buffer[IFX_SPI_HEADER_OVERHEAD]);
707 decode_result = ifx_spi_decode_spi_header(ifx_dev->rx_buffer, 622 decode_result = ifx_spi_decode_spi_header(ifx_dev->rx_buffer,
708 &length, &more, &cts); 623 &length, &more, &cts);
@@ -721,8 +636,7 @@ static void ifx_spi_complete(void *ctx)
721 636
722 actual_length = min((unsigned int)length, 637 actual_length = min((unsigned int)length,
723 ifx_dev->spi_msg.actual_length); 638 ifx_dev->spi_msg.actual_length);
724 ifx_dev->swap_buf( 639 swap_buf((u16 *)(ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD),
725 (ifx_dev->rx_buffer + IFX_SPI_HEADER_OVERHEAD),
726 actual_length, 640 actual_length,
727 &ifx_dev->rx_buffer[IFX_SPI_TRANSFER_SIZE]); 641 &ifx_dev->rx_buffer[IFX_SPI_TRANSFER_SIZE]);
728 ifx_spi_insert_flip_string( 642 ifx_spi_insert_flip_string(
@@ -791,8 +705,7 @@ static void ifx_spi_io(unsigned long data)
791 int retval; 705 int retval;
792 struct ifx_spi_device *ifx_dev = (struct ifx_spi_device *) data; 706 struct ifx_spi_device *ifx_dev = (struct ifx_spi_device *) data;
793 707
794 if (!test_and_set_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags) && 708 if (!test_and_set_bit(IFX_SPI_STATE_IO_IN_PROGRESS, &ifx_dev->flags)) {
795 test_bit(IFX_SPI_STATE_IO_AVAILABLE, &ifx_dev->flags)) {
796 if (ifx_dev->gpio.unack_srdy_int_nb > 0) 709 if (ifx_dev->gpio.unack_srdy_int_nb > 0)
797 ifx_dev->gpio.unack_srdy_int_nb--; 710 ifx_dev->gpio.unack_srdy_int_nb--;
798 711
@@ -860,7 +773,6 @@ static void ifx_spi_free_port(struct ifx_spi_device *ifx_dev)
860{ 773{
861 if (ifx_dev->tty_dev) 774 if (ifx_dev->tty_dev)
862 tty_unregister_device(tty_drv, ifx_dev->minor); 775 tty_unregister_device(tty_drv, ifx_dev->minor);
863 tty_port_destroy(&ifx_dev->tty_port);
864 kfifo_free(&ifx_dev->tx_fifo); 776 kfifo_free(&ifx_dev->tx_fifo);
865} 777}
866 778
@@ -888,18 +800,16 @@ static int ifx_spi_create_port(struct ifx_spi_device *ifx_dev)
888 tty_port_init(pport); 800 tty_port_init(pport);
889 pport->ops = &ifx_tty_port_ops; 801 pport->ops = &ifx_tty_port_ops;
890 ifx_dev->minor = IFX_SPI_TTY_ID; 802 ifx_dev->minor = IFX_SPI_TTY_ID;
891 ifx_dev->tty_dev = tty_port_register_device(pport, tty_drv, 803 ifx_dev->tty_dev = tty_register_device(tty_drv, ifx_dev->minor,
892 ifx_dev->minor, &ifx_dev->spi_dev->dev); 804 &ifx_dev->spi_dev->dev);
893 if (IS_ERR(ifx_dev->tty_dev)) { 805 if (IS_ERR(ifx_dev->tty_dev)) {
894 dev_dbg(&ifx_dev->spi_dev->dev, 806 dev_dbg(&ifx_dev->spi_dev->dev,
895 "%s: registering tty device failed", __func__); 807 "%s: registering tty device failed", __func__);
896 ret = PTR_ERR(ifx_dev->tty_dev); 808 ret = PTR_ERR(ifx_dev->tty_dev);
897 goto error_port; 809 goto error_ret;
898 } 810 }
899 return 0; 811 return 0;
900 812
901error_port:
902 tty_port_destroy(pport);
903error_ret: 813error_ret:
904 ifx_spi_free_port(ifx_dev); 814 ifx_spi_free_port(ifx_dev);
905 return ret; 815 return ret;
@@ -916,7 +826,7 @@ error_ret:
916static void ifx_spi_handle_srdy(struct ifx_spi_device *ifx_dev) 826static void ifx_spi_handle_srdy(struct ifx_spi_device *ifx_dev)
917{ 827{
918 if (test_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags)) { 828 if (test_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags)) {
919 del_timer(&ifx_dev->spi_timer); 829 del_timer_sync(&ifx_dev->spi_timer);
920 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags); 830 clear_bit(IFX_SPI_STATE_TIMER_PENDING, &ifx_dev->flags);
921 } 831 }
922 832
@@ -1091,14 +1001,6 @@ static int ifx_spi_spi_probe(struct spi_device *spi)
1091 return -ENODEV; 1001 return -ENODEV;
1092 } 1002 }
1093 1003
1094 /* init swap_buf function according to word width configuration */
1095 if (spi->bits_per_word == 32)
1096 ifx_dev->swap_buf = swap_buf_32;
1097 else if (spi->bits_per_word == 16)
1098 ifx_dev->swap_buf = swap_buf_16;
1099 else
1100 ifx_dev->swap_buf = swap_buf_8;
1101
1102 /* ensure SPI protocol flags are initialized to enable transfer */ 1004 /* ensure SPI protocol flags are initialized to enable transfer */
1103 ifx_dev->spi_more = 0; 1005 ifx_dev->spi_more = 0;
1104 ifx_dev->spi_slave_cts = 0; 1006 ifx_dev->spi_slave_cts = 0;
@@ -1317,9 +1219,6 @@ static int ifx_spi_spi_remove(struct spi_device *spi)
1317 1219
1318static void ifx_spi_spi_shutdown(struct spi_device *spi) 1220static void ifx_spi_spi_shutdown(struct spi_device *spi)
1319{ 1221{
1320 struct ifx_spi_device *ifx_dev = spi_get_drvdata(spi);
1321
1322 ifx_modem_power_off(ifx_dev);
1323} 1222}
1324 1223
1325/* 1224/*
@@ -1432,14 +1331,15 @@ static const struct spi_device_id ifx_id_table[] = {
1432MODULE_DEVICE_TABLE(spi, ifx_id_table); 1331MODULE_DEVICE_TABLE(spi, ifx_id_table);
1433 1332
1434/* spi operations */ 1333/* spi operations */
1435static struct spi_driver ifx_spi_driver = { 1334static const struct spi_driver ifx_spi_driver = {
1436 .driver = { 1335 .driver = {
1437 .name = DRVNAME, 1336 .name = DRVNAME,
1337 .bus = &spi_bus_type,
1438 .pm = &ifx_spi_pm, 1338 .pm = &ifx_spi_pm,
1439 .owner = THIS_MODULE}, 1339 .owner = THIS_MODULE},
1440 .probe = ifx_spi_spi_probe, 1340 .probe = ifx_spi_spi_probe,
1441 .shutdown = ifx_spi_spi_shutdown, 1341 .shutdown = ifx_spi_spi_shutdown,
1442 .remove = ifx_spi_spi_remove, 1342 .remove = __devexit_p(ifx_spi_spi_remove),
1443 .suspend = ifx_spi_spi_suspend, 1343 .suspend = ifx_spi_spi_suspend,
1444 .resume = ifx_spi_spi_resume, 1344 .resume = ifx_spi_spi_resume,
1445 .id_table = ifx_id_table 1345 .id_table = ifx_id_table
@@ -1455,9 +1355,7 @@ static void __exit ifx_spi_exit(void)
1455{ 1355{
1456 /* unregister */ 1356 /* unregister */
1457 tty_unregister_driver(tty_drv); 1357 tty_unregister_driver(tty_drv);
1458 put_tty_driver(tty_drv);
1459 spi_unregister_driver((void *)&ifx_spi_driver); 1358 spi_unregister_driver((void *)&ifx_spi_driver);
1460 unregister_reboot_notifier(&ifx_modem_reboot_notifier_block);
1461} 1359}
1462 1360
1463/** 1361/**
@@ -1478,9 +1376,12 @@ static int __init ifx_spi_init(void)
1478 return -ENOMEM; 1376 return -ENOMEM;
1479 } 1377 }
1480 1378
1379 tty_drv->magic = TTY_DRIVER_MAGIC;
1380 tty_drv->owner = THIS_MODULE;
1481 tty_drv->driver_name = DRVNAME; 1381 tty_drv->driver_name = DRVNAME;
1482 tty_drv->name = TTYNAME; 1382 tty_drv->name = TTYNAME;
1483 tty_drv->minor_start = IFX_SPI_TTY_ID; 1383 tty_drv->minor_start = IFX_SPI_TTY_ID;
1384 tty_drv->num = 1;
1484 tty_drv->type = TTY_DRIVER_TYPE_SERIAL; 1385 tty_drv->type = TTY_DRIVER_TYPE_SERIAL;
1485 tty_drv->subtype = SERIAL_TYPE_NORMAL; 1386 tty_drv->subtype = SERIAL_TYPE_NORMAL;
1486 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1387 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
@@ -1492,31 +1393,16 @@ static int __init ifx_spi_init(void)
1492 if (result) { 1393 if (result) {
1493 pr_err("%s: tty_register_driver failed(%d)", 1394 pr_err("%s: tty_register_driver failed(%d)",
1494 DRVNAME, result); 1395 DRVNAME, result);
1495 goto err_free_tty; 1396 put_tty_driver(tty_drv);
1397 return result;
1496 } 1398 }
1497 1399
1498 result = spi_register_driver((void *)&ifx_spi_driver); 1400 result = spi_register_driver((void *)&ifx_spi_driver);
1499 if (result) { 1401 if (result) {
1500 pr_err("%s: spi_register_driver failed(%d)", 1402 pr_err("%s: spi_register_driver failed(%d)",
1501 DRVNAME, result); 1403 DRVNAME, result);
1502 goto err_unreg_tty; 1404 tty_unregister_driver(tty_drv);
1503 } 1405 }
1504
1505 result = register_reboot_notifier(&ifx_modem_reboot_notifier_block);
1506 if (result) {
1507 pr_err("%s: register ifx modem reboot notifier failed(%d)",
1508 DRVNAME, result);
1509 goto err_unreg_spi;
1510 }
1511
1512 return 0;
1513err_unreg_spi:
1514 spi_unregister_driver((void *)&ifx_spi_driver);
1515err_unreg_tty:
1516 tty_unregister_driver(tty_drv);
1517err_free_tty:
1518 put_tty_driver(tty_drv);
1519
1520 return result; 1406 return result;
1521} 1407}
1522 1408
diff --git a/drivers/tty/serial/ifx6x60.h b/drivers/tty/serial/ifx6x60.h
index 4fbddc29783..e8464baf9e7 100644
--- a/drivers/tty/serial/ifx6x60.h
+++ b/drivers/tty/serial/ifx6x60.h
@@ -41,7 +41,6 @@
41#define IFX_SPI_STATE_IO_IN_PROGRESS 1 41#define IFX_SPI_STATE_IO_IN_PROGRESS 1
42#define IFX_SPI_STATE_IO_READY 2 42#define IFX_SPI_STATE_IO_READY 2
43#define IFX_SPI_STATE_TIMER_PENDING 3 43#define IFX_SPI_STATE_TIMER_PENDING 3
44#define IFX_SPI_STATE_IO_AVAILABLE 4
45 44
46/* flow control bitfields */ 45/* flow control bitfields */
47#define IFX_SPI_DCD 0 46#define IFX_SPI_DCD 0
@@ -125,7 +124,6 @@ struct ifx_spi_device {
125#define MR_INPROGRESS 1 124#define MR_INPROGRESS 1
126#define MR_COMPLETE 2 125#define MR_COMPLETE 2
127 wait_queue_head_t mdm_reset_wait; 126 wait_queue_head_t mdm_reset_wait;
128 void (*swap_buf)(unsigned char *buf, int len, void *end);
129}; 127};
130 128
131#endif /* _IFX6X60_H */ 129#endif /* _IFX6X60_H */
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 59819121fe9..7e91b3d368c 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -47,11 +47,10 @@
47#include <linux/slab.h> 47#include <linux/slab.h>
48#include <linux/of.h> 48#include <linux/of.h>
49#include <linux/of_device.h> 49#include <linux/of_device.h>
50#include <linux/pinctrl/consumer.h>
51 50
52#include <asm/io.h> 51#include <asm/io.h>
53#include <asm/irq.h> 52#include <asm/irq.h>
54#include <linux/platform_data/serial-imx.h> 53#include <mach/imx-uart.h>
55 54
56/* Register definitions */ 55/* Register definitions */
57#define URXD0 0x0 /* Receiver Register */ 56#define URXD0 0x0 /* Receiver Register */
@@ -103,7 +102,6 @@
103#define UCR2_STPB (1<<6) /* Stop */ 102#define UCR2_STPB (1<<6) /* Stop */
104#define UCR2_WS (1<<5) /* Word size */ 103#define UCR2_WS (1<<5) /* Word size */
105#define UCR2_RTSEN (1<<4) /* Request to send interrupt enable */ 104#define UCR2_RTSEN (1<<4) /* Request to send interrupt enable */
106#define UCR2_ATEN (1<<3) /* Aging Timer Enable */
107#define UCR2_TXEN (1<<2) /* Transmitter enabled */ 105#define UCR2_TXEN (1<<2) /* Transmitter enabled */
108#define UCR2_RXEN (1<<1) /* Receiver enabled */ 106#define UCR2_RXEN (1<<1) /* Receiver enabled */
109#define UCR2_SRST (1<<0) /* SW reset */ 107#define UCR2_SRST (1<<0) /* SW reset */
@@ -132,7 +130,6 @@
132#define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */ 130#define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */
133#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ 131#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */
134#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ 132#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */
135#define UFCR_DCEDTE (1<<6) /* DCE/DTE mode select */
136#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ 133#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */
137#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7) 134#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7)
138#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ 135#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */
@@ -170,6 +167,7 @@
170#define SERIAL_IMX_MAJOR 207 167#define SERIAL_IMX_MAJOR 207
171#define MINOR_START 16 168#define MINOR_START 16
172#define DEV_NAME "ttymxc" 169#define DEV_NAME "ttymxc"
170#define MAX_INTERNAL_IRQ MXC_INTERNAL_IRQS
173 171
174/* 172/*
175 * This determines how often we check the modem status signals 173 * This determines how often we check the modem status signals
@@ -205,15 +203,8 @@ struct imx_port {
205 unsigned int irda_inv_rx:1; 203 unsigned int irda_inv_rx:1;
206 unsigned int irda_inv_tx:1; 204 unsigned int irda_inv_tx:1;
207 unsigned short trcv_delay; /* transceiver delay */ 205 unsigned short trcv_delay; /* transceiver delay */
208 struct clk *clk_ipg; 206 struct clk *clk;
209 struct clk *clk_per; 207 struct imx_uart_data *devdata;
210 const struct imx_uart_data *devdata;
211};
212
213struct imx_port_ucrs {
214 unsigned int ucr1;
215 unsigned int ucr2;
216 unsigned int ucr3;
217}; 208};
218 209
219#ifdef CONFIG_IRDA 210#ifdef CONFIG_IRDA
@@ -269,27 +260,6 @@ static inline int is_imx21_uart(struct imx_port *sport)
269} 260}
270 261
271/* 262/*
272 * Save and restore functions for UCR1, UCR2 and UCR3 registers
273 */
274static void imx_port_ucrs_save(struct uart_port *port,
275 struct imx_port_ucrs *ucr)
276{
277 /* save control registers */
278 ucr->ucr1 = readl(port->membase + UCR1);
279 ucr->ucr2 = readl(port->membase + UCR2);
280 ucr->ucr3 = readl(port->membase + UCR3);
281}
282
283static void imx_port_ucrs_restore(struct uart_port *port,
284 struct imx_port_ucrs *ucr)
285{
286 /* restore control registers */
287 writel(ucr->ucr1, port->membase + UCR1);
288 writel(ucr->ucr2, port->membase + UCR2);
289 writel(ucr->ucr3, port->membase + UCR3);
290}
291
292/*
293 * Handle any change of modem status signal since we were last called. 263 * Handle any change of modem status signal since we were last called.
294 */ 264 */
295static void imx_mctrl_check(struct imx_port *sport) 265static void imx_mctrl_check(struct imx_port *sport)
@@ -538,10 +508,8 @@ static irqreturn_t imx_rxint(int irq, void *dev_id)
538 if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx)) 508 if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
539 continue; 509 continue;
540 510
541 if (unlikely(rx & URXD_ERR)) { 511 if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) {
542 if (rx & URXD_BRK) 512 if (rx & URXD_PRERR)
543 sport->port.icount.brk++;
544 else if (rx & URXD_PRERR)
545 sport->port.icount.parity++; 513 sport->port.icount.parity++;
546 else if (rx & URXD_FRMERR) 514 else if (rx & URXD_FRMERR)
547 sport->port.icount.frame++; 515 sport->port.icount.frame++;
@@ -556,9 +524,7 @@ static irqreturn_t imx_rxint(int irq, void *dev_id)
556 524
557 rx &= sport->port.read_status_mask; 525 rx &= sport->port.read_status_mask;
558 526
559 if (rx & URXD_BRK) 527 if (rx & URXD_PRERR)
560 flg = TTY_BREAK;
561 else if (rx & URXD_PRERR)
562 flg = TTY_PARITY; 528 flg = TTY_PARITY;
563 else if (rx & URXD_FRMERR) 529 else if (rx & URXD_FRMERR)
564 flg = TTY_FRAME; 530 flg = TTY_FRAME;
@@ -596,9 +562,6 @@ static irqreturn_t imx_int(int irq, void *dev_id)
596 if (sts & USR1_RTSD) 562 if (sts & USR1_RTSD)
597 imx_rtsint(irq, dev_id); 563 imx_rtsint(irq, dev_id);
598 564
599 if (sts & USR1_AWAKE)
600 writel(USR1_AWAKE, sport->port.membase + USR1);
601
602 return IRQ_HANDLED; 565 return IRQ_HANDLED;
603} 566}
604 567
@@ -668,11 +631,22 @@ static void imx_break_ctl(struct uart_port *port, int break_state)
668static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode) 631static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
669{ 632{
670 unsigned int val; 633 unsigned int val;
634 unsigned int ufcr_rfdiv;
635
636 /* set receiver / transmitter trigger level.
637 * RFDIV is set such way to satisfy requested uartclk value
638 */
639 val = TXTL << 10 | RXTL;
640 ufcr_rfdiv = (clk_get_rate(sport->clk) + sport->port.uartclk / 2)
641 / sport->port.uartclk;
642
643 if(!ufcr_rfdiv)
644 ufcr_rfdiv = 1;
645
646 val |= UFCR_RFDIV_REG(ufcr_rfdiv);
671 647
672 /* set receiver / transmitter trigger level */
673 val = readl(sport->port.membase + UFCR) & (UFCR_RFDIV | UFCR_DCEDTE);
674 val |= TXTL << UFCR_TXTL_SHF | RXTL;
675 writel(val, sport->port.membase + UFCR); 648 writel(val, sport->port.membase + UFCR);
649
676 return 0; 650 return 0;
677} 651}
678 652
@@ -730,7 +704,10 @@ static int imx_startup(struct uart_port *port)
730 704
731 /* do not use RTS IRQ on IrDA */ 705 /* do not use RTS IRQ on IrDA */
732 if (!USE_IRDA(sport)) { 706 if (!USE_IRDA(sport)) {
733 retval = request_irq(sport->rtsirq, imx_rtsint, 0, 707 retval = request_irq(sport->rtsirq, imx_rtsint,
708 (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 :
709 IRQF_TRIGGER_FALLING |
710 IRQF_TRIGGER_RISING,
734 DRIVER_NAME, sport); 711 DRIVER_NAME, sport);
735 if (retval) 712 if (retval)
736 goto error_out3; 713 goto error_out3;
@@ -744,7 +721,6 @@ static int imx_startup(struct uart_port *port)
744 } 721 }
745 } 722 }
746 723
747 spin_lock_irqsave(&sport->port.lock, flags);
748 /* 724 /*
749 * Finally, clear and enable interrupts 725 * Finally, clear and enable interrupts
750 */ 726 */
@@ -798,6 +774,7 @@ static int imx_startup(struct uart_port *port)
798 /* 774 /*
799 * Enable modem status interrupts 775 * Enable modem status interrupts
800 */ 776 */
777 spin_lock_irqsave(&sport->port.lock,flags);
801 imx_enable_ms(&sport->port); 778 imx_enable_ms(&sport->port);
802 spin_unlock_irqrestore(&sport->port.lock,flags); 779 spin_unlock_irqrestore(&sport->port.lock,flags);
803 780
@@ -827,13 +804,10 @@ static void imx_shutdown(struct uart_port *port)
827{ 804{
828 struct imx_port *sport = (struct imx_port *)port; 805 struct imx_port *sport = (struct imx_port *)port;
829 unsigned long temp; 806 unsigned long temp;
830 unsigned long flags;
831 807
832 spin_lock_irqsave(&sport->port.lock, flags);
833 temp = readl(sport->port.membase + UCR2); 808 temp = readl(sport->port.membase + UCR2);
834 temp &= ~(UCR2_TXEN); 809 temp &= ~(UCR2_TXEN);
835 writel(temp, sport->port.membase + UCR2); 810 writel(temp, sport->port.membase + UCR2);
836 spin_unlock_irqrestore(&sport->port.lock, flags);
837 811
838 if (USE_IRDA(sport)) { 812 if (USE_IRDA(sport)) {
839 struct imxuart_platform_data *pdata; 813 struct imxuart_platform_data *pdata;
@@ -862,14 +836,12 @@ static void imx_shutdown(struct uart_port *port)
862 * Disable all interrupts, port and break condition. 836 * Disable all interrupts, port and break condition.
863 */ 837 */
864 838
865 spin_lock_irqsave(&sport->port.lock, flags);
866 temp = readl(sport->port.membase + UCR1); 839 temp = readl(sport->port.membase + UCR1);
867 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); 840 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN);
868 if (USE_IRDA(sport)) 841 if (USE_IRDA(sport))
869 temp &= ~(UCR1_IREN); 842 temp &= ~(UCR1_IREN);
870 843
871 writel(temp, sport->port.membase + UCR1); 844 writel(temp, sport->port.membase + UCR1);
872 spin_unlock_irqrestore(&sport->port.lock, flags);
873} 845}
874 846
875static void 847static void
@@ -925,8 +897,6 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
925 ucr2 |= UCR2_PROE; 897 ucr2 |= UCR2_PROE;
926 } 898 }
927 899
928 del_timer_sync(&sport->timer);
929
930 /* 900 /*
931 * Ask the core to calculate the divisor for us. 901 * Ask the core to calculate the divisor for us.
932 */ 902 */
@@ -957,6 +927,8 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
957 sport->port.ignore_status_mask |= URXD_OVRRUN; 927 sport->port.ignore_status_mask |= URXD_OVRRUN;
958 } 928 }
959 929
930 del_timer_sync(&sport->timer);
931
960 /* 932 /*
961 * Update the per-port timeout. 933 * Update the per-port timeout.
962 */ 934 */
@@ -1103,70 +1075,6 @@ imx_verify_port(struct uart_port *port, struct serial_struct *ser)
1103 return ret; 1075 return ret;
1104} 1076}
1105 1077
1106#if defined(CONFIG_CONSOLE_POLL)
1107static int imx_poll_get_char(struct uart_port *port)
1108{
1109 struct imx_port_ucrs old_ucr;
1110 unsigned int status;
1111 unsigned char c;
1112
1113 /* save control registers */
1114 imx_port_ucrs_save(port, &old_ucr);
1115
1116 /* disable interrupts */
1117 writel(UCR1_UARTEN, port->membase + UCR1);
1118 writel(old_ucr.ucr2 & ~(UCR2_ATEN | UCR2_RTSEN | UCR2_ESCI),
1119 port->membase + UCR2);
1120 writel(old_ucr.ucr3 & ~(UCR3_DCD | UCR3_RI | UCR3_DTREN),
1121 port->membase + UCR3);
1122
1123 /* poll */
1124 do {
1125 status = readl(port->membase + USR2);
1126 } while (~status & USR2_RDR);
1127
1128 /* read */
1129 c = readl(port->membase + URXD0);
1130
1131 /* restore control registers */
1132 imx_port_ucrs_restore(port, &old_ucr);
1133
1134 return c;
1135}
1136
1137static void imx_poll_put_char(struct uart_port *port, unsigned char c)
1138{
1139 struct imx_port_ucrs old_ucr;
1140 unsigned int status;
1141
1142 /* save control registers */
1143 imx_port_ucrs_save(port, &old_ucr);
1144
1145 /* disable interrupts */
1146 writel(UCR1_UARTEN, port->membase + UCR1);
1147 writel(old_ucr.ucr2 & ~(UCR2_ATEN | UCR2_RTSEN | UCR2_ESCI),
1148 port->membase + UCR2);
1149 writel(old_ucr.ucr3 & ~(UCR3_DCD | UCR3_RI | UCR3_DTREN),
1150 port->membase + UCR3);
1151
1152 /* drain */
1153 do {
1154 status = readl(port->membase + USR1);
1155 } while (~status & USR1_TRDY);
1156
1157 /* write */
1158 writel(c, port->membase + URTX0);
1159
1160 /* flush */
1161 do {
1162 status = readl(port->membase + USR2);
1163 } while (~status & USR2_TXDC);
1164
1165 /* restore control registers */
1166 imx_port_ucrs_restore(port, &old_ucr);
1167}
1168#endif
1169
1170static struct uart_ops imx_pops = { 1078static struct uart_ops imx_pops = {
1171 .tx_empty = imx_tx_empty, 1079 .tx_empty = imx_tx_empty,
1172 .set_mctrl = imx_set_mctrl, 1080 .set_mctrl = imx_set_mctrl,
@@ -1184,10 +1092,6 @@ static struct uart_ops imx_pops = {
1184 .request_port = imx_request_port, 1092 .request_port = imx_request_port,
1185 .config_port = imx_config_port, 1093 .config_port = imx_config_port,
1186 .verify_port = imx_verify_port, 1094 .verify_port = imx_verify_port,
1187#if defined(CONFIG_CONSOLE_POLL)
1188 .poll_get_char = imx_poll_get_char,
1189 .poll_put_char = imx_poll_put_char,
1190#endif
1191}; 1095};
1192 1096
1193static struct imx_port *imx_ports[UART_NR]; 1097static struct imx_port *imx_ports[UART_NR];
@@ -1210,17 +1114,13 @@ static void
1210imx_console_write(struct console *co, const char *s, unsigned int count) 1114imx_console_write(struct console *co, const char *s, unsigned int count)
1211{ 1115{
1212 struct imx_port *sport = imx_ports[co->index]; 1116 struct imx_port *sport = imx_ports[co->index];
1213 struct imx_port_ucrs old_ucr; 1117 unsigned int old_ucr1, old_ucr2, ucr1;
1214 unsigned int ucr1;
1215 unsigned long flags;
1216
1217 spin_lock_irqsave(&sport->port.lock, flags);
1218 1118
1219 /* 1119 /*
1220 * First, save UCR1/2/3 and then disable interrupts 1120 * First, save UCR1/2 and then disable interrupts
1221 */ 1121 */
1222 imx_port_ucrs_save(&sport->port, &old_ucr); 1122 ucr1 = old_ucr1 = readl(sport->port.membase + UCR1);
1223 ucr1 = old_ucr.ucr1; 1123 old_ucr2 = readl(sport->port.membase + UCR2);
1224 1124
1225 if (is_imx1_uart(sport)) 1125 if (is_imx1_uart(sport))
1226 ucr1 |= IMX1_UCR1_UARTCLKEN; 1126 ucr1 |= IMX1_UCR1_UARTCLKEN;
@@ -1229,19 +1129,18 @@ imx_console_write(struct console *co, const char *s, unsigned int count)
1229 1129
1230 writel(ucr1, sport->port.membase + UCR1); 1130 writel(ucr1, sport->port.membase + UCR1);
1231 1131
1232 writel(old_ucr.ucr2 | UCR2_TXEN, sport->port.membase + UCR2); 1132 writel(old_ucr2 | UCR2_TXEN, sport->port.membase + UCR2);
1233 1133
1234 uart_console_write(&sport->port, s, count, imx_console_putchar); 1134 uart_console_write(&sport->port, s, count, imx_console_putchar);
1235 1135
1236 /* 1136 /*
1237 * Finally, wait for transmitter to become empty 1137 * Finally, wait for transmitter to become empty
1238 * and restore UCR1/2/3 1138 * and restore UCR1/2
1239 */ 1139 */
1240 while (!(readl(sport->port.membase + USR2) & USR2_TXDC)); 1140 while (!(readl(sport->port.membase + USR2) & USR2_TXDC));
1241 1141
1242 imx_port_ucrs_restore(&sport->port, &old_ucr); 1142 writel(old_ucr1, sport->port.membase + UCR1);
1243 1143 writel(old_ucr2, sport->port.membase + UCR2);
1244 spin_unlock_irqrestore(&sport->port.lock, flags);
1245} 1144}
1246 1145
1247/* 1146/*
@@ -1283,7 +1182,7 @@ imx_console_get_options(struct imx_port *sport, int *baud,
1283 else 1182 else
1284 ucfr_rfdiv = 6 - ucfr_rfdiv; 1183 ucfr_rfdiv = 6 - ucfr_rfdiv;
1285 1184
1286 uartclk = clk_get_rate(sport->clk_per); 1185 uartclk = clk_get_rate(sport->clk);
1287 uartclk /= ucfr_rfdiv; 1186 uartclk /= ucfr_rfdiv;
1288 1187
1289 { /* 1188 { /*
@@ -1366,14 +1265,9 @@ static struct uart_driver imx_reg = {
1366static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) 1265static int serial_imx_suspend(struct platform_device *dev, pm_message_t state)
1367{ 1266{
1368 struct imx_port *sport = platform_get_drvdata(dev); 1267 struct imx_port *sport = platform_get_drvdata(dev);
1369 unsigned int val;
1370
1371 /* enable wakeup from i.MX UART */
1372 val = readl(sport->port.membase + UCR3);
1373 val |= UCR3_AWAKEN;
1374 writel(val, sport->port.membase + UCR3);
1375 1268
1376 uart_suspend_port(&imx_reg, &sport->port); 1269 if (sport)
1270 uart_suspend_port(&imx_reg, &sport->port);
1377 1271
1378 return 0; 1272 return 0;
1379} 1273}
@@ -1381,41 +1275,28 @@ static int serial_imx_suspend(struct platform_device *dev, pm_message_t state)
1381static int serial_imx_resume(struct platform_device *dev) 1275static int serial_imx_resume(struct platform_device *dev)
1382{ 1276{
1383 struct imx_port *sport = platform_get_drvdata(dev); 1277 struct imx_port *sport = platform_get_drvdata(dev);
1384 unsigned int val;
1385
1386 /* disable wakeup from i.MX UART */
1387 val = readl(sport->port.membase + UCR3);
1388 val &= ~UCR3_AWAKEN;
1389 writel(val, sport->port.membase + UCR3);
1390 1278
1391 uart_resume_port(&imx_reg, &sport->port); 1279 if (sport)
1280 uart_resume_port(&imx_reg, &sport->port);
1392 1281
1393 return 0; 1282 return 0;
1394} 1283}
1395 1284
1396#ifdef CONFIG_OF 1285#ifdef CONFIG_OF
1397/*
1398 * This function returns 1 iff pdev isn't a device instatiated by dt, 0 iff it
1399 * could successfully get all information from dt or a negative errno.
1400 */
1401static int serial_imx_probe_dt(struct imx_port *sport, 1286static int serial_imx_probe_dt(struct imx_port *sport,
1402 struct platform_device *pdev) 1287 struct platform_device *pdev)
1403{ 1288{
1289 static int portnum = 0;
1404 struct device_node *np = pdev->dev.of_node; 1290 struct device_node *np = pdev->dev.of_node;
1405 const struct of_device_id *of_id = 1291 const struct of_device_id *of_id =
1406 of_match_device(imx_uart_dt_ids, &pdev->dev); 1292 of_match_device(imx_uart_dt_ids, &pdev->dev);
1407 int ret;
1408 1293
1409 if (!np) 1294 if (!np)
1410 /* no device tree device */ 1295 return -ENODEV;
1411 return 1;
1412 1296
1413 ret = of_alias_get_id(np, "serial"); 1297 sport->port.line = portnum++;
1414 if (ret < 0) { 1298 if (sport->port.line >= UART_NR)
1415 dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); 1299 return -EINVAL;
1416 return ret;
1417 }
1418 sport->port.line = ret;
1419 1300
1420 if (of_get_property(np, "fsl,uart-has-rtscts", NULL)) 1301 if (of_get_property(np, "fsl,uart-has-rtscts", NULL))
1421 sport->have_rtscts = 1; 1302 sport->have_rtscts = 1;
@@ -1431,7 +1312,7 @@ static int serial_imx_probe_dt(struct imx_port *sport,
1431static inline int serial_imx_probe_dt(struct imx_port *sport, 1312static inline int serial_imx_probe_dt(struct imx_port *sport,
1432 struct platform_device *pdev) 1313 struct platform_device *pdev)
1433{ 1314{
1434 return 1; 1315 return -ENODEV;
1435} 1316}
1436#endif 1317#endif
1437 1318
@@ -1460,17 +1341,14 @@ static int serial_imx_probe(struct platform_device *pdev)
1460 void __iomem *base; 1341 void __iomem *base;
1461 int ret = 0; 1342 int ret = 0;
1462 struct resource *res; 1343 struct resource *res;
1463 struct pinctrl *pinctrl;
1464 1344
1465 sport = kzalloc(sizeof(*sport), GFP_KERNEL); 1345 sport = kzalloc(sizeof(*sport), GFP_KERNEL);
1466 if (!sport) 1346 if (!sport)
1467 return -ENOMEM; 1347 return -ENOMEM;
1468 1348
1469 ret = serial_imx_probe_dt(sport, pdev); 1349 ret = serial_imx_probe_dt(sport, pdev);
1470 if (ret > 0) 1350 if (ret == -ENODEV)
1471 serial_imx_probe_pdata(sport, pdev); 1351 serial_imx_probe_pdata(sport, pdev);
1472 else if (ret < 0)
1473 goto free;
1474 1352
1475 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1353 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1476 if (!res) { 1354 if (!res) {
@@ -1500,31 +1378,14 @@ static int serial_imx_probe(struct platform_device *pdev)
1500 sport->timer.function = imx_timeout; 1378 sport->timer.function = imx_timeout;
1501 sport->timer.data = (unsigned long)sport; 1379 sport->timer.data = (unsigned long)sport;
1502 1380
1503 pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 1381 sport->clk = clk_get(&pdev->dev, "uart");
1504 if (IS_ERR(pinctrl)) { 1382 if (IS_ERR(sport->clk)) {
1505 ret = PTR_ERR(pinctrl); 1383 ret = PTR_ERR(sport->clk);
1506 dev_err(&pdev->dev, "failed to get default pinctrl: %d\n", ret);
1507 goto unmap; 1384 goto unmap;
1508 } 1385 }
1386 clk_enable(sport->clk);
1509 1387
1510 sport->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); 1388 sport->port.uartclk = clk_get_rate(sport->clk);
1511 if (IS_ERR(sport->clk_ipg)) {
1512 ret = PTR_ERR(sport->clk_ipg);
1513 dev_err(&pdev->dev, "failed to get ipg clk: %d\n", ret);
1514 goto unmap;
1515 }
1516
1517 sport->clk_per = devm_clk_get(&pdev->dev, "per");
1518 if (IS_ERR(sport->clk_per)) {
1519 ret = PTR_ERR(sport->clk_per);
1520 dev_err(&pdev->dev, "failed to get per clk: %d\n", ret);
1521 goto unmap;
1522 }
1523
1524 clk_prepare_enable(sport->clk_per);
1525 clk_prepare_enable(sport->clk_ipg);
1526
1527 sport->port.uartclk = clk_get_rate(sport->clk_per);
1528 1389
1529 imx_ports[sport->port.line] = sport; 1390 imx_ports[sport->port.line] = sport;
1530 1391
@@ -1538,15 +1399,15 @@ static int serial_imx_probe(struct platform_device *pdev)
1538 ret = uart_add_one_port(&imx_reg, &sport->port); 1399 ret = uart_add_one_port(&imx_reg, &sport->port);
1539 if (ret) 1400 if (ret)
1540 goto deinit; 1401 goto deinit;
1541 platform_set_drvdata(pdev, sport); 1402 platform_set_drvdata(pdev, &sport->port);
1542 1403
1543 return 0; 1404 return 0;
1544deinit: 1405deinit:
1545 if (pdata && pdata->exit) 1406 if (pdata && pdata->exit)
1546 pdata->exit(pdev); 1407 pdata->exit(pdev);
1547clkput: 1408clkput:
1548 clk_disable_unprepare(sport->clk_per); 1409 clk_put(sport->clk);
1549 clk_disable_unprepare(sport->clk_ipg); 1410 clk_disable(sport->clk);
1550unmap: 1411unmap:
1551 iounmap(sport->port.membase); 1412 iounmap(sport->port.membase);
1552free: 1413free:
@@ -1564,10 +1425,12 @@ static int serial_imx_remove(struct platform_device *pdev)
1564 1425
1565 platform_set_drvdata(pdev, NULL); 1426 platform_set_drvdata(pdev, NULL);
1566 1427
1567 uart_remove_one_port(&imx_reg, &sport->port); 1428 if (sport) {
1429 uart_remove_one_port(&imx_reg, &sport->port);
1430 clk_put(sport->clk);
1431 }
1568 1432
1569 clk_disable_unprepare(sport->clk_per); 1433 clk_disable(sport->clk);
1570 clk_disable_unprepare(sport->clk_ipg);
1571 1434
1572 if (pdata && pdata->exit) 1435 if (pdata && pdata->exit)
1573 pdata->exit(pdev); 1436 pdata->exit(pdev);
@@ -1606,7 +1469,7 @@ static int __init imx_serial_init(void)
1606 if (ret != 0) 1469 if (ret != 0)
1607 uart_unregister_driver(&imx_reg); 1470 uart_unregister_driver(&imx_reg);
1608 1471
1609 return ret; 1472 return 0;
1610} 1473}
1611 1474
1612static void __exit imx_serial_exit(void) 1475static void __exit imx_serial_exit(void)
diff --git a/drivers/tty/serial/ioc3_serial.c b/drivers/tty/serial/ioc3_serial.c
index d8f1d1d5447..ee43efc7bdc 100644
--- a/drivers/tty/serial/ioc3_serial.c
+++ b/drivers/tty/serial/ioc3_serial.c
@@ -13,7 +13,6 @@
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>
17#include <linux/serial.h> 16#include <linux/serial.h>
18#include <linux/circ_buf.h> 17#include <linux/circ_buf.h>
19#include <linux/serial_reg.h> 18#include <linux/serial_reg.h>
@@ -1120,14 +1119,13 @@ static inline int do_read(struct uart_port *the_port, char *buf, int len)
1120 struct ioc3_port *port = get_ioc3_port(the_port); 1119 struct ioc3_port *port = get_ioc3_port(the_port);
1121 struct ring *inring; 1120 struct ring *inring;
1122 struct ring_entry *entry; 1121 struct ring_entry *entry;
1123 struct port_hooks *hooks; 1122 struct port_hooks *hooks = port->ip_hooks;
1124 int byte_num; 1123 int byte_num;
1125 char *sc; 1124 char *sc;
1126 int loop_counter; 1125 int loop_counter;
1127 1126
1128 BUG_ON(!(len >= 0)); 1127 BUG_ON(!(len >= 0));
1129 BUG_ON(!port); 1128 BUG_ON(!port);
1130 hooks = port->ip_hooks;
1131 1129
1132 /* There is a nasty timing issue in the IOC3. When the rx_timer 1130 /* There is a nasty timing issue in the IOC3. When the rx_timer
1133 * expires or the rx_high condition arises, we take an interrupt. 1131 * expires or the rx_high condition arises, we take an interrupt.
@@ -2010,7 +2008,7 @@ static int ioc3uart_remove(struct ioc3_submodule *is,
2010 * @idd: ioc3 driver data for this card 2008 * @idd: ioc3 driver data for this card
2011 */ 2009 */
2012 2010
2013static int 2011static int __devinit
2014ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd) 2012ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2015{ 2013{
2016 struct pci_dev *pdev = idd->pdev; 2014 struct pci_dev *pdev = idd->pdev;
diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
index 3e7da10cebb..fcfe82653ac 100644
--- a/drivers/tty/serial/ioc4_serial.c
+++ b/drivers/tty/serial/ioc4_serial.c
@@ -14,8 +14,8 @@
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>
18#include <linux/serial.h> 17#include <linux/serial.h>
18#include <linux/serialP.h>
19#include <linux/circ_buf.h> 19#include <linux/circ_buf.h>
20#include <linux/serial_reg.h> 20#include <linux/serial_reg.h>
21#include <linux/module.h> 21#include <linux/module.h>
@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
974 BUG_ON(!((type == IOC4_SIO_INTR_TYPE) 974 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
975 || (type == IOC4_OTHER_INTR_TYPE))); 975 || (type == IOC4_OTHER_INTR_TYPE)));
976 976
977 i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1; 977 i = atomic_inc(&soft-> is_intr_type[type].is_num_intrs) - 1;
978 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0))); 978 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
979 979
980 /* Save off the lower level interrupt handler */ 980 /* Save off the lower level interrupt handler */
@@ -1803,7 +1803,7 @@ static inline int ic4_startup_local(struct uart_port *the_port)
1803 ioc4_set_proto(port, the_port->mapbase); 1803 ioc4_set_proto(port, the_port->mapbase);
1804 1804
1805 /* set the speed of the serial port */ 1805 /* set the speed of the serial port */
1806 ioc4_change_speed(the_port, &state->port.tty->termios, 1806 ioc4_change_speed(the_port, state->port.tty->termios,
1807 (struct ktermios *)0); 1807 (struct ktermios *)0);
1808 1808
1809 return 0; 1809 return 0;
@@ -2069,14 +2069,13 @@ static inline int do_read(struct uart_port *the_port, unsigned char *buf,
2069 struct ioc4_port *port = get_ioc4_port(the_port, 0); 2069 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2070 struct ring *inring; 2070 struct ring *inring;
2071 struct ring_entry *entry; 2071 struct ring_entry *entry;
2072 struct hooks *hooks; 2072 struct hooks *hooks = port->ip_hooks;
2073 int byte_num; 2073 int byte_num;
2074 char *sc; 2074 char *sc;
2075 int loop_counter; 2075 int loop_counter;
2076 2076
2077 BUG_ON(!(len >= 0)); 2077 BUG_ON(!(len >= 0));
2078 BUG_ON(!port); 2078 BUG_ON(!port);
2079 hooks = port->ip_hooks;
2080 2079
2081 /* There is a nasty timing issue in the IOC4. When the rx_timer 2080 /* There is a nasty timing issue in the IOC4. When the rx_timer
2082 * expires or the rx_high condition arises, we take an interrupt. 2081 * expires or the rx_high condition arises, we take an interrupt.
diff --git a/drivers/tty/serial/jsm/jsm.h b/drivers/tty/serial/jsm/jsm.h
index 844d5e4eb1a..5b837e749c1 100644
--- a/drivers/tty/serial/jsm/jsm.h
+++ b/drivers/tty/serial/jsm/jsm.h
@@ -57,11 +57,9 @@ enum {
57 DBG_CARR = 0x10000, 57 DBG_CARR = 0x10000,
58}; 58};
59 59
60#define jsm_dbg(nlevel, pdev, fmt, ...) \ 60#define jsm_printk(nlevel, klevel, pdev, fmt, args...) \
61do { \ 61 if ((DBG_##nlevel & jsm_debug)) \
62 if (DBG_##nlevel & jsm_debug) \ 62 dev_printk(KERN_##klevel, pdev->dev, fmt, ## args)
63 dev_dbg(pdev->dev, fmt, ##__VA_ARGS__); \
64} while (0)
65 63
66#define MAXLINES 256 64#define MAXLINES 256
67#define MAXPORTS 8 65#define MAXPORTS 8
@@ -90,6 +88,7 @@ do { \
90 88
91/* 4 extra for alignment play space */ 89/* 4 extra for alignment play space */
92#define WRITEBUFLEN ((4096) + 4) 90#define WRITEBUFLEN ((4096) + 4)
91#define MYFLIPLEN N_TTY_BUF_SIZE
93 92
94#define JSM_VERSION "jsm: 1.2-1-INKERNEL" 93#define JSM_VERSION "jsm: 1.2-1-INKERNEL"
95#define JSM_PARTNUM "40002438_A-INKERNEL" 94#define JSM_PARTNUM "40002438_A-INKERNEL"
@@ -151,6 +150,7 @@ struct jsm_board
151 u32 bd_uart_offset; /* Space between each UART */ 150 u32 bd_uart_offset; /* Space between each UART */
152 151
153 struct jsm_channel *channels[MAXPORTS]; /* array of pointers to our channels. */ 152 struct jsm_channel *channels[MAXPORTS]; /* array of pointers to our channels. */
153 char *flipbuf; /* Our flip buffer, alloced if board is found */
154 154
155 u32 bd_dividend; /* Board/UARTs specific dividend */ 155 u32 bd_dividend; /* Board/UARTs specific dividend */
156 156
@@ -177,6 +177,7 @@ struct jsm_board
177#define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */ 177#define CH_TX_FIFO_LWM 0x0800 /* TX Fifo is below Low Water */
178#define CH_BREAK_SENDING 0x1000 /* Break is being sent */ 178#define CH_BREAK_SENDING 0x1000 /* Break is being sent */
179#define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */ 179#define CH_LOOPBACK 0x2000 /* Channel is in lookback mode */
180#define CH_FLIPBUF_IN_USE 0x4000 /* Channel's flipbuf is in use */
180#define CH_BAUD0 0x08000 /* Used for checking B0 transitions */ 181#define CH_BAUD0 0x08000 /* Used for checking B0 transitions */
181 182
182/* Our Read/Error/Write queue sizes */ 183/* Our Read/Error/Write queue sizes */
diff --git a/drivers/tty/serial/jsm/jsm_driver.c b/drivers/tty/serial/jsm/jsm_driver.c
index a47d882d674..6c12d94e6d3 100644
--- a/drivers/tty/serial/jsm/jsm_driver.c
+++ b/drivers/tty/serial/jsm/jsm_driver.c
@@ -24,7 +24,7 @@
24 * 24 *
25 * 25 *
26 ***********************************************************************/ 26 ***********************************************************************/
27#include <linux/module.h> 27#include <linux/moduleparam.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
@@ -54,7 +54,7 @@ static pci_ers_result_t jsm_io_error_detected(struct pci_dev *pdev,
54static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev); 54static pci_ers_result_t jsm_io_slot_reset(struct pci_dev *pdev);
55static void jsm_io_resume(struct pci_dev *pdev); 55static void jsm_io_resume(struct pci_dev *pdev);
56 56
57static const struct pci_error_handlers jsm_err_handler = { 57static struct pci_error_handlers jsm_err_handler = {
58 .error_detected = jsm_io_error_detected, 58 .error_detected = jsm_io_error_detected,
59 .slot_reset = jsm_io_slot_reset, 59 .slot_reset = jsm_io_slot_reset,
60 .resume = jsm_io_resume, 60 .resume = jsm_io_resume,
@@ -64,7 +64,7 @@ int jsm_debug;
64module_param(jsm_debug, int, 0); 64module_param(jsm_debug, int, 0);
65MODULE_PARM_DESC(jsm_debug, "Driver debugging level"); 65MODULE_PARM_DESC(jsm_debug, "Driver debugging level");
66 66
67static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent) 67static int __devinit jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
68{ 68{
69 int rc = 0; 69 int rc = 0;
70 struct jsm_board *brd; 70 struct jsm_board *brd;
@@ -107,7 +107,8 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
107 107
108 brd->irq = pdev->irq; 108 brd->irq = pdev->irq;
109 109
110 jsm_dbg(INIT, &brd->pci_dev, "jsm_found_board - NEO adapter\n"); 110 jsm_printk(INIT, INFO, &brd->pci_dev,
111 "jsm_found_board - NEO adapter\n");
111 112
112 /* get the PCI Base Address Registers */ 113 /* get the PCI Base Address Registers */
113 brd->membase = pci_resource_start(pdev, 0); 114 brd->membase = pci_resource_start(pdev, 0);
@@ -159,10 +160,27 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
159 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",
160 adapter_count, brd->rev, brd->irq); 161 adapter_count, brd->rev, brd->irq);
161 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
162 pci_set_drvdata(pdev, brd); 178 pci_set_drvdata(pdev, brd);
163 pci_save_state(pdev); 179 pci_save_state(pdev);
164 180
165 return 0; 181 return 0;
182 out_free_uart:
183 jsm_remove_uart_port(brd);
166 out_free_irq: 184 out_free_irq:
167 jsm_remove_uart_port(brd); 185 jsm_remove_uart_port(brd);
168 free_irq(brd->irq, brd); 186 free_irq(brd->irq, brd);
@@ -178,7 +196,7 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
178 return rc; 196 return rc;
179} 197}
180 198
181static void jsm_remove_one(struct pci_dev *pdev) 199static void __devexit jsm_remove_one(struct pci_dev *pdev)
182{ 200{
183 struct jsm_board *brd = pci_get_drvdata(pdev); 201 struct jsm_board *brd = pci_get_drvdata(pdev);
184 int i = 0; 202 int i = 0;
@@ -199,6 +217,7 @@ static void jsm_remove_one(struct pci_dev *pdev)
199 217
200 pci_release_regions(pdev); 218 pci_release_regions(pdev);
201 pci_disable_device(pdev); 219 pci_disable_device(pdev);
220 kfree(brd->flipbuf);
202 kfree(brd); 221 kfree(brd);
203} 222}
204 223
@@ -217,7 +236,7 @@ static struct pci_driver jsm_driver = {
217 .name = "jsm", 236 .name = "jsm",
218 .id_table = jsm_pci_tbl, 237 .id_table = jsm_pci_tbl,
219 .probe = jsm_probe_one, 238 .probe = jsm_probe_one,
220 .remove = jsm_remove_one, 239 .remove = __devexit_p(jsm_remove_one),
221 .err_handler = &jsm_err_handler, 240 .err_handler = &jsm_err_handler,
222}; 241};
223 242
diff --git a/drivers/tty/serial/jsm/jsm_neo.c b/drivers/tty/serial/jsm/jsm_neo.c
index dfaf4882641..bd6e84699e1 100644
--- a/drivers/tty/serial/jsm/jsm_neo.c
+++ b/drivers/tty/serial/jsm/jsm_neo.c
@@ -52,7 +52,7 @@ static void neo_set_cts_flow_control(struct jsm_channel *ch)
52 ier = readb(&ch->ch_neo_uart->ier); 52 ier = readb(&ch->ch_neo_uart->ier);
53 efr = readb(&ch->ch_neo_uart->efr); 53 efr = readb(&ch->ch_neo_uart->efr);
54 54
55 jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting CTSFLOW\n"); 55 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting CTSFLOW\n");
56 56
57 /* Turn on auto CTS flow control */ 57 /* Turn on auto CTS flow control */
58 ier |= (UART_17158_IER_CTSDSR); 58 ier |= (UART_17158_IER_CTSDSR);
@@ -83,7 +83,7 @@ static void neo_set_rts_flow_control(struct jsm_channel *ch)
83 ier = readb(&ch->ch_neo_uart->ier); 83 ier = readb(&ch->ch_neo_uart->ier);
84 efr = readb(&ch->ch_neo_uart->efr); 84 efr = readb(&ch->ch_neo_uart->efr);
85 85
86 jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting RTSFLOW\n"); 86 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting RTSFLOW\n");
87 87
88 /* Turn on auto RTS flow control */ 88 /* Turn on auto RTS flow control */
89 ier |= (UART_17158_IER_RTSDTR); 89 ier |= (UART_17158_IER_RTSDTR);
@@ -123,7 +123,7 @@ static void neo_set_ixon_flow_control(struct jsm_channel *ch)
123 ier = readb(&ch->ch_neo_uart->ier); 123 ier = readb(&ch->ch_neo_uart->ier);
124 efr = readb(&ch->ch_neo_uart->efr); 124 efr = readb(&ch->ch_neo_uart->efr);
125 125
126 jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting IXON FLOW\n"); 126 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting IXON FLOW\n");
127 127
128 /* Turn off auto CTS flow control */ 128 /* Turn off auto CTS flow control */
129 ier &= ~(UART_17158_IER_CTSDSR); 129 ier &= ~(UART_17158_IER_CTSDSR);
@@ -160,7 +160,7 @@ static void neo_set_ixoff_flow_control(struct jsm_channel *ch)
160 ier = readb(&ch->ch_neo_uart->ier); 160 ier = readb(&ch->ch_neo_uart->ier);
161 efr = readb(&ch->ch_neo_uart->efr); 161 efr = readb(&ch->ch_neo_uart->efr);
162 162
163 jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Setting IXOFF FLOW\n"); 163 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting IXOFF FLOW\n");
164 164
165 /* Turn off auto RTS flow control */ 165 /* Turn off auto RTS flow control */
166 ier &= ~(UART_17158_IER_RTSDTR); 166 ier &= ~(UART_17158_IER_RTSDTR);
@@ -198,7 +198,7 @@ static void neo_set_no_input_flow_control(struct jsm_channel *ch)
198 ier = readb(&ch->ch_neo_uart->ier); 198 ier = readb(&ch->ch_neo_uart->ier);
199 efr = readb(&ch->ch_neo_uart->efr); 199 efr = readb(&ch->ch_neo_uart->efr);
200 200
201 jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Unsetting Input FLOW\n"); 201 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Unsetting Input FLOW\n");
202 202
203 /* Turn off auto RTS flow control */ 203 /* Turn off auto RTS flow control */
204 ier &= ~(UART_17158_IER_RTSDTR); 204 ier &= ~(UART_17158_IER_RTSDTR);
@@ -237,7 +237,7 @@ static void neo_set_no_output_flow_control(struct jsm_channel *ch)
237 ier = readb(&ch->ch_neo_uart->ier); 237 ier = readb(&ch->ch_neo_uart->ier);
238 efr = readb(&ch->ch_neo_uart->efr); 238 efr = readb(&ch->ch_neo_uart->efr);
239 239
240 jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "Unsetting Output FLOW\n"); 240 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Unsetting Output FLOW\n");
241 241
242 /* Turn off auto CTS flow control */ 242 /* Turn off auto CTS flow control */
243 ier &= ~(UART_17158_IER_CTSDSR); 243 ier &= ~(UART_17158_IER_CTSDSR);
@@ -276,7 +276,7 @@ static inline void neo_set_new_start_stop_chars(struct jsm_channel *ch)
276 if (ch->ch_c_cflag & CRTSCTS) 276 if (ch->ch_c_cflag & CRTSCTS)
277 return; 277 return;
278 278
279 jsm_dbg(PARAM, &ch->ch_bd->pci_dev, "start\n"); 279 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "start\n");
280 280
281 /* Tell UART what start/stop chars it should be looking for */ 281 /* Tell UART what start/stop chars it should be looking for */
282 writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1); 282 writeb(ch->ch_startc, &ch->ch_neo_uart->xonchar1);
@@ -455,7 +455,7 @@ static void neo_copy_data_from_uart_to_queue(struct jsm_channel *ch)
455 * I hope thats okay with everyone? Yes? Good. 455 * I hope thats okay with everyone? Yes? Good.
456 */ 456 */
457 while (qleft < 1) { 457 while (qleft < 1) {
458 jsm_dbg(READ, &ch->ch_bd->pci_dev, 458 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
459 "Queue full, dropping DATA:%x LSR:%x\n", 459 "Queue full, dropping DATA:%x LSR:%x\n",
460 ch->ch_rqueue[tail], ch->ch_equeue[tail]); 460 ch->ch_rqueue[tail], ch->ch_equeue[tail]);
461 461
@@ -467,8 +467,8 @@ static void neo_copy_data_from_uart_to_queue(struct jsm_channel *ch)
467 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1); 467 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
468 ch->ch_equeue[head] = (u8) linestatus; 468 ch->ch_equeue[head] = (u8) linestatus;
469 469
470 jsm_dbg(READ, &ch->ch_bd->pci_dev, "DATA/LSR pair: %x %x\n", 470 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
471 ch->ch_rqueue[head], ch->ch_equeue[head]); 471 "DATA/LSR pair: %x %x\n", ch->ch_rqueue[head], ch->ch_equeue[head]);
472 472
473 /* Ditch any remaining linestatus value. */ 473 /* Ditch any remaining linestatus value. */
474 linestatus = 0; 474 linestatus = 0;
@@ -521,8 +521,8 @@ static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)
521 ch->ch_cached_lsr &= ~(UART_LSR_THRE); 521 ch->ch_cached_lsr &= ~(UART_LSR_THRE);
522 522
523 writeb(circ->buf[circ->tail], &ch->ch_neo_uart->txrx); 523 writeb(circ->buf[circ->tail], &ch->ch_neo_uart->txrx);
524 jsm_dbg(WRITE, &ch->ch_bd->pci_dev, 524 jsm_printk(WRITE, INFO, &ch->ch_bd->pci_dev,
525 "Tx data: %x\n", circ->buf[circ->tail]); 525 "Tx data: %x\n", circ->buf[circ->head]);
526 circ->tail = (circ->tail + 1) & (UART_XMIT_SIZE - 1); 526 circ->tail = (circ->tail + 1) & (UART_XMIT_SIZE - 1);
527 ch->ch_txcount++; 527 ch->ch_txcount++;
528 } 528 }
@@ -575,9 +575,8 @@ static void neo_parse_modem(struct jsm_channel *ch, u8 signals)
575{ 575{
576 u8 msignals = signals; 576 u8 msignals = signals;
577 577
578 jsm_dbg(MSIGS, &ch->ch_bd->pci_dev, 578 jsm_printk(MSIGS, INFO, &ch->ch_bd->pci_dev,
579 "neo_parse_modem: port: %d msignals: %x\n", 579 "neo_parse_modem: port: %d msignals: %x\n", ch->ch_portnum, msignals);
580 ch->ch_portnum, msignals);
581 580
582 /* Scrub off lower bits. They signify delta's, which I don't care about */ 581 /* Scrub off lower bits. They signify delta's, which I don't care about */
583 /* Keep DDCD and DDSR though */ 582 /* Keep DDCD and DDSR though */
@@ -607,8 +606,8 @@ static void neo_parse_modem(struct jsm_channel *ch, u8 signals)
607 else 606 else
608 ch->ch_mistat &= ~UART_MSR_CTS; 607 ch->ch_mistat &= ~UART_MSR_CTS;
609 608
610 jsm_dbg(MSIGS, &ch->ch_bd->pci_dev, 609 jsm_printk(MSIGS, INFO, &ch->ch_bd->pci_dev,
611 "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n", 610 "Port: %d DTR: %d RTS: %d CTS: %d DSR: %d " "RI: %d CD: %d\n",
612 ch->ch_portnum, 611 ch->ch_portnum,
613 !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR), 612 !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_DTR),
614 !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS), 613 !!((ch->ch_mistat | ch->ch_mostat) & UART_MCR_RTS),
@@ -650,8 +649,8 @@ static void neo_flush_uart_write(struct jsm_channel *ch)
650 /* Check to see if the UART feels it completely flushed the FIFO. */ 649 /* Check to see if the UART feels it completely flushed the FIFO. */
651 tmp = readb(&ch->ch_neo_uart->isr_fcr); 650 tmp = readb(&ch->ch_neo_uart->isr_fcr);
652 if (tmp & 4) { 651 if (tmp & 4) {
653 jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, 652 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
654 "Still flushing TX UART... i: %d\n", i); 653 "Still flushing TX UART... i: %d\n", i);
655 udelay(10); 654 udelay(10);
656 } 655 }
657 else 656 else
@@ -682,8 +681,8 @@ static void neo_flush_uart_read(struct jsm_channel *ch)
682 /* Check to see if the UART feels it completely flushed the FIFO. */ 681 /* Check to see if the UART feels it completely flushed the FIFO. */
683 tmp = readb(&ch->ch_neo_uart->isr_fcr); 682 tmp = readb(&ch->ch_neo_uart->isr_fcr);
684 if (tmp & 2) { 683 if (tmp & 2) {
685 jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, 684 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
686 "Still flushing RX UART... i: %d\n", i); 685 "Still flushing RX UART... i: %d\n", i);
687 udelay(10); 686 udelay(10);
688 } 687 }
689 else 688 else
@@ -706,9 +705,8 @@ static void neo_clear_break(struct jsm_channel *ch, int force)
706 writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr); 705 writeb((temp & ~UART_LCR_SBC), &ch->ch_neo_uart->lcr);
707 706
708 ch->ch_flags &= ~(CH_BREAK_SENDING); 707 ch->ch_flags &= ~(CH_BREAK_SENDING);
709 jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, 708 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev,
710 "clear break Finishing UART_LCR_SBC! finished: %lx\n", 709 "clear break Finishing UART_LCR_SBC! finished: %lx\n", jiffies);
711 jiffies);
712 710
713 /* flush write operation */ 711 /* flush write operation */
714 neo_pci_posting_flush(ch->ch_bd); 712 neo_pci_posting_flush(ch->ch_bd);
@@ -750,8 +748,8 @@ static inline void neo_parse_isr(struct jsm_board *brd, u32 port)
750 */ 748 */
751 isr &= ~(UART_17158_IIR_FIFO_ENABLED); 749 isr &= ~(UART_17158_IIR_FIFO_ENABLED);
752 750
753 jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d isr: %x\n", 751 jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
754 __FILE__, __LINE__, isr); 752 "%s:%d isr: %x\n", __FILE__, __LINE__, isr);
755 753
756 if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) { 754 if (isr & (UART_17158_IIR_RDI_TIMEOUT | UART_IIR_RDI)) {
757 /* Read data from uart -> queue */ 755 /* Read data from uart -> queue */
@@ -774,9 +772,8 @@ static inline void neo_parse_isr(struct jsm_board *brd, u32 port)
774 if (isr & UART_17158_IIR_XONXOFF) { 772 if (isr & UART_17158_IIR_XONXOFF) {
775 cause = readb(&ch->ch_neo_uart->xoffchar1); 773 cause = readb(&ch->ch_neo_uart->xoffchar1);
776 774
777 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 775 jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
778 "Port %d. Got ISR_XONXOFF: cause:%x\n", 776 "Port %d. Got ISR_XONXOFF: cause:%x\n", port, cause);
779 port, cause);
780 777
781 /* 778 /*
782 * Since the UART detected either an XON or 779 * Since the UART detected either an XON or
@@ -789,19 +786,17 @@ static inline void neo_parse_isr(struct jsm_board *brd, u32 port)
789 if (brd->channels[port]->ch_flags & CH_STOP) { 786 if (brd->channels[port]->ch_flags & CH_STOP) {
790 ch->ch_flags &= ~(CH_STOP); 787 ch->ch_flags &= ~(CH_STOP);
791 } 788 }
792 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 789 jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
793 "Port %d. XON detected in incoming data\n", 790 "Port %d. XON detected in incoming data\n", port);
794 port);
795 } 791 }
796 else if (cause == UART_17158_XOFF_DETECT) { 792 else if (cause == UART_17158_XOFF_DETECT) {
797 if (!(brd->channels[port]->ch_flags & CH_STOP)) { 793 if (!(brd->channels[port]->ch_flags & CH_STOP)) {
798 ch->ch_flags |= CH_STOP; 794 ch->ch_flags |= CH_STOP;
799 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 795 jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
800 "Setting CH_STOP\n"); 796 "Setting CH_STOP\n");
801 } 797 }
802 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 798 jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
803 "Port: %d. XOFF detected in incoming data\n", 799 "Port: %d. XOFF detected in incoming data\n", port);
804 port);
805 } 800 }
806 spin_unlock_irqrestore(&ch->ch_lock, lock_flags); 801 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
807 } 802 }
@@ -830,8 +825,8 @@ static inline void neo_parse_isr(struct jsm_board *brd, u32 port)
830 } 825 }
831 826
832 /* Parse any modem signal changes */ 827 /* Parse any modem signal changes */
833 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 828 jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
834 "MOD_STAT: sending to parse_modem_sigs\n"); 829 "MOD_STAT: sending to parse_modem_sigs\n");
835 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr)); 830 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
836 } 831 }
837} 832}
@@ -854,8 +849,8 @@ static inline void neo_parse_lsr(struct jsm_board *brd, u32 port)
854 849
855 linestatus = readb(&ch->ch_neo_uart->lsr); 850 linestatus = readb(&ch->ch_neo_uart->lsr);
856 851
857 jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d port: %d linestatus: %x\n", 852 jsm_printk(INTR, INFO, &ch->ch_bd->pci_dev,
858 __FILE__, __LINE__, port, linestatus); 853 "%s:%d port: %d linestatus: %x\n", __FILE__, __LINE__, port, linestatus);
859 854
860 ch->ch_cached_lsr |= linestatus; 855 ch->ch_cached_lsr |= linestatus;
861 856
@@ -874,7 +869,7 @@ static inline void neo_parse_lsr(struct jsm_board *brd, u32 port)
874 *to do the special RX+LSR read for this FIFO load. 869 *to do the special RX+LSR read for this FIFO load.
875 */ 870 */
876 if (linestatus & UART_17158_RX_FIFO_DATA_ERROR) 871 if (linestatus & UART_17158_RX_FIFO_DATA_ERROR)
877 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 872 jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
878 "%s:%d Port: %d Got an RX error, need to parse LSR\n", 873 "%s:%d Port: %d Got an RX error, need to parse LSR\n",
879 __FILE__, __LINE__, port); 874 __FILE__, __LINE__, port);
880 875
@@ -885,21 +880,20 @@ static inline void neo_parse_lsr(struct jsm_board *brd, u32 port)
885 880
886 if (linestatus & UART_LSR_PE) { 881 if (linestatus & UART_LSR_PE) {
887 ch->ch_err_parity++; 882 ch->ch_err_parity++;
888 jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d Port: %d. PAR ERR!\n", 883 jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
889 __FILE__, __LINE__, port); 884 "%s:%d Port: %d. PAR ERR!\n", __FILE__, __LINE__, port);
890 } 885 }
891 886
892 if (linestatus & UART_LSR_FE) { 887 if (linestatus & UART_LSR_FE) {
893 ch->ch_err_frame++; 888 ch->ch_err_frame++;
894 jsm_dbg(INTR, &ch->ch_bd->pci_dev, "%s:%d Port: %d. FRM ERR!\n", 889 jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
895 __FILE__, __LINE__, port); 890 "%s:%d Port: %d. FRM ERR!\n", __FILE__, __LINE__, port);
896 } 891 }
897 892
898 if (linestatus & UART_LSR_BI) { 893 if (linestatus & UART_LSR_BI) {
899 ch->ch_err_break++; 894 ch->ch_err_break++;
900 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 895 jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
901 "%s:%d Port: %d. BRK INTR!\n", 896 "%s:%d Port: %d. BRK INTR!\n", __FILE__, __LINE__, port);
902 __FILE__, __LINE__, port);
903 } 897 }
904 898
905 if (linestatus & UART_LSR_OE) { 899 if (linestatus & UART_LSR_OE) {
@@ -910,9 +904,8 @@ static inline void neo_parse_lsr(struct jsm_board *brd, u32 port)
910 * Probably we should eventually have an orun stat in our driver... 904 * Probably we should eventually have an orun stat in our driver...
911 */ 905 */
912 ch->ch_err_overrun++; 906 ch->ch_err_overrun++;
913 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 907 jsm_printk(INTR, DEBUG, &ch->ch_bd->pci_dev,
914 "%s:%d Port: %d. Rx Overrun!\n", 908 "%s:%d Port: %d. Rx Overrun!\n", __FILE__, __LINE__, port);
915 __FILE__, __LINE__, port);
916 } 909 }
917 910
918 if (linestatus & UART_LSR_THRE) { 911 if (linestatus & UART_LSR_THRE) {
@@ -1135,11 +1128,11 @@ static irqreturn_t neo_intr(int irq, void *voidbrd)
1135 */ 1128 */
1136 uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET); 1129 uart_poll = readl(brd->re_map_membase + UART_17158_POLL_ADDR_OFFSET);
1137 1130
1138 jsm_dbg(INTR, &brd->pci_dev, "%s:%d uart_poll: %x\n", 1131 jsm_printk(INTR, INFO, &brd->pci_dev,
1139 __FILE__, __LINE__, uart_poll); 1132 "%s:%d uart_poll: %x\n", __FILE__, __LINE__, uart_poll);
1140 1133
1141 if (!uart_poll) { 1134 if (!uart_poll) {
1142 jsm_dbg(INTR, &brd->pci_dev, 1135 jsm_printk(INTR, INFO, &brd->pci_dev,
1143 "Kernel interrupted to me, but no pending interrupts...\n"); 1136 "Kernel interrupted to me, but no pending interrupts...\n");
1144 spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags); 1137 spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
1145 return IRQ_NONE; 1138 return IRQ_NONE;
@@ -1165,15 +1158,15 @@ static irqreturn_t neo_intr(int irq, void *voidbrd)
1165 continue; 1158 continue;
1166 } 1159 }
1167 1160
1168 jsm_dbg(INTR, &brd->pci_dev, "%s:%d port: %x type: %x\n", 1161 jsm_printk(INTR, INFO, &brd->pci_dev,
1169 __FILE__, __LINE__, port, type); 1162 "%s:%d port: %x type: %x\n", __FILE__, __LINE__, port, type);
1170 1163
1171 /* Remove this port + type from uart_poll */ 1164 /* Remove this port + type from uart_poll */
1172 uart_poll &= ~(jsm_offset_table[port]); 1165 uart_poll &= ~(jsm_offset_table[port]);
1173 1166
1174 if (!type) { 1167 if (!type) {
1175 /* If no type, just ignore it, and move onto next port */ 1168 /* If no type, just ignore it, and move onto next port */
1176 jsm_dbg(INTR, &brd->pci_dev, 1169 jsm_printk(INTR, ERR, &brd->pci_dev,
1177 "Interrupt with no type! port: %d\n", port); 1170 "Interrupt with no type! port: %d\n", port);
1178 continue; 1171 continue;
1179 } 1172 }
@@ -1238,16 +1231,15 @@ static irqreturn_t neo_intr(int irq, void *voidbrd)
1238 * these once and awhile. 1231 * these once and awhile.
1239 * Its harmless, just ignore it and move on. 1232 * Its harmless, just ignore it and move on.
1240 */ 1233 */
1241 jsm_dbg(INTR, &brd->pci_dev, 1234 jsm_printk(INTR, ERR, &brd->pci_dev,
1242 "%s:%d Unknown Interrupt type: %x\n", 1235 "%s:%d Unknown Interrupt type: %x\n", __FILE__, __LINE__, type);
1243 __FILE__, __LINE__, type);
1244 continue; 1236 continue;
1245 } 1237 }
1246 } 1238 }
1247 1239
1248 spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags); 1240 spin_unlock_irqrestore(&brd->bd_intr_lock, lock_flags);
1249 1241
1250 jsm_dbg(INTR, &brd->pci_dev, "finish\n"); 1242 jsm_printk(INTR, INFO, &brd->pci_dev, "finish.\n");
1251 return IRQ_HANDLED; 1243 return IRQ_HANDLED;
1252} 1244}
1253 1245
diff --git a/drivers/tty/serial/jsm/jsm_tty.c b/drivers/tty/serial/jsm/jsm_tty.c
index 4c00c5550b1..434bd881fca 100644
--- a/drivers/tty/serial/jsm/jsm_tty.c
+++ b/drivers/tty/serial/jsm/jsm_tty.c
@@ -43,7 +43,7 @@ static inline int jsm_get_mstat(struct jsm_channel *ch)
43 unsigned char mstat; 43 unsigned char mstat;
44 unsigned result; 44 unsigned result;
45 45
46 jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, "start\n"); 46 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev, "start\n");
47 47
48 mstat = (ch->ch_mostat | ch->ch_mistat); 48 mstat = (ch->ch_mostat | ch->ch_mistat);
49 49
@@ -62,7 +62,7 @@ static inline int jsm_get_mstat(struct jsm_channel *ch)
62 if (mstat & UART_MSR_DCD) 62 if (mstat & UART_MSR_DCD)
63 result |= TIOCM_CD; 63 result |= TIOCM_CD;
64 64
65 jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, "finish\n"); 65 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev, "finish\n");
66 return result; 66 return result;
67} 67}
68 68
@@ -79,14 +79,14 @@ static unsigned int jsm_tty_get_mctrl(struct uart_port *port)
79 int result; 79 int result;
80 struct jsm_channel *channel = (struct jsm_channel *)port; 80 struct jsm_channel *channel = (struct jsm_channel *)port;
81 81
82 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n"); 82 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "start\n");
83 83
84 result = jsm_get_mstat(channel); 84 result = jsm_get_mstat(channel);
85 85
86 if (result < 0) 86 if (result < 0)
87 return -ENXIO; 87 return -ENXIO;
88 88
89 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "finish\n"); 89 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "finish\n");
90 90
91 return result; 91 return result;
92} 92}
@@ -100,7 +100,7 @@ static void jsm_tty_set_mctrl(struct uart_port *port, unsigned int mctrl)
100{ 100{
101 struct jsm_channel *channel = (struct jsm_channel *)port; 101 struct jsm_channel *channel = (struct jsm_channel *)port;
102 102
103 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n"); 103 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "start\n");
104 104
105 if (mctrl & TIOCM_RTS) 105 if (mctrl & TIOCM_RTS)
106 channel->ch_mostat |= UART_MCR_RTS; 106 channel->ch_mostat |= UART_MCR_RTS;
@@ -114,7 +114,7 @@ static void jsm_tty_set_mctrl(struct uart_port *port, unsigned int mctrl)
114 114
115 channel->ch_bd->bd_ops->assert_modem_signals(channel); 115 channel->ch_bd->bd_ops->assert_modem_signals(channel);
116 116
117 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "finish\n"); 117 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "finish\n");
118 udelay(10); 118 udelay(10);
119} 119}
120 120
@@ -135,23 +135,23 @@ static void jsm_tty_start_tx(struct uart_port *port)
135{ 135{
136 struct jsm_channel *channel = (struct jsm_channel *)port; 136 struct jsm_channel *channel = (struct jsm_channel *)port;
137 137
138 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n"); 138 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "start\n");
139 139
140 channel->ch_flags &= ~(CH_STOP); 140 channel->ch_flags &= ~(CH_STOP);
141 jsm_tty_write(port); 141 jsm_tty_write(port);
142 142
143 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "finish\n"); 143 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "finish\n");
144} 144}
145 145
146static void jsm_tty_stop_tx(struct uart_port *port) 146static void jsm_tty_stop_tx(struct uart_port *port)
147{ 147{
148 struct jsm_channel *channel = (struct jsm_channel *)port; 148 struct jsm_channel *channel = (struct jsm_channel *)port;
149 149
150 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "start\n"); 150 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "start\n");
151 151
152 channel->ch_flags |= (CH_STOP); 152 channel->ch_flags |= (CH_STOP);
153 153
154 jsm_dbg(IOCTL, &channel->ch_bd->pci_dev, "finish\n"); 154 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "finish\n");
155} 155}
156 156
157static void jsm_tty_send_xchar(struct uart_port *port, char ch) 157static void jsm_tty_send_xchar(struct uart_port *port, char ch)
@@ -161,7 +161,7 @@ static void jsm_tty_send_xchar(struct uart_port *port, char ch)
161 struct ktermios *termios; 161 struct ktermios *termios;
162 162
163 spin_lock_irqsave(&port->lock, lock_flags); 163 spin_lock_irqsave(&port->lock, lock_flags);
164 termios = &port->state->port.tty->termios; 164 termios = port->state->port.tty->termios;
165 if (ch == termios->c_cc[VSTART]) 165 if (ch == termios->c_cc[VSTART])
166 channel->ch_bd->bd_ops->send_start_character(channel); 166 channel->ch_bd->bd_ops->send_start_character(channel);
167 167
@@ -216,16 +216,16 @@ static int jsm_tty_open(struct uart_port *port)
216 if (!channel->ch_rqueue) { 216 if (!channel->ch_rqueue) {
217 channel->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL); 217 channel->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL);
218 if (!channel->ch_rqueue) { 218 if (!channel->ch_rqueue) {
219 jsm_dbg(INIT, &channel->ch_bd->pci_dev, 219 jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
220 "unable to allocate read queue buf\n"); 220 "unable to allocate read queue buf");
221 return -ENOMEM; 221 return -ENOMEM;
222 } 222 }
223 } 223 }
224 if (!channel->ch_equeue) { 224 if (!channel->ch_equeue) {
225 channel->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL); 225 channel->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL);
226 if (!channel->ch_equeue) { 226 if (!channel->ch_equeue) {
227 jsm_dbg(INIT, &channel->ch_bd->pci_dev, 227 jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
228 "unable to allocate error queue buf\n"); 228 "unable to allocate error queue buf");
229 return -ENOMEM; 229 return -ENOMEM;
230 } 230 }
231 } 231 }
@@ -234,7 +234,7 @@ static int jsm_tty_open(struct uart_port *port)
234 /* 234 /*
235 * Initialize if neither terminal is open. 235 * Initialize if neither terminal is open.
236 */ 236 */
237 jsm_dbg(OPEN, &channel->ch_bd->pci_dev, 237 jsm_printk(OPEN, INFO, &channel->ch_bd->pci_dev,
238 "jsm_open: initializing channel in open...\n"); 238 "jsm_open: initializing channel in open...\n");
239 239
240 /* 240 /*
@@ -250,7 +250,7 @@ static int jsm_tty_open(struct uart_port *port)
250 channel->ch_cached_lsr = 0; 250 channel->ch_cached_lsr = 0;
251 channel->ch_stops_sent = 0; 251 channel->ch_stops_sent = 0;
252 252
253 termios = &port->state->port.tty->termios; 253 termios = port->state->port.tty->termios;
254 channel->ch_c_cflag = termios->c_cflag; 254 channel->ch_c_cflag = termios->c_cflag;
255 channel->ch_c_iflag = termios->c_iflag; 255 channel->ch_c_iflag = termios->c_iflag;
256 channel->ch_c_oflag = termios->c_oflag; 256 channel->ch_c_oflag = termios->c_oflag;
@@ -270,7 +270,7 @@ static int jsm_tty_open(struct uart_port *port)
270 270
271 channel->ch_open_count++; 271 channel->ch_open_count++;
272 272
273 jsm_dbg(OPEN, &channel->ch_bd->pci_dev, "finish\n"); 273 jsm_printk(OPEN, INFO, &channel->ch_bd->pci_dev, "finish\n");
274 return 0; 274 return 0;
275} 275}
276 276
@@ -280,10 +280,10 @@ static void jsm_tty_close(struct uart_port *port)
280 struct ktermios *ts; 280 struct ktermios *ts;
281 struct jsm_channel *channel = (struct jsm_channel *)port; 281 struct jsm_channel *channel = (struct jsm_channel *)port;
282 282
283 jsm_dbg(CLOSE, &channel->ch_bd->pci_dev, "start\n"); 283 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev, "start\n");
284 284
285 bd = channel->ch_bd; 285 bd = channel->ch_bd;
286 ts = &port->state->port.tty->termios; 286 ts = port->state->port.tty->termios;
287 287
288 channel->ch_flags &= ~(CH_STOPI); 288 channel->ch_flags &= ~(CH_STOPI);
289 289
@@ -293,7 +293,7 @@ static void jsm_tty_close(struct uart_port *port)
293 * If we have HUPCL set, lower DTR and RTS 293 * If we have HUPCL set, lower DTR and RTS
294 */ 294 */
295 if (channel->ch_c_cflag & HUPCL) { 295 if (channel->ch_c_cflag & HUPCL) {
296 jsm_dbg(CLOSE, &channel->ch_bd->pci_dev, 296 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev,
297 "Close. HUPCL set, dropping DTR/RTS\n"); 297 "Close. HUPCL set, dropping DTR/RTS\n");
298 298
299 /* Drop RTS/DTR */ 299 /* Drop RTS/DTR */
@@ -304,7 +304,7 @@ static void jsm_tty_close(struct uart_port *port)
304 /* Turn off UART interrupts for this port */ 304 /* Turn off UART interrupts for this port */
305 channel->ch_bd->bd_ops->uart_off(channel); 305 channel->ch_bd->bd_ops->uart_off(channel);
306 306
307 jsm_dbg(CLOSE, &channel->ch_bd->pci_dev, "finish\n"); 307 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev, "finish\n");
308} 308}
309 309
310static void jsm_tty_set_termios(struct uart_port *port, 310static void jsm_tty_set_termios(struct uart_port *port,
@@ -371,7 +371,7 @@ static struct uart_ops jsm_ops = {
371 * Init the tty subsystem. Called once per board after board has been 371 * Init the tty subsystem. Called once per board after board has been
372 * downloaded and init'ed. 372 * downloaded and init'ed.
373 */ 373 */
374int jsm_tty_init(struct jsm_board *brd) 374int __devinit jsm_tty_init(struct jsm_board *brd)
375{ 375{
376 int i; 376 int i;
377 void __iomem *vaddr; 377 void __iomem *vaddr;
@@ -380,7 +380,7 @@ int jsm_tty_init(struct jsm_board *brd)
380 if (!brd) 380 if (!brd)
381 return -ENXIO; 381 return -ENXIO;
382 382
383 jsm_dbg(INIT, &brd->pci_dev, "start\n"); 383 jsm_printk(INIT, INFO, &brd->pci_dev, "start\n");
384 384
385 /* 385 /*
386 * Initialize board structure elements. 386 * Initialize board structure elements.
@@ -401,9 +401,9 @@ int jsm_tty_init(struct jsm_board *brd)
401 */ 401 */
402 brd->channels[i] = kzalloc(sizeof(struct jsm_channel), GFP_KERNEL); 402 brd->channels[i] = kzalloc(sizeof(struct jsm_channel), GFP_KERNEL);
403 if (!brd->channels[i]) { 403 if (!brd->channels[i]) {
404 jsm_dbg(CORE, &brd->pci_dev, 404 jsm_printk(CORE, ERR, &brd->pci_dev,
405 "%s:%d Unable to allocate memory for channel struct\n", 405 "%s:%d Unable to allocate memory for channel struct\n",
406 __FILE__, __LINE__); 406 __FILE__, __LINE__);
407 } 407 }
408 } 408 }
409 } 409 }
@@ -431,7 +431,7 @@ int jsm_tty_init(struct jsm_board *brd)
431 init_waitqueue_head(&ch->ch_flags_wait); 431 init_waitqueue_head(&ch->ch_flags_wait);
432 } 432 }
433 433
434 jsm_dbg(INIT, &brd->pci_dev, "finish\n"); 434 jsm_printk(INIT, INFO, &brd->pci_dev, "finish\n");
435 return 0; 435 return 0;
436} 436}
437 437
@@ -444,7 +444,7 @@ int jsm_uart_port_init(struct jsm_board *brd)
444 if (!brd) 444 if (!brd)
445 return -ENXIO; 445 return -ENXIO;
446 446
447 jsm_dbg(INIT, &brd->pci_dev, "start\n"); 447 jsm_printk(INIT, INFO, &brd->pci_dev, "start\n");
448 448
449 /* 449 /*
450 * Initialize board structure elements. 450 * Initialize board structure elements.
@@ -481,7 +481,7 @@ int jsm_uart_port_init(struct jsm_board *brd)
481 printk(KERN_INFO "jsm: Port %d added\n", i); 481 printk(KERN_INFO "jsm: Port %d added\n", i);
482 } 482 }
483 483
484 jsm_dbg(INIT, &brd->pci_dev, "finish\n"); 484 jsm_printk(INIT, INFO, &brd->pci_dev, "finish\n");
485 return 0; 485 return 0;
486} 486}
487 487
@@ -493,7 +493,7 @@ int jsm_remove_uart_port(struct jsm_board *brd)
493 if (!brd) 493 if (!brd)
494 return -ENXIO; 494 return -ENXIO;
495 495
496 jsm_dbg(INIT, &brd->pci_dev, "start\n"); 496 jsm_printk(INIT, INFO, &brd->pci_dev, "start\n");
497 497
498 /* 498 /*
499 * Initialize board structure elements. 499 * Initialize board structure elements.
@@ -513,7 +513,7 @@ int jsm_remove_uart_port(struct jsm_board *brd)
513 uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port); 513 uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port);
514 } 514 }
515 515
516 jsm_dbg(INIT, &brd->pci_dev, "finish\n"); 516 jsm_printk(INIT, INFO, &brd->pci_dev, "finish\n");
517 return 0; 517 return 0;
518} 518}
519 519
@@ -531,7 +531,7 @@ void jsm_input(struct jsm_channel *ch)
531 int s = 0; 531 int s = 0;
532 int i = 0; 532 int i = 0;
533 533
534 jsm_dbg(READ, &ch->ch_bd->pci_dev, "start\n"); 534 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "start\n");
535 535
536 if (!ch) 536 if (!ch)
537 return; 537 return;
@@ -560,18 +560,17 @@ void jsm_input(struct jsm_channel *ch)
560 return; 560 return;
561 } 561 }
562 562
563 jsm_dbg(READ, &ch->ch_bd->pci_dev, "start\n"); 563 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "start\n");
564 564
565 /* 565 /*
566 *If the device is not open, or CREAD is off, flush 566 *If the device is not open, or CREAD is off, flush
567 *input data and return immediately. 567 *input data and return immediately.
568 */ 568 */
569 if (!tp || 569 if (!tp ||
570 !(tp->termios.c_cflag & CREAD) ) { 570 !(tp->termios->c_cflag & CREAD) ) {
571 571
572 jsm_dbg(READ, &ch->ch_bd->pci_dev, 572 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
573 "input. dropping %d bytes on port %d...\n", 573 "input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum);
574 data_len, ch->ch_portnum);
575 ch->ch_r_head = tail; 574 ch->ch_r_head = tail;
576 575
577 /* Force queue flow control to be released, if needed */ 576 /* Force queue flow control to be released, if needed */
@@ -586,17 +585,17 @@ void jsm_input(struct jsm_channel *ch)
586 */ 585 */
587 if (ch->ch_flags & CH_STOPI) { 586 if (ch->ch_flags & CH_STOPI) {
588 spin_unlock_irqrestore(&ch->ch_lock, lock_flags); 587 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
589 jsm_dbg(READ, &ch->ch_bd->pci_dev, 588 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
590 "Port %d throttled, not reading any data. head: %x tail: %x\n", 589 "Port %d throttled, not reading any data. head: %x tail: %x\n",
591 ch->ch_portnum, head, tail); 590 ch->ch_portnum, head, tail);
592 return; 591 return;
593 } 592 }
594 593
595 jsm_dbg(READ, &ch->ch_bd->pci_dev, "start 2\n"); 594 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "start 2\n");
596 595
597 if (data_len <= 0) { 596 if (data_len <= 0) {
598 spin_unlock_irqrestore(&ch->ch_lock, lock_flags); 597 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
599 jsm_dbg(READ, &ch->ch_bd->pci_dev, "jsm_input 1\n"); 598 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "jsm_input 1\n");
600 return; 599 return;
601 } 600 }
602 601
@@ -654,7 +653,7 @@ void jsm_input(struct jsm_channel *ch)
654 /* Tell the tty layer its okay to "eat" the data now */ 653 /* Tell the tty layer its okay to "eat" the data now */
655 tty_flip_buffer_push(tp); 654 tty_flip_buffer_push(tp);
656 655
657 jsm_dbg(IOCTL, &ch->ch_bd->pci_dev, "finish\n"); 656 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev, "finish\n");
658} 657}
659 658
660static void jsm_carrier(struct jsm_channel *ch) 659static void jsm_carrier(struct jsm_channel *ch)
@@ -664,7 +663,7 @@ static void jsm_carrier(struct jsm_channel *ch)
664 int virt_carrier = 0; 663 int virt_carrier = 0;
665 int phys_carrier = 0; 664 int phys_carrier = 0;
666 665
667 jsm_dbg(CARR, &ch->ch_bd->pci_dev, "start\n"); 666 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev, "start\n");
668 if (!ch) 667 if (!ch)
669 return; 668 return;
670 669
@@ -674,16 +673,16 @@ static void jsm_carrier(struct jsm_channel *ch)
674 return; 673 return;
675 674
676 if (ch->ch_mistat & UART_MSR_DCD) { 675 if (ch->ch_mistat & UART_MSR_DCD) {
677 jsm_dbg(CARR, &ch->ch_bd->pci_dev, "mistat: %x D_CD: %x\n", 676 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev,
678 ch->ch_mistat, ch->ch_mistat & UART_MSR_DCD); 677 "mistat: %x D_CD: %x\n", ch->ch_mistat, ch->ch_mistat & UART_MSR_DCD);
679 phys_carrier = 1; 678 phys_carrier = 1;
680 } 679 }
681 680
682 if (ch->ch_c_cflag & CLOCAL) 681 if (ch->ch_c_cflag & CLOCAL)
683 virt_carrier = 1; 682 virt_carrier = 1;
684 683
685 jsm_dbg(CARR, &ch->ch_bd->pci_dev, "DCD: physical: %d virt: %d\n", 684 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev,
686 phys_carrier, virt_carrier); 685 "DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier);
687 686
688 /* 687 /*
689 * Test for a VIRTUAL carrier transition to HIGH. 688 * Test for a VIRTUAL carrier transition to HIGH.
@@ -695,7 +694,8 @@ static void jsm_carrier(struct jsm_channel *ch)
695 * for carrier in the open routine. 694 * for carrier in the open routine.
696 */ 695 */
697 696
698 jsm_dbg(CARR, &ch->ch_bd->pci_dev, "carrier: virt DCD rose\n"); 697 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev,
698 "carrier: virt DCD rose\n");
699 699
700 if (waitqueue_active(&(ch->ch_flags_wait))) 700 if (waitqueue_active(&(ch->ch_flags_wait)))
701 wake_up_interruptible(&ch->ch_flags_wait); 701 wake_up_interruptible(&ch->ch_flags_wait);
@@ -711,7 +711,7 @@ static void jsm_carrier(struct jsm_channel *ch)
711 * for carrier in the open routine. 711 * for carrier in the open routine.
712 */ 712 */
713 713
714 jsm_dbg(CARR, &ch->ch_bd->pci_dev, 714 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev,
715 "carrier: physical DCD rose\n"); 715 "carrier: physical DCD rose\n");
716 716
717 if (waitqueue_active(&(ch->ch_flags_wait))) 717 if (waitqueue_active(&(ch->ch_flags_wait)))
@@ -790,8 +790,8 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
790 if(!(ch->ch_flags & CH_RECEIVER_OFF)) { 790 if(!(ch->ch_flags & CH_RECEIVER_OFF)) {
791 bd_ops->disable_receiver(ch); 791 bd_ops->disable_receiver(ch);
792 ch->ch_flags |= (CH_RECEIVER_OFF); 792 ch->ch_flags |= (CH_RECEIVER_OFF);
793 jsm_dbg(READ, &ch->ch_bd->pci_dev, 793 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
794 "Internal queue hit hilevel mark (%d)! Turning off interrupts\n", 794 "Internal queue hit hilevel mark (%d)! Turning off interrupts.\n",
795 qleft); 795 qleft);
796 } 796 }
797 } 797 }
@@ -800,9 +800,8 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
800 if (ch->ch_stops_sent <= MAX_STOPS_SENT) { 800 if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
801 bd_ops->send_stop_character(ch); 801 bd_ops->send_stop_character(ch);
802 ch->ch_stops_sent++; 802 ch->ch_stops_sent++;
803 jsm_dbg(READ, &ch->ch_bd->pci_dev, 803 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
804 "Sending stop char! Times sent: %x\n", 804 "Sending stop char! Times sent: %x\n", ch->ch_stops_sent);
805 ch->ch_stops_sent);
806 } 805 }
807 } 806 }
808 } 807 }
@@ -828,8 +827,8 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
828 if (ch->ch_flags & CH_RECEIVER_OFF) { 827 if (ch->ch_flags & CH_RECEIVER_OFF) {
829 bd_ops->enable_receiver(ch); 828 bd_ops->enable_receiver(ch);
830 ch->ch_flags &= ~(CH_RECEIVER_OFF); 829 ch->ch_flags &= ~(CH_RECEIVER_OFF);
831 jsm_dbg(READ, &ch->ch_bd->pci_dev, 830 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
832 "Internal queue hit lowlevel mark (%d)! Turning on interrupts\n", 831 "Internal queue hit lowlevel mark (%d)! Turning on interrupts.\n",
833 qleft); 832 qleft);
834 } 833 }
835 } 834 }
@@ -837,8 +836,7 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
837 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) { 836 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
838 ch->ch_stops_sent = 0; 837 ch->ch_stops_sent = 0;
839 bd_ops->send_start_character(ch); 838 bd_ops->send_start_character(ch);
840 jsm_dbg(READ, &ch->ch_bd->pci_dev, 839 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "Sending start char!\n");
841 "Sending start char!\n");
842 } 840 }
843 } 841 }
844} 842}
diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
deleted file mode 100644
index 6ac2b797a76..00000000000
--- a/drivers/tty/serial/kgdb_nmi.c
+++ /dev/null
@@ -1,404 +0,0 @@
1/*
2 * KGDB NMI serial console
3 *
4 * Copyright 2010 Google, Inc.
5 * Arve Hjønnevåg <arve@android.com>
6 * Colin Cross <ccross@android.com>
7 * Copyright 2012 Linaro Ltd.
8 * Anton Vorontsov <anton.vorontsov@linaro.org>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/compiler.h>
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/errno.h>
21#include <linux/atomic.h>
22#include <linux/console.h>
23#include <linux/tty.h>
24#include <linux/tty_driver.h>
25#include <linux/tty_flip.h>
26#include <linux/interrupt.h>
27#include <linux/hrtimer.h>
28#include <linux/tick.h>
29#include <linux/kfifo.h>
30#include <linux/kgdb.h>
31#include <linux/kdb.h>
32
33static int kgdb_nmi_knock = 1;
34module_param_named(knock, kgdb_nmi_knock, int, 0600);
35MODULE_PARM_DESC(knock, "if set to 1 (default), the special '$3#33' command " \
36 "must be used to enter the debugger; when set to 0, " \
37 "hitting return key is enough to enter the debugger; " \
38 "when set to -1, the debugger is entered immediately " \
39 "upon NMI");
40
41static char *kgdb_nmi_magic = "$3#33";
42module_param_named(magic, kgdb_nmi_magic, charp, 0600);
43MODULE_PARM_DESC(magic, "magic sequence to enter NMI debugger (default $3#33)");
44
45static bool kgdb_nmi_tty_enabled;
46
47static void kgdb_nmi_console_write(struct console *co, const char *s, uint c)
48{
49 int i;
50
51 if (!kgdb_nmi_tty_enabled || atomic_read(&kgdb_active) >= 0)
52 return;
53
54 for (i = 0; i < c; i++)
55 dbg_io_ops->write_char(s[i]);
56}
57
58static struct tty_driver *kgdb_nmi_tty_driver;
59
60static struct tty_driver *kgdb_nmi_console_device(struct console *co, int *idx)
61{
62 *idx = co->index;
63 return kgdb_nmi_tty_driver;
64}
65
66static struct console kgdb_nmi_console = {
67 .name = "ttyNMI",
68 .write = kgdb_nmi_console_write,
69 .device = kgdb_nmi_console_device,
70 .flags = CON_PRINTBUFFER | CON_ANYTIME | CON_ENABLED,
71 .index = -1,
72};
73
74/*
75 * This is usually the maximum rate on debug ports. We make fifo large enough
76 * to make copy-pasting to the terminal usable.
77 */
78#define KGDB_NMI_BAUD 115200
79#define KGDB_NMI_FIFO_SIZE roundup_pow_of_two(KGDB_NMI_BAUD / 8 / HZ)
80
81struct kgdb_nmi_tty_priv {
82 struct tty_port port;
83 struct tasklet_struct tlet;
84 STRUCT_KFIFO(char, KGDB_NMI_FIFO_SIZE) fifo;
85};
86
87static struct kgdb_nmi_tty_priv *kgdb_nmi_port_to_priv(struct tty_port *port)
88{
89 return container_of(port, struct kgdb_nmi_tty_priv, port);
90}
91
92/*
93 * Our debugging console is polled in a tasklet, so we'll check for input
94 * every tick. In HZ-less mode, we should program the next tick. We have
95 * to use the lowlevel stuff as no locks should be grabbed.
96 */
97#ifdef CONFIG_HIGH_RES_TIMERS
98static void kgdb_tty_poke(void)
99{
100 tick_program_event(ktime_get(), 0);
101}
102#else
103static inline void kgdb_tty_poke(void) {}
104#endif
105
106static struct tty_port *kgdb_nmi_port;
107
108static void kgdb_tty_recv(int ch)
109{
110 struct kgdb_nmi_tty_priv *priv;
111 char c = ch;
112
113 if (!kgdb_nmi_port || ch < 0)
114 return;
115 /*
116 * Can't use port->tty->driver_data as tty might be not there. Tasklet
117 * will check for tty and will get the ref, but here we don't have to
118 * do that, and actually, we can't: we're in NMI context, no locks are
119 * possible.
120 */
121 priv = kgdb_nmi_port_to_priv(kgdb_nmi_port);
122 kfifo_in(&priv->fifo, &c, 1);
123 kgdb_tty_poke();
124}
125
126static int kgdb_nmi_poll_one_knock(void)
127{
128 static int n;
129 int c = -1;
130 const char *magic = kgdb_nmi_magic;
131 size_t m = strlen(magic);
132 bool printch = 0;
133
134 c = dbg_io_ops->read_char();
135 if (c == NO_POLL_CHAR)
136 return c;
137
138 if (!kgdb_nmi_knock && (c == '\r' || c == '\n')) {
139 return 1;
140 } else if (c == magic[n]) {
141 n = (n + 1) % m;
142 if (!n)
143 return 1;
144 printch = 1;
145 } else {
146 n = 0;
147 }
148
149 if (kgdb_nmi_tty_enabled) {
150 kgdb_tty_recv(c);
151 return 0;
152 }
153
154 if (printch) {
155 kdb_printf("%c", c);
156 return 0;
157 }
158
159 kdb_printf("\r%s %s to enter the debugger> %*s",
160 kgdb_nmi_knock ? "Type" : "Hit",
161 kgdb_nmi_knock ? magic : "<return>", (int)m, "");
162 while (m--)
163 kdb_printf("\b");
164 return 0;
165}
166
167/**
168 * kgdb_nmi_poll_knock - Check if it is time to enter the debugger
169 *
170 * "Serial ports are often noisy, especially when muxed over another port (we
171 * often use serial over the headset connector). Noise on the async command
172 * line just causes characters that are ignored, on a command line that blocked
173 * execution noise would be catastrophic." -- Colin Cross
174 *
175 * So, this function implements KGDB/KDB knocking on the serial line: we won't
176 * enter the debugger until we receive a known magic phrase (which is actually
177 * "$3#33", known as "escape to KDB" command. There is also a relaxed variant
178 * of knocking, i.e. just pressing the return key is enough to enter the
179 * debugger. And if knocking is disabled, the function always returns 1.
180 */
181bool kgdb_nmi_poll_knock(void)
182{
183 if (kgdb_nmi_knock < 0)
184 return 1;
185
186 while (1) {
187 int ret;
188
189 ret = kgdb_nmi_poll_one_knock();
190 if (ret == NO_POLL_CHAR)
191 return 0;
192 else if (ret == 1)
193 break;
194 }
195 return 1;
196}
197
198/*
199 * The tasklet is cheap, it does not cause wakeups when reschedules itself,
200 * instead it waits for the next tick.
201 */
202static void kgdb_nmi_tty_receiver(unsigned long data)
203{
204 struct kgdb_nmi_tty_priv *priv = (void *)data;
205 struct tty_struct *tty;
206 char ch;
207
208 tasklet_schedule(&priv->tlet);
209
210 if (likely(!kgdb_nmi_tty_enabled || !kfifo_len(&priv->fifo)))
211 return;
212
213 /* Port is there, but tty might be hung up, check. */
214 tty = tty_port_tty_get(kgdb_nmi_port);
215 if (!tty)
216 return;
217
218 while (kfifo_out(&priv->fifo, &ch, 1))
219 tty_insert_flip_char(priv->port.tty, ch, TTY_NORMAL);
220 tty_flip_buffer_push(priv->port.tty);
221
222 tty_kref_put(tty);
223}
224
225static int kgdb_nmi_tty_activate(struct tty_port *port, struct tty_struct *tty)
226{
227 struct kgdb_nmi_tty_priv *priv = tty->driver_data;
228
229 kgdb_nmi_port = port;
230 tasklet_schedule(&priv->tlet);
231 return 0;
232}
233
234static void kgdb_nmi_tty_shutdown(struct tty_port *port)
235{
236 struct kgdb_nmi_tty_priv *priv = port->tty->driver_data;
237
238 tasklet_kill(&priv->tlet);
239 kgdb_nmi_port = NULL;
240}
241
242static const struct tty_port_operations kgdb_nmi_tty_port_ops = {
243 .activate = kgdb_nmi_tty_activate,
244 .shutdown = kgdb_nmi_tty_shutdown,
245};
246
247static int kgdb_nmi_tty_install(struct tty_driver *drv, struct tty_struct *tty)
248{
249 struct kgdb_nmi_tty_priv *priv;
250 int ret;
251
252 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
253 if (!priv)
254 return -ENOMEM;
255
256 INIT_KFIFO(priv->fifo);
257 tasklet_init(&priv->tlet, kgdb_nmi_tty_receiver, (unsigned long)priv);
258 tty_port_init(&priv->port);
259 priv->port.ops = &kgdb_nmi_tty_port_ops;
260 tty->driver_data = priv;
261
262 ret = tty_port_install(&priv->port, drv, tty);
263 if (ret) {
264 pr_err("%s: can't install tty port: %d\n", __func__, ret);
265 goto err;
266 }
267 return 0;
268err:
269 tty_port_destroy(&priv->port);
270 kfree(priv);
271 return ret;
272}
273
274static void kgdb_nmi_tty_cleanup(struct tty_struct *tty)
275{
276 struct kgdb_nmi_tty_priv *priv = tty->driver_data;
277
278 tty->driver_data = NULL;
279 tty_port_destroy(&priv->port);
280 kfree(priv);
281}
282
283static int kgdb_nmi_tty_open(struct tty_struct *tty, struct file *file)
284{
285 struct kgdb_nmi_tty_priv *priv = tty->driver_data;
286
287 return tty_port_open(&priv->port, tty, file);
288}
289
290static void kgdb_nmi_tty_close(struct tty_struct *tty, struct file *file)
291{
292 struct kgdb_nmi_tty_priv *priv = tty->driver_data;
293
294 tty_port_close(&priv->port, tty, file);
295}
296
297static void kgdb_nmi_tty_hangup(struct tty_struct *tty)
298{
299 struct kgdb_nmi_tty_priv *priv = tty->driver_data;
300
301 tty_port_hangup(&priv->port);
302}
303
304static int kgdb_nmi_tty_write_room(struct tty_struct *tty)
305{
306 /* Actually, we can handle any amount as we use polled writes. */
307 return 2048;
308}
309
310static int kgdb_nmi_tty_write(struct tty_struct *tty, const unchar *buf, int c)
311{
312 int i;
313
314 for (i = 0; i < c; i++)
315 dbg_io_ops->write_char(buf[i]);
316 return c;
317}
318
319static const struct tty_operations kgdb_nmi_tty_ops = {
320 .open = kgdb_nmi_tty_open,
321 .close = kgdb_nmi_tty_close,
322 .install = kgdb_nmi_tty_install,
323 .cleanup = kgdb_nmi_tty_cleanup,
324 .hangup = kgdb_nmi_tty_hangup,
325 .write_room = kgdb_nmi_tty_write_room,
326 .write = kgdb_nmi_tty_write,
327};
328
329static int kgdb_nmi_enable_console(int argc, const char *argv[])
330{
331 kgdb_nmi_tty_enabled = !(argc == 1 && !strcmp(argv[1], "off"));
332 return 0;
333}
334
335int kgdb_register_nmi_console(void)
336{
337 int ret;
338
339 if (!arch_kgdb_ops.enable_nmi)
340 return 0;
341
342 kgdb_nmi_tty_driver = alloc_tty_driver(1);
343 if (!kgdb_nmi_tty_driver) {
344 pr_err("%s: cannot allocate tty\n", __func__);
345 return -ENOMEM;
346 }
347 kgdb_nmi_tty_driver->driver_name = "ttyNMI";
348 kgdb_nmi_tty_driver->name = "ttyNMI";
349 kgdb_nmi_tty_driver->num = 1;
350 kgdb_nmi_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
351 kgdb_nmi_tty_driver->subtype = SERIAL_TYPE_NORMAL;
352 kgdb_nmi_tty_driver->flags = TTY_DRIVER_REAL_RAW;
353 kgdb_nmi_tty_driver->init_termios = tty_std_termios;
354 tty_termios_encode_baud_rate(&kgdb_nmi_tty_driver->init_termios,
355 KGDB_NMI_BAUD, KGDB_NMI_BAUD);
356 tty_set_operations(kgdb_nmi_tty_driver, &kgdb_nmi_tty_ops);
357
358 ret = tty_register_driver(kgdb_nmi_tty_driver);
359 if (ret) {
360 pr_err("%s: can't register tty driver: %d\n", __func__, ret);
361 goto err_drv_reg;
362 }
363
364 ret = kdb_register("nmi_console", kgdb_nmi_enable_console, "[off]",
365 "switch to Linux NMI console", 0);
366 if (ret) {
367 pr_err("%s: can't register kdb command: %d\n", __func__, ret);
368 goto err_kdb_reg;
369 }
370
371 register_console(&kgdb_nmi_console);
372 arch_kgdb_ops.enable_nmi(1);
373
374 return 0;
375err_kdb_reg:
376 tty_unregister_driver(kgdb_nmi_tty_driver);
377err_drv_reg:
378 put_tty_driver(kgdb_nmi_tty_driver);
379 return ret;
380}
381EXPORT_SYMBOL_GPL(kgdb_register_nmi_console);
382
383int kgdb_unregister_nmi_console(void)
384{
385 int ret;
386
387 if (!arch_kgdb_ops.enable_nmi)
388 return 0;
389 arch_kgdb_ops.enable_nmi(0);
390
391 kdb_unregister("nmi_console");
392
393 ret = unregister_console(&kgdb_nmi_console);
394 if (ret)
395 return ret;
396
397 ret = tty_unregister_driver(kgdb_nmi_tty_driver);
398 if (ret)
399 return ret;
400 put_tty_driver(kgdb_nmi_tty_driver);
401
402 return 0;
403}
404EXPORT_SYMBOL_GPL(kgdb_unregister_nmi_console);
diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
index 10020547c60..87e7e6c876d 100644
--- a/drivers/tty/serial/kgdboc.c
+++ b/drivers/tty/serial/kgdboc.c
@@ -19,7 +19,6 @@
19#include <linux/console.h> 19#include <linux/console.h>
20#include <linux/vt_kern.h> 20#include <linux/vt_kern.h>
21#include <linux/input.h> 21#include <linux/input.h>
22#include <linux/module.h>
23 22
24#define MAX_CONFIG_LEN 40 23#define MAX_CONFIG_LEN 40
25 24
@@ -97,8 +96,7 @@ static void kgdboc_restore_input(void)
97 96
98static int kgdboc_register_kbd(char **cptr) 97static int kgdboc_register_kbd(char **cptr)
99{ 98{
100 if (strncmp(*cptr, "kbd", 3) == 0 || 99 if (strncmp(*cptr, "kbd", 3) == 0) {
101 strncmp(*cptr, "kdb", 3) == 0) {
102 if (kdb_poll_idx < KDB_POLL_FUNC_MAX) { 100 if (kdb_poll_idx < KDB_POLL_FUNC_MAX) {
103 kdb_poll_funcs[kdb_poll_idx] = kdb_get_kbd_char; 101 kdb_poll_funcs[kdb_poll_idx] = kdb_get_kbd_char;
104 kdb_poll_idx++; 102 kdb_poll_idx++;
@@ -123,7 +121,7 @@ static void kgdboc_unregister_kbd(void)
123 i--; 121 i--;
124 } 122 }
125 } 123 }
126 flush_work(&kgdboc_restore_input_work); 124 flush_work_sync(&kgdboc_restore_input_work);
127} 125}
128#else /* ! CONFIG_KDB_KEYBOARD */ 126#else /* ! CONFIG_KDB_KEYBOARD */
129#define kgdboc_register_kbd(x) 0 127#define kgdboc_register_kbd(x) 0
@@ -146,8 +144,6 @@ __setup("kgdboc=", kgdboc_option_setup);
146 144
147static void cleanup_kgdboc(void) 145static void cleanup_kgdboc(void)
148{ 146{
149 if (kgdb_unregister_nmi_console())
150 return;
151 kgdboc_unregister_kbd(); 147 kgdboc_unregister_kbd();
152 if (configured == 1) 148 if (configured == 1)
153 kgdb_unregister_io_module(&kgdboc_io_ops); 149 kgdb_unregister_io_module(&kgdboc_io_ops);
@@ -201,18 +197,11 @@ do_register:
201 if (err) 197 if (err)
202 goto noconfig; 198 goto noconfig;
203 199
204 err = kgdb_register_nmi_console();
205 if (err)
206 goto nmi_con_failed;
207
208 configured = 1; 200 configured = 1;
209 201
210 return 0; 202 return 0;
211 203
212nmi_con_failed:
213 kgdb_unregister_io_module(&kgdboc_io_ops);
214noconfig: 204noconfig:
215 kgdboc_unregister_kbd();
216 config[0] = 0; 205 config[0] = 0;
217 configured = 0; 206 configured = 0;
218 cleanup_kgdboc(); 207 cleanup_kgdboc();
diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c
index 02da071fe1e..bc95f52cad8 100644
--- a/drivers/tty/serial/lantiq.c
+++ b/drivers/tty/serial/lantiq.c
@@ -31,19 +31,16 @@
31#include <linux/tty_flip.h> 31#include <linux/tty_flip.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/of_platform.h> 34#include <linux/platform_device.h>
35#include <linux/of_address.h>
36#include <linux/of_irq.h>
37#include <linux/io.h> 35#include <linux/io.h>
38#include <linux/clk.h> 36#include <linux/clk.h>
39#include <linux/gpio.h>
40 37
41#include <lantiq_soc.h> 38#include <lantiq_soc.h>
42 39
43#define PORT_LTQ_ASC 111 40#define PORT_LTQ_ASC 111
44#define MAXPORTS 2 41#define MAXPORTS 2
45#define UART_DUMMY_UER_RX 1 42#define UART_DUMMY_UER_RX 1
46#define DRVNAME "lantiq,asc" 43#define DRVNAME "ltq_asc"
47#ifdef __BIG_ENDIAN 44#ifdef __BIG_ENDIAN
48#define LTQ_ASC_TBUF (0x0020 + 3) 45#define LTQ_ASC_TBUF (0x0020 + 3)
49#define LTQ_ASC_RBUF (0x0024 + 3) 46#define LTQ_ASC_RBUF (0x0024 + 3)
@@ -117,9 +114,6 @@ static DEFINE_SPINLOCK(ltq_asc_lock);
117 114
118struct ltq_uart_port { 115struct ltq_uart_port {
119 struct uart_port port; 116 struct uart_port port;
120 /* clock used to derive divider */
121 struct clk *fpiclk;
122 /* clock gating of the ASC core */
123 struct clk *clk; 117 struct clk *clk;
124 unsigned int tx_irq; 118 unsigned int tx_irq;
125 unsigned int rx_irq; 119 unsigned int rx_irq;
@@ -322,9 +316,7 @@ lqasc_startup(struct uart_port *port)
322 struct ltq_uart_port *ltq_port = to_ltq_uart_port(port); 316 struct ltq_uart_port *ltq_port = to_ltq_uart_port(port);
323 int retval; 317 int retval;
324 318
325 if (ltq_port->clk) 319 port->uartclk = clk_get_rate(ltq_port->clk);
326 clk_enable(ltq_port->clk);
327 port->uartclk = clk_get_rate(ltq_port->fpiclk);
328 320
329 ltq_w32_mask(ASCCLC_DISS | ASCCLC_RMCMASK, (1 << ASCCLC_RMCOFFSET), 321 ltq_w32_mask(ASCCLC_DISS | ASCCLC_RMCMASK, (1 << ASCCLC_RMCOFFSET),
330 port->membase + LTQ_ASC_CLC); 322 port->membase + LTQ_ASC_CLC);
@@ -346,21 +338,21 @@ lqasc_startup(struct uart_port *port)
346 ASCCON_ROEN, port->membase + LTQ_ASC_CON); 338 ASCCON_ROEN, port->membase + LTQ_ASC_CON);
347 339
348 retval = request_irq(ltq_port->tx_irq, lqasc_tx_int, 340 retval = request_irq(ltq_port->tx_irq, lqasc_tx_int,
349 0, "asc_tx", port); 341 IRQF_DISABLED, "asc_tx", port);
350 if (retval) { 342 if (retval) {
351 pr_err("failed to request lqasc_tx_int\n"); 343 pr_err("failed to request lqasc_tx_int\n");
352 return retval; 344 return retval;
353 } 345 }
354 346
355 retval = request_irq(ltq_port->rx_irq, lqasc_rx_int, 347 retval = request_irq(ltq_port->rx_irq, lqasc_rx_int,
356 0, "asc_rx", port); 348 IRQF_DISABLED, "asc_rx", port);
357 if (retval) { 349 if (retval) {
358 pr_err("failed to request lqasc_rx_int\n"); 350 pr_err("failed to request lqasc_rx_int\n");
359 goto err1; 351 goto err1;
360 } 352 }
361 353
362 retval = request_irq(ltq_port->err_irq, lqasc_err_int, 354 retval = request_irq(ltq_port->err_irq, lqasc_err_int,
363 0, "asc_err", port); 355 IRQF_DISABLED, "asc_err", port);
364 if (retval) { 356 if (retval) {
365 pr_err("failed to request lqasc_err_int\n"); 357 pr_err("failed to request lqasc_err_int\n");
366 goto err2; 358 goto err2;
@@ -390,8 +382,6 @@ lqasc_shutdown(struct uart_port *port)
390 port->membase + LTQ_ASC_RXFCON); 382 port->membase + LTQ_ASC_RXFCON);
391 ltq_w32_mask(ASCTXFCON_TXFEN, ASCTXFCON_TXFFLU, 383 ltq_w32_mask(ASCTXFCON_TXFEN, ASCTXFCON_TXFFLU,
392 port->membase + LTQ_ASC_TXFCON); 384 port->membase + LTQ_ASC_TXFCON);
393 if (ltq_port->clk)
394 clk_disable(ltq_port->clk);
395} 385}
396 386
397static void 387static void
@@ -640,7 +630,7 @@ lqasc_console_setup(struct console *co, char *options)
640 630
641 port = &ltq_port->port; 631 port = &ltq_port->port;
642 632
643 port->uartclk = clk_get_rate(ltq_port->fpiclk); 633 port->uartclk = clk_get_rate(ltq_port->clk);
644 634
645 if (options) 635 if (options)
646 uart_parse_options(options, &baud, &parity, &bits, &flow); 636 uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -678,32 +668,37 @@ static struct uart_driver lqasc_reg = {
678static int __init 668static int __init
679lqasc_probe(struct platform_device *pdev) 669lqasc_probe(struct platform_device *pdev)
680{ 670{
681 struct device_node *node = pdev->dev.of_node;
682 struct ltq_uart_port *ltq_port; 671 struct ltq_uart_port *ltq_port;
683 struct uart_port *port; 672 struct uart_port *port;
684 struct resource *mmres, irqres[3]; 673 struct resource *mmres, *irqres;
685 int line = 0; 674 int tx_irq, rx_irq, err_irq;
675 struct clk *clk;
686 int ret; 676 int ret;
687 677
688 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0); 678 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
689 ret = of_irq_to_resource_table(node, irqres, 3); 679 irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
690 if (!mmres || (ret != 3)) { 680 if (!mmres || !irqres)
691 dev_err(&pdev->dev,
692 "failed to get memory/irq for serial port\n");
693 return -ENODEV; 681 return -ENODEV;
694 }
695 682
696 /* check if this is the console port */ 683 if (pdev->id >= MAXPORTS)
697 if (mmres->start != CPHYSADDR(LTQ_EARLY_ASC)) 684 return -EBUSY;
698 line = 1;
699 685
700 if (lqasc_port[line]) { 686 if (lqasc_port[pdev->id] != NULL)
701 dev_err(&pdev->dev, "port %d already allocated\n", line);
702 return -EBUSY; 687 return -EBUSY;
688
689 clk = clk_get(&pdev->dev, "fpi");
690 if (IS_ERR(clk)) {
691 pr_err("failed to get fpi clk\n");
692 return -ENOENT;
703 } 693 }
704 694
705 ltq_port = devm_kzalloc(&pdev->dev, sizeof(struct ltq_uart_port), 695 tx_irq = platform_get_irq_byname(pdev, "tx");
706 GFP_KERNEL); 696 rx_irq = platform_get_irq_byname(pdev, "rx");
697 err_irq = platform_get_irq_byname(pdev, "err");
698 if ((tx_irq < 0) | (rx_irq < 0) | (err_irq < 0))
699 return -ENODEV;
700
701 ltq_port = kzalloc(sizeof(struct ltq_uart_port), GFP_KERNEL);
707 if (!ltq_port) 702 if (!ltq_port)
708 return -ENOMEM; 703 return -ENOMEM;
709 704
@@ -714,26 +709,19 @@ lqasc_probe(struct platform_device *pdev)
714 port->ops = &lqasc_pops; 709 port->ops = &lqasc_pops;
715 port->fifosize = 16; 710 port->fifosize = 16;
716 port->type = PORT_LTQ_ASC, 711 port->type = PORT_LTQ_ASC,
717 port->line = line; 712 port->line = pdev->id;
718 port->dev = &pdev->dev; 713 port->dev = &pdev->dev;
719 /* unused, just to be backward-compatible */
720 port->irq = irqres[0].start;
721 port->mapbase = mmres->start;
722 714
723 ltq_port->fpiclk = clk_get_fpi(); 715 port->irq = tx_irq; /* unused, just to be backward-compatibe */
724 if (IS_ERR(ltq_port->fpiclk)) { 716 port->mapbase = mmres->start;
725 pr_err("failed to get fpi clk\n");
726 return -ENOENT;
727 }
728 717
729 /* not all asc ports have clock gates, lets ignore the return code */ 718 ltq_port->clk = clk;
730 ltq_port->clk = clk_get(&pdev->dev, NULL);
731 719
732 ltq_port->tx_irq = irqres[0].start; 720 ltq_port->tx_irq = tx_irq;
733 ltq_port->rx_irq = irqres[1].start; 721 ltq_port->rx_irq = rx_irq;
734 ltq_port->err_irq = irqres[2].start; 722 ltq_port->err_irq = err_irq;
735 723
736 lqasc_port[line] = ltq_port; 724 lqasc_port[pdev->id] = ltq_port;
737 platform_set_drvdata(pdev, ltq_port); 725 platform_set_drvdata(pdev, ltq_port);
738 726
739 ret = uart_add_one_port(&lqasc_reg, port); 727 ret = uart_add_one_port(&lqasc_reg, port);
@@ -741,17 +729,10 @@ lqasc_probe(struct platform_device *pdev)
741 return ret; 729 return ret;
742} 730}
743 731
744static const struct of_device_id ltq_asc_match[] = {
745 { .compatible = DRVNAME },
746 {},
747};
748MODULE_DEVICE_TABLE(of, ltq_asc_match);
749
750static struct platform_driver lqasc_driver = { 732static struct platform_driver lqasc_driver = {
751 .driver = { 733 .driver = {
752 .name = DRVNAME, 734 .name = DRVNAME,
753 .owner = THIS_MODULE, 735 .owner = THIS_MODULE,
754 .of_match_table = ltq_asc_match,
755 }, 736 },
756}; 737};
757 738
diff --git a/drivers/tty/serial/lpc32xx_hs.c b/drivers/tty/serial/lpc32xx_hs.c
deleted file mode 100644
index 0e86bff3fe2..00000000000
--- a/drivers/tty/serial/lpc32xx_hs.c
+++ /dev/null
@@ -1,823 +0,0 @@
1/*
2 * High Speed Serial Ports on NXP LPC32xx SoC
3 *
4 * Authors: Kevin Wells <kevin.wells@nxp.com>
5 * Roland Stigge <stigge@antcom.de>
6 *
7 * Copyright (C) 2010 NXP Semiconductors
8 * Copyright (C) 2012 Roland Stigge
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/ioport.h>
23#include <linux/init.h>
24#include <linux/console.h>
25#include <linux/sysrq.h>
26#include <linux/tty.h>
27#include <linux/tty_flip.h>
28#include <linux/serial_core.h>
29#include <linux/serial.h>
30#include <linux/platform_device.h>
31#include <linux/delay.h>
32#include <linux/nmi.h>
33#include <linux/io.h>
34#include <linux/irq.h>
35#include <linux/gpio.h>
36#include <linux/of.h>
37#include <mach/platform.h>
38#include <mach/hardware.h>
39
40/*
41 * High Speed UART register offsets
42 */
43#define LPC32XX_HSUART_FIFO(x) ((x) + 0x00)
44#define LPC32XX_HSUART_LEVEL(x) ((x) + 0x04)
45#define LPC32XX_HSUART_IIR(x) ((x) + 0x08)
46#define LPC32XX_HSUART_CTRL(x) ((x) + 0x0C)
47#define LPC32XX_HSUART_RATE(x) ((x) + 0x10)
48
49#define LPC32XX_HSU_BREAK_DATA (1 << 10)
50#define LPC32XX_HSU_ERROR_DATA (1 << 9)
51#define LPC32XX_HSU_RX_EMPTY (1 << 8)
52
53#define LPC32XX_HSU_TX_LEV(n) (((n) >> 8) & 0xFF)
54#define LPC32XX_HSU_RX_LEV(n) ((n) & 0xFF)
55
56#define LPC32XX_HSU_TX_INT_SET (1 << 6)
57#define LPC32XX_HSU_RX_OE_INT (1 << 5)
58#define LPC32XX_HSU_BRK_INT (1 << 4)
59#define LPC32XX_HSU_FE_INT (1 << 3)
60#define LPC32XX_HSU_RX_TIMEOUT_INT (1 << 2)
61#define LPC32XX_HSU_RX_TRIG_INT (1 << 1)
62#define LPC32XX_HSU_TX_INT (1 << 0)
63
64#define LPC32XX_HSU_HRTS_INV (1 << 21)
65#define LPC32XX_HSU_HRTS_TRIG_8B (0x0 << 19)
66#define LPC32XX_HSU_HRTS_TRIG_16B (0x1 << 19)
67#define LPC32XX_HSU_HRTS_TRIG_32B (0x2 << 19)
68#define LPC32XX_HSU_HRTS_TRIG_48B (0x3 << 19)
69#define LPC32XX_HSU_HRTS_EN (1 << 18)
70#define LPC32XX_HSU_TMO_DISABLED (0x0 << 16)
71#define LPC32XX_HSU_TMO_INACT_4B (0x1 << 16)
72#define LPC32XX_HSU_TMO_INACT_8B (0x2 << 16)
73#define LPC32XX_HSU_TMO_INACT_16B (0x3 << 16)
74#define LPC32XX_HSU_HCTS_INV (1 << 15)
75#define LPC32XX_HSU_HCTS_EN (1 << 14)
76#define LPC32XX_HSU_OFFSET(n) ((n) << 9)
77#define LPC32XX_HSU_BREAK (1 << 8)
78#define LPC32XX_HSU_ERR_INT_EN (1 << 7)
79#define LPC32XX_HSU_RX_INT_EN (1 << 6)
80#define LPC32XX_HSU_TX_INT_EN (1 << 5)
81#define LPC32XX_HSU_RX_TL1B (0x0 << 2)
82#define LPC32XX_HSU_RX_TL4B (0x1 << 2)
83#define LPC32XX_HSU_RX_TL8B (0x2 << 2)
84#define LPC32XX_HSU_RX_TL16B (0x3 << 2)
85#define LPC32XX_HSU_RX_TL32B (0x4 << 2)
86#define LPC32XX_HSU_RX_TL48B (0x5 << 2)
87#define LPC32XX_HSU_TX_TLEMPTY (0x0 << 0)
88#define LPC32XX_HSU_TX_TL0B (0x0 << 0)
89#define LPC32XX_HSU_TX_TL4B (0x1 << 0)
90#define LPC32XX_HSU_TX_TL8B (0x2 << 0)
91#define LPC32XX_HSU_TX_TL16B (0x3 << 0)
92
93#define MODNAME "lpc32xx_hsuart"
94
95struct lpc32xx_hsuart_port {
96 struct uart_port port;
97};
98
99#define FIFO_READ_LIMIT 128
100#define MAX_PORTS 3
101#define LPC32XX_TTY_NAME "ttyTX"
102static struct lpc32xx_hsuart_port lpc32xx_hs_ports[MAX_PORTS];
103
104#ifdef CONFIG_SERIAL_HS_LPC32XX_CONSOLE
105static void wait_for_xmit_empty(struct uart_port *port)
106{
107 unsigned int timeout = 10000;
108
109 do {
110 if (LPC32XX_HSU_TX_LEV(readl(LPC32XX_HSUART_LEVEL(
111 port->membase))) == 0)
112 break;
113 if (--timeout == 0)
114 break;
115 udelay(1);
116 } while (1);
117}
118
119static void wait_for_xmit_ready(struct uart_port *port)
120{
121 unsigned int timeout = 10000;
122
123 while (1) {
124 if (LPC32XX_HSU_TX_LEV(readl(LPC32XX_HSUART_LEVEL(
125 port->membase))) < 32)
126 break;
127 if (--timeout == 0)
128 break;
129 udelay(1);
130 }
131}
132
133static void lpc32xx_hsuart_console_putchar(struct uart_port *port, int ch)
134{
135 wait_for_xmit_ready(port);
136 writel((u32)ch, LPC32XX_HSUART_FIFO(port->membase));
137}
138
139static void lpc32xx_hsuart_console_write(struct console *co, const char *s,
140 unsigned int count)
141{
142 struct lpc32xx_hsuart_port *up = &lpc32xx_hs_ports[co->index];
143 unsigned long flags;
144 int locked = 1;
145
146 touch_nmi_watchdog();
147 local_irq_save(flags);
148 if (up->port.sysrq)
149 locked = 0;
150 else if (oops_in_progress)
151 locked = spin_trylock(&up->port.lock);
152 else
153 spin_lock(&up->port.lock);
154
155 uart_console_write(&up->port, s, count, lpc32xx_hsuart_console_putchar);
156 wait_for_xmit_empty(&up->port);
157
158 if (locked)
159 spin_unlock(&up->port.lock);
160 local_irq_restore(flags);
161}
162
163static int __init lpc32xx_hsuart_console_setup(struct console *co,
164 char *options)
165{
166 struct uart_port *port;
167 int baud = 115200;
168 int bits = 8;
169 int parity = 'n';
170 int flow = 'n';
171
172 if (co->index >= MAX_PORTS)
173 co->index = 0;
174
175 port = &lpc32xx_hs_ports[co->index].port;
176 if (!port->membase)
177 return -ENODEV;
178
179 if (options)
180 uart_parse_options(options, &baud, &parity, &bits, &flow);
181
182 return uart_set_options(port, co, baud, parity, bits, flow);
183}
184
185static struct uart_driver lpc32xx_hsuart_reg;
186static struct console lpc32xx_hsuart_console = {
187 .name = LPC32XX_TTY_NAME,
188 .write = lpc32xx_hsuart_console_write,
189 .device = uart_console_device,
190 .setup = lpc32xx_hsuart_console_setup,
191 .flags = CON_PRINTBUFFER,
192 .index = -1,
193 .data = &lpc32xx_hsuart_reg,
194};
195
196static int __init lpc32xx_hsuart_console_init(void)
197{
198 register_console(&lpc32xx_hsuart_console);
199 return 0;
200}
201console_initcall(lpc32xx_hsuart_console_init);
202
203#define LPC32XX_HSUART_CONSOLE (&lpc32xx_hsuart_console)
204#else
205#define LPC32XX_HSUART_CONSOLE NULL
206#endif
207
208static struct uart_driver lpc32xx_hs_reg = {
209 .owner = THIS_MODULE,
210 .driver_name = MODNAME,
211 .dev_name = LPC32XX_TTY_NAME,
212 .nr = MAX_PORTS,
213 .cons = LPC32XX_HSUART_CONSOLE,
214};
215static int uarts_registered;
216
217static unsigned int __serial_get_clock_div(unsigned long uartclk,
218 unsigned long rate)
219{
220 u32 div, goodrate, hsu_rate, l_hsu_rate, comprate;
221 u32 rate_diff;
222
223 /* Find the closest divider to get the desired clock rate */
224 div = uartclk / rate;
225 goodrate = hsu_rate = (div / 14) - 1;
226 if (hsu_rate != 0)
227 hsu_rate--;
228
229 /* Tweak divider */
230 l_hsu_rate = hsu_rate + 3;
231 rate_diff = 0xFFFFFFFF;
232
233 while (hsu_rate < l_hsu_rate) {
234 comprate = uartclk / ((hsu_rate + 1) * 14);
235 if (abs(comprate - rate) < rate_diff) {
236 goodrate = hsu_rate;
237 rate_diff = abs(comprate - rate);
238 }
239
240 hsu_rate++;
241 }
242 if (hsu_rate > 0xFF)
243 hsu_rate = 0xFF;
244
245 return goodrate;
246}
247
248static void __serial_uart_flush(struct uart_port *port)
249{
250 u32 tmp;
251 int cnt = 0;
252
253 while ((readl(LPC32XX_HSUART_LEVEL(port->membase)) > 0) &&
254 (cnt++ < FIFO_READ_LIMIT))
255 tmp = readl(LPC32XX_HSUART_FIFO(port->membase));
256}
257
258static void __serial_lpc32xx_rx(struct uart_port *port)
259{
260 unsigned int tmp, flag;
261 struct tty_struct *tty = tty_port_tty_get(&port->state->port);
262
263 if (!tty) {
264 /* Discard data: no tty available */
265 while (!(readl(LPC32XX_HSUART_FIFO(port->membase)) &
266 LPC32XX_HSU_RX_EMPTY))
267 ;
268
269 return;
270 }
271
272 /* Read data from FIFO and push into terminal */
273 tmp = readl(LPC32XX_HSUART_FIFO(port->membase));
274 while (!(tmp & LPC32XX_HSU_RX_EMPTY)) {
275 flag = TTY_NORMAL;
276 port->icount.rx++;
277
278 if (tmp & LPC32XX_HSU_ERROR_DATA) {
279 /* Framing error */
280 writel(LPC32XX_HSU_FE_INT,
281 LPC32XX_HSUART_IIR(port->membase));
282 port->icount.frame++;
283 flag = TTY_FRAME;
284 tty_insert_flip_char(tty, 0, TTY_FRAME);
285 }
286
287 tty_insert_flip_char(tty, (tmp & 0xFF), flag);
288
289 tmp = readl(LPC32XX_HSUART_FIFO(port->membase));
290 }
291 tty_flip_buffer_push(tty);
292 tty_kref_put(tty);
293}
294
295static void __serial_lpc32xx_tx(struct uart_port *port)
296{
297 struct circ_buf *xmit = &port->state->xmit;
298 unsigned int tmp;
299
300 if (port->x_char) {
301 writel((u32)port->x_char, LPC32XX_HSUART_FIFO(port->membase));
302 port->icount.tx++;
303 port->x_char = 0;
304 return;
305 }
306
307 if (uart_circ_empty(xmit) || uart_tx_stopped(port))
308 goto exit_tx;
309
310 /* Transfer data */
311 while (LPC32XX_HSU_TX_LEV(readl(
312 LPC32XX_HSUART_LEVEL(port->membase))) < 64) {
313 writel((u32) xmit->buf[xmit->tail],
314 LPC32XX_HSUART_FIFO(port->membase));
315 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
316 port->icount.tx++;
317 if (uart_circ_empty(xmit))
318 break;
319 }
320
321 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
322 uart_write_wakeup(port);
323
324exit_tx:
325 if (uart_circ_empty(xmit)) {
326 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
327 tmp &= ~LPC32XX_HSU_TX_INT_EN;
328 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
329 }
330}
331
332static irqreturn_t serial_lpc32xx_interrupt(int irq, void *dev_id)
333{
334 struct uart_port *port = dev_id;
335 struct tty_struct *tty = tty_port_tty_get(&port->state->port);
336 u32 status;
337
338 spin_lock(&port->lock);
339
340 /* Read UART status and clear latched interrupts */
341 status = readl(LPC32XX_HSUART_IIR(port->membase));
342
343 if (status & LPC32XX_HSU_BRK_INT) {
344 /* Break received */
345 writel(LPC32XX_HSU_BRK_INT, LPC32XX_HSUART_IIR(port->membase));
346 port->icount.brk++;
347 uart_handle_break(port);
348 }
349
350 /* Framing error */
351 if (status & LPC32XX_HSU_FE_INT)
352 writel(LPC32XX_HSU_FE_INT, LPC32XX_HSUART_IIR(port->membase));
353
354 if (status & LPC32XX_HSU_RX_OE_INT) {
355 /* Receive FIFO overrun */
356 writel(LPC32XX_HSU_RX_OE_INT,
357 LPC32XX_HSUART_IIR(port->membase));
358 port->icount.overrun++;
359 if (tty) {
360 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
361 tty_schedule_flip(tty);
362 }
363 }
364
365 /* Data received? */
366 if (status & (LPC32XX_HSU_RX_TIMEOUT_INT | LPC32XX_HSU_RX_TRIG_INT)) {
367 __serial_lpc32xx_rx(port);
368 if (tty)
369 tty_flip_buffer_push(tty);
370 }
371
372 /* Transmit data request? */
373 if ((status & LPC32XX_HSU_TX_INT) && (!uart_tx_stopped(port))) {
374 writel(LPC32XX_HSU_TX_INT, LPC32XX_HSUART_IIR(port->membase));
375 __serial_lpc32xx_tx(port);
376 }
377
378 spin_unlock(&port->lock);
379 tty_kref_put(tty);
380
381 return IRQ_HANDLED;
382}
383
384/* port->lock is not held. */
385static unsigned int serial_lpc32xx_tx_empty(struct uart_port *port)
386{
387 unsigned int ret = 0;
388
389 if (LPC32XX_HSU_TX_LEV(readl(LPC32XX_HSUART_LEVEL(port->membase))) == 0)
390 ret = TIOCSER_TEMT;
391
392 return ret;
393}
394
395/* port->lock held by caller. */
396static void serial_lpc32xx_set_mctrl(struct uart_port *port,
397 unsigned int mctrl)
398{
399 /* No signals are supported on HS UARTs */
400}
401
402/* port->lock is held by caller and interrupts are disabled. */
403static unsigned int serial_lpc32xx_get_mctrl(struct uart_port *port)
404{
405 /* No signals are supported on HS UARTs */
406 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
407}
408
409/* port->lock held by caller. */
410static void serial_lpc32xx_stop_tx(struct uart_port *port)
411{
412 u32 tmp;
413
414 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
415 tmp &= ~LPC32XX_HSU_TX_INT_EN;
416 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
417}
418
419/* port->lock held by caller. */
420static void serial_lpc32xx_start_tx(struct uart_port *port)
421{
422 u32 tmp;
423
424 __serial_lpc32xx_tx(port);
425 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
426 tmp |= LPC32XX_HSU_TX_INT_EN;
427 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
428}
429
430/* port->lock held by caller. */
431static void serial_lpc32xx_stop_rx(struct uart_port *port)
432{
433 u32 tmp;
434
435 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
436 tmp &= ~(LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN);
437 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
438
439 writel((LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT |
440 LPC32XX_HSU_FE_INT), LPC32XX_HSUART_IIR(port->membase));
441}
442
443/* port->lock held by caller. */
444static void serial_lpc32xx_enable_ms(struct uart_port *port)
445{
446 /* Modem status is not supported */
447}
448
449/* port->lock is not held. */
450static void serial_lpc32xx_break_ctl(struct uart_port *port,
451 int break_state)
452{
453 unsigned long flags;
454 u32 tmp;
455
456 spin_lock_irqsave(&port->lock, flags);
457 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
458 if (break_state != 0)
459 tmp |= LPC32XX_HSU_BREAK;
460 else
461 tmp &= ~LPC32XX_HSU_BREAK;
462 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
463 spin_unlock_irqrestore(&port->lock, flags);
464}
465
466/* LPC3250 Errata HSUART.1: Hang workaround via loopback mode on inactivity */
467static void lpc32xx_loopback_set(resource_size_t mapbase, int state)
468{
469 int bit;
470 u32 tmp;
471
472 switch (mapbase) {
473 case LPC32XX_HS_UART1_BASE:
474 bit = 0;
475 break;
476 case LPC32XX_HS_UART2_BASE:
477 bit = 1;
478 break;
479 case LPC32XX_HS_UART7_BASE:
480 bit = 6;
481 break;
482 default:
483 WARN(1, "lpc32xx_hs: Warning: Unknown port at %08x\n", mapbase);
484 return;
485 }
486
487 tmp = readl(LPC32XX_UARTCTL_CLOOP);
488 if (state)
489 tmp |= (1 << bit);
490 else
491 tmp &= ~(1 << bit);
492 writel(tmp, LPC32XX_UARTCTL_CLOOP);
493}
494
495/* port->lock is not held. */
496static int serial_lpc32xx_startup(struct uart_port *port)
497{
498 int retval;
499 unsigned long flags;
500 u32 tmp;
501
502 spin_lock_irqsave(&port->lock, flags);
503
504 __serial_uart_flush(port);
505
506 writel((LPC32XX_HSU_TX_INT | LPC32XX_HSU_FE_INT |
507 LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT),
508 LPC32XX_HSUART_IIR(port->membase));
509
510 writel(0xFF, LPC32XX_HSUART_RATE(port->membase));
511
512 /*
513 * Set receiver timeout, HSU offset of 20, no break, no interrupts,
514 * and default FIFO trigger levels
515 */
516 tmp = LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
517 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B;
518 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
519
520 lpc32xx_loopback_set(port->mapbase, 0); /* get out of loopback mode */
521
522 spin_unlock_irqrestore(&port->lock, flags);
523
524 retval = request_irq(port->irq, serial_lpc32xx_interrupt,
525 0, MODNAME, port);
526 if (!retval)
527 writel((tmp | LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN),
528 LPC32XX_HSUART_CTRL(port->membase));
529
530 return retval;
531}
532
533/* port->lock is not held. */
534static void serial_lpc32xx_shutdown(struct uart_port *port)
535{
536 u32 tmp;
537 unsigned long flags;
538
539 spin_lock_irqsave(&port->lock, flags);
540
541 tmp = LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
542 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B;
543 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
544
545 lpc32xx_loopback_set(port->mapbase, 1); /* go to loopback mode */
546
547 spin_unlock_irqrestore(&port->lock, flags);
548
549 free_irq(port->irq, port);
550}
551
552/* port->lock is not held. */
553static void serial_lpc32xx_set_termios(struct uart_port *port,
554 struct ktermios *termios,
555 struct ktermios *old)
556{
557 unsigned long flags;
558 unsigned int baud, quot;
559 u32 tmp;
560
561 /* Always 8-bit, no parity, 1 stop bit */
562 termios->c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD);
563 termios->c_cflag |= CS8;
564
565 termios->c_cflag &= ~(HUPCL | CMSPAR | CLOCAL | CRTSCTS);
566
567 baud = uart_get_baud_rate(port, termios, old, 0,
568 port->uartclk / 14);
569
570 quot = __serial_get_clock_div(port->uartclk, baud);
571
572 spin_lock_irqsave(&port->lock, flags);
573
574 /* Ignore characters? */
575 tmp = readl(LPC32XX_HSUART_CTRL(port->membase));
576 if ((termios->c_cflag & CREAD) == 0)
577 tmp &= ~(LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN);
578 else
579 tmp |= LPC32XX_HSU_RX_INT_EN | LPC32XX_HSU_ERR_INT_EN;
580 writel(tmp, LPC32XX_HSUART_CTRL(port->membase));
581
582 writel(quot, LPC32XX_HSUART_RATE(port->membase));
583
584 uart_update_timeout(port, termios->c_cflag, baud);
585
586 spin_unlock_irqrestore(&port->lock, flags);
587
588 /* Don't rewrite B0 */
589 if (tty_termios_baud_rate(termios))
590 tty_termios_encode_baud_rate(termios, baud, baud);
591}
592
593static const char *serial_lpc32xx_type(struct uart_port *port)
594{
595 return MODNAME;
596}
597
598static void serial_lpc32xx_release_port(struct uart_port *port)
599{
600 if ((port->iotype == UPIO_MEM32) && (port->mapbase)) {
601 if (port->flags & UPF_IOREMAP) {
602 iounmap(port->membase);
603 port->membase = NULL;
604 }
605
606 release_mem_region(port->mapbase, SZ_4K);
607 }
608}
609
610static int serial_lpc32xx_request_port(struct uart_port *port)
611{
612 int ret = -ENODEV;
613
614 if ((port->iotype == UPIO_MEM32) && (port->mapbase)) {
615 ret = 0;
616
617 if (!request_mem_region(port->mapbase, SZ_4K, MODNAME))
618 ret = -EBUSY;
619 else if (port->flags & UPF_IOREMAP) {
620 port->membase = ioremap(port->mapbase, SZ_4K);
621 if (!port->membase) {
622 release_mem_region(port->mapbase, SZ_4K);
623 ret = -ENOMEM;
624 }
625 }
626 }
627
628 return ret;
629}
630
631static void serial_lpc32xx_config_port(struct uart_port *port, int uflags)
632{
633 int ret;
634
635 ret = serial_lpc32xx_request_port(port);
636 if (ret < 0)
637 return;
638 port->type = PORT_UART00;
639 port->fifosize = 64;
640
641 __serial_uart_flush(port);
642
643 writel((LPC32XX_HSU_TX_INT | LPC32XX_HSU_FE_INT |
644 LPC32XX_HSU_BRK_INT | LPC32XX_HSU_RX_OE_INT),
645 LPC32XX_HSUART_IIR(port->membase));
646
647 writel(0xFF, LPC32XX_HSUART_RATE(port->membase));
648
649 /* Set receiver timeout, HSU offset of 20, no break, no interrupts,
650 and default FIFO trigger levels */
651 writel(LPC32XX_HSU_TX_TL8B | LPC32XX_HSU_RX_TL32B |
652 LPC32XX_HSU_OFFSET(20) | LPC32XX_HSU_TMO_INACT_4B,
653 LPC32XX_HSUART_CTRL(port->membase));
654}
655
656static int serial_lpc32xx_verify_port(struct uart_port *port,
657 struct serial_struct *ser)
658{
659 int ret = 0;
660
661 if (ser->type != PORT_UART00)
662 ret = -EINVAL;
663
664 return ret;
665}
666
667static struct uart_ops serial_lpc32xx_pops = {
668 .tx_empty = serial_lpc32xx_tx_empty,
669 .set_mctrl = serial_lpc32xx_set_mctrl,
670 .get_mctrl = serial_lpc32xx_get_mctrl,
671 .stop_tx = serial_lpc32xx_stop_tx,
672 .start_tx = serial_lpc32xx_start_tx,
673 .stop_rx = serial_lpc32xx_stop_rx,
674 .enable_ms = serial_lpc32xx_enable_ms,
675 .break_ctl = serial_lpc32xx_break_ctl,
676 .startup = serial_lpc32xx_startup,
677 .shutdown = serial_lpc32xx_shutdown,
678 .set_termios = serial_lpc32xx_set_termios,
679 .type = serial_lpc32xx_type,
680 .release_port = serial_lpc32xx_release_port,
681 .request_port = serial_lpc32xx_request_port,
682 .config_port = serial_lpc32xx_config_port,
683 .verify_port = serial_lpc32xx_verify_port,
684};
685
686/*
687 * Register a set of serial devices attached to a platform device
688 */
689static int serial_hs_lpc32xx_probe(struct platform_device *pdev)
690{
691 struct lpc32xx_hsuart_port *p = &lpc32xx_hs_ports[uarts_registered];
692 int ret = 0;
693 struct resource *res;
694
695 if (uarts_registered >= MAX_PORTS) {
696 dev_err(&pdev->dev,
697 "Error: Number of possible ports exceeded (%d)!\n",
698 uarts_registered + 1);
699 return -ENXIO;
700 }
701
702 memset(p, 0, sizeof(*p));
703
704 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
705 if (!res) {
706 dev_err(&pdev->dev,
707 "Error getting mem resource for HS UART port %d\n",
708 uarts_registered);
709 return -ENXIO;
710 }
711 p->port.mapbase = res->start;
712 p->port.membase = NULL;
713
714 p->port.irq = platform_get_irq(pdev, 0);
715 if (p->port.irq < 0) {
716 dev_err(&pdev->dev, "Error getting irq for HS UART port %d\n",
717 uarts_registered);
718 return p->port.irq;
719 }
720
721 p->port.iotype = UPIO_MEM32;
722 p->port.uartclk = LPC32XX_MAIN_OSC_FREQ;
723 p->port.regshift = 2;
724 p->port.flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT | UPF_IOREMAP;
725 p->port.dev = &pdev->dev;
726 p->port.ops = &serial_lpc32xx_pops;
727 p->port.line = uarts_registered++;
728 spin_lock_init(&p->port.lock);
729
730 /* send port to loopback mode by default */
731 lpc32xx_loopback_set(p->port.mapbase, 1);
732
733 ret = uart_add_one_port(&lpc32xx_hs_reg, &p->port);
734
735 platform_set_drvdata(pdev, p);
736
737 return ret;
738}
739
740/*
741 * Remove serial ports registered against a platform device.
742 */
743static int serial_hs_lpc32xx_remove(struct platform_device *pdev)
744{
745 struct lpc32xx_hsuart_port *p = platform_get_drvdata(pdev);
746
747 uart_remove_one_port(&lpc32xx_hs_reg, &p->port);
748
749 return 0;
750}
751
752
753#ifdef CONFIG_PM
754static int serial_hs_lpc32xx_suspend(struct platform_device *pdev,
755 pm_message_t state)
756{
757 struct lpc32xx_hsuart_port *p = platform_get_drvdata(pdev);
758
759 uart_suspend_port(&lpc32xx_hs_reg, &p->port);
760
761 return 0;
762}
763
764static int serial_hs_lpc32xx_resume(struct platform_device *pdev)
765{
766 struct lpc32xx_hsuart_port *p = platform_get_drvdata(pdev);
767
768 uart_resume_port(&lpc32xx_hs_reg, &p->port);
769
770 return 0;
771}
772#else
773#define serial_hs_lpc32xx_suspend NULL
774#define serial_hs_lpc32xx_resume NULL
775#endif
776
777static const struct of_device_id serial_hs_lpc32xx_dt_ids[] = {
778 { .compatible = "nxp,lpc3220-hsuart" },
779 { /* sentinel */ }
780};
781
782MODULE_DEVICE_TABLE(of, serial_hs_lpc32xx_dt_ids);
783
784static struct platform_driver serial_hs_lpc32xx_driver = {
785 .probe = serial_hs_lpc32xx_probe,
786 .remove = serial_hs_lpc32xx_remove,
787 .suspend = serial_hs_lpc32xx_suspend,
788 .resume = serial_hs_lpc32xx_resume,
789 .driver = {
790 .name = MODNAME,
791 .owner = THIS_MODULE,
792 .of_match_table = serial_hs_lpc32xx_dt_ids,
793 },
794};
795
796static int __init lpc32xx_hsuart_init(void)
797{
798 int ret;
799
800 ret = uart_register_driver(&lpc32xx_hs_reg);
801 if (ret)
802 return ret;
803
804 ret = platform_driver_register(&serial_hs_lpc32xx_driver);
805 if (ret)
806 uart_unregister_driver(&lpc32xx_hs_reg);
807
808 return ret;
809}
810
811static void __exit lpc32xx_hsuart_exit(void)
812{
813 platform_driver_unregister(&serial_hs_lpc32xx_driver);
814 uart_unregister_driver(&lpc32xx_hs_reg);
815}
816
817module_init(lpc32xx_hsuart_init);
818module_exit(lpc32xx_hsuart_exit);
819
820MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com>");
821MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
822MODULE_DESCRIPTION("NXP LPC32XX High Speed UART driver");
823MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/m32r_sio.c b/drivers/tty/serial/m32r_sio.c
index b13949ad340..8e07517f8ac 100644
--- a/drivers/tty/serial/m32r_sio.c
+++ b/drivers/tty/serial/m32r_sio.c
@@ -32,18 +32,20 @@
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>
36#include <linux/ioport.h> 35#include <linux/ioport.h>
37#include <linux/init.h> 36#include <linux/init.h>
38#include <linux/console.h> 37#include <linux/console.h>
39#include <linux/sysrq.h> 38#include <linux/sysrq.h>
40#include <linux/serial.h> 39#include <linux/serial.h>
40#include <linux/serialP.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42 42
43#include <asm/m32r.h> 43#include <asm/m32r.h>
44#include <asm/io.h> 44#include <asm/io.h>
45#include <asm/irq.h> 45#include <asm/irq.h>
46 46
47#define PORT_M32R_BASE PORT_M32R_SIO
48#define PORT_INDEX(x) (x - PORT_M32R_BASE + 1)
47#define BAUD_RATE 115200 49#define BAUD_RATE 115200
48 50
49#include <linux/serial_core.h> 51#include <linux/serial_core.h>
@@ -67,6 +69,13 @@
67 69
68#define PASS_LIMIT 256 70#define PASS_LIMIT 256
69 71
72/*
73 * We default to IRQ0 for the "no irq" hack. Some
74 * machine types want others as well - they're free
75 * to redefine this in their header file.
76 */
77#define is_real_interrupt(irq) ((irq) != 0)
78
70#define BASE_BAUD 115200 79#define BASE_BAUD 115200
71 80
72/* Standard COM flags */ 81/* Standard COM flags */
@@ -130,6 +139,22 @@ struct irq_info {
130 139
131static struct irq_info irq_lists[NR_IRQS]; 140static struct irq_info irq_lists[NR_IRQS];
132 141
142/*
143 * Here we define the default xmit fifo size used for each type of UART.
144 */
145static const struct serial_uart_config uart_config[] = {
146 [PORT_UNKNOWN] = {
147 .name = "unknown",
148 .dfl_xmit_fifo_size = 1,
149 .flags = 0,
150 },
151 [PORT_INDEX(PORT_M32R_SIO)] = {
152 .name = "M32RSIO",
153 .dfl_xmit_fifo_size = 1,
154 .flags = 0,
155 },
156};
157
133#ifdef CONFIG_SERIAL_M32R_PLDSIO 158#ifdef CONFIG_SERIAL_M32R_PLDSIO
134 159
135#define __sio_in(x) inw((unsigned long)(x)) 160#define __sio_in(x) inw((unsigned long)(x))
@@ -614,7 +639,7 @@ static int m32r_sio_startup(struct uart_port *port)
614 * hardware interrupt, we use a timer-based system. The original 639 * hardware interrupt, we use a timer-based system. The original
615 * driver used to do this with IRQ0. 640 * driver used to do this with IRQ0.
616 */ 641 */
617 if (!up->port.irq) { 642 if (!is_real_interrupt(up->port.irq)) {
618 unsigned int timeout = up->port.timeout; 643 unsigned int timeout = up->port.timeout;
619 644
620 timeout = timeout > 6 ? (timeout / 2 - 2) : 1; 645 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
@@ -661,7 +686,7 @@ static void m32r_sio_shutdown(struct uart_port *port)
661 686
662 sio_init(); 687 sio_init();
663 688
664 if (!up->port.irq) 689 if (!is_real_interrupt(up->port.irq))
665 del_timer_sync(&up->timer); 690 del_timer_sync(&up->timer);
666 else 691 else
667 serial_unlink_irq_chain(up); 692 serial_unlink_irq_chain(up);
@@ -889,7 +914,8 @@ static void m32r_sio_config_port(struct uart_port *port, int unused)
889 914
890 spin_lock_irqsave(&up->port.lock, flags); 915 spin_lock_irqsave(&up->port.lock, flags);
891 916
892 up->port.fifosize = 1; 917 up->port.type = (PORT_M32R_SIO - PORT_M32R_BASE + 1);
918 up->port.fifosize = uart_config[up->port.type].dfl_xmit_fifo_size;
893 919
894 spin_unlock_irqrestore(&up->port.lock, flags); 920 spin_unlock_irqrestore(&up->port.lock, flags);
895} 921}
@@ -897,11 +923,23 @@ static void m32r_sio_config_port(struct uart_port *port, int unused)
897static int 923static int
898m32r_sio_verify_port(struct uart_port *port, struct serial_struct *ser) 924m32r_sio_verify_port(struct uart_port *port, struct serial_struct *ser)
899{ 925{
900 if (ser->irq >= nr_irqs || ser->irq < 0 || ser->baud_base < 9600) 926 if (ser->irq >= nr_irqs || ser->irq < 0 ||
927 ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
928 ser->type >= ARRAY_SIZE(uart_config))
901 return -EINVAL; 929 return -EINVAL;
902 return 0; 930 return 0;
903} 931}
904 932
933static const char *
934m32r_sio_type(struct uart_port *port)
935{
936 int type = port->type;
937
938 if (type >= ARRAY_SIZE(uart_config))
939 type = 0;
940 return uart_config[type].name;
941}
942
905static struct uart_ops m32r_sio_pops = { 943static struct uart_ops m32r_sio_pops = {
906 .tx_empty = m32r_sio_tx_empty, 944 .tx_empty = m32r_sio_tx_empty,
907 .set_mctrl = m32r_sio_set_mctrl, 945 .set_mctrl = m32r_sio_set_mctrl,
@@ -915,6 +953,7 @@ static struct uart_ops m32r_sio_pops = {
915 .shutdown = m32r_sio_shutdown, 953 .shutdown = m32r_sio_shutdown,
916 .set_termios = m32r_sio_set_termios, 954 .set_termios = m32r_sio_set_termios,
917 .pm = m32r_sio_pm, 955 .pm = m32r_sio_pm,
956 .type = m32r_sio_type,
918 .release_port = m32r_sio_release_port, 957 .release_port = m32r_sio_release_port,
919 .request_port = m32r_sio_request_port, 958 .request_port = m32r_sio_request_port,
920 .config_port = m32r_sio_config_port, 959 .config_port = m32r_sio_config_port,
@@ -960,8 +999,11 @@ static void __init m32r_sio_register_ports(struct uart_driver *drv)
960 init_timer(&up->timer); 999 init_timer(&up->timer);
961 up->timer.function = m32r_sio_timeout; 1000 up->timer.function = m32r_sio_timeout;
962 1001
963 up->mcr_mask = ~0; 1002 /*
964 up->mcr_force = 0; 1003 * ALPHA_KLUDGE_MCR needs to be killed.
1004 */
1005 up->mcr_mask = ~ALPHA_KLUDGE_MCR;
1006 up->mcr_force = ALPHA_KLUDGE_MCR;
965 1007
966 uart_add_one_port(drv, &up->port); 1008 uart_add_one_port(drv, &up->port);
967 } 1009 }
diff --git a/drivers/tty/serial/m32r_sio.h b/drivers/tty/serial/m32r_sio.h
index 8129824496c..e9b7e11793b 100644
--- a/drivers/tty/serial/m32r_sio.h
+++ b/drivers/tty/serial/m32r_sio.h
@@ -15,7 +15,6 @@
15 * (at your option) any later version. 15 * (at your option) any later version.
16 */ 16 */
17 17
18#include <linux/pci.h>
19 18
20struct m32r_sio_probe { 19struct m32r_sio_probe {
21 struct module *owner; 20 struct module *owner;
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 7ce3197087b..7b951adac54 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -43,13 +43,10 @@
43#include <linux/delay.h> 43#include <linux/delay.h>
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/device.h> 45#include <linux/device.h>
46#include <linux/module.h>
47#include <linux/serial_core.h> 46#include <linux/serial_core.h>
48#include <linux/serial.h> 47#include <linux/serial.h>
49#include <linux/spi/spi.h> 48#include <linux/spi/spi.h>
50#include <linux/freezer.h> 49#include <linux/freezer.h>
51#include <linux/tty.h>
52#include <linux/tty_flip.h>
53 50
54#include <linux/serial_max3100.h> 51#include <linux/serial_max3100.h>
55 52
@@ -742,7 +739,7 @@ static struct uart_driver max3100_uart_driver = {
742}; 739};
743static int uart_driver_registered; 740static int uart_driver_registered;
744 741
745static int max3100_probe(struct spi_device *spi) 742static int __devinit max3100_probe(struct spi_device *spi)
746{ 743{
747 int i, retval; 744 int i, retval;
748 struct plat_max3100 *pdata; 745 struct plat_max3100 *pdata;
@@ -818,7 +815,7 @@ static int max3100_probe(struct spi_device *spi)
818 return 0; 815 return 0;
819} 816}
820 817
821static int max3100_remove(struct spi_device *spi) 818static int __devexit max3100_remove(struct spi_device *spi)
822{ 819{
823 struct max3100_port *s = dev_get_drvdata(&spi->dev); 820 struct max3100_port *s = dev_get_drvdata(&spi->dev);
824 int i; 821 int i;
@@ -827,16 +824,14 @@ static int max3100_remove(struct spi_device *spi)
827 824
828 /* find out the index for the chip we are removing */ 825 /* find out the index for the chip we are removing */
829 for (i = 0; i < MAX_MAX3100; i++) 826 for (i = 0; i < MAX_MAX3100; i++)
830 if (max3100s[i] == s) { 827 if (max3100s[i] == s)
831 dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i);
832 uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port);
833 kfree(max3100s[i]);
834 max3100s[i] = NULL;
835 break; 828 break;
836 }
837 829
838 WARN_ON(i == MAX_MAX3100); 830 dev_dbg(&spi->dev, "%s: removing port %d\n", __func__, i);
839 831 uart_remove_one_port(&max3100_uart_driver, &max3100s[i]->port);
832 kfree(max3100s[i]);
833 max3100s[i] = NULL;
834
840 /* check if this is the last chip we have */ 835 /* check if this is the last chip we have */
841 for (i = 0; i < MAX_MAX3100; i++) 836 for (i = 0; i < MAX_MAX3100; i++)
842 if (max3100s[i]) { 837 if (max3100s[i]) {
@@ -903,16 +898,27 @@ static int max3100_resume(struct spi_device *spi)
903static struct spi_driver max3100_driver = { 898static struct spi_driver max3100_driver = {
904 .driver = { 899 .driver = {
905 .name = "max3100", 900 .name = "max3100",
901 .bus = &spi_bus_type,
906 .owner = THIS_MODULE, 902 .owner = THIS_MODULE,
907 }, 903 },
908 904
909 .probe = max3100_probe, 905 .probe = max3100_probe,
910 .remove = max3100_remove, 906 .remove = __devexit_p(max3100_remove),
911 .suspend = max3100_suspend, 907 .suspend = max3100_suspend,
912 .resume = max3100_resume, 908 .resume = max3100_resume,
913}; 909};
914 910
915module_spi_driver(max3100_driver); 911static int __init max3100_init(void)
912{
913 return spi_register_driver(&max3100_driver);
914}
915module_init(max3100_init);
916
917static void __exit max3100_exit(void)
918{
919 spi_unregister_driver(&max3100_driver);
920}
921module_exit(max3100_exit);
916 922
917MODULE_DESCRIPTION("MAX3100 driver"); 923MODULE_DESCRIPTION("MAX3100 driver");
918MODULE_AUTHOR("Christian Pellegrin <chripell@evolware.org>"); 924MODULE_AUTHOR("Christian Pellegrin <chripell@evolware.org>");
diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
deleted file mode 100644
index a801f6872ca..00000000000
--- a/drivers/tty/serial/max310x.c
+++ /dev/null
@@ -1,1262 +0,0 @@
1/*
2 * Maxim (Dallas) MAX3107/8 serial driver
3 *
4 * Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
5 *
6 * Based on max3100.c, by Christian Pellegrin <chripell@evolware.org>
7 * Based on max3110.c, by Feng Tang <feng.tang@intel.com>
8 * Based on max3107.c, by Aavamobile
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 */
15
16/* TODO: MAX3109 support (Dual) */
17/* TODO: MAX14830 support (Quad) */
18
19#include <linux/module.h>
20#include <linux/device.h>
21#include <linux/serial_core.h>
22#include <linux/serial.h>
23#include <linux/tty.h>
24#include <linux/tty_flip.h>
25#include <linux/regmap.h>
26#include <linux/gpio.h>
27#include <linux/spi/spi.h>
28#include <linux/platform_data/max310x.h>
29
30#define MAX310X_MAJOR 204
31#define MAX310X_MINOR 209
32
33/* MAX310X register definitions */
34#define MAX310X_RHR_REG (0x00) /* RX FIFO */
35#define MAX310X_THR_REG (0x00) /* TX FIFO */
36#define MAX310X_IRQEN_REG (0x01) /* IRQ enable */
37#define MAX310X_IRQSTS_REG (0x02) /* IRQ status */
38#define MAX310X_LSR_IRQEN_REG (0x03) /* LSR IRQ enable */
39#define MAX310X_LSR_IRQSTS_REG (0x04) /* LSR IRQ status */
40#define MAX310X_SPCHR_IRQEN_REG (0x05) /* Special char IRQ enable */
41#define MAX310X_SPCHR_IRQSTS_REG (0x06) /* Special char IRQ status */
42#define MAX310X_STS_IRQEN_REG (0x07) /* Status IRQ enable */
43#define MAX310X_STS_IRQSTS_REG (0x08) /* Status IRQ status */
44#define MAX310X_MODE1_REG (0x09) /* MODE1 */
45#define MAX310X_MODE2_REG (0x0a) /* MODE2 */
46#define MAX310X_LCR_REG (0x0b) /* LCR */
47#define MAX310X_RXTO_REG (0x0c) /* RX timeout */
48#define MAX310X_HDPIXDELAY_REG (0x0d) /* Auto transceiver delays */
49#define MAX310X_IRDA_REG (0x0e) /* IRDA settings */
50#define MAX310X_FLOWLVL_REG (0x0f) /* Flow control levels */
51#define MAX310X_FIFOTRIGLVL_REG (0x10) /* FIFO IRQ trigger levels */
52#define MAX310X_TXFIFOLVL_REG (0x11) /* TX FIFO level */
53#define MAX310X_RXFIFOLVL_REG (0x12) /* RX FIFO level */
54#define MAX310X_FLOWCTRL_REG (0x13) /* Flow control */
55#define MAX310X_XON1_REG (0x14) /* XON1 character */
56#define MAX310X_XON2_REG (0x15) /* XON2 character */
57#define MAX310X_XOFF1_REG (0x16) /* XOFF1 character */
58#define MAX310X_XOFF2_REG (0x17) /* XOFF2 character */
59#define MAX310X_GPIOCFG_REG (0x18) /* GPIO config */
60#define MAX310X_GPIODATA_REG (0x19) /* GPIO data */
61#define MAX310X_PLLCFG_REG (0x1a) /* PLL config */
62#define MAX310X_BRGCFG_REG (0x1b) /* Baud rate generator conf */
63#define MAX310X_BRGDIVLSB_REG (0x1c) /* Baud rate divisor LSB */
64#define MAX310X_BRGDIVMSB_REG (0x1d) /* Baud rate divisor MSB */
65#define MAX310X_CLKSRC_REG (0x1e) /* Clock source */
66/* Only present in MAX3107 */
67#define MAX3107_REVID_REG (0x1f) /* Revision identification */
68
69/* IRQ register bits */
70#define MAX310X_IRQ_LSR_BIT (1 << 0) /* LSR interrupt */
71#define MAX310X_IRQ_SPCHR_BIT (1 << 1) /* Special char interrupt */
72#define MAX310X_IRQ_STS_BIT (1 << 2) /* Status interrupt */
73#define MAX310X_IRQ_RXFIFO_BIT (1 << 3) /* RX FIFO interrupt */
74#define MAX310X_IRQ_TXFIFO_BIT (1 << 4) /* TX FIFO interrupt */
75#define MAX310X_IRQ_TXEMPTY_BIT (1 << 5) /* TX FIFO empty interrupt */
76#define MAX310X_IRQ_RXEMPTY_BIT (1 << 6) /* RX FIFO empty interrupt */
77#define MAX310X_IRQ_CTS_BIT (1 << 7) /* CTS interrupt */
78
79/* LSR register bits */
80#define MAX310X_LSR_RXTO_BIT (1 << 0) /* RX timeout */
81#define MAX310X_LSR_RXOVR_BIT (1 << 1) /* RX overrun */
82#define MAX310X_LSR_RXPAR_BIT (1 << 2) /* RX parity error */
83#define MAX310X_LSR_FRERR_BIT (1 << 3) /* Frame error */
84#define MAX310X_LSR_RXBRK_BIT (1 << 4) /* RX break */
85#define MAX310X_LSR_RXNOISE_BIT (1 << 5) /* RX noise */
86#define MAX310X_LSR_CTS_BIT (1 << 7) /* CTS pin state */
87
88/* Special character register bits */
89#define MAX310X_SPCHR_XON1_BIT (1 << 0) /* XON1 character */
90#define MAX310X_SPCHR_XON2_BIT (1 << 1) /* XON2 character */
91#define MAX310X_SPCHR_XOFF1_BIT (1 << 2) /* XOFF1 character */
92#define MAX310X_SPCHR_XOFF2_BIT (1 << 3) /* XOFF2 character */
93#define MAX310X_SPCHR_BREAK_BIT (1 << 4) /* RX break */
94#define MAX310X_SPCHR_MULTIDROP_BIT (1 << 5) /* 9-bit multidrop addr char */
95
96/* Status register bits */
97#define MAX310X_STS_GPIO0_BIT (1 << 0) /* GPIO 0 interrupt */
98#define MAX310X_STS_GPIO1_BIT (1 << 1) /* GPIO 1 interrupt */
99#define MAX310X_STS_GPIO2_BIT (1 << 2) /* GPIO 2 interrupt */
100#define MAX310X_STS_GPIO3_BIT (1 << 3) /* GPIO 3 interrupt */
101#define MAX310X_STS_CLKREADY_BIT (1 << 5) /* Clock ready */
102#define MAX310X_STS_SLEEP_BIT (1 << 6) /* Sleep interrupt */
103
104/* MODE1 register bits */
105#define MAX310X_MODE1_RXDIS_BIT (1 << 0) /* RX disable */
106#define MAX310X_MODE1_TXDIS_BIT (1 << 1) /* TX disable */
107#define MAX310X_MODE1_TXHIZ_BIT (1 << 2) /* TX pin three-state */
108#define MAX310X_MODE1_RTSHIZ_BIT (1 << 3) /* RTS pin three-state */
109#define MAX310X_MODE1_TRNSCVCTRL_BIT (1 << 4) /* Transceiver ctrl enable */
110#define MAX310X_MODE1_FORCESLEEP_BIT (1 << 5) /* Force sleep mode */
111#define MAX310X_MODE1_AUTOSLEEP_BIT (1 << 6) /* Auto sleep enable */
112#define MAX310X_MODE1_IRQSEL_BIT (1 << 7) /* IRQ pin enable */
113
114/* MODE2 register bits */
115#define MAX310X_MODE2_RST_BIT (1 << 0) /* Chip reset */
116#define MAX310X_MODE2_FIFORST_BIT (1 << 1) /* FIFO reset */
117#define MAX310X_MODE2_RXTRIGINV_BIT (1 << 2) /* RX FIFO INT invert */
118#define MAX310X_MODE2_RXEMPTINV_BIT (1 << 3) /* RX FIFO empty INT invert */
119#define MAX310X_MODE2_SPCHR_BIT (1 << 4) /* Special chr detect enable */
120#define MAX310X_MODE2_LOOPBACK_BIT (1 << 5) /* Internal loopback enable */
121#define MAX310X_MODE2_MULTIDROP_BIT (1 << 6) /* 9-bit multidrop enable */
122#define MAX310X_MODE2_ECHOSUPR_BIT (1 << 7) /* ECHO suppression enable */
123
124/* LCR register bits */
125#define MAX310X_LCR_LENGTH0_BIT (1 << 0) /* Word length bit 0 */
126#define MAX310X_LCR_LENGTH1_BIT (1 << 1) /* Word length bit 1
127 *
128 * Word length bits table:
129 * 00 -> 5 bit words
130 * 01 -> 6 bit words
131 * 10 -> 7 bit words
132 * 11 -> 8 bit words
133 */
134#define MAX310X_LCR_STOPLEN_BIT (1 << 2) /* STOP length bit
135 *
136 * STOP length bit table:
137 * 0 -> 1 stop bit
138 * 1 -> 1-1.5 stop bits if
139 * word length is 5,
140 * 2 stop bits otherwise
141 */
142#define MAX310X_LCR_PARITY_BIT (1 << 3) /* Parity bit enable */
143#define MAX310X_LCR_EVENPARITY_BIT (1 << 4) /* Even parity bit enable */
144#define MAX310X_LCR_FORCEPARITY_BIT (1 << 5) /* 9-bit multidrop parity */
145#define MAX310X_LCR_TXBREAK_BIT (1 << 6) /* TX break enable */
146#define MAX310X_LCR_RTS_BIT (1 << 7) /* RTS pin control */
147#define MAX310X_LCR_WORD_LEN_5 (0x00)
148#define MAX310X_LCR_WORD_LEN_6 (0x01)
149#define MAX310X_LCR_WORD_LEN_7 (0x02)
150#define MAX310X_LCR_WORD_LEN_8 (0x03)
151
152/* IRDA register bits */
153#define MAX310X_IRDA_IRDAEN_BIT (1 << 0) /* IRDA mode enable */
154#define MAX310X_IRDA_SIR_BIT (1 << 1) /* SIR mode enable */
155#define MAX310X_IRDA_SHORTIR_BIT (1 << 2) /* Short SIR mode enable */
156#define MAX310X_IRDA_MIR_BIT (1 << 3) /* MIR mode enable */
157#define MAX310X_IRDA_RXINV_BIT (1 << 4) /* RX logic inversion enable */
158#define MAX310X_IRDA_TXINV_BIT (1 << 5) /* TX logic inversion enable */
159
160/* Flow control trigger level register masks */
161#define MAX310X_FLOWLVL_HALT_MASK (0x000f) /* Flow control halt level */
162#define MAX310X_FLOWLVL_RES_MASK (0x00f0) /* Flow control resume level */
163#define MAX310X_FLOWLVL_HALT(words) ((words / 8) & 0x0f)
164#define MAX310X_FLOWLVL_RES(words) (((words / 8) & 0x0f) << 4)
165
166/* FIFO interrupt trigger level register masks */
167#define MAX310X_FIFOTRIGLVL_TX_MASK (0x0f) /* TX FIFO trigger level */
168#define MAX310X_FIFOTRIGLVL_RX_MASK (0xf0) /* RX FIFO trigger level */
169#define MAX310X_FIFOTRIGLVL_TX(words) ((words / 8) & 0x0f)
170#define MAX310X_FIFOTRIGLVL_RX(words) (((words / 8) & 0x0f) << 4)
171
172/* Flow control register bits */
173#define MAX310X_FLOWCTRL_AUTORTS_BIT (1 << 0) /* Auto RTS flow ctrl enable */
174#define MAX310X_FLOWCTRL_AUTOCTS_BIT (1 << 1) /* Auto CTS flow ctrl enable */
175#define MAX310X_FLOWCTRL_GPIADDR_BIT (1 << 2) /* Enables that GPIO inputs
176 * are used in conjunction with
177 * XOFF2 for definition of
178 * special character */
179#define MAX310X_FLOWCTRL_SWFLOWEN_BIT (1 << 3) /* Auto SW flow ctrl enable */
180#define MAX310X_FLOWCTRL_SWFLOW0_BIT (1 << 4) /* SWFLOW bit 0 */
181#define MAX310X_FLOWCTRL_SWFLOW1_BIT (1 << 5) /* SWFLOW bit 1
182 *
183 * SWFLOW bits 1 & 0 table:
184 * 00 -> no transmitter flow
185 * control
186 * 01 -> receiver compares
187 * XON2 and XOFF2
188 * and controls
189 * transmitter
190 * 10 -> receiver compares
191 * XON1 and XOFF1
192 * and controls
193 * transmitter
194 * 11 -> receiver compares
195 * XON1, XON2, XOFF1 and
196 * XOFF2 and controls
197 * transmitter
198 */
199#define MAX310X_FLOWCTRL_SWFLOW2_BIT (1 << 6) /* SWFLOW bit 2 */
200#define MAX310X_FLOWCTRL_SWFLOW3_BIT (1 << 7) /* SWFLOW bit 3
201 *
202 * SWFLOW bits 3 & 2 table:
203 * 00 -> no received flow
204 * control
205 * 01 -> transmitter generates
206 * XON2 and XOFF2
207 * 10 -> transmitter generates
208 * XON1 and XOFF1
209 * 11 -> transmitter generates
210 * XON1, XON2, XOFF1 and
211 * XOFF2
212 */
213
214/* GPIO configuration register bits */
215#define MAX310X_GPIOCFG_GP0OUT_BIT (1 << 0) /* GPIO 0 output enable */
216#define MAX310X_GPIOCFG_GP1OUT_BIT (1 << 1) /* GPIO 1 output enable */
217#define MAX310X_GPIOCFG_GP2OUT_BIT (1 << 2) /* GPIO 2 output enable */
218#define MAX310X_GPIOCFG_GP3OUT_BIT (1 << 3) /* GPIO 3 output enable */
219#define MAX310X_GPIOCFG_GP0OD_BIT (1 << 4) /* GPIO 0 open-drain enable */
220#define MAX310X_GPIOCFG_GP1OD_BIT (1 << 5) /* GPIO 1 open-drain enable */
221#define MAX310X_GPIOCFG_GP2OD_BIT (1 << 6) /* GPIO 2 open-drain enable */
222#define MAX310X_GPIOCFG_GP3OD_BIT (1 << 7) /* GPIO 3 open-drain enable */
223
224/* GPIO DATA register bits */
225#define MAX310X_GPIODATA_GP0OUT_BIT (1 << 0) /* GPIO 0 output value */
226#define MAX310X_GPIODATA_GP1OUT_BIT (1 << 1) /* GPIO 1 output value */
227#define MAX310X_GPIODATA_GP2OUT_BIT (1 << 2) /* GPIO 2 output value */
228#define MAX310X_GPIODATA_GP3OUT_BIT (1 << 3) /* GPIO 3 output value */
229#define MAX310X_GPIODATA_GP0IN_BIT (1 << 4) /* GPIO 0 input value */
230#define MAX310X_GPIODATA_GP1IN_BIT (1 << 5) /* GPIO 1 input value */
231#define MAX310X_GPIODATA_GP2IN_BIT (1 << 6) /* GPIO 2 input value */
232#define MAX310X_GPIODATA_GP3IN_BIT (1 << 7) /* GPIO 3 input value */
233
234/* PLL configuration register masks */
235#define MAX310X_PLLCFG_PREDIV_MASK (0x3f) /* PLL predivision value */
236#define MAX310X_PLLCFG_PLLFACTOR_MASK (0xc0) /* PLL multiplication factor */
237
238/* Baud rate generator configuration register bits */
239#define MAX310X_BRGCFG_2XMODE_BIT (1 << 4) /* Double baud rate */
240#define MAX310X_BRGCFG_4XMODE_BIT (1 << 5) /* Quadruple baud rate */
241
242/* Clock source register bits */
243#define MAX310X_CLKSRC_CRYST_BIT (1 << 1) /* Crystal osc enable */
244#define MAX310X_CLKSRC_PLL_BIT (1 << 2) /* PLL enable */
245#define MAX310X_CLKSRC_PLLBYP_BIT (1 << 3) /* PLL bypass */
246#define MAX310X_CLKSRC_EXTCLK_BIT (1 << 4) /* External clock enable */
247#define MAX310X_CLKSRC_CLK2RTS_BIT (1 << 7) /* Baud clk to RTS pin */
248
249/* Misc definitions */
250#define MAX310X_FIFO_SIZE (128)
251
252/* MAX3107 specific */
253#define MAX3107_REV_ID (0xa0)
254#define MAX3107_REV_MASK (0xfe)
255
256/* IRQ status bits definitions */
257#define MAX310X_IRQ_TX (MAX310X_IRQ_TXFIFO_BIT | \
258 MAX310X_IRQ_TXEMPTY_BIT)
259#define MAX310X_IRQ_RX (MAX310X_IRQ_RXFIFO_BIT | \
260 MAX310X_IRQ_RXEMPTY_BIT)
261
262/* Supported chip types */
263enum {
264 MAX310X_TYPE_MAX3107 = 3107,
265 MAX310X_TYPE_MAX3108 = 3108,
266};
267
268struct max310x_port {
269 struct uart_driver uart;
270 struct uart_port port;
271
272 const char *name;
273 int uartclk;
274
275 unsigned int nr_gpio;
276#ifdef CONFIG_GPIOLIB
277 struct gpio_chip gpio;
278#endif
279
280 struct regmap *regmap;
281 struct regmap_config regcfg;
282
283 struct workqueue_struct *wq;
284 struct work_struct tx_work;
285
286 struct mutex max310x_mutex;
287
288 struct max310x_pdata *pdata;
289};
290
291static bool max3107_8_reg_writeable(struct device *dev, unsigned int reg)
292{
293 switch (reg) {
294 case MAX310X_IRQSTS_REG:
295 case MAX310X_LSR_IRQSTS_REG:
296 case MAX310X_SPCHR_IRQSTS_REG:
297 case MAX310X_STS_IRQSTS_REG:
298 case MAX310X_TXFIFOLVL_REG:
299 case MAX310X_RXFIFOLVL_REG:
300 case MAX3107_REVID_REG: /* Only available on MAX3107 */
301 return false;
302 default:
303 break;
304 }
305
306 return true;
307}
308
309static bool max310x_reg_volatile(struct device *dev, unsigned int reg)
310{
311 switch (reg) {
312 case MAX310X_RHR_REG:
313 case MAX310X_IRQSTS_REG:
314 case MAX310X_LSR_IRQSTS_REG:
315 case MAX310X_SPCHR_IRQSTS_REG:
316 case MAX310X_STS_IRQSTS_REG:
317 case MAX310X_TXFIFOLVL_REG:
318 case MAX310X_RXFIFOLVL_REG:
319 case MAX310X_GPIODATA_REG:
320 return true;
321 default:
322 break;
323 }
324
325 return false;
326}
327
328static bool max310x_reg_precious(struct device *dev, unsigned int reg)
329{
330 switch (reg) {
331 case MAX310X_RHR_REG:
332 case MAX310X_IRQSTS_REG:
333 case MAX310X_SPCHR_IRQSTS_REG:
334 case MAX310X_STS_IRQSTS_REG:
335 return true;
336 default:
337 break;
338 }
339
340 return false;
341}
342
343static void max310x_set_baud(struct max310x_port *s, int baud)
344{
345 unsigned int mode = 0, div = s->uartclk / baud;
346
347 if (!(div / 16)) {
348 /* Mode x2 */
349 mode = MAX310X_BRGCFG_2XMODE_BIT;
350 div = (s->uartclk * 2) / baud;
351 }
352
353 if (!(div / 16)) {
354 /* Mode x4 */
355 mode = MAX310X_BRGCFG_4XMODE_BIT;
356 div = (s->uartclk * 4) / baud;
357 }
358
359 regmap_write(s->regmap, MAX310X_BRGDIVMSB_REG,
360 ((div / 16) >> 8) & 0xff);
361 regmap_write(s->regmap, MAX310X_BRGDIVLSB_REG, (div / 16) & 0xff);
362 regmap_write(s->regmap, MAX310X_BRGCFG_REG, (div % 16) | mode);
363}
364
365static void max310x_wait_pll(struct max310x_port *s)
366{
367 int tryes = 1000;
368
369 /* Wait for PLL only if crystal is used */
370 if (!(s->pdata->driver_flags & MAX310X_EXT_CLK)) {
371 unsigned int sts = 0;
372
373 while (tryes--) {
374 regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &sts);
375 if (sts & MAX310X_STS_CLKREADY_BIT)
376 break;
377 }
378 }
379}
380
381static int max310x_update_best_err(unsigned long f, long *besterr)
382{
383 /* Use baudrate 115200 for calculate error */
384 long err = f % (115200 * 16);
385
386 if ((*besterr < 0) || (*besterr > err)) {
387 *besterr = err;
388 return 0;
389 }
390
391 return 1;
392}
393
394static int max310x_set_ref_clk(struct max310x_port *s)
395{
396 unsigned int div, clksrc, pllcfg = 0;
397 long besterr = -1;
398 unsigned long fdiv, fmul, bestfreq = s->pdata->frequency;
399
400 /* First, update error without PLL */
401 max310x_update_best_err(s->pdata->frequency, &besterr);
402
403 /* Try all possible PLL dividers */
404 for (div = 1; (div <= 63) && besterr; div++) {
405 fdiv = DIV_ROUND_CLOSEST(s->pdata->frequency, div);
406
407 /* Try multiplier 6 */
408 fmul = fdiv * 6;
409 if ((fdiv >= 500000) && (fdiv <= 800000))
410 if (!max310x_update_best_err(fmul, &besterr)) {
411 pllcfg = (0 << 6) | div;
412 bestfreq = fmul;
413 }
414 /* Try multiplier 48 */
415 fmul = fdiv * 48;
416 if ((fdiv >= 850000) && (fdiv <= 1200000))
417 if (!max310x_update_best_err(fmul, &besterr)) {
418 pllcfg = (1 << 6) | div;
419 bestfreq = fmul;
420 }
421 /* Try multiplier 96 */
422 fmul = fdiv * 96;
423 if ((fdiv >= 425000) && (fdiv <= 1000000))
424 if (!max310x_update_best_err(fmul, &besterr)) {
425 pllcfg = (2 << 6) | div;
426 bestfreq = fmul;
427 }
428 /* Try multiplier 144 */
429 fmul = fdiv * 144;
430 if ((fdiv >= 390000) && (fdiv <= 667000))
431 if (!max310x_update_best_err(fmul, &besterr)) {
432 pllcfg = (3 << 6) | div;
433 bestfreq = fmul;
434 }
435 }
436
437 /* Configure clock source */
438 if (s->pdata->driver_flags & MAX310X_EXT_CLK)
439 clksrc = MAX310X_CLKSRC_EXTCLK_BIT;
440 else
441 clksrc = MAX310X_CLKSRC_CRYST_BIT;
442
443 /* Configure PLL */
444 if (pllcfg) {
445 clksrc |= MAX310X_CLKSRC_PLL_BIT;
446 regmap_write(s->regmap, MAX310X_PLLCFG_REG, pllcfg);
447 } else
448 clksrc |= MAX310X_CLKSRC_PLLBYP_BIT;
449
450 regmap_write(s->regmap, MAX310X_CLKSRC_REG, clksrc);
451
452 if (pllcfg)
453 max310x_wait_pll(s);
454
455 dev_dbg(s->port.dev, "Reference clock set to %lu Hz\n", bestfreq);
456
457 return (int)bestfreq;
458}
459
460static void max310x_handle_rx(struct max310x_port *s, unsigned int rxlen)
461{
462 unsigned int sts = 0, ch = 0, flag;
463 struct tty_struct *tty = tty_port_tty_get(&s->port.state->port);
464
465 if (!tty)
466 return;
467
468 if (unlikely(rxlen >= MAX310X_FIFO_SIZE)) {
469 dev_warn(s->port.dev, "Possible RX FIFO overrun %d\n", rxlen);
470 /* Ensure sanity of RX level */
471 rxlen = MAX310X_FIFO_SIZE;
472 }
473
474 dev_dbg(s->port.dev, "RX Len = %u\n", rxlen);
475
476 while (rxlen--) {
477 regmap_read(s->regmap, MAX310X_RHR_REG, &ch);
478 regmap_read(s->regmap, MAX310X_LSR_IRQSTS_REG, &sts);
479
480 sts &= MAX310X_LSR_RXPAR_BIT | MAX310X_LSR_FRERR_BIT |
481 MAX310X_LSR_RXOVR_BIT | MAX310X_LSR_RXBRK_BIT;
482
483 s->port.icount.rx++;
484 flag = TTY_NORMAL;
485
486 if (unlikely(sts)) {
487 if (sts & MAX310X_LSR_RXBRK_BIT) {
488 s->port.icount.brk++;
489 if (uart_handle_break(&s->port))
490 continue;
491 } else if (sts & MAX310X_LSR_RXPAR_BIT)
492 s->port.icount.parity++;
493 else if (sts & MAX310X_LSR_FRERR_BIT)
494 s->port.icount.frame++;
495 else if (sts & MAX310X_LSR_RXOVR_BIT)
496 s->port.icount.overrun++;
497
498 sts &= s->port.read_status_mask;
499 if (sts & MAX310X_LSR_RXBRK_BIT)
500 flag = TTY_BREAK;
501 else if (sts & MAX310X_LSR_RXPAR_BIT)
502 flag = TTY_PARITY;
503 else if (sts & MAX310X_LSR_FRERR_BIT)
504 flag = TTY_FRAME;
505 else if (sts & MAX310X_LSR_RXOVR_BIT)
506 flag = TTY_OVERRUN;
507 }
508
509 if (uart_handle_sysrq_char(s->port, ch))
510 continue;
511
512 if (sts & s->port.ignore_status_mask)
513 continue;
514
515 uart_insert_char(&s->port, sts, MAX310X_LSR_RXOVR_BIT,
516 ch, flag);
517 }
518
519 tty_flip_buffer_push(tty);
520
521 tty_kref_put(tty);
522}
523
524static void max310x_handle_tx(struct max310x_port *s)
525{
526 struct circ_buf *xmit = &s->port.state->xmit;
527 unsigned int txlen = 0, to_send;
528
529 if (unlikely(s->port.x_char)) {
530 regmap_write(s->regmap, MAX310X_THR_REG, s->port.x_char);
531 s->port.icount.tx++;
532 s->port.x_char = 0;
533 return;
534 }
535
536 if (uart_circ_empty(xmit) || uart_tx_stopped(&s->port))
537 return;
538
539 /* Get length of data pending in circular buffer */
540 to_send = uart_circ_chars_pending(xmit);
541 if (likely(to_send)) {
542 /* Limit to size of TX FIFO */
543 regmap_read(s->regmap, MAX310X_TXFIFOLVL_REG, &txlen);
544 txlen = MAX310X_FIFO_SIZE - txlen;
545 to_send = (to_send > txlen) ? txlen : to_send;
546
547 dev_dbg(s->port.dev, "TX Len = %u\n", to_send);
548
549 /* Add data to send */
550 s->port.icount.tx += to_send;
551 while (to_send--) {
552 regmap_write(s->regmap, MAX310X_THR_REG,
553 xmit->buf[xmit->tail]);
554 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
555 };
556 }
557
558 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
559 uart_write_wakeup(&s->port);
560}
561
562static irqreturn_t max310x_ist(int irq, void *dev_id)
563{
564 struct max310x_port *s = (struct max310x_port *)dev_id;
565 unsigned int ists = 0, lsr = 0, rxlen = 0;
566
567 mutex_lock(&s->max310x_mutex);
568
569 for (;;) {
570 /* Read IRQ status & RX FIFO level */
571 regmap_read(s->regmap, MAX310X_IRQSTS_REG, &ists);
572 regmap_read(s->regmap, MAX310X_LSR_IRQSTS_REG, &lsr);
573 regmap_read(s->regmap, MAX310X_RXFIFOLVL_REG, &rxlen);
574 if (!ists && !(lsr & MAX310X_LSR_RXTO_BIT) && !rxlen)
575 break;
576
577 dev_dbg(s->port.dev, "IRQ status: 0x%02x\n", ists);
578
579 if (rxlen)
580 max310x_handle_rx(s, rxlen);
581 if (ists & MAX310X_IRQ_TX)
582 max310x_handle_tx(s);
583 if (ists & MAX310X_IRQ_CTS_BIT)
584 uart_handle_cts_change(&s->port,
585 !!(lsr & MAX310X_LSR_CTS_BIT));
586 }
587
588 mutex_unlock(&s->max310x_mutex);
589
590 return IRQ_HANDLED;
591}
592
593static void max310x_wq_proc(struct work_struct *ws)
594{
595 struct max310x_port *s = container_of(ws, struct max310x_port, tx_work);
596
597 mutex_lock(&s->max310x_mutex);
598 max310x_handle_tx(s);
599 mutex_unlock(&s->max310x_mutex);
600}
601
602static void max310x_start_tx(struct uart_port *port)
603{
604 struct max310x_port *s = container_of(port, struct max310x_port, port);
605
606 queue_work(s->wq, &s->tx_work);
607}
608
609static void max310x_stop_tx(struct uart_port *port)
610{
611 /* Do nothing */
612}
613
614static void max310x_stop_rx(struct uart_port *port)
615{
616 /* Do nothing */
617}
618
619static unsigned int max310x_tx_empty(struct uart_port *port)
620{
621 unsigned int val = 0;
622 struct max310x_port *s = container_of(port, struct max310x_port, port);
623
624 mutex_lock(&s->max310x_mutex);
625 regmap_read(s->regmap, MAX310X_TXFIFOLVL_REG, &val);
626 mutex_unlock(&s->max310x_mutex);
627
628 return val ? 0 : TIOCSER_TEMT;
629}
630
631static void max310x_enable_ms(struct uart_port *port)
632{
633 /* Modem status not supported */
634}
635
636static unsigned int max310x_get_mctrl(struct uart_port *port)
637{
638 /* DCD and DSR are not wired and CTS/RTS is handled automatically
639 * so just indicate DSR and CAR asserted
640 */
641 return TIOCM_DSR | TIOCM_CAR;
642}
643
644static void max310x_set_mctrl(struct uart_port *port, unsigned int mctrl)
645{
646 /* DCD and DSR are not wired and CTS/RTS is hadnled automatically
647 * so do nothing
648 */
649}
650
651static void max310x_break_ctl(struct uart_port *port, int break_state)
652{
653 struct max310x_port *s = container_of(port, struct max310x_port, port);
654
655 mutex_lock(&s->max310x_mutex);
656 regmap_update_bits(s->regmap, MAX310X_LCR_REG,
657 MAX310X_LCR_TXBREAK_BIT,
658 break_state ? MAX310X_LCR_TXBREAK_BIT : 0);
659 mutex_unlock(&s->max310x_mutex);
660}
661
662static void max310x_set_termios(struct uart_port *port,
663 struct ktermios *termios,
664 struct ktermios *old)
665{
666 struct max310x_port *s = container_of(port, struct max310x_port, port);
667 unsigned int lcr, flow = 0;
668 int baud;
669
670 mutex_lock(&s->max310x_mutex);
671
672 /* Mask termios capabilities we don't support */
673 termios->c_cflag &= ~CMSPAR;
674 termios->c_iflag &= ~IXANY;
675
676 /* Word size */
677 switch (termios->c_cflag & CSIZE) {
678 case CS5:
679 lcr = MAX310X_LCR_WORD_LEN_5;
680 break;
681 case CS6:
682 lcr = MAX310X_LCR_WORD_LEN_6;
683 break;
684 case CS7:
685 lcr = MAX310X_LCR_WORD_LEN_7;
686 break;
687 case CS8:
688 default:
689 lcr = MAX310X_LCR_WORD_LEN_8;
690 break;
691 }
692
693 /* Parity */
694 if (termios->c_cflag & PARENB) {
695 lcr |= MAX310X_LCR_PARITY_BIT;
696 if (!(termios->c_cflag & PARODD))
697 lcr |= MAX310X_LCR_EVENPARITY_BIT;
698 }
699
700 /* Stop bits */
701 if (termios->c_cflag & CSTOPB)
702 lcr |= MAX310X_LCR_STOPLEN_BIT; /* 2 stops */
703
704 /* Update LCR register */
705 regmap_write(s->regmap, MAX310X_LCR_REG, lcr);
706
707 /* Set read status mask */
708 port->read_status_mask = MAX310X_LSR_RXOVR_BIT;
709 if (termios->c_iflag & INPCK)
710 port->read_status_mask |= MAX310X_LSR_RXPAR_BIT |
711 MAX310X_LSR_FRERR_BIT;
712 if (termios->c_iflag & (BRKINT | PARMRK))
713 port->read_status_mask |= MAX310X_LSR_RXBRK_BIT;
714
715 /* Set status ignore mask */
716 port->ignore_status_mask = 0;
717 if (termios->c_iflag & IGNBRK)
718 port->ignore_status_mask |= MAX310X_LSR_RXBRK_BIT;
719 if (!(termios->c_cflag & CREAD))
720 port->ignore_status_mask |= MAX310X_LSR_RXPAR_BIT |
721 MAX310X_LSR_RXOVR_BIT |
722 MAX310X_LSR_FRERR_BIT |
723 MAX310X_LSR_RXBRK_BIT;
724
725 /* Configure flow control */
726 regmap_write(s->regmap, MAX310X_XON1_REG, termios->c_cc[VSTART]);
727 regmap_write(s->regmap, MAX310X_XOFF1_REG, termios->c_cc[VSTOP]);
728 if (termios->c_cflag & CRTSCTS)
729 flow |= MAX310X_FLOWCTRL_AUTOCTS_BIT |
730 MAX310X_FLOWCTRL_AUTORTS_BIT;
731 if (termios->c_iflag & IXON)
732 flow |= MAX310X_FLOWCTRL_SWFLOW3_BIT |
733 MAX310X_FLOWCTRL_SWFLOWEN_BIT;
734 if (termios->c_iflag & IXOFF)
735 flow |= MAX310X_FLOWCTRL_SWFLOW1_BIT |
736 MAX310X_FLOWCTRL_SWFLOWEN_BIT;
737 regmap_write(s->regmap, MAX310X_FLOWCTRL_REG, flow);
738
739 /* Get baud rate generator configuration */
740 baud = uart_get_baud_rate(port, termios, old,
741 port->uartclk / 16 / 0xffff,
742 port->uartclk / 4);
743
744 /* Setup baudrate generator */
745 max310x_set_baud(s, baud);
746
747 /* Update timeout according to new baud rate */
748 uart_update_timeout(port, termios->c_cflag, baud);
749
750 mutex_unlock(&s->max310x_mutex);
751}
752
753static int max310x_startup(struct uart_port *port)
754{
755 unsigned int val, line = port->line;
756 struct max310x_port *s = container_of(port, struct max310x_port, port);
757
758 if (s->pdata->suspend)
759 s->pdata->suspend(0);
760
761 mutex_lock(&s->max310x_mutex);
762
763 /* Configure baud rate, 9600 as default */
764 max310x_set_baud(s, 9600);
765
766 /* Configure LCR register, 8N1 mode by default */
767 val = MAX310X_LCR_WORD_LEN_8;
768 regmap_write(s->regmap, MAX310X_LCR_REG, val);
769
770 /* Configure MODE1 register */
771 regmap_update_bits(s->regmap, MAX310X_MODE1_REG,
772 MAX310X_MODE1_TRNSCVCTRL_BIT,
773 (s->pdata->uart_flags[line] & MAX310X_AUTO_DIR_CTRL)
774 ? MAX310X_MODE1_TRNSCVCTRL_BIT : 0);
775
776 /* Configure MODE2 register */
777 val = MAX310X_MODE2_RXEMPTINV_BIT;
778 if (s->pdata->uart_flags[line] & MAX310X_LOOPBACK)
779 val |= MAX310X_MODE2_LOOPBACK_BIT;
780 if (s->pdata->uart_flags[line] & MAX310X_ECHO_SUPRESS)
781 val |= MAX310X_MODE2_ECHOSUPR_BIT;
782
783 /* Reset FIFOs */
784 val |= MAX310X_MODE2_FIFORST_BIT;
785 regmap_write(s->regmap, MAX310X_MODE2_REG, val);
786
787 /* Configure FIFO trigger level register */
788 /* RX FIFO trigger for 16 words, TX FIFO trigger for 64 words */
789 val = MAX310X_FIFOTRIGLVL_RX(16) | MAX310X_FIFOTRIGLVL_TX(64);
790 regmap_write(s->regmap, MAX310X_FIFOTRIGLVL_REG, val);
791
792 /* Configure flow control levels */
793 /* Flow control halt level 96, resume level 48 */
794 val = MAX310X_FLOWLVL_RES(48) | MAX310X_FLOWLVL_HALT(96);
795 regmap_write(s->regmap, MAX310X_FLOWLVL_REG, val);
796
797 /* Clear timeout register */
798 regmap_write(s->regmap, MAX310X_RXTO_REG, 0);
799
800 /* Configure LSR interrupt enable register */
801 /* Enable RX timeout interrupt */
802 val = MAX310X_LSR_RXTO_BIT;
803 regmap_write(s->regmap, MAX310X_LSR_IRQEN_REG, val);
804
805 /* Clear FIFO reset */
806 regmap_update_bits(s->regmap, MAX310X_MODE2_REG,
807 MAX310X_MODE2_FIFORST_BIT, 0);
808
809 /* Clear IRQ status register by reading it */
810 regmap_read(s->regmap, MAX310X_IRQSTS_REG, &val);
811
812 /* Configure interrupt enable register */
813 /* Enable CTS change interrupt */
814 val = MAX310X_IRQ_CTS_BIT;
815 /* Enable RX, TX interrupts */
816 val |= MAX310X_IRQ_RX | MAX310X_IRQ_TX;
817 regmap_write(s->regmap, MAX310X_IRQEN_REG, val);
818
819 mutex_unlock(&s->max310x_mutex);
820
821 return 0;
822}
823
824static void max310x_shutdown(struct uart_port *port)
825{
826 struct max310x_port *s = container_of(port, struct max310x_port, port);
827
828 /* Disable all interrupts */
829 mutex_lock(&s->max310x_mutex);
830 regmap_write(s->regmap, MAX310X_IRQEN_REG, 0);
831 mutex_unlock(&s->max310x_mutex);
832
833 if (s->pdata->suspend)
834 s->pdata->suspend(1);
835}
836
837static const char *max310x_type(struct uart_port *port)
838{
839 struct max310x_port *s = container_of(port, struct max310x_port, port);
840
841 return (port->type == PORT_MAX310X) ? s->name : NULL;
842}
843
844static int max310x_request_port(struct uart_port *port)
845{
846 /* Do nothing */
847 return 0;
848}
849
850static void max310x_release_port(struct uart_port *port)
851{
852 /* Do nothing */
853}
854
855static void max310x_config_port(struct uart_port *port, int flags)
856{
857 if (flags & UART_CONFIG_TYPE)
858 port->type = PORT_MAX310X;
859}
860
861static int max310x_verify_port(struct uart_port *port, struct serial_struct *ser)
862{
863 if ((ser->type == PORT_UNKNOWN) || (ser->type == PORT_MAX310X))
864 return 0;
865 if (ser->irq == port->irq)
866 return 0;
867
868 return -EINVAL;
869}
870
871static struct uart_ops max310x_ops = {
872 .tx_empty = max310x_tx_empty,
873 .set_mctrl = max310x_set_mctrl,
874 .get_mctrl = max310x_get_mctrl,
875 .stop_tx = max310x_stop_tx,
876 .start_tx = max310x_start_tx,
877 .stop_rx = max310x_stop_rx,
878 .enable_ms = max310x_enable_ms,
879 .break_ctl = max310x_break_ctl,
880 .startup = max310x_startup,
881 .shutdown = max310x_shutdown,
882 .set_termios = max310x_set_termios,
883 .type = max310x_type,
884 .request_port = max310x_request_port,
885 .release_port = max310x_release_port,
886 .config_port = max310x_config_port,
887 .verify_port = max310x_verify_port,
888};
889
890static int max310x_suspend(struct spi_device *spi, pm_message_t state)
891{
892 int ret;
893 struct max310x_port *s = dev_get_drvdata(&spi->dev);
894
895 dev_dbg(&spi->dev, "Suspend\n");
896
897 ret = uart_suspend_port(&s->uart, &s->port);
898
899 mutex_lock(&s->max310x_mutex);
900
901 /* Enable sleep mode */
902 regmap_update_bits(s->regmap, MAX310X_MODE1_REG,
903 MAX310X_MODE1_FORCESLEEP_BIT,
904 MAX310X_MODE1_FORCESLEEP_BIT);
905
906 mutex_unlock(&s->max310x_mutex);
907
908 if (s->pdata->suspend)
909 s->pdata->suspend(1);
910
911 return ret;
912}
913
914static int max310x_resume(struct spi_device *spi)
915{
916 struct max310x_port *s = dev_get_drvdata(&spi->dev);
917
918 dev_dbg(&spi->dev, "Resume\n");
919
920 if (s->pdata->suspend)
921 s->pdata->suspend(0);
922
923 mutex_lock(&s->max310x_mutex);
924
925 /* Disable sleep mode */
926 regmap_update_bits(s->regmap, MAX310X_MODE1_REG,
927 MAX310X_MODE1_FORCESLEEP_BIT,
928 0);
929
930 max310x_wait_pll(s);
931
932 mutex_unlock(&s->max310x_mutex);
933
934 return uart_resume_port(&s->uart, &s->port);
935}
936
937#ifdef CONFIG_GPIOLIB
938static int max310x_gpio_get(struct gpio_chip *chip, unsigned offset)
939{
940 unsigned int val = 0;
941 struct max310x_port *s = container_of(chip, struct max310x_port, gpio);
942
943 mutex_lock(&s->max310x_mutex);
944 regmap_read(s->regmap, MAX310X_GPIODATA_REG, &val);
945 mutex_unlock(&s->max310x_mutex);
946
947 return !!((val >> 4) & (1 << offset));
948}
949
950static void max310x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
951{
952 struct max310x_port *s = container_of(chip, struct max310x_port, gpio);
953
954 mutex_lock(&s->max310x_mutex);
955 regmap_update_bits(s->regmap, MAX310X_GPIODATA_REG, 1 << offset, value ?
956 1 << offset : 0);
957 mutex_unlock(&s->max310x_mutex);
958}
959
960static int max310x_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
961{
962 struct max310x_port *s = container_of(chip, struct max310x_port, gpio);
963
964 mutex_lock(&s->max310x_mutex);
965
966 regmap_update_bits(s->regmap, MAX310X_GPIOCFG_REG, 1 << offset, 0);
967
968 mutex_unlock(&s->max310x_mutex);
969
970 return 0;
971}
972
973static int max310x_gpio_direction_output(struct gpio_chip *chip,
974 unsigned offset, int value)
975{
976 struct max310x_port *s = container_of(chip, struct max310x_port, gpio);
977
978 mutex_lock(&s->max310x_mutex);
979
980 regmap_update_bits(s->regmap, MAX310X_GPIOCFG_REG, 1 << offset,
981 1 << offset);
982 regmap_update_bits(s->regmap, MAX310X_GPIODATA_REG, 1 << offset, value ?
983 1 << offset : 0);
984
985 mutex_unlock(&s->max310x_mutex);
986
987 return 0;
988}
989#endif
990
991/* Generic platform data */
992static struct max310x_pdata generic_plat_data = {
993 .driver_flags = MAX310X_EXT_CLK,
994 .uart_flags[0] = MAX310X_ECHO_SUPRESS,
995 .frequency = 26000000,
996};
997
998static int max310x_probe(struct spi_device *spi)
999{
1000 struct max310x_port *s;
1001 struct device *dev = &spi->dev;
1002 int chiptype = spi_get_device_id(spi)->driver_data;
1003 struct max310x_pdata *pdata = dev->platform_data;
1004 unsigned int val = 0;
1005 int ret;
1006
1007 /* Check for IRQ */
1008 if (spi->irq <= 0) {
1009 dev_err(dev, "No IRQ specified\n");
1010 return -ENOTSUPP;
1011 }
1012
1013 /* Alloc port structure */
1014 s = devm_kzalloc(dev, sizeof(struct max310x_port), GFP_KERNEL);
1015 if (!s) {
1016 dev_err(dev, "Error allocating port structure\n");
1017 return -ENOMEM;
1018 }
1019 dev_set_drvdata(dev, s);
1020
1021 if (!pdata) {
1022 dev_warn(dev, "No platform data supplied, using defaults\n");
1023 pdata = &generic_plat_data;
1024 }
1025 s->pdata = pdata;
1026
1027 /* Individual chip settings */
1028 switch (chiptype) {
1029 case MAX310X_TYPE_MAX3107:
1030 s->name = "MAX3107";
1031 s->nr_gpio = 4;
1032 s->uart.nr = 1;
1033 s->regcfg.max_register = 0x1f;
1034 break;
1035 case MAX310X_TYPE_MAX3108:
1036 s->name = "MAX3108";
1037 s->nr_gpio = 4;
1038 s->uart.nr = 1;
1039 s->regcfg.max_register = 0x1e;
1040 break;
1041 default:
1042 dev_err(dev, "Unsupported chip type %i\n", chiptype);
1043 return -ENOTSUPP;
1044 }
1045
1046 /* Check input frequency */
1047 if ((pdata->driver_flags & MAX310X_EXT_CLK) &&
1048 ((pdata->frequency < 500000) || (pdata->frequency > 35000000)))
1049 goto err_freq;
1050 /* Check frequency for quartz */
1051 if (!(pdata->driver_flags & MAX310X_EXT_CLK) &&
1052 ((pdata->frequency < 1000000) || (pdata->frequency > 4000000)))
1053 goto err_freq;
1054
1055 mutex_init(&s->max310x_mutex);
1056
1057 /* Setup SPI bus */
1058 spi->mode = SPI_MODE_0;
1059 spi->bits_per_word = 8;
1060 spi->max_speed_hz = 26000000;
1061 spi_setup(spi);
1062
1063 /* Setup regmap */
1064 s->regcfg.reg_bits = 8;
1065 s->regcfg.val_bits = 8;
1066 s->regcfg.read_flag_mask = 0x00;
1067 s->regcfg.write_flag_mask = 0x80;
1068 s->regcfg.cache_type = REGCACHE_RBTREE;
1069 s->regcfg.writeable_reg = max3107_8_reg_writeable;
1070 s->regcfg.volatile_reg = max310x_reg_volatile;
1071 s->regcfg.precious_reg = max310x_reg_precious;
1072 s->regmap = devm_regmap_init_spi(spi, &s->regcfg);
1073 if (IS_ERR(s->regmap)) {
1074 ret = PTR_ERR(s->regmap);
1075 dev_err(dev, "Failed to initialize register map\n");
1076 goto err_out;
1077 }
1078
1079 /* Reset chip & check SPI function */
1080 ret = regmap_write(s->regmap, MAX310X_MODE2_REG, MAX310X_MODE2_RST_BIT);
1081 if (ret) {
1082 dev_err(dev, "SPI transfer failed\n");
1083 goto err_out;
1084 }
1085 /* Clear chip reset */
1086 regmap_write(s->regmap, MAX310X_MODE2_REG, 0);
1087
1088 switch (chiptype) {
1089 case MAX310X_TYPE_MAX3107:
1090 /* Check REV ID to ensure we are talking to what we expect */
1091 regmap_read(s->regmap, MAX3107_REVID_REG, &val);
1092 if (((val & MAX3107_REV_MASK) != MAX3107_REV_ID)) {
1093 dev_err(dev, "%s ID 0x%02x does not match\n",
1094 s->name, val);
1095 ret = -ENODEV;
1096 goto err_out;
1097 }
1098 break;
1099 case MAX310X_TYPE_MAX3108:
1100 /* MAX3108 have not REV ID register, we just check default value
1101 * from clocksource register to make sure everything works.
1102 */
1103 regmap_read(s->regmap, MAX310X_CLKSRC_REG, &val);
1104 if (val != (MAX310X_CLKSRC_EXTCLK_BIT |
1105 MAX310X_CLKSRC_PLLBYP_BIT)) {
1106 dev_err(dev, "%s not present\n", s->name);
1107 ret = -ENODEV;
1108 goto err_out;
1109 }
1110 break;
1111 }
1112
1113 /* Board specific configure */
1114 if (pdata->init)
1115 pdata->init();
1116 if (pdata->suspend)
1117 pdata->suspend(0);
1118
1119 /* Calculate referecne clock */
1120 s->uartclk = max310x_set_ref_clk(s);
1121
1122 /* Disable all interrupts */
1123 regmap_write(s->regmap, MAX310X_IRQEN_REG, 0);
1124
1125 /* Setup MODE1 register */
1126 val = MAX310X_MODE1_IRQSEL_BIT; /* Enable IRQ pin */
1127 if (pdata->driver_flags & MAX310X_AUTOSLEEP)
1128 val = MAX310X_MODE1_AUTOSLEEP_BIT;
1129 regmap_write(s->regmap, MAX310X_MODE1_REG, val);
1130
1131 /* Setup interrupt */
1132 ret = devm_request_threaded_irq(dev, spi->irq, NULL, max310x_ist,
1133 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
1134 dev_name(dev), s);
1135 if (ret) {
1136 dev_err(dev, "Unable to reguest IRQ %i\n", spi->irq);
1137 goto err_out;
1138 }
1139
1140 /* Register UART driver */
1141 s->uart.owner = THIS_MODULE;
1142 s->uart.driver_name = dev_name(dev);
1143 s->uart.dev_name = "ttyMAX";
1144 s->uart.major = MAX310X_MAJOR;
1145 s->uart.minor = MAX310X_MINOR;
1146 ret = uart_register_driver(&s->uart);
1147 if (ret) {
1148 dev_err(dev, "Registering UART driver failed\n");
1149 goto err_out;
1150 }
1151
1152 /* Initialize workqueue for start TX */
1153 s->wq = create_freezable_workqueue(dev_name(dev));
1154 INIT_WORK(&s->tx_work, max310x_wq_proc);
1155
1156 /* Initialize UART port data */
1157 s->port.line = 0;
1158 s->port.dev = dev;
1159 s->port.irq = spi->irq;
1160 s->port.type = PORT_MAX310X;
1161 s->port.fifosize = MAX310X_FIFO_SIZE;
1162 s->port.flags = UPF_SKIP_TEST | UPF_FIXED_TYPE;
1163 s->port.iotype = UPIO_PORT;
1164 s->port.membase = (void __iomem *)0xffffffff; /* Bogus value */
1165 s->port.uartclk = s->uartclk;
1166 s->port.ops = &max310x_ops;
1167 uart_add_one_port(&s->uart, &s->port);
1168
1169#ifdef CONFIG_GPIOLIB
1170 /* Setup GPIO cotroller */
1171 if (pdata->gpio_base) {
1172 s->gpio.owner = THIS_MODULE;
1173 s->gpio.dev = dev;
1174 s->gpio.label = dev_name(dev);
1175 s->gpio.direction_input = max310x_gpio_direction_input;
1176 s->gpio.get = max310x_gpio_get;
1177 s->gpio.direction_output= max310x_gpio_direction_output;
1178 s->gpio.set = max310x_gpio_set;
1179 s->gpio.base = pdata->gpio_base;
1180 s->gpio.ngpio = s->nr_gpio;
1181 s->gpio.can_sleep = 1;
1182 if (gpiochip_add(&s->gpio)) {
1183 /* Indicate that we should not call gpiochip_remove */
1184 s->gpio.base = 0;
1185 }
1186 } else
1187 dev_info(dev, "GPIO support not enabled\n");
1188#endif
1189
1190 /* Go to suspend mode */
1191 if (pdata->suspend)
1192 pdata->suspend(1);
1193
1194 return 0;
1195
1196err_freq:
1197 dev_err(dev, "Frequency parameter incorrect\n");
1198 ret = -EINVAL;
1199
1200err_out:
1201 dev_set_drvdata(dev, NULL);
1202
1203 return ret;
1204}
1205
1206static int max310x_remove(struct spi_device *spi)
1207{
1208 struct device *dev = &spi->dev;
1209 struct max310x_port *s = dev_get_drvdata(dev);
1210 int ret = 0;
1211
1212 dev_dbg(dev, "Removing port\n");
1213
1214 devm_free_irq(dev, s->port.irq, s);
1215
1216 destroy_workqueue(s->wq);
1217
1218 uart_remove_one_port(&s->uart, &s->port);
1219
1220 uart_unregister_driver(&s->uart);
1221
1222#ifdef CONFIG_GPIOLIB
1223 if (s->pdata->gpio_base) {
1224 ret = gpiochip_remove(&s->gpio);
1225 if (ret)
1226 dev_err(dev, "Failed to remove gpio chip: %d\n", ret);
1227 }
1228#endif
1229
1230 dev_set_drvdata(dev, NULL);
1231
1232 if (s->pdata->suspend)
1233 s->pdata->suspend(1);
1234 if (s->pdata->exit)
1235 s->pdata->exit();
1236
1237 return ret;
1238}
1239
1240static const struct spi_device_id max310x_id_table[] = {
1241 { "max3107", MAX310X_TYPE_MAX3107 },
1242 { "max3108", MAX310X_TYPE_MAX3108 },
1243 { }
1244};
1245MODULE_DEVICE_TABLE(spi, max310x_id_table);
1246
1247static struct spi_driver max310x_driver = {
1248 .driver = {
1249 .name = "max310x",
1250 .owner = THIS_MODULE,
1251 },
1252 .probe = max310x_probe,
1253 .remove = max310x_remove,
1254 .suspend = max310x_suspend,
1255 .resume = max310x_resume,
1256 .id_table = max310x_id_table,
1257};
1258module_spi_driver(max310x_driver);
1259
1260MODULE_LICENSE("GPL v2");
1261MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
1262MODULE_DESCRIPTION("MAX310X serial driver");
diff --git a/drivers/tty/serial/mcf.c b/drivers/tty/serial/mcf.c
index fcd56ab6053..3394b7cc172 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, 0, "UART", port)) 383 if (request_irq(port->irq, mcf_interrupt, IRQF_DISABLED, "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}
@@ -571,7 +571,7 @@ static struct uart_driver mcf_driver = {
571 571
572/****************************************************************************/ 572/****************************************************************************/
573 573
574static int mcf_probe(struct platform_device *pdev) 574static int __devinit mcf_probe(struct platform_device *pdev)
575{ 575{
576 struct mcf_platform_uart *platp = pdev->dev.platform_data; 576 struct mcf_platform_uart *platp = pdev->dev.platform_data;
577 struct uart_port *port; 577 struct uart_port *port;
@@ -599,7 +599,7 @@ static int mcf_probe(struct platform_device *pdev)
599 599
600/****************************************************************************/ 600/****************************************************************************/
601 601
602static int mcf_remove(struct platform_device *pdev) 602static int __devexit mcf_remove(struct platform_device *pdev)
603{ 603{
604 struct uart_port *port; 604 struct uart_port *port;
605 int i; 605 int i;
@@ -617,7 +617,7 @@ static int mcf_remove(struct platform_device *pdev)
617 617
618static struct platform_driver mcf_platform_driver = { 618static struct platform_driver mcf_platform_driver = {
619 .probe = mcf_probe, 619 .probe = mcf_probe,
620 .remove = mcf_remove, 620 .remove = __devexit_p(mcf_remove),
621 .driver = { 621 .driver = {
622 .name = "mcfuart", 622 .name = "mcfuart",
623 .owner = THIS_MODULE, 623 .owner = THIS_MODULE,
diff --git a/drivers/tty/serial/mfd.c b/drivers/tty/serial/mfd.c
index 2c01344dc33..cab52f4a88b 100644
--- a/drivers/tty/serial/mfd.c
+++ b/drivers/tty/serial/mfd.c
@@ -36,10 +36,8 @@
36#include <linux/serial_mfd.h> 36#include <linux/serial_mfd.h>
37#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/nmi.h>
40#include <linux/io.h> 39#include <linux/io.h>
41#include <linux/debugfs.h> 40#include <linux/debugfs.h>
42#include <linux/pm_runtime.h>
43 41
44#define HSU_DMA_BUF_SIZE 2048 42#define HSU_DMA_BUF_SIZE 2048
45 43
@@ -128,6 +126,11 @@ static inline void serial_out(struct uart_hsu_port *up, int offset, int value)
128 126
129#define HSU_REGS_BUFSIZE 1024 127#define HSU_REGS_BUFSIZE 1024
130 128
129static int hsu_show_regs_open(struct inode *inode, struct file *file)
130{
131 file->private_data = inode->i_private;
132 return 0;
133}
131 134
132static ssize_t port_show_regs(struct file *file, char __user *user_buf, 135static ssize_t port_show_regs(struct file *file, char __user *user_buf,
133 size_t count, loff_t *ppos) 136 size_t count, loff_t *ppos)
@@ -227,14 +230,14 @@ static ssize_t dma_show_regs(struct file *file, char __user *user_buf,
227 230
228static const struct file_operations port_regs_ops = { 231static const struct file_operations port_regs_ops = {
229 .owner = THIS_MODULE, 232 .owner = THIS_MODULE,
230 .open = simple_open, 233 .open = hsu_show_regs_open,
231 .read = port_show_regs, 234 .read = port_show_regs,
232 .llseek = default_llseek, 235 .llseek = default_llseek,
233}; 236};
234 237
235static const struct file_operations dma_regs_ops = { 238static const struct file_operations dma_regs_ops = {
236 .owner = THIS_MODULE, 239 .owner = THIS_MODULE,
237 .open = simple_open, 240 .open = hsu_show_regs_open,
238 .read = dma_show_regs, 241 .read = dma_show_regs,
239 .llseek = default_llseek, 242 .llseek = default_llseek,
240}; 243};
@@ -761,8 +764,6 @@ static int serial_hsu_startup(struct uart_port *port)
761 container_of(port, struct uart_hsu_port, port); 764 container_of(port, struct uart_hsu_port, port);
762 unsigned long flags; 765 unsigned long flags;
763 766
764 pm_runtime_get_sync(up->dev);
765
766 /* 767 /*
767 * Clear the FIFO buffers and disable them. 768 * Clear the FIFO buffers and disable them.
768 * (they will be reenabled in set_termios()) 769 * (they will be reenabled in set_termios())
@@ -870,8 +871,6 @@ static void serial_hsu_shutdown(struct uart_port *port)
870 UART_FCR_CLEAR_RCVR | 871 UART_FCR_CLEAR_RCVR |
871 UART_FCR_CLEAR_XMIT); 872 UART_FCR_CLEAR_XMIT);
872 serial_out(up, UART_FCR, 0); 873 serial_out(up, UART_FCR, 0);
873
874 pm_runtime_put(up->dev);
875} 874}
876 875
877static void 876static void
@@ -880,6 +879,7 @@ serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,
880{ 879{
881 struct uart_hsu_port *up = 880 struct uart_hsu_port *up =
882 container_of(port, struct uart_hsu_port, port); 881 container_of(port, struct uart_hsu_port, port);
882 struct tty_struct *tty = port->state->port.tty;
883 unsigned char cval, fcr = 0; 883 unsigned char cval, fcr = 0;
884 unsigned long flags; 884 unsigned long flags;
885 unsigned int baud, quot; 885 unsigned int baud, quot;
@@ -902,7 +902,8 @@ serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,
902 } 902 }
903 903
904 /* CMSPAR isn't supported by this driver */ 904 /* CMSPAR isn't supported by this driver */
905 termios->c_cflag &= ~CMSPAR; 905 if (tty)
906 tty->termios->c_cflag &= ~CMSPAR;
906 907
907 if (termios->c_cflag & CSTOPB) 908 if (termios->c_cflag & CSTOPB)
908 cval |= UART_LCR_STOP; 909 cval |= UART_LCR_STOP;
@@ -1114,8 +1115,6 @@ serial_hsu_console_write(struct console *co, const char *s, unsigned int count)
1114 unsigned int ier; 1115 unsigned int ier;
1115 int locked = 1; 1116 int locked = 1;
1116 1117
1117 touch_nmi_watchdog();
1118
1119 local_irq_save(flags); 1118 local_irq_save(flags);
1120 if (up->port.sysrq) 1119 if (up->port.sysrq)
1121 locked = 0; 1120 locked = 0;
@@ -1152,6 +1151,7 @@ serial_hsu_console_setup(struct console *co, char *options)
1152 int bits = 8; 1151 int bits = 8;
1153 int parity = 'n'; 1152 int parity = 'n';
1154 int flow = 'n'; 1153 int flow = 'n';
1154 int ret;
1155 1155
1156 if (co->index == -1 || co->index >= serial_hsu_reg.nr) 1156 if (co->index == -1 || co->index >= serial_hsu_reg.nr)
1157 co->index = 0; 1157 co->index = 0;
@@ -1162,7 +1162,9 @@ serial_hsu_console_setup(struct console *co, char *options)
1162 if (options) 1162 if (options)
1163 uart_parse_options(options, &baud, &parity, &bits, &flow); 1163 uart_parse_options(options, &baud, &parity, &bits, &flow);
1164 1164
1165 return uart_set_options(&up->port, co, baud, parity, bits, flow); 1165 ret = uart_set_options(&up->port, co, baud, parity, bits, flow);
1166
1167 return ret;
1166} 1168}
1167 1169
1168static struct console serial_hsu_console = { 1170static struct console serial_hsu_console = {
@@ -1171,13 +1173,9 @@ static struct console serial_hsu_console = {
1171 .device = uart_console_device, 1173 .device = uart_console_device,
1172 .setup = serial_hsu_console_setup, 1174 .setup = serial_hsu_console_setup,
1173 .flags = CON_PRINTBUFFER, 1175 .flags = CON_PRINTBUFFER,
1174 .index = -1, 1176 .index = 2,
1175 .data = &serial_hsu_reg, 1177 .data = &serial_hsu_reg,
1176}; 1178};
1177
1178#define SERIAL_HSU_CONSOLE (&serial_hsu_console)
1179#else
1180#define SERIAL_HSU_CONSOLE NULL
1181#endif 1179#endif
1182 1180
1183struct uart_ops serial_hsu_pops = { 1181struct uart_ops serial_hsu_pops = {
@@ -1207,7 +1205,6 @@ static struct uart_driver serial_hsu_reg = {
1207 .major = TTY_MAJOR, 1205 .major = TTY_MAJOR,
1208 .minor = 128, 1206 .minor = 128,
1209 .nr = 3, 1207 .nr = 3,
1210 .cons = SERIAL_HSU_CONSOLE,
1211}; 1208};
1212 1209
1213#ifdef CONFIG_PM 1210#ifdef CONFIG_PM
@@ -1252,39 +1249,6 @@ static int serial_hsu_resume(struct pci_dev *pdev)
1252#define serial_hsu_resume NULL 1249#define serial_hsu_resume NULL
1253#endif 1250#endif
1254 1251
1255#ifdef CONFIG_PM_RUNTIME
1256static int serial_hsu_runtime_idle(struct device *dev)
1257{
1258 int err;
1259
1260 err = pm_schedule_suspend(dev, 500);
1261 if (err)
1262 return -EBUSY;
1263
1264 return 0;
1265}
1266
1267static int serial_hsu_runtime_suspend(struct device *dev)
1268{
1269 return 0;
1270}
1271
1272static int serial_hsu_runtime_resume(struct device *dev)
1273{
1274 return 0;
1275}
1276#else
1277#define serial_hsu_runtime_idle NULL
1278#define serial_hsu_runtime_suspend NULL
1279#define serial_hsu_runtime_resume NULL
1280#endif
1281
1282static const struct dev_pm_ops serial_hsu_pm_ops = {
1283 .runtime_suspend = serial_hsu_runtime_suspend,
1284 .runtime_resume = serial_hsu_runtime_resume,
1285 .runtime_idle = serial_hsu_runtime_idle,
1286};
1287
1288/* temp global pointer before we settle down on using one or four PCI dev */ 1252/* temp global pointer before we settle down on using one or four PCI dev */
1289static struct hsu_port *phsu; 1253static struct hsu_port *phsu;
1290 1254
@@ -1342,12 +1306,15 @@ static int serial_hsu_probe(struct pci_dev *pdev,
1342 } 1306 }
1343 uart_add_one_port(&serial_hsu_reg, &uport->port); 1307 uart_add_one_port(&serial_hsu_reg, &uport->port);
1344 1308
1309#ifdef CONFIG_SERIAL_MFD_HSU_CONSOLE
1310 if (index == 2) {
1311 register_console(&serial_hsu_console);
1312 uport->port.cons = &serial_hsu_console;
1313 }
1314#endif
1345 pci_set_drvdata(pdev, uport); 1315 pci_set_drvdata(pdev, uport);
1346 } 1316 }
1347 1317
1348 pm_runtime_put_noidle(&pdev->dev);
1349 pm_runtime_allow(&pdev->dev);
1350
1351 return 0; 1318 return 0;
1352 1319
1353err_disable: 1320err_disable:
@@ -1444,9 +1411,6 @@ static void serial_hsu_remove(struct pci_dev *pdev)
1444 if (!priv) 1411 if (!priv)
1445 return; 1412 return;
1446 1413
1447 pm_runtime_forbid(&pdev->dev);
1448 pm_runtime_get_noresume(&pdev->dev);
1449
1450 /* For port 0/1/2, priv is the address of uart_hsu_port */ 1414 /* For port 0/1/2, priv is the address of uart_hsu_port */
1451 if (pdev->device != 0x081E) { 1415 if (pdev->device != 0x081E) {
1452 up = priv; 1416 up = priv;
@@ -1459,7 +1423,7 @@ static void serial_hsu_remove(struct pci_dev *pdev)
1459} 1423}
1460 1424
1461/* First 3 are UART ports, and the 4th is the DMA */ 1425/* First 3 are UART ports, and the 4th is the DMA */
1462static const struct pci_device_id pci_ids[] = { 1426static const struct pci_device_id pci_ids[] __devinitdata = {
1463 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) }, 1427 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) },
1464 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) }, 1428 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) },
1465 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) }, 1429 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) },
@@ -1471,12 +1435,9 @@ static struct pci_driver hsu_pci_driver = {
1471 .name = "HSU serial", 1435 .name = "HSU serial",
1472 .id_table = pci_ids, 1436 .id_table = pci_ids,
1473 .probe = serial_hsu_probe, 1437 .probe = serial_hsu_probe,
1474 .remove = serial_hsu_remove, 1438 .remove = __devexit_p(serial_hsu_remove),
1475 .suspend = serial_hsu_suspend, 1439 .suspend = serial_hsu_suspend,
1476 .resume = serial_hsu_resume, 1440 .resume = serial_hsu_resume,
1477 .driver = {
1478 .pm = &serial_hsu_pm_ops,
1479 },
1480}; 1441};
1481 1442
1482static int __init hsu_pci_init(void) 1443static int __init hsu_pci_init(void)
diff --git a/drivers/tty/serial/mpc52xx_uart.c b/drivers/tty/serial/mpc52xx_uart.c
index 7c23c4f4c58..a0bcd8a3758 100644
--- a/drivers/tty/serial/mpc52xx_uart.c
+++ b/drivers/tty/serial/mpc52xx_uart.c
@@ -34,7 +34,6 @@
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>
38#include <linux/serial.h> 37#include <linux/serial.h>
39#include <linux/sysrq.h> 38#include <linux/sysrq.h>
40#include <linux/console.h> 39#include <linux/console.h>
@@ -262,9 +261,8 @@ static unsigned int mpc5200b_psc_set_baudrate(struct uart_port *port,
262 port->uartclk / 4); 261 port->uartclk / 4);
263 divisor = (port->uartclk + 2 * baud) / (4 * baud); 262 divisor = (port->uartclk + 2 * baud) / (4 * baud);
264 263
265 /* select the proper prescaler and set the divisor 264 /* select the proper prescaler and set the divisor */
266 * prefer high prescaler for more tolerance on low baudrates */ 265 if (divisor > 0xffff) {
267 if (divisor > 0xffff || baud <= 115200) {
268 divisor = (divisor + 4) / 8; 266 divisor = (divisor + 4) / 8;
269 prescaler = 0xdd00; /* /32 */ 267 prescaler = 0xdd00; /* /32 */
270 } else 268 } else
@@ -275,7 +273,7 @@ static unsigned int mpc5200b_psc_set_baudrate(struct uart_port *port,
275 273
276static void mpc52xx_psc_get_irq(struct uart_port *port, struct device_node *np) 274static void mpc52xx_psc_get_irq(struct uart_port *port, struct device_node *np)
277{ 275{
278 port->irqflags = 0; 276 port->irqflags = IRQF_DISABLED;
279 port->irq = irq_of_parse_and_map(np, 0); 277 port->irq = irq_of_parse_and_map(np, 0);
280} 278}
281 279
@@ -508,7 +506,7 @@ static int __init mpc512x_psc_fifoc_init(void)
508 506
509 psc_fifoc_irq = irq_of_parse_and_map(np, 0); 507 psc_fifoc_irq = irq_of_parse_and_map(np, 0);
510 of_node_put(np); 508 of_node_put(np);
511 if (psc_fifoc_irq == 0) { 509 if (psc_fifoc_irq == NO_IRQ) {
512 pr_err("%s: Can't get FIFOC irq\n", __func__); 510 pr_err("%s: Can't get FIFOC irq\n", __func__);
513 iounmap(psc_fifoc); 511 iounmap(psc_fifoc);
514 return -ENODEV; 512 return -ENODEV;
@@ -598,7 +596,7 @@ static struct psc_ops mpc512x_psc_ops = {
598}; 596};
599#endif 597#endif
600 598
601static const struct psc_ops *psc_ops; 599static struct psc_ops *psc_ops;
602 600
603/* ======================================================================== */ 601/* ======================================================================== */
604/* UART operations */ 602/* UART operations */
@@ -775,15 +773,11 @@ mpc52xx_uart_set_termios(struct uart_port *port, struct ktermios *new,
775 } 773 }
776 774
777 if (new->c_cflag & PARENB) { 775 if (new->c_cflag & PARENB) {
778 if (new->c_cflag & CMSPAR)
779 mr1 |= MPC52xx_PSC_MODE_PARFORCE;
780
781 /* With CMSPAR, PARODD also means high parity (same as termios) */
782 mr1 |= (new->c_cflag & PARODD) ? 776 mr1 |= (new->c_cflag & PARODD) ?
783 MPC52xx_PSC_MODE_PARODD : MPC52xx_PSC_MODE_PAREVEN; 777 MPC52xx_PSC_MODE_PARODD : MPC52xx_PSC_MODE_PAREVEN;
784 } else { 778 } else
785 mr1 |= MPC52xx_PSC_MODE_PARNONE; 779 mr1 |= MPC52xx_PSC_MODE_PARNONE;
786 } 780
787 781
788 mr2 = 0; 782 mr2 = 0;
789 783
@@ -1308,7 +1302,7 @@ static struct of_device_id mpc52xx_uart_of_match[] = {
1308 {}, 1302 {},
1309}; 1303};
1310 1304
1311static int mpc52xx_uart_of_probe(struct platform_device *op) 1305static int __devinit mpc52xx_uart_of_probe(struct platform_device *op)
1312{ 1306{
1313 int idx = -1; 1307 int idx = -1;
1314 unsigned int uartclk; 1308 unsigned int uartclk;
@@ -1359,7 +1353,7 @@ static int mpc52xx_uart_of_probe(struct platform_device *op)
1359 } 1353 }
1360 1354
1361 psc_ops->get_irq(port, op->dev.of_node); 1355 psc_ops->get_irq(port, op->dev.of_node);
1362 if (port->irq == 0) { 1356 if (port->irq == NO_IRQ) {
1363 dev_dbg(&op->dev, "Could not get irq\n"); 1357 dev_dbg(&op->dev, "Could not get irq\n");
1364 return -EINVAL; 1358 return -EINVAL;
1365 } 1359 }
diff --git a/drivers/tty/serial/mrst_max3110.c b/drivers/tty/serial/mrst_max3110.c
index 58734d7e746..23bc743f2a2 100644
--- a/drivers/tty/serial/mrst_max3110.c
+++ b/drivers/tty/serial/mrst_max3110.c
@@ -23,14 +23,10 @@
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 interrupt is used, no need for waiting TXE 26 * 2. Currently only RX available interrrupt 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
34#include <linux/module.h> 30#include <linux/module.h>
35#include <linux/ioport.h> 31#include <linux/ioport.h>
36#include <linux/irq.h> 32#include <linux/irq.h>
@@ -77,9 +73,9 @@ struct uart_max3110 {
77/* global data structure, may need be removed */ 73/* global data structure, may need be removed */
78static struct uart_max3110 *pmax; 74static struct uart_max3110 *pmax;
79 75
80static int receive_chars(struct uart_max3110 *max, 76static void receive_chars(struct uart_max3110 *max,
81 unsigned short *str, int len); 77 unsigned char *str, int len);
82static int max3110_read_multi(struct uart_max3110 *max); 78static int max3110_read_multi(struct uart_max3110 *max, u8 *buf);
83static void max3110_con_receive(struct uart_max3110 *max); 79static void max3110_con_receive(struct uart_max3110 *max);
84 80
85static int max3110_write_then_read(struct uart_max3110 *max, 81static int max3110_write_then_read(struct uart_max3110 *max,
@@ -112,6 +108,7 @@ static int max3110_out(struct uart_max3110 *max, const u16 out)
112{ 108{
113 void *buf; 109 void *buf;
114 u16 *obuf, *ibuf; 110 u16 *obuf, *ibuf;
111 u8 ch;
115 int ret; 112 int ret;
116 113
117 buf = kzalloc(8, GFP_KERNEL | GFP_DMA); 114 buf = kzalloc(8, GFP_KERNEL | GFP_DMA);
@@ -128,7 +125,11 @@ static int max3110_out(struct uart_max3110 *max, const u16 out)
128 goto exit; 125 goto exit;
129 } 126 }
130 127
131 receive_chars(max, ibuf, 1); 128 /* If some valid data is read back */
129 if (*ibuf & MAX3110_READ_DATA_AVAILABLE) {
130 ch = *ibuf & 0xff;
131 receive_chars(max, &ch, 1);
132 }
132 133
133exit: 134exit:
134 kfree(buf); 135 kfree(buf);
@@ -141,11 +142,12 @@ exit:
141 * 142 *
142 * Return how many valide bytes are read back 143 * Return how many valide bytes are read back
143 */ 144 */
144static int max3110_read_multi(struct uart_max3110 *max) 145static int max3110_read_multi(struct uart_max3110 *max, u8 *rxbuf)
145{ 146{
146 void *buf; 147 void *buf;
147 u16 *obuf, *ibuf; 148 u16 *obuf, *ibuf;
148 int ret, blen; 149 u8 *pbuf, valid_str[M3110_RX_FIFO_DEPTH];
150 int i, j, blen;
149 151
150 blen = M3110_RX_FIFO_DEPTH * sizeof(u16); 152 blen = M3110_RX_FIFO_DEPTH * sizeof(u16);
151 buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA); 153 buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA);
@@ -163,10 +165,19 @@ static int max3110_read_multi(struct uart_max3110 *max)
163 return 0; 165 return 0;
164 } 166 }
165 167
166 ret = receive_chars(max, ibuf, M3110_RX_FIFO_DEPTH); 168 /* If caller doesn't provide a buffer, then handle received char */
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);
167 178
168 kfree(buf); 179 kfree(buf);
169 return ret; 180 return j;
170} 181}
171 182
172static void serial_m3110_con_putchar(struct uart_port *port, int ch) 183static void serial_m3110_con_putchar(struct uart_port *port, int ch)
@@ -196,7 +207,7 @@ static void serial_m3110_con_write(struct console *co,
196 uart_console_write(&pmax->port, s, count, serial_m3110_con_putchar); 207 uart_console_write(&pmax->port, s, count, serial_m3110_con_putchar);
197 208
198 if (!test_and_set_bit(CON_TX_NEEDED, &pmax->uart_flags)) 209 if (!test_and_set_bit(CON_TX_NEEDED, &pmax->uart_flags))
199 wake_up(&pmax->wq); 210 wake_up_process(pmax->main_thread);
200} 211}
201 212
202static int __init 213static int __init
@@ -265,7 +276,8 @@ static void send_circ_buf(struct uart_max3110 *max,
265{ 276{
266 void *buf; 277 void *buf;
267 u16 *obuf, *ibuf; 278 u16 *obuf, *ibuf;
268 int i, len, blen, dma_size, left, ret = 0; 279 u8 valid_str[WORDS_PER_XFER];
280 int i, j, len, blen, dma_size, left, ret = 0;
269 281
270 282
271 dma_size = WORDS_PER_XFER * sizeof(u16) * 2; 283 dma_size = WORDS_PER_XFER * sizeof(u16) * 2;
@@ -289,13 +301,18 @@ static void send_circ_buf(struct uart_max3110 *max,
289 } 301 }
290 302
291 /* Fail to send msg to console is not very critical */ 303 /* Fail to send msg to console is not very critical */
292
293 ret = max3110_write_then_read(max, obuf, ibuf, blen, 0); 304 ret = max3110_write_then_read(max, obuf, ibuf, blen, 0);
294 if (ret) 305 if (ret)
295 pr_warning(PR_FMT "%s(): get err msg %d\n", 306 pr_warning(PR_FMT "%s(): get err msg %d\n",
296 __func__, ret); 307 __func__, ret);
297 308
298 receive_chars(max, ibuf, len); 309 for (i = 0, j = 0; i < len; i++) {
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);
299 316
300 max->port.icount.tx += len; 317 max->port.icount.tx += len;
301 left -= len; 318 left -= len;
@@ -332,54 +349,33 @@ static void serial_m3110_start_tx(struct uart_port *port)
332 container_of(port, struct uart_max3110, port); 349 container_of(port, struct uart_max3110, port);
333 350
334 if (!test_and_set_bit(UART_TX_NEEDED, &max->uart_flags)) 351 if (!test_and_set_bit(UART_TX_NEEDED, &max->uart_flags))
335 wake_up(&max->wq); 352 wake_up_process(max->main_thread);
336} 353}
337 354
338static int 355static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len)
339receive_chars(struct uart_max3110 *max, unsigned short *str, int len)
340{ 356{
341 struct uart_port *port = &max->port; 357 struct uart_port *port = &max->port;
342 struct tty_struct *tty; 358 struct tty_struct *tty;
343 char buf[M3110_RX_FIFO_DEPTH]; 359 int usable;
344 int r, w, usable;
345 360
346 /* If uart is not opened, just return */ 361 /* If uart is not opened, just return */
347 if (!port->state) 362 if (!port->state)
348 return 0; 363 return;
349 364
350 tty = tty_port_tty_get(&port->state->port); 365 tty = port->state->port.tty;
351 if (!tty) 366 if (!tty)
352 return 0; 367 return;
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 }
371 368
372 for (r = 0; w; r += usable, w -= usable) { 369 while (len) {
373 usable = tty_buffer_request_room(tty, w); 370 usable = tty_buffer_request_room(tty, len);
374 if (usable) { 371 if (usable) {
375 tty_insert_flip_string(tty, buf + r, usable); 372 tty_insert_flip_string(tty, str, usable);
373 str += usable;
376 port->icount.rx += usable; 374 port->icount.rx += usable;
377 } 375 }
376 len -= usable;
378 } 377 }
379 tty_flip_buffer_push(tty); 378 tty_flip_buffer_push(tty);
380 tty_kref_put(tty);
381
382 return r;
383} 379}
384 380
385/* 381/*
@@ -394,15 +390,28 @@ receive_chars(struct uart_max3110 *max, unsigned short *str, int len)
394 */ 390 */
395static void max3110_con_receive(struct uart_max3110 *max) 391static void max3110_con_receive(struct uart_max3110 *max)
396{ 392{
397 int loop = 1, num; 393 int loop = 1, num, total = 0;
394 u8 recv_buf[512], *pbuf;
398 395
396 pbuf = recv_buf;
399 do { 397 do {
400 num = max3110_read_multi(max); 398 num = max3110_read_multi(max, pbuf);
401 399
402 if (num) { 400 if (num) {
403 loop = 5; 401 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 }
404 } 410 }
405 } while (--loop); 411 } while (--loop);
412
413 if (total)
414 receive_chars(max, recv_buf, total);
406} 415}
407 416
408static int max3110_main_thread(void *_max) 417static int max3110_main_thread(void *_max)
@@ -415,8 +424,7 @@ static int max3110_main_thread(void *_max)
415 pr_info(PR_FMT "start main thread\n"); 424 pr_info(PR_FMT "start main thread\n");
416 425
417 do { 426 do {
418 wait_event_interruptible(*wq, 427 wait_event_interruptible(*wq, max->uart_flags || kthread_should_stop());
419 max->uart_flags || kthread_should_stop());
420 428
421 mutex_lock(&max->thread_mutex); 429 mutex_lock(&max->thread_mutex);
422 430
@@ -444,9 +452,8 @@ static irqreturn_t serial_m3110_irq(int irq, void *dev_id)
444 452
445 /* max3110's irq is a falling edge, not level triggered, 453 /* max3110's irq is a falling edge, not level triggered,
446 * so no need to disable the irq */ 454 * so no need to disable the irq */
447
448 if (!test_and_set_bit(BIT_IRQ_PENDING, &max->uart_flags)) 455 if (!test_and_set_bit(BIT_IRQ_PENDING, &max->uart_flags))
449 wake_up(&max->wq); 456 wake_up_process(max->main_thread);
450 457
451 return IRQ_HANDLED; 458 return IRQ_HANDLED;
452} 459}
@@ -773,7 +780,7 @@ static int serial_m3110_resume(struct spi_device *spi)
773#define serial_m3110_resume NULL 780#define serial_m3110_resume NULL
774#endif 781#endif
775 782
776static int serial_m3110_probe(struct spi_device *spi) 783static int __devinit serial_m3110_probe(struct spi_device *spi)
777{ 784{
778 struct uart_max3110 *max; 785 struct uart_max3110 *max;
779 void *buffer; 786 void *buffer;
@@ -855,7 +862,7 @@ err_get_page:
855 return ret; 862 return ret;
856} 863}
857 864
858static int serial_m3110_remove(struct spi_device *dev) 865static int __devexit serial_m3110_remove(struct spi_device *dev)
859{ 866{
860 struct uart_max3110 *max = spi_get_drvdata(dev); 867 struct uart_max3110 *max = spi_get_drvdata(dev);
861 868
@@ -876,10 +883,11 @@ static int serial_m3110_remove(struct spi_device *dev)
876static struct spi_driver uart_max3110_driver = { 883static struct spi_driver uart_max3110_driver = {
877 .driver = { 884 .driver = {
878 .name = "spi_max3111", 885 .name = "spi_max3111",
886 .bus = &spi_bus_type,
879 .owner = THIS_MODULE, 887 .owner = THIS_MODULE,
880 }, 888 },
881 .probe = serial_m3110_probe, 889 .probe = serial_m3110_probe,
882 .remove = serial_m3110_remove, 890 .remove = __devexit_p(serial_m3110_remove),
883 .suspend = serial_m3110_suspend, 891 .suspend = serial_m3110_suspend,
884 .resume = serial_m3110_resume, 892 .resume = serial_m3110_resume,
885}; 893};
diff --git a/drivers/tty/serial/mrst_max3110.h b/drivers/tty/serial/mrst_max3110.h
index 35af0739513..c37ea48c825 100644
--- a/drivers/tty/serial/mrst_max3110.h
+++ b/drivers/tty/serial/mrst_max3110.h
@@ -7,7 +7,6 @@
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)
11 10
12#define WC_TAG (3 << 14) 11#define WC_TAG (3 << 14)
13#define RC_TAG (1 << 14) 12#define RC_TAG (1 << 14)
diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
index 95fd39be293..e6ba8387650 100644
--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -19,7 +19,6 @@
19# define SUPPORT_SYSRQ 19# define SUPPORT_SYSRQ
20#endif 20#endif
21 21
22#include <linux/atomic.h>
23#include <linux/hrtimer.h> 22#include <linux/hrtimer.h>
24#include <linux/module.h> 23#include <linux/module.h>
25#include <linux/io.h> 24#include <linux/io.h>
@@ -34,8 +33,6 @@
34#include <linux/clk.h> 33#include <linux/clk.h>
35#include <linux/platform_device.h> 34#include <linux/platform_device.h>
36#include <linux/delay.h> 35#include <linux/delay.h>
37#include <linux/of.h>
38#include <linux/of_device.h>
39 36
40#include "msm_serial.h" 37#include "msm_serial.h"
41 38
@@ -592,8 +589,9 @@ static void msm_release_port(struct uart_port *port)
592 iowrite32(GSBI_PROTOCOL_IDLE, msm_port->gsbi_base + 589 iowrite32(GSBI_PROTOCOL_IDLE, msm_port->gsbi_base +
593 GSBI_CONTROL); 590 GSBI_CONTROL);
594 591
595 gsbi_resource = platform_get_resource(pdev, 592 gsbi_resource = platform_get_resource_byname(pdev,
596 IORESOURCE_MEM, 1); 593 IORESOURCE_MEM,
594 "gsbi_resource");
597 595
598 if (unlikely(!gsbi_resource)) 596 if (unlikely(!gsbi_resource))
599 return; 597 return;
@@ -614,7 +612,8 @@ static int msm_request_port(struct uart_port *port)
614 resource_size_t size; 612 resource_size_t size;
615 int ret; 613 int ret;
616 614
617 uart_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); 615 uart_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM,
616 "uart_resource");
618 if (unlikely(!uart_resource)) 617 if (unlikely(!uart_resource))
619 return -ENXIO; 618 return -ENXIO;
620 619
@@ -629,7 +628,8 @@ static int msm_request_port(struct uart_port *port)
629 goto fail_release_port; 628 goto fail_release_port;
630 } 629 }
631 630
632 gsbi_resource = platform_get_resource(pdev, IORESOURCE_MEM, 1); 631 gsbi_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM,
632 "gsbi_resource");
633 /* Is this a GSBI-based port? */ 633 /* Is this a GSBI-based port? */
634 if (gsbi_resource) { 634 if (gsbi_resource) {
635 size = resource_size(gsbi_resource); 635 size = resource_size(gsbi_resource);
@@ -804,6 +804,8 @@ 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
807 msm_init_clock(port); 809 msm_init_clock(port);
808 810
809 if (options) 811 if (options)
@@ -857,8 +859,6 @@ static struct uart_driver msm_uart_driver = {
857 .cons = MSM_CONSOLE, 859 .cons = MSM_CONSOLE,
858}; 860};
859 861
860static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
861
862static int __init msm_serial_probe(struct platform_device *pdev) 862static int __init msm_serial_probe(struct platform_device *pdev)
863{ 863{
864 struct msm_port *msm_port; 864 struct msm_port *msm_port;
@@ -866,9 +866,6 @@ static int __init msm_serial_probe(struct platform_device *pdev)
866 struct uart_port *port; 866 struct uart_port *port;
867 int irq; 867 int irq;
868 868
869 if (pdev->id == -1)
870 pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
871
872 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR)) 869 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
873 return -ENXIO; 870 return -ENXIO;
874 871
@@ -878,7 +875,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
878 port->dev = &pdev->dev; 875 port->dev = &pdev->dev;
879 msm_port = UART_TO_MSM(port); 876 msm_port = UART_TO_MSM(port);
880 877
881 if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) 878 if (platform_get_resource_byname(pdev, IORESOURCE_MEM, "gsbi_resource"))
882 msm_port->is_uartdm = 1; 879 msm_port->is_uartdm = 1;
883 else 880 else
884 msm_port->is_uartdm = 0; 881 msm_port->is_uartdm = 0;
@@ -896,13 +893,14 @@ static int __init msm_serial_probe(struct platform_device *pdev)
896 return PTR_ERR(msm_port->clk); 893 return PTR_ERR(msm_port->clk);
897 894
898 if (msm_port->is_uartdm) 895 if (msm_port->is_uartdm)
899 clk_set_rate(msm_port->clk, 1843200); 896 clk_set_rate(msm_port->clk, 7372800);
900 897
901 port->uartclk = clk_get_rate(msm_port->clk); 898 port->uartclk = clk_get_rate(msm_port->clk);
902 printk(KERN_INFO "uartclk = %d\n", port->uartclk); 899 printk(KERN_INFO "uartclk = %d\n", port->uartclk);
903 900
904 901
905 resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); 902 resource = platform_get_resource_byname(pdev, IORESOURCE_MEM,
903 "uart_resource");
906 if (unlikely(!resource)) 904 if (unlikely(!resource))
907 return -ENXIO; 905 return -ENXIO;
908 port->mapbase = resource->start; 906 port->mapbase = resource->start;
@@ -917,7 +915,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
917 return uart_add_one_port(&msm_uart_driver, port); 915 return uart_add_one_port(&msm_uart_driver, port);
918} 916}
919 917
920static int msm_serial_remove(struct platform_device *pdev) 918static int __devexit msm_serial_remove(struct platform_device *pdev)
921{ 919{
922 struct msm_port *msm_port = platform_get_drvdata(pdev); 920 struct msm_port *msm_port = platform_get_drvdata(pdev);
923 921
@@ -926,17 +924,11 @@ static int msm_serial_remove(struct platform_device *pdev)
926 return 0; 924 return 0;
927} 925}
928 926
929static struct of_device_id msm_match_table[] = {
930 { .compatible = "qcom,msm-uart" },
931 {}
932};
933
934static struct platform_driver msm_platform_driver = { 927static struct platform_driver msm_platform_driver = {
935 .remove = msm_serial_remove, 928 .remove = msm_serial_remove,
936 .driver = { 929 .driver = {
937 .name = "msm_serial", 930 .name = "msm_serial",
938 .owner = THIS_MODULE, 931 .owner = THIS_MODULE,
939 .of_match_table = msm_match_table,
940 }, 932 },
941}; 933};
942 934
diff --git a/drivers/tty/serial/msm_serial_hs.c b/drivers/tty/serial/msm_serial_hs.c
index 1fa92284ade..624701f8138 100644
--- a/drivers/tty/serial/msm_serial_hs.c
+++ b/drivers/tty/serial/msm_serial_hs.c
@@ -30,8 +30,6 @@
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>
35#include <linux/slab.h> 33#include <linux/slab.h>
36#include <linux/init.h> 34#include <linux/init.h>
37#include <linux/interrupt.h> 35#include <linux/interrupt.h>
@@ -50,6 +48,7 @@
50 48
51#include <linux/atomic.h> 49#include <linux/atomic.h>
52#include <asm/irq.h> 50#include <asm/irq.h>
51#include <asm/system.h>
53 52
54#include <mach/hardware.h> 53#include <mach/hardware.h>
55#include <mach/dma.h> 54#include <mach/dma.h>
@@ -401,7 +400,7 @@ static int msm_hs_request_port(struct uart_port *port)
401 return 0; 400 return 0;
402} 401}
403 402
404static int msm_hs_remove(struct platform_device *pdev) 403static int __devexit msm_hs_remove(struct platform_device *pdev)
405{ 404{
406 405
407 struct msm_hs_port *msm_uport; 406 struct msm_hs_port *msm_uport;
@@ -421,9 +420,9 @@ static int msm_hs_remove(struct platform_device *pdev)
421 msm_uport->rx.rbuffer); 420 msm_uport->rx.rbuffer);
422 dma_pool_destroy(msm_uport->rx.pool); 421 dma_pool_destroy(msm_uport->rx.pool);
423 422
424 dma_unmap_single(dev, msm_uport->rx.cmdptr_dmaaddr, sizeof(u32), 423 dma_unmap_single(dev, msm_uport->rx.cmdptr_dmaaddr, sizeof(u32 *),
425 DMA_TO_DEVICE); 424 DMA_TO_DEVICE);
426 dma_unmap_single(dev, msm_uport->tx.mapped_cmd_ptr_ptr, sizeof(u32), 425 dma_unmap_single(dev, msm_uport->tx.mapped_cmd_ptr_ptr, sizeof(u32 *),
427 DMA_TO_DEVICE); 426 DMA_TO_DEVICE);
428 dma_unmap_single(dev, msm_uport->tx.mapped_cmd_ptr, sizeof(dmov_box), 427 dma_unmap_single(dev, msm_uport->tx.mapped_cmd_ptr, sizeof(dmov_box),
429 DMA_TO_DEVICE); 428 DMA_TO_DEVICE);
@@ -811,7 +810,7 @@ static void msm_hs_submit_tx_locked(struct uart_port *uport)
811 *tx->command_ptr_ptr = CMD_PTR_LP | DMOV_CMD_ADDR(tx->mapped_cmd_ptr); 810 *tx->command_ptr_ptr = CMD_PTR_LP | DMOV_CMD_ADDR(tx->mapped_cmd_ptr);
812 811
813 dma_sync_single_for_device(uport->dev, tx->mapped_cmd_ptr_ptr, 812 dma_sync_single_for_device(uport->dev, tx->mapped_cmd_ptr_ptr,
814 sizeof(u32), DMA_TO_DEVICE); 813 sizeof(u32 *), DMA_TO_DEVICE);
815 814
816 /* Save tx_count to use in Callback */ 815 /* Save tx_count to use in Callback */
817 tx->tx_count = tx_count; 816 tx->tx_count = tx_count;
@@ -1086,10 +1085,12 @@ static void msm_hs_config_port(struct uart_port *uport, int cfg_flags)
1086} 1085}
1087 1086
1088/* Handle CTS changes (Called from interrupt handler) */ 1087/* Handle CTS changes (Called from interrupt handler) */
1089static void msm_hs_handle_delta_cts_locked(struct uart_port *uport) 1088static void msm_hs_handle_delta_cts(struct uart_port *uport)
1090{ 1089{
1090 unsigned long flags;
1091 struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1091 struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport);
1092 1092
1093 spin_lock_irqsave(&uport->lock, flags);
1093 clk_enable(msm_uport->clk); 1094 clk_enable(msm_uport->clk);
1094 1095
1095 /* clear interrupt */ 1096 /* clear interrupt */
@@ -1097,6 +1098,7 @@ static void msm_hs_handle_delta_cts_locked(struct uart_port *uport)
1097 uport->icount.cts++; 1098 uport->icount.cts++;
1098 1099
1099 clk_disable(msm_uport->clk); 1100 clk_disable(msm_uport->clk);
1101 spin_unlock_irqrestore(&uport->lock, flags);
1100 1102
1101 /* clear the IOCTL TIOCMIWAIT if called */ 1103 /* clear the IOCTL TIOCMIWAIT if called */
1102 wake_up_interruptible(&uport->state->port.delta_msr_wait); 1104 wake_up_interruptible(&uport->state->port.delta_msr_wait);
@@ -1244,7 +1246,7 @@ static irqreturn_t msm_hs_isr(int irq, void *dev)
1244 1246
1245 /* Change in CTS interrupt */ 1247 /* Change in CTS interrupt */
1246 if (isr_status & UARTDM_ISR_DELTA_CTS_BMSK) 1248 if (isr_status & UARTDM_ISR_DELTA_CTS_BMSK)
1247 msm_hs_handle_delta_cts_locked(uport); 1249 msm_hs_handle_delta_cts(uport);
1248 1250
1249 spin_unlock_irqrestore(&uport->lock, flags); 1251 spin_unlock_irqrestore(&uport->lock, flags);
1250 1252
@@ -1521,7 +1523,7 @@ err_msm_hs_init_clk:
1521} 1523}
1522 1524
1523/* Initialize tx and rx data structures */ 1525/* Initialize tx and rx data structures */
1524static int uartdm_init_port(struct uart_port *uport) 1526static int __devinit uartdm_init_port(struct uart_port *uport)
1525{ 1527{
1526 int ret = 0; 1528 int ret = 0;
1527 struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport); 1529 struct msm_hs_port *msm_uport = UARTDM_TO_MSM(uport);
@@ -1533,7 +1535,7 @@ static int uartdm_init_port(struct uart_port *uport)
1533 if (!tx->command_ptr) 1535 if (!tx->command_ptr)
1534 return -ENOMEM; 1536 return -ENOMEM;
1535 1537
1536 tx->command_ptr_ptr = kmalloc(sizeof(u32), GFP_KERNEL | __GFP_DMA); 1538 tx->command_ptr_ptr = kmalloc(sizeof(u32 *), GFP_KERNEL | __GFP_DMA);
1537 if (!tx->command_ptr_ptr) { 1539 if (!tx->command_ptr_ptr) {
1538 ret = -ENOMEM; 1540 ret = -ENOMEM;
1539 goto err_tx_command_ptr_ptr; 1541 goto err_tx_command_ptr_ptr;
@@ -1543,7 +1545,7 @@ static int uartdm_init_port(struct uart_port *uport)
1543 sizeof(dmov_box), DMA_TO_DEVICE); 1545 sizeof(dmov_box), DMA_TO_DEVICE);
1544 tx->mapped_cmd_ptr_ptr = dma_map_single(uport->dev, 1546 tx->mapped_cmd_ptr_ptr = dma_map_single(uport->dev,
1545 tx->command_ptr_ptr, 1547 tx->command_ptr_ptr,
1546 sizeof(u32), DMA_TO_DEVICE); 1548 sizeof(u32 *), DMA_TO_DEVICE);
1547 tx->xfer.cmdptr = DMOV_CMD_ADDR(tx->mapped_cmd_ptr_ptr); 1549 tx->xfer.cmdptr = DMOV_CMD_ADDR(tx->mapped_cmd_ptr_ptr);
1548 1550
1549 init_waitqueue_head(&rx->wait); 1551 init_waitqueue_head(&rx->wait);
@@ -1571,7 +1573,7 @@ static int uartdm_init_port(struct uart_port *uport)
1571 goto err_rx_command_ptr; 1573 goto err_rx_command_ptr;
1572 } 1574 }
1573 1575
1574 rx->command_ptr_ptr = kmalloc(sizeof(u32), GFP_KERNEL | __GFP_DMA); 1576 rx->command_ptr_ptr = kmalloc(sizeof(u32 *), GFP_KERNEL | __GFP_DMA);
1575 if (!rx->command_ptr_ptr) { 1577 if (!rx->command_ptr_ptr) {
1576 pr_err("%s(): cannot allocate rx->command_ptr_ptr", __func__); 1578 pr_err("%s(): cannot allocate rx->command_ptr_ptr", __func__);
1577 ret = -ENOMEM; 1579 ret = -ENOMEM;
@@ -1589,7 +1591,7 @@ static int uartdm_init_port(struct uart_port *uport)
1589 *rx->command_ptr_ptr = CMD_PTR_LP | DMOV_CMD_ADDR(rx->mapped_cmd_ptr); 1591 *rx->command_ptr_ptr = CMD_PTR_LP | DMOV_CMD_ADDR(rx->mapped_cmd_ptr);
1590 1592
1591 rx->cmdptr_dmaaddr = dma_map_single(uport->dev, rx->command_ptr_ptr, 1593 rx->cmdptr_dmaaddr = dma_map_single(uport->dev, rx->command_ptr_ptr,
1592 sizeof(u32), DMA_TO_DEVICE); 1594 sizeof(u32 *), DMA_TO_DEVICE);
1593 rx->xfer.cmdptr = DMOV_CMD_ADDR(rx->cmdptr_dmaaddr); 1595 rx->xfer.cmdptr = DMOV_CMD_ADDR(rx->cmdptr_dmaaddr);
1594 1596
1595 INIT_WORK(&rx->tty_work, msm_hs_tty_flip_buffer_work); 1597 INIT_WORK(&rx->tty_work, msm_hs_tty_flip_buffer_work);
@@ -1605,7 +1607,7 @@ err_dma_pool_alloc:
1605 dma_pool_destroy(msm_uport->rx.pool); 1607 dma_pool_destroy(msm_uport->rx.pool);
1606err_dma_pool_create: 1608err_dma_pool_create:
1607 dma_unmap_single(uport->dev, msm_uport->tx.mapped_cmd_ptr_ptr, 1609 dma_unmap_single(uport->dev, msm_uport->tx.mapped_cmd_ptr_ptr,
1608 sizeof(u32), DMA_TO_DEVICE); 1610 sizeof(u32 *), DMA_TO_DEVICE);
1609 dma_unmap_single(uport->dev, msm_uport->tx.mapped_cmd_ptr, 1611 dma_unmap_single(uport->dev, msm_uport->tx.mapped_cmd_ptr,
1610 sizeof(dmov_box), DMA_TO_DEVICE); 1612 sizeof(dmov_box), DMA_TO_DEVICE);
1611 kfree(msm_uport->tx.command_ptr_ptr); 1613 kfree(msm_uport->tx.command_ptr_ptr);
@@ -1614,7 +1616,7 @@ err_tx_command_ptr_ptr:
1614 return ret; 1616 return ret;
1615} 1617}
1616 1618
1617static int msm_hs_probe(struct platform_device *pdev) 1619static int __devinit msm_hs_probe(struct platform_device *pdev)
1618{ 1620{
1619 int ret; 1621 int ret;
1620 struct uart_port *uport; 1622 struct uart_port *uport;
@@ -1838,7 +1840,7 @@ static const struct dev_pm_ops msm_hs_dev_pm_ops = {
1838 1840
1839static struct platform_driver msm_serial_hs_platform_driver = { 1841static struct platform_driver msm_serial_hs_platform_driver = {
1840 .probe = msm_hs_probe, 1842 .probe = msm_hs_probe,
1841 .remove = msm_hs_remove, 1843 .remove = __devexit_p(msm_hs_remove),
1842 .driver = { 1844 .driver = {
1843 .name = "msm_serial_hs", 1845 .name = "msm_serial_hs",
1844 .owner = THIS_MODULE, 1846 .owner = THIS_MODULE,
diff --git a/drivers/tty/serial/msm_smd_tty.c b/drivers/tty/serial/msm_smd_tty.c
index 925d1fa153d..4f41dcdcb77 100644
--- a/drivers/tty/serial/msm_smd_tty.c
+++ b/drivers/tty/serial/msm_smd_tty.c
@@ -203,6 +203,7 @@ static int __init smd_tty_init(void)
203 if (smd_tty_driver == 0) 203 if (smd_tty_driver == 0)
204 return -ENOMEM; 204 return -ENOMEM;
205 205
206 smd_tty_driver->owner = THIS_MODULE;
206 smd_tty_driver->driver_name = "smd_tty_driver"; 207 smd_tty_driver->driver_name = "smd_tty_driver";
207 smd_tty_driver->name = "smd"; 208 smd_tty_driver->name = "smd";
208 smd_tty_driver->major = 0; 209 smd_tty_driver->major = 0;
@@ -223,11 +224,9 @@ static int __init smd_tty_init(void)
223 return ret; 224 return ret;
224 225
225 for (i = 0; i < smd_tty_channels_len; i++) { 226 for (i = 0; i < smd_tty_channels_len; i++) {
226 struct tty_port *port = &smd_tty[smd_tty_channels[i].id].port; 227 tty_port_init(&smd_tty[smd_tty_channels[i].id].port);
227 tty_port_init(port); 228 smd_tty[smd_tty_channels[i].id].port.ops = &smd_tty_port_ops;
228 port->ops = &smd_tty_port_ops; 229 tty_register_device(smd_tty_driver, smd_tty_channels[i].id, 0);
229 tty_port_register_device(port, smd_tty_driver,
230 smd_tty_channels[i].id, NULL);
231 } 230 }
232 231
233 return 0; 232 return 0;
diff --git a/drivers/tty/serial/mux.c b/drivers/tty/serial/mux.c
index e2775b6df5a..9711e06a837 100644
--- a/drivers/tty/serial/mux.c
+++ b/drivers/tty/serial/mux.c
@@ -17,11 +17,10 @@
17*/ 17*/
18 18
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/tty.h>
20#include <linux/ioport.h> 21#include <linux/ioport.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <linux/serial.h> 23#include <linux/serial.h>
23#include <linux/tty.h>
24#include <linux/tty_flip.h>
25#include <linux/console.h> 24#include <linux/console.h>
26#include <linux/delay.h> /* for udelay */ 25#include <linux/delay.h> /* for udelay */
27#include <linux/device.h> 26#include <linux/device.h>
@@ -498,7 +497,7 @@ static int __init mux_probe(struct parisc_device *dev)
498 port->membase = ioremap_nocache(port->mapbase, MUX_LINE_OFFSET); 497 port->membase = ioremap_nocache(port->mapbase, MUX_LINE_OFFSET);
499 port->iotype = UPIO_MEM; 498 port->iotype = UPIO_MEM;
500 port->type = PORT_MUX; 499 port->type = PORT_MUX;
501 port->irq = 0; 500 port->irq = NO_IRQ;
502 port->uartclk = 0; 501 port->uartclk = 0;
503 port->fifosize = MUX_FIFO_SIZE; 502 port->fifosize = MUX_FIFO_SIZE;
504 port->ops = &mux_pops; 503 port->ops = &mux_pops;
@@ -520,7 +519,7 @@ static int __init mux_probe(struct parisc_device *dev)
520 return 0; 519 return 0;
521} 520}
522 521
523static int mux_remove(struct parisc_device *dev) 522static int __devexit mux_remove(struct parisc_device *dev)
524{ 523{
525 int i, j; 524 int i, j;
526 int port_count = (long)dev_get_drvdata(&dev->dev); 525 int port_count = (long)dev_get_drvdata(&dev->dev);
@@ -571,14 +570,14 @@ static struct parisc_driver builtin_serial_mux_driver = {
571 .name = "builtin_serial_mux", 570 .name = "builtin_serial_mux",
572 .id_table = builtin_mux_tbl, 571 .id_table = builtin_mux_tbl,
573 .probe = mux_probe, 572 .probe = mux_probe,
574 .remove = mux_remove, 573 .remove = __devexit_p(mux_remove),
575}; 574};
576 575
577static struct parisc_driver serial_mux_driver = { 576static struct parisc_driver serial_mux_driver = {
578 .name = "serial_mux", 577 .name = "serial_mux",
579 .id_table = mux_tbl, 578 .id_table = mux_tbl,
580 .probe = mux_probe, 579 .probe = mux_probe,
581 .remove = mux_remove, 580 .remove = __devexit_p(mux_remove),
582}; 581};
583 582
584/** 583/**
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index 6db23b035ef..7e02c9c344f 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -32,10 +32,6 @@
32#include <linux/clk.h> 32#include <linux/clk.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/io.h> 34#include <linux/io.h>
35#include <linux/pinctrl/consumer.h>
36#include <linux/of_device.h>
37#include <linux/dma-mapping.h>
38#include <linux/fsl/mxs-dma.h>
39 35
40#include <asm/cacheflush.h> 36#include <asm/cacheflush.h>
41 37
@@ -73,18 +69,8 @@
73 69
74#define AUART_CTRL0_SFTRST (1 << 31) 70#define AUART_CTRL0_SFTRST (1 << 31)
75#define AUART_CTRL0_CLKGATE (1 << 30) 71#define AUART_CTRL0_CLKGATE (1 << 30)
76#define AUART_CTRL0_RXTO_ENABLE (1 << 27)
77#define AUART_CTRL0_RXTIMEOUT(v) (((v) & 0x7ff) << 16)
78#define AUART_CTRL0_XFER_COUNT(v) ((v) & 0xffff)
79
80#define AUART_CTRL1_XFER_COUNT(v) ((v) & 0xffff)
81
82#define AUART_CTRL2_DMAONERR (1 << 26)
83#define AUART_CTRL2_TXDMAE (1 << 25)
84#define AUART_CTRL2_RXDMAE (1 << 24)
85 72
86#define AUART_CTRL2_CTSEN (1 << 15) 73#define AUART_CTRL2_CTSEN (1 << 15)
87#define AUART_CTRL2_RTSEN (1 << 14)
88#define AUART_CTRL2_RTS (1 << 11) 74#define AUART_CTRL2_RTS (1 << 11)
89#define AUART_CTRL2_RXE (1 << 9) 75#define AUART_CTRL2_RXE (1 << 9)
90#define AUART_CTRL2_TXE (1 << 8) 76#define AUART_CTRL2_TXE (1 << 8)
@@ -122,170 +108,29 @@
122#define AUART_STAT_BERR (1 << 18) 108#define AUART_STAT_BERR (1 << 18)
123#define AUART_STAT_PERR (1 << 17) 109#define AUART_STAT_PERR (1 << 17)
124#define AUART_STAT_FERR (1 << 16) 110#define AUART_STAT_FERR (1 << 16)
125#define AUART_STAT_RXCOUNT_MASK 0xffff
126 111
127static struct uart_driver auart_driver; 112static struct uart_driver auart_driver;
128 113
129enum mxs_auart_type {
130 IMX23_AUART,
131 IMX28_AUART,
132};
133
134struct mxs_auart_port { 114struct mxs_auart_port {
135 struct uart_port port; 115 struct uart_port port;
136 116
137#define MXS_AUART_DMA_CONFIG 0x1 117 unsigned int flags;
138#define MXS_AUART_DMA_ENABLED 0x2
139#define MXS_AUART_DMA_TX_SYNC 2 /* bit 2 */
140#define MXS_AUART_DMA_RX_READY 3 /* bit 3 */
141 unsigned long flags;
142 unsigned int ctrl; 118 unsigned int ctrl;
143 enum mxs_auart_type devtype;
144 119
145 unsigned int irq; 120 unsigned int irq;
146 121
147 struct clk *clk; 122 struct clk *clk;
148 struct device *dev; 123 struct device *dev;
149
150 /* for DMA */
151 struct mxs_dma_data dma_data;
152 int dma_channel_rx, dma_channel_tx;
153 int dma_irq_rx, dma_irq_tx;
154 int dma_channel;
155
156 struct scatterlist tx_sgl;
157 struct dma_chan *tx_dma_chan;
158 void *tx_dma_buf;
159
160 struct scatterlist rx_sgl;
161 struct dma_chan *rx_dma_chan;
162 void *rx_dma_buf;
163};
164
165static struct platform_device_id mxs_auart_devtype[] = {
166 { .name = "mxs-auart-imx23", .driver_data = IMX23_AUART },
167 { .name = "mxs-auart-imx28", .driver_data = IMX28_AUART },
168 { /* sentinel */ }
169}; 124};
170MODULE_DEVICE_TABLE(platform, mxs_auart_devtype);
171
172static struct of_device_id mxs_auart_dt_ids[] = {
173 {
174 .compatible = "fsl,imx28-auart",
175 .data = &mxs_auart_devtype[IMX28_AUART]
176 }, {
177 .compatible = "fsl,imx23-auart",
178 .data = &mxs_auart_devtype[IMX23_AUART]
179 }, { /* sentinel */ }
180};
181MODULE_DEVICE_TABLE(of, mxs_auart_dt_ids);
182
183static inline int is_imx28_auart(struct mxs_auart_port *s)
184{
185 return s->devtype == IMX28_AUART;
186}
187
188static inline bool auart_dma_enabled(struct mxs_auart_port *s)
189{
190 return s->flags & MXS_AUART_DMA_ENABLED;
191}
192 125
193static void mxs_auart_stop_tx(struct uart_port *u); 126static void mxs_auart_stop_tx(struct uart_port *u);
194 127
195#define to_auart_port(u) container_of(u, struct mxs_auart_port, port) 128#define to_auart_port(u) container_of(u, struct mxs_auart_port, port)
196 129
197static void mxs_auart_tx_chars(struct mxs_auart_port *s); 130static inline void mxs_auart_tx_chars(struct mxs_auart_port *s)
198
199static void dma_tx_callback(void *param)
200{ 131{
201 struct mxs_auart_port *s = param;
202 struct circ_buf *xmit = &s->port.state->xmit; 132 struct circ_buf *xmit = &s->port.state->xmit;
203 133
204 dma_unmap_sg(s->dev, &s->tx_sgl, 1, DMA_TO_DEVICE);
205
206 /* clear the bit used to serialize the DMA tx. */
207 clear_bit(MXS_AUART_DMA_TX_SYNC, &s->flags);
208 smp_mb__after_clear_bit();
209
210 /* wake up the possible processes. */
211 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
212 uart_write_wakeup(&s->port);
213
214 mxs_auart_tx_chars(s);
215}
216
217static int mxs_auart_dma_tx(struct mxs_auart_port *s, int size)
218{
219 struct dma_async_tx_descriptor *desc;
220 struct scatterlist *sgl = &s->tx_sgl;
221 struct dma_chan *channel = s->tx_dma_chan;
222 u32 pio;
223
224 /* [1] : send PIO. Note, the first pio word is CTRL1. */
225 pio = AUART_CTRL1_XFER_COUNT(size);
226 desc = dmaengine_prep_slave_sg(channel, (struct scatterlist *)&pio,
227 1, DMA_TRANS_NONE, 0);
228 if (!desc) {
229 dev_err(s->dev, "step 1 error\n");
230 return -EINVAL;
231 }
232
233 /* [2] : set DMA buffer. */
234 sg_init_one(sgl, s->tx_dma_buf, size);
235 dma_map_sg(s->dev, sgl, 1, DMA_TO_DEVICE);
236 desc = dmaengine_prep_slave_sg(channel, sgl,
237 1, DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
238 if (!desc) {
239 dev_err(s->dev, "step 2 error\n");
240 return -EINVAL;
241 }
242
243 /* [3] : submit the DMA */
244 desc->callback = dma_tx_callback;
245 desc->callback_param = s;
246 dmaengine_submit(desc);
247 dma_async_issue_pending(channel);
248 return 0;
249}
250
251static void mxs_auart_tx_chars(struct mxs_auart_port *s)
252{
253 struct circ_buf *xmit = &s->port.state->xmit;
254
255 if (auart_dma_enabled(s)) {
256 int i = 0;
257 int size;
258 void *buffer = s->tx_dma_buf;
259
260 if (test_and_set_bit(MXS_AUART_DMA_TX_SYNC, &s->flags))
261 return;
262
263 while (!uart_circ_empty(xmit) && !uart_tx_stopped(&s->port)) {
264 size = min_t(u32, UART_XMIT_SIZE - i,
265 CIRC_CNT_TO_END(xmit->head,
266 xmit->tail,
267 UART_XMIT_SIZE));
268 memcpy(buffer + i, xmit->buf + xmit->tail, size);
269 xmit->tail = (xmit->tail + size) & (UART_XMIT_SIZE - 1);
270
271 i += size;
272 if (i >= UART_XMIT_SIZE)
273 break;
274 }
275
276 if (uart_tx_stopped(&s->port))
277 mxs_auart_stop_tx(&s->port);
278
279 if (i) {
280 mxs_auart_dma_tx(s, i);
281 } else {
282 clear_bit(MXS_AUART_DMA_TX_SYNC, &s->flags);
283 smp_mb__after_clear_bit();
284 }
285 return;
286 }
287
288
289 while (!(readl(s->port.membase + AUART_STAT) & 134 while (!(readl(s->port.membase + AUART_STAT) &
290 AUART_STAT_TXFF)) { 135 AUART_STAT_TXFF)) {
291 if (s->port.x_char) { 136 if (s->port.x_char) {
@@ -300,12 +145,11 @@ static void mxs_auart_tx_chars(struct mxs_auart_port *s)
300 writel(xmit->buf[xmit->tail], 145 writel(xmit->buf[xmit->tail],
301 s->port.membase + AUART_DATA); 146 s->port.membase + AUART_DATA);
302 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 147 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
148 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
149 uart_write_wakeup(&s->port);
303 } else 150 } else
304 break; 151 break;
305 } 152 }
306 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
307 uart_write_wakeup(&s->port);
308
309 if (uart_circ_empty(&(s->port.state->xmit))) 153 if (uart_circ_empty(&(s->port.state->xmit)))
310 writel(AUART_INTR_TXIEN, 154 writel(AUART_INTR_TXIEN,
311 s->port.membase + AUART_INTR_CLR); 155 s->port.membase + AUART_INTR_CLR);
@@ -412,12 +256,9 @@ static void mxs_auart_set_mctrl(struct uart_port *u, unsigned mctrl)
412 256
413 u32 ctrl = readl(u->membase + AUART_CTRL2); 257 u32 ctrl = readl(u->membase + AUART_CTRL2);
414 258
415 ctrl &= ~AUART_CTRL2_RTSEN; 259 ctrl &= ~AUART_CTRL2_RTS;
416 if (mctrl & TIOCM_RTS) { 260 if (mctrl & TIOCM_RTS)
417 if (tty_port_cts_enabled(&u->state->port)) 261 ctrl |= AUART_CTRL2_RTS;
418 ctrl |= AUART_CTRL2_RTSEN;
419 }
420
421 s->ctrl = mctrl; 262 s->ctrl = mctrl;
422 writel(ctrl, u->membase + AUART_CTRL2); 263 writel(ctrl, u->membase + AUART_CTRL2);
423} 264}
@@ -439,159 +280,10 @@ static u32 mxs_auart_get_mctrl(struct uart_port *u)
439 return mctrl; 280 return mctrl;
440} 281}
441 282
442static bool mxs_auart_dma_filter(struct dma_chan *chan, void *param)
443{
444 struct mxs_auart_port *s = param;
445
446 if (!mxs_dma_is_apbx(chan))
447 return false;
448
449 if (s->dma_channel == chan->chan_id) {
450 chan->private = &s->dma_data;
451 return true;
452 }
453 return false;
454}
455
456static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s);
457static void dma_rx_callback(void *arg)
458{
459 struct mxs_auart_port *s = (struct mxs_auart_port *) arg;
460 struct tty_struct *tty = s->port.state->port.tty;
461 int count;
462 u32 stat;
463
464 dma_unmap_sg(s->dev, &s->rx_sgl, 1, DMA_FROM_DEVICE);
465
466 stat = readl(s->port.membase + AUART_STAT);
467 stat &= ~(AUART_STAT_OERR | AUART_STAT_BERR |
468 AUART_STAT_PERR | AUART_STAT_FERR);
469
470 count = stat & AUART_STAT_RXCOUNT_MASK;
471 tty_insert_flip_string(tty, s->rx_dma_buf, count);
472
473 writel(stat, s->port.membase + AUART_STAT);
474 tty_flip_buffer_push(tty);
475
476 /* start the next DMA for RX. */
477 mxs_auart_dma_prep_rx(s);
478}
479
480static int mxs_auart_dma_prep_rx(struct mxs_auart_port *s)
481{
482 struct dma_async_tx_descriptor *desc;
483 struct scatterlist *sgl = &s->rx_sgl;
484 struct dma_chan *channel = s->rx_dma_chan;
485 u32 pio[1];
486
487 /* [1] : send PIO */
488 pio[0] = AUART_CTRL0_RXTO_ENABLE
489 | AUART_CTRL0_RXTIMEOUT(0x80)
490 | AUART_CTRL0_XFER_COUNT(UART_XMIT_SIZE);
491 desc = dmaengine_prep_slave_sg(channel, (struct scatterlist *)pio,
492 1, DMA_TRANS_NONE, 0);
493 if (!desc) {
494 dev_err(s->dev, "step 1 error\n");
495 return -EINVAL;
496 }
497
498 /* [2] : send DMA request */
499 sg_init_one(sgl, s->rx_dma_buf, UART_XMIT_SIZE);
500 dma_map_sg(s->dev, sgl, 1, DMA_FROM_DEVICE);
501 desc = dmaengine_prep_slave_sg(channel, sgl, 1, DMA_DEV_TO_MEM,
502 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
503 if (!desc) {
504 dev_err(s->dev, "step 2 error\n");
505 return -1;
506 }
507
508 /* [3] : submit the DMA, but do not issue it. */
509 desc->callback = dma_rx_callback;
510 desc->callback_param = s;
511 dmaengine_submit(desc);
512 dma_async_issue_pending(channel);
513 return 0;
514}
515
516static void mxs_auart_dma_exit_channel(struct mxs_auart_port *s)
517{
518 if (s->tx_dma_chan) {
519 dma_release_channel(s->tx_dma_chan);
520 s->tx_dma_chan = NULL;
521 }
522 if (s->rx_dma_chan) {
523 dma_release_channel(s->rx_dma_chan);
524 s->rx_dma_chan = NULL;
525 }
526
527 kfree(s->tx_dma_buf);
528 kfree(s->rx_dma_buf);
529 s->tx_dma_buf = NULL;
530 s->rx_dma_buf = NULL;
531}
532
533static void mxs_auart_dma_exit(struct mxs_auart_port *s)
534{
535
536 writel(AUART_CTRL2_TXDMAE | AUART_CTRL2_RXDMAE | AUART_CTRL2_DMAONERR,
537 s->port.membase + AUART_CTRL2_CLR);
538
539 mxs_auart_dma_exit_channel(s);
540 s->flags &= ~MXS_AUART_DMA_ENABLED;
541 clear_bit(MXS_AUART_DMA_TX_SYNC, &s->flags);
542 clear_bit(MXS_AUART_DMA_RX_READY, &s->flags);
543}
544
545static int mxs_auart_dma_init(struct mxs_auart_port *s)
546{
547 dma_cap_mask_t mask;
548
549 if (auart_dma_enabled(s))
550 return 0;
551
552 /* We do not get the right DMA channels. */
553 if (s->dma_channel_rx == -1 || s->dma_channel_rx == -1)
554 return -EINVAL;
555
556 /* init for RX */
557 dma_cap_zero(mask);
558 dma_cap_set(DMA_SLAVE, mask);
559 s->dma_channel = s->dma_channel_rx;
560 s->dma_data.chan_irq = s->dma_irq_rx;
561 s->rx_dma_chan = dma_request_channel(mask, mxs_auart_dma_filter, s);
562 if (!s->rx_dma_chan)
563 goto err_out;
564 s->rx_dma_buf = kzalloc(UART_XMIT_SIZE, GFP_KERNEL | GFP_DMA);
565 if (!s->rx_dma_buf)
566 goto err_out;
567
568 /* init for TX */
569 s->dma_channel = s->dma_channel_tx;
570 s->dma_data.chan_irq = s->dma_irq_tx;
571 s->tx_dma_chan = dma_request_channel(mask, mxs_auart_dma_filter, s);
572 if (!s->tx_dma_chan)
573 goto err_out;
574 s->tx_dma_buf = kzalloc(UART_XMIT_SIZE, GFP_KERNEL | GFP_DMA);
575 if (!s->tx_dma_buf)
576 goto err_out;
577
578 /* set the flags */
579 s->flags |= MXS_AUART_DMA_ENABLED;
580 dev_dbg(s->dev, "enabled the DMA support.");
581
582 return 0;
583
584err_out:
585 mxs_auart_dma_exit_channel(s);
586 return -EINVAL;
587
588}
589
590static void mxs_auart_settermios(struct uart_port *u, 283static void mxs_auart_settermios(struct uart_port *u,
591 struct ktermios *termios, 284 struct ktermios *termios,
592 struct ktermios *old) 285 struct ktermios *old)
593{ 286{
594 struct mxs_auart_port *s = to_auart_port(u);
595 u32 bm, ctrl, ctrl2, div; 287 u32 bm, ctrl, ctrl2, div;
596 unsigned int cflag, baud; 288 unsigned int cflag, baud;
597 289
@@ -663,23 +355,10 @@ static void mxs_auart_settermios(struct uart_port *u,
663 ctrl |= AUART_LINECTRL_STP2; 355 ctrl |= AUART_LINECTRL_STP2;
664 356
665 /* figure out the hardware flow control settings */ 357 /* figure out the hardware flow control settings */
666 if (cflag & CRTSCTS) { 358 if (cflag & CRTSCTS)
667 /* 359 ctrl2 |= AUART_CTRL2_CTSEN;
668 * The DMA has a bug(see errata:2836) in mx23. 360 else
669 * So we can not implement the DMA for auart in mx23, 361 ctrl2 &= ~AUART_CTRL2_CTSEN;
670 * we can only implement the DMA support for auart
671 * in mx28.
672 */
673 if (is_imx28_auart(s) && (s->flags & MXS_AUART_DMA_CONFIG)) {
674 if (!mxs_auart_dma_init(s))
675 /* enable DMA tranfer */
676 ctrl2 |= AUART_CTRL2_TXDMAE | AUART_CTRL2_RXDMAE
677 | AUART_CTRL2_DMAONERR;
678 }
679 ctrl2 |= AUART_CTRL2_CTSEN | AUART_CTRL2_RTSEN;
680 } else {
681 ctrl2 &= ~(AUART_CTRL2_CTSEN | AUART_CTRL2_RTSEN);
682 }
683 362
684 /* set baud rate */ 363 /* set baud rate */
685 baud = uart_get_baud_rate(u, termios, old, 0, u->uartclk); 364 baud = uart_get_baud_rate(u, termios, old, 0, u->uartclk);
@@ -689,21 +368,6 @@ static void mxs_auart_settermios(struct uart_port *u,
689 368
690 writel(ctrl, u->membase + AUART_LINECTRL); 369 writel(ctrl, u->membase + AUART_LINECTRL);
691 writel(ctrl2, u->membase + AUART_CTRL2); 370 writel(ctrl2, u->membase + AUART_CTRL2);
692
693 uart_update_timeout(u, termios->c_cflag, baud);
694
695 /* prepare for the DMA RX. */
696 if (auart_dma_enabled(s) &&
697 !test_and_set_bit(MXS_AUART_DMA_RX_READY, &s->flags)) {
698 if (!mxs_auart_dma_prep_rx(s)) {
699 /* Disable the normal RX interrupt. */
700 writel(AUART_INTR_RXIEN | AUART_INTR_RTIEN,
701 u->membase + AUART_INTR_CLR);
702 } else {
703 mxs_auart_dma_exit(s);
704 dev_err(s->dev, "We can not start up the DMA.\n");
705 }
706 }
707} 371}
708 372
709static irqreturn_t mxs_auart_irq_handle(int irq, void *context) 373static irqreturn_t mxs_auart_irq_handle(int irq, void *context)
@@ -722,8 +386,7 @@ static irqreturn_t mxs_auart_irq_handle(int irq, void *context)
722 } 386 }
723 387
724 if (istat & (AUART_INTR_RTIS | AUART_INTR_RXIS)) { 388 if (istat & (AUART_INTR_RTIS | AUART_INTR_RXIS)) {
725 if (!auart_dma_enabled(s)) 389 mxs_auart_rx_chars(s);
726 mxs_auart_rx_chars(s);
727 istat &= ~(AUART_INTR_RTIS | AUART_INTR_RXIS); 390 istat &= ~(AUART_INTR_RTIS | AUART_INTR_RXIS);
728 } 391 }
729 392
@@ -761,7 +424,7 @@ static int mxs_auart_startup(struct uart_port *u)
761{ 424{
762 struct mxs_auart_port *s = to_auart_port(u); 425 struct mxs_auart_port *s = to_auart_port(u);
763 426
764 clk_prepare_enable(s->clk); 427 clk_enable(s->clk);
765 428
766 writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR); 429 writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR);
767 430
@@ -783,17 +446,14 @@ static void mxs_auart_shutdown(struct uart_port *u)
783{ 446{
784 struct mxs_auart_port *s = to_auart_port(u); 447 struct mxs_auart_port *s = to_auart_port(u);
785 448
786 if (auart_dma_enabled(s))
787 mxs_auart_dma_exit(s);
788
789 writel(AUART_CTRL2_UARTEN, u->membase + AUART_CTRL2_CLR); 449 writel(AUART_CTRL2_UARTEN, u->membase + AUART_CTRL2_CLR);
790 450
451 writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_SET);
452
791 writel(AUART_INTR_RXIEN | AUART_INTR_RTIEN | AUART_INTR_CTSMIEN, 453 writel(AUART_INTR_RXIEN | AUART_INTR_RTIEN | AUART_INTR_CTSMIEN,
792 u->membase + AUART_INTR_CLR); 454 u->membase + AUART_INTR_CLR);
793 455
794 writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_SET); 456 clk_disable(s->clk);
795
796 clk_disable_unprepare(s->clk);
797} 457}
798 458
799static unsigned int mxs_auart_tx_empty(struct uart_port *u) 459static unsigned int mxs_auart_tx_empty(struct uart_port *u)
@@ -974,7 +634,7 @@ auart_console_setup(struct console *co, char *options)
974 if (!s) 634 if (!s)
975 return -ENODEV; 635 return -ENODEV;
976 636
977 clk_prepare_enable(s->clk); 637 clk_enable(s->clk);
978 638
979 if (options) 639 if (options)
980 uart_parse_options(options, &baud, &parity, &bits, &flow); 640 uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -983,7 +643,7 @@ auart_console_setup(struct console *co, char *options)
983 643
984 ret = uart_set_options(&s->port, co, baud, parity, bits, flow); 644 ret = uart_set_options(&s->port, co, baud, parity, bits, flow);
985 645
986 clk_disable_unprepare(s->clk); 646 clk_disable(s->clk);
987 647
988 return ret; 648 return ret;
989} 649}
@@ -1011,54 +671,12 @@ static struct uart_driver auart_driver = {
1011#endif 671#endif
1012}; 672};
1013 673
1014/* 674static int __devinit mxs_auart_probe(struct platform_device *pdev)
1015 * This function returns 1 if pdev isn't a device instatiated by dt, 0 if it
1016 * could successfully get all information from dt or a negative errno.
1017 */
1018static int serial_mxs_probe_dt(struct mxs_auart_port *s,
1019 struct platform_device *pdev)
1020{
1021 struct device_node *np = pdev->dev.of_node;
1022 u32 dma_channel[2];
1023 int ret;
1024
1025 if (!np)
1026 /* no device tree device */
1027 return 1;
1028
1029 ret = of_alias_get_id(np, "serial");
1030 if (ret < 0) {
1031 dev_err(&pdev->dev, "failed to get alias id: %d\n", ret);
1032 return ret;
1033 }
1034 s->port.line = ret;
1035
1036 s->dma_irq_rx = platform_get_irq(pdev, 1);
1037 s->dma_irq_tx = platform_get_irq(pdev, 2);
1038
1039 ret = of_property_read_u32_array(np, "fsl,auart-dma-channel",
1040 dma_channel, 2);
1041 if (ret == 0) {
1042 s->dma_channel_rx = dma_channel[0];
1043 s->dma_channel_tx = dma_channel[1];
1044
1045 s->flags |= MXS_AUART_DMA_CONFIG;
1046 } else {
1047 s->dma_channel_rx = -1;
1048 s->dma_channel_tx = -1;
1049 }
1050 return 0;
1051}
1052
1053static int mxs_auart_probe(struct platform_device *pdev)
1054{ 675{
1055 const struct of_device_id *of_id =
1056 of_match_device(mxs_auart_dt_ids, &pdev->dev);
1057 struct mxs_auart_port *s; 676 struct mxs_auart_port *s;
1058 u32 version; 677 u32 version;
1059 int ret = 0; 678 int ret = 0;
1060 struct resource *r; 679 struct resource *r;
1061 struct pinctrl *pinctrl;
1062 680
1063 s = kzalloc(sizeof(struct mxs_auart_port), GFP_KERNEL); 681 s = kzalloc(sizeof(struct mxs_auart_port), GFP_KERNEL);
1064 if (!s) { 682 if (!s) {
@@ -1066,23 +684,6 @@ static int mxs_auart_probe(struct platform_device *pdev)
1066 goto out; 684 goto out;
1067 } 685 }
1068 686
1069 ret = serial_mxs_probe_dt(s, pdev);
1070 if (ret > 0)
1071 s->port.line = pdev->id < 0 ? 0 : pdev->id;
1072 else if (ret < 0)
1073 goto out_free;
1074
1075 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
1076 if (IS_ERR(pinctrl)) {
1077 ret = PTR_ERR(pinctrl);
1078 goto out_free;
1079 }
1080
1081 if (of_id) {
1082 pdev->id_entry = of_id->data;
1083 s->devtype = pdev->id_entry->driver_data;
1084 }
1085
1086 s->clk = clk_get(&pdev->dev, NULL); 687 s->clk = clk_get(&pdev->dev, NULL);
1087 if (IS_ERR(s->clk)) { 688 if (IS_ERR(s->clk)) {
1088 ret = PTR_ERR(s->clk); 689 ret = PTR_ERR(s->clk);
@@ -1099,11 +700,13 @@ static int mxs_auart_probe(struct platform_device *pdev)
1099 s->port.membase = ioremap(r->start, resource_size(r)); 700 s->port.membase = ioremap(r->start, resource_size(r));
1100 s->port.ops = &mxs_auart_ops; 701 s->port.ops = &mxs_auart_ops;
1101 s->port.iotype = UPIO_MEM; 702 s->port.iotype = UPIO_MEM;
703 s->port.line = pdev->id < 0 ? 0 : pdev->id;
1102 s->port.fifosize = 16; 704 s->port.fifosize = 16;
1103 s->port.uartclk = clk_get_rate(s->clk); 705 s->port.uartclk = clk_get_rate(s->clk);
1104 s->port.type = PORT_IMX; 706 s->port.type = PORT_IMX;
1105 s->port.dev = s->dev = get_device(&pdev->dev); 707 s->port.dev = s->dev = get_device(&pdev->dev);
1106 708
709 s->flags = 0;
1107 s->ctrl = 0; 710 s->ctrl = 0;
1108 711
1109 s->irq = platform_get_irq(pdev, 0); 712 s->irq = platform_get_irq(pdev, 0);
@@ -1114,7 +717,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
1114 717
1115 platform_set_drvdata(pdev, s); 718 platform_set_drvdata(pdev, s);
1116 719
1117 auart_port[s->port.line] = s; 720 auart_port[pdev->id] = s;
1118 721
1119 mxs_auart_reset(&s->port); 722 mxs_auart_reset(&s->port);
1120 723
@@ -1133,7 +736,6 @@ out_free_irq:
1133 auart_port[pdev->id] = NULL; 736 auart_port[pdev->id] = NULL;
1134 free_irq(s->irq, s); 737 free_irq(s->irq, s);
1135out_free_clk: 738out_free_clk:
1136 put_device(s->dev);
1137 clk_put(s->clk); 739 clk_put(s->clk);
1138out_free: 740out_free:
1139 kfree(s); 741 kfree(s);
@@ -1141,7 +743,7 @@ out:
1141 return ret; 743 return ret;
1142} 744}
1143 745
1144static int mxs_auart_remove(struct platform_device *pdev) 746static int __devexit mxs_auart_remove(struct platform_device *pdev)
1145{ 747{
1146 struct mxs_auart_port *s = platform_get_drvdata(pdev); 748 struct mxs_auart_port *s = platform_get_drvdata(pdev);
1147 749
@@ -1149,7 +751,6 @@ static int mxs_auart_remove(struct platform_device *pdev)
1149 751
1150 auart_port[pdev->id] = NULL; 752 auart_port[pdev->id] = NULL;
1151 753
1152 put_device(s->dev);
1153 clk_put(s->clk); 754 clk_put(s->clk);
1154 free_irq(s->irq, s); 755 free_irq(s->irq, s);
1155 kfree(s); 756 kfree(s);
@@ -1159,11 +760,10 @@ static int mxs_auart_remove(struct platform_device *pdev)
1159 760
1160static struct platform_driver mxs_auart_driver = { 761static struct platform_driver mxs_auart_driver = {
1161 .probe = mxs_auart_probe, 762 .probe = mxs_auart_probe,
1162 .remove = mxs_auart_remove, 763 .remove = __devexit_p(mxs_auart_remove),
1163 .driver = { 764 .driver = {
1164 .name = "mxs-auart", 765 .name = "mxs-auart",
1165 .owner = THIS_MODULE, 766 .owner = THIS_MODULE,
1166 .of_match_table = mxs_auart_dt_ids,
1167 }, 767 },
1168}; 768};
1169 769
@@ -1196,4 +796,3 @@ module_init(mxs_auart_init);
1196module_exit(mxs_auart_exit); 796module_exit(mxs_auart_exit);
1197MODULE_LICENSE("GPL"); 797MODULE_LICENSE("GPL");
1198MODULE_DESCRIPTION("Freescale MXS application uart driver"); 798MODULE_DESCRIPTION("Freescale MXS application uart driver");
1199MODULE_ALIAS("platform:mxs-auart");
diff --git a/drivers/tty/serial/nwpserial.c b/drivers/tty/serial/nwpserial.c
index dd4c31d1aee..de173671e3d 100644
--- a/drivers/tty/serial/nwpserial.c
+++ b/drivers/tty/serial/nwpserial.c
@@ -10,13 +10,11 @@
10 * 10 *
11 */ 11 */
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/export.h>
14#include <linux/console.h> 13#include <linux/console.h>
15#include <linux/serial.h> 14#include <linux/serial.h>
16#include <linux/serial_reg.h> 15#include <linux/serial_reg.h>
17#include <linux/serial_core.h> 16#include <linux/serial_core.h>
18#include <linux/tty.h> 17#include <linux/tty.h>
19#include <linux/tty_flip.h>
20#include <linux/irqreturn.h> 18#include <linux/irqreturn.h>
21#include <linux/mutex.h> 19#include <linux/mutex.h>
22#include <linux/of_platform.h> 20#include <linux/of_platform.h>
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index e7cae1c2d7d..e58cece6f44 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -12,49 +12,23 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/delay.h>
16#include <linux/serial_core.h> 15#include <linux/serial_core.h>
17#include <linux/serial_8250.h> 16#include <linux/serial_8250.h>
18#include <linux/serial_reg.h>
19#include <linux/of_address.h> 17#include <linux/of_address.h>
20#include <linux/of_irq.h> 18#include <linux/of_irq.h>
21#include <linux/of_serial.h>
22#include <linux/of_platform.h> 19#include <linux/of_platform.h>
23#include <linux/nwpserial.h> 20#include <linux/nwpserial.h>
24#include <linux/clk.h>
25 21
26struct of_serial_info { 22struct of_serial_info {
27 struct clk *clk;
28 int type; 23 int type;
29 int line; 24 int line;
30}; 25};
31 26
32#ifdef CONFIG_ARCH_TEGRA
33void tegra_serial_handle_break(struct uart_port *p)
34{
35 unsigned int status, tmout = 10000;
36
37 do {
38 status = p->serial_in(p, UART_LSR);
39 if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS))
40 status = p->serial_in(p, UART_RX);
41 else
42 break;
43 if (--tmout == 0)
44 break;
45 udelay(1);
46 } while (1);
47}
48/* FIXME remove this export when tegra finishes conversion to open firmware */
49EXPORT_SYMBOL_GPL(tegra_serial_handle_break);
50#endif
51
52/* 27/*
53 * Fill a struct uart_port for a given device node 28 * Fill a struct uart_port for a given device node
54 */ 29 */
55static int of_platform_serial_setup(struct platform_device *ofdev, 30static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
56 int type, struct uart_port *port, 31 int type, struct uart_port *port)
57 struct of_serial_info *info)
58{ 32{
59 struct resource resource; 33 struct resource resource;
60 struct device_node *np = ofdev->dev.of_node; 34 struct device_node *np = ofdev->dev.of_node;
@@ -63,17 +37,8 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
63 37
64 memset(port, 0, sizeof *port); 38 memset(port, 0, sizeof *port);
65 if (of_property_read_u32(np, "clock-frequency", &clk)) { 39 if (of_property_read_u32(np, "clock-frequency", &clk)) {
66 40 dev_warn(&ofdev->dev, "no clock-frequency property set\n");
67 /* Get clk rate through clk driver if present */ 41 return -ENODEV;
68 info->clk = clk_get(&ofdev->dev, NULL);
69 if (IS_ERR(info->clk)) {
70 dev_warn(&ofdev->dev,
71 "clk or clock-frequency not defined\n");
72 return PTR_ERR(info->clk);
73 }
74
75 clk_prepare_enable(info->clk);
76 clk = clk_get_rate(info->clk);
77 } 42 }
78 /* If current-speed was set, then try not to change it. */ 43 /* If current-speed was set, then try not to change it. */
79 if (of_property_read_u32(np, "current-speed", &spd) == 0) 44 if (of_property_read_u32(np, "current-speed", &spd) == 0)
@@ -82,7 +47,7 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
82 ret = of_address_to_resource(np, 0, &resource); 47 ret = of_address_to_resource(np, 0, &resource);
83 if (ret) { 48 if (ret) {
84 dev_warn(&ofdev->dev, "invalid address\n"); 49 dev_warn(&ofdev->dev, "invalid address\n");
85 goto out; 50 return ret;
86 } 51 }
87 52
88 spin_lock_init(&port->lock); 53 spin_lock_init(&port->lock);
@@ -109,8 +74,7 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
109 default: 74 default:
110 dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n", 75 dev_warn(&ofdev->dev, "unsupported reg-io-width (%d)\n",
111 prop); 76 prop);
112 ret = -EINVAL; 77 return -EINVAL;
113 goto out;
114 } 78 }
115 } 79 }
116 80
@@ -118,27 +82,16 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
118 port->uartclk = clk; 82 port->uartclk = clk;
119 port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP 83 port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP
120 | UPF_FIXED_PORT | UPF_FIXED_TYPE; 84 | UPF_FIXED_PORT | UPF_FIXED_TYPE;
121
122 if (of_find_property(np, "no-loopback-test", NULL))
123 port->flags |= UPF_SKIP_TEST;
124
125 port->dev = &ofdev->dev; 85 port->dev = &ofdev->dev;
126 86
127 if (type == PORT_TEGRA)
128 port->handle_break = tegra_serial_handle_break;
129
130 return 0; 87 return 0;
131out:
132 if (info->clk)
133 clk_disable_unprepare(info->clk);
134 return ret;
135} 88}
136 89
137/* 90/*
138 * Try to register a serial port 91 * Try to register a serial port
139 */ 92 */
140static struct of_device_id of_platform_serial_table[]; 93static struct of_device_id of_platform_serial_table[];
141static int of_platform_serial_probe(struct platform_device *ofdev) 94static int __devinit of_platform_serial_probe(struct platform_device *ofdev)
142{ 95{
143 const struct of_device_id *match; 96 const struct of_device_id *match;
144 struct of_serial_info *info; 97 struct of_serial_info *info;
@@ -158,22 +111,15 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
158 return -ENOMEM; 111 return -ENOMEM;
159 112
160 port_type = (unsigned long)match->data; 113 port_type = (unsigned long)match->data;
161 ret = of_platform_serial_setup(ofdev, port_type, &port, info); 114 ret = of_platform_serial_setup(ofdev, port_type, &port);
162 if (ret) 115 if (ret)
163 goto out; 116 goto out;
164 117
165 switch (port_type) { 118 switch (port_type) {
166#ifdef CONFIG_SERIAL_8250 119#ifdef CONFIG_SERIAL_8250
167 case PORT_8250 ... PORT_MAX_8250: 120 case PORT_8250 ... PORT_MAX_8250:
168 { 121 ret = serial8250_register_port(&port);
169 /* For now the of bindings don't support the extra
170 8250 specific bits */
171 struct uart_8250_port port8250;
172 memset(&port8250, 0, sizeof(port8250));
173 port8250.port = port;
174 ret = serial8250_register_8250_port(&port8250);
175 break; 122 break;
176 }
177#endif 123#endif
178#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL 124#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL
179 case PORT_NWPSERIAL: 125 case PORT_NWPSERIAL:
@@ -221,9 +167,6 @@ static int of_platform_serial_remove(struct platform_device *ofdev)
221 /* need to add code for these */ 167 /* need to add code for these */
222 break; 168 break;
223 } 169 }
224
225 if (info->clk)
226 clk_disable_unprepare(info->clk);
227 kfree(info); 170 kfree(info);
228 return 0; 171 return 0;
229} 172}
@@ -231,7 +174,7 @@ static int of_platform_serial_remove(struct platform_device *ofdev)
231/* 174/*
232 * A few common types, add more as needed. 175 * A few common types, add more as needed.
233 */ 176 */
234static struct of_device_id of_platform_serial_table[] = { 177static struct of_device_id __devinitdata of_platform_serial_table[] = {
235 { .compatible = "ns8250", .data = (void *)PORT_8250, }, 178 { .compatible = "ns8250", .data = (void *)PORT_8250, },
236 { .compatible = "ns16450", .data = (void *)PORT_16450, }, 179 { .compatible = "ns16450", .data = (void *)PORT_16450, },
237 { .compatible = "ns16550a", .data = (void *)PORT_16550A, }, 180 { .compatible = "ns16550a", .data = (void *)PORT_16550A, },
@@ -239,7 +182,6 @@ static struct of_device_id of_platform_serial_table[] = {
239 { .compatible = "ns16750", .data = (void *)PORT_16750, }, 182 { .compatible = "ns16750", .data = (void *)PORT_16750, },
240 { .compatible = "ns16850", .data = (void *)PORT_16850, }, 183 { .compatible = "ns16850", .data = (void *)PORT_16850, },
241 { .compatible = "nvidia,tegra20-uart", .data = (void *)PORT_TEGRA, }, 184 { .compatible = "nvidia,tegra20-uart", .data = (void *)PORT_TEGRA, },
242 { .compatible = "nxp,lpc3220-uart", .data = (void *)PORT_LPC3220, },
243#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL 185#ifdef CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL
244 { .compatible = "ibm,qpace-nwp-serial", 186 { .compatible = "ibm,qpace-nwp-serial",
245 .data = (void *)PORT_NWPSERIAL, }, 187 .data = (void *)PORT_NWPSERIAL, },
@@ -258,7 +200,17 @@ static struct platform_driver of_platform_serial_driver = {
258 .remove = of_platform_serial_remove, 200 .remove = of_platform_serial_remove,
259}; 201};
260 202
261module_platform_driver(of_platform_serial_driver); 203static int __init of_platform_serial_init(void)
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);
262 214
263MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>"); 215MODULE_AUTHOR("Arnd Bergmann <arnd@arndb.de>");
264MODULE_LICENSE("GPL"); 216MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 57d6b29c039..5e713d3ef1f 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -32,144 +32,22 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/tty.h> 33#include <linux/tty.h>
34#include <linux/tty_flip.h> 34#include <linux/tty_flip.h>
35#include <linux/platform_device.h>
36#include <linux/io.h> 35#include <linux/io.h>
36#include <linux/dma-mapping.h>
37#include <linux/clk.h> 37#include <linux/clk.h>
38#include <linux/serial_core.h> 38#include <linux/serial_core.h>
39#include <linux/irq.h> 39#include <linux/irq.h>
40#include <linux/pm_runtime.h>
41#include <linux/of.h>
42#include <linux/gpio.h>
43#include <linux/pinctrl/consumer.h>
44#include <linux/platform_data/serial-omap.h>
45 40
46#define OMAP_MAX_HSUART_PORTS 6 41#include <plat/dma.h>
47 42#include <plat/dmtimer.h>
48#define UART_BUILD_REVISION(x, y) (((x) << 8) | (y)) 43#include <plat/omap-serial.h>
49
50#define OMAP_UART_REV_42 0x0402
51#define OMAP_UART_REV_46 0x0406
52#define OMAP_UART_REV_52 0x0502
53#define OMAP_UART_REV_63 0x0603
54
55#define UART_ERRATA_i202_MDR1_ACCESS BIT(0)
56#define UART_ERRATA_i291_DMA_FORCEIDLE BIT(1)
57
58#define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/
59
60/* SCR register bitmasks */
61#define OMAP_UART_SCR_RX_TRIG_GRANU1_MASK (1 << 7)
62#define OMAP_UART_SCR_TX_EMPTY (1 << 3)
63
64/* FCR register bitmasks */
65#define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6)
66#define OMAP_UART_FCR_TX_FIFO_TRIG_MASK (0x3 << 4)
67
68/* MVR register bitmasks */
69#define OMAP_UART_MVR_SCHEME_SHIFT 30
70
71#define OMAP_UART_LEGACY_MVR_MAJ_MASK 0xf0
72#define OMAP_UART_LEGACY_MVR_MAJ_SHIFT 4
73#define OMAP_UART_LEGACY_MVR_MIN_MASK 0x0f
74
75#define OMAP_UART_MVR_MAJ_MASK 0x700
76#define OMAP_UART_MVR_MAJ_SHIFT 8
77#define OMAP_UART_MVR_MIN_MASK 0x3f
78
79#define OMAP_UART_DMA_CH_FREE -1
80
81#define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
82#define OMAP_MODE13X_SPEED 230400
83
84/* WER = 0x7F
85 * Enable module level wakeup in WER reg
86 */
87#define OMAP_UART_WER_MOD_WKUP 0X7F
88
89/* Enable XON/XOFF flow control on output */
90#define OMAP_UART_SW_TX 0x08
91
92/* Enable XON/XOFF flow control on input */
93#define OMAP_UART_SW_RX 0x02
94
95#define OMAP_UART_SW_CLR 0xF0
96
97#define OMAP_UART_TCR_TRIG 0x0F
98
99struct uart_omap_dma {
100 u8 uart_dma_tx;
101 u8 uart_dma_rx;
102 int rx_dma_channel;
103 int tx_dma_channel;
104 dma_addr_t rx_buf_dma_phys;
105 dma_addr_t tx_buf_dma_phys;
106 unsigned int uart_base;
107 /*
108 * Buffer for rx dma.It is not required for tx because the buffer
109 * comes from port structure.
110 */
111 unsigned char *rx_buf;
112 unsigned int prev_rx_dma_pos;
113 int tx_buf_size;
114 int tx_dma_used;
115 int rx_dma_used;
116 spinlock_t tx_lock;
117 spinlock_t rx_lock;
118 /* timer to poll activity on rx dma */
119 struct timer_list rx_timer;
120 unsigned int rx_buf_size;
121 unsigned int rx_poll_rate;
122 unsigned int rx_timeout;
123};
124
125struct uart_omap_port {
126 struct uart_port port;
127 struct uart_omap_dma uart_dma;
128 struct device *dev;
129
130 unsigned char ier;
131 unsigned char lcr;
132 unsigned char mcr;
133 unsigned char fcr;
134 unsigned char efr;
135 unsigned char dll;
136 unsigned char dlh;
137 unsigned char mdr1;
138 unsigned char scr;
139
140 int use_dma;
141 /*
142 * Some bits in registers are cleared on a read, so they must
143 * be saved whenever the register is read but the bits will not
144 * be immediately processed.
145 */
146 unsigned int lsr_break_flag;
147 unsigned char msr_saved_flags;
148 char name[20];
149 unsigned long port_activity;
150 int context_loss_cnt;
151 u32 errata;
152 u8 wakeups_enabled;
153
154 int DTR_gpio;
155 int DTR_inverted;
156 int DTR_active;
157
158 struct pm_qos_request pm_qos_request;
159 u32 latency;
160 u32 calc_latency;
161 struct work_struct qos_work;
162 struct pinctrl *pins;
163};
164
165#define to_uart_omap_port(p) ((container_of((p), struct uart_omap_port, port)))
166 44
167static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS]; 45static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS];
168 46
169/* Forward declaration of functions */ 47/* Forward declaration of functions */
170static void serial_omap_mdr1_errataset(struct uart_omap_port *up, u8 mdr1); 48static void uart_tx_dma_callback(int lch, u16 ch_status, void *data);
171 49static void serial_omap_rx_timeout(unsigned long uart_no);
172static struct workqueue_struct *serial_omap_uart_wq; 50static int serial_omap_start_rxdma(struct uart_omap_port *up);
173 51
174static inline unsigned int serial_in(struct uart_omap_port *up, int offset) 52static inline unsigned int serial_in(struct uart_omap_port *up, int offset)
175{ 53{
@@ -191,46 +69,6 @@ static inline void serial_omap_clear_fifos(struct uart_omap_port *up)
191 serial_out(up, UART_FCR, 0); 69 serial_out(up, UART_FCR, 0);
192} 70}
193 71
194static int serial_omap_get_context_loss_count(struct uart_omap_port *up)
195{
196 struct omap_uart_port_info *pdata = up->dev->platform_data;
197
198 if (!pdata || !pdata->get_context_loss_count)
199 return 0;
200
201 return pdata->get_context_loss_count(up->dev);
202}
203
204static void serial_omap_set_forceidle(struct uart_omap_port *up)
205{
206 struct omap_uart_port_info *pdata = up->dev->platform_data;
207
208 if (!pdata || !pdata->set_forceidle)
209 return;
210
211 pdata->set_forceidle(up->dev);
212}
213
214static void serial_omap_set_noidle(struct uart_omap_port *up)
215{
216 struct omap_uart_port_info *pdata = up->dev->platform_data;
217
218 if (!pdata || !pdata->set_noidle)
219 return;
220
221 pdata->set_noidle(up->dev);
222}
223
224static void serial_omap_enable_wakeup(struct uart_omap_port *up, bool enable)
225{
226 struct omap_uart_port_info *pdata = up->dev->platform_data;
227
228 if (!pdata || !pdata->enable_wakeup)
229 return;
230
231 pdata->enable_wakeup(up->dev, enable);
232}
233
234/* 72/*
235 * serial_omap_get_divisor - calculate divisor value 73 * serial_omap_get_divisor - calculate divisor value
236 * @port: uart port info 74 * @port: uart port info
@@ -256,55 +94,132 @@ serial_omap_get_divisor(struct uart_port *port, unsigned int baud)
256 return port->uartclk/(baud * divisor); 94 return port->uartclk/(baud * divisor);
257} 95}
258 96
259static void serial_omap_enable_ms(struct uart_port *port) 97static void serial_omap_stop_rxdma(struct uart_omap_port *up)
260{ 98{
261 struct uart_omap_port *up = to_uart_omap_port(port); 99 if (up->uart_dma.rx_dma_used) {
100 del_timer(&up->uart_dma.rx_timer);
101 omap_stop_dma(up->uart_dma.rx_dma_channel);
102 omap_free_dma(up->uart_dma.rx_dma_channel);
103 up->uart_dma.rx_dma_channel = OMAP_UART_DMA_CH_FREE;
104 up->uart_dma.rx_dma_used = false;
105 }
106}
262 107
263 dev_dbg(up->port.dev, "serial_omap_enable_ms+%d\n", up->port.line); 108static void serial_omap_enable_ms(struct uart_port *port)
109{
110 struct uart_omap_port *up = (struct uart_omap_port *)port;
264 111
265 pm_runtime_get_sync(up->dev); 112 dev_dbg(up->port.dev, "serial_omap_enable_ms+%d\n", up->pdev->id);
266 up->ier |= UART_IER_MSI; 113 up->ier |= UART_IER_MSI;
267 serial_out(up, UART_IER, up->ier); 114 serial_out(up, UART_IER, up->ier);
268 pm_runtime_mark_last_busy(up->dev);
269 pm_runtime_put_autosuspend(up->dev);
270} 115}
271 116
272static void serial_omap_stop_tx(struct uart_port *port) 117static void serial_omap_stop_tx(struct uart_port *port)
273{ 118{
274 struct uart_omap_port *up = to_uart_omap_port(port); 119 struct uart_omap_port *up = (struct uart_omap_port *)port;
120
121 if (up->use_dma &&
122 up->uart_dma.tx_dma_channel != OMAP_UART_DMA_CH_FREE) {
123 /*
124 * Check if dma is still active. If yes do nothing,
125 * return. Else stop dma
126 */
127 if (omap_get_dma_active_status(up->uart_dma.tx_dma_channel))
128 return;
129 omap_stop_dma(up->uart_dma.tx_dma_channel);
130 omap_free_dma(up->uart_dma.tx_dma_channel);
131 up->uart_dma.tx_dma_channel = OMAP_UART_DMA_CH_FREE;
132 }
275 133
276 pm_runtime_get_sync(up->dev);
277 if (up->ier & UART_IER_THRI) { 134 if (up->ier & UART_IER_THRI) {
278 up->ier &= ~UART_IER_THRI; 135 up->ier &= ~UART_IER_THRI;
279 serial_out(up, UART_IER, up->ier); 136 serial_out(up, UART_IER, up->ier);
280 } 137 }
281
282 serial_omap_set_forceidle(up);
283
284 pm_runtime_mark_last_busy(up->dev);
285 pm_runtime_put_autosuspend(up->dev);
286} 138}
287 139
288static void serial_omap_stop_rx(struct uart_port *port) 140static void serial_omap_stop_rx(struct uart_port *port)
289{ 141{
290 struct uart_omap_port *up = to_uart_omap_port(port); 142 struct uart_omap_port *up = (struct uart_omap_port *)port;
291 143
292 pm_runtime_get_sync(up->dev); 144 if (up->use_dma)
145 serial_omap_stop_rxdma(up);
293 up->ier &= ~UART_IER_RLSI; 146 up->ier &= ~UART_IER_RLSI;
294 up->port.read_status_mask &= ~UART_LSR_DR; 147 up->port.read_status_mask &= ~UART_LSR_DR;
295 serial_out(up, UART_IER, up->ier); 148 serial_out(up, UART_IER, up->ier);
296 pm_runtime_mark_last_busy(up->dev);
297 pm_runtime_put_autosuspend(up->dev);
298} 149}
299 150
300static void transmit_chars(struct uart_omap_port *up, unsigned int lsr) 151static inline void receive_chars(struct uart_omap_port *up, int *status)
152{
153 struct tty_struct *tty = up->port.state->port.tty;
154 unsigned int flag;
155 unsigned char ch, lsr = *status;
156 int max_count = 256;
157
158 do {
159 if (likely(lsr & UART_LSR_DR))
160 ch = serial_in(up, UART_RX);
161 flag = TTY_NORMAL;
162 up->port.icount.rx++;
163
164 if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
165 /*
166 * For statistics only
167 */
168 if (lsr & UART_LSR_BI) {
169 lsr &= ~(UART_LSR_FE | UART_LSR_PE);
170 up->port.icount.brk++;
171 /*
172 * We do the SysRQ and SAK checking
173 * here because otherwise the break
174 * may get masked by ignore_status_mask
175 * or read_status_mask.
176 */
177 if (uart_handle_break(&up->port))
178 goto ignore_char;
179 } else if (lsr & UART_LSR_PE) {
180 up->port.icount.parity++;
181 } else if (lsr & UART_LSR_FE) {
182 up->port.icount.frame++;
183 }
184
185 if (lsr & UART_LSR_OE)
186 up->port.icount.overrun++;
187
188 /*
189 * Mask off conditions which should be ignored.
190 */
191 lsr &= up->port.read_status_mask;
192
193#ifdef CONFIG_SERIAL_OMAP_CONSOLE
194 if (up->port.line == up->port.cons->index) {
195 /* Recover the break flag from console xmit */
196 lsr |= up->lsr_break_flag;
197 }
198#endif
199 if (lsr & UART_LSR_BI)
200 flag = TTY_BREAK;
201 else if (lsr & UART_LSR_PE)
202 flag = TTY_PARITY;
203 else if (lsr & UART_LSR_FE)
204 flag = TTY_FRAME;
205 }
206
207 if (uart_handle_sysrq_char(&up->port, ch))
208 goto ignore_char;
209 uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
210ignore_char:
211 lsr = serial_in(up, UART_LSR);
212 } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
213 spin_unlock(&up->port.lock);
214 tty_flip_buffer_push(tty);
215 spin_lock(&up->port.lock);
216}
217
218static void transmit_chars(struct uart_omap_port *up)
301{ 219{
302 struct circ_buf *xmit = &up->port.state->xmit; 220 struct circ_buf *xmit = &up->port.state->xmit;
303 int count; 221 int count;
304 222
305 if (!(lsr & UART_LSR_THRE))
306 return;
307
308 if (up->port.x_char) { 223 if (up->port.x_char) {
309 serial_out(up, UART_TX, up->port.x_char); 224 serial_out(up, UART_TX, up->port.x_char);
310 up->port.icount.tx++; 225 up->port.icount.tx++;
@@ -324,11 +239,8 @@ static void transmit_chars(struct uart_omap_port *up, unsigned int lsr)
324 break; 239 break;
325 } while (--count > 0); 240 } while (--count > 0);
326 241
327 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) { 242 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
328 spin_unlock(&up->port.lock);
329 uart_write_wakeup(&up->port); 243 uart_write_wakeup(&up->port);
330 spin_lock(&up->port.lock);
331 }
332 244
333 if (uart_circ_empty(xmit)) 245 if (uart_circ_empty(xmit))
334 serial_omap_stop_tx(&up->port); 246 serial_omap_stop_tx(&up->port);
@@ -344,41 +256,63 @@ static inline void serial_omap_enable_ier_thri(struct uart_omap_port *up)
344 256
345static void serial_omap_start_tx(struct uart_port *port) 257static void serial_omap_start_tx(struct uart_port *port)
346{ 258{
347 struct uart_omap_port *up = to_uart_omap_port(port); 259 struct uart_omap_port *up = (struct uart_omap_port *)port;
260 struct circ_buf *xmit;
261 unsigned int start;
262 int ret = 0;
348 263
349 pm_runtime_get_sync(up->dev); 264 if (!up->use_dma) {
350 serial_omap_enable_ier_thri(up); 265 serial_omap_enable_ier_thri(up);
351 serial_omap_set_noidle(up); 266 return;
352 pm_runtime_mark_last_busy(up->dev); 267 }
353 pm_runtime_put_autosuspend(up->dev);
354}
355 268
356static void serial_omap_throttle(struct uart_port *port) 269 if (up->uart_dma.tx_dma_used)
357{ 270 return;
358 struct uart_omap_port *up = to_uart_omap_port(port);
359 unsigned long flags;
360 271
361 pm_runtime_get_sync(up->dev); 272 xmit = &up->port.state->xmit;
362 spin_lock_irqsave(&up->port.lock, flags);
363 up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
364 serial_out(up, UART_IER, up->ier);
365 spin_unlock_irqrestore(&up->port.lock, flags);
366 pm_runtime_mark_last_busy(up->dev);
367 pm_runtime_put_autosuspend(up->dev);
368}
369 273
370static void serial_omap_unthrottle(struct uart_port *port) 274 if (up->uart_dma.tx_dma_channel == OMAP_UART_DMA_CH_FREE) {
371{ 275 ret = omap_request_dma(up->uart_dma.uart_dma_tx,
372 struct uart_omap_port *up = to_uart_omap_port(port); 276 "UART Tx DMA",
373 unsigned long flags; 277 (void *)uart_tx_dma_callback, up,
278 &(up->uart_dma.tx_dma_channel));
374 279
375 pm_runtime_get_sync(up->dev); 280 if (ret < 0) {
376 spin_lock_irqsave(&up->port.lock, flags); 281 serial_omap_enable_ier_thri(up);
377 up->ier |= UART_IER_RLSI | UART_IER_RDI; 282 return;
378 serial_out(up, UART_IER, up->ier); 283 }
379 spin_unlock_irqrestore(&up->port.lock, flags); 284 }
380 pm_runtime_mark_last_busy(up->dev); 285 spin_lock(&(up->uart_dma.tx_lock));
381 pm_runtime_put_autosuspend(up->dev); 286 up->uart_dma.tx_dma_used = true;
287 spin_unlock(&(up->uart_dma.tx_lock));
288
289 start = up->uart_dma.tx_buf_dma_phys +
290 (xmit->tail & (UART_XMIT_SIZE - 1));
291
292 up->uart_dma.tx_buf_size = uart_circ_chars_pending(xmit);
293 /*
294 * It is a circular buffer. See if the buffer has wounded back.
295 * If yes it will have to be transferred in two separate dma
296 * transfers
297 */
298 if (start + up->uart_dma.tx_buf_size >=
299 up->uart_dma.tx_buf_dma_phys + UART_XMIT_SIZE)
300 up->uart_dma.tx_buf_size =
301 (up->uart_dma.tx_buf_dma_phys +
302 UART_XMIT_SIZE) - start;
303
304 omap_set_dma_dest_params(up->uart_dma.tx_dma_channel, 0,
305 OMAP_DMA_AMODE_CONSTANT,
306 up->uart_dma.uart_base, 0, 0);
307 omap_set_dma_src_params(up->uart_dma.tx_dma_channel, 0,
308 OMAP_DMA_AMODE_POST_INC, start, 0, 0);
309 omap_set_dma_transfer_params(up->uart_dma.tx_dma_channel,
310 OMAP_DMA_DATA_TYPE_S8,
311 up->uart_dma.tx_buf_size, 1,
312 OMAP_DMA_SYNC_ELEMENT,
313 up->uart_dma.uart_dma_tx, 0);
314 /* FIXME: Cache maintenance needed here? */
315 omap_start_dma(up->uart_dma.tx_dma_channel);
382} 316}
383 317
384static unsigned int check_modem_status(struct uart_omap_port *up) 318static unsigned int check_modem_status(struct uart_omap_port *up)
@@ -409,164 +343,67 @@ static unsigned int check_modem_status(struct uart_omap_port *up)
409 return status; 343 return status;
410} 344}
411 345
412static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr)
413{
414 unsigned int flag;
415 unsigned char ch = 0;
416
417 if (likely(lsr & UART_LSR_DR))
418 ch = serial_in(up, UART_RX);
419
420 up->port.icount.rx++;
421 flag = TTY_NORMAL;
422
423 if (lsr & UART_LSR_BI) {
424 flag = TTY_BREAK;
425 lsr &= ~(UART_LSR_FE | UART_LSR_PE);
426 up->port.icount.brk++;
427 /*
428 * We do the SysRQ and SAK checking
429 * here because otherwise the break
430 * may get masked by ignore_status_mask
431 * or read_status_mask.
432 */
433 if (uart_handle_break(&up->port))
434 return;
435
436 }
437
438 if (lsr & UART_LSR_PE) {
439 flag = TTY_PARITY;
440 up->port.icount.parity++;
441 }
442
443 if (lsr & UART_LSR_FE) {
444 flag = TTY_FRAME;
445 up->port.icount.frame++;
446 }
447
448 if (lsr & UART_LSR_OE)
449 up->port.icount.overrun++;
450
451#ifdef CONFIG_SERIAL_OMAP_CONSOLE
452 if (up->port.line == up->port.cons->index) {
453 /* Recover the break flag from console xmit */
454 lsr |= up->lsr_break_flag;
455 }
456#endif
457 uart_insert_char(&up->port, lsr, UART_LSR_OE, 0, flag);
458}
459
460static void serial_omap_rdi(struct uart_omap_port *up, unsigned int lsr)
461{
462 unsigned char ch = 0;
463 unsigned int flag;
464
465 if (!(lsr & UART_LSR_DR))
466 return;
467
468 ch = serial_in(up, UART_RX);
469 flag = TTY_NORMAL;
470 up->port.icount.rx++;
471
472 if (uart_handle_sysrq_char(&up->port, ch))
473 return;
474
475 uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
476}
477
478/** 346/**
479 * serial_omap_irq() - This handles the interrupt from one port 347 * serial_omap_irq() - This handles the interrupt from one port
480 * @irq: uart port irq number 348 * @irq: uart port irq number
481 * @dev_id: uart port info 349 * @dev_id: uart port info
482 */ 350 */
483static irqreturn_t serial_omap_irq(int irq, void *dev_id) 351static inline irqreturn_t serial_omap_irq(int irq, void *dev_id)
484{ 352{
485 struct uart_omap_port *up = dev_id; 353 struct uart_omap_port *up = dev_id;
486 struct tty_struct *tty = up->port.state->port.tty;
487 unsigned int iir, lsr; 354 unsigned int iir, lsr;
488 unsigned int type; 355 unsigned long flags;
489 irqreturn_t ret = IRQ_NONE;
490 int max_count = 256;
491
492 spin_lock(&up->port.lock);
493 pm_runtime_get_sync(up->dev);
494
495 do {
496 iir = serial_in(up, UART_IIR);
497 if (iir & UART_IIR_NO_INT)
498 break;
499
500 ret = IRQ_HANDLED;
501 lsr = serial_in(up, UART_LSR);
502 356
503 /* extract IRQ type from IIR register */ 357 iir = serial_in(up, UART_IIR);
504 type = iir & 0x3e; 358 if (iir & UART_IIR_NO_INT)
359 return IRQ_NONE;
505 360
506 switch (type) { 361 spin_lock_irqsave(&up->port.lock, flags);
507 case UART_IIR_MSI: 362 lsr = serial_in(up, UART_LSR);
508 check_modem_status(up); 363 if (iir & UART_IIR_RLSI) {
509 break; 364 if (!up->use_dma) {
510 case UART_IIR_THRI: 365 if (lsr & UART_LSR_DR)
511 transmit_chars(up, lsr); 366 receive_chars(up, &lsr);
512 break; 367 } else {
513 case UART_IIR_RX_TIMEOUT: 368 up->ier &= ~(UART_IER_RDI | UART_IER_RLSI);
514 /* FALLTHROUGH */ 369 serial_out(up, UART_IER, up->ier);
515 case UART_IIR_RDI: 370 if ((serial_omap_start_rxdma(up) != 0) &&
516 serial_omap_rdi(up, lsr); 371 (lsr & UART_LSR_DR))
517 break; 372 receive_chars(up, &lsr);
518 case UART_IIR_RLSI:
519 serial_omap_rlsi(up, lsr);
520 break;
521 case UART_IIR_CTS_RTS_DSR:
522 /* simply try again */
523 break;
524 case UART_IIR_XOFF:
525 /* FALLTHROUGH */
526 default:
527 break;
528 } 373 }
529 } while (!(iir & UART_IIR_NO_INT) && max_count--); 374 }
530
531 spin_unlock(&up->port.lock);
532 375
533 tty_flip_buffer_push(tty); 376 check_modem_status(up);
377 if ((lsr & UART_LSR_THRE) && (iir & UART_IIR_THRI))
378 transmit_chars(up);
534 379
535 pm_runtime_mark_last_busy(up->dev); 380 spin_unlock_irqrestore(&up->port.lock, flags);
536 pm_runtime_put_autosuspend(up->dev);
537 up->port_activity = jiffies; 381 up->port_activity = jiffies;
538 382 return IRQ_HANDLED;
539 return ret;
540} 383}
541 384
542static unsigned int serial_omap_tx_empty(struct uart_port *port) 385static unsigned int serial_omap_tx_empty(struct uart_port *port)
543{ 386{
544 struct uart_omap_port *up = to_uart_omap_port(port); 387 struct uart_omap_port *up = (struct uart_omap_port *)port;
545 unsigned long flags = 0; 388 unsigned long flags = 0;
546 unsigned int ret = 0; 389 unsigned int ret = 0;
547 390
548 pm_runtime_get_sync(up->dev); 391 dev_dbg(up->port.dev, "serial_omap_tx_empty+%d\n", up->pdev->id);
549 dev_dbg(up->port.dev, "serial_omap_tx_empty+%d\n", up->port.line);
550 spin_lock_irqsave(&up->port.lock, flags); 392 spin_lock_irqsave(&up->port.lock, flags);
551 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; 393 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
552 spin_unlock_irqrestore(&up->port.lock, flags); 394 spin_unlock_irqrestore(&up->port.lock, flags);
553 pm_runtime_mark_last_busy(up->dev); 395
554 pm_runtime_put_autosuspend(up->dev);
555 return ret; 396 return ret;
556} 397}
557 398
558static unsigned int serial_omap_get_mctrl(struct uart_port *port) 399static unsigned int serial_omap_get_mctrl(struct uart_port *port)
559{ 400{
560 struct uart_omap_port *up = to_uart_omap_port(port); 401 struct uart_omap_port *up = (struct uart_omap_port *)port;
561 unsigned int status; 402 unsigned char status;
562 unsigned int ret = 0; 403 unsigned int ret = 0;
563 404
564 pm_runtime_get_sync(up->dev);
565 status = check_modem_status(up); 405 status = check_modem_status(up);
566 pm_runtime_mark_last_busy(up->dev); 406 dev_dbg(up->port.dev, "serial_omap_get_mctrl+%d\n", up->pdev->id);
567 pm_runtime_put_autosuspend(up->dev);
568
569 dev_dbg(up->port.dev, "serial_omap_get_mctrl+%d\n", up->port.line);
570 407
571 if (status & UART_MSR_DCD) 408 if (status & UART_MSR_DCD)
572 ret |= TIOCM_CAR; 409 ret |= TIOCM_CAR;
@@ -581,10 +418,10 @@ static unsigned int serial_omap_get_mctrl(struct uart_port *port)
581 418
582static void serial_omap_set_mctrl(struct uart_port *port, unsigned int mctrl) 419static void serial_omap_set_mctrl(struct uart_port *port, unsigned int mctrl)
583{ 420{
584 struct uart_omap_port *up = to_uart_omap_port(port); 421 struct uart_omap_port *up = (struct uart_omap_port *)port;
585 unsigned char mcr = 0, old_mcr; 422 unsigned char mcr = 0;
586 423
587 dev_dbg(up->port.dev, "serial_omap_set_mctrl+%d\n", up->port.line); 424 dev_dbg(up->port.dev, "serial_omap_set_mctrl+%d\n", up->pdev->id);
588 if (mctrl & TIOCM_RTS) 425 if (mctrl & TIOCM_RTS)
589 mcr |= UART_MCR_RTS; 426 mcr |= UART_MCR_RTS;
590 if (mctrl & TIOCM_DTR) 427 if (mctrl & TIOCM_DTR)
@@ -596,33 +433,16 @@ static void serial_omap_set_mctrl(struct uart_port *port, unsigned int mctrl)
596 if (mctrl & TIOCM_LOOP) 433 if (mctrl & TIOCM_LOOP)
597 mcr |= UART_MCR_LOOP; 434 mcr |= UART_MCR_LOOP;
598 435
599 pm_runtime_get_sync(up->dev); 436 mcr |= up->mcr;
600 old_mcr = serial_in(up, UART_MCR); 437 serial_out(up, UART_MCR, mcr);
601 old_mcr &= ~(UART_MCR_LOOP | UART_MCR_OUT2 | UART_MCR_OUT1 |
602 UART_MCR_DTR | UART_MCR_RTS);
603 up->mcr = old_mcr | mcr;
604 serial_out(up, UART_MCR, up->mcr);
605 pm_runtime_mark_last_busy(up->dev);
606 pm_runtime_put_autosuspend(up->dev);
607
608 if (gpio_is_valid(up->DTR_gpio) &&
609 !!(mctrl & TIOCM_DTR) != up->DTR_active) {
610 up->DTR_active = !up->DTR_active;
611 if (gpio_cansleep(up->DTR_gpio))
612 schedule_work(&up->qos_work);
613 else
614 gpio_set_value(up->DTR_gpio,
615 up->DTR_active != up->DTR_inverted);
616 }
617} 438}
618 439
619static void serial_omap_break_ctl(struct uart_port *port, int break_state) 440static void serial_omap_break_ctl(struct uart_port *port, int break_state)
620{ 441{
621 struct uart_omap_port *up = to_uart_omap_port(port); 442 struct uart_omap_port *up = (struct uart_omap_port *)port;
622 unsigned long flags = 0; 443 unsigned long flags = 0;
623 444
624 dev_dbg(up->port.dev, "serial_omap_break_ctl+%d\n", up->port.line); 445 dev_dbg(up->port.dev, "serial_omap_break_ctl+%d\n", up->pdev->id);
625 pm_runtime_get_sync(up->dev);
626 spin_lock_irqsave(&up->port.lock, flags); 446 spin_lock_irqsave(&up->port.lock, flags);
627 if (break_state == -1) 447 if (break_state == -1)
628 up->lcr |= UART_LCR_SBC; 448 up->lcr |= UART_LCR_SBC;
@@ -630,13 +450,11 @@ static void serial_omap_break_ctl(struct uart_port *port, int break_state)
630 up->lcr &= ~UART_LCR_SBC; 450 up->lcr &= ~UART_LCR_SBC;
631 serial_out(up, UART_LCR, up->lcr); 451 serial_out(up, UART_LCR, up->lcr);
632 spin_unlock_irqrestore(&up->port.lock, flags); 452 spin_unlock_irqrestore(&up->port.lock, flags);
633 pm_runtime_mark_last_busy(up->dev);
634 pm_runtime_put_autosuspend(up->dev);
635} 453}
636 454
637static int serial_omap_startup(struct uart_port *port) 455static int serial_omap_startup(struct uart_port *port)
638{ 456{
639 struct uart_omap_port *up = to_uart_omap_port(port); 457 struct uart_omap_port *up = (struct uart_omap_port *)port;
640 unsigned long flags = 0; 458 unsigned long flags = 0;
641 int retval; 459 int retval;
642 460
@@ -648,9 +466,8 @@ static int serial_omap_startup(struct uart_port *port)
648 if (retval) 466 if (retval)
649 return retval; 467 return retval;
650 468
651 dev_dbg(up->port.dev, "serial_omap_startup+%d\n", up->port.line); 469 dev_dbg(up->port.dev, "serial_omap_startup+%d\n", up->pdev->id);
652 470
653 pm_runtime_get_sync(up->dev);
654 /* 471 /*
655 * Clear the FIFO buffers and disable them. 472 * Clear the FIFO buffers and disable them.
656 * (they will be reenabled in set_termios()) 473 * (they will be reenabled in set_termios())
@@ -681,6 +498,20 @@ static int serial_omap_startup(struct uart_port *port)
681 spin_unlock_irqrestore(&up->port.lock, flags); 498 spin_unlock_irqrestore(&up->port.lock, flags);
682 499
683 up->msr_saved_flags = 0; 500 up->msr_saved_flags = 0;
501 if (up->use_dma) {
502 free_page((unsigned long)up->port.state->xmit.buf);
503 up->port.state->xmit.buf = dma_alloc_coherent(NULL,
504 UART_XMIT_SIZE,
505 (dma_addr_t *)&(up->uart_dma.tx_buf_dma_phys),
506 0);
507 init_timer(&(up->uart_dma.rx_timer));
508 up->uart_dma.rx_timer.function = serial_omap_rx_timeout;
509 up->uart_dma.rx_timer.data = up->pdev->id;
510 /* Currently the buffer size is 4KB. Can increase it */
511 up->uart_dma.rx_buf = dma_alloc_coherent(NULL,
512 up->uart_dma.rx_buf_size,
513 (dma_addr_t *)&(up->uart_dma.rx_buf_dma_phys), 0);
514 }
684 /* 515 /*
685 * Finally, enable interrupts. Note: Modem status interrupts 516 * Finally, enable interrupts. Note: Modem status interrupts
686 * are set via set_termios(), which will be occurring imminently 517 * are set via set_termios(), which will be occurring imminently
@@ -692,20 +523,16 @@ static int serial_omap_startup(struct uart_port *port)
692 /* Enable module level wake up */ 523 /* Enable module level wake up */
693 serial_out(up, UART_OMAP_WER, OMAP_UART_WER_MOD_WKUP); 524 serial_out(up, UART_OMAP_WER, OMAP_UART_WER_MOD_WKUP);
694 525
695 pm_runtime_mark_last_busy(up->dev);
696 pm_runtime_put_autosuspend(up->dev);
697 up->port_activity = jiffies; 526 up->port_activity = jiffies;
698 return 0; 527 return 0;
699} 528}
700 529
701static void serial_omap_shutdown(struct uart_port *port) 530static void serial_omap_shutdown(struct uart_port *port)
702{ 531{
703 struct uart_omap_port *up = to_uart_omap_port(port); 532 struct uart_omap_port *up = (struct uart_omap_port *)port;
704 unsigned long flags = 0; 533 unsigned long flags = 0;
705 534
706 dev_dbg(up->port.dev, "serial_omap_shutdown+%d\n", up->port.line); 535 dev_dbg(up->port.dev, "serial_omap_shutdown+%d\n", up->pdev->id);
707
708 pm_runtime_get_sync(up->dev);
709 /* 536 /*
710 * Disable interrupts from this port 537 * Disable interrupts from this port
711 */ 538 */
@@ -728,29 +555,89 @@ static void serial_omap_shutdown(struct uart_port *port)
728 */ 555 */
729 if (serial_in(up, UART_LSR) & UART_LSR_DR) 556 if (serial_in(up, UART_LSR) & UART_LSR_DR)
730 (void) serial_in(up, UART_RX); 557 (void) serial_in(up, UART_RX);
731 558 if (up->use_dma) {
732 pm_runtime_mark_last_busy(up->dev); 559 dma_free_coherent(up->port.dev,
733 pm_runtime_put_autosuspend(up->dev); 560 UART_XMIT_SIZE, up->port.state->xmit.buf,
561 up->uart_dma.tx_buf_dma_phys);
562 up->port.state->xmit.buf = NULL;
563 serial_omap_stop_rx(port);
564 dma_free_coherent(up->port.dev,
565 up->uart_dma.rx_buf_size, up->uart_dma.rx_buf,
566 up->uart_dma.rx_buf_dma_phys);
567 up->uart_dma.rx_buf = NULL;
568 }
734 free_irq(up->port.irq, up); 569 free_irq(up->port.irq, up);
735} 570}
736 571
737static void serial_omap_uart_qos_work(struct work_struct *work) 572static inline void
573serial_omap_configure_xonxoff
574 (struct uart_omap_port *up, struct ktermios *termios)
738{ 575{
739 struct uart_omap_port *up = container_of(work, struct uart_omap_port, 576 unsigned char efr = 0;
740 qos_work); 577
578 up->lcr = serial_in(up, UART_LCR);
579 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
580 up->efr = serial_in(up, UART_EFR);
581 serial_out(up, UART_EFR, up->efr & ~UART_EFR_ECB);
582
583 serial_out(up, UART_XON1, termios->c_cc[VSTART]);
584 serial_out(up, UART_XOFF1, termios->c_cc[VSTOP]);
585
586 /* clear SW control mode bits */
587 efr = up->efr;
588 efr &= OMAP_UART_SW_CLR;
589
590 /*
591 * IXON Flag:
592 * Enable XON/XOFF flow control on output.
593 * Transmit XON1, XOFF1
594 */
595 if (termios->c_iflag & IXON)
596 efr |= OMAP_UART_SW_TX;
597
598 /*
599 * IXOFF Flag:
600 * Enable XON/XOFF flow control on input.
601 * Receiver compares XON1, XOFF1.
602 */
603 if (termios->c_iflag & IXOFF)
604 efr |= OMAP_UART_SW_RX;
605
606 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
607 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
608
609 up->mcr = serial_in(up, UART_MCR);
610
611 /*
612 * IXANY Flag:
613 * Enable any character to restart output.
614 * Operation resumes after receiving any
615 * character after recognition of the XOFF character
616 */
617 if (termios->c_iflag & IXANY)
618 up->mcr |= UART_MCR_XONANY;
619
620 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR);
621 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
622 serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG);
623 /* Enable special char function UARTi.EFR_REG[5] and
624 * load the new software flow control mode IXON or IXOFF
625 * and restore the UARTi.EFR_REG[4] ENHANCED_EN value.
626 */
627 serial_out(up, UART_EFR, efr | UART_EFR_SCD);
628 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
741 629
742 pm_qos_update_request(&up->pm_qos_request, up->latency); 630 serial_out(up, UART_MCR, up->mcr & ~UART_MCR_TCRTLR);
743 if (gpio_is_valid(up->DTR_gpio)) 631 serial_out(up, UART_LCR, up->lcr);
744 gpio_set_value_cansleep(up->DTR_gpio,
745 up->DTR_active != up->DTR_inverted);
746} 632}
747 633
748static void 634static void
749serial_omap_set_termios(struct uart_port *port, struct ktermios *termios, 635serial_omap_set_termios(struct uart_port *port, struct ktermios *termios,
750 struct ktermios *old) 636 struct ktermios *old)
751{ 637{
752 struct uart_omap_port *up = to_uart_omap_port(port); 638 struct uart_omap_port *up = (struct uart_omap_port *)port;
753 unsigned char cval = 0; 639 unsigned char cval = 0;
640 unsigned char efr = 0;
754 unsigned long flags = 0; 641 unsigned long flags = 0;
755 unsigned int baud, quot; 642 unsigned int baud, quot;
756 643
@@ -784,23 +671,15 @@ serial_omap_set_termios(struct uart_port *port, struct ktermios *termios,
784 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/13); 671 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/13);
785 quot = serial_omap_get_divisor(port, baud); 672 quot = serial_omap_get_divisor(port, baud);
786 673
787 /* calculate wakeup latency constraint */
788 up->calc_latency = (USEC_PER_SEC * up->port.fifosize) / (baud / 8);
789 up->latency = up->calc_latency;
790 schedule_work(&up->qos_work);
791
792 up->dll = quot & 0xff;
793 up->dlh = quot >> 8;
794 up->mdr1 = UART_OMAP_MDR1_DISABLE;
795
796 up->fcr = UART_FCR_R_TRIG_01 | UART_FCR_T_TRIG_01 | 674 up->fcr = UART_FCR_R_TRIG_01 | UART_FCR_T_TRIG_01 |
797 UART_FCR_ENABLE_FIFO; 675 UART_FCR_ENABLE_FIFO;
676 if (up->use_dma)
677 up->fcr |= UART_FCR_DMA_SELECT;
798 678
799 /* 679 /*
800 * Ok, we're now changing the port state. Do it with 680 * Ok, we're now changing the port state. Do it with
801 * interrupts disabled. 681 * interrupts disabled.
802 */ 682 */
803 pm_runtime_get_sync(up->dev);
804 spin_lock_irqsave(&up->port.lock, flags); 683 spin_lock_irqsave(&up->port.lock, flags);
805 684
806 /* 685 /*
@@ -844,8 +723,6 @@ serial_omap_set_termios(struct uart_port *port, struct ktermios *termios,
844 up->ier |= UART_IER_MSI; 723 up->ier |= UART_IER_MSI;
845 serial_out(up, UART_IER, up->ier); 724 serial_out(up, UART_IER, up->ier);
846 serial_out(up, UART_LCR, cval); /* reset DLAB */ 725 serial_out(up, UART_LCR, cval); /* reset DLAB */
847 up->lcr = cval;
848 up->scr = OMAP_UART_SCR_TX_EMPTY;
849 726
850 /* FIFOs and DMA Settings */ 727 /* FIFOs and DMA Settings */
851 728
@@ -860,53 +737,40 @@ serial_omap_set_termios(struct uart_port *port, struct ktermios *termios,
860 737
861 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 738 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
862 739
863 up->efr = serial_in(up, UART_EFR) & ~UART_EFR_ECB; 740 up->efr = serial_in(up, UART_EFR);
864 up->efr &= ~UART_EFR_SCD;
865 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); 741 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
866 742
867 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 743 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
868 up->mcr = serial_in(up, UART_MCR) & ~UART_MCR_TCRTLR; 744 up->mcr = serial_in(up, UART_MCR);
869 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR); 745 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR);
870 /* FIFO ENABLE, DMA MODE */ 746 /* FIFO ENABLE, DMA MODE */
871
872 up->scr |= OMAP_UART_SCR_RX_TRIG_GRANU1_MASK;
873
874 /* Set receive FIFO threshold to 16 characters and
875 * transmit FIFO threshold to 16 spaces
876 */
877 up->fcr &= ~OMAP_UART_FCR_RX_FIFO_TRIG_MASK;
878 up->fcr &= ~OMAP_UART_FCR_TX_FIFO_TRIG_MASK;
879 up->fcr |= UART_FCR6_R_TRIGGER_16 | UART_FCR6_T_TRIGGER_24 |
880 UART_FCR_ENABLE_FIFO;
881
882 serial_out(up, UART_FCR, up->fcr); 747 serial_out(up, UART_FCR, up->fcr);
883 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 748 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
884 749
885 serial_out(up, UART_OMAP_SCR, up->scr); 750 if (up->use_dma) {
751 serial_out(up, UART_TI752_TLR, 0);
752 serial_out(up, UART_OMAP_SCR,
753 (UART_FCR_TRIGGER_4 | UART_FCR_TRIGGER_8));
754 }
886 755
887 /* Reset UART_MCR_TCRTLR: this must be done with the EFR_ECB bit set */
888 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
889 serial_out(up, UART_MCR, up->mcr);
890 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
891 serial_out(up, UART_EFR, up->efr); 756 serial_out(up, UART_EFR, up->efr);
892 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 757 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
758 serial_out(up, UART_MCR, up->mcr);
893 759
894 /* Protocol, Baud Rate, and Interrupt Settings */ 760 /* Protocol, Baud Rate, and Interrupt Settings */
895 761
896 if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) 762 serial_out(up, UART_OMAP_MDR1, UART_OMAP_MDR1_DISABLE);
897 serial_omap_mdr1_errataset(up, up->mdr1);
898 else
899 serial_out(up, UART_OMAP_MDR1, up->mdr1);
900
901 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 763 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
764
765 up->efr = serial_in(up, UART_EFR);
902 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB); 766 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
903 767
904 serial_out(up, UART_LCR, 0); 768 serial_out(up, UART_LCR, 0);
905 serial_out(up, UART_IER, 0); 769 serial_out(up, UART_IER, 0);
906 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 770 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
907 771
908 serial_out(up, UART_DLL, up->dll); /* LS of divisor */ 772 serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */
909 serial_out(up, UART_DLM, up->dlh); /* MS of divisor */ 773 serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */
910 774
911 serial_out(up, UART_LCR, 0); 775 serial_out(up, UART_LCR, 0);
912 serial_out(up, UART_IER, up->ier); 776 serial_out(up, UART_IER, up->ier);
@@ -916,103 +780,46 @@ serial_omap_set_termios(struct uart_port *port, struct ktermios *termios,
916 serial_out(up, UART_LCR, cval); 780 serial_out(up, UART_LCR, cval);
917 781
918 if (baud > 230400 && baud != 3000000) 782 if (baud > 230400 && baud != 3000000)
919 up->mdr1 = UART_OMAP_MDR1_13X_MODE; 783 serial_out(up, UART_OMAP_MDR1, UART_OMAP_MDR1_13X_MODE);
920 else 784 else
921 up->mdr1 = UART_OMAP_MDR1_16X_MODE; 785 serial_out(up, UART_OMAP_MDR1, UART_OMAP_MDR1_16X_MODE);
922 786
923 if (up->errata & UART_ERRATA_i202_MDR1_ACCESS) 787 /* Hardware Flow Control Configuration */
924 serial_omap_mdr1_errataset(up, up->mdr1);
925 else
926 serial_out(up, UART_OMAP_MDR1, up->mdr1);
927 788
928 /* Configure flow control */ 789 if (termios->c_cflag & CRTSCTS) {
929 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 790 efr |= (UART_EFR_CTS | UART_EFR_RTS);
791 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
930 792
931 /* XON1/XOFF1 accessible mode B, TCRTLR=0, ECB=0 */ 793 up->mcr = serial_in(up, UART_MCR);
932 serial_out(up, UART_XON1, termios->c_cc[VSTART]); 794 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR);
933 serial_out(up, UART_XOFF1, termios->c_cc[VSTOP]);
934
935 /* Enable access to TCR/TLR */
936 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
937 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
938 serial_out(up, UART_MCR, up->mcr | UART_MCR_TCRTLR);
939 795
940 serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG); 796 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
941 797 up->efr = serial_in(up, UART_EFR);
942 if (termios->c_cflag & CRTSCTS && up->port.flags & UPF_HARD_FLOW) { 798 serial_out(up, UART_EFR, up->efr | UART_EFR_ECB);
943 /* Enable AUTORTS and AUTOCTS */
944 up->efr |= UART_EFR_CTS | UART_EFR_RTS;
945 799
946 /* Ensure MCR RTS is asserted */ 800 serial_out(up, UART_TI752_TCR, OMAP_UART_TCR_TRIG);
947 up->mcr |= UART_MCR_RTS; 801 serial_out(up, UART_EFR, efr); /* Enable AUTORTS and AUTOCTS */
948 } else { 802 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
949 /* Disable AUTORTS and AUTOCTS */ 803 serial_out(up, UART_MCR, up->mcr | UART_MCR_RTS);
950 up->efr &= ~(UART_EFR_CTS | UART_EFR_RTS); 804 serial_out(up, UART_LCR, cval);
951 } 805 }
952 806
953 if (up->port.flags & UPF_SOFT_FLOW) {
954 /* clear SW control mode bits */
955 up->efr &= OMAP_UART_SW_CLR;
956
957 /*
958 * IXON Flag:
959 * Enable XON/XOFF flow control on input.
960 * Receiver compares XON1, XOFF1.
961 */
962 if (termios->c_iflag & IXON)
963 up->efr |= OMAP_UART_SW_RX;
964
965 /*
966 * IXOFF Flag:
967 * Enable XON/XOFF flow control on output.
968 * Transmit XON1, XOFF1
969 */
970 if (termios->c_iflag & IXOFF)
971 up->efr |= OMAP_UART_SW_TX;
972
973 /*
974 * IXANY Flag:
975 * Enable any character to restart output.
976 * Operation resumes after receiving any
977 * character after recognition of the XOFF character
978 */
979 if (termios->c_iflag & IXANY)
980 up->mcr |= UART_MCR_XONANY;
981 else
982 up->mcr &= ~UART_MCR_XONANY;
983 }
984 serial_out(up, UART_MCR, up->mcr);
985 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
986 serial_out(up, UART_EFR, up->efr);
987 serial_out(up, UART_LCR, up->lcr);
988
989 serial_omap_set_mctrl(&up->port, up->port.mctrl); 807 serial_omap_set_mctrl(&up->port, up->port.mctrl);
808 /* Software Flow Control Configuration */
809 serial_omap_configure_xonxoff(up, termios);
990 810
991 spin_unlock_irqrestore(&up->port.lock, flags); 811 spin_unlock_irqrestore(&up->port.lock, flags);
992 pm_runtime_mark_last_busy(up->dev); 812 dev_dbg(up->port.dev, "serial_omap_set_termios+%d\n", up->pdev->id);
993 pm_runtime_put_autosuspend(up->dev);
994 dev_dbg(up->port.dev, "serial_omap_set_termios+%d\n", up->port.line);
995}
996
997static int serial_omap_set_wake(struct uart_port *port, unsigned int state)
998{
999 struct uart_omap_port *up = to_uart_omap_port(port);
1000
1001 serial_omap_enable_wakeup(up, state);
1002
1003 return 0;
1004} 813}
1005 814
1006static void 815static void
1007serial_omap_pm(struct uart_port *port, unsigned int state, 816serial_omap_pm(struct uart_port *port, unsigned int state,
1008 unsigned int oldstate) 817 unsigned int oldstate)
1009{ 818{
1010 struct uart_omap_port *up = to_uart_omap_port(port); 819 struct uart_omap_port *up = (struct uart_omap_port *)port;
1011 unsigned char efr; 820 unsigned char efr;
1012 821
1013 dev_dbg(up->port.dev, "serial_omap_pm+%d\n", up->port.line); 822 dev_dbg(up->port.dev, "serial_omap_pm+%d\n", up->pdev->id);
1014
1015 pm_runtime_get_sync(up->dev);
1016 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 823 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
1017 efr = serial_in(up, UART_EFR); 824 efr = serial_in(up, UART_EFR);
1018 serial_out(up, UART_EFR, efr | UART_EFR_ECB); 825 serial_out(up, UART_EFR, efr | UART_EFR_ECB);
@@ -1022,16 +829,6 @@ serial_omap_pm(struct uart_port *port, unsigned int state,
1022 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 829 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
1023 serial_out(up, UART_EFR, efr); 830 serial_out(up, UART_EFR, efr);
1024 serial_out(up, UART_LCR, 0); 831 serial_out(up, UART_LCR, 0);
1025
1026 if (!device_may_wakeup(up->dev)) {
1027 if (!state)
1028 pm_runtime_forbid(up->dev);
1029 else
1030 pm_runtime_allow(up->dev);
1031 }
1032
1033 pm_runtime_mark_last_busy(up->dev);
1034 pm_runtime_put_autosuspend(up->dev);
1035} 832}
1036 833
1037static void serial_omap_release_port(struct uart_port *port) 834static void serial_omap_release_port(struct uart_port *port)
@@ -1047,12 +844,11 @@ static int serial_omap_request_port(struct uart_port *port)
1047 844
1048static void serial_omap_config_port(struct uart_port *port, int flags) 845static void serial_omap_config_port(struct uart_port *port, int flags)
1049{ 846{
1050 struct uart_omap_port *up = to_uart_omap_port(port); 847 struct uart_omap_port *up = (struct uart_omap_port *)port;
1051 848
1052 dev_dbg(up->port.dev, "serial_omap_config_port+%d\n", 849 dev_dbg(up->port.dev, "serial_omap_config_port+%d\n",
1053 up->port.line); 850 up->pdev->id);
1054 up->port.type = PORT_OMAP; 851 up->port.type = PORT_OMAP;
1055 up->port.flags |= UPF_SOFT_FLOW | UPF_HARD_FLOW;
1056} 852}
1057 853
1058static int 854static int
@@ -1066,9 +862,9 @@ serial_omap_verify_port(struct uart_port *port, struct serial_struct *ser)
1066static const char * 862static const char *
1067serial_omap_type(struct uart_port *port) 863serial_omap_type(struct uart_port *port)
1068{ 864{
1069 struct uart_omap_port *up = to_uart_omap_port(port); 865 struct uart_omap_port *up = (struct uart_omap_port *)port;
1070 866
1071 dev_dbg(up->port.dev, "serial_omap_type+%d\n", up->port.line); 867 dev_dbg(up->port.dev, "serial_omap_type+%d\n", up->pdev->id);
1072 return up->name; 868 return up->name;
1073} 869}
1074 870
@@ -1109,47 +905,33 @@ static inline void wait_for_xmitr(struct uart_omap_port *up)
1109 905
1110static void serial_omap_poll_put_char(struct uart_port *port, unsigned char ch) 906static void serial_omap_poll_put_char(struct uart_port *port, unsigned char ch)
1111{ 907{
1112 struct uart_omap_port *up = to_uart_omap_port(port); 908 struct uart_omap_port *up = (struct uart_omap_port *)port;
1113
1114 pm_runtime_get_sync(up->dev);
1115 wait_for_xmitr(up); 909 wait_for_xmitr(up);
1116 serial_out(up, UART_TX, ch); 910 serial_out(up, UART_TX, ch);
1117 pm_runtime_mark_last_busy(up->dev);
1118 pm_runtime_put_autosuspend(up->dev);
1119} 911}
1120 912
1121static int serial_omap_poll_get_char(struct uart_port *port) 913static int serial_omap_poll_get_char(struct uart_port *port)
1122{ 914{
1123 struct uart_omap_port *up = to_uart_omap_port(port); 915 struct uart_omap_port *up = (struct uart_omap_port *)port;
1124 unsigned int status; 916 unsigned int status = serial_in(up, UART_LSR);
1125
1126 pm_runtime_get_sync(up->dev);
1127 status = serial_in(up, UART_LSR);
1128 if (!(status & UART_LSR_DR)) {
1129 status = NO_POLL_CHAR;
1130 goto out;
1131 }
1132 917
1133 status = serial_in(up, UART_RX); 918 if (!(status & UART_LSR_DR))
919 return NO_POLL_CHAR;
1134 920
1135out: 921 return serial_in(up, UART_RX);
1136 pm_runtime_mark_last_busy(up->dev);
1137 pm_runtime_put_autosuspend(up->dev);
1138
1139 return status;
1140} 922}
1141 923
1142#endif /* CONFIG_CONSOLE_POLL */ 924#endif /* CONFIG_CONSOLE_POLL */
1143 925
1144#ifdef CONFIG_SERIAL_OMAP_CONSOLE 926#ifdef CONFIG_SERIAL_OMAP_CONSOLE
1145 927
1146static struct uart_omap_port *serial_omap_console_ports[OMAP_MAX_HSUART_PORTS]; 928static struct uart_omap_port *serial_omap_console_ports[4];
1147 929
1148static struct uart_driver serial_omap_reg; 930static struct uart_driver serial_omap_reg;
1149 931
1150static void serial_omap_console_putchar(struct uart_port *port, int ch) 932static void serial_omap_console_putchar(struct uart_port *port, int ch)
1151{ 933{
1152 struct uart_omap_port *up = to_uart_omap_port(port); 934 struct uart_omap_port *up = (struct uart_omap_port *)port;
1153 935
1154 wait_for_xmitr(up); 936 wait_for_xmitr(up);
1155 serial_out(up, UART_TX, ch); 937 serial_out(up, UART_TX, ch);
@@ -1164,8 +946,6 @@ serial_omap_console_write(struct console *co, const char *s,
1164 unsigned int ier; 946 unsigned int ier;
1165 int locked = 1; 947 int locked = 1;
1166 948
1167 pm_runtime_get_sync(up->dev);
1168
1169 local_irq_save(flags); 949 local_irq_save(flags);
1170 if (up->port.sysrq) 950 if (up->port.sysrq)
1171 locked = 0; 951 locked = 0;
@@ -1198,8 +978,6 @@ serial_omap_console_write(struct console *co, const char *s,
1198 if (up->msr_saved_flags) 978 if (up->msr_saved_flags)
1199 check_modem_status(up); 979 check_modem_status(up);
1200 980
1201 pm_runtime_mark_last_busy(up->dev);
1202 pm_runtime_put_autosuspend(up->dev);
1203 if (locked) 981 if (locked)
1204 spin_unlock(&up->port.lock); 982 spin_unlock(&up->port.lock);
1205 local_irq_restore(flags); 983 local_irq_restore(flags);
@@ -1236,7 +1014,7 @@ static struct console serial_omap_console = {
1236 1014
1237static void serial_omap_add_console_port(struct uart_omap_port *up) 1015static void serial_omap_add_console_port(struct uart_omap_port *up)
1238{ 1016{
1239 serial_omap_console_ports[up->port.line] = up; 1017 serial_omap_console_ports[up->pdev->id] = up;
1240} 1018}
1241 1019
1242#define OMAP_CONSOLE (&serial_omap_console) 1020#define OMAP_CONSOLE (&serial_omap_console)
@@ -1256,8 +1034,6 @@ static struct uart_ops serial_omap_pops = {
1256 .get_mctrl = serial_omap_get_mctrl, 1034 .get_mctrl = serial_omap_get_mctrl,
1257 .stop_tx = serial_omap_stop_tx, 1035 .stop_tx = serial_omap_stop_tx,
1258 .start_tx = serial_omap_start_tx, 1036 .start_tx = serial_omap_start_tx,
1259 .throttle = serial_omap_throttle,
1260 .unthrottle = serial_omap_unthrottle,
1261 .stop_rx = serial_omap_stop_rx, 1037 .stop_rx = serial_omap_stop_rx,
1262 .enable_ms = serial_omap_enable_ms, 1038 .enable_ms = serial_omap_enable_ms,
1263 .break_ctl = serial_omap_break_ctl, 1039 .break_ctl = serial_omap_break_ctl,
@@ -1265,7 +1041,6 @@ static struct uart_ops serial_omap_pops = {
1265 .shutdown = serial_omap_shutdown, 1041 .shutdown = serial_omap_shutdown,
1266 .set_termios = serial_omap_set_termios, 1042 .set_termios = serial_omap_set_termios,
1267 .pm = serial_omap_pm, 1043 .pm = serial_omap_pm,
1268 .set_wake = serial_omap_set_wake,
1269 .type = serial_omap_type, 1044 .type = serial_omap_type,
1270 .release_port = serial_omap_release_port, 1045 .release_port = serial_omap_release_port,
1271 .request_port = serial_omap_request_port, 1046 .request_port = serial_omap_request_port,
@@ -1285,102 +1060,173 @@ static struct uart_driver serial_omap_reg = {
1285 .cons = OMAP_CONSOLE, 1060 .cons = OMAP_CONSOLE,
1286}; 1061};
1287 1062
1288#ifdef CONFIG_PM_SLEEP 1063static int
1289static int serial_omap_suspend(struct device *dev) 1064serial_omap_suspend(struct platform_device *pdev, pm_message_t state)
1290{ 1065{
1291 struct uart_omap_port *up = dev_get_drvdata(dev); 1066 struct uart_omap_port *up = platform_get_drvdata(pdev);
1292
1293 uart_suspend_port(&serial_omap_reg, &up->port);
1294 flush_work(&up->qos_work);
1295 1067
1068 if (up)
1069 uart_suspend_port(&serial_omap_reg, &up->port);
1296 return 0; 1070 return 0;
1297} 1071}
1298 1072
1299static int serial_omap_resume(struct device *dev) 1073static int serial_omap_resume(struct platform_device *dev)
1300{ 1074{
1301 struct uart_omap_port *up = dev_get_drvdata(dev); 1075 struct uart_omap_port *up = platform_get_drvdata(dev);
1302
1303 uart_resume_port(&serial_omap_reg, &up->port);
1304 1076
1077 if (up)
1078 uart_resume_port(&serial_omap_reg, &up->port);
1305 return 0; 1079 return 0;
1306} 1080}
1307#endif
1308 1081
1309static void omap_serial_fill_features_erratas(struct uart_omap_port *up) 1082static void serial_omap_rx_timeout(unsigned long uart_no)
1310{ 1083{
1311 u32 mvr, scheme; 1084 struct uart_omap_port *up = ui[uart_no];
1312 u16 revision, major, minor; 1085 unsigned int curr_dma_pos, curr_transmitted_size;
1086 int ret = 0;
1087
1088 curr_dma_pos = omap_get_dma_dst_pos(up->uart_dma.rx_dma_channel);
1089 if ((curr_dma_pos == up->uart_dma.prev_rx_dma_pos) ||
1090 (curr_dma_pos == 0)) {
1091 if (jiffies_to_msecs(jiffies - up->port_activity) <
1092 RX_TIMEOUT) {
1093 mod_timer(&up->uart_dma.rx_timer, jiffies +
1094 usecs_to_jiffies(up->uart_dma.rx_timeout));
1095 } else {
1096 serial_omap_stop_rxdma(up);
1097 up->ier |= (UART_IER_RDI | UART_IER_RLSI);
1098 serial_out(up, UART_IER, up->ier);
1099 }
1100 return;
1101 }
1313 1102
1314 mvr = serial_in(up, UART_OMAP_MVER); 1103 curr_transmitted_size = curr_dma_pos -
1104 up->uart_dma.prev_rx_dma_pos;
1105 up->port.icount.rx += curr_transmitted_size;
1106 tty_insert_flip_string(up->port.state->port.tty,
1107 up->uart_dma.rx_buf +
1108 (up->uart_dma.prev_rx_dma_pos -
1109 up->uart_dma.rx_buf_dma_phys),
1110 curr_transmitted_size);
1111 tty_flip_buffer_push(up->port.state->port.tty);
1112 up->uart_dma.prev_rx_dma_pos = curr_dma_pos;
1113 if (up->uart_dma.rx_buf_size +
1114 up->uart_dma.rx_buf_dma_phys == curr_dma_pos) {
1115 ret = serial_omap_start_rxdma(up);
1116 if (ret < 0) {
1117 serial_omap_stop_rxdma(up);
1118 up->ier |= (UART_IER_RDI | UART_IER_RLSI);
1119 serial_out(up, UART_IER, up->ier);
1120 }
1121 } else {
1122 mod_timer(&up->uart_dma.rx_timer, jiffies +
1123 usecs_to_jiffies(up->uart_dma.rx_timeout));
1124 }
1125 up->port_activity = jiffies;
1126}
1315 1127
1316 /* Check revision register scheme */ 1128static void uart_rx_dma_callback(int lch, u16 ch_status, void *data)
1317 scheme = mvr >> OMAP_UART_MVR_SCHEME_SHIFT; 1129{
1130 return;
1131}
1318 1132
1319 switch (scheme) { 1133static int serial_omap_start_rxdma(struct uart_omap_port *up)
1320 case 0: /* Legacy Scheme: OMAP2/3 */ 1134{
1321 /* MINOR_REV[0:4], MAJOR_REV[4:7] */ 1135 int ret = 0;
1322 major = (mvr & OMAP_UART_LEGACY_MVR_MAJ_MASK) >>
1323 OMAP_UART_LEGACY_MVR_MAJ_SHIFT;
1324 minor = (mvr & OMAP_UART_LEGACY_MVR_MIN_MASK);
1325 break;
1326 case 1:
1327 /* New Scheme: OMAP4+ */
1328 /* MINOR_REV[0:5], MAJOR_REV[8:10] */
1329 major = (mvr & OMAP_UART_MVR_MAJ_MASK) >>
1330 OMAP_UART_MVR_MAJ_SHIFT;
1331 minor = (mvr & OMAP_UART_MVR_MIN_MASK);
1332 break;
1333 default:
1334 dev_warn(up->dev,
1335 "Unknown %s revision, defaulting to highest\n",
1336 up->name);
1337 /* highest possible revision */
1338 major = 0xff;
1339 minor = 0xff;
1340 }
1341 1136
1342 /* normalize revision for the driver */ 1137 if (up->uart_dma.rx_dma_channel == -1) {
1343 revision = UART_BUILD_REVISION(major, minor); 1138 ret = omap_request_dma(up->uart_dma.uart_dma_rx,
1139 "UART Rx DMA",
1140 (void *)uart_rx_dma_callback, up,
1141 &(up->uart_dma.rx_dma_channel));
1142 if (ret < 0)
1143 return ret;
1344 1144
1345 switch (revision) { 1145 omap_set_dma_src_params(up->uart_dma.rx_dma_channel, 0,
1346 case OMAP_UART_REV_46: 1146 OMAP_DMA_AMODE_CONSTANT,
1347 up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | 1147 up->uart_dma.uart_base, 0, 0);
1348 UART_ERRATA_i291_DMA_FORCEIDLE); 1148 omap_set_dma_dest_params(up->uart_dma.rx_dma_channel, 0,
1349 break; 1149 OMAP_DMA_AMODE_POST_INC,
1350 case OMAP_UART_REV_52: 1150 up->uart_dma.rx_buf_dma_phys, 0, 0);
1351 up->errata |= (UART_ERRATA_i202_MDR1_ACCESS | 1151 omap_set_dma_transfer_params(up->uart_dma.rx_dma_channel,
1352 UART_ERRATA_i291_DMA_FORCEIDLE); 1152 OMAP_DMA_DATA_TYPE_S8,
1353 break; 1153 up->uart_dma.rx_buf_size, 1,
1354 case OMAP_UART_REV_63: 1154 OMAP_DMA_SYNC_ELEMENT,
1355 up->errata |= UART_ERRATA_i202_MDR1_ACCESS; 1155 up->uart_dma.uart_dma_rx, 0);
1356 break;
1357 default:
1358 break;
1359 } 1156 }
1157 up->uart_dma.prev_rx_dma_pos = up->uart_dma.rx_buf_dma_phys;
1158 /* FIXME: Cache maintenance needed here? */
1159 omap_start_dma(up->uart_dma.rx_dma_channel);
1160 mod_timer(&up->uart_dma.rx_timer, jiffies +
1161 usecs_to_jiffies(up->uart_dma.rx_timeout));
1162 up->uart_dma.rx_dma_used = true;
1163 return ret;
1164}
1165
1166static void serial_omap_continue_tx(struct uart_omap_port *up)
1167{
1168 struct circ_buf *xmit = &up->port.state->xmit;
1169 unsigned int start = up->uart_dma.tx_buf_dma_phys
1170 + (xmit->tail & (UART_XMIT_SIZE - 1));
1171
1172 if (uart_circ_empty(xmit))
1173 return;
1174
1175 up->uart_dma.tx_buf_size = uart_circ_chars_pending(xmit);
1176 /*
1177 * It is a circular buffer. See if the buffer has wounded back.
1178 * If yes it will have to be transferred in two separate dma
1179 * transfers
1180 */
1181 if (start + up->uart_dma.tx_buf_size >=
1182 up->uart_dma.tx_buf_dma_phys + UART_XMIT_SIZE)
1183 up->uart_dma.tx_buf_size =
1184 (up->uart_dma.tx_buf_dma_phys + UART_XMIT_SIZE) - start;
1185 omap_set_dma_dest_params(up->uart_dma.tx_dma_channel, 0,
1186 OMAP_DMA_AMODE_CONSTANT,
1187 up->uart_dma.uart_base, 0, 0);
1188 omap_set_dma_src_params(up->uart_dma.tx_dma_channel, 0,
1189 OMAP_DMA_AMODE_POST_INC, start, 0, 0);
1190 omap_set_dma_transfer_params(up->uart_dma.tx_dma_channel,
1191 OMAP_DMA_DATA_TYPE_S8,
1192 up->uart_dma.tx_buf_size, 1,
1193 OMAP_DMA_SYNC_ELEMENT,
1194 up->uart_dma.uart_dma_tx, 0);
1195 /* FIXME: Cache maintenance needed here? */
1196 omap_start_dma(up->uart_dma.tx_dma_channel);
1360} 1197}
1361 1198
1362static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) 1199static void uart_tx_dma_callback(int lch, u16 ch_status, void *data)
1363{ 1200{
1364 struct omap_uart_port_info *omap_up_info; 1201 struct uart_omap_port *up = (struct uart_omap_port *)data;
1202 struct circ_buf *xmit = &up->port.state->xmit;
1365 1203
1366 omap_up_info = devm_kzalloc(dev, sizeof(*omap_up_info), GFP_KERNEL); 1204 xmit->tail = (xmit->tail + up->uart_dma.tx_buf_size) & \
1367 if (!omap_up_info) 1205 (UART_XMIT_SIZE - 1);
1368 return NULL; /* out of memory */ 1206 up->port.icount.tx += up->uart_dma.tx_buf_size;
1369 1207
1370 of_property_read_u32(dev->of_node, "clock-frequency", 1208 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
1371 &omap_up_info->uartclk); 1209 uart_write_wakeup(&up->port);
1372 return omap_up_info; 1210
1211 if (uart_circ_empty(xmit)) {
1212 spin_lock(&(up->uart_dma.tx_lock));
1213 serial_omap_stop_tx(&up->port);
1214 up->uart_dma.tx_dma_used = false;
1215 spin_unlock(&(up->uart_dma.tx_lock));
1216 } else {
1217 omap_stop_dma(up->uart_dma.tx_dma_channel);
1218 serial_omap_continue_tx(up);
1219 }
1220 up->port_activity = jiffies;
1221 return;
1373} 1222}
1374 1223
1375static int serial_omap_probe(struct platform_device *pdev) 1224static int serial_omap_probe(struct platform_device *pdev)
1376{ 1225{
1377 struct uart_omap_port *up; 1226 struct uart_omap_port *up;
1378 struct resource *mem, *irq; 1227 struct resource *mem, *irq, *dma_tx, *dma_rx;
1379 struct omap_uart_port_info *omap_up_info = pdev->dev.platform_data; 1228 struct omap_uart_port_info *omap_up_info = pdev->dev.platform_data;
1380 int ret; 1229 int ret = -ENOSPC;
1381
1382 if (pdev->dev.of_node)
1383 omap_up_info = of_get_uart_port_info(&pdev->dev);
1384 1230
1385 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1231 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1386 if (!mem) { 1232 if (!mem) {
@@ -1394,36 +1240,31 @@ static int serial_omap_probe(struct platform_device *pdev)
1394 return -ENODEV; 1240 return -ENODEV;
1395 } 1241 }
1396 1242
1397 if (!devm_request_mem_region(&pdev->dev, mem->start, resource_size(mem), 1243 if (!request_mem_region(mem->start, resource_size(mem),
1398 pdev->dev.driver->name)) { 1244 pdev->dev.driver->name)) {
1399 dev_err(&pdev->dev, "memory region already claimed\n"); 1245 dev_err(&pdev->dev, "memory region already claimed\n");
1400 return -EBUSY; 1246 return -EBUSY;
1401 } 1247 }
1402 1248
1403 if (gpio_is_valid(omap_up_info->DTR_gpio) && 1249 dma_rx = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1404 omap_up_info->DTR_present) { 1250 if (!dma_rx) {
1405 ret = gpio_request(omap_up_info->DTR_gpio, "omap-serial"); 1251 ret = -EINVAL;
1406 if (ret < 0) 1252 goto err;
1407 return ret;
1408 ret = gpio_direction_output(omap_up_info->DTR_gpio,
1409 omap_up_info->DTR_inverted);
1410 if (ret < 0)
1411 return ret;
1412 } 1253 }
1413 1254
1414 up = devm_kzalloc(&pdev->dev, sizeof(*up), GFP_KERNEL); 1255 dma_tx = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
1415 if (!up) 1256 if (!dma_tx) {
1416 return -ENOMEM; 1257 ret = -EINVAL;
1417 1258 goto err;
1418 if (gpio_is_valid(omap_up_info->DTR_gpio) && 1259 }
1419 omap_up_info->DTR_present) {
1420 up->DTR_gpio = omap_up_info->DTR_gpio;
1421 up->DTR_inverted = omap_up_info->DTR_inverted;
1422 } else
1423 up->DTR_gpio = -EINVAL;
1424 up->DTR_active = 0;
1425 1260
1426 up->dev = &pdev->dev; 1261 up = kzalloc(sizeof(*up), GFP_KERNEL);
1262 if (up == NULL) {
1263 ret = -ENOMEM;
1264 goto do_release_region;
1265 }
1266 sprintf(up->name, "OMAP UART%d", pdev->id);
1267 up->pdev = pdev;
1427 up->port.dev = &pdev->dev; 1268 up->port.dev = &pdev->dev;
1428 up->port.type = PORT_OMAP; 1269 up->port.type = PORT_OMAP;
1429 up->port.iotype = UPIO_MEM; 1270 up->port.iotype = UPIO_MEM;
@@ -1432,80 +1273,41 @@ static int serial_omap_probe(struct platform_device *pdev)
1432 up->port.regshift = 2; 1273 up->port.regshift = 2;
1433 up->port.fifosize = 64; 1274 up->port.fifosize = 64;
1434 up->port.ops = &serial_omap_pops; 1275 up->port.ops = &serial_omap_pops;
1276 up->port.line = pdev->id;
1435 1277
1436 if (pdev->dev.of_node) 1278 up->port.membase = omap_up_info->membase;
1437 up->port.line = of_alias_get_id(pdev->dev.of_node, "serial"); 1279 up->port.mapbase = omap_up_info->mapbase;
1438 else
1439 up->port.line = pdev->id;
1440
1441 if (up->port.line < 0) {
1442 dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n",
1443 up->port.line);
1444 ret = -ENODEV;
1445 goto err_port_line;
1446 }
1447
1448 up->pins = devm_pinctrl_get_select_default(&pdev->dev);
1449 if (IS_ERR(up->pins)) {
1450 dev_warn(&pdev->dev, "did not get pins for uart%i error: %li\n",
1451 up->port.line, PTR_ERR(up->pins));
1452 up->pins = NULL;
1453 }
1454
1455 sprintf(up->name, "OMAP UART%d", up->port.line);
1456 up->port.mapbase = mem->start;
1457 up->port.membase = devm_ioremap(&pdev->dev, mem->start,
1458 resource_size(mem));
1459 if (!up->port.membase) {
1460 dev_err(&pdev->dev, "can't ioremap UART\n");
1461 ret = -ENOMEM;
1462 goto err_ioremap;
1463 }
1464
1465 up->port.flags = omap_up_info->flags; 1280 up->port.flags = omap_up_info->flags;
1281 up->port.irqflags = omap_up_info->irqflags;
1466 up->port.uartclk = omap_up_info->uartclk; 1282 up->port.uartclk = omap_up_info->uartclk;
1467 if (!up->port.uartclk) { 1283 up->uart_dma.uart_base = mem->start;
1468 up->port.uartclk = DEFAULT_CLK_SPEED; 1284
1469 dev_warn(&pdev->dev, "No clock speed specified: using default:" 1285 if (omap_up_info->dma_enabled) {
1470 "%d\n", DEFAULT_CLK_SPEED); 1286 up->uart_dma.uart_dma_tx = dma_tx->start;
1287 up->uart_dma.uart_dma_rx = dma_rx->start;
1288 up->use_dma = 1;
1289 up->uart_dma.rx_buf_size = 4096;
1290 up->uart_dma.rx_timeout = 2;
1291 spin_lock_init(&(up->uart_dma.tx_lock));
1292 spin_lock_init(&(up->uart_dma.rx_lock));
1293 up->uart_dma.tx_dma_channel = OMAP_UART_DMA_CH_FREE;
1294 up->uart_dma.rx_dma_channel = OMAP_UART_DMA_CH_FREE;
1471 } 1295 }
1472 1296
1473 up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE; 1297 ui[pdev->id] = up;
1474 up->calc_latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
1475 pm_qos_add_request(&up->pm_qos_request,
1476 PM_QOS_CPU_DMA_LATENCY, up->latency);
1477 serial_omap_uart_wq = create_singlethread_workqueue(up->name);
1478 INIT_WORK(&up->qos_work, serial_omap_uart_qos_work);
1479
1480 platform_set_drvdata(pdev, up);
1481 pm_runtime_enable(&pdev->dev);
1482 pm_runtime_use_autosuspend(&pdev->dev);
1483 pm_runtime_set_autosuspend_delay(&pdev->dev,
1484 omap_up_info->autosuspend_timeout);
1485
1486 pm_runtime_irq_safe(&pdev->dev);
1487 pm_runtime_get_sync(&pdev->dev);
1488
1489 omap_serial_fill_features_erratas(up);
1490
1491 ui[up->port.line] = up;
1492 serial_omap_add_console_port(up); 1298 serial_omap_add_console_port(up);
1493 1299
1494 ret = uart_add_one_port(&serial_omap_reg, &up->port); 1300 ret = uart_add_one_port(&serial_omap_reg, &up->port);
1495 if (ret != 0) 1301 if (ret != 0)
1496 goto err_add_port; 1302 goto do_release_region;
1497 1303
1498 pm_runtime_mark_last_busy(up->dev); 1304 platform_set_drvdata(pdev, up);
1499 pm_runtime_put_autosuspend(up->dev);
1500 return 0; 1305 return 0;
1501 1306err:
1502err_add_port:
1503 pm_runtime_put(&pdev->dev);
1504 pm_runtime_disable(&pdev->dev);
1505err_ioremap:
1506err_port_line:
1507 dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n", 1307 dev_err(&pdev->dev, "[UART%d]: failure [%s]: %d\n",
1508 pdev->id, __func__, ret); 1308 pdev->id, __func__, ret);
1309do_release_region:
1310 release_mem_region(mem->start, resource_size(mem));
1509 return ret; 1311 return ret;
1510} 1312}
1511 1313
@@ -1513,152 +1315,22 @@ static int serial_omap_remove(struct platform_device *dev)
1513{ 1315{
1514 struct uart_omap_port *up = platform_get_drvdata(dev); 1316 struct uart_omap_port *up = platform_get_drvdata(dev);
1515 1317
1516 pm_runtime_put_sync(up->dev); 1318 platform_set_drvdata(dev, NULL);
1517 pm_runtime_disable(up->dev); 1319 if (up) {
1518 uart_remove_one_port(&serial_omap_reg, &up->port); 1320 uart_remove_one_port(&serial_omap_reg, &up->port);
1519 pm_qos_remove_request(&up->pm_qos_request); 1321 kfree(up);
1520
1521 return 0;
1522}
1523
1524/*
1525 * Work Around for Errata i202 (2430, 3430, 3630, 4430 and 4460)
1526 * The access to uart register after MDR1 Access
1527 * causes UART to corrupt data.
1528 *
1529 * Need a delay =
1530 * 5 L4 clock cycles + 5 UART functional clock cycle (@48MHz = ~0.2uS)
1531 * give 10 times as much
1532 */
1533static void serial_omap_mdr1_errataset(struct uart_omap_port *up, u8 mdr1)
1534{
1535 u8 timeout = 255;
1536
1537 serial_out(up, UART_OMAP_MDR1, mdr1);
1538 udelay(2);
1539 serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_XMIT |
1540 UART_FCR_CLEAR_RCVR);
1541 /*
1542 * Wait for FIFO to empty: when empty, RX_FIFO_E bit is 0 and
1543 * TX_FIFO_E bit is 1.
1544 */
1545 while (UART_LSR_THRE != (serial_in(up, UART_LSR) &
1546 (UART_LSR_THRE | UART_LSR_DR))) {
1547 timeout--;
1548 if (!timeout) {
1549 /* Should *never* happen. we warn and carry on */
1550 dev_crit(up->dev, "Errata i202: timedout %x\n",
1551 serial_in(up, UART_LSR));
1552 break;
1553 }
1554 udelay(1);
1555 } 1322 }
1556}
1557
1558#ifdef CONFIG_PM_RUNTIME
1559static void serial_omap_restore_context(struct uart_omap_port *up)
1560{
1561 if (up->errata & UART_ERRATA_i202_MDR1_ACCESS)
1562 serial_omap_mdr1_errataset(up, UART_OMAP_MDR1_DISABLE);
1563 else
1564 serial_out(up, UART_OMAP_MDR1, UART_OMAP_MDR1_DISABLE);
1565
1566 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */
1567 serial_out(up, UART_EFR, UART_EFR_ECB);
1568 serial_out(up, UART_LCR, 0x0); /* Operational mode */
1569 serial_out(up, UART_IER, 0x0);
1570 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */
1571 serial_out(up, UART_DLL, up->dll);
1572 serial_out(up, UART_DLM, up->dlh);
1573 serial_out(up, UART_LCR, 0x0); /* Operational mode */
1574 serial_out(up, UART_IER, up->ier);
1575 serial_out(up, UART_FCR, up->fcr);
1576 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A);
1577 serial_out(up, UART_MCR, up->mcr);
1578 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); /* Config B mode */
1579 serial_out(up, UART_OMAP_SCR, up->scr);
1580 serial_out(up, UART_EFR, up->efr);
1581 serial_out(up, UART_LCR, up->lcr);
1582 if (up->errata & UART_ERRATA_i202_MDR1_ACCESS)
1583 serial_omap_mdr1_errataset(up, up->mdr1);
1584 else
1585 serial_out(up, UART_OMAP_MDR1, up->mdr1);
1586}
1587
1588static int serial_omap_runtime_suspend(struct device *dev)
1589{
1590 struct uart_omap_port *up = dev_get_drvdata(dev);
1591 struct omap_uart_port_info *pdata = dev->platform_data;
1592
1593 if (!up)
1594 return -EINVAL;
1595
1596 if (!pdata)
1597 return 0;
1598
1599 up->context_loss_cnt = serial_omap_get_context_loss_count(up);
1600
1601 if (device_may_wakeup(dev)) {
1602 if (!up->wakeups_enabled) {
1603 serial_omap_enable_wakeup(up, true);
1604 up->wakeups_enabled = true;
1605 }
1606 } else {
1607 if (up->wakeups_enabled) {
1608 serial_omap_enable_wakeup(up, false);
1609 up->wakeups_enabled = false;
1610 }
1611 }
1612
1613 up->latency = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE;
1614 schedule_work(&up->qos_work);
1615
1616 return 0; 1323 return 0;
1617} 1324}
1618 1325
1619static int serial_omap_runtime_resume(struct device *dev)
1620{
1621 struct uart_omap_port *up = dev_get_drvdata(dev);
1622
1623 int loss_cnt = serial_omap_get_context_loss_count(up);
1624
1625 if (loss_cnt < 0) {
1626 dev_err(dev, "serial_omap_get_context_loss_count failed : %d\n",
1627 loss_cnt);
1628 serial_omap_restore_context(up);
1629 } else if (up->context_loss_cnt != loss_cnt) {
1630 serial_omap_restore_context(up);
1631 }
1632 up->latency = up->calc_latency;
1633 schedule_work(&up->qos_work);
1634
1635 return 0;
1636}
1637#endif
1638
1639static const struct dev_pm_ops serial_omap_dev_pm_ops = {
1640 SET_SYSTEM_SLEEP_PM_OPS(serial_omap_suspend, serial_omap_resume)
1641 SET_RUNTIME_PM_OPS(serial_omap_runtime_suspend,
1642 serial_omap_runtime_resume, NULL)
1643};
1644
1645#if defined(CONFIG_OF)
1646static const struct of_device_id omap_serial_of_match[] = {
1647 { .compatible = "ti,omap2-uart" },
1648 { .compatible = "ti,omap3-uart" },
1649 { .compatible = "ti,omap4-uart" },
1650 {},
1651};
1652MODULE_DEVICE_TABLE(of, omap_serial_of_match);
1653#endif
1654
1655static struct platform_driver serial_omap_driver = { 1326static struct platform_driver serial_omap_driver = {
1656 .probe = serial_omap_probe, 1327 .probe = serial_omap_probe,
1657 .remove = serial_omap_remove, 1328 .remove = serial_omap_remove,
1329
1330 .suspend = serial_omap_suspend,
1331 .resume = serial_omap_resume,
1658 .driver = { 1332 .driver = {
1659 .name = DRIVER_NAME, 1333 .name = DRIVER_NAME,
1660 .pm = &serial_omap_dev_pm_ops,
1661 .of_match_table = of_match_ptr(omap_serial_of_match),
1662 }, 1334 },
1663}; 1335};
1664 1336
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index 8318925fbf6..f913ed054c1 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -1,5 +1,5 @@
1/* 1/*
2 *Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. 2 *Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD.
3 * 3 *
4 *This program is free software; you can redistribute it and/or modify 4 *This program is free software; you can redistribute it and/or modify
5 *it under the terms of the GNU General Public License as published by 5 *it under the terms of the GNU General Public License as published by
@@ -20,16 +20,10 @@
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>
25#include <linux/interrupt.h> 23#include <linux/interrupt.h>
26#include <linux/io.h> 24#include <linux/io.h>
27#include <linux/dmi.h> 25#include <linux/dmi.h>
28#include <linux/console.h>
29#include <linux/nmi.h>
30#include <linux/delay.h>
31 26
32#include <linux/debugfs.h>
33#include <linux/dmaengine.h> 27#include <linux/dmaengine.h>
34#include <linux/pch_dma.h> 28#include <linux/pch_dma.h>
35 29
@@ -39,7 +33,6 @@ enum {
39 PCH_UART_HANDLED_RX_ERR_INT_SHIFT, 33 PCH_UART_HANDLED_RX_ERR_INT_SHIFT,
40 PCH_UART_HANDLED_RX_TRG_INT_SHIFT, 34 PCH_UART_HANDLED_RX_TRG_INT_SHIFT,
41 PCH_UART_HANDLED_MS_INT_SHIFT, 35 PCH_UART_HANDLED_MS_INT_SHIFT,
42 PCH_UART_HANDLED_LS_INT_SHIFT,
43}; 36};
44 37
45enum { 38enum {
@@ -51,8 +44,8 @@ enum {
51 44
52/* Set the max number of UART port 45/* Set the max number of UART port
53 * Intel EG20T PCH: 4 port 46 * Intel EG20T PCH: 4 port
54 * LAPIS Semiconductor ML7213 IOH: 3 port 47 * OKI SEMICONDUCTOR ML7213 IOH: 3 port
55 * LAPIS Semiconductor ML7223 IOH: 2 port 48 * OKI SEMICONDUCTOR ML7223 IOH: 2 port
56*/ 49*/
57#define PCH_UART_NR 4 50#define PCH_UART_NR 4
58 51
@@ -64,8 +57,6 @@ enum {
64 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1)) 57 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1))
65#define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1)) 58#define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1))
66 59
67#define PCH_UART_HANDLED_LS_INT (1<<((PCH_UART_HANDLED_LS_INT_SHIFT)<<1))
68
69#define PCH_UART_RBR 0x00 60#define PCH_UART_RBR 0x00
70#define PCH_UART_THR 0x00 61#define PCH_UART_THR 0x00
71 62
@@ -148,8 +139,6 @@ enum {
148#define PCH_UART_DLL 0x00 139#define PCH_UART_DLL 0x00
149#define PCH_UART_DLM 0x01 140#define PCH_UART_DLM 0x01
150 141
151#define PCH_UART_BRCSR 0x0E
152
153#define PCH_UART_IID_RLS (PCH_UART_IIR_REI) 142#define PCH_UART_IID_RLS (PCH_UART_IIR_REI)
154#define PCH_UART_IID_RDR (PCH_UART_IIR_RRI) 143#define PCH_UART_IID_RDR (PCH_UART_IIR_RRI)
155#define PCH_UART_IID_RDR_TO (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI) 144#define PCH_UART_IID_RDR_TO (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI)
@@ -207,14 +196,6 @@ enum {
207 196
208#define PCI_VENDOR_ID_ROHM 0x10DB 197#define PCI_VENDOR_ID_ROHM 0x10DB
209 198
210#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
211
212#define DEFAULT_UARTCLK 1843200 /* 1.8432 MHz */
213#define CMITC_UARTCLK 192000000 /* 192.0000 MHz */
214#define FRI2_64_UARTCLK 64000000 /* 64.0000 MHz */
215#define FRI2_48_UARTCLK 48000000 /* 48.0000 MHz */
216#define NTC1_UARTCLK 64000000 /* 64.0000 MHz */
217
218struct pch_uart_buffer { 199struct pch_uart_buffer {
219 unsigned char *buf; 200 unsigned char *buf;
220 int size; 201 int size;
@@ -228,10 +209,11 @@ struct eg20t_port {
228 unsigned int iobase; 209 unsigned int iobase;
229 struct pci_dev *pdev; 210 struct pci_dev *pdev;
230 int fifo_size; 211 int fifo_size;
231 int uartclk; 212 int base_baud;
232 int start_tx; 213 int start_tx;
233 int start_rx; 214 int start_rx;
234 int tx_empty; 215 int tx_empty;
216 int int_dis_flag;
235 int trigger; 217 int trigger;
236 int trigger_level; 218 int trigger_level;
237 struct pch_uart_buffer rxbuf; 219 struct pch_uart_buffer rxbuf;
@@ -239,6 +221,7 @@ struct eg20t_port {
239 unsigned int fcr; 221 unsigned int fcr;
240 unsigned int mcr; 222 unsigned int mcr;
241 unsigned int use_dma; 223 unsigned int use_dma;
224 unsigned int use_dma_flag;
242 struct dma_async_tx_descriptor *desc_tx; 225 struct dma_async_tx_descriptor *desc_tx;
243 struct dma_async_tx_descriptor *desc_rx; 226 struct dma_async_tx_descriptor *desc_rx;
244 struct pch_dma_slave param_tx; 227 struct pch_dma_slave param_tx;
@@ -251,11 +234,6 @@ struct eg20t_port {
251 int tx_dma_use; 234 int tx_dma_use;
252 void *rx_buf_virt; 235 void *rx_buf_virt;
253 dma_addr_t rx_buf_dma; 236 dma_addr_t rx_buf_dma;
254
255 struct dentry *debugfs;
256
257 /* protect the eg20t_port private structure and io access to membase */
258 spinlock_t lock;
259}; 237};
260 238
261/** 239/**
@@ -296,106 +274,27 @@ static struct pch_uart_driver_data drv_dat[] = {
296 [pch_ml7831_uart1] = {PCH_UART_2LINE, 1}, 274 [pch_ml7831_uart1] = {PCH_UART_2LINE, 1},
297}; 275};
298 276
299#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
300static struct eg20t_port *pch_uart_ports[PCH_UART_NR];
301#endif
302static unsigned int default_baud = 9600; 277static unsigned int default_baud = 9600;
303static unsigned int user_uartclk = 0;
304static const int trigger_level_256[4] = { 1, 64, 128, 224 }; 278static const int trigger_level_256[4] = { 1, 64, 128, 224 };
305static const int trigger_level_64[4] = { 1, 16, 32, 56 }; 279static const int trigger_level_64[4] = { 1, 16, 32, 56 };
306static const int trigger_level_16[4] = { 1, 4, 8, 14 }; 280static const int trigger_level_16[4] = { 1, 4, 8, 14 };
307static const int trigger_level_1[4] = { 1, 1, 1, 1 }; 281static const int trigger_level_1[4] = { 1, 1, 1, 1 };
308 282
309#ifdef CONFIG_DEBUG_FS 283static void pch_uart_hal_request(struct pci_dev *pdev, int fifosize,
310 284 int base_baud)
311#define PCH_REGS_BUFSIZE 1024
312
313
314static ssize_t port_show_regs(struct file *file, char __user *user_buf,
315 size_t count, loff_t *ppos)
316{ 285{
317 struct eg20t_port *priv = file->private_data; 286 struct eg20t_port *priv = pci_get_drvdata(pdev);
318 char *buf;
319 u32 len = 0;
320 ssize_t ret;
321 unsigned char lcr;
322
323 buf = kzalloc(PCH_REGS_BUFSIZE, GFP_KERNEL);
324 if (!buf)
325 return 0;
326
327 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
328 "PCH EG20T port[%d] regs:\n", priv->port.line);
329
330 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
331 "=================================\n");
332 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
333 "IER: \t0x%02x\n", ioread8(priv->membase + UART_IER));
334 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
335 "IIR: \t0x%02x\n", ioread8(priv->membase + UART_IIR));
336 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
337 "LCR: \t0x%02x\n", ioread8(priv->membase + UART_LCR));
338 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
339 "MCR: \t0x%02x\n", ioread8(priv->membase + UART_MCR));
340 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
341 "LSR: \t0x%02x\n", ioread8(priv->membase + UART_LSR));
342 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
343 "MSR: \t0x%02x\n", ioread8(priv->membase + UART_MSR));
344 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
345 "BRCSR: \t0x%02x\n",
346 ioread8(priv->membase + PCH_UART_BRCSR));
347
348 lcr = ioread8(priv->membase + UART_LCR);
349 iowrite8(PCH_UART_LCR_DLAB, priv->membase + UART_LCR);
350 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
351 "DLL: \t0x%02x\n", ioread8(priv->membase + UART_DLL));
352 len += snprintf(buf + len, PCH_REGS_BUFSIZE - len,
353 "DLM: \t0x%02x\n", ioread8(priv->membase + UART_DLM));
354 iowrite8(lcr, priv->membase + UART_LCR);
355
356 if (len > PCH_REGS_BUFSIZE)
357 len = PCH_REGS_BUFSIZE;
358 287
359 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); 288 priv->trigger_level = 1;
360 kfree(buf); 289 priv->fcr = 0;
361 return ret;
362} 290}
363 291
364static const struct file_operations port_regs_ops = { 292static unsigned int get_msr(struct eg20t_port *priv, void __iomem *base)
365 .owner = THIS_MODULE,
366 .open = simple_open,
367 .read = port_show_regs,
368 .llseek = default_llseek,
369};
370#endif /* CONFIG_DEBUG_FS */
371
372/* Return UART clock, checking for board specific clocks. */
373static int pch_uart_get_uartclk(void)
374{ 293{
375 const char *cmp; 294 unsigned int msr = ioread8(base + UART_MSR);
295 priv->dmsr |= msr & PCH_UART_MSR_DELTA;
376 296
377 if (user_uartclk) 297 return msr;
378 return user_uartclk;
379
380 cmp = dmi_get_system_info(DMI_BOARD_NAME);
381 if (cmp && strstr(cmp, "CM-iTC"))
382 return CMITC_UARTCLK;
383
384 cmp = dmi_get_system_info(DMI_BIOS_VERSION);
385 if (cmp && strnstr(cmp, "FRI2", 4))
386 return FRI2_64_UARTCLK;
387
388 cmp = dmi_get_system_info(DMI_PRODUCT_NAME);
389 if (cmp && strstr(cmp, "Fish River Island II"))
390 return FRI2_48_UARTCLK;
391
392 /* Kontron COMe-mTT10 (nanoETXexpress-TT) */
393 cmp = dmi_get_system_info(DMI_BOARD_NAME);
394 if (cmp && (strstr(cmp, "COMe-mTT") ||
395 strstr(cmp, "nanoETXexpress-TT")))
396 return NTC1_UARTCLK;
397
398 return DEFAULT_UARTCLK;
399} 298}
400 299
401static void pch_uart_hal_enable_interrupt(struct eg20t_port *priv, 300static void pch_uart_hal_enable_interrupt(struct eg20t_port *priv,
@@ -421,7 +320,7 @@ static int pch_uart_hal_set_line(struct eg20t_port *priv, int baud,
421 unsigned int dll, dlm, lcr; 320 unsigned int dll, dlm, lcr;
422 int div; 321 int div;
423 322
424 div = DIV_ROUND_CLOSEST(priv->uartclk / 16, baud); 323 div = DIV_ROUND_CLOSEST(priv->base_baud / 16, baud);
425 if (div < 0 || USHRT_MAX <= div) { 324 if (div < 0 || USHRT_MAX <= div) {
426 dev_err(priv->port.dev, "Invalid Baud(div=0x%x)\n", div); 325 dev_err(priv->port.dev, "Invalid Baud(div=0x%x)\n", div);
427 return -EINVAL; 326 return -EINVAL;
@@ -531,9 +430,8 @@ static int pch_uart_hal_set_fifo(struct eg20t_port *priv,
531 430
532static u8 pch_uart_hal_get_modem(struct eg20t_port *priv) 431static u8 pch_uart_hal_get_modem(struct eg20t_port *priv)
533{ 432{
534 unsigned int msr = ioread8(priv->membase + UART_MSR); 433 priv->dmsr = 0;
535 priv->dmsr = msr & PCH_UART_MSR_DELTA; 434 return get_msr(priv, priv->membase);
536 return (u8)msr;
537} 435}
538 436
539static void pch_uart_hal_write(struct eg20t_port *priv, 437static void pch_uart_hal_write(struct eg20t_port *priv,
@@ -564,10 +462,14 @@ static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf,
564 return i; 462 return i;
565} 463}
566 464
567static unsigned char pch_uart_hal_get_iid(struct eg20t_port *priv) 465static unsigned int pch_uart_hal_get_iid(struct eg20t_port *priv)
568{ 466{
569 return ioread8(priv->membase + UART_IIR) &\ 467 unsigned int iir;
570 (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP); 468 int ret;
469
470 iir = ioread8(priv->membase + UART_IIR);
471 ret = (iir & (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP));
472 return ret;
571} 473}
572 474
573static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv) 475static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv)
@@ -610,7 +512,7 @@ static int push_rx(struct eg20t_port *priv, const unsigned char *buf,
610 512
611static int pop_tx_x(struct eg20t_port *priv, unsigned char *buf) 513static int pop_tx_x(struct eg20t_port *priv, unsigned char *buf)
612{ 514{
613 int ret = 0; 515 int ret;
614 struct uart_port *port = &priv->port; 516 struct uart_port *port = &priv->port;
615 517
616 if (port->x_char) { 518 if (port->x_char) {
@@ -619,6 +521,8 @@ static int pop_tx_x(struct eg20t_port *priv, unsigned char *buf)
619 buf[0] = port->x_char; 521 buf[0] = port->x_char;
620 port->x_char = 0; 522 port->x_char = 0;
621 ret = 1; 523 ret = 1;
524 } else {
525 ret = 0;
622 } 526 }
623 527
624 return ret; 528 return ret;
@@ -666,13 +570,10 @@ static void pch_free_dma(struct uart_port *port)
666 dma_release_channel(priv->chan_rx); 570 dma_release_channel(priv->chan_rx);
667 priv->chan_rx = NULL; 571 priv->chan_rx = NULL;
668 } 572 }
669 573 if (sg_dma_address(&priv->sg_rx))
670 if (priv->rx_buf_dma) { 574 dma_free_coherent(port->dev, port->fifosize,
671 dma_free_coherent(port->dev, port->fifosize, priv->rx_buf_virt, 575 sg_virt(&priv->sg_rx),
672 priv->rx_buf_dma); 576 sg_dma_address(&priv->sg_rx));
673 priv->rx_buf_virt = NULL;
674 priv->rx_buf_dma = 0;
675 }
676 577
677 return; 578 return;
678} 579}
@@ -757,8 +658,7 @@ static void pch_dma_rx_complete(void *arg)
757 tty_flip_buffer_push(tty); 658 tty_flip_buffer_push(tty);
758 tty_kref_put(tty); 659 tty_kref_put(tty);
759 async_tx_ack(priv->desc_rx); 660 async_tx_ack(priv->desc_rx);
760 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT | 661 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT);
761 PCH_UART_HAL_RX_ERR_INT);
762} 662}
763 663
764static void pch_dma_tx_complete(void *arg) 664static void pch_dma_tx_complete(void *arg)
@@ -813,8 +713,7 @@ static int handle_rx_to(struct eg20t_port *priv)
813 int rx_size; 713 int rx_size;
814 int ret; 714 int ret;
815 if (!priv->start_rx) { 715 if (!priv->start_rx) {
816 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT | 716 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT);
817 PCH_UART_HAL_RX_ERR_INT);
818 return 0; 717 return 0;
819 } 718 }
820 buf = &priv->rxbuf; 719 buf = &priv->rxbuf;
@@ -852,8 +751,8 @@ static int dma_handle_rx(struct eg20t_port *priv)
852 751
853 sg_dma_address(sg) = priv->rx_buf_dma; 752 sg_dma_address(sg) = priv->rx_buf_dma;
854 753
855 desc = dmaengine_prep_slave_sg(priv->chan_rx, 754 desc = priv->chan_rx->device->device_prep_slave_sg(priv->chan_rx,
856 sg, 1, DMA_DEV_TO_MEM, 755 sg, 1, DMA_FROM_DEVICE,
857 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 756 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
858 757
859 if (!desc) 758 if (!desc)
@@ -979,10 +878,6 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv)
979 priv->tx_dma_use = 1; 878 priv->tx_dma_use = 1;
980 879
981 priv->sg_tx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC); 880 priv->sg_tx_p = kzalloc(sizeof(struct scatterlist)*num, GFP_ATOMIC);
982 if (!priv->sg_tx_p) {
983 dev_err(priv->port.dev, "%s:kzalloc Failed\n", __func__);
984 return 0;
985 }
986 881
987 sg_init_table(priv->sg_tx_p, num); /* Initialize SG table */ 882 sg_init_table(priv->sg_tx_p, num); /* Initialize SG table */
988 sg = priv->sg_tx_p; 883 sg = priv->sg_tx_p;
@@ -1015,8 +910,8 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv)
1015 sg_dma_len(sg) = size; 910 sg_dma_len(sg) = size;
1016 } 911 }
1017 912
1018 desc = dmaengine_prep_slave_sg(priv->chan_tx, 913 desc = priv->chan_tx->device->device_prep_slave_sg(priv->chan_tx,
1019 priv->sg_tx_p, nent, DMA_MEM_TO_DEV, 914 priv->sg_tx_p, nent, DMA_TO_DEVICE,
1020 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 915 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1021 if (!desc) { 916 if (!desc) {
1022 dev_err(priv->port.dev, "%s:device_prep_slave_sg Failed\n", 917 dev_err(priv->port.dev, "%s:device_prep_slave_sg Failed\n",
@@ -1062,17 +957,12 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1062 unsigned int handled; 957 unsigned int handled;
1063 u8 lsr; 958 u8 lsr;
1064 int ret = 0; 959 int ret = 0;
1065 unsigned char iid; 960 unsigned int iid;
1066 unsigned long flags; 961 unsigned long flags;
1067 int next = 1;
1068 u8 msr;
1069 962
1070 spin_lock_irqsave(&priv->lock, flags); 963 spin_lock_irqsave(&priv->port.lock, flags);
1071 handled = 0; 964 handled = 0;
1072 while (next) { 965 while ((iid = pch_uart_hal_get_iid(priv)) > 1) {
1073 iid = pch_uart_hal_get_iid(priv);
1074 if (iid & PCH_UART_IIR_IP) /* No Interrupt */
1075 break;
1076 switch (iid) { 966 switch (iid) {
1077 case PCH_UART_IID_RLS: /* Receiver Line Status */ 967 case PCH_UART_IID_RLS: /* Receiver Line Status */
1078 lsr = pch_uart_hal_get_line_status(priv); 968 lsr = pch_uart_hal_get_line_status(priv);
@@ -1080,20 +970,16 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1080 UART_LSR_PE | UART_LSR_OE)) { 970 UART_LSR_PE | UART_LSR_OE)) {
1081 pch_uart_err_ir(priv, lsr); 971 pch_uart_err_ir(priv, lsr);
1082 ret = PCH_UART_HANDLED_RX_ERR_INT; 972 ret = PCH_UART_HANDLED_RX_ERR_INT;
1083 } else {
1084 ret = PCH_UART_HANDLED_LS_INT;
1085 } 973 }
1086 break; 974 break;
1087 case PCH_UART_IID_RDR: /* Received Data Ready */ 975 case PCH_UART_IID_RDR: /* Received Data Ready */
1088 if (priv->use_dma) { 976 if (priv->use_dma) {
1089 pch_uart_hal_disable_interrupt(priv, 977 pch_uart_hal_disable_interrupt(priv,
1090 PCH_UART_HAL_RX_INT | 978 PCH_UART_HAL_RX_INT);
1091 PCH_UART_HAL_RX_ERR_INT);
1092 ret = dma_handle_rx(priv); 979 ret = dma_handle_rx(priv);
1093 if (!ret) 980 if (!ret)
1094 pch_uart_hal_enable_interrupt(priv, 981 pch_uart_hal_enable_interrupt(priv,
1095 PCH_UART_HAL_RX_INT | 982 PCH_UART_HAL_RX_INT);
1096 PCH_UART_HAL_RX_ERR_INT);
1097 } else { 983 } else {
1098 ret = handle_rx(priv); 984 ret = handle_rx(priv);
1099 } 985 }
@@ -1110,24 +996,22 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1110 ret = handle_tx(priv); 996 ret = handle_tx(priv);
1111 break; 997 break;
1112 case PCH_UART_IID_MS: /* Modem Status */ 998 case PCH_UART_IID_MS: /* Modem Status */
1113 msr = pch_uart_hal_get_modem(priv); 999 ret = PCH_UART_HANDLED_MS_INT;
1114 next = 0; /* MS ir prioirty is the lowest. So, MS ir
1115 means final interrupt */
1116 if ((msr & UART_MSR_ANY_DELTA) == 0)
1117 break;
1118 ret |= PCH_UART_HANDLED_MS_INT;
1119 break; 1000 break;
1120 default: /* Never junp to this label */ 1001 default: /* Never junp to this label */
1121 dev_err(priv->port.dev, "%s:iid=%02x (%lu)\n", __func__, 1002 dev_err(priv->port.dev, "%s:iid=%d (%lu)\n", __func__,
1122 iid, jiffies); 1003 iid, jiffies);
1123 ret = -1; 1004 ret = -1;
1124 next = 0;
1125 break; 1005 break;
1126 } 1006 }
1127 handled |= (unsigned int)ret; 1007 handled |= (unsigned int)ret;
1128 } 1008 }
1009 if (handled == 0 && iid <= 1) {
1010 if (priv->int_dis_flag)
1011 priv->int_dis_flag = 0;
1012 }
1129 1013
1130 spin_unlock_irqrestore(&priv->lock, flags); 1014 spin_unlock_irqrestore(&priv->port.lock, flags);
1131 return IRQ_RETVAL(handled); 1015 return IRQ_RETVAL(handled);
1132} 1016}
1133 1017
@@ -1136,12 +1020,14 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1136static unsigned int pch_uart_tx_empty(struct uart_port *port) 1020static unsigned int pch_uart_tx_empty(struct uart_port *port)
1137{ 1021{
1138 struct eg20t_port *priv; 1022 struct eg20t_port *priv;
1139 1023 int ret;
1140 priv = container_of(port, struct eg20t_port, port); 1024 priv = container_of(port, struct eg20t_port, port);
1141 if (priv->tx_empty) 1025 if (priv->tx_empty)
1142 return TIOCSER_TEMT; 1026 ret = TIOCSER_TEMT;
1143 else 1027 else
1144 return 0; 1028 ret = 0;
1029
1030 return ret;
1145} 1031}
1146 1032
1147/* Returns the current state of modem control inputs. */ 1033/* Returns the current state of modem control inputs. */
@@ -1219,8 +1105,8 @@ static void pch_uart_stop_rx(struct uart_port *port)
1219 struct eg20t_port *priv; 1105 struct eg20t_port *priv;
1220 priv = container_of(port, struct eg20t_port, port); 1106 priv = container_of(port, struct eg20t_port, port);
1221 priv->start_rx = 0; 1107 priv->start_rx = 0;
1222 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT | 1108 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT);
1223 PCH_UART_HAL_RX_ERR_INT); 1109 priv->int_dis_flag = 1;
1224} 1110}
1225 1111
1226/* Enable the modem status interrupts. */ 1112/* Enable the modem status interrupts. */
@@ -1238,9 +1124,9 @@ static void pch_uart_break_ctl(struct uart_port *port, int ctl)
1238 unsigned long flags; 1124 unsigned long flags;
1239 1125
1240 priv = container_of(port, struct eg20t_port, port); 1126 priv = container_of(port, struct eg20t_port, port);
1241 spin_lock_irqsave(&priv->lock, flags); 1127 spin_lock_irqsave(&port->lock, flags);
1242 pch_uart_hal_set_break(priv, ctl); 1128 pch_uart_hal_set_break(priv, ctl);
1243 spin_unlock_irqrestore(&priv->lock, flags); 1129 spin_unlock_irqrestore(&port->lock, flags);
1244} 1130}
1245 1131
1246/* Grab any interrupt resources and initialise any low level driver state. */ 1132/* Grab any interrupt resources and initialise any low level driver state. */
@@ -1255,9 +1141,9 @@ static int pch_uart_startup(struct uart_port *port)
1255 priv->tx_empty = 1; 1141 priv->tx_empty = 1;
1256 1142
1257 if (port->uartclk) 1143 if (port->uartclk)
1258 priv->uartclk = port->uartclk; 1144 priv->base_baud = port->uartclk;
1259 else 1145 else
1260 port->uartclk = priv->uartclk; 1146 port->uartclk = priv->base_baud;
1261 1147
1262 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT); 1148 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1263 ret = pch_uart_hal_set_line(priv, default_baud, 1149 ret = pch_uart_hal_set_line(priv, default_baud,
@@ -1275,7 +1161,6 @@ static int pch_uart_startup(struct uart_port *port)
1275 break; 1161 break;
1276 case 16: 1162 case 16:
1277 fifo_size = PCH_UART_HAL_FIFO16; 1163 fifo_size = PCH_UART_HAL_FIFO16;
1278 break;
1279 case 1: 1164 case 1:
1280 default: 1165 default:
1281 fifo_size = PCH_UART_HAL_FIFO_DIS; 1166 fifo_size = PCH_UART_HAL_FIFO_DIS;
@@ -1313,8 +1198,7 @@ static int pch_uart_startup(struct uart_port *port)
1313 pch_request_dma(port); 1198 pch_request_dma(port);
1314 1199
1315 priv->start_rx = 1; 1200 priv->start_rx = 1;
1316 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT | 1201 pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT);
1317 PCH_UART_HAL_RX_ERR_INT);
1318 uart_update_timeout(port, CS8, default_baud); 1202 uart_update_timeout(port, CS8, default_baud);
1319 1203
1320 return 0; 1204 return 0;
@@ -1372,13 +1256,14 @@ static void pch_uart_set_termios(struct uart_port *port,
1372 stb = PCH_UART_HAL_STB1; 1256 stb = PCH_UART_HAL_STB1;
1373 1257
1374 if (termios->c_cflag & PARENB) { 1258 if (termios->c_cflag & PARENB) {
1375 if (termios->c_cflag & PARODD) 1259 if (!(termios->c_cflag & PARODD))
1376 parity = PCH_UART_HAL_PARITY_ODD; 1260 parity = PCH_UART_HAL_PARITY_ODD;
1377 else 1261 else
1378 parity = PCH_UART_HAL_PARITY_EVEN; 1262 parity = PCH_UART_HAL_PARITY_EVEN;
1379 1263
1380 } else 1264 } else {
1381 parity = PCH_UART_HAL_PARITY_NONE; 1265 parity = PCH_UART_HAL_PARITY_NONE;
1266 }
1382 1267
1383 /* Only UART0 has auto hardware flow function */ 1268 /* Only UART0 has auto hardware flow function */
1384 if ((termios->c_cflag & CRTSCTS) && (priv->fifo_size == 256)) 1269 if ((termios->c_cflag & CRTSCTS) && (priv->fifo_size == 256))
@@ -1390,8 +1275,7 @@ static void pch_uart_set_termios(struct uart_port *port,
1390 1275
1391 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16); 1276 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
1392 1277
1393 spin_lock_irqsave(&priv->lock, flags); 1278 spin_lock_irqsave(&port->lock, flags);
1394 spin_lock(&port->lock);
1395 1279
1396 uart_update_timeout(port, termios->c_cflag, baud); 1280 uart_update_timeout(port, termios->c_cflag, baud);
1397 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb); 1281 rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb);
@@ -1404,8 +1288,7 @@ static void pch_uart_set_termios(struct uart_port *port,
1404 tty_termios_encode_baud_rate(termios, baud, baud); 1288 tty_termios_encode_baud_rate(termios, baud, baud);
1405 1289
1406out: 1290out:
1407 spin_unlock(&port->lock); 1291 spin_unlock_irqrestore(&port->lock, flags);
1408 spin_unlock_irqrestore(&priv->lock, flags);
1409} 1292}
1410 1293
1411static const char *pch_uart_type(struct uart_port *port) 1294static const char *pch_uart_type(struct uart_port *port)
@@ -1471,10 +1354,9 @@ static int pch_uart_verify_port(struct uart_port *port,
1471 __func__); 1354 __func__);
1472 return -EOPNOTSUPP; 1355 return -EOPNOTSUPP;
1473#endif 1356#endif
1474 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n");
1475 if (!priv->use_dma)
1476 pch_request_dma(port);
1477 priv->use_dma = 1; 1357 priv->use_dma = 1;
1358 priv->use_dma_flag = 1;
1359 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n");
1478 } 1360 }
1479 1361
1480 return 0; 1362 return 0;
@@ -1501,148 +1383,6 @@ static struct uart_ops pch_uart_ops = {
1501 .verify_port = pch_uart_verify_port 1383 .verify_port = pch_uart_verify_port
1502}; 1384};
1503 1385
1504#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1505
1506/*
1507 * Wait for transmitter & holding register to empty
1508 */
1509static void wait_for_xmitr(struct eg20t_port *up, int bits)
1510{
1511 unsigned int status, tmout = 10000;
1512
1513 /* Wait up to 10ms for the character(s) to be sent. */
1514 for (;;) {
1515 status = ioread8(up->membase + UART_LSR);
1516
1517 if ((status & bits) == bits)
1518 break;
1519 if (--tmout == 0)
1520 break;
1521 udelay(1);
1522 }
1523
1524 /* Wait up to 1s for flow control if necessary */
1525 if (up->port.flags & UPF_CONS_FLOW) {
1526 unsigned int tmout;
1527 for (tmout = 1000000; tmout; tmout--) {
1528 unsigned int msr = ioread8(up->membase + UART_MSR);
1529 if (msr & UART_MSR_CTS)
1530 break;
1531 udelay(1);
1532 touch_nmi_watchdog();
1533 }
1534 }
1535}
1536
1537static void pch_console_putchar(struct uart_port *port, int ch)
1538{
1539 struct eg20t_port *priv =
1540 container_of(port, struct eg20t_port, port);
1541
1542 wait_for_xmitr(priv, UART_LSR_THRE);
1543 iowrite8(ch, priv->membase + PCH_UART_THR);
1544}
1545
1546/*
1547 * Print a string to the serial port trying not to disturb
1548 * any possible real use of the port...
1549 *
1550 * The console_lock must be held when we get here.
1551 */
1552static void
1553pch_console_write(struct console *co, const char *s, unsigned int count)
1554{
1555 struct eg20t_port *priv;
1556 unsigned long flags;
1557 int priv_locked = 1;
1558 int port_locked = 1;
1559 u8 ier;
1560
1561 priv = pch_uart_ports[co->index];
1562
1563 touch_nmi_watchdog();
1564
1565 local_irq_save(flags);
1566 if (priv->port.sysrq) {
1567 spin_lock(&priv->lock);
1568 /* serial8250_handle_port() already took the port lock */
1569 port_locked = 0;
1570 } else if (oops_in_progress) {
1571 priv_locked = spin_trylock(&priv->lock);
1572 port_locked = spin_trylock(&priv->port.lock);
1573 } else {
1574 spin_lock(&priv->lock);
1575 spin_lock(&priv->port.lock);
1576 }
1577
1578 /*
1579 * First save the IER then disable the interrupts
1580 */
1581 ier = ioread8(priv->membase + UART_IER);
1582
1583 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_ALL_INT);
1584
1585 uart_console_write(&priv->port, s, count, pch_console_putchar);
1586
1587 /*
1588 * Finally, wait for transmitter to become empty
1589 * and restore the IER
1590 */
1591 wait_for_xmitr(priv, BOTH_EMPTY);
1592 iowrite8(ier, priv->membase + UART_IER);
1593
1594 if (port_locked)
1595 spin_unlock(&priv->port.lock);
1596 if (priv_locked)
1597 spin_unlock(&priv->lock);
1598 local_irq_restore(flags);
1599}
1600
1601static int __init pch_console_setup(struct console *co, char *options)
1602{
1603 struct uart_port *port;
1604 int baud = default_baud;
1605 int bits = 8;
1606 int parity = 'n';
1607 int flow = 'n';
1608
1609 /*
1610 * Check whether an invalid uart number has been specified, and
1611 * if so, search for the first available port that does have
1612 * console support.
1613 */
1614 if (co->index >= PCH_UART_NR)
1615 co->index = 0;
1616 port = &pch_uart_ports[co->index]->port;
1617
1618 if (!port || (!port->iobase && !port->membase))
1619 return -ENODEV;
1620
1621 port->uartclk = pch_uart_get_uartclk();
1622
1623 if (options)
1624 uart_parse_options(options, &baud, &parity, &bits, &flow);
1625
1626 return uart_set_options(port, co, baud, parity, bits, flow);
1627}
1628
1629static struct uart_driver pch_uart_driver;
1630
1631static struct console pch_console = {
1632 .name = PCH_UART_DRIVER_DEVICE,
1633 .write = pch_console_write,
1634 .device = uart_console_device,
1635 .setup = pch_console_setup,
1636 .flags = CON_PRINTBUFFER | CON_ANYTIME,
1637 .index = -1,
1638 .data = &pch_uart_driver,
1639};
1640
1641#define PCH_CONSOLE (&pch_console)
1642#else
1643#define PCH_CONSOLE NULL
1644#endif
1645
1646static struct uart_driver pch_uart_driver = { 1386static struct uart_driver pch_uart_driver = {
1647 .owner = THIS_MODULE, 1387 .owner = THIS_MODULE,
1648 .driver_name = KBUILD_MODNAME, 1388 .driver_name = KBUILD_MODNAME,
@@ -1650,7 +1390,6 @@ static struct uart_driver pch_uart_driver = {
1650 .major = 0, 1390 .major = 0,
1651 .minor = 0, 1391 .minor = 0,
1652 .nr = PCH_UART_NR, 1392 .nr = PCH_UART_NR,
1653 .cons = PCH_CONSOLE,
1654}; 1393};
1655 1394
1656static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev, 1395static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
@@ -1661,10 +1400,10 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
1661 unsigned int iobase; 1400 unsigned int iobase;
1662 unsigned int mapbase; 1401 unsigned int mapbase;
1663 unsigned char *rxbuf; 1402 unsigned char *rxbuf;
1664 int fifosize; 1403 int fifosize, base_baud;
1665 int port_type; 1404 int port_type;
1666 struct pch_uart_driver_data *board; 1405 struct pch_uart_driver_data *board;
1667 char name[32]; /* for debugfs file name */ 1406 const char *board_name;
1668 1407
1669 board = &drv_dat[id->driver_data]; 1408 board = &drv_dat[id->driver_data];
1670 port_type = board->port_type; 1409 port_type = board->port_type;
@@ -1677,6 +1416,13 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
1677 if (!rxbuf) 1416 if (!rxbuf)
1678 goto init_port_free_txbuf; 1417 goto init_port_free_txbuf;
1679 1418
1419 base_baud = 1843200; /* 1.8432MHz */
1420
1421 /* quirk for CM-iTC board */
1422 board_name = dmi_get_system_info(DMI_BOARD_NAME);
1423 if (board_name && strstr(board_name, "CM-iTC"))
1424 base_baud = 192000000; /* 192.0MHz */
1425
1680 switch (port_type) { 1426 switch (port_type) {
1681 case PORT_UNKNOWN: 1427 case PORT_UNKNOWN:
1682 fifosize = 256; /* EG20T/ML7213: UART0 */ 1428 fifosize = 256; /* EG20T/ML7213: UART0 */
@@ -1690,9 +1436,6 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
1690 } 1436 }
1691 1437
1692 pci_enable_msi(pdev); 1438 pci_enable_msi(pdev);
1693 pci_set_master(pdev);
1694
1695 spin_lock_init(&priv->lock);
1696 1439
1697 iobase = pci_resource_start(pdev, 0); 1440 iobase = pci_resource_start(pdev, 0);
1698 mapbase = pci_resource_start(pdev, 1); 1441 mapbase = pci_resource_start(pdev, 1);
@@ -1704,7 +1447,7 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
1704 priv->rxbuf.size = PAGE_SIZE; 1447 priv->rxbuf.size = PAGE_SIZE;
1705 1448
1706 priv->fifo_size = fifosize; 1449 priv->fifo_size = fifosize;
1707 priv->uartclk = pch_uart_get_uartclk(); 1450 priv->base_baud = base_baud;
1708 priv->port_type = PORT_MAX_8250 + port_type + 1; 1451 priv->port_type = PORT_MAX_8250 + port_type + 1;
1709 priv->port.dev = &pdev->dev; 1452 priv->port.dev = &pdev->dev;
1710 priv->port.iobase = iobase; 1453 priv->port.iobase = iobase;
@@ -1721,28 +1464,15 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
1721 spin_lock_init(&priv->port.lock); 1464 spin_lock_init(&priv->port.lock);
1722 1465
1723 pci_set_drvdata(pdev, priv); 1466 pci_set_drvdata(pdev, priv);
1724 priv->trigger_level = 1; 1467 pch_uart_hal_request(pdev, fifosize, base_baud);
1725 priv->fcr = 0;
1726 1468
1727#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1728 pch_uart_ports[board->line_no] = priv;
1729#endif
1730 ret = uart_add_one_port(&pch_uart_driver, &priv->port); 1469 ret = uart_add_one_port(&pch_uart_driver, &priv->port);
1731 if (ret < 0) 1470 if (ret < 0)
1732 goto init_port_hal_free; 1471 goto init_port_hal_free;
1733 1472
1734#ifdef CONFIG_DEBUG_FS
1735 snprintf(name, sizeof(name), "uart%d_regs", board->line_no);
1736 priv->debugfs = debugfs_create_file(name, S_IFREG | S_IRUGO,
1737 NULL, priv, &port_regs_ops);
1738#endif
1739
1740 return priv; 1473 return priv;
1741 1474
1742init_port_hal_free: 1475init_port_hal_free:
1743#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
1744 pch_uart_ports[board->line_no] = NULL;
1745#endif
1746 free_page((unsigned long)rxbuf); 1476 free_page((unsigned long)rxbuf);
1747init_port_free_txbuf: 1477init_port_free_txbuf:
1748 kfree(priv); 1478 kfree(priv);
@@ -1753,11 +1483,6 @@ init_port_alloc_err:
1753 1483
1754static void pch_uart_exit_port(struct eg20t_port *priv) 1484static void pch_uart_exit_port(struct eg20t_port *priv)
1755{ 1485{
1756
1757#ifdef CONFIG_DEBUG_FS
1758 if (priv->debugfs)
1759 debugfs_remove(priv->debugfs);
1760#endif
1761 uart_remove_one_port(&pch_uart_driver, &priv->port); 1486 uart_remove_one_port(&pch_uart_driver, &priv->port);
1762 pci_set_drvdata(priv->pdev, NULL); 1487 pci_set_drvdata(priv->pdev, NULL);
1763 free_page((unsigned long)priv->rxbuf.buf); 1488 free_page((unsigned long)priv->rxbuf.buf);
@@ -1765,13 +1490,11 @@ static void pch_uart_exit_port(struct eg20t_port *priv)
1765 1490
1766static void pch_uart_pci_remove(struct pci_dev *pdev) 1491static void pch_uart_pci_remove(struct pci_dev *pdev)
1767{ 1492{
1768 struct eg20t_port *priv = pci_get_drvdata(pdev); 1493 struct eg20t_port *priv;
1769 1494
1770 pci_disable_msi(pdev); 1495 priv = (struct eg20t_port *)pci_get_drvdata(pdev);
1771 1496
1772#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE 1497 pci_disable_msi(pdev);
1773 pch_uart_ports[priv->port.line] = NULL;
1774#endif
1775 pch_uart_exit_port(priv); 1498 pch_uart_exit_port(priv);
1776 pci_disable_device(pdev); 1499 pci_disable_device(pdev);
1777 kfree(priv); 1500 kfree(priv);
@@ -1839,7 +1562,7 @@ static DEFINE_PCI_DEVICE_TABLE(pch_uart_pci_id) = {
1839 {0,}, 1562 {0,},
1840}; 1563};
1841 1564
1842static int pch_uart_pci_probe(struct pci_dev *pdev, 1565static int __devinit pch_uart_pci_probe(struct pci_dev *pdev,
1843 const struct pci_device_id *id) 1566 const struct pci_device_id *id)
1844{ 1567{
1845 int ret; 1568 int ret;
@@ -1869,7 +1592,7 @@ static struct pci_driver pch_uart_pci_driver = {
1869 .name = "pch_uart", 1592 .name = "pch_uart",
1870 .id_table = pch_uart_pci_id, 1593 .id_table = pch_uart_pci_id,
1871 .probe = pch_uart_pci_probe, 1594 .probe = pch_uart_pci_probe,
1872 .remove = pch_uart_pci_remove, 1595 .remove = __devexit_p(pch_uart_pci_remove),
1873 .suspend = pch_uart_pci_suspend, 1596 .suspend = pch_uart_pci_suspend,
1874 .resume = pch_uart_pci_resume, 1597 .resume = pch_uart_pci_resume,
1875}; 1598};
@@ -1902,8 +1625,3 @@ module_exit(pch_uart_module_exit);
1902MODULE_LICENSE("GPL v2"); 1625MODULE_LICENSE("GPL v2");
1903MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver"); 1626MODULE_DESCRIPTION("Intel EG20T PCH UART PCI Driver");
1904module_param(default_baud, uint, S_IRUGO); 1627module_param(default_baud, uint, S_IRUGO);
1905MODULE_PARM_DESC(default_baud,
1906 "Default BAUD for initial driver state and console (default 9600)");
1907module_param(user_uartclk, uint, S_IRUGO);
1908MODULE_PARM_DESC(user_uartclk,
1909 "Override UART default or board specific UART clock");
diff --git a/drivers/tty/serial/pmac_zilog.c b/drivers/tty/serial/pmac_zilog.c
index 333c8d012b0..5acd24a27d0 100644
--- a/drivers/tty/serial/pmac_zilog.c
+++ b/drivers/tty/serial/pmac_zilog.c
@@ -99,9 +99,6 @@ MODULE_LICENSE("GPL");
99#define PMACZILOG_NAME "ttyPZ" 99#define PMACZILOG_NAME "ttyPZ"
100#endif 100#endif
101 101
102#define pmz_debug(fmt, arg...) pr_debug("ttyPZ%d: " fmt, uap->port.line, ## arg)
103#define pmz_error(fmt, arg...) pr_err("ttyPZ%d: " fmt, uap->port.line, ## arg)
104#define pmz_info(fmt, arg...) pr_info("ttyPZ%d: " fmt, uap->port.line, ## arg)
105 102
106/* 103/*
107 * For the sake of early serial console, we can do a pre-probe 104 * For the sake of early serial console, we can do a pre-probe
@@ -109,6 +106,7 @@ MODULE_LICENSE("GPL");
109 */ 106 */
110static struct uart_pmac_port pmz_ports[MAX_ZS_PORTS]; 107static struct uart_pmac_port pmz_ports[MAX_ZS_PORTS];
111static int pmz_ports_count; 108static int pmz_ports_count;
109static DEFINE_MUTEX(pmz_irq_mutex);
112 110
113static struct uart_driver pmz_uart_reg = { 111static struct uart_driver pmz_uart_reg = {
114 .owner = THIS_MODULE, 112 .owner = THIS_MODULE,
@@ -128,6 +126,9 @@ static void pmz_load_zsregs(struct uart_pmac_port *uap, u8 *regs)
128{ 126{
129 int i; 127 int i;
130 128
129 if (ZS_IS_ASLEEP(uap))
130 return;
131
131 /* Let pending transmits finish. */ 132 /* Let pending transmits finish. */
132 for (i = 0; i < 1000; i++) { 133 for (i = 0; i < 1000; i++) {
133 unsigned char stat = read_zsreg(uap, R1); 134 unsigned char stat = read_zsreg(uap, R1);
@@ -215,24 +216,32 @@ static void pmz_maybe_update_regs(struct uart_pmac_port *uap)
215 } 216 }
216} 217}
217 218
218static void pmz_interrupt_control(struct uart_pmac_port *uap, int enable)
219{
220 if (enable) {
221 uap->curregs[1] |= INT_ALL_Rx | TxINT_ENAB;
222 if (!ZS_IS_EXTCLK(uap))
223 uap->curregs[1] |= EXT_INT_ENAB;
224 } else {
225 uap->curregs[1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
226 }
227 write_zsreg(uap, R1, uap->curregs[1]);
228}
229
230static struct tty_struct *pmz_receive_chars(struct uart_pmac_port *uap) 219static struct tty_struct *pmz_receive_chars(struct uart_pmac_port *uap)
231{ 220{
232 struct tty_struct *tty = NULL; 221 struct tty_struct *tty = NULL;
233 unsigned char ch, r1, drop, error, flag; 222 unsigned char ch, r1, drop, error, flag;
234 int loops = 0; 223 int loops = 0;
235 224
225 /* The interrupt can be enabled when the port isn't open, typically
226 * that happens when using one port is open and the other closed (stale
227 * interrupt) or when one port is used as a console.
228 */
229 if (!ZS_IS_OPEN(uap)) {
230 pmz_debug("pmz: draining input\n");
231 /* Port is closed, drain input data */
232 for (;;) {
233 if ((++loops) > 1000)
234 goto flood;
235 (void)read_zsreg(uap, R1);
236 write_zsreg(uap, R0, ERR_RES);
237 (void)read_zsdata(uap);
238 ch = read_zsreg(uap, R0);
239 if (!(ch & Rx_CH_AV))
240 break;
241 }
242 return NULL;
243 }
244
236 /* Sanity check, make sure the old bug is no longer happening */ 245 /* Sanity check, make sure the old bug is no longer happening */
237 if (uap->port.state == NULL || uap->port.state->port.tty == NULL) { 246 if (uap->port.state == NULL || uap->port.state->port.tty == NULL) {
238 WARN_ON(1); 247 WARN_ON(1);
@@ -330,7 +339,9 @@ static struct tty_struct *pmz_receive_chars(struct uart_pmac_port *uap)
330 339
331 return tty; 340 return tty;
332 flood: 341 flood:
333 pmz_interrupt_control(uap, 0); 342 uap->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
343 write_zsreg(uap, R1, uap->curregs[R1]);
344 zssync(uap);
334 pmz_error("pmz: rx irq flood !\n"); 345 pmz_error("pmz: rx irq flood !\n");
335 return tty; 346 return tty;
336} 347}
@@ -372,6 +383,8 @@ static void pmz_transmit_chars(struct uart_pmac_port *uap)
372{ 383{
373 struct circ_buf *xmit; 384 struct circ_buf *xmit;
374 385
386 if (ZS_IS_ASLEEP(uap))
387 return;
375 if (ZS_IS_CONS(uap)) { 388 if (ZS_IS_CONS(uap)) {
376 unsigned char status = read_zsreg(uap, R0); 389 unsigned char status = read_zsreg(uap, R0);
377 390
@@ -468,10 +481,6 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
468 /* Channel A */ 481 /* Channel A */
469 tty = NULL; 482 tty = NULL;
470 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) { 483 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
471 if (!ZS_IS_OPEN(uap_a)) {
472 pmz_debug("ChanA interrupt while not open !\n");
473 goto skip_a;
474 }
475 write_zsreg(uap_a, R0, RES_H_IUS); 484 write_zsreg(uap_a, R0, RES_H_IUS);
476 zssync(uap_a); 485 zssync(uap_a);
477 if (r3 & CHAEXT) 486 if (r3 & CHAEXT)
@@ -482,21 +491,16 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
482 pmz_transmit_chars(uap_a); 491 pmz_transmit_chars(uap_a);
483 rc = IRQ_HANDLED; 492 rc = IRQ_HANDLED;
484 } 493 }
485 skip_a:
486 spin_unlock(&uap_a->port.lock); 494 spin_unlock(&uap_a->port.lock);
487 if (tty != NULL) 495 if (tty != NULL)
488 tty_flip_buffer_push(tty); 496 tty_flip_buffer_push(tty);
489 497
490 if (!uap_b) 498 if (uap_b->node == NULL)
491 goto out; 499 goto out;
492 500
493 spin_lock(&uap_b->port.lock); 501 spin_lock(&uap_b->port.lock);
494 tty = NULL; 502 tty = NULL;
495 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { 503 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
496 if (!ZS_IS_OPEN(uap_b)) {
497 pmz_debug("ChanB interrupt while not open !\n");
498 goto skip_b;
499 }
500 write_zsreg(uap_b, R0, RES_H_IUS); 504 write_zsreg(uap_b, R0, RES_H_IUS);
501 zssync(uap_b); 505 zssync(uap_b);
502 if (r3 & CHBEXT) 506 if (r3 & CHBEXT)
@@ -507,12 +511,14 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
507 pmz_transmit_chars(uap_b); 511 pmz_transmit_chars(uap_b);
508 rc = IRQ_HANDLED; 512 rc = IRQ_HANDLED;
509 } 513 }
510 skip_b:
511 spin_unlock(&uap_b->port.lock); 514 spin_unlock(&uap_b->port.lock);
512 if (tty != NULL) 515 if (tty != NULL)
513 tty_flip_buffer_push(tty); 516 tty_flip_buffer_push(tty);
514 517
515 out: 518 out:
519#ifdef DEBUG_HARD
520 pmz_debug("irq done.\n");
521#endif
516 return rc; 522 return rc;
517} 523}
518 524
@@ -537,8 +543,12 @@ static inline u8 pmz_peek_status(struct uart_pmac_port *uap)
537 */ 543 */
538static unsigned int pmz_tx_empty(struct uart_port *port) 544static unsigned int pmz_tx_empty(struct uart_port *port)
539{ 545{
546 struct uart_pmac_port *uap = to_pmz(port);
540 unsigned char status; 547 unsigned char status;
541 548
549 if (ZS_IS_ASLEEP(uap) || uap->node == NULL)
550 return TIOCSER_TEMT;
551
542 status = pmz_peek_status(to_pmz(port)); 552 status = pmz_peek_status(to_pmz(port));
543 if (status & Tx_BUF_EMP) 553 if (status & Tx_BUF_EMP)
544 return TIOCSER_TEMT; 554 return TIOCSER_TEMT;
@@ -560,7 +570,8 @@ static void pmz_set_mctrl(struct uart_port *port, unsigned int mctrl)
560 if (ZS_IS_IRDA(uap)) 570 if (ZS_IS_IRDA(uap))
561 return; 571 return;
562 /* We get called during boot with a port not up yet */ 572 /* We get called during boot with a port not up yet */
563 if (!(ZS_IS_OPEN(uap) || ZS_IS_CONS(uap))) 573 if (ZS_IS_ASLEEP(uap) ||
574 !(ZS_IS_OPEN(uap) || ZS_IS_CONS(uap)))
564 return; 575 return;
565 576
566 set_bits = clear_bits = 0; 577 set_bits = clear_bits = 0;
@@ -579,7 +590,8 @@ static void pmz_set_mctrl(struct uart_port *port, unsigned int mctrl)
579 /* NOTE: Not subject to 'transmitter active' rule. */ 590 /* NOTE: Not subject to 'transmitter active' rule. */
580 uap->curregs[R5] |= set_bits; 591 uap->curregs[R5] |= set_bits;
581 uap->curregs[R5] &= ~clear_bits; 592 uap->curregs[R5] &= ~clear_bits;
582 593 if (ZS_IS_ASLEEP(uap))
594 return;
583 write_zsreg(uap, R5, uap->curregs[R5]); 595 write_zsreg(uap, R5, uap->curregs[R5]);
584 pmz_debug("pmz_set_mctrl: set bits: %x, clear bits: %x -> %x\n", 596 pmz_debug("pmz_set_mctrl: set bits: %x, clear bits: %x -> %x\n",
585 set_bits, clear_bits, uap->curregs[R5]); 597 set_bits, clear_bits, uap->curregs[R5]);
@@ -597,6 +609,9 @@ static unsigned int pmz_get_mctrl(struct uart_port *port)
597 unsigned char status; 609 unsigned char status;
598 unsigned int ret; 610 unsigned int ret;
599 611
612 if (ZS_IS_ASLEEP(uap) || uap->node == NULL)
613 return 0;
614
600 status = read_zsreg(uap, R0); 615 status = read_zsreg(uap, R0);
601 616
602 ret = 0; 617 ret = 0;
@@ -634,6 +649,9 @@ static void pmz_start_tx(struct uart_port *port)
634 uap->flags |= PMACZILOG_FLAG_TX_ACTIVE; 649 uap->flags |= PMACZILOG_FLAG_TX_ACTIVE;
635 uap->flags &= ~PMACZILOG_FLAG_TX_STOPPED; 650 uap->flags &= ~PMACZILOG_FLAG_TX_STOPPED;
636 651
652 if (ZS_IS_ASLEEP(uap) || uap->node == NULL)
653 return;
654
637 status = read_zsreg(uap, R0); 655 status = read_zsreg(uap, R0);
638 656
639 /* TX busy? Just wait for the TX done interrupt. */ 657 /* TX busy? Just wait for the TX done interrupt. */
@@ -672,6 +690,9 @@ static void pmz_stop_rx(struct uart_port *port)
672{ 690{
673 struct uart_pmac_port *uap = to_pmz(port); 691 struct uart_pmac_port *uap = to_pmz(port);
674 692
693 if (ZS_IS_ASLEEP(uap) || uap->node == NULL)
694 return;
695
675 pmz_debug("pmz: stop_rx()()\n"); 696 pmz_debug("pmz: stop_rx()()\n");
676 697
677 /* Disable all RX interrupts. */ 698 /* Disable all RX interrupts. */
@@ -690,12 +711,14 @@ static void pmz_enable_ms(struct uart_port *port)
690 struct uart_pmac_port *uap = to_pmz(port); 711 struct uart_pmac_port *uap = to_pmz(port);
691 unsigned char new_reg; 712 unsigned char new_reg;
692 713
693 if (ZS_IS_IRDA(uap)) 714 if (ZS_IS_IRDA(uap) || uap->node == NULL)
694 return; 715 return;
695 new_reg = uap->curregs[R15] | (DCDIE | SYNCIE | CTSIE); 716 new_reg = uap->curregs[R15] | (DCDIE | SYNCIE | CTSIE);
696 if (new_reg != uap->curregs[R15]) { 717 if (new_reg != uap->curregs[R15]) {
697 uap->curregs[R15] = new_reg; 718 uap->curregs[R15] = new_reg;
698 719
720 if (ZS_IS_ASLEEP(uap))
721 return;
699 /* NOTE: Not subject to 'transmitter active' rule. */ 722 /* NOTE: Not subject to 'transmitter active' rule. */
700 write_zsreg(uap, R15, uap->curregs[R15]); 723 write_zsreg(uap, R15, uap->curregs[R15]);
701 } 724 }
@@ -711,6 +734,8 @@ static void pmz_break_ctl(struct uart_port *port, int break_state)
711 unsigned char set_bits, clear_bits, new_reg; 734 unsigned char set_bits, clear_bits, new_reg;
712 unsigned long flags; 735 unsigned long flags;
713 736
737 if (uap->node == NULL)
738 return;
714 set_bits = clear_bits = 0; 739 set_bits = clear_bits = 0;
715 740
716 if (break_state) 741 if (break_state)
@@ -723,6 +748,12 @@ static void pmz_break_ctl(struct uart_port *port, int break_state)
723 new_reg = (uap->curregs[R5] | set_bits) & ~clear_bits; 748 new_reg = (uap->curregs[R5] | set_bits) & ~clear_bits;
724 if (new_reg != uap->curregs[R5]) { 749 if (new_reg != uap->curregs[R5]) {
725 uap->curregs[R5] = new_reg; 750 uap->curregs[R5] = new_reg;
751
752 /* NOTE: Not subject to 'transmitter active' rule. */
753 if (ZS_IS_ASLEEP(uap)) {
754 spin_unlock_irqrestore(&port->lock, flags);
755 return;
756 }
726 write_zsreg(uap, R5, uap->curregs[R5]); 757 write_zsreg(uap, R5, uap->curregs[R5]);
727 } 758 }
728 759
@@ -896,21 +927,14 @@ static int __pmz_startup(struct uart_pmac_port *uap)
896 927
897static void pmz_irda_reset(struct uart_pmac_port *uap) 928static void pmz_irda_reset(struct uart_pmac_port *uap)
898{ 929{
899 unsigned long flags;
900
901 spin_lock_irqsave(&uap->port.lock, flags);
902 uap->curregs[R5] |= DTR; 930 uap->curregs[R5] |= DTR;
903 write_zsreg(uap, R5, uap->curregs[R5]); 931 write_zsreg(uap, R5, uap->curregs[R5]);
904 zssync(uap); 932 zssync(uap);
905 spin_unlock_irqrestore(&uap->port.lock, flags); 933 mdelay(110);
906 msleep(110);
907
908 spin_lock_irqsave(&uap->port.lock, flags);
909 uap->curregs[R5] &= ~DTR; 934 uap->curregs[R5] &= ~DTR;
910 write_zsreg(uap, R5, uap->curregs[R5]); 935 write_zsreg(uap, R5, uap->curregs[R5]);
911 zssync(uap); 936 zssync(uap);
912 spin_unlock_irqrestore(&uap->port.lock, flags); 937 mdelay(10);
913 msleep(10);
914} 938}
915 939
916/* 940/*
@@ -925,6 +949,13 @@ static int pmz_startup(struct uart_port *port)
925 949
926 pmz_debug("pmz: startup()\n"); 950 pmz_debug("pmz: startup()\n");
927 951
952 if (ZS_IS_ASLEEP(uap))
953 return -EAGAIN;
954 if (uap->node == NULL)
955 return -ENODEV;
956
957 mutex_lock(&pmz_irq_mutex);
958
928 uap->flags |= PMACZILOG_FLAG_IS_OPEN; 959 uap->flags |= PMACZILOG_FLAG_IS_OPEN;
929 960
930 /* A console is never powered down. Else, power up and 961 /* A console is never powered down. Else, power up and
@@ -935,14 +966,18 @@ static int pmz_startup(struct uart_port *port)
935 pwr_delay = __pmz_startup(uap); 966 pwr_delay = __pmz_startup(uap);
936 spin_unlock_irqrestore(&port->lock, flags); 967 spin_unlock_irqrestore(&port->lock, flags);
937 } 968 }
938 sprintf(uap->irq_name, PMACZILOG_NAME"%d", uap->port.line); 969
970 pmz_get_port_A(uap)->flags |= PMACZILOG_FLAG_IS_IRQ_ON;
939 if (request_irq(uap->port.irq, pmz_interrupt, IRQF_SHARED, 971 if (request_irq(uap->port.irq, pmz_interrupt, IRQF_SHARED,
940 uap->irq_name, uap)) { 972 "SCC", uap)) {
941 pmz_error("Unable to register zs interrupt handler.\n"); 973 pmz_error("Unable to register zs interrupt handler.\n");
942 pmz_set_scc_power(uap, 0); 974 pmz_set_scc_power(uap, 0);
975 mutex_unlock(&pmz_irq_mutex);
943 return -ENXIO; 976 return -ENXIO;
944 } 977 }
945 978
979 mutex_unlock(&pmz_irq_mutex);
980
946 /* Right now, we deal with delay by blocking here, I'll be 981 /* Right now, we deal with delay by blocking here, I'll be
947 * smarter later on 982 * smarter later on
948 */ 983 */
@@ -955,9 +990,12 @@ static int pmz_startup(struct uart_port *port)
955 if (ZS_IS_IRDA(uap)) 990 if (ZS_IS_IRDA(uap))
956 pmz_irda_reset(uap); 991 pmz_irda_reset(uap);
957 992
958 /* Enable interrupt requests for the channel */ 993 /* Enable interrupts emission from the chip */
959 spin_lock_irqsave(&port->lock, flags); 994 spin_lock_irqsave(&port->lock, flags);
960 pmz_interrupt_control(uap, 1); 995 uap->curregs[R1] |= INT_ALL_Rx | TxINT_ENAB;
996 if (!ZS_IS_EXTCLK(uap))
997 uap->curregs[R1] |= EXT_INT_ENAB;
998 write_zsreg(uap, R1, uap->curregs[R1]);
961 spin_unlock_irqrestore(&port->lock, flags); 999 spin_unlock_irqrestore(&port->lock, flags);
962 1000
963 pmz_debug("pmz: startup() done.\n"); 1001 pmz_debug("pmz: startup() done.\n");
@@ -972,22 +1010,10 @@ static void pmz_shutdown(struct uart_port *port)
972 1010
973 pmz_debug("pmz: shutdown()\n"); 1011 pmz_debug("pmz: shutdown()\n");
974 1012
975 spin_lock_irqsave(&port->lock, flags); 1013 if (uap->node == NULL)
976 1014 return;
977 /* Disable interrupt requests for the channel */
978 pmz_interrupt_control(uap, 0);
979
980 if (!ZS_IS_CONS(uap)) {
981 /* Disable receiver and transmitter */
982 uap->curregs[R3] &= ~RxENABLE;
983 uap->curregs[R5] &= ~TxENABLE;
984
985 /* Disable break assertion */
986 uap->curregs[R5] &= ~SND_BRK;
987 pmz_maybe_update_regs(uap);
988 }
989 1015
990 spin_unlock_irqrestore(&port->lock, flags); 1016 mutex_lock(&pmz_irq_mutex);
991 1017
992 /* Release interrupt handler */ 1018 /* Release interrupt handler */
993 free_irq(uap->port.irq, uap); 1019 free_irq(uap->port.irq, uap);
@@ -996,11 +1022,37 @@ static void pmz_shutdown(struct uart_port *port)
996 1022
997 uap->flags &= ~PMACZILOG_FLAG_IS_OPEN; 1023 uap->flags &= ~PMACZILOG_FLAG_IS_OPEN;
998 1024
999 if (!ZS_IS_CONS(uap)) 1025 if (!ZS_IS_OPEN(uap->mate))
1000 pmz_set_scc_power(uap, 0); /* Shut the chip down */ 1026 pmz_get_port_A(uap)->flags &= ~PMACZILOG_FLAG_IS_IRQ_ON;
1027
1028 /* Disable interrupts */
1029 if (!ZS_IS_ASLEEP(uap)) {
1030 uap->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
1031 write_zsreg(uap, R1, uap->curregs[R1]);
1032 zssync(uap);
1033 }
1034
1035 if (ZS_IS_CONS(uap) || ZS_IS_ASLEEP(uap)) {
1036 spin_unlock_irqrestore(&port->lock, flags);
1037 mutex_unlock(&pmz_irq_mutex);
1038 return;
1039 }
1040
1041 /* Disable receiver and transmitter. */
1042 uap->curregs[R3] &= ~RxENABLE;
1043 uap->curregs[R5] &= ~TxENABLE;
1044
1045 /* Disable all interrupts and BRK assertion. */
1046 uap->curregs[R5] &= ~SND_BRK;
1047 pmz_maybe_update_regs(uap);
1048
1049 /* Shut the chip down */
1050 pmz_set_scc_power(uap, 0);
1001 1051
1002 spin_unlock_irqrestore(&port->lock, flags); 1052 spin_unlock_irqrestore(&port->lock, flags);
1003 1053
1054 mutex_unlock(&pmz_irq_mutex);
1055
1004 pmz_debug("pmz: shutdown() done.\n"); 1056 pmz_debug("pmz: shutdown() done.\n");
1005} 1057}
1006 1058
@@ -1248,6 +1300,9 @@ static void __pmz_set_termios(struct uart_port *port, struct ktermios *termios,
1248 1300
1249 pmz_debug("pmz: set_termios()\n"); 1301 pmz_debug("pmz: set_termios()\n");
1250 1302
1303 if (ZS_IS_ASLEEP(uap))
1304 return;
1305
1251 memcpy(&uap->termios_cache, termios, sizeof(struct ktermios)); 1306 memcpy(&uap->termios_cache, termios, sizeof(struct ktermios));
1252 1307
1253 /* XXX Check which revs of machines actually allow 1 and 4Mb speeds 1308 /* XXX Check which revs of machines actually allow 1 and 4Mb speeds
@@ -1297,15 +1352,19 @@ static void pmz_set_termios(struct uart_port *port, struct ktermios *termios,
1297 spin_lock_irqsave(&port->lock, flags); 1352 spin_lock_irqsave(&port->lock, flags);
1298 1353
1299 /* Disable IRQs on the port */ 1354 /* Disable IRQs on the port */
1300 pmz_interrupt_control(uap, 0); 1355 uap->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
1356 write_zsreg(uap, R1, uap->curregs[R1]);
1301 1357
1302 /* Setup new port configuration */ 1358 /* Setup new port configuration */
1303 __pmz_set_termios(port, termios, old); 1359 __pmz_set_termios(port, termios, old);
1304 1360
1305 /* Re-enable IRQs on the port */ 1361 /* Re-enable IRQs on the port */
1306 if (ZS_IS_OPEN(uap)) 1362 if (ZS_IS_OPEN(uap)) {
1307 pmz_interrupt_control(uap, 1); 1363 uap->curregs[R1] |= INT_ALL_Rx | TxINT_ENAB;
1308 1364 if (!ZS_IS_EXTCLK(uap))
1365 uap->curregs[R1] |= EXT_INT_ENAB;
1366 write_zsreg(uap, R1, uap->curregs[R1]);
1367 }
1309 spin_unlock_irqrestore(&port->lock, flags); 1368 spin_unlock_irqrestore(&port->lock, flags);
1310} 1369}
1311 1370
@@ -1348,16 +1407,10 @@ static int pmz_verify_port(struct uart_port *port, struct serial_struct *ser)
1348static int pmz_poll_get_char(struct uart_port *port) 1407static int pmz_poll_get_char(struct uart_port *port)
1349{ 1408{
1350 struct uart_pmac_port *uap = (struct uart_pmac_port *)port; 1409 struct uart_pmac_port *uap = (struct uart_pmac_port *)port;
1351 int tries = 2;
1352 1410
1353 while (tries) { 1411 while ((read_zsreg(uap, R0) & Rx_CH_AV) == 0)
1354 if ((read_zsreg(uap, R0) & Rx_CH_AV) != 0) 1412 udelay(5);
1355 return read_zsdata(uap); 1413 return read_zsdata(uap);
1356 if (tries--)
1357 udelay(5);
1358 }
1359
1360 return NO_POLL_CHAR;
1361} 1414}
1362 1415
1363static void pmz_poll_put_char(struct uart_port *port, unsigned char c) 1416static void pmz_poll_put_char(struct uart_port *port, unsigned char c)
@@ -1512,7 +1565,7 @@ no_dma:
1512 * fixed up interrupt info, but we use the device-tree directly 1565 * fixed up interrupt info, but we use the device-tree directly
1513 * here due to early probing so we need the fixup too. 1566 * here due to early probing so we need the fixup too.
1514 */ 1567 */
1515 if (uap->port.irq == 0 && 1568 if (uap->port.irq == NO_IRQ &&
1516 np->parent && np->parent->parent && 1569 np->parent && np->parent->parent &&
1517 of_device_is_compatible(np->parent->parent, "gatwick")) { 1570 of_device_is_compatible(np->parent->parent, "gatwick")) {
1518 /* IRQs on gatwick are offset by 64 */ 1571 /* IRQs on gatwick are offset by 64 */
@@ -1551,34 +1604,25 @@ static void pmz_dispose_port(struct uart_pmac_port *uap)
1551 */ 1604 */
1552static int pmz_attach(struct macio_dev *mdev, const struct of_device_id *match) 1605static int pmz_attach(struct macio_dev *mdev, const struct of_device_id *match)
1553{ 1606{
1554 struct uart_pmac_port *uap;
1555 int i; 1607 int i;
1556 1608
1557 /* Iterate the pmz_ports array to find a matching entry 1609 /* Iterate the pmz_ports array to find a matching entry
1558 */ 1610 */
1559 for (i = 0; i < MAX_ZS_PORTS; i++) 1611 for (i = 0; i < MAX_ZS_PORTS; i++)
1560 if (pmz_ports[i].node == mdev->ofdev.dev.of_node) 1612 if (pmz_ports[i].node == mdev->ofdev.dev.of_node) {
1561 break; 1613 struct uart_pmac_port *uap = &pmz_ports[i];
1562 if (i >= MAX_ZS_PORTS) 1614
1563 return -ENODEV; 1615 uap->dev = mdev;
1564 1616 dev_set_drvdata(&mdev->ofdev.dev, uap);
1565 1617 if (macio_request_resources(uap->dev, "pmac_zilog"))
1566 uap = &pmz_ports[i]; 1618 printk(KERN_WARNING "%s: Failed to request resource"
1567 uap->dev = mdev; 1619 ", port still active\n",
1568 uap->port.dev = &mdev->ofdev.dev; 1620 uap->node->name);
1569 dev_set_drvdata(&mdev->ofdev.dev, uap); 1621 else
1570 1622 uap->flags |= PMACZILOG_FLAG_RSRC_REQUESTED;
1571 /* We still activate the port even when failing to request resources 1623 return 0;
1572 * to work around bugs in ancient Apple device-trees 1624 }
1573 */ 1625 return -ENODEV;
1574 if (macio_request_resources(uap->dev, "pmac_zilog"))
1575 printk(KERN_WARNING "%s: Failed to request resource"
1576 ", port still active\n",
1577 uap->node->name);
1578 else
1579 uap->flags |= PMACZILOG_FLAG_RSRC_REQUESTED;
1580
1581 return uart_add_one_port(&pmz_uart_reg, &uap->port);
1582} 1626}
1583 1627
1584/* 1628/*
@@ -1592,15 +1636,12 @@ static int pmz_detach(struct macio_dev *mdev)
1592 if (!uap) 1636 if (!uap)
1593 return -ENODEV; 1637 return -ENODEV;
1594 1638
1595 uart_remove_one_port(&pmz_uart_reg, &uap->port);
1596
1597 if (uap->flags & PMACZILOG_FLAG_RSRC_REQUESTED) { 1639 if (uap->flags & PMACZILOG_FLAG_RSRC_REQUESTED) {
1598 macio_release_resources(uap->dev); 1640 macio_release_resources(uap->dev);
1599 uap->flags &= ~PMACZILOG_FLAG_RSRC_REQUESTED; 1641 uap->flags &= ~PMACZILOG_FLAG_RSRC_REQUESTED;
1600 } 1642 }
1601 dev_set_drvdata(&mdev->ofdev.dev, NULL); 1643 dev_set_drvdata(&mdev->ofdev.dev, NULL);
1602 uap->dev = NULL; 1644 uap->dev = NULL;
1603 uap->port.dev = NULL;
1604 1645
1605 return 0; 1646 return 0;
1606} 1647}
@@ -1609,13 +1650,59 @@ static int pmz_detach(struct macio_dev *mdev)
1609static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state) 1650static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state)
1610{ 1651{
1611 struct uart_pmac_port *uap = dev_get_drvdata(&mdev->ofdev.dev); 1652 struct uart_pmac_port *uap = dev_get_drvdata(&mdev->ofdev.dev);
1653 struct uart_state *state;
1654 unsigned long flags;
1612 1655
1613 if (uap == NULL) { 1656 if (uap == NULL) {
1614 printk("HRM... pmz_suspend with NULL uap\n"); 1657 printk("HRM... pmz_suspend with NULL uap\n");
1615 return 0; 1658 return 0;
1616 } 1659 }
1617 1660
1618 uart_suspend_port(&pmz_uart_reg, &uap->port); 1661 if (pm_state.event == mdev->ofdev.dev.power.power_state.event)
1662 return 0;
1663
1664 pmz_debug("suspend, switching to state %d\n", pm_state.event);
1665
1666 state = pmz_uart_reg.state + uap->port.line;
1667
1668 mutex_lock(&pmz_irq_mutex);
1669 mutex_lock(&state->port.mutex);
1670
1671 spin_lock_irqsave(&uap->port.lock, flags);
1672
1673 if (ZS_IS_OPEN(uap) || ZS_IS_CONS(uap)) {
1674 /* Disable receiver and transmitter. */
1675 uap->curregs[R3] &= ~RxENABLE;
1676 uap->curregs[R5] &= ~TxENABLE;
1677
1678 /* Disable all interrupts and BRK assertion. */
1679 uap->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
1680 uap->curregs[R5] &= ~SND_BRK;
1681 pmz_load_zsregs(uap, uap->curregs);
1682 uap->flags |= PMACZILOG_FLAG_IS_ASLEEP;
1683 mb();
1684 }
1685
1686 spin_unlock_irqrestore(&uap->port.lock, flags);
1687
1688 if (ZS_IS_OPEN(uap) || ZS_IS_OPEN(uap->mate))
1689 if (ZS_IS_ASLEEP(uap->mate) && ZS_IS_IRQ_ON(pmz_get_port_A(uap))) {
1690 pmz_get_port_A(uap)->flags &= ~PMACZILOG_FLAG_IS_IRQ_ON;
1691 disable_irq(uap->port.irq);
1692 }
1693
1694 if (ZS_IS_CONS(uap))
1695 uap->port.cons->flags &= ~CON_ENABLED;
1696
1697 /* Shut the chip down */
1698 pmz_set_scc_power(uap, 0);
1699
1700 mutex_unlock(&state->port.mutex);
1701 mutex_unlock(&pmz_irq_mutex);
1702
1703 pmz_debug("suspend, switching complete\n");
1704
1705 mdev->ofdev.dev.power.power_state = pm_state;
1619 1706
1620 return 0; 1707 return 0;
1621} 1708}
@@ -1624,20 +1711,76 @@ static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state)
1624static int pmz_resume(struct macio_dev *mdev) 1711static int pmz_resume(struct macio_dev *mdev)
1625{ 1712{
1626 struct uart_pmac_port *uap = dev_get_drvdata(&mdev->ofdev.dev); 1713 struct uart_pmac_port *uap = dev_get_drvdata(&mdev->ofdev.dev);
1714 struct uart_state *state;
1715 unsigned long flags;
1716 int pwr_delay = 0;
1627 1717
1628 if (uap == NULL) 1718 if (uap == NULL)
1629 return 0; 1719 return 0;
1630 1720
1631 uart_resume_port(&pmz_uart_reg, &uap->port); 1721 if (mdev->ofdev.dev.power.power_state.event == PM_EVENT_ON)
1722 return 0;
1723
1724 pmz_debug("resume, switching to state 0\n");
1725
1726 state = pmz_uart_reg.state + uap->port.line;
1727
1728 mutex_lock(&pmz_irq_mutex);
1729 mutex_lock(&state->port.mutex);
1730
1731 spin_lock_irqsave(&uap->port.lock, flags);
1732 if (!ZS_IS_OPEN(uap) && !ZS_IS_CONS(uap)) {
1733 spin_unlock_irqrestore(&uap->port.lock, flags);
1734 goto bail;
1735 }
1736 pwr_delay = __pmz_startup(uap);
1737
1738 /* Take care of config that may have changed while asleep */
1739 __pmz_set_termios(&uap->port, &uap->termios_cache, NULL);
1740
1741 if (ZS_IS_OPEN(uap)) {
1742 /* Enable interrupts */
1743 uap->curregs[R1] |= INT_ALL_Rx | TxINT_ENAB;
1744 if (!ZS_IS_EXTCLK(uap))
1745 uap->curregs[R1] |= EXT_INT_ENAB;
1746 write_zsreg(uap, R1, uap->curregs[R1]);
1747 }
1748
1749 spin_unlock_irqrestore(&uap->port.lock, flags);
1750
1751 if (ZS_IS_CONS(uap))
1752 uap->port.cons->flags |= CON_ENABLED;
1753
1754 /* Re-enable IRQ on the controller */
1755 if (ZS_IS_OPEN(uap) && !ZS_IS_IRQ_ON(pmz_get_port_A(uap))) {
1756 pmz_get_port_A(uap)->flags |= PMACZILOG_FLAG_IS_IRQ_ON;
1757 enable_irq(uap->port.irq);
1758 }
1759
1760 bail:
1761 mutex_unlock(&state->port.mutex);
1762 mutex_unlock(&pmz_irq_mutex);
1763
1764 /* Right now, we deal with delay by blocking here, I'll be
1765 * smarter later on
1766 */
1767 if (pwr_delay != 0) {
1768 pmz_debug("pmz: delaying %d ms\n", pwr_delay);
1769 msleep(pwr_delay);
1770 }
1771
1772 pmz_debug("resume, switching complete\n");
1773
1774 mdev->ofdev.dev.power.power_state.event = PM_EVENT_ON;
1632 1775
1633 return 0; 1776 return 0;
1634} 1777}
1635 1778
1636/* 1779/*
1637 * Probe all ports in the system and build the ports array, we register 1780 * Probe all ports in the system and build the ports array, we register
1638 * with the serial layer later, so we get a proper struct device which 1781 * with the serial layer at this point, the macio-type probing is only
1639 * allows the tty to attach properly. This is later than it used to be 1782 * used later to "attach" to the sysfs tree so we get power management
1640 * but the tty layer really wants it that way. 1783 * events
1641 */ 1784 */
1642static int __init pmz_probe(void) 1785static int __init pmz_probe(void)
1643{ 1786{
@@ -1673,10 +1816,8 @@ static int __init pmz_probe(void)
1673 /* 1816 /*
1674 * Fill basic fields in the port structures 1817 * Fill basic fields in the port structures
1675 */ 1818 */
1676 if (node_b != NULL) { 1819 pmz_ports[count].mate = &pmz_ports[count+1];
1677 pmz_ports[count].mate = &pmz_ports[count+1]; 1820 pmz_ports[count+1].mate = &pmz_ports[count];
1678 pmz_ports[count+1].mate = &pmz_ports[count];
1679 }
1680 pmz_ports[count].flags = PMACZILOG_FLAG_IS_CHANNEL_A; 1821 pmz_ports[count].flags = PMACZILOG_FLAG_IS_CHANNEL_A;
1681 pmz_ports[count].node = node_a; 1822 pmz_ports[count].node = node_a;
1682 pmz_ports[count+1].node = node_b; 1823 pmz_ports[count+1].node = node_b;
@@ -1714,8 +1855,8 @@ static int __init pmz_init_port(struct uart_pmac_port *uap)
1714 struct resource *r_ports; 1855 struct resource *r_ports;
1715 int irq; 1856 int irq;
1716 1857
1717 r_ports = platform_get_resource(uap->pdev, IORESOURCE_MEM, 0); 1858 r_ports = platform_get_resource(uap->node, IORESOURCE_MEM, 0);
1718 irq = platform_get_irq(uap->pdev, 0); 1859 irq = platform_get_irq(uap->node, 0);
1719 if (!r_ports || !irq) 1860 if (!r_ports || !irq)
1720 return -ENODEV; 1861 return -ENODEV;
1721 1862
@@ -1744,19 +1885,19 @@ static int __init pmz_probe(void)
1744 1885
1745 pmz_ports_count = 0; 1886 pmz_ports_count = 0;
1746 1887
1888 pmz_ports[0].mate = &pmz_ports[1];
1747 pmz_ports[0].port.line = 0; 1889 pmz_ports[0].port.line = 0;
1748 pmz_ports[0].flags = PMACZILOG_FLAG_IS_CHANNEL_A; 1890 pmz_ports[0].flags = PMACZILOG_FLAG_IS_CHANNEL_A;
1749 pmz_ports[0].pdev = &scc_a_pdev; 1891 pmz_ports[0].node = &scc_a_pdev;
1750 err = pmz_init_port(&pmz_ports[0]); 1892 err = pmz_init_port(&pmz_ports[0]);
1751 if (err) 1893 if (err)
1752 return err; 1894 return err;
1753 pmz_ports_count++; 1895 pmz_ports_count++;
1754 1896
1755 pmz_ports[0].mate = &pmz_ports[1];
1756 pmz_ports[1].mate = &pmz_ports[0]; 1897 pmz_ports[1].mate = &pmz_ports[0];
1757 pmz_ports[1].port.line = 1; 1898 pmz_ports[1].port.line = 1;
1758 pmz_ports[1].flags = 0; 1899 pmz_ports[1].flags = 0;
1759 pmz_ports[1].pdev = &scc_b_pdev; 1900 pmz_ports[1].node = &scc_b_pdev;
1760 err = pmz_init_port(&pmz_ports[1]); 1901 err = pmz_init_port(&pmz_ports[1]);
1761 if (err) 1902 if (err)
1762 return err; 1903 return err;
@@ -1772,35 +1913,16 @@ static void pmz_dispose_port(struct uart_pmac_port *uap)
1772 1913
1773static int __init pmz_attach(struct platform_device *pdev) 1914static int __init pmz_attach(struct platform_device *pdev)
1774{ 1915{
1775 struct uart_pmac_port *uap;
1776 int i; 1916 int i;
1777 1917
1778 /* Iterate the pmz_ports array to find a matching entry */
1779 for (i = 0; i < pmz_ports_count; i++) 1918 for (i = 0; i < pmz_ports_count; i++)
1780 if (pmz_ports[i].pdev == pdev) 1919 if (pmz_ports[i].node == pdev)
1781 break; 1920 return 0;
1782 if (i >= pmz_ports_count) 1921 return -ENODEV;
1783 return -ENODEV;
1784
1785 uap = &pmz_ports[i];
1786 uap->port.dev = &pdev->dev;
1787 platform_set_drvdata(pdev, uap);
1788
1789 return uart_add_one_port(&pmz_uart_reg, &uap->port);
1790} 1922}
1791 1923
1792static int __exit pmz_detach(struct platform_device *pdev) 1924static int __exit pmz_detach(struct platform_device *pdev)
1793{ 1925{
1794 struct uart_pmac_port *uap = platform_get_drvdata(pdev);
1795
1796 if (!uap)
1797 return -ENODEV;
1798
1799 uart_remove_one_port(&pmz_uart_reg, &uap->port);
1800
1801 platform_set_drvdata(pdev, NULL);
1802 uap->port.dev = NULL;
1803
1804 return 0; 1926 return 0;
1805} 1927}
1806 1928
@@ -1832,13 +1954,38 @@ static struct console pmz_console = {
1832 */ 1954 */
1833static int __init pmz_register(void) 1955static int __init pmz_register(void)
1834{ 1956{
1957 int i, rc;
1958
1835 pmz_uart_reg.nr = pmz_ports_count; 1959 pmz_uart_reg.nr = pmz_ports_count;
1836 pmz_uart_reg.cons = PMACZILOG_CONSOLE; 1960 pmz_uart_reg.cons = PMACZILOG_CONSOLE;
1837 1961
1838 /* 1962 /*
1839 * Register this driver with the serial core 1963 * Register this driver with the serial core
1840 */ 1964 */
1841 return uart_register_driver(&pmz_uart_reg); 1965 rc = uart_register_driver(&pmz_uart_reg);
1966 if (rc)
1967 return rc;
1968
1969 /*
1970 * Register each port with the serial core
1971 */
1972 for (i = 0; i < pmz_ports_count; i++) {
1973 struct uart_pmac_port *uport = &pmz_ports[i];
1974 /* NULL node may happen on wallstreet */
1975 if (uport->node != NULL)
1976 rc = uart_add_one_port(&pmz_uart_reg, &uport->port);
1977 if (rc)
1978 goto err_out;
1979 }
1980
1981 return 0;
1982err_out:
1983 while (i-- > 0) {
1984 struct uart_pmac_port *uport = &pmz_ports[i];
1985 uart_remove_one_port(&pmz_uart_reg, &uport->port);
1986 }
1987 uart_unregister_driver(&pmz_uart_reg);
1988 return rc;
1842} 1989}
1843 1990
1844#ifdef CONFIG_PPC_PMAC 1991#ifdef CONFIG_PPC_PMAC
@@ -1937,13 +2084,10 @@ static void __exit exit_pmz(void)
1937 2084
1938 for (i = 0; i < pmz_ports_count; i++) { 2085 for (i = 0; i < pmz_ports_count; i++) {
1939 struct uart_pmac_port *uport = &pmz_ports[i]; 2086 struct uart_pmac_port *uport = &pmz_ports[i];
1940#ifdef CONFIG_PPC_PMAC 2087 if (uport->node != NULL) {
1941 if (uport->node != NULL) 2088 uart_remove_one_port(&pmz_uart_reg, &uport->port);
1942 pmz_dispose_port(uport);
1943#else
1944 if (uport->pdev != NULL)
1945 pmz_dispose_port(uport); 2089 pmz_dispose_port(uport);
1946#endif 2090 }
1947 } 2091 }
1948 /* Unregister UART driver */ 2092 /* Unregister UART driver */
1949 uart_unregister_driver(&pmz_uart_reg); 2093 uart_unregister_driver(&pmz_uart_reg);
@@ -1970,6 +2114,8 @@ static void pmz_console_write(struct console *con, const char *s, unsigned int c
1970 struct uart_pmac_port *uap = &pmz_ports[con->index]; 2114 struct uart_pmac_port *uap = &pmz_ports[con->index];
1971 unsigned long flags; 2115 unsigned long flags;
1972 2116
2117 if (ZS_IS_ASLEEP(uap))
2118 return;
1973 spin_lock_irqsave(&uap->port.lock, flags); 2119 spin_lock_irqsave(&uap->port.lock, flags);
1974 2120
1975 /* Turn of interrupts and enable the transmitter. */ 2121 /* Turn of interrupts and enable the transmitter. */
@@ -2014,13 +2160,8 @@ static int __init pmz_console_setup(struct console *co, char *options)
2014 if (co->index >= pmz_ports_count) 2160 if (co->index >= pmz_ports_count)
2015 co->index = 0; 2161 co->index = 0;
2016 uap = &pmz_ports[co->index]; 2162 uap = &pmz_ports[co->index];
2017#ifdef CONFIG_PPC_PMAC
2018 if (uap->node == NULL) 2163 if (uap->node == NULL)
2019 return -ENODEV; 2164 return -ENODEV;
2020#else
2021 if (uap->pdev == NULL)
2022 return -ENODEV;
2023#endif
2024 port = &uap->port; 2165 port = &uap->port;
2025 2166
2026 /* 2167 /*
diff --git a/drivers/tty/serial/pmac_zilog.h b/drivers/tty/serial/pmac_zilog.h
index 3483242ee3e..cbc34fbb1b2 100644
--- a/drivers/tty/serial/pmac_zilog.h
+++ b/drivers/tty/serial/pmac_zilog.h
@@ -1,6 +1,16 @@
1#ifndef __PMAC_ZILOG_H__ 1#ifndef __PMAC_ZILOG_H__
2#define __PMAC_ZILOG_H__ 2#define __PMAC_ZILOG_H__
3 3
4#ifdef CONFIG_PPC_PMAC
5#define pmz_debug(fmt, arg...) dev_dbg(&uap->dev->ofdev.dev, fmt, ## arg)
6#define pmz_error(fmt, arg...) dev_err(&uap->dev->ofdev.dev, fmt, ## arg)
7#define pmz_info(fmt, arg...) dev_info(&uap->dev->ofdev.dev, fmt, ## arg)
8#else
9#define pmz_debug(fmt, arg...) dev_dbg(&uap->node->dev, fmt, ## arg)
10#define pmz_error(fmt, arg...) dev_err(&uap->node->dev, fmt, ## arg)
11#define pmz_info(fmt, arg...) dev_info(&uap->node->dev, fmt, ## arg)
12#endif
13
4/* 14/*
5 * At most 2 ESCCs with 2 ports each 15 * At most 2 ESCCs with 2 ports each
6 */ 16 */
@@ -25,7 +35,7 @@ struct uart_pmac_port {
25 */ 35 */
26 struct device_node *node; 36 struct device_node *node;
27#else 37#else
28 struct platform_device *pdev; 38 struct platform_device *node;
29#endif 39#endif
30 40
31 /* Port type as obtained from device tree (IRDA, modem, ...) */ 41 /* Port type as obtained from device tree (IRDA, modem, ...) */
@@ -40,11 +50,14 @@ struct uart_pmac_port {
40#define PMACZILOG_FLAG_REGS_HELD 0x00000010 50#define PMACZILOG_FLAG_REGS_HELD 0x00000010
41#define PMACZILOG_FLAG_TX_STOPPED 0x00000020 51#define PMACZILOG_FLAG_TX_STOPPED 0x00000020
42#define PMACZILOG_FLAG_TX_ACTIVE 0x00000040 52#define PMACZILOG_FLAG_TX_ACTIVE 0x00000040
53#define PMACZILOG_FLAG_ENABLED 0x00000080
43#define PMACZILOG_FLAG_IS_IRDA 0x00000100 54#define PMACZILOG_FLAG_IS_IRDA 0x00000100
44#define PMACZILOG_FLAG_IS_INTMODEM 0x00000200 55#define PMACZILOG_FLAG_IS_INTMODEM 0x00000200
45#define PMACZILOG_FLAG_HAS_DMA 0x00000400 56#define PMACZILOG_FLAG_HAS_DMA 0x00000400
46#define PMACZILOG_FLAG_RSRC_REQUESTED 0x00000800 57#define PMACZILOG_FLAG_RSRC_REQUESTED 0x00000800
58#define PMACZILOG_FLAG_IS_ASLEEP 0x00001000
47#define PMACZILOG_FLAG_IS_OPEN 0x00002000 59#define PMACZILOG_FLAG_IS_OPEN 0x00002000
60#define PMACZILOG_FLAG_IS_IRQ_ON 0x00004000
48#define PMACZILOG_FLAG_IS_EXTCLK 0x00008000 61#define PMACZILOG_FLAG_IS_EXTCLK 0x00008000
49#define PMACZILOG_FLAG_BREAK 0x00010000 62#define PMACZILOG_FLAG_BREAK 0x00010000
50 63
@@ -61,8 +74,6 @@ struct uart_pmac_port {
61 volatile struct dbdma_regs __iomem *rx_dma_regs; 74 volatile struct dbdma_regs __iomem *rx_dma_regs;
62#endif 75#endif
63 76
64 unsigned char irq_name[8];
65
66 struct ktermios termios_cache; 77 struct ktermios termios_cache;
67}; 78};
68 79
@@ -377,7 +388,9 @@ static inline void zssync(struct uart_pmac_port *port)
377#define ZS_IS_IRDA(UP) ((UP)->flags & PMACZILOG_FLAG_IS_IRDA) 388#define ZS_IS_IRDA(UP) ((UP)->flags & PMACZILOG_FLAG_IS_IRDA)
378#define ZS_IS_INTMODEM(UP) ((UP)->flags & PMACZILOG_FLAG_IS_INTMODEM) 389#define ZS_IS_INTMODEM(UP) ((UP)->flags & PMACZILOG_FLAG_IS_INTMODEM)
379#define ZS_HAS_DMA(UP) ((UP)->flags & PMACZILOG_FLAG_HAS_DMA) 390#define ZS_HAS_DMA(UP) ((UP)->flags & PMACZILOG_FLAG_HAS_DMA)
391#define ZS_IS_ASLEEP(UP) ((UP)->flags & PMACZILOG_FLAG_IS_ASLEEP)
380#define ZS_IS_OPEN(UP) ((UP)->flags & PMACZILOG_FLAG_IS_OPEN) 392#define ZS_IS_OPEN(UP) ((UP)->flags & PMACZILOG_FLAG_IS_OPEN)
393#define ZS_IS_IRQ_ON(UP) ((UP)->flags & PMACZILOG_FLAG_IS_IRQ_ON)
381#define ZS_IS_EXTCLK(UP) ((UP)->flags & PMACZILOG_FLAG_IS_EXTCLK) 394#define ZS_IS_EXTCLK(UP) ((UP)->flags & PMACZILOG_FLAG_IS_EXTCLK)
382 395
383#endif /* __PMAC_ZILOG_H__ */ 396#endif /* __PMAC_ZILOG_H__ */
diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c
index 2764828251f..5c8e3bba6c8 100644
--- a/drivers/tty/serial/pxa.c
+++ b/drivers/tty/serial/pxa.c
@@ -36,7 +36,6 @@
36#include <linux/circ_buf.h> 36#include <linux/circ_buf.h>
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/interrupt.h> 38#include <linux/interrupt.h>
39#include <linux/of.h>
40#include <linux/platform_device.h> 39#include <linux/platform_device.h>
41#include <linux/tty.h> 40#include <linux/tty.h>
42#include <linux/tty_flip.h> 41#include <linux/tty_flip.h>
@@ -45,8 +44,6 @@
45#include <linux/io.h> 44#include <linux/io.h>
46#include <linux/slab.h> 45#include <linux/slab.h>
47 46
48#define PXA_NAME_LEN 8
49
50struct uart_pxa_port { 47struct uart_pxa_port {
51 struct uart_port port; 48 struct uart_port port;
52 unsigned char ier; 49 unsigned char ier;
@@ -54,7 +51,7 @@ struct uart_pxa_port {
54 unsigned char mcr; 51 unsigned char mcr;
55 unsigned int lsr_break_flag; 52 unsigned int lsr_break_flag;
56 struct clk *clk; 53 struct clk *clk;
57 char name[PXA_NAME_LEN]; 54 char *name;
58}; 55};
59 56
60static inline unsigned int serial_in(struct uart_pxa_port *up, int offset) 57static inline unsigned int serial_in(struct uart_pxa_port *up, int offset)
@@ -582,9 +579,9 @@ serial_pxa_pm(struct uart_port *port, unsigned int state,
582 struct uart_pxa_port *up = (struct uart_pxa_port *)port; 579 struct uart_pxa_port *up = (struct uart_pxa_port *)port;
583 580
584 if (!state) 581 if (!state)
585 clk_prepare_enable(up->clk); 582 clk_enable(up->clk);
586 else 583 else
587 clk_disable_unprepare(up->clk); 584 clk_disable(up->clk);
588} 585}
589 586
590static void serial_pxa_release_port(struct uart_port *port) 587static void serial_pxa_release_port(struct uart_port *port)
@@ -670,18 +667,8 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
670{ 667{
671 struct uart_pxa_port *up = serial_pxa_ports[co->index]; 668 struct uart_pxa_port *up = serial_pxa_ports[co->index];
672 unsigned int ier; 669 unsigned int ier;
673 unsigned long flags;
674 int locked = 1;
675 670
676 clk_prepare_enable(up->clk); 671 clk_enable(up->clk);
677
678 local_irq_save(flags);
679 if (up->port.sysrq)
680 locked = 0;
681 else if (oops_in_progress)
682 locked = spin_trylock(&up->port.lock);
683 else
684 spin_lock(&up->port.lock);
685 672
686 /* 673 /*
687 * First save the IER then disable the interrupts 674 * First save the IER then disable the interrupts
@@ -698,64 +685,9 @@ serial_pxa_console_write(struct console *co, const char *s, unsigned int count)
698 wait_for_xmitr(up); 685 wait_for_xmitr(up);
699 serial_out(up, UART_IER, ier); 686 serial_out(up, UART_IER, ier);
700 687
701 if (locked) 688 clk_disable(up->clk);
702 spin_unlock(&up->port.lock);
703 local_irq_restore(flags);
704
705 clk_disable_unprepare(up->clk);
706}
707
708#ifdef CONFIG_CONSOLE_POLL
709/*
710 * Console polling routines for writing and reading from the uart while
711 * in an interrupt or debug context.
712 */
713
714static int serial_pxa_get_poll_char(struct uart_port *port)
715{
716 struct uart_pxa_port *up = (struct uart_pxa_port *)port;
717 unsigned char lsr = serial_in(up, UART_LSR);
718
719 while (!(lsr & UART_LSR_DR))
720 lsr = serial_in(up, UART_LSR);
721
722 return serial_in(up, UART_RX);
723} 689}
724 690
725
726static void serial_pxa_put_poll_char(struct uart_port *port,
727 unsigned char c)
728{
729 unsigned int ier;
730 struct uart_pxa_port *up = (struct uart_pxa_port *)port;
731
732 /*
733 * First save the IER then disable the interrupts
734 */
735 ier = serial_in(up, UART_IER);
736 serial_out(up, UART_IER, UART_IER_UUE);
737
738 wait_for_xmitr(up);
739 /*
740 * Send the character out.
741 * If a LF, also do CR...
742 */
743 serial_out(up, UART_TX, c);
744 if (c == 10) {
745 wait_for_xmitr(up);
746 serial_out(up, UART_TX, 13);
747 }
748
749 /*
750 * Finally, wait for transmitter to become empty
751 * and restore the IER
752 */
753 wait_for_xmitr(up);
754 serial_out(up, UART_IER, ier);
755}
756
757#endif /* CONFIG_CONSOLE_POLL */
758
759static int __init 691static int __init
760serial_pxa_console_setup(struct console *co, char *options) 692serial_pxa_console_setup(struct console *co, char *options)
761{ 693{
@@ -810,10 +742,6 @@ struct uart_ops serial_pxa_pops = {
810 .request_port = serial_pxa_request_port, 742 .request_port = serial_pxa_request_port,
811 .config_port = serial_pxa_config_port, 743 .config_port = serial_pxa_config_port,
812 .verify_port = serial_pxa_verify_port, 744 .verify_port = serial_pxa_verify_port,
813#ifdef CONFIG_CONSOLE_POLL
814 .poll_get_char = serial_pxa_get_poll_char,
815 .poll_put_char = serial_pxa_put_poll_char,
816#endif
817}; 745};
818 746
819static struct uart_driver serial_pxa_reg = { 747static struct uart_driver serial_pxa_reg = {
@@ -853,31 +781,6 @@ static const struct dev_pm_ops serial_pxa_pm_ops = {
853}; 781};
854#endif 782#endif
855 783
856static struct of_device_id serial_pxa_dt_ids[] = {
857 { .compatible = "mrvl,pxa-uart", },
858 { .compatible = "mrvl,mmp-uart", },
859 {}
860};
861MODULE_DEVICE_TABLE(of, serial_pxa_dt_ids);
862
863static int serial_pxa_probe_dt(struct platform_device *pdev,
864 struct uart_pxa_port *sport)
865{
866 struct device_node *np = pdev->dev.of_node;
867 int ret;
868
869 if (!np)
870 return 1;
871
872 ret = of_alias_get_id(np, "serial");
873 if (ret < 0) {
874 dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
875 return ret;
876 }
877 sport->port.line = ret;
878 return 0;
879}
880
881static int serial_pxa_probe(struct platform_device *dev) 784static int serial_pxa_probe(struct platform_device *dev)
882{ 785{
883 struct uart_pxa_port *sport; 786 struct uart_pxa_port *sport;
@@ -905,16 +808,20 @@ static int serial_pxa_probe(struct platform_device *dev)
905 sport->port.irq = irqres->start; 808 sport->port.irq = irqres->start;
906 sport->port.fifosize = 64; 809 sport->port.fifosize = 64;
907 sport->port.ops = &serial_pxa_pops; 810 sport->port.ops = &serial_pxa_pops;
811 sport->port.line = dev->id;
908 sport->port.dev = &dev->dev; 812 sport->port.dev = &dev->dev;
909 sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; 813 sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
910 sport->port.uartclk = clk_get_rate(sport->clk); 814 sport->port.uartclk = clk_get_rate(sport->clk);
911 815
912 ret = serial_pxa_probe_dt(dev, sport); 816 switch (dev->id) {
913 if (ret > 0) 817 case 0: sport->name = "FFUART"; break;
914 sport->port.line = dev->id; 818 case 1: sport->name = "BTUART"; break;
915 else if (ret < 0) 819 case 2: sport->name = "STUART"; break;
916 goto err_clk; 820 case 3: sport->name = "HWUART"; break;
917 snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1); 821 default:
822 sport->name = "???";
823 break;
824 }
918 825
919 sport->port.membase = ioremap(mmres->start, resource_size(mmres)); 826 sport->port.membase = ioremap(mmres->start, resource_size(mmres));
920 if (!sport->port.membase) { 827 if (!sport->port.membase) {
@@ -922,7 +829,7 @@ static int serial_pxa_probe(struct platform_device *dev)
922 goto err_clk; 829 goto err_clk;
923 } 830 }
924 831
925 serial_pxa_ports[sport->port.line] = sport; 832 serial_pxa_ports[dev->id] = sport;
926 833
927 uart_add_one_port(&serial_pxa_reg, &sport->port); 834 uart_add_one_port(&serial_pxa_reg, &sport->port);
928 platform_set_drvdata(dev, sport); 835 platform_set_drvdata(dev, sport);
@@ -959,7 +866,6 @@ static struct platform_driver serial_pxa_driver = {
959#ifdef CONFIG_PM 866#ifdef CONFIG_PM
960 .pm = &serial_pxa_pm_ops, 867 .pm = &serial_pxa_pm_ops,
961#endif 868#endif
962 .of_match_table = serial_pxa_dt_ids,
963 }, 869 },
964}; 870};
965 871
diff --git a/drivers/tty/serial/sa1100.c b/drivers/tty/serial/sa1100.c
index 5d4b9b449b4..ef7a21a6a01 100644
--- a/drivers/tty/serial/sa1100.c
+++ b/drivers/tty/serial/sa1100.c
@@ -29,7 +29,6 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/console.h> 30#include <linux/console.h>
31#include <linux/sysrq.h> 31#include <linux/sysrq.h>
32#include <linux/platform_data/sa11x0-serial.h>
33#include <linux/platform_device.h> 32#include <linux/platform_device.h>
34#include <linux/tty.h> 33#include <linux/tty.h>
35#include <linux/tty_flip.h> 34#include <linux/tty_flip.h>
@@ -39,7 +38,7 @@
39 38
40#include <asm/irq.h> 39#include <asm/irq.h>
41#include <mach/hardware.h> 40#include <mach/hardware.h>
42#include <mach/irqs.h> 41#include <asm/mach/serial_sa1100.h>
43 42
44/* We've been assigned a range on the "Low-density serial ports" major */ 43/* We've been assigned a range on the "Low-density serial ports" major */
45#define SERIAL_SA1100_MAJOR 204 44#define SERIAL_SA1100_MAJOR 204
@@ -637,7 +636,7 @@ static void __init sa1100_init_ports(void)
637 PPSR |= PPC_TXD1 | PPC_TXD3; 636 PPSR |= PPC_TXD1 | PPC_TXD3;
638} 637}
639 638
640void sa1100_register_uart_fns(struct sa1100_port_fns *fns) 639void __devinit sa1100_register_uart_fns(struct sa1100_port_fns *fns)
641{ 640{
642 if (fns->get_mctrl) 641 if (fns->get_mctrl)
643 sa1100_pops.get_mctrl = fns->get_mctrl; 642 sa1100_pops.get_mctrl = fns->get_mctrl;
diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index 12e5249d053..6edafb5ace1 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -42,7 +42,6 @@
42#include <linux/delay.h> 42#include <linux/delay.h>
43#include <linux/clk.h> 43#include <linux/clk.h>
44#include <linux/cpufreq.h> 44#include <linux/cpufreq.h>
45#include <linux/of.h>
46 45
47#include <asm/irq.h> 46#include <asm/irq.h>
48 47
@@ -50,7 +49,6 @@
50#include <mach/map.h> 49#include <mach/map.h>
51 50
52#include <plat/regs-serial.h> 51#include <plat/regs-serial.h>
53#include <plat/clock.h>
54 52
55#include "samsung.h" 53#include "samsung.h"
56 54
@@ -82,17 +80,7 @@ static inline const char *s3c24xx_serial_portname(struct uart_port *port)
82 80
83static int s3c24xx_serial_txempty_nofifo(struct uart_port *port) 81static int s3c24xx_serial_txempty_nofifo(struct uart_port *port)
84{ 82{
85 return rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE; 83 return (rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE);
86}
87
88/*
89 * s3c64xx and later SoC's include the interrupt mask and status registers in
90 * the controller itself, unlike the s3c24xx SoC's which have these registers
91 * in the interrupt controller. Check if the port type is s3c64xx or higher.
92 */
93static int s3c24xx_serial_has_interrupt_mask(struct uart_port *port)
94{
95 return to_ourport(port)->info->type == PORT_S3C6400;
96} 84}
97 85
98static void s3c24xx_serial_rx_enable(struct uart_port *port) 86static void s3c24xx_serial_rx_enable(struct uart_port *port)
@@ -138,11 +126,7 @@ static void s3c24xx_serial_stop_tx(struct uart_port *port)
138 struct s3c24xx_uart_port *ourport = to_ourport(port); 126 struct s3c24xx_uart_port *ourport = to_ourport(port);
139 127
140 if (tx_enabled(port)) { 128 if (tx_enabled(port)) {
141 if (s3c24xx_serial_has_interrupt_mask(port)) 129 disable_irq_nosync(ourport->tx_irq);
142 __set_bit(S3C64XX_UINTM_TXD,
143 portaddrl(port, S3C64XX_UINTM));
144 else
145 disable_irq_nosync(ourport->tx_irq);
146 tx_enabled(port) = 0; 130 tx_enabled(port) = 0;
147 if (port->flags & UPF_CONS_FLOW) 131 if (port->flags & UPF_CONS_FLOW)
148 s3c24xx_serial_rx_enable(port); 132 s3c24xx_serial_rx_enable(port);
@@ -157,26 +141,19 @@ static void s3c24xx_serial_start_tx(struct uart_port *port)
157 if (port->flags & UPF_CONS_FLOW) 141 if (port->flags & UPF_CONS_FLOW)
158 s3c24xx_serial_rx_disable(port); 142 s3c24xx_serial_rx_disable(port);
159 143
160 if (s3c24xx_serial_has_interrupt_mask(port)) 144 enable_irq(ourport->tx_irq);
161 __clear_bit(S3C64XX_UINTM_TXD,
162 portaddrl(port, S3C64XX_UINTM));
163 else
164 enable_irq(ourport->tx_irq);
165 tx_enabled(port) = 1; 145 tx_enabled(port) = 1;
166 } 146 }
167} 147}
168 148
149
169static void s3c24xx_serial_stop_rx(struct uart_port *port) 150static void s3c24xx_serial_stop_rx(struct uart_port *port)
170{ 151{
171 struct s3c24xx_uart_port *ourport = to_ourport(port); 152 struct s3c24xx_uart_port *ourport = to_ourport(port);
172 153
173 if (rx_enabled(port)) { 154 if (rx_enabled(port)) {
174 dbg("s3c24xx_serial_stop_rx: port=%p\n", port); 155 dbg("s3c24xx_serial_stop_rx: port=%p\n", port);
175 if (s3c24xx_serial_has_interrupt_mask(port)) 156 disable_irq_nosync(ourport->rx_irq);
176 __set_bit(S3C64XX_UINTM_RXD,
177 portaddrl(port, S3C64XX_UINTM));
178 else
179 disable_irq_nosync(ourport->rx_irq);
180 rx_enabled(port) = 0; 157 rx_enabled(port) = 0;
181 } 158 }
182} 159}
@@ -192,13 +169,10 @@ static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *p
192 169
193static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port) 170static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port)
194{ 171{
195 struct s3c24xx_uart_port *ourport;
196
197 if (port->dev == NULL) 172 if (port->dev == NULL)
198 return NULL; 173 return NULL;
199 174
200 ourport = container_of(port, struct s3c24xx_uart_port, port); 175 return (struct s3c2410_uartcfg *)port->dev->platform_data;
201 return ourport->cfg;
202} 176}
203 177
204static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport, 178static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
@@ -207,7 +181,7 @@ static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
207 struct s3c24xx_uart_info *info = ourport->info; 181 struct s3c24xx_uart_info *info = ourport->info;
208 182
209 if (ufstat & info->rx_fifofull) 183 if (ufstat & info->rx_fifofull)
210 return ourport->port.fifosize; 184 return info->fifosize;
211 185
212 return (ufstat & info->rx_fifomask) >> info->rx_fifoshift; 186 return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
213} 187}
@@ -223,11 +197,8 @@ s3c24xx_serial_rx_chars(int irq, void *dev_id)
223 struct uart_port *port = &ourport->port; 197 struct uart_port *port = &ourport->port;
224 struct tty_struct *tty = port->state->port.tty; 198 struct tty_struct *tty = port->state->port.tty;
225 unsigned int ufcon, ch, flag, ufstat, uerstat; 199 unsigned int ufcon, ch, flag, ufstat, uerstat;
226 unsigned long flags;
227 int max_count = 64; 200 int max_count = 64;
228 201
229 spin_lock_irqsave(&port->lock, flags);
230
231 while (max_count-- > 0) { 202 while (max_count-- > 0) {
232 ufcon = rd_regl(port, S3C2410_UFCON); 203 ufcon = rd_regl(port, S3C2410_UFCON);
233 ufstat = rd_regl(port, S3C2410_UFSTAT); 204 ufstat = rd_regl(port, S3C2410_UFSTAT);
@@ -271,7 +242,7 @@ s3c24xx_serial_rx_chars(int irq, void *dev_id)
271 dbg("break!\n"); 242 dbg("break!\n");
272 port->icount.brk++; 243 port->icount.brk++;
273 if (uart_handle_break(port)) 244 if (uart_handle_break(port))
274 goto ignore_char; 245 goto ignore_char;
275 } 246 }
276 247
277 if (uerstat & S3C2410_UERSTAT_FRAME) 248 if (uerstat & S3C2410_UERSTAT_FRAME)
@@ -302,7 +273,6 @@ s3c24xx_serial_rx_chars(int irq, void *dev_id)
302 tty_flip_buffer_push(tty); 273 tty_flip_buffer_push(tty);
303 274
304 out: 275 out:
305 spin_unlock_irqrestore(&port->lock, flags);
306 return IRQ_HANDLED; 276 return IRQ_HANDLED;
307} 277}
308 278
@@ -311,11 +281,8 @@ static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
311 struct s3c24xx_uart_port *ourport = id; 281 struct s3c24xx_uart_port *ourport = id;
312 struct uart_port *port = &ourport->port; 282 struct uart_port *port = &ourport->port;
313 struct circ_buf *xmit = &port->state->xmit; 283 struct circ_buf *xmit = &port->state->xmit;
314 unsigned long flags;
315 int count = 256; 284 int count = 256;
316 285
317 spin_lock_irqsave(&port->lock, flags);
318
319 if (port->x_char) { 286 if (port->x_char) {
320 wr_regb(port, S3C2410_UTXH, port->x_char); 287 wr_regb(port, S3C2410_UTXH, port->x_char);
321 port->icount.tx++; 288 port->icount.tx++;
@@ -343,39 +310,16 @@ static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
343 port->icount.tx++; 310 port->icount.tx++;
344 } 311 }
345 312
346 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) { 313 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
347 spin_unlock(&port->lock);
348 uart_write_wakeup(port); 314 uart_write_wakeup(port);
349 spin_lock(&port->lock);
350 }
351 315
352 if (uart_circ_empty(xmit)) 316 if (uart_circ_empty(xmit))
353 s3c24xx_serial_stop_tx(port); 317 s3c24xx_serial_stop_tx(port);
354 318
355 out: 319 out:
356 spin_unlock_irqrestore(&port->lock, flags);
357 return IRQ_HANDLED; 320 return IRQ_HANDLED;
358} 321}
359 322
360/* interrupt handler for s3c64xx and later SoC's.*/
361static irqreturn_t s3c64xx_serial_handle_irq(int irq, void *id)
362{
363 struct s3c24xx_uart_port *ourport = id;
364 struct uart_port *port = &ourport->port;
365 unsigned int pend = rd_regl(port, S3C64XX_UINTP);
366 irqreturn_t ret = IRQ_HANDLED;
367
368 if (pend & S3C64XX_UINTM_RXD_MSK) {
369 ret = s3c24xx_serial_rx_chars(irq, id);
370 wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_RXD_MSK);
371 }
372 if (pend & S3C64XX_UINTM_TXD_MSK) {
373 ret = s3c24xx_serial_tx_chars(irq, id);
374 wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_TXD_MSK);
375 }
376 return ret;
377}
378
379static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port) 323static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
380{ 324{
381 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 325 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
@@ -433,26 +377,19 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
433 struct s3c24xx_uart_port *ourport = to_ourport(port); 377 struct s3c24xx_uart_port *ourport = to_ourport(port);
434 378
435 if (ourport->tx_claimed) { 379 if (ourport->tx_claimed) {
436 if (!s3c24xx_serial_has_interrupt_mask(port)) 380 free_irq(ourport->tx_irq, ourport);
437 free_irq(ourport->tx_irq, ourport);
438 tx_enabled(port) = 0; 381 tx_enabled(port) = 0;
439 ourport->tx_claimed = 0; 382 ourport->tx_claimed = 0;
440 } 383 }
441 384
442 if (ourport->rx_claimed) { 385 if (ourport->rx_claimed) {
443 if (!s3c24xx_serial_has_interrupt_mask(port)) 386 free_irq(ourport->rx_irq, ourport);
444 free_irq(ourport->rx_irq, ourport);
445 ourport->rx_claimed = 0; 387 ourport->rx_claimed = 0;
446 rx_enabled(port) = 0; 388 rx_enabled(port) = 0;
447 } 389 }
448
449 /* Clear pending interrupts and mask all interrupts */
450 if (s3c24xx_serial_has_interrupt_mask(port)) {
451 wr_regl(port, S3C64XX_UINTP, 0xf);
452 wr_regl(port, S3C64XX_UINTM, 0xf);
453 }
454} 390}
455 391
392
456static int s3c24xx_serial_startup(struct uart_port *port) 393static int s3c24xx_serial_startup(struct uart_port *port)
457{ 394{
458 struct s3c24xx_uart_port *ourport = to_ourport(port); 395 struct s3c24xx_uart_port *ourport = to_ourport(port);
@@ -467,7 +404,7 @@ static int s3c24xx_serial_startup(struct uart_port *port)
467 s3c24xx_serial_portname(port), ourport); 404 s3c24xx_serial_portname(port), ourport);
468 405
469 if (ret != 0) { 406 if (ret != 0) {
470 dev_err(port->dev, "cannot get irq %d\n", ourport->rx_irq); 407 printk(KERN_ERR "cannot get irq %d\n", ourport->rx_irq);
471 return ret; 408 return ret;
472 } 409 }
473 410
@@ -481,7 +418,7 @@ static int s3c24xx_serial_startup(struct uart_port *port)
481 s3c24xx_serial_portname(port), ourport); 418 s3c24xx_serial_portname(port), ourport);
482 419
483 if (ret) { 420 if (ret) {
484 dev_err(port->dev, "cannot get irq %d\n", ourport->tx_irq); 421 printk(KERN_ERR "cannot get irq %d\n", ourport->tx_irq);
485 goto err; 422 goto err;
486 } 423 }
487 424
@@ -499,33 +436,6 @@ static int s3c24xx_serial_startup(struct uart_port *port)
499 return ret; 436 return ret;
500} 437}
501 438
502static int s3c64xx_serial_startup(struct uart_port *port)
503{
504 struct s3c24xx_uart_port *ourport = to_ourport(port);
505 int ret;
506
507 dbg("s3c64xx_serial_startup: port=%p (%08lx,%p)\n",
508 port->mapbase, port->membase);
509
510 ret = request_irq(port->irq, s3c64xx_serial_handle_irq, IRQF_SHARED,
511 s3c24xx_serial_portname(port), ourport);
512 if (ret) {
513 dev_err(port->dev, "cannot get irq %d\n", port->irq);
514 return ret;
515 }
516
517 /* For compatibility with s3c24xx Soc's */
518 rx_enabled(port) = 1;
519 ourport->rx_claimed = 1;
520 tx_enabled(port) = 0;
521 ourport->tx_claimed = 1;
522
523 /* Enable Rx Interrupt */
524 __clear_bit(S3C64XX_UINTM_RXD, portaddrl(port, S3C64XX_UINTM));
525 dbg("s3c64xx_serial_startup ok\n");
526 return ret;
527}
528
529/* power power management control */ 439/* power power management control */
530 440
531static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level, 441static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
@@ -537,21 +447,21 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
537 447
538 switch (level) { 448 switch (level) {
539 case 3: 449 case 3:
540 if (!IS_ERR(ourport->baudclk)) 450 if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
541 clk_disable_unprepare(ourport->baudclk); 451 clk_disable(ourport->baudclk);
542 452
543 clk_disable_unprepare(ourport->clk); 453 clk_disable(ourport->clk);
544 break; 454 break;
545 455
546 case 0: 456 case 0:
547 clk_prepare_enable(ourport->clk); 457 clk_enable(ourport->clk);
548 458
549 if (!IS_ERR(ourport->baudclk)) 459 if (!IS_ERR(ourport->baudclk) && ourport->baudclk != NULL)
550 clk_prepare_enable(ourport->baudclk); 460 clk_enable(ourport->baudclk);
551 461
552 break; 462 break;
553 default: 463 default:
554 dev_err(port->dev, "s3c24xx_serial: unknown pm %d\n", level); 464 printk(KERN_ERR "s3c24xx_serial: unknown pm %d\n", level);
555 } 465 }
556} 466}
557 467
@@ -568,97 +478,154 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
568 * 478 *
569*/ 479*/
570 480
571#define MAX_CLK_NAME_LENGTH 15
572 481
573static inline int s3c24xx_serial_getsource(struct uart_port *port) 482#define MAX_CLKS (8)
483
484static struct s3c24xx_uart_clksrc tmp_clksrc = {
485 .name = "pclk",
486 .min_baud = 0,
487 .max_baud = 0,
488 .divisor = 1,
489};
490
491static inline int
492s3c24xx_serial_getsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
574{ 493{
575 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 494 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
576 unsigned int ucon;
577
578 if (info->num_clks == 1)
579 return 0;
580 495
581 ucon = rd_regl(port, S3C2410_UCON); 496 return (info->get_clksrc)(port, c);
582 ucon &= info->clksel_mask;
583 return ucon >> info->clksel_shift;
584} 497}
585 498
586static void s3c24xx_serial_setsource(struct uart_port *port, 499static inline int
587 unsigned int clk_sel) 500s3c24xx_serial_setsource(struct uart_port *port, struct s3c24xx_uart_clksrc *c)
588{ 501{
589 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 502 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
590 unsigned int ucon;
591 503
592 if (info->num_clks == 1) 504 return (info->set_clksrc)(port, c);
593 return; 505}
594 506
595 ucon = rd_regl(port, S3C2410_UCON); 507struct baud_calc {
596 if ((ucon & info->clksel_mask) >> info->clksel_shift == clk_sel) 508 struct s3c24xx_uart_clksrc *clksrc;
597 return; 509 unsigned int calc;
510 unsigned int divslot;
511 unsigned int quot;
512 struct clk *src;
513};
598 514
599 ucon &= ~info->clksel_mask; 515static int s3c24xx_serial_calcbaud(struct baud_calc *calc,
600 ucon |= clk_sel << info->clksel_shift; 516 struct uart_port *port,
601 wr_regl(port, S3C2410_UCON, ucon); 517 struct s3c24xx_uart_clksrc *clksrc,
518 unsigned int baud)
519{
520 struct s3c24xx_uart_port *ourport = to_ourport(port);
521 unsigned long rate;
522
523 calc->src = clk_get(port->dev, clksrc->name);
524 if (calc->src == NULL || IS_ERR(calc->src))
525 return 0;
526
527 rate = clk_get_rate(calc->src);
528 rate /= clksrc->divisor;
529
530 calc->clksrc = clksrc;
531
532 if (ourport->info->has_divslot) {
533 unsigned long div = rate / baud;
534
535 /* The UDIVSLOT register on the newer UARTs allows us to
536 * get a divisor adjustment of 1/16th on the baud clock.
537 *
538 * We don't keep the UDIVSLOT value (the 16ths we calculated
539 * by not multiplying the baud by 16) as it is easy enough
540 * to recalculate.
541 */
542
543 calc->quot = div / 16;
544 calc->calc = rate / div;
545 } else {
546 calc->quot = (rate + (8 * baud)) / (16 * baud);
547 calc->calc = (rate / (calc->quot * 16));
548 }
549
550 calc->quot--;
551 return 1;
602} 552}
603 553
604static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport, 554static unsigned int s3c24xx_serial_getclk(struct uart_port *port,
605 unsigned int req_baud, struct clk **best_clk, 555 struct s3c24xx_uart_clksrc **clksrc,
606 unsigned int *clk_num) 556 struct clk **clk,
557 unsigned int baud)
607{ 558{
608 struct s3c24xx_uart_info *info = ourport->info; 559 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
609 struct clk *clk; 560 struct s3c24xx_uart_clksrc *clkp;
610 unsigned long rate; 561 struct baud_calc res[MAX_CLKS];
611 unsigned int cnt, baud, quot, clk_sel, best_quot = 0; 562 struct baud_calc *resptr, *best, *sptr;
612 char clkname[MAX_CLK_NAME_LENGTH]; 563 int i;
613 int calc_deviation, deviation = (1 << 30) - 1; 564
614 565 clkp = cfg->clocks;
615 clk_sel = (ourport->cfg->clk_sel) ? ourport->cfg->clk_sel : 566 best = NULL;
616 ourport->info->def_clk_sel; 567
617 for (cnt = 0; cnt < info->num_clks; cnt++) { 568 if (cfg->clocks_size < 2) {
618 if (!(clk_sel & (1 << cnt))) 569 if (cfg->clocks_size == 0)
619 continue; 570 clkp = &tmp_clksrc;
620 571
621 sprintf(clkname, "clk_uart_baud%d", cnt); 572 /* check to see if we're sourcing fclk, and if so we're
622 clk = clk_get(ourport->port.dev, clkname); 573 * going to have to update the clock source
623 if (IS_ERR(clk)) 574 */
624 continue; 575
625 576 if (strcmp(clkp->name, "fclk") == 0) {
626 rate = clk_get_rate(clk); 577 struct s3c24xx_uart_clksrc src;
627 if (!rate) 578
628 continue; 579 s3c24xx_serial_getsource(port, &src);
629 580
630 if (ourport->info->has_divslot) { 581 /* check that the port already using fclk, and if
631 unsigned long div = rate / req_baud; 582 * not, then re-select fclk
632
633 /* The UDIVSLOT register on the newer UARTs allows us to
634 * get a divisor adjustment of 1/16th on the baud clock.
635 *
636 * We don't keep the UDIVSLOT value (the 16ths we
637 * calculated by not multiplying the baud by 16) as it
638 * is easy enough to recalculate.
639 */ 583 */
640 584
641 quot = div / 16; 585 if (strcmp(src.name, clkp->name) == 0) {
642 baud = rate / div; 586 s3c24xx_serial_setsource(port, clkp);
643 } else { 587 s3c24xx_serial_getsource(port, &src);
644 quot = (rate + (8 * req_baud)) / (16 * req_baud); 588 }
645 baud = rate / (quot * 16); 589
590 clkp->divisor = src.divisor;
591 }
592
593 s3c24xx_serial_calcbaud(res, port, clkp, baud);
594 best = res;
595 resptr = best + 1;
596 } else {
597 resptr = res;
598
599 for (i = 0; i < cfg->clocks_size; i++, clkp++) {
600 if (s3c24xx_serial_calcbaud(resptr, port, clkp, baud))
601 resptr++;
646 } 602 }
647 quot--; 603 }
604
605 /* ok, we now need to select the best clock we found */
648 606
649 calc_deviation = req_baud - baud; 607 if (!best) {
650 if (calc_deviation < 0) 608 unsigned int deviation = (1<<30)|((1<<30)-1);
651 calc_deviation = -calc_deviation; 609 int calc_deviation;
652 610
653 if (calc_deviation < deviation) { 611 for (sptr = res; sptr < resptr; sptr++) {
654 *best_clk = clk; 612 calc_deviation = baud - sptr->calc;
655 best_quot = quot; 613 if (calc_deviation < 0)
656 *clk_num = cnt; 614 calc_deviation = -calc_deviation;
657 deviation = calc_deviation; 615
616 if (calc_deviation < deviation) {
617 best = sptr;
618 deviation = calc_deviation;
619 }
658 } 620 }
659 } 621 }
660 622
661 return best_quot; 623 /* store results to pass back */
624
625 *clksrc = best->clksrc;
626 *clk = best->src;
627
628 return best->quot;
662} 629}
663 630
664/* udivslot_table[] 631/* udivslot_table[]
@@ -691,9 +658,10 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,
691{ 658{
692 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port); 659 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
693 struct s3c24xx_uart_port *ourport = to_ourport(port); 660 struct s3c24xx_uart_port *ourport = to_ourport(port);
694 struct clk *clk = ERR_PTR(-EINVAL); 661 struct s3c24xx_uart_clksrc *clksrc = NULL;
662 struct clk *clk = NULL;
695 unsigned long flags; 663 unsigned long flags;
696 unsigned int baud, quot, clk_sel = 0; 664 unsigned int baud, quot;
697 unsigned int ulcon; 665 unsigned int ulcon;
698 unsigned int umcon; 666 unsigned int umcon;
699 unsigned int udivslot = 0; 667 unsigned int udivslot = 0;
@@ -709,24 +677,26 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,
709 */ 677 */
710 678
711 baud = uart_get_baud_rate(port, termios, old, 0, 115200*8); 679 baud = uart_get_baud_rate(port, termios, old, 0, 115200*8);
712 quot = s3c24xx_serial_getclk(ourport, baud, &clk, &clk_sel); 680
713 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) 681 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
714 quot = port->custom_divisor; 682 quot = port->custom_divisor;
715 if (IS_ERR(clk)) 683 else
716 return; 684 quot = s3c24xx_serial_getclk(port, &clksrc, &clk, baud);
717 685
718 /* check to see if we need to change clock source */ 686 /* check to see if we need to change clock source */
719 687
720 if (ourport->baudclk != clk) { 688 if (ourport->clksrc != clksrc || ourport->baudclk != clk) {
721 s3c24xx_serial_setsource(port, clk_sel); 689 dbg("selecting clock %p\n", clk);
690 s3c24xx_serial_setsource(port, clksrc);
722 691
723 if (!IS_ERR(ourport->baudclk)) { 692 if (ourport->baudclk != NULL && !IS_ERR(ourport->baudclk)) {
724 clk_disable_unprepare(ourport->baudclk); 693 clk_disable(ourport->baudclk);
725 ourport->baudclk = ERR_PTR(-EINVAL); 694 ourport->baudclk = NULL;
726 } 695 }
727 696
728 clk_prepare_enable(clk); 697 clk_enable(clk);
729 698
699 ourport->clksrc = clksrc;
730 ourport->baudclk = clk; 700 ourport->baudclk = clk;
731 ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0; 701 ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
732 } 702 }
@@ -884,24 +854,11 @@ s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
884 854
885static struct console s3c24xx_serial_console; 855static struct console s3c24xx_serial_console;
886 856
887static int __init s3c24xx_serial_console_init(void)
888{
889 register_console(&s3c24xx_serial_console);
890 return 0;
891}
892console_initcall(s3c24xx_serial_console_init);
893
894#define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console 857#define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
895#else 858#else
896#define S3C24XX_SERIAL_CONSOLE NULL 859#define S3C24XX_SERIAL_CONSOLE NULL
897#endif 860#endif
898 861
899#ifdef CONFIG_CONSOLE_POLL
900static int s3c24xx_serial_get_poll_char(struct uart_port *port);
901static void s3c24xx_serial_put_poll_char(struct uart_port *port,
902 unsigned char c);
903#endif
904
905static struct uart_ops s3c24xx_serial_ops = { 862static struct uart_ops s3c24xx_serial_ops = {
906 .pm = s3c24xx_serial_pm, 863 .pm = s3c24xx_serial_pm,
907 .tx_empty = s3c24xx_serial_tx_empty, 864 .tx_empty = s3c24xx_serial_tx_empty,
@@ -920,12 +877,9 @@ static struct uart_ops s3c24xx_serial_ops = {
920 .request_port = s3c24xx_serial_request_port, 877 .request_port = s3c24xx_serial_request_port,
921 .config_port = s3c24xx_serial_config_port, 878 .config_port = s3c24xx_serial_config_port,
922 .verify_port = s3c24xx_serial_verify_port, 879 .verify_port = s3c24xx_serial_verify_port,
923#ifdef CONFIG_CONSOLE_POLL
924 .poll_get_char = s3c24xx_serial_get_poll_char,
925 .poll_put_char = s3c24xx_serial_put_poll_char,
926#endif
927}; 880};
928 881
882
929static struct uart_driver s3c24xx_uart_drv = { 883static struct uart_driver s3c24xx_uart_drv = {
930 .owner = THIS_MODULE, 884 .owner = THIS_MODULE,
931 .driver_name = "s3c2410_serial", 885 .driver_name = "s3c2410_serial",
@@ -941,6 +895,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
941 .port = { 895 .port = {
942 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock), 896 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
943 .iotype = UPIO_MEM, 897 .iotype = UPIO_MEM,
898 .irq = IRQ_S3CUART_RX0,
944 .uartclk = 0, 899 .uartclk = 0,
945 .fifosize = 16, 900 .fifosize = 16,
946 .ops = &s3c24xx_serial_ops, 901 .ops = &s3c24xx_serial_ops,
@@ -952,6 +907,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
952 .port = { 907 .port = {
953 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock), 908 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
954 .iotype = UPIO_MEM, 909 .iotype = UPIO_MEM,
910 .irq = IRQ_S3CUART_RX1,
955 .uartclk = 0, 911 .uartclk = 0,
956 .fifosize = 16, 912 .fifosize = 16,
957 .ops = &s3c24xx_serial_ops, 913 .ops = &s3c24xx_serial_ops,
@@ -965,6 +921,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
965 .port = { 921 .port = {
966 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock), 922 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
967 .iotype = UPIO_MEM, 923 .iotype = UPIO_MEM,
924 .irq = IRQ_S3CUART_RX2,
968 .uartclk = 0, 925 .uartclk = 0,
969 .fifosize = 16, 926 .fifosize = 16,
970 .ops = &s3c24xx_serial_ops, 927 .ops = &s3c24xx_serial_ops,
@@ -978,6 +935,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
978 .port = { 935 .port = {
979 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[3].port.lock), 936 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[3].port.lock),
980 .iotype = UPIO_MEM, 937 .iotype = UPIO_MEM,
938 .irq = IRQ_S3CUART_RX3,
981 .uartclk = 0, 939 .uartclk = 0,
982 .fifosize = 16, 940 .fifosize = 16,
983 .ops = &s3c24xx_serial_ops, 941 .ops = &s3c24xx_serial_ops,
@@ -990,30 +948,16 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS
990 948
991/* s3c24xx_serial_resetport 949/* s3c24xx_serial_resetport
992 * 950 *
993 * reset the fifos and other the settings. 951 * wrapper to call the specific reset for this port (reset the fifos
952 * and the settings)
994*/ 953*/
995 954
996static void s3c24xx_serial_resetport(struct uart_port *port, 955static inline int s3c24xx_serial_resetport(struct uart_port *port,
997 struct s3c2410_uartcfg *cfg) 956 struct s3c2410_uartcfg *cfg)
998{ 957{
999 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port); 958 struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
1000 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1001 unsigned int ucon_mask;
1002
1003 ucon_mask = info->clksel_mask;
1004 if (info->type == PORT_S3C2440)
1005 ucon_mask |= S3C2440_UCON0_DIVMASK;
1006 959
1007 ucon &= ucon_mask; 960 return (info->reset_port)(port, cfg);
1008 wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
1009 wr_regl(port, S3C2410_ULCON, cfg->ulcon);
1010
1011 /* reset both fifos */
1012 wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
1013 wr_regl(port, S3C2410_UFCON, cfg->ufcon);
1014
1015 /* some delay is required after fifo reset */
1016 udelay(1);
1017} 961}
1018 962
1019 963
@@ -1038,10 +982,10 @@ static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb,
1038 * a disturbance in the clock-rate over the change. 982 * a disturbance in the clock-rate over the change.
1039 */ 983 */
1040 984
1041 if (IS_ERR(port->baudclk)) 985 if (IS_ERR(port->clk))
1042 goto exit; 986 goto exit;
1043 987
1044 if (port->baudclk_rate == clk_get_rate(port->baudclk)) 988 if (port->baudclk_rate == clk_get_rate(port->clk))
1045 goto exit; 989 goto exit;
1046 990
1047 if (val == CPUFREQ_PRECHANGE) { 991 if (val == CPUFREQ_PRECHANGE) {
@@ -1060,10 +1004,10 @@ static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb,
1060 if (tty == NULL) 1004 if (tty == NULL)
1061 goto exit; 1005 goto exit;
1062 1006
1063 termios = &tty->termios; 1007 termios = tty->termios;
1064 1008
1065 if (termios == NULL) { 1009 if (termios == NULL) {
1066 dev_warn(uport->dev, "%s: no termios?\n", __func__); 1010 printk(KERN_WARNING "%s: no termios?\n", __func__);
1067 goto exit; 1011 goto exit;
1068 } 1012 }
1069 1013
@@ -1105,10 +1049,11 @@ static inline void s3c24xx_serial_cpufreq_deregister(struct s3c24xx_uart_port *p
1105 */ 1049 */
1106 1050
1107static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, 1051static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1052 struct s3c24xx_uart_info *info,
1108 struct platform_device *platdev) 1053 struct platform_device *platdev)
1109{ 1054{
1110 struct uart_port *port = &ourport->port; 1055 struct uart_port *port = &ourport->port;
1111 struct s3c2410_uartcfg *cfg = ourport->cfg; 1056 struct s3c2410_uartcfg *cfg;
1112 struct resource *res; 1057 struct resource *res;
1113 int ret; 1058 int ret;
1114 1059
@@ -1117,15 +1062,25 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1117 if (platdev == NULL) 1062 if (platdev == NULL)
1118 return -ENODEV; 1063 return -ENODEV;
1119 1064
1065 cfg = s3c24xx_dev_to_cfg(&platdev->dev);
1066
1120 if (port->mapbase != 0) 1067 if (port->mapbase != 0)
1121 return 0; 1068 return 0;
1122 1069
1070 if (cfg->hwport > CONFIG_SERIAL_SAMSUNG_UARTS) {
1071 printk(KERN_ERR "%s: port %d bigger than %d\n", __func__,
1072 cfg->hwport, CONFIG_SERIAL_SAMSUNG_UARTS);
1073 return -ERANGE;
1074 }
1075
1123 /* setup info for port */ 1076 /* setup info for port */
1124 port->dev = &platdev->dev; 1077 port->dev = &platdev->dev;
1078 ourport->info = info;
1079
1080 /* copy the info in from provided structure */
1081 ourport->port.fifosize = info->fifosize;
1125 1082
1126 /* Startup sequence is different for s3c64xx and higher SoC's */ 1083 dbg("s3c24xx_serial_init_port: %p (hw %d)...\n", port, cfg->hwport);
1127 if (s3c24xx_serial_has_interrupt_mask(port))
1128 s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
1129 1084
1130 port->uartclk = 1; 1085 port->uartclk = 1;
1131 1086
@@ -1138,7 +1093,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1138 1093
1139 res = platform_get_resource(platdev, IORESOURCE_MEM, 0); 1094 res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
1140 if (res == NULL) { 1095 if (res == NULL) {
1141 dev_err(port->dev, "failed to find memory resource for uart\n"); 1096 printk(KERN_ERR "failed to find memory resource for uart\n");
1142 return -EINVAL; 1097 return -EINVAL;
1143 } 1098 }
1144 1099
@@ -1154,20 +1109,13 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1154 ourport->rx_irq = ret; 1109 ourport->rx_irq = ret;
1155 ourport->tx_irq = ret + 1; 1110 ourport->tx_irq = ret + 1;
1156 } 1111 }
1157 1112
1158 ret = platform_get_irq(platdev, 1); 1113 ret = platform_get_irq(platdev, 1);
1159 if (ret > 0) 1114 if (ret > 0)
1160 ourport->tx_irq = ret; 1115 ourport->tx_irq = ret;
1161 1116
1162 ourport->clk = clk_get(&platdev->dev, "uart"); 1117 ourport->clk = clk_get(&platdev->dev, "uart");
1163 1118
1164 /* Keep all interrupts masked and cleared */
1165 if (s3c24xx_serial_has_interrupt_mask(port)) {
1166 wr_regl(port, S3C64XX_UINTM, 0xf);
1167 wr_regl(port, S3C64XX_UINTP, 0xf);
1168 wr_regl(port, S3C64XX_UINTSP, 0xf);
1169 }
1170
1171 dbg("port: map=%08x, mem=%08x, irq=%d (%d,%d), clock=%ld\n", 1119 dbg("port: map=%08x, mem=%08x, irq=%d (%d,%d), clock=%ld\n",
1172 port->mapbase, port->membase, port->irq, 1120 port->mapbase, port->membase, port->irq,
1173 ourport->rx_irq, ourport->tx_irq, port->uartclk); 1121 ourport->rx_irq, ourport->tx_irq, port->uartclk);
@@ -1184,79 +1132,43 @@ static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
1184 struct uart_port *port = s3c24xx_dev_to_port(dev); 1132 struct uart_port *port = s3c24xx_dev_to_port(dev);
1185 struct s3c24xx_uart_port *ourport = to_ourport(port); 1133 struct s3c24xx_uart_port *ourport = to_ourport(port);
1186 1134
1187 if (IS_ERR(ourport->baudclk)) 1135 return snprintf(buf, PAGE_SIZE, "* %s\n", ourport->clksrc->name);
1188 return -EINVAL;
1189
1190 return snprintf(buf, PAGE_SIZE, "* %s\n",
1191 ourport->baudclk->name ?: "(null)");
1192} 1136}
1193 1137
1194static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL); 1138static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL);
1195 1139
1196
1197/* Device driver serial port probe */ 1140/* Device driver serial port probe */
1198 1141
1199static const struct of_device_id s3c24xx_uart_dt_match[];
1200static int probe_index; 1142static int probe_index;
1201 1143
1202static inline struct s3c24xx_serial_drv_data *s3c24xx_get_driver_data( 1144int s3c24xx_serial_probe(struct platform_device *dev,
1203 struct platform_device *pdev) 1145 struct s3c24xx_uart_info *info)
1204{
1205#ifdef CONFIG_OF
1206 if (pdev->dev.of_node) {
1207 const struct of_device_id *match;
1208 match = of_match_node(s3c24xx_uart_dt_match, pdev->dev.of_node);
1209 return (struct s3c24xx_serial_drv_data *)match->data;
1210 }
1211#endif
1212 return (struct s3c24xx_serial_drv_data *)
1213 platform_get_device_id(pdev)->driver_data;
1214}
1215
1216static int s3c24xx_serial_probe(struct platform_device *pdev)
1217{ 1146{
1218 struct s3c24xx_uart_port *ourport; 1147 struct s3c24xx_uart_port *ourport;
1219 int ret; 1148 int ret;
1220 1149
1221 dbg("s3c24xx_serial_probe(%p) %d\n", pdev, probe_index); 1150 dbg("s3c24xx_serial_probe(%p, %p) %d\n", dev, info, probe_index);
1222 1151
1223 ourport = &s3c24xx_serial_ports[probe_index]; 1152 ourport = &s3c24xx_serial_ports[probe_index];
1224
1225 ourport->drv_data = s3c24xx_get_driver_data(pdev);
1226 if (!ourport->drv_data) {
1227 dev_err(&pdev->dev, "could not find driver data\n");
1228 return -ENODEV;
1229 }
1230
1231 ourport->baudclk = ERR_PTR(-EINVAL);
1232 ourport->info = ourport->drv_data->info;
1233 ourport->cfg = (pdev->dev.platform_data) ?
1234 (struct s3c2410_uartcfg *)pdev->dev.platform_data :
1235 ourport->drv_data->def_cfg;
1236
1237 ourport->port.fifosize = (ourport->info->fifosize) ?
1238 ourport->info->fifosize :
1239 ourport->drv_data->fifosize[probe_index];
1240
1241 probe_index++; 1153 probe_index++;
1242 1154
1243 dbg("%s: initialising port %p...\n", __func__, ourport); 1155 dbg("%s: initialising port %p...\n", __func__, ourport);
1244 1156
1245 ret = s3c24xx_serial_init_port(ourport, pdev); 1157 ret = s3c24xx_serial_init_port(ourport, info, dev);
1246 if (ret < 0) 1158 if (ret < 0)
1247 goto probe_err; 1159 goto probe_err;
1248 1160
1249 dbg("%s: adding port\n", __func__); 1161 dbg("%s: adding port\n", __func__);
1250 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port); 1162 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
1251 platform_set_drvdata(pdev, &ourport->port); 1163 platform_set_drvdata(dev, &ourport->port);
1252 1164
1253 ret = device_create_file(&pdev->dev, &dev_attr_clock_source); 1165 ret = device_create_file(&dev->dev, &dev_attr_clock_source);
1254 if (ret < 0) 1166 if (ret < 0)
1255 dev_err(&pdev->dev, "failed to add clock source attr.\n"); 1167 printk(KERN_ERR "%s: failed to add clksrc attr.\n", __func__);
1256 1168
1257 ret = s3c24xx_serial_cpufreq_register(ourport); 1169 ret = s3c24xx_serial_cpufreq_register(ourport);
1258 if (ret < 0) 1170 if (ret < 0)
1259 dev_err(&pdev->dev, "failed to add cpufreq notifier\n"); 1171 dev_err(&dev->dev, "failed to add cpufreq notifier\n");
1260 1172
1261 return 0; 1173 return 0;
1262 1174
@@ -1264,7 +1176,9 @@ static int s3c24xx_serial_probe(struct platform_device *pdev)
1264 return ret; 1176 return ret;
1265} 1177}
1266 1178
1267static int s3c24xx_serial_remove(struct platform_device *dev) 1179EXPORT_SYMBOL_GPL(s3c24xx_serial_probe);
1180
1181int __devexit s3c24xx_serial_remove(struct platform_device *dev)
1268{ 1182{
1269 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev); 1183 struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
1270 1184
@@ -1277,6 +1191,8 @@ static int s3c24xx_serial_remove(struct platform_device *dev)
1277 return 0; 1191 return 0;
1278} 1192}
1279 1193
1194EXPORT_SYMBOL_GPL(s3c24xx_serial_remove);
1195
1280/* UART power management code */ 1196/* UART power management code */
1281#ifdef CONFIG_PM_SLEEP 1197#ifdef CONFIG_PM_SLEEP
1282static int s3c24xx_serial_suspend(struct device *dev) 1198static int s3c24xx_serial_suspend(struct device *dev)
@@ -1295,9 +1211,9 @@ static int s3c24xx_serial_resume(struct device *dev)
1295 struct s3c24xx_uart_port *ourport = to_ourport(port); 1211 struct s3c24xx_uart_port *ourport = to_ourport(port);
1296 1212
1297 if (port) { 1213 if (port) {
1298 clk_prepare_enable(ourport->clk); 1214 clk_enable(ourport->clk);
1299 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port)); 1215 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
1300 clk_disable_unprepare(ourport->clk); 1216 clk_disable(ourport->clk);
1301 1217
1302 uart_resume_port(&s3c24xx_uart_drv, port); 1218 uart_resume_port(&s3c24xx_uart_drv, port);
1303 } 1219 }
@@ -1316,6 +1232,41 @@ static const struct dev_pm_ops s3c24xx_serial_pm_ops = {
1316#define SERIAL_SAMSUNG_PM_OPS NULL 1232#define SERIAL_SAMSUNG_PM_OPS NULL
1317#endif /* CONFIG_PM_SLEEP */ 1233#endif /* CONFIG_PM_SLEEP */
1318 1234
1235int s3c24xx_serial_init(struct platform_driver *drv,
1236 struct s3c24xx_uart_info *info)
1237{
1238 dbg("s3c24xx_serial_init(%p,%p)\n", drv, info);
1239
1240 drv->driver.pm = SERIAL_SAMSUNG_PM_OPS;
1241
1242 return platform_driver_register(drv);
1243}
1244
1245EXPORT_SYMBOL_GPL(s3c24xx_serial_init);
1246
1247/* module initialisation code */
1248
1249static int __init s3c24xx_serial_modinit(void)
1250{
1251 int ret;
1252
1253 ret = uart_register_driver(&s3c24xx_uart_drv);
1254 if (ret < 0) {
1255 printk(KERN_ERR "failed to register UART driver\n");
1256 return -1;
1257 }
1258
1259 return 0;
1260}
1261
1262static void __exit s3c24xx_serial_modexit(void)
1263{
1264 uart_unregister_driver(&s3c24xx_uart_drv);
1265}
1266
1267module_init(s3c24xx_serial_modinit);
1268module_exit(s3c24xx_serial_modexit);
1269
1319/* Console code */ 1270/* Console code */
1320 1271
1321#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE 1272#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
@@ -1341,36 +1292,6 @@ s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
1341 return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0; 1292 return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
1342} 1293}
1343 1294
1344#ifdef CONFIG_CONSOLE_POLL
1345/*
1346 * Console polling routines for writing and reading from the uart while
1347 * in an interrupt or debug context.
1348 */
1349
1350static int s3c24xx_serial_get_poll_char(struct uart_port *port)
1351{
1352 struct s3c24xx_uart_port *ourport = to_ourport(port);
1353 unsigned int ufstat;
1354
1355 ufstat = rd_regl(port, S3C2410_UFSTAT);
1356 if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
1357 return NO_POLL_CHAR;
1358
1359 return rd_regb(port, S3C2410_URXH);
1360}
1361
1362static void s3c24xx_serial_put_poll_char(struct uart_port *port,
1363 unsigned char c)
1364{
1365 unsigned int ufcon = rd_regl(cons_uart, S3C2410_UFCON);
1366
1367 while (!s3c24xx_serial_console_txrdy(port, ufcon))
1368 cpu_relax();
1369 wr_regb(cons_uart, S3C2410_UTXH, c);
1370}
1371
1372#endif /* CONFIG_CONSOLE_POLL */
1373
1374static void 1295static void
1375s3c24xx_serial_console_putchar(struct uart_port *port, int ch) 1296s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
1376{ 1297{
@@ -1391,13 +1312,12 @@ static void __init
1391s3c24xx_serial_get_options(struct uart_port *port, int *baud, 1312s3c24xx_serial_get_options(struct uart_port *port, int *baud,
1392 int *parity, int *bits) 1313 int *parity, int *bits)
1393{ 1314{
1315 struct s3c24xx_uart_clksrc clksrc;
1394 struct clk *clk; 1316 struct clk *clk;
1395 unsigned int ulcon; 1317 unsigned int ulcon;
1396 unsigned int ucon; 1318 unsigned int ucon;
1397 unsigned int ubrdiv; 1319 unsigned int ubrdiv;
1398 unsigned long rate; 1320 unsigned long rate;
1399 unsigned int clk_sel;
1400 char clk_name[MAX_CLK_NAME_LENGTH];
1401 1321
1402 ulcon = rd_regl(port, S3C2410_ULCON); 1322 ulcon = rd_regl(port, S3C2410_ULCON);
1403 ucon = rd_regl(port, S3C2410_UCON); 1323 ucon = rd_regl(port, S3C2410_UCON);
@@ -1442,21 +1362,44 @@ s3c24xx_serial_get_options(struct uart_port *port, int *baud,
1442 1362
1443 /* now calculate the baud rate */ 1363 /* now calculate the baud rate */
1444 1364
1445 clk_sel = s3c24xx_serial_getsource(port); 1365 s3c24xx_serial_getsource(port, &clksrc);
1446 sprintf(clk_name, "clk_uart_baud%d", clk_sel);
1447 1366
1448 clk = clk_get(port->dev, clk_name); 1367 clk = clk_get(port->dev, clksrc.name);
1449 if (!IS_ERR(clk)) 1368 if (!IS_ERR(clk) && clk != NULL)
1450 rate = clk_get_rate(clk); 1369 rate = clk_get_rate(clk) / clksrc.divisor;
1451 else 1370 else
1452 rate = 1; 1371 rate = 1;
1453 1372
1373
1454 *baud = rate / (16 * (ubrdiv + 1)); 1374 *baud = rate / (16 * (ubrdiv + 1));
1455 dbg("calculated baud %d\n", *baud); 1375 dbg("calculated baud %d\n", *baud);
1456 } 1376 }
1457 1377
1458} 1378}
1459 1379
1380/* s3c24xx_serial_init_ports
1381 *
1382 * initialise the serial ports from the machine provided initialisation
1383 * data.
1384*/
1385
1386static int s3c24xx_serial_init_ports(struct s3c24xx_uart_info **info)
1387{
1388 struct s3c24xx_uart_port *ptr = s3c24xx_serial_ports;
1389 struct platform_device **platdev_ptr;
1390 int i;
1391
1392 dbg("s3c24xx_serial_init_ports: initialising ports...\n");
1393
1394 platdev_ptr = s3c24xx_uart_devs;
1395
1396 for (i = 0; i < CONFIG_SERIAL_SAMSUNG_UARTS; i++, ptr++, platdev_ptr++) {
1397 s3c24xx_serial_init_port(ptr, info[i], *platdev_ptr);
1398 }
1399
1400 return 0;
1401}
1402
1460static int __init 1403static int __init
1461s3c24xx_serial_console_setup(struct console *co, char *options) 1404s3c24xx_serial_console_setup(struct console *co, char *options)
1462{ 1405{
@@ -1500,6 +1443,11 @@ s3c24xx_serial_console_setup(struct console *co, char *options)
1500 return uart_set_options(port, co, baud, parity, bits, flow); 1443 return uart_set_options(port, co, baud, parity, bits, flow);
1501} 1444}
1502 1445
1446/* s3c24xx_serial_initconsole
1447 *
1448 * initialise the console from one of the uart drivers
1449*/
1450
1503static struct console s3c24xx_serial_console = { 1451static struct console s3c24xx_serial_console = {
1504 .name = S3C24XX_SERIAL_NAME, 1452 .name = S3C24XX_SERIAL_NAME,
1505 .device = uart_console_device, 1453 .device = uart_console_device,
@@ -1509,262 +1457,34 @@ static struct console s3c24xx_serial_console = {
1509 .setup = s3c24xx_serial_console_setup, 1457 .setup = s3c24xx_serial_console_setup,
1510 .data = &s3c24xx_uart_drv, 1458 .data = &s3c24xx_uart_drv,
1511}; 1459};
1512#endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */
1513
1514#ifdef CONFIG_CPU_S3C2410
1515static struct s3c24xx_serial_drv_data s3c2410_serial_drv_data = {
1516 .info = &(struct s3c24xx_uart_info) {
1517 .name = "Samsung S3C2410 UART",
1518 .type = PORT_S3C2410,
1519 .fifosize = 16,
1520 .rx_fifomask = S3C2410_UFSTAT_RXMASK,
1521 .rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
1522 .rx_fifofull = S3C2410_UFSTAT_RXFULL,
1523 .tx_fifofull = S3C2410_UFSTAT_TXFULL,
1524 .tx_fifomask = S3C2410_UFSTAT_TXMASK,
1525 .tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
1526 .def_clk_sel = S3C2410_UCON_CLKSEL0,
1527 .num_clks = 2,
1528 .clksel_mask = S3C2410_UCON_CLKMASK,
1529 .clksel_shift = S3C2410_UCON_CLKSHIFT,
1530 },
1531 .def_cfg = &(struct s3c2410_uartcfg) {
1532 .ucon = S3C2410_UCON_DEFAULT,
1533 .ufcon = S3C2410_UFCON_DEFAULT,
1534 },
1535};
1536#define S3C2410_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2410_serial_drv_data)
1537#else
1538#define S3C2410_SERIAL_DRV_DATA (kernel_ulong_t)NULL
1539#endif
1540
1541#ifdef CONFIG_CPU_S3C2412
1542static struct s3c24xx_serial_drv_data s3c2412_serial_drv_data = {
1543 .info = &(struct s3c24xx_uart_info) {
1544 .name = "Samsung S3C2412 UART",
1545 .type = PORT_S3C2412,
1546 .fifosize = 64,
1547 .has_divslot = 1,
1548 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
1549 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
1550 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
1551 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
1552 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
1553 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
1554 .def_clk_sel = S3C2410_UCON_CLKSEL2,
1555 .num_clks = 4,
1556 .clksel_mask = S3C2412_UCON_CLKMASK,
1557 .clksel_shift = S3C2412_UCON_CLKSHIFT,
1558 },
1559 .def_cfg = &(struct s3c2410_uartcfg) {
1560 .ucon = S3C2410_UCON_DEFAULT,
1561 .ufcon = S3C2410_UFCON_DEFAULT,
1562 },
1563};
1564#define S3C2412_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2412_serial_drv_data)
1565#else
1566#define S3C2412_SERIAL_DRV_DATA (kernel_ulong_t)NULL
1567#endif
1568
1569#if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2416) || \
1570 defined(CONFIG_CPU_S3C2443) || defined(CONFIG_CPU_S3C2442)
1571static struct s3c24xx_serial_drv_data s3c2440_serial_drv_data = {
1572 .info = &(struct s3c24xx_uart_info) {
1573 .name = "Samsung S3C2440 UART",
1574 .type = PORT_S3C2440,
1575 .fifosize = 64,
1576 .has_divslot = 1,
1577 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
1578 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
1579 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
1580 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
1581 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
1582 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
1583 .def_clk_sel = S3C2410_UCON_CLKSEL2,
1584 .num_clks = 4,
1585 .clksel_mask = S3C2412_UCON_CLKMASK,
1586 .clksel_shift = S3C2412_UCON_CLKSHIFT,
1587 },
1588 .def_cfg = &(struct s3c2410_uartcfg) {
1589 .ucon = S3C2410_UCON_DEFAULT,
1590 .ufcon = S3C2410_UFCON_DEFAULT,
1591 },
1592};
1593#define S3C2440_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2440_serial_drv_data)
1594#else
1595#define S3C2440_SERIAL_DRV_DATA (kernel_ulong_t)NULL
1596#endif
1597
1598#if defined(CONFIG_CPU_S3C6400) || defined(CONFIG_CPU_S3C6410) || \
1599 defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450) || \
1600 defined(CONFIG_CPU_S5PC100)
1601static struct s3c24xx_serial_drv_data s3c6400_serial_drv_data = {
1602 .info = &(struct s3c24xx_uart_info) {
1603 .name = "Samsung S3C6400 UART",
1604 .type = PORT_S3C6400,
1605 .fifosize = 64,
1606 .has_divslot = 1,
1607 .rx_fifomask = S3C2440_UFSTAT_RXMASK,
1608 .rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
1609 .rx_fifofull = S3C2440_UFSTAT_RXFULL,
1610 .tx_fifofull = S3C2440_UFSTAT_TXFULL,
1611 .tx_fifomask = S3C2440_UFSTAT_TXMASK,
1612 .tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
1613 .def_clk_sel = S3C2410_UCON_CLKSEL2,
1614 .num_clks = 4,
1615 .clksel_mask = S3C6400_UCON_CLKMASK,
1616 .clksel_shift = S3C6400_UCON_CLKSHIFT,
1617 },
1618 .def_cfg = &(struct s3c2410_uartcfg) {
1619 .ucon = S3C2410_UCON_DEFAULT,
1620 .ufcon = S3C2410_UFCON_DEFAULT,
1621 },
1622};
1623#define S3C6400_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c6400_serial_drv_data)
1624#else
1625#define S3C6400_SERIAL_DRV_DATA (kernel_ulong_t)NULL
1626#endif
1627
1628#ifdef CONFIG_CPU_S5PV210
1629static struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = {
1630 .info = &(struct s3c24xx_uart_info) {
1631 .name = "Samsung S5PV210 UART",
1632 .type = PORT_S3C6400,
1633 .has_divslot = 1,
1634 .rx_fifomask = S5PV210_UFSTAT_RXMASK,
1635 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
1636 .rx_fifofull = S5PV210_UFSTAT_RXFULL,
1637 .tx_fifofull = S5PV210_UFSTAT_TXFULL,
1638 .tx_fifomask = S5PV210_UFSTAT_TXMASK,
1639 .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
1640 .def_clk_sel = S3C2410_UCON_CLKSEL0,
1641 .num_clks = 2,
1642 .clksel_mask = S5PV210_UCON_CLKMASK,
1643 .clksel_shift = S5PV210_UCON_CLKSHIFT,
1644 },
1645 .def_cfg = &(struct s3c2410_uartcfg) {
1646 .ucon = S5PV210_UCON_DEFAULT,
1647 .ufcon = S5PV210_UFCON_DEFAULT,
1648 },
1649 .fifosize = { 256, 64, 16, 16 },
1650};
1651#define S5PV210_SERIAL_DRV_DATA ((kernel_ulong_t)&s5pv210_serial_drv_data)
1652#else
1653#define S5PV210_SERIAL_DRV_DATA (kernel_ulong_t)NULL
1654#endif
1655
1656#if defined(CONFIG_CPU_EXYNOS4210) || defined(CONFIG_SOC_EXYNOS4212) || \
1657 defined(CONFIG_SOC_EXYNOS4412) || defined(CONFIG_SOC_EXYNOS5250) || \
1658 defined(CONFIG_SOC_EXYNOS5440)
1659static struct s3c24xx_serial_drv_data exynos4210_serial_drv_data = {
1660 .info = &(struct s3c24xx_uart_info) {
1661 .name = "Samsung Exynos4 UART",
1662 .type = PORT_S3C6400,
1663 .has_divslot = 1,
1664 .rx_fifomask = S5PV210_UFSTAT_RXMASK,
1665 .rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
1666 .rx_fifofull = S5PV210_UFSTAT_RXFULL,
1667 .tx_fifofull = S5PV210_UFSTAT_TXFULL,
1668 .tx_fifomask = S5PV210_UFSTAT_TXMASK,
1669 .tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
1670 .def_clk_sel = S3C2410_UCON_CLKSEL0,
1671 .num_clks = 1,
1672 .clksel_mask = 0,
1673 .clksel_shift = 0,
1674 },
1675 .def_cfg = &(struct s3c2410_uartcfg) {
1676 .ucon = S5PV210_UCON_DEFAULT,
1677 .ufcon = S5PV210_UFCON_DEFAULT,
1678 .has_fracval = 1,
1679 },
1680 .fifosize = { 256, 64, 16, 16 },
1681};
1682#define EXYNOS4210_SERIAL_DRV_DATA ((kernel_ulong_t)&exynos4210_serial_drv_data)
1683#else
1684#define EXYNOS4210_SERIAL_DRV_DATA (kernel_ulong_t)NULL
1685#endif
1686 1460
1687static struct platform_device_id s3c24xx_serial_driver_ids[] = { 1461int s3c24xx_serial_initconsole(struct platform_driver *drv,
1688 { 1462 struct s3c24xx_uart_info **info)
1689 .name = "s3c2410-uart",
1690 .driver_data = S3C2410_SERIAL_DRV_DATA,
1691 }, {
1692 .name = "s3c2412-uart",
1693 .driver_data = S3C2412_SERIAL_DRV_DATA,
1694 }, {
1695 .name = "s3c2440-uart",
1696 .driver_data = S3C2440_SERIAL_DRV_DATA,
1697 }, {
1698 .name = "s3c6400-uart",
1699 .driver_data = S3C6400_SERIAL_DRV_DATA,
1700 }, {
1701 .name = "s5pv210-uart",
1702 .driver_data = S5PV210_SERIAL_DRV_DATA,
1703 }, {
1704 .name = "exynos4210-uart",
1705 .driver_data = EXYNOS4210_SERIAL_DRV_DATA,
1706 },
1707 { },
1708};
1709MODULE_DEVICE_TABLE(platform, s3c24xx_serial_driver_ids);
1710
1711#ifdef CONFIG_OF
1712static const struct of_device_id s3c24xx_uart_dt_match[] = {
1713 { .compatible = "samsung,s3c2410-uart",
1714 .data = (void *)S3C2410_SERIAL_DRV_DATA },
1715 { .compatible = "samsung,s3c2412-uart",
1716 .data = (void *)S3C2412_SERIAL_DRV_DATA },
1717 { .compatible = "samsung,s3c2440-uart",
1718 .data = (void *)S3C2440_SERIAL_DRV_DATA },
1719 { .compatible = "samsung,s3c6400-uart",
1720 .data = (void *)S3C6400_SERIAL_DRV_DATA },
1721 { .compatible = "samsung,s5pv210-uart",
1722 .data = (void *)S5PV210_SERIAL_DRV_DATA },
1723 { .compatible = "samsung,exynos4210-uart",
1724 .data = (void *)EXYNOS4210_SERIAL_DRV_DATA },
1725 {},
1726};
1727MODULE_DEVICE_TABLE(of, s3c24xx_uart_dt_match);
1728#else
1729#define s3c24xx_uart_dt_match NULL
1730#endif
1731 1463
1732static struct platform_driver samsung_serial_driver = { 1464{
1733 .probe = s3c24xx_serial_probe, 1465 struct platform_device *dev = s3c24xx_uart_devs[0];
1734 .remove = s3c24xx_serial_remove,
1735 .id_table = s3c24xx_serial_driver_ids,
1736 .driver = {
1737 .name = "samsung-uart",
1738 .owner = THIS_MODULE,
1739 .pm = SERIAL_SAMSUNG_PM_OPS,
1740 .of_match_table = s3c24xx_uart_dt_match,
1741 },
1742};
1743 1466
1744/* module initialisation code */ 1467 dbg("s3c24xx_serial_initconsole\n");
1745 1468
1746static int __init s3c24xx_serial_modinit(void) 1469 /* select driver based on the cpu */
1747{
1748 int ret;
1749 1470
1750 ret = uart_register_driver(&s3c24xx_uart_drv); 1471 if (dev == NULL) {
1751 if (ret < 0) { 1472 printk(KERN_ERR "s3c24xx: no devices for console init\n");
1752 pr_err("Failed to register Samsung UART driver\n"); 1473 return 0;
1753 return ret;
1754 } 1474 }
1755 1475
1756 return platform_driver_register(&samsung_serial_driver); 1476 if (strcmp(dev->name, drv->driver.name) != 0)
1757} 1477 return 0;
1758 1478
1759static void __exit s3c24xx_serial_modexit(void) 1479 s3c24xx_serial_console.data = &s3c24xx_uart_drv;
1760{ 1480 s3c24xx_serial_init_ports(info);
1761 uart_unregister_driver(&s3c24xx_uart_drv); 1481
1482 register_console(&s3c24xx_serial_console);
1483 return 0;
1762} 1484}
1763 1485
1764module_init(s3c24xx_serial_modinit); 1486#endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */
1765module_exit(s3c24xx_serial_modexit);
1766 1487
1767MODULE_ALIAS("platform:samsung-uart");
1768MODULE_DESCRIPTION("Samsung SoC Serial port driver"); 1488MODULE_DESCRIPTION("Samsung SoC Serial port driver");
1769MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 1489MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
1770MODULE_LICENSE("GPL v2"); 1490MODULE_LICENSE("GPL v2");
diff --git a/drivers/tty/serial/samsung.h b/drivers/tty/serial/samsung.h
index 1a4bca3e417..a69d9a54be9 100644
--- a/drivers/tty/serial/samsung.h
+++ b/drivers/tty/serial/samsung.h
@@ -19,25 +19,20 @@ struct s3c24xx_uart_info {
19 unsigned long tx_fifomask; 19 unsigned long tx_fifomask;
20 unsigned long tx_fifoshift; 20 unsigned long tx_fifoshift;
21 unsigned long tx_fifofull; 21 unsigned long tx_fifofull;
22 unsigned int def_clk_sel;
23 unsigned long num_clks;
24 unsigned long clksel_mask;
25 unsigned long clksel_shift;
26 22
27 /* uart port features */ 23 /* uart port features */
28 24
29 unsigned int has_divslot:1; 25 unsigned int has_divslot:1;
30 26
27 /* clock source control */
28
29 int (*get_clksrc)(struct uart_port *, struct s3c24xx_uart_clksrc *clk);
30 int (*set_clksrc)(struct uart_port *, struct s3c24xx_uart_clksrc *clk);
31
31 /* uart controls */ 32 /* uart controls */
32 int (*reset_port)(struct uart_port *, struct s3c2410_uartcfg *); 33 int (*reset_port)(struct uart_port *, struct s3c2410_uartcfg *);
33}; 34};
34 35
35struct s3c24xx_serial_drv_data {
36 struct s3c24xx_uart_info *info;
37 struct s3c2410_uartcfg *def_cfg;
38 unsigned int fifosize[CONFIG_SERIAL_SAMSUNG_UARTS];
39};
40
41struct s3c24xx_uart_port { 36struct s3c24xx_uart_port {
42 unsigned char rx_claimed; 37 unsigned char rx_claimed;
43 unsigned char tx_claimed; 38 unsigned char tx_claimed;
@@ -48,13 +43,10 @@ struct s3c24xx_uart_port {
48 unsigned int tx_irq; 43 unsigned int tx_irq;
49 44
50 struct s3c24xx_uart_info *info; 45 struct s3c24xx_uart_info *info;
46 struct s3c24xx_uart_clksrc *clksrc;
51 struct clk *clk; 47 struct clk *clk;
52 struct clk *baudclk; 48 struct clk *baudclk;
53 struct uart_port port; 49 struct uart_port port;
54 struct s3c24xx_serial_drv_data *drv_data;
55
56 /* reference to platform data */
57 struct s3c2410_uartcfg *cfg;
58 50
59#ifdef CONFIG_CPU_FREQ 51#ifdef CONFIG_CPU_FREQ
60 struct notifier_block freq_transition; 52 struct notifier_block freq_transition;
@@ -64,11 +56,11 @@ struct s3c24xx_uart_port {
64/* conversion functions */ 56/* conversion functions */
65 57
66#define s3c24xx_dev_to_port(__dev) (struct uart_port *)dev_get_drvdata(__dev) 58#define s3c24xx_dev_to_port(__dev) (struct uart_port *)dev_get_drvdata(__dev)
59#define s3c24xx_dev_to_cfg(__dev) (struct s3c2410_uartcfg *)((__dev)->platform_data)
67 60
68/* register access controls */ 61/* register access controls */
69 62
70#define portaddr(port, reg) ((port)->membase + (reg)) 63#define portaddr(port, reg) ((port)->membase + (reg))
71#define portaddrl(port, reg) ((unsigned long *)((port)->membase + (reg)))
72 64
73#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg))) 65#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg)))
74#define rd_regl(port, reg) (__raw_readl(portaddr(port, reg))) 66#define rd_regl(port, reg) (__raw_readl(portaddr(port, reg)))
@@ -76,6 +68,17 @@ struct s3c24xx_uart_port {
76#define wr_regb(port, reg, val) __raw_writeb(val, portaddr(port, reg)) 68#define wr_regb(port, reg, val) __raw_writeb(val, portaddr(port, reg))
77#define wr_regl(port, reg, val) __raw_writel(val, portaddr(port, reg)) 69#define wr_regl(port, reg, val) __raw_writel(val, portaddr(port, reg))
78 70
71extern int s3c24xx_serial_probe(struct platform_device *dev,
72 struct s3c24xx_uart_info *uart);
73
74extern int __devexit s3c24xx_serial_remove(struct platform_device *dev);
75
76extern int s3c24xx_serial_initconsole(struct platform_driver *drv,
77 struct s3c24xx_uart_info **uart);
78
79extern int s3c24xx_serial_init(struct platform_driver *drv,
80 struct s3c24xx_uart_info *info);
81
79#ifdef CONFIG_SERIAL_SAMSUNG_DEBUG 82#ifdef CONFIG_SERIAL_SAMSUNG_DEBUG
80 83
81extern void printascii(const char *); 84extern void printascii(const char *);
diff --git a/drivers/tty/serial/sb1250-duart.c b/drivers/tty/serial/sb1250-duart.c
index f76b1688c5c..6bc2e3f876f 100644
--- a/drivers/tty/serial/sb1250-duart.c
+++ b/drivers/tty/serial/sb1250-duart.c
@@ -31,14 +31,12 @@
31#include <linux/interrupt.h> 31#include <linux/interrupt.h>
32#include <linux/ioport.h> 32#include <linux/ioport.h>
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/major.h> 34#include <linux/major.h>
36#include <linux/serial.h> 35#include <linux/serial.h>
37#include <linux/serial_core.h> 36#include <linux/serial_core.h>
38#include <linux/spinlock.h> 37#include <linux/spinlock.h>
39#include <linux/sysrq.h> 38#include <linux/sysrq.h>
40#include <linux/tty.h> 39#include <linux/tty.h>
41#include <linux/tty_flip.h>
42#include <linux/types.h> 40#include <linux/types.h>
43 41
44#include <linux/atomic.h> 42#include <linux/atomic.h>
diff --git a/drivers/tty/serial/sc26xx.c b/drivers/tty/serial/sc26xx.c
index aced1dd923d..75038ad2b24 100644
--- a/drivers/tty/serial/sc26xx.c
+++ b/drivers/tty/serial/sc26xx.c
@@ -20,10 +20,6 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/io.h>
24
25#warning "Please try migrate to use new driver SCCNXP and report the status" \
26 "in the linux-serial mailing list."
27 23
28#if defined(CONFIG_MAGIC_SYSRQ) 24#if defined(CONFIG_MAGIC_SYSRQ)
29#define SUPPORT_SYSRQ 25#define SUPPORT_SYSRQ
@@ -621,7 +617,7 @@ static u8 sc26xx_flags2mask(unsigned int flags, unsigned int bitpos)
621 return bit ? (1 << (bit - 1)) : 0; 617 return bit ? (1 << (bit - 1)) : 0;
622} 618}
623 619
624static void sc26xx_init_masks(struct uart_sc26xx_port *up, 620static void __devinit sc26xx_init_masks(struct uart_sc26xx_port *up,
625 int line, unsigned int data) 621 int line, unsigned int data)
626{ 622{
627 up->dtr_mask[line] = sc26xx_flags2mask(data, 0); 623 up->dtr_mask[line] = sc26xx_flags2mask(data, 0);
@@ -632,7 +628,7 @@ static void sc26xx_init_masks(struct uart_sc26xx_port *up,
632 up->ri_mask[line] = sc26xx_flags2mask(data, 20); 628 up->ri_mask[line] = sc26xx_flags2mask(data, 20);
633} 629}
634 630
635static int sc26xx_probe(struct platform_device *dev) 631static int __devinit sc26xx_probe(struct platform_device *dev)
636{ 632{
637 struct resource *res; 633 struct resource *res;
638 struct uart_sc26xx_port *up; 634 struct uart_sc26xx_port *up;
@@ -733,14 +729,26 @@ static int __exit sc26xx_driver_remove(struct platform_device *dev)
733 729
734static struct platform_driver sc26xx_driver = { 730static struct platform_driver sc26xx_driver = {
735 .probe = sc26xx_probe, 731 .probe = sc26xx_probe,
736 .remove = sc26xx_driver_remove, 732 .remove = __devexit_p(sc26xx_driver_remove),
737 .driver = { 733 .driver = {
738 .name = "SC26xx", 734 .name = "SC26xx",
739 .owner = THIS_MODULE, 735 .owner = THIS_MODULE,
740 }, 736 },
741}; 737};
742 738
743module_platform_driver(sc26xx_driver); 739static int __init sc26xx_init(void)
740{
741 return platform_driver_register(&sc26xx_driver);
742}
743
744static void __exit sc26xx_exit(void)
745{
746 platform_driver_unregister(&sc26xx_driver);
747}
748
749module_init(sc26xx_init);
750module_exit(sc26xx_exit);
751
744 752
745MODULE_AUTHOR("Thomas Bogendörfer"); 753MODULE_AUTHOR("Thomas Bogendörfer");
746MODULE_DESCRIPTION("SC681/SC2692 serial driver"); 754MODULE_DESCRIPTION("SC681/SC2692 serial driver");
diff --git a/drivers/tty/serial/sccnxp.c b/drivers/tty/serial/sccnxp.c
deleted file mode 100644
index 418b495e323..00000000000
--- a/drivers/tty/serial/sccnxp.c
+++ /dev/null
@@ -1,991 +0,0 @@
1/*
2 * NXP (Philips) SCC+++(SCN+++) serial driver
3 *
4 * Copyright (C) 2012 Alexander Shiyan <shc_work@mail.ru>
5 *
6 * Based on sc26xx.c, by Thomas Bogendörfer (tsbogend@alpha.franken.de)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#if defined(CONFIG_SERIAL_SCCNXP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
15#define SUPPORT_SYSRQ
16#endif
17
18#include <linux/module.h>
19#include <linux/device.h>
20#include <linux/console.h>
21#include <linux/serial_core.h>
22#include <linux/serial.h>
23#include <linux/io.h>
24#include <linux/tty.h>
25#include <linux/tty_flip.h>
26#include <linux/platform_device.h>
27#include <linux/platform_data/sccnxp.h>
28
29#define SCCNXP_NAME "uart-sccnxp"
30#define SCCNXP_MAJOR 204
31#define SCCNXP_MINOR 205
32
33#define SCCNXP_MR_REG (0x00)
34# define MR0_BAUD_NORMAL (0 << 0)
35# define MR0_BAUD_EXT1 (1 << 0)
36# define MR0_BAUD_EXT2 (5 << 0)
37# define MR0_FIFO (1 << 3)
38# define MR0_TXLVL (1 << 4)
39# define MR1_BITS_5 (0 << 0)
40# define MR1_BITS_6 (1 << 0)
41# define MR1_BITS_7 (2 << 0)
42# define MR1_BITS_8 (3 << 0)
43# define MR1_PAR_EVN (0 << 2)
44# define MR1_PAR_ODD (1 << 2)
45# define MR1_PAR_NO (4 << 2)
46# define MR2_STOP1 (7 << 0)
47# define MR2_STOP2 (0xf << 0)
48#define SCCNXP_SR_REG (0x01)
49#define SCCNXP_CSR_REG SCCNXP_SR_REG
50# define SR_RXRDY (1 << 0)
51# define SR_FULL (1 << 1)
52# define SR_TXRDY (1 << 2)
53# define SR_TXEMT (1 << 3)
54# define SR_OVR (1 << 4)
55# define SR_PE (1 << 5)
56# define SR_FE (1 << 6)
57# define SR_BRK (1 << 7)
58#define SCCNXP_CR_REG (0x02)
59# define CR_RX_ENABLE (1 << 0)
60# define CR_RX_DISABLE (1 << 1)
61# define CR_TX_ENABLE (1 << 2)
62# define CR_TX_DISABLE (1 << 3)
63# define CR_CMD_MRPTR1 (0x01 << 4)
64# define CR_CMD_RX_RESET (0x02 << 4)
65# define CR_CMD_TX_RESET (0x03 << 4)
66# define CR_CMD_STATUS_RESET (0x04 << 4)
67# define CR_CMD_BREAK_RESET (0x05 << 4)
68# define CR_CMD_START_BREAK (0x06 << 4)
69# define CR_CMD_STOP_BREAK (0x07 << 4)
70# define CR_CMD_MRPTR0 (0x0b << 4)
71#define SCCNXP_RHR_REG (0x03)
72#define SCCNXP_THR_REG SCCNXP_RHR_REG
73#define SCCNXP_IPCR_REG (0x04)
74#define SCCNXP_ACR_REG SCCNXP_IPCR_REG
75# define ACR_BAUD0 (0 << 7)
76# define ACR_BAUD1 (1 << 7)
77# define ACR_TIMER_MODE (6 << 4)
78#define SCCNXP_ISR_REG (0x05)
79#define SCCNXP_IMR_REG SCCNXP_ISR_REG
80# define IMR_TXRDY (1 << 0)
81# define IMR_RXRDY (1 << 1)
82# define ISR_TXRDY(x) (1 << ((x * 4) + 0))
83# define ISR_RXRDY(x) (1 << ((x * 4) + 1))
84#define SCCNXP_IPR_REG (0x0d)
85#define SCCNXP_OPCR_REG SCCNXP_IPR_REG
86#define SCCNXP_SOP_REG (0x0e)
87#define SCCNXP_ROP_REG (0x0f)
88
89/* Route helpers */
90#define MCTRL_MASK(sig) (0xf << (sig))
91#define MCTRL_IBIT(cfg, sig) ((((cfg) >> (sig)) & 0xf) - LINE_IP0)
92#define MCTRL_OBIT(cfg, sig) ((((cfg) >> (sig)) & 0xf) - LINE_OP0)
93
94/* Supported chip types */
95enum {
96 SCCNXP_TYPE_SC2681 = 2681,
97 SCCNXP_TYPE_SC2691 = 2691,
98 SCCNXP_TYPE_SC2692 = 2692,
99 SCCNXP_TYPE_SC2891 = 2891,
100 SCCNXP_TYPE_SC2892 = 2892,
101 SCCNXP_TYPE_SC28202 = 28202,
102 SCCNXP_TYPE_SC68681 = 68681,
103 SCCNXP_TYPE_SC68692 = 68692,
104};
105
106struct sccnxp_port {
107 struct uart_driver uart;
108 struct uart_port port[SCCNXP_MAX_UARTS];
109
110 const char *name;
111 int irq;
112
113 u8 imr;
114 u8 addr_mask;
115 int freq_std;
116
117 int flags;
118#define SCCNXP_HAVE_IO 0x00000001
119#define SCCNXP_HAVE_MR0 0x00000002
120
121#ifdef CONFIG_SERIAL_SCCNXP_CONSOLE
122 struct console console;
123#endif
124
125 struct mutex sccnxp_mutex;
126
127 struct sccnxp_pdata pdata;
128};
129
130static inline u8 sccnxp_raw_read(void __iomem *base, u8 reg, u8 shift)
131{
132 return readb(base + (reg << shift));
133}
134
135static inline void sccnxp_raw_write(void __iomem *base, u8 reg, u8 shift, u8 v)
136{
137 writeb(v, base + (reg << shift));
138}
139
140static inline u8 sccnxp_read(struct uart_port *port, u8 reg)
141{
142 struct sccnxp_port *s = dev_get_drvdata(port->dev);
143
144 return sccnxp_raw_read(port->membase, reg & s->addr_mask,
145 port->regshift);
146}
147
148static inline void sccnxp_write(struct uart_port *port, u8 reg, u8 v)
149{
150 struct sccnxp_port *s = dev_get_drvdata(port->dev);
151
152 sccnxp_raw_write(port->membase, reg & s->addr_mask, port->regshift, v);
153}
154
155static inline u8 sccnxp_port_read(struct uart_port *port, u8 reg)
156{
157 return sccnxp_read(port, (port->line << 3) + reg);
158}
159
160static inline void sccnxp_port_write(struct uart_port *port, u8 reg, u8 v)
161{
162 sccnxp_write(port, (port->line << 3) + reg, v);
163}
164
165static int sccnxp_update_best_err(int a, int b, int *besterr)
166{
167 int err = abs(a - b);
168
169 if ((*besterr < 0) || (*besterr > err)) {
170 *besterr = err;
171 return 0;
172 }
173
174 return 1;
175}
176
177struct baud_table {
178 u8 csr;
179 u8 acr;
180 u8 mr0;
181 int baud;
182};
183
184const struct baud_table baud_std[] = {
185 { 0, ACR_BAUD0, MR0_BAUD_NORMAL, 50, },
186 { 0, ACR_BAUD1, MR0_BAUD_NORMAL, 75, },
187 { 1, ACR_BAUD0, MR0_BAUD_NORMAL, 110, },
188 { 2, ACR_BAUD0, MR0_BAUD_NORMAL, 134, },
189 { 3, ACR_BAUD1, MR0_BAUD_NORMAL, 150, },
190 { 3, ACR_BAUD0, MR0_BAUD_NORMAL, 200, },
191 { 4, ACR_BAUD0, MR0_BAUD_NORMAL, 300, },
192 { 0, ACR_BAUD1, MR0_BAUD_EXT1, 450, },
193 { 1, ACR_BAUD0, MR0_BAUD_EXT2, 880, },
194 { 3, ACR_BAUD1, MR0_BAUD_EXT1, 900, },
195 { 5, ACR_BAUD0, MR0_BAUD_NORMAL, 600, },
196 { 7, ACR_BAUD0, MR0_BAUD_NORMAL, 1050, },
197 { 2, ACR_BAUD0, MR0_BAUD_EXT2, 1076, },
198 { 6, ACR_BAUD0, MR0_BAUD_NORMAL, 1200, },
199 { 10, ACR_BAUD1, MR0_BAUD_NORMAL, 1800, },
200 { 7, ACR_BAUD1, MR0_BAUD_NORMAL, 2000, },
201 { 8, ACR_BAUD0, MR0_BAUD_NORMAL, 2400, },
202 { 5, ACR_BAUD1, MR0_BAUD_EXT1, 3600, },
203 { 9, ACR_BAUD0, MR0_BAUD_NORMAL, 4800, },
204 { 10, ACR_BAUD0, MR0_BAUD_NORMAL, 7200, },
205 { 11, ACR_BAUD0, MR0_BAUD_NORMAL, 9600, },
206 { 8, ACR_BAUD0, MR0_BAUD_EXT1, 14400, },
207 { 12, ACR_BAUD1, MR0_BAUD_NORMAL, 19200, },
208 { 9, ACR_BAUD0, MR0_BAUD_EXT1, 28800, },
209 { 12, ACR_BAUD0, MR0_BAUD_NORMAL, 38400, },
210 { 11, ACR_BAUD0, MR0_BAUD_EXT1, 57600, },
211 { 12, ACR_BAUD1, MR0_BAUD_EXT1, 115200, },
212 { 12, ACR_BAUD0, MR0_BAUD_EXT1, 230400, },
213 { 0, 0, 0, 0 }
214};
215
216static int sccnxp_set_baud(struct uart_port *port, int baud)
217{
218 struct sccnxp_port *s = dev_get_drvdata(port->dev);
219 int div_std, tmp_baud, bestbaud = baud, besterr = -1;
220 u8 i, acr = 0, csr = 0, mr0 = 0;
221
222 /* Find best baud from table */
223 for (i = 0; baud_std[i].baud && besterr; i++) {
224 if (baud_std[i].mr0 && !(s->flags & SCCNXP_HAVE_MR0))
225 continue;
226 div_std = DIV_ROUND_CLOSEST(s->freq_std, baud_std[i].baud);
227 tmp_baud = DIV_ROUND_CLOSEST(port->uartclk, div_std);
228 if (!sccnxp_update_best_err(baud, tmp_baud, &besterr)) {
229 acr = baud_std[i].acr;
230 csr = baud_std[i].csr;
231 mr0 = baud_std[i].mr0;
232 bestbaud = tmp_baud;
233 }
234 }
235
236 if (s->flags & SCCNXP_HAVE_MR0) {
237 /* Enable FIFO, set half level for TX */
238 mr0 |= MR0_FIFO | MR0_TXLVL;
239 /* Update MR0 */
240 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_MRPTR0);
241 sccnxp_port_write(port, SCCNXP_MR_REG, mr0);
242 }
243
244 sccnxp_port_write(port, SCCNXP_ACR_REG, acr | ACR_TIMER_MODE);
245 sccnxp_port_write(port, SCCNXP_CSR_REG, (csr << 4) | csr);
246
247 if (baud != bestbaud)
248 dev_dbg(port->dev, "Baudrate desired: %i, calculated: %i\n",
249 baud, bestbaud);
250
251 return bestbaud;
252}
253
254static void sccnxp_enable_irq(struct uart_port *port, int mask)
255{
256 struct sccnxp_port *s = dev_get_drvdata(port->dev);
257
258 s->imr |= mask << (port->line * 4);
259 sccnxp_write(port, SCCNXP_IMR_REG, s->imr);
260}
261
262static void sccnxp_disable_irq(struct uart_port *port, int mask)
263{
264 struct sccnxp_port *s = dev_get_drvdata(port->dev);
265
266 s->imr &= ~(mask << (port->line * 4));
267 sccnxp_write(port, SCCNXP_IMR_REG, s->imr);
268}
269
270static void sccnxp_set_bit(struct uart_port *port, int sig, int state)
271{
272 u8 bitmask;
273 struct sccnxp_port *s = dev_get_drvdata(port->dev);
274
275 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(sig)) {
276 bitmask = 1 << MCTRL_OBIT(s->pdata.mctrl_cfg[port->line], sig);
277 if (state)
278 sccnxp_write(port, SCCNXP_SOP_REG, bitmask);
279 else
280 sccnxp_write(port, SCCNXP_ROP_REG, bitmask);
281 }
282}
283
284static void sccnxp_handle_rx(struct uart_port *port)
285{
286 u8 sr;
287 unsigned int ch, flag;
288 struct tty_struct *tty = tty_port_tty_get(&port->state->port);
289
290 if (!tty)
291 return;
292
293 for (;;) {
294 sr = sccnxp_port_read(port, SCCNXP_SR_REG);
295 if (!(sr & SR_RXRDY))
296 break;
297 sr &= SR_PE | SR_FE | SR_OVR | SR_BRK;
298
299 ch = sccnxp_port_read(port, SCCNXP_RHR_REG);
300
301 port->icount.rx++;
302 flag = TTY_NORMAL;
303
304 if (unlikely(sr)) {
305 if (sr & SR_BRK) {
306 port->icount.brk++;
307 if (uart_handle_break(port))
308 continue;
309 } else if (sr & SR_PE)
310 port->icount.parity++;
311 else if (sr & SR_FE)
312 port->icount.frame++;
313 else if (sr & SR_OVR)
314 port->icount.overrun++;
315
316 sr &= port->read_status_mask;
317 if (sr & SR_BRK)
318 flag = TTY_BREAK;
319 else if (sr & SR_PE)
320 flag = TTY_PARITY;
321 else if (sr & SR_FE)
322 flag = TTY_FRAME;
323 else if (sr & SR_OVR)
324 flag = TTY_OVERRUN;
325 }
326
327 if (uart_handle_sysrq_char(port, ch))
328 continue;
329
330 if (sr & port->ignore_status_mask)
331 continue;
332
333 uart_insert_char(port, sr, SR_OVR, ch, flag);
334 }
335
336 tty_flip_buffer_push(tty);
337
338 tty_kref_put(tty);
339}
340
341static void sccnxp_handle_tx(struct uart_port *port)
342{
343 u8 sr;
344 struct circ_buf *xmit = &port->state->xmit;
345 struct sccnxp_port *s = dev_get_drvdata(port->dev);
346
347 if (unlikely(port->x_char)) {
348 sccnxp_port_write(port, SCCNXP_THR_REG, port->x_char);
349 port->icount.tx++;
350 port->x_char = 0;
351 return;
352 }
353
354 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
355 /* Disable TX if FIFO is empty */
356 if (sccnxp_port_read(port, SCCNXP_SR_REG) & SR_TXEMT) {
357 sccnxp_disable_irq(port, IMR_TXRDY);
358
359 /* Set direction to input */
360 if (s->flags & SCCNXP_HAVE_IO)
361 sccnxp_set_bit(port, DIR_OP, 0);
362 }
363 return;
364 }
365
366 while (!uart_circ_empty(xmit)) {
367 sr = sccnxp_port_read(port, SCCNXP_SR_REG);
368 if (!(sr & SR_TXRDY))
369 break;
370
371 sccnxp_port_write(port, SCCNXP_THR_REG, xmit->buf[xmit->tail]);
372 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
373 port->icount.tx++;
374 }
375
376 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
377 uart_write_wakeup(port);
378}
379
380static irqreturn_t sccnxp_ist(int irq, void *dev_id)
381{
382 int i;
383 u8 isr;
384 struct sccnxp_port *s = (struct sccnxp_port *)dev_id;
385
386 mutex_lock(&s->sccnxp_mutex);
387
388 for (;;) {
389 isr = sccnxp_read(&s->port[0], SCCNXP_ISR_REG);
390 isr &= s->imr;
391 if (!isr)
392 break;
393
394 dev_dbg(s->port[0].dev, "IRQ status: 0x%02x\n", isr);
395
396 for (i = 0; i < s->uart.nr; i++) {
397 if (isr & ISR_RXRDY(i))
398 sccnxp_handle_rx(&s->port[i]);
399 if (isr & ISR_TXRDY(i))
400 sccnxp_handle_tx(&s->port[i]);
401 }
402 }
403
404 mutex_unlock(&s->sccnxp_mutex);
405
406 return IRQ_HANDLED;
407}
408
409static void sccnxp_start_tx(struct uart_port *port)
410{
411 struct sccnxp_port *s = dev_get_drvdata(port->dev);
412
413 mutex_lock(&s->sccnxp_mutex);
414
415 /* Set direction to output */
416 if (s->flags & SCCNXP_HAVE_IO)
417 sccnxp_set_bit(port, DIR_OP, 1);
418
419 sccnxp_enable_irq(port, IMR_TXRDY);
420
421 mutex_unlock(&s->sccnxp_mutex);
422}
423
424static void sccnxp_stop_tx(struct uart_port *port)
425{
426 /* Do nothing */
427}
428
429static void sccnxp_stop_rx(struct uart_port *port)
430{
431 struct sccnxp_port *s = dev_get_drvdata(port->dev);
432
433 mutex_lock(&s->sccnxp_mutex);
434 sccnxp_port_write(port, SCCNXP_CR_REG, CR_RX_DISABLE);
435 mutex_unlock(&s->sccnxp_mutex);
436}
437
438static unsigned int sccnxp_tx_empty(struct uart_port *port)
439{
440 u8 val;
441 struct sccnxp_port *s = dev_get_drvdata(port->dev);
442
443 mutex_lock(&s->sccnxp_mutex);
444 val = sccnxp_port_read(port, SCCNXP_SR_REG);
445 mutex_unlock(&s->sccnxp_mutex);
446
447 return (val & SR_TXEMT) ? TIOCSER_TEMT : 0;
448}
449
450static void sccnxp_enable_ms(struct uart_port *port)
451{
452 /* Do nothing */
453}
454
455static void sccnxp_set_mctrl(struct uart_port *port, unsigned int mctrl)
456{
457 struct sccnxp_port *s = dev_get_drvdata(port->dev);
458
459 if (!(s->flags & SCCNXP_HAVE_IO))
460 return;
461
462 mutex_lock(&s->sccnxp_mutex);
463
464 sccnxp_set_bit(port, DTR_OP, mctrl & TIOCM_DTR);
465 sccnxp_set_bit(port, RTS_OP, mctrl & TIOCM_RTS);
466
467 mutex_unlock(&s->sccnxp_mutex);
468}
469
470static unsigned int sccnxp_get_mctrl(struct uart_port *port)
471{
472 u8 bitmask, ipr;
473 struct sccnxp_port *s = dev_get_drvdata(port->dev);
474 unsigned int mctrl = TIOCM_DSR | TIOCM_CTS | TIOCM_CAR;
475
476 if (!(s->flags & SCCNXP_HAVE_IO))
477 return mctrl;
478
479 mutex_lock(&s->sccnxp_mutex);
480
481 ipr = ~sccnxp_read(port, SCCNXP_IPCR_REG);
482
483 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(DSR_IP)) {
484 bitmask = 1 << MCTRL_IBIT(s->pdata.mctrl_cfg[port->line],
485 DSR_IP);
486 mctrl &= ~TIOCM_DSR;
487 mctrl |= (ipr & bitmask) ? TIOCM_DSR : 0;
488 }
489 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(CTS_IP)) {
490 bitmask = 1 << MCTRL_IBIT(s->pdata.mctrl_cfg[port->line],
491 CTS_IP);
492 mctrl &= ~TIOCM_CTS;
493 mctrl |= (ipr & bitmask) ? TIOCM_CTS : 0;
494 }
495 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(DCD_IP)) {
496 bitmask = 1 << MCTRL_IBIT(s->pdata.mctrl_cfg[port->line],
497 DCD_IP);
498 mctrl &= ~TIOCM_CAR;
499 mctrl |= (ipr & bitmask) ? TIOCM_CAR : 0;
500 }
501 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(RNG_IP)) {
502 bitmask = 1 << MCTRL_IBIT(s->pdata.mctrl_cfg[port->line],
503 RNG_IP);
504 mctrl &= ~TIOCM_RNG;
505 mctrl |= (ipr & bitmask) ? TIOCM_RNG : 0;
506 }
507
508 mutex_unlock(&s->sccnxp_mutex);
509
510 return mctrl;
511}
512
513static void sccnxp_break_ctl(struct uart_port *port, int break_state)
514{
515 struct sccnxp_port *s = dev_get_drvdata(port->dev);
516
517 mutex_lock(&s->sccnxp_mutex);
518 sccnxp_port_write(port, SCCNXP_CR_REG, break_state ?
519 CR_CMD_START_BREAK : CR_CMD_STOP_BREAK);
520 mutex_unlock(&s->sccnxp_mutex);
521}
522
523static void sccnxp_set_termios(struct uart_port *port,
524 struct ktermios *termios, struct ktermios *old)
525{
526 struct sccnxp_port *s = dev_get_drvdata(port->dev);
527 u8 mr1, mr2;
528 int baud;
529
530 mutex_lock(&s->sccnxp_mutex);
531
532 /* Mask termios capabilities we don't support */
533 termios->c_cflag &= ~CMSPAR;
534
535 /* Disable RX & TX, reset break condition, status and FIFOs */
536 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_RX_RESET |
537 CR_RX_DISABLE | CR_TX_DISABLE);
538 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_TX_RESET);
539 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_STATUS_RESET);
540 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_BREAK_RESET);
541
542 /* Word size */
543 switch (termios->c_cflag & CSIZE) {
544 case CS5:
545 mr1 = MR1_BITS_5;
546 break;
547 case CS6:
548 mr1 = MR1_BITS_6;
549 break;
550 case CS7:
551 mr1 = MR1_BITS_7;
552 break;
553 case CS8:
554 default:
555 mr1 = MR1_BITS_8;
556 break;
557 }
558
559 /* Parity */
560 if (termios->c_cflag & PARENB) {
561 if (termios->c_cflag & PARODD)
562 mr1 |= MR1_PAR_ODD;
563 } else
564 mr1 |= MR1_PAR_NO;
565
566 /* Stop bits */
567 mr2 = (termios->c_cflag & CSTOPB) ? MR2_STOP2 : MR2_STOP1;
568
569 /* Update desired format */
570 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_MRPTR1);
571 sccnxp_port_write(port, SCCNXP_MR_REG, mr1);
572 sccnxp_port_write(port, SCCNXP_MR_REG, mr2);
573
574 /* Set read status mask */
575 port->read_status_mask = SR_OVR;
576 if (termios->c_iflag & INPCK)
577 port->read_status_mask |= SR_PE | SR_FE;
578 if (termios->c_iflag & (BRKINT | PARMRK))
579 port->read_status_mask |= SR_BRK;
580
581 /* Set status ignore mask */
582 port->ignore_status_mask = 0;
583 if (termios->c_iflag & IGNBRK)
584 port->ignore_status_mask |= SR_BRK;
585 if (!(termios->c_cflag & CREAD))
586 port->ignore_status_mask |= SR_PE | SR_OVR | SR_FE | SR_BRK;
587
588 /* Setup baudrate */
589 baud = uart_get_baud_rate(port, termios, old, 50,
590 (s->flags & SCCNXP_HAVE_MR0) ?
591 230400 : 38400);
592 baud = sccnxp_set_baud(port, baud);
593
594 /* Update timeout according to new baud rate */
595 uart_update_timeout(port, termios->c_cflag, baud);
596
597 if (tty_termios_baud_rate(termios))
598 tty_termios_encode_baud_rate(termios, baud, baud);
599
600 /* Enable RX & TX */
601 sccnxp_port_write(port, SCCNXP_CR_REG, CR_RX_ENABLE | CR_TX_ENABLE);
602
603 mutex_unlock(&s->sccnxp_mutex);
604}
605
606static int sccnxp_startup(struct uart_port *port)
607{
608 struct sccnxp_port *s = dev_get_drvdata(port->dev);
609
610 mutex_lock(&s->sccnxp_mutex);
611
612 if (s->flags & SCCNXP_HAVE_IO) {
613 /* Outputs are controlled manually */
614 sccnxp_write(port, SCCNXP_OPCR_REG, 0);
615 }
616
617 /* Reset break condition, status and FIFOs */
618 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_RX_RESET);
619 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_TX_RESET);
620 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_STATUS_RESET);
621 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_BREAK_RESET);
622
623 /* Enable RX & TX */
624 sccnxp_port_write(port, SCCNXP_CR_REG, CR_RX_ENABLE | CR_TX_ENABLE);
625
626 /* Enable RX interrupt */
627 sccnxp_enable_irq(port, IMR_RXRDY);
628
629 mutex_unlock(&s->sccnxp_mutex);
630
631 return 0;
632}
633
634static void sccnxp_shutdown(struct uart_port *port)
635{
636 struct sccnxp_port *s = dev_get_drvdata(port->dev);
637
638 mutex_lock(&s->sccnxp_mutex);
639
640 /* Disable interrupts */
641 sccnxp_disable_irq(port, IMR_TXRDY | IMR_RXRDY);
642
643 /* Disable TX & RX */
644 sccnxp_port_write(port, SCCNXP_CR_REG, CR_RX_DISABLE | CR_TX_DISABLE);
645
646 /* Leave direction to input */
647 if (s->flags & SCCNXP_HAVE_IO)
648 sccnxp_set_bit(port, DIR_OP, 0);
649
650 mutex_unlock(&s->sccnxp_mutex);
651}
652
653static const char *sccnxp_type(struct uart_port *port)
654{
655 struct sccnxp_port *s = dev_get_drvdata(port->dev);
656
657 return (port->type == PORT_SC26XX) ? s->name : NULL;
658}
659
660static void sccnxp_release_port(struct uart_port *port)
661{
662 /* Do nothing */
663}
664
665static int sccnxp_request_port(struct uart_port *port)
666{
667 /* Do nothing */
668 return 0;
669}
670
671static void sccnxp_config_port(struct uart_port *port, int flags)
672{
673 if (flags & UART_CONFIG_TYPE)
674 port->type = PORT_SC26XX;
675}
676
677static int sccnxp_verify_port(struct uart_port *port, struct serial_struct *s)
678{
679 if ((s->type == PORT_UNKNOWN) || (s->type == PORT_SC26XX))
680 return 0;
681 if (s->irq == port->irq)
682 return 0;
683
684 return -EINVAL;
685}
686
687static const struct uart_ops sccnxp_ops = {
688 .tx_empty = sccnxp_tx_empty,
689 .set_mctrl = sccnxp_set_mctrl,
690 .get_mctrl = sccnxp_get_mctrl,
691 .stop_tx = sccnxp_stop_tx,
692 .start_tx = sccnxp_start_tx,
693 .stop_rx = sccnxp_stop_rx,
694 .enable_ms = sccnxp_enable_ms,
695 .break_ctl = sccnxp_break_ctl,
696 .startup = sccnxp_startup,
697 .shutdown = sccnxp_shutdown,
698 .set_termios = sccnxp_set_termios,
699 .type = sccnxp_type,
700 .release_port = sccnxp_release_port,
701 .request_port = sccnxp_request_port,
702 .config_port = sccnxp_config_port,
703 .verify_port = sccnxp_verify_port,
704};
705
706#ifdef CONFIG_SERIAL_SCCNXP_CONSOLE
707static void sccnxp_console_putchar(struct uart_port *port, int c)
708{
709 int tryes = 100000;
710
711 while (tryes--) {
712 if (sccnxp_port_read(port, SCCNXP_SR_REG) & SR_TXRDY) {
713 sccnxp_port_write(port, SCCNXP_THR_REG, c);
714 break;
715 }
716 barrier();
717 }
718}
719
720static void sccnxp_console_write(struct console *co, const char *c, unsigned n)
721{
722 struct sccnxp_port *s = (struct sccnxp_port *)co->data;
723 struct uart_port *port = &s->port[co->index];
724
725 mutex_lock(&s->sccnxp_mutex);
726 uart_console_write(port, c, n, sccnxp_console_putchar);
727 mutex_unlock(&s->sccnxp_mutex);
728}
729
730static int sccnxp_console_setup(struct console *co, char *options)
731{
732 struct sccnxp_port *s = (struct sccnxp_port *)co->data;
733 struct uart_port *port = &s->port[(co->index > 0) ? co->index : 0];
734 int baud = 9600, bits = 8, parity = 'n', flow = 'n';
735
736 if (options)
737 uart_parse_options(options, &baud, &parity, &bits, &flow);
738
739 return uart_set_options(port, co, baud, parity, bits, flow);
740}
741#endif
742
743static int sccnxp_probe(struct platform_device *pdev)
744{
745 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
746 int chiptype = pdev->id_entry->driver_data;
747 struct sccnxp_pdata *pdata = dev_get_platdata(&pdev->dev);
748 int i, ret, fifosize, freq_min, freq_max;
749 struct sccnxp_port *s;
750 void __iomem *membase;
751
752 if (!res) {
753 dev_err(&pdev->dev, "Missing memory resource data\n");
754 return -EADDRNOTAVAIL;
755 }
756
757 dev_set_name(&pdev->dev, SCCNXP_NAME);
758
759 s = devm_kzalloc(&pdev->dev, sizeof(struct sccnxp_port), GFP_KERNEL);
760 if (!s) {
761 dev_err(&pdev->dev, "Error allocating port structure\n");
762 return -ENOMEM;
763 }
764 platform_set_drvdata(pdev, s);
765
766 mutex_init(&s->sccnxp_mutex);
767
768 /* Individual chip settings */
769 switch (chiptype) {
770 case SCCNXP_TYPE_SC2681:
771 s->name = "SC2681";
772 s->uart.nr = 2;
773 s->freq_std = 3686400;
774 s->addr_mask = 0x0f;
775 s->flags = SCCNXP_HAVE_IO;
776 fifosize = 3;
777 freq_min = 1000000;
778 freq_max = 4000000;
779 break;
780 case SCCNXP_TYPE_SC2691:
781 s->name = "SC2691";
782 s->uart.nr = 1;
783 s->freq_std = 3686400;
784 s->addr_mask = 0x07;
785 s->flags = 0;
786 fifosize = 3;
787 freq_min = 1000000;
788 freq_max = 4000000;
789 break;
790 case SCCNXP_TYPE_SC2692:
791 s->name = "SC2692";
792 s->uart.nr = 2;
793 s->freq_std = 3686400;
794 s->addr_mask = 0x0f;
795 s->flags = SCCNXP_HAVE_IO;
796 fifosize = 3;
797 freq_min = 1000000;
798 freq_max = 4000000;
799 break;
800 case SCCNXP_TYPE_SC2891:
801 s->name = "SC2891";
802 s->uart.nr = 1;
803 s->freq_std = 3686400;
804 s->addr_mask = 0x0f;
805 s->flags = SCCNXP_HAVE_IO | SCCNXP_HAVE_MR0;
806 fifosize = 16;
807 freq_min = 100000;
808 freq_max = 8000000;
809 break;
810 case SCCNXP_TYPE_SC2892:
811 s->name = "SC2892";
812 s->uart.nr = 2;
813 s->freq_std = 3686400;
814 s->addr_mask = 0x0f;
815 s->flags = SCCNXP_HAVE_IO | SCCNXP_HAVE_MR0;
816 fifosize = 16;
817 freq_min = 100000;
818 freq_max = 8000000;
819 break;
820 case SCCNXP_TYPE_SC28202:
821 s->name = "SC28202";
822 s->uart.nr = 2;
823 s->freq_std = 14745600;
824 s->addr_mask = 0x7f;
825 s->flags = SCCNXP_HAVE_IO | SCCNXP_HAVE_MR0;
826 fifosize = 256;
827 freq_min = 1000000;
828 freq_max = 50000000;
829 break;
830 case SCCNXP_TYPE_SC68681:
831 s->name = "SC68681";
832 s->uart.nr = 2;
833 s->freq_std = 3686400;
834 s->addr_mask = 0x0f;
835 s->flags = SCCNXP_HAVE_IO;
836 fifosize = 3;
837 freq_min = 1000000;
838 freq_max = 4000000;
839 break;
840 case SCCNXP_TYPE_SC68692:
841 s->name = "SC68692";
842 s->uart.nr = 2;
843 s->freq_std = 3686400;
844 s->addr_mask = 0x0f;
845 s->flags = SCCNXP_HAVE_IO;
846 fifosize = 3;
847 freq_min = 1000000;
848 freq_max = 4000000;
849 break;
850 default:
851 dev_err(&pdev->dev, "Unsupported chip type %i\n", chiptype);
852 ret = -ENOTSUPP;
853 goto err_out;
854 }
855
856 if (!pdata) {
857 dev_warn(&pdev->dev,
858 "No platform data supplied, using defaults\n");
859 s->pdata.frequency = s->freq_std;
860 } else
861 memcpy(&s->pdata, pdata, sizeof(struct sccnxp_pdata));
862
863 s->irq = platform_get_irq(pdev, 0);
864 if (s->irq <= 0) {
865 dev_err(&pdev->dev, "Missing irq resource data\n");
866 ret = -ENXIO;
867 goto err_out;
868 }
869
870 /* Check input frequency */
871 if ((s->pdata.frequency < freq_min) ||
872 (s->pdata.frequency > freq_max)) {
873 dev_err(&pdev->dev, "Frequency out of bounds\n");
874 ret = -EINVAL;
875 goto err_out;
876 }
877
878 membase = devm_request_and_ioremap(&pdev->dev, res);
879 if (!membase) {
880 dev_err(&pdev->dev, "Failed to ioremap\n");
881 ret = -EIO;
882 goto err_out;
883 }
884
885 s->uart.owner = THIS_MODULE;
886 s->uart.dev_name = "ttySC";
887 s->uart.major = SCCNXP_MAJOR;
888 s->uart.minor = SCCNXP_MINOR;
889#ifdef CONFIG_SERIAL_SCCNXP_CONSOLE
890 s->uart.cons = &s->console;
891 s->uart.cons->device = uart_console_device;
892 s->uart.cons->write = sccnxp_console_write;
893 s->uart.cons->setup = sccnxp_console_setup;
894 s->uart.cons->flags = CON_PRINTBUFFER;
895 s->uart.cons->index = -1;
896 s->uart.cons->data = s;
897 strcpy(s->uart.cons->name, "ttySC");
898#endif
899 ret = uart_register_driver(&s->uart);
900 if (ret) {
901 dev_err(&pdev->dev, "Registering UART driver failed\n");
902 goto err_out;
903 }
904
905 for (i = 0; i < s->uart.nr; i++) {
906 s->port[i].line = i;
907 s->port[i].dev = &pdev->dev;
908 s->port[i].irq = s->irq;
909 s->port[i].type = PORT_SC26XX;
910 s->port[i].fifosize = fifosize;
911 s->port[i].flags = UPF_SKIP_TEST | UPF_FIXED_TYPE;
912 s->port[i].iotype = UPIO_MEM;
913 s->port[i].mapbase = res->start;
914 s->port[i].membase = membase;
915 s->port[i].regshift = s->pdata.reg_shift;
916 s->port[i].uartclk = s->pdata.frequency;
917 s->port[i].ops = &sccnxp_ops;
918 uart_add_one_port(&s->uart, &s->port[i]);
919 /* Set direction to input */
920 if (s->flags & SCCNXP_HAVE_IO)
921 sccnxp_set_bit(&s->port[i], DIR_OP, 0);
922 }
923
924 /* Disable interrupts */
925 s->imr = 0;
926 sccnxp_write(&s->port[0], SCCNXP_IMR_REG, 0);
927
928 /* Board specific configure */
929 if (s->pdata.init)
930 s->pdata.init();
931
932 ret = devm_request_threaded_irq(&pdev->dev, s->irq, NULL, sccnxp_ist,
933 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
934 dev_name(&pdev->dev), s);
935 if (!ret)
936 return 0;
937
938 dev_err(&pdev->dev, "Unable to reguest IRQ %i\n", s->irq);
939
940err_out:
941 platform_set_drvdata(pdev, NULL);
942
943 return ret;
944}
945
946static int sccnxp_remove(struct platform_device *pdev)
947{
948 int i;
949 struct sccnxp_port *s = platform_get_drvdata(pdev);
950
951 devm_free_irq(&pdev->dev, s->irq, s);
952
953 for (i = 0; i < s->uart.nr; i++)
954 uart_remove_one_port(&s->uart, &s->port[i]);
955
956 uart_unregister_driver(&s->uart);
957 platform_set_drvdata(pdev, NULL);
958
959 if (s->pdata.exit)
960 s->pdata.exit();
961
962 return 0;
963}
964
965static const struct platform_device_id sccnxp_id_table[] = {
966 { "sc2681", SCCNXP_TYPE_SC2681 },
967 { "sc2691", SCCNXP_TYPE_SC2691 },
968 { "sc2692", SCCNXP_TYPE_SC2692 },
969 { "sc2891", SCCNXP_TYPE_SC2891 },
970 { "sc2892", SCCNXP_TYPE_SC2892 },
971 { "sc28202", SCCNXP_TYPE_SC28202 },
972 { "sc68681", SCCNXP_TYPE_SC68681 },
973 { "sc68692", SCCNXP_TYPE_SC68692 },
974 { },
975};
976MODULE_DEVICE_TABLE(platform, sccnxp_id_table);
977
978static struct platform_driver sccnxp_uart_driver = {
979 .driver = {
980 .name = SCCNXP_NAME,
981 .owner = THIS_MODULE,
982 },
983 .probe = sccnxp_probe,
984 .remove = sccnxp_remove,
985 .id_table = sccnxp_id_table,
986};
987module_platform_driver(sccnxp_uart_driver);
988
989MODULE_LICENSE("GPL v2");
990MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>");
991MODULE_DESCRIPTION("SCCNXP serial driver");
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 2c7230aaefd..681955ac328 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -22,7 +22,6 @@
22 */ 22 */
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/tty.h> 24#include <linux/tty.h>
25#include <linux/tty_flip.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27#include <linux/init.h> 26#include <linux/init.h>
28#include <linux/console.h> 27#include <linux/console.h>
@@ -58,11 +57,9 @@ static struct lock_class_key port_lock_key;
58 57
59static 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,
60 struct ktermios *old_termios); 59 struct ktermios *old_termios);
61static void uart_wait_until_sent(struct tty_struct *tty, int timeout); 60static void __uart_wait_until_sent(struct uart_port *port, int timeout);
62static void uart_change_pm(struct uart_state *state, int pm_state); 61static void uart_change_pm(struct uart_state *state, int pm_state);
63 62
64static void uart_port_shutdown(struct tty_port *port);
65
66/* 63/*
67 * This routine is used by the interrupt handler to schedule processing in 64 * This routine is used by the interrupt handler to schedule processing in
68 * the software interrupt portion of the driver. 65 * the software interrupt portion of the driver.
@@ -75,7 +72,7 @@ void uart_write_wakeup(struct uart_port *port)
75 * closed. No cookie for you. 72 * closed. No cookie for you.
76 */ 73 */
77 BUG_ON(!state); 74 BUG_ON(!state);
78 tty_wakeup(state->port.tty); 75 tasklet_schedule(&state->tlet);
79} 76}
80 77
81static void uart_stop(struct tty_struct *tty) 78static void uart_stop(struct tty_struct *tty)
@@ -94,6 +91,9 @@ static void __uart_start(struct tty_struct *tty)
94 struct uart_state *state = tty->driver_data; 91 struct uart_state *state = tty->driver_data;
95 struct uart_port *port = state->uart_port; 92 struct uart_port *port = state->uart_port;
96 93
94 if (port->ops->wake_peer)
95 port->ops->wake_peer(port);
96
97 if (!uart_circ_empty(&state->xmit) && state->xmit.buf && 97 if (!uart_circ_empty(&state->xmit) && state->xmit.buf &&
98 !tty->stopped && !tty->hw_stopped) 98 !tty->stopped && !tty->hw_stopped)
99 port->ops->start_tx(port); 99 port->ops->start_tx(port);
@@ -110,6 +110,12 @@ static void uart_start(struct tty_struct *tty)
110 spin_unlock_irqrestore(&port->lock, flags); 110 spin_unlock_irqrestore(&port->lock, flags);
111} 111}
112 112
113static void uart_tasklet_action(unsigned long data)
114{
115 struct uart_state *state = (struct uart_state *)data;
116 tty_wakeup(state->port.tty);
117}
118
113static inline void 119static inline void
114uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear) 120uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
115{ 121{
@@ -131,16 +137,25 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
131 * Startup the port. This will be called once per open. All calls 137 * Startup the port. This will be called once per open. All calls
132 * will be serialised by the per-port mutex. 138 * will be serialised by the per-port mutex.
133 */ 139 */
134static int uart_port_startup(struct tty_struct *tty, struct uart_state *state, 140static int uart_startup(struct tty_struct *tty, struct uart_state *state, int init_hw)
135 int init_hw)
136{ 141{
137 struct uart_port *uport = state->uart_port; 142 struct uart_port *uport = state->uart_port;
138 struct tty_port *port = &state->port; 143 struct tty_port *port = &state->port;
139 unsigned long page; 144 unsigned long page;
140 int retval = 0; 145 int retval = 0;
141 146
147 if (port->flags & ASYNC_INITIALIZED)
148 return 0;
149
150 /*
151 * Set the TTY IO error marker - we will only clear this
152 * once we have successfully opened the port. Also set
153 * up the tty->alt_speed kludge
154 */
155 set_bit(TTY_IO_ERROR, &tty->flags);
156
142 if (uport->type == PORT_UNKNOWN) 157 if (uport->type == PORT_UNKNOWN)
143 return 1; 158 return 0;
144 159
145 /* 160 /*
146 * Initialise and allocate the transmit and temporary 161 * Initialise and allocate the transmit and temporary
@@ -159,7 +174,7 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state,
159 retval = uport->ops->startup(uport); 174 retval = uport->ops->startup(uport);
160 if (retval == 0) { 175 if (retval == 0) {
161 if (uart_console(uport) && uport->cons->cflag) { 176 if (uart_console(uport) && uport->cons->cflag) {
162 tty->termios.c_cflag = uport->cons->cflag; 177 tty->termios->c_cflag = uport->cons->cflag;
163 uport->cons->cflag = 0; 178 uport->cons->cflag = 0;
164 } 179 }
165 /* 180 /*
@@ -172,16 +187,20 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state,
172 * Setup the RTS and DTR signals once the 187 * Setup the RTS and DTR signals once the
173 * port is open and ready to respond. 188 * port is open and ready to respond.
174 */ 189 */
175 if (tty->termios.c_cflag & CBAUD) 190 if (tty->termios->c_cflag & CBAUD)
176 uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR); 191 uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR);
177 } 192 }
178 193
179 if (tty_port_cts_enabled(port)) { 194 if (port->flags & ASYNC_CTS_FLOW) {
180 spin_lock_irq(&uport->lock); 195 spin_lock_irq(&uport->lock);
181 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS)) 196 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS))
182 tty->hw_stopped = 1; 197 tty->hw_stopped = 1;
183 spin_unlock_irq(&uport->lock); 198 spin_unlock_irq(&uport->lock);
184 } 199 }
200
201 set_bit(ASYNCB_INITIALIZED, &port->flags);
202
203 clear_bit(TTY_IO_ERROR, &tty->flags);
185 } 204 }
186 205
187 /* 206 /*
@@ -190,31 +209,6 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state,
190 * now. 209 * now.
191 */ 210 */
192 if (retval && capable(CAP_SYS_ADMIN)) 211 if (retval && capable(CAP_SYS_ADMIN))
193 return 1;
194
195 return retval;
196}
197
198static int uart_startup(struct tty_struct *tty, struct uart_state *state,
199 int init_hw)
200{
201 struct tty_port *port = &state->port;
202 int retval;
203
204 if (port->flags & ASYNC_INITIALIZED)
205 return 0;
206
207 /*
208 * Set the TTY IO error marker - we will only clear this
209 * once we have successfully opened the port.
210 */
211 set_bit(TTY_IO_ERROR, &tty->flags);
212
213 retval = uart_port_startup(tty, state, init_hw);
214 if (!retval) {
215 set_bit(ASYNCB_INITIALIZED, &port->flags);
216 clear_bit(TTY_IO_ERROR, &tty->flags);
217 } else if (retval > 0)
218 retval = 0; 212 retval = 0;
219 213
220 return retval; 214 return retval;
@@ -240,18 +234,33 @@ static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
240 /* 234 /*
241 * Turn off DTR and RTS early. 235 * Turn off DTR and RTS early.
242 */ 236 */
243 if (!tty || (tty->termios.c_cflag & HUPCL)) 237 if (!tty || (tty->termios->c_cflag & HUPCL))
244 uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS); 238 uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
245 239
246 uart_port_shutdown(port); 240 /*
241 * clear delta_msr_wait queue to avoid mem leaks: we may free
242 * the irq here so the queue might never be woken up. Note
243 * that we won't end up waiting on delta_msr_wait again since
244 * any outstanding file descriptors should be pointing at
245 * hung_up_tty_fops now.
246 */
247 wake_up_interruptible(&port->delta_msr_wait);
248
249 /*
250 * Free the IRQ and disable the port.
251 */
252 uport->ops->shutdown(uport);
253
254 /*
255 * Ensure that the IRQ handler isn't running on another CPU.
256 */
257 synchronize_irq(uport->irq);
247 } 258 }
248 259
249 /* 260 /*
250 * It's possible for shutdown to be called after suspend if we get 261 * kill off our tasklet
251 * a DCD drop (hangup) at just the right time. Clear suspended bit so
252 * we don't try to resume a port that has been shutdown.
253 */ 262 */
254 clear_bit(ASYNCB_SUSPENDED, &port->flags); 263 tasklet_kill(&state->tlet);
255 264
256 /* 265 /*
257 * Free the transmit buffer page. 266 * Free the transmit buffer page.
@@ -421,7 +430,7 @@ uart_get_divisor(struct uart_port *port, unsigned int baud)
421 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) 430 if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
422 quot = port->custom_divisor; 431 quot = port->custom_divisor;
423 else 432 else
424 quot = DIV_ROUND_CLOSEST(port->uartclk, 16 * baud); 433 quot = (port->uartclk + (8 * baud)) / (16 * baud);
425 434
426 return quot; 435 return quot;
427} 436}
@@ -440,10 +449,10 @@ static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
440 * If we have no tty, termios, or the port does not exist, 449 * If we have no tty, termios, or the port does not exist,
441 * then we can't set the parameters for this port. 450 * then we can't set the parameters for this port.
442 */ 451 */
443 if (!tty || uport->type == PORT_UNKNOWN) 452 if (!tty || !tty->termios || uport->type == PORT_UNKNOWN)
444 return; 453 return;
445 454
446 termios = &tty->termios; 455 termios = tty->termios;
447 456
448 /* 457 /*
449 * Set flags based on termios cflag 458 * Set flags based on termios cflag
@@ -610,126 +619,104 @@ static void uart_send_xchar(struct tty_struct *tty, char ch)
610static void uart_throttle(struct tty_struct *tty) 619static void uart_throttle(struct tty_struct *tty)
611{ 620{
612 struct uart_state *state = tty->driver_data; 621 struct uart_state *state = tty->driver_data;
613 struct uart_port *port = state->uart_port;
614 uint32_t mask = 0;
615 622
616 if (I_IXOFF(tty)) 623 if (I_IXOFF(tty))
617 mask |= UPF_SOFT_FLOW;
618 if (tty->termios.c_cflag & CRTSCTS)
619 mask |= UPF_HARD_FLOW;
620
621 if (port->flags & mask) {
622 port->ops->throttle(port);
623 mask &= ~port->flags;
624 }
625
626 if (mask & UPF_SOFT_FLOW)
627 uart_send_xchar(tty, STOP_CHAR(tty)); 624 uart_send_xchar(tty, STOP_CHAR(tty));
628 625
629 if (mask & UPF_HARD_FLOW) 626 if (tty->termios->c_cflag & CRTSCTS)
630 uart_clear_mctrl(port, TIOCM_RTS); 627 uart_clear_mctrl(state->uart_port, TIOCM_RTS);
631} 628}
632 629
633static void uart_unthrottle(struct tty_struct *tty) 630static void uart_unthrottle(struct tty_struct *tty)
634{ 631{
635 struct uart_state *state = tty->driver_data; 632 struct uart_state *state = tty->driver_data;
636 struct uart_port *port = state->uart_port; 633 struct uart_port *port = state->uart_port;
637 uint32_t mask = 0;
638
639 if (I_IXOFF(tty))
640 mask |= UPF_SOFT_FLOW;
641 if (tty->termios.c_cflag & CRTSCTS)
642 mask |= UPF_HARD_FLOW;
643
644 if (port->flags & mask) {
645 port->ops->unthrottle(port);
646 mask &= ~port->flags;
647 }
648 634
649 if (mask & UPF_SOFT_FLOW) { 635 if (I_IXOFF(tty)) {
650 if (port->x_char) 636 if (port->x_char)
651 port->x_char = 0; 637 port->x_char = 0;
652 else 638 else
653 uart_send_xchar(tty, START_CHAR(tty)); 639 uart_send_xchar(tty, START_CHAR(tty));
654 } 640 }
655 641
656 if (mask & UPF_HARD_FLOW) 642 if (tty->termios->c_cflag & CRTSCTS)
657 uart_set_mctrl(port, TIOCM_RTS); 643 uart_set_mctrl(port, TIOCM_RTS);
658} 644}
659 645
660static void do_uart_get_info(struct tty_port *port, 646static int uart_get_info(struct uart_state *state,
661 struct serial_struct *retinfo) 647 struct serial_struct __user *retinfo)
662{ 648{
663 struct uart_state *state = container_of(port, struct uart_state, port);
664 struct uart_port *uport = state->uart_port; 649 struct uart_port *uport = state->uart_port;
650 struct tty_port *port = &state->port;
651 struct serial_struct tmp;
665 652
666 memset(retinfo, 0, sizeof(*retinfo)); 653 memset(&tmp, 0, sizeof(tmp));
667
668 retinfo->type = uport->type;
669 retinfo->line = uport->line;
670 retinfo->port = uport->iobase;
671 if (HIGH_BITS_OFFSET)
672 retinfo->port_high = (long) uport->iobase >> HIGH_BITS_OFFSET;
673 retinfo->irq = uport->irq;
674 retinfo->flags = uport->flags;
675 retinfo->xmit_fifo_size = uport->fifosize;
676 retinfo->baud_base = uport->uartclk / 16;
677 retinfo->close_delay = jiffies_to_msecs(port->close_delay) / 10;
678 retinfo->closing_wait = port->closing_wait == ASYNC_CLOSING_WAIT_NONE ?
679 ASYNC_CLOSING_WAIT_NONE :
680 jiffies_to_msecs(port->closing_wait) / 10;
681 retinfo->custom_divisor = uport->custom_divisor;
682 retinfo->hub6 = uport->hub6;
683 retinfo->io_type = uport->iotype;
684 retinfo->iomem_reg_shift = uport->regshift;
685 retinfo->iomem_base = (void *)(unsigned long)uport->mapbase;
686}
687 654
688static void uart_get_info(struct tty_port *port,
689 struct serial_struct *retinfo)
690{
691 /* Ensure the state we copy is consistent and no hardware changes 655 /* Ensure the state we copy is consistent and no hardware changes
692 occur as we go */ 656 occur as we go */
693 mutex_lock(&port->mutex); 657 mutex_lock(&port->mutex);
694 do_uart_get_info(port, retinfo);
695 mutex_unlock(&port->mutex);
696}
697 658
698static int uart_get_info_user(struct tty_port *port, 659 tmp.type = uport->type;
699 struct serial_struct __user *retinfo) 660 tmp.line = uport->line;
700{ 661 tmp.port = uport->iobase;
701 struct serial_struct tmp; 662 if (HIGH_BITS_OFFSET)
702 uart_get_info(port, &tmp); 663 tmp.port_high = (long) uport->iobase >> HIGH_BITS_OFFSET;
664 tmp.irq = uport->irq;
665 tmp.flags = uport->flags;
666 tmp.xmit_fifo_size = uport->fifosize;
667 tmp.baud_base = uport->uartclk / 16;
668 tmp.close_delay = port->close_delay / 10;
669 tmp.closing_wait = port->closing_wait == ASYNC_CLOSING_WAIT_NONE ?
670 ASYNC_CLOSING_WAIT_NONE :
671 port->closing_wait / 10;
672 tmp.custom_divisor = uport->custom_divisor;
673 tmp.hub6 = uport->hub6;
674 tmp.io_type = uport->iotype;
675 tmp.iomem_reg_shift = uport->regshift;
676 tmp.iomem_base = (void *)(unsigned long)uport->mapbase;
677
678 mutex_unlock(&port->mutex);
703 679
704 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 680 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
705 return -EFAULT; 681 return -EFAULT;
706 return 0; 682 return 0;
707} 683}
708 684
709static int uart_set_info(struct tty_struct *tty, struct tty_port *port, 685static int uart_set_info(struct tty_struct *tty, struct uart_state *state,
710 struct uart_state *state, 686 struct serial_struct __user *newinfo)
711 struct serial_struct *new_info)
712{ 687{
688 struct serial_struct new_serial;
713 struct uart_port *uport = state->uart_port; 689 struct uart_port *uport = state->uart_port;
690 struct tty_port *port = &state->port;
714 unsigned long new_port; 691 unsigned long new_port;
715 unsigned int change_irq, change_port, closing_wait; 692 unsigned int change_irq, change_port, closing_wait;
716 unsigned int old_custom_divisor, close_delay; 693 unsigned int old_custom_divisor, close_delay;
717 upf_t old_flags, new_flags; 694 upf_t old_flags, new_flags;
718 int retval = 0; 695 int retval = 0;
719 696
720 new_port = new_info->port; 697 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
698 return -EFAULT;
699
700 new_port = new_serial.port;
721 if (HIGH_BITS_OFFSET) 701 if (HIGH_BITS_OFFSET)
722 new_port += (unsigned long) new_info->port_high << HIGH_BITS_OFFSET; 702 new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET;
723 703
724 new_info->irq = irq_canonicalize(new_info->irq); 704 new_serial.irq = irq_canonicalize(new_serial.irq);
725 close_delay = msecs_to_jiffies(new_info->close_delay * 10); 705 close_delay = new_serial.close_delay * 10;
726 closing_wait = new_info->closing_wait == ASYNC_CLOSING_WAIT_NONE ? 706 closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
727 ASYNC_CLOSING_WAIT_NONE : 707 ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
728 msecs_to_jiffies(new_info->closing_wait * 10);
729 708
709 /*
710 * This semaphore protects port->count. It is also
711 * very useful to prevent opens. Also, take the
712 * port configuration semaphore to make sure that a
713 * module insertion/removal doesn't change anything
714 * under us.
715 */
716 mutex_lock(&port->mutex);
730 717
731 change_irq = !(uport->flags & UPF_FIXED_PORT) 718 change_irq = !(uport->flags & UPF_FIXED_PORT)
732 && new_info->irq != uport->irq; 719 && new_serial.irq != uport->irq;
733 720
734 /* 721 /*
735 * Since changing the 'type' of the port changes its resource 722 * Since changing the 'type' of the port changes its resource
@@ -738,29 +725,29 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
738 */ 725 */
739 change_port = !(uport->flags & UPF_FIXED_PORT) 726 change_port = !(uport->flags & UPF_FIXED_PORT)
740 && (new_port != uport->iobase || 727 && (new_port != uport->iobase ||
741 (unsigned long)new_info->iomem_base != uport->mapbase || 728 (unsigned long)new_serial.iomem_base != uport->mapbase ||
742 new_info->hub6 != uport->hub6 || 729 new_serial.hub6 != uport->hub6 ||
743 new_info->io_type != uport->iotype || 730 new_serial.io_type != uport->iotype ||
744 new_info->iomem_reg_shift != uport->regshift || 731 new_serial.iomem_reg_shift != uport->regshift ||
745 new_info->type != uport->type); 732 new_serial.type != uport->type);
746 733
747 old_flags = uport->flags; 734 old_flags = uport->flags;
748 new_flags = new_info->flags; 735 new_flags = new_serial.flags;
749 old_custom_divisor = uport->custom_divisor; 736 old_custom_divisor = uport->custom_divisor;
750 737
751 if (!capable(CAP_SYS_ADMIN)) { 738 if (!capable(CAP_SYS_ADMIN)) {
752 retval = -EPERM; 739 retval = -EPERM;
753 if (change_irq || change_port || 740 if (change_irq || change_port ||
754 (new_info->baud_base != uport->uartclk / 16) || 741 (new_serial.baud_base != uport->uartclk / 16) ||
755 (close_delay != port->close_delay) || 742 (close_delay != port->close_delay) ||
756 (closing_wait != port->closing_wait) || 743 (closing_wait != port->closing_wait) ||
757 (new_info->xmit_fifo_size && 744 (new_serial.xmit_fifo_size &&
758 new_info->xmit_fifo_size != uport->fifosize) || 745 new_serial.xmit_fifo_size != uport->fifosize) ||
759 (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0)) 746 (((new_flags ^ old_flags) & ~UPF_USR_MASK) != 0))
760 goto exit; 747 goto exit;
761 uport->flags = ((uport->flags & ~UPF_USR_MASK) | 748 uport->flags = ((uport->flags & ~UPF_USR_MASK) |
762 (new_flags & UPF_USR_MASK)); 749 (new_flags & UPF_USR_MASK));
763 uport->custom_divisor = new_info->custom_divisor; 750 uport->custom_divisor = new_serial.custom_divisor;
764 goto check_and_exit; 751 goto check_and_exit;
765 } 752 }
766 753
@@ -768,10 +755,10 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
768 * Ask the low level driver to verify the settings. 755 * Ask the low level driver to verify the settings.
769 */ 756 */
770 if (uport->ops->verify_port) 757 if (uport->ops->verify_port)
771 retval = uport->ops->verify_port(uport, new_info); 758 retval = uport->ops->verify_port(uport, &new_serial);
772 759
773 if ((new_info->irq >= nr_irqs) || (new_info->irq < 0) || 760 if ((new_serial.irq >= nr_irqs) || (new_serial.irq < 0) ||
774 (new_info->baud_base < 9600)) 761 (new_serial.baud_base < 9600))
775 retval = -EINVAL; 762 retval = -EINVAL;
776 763
777 if (retval) 764 if (retval)
@@ -811,11 +798,11 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
811 uport->ops->release_port(uport); 798 uport->ops->release_port(uport);
812 799
813 uport->iobase = new_port; 800 uport->iobase = new_port;
814 uport->type = new_info->type; 801 uport->type = new_serial.type;
815 uport->hub6 = new_info->hub6; 802 uport->hub6 = new_serial.hub6;
816 uport->iotype = new_info->io_type; 803 uport->iotype = new_serial.io_type;
817 uport->regshift = new_info->iomem_reg_shift; 804 uport->regshift = new_serial.iomem_reg_shift;
818 uport->mapbase = (unsigned long)new_info->iomem_base; 805 uport->mapbase = (unsigned long)new_serial.iomem_base;
819 806
820 /* 807 /*
821 * Claim and map the new regions 808 * Claim and map the new regions
@@ -856,16 +843,16 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
856 } 843 }
857 844
858 if (change_irq) 845 if (change_irq)
859 uport->irq = new_info->irq; 846 uport->irq = new_serial.irq;
860 if (!(uport->flags & UPF_FIXED_PORT)) 847 if (!(uport->flags & UPF_FIXED_PORT))
861 uport->uartclk = new_info->baud_base * 16; 848 uport->uartclk = new_serial.baud_base * 16;
862 uport->flags = (uport->flags & ~UPF_CHANGE_MASK) | 849 uport->flags = (uport->flags & ~UPF_CHANGE_MASK) |
863 (new_flags & UPF_CHANGE_MASK); 850 (new_flags & UPF_CHANGE_MASK);
864 uport->custom_divisor = new_info->custom_divisor; 851 uport->custom_divisor = new_serial.custom_divisor;
865 port->close_delay = close_delay; 852 port->close_delay = close_delay;
866 port->closing_wait = closing_wait; 853 port->closing_wait = closing_wait;
867 if (new_info->xmit_fifo_size) 854 if (new_serial.xmit_fifo_size)
868 uport->fifosize = new_info->xmit_fifo_size; 855 uport->fifosize = new_serial.xmit_fifo_size;
869 if (port->tty) 856 if (port->tty)
870 port->tty->low_latency = 857 port->tty->low_latency =
871 (uport->flags & UPF_LOW_LATENCY) ? 1 : 0; 858 (uport->flags & UPF_LOW_LATENCY) ? 1 : 0;
@@ -894,28 +881,6 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
894 } else 881 } else
895 retval = uart_startup(tty, state, 1); 882 retval = uart_startup(tty, state, 1);
896 exit: 883 exit:
897 return retval;
898}
899
900static int uart_set_info_user(struct tty_struct *tty, struct uart_state *state,
901 struct serial_struct __user *newinfo)
902{
903 struct serial_struct new_serial;
904 struct tty_port *port = &state->port;
905 int retval;
906
907 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
908 return -EFAULT;
909
910 /*
911 * This semaphore protects port->count. It is also
912 * very useful to prevent opens. Also, take the
913 * port configuration semaphore to make sure that a
914 * module insertion/removal doesn't change anything
915 * under us.
916 */
917 mutex_lock(&port->mutex);
918 retval = uart_set_info(tty, port, state, &new_serial);
919 mutex_unlock(&port->mutex); 884 mutex_unlock(&port->mutex);
920 return retval; 885 return retval;
921} 886}
@@ -1158,11 +1123,11 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd,
1158 */ 1123 */
1159 switch (cmd) { 1124 switch (cmd) {
1160 case TIOCGSERIAL: 1125 case TIOCGSERIAL:
1161 ret = uart_get_info_user(port, uarg); 1126 ret = uart_get_info(state, uarg);
1162 break; 1127 break;
1163 1128
1164 case TIOCSSERIAL: 1129 case TIOCSSERIAL:
1165 ret = uart_set_info_user(tty, state, uarg); 1130 ret = uart_set_info(tty, state, uarg);
1166 break; 1131 break;
1167 1132
1168 case TIOCSERCONFIG: 1133 case TIOCSERCONFIG:
@@ -1230,29 +1195,16 @@ static void uart_set_ldisc(struct tty_struct *tty)
1230 struct uart_port *uport = state->uart_port; 1195 struct uart_port *uport = state->uart_port;
1231 1196
1232 if (uport->ops->set_ldisc) 1197 if (uport->ops->set_ldisc)
1233 uport->ops->set_ldisc(uport, tty->termios.c_line); 1198 uport->ops->set_ldisc(uport, tty->termios->c_line);
1234} 1199}
1235 1200
1236static void uart_set_termios(struct tty_struct *tty, 1201static void uart_set_termios(struct tty_struct *tty,
1237 struct ktermios *old_termios) 1202 struct ktermios *old_termios)
1238{ 1203{
1239 struct uart_state *state = tty->driver_data; 1204 struct uart_state *state = tty->driver_data;
1240 struct uart_port *uport = state->uart_port;
1241 unsigned long flags; 1205 unsigned long flags;
1242 unsigned int cflag = tty->termios.c_cflag; 1206 unsigned int cflag = tty->termios->c_cflag;
1243 unsigned int iflag_mask = IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK;
1244 bool sw_changed = false;
1245 1207
1246 /*
1247 * Drivers doing software flow control also need to know
1248 * about changes to these input settings.
1249 */
1250 if (uport->flags & UPF_SOFT_FLOW) {
1251 iflag_mask |= IXANY|IXON|IXOFF;
1252 sw_changed =
1253 tty->termios.c_cc[VSTART] != old_termios->c_cc[VSTART] ||
1254 tty->termios.c_cc[VSTOP] != old_termios->c_cc[VSTOP];
1255 }
1256 1208
1257 /* 1209 /*
1258 * These are the bits that are used to setup various 1210 * These are the bits that are used to setup various
@@ -1260,11 +1212,11 @@ static void uart_set_termios(struct tty_struct *tty,
1260 * bits in c_cflag; c_[io]speed will always be set 1212 * bits in c_cflag; c_[io]speed will always be set
1261 * appropriately by set_termios() in tty_ioctl.c 1213 * appropriately by set_termios() in tty_ioctl.c
1262 */ 1214 */
1215#define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1263 if ((cflag ^ old_termios->c_cflag) == 0 && 1216 if ((cflag ^ old_termios->c_cflag) == 0 &&
1264 tty->termios.c_ospeed == old_termios->c_ospeed && 1217 tty->termios->c_ospeed == old_termios->c_ospeed &&
1265 tty->termios.c_ispeed == old_termios->c_ispeed && 1218 tty->termios->c_ispeed == old_termios->c_ispeed &&
1266 ((tty->termios.c_iflag ^ old_termios->c_iflag) & iflag_mask) == 0 && 1219 RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0) {
1267 !sw_changed) {
1268 return; 1220 return;
1269 } 1221 }
1270 1222
@@ -1272,38 +1224,31 @@ static void uart_set_termios(struct tty_struct *tty,
1272 1224
1273 /* Handle transition to B0 status */ 1225 /* Handle transition to B0 status */
1274 if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) 1226 if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
1275 uart_clear_mctrl(uport, TIOCM_RTS | TIOCM_DTR); 1227 uart_clear_mctrl(state->uart_port, TIOCM_RTS | TIOCM_DTR);
1276 /* Handle transition away from B0 status */ 1228 /* Handle transition away from B0 status */
1277 else if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { 1229 else if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
1278 unsigned int mask = TIOCM_DTR; 1230 unsigned int mask = TIOCM_DTR;
1279 if (!(cflag & CRTSCTS) || 1231 if (!(cflag & CRTSCTS) ||
1280 !test_bit(TTY_THROTTLED, &tty->flags)) 1232 !test_bit(TTY_THROTTLED, &tty->flags))
1281 mask |= TIOCM_RTS; 1233 mask |= TIOCM_RTS;
1282 uart_set_mctrl(uport, mask); 1234 uart_set_mctrl(state->uart_port, mask);
1283 } 1235 }
1284 1236
1285 /*
1286 * If the port is doing h/w assisted flow control, do nothing.
1287 * We assume that tty->hw_stopped has never been set.
1288 */
1289 if (uport->flags & UPF_HARD_FLOW)
1290 return;
1291
1292 /* Handle turning off CRTSCTS */ 1237 /* Handle turning off CRTSCTS */
1293 if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) { 1238 if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) {
1294 spin_lock_irqsave(&uport->lock, flags); 1239 spin_lock_irqsave(&state->uart_port->lock, flags);
1295 tty->hw_stopped = 0; 1240 tty->hw_stopped = 0;
1296 __uart_start(tty); 1241 __uart_start(tty);
1297 spin_unlock_irqrestore(&uport->lock, flags); 1242 spin_unlock_irqrestore(&state->uart_port->lock, flags);
1298 } 1243 }
1299 /* Handle turning on CRTSCTS */ 1244 /* Handle turning on CRTSCTS */
1300 else if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) { 1245 else if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
1301 spin_lock_irqsave(&uport->lock, flags); 1246 spin_lock_irqsave(&state->uart_port->lock, flags);
1302 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS)) { 1247 if (!(state->uart_port->ops->get_mctrl(state->uart_port) & TIOCM_CTS)) {
1303 tty->hw_stopped = 1; 1248 tty->hw_stopped = 1;
1304 uport->ops->stop_tx(uport); 1249 state->uart_port->ops->stop_tx(state->uart_port);
1305 } 1250 }
1306 spin_unlock_irqrestore(&uport->lock, flags); 1251 spin_unlock_irqrestore(&state->uart_port->lock, flags);
1307 } 1252 }
1308} 1253}
1309 1254
@@ -1319,6 +1264,8 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1319 struct uart_port *uport; 1264 struct uart_port *uport;
1320 unsigned long flags; 1265 unsigned long flags;
1321 1266
1267 BUG_ON(!tty_locked());
1268
1322 if (!state) 1269 if (!state)
1323 return; 1270 return;
1324 1271
@@ -1327,8 +1274,54 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1327 1274
1328 pr_debug("uart_close(%d) called\n", uport->line); 1275 pr_debug("uart_close(%d) called\n", uport->line);
1329 1276
1330 if (tty_port_close_start(port, tty, filp) == 0) 1277 mutex_lock(&port->mutex);
1331 return; 1278 spin_lock_irqsave(&port->lock, flags);
1279
1280 if (tty_hung_up_p(filp)) {
1281 spin_unlock_irqrestore(&port->lock, flags);
1282 goto done;
1283 }
1284
1285 if ((tty->count == 1) && (port->count != 1)) {
1286 /*
1287 * Uh, oh. tty->count is 1, which means that the tty
1288 * structure will be freed. port->count should always
1289 * be one in these conditions. If it's greater than
1290 * one, we've got real problems, since it means the
1291 * serial port won't be shutdown.
1292 */
1293 printk(KERN_ERR "uart_close: bad serial port count; tty->count is 1, "
1294 "port->count is %d\n", port->count);
1295 port->count = 1;
1296 }
1297 if (--port->count < 0) {
1298 printk(KERN_ERR "uart_close: bad serial port count for %s: %d\n",
1299 tty->name, port->count);
1300 port->count = 0;
1301 }
1302 if (port->count) {
1303 spin_unlock_irqrestore(&port->lock, flags);
1304 goto done;
1305 }
1306
1307 /*
1308 * Now we wait for the transmit buffer to clear; and we notify
1309 * the line discipline to only process XON/XOFF characters by
1310 * setting tty->closing.
1311 */
1312 tty->closing = 1;
1313 spin_unlock_irqrestore(&port->lock, flags);
1314
1315 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
1316 /*
1317 * hack: open-coded tty_wait_until_sent to avoid
1318 * recursive tty_lock
1319 */
1320 long timeout = msecs_to_jiffies(port->closing_wait);
1321 if (wait_event_interruptible_timeout(tty->write_wait,
1322 !tty_chars_in_buffer(tty), timeout) >= 0)
1323 __uart_wait_until_sent(uport, timeout);
1324 }
1332 1325
1333 /* 1326 /*
1334 * At this point, we stop accepting input. To do this, we 1327 * At this point, we stop accepting input. To do this, we
@@ -1344,10 +1337,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1344 * has completely drained; this is especially 1337 * has completely drained; this is especially
1345 * important if there is a transmit FIFO! 1338 * important if there is a transmit FIFO!
1346 */ 1339 */
1347 uart_wait_until_sent(tty, uport->timeout); 1340 __uart_wait_until_sent(uport, uport->timeout);
1348 } 1341 }
1349 1342
1350 mutex_lock(&port->mutex);
1351 uart_shutdown(tty, state); 1343 uart_shutdown(tty, state);
1352 uart_flush_buffer(tty); 1344 uart_flush_buffer(tty);
1353 1345
@@ -1360,8 +1352,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1360 if (port->blocked_open) { 1352 if (port->blocked_open) {
1361 spin_unlock_irqrestore(&port->lock, flags); 1353 spin_unlock_irqrestore(&port->lock, flags);
1362 if (port->close_delay) 1354 if (port->close_delay)
1363 msleep_interruptible( 1355 msleep_interruptible(port->close_delay);
1364 jiffies_to_msecs(port->close_delay));
1365 spin_lock_irqsave(&port->lock, flags); 1356 spin_lock_irqsave(&port->lock, flags);
1366 } else if (!uart_console(uport)) { 1357 } else if (!uart_console(uport)) {
1367 spin_unlock_irqrestore(&port->lock, flags); 1358 spin_unlock_irqrestore(&port->lock, flags);
@@ -1373,18 +1364,15 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1373 * Wake up anyone trying to open this port. 1364 * Wake up anyone trying to open this port.
1374 */ 1365 */
1375 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags); 1366 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1376 clear_bit(ASYNCB_CLOSING, &port->flags);
1377 spin_unlock_irqrestore(&port->lock, flags); 1367 spin_unlock_irqrestore(&port->lock, flags);
1378 wake_up_interruptible(&port->open_wait); 1368 wake_up_interruptible(&port->open_wait);
1379 wake_up_interruptible(&port->close_wait);
1380 1369
1370done:
1381 mutex_unlock(&port->mutex); 1371 mutex_unlock(&port->mutex);
1382} 1372}
1383 1373
1384static void uart_wait_until_sent(struct tty_struct *tty, int timeout) 1374static void __uart_wait_until_sent(struct uart_port *port, int timeout)
1385{ 1375{
1386 struct uart_state *state = tty->driver_data;
1387 struct uart_port *port = state->uart_port;
1388 unsigned long char_time, expire; 1376 unsigned long char_time, expire;
1389 1377
1390 if (port->type == PORT_UNKNOWN || port->fifosize == 0) 1378 if (port->type == PORT_UNKNOWN || port->fifosize == 0)
@@ -1436,6 +1424,16 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1436 } 1424 }
1437} 1425}
1438 1426
1427static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1428{
1429 struct uart_state *state = tty->driver_data;
1430 struct uart_port *port = state->uart_port;
1431
1432 tty_lock();
1433 __uart_wait_until_sent(port, timeout);
1434 tty_unlock();
1435}
1436
1439/* 1437/*
1440 * This is called with the BKL held in 1438 * This is called with the BKL held in
1441 * linux/drivers/char/tty_io.c:do_tty_hangup() 1439 * linux/drivers/char/tty_io.c:do_tty_hangup()
@@ -1448,6 +1446,7 @@ static void uart_hangup(struct tty_struct *tty)
1448 struct tty_port *port = &state->port; 1446 struct tty_port *port = &state->port;
1449 unsigned long flags; 1447 unsigned long flags;
1450 1448
1449 BUG_ON(!tty_locked());
1451 pr_debug("uart_hangup(%d)\n", state->uart_port->line); 1450 pr_debug("uart_hangup(%d)\n", state->uart_port->line);
1452 1451
1453 mutex_lock(&port->mutex); 1452 mutex_lock(&port->mutex);
@@ -1465,36 +1464,6 @@ static void uart_hangup(struct tty_struct *tty)
1465 mutex_unlock(&port->mutex); 1464 mutex_unlock(&port->mutex);
1466} 1465}
1467 1466
1468static int uart_port_activate(struct tty_port *port, struct tty_struct *tty)
1469{
1470 return 0;
1471}
1472
1473static void uart_port_shutdown(struct tty_port *port)
1474{
1475 struct uart_state *state = container_of(port, struct uart_state, port);
1476 struct uart_port *uport = state->uart_port;
1477
1478 /*
1479 * clear delta_msr_wait queue to avoid mem leaks: we may free
1480 * the irq here so the queue might never be woken up. Note
1481 * that we won't end up waiting on delta_msr_wait again since
1482 * any outstanding file descriptors should be pointing at
1483 * hung_up_tty_fops now.
1484 */
1485 wake_up_interruptible(&port->delta_msr_wait);
1486
1487 /*
1488 * Free the IRQ and disable the port.
1489 */
1490 uport->ops->shutdown(uport);
1491
1492 /*
1493 * Ensure that the IRQ handler isn't running on another CPU.
1494 */
1495 synchronize_irq(uport->irq);
1496}
1497
1498static int uart_carrier_raised(struct tty_port *port) 1467static int uart_carrier_raised(struct tty_port *port)
1499{ 1468{
1500 struct uart_state *state = container_of(port, struct uart_state, port); 1469 struct uart_state *state = container_of(port, struct uart_state, port);
@@ -1520,6 +1489,33 @@ static void uart_dtr_rts(struct tty_port *port, int onoff)
1520 uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS); 1489 uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
1521} 1490}
1522 1491
1492static struct uart_state *uart_get(struct uart_driver *drv, int line)
1493{
1494 struct uart_state *state;
1495 struct tty_port *port;
1496 int ret = 0;
1497
1498 state = drv->state + line;
1499 port = &state->port;
1500 if (mutex_lock_interruptible(&port->mutex)) {
1501 ret = -ERESTARTSYS;
1502 goto err;
1503 }
1504
1505 port->count++;
1506 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
1507 ret = -ENXIO;
1508 goto err_unlock;
1509 }
1510 return state;
1511
1512 err_unlock:
1513 port->count--;
1514 mutex_unlock(&port->mutex);
1515 err:
1516 return ERR_PTR(ret);
1517}
1518
1523/* 1519/*
1524 * calls to uart_open are serialised by the BKL in 1520 * calls to uart_open are serialised by the BKL in
1525 * fs/char_dev.c:chrdev_open() 1521 * fs/char_dev.c:chrdev_open()
@@ -1533,29 +1529,27 @@ static void uart_dtr_rts(struct tty_port *port, int onoff)
1533static int uart_open(struct tty_struct *tty, struct file *filp) 1529static int uart_open(struct tty_struct *tty, struct file *filp)
1534{ 1530{
1535 struct uart_driver *drv = (struct uart_driver *)tty->driver->driver_state; 1531 struct uart_driver *drv = (struct uart_driver *)tty->driver->driver_state;
1532 struct uart_state *state;
1533 struct tty_port *port;
1536 int retval, line = tty->index; 1534 int retval, line = tty->index;
1537 struct uart_state *state = drv->state + line;
1538 struct tty_port *port = &state->port;
1539 1535
1536 BUG_ON(!tty_locked());
1540 pr_debug("uart_open(%d) called\n", line); 1537 pr_debug("uart_open(%d) called\n", line);
1541 1538
1542 /* 1539 /*
1543 * We take the semaphore here to guarantee that we won't be re-entered 1540 * We take the semaphore inside uart_get to guarantee that we won't
1544 * while allocating the state structure, or while we request any IRQs 1541 * be re-entered while allocating the state structure, or while we
1545 * that the driver may need. This also has the nice side-effect that 1542 * request any IRQs that the driver may need. This also has the nice
1546 * it delays the action of uart_hangup, so we can guarantee that 1543 * side-effect that it delays the action of uart_hangup, so we can
1547 * state->port.tty will always contain something reasonable. 1544 * guarantee that state->port.tty will always contain something
1545 * reasonable.
1548 */ 1546 */
1549 if (mutex_lock_interruptible(&port->mutex)) { 1547 state = uart_get(drv, line);
1550 retval = -ERESTARTSYS; 1548 if (IS_ERR(state)) {
1551 goto end; 1549 retval = PTR_ERR(state);
1552 } 1550 goto fail;
1553
1554 port->count++;
1555 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
1556 retval = -ENXIO;
1557 goto err_dec_count;
1558 } 1551 }
1552 port = &state->port;
1559 1553
1560 /* 1554 /*
1561 * Once we set tty->driver_data here, we are guaranteed that 1555 * Once we set tty->driver_data here, we are guaranteed that
@@ -1565,6 +1559,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1565 tty->driver_data = state; 1559 tty->driver_data = state;
1566 state->uart_port->state = state; 1560 state->uart_port->state = state;
1567 tty->low_latency = (state->uart_port->flags & UPF_LOW_LATENCY) ? 1 : 0; 1561 tty->low_latency = (state->uart_port->flags & UPF_LOW_LATENCY) ? 1 : 0;
1562 tty->alt_speed = 0;
1568 tty_port_tty_set(port, tty); 1563 tty_port_tty_set(port, tty);
1569 1564
1570 /* 1565 /*
@@ -1572,7 +1567,9 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1572 */ 1567 */
1573 if (tty_hung_up_p(filp)) { 1568 if (tty_hung_up_p(filp)) {
1574 retval = -EAGAIN; 1569 retval = -EAGAIN;
1575 goto err_dec_count; 1570 port->count--;
1571 mutex_unlock(&port->mutex);
1572 goto fail;
1576 } 1573 }
1577 1574
1578 /* 1575 /*
@@ -1593,12 +1590,8 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1593 if (retval == 0) 1590 if (retval == 0)
1594 retval = tty_port_block_til_ready(port, tty, filp); 1591 retval = tty_port_block_til_ready(port, tty, filp);
1595 1592
1596end: 1593fail:
1597 return retval; 1594 return retval;
1598err_dec_count:
1599 port->count--;
1600 mutex_unlock(&port->mutex);
1601 goto end;
1602} 1595}
1603 1596
1604static const char *uart_type(struct uart_port *port) 1597static const char *uart_type(struct uart_port *port)
@@ -1889,14 +1882,6 @@ uart_set_options(struct uart_port *port, struct console *co,
1889EXPORT_SYMBOL_GPL(uart_set_options); 1882EXPORT_SYMBOL_GPL(uart_set_options);
1890#endif /* CONFIG_SERIAL_CORE_CONSOLE */ 1883#endif /* CONFIG_SERIAL_CORE_CONSOLE */
1891 1884
1892/**
1893 * uart_change_pm - set power state of the port
1894 *
1895 * @state: port descriptor
1896 * @pm_state: new state
1897 *
1898 * Locking: port->mutex has to be held
1899 */
1900static void uart_change_pm(struct uart_state *state, int pm_state) 1885static void uart_change_pm(struct uart_state *state, int pm_state)
1901{ 1886{
1902 struct uart_port *port = state->uart_port; 1887 struct uart_port *port = state->uart_port;
@@ -2023,12 +2008,13 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
2023 /* 2008 /*
2024 * If that's unset, use the tty termios setting. 2009 * If that's unset, use the tty termios setting.
2025 */ 2010 */
2026 if (port->tty && termios.c_cflag == 0) 2011 if (port->tty && port->tty->termios && termios.c_cflag == 0)
2027 termios = port->tty->termios; 2012 termios = *(port->tty->termios);
2028 2013
2029 if (console_suspend_enabled) 2014 if (console_suspend_enabled)
2030 uart_change_pm(state, 0); 2015 uart_change_pm(state, 0);
2031 uport->ops->set_termios(uport, &termios, NULL); 2016 if (uport->type != PORT_TEGRA)
2017 uport->ops->set_termios(uport, &termios, NULL);
2032 if (console_suspend_enabled) 2018 if (console_suspend_enabled)
2033 console_start(uport->cons); 2019 console_start(uport->cons);
2034 } 2020 }
@@ -2088,6 +2074,8 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port)
2088 case UPIO_MEM32: 2074 case UPIO_MEM32:
2089 case UPIO_AU: 2075 case UPIO_AU:
2090 case UPIO_TSI: 2076 case UPIO_TSI:
2077 case UPIO_DWAPB:
2078 case UPIO_DWAPB32:
2091 snprintf(address, sizeof(address), 2079 snprintf(address, sizeof(address),
2092 "MMIO 0x%llx", (unsigned long long)port->mapbase); 2080 "MMIO 0x%llx", (unsigned long long)port->mapbase);
2093 break; 2081 break;
@@ -2176,7 +2164,6 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options)
2176 int bits = 8; 2164 int bits = 8;
2177 int parity = 'n'; 2165 int parity = 'n';
2178 int flow = 'n'; 2166 int flow = 'n';
2179 int ret;
2180 2167
2181 if (!state || !state->uart_port) 2168 if (!state || !state->uart_port)
2182 return -1; 2169 return -1;
@@ -2185,22 +2172,6 @@ static int uart_poll_init(struct tty_driver *driver, int line, char *options)
2185 if (!(port->ops->poll_get_char && port->ops->poll_put_char)) 2172 if (!(port->ops->poll_get_char && port->ops->poll_put_char))
2186 return -1; 2173 return -1;
2187 2174
2188 if (port->ops->poll_init) {
2189 struct tty_port *tport = &state->port;
2190
2191 ret = 0;
2192 mutex_lock(&tport->mutex);
2193 /*
2194 * We don't set ASYNCB_INITIALIZED as we only initialized the
2195 * hw, e.g. state->xmit is still uninitialized.
2196 */
2197 if (!test_bit(ASYNCB_INITIALIZED, &tport->flags))
2198 ret = port->ops->poll_init(port);
2199 mutex_unlock(&tport->mutex);
2200 if (ret)
2201 return ret;
2202 }
2203
2204 if (options) { 2175 if (options) {
2205 uart_parse_options(options, &baud, &parity, &bits, &flow); 2176 uart_parse_options(options, &baud, &parity, &bits, &flow);
2206 return uart_set_options(port, NULL, baud, parity, bits, flow); 2177 return uart_set_options(port, NULL, baud, parity, bits, flow);
@@ -2270,8 +2241,6 @@ static const struct tty_operations uart_ops = {
2270}; 2241};
2271 2242
2272static const struct tty_port_operations uart_port_ops = { 2243static const struct tty_port_operations uart_port_ops = {
2273 .activate = uart_port_activate,
2274 .shutdown = uart_port_shutdown,
2275 .carrier_raised = uart_carrier_raised, 2244 .carrier_raised = uart_carrier_raised,
2276 .dtr_rts = uart_dtr_rts, 2245 .dtr_rts = uart_dtr_rts,
2277}; 2246};
@@ -2310,6 +2279,7 @@ int uart_register_driver(struct uart_driver *drv)
2310 2279
2311 drv->tty_driver = normal; 2280 drv->tty_driver = normal;
2312 2281
2282 normal->owner = drv->owner;
2313 normal->driver_name = drv->driver_name; 2283 normal->driver_name = drv->driver_name;
2314 normal->name = drv->dev_name; 2284 normal->name = drv->dev_name;
2315 normal->major = drv->major; 2285 normal->major = drv->major;
@@ -2332,16 +2302,16 @@ int uart_register_driver(struct uart_driver *drv)
2332 2302
2333 tty_port_init(port); 2303 tty_port_init(port);
2334 port->ops = &uart_port_ops; 2304 port->ops = &uart_port_ops;
2335 port->close_delay = HZ / 2; /* .5 seconds */ 2305 port->close_delay = 500; /* .5 seconds */
2336 port->closing_wait = 30 * HZ;/* 30 seconds */ 2306 port->closing_wait = 30000; /* 30 seconds */
2307 tasklet_init(&state->tlet, uart_tasklet_action,
2308 (unsigned long)state);
2337 } 2309 }
2338 2310
2339 retval = tty_register_driver(normal); 2311 retval = tty_register_driver(normal);
2340 if (retval >= 0) 2312 if (retval >= 0)
2341 return retval; 2313 return retval;
2342 2314
2343 for (i = 0; i < drv->nr; i++)
2344 tty_port_destroy(&drv->state[i].port);
2345 put_tty_driver(normal); 2315 put_tty_driver(normal);
2346out_kfree: 2316out_kfree:
2347 kfree(drv->state); 2317 kfree(drv->state);
@@ -2361,14 +2331,9 @@ out:
2361void uart_unregister_driver(struct uart_driver *drv) 2331void uart_unregister_driver(struct uart_driver *drv)
2362{ 2332{
2363 struct tty_driver *p = drv->tty_driver; 2333 struct tty_driver *p = drv->tty_driver;
2364 unsigned int i;
2365
2366 tty_unregister_driver(p); 2334 tty_unregister_driver(p);
2367 put_tty_driver(p); 2335 put_tty_driver(p);
2368 for (i = 0; i < drv->nr; i++)
2369 tty_port_destroy(&drv->state[i].port);
2370 kfree(drv->state); 2336 kfree(drv->state);
2371 drv->state = NULL;
2372 drv->tty_driver = NULL; 2337 drv->tty_driver = NULL;
2373} 2338}
2374 2339
@@ -2379,182 +2344,6 @@ struct tty_driver *uart_console_device(struct console *co, int *index)
2379 return p->tty_driver; 2344 return p->tty_driver;
2380} 2345}
2381 2346
2382static ssize_t uart_get_attr_uartclk(struct device *dev,
2383 struct device_attribute *attr, char *buf)
2384{
2385 struct serial_struct tmp;
2386 struct tty_port *port = dev_get_drvdata(dev);
2387
2388 uart_get_info(port, &tmp);
2389 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.baud_base * 16);
2390}
2391
2392static ssize_t uart_get_attr_type(struct device *dev,
2393 struct device_attribute *attr, char *buf)
2394{
2395 struct serial_struct tmp;
2396 struct tty_port *port = dev_get_drvdata(dev);
2397
2398 uart_get_info(port, &tmp);
2399 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.type);
2400}
2401static ssize_t uart_get_attr_line(struct device *dev,
2402 struct device_attribute *attr, char *buf)
2403{
2404 struct serial_struct tmp;
2405 struct tty_port *port = dev_get_drvdata(dev);
2406
2407 uart_get_info(port, &tmp);
2408 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.line);
2409}
2410
2411static ssize_t uart_get_attr_port(struct device *dev,
2412 struct device_attribute *attr, char *buf)
2413{
2414 struct serial_struct tmp;
2415 struct tty_port *port = dev_get_drvdata(dev);
2416 unsigned long ioaddr;
2417
2418 uart_get_info(port, &tmp);
2419 ioaddr = tmp.port;
2420 if (HIGH_BITS_OFFSET)
2421 ioaddr |= (unsigned long)tmp.port_high << HIGH_BITS_OFFSET;
2422 return snprintf(buf, PAGE_SIZE, "0x%lX\n", ioaddr);
2423}
2424
2425static ssize_t uart_get_attr_irq(struct device *dev,
2426 struct device_attribute *attr, char *buf)
2427{
2428 struct serial_struct tmp;
2429 struct tty_port *port = dev_get_drvdata(dev);
2430
2431 uart_get_info(port, &tmp);
2432 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.irq);
2433}
2434
2435static ssize_t uart_get_attr_flags(struct device *dev,
2436 struct device_attribute *attr, char *buf)
2437{
2438 struct serial_struct tmp;
2439 struct tty_port *port = dev_get_drvdata(dev);
2440
2441 uart_get_info(port, &tmp);
2442 return snprintf(buf, PAGE_SIZE, "0x%X\n", tmp.flags);
2443}
2444
2445static ssize_t uart_get_attr_xmit_fifo_size(struct device *dev,
2446 struct device_attribute *attr, char *buf)
2447{
2448 struct serial_struct tmp;
2449 struct tty_port *port = dev_get_drvdata(dev);
2450
2451 uart_get_info(port, &tmp);
2452 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.xmit_fifo_size);
2453}
2454
2455
2456static ssize_t uart_get_attr_close_delay(struct device *dev,
2457 struct device_attribute *attr, char *buf)
2458{
2459 struct serial_struct tmp;
2460 struct tty_port *port = dev_get_drvdata(dev);
2461
2462 uart_get_info(port, &tmp);
2463 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.close_delay);
2464}
2465
2466
2467static ssize_t uart_get_attr_closing_wait(struct device *dev,
2468 struct device_attribute *attr, char *buf)
2469{
2470 struct serial_struct tmp;
2471 struct tty_port *port = dev_get_drvdata(dev);
2472
2473 uart_get_info(port, &tmp);
2474 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.closing_wait);
2475}
2476
2477static ssize_t uart_get_attr_custom_divisor(struct device *dev,
2478 struct device_attribute *attr, char *buf)
2479{
2480 struct serial_struct tmp;
2481 struct tty_port *port = dev_get_drvdata(dev);
2482
2483 uart_get_info(port, &tmp);
2484 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.custom_divisor);
2485}
2486
2487static ssize_t uart_get_attr_io_type(struct device *dev,
2488 struct device_attribute *attr, char *buf)
2489{
2490 struct serial_struct tmp;
2491 struct tty_port *port = dev_get_drvdata(dev);
2492
2493 uart_get_info(port, &tmp);
2494 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.io_type);
2495}
2496
2497static ssize_t uart_get_attr_iomem_base(struct device *dev,
2498 struct device_attribute *attr, char *buf)
2499{
2500 struct serial_struct tmp;
2501 struct tty_port *port = dev_get_drvdata(dev);
2502
2503 uart_get_info(port, &tmp);
2504 return snprintf(buf, PAGE_SIZE, "0x%lX\n", (unsigned long)tmp.iomem_base);
2505}
2506
2507static ssize_t uart_get_attr_iomem_reg_shift(struct device *dev,
2508 struct device_attribute *attr, char *buf)
2509{
2510 struct serial_struct tmp;
2511 struct tty_port *port = dev_get_drvdata(dev);
2512
2513 uart_get_info(port, &tmp);
2514 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.iomem_reg_shift);
2515}
2516
2517static DEVICE_ATTR(type, S_IRUSR | S_IRGRP, uart_get_attr_type, NULL);
2518static DEVICE_ATTR(line, S_IRUSR | S_IRGRP, uart_get_attr_line, NULL);
2519static DEVICE_ATTR(port, S_IRUSR | S_IRGRP, uart_get_attr_port, NULL);
2520static DEVICE_ATTR(irq, S_IRUSR | S_IRGRP, uart_get_attr_irq, NULL);
2521static DEVICE_ATTR(flags, S_IRUSR | S_IRGRP, uart_get_attr_flags, NULL);
2522static DEVICE_ATTR(xmit_fifo_size, S_IRUSR | S_IRGRP, uart_get_attr_xmit_fifo_size, NULL);
2523static DEVICE_ATTR(uartclk, S_IRUSR | S_IRGRP, uart_get_attr_uartclk, NULL);
2524static DEVICE_ATTR(close_delay, S_IRUSR | S_IRGRP, uart_get_attr_close_delay, NULL);
2525static DEVICE_ATTR(closing_wait, S_IRUSR | S_IRGRP, uart_get_attr_closing_wait, NULL);
2526static DEVICE_ATTR(custom_divisor, S_IRUSR | S_IRGRP, uart_get_attr_custom_divisor, NULL);
2527static DEVICE_ATTR(io_type, S_IRUSR | S_IRGRP, uart_get_attr_io_type, NULL);
2528static DEVICE_ATTR(iomem_base, S_IRUSR | S_IRGRP, uart_get_attr_iomem_base, NULL);
2529static DEVICE_ATTR(iomem_reg_shift, S_IRUSR | S_IRGRP, uart_get_attr_iomem_reg_shift, NULL);
2530
2531static struct attribute *tty_dev_attrs[] = {
2532 &dev_attr_type.attr,
2533 &dev_attr_line.attr,
2534 &dev_attr_port.attr,
2535 &dev_attr_irq.attr,
2536 &dev_attr_flags.attr,
2537 &dev_attr_xmit_fifo_size.attr,
2538 &dev_attr_uartclk.attr,
2539 &dev_attr_close_delay.attr,
2540 &dev_attr_closing_wait.attr,
2541 &dev_attr_custom_divisor.attr,
2542 &dev_attr_io_type.attr,
2543 &dev_attr_iomem_base.attr,
2544 &dev_attr_iomem_reg_shift.attr,
2545 NULL,
2546 };
2547
2548static const struct attribute_group tty_dev_attr_group = {
2549 .attrs = tty_dev_attrs,
2550 };
2551
2552static const struct attribute_group *tty_dev_attr_groups[] = {
2553 &tty_dev_attr_group,
2554 NULL
2555 };
2556
2557
2558/** 2347/**
2559 * uart_add_one_port - attach a driver-defined port structure 2348 * uart_add_one_port - attach a driver-defined port structure
2560 * @drv: pointer to the uart low level driver structure for this port 2349 * @drv: pointer to the uart low level driver structure for this port
@@ -2608,14 +2397,13 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
2608 * Register the port whether it's detected or not. This allows 2397 * Register the port whether it's detected or not. This allows
2609 * setserial to be used to alter this ports parameters. 2398 * setserial to be used to alter this ports parameters.
2610 */ 2399 */
2611 tty_dev = tty_port_register_device_attr(port, drv->tty_driver, 2400 tty_dev = tty_register_device(drv->tty_driver, uport->line, uport->dev);
2612 uport->line, uport->dev, port, tty_dev_attr_groups);
2613 if (likely(!IS_ERR(tty_dev))) { 2401 if (likely(!IS_ERR(tty_dev))) {
2614 device_set_wakeup_capable(tty_dev, 1); 2402 device_init_wakeup(tty_dev, 1);
2615 } else { 2403 device_set_wakeup_enable(tty_dev, 0);
2404 } else
2616 printk(KERN_ERR "Cannot register tty device on line %d\n", 2405 printk(KERN_ERR "Cannot register tty device on line %d\n",
2617 uport->line); 2406 uport->line);
2618 }
2619 2407
2620 /* 2408 /*
2621 * Ensure UPF_DEAD is not set. 2409 * Ensure UPF_DEAD is not set.
@@ -2678,6 +2466,11 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *uport)
2678 */ 2466 */
2679 uport->type = PORT_UNKNOWN; 2467 uport->type = PORT_UNKNOWN;
2680 2468
2469 /*
2470 * Kill the tasklet, and free resources.
2471 */
2472 tasklet_kill(&state->tlet);
2473
2681 state->uart_port = NULL; 2474 state->uart_port = NULL;
2682 mutex_unlock(&port_mutex); 2475 mutex_unlock(&port_mutex);
2683 2476
@@ -2702,110 +2495,14 @@ int uart_match_port(struct uart_port *port1, struct uart_port *port2)
2702 case UPIO_MEM32: 2495 case UPIO_MEM32:
2703 case UPIO_AU: 2496 case UPIO_AU:
2704 case UPIO_TSI: 2497 case UPIO_TSI:
2498 case UPIO_DWAPB:
2499 case UPIO_DWAPB32:
2705 return (port1->mapbase == port2->mapbase); 2500 return (port1->mapbase == port2->mapbase);
2706 } 2501 }
2707 return 0; 2502 return 0;
2708} 2503}
2709EXPORT_SYMBOL(uart_match_port); 2504EXPORT_SYMBOL(uart_match_port);
2710 2505
2711/**
2712 * uart_handle_dcd_change - handle a change of carrier detect state
2713 * @uport: uart_port structure for the open port
2714 * @status: new carrier detect status, nonzero if active
2715 */
2716void uart_handle_dcd_change(struct uart_port *uport, unsigned int status)
2717{
2718 struct uart_state *state = uport->state;
2719 struct tty_port *port = &state->port;
2720 struct tty_ldisc *ld = NULL;
2721 struct pps_event_time ts;
2722 struct tty_struct *tty = port->tty;
2723
2724 if (tty)
2725 ld = tty_ldisc_ref(tty);
2726 if (ld && ld->ops->dcd_change)
2727 pps_get_ts(&ts);
2728
2729 uport->icount.dcd++;
2730#ifdef CONFIG_HARD_PPS
2731 if ((uport->flags & UPF_HARDPPS_CD) && status)
2732 hardpps();
2733#endif
2734
2735 if (port->flags & ASYNC_CHECK_CD) {
2736 if (status)
2737 wake_up_interruptible(&port->open_wait);
2738 else if (tty)
2739 tty_hangup(tty);
2740 }
2741
2742 if (ld && ld->ops->dcd_change)
2743 ld->ops->dcd_change(tty, status, &ts);
2744 if (ld)
2745 tty_ldisc_deref(ld);
2746}
2747EXPORT_SYMBOL_GPL(uart_handle_dcd_change);
2748
2749/**
2750 * uart_handle_cts_change - handle a change of clear-to-send state
2751 * @uport: uart_port structure for the open port
2752 * @status: new clear to send status, nonzero if active
2753 */
2754void uart_handle_cts_change(struct uart_port *uport, unsigned int status)
2755{
2756 struct tty_port *port = &uport->state->port;
2757 struct tty_struct *tty = port->tty;
2758
2759 uport->icount.cts++;
2760
2761 if (tty_port_cts_enabled(port)) {
2762 if (tty->hw_stopped) {
2763 if (status) {
2764 tty->hw_stopped = 0;
2765 uport->ops->start_tx(uport);
2766 uart_write_wakeup(uport);
2767 }
2768 } else {
2769 if (!status) {
2770 tty->hw_stopped = 1;
2771 uport->ops->stop_tx(uport);
2772 }
2773 }
2774 }
2775}
2776EXPORT_SYMBOL_GPL(uart_handle_cts_change);
2777
2778/**
2779 * uart_insert_char - push a char to the uart layer
2780 *
2781 * User is responsible to call tty_flip_buffer_push when they are done with
2782 * insertion.
2783 *
2784 * @port: corresponding port
2785 * @status: state of the serial port RX buffer (LSR for 8250)
2786 * @overrun: mask of overrun bits in @status
2787 * @ch: character to push
2788 * @flag: flag for the character (see TTY_NORMAL and friends)
2789 */
2790void uart_insert_char(struct uart_port *port, unsigned int status,
2791 unsigned int overrun, unsigned int ch, unsigned int flag)
2792{
2793 struct tty_struct *tty = port->state->port.tty;
2794
2795 if ((status & port->ignore_status_mask & ~overrun) == 0)
2796 if (tty_insert_flip_char(tty, ch, flag) == 0)
2797 ++port->icount.buf_overrun;
2798
2799 /*
2800 * Overrun is special. Since it's reported immediately,
2801 * it doesn't affect the current character.
2802 */
2803 if (status & ~port->ignore_status_mask & overrun)
2804 if (tty_insert_flip_char(tty, 0, TTY_OVERRUN) == 0)
2805 ++port->icount.buf_overrun;
2806}
2807EXPORT_SYMBOL_GPL(uart_insert_char);
2808
2809EXPORT_SYMBOL(uart_write_wakeup); 2506EXPORT_SYMBOL(uart_write_wakeup);
2810EXPORT_SYMBOL(uart_register_driver); 2507EXPORT_SYMBOL(uart_register_driver);
2811EXPORT_SYMBOL(uart_unregister_driver); 2508EXPORT_SYMBOL(uart_unregister_driver);
diff --git a/drivers/tty/serial/serial_ks8695.c b/drivers/tty/serial/serial_ks8695.c
index 9bd004f9da8..2430319f2f5 100644
--- a/drivers/tty/serial/serial_ks8695.c
+++ b/drivers/tty/serial/serial_ks8695.c
@@ -13,7 +13,6 @@
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>
17#include <linux/ioport.h> 16#include <linux/ioport.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/serial.h> 18#include <linux/serial.h>
@@ -337,19 +336,19 @@ static int ks8695uart_startup(struct uart_port *port)
337 /* 336 /*
338 * Allocate the IRQ 337 * Allocate the IRQ
339 */ 338 */
340 retval = request_irq(KS8695_IRQ_UART_TX, ks8695uart_tx_chars, 0, "UART TX", port); 339 retval = request_irq(KS8695_IRQ_UART_TX, ks8695uart_tx_chars, IRQF_DISABLED, "UART TX", port);
341 if (retval) 340 if (retval)
342 goto err_tx; 341 goto err_tx;
343 342
344 retval = request_irq(KS8695_IRQ_UART_RX, ks8695uart_rx_chars, 0, "UART RX", port); 343 retval = request_irq(KS8695_IRQ_UART_RX, ks8695uart_rx_chars, IRQF_DISABLED, "UART RX", port);
345 if (retval) 344 if (retval)
346 goto err_rx; 345 goto err_rx;
347 346
348 retval = request_irq(KS8695_IRQ_UART_LINE_STATUS, ks8695uart_rx_chars, 0, "UART LineStatus", port); 347 retval = request_irq(KS8695_IRQ_UART_LINE_STATUS, ks8695uart_rx_chars, IRQF_DISABLED, "UART LineStatus", port);
349 if (retval) 348 if (retval)
350 goto err_ls; 349 goto err_ls;
351 350
352 retval = request_irq(KS8695_IRQ_UART_MODEM_STATUS, ks8695uart_modem_status, 0, "UART ModemStatus", port); 351 retval = request_irq(KS8695_IRQ_UART_MODEM_STATUS, ks8695uart_modem_status, IRQF_DISABLED, "UART ModemStatus", port);
353 if (retval) 352 if (retval)
354 goto err_ms; 353 goto err_ms;
355 354
@@ -548,8 +547,8 @@ static struct uart_ops ks8695uart_pops = {
548 547
549static struct uart_port ks8695uart_ports[SERIAL_KS8695_NR] = { 548static struct uart_port ks8695uart_ports[SERIAL_KS8695_NR] = {
550 { 549 {
551 .membase = KS8695_UART_VA, 550 .membase = (void *) KS8695_UART_VA,
552 .mapbase = KS8695_UART_PA, 551 .mapbase = KS8695_UART_VA,
553 .iotype = SERIAL_IO_MEM, 552 .iotype = SERIAL_IO_MEM,
554 .irq = KS8695_IRQ_UART_TX, 553 .irq = KS8695_IRQ_UART_TX,
555 .uartclk = KS8695_CLOCK_RATE * 16, 554 .uartclk = KS8695_CLOCK_RATE * 16,
diff --git a/drivers/tty/serial/serial_txx9.c b/drivers/tty/serial/serial_txx9.c
index b52b21aeb25..8e3fc1944e6 100644
--- a/drivers/tty/serial/serial_txx9.c
+++ b/drivers/tty/serial/serial_txx9.c
@@ -28,8 +28,6 @@
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>
33 31
34#include <asm/io.h> 32#include <asm/io.h>
35 33
@@ -466,7 +464,7 @@ static void serial_txx9_break_ctl(struct uart_port *port, int break_state)
466 spin_unlock_irqrestore(&up->port.lock, flags); 464 spin_unlock_irqrestore(&up->port.lock, flags);
467} 465}
468 466
469#if defined(CONFIG_SERIAL_TXX9_CONSOLE) || defined(CONFIG_CONSOLE_POLL) 467#if defined(CONFIG_SERIAL_TXX9_CONSOLE) || (CONFIG_CONSOLE_POLL)
470/* 468/*
471 * Wait for transmitter & holding register to empty 469 * Wait for transmitter & holding register to empty
472 */ 470 */
@@ -1030,7 +1028,7 @@ static DEFINE_MUTEX(serial_txx9_mutex);
1030 * 1028 *
1031 * On success the port is ready to use and the line number is returned. 1029 * On success the port is ready to use and the line number is returned.
1032 */ 1030 */
1033static int serial_txx9_register_port(struct uart_port *port) 1031static int __devinit serial_txx9_register_port(struct uart_port *port)
1034{ 1032{
1035 int i; 1033 int i;
1036 struct uart_txx9_port *uart; 1034 struct uart_txx9_port *uart;
@@ -1078,7 +1076,7 @@ static int serial_txx9_register_port(struct uart_port *port)
1078 * Remove one serial port. This may not be called from interrupt 1076 * Remove one serial port. This may not be called from interrupt
1079 * context. We hand the port back to the our control. 1077 * context. We hand the port back to the our control.
1080 */ 1078 */
1081static void serial_txx9_unregister_port(int line) 1079static void __devexit serial_txx9_unregister_port(int line)
1082{ 1080{
1083 struct uart_txx9_port *uart = &serial_txx9_ports[line]; 1081 struct uart_txx9_port *uart = &serial_txx9_ports[line];
1084 1082
@@ -1096,7 +1094,7 @@ static void serial_txx9_unregister_port(int line)
1096/* 1094/*
1097 * Register a set of serial devices attached to a platform device. 1095 * Register a set of serial devices attached to a platform device.
1098 */ 1096 */
1099static int serial_txx9_probe(struct platform_device *dev) 1097static int __devinit serial_txx9_probe(struct platform_device *dev)
1100{ 1098{
1101 struct uart_port *p = dev->dev.platform_data; 1099 struct uart_port *p = dev->dev.platform_data;
1102 struct uart_port port; 1100 struct uart_port port;
@@ -1126,7 +1124,7 @@ static int serial_txx9_probe(struct platform_device *dev)
1126/* 1124/*
1127 * Remove serial ports registered against a platform device. 1125 * Remove serial ports registered against a platform device.
1128 */ 1126 */
1129static int serial_txx9_remove(struct platform_device *dev) 1127static int __devexit serial_txx9_remove(struct platform_device *dev)
1130{ 1128{
1131 int i; 1129 int i;
1132 1130
@@ -1171,7 +1169,7 @@ static int serial_txx9_resume(struct platform_device *dev)
1171 1169
1172static struct platform_driver serial_txx9_plat_driver = { 1170static struct platform_driver serial_txx9_plat_driver = {
1173 .probe = serial_txx9_probe, 1171 .probe = serial_txx9_probe,
1174 .remove = serial_txx9_remove, 1172 .remove = __devexit_p(serial_txx9_remove),
1175#ifdef CONFIG_PM 1173#ifdef CONFIG_PM
1176 .suspend = serial_txx9_suspend, 1174 .suspend = serial_txx9_suspend,
1177 .resume = serial_txx9_resume, 1175 .resume = serial_txx9_resume,
@@ -1187,7 +1185,7 @@ static struct platform_driver serial_txx9_plat_driver = {
1187 * Probe one serial board. Unfortunately, there is no rhyme nor reason 1185 * Probe one serial board. Unfortunately, there is no rhyme nor reason
1188 * to the arrangement of serial ports on a PCI card. 1186 * to the arrangement of serial ports on a PCI card.
1189 */ 1187 */
1190static int 1188static int __devinit
1191pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent) 1189pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
1192{ 1190{
1193 struct uart_port port; 1191 struct uart_port port;
@@ -1217,7 +1215,7 @@ pciserial_txx9_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
1217 return 0; 1215 return 0;
1218} 1216}
1219 1217
1220static void pciserial_txx9_remove_one(struct pci_dev *dev) 1218static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev)
1221{ 1219{
1222 struct uart_txx9_port *up = pci_get_drvdata(dev); 1220 struct uart_txx9_port *up = pci_get_drvdata(dev);
1223 1221
@@ -1261,7 +1259,7 @@ static const struct pci_device_id serial_txx9_pci_tbl[] = {
1261static struct pci_driver serial_txx9_pci_driver = { 1259static struct pci_driver serial_txx9_pci_driver = {
1262 .name = "serial_txx9", 1260 .name = "serial_txx9",
1263 .probe = pciserial_txx9_init_one, 1261 .probe = pciserial_txx9_init_one,
1264 .remove = pciserial_txx9_remove_one, 1262 .remove = __devexit_p(pciserial_txx9_remove_one),
1265#ifdef CONFIG_PM 1263#ifdef CONFIG_PM
1266 .suspend = pciserial_txx9_suspend_one, 1264 .suspend = pciserial_txx9_suspend_one,
1267 .resume = pciserial_txx9_resume_one, 1265 .resume = pciserial_txx9_resume_one,
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 61477567423..5ea6ec3442e 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -25,7 +25,6 @@
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/errno.h> 27#include <linux/errno.h>
28#include <linux/sh_dma.h>
29#include <linux/timer.h> 28#include <linux/timer.h>
30#include <linux/interrupt.h> 29#include <linux/interrupt.h>
31#include <linux/tty.h> 30#include <linux/tty.h>
@@ -51,7 +50,6 @@
51#include <linux/dma-mapping.h> 50#include <linux/dma-mapping.h>
52#include <linux/scatterlist.h> 51#include <linux/scatterlist.h>
53#include <linux/slab.h> 52#include <linux/slab.h>
54#include <linux/gpio.h>
55 53
56#ifdef CONFIG_SUPERH 54#ifdef CONFIG_SUPERH
57#include <asm/sh_bios.h> 55#include <asm/sh_bios.h>
@@ -75,7 +73,6 @@ struct sci_port {
75 struct clk *fclk; 73 struct clk *fclk;
76 74
77 char *irqstr[SCIx_NR_IRQS]; 75 char *irqstr[SCIx_NR_IRQS];
78 char *gpiostr[SCIx_NR_FNS];
79 76
80 struct dma_chan *chan_tx; 77 struct dma_chan *chan_tx;
81 struct dma_chan *chan_rx; 78 struct dma_chan *chan_rx;
@@ -99,6 +96,12 @@ struct sci_port {
99#endif 96#endif
100 97
101 struct notifier_block freq_transition; 98 struct notifier_block freq_transition;
99
100#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
101 unsigned short saved_smr;
102 unsigned short saved_fcr;
103 unsigned char saved_brr;
104#endif
102}; 105};
103 106
104/* Function prototypes */ 107/* Function prototypes */
@@ -196,30 +199,11 @@ static struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
196 [SCxSR] = { 0x14, 16 }, 199 [SCxSR] = { 0x14, 16 },
197 [SCxRDR] = { 0x60, 8 }, 200 [SCxRDR] = { 0x60, 8 },
198 [SCFCR] = { 0x18, 16 }, 201 [SCFCR] = { 0x18, 16 },
199 [SCFDR] = sci_reg_invalid,
200 [SCTFDR] = { 0x38, 16 },
201 [SCRFDR] = { 0x3c, 16 },
202 [SCSPTR] = sci_reg_invalid,
203 [SCLSR] = sci_reg_invalid,
204 },
205
206 /*
207 * Common SH-2(A) SCIF definitions for ports with FIFO data
208 * count registers.
209 */
210 [SCIx_SH2_SCIF_FIFODATA_REGTYPE] = {
211 [SCSMR] = { 0x00, 16 },
212 [SCBRR] = { 0x04, 8 },
213 [SCSCR] = { 0x08, 16 },
214 [SCxTDR] = { 0x0c, 8 },
215 [SCxSR] = { 0x10, 16 },
216 [SCxRDR] = { 0x14, 8 },
217 [SCFCR] = { 0x18, 16 },
218 [SCFDR] = { 0x1c, 16 }, 202 [SCFDR] = { 0x1c, 16 },
219 [SCTFDR] = sci_reg_invalid, 203 [SCTFDR] = sci_reg_invalid,
220 [SCRFDR] = sci_reg_invalid, 204 [SCRFDR] = sci_reg_invalid,
221 [SCSPTR] = { 0x20, 16 }, 205 [SCSPTR] = sci_reg_invalid,
222 [SCLSR] = { 0x24, 16 }, 206 [SCLSR] = sci_reg_invalid,
223 }, 207 },
224 208
225 /* 209 /*
@@ -350,6 +334,9 @@ static void sci_serial_out(struct uart_port *p, int offset, int value)
350 WARN(1, "Invalid register access\n"); 334 WARN(1, "Invalid register access\n");
351} 335}
352 336
337#define sci_in(up, offset) (up->serial_in(up, offset))
338#define sci_out(up, offset, value) (up->serial_out(up, offset, value))
339
353static int sci_probe_regmap(struct plat_sci_port *cfg) 340static int sci_probe_regmap(struct plat_sci_port *cfg)
354{ 341{
355 switch (cfg->type) { 342 switch (cfg->type) {
@@ -414,9 +401,9 @@ static int sci_poll_get_char(struct uart_port *port)
414 int c; 401 int c;
415 402
416 do { 403 do {
417 status = serial_port_in(port, SCxSR); 404 status = sci_in(port, SCxSR);
418 if (status & SCxSR_ERRORS(port)) { 405 if (status & SCxSR_ERRORS(port)) {
419 serial_port_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); 406 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
420 continue; 407 continue;
421 } 408 }
422 break; 409 break;
@@ -425,11 +412,11 @@ static int sci_poll_get_char(struct uart_port *port)
425 if (!(status & SCxSR_RDxF(port))) 412 if (!(status & SCxSR_RDxF(port)))
426 return NO_POLL_CHAR; 413 return NO_POLL_CHAR;
427 414
428 c = serial_port_in(port, SCxRDR); 415 c = sci_in(port, SCxRDR);
429 416
430 /* Dummy read */ 417 /* Dummy read */
431 serial_port_in(port, SCxSR); 418 sci_in(port, SCxSR);
432 serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 419 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
433 420
434 return c; 421 return c;
435} 422}
@@ -440,11 +427,11 @@ static void sci_poll_put_char(struct uart_port *port, unsigned char c)
440 unsigned short status; 427 unsigned short status;
441 428
442 do { 429 do {
443 status = serial_port_in(port, SCxSR); 430 status = sci_in(port, SCxSR);
444 } while (!(status & SCxSR_TDxE(port))); 431 } while (!(status & SCxSR_TDxE(port)));
445 432
446 serial_port_out(port, SCxTDR, c); 433 sci_out(port, SCxTDR, c);
447 serial_port_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port)); 434 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
448} 435}
449#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */ 436#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */
450 437
@@ -468,15 +455,8 @@ static void sci_init_pins(struct uart_port *port, unsigned int cflag)
468 if (!reg->size) 455 if (!reg->size)
469 return; 456 return;
470 457
471 if ((s->cfg->capabilities & SCIx_HAVE_RTSCTS) && 458 if (!(cflag & CRTSCTS))
472 ((!(cflag & CRTSCTS)))) { 459 sci_out(port, SCSPTR, 0x0080); /* Set RTS = 1 */
473 unsigned short status;
474
475 status = serial_port_in(port, SCSPTR);
476 status &= ~SCSPTR_CTSIO;
477 status |= SCSPTR_RTSIO;
478 serial_port_out(port, SCSPTR, status); /* Set RTS = 1 */
479 }
480} 460}
481 461
482static int sci_txfill(struct uart_port *port) 462static int sci_txfill(struct uart_port *port)
@@ -485,13 +465,13 @@ static int sci_txfill(struct uart_port *port)
485 465
486 reg = sci_getreg(port, SCTFDR); 466 reg = sci_getreg(port, SCTFDR);
487 if (reg->size) 467 if (reg->size)
488 return serial_port_in(port, SCTFDR) & ((port->fifosize << 1) - 1); 468 return sci_in(port, SCTFDR) & 0xff;
489 469
490 reg = sci_getreg(port, SCFDR); 470 reg = sci_getreg(port, SCFDR);
491 if (reg->size) 471 if (reg->size)
492 return serial_port_in(port, SCFDR) >> 8; 472 return sci_in(port, SCFDR) >> 8;
493 473
494 return !(serial_port_in(port, SCxSR) & SCI_TDRE); 474 return !(sci_in(port, SCxSR) & SCI_TDRE);
495} 475}
496 476
497static int sci_txroom(struct uart_port *port) 477static int sci_txroom(struct uart_port *port)
@@ -505,13 +485,13 @@ static int sci_rxfill(struct uart_port *port)
505 485
506 reg = sci_getreg(port, SCRFDR); 486 reg = sci_getreg(port, SCRFDR);
507 if (reg->size) 487 if (reg->size)
508 return serial_port_in(port, SCRFDR) & ((port->fifosize << 1) - 1); 488 return sci_in(port, SCRFDR) & 0xff;
509 489
510 reg = sci_getreg(port, SCFDR); 490 reg = sci_getreg(port, SCFDR);
511 if (reg->size) 491 if (reg->size)
512 return serial_port_in(port, SCFDR) & ((port->fifosize << 1) - 1); 492 return sci_in(port, SCFDR) & ((port->fifosize << 1) - 1);
513 493
514 return (serial_port_in(port, SCxSR) & SCxSR_RDxF(port)) != 0; 494 return (sci_in(port, SCxSR) & SCxSR_RDxF(port)) != 0;
515} 495}
516 496
517/* 497/*
@@ -524,8 +504,7 @@ static inline int sci_rxd_in(struct uart_port *port)
524 if (s->cfg->port_reg <= 0) 504 if (s->cfg->port_reg <= 0)
525 return 1; 505 return 1;
526 506
527 /* Cast for ARM damage */ 507 return !!__raw_readb(s->cfg->port_reg);
528 return !!__raw_readb((void __iomem *)s->cfg->port_reg);
529} 508}
530 509
531/* ********************************************************************** * 510/* ********************************************************************** *
@@ -540,14 +519,14 @@ static void sci_transmit_chars(struct uart_port *port)
540 unsigned short ctrl; 519 unsigned short ctrl;
541 int count; 520 int count;
542 521
543 status = serial_port_in(port, SCxSR); 522 status = sci_in(port, SCxSR);
544 if (!(status & SCxSR_TDxE(port))) { 523 if (!(status & SCxSR_TDxE(port))) {
545 ctrl = serial_port_in(port, SCSCR); 524 ctrl = sci_in(port, SCSCR);
546 if (uart_circ_empty(xmit)) 525 if (uart_circ_empty(xmit))
547 ctrl &= ~SCSCR_TIE; 526 ctrl &= ~SCSCR_TIE;
548 else 527 else
549 ctrl |= SCSCR_TIE; 528 ctrl |= SCSCR_TIE;
550 serial_port_out(port, SCSCR, ctrl); 529 sci_out(port, SCSCR, ctrl);
551 return; 530 return;
552 } 531 }
553 532
@@ -566,27 +545,27 @@ static void sci_transmit_chars(struct uart_port *port)
566 break; 545 break;
567 } 546 }
568 547
569 serial_port_out(port, SCxTDR, c); 548 sci_out(port, SCxTDR, c);
570 549
571 port->icount.tx++; 550 port->icount.tx++;
572 } while (--count > 0); 551 } while (--count > 0);
573 552
574 serial_port_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); 553 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
575 554
576 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 555 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
577 uart_write_wakeup(port); 556 uart_write_wakeup(port);
578 if (uart_circ_empty(xmit)) { 557 if (uart_circ_empty(xmit)) {
579 sci_stop_tx(port); 558 sci_stop_tx(port);
580 } else { 559 } else {
581 ctrl = serial_port_in(port, SCSCR); 560 ctrl = sci_in(port, SCSCR);
582 561
583 if (port->type != PORT_SCI) { 562 if (port->type != PORT_SCI) {
584 serial_port_in(port, SCxSR); /* Dummy read */ 563 sci_in(port, SCxSR); /* Dummy read */
585 serial_port_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); 564 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
586 } 565 }
587 566
588 ctrl |= SCSCR_TIE; 567 ctrl |= SCSCR_TIE;
589 serial_port_out(port, SCSCR, ctrl); 568 sci_out(port, SCSCR, ctrl);
590 } 569 }
591} 570}
592 571
@@ -601,7 +580,7 @@ static void sci_receive_chars(struct uart_port *port)
601 unsigned short status; 580 unsigned short status;
602 unsigned char flag; 581 unsigned char flag;
603 582
604 status = serial_port_in(port, SCxSR); 583 status = sci_in(port, SCxSR);
605 if (!(status & SCxSR_RDxF(port))) 584 if (!(status & SCxSR_RDxF(port)))
606 return; 585 return;
607 586
@@ -614,7 +593,7 @@ static void sci_receive_chars(struct uart_port *port)
614 break; 593 break;
615 594
616 if (port->type == PORT_SCI) { 595 if (port->type == PORT_SCI) {
617 char c = serial_port_in(port, SCxRDR); 596 char c = sci_in(port, SCxRDR);
618 if (uart_handle_sysrq_char(port, c) || 597 if (uart_handle_sysrq_char(port, c) ||
619 sci_port->break_flag) 598 sci_port->break_flag)
620 count = 0; 599 count = 0;
@@ -622,9 +601,8 @@ static void sci_receive_chars(struct uart_port *port)
622 tty_insert_flip_char(tty, c, TTY_NORMAL); 601 tty_insert_flip_char(tty, c, TTY_NORMAL);
623 } else { 602 } else {
624 for (i = 0; i < count; i++) { 603 for (i = 0; i < count; i++) {
625 char c = serial_port_in(port, SCxRDR); 604 char c = sci_in(port, SCxRDR);
626 605 status = sci_in(port, SCxSR);
627 status = serial_port_in(port, SCxSR);
628#if defined(CONFIG_CPU_SH3) 606#if defined(CONFIG_CPU_SH3)
629 /* Skip "chars" during break */ 607 /* Skip "chars" during break */
630 if (sci_port->break_flag) { 608 if (sci_port->break_flag) {
@@ -652,11 +630,9 @@ static void sci_receive_chars(struct uart_port *port)
652 /* Store data and status */ 630 /* Store data and status */
653 if (status & SCxSR_FER(port)) { 631 if (status & SCxSR_FER(port)) {
654 flag = TTY_FRAME; 632 flag = TTY_FRAME;
655 port->icount.frame++;
656 dev_notice(port->dev, "frame error\n"); 633 dev_notice(port->dev, "frame error\n");
657 } else if (status & SCxSR_PER(port)) { 634 } else if (status & SCxSR_PER(port)) {
658 flag = TTY_PARITY; 635 flag = TTY_PARITY;
659 port->icount.parity++;
660 dev_notice(port->dev, "parity error\n"); 636 dev_notice(port->dev, "parity error\n");
661 } else 637 } else
662 flag = TTY_NORMAL; 638 flag = TTY_NORMAL;
@@ -665,8 +641,8 @@ static void sci_receive_chars(struct uart_port *port)
665 } 641 }
666 } 642 }
667 643
668 serial_port_in(port, SCxSR); /* dummy read */ 644 sci_in(port, SCxSR); /* dummy read */
669 serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 645 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
670 646
671 copied += count; 647 copied += count;
672 port->icount.rx += count; 648 port->icount.rx += count;
@@ -676,8 +652,8 @@ static void sci_receive_chars(struct uart_port *port)
676 /* Tell the rest of the system the news. New characters! */ 652 /* Tell the rest of the system the news. New characters! */
677 tty_flip_buffer_push(tty); 653 tty_flip_buffer_push(tty);
678 } else { 654 } else {
679 serial_port_in(port, SCxSR); /* dummy read */ 655 sci_in(port, SCxSR); /* dummy read */
680 serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 656 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
681 } 657 }
682} 658}
683 659
@@ -719,7 +695,7 @@ static void sci_break_timer(unsigned long data)
719static int sci_handle_errors(struct uart_port *port) 695static int sci_handle_errors(struct uart_port *port)
720{ 696{
721 int copied = 0; 697 int copied = 0;
722 unsigned short status = serial_port_in(port, SCxSR); 698 unsigned short status = sci_in(port, SCxSR);
723 struct tty_struct *tty = port->state->port.tty; 699 struct tty_struct *tty = port->state->port.tty;
724 struct sci_port *s = to_sci_port(port); 700 struct sci_port *s = to_sci_port(port);
725 701
@@ -728,8 +704,6 @@ static int sci_handle_errors(struct uart_port *port)
728 */ 704 */
729 if (s->cfg->overrun_bit != SCIx_NOT_SUPPORTED) { 705 if (s->cfg->overrun_bit != SCIx_NOT_SUPPORTED) {
730 if (status & (1 << s->cfg->overrun_bit)) { 706 if (status & (1 << s->cfg->overrun_bit)) {
731 port->icount.overrun++;
732
733 /* overrun error */ 707 /* overrun error */
734 if (tty_insert_flip_char(tty, 0, TTY_OVERRUN)) 708 if (tty_insert_flip_char(tty, 0, TTY_OVERRUN))
735 copied++; 709 copied++;
@@ -744,8 +718,6 @@ static int sci_handle_errors(struct uart_port *port)
744 struct sci_port *sci_port = to_sci_port(port); 718 struct sci_port *sci_port = to_sci_port(port);
745 719
746 if (!sci_port->break_flag) { 720 if (!sci_port->break_flag) {
747 port->icount.brk++;
748
749 sci_port->break_flag = 1; 721 sci_port->break_flag = 1;
750 sci_schedule_break_timer(sci_port); 722 sci_schedule_break_timer(sci_port);
751 723
@@ -761,8 +733,6 @@ static int sci_handle_errors(struct uart_port *port)
761 733
762 } else { 734 } else {
763 /* frame error */ 735 /* frame error */
764 port->icount.frame++;
765
766 if (tty_insert_flip_char(tty, 0, TTY_FRAME)) 736 if (tty_insert_flip_char(tty, 0, TTY_FRAME))
767 copied++; 737 copied++;
768 738
@@ -772,8 +742,6 @@ static int sci_handle_errors(struct uart_port *port)
772 742
773 if (status & SCxSR_PER(port)) { 743 if (status & SCxSR_PER(port)) {
774 /* parity error */ 744 /* parity error */
775 port->icount.parity++;
776
777 if (tty_insert_flip_char(tty, 0, TTY_PARITY)) 745 if (tty_insert_flip_char(tty, 0, TTY_PARITY))
778 copied++; 746 copied++;
779 747
@@ -797,10 +765,8 @@ static int sci_handle_fifo_overrun(struct uart_port *port)
797 if (!reg->size) 765 if (!reg->size)
798 return 0; 766 return 0;
799 767
800 if ((serial_port_in(port, SCLSR) & (1 << s->cfg->overrun_bit))) { 768 if ((sci_in(port, SCLSR) & (1 << s->cfg->overrun_bit))) {
801 serial_port_out(port, SCLSR, 0); 769 sci_out(port, SCLSR, 0);
802
803 port->icount.overrun++;
804 770
805 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 771 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
806 tty_flip_buffer_push(tty); 772 tty_flip_buffer_push(tty);
@@ -815,7 +781,7 @@ static int sci_handle_fifo_overrun(struct uart_port *port)
815static int sci_handle_breaks(struct uart_port *port) 781static int sci_handle_breaks(struct uart_port *port)
816{ 782{
817 int copied = 0; 783 int copied = 0;
818 unsigned short status = serial_port_in(port, SCxSR); 784 unsigned short status = sci_in(port, SCxSR);
819 struct tty_struct *tty = port->state->port.tty; 785 struct tty_struct *tty = port->state->port.tty;
820 struct sci_port *s = to_sci_port(port); 786 struct sci_port *s = to_sci_port(port);
821 787
@@ -827,9 +793,6 @@ static int sci_handle_breaks(struct uart_port *port)
827 /* Debounce break */ 793 /* Debounce break */
828 s->break_flag = 1; 794 s->break_flag = 1;
829#endif 795#endif
830
831 port->icount.brk++;
832
833 /* Notify of BREAK */ 796 /* Notify of BREAK */
834 if (tty_insert_flip_char(tty, 0, TTY_BREAK)) 797 if (tty_insert_flip_char(tty, 0, TTY_BREAK))
835 copied++; 798 copied++;
@@ -852,8 +815,8 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
852 struct sci_port *s = to_sci_port(port); 815 struct sci_port *s = to_sci_port(port);
853 816
854 if (s->chan_rx) { 817 if (s->chan_rx) {
855 u16 scr = serial_port_in(port, SCSCR); 818 u16 scr = sci_in(port, SCSCR);
856 u16 ssr = serial_port_in(port, SCxSR); 819 u16 ssr = sci_in(port, SCxSR);
857 820
858 /* Disable future Rx interrupts */ 821 /* Disable future Rx interrupts */
859 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 822 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
@@ -862,9 +825,9 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
862 } else { 825 } else {
863 scr &= ~SCSCR_RIE; 826 scr &= ~SCSCR_RIE;
864 } 827 }
865 serial_port_out(port, SCSCR, scr); 828 sci_out(port, SCSCR, scr);
866 /* Clear current interrupt */ 829 /* Clear current interrupt */
867 serial_port_out(port, SCxSR, ssr & ~(1 | SCxSR_RDxF(port))); 830 sci_out(port, SCxSR, ssr & ~(1 | SCxSR_RDxF(port)));
868 dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u jiffies\n", 831 dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u jiffies\n",
869 jiffies, s->rx_timeout); 832 jiffies, s->rx_timeout);
870 mod_timer(&s->rx_timer, jiffies + s->rx_timeout); 833 mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
@@ -902,15 +865,15 @@ static irqreturn_t sci_er_interrupt(int irq, void *ptr)
902 if (port->type == PORT_SCI) { 865 if (port->type == PORT_SCI) {
903 if (sci_handle_errors(port)) { 866 if (sci_handle_errors(port)) {
904 /* discard character in rx buffer */ 867 /* discard character in rx buffer */
905 serial_port_in(port, SCxSR); 868 sci_in(port, SCxSR);
906 serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port)); 869 sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
907 } 870 }
908 } else { 871 } else {
909 sci_handle_fifo_overrun(port); 872 sci_handle_fifo_overrun(port);
910 sci_rx_interrupt(irq, ptr); 873 sci_rx_interrupt(irq, ptr);
911 } 874 }
912 875
913 serial_port_out(port, SCxSR, SCxSR_ERROR_CLEAR(port)); 876 sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
914 877
915 /* Kick the transmission */ 878 /* Kick the transmission */
916 sci_tx_interrupt(irq, ptr); 879 sci_tx_interrupt(irq, ptr);
@@ -924,7 +887,7 @@ static irqreturn_t sci_br_interrupt(int irq, void *ptr)
924 887
925 /* Handle BREAKs */ 888 /* Handle BREAKs */
926 sci_handle_breaks(port); 889 sci_handle_breaks(port);
927 serial_port_out(port, SCxSR, SCxSR_BREAK_CLEAR(port)); 890 sci_out(port, SCxSR, SCxSR_BREAK_CLEAR(port));
928 891
929 return IRQ_HANDLED; 892 return IRQ_HANDLED;
930} 893}
@@ -948,8 +911,8 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
948 struct sci_port *s = to_sci_port(port); 911 struct sci_port *s = to_sci_port(port);
949 irqreturn_t ret = IRQ_NONE; 912 irqreturn_t ret = IRQ_NONE;
950 913
951 ssr_status = serial_port_in(port, SCxSR); 914 ssr_status = sci_in(port, SCxSR);
952 scr_status = serial_port_in(port, SCSCR); 915 scr_status = sci_in(port, SCSCR);
953 err_enabled = scr_status & port_rx_irq_mask(port); 916 err_enabled = scr_status & port_rx_irq_mask(port);
954 917
955 /* Tx Interrupt */ 918 /* Tx Interrupt */
@@ -1048,17 +1011,9 @@ static int sci_request_irq(struct sci_port *port)
1048 if (SCIx_IRQ_IS_MUXED(port)) { 1011 if (SCIx_IRQ_IS_MUXED(port)) {
1049 i = SCIx_MUX_IRQ; 1012 i = SCIx_MUX_IRQ;
1050 irq = up->irq; 1013 irq = up->irq;
1051 } else { 1014 } else
1052 irq = port->cfg->irqs[i]; 1015 irq = port->cfg->irqs[i];
1053 1016
1054 /*
1055 * Certain port types won't support all of the
1056 * available interrupt sources.
1057 */
1058 if (unlikely(!irq))
1059 continue;
1060 }
1061
1062 desc = sci_irq_desc + i; 1017 desc = sci_irq_desc + i;
1063 port->irqstr[j] = kasprintf(GFP_KERNEL, "%s:%s", 1018 port->irqstr[j] = kasprintf(GFP_KERNEL, "%s:%s",
1064 dev_name(up->dev), desc->desc); 1019 dev_name(up->dev), desc->desc);
@@ -1098,15 +1053,6 @@ static void sci_free_irq(struct sci_port *port)
1098 * IRQ first. 1053 * IRQ first.
1099 */ 1054 */
1100 for (i = 0; i < SCIx_NR_IRQS; i++) { 1055 for (i = 0; i < SCIx_NR_IRQS; i++) {
1101 unsigned int irq = port->cfg->irqs[i];
1102
1103 /*
1104 * Certain port types won't support all of the available
1105 * interrupt sources.
1106 */
1107 if (unlikely(!irq))
1108 continue;
1109
1110 free_irq(port->cfg->irqs[i], port); 1056 free_irq(port->cfg->irqs[i], port);
1111 kfree(port->irqstr[i]); 1057 kfree(port->irqstr[i]);
1112 1058
@@ -1117,108 +1063,27 @@ static void sci_free_irq(struct sci_port *port)
1117 } 1063 }
1118} 1064}
1119 1065
1120static const char *sci_gpio_names[SCIx_NR_FNS] = {
1121 "sck", "rxd", "txd", "cts", "rts",
1122};
1123
1124static const char *sci_gpio_str(unsigned int index)
1125{
1126 return sci_gpio_names[index];
1127}
1128
1129static void sci_init_gpios(struct sci_port *port)
1130{
1131 struct uart_port *up = &port->port;
1132 int i;
1133
1134 if (!port->cfg)
1135 return;
1136
1137 for (i = 0; i < SCIx_NR_FNS; i++) {
1138 const char *desc;
1139 int ret;
1140
1141 if (!port->cfg->gpios[i])
1142 continue;
1143
1144 desc = sci_gpio_str(i);
1145
1146 port->gpiostr[i] = kasprintf(GFP_KERNEL, "%s:%s",
1147 dev_name(up->dev), desc);
1148
1149 /*
1150 * If we've failed the allocation, we can still continue
1151 * on with a NULL string.
1152 */
1153 if (!port->gpiostr[i])
1154 dev_notice(up->dev, "%s string allocation failure\n",
1155 desc);
1156
1157 ret = gpio_request(port->cfg->gpios[i], port->gpiostr[i]);
1158 if (unlikely(ret != 0)) {
1159 dev_notice(up->dev, "failed %s gpio request\n", desc);
1160
1161 /*
1162 * If we can't get the GPIO for whatever reason,
1163 * no point in keeping the verbose string around.
1164 */
1165 kfree(port->gpiostr[i]);
1166 }
1167 }
1168}
1169
1170static void sci_free_gpios(struct sci_port *port)
1171{
1172 int i;
1173
1174 for (i = 0; i < SCIx_NR_FNS; i++)
1175 if (port->cfg->gpios[i]) {
1176 gpio_free(port->cfg->gpios[i]);
1177 kfree(port->gpiostr[i]);
1178 }
1179}
1180
1181static unsigned int sci_tx_empty(struct uart_port *port) 1066static unsigned int sci_tx_empty(struct uart_port *port)
1182{ 1067{
1183 unsigned short status = serial_port_in(port, SCxSR); 1068 unsigned short status = sci_in(port, SCxSR);
1184 unsigned short in_tx_fifo = sci_txfill(port); 1069 unsigned short in_tx_fifo = sci_txfill(port);
1185 1070
1186 return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0; 1071 return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0;
1187} 1072}
1188 1073
1189/*
1190 * Modem control is a bit of a mixed bag for SCI(F) ports. Generally
1191 * CTS/RTS is supported in hardware by at least one port and controlled
1192 * via SCSPTR (SCxPCR for SCIFA/B parts), or external pins (presently
1193 * handled via the ->init_pins() op, which is a bit of a one-way street,
1194 * lacking any ability to defer pin control -- this will later be
1195 * converted over to the GPIO framework).
1196 *
1197 * Other modes (such as loopback) are supported generically on certain
1198 * port types, but not others. For these it's sufficient to test for the
1199 * existence of the support register and simply ignore the port type.
1200 */
1201static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl) 1074static void sci_set_mctrl(struct uart_port *port, unsigned int mctrl)
1202{ 1075{
1203 if (mctrl & TIOCM_LOOP) { 1076 /* This routine is used for seting signals of: DTR, DCD, CTS/RTS */
1204 struct plat_sci_reg *reg; 1077 /* We use SCIF's hardware for CTS/RTS, so don't need any for that. */
1205 1078 /* If you have signals for DTR and DCD, please implement here. */
1206 /*
1207 * Standard loopback mode for SCFCR ports.
1208 */
1209 reg = sci_getreg(port, SCFCR);
1210 if (reg->size)
1211 serial_port_out(port, SCFCR, serial_port_in(port, SCFCR) | 1);
1212 }
1213} 1079}
1214 1080
1215static unsigned int sci_get_mctrl(struct uart_port *port) 1081static unsigned int sci_get_mctrl(struct uart_port *port)
1216{ 1082{
1217 /* 1083 /* This routine is used for getting signals of: DTR, DCD, DSR, RI,
1218 * CTS/RTS is handled in hardware when supported, while nothing 1084 and CTS/RTS */
1219 * else is wired up. Keep it simple and simply assert DSR/CAR. 1085
1220 */ 1086 return TIOCM_DTR | TIOCM_RTS | TIOCM_CTS | TIOCM_DSR;
1221 return TIOCM_DSR | TIOCM_CAR;
1222} 1087}
1223 1088
1224#ifdef CONFIG_SERIAL_SH_SCI_DMA 1089#ifdef CONFIG_SERIAL_SH_SCI_DMA
@@ -1239,20 +1104,17 @@ static void sci_dma_tx_complete(void *arg)
1239 port->icount.tx += sg_dma_len(&s->sg_tx); 1104 port->icount.tx += sg_dma_len(&s->sg_tx);
1240 1105
1241 async_tx_ack(s->desc_tx); 1106 async_tx_ack(s->desc_tx);
1107 s->cookie_tx = -EINVAL;
1242 s->desc_tx = NULL; 1108 s->desc_tx = NULL;
1243 1109
1244 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 1110 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
1245 uart_write_wakeup(port); 1111 uart_write_wakeup(port);
1246 1112
1247 if (!uart_circ_empty(xmit)) { 1113 if (!uart_circ_empty(xmit)) {
1248 s->cookie_tx = 0;
1249 schedule_work(&s->work_tx); 1114 schedule_work(&s->work_tx);
1250 } else { 1115 } else if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1251 s->cookie_tx = -EINVAL; 1116 u16 ctrl = sci_in(port, SCSCR);
1252 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 1117 sci_out(port, SCSCR, ctrl & ~SCSCR_TIE);
1253 u16 ctrl = serial_port_in(port, SCSCR);
1254 serial_port_out(port, SCSCR, ctrl & ~SCSCR_TIE);
1255 }
1256 } 1118 }
1257 1119
1258 spin_unlock_irqrestore(&port->lock, flags); 1120 spin_unlock_irqrestore(&port->lock, flags);
@@ -1351,8 +1213,8 @@ static void sci_submit_rx(struct sci_port *s)
1351 struct scatterlist *sg = &s->sg_rx[i]; 1213 struct scatterlist *sg = &s->sg_rx[i];
1352 struct dma_async_tx_descriptor *desc; 1214 struct dma_async_tx_descriptor *desc;
1353 1215
1354 desc = dmaengine_prep_slave_sg(chan, 1216 desc = chan->device->device_prep_slave_sg(chan,
1355 sg, 1, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT); 1217 sg, 1, DMA_FROM_DEVICE, DMA_PREP_INTERRUPT);
1356 1218
1357 if (desc) { 1219 if (desc) {
1358 s->desc_rx[i] = desc; 1220 s->desc_rx[i] = desc;
@@ -1406,8 +1268,8 @@ static void work_fn_rx(struct work_struct *work)
1406 /* Handle incomplete DMA receive */ 1268 /* Handle incomplete DMA receive */
1407 struct tty_struct *tty = port->state->port.tty; 1269 struct tty_struct *tty = port->state->port.tty;
1408 struct dma_chan *chan = s->chan_rx; 1270 struct dma_chan *chan = s->chan_rx;
1409 struct shdma_desc *sh_desc = container_of(desc, 1271 struct sh_desc *sh_desc = container_of(desc, struct sh_desc,
1410 struct shdma_desc, async_tx); 1272 async_tx);
1411 unsigned long flags; 1273 unsigned long flags;
1412 int count; 1274 int count;
1413 1275
@@ -1466,8 +1328,8 @@ static void work_fn_tx(struct work_struct *work)
1466 1328
1467 BUG_ON(!sg_dma_len(sg)); 1329 BUG_ON(!sg_dma_len(sg));
1468 1330
1469 desc = dmaengine_prep_slave_sg(chan, 1331 desc = chan->device->device_prep_slave_sg(chan,
1470 sg, s->sg_len_tx, DMA_MEM_TO_DEV, 1332 sg, s->sg_len_tx, DMA_TO_DEVICE,
1471 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1333 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1472 if (!desc) { 1334 if (!desc) {
1473 /* switch to PIO */ 1335 /* switch to PIO */
@@ -1504,26 +1366,24 @@ static void sci_start_tx(struct uart_port *port)
1504 1366
1505#ifdef CONFIG_SERIAL_SH_SCI_DMA 1367#ifdef CONFIG_SERIAL_SH_SCI_DMA
1506 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 1368 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1507 u16 new, scr = serial_port_in(port, SCSCR); 1369 u16 new, scr = sci_in(port, SCSCR);
1508 if (s->chan_tx) 1370 if (s->chan_tx)
1509 new = scr | 0x8000; 1371 new = scr | 0x8000;
1510 else 1372 else
1511 new = scr & ~0x8000; 1373 new = scr & ~0x8000;
1512 if (new != scr) 1374 if (new != scr)
1513 serial_port_out(port, SCSCR, new); 1375 sci_out(port, SCSCR, new);
1514 } 1376 }
1515 1377
1516 if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) && 1378 if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) &&
1517 s->cookie_tx < 0) { 1379 s->cookie_tx < 0)
1518 s->cookie_tx = 0;
1519 schedule_work(&s->work_tx); 1380 schedule_work(&s->work_tx);
1520 }
1521#endif 1381#endif
1522 1382
1523 if (!s->chan_tx || port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 1383 if (!s->chan_tx || port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1524 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */ 1384 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
1525 ctrl = serial_port_in(port, SCSCR); 1385 ctrl = sci_in(port, SCSCR);
1526 serial_port_out(port, SCSCR, ctrl | SCSCR_TIE); 1386 sci_out(port, SCSCR, ctrl | SCSCR_TIE);
1527 } 1387 }
1528} 1388}
1529 1389
@@ -1532,77 +1392,50 @@ static void sci_stop_tx(struct uart_port *port)
1532 unsigned short ctrl; 1392 unsigned short ctrl;
1533 1393
1534 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */ 1394 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
1535 ctrl = serial_port_in(port, SCSCR); 1395 ctrl = sci_in(port, SCSCR);
1536 1396
1537 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 1397 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1538 ctrl &= ~0x8000; 1398 ctrl &= ~0x8000;
1539 1399
1540 ctrl &= ~SCSCR_TIE; 1400 ctrl &= ~SCSCR_TIE;
1541 1401
1542 serial_port_out(port, SCSCR, ctrl); 1402 sci_out(port, SCSCR, ctrl);
1543} 1403}
1544 1404
1545static void sci_start_rx(struct uart_port *port) 1405static void sci_start_rx(struct uart_port *port)
1546{ 1406{
1547 unsigned short ctrl; 1407 unsigned short ctrl;
1548 1408
1549 ctrl = serial_port_in(port, SCSCR) | port_rx_irq_mask(port); 1409 ctrl = sci_in(port, SCSCR) | port_rx_irq_mask(port);
1550 1410
1551 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 1411 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1552 ctrl &= ~0x4000; 1412 ctrl &= ~0x4000;
1553 1413
1554 serial_port_out(port, SCSCR, ctrl); 1414 sci_out(port, SCSCR, ctrl);
1555} 1415}
1556 1416
1557static void sci_stop_rx(struct uart_port *port) 1417static void sci_stop_rx(struct uart_port *port)
1558{ 1418{
1559 unsigned short ctrl; 1419 unsigned short ctrl;
1560 1420
1561 ctrl = serial_port_in(port, SCSCR); 1421 ctrl = sci_in(port, SCSCR);
1562 1422
1563 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) 1423 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1564 ctrl &= ~0x4000; 1424 ctrl &= ~0x4000;
1565 1425
1566 ctrl &= ~port_rx_irq_mask(port); 1426 ctrl &= ~port_rx_irq_mask(port);
1567 1427
1568 serial_port_out(port, SCSCR, ctrl); 1428 sci_out(port, SCSCR, ctrl);
1569} 1429}
1570 1430
1571static void sci_enable_ms(struct uart_port *port) 1431static void sci_enable_ms(struct uart_port *port)
1572{ 1432{
1573 /* 1433 /* Nothing here yet .. */
1574 * Not supported by hardware, always a nop.
1575 */
1576} 1434}
1577 1435
1578static void sci_break_ctl(struct uart_port *port, int break_state) 1436static void sci_break_ctl(struct uart_port *port, int break_state)
1579{ 1437{
1580 struct sci_port *s = to_sci_port(port); 1438 /* Nothing here yet .. */
1581 struct plat_sci_reg *reg = sci_regmap[s->cfg->regtype] + SCSPTR;
1582 unsigned short scscr, scsptr;
1583
1584 /* check wheter the port has SCSPTR */
1585 if (!reg->size) {
1586 /*
1587 * Not supported by hardware. Most parts couple break and rx
1588 * interrupts together, with break detection always enabled.
1589 */
1590 return;
1591 }
1592
1593 scsptr = serial_port_in(port, SCSPTR);
1594 scscr = serial_port_in(port, SCSCR);
1595
1596 if (break_state == -1) {
1597 scsptr = (scsptr | SCSPTR_SPB2IO) & ~SCSPTR_SPB2DT;
1598 scscr &= ~SCSCR_TE;
1599 } else {
1600 scsptr = (scsptr | SCSPTR_SPB2DT) & ~SCSPTR_SPB2IO;
1601 scscr |= SCSCR_TE;
1602 }
1603
1604 serial_port_out(port, SCSPTR, scsptr);
1605 serial_port_out(port, SCSCR, scscr);
1606} 1439}
1607 1440
1608#ifdef CONFIG_SERIAL_SH_SCI_DMA 1441#ifdef CONFIG_SERIAL_SH_SCI_DMA
@@ -1611,23 +1444,27 @@ static bool filter(struct dma_chan *chan, void *slave)
1611 struct sh_dmae_slave *param = slave; 1444 struct sh_dmae_slave *param = slave;
1612 1445
1613 dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__, 1446 dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__,
1614 param->shdma_slave.slave_id); 1447 param->slave_id);
1615 1448
1616 chan->private = &param->shdma_slave; 1449 if (param->dma_dev == chan->device->dev) {
1617 return true; 1450 chan->private = param;
1451 return true;
1452 } else {
1453 return false;
1454 }
1618} 1455}
1619 1456
1620static void rx_timer_fn(unsigned long arg) 1457static void rx_timer_fn(unsigned long arg)
1621{ 1458{
1622 struct sci_port *s = (struct sci_port *)arg; 1459 struct sci_port *s = (struct sci_port *)arg;
1623 struct uart_port *port = &s->port; 1460 struct uart_port *port = &s->port;
1624 u16 scr = serial_port_in(port, SCSCR); 1461 u16 scr = sci_in(port, SCSCR);
1625 1462
1626 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { 1463 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1627 scr &= ~0x4000; 1464 scr &= ~0x4000;
1628 enable_irq(s->cfg->irqs[1]); 1465 enable_irq(s->cfg->irqs[1]);
1629 } 1466 }
1630 serial_port_out(port, SCSCR, scr | SCSCR_RIE); 1467 sci_out(port, SCSCR, scr | SCSCR_RIE);
1631 dev_dbg(port->dev, "DMA Rx timed out\n"); 1468 dev_dbg(port->dev, "DMA Rx timed out\n");
1632 schedule_work(&s->work_rx); 1469 schedule_work(&s->work_rx);
1633} 1470}
@@ -1640,10 +1477,10 @@ static void sci_request_dma(struct uart_port *port)
1640 dma_cap_mask_t mask; 1477 dma_cap_mask_t mask;
1641 int nent; 1478 int nent;
1642 1479
1643 dev_dbg(port->dev, "%s: port %d\n", __func__, 1480 dev_dbg(port->dev, "%s: port %d DMA %p\n", __func__,
1644 port->line); 1481 port->line, s->cfg->dma_dev);
1645 1482
1646 if (s->cfg->dma_slave_tx <= 0 || s->cfg->dma_slave_rx <= 0) 1483 if (!s->cfg->dma_dev)
1647 return; 1484 return;
1648 1485
1649 dma_cap_zero(mask); 1486 dma_cap_zero(mask);
@@ -1652,7 +1489,8 @@ static void sci_request_dma(struct uart_port *port)
1652 param = &s->param_tx; 1489 param = &s->param_tx;
1653 1490
1654 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */ 1491 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */
1655 param->shdma_slave.slave_id = s->cfg->dma_slave_tx; 1492 param->slave_id = s->cfg->dma_slave_tx;
1493 param->dma_dev = s->cfg->dma_dev;
1656 1494
1657 s->cookie_tx = -EINVAL; 1495 s->cookie_tx = -EINVAL;
1658 chan = dma_request_channel(mask, filter, param); 1496 chan = dma_request_channel(mask, filter, param);
@@ -1680,7 +1518,8 @@ static void sci_request_dma(struct uart_port *port)
1680 param = &s->param_rx; 1518 param = &s->param_rx;
1681 1519
1682 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */ 1520 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */
1683 param->shdma_slave.slave_id = s->cfg->dma_slave_rx; 1521 param->slave_id = s->cfg->dma_slave_rx;
1522 param->dma_dev = s->cfg->dma_dev;
1684 1523
1685 chan = dma_request_channel(mask, filter, param); 1524 chan = dma_request_channel(mask, filter, param);
1686 dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan); 1525 dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan);
@@ -1725,6 +1564,9 @@ static void sci_free_dma(struct uart_port *port)
1725{ 1564{
1726 struct sci_port *s = to_sci_port(port); 1565 struct sci_port *s = to_sci_port(port);
1727 1566
1567 if (!s->cfg->dma_dev)
1568 return;
1569
1728 if (s->chan_tx) 1570 if (s->chan_tx)
1729 sci_tx_dma_release(s, false); 1571 sci_tx_dma_release(s, false);
1730 if (s->chan_rx) 1572 if (s->chan_rx)
@@ -1743,21 +1585,20 @@ static inline void sci_free_dma(struct uart_port *port)
1743static int sci_startup(struct uart_port *port) 1585static int sci_startup(struct uart_port *port)
1744{ 1586{
1745 struct sci_port *s = to_sci_port(port); 1587 struct sci_port *s = to_sci_port(port);
1746 unsigned long flags;
1747 int ret; 1588 int ret;
1748 1589
1749 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); 1590 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
1750 1591
1592 sci_port_enable(s);
1593
1751 ret = sci_request_irq(s); 1594 ret = sci_request_irq(s);
1752 if (unlikely(ret < 0)) 1595 if (unlikely(ret < 0))
1753 return ret; 1596 return ret;
1754 1597
1755 sci_request_dma(port); 1598 sci_request_dma(port);
1756 1599
1757 spin_lock_irqsave(&port->lock, flags);
1758 sci_start_tx(port); 1600 sci_start_tx(port);
1759 sci_start_rx(port); 1601 sci_start_rx(port);
1760 spin_unlock_irqrestore(&port->lock, flags);
1761 1602
1762 return 0; 1603 return 0;
1763} 1604}
@@ -1765,17 +1606,16 @@ static int sci_startup(struct uart_port *port)
1765static void sci_shutdown(struct uart_port *port) 1606static void sci_shutdown(struct uart_port *port)
1766{ 1607{
1767 struct sci_port *s = to_sci_port(port); 1608 struct sci_port *s = to_sci_port(port);
1768 unsigned long flags;
1769 1609
1770 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); 1610 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
1771 1611
1772 spin_lock_irqsave(&port->lock, flags);
1773 sci_stop_rx(port); 1612 sci_stop_rx(port);
1774 sci_stop_tx(port); 1613 sci_stop_tx(port);
1775 spin_unlock_irqrestore(&port->lock, flags);
1776 1614
1777 sci_free_dma(port); 1615 sci_free_dma(port);
1778 sci_free_irq(s); 1616 sci_free_irq(s);
1617
1618 sci_port_disable(s);
1779} 1619}
1780 1620
1781static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps, 1621static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps,
@@ -1802,27 +1642,25 @@ static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps,
1802 1642
1803static void sci_reset(struct uart_port *port) 1643static void sci_reset(struct uart_port *port)
1804{ 1644{
1805 struct plat_sci_reg *reg;
1806 unsigned int status; 1645 unsigned int status;
1807 1646
1808 do { 1647 do {
1809 status = serial_port_in(port, SCxSR); 1648 status = sci_in(port, SCxSR);
1810 } while (!(status & SCxSR_TEND(port))); 1649 } while (!(status & SCxSR_TEND(port)));
1811 1650
1812 serial_port_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */ 1651 sci_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */
1813 1652
1814 reg = sci_getreg(port, SCFCR); 1653 if (port->type != PORT_SCI)
1815 if (reg->size) 1654 sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
1816 serial_port_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
1817} 1655}
1818 1656
1819static void sci_set_termios(struct uart_port *port, struct ktermios *termios, 1657static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1820 struct ktermios *old) 1658 struct ktermios *old)
1821{ 1659{
1822 struct sci_port *s = to_sci_port(port); 1660 struct sci_port *s = to_sci_port(port);
1823 struct plat_sci_reg *reg; 1661 unsigned int baud, smr_val, max_baud;
1824 unsigned int baud, smr_val, max_baud, cks;
1825 int t = -1; 1662 int t = -1;
1663 u16 scfcr = 0;
1826 1664
1827 /* 1665 /*
1828 * earlyprintk comes here early on with port->uartclk set to zero. 1666 * earlyprintk comes here early on with port->uartclk set to zero.
@@ -1842,7 +1680,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1842 1680
1843 sci_reset(port); 1681 sci_reset(port);
1844 1682
1845 smr_val = serial_port_in(port, SCSMR) & 3; 1683 smr_val = sci_in(port, SCSMR) & 3;
1846 1684
1847 if ((termios->c_cflag & CSIZE) == CS7) 1685 if ((termios->c_cflag & CSIZE) == CS7)
1848 smr_val |= 0x40; 1686 smr_val |= 0x40;
@@ -1855,43 +1693,26 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1855 1693
1856 uart_update_timeout(port, termios->c_cflag, baud); 1694 uart_update_timeout(port, termios->c_cflag, baud);
1857 1695
1858 for (cks = 0; t >= 256 && cks <= 3; cks++) 1696 sci_out(port, SCSMR, smr_val);
1859 t >>= 2; 1697
1698 dev_dbg(port->dev, "%s: SMR %x, t %x, SCSCR %x\n", __func__, smr_val, t,
1699 s->cfg->scscr);
1860 1700
1861 dev_dbg(port->dev, "%s: SMR %x, cks %x, t %x, SCSCR %x\n", 1701 if (t > 0) {
1862 __func__, smr_val, cks, t, s->cfg->scscr); 1702 if (t >= 256) {
1703 sci_out(port, SCSMR, (sci_in(port, SCSMR) & ~3) | 1);
1704 t >>= 2;
1705 } else
1706 sci_out(port, SCSMR, sci_in(port, SCSMR) & ~3);
1863 1707
1864 if (t >= 0) { 1708 sci_out(port, SCBRR, t);
1865 serial_port_out(port, SCSMR, (smr_val & ~3) | cks);
1866 serial_port_out(port, SCBRR, t);
1867 udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */ 1709 udelay((1000000+(baud-1)) / baud); /* Wait one bit interval */
1868 } else 1710 }
1869 serial_port_out(port, SCSMR, smr_val);
1870 1711
1871 sci_init_pins(port, termios->c_cflag); 1712 sci_init_pins(port, termios->c_cflag);
1713 sci_out(port, SCFCR, scfcr | ((termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0));
1872 1714
1873 reg = sci_getreg(port, SCFCR); 1715 sci_out(port, SCSCR, s->cfg->scscr);
1874 if (reg->size) {
1875 unsigned short ctrl = serial_port_in(port, SCFCR);
1876
1877 if (s->cfg->capabilities & SCIx_HAVE_RTSCTS) {
1878 if (termios->c_cflag & CRTSCTS)
1879 ctrl |= SCFCR_MCE;
1880 else
1881 ctrl &= ~SCFCR_MCE;
1882 }
1883
1884 /*
1885 * As we've done a sci_reset() above, ensure we don't
1886 * interfere with the FIFOs while toggling MCE. As the
1887 * reset values could still be set, simply mask them out.
1888 */
1889 ctrl &= ~(SCFCR_RFRST | SCFCR_TFRST);
1890
1891 serial_port_out(port, SCFCR, ctrl);
1892 }
1893
1894 serial_port_out(port, SCSCR, s->cfg->scscr);
1895 1716
1896#ifdef CONFIG_SERIAL_SH_SCI_DMA 1717#ifdef CONFIG_SERIAL_SH_SCI_DMA
1897 /* 1718 /*
@@ -1921,21 +1742,6 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
1921 sci_port_disable(s); 1742 sci_port_disable(s);
1922} 1743}
1923 1744
1924static void sci_pm(struct uart_port *port, unsigned int state,
1925 unsigned int oldstate)
1926{
1927 struct sci_port *sci_port = to_sci_port(port);
1928
1929 switch (state) {
1930 case 3:
1931 sci_port_disable(sci_port);
1932 break;
1933 default:
1934 sci_port_enable(sci_port);
1935 break;
1936 }
1937}
1938
1939static const char *sci_type(struct uart_port *port) 1745static const char *sci_type(struct uart_port *port)
1940{ 1746{
1941 switch (port->type) { 1747 switch (port->type) {
@@ -2057,7 +1863,6 @@ static struct uart_ops sci_uart_ops = {
2057 .startup = sci_startup, 1863 .startup = sci_startup,
2058 .shutdown = sci_shutdown, 1864 .shutdown = sci_shutdown,
2059 .set_termios = sci_set_termios, 1865 .set_termios = sci_set_termios,
2060 .pm = sci_pm,
2061 .type = sci_type, 1866 .type = sci_type,
2062 .release_port = sci_release_port, 1867 .release_port = sci_release_port,
2063 .request_port = sci_request_port, 1868 .request_port = sci_request_port,
@@ -2069,7 +1874,7 @@ static struct uart_ops sci_uart_ops = {
2069#endif 1874#endif
2070}; 1875};
2071 1876
2072static int sci_init_single(struct platform_device *dev, 1877static int __devinit sci_init_single(struct platform_device *dev,
2073 struct sci_port *sci_port, 1878 struct sci_port *sci_port,
2074 unsigned int index, 1879 unsigned int index,
2075 struct plat_sci_port *p) 1880 struct plat_sci_port *p)
@@ -2077,8 +1882,6 @@ static int sci_init_single(struct platform_device *dev,
2077 struct uart_port *port = &sci_port->port; 1882 struct uart_port *port = &sci_port->port;
2078 int ret; 1883 int ret;
2079 1884
2080 sci_port->cfg = p;
2081
2082 port->ops = &sci_uart_ops; 1885 port->ops = &sci_uart_ops;
2083 port->iotype = UPIO_MEM; 1886 port->iotype = UPIO_MEM;
2084 port->line = index; 1887 port->line = index;
@@ -2124,8 +1927,7 @@ static int sci_init_single(struct platform_device *dev,
2124 1927
2125 port->dev = &dev->dev; 1928 port->dev = &dev->dev;
2126 1929
2127 sci_init_gpios(sci_port); 1930 pm_runtime_irq_safe(&dev->dev);
2128
2129 pm_runtime_enable(&dev->dev); 1931 pm_runtime_enable(&dev->dev);
2130 } 1932 }
2131 1933
@@ -2159,6 +1961,8 @@ static int sci_init_single(struct platform_device *dev,
2159 p->error_mask |= (1 << p->overrun_bit); 1961 p->error_mask |= (1 << p->overrun_bit);
2160 } 1962 }
2161 1963
1964 sci_port->cfg = p;
1965
2162 port->mapbase = p->mapbase; 1966 port->mapbase = p->mapbase;
2163 port->type = p->type; 1967 port->type = p->type;
2164 port->flags = p->flags; 1968 port->flags = p->flags;
@@ -2172,28 +1976,18 @@ static int sci_init_single(struct platform_device *dev,
2172 * For the muxed case there's nothing more to do. 1976 * For the muxed case there's nothing more to do.
2173 */ 1977 */
2174 port->irq = p->irqs[SCIx_RXI_IRQ]; 1978 port->irq = p->irqs[SCIx_RXI_IRQ];
2175 port->irqflags = 0; 1979 port->irqflags = IRQF_DISABLED;
2176 1980
2177 port->serial_in = sci_serial_in; 1981 port->serial_in = sci_serial_in;
2178 port->serial_out = sci_serial_out; 1982 port->serial_out = sci_serial_out;
2179 1983
2180 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) 1984 if (p->dma_dev)
2181 dev_dbg(port->dev, "DMA tx %d, rx %d\n", 1985 dev_dbg(port->dev, "DMA device %p, tx %d, rx %d\n",
2182 p->dma_slave_tx, p->dma_slave_rx); 1986 p->dma_dev, p->dma_slave_tx, p->dma_slave_rx);
2183 1987
2184 return 0; 1988 return 0;
2185} 1989}
2186 1990
2187static void sci_cleanup_single(struct sci_port *port)
2188{
2189 sci_free_gpios(port);
2190
2191 clk_put(port->iclk);
2192 clk_put(port->fclk);
2193
2194 pm_runtime_disable(port->port.dev);
2195}
2196
2197#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE 1991#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
2198static void serial_console_putchar(struct uart_port *port, int ch) 1992static void serial_console_putchar(struct uart_port *port, int ch)
2199{ 1993{
@@ -2209,38 +2003,21 @@ static void serial_console_write(struct console *co, const char *s,
2209{ 2003{
2210 struct sci_port *sci_port = &sci_ports[co->index]; 2004 struct sci_port *sci_port = &sci_ports[co->index];
2211 struct uart_port *port = &sci_port->port; 2005 struct uart_port *port = &sci_port->port;
2212 unsigned short bits, ctrl; 2006 unsigned short bits;
2213 unsigned long flags;
2214 int locked = 1;
2215 2007
2216 local_irq_save(flags); 2008 sci_port_enable(sci_port);
2217 if (port->sysrq)
2218 locked = 0;
2219 else if (oops_in_progress)
2220 locked = spin_trylock(&port->lock);
2221 else
2222 spin_lock(&port->lock);
2223
2224 /* first save the SCSCR then disable the interrupts */
2225 ctrl = serial_port_in(port, SCSCR);
2226 serial_port_out(port, SCSCR, sci_port->cfg->scscr);
2227 2009
2228 uart_console_write(port, s, count, serial_console_putchar); 2010 uart_console_write(port, s, count, serial_console_putchar);
2229 2011
2230 /* wait until fifo is empty and last bit has been transmitted */ 2012 /* wait until fifo is empty and last bit has been transmitted */
2231 bits = SCxSR_TDxE(port) | SCxSR_TEND(port); 2013 bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
2232 while ((serial_port_in(port, SCxSR) & bits) != bits) 2014 while ((sci_in(port, SCxSR) & bits) != bits)
2233 cpu_relax(); 2015 cpu_relax();
2234 2016
2235 /* restore the SCSCR */ 2017 sci_port_disable(sci_port);
2236 serial_port_out(port, SCSCR, ctrl);
2237
2238 if (locked)
2239 spin_unlock(&port->lock);
2240 local_irq_restore(flags);
2241} 2018}
2242 2019
2243static int serial_console_setup(struct console *co, char *options) 2020static int __devinit serial_console_setup(struct console *co, char *options)
2244{ 2021{
2245 struct sci_port *sci_port; 2022 struct sci_port *sci_port;
2246 struct uart_port *port; 2023 struct uart_port *port;
@@ -2269,9 +2046,13 @@ static int serial_console_setup(struct console *co, char *options)
2269 if (unlikely(ret != 0)) 2046 if (unlikely(ret != 0))
2270 return ret; 2047 return ret;
2271 2048
2049 sci_port_enable(sci_port);
2050
2272 if (options) 2051 if (options)
2273 uart_parse_options(options, &baud, &parity, &bits, &flow); 2052 uart_parse_options(options, &baud, &parity, &bits, &flow);
2274 2053
2054 sci_port_disable(sci_port);
2055
2275 return uart_set_options(port, co, baud, parity, bits, flow); 2056 return uart_set_options(port, co, baud, parity, bits, flow);
2276} 2057}
2277 2058
@@ -2294,7 +2075,7 @@ static struct console early_serial_console = {
2294 2075
2295static char early_serial_buf[32]; 2076static char early_serial_buf[32];
2296 2077
2297static int sci_probe_earlyprintk(struct platform_device *pdev) 2078static int __devinit sci_probe_earlyprintk(struct platform_device *pdev)
2298{ 2079{
2299 struct plat_sci_port *cfg = pdev->dev.platform_data; 2080 struct plat_sci_port *cfg = pdev->dev.platform_data;
2300 2081
@@ -2314,15 +2095,47 @@ static int sci_probe_earlyprintk(struct platform_device *pdev)
2314 return 0; 2095 return 0;
2315} 2096}
2316 2097
2098#define uart_console(port) ((port)->cons->index == (port)->line)
2099
2100static int sci_runtime_suspend(struct device *dev)
2101{
2102 struct sci_port *sci_port = dev_get_drvdata(dev);
2103 struct uart_port *port = &sci_port->port;
2104
2105 if (uart_console(port)) {
2106 sci_port->saved_smr = sci_in(port, SCSMR);
2107 sci_port->saved_brr = sci_in(port, SCBRR);
2108 sci_port->saved_fcr = sci_in(port, SCFCR);
2109 }
2110 return 0;
2111}
2112
2113static int sci_runtime_resume(struct device *dev)
2114{
2115 struct sci_port *sci_port = dev_get_drvdata(dev);
2116 struct uart_port *port = &sci_port->port;
2117
2118 if (uart_console(port)) {
2119 sci_reset(port);
2120 sci_out(port, SCSMR, sci_port->saved_smr);
2121 sci_out(port, SCBRR, sci_port->saved_brr);
2122 sci_out(port, SCFCR, sci_port->saved_fcr);
2123 sci_out(port, SCSCR, sci_port->cfg->scscr);
2124 }
2125 return 0;
2126}
2127
2317#define SCI_CONSOLE (&serial_console) 2128#define SCI_CONSOLE (&serial_console)
2318 2129
2319#else 2130#else
2320static inline int sci_probe_earlyprintk(struct platform_device *pdev) 2131static inline int __devinit sci_probe_earlyprintk(struct platform_device *pdev)
2321{ 2132{
2322 return -EINVAL; 2133 return -EINVAL;
2323} 2134}
2324 2135
2325#define SCI_CONSOLE NULL 2136#define SCI_CONSOLE NULL
2137#define sci_runtime_suspend NULL
2138#define sci_runtime_resume NULL
2326 2139
2327#endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */ 2140#endif /* CONFIG_SERIAL_SH_SCI_CONSOLE */
2328 2141
@@ -2348,12 +2161,14 @@ static int sci_remove(struct platform_device *dev)
2348 2161
2349 uart_remove_one_port(&sci_uart_driver, &port->port); 2162 uart_remove_one_port(&sci_uart_driver, &port->port);
2350 2163
2351 sci_cleanup_single(port); 2164 clk_put(port->iclk);
2165 clk_put(port->fclk);
2352 2166
2167 pm_runtime_disable(&dev->dev);
2353 return 0; 2168 return 0;
2354} 2169}
2355 2170
2356static int sci_probe_single(struct platform_device *dev, 2171static int __devinit sci_probe_single(struct platform_device *dev,
2357 unsigned int index, 2172 unsigned int index,
2358 struct plat_sci_port *p, 2173 struct plat_sci_port *p,
2359 struct sci_port *sciport) 2174 struct sci_port *sciport)
@@ -2367,23 +2182,17 @@ static int sci_probe_single(struct platform_device *dev,
2367 index+1, SCI_NPORTS); 2182 index+1, SCI_NPORTS);
2368 dev_notice(&dev->dev, "Consider bumping " 2183 dev_notice(&dev->dev, "Consider bumping "
2369 "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n"); 2184 "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n");
2370 return -EINVAL; 2185 return 0;
2371 } 2186 }
2372 2187
2373 ret = sci_init_single(dev, sciport, index, p); 2188 ret = sci_init_single(dev, sciport, index, p);
2374 if (ret) 2189 if (ret)
2375 return ret; 2190 return ret;
2376 2191
2377 ret = uart_add_one_port(&sci_uart_driver, &sciport->port); 2192 return uart_add_one_port(&sci_uart_driver, &sciport->port);
2378 if (ret) {
2379 sci_cleanup_single(sciport);
2380 return ret;
2381 }
2382
2383 return 0;
2384} 2193}
2385 2194
2386static int sci_probe(struct platform_device *dev) 2195static int __devinit sci_probe(struct platform_device *dev)
2387{ 2196{
2388 struct plat_sci_port *p = dev->dev.platform_data; 2197 struct plat_sci_port *p = dev->dev.platform_data;
2389 struct sci_port *sp = &sci_ports[dev->id]; 2198 struct sci_port *sp = &sci_ports[dev->id];
@@ -2401,22 +2210,24 @@ static int sci_probe(struct platform_device *dev)
2401 2210
2402 ret = sci_probe_single(dev, dev->id, p, sp); 2211 ret = sci_probe_single(dev, dev->id, p, sp);
2403 if (ret) 2212 if (ret)
2404 return ret; 2213 goto err_unreg;
2405 2214
2406 sp->freq_transition.notifier_call = sci_notifier; 2215 sp->freq_transition.notifier_call = sci_notifier;
2407 2216
2408 ret = cpufreq_register_notifier(&sp->freq_transition, 2217 ret = cpufreq_register_notifier(&sp->freq_transition,
2409 CPUFREQ_TRANSITION_NOTIFIER); 2218 CPUFREQ_TRANSITION_NOTIFIER);
2410 if (unlikely(ret < 0)) { 2219 if (unlikely(ret < 0))
2411 sci_cleanup_single(sp); 2220 goto err_unreg;
2412 return ret;
2413 }
2414 2221
2415#ifdef CONFIG_SH_STANDARD_BIOS 2222#ifdef CONFIG_SH_STANDARD_BIOS
2416 sh_bios_gdb_detach(); 2223 sh_bios_gdb_detach();
2417#endif 2224#endif
2418 2225
2419 return 0; 2226 return 0;
2227
2228err_unreg:
2229 sci_remove(dev);
2230 return ret;
2420} 2231}
2421 2232
2422static int sci_suspend(struct device *dev) 2233static int sci_suspend(struct device *dev)
@@ -2440,6 +2251,8 @@ static int sci_resume(struct device *dev)
2440} 2251}
2441 2252
2442static const struct dev_pm_ops sci_dev_pm_ops = { 2253static const struct dev_pm_ops sci_dev_pm_ops = {
2254 .runtime_suspend = sci_runtime_suspend,
2255 .runtime_resume = sci_runtime_resume,
2443 .suspend = sci_suspend, 2256 .suspend = sci_suspend,
2444 .resume = sci_resume, 2257 .resume = sci_resume,
2445}; 2258};
diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h
index 4c22a1529aa..e9bed038aa1 100644
--- a/drivers/tty/serial/sh-sci.h
+++ b/drivers/tty/serial/sh-sci.h
@@ -17,13 +17,11 @@
17 defined(CONFIG_ARCH_SH73A0) || \ 17 defined(CONFIG_ARCH_SH73A0) || \
18 defined(CONFIG_ARCH_SH7367) || \ 18 defined(CONFIG_ARCH_SH7367) || \
19 defined(CONFIG_ARCH_SH7377) || \ 19 defined(CONFIG_ARCH_SH7377) || \
20 defined(CONFIG_ARCH_SH7372) || \ 20 defined(CONFIG_ARCH_SH7372)
21 defined(CONFIG_ARCH_R8A7740) 21# define SCxSR_RDxF_CLEAR(port) (sci_in(port, SCxSR) & 0xfffc)
22 22# define SCxSR_ERROR_CLEAR(port) (sci_in(port, SCxSR) & 0xfd73)
23# define SCxSR_RDxF_CLEAR(port) (serial_port_in(port, SCxSR) & 0xfffc) 23# define SCxSR_TDxE_CLEAR(port) (sci_in(port, SCxSR) & 0xffdf)
24# define SCxSR_ERROR_CLEAR(port) (serial_port_in(port, SCxSR) & 0xfd73) 24# define SCxSR_BREAK_CLEAR(port) (sci_in(port, SCxSR) & 0xffe3)
25# define SCxSR_TDxE_CLEAR(port) (serial_port_in(port, SCxSR) & 0xffdf)
26# define SCxSR_BREAK_CLEAR(port) (serial_port_in(port, SCxSR) & 0xffe3)
27#else 25#else
28# define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc) 26# define SCxSR_RDxF_CLEAR(port) (((port)->type == PORT_SCI) ? 0xbc : 0x00fc)
29# define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073) 27# define SCxSR_ERROR_CLEAR(port) (((port)->type == PORT_SCI) ? 0xc4 : 0x0073)
diff --git a/drivers/tty/serial/sirfsoc_uart.c b/drivers/tty/serial/sirfsoc_uart.c
deleted file mode 100644
index 5da5cb96276..00000000000
--- a/drivers/tty/serial/sirfsoc_uart.c
+++ /dev/null
@@ -1,773 +0,0 @@
1/*
2 * Driver for CSR SiRFprimaII onboard UARTs.
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/module.h>
10#include <linux/ioport.h>
11#include <linux/platform_device.h>
12#include <linux/init.h>
13#include <linux/sysrq.h>
14#include <linux/console.h>
15#include <linux/tty.h>
16#include <linux/tty_flip.h>
17#include <linux/serial_core.h>
18#include <linux/serial.h>
19#include <linux/clk.h>
20#include <linux/of.h>
21#include <linux/slab.h>
22#include <linux/io.h>
23#include <asm/irq.h>
24#include <asm/mach/irq.h>
25#include <linux/pinctrl/consumer.h>
26
27#include "sirfsoc_uart.h"
28
29static unsigned int
30sirfsoc_uart_pio_tx_chars(struct sirfsoc_uart_port *sirfport, int count);
31static unsigned int
32sirfsoc_uart_pio_rx_chars(struct uart_port *port, unsigned int max_rx_count);
33static struct uart_driver sirfsoc_uart_drv;
34
35static const struct sirfsoc_baudrate_to_regv baudrate_to_regv[] = {
36 {4000000, 2359296},
37 {3500000, 1310721},
38 {3000000, 1572865},
39 {2500000, 1245186},
40 {2000000, 1572866},
41 {1500000, 1245188},
42 {1152000, 1638404},
43 {1000000, 1572869},
44 {921600, 1114120},
45 {576000, 1245196},
46 {500000, 1245198},
47 {460800, 1572876},
48 {230400, 1310750},
49 {115200, 1310781},
50 {57600, 1310843},
51 {38400, 1114328},
52 {19200, 1114545},
53 {9600, 1114979},
54};
55
56static struct sirfsoc_uart_port sirfsoc_uart_ports[SIRFSOC_UART_NR] = {
57 [0] = {
58 .port = {
59 .iotype = UPIO_MEM,
60 .flags = UPF_BOOT_AUTOCONF,
61 .line = 0,
62 },
63 },
64 [1] = {
65 .port = {
66 .iotype = UPIO_MEM,
67 .flags = UPF_BOOT_AUTOCONF,
68 .line = 1,
69 },
70 },
71 [2] = {
72 .port = {
73 .iotype = UPIO_MEM,
74 .flags = UPF_BOOT_AUTOCONF,
75 .line = 2,
76 },
77 },
78};
79
80static inline struct sirfsoc_uart_port *to_sirfport(struct uart_port *port)
81{
82 return container_of(port, struct sirfsoc_uart_port, port);
83}
84
85static inline unsigned int sirfsoc_uart_tx_empty(struct uart_port *port)
86{
87 unsigned long reg;
88 reg = rd_regl(port, SIRFUART_TX_FIFO_STATUS);
89 if (reg & SIRFUART_FIFOEMPTY_MASK(port))
90 return TIOCSER_TEMT;
91 else
92 return 0;
93}
94
95static unsigned int sirfsoc_uart_get_mctrl(struct uart_port *port)
96{
97 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
98 if (!(sirfport->ms_enabled)) {
99 goto cts_asserted;
100 } else if (sirfport->hw_flow_ctrl) {
101 if (!(rd_regl(port, SIRFUART_AFC_CTRL) &
102 SIRFUART_CTS_IN_STATUS))
103 goto cts_asserted;
104 else
105 goto cts_deasserted;
106 }
107cts_deasserted:
108 return TIOCM_CAR | TIOCM_DSR;
109cts_asserted:
110 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
111}
112
113static void sirfsoc_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
114{
115 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
116 unsigned int assert = mctrl & TIOCM_RTS;
117 unsigned int val = assert ? SIRFUART_AFC_CTRL_RX_THD : 0x0;
118 unsigned int current_val;
119 if (sirfport->hw_flow_ctrl) {
120 current_val = rd_regl(port, SIRFUART_AFC_CTRL) & ~0xFF;
121 val |= current_val;
122 wr_regl(port, SIRFUART_AFC_CTRL, val);
123 }
124}
125
126static void sirfsoc_uart_stop_tx(struct uart_port *port)
127{
128 unsigned int regv;
129 regv = rd_regl(port, SIRFUART_INT_EN);
130 wr_regl(port, SIRFUART_INT_EN, regv & ~SIRFUART_TX_INT_EN);
131}
132
133void sirfsoc_uart_start_tx(struct uart_port *port)
134{
135 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
136 unsigned long regv;
137 sirfsoc_uart_pio_tx_chars(sirfport, 1);
138 wr_regl(port, SIRFUART_TX_FIFO_OP, SIRFUART_TX_FIFO_START);
139 regv = rd_regl(port, SIRFUART_INT_EN);
140 wr_regl(port, SIRFUART_INT_EN, regv | SIRFUART_TX_INT_EN);
141}
142
143static void sirfsoc_uart_stop_rx(struct uart_port *port)
144{
145 unsigned long regv;
146 wr_regl(port, SIRFUART_RX_FIFO_OP, 0);
147 regv = rd_regl(port, SIRFUART_INT_EN);
148 wr_regl(port, SIRFUART_INT_EN, regv & ~SIRFUART_RX_IO_INT_EN);
149}
150
151static void sirfsoc_uart_disable_ms(struct uart_port *port)
152{
153 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
154 unsigned long reg;
155 sirfport->ms_enabled = 0;
156 if (!sirfport->hw_flow_ctrl)
157 return;
158 reg = rd_regl(port, SIRFUART_AFC_CTRL);
159 wr_regl(port, SIRFUART_AFC_CTRL, reg & ~0x3FF);
160 reg = rd_regl(port, SIRFUART_INT_EN);
161 wr_regl(port, SIRFUART_INT_EN, reg & ~SIRFUART_CTS_INT_EN);
162}
163
164static void sirfsoc_uart_enable_ms(struct uart_port *port)
165{
166 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
167 unsigned long reg;
168 unsigned long flg;
169 if (!sirfport->hw_flow_ctrl)
170 return;
171 flg = SIRFUART_AFC_RX_EN | SIRFUART_AFC_TX_EN;
172 reg = rd_regl(port, SIRFUART_AFC_CTRL);
173 wr_regl(port, SIRFUART_AFC_CTRL, reg | flg);
174 reg = rd_regl(port, SIRFUART_INT_EN);
175 wr_regl(port, SIRFUART_INT_EN, reg | SIRFUART_CTS_INT_EN);
176 uart_handle_cts_change(port,
177 !(rd_regl(port, SIRFUART_AFC_CTRL) & SIRFUART_CTS_IN_STATUS));
178 sirfport->ms_enabled = 1;
179}
180
181static void sirfsoc_uart_break_ctl(struct uart_port *port, int break_state)
182{
183 unsigned long ulcon = rd_regl(port, SIRFUART_LINE_CTRL);
184 if (break_state)
185 ulcon |= SIRFUART_SET_BREAK;
186 else
187 ulcon &= ~SIRFUART_SET_BREAK;
188 wr_regl(port, SIRFUART_LINE_CTRL, ulcon);
189}
190
191static unsigned int
192sirfsoc_uart_pio_rx_chars(struct uart_port *port, unsigned int max_rx_count)
193{
194 unsigned int ch, rx_count = 0;
195 struct tty_struct *tty;
196
197 tty = tty_port_tty_get(&port->state->port);
198 if (!tty)
199 return -ENODEV;
200
201 while (!(rd_regl(port, SIRFUART_RX_FIFO_STATUS) &
202 SIRFUART_FIFOEMPTY_MASK(port))) {
203 ch = rd_regl(port, SIRFUART_RX_FIFO_DATA) | SIRFUART_DUMMY_READ;
204 if (unlikely(uart_handle_sysrq_char(port, ch)))
205 continue;
206 uart_insert_char(port, 0, 0, ch, TTY_NORMAL);
207 rx_count++;
208 if (rx_count >= max_rx_count)
209 break;
210 }
211
212 port->icount.rx += rx_count;
213 tty_flip_buffer_push(tty);
214 tty_kref_put(tty);
215
216 return rx_count;
217}
218
219static unsigned int
220sirfsoc_uart_pio_tx_chars(struct sirfsoc_uart_port *sirfport, int count)
221{
222 struct uart_port *port = &sirfport->port;
223 struct circ_buf *xmit = &port->state->xmit;
224 unsigned int num_tx = 0;
225 while (!uart_circ_empty(xmit) &&
226 !(rd_regl(port, SIRFUART_TX_FIFO_STATUS) &
227 SIRFUART_FIFOFULL_MASK(port)) &&
228 count--) {
229 wr_regl(port, SIRFUART_TX_FIFO_DATA, xmit->buf[xmit->tail]);
230 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
231 port->icount.tx++;
232 num_tx++;
233 }
234 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
235 uart_write_wakeup(port);
236 return num_tx;
237}
238
239static irqreturn_t sirfsoc_uart_isr(int irq, void *dev_id)
240{
241 unsigned long intr_status;
242 unsigned long cts_status;
243 unsigned long flag = TTY_NORMAL;
244 struct sirfsoc_uart_port *sirfport = (struct sirfsoc_uart_port *)dev_id;
245 struct uart_port *port = &sirfport->port;
246 struct uart_state *state = port->state;
247 struct circ_buf *xmit = &port->state->xmit;
248 intr_status = rd_regl(port, SIRFUART_INT_STATUS);
249 wr_regl(port, SIRFUART_INT_STATUS, intr_status);
250 intr_status &= rd_regl(port, SIRFUART_INT_EN);
251 if (unlikely(intr_status & (SIRFUART_ERR_INT_STAT))) {
252 if (intr_status & SIRFUART_RXD_BREAK) {
253 if (uart_handle_break(port))
254 goto recv_char;
255 uart_insert_char(port, intr_status,
256 SIRFUART_RX_OFLOW, 0, TTY_BREAK);
257 return IRQ_HANDLED;
258 }
259 if (intr_status & SIRFUART_RX_OFLOW)
260 port->icount.overrun++;
261 if (intr_status & SIRFUART_FRM_ERR) {
262 port->icount.frame++;
263 flag = TTY_FRAME;
264 }
265 if (intr_status & SIRFUART_PARITY_ERR)
266 flag = TTY_PARITY;
267 wr_regl(port, SIRFUART_RX_FIFO_OP, SIRFUART_RX_FIFO_RESET);
268 wr_regl(port, SIRFUART_RX_FIFO_OP, 0);
269 wr_regl(port, SIRFUART_RX_FIFO_OP, SIRFUART_RX_FIFO_START);
270 intr_status &= port->read_status_mask;
271 uart_insert_char(port, intr_status,
272 SIRFUART_RX_OFLOW_INT, 0, flag);
273 }
274recv_char:
275 if (intr_status & SIRFUART_CTS_INT_EN) {
276 cts_status = !(rd_regl(port, SIRFUART_AFC_CTRL) &
277 SIRFUART_CTS_IN_STATUS);
278 if (cts_status != 0) {
279 uart_handle_cts_change(port, 1);
280 } else {
281 uart_handle_cts_change(port, 0);
282 wake_up_interruptible(&state->port.delta_msr_wait);
283 }
284 }
285 if (intr_status & SIRFUART_RX_IO_INT_EN)
286 sirfsoc_uart_pio_rx_chars(port, SIRFSOC_UART_IO_RX_MAX_CNT);
287 if (intr_status & SIRFUART_TX_INT_EN) {
288 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
289 return IRQ_HANDLED;
290 } else {
291 sirfsoc_uart_pio_tx_chars(sirfport,
292 SIRFSOC_UART_IO_TX_REASONABLE_CNT);
293 if ((uart_circ_empty(xmit)) &&
294 (rd_regl(port, SIRFUART_TX_FIFO_STATUS) &
295 SIRFUART_FIFOEMPTY_MASK(port)))
296 sirfsoc_uart_stop_tx(port);
297 }
298 }
299 return IRQ_HANDLED;
300}
301
302static void sirfsoc_uart_start_rx(struct uart_port *port)
303{
304 unsigned long regv;
305 regv = rd_regl(port, SIRFUART_INT_EN);
306 wr_regl(port, SIRFUART_INT_EN, regv | SIRFUART_RX_IO_INT_EN);
307 wr_regl(port, SIRFUART_RX_FIFO_OP, SIRFUART_RX_FIFO_RESET);
308 wr_regl(port, SIRFUART_RX_FIFO_OP, 0);
309 wr_regl(port, SIRFUART_RX_FIFO_OP, SIRFUART_RX_FIFO_START);
310}
311
312static unsigned int
313sirfsoc_calc_sample_div(unsigned long baud_rate,
314 unsigned long ioclk_rate, unsigned long *setted_baud)
315{
316 unsigned long min_delta = ~0UL;
317 unsigned short sample_div;
318 unsigned int regv = 0;
319 unsigned long ioclk_div;
320 unsigned long baud_tmp;
321 int temp_delta;
322
323 for (sample_div = SIRF_MIN_SAMPLE_DIV;
324 sample_div <= SIRF_MAX_SAMPLE_DIV; sample_div++) {
325 ioclk_div = (ioclk_rate / (baud_rate * (sample_div + 1))) - 1;
326 if (ioclk_div > SIRF_IOCLK_DIV_MAX)
327 continue;
328 baud_tmp = ioclk_rate / ((ioclk_div + 1) * (sample_div + 1));
329 temp_delta = baud_tmp - baud_rate;
330 temp_delta = (temp_delta > 0) ? temp_delta : -temp_delta;
331 if (temp_delta < min_delta) {
332 regv = regv & (~SIRF_IOCLK_DIV_MASK);
333 regv = regv | ioclk_div;
334 regv = regv & (~SIRF_SAMPLE_DIV_MASK);
335 regv = regv | (sample_div << SIRF_SAMPLE_DIV_SHIFT);
336 min_delta = temp_delta;
337 *setted_baud = baud_tmp;
338 }
339 }
340 return regv;
341}
342
343static void sirfsoc_uart_set_termios(struct uart_port *port,
344 struct ktermios *termios,
345 struct ktermios *old)
346{
347 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
348 unsigned long ioclk_rate;
349 unsigned long config_reg = 0;
350 unsigned long baud_rate;
351 unsigned long setted_baud;
352 unsigned long flags;
353 unsigned long ic;
354 unsigned int clk_div_reg = 0;
355 unsigned long temp_reg_val;
356 unsigned long rx_time_out;
357 int threshold_div;
358 int temp;
359
360 ioclk_rate = 150000000;
361 switch (termios->c_cflag & CSIZE) {
362 default:
363 case CS8:
364 config_reg |= SIRFUART_DATA_BIT_LEN_8;
365 break;
366 case CS7:
367 config_reg |= SIRFUART_DATA_BIT_LEN_7;
368 break;
369 case CS6:
370 config_reg |= SIRFUART_DATA_BIT_LEN_6;
371 break;
372 case CS5:
373 config_reg |= SIRFUART_DATA_BIT_LEN_5;
374 break;
375 }
376 if (termios->c_cflag & CSTOPB)
377 config_reg |= SIRFUART_STOP_BIT_LEN_2;
378 baud_rate = uart_get_baud_rate(port, termios, old, 0, 4000000);
379 spin_lock_irqsave(&port->lock, flags);
380 port->read_status_mask = SIRFUART_RX_OFLOW_INT;
381 port->ignore_status_mask = 0;
382 /* read flags */
383 if (termios->c_iflag & INPCK)
384 port->read_status_mask |=
385 SIRFUART_FRM_ERR_INT | SIRFUART_PARITY_ERR_INT;
386 if (termios->c_iflag & (BRKINT | PARMRK))
387 port->read_status_mask |= SIRFUART_RXD_BREAK_INT;
388 /* ignore flags */
389 if (termios->c_iflag & IGNPAR)
390 port->ignore_status_mask |=
391 SIRFUART_FRM_ERR_INT | SIRFUART_PARITY_ERR_INT;
392 if ((termios->c_cflag & CREAD) == 0)
393 port->ignore_status_mask |= SIRFUART_DUMMY_READ;
394 /* enable parity if PARENB is set*/
395 if (termios->c_cflag & PARENB) {
396 if (termios->c_cflag & CMSPAR) {
397 if (termios->c_cflag & PARODD)
398 config_reg |= SIRFUART_STICK_BIT_MARK;
399 else
400 config_reg |= SIRFUART_STICK_BIT_SPACE;
401 } else if (termios->c_cflag & PARODD) {
402 config_reg |= SIRFUART_STICK_BIT_ODD;
403 } else {
404 config_reg |= SIRFUART_STICK_BIT_EVEN;
405 }
406 }
407 /* Hardware Flow Control Settings */
408 if (UART_ENABLE_MS(port, termios->c_cflag)) {
409 if (!sirfport->ms_enabled)
410 sirfsoc_uart_enable_ms(port);
411 } else {
412 if (sirfport->ms_enabled)
413 sirfsoc_uart_disable_ms(port);
414 }
415
416 /* common rate: fast calculation */
417 for (ic = 0; ic < SIRF_BAUD_RATE_SUPPORT_NR; ic++)
418 if (baud_rate == baudrate_to_regv[ic].baud_rate)
419 clk_div_reg = baudrate_to_regv[ic].reg_val;
420 setted_baud = baud_rate;
421 /* arbitary rate setting */
422 if (unlikely(clk_div_reg == 0))
423 clk_div_reg = sirfsoc_calc_sample_div(baud_rate, ioclk_rate,
424 &setted_baud);
425 wr_regl(port, SIRFUART_DIVISOR, clk_div_reg);
426
427 if (tty_termios_baud_rate(termios))
428 tty_termios_encode_baud_rate(termios, setted_baud, setted_baud);
429
430 /* set receive timeout */
431 rx_time_out = SIRFSOC_UART_RX_TIMEOUT(baud_rate, 20000);
432 rx_time_out = (rx_time_out > 0xFFFF) ? 0xFFFF : rx_time_out;
433 config_reg |= SIRFUART_RECV_TIMEOUT(rx_time_out);
434 temp_reg_val = rd_regl(port, SIRFUART_TX_FIFO_OP);
435 wr_regl(port, SIRFUART_RX_FIFO_OP, 0);
436 wr_regl(port, SIRFUART_TX_FIFO_OP,
437 temp_reg_val & ~SIRFUART_TX_FIFO_START);
438 wr_regl(port, SIRFUART_TX_DMA_IO_CTRL, SIRFUART_TX_MODE_IO);
439 wr_regl(port, SIRFUART_RX_DMA_IO_CTRL, SIRFUART_RX_MODE_IO);
440 wr_regl(port, SIRFUART_LINE_CTRL, config_reg);
441
442 /* Reset Rx/Tx FIFO Threshold level for proper baudrate */
443 if (baud_rate < 1000000)
444 threshold_div = 1;
445 else
446 threshold_div = 2;
447 temp = port->line == 1 ? 16 : 64;
448 wr_regl(port, SIRFUART_TX_FIFO_CTRL, temp / threshold_div);
449 wr_regl(port, SIRFUART_RX_FIFO_CTRL, temp / threshold_div);
450 temp_reg_val |= SIRFUART_TX_FIFO_START;
451 wr_regl(port, SIRFUART_TX_FIFO_OP, temp_reg_val);
452 uart_update_timeout(port, termios->c_cflag, baud_rate);
453 sirfsoc_uart_start_rx(port);
454 wr_regl(port, SIRFUART_TX_RX_EN, SIRFUART_TX_EN | SIRFUART_RX_EN);
455 spin_unlock_irqrestore(&port->lock, flags);
456}
457
458static void startup_uart_controller(struct uart_port *port)
459{
460 unsigned long temp_regv;
461 int temp;
462 temp_regv = rd_regl(port, SIRFUART_TX_DMA_IO_CTRL);
463 wr_regl(port, SIRFUART_TX_DMA_IO_CTRL, temp_regv | SIRFUART_TX_MODE_IO);
464 temp_regv = rd_regl(port, SIRFUART_RX_DMA_IO_CTRL);
465 wr_regl(port, SIRFUART_RX_DMA_IO_CTRL, temp_regv | SIRFUART_RX_MODE_IO);
466 wr_regl(port, SIRFUART_TX_DMA_IO_LEN, 0);
467 wr_regl(port, SIRFUART_RX_DMA_IO_LEN, 0);
468 wr_regl(port, SIRFUART_TX_RX_EN, SIRFUART_RX_EN | SIRFUART_TX_EN);
469 wr_regl(port, SIRFUART_TX_FIFO_OP, SIRFUART_TX_FIFO_RESET);
470 wr_regl(port, SIRFUART_TX_FIFO_OP, 0);
471 wr_regl(port, SIRFUART_RX_FIFO_OP, SIRFUART_RX_FIFO_RESET);
472 wr_regl(port, SIRFUART_RX_FIFO_OP, 0);
473 temp = port->line == 1 ? 16 : 64;
474 wr_regl(port, SIRFUART_TX_FIFO_CTRL, temp);
475 wr_regl(port, SIRFUART_RX_FIFO_CTRL, temp);
476}
477
478static int sirfsoc_uart_startup(struct uart_port *port)
479{
480 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
481 unsigned int index = port->line;
482 int ret;
483 set_irq_flags(port->irq, IRQF_VALID | IRQF_NOAUTOEN);
484 ret = request_irq(port->irq,
485 sirfsoc_uart_isr,
486 0,
487 SIRFUART_PORT_NAME,
488 sirfport);
489 if (ret != 0) {
490 dev_err(port->dev, "UART%d request IRQ line (%d) failed.\n",
491 index, port->irq);
492 goto irq_err;
493 }
494 startup_uart_controller(port);
495 enable_irq(port->irq);
496irq_err:
497 return ret;
498}
499
500static void sirfsoc_uart_shutdown(struct uart_port *port)
501{
502 struct sirfsoc_uart_port *sirfport = to_sirfport(port);
503 wr_regl(port, SIRFUART_INT_EN, 0);
504 free_irq(port->irq, sirfport);
505 if (sirfport->ms_enabled) {
506 sirfsoc_uart_disable_ms(port);
507 sirfport->ms_enabled = 0;
508 }
509}
510
511static const char *sirfsoc_uart_type(struct uart_port *port)
512{
513 return port->type == SIRFSOC_PORT_TYPE ? SIRFUART_PORT_NAME : NULL;
514}
515
516static int sirfsoc_uart_request_port(struct uart_port *port)
517{
518 void *ret;
519 ret = request_mem_region(port->mapbase,
520 SIRFUART_MAP_SIZE, SIRFUART_PORT_NAME);
521 return ret ? 0 : -EBUSY;
522}
523
524static void sirfsoc_uart_release_port(struct uart_port *port)
525{
526 release_mem_region(port->mapbase, SIRFUART_MAP_SIZE);
527}
528
529static void sirfsoc_uart_config_port(struct uart_port *port, int flags)
530{
531 if (flags & UART_CONFIG_TYPE) {
532 port->type = SIRFSOC_PORT_TYPE;
533 sirfsoc_uart_request_port(port);
534 }
535}
536
537static struct uart_ops sirfsoc_uart_ops = {
538 .tx_empty = sirfsoc_uart_tx_empty,
539 .get_mctrl = sirfsoc_uart_get_mctrl,
540 .set_mctrl = sirfsoc_uart_set_mctrl,
541 .stop_tx = sirfsoc_uart_stop_tx,
542 .start_tx = sirfsoc_uart_start_tx,
543 .stop_rx = sirfsoc_uart_stop_rx,
544 .enable_ms = sirfsoc_uart_enable_ms,
545 .break_ctl = sirfsoc_uart_break_ctl,
546 .startup = sirfsoc_uart_startup,
547 .shutdown = sirfsoc_uart_shutdown,
548 .set_termios = sirfsoc_uart_set_termios,
549 .type = sirfsoc_uart_type,
550 .release_port = sirfsoc_uart_release_port,
551 .request_port = sirfsoc_uart_request_port,
552 .config_port = sirfsoc_uart_config_port,
553};
554
555#ifdef CONFIG_SERIAL_SIRFSOC_CONSOLE
556static int __init sirfsoc_uart_console_setup(struct console *co, char *options)
557{
558 unsigned int baud = 115200;
559 unsigned int bits = 8;
560 unsigned int parity = 'n';
561 unsigned int flow = 'n';
562 struct uart_port *port = &sirfsoc_uart_ports[co->index].port;
563
564 if (co->index < 0 || co->index >= SIRFSOC_UART_NR)
565 return -EINVAL;
566
567 if (!port->mapbase)
568 return -ENODEV;
569
570 if (options)
571 uart_parse_options(options, &baud, &parity, &bits, &flow);
572 port->cons = co;
573 return uart_set_options(port, co, baud, parity, bits, flow);
574}
575
576static void sirfsoc_uart_console_putchar(struct uart_port *port, int ch)
577{
578 while (rd_regl(port,
579 SIRFUART_TX_FIFO_STATUS) & SIRFUART_FIFOFULL_MASK(port))
580 cpu_relax();
581 wr_regb(port, SIRFUART_TX_FIFO_DATA, ch);
582}
583
584static void sirfsoc_uart_console_write(struct console *co, const char *s,
585 unsigned int count)
586{
587 struct uart_port *port = &sirfsoc_uart_ports[co->index].port;
588 uart_console_write(port, s, count, sirfsoc_uart_console_putchar);
589}
590
591static struct console sirfsoc_uart_console = {
592 .name = SIRFSOC_UART_NAME,
593 .device = uart_console_device,
594 .flags = CON_PRINTBUFFER,
595 .index = -1,
596 .write = sirfsoc_uart_console_write,
597 .setup = sirfsoc_uart_console_setup,
598 .data = &sirfsoc_uart_drv,
599};
600
601static int __init sirfsoc_uart_console_init(void)
602{
603 register_console(&sirfsoc_uart_console);
604 return 0;
605}
606console_initcall(sirfsoc_uart_console_init);
607#endif
608
609static struct uart_driver sirfsoc_uart_drv = {
610 .owner = THIS_MODULE,
611 .driver_name = SIRFUART_PORT_NAME,
612 .nr = SIRFSOC_UART_NR,
613 .dev_name = SIRFSOC_UART_NAME,
614 .major = SIRFSOC_UART_MAJOR,
615 .minor = SIRFSOC_UART_MINOR,
616#ifdef CONFIG_SERIAL_SIRFSOC_CONSOLE
617 .cons = &sirfsoc_uart_console,
618#else
619 .cons = NULL,
620#endif
621};
622
623int sirfsoc_uart_probe(struct platform_device *pdev)
624{
625 struct sirfsoc_uart_port *sirfport;
626 struct uart_port *port;
627 struct resource *res;
628 int ret;
629
630 if (of_property_read_u32(pdev->dev.of_node, "cell-index", &pdev->id)) {
631 dev_err(&pdev->dev,
632 "Unable to find cell-index in uart node.\n");
633 ret = -EFAULT;
634 goto err;
635 }
636
637 sirfport = &sirfsoc_uart_ports[pdev->id];
638 port = &sirfport->port;
639 port->dev = &pdev->dev;
640 port->private_data = sirfport;
641
642 if (of_find_property(pdev->dev.of_node, "hw_flow_ctrl", NULL))
643 sirfport->hw_flow_ctrl = 1;
644
645 if (of_property_read_u32(pdev->dev.of_node,
646 "fifosize",
647 &port->fifosize)) {
648 dev_err(&pdev->dev,
649 "Unable to find fifosize in uart node.\n");
650 ret = -EFAULT;
651 goto err;
652 }
653
654 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
655 if (res == NULL) {
656 dev_err(&pdev->dev, "Insufficient resources.\n");
657 ret = -EFAULT;
658 goto err;
659 }
660 port->mapbase = res->start;
661 port->membase = devm_ioremap(&pdev->dev, res->start, resource_size(res));
662 if (!port->membase) {
663 dev_err(&pdev->dev, "Cannot remap resource.\n");
664 ret = -ENOMEM;
665 goto err;
666 }
667 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
668 if (res == NULL) {
669 dev_err(&pdev->dev, "Insufficient resources.\n");
670 ret = -EFAULT;
671 goto err;
672 }
673 port->irq = res->start;
674
675 if (sirfport->hw_flow_ctrl) {
676 sirfport->p = pinctrl_get_select_default(&pdev->dev);
677 ret = IS_ERR(sirfport->p);
678 if (ret)
679 goto err;
680 }
681
682 port->ops = &sirfsoc_uart_ops;
683 spin_lock_init(&port->lock);
684
685 platform_set_drvdata(pdev, sirfport);
686 ret = uart_add_one_port(&sirfsoc_uart_drv, port);
687 if (ret != 0) {
688 dev_err(&pdev->dev, "Cannot add UART port(%d).\n", pdev->id);
689 goto port_err;
690 }
691
692 return 0;
693
694port_err:
695 platform_set_drvdata(pdev, NULL);
696 if (sirfport->hw_flow_ctrl)
697 pinctrl_put(sirfport->p);
698err:
699 return ret;
700}
701
702static int sirfsoc_uart_remove(struct platform_device *pdev)
703{
704 struct sirfsoc_uart_port *sirfport = platform_get_drvdata(pdev);
705 struct uart_port *port = &sirfport->port;
706 platform_set_drvdata(pdev, NULL);
707 if (sirfport->hw_flow_ctrl)
708 pinctrl_put(sirfport->p);
709 uart_remove_one_port(&sirfsoc_uart_drv, port);
710 return 0;
711}
712
713static int
714sirfsoc_uart_suspend(struct platform_device *pdev, pm_message_t state)
715{
716 struct sirfsoc_uart_port *sirfport = platform_get_drvdata(pdev);
717 struct uart_port *port = &sirfport->port;
718 uart_suspend_port(&sirfsoc_uart_drv, port);
719 return 0;
720}
721
722static int sirfsoc_uart_resume(struct platform_device *pdev)
723{
724 struct sirfsoc_uart_port *sirfport = platform_get_drvdata(pdev);
725 struct uart_port *port = &sirfport->port;
726 uart_resume_port(&sirfsoc_uart_drv, port);
727 return 0;
728}
729
730static struct of_device_id sirfsoc_uart_ids[] = {
731 { .compatible = "sirf,prima2-uart", },
732 {}
733};
734MODULE_DEVICE_TABLE(of, sirfsoc_serial_of_match);
735
736static struct platform_driver sirfsoc_uart_driver = {
737 .probe = sirfsoc_uart_probe,
738 .remove = sirfsoc_uart_remove,
739 .suspend = sirfsoc_uart_suspend,
740 .resume = sirfsoc_uart_resume,
741 .driver = {
742 .name = SIRFUART_PORT_NAME,
743 .owner = THIS_MODULE,
744 .of_match_table = sirfsoc_uart_ids,
745 },
746};
747
748static int __init sirfsoc_uart_init(void)
749{
750 int ret = 0;
751
752 ret = uart_register_driver(&sirfsoc_uart_drv);
753 if (ret)
754 goto out;
755
756 ret = platform_driver_register(&sirfsoc_uart_driver);
757 if (ret)
758 uart_unregister_driver(&sirfsoc_uart_drv);
759out:
760 return ret;
761}
762module_init(sirfsoc_uart_init);
763
764static void __exit sirfsoc_uart_exit(void)
765{
766 platform_driver_unregister(&sirfsoc_uart_driver);
767 uart_unregister_driver(&sirfsoc_uart_drv);
768}
769module_exit(sirfsoc_uart_exit);
770
771MODULE_LICENSE("GPL v2");
772MODULE_AUTHOR("Bin Shi <Bin.Shi@csr.com>, Rong Wang<Rong.Wang@csr.com>");
773MODULE_DESCRIPTION("CSR SiRFprimaII Uart Driver");
diff --git a/drivers/tty/serial/sirfsoc_uart.h b/drivers/tty/serial/sirfsoc_uart.h
deleted file mode 100644
index 6e207fdc2fe..00000000000
--- a/drivers/tty/serial/sirfsoc_uart.h
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 * Drivers for CSR SiRFprimaII onboard UARTs.
3 *
4 * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8#include <linux/bitops.h>
9
10/* UART Register Offset Define */
11#define SIRFUART_LINE_CTRL 0x0040
12#define SIRFUART_TX_RX_EN 0x004c
13#define SIRFUART_DIVISOR 0x0050
14#define SIRFUART_INT_EN 0x0054
15#define SIRFUART_INT_STATUS 0x0058
16#define SIRFUART_TX_DMA_IO_CTRL 0x0100
17#define SIRFUART_TX_DMA_IO_LEN 0x0104
18#define SIRFUART_TX_FIFO_CTRL 0x0108
19#define SIRFUART_TX_FIFO_LEVEL_CHK 0x010C
20#define SIRFUART_TX_FIFO_OP 0x0110
21#define SIRFUART_TX_FIFO_STATUS 0x0114
22#define SIRFUART_TX_FIFO_DATA 0x0118
23#define SIRFUART_RX_DMA_IO_CTRL 0x0120
24#define SIRFUART_RX_DMA_IO_LEN 0x0124
25#define SIRFUART_RX_FIFO_CTRL 0x0128
26#define SIRFUART_RX_FIFO_LEVEL_CHK 0x012C
27#define SIRFUART_RX_FIFO_OP 0x0130
28#define SIRFUART_RX_FIFO_STATUS 0x0134
29#define SIRFUART_RX_FIFO_DATA 0x0138
30#define SIRFUART_AFC_CTRL 0x0140
31#define SIRFUART_SWH_DMA_IO 0x0148
32
33/* UART Line Control Register */
34#define SIRFUART_DATA_BIT_LEN_MASK 0x3
35#define SIRFUART_DATA_BIT_LEN_5 BIT(0)
36#define SIRFUART_DATA_BIT_LEN_6 1
37#define SIRFUART_DATA_BIT_LEN_7 2
38#define SIRFUART_DATA_BIT_LEN_8 3
39#define SIRFUART_STOP_BIT_LEN_1 0
40#define SIRFUART_STOP_BIT_LEN_2 BIT(2)
41#define SIRFUART_PARITY_EN BIT(3)
42#define SIRFUART_EVEN_BIT BIT(4)
43#define SIRFUART_STICK_BIT_MASK (7 << 3)
44#define SIRFUART_STICK_BIT_NONE (0 << 3)
45#define SIRFUART_STICK_BIT_EVEN BIT(3)
46#define SIRFUART_STICK_BIT_ODD (3 << 3)
47#define SIRFUART_STICK_BIT_MARK (5 << 3)
48#define SIRFUART_STICK_BIT_SPACE (7 << 3)
49#define SIRFUART_SET_BREAK BIT(6)
50#define SIRFUART_LOOP_BACK BIT(7)
51#define SIRFUART_PARITY_MASK (7 << 3)
52#define SIRFUART_DUMMY_READ BIT(16)
53
54#define SIRFSOC_UART_RX_TIMEOUT(br, to) (((br) * (((to) + 999) / 1000)) / 1000)
55#define SIRFUART_RECV_TIMEOUT_MASK (0xFFFF << 16)
56#define SIRFUART_RECV_TIMEOUT(x) (((x) & 0xFFFF) << 16)
57
58/* UART Auto Flow Control */
59#define SIRFUART_AFC_RX_THD_MASK 0x000000FF
60#define SIRFUART_AFC_RX_EN BIT(8)
61#define SIRFUART_AFC_TX_EN BIT(9)
62#define SIRFUART_CTS_CTRL BIT(10)
63#define SIRFUART_RTS_CTRL BIT(11)
64#define SIRFUART_CTS_IN_STATUS BIT(12)
65#define SIRFUART_RTS_OUT_STATUS BIT(13)
66
67/* UART Interrupt Enable Register */
68#define SIRFUART_RX_DONE_INT BIT(0)
69#define SIRFUART_TX_DONE_INT BIT(1)
70#define SIRFUART_RX_OFLOW_INT BIT(2)
71#define SIRFUART_TX_ALLOUT_INT BIT(3)
72#define SIRFUART_RX_IO_DMA_INT BIT(4)
73#define SIRFUART_TX_IO_DMA_INT BIT(5)
74#define SIRFUART_RXFIFO_FULL_INT BIT(6)
75#define SIRFUART_TXFIFO_EMPTY_INT BIT(7)
76#define SIRFUART_RXFIFO_THD_INT BIT(8)
77#define SIRFUART_TXFIFO_THD_INT BIT(9)
78#define SIRFUART_FRM_ERR_INT BIT(10)
79#define SIRFUART_RXD_BREAK_INT BIT(11)
80#define SIRFUART_RX_TIMEOUT_INT BIT(12)
81#define SIRFUART_PARITY_ERR_INT BIT(13)
82#define SIRFUART_CTS_INT_EN BIT(14)
83#define SIRFUART_RTS_INT_EN BIT(15)
84
85/* UART Interrupt Status Register */
86#define SIRFUART_RX_DONE BIT(0)
87#define SIRFUART_TX_DONE BIT(1)
88#define SIRFUART_RX_OFLOW BIT(2)
89#define SIRFUART_TX_ALL_EMPTY BIT(3)
90#define SIRFUART_DMA_IO_RX_DONE BIT(4)
91#define SIRFUART_DMA_IO_TX_DONE BIT(5)
92#define SIRFUART_RXFIFO_FULL BIT(6)
93#define SIRFUART_TXFIFO_EMPTY BIT(7)
94#define SIRFUART_RXFIFO_THD_REACH BIT(8)
95#define SIRFUART_TXFIFO_THD_REACH BIT(9)
96#define SIRFUART_FRM_ERR BIT(10)
97#define SIRFUART_RXD_BREAK BIT(11)
98#define SIRFUART_RX_TIMEOUT BIT(12)
99#define SIRFUART_PARITY_ERR BIT(13)
100#define SIRFUART_CTS_CHANGE BIT(14)
101#define SIRFUART_RTS_CHANGE BIT(15)
102#define SIRFUART_PLUG_IN BIT(16)
103
104#define SIRFUART_ERR_INT_STAT \
105 (SIRFUART_RX_OFLOW | \
106 SIRFUART_FRM_ERR | \
107 SIRFUART_RXD_BREAK | \
108 SIRFUART_PARITY_ERR)
109#define SIRFUART_ERR_INT_EN \
110 (SIRFUART_RX_OFLOW_INT | \
111 SIRFUART_FRM_ERR_INT | \
112 SIRFUART_RXD_BREAK_INT | \
113 SIRFUART_PARITY_ERR_INT)
114#define SIRFUART_TX_INT_EN SIRFUART_TXFIFO_EMPTY_INT
115#define SIRFUART_RX_IO_INT_EN \
116 (SIRFUART_RX_TIMEOUT_INT | \
117 SIRFUART_RXFIFO_THD_INT | \
118 SIRFUART_RXFIFO_FULL_INT | \
119 SIRFUART_ERR_INT_EN)
120
121/* UART FIFO Register */
122#define SIRFUART_TX_FIFO_STOP 0x0
123#define SIRFUART_TX_FIFO_RESET 0x1
124#define SIRFUART_TX_FIFO_START 0x2
125#define SIRFUART_RX_FIFO_STOP 0x0
126#define SIRFUART_RX_FIFO_RESET 0x1
127#define SIRFUART_RX_FIFO_START 0x2
128#define SIRFUART_TX_MODE_DMA 0
129#define SIRFUART_TX_MODE_IO 1
130#define SIRFUART_RX_MODE_DMA 0
131#define SIRFUART_RX_MODE_IO 1
132
133#define SIRFUART_RX_EN 0x1
134#define SIRFUART_TX_EN 0x2
135
136/* Generic Definitions */
137#define SIRFSOC_UART_NAME "ttySiRF"
138#define SIRFSOC_UART_MAJOR 0
139#define SIRFSOC_UART_MINOR 0
140#define SIRFUART_PORT_NAME "sirfsoc-uart"
141#define SIRFUART_MAP_SIZE 0x200
142#define SIRFSOC_UART_NR 3
143#define SIRFSOC_PORT_TYPE 0xa5
144
145/* Baud Rate Calculation */
146#define SIRF_MIN_SAMPLE_DIV 0xf
147#define SIRF_MAX_SAMPLE_DIV 0x3f
148#define SIRF_IOCLK_DIV_MAX 0xffff
149#define SIRF_SAMPLE_DIV_SHIFT 16
150#define SIRF_IOCLK_DIV_MASK 0xffff
151#define SIRF_SAMPLE_DIV_MASK 0x3f0000
152#define SIRF_BAUD_RATE_SUPPORT_NR 18
153
154/* For Fast Baud Rate Calculation */
155struct sirfsoc_baudrate_to_regv {
156 unsigned int baud_rate;
157 unsigned int reg_val;
158};
159
160struct sirfsoc_uart_port {
161 unsigned char hw_flow_ctrl;
162 unsigned char ms_enabled;
163
164 struct uart_port port;
165 struct pinctrl *p;
166};
167
168/* Hardware Flow Control */
169#define SIRFUART_AFC_CTRL_RX_THD 0x70
170
171/* Register Access Control */
172#define portaddr(port, reg) ((port)->membase + (reg))
173#define rd_regb(port, reg) (__raw_readb(portaddr(port, reg)))
174#define rd_regl(port, reg) (__raw_readl(portaddr(port, reg)))
175#define wr_regb(port, reg, val) __raw_writeb(val, portaddr(port, reg))
176#define wr_regl(port, reg, val) __raw_writel(val, portaddr(port, reg))
177
178/* UART Port Mask */
179#define SIRFUART_FIFOLEVEL_MASK(port) ((port->line == 1) ? (0x1f) : (0x7f))
180#define SIRFUART_FIFOFULL_MASK(port) ((port->line == 1) ? (0x20) : (0x80))
181#define SIRFUART_FIFOEMPTY_MASK(port) ((port->line == 1) ? (0x40) : (0x100))
182
183/* I/O Mode */
184#define SIRFSOC_UART_IO_RX_MAX_CNT 256
185#define SIRFSOC_UART_IO_TX_REASONABLE_CNT 6
diff --git a/drivers/tty/serial/sn_console.c b/drivers/tty/serial/sn_console.c
index 1c6de9f5869..377ae74e715 100644
--- a/drivers/tty/serial/sn_console.c
+++ b/drivers/tty/serial/sn_console.c
@@ -39,7 +39,6 @@
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>
43#include <linux/serial.h> 42#include <linux/serial.h>
44#include <linux/console.h> 43#include <linux/console.h>
45#include <linux/module.h> 44#include <linux/module.h>
@@ -461,12 +460,12 @@ sn_receive_chars(struct sn_cons_port *port, unsigned long flags)
461 struct tty_struct *tty; 460 struct tty_struct *tty;
462 461
463 if (!port) { 462 if (!port) {
464 printk(KERN_ERR "sn_receive_chars - port NULL so can't receive\n"); 463 printk(KERN_ERR "sn_receive_chars - port NULL so can't receieve\n");
465 return; 464 return;
466 } 465 }
467 466
468 if (!port->sc_ops) { 467 if (!port->sc_ops) {
469 printk(KERN_ERR "sn_receive_chars - port->sc_ops NULL so can't receive\n"); 468 printk(KERN_ERR "sn_receive_chars - port->sc_ops NULL so can't receieve\n");
470 return; 469 return;
471 } 470 }
472 471
@@ -738,12 +737,11 @@ static void __init sn_sal_switch_to_interrupts(struct sn_cons_port *port)
738 DPRINTF("sn_console: switching to interrupt driven console\n"); 737 DPRINTF("sn_console: switching to interrupt driven console\n");
739 738
740 if (request_irq(SGI_UART_VECTOR, sn_sal_interrupt, 739 if (request_irq(SGI_UART_VECTOR, sn_sal_interrupt,
741 IRQF_SHARED, 740 IRQF_DISABLED | IRQF_SHARED,
742 "SAL console driver", port) >= 0) { 741 "SAL console driver", port) >= 0) {
743 spin_lock_irqsave(&port->sc_port.lock, flags); 742 spin_lock_irqsave(&port->sc_port.lock, flags);
744 port->sc_port.irq = SGI_UART_VECTOR; 743 port->sc_port.irq = SGI_UART_VECTOR;
745 port->sc_ops = &intr_ops; 744 port->sc_ops = &intr_ops;
746 irq_set_handler(port->sc_port.irq, handle_level_irq);
747 745
748 /* turn on receive interrupts */ 746 /* turn on receive interrupts */
749 ia64_sn_console_intr_enable(SAL_CONSOLE_INTR_RECV); 747 ia64_sn_console_intr_enable(SAL_CONSOLE_INTR_RECV);
diff --git a/drivers/tty/serial/suncore.c b/drivers/tty/serial/suncore.c
index 6e4ac8db2d7..6381a0282ee 100644
--- a/drivers/tty/serial/suncore.c
+++ b/drivers/tty/serial/suncore.c
@@ -17,11 +17,11 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/serial_core.h> 19#include <linux/serial_core.h>
20#include <linux/sunserialcore.h>
21#include <linux/init.h> 20#include <linux/init.h>
22 21
23#include <asm/prom.h> 22#include <asm/prom.h>
24 23
24#include "suncore.h"
25 25
26static int sunserial_current_minor = 64; 26static int sunserial_current_minor = 64;
27 27
diff --git a/drivers/tty/serial/sunhv.c b/drivers/tty/serial/sunhv.c
index b9bf9c53f7f..c0b7246d733 100644
--- a/drivers/tty/serial/sunhv.c
+++ b/drivers/tty/serial/sunhv.c
@@ -23,14 +23,14 @@
23#include <asm/spitfire.h> 23#include <asm/spitfire.h>
24#include <asm/prom.h> 24#include <asm/prom.h>
25#include <asm/irq.h> 25#include <asm/irq.h>
26#include <asm/setup.h>
27 26
28#if defined(CONFIG_MAGIC_SYSRQ) 27#if defined(CONFIG_MAGIC_SYSRQ)
29#define SUPPORT_SYSRQ 28#define SUPPORT_SYSRQ
30#endif 29#endif
31 30
32#include <linux/serial_core.h> 31#include <linux/serial_core.h>
33#include <linux/sunserialcore.h> 32
33#include "suncore.h"
34 34
35#define CON_BREAK ((long)-1) 35#define CON_BREAK ((long)-1)
36#define CON_HUP ((long)-2) 36#define CON_HUP ((long)-2)
@@ -519,7 +519,7 @@ static struct console sunhv_console = {
519 .data = &sunhv_reg, 519 .data = &sunhv_reg,
520}; 520};
521 521
522static int hv_probe(struct platform_device *op) 522static int __devinit hv_probe(struct platform_device *op)
523{ 523{
524 struct uart_port *port; 524 struct uart_port *port;
525 unsigned long minor; 525 unsigned long minor;
@@ -598,7 +598,7 @@ out_free_port:
598 return err; 598 return err;
599} 599}
600 600
601static int hv_remove(struct platform_device *dev) 601static int __devexit hv_remove(struct platform_device *dev)
602{ 602{
603 struct uart_port *port = dev_get_drvdata(&dev->dev); 603 struct uart_port *port = dev_get_drvdata(&dev->dev);
604 604
@@ -636,7 +636,7 @@ static struct platform_driver hv_driver = {
636 .of_match_table = hv_match, 636 .of_match_table = hv_match,
637 }, 637 },
638 .probe = hv_probe, 638 .probe = hv_probe,
639 .remove = hv_remove, 639 .remove = __devexit_p(hv_remove),
640}; 640};
641 641
642static int __init sunhv_init(void) 642static int __init sunhv_init(void)
diff --git a/drivers/tty/serial/sunsab.c b/drivers/tty/serial/sunsab.c
index bd8b3b63410..b5fa2a57b9d 100644
--- a/drivers/tty/serial/sunsab.c
+++ b/drivers/tty/serial/sunsab.c
@@ -37,15 +37,14 @@
37#include <asm/io.h> 37#include <asm/io.h>
38#include <asm/irq.h> 38#include <asm/irq.h>
39#include <asm/prom.h> 39#include <asm/prom.h>
40#include <asm/setup.h>
41 40
42#if defined(CONFIG_SERIAL_SUNSAB_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 41#if defined(CONFIG_SERIAL_SUNSAB_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
43#define SUPPORT_SYSRQ 42#define SUPPORT_SYSRQ
44#endif 43#endif
45 44
46#include <linux/serial_core.h> 45#include <linux/serial_core.h>
47#include <linux/sunserialcore.h>
48 46
47#include "suncore.h"
49#include "sunsab.h" 48#include "sunsab.h"
50 49
51struct uart_sunsab_port { 50struct uart_sunsab_port {
@@ -954,7 +953,7 @@ static inline struct console *SUNSAB_CONSOLE(void)
954#define sunsab_console_init() do { } while (0) 953#define sunsab_console_init() do { } while (0)
955#endif 954#endif
956 955
957static int sunsab_init_one(struct uart_sunsab_port *up, 956static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
958 struct platform_device *op, 957 struct platform_device *op,
959 unsigned long offset, 958 unsigned long offset,
960 int line) 959 int line)
@@ -1007,7 +1006,7 @@ static int sunsab_init_one(struct uart_sunsab_port *up,
1007 return 0; 1006 return 0;
1008} 1007}
1009 1008
1010static int sab_probe(struct platform_device *op) 1009static int __devinit sab_probe(struct platform_device *op)
1011{ 1010{
1012 static int inst; 1011 static int inst;
1013 struct uart_sunsab_port *up; 1012 struct uart_sunsab_port *up;
@@ -1063,7 +1062,7 @@ out:
1063 return err; 1062 return err;
1064} 1063}
1065 1064
1066static int sab_remove(struct platform_device *op) 1065static int __devexit sab_remove(struct platform_device *op)
1067{ 1066{
1068 struct uart_sunsab_port *up = dev_get_drvdata(&op->dev); 1067 struct uart_sunsab_port *up = dev_get_drvdata(&op->dev);
1069 1068
@@ -1100,7 +1099,7 @@ static struct platform_driver sab_driver = {
1100 .of_match_table = sab_match, 1099 .of_match_table = sab_match,
1101 }, 1100 },
1102 .probe = sab_probe, 1101 .probe = sab_probe,
1103 .remove = sab_remove, 1102 .remove = __devexit_p(sab_remove),
1104}; 1103};
1105 1104
1106static int __init sunsab_init(void) 1105static int __init sunsab_init(void)
diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c
index 220da3f9724..ad0f8f5f6ea 100644
--- a/drivers/tty/serial/sunsu.c
+++ b/drivers/tty/serial/sunsu.c
@@ -41,14 +41,14 @@
41#include <asm/io.h> 41#include <asm/io.h>
42#include <asm/irq.h> 42#include <asm/irq.h>
43#include <asm/prom.h> 43#include <asm/prom.h>
44#include <asm/setup.h>
45 44
46#if defined(CONFIG_SERIAL_SUNSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 45#if defined(CONFIG_SERIAL_SUNSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
47#define SUPPORT_SYSRQ 46#define SUPPORT_SYSRQ
48#endif 47#endif
49 48
50#include <linux/serial_core.h> 49#include <linux/serial_core.h>
51#include <linux/sunserialcore.h> 50
51#include "suncore.h"
52 52
53/* We are on a NS PC87303 clocked with 24.0 MHz, which results 53/* We are on a NS PC87303 clocked with 24.0 MHz, which results
54 * in a UART clock of 1.8462 MHz. 54 * in a UART clock of 1.8462 MHz.
@@ -58,16 +58,10 @@
58enum su_type { SU_PORT_NONE, SU_PORT_MS, SU_PORT_KBD, SU_PORT_PORT }; 58enum su_type { SU_PORT_NONE, SU_PORT_MS, SU_PORT_KBD, SU_PORT_PORT };
59static char *su_typev[] = { "su(???)", "su(mouse)", "su(kbd)", "su(serial)" }; 59static char *su_typev[] = { "su(???)", "su(mouse)", "su(kbd)", "su(serial)" };
60 60
61struct serial_uart_config {
62 char *name;
63 int dfl_xmit_fifo_size;
64 int flags;
65};
66
67/* 61/*
68 * Here we define the default xmit fifo size used for each type of UART. 62 * Here we define the default xmit fifo size used for each type of UART.
69 */ 63 */
70static const struct serial_uart_config uart_config[] = { 64static const struct serial_uart_config uart_config[PORT_MAX_8250+1] = {
71 { "unknown", 1, 0 }, 65 { "unknown", 1, 0 },
72 { "8250", 1, 0 }, 66 { "8250", 1, 0 },
73 { "16450", 1, 0 }, 67 { "16450", 1, 0 },
@@ -1185,7 +1179,7 @@ static struct uart_driver sunsu_reg = {
1185 .major = TTY_MAJOR, 1179 .major = TTY_MAJOR,
1186}; 1180};
1187 1181
1188static int sunsu_kbd_ms_init(struct uart_sunsu_port *up) 1182static int __devinit sunsu_kbd_ms_init(struct uart_sunsu_port *up)
1189{ 1183{
1190 int quot, baud; 1184 int quot, baud;
1191#ifdef CONFIG_SERIO 1185#ifdef CONFIG_SERIO
@@ -1391,7 +1385,7 @@ static inline struct console *SUNSU_CONSOLE(void)
1391#define sunsu_serial_console_init() do { } while (0) 1385#define sunsu_serial_console_init() do { } while (0)
1392#endif 1386#endif
1393 1387
1394static enum su_type su_get_type(struct device_node *dp) 1388static enum su_type __devinit su_get_type(struct device_node *dp)
1395{ 1389{
1396 struct device_node *ap = of_find_node_by_path("/aliases"); 1390 struct device_node *ap = of_find_node_by_path("/aliases");
1397 1391
@@ -1412,7 +1406,7 @@ static enum su_type su_get_type(struct device_node *dp)
1412 return SU_PORT_PORT; 1406 return SU_PORT_PORT;
1413} 1407}
1414 1408
1415static int su_probe(struct platform_device *op) 1409static int __devinit su_probe(struct platform_device *op)
1416{ 1410{
1417 static int inst; 1411 static int inst;
1418 struct device_node *dp = op->dev.of_node; 1412 struct device_node *dp = op->dev.of_node;
@@ -1503,7 +1497,7 @@ out_unmap:
1503 return err; 1497 return err;
1504} 1498}
1505 1499
1506static int su_remove(struct platform_device *op) 1500static int __devexit su_remove(struct platform_device *op)
1507{ 1501{
1508 struct uart_sunsu_port *up = dev_get_drvdata(&op->dev); 1502 struct uart_sunsu_port *up = dev_get_drvdata(&op->dev);
1509 bool kbdms = false; 1503 bool kbdms = false;
@@ -1556,7 +1550,7 @@ static struct platform_driver su_driver = {
1556 .of_match_table = su_match, 1550 .of_match_table = su_match,
1557 }, 1551 },
1558 .probe = su_probe, 1552 .probe = su_probe,
1559 .remove = su_remove, 1553 .remove = __devexit_p(su_remove),
1560}; 1554};
1561 1555
1562static int __init sunsu_init(void) 1556static int __init sunsu_init(void)
diff --git a/drivers/tty/serial/sunzilog.c b/drivers/tty/serial/sunzilog.c
index aef4fab957c..8e916e76b7b 100644
--- a/drivers/tty/serial/sunzilog.c
+++ b/drivers/tty/serial/sunzilog.c
@@ -37,15 +37,14 @@
37#include <asm/io.h> 37#include <asm/io.h>
38#include <asm/irq.h> 38#include <asm/irq.h>
39#include <asm/prom.h> 39#include <asm/prom.h>
40#include <asm/setup.h>
41 40
42#if defined(CONFIG_SERIAL_SUNZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 41#if defined(CONFIG_SERIAL_SUNZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
43#define SUPPORT_SYSRQ 42#define SUPPORT_SYSRQ
44#endif 43#endif
45 44
46#include <linux/serial_core.h> 45#include <linux/serial_core.h>
47#include <linux/sunserialcore.h>
48 46
47#include "suncore.h"
49#include "sunzilog.h" 48#include "sunzilog.h"
50 49
51/* On 32-bit sparcs we need to delay after register accesses 50/* On 32-bit sparcs we need to delay after register accesses
@@ -1282,7 +1281,7 @@ static inline struct console *SUNZILOG_CONSOLE(void)
1282#define SUNZILOG_CONSOLE() (NULL) 1281#define SUNZILOG_CONSOLE() (NULL)
1283#endif 1282#endif
1284 1283
1285static void sunzilog_init_kbdms(struct uart_sunzilog_port *up) 1284static void __devinit sunzilog_init_kbdms(struct uart_sunzilog_port *up)
1286{ 1285{
1287 int baud, brg; 1286 int baud, brg;
1288 1287
@@ -1302,7 +1301,7 @@ static void sunzilog_init_kbdms(struct uart_sunzilog_port *up)
1302} 1301}
1303 1302
1304#ifdef CONFIG_SERIO 1303#ifdef CONFIG_SERIO
1305static void sunzilog_register_serio(struct uart_sunzilog_port *up) 1304static void __devinit sunzilog_register_serio(struct uart_sunzilog_port *up)
1306{ 1305{
1307 struct serio *serio = &up->serio; 1306 struct serio *serio = &up->serio;
1308 1307
@@ -1331,7 +1330,7 @@ static void sunzilog_register_serio(struct uart_sunzilog_port *up)
1331} 1330}
1332#endif 1331#endif
1333 1332
1334static void sunzilog_init_hw(struct uart_sunzilog_port *up) 1333static void __devinit sunzilog_init_hw(struct uart_sunzilog_port *up)
1335{ 1334{
1336 struct zilog_channel __iomem *channel; 1335 struct zilog_channel __iomem *channel;
1337 unsigned long flags; 1336 unsigned long flags;
@@ -1398,9 +1397,9 @@ static void sunzilog_init_hw(struct uart_sunzilog_port *up)
1398#endif 1397#endif
1399} 1398}
1400 1399
1401static int zilog_irq; 1400static int zilog_irq = -1;
1402 1401
1403static int zs_probe(struct platform_device *op) 1402static int __devinit zs_probe(struct platform_device *op)
1404{ 1403{
1405 static int kbm_inst, uart_inst; 1404 static int kbm_inst, uart_inst;
1406 int inst; 1405 int inst;
@@ -1426,7 +1425,7 @@ static int zs_probe(struct platform_device *op)
1426 1425
1427 rp = sunzilog_chip_regs[inst]; 1426 rp = sunzilog_chip_regs[inst];
1428 1427
1429 if (!zilog_irq) 1428 if (zilog_irq == -1)
1430 zilog_irq = op->archdata.irqs[0]; 1429 zilog_irq = op->archdata.irqs[0];
1431 1430
1432 up = &sunzilog_port_table[inst * 2]; 1431 up = &sunzilog_port_table[inst * 2];
@@ -1507,7 +1506,7 @@ static int zs_probe(struct platform_device *op)
1507 return 0; 1506 return 0;
1508} 1507}
1509 1508
1510static void zs_remove_one(struct uart_sunzilog_port *up) 1509static void __devexit zs_remove_one(struct uart_sunzilog_port *up)
1511{ 1510{
1512 if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up)) { 1511 if (ZS_IS_KEYB(up) || ZS_IS_MOUSE(up)) {
1513#ifdef CONFIG_SERIO 1512#ifdef CONFIG_SERIO
@@ -1517,7 +1516,7 @@ static void zs_remove_one(struct uart_sunzilog_port *up)
1517 uart_remove_one_port(&sunzilog_reg, &up->port); 1516 uart_remove_one_port(&sunzilog_reg, &up->port);
1518} 1517}
1519 1518
1520static int zs_remove(struct platform_device *op) 1519static int __devexit zs_remove(struct platform_device *op)
1521{ 1520{
1522 struct uart_sunzilog_port *up = dev_get_drvdata(&op->dev); 1521 struct uart_sunzilog_port *up = dev_get_drvdata(&op->dev);
1523 struct zilog_layout __iomem *regs; 1522 struct zilog_layout __iomem *regs;
@@ -1548,7 +1547,7 @@ static struct platform_driver zs_driver = {
1548 .of_match_table = zs_match, 1547 .of_match_table = zs_match,
1549 }, 1548 },
1550 .probe = zs_probe, 1549 .probe = zs_probe,
1551 .remove = zs_remove, 1550 .remove = __devexit_p(zs_remove),
1552}; 1551};
1553 1552
1554static int __init sunzilog_init(void) 1553static int __init sunzilog_init(void)
@@ -1581,7 +1580,7 @@ static int __init sunzilog_init(void)
1581 if (err) 1580 if (err)
1582 goto out_unregister_uart; 1581 goto out_unregister_uart;
1583 1582
1584 if (zilog_irq) { 1583 if (zilog_irq != -1) {
1585 struct uart_sunzilog_port *up = sunzilog_irq_chain; 1584 struct uart_sunzilog_port *up = sunzilog_irq_chain;
1586 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED, 1585 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED,
1587 "zs", sunzilog_irq_chain); 1586 "zs", sunzilog_irq_chain);
@@ -1622,7 +1621,7 @@ static void __exit sunzilog_exit(void)
1622{ 1621{
1623 platform_driver_unregister(&zs_driver); 1622 platform_driver_unregister(&zs_driver);
1624 1623
1625 if (zilog_irq) { 1624 if (zilog_irq != -1) {
1626 struct uart_sunzilog_port *up = sunzilog_irq_chain; 1625 struct uart_sunzilog_port *up = sunzilog_irq_chain;
1627 1626
1628 /* Disable Interrupts */ 1627 /* Disable Interrupts */
@@ -1638,7 +1637,7 @@ static void __exit sunzilog_exit(void)
1638 } 1637 }
1639 1638
1640 free_irq(zilog_irq, sunzilog_irq_chain); 1639 free_irq(zilog_irq, sunzilog_irq_chain);
1641 zilog_irq = 0; 1640 zilog_irq = -1;
1642 } 1641 }
1643 1642
1644 if (sunzilog_reg.nr) { 1643 if (sunzilog_reg.nr) {
diff --git a/drivers/tty/serial/timbuart.c b/drivers/tty/serial/timbuart.c
index 5be0d68fece..1f36b7eb735 100644
--- a/drivers/tty/serial/timbuart.c
+++ b/drivers/tty/serial/timbuart.c
@@ -23,13 +23,10 @@
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>
28#include <linux/kernel.h> 26#include <linux/kernel.h>
29#include <linux/platform_device.h> 27#include <linux/platform_device.h>
30#include <linux/ioport.h> 28#include <linux/ioport.h>
31#include <linux/slab.h> 29#include <linux/slab.h>
32#include <linux/module.h>
33 30
34#include "timbuart.h" 31#include "timbuart.h"
35 32
@@ -426,7 +423,7 @@ static struct uart_driver timbuart_driver = {
426 .nr = 1 423 .nr = 1
427}; 424};
428 425
429static int timbuart_probe(struct platform_device *dev) 426static int __devinit timbuart_probe(struct platform_device *dev)
430{ 427{
431 int err, irq; 428 int err, irq;
432 struct timbuart_port *uart; 429 struct timbuart_port *uart;
@@ -492,7 +489,7 @@ err_mem:
492 return err; 489 return err;
493} 490}
494 491
495static int timbuart_remove(struct platform_device *dev) 492static int __devexit timbuart_remove(struct platform_device *dev)
496{ 493{
497 struct timbuart_port *uart = platform_get_drvdata(dev); 494 struct timbuart_port *uart = platform_get_drvdata(dev);
498 495
@@ -510,10 +507,23 @@ static struct platform_driver timbuart_platform_driver = {
510 .owner = THIS_MODULE, 507 .owner = THIS_MODULE,
511 }, 508 },
512 .probe = timbuart_probe, 509 .probe = timbuart_probe,
513 .remove = timbuart_remove, 510 .remove = __devexit_p(timbuart_remove),
514}; 511};
515 512
516module_platform_driver(timbuart_platform_driver); 513/*--------------------------------------------------------------------------*/
514
515static int __init timbuart_init(void)
516{
517 return platform_driver_register(&timbuart_platform_driver);
518}
519
520static void __exit timbuart_exit(void)
521{
522 platform_driver_unregister(&timbuart_platform_driver);
523}
524
525module_init(timbuart_init);
526module_exit(timbuart_exit);
517 527
518MODULE_DESCRIPTION("Timberdale UART driver"); 528MODULE_DESCRIPTION("Timberdale UART driver");
519MODULE_LICENSE("GPL v2"); 529MODULE_LICENSE("GPL v2");
diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index 89eee43c4e2..8af1ed83a4c 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -15,7 +15,6 @@
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>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/interrupt.h> 19#include <linux/interrupt.h>
21#include <linux/init.h> 20#include <linux/init.h>
@@ -216,7 +215,8 @@ static int ulite_startup(struct uart_port *port)
216{ 215{
217 int ret; 216 int ret;
218 217
219 ret = request_irq(port->irq, ulite_isr, IRQF_SHARED, "uartlite", port); 218 ret = request_irq(port->irq, ulite_isr,
219 IRQF_SHARED | IRQF_SAMPLE_RANDOM, "uartlite", port);
220 if (ret) 220 if (ret)
221 return ret; 221 return ret;
222 222
@@ -408,7 +408,7 @@ static void ulite_console_write(struct console *co, const char *s,
408 spin_unlock_irqrestore(&port->lock, flags); 408 spin_unlock_irqrestore(&port->lock, flags);
409} 409}
410 410
411static int ulite_console_setup(struct console *co, char *options) 411static int __devinit ulite_console_setup(struct console *co, char *options)
412{ 412{
413 struct uart_port *port; 413 struct uart_port *port;
414 int baud = 9600; 414 int baud = 9600;
@@ -486,7 +486,7 @@ static struct uart_driver ulite_uart_driver = {
486 * 486 *
487 * Returns: 0 on success, <0 otherwise 487 * Returns: 0 on success, <0 otherwise
488 */ 488 */
489static int ulite_assign(struct device *dev, int id, u32 base, int irq) 489static int __devinit ulite_assign(struct device *dev, int id, u32 base, int irq)
490{ 490{
491 struct uart_port *port; 491 struct uart_port *port;
492 int rc; 492 int rc;
@@ -542,7 +542,7 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq)
542 * 542 *
543 * @dev: pointer to device structure 543 * @dev: pointer to device structure
544 */ 544 */
545static int ulite_release(struct device *dev) 545static int __devexit ulite_release(struct device *dev)
546{ 546{
547 struct uart_port *port = dev_get_drvdata(dev); 547 struct uart_port *port = dev_get_drvdata(dev);
548 int rc = 0; 548 int rc = 0;
@@ -562,15 +562,17 @@ static int ulite_release(struct device *dev)
562 562
563#if defined(CONFIG_OF) 563#if defined(CONFIG_OF)
564/* Match table for of_platform binding */ 564/* Match table for of_platform binding */
565static struct of_device_id ulite_of_match[] = { 565static struct of_device_id ulite_of_match[] __devinitdata = {
566 { .compatible = "xlnx,opb-uartlite-1.00.b", }, 566 { .compatible = "xlnx,opb-uartlite-1.00.b", },
567 { .compatible = "xlnx,xps-uartlite-1.00.a", }, 567 { .compatible = "xlnx,xps-uartlite-1.00.a", },
568 {} 568 {}
569}; 569};
570MODULE_DEVICE_TABLE(of, ulite_of_match); 570MODULE_DEVICE_TABLE(of, ulite_of_match);
571#else /* CONFIG_OF */
572#define ulite_of_match NULL
571#endif /* CONFIG_OF */ 573#endif /* CONFIG_OF */
572 574
573static int ulite_probe(struct platform_device *pdev) 575static int __devinit ulite_probe(struct platform_device *pdev)
574{ 576{
575 struct resource *res, *res2; 577 struct resource *res, *res2;
576 int id = pdev->id; 578 int id = pdev->id;
@@ -593,7 +595,7 @@ static int ulite_probe(struct platform_device *pdev)
593 return ulite_assign(&pdev->dev, id, res->start, res2->start); 595 return ulite_assign(&pdev->dev, id, res->start, res2->start);
594} 596}
595 597
596static int ulite_remove(struct platform_device *pdev) 598static int __devexit ulite_remove(struct platform_device *pdev)
597{ 599{
598 return ulite_release(&pdev->dev); 600 return ulite_release(&pdev->dev);
599} 601}
@@ -603,11 +605,11 @@ MODULE_ALIAS("platform:uartlite");
603 605
604static struct platform_driver ulite_platform_driver = { 606static struct platform_driver ulite_platform_driver = {
605 .probe = ulite_probe, 607 .probe = ulite_probe,
606 .remove = ulite_remove, 608 .remove = __devexit_p(ulite_remove),
607 .driver = { 609 .driver = {
608 .owner = THIS_MODULE, 610 .owner = THIS_MODULE,
609 .name = "uartlite", 611 .name = "uartlite",
610 .of_match_table = of_match_ptr(ulite_of_match), 612 .of_match_table = ulite_of_match,
611 }, 613 },
612}; 614};
613 615
diff --git a/drivers/tty/serial/ucc_uart.c b/drivers/tty/serial/ucc_uart.c
index f99b0c965f8..9af9f0879a2 100644
--- a/drivers/tty/serial/ucc_uart.c
+++ b/drivers/tty/serial/ucc_uart.c
@@ -20,10 +20,8 @@
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/serial_core.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25#include <linux/tty.h> 24#include <linux/serial_core.h>
26#include <linux/tty_flip.h>
27#include <linux/io.h> 25#include <linux/io.h>
28#include <linux/of_platform.h> 26#include <linux/of_platform.h>
29#include <linux/dma-mapping.h> 27#include <linux/dma-mapping.h>
@@ -963,9 +961,6 @@ static void qe_uart_set_termios(struct uart_port *port,
963 /* Do we really need a spinlock here? */ 961 /* Do we really need a spinlock here? */
964 spin_lock_irqsave(&port->lock, flags); 962 spin_lock_irqsave(&port->lock, flags);
965 963
966 /* Update the per-port timeout. */
967 uart_update_timeout(port, termios->c_cflag, baud);
968
969 out_be16(&uccp->upsmr, upsmr); 964 out_be16(&uccp->upsmr, upsmr);
970 if (soft_uart) { 965 if (soft_uart) {
971 out_be16(&uccup->supsmr, supsmr); 966 out_be16(&uccup->supsmr, supsmr);
@@ -1360,7 +1355,7 @@ static int ucc_uart_probe(struct platform_device *ofdev)
1360 } 1355 }
1361 1356
1362 qe_port->port.irq = irq_of_parse_and_map(np, 0); 1357 qe_port->port.irq = irq_of_parse_and_map(np, 0);
1363 if (qe_port->port.irq == 0) { 1358 if (qe_port->port.irq == NO_IRQ) {
1364 dev_err(&ofdev->dev, "could not map IRQ for UCC%u\n", 1359 dev_err(&ofdev->dev, "could not map IRQ for UCC%u\n",
1365 qe_port->ucc_num + 1); 1360 qe_port->ucc_num + 1);
1366 ret = -EINVAL; 1361 ret = -EINVAL;
diff --git a/drivers/tty/serial/vr41xx_siu.c b/drivers/tty/serial/vr41xx_siu.c
index 62ee0166bc6..3beb6ab4fa6 100644
--- a/drivers/tty/serial/vr41xx_siu.c
+++ b/drivers/tty/serial/vr41xx_siu.c
@@ -61,7 +61,7 @@
61static struct uart_port siu_uart_ports[SIU_PORTS_MAX] = { 61static struct uart_port siu_uart_ports[SIU_PORTS_MAX] = {
62 [0 ... SIU_PORTS_MAX-1] = { 62 [0 ... SIU_PORTS_MAX-1] = {
63 .lock = __SPIN_LOCK_UNLOCKED(siu_uart_ports->lock), 63 .lock = __SPIN_LOCK_UNLOCKED(siu_uart_ports->lock),
64 .irq = 0, 64 .irq = -1,
65 }, 65 },
66}; 66};
67 67
@@ -171,7 +171,7 @@ static inline unsigned int siu_check_type(struct uart_port *port)
171{ 171{
172 if (port->line == 0) 172 if (port->line == 0)
173 return PORT_VR41XX_SIU; 173 return PORT_VR41XX_SIU;
174 if (port->line == 1 && port->irq) 174 if (port->line == 1 && port->irq != -1)
175 return PORT_VR41XX_DSIU; 175 return PORT_VR41XX_DSIU;
176 176
177 return PORT_UNKNOWN; 177 return PORT_UNKNOWN;
@@ -823,7 +823,7 @@ static struct console siu_console = {
823 .data = &siu_uart_driver, 823 .data = &siu_uart_driver,
824}; 824};
825 825
826static int siu_console_init(void) 826static int __devinit siu_console_init(void)
827{ 827{
828 struct uart_port *port; 828 struct uart_port *port;
829 int i; 829 int i;
@@ -867,7 +867,7 @@ static struct uart_driver siu_uart_driver = {
867 .cons = SERIAL_VR41XX_CONSOLE, 867 .cons = SERIAL_VR41XX_CONSOLE,
868}; 868};
869 869
870static int siu_probe(struct platform_device *dev) 870static int __devinit siu_probe(struct platform_device *dev)
871{ 871{
872 struct uart_port *port; 872 struct uart_port *port;
873 int num, i, retval; 873 int num, i, retval;
@@ -901,7 +901,7 @@ static int siu_probe(struct platform_device *dev)
901 return 0; 901 return 0;
902} 902}
903 903
904static int siu_remove(struct platform_device *dev) 904static int __devexit siu_remove(struct platform_device *dev)
905{ 905{
906 struct uart_port *port; 906 struct uart_port *port;
907 int i; 907 int i;
@@ -952,7 +952,7 @@ static int siu_resume(struct platform_device *dev)
952 952
953static struct platform_driver siu_device_driver = { 953static struct platform_driver siu_device_driver = {
954 .probe = siu_probe, 954 .probe = siu_probe,
955 .remove = siu_remove, 955 .remove = __devexit_p(siu_remove),
956 .suspend = siu_suspend, 956 .suspend = siu_suspend,
957 .resume = siu_resume, 957 .resume = siu_resume,
958 .driver = { 958 .driver = {
@@ -961,7 +961,18 @@ static struct platform_driver siu_device_driver = {
961 }, 961 },
962}; 962};
963 963
964module_platform_driver(siu_device_driver); 964static int __init vr41xx_siu_init(void)
965{
966 return platform_driver_register(&siu_device_driver);
967}
968
969static void __exit vr41xx_siu_exit(void)
970{
971 platform_driver_unregister(&siu_device_driver);
972}
973
974module_init(vr41xx_siu_init);
975module_exit(vr41xx_siu_exit);
965 976
966MODULE_LICENSE("GPL"); 977MODULE_LICENSE("GPL");
967MODULE_ALIAS("platform:SIU"); 978MODULE_ALIAS("platform:SIU");
diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c
index 8fd181436a6..026cb9ea5cd 100644
--- a/drivers/tty/serial/vt8500_serial.c
+++ b/drivers/tty/serial/vt8500_serial.c
@@ -34,7 +34,6 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/of.h>
38 37
39/* 38/*
40 * UART Register offsets 39 * UART Register offsets
@@ -77,8 +76,6 @@
77#define RX_FIFO_INTS (RXFAF | RXFF | RXOVER | PER | FER | RXTOUT) 76#define RX_FIFO_INTS (RXFAF | RXFF | RXOVER | PER | FER | RXTOUT)
78#define TX_FIFO_INTS (TXFAE | TXFE | TXUDR) 77#define TX_FIFO_INTS (TXFAE | TXFE | TXUDR)
79 78
80#define VT8500_MAX_PORTS 6
81
82struct vt8500_port { 79struct vt8500_port {
83 struct uart_port uart; 80 struct uart_port uart;
84 char name[16]; 81 char name[16];
@@ -86,13 +83,6 @@ struct vt8500_port {
86 unsigned int ier; 83 unsigned int ier;
87}; 84};
88 85
89/*
90 * we use this variable to keep track of which ports
91 * have been allocated as we can't use pdev->id in
92 * devicetree
93 */
94static unsigned long vt8500_ports_in_use;
95
96static inline void vt8500_write(struct uart_port *port, unsigned int val, 86static inline void vt8500_write(struct uart_port *port, unsigned int val,
97 unsigned int off) 87 unsigned int off)
98{ 88{
@@ -441,7 +431,7 @@ static int vt8500_verify_port(struct uart_port *port,
441 return 0; 431 return 0;
442} 432}
443 433
444static struct vt8500_port *vt8500_uart_ports[VT8500_MAX_PORTS]; 434static struct vt8500_port *vt8500_uart_ports[4];
445static struct uart_driver vt8500_uart_driver; 435static struct uart_driver vt8500_uart_driver;
446 436
447#ifdef CONFIG_SERIAL_VT8500_CONSOLE 437#ifdef CONFIG_SERIAL_VT8500_CONSOLE
@@ -554,41 +544,17 @@ static struct uart_driver vt8500_uart_driver = {
554 .cons = VT8500_CONSOLE, 544 .cons = VT8500_CONSOLE,
555}; 545};
556 546
557static int vt8500_serial_probe(struct platform_device *pdev) 547static int __init vt8500_serial_probe(struct platform_device *pdev)
558{ 548{
559 struct vt8500_port *vt8500_port; 549 struct vt8500_port *vt8500_port;
560 struct resource *mmres, *irqres; 550 struct resource *mmres, *irqres;
561 struct device_node *np = pdev->dev.of_node;
562 int ret; 551 int ret;
563 int port;
564 552
565 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0); 553 mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
566 irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 554 irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
567 if (!mmres || !irqres) 555 if (!mmres || !irqres)
568 return -ENODEV; 556 return -ENODEV;
569 557
570 if (np)
571 port = of_alias_get_id(np, "serial");
572 if (port > VT8500_MAX_PORTS)
573 port = -1;
574 else
575 port = -1;
576
577 if (port < 0) {
578 /* calculate the port id */
579 port = find_first_zero_bit(&vt8500_ports_in_use,
580 sizeof(vt8500_ports_in_use));
581 }
582
583 if (port > VT8500_MAX_PORTS)
584 return -ENODEV;
585
586 /* reserve the port id */
587 if (test_and_set_bit(port, &vt8500_ports_in_use)) {
588 /* port already in use - shouldn't really happen */
589 return -EBUSY;
590 }
591
592 vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL); 558 vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL);
593 if (!vt8500_port) 559 if (!vt8500_port)
594 return -ENOMEM; 560 return -ENOMEM;
@@ -599,18 +565,10 @@ static int vt8500_serial_probe(struct platform_device *pdev)
599 vt8500_port->uart.irq = irqres->start; 565 vt8500_port->uart.irq = irqres->start;
600 vt8500_port->uart.fifosize = 16; 566 vt8500_port->uart.fifosize = 16;
601 vt8500_port->uart.ops = &vt8500_uart_pops; 567 vt8500_port->uart.ops = &vt8500_uart_pops;
602 vt8500_port->uart.line = port; 568 vt8500_port->uart.line = pdev->id;
603 vt8500_port->uart.dev = &pdev->dev; 569 vt8500_port->uart.dev = &pdev->dev;
604 vt8500_port->uart.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; 570 vt8500_port->uart.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
605 571 vt8500_port->uart.uartclk = 24000000;
606 vt8500_port->clk = of_clk_get(pdev->dev.of_node, 0);
607 if (vt8500_port->clk) {
608 vt8500_port->uart.uartclk = clk_get_rate(vt8500_port->clk);
609 } else {
610 /* use the default of 24Mhz if not specified and warn */
611 pr_warn("%s: serial clock source not specified\n", __func__);
612 vt8500_port->uart.uartclk = 24000000;
613 }
614 572
615 snprintf(vt8500_port->name, sizeof(vt8500_port->name), 573 snprintf(vt8500_port->name, sizeof(vt8500_port->name),
616 "VT8500 UART%d", pdev->id); 574 "VT8500 UART%d", pdev->id);
@@ -621,7 +579,7 @@ static int vt8500_serial_probe(struct platform_device *pdev)
621 goto err; 579 goto err;
622 } 580 }
623 581
624 vt8500_uart_ports[port] = vt8500_port; 582 vt8500_uart_ports[pdev->id] = vt8500_port;
625 583
626 uart_add_one_port(&vt8500_uart_driver, &vt8500_port->uart); 584 uart_add_one_port(&vt8500_uart_driver, &vt8500_port->uart);
627 585
@@ -634,7 +592,7 @@ err:
634 return ret; 592 return ret;
635} 593}
636 594
637static int vt8500_serial_remove(struct platform_device *pdev) 595static int __devexit vt8500_serial_remove(struct platform_device *pdev)
638{ 596{
639 struct vt8500_port *vt8500_port = platform_get_drvdata(pdev); 597 struct vt8500_port *vt8500_port = platform_get_drvdata(pdev);
640 598
@@ -645,18 +603,12 @@ static int vt8500_serial_remove(struct platform_device *pdev)
645 return 0; 603 return 0;
646} 604}
647 605
648static const struct of_device_id wmt_dt_ids[] = {
649 { .compatible = "via,vt8500-uart", },
650 {}
651};
652
653static struct platform_driver vt8500_platform_driver = { 606static struct platform_driver vt8500_platform_driver = {
654 .probe = vt8500_serial_probe, 607 .probe = vt8500_serial_probe,
655 .remove = vt8500_serial_remove, 608 .remove = vt8500_serial_remove,
656 .driver = { 609 .driver = {
657 .name = "vt8500_serial", 610 .name = "vt8500_serial",
658 .owner = THIS_MODULE, 611 .owner = THIS_MODULE,
659 .of_match_table = of_match_ptr(wmt_dt_ids),
660 }, 612 },
661}; 613};
662 614
@@ -690,4 +642,4 @@ module_exit(vt8500_serial_exit);
690 642
691MODULE_AUTHOR("Alexey Charkov <alchark@gmail.com>"); 643MODULE_AUTHOR("Alexey Charkov <alchark@gmail.com>");
692MODULE_DESCRIPTION("Driver for vt8500 serial device"); 644MODULE_DESCRIPTION("Driver for vt8500 serial device");
693MODULE_LICENSE("GPL v2"); 645MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index 9ab910370c5..19cc1e8149d 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -12,15 +12,12 @@
12 */ 12 */
13 13
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/serial.h>
16#include <linux/serial_core.h> 15#include <linux/serial_core.h>
17#include <linux/tty.h>
18#include <linux/tty_flip.h>
19#include <linux/console.h> 16#include <linux/console.h>
17#include <linux/serial.h>
20#include <linux/irq.h> 18#include <linux/irq.h>
21#include <linux/io.h> 19#include <linux/io.h>
22#include <linux/of.h> 20#include <linux/of.h>
23#include <linux/module.h>
24 21
25#define XUARTPS_TTY_NAME "ttyPS" 22#define XUARTPS_TTY_NAME "ttyPS"
26#define XUARTPS_NAME "xuartps" 23#define XUARTPS_NAME "xuartps"
@@ -939,18 +936,22 @@ static struct uart_driver xuartps_uart_driver = {
939 * 936 *
940 * Returns 0 on success, negative error otherwise 937 * Returns 0 on success, negative error otherwise
941 **/ 938 **/
942static int xuartps_probe(struct platform_device *pdev) 939static int __devinit xuartps_probe(struct platform_device *pdev)
943{ 940{
944 int rc; 941 int rc;
945 struct uart_port *port; 942 struct uart_port *port;
946 struct resource *res, *res2; 943 struct resource *res, *res2;
947 int clk = 0; 944 int clk = 0;
948 945
946#ifdef CONFIG_OF
949 const unsigned int *prop; 947 const unsigned int *prop;
950 948
951 prop = of_get_property(pdev->dev.of_node, "clock", NULL); 949 prop = of_get_property(pdev->dev.of_node, "clock", NULL);
952 if (prop) 950 if (prop)
953 clk = be32_to_cpup(prop); 951 clk = be32_to_cpup(prop);
952#else
953 clk = *((unsigned int *)(pdev->dev.platform_data));
954#endif
954 if (!clk) { 955 if (!clk) {
955 dev_err(&pdev->dev, "no clock specified\n"); 956 dev_err(&pdev->dev, "no clock specified\n");
956 return -ENODEV; 957 return -ENODEV;
@@ -997,7 +998,7 @@ static int xuartps_probe(struct platform_device *pdev)
997 * 998 *
998 * Returns 0 on success, negative error otherwise 999 * Returns 0 on success, negative error otherwise
999 **/ 1000 **/
1000static int xuartps_remove(struct platform_device *pdev) 1001static int __devexit xuartps_remove(struct platform_device *pdev)
1001{ 1002{
1002 struct uart_port *port = dev_get_drvdata(&pdev->dev); 1003 struct uart_port *port = dev_get_drvdata(&pdev->dev);
1003 int rc = 0; 1004 int rc = 0;
@@ -1040,11 +1041,16 @@ static int xuartps_resume(struct platform_device *pdev)
1040} 1041}
1041 1042
1042/* Match table for of_platform binding */ 1043/* Match table for of_platform binding */
1043static struct of_device_id xuartps_of_match[] = { 1044
1045#ifdef CONFIG_OF
1046static struct of_device_id xuartps_of_match[] __devinitdata = {
1044 { .compatible = "xlnx,xuartps", }, 1047 { .compatible = "xlnx,xuartps", },
1045 {} 1048 {}
1046}; 1049};
1047MODULE_DEVICE_TABLE(of, xuartps_of_match); 1050MODULE_DEVICE_TABLE(of, xuartps_of_match);
1051#else
1052#define xuartps_of_match NULL
1053#endif
1048 1054
1049static struct platform_driver xuartps_platform_driver = { 1055static struct platform_driver xuartps_platform_driver = {
1050 .probe = xuartps_probe, /* Probe method */ 1056 .probe = xuartps_probe, /* Probe method */
diff --git a/drivers/tty/serial/zs.c b/drivers/tty/serial/zs.c
index 92c00b24d0d..0aebd7121b5 100644
--- a/drivers/tty/serial/zs.c
+++ b/drivers/tty/serial/zs.c
@@ -57,17 +57,16 @@
57#include <linux/ioport.h> 57#include <linux/ioport.h>
58#include <linux/irqflags.h> 58#include <linux/irqflags.h>
59#include <linux/kernel.h> 59#include <linux/kernel.h>
60#include <linux/module.h>
61#include <linux/major.h> 60#include <linux/major.h>
62#include <linux/serial.h> 61#include <linux/serial.h>
63#include <linux/serial_core.h> 62#include <linux/serial_core.h>
64#include <linux/spinlock.h> 63#include <linux/spinlock.h>
65#include <linux/sysrq.h> 64#include <linux/sysrq.h>
66#include <linux/tty.h> 65#include <linux/tty.h>
67#include <linux/tty_flip.h>
68#include <linux/types.h> 66#include <linux/types.h>
69 67
70#include <linux/atomic.h> 68#include <linux/atomic.h>
69#include <asm/system.h>
71 70
72#include <asm/dec/interrupts.h> 71#include <asm/dec/interrupts.h>
73#include <asm/dec/ioasic_addrs.h> 72#include <asm/dec/ioasic_addrs.h>
diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
index 9e071f6985f..272e417a9b0 100644
--- a/drivers/tty/synclink.c
+++ b/drivers/tty/synclink.c
@@ -86,6 +86,7 @@
86#include <linux/ioctl.h> 86#include <linux/ioctl.h>
87#include <linux/synclink.h> 87#include <linux/synclink.h>
88 88
89#include <asm/system.h>
89#include <asm/io.h> 90#include <asm/io.h>
90#include <asm/irq.h> 91#include <asm/irq.h>
91#include <asm/dma.h> 92#include <asm/dma.h>
@@ -849,7 +850,7 @@ static int mgsl_device_count;
849 * .text section address and breakpoint on module load. 850 * .text section address and breakpoint on module load.
850 * This is useful for use with gdb and add-symbol-file command. 851 * This is useful for use with gdb and add-symbol-file command.
851 */ 852 */
852static bool break_on_load; 853static int break_on_load;
853 854
854/* 855/*
855 * Driver major number, defaults to zero to get auto 856 * Driver major number, defaults to zero to get auto
@@ -898,7 +899,7 @@ static struct pci_driver synclink_pci_driver = {
898 .name = "synclink", 899 .name = "synclink",
899 .id_table = synclink_pci_tbl, 900 .id_table = synclink_pci_tbl,
900 .probe = synclink_init_one, 901 .probe = synclink_init_one,
901 .remove = synclink_remove_one, 902 .remove = __devexit_p(synclink_remove_one),
902}; 903};
903 904
904static struct tty_driver *serial_driver; 905static struct tty_driver *serial_driver;
@@ -1359,7 +1360,7 @@ static void mgsl_isr_io_pin( struct mgsl_struct *info )
1359 } 1360 }
1360 } 1361 }
1361 1362
1362 if (tty_port_cts_enabled(&info->port) && 1363 if ( (info->port.flags & ASYNC_CTS_FLOW) &&
1363 (status & MISCSTATUS_CTS_LATCHED) ) { 1364 (status & MISCSTATUS_CTS_LATCHED) ) {
1364 if (info->port.tty->hw_stopped) { 1365 if (info->port.tty->hw_stopped) {
1365 if (status & MISCSTATUS_CTS) { 1366 if (status & MISCSTATUS_CTS) {
@@ -1840,22 +1841,22 @@ static void shutdown(struct mgsl_struct * info)
1840 usc_DisableInterrupts(info,RECEIVE_DATA + RECEIVE_STATUS + 1841 usc_DisableInterrupts(info,RECEIVE_DATA + RECEIVE_STATUS +
1841 TRANSMIT_DATA + TRANSMIT_STATUS + IO_PIN + MISC ); 1842 TRANSMIT_DATA + TRANSMIT_STATUS + IO_PIN + MISC );
1842 usc_DisableDmaInterrupts(info,DICR_MASTER + DICR_TRANSMIT + DICR_RECEIVE); 1843 usc_DisableDmaInterrupts(info,DICR_MASTER + DICR_TRANSMIT + DICR_RECEIVE);
1843 1844
1844 /* Disable DMAEN (Port 7, Bit 14) */ 1845 /* Disable DMAEN (Port 7, Bit 14) */
1845 /* This disconnects the DMA request signal from the ISA bus */ 1846 /* This disconnects the DMA request signal from the ISA bus */
1846 /* on the ISA adapter. This has no effect for the PCI adapter */ 1847 /* on the ISA adapter. This has no effect for the PCI adapter */
1847 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT15) | BIT14)); 1848 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT15) | BIT14));
1848 1849
1849 /* Disable INTEN (Port 6, Bit12) */ 1850 /* Disable INTEN (Port 6, Bit12) */
1850 /* This disconnects the IRQ request signal to the ISA bus */ 1851 /* This disconnects the IRQ request signal to the ISA bus */
1851 /* on the ISA adapter. This has no effect for the PCI adapter */ 1852 /* on the ISA adapter. This has no effect for the PCI adapter */
1852 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) | BIT12)); 1853 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) | BIT12));
1853 1854
1854 if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) { 1855 if (!info->port.tty || info->port.tty->termios->c_cflag & HUPCL) {
1855 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS); 1856 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
1856 usc_set_serial_signals(info); 1857 usc_set_serial_signals(info);
1857 } 1858 }
1858 1859
1859 spin_unlock_irqrestore(&info->irq_spinlock,flags); 1860 spin_unlock_irqrestore(&info->irq_spinlock,flags);
1860 1861
1861 mgsl_release_resources(info); 1862 mgsl_release_resources(info);
@@ -1895,7 +1896,7 @@ static void mgsl_program_hw(struct mgsl_struct *info)
1895 usc_EnableInterrupts(info, IO_PIN); 1896 usc_EnableInterrupts(info, IO_PIN);
1896 usc_get_serial_signals(info); 1897 usc_get_serial_signals(info);
1897 1898
1898 if (info->netcount || info->port.tty->termios.c_cflag & CREAD) 1899 if (info->netcount || info->port.tty->termios->c_cflag & CREAD)
1899 usc_start_receiver(info); 1900 usc_start_receiver(info);
1900 1901
1901 spin_unlock_irqrestore(&info->irq_spinlock,flags); 1902 spin_unlock_irqrestore(&info->irq_spinlock,flags);
@@ -1908,14 +1909,14 @@ static void mgsl_change_params(struct mgsl_struct *info)
1908 unsigned cflag; 1909 unsigned cflag;
1909 int bits_per_char; 1910 int bits_per_char;
1910 1911
1911 if (!info->port.tty) 1912 if (!info->port.tty || !info->port.tty->termios)
1912 return; 1913 return;
1913 1914
1914 if (debug_level >= DEBUG_LEVEL_INFO) 1915 if (debug_level >= DEBUG_LEVEL_INFO)
1915 printk("%s(%d):mgsl_change_params(%s)\n", 1916 printk("%s(%d):mgsl_change_params(%s)\n",
1916 __FILE__,__LINE__, info->device_name ); 1917 __FILE__,__LINE__, info->device_name );
1917 1918
1918 cflag = info->port.tty->termios.c_cflag; 1919 cflag = info->port.tty->termios->c_cflag;
1919 1920
1920 /* if B0 rate (hangup) specified then negate DTR and RTS */ 1921 /* if B0 rate (hangup) specified then negate DTR and RTS */
1921 /* otherwise assert DTR and RTS */ 1922 /* otherwise assert DTR and RTS */
@@ -2123,6 +2124,7 @@ static int mgsl_write(struct tty_struct * tty,
2123 if ( info->params.mode == MGSL_MODE_HDLC || 2124 if ( info->params.mode == MGSL_MODE_HDLC ||
2124 info->params.mode == MGSL_MODE_RAW ) { 2125 info->params.mode == MGSL_MODE_RAW ) {
2125 /* operating in synchronous (frame oriented) mode */ 2126 /* operating in synchronous (frame oriented) mode */
2127 /* operating in synchronous (frame oriented) mode */
2126 if (info->tx_active) { 2128 if (info->tx_active) {
2127 2129
2128 if ( info->params.mode == MGSL_MODE_HDLC ) { 2130 if ( info->params.mode == MGSL_MODE_HDLC ) {
@@ -2367,8 +2369,8 @@ static void mgsl_throttle(struct tty_struct * tty)
2367 2369
2368 if (I_IXOFF(tty)) 2370 if (I_IXOFF(tty))
2369 mgsl_send_xchar(tty, STOP_CHAR(tty)); 2371 mgsl_send_xchar(tty, STOP_CHAR(tty));
2370 2372
2371 if (tty->termios.c_cflag & CRTSCTS) { 2373 if (tty->termios->c_cflag & CRTSCTS) {
2372 spin_lock_irqsave(&info->irq_spinlock,flags); 2374 spin_lock_irqsave(&info->irq_spinlock,flags);
2373 info->serial_signals &= ~SerialSignal_RTS; 2375 info->serial_signals &= ~SerialSignal_RTS;
2374 usc_set_serial_signals(info); 2376 usc_set_serial_signals(info);
@@ -2401,8 +2403,8 @@ static void mgsl_unthrottle(struct tty_struct * tty)
2401 else 2403 else
2402 mgsl_send_xchar(tty, START_CHAR(tty)); 2404 mgsl_send_xchar(tty, START_CHAR(tty));
2403 } 2405 }
2404 2406
2405 if (tty->termios.c_cflag & CRTSCTS) { 2407 if (tty->termios->c_cflag & CRTSCTS) {
2406 spin_lock_irqsave(&info->irq_spinlock,flags); 2408 spin_lock_irqsave(&info->irq_spinlock,flags);
2407 info->serial_signals |= SerialSignal_RTS; 2409 info->serial_signals |= SerialSignal_RTS;
2408 usc_set_serial_signals(info); 2410 usc_set_serial_signals(info);
@@ -3045,7 +3047,7 @@ static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termio
3045 3047
3046 /* Handle transition to B0 status */ 3048 /* Handle transition to B0 status */
3047 if (old_termios->c_cflag & CBAUD && 3049 if (old_termios->c_cflag & CBAUD &&
3048 !(tty->termios.c_cflag & CBAUD)) { 3050 !(tty->termios->c_cflag & CBAUD)) {
3049 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR); 3051 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
3050 spin_lock_irqsave(&info->irq_spinlock,flags); 3052 spin_lock_irqsave(&info->irq_spinlock,flags);
3051 usc_set_serial_signals(info); 3053 usc_set_serial_signals(info);
@@ -3054,9 +3056,9 @@ static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termio
3054 3056
3055 /* Handle transition away from B0 status */ 3057 /* Handle transition away from B0 status */
3056 if (!(old_termios->c_cflag & CBAUD) && 3058 if (!(old_termios->c_cflag & CBAUD) &&
3057 tty->termios.c_cflag & CBAUD) { 3059 tty->termios->c_cflag & CBAUD) {
3058 info->serial_signals |= SerialSignal_DTR; 3060 info->serial_signals |= SerialSignal_DTR;
3059 if (!(tty->termios.c_cflag & CRTSCTS) || 3061 if (!(tty->termios->c_cflag & CRTSCTS) ||
3060 !test_bit(TTY_THROTTLED, &tty->flags)) { 3062 !test_bit(TTY_THROTTLED, &tty->flags)) {
3061 info->serial_signals |= SerialSignal_RTS; 3063 info->serial_signals |= SerialSignal_RTS;
3062 } 3064 }
@@ -3067,7 +3069,7 @@ static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termio
3067 3069
3068 /* Handle turning off CRTSCTS */ 3070 /* Handle turning off CRTSCTS */
3069 if (old_termios->c_cflag & CRTSCTS && 3071 if (old_termios->c_cflag & CRTSCTS &&
3070 !(tty->termios.c_cflag & CRTSCTS)) { 3072 !(tty->termios->c_cflag & CRTSCTS)) {
3071 tty->hw_stopped = 0; 3073 tty->hw_stopped = 0;
3072 mgsl_start(tty); 3074 mgsl_start(tty);
3073 } 3075 }
@@ -3287,7 +3289,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3287 return 0; 3289 return 0;
3288 } 3290 }
3289 3291
3290 if (tty->termios.c_cflag & CLOCAL) 3292 if (tty->termios->c_cflag & CLOCAL)
3291 do_clocal = true; 3293 do_clocal = true;
3292 3294
3293 /* Wait for carrier detect and the line to become 3295 /* Wait for carrier detect and the line to become
@@ -3313,7 +3315,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3313 port->blocked_open++; 3315 port->blocked_open++;
3314 3316
3315 while (1) { 3317 while (1) {
3316 if (tty->termios.c_cflag & CBAUD) 3318 if (tty->termios->c_cflag & CBAUD)
3317 tty_port_raise_dtr_rts(port); 3319 tty_port_raise_dtr_rts(port);
3318 3320
3319 set_current_state(TASK_INTERRUPTIBLE); 3321 set_current_state(TASK_INTERRUPTIBLE);
@@ -3338,9 +3340,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3338 printk("%s(%d):block_til_ready blocking on %s count=%d\n", 3340 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
3339 __FILE__,__LINE__, tty->driver->name, port->count ); 3341 __FILE__,__LINE__, tty->driver->name, port->count );
3340 3342
3341 tty_unlock(tty); 3343 tty_unlock();
3342 schedule(); 3344 schedule();
3343 tty_lock(tty); 3345 tty_lock();
3344 } 3346 }
3345 3347
3346 set_current_state(TASK_RUNNING); 3348 set_current_state(TASK_RUNNING);
@@ -3362,29 +3364,6 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3362 3364
3363} /* end of block_til_ready() */ 3365} /* end of block_til_ready() */
3364 3366
3365static int mgsl_install(struct tty_driver *driver, struct tty_struct *tty)
3366{
3367 struct mgsl_struct *info;
3368 int line = tty->index;
3369
3370 /* verify range of specified line number */
3371 if (line >= mgsl_device_count) {
3372 printk("%s(%d):mgsl_open with invalid line #%d.\n",
3373 __FILE__, __LINE__, line);
3374 return -ENODEV;
3375 }
3376
3377 /* find the info structure for the specified line */
3378 info = mgsl_device_list;
3379 while (info && info->line != line)
3380 info = info->next_device;
3381 if (mgsl_paranoia_check(info, tty->name, "mgsl_open"))
3382 return -ENODEV;
3383 tty->driver_data = info;
3384
3385 return tty_port_install(&info->port, driver, tty);
3386}
3387
3388/* mgsl_open() 3367/* mgsl_open()
3389 * 3368 *
3390 * Called when a port is opened. Init and enable port. 3369 * Called when a port is opened. Init and enable port.
@@ -3397,10 +3376,26 @@ static int mgsl_install(struct tty_driver *driver, struct tty_struct *tty)
3397 */ 3376 */
3398static int mgsl_open(struct tty_struct *tty, struct file * filp) 3377static int mgsl_open(struct tty_struct *tty, struct file * filp)
3399{ 3378{
3400 struct mgsl_struct *info = tty->driver_data; 3379 struct mgsl_struct *info;
3380 int retval, line;
3401 unsigned long flags; 3381 unsigned long flags;
3402 int retval;
3403 3382
3383 /* verify range of specified line number */
3384 line = tty->index;
3385 if ((line < 0) || (line >= mgsl_device_count)) {
3386 printk("%s(%d):mgsl_open with invalid line #%d.\n",
3387 __FILE__,__LINE__,line);
3388 return -ENODEV;
3389 }
3390
3391 /* find the info structure for the specified line */
3392 info = mgsl_device_list;
3393 while(info && info->line != line)
3394 info = info->next_device;
3395 if (mgsl_paranoia_check(info, tty->name, "mgsl_open"))
3396 return -ENODEV;
3397
3398 tty->driver_data = info;
3404 info->port.tty = tty; 3399 info->port.tty = tty;
3405 3400
3406 if (debug_level >= DEBUG_LEVEL_INFO) 3401 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -4304,7 +4299,6 @@ static struct mgsl_struct* mgsl_allocate_device(void)
4304} /* end of mgsl_allocate_device()*/ 4299} /* end of mgsl_allocate_device()*/
4305 4300
4306static const struct tty_operations mgsl_ops = { 4301static const struct tty_operations mgsl_ops = {
4307 .install = mgsl_install,
4308 .open = mgsl_open, 4302 .open = mgsl_open,
4309 .close = mgsl_close, 4303 .close = mgsl_close,
4310 .write = mgsl_write, 4304 .write = mgsl_write,
@@ -4340,6 +4334,7 @@ static int mgsl_init_tty(void)
4340 if (!serial_driver) 4334 if (!serial_driver)
4341 return -ENOMEM; 4335 return -ENOMEM;
4342 4336
4337 serial_driver->owner = THIS_MODULE;
4343 serial_driver->driver_name = "synclink"; 4338 serial_driver->driver_name = "synclink";
4344 serial_driver->name = "ttySL"; 4339 serial_driver->name = "ttySL";
4345 serial_driver->major = ttymajor; 4340 serial_driver->major = ttymajor;
@@ -4425,7 +4420,6 @@ static void synclink_cleanup(void)
4425 mgsl_release_resources(info); 4420 mgsl_release_resources(info);
4426 tmp = info; 4421 tmp = info;
4427 info = info->next_device; 4422 info = info->next_device;
4428 tty_port_destroy(&tmp->port);
4429 kfree(tmp); 4423 kfree(tmp);
4430 } 4424 }
4431 4425
@@ -8065,7 +8059,7 @@ static void hdlcdev_exit(struct mgsl_struct *info)
8065#endif /* CONFIG_HDLC */ 8059#endif /* CONFIG_HDLC */
8066 8060
8067 8061
8068static int synclink_init_one (struct pci_dev *dev, 8062static int __devinit synclink_init_one (struct pci_dev *dev,
8069 const struct pci_device_id *ent) 8063 const struct pci_device_id *ent)
8070{ 8064{
8071 struct mgsl_struct *info; 8065 struct mgsl_struct *info;
@@ -8117,7 +8111,7 @@ static int synclink_init_one (struct pci_dev *dev,
8117 return 0; 8111 return 0;
8118} 8112}
8119 8113
8120static void synclink_remove_one (struct pci_dev *dev) 8114static void __devexit synclink_remove_one (struct pci_dev *dev)
8121{ 8115{
8122} 8116}
8123 8117
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index aba1e59f4a8..18b48cd3b41 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -73,6 +73,7 @@
73#include <linux/hdlc.h> 73#include <linux/hdlc.h>
74#include <linux/synclink.h> 74#include <linux/synclink.h>
75 75
76#include <asm/system.h>
76#include <asm/io.h> 77#include <asm/io.h>
77#include <asm/irq.h> 78#include <asm/irq.h>
78#include <asm/dma.h> 79#include <asm/dma.h>
@@ -110,7 +111,7 @@ static struct pci_driver pci_driver = {
110 .name = "synclink_gt", 111 .name = "synclink_gt",
111 .id_table = pci_table, 112 .id_table = pci_table,
112 .probe = init_one, 113 .probe = init_one,
113 .remove = remove_one, 114 .remove = __devexit_p(remove_one),
114}; 115};
115 116
116static bool pci_registered; 117static bool pci_registered;
@@ -653,7 +654,7 @@ static int open(struct tty_struct *tty, struct file *filp)
653 unsigned long flags; 654 unsigned long flags;
654 655
655 line = tty->index; 656 line = tty->index;
656 if (line >= slgt_device_count) { 657 if ((line < 0) || (line >= slgt_device_count)) {
657 DBGERR(("%s: open with invalid line #%d.\n", driver_name, line)); 658 DBGERR(("%s: open with invalid line #%d.\n", driver_name, line));
658 return -ENODEV; 659 return -ENODEV;
659 } 660 }
@@ -785,7 +786,7 @@ static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
785 786
786 /* Handle transition to B0 status */ 787 /* Handle transition to B0 status */
787 if (old_termios->c_cflag & CBAUD && 788 if (old_termios->c_cflag & CBAUD &&
788 !(tty->termios.c_cflag & CBAUD)) { 789 !(tty->termios->c_cflag & CBAUD)) {
789 info->signals &= ~(SerialSignal_RTS + SerialSignal_DTR); 790 info->signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
790 spin_lock_irqsave(&info->lock,flags); 791 spin_lock_irqsave(&info->lock,flags);
791 set_signals(info); 792 set_signals(info);
@@ -794,9 +795,9 @@ static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
794 795
795 /* Handle transition away from B0 status */ 796 /* Handle transition away from B0 status */
796 if (!(old_termios->c_cflag & CBAUD) && 797 if (!(old_termios->c_cflag & CBAUD) &&
797 tty->termios.c_cflag & CBAUD) { 798 tty->termios->c_cflag & CBAUD) {
798 info->signals |= SerialSignal_DTR; 799 info->signals |= SerialSignal_DTR;
799 if (!(tty->termios.c_cflag & CRTSCTS) || 800 if (!(tty->termios->c_cflag & CRTSCTS) ||
800 !test_bit(TTY_THROTTLED, &tty->flags)) { 801 !test_bit(TTY_THROTTLED, &tty->flags)) {
801 info->signals |= SerialSignal_RTS; 802 info->signals |= SerialSignal_RTS;
802 } 803 }
@@ -807,7 +808,7 @@ static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
807 808
808 /* Handle turning off CRTSCTS */ 809 /* Handle turning off CRTSCTS */
809 if (old_termios->c_cflag & CRTSCTS && 810 if (old_termios->c_cflag & CRTSCTS &&
810 !(tty->termios.c_cflag & CRTSCTS)) { 811 !(tty->termios->c_cflag & CRTSCTS)) {
811 tty->hw_stopped = 0; 812 tty->hw_stopped = 0;
812 tx_release(tty); 813 tx_release(tty);
813 } 814 }
@@ -1372,7 +1373,7 @@ static void throttle(struct tty_struct * tty)
1372 DBGINFO(("%s throttle\n", info->device_name)); 1373 DBGINFO(("%s throttle\n", info->device_name));
1373 if (I_IXOFF(tty)) 1374 if (I_IXOFF(tty))
1374 send_xchar(tty, STOP_CHAR(tty)); 1375 send_xchar(tty, STOP_CHAR(tty));
1375 if (tty->termios.c_cflag & CRTSCTS) { 1376 if (tty->termios->c_cflag & CRTSCTS) {
1376 spin_lock_irqsave(&info->lock,flags); 1377 spin_lock_irqsave(&info->lock,flags);
1377 info->signals &= ~SerialSignal_RTS; 1378 info->signals &= ~SerialSignal_RTS;
1378 set_signals(info); 1379 set_signals(info);
@@ -1397,7 +1398,7 @@ static void unthrottle(struct tty_struct * tty)
1397 else 1398 else
1398 send_xchar(tty, START_CHAR(tty)); 1399 send_xchar(tty, START_CHAR(tty));
1399 } 1400 }
1400 if (tty->termios.c_cflag & CRTSCTS) { 1401 if (tty->termios->c_cflag & CRTSCTS) {
1401 spin_lock_irqsave(&info->lock,flags); 1402 spin_lock_irqsave(&info->lock,flags);
1402 info->signals |= SerialSignal_RTS; 1403 info->signals |= SerialSignal_RTS;
1403 set_signals(info); 1404 set_signals(info);
@@ -2053,7 +2054,7 @@ static void cts_change(struct slgt_info *info, unsigned short status)
2053 wake_up_interruptible(&info->event_wait_q); 2054 wake_up_interruptible(&info->event_wait_q);
2054 info->pending_bh |= BH_STATUS; 2055 info->pending_bh |= BH_STATUS;
2055 2056
2056 if (tty_port_cts_enabled(&info->port)) { 2057 if (info->port.flags & ASYNC_CTS_FLOW) {
2057 if (info->port.tty) { 2058 if (info->port.tty) {
2058 if (info->port.tty->hw_stopped) { 2059 if (info->port.tty->hw_stopped) {
2059 if (info->signals & SerialSignal_CTS) { 2060 if (info->signals & SerialSignal_CTS) {
@@ -2493,7 +2494,7 @@ static void shutdown(struct slgt_info *info)
2493 2494
2494 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); 2495 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
2495 2496
2496 if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) { 2497 if (!info->port.tty || info->port.tty->termios->c_cflag & HUPCL) {
2497 info->signals &= ~(SerialSignal_DTR + SerialSignal_RTS); 2498 info->signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
2498 set_signals(info); 2499 set_signals(info);
2499 } 2500 }
@@ -2534,7 +2535,7 @@ static void program_hw(struct slgt_info *info)
2534 get_signals(info); 2535 get_signals(info);
2535 2536
2536 if (info->netcount || 2537 if (info->netcount ||
2537 (info->port.tty && info->port.tty->termios.c_cflag & CREAD)) 2538 (info->port.tty && info->port.tty->termios->c_cflag & CREAD))
2538 rx_start(info); 2539 rx_start(info);
2539 2540
2540 spin_unlock_irqrestore(&info->lock,flags); 2541 spin_unlock_irqrestore(&info->lock,flags);
@@ -2548,11 +2549,11 @@ static void change_params(struct slgt_info *info)
2548 unsigned cflag; 2549 unsigned cflag;
2549 int bits_per_char; 2550 int bits_per_char;
2550 2551
2551 if (!info->port.tty) 2552 if (!info->port.tty || !info->port.tty->termios)
2552 return; 2553 return;
2553 DBGINFO(("%s change_params\n", info->device_name)); 2554 DBGINFO(("%s change_params\n", info->device_name));
2554 2555
2555 cflag = info->port.tty->termios.c_cflag; 2556 cflag = info->port.tty->termios->c_cflag;
2556 2557
2557 /* if B0 rate (hangup) specified then negate DTR and RTS */ 2558 /* if B0 rate (hangup) specified then negate DTR and RTS */
2558 /* otherwise assert DTR and RTS */ 2559 /* otherwise assert DTR and RTS */
@@ -3292,7 +3293,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3292 return 0; 3293 return 0;
3293 } 3294 }
3294 3295
3295 if (tty->termios.c_cflag & CLOCAL) 3296 if (tty->termios->c_cflag & CLOCAL)
3296 do_clocal = true; 3297 do_clocal = true;
3297 3298
3298 /* Wait for carrier detect and the line to become 3299 /* Wait for carrier detect and the line to become
@@ -3314,7 +3315,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3314 port->blocked_open++; 3315 port->blocked_open++;
3315 3316
3316 while (1) { 3317 while (1) {
3317 if ((tty->termios.c_cflag & CBAUD)) 3318 if ((tty->termios->c_cflag & CBAUD))
3318 tty_port_raise_dtr_rts(port); 3319 tty_port_raise_dtr_rts(port);
3319 3320
3320 set_current_state(TASK_INTERRUPTIBLE); 3321 set_current_state(TASK_INTERRUPTIBLE);
@@ -3336,9 +3337,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3336 } 3337 }
3337 3338
3338 DBGINFO(("%s block_til_ready wait\n", tty->driver->name)); 3339 DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
3339 tty_unlock(tty); 3340 tty_unlock();
3340 schedule(); 3341 schedule();
3341 tty_lock(tty); 3342 tty_lock();
3342 } 3343 }
3343 3344
3344 set_current_state(TASK_RUNNING); 3345 set_current_state(TASK_RUNNING);
@@ -3645,10 +3646,8 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
3645 for (i=0; i < port_count; ++i) { 3646 for (i=0; i < port_count; ++i) {
3646 port_array[i] = alloc_dev(adapter_num, i, pdev); 3647 port_array[i] = alloc_dev(adapter_num, i, pdev);
3647 if (port_array[i] == NULL) { 3648 if (port_array[i] == NULL) {
3648 for (--i; i >= 0; --i) { 3649 for (--i; i >= 0; --i)
3649 tty_port_destroy(&port_array[i]->port);
3650 kfree(port_array[i]); 3650 kfree(port_array[i]);
3651 }
3652 return; 3651 return;
3653 } 3652 }
3654 } 3653 }
@@ -3691,14 +3690,11 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
3691 } 3690 }
3692 } 3691 }
3693 3692
3694 for (i = 0; i < port_count; ++i) { 3693 for (i=0; i < port_count; ++i)
3695 struct slgt_info *info = port_array[i]; 3694 tty_register_device(serial_driver, port_array[i]->line, &(port_array[i]->pdev->dev));
3696 tty_port_register_device(&info->port, serial_driver, info->line,
3697 &info->pdev->dev);
3698 }
3699} 3695}
3700 3696
3701static int init_one(struct pci_dev *dev, 3697static int __devinit init_one(struct pci_dev *dev,
3702 const struct pci_device_id *ent) 3698 const struct pci_device_id *ent)
3703{ 3699{
3704 if (pci_enable_device(dev)) { 3700 if (pci_enable_device(dev)) {
@@ -3710,7 +3706,7 @@ static int init_one(struct pci_dev *dev,
3710 return 0; 3706 return 0;
3711} 3707}
3712 3708
3713static void remove_one(struct pci_dev *dev) 3709static void __devexit remove_one(struct pci_dev *dev)
3714{ 3710{
3715} 3711}
3716 3712
@@ -3775,7 +3771,6 @@ static void slgt_cleanup(void)
3775 release_resources(info); 3771 release_resources(info);
3776 tmp = info; 3772 tmp = info;
3777 info = info->next_device; 3773 info = info->next_device;
3778 tty_port_destroy(&tmp->port);
3779 kfree(tmp); 3774 kfree(tmp);
3780 } 3775 }
3781 3776
@@ -3800,6 +3795,7 @@ static int __init slgt_init(void)
3800 3795
3801 /* Initialize the tty_driver structure */ 3796 /* Initialize the tty_driver structure */
3802 3797
3798 serial_driver->owner = THIS_MODULE;
3803 serial_driver->driver_name = tty_driver_name; 3799 serial_driver->driver_name = tty_driver_name;
3804 serial_driver->name = tty_dev_prefix; 3800 serial_driver->name = tty_dev_prefix;
3805 serial_driver->major = ttymajor; 3801 serial_driver->major = ttymajor;
@@ -3928,7 +3924,7 @@ static void tdma_reset(struct slgt_info *info)
3928 */ 3924 */
3929static void enable_loopback(struct slgt_info *info) 3925static void enable_loopback(struct slgt_info *info)
3930{ 3926{
3931 /* SCR (serial control) BIT2=loopback enable */ 3927 /* SCR (serial control) BIT2=looopback enable */
3932 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2)); 3928 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2));
3933 3929
3934 if (info->params.mode != MGSL_MODE_ASYNC) { 3930 if (info->params.mode != MGSL_MODE_ASYNC) {
diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
index fd43fb6f7ce..c77831c7675 100644
--- a/drivers/tty/synclinkmp.c
+++ b/drivers/tty/synclinkmp.c
@@ -58,6 +58,7 @@
58#include <linux/delay.h> 58#include <linux/delay.h>
59#include <linux/ioctl.h> 59#include <linux/ioctl.h>
60 60
61#include <asm/system.h>
61#include <asm/io.h> 62#include <asm/io.h>
62#include <asm/irq.h> 63#include <asm/irq.h>
63#include <asm/dma.h> 64#include <asm/dma.h>
@@ -455,7 +456,7 @@ static int synclinkmp_device_count = 0;
455 * .text section address and breakpoint on module load. 456 * .text section address and breakpoint on module load.
456 * This is useful for use with gdb and add-symbol-file command. 457 * This is useful for use with gdb and add-symbol-file command.
457 */ 458 */
458static bool break_on_load = 0; 459static int break_on_load = 0;
459 460
460/* 461/*
461 * Driver major number, defaults to zero to get auto 462 * Driver major number, defaults to zero to get auto
@@ -492,7 +493,7 @@ static struct pci_driver synclinkmp_pci_driver = {
492 .name = "synclinkmp", 493 .name = "synclinkmp",
493 .id_table = synclinkmp_pci_tbl, 494 .id_table = synclinkmp_pci_tbl,
494 .probe = synclinkmp_init_one, 495 .probe = synclinkmp_init_one,
495 .remove = synclinkmp_remove_one, 496 .remove = __devexit_p(synclinkmp_remove_one),
496}; 497};
497 498
498 499
@@ -711,42 +712,33 @@ static void ldisc_receive_buf(struct tty_struct *tty,
711 712
712/* tty callbacks */ 713/* tty callbacks */
713 714
714static int install(struct tty_driver *driver, struct tty_struct *tty) 715/* Called when a port is opened. Init and enable port.
716 */
717static int open(struct tty_struct *tty, struct file *filp)
715{ 718{
716 SLMP_INFO *info; 719 SLMP_INFO *info;
717 int line = tty->index; 720 int retval, line;
721 unsigned long flags;
718 722
719 if (line >= synclinkmp_device_count) { 723 line = tty->index;
724 if ((line < 0) || (line >= synclinkmp_device_count)) {
720 printk("%s(%d): open with invalid line #%d.\n", 725 printk("%s(%d): open with invalid line #%d.\n",
721 __FILE__,__LINE__,line); 726 __FILE__,__LINE__,line);
722 return -ENODEV; 727 return -ENODEV;
723 } 728 }
724 729
725 info = synclinkmp_device_list; 730 info = synclinkmp_device_list;
726 while (info && info->line != line) 731 while(info && info->line != line)
727 info = info->next_device; 732 info = info->next_device;
728 if (sanity_check(info, tty->name, "open")) 733 if (sanity_check(info, tty->name, "open"))
729 return -ENODEV; 734 return -ENODEV;
730 if (info->init_error) { 735 if ( info->init_error ) {
731 printk("%s(%d):%s device is not allocated, init error=%d\n", 736 printk("%s(%d):%s device is not allocated, init error=%d\n",
732 __FILE__, __LINE__, info->device_name, 737 __FILE__,__LINE__,info->device_name,info->init_error);
733 info->init_error);
734 return -ENODEV; 738 return -ENODEV;
735 } 739 }
736 740
737 tty->driver_data = info; 741 tty->driver_data = info;
738
739 return tty_port_install(&info->port, driver, tty);
740}
741
742/* Called when a port is opened. Init and enable port.
743 */
744static int open(struct tty_struct *tty, struct file *filp)
745{
746 SLMP_INFO *info = tty->driver_data;
747 unsigned long flags;
748 int retval;
749
750 info->port.tty = tty; 742 info->port.tty = tty;
751 743
752 if (debug_level >= DEBUG_LEVEL_INFO) 744 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -882,7 +874,7 @@ static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
882 874
883 /* Handle transition to B0 status */ 875 /* Handle transition to B0 status */
884 if (old_termios->c_cflag & CBAUD && 876 if (old_termios->c_cflag & CBAUD &&
885 !(tty->termios.c_cflag & CBAUD)) { 877 !(tty->termios->c_cflag & CBAUD)) {
886 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR); 878 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
887 spin_lock_irqsave(&info->lock,flags); 879 spin_lock_irqsave(&info->lock,flags);
888 set_signals(info); 880 set_signals(info);
@@ -891,9 +883,9 @@ static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
891 883
892 /* Handle transition away from B0 status */ 884 /* Handle transition away from B0 status */
893 if (!(old_termios->c_cflag & CBAUD) && 885 if (!(old_termios->c_cflag & CBAUD) &&
894 tty->termios.c_cflag & CBAUD) { 886 tty->termios->c_cflag & CBAUD) {
895 info->serial_signals |= SerialSignal_DTR; 887 info->serial_signals |= SerialSignal_DTR;
896 if (!(tty->termios.c_cflag & CRTSCTS) || 888 if (!(tty->termios->c_cflag & CRTSCTS) ||
897 !test_bit(TTY_THROTTLED, &tty->flags)) { 889 !test_bit(TTY_THROTTLED, &tty->flags)) {
898 info->serial_signals |= SerialSignal_RTS; 890 info->serial_signals |= SerialSignal_RTS;
899 } 891 }
@@ -904,7 +896,7 @@ static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
904 896
905 /* Handle turning off CRTSCTS */ 897 /* Handle turning off CRTSCTS */
906 if (old_termios->c_cflag & CRTSCTS && 898 if (old_termios->c_cflag & CRTSCTS &&
907 !(tty->termios.c_cflag & CRTSCTS)) { 899 !(tty->termios->c_cflag & CRTSCTS)) {
908 tty->hw_stopped = 0; 900 tty->hw_stopped = 0;
909 tx_release(tty); 901 tx_release(tty);
910 } 902 }
@@ -1482,7 +1474,7 @@ static void throttle(struct tty_struct * tty)
1482 if (I_IXOFF(tty)) 1474 if (I_IXOFF(tty))
1483 send_xchar(tty, STOP_CHAR(tty)); 1475 send_xchar(tty, STOP_CHAR(tty));
1484 1476
1485 if (tty->termios.c_cflag & CRTSCTS) { 1477 if (tty->termios->c_cflag & CRTSCTS) {
1486 spin_lock_irqsave(&info->lock,flags); 1478 spin_lock_irqsave(&info->lock,flags);
1487 info->serial_signals &= ~SerialSignal_RTS; 1479 info->serial_signals &= ~SerialSignal_RTS;
1488 set_signals(info); 1480 set_signals(info);
@@ -1511,7 +1503,7 @@ static void unthrottle(struct tty_struct * tty)
1511 send_xchar(tty, START_CHAR(tty)); 1503 send_xchar(tty, START_CHAR(tty));
1512 } 1504 }
1513 1505
1514 if (tty->termios.c_cflag & CRTSCTS) { 1506 if (tty->termios->c_cflag & CRTSCTS) {
1515 spin_lock_irqsave(&info->lock,flags); 1507 spin_lock_irqsave(&info->lock,flags);
1516 info->serial_signals |= SerialSignal_RTS; 1508 info->serial_signals |= SerialSignal_RTS;
1517 set_signals(info); 1509 set_signals(info);
@@ -2500,7 +2492,7 @@ static void isr_io_pin( SLMP_INFO *info, u16 status )
2500 } 2492 }
2501 } 2493 }
2502 2494
2503 if (tty_port_cts_enabled(&info->port) && 2495 if ( (info->port.flags & ASYNC_CTS_FLOW) &&
2504 (status & MISCSTATUS_CTS_LATCHED) ) { 2496 (status & MISCSTATUS_CTS_LATCHED) ) {
2505 if ( info->port.tty ) { 2497 if ( info->port.tty ) {
2506 if (info->port.tty->hw_stopped) { 2498 if (info->port.tty->hw_stopped) {
@@ -2717,7 +2709,7 @@ static void shutdown(SLMP_INFO * info)
2717 2709
2718 reset_port(info); 2710 reset_port(info);
2719 2711
2720 if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) { 2712 if (!info->port.tty || info->port.tty->termios->c_cflag & HUPCL) {
2721 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS); 2713 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
2722 set_signals(info); 2714 set_signals(info);
2723 } 2715 }
@@ -2758,7 +2750,7 @@ static void program_hw(SLMP_INFO *info)
2758 2750
2759 get_signals(info); 2751 get_signals(info);
2760 2752
2761 if (info->netcount || (info->port.tty && info->port.tty->termios.c_cflag & CREAD) ) 2753 if (info->netcount || (info->port.tty && info->port.tty->termios->c_cflag & CREAD) )
2762 rx_start(info); 2754 rx_start(info);
2763 2755
2764 spin_unlock_irqrestore(&info->lock,flags); 2756 spin_unlock_irqrestore(&info->lock,flags);
@@ -2771,14 +2763,14 @@ static void change_params(SLMP_INFO *info)
2771 unsigned cflag; 2763 unsigned cflag;
2772 int bits_per_char; 2764 int bits_per_char;
2773 2765
2774 if (!info->port.tty) 2766 if (!info->port.tty || !info->port.tty->termios)
2775 return; 2767 return;
2776 2768
2777 if (debug_level >= DEBUG_LEVEL_INFO) 2769 if (debug_level >= DEBUG_LEVEL_INFO)
2778 printk("%s(%d):%s change_params()\n", 2770 printk("%s(%d):%s change_params()\n",
2779 __FILE__,__LINE__, info->device_name ); 2771 __FILE__,__LINE__, info->device_name );
2780 2772
2781 cflag = info->port.tty->termios.c_cflag; 2773 cflag = info->port.tty->termios->c_cflag;
2782 2774
2783 /* if B0 rate (hangup) specified then negate DTR and RTS */ 2775 /* if B0 rate (hangup) specified then negate DTR and RTS */
2784 /* otherwise assert DTR and RTS */ 2776 /* otherwise assert DTR and RTS */
@@ -3315,7 +3307,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3315 return 0; 3307 return 0;
3316 } 3308 }
3317 3309
3318 if (tty->termios.c_cflag & CLOCAL) 3310 if (tty->termios->c_cflag & CLOCAL)
3319 do_clocal = true; 3311 do_clocal = true;
3320 3312
3321 /* Wait for carrier detect and the line to become 3313 /* Wait for carrier detect and the line to become
@@ -3341,7 +3333,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3341 port->blocked_open++; 3333 port->blocked_open++;
3342 3334
3343 while (1) { 3335 while (1) {
3344 if (tty->termios.c_cflag & CBAUD) 3336 if (tty->termios->c_cflag & CBAUD)
3345 tty_port_raise_dtr_rts(port); 3337 tty_port_raise_dtr_rts(port);
3346 3338
3347 set_current_state(TASK_INTERRUPTIBLE); 3339 set_current_state(TASK_INTERRUPTIBLE);
@@ -3366,9 +3358,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3366 printk("%s(%d):%s block_til_ready() count=%d\n", 3358 printk("%s(%d):%s block_til_ready() count=%d\n",
3367 __FILE__,__LINE__, tty->driver->name, port->count ); 3359 __FILE__,__LINE__, tty->driver->name, port->count );
3368 3360
3369 tty_unlock(tty); 3361 tty_unlock();
3370 schedule(); 3362 schedule();
3371 tty_lock(tty); 3363 tty_lock();
3372 } 3364 }
3373 3365
3374 set_current_state(TASK_RUNNING); 3366 set_current_state(TASK_RUNNING);
@@ -3843,10 +3835,8 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
3843 for ( port = 0; port < SCA_MAX_PORTS; ++port ) { 3835 for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
3844 port_array[port] = alloc_dev(adapter_num,port,pdev); 3836 port_array[port] = alloc_dev(adapter_num,port,pdev);
3845 if( port_array[port] == NULL ) { 3837 if( port_array[port] == NULL ) {
3846 for (--port; port >= 0; --port) { 3838 for ( --port; port >= 0; --port )
3847 tty_port_destroy(&port_array[port]->port);
3848 kfree(port_array[port]); 3839 kfree(port_array[port]);
3849 }
3850 return; 3840 return;
3851 } 3841 }
3852 } 3842 }
@@ -3892,7 +3882,6 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
3892} 3882}
3893 3883
3894static const struct tty_operations ops = { 3884static const struct tty_operations ops = {
3895 .install = install,
3896 .open = open, 3885 .open = open,
3897 .close = close, 3886 .close = close,
3898 .write = write, 3887 .write = write,
@@ -3955,7 +3944,6 @@ static void synclinkmp_cleanup(void)
3955 } 3944 }
3956 tmp = info; 3945 tmp = info;
3957 info = info->next_device; 3946 info = info->next_device;
3958 tty_port_destroy(&tmp->port);
3959 kfree(tmp); 3947 kfree(tmp);
3960 } 3948 }
3961 3949
@@ -3989,6 +3977,7 @@ static int __init synclinkmp_init(void)
3989 3977
3990 /* Initialize the tty_driver structure */ 3978 /* Initialize the tty_driver structure */
3991 3979
3980 serial_driver->owner = THIS_MODULE;
3992 serial_driver->driver_name = "synclinkmp"; 3981 serial_driver->driver_name = "synclinkmp";
3993 serial_driver->name = "ttySLM"; 3982 serial_driver->name = "ttySLM";
3994 serial_driver->major = ttymajor; 3983 serial_driver->major = ttymajor;
@@ -4961,7 +4950,7 @@ CheckAgain:
4961 4950
4962 if ( debug_level >= DEBUG_LEVEL_DATA ) 4951 if ( debug_level >= DEBUG_LEVEL_DATA )
4963 trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr, 4952 trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr,
4964 min_t(unsigned int, framesize, SCABUFSIZE), 0); 4953 min_t(int, framesize,SCABUFSIZE),0);
4965 4954
4966 if (framesize) { 4955 if (framesize) {
4967 if (framesize > info->max_frame_size) 4956 if (framesize > info->max_frame_size)
@@ -5026,14 +5015,14 @@ static void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int co
5026 SCADESC_EX *desc_ex; 5015 SCADESC_EX *desc_ex;
5027 5016
5028 if ( debug_level >= DEBUG_LEVEL_DATA ) 5017 if ( debug_level >= DEBUG_LEVEL_DATA )
5029 trace_block(info, buf, min_t(unsigned int, count, SCABUFSIZE), 1); 5018 trace_block(info,buf, min_t(int, count,SCABUFSIZE), 1);
5030 5019
5031 /* Copy source buffer to one or more DMA buffers, starting with 5020 /* Copy source buffer to one or more DMA buffers, starting with
5032 * the first transmit dma buffer. 5021 * the first transmit dma buffer.
5033 */ 5022 */
5034 for(i=0;;) 5023 for(i=0;;)
5035 { 5024 {
5036 copy_count = min_t(unsigned int, count, SCABUFSIZE); 5025 copy_count = min_t(unsigned short,count,SCABUFSIZE);
5037 5026
5038 desc = &info->tx_buf_list[i]; 5027 desc = &info->tx_buf_list[i];
5039 desc_ex = &info->tx_buf_list_ex[i]; 5028 desc_ex = &info->tx_buf_list_ex[i];
@@ -5595,7 +5584,7 @@ static void write_control_reg(SLMP_INFO * info)
5595} 5584}
5596 5585
5597 5586
5598static int synclinkmp_init_one (struct pci_dev *dev, 5587static int __devinit synclinkmp_init_one (struct pci_dev *dev,
5599 const struct pci_device_id *ent) 5588 const struct pci_device_id *ent)
5600{ 5589{
5601 if (pci_enable_device(dev)) { 5590 if (pci_enable_device(dev)) {
@@ -5606,6 +5595,6 @@ static int synclinkmp_init_one (struct pci_dev *dev,
5606 return 0; 5595 return 0;
5607} 5596}
5608 5597
5609static void synclinkmp_remove_one (struct pci_dev *dev) 5598static void __devexit synclinkmp_remove_one (struct pci_dev *dev)
5610{ 5599{
5611} 5600}
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index b3c4a250ff8..43db715f150 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -32,6 +32,7 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/suspend.h> 33#include <linux/suspend.h>
34#include <linux/writeback.h> 34#include <linux/writeback.h>
35#include <linux/buffer_head.h> /* for fsync_bdev() */
35#include <linux/swap.h> 36#include <linux/swap.h>
36#include <linux/spinlock.h> 37#include <linux/spinlock.h>
37#include <linux/vt_kern.h> 38#include <linux/vt_kern.h>
@@ -40,7 +41,6 @@
40#include <linux/oom.h> 41#include <linux/oom.h>
41#include <linux/slab.h> 42#include <linux/slab.h>
42#include <linux/input.h> 43#include <linux/input.h>
43#include <linux/uaccess.h>
44 44
45#include <asm/ptrace.h> 45#include <asm/ptrace.h>
46#include <asm/irq_regs.h> 46#include <asm/irq_regs.h>
@@ -110,9 +110,11 @@ static struct sysrq_key_op sysrq_SAK_op = {
110#ifdef CONFIG_VT 110#ifdef CONFIG_VT
111static void sysrq_handle_unraw(int key) 111static void sysrq_handle_unraw(int key)
112{ 112{
113 vt_reset_unicode(fg_console); 113 struct kbd_struct *kbd = &kbd_table[fg_console];
114}
115 114
115 if (kbd)
116 kbd->kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE;
117}
116static struct sysrq_key_op sysrq_unraw_op = { 118static struct sysrq_key_op sysrq_unraw_op = {
117 .handler = sysrq_handle_unraw, 119 .handler = sysrq_handle_unraw,
118 .help_msg = "unRaw", 120 .help_msg = "unRaw",
@@ -320,16 +322,11 @@ static void send_sig_all(int sig)
320{ 322{
321 struct task_struct *p; 323 struct task_struct *p;
322 324
323 read_lock(&tasklist_lock);
324 for_each_process(p) { 325 for_each_process(p) {
325 if (p->flags & PF_KTHREAD) 326 if (p->mm && !is_global_init(p))
326 continue; 327 /* Not swapper, init nor kernel thread */
327 if (is_global_init(p)) 328 force_sig(sig, p);
328 continue;
329
330 do_send_sig_info(sig, SEND_SIG_FORCED, p, true);
331 } 329 }
332 read_unlock(&tasklist_lock);
333} 330}
334 331
335static void sysrq_handle_term(int key) 332static void sysrq_handle_term(int key)
@@ -346,8 +343,7 @@ static struct sysrq_key_op sysrq_term_op = {
346 343
347static void moom_callback(struct work_struct *ignored) 344static void moom_callback(struct work_struct *ignored)
348{ 345{
349 out_of_memory(node_zonelist(first_online_node, GFP_KERNEL), GFP_KERNEL, 346 out_of_memory(node_zonelist(0, GFP_KERNEL), GFP_KERNEL, 0, NULL);
350 0, NULL, true);
351} 347}
352 348
353static DECLARE_WORK(moom_work, moom_callback); 349static DECLARE_WORK(moom_work, moom_callback);
@@ -453,7 +449,6 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
453 NULL, /* v */ 449 NULL, /* v */
454 &sysrq_showstate_blocked_op, /* w */ 450 &sysrq_showstate_blocked_op, /* w */
455 /* x: May be registered on ppc/powerpc for xmon */ 451 /* x: May be registered on ppc/powerpc for xmon */
456 /* x: May be registered on sparc64 for global PMU dump */
457 NULL, /* x */ 452 NULL, /* x */
458 /* y: May be registered on sparc64 for global register dump */ 453 /* y: May be registered on sparc64 for global register dump */
459 NULL, /* y */ 454 NULL, /* y */
diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c
index 6953dc82850..7c586692062 100644
--- a/drivers/tty/tty_audit.c
+++ b/drivers/tty/tty_audit.c
@@ -23,7 +23,7 @@ struct tty_audit_buf {
23}; 23};
24 24
25static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor, 25static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor,
26 unsigned icanon) 26 int icanon)
27{ 27{
28 struct tty_audit_buf *buf; 28 struct tty_audit_buf *buf;
29 29
@@ -61,7 +61,7 @@ static void tty_audit_buf_put(struct tty_audit_buf *buf)
61} 61}
62 62
63static void tty_audit_log(const char *description, struct task_struct *tsk, 63static void tty_audit_log(const char *description, struct task_struct *tsk,
64 kuid_t loginuid, unsigned sessionid, int major, 64 uid_t loginuid, unsigned sessionid, int major,
65 int minor, unsigned char *data, size_t size) 65 int minor, unsigned char *data, size_t size)
66{ 66{
67 struct audit_buffer *ab; 67 struct audit_buffer *ab;
@@ -69,14 +69,11 @@ static void tty_audit_log(const char *description, struct task_struct *tsk,
69 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY); 69 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY);
70 if (ab) { 70 if (ab) {
71 char name[sizeof(tsk->comm)]; 71 char name[sizeof(tsk->comm)];
72 kuid_t uid = task_uid(tsk); 72 uid_t uid = task_uid(tsk);
73 73
74 audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u " 74 audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u "
75 "major=%d minor=%d comm=", description, 75 "major=%d minor=%d comm=", description,
76 tsk->pid, 76 tsk->pid, uid, loginuid, sessionid,
77 from_kuid(&init_user_ns, uid),
78 from_kuid(&init_user_ns, loginuid),
79 sessionid,
80 major, minor); 77 major, minor);
81 get_task_comm(name, tsk); 78 get_task_comm(name, tsk);
82 audit_log_untrustedstring(ab, name); 79 audit_log_untrustedstring(ab, name);
@@ -92,7 +89,7 @@ static void tty_audit_log(const char *description, struct task_struct *tsk,
92 * Generate an audit message from the contents of @buf, which is owned by 89 * Generate an audit message from the contents of @buf, which is owned by
93 * @tsk with @loginuid. @buf->mutex must be locked. 90 * @tsk with @loginuid. @buf->mutex must be locked.
94 */ 91 */
95static void tty_audit_buf_push(struct task_struct *tsk, kuid_t loginuid, 92static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid,
96 unsigned int sessionid, 93 unsigned int sessionid,
97 struct tty_audit_buf *buf) 94 struct tty_audit_buf *buf)
98{ 95{
@@ -115,7 +112,7 @@ static void tty_audit_buf_push(struct task_struct *tsk, kuid_t loginuid,
115 */ 112 */
116static void tty_audit_buf_push_current(struct tty_audit_buf *buf) 113static void tty_audit_buf_push_current(struct tty_audit_buf *buf)
117{ 114{
118 kuid_t auid = audit_get_loginuid(current); 115 uid_t auid = audit_get_loginuid(current);
119 unsigned int sessionid = audit_get_sessionid(current); 116 unsigned int sessionid = audit_get_sessionid(current);
120 tty_audit_buf_push(current, auid, sessionid, buf); 117 tty_audit_buf_push(current, auid, sessionid, buf);
121} 118}
@@ -182,7 +179,7 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
182 } 179 }
183 180
184 if (should_audit && audit_enabled) { 181 if (should_audit && audit_enabled) {
185 kuid_t auid; 182 uid_t auid;
186 unsigned int sessionid; 183 unsigned int sessionid;
187 184
188 auid = audit_get_loginuid(current); 185 auid = audit_get_loginuid(current);
@@ -202,7 +199,7 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
202 * reference to the tty audit buffer if available. 199 * reference to the tty audit buffer if available.
203 * Flush the buffer or return an appropriate error code. 200 * Flush the buffer or return an appropriate error code.
204 */ 201 */
205int tty_audit_push_task(struct task_struct *tsk, kuid_t loginuid, u32 sessionid) 202int tty_audit_push_task(struct task_struct *tsk, uid_t loginuid, u32 sessionid)
206{ 203{
207 struct tty_audit_buf *buf = ERR_PTR(-EPERM); 204 struct tty_audit_buf *buf = ERR_PTR(-EPERM);
208 unsigned long flags; 205 unsigned long flags;
@@ -239,8 +236,7 @@ int tty_audit_push_task(struct task_struct *tsk, kuid_t loginuid, u32 sessionid)
239 * if TTY auditing is disabled or out of memory. Otherwise, return a new 236 * if TTY auditing is disabled or out of memory. Otherwise, return a new
240 * reference to the buffer. 237 * reference to the buffer.
241 */ 238 */
242static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty, 239static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty)
243 unsigned icanon)
244{ 240{
245 struct tty_audit_buf *buf, *buf2; 241 struct tty_audit_buf *buf, *buf2;
246 242
@@ -258,7 +254,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
258 254
259 buf2 = tty_audit_buf_alloc(tty->driver->major, 255 buf2 = tty_audit_buf_alloc(tty->driver->major,
260 tty->driver->minor_start + tty->index, 256 tty->driver->minor_start + tty->index,
261 icanon); 257 tty->icanon);
262 if (buf2 == NULL) { 258 if (buf2 == NULL) {
263 audit_log_lost("out of memory in TTY auditing"); 259 audit_log_lost("out of memory in TTY auditing");
264 return NULL; 260 return NULL;
@@ -288,7 +284,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
288 * Audit @data of @size from @tty, if necessary. 284 * Audit @data of @size from @tty, if necessary.
289 */ 285 */
290void tty_audit_add_data(struct tty_struct *tty, unsigned char *data, 286void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
291 size_t size, unsigned icanon) 287 size_t size)
292{ 288{
293 struct tty_audit_buf *buf; 289 struct tty_audit_buf *buf;
294 int major, minor; 290 int major, minor;
@@ -300,7 +296,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
300 && tty->driver->subtype == PTY_TYPE_MASTER) 296 && tty->driver->subtype == PTY_TYPE_MASTER)
301 return; 297 return;
302 298
303 buf = tty_audit_buf_get(tty, icanon); 299 buf = tty_audit_buf_get(tty);
304 if (!buf) 300 if (!buf)
305 return; 301 return;
306 302
@@ -308,11 +304,11 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
308 major = tty->driver->major; 304 major = tty->driver->major;
309 minor = tty->driver->minor_start + tty->index; 305 minor = tty->driver->minor_start + tty->index;
310 if (buf->major != major || buf->minor != minor 306 if (buf->major != major || buf->minor != minor
311 || buf->icanon != icanon) { 307 || buf->icanon != tty->icanon) {
312 tty_audit_buf_push_current(buf); 308 tty_audit_buf_push_current(buf);
313 buf->major = major; 309 buf->major = major;
314 buf->minor = minor; 310 buf->minor = minor;
315 buf->icanon = icanon; 311 buf->icanon = tty->icanon;
316 } 312 }
317 do { 313 do {
318 size_t run; 314 size_t run;
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 45d916198f7..6c9b7cd6778 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -27,21 +27,19 @@
27 * Locking: none 27 * Locking: none
28 */ 28 */
29 29
30void tty_buffer_free_all(struct tty_port *port) 30void tty_buffer_free_all(struct tty_struct *tty)
31{ 31{
32 struct tty_bufhead *buf = &port->buf;
33 struct tty_buffer *thead; 32 struct tty_buffer *thead;
34 33 while ((thead = tty->buf.head) != NULL) {
35 while ((thead = buf->head) != NULL) { 34 tty->buf.head = thead->next;
36 buf->head = thead->next;
37 kfree(thead); 35 kfree(thead);
38 } 36 }
39 while ((thead = buf->free) != NULL) { 37 while ((thead = tty->buf.free) != NULL) {
40 buf->free = thead->next; 38 tty->buf.free = thead->next;
41 kfree(thead); 39 kfree(thead);
42 } 40 }
43 buf->tail = NULL; 41 tty->buf.tail = NULL;
44 buf->memory_used = 0; 42 tty->buf.memory_used = 0;
45} 43}
46 44
47/** 45/**
@@ -56,11 +54,11 @@ void tty_buffer_free_all(struct tty_port *port)
56 * Locking: Caller must hold tty->buf.lock 54 * Locking: Caller must hold tty->buf.lock
57 */ 55 */
58 56
59static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size) 57static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
60{ 58{
61 struct tty_buffer *p; 59 struct tty_buffer *p;
62 60
63 if (port->buf.memory_used + size > 65536) 61 if (tty->buf.memory_used + size > 65536)
64 return NULL; 62 return NULL;
65 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC); 63 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
66 if (p == NULL) 64 if (p == NULL)
@@ -72,7 +70,7 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size)
72 p->read = 0; 70 p->read = 0;
73 p->char_buf_ptr = (char *)(p->data); 71 p->char_buf_ptr = (char *)(p->data);
74 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size; 72 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
75 port->buf.memory_used += size; 73 tty->buf.memory_used += size;
76 return p; 74 return p;
77} 75}
78 76
@@ -87,19 +85,17 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size)
87 * Locking: Caller must hold tty->buf.lock 85 * Locking: Caller must hold tty->buf.lock
88 */ 86 */
89 87
90static void tty_buffer_free(struct tty_port *port, struct tty_buffer *b) 88static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
91{ 89{
92 struct tty_bufhead *buf = &port->buf;
93
94 /* Dumb strategy for now - should keep some stats */ 90 /* Dumb strategy for now - should keep some stats */
95 buf->memory_used -= b->size; 91 tty->buf.memory_used -= b->size;
96 WARN_ON(buf->memory_used < 0); 92 WARN_ON(tty->buf.memory_used < 0);
97 93
98 if (b->size >= 512) 94 if (b->size >= 512)
99 kfree(b); 95 kfree(b);
100 else { 96 else {
101 b->next = buf->free; 97 b->next = tty->buf.free;
102 buf->free = b; 98 tty->buf.free = b;
103 } 99 }
104} 100}
105 101
@@ -114,16 +110,15 @@ static void tty_buffer_free(struct tty_port *port, struct tty_buffer *b)
114 * Locking: Caller must hold tty->buf.lock 110 * Locking: Caller must hold tty->buf.lock
115 */ 111 */
116 112
117static void __tty_buffer_flush(struct tty_port *port) 113static void __tty_buffer_flush(struct tty_struct *tty)
118{ 114{
119 struct tty_bufhead *buf = &port->buf;
120 struct tty_buffer *thead; 115 struct tty_buffer *thead;
121 116
122 while ((thead = buf->head) != NULL) { 117 while ((thead = tty->buf.head) != NULL) {
123 buf->head = thead->next; 118 tty->buf.head = thead->next;
124 tty_buffer_free(port, thead); 119 tty_buffer_free(tty, thead);
125 } 120 }
126 buf->tail = NULL; 121 tty->buf.tail = NULL;
127} 122}
128 123
129/** 124/**
@@ -139,24 +134,21 @@ static void __tty_buffer_flush(struct tty_port *port)
139 134
140void tty_buffer_flush(struct tty_struct *tty) 135void tty_buffer_flush(struct tty_struct *tty)
141{ 136{
142 struct tty_port *port = tty->port;
143 struct tty_bufhead *buf = &port->buf;
144 unsigned long flags; 137 unsigned long flags;
145 138 spin_lock_irqsave(&tty->buf.lock, flags);
146 spin_lock_irqsave(&buf->lock, flags);
147 139
148 /* If the data is being pushed to the tty layer then we can't 140 /* If the data is being pushed to the tty layer then we can't
149 process it here. Instead set a flag and the flush_to_ldisc 141 process it here. Instead set a flag and the flush_to_ldisc
150 path will process the flush request before it exits */ 142 path will process the flush request before it exits */
151 if (test_bit(TTYP_FLUSHING, &port->iflags)) { 143 if (test_bit(TTY_FLUSHING, &tty->flags)) {
152 set_bit(TTYP_FLUSHPENDING, &port->iflags); 144 set_bit(TTY_FLUSHPENDING, &tty->flags);
153 spin_unlock_irqrestore(&buf->lock, flags); 145 spin_unlock_irqrestore(&tty->buf.lock, flags);
154 wait_event(tty->read_wait, 146 wait_event(tty->read_wait,
155 test_bit(TTYP_FLUSHPENDING, &port->iflags) == 0); 147 test_bit(TTY_FLUSHPENDING, &tty->flags) == 0);
156 return; 148 return;
157 } else 149 } else
158 __tty_buffer_flush(port); 150 __tty_buffer_flush(tty);
159 spin_unlock_irqrestore(&buf->lock, flags); 151 spin_unlock_irqrestore(&tty->buf.lock, flags);
160} 152}
161 153
162/** 154/**
@@ -171,9 +163,9 @@ void tty_buffer_flush(struct tty_struct *tty)
171 * Locking: Caller must hold tty->buf.lock 163 * Locking: Caller must hold tty->buf.lock
172 */ 164 */
173 165
174static struct tty_buffer *tty_buffer_find(struct tty_port *port, size_t size) 166static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
175{ 167{
176 struct tty_buffer **tbh = &port->buf.free; 168 struct tty_buffer **tbh = &tty->buf.free;
177 while ((*tbh) != NULL) { 169 while ((*tbh) != NULL) {
178 struct tty_buffer *t = *tbh; 170 struct tty_buffer *t = *tbh;
179 if (t->size >= size) { 171 if (t->size >= size) {
@@ -182,78 +174,60 @@ static struct tty_buffer *tty_buffer_find(struct tty_port *port, size_t size)
182 t->used = 0; 174 t->used = 0;
183 t->commit = 0; 175 t->commit = 0;
184 t->read = 0; 176 t->read = 0;
185 port->buf.memory_used += t->size; 177 tty->buf.memory_used += t->size;
186 return t; 178 return t;
187 } 179 }
188 tbh = &((*tbh)->next); 180 tbh = &((*tbh)->next);
189 } 181 }
190 /* Round the buffer size out */ 182 /* Round the buffer size out */
191 size = (size + 0xFF) & ~0xFF; 183 size = (size + 0xFF) & ~0xFF;
192 return tty_buffer_alloc(port, size); 184 return tty_buffer_alloc(tty, size);
193 /* Should possibly check if this fails for the largest buffer we 185 /* Should possibly check if this fails for the largest buffer we
194 have queued and recycle that ? */ 186 have queued and recycle that ? */
195} 187}
188
196/** 189/**
197 * __tty_buffer_request_room - grow tty buffer if needed 190 * tty_buffer_request_room - grow tty buffer if needed
198 * @tty: tty structure 191 * @tty: tty structure
199 * @size: size desired 192 * @size: size desired
200 * 193 *
201 * Make at least size bytes of linear space available for the tty 194 * Make at least size bytes of linear space available for the tty
202 * buffer. If we fail return the size we managed to find. 195 * buffer. If we fail return the size we managed to find.
203 * Locking: Caller must hold port->buf.lock 196 *
197 * Locking: Takes tty->buf.lock
204 */ 198 */
205static int __tty_buffer_request_room(struct tty_port *port, size_t size) 199int tty_buffer_request_room(struct tty_struct *tty, size_t size)
206{ 200{
207 struct tty_bufhead *buf = &port->buf;
208 struct tty_buffer *b, *n; 201 struct tty_buffer *b, *n;
209 int left; 202 int left;
203 unsigned long flags;
204
205 spin_lock_irqsave(&tty->buf.lock, flags);
206
210 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to 207 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to
211 remove this conditional if its worth it. This would be invisible 208 remove this conditional if its worth it. This would be invisible
212 to the callers */ 209 to the callers */
213 b = buf->tail; 210 if ((b = tty->buf.tail) != NULL)
214 if (b != NULL)
215 left = b->size - b->used; 211 left = b->size - b->used;
216 else 212 else
217 left = 0; 213 left = 0;
218 214
219 if (left < size) { 215 if (left < size) {
220 /* This is the slow path - looking for new buffers to use */ 216 /* This is the slow path - looking for new buffers to use */
221 if ((n = tty_buffer_find(port, size)) != NULL) { 217 if ((n = tty_buffer_find(tty, size)) != NULL) {
222 if (b != NULL) { 218 if (b != NULL) {
223 b->next = n; 219 b->next = n;
224 b->commit = b->used; 220 b->commit = b->used;
225 } else 221 } else
226 buf->head = n; 222 tty->buf.head = n;
227 buf->tail = n; 223 tty->buf.tail = n;
228 } else 224 } else
229 size = left; 225 size = left;
230 } 226 }
231 227
228 spin_unlock_irqrestore(&tty->buf.lock, flags);
232 return size; 229 return size;
233} 230}
234
235
236/**
237 * tty_buffer_request_room - grow tty buffer if needed
238 * @tty: tty structure
239 * @size: size desired
240 *
241 * Make at least size bytes of linear space available for the tty
242 * buffer. If we fail return the size we managed to find.
243 *
244 * Locking: Takes port->buf.lock
245 */
246int tty_buffer_request_room(struct tty_struct *tty, size_t size)
247{
248 struct tty_port *port = tty->port;
249 unsigned long flags;
250 int length;
251
252 spin_lock_irqsave(&port->buf.lock, flags);
253 length = __tty_buffer_request_room(port, size);
254 spin_unlock_irqrestore(&port->buf.lock, flags);
255 return length;
256}
257EXPORT_SYMBOL_GPL(tty_buffer_request_room); 231EXPORT_SYMBOL_GPL(tty_buffer_request_room);
258 232
259/** 233/**
@@ -266,32 +240,23 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room);
266 * Queue a series of bytes to the tty buffering. All the characters 240 * Queue a series of bytes to the tty buffering. All the characters
267 * passed are marked with the supplied flag. Returns the number added. 241 * passed are marked with the supplied flag. Returns the number added.
268 * 242 *
269 * Locking: Called functions may take port->buf.lock 243 * Locking: Called functions may take tty->buf.lock
270 */ 244 */
271 245
272int tty_insert_flip_string_fixed_flag(struct tty_struct *tty, 246int tty_insert_flip_string_fixed_flag(struct tty_struct *tty,
273 const unsigned char *chars, char flag, size_t size) 247 const unsigned char *chars, char flag, size_t size)
274{ 248{
275 struct tty_bufhead *buf = &tty->port->buf;
276 int copied = 0; 249 int copied = 0;
277 do { 250 do {
278 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 251 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
279 int space; 252 int space = tty_buffer_request_room(tty, goal);
280 unsigned long flags; 253 struct tty_buffer *tb = tty->buf.tail;
281 struct tty_buffer *tb;
282
283 spin_lock_irqsave(&buf->lock, flags);
284 space = __tty_buffer_request_room(tty->port, goal);
285 tb = buf->tail;
286 /* If there is no space then tb may be NULL */ 254 /* If there is no space then tb may be NULL */
287 if (unlikely(space == 0)) { 255 if (unlikely(space == 0))
288 spin_unlock_irqrestore(&buf->lock, flags);
289 break; 256 break;
290 }
291 memcpy(tb->char_buf_ptr + tb->used, chars, space); 257 memcpy(tb->char_buf_ptr + tb->used, chars, space);
292 memset(tb->flag_buf_ptr + tb->used, flag, space); 258 memset(tb->flag_buf_ptr + tb->used, flag, space);
293 tb->used += space; 259 tb->used += space;
294 spin_unlock_irqrestore(&buf->lock, flags);
295 copied += space; 260 copied += space;
296 chars += space; 261 chars += space;
297 /* There is a small chance that we need to split the data over 262 /* There is a small chance that we need to split the data over
@@ -312,32 +277,23 @@ EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
312 * the flags array indicates the status of the character. Returns the 277 * the flags array indicates the status of the character. Returns the
313 * number added. 278 * number added.
314 * 279 *
315 * Locking: Called functions may take port->buf.lock 280 * Locking: Called functions may take tty->buf.lock
316 */ 281 */
317 282
318int tty_insert_flip_string_flags(struct tty_struct *tty, 283int tty_insert_flip_string_flags(struct tty_struct *tty,
319 const unsigned char *chars, const char *flags, size_t size) 284 const unsigned char *chars, const char *flags, size_t size)
320{ 285{
321 struct tty_bufhead *buf = &tty->port->buf;
322 int copied = 0; 286 int copied = 0;
323 do { 287 do {
324 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 288 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
325 int space; 289 int space = tty_buffer_request_room(tty, goal);
326 unsigned long __flags; 290 struct tty_buffer *tb = tty->buf.tail;
327 struct tty_buffer *tb;
328
329 spin_lock_irqsave(&buf->lock, __flags);
330 space = __tty_buffer_request_room(tty->port, goal);
331 tb = buf->tail;
332 /* If there is no space then tb may be NULL */ 291 /* If there is no space then tb may be NULL */
333 if (unlikely(space == 0)) { 292 if (unlikely(space == 0))
334 spin_unlock_irqrestore(&buf->lock, __flags);
335 break; 293 break;
336 }
337 memcpy(tb->char_buf_ptr + tb->used, chars, space); 294 memcpy(tb->char_buf_ptr + tb->used, chars, space);
338 memcpy(tb->flag_buf_ptr + tb->used, flags, space); 295 memcpy(tb->flag_buf_ptr + tb->used, flags, space);
339 tb->used += space; 296 tb->used += space;
340 spin_unlock_irqrestore(&buf->lock, __flags);
341 copied += space; 297 copied += space;
342 chars += space; 298 chars += space;
343 flags += space; 299 flags += space;
@@ -355,23 +311,18 @@ EXPORT_SYMBOL(tty_insert_flip_string_flags);
355 * Takes any pending buffers and transfers their ownership to the 311 * Takes any pending buffers and transfers their ownership to the
356 * ldisc side of the queue. It then schedules those characters for 312 * ldisc side of the queue. It then schedules those characters for
357 * processing by the line discipline. 313 * processing by the line discipline.
358 * Note that this function can only be used when the low_latency flag
359 * is unset. Otherwise the workqueue won't be flushed.
360 * 314 *
361 * Locking: Takes port->buf.lock 315 * Locking: Takes tty->buf.lock
362 */ 316 */
363 317
364void tty_schedule_flip(struct tty_struct *tty) 318void tty_schedule_flip(struct tty_struct *tty)
365{ 319{
366 struct tty_bufhead *buf = &tty->port->buf;
367 unsigned long flags; 320 unsigned long flags;
368 WARN_ON(tty->low_latency); 321 spin_lock_irqsave(&tty->buf.lock, flags);
369 322 if (tty->buf.tail != NULL)
370 spin_lock_irqsave(&buf->lock, flags); 323 tty->buf.tail->commit = tty->buf.tail->used;
371 if (buf->tail != NULL) 324 spin_unlock_irqrestore(&tty->buf.lock, flags);
372 buf->tail->commit = buf->tail->used; 325 schedule_work(&tty->buf.work);
373 spin_unlock_irqrestore(&buf->lock, flags);
374 schedule_work(&buf->work);
375} 326}
376EXPORT_SYMBOL(tty_schedule_flip); 327EXPORT_SYMBOL(tty_schedule_flip);
377 328
@@ -387,27 +338,19 @@ EXPORT_SYMBOL(tty_schedule_flip);
387 * that need their own block copy routines into the buffer. There is no 338 * that need their own block copy routines into the buffer. There is no
388 * guarantee the buffer is a DMA target! 339 * guarantee the buffer is a DMA target!
389 * 340 *
390 * Locking: May call functions taking port->buf.lock 341 * Locking: May call functions taking tty->buf.lock
391 */ 342 */
392 343
393int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, 344int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,
394 size_t size) 345 size_t size)
395{ 346{
396 struct tty_bufhead *buf = &tty->port->buf; 347 int space = tty_buffer_request_room(tty, size);
397 int space;
398 unsigned long flags;
399 struct tty_buffer *tb;
400
401 spin_lock_irqsave(&buf->lock, flags);
402 space = __tty_buffer_request_room(tty->port, size);
403
404 tb = buf->tail;
405 if (likely(space)) { 348 if (likely(space)) {
349 struct tty_buffer *tb = tty->buf.tail;
406 *chars = tb->char_buf_ptr + tb->used; 350 *chars = tb->char_buf_ptr + tb->used;
407 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); 351 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
408 tb->used += space; 352 tb->used += space;
409 } 353 }
410 spin_unlock_irqrestore(&buf->lock, flags);
411 return space; 354 return space;
412} 355}
413EXPORT_SYMBOL_GPL(tty_prepare_flip_string); 356EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
@@ -425,27 +368,19 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
425 * that need their own block copy routines into the buffer. There is no 368 * that need their own block copy routines into the buffer. There is no
426 * guarantee the buffer is a DMA target! 369 * guarantee the buffer is a DMA target!
427 * 370 *
428 * Locking: May call functions taking port->buf.lock 371 * Locking: May call functions taking tty->buf.lock
429 */ 372 */
430 373
431int tty_prepare_flip_string_flags(struct tty_struct *tty, 374int tty_prepare_flip_string_flags(struct tty_struct *tty,
432 unsigned char **chars, char **flags, size_t size) 375 unsigned char **chars, char **flags, size_t size)
433{ 376{
434 struct tty_bufhead *buf = &tty->port->buf; 377 int space = tty_buffer_request_room(tty, size);
435 int space;
436 unsigned long __flags;
437 struct tty_buffer *tb;
438
439 spin_lock_irqsave(&buf->lock, __flags);
440 space = __tty_buffer_request_room(tty->port, size);
441
442 tb = buf->tail;
443 if (likely(space)) { 378 if (likely(space)) {
379 struct tty_buffer *tb = tty->buf.tail;
444 *chars = tb->char_buf_ptr + tb->used; 380 *chars = tb->char_buf_ptr + tb->used;
445 *flags = tb->flag_buf_ptr + tb->used; 381 *flags = tb->flag_buf_ptr + tb->used;
446 tb->used += space; 382 tb->used += space;
447 } 383 }
448 spin_unlock_irqrestore(&buf->lock, __flags);
449 return space; 384 return space;
450} 385}
451EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags); 386EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
@@ -466,25 +401,20 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
466 401
467static void flush_to_ldisc(struct work_struct *work) 402static void flush_to_ldisc(struct work_struct *work)
468{ 403{
469 struct tty_port *port = container_of(work, struct tty_port, buf.work); 404 struct tty_struct *tty =
470 struct tty_bufhead *buf = &port->buf; 405 container_of(work, struct tty_struct, buf.work);
471 struct tty_struct *tty;
472 unsigned long flags; 406 unsigned long flags;
473 struct tty_ldisc *disc; 407 struct tty_ldisc *disc;
474 408
475 tty = port->itty;
476 if (WARN_RATELIMIT(tty == NULL, "tty is NULL\n"))
477 return;
478
479 disc = tty_ldisc_ref(tty); 409 disc = tty_ldisc_ref(tty);
480 if (disc == NULL) /* !TTY_LDISC */ 410 if (disc == NULL) /* !TTY_LDISC */
481 return; 411 return;
482 412
483 spin_lock_irqsave(&buf->lock, flags); 413 spin_lock_irqsave(&tty->buf.lock, flags);
484 414
485 if (!test_and_set_bit(TTYP_FLUSHING, &port->iflags)) { 415 if (!test_and_set_bit(TTY_FLUSHING, &tty->flags)) {
486 struct tty_buffer *head; 416 struct tty_buffer *head;
487 while ((head = buf->head) != NULL) { 417 while ((head = tty->buf.head) != NULL) {
488 int count; 418 int count;
489 char *char_buf; 419 char *char_buf;
490 unsigned char *flag_buf; 420 unsigned char *flag_buf;
@@ -493,14 +423,14 @@ static void flush_to_ldisc(struct work_struct *work)
493 if (!count) { 423 if (!count) {
494 if (head->next == NULL) 424 if (head->next == NULL)
495 break; 425 break;
496 buf->head = head->next; 426 tty->buf.head = head->next;
497 tty_buffer_free(port, head); 427 tty_buffer_free(tty, head);
498 continue; 428 continue;
499 } 429 }
500 /* Ldisc or user is trying to flush the buffers 430 /* Ldisc or user is trying to flush the buffers
501 we are feeding to the ldisc, stop feeding the 431 we are feeding to the ldisc, stop feeding the
502 line discipline as we want to empty the queue */ 432 line discipline as we want to empty the queue */
503 if (test_bit(TTYP_FLUSHPENDING, &port->iflags)) 433 if (test_bit(TTY_FLUSHPENDING, &tty->flags))
504 break; 434 break;
505 if (!tty->receive_room) 435 if (!tty->receive_room)
506 break; 436 break;
@@ -509,22 +439,22 @@ static void flush_to_ldisc(struct work_struct *work)
509 char_buf = head->char_buf_ptr + head->read; 439 char_buf = head->char_buf_ptr + head->read;
510 flag_buf = head->flag_buf_ptr + head->read; 440 flag_buf = head->flag_buf_ptr + head->read;
511 head->read += count; 441 head->read += count;
512 spin_unlock_irqrestore(&buf->lock, flags); 442 spin_unlock_irqrestore(&tty->buf.lock, flags);
513 disc->ops->receive_buf(tty, char_buf, 443 disc->ops->receive_buf(tty, char_buf,
514 flag_buf, count); 444 flag_buf, count);
515 spin_lock_irqsave(&buf->lock, flags); 445 spin_lock_irqsave(&tty->buf.lock, flags);
516 } 446 }
517 clear_bit(TTYP_FLUSHING, &port->iflags); 447 clear_bit(TTY_FLUSHING, &tty->flags);
518 } 448 }
519 449
520 /* We may have a deferred request to flush the input buffer, 450 /* We may have a deferred request to flush the input buffer,
521 if so pull the chain under the lock and empty the queue */ 451 if so pull the chain under the lock and empty the queue */
522 if (test_bit(TTYP_FLUSHPENDING, &port->iflags)) { 452 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) {
523 __tty_buffer_flush(port); 453 __tty_buffer_flush(tty);
524 clear_bit(TTYP_FLUSHPENDING, &port->iflags); 454 clear_bit(TTY_FLUSHPENDING, &tty->flags);
525 wake_up(&tty->read_wait); 455 wake_up(&tty->read_wait);
526 } 456 }
527 spin_unlock_irqrestore(&buf->lock, flags); 457 spin_unlock_irqrestore(&tty->buf.lock, flags);
528 458
529 tty_ldisc_deref(disc); 459 tty_ldisc_deref(disc);
530} 460}
@@ -539,8 +469,7 @@ static void flush_to_ldisc(struct work_struct *work)
539 */ 469 */
540void tty_flush_to_ldisc(struct tty_struct *tty) 470void tty_flush_to_ldisc(struct tty_struct *tty)
541{ 471{
542 if (!tty->low_latency) 472 flush_work(&tty->buf.work);
543 flush_work(&tty->port->buf.work);
544} 473}
545 474
546/** 475/**
@@ -558,18 +487,16 @@ void tty_flush_to_ldisc(struct tty_struct *tty)
558 487
559void tty_flip_buffer_push(struct tty_struct *tty) 488void tty_flip_buffer_push(struct tty_struct *tty)
560{ 489{
561 struct tty_bufhead *buf = &tty->port->buf;
562 unsigned long flags; 490 unsigned long flags;
563 491 spin_lock_irqsave(&tty->buf.lock, flags);
564 spin_lock_irqsave(&buf->lock, flags); 492 if (tty->buf.tail != NULL)
565 if (buf->tail != NULL) 493 tty->buf.tail->commit = tty->buf.tail->used;
566 buf->tail->commit = buf->tail->used; 494 spin_unlock_irqrestore(&tty->buf.lock, flags);
567 spin_unlock_irqrestore(&buf->lock, flags);
568 495
569 if (tty->low_latency) 496 if (tty->low_latency)
570 flush_to_ldisc(&buf->work); 497 flush_to_ldisc(&tty->buf.work);
571 else 498 else
572 schedule_work(&buf->work); 499 schedule_work(&tty->buf.work);
573} 500}
574EXPORT_SYMBOL(tty_flip_buffer_push); 501EXPORT_SYMBOL(tty_flip_buffer_push);
575 502
@@ -583,15 +510,13 @@ EXPORT_SYMBOL(tty_flip_buffer_push);
583 * Locking: none 510 * Locking: none
584 */ 511 */
585 512
586void tty_buffer_init(struct tty_port *port) 513void tty_buffer_init(struct tty_struct *tty)
587{ 514{
588 struct tty_bufhead *buf = &port->buf; 515 spin_lock_init(&tty->buf.lock);
589 516 tty->buf.head = NULL;
590 spin_lock_init(&buf->lock); 517 tty->buf.tail = NULL;
591 buf->head = NULL; 518 tty->buf.free = NULL;
592 buf->tail = NULL; 519 tty->buf.memory_used = 0;
593 buf->free = NULL; 520 INIT_WORK(&tty->buf.work, flush_to_ldisc);
594 buf->memory_used = 0;
595 INIT_WORK(&buf->work, flush_to_ldisc);
596} 521}
597 522
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index da9fde85075..1a890e270be 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -97,6 +97,7 @@
97#include <linux/ratelimit.h> 97#include <linux/ratelimit.h>
98 98
99#include <linux/uaccess.h> 99#include <linux/uaccess.h>
100#include <asm/system.h>
100 101
101#include <linux/kbd_kern.h> 102#include <linux/kbd_kern.h>
102#include <linux/vt_kern.h> 103#include <linux/vt_kern.h>
@@ -181,12 +182,10 @@ struct tty_struct *alloc_tty_struct(void)
181 182
182void free_tty_struct(struct tty_struct *tty) 183void free_tty_struct(struct tty_struct *tty)
183{ 184{
184 if (!tty)
185 return;
186 if (tty->dev) 185 if (tty->dev)
187 put_device(tty->dev); 186 put_device(tty->dev);
188 kfree(tty->write_buf); 187 kfree(tty->write_buf);
189 tty->magic = 0xDEADDEAD; 188 tty_buffer_free_all(tty);
190 kfree(tty); 189 kfree(tty);
191} 190}
192 191
@@ -236,7 +235,7 @@ void tty_free_file(struct file *file)
236} 235}
237 236
238/* Delete file from its tty */ 237/* Delete file from its tty */
239static void tty_del_file(struct file *file) 238void tty_del_file(struct file *file)
240{ 239{
241 struct tty_file_private *priv = file->private_data; 240 struct tty_file_private *priv = file->private_data;
242 241
@@ -554,7 +553,7 @@ EXPORT_SYMBOL_GPL(tty_wakeup);
554 * tasklist_lock to walk task list for hangup event 553 * tasklist_lock to walk task list for hangup event
555 * ->siglock to protect ->signal/->sighand 554 * ->siglock to protect ->signal/->sighand
556 */ 555 */
557static void __tty_hangup(struct tty_struct *tty) 556void __tty_hangup(struct tty_struct *tty)
558{ 557{
559 struct file *cons_filp = NULL; 558 struct file *cons_filp = NULL;
560 struct file *filp, *f = NULL; 559 struct file *filp, *f = NULL;
@@ -575,7 +574,7 @@ static void __tty_hangup(struct tty_struct *tty)
575 } 574 }
576 spin_unlock(&redirect_lock); 575 spin_unlock(&redirect_lock);
577 576
578 tty_lock(tty); 577 tty_lock();
579 578
580 /* some functions below drop BTM, so we need this bit */ 579 /* some functions below drop BTM, so we need this bit */
581 set_bit(TTY_HUPPING, &tty->flags); 580 set_bit(TTY_HUPPING, &tty->flags);
@@ -668,7 +667,7 @@ static void __tty_hangup(struct tty_struct *tty)
668 clear_bit(TTY_HUPPING, &tty->flags); 667 clear_bit(TTY_HUPPING, &tty->flags);
669 tty_ldisc_enable(tty); 668 tty_ldisc_enable(tty);
670 669
671 tty_unlock(tty); 670 tty_unlock();
672 671
673 if (f) 672 if (f)
674 fput(f); 673 fput(f);
@@ -791,24 +790,19 @@ static void session_clear_tty(struct pid *session)
791void disassociate_ctty(int on_exit) 790void disassociate_ctty(int on_exit)
792{ 791{
793 struct tty_struct *tty; 792 struct tty_struct *tty;
793 struct pid *tty_pgrp = NULL;
794 794
795 if (!current->signal->leader) 795 if (!current->signal->leader)
796 return; 796 return;
797 797
798 tty = get_current_tty(); 798 tty = get_current_tty();
799 if (tty) { 799 if (tty) {
800 struct pid *tty_pgrp = get_pid(tty->pgrp); 800 tty_pgrp = get_pid(tty->pgrp);
801 if (on_exit) { 801 if (on_exit) {
802 if (tty->driver->type != TTY_DRIVER_TYPE_PTY) 802 if (tty->driver->type != TTY_DRIVER_TYPE_PTY)
803 tty_vhangup(tty); 803 tty_vhangup(tty);
804 } 804 }
805 tty_kref_put(tty); 805 tty_kref_put(tty);
806 if (tty_pgrp) {
807 kill_pgrp(tty_pgrp, SIGHUP, on_exit);
808 if (!on_exit)
809 kill_pgrp(tty_pgrp, SIGCONT, on_exit);
810 put_pid(tty_pgrp);
811 }
812 } else if (on_exit) { 806 } else if (on_exit) {
813 struct pid *old_pgrp; 807 struct pid *old_pgrp;
814 spin_lock_irq(&current->sighand->siglock); 808 spin_lock_irq(&current->sighand->siglock);
@@ -822,6 +816,12 @@ void disassociate_ctty(int on_exit)
822 } 816 }
823 return; 817 return;
824 } 818 }
819 if (tty_pgrp) {
820 kill_pgrp(tty_pgrp, SIGHUP, on_exit);
821 if (!on_exit)
822 kill_pgrp(tty_pgrp, SIGCONT, on_exit);
823 put_pid(tty_pgrp);
824 }
825 825
826 spin_lock_irq(&current->sighand->siglock); 826 spin_lock_irq(&current->sighand->siglock);
827 put_pid(current->signal->tty_old_pgrp); 827 put_pid(current->signal->tty_old_pgrp);
@@ -857,11 +857,10 @@ void disassociate_ctty(int on_exit)
857 */ 857 */
858void no_tty(void) 858void no_tty(void)
859{ 859{
860 /* FIXME: Review locking here. The tty_lock never covered any race
861 between a new association and proc_clear_tty but possible we need
862 to protect against this anyway */
863 struct task_struct *tsk = current; 860 struct task_struct *tsk = current;
861 tty_lock();
864 disassociate_ctty(0); 862 disassociate_ctty(0);
863 tty_unlock();
865 proc_clear_tty(tsk); 864 proc_clear_tty(tsk);
866} 865}
867 866
@@ -1105,12 +1104,12 @@ void tty_write_message(struct tty_struct *tty, char *msg)
1105{ 1104{
1106 if (tty) { 1105 if (tty) {
1107 mutex_lock(&tty->atomic_write_lock); 1106 mutex_lock(&tty->atomic_write_lock);
1108 tty_lock(tty); 1107 tty_lock();
1109 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { 1108 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1110 tty_unlock(tty); 1109 tty_unlock();
1111 tty->ops->write(tty, msg, strlen(msg)); 1110 tty->ops->write(tty, msg, strlen(msg));
1112 } else 1111 } else
1113 tty_unlock(tty); 1112 tty_unlock();
1114 tty_write_unlock(tty); 1113 tty_write_unlock(tty);
1115 } 1114 }
1116 return; 1115 return;
@@ -1165,8 +1164,10 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
1165 struct file *p = NULL; 1164 struct file *p = NULL;
1166 1165
1167 spin_lock(&redirect_lock); 1166 spin_lock(&redirect_lock);
1168 if (redirect) 1167 if (redirect) {
1169 p = get_file(redirect); 1168 get_file(redirect);
1169 p = redirect;
1170 }
1170 spin_unlock(&redirect_lock); 1171 spin_unlock(&redirect_lock);
1171 1172
1172 if (p) { 1173 if (p) {
@@ -1213,10 +1214,7 @@ static void pty_line_name(struct tty_driver *driver, int index, char *p)
1213 */ 1214 */
1214static void tty_line_name(struct tty_driver *driver, int index, char *p) 1215static void tty_line_name(struct tty_driver *driver, int index, char *p)
1215{ 1216{
1216 if (driver->flags & TTY_DRIVER_UNNUMBERED_NODE) 1217 sprintf(p, "%s%d", driver->name, index + driver->name_base);
1217 strcpy(p, driver->name);
1218 else
1219 sprintf(p, "%s%d", driver->name, index + driver->name_base);
1220} 1218}
1221 1219
1222/** 1220/**
@@ -1233,10 +1231,13 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p)
1233static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, 1231static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
1234 struct inode *inode, int idx) 1232 struct inode *inode, int idx)
1235{ 1233{
1234 struct tty_struct *tty;
1235
1236 if (driver->ops->lookup) 1236 if (driver->ops->lookup)
1237 return driver->ops->lookup(driver, inode, idx); 1237 return driver->ops->lookup(driver, inode, idx);
1238 1238
1239 return driver->ttys[idx]; 1239 tty = driver->ttys[idx];
1240 return tty;
1240} 1241}
1241 1242
1242/** 1243/**
@@ -1252,36 +1253,25 @@ int tty_init_termios(struct tty_struct *tty)
1252 struct ktermios *tp; 1253 struct ktermios *tp;
1253 int idx = tty->index; 1254 int idx = tty->index;
1254 1255
1255 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) 1256 tp = tty->driver->termios[idx];
1256 tty->termios = tty->driver->init_termios; 1257 if (tp == NULL) {
1257 else { 1258 tp = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
1258 /* Check for lazy saved data */ 1259 if (tp == NULL)
1259 tp = tty->driver->termios[idx]; 1260 return -ENOMEM;
1260 if (tp != NULL) 1261 memcpy(tp, &tty->driver->init_termios,
1261 tty->termios = *tp; 1262 sizeof(struct ktermios));
1262 else 1263 tty->driver->termios[idx] = tp;
1263 tty->termios = tty->driver->init_termios;
1264 } 1264 }
1265 tty->termios = tp;
1266 tty->termios_locked = tp + 1;
1267
1265 /* Compatibility until drivers always set this */ 1268 /* Compatibility until drivers always set this */
1266 tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); 1269 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
1267 tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); 1270 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
1268 return 0; 1271 return 0;
1269} 1272}
1270EXPORT_SYMBOL_GPL(tty_init_termios); 1273EXPORT_SYMBOL_GPL(tty_init_termios);
1271 1274
1272int tty_standard_install(struct tty_driver *driver, struct tty_struct *tty)
1273{
1274 int ret = tty_init_termios(tty);
1275 if (ret)
1276 return ret;
1277
1278 tty_driver_kref_get(driver);
1279 tty->count++;
1280 driver->ttys[tty->index] = tty;
1281 return 0;
1282}
1283EXPORT_SYMBOL_GPL(tty_standard_install);
1284
1285/** 1275/**
1286 * tty_driver_install_tty() - install a tty entry in the driver 1276 * tty_driver_install_tty() - install a tty entry in the driver
1287 * @driver: the driver for the tty 1277 * @driver: the driver for the tty
@@ -1297,8 +1287,21 @@ EXPORT_SYMBOL_GPL(tty_standard_install);
1297static int tty_driver_install_tty(struct tty_driver *driver, 1287static int tty_driver_install_tty(struct tty_driver *driver,
1298 struct tty_struct *tty) 1288 struct tty_struct *tty)
1299{ 1289{
1300 return driver->ops->install ? driver->ops->install(driver, tty) : 1290 int idx = tty->index;
1301 tty_standard_install(driver, tty); 1291 int ret;
1292
1293 if (driver->ops->install) {
1294 ret = driver->ops->install(driver, tty);
1295 return ret;
1296 }
1297
1298 if (tty_init_termios(tty) == 0) {
1299 tty_driver_kref_get(driver);
1300 tty->count++;
1301 driver->ttys[idx] = tty;
1302 return 0;
1303 }
1304 return -ENOMEM;
1302} 1305}
1303 1306
1304/** 1307/**
@@ -1349,6 +1352,7 @@ static int tty_reopen(struct tty_struct *tty)
1349 tty->link->count++; 1352 tty->link->count++;
1350 } 1353 }
1351 tty->count++; 1354 tty->count++;
1355 tty->driver = driver; /* N.B. why do this every time?? */
1352 1356
1353 mutex_lock(&tty->ldisc_mutex); 1357 mutex_lock(&tty->ldisc_mutex);
1354 WARN_ON(!test_bit(TTY_LDISC, &tty->flags)); 1358 WARN_ON(!test_bit(TTY_LDISC, &tty->flags));
@@ -1362,6 +1366,7 @@ static int tty_reopen(struct tty_struct *tty)
1362 * @driver: tty driver we are opening a device on 1366 * @driver: tty driver we are opening a device on
1363 * @idx: device index 1367 * @idx: device index
1364 * @ret_tty: returned tty structure 1368 * @ret_tty: returned tty structure
1369 * @first_ok: ok to open a new device (used by ptmx)
1365 * 1370 *
1366 * Prepare a tty device. This may not be a "new" clean device but 1371 * Prepare a tty device. This may not be a "new" clean device but
1367 * could also be an active device. The pty drivers require special 1372 * could also be an active device. The pty drivers require special
@@ -1381,11 +1386,18 @@ static int tty_reopen(struct tty_struct *tty)
1381 * relaxed for the (most common) case of reopening a tty. 1386 * relaxed for the (most common) case of reopening a tty.
1382 */ 1387 */
1383 1388
1384struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx) 1389struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
1390 int first_ok)
1385{ 1391{
1386 struct tty_struct *tty; 1392 struct tty_struct *tty;
1387 int retval; 1393 int retval;
1388 1394
1395 /* Check if pty master is being opened multiple times */
1396 if (driver->subtype == PTY_TYPE_MASTER &&
1397 (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
1398 return ERR_PTR(-EIO);
1399 }
1400
1389 /* 1401 /*
1390 * First time open is complex, especially for PTY devices. 1402 * First time open is complex, especially for PTY devices.
1391 * This code guarantees that either everything succeeds and the 1403 * This code guarantees that either everything succeeds and the
@@ -1404,20 +1416,10 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1404 } 1416 }
1405 initialize_tty_struct(tty, driver, idx); 1417 initialize_tty_struct(tty, driver, idx);
1406 1418
1407 tty_lock(tty);
1408 retval = tty_driver_install_tty(driver, tty); 1419 retval = tty_driver_install_tty(driver, tty);
1409 if (retval < 0) 1420 if (retval < 0)
1410 goto err_deinit_tty; 1421 goto err_deinit_tty;
1411 1422
1412 if (!tty->port)
1413 tty->port = driver->ports[idx];
1414
1415 WARN_RATELIMIT(!tty->port,
1416 "%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n",
1417 __func__, tty->driver->name);
1418
1419 tty->port->itty = tty;
1420
1421 /* 1423 /*
1422 * Structures all installed ... call the ldisc open routines. 1424 * Structures all installed ... call the ldisc open routines.
1423 * If we fail here just call release_tty to clean up. No need 1425 * If we fail here just call release_tty to clean up. No need
@@ -1426,11 +1428,9 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1426 retval = tty_ldisc_setup(tty, tty->link); 1428 retval = tty_ldisc_setup(tty, tty->link);
1427 if (retval) 1429 if (retval)
1428 goto err_release_tty; 1430 goto err_release_tty;
1429 /* Return the tty locked so that it cannot vanish under the caller */
1430 return tty; 1431 return tty;
1431 1432
1432err_deinit_tty: 1433err_deinit_tty:
1433 tty_unlock(tty);
1434 deinitialize_tty_struct(tty); 1434 deinitialize_tty_struct(tty);
1435 free_tty_struct(tty); 1435 free_tty_struct(tty);
1436err_module_put: 1436err_module_put:
@@ -1439,7 +1439,6 @@ err_module_put:
1439 1439
1440 /* call the tty release_tty routine to clean out this slot */ 1440 /* call the tty release_tty routine to clean out this slot */
1441err_release_tty: 1441err_release_tty:
1442 tty_unlock(tty);
1443 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " 1442 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, "
1444 "clearing slot %d\n", idx); 1443 "clearing slot %d\n", idx);
1445 release_tty(tty, idx); 1444 release_tty(tty, idx);
@@ -1450,25 +1449,22 @@ void tty_free_termios(struct tty_struct *tty)
1450{ 1449{
1451 struct ktermios *tp; 1450 struct ktermios *tp;
1452 int idx = tty->index; 1451 int idx = tty->index;
1453 1452 /* Kill this flag and push into drivers for locking etc */
1454 /* If the port is going to reset then it has no termios to save */ 1453 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) {
1455 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) 1454 /* FIXME: Locking on ->termios array */
1456 return; 1455 tp = tty->termios;
1457 1456 tty->driver->termios[idx] = NULL;
1458 /* Stash the termios data */ 1457 kfree(tp);
1459 tp = tty->driver->termios[idx];
1460 if (tp == NULL) {
1461 tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
1462 if (tp == NULL) {
1463 pr_warn("tty: no memory to save termios state.\n");
1464 return;
1465 }
1466 tty->driver->termios[idx] = tp;
1467 } 1458 }
1468 *tp = tty->termios;
1469} 1459}
1470EXPORT_SYMBOL(tty_free_termios); 1460EXPORT_SYMBOL(tty_free_termios);
1471 1461
1462void tty_shutdown(struct tty_struct *tty)
1463{
1464 tty_driver_remove_tty(tty->driver, tty);
1465 tty_free_termios(tty);
1466}
1467EXPORT_SYMBOL(tty_shutdown);
1472 1468
1473/** 1469/**
1474 * release_one_tty - release tty structure memory 1470 * release_one_tty - release tty structure memory
@@ -1479,6 +1475,7 @@ EXPORT_SYMBOL(tty_free_termios);
1479 * in use. It also gets called when setup of a device fails. 1475 * in use. It also gets called when setup of a device fails.
1480 * 1476 *
1481 * Locking: 1477 * Locking:
1478 * tty_mutex - sometimes only
1482 * takes the file list lock internally when working on the list 1479 * takes the file list lock internally when working on the list
1483 * of ttys that the driver keeps. 1480 * of ttys that the driver keeps.
1484 * 1481 *
@@ -1511,6 +1508,11 @@ static void queue_release_one_tty(struct kref *kref)
1511{ 1508{
1512 struct tty_struct *tty = container_of(kref, struct tty_struct, kref); 1509 struct tty_struct *tty = container_of(kref, struct tty_struct, kref);
1513 1510
1511 if (tty->ops->shutdown)
1512 tty->ops->shutdown(tty);
1513 else
1514 tty_shutdown(tty);
1515
1514 /* The hangup queue is now free so we can reuse it rather than 1516 /* The hangup queue is now free so we can reuse it rather than
1515 waste a chunk of memory for each port */ 1517 waste a chunk of memory for each port */
1516 INIT_WORK(&tty->hangup_work, release_one_tty); 1518 INIT_WORK(&tty->hangup_work, release_one_tty);
@@ -1539,21 +1541,16 @@ EXPORT_SYMBOL(tty_kref_put);
1539 * and decrement the refcount of the backing module. 1541 * and decrement the refcount of the backing module.
1540 * 1542 *
1541 * Locking: 1543 * Locking:
1542 * tty_mutex 1544 * tty_mutex - sometimes only
1543 * takes the file list lock internally when working on the list 1545 * takes the file list lock internally when working on the list
1544 * of ttys that the driver keeps. 1546 * of ttys that the driver keeps.
1547 * FIXME: should we require tty_mutex is held here ??
1545 * 1548 *
1546 */ 1549 */
1547static void release_tty(struct tty_struct *tty, int idx) 1550static void release_tty(struct tty_struct *tty, int idx)
1548{ 1551{
1549 /* This should always be true but check for the moment */ 1552 /* This should always be true but check for the moment */
1550 WARN_ON(tty->index != idx); 1553 WARN_ON(tty->index != idx);
1551 WARN_ON(!mutex_is_locked(&tty_mutex));
1552 if (tty->ops->shutdown)
1553 tty->ops->shutdown(tty);
1554 tty_free_termios(tty);
1555 tty_driver_remove_tty(tty->driver, tty);
1556 tty->port->itty = NULL;
1557 1554
1558 if (tty->link) 1555 if (tty->link)
1559 tty_kref_put(tty->link); 1556 tty_kref_put(tty->link);
@@ -1561,49 +1558,6 @@ static void release_tty(struct tty_struct *tty, int idx)
1561} 1558}
1562 1559
1563/** 1560/**
1564 * tty_release_checks - check a tty before real release
1565 * @tty: tty to check
1566 * @o_tty: link of @tty (if any)
1567 * @idx: index of the tty
1568 *
1569 * Performs some paranoid checking before true release of the @tty.
1570 * This is a no-op unless TTY_PARANOIA_CHECK is defined.
1571 */
1572static int tty_release_checks(struct tty_struct *tty, struct tty_struct *o_tty,
1573 int idx)
1574{
1575#ifdef TTY_PARANOIA_CHECK
1576 if (idx < 0 || idx >= tty->driver->num) {
1577 printk(KERN_DEBUG "%s: bad idx when trying to free (%s)\n",
1578 __func__, tty->name);
1579 return -1;
1580 }
1581
1582 /* not much to check for devpts */
1583 if (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)
1584 return 0;
1585
1586 if (tty != tty->driver->ttys[idx]) {
1587 printk(KERN_DEBUG "%s: driver.table[%d] not tty for (%s)\n",
1588 __func__, idx, tty->name);
1589 return -1;
1590 }
1591 if (tty->driver->other) {
1592 if (o_tty != tty->driver->other->ttys[idx]) {
1593 printk(KERN_DEBUG "%s: other->table[%d] not o_tty for (%s)\n",
1594 __func__, idx, tty->name);
1595 return -1;
1596 }
1597 if (o_tty->link != tty) {
1598 printk(KERN_DEBUG "%s: bad pty pointers\n", __func__);
1599 return -1;
1600 }
1601 }
1602#endif
1603 return 0;
1604}
1605
1606/**
1607 * tty_release - vfs callback for close 1561 * tty_release - vfs callback for close
1608 * @inode: inode of tty 1562 * @inode: inode of tty
1609 * @filp: file pointer for handle to tty 1563 * @filp: file pointer for handle to tty
@@ -1627,37 +1581,81 @@ int tty_release(struct inode *inode, struct file *filp)
1627 struct tty_struct *tty = file_tty(filp); 1581 struct tty_struct *tty = file_tty(filp);
1628 struct tty_struct *o_tty; 1582 struct tty_struct *o_tty;
1629 int pty_master, tty_closing, o_tty_closing, do_sleep; 1583 int pty_master, tty_closing, o_tty_closing, do_sleep;
1584 int devpts;
1630 int idx; 1585 int idx;
1631 char buf[64]; 1586 char buf[64];
1632 1587
1633 if (tty_paranoia_check(tty, inode, __func__)) 1588 if (tty_paranoia_check(tty, inode, "tty_release_dev"))
1634 return 0; 1589 return 0;
1635 1590
1636 tty_lock(tty); 1591 tty_lock();
1637 check_tty_count(tty, __func__); 1592 check_tty_count(tty, "tty_release_dev");
1638 1593
1639 __tty_fasync(-1, filp, 0); 1594 __tty_fasync(-1, filp, 0);
1640 1595
1641 idx = tty->index; 1596 idx = tty->index;
1642 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1597 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1643 tty->driver->subtype == PTY_TYPE_MASTER); 1598 tty->driver->subtype == PTY_TYPE_MASTER);
1644 /* Review: parallel close */ 1599 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0;
1645 o_tty = tty->link; 1600 o_tty = tty->link;
1646 1601
1647 if (tty_release_checks(tty, o_tty, idx)) { 1602#ifdef TTY_PARANOIA_CHECK
1648 tty_unlock(tty); 1603 if (idx < 0 || idx >= tty->driver->num) {
1604 printk(KERN_DEBUG "tty_release_dev: bad idx when trying to "
1605 "free (%s)\n", tty->name);
1606 tty_unlock();
1649 return 0; 1607 return 0;
1650 } 1608 }
1609 if (!devpts) {
1610 if (tty != tty->driver->ttys[idx]) {
1611 tty_unlock();
1612 printk(KERN_DEBUG "tty_release_dev: driver.table[%d] not tty "
1613 "for (%s)\n", idx, tty->name);
1614 return 0;
1615 }
1616 if (tty->termios != tty->driver->termios[idx]) {
1617 tty_unlock();
1618 printk(KERN_DEBUG "tty_release_dev: driver.termios[%d] not termios "
1619 "for (%s)\n",
1620 idx, tty->name);
1621 return 0;
1622 }
1623 }
1624#endif
1651 1625
1652#ifdef TTY_DEBUG_HANGUP 1626#ifdef TTY_DEBUG_HANGUP
1653 printk(KERN_DEBUG "%s: %s (tty count=%d)...\n", __func__, 1627 printk(KERN_DEBUG "tty_release_dev of %s (tty count=%d)...",
1654 tty_name(tty, buf), tty->count); 1628 tty_name(tty, buf), tty->count);
1655#endif 1629#endif
1656 1630
1631#ifdef TTY_PARANOIA_CHECK
1632 if (tty->driver->other &&
1633 !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
1634 if (o_tty != tty->driver->other->ttys[idx]) {
1635 tty_unlock();
1636 printk(KERN_DEBUG "tty_release_dev: other->table[%d] "
1637 "not o_tty for (%s)\n",
1638 idx, tty->name);
1639 return 0 ;
1640 }
1641 if (o_tty->termios != tty->driver->other->termios[idx]) {
1642 tty_unlock();
1643 printk(KERN_DEBUG "tty_release_dev: other->termios[%d] "
1644 "not o_termios for (%s)\n",
1645 idx, tty->name);
1646 return 0;
1647 }
1648 if (o_tty->link != tty) {
1649 tty_unlock();
1650 printk(KERN_DEBUG "tty_release_dev: bad pty pointers\n");
1651 return 0;
1652 }
1653 }
1654#endif
1657 if (tty->ops->close) 1655 if (tty->ops->close)
1658 tty->ops->close(tty, filp); 1656 tty->ops->close(tty, filp);
1659 1657
1660 tty_unlock(tty); 1658 tty_unlock();
1661 /* 1659 /*
1662 * Sanity check: if tty->count is going to zero, there shouldn't be 1660 * Sanity check: if tty->count is going to zero, there shouldn't be
1663 * any waiters on tty->read_wait or tty->write_wait. We test the 1661 * any waiters on tty->read_wait or tty->write_wait. We test the
@@ -1680,7 +1678,7 @@ int tty_release(struct inode *inode, struct file *filp)
1680 opens on /dev/tty */ 1678 opens on /dev/tty */
1681 1679
1682 mutex_lock(&tty_mutex); 1680 mutex_lock(&tty_mutex);
1683 tty_lock_pair(tty, o_tty); 1681 tty_lock();
1684 tty_closing = tty->count <= 1; 1682 tty_closing = tty->count <= 1;
1685 o_tty_closing = o_tty && 1683 o_tty_closing = o_tty &&
1686 (o_tty->count <= (pty_master ? 1 : 0)); 1684 (o_tty->count <= (pty_master ? 1 : 0));
@@ -1709,9 +1707,9 @@ int tty_release(struct inode *inode, struct file *filp)
1709 if (!do_sleep) 1707 if (!do_sleep)
1710 break; 1708 break;
1711 1709
1712 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", 1710 printk(KERN_WARNING "tty_release_dev: %s: read/write wait queue "
1713 __func__, tty_name(tty, buf)); 1711 "active!\n", tty_name(tty, buf));
1714 tty_unlock_pair(tty, o_tty); 1712 tty_unlock();
1715 mutex_unlock(&tty_mutex); 1713 mutex_unlock(&tty_mutex);
1716 schedule(); 1714 schedule();
1717 } 1715 }
@@ -1720,20 +1718,18 @@ int tty_release(struct inode *inode, struct file *filp)
1720 * The closing flags are now consistent with the open counts on 1718 * The closing flags are now consistent with the open counts on
1721 * both sides, and we've completed the last operation that could 1719 * both sides, and we've completed the last operation that could
1722 * block, so it's safe to proceed with closing. 1720 * block, so it's safe to proceed with closing.
1723 *
1724 * We must *not* drop the tty_mutex until we ensure that a further
1725 * entry into tty_open can not pick up this tty.
1726 */ 1721 */
1727 if (pty_master) { 1722 if (pty_master) {
1728 if (--o_tty->count < 0) { 1723 if (--o_tty->count < 0) {
1729 printk(KERN_WARNING "%s: bad pty slave count (%d) for %s\n", 1724 printk(KERN_WARNING "tty_release_dev: bad pty slave count "
1730 __func__, o_tty->count, tty_name(o_tty, buf)); 1725 "(%d) for %s\n",
1726 o_tty->count, tty_name(o_tty, buf));
1731 o_tty->count = 0; 1727 o_tty->count = 0;
1732 } 1728 }
1733 } 1729 }
1734 if (--tty->count < 0) { 1730 if (--tty->count < 0) {
1735 printk(KERN_WARNING "%s: bad tty->count (%d) for %s\n", 1731 printk(KERN_WARNING "tty_release_dev: bad tty->count (%d) for %s\n",
1736 __func__, tty->count, tty_name(tty, buf)); 1732 tty->count, tty_name(tty, buf));
1737 tty->count = 0; 1733 tty->count = 0;
1738 } 1734 }
1739 1735
@@ -1774,16 +1770,15 @@ int tty_release(struct inode *inode, struct file *filp)
1774 } 1770 }
1775 1771
1776 mutex_unlock(&tty_mutex); 1772 mutex_unlock(&tty_mutex);
1777 tty_unlock_pair(tty, o_tty);
1778 /* At this point the TTY_CLOSING flag should ensure a dead tty
1779 cannot be re-opened by a racing opener */
1780 1773
1781 /* check whether both sides are closing ... */ 1774 /* check whether both sides are closing ... */
1782 if (!tty_closing || (o_tty && !o_tty_closing)) 1775 if (!tty_closing || (o_tty && !o_tty_closing)) {
1776 tty_unlock();
1783 return 0; 1777 return 0;
1778 }
1784 1779
1785#ifdef TTY_DEBUG_HANGUP 1780#ifdef TTY_DEBUG_HANGUP
1786 printk(KERN_DEBUG "%s: freeing tty structure...\n", __func__); 1781 printk(KERN_DEBUG "freeing tty structure...");
1787#endif 1782#endif
1788 /* 1783 /*
1789 * Ask the line discipline code to release its structures 1784 * Ask the line discipline code to release its structures
@@ -1791,99 +1786,18 @@ int tty_release(struct inode *inode, struct file *filp)
1791 tty_ldisc_release(tty, o_tty); 1786 tty_ldisc_release(tty, o_tty);
1792 /* 1787 /*
1793 * The release_tty function takes care of the details of clearing 1788 * The release_tty function takes care of the details of clearing
1794 * the slots and preserving the termios structure. The tty_unlock_pair 1789 * the slots and preserving the termios structure.
1795 * should be safe as we keep a kref while the tty is locked (so the
1796 * unlock never unlocks a freed tty).
1797 */ 1790 */
1798 mutex_lock(&tty_mutex);
1799 release_tty(tty, idx); 1791 release_tty(tty, idx);
1800 mutex_unlock(&tty_mutex);
1801 1792
1793 /* Make this pty number available for reallocation */
1794 if (devpts)
1795 devpts_kill_index(inode, idx);
1796 tty_unlock();
1802 return 0; 1797 return 0;
1803} 1798}
1804 1799
1805/** 1800/**
1806 * tty_open_current_tty - get tty of current task for open
1807 * @device: device number
1808 * @filp: file pointer to tty
1809 * @return: tty of the current task iff @device is /dev/tty
1810 *
1811 * We cannot return driver and index like for the other nodes because
1812 * devpts will not work then. It expects inodes to be from devpts FS.
1813 *
1814 * We need to move to returning a refcounted object from all the lookup
1815 * paths including this one.
1816 */
1817static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp)
1818{
1819 struct tty_struct *tty;
1820
1821 if (device != MKDEV(TTYAUX_MAJOR, 0))
1822 return NULL;
1823
1824 tty = get_current_tty();
1825 if (!tty)
1826 return ERR_PTR(-ENXIO);
1827
1828 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
1829 /* noctty = 1; */
1830 tty_kref_put(tty);
1831 /* FIXME: we put a reference and return a TTY! */
1832 /* This is only safe because the caller holds tty_mutex */
1833 return tty;
1834}
1835
1836/**
1837 * tty_lookup_driver - lookup a tty driver for a given device file
1838 * @device: device number
1839 * @filp: file pointer to tty
1840 * @noctty: set if the device should not become a controlling tty
1841 * @index: index for the device in the @return driver
1842 * @return: driver for this inode (with increased refcount)
1843 *
1844 * If @return is not erroneous, the caller is responsible to decrement the
1845 * refcount by tty_driver_kref_put.
1846 *
1847 * Locking: tty_mutex protects get_tty_driver
1848 */
1849static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
1850 int *noctty, int *index)
1851{
1852 struct tty_driver *driver;
1853
1854 switch (device) {
1855#ifdef CONFIG_VT
1856 case MKDEV(TTY_MAJOR, 0): {
1857 extern struct tty_driver *console_driver;
1858 driver = tty_driver_kref_get(console_driver);
1859 *index = fg_console;
1860 *noctty = 1;
1861 break;
1862 }
1863#endif
1864 case MKDEV(TTYAUX_MAJOR, 1): {
1865 struct tty_driver *console_driver = console_device(index);
1866 if (console_driver) {
1867 driver = tty_driver_kref_get(console_driver);
1868 if (driver) {
1869 /* Don't let /dev/console block */
1870 filp->f_flags |= O_NONBLOCK;
1871 *noctty = 1;
1872 break;
1873 }
1874 }
1875 return ERR_PTR(-ENODEV);
1876 }
1877 default:
1878 driver = get_tty_driver(device, index);
1879 if (!driver)
1880 return ERR_PTR(-ENODEV);
1881 break;
1882 }
1883 return driver;
1884}
1885
1886/**
1887 * tty_open - open a tty device 1801 * tty_open - open a tty device
1888 * @inode: inode of device file 1802 * @inode: inode of device file
1889 * @filp: file pointer to tty 1803 * @filp: file pointer to tty
@@ -1899,19 +1813,16 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
1899 * The termios state of a pty is reset on first open so that 1813 * The termios state of a pty is reset on first open so that
1900 * settings don't persist across reuse. 1814 * settings don't persist across reuse.
1901 * 1815 *
1902 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. 1816 * Locking: tty_mutex protects tty, get_tty_driver and tty_init_dev work.
1903 * tty->count should protect the rest. 1817 * tty->count should protect the rest.
1904 * ->siglock protects ->signal/->sighand 1818 * ->siglock protects ->signal/->sighand
1905 *
1906 * Note: the tty_unlock/lock cases without a ref are only safe due to
1907 * tty_mutex
1908 */ 1819 */
1909 1820
1910static int tty_open(struct inode *inode, struct file *filp) 1821static int tty_open(struct inode *inode, struct file *filp)
1911{ 1822{
1912 struct tty_struct *tty; 1823 struct tty_struct *tty = NULL;
1913 int noctty, retval; 1824 int noctty, retval;
1914 struct tty_driver *driver = NULL; 1825 struct tty_driver *driver;
1915 int index; 1826 int index;
1916 dev_t device = inode->i_rdev; 1827 dev_t device = inode->i_rdev;
1917 unsigned saved_flags = filp->f_flags; 1828 unsigned saved_flags = filp->f_flags;
@@ -1928,52 +1839,94 @@ retry_open:
1928 retval = 0; 1839 retval = 0;
1929 1840
1930 mutex_lock(&tty_mutex); 1841 mutex_lock(&tty_mutex);
1931 /* This is protected by the tty_mutex */ 1842 tty_lock();
1932 tty = tty_open_current_tty(device, filp); 1843
1933 if (IS_ERR(tty)) { 1844 if (device == MKDEV(TTYAUX_MAJOR, 0)) {
1934 retval = PTR_ERR(tty); 1845 tty = get_current_tty();
1935 goto err_unlock; 1846 if (!tty) {
1936 } else if (!tty) { 1847 tty_unlock();
1937 driver = tty_lookup_driver(device, filp, &noctty, &index); 1848 mutex_unlock(&tty_mutex);
1938 if (IS_ERR(driver)) { 1849 tty_free_file(filp);
1939 retval = PTR_ERR(driver); 1850 return -ENXIO;
1940 goto err_unlock;
1941 } 1851 }
1852 driver = tty_driver_kref_get(tty->driver);
1853 index = tty->index;
1854 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
1855 /* noctty = 1; */
1856 /* FIXME: Should we take a driver reference ? */
1857 tty_kref_put(tty);
1858 goto got_driver;
1859 }
1860#ifdef CONFIG_VT
1861 if (device == MKDEV(TTY_MAJOR, 0)) {
1862 extern struct tty_driver *console_driver;
1863 driver = tty_driver_kref_get(console_driver);
1864 index = fg_console;
1865 noctty = 1;
1866 goto got_driver;
1867 }
1868#endif
1869 if (device == MKDEV(TTYAUX_MAJOR, 1)) {
1870 struct tty_driver *console_driver = console_device(&index);
1871 if (console_driver) {
1872 driver = tty_driver_kref_get(console_driver);
1873 if (driver) {
1874 /* Don't let /dev/console block */
1875 filp->f_flags |= O_NONBLOCK;
1876 noctty = 1;
1877 goto got_driver;
1878 }
1879 }
1880 tty_unlock();
1881 mutex_unlock(&tty_mutex);
1882 tty_free_file(filp);
1883 return -ENODEV;
1884 }
1942 1885
1886 driver = get_tty_driver(device, &index);
1887 if (!driver) {
1888 tty_unlock();
1889 mutex_unlock(&tty_mutex);
1890 tty_free_file(filp);
1891 return -ENODEV;
1892 }
1893got_driver:
1894 if (!tty) {
1943 /* check whether we're reopening an existing tty */ 1895 /* check whether we're reopening an existing tty */
1944 tty = tty_driver_lookup_tty(driver, inode, index); 1896 tty = tty_driver_lookup_tty(driver, inode, index);
1897
1945 if (IS_ERR(tty)) { 1898 if (IS_ERR(tty)) {
1946 retval = PTR_ERR(tty); 1899 tty_unlock();
1947 goto err_unlock; 1900 mutex_unlock(&tty_mutex);
1901 tty_driver_kref_put(driver);
1902 tty_free_file(filp);
1903 return PTR_ERR(tty);
1948 } 1904 }
1949 } 1905 }
1950 1906
1951 if (tty) { 1907 if (tty) {
1952 tty_lock(tty);
1953 retval = tty_reopen(tty); 1908 retval = tty_reopen(tty);
1954 if (retval < 0) { 1909 if (retval)
1955 tty_unlock(tty);
1956 tty = ERR_PTR(retval); 1910 tty = ERR_PTR(retval);
1957 } 1911 } else
1958 } else /* Returns with the tty_lock held for now */ 1912 tty = tty_init_dev(driver, index, 0);
1959 tty = tty_init_dev(driver, index);
1960 1913
1961 mutex_unlock(&tty_mutex); 1914 mutex_unlock(&tty_mutex);
1962 if (driver) 1915 tty_driver_kref_put(driver);
1963 tty_driver_kref_put(driver);
1964 if (IS_ERR(tty)) { 1916 if (IS_ERR(tty)) {
1965 retval = PTR_ERR(tty); 1917 tty_unlock();
1966 goto err_file; 1918 tty_free_file(filp);
1919 return PTR_ERR(tty);
1967 } 1920 }
1968 1921
1969 tty_add_file(tty, filp); 1922 tty_add_file(tty, filp);
1970 1923
1971 check_tty_count(tty, __func__); 1924 check_tty_count(tty, "tty_open");
1972 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1925 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1973 tty->driver->subtype == PTY_TYPE_MASTER) 1926 tty->driver->subtype == PTY_TYPE_MASTER)
1974 noctty = 1; 1927 noctty = 1;
1975#ifdef TTY_DEBUG_HANGUP 1928#ifdef TTY_DEBUG_HANGUP
1976 printk(KERN_DEBUG "%s: opening %s...\n", __func__, tty->name); 1929 printk(KERN_DEBUG "opening %s...", tty->name);
1977#endif 1930#endif
1978 if (tty->ops->open) 1931 if (tty->ops->open)
1979 retval = tty->ops->open(tty, filp); 1932 retval = tty->ops->open(tty, filp);
@@ -1987,10 +1940,10 @@ retry_open:
1987 1940
1988 if (retval) { 1941 if (retval) {
1989#ifdef TTY_DEBUG_HANGUP 1942#ifdef TTY_DEBUG_HANGUP
1990 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, 1943 printk(KERN_DEBUG "error %d in opening %s...", retval,
1991 retval, tty->name); 1944 tty->name);
1992#endif 1945#endif
1993 tty_unlock(tty); /* need to call tty_release without BTM */ 1946 tty_unlock(); /* need to call tty_release without BTM */
1994 tty_release(inode, filp); 1947 tty_release(inode, filp);
1995 if (retval != -ERESTARTSYS) 1948 if (retval != -ERESTARTSYS)
1996 return retval; 1949 return retval;
@@ -2002,15 +1955,17 @@ retry_open:
2002 /* 1955 /*
2003 * Need to reset f_op in case a hangup happened. 1956 * Need to reset f_op in case a hangup happened.
2004 */ 1957 */
1958 tty_lock();
2005 if (filp->f_op == &hung_up_tty_fops) 1959 if (filp->f_op == &hung_up_tty_fops)
2006 filp->f_op = &tty_fops; 1960 filp->f_op = &tty_fops;
1961 tty_unlock();
2007 goto retry_open; 1962 goto retry_open;
2008 } 1963 }
2009 tty_unlock(tty); 1964 tty_unlock();
2010 1965
2011 1966
2012 mutex_lock(&tty_mutex); 1967 mutex_lock(&tty_mutex);
2013 tty_lock(tty); 1968 tty_lock();
2014 spin_lock_irq(&current->sighand->siglock); 1969 spin_lock_irq(&current->sighand->siglock);
2015 if (!noctty && 1970 if (!noctty &&
2016 current->signal->leader && 1971 current->signal->leader &&
@@ -2018,17 +1973,9 @@ retry_open:
2018 tty->session == NULL) 1973 tty->session == NULL)
2019 __proc_set_tty(current, tty); 1974 __proc_set_tty(current, tty);
2020 spin_unlock_irq(&current->sighand->siglock); 1975 spin_unlock_irq(&current->sighand->siglock);
2021 tty_unlock(tty); 1976 tty_unlock();
2022 mutex_unlock(&tty_mutex); 1977 mutex_unlock(&tty_mutex);
2023 return 0; 1978 return 0;
2024err_unlock:
2025 mutex_unlock(&tty_mutex);
2026 /* after locks to avoid deadlock */
2027 if (!IS_ERR_OR_NULL(driver))
2028 tty_driver_kref_put(driver);
2029err_file:
2030 tty_free_file(filp);
2031 return retval;
2032} 1979}
2033 1980
2034 1981
@@ -2104,13 +2051,10 @@ out:
2104 2051
2105static int tty_fasync(int fd, struct file *filp, int on) 2052static int tty_fasync(int fd, struct file *filp, int on)
2106{ 2053{
2107 struct tty_struct *tty = file_tty(filp);
2108 int retval; 2054 int retval;
2109 2055 tty_lock();
2110 tty_lock(tty);
2111 retval = __tty_fasync(fd, filp, on); 2056 retval = __tty_fasync(fd, filp, on);
2112 tty_unlock(tty); 2057 tty_unlock();
2113
2114 return retval; 2058 return retval;
2115} 2059}
2116 2060
@@ -2259,7 +2203,8 @@ static int tioccons(struct file *file)
2259 spin_unlock(&redirect_lock); 2203 spin_unlock(&redirect_lock);
2260 return -EBUSY; 2204 return -EBUSY;
2261 } 2205 }
2262 redirect = get_file(file); 2206 get_file(file);
2207 redirect = file;
2263 spin_unlock(&redirect_lock); 2208 spin_unlock(&redirect_lock);
2264 return 0; 2209 return 0;
2265} 2210}
@@ -2687,11 +2632,6 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2687 case TIOCNXCL: 2632 case TIOCNXCL:
2688 clear_bit(TTY_EXCLUSIVE, &tty->flags); 2633 clear_bit(TTY_EXCLUSIVE, &tty->flags);
2689 return 0; 2634 return 0;
2690 case TIOCGEXCL:
2691 {
2692 int excl = test_bit(TTY_EXCLUSIVE, &tty->flags);
2693 return put_user(excl, (int __user *)p);
2694 }
2695 case TIOCNOTTY: 2635 case TIOCNOTTY:
2696 if (current->signal->tty != tty) 2636 if (current->signal->tty != tty)
2697 return -ENOTTY; 2637 return -ENOTTY;
@@ -2773,7 +2713,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2773 if (ld->ops->ioctl) { 2713 if (ld->ops->ioctl) {
2774 retval = ld->ops->ioctl(tty, file, cmd, arg); 2714 retval = ld->ops->ioctl(tty, file, cmd, arg);
2775 if (retval == -ENOIOCTLCMD) 2715 if (retval == -ENOIOCTLCMD)
2776 retval = -ENOTTY; 2716 retval = -EINVAL;
2777 } 2717 }
2778 tty_ldisc_deref(ld); 2718 tty_ldisc_deref(ld);
2779 return retval; 2719 return retval;
@@ -2800,21 +2740,12 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
2800 ld = tty_ldisc_ref_wait(tty); 2740 ld = tty_ldisc_ref_wait(tty);
2801 if (ld->ops->compat_ioctl) 2741 if (ld->ops->compat_ioctl)
2802 retval = ld->ops->compat_ioctl(tty, file, cmd, arg); 2742 retval = ld->ops->compat_ioctl(tty, file, cmd, arg);
2803 else
2804 retval = n_tty_compat_ioctl_helper(tty, file, cmd, arg);
2805 tty_ldisc_deref(ld); 2743 tty_ldisc_deref(ld);
2806 2744
2807 return retval; 2745 return retval;
2808} 2746}
2809#endif 2747#endif
2810 2748
2811static int this_tty(const void *t, struct file *file, unsigned fd)
2812{
2813 if (likely(file->f_op->read != tty_read))
2814 return 0;
2815 return file_tty(file) != t ? 0 : fd + 1;
2816}
2817
2818/* 2749/*
2819 * This implements the "Secure Attention Key" --- the idea is to 2750 * This implements the "Secure Attention Key" --- the idea is to
2820 * prevent trojan horses by killing all processes associated with this 2751 * prevent trojan horses by killing all processes associated with this
@@ -2842,6 +2773,8 @@ void __do_SAK(struct tty_struct *tty)
2842 struct task_struct *g, *p; 2773 struct task_struct *g, *p;
2843 struct pid *session; 2774 struct pid *session;
2844 int i; 2775 int i;
2776 struct file *filp;
2777 struct fdtable *fdt;
2845 2778
2846 if (!tty) 2779 if (!tty)
2847 return; 2780 return;
@@ -2871,12 +2804,27 @@ void __do_SAK(struct tty_struct *tty)
2871 continue; 2804 continue;
2872 } 2805 }
2873 task_lock(p); 2806 task_lock(p);
2874 i = iterate_fd(p->files, 0, this_tty, tty); 2807 if (p->files) {
2875 if (i != 0) { 2808 /*
2876 printk(KERN_NOTICE "SAK: killed process %d" 2809 * We don't take a ref to the file, so we must
2877 " (%s): fd#%d opened to the tty\n", 2810 * hold ->file_lock instead.
2878 task_pid_nr(p), p->comm, i - 1); 2811 */
2879 force_sig(SIGKILL, p); 2812 spin_lock(&p->files->file_lock);
2813 fdt = files_fdtable(p->files);
2814 for (i = 0; i < fdt->max_fds; i++) {
2815 filp = fcheck_files(p->files, i);
2816 if (!filp)
2817 continue;
2818 if (filp->f_op->read == tty_read &&
2819 file_tty(filp) == tty) {
2820 printk(KERN_NOTICE "SAK: killed process %d"
2821 " (%s): fd#%d opened to the tty\n",
2822 task_pid_nr(p), p->comm, i);
2823 force_sig(SIGKILL, p);
2824 break;
2825 }
2826 }
2827 spin_unlock(&p->files->file_lock);
2880 } 2828 }
2881 task_unlock(p); 2829 task_unlock(p);
2882 } while_each_thread(g, p); 2830 } while_each_thread(g, p);
@@ -2939,13 +2887,19 @@ void initialize_tty_struct(struct tty_struct *tty,
2939 tty_ldisc_init(tty); 2887 tty_ldisc_init(tty);
2940 tty->session = NULL; 2888 tty->session = NULL;
2941 tty->pgrp = NULL; 2889 tty->pgrp = NULL;
2942 mutex_init(&tty->legacy_mutex); 2890 tty->overrun_time = jiffies;
2891 tty->buf.head = tty->buf.tail = NULL;
2892 tty_buffer_init(tty);
2943 mutex_init(&tty->termios_mutex); 2893 mutex_init(&tty->termios_mutex);
2944 mutex_init(&tty->ldisc_mutex); 2894 mutex_init(&tty->ldisc_mutex);
2945 init_waitqueue_head(&tty->write_wait); 2895 init_waitqueue_head(&tty->write_wait);
2946 init_waitqueue_head(&tty->read_wait); 2896 init_waitqueue_head(&tty->read_wait);
2947 INIT_WORK(&tty->hangup_work, do_tty_hangup); 2897 INIT_WORK(&tty->hangup_work, do_tty_hangup);
2898 mutex_init(&tty->atomic_read_lock);
2948 mutex_init(&tty->atomic_write_lock); 2899 mutex_init(&tty->atomic_write_lock);
2900 mutex_init(&tty->output_lock);
2901 mutex_init(&tty->echo_lock);
2902 spin_lock_init(&tty->read_lock);
2949 spin_lock_init(&tty->ctrl_lock); 2903 spin_lock_init(&tty->ctrl_lock);
2950 INIT_LIST_HEAD(&tty->tty_files); 2904 INIT_LIST_HEAD(&tty->tty_files);
2951 INIT_WORK(&tty->SAK_work, do_SAK_work); 2905 INIT_WORK(&tty->SAK_work, do_SAK_work);
@@ -2993,15 +2947,6 @@ EXPORT_SYMBOL_GPL(tty_put_char);
2993 2947
2994struct class *tty_class; 2948struct class *tty_class;
2995 2949
2996static int tty_cdev_add(struct tty_driver *driver, dev_t dev,
2997 unsigned int index, unsigned int count)
2998{
2999 /* init here, since reused cdevs cause crashes */
3000 cdev_init(&driver->cdevs[index], &tty_fops);
3001 driver->cdevs[index].owner = driver->owner;
3002 return cdev_add(&driver->cdevs[index], dev, count);
3003}
3004
3005/** 2950/**
3006 * tty_register_device - register a tty device 2951 * tty_register_device - register a tty device
3007 * @driver: the tty driver that describes the tty device 2952 * @driver: the tty driver that describes the tty device
@@ -3024,46 +2969,8 @@ static int tty_cdev_add(struct tty_driver *driver, dev_t dev,
3024struct device *tty_register_device(struct tty_driver *driver, unsigned index, 2969struct device *tty_register_device(struct tty_driver *driver, unsigned index,
3025 struct device *device) 2970 struct device *device)
3026{ 2971{
3027 return tty_register_device_attr(driver, index, device, NULL, NULL);
3028}
3029EXPORT_SYMBOL(tty_register_device);
3030
3031static void tty_device_create_release(struct device *dev)
3032{
3033 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
3034 kfree(dev);
3035}
3036
3037/**
3038 * tty_register_device_attr - register a tty device
3039 * @driver: the tty driver that describes the tty device
3040 * @index: the index in the tty driver for this tty device
3041 * @device: a struct device that is associated with this tty device.
3042 * This field is optional, if there is no known struct device
3043 * for this tty device it can be set to NULL safely.
3044 * @drvdata: Driver data to be set to device.
3045 * @attr_grp: Attribute group to be set on device.
3046 *
3047 * Returns a pointer to the struct device for this tty device
3048 * (or ERR_PTR(-EFOO) on error).
3049 *
3050 * This call is required to be made to register an individual tty device
3051 * if the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If
3052 * that bit is not set, this function should not be called by a tty
3053 * driver.
3054 *
3055 * Locking: ??
3056 */
3057struct device *tty_register_device_attr(struct tty_driver *driver,
3058 unsigned index, struct device *device,
3059 void *drvdata,
3060 const struct attribute_group **attr_grp)
3061{
3062 char name[64]; 2972 char name[64];
3063 dev_t devt = MKDEV(driver->major, driver->minor_start) + index; 2973 dev_t dev = MKDEV(driver->major, driver->minor_start) + index;
3064 struct device *dev = NULL;
3065 int retval = -ENODEV;
3066 bool cdev = false;
3067 2974
3068 if (index >= driver->num) { 2975 if (index >= driver->num) {
3069 printk(KERN_ERR "Attempt to register invalid tty line number " 2976 printk(KERN_ERR "Attempt to register invalid tty line number "
@@ -3076,40 +2983,9 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
3076 else 2983 else
3077 tty_line_name(driver, index, name); 2984 tty_line_name(driver, index, name);
3078 2985
3079 if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) { 2986 return device_create(tty_class, device, dev, NULL, name);
3080 retval = tty_cdev_add(driver, devt, index, 1);
3081 if (retval)
3082 goto error;
3083 cdev = true;
3084 }
3085
3086 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
3087 if (!dev) {
3088 retval = -ENOMEM;
3089 goto error;
3090 }
3091
3092 dev->devt = devt;
3093 dev->class = tty_class;
3094 dev->parent = device;
3095 dev->release = tty_device_create_release;
3096 dev_set_name(dev, "%s", name);
3097 dev->groups = attr_grp;
3098 dev_set_drvdata(dev, drvdata);
3099
3100 retval = device_register(dev);
3101 if (retval)
3102 goto error;
3103
3104 return dev;
3105
3106error:
3107 put_device(dev);
3108 if (cdev)
3109 cdev_del(&driver->cdevs[index]);
3110 return ERR_PTR(retval);
3111} 2987}
3112EXPORT_SYMBOL_GPL(tty_register_device_attr); 2988EXPORT_SYMBOL(tty_register_device);
3113 2989
3114/** 2990/**
3115 * tty_unregister_device - unregister a tty device 2991 * tty_unregister_device - unregister a tty device
@@ -3126,82 +3002,30 @@ void tty_unregister_device(struct tty_driver *driver, unsigned index)
3126{ 3002{
3127 device_destroy(tty_class, 3003 device_destroy(tty_class,
3128 MKDEV(driver->major, driver->minor_start) + index); 3004 MKDEV(driver->major, driver->minor_start) + index);
3129 if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC))
3130 cdev_del(&driver->cdevs[index]);
3131} 3005}
3132EXPORT_SYMBOL(tty_unregister_device); 3006EXPORT_SYMBOL(tty_unregister_device);
3133 3007
3134/** 3008struct tty_driver *alloc_tty_driver(int lines)
3135 * __tty_alloc_driver -- allocate tty driver
3136 * @lines: count of lines this driver can handle at most
3137 * @owner: module which is repsonsible for this driver
3138 * @flags: some of TTY_DRIVER_* flags, will be set in driver->flags
3139 *
3140 * This should not be called directly, some of the provided macros should be
3141 * used instead. Use IS_ERR and friends on @retval.
3142 */
3143struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner,
3144 unsigned long flags)
3145{ 3009{
3146 struct tty_driver *driver; 3010 struct tty_driver *driver;
3147 unsigned int cdevs = 1;
3148 int err;
3149
3150 if (!lines || (flags & TTY_DRIVER_UNNUMBERED_NODE && lines > 1))
3151 return ERR_PTR(-EINVAL);
3152 3011
3153 driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL); 3012 driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL);
3154 if (!driver) 3013 if (driver) {
3155 return ERR_PTR(-ENOMEM); 3014 kref_init(&driver->kref);
3156 3015 driver->magic = TTY_DRIVER_MAGIC;
3157 kref_init(&driver->kref); 3016 driver->num = lines;
3158 driver->magic = TTY_DRIVER_MAGIC; 3017 /* later we'll move allocation of tables here */
3159 driver->num = lines;
3160 driver->owner = owner;
3161 driver->flags = flags;
3162
3163 if (!(flags & TTY_DRIVER_DEVPTS_MEM)) {
3164 driver->ttys = kcalloc(lines, sizeof(*driver->ttys),
3165 GFP_KERNEL);
3166 driver->termios = kcalloc(lines, sizeof(*driver->termios),
3167 GFP_KERNEL);
3168 if (!driver->ttys || !driver->termios) {
3169 err = -ENOMEM;
3170 goto err_free_all;
3171 }
3172 }
3173
3174 if (!(flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
3175 driver->ports = kcalloc(lines, sizeof(*driver->ports),
3176 GFP_KERNEL);
3177 if (!driver->ports) {
3178 err = -ENOMEM;
3179 goto err_free_all;
3180 }
3181 cdevs = lines;
3182 }
3183
3184 driver->cdevs = kcalloc(cdevs, sizeof(*driver->cdevs), GFP_KERNEL);
3185 if (!driver->cdevs) {
3186 err = -ENOMEM;
3187 goto err_free_all;
3188 } 3018 }
3189
3190 return driver; 3019 return driver;
3191err_free_all:
3192 kfree(driver->ports);
3193 kfree(driver->ttys);
3194 kfree(driver->termios);
3195 kfree(driver);
3196 return ERR_PTR(err);
3197} 3020}
3198EXPORT_SYMBOL(__tty_alloc_driver); 3021EXPORT_SYMBOL(alloc_tty_driver);
3199 3022
3200static void destruct_tty_driver(struct kref *kref) 3023static void destruct_tty_driver(struct kref *kref)
3201{ 3024{
3202 struct tty_driver *driver = container_of(kref, struct tty_driver, kref); 3025 struct tty_driver *driver = container_of(kref, struct tty_driver, kref);
3203 int i; 3026 int i;
3204 struct ktermios *tp; 3027 struct ktermios *tp;
3028 void *p;
3205 3029
3206 if (driver->flags & TTY_DRIVER_INSTALLED) { 3030 if (driver->flags & TTY_DRIVER_INSTALLED) {
3207 /* 3031 /*
@@ -3218,14 +3042,13 @@ static void destruct_tty_driver(struct kref *kref)
3218 if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) 3042 if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV))
3219 tty_unregister_device(driver, i); 3043 tty_unregister_device(driver, i);
3220 } 3044 }
3045 p = driver->ttys;
3221 proc_tty_unregister_driver(driver); 3046 proc_tty_unregister_driver(driver);
3222 if (driver->flags & TTY_DRIVER_DYNAMIC_ALLOC) 3047 driver->ttys = NULL;
3223 cdev_del(&driver->cdevs[0]); 3048 driver->termios = NULL;
3049 kfree(p);
3050 cdev_del(&driver->cdev);
3224 } 3051 }
3225 kfree(driver->cdevs);
3226 kfree(driver->ports);
3227 kfree(driver->termios);
3228 kfree(driver->ttys);
3229 kfree(driver); 3052 kfree(driver);
3230} 3053}
3231 3054
@@ -3256,8 +3079,15 @@ int tty_register_driver(struct tty_driver *driver)
3256 int error; 3079 int error;
3257 int i; 3080 int i;
3258 dev_t dev; 3081 dev_t dev;
3082 void **p = NULL;
3259 struct device *d; 3083 struct device *d;
3260 3084
3085 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) {
3086 p = kzalloc(driver->num * 2 * sizeof(void *), GFP_KERNEL);
3087 if (!p)
3088 return -ENOMEM;
3089 }
3090
3261 if (!driver->major) { 3091 if (!driver->major) {
3262 error = alloc_chrdev_region(&dev, driver->minor_start, 3092 error = alloc_chrdev_region(&dev, driver->minor_start,
3263 driver->num, driver->name); 3093 driver->num, driver->name);
@@ -3269,13 +3099,28 @@ int tty_register_driver(struct tty_driver *driver)
3269 dev = MKDEV(driver->major, driver->minor_start); 3099 dev = MKDEV(driver->major, driver->minor_start);
3270 error = register_chrdev_region(dev, driver->num, driver->name); 3100 error = register_chrdev_region(dev, driver->num, driver->name);
3271 } 3101 }
3272 if (error < 0) 3102 if (error < 0) {
3273 goto err; 3103 kfree(p);
3104 return error;
3105 }
3274 3106
3275 if (driver->flags & TTY_DRIVER_DYNAMIC_ALLOC) { 3107 if (p) {
3276 error = tty_cdev_add(driver, dev, 0, driver->num); 3108 driver->ttys = (struct tty_struct **)p;
3277 if (error) 3109 driver->termios = (struct ktermios **)(p + driver->num);
3278 goto err_unreg_char; 3110 } else {
3111 driver->ttys = NULL;
3112 driver->termios = NULL;
3113 }
3114
3115 cdev_init(&driver->cdev, &tty_fops);
3116 driver->cdev.owner = driver->owner;
3117 error = cdev_add(&driver->cdev, dev, driver->num);
3118 if (error) {
3119 unregister_chrdev_region(dev, driver->num);
3120 driver->ttys = NULL;
3121 driver->termios = NULL;
3122 kfree(p);
3123 return error;
3279 } 3124 }
3280 3125
3281 mutex_lock(&tty_mutex); 3126 mutex_lock(&tty_mutex);
@@ -3287,7 +3132,7 @@ int tty_register_driver(struct tty_driver *driver)
3287 d = tty_register_device(driver, i, NULL); 3132 d = tty_register_device(driver, i, NULL);
3288 if (IS_ERR(d)) { 3133 if (IS_ERR(d)) {
3289 error = PTR_ERR(d); 3134 error = PTR_ERR(d);
3290 goto err_unreg_devs; 3135 goto err;
3291 } 3136 }
3292 } 3137 }
3293 } 3138 }
@@ -3295,7 +3140,7 @@ int tty_register_driver(struct tty_driver *driver)
3295 driver->flags |= TTY_DRIVER_INSTALLED; 3140 driver->flags |= TTY_DRIVER_INSTALLED;
3296 return 0; 3141 return 0;
3297 3142
3298err_unreg_devs: 3143err:
3299 for (i--; i >= 0; i--) 3144 for (i--; i >= 0; i--)
3300 tty_unregister_device(driver, i); 3145 tty_unregister_device(driver, i);
3301 3146
@@ -3303,11 +3148,13 @@ err_unreg_devs:
3303 list_del(&driver->tty_drivers); 3148 list_del(&driver->tty_drivers);
3304 mutex_unlock(&tty_mutex); 3149 mutex_unlock(&tty_mutex);
3305 3150
3306err_unreg_char:
3307 unregister_chrdev_region(dev, driver->num); 3151 unregister_chrdev_region(dev, driver->num);
3308err: 3152 driver->ttys = NULL;
3153 driver->termios = NULL;
3154 kfree(p);
3309 return error; 3155 return error;
3310} 3156}
3157
3311EXPORT_SYMBOL(tty_register_driver); 3158EXPORT_SYMBOL(tty_register_driver);
3312 3159
3313/* 3160/*
@@ -3418,7 +3265,7 @@ void __init console_init(void)
3418 } 3265 }
3419} 3266}
3420 3267
3421static char *tty_devnode(struct device *dev, umode_t *mode) 3268static char *tty_devnode(struct device *dev, mode_t *mode)
3422{ 3269{
3423 if (!mode) 3270 if (!mode)
3424 return NULL; 3271 return NULL;
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 8481b29d5b3..53f2442c609 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -19,10 +19,10 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/bitops.h> 20#include <linux/bitops.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/compat.h>
23 22
24#include <asm/io.h> 23#include <asm/io.h>
25#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25#include <asm/system.h>
26 26
27#undef TTY_DEBUG_WAIT_UNTIL_SENT 27#undef TTY_DEBUG_WAIT_UNTIL_SENT
28 28
@@ -410,7 +410,7 @@ EXPORT_SYMBOL_GPL(tty_termios_encode_baud_rate);
410 410
411void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud, speed_t obaud) 411void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud, speed_t obaud)
412{ 412{
413 tty_termios_encode_baud_rate(&tty->termios, ibaud, obaud); 413 tty_termios_encode_baud_rate(tty->termios, ibaud, obaud);
414} 414}
415EXPORT_SYMBOL_GPL(tty_encode_baud_rate); 415EXPORT_SYMBOL_GPL(tty_encode_baud_rate);
416 416
@@ -427,7 +427,7 @@ EXPORT_SYMBOL_GPL(tty_encode_baud_rate);
427 427
428speed_t tty_get_baud_rate(struct tty_struct *tty) 428speed_t tty_get_baud_rate(struct tty_struct *tty)
429{ 429{
430 speed_t baud = tty_termios_baud_rate(&tty->termios); 430 speed_t baud = tty_termios_baud_rate(tty->termios);
431 431
432 if (baud == 38400 && tty->alt_speed) { 432 if (baud == 38400 && tty->alt_speed) {
433 if (!tty->warned) { 433 if (!tty->warned) {
@@ -509,14 +509,14 @@ int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios)
509 /* FIXME: we need to decide on some locking/ordering semantics 509 /* FIXME: we need to decide on some locking/ordering semantics
510 for the set_termios notification eventually */ 510 for the set_termios notification eventually */
511 mutex_lock(&tty->termios_mutex); 511 mutex_lock(&tty->termios_mutex);
512 old_termios = tty->termios; 512 old_termios = *tty->termios;
513 tty->termios = *new_termios; 513 *tty->termios = *new_termios;
514 unset_locked_termios(&tty->termios, &old_termios, &tty->termios_locked); 514 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked);
515 515
516 /* See if packet mode change of state. */ 516 /* See if packet mode change of state. */
517 if (tty->link && tty->link->packet) { 517 if (tty->link && tty->link->packet) {
518 int extproc = (old_termios.c_lflag & EXTPROC) | 518 int extproc = (old_termios.c_lflag & EXTPROC) |
519 (tty->termios.c_lflag & EXTPROC); 519 (tty->termios->c_lflag & EXTPROC);
520 int old_flow = ((old_termios.c_iflag & IXON) && 520 int old_flow = ((old_termios.c_iflag & IXON) &&
521 (old_termios.c_cc[VSTOP] == '\023') && 521 (old_termios.c_cc[VSTOP] == '\023') &&
522 (old_termios.c_cc[VSTART] == '\021')); 522 (old_termios.c_cc[VSTART] == '\021'));
@@ -542,7 +542,7 @@ int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios)
542 if (tty->ops->set_termios) 542 if (tty->ops->set_termios)
543 (*tty->ops->set_termios)(tty, &old_termios); 543 (*tty->ops->set_termios)(tty, &old_termios);
544 else 544 else
545 tty_termios_copy_hw(&tty->termios, &old_termios); 545 tty_termios_copy_hw(tty->termios, &old_termios);
546 546
547 ld = tty_ldisc_ref(tty); 547 ld = tty_ldisc_ref(tty);
548 if (ld != NULL) { 548 if (ld != NULL) {
@@ -578,7 +578,7 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
578 return retval; 578 return retval;
579 579
580 mutex_lock(&tty->termios_mutex); 580 mutex_lock(&tty->termios_mutex);
581 tmp_termios = tty->termios; 581 memcpy(&tmp_termios, tty->termios, sizeof(struct ktermios));
582 mutex_unlock(&tty->termios_mutex); 582 mutex_unlock(&tty->termios_mutex);
583 583
584 if (opt & TERMIOS_TERMIO) { 584 if (opt & TERMIOS_TERMIO) {
@@ -632,14 +632,14 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
632static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) 632static void copy_termios(struct tty_struct *tty, struct ktermios *kterm)
633{ 633{
634 mutex_lock(&tty->termios_mutex); 634 mutex_lock(&tty->termios_mutex);
635 *kterm = tty->termios; 635 memcpy(kterm, tty->termios, sizeof(struct ktermios));
636 mutex_unlock(&tty->termios_mutex); 636 mutex_unlock(&tty->termios_mutex);
637} 637}
638 638
639static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) 639static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm)
640{ 640{
641 mutex_lock(&tty->termios_mutex); 641 mutex_lock(&tty->termios_mutex);
642 *kterm = tty->termios_locked; 642 memcpy(kterm, tty->termios_locked, sizeof(struct ktermios));
643 mutex_unlock(&tty->termios_mutex); 643 mutex_unlock(&tty->termios_mutex);
644} 644}
645 645
@@ -707,16 +707,16 @@ static int get_sgflags(struct tty_struct *tty)
707{ 707{
708 int flags = 0; 708 int flags = 0;
709 709
710 if (!(tty->termios.c_lflag & ICANON)) { 710 if (!(tty->termios->c_lflag & ICANON)) {
711 if (tty->termios.c_lflag & ISIG) 711 if (tty->termios->c_lflag & ISIG)
712 flags |= 0x02; /* cbreak */ 712 flags |= 0x02; /* cbreak */
713 else 713 else
714 flags |= 0x20; /* raw */ 714 flags |= 0x20; /* raw */
715 } 715 }
716 if (tty->termios.c_lflag & ECHO) 716 if (tty->termios->c_lflag & ECHO)
717 flags |= 0x08; /* echo */ 717 flags |= 0x08; /* echo */
718 if (tty->termios.c_oflag & OPOST) 718 if (tty->termios->c_oflag & OPOST)
719 if (tty->termios.c_oflag & ONLCR) 719 if (tty->termios->c_oflag & ONLCR)
720 flags |= 0x10; /* crmod */ 720 flags |= 0x10; /* crmod */
721 return flags; 721 return flags;
722} 722}
@@ -726,10 +726,10 @@ static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb)
726 struct sgttyb tmp; 726 struct sgttyb tmp;
727 727
728 mutex_lock(&tty->termios_mutex); 728 mutex_lock(&tty->termios_mutex);
729 tmp.sg_ispeed = tty->termios.c_ispeed; 729 tmp.sg_ispeed = tty->termios->c_ispeed;
730 tmp.sg_ospeed = tty->termios.c_ospeed; 730 tmp.sg_ospeed = tty->termios->c_ospeed;
731 tmp.sg_erase = tty->termios.c_cc[VERASE]; 731 tmp.sg_erase = tty->termios->c_cc[VERASE];
732 tmp.sg_kill = tty->termios.c_cc[VKILL]; 732 tmp.sg_kill = tty->termios->c_cc[VKILL];
733 tmp.sg_flags = get_sgflags(tty); 733 tmp.sg_flags = get_sgflags(tty);
734 mutex_unlock(&tty->termios_mutex); 734 mutex_unlock(&tty->termios_mutex);
735 735
@@ -787,7 +787,7 @@ static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb)
787 return -EFAULT; 787 return -EFAULT;
788 788
789 mutex_lock(&tty->termios_mutex); 789 mutex_lock(&tty->termios_mutex);
790 termios = tty->termios; 790 termios = *tty->termios;
791 termios.c_cc[VERASE] = tmp.sg_erase; 791 termios.c_cc[VERASE] = tmp.sg_erase;
792 termios.c_cc[VKILL] = tmp.sg_kill; 792 termios.c_cc[VKILL] = tmp.sg_kill;
793 set_sgflags(&termios, tmp.sg_flags); 793 set_sgflags(&termios, tmp.sg_flags);
@@ -808,12 +808,12 @@ static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars)
808 struct tchars tmp; 808 struct tchars tmp;
809 809
810 mutex_lock(&tty->termios_mutex); 810 mutex_lock(&tty->termios_mutex);
811 tmp.t_intrc = tty->termios.c_cc[VINTR]; 811 tmp.t_intrc = tty->termios->c_cc[VINTR];
812 tmp.t_quitc = tty->termios.c_cc[VQUIT]; 812 tmp.t_quitc = tty->termios->c_cc[VQUIT];
813 tmp.t_startc = tty->termios.c_cc[VSTART]; 813 tmp.t_startc = tty->termios->c_cc[VSTART];
814 tmp.t_stopc = tty->termios.c_cc[VSTOP]; 814 tmp.t_stopc = tty->termios->c_cc[VSTOP];
815 tmp.t_eofc = tty->termios.c_cc[VEOF]; 815 tmp.t_eofc = tty->termios->c_cc[VEOF];
816 tmp.t_brkc = tty->termios.c_cc[VEOL2]; /* what is brkc anyway? */ 816 tmp.t_brkc = tty->termios->c_cc[VEOL2]; /* what is brkc anyway? */
817 mutex_unlock(&tty->termios_mutex); 817 mutex_unlock(&tty->termios_mutex);
818 return copy_to_user(tchars, &tmp, sizeof(tmp)) ? -EFAULT : 0; 818 return copy_to_user(tchars, &tmp, sizeof(tmp)) ? -EFAULT : 0;
819} 819}
@@ -825,12 +825,12 @@ static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars)
825 if (copy_from_user(&tmp, tchars, sizeof(tmp))) 825 if (copy_from_user(&tmp, tchars, sizeof(tmp)))
826 return -EFAULT; 826 return -EFAULT;
827 mutex_lock(&tty->termios_mutex); 827 mutex_lock(&tty->termios_mutex);
828 tty->termios.c_cc[VINTR] = tmp.t_intrc; 828 tty->termios->c_cc[VINTR] = tmp.t_intrc;
829 tty->termios.c_cc[VQUIT] = tmp.t_quitc; 829 tty->termios->c_cc[VQUIT] = tmp.t_quitc;
830 tty->termios.c_cc[VSTART] = tmp.t_startc; 830 tty->termios->c_cc[VSTART] = tmp.t_startc;
831 tty->termios.c_cc[VSTOP] = tmp.t_stopc; 831 tty->termios->c_cc[VSTOP] = tmp.t_stopc;
832 tty->termios.c_cc[VEOF] = tmp.t_eofc; 832 tty->termios->c_cc[VEOF] = tmp.t_eofc;
833 tty->termios.c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */ 833 tty->termios->c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */
834 mutex_unlock(&tty->termios_mutex); 834 mutex_unlock(&tty->termios_mutex);
835 return 0; 835 return 0;
836} 836}
@@ -842,14 +842,14 @@ static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
842 struct ltchars tmp; 842 struct ltchars tmp;
843 843
844 mutex_lock(&tty->termios_mutex); 844 mutex_lock(&tty->termios_mutex);
845 tmp.t_suspc = tty->termios.c_cc[VSUSP]; 845 tmp.t_suspc = tty->termios->c_cc[VSUSP];
846 /* what is dsuspc anyway? */ 846 /* what is dsuspc anyway? */
847 tmp.t_dsuspc = tty->termios.c_cc[VSUSP]; 847 tmp.t_dsuspc = tty->termios->c_cc[VSUSP];
848 tmp.t_rprntc = tty->termios.c_cc[VREPRINT]; 848 tmp.t_rprntc = tty->termios->c_cc[VREPRINT];
849 /* what is flushc anyway? */ 849 /* what is flushc anyway? */
850 tmp.t_flushc = tty->termios.c_cc[VEOL2]; 850 tmp.t_flushc = tty->termios->c_cc[VEOL2];
851 tmp.t_werasc = tty->termios.c_cc[VWERASE]; 851 tmp.t_werasc = tty->termios->c_cc[VWERASE];
852 tmp.t_lnextc = tty->termios.c_cc[VLNEXT]; 852 tmp.t_lnextc = tty->termios->c_cc[VLNEXT];
853 mutex_unlock(&tty->termios_mutex); 853 mutex_unlock(&tty->termios_mutex);
854 return copy_to_user(ltchars, &tmp, sizeof(tmp)) ? -EFAULT : 0; 854 return copy_to_user(ltchars, &tmp, sizeof(tmp)) ? -EFAULT : 0;
855} 855}
@@ -862,14 +862,14 @@ static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
862 return -EFAULT; 862 return -EFAULT;
863 863
864 mutex_lock(&tty->termios_mutex); 864 mutex_lock(&tty->termios_mutex);
865 tty->termios.c_cc[VSUSP] = tmp.t_suspc; 865 tty->termios->c_cc[VSUSP] = tmp.t_suspc;
866 /* what is dsuspc anyway? */ 866 /* what is dsuspc anyway? */
867 tty->termios.c_cc[VEOL2] = tmp.t_dsuspc; 867 tty->termios->c_cc[VEOL2] = tmp.t_dsuspc;
868 tty->termios.c_cc[VREPRINT] = tmp.t_rprntc; 868 tty->termios->c_cc[VREPRINT] = tmp.t_rprntc;
869 /* what is flushc anyway? */ 869 /* what is flushc anyway? */
870 tty->termios.c_cc[VEOL2] = tmp.t_flushc; 870 tty->termios->c_cc[VEOL2] = tmp.t_flushc;
871 tty->termios.c_cc[VWERASE] = tmp.t_werasc; 871 tty->termios->c_cc[VWERASE] = tmp.t_werasc;
872 tty->termios.c_cc[VLNEXT] = tmp.t_lnextc; 872 tty->termios->c_cc[VLNEXT] = tmp.t_lnextc;
873 mutex_unlock(&tty->termios_mutex); 873 mutex_unlock(&tty->termios_mutex);
874 return 0; 874 return 0;
875} 875}
@@ -920,12 +920,12 @@ static int tty_change_softcar(struct tty_struct *tty, int arg)
920 struct ktermios old; 920 struct ktermios old;
921 921
922 mutex_lock(&tty->termios_mutex); 922 mutex_lock(&tty->termios_mutex);
923 old = tty->termios; 923 old = *tty->termios;
924 tty->termios.c_cflag &= ~CLOCAL; 924 tty->termios->c_cflag &= ~CLOCAL;
925 tty->termios.c_cflag |= bit; 925 tty->termios->c_cflag |= bit;
926 if (tty->ops->set_termios) 926 if (tty->ops->set_termios)
927 tty->ops->set_termios(tty, &old); 927 tty->ops->set_termios(tty, &old);
928 if ((tty->termios.c_cflag & CLOCAL) != bit) 928 if ((tty->termios->c_cflag & CLOCAL) != bit)
929 ret = -EINVAL; 929 ret = -EINVAL;
930 mutex_unlock(&tty->termios_mutex); 930 mutex_unlock(&tty->termios_mutex);
931 return ret; 931 return ret;
@@ -1031,7 +1031,7 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
1031 (struct termios __user *) arg)) 1031 (struct termios __user *) arg))
1032 return -EFAULT; 1032 return -EFAULT;
1033 mutex_lock(&real_tty->termios_mutex); 1033 mutex_lock(&real_tty->termios_mutex);
1034 real_tty->termios_locked = kterm; 1034 memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios));
1035 mutex_unlock(&real_tty->termios_mutex); 1035 mutex_unlock(&real_tty->termios_mutex);
1036 return 0; 1036 return 0;
1037#else 1037#else
@@ -1048,7 +1048,7 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
1048 (struct termios __user *) arg)) 1048 (struct termios __user *) arg))
1049 return -EFAULT; 1049 return -EFAULT;
1050 mutex_lock(&real_tty->termios_mutex); 1050 mutex_lock(&real_tty->termios_mutex);
1051 real_tty->termios_locked = kterm; 1051 memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios));
1052 mutex_unlock(&real_tty->termios_mutex); 1052 mutex_unlock(&real_tty->termios_mutex);
1053 return ret; 1053 return ret;
1054#endif 1054#endif
@@ -1118,6 +1118,7 @@ EXPORT_SYMBOL_GPL(tty_perform_flush);
1118int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, 1118int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
1119 unsigned int cmd, unsigned long arg) 1119 unsigned int cmd, unsigned long arg)
1120{ 1120{
1121 unsigned long flags;
1121 int retval; 1122 int retval;
1122 1123
1123 switch (cmd) { 1124 switch (cmd) {
@@ -1152,25 +1153,29 @@ int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
1152 return 0; 1153 return 0;
1153 case TCFLSH: 1154 case TCFLSH:
1154 return tty_perform_flush(tty, arg); 1155 return tty_perform_flush(tty, arg);
1156 case TIOCPKT:
1157 {
1158 int pktmode;
1159
1160 if (tty->driver->type != TTY_DRIVER_TYPE_PTY ||
1161 tty->driver->subtype != PTY_TYPE_MASTER)
1162 return -ENOTTY;
1163 if (get_user(pktmode, (int __user *) arg))
1164 return -EFAULT;
1165 spin_lock_irqsave(&tty->ctrl_lock, flags);
1166 if (pktmode) {
1167 if (!tty->packet) {
1168 tty->packet = 1;
1169 tty->link->ctrl_status = 0;
1170 }
1171 } else
1172 tty->packet = 0;
1173 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1174 return 0;
1175 }
1155 default: 1176 default:
1156 /* Try the mode commands */ 1177 /* Try the mode commands */
1157 return tty_mode_ioctl(tty, file, cmd, arg); 1178 return tty_mode_ioctl(tty, file, cmd, arg);
1158 } 1179 }
1159} 1180}
1160EXPORT_SYMBOL(n_tty_ioctl_helper); 1181EXPORT_SYMBOL(n_tty_ioctl_helper);
1161
1162#ifdef CONFIG_COMPAT
1163long n_tty_compat_ioctl_helper(struct tty_struct *tty, struct file *file,
1164 unsigned int cmd, unsigned long arg)
1165{
1166 switch (cmd) {
1167 case TIOCGLCKTRMIOS:
1168 case TIOCSLCKTRMIOS:
1169 return tty_mode_ioctl(tty, file, cmd, (unsigned long) compat_ptr(arg));
1170 default:
1171 return -ENOIOCTLCMD;
1172 }
1173}
1174EXPORT_SYMBOL(n_tty_compat_ioctl_helper);
1175#endif
1176
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index c5782294e53..a76c808afad 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -1,11 +1,19 @@
1#include <linux/types.h> 1#include <linux/types.h>
2#include <linux/major.h>
2#include <linux/errno.h> 3#include <linux/errno.h>
3#include <linux/kmod.h> 4#include <linux/signal.h>
5#include <linux/fcntl.h>
4#include <linux/sched.h> 6#include <linux/sched.h>
5#include <linux/interrupt.h> 7#include <linux/interrupt.h>
6#include <linux/tty.h> 8#include <linux/tty.h>
7#include <linux/tty_driver.h> 9#include <linux/tty_driver.h>
10#include <linux/tty_flip.h>
11#include <linux/devpts_fs.h>
8#include <linux/file.h> 12#include <linux/file.h>
13#include <linux/console.h>
14#include <linux/timer.h>
15#include <linux/ctype.h>
16#include <linux/kd.h>
9#include <linux/mm.h> 17#include <linux/mm.h>
10#include <linux/string.h> 18#include <linux/string.h>
11#include <linux/slab.h> 19#include <linux/slab.h>
@@ -16,8 +24,18 @@
16#include <linux/device.h> 24#include <linux/device.h>
17#include <linux/wait.h> 25#include <linux/wait.h>
18#include <linux/bitops.h> 26#include <linux/bitops.h>
27#include <linux/delay.h>
19#include <linux/seq_file.h> 28#include <linux/seq_file.h>
29
20#include <linux/uaccess.h> 30#include <linux/uaccess.h>
31#include <asm/system.h>
32
33#include <linux/kbd_kern.h>
34#include <linux/vt_kern.h>
35#include <linux/selection.h>
36
37#include <linux/kmod.h>
38#include <linux/nsproxy.h>
21#include <linux/ratelimit.h> 39#include <linux/ratelimit.h>
22 40
23/* 41/*
@@ -26,8 +44,9 @@
26 * callers who will do ldisc lookups and cannot sleep. 44 * callers who will do ldisc lookups and cannot sleep.
27 */ 45 */
28 46
29static DEFINE_RAW_SPINLOCK(tty_ldisc_lock); 47static DEFINE_SPINLOCK(tty_ldisc_lock);
30static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); 48static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
49static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_idle);
31/* Line disc dispatch table */ 50/* Line disc dispatch table */
32static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; 51static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
33 52
@@ -49,22 +68,22 @@ static void put_ldisc(struct tty_ldisc *ld)
49 * If this is the last user, free the ldisc, and 68 * If this is the last user, free the ldisc, and
50 * release the ldisc ops. 69 * release the ldisc ops.
51 * 70 *
52 * We really want an "atomic_dec_and_raw_lock_irqsave()", 71 * We really want an "atomic_dec_and_lock_irqsave()",
53 * but we don't have it, so this does it by hand. 72 * but we don't have it, so this does it by hand.
54 */ 73 */
55 raw_spin_lock_irqsave(&tty_ldisc_lock, flags); 74 local_irq_save(flags);
56 if (atomic_dec_and_test(&ld->users)) { 75 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
57 struct tty_ldisc_ops *ldo = ld->ops; 76 struct tty_ldisc_ops *ldo = ld->ops;
58 77
59 ldo->refcount--; 78 ldo->refcount--;
60 module_put(ldo->owner); 79 module_put(ldo->owner);
61 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags); 80 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
62 81
63 kfree(ld); 82 kfree(ld);
64 return; 83 return;
65 } 84 }
66 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags); 85 local_irq_restore(flags);
67 wake_up(&ld->wq_idle); 86 wake_up(&tty_ldisc_idle);
68} 87}
69 88
70/** 89/**
@@ -88,11 +107,11 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
88 if (disc < N_TTY || disc >= NR_LDISCS) 107 if (disc < N_TTY || disc >= NR_LDISCS)
89 return -EINVAL; 108 return -EINVAL;
90 109
91 raw_spin_lock_irqsave(&tty_ldisc_lock, flags); 110 spin_lock_irqsave(&tty_ldisc_lock, flags);
92 tty_ldiscs[disc] = new_ldisc; 111 tty_ldiscs[disc] = new_ldisc;
93 new_ldisc->num = disc; 112 new_ldisc->num = disc;
94 new_ldisc->refcount = 0; 113 new_ldisc->refcount = 0;
95 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags); 114 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
96 115
97 return ret; 116 return ret;
98} 117}
@@ -118,12 +137,12 @@ int tty_unregister_ldisc(int disc)
118 if (disc < N_TTY || disc >= NR_LDISCS) 137 if (disc < N_TTY || disc >= NR_LDISCS)
119 return -EINVAL; 138 return -EINVAL;
120 139
121 raw_spin_lock_irqsave(&tty_ldisc_lock, flags); 140 spin_lock_irqsave(&tty_ldisc_lock, flags);
122 if (tty_ldiscs[disc]->refcount) 141 if (tty_ldiscs[disc]->refcount)
123 ret = -EBUSY; 142 ret = -EBUSY;
124 else 143 else
125 tty_ldiscs[disc] = NULL; 144 tty_ldiscs[disc] = NULL;
126 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags); 145 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
127 146
128 return ret; 147 return ret;
129} 148}
@@ -134,7 +153,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
134 unsigned long flags; 153 unsigned long flags;
135 struct tty_ldisc_ops *ldops, *ret; 154 struct tty_ldisc_ops *ldops, *ret;
136 155
137 raw_spin_lock_irqsave(&tty_ldisc_lock, flags); 156 spin_lock_irqsave(&tty_ldisc_lock, flags);
138 ret = ERR_PTR(-EINVAL); 157 ret = ERR_PTR(-EINVAL);
139 ldops = tty_ldiscs[disc]; 158 ldops = tty_ldiscs[disc];
140 if (ldops) { 159 if (ldops) {
@@ -144,7 +163,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
144 ret = ldops; 163 ret = ldops;
145 } 164 }
146 } 165 }
147 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags); 166 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
148 return ret; 167 return ret;
149} 168}
150 169
@@ -152,10 +171,10 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
152{ 171{
153 unsigned long flags; 172 unsigned long flags;
154 173
155 raw_spin_lock_irqsave(&tty_ldisc_lock, flags); 174 spin_lock_irqsave(&tty_ldisc_lock, flags);
156 ldops->refcount--; 175 ldops->refcount--;
157 module_put(ldops->owner); 176 module_put(ldops->owner);
158 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags); 177 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
159} 178}
160 179
161/** 180/**
@@ -199,8 +218,6 @@ static struct tty_ldisc *tty_ldisc_get(int disc)
199 218
200 ld->ops = ldops; 219 ld->ops = ldops;
201 atomic_set(&ld->users, 1); 220 atomic_set(&ld->users, 1);
202 init_waitqueue_head(&ld->wq_idle);
203
204 return ld; 221 return ld;
205} 222}
206 223
@@ -287,11 +304,11 @@ static struct tty_ldisc *tty_ldisc_try(struct tty_struct *tty)
287 unsigned long flags; 304 unsigned long flags;
288 struct tty_ldisc *ld; 305 struct tty_ldisc *ld;
289 306
290 raw_spin_lock_irqsave(&tty_ldisc_lock, flags); 307 spin_lock_irqsave(&tty_ldisc_lock, flags);
291 ld = NULL; 308 ld = NULL;
292 if (test_bit(TTY_LDISC, &tty->flags)) 309 if (test_bit(TTY_LDISC, &tty->flags))
293 ld = get_ldisc(tty->ldisc); 310 ld = get_ldisc(tty->ldisc);
294 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags); 311 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
295 return ld; 312 return ld;
296} 313}
297 314
@@ -413,7 +430,7 @@ EXPORT_SYMBOL_GPL(tty_ldisc_flush);
413static void tty_set_termios_ldisc(struct tty_struct *tty, int num) 430static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
414{ 431{
415 mutex_lock(&tty->termios_mutex); 432 mutex_lock(&tty->termios_mutex);
416 tty->termios.c_line = num; 433 tty->termios->c_line = num;
417 mutex_unlock(&tty->termios_mutex); 434 mutex_unlock(&tty->termios_mutex);
418} 435}
419 436
@@ -434,6 +451,7 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
434 if (ld->ops->open) { 451 if (ld->ops->open) {
435 int ret; 452 int ret;
436 /* BTM here locks versus a hangup event */ 453 /* BTM here locks versus a hangup event */
454 WARN_ON(!tty_locked());
437 ret = ld->ops->open(tty); 455 ret = ld->ops->open(tty);
438 if (ret) 456 if (ret)
439 clear_bit(TTY_LDISC_OPEN, &tty->flags); 457 clear_bit(TTY_LDISC_OPEN, &tty->flags);
@@ -512,7 +530,7 @@ static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
512static int tty_ldisc_halt(struct tty_struct *tty) 530static int tty_ldisc_halt(struct tty_struct *tty)
513{ 531{
514 clear_bit(TTY_LDISC, &tty->flags); 532 clear_bit(TTY_LDISC, &tty->flags);
515 return cancel_work_sync(&tty->port->buf.work); 533 return cancel_work_sync(&tty->buf.work);
516} 534}
517 535
518/** 536/**
@@ -523,9 +541,9 @@ static int tty_ldisc_halt(struct tty_struct *tty)
523 */ 541 */
524static void tty_ldisc_flush_works(struct tty_struct *tty) 542static void tty_ldisc_flush_works(struct tty_struct *tty)
525{ 543{
526 flush_work(&tty->hangup_work); 544 flush_work_sync(&tty->hangup_work);
527 flush_work(&tty->SAK_work); 545 flush_work_sync(&tty->SAK_work);
528 flush_work(&tty->port->buf.work); 546 flush_work_sync(&tty->buf.work);
529} 547}
530 548
531/** 549/**
@@ -539,8 +557,10 @@ static void tty_ldisc_flush_works(struct tty_struct *tty)
539static int tty_ldisc_wait_idle(struct tty_struct *tty, long timeout) 557static int tty_ldisc_wait_idle(struct tty_struct *tty, long timeout)
540{ 558{
541 long ret; 559 long ret;
542 ret = wait_event_timeout(tty->ldisc->wq_idle, 560 ret = wait_event_timeout(tty_ldisc_idle,
543 atomic_read(&tty->ldisc->users) == 1, timeout); 561 atomic_read(&tty->ldisc->users) == 1, timeout);
562 if (ret < 0)
563 return ret;
544 return ret > 0 ? 0 : -EBUSY; 564 return ret > 0 ? 0 : -EBUSY;
545} 565}
546 566
@@ -568,7 +588,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
568 if (IS_ERR(new_ldisc)) 588 if (IS_ERR(new_ldisc))
569 return PTR_ERR(new_ldisc); 589 return PTR_ERR(new_ldisc);
570 590
571 tty_lock(tty); 591 tty_lock();
572 /* 592 /*
573 * We need to look at the tty locking here for pty/tty pairs 593 * We need to look at the tty locking here for pty/tty pairs
574 * when both sides try to change in parallel. 594 * when both sides try to change in parallel.
@@ -582,12 +602,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
582 */ 602 */
583 603
584 if (tty->ldisc->ops->num == ldisc) { 604 if (tty->ldisc->ops->num == ldisc) {
585 tty_unlock(tty); 605 tty_unlock();
586 tty_ldisc_put(new_ldisc); 606 tty_ldisc_put(new_ldisc);
587 return 0; 607 return 0;
588 } 608 }
589 609
590 tty_unlock(tty); 610 tty_unlock();
591 /* 611 /*
592 * Problem: What do we do if this blocks ? 612 * Problem: What do we do if this blocks ?
593 * We could deadlock here 613 * We could deadlock here
@@ -595,7 +615,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
595 615
596 tty_wait_until_sent(tty, 0); 616 tty_wait_until_sent(tty, 0);
597 617
598 tty_lock(tty); 618 tty_lock();
599 mutex_lock(&tty->ldisc_mutex); 619 mutex_lock(&tty->ldisc_mutex);
600 620
601 /* 621 /*
@@ -605,10 +625,10 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
605 625
606 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { 626 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
607 mutex_unlock(&tty->ldisc_mutex); 627 mutex_unlock(&tty->ldisc_mutex);
608 tty_unlock(tty); 628 tty_unlock();
609 wait_event(tty_ldisc_wait, 629 wait_event(tty_ldisc_wait,
610 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); 630 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
611 tty_lock(tty); 631 tty_lock();
612 mutex_lock(&tty->ldisc_mutex); 632 mutex_lock(&tty->ldisc_mutex);
613 } 633 }
614 634
@@ -623,7 +643,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
623 643
624 o_ldisc = tty->ldisc; 644 o_ldisc = tty->ldisc;
625 645
626 tty_unlock(tty); 646 tty_unlock();
627 /* 647 /*
628 * Make sure we don't change while someone holds a 648 * Make sure we don't change while someone holds a
629 * reference to the line discipline. The TTY_LDISC bit 649 * reference to the line discipline. The TTY_LDISC bit
@@ -650,7 +670,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
650 670
651 retval = tty_ldisc_wait_idle(tty, 5 * HZ); 671 retval = tty_ldisc_wait_idle(tty, 5 * HZ);
652 672
653 tty_lock(tty); 673 tty_lock();
654 mutex_lock(&tty->ldisc_mutex); 674 mutex_lock(&tty->ldisc_mutex);
655 675
656 /* handle wait idle failure locked */ 676 /* handle wait idle failure locked */
@@ -659,13 +679,13 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
659 goto enable; 679 goto enable;
660 } 680 }
661 681
662 if (test_bit(TTY_HUPPING, &tty->flags)) { 682 if (test_bit(TTY_HUPPED, &tty->flags)) {
663 /* We were raced by the hangup method. It will have stomped 683 /* We were raced by the hangup method. It will have stomped
664 the ldisc data and closed the ldisc down */ 684 the ldisc data and closed the ldisc down */
665 clear_bit(TTY_LDISC_CHANGING, &tty->flags); 685 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
666 mutex_unlock(&tty->ldisc_mutex); 686 mutex_unlock(&tty->ldisc_mutex);
667 tty_ldisc_put(new_ldisc); 687 tty_ldisc_put(new_ldisc);
668 tty_unlock(tty); 688 tty_unlock();
669 return -EIO; 689 return -EIO;
670 } 690 }
671 691
@@ -704,11 +724,11 @@ enable:
704 /* Restart the work queue in case no characters kick it off. Safe if 724 /* Restart the work queue in case no characters kick it off. Safe if
705 already running */ 725 already running */
706 if (work) 726 if (work)
707 schedule_work(&tty->port->buf.work); 727 schedule_work(&tty->buf.work);
708 if (o_work) 728 if (o_work)
709 schedule_work(&o_tty->port->buf.work); 729 schedule_work(&o_tty->buf.work);
710 mutex_unlock(&tty->ldisc_mutex); 730 mutex_unlock(&tty->ldisc_mutex);
711 tty_unlock(tty); 731 tty_unlock();
712 return retval; 732 return retval;
713} 733}
714 734
@@ -722,9 +742,9 @@ enable:
722static void tty_reset_termios(struct tty_struct *tty) 742static void tty_reset_termios(struct tty_struct *tty)
723{ 743{
724 mutex_lock(&tty->termios_mutex); 744 mutex_lock(&tty->termios_mutex);
725 tty->termios = tty->driver->init_termios; 745 *tty->termios = tty->driver->init_termios;
726 tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); 746 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
727 tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); 747 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
728 mutex_unlock(&tty->termios_mutex); 748 mutex_unlock(&tty->termios_mutex);
729} 749}
730 750
@@ -816,11 +836,11 @@ void tty_ldisc_hangup(struct tty_struct *tty)
816 * need to wait for another function taking the BTM 836 * need to wait for another function taking the BTM
817 */ 837 */
818 clear_bit(TTY_LDISC, &tty->flags); 838 clear_bit(TTY_LDISC, &tty->flags);
819 tty_unlock(tty); 839 tty_unlock();
820 cancel_work_sync(&tty->port->buf.work); 840 cancel_work_sync(&tty->buf.work);
821 mutex_unlock(&tty->ldisc_mutex); 841 mutex_unlock(&tty->ldisc_mutex);
822retry: 842retry:
823 tty_lock(tty); 843 tty_lock();
824 mutex_lock(&tty->ldisc_mutex); 844 mutex_lock(&tty->ldisc_mutex);
825 845
826 /* At this point we have a closed ldisc and we want to 846 /* At this point we have a closed ldisc and we want to
@@ -831,7 +851,7 @@ retry:
831 if (atomic_read(&tty->ldisc->users) != 1) { 851 if (atomic_read(&tty->ldisc->users) != 1) {
832 char cur_n[TASK_COMM_LEN], tty_n[64]; 852 char cur_n[TASK_COMM_LEN], tty_n[64];
833 long timeout = 3 * HZ; 853 long timeout = 3 * HZ;
834 tty_unlock(tty); 854 tty_unlock();
835 855
836 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { 856 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) {
837 timeout = MAX_SCHEDULE_TIMEOUT; 857 timeout = MAX_SCHEDULE_TIMEOUT;
@@ -846,7 +866,7 @@ retry:
846 866
847 if (reset == 0) { 867 if (reset == 0) {
848 868
849 if (!tty_ldisc_reinit(tty, tty->termios.c_line)) 869 if (!tty_ldisc_reinit(tty, tty->termios->c_line))
850 err = tty_ldisc_open(tty, tty->ldisc); 870 err = tty_ldisc_open(tty, tty->ldisc);
851 else 871 else
852 err = 1; 872 err = 1;
@@ -894,28 +914,6 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
894 tty_ldisc_enable(tty); 914 tty_ldisc_enable(tty);
895 return 0; 915 return 0;
896} 916}
897
898static void tty_ldisc_kill(struct tty_struct *tty)
899{
900 /* There cannot be users from userspace now. But there still might be
901 * drivers holding a reference via tty_ldisc_ref. Do not steal them the
902 * ldisc until they are done. */
903 tty_ldisc_wait_idle(tty, MAX_SCHEDULE_TIMEOUT);
904
905 mutex_lock(&tty->ldisc_mutex);
906 /*
907 * Now kill off the ldisc
908 */
909 tty_ldisc_close(tty, tty->ldisc);
910 tty_ldisc_put(tty->ldisc);
911 /* Force an oops if we mess this up */
912 tty->ldisc = NULL;
913
914 /* Ensure the next open requests the N_TTY ldisc */
915 tty_set_termios_ldisc(tty, N_TTY);
916 mutex_unlock(&tty->ldisc_mutex);
917}
918
919/** 917/**
920 * tty_ldisc_release - release line discipline 918 * tty_ldisc_release - release line discipline
921 * @tty: tty being shut down 919 * @tty: tty being shut down
@@ -934,21 +932,28 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
934 * race with the set_ldisc code path. 932 * race with the set_ldisc code path.
935 */ 933 */
936 934
937 tty_lock_pair(tty, o_tty); 935 tty_unlock();
938 tty_ldisc_halt(tty); 936 tty_ldisc_halt(tty);
939 tty_ldisc_flush_works(tty); 937 tty_ldisc_flush_works(tty);
940 if (o_tty) { 938 tty_lock();
941 tty_ldisc_halt(o_tty);
942 tty_ldisc_flush_works(o_tty);
943 }
944 939
945 /* This will need doing differently if we need to lock */ 940 mutex_lock(&tty->ldisc_mutex);
946 tty_ldisc_kill(tty); 941 /*
942 * Now kill off the ldisc
943 */
944 tty_ldisc_close(tty, tty->ldisc);
945 tty_ldisc_put(tty->ldisc);
946 /* Force an oops if we mess this up */
947 tty->ldisc = NULL;
947 948
949 /* Ensure the next open requests the N_TTY ldisc */
950 tty_set_termios_ldisc(tty, N_TTY);
951 mutex_unlock(&tty->ldisc_mutex);
952
953 /* This will need doing differently if we need to lock */
948 if (o_tty) 954 if (o_tty)
949 tty_ldisc_kill(o_tty); 955 tty_ldisc_release(o_tty, NULL);
950 956
951 tty_unlock_pair(tty, o_tty);
952 /* And the memory resources remaining (buffers, termios) will be 957 /* And the memory resources remaining (buffers, termios) will be
953 disposed of when the kref hits zero */ 958 disposed of when the kref hits zero */
954} 959}
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 2e41abebbcb..3b2bb771944 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -4,70 +4,41 @@
4#include <linux/semaphore.h> 4#include <linux/semaphore.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6 6
7/* Legacy tty mutex glue */ 7/*
8 8 * The 'big tty mutex'
9enum { 9 *
10 TTY_MUTEX_NORMAL, 10 * This mutex is taken and released by tty_lock() and tty_unlock(),
11 TTY_MUTEX_NESTED, 11 * replacing the older big kernel lock.
12}; 12 * It can no longer be taken recursively, and does not get
13 * released implicitly while sleeping.
14 *
15 * Don't use in new code.
16 */
17static DEFINE_MUTEX(big_tty_mutex);
18struct task_struct *__big_tty_mutex_owner;
19EXPORT_SYMBOL_GPL(__big_tty_mutex_owner);
13 20
14/* 21/*
15 * Getting the big tty mutex. 22 * Getting the big tty mutex.
16 */ 23 */
17 24void __lockfunc tty_lock(void)
18static void __lockfunc tty_lock_nested(struct tty_struct *tty,
19 unsigned int subclass)
20{ 25{
21 if (tty->magic != TTY_MAGIC) { 26 struct task_struct *task = current;
22 pr_err("L Bad %p\n", tty);
23 WARN_ON(1);
24 return;
25 }
26 tty_kref_get(tty);
27 mutex_lock_nested(&tty->legacy_mutex, subclass);
28}
29 27
30void __lockfunc tty_lock(struct tty_struct *tty) 28 WARN_ON(__big_tty_mutex_owner == task);
31{ 29
32 return tty_lock_nested(tty, TTY_MUTEX_NORMAL); 30 mutex_lock(&big_tty_mutex);
31 __big_tty_mutex_owner = task;
33} 32}
34EXPORT_SYMBOL(tty_lock); 33EXPORT_SYMBOL(tty_lock);
35 34
36void __lockfunc tty_unlock(struct tty_struct *tty) 35void __lockfunc tty_unlock(void)
37{ 36{
38 if (tty->magic != TTY_MAGIC) { 37 struct task_struct *task = current;
39 pr_err("U Bad %p\n", tty);
40 WARN_ON(1);
41 return;
42 }
43 mutex_unlock(&tty->legacy_mutex);
44 tty_kref_put(tty);
45}
46EXPORT_SYMBOL(tty_unlock);
47 38
48/* 39 WARN_ON(__big_tty_mutex_owner != task);
49 * Getting the big tty mutex for a pair of ttys with lock ordering 40 __big_tty_mutex_owner = NULL;
50 * On a non pty/tty pair tty2 can be NULL which is just fine.
51 */
52void __lockfunc tty_lock_pair(struct tty_struct *tty,
53 struct tty_struct *tty2)
54{
55 if (tty < tty2) {
56 tty_lock(tty);
57 tty_lock_nested(tty2, TTY_MUTEX_NESTED);
58 } else {
59 if (tty2 && tty2 != tty)
60 tty_lock(tty2);
61 tty_lock_nested(tty, TTY_MUTEX_NESTED);
62 }
63}
64EXPORT_SYMBOL(tty_lock_pair);
65 41
66void __lockfunc tty_unlock_pair(struct tty_struct *tty, 42 mutex_unlock(&big_tty_mutex);
67 struct tty_struct *tty2)
68{
69 tty_unlock(tty);
70 if (tty2 && tty2 != tty)
71 tty_unlock(tty2);
72} 43}
73EXPORT_SYMBOL(tty_unlock_pair); 44EXPORT_SYMBOL(tty_unlock);
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index b7ff59d3db8..a4aaca0e014 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -21,7 +21,6 @@
21void tty_port_init(struct tty_port *port) 21void tty_port_init(struct tty_port *port)
22{ 22{
23 memset(port, 0, sizeof(*port)); 23 memset(port, 0, sizeof(*port));
24 tty_buffer_init(port);
25 init_waitqueue_head(&port->open_wait); 24 init_waitqueue_head(&port->open_wait);
26 init_waitqueue_head(&port->close_wait); 25 init_waitqueue_head(&port->close_wait);
27 init_waitqueue_head(&port->delta_msr_wait); 26 init_waitqueue_head(&port->delta_msr_wait);
@@ -34,70 +33,6 @@ void tty_port_init(struct tty_port *port)
34} 33}
35EXPORT_SYMBOL(tty_port_init); 34EXPORT_SYMBOL(tty_port_init);
36 35
37/**
38 * tty_port_link_device - link tty and tty_port
39 * @port: tty_port of the device
40 * @driver: tty_driver for this device
41 * @index: index of the tty
42 *
43 * Provide the tty layer wit ha link from a tty (specified by @index) to a
44 * tty_port (@port). Use this only if neither tty_port_register_device nor
45 * tty_port_install is used in the driver. If used, this has to be called before
46 * tty_register_driver.
47 */
48void tty_port_link_device(struct tty_port *port,
49 struct tty_driver *driver, unsigned index)
50{
51 if (WARN_ON(index >= driver->num))
52 return;
53 driver->ports[index] = port;
54}
55EXPORT_SYMBOL_GPL(tty_port_link_device);
56
57/**
58 * tty_port_register_device - register tty device
59 * @port: tty_port of the device
60 * @driver: tty_driver for this device
61 * @index: index of the tty
62 * @device: parent if exists, otherwise NULL
63 *
64 * It is the same as tty_register_device except the provided @port is linked to
65 * a concrete tty specified by @index. Use this or tty_port_install (or both).
66 * Call tty_port_link_device as a last resort.
67 */
68struct device *tty_port_register_device(struct tty_port *port,
69 struct tty_driver *driver, unsigned index,
70 struct device *device)
71{
72 tty_port_link_device(port, driver, index);
73 return tty_register_device(driver, index, device);
74}
75EXPORT_SYMBOL_GPL(tty_port_register_device);
76
77/**
78 * tty_port_register_device_attr - register tty device
79 * @port: tty_port of the device
80 * @driver: tty_driver for this device
81 * @index: index of the tty
82 * @device: parent if exists, otherwise NULL
83 * @drvdata: Driver data to be set to device.
84 * @attr_grp: Attribute group to be set on device.
85 *
86 * It is the same as tty_register_device_attr except the provided @port is
87 * linked to a concrete tty specified by @index. Use this or tty_port_install
88 * (or both). Call tty_port_link_device as a last resort.
89 */
90struct device *tty_port_register_device_attr(struct tty_port *port,
91 struct tty_driver *driver, unsigned index,
92 struct device *device, void *drvdata,
93 const struct attribute_group **attr_grp)
94{
95 tty_port_link_device(port, driver, index);
96 return tty_register_device_attr(driver, index, device, drvdata,
97 attr_grp);
98}
99EXPORT_SYMBOL_GPL(tty_port_register_device_attr);
100
101int tty_port_alloc_xmit_buf(struct tty_port *port) 36int tty_port_alloc_xmit_buf(struct tty_port *port)
102{ 37{
103 /* We may sleep in get_zeroed_page() */ 38 /* We may sleep in get_zeroed_page() */
@@ -122,27 +57,12 @@ void tty_port_free_xmit_buf(struct tty_port *port)
122} 57}
123EXPORT_SYMBOL(tty_port_free_xmit_buf); 58EXPORT_SYMBOL(tty_port_free_xmit_buf);
124 59
125/**
126 * tty_port_destroy -- destroy inited port
127 * @port: tty port to be doestroyed
128 *
129 * When a port was initialized using tty_port_init, one has to destroy the
130 * port by this function. Either indirectly by using tty_port refcounting
131 * (tty_port_put) or directly if refcounting is not used.
132 */
133void tty_port_destroy(struct tty_port *port)
134{
135 tty_buffer_free_all(port);
136}
137EXPORT_SYMBOL(tty_port_destroy);
138
139static void tty_port_destructor(struct kref *kref) 60static void tty_port_destructor(struct kref *kref)
140{ 61{
141 struct tty_port *port = container_of(kref, struct tty_port, kref); 62 struct tty_port *port = container_of(kref, struct tty_port, kref);
142 if (port->xmit_buf) 63 if (port->xmit_buf)
143 free_page((unsigned long)port->xmit_buf); 64 free_page((unsigned long)port->xmit_buf);
144 tty_port_destroy(port); 65 if (port->ops->destruct)
145 if (port->ops && port->ops->destruct)
146 port->ops->destruct(port); 66 port->ops->destruct(port);
147 else 67 else
148 kfree(port); 68 kfree(port);
@@ -310,7 +230,7 @@ int tty_port_block_til_ready(struct tty_port *port,
310 230
311 /* block if port is in the process of being closed */ 231 /* block if port is in the process of being closed */
312 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { 232 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
313 wait_event_interruptible_tty(tty, port->close_wait, 233 wait_event_interruptible_tty(port->close_wait,
314 !(port->flags & ASYNC_CLOSING)); 234 !(port->flags & ASYNC_CLOSING));
315 if (port->flags & ASYNC_HUP_NOTIFY) 235 if (port->flags & ASYNC_HUP_NOTIFY)
316 return -EAGAIN; 236 return -EAGAIN;
@@ -326,7 +246,7 @@ int tty_port_block_til_ready(struct tty_port *port,
326 } 246 }
327 if (filp->f_flags & O_NONBLOCK) { 247 if (filp->f_flags & O_NONBLOCK) {
328 /* Indicate we are open */ 248 /* Indicate we are open */
329 if (tty->termios.c_cflag & CBAUD) 249 if (tty->termios->c_cflag & CBAUD)
330 tty_port_raise_dtr_rts(port); 250 tty_port_raise_dtr_rts(port);
331 port->flags |= ASYNC_NORMAL_ACTIVE; 251 port->flags |= ASYNC_NORMAL_ACTIVE;
332 return 0; 252 return 0;
@@ -350,7 +270,7 @@ int tty_port_block_til_ready(struct tty_port *port,
350 270
351 while (1) { 271 while (1) {
352 /* Indicate we are open */ 272 /* Indicate we are open */
353 if (tty->termios.c_cflag & CBAUD) 273 if (tty->termios->c_cflag & CBAUD)
354 tty_port_raise_dtr_rts(port); 274 tty_port_raise_dtr_rts(port);
355 275
356 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); 276 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
@@ -376,9 +296,9 @@ int tty_port_block_til_ready(struct tty_port *port,
376 retval = -ERESTARTSYS; 296 retval = -ERESTARTSYS;
377 break; 297 break;
378 } 298 }
379 tty_unlock(tty); 299 tty_unlock();
380 schedule(); 300 schedule();
381 tty_lock(tty); 301 tty_lock();
382 } 302 }
383 finish_wait(&port->open_wait, &wait); 303 finish_wait(&port->open_wait, &wait);
384 304
@@ -432,7 +352,7 @@ int tty_port_close_start(struct tty_port *port,
432 tty_driver_flush_buffer(tty); 352 tty_driver_flush_buffer(tty);
433 if (test_bit(ASYNCB_INITIALIZED, &port->flags) && 353 if (test_bit(ASYNCB_INITIALIZED, &port->flags) &&
434 port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 354 port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
435 tty_wait_until_sent_from_close(tty, port->closing_wait); 355 tty_wait_until_sent(tty, port->closing_wait);
436 if (port->drain_delay) { 356 if (port->drain_delay) {
437 unsigned int bps = tty_get_baud_rate(tty); 357 unsigned int bps = tty_get_baud_rate(tty);
438 long timeout; 358 long timeout;
@@ -449,7 +369,7 @@ int tty_port_close_start(struct tty_port *port,
449 369
450 /* Drop DTR/RTS if HUPCL is set. This causes any attached modem to 370 /* Drop DTR/RTS if HUPCL is set. This causes any attached modem to
451 hang up the line */ 371 hang up the line */
452 if (tty->termios.c_cflag & HUPCL) 372 if (tty->termios->c_cflag & HUPCL)
453 tty_port_lower_dtr_rts(port); 373 tty_port_lower_dtr_rts(port);
454 374
455 /* Don't call port->drop for the last reference. Callers will want 375 /* Don't call port->drop for the last reference. Callers will want
@@ -493,24 +413,6 @@ void tty_port_close(struct tty_port *port, struct tty_struct *tty,
493} 413}
494EXPORT_SYMBOL(tty_port_close); 414EXPORT_SYMBOL(tty_port_close);
495 415
496/**
497 * tty_port_install - generic tty->ops->install handler
498 * @port: tty_port of the device
499 * @driver: tty_driver for this device
500 * @tty: tty to be installed
501 *
502 * It is the same as tty_standard_install except the provided @port is linked
503 * to a concrete tty specified by @tty. Use this or tty_port_register_device
504 * (or both). Call tty_port_link_device as a last resort.
505 */
506int tty_port_install(struct tty_port *port, struct tty_driver *driver,
507 struct tty_struct *tty)
508{
509 tty->port = port;
510 return tty_standard_install(driver, tty);
511}
512EXPORT_SYMBOL_GPL(tty_port_install);
513
514int tty_port_open(struct tty_port *port, struct tty_struct *tty, 416int tty_port_open(struct tty_port *port, struct tty_struct *tty,
515 struct file *filp) 417 struct file *filp)
516{ 418{
diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index 248381b3072..45d3e80156d 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -19,7 +19,6 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/tty.h> 20#include <linux/tty.h>
21#include <asm/uaccess.h> 21#include <asm/uaccess.h>
22#include <linux/console.h>
23#include <linux/consolemap.h> 22#include <linux/consolemap.h>
24#include <linux/vt_kern.h> 23#include <linux/vt_kern.h>
25 24
@@ -313,7 +312,6 @@ int con_set_trans_old(unsigned char __user * arg)
313 if (!access_ok(VERIFY_READ, arg, E_TABSZ)) 312 if (!access_ok(VERIFY_READ, arg, E_TABSZ))
314 return -EFAULT; 313 return -EFAULT;
315 314
316 console_lock();
317 for (i=0; i<E_TABSZ ; i++) { 315 for (i=0; i<E_TABSZ ; i++) {
318 unsigned char uc; 316 unsigned char uc;
319 __get_user(uc, arg+i); 317 __get_user(uc, arg+i);
@@ -321,7 +319,6 @@ int con_set_trans_old(unsigned char __user * arg)
321 } 319 }
322 320
323 update_user_maps(); 321 update_user_maps();
324 console_unlock();
325 return 0; 322 return 0;
326} 323}
327 324
@@ -333,13 +330,11 @@ int con_get_trans_old(unsigned char __user * arg)
333 if (!access_ok(VERIFY_WRITE, arg, E_TABSZ)) 330 if (!access_ok(VERIFY_WRITE, arg, E_TABSZ))
334 return -EFAULT; 331 return -EFAULT;
335 332
336 console_lock();
337 for (i=0; i<E_TABSZ ; i++) 333 for (i=0; i<E_TABSZ ; i++)
338 { 334 {
339 ch = conv_uni_to_pc(vc_cons[fg_console].d, p[i]); 335 ch = conv_uni_to_pc(vc_cons[fg_console].d, p[i]);
340 __put_user((ch & ~0xff) ? 0 : ch, arg+i); 336 __put_user((ch & ~0xff) ? 0 : ch, arg+i);
341 } 337 }
342 console_unlock();
343 return 0; 338 return 0;
344} 339}
345 340
@@ -351,7 +346,6 @@ int con_set_trans_new(ushort __user * arg)
351 if (!access_ok(VERIFY_READ, arg, E_TABSZ*sizeof(unsigned short))) 346 if (!access_ok(VERIFY_READ, arg, E_TABSZ*sizeof(unsigned short)))
352 return -EFAULT; 347 return -EFAULT;
353 348
354 console_lock();
355 for (i=0; i<E_TABSZ ; i++) { 349 for (i=0; i<E_TABSZ ; i++) {
356 unsigned short us; 350 unsigned short us;
357 __get_user(us, arg+i); 351 __get_user(us, arg+i);
@@ -359,7 +353,6 @@ int con_set_trans_new(ushort __user * arg)
359 } 353 }
360 354
361 update_user_maps(); 355 update_user_maps();
362 console_unlock();
363 return 0; 356 return 0;
364} 357}
365 358
@@ -371,10 +364,8 @@ int con_get_trans_new(ushort __user * arg)
371 if (!access_ok(VERIFY_WRITE, arg, E_TABSZ*sizeof(unsigned short))) 364 if (!access_ok(VERIFY_WRITE, arg, E_TABSZ*sizeof(unsigned short)))
372 return -EFAULT; 365 return -EFAULT;
373 366
374 console_lock();
375 for (i=0; i<E_TABSZ ; i++) 367 for (i=0; i<E_TABSZ ; i++)
376 __put_user(p[i], arg+i); 368 __put_user(p[i], arg+i);
377 console_unlock();
378 369
379 return 0; 370 return 0;
380} 371}
@@ -410,11 +401,12 @@ static void con_release_unimap(struct uni_pagedir *p)
410 kfree(p->inverse_translations[i]); 401 kfree(p->inverse_translations[i]);
411 p->inverse_translations[i] = NULL; 402 p->inverse_translations[i] = NULL;
412 } 403 }
413 kfree(p->inverse_trans_unicode); 404 if (p->inverse_trans_unicode) {
414 p->inverse_trans_unicode = NULL; 405 kfree(p->inverse_trans_unicode);
406 p->inverse_trans_unicode = NULL;
407 }
415} 408}
416 409
417/* Caller must hold the console lock */
418void con_free_unimap(struct vc_data *vc) 410void con_free_unimap(struct vc_data *vc)
419{ 411{
420 struct uni_pagedir *p; 412 struct uni_pagedir *p;
@@ -495,21 +487,17 @@ con_insert_unipair(struct uni_pagedir *p, u_short unicode, u_short fontpos)
495 return 0; 487 return 0;
496} 488}
497 489
498/* ui is a leftover from using a hashtable, but might be used again 490/* ui is a leftover from using a hashtable, but might be used again */
499 Caller must hold the lock */ 491int con_clear_unimap(struct vc_data *vc, struct unimapinit *ui)
500static int con_do_clear_unimap(struct vc_data *vc, struct unimapinit *ui)
501{ 492{
502 struct uni_pagedir *p, *q; 493 struct uni_pagedir *p, *q;
503 494
504 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; 495 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;
505 if (p && p->readonly) 496 if (p && p->readonly) return -EIO;
506 return -EIO;
507
508 if (!p || --p->refcount) { 497 if (!p || --p->refcount) {
509 q = kzalloc(sizeof(*p), GFP_KERNEL); 498 q = kzalloc(sizeof(*p), GFP_KERNEL);
510 if (!q) { 499 if (!q) {
511 if (p) 500 if (p) p->refcount++;
512 p->refcount++;
513 return -ENOMEM; 501 return -ENOMEM;
514 } 502 }
515 q->refcount=1; 503 q->refcount=1;
@@ -523,96 +511,43 @@ static int con_do_clear_unimap(struct vc_data *vc, struct unimapinit *ui)
523 return 0; 511 return 0;
524} 512}
525 513
526int con_clear_unimap(struct vc_data *vc, struct unimapinit *ui)
527{
528 int ret;
529 console_lock();
530 ret = con_do_clear_unimap(vc, ui);
531 console_unlock();
532 return ret;
533}
534
535int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list) 514int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
536{ 515{
537 int err = 0, err1, i; 516 int err = 0, err1, i;
538 struct uni_pagedir *p, *q; 517 struct uni_pagedir *p, *q;
539 518
540 console_lock();
541
542 /* Save original vc_unipagdir_loc in case we allocate a new one */
543 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; 519 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;
544 if (p->readonly) { 520 if (p->readonly) return -EIO;
545 console_unlock();
546 return -EIO;
547 }
548 521
549 if (!ct) { 522 if (!ct) return 0;
550 console_unlock();
551 return 0;
552 }
553 523
554 if (p->refcount > 1) { 524 if (p->refcount > 1) {
555 int j, k; 525 int j, k;
556 u16 **p1, *p2, l; 526 u16 **p1, *p2, l;
557 527
558 err1 = con_do_clear_unimap(vc, NULL); 528 err1 = con_clear_unimap(vc, NULL);
559 if (err1) { 529 if (err1) return err1;
560 console_unlock();
561 return err1;
562 }
563 530
564 /*
565 * Since refcount was > 1, con_clear_unimap() allocated a
566 * a new uni_pagedir for this vc. Re: p != q
567 */
568 q = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; 531 q = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;
569 532 for (i = 0, l = 0; i < 32; i++)
570 /*
571 * uni_pgdir is a 32*32*64 table with rows allocated
572 * when its first entry is added. The unicode value must
573 * still be incremented for empty rows. We are copying
574 * entries from "p" (old) to "q" (new).
575 */
576 l = 0; /* unicode value */
577 for (i = 0; i < 32; i++)
578 if ((p1 = p->uni_pgdir[i])) 533 if ((p1 = p->uni_pgdir[i]))
579 for (j = 0; j < 32; j++) 534 for (j = 0; j < 32; j++)
580 if ((p2 = p1[j])) { 535 if ((p2 = p1[j]))
581 for (k = 0; k < 64; k++, l++) 536 for (k = 0; k < 64; k++, l++)
582 if (p2[k] != 0xffff) { 537 if (p2[k] != 0xffff) {
583 /*
584 * Found one, copy entry for unicode
585 * l with fontpos value p2[k].
586 */
587 err1 = con_insert_unipair(q, l, p2[k]); 538 err1 = con_insert_unipair(q, l, p2[k]);
588 if (err1) { 539 if (err1) {
589 p->refcount++; 540 p->refcount++;
590 *vc->vc_uni_pagedir_loc = (unsigned long)p; 541 *vc->vc_uni_pagedir_loc = (unsigned long)p;
591 con_release_unimap(q); 542 con_release_unimap(q);
592 kfree(q); 543 kfree(q);
593 console_unlock();
594 return err1; 544 return err1;
595 } 545 }
596 } 546 }
597 } else { 547 p = q;
598 /* Account for row of 64 empty entries */ 548 } else if (p == dflt)
599 l += 64;
600 }
601 else
602 /* Account for empty table */
603 l += 32 * 64;
604
605 /*
606 * Finished copying font table, set vc_uni_pagedir to new table
607 */
608 p = q;
609 } else if (p == dflt) {
610 dflt = NULL; 549 dflt = NULL;
611 } 550
612
613 /*
614 * Insert user specified unicode pairs into new table.
615 */
616 while (ct--) { 551 while (ct--) {
617 unsigned short unicode, fontpos; 552 unsigned short unicode, fontpos;
618 __get_user(unicode, &list->unicode); 553 __get_user(unicode, &list->unicode);
@@ -622,33 +557,21 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
622 list++; 557 list++;
623 } 558 }
624 559
625 /* 560 if (con_unify_unimap(vc, p))
626 * Merge with fontmaps of any other virtual consoles.
627 */
628 if (con_unify_unimap(vc, p)) {
629 console_unlock();
630 return err; 561 return err;
631 }
632 562
633 for (i = 0; i <= 3; i++) 563 for (i = 0; i <= 3; i++)
634 set_inverse_transl(vc, p, i); /* Update inverse translations */ 564 set_inverse_transl(vc, p, i); /* Update all inverse translations */
635 set_inverse_trans_unicode(vc, p); 565 set_inverse_trans_unicode(vc, p);
636 566
637 console_unlock();
638 return err; 567 return err;
639} 568}
640 569
641/** 570/* Loads the unimap for the hardware font, as defined in uni_hash.tbl.
642 * con_set_default_unimap - set default unicode map 571 The representation used was the most compact I could come up
643 * @vc: the console we are updating 572 with. This routine is executed at sys_setup time, and when the
644 * 573 PIO_FONTRESET ioctl is called. */
645 * Loads the unimap for the hardware font, as defined in uni_hash.tbl. 574
646 * The representation used was the most compact I could come up
647 * with. This routine is executed at video setup, and when the
648 * PIO_FONTRESET ioctl is called.
649 *
650 * The caller must hold the console lock
651 */
652int con_set_default_unimap(struct vc_data *vc) 575int con_set_default_unimap(struct vc_data *vc)
653{ 576{
654 int i, j, err = 0, err1; 577 int i, j, err = 0, err1;
@@ -659,10 +582,9 @@ int con_set_default_unimap(struct vc_data *vc)
659 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; 582 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;
660 if (p == dflt) 583 if (p == dflt)
661 return 0; 584 return 0;
662
663 dflt->refcount++; 585 dflt->refcount++;
664 *vc->vc_uni_pagedir_loc = (unsigned long)dflt; 586 *vc->vc_uni_pagedir_loc = (unsigned long)dflt;
665 if (p && !--p->refcount) { 587 if (p && --p->refcount) {
666 con_release_unimap(p); 588 con_release_unimap(p);
667 kfree(p); 589 kfree(p);
668 } 590 }
@@ -671,9 +593,8 @@ int con_set_default_unimap(struct vc_data *vc)
671 593
672 /* The default font is always 256 characters */ 594 /* The default font is always 256 characters */
673 595
674 err = con_do_clear_unimap(vc, NULL); 596 err = con_clear_unimap(vc, NULL);
675 if (err) 597 if (err) return err;
676 return err;
677 598
678 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; 599 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;
679 q = dfont_unitable; 600 q = dfont_unitable;
@@ -698,13 +619,6 @@ int con_set_default_unimap(struct vc_data *vc)
698} 619}
699EXPORT_SYMBOL(con_set_default_unimap); 620EXPORT_SYMBOL(con_set_default_unimap);
700 621
701/**
702 * con_copy_unimap - copy unimap between two vts
703 * @dst_vc: target
704 * @src_vt: source
705 *
706 * The caller must hold the console lock when invoking this method
707 */
708int con_copy_unimap(struct vc_data *dst_vc, struct vc_data *src_vc) 622int con_copy_unimap(struct vc_data *dst_vc, struct vc_data *src_vc)
709{ 623{
710 struct uni_pagedir *q; 624 struct uni_pagedir *q;
@@ -719,23 +633,13 @@ int con_copy_unimap(struct vc_data *dst_vc, struct vc_data *src_vc)
719 *dst_vc->vc_uni_pagedir_loc = (long)q; 633 *dst_vc->vc_uni_pagedir_loc = (long)q;
720 return 0; 634 return 0;
721} 635}
722EXPORT_SYMBOL(con_copy_unimap);
723 636
724/**
725 * con_get_unimap - get the unicode map
726 * @vc: the console to read from
727 *
728 * Read the console unicode data for this console. Called from the ioctl
729 * handlers.
730 */
731int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct unipair __user *list) 637int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct unipair __user *list)
732{ 638{
733 int i, j, k, ect; 639 int i, j, k, ect;
734 u16 **p1, *p2; 640 u16 **p1, *p2;
735 struct uni_pagedir *p; 641 struct uni_pagedir *p;
736 642
737 console_lock();
738
739 ect = 0; 643 ect = 0;
740 if (*vc->vc_uni_pagedir_loc) { 644 if (*vc->vc_uni_pagedir_loc) {
741 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc; 645 p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;
@@ -755,19 +659,22 @@ int con_get_unimap(struct vc_data *vc, ushort ct, ushort __user *uct, struct uni
755 } 659 }
756 } 660 }
757 __put_user(ect, uct); 661 __put_user(ect, uct);
758 console_unlock();
759 return ((ect <= ct) ? 0 : -ENOMEM); 662 return ((ect <= ct) ? 0 : -ENOMEM);
760} 663}
761 664
665void con_protect_unimap(struct vc_data *vc, int rdonly)
666{
667 struct uni_pagedir *p = (struct uni_pagedir *)*vc->vc_uni_pagedir_loc;
668
669 if (p)
670 p->readonly = rdonly;
671}
672
762/* 673/*
763 * Always use USER_MAP. These functions are used by the keyboard, 674 * Always use USER_MAP. These functions are used by the keyboard,
764 * which shouldn't be affected by G0/G1 switching, etc. 675 * which shouldn't be affected by G0/G1 switching, etc.
765 * If the user map still contains default values, i.e. the 676 * If the user map still contains default values, i.e. the
766 * direct-to-font mapping, then assume user is using Latin1. 677 * direct-to-font mapping, then assume user is using Latin1.
767 *
768 * FIXME: at some point we need to decide if we want to lock the table
769 * update element itself via the keyboard_event_lock for consistency with the
770 * keyboard driver as well as the consoles
771 */ 678 */
772/* may be called during an interrupt */ 679/* may be called during an interrupt */
773u32 conv_8bit_to_uni(unsigned char c) 680u32 conv_8bit_to_uni(unsigned char c)
@@ -835,3 +742,4 @@ console_map_init(void)
835 con_set_default_unimap(vc_cons[i].d); 742 con_set_default_unimap(vc_cons[i].d);
836} 743}
837 744
745EXPORT_SYMBOL(con_copy_unimap);
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 681765baef6..3761ccf0f34 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -33,6 +33,7 @@
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/irq.h>
36 37
37#include <linux/kbd_kern.h> 38#include <linux/kbd_kern.h>
38#include <linux/kbd_diacr.h> 39#include <linux/kbd_diacr.h>
@@ -41,9 +42,6 @@
41#include <linux/reboot.h> 42#include <linux/reboot.h>
42#include <linux/notifier.h> 43#include <linux/notifier.h>
43#include <linux/jiffies.h> 44#include <linux/jiffies.h>
44#include <linux/uaccess.h>
45
46#include <asm/irq_regs.h>
47 45
48extern void ctrl_alt_del(void); 46extern void ctrl_alt_del(void);
49 47
@@ -53,17 +51,23 @@ extern void ctrl_alt_del(void);
53 51
54#define KBD_DEFMODE ((1 << VC_REPEAT) | (1 << VC_META)) 52#define KBD_DEFMODE ((1 << VC_REPEAT) | (1 << VC_META))
55 53
56#if defined(CONFIG_X86) || defined(CONFIG_PARISC) 54/*
57#include <asm/kbdleds.h> 55 * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on.
56 * This seems a good reason to start with NumLock off. On HIL keyboards
57 * of PARISC machines however there is no NumLock key and everyone expects the keypad
58 * to be used for numbers.
59 */
60
61#if defined(CONFIG_PARISC) && (defined(CONFIG_KEYBOARD_HIL) || defined(CONFIG_KEYBOARD_HIL_OLD))
62#define KBD_DEFLEDS (1 << VC_NUMLOCK)
58#else 63#else
59static inline int kbd_defleds(void) 64#define KBD_DEFLEDS 0
60{
61 return 0;
62}
63#endif 65#endif
64 66
65#define KBD_DEFLOCK 0 67#define KBD_DEFLOCK 0
66 68
69void compute_shiftstate(void);
70
67/* 71/*
68 * Handler Tables. 72 * Handler Tables.
69 */ 73 */
@@ -94,32 +98,37 @@ static fn_handler_fn *fn_handler[] = { FN_HANDLERS };
94 * Variables exported for vt_ioctl.c 98 * Variables exported for vt_ioctl.c
95 */ 99 */
96 100
101/* maximum values each key_handler can handle */
102const int max_vals[] = {
103 255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1,
104 NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1,
105 255, NR_LOCK - 1, 255, NR_BRL - 1
106};
107
108const int NR_TYPES = ARRAY_SIZE(max_vals);
109
110struct kbd_struct kbd_table[MAX_NR_CONSOLES];
111EXPORT_SYMBOL_GPL(kbd_table);
112static struct kbd_struct *kbd = kbd_table;
113
97struct vt_spawn_console vt_spawn_con = { 114struct vt_spawn_console vt_spawn_con = {
98 .lock = __SPIN_LOCK_UNLOCKED(vt_spawn_con.lock), 115 .lock = __SPIN_LOCK_UNLOCKED(vt_spawn_con.lock),
99 .pid = NULL, 116 .pid = NULL,
100 .sig = 0, 117 .sig = 0,
101}; 118};
102 119
103
104/* 120/*
105 * Internal Data. 121 * Variables exported for vt.c
106 */ 122 */
107 123
108static struct kbd_struct kbd_table[MAX_NR_CONSOLES]; 124int shift_state = 0;
109static struct kbd_struct *kbd = kbd_table;
110 125
111/* maximum values each key_handler can handle */ 126/*
112static const int max_vals[] = { 127 * Internal Data.
113 255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1, 128 */
114 NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1,
115 255, NR_LOCK - 1, 255, NR_BRL - 1
116};
117
118static const int NR_TYPES = ARRAY_SIZE(max_vals);
119 129
120static struct input_handler kbd_handler; 130static struct input_handler kbd_handler;
121static DEFINE_SPINLOCK(kbd_event_lock); 131static DEFINE_SPINLOCK(kbd_event_lock);
122static DEFINE_SPINLOCK(led_lock);
123static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */ 132static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */
124static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ 133static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */
125static bool dead_key_next; 134static bool dead_key_next;
@@ -127,8 +136,6 @@ static int npadch = -1; /* -1 or number assembled on pad */
127static unsigned int diacr; 136static unsigned int diacr;
128static char rep; /* flag telling character repeat */ 137static char rep; /* flag telling character repeat */
129 138
130static int shift_state = 0;
131
132static unsigned char ledstate = 0xff; /* undefined */ 139static unsigned char ledstate = 0xff; /* undefined */
133static unsigned char ledioctl; 140static unsigned char ledioctl;
134 141
@@ -179,7 +186,7 @@ static int getkeycode_helper(struct input_handle *handle, void *data)
179 return d->error == 0; /* stop as soon as we successfully get one */ 186 return d->error == 0; /* stop as soon as we successfully get one */
180} 187}
181 188
182static int getkeycode(unsigned int scancode) 189int getkeycode(unsigned int scancode)
183{ 190{
184 struct getset_keycode_data d = { 191 struct getset_keycode_data d = {
185 .ke = { 192 .ke = {
@@ -206,7 +213,7 @@ static int setkeycode_helper(struct input_handle *handle, void *data)
206 return d->error == 0; /* stop as soon as we successfully set one */ 213 return d->error == 0; /* stop as soon as we successfully set one */
207} 214}
208 215
209static int setkeycode(unsigned int scancode, unsigned int keycode) 216int setkeycode(unsigned int scancode, unsigned int keycode)
210{ 217{
211 struct getset_keycode_data d = { 218 struct getset_keycode_data d = {
212 .ke = { 219 .ke = {
@@ -311,7 +318,7 @@ static void put_queue(struct vc_data *vc, int ch)
311 318
312 if (tty) { 319 if (tty) {
313 tty_insert_flip_char(tty, ch, 0); 320 tty_insert_flip_char(tty, ch, 0);
314 tty_schedule_flip(tty); 321 con_schedule_flip(tty);
315 } 322 }
316} 323}
317 324
@@ -326,7 +333,7 @@ static void puts_queue(struct vc_data *vc, char *cp)
326 tty_insert_flip_char(tty, *cp, 0); 333 tty_insert_flip_char(tty, *cp, 0);
327 cp++; 334 cp++;
328 } 335 }
329 tty_schedule_flip(tty); 336 con_schedule_flip(tty);
330} 337}
331 338
332static void applkey(struct vc_data *vc, int key, char mode) 339static void applkey(struct vc_data *vc, int key, char mode)
@@ -374,11 +381,9 @@ static void to_utf8(struct vc_data *vc, uint c)
374/* 381/*
375 * Called after returning from RAW mode or when changing consoles - recompute 382 * Called after returning from RAW mode or when changing consoles - recompute
376 * shift_down[] and shift_state from key_down[] maybe called when keymap is 383 * shift_down[] and shift_state from key_down[] maybe called when keymap is
377 * undefined, so that shiftkey release is seen. The caller must hold the 384 * undefined, so that shiftkey release is seen
378 * kbd_event_lock.
379 */ 385 */
380 386void compute_shiftstate(void)
381static void do_compute_shiftstate(void)
382{ 387{
383 unsigned int i, j, k, sym, val; 388 unsigned int i, j, k, sym, val;
384 389
@@ -411,15 +416,6 @@ static void do_compute_shiftstate(void)
411 } 416 }
412} 417}
413 418
414/* We still have to export this method to vt.c */
415void compute_shiftstate(void)
416{
417 unsigned long flags;
418 spin_lock_irqsave(&kbd_event_lock, flags);
419 do_compute_shiftstate();
420 spin_unlock_irqrestore(&kbd_event_lock, flags);
421}
422
423/* 419/*
424 * We have a combining character DIACR here, followed by the character CH. 420 * We have a combining character DIACR here, followed by the character CH.
425 * If the combination occurs in the table, return the corresponding value. 421 * If the combination occurs in the table, return the corresponding value.
@@ -587,7 +583,7 @@ static void fn_send_intr(struct vc_data *vc)
587 if (!tty) 583 if (!tty)
588 return; 584 return;
589 tty_insert_flip_char(tty, 0, TTY_BREAK); 585 tty_insert_flip_char(tty, 0, TTY_BREAK);
590 tty_schedule_flip(tty); 586 con_schedule_flip(tty);
591} 587}
592 588
593static void fn_scroll_forw(struct vc_data *vc) 589static void fn_scroll_forw(struct vc_data *vc)
@@ -639,7 +635,7 @@ static void fn_SAK(struct vc_data *vc)
639 635
640static void fn_null(struct vc_data *vc) 636static void fn_null(struct vc_data *vc)
641{ 637{
642 do_compute_shiftstate(); 638 compute_shiftstate();
643} 639}
644 640
645/* 641/*
@@ -985,15 +981,13 @@ static void k_brl(struct vc_data *vc, unsigned char value, char up_flag)
985 * or (ii) whatever pattern of lights people want to show using KDSETLED, 981 * or (ii) whatever pattern of lights people want to show using KDSETLED,
986 * or (iii) specified bits of specified words in kernel memory. 982 * or (iii) specified bits of specified words in kernel memory.
987 */ 983 */
988static unsigned char getledstate(void) 984unsigned char getledstate(void)
989{ 985{
990 return ledstate; 986 return ledstate;
991} 987}
992 988
993void setledstate(struct kbd_struct *kbd, unsigned int led) 989void setledstate(struct kbd_struct *kbd, unsigned int led)
994{ 990{
995 unsigned long flags;
996 spin_lock_irqsave(&led_lock, flags);
997 if (!(led & ~7)) { 991 if (!(led & ~7)) {
998 ledioctl = led; 992 ledioctl = led;
999 kbd->ledmode = LED_SHOW_IOCTL; 993 kbd->ledmode = LED_SHOW_IOCTL;
@@ -1001,7 +995,6 @@ void setledstate(struct kbd_struct *kbd, unsigned int led)
1001 kbd->ledmode = LED_SHOW_FLAGS; 995 kbd->ledmode = LED_SHOW_FLAGS;
1002 996
1003 set_leds(); 997 set_leds();
1004 spin_unlock_irqrestore(&led_lock, flags);
1005} 998}
1006 999
1007static inline unsigned char getleds(void) 1000static inline unsigned char getleds(void)
@@ -1041,96 +1034,16 @@ static int kbd_update_leds_helper(struct input_handle *handle, void *data)
1041 return 0; 1034 return 0;
1042} 1035}
1043 1036
1044/**
1045 * vt_get_leds - helper for braille console
1046 * @console: console to read
1047 * @flag: flag we want to check
1048 *
1049 * Check the status of a keyboard led flag and report it back
1050 */
1051int vt_get_leds(int console, int flag)
1052{
1053 struct kbd_struct * kbd = kbd_table + console;
1054 int ret;
1055 unsigned long flags;
1056
1057 spin_lock_irqsave(&led_lock, flags);
1058 ret = vc_kbd_led(kbd, flag);
1059 spin_unlock_irqrestore(&led_lock, flags);
1060
1061 return ret;
1062}
1063EXPORT_SYMBOL_GPL(vt_get_leds);
1064
1065/**
1066 * vt_set_led_state - set LED state of a console
1067 * @console: console to set
1068 * @leds: LED bits
1069 *
1070 * Set the LEDs on a console. This is a wrapper for the VT layer
1071 * so that we can keep kbd knowledge internal
1072 */
1073void vt_set_led_state(int console, int leds)
1074{
1075 struct kbd_struct * kbd = kbd_table + console;
1076 setledstate(kbd, leds);
1077}
1078
1079/**
1080 * vt_kbd_con_start - Keyboard side of console start
1081 * @console: console
1082 *
1083 * Handle console start. This is a wrapper for the VT layer
1084 * so that we can keep kbd knowledge internal
1085 *
1086 * FIXME: We eventually need to hold the kbd lock here to protect
1087 * the LED updating. We can't do it yet because fn_hold calls stop_tty
1088 * and start_tty under the kbd_event_lock, while normal tty paths
1089 * don't hold the lock. We probably need to split out an LED lock
1090 * but not during an -rc release!
1091 */
1092void vt_kbd_con_start(int console)
1093{
1094 struct kbd_struct * kbd = kbd_table + console;
1095 unsigned long flags;
1096 spin_lock_irqsave(&led_lock, flags);
1097 clr_vc_kbd_led(kbd, VC_SCROLLOCK);
1098 set_leds();
1099 spin_unlock_irqrestore(&led_lock, flags);
1100}
1101
1102/**
1103 * vt_kbd_con_stop - Keyboard side of console stop
1104 * @console: console
1105 *
1106 * Handle console stop. This is a wrapper for the VT layer
1107 * so that we can keep kbd knowledge internal
1108 */
1109void vt_kbd_con_stop(int console)
1110{
1111 struct kbd_struct * kbd = kbd_table + console;
1112 unsigned long flags;
1113 spin_lock_irqsave(&led_lock, flags);
1114 set_vc_kbd_led(kbd, VC_SCROLLOCK);
1115 set_leds();
1116 spin_unlock_irqrestore(&led_lock, flags);
1117}
1118
1119/* 1037/*
1120 * This is the tasklet that updates LED state on all keyboards 1038 * This is the tasklet that updates LED state on all keyboards
1121 * attached to the box. The reason we use tasklet is that we 1039 * attached to the box. The reason we use tasklet is that we
1122 * need to handle the scenario when keyboard handler is not 1040 * need to handle the scenario when keyboard handler is not
1123 * registered yet but we already getting updates from the VT to 1041 * registered yet but we already getting updates form VT to
1124 * update led state. 1042 * update led state.
1125 */ 1043 */
1126static void kbd_bh(unsigned long dummy) 1044static void kbd_bh(unsigned long dummy)
1127{ 1045{
1128 unsigned char leds; 1046 unsigned char leds = getleds();
1129 unsigned long flags;
1130
1131 spin_lock_irqsave(&led_lock, flags);
1132 leds = getleds();
1133 spin_unlock_irqrestore(&led_lock, flags);
1134 1047
1135 if (leds != ledstate) { 1048 if (leds != ledstate) {
1136 input_handler_for_each_handle(&kbd_handler, &leds, 1049 input_handler_for_each_handle(&kbd_handler, &leds,
@@ -1340,7 +1253,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1340 if (rc == NOTIFY_STOP || !key_map) { 1253 if (rc == NOTIFY_STOP || !key_map) {
1341 atomic_notifier_call_chain(&keyboard_notifier_list, 1254 atomic_notifier_call_chain(&keyboard_notifier_list,
1342 KBD_UNBOUND_KEYCODE, &param); 1255 KBD_UNBOUND_KEYCODE, &param);
1343 do_compute_shiftstate(); 1256 compute_shiftstate();
1344 kbd->slockstate = 0; 1257 kbd->slockstate = 0;
1345 return; 1258 return;
1346 } 1259 }
@@ -1490,14 +1403,14 @@ static void kbd_start(struct input_handle *handle)
1490 1403
1491static const struct input_device_id kbd_ids[] = { 1404static const struct input_device_id kbd_ids[] = {
1492 { 1405 {
1493 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1406 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
1494 .evbit = { BIT_MASK(EV_KEY) }, 1407 .evbit = { BIT_MASK(EV_KEY) },
1495 }, 1408 },
1496 1409
1497 { 1410 {
1498 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1411 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
1499 .evbit = { BIT_MASK(EV_SND) }, 1412 .evbit = { BIT_MASK(EV_SND) },
1500 }, 1413 },
1501 1414
1502 { }, /* Terminating entry */ 1415 { }, /* Terminating entry */
1503}; 1416};
@@ -1519,9 +1432,9 @@ int __init kbd_init(void)
1519 int i; 1432 int i;
1520 int error; 1433 int error;
1521 1434
1522 for (i = 0; i < MAX_NR_CONSOLES; i++) { 1435 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1523 kbd_table[i].ledflagstate = kbd_defleds(); 1436 kbd_table[i].ledflagstate = KBD_DEFLEDS;
1524 kbd_table[i].default_ledflagstate = kbd_defleds(); 1437 kbd_table[i].default_ledflagstate = KBD_DEFLEDS;
1525 kbd_table[i].ledmode = LED_SHOW_FLAGS; 1438 kbd_table[i].ledmode = LED_SHOW_FLAGS;
1526 kbd_table[i].lockstate = KBD_DEFLOCK; 1439 kbd_table[i].lockstate = KBD_DEFLOCK;
1527 kbd_table[i].slockstate = 0; 1440 kbd_table[i].slockstate = 0;
@@ -1538,660 +1451,3 @@ int __init kbd_init(void)
1538 1451
1539 return 0; 1452 return 0;
1540} 1453}
1541
1542/* Ioctl support code */
1543
1544/**
1545 * vt_do_diacrit - diacritical table updates
1546 * @cmd: ioctl request
1547 * @up: pointer to user data for ioctl
1548 * @perm: permissions check computed by caller
1549 *
1550 * Update the diacritical tables atomically and safely. Lock them
1551 * against simultaneous keypresses
1552 */
1553int vt_do_diacrit(unsigned int cmd, void __user *up, int perm)
1554{
1555 struct kbdiacrs __user *a = up;
1556 unsigned long flags;
1557 int asize;
1558 int ret = 0;
1559
1560 switch (cmd) {
1561 case KDGKBDIACR:
1562 {
1563 struct kbdiacr *diacr;
1564 int i;
1565
1566 diacr = kmalloc(MAX_DIACR * sizeof(struct kbdiacr),
1567 GFP_KERNEL);
1568 if (diacr == NULL)
1569 return -ENOMEM;
1570
1571 /* Lock the diacriticals table, make a copy and then
1572 copy it after we unlock */
1573 spin_lock_irqsave(&kbd_event_lock, flags);
1574
1575 asize = accent_table_size;
1576 for (i = 0; i < asize; i++) {
1577 diacr[i].diacr = conv_uni_to_8bit(
1578 accent_table[i].diacr);
1579 diacr[i].base = conv_uni_to_8bit(
1580 accent_table[i].base);
1581 diacr[i].result = conv_uni_to_8bit(
1582 accent_table[i].result);
1583 }
1584 spin_unlock_irqrestore(&kbd_event_lock, flags);
1585
1586 if (put_user(asize, &a->kb_cnt))
1587 ret = -EFAULT;
1588 else if (copy_to_user(a->kbdiacr, diacr,
1589 asize * sizeof(struct kbdiacr)))
1590 ret = -EFAULT;
1591 kfree(diacr);
1592 return ret;
1593 }
1594 case KDGKBDIACRUC:
1595 {
1596 struct kbdiacrsuc __user *a = up;
1597 void *buf;
1598
1599 buf = kmalloc(MAX_DIACR * sizeof(struct kbdiacruc),
1600 GFP_KERNEL);
1601 if (buf == NULL)
1602 return -ENOMEM;
1603
1604 /* Lock the diacriticals table, make a copy and then
1605 copy it after we unlock */
1606 spin_lock_irqsave(&kbd_event_lock, flags);
1607
1608 asize = accent_table_size;
1609 memcpy(buf, accent_table, asize * sizeof(struct kbdiacruc));
1610
1611 spin_unlock_irqrestore(&kbd_event_lock, flags);
1612
1613 if (put_user(asize, &a->kb_cnt))
1614 ret = -EFAULT;
1615 else if (copy_to_user(a->kbdiacruc, buf,
1616 asize*sizeof(struct kbdiacruc)))
1617 ret = -EFAULT;
1618 kfree(buf);
1619 return ret;
1620 }
1621
1622 case KDSKBDIACR:
1623 {
1624 struct kbdiacrs __user *a = up;
1625 struct kbdiacr *diacr = NULL;
1626 unsigned int ct;
1627 int i;
1628
1629 if (!perm)
1630 return -EPERM;
1631 if (get_user(ct, &a->kb_cnt))
1632 return -EFAULT;
1633 if (ct >= MAX_DIACR)
1634 return -EINVAL;
1635
1636 if (ct) {
1637 diacr = kmalloc(sizeof(struct kbdiacr) * ct,
1638 GFP_KERNEL);
1639 if (diacr == NULL)
1640 return -ENOMEM;
1641
1642 if (copy_from_user(diacr, a->kbdiacr,
1643 sizeof(struct kbdiacr) * ct)) {
1644 kfree(diacr);
1645 return -EFAULT;
1646 }
1647 }
1648
1649 spin_lock_irqsave(&kbd_event_lock, flags);
1650 accent_table_size = ct;
1651 for (i = 0; i < ct; i++) {
1652 accent_table[i].diacr =
1653 conv_8bit_to_uni(diacr[i].diacr);
1654 accent_table[i].base =
1655 conv_8bit_to_uni(diacr[i].base);
1656 accent_table[i].result =
1657 conv_8bit_to_uni(diacr[i].result);
1658 }
1659 spin_unlock_irqrestore(&kbd_event_lock, flags);
1660 kfree(diacr);
1661 return 0;
1662 }
1663
1664 case KDSKBDIACRUC:
1665 {
1666 struct kbdiacrsuc __user *a = up;
1667 unsigned int ct;
1668 void *buf = NULL;
1669
1670 if (!perm)
1671 return -EPERM;
1672
1673 if (get_user(ct, &a->kb_cnt))
1674 return -EFAULT;
1675
1676 if (ct >= MAX_DIACR)
1677 return -EINVAL;
1678
1679 if (ct) {
1680 buf = kmalloc(ct * sizeof(struct kbdiacruc),
1681 GFP_KERNEL);
1682 if (buf == NULL)
1683 return -ENOMEM;
1684
1685 if (copy_from_user(buf, a->kbdiacruc,
1686 ct * sizeof(struct kbdiacruc))) {
1687 kfree(buf);
1688 return -EFAULT;
1689 }
1690 }
1691 spin_lock_irqsave(&kbd_event_lock, flags);
1692 if (ct)
1693 memcpy(accent_table, buf,
1694 ct * sizeof(struct kbdiacruc));
1695 accent_table_size = ct;
1696 spin_unlock_irqrestore(&kbd_event_lock, flags);
1697 kfree(buf);
1698 return 0;
1699 }
1700 }
1701 return ret;
1702}
1703
1704/**
1705 * vt_do_kdskbmode - set keyboard mode ioctl
1706 * @console: the console to use
1707 * @arg: the requested mode
1708 *
1709 * Update the keyboard mode bits while holding the correct locks.
1710 * Return 0 for success or an error code.
1711 */
1712int vt_do_kdskbmode(int console, unsigned int arg)
1713{
1714 struct kbd_struct * kbd = kbd_table + console;
1715 int ret = 0;
1716 unsigned long flags;
1717
1718 spin_lock_irqsave(&kbd_event_lock, flags);
1719 switch(arg) {
1720 case K_RAW:
1721 kbd->kbdmode = VC_RAW;
1722 break;
1723 case K_MEDIUMRAW:
1724 kbd->kbdmode = VC_MEDIUMRAW;
1725 break;
1726 case K_XLATE:
1727 kbd->kbdmode = VC_XLATE;
1728 do_compute_shiftstate();
1729 break;
1730 case K_UNICODE:
1731 kbd->kbdmode = VC_UNICODE;
1732 do_compute_shiftstate();
1733 break;
1734 case K_OFF:
1735 kbd->kbdmode = VC_OFF;
1736 break;
1737 default:
1738 ret = -EINVAL;
1739 }
1740 spin_unlock_irqrestore(&kbd_event_lock, flags);
1741 return ret;
1742}
1743
1744/**
1745 * vt_do_kdskbmeta - set keyboard meta state
1746 * @console: the console to use
1747 * @arg: the requested meta state
1748 *
1749 * Update the keyboard meta bits while holding the correct locks.
1750 * Return 0 for success or an error code.
1751 */
1752int vt_do_kdskbmeta(int console, unsigned int arg)
1753{
1754 struct kbd_struct * kbd = kbd_table + console;
1755 int ret = 0;
1756 unsigned long flags;
1757
1758 spin_lock_irqsave(&kbd_event_lock, flags);
1759 switch(arg) {
1760 case K_METABIT:
1761 clr_vc_kbd_mode(kbd, VC_META);
1762 break;
1763 case K_ESCPREFIX:
1764 set_vc_kbd_mode(kbd, VC_META);
1765 break;
1766 default:
1767 ret = -EINVAL;
1768 }
1769 spin_unlock_irqrestore(&kbd_event_lock, flags);
1770 return ret;
1771}
1772
1773int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc,
1774 int perm)
1775{
1776 struct kbkeycode tmp;
1777 int kc = 0;
1778
1779 if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode)))
1780 return -EFAULT;
1781 switch (cmd) {
1782 case KDGETKEYCODE:
1783 kc = getkeycode(tmp.scancode);
1784 if (kc >= 0)
1785 kc = put_user(kc, &user_kbkc->keycode);
1786 break;
1787 case KDSETKEYCODE:
1788 if (!perm)
1789 return -EPERM;
1790 kc = setkeycode(tmp.scancode, tmp.keycode);
1791 break;
1792 }
1793 return kc;
1794}
1795
1796#define i (tmp.kb_index)
1797#define s (tmp.kb_table)
1798#define v (tmp.kb_value)
1799
1800int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
1801 int console)
1802{
1803 struct kbd_struct * kbd = kbd_table + console;
1804 struct kbentry tmp;
1805 ushort *key_map, *new_map, val, ov;
1806 unsigned long flags;
1807
1808 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
1809 return -EFAULT;
1810
1811 if (!capable(CAP_SYS_TTY_CONFIG))
1812 perm = 0;
1813
1814 switch (cmd) {
1815 case KDGKBENT:
1816 /* Ensure another thread doesn't free it under us */
1817 spin_lock_irqsave(&kbd_event_lock, flags);
1818 key_map = key_maps[s];
1819 if (key_map) {
1820 val = U(key_map[i]);
1821 if (kbd->kbdmode != VC_UNICODE && KTYP(val) >= NR_TYPES)
1822 val = K_HOLE;
1823 } else
1824 val = (i ? K_HOLE : K_NOSUCHMAP);
1825 spin_unlock_irqrestore(&kbd_event_lock, flags);
1826 return put_user(val, &user_kbe->kb_value);
1827 case KDSKBENT:
1828 if (!perm)
1829 return -EPERM;
1830 if (!i && v == K_NOSUCHMAP) {
1831 spin_lock_irqsave(&kbd_event_lock, flags);
1832 /* deallocate map */
1833 key_map = key_maps[s];
1834 if (s && key_map) {
1835 key_maps[s] = NULL;
1836 if (key_map[0] == U(K_ALLOCATED)) {
1837 kfree(key_map);
1838 keymap_count--;
1839 }
1840 }
1841 spin_unlock_irqrestore(&kbd_event_lock, flags);
1842 break;
1843 }
1844
1845 if (KTYP(v) < NR_TYPES) {
1846 if (KVAL(v) > max_vals[KTYP(v)])
1847 return -EINVAL;
1848 } else
1849 if (kbd->kbdmode != VC_UNICODE)
1850 return -EINVAL;
1851
1852 /* ++Geert: non-PC keyboards may generate keycode zero */
1853#if !defined(__mc68000__) && !defined(__powerpc__)
1854 /* assignment to entry 0 only tests validity of args */
1855 if (!i)
1856 break;
1857#endif
1858
1859 new_map = kmalloc(sizeof(plain_map), GFP_KERNEL);
1860 if (!new_map)
1861 return -ENOMEM;
1862 spin_lock_irqsave(&kbd_event_lock, flags);
1863 key_map = key_maps[s];
1864 if (key_map == NULL) {
1865 int j;
1866
1867 if (keymap_count >= MAX_NR_OF_USER_KEYMAPS &&
1868 !capable(CAP_SYS_RESOURCE)) {
1869 spin_unlock_irqrestore(&kbd_event_lock, flags);
1870 kfree(new_map);
1871 return -EPERM;
1872 }
1873 key_maps[s] = new_map;
1874 key_map = new_map;
1875 key_map[0] = U(K_ALLOCATED);
1876 for (j = 1; j < NR_KEYS; j++)
1877 key_map[j] = U(K_HOLE);
1878 keymap_count++;
1879 } else
1880 kfree(new_map);
1881
1882 ov = U(key_map[i]);
1883 if (v == ov)
1884 goto out;
1885 /*
1886 * Attention Key.
1887 */
1888 if (((ov == K_SAK) || (v == K_SAK)) && !capable(CAP_SYS_ADMIN)) {
1889 spin_unlock_irqrestore(&kbd_event_lock, flags);
1890 return -EPERM;
1891 }
1892 key_map[i] = U(v);
1893 if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT))
1894 do_compute_shiftstate();
1895out:
1896 spin_unlock_irqrestore(&kbd_event_lock, flags);
1897 break;
1898 }
1899 return 0;
1900}
1901#undef i
1902#undef s
1903#undef v
1904
1905/* FIXME: This one needs untangling and locking */
1906int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
1907{
1908 struct kbsentry *kbs;
1909 char *p;
1910 u_char *q;
1911 u_char __user *up;
1912 int sz;
1913 int delta;
1914 char *first_free, *fj, *fnw;
1915 int i, j, k;
1916 int ret;
1917
1918 if (!capable(CAP_SYS_TTY_CONFIG))
1919 perm = 0;
1920
1921 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
1922 if (!kbs) {
1923 ret = -ENOMEM;
1924 goto reterr;
1925 }
1926
1927 /* we mostly copy too much here (512bytes), but who cares ;) */
1928 if (copy_from_user(kbs, user_kdgkb, sizeof(struct kbsentry))) {
1929 ret = -EFAULT;
1930 goto reterr;
1931 }
1932 kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0';
1933 i = kbs->kb_func;
1934
1935 switch (cmd) {
1936 case KDGKBSENT:
1937 sz = sizeof(kbs->kb_string) - 1; /* sz should have been
1938 a struct member */
1939 up = user_kdgkb->kb_string;
1940 p = func_table[i];
1941 if(p)
1942 for ( ; *p && sz; p++, sz--)
1943 if (put_user(*p, up++)) {
1944 ret = -EFAULT;
1945 goto reterr;
1946 }
1947 if (put_user('\0', up)) {
1948 ret = -EFAULT;
1949 goto reterr;
1950 }
1951 kfree(kbs);
1952 return ((p && *p) ? -EOVERFLOW : 0);
1953 case KDSKBSENT:
1954 if (!perm) {
1955 ret = -EPERM;
1956 goto reterr;
1957 }
1958
1959 q = func_table[i];
1960 first_free = funcbufptr + (funcbufsize - funcbufleft);
1961 for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
1962 ;
1963 if (j < MAX_NR_FUNC)
1964 fj = func_table[j];
1965 else
1966 fj = first_free;
1967
1968 delta = (q ? -strlen(q) : 1) + strlen(kbs->kb_string);
1969 if (delta <= funcbufleft) { /* it fits in current buf */
1970 if (j < MAX_NR_FUNC) {
1971 memmove(fj + delta, fj, first_free - fj);
1972 for (k = j; k < MAX_NR_FUNC; k++)
1973 if (func_table[k])
1974 func_table[k] += delta;
1975 }
1976 if (!q)
1977 func_table[i] = fj;
1978 funcbufleft -= delta;
1979 } else { /* allocate a larger buffer */
1980 sz = 256;
1981 while (sz < funcbufsize - funcbufleft + delta)
1982 sz <<= 1;
1983 fnw = kmalloc(sz, GFP_KERNEL);
1984 if(!fnw) {
1985 ret = -ENOMEM;
1986 goto reterr;
1987 }
1988
1989 if (!q)
1990 func_table[i] = fj;
1991 if (fj > funcbufptr)
1992 memmove(fnw, funcbufptr, fj - funcbufptr);
1993 for (k = 0; k < j; k++)
1994 if (func_table[k])
1995 func_table[k] = fnw + (func_table[k] - funcbufptr);
1996
1997 if (first_free > fj) {
1998 memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj);
1999 for (k = j; k < MAX_NR_FUNC; k++)
2000 if (func_table[k])
2001 func_table[k] = fnw + (func_table[k] - funcbufptr) + delta;
2002 }
2003 if (funcbufptr != func_buf)
2004 kfree(funcbufptr);
2005 funcbufptr = fnw;
2006 funcbufleft = funcbufleft - delta + sz - funcbufsize;
2007 funcbufsize = sz;
2008 }
2009 strcpy(func_table[i], kbs->kb_string);
2010 break;
2011 }
2012 ret = 0;
2013reterr:
2014 kfree(kbs);
2015 return ret;
2016}
2017
2018int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm)
2019{
2020 struct kbd_struct * kbd = kbd_table + console;
2021 unsigned long flags;
2022 unsigned char ucval;
2023
2024 switch(cmd) {
2025 /* the ioctls below read/set the flags usually shown in the leds */
2026 /* don't use them - they will go away without warning */
2027 case KDGKBLED:
2028 spin_lock_irqsave(&kbd_event_lock, flags);
2029 ucval = kbd->ledflagstate | (kbd->default_ledflagstate << 4);
2030 spin_unlock_irqrestore(&kbd_event_lock, flags);
2031 return put_user(ucval, (char __user *)arg);
2032
2033 case KDSKBLED:
2034 if (!perm)
2035 return -EPERM;
2036 if (arg & ~0x77)
2037 return -EINVAL;
2038 spin_lock_irqsave(&led_lock, flags);
2039 kbd->ledflagstate = (arg & 7);
2040 kbd->default_ledflagstate = ((arg >> 4) & 7);
2041 set_leds();
2042 spin_unlock_irqrestore(&led_lock, flags);
2043 return 0;
2044
2045 /* the ioctls below only set the lights, not the functions */
2046 /* for those, see KDGKBLED and KDSKBLED above */
2047 case KDGETLED:
2048 ucval = getledstate();
2049 return put_user(ucval, (char __user *)arg);
2050
2051 case KDSETLED:
2052 if (!perm)
2053 return -EPERM;
2054 setledstate(kbd, arg);
2055 return 0;
2056 }
2057 return -ENOIOCTLCMD;
2058}
2059
2060int vt_do_kdgkbmode(int console)
2061{
2062 struct kbd_struct * kbd = kbd_table + console;
2063 /* This is a spot read so needs no locking */
2064 switch (kbd->kbdmode) {
2065 case VC_RAW:
2066 return K_RAW;
2067 case VC_MEDIUMRAW:
2068 return K_MEDIUMRAW;
2069 case VC_UNICODE:
2070 return K_UNICODE;
2071 case VC_OFF:
2072 return K_OFF;
2073 default:
2074 return K_XLATE;
2075 }
2076}
2077
2078/**
2079 * vt_do_kdgkbmeta - report meta status
2080 * @console: console to report
2081 *
2082 * Report the meta flag status of this console
2083 */
2084int vt_do_kdgkbmeta(int console)
2085{
2086 struct kbd_struct * kbd = kbd_table + console;
2087 /* Again a spot read so no locking */
2088 return vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT;
2089}
2090
2091/**
2092 * vt_reset_unicode - reset the unicode status
2093 * @console: console being reset
2094 *
2095 * Restore the unicode console state to its default
2096 */
2097void vt_reset_unicode(int console)
2098{
2099 unsigned long flags;
2100
2101 spin_lock_irqsave(&kbd_event_lock, flags);
2102 kbd_table[console].kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE;
2103 spin_unlock_irqrestore(&kbd_event_lock, flags);
2104}
2105
2106/**
2107 * vt_get_shiftstate - shift bit state
2108 *
2109 * Report the shift bits from the keyboard state. We have to export
2110 * this to support some oddities in the vt layer.
2111 */
2112int vt_get_shift_state(void)
2113{
2114 /* Don't lock as this is a transient report */
2115 return shift_state;
2116}
2117
2118/**
2119 * vt_reset_keyboard - reset keyboard state
2120 * @console: console to reset
2121 *
2122 * Reset the keyboard bits for a console as part of a general console
2123 * reset event
2124 */
2125void vt_reset_keyboard(int console)
2126{
2127 struct kbd_struct * kbd = kbd_table + console;
2128 unsigned long flags;
2129
2130 spin_lock_irqsave(&kbd_event_lock, flags);
2131 set_vc_kbd_mode(kbd, VC_REPEAT);
2132 clr_vc_kbd_mode(kbd, VC_CKMODE);
2133 clr_vc_kbd_mode(kbd, VC_APPLIC);
2134 clr_vc_kbd_mode(kbd, VC_CRLF);
2135 kbd->lockstate = 0;
2136 kbd->slockstate = 0;
2137 spin_lock(&led_lock);
2138 kbd->ledmode = LED_SHOW_FLAGS;
2139 kbd->ledflagstate = kbd->default_ledflagstate;
2140 spin_unlock(&led_lock);
2141 /* do not do set_leds here because this causes an endless tasklet loop
2142 when the keyboard hasn't been initialized yet */
2143 spin_unlock_irqrestore(&kbd_event_lock, flags);
2144}
2145
2146/**
2147 * vt_get_kbd_mode_bit - read keyboard status bits
2148 * @console: console to read from
2149 * @bit: mode bit to read
2150 *
2151 * Report back a vt mode bit. We do this without locking so the
2152 * caller must be sure that there are no synchronization needs
2153 */
2154
2155int vt_get_kbd_mode_bit(int console, int bit)
2156{
2157 struct kbd_struct * kbd = kbd_table + console;
2158 return vc_kbd_mode(kbd, bit);
2159}
2160
2161/**
2162 * vt_set_kbd_mode_bit - read keyboard status bits
2163 * @console: console to read from
2164 * @bit: mode bit to read
2165 *
2166 * Set a vt mode bit. We do this without locking so the
2167 * caller must be sure that there are no synchronization needs
2168 */
2169
2170void vt_set_kbd_mode_bit(int console, int bit)
2171{
2172 struct kbd_struct * kbd = kbd_table + console;
2173 unsigned long flags;
2174
2175 spin_lock_irqsave(&kbd_event_lock, flags);
2176 set_vc_kbd_mode(kbd, bit);
2177 spin_unlock_irqrestore(&kbd_event_lock, flags);
2178}
2179
2180/**
2181 * vt_clr_kbd_mode_bit - read keyboard status bits
2182 * @console: console to read from
2183 * @bit: mode bit to read
2184 *
2185 * Report back a vt mode bit. We do this without locking so the
2186 * caller must be sure that there are no synchronization needs
2187 */
2188
2189void vt_clr_kbd_mode_bit(int console, int bit)
2190{
2191 struct kbd_struct * kbd = kbd_table + console;
2192 unsigned long flags;
2193
2194 spin_lock_irqsave(&kbd_event_lock, flags);
2195 clr_vc_kbd_mode(kbd, bit);
2196 spin_unlock_irqrestore(&kbd_event_lock, flags);
2197}
diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 60b7b692605..fb864e7fcd1 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -30,7 +30,6 @@
30 30
31extern void poke_blanked_console(void); 31extern void poke_blanked_console(void);
32 32
33/* FIXME: all this needs locking */
34/* Variables for selection control. */ 33/* Variables for selection control. */
35/* Use a dynamic buffer, instead of static (Dec 1994) */ 34/* Use a dynamic buffer, instead of static (Dec 1994) */
36struct vc_data *sel_cons; /* must not be deallocated */ 35struct vc_data *sel_cons; /* must not be deallocated */
@@ -62,14 +61,10 @@ sel_pos(int n)
62 use_unicode); 61 use_unicode);
63} 62}
64 63
65/** 64/* remove the current selection highlight, if any,
66 * clear_selection - remove current selection 65 from the console holding the selection. */
67 * 66void
68 * Remove the current selection highlight, if any from the console 67clear_selection(void) {
69 * holding the selection. The caller must hold the console lock.
70 */
71void clear_selection(void)
72{
73 highlight_pointer(-1); /* hide the pointer */ 68 highlight_pointer(-1); /* hide the pointer */
74 if (sel_start != -1) { 69 if (sel_start != -1) {
75 highlight(sel_start, sel_end); 70 highlight(sel_start, sel_end);
@@ -79,7 +74,7 @@ void clear_selection(void)
79 74
80/* 75/*
81 * User settable table: what characters are to be considered alphabetic? 76 * User settable table: what characters are to be considered alphabetic?
82 * 256 bits. Locked by the console lock. 77 * 256 bits
83 */ 78 */
84static u32 inwordLut[8]={ 79static u32 inwordLut[8]={
85 0x00000000, /* control chars */ 80 0x00000000, /* control chars */
@@ -96,20 +91,10 @@ static inline int inword(const u16 c) {
96 return c > 0xff || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1); 91 return c > 0xff || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1);
97} 92}
98 93
99/** 94/* set inwordLut contents. Invoked by ioctl(). */
100 * set loadlut - load the LUT table
101 * @p: user table
102 *
103 * Load the LUT table from user space. The caller must hold the console
104 * lock. Make a temporary copy so a partial update doesn't make a mess.
105 */
106int sel_loadlut(char __user *p) 95int sel_loadlut(char __user *p)
107{ 96{
108 u32 tmplut[8]; 97 return copy_from_user(inwordLut, (u32 __user *)(p+4), 32) ? -EFAULT : 0;
109 if (copy_from_user(tmplut, (u32 __user *)(p+4), 32))
110 return -EFAULT;
111 memcpy(inwordLut, tmplut, 32);
112 return 0;
113} 98}
114 99
115/* does screen address p correspond to character at LH/RH edge of screen? */ 100/* does screen address p correspond to character at LH/RH edge of screen? */
@@ -145,16 +130,7 @@ static int store_utf8(u16 c, char *p)
145 } 130 }
146} 131}
147 132
148/** 133/* set the current selection. Invoked by ioctl() or by kernel code. */
149 * set_selection - set the current selection.
150 * @sel: user selection info
151 * @tty: the console tty
152 *
153 * Invoked by the ioctl handle for the vt layer.
154 *
155 * The entire selection process is managed under the console_lock. It's
156 * a lot under the lock but its hardly a performance path
157 */
158int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty) 134int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty)
159{ 135{
160 struct vc_data *vc = vc_cons[fg_console].d; 136 struct vc_data *vc = vc_cons[fg_console].d;
@@ -162,7 +138,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t
162 char *bp, *obp; 138 char *bp, *obp;
163 int i, ps, pe, multiplier; 139 int i, ps, pe, multiplier;
164 u16 c; 140 u16 c;
165 int mode; 141 struct kbd_struct *kbd = kbd_table + fg_console;
166 142
167 poke_blanked_console(); 143 poke_blanked_console();
168 144
@@ -206,11 +182,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t
206 clear_selection(); 182 clear_selection();
207 sel_cons = vc_cons[fg_console].d; 183 sel_cons = vc_cons[fg_console].d;
208 } 184 }
209 mode = vt_do_kdgkbmode(fg_console); 185 use_unicode = kbd && kbd->kbdmode == VC_UNICODE;
210 if (mode == K_UNICODE)
211 use_unicode = 1;
212 else
213 use_unicode = 0;
214 186
215 switch (sel_mode) 187 switch (sel_mode)
216 { 188 {
@@ -329,9 +301,6 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t
329/* Insert the contents of the selection buffer into the 301/* Insert the contents of the selection buffer into the
330 * queue of the tty associated with the current console. 302 * queue of the tty associated with the current console.
331 * Invoked by ioctl(). 303 * Invoked by ioctl().
332 *
333 * Locking: called without locks. Calls the ldisc wrongly with
334 * unsafe methods,
335 */ 304 */
336int paste_selection(struct tty_struct *tty) 305int paste_selection(struct tty_struct *tty)
337{ 306{
@@ -341,13 +310,20 @@ int paste_selection(struct tty_struct *tty)
341 struct tty_ldisc *ld; 310 struct tty_ldisc *ld;
342 DECLARE_WAITQUEUE(wait, current); 311 DECLARE_WAITQUEUE(wait, current);
343 312
313 /* always called with BTM from vt_ioctl */
314 WARN_ON(!tty_locked());
315
344 console_lock(); 316 console_lock();
345 poke_blanked_console(); 317 poke_blanked_console();
346 console_unlock(); 318 console_unlock();
347 319
348 ld = tty_ldisc_ref_wait(tty); 320 ld = tty_ldisc_ref(tty);
321 if (!ld) {
322 tty_unlock();
323 ld = tty_ldisc_ref_wait(tty);
324 tty_lock();
325 }
349 326
350 /* FIXME: this is completely unsafe */
351 add_wait_queue(&vc->paste_wait, &wait); 327 add_wait_queue(&vc->paste_wait, &wait);
352 while (sel_buffer && sel_buffer_lth > pasted) { 328 while (sel_buffer && sel_buffer_lth > pasted) {
353 set_current_state(TASK_INTERRUPTIBLE); 329 set_current_state(TASK_INTERRUPTIBLE);
@@ -357,7 +333,8 @@ int paste_selection(struct tty_struct *tty)
357 } 333 }
358 count = sel_buffer_lth - pasted; 334 count = sel_buffer_lth - pasted;
359 count = min(count, tty->receive_room); 335 count = min(count, tty->receive_room);
360 ld->ops->receive_buf(tty, sel_buffer + pasted, NULL, count); 336 tty->ldisc->ops->receive_buf(tty, sel_buffer + pasted,
337 NULL, count);
361 pasted += count; 338 pasted += count;
362 } 339 }
363 remove_wait_queue(&vc->paste_wait, &wait); 340 remove_wait_queue(&vc->paste_wait, &wait);
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index fa7268a93c0..66825c9f516 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -22,7 +22,6 @@
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/major.h> 23#include <linux/major.h>
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/export.h>
26#include <linux/tty.h> 25#include <linux/tty.h>
27#include <linux/interrupt.h> 26#include <linux/interrupt.h>
28#include <linux/mm.h> 27#include <linux/mm.h>
@@ -608,10 +607,10 @@ vcs_open(struct inode *inode, struct file *filp)
608 unsigned int currcons = iminor(inode) & 127; 607 unsigned int currcons = iminor(inode) & 127;
609 int ret = 0; 608 int ret = 0;
610 609
611 console_lock(); 610 tty_lock();
612 if(currcons && !vc_cons_allocated(currcons-1)) 611 if(currcons && !vc_cons_allocated(currcons-1))
613 ret = -ENXIO; 612 ret = -ENXIO;
614 console_unlock(); 613 tty_unlock();
615 return ret; 614 return ret;
616} 615}
617 616
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 8fd89687d06..b3915b7ad3e 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -99,6 +99,7 @@
99#include <linux/notifier.h> 99#include <linux/notifier.h>
100#include <linux/device.h> 100#include <linux/device.h>
101#include <linux/io.h> 101#include <linux/io.h>
102#include <asm/system.h>
102#include <linux/uaccess.h> 103#include <linux/uaccess.h>
103#include <linux/kdb.h> 104#include <linux/kdb.h>
104#include <linux/ctype.h> 105#include <linux/ctype.h>
@@ -258,7 +259,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
258 259
259static void notify_write(struct vc_data *vc, unsigned int unicode) 260static void notify_write(struct vc_data *vc, unsigned int unicode)
260{ 261{
261 struct vt_notifier_param param = { .vc = vc, .c = unicode }; 262 struct vt_notifier_param param = { .vc = vc, unicode = unicode };
262 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param); 263 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
263} 264}
264 265
@@ -537,27 +538,45 @@ void complement_pos(struct vc_data *vc, int offset)
537 538
538static void insert_char(struct vc_data *vc, unsigned int nr) 539static void insert_char(struct vc_data *vc, unsigned int nr)
539{ 540{
540 unsigned short *p = (unsigned short *) vc->vc_pos; 541 unsigned short *p, *q = (unsigned short *)vc->vc_pos;
541 542
542 scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x) * 2); 543 p = q + vc->vc_cols - nr - vc->vc_x;
543 scr_memsetw(p, vc->vc_video_erase_char, nr * 2); 544 while (--p >= q)
545 scr_writew(scr_readw(p), p + nr);
546 scr_memsetw(q, vc->vc_video_erase_char, nr * 2);
544 vc->vc_need_wrap = 0; 547 vc->vc_need_wrap = 0;
545 if (DO_UPDATE(vc)) 548 if (DO_UPDATE(vc)) {
546 do_update_region(vc, (unsigned long) p, 549 unsigned short oldattr = vc->vc_attr;
547 vc->vc_cols - vc->vc_x); 550 vc->vc_sw->con_bmove(vc, vc->vc_y, vc->vc_x, vc->vc_y, vc->vc_x + nr, 1,
551 vc->vc_cols - vc->vc_x - nr);
552 vc->vc_attr = vc->vc_video_erase_char >> 8;
553 while (nr--)
554 vc->vc_sw->con_putc(vc, vc->vc_video_erase_char, vc->vc_y, vc->vc_x + nr);
555 vc->vc_attr = oldattr;
556 }
548} 557}
549 558
550static void delete_char(struct vc_data *vc, unsigned int nr) 559static void delete_char(struct vc_data *vc, unsigned int nr)
551{ 560{
552 unsigned short *p = (unsigned short *) vc->vc_pos; 561 unsigned int i = vc->vc_x;
562 unsigned short *p = (unsigned short *)vc->vc_pos;
553 563
554 scr_memcpyw(p, p + nr, (vc->vc_cols - vc->vc_x - nr) * 2); 564 while (++i <= vc->vc_cols - nr) {
555 scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char, 565 scr_writew(scr_readw(p+nr), p);
556 nr * 2); 566 p++;
567 }
568 scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
557 vc->vc_need_wrap = 0; 569 vc->vc_need_wrap = 0;
558 if (DO_UPDATE(vc)) 570 if (DO_UPDATE(vc)) {
559 do_update_region(vc, (unsigned long) p, 571 unsigned short oldattr = vc->vc_attr;
560 vc->vc_cols - vc->vc_x); 572 vc->vc_sw->con_bmove(vc, vc->vc_y, vc->vc_x + nr, vc->vc_y, vc->vc_x, 1,
573 vc->vc_cols - vc->vc_x - nr);
574 vc->vc_attr = vc->vc_video_erase_char >> 8;
575 while (nr--)
576 vc->vc_sw->con_putc(vc, vc->vc_video_erase_char, vc->vc_y,
577 vc->vc_cols - 1 - nr);
578 vc->vc_attr = oldattr;
579 }
561} 580}
562 581
563static int softcursor_original; 582static int softcursor_original;
@@ -779,7 +798,6 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
779 con_set_default_unimap(vc); 798 con_set_default_unimap(vc);
780 vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); 799 vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL);
781 if (!vc->vc_screenbuf) { 800 if (!vc->vc_screenbuf) {
782 tty_port_destroy(&vc->port);
783 kfree(vc); 801 kfree(vc);
784 vc_cons[currcons].d = NULL; 802 vc_cons[currcons].d = NULL;
785 return -ENOMEM; 803 return -ENOMEM;
@@ -1000,10 +1018,8 @@ void vc_deallocate(unsigned int currcons)
1000 put_pid(vc->vt_pid); 1018 put_pid(vc->vt_pid);
1001 module_put(vc->vc_sw->owner); 1019 module_put(vc->vc_sw->owner);
1002 kfree(vc->vc_screenbuf); 1020 kfree(vc->vc_screenbuf);
1003 if (currcons >= MIN_NR_CONSOLES) { 1021 if (currcons >= MIN_NR_CONSOLES)
1004 tty_port_destroy(&vc->port);
1005 kfree(vc); 1022 kfree(vc);
1006 }
1007 vc_cons[currcons].d = NULL; 1023 vc_cons[currcons].d = NULL;
1008 } 1024 }
1009} 1025}
@@ -1012,9 +1028,9 @@ void vc_deallocate(unsigned int currcons)
1012 * VT102 emulator 1028 * VT102 emulator
1013 */ 1029 */
1014 1030
1015#define set_kbd(vc, x) vt_set_kbd_mode_bit((vc)->vc_num, (x)) 1031#define set_kbd(vc, x) set_vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
1016#define clr_kbd(vc, x) vt_clr_kbd_mode_bit((vc)->vc_num, (x)) 1032#define clr_kbd(vc, x) clr_vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
1017#define is_kbd(vc, x) vt_get_kbd_mode_bit((vc)->vc_num, (x)) 1033#define is_kbd(vc, x) vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
1018 1034
1019#define decarm VC_REPEAT 1035#define decarm VC_REPEAT
1020#define decckm VC_CKMODE 1036#define decckm VC_CKMODE
@@ -1157,26 +1173,45 @@ static void csi_J(struct vc_data *vc, int vpar)
1157 case 0: /* erase from cursor to end of display */ 1173 case 0: /* erase from cursor to end of display */
1158 count = (vc->vc_scr_end - vc->vc_pos) >> 1; 1174 count = (vc->vc_scr_end - vc->vc_pos) >> 1;
1159 start = (unsigned short *)vc->vc_pos; 1175 start = (unsigned short *)vc->vc_pos;
1176 if (DO_UPDATE(vc)) {
1177 /* do in two stages */
1178 vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,
1179 vc->vc_cols - vc->vc_x);
1180 vc->vc_sw->con_clear(vc, vc->vc_y + 1, 0,
1181 vc->vc_rows - vc->vc_y - 1,
1182 vc->vc_cols);
1183 }
1160 break; 1184 break;
1161 case 1: /* erase from start to cursor */ 1185 case 1: /* erase from start to cursor */
1162 count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1; 1186 count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;
1163 start = (unsigned short *)vc->vc_origin; 1187 start = (unsigned short *)vc->vc_origin;
1188 if (DO_UPDATE(vc)) {
1189 /* do in two stages */
1190 vc->vc_sw->con_clear(vc, 0, 0, vc->vc_y,
1191 vc->vc_cols);
1192 vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
1193 vc->vc_x + 1);
1194 }
1164 break; 1195 break;
1165 case 3: /* erase scroll-back buffer (and whole display) */ 1196 case 3: /* erase scroll-back buffer (and whole display) */
1166 scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char, 1197 scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char,
1167 vc->vc_screenbuf_size >> 1); 1198 vc->vc_screenbuf_size >> 1);
1168 set_origin(vc); 1199 set_origin(vc);
1200 if (CON_IS_VISIBLE(vc))
1201 update_screen(vc);
1169 /* fall through */ 1202 /* fall through */
1170 case 2: /* erase whole display */ 1203 case 2: /* erase whole display */
1171 count = vc->vc_cols * vc->vc_rows; 1204 count = vc->vc_cols * vc->vc_rows;
1172 start = (unsigned short *)vc->vc_origin; 1205 start = (unsigned short *)vc->vc_origin;
1206 if (DO_UPDATE(vc))
1207 vc->vc_sw->con_clear(vc, 0, 0,
1208 vc->vc_rows,
1209 vc->vc_cols);
1173 break; 1210 break;
1174 default: 1211 default:
1175 return; 1212 return;
1176 } 1213 }
1177 scr_memsetw(start, vc->vc_video_erase_char, 2 * count); 1214 scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
1178 if (DO_UPDATE(vc))
1179 do_update_region(vc, (unsigned long) start, count);
1180 vc->vc_need_wrap = 0; 1215 vc->vc_need_wrap = 0;
1181} 1216}
1182 1217
@@ -1189,22 +1224,29 @@ static void csi_K(struct vc_data *vc, int vpar)
1189 case 0: /* erase from cursor to end of line */ 1224 case 0: /* erase from cursor to end of line */
1190 count = vc->vc_cols - vc->vc_x; 1225 count = vc->vc_cols - vc->vc_x;
1191 start = (unsigned short *)vc->vc_pos; 1226 start = (unsigned short *)vc->vc_pos;
1227 if (DO_UPDATE(vc))
1228 vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,
1229 vc->vc_cols - vc->vc_x);
1192 break; 1230 break;
1193 case 1: /* erase from start of line to cursor */ 1231 case 1: /* erase from start of line to cursor */
1194 start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1)); 1232 start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));
1195 count = vc->vc_x + 1; 1233 count = vc->vc_x + 1;
1234 if (DO_UPDATE(vc))
1235 vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
1236 vc->vc_x + 1);
1196 break; 1237 break;
1197 case 2: /* erase whole line */ 1238 case 2: /* erase whole line */
1198 start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1)); 1239 start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));
1199 count = vc->vc_cols; 1240 count = vc->vc_cols;
1241 if (DO_UPDATE(vc))
1242 vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
1243 vc->vc_cols);
1200 break; 1244 break;
1201 default: 1245 default:
1202 return; 1246 return;
1203 } 1247 }
1204 scr_memsetw(start, vc->vc_video_erase_char, 2 * count); 1248 scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
1205 vc->vc_need_wrap = 0; 1249 vc->vc_need_wrap = 0;
1206 if (DO_UPDATE(vc))
1207 do_update_region(vc, (unsigned long) start, count);
1208} 1250}
1209 1251
1210static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar positions */ 1252static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar positions */
@@ -1339,7 +1381,7 @@ static void respond_string(const char *p, struct tty_struct *tty)
1339 tty_insert_flip_char(tty, *p, 0); 1381 tty_insert_flip_char(tty, *p, 0);
1340 p++; 1382 p++;
1341 } 1383 }
1342 tty_schedule_flip(tty); 1384 con_schedule_flip(tty);
1343} 1385}
1344 1386
1345static void cursor_report(struct vc_data *vc, struct tty_struct *tty) 1387static void cursor_report(struct vc_data *vc, struct tty_struct *tty)
@@ -1610,7 +1652,16 @@ static void reset_terminal(struct vc_data *vc, int do_clear)
1610 vc->vc_deccm = global_cursor_default; 1652 vc->vc_deccm = global_cursor_default;
1611 vc->vc_decim = 0; 1653 vc->vc_decim = 0;
1612 1654
1613 vt_reset_keyboard(vc->vc_num); 1655 set_kbd(vc, decarm);
1656 clr_kbd(vc, decckm);
1657 clr_kbd(vc, kbdapplic);
1658 clr_kbd(vc, lnm);
1659 kbd_table[vc->vc_num].lockstate = 0;
1660 kbd_table[vc->vc_num].slockstate = 0;
1661 kbd_table[vc->vc_num].ledmode = LED_SHOW_FLAGS;
1662 kbd_table[vc->vc_num].ledflagstate = kbd_table[vc->vc_num].default_ledflagstate;
1663 /* do not do set_leds here because this causes an endless tasklet loop
1664 when the keyboard hasn't been initialized yet */
1614 1665
1615 vc->vc_cursor_type = cur_default; 1666 vc->vc_cursor_type = cur_default;
1616 vc->vc_complement_mask = vc->vc_s_complement_mask; 1667 vc->vc_complement_mask = vc->vc_s_complement_mask;
@@ -1928,7 +1979,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
1928 case 'q': /* DECLL - but only 3 leds */ 1979 case 'q': /* DECLL - but only 3 leds */
1929 /* map 0,1,2,3 to 0,1,2,4 */ 1980 /* map 0,1,2,3 to 0,1,2,4 */
1930 if (vc->vc_par[0] < 4) 1981 if (vc->vc_par[0] < 4)
1931 vt_set_led_state(vc->vc_num, 1982 setledstate(kbd_table + vc->vc_num,
1932 (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4); 1983 (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4);
1933 return; 1984 return;
1934 case 'r': 1985 case 'r':
@@ -2581,9 +2632,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2581 console_unlock(); 2632 console_unlock();
2582 break; 2633 break;
2583 case TIOCL_SELLOADLUT: 2634 case TIOCL_SELLOADLUT:
2584 console_lock();
2585 ret = sel_loadlut(p); 2635 ret = sel_loadlut(p);
2586 console_unlock();
2587 break; 2636 break;
2588 case TIOCL_GETSHIFTSTATE: 2637 case TIOCL_GETSHIFTSTATE:
2589 2638
@@ -2593,19 +2642,15 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2593 * kernel-internal variable; programs not closely 2642 * kernel-internal variable; programs not closely
2594 * related to the kernel should not use this. 2643 * related to the kernel should not use this.
2595 */ 2644 */
2596 data = vt_get_shift_state(); 2645 data = shift_state;
2597 ret = __put_user(data, p); 2646 ret = __put_user(data, p);
2598 break; 2647 break;
2599 case TIOCL_GETMOUSEREPORTING: 2648 case TIOCL_GETMOUSEREPORTING:
2600 console_lock(); /* May be overkill */
2601 data = mouse_reporting(); 2649 data = mouse_reporting();
2602 console_unlock();
2603 ret = __put_user(data, p); 2650 ret = __put_user(data, p);
2604 break; 2651 break;
2605 case TIOCL_SETVESABLANK: 2652 case TIOCL_SETVESABLANK:
2606 console_lock();
2607 ret = set_vesa_blanking(p); 2653 ret = set_vesa_blanking(p);
2608 console_unlock();
2609 break; 2654 break;
2610 case TIOCL_GETKMSGREDIRECT: 2655 case TIOCL_GETKMSGREDIRECT:
2611 data = vt_get_kmsg_redirect(); 2656 data = vt_get_kmsg_redirect();
@@ -2622,21 +2667,13 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2622 } 2667 }
2623 break; 2668 break;
2624 case TIOCL_GETFGCONSOLE: 2669 case TIOCL_GETFGCONSOLE:
2625 /* No locking needed as this is a transiently
2626 correct return anyway if the caller hasn't
2627 disabled switching */
2628 ret = fg_console; 2670 ret = fg_console;
2629 break; 2671 break;
2630 case TIOCL_SCROLLCONSOLE: 2672 case TIOCL_SCROLLCONSOLE:
2631 if (get_user(lines, (s32 __user *)(p+4))) { 2673 if (get_user(lines, (s32 __user *)(p+4))) {
2632 ret = -EFAULT; 2674 ret = -EFAULT;
2633 } else { 2675 } else {
2634 /* Need the console lock here. Note that lots
2635 of other calls need fixing before the lock
2636 is actually useful ! */
2637 console_lock();
2638 scrollfront(vc_cons[fg_console].d, lines); 2676 scrollfront(vc_cons[fg_console].d, lines);
2639 console_unlock();
2640 ret = 0; 2677 ret = 0;
2641 } 2678 }
2642 break; 2679 break;
@@ -2716,7 +2753,8 @@ static void con_stop(struct tty_struct *tty)
2716 console_num = tty->index; 2753 console_num = tty->index;
2717 if (!vc_cons_allocated(console_num)) 2754 if (!vc_cons_allocated(console_num))
2718 return; 2755 return;
2719 vt_kbd_con_stop(console_num); 2756 set_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
2757 set_leds();
2720} 2758}
2721 2759
2722/* 2760/*
@@ -2730,7 +2768,8 @@ static void con_start(struct tty_struct *tty)
2730 console_num = tty->index; 2768 console_num = tty->index;
2731 if (!vc_cons_allocated(console_num)) 2769 if (!vc_cons_allocated(console_num))
2732 return; 2770 return;
2733 vt_kbd_con_start(console_num); 2771 clr_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
2772 set_leds();
2734} 2773}
2735 2774
2736static void con_flush_chars(struct tty_struct *tty) 2775static void con_flush_chars(struct tty_struct *tty)
@@ -2751,52 +2790,41 @@ static void con_flush_chars(struct tty_struct *tty)
2751/* 2790/*
2752 * Allocate the console screen memory. 2791 * Allocate the console screen memory.
2753 */ 2792 */
2754static int con_install(struct tty_driver *driver, struct tty_struct *tty) 2793static int con_open(struct tty_struct *tty, struct file *filp)
2755{ 2794{
2756 unsigned int currcons = tty->index; 2795 unsigned int currcons = tty->index;
2757 struct vc_data *vc; 2796 int ret = 0;
2758 int ret;
2759 2797
2760 console_lock(); 2798 console_lock();
2761 ret = vc_allocate(currcons); 2799 if (tty->driver_data == NULL) {
2762 if (ret) 2800 ret = vc_allocate(currcons);
2763 goto unlock; 2801 if (ret == 0) {
2764 2802 struct vc_data *vc = vc_cons[currcons].d;
2765 vc = vc_cons[currcons].d;
2766
2767 /* Still being freed */
2768 if (vc->port.tty) {
2769 ret = -ERESTARTSYS;
2770 goto unlock;
2771 }
2772
2773 ret = tty_port_install(&vc->port, driver, tty);
2774 if (ret)
2775 goto unlock;
2776 2803
2777 tty->driver_data = vc; 2804 /* Still being freed */
2778 vc->port.tty = tty; 2805 if (vc->port.tty) {
2806 console_unlock();
2807 return -ERESTARTSYS;
2808 }
2809 tty->driver_data = vc;
2810 vc->port.tty = tty;
2779 2811
2780 if (!tty->winsize.ws_row && !tty->winsize.ws_col) { 2812 if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
2781 tty->winsize.ws_row = vc_cons[currcons].d->vc_rows; 2813 tty->winsize.ws_row = vc_cons[currcons].d->vc_rows;
2782 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols; 2814 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols;
2815 }
2816 if (vc->vc_utf)
2817 tty->termios->c_iflag |= IUTF8;
2818 else
2819 tty->termios->c_iflag &= ~IUTF8;
2820 console_unlock();
2821 return ret;
2822 }
2783 } 2823 }
2784 if (vc->vc_utf)
2785 tty->termios.c_iflag |= IUTF8;
2786 else
2787 tty->termios.c_iflag &= ~IUTF8;
2788unlock:
2789 console_unlock(); 2824 console_unlock();
2790 return ret; 2825 return ret;
2791} 2826}
2792 2827
2793static int con_open(struct tty_struct *tty, struct file *filp)
2794{
2795 /* everything done in install */
2796 return 0;
2797}
2798
2799
2800static void con_close(struct tty_struct *tty, struct file *filp) 2828static void con_close(struct tty_struct *tty, struct file *filp)
2801{ 2829{
2802 /* Nothing to do - we defer to shutdown */ 2830 /* Nothing to do - we defer to shutdown */
@@ -2809,6 +2837,7 @@ static void con_shutdown(struct tty_struct *tty)
2809 console_lock(); 2837 console_lock();
2810 vc->port.tty = NULL; 2838 vc->port.tty = NULL;
2811 console_unlock(); 2839 console_unlock();
2840 tty_shutdown(tty);
2812} 2841}
2813 2842
2814static int default_italic_color = 2; // green (ASCII) 2843static int default_italic_color = 2; // green (ASCII)
@@ -2901,10 +2930,11 @@ static int __init con_init(void)
2901 gotoxy(vc, vc->vc_x, vc->vc_y); 2930 gotoxy(vc, vc->vc_x, vc->vc_y);
2902 csi_J(vc, 0); 2931 csi_J(vc, 0);
2903 update_screen(vc); 2932 update_screen(vc);
2904 pr_info("Console: %s %s %dx%d\n", 2933 pr_info("Console: %s %s %dx%d",
2905 vc->vc_can_do_color ? "colour" : "mono", 2934 vc->vc_can_do_color ? "colour" : "mono",
2906 display_desc, vc->vc_cols, vc->vc_rows); 2935 display_desc, vc->vc_cols, vc->vc_rows);
2907 printable = 1; 2936 printable = 1;
2937 printk("\n");
2908 2938
2909 console_unlock(); 2939 console_unlock();
2910 2940
@@ -2916,7 +2946,6 @@ static int __init con_init(void)
2916console_initcall(con_init); 2946console_initcall(con_init);
2917 2947
2918static const struct tty_operations con_ops = { 2948static const struct tty_operations con_ops = {
2919 .install = con_install,
2920 .open = con_open, 2949 .open = con_open,
2921 .close = con_close, 2950 .close = con_close,
2922 .write = con_write, 2951 .write = con_write,
@@ -2962,7 +2991,7 @@ int __init vty_init(const struct file_operations *console_fops)
2962 console_driver = alloc_tty_driver(MAX_NR_CONSOLES); 2991 console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
2963 if (!console_driver) 2992 if (!console_driver)
2964 panic("Couldn't allocate console driver\n"); 2993 panic("Couldn't allocate console driver\n");
2965 2994 console_driver->owner = THIS_MODULE;
2966 console_driver->name = "tty"; 2995 console_driver->name = "tty";
2967 console_driver->name_base = 1; 2996 console_driver->name_base = 1;
2968 console_driver->major = TTY_MAJOR; 2997 console_driver->major = TTY_MAJOR;
@@ -3445,19 +3474,6 @@ int con_debug_enter(struct vc_data *vc)
3445 kdb_set(2, setargs); 3474 kdb_set(2, setargs);
3446 } 3475 }
3447 } 3476 }
3448 if (vc->vc_cols < 999) {
3449 int colcount;
3450 char cols[4];
3451 const char *setargs[3] = {
3452 "set",
3453 "COLUMNS",
3454 cols,
3455 };
3456 if (kdbgetintenv(setargs[0], &colcount)) {
3457 snprintf(cols, 4, "%i", vc->vc_cols);
3458 kdb_set(2, setargs);
3459 }
3460 }
3461#endif /* CONFIG_KGDB_KDB */ 3477#endif /* CONFIG_KGDB_KDB */
3462 return ret; 3478 return ret;
3463} 3479}
@@ -3875,6 +3891,36 @@ static void set_palette(struct vc_data *vc)
3875 vc->vc_sw->con_set_palette(vc, color_table); 3891 vc->vc_sw->con_set_palette(vc, color_table);
3876} 3892}
3877 3893
3894static int set_get_cmap(unsigned char __user *arg, int set)
3895{
3896 int i, j, k;
3897
3898 WARN_CONSOLE_UNLOCKED();
3899
3900 for (i = 0; i < 16; i++)
3901 if (set) {
3902 get_user(default_red[i], arg++);
3903 get_user(default_grn[i], arg++);
3904 get_user(default_blu[i], arg++);
3905 } else {
3906 put_user(default_red[i], arg++);
3907 put_user(default_grn[i], arg++);
3908 put_user(default_blu[i], arg++);
3909 }
3910 if (set) {
3911 for (i = 0; i < MAX_NR_CONSOLES; i++)
3912 if (vc_cons_allocated(i)) {
3913 for (j = k = 0; j < 16; j++) {
3914 vc_cons[i].d->vc_palette[k++] = default_red[j];
3915 vc_cons[i].d->vc_palette[k++] = default_grn[j];
3916 vc_cons[i].d->vc_palette[k++] = default_blu[j];
3917 }
3918 set_palette(vc_cons[i].d);
3919 }
3920 }
3921 return 0;
3922}
3923
3878/* 3924/*
3879 * Load palette into the DAC registers. arg points to a colour 3925 * Load palette into the DAC registers. arg points to a colour
3880 * map, 3 bytes per colour, 16 colours, range from 0 to 255. 3926 * map, 3 bytes per colour, 16 colours, range from 0 to 255.
@@ -3882,50 +3928,24 @@ static void set_palette(struct vc_data *vc)
3882 3928
3883int con_set_cmap(unsigned char __user *arg) 3929int con_set_cmap(unsigned char __user *arg)
3884{ 3930{
3885 int i, j, k; 3931 int rc;
3886 unsigned char colormap[3*16];
3887
3888 if (copy_from_user(colormap, arg, sizeof(colormap)))
3889 return -EFAULT;
3890 3932
3891 console_lock(); 3933 console_lock();
3892 for (i = k = 0; i < 16; i++) { 3934 rc = set_get_cmap (arg,1);
3893 default_red[i] = colormap[k++];
3894 default_grn[i] = colormap[k++];
3895 default_blu[i] = colormap[k++];
3896 }
3897 for (i = 0; i < MAX_NR_CONSOLES; i++) {
3898 if (!vc_cons_allocated(i))
3899 continue;
3900 for (j = k = 0; j < 16; j++) {
3901 vc_cons[i].d->vc_palette[k++] = default_red[j];
3902 vc_cons[i].d->vc_palette[k++] = default_grn[j];
3903 vc_cons[i].d->vc_palette[k++] = default_blu[j];
3904 }
3905 set_palette(vc_cons[i].d);
3906 }
3907 console_unlock(); 3935 console_unlock();
3908 3936
3909 return 0; 3937 return rc;
3910} 3938}
3911 3939
3912int con_get_cmap(unsigned char __user *arg) 3940int con_get_cmap(unsigned char __user *arg)
3913{ 3941{
3914 int i, k; 3942 int rc;
3915 unsigned char colormap[3*16];
3916 3943
3917 console_lock(); 3944 console_lock();
3918 for (i = k = 0; i < 16; i++) { 3945 rc = set_get_cmap (arg,0);
3919 colormap[k++] = default_red[i];
3920 colormap[k++] = default_grn[i];
3921 colormap[k++] = default_blu[i];
3922 }
3923 console_unlock(); 3946 console_unlock();
3924 3947
3925 if (copy_to_user(arg, colormap, sizeof(colormap))) 3948 return rc;
3926 return -EFAULT;
3927
3928 return 0;
3929} 3949}
3930 3950
3931void reset_palette(struct vc_data *vc) 3951void reset_palette(struct vc_data *vc)
@@ -3960,6 +3980,9 @@ static int con_font_get(struct vc_data *vc, struct console_font_op *op)
3960 int rc = -EINVAL; 3980 int rc = -EINVAL;
3961 int c; 3981 int c;
3962 3982
3983 if (vc->vc_mode != KD_TEXT)
3984 return -EINVAL;
3985
3963 if (op->data) { 3986 if (op->data) {
3964 font.data = kmalloc(max_font_size, GFP_KERNEL); 3987 font.data = kmalloc(max_font_size, GFP_KERNEL);
3965 if (!font.data) 3988 if (!font.data)
@@ -3968,9 +3991,7 @@ static int con_font_get(struct vc_data *vc, struct console_font_op *op)
3968 font.data = NULL; 3991 font.data = NULL;
3969 3992
3970 console_lock(); 3993 console_lock();
3971 if (vc->vc_mode != KD_TEXT) 3994 if (vc->vc_sw->con_font_get)
3972 rc = -EINVAL;
3973 else if (vc->vc_sw->con_font_get)
3974 rc = vc->vc_sw->con_font_get(vc, &font); 3995 rc = vc->vc_sw->con_font_get(vc, &font);
3975 else 3996 else
3976 rc = -ENOSYS; 3997 rc = -ENOSYS;
@@ -4052,9 +4073,7 @@ static int con_font_set(struct vc_data *vc, struct console_font_op *op)
4052 if (IS_ERR(font.data)) 4073 if (IS_ERR(font.data))
4053 return PTR_ERR(font.data); 4074 return PTR_ERR(font.data);
4054 console_lock(); 4075 console_lock();
4055 if (vc->vc_mode != KD_TEXT) 4076 if (vc->vc_sw->con_font_set)
4056 rc = -EINVAL;
4057 else if (vc->vc_sw->con_font_set)
4058 rc = vc->vc_sw->con_font_set(vc, &font, op->flags); 4077 rc = vc->vc_sw->con_font_set(vc, &font, op->flags);
4059 else 4078 else
4060 rc = -ENOSYS; 4079 rc = -ENOSYS;
@@ -4070,6 +4089,8 @@ static int con_font_default(struct vc_data *vc, struct console_font_op *op)
4070 char *s = name; 4089 char *s = name;
4071 int rc; 4090 int rc;
4072 4091
4092 if (vc->vc_mode != KD_TEXT)
4093 return -EINVAL;
4073 4094
4074 if (!op->data) 4095 if (!op->data)
4075 s = NULL; 4096 s = NULL;
@@ -4079,10 +4100,6 @@ static int con_font_default(struct vc_data *vc, struct console_font_op *op)
4079 name[MAX_FONT_NAME - 1] = 0; 4100 name[MAX_FONT_NAME - 1] = 0;
4080 4101
4081 console_lock(); 4102 console_lock();
4082 if (vc->vc_mode != KD_TEXT) {
4083 console_unlock();
4084 return -EINVAL;
4085 }
4086 if (vc->vc_sw->con_font_default) 4103 if (vc->vc_sw->con_font_default)
4087 rc = vc->vc_sw->con_font_default(vc, &font, s); 4104 rc = vc->vc_sw->con_font_default(vc, &font, s);
4088 else 4105 else
@@ -4100,11 +4117,11 @@ static int con_font_copy(struct vc_data *vc, struct console_font_op *op)
4100 int con = op->height; 4117 int con = op->height;
4101 int rc; 4118 int rc;
4102 4119
4120 if (vc->vc_mode != KD_TEXT)
4121 return -EINVAL;
4103 4122
4104 console_lock(); 4123 console_lock();
4105 if (vc->vc_mode != KD_TEXT) 4124 if (!vc->vc_sw->con_font_copy)
4106 rc = -EINVAL;
4107 else if (!vc->vc_sw->con_font_copy)
4108 rc = -ENOSYS; 4125 rc = -ENOSYS;
4109 else if (con < 0 || !vc_cons_allocated(con)) 4126 else if (con < 0 || !vc_cons_allocated(con))
4110 rc = -ENOTTY; 4127 rc = -ENOTTY;
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 98ff1735eaf..5e096f43bce 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -25,7 +25,6 @@
25#include <linux/console.h> 25#include <linux/console.h>
26#include <linux/consolemap.h> 26#include <linux/consolemap.h>
27#include <linux/signal.h> 27#include <linux/signal.h>
28#include <linux/suspend.h>
29#include <linux/timex.h> 28#include <linux/timex.h>
30 29
31#include <asm/io.h> 30#include <asm/io.h>
@@ -111,7 +110,16 @@ void vt_event_post(unsigned int event, unsigned int old, unsigned int new)
111 wake_up_interruptible(&vt_event_waitqueue); 110 wake_up_interruptible(&vt_event_waitqueue);
112} 111}
113 112
114static void __vt_event_queue(struct vt_event_wait *vw) 113/**
114 * vt_event_wait - wait for an event
115 * @vw: our event
116 *
117 * Waits for an event to occur which completes our vt_event_wait
118 * structure. On return the structure has wv->done set to 1 for success
119 * or 0 if some event such as a signal ended the wait.
120 */
121
122static void vt_event_wait(struct vt_event_wait *vw)
115{ 123{
116 unsigned long flags; 124 unsigned long flags;
117 /* Prepare the event */ 125 /* Prepare the event */
@@ -121,18 +129,8 @@ static void __vt_event_queue(struct vt_event_wait *vw)
121 spin_lock_irqsave(&vt_event_lock, flags); 129 spin_lock_irqsave(&vt_event_lock, flags);
122 list_add(&vw->list, &vt_events); 130 list_add(&vw->list, &vt_events);
123 spin_unlock_irqrestore(&vt_event_lock, flags); 131 spin_unlock_irqrestore(&vt_event_lock, flags);
124}
125
126static void __vt_event_wait(struct vt_event_wait *vw)
127{
128 /* Wait for it to pass */ 132 /* Wait for it to pass */
129 wait_event_interruptible(vt_event_waitqueue, vw->done); 133 wait_event_interruptible_tty(vt_event_waitqueue, vw->done);
130}
131
132static void __vt_event_dequeue(struct vt_event_wait *vw)
133{
134 unsigned long flags;
135
136 /* Dequeue it */ 134 /* Dequeue it */
137 spin_lock_irqsave(&vt_event_lock, flags); 135 spin_lock_irqsave(&vt_event_lock, flags);
138 list_del(&vw->list); 136 list_del(&vw->list);
@@ -140,22 +138,6 @@ static void __vt_event_dequeue(struct vt_event_wait *vw)
140} 138}
141 139
142/** 140/**
143 * vt_event_wait - wait for an event
144 * @vw: our event
145 *
146 * Waits for an event to occur which completes our vt_event_wait
147 * structure. On return the structure has wv->done set to 1 for success
148 * or 0 if some event such as a signal ended the wait.
149 */
150
151static void vt_event_wait(struct vt_event_wait *vw)
152{
153 __vt_event_queue(vw);
154 __vt_event_wait(vw);
155 __vt_event_dequeue(vw);
156}
157
158/**
159 * vt_event_wait_ioctl - event ioctl handler 141 * vt_event_wait_ioctl - event ioctl handler
160 * @arg: argument to ioctl 142 * @arg: argument to ioctl
161 * 143 *
@@ -195,14 +177,10 @@ int vt_waitactive(int n)
195{ 177{
196 struct vt_event_wait vw; 178 struct vt_event_wait vw;
197 do { 179 do {
198 vw.event.event = VT_EVENT_SWITCH; 180 if (n == fg_console + 1)
199 __vt_event_queue(&vw);
200 if (n == fg_console + 1) {
201 __vt_event_dequeue(&vw);
202 break; 181 break;
203 } 182 vw.event.event = VT_EVENT_SWITCH;
204 __vt_event_wait(&vw); 183 vt_event_wait(&vw);
205 __vt_event_dequeue(&vw);
206 if (vw.done == 0) 184 if (vw.done == 0)
207 return -EINTR; 185 return -EINTR;
208 } while (vw.event.newev != n); 186 } while (vw.event.newev != n);
@@ -217,7 +195,232 @@ int vt_waitactive(int n)
217#define GPLAST 0x3df 195#define GPLAST 0x3df
218#define GPNUM (GPLAST - GPFIRST + 1) 196#define GPNUM (GPLAST - GPFIRST + 1)
219 197
198#define i (tmp.kb_index)
199#define s (tmp.kb_table)
200#define v (tmp.kb_value)
201static inline int
202do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_struct *kbd)
203{
204 struct kbentry tmp;
205 ushort *key_map, val, ov;
206
207 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
208 return -EFAULT;
209
210 if (!capable(CAP_SYS_TTY_CONFIG))
211 perm = 0;
212
213 switch (cmd) {
214 case KDGKBENT:
215 key_map = key_maps[s];
216 if (key_map) {
217 val = U(key_map[i]);
218 if (kbd->kbdmode != VC_UNICODE && KTYP(val) >= NR_TYPES)
219 val = K_HOLE;
220 } else
221 val = (i ? K_HOLE : K_NOSUCHMAP);
222 return put_user(val, &user_kbe->kb_value);
223 case KDSKBENT:
224 if (!perm)
225 return -EPERM;
226 if (!i && v == K_NOSUCHMAP) {
227 /* deallocate map */
228 key_map = key_maps[s];
229 if (s && key_map) {
230 key_maps[s] = NULL;
231 if (key_map[0] == U(K_ALLOCATED)) {
232 kfree(key_map);
233 keymap_count--;
234 }
235 }
236 break;
237 }
238
239 if (KTYP(v) < NR_TYPES) {
240 if (KVAL(v) > max_vals[KTYP(v)])
241 return -EINVAL;
242 } else
243 if (kbd->kbdmode != VC_UNICODE)
244 return -EINVAL;
245
246 /* ++Geert: non-PC keyboards may generate keycode zero */
247#if !defined(__mc68000__) && !defined(__powerpc__)
248 /* assignment to entry 0 only tests validity of args */
249 if (!i)
250 break;
251#endif
252
253 if (!(key_map = key_maps[s])) {
254 int j;
255
256 if (keymap_count >= MAX_NR_OF_USER_KEYMAPS &&
257 !capable(CAP_SYS_RESOURCE))
258 return -EPERM;
259
260 key_map = kmalloc(sizeof(plain_map),
261 GFP_KERNEL);
262 if (!key_map)
263 return -ENOMEM;
264 key_maps[s] = key_map;
265 key_map[0] = U(K_ALLOCATED);
266 for (j = 1; j < NR_KEYS; j++)
267 key_map[j] = U(K_HOLE);
268 keymap_count++;
269 }
270 ov = U(key_map[i]);
271 if (v == ov)
272 break; /* nothing to do */
273 /*
274 * Attention Key.
275 */
276 if (((ov == K_SAK) || (v == K_SAK)) && !capable(CAP_SYS_ADMIN))
277 return -EPERM;
278 key_map[i] = U(v);
279 if (!s && (KTYP(ov) == KT_SHIFT || KTYP(v) == KT_SHIFT))
280 compute_shiftstate();
281 break;
282 }
283 return 0;
284}
285#undef i
286#undef s
287#undef v
288
289static inline int
290do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc, int perm)
291{
292 struct kbkeycode tmp;
293 int kc = 0;
294
295 if (copy_from_user(&tmp, user_kbkc, sizeof(struct kbkeycode)))
296 return -EFAULT;
297 switch (cmd) {
298 case KDGETKEYCODE:
299 kc = getkeycode(tmp.scancode);
300 if (kc >= 0)
301 kc = put_user(kc, &user_kbkc->keycode);
302 break;
303 case KDSETKEYCODE:
304 if (!perm)
305 return -EPERM;
306 kc = setkeycode(tmp.scancode, tmp.keycode);
307 break;
308 }
309 return kc;
310}
311
312static inline int
313do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
314{
315 struct kbsentry *kbs;
316 char *p;
317 u_char *q;
318 u_char __user *up;
319 int sz;
320 int delta;
321 char *first_free, *fj, *fnw;
322 int i, j, k;
323 int ret;
324
325 if (!capable(CAP_SYS_TTY_CONFIG))
326 perm = 0;
327
328 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
329 if (!kbs) {
330 ret = -ENOMEM;
331 goto reterr;
332 }
220 333
334 /* we mostly copy too much here (512bytes), but who cares ;) */
335 if (copy_from_user(kbs, user_kdgkb, sizeof(struct kbsentry))) {
336 ret = -EFAULT;
337 goto reterr;
338 }
339 kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0';
340 i = kbs->kb_func;
341
342 switch (cmd) {
343 case KDGKBSENT:
344 sz = sizeof(kbs->kb_string) - 1; /* sz should have been
345 a struct member */
346 up = user_kdgkb->kb_string;
347 p = func_table[i];
348 if(p)
349 for ( ; *p && sz; p++, sz--)
350 if (put_user(*p, up++)) {
351 ret = -EFAULT;
352 goto reterr;
353 }
354 if (put_user('\0', up)) {
355 ret = -EFAULT;
356 goto reterr;
357 }
358 kfree(kbs);
359 return ((p && *p) ? -EOVERFLOW : 0);
360 case KDSKBSENT:
361 if (!perm) {
362 ret = -EPERM;
363 goto reterr;
364 }
365
366 q = func_table[i];
367 first_free = funcbufptr + (funcbufsize - funcbufleft);
368 for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
369 ;
370 if (j < MAX_NR_FUNC)
371 fj = func_table[j];
372 else
373 fj = first_free;
374
375 delta = (q ? -strlen(q) : 1) + strlen(kbs->kb_string);
376 if (delta <= funcbufleft) { /* it fits in current buf */
377 if (j < MAX_NR_FUNC) {
378 memmove(fj + delta, fj, first_free - fj);
379 for (k = j; k < MAX_NR_FUNC; k++)
380 if (func_table[k])
381 func_table[k] += delta;
382 }
383 if (!q)
384 func_table[i] = fj;
385 funcbufleft -= delta;
386 } else { /* allocate a larger buffer */
387 sz = 256;
388 while (sz < funcbufsize - funcbufleft + delta)
389 sz <<= 1;
390 fnw = kmalloc(sz, GFP_KERNEL);
391 if(!fnw) {
392 ret = -ENOMEM;
393 goto reterr;
394 }
395
396 if (!q)
397 func_table[i] = fj;
398 if (fj > funcbufptr)
399 memmove(fnw, funcbufptr, fj - funcbufptr);
400 for (k = 0; k < j; k++)
401 if (func_table[k])
402 func_table[k] = fnw + (func_table[k] - funcbufptr);
403
404 if (first_free > fj) {
405 memmove(fnw + (fj - funcbufptr) + delta, fj, first_free - fj);
406 for (k = j; k < MAX_NR_FUNC; k++)
407 if (func_table[k])
408 func_table[k] = fnw + (func_table[k] - funcbufptr) + delta;
409 }
410 if (funcbufptr != func_buf)
411 kfree(funcbufptr);
412 funcbufptr = fnw;
413 funcbufleft = funcbufleft - delta + sz - funcbufsize;
414 funcbufsize = sz;
415 }
416 strcpy(func_table[i], kbs->kb_string);
417 break;
418 }
419 ret = 0;
420reterr:
421 kfree(kbs);
422 return ret;
423}
221 424
222static inline int 425static inline int
223do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struct console_font_op *op) 426do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struct console_font_op *op)
@@ -294,6 +497,7 @@ int vt_ioctl(struct tty_struct *tty,
294{ 497{
295 struct vc_data *vc = tty->driver_data; 498 struct vc_data *vc = tty->driver_data;
296 struct console_font_op op; /* used in multiple places here */ 499 struct console_font_op op; /* used in multiple places here */
500 struct kbd_struct * kbd;
297 unsigned int console; 501 unsigned int console;
298 unsigned char ucval; 502 unsigned char ucval;
299 unsigned int uival; 503 unsigned int uival;
@@ -303,6 +507,7 @@ int vt_ioctl(struct tty_struct *tty,
303 507
304 console = vc->vc_num; 508 console = vc->vc_num;
305 509
510 tty_lock();
306 511
307 if (!vc_cons_allocated(console)) { /* impossible? */ 512 if (!vc_cons_allocated(console)) { /* impossible? */
308 ret = -ENOIOCTLCMD; 513 ret = -ENOIOCTLCMD;
@@ -318,18 +523,19 @@ int vt_ioctl(struct tty_struct *tty,
318 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG)) 523 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
319 perm = 1; 524 perm = 1;
320 525
526 kbd = kbd_table + console;
321 switch (cmd) { 527 switch (cmd) {
322 case TIOCLINUX: 528 case TIOCLINUX:
323 ret = tioclinux(tty, arg); 529 ret = tioclinux(tty, arg);
324 break; 530 break;
325 case KIOCSOUND: 531 case KIOCSOUND:
326 if (!perm) 532 if (!perm)
327 return -EPERM; 533 goto eperm;
328 /* 534 /*
329 * The use of PIT_TICK_RATE is historic, it used to be 535 * The use of PIT_TICK_RATE is historic, it used to be
330 * the platform-dependent CLOCK_TICK_RATE between 2.6.12 536 * the platform-dependent CLOCK_TICK_RATE between 2.6.12
331 * and 2.6.36, which was a minor but unfortunate ABI 537 * and 2.6.36, which was a minor but unfortunate ABI
332 * change. kd_mksound is locked by the input layer. 538 * change.
333 */ 539 */
334 if (arg) 540 if (arg)
335 arg = PIT_TICK_RATE / arg; 541 arg = PIT_TICK_RATE / arg;
@@ -338,7 +544,7 @@ int vt_ioctl(struct tty_struct *tty,
338 544
339 case KDMKTONE: 545 case KDMKTONE:
340 if (!perm) 546 if (!perm)
341 return -EPERM; 547 goto eperm;
342 { 548 {
343 unsigned int ticks, count; 549 unsigned int ticks, count;
344 550
@@ -356,11 +562,10 @@ int vt_ioctl(struct tty_struct *tty,
356 562
357 case KDGKBTYPE: 563 case KDGKBTYPE:
358 /* 564 /*
359 * this is naïve. 565 * this is naive.
360 */ 566 */
361 ucval = KB_101; 567 ucval = KB_101;
362 ret = put_user(ucval, (char __user *)arg); 568 goto setchar;
363 break;
364 569
365 /* 570 /*
366 * These cannot be implemented on any machine that implements 571 * These cannot be implemented on any machine that implements
@@ -374,8 +579,6 @@ int vt_ioctl(struct tty_struct *tty,
374 /* 579 /*
375 * KDADDIO and KDDELIO may be able to add ports beyond what 580 * KDADDIO and KDDELIO may be able to add ports beyond what
376 * we reject here, but to be safe... 581 * we reject here, but to be safe...
377 *
378 * These are locked internally via sys_ioperm
379 */ 582 */
380 if (arg < GPFIRST || arg > GPLAST) { 583 if (arg < GPFIRST || arg > GPLAST) {
381 ret = -EINVAL; 584 ret = -EINVAL;
@@ -398,7 +601,7 @@ int vt_ioctl(struct tty_struct *tty,
398 struct kbd_repeat kbrep; 601 struct kbd_repeat kbrep;
399 602
400 if (!capable(CAP_SYS_TTY_CONFIG)) 603 if (!capable(CAP_SYS_TTY_CONFIG))
401 return -EPERM; 604 goto eperm;
402 605
403 if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) { 606 if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) {
404 ret = -EFAULT; 607 ret = -EFAULT;
@@ -422,7 +625,7 @@ int vt_ioctl(struct tty_struct *tty,
422 * need to restore their engine state. --BenH 625 * need to restore their engine state. --BenH
423 */ 626 */
424 if (!perm) 627 if (!perm)
425 return -EPERM; 628 goto eperm;
426 switch (arg) { 629 switch (arg) {
427 case KD_GRAPHICS: 630 case KD_GRAPHICS:
428 break; 631 break;
@@ -435,7 +638,6 @@ int vt_ioctl(struct tty_struct *tty,
435 ret = -EINVAL; 638 ret = -EINVAL;
436 goto out; 639 goto out;
437 } 640 }
438 /* FIXME: this needs the console lock extending */
439 if (vc->vc_mode == (unsigned char) arg) 641 if (vc->vc_mode == (unsigned char) arg)
440 break; 642 break;
441 vc->vc_mode = (unsigned char) arg; 643 vc->vc_mode = (unsigned char) arg;
@@ -467,26 +669,69 @@ int vt_ioctl(struct tty_struct *tty,
467 669
468 case KDSKBMODE: 670 case KDSKBMODE:
469 if (!perm) 671 if (!perm)
470 return -EPERM; 672 goto eperm;
471 ret = vt_do_kdskbmode(console, arg); 673 switch(arg) {
472 if (ret == 0) 674 case K_RAW:
473 tty_ldisc_flush(tty); 675 kbd->kbdmode = VC_RAW;
676 break;
677 case K_MEDIUMRAW:
678 kbd->kbdmode = VC_MEDIUMRAW;
679 break;
680 case K_XLATE:
681 kbd->kbdmode = VC_XLATE;
682 compute_shiftstate();
683 break;
684 case K_UNICODE:
685 kbd->kbdmode = VC_UNICODE;
686 compute_shiftstate();
687 break;
688 case K_OFF:
689 kbd->kbdmode = VC_OFF;
690 break;
691 default:
692 ret = -EINVAL;
693 goto out;
694 }
695 tty_ldisc_flush(tty);
474 break; 696 break;
475 697
476 case KDGKBMODE: 698 case KDGKBMODE:
477 uival = vt_do_kdgkbmode(console); 699 switch (kbd->kbdmode) {
478 ret = put_user(uival, (int __user *)arg); 700 case VC_RAW:
479 break; 701 uival = K_RAW;
702 break;
703 case VC_MEDIUMRAW:
704 uival = K_MEDIUMRAW;
705 break;
706 case VC_UNICODE:
707 uival = K_UNICODE;
708 break;
709 case VC_OFF:
710 uival = K_OFF;
711 break;
712 default:
713 uival = K_XLATE;
714 break;
715 }
716 goto setint;
480 717
481 /* this could be folded into KDSKBMODE, but for compatibility 718 /* this could be folded into KDSKBMODE, but for compatibility
482 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */ 719 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
483 case KDSKBMETA: 720 case KDSKBMETA:
484 ret = vt_do_kdskbmeta(console, arg); 721 switch(arg) {
722 case K_METABIT:
723 clr_vc_kbd_mode(kbd, VC_META);
724 break;
725 case K_ESCPREFIX:
726 set_vc_kbd_mode(kbd, VC_META);
727 break;
728 default:
729 ret = -EINVAL;
730 }
485 break; 731 break;
486 732
487 case KDGKBMETA: 733 case KDGKBMETA:
488 /* FIXME: should review whether this is worth locking */ 734 uival = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT);
489 uival = vt_do_kdgkbmeta(console);
490 setint: 735 setint:
491 ret = put_user(uival, (int __user *)arg); 736 ret = put_user(uival, (int __user *)arg);
492 break; 737 break;
@@ -495,35 +740,133 @@ int vt_ioctl(struct tty_struct *tty,
495 case KDSETKEYCODE: 740 case KDSETKEYCODE:
496 if(!capable(CAP_SYS_TTY_CONFIG)) 741 if(!capable(CAP_SYS_TTY_CONFIG))
497 perm = 0; 742 perm = 0;
498 ret = vt_do_kbkeycode_ioctl(cmd, up, perm); 743 ret = do_kbkeycode_ioctl(cmd, up, perm);
499 break; 744 break;
500 745
501 case KDGKBENT: 746 case KDGKBENT:
502 case KDSKBENT: 747 case KDSKBENT:
503 ret = vt_do_kdsk_ioctl(cmd, up, perm, console); 748 ret = do_kdsk_ioctl(cmd, up, perm, kbd);
504 break; 749 break;
505 750
506 case KDGKBSENT: 751 case KDGKBSENT:
507 case KDSKBSENT: 752 case KDSKBSENT:
508 ret = vt_do_kdgkb_ioctl(cmd, up, perm); 753 ret = do_kdgkb_ioctl(cmd, up, perm);
509 break; 754 break;
510 755
511 /* Diacritical processing. Handled in keyboard.c as it has
512 to operate on the keyboard locks and structures */
513 case KDGKBDIACR: 756 case KDGKBDIACR:
757 {
758 struct kbdiacrs __user *a = up;
759 struct kbdiacr diacr;
760 int i;
761
762 if (put_user(accent_table_size, &a->kb_cnt)) {
763 ret = -EFAULT;
764 break;
765 }
766 for (i = 0; i < accent_table_size; i++) {
767 diacr.diacr = conv_uni_to_8bit(accent_table[i].diacr);
768 diacr.base = conv_uni_to_8bit(accent_table[i].base);
769 diacr.result = conv_uni_to_8bit(accent_table[i].result);
770 if (copy_to_user(a->kbdiacr + i, &diacr, sizeof(struct kbdiacr))) {
771 ret = -EFAULT;
772 break;
773 }
774 }
775 break;
776 }
514 case KDGKBDIACRUC: 777 case KDGKBDIACRUC:
778 {
779 struct kbdiacrsuc __user *a = up;
780
781 if (put_user(accent_table_size, &a->kb_cnt))
782 ret = -EFAULT;
783 else if (copy_to_user(a->kbdiacruc, accent_table,
784 accent_table_size*sizeof(struct kbdiacruc)))
785 ret = -EFAULT;
786 break;
787 }
788
515 case KDSKBDIACR: 789 case KDSKBDIACR:
790 {
791 struct kbdiacrs __user *a = up;
792 struct kbdiacr diacr;
793 unsigned int ct;
794 int i;
795
796 if (!perm)
797 goto eperm;
798 if (get_user(ct,&a->kb_cnt)) {
799 ret = -EFAULT;
800 break;
801 }
802 if (ct >= MAX_DIACR) {
803 ret = -EINVAL;
804 break;
805 }
806 accent_table_size = ct;
807 for (i = 0; i < ct; i++) {
808 if (copy_from_user(&diacr, a->kbdiacr + i, sizeof(struct kbdiacr))) {
809 ret = -EFAULT;
810 break;
811 }
812 accent_table[i].diacr = conv_8bit_to_uni(diacr.diacr);
813 accent_table[i].base = conv_8bit_to_uni(diacr.base);
814 accent_table[i].result = conv_8bit_to_uni(diacr.result);
815 }
816 break;
817 }
818
516 case KDSKBDIACRUC: 819 case KDSKBDIACRUC:
517 ret = vt_do_diacrit(cmd, up, perm); 820 {
821 struct kbdiacrsuc __user *a = up;
822 unsigned int ct;
823
824 if (!perm)
825 goto eperm;
826 if (get_user(ct,&a->kb_cnt)) {
827 ret = -EFAULT;
828 break;
829 }
830 if (ct >= MAX_DIACR) {
831 ret = -EINVAL;
832 break;
833 }
834 accent_table_size = ct;
835 if (copy_from_user(accent_table, a->kbdiacruc, ct*sizeof(struct kbdiacruc)))
836 ret = -EFAULT;
518 break; 837 break;
838 }
519 839
520 /* the ioctls below read/set the flags usually shown in the leds */ 840 /* the ioctls below read/set the flags usually shown in the leds */
521 /* don't use them - they will go away without warning */ 841 /* don't use them - they will go away without warning */
522 case KDGKBLED: 842 case KDGKBLED:
843 ucval = kbd->ledflagstate | (kbd->default_ledflagstate << 4);
844 goto setchar;
845
523 case KDSKBLED: 846 case KDSKBLED:
847 if (!perm)
848 goto eperm;
849 if (arg & ~0x77) {
850 ret = -EINVAL;
851 break;
852 }
853 kbd->ledflagstate = (arg & 7);
854 kbd->default_ledflagstate = ((arg >> 4) & 7);
855 set_leds();
856 break;
857
858 /* the ioctls below only set the lights, not the functions */
859 /* for those, see KDGKBLED and KDSKBLED above */
524 case KDGETLED: 860 case KDGETLED:
861 ucval = getledstate();
862 setchar:
863 ret = put_user(ucval, (char __user *)arg);
864 break;
865
525 case KDSETLED: 866 case KDSETLED:
526 ret = vt_do_kdskled(console, cmd, arg, perm); 867 if (!perm)
868 goto eperm;
869 setledstate(kbd, arg);
527 break; 870 break;
528 871
529 /* 872 /*
@@ -536,7 +879,7 @@ int vt_ioctl(struct tty_struct *tty,
536 case KDSIGACCEPT: 879 case KDSIGACCEPT:
537 { 880 {
538 if (!perm || !capable(CAP_KILL)) 881 if (!perm || !capable(CAP_KILL))
539 return -EPERM; 882 goto eperm;
540 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL) 883 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
541 ret = -EINVAL; 884 ret = -EINVAL;
542 else { 885 else {
@@ -554,7 +897,7 @@ int vt_ioctl(struct tty_struct *tty,
554 struct vt_mode tmp; 897 struct vt_mode tmp;
555 898
556 if (!perm) 899 if (!perm)
557 return -EPERM; 900 goto eperm;
558 if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) { 901 if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) {
559 ret = -EFAULT; 902 ret = -EFAULT;
560 goto out; 903 goto out;
@@ -600,7 +943,6 @@ int vt_ioctl(struct tty_struct *tty,
600 struct vt_stat __user *vtstat = up; 943 struct vt_stat __user *vtstat = up;
601 unsigned short state, mask; 944 unsigned short state, mask;
602 945
603 /* Review: FIXME: Console lock ? */
604 if (put_user(fg_console + 1, &vtstat->v_active)) 946 if (put_user(fg_console + 1, &vtstat->v_active))
605 ret = -EFAULT; 947 ret = -EFAULT;
606 else { 948 else {
@@ -618,7 +960,6 @@ int vt_ioctl(struct tty_struct *tty,
618 * Returns the first available (non-opened) console. 960 * Returns the first available (non-opened) console.
619 */ 961 */
620 case VT_OPENQRY: 962 case VT_OPENQRY:
621 /* FIXME: locking ? - but then this is a stupid API */
622 for (i = 0; i < MAX_NR_CONSOLES; ++i) 963 for (i = 0; i < MAX_NR_CONSOLES; ++i)
623 if (! VT_IS_IN_USE(i)) 964 if (! VT_IS_IN_USE(i))
624 break; 965 break;
@@ -632,7 +973,7 @@ int vt_ioctl(struct tty_struct *tty,
632 */ 973 */
633 case VT_ACTIVATE: 974 case VT_ACTIVATE:
634 if (!perm) 975 if (!perm)
635 return -EPERM; 976 goto eperm;
636 if (arg == 0 || arg > MAX_NR_CONSOLES) 977 if (arg == 0 || arg > MAX_NR_CONSOLES)
637 ret = -ENXIO; 978 ret = -ENXIO;
638 else { 979 else {
@@ -651,7 +992,7 @@ int vt_ioctl(struct tty_struct *tty,
651 struct vt_setactivate vsa; 992 struct vt_setactivate vsa;
652 993
653 if (!perm) 994 if (!perm)
654 return -EPERM; 995 goto eperm;
655 996
656 if (copy_from_user(&vsa, (struct vt_setactivate __user *)arg, 997 if (copy_from_user(&vsa, (struct vt_setactivate __user *)arg,
657 sizeof(struct vt_setactivate))) { 998 sizeof(struct vt_setactivate))) {
@@ -679,7 +1020,6 @@ int vt_ioctl(struct tty_struct *tty,
679 if (ret) 1020 if (ret)
680 break; 1021 break;
681 /* Commence switch and lock */ 1022 /* Commence switch and lock */
682 /* Review set_console locks */
683 set_console(vsa.console); 1023 set_console(vsa.console);
684 } 1024 }
685 break; 1025 break;
@@ -690,7 +1030,7 @@ int vt_ioctl(struct tty_struct *tty,
690 */ 1030 */
691 case VT_WAITACTIVE: 1031 case VT_WAITACTIVE:
692 if (!perm) 1032 if (!perm)
693 return -EPERM; 1033 goto eperm;
694 if (arg == 0 || arg > MAX_NR_CONSOLES) 1034 if (arg == 0 || arg > MAX_NR_CONSOLES)
695 ret = -ENXIO; 1035 ret = -ENXIO;
696 else 1036 else
@@ -709,17 +1049,16 @@ int vt_ioctl(struct tty_struct *tty,
709 */ 1049 */
710 case VT_RELDISP: 1050 case VT_RELDISP:
711 if (!perm) 1051 if (!perm)
712 return -EPERM; 1052 goto eperm;
713 1053
714 console_lock();
715 if (vc->vt_mode.mode != VT_PROCESS) { 1054 if (vc->vt_mode.mode != VT_PROCESS) {
716 console_unlock();
717 ret = -EINVAL; 1055 ret = -EINVAL;
718 break; 1056 break;
719 } 1057 }
720 /* 1058 /*
721 * Switching-from response 1059 * Switching-from response
722 */ 1060 */
1061 console_lock();
723 if (vc->vt_newvt >= 0) { 1062 if (vc->vt_newvt >= 0) {
724 if (arg == 0) 1063 if (arg == 0)
725 /* 1064 /*
@@ -796,7 +1135,7 @@ int vt_ioctl(struct tty_struct *tty,
796 1135
797 ushort ll,cc; 1136 ushort ll,cc;
798 if (!perm) 1137 if (!perm)
799 return -EPERM; 1138 goto eperm;
800 if (get_user(ll, &vtsizes->v_rows) || 1139 if (get_user(ll, &vtsizes->v_rows) ||
801 get_user(cc, &vtsizes->v_cols)) 1140 get_user(cc, &vtsizes->v_cols))
802 ret = -EFAULT; 1141 ret = -EFAULT;
@@ -807,7 +1146,6 @@ int vt_ioctl(struct tty_struct *tty,
807 1146
808 if (vc) { 1147 if (vc) {
809 vc->vc_resize_user = 1; 1148 vc->vc_resize_user = 1;
810 /* FIXME: review v tty lock */
811 vc_resize(vc_cons[i].d, cc, ll); 1149 vc_resize(vc_cons[i].d, cc, ll);
812 } 1150 }
813 } 1151 }
@@ -821,7 +1159,7 @@ int vt_ioctl(struct tty_struct *tty,
821 struct vt_consize __user *vtconsize = up; 1159 struct vt_consize __user *vtconsize = up;
822 ushort ll,cc,vlin,clin,vcol,ccol; 1160 ushort ll,cc,vlin,clin,vcol,ccol;
823 if (!perm) 1161 if (!perm)
824 return -EPERM; 1162 goto eperm;
825 if (!access_ok(VERIFY_READ, vtconsize, 1163 if (!access_ok(VERIFY_READ, vtconsize,
826 sizeof(struct vt_consize))) { 1164 sizeof(struct vt_consize))) {
827 ret = -EFAULT; 1165 ret = -EFAULT;
@@ -877,7 +1215,7 @@ int vt_ioctl(struct tty_struct *tty,
877 1215
878 case PIO_FONT: { 1216 case PIO_FONT: {
879 if (!perm) 1217 if (!perm)
880 return -EPERM; 1218 goto eperm;
881 op.op = KD_FONT_OP_SET; 1219 op.op = KD_FONT_OP_SET;
882 op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */ 1220 op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
883 op.width = 8; 1221 op.width = 8;
@@ -918,7 +1256,7 @@ int vt_ioctl(struct tty_struct *tty,
918 case PIO_FONTRESET: 1256 case PIO_FONTRESET:
919 { 1257 {
920 if (!perm) 1258 if (!perm)
921 return -EPERM; 1259 goto eperm;
922 1260
923#ifdef BROKEN_GRAPHICS_PROGRAMS 1261#ifdef BROKEN_GRAPHICS_PROGRAMS
924 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default 1262 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
@@ -932,9 +1270,7 @@ int vt_ioctl(struct tty_struct *tty,
932 ret = con_font_op(vc_cons[fg_console].d, &op); 1270 ret = con_font_op(vc_cons[fg_console].d, &op);
933 if (ret) 1271 if (ret)
934 break; 1272 break;
935 console_lock();
936 con_set_default_unimap(vc_cons[fg_console].d); 1273 con_set_default_unimap(vc_cons[fg_console].d);
937 console_unlock();
938 break; 1274 break;
939 } 1275 }
940#endif 1276#endif
@@ -946,7 +1282,7 @@ int vt_ioctl(struct tty_struct *tty,
946 break; 1282 break;
947 } 1283 }
948 if (!perm && op.op != KD_FONT_OP_GET) 1284 if (!perm && op.op != KD_FONT_OP_GET)
949 return -EPERM; 1285 goto eperm;
950 ret = con_font_op(vc, &op); 1286 ret = con_font_op(vc, &op);
951 if (ret) 1287 if (ret)
952 break; 1288 break;
@@ -980,7 +1316,7 @@ int vt_ioctl(struct tty_struct *tty,
980 case PIO_UNIMAPCLR: 1316 case PIO_UNIMAPCLR:
981 { struct unimapinit ui; 1317 { struct unimapinit ui;
982 if (!perm) 1318 if (!perm)
983 return -EPERM; 1319 goto eperm;
984 ret = copy_from_user(&ui, up, sizeof(struct unimapinit)); 1320 ret = copy_from_user(&ui, up, sizeof(struct unimapinit));
985 if (ret) 1321 if (ret)
986 ret = -EFAULT; 1322 ret = -EFAULT;
@@ -996,12 +1332,12 @@ int vt_ioctl(struct tty_struct *tty,
996 1332
997 case VT_LOCKSWITCH: 1333 case VT_LOCKSWITCH:
998 if (!capable(CAP_SYS_TTY_CONFIG)) 1334 if (!capable(CAP_SYS_TTY_CONFIG))
999 return -EPERM; 1335 goto eperm;
1000 vt_dont_switch = 1; 1336 vt_dont_switch = 1;
1001 break; 1337 break;
1002 case VT_UNLOCKSWITCH: 1338 case VT_UNLOCKSWITCH:
1003 if (!capable(CAP_SYS_TTY_CONFIG)) 1339 if (!capable(CAP_SYS_TTY_CONFIG))
1004 return -EPERM; 1340 goto eperm;
1005 vt_dont_switch = 0; 1341 vt_dont_switch = 0;
1006 break; 1342 break;
1007 case VT_GETHIFONTMASK: 1343 case VT_GETHIFONTMASK:
@@ -1015,13 +1351,17 @@ int vt_ioctl(struct tty_struct *tty,
1015 ret = -ENOIOCTLCMD; 1351 ret = -ENOIOCTLCMD;
1016 } 1352 }
1017out: 1353out:
1354 tty_unlock();
1018 return ret; 1355 return ret;
1356eperm:
1357 ret = -EPERM;
1358 goto out;
1019} 1359}
1020 1360
1021void reset_vc(struct vc_data *vc) 1361void reset_vc(struct vc_data *vc)
1022{ 1362{
1023 vc->vc_mode = KD_TEXT; 1363 vc->vc_mode = KD_TEXT;
1024 vt_reset_unicode(vc->vc_num); 1364 kbd_table[vc->vc_num].kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE;
1025 vc->vt_mode.mode = VT_AUTO; 1365 vc->vt_mode.mode = VT_AUTO;
1026 vc->vt_mode.waitv = 0; 1366 vc->vt_mode.waitv = 0;
1027 vc->vt_mode.relsig = 0; 1367 vc->vt_mode.relsig = 0;
@@ -1044,7 +1384,6 @@ void vc_SAK(struct work_struct *work)
1044 console_lock(); 1384 console_lock();
1045 vc = vc_con->d; 1385 vc = vc_con->d;
1046 if (vc) { 1386 if (vc) {
1047 /* FIXME: review tty ref counting */
1048 tty = vc->port.tty; 1387 tty = vc->port.tty;
1049 /* 1388 /*
1050 * SAK should also work in all raw modes and reset 1389 * SAK should also work in all raw modes and reset
@@ -1124,6 +1463,7 @@ compat_kdfontop_ioctl(struct compat_console_font_op __user *fontop,
1124 if (!perm && op->op != KD_FONT_OP_GET) 1463 if (!perm && op->op != KD_FONT_OP_GET)
1125 return -EPERM; 1464 return -EPERM;
1126 op->data = compat_ptr(((struct compat_console_font_op *)op)->data); 1465 op->data = compat_ptr(((struct compat_console_font_op *)op)->data);
1466 op->flags |= KD_FONT_FLAG_OLD;
1127 i = con_font_op(vc, op); 1467 i = con_font_op(vc, op);
1128 if (i) 1468 if (i)
1129 return i; 1469 return i;
@@ -1177,6 +1517,8 @@ long vt_compat_ioctl(struct tty_struct *tty,
1177 1517
1178 console = vc->vc_num; 1518 console = vc->vc_num;
1179 1519
1520 tty_lock();
1521
1180 if (!vc_cons_allocated(console)) { /* impossible? */ 1522 if (!vc_cons_allocated(console)) { /* impossible? */
1181 ret = -ENOIOCTLCMD; 1523 ret = -ENOIOCTLCMD;
1182 goto out; 1524 goto out;
@@ -1242,9 +1584,11 @@ long vt_compat_ioctl(struct tty_struct *tty,
1242 goto fallback; 1584 goto fallback;
1243 } 1585 }
1244out: 1586out:
1587 tty_unlock();
1245 return ret; 1588 return ret;
1246 1589
1247fallback: 1590fallback:
1591 tty_unlock();
1248 return vt_ioctl(tty, cmd, arg); 1592 return vt_ioctl(tty, cmd, arg);
1249} 1593}
1250 1594
@@ -1430,10 +1774,13 @@ int vt_move_to_console(unsigned int vt, int alloc)
1430 return -EIO; 1774 return -EIO;
1431 } 1775 }
1432 console_unlock(); 1776 console_unlock();
1777 tty_lock();
1433 if (vt_waitactive(vt + 1)) { 1778 if (vt_waitactive(vt + 1)) {
1434 pr_debug("Suspend: Can't switch VCs."); 1779 pr_debug("Suspend: Can't switch VCs.");
1780 tty_unlock();
1435 return -EINTR; 1781 return -EINTR;
1436 } 1782 }
1783 tty_unlock();
1437 return prev; 1784 return prev;
1438} 1785}
1439 1786