Lines Matching +full:per +full:- +full:port

1 // SPDX-License-Identifier: GPL-2.0
58 #define PER (1 << 8) /* Parity error */ macro
65 #define RX_FIFO_INTS (RXFAF | RXFF | RXOVER | PER | FER | RXTOUT)
74 #define VT8500_CS8 (1 << 2) /* 8-bit data length (vs. 7-bit) */
83 #define VT8500_SWRTSCTS (1 << 11) /* Software-controlled RTS/CTS */
86 * Capability flags (driver-internal)
106 * have been allocated as we can't use pdev->id in
111 static inline void vt8500_write(struct uart_port *port, unsigned int val, in vt8500_write() argument
114 writel(val, port->membase + off); in vt8500_write()
117 static inline unsigned int vt8500_read(struct uart_port *port, unsigned int off) in vt8500_read() argument
119 return readl(port->membase + off); in vt8500_read()
122 static void vt8500_stop_tx(struct uart_port *port) in vt8500_stop_tx() argument
124 struct vt8500_port *vt8500_port = container_of(port, in vt8500_stop_tx()
128 vt8500_port->ier &= ~TX_FIFO_INTS; in vt8500_stop_tx()
129 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_stop_tx()
132 static void vt8500_stop_rx(struct uart_port *port) in vt8500_stop_rx() argument
134 struct vt8500_port *vt8500_port = container_of(port, in vt8500_stop_rx()
138 vt8500_port->ier &= ~RX_FIFO_INTS; in vt8500_stop_rx()
139 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_stop_rx()
142 static void vt8500_enable_ms(struct uart_port *port) in vt8500_enable_ms() argument
144 struct vt8500_port *vt8500_port = container_of(port, in vt8500_enable_ms()
148 vt8500_port->ier |= TCTS; in vt8500_enable_ms()
149 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_enable_ms()
152 static void handle_rx(struct uart_port *port) in handle_rx() argument
154 struct tty_port *tport = &port->state->port; in handle_rx()
159 if ((vt8500_read(port, VT8500_URISR) & RXOVER)) { in handle_rx()
160 port->icount.overrun++; in handle_rx()
165 while (vt8500_read(port, VT8500_URFIDX) & 0x1f00) { in handle_rx()
169 c = readw(port->membase + VT8500_RXFIFO) & 0x3ff; in handle_rx()
172 c &= ~port->read_status_mask; in handle_rx()
175 port->icount.frame++; in handle_rx()
177 } else if (c & PER) { in handle_rx()
178 port->icount.parity++; in handle_rx()
181 port->icount.rx++; in handle_rx()
183 if (!uart_handle_sysrq_char(port, c)) in handle_rx()
187 spin_unlock(&port->lock); in handle_rx()
189 spin_lock(&port->lock); in handle_rx()
192 static void handle_tx(struct uart_port *port) in handle_tx() argument
194 struct circ_buf *xmit = &port->state->xmit; in handle_tx()
196 if (port->x_char) { in handle_tx()
197 writeb(port->x_char, port->membase + VT8500_TXFIFO); in handle_tx()
198 port->icount.tx++; in handle_tx()
199 port->x_char = 0; in handle_tx()
201 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { in handle_tx()
202 vt8500_stop_tx(port); in handle_tx()
206 while ((vt8500_read(port, VT8500_URFIDX) & 0x1f) < 16) { in handle_tx()
210 writeb(xmit->buf[xmit->tail], port->membase + VT8500_TXFIFO); in handle_tx()
212 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in handle_tx()
213 port->icount.tx++; in handle_tx()
217 uart_write_wakeup(port); in handle_tx()
220 vt8500_stop_tx(port); in handle_tx()
223 static void vt8500_start_tx(struct uart_port *port) in vt8500_start_tx() argument
225 struct vt8500_port *vt8500_port = container_of(port, in vt8500_start_tx()
229 vt8500_port->ier &= ~TX_FIFO_INTS; in vt8500_start_tx()
230 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_start_tx()
231 handle_tx(port); in vt8500_start_tx()
232 vt8500_port->ier |= TX_FIFO_INTS; in vt8500_start_tx()
233 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_start_tx()
236 static void handle_delta_cts(struct uart_port *port) in handle_delta_cts() argument
238 port->icount.cts++; in handle_delta_cts()
239 wake_up_interruptible(&port->state->port.delta_msr_wait); in handle_delta_cts()
244 struct uart_port *port = dev_id; in vt8500_irq() local
247 spin_lock(&port->lock); in vt8500_irq()
248 isr = vt8500_read(port, VT8500_URISR); in vt8500_irq()
251 vt8500_write(port, isr, VT8500_URISR); in vt8500_irq()
254 handle_rx(port); in vt8500_irq()
256 handle_tx(port); in vt8500_irq()
258 handle_delta_cts(port); in vt8500_irq()
260 spin_unlock(&port->lock); in vt8500_irq()
265 static unsigned int vt8500_tx_empty(struct uart_port *port) in vt8500_tx_empty() argument
267 return (vt8500_read(port, VT8500_URFIDX) & 0x1f) < 16 ? in vt8500_tx_empty()
271 static unsigned int vt8500_get_mctrl(struct uart_port *port) in vt8500_get_mctrl() argument
275 usr = vt8500_read(port, VT8500_URUSR); in vt8500_get_mctrl()
282 static void vt8500_set_mctrl(struct uart_port *port, unsigned int mctrl) in vt8500_set_mctrl() argument
284 unsigned int lcr = vt8500_read(port, VT8500_URLCR); in vt8500_set_mctrl()
291 vt8500_write(port, lcr, VT8500_URLCR); in vt8500_set_mctrl()
294 static void vt8500_break_ctl(struct uart_port *port, int break_ctl) in vt8500_break_ctl() argument
297 vt8500_write(port, in vt8500_break_ctl()
298 vt8500_read(port, VT8500_URLCR) | VT8500_BREAK, in vt8500_break_ctl()
302 static int vt8500_set_baud_rate(struct uart_port *port, unsigned int baud) in vt8500_set_baud_rate() argument
305 container_of(port, struct vt8500_port, uart); in vt8500_set_baud_rate()
309 div = ((vt8500_port->clk_predivisor - 1) & 0xf) << 16; in vt8500_set_baud_rate()
310 div |= (uart_get_divisor(port, baud) - 1) & 0x3ff; in vt8500_set_baud_rate()
313 baud = port->uartclk / 16 / ((div & 0x3ff) + 1); in vt8500_set_baud_rate()
315 while ((vt8500_read(port, VT8500_URUSR) & (1 << 5)) && --loops) in vt8500_set_baud_rate()
318 vt8500_write(port, div, VT8500_URDIV); in vt8500_set_baud_rate()
321 vt8500_write(port, mult_frac(baud, 4096, 1000000), VT8500_URBKR); in vt8500_set_baud_rate()
326 static int vt8500_startup(struct uart_port *port) in vt8500_startup() argument
329 container_of(port, struct vt8500_port, uart); in vt8500_startup()
332 snprintf(vt8500_port->name, sizeof(vt8500_port->name), in vt8500_startup()
333 "vt8500_serial%d", port->line); in vt8500_startup()
335 ret = request_irq(port->irq, vt8500_irq, IRQF_TRIGGER_HIGH, in vt8500_startup()
336 vt8500_port->name, port); in vt8500_startup()
340 vt8500_write(port, 0x03, VT8500_URLCR); /* enable TX & RX */ in vt8500_startup()
345 static void vt8500_shutdown(struct uart_port *port) in vt8500_shutdown() argument
348 container_of(port, struct vt8500_port, uart); in vt8500_shutdown()
350 vt8500_port->ier = 0; in vt8500_shutdown()
353 vt8500_write(&vt8500_port->uart, 0, VT8500_URIER); in vt8500_shutdown()
354 vt8500_write(&vt8500_port->uart, 0x880, VT8500_URFCR); in vt8500_shutdown()
355 free_irq(port->irq, port); in vt8500_shutdown()
358 static void vt8500_set_termios(struct uart_port *port, in vt8500_set_termios() argument
363 container_of(port, struct vt8500_port, uart); in vt8500_set_termios()
368 spin_lock_irqsave(&port->lock, flags); in vt8500_set_termios()
371 baud = uart_get_baud_rate(port, termios, old, 900, 921600); in vt8500_set_termios()
372 baud = vt8500_set_baud_rate(port, baud); in vt8500_set_termios()
377 lcr = vt8500_read(&vt8500_port->uart, VT8500_URLCR); in vt8500_set_termios()
379 if (termios->c_cflag & PARENB) { in vt8500_set_termios()
381 termios->c_cflag &= ~CMSPAR; in vt8500_set_termios()
382 if (termios->c_cflag & PARODD) in vt8500_set_termios()
386 /* calculate bits per char */ in vt8500_set_termios()
388 switch (termios->c_cflag & CSIZE) { in vt8500_set_termios()
394 termios->c_cflag &= ~CSIZE; in vt8500_set_termios()
395 termios->c_cflag |= CS8; in vt8500_set_termios()
401 if (termios->c_cflag & CSTOPB) in vt8500_set_termios()
405 if (vt8500_port->vt8500_uart_flags & VT8500_HAS_SWRTSCTS_SWITCH) in vt8500_set_termios()
408 /* set parity, bits per char, and stop bit */ in vt8500_set_termios()
409 vt8500_write(&vt8500_port->uart, lcr, VT8500_URLCR); in vt8500_set_termios()
412 port->read_status_mask = 0; in vt8500_set_termios()
413 if (termios->c_iflag & IGNPAR) in vt8500_set_termios()
414 port->read_status_mask = FER | PER; in vt8500_set_termios()
416 uart_update_timeout(port, termios->c_cflag, baud); in vt8500_set_termios()
419 vt8500_write(&vt8500_port->uart, 0x88c, VT8500_URFCR); in vt8500_set_termios()
420 while ((vt8500_read(&vt8500_port->uart, VT8500_URFCR) & 0xc) in vt8500_set_termios()
421 && --loops) in vt8500_set_termios()
424 /* Every possible FIFO-related interrupt */ in vt8500_set_termios()
425 vt8500_port->ier = RX_FIFO_INTS | TX_FIFO_INTS; in vt8500_set_termios()
430 if (UART_ENABLE_MS(&vt8500_port->uart, termios->c_cflag)) in vt8500_set_termios()
431 vt8500_port->ier |= TCTS; in vt8500_set_termios()
433 vt8500_write(&vt8500_port->uart, 0x881, VT8500_URFCR); in vt8500_set_termios()
434 vt8500_write(&vt8500_port->uart, vt8500_port->ier, VT8500_URIER); in vt8500_set_termios()
436 spin_unlock_irqrestore(&port->lock, flags); in vt8500_set_termios()
439 static const char *vt8500_type(struct uart_port *port) in vt8500_type() argument
442 container_of(port, struct vt8500_port, uart); in vt8500_type()
443 return vt8500_port->name; in vt8500_type()
446 static void vt8500_release_port(struct uart_port *port) in vt8500_release_port() argument
450 static int vt8500_request_port(struct uart_port *port) in vt8500_request_port() argument
455 static void vt8500_config_port(struct uart_port *port, int flags) in vt8500_config_port() argument
457 port->type = PORT_VT8500; in vt8500_config_port()
460 static int vt8500_verify_port(struct uart_port *port, in vt8500_verify_port() argument
463 if (unlikely(ser->type != PORT_UNKNOWN && ser->type != PORT_VT8500)) in vt8500_verify_port()
464 return -EINVAL; in vt8500_verify_port()
465 if (unlikely(port->irq != ser->irq)) in vt8500_verify_port()
466 return -EINVAL; in vt8500_verify_port()
475 static void wait_for_xmitr(struct uart_port *port) in wait_for_xmitr() argument
481 status = vt8500_read(port, VT8500_URFIDX); in wait_for_xmitr()
483 if (--tmout == 0) in wait_for_xmitr()
489 static void vt8500_console_putchar(struct uart_port *port, int c) in vt8500_console_putchar() argument
491 wait_for_xmitr(port); in vt8500_console_putchar()
492 writeb(c, port->membase + VT8500_TXFIFO); in vt8500_console_putchar()
498 struct vt8500_port *vt8500_port = vt8500_uart_ports[co->index]; in vt8500_console_write()
501 BUG_ON(co->index < 0 || co->index >= vt8500_uart_driver.nr); in vt8500_console_write()
503 ier = vt8500_read(&vt8500_port->uart, VT8500_URIER); in vt8500_console_write()
504 vt8500_write(&vt8500_port->uart, VT8500_URIER, 0); in vt8500_console_write()
506 uart_console_write(&vt8500_port->uart, s, count, in vt8500_console_write()
513 wait_for_xmitr(&vt8500_port->uart); in vt8500_console_write()
514 vt8500_write(&vt8500_port->uart, VT8500_URIER, ier); in vt8500_console_write()
525 if (unlikely(co->index >= vt8500_uart_driver.nr || co->index < 0)) in vt8500_console_setup()
526 return -ENXIO; in vt8500_console_setup()
528 vt8500_port = vt8500_uart_ports[co->index]; in vt8500_console_setup()
531 return -ENODEV; in vt8500_console_setup()
536 return uart_set_options(&vt8500_port->uart, in vt8500_console_setup()
546 .index = -1,
557 static int vt8500_get_poll_char(struct uart_port *port) in vt8500_get_poll_char() argument
559 unsigned int status = vt8500_read(port, VT8500_URFIDX); in vt8500_get_poll_char()
564 return vt8500_read(port, VT8500_RXFIFO) & 0xff; in vt8500_get_poll_char()
567 static void vt8500_put_poll_char(struct uart_port *port, unsigned char c) in vt8500_put_poll_char() argument
572 status = vt8500_read(port, VT8500_URFIDX); in vt8500_put_poll_char()
574 if (--tmout == 0) in vt8500_put_poll_char()
579 vt8500_write(port, c, VT8500_TXFIFO); in vt8500_put_poll_char()
618 { .compatible = "via,vt8500-uart", .data = &vt8500_flags},
619 { .compatible = "wm,wm8880-uart", .data = &wm8880_flags},
627 struct device_node *np = pdev->dev.of_node; in vt8500_serial_probe()
631 int port; in vt8500_serial_probe() local
633 match = of_match_device(wmt_dt_ids, &pdev->dev); in vt8500_serial_probe()
635 return -EINVAL; in vt8500_serial_probe()
637 flags = match->data; in vt8500_serial_probe()
642 return -ENODEV; in vt8500_serial_probe()
645 port = of_alias_get_id(np, "serial"); in vt8500_serial_probe()
646 if (port >= VT8500_MAX_PORTS) in vt8500_serial_probe()
647 port = -1; in vt8500_serial_probe()
649 port = -1; in vt8500_serial_probe()
652 if (port < 0) { in vt8500_serial_probe()
653 /* calculate the port id */ in vt8500_serial_probe()
654 port = find_first_zero_bit(vt8500_ports_in_use, in vt8500_serial_probe()
658 if (port >= VT8500_MAX_PORTS) in vt8500_serial_probe()
659 return -ENODEV; in vt8500_serial_probe()
661 /* reserve the port id */ in vt8500_serial_probe()
662 if (test_and_set_bit(port, vt8500_ports_in_use)) { in vt8500_serial_probe()
663 /* port already in use - shouldn't really happen */ in vt8500_serial_probe()
664 return -EBUSY; in vt8500_serial_probe()
667 vt8500_port = devm_kzalloc(&pdev->dev, sizeof(struct vt8500_port), in vt8500_serial_probe()
670 return -ENOMEM; in vt8500_serial_probe()
672 vt8500_port->uart.membase = devm_ioremap_resource(&pdev->dev, mmres); in vt8500_serial_probe()
673 if (IS_ERR(vt8500_port->uart.membase)) in vt8500_serial_probe()
674 return PTR_ERR(vt8500_port->uart.membase); in vt8500_serial_probe()
676 vt8500_port->clk = of_clk_get(pdev->dev.of_node, 0); in vt8500_serial_probe()
677 if (IS_ERR(vt8500_port->clk)) { in vt8500_serial_probe()
678 dev_err(&pdev->dev, "failed to get clock\n"); in vt8500_serial_probe()
679 return -EINVAL; in vt8500_serial_probe()
682 ret = clk_prepare_enable(vt8500_port->clk); in vt8500_serial_probe()
684 dev_err(&pdev->dev, "failed to enable clock\n"); in vt8500_serial_probe()
688 vt8500_port->vt8500_uart_flags = *flags; in vt8500_serial_probe()
689 vt8500_port->clk_predivisor = DIV_ROUND_CLOSEST( in vt8500_serial_probe()
690 clk_get_rate(vt8500_port->clk), in vt8500_serial_probe()
693 vt8500_port->uart.type = PORT_VT8500; in vt8500_serial_probe()
694 vt8500_port->uart.iotype = UPIO_MEM; in vt8500_serial_probe()
695 vt8500_port->uart.mapbase = mmres->start; in vt8500_serial_probe()
696 vt8500_port->uart.irq = irqres->start; in vt8500_serial_probe()
697 vt8500_port->uart.fifosize = 16; in vt8500_serial_probe()
698 vt8500_port->uart.ops = &vt8500_uart_pops; in vt8500_serial_probe()
699 vt8500_port->uart.line = port; in vt8500_serial_probe()
700 vt8500_port->uart.dev = &pdev->dev; in vt8500_serial_probe()
701 vt8500_port->uart.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; in vt8500_serial_probe()
702 vt8500_port->uart.has_sysrq = IS_ENABLED(CONFIG_SERIAL_VT8500_CONSOLE); in vt8500_serial_probe()
704 /* Serial core uses the magic "16" everywhere - adjust for it */ in vt8500_serial_probe()
705 vt8500_port->uart.uartclk = 16 * clk_get_rate(vt8500_port->clk) / in vt8500_serial_probe()
706 vt8500_port->clk_predivisor / in vt8500_serial_probe()
709 snprintf(vt8500_port->name, sizeof(vt8500_port->name), in vt8500_serial_probe()
710 "VT8500 UART%d", pdev->id); in vt8500_serial_probe()
712 vt8500_uart_ports[port] = vt8500_port; in vt8500_serial_probe()
714 uart_add_one_port(&vt8500_uart_driver, &vt8500_port->uart); in vt8500_serial_probe()