From 97d303b7657c1a45c158d002f829ff69196c493d Mon Sep 17 00:00:00 2001 From: David Daney Date: Tue, 5 Oct 2010 11:40:07 -0700 Subject: serial: 8250: Don't delay after transmitter is ready. The loop in wait_for_xmitr() is delaying one extra uS after the ready condition has been met. Rewrite the loop to only delay if the transmitter is not ready. Signed-off-by: David Daney Signed-off-by: Greg Kroah-Hartman --- drivers/serial/8250.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/serial/8250.c') diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index 24110f6f61e0..31b8cca179cd 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c @@ -1867,15 +1867,17 @@ static void wait_for_xmitr(struct uart_8250_port *up, int bits) unsigned int status, tmout = 10000; /* Wait up to 10ms for the character(s) to be sent. */ - do { + for (;;) { status = serial_in(up, UART_LSR); up->lsr_saved_flags |= status & LSR_SAVE_FLAGS; + if ((status & bits) == bits) + break; if (--tmout == 0) break; udelay(1); - } while ((status & bits) != bits); + } /* Wait up to 1s for flow control if necessary */ if (up->port.flags & UPF_CONS_FLOW) { -- cgit v1.2.3-55-g7522 From 54381067ed7873e6173d6fe32818a585ad667723 Mon Sep 17 00:00:00 2001 From: Anton Vorontsov Date: Fri, 1 Oct 2010 17:21:25 +0400 Subject: serial: Factor out uart_poll_timeout() from 8250 driver Soon we will use that handy function in the altera_uart driver. Signed-off-by: Anton Vorontsov Cc: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/serial/8250.c | 14 ++++---------- include/linux/serial_core.h | 8 ++++++++ 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'drivers/serial/8250.c') diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index 31b8cca179cd..b586406f04ca 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c @@ -1722,12 +1722,6 @@ static void serial_unlink_irq_chain(struct uart_8250_port *up) mutex_unlock(&hash_mutex); } -/* Base timer interval for polling */ -static inline int poll_timeout(int timeout) -{ - return timeout > 6 ? (timeout / 2 - 2) : 1; -} - /* * This function is used to handle ports that do not have an * interrupt. This doesn't work very well for 16450's, but gives @@ -1742,7 +1736,7 @@ static void serial8250_timeout(unsigned long data) iir = serial_in(up, UART_IIR); if (!(iir & UART_IIR_NO_INT)) serial8250_handle_port(up); - mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout)); + mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port)); } static void serial8250_backup_timeout(unsigned long data) @@ -1787,7 +1781,7 @@ static void serial8250_backup_timeout(unsigned long data) /* Standard timer interval plus 0.2s to keep the port running */ mod_timer(&up->timer, - jiffies + poll_timeout(up->port.timeout) + HZ / 5); + jiffies + uart_poll_timeout(&up->port) + HZ / 5); } static unsigned int serial8250_tx_empty(struct uart_port *port) @@ -2071,7 +2065,7 @@ static int serial8250_startup(struct uart_port *port) up->timer.function = serial8250_backup_timeout; up->timer.data = (unsigned long)up; mod_timer(&up->timer, jiffies + - poll_timeout(up->port.timeout) + HZ / 5); + uart_poll_timeout(port) + HZ / 5); } /* @@ -2081,7 +2075,7 @@ static int serial8250_startup(struct uart_port *port) */ if (!is_real_interrupt(up->port.irq)) { up->timer.data = (unsigned long)up; - mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout)); + mod_timer(&up->timer, jiffies + uart_poll_timeout(port)); } else { retval = serial_link_irq_chain(up); if (retval) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 563e23400913..ac48082f3559 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -411,6 +411,14 @@ unsigned int uart_get_baud_rate(struct uart_port *port, struct ktermios *termios unsigned int max); unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud); +/* Base timer interval for polling */ +static inline int uart_poll_timeout(struct uart_port *port) +{ + int timeout = port->timeout; + + return timeout > 6 ? (timeout / 2 - 2) : 1; +} + /* * Console helpers. */ -- cgit v1.2.3-55-g7522 From c161afe9759ddcc174d08e7c4f683d08ac9ba86f Mon Sep 17 00:00:00 2001 From: Manuel Lauss Date: Sat, 25 Sep 2010 15:13:45 +0200 Subject: 8250: allow platforms to override PM hook. Add a hook for platforms to specify custom pm methods. Signed-off-by: Manuel Lauss Cc: Alan Cox Signed-off-by: Greg Kroah-Hartman --- drivers/serial/8250.c | 27 ++++++++++++++++----------- include/linux/serial_8250.h | 4 ++++ include/linux/serial_core.h | 2 ++ 3 files changed, 22 insertions(+), 11 deletions(-) (limited to 'drivers/serial/8250.c') diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index b586406f04ca..6994afb5571a 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c @@ -154,12 +154,6 @@ struct uart_8250_port { unsigned char lsr_saved_flags; #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA unsigned char msr_saved_flags; - - /* - * We provide a per-port pm hook. - */ - void (*pm)(struct uart_port *port, - unsigned int state, unsigned int old); }; struct irq_info { @@ -2436,16 +2430,24 @@ serial8250_set_ldisc(struct uart_port *port, int new) port->flags &= ~UPF_HARDPPS_CD; } -static void -serial8250_pm(struct uart_port *port, unsigned int state, - unsigned int oldstate) + +void serial8250_do_pm(struct uart_port *port, unsigned int state, + unsigned int oldstate) { struct uart_8250_port *p = (struct uart_8250_port *)port; serial8250_set_sleep(p, state != 0); +} +EXPORT_SYMBOL(serial8250_do_pm); - if (p->pm) - p->pm(port, state, oldstate); +static void +serial8250_pm(struct uart_port *port, unsigned int state, + unsigned int oldstate) +{ + if (port->pm) + port->pm(port, state, oldstate); + else + serial8250_do_pm(port, state, oldstate); } static unsigned int serial8250_port_size(struct uart_8250_port *pt) @@ -3006,6 +3008,7 @@ static int __devinit serial8250_probe(struct platform_device *dev) port.serial_in = p->serial_in; port.serial_out = p->serial_out; port.set_termios = p->set_termios; + port.pm = p->pm; port.dev = &dev->dev; port.irqflags |= irqflag; ret = serial8250_register_port(&port); @@ -3172,6 +3175,8 @@ int serial8250_register_port(struct uart_port *port) /* Possibly override set_termios call */ if (port->set_termios) uart->port.set_termios = port->set_termios; + if (port->pm) + uart->port.pm = port->pm; ret = uart_add_one_port(&serial8250_reg, &uart->port); if (ret == 0) diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h index 7638deaaba65..bf9c2bdb2e05 100644 --- a/include/linux/serial_8250.h +++ b/include/linux/serial_8250.h @@ -35,6 +35,8 @@ struct plat_serial8250_port { void (*set_termios)(struct uart_port *, struct ktermios *new, struct ktermios *old); + void (*pm)(struct uart_port *, unsigned int state, + unsigned old); }; /* @@ -76,5 +78,7 @@ extern int serial8250_find_port_for_earlycon(void); extern int setup_early_serial8250_console(char *cmdline); extern void serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old); +extern void serial8250_do_pm(struct uart_port *port, unsigned int state, + unsigned int oldstate); #endif diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index ac48082f3559..99e5994e6f84 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -289,6 +289,8 @@ struct uart_port { void (*set_termios)(struct uart_port *, struct ktermios *new, struct ktermios *old); + void (*pm)(struct uart_port *, unsigned int state, + unsigned int old); unsigned int irq; /* irq number */ unsigned long irqflags; /* irq flags */ unsigned int uartclk; /* base uart clock */ -- cgit v1.2.3-55-g7522 From af7f3743567e3d5b40e2f9c21541b7f40b99c103 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 18 Oct 2010 11:38:02 -0700 Subject: serial: abstraction for 8250 legacy ports Not every platform that has generic legacy 8250 ports manages to have them clocked the right way or without errata. Provide a generic interface to allow platforms to override the default behaviour in a manner that dumps the complexity in *their* code not the 8250 driver. Signed-off-by: Alan Cox Signed-off-by: Dirk Brandewie Acked-by: Thomas Gleixner Signed-off-by: Greg Kroah-Hartman --- drivers/serial/8250.c | 17 +++++++++++++++++ include/linux/serial_8250.h | 4 ++++ 2 files changed, 21 insertions(+) (limited to 'drivers/serial/8250.c') diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index 6994afb5571a..37f19a678c97 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c @@ -2672,6 +2672,16 @@ static struct uart_ops serial8250_pops = { static struct uart_8250_port serial8250_ports[UART_NR]; +static void (*serial8250_isa_config)(int port, struct uart_port *up, + unsigned short *capabilities); + +void serial8250_set_isa_configurator( + void (*v)(int port, struct uart_port *up, unsigned short *capabilities)) +{ + serial8250_isa_config = v; +} +EXPORT_SYMBOL(serial8250_set_isa_configurator); + static void __init serial8250_isa_init_ports(void) { struct uart_8250_port *up; @@ -2717,6 +2727,9 @@ static void __init serial8250_isa_init_ports(void) up->port.regshift = old_serial_port[i].iomem_reg_shift; set_io_from_upio(&up->port); up->port.irqflags |= irqflag; + if (serial8250_isa_config != NULL) + serial8250_isa_config(i, &up->port, &up->capabilities); + } } @@ -3178,6 +3191,10 @@ int serial8250_register_port(struct uart_port *port) if (port->pm) uart->port.pm = port->pm; + if (serial8250_isa_config != NULL) + serial8250_isa_config(0, &uart->port, + &uart->capabilities); + ret = uart_add_one_port(&serial8250_reg, &uart->port); if (ret == 0) ret = uart->port.line; diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h index bf9c2bdb2e05..97f5b45bbc07 100644 --- a/include/linux/serial_8250.h +++ b/include/linux/serial_8250.h @@ -81,4 +81,8 @@ extern void serial8250_do_set_termios(struct uart_port *port, extern void serial8250_do_pm(struct uart_port *port, unsigned int state, unsigned int oldstate); +extern void serial8250_set_isa_configurator(void (*v) + (int port, struct uart_port *up, + unsigned short *capabilities)); + #endif -- cgit v1.2.3-55-g7522 From cd3ecad19aea8debae9a48b53de2ec7a571f24e9 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Wed, 20 Oct 2010 16:00:48 -0700 Subject: serial8250: ratelimit "too much work" error Running a serial console, if too many kernel messages are generated within a short time causing a lot of serial I/O, the 8250 driver will generate another kernel message reporting this, which just adds to the I/O. It has a cascading effect and quickly results the system being brought to its knees by a flood of "too much work" messages. Ratelimit the error message to avoid this. [akpm@linux-foundation.org: use the superior printk_ratelimited()] [akpm@linux-foundation.org: printk_ratelimited() needs ratelimit.h] Signed-off-by: Daniel Drake Acked-by: Alan Cox Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/serial/8250.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/serial/8250.c') diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index 37f19a678c97..167c4a6ccbc3 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1600,8 +1601,8 @@ static irqreturn_t serial8250_interrupt(int irq, void *dev_id) if (l == i->head && pass_counter++ > PASS_LIMIT) { /* If we hit this, we're dead. */ - printk(KERN_ERR "serial8250: too much work for " - "irq%d\n", irq); + printk_ratelimited(KERN_ERR + "serial8250: too much work for irq%d\n", irq); break; } } while (l != end); -- cgit v1.2.3-55-g7522