| From 291546c8ba381a8579bdcfc2a1dee3971c3ac9b9 Mon Sep 17 00:00:00 2001 |
| From: Paul Gortmaker <paul.gortmaker@windriver.com> |
| Date: Thu, 8 Mar 2012 19:12:13 -0500 |
| Subject: serial: use serial_port_in/out vs serial_in/out in 8250 |
| |
| The serial_in and serial_out helpers are expecting to operate |
| on an 8250_port struct. These in turn go after the contained |
| normal port struct which actually has the actual in/out accessors. |
| |
| But what is happening in some cases, is that a function is passed |
| in a port struct, and it runs container_of to get the 8250_port |
| struct, and then it uses serial_in/out helpers on that. But when |
| you do, it goes full circle, since it jumps back inside the 8250_port |
| to find the contained port struct (which we already knew!). |
| |
| So, if we are operating in a scope where we know the struct port, |
| then use the serial_port_in/out helpers and avoid the bouncing |
| around. If we don't have the struct port handy, and it isn't |
| worth making a local for it, then just leave things as-is which |
| uses the serial_in/out helpers that will resolve the 8250_port |
| onto the struct port. |
| |
| Mostly, gcc figures this out on its own -- so this doesn't bring to |
| the table any revolutionary runtime delta. However, it is somewhat |
| misleading to always hammer away on 8250 structs, when the actual |
| underlying property isn't at all 8250 specific -- and this change |
| makes that clear. |
| |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| Acked-by: Alan Cox <alan@linux.intel.com> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| (cherry picked from commit 4fd996a14660f56a6fd92ce7c8fb167d262c994f) |
| |
| Signed-off-by: Simon Horman <horms@verge.net.au> |
| --- |
| drivers/tty/serial/8250/8250.c | 160 ++++++++++++++++++++-------------------- |
| 1 file changed, 80 insertions(+), 80 deletions(-) |
| |
| diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250.c |
| index 9ffb3cf..cb45a29 100644 |
| --- a/drivers/tty/serial/8250/8250.c |
| +++ b/drivers/tty/serial/8250/8250.c |
| @@ -1287,7 +1287,7 @@ static void serial8250_start_tx(struct uart_port *port) |
| |
| if (!(up->ier & UART_IER_THRI)) { |
| up->ier |= UART_IER_THRI; |
| - serial_out(up, UART_IER, up->ier); |
| + serial_port_out(port, UART_IER, up->ier); |
| |
| if (up->bugs & UART_BUG_TXEN) { |
| unsigned char lsr; |
| @@ -1316,7 +1316,7 @@ static void serial8250_stop_rx(struct uart_port *port) |
| |
| up->ier &= ~UART_IER_RLSI; |
| up->port.read_status_mask &= ~UART_LSR_DR; |
| - serial_out(up, UART_IER, up->ier); |
| + serial_port_out(port, UART_IER, up->ier); |
| } |
| |
| static void serial8250_enable_ms(struct uart_port *port) |
| @@ -1329,7 +1329,7 @@ static void serial8250_enable_ms(struct uart_port *port) |
| return; |
| |
| up->ier |= UART_IER_MSI; |
| - serial_out(up, UART_IER, up->ier); |
| + serial_port_out(port, UART_IER, up->ier); |
| } |
| |
| /* |
| @@ -1523,7 +1523,7 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir) |
| |
| spin_lock_irqsave(&port->lock, flags); |
| |
| - status = serial_in(up, UART_LSR); |
| + status = serial_port_in(port, UART_LSR); |
| |
| DEBUG_INTR("status = %x...", status); |
| |
| @@ -1540,9 +1540,7 @@ EXPORT_SYMBOL_GPL(serial8250_handle_irq); |
| |
| static int serial8250_default_handle_irq(struct uart_port *port) |
| { |
| - struct uart_8250_port *up = |
| - container_of(port, struct uart_8250_port, port); |
| - unsigned int iir = serial_in(up, UART_IIR); |
| + unsigned int iir = serial_port_in(port, UART_IIR); |
| |
| return serial8250_handle_irq(port, iir); |
| } |
| @@ -1774,7 +1772,7 @@ static unsigned int serial8250_tx_empty(struct uart_port *port) |
| unsigned int lsr; |
| |
| spin_lock_irqsave(&port->lock, flags); |
| - lsr = serial_in(up, UART_LSR); |
| + lsr = serial_port_in(port, UART_LSR); |
| up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
| spin_unlock_irqrestore(&port->lock, flags); |
| |
| @@ -1821,7 +1819,7 @@ static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
| |
| mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; |
| |
| - serial_out(up, UART_MCR, mcr); |
| + serial_port_out(port, UART_MCR, mcr); |
| } |
| |
| static void serial8250_break_ctl(struct uart_port *port, int break_state) |
| @@ -1835,7 +1833,7 @@ static void serial8250_break_ctl(struct uart_port *port, int break_state) |
| up->lcr |= UART_LCR_SBC; |
| else |
| up->lcr &= ~UART_LCR_SBC; |
| - serial_out(up, UART_LCR, up->lcr); |
| + serial_port_out(port, UART_LCR, up->lcr); |
| spin_unlock_irqrestore(&port->lock, flags); |
| } |
| |
| @@ -1881,14 +1879,12 @@ static void wait_for_xmitr(struct uart_8250_port *up, int bits) |
| |
| static int serial8250_get_poll_char(struct uart_port *port) |
| { |
| - struct uart_8250_port *up = |
| - container_of(port, struct uart_8250_port, port); |
| - unsigned char lsr = serial_in(up, UART_LSR); |
| + unsigned char lsr = serial_port_in(port, UART_LSR); |
| |
| if (!(lsr & UART_LSR_DR)) |
| return NO_POLL_CHAR; |
| |
| - return serial_in(up, UART_RX); |
| + return serial_port_in(port, UART_RX); |
| } |
| |
| |
| @@ -1902,21 +1898,21 @@ static void serial8250_put_poll_char(struct uart_port *port, |
| /* |
| * First save the IER then disable the interrupts |
| */ |
| - ier = serial_in(up, UART_IER); |
| + ier = serial_port_in(port, UART_IER); |
| if (up->capabilities & UART_CAP_UUE) |
| - serial_out(up, UART_IER, UART_IER_UUE); |
| + serial_port_out(port, UART_IER, UART_IER_UUE); |
| else |
| - serial_out(up, UART_IER, 0); |
| + serial_port_out(port, UART_IER, 0); |
| |
| wait_for_xmitr(up, BOTH_EMPTY); |
| /* |
| * Send the character out. |
| * If a LF, also do CR... |
| */ |
| - serial_out(up, UART_TX, c); |
| + serial_port_out(port, UART_TX, c); |
| if (c == 10) { |
| wait_for_xmitr(up, BOTH_EMPTY); |
| - serial_out(up, UART_TX, 13); |
| + serial_port_out(port, UART_TX, 13); |
| } |
| |
| /* |
| @@ -1924,7 +1920,7 @@ static void serial8250_put_poll_char(struct uart_port *port, |
| * and restore the IER |
| */ |
| wait_for_xmitr(up, BOTH_EMPTY); |
| - serial_out(up, UART_IER, ier); |
| + serial_port_out(port, UART_IER, ier); |
| } |
| |
| #endif /* CONFIG_CONSOLE_POLL */ |
| @@ -1948,14 +1944,14 @@ static int serial8250_startup(struct uart_port *port) |
| if (port->type == PORT_16C950) { |
| /* Wake up and initialize UART */ |
| up->acr = 0; |
| - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
| - serial_out(up, UART_EFR, UART_EFR_ECB); |
| - serial_out(up, UART_IER, 0); |
| - serial_out(up, UART_LCR, 0); |
| + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); |
| + serial_port_out(port, UART_EFR, UART_EFR_ECB); |
| + serial_port_out(port, UART_IER, 0); |
| + serial_port_out(port, UART_LCR, 0); |
| serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ |
| - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
| - serial_out(up, UART_EFR, UART_EFR_ECB); |
| - serial_out(up, UART_LCR, 0); |
| + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); |
| + serial_port_out(port, UART_EFR, UART_EFR_ECB); |
| + serial_port_out(port, UART_LCR, 0); |
| } |
| |
| #ifdef CONFIG_SERIAL_8250_RSA |
| @@ -1975,10 +1971,10 @@ static int serial8250_startup(struct uart_port *port) |
| /* |
| * Clear the interrupt registers. |
| */ |
| - serial_in(up, UART_LSR); |
| - serial_in(up, UART_RX); |
| - serial_in(up, UART_IIR); |
| - serial_in(up, UART_MSR); |
| + serial_port_in(port, UART_LSR); |
| + serial_port_in(port, UART_RX); |
| + serial_port_in(port, UART_IIR); |
| + serial_port_in(port, UART_MSR); |
| |
| /* |
| * At this point, there's no way the LSR could still be 0xff; |
| @@ -1986,7 +1982,7 @@ static int serial8250_startup(struct uart_port *port) |
| * here. |
| */ |
| if (!(port->flags & UPF_BUGGY_UART) && |
| - (serial_in(up, UART_LSR) == 0xff)) { |
| + (serial_port_in(port, UART_LSR) == 0xff)) { |
| printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n", |
| serial_index(port)); |
| return -ENODEV; |
| @@ -2001,12 +1997,14 @@ static int serial8250_startup(struct uart_port *port) |
| serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
| |
| fctr = serial_in(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX); |
| - serial_out(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX); |
| - serial_out(up, UART_TRG, UART_TRG_96); |
| - serial_out(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX); |
| - serial_out(up, UART_TRG, UART_TRG_96); |
| + serial_port_out(port, UART_FCTR, |
| + fctr | UART_FCTR_TRGD | UART_FCTR_RX); |
| + serial_port_out(port, UART_TRG, UART_TRG_96); |
| + serial_port_out(port, UART_FCTR, |
| + fctr | UART_FCTR_TRGD | UART_FCTR_TX); |
| + serial_port_out(port, UART_TRG, UART_TRG_96); |
| |
| - serial_out(up, UART_LCR, 0); |
| + serial_port_out(port, UART_LCR, 0); |
| } |
| |
| if (port->irq) { |
| @@ -2026,12 +2024,12 @@ static int serial8250_startup(struct uart_port *port) |
| wait_for_xmitr(up, UART_LSR_THRE); |
| serial_out_sync(up, UART_IER, UART_IER_THRI); |
| udelay(1); /* allow THRE to set */ |
| - iir1 = serial_in(up, UART_IIR); |
| - serial_out(up, UART_IER, 0); |
| + iir1 = serial_port_in(port, UART_IIR); |
| + serial_port_out(port, UART_IER, 0); |
| serial_out_sync(up, UART_IER, UART_IER_THRI); |
| udelay(1); /* allow a working UART time to re-assert THRE */ |
| - iir = serial_in(up, UART_IIR); |
| - serial_out(up, UART_IER, 0); |
| + iir = serial_port_in(port, UART_IIR); |
| + serial_port_out(port, UART_IER, 0); |
| |
| if (port->irqflags & IRQF_SHARED) |
| enable_irq(port->irq); |
| @@ -2076,7 +2074,7 @@ static int serial8250_startup(struct uart_port *port) |
| /* |
| * Now, initialize the UART |
| */ |
| - serial_out(up, UART_LCR, UART_LCR_WLEN8); |
| + serial_port_out(port, UART_LCR, UART_LCR_WLEN8); |
| |
| spin_lock_irqsave(&port->lock, flags); |
| if (up->port.flags & UPF_FOURPORT) { |
| @@ -2109,10 +2107,10 @@ static int serial8250_startup(struct uart_port *port) |
| * Do a quick test to see if we receive an |
| * interrupt when we enable the TX irq. |
| */ |
| - serial_out(up, UART_IER, UART_IER_THRI); |
| - lsr = serial_in(up, UART_LSR); |
| - iir = serial_in(up, UART_IIR); |
| - serial_out(up, UART_IER, 0); |
| + serial_port_out(port, UART_IER, UART_IER_THRI); |
| + lsr = serial_port_in(port, UART_LSR); |
| + iir = serial_port_in(port, UART_IIR); |
| + serial_port_out(port, UART_IER, 0); |
| |
| if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) { |
| if (!(up->bugs & UART_BUG_TXEN)) { |
| @@ -2132,10 +2130,10 @@ dont_test_tx_en: |
| * saved flags to avoid getting false values from polling |
| * routines or the previous session. |
| */ |
| - serial_in(up, UART_LSR); |
| - serial_in(up, UART_RX); |
| - serial_in(up, UART_IIR); |
| - serial_in(up, UART_MSR); |
| + serial_port_in(port, UART_LSR); |
| + serial_port_in(port, UART_RX); |
| + serial_port_in(port, UART_IIR); |
| + serial_port_in(port, UART_MSR); |
| up->lsr_saved_flags = 0; |
| up->msr_saved_flags = 0; |
| |
| @@ -2145,7 +2143,7 @@ dont_test_tx_en: |
| * anyway, so we don't enable them here. |
| */ |
| up->ier = UART_IER_RLSI | UART_IER_RDI; |
| - serial_out(up, UART_IER, up->ier); |
| + serial_port_out(port, UART_IER, up->ier); |
| |
| if (port->flags & UPF_FOURPORT) { |
| unsigned int icp; |
| @@ -2170,7 +2168,7 @@ static void serial8250_shutdown(struct uart_port *port) |
| * Disable interrupts from this port |
| */ |
| up->ier = 0; |
| - serial_out(up, UART_IER, 0); |
| + serial_port_out(port, UART_IER, 0); |
| |
| spin_lock_irqsave(&port->lock, flags); |
| if (port->flags & UPF_FOURPORT) { |
| @@ -2186,7 +2184,8 @@ static void serial8250_shutdown(struct uart_port *port) |
| /* |
| * Disable break condition and FIFOs |
| */ |
| - serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC); |
| + serial_port_out(port, UART_LCR, |
| + serial_port_in(port, UART_LCR) & ~UART_LCR_SBC); |
| serial8250_clear_fifos(up); |
| |
| #ifdef CONFIG_SERIAL_8250_RSA |
| @@ -2200,7 +2199,7 @@ static void serial8250_shutdown(struct uart_port *port) |
| * Read data port to reset things, and then unlink from |
| * the IRQ chain. |
| */ |
| - serial_in(up, UART_RX); |
| + serial_port_in(port, UART_RX); |
| |
| del_timer_sync(&up->timer); |
| up->timer.function = serial8250_timeout; |
| @@ -2351,7 +2350,7 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, |
| if (up->capabilities & UART_CAP_RTOIE) |
| up->ier |= UART_IER_RTOIE; |
| |
| - serial_out(up, UART_IER, up->ier); |
| + serial_port_out(port, UART_IER, up->ier); |
| |
| if (up->capabilities & UART_CAP_EFR) { |
| unsigned char efr = 0; |
| @@ -2363,11 +2362,11 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, |
| if (termios->c_cflag & CRTSCTS) |
| efr |= UART_EFR_CTS; |
| |
| - serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); |
| + serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); |
| if (port->flags & UPF_EXAR_EFR) |
| - serial_out(up, UART_XR_EFR, efr); |
| + serial_port_out(port, UART_XR_EFR, efr); |
| else |
| - serial_out(up, UART_EFR, efr); |
| + serial_port_out(port, UART_EFR, efr); |
| } |
| |
| #ifdef CONFIG_ARCH_OMAP |
| @@ -2375,18 +2374,20 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, |
| if (cpu_is_omap1510() && is_omap_port(up)) { |
| if (baud == 115200) { |
| quot = 1; |
| - serial_out(up, UART_OMAP_OSC_12M_SEL, 1); |
| + serial_port_out(port, UART_OMAP_OSC_12M_SEL, 1); |
| } else |
| - serial_out(up, UART_OMAP_OSC_12M_SEL, 0); |
| + serial_port_out(port, UART_OMAP_OSC_12M_SEL, 0); |
| } |
| #endif |
| |
| - if (up->capabilities & UART_NATSEMI) { |
| - /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */ |
| - serial_out(up, UART_LCR, 0xe0); |
| - } else { |
| - serial_out(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ |
| - } |
| + /* |
| + * For NatSemi, switch to bank 2 not bank 1, to avoid resetting EXCR2, |
| + * otherwise just set DLAB |
| + */ |
| + if (up->capabilities & UART_NATSEMI) |
| + serial_port_out(port, UART_LCR, 0xe0); |
| + else |
| + serial_port_out(port, UART_LCR, cval | UART_LCR_DLAB); |
| |
| serial_dl_write(up, quot); |
| |
| @@ -2395,16 +2396,15 @@ serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, |
| * is written without DLAB set, this mode will be disabled. |
| */ |
| if (port->type == PORT_16750) |
| - serial_out(up, UART_FCR, fcr); |
| + serial_port_out(port, UART_FCR, fcr); |
| |
| - serial_out(up, UART_LCR, cval); /* reset DLAB */ |
| + serial_port_out(port, UART_LCR, cval); /* reset DLAB */ |
| up->lcr = cval; /* Save LCR */ |
| if (port->type != PORT_16750) { |
| - if (fcr & UART_FCR_ENABLE_FIFO) { |
| - /* emulated UARTs (Lucent Venus 167x) need two steps */ |
| - serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); |
| - } |
| - serial_out(up, UART_FCR, fcr); /* set fcr */ |
| + /* emulated UARTs (Lucent Venus 167x) need two steps */ |
| + if (fcr & UART_FCR_ENABLE_FIFO) |
| + serial_port_out(port, UART_FCR, UART_FCR_ENABLE_FIFO); |
| + serial_port_out(port, UART_FCR, fcr); /* set fcr */ |
| } |
| serial8250_set_mctrl(port, port->mctrl); |
| spin_unlock_irqrestore(&port->lock, flags); |
| @@ -2786,7 +2786,7 @@ static void serial8250_console_putchar(struct uart_port *port, int ch) |
| container_of(port, struct uart_8250_port, port); |
| |
| wait_for_xmitr(up, UART_LSR_THRE); |
| - serial_out(up, UART_TX, ch); |
| + serial_port_out(port, UART_TX, ch); |
| } |
| |
| /* |
| @@ -2818,12 +2818,12 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count) |
| /* |
| * First save the IER then disable the interrupts |
| */ |
| - ier = serial_in(up, UART_IER); |
| + ier = serial_port_in(port, UART_IER); |
| |
| if (up->capabilities & UART_CAP_UUE) |
| - serial_out(up, UART_IER, UART_IER_UUE); |
| + serial_port_out(port, UART_IER, UART_IER_UUE); |
| else |
| - serial_out(up, UART_IER, 0); |
| + serial_port_out(port, UART_IER, 0); |
| |
| uart_console_write(port, s, count, serial8250_console_putchar); |
| |
| @@ -2832,7 +2832,7 @@ serial8250_console_write(struct console *co, const char *s, unsigned int count) |
| * and restore the IER |
| */ |
| wait_for_xmitr(up, BOTH_EMPTY); |
| - serial_out(up, UART_IER, ier); |
| + serial_port_out(port, UART_IER, ier); |
| |
| /* |
| * The receive handling will happen properly because the |
| @@ -2994,11 +2994,11 @@ void serial8250_resume_port(int line) |
| |
| if (up->capabilities & UART_NATSEMI) { |
| /* Ensure it's still in high speed mode */ |
| - serial_out(up, UART_LCR, 0xE0); |
| + serial_port_out(port, UART_LCR, 0xE0); |
| |
| ns16550a_goto_highspeed(up); |
| |
| - serial_out(up, UART_LCR, 0); |
| + serial_port_out(port, UART_LCR, 0); |
| port->uartclk = 921600*16; |
| } |
| uart_resume_port(&serial8250_reg, port); |
| -- |
| 1.7.10.1.362.g242cab3 |
| |