| .. | .. |
|---|
| 15 | 15 | #include <linux/moduleparam.h> |
|---|
| 16 | 16 | #include <linux/ioport.h> |
|---|
| 17 | 17 | #include <linux/init.h> |
|---|
| 18 | +#include <linux/irq.h> |
|---|
| 18 | 19 | #include <linux/console.h> |
|---|
| 19 | 20 | #include <linux/gpio/consumer.h> |
|---|
| 20 | 21 | #include <linux/sysrq.h> |
|---|
| .. | .. |
|---|
| 737 | 738 | serial_out(p, UART_EFR, UART_EFR_ECB); |
|---|
| 738 | 739 | serial_out(p, UART_LCR, 0); |
|---|
| 739 | 740 | } |
|---|
| 740 | | - serial8250_set_IER(p, sleep ? UART_IERX_SLEEP : 0); |
|---|
| 741 | + serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); |
|---|
| 741 | 742 | if (p->capabilities & UART_CAP_EFR) { |
|---|
| 742 | 743 | serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); |
|---|
| 743 | 744 | serial_out(p, UART_EFR, efr); |
|---|
| .. | .. |
|---|
| 1411 | 1412 | |
|---|
| 1412 | 1413 | up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); |
|---|
| 1413 | 1414 | up->port.read_status_mask &= ~UART_LSR_DR; |
|---|
| 1414 | | - serial8250_set_IER(up, up->ier); |
|---|
| 1415 | + serial_port_out(port, UART_IER, up->ier); |
|---|
| 1415 | 1416 | |
|---|
| 1416 | 1417 | serial8250_rpm_put(up); |
|---|
| 1417 | 1418 | } |
|---|
| .. | .. |
|---|
| 1441 | 1442 | serial8250_clear_and_reinit_fifos(p); |
|---|
| 1442 | 1443 | |
|---|
| 1443 | 1444 | p->ier |= UART_IER_RLSI | UART_IER_RDI; |
|---|
| 1444 | | - serial8250_set_IER(p, p->ier); |
|---|
| 1445 | + serial_port_out(&p->port, UART_IER, p->ier); |
|---|
| 1445 | 1446 | } |
|---|
| 1446 | 1447 | } |
|---|
| 1447 | 1448 | EXPORT_SYMBOL_GPL(serial8250_em485_stop_tx); |
|---|
| .. | .. |
|---|
| 1688 | 1689 | mctrl_gpio_disable_ms(up->gpios); |
|---|
| 1689 | 1690 | |
|---|
| 1690 | 1691 | up->ier &= ~UART_IER_MSI; |
|---|
| 1691 | | - serial8250_set_IER(up, up->ier); |
|---|
| 1692 | + serial_port_out(port, UART_IER, up->ier); |
|---|
| 1692 | 1693 | } |
|---|
| 1693 | 1694 | |
|---|
| 1694 | 1695 | static void serial8250_enable_ms(struct uart_port *port) |
|---|
| .. | .. |
|---|
| 1704 | 1705 | up->ier |= UART_IER_MSI; |
|---|
| 1705 | 1706 | |
|---|
| 1706 | 1707 | serial8250_rpm_get(up); |
|---|
| 1707 | | - serial8250_set_IER(up, up->ier); |
|---|
| 1708 | + serial_port_out(port, UART_IER, up->ier); |
|---|
| 1708 | 1709 | serial8250_rpm_put(up); |
|---|
| 1709 | 1710 | } |
|---|
| 1710 | 1711 | |
|---|
| .. | .. |
|---|
| 1909 | 1910 | unsigned long flags; |
|---|
| 1910 | 1911 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 1911 | 1912 | #ifndef CONFIG_ARCH_ROCKCHIP |
|---|
| 1913 | + struct tty_port *tport = &port->state->port; |
|---|
| 1912 | 1914 | bool skip_rx = false; |
|---|
| 1913 | 1915 | #endif |
|---|
| 1914 | 1916 | |
|---|
| .. | .. |
|---|
| 1944 | 1946 | skip_rx = true; |
|---|
| 1945 | 1947 | |
|---|
| 1946 | 1948 | if (status & (UART_LSR_DR | UART_LSR_BI) && !skip_rx) { |
|---|
| 1949 | + struct irq_data *d; |
|---|
| 1950 | + |
|---|
| 1951 | + d = irq_get_irq_data(port->irq); |
|---|
| 1952 | + if (d && irqd_is_wakeup_set(d)) |
|---|
| 1953 | + pm_wakeup_event(tport->tty->dev, 0); |
|---|
| 1947 | 1954 | if (!up->dma || handle_rx_dma(up, iir)) |
|---|
| 1948 | 1955 | status = serial8250_rx_chars(up, status); |
|---|
| 1949 | 1956 | } |
|---|
| .. | .. |
|---|
| 2022 | 2029 | static unsigned int serial8250_tx_empty(struct uart_port *port) |
|---|
| 2023 | 2030 | { |
|---|
| 2024 | 2031 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 2032 | + unsigned int result = 0; |
|---|
| 2025 | 2033 | unsigned long flags; |
|---|
| 2026 | 2034 | unsigned int lsr; |
|---|
| 2027 | 2035 | |
|---|
| 2028 | 2036 | serial8250_rpm_get(up); |
|---|
| 2029 | 2037 | |
|---|
| 2030 | 2038 | spin_lock_irqsave(&port->lock, flags); |
|---|
| 2031 | | - lsr = serial_port_in(port, UART_LSR); |
|---|
| 2032 | | - up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
|---|
| 2039 | + if (!serial8250_tx_dma_running(up)) { |
|---|
| 2040 | + lsr = serial_port_in(port, UART_LSR); |
|---|
| 2041 | + up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS; |
|---|
| 2042 | + |
|---|
| 2043 | + if ((lsr & BOTH_EMPTY) == BOTH_EMPTY) |
|---|
| 2044 | + result = TIOCSER_TEMT; |
|---|
| 2045 | + } |
|---|
| 2033 | 2046 | spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 2034 | 2047 | |
|---|
| 2035 | 2048 | serial8250_rpm_put(up); |
|---|
| 2036 | 2049 | |
|---|
| 2037 | | - return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0; |
|---|
| 2050 | + return result; |
|---|
| 2038 | 2051 | } |
|---|
| 2039 | 2052 | |
|---|
| 2040 | 2053 | unsigned int serial8250_do_get_mctrl(struct uart_port *port) |
|---|
| .. | .. |
|---|
| 2171 | 2184 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 2172 | 2185 | |
|---|
| 2173 | 2186 | serial8250_rpm_get(up); |
|---|
| 2174 | | - ier = serial8250_clear_IER(up); |
|---|
| 2187 | + /* |
|---|
| 2188 | + * First save the IER then disable the interrupts |
|---|
| 2189 | + */ |
|---|
| 2190 | + ier = serial_port_in(port, UART_IER); |
|---|
| 2191 | + if (up->capabilities & UART_CAP_UUE) |
|---|
| 2192 | + serial_port_out(port, UART_IER, UART_IER_UUE); |
|---|
| 2193 | + else |
|---|
| 2194 | + serial_port_out(port, UART_IER, 0); |
|---|
| 2175 | 2195 | |
|---|
| 2176 | 2196 | wait_for_xmitr(up, BOTH_EMPTY); |
|---|
| 2177 | 2197 | /* |
|---|
| .. | .. |
|---|
| 2184 | 2204 | * and restore the IER |
|---|
| 2185 | 2205 | */ |
|---|
| 2186 | 2206 | wait_for_xmitr(up, BOTH_EMPTY); |
|---|
| 2187 | | - serial8250_set_IER(up, ier); |
|---|
| 2207 | + serial_port_out(port, UART_IER, ier); |
|---|
| 2188 | 2208 | serial8250_rpm_put(up); |
|---|
| 2189 | 2209 | } |
|---|
| 2190 | 2210 | |
|---|
| .. | .. |
|---|
| 2491 | 2511 | */ |
|---|
| 2492 | 2512 | spin_lock_irqsave(&port->lock, flags); |
|---|
| 2493 | 2513 | up->ier = 0; |
|---|
| 2494 | | - serial8250_set_IER(up, 0); |
|---|
| 2514 | + serial_port_out(port, UART_IER, 0); |
|---|
| 2495 | 2515 | spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 2496 | 2516 | |
|---|
| 2497 | 2517 | synchronize_irq(port->irq); |
|---|
| .. | .. |
|---|
| 2863 | 2883 | if (up->capabilities & UART_CAP_RTOIE) |
|---|
| 2864 | 2884 | up->ier |= UART_IER_RTOIE; |
|---|
| 2865 | 2885 | |
|---|
| 2866 | | - serial8250_set_IER(up, up->ier); |
|---|
| 2886 | + serial_port_out(port, UART_IER, up->ier); |
|---|
| 2867 | 2887 | #endif |
|---|
| 2868 | 2888 | |
|---|
| 2869 | 2889 | if (up->capabilities & UART_CAP_EFR) { |
|---|
| .. | .. |
|---|
| 2923 | 2943 | if (up->capabilities & UART_CAP_RTOIE) |
|---|
| 2924 | 2944 | up->ier |= UART_IER_RTOIE; |
|---|
| 2925 | 2945 | |
|---|
| 2926 | | - serial8250_set_IER(up, up->ier); |
|---|
| 2946 | + serial_port_out(port, UART_IER, up->ier); |
|---|
| 2927 | 2947 | #endif |
|---|
| 2928 | 2948 | |
|---|
| 2929 | 2949 | spin_unlock_irqrestore(&port->lock, flags); |
|---|
| .. | .. |
|---|
| 3319 | 3339 | struct uart_port *port = &up->port; |
|---|
| 3320 | 3340 | |
|---|
| 3321 | 3341 | spin_lock_init(&port->lock); |
|---|
| 3342 | + port->pm = NULL; |
|---|
| 3322 | 3343 | port->ops = &serial8250_pops; |
|---|
| 3323 | 3344 | port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); |
|---|
| 3324 | 3345 | |
|---|
| .. | .. |
|---|
| 3355 | 3376 | |
|---|
| 3356 | 3377 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
|---|
| 3357 | 3378 | |
|---|
| 3358 | | -static void serial8250_console_putchar_locked(struct uart_port *port, int ch) |
|---|
| 3379 | +static void serial8250_console_putchar(struct uart_port *port, int ch) |
|---|
| 3359 | 3380 | { |
|---|
| 3360 | 3381 | struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 3361 | 3382 | |
|---|
| 3362 | 3383 | wait_for_xmitr(up, UART_LSR_THRE); |
|---|
| 3363 | 3384 | serial_port_out(port, UART_TX, ch); |
|---|
| 3364 | | -} |
|---|
| 3365 | | - |
|---|
| 3366 | | -static void serial8250_console_putchar(struct uart_port *port, int ch) |
|---|
| 3367 | | -{ |
|---|
| 3368 | | - struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 3369 | | - unsigned int flags; |
|---|
| 3370 | | - |
|---|
| 3371 | | - wait_for_xmitr(up, UART_LSR_THRE); |
|---|
| 3372 | | - |
|---|
| 3373 | | - console_atomic_lock(&flags); |
|---|
| 3374 | | - serial8250_console_putchar_locked(port, ch); |
|---|
| 3375 | | - console_atomic_unlock(flags); |
|---|
| 3376 | 3385 | } |
|---|
| 3377 | 3386 | |
|---|
| 3378 | 3387 | /* |
|---|
| .. | .. |
|---|
| 3396 | 3405 | serial8250_out_MCR(up, up->mcr | UART_MCR_DTR | UART_MCR_RTS); |
|---|
| 3397 | 3406 | } |
|---|
| 3398 | 3407 | |
|---|
| 3399 | | -void serial8250_console_write_atomic(struct uart_8250_port *up, |
|---|
| 3400 | | - const char *s, unsigned int count) |
|---|
| 3401 | | -{ |
|---|
| 3402 | | - struct uart_port *port = &up->port; |
|---|
| 3403 | | - unsigned int flags; |
|---|
| 3404 | | - unsigned int ier; |
|---|
| 3405 | | - |
|---|
| 3406 | | - console_atomic_lock(&flags); |
|---|
| 3407 | | - |
|---|
| 3408 | | - touch_nmi_watchdog(); |
|---|
| 3409 | | - |
|---|
| 3410 | | - ier = serial8250_clear_IER(up); |
|---|
| 3411 | | - |
|---|
| 3412 | | - if (atomic_fetch_inc(&up->console_printing)) { |
|---|
| 3413 | | - uart_console_write(port, "\n", 1, |
|---|
| 3414 | | - serial8250_console_putchar_locked); |
|---|
| 3415 | | - } |
|---|
| 3416 | | - uart_console_write(port, s, count, serial8250_console_putchar_locked); |
|---|
| 3417 | | - atomic_dec(&up->console_printing); |
|---|
| 3418 | | - |
|---|
| 3419 | | - wait_for_xmitr(up, BOTH_EMPTY); |
|---|
| 3420 | | - serial8250_set_IER(up, ier); |
|---|
| 3421 | | - |
|---|
| 3422 | | - console_atomic_unlock(flags); |
|---|
| 3423 | | -} |
|---|
| 3424 | | - |
|---|
| 3425 | 3408 | /* |
|---|
| 3426 | 3409 | * Print a string to the serial port trying not to disturb |
|---|
| 3427 | 3410 | * any possible real use of the port... |
|---|
| .. | .. |
|---|
| 3438 | 3421 | struct uart_port *port = &up->port; |
|---|
| 3439 | 3422 | unsigned long flags; |
|---|
| 3440 | 3423 | unsigned int ier; |
|---|
| 3424 | + int locked = 1; |
|---|
| 3441 | 3425 | |
|---|
| 3442 | 3426 | touch_nmi_watchdog(); |
|---|
| 3443 | 3427 | |
|---|
| 3444 | | - spin_lock_irqsave(&port->lock, flags); |
|---|
| 3428 | + if (oops_in_progress) |
|---|
| 3429 | + locked = spin_trylock_irqsave(&port->lock, flags); |
|---|
| 3430 | + else |
|---|
| 3431 | + spin_lock_irqsave(&port->lock, flags); |
|---|
| 3445 | 3432 | |
|---|
| 3446 | | - ier = serial8250_clear_IER(up); |
|---|
| 3433 | + /* |
|---|
| 3434 | + * First save the IER then disable the interrupts |
|---|
| 3435 | + */ |
|---|
| 3436 | + ier = serial_port_in(port, UART_IER); |
|---|
| 3437 | + |
|---|
| 3438 | + if (up->capabilities & UART_CAP_UUE) |
|---|
| 3439 | + serial_port_out(port, UART_IER, UART_IER_UUE); |
|---|
| 3440 | + else |
|---|
| 3441 | + serial_port_out(port, UART_IER, 0); |
|---|
| 3447 | 3442 | |
|---|
| 3448 | 3443 | /* check scratch reg to see if port powered off during system sleep */ |
|---|
| 3449 | 3444 | if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) { |
|---|
| .. | .. |
|---|
| 3457 | 3452 | mdelay(port->rs485.delay_rts_before_send); |
|---|
| 3458 | 3453 | } |
|---|
| 3459 | 3454 | |
|---|
| 3460 | | - atomic_inc(&up->console_printing); |
|---|
| 3461 | 3455 | uart_console_write(port, s, count, serial8250_console_putchar); |
|---|
| 3462 | | - atomic_dec(&up->console_printing); |
|---|
| 3463 | 3456 | |
|---|
| 3464 | 3457 | /* |
|---|
| 3465 | 3458 | * Finally, wait for transmitter to become empty |
|---|
| .. | .. |
|---|
| 3472 | 3465 | if (em485->tx_stopped) |
|---|
| 3473 | 3466 | up->rs485_stop_tx(up); |
|---|
| 3474 | 3467 | } |
|---|
| 3475 | | - serial8250_set_IER(up, ier); |
|---|
| 3468 | + |
|---|
| 3469 | + serial_port_out(port, UART_IER, ier); |
|---|
| 3476 | 3470 | |
|---|
| 3477 | 3471 | /* |
|---|
| 3478 | 3472 | * The receive handling will happen properly because the |
|---|
| .. | .. |
|---|
| 3484 | 3478 | if (up->msr_saved_flags) |
|---|
| 3485 | 3479 | serial8250_modem_status(up); |
|---|
| 3486 | 3480 | |
|---|
| 3487 | | - spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 3481 | + if (locked) |
|---|
| 3482 | + spin_unlock_irqrestore(&port->lock, flags); |
|---|
| 3488 | 3483 | } |
|---|
| 3489 | 3484 | |
|---|
| 3490 | 3485 | static unsigned int probe_baud(struct uart_port *port) |
|---|
| .. | .. |
|---|
| 3504 | 3499 | |
|---|
| 3505 | 3500 | int serial8250_console_setup(struct uart_port *port, char *options, bool probe) |
|---|
| 3506 | 3501 | { |
|---|
| 3507 | | - struct uart_8250_port *up = up_to_u8250p(port); |
|---|
| 3508 | 3502 | int baud = 9600; |
|---|
| 3509 | 3503 | int bits = 8; |
|---|
| 3510 | 3504 | int parity = 'n'; |
|---|
| .. | .. |
|---|
| 3513 | 3507 | |
|---|
| 3514 | 3508 | if (!port->iobase && !port->membase) |
|---|
| 3515 | 3509 | return -ENODEV; |
|---|
| 3516 | | - |
|---|
| 3517 | | - atomic_set(&up->console_printing, 0); |
|---|
| 3518 | 3510 | |
|---|
| 3519 | 3511 | if (options) |
|---|
| 3520 | 3512 | uart_parse_options(options, &baud, &parity, &bits, &flow); |
|---|