Lines Matching +full:auto +full:- +full:baud

1 // SPDX-License-Identifier: GPL-2.0+
3 * Base port operations for 8250/16550-type serial ports
255 * tx_loadsz is set to 63-bytes instead of 64-bytes to implement
256 * workaround of errata A-008006 which states that tx_loadsz should
268 .name = "Palmchip BK-3103",
354 offset = offset << p->regshift; in hub6_serial_in()
355 outb(p->hub6 - 1 + offset, p->iobase); in hub6_serial_in()
356 return inb(p->iobase + 1); in hub6_serial_in()
361 offset = offset << p->regshift; in hub6_serial_out()
362 outb(p->hub6 - 1 + offset, p->iobase); in hub6_serial_out()
363 outb(value, p->iobase + 1); in hub6_serial_out()
368 offset = offset << p->regshift; in mem_serial_in()
369 return readb(p->membase + offset); in mem_serial_in()
374 offset = offset << p->regshift; in mem_serial_out()
375 writeb(value, p->membase + offset); in mem_serial_out()
380 offset = offset << p->regshift; in mem16_serial_out()
381 writew(value, p->membase + offset); in mem16_serial_out()
386 offset = offset << p->regshift; in mem16_serial_in()
387 return readw(p->membase + offset); in mem16_serial_in()
392 offset = offset << p->regshift; in mem32_serial_out()
393 writel(value, p->membase + offset); in mem32_serial_out()
398 offset = offset << p->regshift; in mem32_serial_in()
399 return readl(p->membase + offset); in mem32_serial_in()
404 offset = offset << p->regshift; in mem32be_serial_out()
405 iowrite32be(value, p->membase + offset); in mem32be_serial_out()
410 offset = offset << p->regshift; in mem32be_serial_in()
411 return ioread32be(p->membase + offset); in mem32be_serial_in()
416 offset = offset << p->regshift; in io_serial_in()
417 return inb(p->iobase + offset); in io_serial_in()
422 offset = offset << p->regshift; in io_serial_out()
423 outb(value, p->iobase + offset); in io_serial_out()
432 up->dl_read = default_serial_dl_read; in set_io_from_upio()
433 up->dl_write = default_serial_dl_write; in set_io_from_upio()
435 switch (p->iotype) { in set_io_from_upio()
437 p->serial_in = hub6_serial_in; in set_io_from_upio()
438 p->serial_out = hub6_serial_out; in set_io_from_upio()
442 p->serial_in = mem_serial_in; in set_io_from_upio()
443 p->serial_out = mem_serial_out; in set_io_from_upio()
447 p->serial_in = mem16_serial_in; in set_io_from_upio()
448 p->serial_out = mem16_serial_out; in set_io_from_upio()
452 p->serial_in = mem32_serial_in; in set_io_from_upio()
453 p->serial_out = mem32_serial_out; in set_io_from_upio()
457 p->serial_in = mem32be_serial_in; in set_io_from_upio()
458 p->serial_out = mem32be_serial_out; in set_io_from_upio()
462 p->serial_in = io_serial_in; in set_io_from_upio()
463 p->serial_out = io_serial_out; in set_io_from_upio()
467 up->cur_iotype = p->iotype; in set_io_from_upio()
468 p->handle_irq = serial8250_default_handle_irq; in set_io_from_upio()
474 switch (p->iotype) { in serial_port_out_sync()
480 p->serial_out(p, offset, value); in serial_port_out_sync()
481 p->serial_in(p, UART_LCR); /* safe, no side-effects */ in serial_port_out_sync()
484 p->serial_out(p, offset, value); in serial_port_out_sync()
493 if (p->capabilities & UART_CAP_FIFO) { in serial8250_clear_fifos()
507 serial_out(p, UART_FCR, p->fcr); in serial8250_clear_and_reinit_fifos()
513 if (!(p->capabilities & UART_CAP_RPM)) in serial8250_rpm_get()
515 pm_runtime_get_sync(p->port.dev); in serial8250_rpm_get()
521 if (!(p->capabilities & UART_CAP_RPM)) in serial8250_rpm_put()
523 pm_runtime_mark_last_busy(p->port.dev); in serial8250_rpm_put()
524 pm_runtime_put_autosuspend(p->port.dev); in serial8250_rpm_put()
529 * serial8250_em485_init() - put uart_8250_port into rs485 emulating
542 * or from any other callback protected with p->port.lock spinlock.
546 * Return 0 - success, -errno - otherwise
551 lockdep_assert_held_once(&p->port.lock); in serial8250_em485_init()
553 if (p->em485) in serial8250_em485_init()
556 p->em485 = kmalloc(sizeof(struct uart_8250_em485), GFP_ATOMIC); in serial8250_em485_init()
557 if (!p->em485) in serial8250_em485_init()
558 return -ENOMEM; in serial8250_em485_init()
560 hrtimer_init(&p->em485->stop_tx_timer, CLOCK_MONOTONIC, in serial8250_em485_init()
562 hrtimer_init(&p->em485->start_tx_timer, CLOCK_MONOTONIC, in serial8250_em485_init()
564 p->em485->stop_tx_timer.function = &serial8250_em485_handle_stop_tx; in serial8250_em485_init()
565 p->em485->start_tx_timer.function = &serial8250_em485_handle_start_tx; in serial8250_em485_init()
566 p->em485->port = p; in serial8250_em485_init()
567 p->em485->active_timer = NULL; in serial8250_em485_init()
568 p->em485->tx_stopped = true; in serial8250_em485_init()
571 if (p->em485->tx_stopped) in serial8250_em485_init()
572 p->rs485_stop_tx(p); in serial8250_em485_init()
578 * serial8250_em485_destroy() - put uart_8250_port into normal state
586 * or from any other callback protected with p->port.lock spinlock.
592 if (!p->em485) in serial8250_em485_destroy()
595 hrtimer_cancel(&p->em485->start_tx_timer); in serial8250_em485_destroy()
596 hrtimer_cancel(&p->em485->stop_tx_timer); in serial8250_em485_destroy()
598 kfree(p->em485); in serial8250_em485_destroy()
599 p->em485 = NULL; in serial8250_em485_destroy()
612 * serial8250_em485_config() - generic ->rs485_config() callback
627 if (!!(rs485->flags & SER_RS485_RTS_ON_SEND) == in serial8250_em485_config()
628 !!(rs485->flags & SER_RS485_RTS_AFTER_SEND)) { in serial8250_em485_config()
629 rs485->flags |= SER_RS485_RTS_ON_SEND; in serial8250_em485_config()
630 rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; in serial8250_em485_config()
637 if (rs485->flags & SER_RS485_ENABLED) in serial8250_em485_config()
654 if (!(p->capabilities & UART_CAP_RPM)) in serial8250_rpm_get_tx()
657 rpm_active = xchg(&p->rpm_tx_active, 1); in serial8250_rpm_get_tx()
660 pm_runtime_get_sync(p->port.dev); in serial8250_rpm_get_tx()
668 if (!(p->capabilities & UART_CAP_RPM)) in serial8250_rpm_put_tx()
671 rpm_active = xchg(&p->rpm_tx_active, 0); in serial8250_rpm_put_tx()
674 pm_runtime_mark_last_busy(p->port.dev); in serial8250_rpm_put_tx()
675 pm_runtime_put_autosuspend(p->port.dev); in serial8250_rpm_put_tx()
690 if (p->capabilities & UART_CAP_SLEEP) { in serial8250_set_sleep()
692 spin_lock_irq(&p->port.lock); in serial8250_set_sleep()
693 if (p->capabilities & UART_CAP_EFR) { in serial8250_set_sleep()
701 if (p->capabilities & UART_CAP_EFR) { in serial8250_set_sleep()
706 spin_unlock_irq(&p->port.lock); in serial8250_set_sleep()
714 if (up->capabilities & UART_CAP_UUE) in serial8250_clear_IER()
740 up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16; in __enable_rsa()
747 if (up->port.type == PORT_RSA) { in enable_rsa()
748 if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) { in enable_rsa()
749 spin_lock_irq(&up->port.lock); in enable_rsa()
751 spin_unlock_irq(&up->port.lock); in enable_rsa()
753 if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) in enable_rsa()
769 if (up->port.type == PORT_RSA && in disable_rsa()
770 up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { in disable_rsa()
771 spin_lock_irq(&up->port.lock); in disable_rsa()
783 up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16; in disable_rsa()
784 spin_unlock_irq(&up->port.lock); in disable_rsa()
812 mdelay(20);/* FIXME - schedule_timeout */ in size_fifo()
826 * Read UART ID using the divisor method - set DLL and DLM to zero
864 up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; in autoconfig_has_efr()
869 * If we have to do this here because some non-National in autoconfig_has_efr()
883 up->acr = 0; in autoconfig_has_efr()
896 up->port.type = PORT_16C950; in autoconfig_has_efr()
900 * chip which causes it to seriously miscalculate baud rates in autoconfig_has_efr()
904 up->bugs |= UART_BUG_QUOT; in autoconfig_has_efr()
912 * 0x10 - XR16C850 and the DLL contains the chip revision. in autoconfig_has_efr()
913 * 0x12 - XR16C2850. in autoconfig_has_efr()
914 * 0x14 - XR16C854. in autoconfig_has_efr()
921 up->port.type = PORT_16850; in autoconfig_has_efr()
932 * I've had problems doing this in the past. -TYT in autoconfig_has_efr()
935 up->port.type = PORT_16654; in autoconfig_has_efr()
937 up->port.type = PORT_16650V2; in autoconfig_has_efr()
942 * this category - the original 8250 and the 16450. The
949 up->port.type = PORT_8250; in autoconfig_8250()
959 up->port.type = PORT_16450; in autoconfig_8250()
967 * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html in broken_efr()
987 lockdep_assert_held_once(&up->port.lock); in autoconfig_16550a()
989 up->port.type = PORT_16550A; in autoconfig_16550a()
990 up->capabilities |= UART_CAP_FIFO; in autoconfig_16550a()
993 !(up->port.flags & UPF_FULL_PROBE)) in autoconfig_16550a()
1005 up->port.type = PORT_16650; in autoconfig_16550a()
1006 up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP; in autoconfig_16550a()
1017 up->port.type = PORT_16550A_FSL64; in autoconfig_16550a()
1041 * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2 in autoconfig_16550a()
1069 up->port.uartclk = 921600*16; in autoconfig_16550a()
1070 up->port.type = PORT_NS16550A; in autoconfig_16550a()
1071 up->capabilities |= UART_NATSEMI; in autoconfig_16550a()
1098 up->port.type = PORT_16750; in autoconfig_16550a()
1099 up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP; in autoconfig_16550a()
1125 up->port.type = PORT_XSCALE; in autoconfig_16550a()
1126 up->capabilities |= UART_CAP_UUE | UART_CAP_RTOIE; in autoconfig_16550a()
1142 if (up->port.type == PORT_16550A && size_fifo(up) == 64) { in autoconfig_16550a()
1143 up->port.type = PORT_U6_16550A; in autoconfig_16550a()
1144 up->capabilities |= UART_CAP_AFE; in autoconfig_16550a()
1159 struct uart_port *port = &up->port; in autoconfig()
1163 if (!port->iobase && !port->mapbase && !port->membase) in autoconfig()
1167 port->name, port->iobase, port->membase); in autoconfig()
1170 * We really do need global IRQs disabled here - we're going to in autoconfig()
1175 spin_lock_irqsave(&port->lock, flags); in autoconfig()
1177 up->capabilities = 0; in autoconfig()
1178 up->bugs = 0; in autoconfig()
1180 if (!(port->flags & UPF_BUGGY_UART)) { in autoconfig()
1187 * assumption is that 0x80 is a non-existent port; in autoconfig()
1214 spin_unlock_irqrestore(&port->lock, flags); in autoconfig()
1231 * that conflicts with COM 1-4 --- we hope! in autoconfig()
1233 if (!(port->flags & UPF_SKIP_TEST)) { in autoconfig()
1238 spin_unlock_irqrestore(&port->lock, flags); in autoconfig()
1265 port->type = PORT_16550; in autoconfig()
1271 port->type = PORT_UNKNOWN; in autoconfig()
1279 if (port->type == PORT_16550A && up->probe & UART_PROBE_RSA && in autoconfig()
1281 port->type = PORT_RSA; in autoconfig()
1286 port->fifosize = uart_config[up->port.type].fifo_size; in autoconfig()
1287 old_capabilities = up->capabilities; in autoconfig()
1288 up->capabilities = uart_config[port->type].flags; in autoconfig()
1289 up->tx_loadsz = uart_config[port->type].tx_loadsz; in autoconfig()
1291 if (port->type == PORT_UNKNOWN) in autoconfig()
1298 if (port->type == PORT_RSA) in autoconfig()
1307 spin_unlock_irqrestore(&port->lock, flags); in autoconfig()
1312 if (port->type == PORT_16550A && port->iotype == UPIO_PORT) in autoconfig()
1315 if (up->capabilities != old_capabilities) { in autoconfig()
1316 dev_warn(port->dev, "detected caps %08x should be %08x\n", in autoconfig()
1317 old_capabilities, up->capabilities); in autoconfig()
1321 DEBUG_AUTOCONF("type=%s\n", uart_config[port->type].name); in autoconfig()
1326 struct uart_port *port = &up->port; in autoconfig_irq()
1333 if (port->flags & UPF_FOURPORT) { in autoconfig_irq()
1334 ICP = (port->iobase & 0xfe0) | 0x1f; in autoconfig_irq()
1344 spin_lock_irq(&port->lock); in autoconfig_irq()
1346 spin_unlock_irq(&port->lock); in autoconfig_irq()
1352 if (port->flags & UPF_FOURPORT) { in autoconfig_irq()
1359 spin_lock_irq(&port->lock); in autoconfig_irq()
1361 spin_unlock_irq(&port->lock); in autoconfig_irq()
1372 spin_lock_irq(&port->lock); in autoconfig_irq()
1374 spin_unlock_irq(&port->lock); in autoconfig_irq()
1376 if (port->flags & UPF_FOURPORT) in autoconfig_irq()
1379 port->irq = (irq > 0) ? irq : 0; in autoconfig_irq()
1387 lockdep_assert_held_once(&port->lock); in serial8250_stop_rx()
1391 up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); in serial8250_stop_rx()
1392 up->port.read_status_mask &= ~UART_LSR_DR; in serial8250_stop_rx()
1393 serial_port_out(port, UART_IER, up->ier); in serial8250_stop_rx()
1399 * serial8250_em485_stop_tx() - generic ->rs485_stop_tx() callback
1409 lockdep_assert_held_once(&p->port.lock); in serial8250_em485_stop_tx()
1411 if (p->port.rs485.flags & SER_RS485_RTS_AFTER_SEND) in serial8250_em485_stop_tx()
1419 * received during the half-duplex transmission. in serial8250_em485_stop_tx()
1422 if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX)) { in serial8250_em485_stop_tx()
1425 p->ier |= UART_IER_RLSI | UART_IER_RDI; in serial8250_em485_stop_tx()
1426 serial_port_out(&p->port, UART_IER, p->ier); in serial8250_em485_stop_tx()
1435 struct uart_8250_port *p = em485->port; in serial8250_em485_handle_stop_tx()
1439 spin_lock_irqsave(&p->port.lock, flags); in serial8250_em485_handle_stop_tx()
1440 if (em485->active_timer == &em485->stop_tx_timer) { in serial8250_em485_handle_stop_tx()
1441 p->rs485_stop_tx(p); in serial8250_em485_handle_stop_tx()
1442 em485->active_timer = NULL; in serial8250_em485_handle_stop_tx()
1443 em485->tx_stopped = true; in serial8250_em485_handle_stop_tx()
1445 spin_unlock_irqrestore(&p->port.lock, flags); in serial8250_em485_handle_stop_tx()
1458 struct uart_8250_em485 *em485 = p->em485; in __stop_tx_rs485()
1461 lockdep_assert_held_once(&p->port.lock); in __stop_tx_rs485()
1463 stop_delay += (u64)p->port.rs485.delay_rts_after_send * NSEC_PER_MSEC; in __stop_tx_rs485()
1470 em485->active_timer = &em485->stop_tx_timer; in __stop_tx_rs485()
1471 hrtimer_start(&em485->stop_tx_timer, ns_to_ktime(stop_delay), HRTIMER_MODE_REL); in __stop_tx_rs485()
1473 p->rs485_stop_tx(p); in __stop_tx_rs485()
1474 em485->active_timer = NULL; in __stop_tx_rs485()
1475 em485->tx_stopped = true; in __stop_tx_rs485()
1481 struct uart_8250_em485 *em485 = p->em485; in __stop_tx()
1498 if (!(p->capabilities & UART_CAP_NOTEMT)) in __stop_tx()
1507 stop_delay = p->port.frame_time + DIV_ROUND_UP(p->port.frame_time, 7); in __stop_tx()
1527 if (port->type == PORT_16C950) { in serial8250_stop_tx()
1528 up->acr |= UART_ACR_TXDIS; in serial8250_stop_tx()
1529 serial_icr_write(up, UART_ACR, up->acr); in serial8250_stop_tx()
1538 if (up->dma && !up->dma->tx_dma(up)) in __start_tx()
1542 if (up->bugs & UART_BUG_TXEN) { in __start_tx()
1551 * Re-enable the transmitter if we disabled it. in __start_tx()
1553 if (port->type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { in __start_tx()
1554 up->acr &= ~UART_ACR_TXDIS; in __start_tx()
1555 serial_icr_write(up, UART_ACR, up->acr); in __start_tx()
1560 * serial8250_em485_start_tx() - generic ->rs485_start_tx() callback
1573 if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) in serial8250_em485_start_tx()
1574 serial8250_stop_rx(&up->port); in serial8250_em485_start_tx()
1576 if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) in serial8250_em485_start_tx()
1588 struct uart_8250_em485 *em485 = up->em485; in start_tx_rs485()
1592 * em485->active_timer != &em485->stop_tx_timer, it might happen that in start_tx_rs485()
1594 * chars is send and em485->active_timer == &em485->stop_tx_timer again. in start_tx_rs485()
1597 * em485->active_timer when &em485->stop_tx_timer is armed again. in start_tx_rs485()
1599 if (em485->active_timer == &em485->stop_tx_timer) in start_tx_rs485()
1600 hrtimer_try_to_cancel(&em485->stop_tx_timer); in start_tx_rs485()
1602 em485->active_timer = NULL; in start_tx_rs485()
1604 if (em485->tx_stopped) { in start_tx_rs485()
1605 em485->tx_stopped = false; in start_tx_rs485()
1607 up->rs485_start_tx(up); in start_tx_rs485()
1609 if (up->port.rs485.delay_rts_before_send > 0) { in start_tx_rs485()
1610 em485->active_timer = &em485->start_tx_timer; in start_tx_rs485()
1611 start_hrtimer_ms(&em485->start_tx_timer, in start_tx_rs485()
1612 up->port.rs485.delay_rts_before_send); in start_tx_rs485()
1624 struct uart_8250_port *p = em485->port; in serial8250_em485_handle_start_tx()
1627 spin_lock_irqsave(&p->port.lock, flags); in serial8250_em485_handle_start_tx()
1628 if (em485->active_timer == &em485->start_tx_timer) { in serial8250_em485_handle_start_tx()
1629 __start_tx(&p->port); in serial8250_em485_handle_start_tx()
1630 em485->active_timer = NULL; in serial8250_em485_handle_start_tx()
1632 spin_unlock_irqrestore(&p->port.lock, flags); in serial8250_em485_handle_start_tx()
1640 struct uart_8250_em485 *em485 = up->em485; in serial8250_start_tx()
1643 lockdep_assert_held_once(&port->lock); in serial8250_start_tx()
1645 if (!port->x_char && uart_circ_empty(&port->state->xmit)) in serial8250_start_tx()
1651 if ((em485->active_timer == &em485->start_tx_timer) || in serial8250_start_tx()
1660 port->throttle(port); in serial8250_throttle()
1665 port->unthrottle(port); in serial8250_unthrottle()
1673 lockdep_assert_held_once(&port->lock); in serial8250_disable_ms()
1676 if (up->bugs & UART_BUG_NOMSR) in serial8250_disable_ms()
1679 mctrl_gpio_disable_ms(up->gpios); in serial8250_disable_ms()
1681 up->ier &= ~UART_IER_MSI; in serial8250_disable_ms()
1682 serial_port_out(port, UART_IER, up->ier); in serial8250_disable_ms()
1690 lockdep_assert_held_once(&port->lock); in serial8250_enable_ms()
1693 if (up->bugs & UART_BUG_NOMSR) in serial8250_enable_ms()
1696 mctrl_gpio_enable_ms(up->gpios); in serial8250_enable_ms()
1698 up->ier |= UART_IER_MSI; in serial8250_enable_ms()
1701 serial_port_out(port, UART_IER, up->ier); in serial8250_enable_ms()
1707 struct uart_port *port = &up->port; in serial8250_read_char()
1722 port->icount.rx++; in serial8250_read_char()
1724 lsr |= up->lsr_saved_flags; in serial8250_read_char()
1725 up->lsr_saved_flags = 0; in serial8250_read_char()
1730 port->icount.brk++; in serial8250_read_char()
1740 port->icount.parity++; in serial8250_read_char()
1742 port->icount.frame++; in serial8250_read_char()
1744 port->icount.overrun++; in serial8250_read_char()
1749 lsr &= port->read_status_mask; in serial8250_read_char()
1752 dev_dbg(port->dev, "handling break\n"); in serial8250_read_char()
1767 * serial8250_rx_chars - Read characters. The first LSR value must be passed in.
1769 * Returns LSR bits. The caller should rely only on non-Rx related LSR bits
1775 struct uart_port *port = &up->port; in serial8250_rx_chars()
1780 if (--max_count == 0) in serial8250_rx_chars()
1785 tty_flip_buffer_push(&port->state->port); in serial8250_rx_chars()
1792 struct uart_port *port = &up->port; in serial8250_tx_chars()
1793 struct circ_buf *xmit = &port->state->xmit; in serial8250_tx_chars()
1796 if (port->x_char) { in serial8250_tx_chars()
1809 count = up->tx_loadsz; in serial8250_tx_chars()
1811 serial_out(up, UART_TX, xmit->buf[xmit->tail]); in serial8250_tx_chars()
1812 if (up->bugs & UART_BUG_TXRACE) { in serial8250_tx_chars()
1818 * Delay back-to-back writes by a read cycle to avoid in serial8250_tx_chars()
1820 * side-effects and discard the result. in serial8250_tx_chars()
1827 if ((up->capabilities & UART_CAP_HFIFO) && in serial8250_tx_chars()
1830 /* The BCM2835 MINI UART THRE bit is really a not-full bit. */ in serial8250_tx_chars()
1831 if ((up->capabilities & UART_CAP_MINI) && in serial8250_tx_chars()
1834 } while (--count > 0); in serial8250_tx_chars()
1844 if (uart_circ_empty(xmit) && !(up->capabilities & UART_CAP_RPM)) in serial8250_tx_chars()
1852 struct uart_port *port = &up->port; in serial8250_modem_status()
1855 status |= up->msr_saved_flags; in serial8250_modem_status()
1856 up->msr_saved_flags = 0; in serial8250_modem_status()
1857 if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI && in serial8250_modem_status()
1858 port->state != NULL) { in serial8250_modem_status()
1860 port->icount.rng++; in serial8250_modem_status()
1862 port->icount.dsr++; in serial8250_modem_status()
1868 wake_up_interruptible(&port->state->port.delta_msr_wait); in serial8250_modem_status()
1890 if (!up->dma->rx_running) in handle_rx_dma()
1898 return up->dma->rx_dma(up); in handle_rx_dma()
1907 struct tty_port *tport = &port->state->port; in serial8250_handle_irq()
1915 spin_lock_irqsave(&port->lock, flags); in serial8250_handle_irq()
1922 * overflow. Not servicing, RX FIFO would trigger auto HW flow in serial8250_handle_irq()
1924 * halting RX. This only works when auto HW flow control is in serial8250_handle_irq()
1928 (port->status & (UPSTAT_AUTOCTS | UPSTAT_AUTORTS)) && in serial8250_handle_irq()
1929 !(port->read_status_mask & UART_LSR_DR)) in serial8250_handle_irq()
1935 d = irq_get_irq_data(port->irq); in serial8250_handle_irq()
1937 pm_wakeup_event(tport->tty->dev, 0); in serial8250_handle_irq()
1938 if (!up->dma || handle_rx_dma(up, iir)) in serial8250_handle_irq()
1942 if ((status & UART_LSR_THRE) && (up->ier & UART_IER_THRI)) { in serial8250_handle_irq()
1943 if (!up->dma || up->dma->tx_err) in serial8250_handle_irq()
1945 else if (!up->dma->tx_running) in serial8250_handle_irq()
1985 spin_lock_irqsave(&port->lock, flags); in serial8250_tx_threshold_handle_irq()
1987 spin_unlock_irqrestore(&port->lock, flags); in serial8250_tx_threshold_handle_irq()
2002 spin_lock_irqsave(&port->lock, flags); in serial8250_tx_empty()
2005 spin_unlock_irqrestore(&port->lock, flags); in serial8250_tx_empty()
2023 if (up->gpios) in serial8250_do_get_mctrl()
2024 return mctrl_gpio_get(up->gpios, &val); in serial8250_do_get_mctrl()
2032 if (port->get_mctrl) in serial8250_get_mctrl()
2033 return port->get_mctrl(port); in serial8250_get_mctrl()
2044 mcr |= up->mcr; in serial8250_do_set_mctrl()
2052 if (port->rs485.flags & SER_RS485_ENABLED) in serial8250_set_mctrl()
2055 if (port->set_mctrl) in serial8250_set_mctrl()
2056 port->set_mctrl(port, mctrl); in serial8250_set_mctrl()
2067 spin_lock_irqsave(&port->lock, flags); in serial8250_break_ctl()
2068 if (break_state == -1) in serial8250_break_ctl()
2069 up->lcr |= UART_LCR_SBC; in serial8250_break_ctl()
2071 up->lcr &= ~UART_LCR_SBC; in serial8250_break_ctl()
2072 serial_port_out(port, UART_LCR, up->lcr); in serial8250_break_ctl()
2073 spin_unlock_irqrestore(&port->lock, flags); in serial8250_break_ctl()
2087 if (--tmout == 0) in wait_for_lsr()
2104 if (up->port.flags & UPF_CONS_FLOW) { in wait_for_xmitr()
2105 for (tmout = 1000000; tmout; tmout--) { in wait_for_xmitr()
2107 up->msr_saved_flags |= msr & MSR_SAVE_FLAGS; in wait_for_xmitr()
2190 if (!port->fifosize) in serial8250_do_startup()
2191 port->fifosize = uart_config[port->type].fifo_size; in serial8250_do_startup()
2192 if (!up->tx_loadsz) in serial8250_do_startup()
2193 up->tx_loadsz = uart_config[port->type].tx_loadsz; in serial8250_do_startup()
2194 if (!up->capabilities) in serial8250_do_startup()
2195 up->capabilities = uart_config[port->type].flags; in serial8250_do_startup()
2196 up->mcr = 0; in serial8250_do_startup()
2198 if (port->iotype != up->cur_iotype) in serial8250_do_startup()
2202 if (port->type == PORT_16C950) { in serial8250_do_startup()
2208 spin_lock_irqsave(&port->lock, flags); in serial8250_do_startup()
2209 up->acr = 0; in serial8250_do_startup()
2218 spin_unlock_irqrestore(&port->lock, flags); in serial8250_do_startup()
2221 if (port->type == PORT_DA830) { in serial8250_do_startup()
2227 spin_lock_irqsave(&port->lock, flags); in serial8250_do_startup()
2230 spin_unlock_irqrestore(&port->lock, flags); in serial8250_do_startup()
2240 if (port->type == PORT_NPCM) { in serial8250_do_startup()
2276 if (!(port->flags & UPF_BUGGY_UART) && in serial8250_do_startup()
2278 dev_info_ratelimited(port->dev, "LSR safety check engaged!\n"); in serial8250_do_startup()
2279 retval = -ENODEV; in serial8250_do_startup()
2286 if (port->type == PORT_16850) { in serial8250_do_startup()
2305 if (((port->type == PORT_ALTR_16550_F32) || in serial8250_do_startup()
2306 (port->type == PORT_ALTR_16550_F64) || in serial8250_do_startup()
2307 (port->type == PORT_ALTR_16550_F128)) && (port->fifosize > 1)) { in serial8250_do_startup()
2308 /* Bounds checking of TX threshold (valid 0 to fifosize-2) */ in serial8250_do_startup()
2309 if ((up->tx_loadsz < 2) || (up->tx_loadsz > port->fifosize)) { in serial8250_do_startup()
2310 dev_err(port->dev, "TX FIFO Threshold errors, skipping\n"); in serial8250_do_startup()
2315 port->fifosize - up->tx_loadsz); in serial8250_do_startup()
2316 port->handle_irq = serial8250_tx_threshold_handle_irq; in serial8250_do_startup()
2321 if (port->irq && (up->port.flags & UPF_SHARE_IRQ)) in serial8250_do_startup()
2322 up->port.irqflags |= IRQF_SHARED; in serial8250_do_startup()
2324 retval = up->ops->setup_irq(up); in serial8250_do_startup()
2328 if (port->irq && !(up->port.flags & UPF_NO_THRE_TEST)) { in serial8250_do_startup()
2331 if (port->irqflags & IRQF_SHARED) in serial8250_do_startup()
2332 disable_irq_nosync(port->irq); in serial8250_do_startup()
2344 spin_lock_irqsave(&port->lock, flags); in serial8250_do_startup()
2352 udelay(1); /* allow a working UART time to re-assert THRE */ in serial8250_do_startup()
2356 spin_unlock_irqrestore(&port->lock, flags); in serial8250_do_startup()
2358 if (port->irqflags & IRQF_SHARED) in serial8250_do_startup()
2359 enable_irq(port->irq); in serial8250_do_startup()
2367 up->port.flags & UPF_BUG_THRE) { in serial8250_do_startup()
2368 up->bugs |= UART_BUG_THRE; in serial8250_do_startup()
2372 up->ops->setup_timer(up); in serial8250_do_startup()
2379 spin_lock_irqsave(&port->lock, flags); in serial8250_do_startup()
2380 if (up->port.flags & UPF_FOURPORT) { in serial8250_do_startup()
2381 if (!up->port.irq) in serial8250_do_startup()
2382 up->port.mctrl |= TIOCM_OUT1; in serial8250_do_startup()
2387 if (port->irq) in serial8250_do_startup()
2388 up->port.mctrl |= TIOCM_OUT2; in serial8250_do_startup()
2390 serial8250_set_mctrl(port, port->mctrl); in serial8250_do_startup()
2403 if (up->port.quirks & UPQ_NO_TXEN_TEST) in serial8250_do_startup()
2416 if (!(up->bugs & UART_BUG_TXEN)) { in serial8250_do_startup()
2417 up->bugs |= UART_BUG_TXEN; in serial8250_do_startup()
2418 dev_dbg(port->dev, "enabling bad tx status workarounds\n"); in serial8250_do_startup()
2421 up->bugs &= ~UART_BUG_TXEN; in serial8250_do_startup()
2425 spin_unlock_irqrestore(&port->lock, flags); in serial8250_do_startup()
2436 up->lsr_saved_flags = 0; in serial8250_do_startup()
2437 up->msr_saved_flags = 0; in serial8250_do_startup()
2442 if (up->dma) { in serial8250_do_startup()
2450 dev_warn_ratelimited(port->dev, "%s\n", msg); in serial8250_do_startup()
2451 up->dma = NULL; in serial8250_do_startup()
2457 * enable until after the FIFOs are enabled; otherwise, an already- in serial8250_do_startup()
2460 up->ier = UART_IER_RLSI | UART_IER_RDI; in serial8250_do_startup()
2462 if (port->flags & UPF_FOURPORT) { in serial8250_do_startup()
2467 icp = (port->iobase & 0xfe0) | 0x01f; in serial8250_do_startup()
2480 if (port->startup) in serial8250_startup()
2481 return port->startup(port); in serial8250_startup()
2496 spin_lock_irqsave(&port->lock, flags); in serial8250_do_shutdown()
2497 up->ier = 0; in serial8250_do_shutdown()
2499 spin_unlock_irqrestore(&port->lock, flags); in serial8250_do_shutdown()
2501 synchronize_irq(port->irq); in serial8250_do_shutdown()
2503 if (up->dma) in serial8250_do_shutdown()
2506 spin_lock_irqsave(&port->lock, flags); in serial8250_do_shutdown()
2507 if (port->flags & UPF_FOURPORT) { in serial8250_do_shutdown()
2509 inb((port->iobase & 0xfe0) | 0x1f); in serial8250_do_shutdown()
2510 port->mctrl |= TIOCM_OUT1; in serial8250_do_shutdown()
2512 port->mctrl &= ~TIOCM_OUT2; in serial8250_do_shutdown()
2514 serial8250_set_mctrl(port, port->mctrl); in serial8250_do_shutdown()
2515 spin_unlock_irqrestore(&port->lock, flags); in serial8250_do_shutdown()
2538 up->ops->release_irq(up); in serial8250_do_shutdown()
2544 if (port->shutdown) in serial8250_shutdown()
2545 port->shutdown(port); in serial8250_shutdown()
2552 unsigned int baud) in npcm_get_divisor() argument
2554 struct uart_port *port = &up->port; in npcm_get_divisor()
2556 return DIV_ROUND_CLOSEST(port->uartclk, 16 * baud + 2) - 2; in npcm_get_divisor()
2560 unsigned int baud, in serial8250_do_get_divisor() argument
2563 upf_t magic_multiplier = port->flags & UPF_MAGIC_MULTIPLIER; in serial8250_do_get_divisor()
2568 * Handle magic divisors for baud rates above baud_base on SMSC in serial8250_do_get_divisor()
2571 * magic divisors actually reprogram the baud rate generator's in serial8250_do_get_divisor()
2576 * for the extra baud rates of 460800bps and 230400bps rather in serial8250_do_get_divisor()
2583 * the base frequency is divided by 4 for use by the Baud Rate in serial8250_do_get_divisor()
2585 * the divisor produces the baud rate of 115200bps. Conversely, in serial8250_do_get_divisor()
2586 * if set to 1 and high-speed operation has been enabled with the in serial8250_do_get_divisor()
2588 * then the base frequency is supplied directly to the Baud Rate in serial8250_do_get_divisor()
2590 * 0x8004, etc. the respective baud rates produced are 460800bps, in serial8250_do_get_divisor()
2594 * the baud base and therefore 32767 is the maximum divisor value in serial8250_do_get_divisor()
2596 * Baud Rate Generator is capable of dividing the internal PLL in serial8250_do_get_divisor()
2599 if (magic_multiplier && baud >= port->uartclk / 6) in serial8250_do_get_divisor()
2601 else if (magic_multiplier && baud >= port->uartclk / 12) in serial8250_do_get_divisor()
2603 else if (up->port.type == PORT_NPCM) in serial8250_do_get_divisor()
2604 quot = npcm_get_divisor(up, baud); in serial8250_do_get_divisor()
2606 quot = uart_get_divisor(port, baud); in serial8250_do_get_divisor()
2611 if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0) in serial8250_do_get_divisor()
2618 unsigned int baud, in serial8250_get_divisor() argument
2621 if (port->get_divisor) in serial8250_get_divisor()
2622 return port->get_divisor(port, baud, frac); in serial8250_get_divisor()
2624 return serial8250_do_get_divisor(port, baud, frac); in serial8250_get_divisor()
2646 void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud, in serial8250_do_set_divisor() argument
2651 /* Workaround to enable 115200 baud on OMAP1510 internal ports */ in serial8250_do_set_divisor()
2653 if (baud == 115200) { in serial8250_do_set_divisor()
2664 if (up->capabilities & UART_NATSEMI) in serial8250_do_set_divisor()
2667 serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB); in serial8250_do_set_divisor()
2673 static void serial8250_set_divisor(struct uart_port *port, unsigned int baud, in serial8250_set_divisor() argument
2676 if (port->set_divisor) in serial8250_set_divisor()
2677 port->set_divisor(port, baud, quot, quot_frac); in serial8250_set_divisor()
2679 serial8250_do_set_divisor(port, baud, quot, quot_frac); in serial8250_set_divisor()
2686 unsigned int tolerance = port->uartclk / 100; in serial8250_get_baud_rate()
2691 * Handle magic divisors for baud rates above baud_base on SMSC in serial8250_get_baud_rate()
2695 if (port->flags & UPF_MAGIC_MULTIPLIER) { in serial8250_get_baud_rate()
2696 min = port->uartclk / 16 / UART_DIV_MAX >> 1; in serial8250_get_baud_rate()
2697 max = (port->uartclk + tolerance) / 4; in serial8250_get_baud_rate()
2699 min = port->uartclk / 16 / UART_DIV_MAX; in serial8250_get_baud_rate()
2700 max = (port->uartclk + tolerance) / 16; in serial8250_get_baud_rate()
2706 * slower than nominal still match standard baud rates without in serial8250_get_baud_rate()
2720 struct tty_port *tport = &port->state->port; in serial8250_update_uartclk()
2721 unsigned int baud, quot, frac = 0; in serial8250_update_uartclk() local
2728 mutex_lock(&tport->mutex); in serial8250_update_uartclk()
2729 port->uartclk = uartclk; in serial8250_update_uartclk()
2730 mutex_unlock(&tport->mutex); in serial8250_update_uartclk()
2734 down_write(&tty->termios_rwsem); in serial8250_update_uartclk()
2735 mutex_lock(&tport->mutex); in serial8250_update_uartclk()
2737 if (port->uartclk == uartclk) in serial8250_update_uartclk()
2740 port->uartclk = uartclk; in serial8250_update_uartclk()
2745 termios = &tty->termios; in serial8250_update_uartclk()
2747 baud = serial8250_get_baud_rate(port, termios, NULL); in serial8250_update_uartclk()
2748 quot = serial8250_get_divisor(port, baud, &frac); in serial8250_update_uartclk()
2751 spin_lock_irqsave(&port->lock, flags); in serial8250_update_uartclk()
2753 uart_update_timeout(port, termios->c_cflag, baud); in serial8250_update_uartclk()
2755 serial8250_set_divisor(port, baud, quot, frac); in serial8250_update_uartclk()
2756 serial_port_out(port, UART_LCR, up->lcr); in serial8250_update_uartclk()
2758 spin_unlock_irqrestore(&port->lock, flags); in serial8250_update_uartclk()
2762 mutex_unlock(&tport->mutex); in serial8250_update_uartclk()
2763 up_write(&tty->termios_rwsem); in serial8250_update_uartclk()
2775 unsigned int baud, quot, frac = 0; in serial8250_do_set_termios() local
2777 if (up->capabilities & UART_CAP_MINI) { in serial8250_do_set_termios()
2778 termios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CMSPAR); in serial8250_do_set_termios()
2779 if ((termios->c_cflag & CSIZE) == CS5 || in serial8250_do_set_termios()
2780 (termios->c_cflag & CSIZE) == CS6) in serial8250_do_set_termios()
2781 termios->c_cflag = (termios->c_cflag & ~CSIZE) | CS7; in serial8250_do_set_termios()
2783 cval = serial8250_compute_lcr(up, termios->c_cflag); in serial8250_do_set_termios()
2785 baud = serial8250_get_baud_rate(port, termios, old); in serial8250_do_set_termios()
2786 quot = serial8250_get_divisor(port, baud, &frac); in serial8250_do_set_termios()
2795 spin_lock_irqsave(&port->lock, flags); in serial8250_do_set_termios()
2797 up->lcr = cval; /* Save computed LCR */ in serial8250_do_set_termios()
2799 if (up->capabilities & UART_CAP_FIFO && port->fifosize > 1) { in serial8250_do_set_termios()
2800 if (baud < 2400 && !up->dma) { in serial8250_do_set_termios()
2801 up->fcr &= ~UART_FCR_TRIGGER_MASK; in serial8250_do_set_termios()
2802 up->fcr |= UART_FCR_TRIGGER_1; in serial8250_do_set_termios()
2807 * MCR-based auto flow control. When AFE is enabled, RTS will be in serial8250_do_set_termios()
2811 if (up->capabilities & UART_CAP_AFE) { in serial8250_do_set_termios()
2812 up->mcr &= ~UART_MCR_AFE; in serial8250_do_set_termios()
2813 if (termios->c_cflag & CRTSCTS) in serial8250_do_set_termios()
2814 up->mcr |= UART_MCR_AFE; in serial8250_do_set_termios()
2818 * Update the per-port timeout. in serial8250_do_set_termios()
2820 uart_update_timeout(port, termios->c_cflag, baud); in serial8250_do_set_termios()
2822 port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; in serial8250_do_set_termios()
2823 if (termios->c_iflag & INPCK) in serial8250_do_set_termios()
2824 port->read_status_mask |= UART_LSR_FE | UART_LSR_PE; in serial8250_do_set_termios()
2825 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) in serial8250_do_set_termios()
2826 port->read_status_mask |= UART_LSR_BI; in serial8250_do_set_termios()
2831 port->ignore_status_mask = 0; in serial8250_do_set_termios()
2832 if (termios->c_iflag & IGNPAR) in serial8250_do_set_termios()
2833 port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; in serial8250_do_set_termios()
2834 if (termios->c_iflag & IGNBRK) { in serial8250_do_set_termios()
2835 port->ignore_status_mask |= UART_LSR_BI; in serial8250_do_set_termios()
2840 if (termios->c_iflag & IGNPAR) in serial8250_do_set_termios()
2841 port->ignore_status_mask |= UART_LSR_OE; in serial8250_do_set_termios()
2847 if ((termios->c_cflag & CREAD) == 0) in serial8250_do_set_termios()
2848 port->ignore_status_mask |= UART_LSR_DR; in serial8250_do_set_termios()
2853 up->ier &= ~UART_IER_MSI; in serial8250_do_set_termios()
2854 if (!(up->bugs & UART_BUG_NOMSR) && in serial8250_do_set_termios()
2855 UART_ENABLE_MS(&up->port, termios->c_cflag)) in serial8250_do_set_termios()
2856 up->ier |= UART_IER_MSI; in serial8250_do_set_termios()
2857 if (up->capabilities & UART_CAP_UUE) in serial8250_do_set_termios()
2858 up->ier |= UART_IER_UUE; in serial8250_do_set_termios()
2859 if (up->capabilities & UART_CAP_RTOIE) in serial8250_do_set_termios()
2860 up->ier |= UART_IER_RTOIE; in serial8250_do_set_termios()
2862 serial_port_out(port, UART_IER, up->ier); in serial8250_do_set_termios()
2864 if (up->capabilities & UART_CAP_EFR) { in serial8250_do_set_termios()
2868 * - TI16C752 requires control thresholds to be set. in serial8250_do_set_termios()
2869 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled. in serial8250_do_set_termios()
2871 if (termios->c_cflag & CRTSCTS) in serial8250_do_set_termios()
2875 if (port->flags & UPF_EXAR_EFR) in serial8250_do_set_termios()
2881 serial8250_set_divisor(port, baud, quot, frac); in serial8250_do_set_termios()
2884 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR in serial8250_do_set_termios()
2887 if (port->type == PORT_16750) in serial8250_do_set_termios()
2888 serial_port_out(port, UART_FCR, up->fcr); in serial8250_do_set_termios()
2890 serial_port_out(port, UART_LCR, up->lcr); /* reset DLAB */ in serial8250_do_set_termios()
2891 if (port->type != PORT_16750) { in serial8250_do_set_termios()
2893 if (up->fcr & UART_FCR_ENABLE_FIFO) in serial8250_do_set_termios()
2895 serial_port_out(port, UART_FCR, up->fcr); /* set fcr */ in serial8250_do_set_termios()
2897 serial8250_set_mctrl(port, port->mctrl); in serial8250_do_set_termios()
2898 spin_unlock_irqrestore(&port->lock, flags); in serial8250_do_set_termios()
2903 tty_termios_encode_baud_rate(termios, baud, baud); in serial8250_do_set_termios()
2911 if (port->set_termios) in serial8250_set_termios()
2912 port->set_termios(port, termios, old); in serial8250_set_termios()
2919 if (termios->c_line == N_PPS) { in serial8250_do_set_ldisc()
2920 port->flags |= UPF_HARDPPS_CD; in serial8250_do_set_ldisc()
2921 spin_lock_irq(&port->lock); in serial8250_do_set_ldisc()
2923 spin_unlock_irq(&port->lock); in serial8250_do_set_ldisc()
2925 port->flags &= ~UPF_HARDPPS_CD; in serial8250_do_set_ldisc()
2926 if (!UART_ENABLE_MS(port, termios->c_cflag)) { in serial8250_do_set_ldisc()
2927 spin_lock_irq(&port->lock); in serial8250_do_set_ldisc()
2929 spin_unlock_irq(&port->lock); in serial8250_do_set_ldisc()
2938 if (port->set_ldisc) in serial8250_set_ldisc()
2939 port->set_ldisc(port, termios); in serial8250_set_ldisc()
2957 if (port->pm) in serial8250_pm()
2958 port->pm(port, state, oldstate); in serial8250_pm()
2965 if (pt->port.mapsize) in serial8250_port_size()
2966 return pt->port.mapsize; in serial8250_port_size()
2968 return 0x16 << pt->port.regshift; in serial8250_port_size()
2970 return 8 << pt->port.regshift; in serial8250_port_size()
2979 struct uart_port *port = &up->port; in serial8250_request_std_resource()
2982 switch (port->iotype) { in serial8250_request_std_resource()
2989 if (!port->mapbase) { in serial8250_request_std_resource()
2990 ret = -EINVAL; in serial8250_request_std_resource()
2994 if (!request_mem_region(port->mapbase, size, "serial")) { in serial8250_request_std_resource()
2995 ret = -EBUSY; in serial8250_request_std_resource()
2999 if (port->flags & UPF_IOREMAP) { in serial8250_request_std_resource()
3000 port->membase = ioremap(port->mapbase, size); in serial8250_request_std_resource()
3001 if (!port->membase) { in serial8250_request_std_resource()
3002 release_mem_region(port->mapbase, size); in serial8250_request_std_resource()
3003 ret = -ENOMEM; in serial8250_request_std_resource()
3010 if (!request_region(port->iobase, size, "serial")) in serial8250_request_std_resource()
3011 ret = -EBUSY; in serial8250_request_std_resource()
3020 struct uart_port *port = &up->port; in serial8250_release_std_resource()
3022 switch (port->iotype) { in serial8250_release_std_resource()
3029 if (!port->mapbase) in serial8250_release_std_resource()
3032 if (port->flags & UPF_IOREMAP) { in serial8250_release_std_resource()
3033 iounmap(port->membase); in serial8250_release_std_resource()
3034 port->membase = NULL; in serial8250_release_std_resource()
3037 release_mem_region(port->mapbase, size); in serial8250_release_std_resource()
3042 release_region(port->iobase, size); in serial8250_release_std_resource()
3063 const struct serial8250_config *conf_type = &uart_config[up->port.type]; in fcr_get_rxtrig_bytes()
3066 bytes = conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(up->fcr)]; in fcr_get_rxtrig_bytes()
3068 return bytes ? bytes : -EOPNOTSUPP; in fcr_get_rxtrig_bytes()
3073 const struct serial8250_config *conf_type = &uart_config[up->port.type]; in bytes_to_fcr_rxtrig()
3076 if (!conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(UART_FCR_R_TRIG_00)]) in bytes_to_fcr_rxtrig()
3077 return -EOPNOTSUPP; in bytes_to_fcr_rxtrig()
3080 if (bytes < conf_type->rxtrig_bytes[i]) in bytes_to_fcr_rxtrig()
3082 return (--i) << UART_FCR_R_TRIG_SHIFT; in bytes_to_fcr_rxtrig()
3091 struct uart_port *uport = state->uart_port; in do_get_rxtrig()
3094 if (!(up->capabilities & UART_CAP_FIFO) || uport->fifosize <= 1) in do_get_rxtrig()
3095 return -EINVAL; in do_get_rxtrig()
3104 mutex_lock(&port->mutex); in do_serial8250_get_rxtrig()
3106 mutex_unlock(&port->mutex); in do_serial8250_get_rxtrig()
3127 struct uart_port *uport = state->uart_port; in do_set_rxtrig()
3131 if (!(up->capabilities & UART_CAP_FIFO) || uport->fifosize <= 1) in do_set_rxtrig()
3132 return -EINVAL; in do_set_rxtrig()
3139 up->fcr &= ~UART_FCR_TRIGGER_MASK; in do_set_rxtrig()
3140 up->fcr |= (unsigned char)rxtrig; in do_set_rxtrig()
3141 serial_out(up, UART_FCR, up->fcr); in do_set_rxtrig()
3149 mutex_lock(&port->mutex); in do_serial8250_set_rxtrig()
3151 mutex_unlock(&port->mutex); in do_serial8250_set_rxtrig()
3164 return -EINVAL; in rx_trig_bytes_store()
3190 const struct serial8250_config *conf_type = &uart_config[up->port.type]; in register_dev_spec_attr_grp()
3192 if (conf_type->rxtrig_bytes[0]) in register_dev_spec_attr_grp()
3193 up->port.attr_group = &serial8250_dev_attr_group; in register_dev_spec_attr_grp()
3209 if (port->iotype != up->cur_iotype) in serial8250_config_port()
3216 if (port->type == PORT_TEGRA) in serial8250_config_port()
3217 up->bugs |= UART_BUG_NOMSR; in serial8250_config_port()
3219 if (port->type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) in serial8250_config_port()
3222 if (port->type == PORT_UNKNOWN) in serial8250_config_port()
3226 up->fcr = uart_config[up->port.type].fcr; in serial8250_config_port()
3232 if (ser->irq >= nr_irqs || ser->irq < 0 || in serial8250_verify_port()
3233 ser->baud_base < 9600 || ser->type < PORT_UNKNOWN || in serial8250_verify_port()
3234 ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS || in serial8250_verify_port()
3235 ser->type == PORT_STARTECH) in serial8250_verify_port()
3236 return -EINVAL; in serial8250_verify_port()
3242 int type = port->type; in serial8250_type()
3278 struct uart_port *port = &up->port; in serial8250_init_port()
3280 spin_lock_init(&port->lock); in serial8250_init_port()
3281 port->ctrl_id = 0; in serial8250_init_port()
3282 port->pm = NULL; in serial8250_init_port()
3283 port->ops = &serial8250_pops; in serial8250_init_port()
3284 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); in serial8250_init_port()
3286 up->cur_iotype = 0xFF; in serial8250_init_port()
3292 struct uart_port *port = &up->port; in serial8250_set_defaults()
3294 if (up->port.flags & UPF_FIXED_TYPE) { in serial8250_set_defaults()
3295 unsigned int type = up->port.type; in serial8250_set_defaults()
3297 if (!up->port.fifosize) in serial8250_set_defaults()
3298 up->port.fifosize = uart_config[type].fifo_size; in serial8250_set_defaults()
3299 if (!up->tx_loadsz) in serial8250_set_defaults()
3300 up->tx_loadsz = uart_config[type].tx_loadsz; in serial8250_set_defaults()
3301 if (!up->capabilities) in serial8250_set_defaults()
3302 up->capabilities = uart_config[type].flags; in serial8250_set_defaults()
3308 if (up->dma) { in serial8250_set_defaults()
3309 if (!up->dma->tx_dma) in serial8250_set_defaults()
3310 up->dma->tx_dma = serial8250_tx_dma; in serial8250_set_defaults()
3311 if (!up->dma->rx_dma) in serial8250_set_defaults()
3312 up->dma->rx_dma = serial8250_rx_dma; in serial8250_set_defaults()
3328 * Restore serial console when h/w power-off detected
3332 struct uart_port *port = &up->port; in serial8250_console_restore()
3334 unsigned int baud, quot, frac = 0; in serial8250_console_restore() local
3336 termios.c_cflag = port->cons->cflag; in serial8250_console_restore()
3337 termios.c_ispeed = port->cons->ispeed; in serial8250_console_restore()
3338 termios.c_ospeed = port->cons->ospeed; in serial8250_console_restore()
3339 if (port->state->port.tty && termios.c_cflag == 0) { in serial8250_console_restore()
3340 termios.c_cflag = port->state->port.tty->termios.c_cflag; in serial8250_console_restore()
3341 termios.c_ispeed = port->state->port.tty->termios.c_ispeed; in serial8250_console_restore()
3342 termios.c_ospeed = port->state->port.tty->termios.c_ospeed; in serial8250_console_restore()
3345 baud = serial8250_get_baud_rate(port, &termios, NULL); in serial8250_console_restore()
3346 quot = serial8250_get_divisor(port, baud, &frac); in serial8250_console_restore()
3348 serial8250_set_divisor(port, baud, quot, frac); in serial8250_console_restore()
3349 serial_port_out(port, UART_LCR, up->lcr); in serial8250_console_restore()
3350 serial8250_out_MCR(up, up->mcr | UART_MCR_DTR | UART_MCR_RTS); in serial8250_console_restore()
3364 unsigned int fifosize = up->tx_loadsz; in serial8250_console_fifo_write()
3394 struct uart_8250_em485 *em485 = up->em485; in serial8250_console_write()
3395 struct uart_port *port = &up->port; in serial8250_console_write()
3403 locked = spin_trylock_irqsave(&port->lock, flags); in serial8250_console_write()
3405 spin_lock_irqsave(&port->lock, flags); in serial8250_console_write()
3414 if (up->canary && (up->canary != serial_port_in(port, UART_SCR))) { in serial8250_console_write()
3416 up->canary = 0; in serial8250_console_write()
3420 if (em485->tx_stopped) in serial8250_console_write()
3421 up->rs485_start_tx(up); in serial8250_console_write()
3422 mdelay(port->rs485.delay_rts_before_send); in serial8250_console_write()
3425 use_fifo = (up->capabilities & UART_CAP_FIFO) && in serial8250_console_write()
3430 !(up->capabilities & UART_CAP_MINI) && in serial8250_console_write()
3434 up->tx_loadsz > 1 && in serial8250_console_write()
3435 (up->fcr & UART_FCR_ENABLE_FIFO) && in serial8250_console_write()
3436 port->state && in serial8250_console_write()
3437 test_bit(TTY_PORT_INITIALIZED, &port->state->port.iflags) && in serial8250_console_write()
3443 !(up->port.flags & UPF_CONS_FLOW); in serial8250_console_write()
3457 mdelay(port->rs485.delay_rts_after_send); in serial8250_console_write()
3458 if (em485->tx_stopped) in serial8250_console_write()
3459 up->rs485_stop_tx(up); in serial8250_console_write()
3471 if (up->msr_saved_flags) in serial8250_console_write()
3475 spin_unlock_irqrestore(&port->lock, flags); in serial8250_console_write()
3490 return (port->uartclk / 16) / quot; in probe_baud()
3495 int baud = 9600; in serial8250_console_setup() local
3501 if (!port->iobase && !port->membase) in serial8250_console_setup()
3502 return -ENODEV; in serial8250_console_setup()
3505 uart_parse_options(options, &baud, &parity, &bits, &flow); in serial8250_console_setup()
3507 baud = probe_baud(port); in serial8250_console_setup()
3509 ret = uart_set_options(port, port->cons, baud, parity, bits, flow); in serial8250_console_setup()
3513 if (port->dev) in serial8250_console_setup()
3514 pm_runtime_get_sync(port->dev); in serial8250_console_setup()
3521 if (port->dev) in serial8250_console_exit()
3522 pm_runtime_put_sync(port->dev); in serial8250_console_exit()