aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-10-22 22:59:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-22 22:59:04 -0400
commit73ecf3a6e3f0206bf56a0fefe3b3eda042fb7034 (patch)
tree866f0ebb2b148479e93b5ac955097b1cc94ceb4e /drivers/serial
parentb9da0571050c09863e59f94d0b8594a290d61b88 (diff)
parentcd3ecad19aea8debae9a48b53de2ec7a571f24e9 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6: (49 commits) serial8250: ratelimit "too much work" error serial: bfin_sport_uart: speed up sport RX sample rate to be 3% faster serial: abstraction for 8250 legacy ports serial/imx: check that the buffer is non-empty before sending it out serial: mfd: add more baud rates support jsm: Remove the uart port on errors Alchemy: Add UART PM methods. 8250: allow platforms to override PM hook. altera_uart: Don't use plain integer as NULL pointer altera_uart: Fix missing prototype for registering an early console altera_uart: Fixup type usage of port flags altera_uart: Make it possible to use Altera UART and 8250 ports together altera_uart: Add support for different address strides altera_uart: Add support for getting mapbase and IRQ from resources altera_uart: Add support for polling mode (IRQ-less) serial: Factor out uart_poll_timeout() from 8250 driver serial: mark the 8250 driver as maintained serial: 8250: Don't delay after transmitter is ready. tty: MAINTAINERS: add drivers/serial/jsm/ as maintained driver vcs: invoke the vt update callback when /dev/vcs* is written to ...
Diffstat (limited to 'drivers/serial')
-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
13 files changed, 515 insertions, 299 deletions
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/* ---------------------------------------------------------------------