Lines Matching refs:port
88 static void meson_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) in meson_uart_set_mctrl() argument
92 static unsigned int meson_uart_get_mctrl(struct uart_port *port) in meson_uart_get_mctrl() argument
97 static unsigned int meson_uart_tx_empty(struct uart_port *port) in meson_uart_tx_empty() argument
101 val = readl(port->membase + AML_UART_STATUS); in meson_uart_tx_empty()
106 static void meson_uart_stop_tx(struct uart_port *port) in meson_uart_stop_tx() argument
110 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_stop_tx()
112 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_stop_tx()
115 static void meson_uart_stop_rx(struct uart_port *port) in meson_uart_stop_rx() argument
119 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_stop_rx()
121 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_stop_rx()
124 static void meson_uart_shutdown(struct uart_port *port) in meson_uart_shutdown() argument
129 free_irq(port->irq, port); in meson_uart_shutdown()
131 spin_lock_irqsave(&port->lock, flags); in meson_uart_shutdown()
133 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_shutdown()
136 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_shutdown()
138 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_shutdown()
141 static void meson_uart_start_tx(struct uart_port *port) in meson_uart_start_tx() argument
143 struct circ_buf *xmit = &port->state->xmit; in meson_uart_start_tx()
147 if (uart_tx_stopped(port)) { in meson_uart_start_tx()
148 meson_uart_stop_tx(port); in meson_uart_start_tx()
152 while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) { in meson_uart_start_tx()
153 if (port->x_char) { in meson_uart_start_tx()
154 writel(port->x_char, port->membase + AML_UART_WFIFO); in meson_uart_start_tx()
155 port->icount.tx++; in meson_uart_start_tx()
156 port->x_char = 0; in meson_uart_start_tx()
164 writel(ch, port->membase + AML_UART_WFIFO); in meson_uart_start_tx()
166 port->icount.tx++; in meson_uart_start_tx()
170 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_start_tx()
172 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_start_tx()
176 uart_write_wakeup(port); in meson_uart_start_tx()
179 static void meson_receive_chars(struct uart_port *port) in meson_receive_chars() argument
181 struct tty_port *tport = &port->state->port; in meson_receive_chars()
187 port->icount.rx++; in meson_receive_chars()
188 ostatus = status = readl(port->membase + AML_UART_STATUS); in meson_receive_chars()
192 port->icount.overrun++; in meson_receive_chars()
194 port->icount.frame++; in meson_receive_chars()
196 port->icount.frame++; in meson_receive_chars()
198 mode = readl(port->membase + AML_UART_CONTROL); in meson_receive_chars()
200 writel(mode, port->membase + AML_UART_CONTROL); in meson_receive_chars()
204 writel(mode, port->membase + AML_UART_CONTROL); in meson_receive_chars()
206 status &= port->read_status_mask; in meson_receive_chars()
213 ch = readl(port->membase + AML_UART_RFIFO); in meson_receive_chars()
217 port->icount.brk++; in meson_receive_chars()
219 if (uart_handle_break(port)) in meson_receive_chars()
223 if (uart_handle_sysrq_char(port, ch)) in meson_receive_chars()
226 if ((status & port->ignore_status_mask) == 0) in meson_receive_chars()
232 } while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)); in meson_receive_chars()
239 struct uart_port *port = (struct uart_port *)dev_id; in meson_uart_interrupt() local
241 spin_lock(&port->lock); in meson_uart_interrupt()
243 if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)) in meson_uart_interrupt()
244 meson_receive_chars(port); in meson_uart_interrupt()
246 if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) { in meson_uart_interrupt()
247 if (readl(port->membase + AML_UART_CONTROL) & AML_UART_TX_INT_EN) in meson_uart_interrupt()
248 meson_uart_start_tx(port); in meson_uart_interrupt()
251 spin_unlock(&port->lock); in meson_uart_interrupt()
256 static const char *meson_uart_type(struct uart_port *port) in meson_uart_type() argument
258 return (port->type == PORT_MESON) ? "meson_uart" : NULL; in meson_uart_type()
269 static void meson_uart_reset(struct uart_port *port) in meson_uart_reset() argument
273 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_reset()
275 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_reset()
278 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_reset()
281 static int meson_uart_startup(struct uart_port *port) in meson_uart_startup() argument
287 spin_lock_irqsave(&port->lock, flags); in meson_uart_startup()
289 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_startup()
291 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
293 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
296 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
299 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
301 val = (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2)); in meson_uart_startup()
302 writel(val, port->membase + AML_UART_MISC); in meson_uart_startup()
304 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_startup()
306 ret = request_irq(port->irq, meson_uart_interrupt, 0, in meson_uart_startup()
307 port->name, port); in meson_uart_startup()
312 static void meson_uart_change_speed(struct uart_port *port, unsigned long baud) in meson_uart_change_speed() argument
314 const struct meson_uart_data *private_data = port->private_data; in meson_uart_change_speed()
317 while (!meson_uart_tx_empty(port)) in meson_uart_change_speed()
320 if (port->uartclk == 24000000) { in meson_uart_change_speed()
327 val |= DIV_ROUND_CLOSEST(port->uartclk / xtal_div, baud) - 1; in meson_uart_change_speed()
330 val = DIV_ROUND_CLOSEST(port->uartclk / 4, baud) - 1; in meson_uart_change_speed()
333 writel(val, port->membase + AML_UART_REG5); in meson_uart_change_speed()
336 static void meson_uart_set_termios(struct uart_port *port, in meson_uart_set_termios() argument
344 spin_lock_irqsave(&port->lock, flags); in meson_uart_set_termios()
349 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_set_termios()
388 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_set_termios()
390 baud = uart_get_baud_rate(port, termios, old, 50, 4000000); in meson_uart_set_termios()
391 meson_uart_change_speed(port, baud); in meson_uart_set_termios()
393 port->read_status_mask = AML_UART_TX_FIFO_WERR; in meson_uart_set_termios()
395 port->read_status_mask |= AML_UART_PARITY_ERR | in meson_uart_set_termios()
398 port->ignore_status_mask = 0; in meson_uart_set_termios()
400 port->ignore_status_mask |= AML_UART_PARITY_ERR | in meson_uart_set_termios()
403 uart_update_timeout(port, termios->c_cflag, baud); in meson_uart_set_termios()
404 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_set_termios()
407 static int meson_uart_verify_port(struct uart_port *port, in meson_uart_verify_port() argument
412 if (port->type != PORT_MESON) in meson_uart_verify_port()
414 if (port->irq != ser->irq) in meson_uart_verify_port()
421 static void meson_uart_release_port(struct uart_port *port) in meson_uart_release_port() argument
423 devm_iounmap(port->dev, port->membase); in meson_uart_release_port()
424 port->membase = NULL; in meson_uart_release_port()
425 devm_release_mem_region(port->dev, port->mapbase, port->mapsize); in meson_uart_release_port()
428 static int meson_uart_request_port(struct uart_port *port) in meson_uart_request_port() argument
430 if (!devm_request_mem_region(port->dev, port->mapbase, port->mapsize, in meson_uart_request_port()
431 dev_name(port->dev))) { in meson_uart_request_port()
432 dev_err(port->dev, "Memory region busy\n"); in meson_uart_request_port()
436 port->membase = devm_ioremap(port->dev, port->mapbase, in meson_uart_request_port()
437 port->mapsize); in meson_uart_request_port()
438 if (!port->membase) in meson_uart_request_port()
444 static void meson_uart_config_port(struct uart_port *port, int flags) in meson_uart_config_port() argument
447 port->type = PORT_MESON; in meson_uart_config_port()
448 meson_uart_request_port(port); in meson_uart_config_port()
458 static int meson_uart_poll_get_char(struct uart_port *port) in meson_uart_poll_get_char() argument
463 spin_lock_irqsave(&port->lock, flags); in meson_uart_poll_get_char()
465 if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY) in meson_uart_poll_get_char()
468 c = readl(port->membase + AML_UART_RFIFO); in meson_uart_poll_get_char()
470 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_poll_get_char()
475 static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c) in meson_uart_poll_put_char() argument
481 spin_lock_irqsave(&port->lock, flags); in meson_uart_poll_put_char()
484 ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, in meson_uart_poll_put_char()
489 dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); in meson_uart_poll_put_char()
494 writel(c, port->membase + AML_UART_WFIFO); in meson_uart_poll_put_char()
497 ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, in meson_uart_poll_put_char()
502 dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); in meson_uart_poll_put_char()
505 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_poll_put_char()
532 static void meson_uart_enable_tx_engine(struct uart_port *port) in meson_uart_enable_tx_engine() argument
536 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_enable_tx_engine()
538 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_enable_tx_engine()
541 static void meson_console_putchar(struct uart_port *port, unsigned char ch) in meson_console_putchar() argument
543 if (!port->membase) in meson_console_putchar()
546 while (readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL) in meson_console_putchar()
548 writel(ch, port->membase + AML_UART_WFIFO); in meson_console_putchar()
551 static void meson_serial_port_write(struct uart_port *port, const char *s, in meson_serial_port_write() argument
559 if (port->sysrq) { in meson_serial_port_write()
562 locked = spin_trylock(&port->lock); in meson_serial_port_write()
564 spin_lock(&port->lock); in meson_serial_port_write()
568 val = readl(port->membase + AML_UART_CONTROL); in meson_serial_port_write()
570 writel(tmp, port->membase + AML_UART_CONTROL); in meson_serial_port_write()
572 uart_console_write(port, s, count, meson_console_putchar); in meson_serial_port_write()
573 writel(val, port->membase + AML_UART_CONTROL); in meson_serial_port_write()
576 spin_unlock(&port->lock); in meson_serial_port_write()
583 struct uart_port *port; in meson_serial_console_write() local
585 port = meson_ports[co->index]; in meson_serial_console_write()
586 if (!port) in meson_serial_console_write()
589 meson_serial_port_write(port, s, count); in meson_serial_console_write()
594 struct uart_port *port; in meson_serial_console_setup() local
603 port = meson_ports[co->index]; in meson_serial_console_setup()
604 if (!port || !port->membase) in meson_serial_console_setup()
607 meson_uart_enable_tx_engine(port); in meson_serial_console_setup()
612 return uart_set_options(port, co, baud, parity, bits, flow); in meson_serial_console_setup()
637 meson_serial_port_write(&dev->port, s, count); in meson_serial_early_console_write()
643 if (!device->port.membase) in meson_serial_early_console_setup()
646 meson_uart_enable_tx_engine(&device->port); in meson_serial_early_console_setup()
671 struct uart_port *port) in meson_uart_probe_clocks() argument
689 port->uartclk = clk_get_rate(clk_baud); in meson_uart_probe_clocks()
697 struct uart_port *port; in meson_uart_probe() local
734 port = devm_kzalloc(&pdev->dev, sizeof(struct uart_port), GFP_KERNEL); in meson_uart_probe()
735 if (!port) in meson_uart_probe()
738 ret = meson_uart_probe_clocks(pdev, port); in meson_uart_probe()
742 port->iotype = UPIO_MEM; in meson_uart_probe()
743 port->mapbase = res_mem->start; in meson_uart_probe()
744 port->mapsize = resource_size(res_mem); in meson_uart_probe()
745 port->irq = irq; in meson_uart_probe()
746 port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY; in meson_uart_probe()
747 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE); in meson_uart_probe()
748 port->dev = &pdev->dev; in meson_uart_probe()
749 port->line = pdev->id; in meson_uart_probe()
750 port->type = PORT_MESON; in meson_uart_probe()
751 port->x_char = 0; in meson_uart_probe()
752 port->ops = &meson_uart_ops; in meson_uart_probe()
753 port->fifosize = fifosize; in meson_uart_probe()
754 port->private_data = (void *)device_get_match_data(&pdev->dev); in meson_uart_probe()
756 meson_ports[pdev->id] = port; in meson_uart_probe()
757 platform_set_drvdata(pdev, port); in meson_uart_probe()
760 if (meson_uart_request_port(port) >= 0) { in meson_uart_probe()
761 meson_uart_reset(port); in meson_uart_probe()
762 meson_uart_release_port(port); in meson_uart_probe()
765 ret = uart_add_one_port(&meson_uart_driver, port); in meson_uart_probe()
774 struct uart_port *port; in meson_uart_remove() local
776 port = platform_get_drvdata(pdev); in meson_uart_remove()
777 uart_remove_one_port(&meson_uart_driver, port); in meson_uart_remove()