Lines Matching refs:port

89 static void meson_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)  in meson_uart_set_mctrl()  argument
93 static unsigned int meson_uart_get_mctrl(struct uart_port *port) in meson_uart_get_mctrl() argument
98 static unsigned int meson_uart_tx_empty(struct uart_port *port) in meson_uart_tx_empty() argument
102 val = readl(port->membase + AML_UART_STATUS); in meson_uart_tx_empty()
107 static void meson_uart_stop_tx(struct uart_port *port) in meson_uart_stop_tx() argument
111 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_stop_tx()
113 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_stop_tx()
116 static void meson_uart_stop_rx(struct uart_port *port) in meson_uart_stop_rx() argument
120 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_stop_rx()
122 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_stop_rx()
125 static void meson_uart_shutdown(struct uart_port *port) in meson_uart_shutdown() argument
130 free_irq(port->irq, port); in meson_uart_shutdown()
132 spin_lock_irqsave(&port->lock, flags); in meson_uart_shutdown()
134 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_shutdown()
137 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_shutdown()
139 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_shutdown()
142 static void meson_uart_start_tx(struct uart_port *port) in meson_uart_start_tx() argument
144 struct circ_buf *xmit = &port->state->xmit; in meson_uart_start_tx()
148 if (uart_tx_stopped(port)) { in meson_uart_start_tx()
149 meson_uart_stop_tx(port); in meson_uart_start_tx()
153 while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) { in meson_uart_start_tx()
154 if (port->x_char) { in meson_uart_start_tx()
155 writel(port->x_char, port->membase + AML_UART_WFIFO); in meson_uart_start_tx()
156 port->icount.tx++; in meson_uart_start_tx()
157 port->x_char = 0; in meson_uart_start_tx()
165 writel(ch, port->membase + AML_UART_WFIFO); in meson_uart_start_tx()
166 uart_xmit_advance(port, 1); 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()
384 if (port->flags & UPF_HARD_FLOW) in meson_uart_set_termios()
392 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_set_termios()
394 baud = uart_get_baud_rate(port, termios, old, 50, 4000000); in meson_uart_set_termios()
395 meson_uart_change_speed(port, baud); in meson_uart_set_termios()
397 port->read_status_mask = AML_UART_TX_FIFO_WERR; in meson_uart_set_termios()
399 port->read_status_mask |= AML_UART_PARITY_ERR | in meson_uart_set_termios()
402 port->ignore_status_mask = 0; in meson_uart_set_termios()
404 port->ignore_status_mask |= AML_UART_PARITY_ERR | in meson_uart_set_termios()
407 uart_update_timeout(port, termios->c_cflag, baud); in meson_uart_set_termios()
408 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_set_termios()
411 static int meson_uart_verify_port(struct uart_port *port, in meson_uart_verify_port() argument
416 if (port->type != PORT_MESON) in meson_uart_verify_port()
418 if (port->irq != ser->irq) in meson_uart_verify_port()
425 static void meson_uart_release_port(struct uart_port *port) in meson_uart_release_port() argument
427 devm_iounmap(port->dev, port->membase); in meson_uart_release_port()
428 port->membase = NULL; in meson_uart_release_port()
429 devm_release_mem_region(port->dev, port->mapbase, port->mapsize); in meson_uart_release_port()
432 static int meson_uart_request_port(struct uart_port *port) in meson_uart_request_port() argument
434 if (!devm_request_mem_region(port->dev, port->mapbase, port->mapsize, in meson_uart_request_port()
435 dev_name(port->dev))) { in meson_uart_request_port()
436 dev_err(port->dev, "Memory region busy\n"); in meson_uart_request_port()
440 port->membase = devm_ioremap(port->dev, port->mapbase, in meson_uart_request_port()
441 port->mapsize); in meson_uart_request_port()
442 if (!port->membase) in meson_uart_request_port()
448 static void meson_uart_config_port(struct uart_port *port, int flags) in meson_uart_config_port() argument
451 port->type = PORT_MESON; in meson_uart_config_port()
452 meson_uart_request_port(port); in meson_uart_config_port()
462 static int meson_uart_poll_get_char(struct uart_port *port) in meson_uart_poll_get_char() argument
467 spin_lock_irqsave(&port->lock, flags); in meson_uart_poll_get_char()
469 if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY) in meson_uart_poll_get_char()
472 c = readl(port->membase + AML_UART_RFIFO); in meson_uart_poll_get_char()
474 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_poll_get_char()
479 static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c) in meson_uart_poll_put_char() argument
485 spin_lock_irqsave(&port->lock, flags); in meson_uart_poll_put_char()
488 ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, in meson_uart_poll_put_char()
493 dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); in meson_uart_poll_put_char()
498 writel(c, port->membase + AML_UART_WFIFO); in meson_uart_poll_put_char()
501 ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, in meson_uart_poll_put_char()
506 dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); in meson_uart_poll_put_char()
509 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_poll_put_char()
536 static void meson_uart_enable_tx_engine(struct uart_port *port) in meson_uart_enable_tx_engine() argument
540 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_enable_tx_engine()
542 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_enable_tx_engine()
545 static void meson_console_putchar(struct uart_port *port, unsigned char ch) in meson_console_putchar() argument
547 if (!port->membase) in meson_console_putchar()
550 while (readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL) in meson_console_putchar()
552 writel(ch, port->membase + AML_UART_WFIFO); in meson_console_putchar()
555 static void meson_serial_port_write(struct uart_port *port, const char *s, in meson_serial_port_write() argument
563 if (port->sysrq) { in meson_serial_port_write()
566 locked = spin_trylock(&port->lock); in meson_serial_port_write()
568 spin_lock(&port->lock); in meson_serial_port_write()
572 val = readl(port->membase + AML_UART_CONTROL); in meson_serial_port_write()
574 writel(tmp, port->membase + AML_UART_CONTROL); in meson_serial_port_write()
576 uart_console_write(port, s, count, meson_console_putchar); in meson_serial_port_write()
577 writel(val, port->membase + AML_UART_CONTROL); in meson_serial_port_write()
580 spin_unlock(&port->lock); in meson_serial_port_write()
587 struct uart_port *port; in meson_serial_console_write() local
589 port = meson_ports[co->index]; in meson_serial_console_write()
590 if (!port) in meson_serial_console_write()
593 meson_serial_port_write(port, s, count); in meson_serial_console_write()
598 struct uart_port *port; in meson_serial_console_setup() local
607 port = meson_ports[co->index]; in meson_serial_console_setup()
608 if (!port || !port->membase) in meson_serial_console_setup()
611 meson_uart_enable_tx_engine(port); in meson_serial_console_setup()
616 return uart_set_options(port, co, baud, parity, bits, flow); in meson_serial_console_setup()
639 meson_serial_port_write(&dev->port, s, count); in meson_serial_early_console_write()
645 if (!device->port.membase) in meson_serial_early_console_setup()
648 meson_uart_enable_tx_engine(&device->port); in meson_serial_early_console_setup()
674 struct uart_port *port) in meson_uart_probe_clocks() argument
692 port->uartclk = clk_get_rate(clk_baud); in meson_uart_probe_clocks()
708 struct uart_port *port; in meson_uart_probe() local
747 port = devm_kzalloc(&pdev->dev, sizeof(struct uart_port), GFP_KERNEL); in meson_uart_probe()
748 if (!port) in meson_uart_probe()
751 ret = meson_uart_probe_clocks(pdev, port); in meson_uart_probe()
766 port->iotype = UPIO_MEM; in meson_uart_probe()
767 port->mapbase = res_mem->start; in meson_uart_probe()
768 port->mapsize = resource_size(res_mem); in meson_uart_probe()
769 port->irq = irq; in meson_uart_probe()
770 port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY; in meson_uart_probe()
772 port->flags |= UPF_HARD_FLOW; in meson_uart_probe()
773 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE); in meson_uart_probe()
774 port->dev = &pdev->dev; in meson_uart_probe()
775 port->line = pdev->id; in meson_uart_probe()
776 port->type = PORT_MESON; in meson_uart_probe()
777 port->x_char = 0; in meson_uart_probe()
778 port->ops = &meson_uart_ops; in meson_uart_probe()
779 port->fifosize = fifosize; in meson_uart_probe()
780 port->private_data = (void *)priv_data; in meson_uart_probe()
782 meson_ports[pdev->id] = port; in meson_uart_probe()
783 platform_set_drvdata(pdev, port); in meson_uart_probe()
786 if (meson_uart_request_port(port) >= 0) { in meson_uart_probe()
787 meson_uart_reset(port); in meson_uart_probe()
788 meson_uart_release_port(port); in meson_uart_probe()
791 ret = uart_add_one_port(uart_driver, port); in meson_uart_probe()
801 struct uart_port *port; in meson_uart_remove() local
803 port = platform_get_drvdata(pdev); in meson_uart_remove()
804 uart_driver = meson_uart_current(port->private_data); in meson_uart_remove()
805 uart_remove_one_port(uart_driver, port); in meson_uart_remove()