Lines Matching full: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 uart_port_lock_irqsave(port, &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 uart_port_unlock_irqrestore(port, flags); in meson_uart_shutdown()
142 static void meson_uart_start_tx(struct uart_port *port) in meson_uart_start_tx() argument
144 struct tty_port *tport = &port->state->port; 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()
161 if (!uart_fifo_get(port, &ch)) in meson_uart_start_tx()
164 writel(ch, port->membase + AML_UART_WFIFO); in meson_uart_start_tx()
168 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_start_tx()
170 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_start_tx()
174 uart_write_wakeup(port); in meson_uart_start_tx()
177 static void meson_receive_chars(struct uart_port *port) in meson_receive_chars() argument
179 struct tty_port *tport = &port->state->port; in meson_receive_chars()
185 port->icount.rx++; in meson_receive_chars()
186 ostatus = status = readl(port->membase + AML_UART_STATUS); in meson_receive_chars()
190 port->icount.overrun++; in meson_receive_chars()
192 port->icount.frame++; in meson_receive_chars()
194 port->icount.frame++; in meson_receive_chars()
196 mode = readl(port->membase + AML_UART_CONTROL); in meson_receive_chars()
198 writel(mode, port->membase + AML_UART_CONTROL); in meson_receive_chars()
202 writel(mode, port->membase + AML_UART_CONTROL); in meson_receive_chars()
204 status &= port->read_status_mask; in meson_receive_chars()
211 ch = readl(port->membase + AML_UART_RFIFO); in meson_receive_chars()
215 port->icount.brk++; in meson_receive_chars()
217 if (uart_handle_break(port)) in meson_receive_chars()
221 if (uart_prepare_sysrq_char(port, ch)) in meson_receive_chars()
224 if ((status & port->ignore_status_mask) == 0) in meson_receive_chars()
230 } while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)); in meson_receive_chars()
237 struct uart_port *port = (struct uart_port *)dev_id; in meson_uart_interrupt() local
239 uart_port_lock(port); in meson_uart_interrupt()
241 if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)) in meson_uart_interrupt()
242 meson_receive_chars(port); in meson_uart_interrupt()
244 if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) { in meson_uart_interrupt()
245 if (readl(port->membase + AML_UART_CONTROL) & AML_UART_TX_INT_EN) in meson_uart_interrupt()
246 meson_uart_start_tx(port); in meson_uart_interrupt()
249 uart_unlock_and_check_sysrq(port); in meson_uart_interrupt()
254 static const char *meson_uart_type(struct uart_port *port) in meson_uart_type() argument
256 return (port->type == PORT_MESON) ? "meson_uart" : NULL; in meson_uart_type()
263 * console on this port at this time. Hence it is not necessary for this
264 * function to acquire the port->lock. (Since there is no console on this
265 * port at this time, the port->lock is not initialized yet.)
267 static void meson_uart_reset(struct uart_port *port) in meson_uart_reset() argument
271 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_reset()
273 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_reset()
276 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_reset()
279 static int meson_uart_startup(struct uart_port *port) in meson_uart_startup() argument
285 uart_port_lock_irqsave(port, &flags); in meson_uart_startup()
287 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_startup()
289 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
291 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
294 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
297 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
299 val = (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2)); in meson_uart_startup()
300 writel(val, port->membase + AML_UART_MISC); in meson_uart_startup()
302 uart_port_unlock_irqrestore(port, flags); in meson_uart_startup()
304 ret = request_irq(port->irq, meson_uart_interrupt, 0, in meson_uart_startup()
305 port->name, port); in meson_uart_startup()
310 static void meson_uart_change_speed(struct uart_port *port, unsigned long baud) in meson_uart_change_speed() argument
312 const struct meson_uart_data *private_data = port->private_data; in meson_uart_change_speed()
315 while (!meson_uart_tx_empty(port)) in meson_uart_change_speed()
318 if (port->uartclk == 24000000) { in meson_uart_change_speed()
325 val |= DIV_ROUND_CLOSEST(port->uartclk / xtal_div, baud) - 1; in meson_uart_change_speed()
328 val = DIV_ROUND_CLOSEST(port->uartclk / 4, baud) - 1; in meson_uart_change_speed()
331 writel(val, port->membase + AML_UART_REG5); in meson_uart_change_speed()
334 static void meson_uart_set_termios(struct uart_port *port, in meson_uart_set_termios() argument
342 uart_port_lock_irqsave(port, &flags); in meson_uart_set_termios()
347 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_set_termios()
382 if (port->flags & UPF_HARD_FLOW) in meson_uart_set_termios()
390 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_set_termios()
392 baud = uart_get_baud_rate(port, termios, old, 50, 4000000); in meson_uart_set_termios()
393 meson_uart_change_speed(port, baud); in meson_uart_set_termios()
395 port->read_status_mask = AML_UART_TX_FIFO_WERR; in meson_uart_set_termios()
397 port->read_status_mask |= AML_UART_PARITY_ERR | in meson_uart_set_termios()
400 port->ignore_status_mask = 0; in meson_uart_set_termios()
402 port->ignore_status_mask |= AML_UART_PARITY_ERR | in meson_uart_set_termios()
405 uart_update_timeout(port, termios->c_cflag, baud); in meson_uart_set_termios()
406 uart_port_unlock_irqrestore(port, flags); in meson_uart_set_termios()
409 static int meson_uart_verify_port(struct uart_port *port, in meson_uart_verify_port() argument
414 if (port->type != PORT_MESON) in meson_uart_verify_port()
416 if (port->irq != ser->irq) in meson_uart_verify_port()
423 static void meson_uart_release_port(struct uart_port *port) in meson_uart_release_port() argument
425 devm_iounmap(port->dev, port->membase); in meson_uart_release_port()
426 port->membase = NULL; in meson_uart_release_port()
427 devm_release_mem_region(port->dev, port->mapbase, port->mapsize); in meson_uart_release_port()
430 static int meson_uart_request_port(struct uart_port *port) in meson_uart_request_port() argument
432 if (!devm_request_mem_region(port->dev, port->mapbase, port->mapsize, in meson_uart_request_port()
433 dev_name(port->dev))) { in meson_uart_request_port()
434 dev_err(port->dev, "Memory region busy\n"); in meson_uart_request_port()
438 port->membase = devm_ioremap(port->dev, port->mapbase, in meson_uart_request_port()
439 port->mapsize); in meson_uart_request_port()
440 if (!port->membase) in meson_uart_request_port()
446 static void meson_uart_config_port(struct uart_port *port, int flags) in meson_uart_config_port() argument
449 port->type = PORT_MESON; in meson_uart_config_port()
450 meson_uart_request_port(port); in meson_uart_config_port()
460 static int meson_uart_poll_get_char(struct uart_port *port) in meson_uart_poll_get_char() argument
465 uart_port_lock_irqsave(port, &flags); in meson_uart_poll_get_char()
467 if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY) in meson_uart_poll_get_char()
470 c = readl(port->membase + AML_UART_RFIFO); in meson_uart_poll_get_char()
472 uart_port_unlock_irqrestore(port, flags); in meson_uart_poll_get_char()
477 static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c) in meson_uart_poll_put_char() argument
483 uart_port_lock_irqsave(port, &flags); in meson_uart_poll_put_char()
486 ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, in meson_uart_poll_put_char()
491 dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); in meson_uart_poll_put_char()
496 writel(c, port->membase + AML_UART_WFIFO); in meson_uart_poll_put_char()
499 ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, in meson_uart_poll_put_char()
504 dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); in meson_uart_poll_put_char()
507 uart_port_unlock_irqrestore(port, flags); in meson_uart_poll_put_char()
534 static void meson_uart_enable_tx_engine(struct uart_port *port) in meson_uart_enable_tx_engine() argument
538 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_enable_tx_engine()
540 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_enable_tx_engine()
543 static void meson_console_putchar(struct uart_port *port, unsigned char ch) in meson_console_putchar() argument
545 if (!port->membase) in meson_console_putchar()
548 while (readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL) in meson_console_putchar()
550 writel(ch, port->membase + AML_UART_WFIFO); in meson_console_putchar()
553 static void meson_serial_port_write(struct uart_port *port, const char *s, in meson_serial_port_write() argument
561 locked = uart_port_trylock_irqsave(port, &flags); in meson_serial_port_write()
563 uart_port_lock_irqsave(port, &flags); in meson_serial_port_write()
565 val = readl(port->membase + AML_UART_CONTROL); in meson_serial_port_write()
567 writel(tmp, port->membase + AML_UART_CONTROL); in meson_serial_port_write()
569 uart_console_write(port, s, count, meson_console_putchar); in meson_serial_port_write()
570 writel(val, port->membase + AML_UART_CONTROL); in meson_serial_port_write()
573 uart_port_unlock_irqrestore(port, flags); in meson_serial_port_write()
579 struct uart_port *port; in meson_serial_console_write() local
581 port = meson_ports[co->index]; in meson_serial_console_write()
582 if (!port) in meson_serial_console_write()
585 meson_serial_port_write(port, s, count); in meson_serial_console_write()
590 struct uart_port *port; in meson_serial_console_setup() local
599 port = meson_ports[co->index]; in meson_serial_console_setup()
600 if (!port || !port->membase) in meson_serial_console_setup()
603 meson_uart_enable_tx_engine(port); in meson_serial_console_setup()
608 return uart_set_options(port, co, baud, parity, bits, flow); in meson_serial_console_setup()
631 meson_serial_port_write(&dev->port, s, count); in meson_serial_early_console_write()
637 if (!device->port.membase) in meson_serial_early_console_setup()
640 meson_uart_enable_tx_engine(&device->port); in meson_serial_early_console_setup()
666 struct uart_port *port) in meson_uart_probe_clocks() argument
684 port->uartclk = clk_get_rate(clk_baud); in meson_uart_probe_clocks()
700 struct uart_port *port; in meson_uart_probe() local
736 "port %d already allocated\n", pdev->id); in meson_uart_probe()
739 port = devm_kzalloc(&pdev->dev, sizeof(struct uart_port), GFP_KERNEL); in meson_uart_probe()
740 if (!port) in meson_uart_probe()
743 ret = meson_uart_probe_clocks(pdev, port); in meson_uart_probe()
758 port->iotype = UPIO_MEM; in meson_uart_probe()
759 port->mapbase = res_mem->start; in meson_uart_probe()
760 port->mapsize = resource_size(res_mem); in meson_uart_probe()
761 port->irq = irq; in meson_uart_probe()
762 port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY; in meson_uart_probe()
764 port->flags |= UPF_HARD_FLOW; in meson_uart_probe()
765 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE); in meson_uart_probe()
766 port->dev = &pdev->dev; in meson_uart_probe()
767 port->line = pdev->id; in meson_uart_probe()
768 port->type = PORT_MESON; in meson_uart_probe()
769 port->x_char = 0; in meson_uart_probe()
770 port->ops = &meson_uart_ops; in meson_uart_probe()
771 port->fifosize = fifosize; in meson_uart_probe()
772 port->private_data = (void *)priv_data; in meson_uart_probe()
774 meson_ports[pdev->id] = port; in meson_uart_probe()
775 platform_set_drvdata(pdev, port); in meson_uart_probe()
777 /* reset port before registering (and possibly registering console) */ in meson_uart_probe()
778 if (meson_uart_request_port(port) >= 0) { in meson_uart_probe()
779 meson_uart_reset(port); in meson_uart_probe()
780 meson_uart_release_port(port); in meson_uart_probe()
783 ret = uart_add_one_port(uart_driver, port); in meson_uart_probe()
793 struct uart_port *port; in meson_uart_remove() local
795 port = platform_get_drvdata(pdev); in meson_uart_remove()
796 uart_driver = meson_uart_current(port->private_data); in meson_uart_remove()
797 uart_remove_one_port(uart_driver, port); in meson_uart_remove()
855 MODULE_DESCRIPTION("Amlogic Meson serial port driver");