• Home
  • Raw
  • Download

Lines Matching +full:port +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0
54 #define TXDE (1 << 0) /* Tx Data empty */
55 #define RXDF (1 << 1) /* Rx Data full */
56 #define TXFAE (1 << 2) /* Tx FIFO almost empty */
57 #define TXFE (1 << 3) /* Tx FIFO empty */
58 #define RXFAF (1 << 4) /* Rx FIFO almost full */
59 #define RXFF (1 << 5) /* Rx FIFO full */
60 #define TXUDR (1 << 6) /* Tx underrun */
61 #define RXOVER (1 << 7) /* Rx overrun */
62 #define PER (1 << 8) /* Parity error */
63 #define FER (1 << 9) /* Frame error */
64 #define TCTS (1 << 10) /* Toggle of CTS */
65 #define RXTOUT (1 << 11) /* Rx timeout */
66 #define BKDONE (1 << 12) /* Break signal done */
67 #define ERR (1 << 13) /* AHB error response */
76 #define VT8500_TXEN (1 << 0) /* Enable transmit logic */
77 #define VT8500_RXEN (1 << 1) /* Enable receive logic */
78 #define VT8500_CS8 (1 << 2) /* 8-bit data length (vs. 7-bit) */
79 #define VT8500_CSTOPB (1 << 3) /* 2 stop bits (vs. 1) */
80 #define VT8500_PARENB (1 << 4) /* Enable parity */
81 #define VT8500_PARODD (1 << 5) /* Odd parity (vs. even) */
82 #define VT8500_RTS (1 << 6) /* Ready to send */
83 #define VT8500_LOOPBK (1 << 7) /* Enable internal loopback */
84 #define VT8500_DMA (1 << 8) /* Enable DMA mode (needs FIFO) */
85 #define VT8500_BREAK (1 << 9) /* Initiate break signal */
86 #define VT8500_PSLVERR (1 << 10) /* APB error upon empty RX FIFO read */
87 #define VT8500_SWRTSCTS (1 << 11) /* Software-controlled RTS/CTS */
90 * Capability flags (driver-internal)
93 #define VT8500_HAS_SWRTSCTS_SWITCH (1 << 1)
110 * have been allocated as we can't use pdev->id in
115 static inline void vt8500_write(struct uart_port *port, unsigned int val, in vt8500_write() argument
118 writel(val, port->membase + off); in vt8500_write()
121 static inline unsigned int vt8500_read(struct uart_port *port, unsigned int off) in vt8500_read() argument
123 return readl(port->membase + off); in vt8500_read()
126 static void vt8500_stop_tx(struct uart_port *port) in vt8500_stop_tx() argument
128 struct vt8500_port *vt8500_port = container_of(port, in vt8500_stop_tx()
132 vt8500_port->ier &= ~TX_FIFO_INTS; in vt8500_stop_tx()
133 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_stop_tx()
136 static void vt8500_stop_rx(struct uart_port *port) in vt8500_stop_rx() argument
138 struct vt8500_port *vt8500_port = container_of(port, in vt8500_stop_rx()
142 vt8500_port->ier &= ~RX_FIFO_INTS; in vt8500_stop_rx()
143 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_stop_rx()
146 static void vt8500_enable_ms(struct uart_port *port) in vt8500_enable_ms() argument
148 struct vt8500_port *vt8500_port = container_of(port, in vt8500_enable_ms()
152 vt8500_port->ier |= TCTS; in vt8500_enable_ms()
153 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_enable_ms()
156 static void handle_rx(struct uart_port *port) in handle_rx() argument
158 struct tty_port *tport = &port->state->port; in handle_rx()
163 if ((vt8500_read(port, VT8500_URISR) & RXOVER)) { in handle_rx()
164 port->icount.overrun++; in handle_rx()
169 while (vt8500_read(port, VT8500_URFIDX) & 0x1f00) { in handle_rx()
173 c = readw(port->membase + VT8500_RXFIFO) & 0x3ff; in handle_rx()
176 c &= ~port->read_status_mask; in handle_rx()
179 port->icount.frame++; in handle_rx()
182 port->icount.parity++; in handle_rx()
185 port->icount.rx++; in handle_rx()
187 if (!uart_handle_sysrq_char(port, c)) in handle_rx()
191 spin_unlock(&port->lock); in handle_rx()
193 spin_lock(&port->lock); in handle_rx()
196 static void handle_tx(struct uart_port *port) in handle_tx() argument
198 struct circ_buf *xmit = &port->state->xmit; in handle_tx()
200 if (port->x_char) { in handle_tx()
201 writeb(port->x_char, port->membase + VT8500_TXFIFO); in handle_tx()
202 port->icount.tx++; in handle_tx()
203 port->x_char = 0; in handle_tx()
205 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { in handle_tx()
206 vt8500_stop_tx(port); in handle_tx()
210 while ((vt8500_read(port, VT8500_URFIDX) & 0x1f) < 16) { in handle_tx()
214 writeb(xmit->buf[xmit->tail], port->membase + VT8500_TXFIFO); in handle_tx()
216 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in handle_tx()
217 port->icount.tx++; in handle_tx()
221 uart_write_wakeup(port); in handle_tx()
224 vt8500_stop_tx(port); in handle_tx()
227 static void vt8500_start_tx(struct uart_port *port) in vt8500_start_tx() argument
229 struct vt8500_port *vt8500_port = container_of(port, in vt8500_start_tx()
233 vt8500_port->ier &= ~TX_FIFO_INTS; in vt8500_start_tx()
234 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_start_tx()
235 handle_tx(port); in vt8500_start_tx()
236 vt8500_port->ier |= TX_FIFO_INTS; in vt8500_start_tx()
237 vt8500_write(port, vt8500_port->ier, VT8500_URIER); in vt8500_start_tx()
240 static void handle_delta_cts(struct uart_port *port) in handle_delta_cts() argument
242 port->icount.cts++; in handle_delta_cts()
243 wake_up_interruptible(&port->state->port.delta_msr_wait); in handle_delta_cts()
248 struct uart_port *port = dev_id; in vt8500_irq() local
251 spin_lock(&port->lock); in vt8500_irq()
252 isr = vt8500_read(port, VT8500_URISR); in vt8500_irq()
255 vt8500_write(port, isr, VT8500_URISR); in vt8500_irq()
258 handle_rx(port); in vt8500_irq()
260 handle_tx(port); in vt8500_irq()
262 handle_delta_cts(port); in vt8500_irq()
264 spin_unlock(&port->lock); in vt8500_irq()
269 static unsigned int vt8500_tx_empty(struct uart_port *port) in vt8500_tx_empty() argument
271 return (vt8500_read(port, VT8500_URFIDX) & 0x1f) < 16 ? in vt8500_tx_empty()
275 static unsigned int vt8500_get_mctrl(struct uart_port *port) in vt8500_get_mctrl() argument
279 usr = vt8500_read(port, VT8500_URUSR); in vt8500_get_mctrl()
280 if (usr & (1 << 4)) in vt8500_get_mctrl()
286 static void vt8500_set_mctrl(struct uart_port *port, unsigned int mctrl) in vt8500_set_mctrl() argument
288 unsigned int lcr = vt8500_read(port, VT8500_URLCR); in vt8500_set_mctrl()
295 vt8500_write(port, lcr, VT8500_URLCR); in vt8500_set_mctrl()
298 static void vt8500_break_ctl(struct uart_port *port, int break_ctl) in vt8500_break_ctl() argument
301 vt8500_write(port, in vt8500_break_ctl()
302 vt8500_read(port, VT8500_URLCR) | VT8500_BREAK, in vt8500_break_ctl()
306 static int vt8500_set_baud_rate(struct uart_port *port, unsigned int baud) in vt8500_set_baud_rate() argument
309 container_of(port, struct vt8500_port, uart); in vt8500_set_baud_rate()
313 div = ((vt8500_port->clk_predivisor - 1) & 0xf) << 16; in vt8500_set_baud_rate()
314 div |= (uart_get_divisor(port, baud) - 1) & 0x3ff; in vt8500_set_baud_rate()
317 baud = port->uartclk / 16 / ((div & 0x3ff) + 1); in vt8500_set_baud_rate()
319 while ((vt8500_read(port, VT8500_URUSR) & (1 << 5)) && --loops) in vt8500_set_baud_rate()
322 vt8500_write(port, div, VT8500_URDIV); in vt8500_set_baud_rate()
325 vt8500_write(port, mult_frac(baud, 4096, 1000000), VT8500_URBKR); in vt8500_set_baud_rate()
330 static int vt8500_startup(struct uart_port *port) in vt8500_startup() argument
333 container_of(port, struct vt8500_port, uart); in vt8500_startup()
336 snprintf(vt8500_port->name, sizeof(vt8500_port->name), in vt8500_startup()
337 "vt8500_serial%d", port->line); in vt8500_startup()
339 ret = request_irq(port->irq, vt8500_irq, IRQF_TRIGGER_HIGH, in vt8500_startup()
340 vt8500_port->name, port); in vt8500_startup()
344 vt8500_write(port, 0x03, VT8500_URLCR); /* enable TX & RX */ in vt8500_startup()
349 static void vt8500_shutdown(struct uart_port *port) in vt8500_shutdown() argument
352 container_of(port, struct vt8500_port, uart); in vt8500_shutdown()
354 vt8500_port->ier = 0; in vt8500_shutdown()
357 vt8500_write(&vt8500_port->uart, 0, VT8500_URIER); in vt8500_shutdown()
358 vt8500_write(&vt8500_port->uart, 0x880, VT8500_URFCR); in vt8500_shutdown()
359 free_irq(port->irq, port); in vt8500_shutdown()
362 static void vt8500_set_termios(struct uart_port *port, in vt8500_set_termios() argument
367 container_of(port, struct vt8500_port, uart); in vt8500_set_termios()
372 spin_lock_irqsave(&port->lock, flags); in vt8500_set_termios()
375 baud = uart_get_baud_rate(port, termios, old, 900, 921600); in vt8500_set_termios()
376 baud = vt8500_set_baud_rate(port, baud); in vt8500_set_termios()
381 lcr = vt8500_read(&vt8500_port->uart, VT8500_URLCR); in vt8500_set_termios()
383 if (termios->c_cflag & PARENB) { in vt8500_set_termios()
385 termios->c_cflag &= ~CMSPAR; in vt8500_set_termios()
386 if (termios->c_cflag & PARODD) in vt8500_set_termios()
392 switch (termios->c_cflag & CSIZE) { in vt8500_set_termios()
398 termios->c_cflag &= ~CSIZE; in vt8500_set_termios()
399 termios->c_cflag |= CS8; in vt8500_set_termios()
405 if (termios->c_cflag & CSTOPB) in vt8500_set_termios()
409 if (vt8500_port->vt8500_uart_flags & VT8500_HAS_SWRTSCTS_SWITCH) in vt8500_set_termios()
413 vt8500_write(&vt8500_port->uart, lcr, VT8500_URLCR); in vt8500_set_termios()
416 port->read_status_mask = 0; in vt8500_set_termios()
417 if (termios->c_iflag & IGNPAR) in vt8500_set_termios()
418 port->read_status_mask = FER | PER; in vt8500_set_termios()
420 uart_update_timeout(port, termios->c_cflag, baud); in vt8500_set_termios()
423 vt8500_write(&vt8500_port->uart, 0x88c, VT8500_URFCR); in vt8500_set_termios()
424 while ((vt8500_read(&vt8500_port->uart, VT8500_URFCR) & 0xc) in vt8500_set_termios()
425 && --loops) in vt8500_set_termios()
428 /* Every possible FIFO-related interrupt */ in vt8500_set_termios()
429 vt8500_port->ier = RX_FIFO_INTS | TX_FIFO_INTS; in vt8500_set_termios()
434 if (UART_ENABLE_MS(&vt8500_port->uart, termios->c_cflag)) in vt8500_set_termios()
435 vt8500_port->ier |= TCTS; in vt8500_set_termios()
437 vt8500_write(&vt8500_port->uart, 0x881, VT8500_URFCR); in vt8500_set_termios()
438 vt8500_write(&vt8500_port->uart, vt8500_port->ier, VT8500_URIER); in vt8500_set_termios()
440 spin_unlock_irqrestore(&port->lock, flags); in vt8500_set_termios()
443 static const char *vt8500_type(struct uart_port *port) in vt8500_type() argument
446 container_of(port, struct vt8500_port, uart); in vt8500_type()
447 return vt8500_port->name; in vt8500_type()
450 static void vt8500_release_port(struct uart_port *port) in vt8500_release_port() argument
454 static int vt8500_request_port(struct uart_port *port) in vt8500_request_port() argument
459 static void vt8500_config_port(struct uart_port *port, int flags) in vt8500_config_port() argument
461 port->type = PORT_VT8500; in vt8500_config_port()
464 static int vt8500_verify_port(struct uart_port *port, in vt8500_verify_port() argument
467 if (unlikely(ser->type != PORT_UNKNOWN && ser->type != PORT_VT8500)) in vt8500_verify_port()
468 return -EINVAL; in vt8500_verify_port()
469 if (unlikely(port->irq != ser->irq)) in vt8500_verify_port()
470 return -EINVAL; in vt8500_verify_port()
479 static void wait_for_xmitr(struct uart_port *port) in wait_for_xmitr() argument
485 status = vt8500_read(port, VT8500_URFIDX); in wait_for_xmitr()
487 if (--tmout == 0) in wait_for_xmitr()
489 udelay(1); in wait_for_xmitr()
493 static void vt8500_console_putchar(struct uart_port *port, int c) in vt8500_console_putchar() argument
495 wait_for_xmitr(port); in vt8500_console_putchar()
496 writeb(c, port->membase + VT8500_TXFIFO); in vt8500_console_putchar()
502 struct vt8500_port *vt8500_port = vt8500_uart_ports[co->index]; in vt8500_console_write()
505 BUG_ON(co->index < 0 || co->index >= vt8500_uart_driver.nr); in vt8500_console_write()
507 ier = vt8500_read(&vt8500_port->uart, VT8500_URIER); in vt8500_console_write()
508 vt8500_write(&vt8500_port->uart, VT8500_URIER, 0); in vt8500_console_write()
510 uart_console_write(&vt8500_port->uart, s, count, in vt8500_console_write()
517 wait_for_xmitr(&vt8500_port->uart); in vt8500_console_write()
518 vt8500_write(&vt8500_port->uart, VT8500_URIER, ier); in vt8500_console_write()
529 if (unlikely(co->index >= vt8500_uart_driver.nr || co->index < 0)) in vt8500_console_setup()
530 return -ENXIO; in vt8500_console_setup()
532 vt8500_port = vt8500_uart_ports[co->index]; in vt8500_console_setup()
535 return -ENODEV; in vt8500_console_setup()
540 return uart_set_options(&vt8500_port->uart, in vt8500_console_setup()
550 .index = -1,
561 static int vt8500_get_poll_char(struct uart_port *port) in vt8500_get_poll_char() argument
563 unsigned int status = vt8500_read(port, VT8500_URFIDX); in vt8500_get_poll_char()
568 return vt8500_read(port, VT8500_RXFIFO) & 0xff; in vt8500_get_poll_char()
571 static void vt8500_put_poll_char(struct uart_port *port, unsigned char c) in vt8500_put_poll_char() argument
576 status = vt8500_read(port, VT8500_URFIDX); in vt8500_put_poll_char()
578 if (--tmout == 0) in vt8500_put_poll_char()
580 udelay(1); in vt8500_put_poll_char()
583 vt8500_write(port, c, VT8500_TXFIFO); in vt8500_put_poll_char()
622 { .compatible = "via,vt8500-uart", .data = &vt8500_flags},
623 { .compatible = "wm,wm8880-uart", .data = &wm8880_flags},
631 struct device_node *np = pdev->dev.of_node; in vt8500_serial_probe()
635 int port; in vt8500_serial_probe() local
637 match = of_match_device(wmt_dt_ids, &pdev->dev); in vt8500_serial_probe()
639 return -EINVAL; in vt8500_serial_probe()
641 flags = match->data; in vt8500_serial_probe()
646 return -ENODEV; in vt8500_serial_probe()
649 port = of_alias_get_id(np, "serial"); in vt8500_serial_probe()
650 if (port >= VT8500_MAX_PORTS) in vt8500_serial_probe()
651 port = -1; in vt8500_serial_probe()
653 port = -1; in vt8500_serial_probe()
656 if (port < 0) { in vt8500_serial_probe()
657 /* calculate the port id */ in vt8500_serial_probe()
658 port = find_first_zero_bit(vt8500_ports_in_use, in vt8500_serial_probe()
662 if (port >= VT8500_MAX_PORTS) in vt8500_serial_probe()
663 return -ENODEV; in vt8500_serial_probe()
665 /* reserve the port id */ in vt8500_serial_probe()
666 if (test_and_set_bit(port, vt8500_ports_in_use)) { in vt8500_serial_probe()
667 /* port already in use - shouldn't really happen */ in vt8500_serial_probe()
668 return -EBUSY; in vt8500_serial_probe()
671 vt8500_port = devm_kzalloc(&pdev->dev, sizeof(struct vt8500_port), in vt8500_serial_probe()
674 return -ENOMEM; in vt8500_serial_probe()
676 vt8500_port->uart.membase = devm_ioremap_resource(&pdev->dev, mmres); in vt8500_serial_probe()
677 if (IS_ERR(vt8500_port->uart.membase)) in vt8500_serial_probe()
678 return PTR_ERR(vt8500_port->uart.membase); in vt8500_serial_probe()
680 vt8500_port->clk = of_clk_get(pdev->dev.of_node, 0); in vt8500_serial_probe()
681 if (IS_ERR(vt8500_port->clk)) { in vt8500_serial_probe()
682 dev_err(&pdev->dev, "failed to get clock\n"); in vt8500_serial_probe()
683 return -EINVAL; in vt8500_serial_probe()
686 ret = clk_prepare_enable(vt8500_port->clk); in vt8500_serial_probe()
688 dev_err(&pdev->dev, "failed to enable clock\n"); in vt8500_serial_probe()
692 vt8500_port->vt8500_uart_flags = *flags; in vt8500_serial_probe()
693 vt8500_port->clk_predivisor = DIV_ROUND_CLOSEST( in vt8500_serial_probe()
694 clk_get_rate(vt8500_port->clk), in vt8500_serial_probe()
697 vt8500_port->uart.type = PORT_VT8500; in vt8500_serial_probe()
698 vt8500_port->uart.iotype = UPIO_MEM; in vt8500_serial_probe()
699 vt8500_port->uart.mapbase = mmres->start; in vt8500_serial_probe()
700 vt8500_port->uart.irq = irqres->start; in vt8500_serial_probe()
701 vt8500_port->uart.fifosize = 16; in vt8500_serial_probe()
702 vt8500_port->uart.ops = &vt8500_uart_pops; in vt8500_serial_probe()
703 vt8500_port->uart.line = port; in vt8500_serial_probe()
704 vt8500_port->uart.dev = &pdev->dev; in vt8500_serial_probe()
705 vt8500_port->uart.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; in vt8500_serial_probe()
707 /* Serial core uses the magic "16" everywhere - adjust for it */ in vt8500_serial_probe()
708 vt8500_port->uart.uartclk = 16 * clk_get_rate(vt8500_port->clk) / in vt8500_serial_probe()
709 vt8500_port->clk_predivisor / in vt8500_serial_probe()
712 snprintf(vt8500_port->name, sizeof(vt8500_port->name), in vt8500_serial_probe()
713 "VT8500 UART%d", pdev->id); in vt8500_serial_probe()
715 vt8500_uart_ports[port] = vt8500_port; in vt8500_serial_probe()
717 uart_add_one_port(&vt8500_uart_driver, &vt8500_port->uart); in vt8500_serial_probe()