aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/Kconfig15
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/amiserial.c56
-rw-r--r--drivers/char/cyclades.c49
-rw-r--r--drivers/char/ip2/ip2main.c72
-rw-r--r--drivers/char/mxser.c109
-rw-r--r--drivers/char/nozomi.c37
-rw-r--r--drivers/char/pcmcia/synclink_cs.c60
-rw-r--r--drivers/char/pty.c4
-rw-r--r--drivers/char/synclink.c73
-rw-r--r--drivers/char/synclink_gt.c55
-rw-r--r--drivers/char/synclinkmp.c61
-rw-r--r--drivers/char/tty_io.c77
-rw-r--r--drivers/char/ttyprintk.c225
-rw-r--r--drivers/char/vc_screen.c135
-rw-r--r--drivers/char/vt.c5
-rw-r--r--drivers/input/serio/serport.c1
-rw-r--r--drivers/net/usb/hso.c35
-rw-r--r--drivers/serial/68360serial.c51
-rw-r--r--drivers/serial/8250.c69
-rw-r--r--drivers/serial/Kconfig7
-rw-r--r--drivers/serial/altera_uart.c156
-rw-r--r--drivers/serial/bfin_sport_uart.c7
-rw-r--r--drivers/serial/imx.c5
-rw-r--r--drivers/serial/jsm/jsm_driver.c4
-rw-r--r--drivers/serial/max3107.c34
-rw-r--r--drivers/serial/mfd.c47
-rw-r--r--drivers/serial/mrst_max3110.c358
-rw-r--r--drivers/serial/mrst_max3110.h1
-rw-r--r--drivers/serial/serial_core.c49
-rw-r--r--drivers/serial/uartlite.c26
-rw-r--r--drivers/usb/serial/ark3116.c40
-rw-r--r--drivers/usb/serial/ftdi_sio.c1
-rw-r--r--drivers/usb/serial/io_edgeport.c49
-rw-r--r--drivers/usb/serial/io_tables.h4
-rw-r--r--drivers/usb/serial/io_ti.c29
-rw-r--r--drivers/usb/serial/mos7720.c54
-rw-r--r--drivers/usb/serial/mos7840.c53
-rw-r--r--drivers/usb/serial/ssu100.c48
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c37
-rw-r--r--drivers/usb/serial/usb-serial.c13
41 files changed, 1480 insertions, 732 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 3d44ec724c17..43d3395325c5 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -493,6 +493,21 @@ config LEGACY_PTY_COUNT
493 When not in use, each legacy PTY occupies 12 bytes on 32-bit 493 When not in use, each legacy PTY occupies 12 bytes on 32-bit
494 architectures and 24 bytes on 64-bit architectures. 494 architectures and 24 bytes on 64-bit architectures.
495 495
496config TTY_PRINTK
497 bool "TTY driver to output user messages via printk"
498 depends on EMBEDDED
499 default n
500 ---help---
501 If you say Y here, the support for writing user messages (i.e.
502 console messages) via printk is available.
503
504 The feature is useful to inline user messages with kernel
505 messages.
506 In order to use this feature, you should output user messages
507 to /dev/ttyprintk or redirect console to this TTY.
508
509 If unsure, say N.
510
496config BRIQ_PANEL 511config BRIQ_PANEL
497 tristate 'Total Impact briQ front panel driver' 512 tristate 'Total Impact briQ front panel driver'
498 depends on PPC_CHRP 513 depends on PPC_CHRP
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index dc9641660605..3a9c01416839 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -12,6 +12,7 @@ obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o tty_buffer.o t
12obj-y += tty_mutex.o 12obj-y += tty_mutex.o
13obj-$(CONFIG_LEGACY_PTYS) += pty.o 13obj-$(CONFIG_LEGACY_PTYS) += pty.o
14obj-$(CONFIG_UNIX98_PTYS) += pty.o 14obj-$(CONFIG_UNIX98_PTYS) += pty.o
15obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o
15obj-y += misc.o 16obj-y += misc.o
16obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o 17obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o
17obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o 18obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index a11c8c9ca3d4..b0a70461a12c 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -1263,6 +1263,36 @@ static int rs_break(struct tty_struct *tty, int break_state)
1263 return 0; 1263 return 0;
1264} 1264}
1265 1265
1266/*
1267 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1268 * Return: write counters to the user passed counter struct
1269 * NB: both 1->0 and 0->1 transitions are counted except for
1270 * RI where only 0->1 is counted.
1271 */
1272static int rs_get_icount(struct tty_struct *tty,
1273 struct serial_icounter_struct *icount)
1274{
1275 struct async_struct *info = tty->driver_data;
1276 struct async_icount cnow;
1277 unsigned long flags;
1278
1279 local_irq_save(flags);
1280 cnow = info->state->icount;
1281 local_irq_restore(flags);
1282 icount->cts = cnow.cts;
1283 icount->dsr = cnow.dsr;
1284 icount->rng = cnow.rng;
1285 icount->dcd = cnow.dcd;
1286 icount->rx = cnow.rx;
1287 icount->tx = cnow.tx;
1288 icount->frame = cnow.frame;
1289 icount->overrun = cnow.overrun;
1290 icount->parity = cnow.parity;
1291 icount->brk = cnow.brk;
1292 icount->buf_overrun = cnow.buf_overrun;
1293
1294 return 0;
1295}
1266 1296
1267static int rs_ioctl(struct tty_struct *tty, struct file * file, 1297static int rs_ioctl(struct tty_struct *tty, struct file * file,
1268 unsigned int cmd, unsigned long arg) 1298 unsigned int cmd, unsigned long arg)
@@ -1332,31 +1362,6 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1332 } 1362 }
1333 /* NOTREACHED */ 1363 /* NOTREACHED */
1334 1364
1335 /*
1336 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1337 * Return: write counters to the user passed counter struct
1338 * NB: both 1->0 and 0->1 transitions are counted except for
1339 * RI where only 0->1 is counted.
1340 */
1341 case TIOCGICOUNT:
1342 local_irq_save(flags);
1343 cnow = info->state->icount;
1344 local_irq_restore(flags);
1345 icount.cts = cnow.cts;
1346 icount.dsr = cnow.dsr;
1347 icount.rng = cnow.rng;
1348 icount.dcd = cnow.dcd;
1349 icount.rx = cnow.rx;
1350 icount.tx = cnow.tx;
1351 icount.frame = cnow.frame;
1352 icount.overrun = cnow.overrun;
1353 icount.parity = cnow.parity;
1354 icount.brk = cnow.brk;
1355 icount.buf_overrun = cnow.buf_overrun;
1356
1357 if (copy_to_user(argp, &icount, sizeof(icount)))
1358 return -EFAULT;
1359 return 0;
1360 case TIOCSERGWILD: 1365 case TIOCSERGWILD:
1361 case TIOCSERSWILD: 1366 case TIOCSERSWILD:
1362 /* "setserial -W" is called in Debian boot */ 1367 /* "setserial -W" is called in Debian boot */
@@ -1958,6 +1963,7 @@ static const struct tty_operations serial_ops = {
1958 .wait_until_sent = rs_wait_until_sent, 1963 .wait_until_sent = rs_wait_until_sent,
1959 .tiocmget = rs_tiocmget, 1964 .tiocmget = rs_tiocmget,
1960 .tiocmset = rs_tiocmset, 1965 .tiocmset = rs_tiocmset,
1966 .get_icount = rs_get_icount,
1961 .proc_fops = &rs_proc_fops, 1967 .proc_fops = &rs_proc_fops,
1962}; 1968};
1963 1969
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 27aad9422332..4f152c28f40e 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -2790,29 +2790,6 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
2790 * NB: both 1->0 and 0->1 transitions are counted except for 2790 * NB: both 1->0 and 0->1 transitions are counted except for
2791 * RI where only 0->1 is counted. 2791 * RI where only 0->1 is counted.
2792 */ 2792 */
2793 case TIOCGICOUNT: {
2794 struct serial_icounter_struct sic = { };
2795
2796 spin_lock_irqsave(&info->card->card_lock, flags);
2797 cnow = info->icount;
2798 spin_unlock_irqrestore(&info->card->card_lock, flags);
2799
2800 sic.cts = cnow.cts;
2801 sic.dsr = cnow.dsr;
2802 sic.rng = cnow.rng;
2803 sic.dcd = cnow.dcd;
2804 sic.rx = cnow.rx;
2805 sic.tx = cnow.tx;
2806 sic.frame = cnow.frame;
2807 sic.overrun = cnow.overrun;
2808 sic.parity = cnow.parity;
2809 sic.brk = cnow.brk;
2810 sic.buf_overrun = cnow.buf_overrun;
2811
2812 if (copy_to_user(argp, &sic, sizeof(sic)))
2813 ret_val = -EFAULT;
2814 break;
2815 }
2816 default: 2793 default:
2817 ret_val = -ENOIOCTLCMD; 2794 ret_val = -ENOIOCTLCMD;
2818 } 2795 }
@@ -2823,6 +2800,31 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
2823 return ret_val; 2800 return ret_val;
2824} /* cy_ioctl */ 2801} /* cy_ioctl */
2825 2802
2803static int cy_get_icount(struct tty_struct *tty,
2804 struct serial_icounter_struct *sic)
2805{
2806 struct cyclades_port *info = tty->driver_data;
2807 struct cyclades_icount cnow; /* Used to snapshot */
2808 unsigned long flags;
2809
2810 spin_lock_irqsave(&info->card->card_lock, flags);
2811 cnow = info->icount;
2812 spin_unlock_irqrestore(&info->card->card_lock, flags);
2813
2814 sic->cts = cnow.cts;
2815 sic->dsr = cnow.dsr;
2816 sic->rng = cnow.rng;
2817 sic->dcd = cnow.dcd;
2818 sic->rx = cnow.rx;
2819 sic->tx = cnow.tx;
2820 sic->frame = cnow.frame;
2821 sic->overrun = cnow.overrun;
2822 sic->parity = cnow.parity;
2823 sic->brk = cnow.brk;
2824 sic->buf_overrun = cnow.buf_overrun;
2825 return 0;
2826}
2827
2826/* 2828/*
2827 * This routine allows the tty driver to be notified when 2829 * This routine allows the tty driver to be notified when
2828 * device's termios settings have changed. Note that a 2830 * device's termios settings have changed. Note that a
@@ -4084,6 +4086,7 @@ static const struct tty_operations cy_ops = {
4084 .wait_until_sent = cy_wait_until_sent, 4086 .wait_until_sent = cy_wait_until_sent,
4085 .tiocmget = cy_tiocmget, 4087 .tiocmget = cy_tiocmget,
4086 .tiocmset = cy_tiocmset, 4088 .tiocmset = cy_tiocmset,
4089 .get_icount = cy_get_icount,
4087 .proc_fops = &cyclades_proc_fops, 4090 .proc_fops = &cyclades_proc_fops,
4088}; 4091};
4089 4092
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 64a439ce2f89..fcd02baa7d65 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -184,6 +184,8 @@ static void ip2_hangup(PTTY);
184static int ip2_tiocmget(struct tty_struct *tty, struct file *file); 184static int ip2_tiocmget(struct tty_struct *tty, struct file *file);
185static int ip2_tiocmset(struct tty_struct *tty, struct file *file, 185static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
186 unsigned int set, unsigned int clear); 186 unsigned int set, unsigned int clear);
187static int ip2_get_icount(struct tty_struct *tty,
188 struct serial_icounter_struct *icount);
187 189
188static void set_irq(int, int); 190static void set_irq(int, int);
189static void ip2_interrupt_bh(struct work_struct *work); 191static void ip2_interrupt_bh(struct work_struct *work);
@@ -456,6 +458,7 @@ static const struct tty_operations ip2_ops = {
456 .hangup = ip2_hangup, 458 .hangup = ip2_hangup,
457 .tiocmget = ip2_tiocmget, 459 .tiocmget = ip2_tiocmget,
458 .tiocmset = ip2_tiocmset, 460 .tiocmset = ip2_tiocmset,
461 .get_icount = ip2_get_icount,
459 .proc_fops = &ip2_proc_fops, 462 .proc_fops = &ip2_proc_fops,
460}; 463};
461 464
@@ -2130,7 +2133,6 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2130 i2ChanStrPtr pCh = DevTable[tty->index]; 2133 i2ChanStrPtr pCh = DevTable[tty->index];
2131 i2eBordStrPtr pB; 2134 i2eBordStrPtr pB;
2132 struct async_icount cprev, cnow; /* kernel counter temps */ 2135 struct async_icount cprev, cnow; /* kernel counter temps */
2133 struct serial_icounter_struct __user *p_cuser;
2134 int rc = 0; 2136 int rc = 0;
2135 unsigned long flags; 2137 unsigned long flags;
2136 void __user *argp = (void __user *)arg; 2138 void __user *argp = (void __user *)arg;
@@ -2299,34 +2301,6 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2299 break; 2301 break;
2300 2302
2301 /* 2303 /*
2302 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2303 * Return: write counters to the user passed counter struct
2304 * NB: both 1->0 and 0->1 transitions are counted except for RI where
2305 * only 0->1 is counted. The controller is quite capable of counting
2306 * both, but this done to preserve compatibility with the standard
2307 * serial driver.
2308 */
2309 case TIOCGICOUNT:
2310 ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
2311
2312 write_lock_irqsave(&pB->read_fifo_spinlock, flags);
2313 cnow = pCh->icount;
2314 write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
2315 p_cuser = argp;
2316 rc = put_user(cnow.cts, &p_cuser->cts);
2317 rc = put_user(cnow.dsr, &p_cuser->dsr);
2318 rc = put_user(cnow.rng, &p_cuser->rng);
2319 rc = put_user(cnow.dcd, &p_cuser->dcd);
2320 rc = put_user(cnow.rx, &p_cuser->rx);
2321 rc = put_user(cnow.tx, &p_cuser->tx);
2322 rc = put_user(cnow.frame, &p_cuser->frame);
2323 rc = put_user(cnow.overrun, &p_cuser->overrun);
2324 rc = put_user(cnow.parity, &p_cuser->parity);
2325 rc = put_user(cnow.brk, &p_cuser->brk);
2326 rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
2327 break;
2328
2329 /*
2330 * The rest are not supported by this driver. By returning -ENOIOCTLCMD they 2304 * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
2331 * will be passed to the line discipline for it to handle. 2305 * will be passed to the line discipline for it to handle.
2332 */ 2306 */
@@ -2350,6 +2324,46 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2350 return rc; 2324 return rc;
2351} 2325}
2352 2326
2327static int ip2_get_icount(struct tty_struct *tty,
2328 struct serial_icounter_struct *icount)
2329{
2330 i2ChanStrPtr pCh = DevTable[tty->index];
2331 i2eBordStrPtr pB;
2332 struct async_icount cnow; /* kernel counter temp */
2333 unsigned long flags;
2334
2335 if ( pCh == NULL )
2336 return -ENODEV;
2337
2338 pB = pCh->pMyBord;
2339
2340 /*
2341 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2342 * Return: write counters to the user passed counter struct
2343 * NB: both 1->0 and 0->1 transitions are counted except for RI where
2344 * only 0->1 is counted. The controller is quite capable of counting
2345 * both, but this done to preserve compatibility with the standard
2346 * serial driver.
2347 */
2348
2349 write_lock_irqsave(&pB->read_fifo_spinlock, flags);
2350 cnow = pCh->icount;
2351 write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
2352
2353 icount->cts = cnow.cts;
2354 icount->dsr = cnow.dsr;
2355 icount->rng = cnow.rng;
2356 icount->dcd = cnow.dcd;
2357 icount->rx = cnow.rx;
2358 icount->tx = cnow.tx;
2359 icount->frame = cnow.frame;
2360 icount->overrun = cnow.overrun;
2361 icount->parity = cnow.parity;
2362 icount->brk = cnow.brk;
2363 icount->buf_overrun = cnow.buf_overrun;
2364 return 0;
2365}
2366
2353/******************************************************************************/ 2367/******************************************************************************/
2354/* Function: GetSerialInfo() */ 2368/* Function: GetSerialInfo() */
2355/* Parameters: Pointer to channel structure */ 2369/* Parameters: Pointer to channel structure */
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 3fc89da856ae..463df27494bd 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -1700,7 +1700,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1700 return 0; 1700 return 0;
1701 } 1701 }
1702 1702
1703 if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && cmd != TIOCGICOUNT && 1703 if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT &&
1704 test_bit(TTY_IO_ERROR, &tty->flags)) 1704 test_bit(TTY_IO_ERROR, &tty->flags))
1705 return -EIO; 1705 return -EIO;
1706 1706
@@ -1730,32 +1730,6 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1730 1730
1731 return wait_event_interruptible(info->port.delta_msr_wait, 1731 return wait_event_interruptible(info->port.delta_msr_wait,
1732 mxser_cflags_changed(info, arg, &cnow)); 1732 mxser_cflags_changed(info, arg, &cnow));
1733 /*
1734 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1735 * Return: write counters to the user passed counter struct
1736 * NB: both 1->0 and 0->1 transitions are counted except for
1737 * RI where only 0->1 is counted.
1738 */
1739 case TIOCGICOUNT: {
1740 struct serial_icounter_struct icnt = { 0 };
1741 spin_lock_irqsave(&info->slock, flags);
1742 cnow = info->icount;
1743 spin_unlock_irqrestore(&info->slock, flags);
1744
1745 icnt.frame = cnow.frame;
1746 icnt.brk = cnow.brk;
1747 icnt.overrun = cnow.overrun;
1748 icnt.buf_overrun = cnow.buf_overrun;
1749 icnt.parity = cnow.parity;
1750 icnt.rx = cnow.rx;
1751 icnt.tx = cnow.tx;
1752 icnt.cts = cnow.cts;
1753 icnt.dsr = cnow.dsr;
1754 icnt.rng = cnow.rng;
1755 icnt.dcd = cnow.dcd;
1756
1757 return copy_to_user(argp, &icnt, sizeof(icnt)) ? -EFAULT : 0;
1758 }
1759 case MOXA_HighSpeedOn: 1733 case MOXA_HighSpeedOn:
1760 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp); 1734 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1761 case MOXA_SDS_RSTICOUNTER: 1735 case MOXA_SDS_RSTICOUNTER:
@@ -1828,6 +1802,39 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1828 return 0; 1802 return 0;
1829} 1803}
1830 1804
1805 /*
1806 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1807 * Return: write counters to the user passed counter struct
1808 * NB: both 1->0 and 0->1 transitions are counted except for
1809 * RI where only 0->1 is counted.
1810 */
1811
1812static int mxser_get_icount(struct tty_struct *tty,
1813 struct serial_icounter_struct *icount)
1814
1815{
1816 struct mxser_port *info = tty->driver_data;
1817 struct async_icount cnow;
1818 unsigned long flags;
1819
1820 spin_lock_irqsave(&info->slock, flags);
1821 cnow = info->icount;
1822 spin_unlock_irqrestore(&info->slock, flags);
1823
1824 icount->frame = cnow.frame;
1825 icount->brk = cnow.brk;
1826 icount->overrun = cnow.overrun;
1827 icount->buf_overrun = cnow.buf_overrun;
1828 icount->parity = cnow.parity;
1829 icount->rx = cnow.rx;
1830 icount->tx = cnow.tx;
1831 icount->cts = cnow.cts;
1832 icount->dsr = cnow.dsr;
1833 icount->rng = cnow.rng;
1834 icount->dcd = cnow.dcd;
1835 return 0;
1836}
1837
1831static void mxser_stoprx(struct tty_struct *tty) 1838static void mxser_stoprx(struct tty_struct *tty)
1832{ 1839{
1833 struct mxser_port *info = tty->driver_data; 1840 struct mxser_port *info = tty->driver_data;
@@ -2326,6 +2333,7 @@ static const struct tty_operations mxser_ops = {
2326 .wait_until_sent = mxser_wait_until_sent, 2333 .wait_until_sent = mxser_wait_until_sent,
2327 .tiocmget = mxser_tiocmget, 2334 .tiocmget = mxser_tiocmget,
2328 .tiocmset = mxser_tiocmset, 2335 .tiocmset = mxser_tiocmset,
2336 .get_icount = mxser_get_icount,
2329}; 2337};
2330 2338
2331struct tty_port_operations mxser_port_ops = { 2339struct tty_port_operations mxser_port_ops = {
@@ -2339,20 +2347,11 @@ struct tty_port_operations mxser_port_ops = {
2339 * The MOXA Smartio/Industio serial driver boot-time initialization code! 2347 * The MOXA Smartio/Industio serial driver boot-time initialization code!
2340 */ 2348 */
2341 2349
2342static void mxser_release_res(struct mxser_board *brd, struct pci_dev *pdev, 2350static void mxser_release_ISA_res(struct mxser_board *brd)
2343 unsigned int irq)
2344{ 2351{
2345 if (irq) 2352 free_irq(brd->irq, brd);
2346 free_irq(brd->irq, brd); 2353 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2347 if (pdev != NULL) { /* PCI */ 2354 release_region(brd->vector, 1);
2348#ifdef CONFIG_PCI
2349 pci_release_region(pdev, 2);
2350 pci_release_region(pdev, 3);
2351#endif
2352 } else {
2353 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2354 release_region(brd->vector, 1);
2355 }
2356} 2355}
2357 2356
2358static int __devinit mxser_initbrd(struct mxser_board *brd, 2357static int __devinit mxser_initbrd(struct mxser_board *brd,
@@ -2397,13 +2396,11 @@ static int __devinit mxser_initbrd(struct mxser_board *brd,
2397 2396
2398 retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser", 2397 retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser",
2399 brd); 2398 brd);
2400 if (retval) { 2399 if (retval)
2401 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may " 2400 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may "
2402 "conflict with another device.\n", 2401 "conflict with another device.\n",
2403 brd->info->name, brd->irq); 2402 brd->info->name, brd->irq);
2404 /* We hold resources, we need to release them. */ 2403
2405 mxser_release_res(brd, pdev, 0);
2406 }
2407 return retval; 2404 return retval;
2408} 2405}
2409 2406
@@ -2555,7 +2552,7 @@ static int __devinit mxser_probe(struct pci_dev *pdev,
2555 ioaddress = pci_resource_start(pdev, 2); 2552 ioaddress = pci_resource_start(pdev, 2);
2556 retval = pci_request_region(pdev, 2, "mxser(IO)"); 2553 retval = pci_request_region(pdev, 2, "mxser(IO)");
2557 if (retval) 2554 if (retval)
2558 goto err; 2555 goto err_dis;
2559 2556
2560 brd->info = &mxser_cards[ent->driver_data]; 2557 brd->info = &mxser_cards[ent->driver_data];
2561 for (i = 0; i < brd->info->nports; i++) 2558 for (i = 0; i < brd->info->nports; i++)
@@ -2565,7 +2562,7 @@ static int __devinit mxser_probe(struct pci_dev *pdev,
2565 ioaddress = pci_resource_start(pdev, 3); 2562 ioaddress = pci_resource_start(pdev, 3);
2566 retval = pci_request_region(pdev, 3, "mxser(vector)"); 2563 retval = pci_request_region(pdev, 3, "mxser(vector)");
2567 if (retval) 2564 if (retval)
2568 goto err_relio; 2565 goto err_zero;
2569 brd->vector = ioaddress; 2566 brd->vector = ioaddress;
2570 2567
2571 /* irq */ 2568 /* irq */
@@ -2608,7 +2605,7 @@ static int __devinit mxser_probe(struct pci_dev *pdev,
2608 /* mxser_initbrd will hook ISR. */ 2605 /* mxser_initbrd will hook ISR. */
2609 retval = mxser_initbrd(brd, pdev); 2606 retval = mxser_initbrd(brd, pdev);
2610 if (retval) 2607 if (retval)
2611 goto err_null; 2608 goto err_rel3;
2612 2609
2613 for (i = 0; i < brd->info->nports; i++) 2610 for (i = 0; i < brd->info->nports; i++)
2614 tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev); 2611 tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev);
@@ -2616,10 +2613,13 @@ static int __devinit mxser_probe(struct pci_dev *pdev,
2616 pci_set_drvdata(pdev, brd); 2613 pci_set_drvdata(pdev, brd);
2617 2614
2618 return 0; 2615 return 0;
2619err_relio: 2616err_rel3:
2620 pci_release_region(pdev, 2); 2617 pci_release_region(pdev, 3);
2621err_null: 2618err_zero:
2622 brd->info = NULL; 2619 brd->info = NULL;
2620 pci_release_region(pdev, 2);
2621err_dis:
2622 pci_disable_device(pdev);
2623err: 2623err:
2624 return retval; 2624 return retval;
2625#else 2625#else
@@ -2629,14 +2629,19 @@ err:
2629 2629
2630static void __devexit mxser_remove(struct pci_dev *pdev) 2630static void __devexit mxser_remove(struct pci_dev *pdev)
2631{ 2631{
2632#ifdef CONFIG_PCI
2632 struct mxser_board *brd = pci_get_drvdata(pdev); 2633 struct mxser_board *brd = pci_get_drvdata(pdev);
2633 unsigned int i; 2634 unsigned int i;
2634 2635
2635 for (i = 0; i < brd->info->nports; i++) 2636 for (i = 0; i < brd->info->nports; i++)
2636 tty_unregister_device(mxvar_sdriver, brd->idx + i); 2637 tty_unregister_device(mxvar_sdriver, brd->idx + i);
2637 2638
2638 mxser_release_res(brd, pdev, 1); 2639 free_irq(pdev->irq, brd);
2640 pci_release_region(pdev, 2);
2641 pci_release_region(pdev, 3);
2642 pci_disable_device(pdev);
2639 brd->info = NULL; 2643 brd->info = NULL;
2644#endif
2640} 2645}
2641 2646
2642static struct pci_driver mxser_driver = { 2647static struct pci_driver mxser_driver = {
@@ -2741,7 +2746,7 @@ static void __exit mxser_module_exit(void)
2741 2746
2742 for (i = 0; i < MXSER_BOARDS; i++) 2747 for (i = 0; i < MXSER_BOARDS; i++)
2743 if (mxser_boards[i].info != NULL) 2748 if (mxser_boards[i].info != NULL)
2744 mxser_release_res(&mxser_boards[i], NULL, 1); 2749 mxser_release_ISA_res(&mxser_boards[i]);
2745} 2750}
2746 2751
2747module_init(mxser_module_init); 2752module_init(mxser_module_init);
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index 817169cbb245..dd3f9b1f11b4 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -1804,24 +1804,24 @@ static int ntty_cflags_changed(struct port *port, unsigned long flags,
1804 return ret; 1804 return ret;
1805} 1805}
1806 1806
1807static int ntty_ioctl_tiocgicount(struct port *port, void __user *argp) 1807static int ntty_tiocgicount(struct tty_struct *tty,
1808 struct serial_icounter_struct *icount)
1808{ 1809{
1810 struct port *port = tty->driver_data;
1809 const struct async_icount cnow = port->tty_icount; 1811 const struct async_icount cnow = port->tty_icount;
1810 struct serial_icounter_struct icount; 1812
1811 1813 icount->cts = cnow.cts;
1812 icount.cts = cnow.cts; 1814 icount->dsr = cnow.dsr;
1813 icount.dsr = cnow.dsr; 1815 icount->rng = cnow.rng;
1814 icount.rng = cnow.rng; 1816 icount->dcd = cnow.dcd;
1815 icount.dcd = cnow.dcd; 1817 icount->rx = cnow.rx;
1816 icount.rx = cnow.rx; 1818 icount->tx = cnow.tx;
1817 icount.tx = cnow.tx; 1819 icount->frame = cnow.frame;
1818 icount.frame = cnow.frame; 1820 icount->overrun = cnow.overrun;
1819 icount.overrun = cnow.overrun; 1821 icount->parity = cnow.parity;
1820 icount.parity = cnow.parity; 1822 icount->brk = cnow.brk;
1821 icount.brk = cnow.brk; 1823 icount->buf_overrun = cnow.buf_overrun;
1822 icount.buf_overrun = cnow.buf_overrun; 1824 return 0;
1823
1824 return copy_to_user(argp, &icount, sizeof(icount)) ? -EFAULT : 0;
1825} 1825}
1826 1826
1827static int ntty_ioctl(struct tty_struct *tty, struct file *file, 1827static int ntty_ioctl(struct tty_struct *tty, struct file *file,
@@ -1840,9 +1840,7 @@ static int ntty_ioctl(struct tty_struct *tty, struct file *file,
1840 rval = wait_event_interruptible(port->tty_wait, 1840 rval = wait_event_interruptible(port->tty_wait,
1841 ntty_cflags_changed(port, arg, &cprev)); 1841 ntty_cflags_changed(port, arg, &cprev));
1842 break; 1842 break;
1843 } case TIOCGICOUNT: 1843 }
1844 rval = ntty_ioctl_tiocgicount(port, argp);
1845 break;
1846 default: 1844 default:
1847 DBG1("ERR: 0x%08X, %d", cmd, cmd); 1845 DBG1("ERR: 0x%08X, %d", cmd, cmd);
1848 break; 1846 break;
@@ -1922,6 +1920,7 @@ static const struct tty_operations tty_ops = {
1922 .chars_in_buffer = ntty_chars_in_buffer, 1920 .chars_in_buffer = ntty_chars_in_buffer,
1923 .tiocmget = ntty_tiocmget, 1921 .tiocmget = ntty_tiocmget,
1924 .tiocmset = ntty_tiocmset, 1922 .tiocmset = ntty_tiocmset,
1923 .get_icount = ntty_tiocgicount,
1925 .install = ntty_install, 1924 .install = ntty_install,
1926 .cleanup = ntty_cleanup, 1925 .cleanup = ntty_cleanup,
1927}; 1926};
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index be1810057607..bfc10f89d951 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2191,6 +2191,32 @@ static int mgslpc_break(struct tty_struct *tty, int break_state)
2191 return 0; 2191 return 0;
2192} 2192}
2193 2193
2194static int mgslpc_get_icount(struct tty_struct *tty,
2195 struct serial_icounter_struct *icount)
2196{
2197 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
2198 struct mgsl_icount cnow; /* kernel counter temps */
2199 unsigned long flags;
2200
2201 spin_lock_irqsave(&info->lock,flags);
2202 cnow = info->icount;
2203 spin_unlock_irqrestore(&info->lock,flags);
2204
2205 icount->cts = cnow.cts;
2206 icount->dsr = cnow.dsr;
2207 icount->rng = cnow.rng;
2208 icount->dcd = cnow.dcd;
2209 icount->rx = cnow.rx;
2210 icount->tx = cnow.tx;
2211 icount->frame = cnow.frame;
2212 icount->overrun = cnow.overrun;
2213 icount->parity = cnow.parity;
2214 icount->brk = cnow.brk;
2215 icount->buf_overrun = cnow.buf_overrun;
2216
2217 return 0;
2218}
2219
2194/* Service an IOCTL request 2220/* Service an IOCTL request
2195 * 2221 *
2196 * Arguments: 2222 * Arguments:
@@ -2206,11 +2232,7 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file,
2206 unsigned int cmd, unsigned long arg) 2232 unsigned int cmd, unsigned long arg)
2207{ 2233{
2208 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; 2234 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
2209 int error;
2210 struct mgsl_icount cnow; /* kernel counter temps */
2211 struct serial_icounter_struct __user *p_cuser; /* user space */
2212 void __user *argp = (void __user *)arg; 2235 void __user *argp = (void __user *)arg;
2213 unsigned long flags;
2214 2236
2215 if (debug_level >= DEBUG_LEVEL_INFO) 2237 if (debug_level >= DEBUG_LEVEL_INFO)
2216 printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__, 2238 printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
@@ -2220,7 +2242,7 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file,
2220 return -ENODEV; 2242 return -ENODEV;
2221 2243
2222 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 2244 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2223 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { 2245 (cmd != TIOCMIWAIT)) {
2224 if (tty->flags & (1 << TTY_IO_ERROR)) 2246 if (tty->flags & (1 << TTY_IO_ERROR))
2225 return -EIO; 2247 return -EIO;
2226 } 2248 }
@@ -2250,34 +2272,6 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file,
2250 return wait_events(info, argp); 2272 return wait_events(info, argp);
2251 case TIOCMIWAIT: 2273 case TIOCMIWAIT:
2252 return modem_input_wait(info,(int)arg); 2274 return modem_input_wait(info,(int)arg);
2253 case TIOCGICOUNT:
2254 spin_lock_irqsave(&info->lock,flags);
2255 cnow = info->icount;
2256 spin_unlock_irqrestore(&info->lock,flags);
2257 p_cuser = argp;
2258 PUT_USER(error,cnow.cts, &p_cuser->cts);
2259 if (error) return error;
2260 PUT_USER(error,cnow.dsr, &p_cuser->dsr);
2261 if (error) return error;
2262 PUT_USER(error,cnow.rng, &p_cuser->rng);
2263 if (error) return error;
2264 PUT_USER(error,cnow.dcd, &p_cuser->dcd);
2265 if (error) return error;
2266 PUT_USER(error,cnow.rx, &p_cuser->rx);
2267 if (error) return error;
2268 PUT_USER(error,cnow.tx, &p_cuser->tx);
2269 if (error) return error;
2270 PUT_USER(error,cnow.frame, &p_cuser->frame);
2271 if (error) return error;
2272 PUT_USER(error,cnow.overrun, &p_cuser->overrun);
2273 if (error) return error;
2274 PUT_USER(error,cnow.parity, &p_cuser->parity);
2275 if (error) return error;
2276 PUT_USER(error,cnow.brk, &p_cuser->brk);
2277 if (error) return error;
2278 PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
2279 if (error) return error;
2280 return 0;
2281 default: 2275 default:
2282 return -ENOIOCTLCMD; 2276 return -ENOIOCTLCMD;
2283 } 2277 }
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index c350d01716bd..923a48585501 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -676,7 +676,9 @@ static int ptmx_open(struct inode *inode, struct file *filp)
676 676
677 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 677 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
678 678
679 tty_add_file(tty, filp); 679 retval = tty_add_file(tty, filp);
680 if (retval)
681 goto out;
680 682
681 retval = devpts_pty_new(inode, tty->link); 683 retval = devpts_pty_new(inode, tty->link);
682 if (retval) 684 if (retval)
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index a2a58004e188..3a6824f12be2 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -2925,6 +2925,38 @@ static int mgsl_break(struct tty_struct *tty, int break_state)
2925 2925
2926} /* end of mgsl_break() */ 2926} /* end of mgsl_break() */
2927 2927
2928/*
2929 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2930 * Return: write counters to the user passed counter struct
2931 * NB: both 1->0 and 0->1 transitions are counted except for
2932 * RI where only 0->1 is counted.
2933 */
2934static int msgl_get_icount(struct tty_struct *tty,
2935 struct serial_icounter_struct *icount)
2936
2937{
2938 struct mgsl_struct * info = tty->driver_data;
2939 struct mgsl_icount cnow; /* kernel counter temps */
2940 unsigned long flags;
2941
2942 spin_lock_irqsave(&info->irq_spinlock,flags);
2943 cnow = info->icount;
2944 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2945
2946 icount->cts = cnow.cts;
2947 icount->dsr = cnow.dsr;
2948 icount->rng = cnow.rng;
2949 icount->dcd = cnow.dcd;
2950 icount->rx = cnow.rx;
2951 icount->tx = cnow.tx;
2952 icount->frame = cnow.frame;
2953 icount->overrun = cnow.overrun;
2954 icount->parity = cnow.parity;
2955 icount->brk = cnow.brk;
2956 icount->buf_overrun = cnow.buf_overrun;
2957 return 0;
2958}
2959
2928/* mgsl_ioctl() Service an IOCTL request 2960/* mgsl_ioctl() Service an IOCTL request
2929 * 2961 *
2930 * Arguments: 2962 * Arguments:
@@ -2949,7 +2981,7 @@ static int mgsl_ioctl(struct tty_struct *tty, struct file * file,
2949 return -ENODEV; 2981 return -ENODEV;
2950 2982
2951 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 2983 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2952 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { 2984 (cmd != TIOCMIWAIT)) {
2953 if (tty->flags & (1 << TTY_IO_ERROR)) 2985 if (tty->flags & (1 << TTY_IO_ERROR))
2954 return -EIO; 2986 return -EIO;
2955 } 2987 }
@@ -2959,11 +2991,7 @@ static int mgsl_ioctl(struct tty_struct *tty, struct file * file,
2959 2991
2960static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg) 2992static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg)
2961{ 2993{
2962 int error;
2963 struct mgsl_icount cnow; /* kernel counter temps */
2964 void __user *argp = (void __user *)arg; 2994 void __user *argp = (void __user *)arg;
2965 struct serial_icounter_struct __user *p_cuser; /* user space */
2966 unsigned long flags;
2967 2995
2968 switch (cmd) { 2996 switch (cmd) {
2969 case MGSL_IOCGPARAMS: 2997 case MGSL_IOCGPARAMS:
@@ -2992,40 +3020,6 @@ static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigne
2992 case TIOCMIWAIT: 3020 case TIOCMIWAIT:
2993 return modem_input_wait(info,(int)arg); 3021 return modem_input_wait(info,(int)arg);
2994 3022
2995 /*
2996 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2997 * Return: write counters to the user passed counter struct
2998 * NB: both 1->0 and 0->1 transitions are counted except for
2999 * RI where only 0->1 is counted.
3000 */
3001 case TIOCGICOUNT:
3002 spin_lock_irqsave(&info->irq_spinlock,flags);
3003 cnow = info->icount;
3004 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3005 p_cuser = argp;
3006 PUT_USER(error,cnow.cts, &p_cuser->cts);
3007 if (error) return error;
3008 PUT_USER(error,cnow.dsr, &p_cuser->dsr);
3009 if (error) return error;
3010 PUT_USER(error,cnow.rng, &p_cuser->rng);
3011 if (error) return error;
3012 PUT_USER(error,cnow.dcd, &p_cuser->dcd);
3013 if (error) return error;
3014 PUT_USER(error,cnow.rx, &p_cuser->rx);
3015 if (error) return error;
3016 PUT_USER(error,cnow.tx, &p_cuser->tx);
3017 if (error) return error;
3018 PUT_USER(error,cnow.frame, &p_cuser->frame);
3019 if (error) return error;
3020 PUT_USER(error,cnow.overrun, &p_cuser->overrun);
3021 if (error) return error;
3022 PUT_USER(error,cnow.parity, &p_cuser->parity);
3023 if (error) return error;
3024 PUT_USER(error,cnow.brk, &p_cuser->brk);
3025 if (error) return error;
3026 PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
3027 if (error) return error;
3028 return 0;
3029 default: 3023 default:
3030 return -ENOIOCTLCMD; 3024 return -ENOIOCTLCMD;
3031 } 3025 }
@@ -4328,6 +4322,7 @@ static const struct tty_operations mgsl_ops = {
4328 .hangup = mgsl_hangup, 4322 .hangup = mgsl_hangup,
4329 .tiocmget = tiocmget, 4323 .tiocmget = tiocmget,
4330 .tiocmset = tiocmset, 4324 .tiocmset = tiocmset,
4325 .get_icount = msgl_get_icount,
4331 .proc_fops = &mgsl_proc_fops, 4326 .proc_fops = &mgsl_proc_fops,
4332}; 4327};
4333 4328
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index e63b830c86cc..1746d91205f7 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1032,9 +1032,6 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1032 unsigned int cmd, unsigned long arg) 1032 unsigned int cmd, unsigned long arg)
1033{ 1033{
1034 struct slgt_info *info = tty->driver_data; 1034 struct slgt_info *info = tty->driver_data;
1035 struct mgsl_icount cnow; /* kernel counter temps */
1036 struct serial_icounter_struct __user *p_cuser; /* user space */
1037 unsigned long flags;
1038 void __user *argp = (void __user *)arg; 1035 void __user *argp = (void __user *)arg;
1039 int ret; 1036 int ret;
1040 1037
@@ -1043,7 +1040,7 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1043 DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd)); 1040 DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd));
1044 1041
1045 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1042 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1046 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { 1043 (cmd != TIOCMIWAIT)) {
1047 if (tty->flags & (1 << TTY_IO_ERROR)) 1044 if (tty->flags & (1 << TTY_IO_ERROR))
1048 return -EIO; 1045 return -EIO;
1049 } 1046 }
@@ -1053,24 +1050,6 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1053 return wait_mgsl_event(info, argp); 1050 return wait_mgsl_event(info, argp);
1054 case TIOCMIWAIT: 1051 case TIOCMIWAIT:
1055 return modem_input_wait(info,(int)arg); 1052 return modem_input_wait(info,(int)arg);
1056 case TIOCGICOUNT:
1057 spin_lock_irqsave(&info->lock,flags);
1058 cnow = info->icount;
1059 spin_unlock_irqrestore(&info->lock,flags);
1060 p_cuser = argp;
1061 if (put_user(cnow.cts, &p_cuser->cts) ||
1062 put_user(cnow.dsr, &p_cuser->dsr) ||
1063 put_user(cnow.rng, &p_cuser->rng) ||
1064 put_user(cnow.dcd, &p_cuser->dcd) ||
1065 put_user(cnow.rx, &p_cuser->rx) ||
1066 put_user(cnow.tx, &p_cuser->tx) ||
1067 put_user(cnow.frame, &p_cuser->frame) ||
1068 put_user(cnow.overrun, &p_cuser->overrun) ||
1069 put_user(cnow.parity, &p_cuser->parity) ||
1070 put_user(cnow.brk, &p_cuser->brk) ||
1071 put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1072 return -EFAULT;
1073 return 0;
1074 case MGSL_IOCSGPIO: 1053 case MGSL_IOCSGPIO:
1075 return set_gpio(info, argp); 1054 return set_gpio(info, argp);
1076 case MGSL_IOCGGPIO: 1055 case MGSL_IOCGGPIO:
@@ -1117,6 +1096,33 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1117 return ret; 1096 return ret;
1118} 1097}
1119 1098
1099static int get_icount(struct tty_struct *tty,
1100 struct serial_icounter_struct *icount)
1101
1102{
1103 struct slgt_info *info = tty->driver_data;
1104 struct mgsl_icount cnow; /* kernel counter temps */
1105 unsigned long flags;
1106
1107 spin_lock_irqsave(&info->lock,flags);
1108 cnow = info->icount;
1109 spin_unlock_irqrestore(&info->lock,flags);
1110
1111 icount->cts = cnow.cts;
1112 icount->dsr = cnow.dsr;
1113 icount->rng = cnow.rng;
1114 icount->dcd = cnow.dcd;
1115 icount->rx = cnow.rx;
1116 icount->tx = cnow.tx;
1117 icount->frame = cnow.frame;
1118 icount->overrun = cnow.overrun;
1119 icount->parity = cnow.parity;
1120 icount->brk = cnow.brk;
1121 icount->buf_overrun = cnow.buf_overrun;
1122
1123 return 0;
1124}
1125
1120/* 1126/*
1121 * support for 32 bit ioctl calls on 64 bit systems 1127 * support for 32 bit ioctl calls on 64 bit systems
1122 */ 1128 */
@@ -1206,10 +1212,6 @@ static long slgt_compat_ioctl(struct tty_struct *tty, struct file *file,
1206 case MGSL_IOCSGPIO: 1212 case MGSL_IOCSGPIO:
1207 case MGSL_IOCGGPIO: 1213 case MGSL_IOCGGPIO:
1208 case MGSL_IOCWAITGPIO: 1214 case MGSL_IOCWAITGPIO:
1209 case TIOCGICOUNT:
1210 rc = ioctl(tty, file, cmd, (unsigned long)(compat_ptr(arg)));
1211 break;
1212
1213 case MGSL_IOCSTXIDLE: 1215 case MGSL_IOCSTXIDLE:
1214 case MGSL_IOCTXENABLE: 1216 case MGSL_IOCTXENABLE:
1215 case MGSL_IOCRXENABLE: 1217 case MGSL_IOCRXENABLE:
@@ -3642,6 +3644,7 @@ static const struct tty_operations ops = {
3642 .hangup = hangup, 3644 .hangup = hangup,
3643 .tiocmget = tiocmget, 3645 .tiocmget = tiocmget,
3644 .tiocmset = tiocmset, 3646 .tiocmset = tiocmset,
3647 .get_icount = get_icount,
3645 .proc_fops = &synclink_gt_proc_fops, 3648 .proc_fops = &synclink_gt_proc_fops,
3646}; 3649};
3647 3650
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index e56caf7d82aa..2f9eb4b0dec1 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -1258,10 +1258,6 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1258 unsigned int cmd, unsigned long arg) 1258 unsigned int cmd, unsigned long arg)
1259{ 1259{
1260 SLMP_INFO *info = tty->driver_data; 1260 SLMP_INFO *info = tty->driver_data;
1261 int error;
1262 struct mgsl_icount cnow; /* kernel counter temps */
1263 struct serial_icounter_struct __user *p_cuser; /* user space */
1264 unsigned long flags;
1265 void __user *argp = (void __user *)arg; 1261 void __user *argp = (void __user *)arg;
1266 1262
1267 if (debug_level >= DEBUG_LEVEL_INFO) 1263 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1272,7 +1268,7 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1272 return -ENODEV; 1268 return -ENODEV;
1273 1269
1274 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1270 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1275 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { 1271 (cmd != TIOCMIWAIT)) {
1276 if (tty->flags & (1 << TTY_IO_ERROR)) 1272 if (tty->flags & (1 << TTY_IO_ERROR))
1277 return -EIO; 1273 return -EIO;
1278 } 1274 }
@@ -1310,40 +1306,38 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1310 * NB: both 1->0 and 0->1 transitions are counted except for 1306 * NB: both 1->0 and 0->1 transitions are counted except for
1311 * RI where only 0->1 is counted. 1307 * RI where only 0->1 is counted.
1312 */ 1308 */
1313 case TIOCGICOUNT:
1314 spin_lock_irqsave(&info->lock,flags);
1315 cnow = info->icount;
1316 spin_unlock_irqrestore(&info->lock,flags);
1317 p_cuser = argp;
1318 PUT_USER(error,cnow.cts, &p_cuser->cts);
1319 if (error) return error;
1320 PUT_USER(error,cnow.dsr, &p_cuser->dsr);
1321 if (error) return error;
1322 PUT_USER(error,cnow.rng, &p_cuser->rng);
1323 if (error) return error;
1324 PUT_USER(error,cnow.dcd, &p_cuser->dcd);
1325 if (error) return error;
1326 PUT_USER(error,cnow.rx, &p_cuser->rx);
1327 if (error) return error;
1328 PUT_USER(error,cnow.tx, &p_cuser->tx);
1329 if (error) return error;
1330 PUT_USER(error,cnow.frame, &p_cuser->frame);
1331 if (error) return error;
1332 PUT_USER(error,cnow.overrun, &p_cuser->overrun);
1333 if (error) return error;
1334 PUT_USER(error,cnow.parity, &p_cuser->parity);
1335 if (error) return error;
1336 PUT_USER(error,cnow.brk, &p_cuser->brk);
1337 if (error) return error;
1338 PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
1339 if (error) return error;
1340 return 0;
1341 default: 1309 default:
1342 return -ENOIOCTLCMD; 1310 return -ENOIOCTLCMD;
1343 } 1311 }
1344 return 0; 1312 return 0;
1345} 1313}
1346 1314
1315static int get_icount(struct tty_struct *tty,
1316 struct serial_icounter_struct *icount)
1317{
1318 SLMP_INFO *info = tty->driver_data;
1319 struct mgsl_icount cnow; /* kernel counter temps */
1320 unsigned long flags;
1321
1322 spin_lock_irqsave(&info->lock,flags);
1323 cnow = info->icount;
1324 spin_unlock_irqrestore(&info->lock,flags);
1325
1326 icount->cts = cnow.cts;
1327 icount->dsr = cnow.dsr;
1328 icount->rng = cnow.rng;
1329 icount->dcd = cnow.dcd;
1330 icount->rx = cnow.rx;
1331 icount->tx = cnow.tx;
1332 icount->frame = cnow.frame;
1333 icount->overrun = cnow.overrun;
1334 icount->parity = cnow.parity;
1335 icount->brk = cnow.brk;
1336 icount->buf_overrun = cnow.buf_overrun;
1337
1338 return 0;
1339}
1340
1347/* 1341/*
1348 * /proc fs routines.... 1342 * /proc fs routines....
1349 */ 1343 */
@@ -3909,6 +3903,7 @@ static const struct tty_operations ops = {
3909 .hangup = hangup, 3903 .hangup = hangup,
3910 .tiocmget = tiocmget, 3904 .tiocmget = tiocmget,
3911 .tiocmset = tiocmset, 3905 .tiocmset = tiocmset,
3906 .get_icount = get_icount,
3912 .proc_fops = &synclinkmp_proc_fops, 3907 .proc_fops = &synclinkmp_proc_fops,
3913}; 3908};
3914 3909
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 613c852ee0fe..c05c5af5aa04 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -96,6 +96,7 @@
96#include <linux/bitops.h> 96#include <linux/bitops.h>
97#include <linux/delay.h> 97#include <linux/delay.h>
98#include <linux/seq_file.h> 98#include <linux/seq_file.h>
99#include <linux/serial.h>
99 100
100#include <linux/uaccess.h> 101#include <linux/uaccess.h>
101#include <asm/system.h> 102#include <asm/system.h>
@@ -183,6 +184,8 @@ struct tty_struct *alloc_tty_struct(void)
183 184
184void free_tty_struct(struct tty_struct *tty) 185void free_tty_struct(struct tty_struct *tty)
185{ 186{
187 if (tty->dev)
188 put_device(tty->dev);
186 kfree(tty->write_buf); 189 kfree(tty->write_buf);
187 tty_buffer_free_all(tty); 190 tty_buffer_free_all(tty);
188 kfree(tty); 191 kfree(tty);
@@ -194,12 +197,13 @@ static inline struct tty_struct *file_tty(struct file *file)
194} 197}
195 198
196/* Associate a new file with the tty structure */ 199/* Associate a new file with the tty structure */
197void tty_add_file(struct tty_struct *tty, struct file *file) 200int tty_add_file(struct tty_struct *tty, struct file *file)
198{ 201{
199 struct tty_file_private *priv; 202 struct tty_file_private *priv;
200 203
201 /* XXX: must implement proper error handling in callers */ 204 priv = kmalloc(sizeof(*priv), GFP_KERNEL);
202 priv = kmalloc(sizeof(*priv), GFP_KERNEL|__GFP_NOFAIL); 205 if (!priv)
206 return -ENOMEM;
203 207
204 priv->tty = tty; 208 priv->tty = tty;
205 priv->file = file; 209 priv->file = file;
@@ -208,6 +212,8 @@ void tty_add_file(struct tty_struct *tty, struct file *file)
208 spin_lock(&tty_files_lock); 212 spin_lock(&tty_files_lock);
209 list_add(&priv->list, &tty->tty_files); 213 list_add(&priv->list, &tty->tty_files);
210 spin_unlock(&tty_files_lock); 214 spin_unlock(&tty_files_lock);
215
216 return 0;
211} 217}
212 218
213/* Delete file from its tty */ 219/* Delete file from its tty */
@@ -1875,7 +1881,11 @@ got_driver:
1875 return PTR_ERR(tty); 1881 return PTR_ERR(tty);
1876 } 1882 }
1877 1883
1878 tty_add_file(tty, filp); 1884 retval = tty_add_file(tty, filp);
1885 if (retval) {
1886 tty_unlock();
1887 return retval;
1888 }
1879 1889
1880 check_tty_count(tty, "tty_open"); 1890 check_tty_count(tty, "tty_open");
1881 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1891 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
@@ -2502,6 +2512,20 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
2502 return tty->ops->tiocmset(tty, file, set, clear); 2512 return tty->ops->tiocmset(tty, file, set, clear);
2503} 2513}
2504 2514
2515static int tty_tiocgicount(struct tty_struct *tty, void __user *arg)
2516{
2517 int retval = -EINVAL;
2518 struct serial_icounter_struct icount;
2519 memset(&icount, 0, sizeof(icount));
2520 if (tty->ops->get_icount)
2521 retval = tty->ops->get_icount(tty, &icount);
2522 if (retval != 0)
2523 return retval;
2524 if (copy_to_user(arg, &icount, sizeof(icount)))
2525 return -EFAULT;
2526 return 0;
2527}
2528
2505struct tty_struct *tty_pair_get_tty(struct tty_struct *tty) 2529struct tty_struct *tty_pair_get_tty(struct tty_struct *tty)
2506{ 2530{
2507 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 2531 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
@@ -2622,6 +2646,12 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2622 case TIOCMBIC: 2646 case TIOCMBIC:
2623 case TIOCMBIS: 2647 case TIOCMBIS:
2624 return tty_tiocmset(tty, file, cmd, p); 2648 return tty_tiocmset(tty, file, cmd, p);
2649 case TIOCGICOUNT:
2650 retval = tty_tiocgicount(tty, p);
2651 /* For the moment allow fall through to the old method */
2652 if (retval != -EINVAL)
2653 return retval;
2654 break;
2625 case TCFLSH: 2655 case TCFLSH:
2626 switch (arg) { 2656 switch (arg) {
2627 case TCIFLUSH: 2657 case TCIFLUSH:
@@ -2783,6 +2813,20 @@ void do_SAK(struct tty_struct *tty)
2783 2813
2784EXPORT_SYMBOL(do_SAK); 2814EXPORT_SYMBOL(do_SAK);
2785 2815
2816static int dev_match_devt(struct device *dev, void *data)
2817{
2818 dev_t *devt = data;
2819 return dev->devt == *devt;
2820}
2821
2822/* Must put_device() after it's unused! */
2823static struct device *tty_get_device(struct tty_struct *tty)
2824{
2825 dev_t devt = tty_devnum(tty);
2826 return class_find_device(tty_class, NULL, &devt, dev_match_devt);
2827}
2828
2829
2786/** 2830/**
2787 * initialize_tty_struct 2831 * initialize_tty_struct
2788 * @tty: tty to initialize 2832 * @tty: tty to initialize
@@ -2823,6 +2867,7 @@ void initialize_tty_struct(struct tty_struct *tty,
2823 tty->ops = driver->ops; 2867 tty->ops = driver->ops;
2824 tty->index = idx; 2868 tty->index = idx;
2825 tty_line_name(driver, idx, tty->name); 2869 tty_line_name(driver, idx, tty->name);
2870 tty->dev = tty_get_device(tty);
2826} 2871}
2827 2872
2828/** 2873/**
@@ -2980,6 +3025,7 @@ int tty_register_driver(struct tty_driver *driver)
2980 int i; 3025 int i;
2981 dev_t dev; 3026 dev_t dev;
2982 void **p = NULL; 3027 void **p = NULL;
3028 struct device *d;
2983 3029
2984 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) { 3030 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) {
2985 p = kzalloc(driver->num * 2 * sizeof(void *), GFP_KERNEL); 3031 p = kzalloc(driver->num * 2 * sizeof(void *), GFP_KERNEL);
@@ -3027,12 +3073,31 @@ int tty_register_driver(struct tty_driver *driver)
3027 mutex_unlock(&tty_mutex); 3073 mutex_unlock(&tty_mutex);
3028 3074
3029 if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) { 3075 if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) {
3030 for (i = 0; i < driver->num; i++) 3076 for (i = 0; i < driver->num; i++) {
3031 tty_register_device(driver, i, NULL); 3077 d = tty_register_device(driver, i, NULL);
3078 if (IS_ERR(d)) {
3079 error = PTR_ERR(d);
3080 goto err;
3081 }
3082 }
3032 } 3083 }
3033 proc_tty_register_driver(driver); 3084 proc_tty_register_driver(driver);
3034 driver->flags |= TTY_DRIVER_INSTALLED; 3085 driver->flags |= TTY_DRIVER_INSTALLED;
3035 return 0; 3086 return 0;
3087
3088err:
3089 for (i--; i >= 0; i--)
3090 tty_unregister_device(driver, i);
3091
3092 mutex_lock(&tty_mutex);
3093 list_del(&driver->tty_drivers);
3094 mutex_unlock(&tty_mutex);
3095
3096 unregister_chrdev_region(dev, driver->num);
3097 driver->ttys = NULL;
3098 driver->termios = NULL;
3099 kfree(p);
3100 return error;
3036} 3101}
3037 3102
3038EXPORT_SYMBOL(tty_register_driver); 3103EXPORT_SYMBOL(tty_register_driver);
diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
new file mode 100644
index 000000000000..c40c1612c8a7
--- /dev/null
+++ b/drivers/char/ttyprintk.c
@@ -0,0 +1,225 @@
1/*
2 * linux/drivers/char/ttyprintk.c
3 *
4 * Copyright (C) 2010 Samo Pogacnik
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the smems of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 */
10
11/*
12 * This pseudo device allows user to make printk messages. It is possible
13 * to store "console" messages inline with kernel messages for better analyses
14 * of the boot process, for example.
15 */
16
17#include <linux/device.h>
18#include <linux/serial.h>
19#include <linux/tty.h>
20
21struct ttyprintk_port {
22 struct tty_port port;
23 struct mutex port_write_mutex;
24};
25
26static struct ttyprintk_port tpk_port;
27
28/*
29 * Our simple preformatting supports transparent output of (time-stamped)
30 * printk messages (also suitable for logging service):
31 * - any cr is replaced by nl
32 * - adds a ttyprintk source tag in front of each line
33 * - too long message is fragmeted, with '\'nl between fragments
34 * - TPK_STR_SIZE isn't really the write_room limiting factor, bcause
35 * it is emptied on the fly during preformatting.
36 */
37#define TPK_STR_SIZE 508 /* should be bigger then max expected line length */
38#define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */
39static const char *tpk_tag = "[U] "; /* U for User */
40static int tpk_curr;
41
42static int tpk_printk(const unsigned char *buf, int count)
43{
44 static char tmp[TPK_STR_SIZE + 4];
45 int i = tpk_curr;
46
47 if (buf == NULL) {
48 /* flush tmp[] */
49 if (tpk_curr > 0) {
50 /* non nl or cr terminated message - add nl */
51 tmp[tpk_curr + 0] = '\n';
52 tmp[tpk_curr + 1] = '\0';
53 printk(KERN_INFO "%s%s", tpk_tag, tmp);
54 tpk_curr = 0;
55 }
56 return i;
57 }
58
59 for (i = 0; i < count; i++) {
60 tmp[tpk_curr] = buf[i];
61 if (tpk_curr < TPK_STR_SIZE) {
62 switch (buf[i]) {
63 case '\r':
64 /* replace cr with nl */
65 tmp[tpk_curr + 0] = '\n';
66 tmp[tpk_curr + 1] = '\0';
67 printk(KERN_INFO "%s%s", tpk_tag, tmp);
68 tpk_curr = 0;
69 if (buf[i + 1] == '\n')
70 i++;
71 break;
72 case '\n':
73 tmp[tpk_curr + 1] = '\0';
74 printk(KERN_INFO "%s%s", tpk_tag, tmp);
75 tpk_curr = 0;
76 break;
77 default:
78 tpk_curr++;
79 }
80 } else {
81 /* end of tmp buffer reached: cut the message in two */
82 tmp[tpk_curr + 1] = '\\';
83 tmp[tpk_curr + 2] = '\n';
84 tmp[tpk_curr + 3] = '\0';
85 printk(KERN_INFO "%s%s", tpk_tag, tmp);
86 tpk_curr = 0;
87 }
88 }
89
90 return count;
91}
92
93/*
94 * TTY operations open function.
95 */
96static int tpk_open(struct tty_struct *tty, struct file *filp)
97{
98 tty->driver_data = &tpk_port;
99
100 return tty_port_open(&tpk_port.port, tty, filp);
101}
102
103/*
104 * TTY operations close function.
105 */
106static void tpk_close(struct tty_struct *tty, struct file *filp)
107{
108 struct ttyprintk_port *tpkp = tty->driver_data;
109
110 mutex_lock(&tpkp->port_write_mutex);
111 /* flush tpk_printk buffer */
112 tpk_printk(NULL, 0);
113 mutex_unlock(&tpkp->port_write_mutex);
114
115 tty_port_close(&tpkp->port, tty, filp);
116}
117
118/*
119 * TTY operations write function.
120 */
121static int tpk_write(struct tty_struct *tty,
122 const unsigned char *buf, int count)
123{
124 struct ttyprintk_port *tpkp = tty->driver_data;
125 int ret;
126
127
128 /* exclusive use of tpk_printk within this tty */
129 mutex_lock(&tpkp->port_write_mutex);
130 ret = tpk_printk(buf, count);
131 mutex_unlock(&tpkp->port_write_mutex);
132
133 return ret;
134}
135
136/*
137 * TTY operations write_room function.
138 */
139static int tpk_write_room(struct tty_struct *tty)
140{
141 return TPK_MAX_ROOM;
142}
143
144/*
145 * TTY operations ioctl function.
146 */
147static int tpk_ioctl(struct tty_struct *tty, struct file *file,
148 unsigned int cmd, unsigned long arg)
149{
150 struct ttyprintk_port *tpkp = tty->driver_data;
151
152 if (!tpkp)
153 return -EINVAL;
154
155 switch (cmd) {
156 /* Stop TIOCCONS */
157 case TIOCCONS:
158 return -EOPNOTSUPP;
159 default:
160 return -ENOIOCTLCMD;
161 }
162 return 0;
163}
164
165static const struct tty_operations ttyprintk_ops = {
166 .open = tpk_open,
167 .close = tpk_close,
168 .write = tpk_write,
169 .write_room = tpk_write_room,
170 .ioctl = tpk_ioctl,
171};
172
173struct tty_port_operations null_ops = { };
174
175static struct tty_driver *ttyprintk_driver;
176
177static int __init ttyprintk_init(void)
178{
179 int ret = -ENOMEM;
180 void *rp;
181
182 ttyprintk_driver = alloc_tty_driver(1);
183 if (!ttyprintk_driver)
184 return ret;
185
186 ttyprintk_driver->owner = THIS_MODULE;
187 ttyprintk_driver->driver_name = "ttyprintk";
188 ttyprintk_driver->name = "ttyprintk";
189 ttyprintk_driver->major = TTYAUX_MAJOR;
190 ttyprintk_driver->minor_start = 3;
191 ttyprintk_driver->num = 1;
192 ttyprintk_driver->type = TTY_DRIVER_TYPE_CONSOLE;
193 ttyprintk_driver->init_termios = tty_std_termios;
194 ttyprintk_driver->init_termios.c_oflag = OPOST | OCRNL | ONOCR | ONLRET;
195 ttyprintk_driver->flags = TTY_DRIVER_RESET_TERMIOS |
196 TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
197 tty_set_operations(ttyprintk_driver, &ttyprintk_ops);
198
199 ret = tty_register_driver(ttyprintk_driver);
200 if (ret < 0) {
201 printk(KERN_ERR "Couldn't register ttyprintk driver\n");
202 goto error;
203 }
204
205 /* create our unnumbered device */
206 rp = device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 3), NULL,
207 ttyprintk_driver->name);
208 if (IS_ERR(rp)) {
209 printk(KERN_ERR "Couldn't create ttyprintk device\n");
210 ret = PTR_ERR(rp);
211 goto error;
212 }
213
214 tty_port_init(&tpk_port.port);
215 tpk_port.port.ops = &null_ops;
216 mutex_init(&tpk_port.port_write_mutex);
217
218 return 0;
219
220error:
221 put_tty_driver(ttyprintk_driver);
222 ttyprintk_driver = NULL;
223 return ret;
224}
225module_init(ttyprintk_init);
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index bcce46c96b88..273ab44cc91d 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -35,6 +35,12 @@
35#include <linux/console.h> 35#include <linux/console.h>
36#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/smp_lock.h> 37#include <linux/smp_lock.h>
38#include <linux/sched.h>
39#include <linux/fs.h>
40#include <linux/poll.h>
41#include <linux/signal.h>
42#include <linux/slab.h>
43#include <linux/notifier.h>
38 44
39#include <asm/uaccess.h> 45#include <asm/uaccess.h>
40#include <asm/byteorder.h> 46#include <asm/byteorder.h>
@@ -45,6 +51,86 @@
45#undef addr 51#undef addr
46#define HEADER_SIZE 4 52#define HEADER_SIZE 4
47 53
54struct vcs_poll_data {
55 struct notifier_block notifier;
56 unsigned int cons_num;
57 bool seen_last_update;
58 wait_queue_head_t waitq;
59 struct fasync_struct *fasync;
60};
61
62static int
63vcs_notifier(struct notifier_block *nb, unsigned long code, void *_param)
64{
65 struct vt_notifier_param *param = _param;
66 struct vc_data *vc = param->vc;
67 struct vcs_poll_data *poll =
68 container_of(nb, struct vcs_poll_data, notifier);
69 int currcons = poll->cons_num;
70
71 if (code != VT_UPDATE)
72 return NOTIFY_DONE;
73
74 if (currcons == 0)
75 currcons = fg_console;
76 else
77 currcons--;
78 if (currcons != vc->vc_num)
79 return NOTIFY_DONE;
80
81 poll->seen_last_update = false;
82 wake_up_interruptible(&poll->waitq);
83 kill_fasync(&poll->fasync, SIGIO, POLL_IN);
84 return NOTIFY_OK;
85}
86
87static void
88vcs_poll_data_free(struct vcs_poll_data *poll)
89{
90 unregister_vt_notifier(&poll->notifier);
91 kfree(poll);
92}
93
94static struct vcs_poll_data *
95vcs_poll_data_get(struct file *file)
96{
97 struct vcs_poll_data *poll = file->private_data;
98
99 if (poll)
100 return poll;
101
102 poll = kzalloc(sizeof(*poll), GFP_KERNEL);
103 if (!poll)
104 return NULL;
105 poll->cons_num = iminor(file->f_path.dentry->d_inode) & 127;
106 init_waitqueue_head(&poll->waitq);
107 poll->notifier.notifier_call = vcs_notifier;
108 if (register_vt_notifier(&poll->notifier) != 0) {
109 kfree(poll);
110 return NULL;
111 }
112
113 /*
114 * This code may be called either through ->poll() or ->fasync().
115 * If we have two threads using the same file descriptor, they could
116 * both enter this function, both notice that the structure hasn't
117 * been allocated yet and go ahead allocating it in parallel, but
118 * only one of them must survive and be shared otherwise we'd leak
119 * memory with a dangling notifier callback.
120 */
121 spin_lock(&file->f_lock);
122 if (!file->private_data) {
123 file->private_data = poll;
124 } else {
125 /* someone else raced ahead of us */
126 vcs_poll_data_free(poll);
127 poll = file->private_data;
128 }
129 spin_unlock(&file->f_lock);
130
131 return poll;
132}
133
48static int 134static int
49vcs_size(struct inode *inode) 135vcs_size(struct inode *inode)
50{ 136{
@@ -102,6 +188,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
102 struct inode *inode = file->f_path.dentry->d_inode; 188 struct inode *inode = file->f_path.dentry->d_inode;
103 unsigned int currcons = iminor(inode); 189 unsigned int currcons = iminor(inode);
104 struct vc_data *vc; 190 struct vc_data *vc;
191 struct vcs_poll_data *poll;
105 long pos; 192 long pos;
106 long viewed, attr, read; 193 long viewed, attr, read;
107 int col, maxcol; 194 int col, maxcol;
@@ -134,6 +221,9 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
134 ret = -EINVAL; 221 ret = -EINVAL;
135 if (pos < 0) 222 if (pos < 0)
136 goto unlock_out; 223 goto unlock_out;
224 poll = file->private_data;
225 if (count && poll)
226 poll->seen_last_update = true;
137 read = 0; 227 read = 0;
138 ret = 0; 228 ret = 0;
139 while (count) { 229 while (count) {
@@ -448,6 +538,8 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
448 } 538 }
449 *ppos += written; 539 *ppos += written;
450 ret = written; 540 ret = written;
541 if (written)
542 vcs_scr_updated(vc);
451 543
452unlock_out: 544unlock_out:
453 release_console_sem(); 545 release_console_sem();
@@ -457,6 +549,37 @@ unlock_out:
457 return ret; 549 return ret;
458} 550}
459 551
552static unsigned int
553vcs_poll(struct file *file, poll_table *wait)
554{
555 struct vcs_poll_data *poll = vcs_poll_data_get(file);
556 int ret = 0;
557
558 if (poll) {
559 poll_wait(file, &poll->waitq, wait);
560 if (!poll->seen_last_update)
561 ret = POLLIN | POLLRDNORM;
562 }
563 return ret;
564}
565
566static int
567vcs_fasync(int fd, struct file *file, int on)
568{
569 struct vcs_poll_data *poll = file->private_data;
570
571 if (!poll) {
572 /* don't allocate anything if all we want is disable fasync */
573 if (!on)
574 return 0;
575 poll = vcs_poll_data_get(file);
576 if (!poll)
577 return -ENOMEM;
578 }
579
580 return fasync_helper(fd, file, on, &poll->fasync);
581}
582
460static int 583static int
461vcs_open(struct inode *inode, struct file *filp) 584vcs_open(struct inode *inode, struct file *filp)
462{ 585{
@@ -470,11 +593,23 @@ vcs_open(struct inode *inode, struct file *filp)
470 return ret; 593 return ret;
471} 594}
472 595
596static int vcs_release(struct inode *inode, struct file *file)
597{
598 struct vcs_poll_data *poll = file->private_data;
599
600 if (poll)
601 vcs_poll_data_free(poll);
602 return 0;
603}
604
473static const struct file_operations vcs_fops = { 605static const struct file_operations vcs_fops = {
474 .llseek = vcs_lseek, 606 .llseek = vcs_lseek,
475 .read = vcs_read, 607 .read = vcs_read,
476 .write = vcs_write, 608 .write = vcs_write,
609 .poll = vcs_poll,
610 .fasync = vcs_fasync,
477 .open = vcs_open, 611 .open = vcs_open,
612 .release = vcs_release,
478}; 613};
479 614
480static struct class *vc_class; 615static struct class *vc_class;
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 281aada7b4a1..a8ec48ed14d9 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -4182,6 +4182,11 @@ void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org)
4182 } 4182 }
4183} 4183}
4184 4184
4185void vcs_scr_updated(struct vc_data *vc)
4186{
4187 notify_update(vc);
4188}
4189
4185/* 4190/*
4186 * Visible symbols for modules 4191 * Visible symbols for modules
4187 */ 4192 */
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 6d345112bcb7..6e362de3f412 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -165,6 +165,7 @@ static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, u
165 serio->open = serport_serio_open; 165 serio->open = serport_serio_open;
166 serio->close = serport_serio_close; 166 serio->close = serport_serio_close;
167 serio->port_data = serport; 167 serio->port_data = serport;
168 serio->dev.parent = tty->dev;
168 169
169 serio_register_port(serport->serio); 170 serio_register_port(serport->serio);
170 printk(KERN_INFO "serio: Serial port %s\n", tty_name(tty, name)); 171 printk(KERN_INFO "serio: Serial port %s\n", tty_name(tty, name));
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 1cd752f9a6e1..b8e957249132 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1645,11 +1645,11 @@ hso_wait_modem_status(struct hso_serial *serial, unsigned long arg)
1645 * NB: both 1->0 and 0->1 transitions are counted except for 1645 * NB: both 1->0 and 0->1 transitions are counted except for
1646 * RI where only 0->1 is counted. 1646 * RI where only 0->1 is counted.
1647 */ 1647 */
1648static int hso_get_count(struct hso_serial *serial, 1648static int hso_get_count(struct tty_struct *tty,
1649 struct serial_icounter_struct __user *icnt) 1649 struct serial_icounter_struct *icount)
1650{ 1650{
1651 struct serial_icounter_struct icount;
1652 struct uart_icount cnow; 1651 struct uart_icount cnow;
1652 struct hso_serial *serial = get_serial_by_tty(tty);
1653 struct hso_tiocmget *tiocmget = serial->tiocmget; 1653 struct hso_tiocmget *tiocmget = serial->tiocmget;
1654 1654
1655 memset(&icount, 0, sizeof(struct serial_icounter_struct)); 1655 memset(&icount, 0, sizeof(struct serial_icounter_struct));
@@ -1660,19 +1660,19 @@ static int hso_get_count(struct hso_serial *serial,
1660 memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount)); 1660 memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
1661 spin_unlock_irq(&serial->serial_lock); 1661 spin_unlock_irq(&serial->serial_lock);
1662 1662
1663 icount.cts = cnow.cts; 1663 icount->cts = cnow.cts;
1664 icount.dsr = cnow.dsr; 1664 icount->dsr = cnow.dsr;
1665 icount.rng = cnow.rng; 1665 icount->rng = cnow.rng;
1666 icount.dcd = cnow.dcd; 1666 icount->dcd = cnow.dcd;
1667 icount.rx = cnow.rx; 1667 icount->rx = cnow.rx;
1668 icount.tx = cnow.tx; 1668 icount->tx = cnow.tx;
1669 icount.frame = cnow.frame; 1669 icount->frame = cnow.frame;
1670 icount.overrun = cnow.overrun; 1670 icount->overrun = cnow.overrun;
1671 icount.parity = cnow.parity; 1671 icount->parity = cnow.parity;
1672 icount.brk = cnow.brk; 1672 icount->brk = cnow.brk;
1673 icount.buf_overrun = cnow.buf_overrun; 1673 icount->buf_overrun = cnow.buf_overrun;
1674 1674
1675 return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0; 1675 return 0;
1676} 1676}
1677 1677
1678 1678
@@ -1764,10 +1764,6 @@ static int hso_serial_ioctl(struct tty_struct *tty, struct file *file,
1764 case TIOCMIWAIT: 1764 case TIOCMIWAIT:
1765 ret = hso_wait_modem_status(serial, arg); 1765 ret = hso_wait_modem_status(serial, arg);
1766 break; 1766 break;
1767
1768 case TIOCGICOUNT:
1769 ret = hso_get_count(serial, uarg);
1770 break;
1771 default: 1767 default:
1772 ret = -ENOIOCTLCMD; 1768 ret = -ENOIOCTLCMD;
1773 break; 1769 break;
@@ -3300,6 +3296,7 @@ static const struct tty_operations hso_serial_ops = {
3300 .chars_in_buffer = hso_serial_chars_in_buffer, 3296 .chars_in_buffer = hso_serial_chars_in_buffer,
3301 .tiocmget = hso_serial_tiocmget, 3297 .tiocmget = hso_serial_tiocmget,
3302 .tiocmset = hso_serial_tiocmset, 3298 .tiocmset = hso_serial_tiocmset,
3299 .get_icount = hso_get_count,
3303 .unthrottle = hso_unthrottle 3300 .unthrottle = hso_unthrottle
3304}; 3301};
3305 3302
diff --git a/drivers/serial/68360serial.c b/drivers/serial/68360serial.c
index 0dff3bbddc8b..88b13356ec10 100644
--- a/drivers/serial/68360serial.c
+++ b/drivers/serial/68360serial.c
@@ -1381,6 +1381,30 @@ static void send_break(ser_info_t *info, unsigned int duration)
1381} 1381}
1382 1382
1383 1383
1384/*
1385 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1386 * Return: write counters to the user passed counter struct
1387 * NB: both 1->0 and 0->1 transitions are counted except for
1388 * RI where only 0->1 is counted.
1389 */
1390static int rs_360_get_icount(struct tty_struct *tty,
1391 struct serial_icounter_struct *icount)
1392{
1393 ser_info_t *info = (ser_info_t *)tty->driver_data;
1394 struct async_icount cnow;
1395
1396 local_irq_disable();
1397 cnow = info->state->icount;
1398 local_irq_enable();
1399
1400 icount->cts = cnow.cts;
1401 icount->dsr = cnow.dsr;
1402 icount->rng = cnow.rng;
1403 icount->dcd = cnow.dcd;
1404
1405 return 0;
1406}
1407
1384static int rs_360_ioctl(struct tty_struct *tty, struct file * file, 1408static int rs_360_ioctl(struct tty_struct *tty, struct file * file,
1385 unsigned int cmd, unsigned long arg) 1409 unsigned int cmd, unsigned long arg)
1386{ 1410{
@@ -1394,7 +1418,7 @@ static int rs_360_ioctl(struct tty_struct *tty, struct file * file,
1394 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) 1418 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1395 return -ENODEV; 1419 return -ENODEV;
1396 1420
1397 if ((cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { 1421 if (cmd != TIOCMIWAIT) {
1398 if (tty->flags & (1 << TTY_IO_ERROR)) 1422 if (tty->flags & (1 << TTY_IO_ERROR))
1399 return -EIO; 1423 return -EIO;
1400 } 1424 }
@@ -1477,31 +1501,6 @@ static int rs_360_ioctl(struct tty_struct *tty, struct file * file,
1477 return 0; 1501 return 0;
1478#endif 1502#endif
1479 1503
1480 /*
1481 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1482 * Return: write counters to the user passed counter struct
1483 * NB: both 1->0 and 0->1 transitions are counted except for
1484 * RI where only 0->1 is counted.
1485 */
1486 case TIOCGICOUNT:
1487 local_irq_disable();
1488 cnow = info->state->icount;
1489 local_irq_enable();
1490 p_cuser = (struct serial_icounter_struct *) arg;
1491/* error = put_user(cnow.cts, &p_cuser->cts); */
1492/* if (error) return error; */
1493/* error = put_user(cnow.dsr, &p_cuser->dsr); */
1494/* if (error) return error; */
1495/* error = put_user(cnow.rng, &p_cuser->rng); */
1496/* if (error) return error; */
1497/* error = put_user(cnow.dcd, &p_cuser->dcd); */
1498/* if (error) return error; */
1499
1500 put_user(cnow.cts, &p_cuser->cts);
1501 put_user(cnow.dsr, &p_cuser->dsr);
1502 put_user(cnow.rng, &p_cuser->rng);
1503 put_user(cnow.dcd, &p_cuser->dcd);
1504 return 0;
1505 1504
1506 default: 1505 default:
1507 return -ENOIOCTLCMD; 1506 return -ENOIOCTLCMD;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 24110f6f61e0..167c4a6ccbc3 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -31,6 +31,7 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/platform_device.h> 32#include <linux/platform_device.h>
33#include <linux/tty.h> 33#include <linux/tty.h>
34#include <linux/ratelimit.h>
34#include <linux/tty_flip.h> 35#include <linux/tty_flip.h>
35#include <linux/serial_reg.h> 36#include <linux/serial_reg.h>
36#include <linux/serial_core.h> 37#include <linux/serial_core.h>
@@ -154,12 +155,6 @@ struct uart_8250_port {
154 unsigned char lsr_saved_flags; 155 unsigned char lsr_saved_flags;
155#define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA 156#define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
156 unsigned char msr_saved_flags; 157 unsigned char msr_saved_flags;
157
158 /*
159 * We provide a per-port pm hook.
160 */
161 void (*pm)(struct uart_port *port,
162 unsigned int state, unsigned int old);
163}; 158};
164 159
165struct irq_info { 160struct irq_info {
@@ -1606,8 +1601,8 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
1606 1601
1607 if (l == i->head && pass_counter++ > PASS_LIMIT) { 1602 if (l == i->head && pass_counter++ > PASS_LIMIT) {
1608 /* If we hit this, we're dead. */ 1603 /* If we hit this, we're dead. */
1609 printk(KERN_ERR "serial8250: too much work for " 1604 printk_ratelimited(KERN_ERR
1610 "irq%d\n", irq); 1605 "serial8250: too much work for irq%d\n", irq);
1611 break; 1606 break;
1612 } 1607 }
1613 } while (l != end); 1608 } while (l != end);
@@ -1722,12 +1717,6 @@ static void serial_unlink_irq_chain(struct uart_8250_port *up)
1722 mutex_unlock(&hash_mutex); 1717 mutex_unlock(&hash_mutex);
1723} 1718}
1724 1719
1725/* Base timer interval for polling */
1726static inline int poll_timeout(int timeout)
1727{
1728 return timeout > 6 ? (timeout / 2 - 2) : 1;
1729}
1730
1731/* 1720/*
1732 * This function is used to handle ports that do not have an 1721 * This function is used to handle ports that do not have an
1733 * interrupt. This doesn't work very well for 16450's, but gives 1722 * interrupt. This doesn't work very well for 16450's, but gives
@@ -1742,7 +1731,7 @@ static void serial8250_timeout(unsigned long data)
1742 iir = serial_in(up, UART_IIR); 1731 iir = serial_in(up, UART_IIR);
1743 if (!(iir & UART_IIR_NO_INT)) 1732 if (!(iir & UART_IIR_NO_INT))
1744 serial8250_handle_port(up); 1733 serial8250_handle_port(up);
1745 mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout)); 1734 mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port));
1746} 1735}
1747 1736
1748static void serial8250_backup_timeout(unsigned long data) 1737static void serial8250_backup_timeout(unsigned long data)
@@ -1787,7 +1776,7 @@ static void serial8250_backup_timeout(unsigned long data)
1787 1776
1788 /* Standard timer interval plus 0.2s to keep the port running */ 1777 /* Standard timer interval plus 0.2s to keep the port running */
1789 mod_timer(&up->timer, 1778 mod_timer(&up->timer,
1790 jiffies + poll_timeout(up->port.timeout) + HZ / 5); 1779 jiffies + uart_poll_timeout(&up->port) + HZ / 5);
1791} 1780}
1792 1781
1793static unsigned int serial8250_tx_empty(struct uart_port *port) 1782static unsigned int serial8250_tx_empty(struct uart_port *port)
@@ -1867,15 +1856,17 @@ static void wait_for_xmitr(struct uart_8250_port *up, int bits)
1867 unsigned int status, tmout = 10000; 1856 unsigned int status, tmout = 10000;
1868 1857
1869 /* Wait up to 10ms for the character(s) to be sent. */ 1858 /* Wait up to 10ms for the character(s) to be sent. */
1870 do { 1859 for (;;) {
1871 status = serial_in(up, UART_LSR); 1860 status = serial_in(up, UART_LSR);
1872 1861
1873 up->lsr_saved_flags |= status & LSR_SAVE_FLAGS; 1862 up->lsr_saved_flags |= status & LSR_SAVE_FLAGS;
1874 1863
1864 if ((status & bits) == bits)
1865 break;
1875 if (--tmout == 0) 1866 if (--tmout == 0)
1876 break; 1867 break;
1877 udelay(1); 1868 udelay(1);
1878 } while ((status & bits) != bits); 1869 }
1879 1870
1880 /* Wait up to 1s for flow control if necessary */ 1871 /* Wait up to 1s for flow control if necessary */
1881 if (up->port.flags & UPF_CONS_FLOW) { 1872 if (up->port.flags & UPF_CONS_FLOW) {
@@ -2069,7 +2060,7 @@ static int serial8250_startup(struct uart_port *port)
2069 up->timer.function = serial8250_backup_timeout; 2060 up->timer.function = serial8250_backup_timeout;
2070 up->timer.data = (unsigned long)up; 2061 up->timer.data = (unsigned long)up;
2071 mod_timer(&up->timer, jiffies + 2062 mod_timer(&up->timer, jiffies +
2072 poll_timeout(up->port.timeout) + HZ / 5); 2063 uart_poll_timeout(port) + HZ / 5);
2073 } 2064 }
2074 2065
2075 /* 2066 /*
@@ -2079,7 +2070,7 @@ static int serial8250_startup(struct uart_port *port)
2079 */ 2070 */
2080 if (!is_real_interrupt(up->port.irq)) { 2071 if (!is_real_interrupt(up->port.irq)) {
2081 up->timer.data = (unsigned long)up; 2072 up->timer.data = (unsigned long)up;
2082 mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout)); 2073 mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
2083 } else { 2074 } else {
2084 retval = serial_link_irq_chain(up); 2075 retval = serial_link_irq_chain(up);
2085 if (retval) 2076 if (retval)
@@ -2440,16 +2431,24 @@ serial8250_set_ldisc(struct uart_port *port, int new)
2440 port->flags &= ~UPF_HARDPPS_CD; 2431 port->flags &= ~UPF_HARDPPS_CD;
2441} 2432}
2442 2433
2443static void 2434
2444serial8250_pm(struct uart_port *port, unsigned int state, 2435void serial8250_do_pm(struct uart_port *port, unsigned int state,
2445 unsigned int oldstate) 2436 unsigned int oldstate)
2446{ 2437{
2447 struct uart_8250_port *p = (struct uart_8250_port *)port; 2438 struct uart_8250_port *p = (struct uart_8250_port *)port;
2448 2439
2449 serial8250_set_sleep(p, state != 0); 2440 serial8250_set_sleep(p, state != 0);
2441}
2442EXPORT_SYMBOL(serial8250_do_pm);
2450 2443
2451 if (p->pm) 2444static void
2452 p->pm(port, state, oldstate); 2445serial8250_pm(struct uart_port *port, unsigned int state,
2446 unsigned int oldstate)
2447{
2448 if (port->pm)
2449 port->pm(port, state, oldstate);
2450 else
2451 serial8250_do_pm(port, state, oldstate);
2453} 2452}
2454 2453
2455static unsigned int serial8250_port_size(struct uart_8250_port *pt) 2454static unsigned int serial8250_port_size(struct uart_8250_port *pt)
@@ -2674,6 +2673,16 @@ static struct uart_ops serial8250_pops = {
2674 2673
2675static struct uart_8250_port serial8250_ports[UART_NR]; 2674static struct uart_8250_port serial8250_ports[UART_NR];
2676 2675
2676static void (*serial8250_isa_config)(int port, struct uart_port *up,
2677 unsigned short *capabilities);
2678
2679void serial8250_set_isa_configurator(
2680 void (*v)(int port, struct uart_port *up, unsigned short *capabilities))
2681{
2682 serial8250_isa_config = v;
2683}
2684EXPORT_SYMBOL(serial8250_set_isa_configurator);
2685
2677static void __init serial8250_isa_init_ports(void) 2686static void __init serial8250_isa_init_ports(void)
2678{ 2687{
2679 struct uart_8250_port *up; 2688 struct uart_8250_port *up;
@@ -2719,6 +2728,9 @@ static void __init serial8250_isa_init_ports(void)
2719 up->port.regshift = old_serial_port[i].iomem_reg_shift; 2728 up->port.regshift = old_serial_port[i].iomem_reg_shift;
2720 set_io_from_upio(&up->port); 2729 set_io_from_upio(&up->port);
2721 up->port.irqflags |= irqflag; 2730 up->port.irqflags |= irqflag;
2731 if (serial8250_isa_config != NULL)
2732 serial8250_isa_config(i, &up->port, &up->capabilities);
2733
2722 } 2734 }
2723} 2735}
2724 2736
@@ -3010,6 +3022,7 @@ static int __devinit serial8250_probe(struct platform_device *dev)
3010 port.serial_in = p->serial_in; 3022 port.serial_in = p->serial_in;
3011 port.serial_out = p->serial_out; 3023 port.serial_out = p->serial_out;
3012 port.set_termios = p->set_termios; 3024 port.set_termios = p->set_termios;
3025 port.pm = p->pm;
3013 port.dev = &dev->dev; 3026 port.dev = &dev->dev;
3014 port.irqflags |= irqflag; 3027 port.irqflags |= irqflag;
3015 ret = serial8250_register_port(&port); 3028 ret = serial8250_register_port(&port);
@@ -3176,6 +3189,12 @@ int serial8250_register_port(struct uart_port *port)
3176 /* Possibly override set_termios call */ 3189 /* Possibly override set_termios call */
3177 if (port->set_termios) 3190 if (port->set_termios)
3178 uart->port.set_termios = port->set_termios; 3191 uart->port.set_termios = port->set_termios;
3192 if (port->pm)
3193 uart->port.pm = port->pm;
3194
3195 if (serial8250_isa_config != NULL)
3196 serial8250_isa_config(0, &uart->port,
3197 &uart->capabilities);
3179 3198
3180 ret = uart_add_one_port(&serial8250_reg, &uart->port); 3199 ret = uart_add_one_port(&serial8250_reg, &uart->port);
3181 if (ret == 0) 3200 if (ret == 0)
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 3198c5335f0b..927816484397 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -718,13 +718,6 @@ config SERIAL_MRST_MAX3110
718 the Intel Moorestown platform. On other systems use the max3100 718 the Intel Moorestown platform. On other systems use the max3100
719 driver. 719 driver.
720 720
721config MRST_MAX3110_IRQ
722 boolean "Enable GPIO IRQ for Max3110 over Moorestown"
723 default n
724 depends on SERIAL_MRST_MAX3110 && GPIO_LANGWELL
725 help
726 This has to be enabled after Moorestown GPIO driver is loaded
727
728config SERIAL_MFD_HSU 721config SERIAL_MFD_HSU
729 tristate "Medfield High Speed UART support" 722 tristate "Medfield High Speed UART support"
730 depends on PCI 723 depends on PCI
diff --git a/drivers/serial/altera_uart.c b/drivers/serial/altera_uart.c
index f8d8a00554da..721216292a50 100644
--- a/drivers/serial/altera_uart.c
+++ b/drivers/serial/altera_uart.c
@@ -15,6 +15,7 @@
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/timer.h>
18#include <linux/interrupt.h> 19#include <linux/interrupt.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/console.h> 21#include <linux/console.h>
@@ -27,6 +28,8 @@
27#include <linux/altera_uart.h> 28#include <linux/altera_uart.h>
28 29
29#define DRV_NAME "altera_uart" 30#define DRV_NAME "altera_uart"
31#define SERIAL_ALTERA_MAJOR 204
32#define SERIAL_ALTERA_MINOR 213
30 33
31/* 34/*
32 * Altera UART register definitions according to the Nios UART datasheet: 35 * Altera UART register definitions according to the Nios UART datasheet:
@@ -76,13 +79,28 @@
76 */ 79 */
77struct altera_uart { 80struct altera_uart {
78 struct uart_port port; 81 struct uart_port port;
82 struct timer_list tmr;
79 unsigned int sigs; /* Local copy of line sigs */ 83 unsigned int sigs; /* Local copy of line sigs */
80 unsigned short imr; /* Local IMR mirror */ 84 unsigned short imr; /* Local IMR mirror */
81}; 85};
82 86
87static u32 altera_uart_readl(struct uart_port *port, int reg)
88{
89 struct altera_uart_platform_uart *platp = port->private_data;
90
91 return readl(port->membase + (reg << platp->bus_shift));
92}
93
94static void altera_uart_writel(struct uart_port *port, u32 dat, int reg)
95{
96 struct altera_uart_platform_uart *platp = port->private_data;
97
98 writel(dat, port->membase + (reg << platp->bus_shift));
99}
100
83static unsigned int altera_uart_tx_empty(struct uart_port *port) 101static unsigned int altera_uart_tx_empty(struct uart_port *port)
84{ 102{
85 return (readl(port->membase + ALTERA_UART_STATUS_REG) & 103 return (altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
86 ALTERA_UART_STATUS_TMT_MSK) ? TIOCSER_TEMT : 0; 104 ALTERA_UART_STATUS_TMT_MSK) ? TIOCSER_TEMT : 0;
87} 105}
88 106
@@ -91,8 +109,7 @@ static unsigned int altera_uart_get_mctrl(struct uart_port *port)
91 struct altera_uart *pp = container_of(port, struct altera_uart, port); 109 struct altera_uart *pp = container_of(port, struct altera_uart, port);
92 unsigned int sigs; 110 unsigned int sigs;
93 111
94 sigs = 112 sigs = (altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
95 (readl(port->membase + ALTERA_UART_STATUS_REG) &
96 ALTERA_UART_STATUS_CTS_MSK) ? TIOCM_CTS : 0; 113 ALTERA_UART_STATUS_CTS_MSK) ? TIOCM_CTS : 0;
97 sigs |= (pp->sigs & TIOCM_RTS); 114 sigs |= (pp->sigs & TIOCM_RTS);
98 115
@@ -108,7 +125,7 @@ static void altera_uart_set_mctrl(struct uart_port *port, unsigned int sigs)
108 pp->imr |= ALTERA_UART_CONTROL_RTS_MSK; 125 pp->imr |= ALTERA_UART_CONTROL_RTS_MSK;
109 else 126 else
110 pp->imr &= ~ALTERA_UART_CONTROL_RTS_MSK; 127 pp->imr &= ~ALTERA_UART_CONTROL_RTS_MSK;
111 writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG); 128 altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
112} 129}
113 130
114static void altera_uart_start_tx(struct uart_port *port) 131static void altera_uart_start_tx(struct uart_port *port)
@@ -116,7 +133,7 @@ static void altera_uart_start_tx(struct uart_port *port)
116 struct altera_uart *pp = container_of(port, struct altera_uart, port); 133 struct altera_uart *pp = container_of(port, struct altera_uart, port);
117 134
118 pp->imr |= ALTERA_UART_CONTROL_TRDY_MSK; 135 pp->imr |= ALTERA_UART_CONTROL_TRDY_MSK;
119 writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG); 136 altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
120} 137}
121 138
122static void altera_uart_stop_tx(struct uart_port *port) 139static void altera_uart_stop_tx(struct uart_port *port)
@@ -124,7 +141,7 @@ static void altera_uart_stop_tx(struct uart_port *port)
124 struct altera_uart *pp = container_of(port, struct altera_uart, port); 141 struct altera_uart *pp = container_of(port, struct altera_uart, port);
125 142
126 pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK; 143 pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK;
127 writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG); 144 altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
128} 145}
129 146
130static void altera_uart_stop_rx(struct uart_port *port) 147static void altera_uart_stop_rx(struct uart_port *port)
@@ -132,7 +149,7 @@ static void altera_uart_stop_rx(struct uart_port *port)
132 struct altera_uart *pp = container_of(port, struct altera_uart, port); 149 struct altera_uart *pp = container_of(port, struct altera_uart, port);
133 150
134 pp->imr &= ~ALTERA_UART_CONTROL_RRDY_MSK; 151 pp->imr &= ~ALTERA_UART_CONTROL_RRDY_MSK;
135 writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG); 152 altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
136} 153}
137 154
138static void altera_uart_break_ctl(struct uart_port *port, int break_state) 155static void altera_uart_break_ctl(struct uart_port *port, int break_state)
@@ -145,7 +162,7 @@ static void altera_uart_break_ctl(struct uart_port *port, int break_state)
145 pp->imr |= ALTERA_UART_CONTROL_TRBK_MSK; 162 pp->imr |= ALTERA_UART_CONTROL_TRBK_MSK;
146 else 163 else
147 pp->imr &= ~ALTERA_UART_CONTROL_TRBK_MSK; 164 pp->imr &= ~ALTERA_UART_CONTROL_TRBK_MSK;
148 writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG); 165 altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
149 spin_unlock_irqrestore(&port->lock, flags); 166 spin_unlock_irqrestore(&port->lock, flags);
150} 167}
151 168
@@ -168,7 +185,8 @@ static void altera_uart_set_termios(struct uart_port *port,
168 tty_termios_encode_baud_rate(termios, baud, baud); 185 tty_termios_encode_baud_rate(termios, baud, baud);
169 186
170 spin_lock_irqsave(&port->lock, flags); 187 spin_lock_irqsave(&port->lock, flags);
171 writel(baudclk, port->membase + ALTERA_UART_DIVISOR_REG); 188 uart_update_timeout(port, termios->c_cflag, baud);
189 altera_uart_writel(port, baudclk, ALTERA_UART_DIVISOR_REG);
172 spin_unlock_irqrestore(&port->lock, flags); 190 spin_unlock_irqrestore(&port->lock, flags);
173} 191}
174 192
@@ -178,14 +196,15 @@ static void altera_uart_rx_chars(struct altera_uart *pp)
178 unsigned char ch, flag; 196 unsigned char ch, flag;
179 unsigned short status; 197 unsigned short status;
180 198
181 while ((status = readl(port->membase + ALTERA_UART_STATUS_REG)) & 199 while ((status = altera_uart_readl(port, ALTERA_UART_STATUS_REG)) &
182 ALTERA_UART_STATUS_RRDY_MSK) { 200 ALTERA_UART_STATUS_RRDY_MSK) {
183 ch = readl(port->membase + ALTERA_UART_RXDATA_REG); 201 ch = altera_uart_readl(port, ALTERA_UART_RXDATA_REG);
184 flag = TTY_NORMAL; 202 flag = TTY_NORMAL;
185 port->icount.rx++; 203 port->icount.rx++;
186 204
187 if (status & ALTERA_UART_STATUS_E_MSK) { 205 if (status & ALTERA_UART_STATUS_E_MSK) {
188 writel(status, port->membase + ALTERA_UART_STATUS_REG); 206 altera_uart_writel(port, status,
207 ALTERA_UART_STATUS_REG);
189 208
190 if (status & ALTERA_UART_STATUS_BRK_MSK) { 209 if (status & ALTERA_UART_STATUS_BRK_MSK) {
191 port->icount.brk++; 210 port->icount.brk++;
@@ -225,18 +244,18 @@ static void altera_uart_tx_chars(struct altera_uart *pp)
225 244
226 if (port->x_char) { 245 if (port->x_char) {
227 /* Send special char - probably flow control */ 246 /* Send special char - probably flow control */
228 writel(port->x_char, port->membase + ALTERA_UART_TXDATA_REG); 247 altera_uart_writel(port, port->x_char, ALTERA_UART_TXDATA_REG);
229 port->x_char = 0; 248 port->x_char = 0;
230 port->icount.tx++; 249 port->icount.tx++;
231 return; 250 return;
232 } 251 }
233 252
234 while (readl(port->membase + ALTERA_UART_STATUS_REG) & 253 while (altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
235 ALTERA_UART_STATUS_TRDY_MSK) { 254 ALTERA_UART_STATUS_TRDY_MSK) {
236 if (xmit->head == xmit->tail) 255 if (xmit->head == xmit->tail)
237 break; 256 break;
238 writel(xmit->buf[xmit->tail], 257 altera_uart_writel(port, xmit->buf[xmit->tail],
239 port->membase + ALTERA_UART_TXDATA_REG); 258 ALTERA_UART_TXDATA_REG);
240 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 259 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
241 port->icount.tx++; 260 port->icount.tx++;
242 } 261 }
@@ -246,7 +265,7 @@ static void altera_uart_tx_chars(struct altera_uart *pp)
246 265
247 if (xmit->head == xmit->tail) { 266 if (xmit->head == xmit->tail) {
248 pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK; 267 pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK;
249 writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG); 268 altera_uart_writel(port, pp->imr, ALTERA_UART_CONTROL_REG);
250 } 269 }
251} 270}
252 271
@@ -256,7 +275,7 @@ static irqreturn_t altera_uart_interrupt(int irq, void *data)
256 struct altera_uart *pp = container_of(port, struct altera_uart, port); 275 struct altera_uart *pp = container_of(port, struct altera_uart, port);
257 unsigned int isr; 276 unsigned int isr;
258 277
259 isr = readl(port->membase + ALTERA_UART_STATUS_REG) & pp->imr; 278 isr = altera_uart_readl(port, ALTERA_UART_STATUS_REG) & pp->imr;
260 279
261 spin_lock(&port->lock); 280 spin_lock(&port->lock);
262 if (isr & ALTERA_UART_STATUS_RRDY_MSK) 281 if (isr & ALTERA_UART_STATUS_RRDY_MSK)
@@ -268,14 +287,23 @@ static irqreturn_t altera_uart_interrupt(int irq, void *data)
268 return IRQ_RETVAL(isr); 287 return IRQ_RETVAL(isr);
269} 288}
270 289
290static void altera_uart_timer(unsigned long data)
291{
292 struct uart_port *port = (void *)data;
293 struct altera_uart *pp = container_of(port, struct altera_uart, port);
294
295 altera_uart_interrupt(0, port);
296 mod_timer(&pp->tmr, jiffies + uart_poll_timeout(port));
297}
298
271static void altera_uart_config_port(struct uart_port *port, int flags) 299static void altera_uart_config_port(struct uart_port *port, int flags)
272{ 300{
273 port->type = PORT_ALTERA_UART; 301 port->type = PORT_ALTERA_UART;
274 302
275 /* Clear mask, so no surprise interrupts. */ 303 /* Clear mask, so no surprise interrupts. */
276 writel(0, port->membase + ALTERA_UART_CONTROL_REG); 304 altera_uart_writel(port, 0, ALTERA_UART_CONTROL_REG);
277 /* Clear status register */ 305 /* Clear status register */
278 writel(0, port->membase + ALTERA_UART_STATUS_REG); 306 altera_uart_writel(port, 0, ALTERA_UART_STATUS_REG);
279} 307}
280 308
281static int altera_uart_startup(struct uart_port *port) 309static int altera_uart_startup(struct uart_port *port)
@@ -284,6 +312,12 @@ static int altera_uart_startup(struct uart_port *port)
284 unsigned long flags; 312 unsigned long flags;
285 int ret; 313 int ret;
286 314
315 if (!port->irq) {
316 setup_timer(&pp->tmr, altera_uart_timer, (unsigned long)port);
317 mod_timer(&pp->tmr, jiffies + uart_poll_timeout(port));
318 return 0;
319 }
320
287 ret = request_irq(port->irq, altera_uart_interrupt, IRQF_DISABLED, 321 ret = request_irq(port->irq, altera_uart_interrupt, IRQF_DISABLED,
288 DRV_NAME, port); 322 DRV_NAME, port);
289 if (ret) { 323 if (ret) {
@@ -316,7 +350,10 @@ static void altera_uart_shutdown(struct uart_port *port)
316 350
317 spin_unlock_irqrestore(&port->lock, flags); 351 spin_unlock_irqrestore(&port->lock, flags);
318 352
319 free_irq(port->irq, port); 353 if (port->irq)
354 free_irq(port->irq, port);
355 else
356 del_timer_sync(&pp->tmr);
320} 357}
321 358
322static const char *altera_uart_type(struct uart_port *port) 359static const char *altera_uart_type(struct uart_port *port)
@@ -384,8 +421,9 @@ int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp)
384 port->iotype = SERIAL_IO_MEM; 421 port->iotype = SERIAL_IO_MEM;
385 port->irq = platp[i].irq; 422 port->irq = platp[i].irq;
386 port->uartclk = platp[i].uartclk; 423 port->uartclk = platp[i].uartclk;
387 port->flags = ASYNC_BOOT_AUTOCONF; 424 port->flags = UPF_BOOT_AUTOCONF;
388 port->ops = &altera_uart_ops; 425 port->ops = &altera_uart_ops;
426 port->private_data = platp;
389 } 427 }
390 428
391 return 0; 429 return 0;
@@ -393,7 +431,7 @@ int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp)
393 431
394static void altera_uart_console_putc(struct uart_port *port, const char c) 432static void altera_uart_console_putc(struct uart_port *port, const char c)
395{ 433{
396 while (!(readl(port->membase + ALTERA_UART_STATUS_REG) & 434 while (!(altera_uart_readl(port, ALTERA_UART_STATUS_REG) &
397 ALTERA_UART_STATUS_TRDY_MSK)) 435 ALTERA_UART_STATUS_TRDY_MSK))
398 cpu_relax(); 436 cpu_relax();
399 437
@@ -423,7 +461,7 @@ static int __init altera_uart_console_setup(struct console *co, char *options)
423 if (co->index < 0 || co->index >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS) 461 if (co->index < 0 || co->index >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
424 return -EINVAL; 462 return -EINVAL;
425 port = &altera_uart_ports[co->index].port; 463 port = &altera_uart_ports[co->index].port;
426 if (port->membase == 0) 464 if (!port->membase)
427 return -ENODEV; 465 return -ENODEV;
428 466
429 if (options) 467 if (options)
@@ -435,7 +473,7 @@ static int __init altera_uart_console_setup(struct console *co, char *options)
435static struct uart_driver altera_uart_driver; 473static struct uart_driver altera_uart_driver;
436 474
437static struct console altera_uart_console = { 475static struct console altera_uart_console = {
438 .name = "ttyS", 476 .name = "ttyAL",
439 .write = altera_uart_console_write, 477 .write = altera_uart_console_write,
440 .device = uart_console_device, 478 .device = uart_console_device,
441 .setup = altera_uart_console_setup, 479 .setup = altera_uart_console_setup,
@@ -466,9 +504,9 @@ console_initcall(altera_uart_console_init);
466static struct uart_driver altera_uart_driver = { 504static struct uart_driver altera_uart_driver = {
467 .owner = THIS_MODULE, 505 .owner = THIS_MODULE,
468 .driver_name = DRV_NAME, 506 .driver_name = DRV_NAME,
469 .dev_name = "ttyS", 507 .dev_name = "ttyAL",
470 .major = TTY_MAJOR, 508 .major = SERIAL_ALTERA_MAJOR,
471 .minor = 64, 509 .minor = SERIAL_ALTERA_MINOR,
472 .nr = CONFIG_SERIAL_ALTERA_UART_MAXPORTS, 510 .nr = CONFIG_SERIAL_ALTERA_UART_MAXPORTS,
473 .cons = ALTERA_UART_CONSOLE, 511 .cons = ALTERA_UART_CONSOLE,
474}; 512};
@@ -477,38 +515,55 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
477{ 515{
478 struct altera_uart_platform_uart *platp = pdev->dev.platform_data; 516 struct altera_uart_platform_uart *platp = pdev->dev.platform_data;
479 struct uart_port *port; 517 struct uart_port *port;
480 int i; 518 struct resource *res_mem;
519 struct resource *res_irq;
520 int i = pdev->id;
481 521
482 for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS && platp[i].mapbase; i++) { 522 /* -1 emphasizes that the platform must have one port, no .N suffix */
483 port = &altera_uart_ports[i].port; 523 if (i == -1)
524 i = 0;
484 525
485 port->line = i; 526 if (i >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
486 port->type = PORT_ALTERA_UART; 527 return -EINVAL;
487 port->mapbase = platp[i].mapbase;
488 port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE);
489 port->iotype = SERIAL_IO_MEM;
490 port->irq = platp[i].irq;
491 port->uartclk = platp[i].uartclk;
492 port->ops = &altera_uart_ops;
493 port->flags = ASYNC_BOOT_AUTOCONF;
494 528
495 uart_add_one_port(&altera_uart_driver, port); 529 port = &altera_uart_ports[i].port;
496 } 530
531 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
532 if (res_mem)
533 port->mapbase = res_mem->start;
534 else if (platp->mapbase)
535 port->mapbase = platp->mapbase;
536 else
537 return -EINVAL;
538
539 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
540 if (res_irq)
541 port->irq = res_irq->start;
542 else if (platp->irq)
543 port->irq = platp->irq;
544
545 port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE);
546 if (!port->membase)
547 return -ENOMEM;
548
549 port->line = i;
550 port->type = PORT_ALTERA_UART;
551 port->iotype = SERIAL_IO_MEM;
552 port->uartclk = platp->uartclk;
553 port->ops = &altera_uart_ops;
554 port->flags = UPF_BOOT_AUTOCONF;
555 port->private_data = platp;
556
557 uart_add_one_port(&altera_uart_driver, port);
497 558
498 return 0; 559 return 0;
499} 560}
500 561
501static int __devexit altera_uart_remove(struct platform_device *pdev) 562static int __devexit altera_uart_remove(struct platform_device *pdev)
502{ 563{
503 struct uart_port *port; 564 struct uart_port *port = &altera_uart_ports[pdev->id].port;
504 int i;
505
506 for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS; i++) {
507 port = &altera_uart_ports[i].port;
508 if (port)
509 uart_remove_one_port(&altera_uart_driver, port);
510 }
511 565
566 uart_remove_one_port(&altera_uart_driver, port);
512 return 0; 567 return 0;
513} 568}
514 569
@@ -550,3 +605,4 @@ MODULE_DESCRIPTION("Altera UART driver");
550MODULE_AUTHOR("Thomas Chou <thomas@wytron.com.tw>"); 605MODULE_AUTHOR("Thomas Chou <thomas@wytron.com.tw>");
551MODULE_LICENSE("GPL"); 606MODULE_LICENSE("GPL");
552MODULE_ALIAS("platform:" DRV_NAME); 607MODULE_ALIAS("platform:" DRV_NAME);
608MODULE_ALIAS_CHARDEV_MAJOR(SERIAL_ALTERA_MAJOR);
diff --git a/drivers/serial/bfin_sport_uart.c b/drivers/serial/bfin_sport_uart.c
index 5318dd3774ae..6f1b51e231e4 100644
--- a/drivers/serial/bfin_sport_uart.c
+++ b/drivers/serial/bfin_sport_uart.c
@@ -131,7 +131,12 @@ static int sport_uart_setup(struct sport_uart_port *up, int size, int baud_rate)
131 pr_debug("%s RCR1:%x, RCR2:%x\n", __func__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up)); 131 pr_debug("%s RCR1:%x, RCR2:%x\n", __func__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up));
132 132
133 tclkdiv = sclk / (2 * baud_rate) - 1; 133 tclkdiv = sclk / (2 * baud_rate) - 1;
134 rclkdiv = sclk / (2 * baud_rate * 2) - 1; 134 /* The actual uart baud rate of devices vary between +/-2%. The sport
135 * RX sample rate should be faster than the double of the worst case,
136 * otherwise, wrong data are received. So, set sport RX clock to be
137 * 3% faster.
138 */
139 rclkdiv = sclk / (2 * baud_rate * 2 * 97 / 100) - 1;
135 SPORT_PUT_TCLKDIV(up, tclkdiv); 140 SPORT_PUT_TCLKDIV(up, tclkdiv);
136 SPORT_PUT_RCLKDIV(up, rclkdiv); 141 SPORT_PUT_RCLKDIV(up, rclkdiv);
137 SSYNC(); 142 SSYNC();
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index 66ecc7ab6dab..dfcf4b1878aa 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -327,14 +327,13 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
327{ 327{
328 struct circ_buf *xmit = &sport->port.state->xmit; 328 struct circ_buf *xmit = &sport->port.state->xmit;
329 329
330 while (!(readl(sport->port.membase + UTS) & UTS_TXFULL)) { 330 while (!uart_circ_empty(xmit) &&
331 !(readl(sport->port.membase + UTS) & UTS_TXFULL)) {
331 /* send xmit->buf[xmit->tail] 332 /* send xmit->buf[xmit->tail]
332 * out the port here */ 333 * out the port here */
333 writel(xmit->buf[xmit->tail], sport->port.membase + URTX0); 334 writel(xmit->buf[xmit->tail], sport->port.membase + URTX0);
334 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 335 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
335 sport->port.icount.tx++; 336 sport->port.icount.tx++;
336 if (uart_circ_empty(xmit))
337 break;
338 } 337 }
339 338
340 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 339 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
diff --git a/drivers/serial/jsm/jsm_driver.c b/drivers/serial/jsm/jsm_driver.c
index eaf545014119..18f548449c63 100644
--- a/drivers/serial/jsm/jsm_driver.c
+++ b/drivers/serial/jsm/jsm_driver.c
@@ -172,13 +172,15 @@ static int __devinit jsm_probe_one(struct pci_dev *pdev, const struct pci_device
172 jsm_uart_port_init here! */ 172 jsm_uart_port_init here! */
173 dev_err(&pdev->dev, "memory allocation for flipbuf failed\n"); 173 dev_err(&pdev->dev, "memory allocation for flipbuf failed\n");
174 rc = -ENOMEM; 174 rc = -ENOMEM;
175 goto out_free_irq; 175 goto out_free_uart;
176 } 176 }
177 177
178 pci_set_drvdata(pdev, brd); 178 pci_set_drvdata(pdev, brd);
179 pci_save_state(pdev); 179 pci_save_state(pdev);
180 180
181 return 0; 181 return 0;
182 out_free_uart:
183 jsm_remove_uart_port(brd);
182 out_free_irq: 184 out_free_irq:
183 jsm_remove_uart_port(brd); 185 jsm_remove_uart_port(brd);
184 free_irq(brd->irq, brd); 186 free_irq(brd->irq, brd);
diff --git a/drivers/serial/max3107.c b/drivers/serial/max3107.c
index 67283c1a57ff..910870edf708 100644
--- a/drivers/serial/max3107.c
+++ b/drivers/serial/max3107.c
@@ -986,12 +986,14 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
986 s->rxbuf = kzalloc(sizeof(u16) * (MAX3107_RX_FIFO_SIZE+2), GFP_KERNEL); 986 s->rxbuf = kzalloc(sizeof(u16) * (MAX3107_RX_FIFO_SIZE+2), GFP_KERNEL);
987 if (!s->rxbuf) { 987 if (!s->rxbuf) {
988 pr_err("Allocating RX buffer failed\n"); 988 pr_err("Allocating RX buffer failed\n");
989 return -ENOMEM; 989 retval = -ENOMEM;
990 goto err_free4;
990 } 991 }
991 s->rxstr = kzalloc(sizeof(u8) * MAX3107_RX_FIFO_SIZE, GFP_KERNEL); 992 s->rxstr = kzalloc(sizeof(u8) * MAX3107_RX_FIFO_SIZE, GFP_KERNEL);
992 if (!s->rxstr) { 993 if (!s->rxstr) {
993 pr_err("Allocating RX buffer failed\n"); 994 pr_err("Allocating RX buffer failed\n");
994 return -ENOMEM; 995 retval = -ENOMEM;
996 goto err_free3;
995 } 997 }
996 /* SPI Tx buffer 998 /* SPI Tx buffer
997 * SPI transfer buffer 999 * SPI transfer buffer
@@ -1002,7 +1004,8 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
1002 s->txbuf = kzalloc(sizeof(u16) * MAX3107_TX_FIFO_SIZE + 3, GFP_KERNEL); 1004 s->txbuf = kzalloc(sizeof(u16) * MAX3107_TX_FIFO_SIZE + 3, GFP_KERNEL);
1003 if (!s->txbuf) { 1005 if (!s->txbuf) {
1004 pr_err("Allocating TX buffer failed\n"); 1006 pr_err("Allocating TX buffer failed\n");
1005 return -ENOMEM; 1007 retval = -ENOMEM;
1008 goto err_free2;
1006 } 1009 }
1007 /* Initialize shared data lock */ 1010 /* Initialize shared data lock */
1008 spin_lock_init(&s->data_lock); 1011 spin_lock_init(&s->data_lock);
@@ -1021,13 +1024,15 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
1021 buf[0] = MAX3107_REVID_REG; 1024 buf[0] = MAX3107_REVID_REG;
1022 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) { 1025 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) {
1023 dev_err(&s->spi->dev, "SPI transfer for REVID read failed\n"); 1026 dev_err(&s->spi->dev, "SPI transfer for REVID read failed\n");
1024 return -EIO; 1027 retval = -EIO;
1028 goto err_free1;
1025 } 1029 }
1026 if ((buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID1 && 1030 if ((buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID1 &&
1027 (buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID2) { 1031 (buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID2) {
1028 dev_err(&s->spi->dev, "REVID %x does not match\n", 1032 dev_err(&s->spi->dev, "REVID %x does not match\n",
1029 (buf[0] & MAX3107_SPI_RX_DATA_MASK)); 1033 (buf[0] & MAX3107_SPI_RX_DATA_MASK));
1030 return -ENODEV; 1034 retval = -ENODEV;
1035 goto err_free1;
1031 } 1036 }
1032 1037
1033 /* Disable all interrupts */ 1038 /* Disable all interrupts */
@@ -1047,7 +1052,8 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
1047 /* Perform SPI transfer */ 1052 /* Perform SPI transfer */
1048 if (max3107_rw(s, (u8 *)buf, NULL, 4)) { 1053 if (max3107_rw(s, (u8 *)buf, NULL, 4)) {
1049 dev_err(&s->spi->dev, "SPI transfer for init failed\n"); 1054 dev_err(&s->spi->dev, "SPI transfer for init failed\n");
1050 return -EIO; 1055 retval = -EIO;
1056 goto err_free1;
1051 } 1057 }
1052 1058
1053 /* Register UART driver */ 1059 /* Register UART driver */
@@ -1055,7 +1061,7 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
1055 retval = uart_register_driver(&max3107_uart_driver); 1061 retval = uart_register_driver(&max3107_uart_driver);
1056 if (retval) { 1062 if (retval) {
1057 dev_err(&s->spi->dev, "Registering UART driver failed\n"); 1063 dev_err(&s->spi->dev, "Registering UART driver failed\n");
1058 return retval; 1064 goto err_free1;
1059 } 1065 }
1060 driver_registered = 1; 1066 driver_registered = 1;
1061 } 1067 }
@@ -1074,13 +1080,13 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
1074 retval = uart_add_one_port(&max3107_uart_driver, &s->port); 1080 retval = uart_add_one_port(&max3107_uart_driver, &s->port);
1075 if (retval < 0) { 1081 if (retval < 0) {
1076 dev_err(&s->spi->dev, "Adding UART port failed\n"); 1082 dev_err(&s->spi->dev, "Adding UART port failed\n");
1077 return retval; 1083 goto err_free1;
1078 } 1084 }
1079 1085
1080 if (pdata->configure) { 1086 if (pdata->configure) {
1081 retval = pdata->configure(s); 1087 retval = pdata->configure(s);
1082 if (retval < 0) 1088 if (retval < 0)
1083 return retval; 1089 goto err_free1;
1084 } 1090 }
1085 1091
1086 /* Go to suspend mode */ 1092 /* Go to suspend mode */
@@ -1088,6 +1094,16 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
1088 pdata->hw_suspend(s, 1); 1094 pdata->hw_suspend(s, 1);
1089 1095
1090 return 0; 1096 return 0;
1097
1098err_free1:
1099 kfree(s->txbuf);
1100err_free2:
1101 kfree(s->rxstr);
1102err_free3:
1103 kfree(s->rxbuf);
1104err_free4:
1105 kfree(s);
1106 return retval;
1091} 1107}
1092EXPORT_SYMBOL_GPL(max3107_probe); 1108EXPORT_SYMBOL_GPL(max3107_probe);
1093 1109
diff --git a/drivers/serial/mfd.c b/drivers/serial/mfd.c
index dc0967fb9ea6..5fc699e929dc 100644
--- a/drivers/serial/mfd.c
+++ b/drivers/serial/mfd.c
@@ -172,6 +172,9 @@ static ssize_t port_show_regs(struct file *file, char __user *user_buf,
172 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 172 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
173 "DIV: \t\t0x%08x\n", serial_in(up, UART_DIV)); 173 "DIV: \t\t0x%08x\n", serial_in(up, UART_DIV));
174 174
175 if (len > HSU_REGS_BUFSIZE)
176 len = HSU_REGS_BUFSIZE;
177
175 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); 178 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
176 kfree(buf); 179 kfree(buf);
177 return ret; 180 return ret;
@@ -219,6 +222,9 @@ static ssize_t dma_show_regs(struct file *file, char __user *user_buf,
219 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len, 222 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
220 "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR)); 223 "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR));
221 224
225 if (len > HSU_REGS_BUFSIZE)
226 len = HSU_REGS_BUFSIZE;
227
222 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); 228 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
223 kfree(buf); 229 kfree(buf);
224 return ret; 230 return ret;
@@ -925,39 +931,52 @@ serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,
925 cval |= UART_LCR_EPAR; 931 cval |= UART_LCR_EPAR;
926 932
927 /* 933 /*
934 * The base clk is 50Mhz, and the baud rate come from:
935 * baud = 50M * MUL / (DIV * PS * DLAB)
936 *
928 * For those basic low baud rate we can get the direct 937 * For those basic low baud rate we can get the direct
929 * scalar from 2746800, like 115200 = 2746800/24, for those 938 * scalar from 2746800, like 115200 = 2746800/24. For those
930 * higher baud rate, we have to handle them case by case, 939 * higher baud rate, we handle them case by case, mainly by
931 * but DIV reg is never touched as its default value 0x3d09 940 * adjusting the MUL/PS registers, and DIV register is kept
941 * as default value 0x3d09 to make things simple
932 */ 942 */
933 baud = uart_get_baud_rate(port, termios, old, 0, 4000000); 943 baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
934 quot = uart_get_divisor(port, baud);
935 944
945 quot = 1;
936 switch (baud) { 946 switch (baud) {
937 case 3500000: 947 case 3500000:
938 mul = 0x3345; 948 mul = 0x3345;
939 ps = 0xC; 949 ps = 0xC;
940 quot = 1; 950 break;
951 case 3000000:
952 mul = 0x2EE0;
941 break; 953 break;
942 case 2500000: 954 case 2500000:
943 mul = 0x2710; 955 mul = 0x2710;
944 ps = 0x10;
945 quot = 1;
946 break; 956 break;
947 case 18432000: 957 case 2000000:
958 mul = 0x1F40;
959 break;
960 case 1843200:
948 mul = 0x2400; 961 mul = 0x2400;
949 ps = 0x10;
950 quot = 1;
951 break; 962 break;
952 case 1500000: 963 case 1500000:
953 mul = 0x1D4C; 964 mul = 0x1770;
954 ps = 0xc; 965 break;
955 quot = 1; 966 case 1000000:
967 mul = 0xFA0;
968 break;
969 case 500000:
970 mul = 0x7D0;
956 break; 971 break;
957 default: 972 default:
958 ; 973 /* Use uart_get_divisor to get quot for other baud rates */
974 quot = 0;
959 } 975 }
960 976
977 if (!quot)
978 quot = uart_get_divisor(port, baud);
979
961 if ((up->port.uartclk / quot) < (2400 * 16)) 980 if ((up->port.uartclk / quot) < (2400 * 16))
962 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_1B; 981 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_1B;
963 else if ((up->port.uartclk / quot) < (230400 * 16)) 982 else if ((up->port.uartclk / quot) < (230400 * 16))
diff --git a/drivers/serial/mrst_max3110.c b/drivers/serial/mrst_max3110.c
index 51c15f58e01e..b62857bf2fdb 100644
--- a/drivers/serial/mrst_max3110.c
+++ b/drivers/serial/mrst_max3110.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * max3110.c - spi uart protocol driver for Maxim 3110 on Moorestown 2 * mrst_max3110.c - spi uart protocol driver for Maxim 3110
3 * 3 *
4 * Copyright (C) Intel 2008 Feng Tang <feng.tang@intel.com> 4 * Copyright (c) 2008-2010, Intel Corporation.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License, 7 * under the terms and conditions of the GNU General Public License,
@@ -32,18 +32,13 @@
32#include <linux/irq.h> 32#include <linux/irq.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/console.h> 34#include <linux/console.h>
35#include <linux/sysrq.h>
36#include <linux/platform_device.h>
37#include <linux/tty.h> 35#include <linux/tty.h>
38#include <linux/tty_flip.h> 36#include <linux/tty_flip.h>
39#include <linux/serial_core.h> 37#include <linux/serial_core.h>
40#include <linux/serial_reg.h> 38#include <linux/serial_reg.h>
41 39
42#include <linux/kthread.h> 40#include <linux/kthread.h>
43#include <linux/delay.h>
44#include <asm/atomic.h>
45#include <linux/spi/spi.h> 41#include <linux/spi/spi.h>
46#include <linux/spi/dw_spi.h>
47 42
48#include "mrst_max3110.h" 43#include "mrst_max3110.h"
49 44
@@ -56,7 +51,7 @@
56struct uart_max3110 { 51struct uart_max3110 {
57 struct uart_port port; 52 struct uart_port port;
58 struct spi_device *spi; 53 struct spi_device *spi;
59 char *name; 54 char name[24];
60 55
61 wait_queue_head_t wq; 56 wait_queue_head_t wq;
62 struct task_struct *main_thread; 57 struct task_struct *main_thread;
@@ -67,35 +62,30 @@ struct uart_max3110 {
67 u16 cur_conf; 62 u16 cur_conf;
68 u8 clock; 63 u8 clock;
69 u8 parity, word_7bits; 64 u8 parity, word_7bits;
65 u16 irq;
70 66
71 unsigned long uart_flags; 67 unsigned long uart_flags;
72 68
73 /* console related */ 69 /* console related */
74 struct circ_buf con_xmit; 70 struct circ_buf con_xmit;
75
76 /* irq related */
77 u16 irq;
78}; 71};
79 72
80/* global data structure, may need be removed */ 73/* global data structure, may need be removed */
81struct uart_max3110 *pmax; 74static struct uart_max3110 *pmax;
82static inline void receive_char(struct uart_max3110 *max, u8 ch); 75
83static void receive_chars(struct uart_max3110 *max, 76static void receive_chars(struct uart_max3110 *max,
84 unsigned char *str, int len); 77 unsigned char *str, int len);
85static int max3110_read_multi(struct uart_max3110 *max, int len, u8 *buf); 78static int max3110_read_multi(struct uart_max3110 *max, u8 *buf);
86static void max3110_console_receive(struct uart_max3110 *max); 79static void max3110_con_receive(struct uart_max3110 *max);
87 80
88int max3110_write_then_read(struct uart_max3110 *max, 81static int max3110_write_then_read(struct uart_max3110 *max,
89 const u8 *txbuf, u8 *rxbuf, unsigned len, int always_fast) 82 const void *txbuf, void *rxbuf, unsigned len, int always_fast)
90{ 83{
91 struct spi_device *spi = max->spi; 84 struct spi_device *spi = max->spi;
92 struct spi_message message; 85 struct spi_message message;
93 struct spi_transfer x; 86 struct spi_transfer x;
94 int ret; 87 int ret;
95 88
96 if (!txbuf || !rxbuf)
97 return -EINVAL;
98
99 spi_message_init(&message); 89 spi_message_init(&message);
100 memset(&x, 0, sizeof x); 90 memset(&x, 0, sizeof x);
101 x.len = len; 91 x.len = len;
@@ -104,7 +94,7 @@ int max3110_write_then_read(struct uart_max3110 *max,
104 spi_message_add_tail(&x, &message); 94 spi_message_add_tail(&x, &message);
105 95
106 if (always_fast) 96 if (always_fast)
107 x.speed_hz = 3125000; 97 x.speed_hz = spi->max_speed_hz;
108 else if (max->baud) 98 else if (max->baud)
109 x.speed_hz = max->baud; 99 x.speed_hz = max->baud;
110 100
@@ -113,58 +103,80 @@ int max3110_write_then_read(struct uart_max3110 *max,
113 return ret; 103 return ret;
114} 104}
115 105
116/* Write a u16 to the device, and return one u16 read back */ 106/* Write a 16b word to the device */
117int max3110_out(struct uart_max3110 *max, const u16 out) 107static int max3110_out(struct uart_max3110 *max, const u16 out)
118{ 108{
119 u16 tmp; 109 void *buf;
110 u16 *obuf, *ibuf;
111 u8 ch;
120 int ret; 112 int ret;
121 113
122 ret = max3110_write_then_read(max, (u8 *)&out, (u8 *)&tmp, 2, 1); 114 buf = kzalloc(8, GFP_KERNEL | GFP_DMA);
123 if (ret) 115 if (!buf)
124 return ret; 116 return -ENOMEM;
117
118 obuf = buf;
119 ibuf = buf + 4;
120 *obuf = out;
121 ret = max3110_write_then_read(max, obuf, ibuf, 2, 1);
122 if (ret) {
123 pr_warning(PR_FMT "%s(): get err msg %d when sending 0x%x\n",
124 __func__, ret, out);
125 goto exit;
126 }
125 127
126 /* If some valid data is read back */ 128 /* If some valid data is read back */
127 if (tmp & MAX3110_READ_DATA_AVAILABLE) 129 if (*ibuf & MAX3110_READ_DATA_AVAILABLE) {
128 receive_char(max, (tmp & 0xff)); 130 ch = *ibuf & 0xff;
131 receive_chars(max, &ch, 1);
132 }
129 133
134exit:
135 kfree(buf);
130 return ret; 136 return ret;
131} 137}
132 138
133#define MAX_READ_LEN 20
134/* 139/*
135 * This is usually used to read data from SPIC RX FIFO, which doesn't 140 * This is usually used to read data from SPIC RX FIFO, which doesn't
136 * need any delay like flushing character out. It returns how many 141 * need any delay like flushing character out.
137 * valide bytes are read back 142 *
143 * Return how many valide bytes are read back
138 */ 144 */
139static int max3110_read_multi(struct uart_max3110 *max, int len, u8 *buf) 145static int max3110_read_multi(struct uart_max3110 *max, u8 *rxbuf)
140{ 146{
141 u16 out[MAX_READ_LEN], in[MAX_READ_LEN]; 147 void *buf;
142 u8 *pbuf, valid_str[MAX_READ_LEN]; 148 u16 *obuf, *ibuf;
143 int i, j, bytelen; 149 u8 *pbuf, valid_str[M3110_RX_FIFO_DEPTH];
150 int i, j, blen;
144 151
145 if (len > MAX_READ_LEN) { 152 blen = M3110_RX_FIFO_DEPTH * sizeof(u16);
146 pr_err(PR_FMT "read len %d is too large\n", len); 153 buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA);
154 if (!buf) {
155 pr_warning(PR_FMT "%s(): fail to alloc dma buffer\n", __func__);
147 return 0; 156 return 0;
148 } 157 }
149 158
150 bytelen = len * 2; 159 /* tx/rx always have the same length */
151 memset(out, 0, bytelen); 160 obuf = buf;
152 memset(in, 0, bytelen); 161 ibuf = buf + blen;
153 162
154 if (max3110_write_then_read(max, (u8 *)out, (u8 *)in, bytelen, 1)) 163 if (max3110_write_then_read(max, obuf, ibuf, blen, 1)) {
164 kfree(buf);
155 return 0; 165 return 0;
166 }
156 167
157 /* If caller don't provide a buffer, then handle received char */ 168 /* If caller doesn't provide a buffer, then handle received char */
158 pbuf = buf ? buf : valid_str; 169 pbuf = rxbuf ? rxbuf : valid_str;
159 170
160 for (i = 0, j = 0; i < len; i++) { 171 for (i = 0, j = 0; i < M3110_RX_FIFO_DEPTH; i++) {
161 if (in[i] & MAX3110_READ_DATA_AVAILABLE) 172 if (ibuf[i] & MAX3110_READ_DATA_AVAILABLE)
162 pbuf[j++] = (u8)(in[i] & 0xff); 173 pbuf[j++] = ibuf[i] & 0xff;
163 } 174 }
164 175
165 if (j && (pbuf == valid_str)) 176 if (j && (pbuf == valid_str))
166 receive_chars(max, valid_str, j); 177 receive_chars(max, valid_str, j);
167 178
179 kfree(buf);
168 return j; 180 return j;
169} 181}
170 182
@@ -178,10 +190,6 @@ static void serial_m3110_con_putchar(struct uart_port *port, int ch)
178 xmit->buf[xmit->head] = (char)ch; 190 xmit->buf[xmit->head] = (char)ch;
179 xmit->head = (xmit->head + 1) & (PAGE_SIZE - 1); 191 xmit->head = (xmit->head + 1) & (PAGE_SIZE - 1);
180 } 192 }
181
182
183 if (!test_and_set_bit(CON_TX_NEEDED, &max->uart_flags))
184 wake_up_process(max->main_thread);
185} 193}
186 194
187/* 195/*
@@ -197,6 +205,9 @@ static void serial_m3110_con_write(struct console *co,
197 return; 205 return;
198 206
199 uart_console_write(&pmax->port, s, count, serial_m3110_con_putchar); 207 uart_console_write(&pmax->port, s, count, serial_m3110_con_putchar);
208
209 if (!test_and_set_bit(CON_TX_NEEDED, &pmax->uart_flags))
210 wake_up_process(pmax->main_thread);
200} 211}
201 212
202static int __init 213static int __init
@@ -210,6 +221,9 @@ serial_m3110_con_setup(struct console *co, char *options)
210 221
211 pr_info(PR_FMT "setting up console\n"); 222 pr_info(PR_FMT "setting up console\n");
212 223
224 if (co->index == -1)
225 co->index = 0;
226
213 if (!max) { 227 if (!max) {
214 pr_err(PR_FMT "pmax is NULL, return"); 228 pr_err(PR_FMT "pmax is NULL, return");
215 return -ENODEV; 229 return -ENODEV;
@@ -240,8 +254,6 @@ static struct console serial_m3110_console = {
240 .data = &serial_m3110_reg, 254 .data = &serial_m3110_reg,
241}; 255};
242 256
243#define MRST_CONSOLE (&serial_m3110_console)
244
245static unsigned int serial_m3110_tx_empty(struct uart_port *port) 257static unsigned int serial_m3110_tx_empty(struct uart_port *port)
246{ 258{
247 return 1; 259 return 1;
@@ -259,32 +271,44 @@ static void serial_m3110_stop_rx(struct uart_port *port)
259} 271}
260 272
261#define WORDS_PER_XFER 128 273#define WORDS_PER_XFER 128
262static inline void send_circ_buf(struct uart_max3110 *max, 274static void send_circ_buf(struct uart_max3110 *max,
263 struct circ_buf *xmit) 275 struct circ_buf *xmit)
264{ 276{
265 int len, left = 0; 277 void *buf;
266 u16 obuf[WORDS_PER_XFER], ibuf[WORDS_PER_XFER]; 278 u16 *obuf, *ibuf;
267 u8 valid_str[WORDS_PER_XFER]; 279 u8 valid_str[WORDS_PER_XFER];
268 int i, j; 280 int i, j, len, blen, dma_size, left, ret = 0;
281
282
283 dma_size = WORDS_PER_XFER * sizeof(u16) * 2;
284 buf = kzalloc(dma_size, GFP_KERNEL | GFP_DMA);
285 if (!buf)
286 return;
287 obuf = buf;
288 ibuf = buf + dma_size/2;
269 289
270 while (!uart_circ_empty(xmit)) { 290 while (!uart_circ_empty(xmit)) {
271 left = uart_circ_chars_pending(xmit); 291 left = uart_circ_chars_pending(xmit);
272 while (left) { 292 while (left) {
273 len = (left >= WORDS_PER_XFER) ? WORDS_PER_XFER : left; 293 len = min(left, WORDS_PER_XFER);
294 blen = len * sizeof(u16);
295 memset(ibuf, 0, blen);
274 296
275 memset(obuf, 0, len * 2);
276 memset(ibuf, 0, len * 2);
277 for (i = 0; i < len; i++) { 297 for (i = 0; i < len; i++) {
278 obuf[i] = (u8)xmit->buf[xmit->tail] | WD_TAG; 298 obuf[i] = (u8)xmit->buf[xmit->tail] | WD_TAG;
279 xmit->tail = (xmit->tail + 1) & 299 xmit->tail = (xmit->tail + 1) &
280 (UART_XMIT_SIZE - 1); 300 (UART_XMIT_SIZE - 1);
281 } 301 }
282 max3110_write_then_read(max, (u8 *)obuf, 302
283 (u8 *)ibuf, len * 2, 0); 303 /* Fail to send msg to console is not very critical */
304 ret = max3110_write_then_read(max, obuf, ibuf, blen, 0);
305 if (ret)
306 pr_warning(PR_FMT "%s(): get err msg %d\n",
307 __func__, ret);
284 308
285 for (i = 0, j = 0; i < len; i++) { 309 for (i = 0, j = 0; i < len; i++) {
286 if (ibuf[i] & MAX3110_READ_DATA_AVAILABLE) 310 if (ibuf[i] & MAX3110_READ_DATA_AVAILABLE)
287 valid_str[j++] = (u8)(ibuf[i] & 0xff); 311 valid_str[j++] = ibuf[i] & 0xff;
288 } 312 }
289 313
290 if (j) 314 if (j)
@@ -294,6 +318,8 @@ static inline void send_circ_buf(struct uart_max3110 *max,
294 left -= len; 318 left -= len;
295 } 319 }
296 } 320 }
321
322 kfree(buf);
297} 323}
298 324
299static void transmit_char(struct uart_max3110 *max) 325static void transmit_char(struct uart_max3110 *max)
@@ -313,8 +339,10 @@ static void transmit_char(struct uart_max3110 *max)
313 serial_m3110_stop_tx(port); 339 serial_m3110_stop_tx(port);
314} 340}
315 341
316/* This will be called by uart_write() and tty_write, can't 342/*
317 * go to sleep */ 343 * This will be called by uart_write() and tty_write, can't
344 * go to sleep
345 */
318static void serial_m3110_start_tx(struct uart_port *port) 346static void serial_m3110_start_tx(struct uart_port *port)
319{ 347{
320 struct uart_max3110 *max = 348 struct uart_max3110 *max =
@@ -336,7 +364,7 @@ static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len)
336 364
337 tty = port->state->port.tty; 365 tty = port->state->port.tty;
338 if (!tty) 366 if (!tty)
339 return; /* receive some char before the tty is opened */ 367 return;
340 368
341 while (len) { 369 while (len) {
342 usable = tty_buffer_request_room(tty, len); 370 usable = tty_buffer_request_room(tty, len);
@@ -344,32 +372,37 @@ static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len)
344 tty_insert_flip_string(tty, str, usable); 372 tty_insert_flip_string(tty, str, usable);
345 str += usable; 373 str += usable;
346 port->icount.rx += usable; 374 port->icount.rx += usable;
347 tty_flip_buffer_push(tty);
348 } 375 }
349 len -= usable; 376 len -= usable;
350 } 377 }
378 tty_flip_buffer_push(tty);
351} 379}
352 380
353static inline void receive_char(struct uart_max3110 *max, u8 ch) 381/*
354{ 382 * This routine will be used in read_thread or RX IRQ handling,
355 receive_chars(max, &ch, 1); 383 * it will first do one round buffer read(8 words), if there is some
356} 384 * valid RX data, will try to read 5 more rounds till all data
357 385 * is read out.
358static void max3110_console_receive(struct uart_max3110 *max) 386 *
387 * Use stack space as data buffer to save some system load, and chose
388 * 504 Btyes as a threadhold to do a bulk push to upper tty layer when
389 * receiving bulk data, a much bigger buffer may cause stack overflow
390 */
391static void max3110_con_receive(struct uart_max3110 *max)
359{ 392{
360 int loop = 1, num, total = 0; 393 int loop = 1, num, total = 0;
361 u8 recv_buf[512], *pbuf; 394 u8 recv_buf[512], *pbuf;
362 395
363 pbuf = recv_buf; 396 pbuf = recv_buf;
364 do { 397 do {
365 num = max3110_read_multi(max, 8, pbuf); 398 num = max3110_read_multi(max, pbuf);
366 399
367 if (num) { 400 if (num) {
368 loop = 10; 401 loop = 5;
369 pbuf += num; 402 pbuf += num;
370 total += num; 403 total += num;
371 404
372 if (total >= 500) { 405 if (total >= 504) {
373 receive_chars(max, recv_buf, total); 406 receive_chars(max, recv_buf, total);
374 pbuf = recv_buf; 407 pbuf = recv_buf;
375 total = 0; 408 total = 0;
@@ -397,7 +430,7 @@ static int max3110_main_thread(void *_max)
397 mutex_lock(&max->thread_mutex); 430 mutex_lock(&max->thread_mutex);
398 431
399 if (test_and_clear_bit(BIT_IRQ_PENDING, &max->uart_flags)) 432 if (test_and_clear_bit(BIT_IRQ_PENDING, &max->uart_flags))
400 max3110_console_receive(max); 433 max3110_con_receive(max);
401 434
402 /* first handle console output */ 435 /* first handle console output */
403 if (test_and_clear_bit(CON_TX_NEEDED, &max->uart_flags)) 436 if (test_and_clear_bit(CON_TX_NEEDED, &max->uart_flags))
@@ -414,7 +447,6 @@ static int max3110_main_thread(void *_max)
414 return ret; 447 return ret;
415} 448}
416 449
417#ifdef CONFIG_MRST_MAX3110_IRQ
418static irqreturn_t serial_m3110_irq(int irq, void *dev_id) 450static irqreturn_t serial_m3110_irq(int irq, void *dev_id)
419{ 451{
420 struct uart_max3110 *max = dev_id; 452 struct uart_max3110 *max = dev_id;
@@ -426,7 +458,7 @@ static irqreturn_t serial_m3110_irq(int irq, void *dev_id)
426 458
427 return IRQ_HANDLED; 459 return IRQ_HANDLED;
428} 460}
429#else 461
430/* if don't use RX IRQ, then need a thread to polling read */ 462/* if don't use RX IRQ, then need a thread to polling read */
431static int max3110_read_thread(void *_max) 463static int max3110_read_thread(void *_max)
432{ 464{
@@ -434,9 +466,14 @@ static int max3110_read_thread(void *_max)
434 466
435 pr_info(PR_FMT "start read thread\n"); 467 pr_info(PR_FMT "start read thread\n");
436 do { 468 do {
437 mutex_lock(&max->thread_mutex); 469 /*
438 max3110_console_receive(max); 470 * If can't acquire the mutex, it means the main thread
439 mutex_unlock(&max->thread_mutex); 471 * is running which will also perform the rx job
472 */
473 if (mutex_trylock(&max->thread_mutex)) {
474 max3110_con_receive(max);
475 mutex_unlock(&max->thread_mutex);
476 }
440 477
441 set_current_state(TASK_INTERRUPTIBLE); 478 set_current_state(TASK_INTERRUPTIBLE);
442 schedule_timeout(HZ / 20); 479 schedule_timeout(HZ / 20);
@@ -444,7 +481,6 @@ static int max3110_read_thread(void *_max)
444 481
445 return 0; 482 return 0;
446} 483}
447#endif
448 484
449static int serial_m3110_startup(struct uart_port *port) 485static int serial_m3110_startup(struct uart_port *port)
450{ 486{
@@ -453,33 +489,54 @@ static int serial_m3110_startup(struct uart_port *port)
453 u16 config = 0; 489 u16 config = 0;
454 int ret = 0; 490 int ret = 0;
455 491
456 if (port->line != 0) 492 if (port->line != 0) {
457 pr_err(PR_FMT "uart port startup failed\n"); 493 pr_err(PR_FMT "uart port startup failed\n");
494 return -1;
495 }
458 496
459 /* firstly disable all IRQ and config it to 115200, 8n1 */ 497 /* Disable all IRQ and config it to 115200, 8n1 */
460 config = WC_TAG | WC_FIFO_ENABLE 498 config = WC_TAG | WC_FIFO_ENABLE
461 | WC_1_STOPBITS 499 | WC_1_STOPBITS
462 | WC_8BIT_WORD 500 | WC_8BIT_WORD
463 | WC_BAUD_DR2; 501 | WC_BAUD_DR2;
464 ret = max3110_out(max, config);
465 502
466 /* as we use thread to handle tx/rx, need set low latency */ 503 /* as we use thread to handle tx/rx, need set low latency */
467 port->state->port.tty->low_latency = 1; 504 port->state->port.tty->low_latency = 1;
468 505
469#ifdef CONFIG_MRST_MAX3110_IRQ 506 if (max->irq) {
470 ret = request_irq(max->irq, serial_m3110_irq, 507 max->read_thread = NULL;
508 ret = request_irq(max->irq, serial_m3110_irq,
471 IRQ_TYPE_EDGE_FALLING, "max3110", max); 509 IRQ_TYPE_EDGE_FALLING, "max3110", max);
472 if (ret) 510 if (ret) {
473 return ret; 511 max->irq = 0;
512 pr_err(PR_FMT "unable to allocate IRQ, polling\n");
513 } else {
514 /* Enable RX IRQ only */
515 config |= WC_RXA_IRQ_ENABLE;
516 }
517 }
474 518
475 /* enable RX IRQ only */ 519 if (max->irq == 0) {
476 config |= WC_RXA_IRQ_ENABLE; 520 /* If IRQ is disabled, start a read thread for input data */
477 max3110_out(max, config); 521 max->read_thread =
478#else 522 kthread_run(max3110_read_thread, max, "max3110_read");
479 /* if IRQ is disabled, start a read thread for input data */ 523 if (IS_ERR(max->read_thread)) {
480 max->read_thread = 524 ret = PTR_ERR(max->read_thread);
481 kthread_run(max3110_read_thread, max, "max3110_read"); 525 max->read_thread = NULL;
482#endif 526 pr_err(PR_FMT "Can't create read thread!\n");
527 return ret;
528 }
529 }
530
531 ret = max3110_out(max, config);
532 if (ret) {
533 if (max->irq)
534 free_irq(max->irq, max);
535 if (max->read_thread)
536 kthread_stop(max->read_thread);
537 max->read_thread = NULL;
538 return ret;
539 }
483 540
484 max->cur_conf = config; 541 max->cur_conf = config;
485 return 0; 542 return 0;
@@ -496,9 +553,8 @@ static void serial_m3110_shutdown(struct uart_port *port)
496 max->read_thread = NULL; 553 max->read_thread = NULL;
497 } 554 }
498 555
499#ifdef CONFIG_MRST_MAX3110_IRQ 556 if (max->irq)
500 free_irq(max->irq, max); 557 free_irq(max->irq, max);
501#endif
502 558
503 /* Disable interrupts from this port */ 559 /* Disable interrupts from this port */
504 config = WC_TAG | WC_SW_SHDI; 560 config = WC_TAG | WC_SW_SHDI;
@@ -516,8 +572,7 @@ static int serial_m3110_request_port(struct uart_port *port)
516 572
517static void serial_m3110_config_port(struct uart_port *port, int flags) 573static void serial_m3110_config_port(struct uart_port *port, int flags)
518{ 574{
519 /* give it fake type */ 575 port->type = PORT_MAX3100;
520 port->type = PORT_PXA;
521} 576}
522 577
523static int 578static int
@@ -552,6 +607,9 @@ serial_m3110_set_termios(struct uart_port *port, struct ktermios *termios,
552 new_conf |= WC_7BIT_WORD; 607 new_conf |= WC_7BIT_WORD;
553 break; 608 break;
554 default: 609 default:
610 /* We only support CS7 & CS8 */
611 termios->c_cflag &= ~CSIZE;
612 termios->c_cflag |= CS8;
555 case CS8: 613 case CS8:
556 cval = UART_LCR_WLEN8; 614 cval = UART_LCR_WLEN8;
557 new_conf |= WC_8BIT_WORD; 615 new_conf |= WC_8BIT_WORD;
@@ -560,7 +618,7 @@ serial_m3110_set_termios(struct uart_port *port, struct ktermios *termios,
560 618
561 baud = uart_get_baud_rate(port, termios, old, 0, 230400); 619 baud = uart_get_baud_rate(port, termios, old, 0, 230400);
562 620
563 /* first calc the div for 1.8MHZ clock case */ 621 /* First calc the div for 1.8MHZ clock case */
564 switch (baud) { 622 switch (baud) {
565 case 300: 623 case 300:
566 clk_div = WC_BAUD_DR384; 624 clk_div = WC_BAUD_DR384;
@@ -596,7 +654,7 @@ serial_m3110_set_termios(struct uart_port *port, struct ktermios *termios,
596 if (max->clock & MAX3110_HIGH_CLK) 654 if (max->clock & MAX3110_HIGH_CLK)
597 break; 655 break;
598 default: 656 default:
599 /* pick the previous baud rate */ 657 /* Pick the previous baud rate */
600 baud = max->baud; 658 baud = max->baud;
601 clk_div = max->cur_conf & WC_BAUD_DIV_MASK; 659 clk_div = max->cur_conf & WC_BAUD_DIV_MASK;
602 tty_termios_encode_baud_rate(termios, baud, baud); 660 tty_termios_encode_baud_rate(termios, baud, baud);
@@ -604,15 +662,21 @@ serial_m3110_set_termios(struct uart_port *port, struct ktermios *termios,
604 662
605 if (max->clock & MAX3110_HIGH_CLK) { 663 if (max->clock & MAX3110_HIGH_CLK) {
606 clk_div += 1; 664 clk_div += 1;
607 /* high clk version max3110 doesn't support B300 */ 665 /* High clk version max3110 doesn't support B300 */
608 if (baud == 300) 666 if (baud == 300) {
609 baud = 600; 667 baud = 600;
668 clk_div = WC_BAUD_DR384;
669 }
610 if (baud == 230400) 670 if (baud == 230400)
611 clk_div = WC_BAUD_DR1; 671 clk_div = WC_BAUD_DR1;
612 tty_termios_encode_baud_rate(termios, baud, baud); 672 tty_termios_encode_baud_rate(termios, baud, baud);
613 } 673 }
614 674
615 new_conf = (new_conf & ~WC_BAUD_DIV_MASK) | clk_div; 675 new_conf = (new_conf & ~WC_BAUD_DIV_MASK) | clk_div;
676
677 if (unlikely(termios->c_cflag & CMSPAR))
678 termios->c_cflag &= ~CMSPAR;
679
616 if (termios->c_cflag & CSTOPB) 680 if (termios->c_cflag & CSTOPB)
617 new_conf |= WC_2_STOPBITS; 681 new_conf |= WC_2_STOPBITS;
618 else 682 else
@@ -632,13 +696,14 @@ serial_m3110_set_termios(struct uart_port *port, struct ktermios *termios,
632 696
633 new_conf |= WC_TAG; 697 new_conf |= WC_TAG;
634 if (new_conf != max->cur_conf) { 698 if (new_conf != max->cur_conf) {
635 max3110_out(max, new_conf); 699 if (!max3110_out(max, new_conf)) {
636 max->cur_conf = new_conf; 700 max->cur_conf = new_conf;
637 max->baud = baud; 701 max->baud = baud;
702 }
638 } 703 }
639} 704}
640 705
641/* don't handle hw handshaking */ 706/* Don't handle hw handshaking */
642static unsigned int serial_m3110_get_mctrl(struct uart_port *port) 707static unsigned int serial_m3110_get_mctrl(struct uart_port *port)
643{ 708{
644 return TIOCM_DSR | TIOCM_CAR | TIOCM_DSR; 709 return TIOCM_DSR | TIOCM_CAR | TIOCM_DSR;
@@ -672,7 +737,7 @@ struct uart_ops serial_m3110_ops = {
672 .break_ctl = serial_m3110_break_ctl, 737 .break_ctl = serial_m3110_break_ctl,
673 .startup = serial_m3110_startup, 738 .startup = serial_m3110_startup,
674 .shutdown = serial_m3110_shutdown, 739 .shutdown = serial_m3110_shutdown,
675 .set_termios = serial_m3110_set_termios, /* must have */ 740 .set_termios = serial_m3110_set_termios,
676 .pm = serial_m3110_pm, 741 .pm = serial_m3110_pm,
677 .type = serial_m3110_type, 742 .type = serial_m3110_type,
678 .release_port = serial_m3110_release_port, 743 .release_port = serial_m3110_release_port,
@@ -688,52 +753,60 @@ static struct uart_driver serial_m3110_reg = {
688 .major = TTY_MAJOR, 753 .major = TTY_MAJOR,
689 .minor = 64, 754 .minor = 64,
690 .nr = 1, 755 .nr = 1,
691 .cons = MRST_CONSOLE, 756 .cons = &serial_m3110_console,
692}; 757};
693 758
759#ifdef CONFIG_PM
694static int serial_m3110_suspend(struct spi_device *spi, pm_message_t state) 760static int serial_m3110_suspend(struct spi_device *spi, pm_message_t state)
695{ 761{
762 struct uart_max3110 *max = spi_get_drvdata(spi);
763
764 disable_irq(max->irq);
765 uart_suspend_port(&serial_m3110_reg, &max->port);
766 max3110_out(max, max->cur_conf | WC_SW_SHDI);
696 return 0; 767 return 0;
697} 768}
698 769
699static int serial_m3110_resume(struct spi_device *spi) 770static int serial_m3110_resume(struct spi_device *spi)
700{ 771{
772 struct uart_max3110 *max = spi_get_drvdata(spi);
773
774 max3110_out(max, max->cur_conf);
775 uart_resume_port(&serial_m3110_reg, &max->port);
776 enable_irq(max->irq);
701 return 0; 777 return 0;
702} 778}
779#else
780#define serial_m3110_suspend NULL
781#define serial_m3110_resume NULL
782#endif
703 783
704static struct dw_spi_chip spi0_uart = { 784static int __devinit serial_m3110_probe(struct spi_device *spi)
705 .poll_mode = 1,
706 .enable_dma = 0,
707 .type = SPI_FRF_SPI,
708};
709
710static int serial_m3110_probe(struct spi_device *spi)
711{ 785{
712 struct uart_max3110 *max; 786 struct uart_max3110 *max;
713 int ret; 787 void *buffer;
714 unsigned char *buffer;
715 u16 res; 788 u16 res;
789 int ret = 0;
790
716 max = kzalloc(sizeof(*max), GFP_KERNEL); 791 max = kzalloc(sizeof(*max), GFP_KERNEL);
717 if (!max) 792 if (!max)
718 return -ENOMEM; 793 return -ENOMEM;
719 794
720 /* set spi info */ 795 /* Set spi info */
721 spi->mode = SPI_MODE_0;
722 spi->bits_per_word = 16; 796 spi->bits_per_word = 16;
723 max->clock = MAX3110_HIGH_CLK; 797 max->clock = MAX3110_HIGH_CLK;
724 spi->controller_data = &spi0_uart;
725 798
726 spi_setup(spi); 799 spi_setup(spi);
727 800
728 max->port.type = PORT_PXA; /* need apply for a max3110 type */ 801 max->port.type = PORT_MAX3100;
729 max->port.fifosize = 2; /* only have 16b buffer */ 802 max->port.fifosize = 2; /* Only have 16b buffer */
730 max->port.ops = &serial_m3110_ops; 803 max->port.ops = &serial_m3110_ops;
731 max->port.line = 0; 804 max->port.line = 0;
732 max->port.dev = &spi->dev; 805 max->port.dev = &spi->dev;
733 max->port.uartclk = 115200; 806 max->port.uartclk = 115200;
734 807
735 max->spi = spi; 808 max->spi = spi;
736 max->name = spi->modalias; /* use spi name as the name */ 809 strcpy(max->name, spi->modalias);
737 max->irq = (u16)spi->irq; 810 max->irq = (u16)spi->irq;
738 811
739 mutex_init(&max->thread_mutex); 812 mutex_init(&max->thread_mutex);
@@ -755,13 +828,15 @@ static int serial_m3110_probe(struct spi_device *spi)
755 ret = -ENODEV; 828 ret = -ENODEV;
756 goto err_get_page; 829 goto err_get_page;
757 } 830 }
758 buffer = (unsigned char *)__get_free_page(GFP_KERNEL); 831
832 buffer = (void *)__get_free_page(GFP_KERNEL);
759 if (!buffer) { 833 if (!buffer) {
760 ret = -ENOMEM; 834 ret = -ENOMEM;
761 goto err_get_page; 835 goto err_get_page;
762 } 836 }
763 max->con_xmit.buf = (unsigned char *)buffer; 837 max->con_xmit.buf = buffer;
764 max->con_xmit.head = max->con_xmit.tail = 0; 838 max->con_xmit.head = 0;
839 max->con_xmit.tail = 0;
765 840
766 max->main_thread = kthread_run(max3110_main_thread, 841 max->main_thread = kthread_run(max3110_main_thread,
767 max, "max3110_main"); 842 max, "max3110_main");
@@ -770,8 +845,10 @@ static int serial_m3110_probe(struct spi_device *spi)
770 goto err_kthread; 845 goto err_kthread;
771 } 846 }
772 847
848 spi_set_drvdata(spi, max);
773 pmax = max; 849 pmax = max;
774 /* give membase a psudo value to pass serial_core's check */ 850
851 /* Give membase a psudo value to pass serial_core's check */
775 max->port.membase = (void *)0xff110000; 852 max->port.membase = (void *)0xff110000;
776 uart_add_one_port(&serial_m3110_reg, &max->port); 853 uart_add_one_port(&serial_m3110_reg, &max->port);
777 854
@@ -780,19 +857,17 @@ static int serial_m3110_probe(struct spi_device *spi)
780err_kthread: 857err_kthread:
781 free_page((unsigned long)buffer); 858 free_page((unsigned long)buffer);
782err_get_page: 859err_get_page:
783 pmax = NULL;
784 kfree(max); 860 kfree(max);
785 return ret; 861 return ret;
786} 862}
787 863
788static int max3110_remove(struct spi_device *dev) 864static int __devexit serial_m3110_remove(struct spi_device *dev)
789{ 865{
790 struct uart_max3110 *max = pmax; 866 struct uart_max3110 *max = spi_get_drvdata(dev);
791 867
792 if (!pmax) 868 if (!max)
793 return 0; 869 return 0;
794 870
795 pmax = NULL;
796 uart_remove_one_port(&serial_m3110_reg, &max->port); 871 uart_remove_one_port(&serial_m3110_reg, &max->port);
797 872
798 free_page((unsigned long)max->con_xmit.buf); 873 free_page((unsigned long)max->con_xmit.buf);
@@ -811,13 +886,12 @@ static struct spi_driver uart_max3110_driver = {
811 .owner = THIS_MODULE, 886 .owner = THIS_MODULE,
812 }, 887 },
813 .probe = serial_m3110_probe, 888 .probe = serial_m3110_probe,
814 .remove = __devexit_p(max3110_remove), 889 .remove = __devexit_p(serial_m3110_remove),
815 .suspend = serial_m3110_suspend, 890 .suspend = serial_m3110_suspend,
816 .resume = serial_m3110_resume, 891 .resume = serial_m3110_resume,
817}; 892};
818 893
819 894static int __init serial_m3110_init(void)
820int __init serial_m3110_init(void)
821{ 895{
822 int ret = 0; 896 int ret = 0;
823 897
@@ -832,7 +906,7 @@ int __init serial_m3110_init(void)
832 return ret; 906 return ret;
833} 907}
834 908
835void __exit serial_m3110_exit(void) 909static void __exit serial_m3110_exit(void)
836{ 910{
837 spi_unregister_driver(&uart_max3110_driver); 911 spi_unregister_driver(&uart_max3110_driver);
838 uart_unregister_driver(&serial_m3110_reg); 912 uart_unregister_driver(&serial_m3110_reg);
@@ -841,5 +915,5 @@ void __exit serial_m3110_exit(void)
841module_init(serial_m3110_init); 915module_init(serial_m3110_init);
842module_exit(serial_m3110_exit); 916module_exit(serial_m3110_exit);
843 917
844MODULE_LICENSE("GPL"); 918MODULE_LICENSE("GPL v2");
845MODULE_ALIAS("max3110-uart"); 919MODULE_ALIAS("max3110-uart");
diff --git a/drivers/serial/mrst_max3110.h b/drivers/serial/mrst_max3110.h
index 363478acb2c3..d1ef43af397c 100644
--- a/drivers/serial/mrst_max3110.h
+++ b/drivers/serial/mrst_max3110.h
@@ -56,4 +56,5 @@
56#define WC_BAUD_DR192 (0xE) 56#define WC_BAUD_DR192 (0xE)
57#define WC_BAUD_DR384 (0xF) 57#define WC_BAUD_DR384 (0xF)
58 58
59#define M3110_RX_FIFO_DEPTH 8
59#endif 60#endif
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index cd8511298bcb..c4ea14670d44 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1074,10 +1074,10 @@ uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1074 * NB: both 1->0 and 0->1 transitions are counted except for 1074 * NB: both 1->0 and 0->1 transitions are counted except for
1075 * RI where only 0->1 is counted. 1075 * RI where only 0->1 is counted.
1076 */ 1076 */
1077static int uart_get_count(struct uart_state *state, 1077static int uart_get_icount(struct tty_struct *tty,
1078 struct serial_icounter_struct __user *icnt) 1078 struct serial_icounter_struct *icount)
1079{ 1079{
1080 struct serial_icounter_struct icount; 1080 struct uart_state *state = tty->driver_data;
1081 struct uart_icount cnow; 1081 struct uart_icount cnow;
1082 struct uart_port *uport = state->uart_port; 1082 struct uart_port *uport = state->uart_port;
1083 1083
@@ -1085,19 +1085,19 @@ static int uart_get_count(struct uart_state *state,
1085 memcpy(&cnow, &uport->icount, sizeof(struct uart_icount)); 1085 memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
1086 spin_unlock_irq(&uport->lock); 1086 spin_unlock_irq(&uport->lock);
1087 1087
1088 icount.cts = cnow.cts; 1088 icount->cts = cnow.cts;
1089 icount.dsr = cnow.dsr; 1089 icount->dsr = cnow.dsr;
1090 icount.rng = cnow.rng; 1090 icount->rng = cnow.rng;
1091 icount.dcd = cnow.dcd; 1091 icount->dcd = cnow.dcd;
1092 icount.rx = cnow.rx; 1092 icount->rx = cnow.rx;
1093 icount.tx = cnow.tx; 1093 icount->tx = cnow.tx;
1094 icount.frame = cnow.frame; 1094 icount->frame = cnow.frame;
1095 icount.overrun = cnow.overrun; 1095 icount->overrun = cnow.overrun;
1096 icount.parity = cnow.parity; 1096 icount->parity = cnow.parity;
1097 icount.brk = cnow.brk; 1097 icount->brk = cnow.brk;
1098 icount.buf_overrun = cnow.buf_overrun; 1098 icount->buf_overrun = cnow.buf_overrun;
1099 1099
1100 return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0; 1100 return 0;
1101} 1101}
1102 1102
1103/* 1103/*
@@ -1150,10 +1150,6 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
1150 case TIOCMIWAIT: 1150 case TIOCMIWAIT:
1151 ret = uart_wait_modem_status(state, arg); 1151 ret = uart_wait_modem_status(state, arg);
1152 break; 1152 break;
1153
1154 case TIOCGICOUNT:
1155 ret = uart_get_count(state, uarg);
1156 break;
1157 } 1153 }
1158 1154
1159 if (ret != -ENOIOCTLCMD) 1155 if (ret != -ENOIOCTLCMD)
@@ -2065,7 +2061,19 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
2065 /* 2061 /*
2066 * Re-enable the console device after suspending. 2062 * Re-enable the console device after suspending.
2067 */ 2063 */
2068 if (uart_console(uport)) { 2064 if (console_suspend_enabled && uart_console(uport)) {
2065 /*
2066 * First try to use the console cflag setting.
2067 */
2068 memset(&termios, 0, sizeof(struct ktermios));
2069 termios.c_cflag = uport->cons->cflag;
2070
2071 /*
2072 * If that's unset, use the tty termios setting.
2073 */
2074 if (port->tty && port->tty->termios && termios.c_cflag == 0)
2075 termios = *(port->tty->termios);
2076
2069 uart_change_pm(state, 0); 2077 uart_change_pm(state, 0);
2070 uport->ops->set_termios(uport, &termios, NULL); 2078 uport->ops->set_termios(uport, &termios, NULL);
2071 console_start(uport->cons); 2079 console_start(uport->cons);
@@ -2283,6 +2291,7 @@ static const struct tty_operations uart_ops = {
2283#endif 2291#endif
2284 .tiocmget = uart_tiocmget, 2292 .tiocmget = uart_tiocmget,
2285 .tiocmset = uart_tiocmset, 2293 .tiocmset = uart_tiocmset,
2294 .get_icount = uart_get_icount,
2286#ifdef CONFIG_CONSOLE_POLL 2295#ifdef CONFIG_CONSOLE_POLL
2287 .poll_init = uart_poll_init, 2296 .poll_init = uart_poll_init,
2288 .poll_get_char = uart_poll_get_char, 2297 .poll_get_char = uart_poll_get_char,
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index 9b03d7b3e456..c4bf54bb3fc7 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -322,6 +322,26 @@ static int ulite_verify_port(struct uart_port *port, struct serial_struct *ser)
322 return -EINVAL; 322 return -EINVAL;
323} 323}
324 324
325#ifdef CONFIG_CONSOLE_POLL
326static int ulite_get_poll_char(struct uart_port *port)
327{
328 if (!(ioread32be(port->membase + ULITE_STATUS)
329 & ULITE_STATUS_RXVALID))
330 return NO_POLL_CHAR;
331
332 return ioread32be(port->membase + ULITE_RX);
333}
334
335static void ulite_put_poll_char(struct uart_port *port, unsigned char ch)
336{
337 while (ioread32be(port->membase + ULITE_STATUS) & ULITE_STATUS_TXFULL)
338 cpu_relax();
339
340 /* write char to device */
341 iowrite32be(ch, port->membase + ULITE_TX);
342}
343#endif
344
325static struct uart_ops ulite_ops = { 345static struct uart_ops ulite_ops = {
326 .tx_empty = ulite_tx_empty, 346 .tx_empty = ulite_tx_empty,
327 .set_mctrl = ulite_set_mctrl, 347 .set_mctrl = ulite_set_mctrl,
@@ -338,7 +358,11 @@ static struct uart_ops ulite_ops = {
338 .release_port = ulite_release_port, 358 .release_port = ulite_release_port,
339 .request_port = ulite_request_port, 359 .request_port = ulite_request_port,
340 .config_port = ulite_config_port, 360 .config_port = ulite_config_port,
341 .verify_port = ulite_verify_port 361 .verify_port = ulite_verify_port,
362#ifdef CONFIG_CONSOLE_POLL
363 .poll_get_char = ulite_get_poll_char,
364 .poll_put_char = ulite_put_poll_char,
365#endif
342}; 366};
343 367
344/* --------------------------------------------------------------------- 368/* ---------------------------------------------------------------------
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 4e41a2a39422..8f1d4fb19d24 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -411,6 +411,26 @@ err_out:
411 return result; 411 return result;
412} 412}
413 413
414static int ark3116_get_icount(struct tty_struct *tty,
415 struct serial_icounter_struct *icount)
416{
417 struct usb_serial_port *port = tty->driver_data;
418 struct ark3116_private *priv = usb_get_serial_port_data(port);
419 struct async_icount cnow = priv->icount;
420 icount->cts = cnow.cts;
421 icount->dsr = cnow.dsr;
422 icount->rng = cnow.rng;
423 icount->dcd = cnow.dcd;
424 icount->rx = cnow.rx;
425 icount->tx = cnow.tx;
426 icount->frame = cnow.frame;
427 icount->overrun = cnow.overrun;
428 icount->parity = cnow.parity;
429 icount->brk = cnow.brk;
430 icount->buf_overrun = cnow.buf_overrun;
431 return 0;
432}
433
414static int ark3116_ioctl(struct tty_struct *tty, struct file *file, 434static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
415 unsigned int cmd, unsigned long arg) 435 unsigned int cmd, unsigned long arg)
416{ 436{
@@ -460,25 +480,6 @@ static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
460 return 0; 480 return 0;
461 } 481 }
462 break; 482 break;
463 case TIOCGICOUNT: {
464 struct serial_icounter_struct icount;
465 struct async_icount cnow = priv->icount;
466 memset(&icount, 0, sizeof(icount));
467 icount.cts = cnow.cts;
468 icount.dsr = cnow.dsr;
469 icount.rng = cnow.rng;
470 icount.dcd = cnow.dcd;
471 icount.rx = cnow.rx;
472 icount.tx = cnow.tx;
473 icount.frame = cnow.frame;
474 icount.overrun = cnow.overrun;
475 icount.parity = cnow.parity;
476 icount.brk = cnow.brk;
477 icount.buf_overrun = cnow.buf_overrun;
478 if (copy_to_user(user_arg, &icount, sizeof(icount)))
479 return -EFAULT;
480 return 0;
481 }
482 } 483 }
483 484
484 return -ENOIOCTLCMD; 485 return -ENOIOCTLCMD;
@@ -736,6 +737,7 @@ static struct usb_serial_driver ark3116_device = {
736 .ioctl = ark3116_ioctl, 737 .ioctl = ark3116_ioctl,
737 .tiocmget = ark3116_tiocmget, 738 .tiocmget = ark3116_tiocmget,
738 .tiocmset = ark3116_tiocmset, 739 .tiocmset = ark3116_tiocmset,
740 .get_icount = ark3116_get_icount,
739 .open = ark3116_open, 741 .open = ark3116_open,
740 .close = ark3116_close, 742 .close = ark3116_close,
741 .break_ctl = ark3116_break_ctl, 743 .break_ctl = ark3116_break_ctl,
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 97cc87d654ce..891c20e3bb38 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -2168,6 +2168,7 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2168 * - mask passed in arg for lines of interest 2168 * - mask passed in arg for lines of interest
2169 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 2169 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2170 * Caller should use TIOCGICOUNT to see which one it was. 2170 * Caller should use TIOCGICOUNT to see which one it was.
2171 * (except that the driver doesn't support it !)
2171 * 2172 *
2172 * This code is borrowed from linux/drivers/char/serial.c 2173 * This code is borrowed from linux/drivers/char/serial.c
2173 */ 2174 */
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 76e6fb3aab7a..a0ab78ada25e 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -222,6 +222,8 @@ static void edge_break(struct tty_struct *tty, int break_state);
222static int edge_tiocmget(struct tty_struct *tty, struct file *file); 222static int edge_tiocmget(struct tty_struct *tty, struct file *file);
223static int edge_tiocmset(struct tty_struct *tty, struct file *file, 223static int edge_tiocmset(struct tty_struct *tty, struct file *file,
224 unsigned int set, unsigned int clear); 224 unsigned int set, unsigned int clear);
225static int edge_get_icount(struct tty_struct *tty,
226 struct serial_icounter_struct *icount);
225static int edge_startup(struct usb_serial *serial); 227static int edge_startup(struct usb_serial *serial);
226static void edge_disconnect(struct usb_serial *serial); 228static void edge_disconnect(struct usb_serial *serial);
227static void edge_release(struct usb_serial *serial); 229static void edge_release(struct usb_serial *serial);
@@ -1624,6 +1626,31 @@ static int edge_tiocmget(struct tty_struct *tty, struct file *file)
1624 return result; 1626 return result;
1625} 1627}
1626 1628
1629static int edge_get_icount(struct tty_struct *tty,
1630 struct serial_icounter_struct *icount)
1631{
1632 struct usb_serial_port *port = tty->driver_data;
1633 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1634 struct async_icount cnow;
1635 cnow = edge_port->icount;
1636
1637 icount->cts = cnow.cts;
1638 icount->dsr = cnow.dsr;
1639 icount->rng = cnow.rng;
1640 icount->dcd = cnow.dcd;
1641 icount->rx = cnow.rx;
1642 icount->tx = cnow.tx;
1643 icount->frame = cnow.frame;
1644 icount->overrun = cnow.overrun;
1645 icount->parity = cnow.parity;
1646 icount->brk = cnow.brk;
1647 icount->buf_overrun = cnow.buf_overrun;
1648
1649 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
1650 __func__, port->number, icount->rx, icount->tx);
1651 return 0;
1652}
1653
1627static int get_serial_info(struct edgeport_port *edge_port, 1654static int get_serial_info(struct edgeport_port *edge_port,
1628 struct serial_struct __user *retinfo) 1655 struct serial_struct __user *retinfo)
1629{ 1656{
@@ -1650,7 +1677,6 @@ static int get_serial_info(struct edgeport_port *edge_port,
1650} 1677}
1651 1678
1652 1679
1653
1654/***************************************************************************** 1680/*****************************************************************************
1655 * SerialIoctl 1681 * SerialIoctl
1656 * this function handles any ioctl calls to the driver 1682 * this function handles any ioctl calls to the driver
@@ -1663,7 +1689,6 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file,
1663 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1689 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1664 struct async_icount cnow; 1690 struct async_icount cnow;
1665 struct async_icount cprev; 1691 struct async_icount cprev;
1666 struct serial_icounter_struct icount;
1667 1692
1668 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 1693 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1669 1694
@@ -1702,26 +1727,6 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file,
1702 /* NOTREACHED */ 1727 /* NOTREACHED */
1703 break; 1728 break;
1704 1729
1705 case TIOCGICOUNT:
1706 cnow = edge_port->icount;
1707 memset(&icount, 0, sizeof(icount));
1708 icount.cts = cnow.cts;
1709 icount.dsr = cnow.dsr;
1710 icount.rng = cnow.rng;
1711 icount.dcd = cnow.dcd;
1712 icount.rx = cnow.rx;
1713 icount.tx = cnow.tx;
1714 icount.frame = cnow.frame;
1715 icount.overrun = cnow.overrun;
1716 icount.parity = cnow.parity;
1717 icount.brk = cnow.brk;
1718 icount.buf_overrun = cnow.buf_overrun;
1719
1720 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d",
1721 __func__, port->number, icount.rx, icount.tx);
1722 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
1723 return -EFAULT;
1724 return 0;
1725 } 1730 }
1726 return -ENOIOCTLCMD; 1731 return -ENOIOCTLCMD;
1727} 1732}
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index feb56a4ca799..6ab2a3f97fe8 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -123,6 +123,7 @@ static struct usb_serial_driver edgeport_2port_device = {
123 .set_termios = edge_set_termios, 123 .set_termios = edge_set_termios,
124 .tiocmget = edge_tiocmget, 124 .tiocmget = edge_tiocmget,
125 .tiocmset = edge_tiocmset, 125 .tiocmset = edge_tiocmset,
126 .get_icount = edge_get_icount,
126 .write = edge_write, 127 .write = edge_write,
127 .write_room = edge_write_room, 128 .write_room = edge_write_room,
128 .chars_in_buffer = edge_chars_in_buffer, 129 .chars_in_buffer = edge_chars_in_buffer,
@@ -152,6 +153,7 @@ static struct usb_serial_driver edgeport_4port_device = {
152 .set_termios = edge_set_termios, 153 .set_termios = edge_set_termios,
153 .tiocmget = edge_tiocmget, 154 .tiocmget = edge_tiocmget,
154 .tiocmset = edge_tiocmset, 155 .tiocmset = edge_tiocmset,
156 .get_icount = edge_get_icount,
155 .write = edge_write, 157 .write = edge_write,
156 .write_room = edge_write_room, 158 .write_room = edge_write_room,
157 .chars_in_buffer = edge_chars_in_buffer, 159 .chars_in_buffer = edge_chars_in_buffer,
@@ -181,6 +183,7 @@ static struct usb_serial_driver edgeport_8port_device = {
181 .set_termios = edge_set_termios, 183 .set_termios = edge_set_termios,
182 .tiocmget = edge_tiocmget, 184 .tiocmget = edge_tiocmget,
183 .tiocmset = edge_tiocmset, 185 .tiocmset = edge_tiocmset,
186 .get_icount = edge_get_icount,
184 .write = edge_write, 187 .write = edge_write,
185 .write_room = edge_write_room, 188 .write_room = edge_write_room,
186 .chars_in_buffer = edge_chars_in_buffer, 189 .chars_in_buffer = edge_chars_in_buffer,
@@ -209,6 +212,7 @@ static struct usb_serial_driver epic_device = {
209 .set_termios = edge_set_termios, 212 .set_termios = edge_set_termios,
210 .tiocmget = edge_tiocmget, 213 .tiocmget = edge_tiocmget,
211 .tiocmset = edge_tiocmset, 214 .tiocmset = edge_tiocmset,
215 .get_icount = edge_get_icount,
212 .write = edge_write, 216 .write = edge_write,
213 .write_room = edge_write_room, 217 .write_room = edge_write_room,
214 .chars_in_buffer = edge_chars_in_buffer, 218 .chars_in_buffer = edge_chars_in_buffer,
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index a7cfc5952937..4dad27a0f22a 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2510,6 +2510,27 @@ static int edge_tiocmget(struct tty_struct *tty, struct file *file)
2510 return result; 2510 return result;
2511} 2511}
2512 2512
2513static int edge_get_icount(struct tty_struct *tty,
2514 struct serial_icounter_struct *icount)
2515{
2516 struct usb_serial_port *port = tty->driver_data;
2517 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2518 struct async_icount *ic = &edge_port->icount;
2519
2520 icount->cts = ic->cts;
2521 icount->dsr = ic->dsr;
2522 icount->rng = ic->rng;
2523 icount->dcd = ic->dcd;
2524 icount->tx = ic->tx;
2525 icount->rx = ic->rx;
2526 icount->frame = ic->frame;
2527 icount->parity = ic->parity;
2528 icount->overrun = ic->overrun;
2529 icount->brk = ic->brk;
2530 icount->buf_overrun = ic->buf_overrun;
2531 return 0;
2532}
2533
2513static int get_serial_info(struct edgeport_port *edge_port, 2534static int get_serial_info(struct edgeport_port *edge_port,
2514 struct serial_struct __user *retinfo) 2535 struct serial_struct __user *retinfo)
2515{ 2536{
@@ -2572,13 +2593,6 @@ static int edge_ioctl(struct tty_struct *tty, struct file *file,
2572 } 2593 }
2573 /* not reached */ 2594 /* not reached */
2574 break; 2595 break;
2575 case TIOCGICOUNT:
2576 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2577 port->number, edge_port->icount.rx, edge_port->icount.tx);
2578 if (copy_to_user((void __user *)arg, &edge_port->icount,
2579 sizeof(edge_port->icount)))
2580 return -EFAULT;
2581 return 0;
2582 } 2596 }
2583 return -ENOIOCTLCMD; 2597 return -ENOIOCTLCMD;
2584} 2598}
@@ -2758,6 +2772,7 @@ static struct usb_serial_driver edgeport_1port_device = {
2758 .set_termios = edge_set_termios, 2772 .set_termios = edge_set_termios,
2759 .tiocmget = edge_tiocmget, 2773 .tiocmget = edge_tiocmget,
2760 .tiocmset = edge_tiocmset, 2774 .tiocmset = edge_tiocmset,
2775 .get_icount = edge_get_icount,
2761 .write = edge_write, 2776 .write = edge_write,
2762 .write_room = edge_write_room, 2777 .write_room = edge_write_room,
2763 .chars_in_buffer = edge_chars_in_buffer, 2778 .chars_in_buffer = edge_chars_in_buffer,
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index aa665817a272..fd0b6414f459 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -1896,10 +1896,37 @@ static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
1896 return 0; 1896 return 0;
1897} 1897}
1898 1898
1899static int mos7720_get_icount(struct tty_struct *tty,
1900 struct serial_icounter_struct *icount)
1901{
1902 struct usb_serial_port *port = tty->driver_data;
1903 struct moschip_port *mos7720_port;
1904 struct async_icount cnow;
1905
1906 mos7720_port = usb_get_serial_port_data(port);
1907 cnow = mos7720_port->icount;
1908
1909 icount->cts = cnow.cts;
1910 icount->dsr = cnow.dsr;
1911 icount->rng = cnow.rng;
1912 icount->dcd = cnow.dcd;
1913 icount->rx = cnow.rx;
1914 icount->tx = cnow.tx;
1915 icount->frame = cnow.frame;
1916 icount->overrun = cnow.overrun;
1917 icount->parity = cnow.parity;
1918 icount->brk = cnow.brk;
1919 icount->buf_overrun = cnow.buf_overrun;
1920
1921 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
1922 port->number, icount->rx, icount->tx);
1923 return 0;
1924}
1925
1899static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, 1926static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1900 unsigned int __user *value) 1927 unsigned int __user *value)
1901{ 1928{
1902 unsigned int mcr ; 1929 unsigned int mcr;
1903 unsigned int arg; 1930 unsigned int arg;
1904 1931
1905 struct usb_serial_port *port; 1932 struct usb_serial_port *port;
@@ -1973,7 +2000,6 @@ static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
1973 struct moschip_port *mos7720_port; 2000 struct moschip_port *mos7720_port;
1974 struct async_icount cnow; 2001 struct async_icount cnow;
1975 struct async_icount cprev; 2002 struct async_icount cprev;
1976 struct serial_icounter_struct icount;
1977 2003
1978 mos7720_port = usb_get_serial_port_data(port); 2004 mos7720_port = usb_get_serial_port_data(port);
1979 if (mos7720_port == NULL) 2005 if (mos7720_port == NULL)
@@ -2021,29 +2047,6 @@ static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
2021 } 2047 }
2022 /* NOTREACHED */ 2048 /* NOTREACHED */
2023 break; 2049 break;
2024
2025 case TIOCGICOUNT:
2026 cnow = mos7720_port->icount;
2027
2028 memset(&icount, 0, sizeof(struct serial_icounter_struct));
2029
2030 icount.cts = cnow.cts;
2031 icount.dsr = cnow.dsr;
2032 icount.rng = cnow.rng;
2033 icount.dcd = cnow.dcd;
2034 icount.rx = cnow.rx;
2035 icount.tx = cnow.tx;
2036 icount.frame = cnow.frame;
2037 icount.overrun = cnow.overrun;
2038 icount.parity = cnow.parity;
2039 icount.brk = cnow.brk;
2040 icount.buf_overrun = cnow.buf_overrun;
2041
2042 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2043 port->number, icount.rx, icount.tx);
2044 if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
2045 return -EFAULT;
2046 return 0;
2047 } 2050 }
2048 2051
2049 return -ENOIOCTLCMD; 2052 return -ENOIOCTLCMD;
@@ -2212,6 +2215,7 @@ static struct usb_serial_driver moschip7720_2port_driver = {
2212 .ioctl = mos7720_ioctl, 2215 .ioctl = mos7720_ioctl,
2213 .tiocmget = mos7720_tiocmget, 2216 .tiocmget = mos7720_tiocmget,
2214 .tiocmset = mos7720_tiocmset, 2217 .tiocmset = mos7720_tiocmset,
2218 .get_icount = mos7720_get_icount,
2215 .set_termios = mos7720_set_termios, 2219 .set_termios = mos7720_set_termios,
2216 .write = mos7720_write, 2220 .write = mos7720_write,
2217 .write_room = mos7720_write_room, 2221 .write_room = mos7720_write_room,
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 1a42bc213799..93dad5853cd5 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -2209,6 +2209,34 @@ static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
2209 return 0; 2209 return 0;
2210} 2210}
2211 2211
2212static int mos7840_get_icount(struct tty_struct *tty,
2213 struct serial_icounter_struct *icount)
2214{
2215 struct usb_serial_port *port = tty->driver_data;
2216 struct moschip_port *mos7840_port;
2217 struct async_icount cnow;
2218
2219 mos7840_port = mos7840_get_port_private(port);
2220 cnow = mos7840_port->icount;
2221
2222 smp_rmb();
2223 icount->cts = cnow.cts;
2224 icount->dsr = cnow.dsr;
2225 icount->rng = cnow.rng;
2226 icount->dcd = cnow.dcd;
2227 icount->rx = cnow.rx;
2228 icount->tx = cnow.tx;
2229 icount->frame = cnow.frame;
2230 icount->overrun = cnow.overrun;
2231 icount->parity = cnow.parity;
2232 icount->brk = cnow.brk;
2233 icount->buf_overrun = cnow.buf_overrun;
2234
2235 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2236 port->number, icount->rx, icount->tx);
2237 return 0;
2238}
2239
2212/***************************************************************************** 2240/*****************************************************************************
2213 * SerialIoctl 2241 * SerialIoctl
2214 * this function handles any ioctl calls to the driver 2242 * this function handles any ioctl calls to the driver
@@ -2223,7 +2251,6 @@ static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2223 2251
2224 struct async_icount cnow; 2252 struct async_icount cnow;
2225 struct async_icount cprev; 2253 struct async_icount cprev;
2226 struct serial_icounter_struct icount;
2227 2254
2228 if (mos7840_port_paranoia_check(port, __func__)) { 2255 if (mos7840_port_paranoia_check(port, __func__)) {
2229 dbg("%s", "Invalid port"); 2256 dbg("%s", "Invalid port");
@@ -2282,29 +2309,6 @@ static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2282 /* NOTREACHED */ 2309 /* NOTREACHED */
2283 break; 2310 break;
2284 2311
2285 case TIOCGICOUNT:
2286 cnow = mos7840_port->icount;
2287 smp_rmb();
2288
2289 memset(&icount, 0, sizeof(struct serial_icounter_struct));
2290
2291 icount.cts = cnow.cts;
2292 icount.dsr = cnow.dsr;
2293 icount.rng = cnow.rng;
2294 icount.dcd = cnow.dcd;
2295 icount.rx = cnow.rx;
2296 icount.tx = cnow.tx;
2297 icount.frame = cnow.frame;
2298 icount.overrun = cnow.overrun;
2299 icount.parity = cnow.parity;
2300 icount.brk = cnow.brk;
2301 icount.buf_overrun = cnow.buf_overrun;
2302
2303 dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __func__,
2304 port->number, icount.rx, icount.tx);
2305 if (copy_to_user(argp, &icount, sizeof(icount)))
2306 return -EFAULT;
2307 return 0;
2308 default: 2312 default:
2309 break; 2313 break;
2310 } 2314 }
@@ -2674,6 +2678,7 @@ static struct usb_serial_driver moschip7840_4port_device = {
2674 .break_ctl = mos7840_break, 2678 .break_ctl = mos7840_break,
2675 .tiocmget = mos7840_tiocmget, 2679 .tiocmget = mos7840_tiocmget,
2676 .tiocmset = mos7840_tiocmset, 2680 .tiocmset = mos7840_tiocmset,
2681 .get_icount = mos7840_get_icount,
2677 .attach = mos7840_startup, 2682 .attach = mos7840_startup,
2678 .disconnect = mos7840_disconnect, 2683 .disconnect = mos7840_disconnect,
2679 .release = mos7840_release, 2684 .release = mos7840_release,
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index e986002b3844..f5312dd3331b 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -416,12 +416,34 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
416 return 0; 416 return 0;
417} 417}
418 418
419static int ssu100_get_icount(struct tty_struct *tty,
420 struct serial_icounter_struct *icount)
421{
422 struct usb_serial_port *port = tty->driver_data;
423 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
424 struct async_icount cnow = priv->icount;
425
426 icount->cts = cnow.cts;
427 icount->dsr = cnow.dsr;
428 icount->rng = cnow.rng;
429 icount->dcd = cnow.dcd;
430 icount->rx = cnow.rx;
431 icount->tx = cnow.tx;
432 icount->frame = cnow.frame;
433 icount->overrun = cnow.overrun;
434 icount->parity = cnow.parity;
435 icount->brk = cnow.brk;
436 icount->buf_overrun = cnow.buf_overrun;
437
438 return 0;
439}
440
441
442
419static int ssu100_ioctl(struct tty_struct *tty, struct file *file, 443static int ssu100_ioctl(struct tty_struct *tty, struct file *file,
420 unsigned int cmd, unsigned long arg) 444 unsigned int cmd, unsigned long arg)
421{ 445{
422 struct usb_serial_port *port = tty->driver_data; 446 struct usb_serial_port *port = tty->driver_data;
423 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
424 void __user *user_arg = (void __user *)arg;
425 447
426 dbg("%s cmd 0x%04x", __func__, cmd); 448 dbg("%s cmd 0x%04x", __func__, cmd);
427 449
@@ -433,27 +455,6 @@ static int ssu100_ioctl(struct tty_struct *tty, struct file *file,
433 case TIOCMIWAIT: 455 case TIOCMIWAIT:
434 return wait_modem_info(port, arg); 456 return wait_modem_info(port, arg);
435 457
436 case TIOCGICOUNT:
437 {
438 struct serial_icounter_struct icount;
439 struct async_icount cnow = priv->icount;
440 memset(&icount, 0, sizeof(icount));
441 icount.cts = cnow.cts;
442 icount.dsr = cnow.dsr;
443 icount.rng = cnow.rng;
444 icount.dcd = cnow.dcd;
445 icount.rx = cnow.rx;
446 icount.tx = cnow.tx;
447 icount.frame = cnow.frame;
448 icount.overrun = cnow.overrun;
449 icount.parity = cnow.parity;
450 icount.brk = cnow.brk;
451 icount.buf_overrun = cnow.buf_overrun;
452 if (copy_to_user(user_arg, &icount, sizeof(icount)))
453 return -EFAULT;
454 return 0;
455 }
456
457 default: 458 default:
458 break; 459 break;
459 } 460 }
@@ -726,6 +727,7 @@ static struct usb_serial_driver ssu100_device = {
726 .process_read_urb = ssu100_process_read_urb, 727 .process_read_urb = ssu100_process_read_urb,
727 .tiocmget = ssu100_tiocmget, 728 .tiocmget = ssu100_tiocmget,
728 .tiocmset = ssu100_tiocmset, 729 .tiocmset = ssu100_tiocmset,
730 .get_icount = ssu100_get_icount,
729 .ioctl = ssu100_ioctl, 731 .ioctl = ssu100_ioctl,
730 .set_termios = ssu100_set_termios, 732 .set_termios = ssu100_set_termios,
731 .disconnect = usb_serial_generic_disconnect, 733 .disconnect = usb_serial_generic_disconnect,
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 90979a1f5311..b2902f307b47 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -108,6 +108,8 @@ static void ti_throttle(struct tty_struct *tty);
108static void ti_unthrottle(struct tty_struct *tty); 108static void ti_unthrottle(struct tty_struct *tty);
109static int ti_ioctl(struct tty_struct *tty, struct file *file, 109static int ti_ioctl(struct tty_struct *tty, struct file *file,
110 unsigned int cmd, unsigned long arg); 110 unsigned int cmd, unsigned long arg);
111static int ti_get_icount(struct tty_struct *tty,
112 struct serial_icounter_struct *icount);
111static void ti_set_termios(struct tty_struct *tty, 113static void ti_set_termios(struct tty_struct *tty,
112 struct usb_serial_port *port, struct ktermios *old_termios); 114 struct usb_serial_port *port, struct ktermios *old_termios);
113static int ti_tiocmget(struct tty_struct *tty, struct file *file); 115static int ti_tiocmget(struct tty_struct *tty, struct file *file);
@@ -237,6 +239,7 @@ static struct usb_serial_driver ti_1port_device = {
237 .set_termios = ti_set_termios, 239 .set_termios = ti_set_termios,
238 .tiocmget = ti_tiocmget, 240 .tiocmget = ti_tiocmget,
239 .tiocmset = ti_tiocmset, 241 .tiocmset = ti_tiocmset,
242 .get_icount = ti_get_icount,
240 .break_ctl = ti_break, 243 .break_ctl = ti_break,
241 .read_int_callback = ti_interrupt_callback, 244 .read_int_callback = ti_interrupt_callback,
242 .read_bulk_callback = ti_bulk_in_callback, 245 .read_bulk_callback = ti_bulk_in_callback,
@@ -265,6 +268,7 @@ static struct usb_serial_driver ti_2port_device = {
265 .set_termios = ti_set_termios, 268 .set_termios = ti_set_termios,
266 .tiocmget = ti_tiocmget, 269 .tiocmget = ti_tiocmget,
267 .tiocmset = ti_tiocmset, 270 .tiocmset = ti_tiocmset,
271 .get_icount = ti_get_icount,
268 .break_ctl = ti_break, 272 .break_ctl = ti_break,
269 .read_int_callback = ti_interrupt_callback, 273 .read_int_callback = ti_interrupt_callback,
270 .read_bulk_callback = ti_bulk_in_callback, 274 .read_bulk_callback = ti_bulk_in_callback,
@@ -788,6 +792,31 @@ static void ti_unthrottle(struct tty_struct *tty)
788 } 792 }
789} 793}
790 794
795static int ti_get_icount(struct tty_struct *tty,
796 struct serial_icounter_struct *icount)
797{
798 struct usb_serial_port *port = tty->driver_data;
799 struct ti_port *tport = usb_get_serial_port_data(port);
800 struct async_icount cnow = tport->tp_icount;
801
802 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d",
803 __func__, port->number,
804 cnow.rx, cnow.tx);
805
806 icount->cts = cnow.cts;
807 icount->dsr = cnow.dsr;
808 icount->rng = cnow.rng;
809 icount->dcd = cnow.dcd;
810 icount->rx = cnow.rx;
811 icount->tx = cnow.tx;
812 icount->frame = cnow.frame;
813 icount->overrun = cnow.overrun;
814 icount->parity = cnow.parity;
815 icount->brk = cnow.brk;
816 icount->buf_overrun = cnow.buf_overrun;
817
818 return 0;
819}
791 820
792static int ti_ioctl(struct tty_struct *tty, struct file *file, 821static int ti_ioctl(struct tty_struct *tty, struct file *file,
793 unsigned int cmd, unsigned long arg) 822 unsigned int cmd, unsigned long arg)
@@ -830,14 +859,6 @@ static int ti_ioctl(struct tty_struct *tty, struct file *file,
830 cprev = cnow; 859 cprev = cnow;
831 } 860 }
832 break; 861 break;
833 case TIOCGICOUNT:
834 dbg("%s - (%d) TIOCGICOUNT RX=%d, TX=%d",
835 __func__, port->number,
836 tport->tp_icount.rx, tport->tp_icount.tx);
837 if (copy_to_user((void __user *)arg, &tport->tp_icount,
838 sizeof(tport->tp_icount)))
839 return -EFAULT;
840 return 0;
841 } 862 }
842 return -ENOIOCTLCMD; 863 return -ENOIOCTLCMD;
843} 864}
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 7a2177c79bde..e64da74bdcc5 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -519,6 +519,18 @@ static int serial_tiocmset(struct tty_struct *tty, struct file *file,
519 return -EINVAL; 519 return -EINVAL;
520} 520}
521 521
522static int serial_get_icount(struct tty_struct *tty,
523 struct serial_icounter_struct *icount)
524{
525 struct usb_serial_port *port = tty->driver_data;
526
527 dbg("%s - port %d", __func__, port->number);
528
529 if (port->serial->type->get_icount)
530 return port->serial->type->get_icount(tty, icount);
531 return -EINVAL;
532}
533
522/* 534/*
523 * We would be calling tty_wakeup here, but unfortunately some line 535 * We would be calling tty_wakeup here, but unfortunately some line
524 * disciplines have an annoying habit of calling tty->write from 536 * disciplines have an annoying habit of calling tty->write from
@@ -1195,6 +1207,7 @@ static const struct tty_operations serial_ops = {
1195 .chars_in_buffer = serial_chars_in_buffer, 1207 .chars_in_buffer = serial_chars_in_buffer,
1196 .tiocmget = serial_tiocmget, 1208 .tiocmget = serial_tiocmget,
1197 .tiocmset = serial_tiocmset, 1209 .tiocmset = serial_tiocmset,
1210 .get_icount = serial_get_icount,
1198 .cleanup = serial_cleanup, 1211 .cleanup = serial_cleanup,
1199 .install = serial_install, 1212 .install = serial_install,
1200 .proc_fops = &serial_proc_fops, 1213 .proc_fops = &serial_proc_fops,