Lines Matching full:port
83 static void meson_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) in meson_uart_set_mctrl() argument
87 static unsigned int meson_uart_get_mctrl(struct uart_port *port) in meson_uart_get_mctrl() argument
92 static unsigned int meson_uart_tx_empty(struct uart_port *port) in meson_uart_tx_empty() argument
96 val = readl(port->membase + AML_UART_STATUS); in meson_uart_tx_empty()
101 static void meson_uart_stop_tx(struct uart_port *port) in meson_uart_stop_tx() argument
105 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_stop_tx()
107 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_stop_tx()
110 static void meson_uart_stop_rx(struct uart_port *port) in meson_uart_stop_rx() argument
114 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_stop_rx()
116 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_stop_rx()
119 static void meson_uart_shutdown(struct uart_port *port) in meson_uart_shutdown() argument
124 free_irq(port->irq, port); in meson_uart_shutdown()
126 spin_lock_irqsave(&port->lock, flags); in meson_uart_shutdown()
128 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_shutdown()
131 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_shutdown()
133 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_shutdown()
136 static void meson_uart_start_tx(struct uart_port *port) in meson_uart_start_tx() argument
138 struct circ_buf *xmit = &port->state->xmit; in meson_uart_start_tx()
142 if (uart_tx_stopped(port)) { in meson_uart_start_tx()
143 meson_uart_stop_tx(port); in meson_uart_start_tx()
147 while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) { in meson_uart_start_tx()
148 if (port->x_char) { in meson_uart_start_tx()
149 writel(port->x_char, port->membase + AML_UART_WFIFO); in meson_uart_start_tx()
150 port->icount.tx++; in meson_uart_start_tx()
151 port->x_char = 0; in meson_uart_start_tx()
159 writel(ch, port->membase + AML_UART_WFIFO); in meson_uart_start_tx()
161 port->icount.tx++; in meson_uart_start_tx()
165 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_start_tx()
167 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_start_tx()
171 uart_write_wakeup(port); in meson_uart_start_tx()
174 static void meson_receive_chars(struct uart_port *port) in meson_receive_chars() argument
176 struct tty_port *tport = &port->state->port; in meson_receive_chars()
182 port->icount.rx++; in meson_receive_chars()
183 ostatus = status = readl(port->membase + AML_UART_STATUS); in meson_receive_chars()
187 port->icount.overrun++; in meson_receive_chars()
189 port->icount.frame++; in meson_receive_chars()
191 port->icount.frame++; in meson_receive_chars()
193 mode = readl(port->membase + AML_UART_CONTROL); in meson_receive_chars()
195 writel(mode, port->membase + AML_UART_CONTROL); in meson_receive_chars()
199 writel(mode, port->membase + AML_UART_CONTROL); in meson_receive_chars()
201 status &= port->read_status_mask; in meson_receive_chars()
208 ch = readl(port->membase + AML_UART_RFIFO); in meson_receive_chars()
212 port->icount.brk++; in meson_receive_chars()
214 if (uart_handle_break(port)) in meson_receive_chars()
218 if (uart_handle_sysrq_char(port, ch)) in meson_receive_chars()
221 if ((status & port->ignore_status_mask) == 0) in meson_receive_chars()
227 } while (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)); in meson_receive_chars()
229 spin_unlock(&port->lock); in meson_receive_chars()
231 spin_lock(&port->lock); in meson_receive_chars()
236 struct uart_port *port = (struct uart_port *)dev_id; in meson_uart_interrupt() local
238 spin_lock(&port->lock); in meson_uart_interrupt()
240 if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)) in meson_uart_interrupt()
241 meson_receive_chars(port); in meson_uart_interrupt()
243 if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL)) { in meson_uart_interrupt()
244 if (readl(port->membase + AML_UART_CONTROL) & AML_UART_TX_INT_EN) in meson_uart_interrupt()
245 meson_uart_start_tx(port); in meson_uart_interrupt()
248 spin_unlock(&port->lock); in meson_uart_interrupt()
253 static const char *meson_uart_type(struct uart_port *port) in meson_uart_type() argument
255 return (port->type == PORT_MESON) ? "meson_uart" : NULL; in meson_uart_type()
258 static void meson_uart_reset(struct uart_port *port) in meson_uart_reset() argument
262 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_reset()
264 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_reset()
267 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_reset()
270 static int meson_uart_startup(struct uart_port *port) in meson_uart_startup() argument
275 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_startup()
277 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
279 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
282 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
285 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_startup()
287 val = (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2)); in meson_uart_startup()
288 writel(val, port->membase + AML_UART_MISC); in meson_uart_startup()
290 ret = request_irq(port->irq, meson_uart_interrupt, 0, in meson_uart_startup()
291 port->name, port); in meson_uart_startup()
296 static void meson_uart_change_speed(struct uart_port *port, unsigned long baud) in meson_uart_change_speed() argument
300 while (!meson_uart_tx_empty(port)) in meson_uart_change_speed()
303 if (port->uartclk == 24000000) { in meson_uart_change_speed()
304 val = ((port->uartclk / 3) / baud) - 1; in meson_uart_change_speed()
307 val = ((port->uartclk * 10 / (baud * 4) + 5) / 10) - 1; in meson_uart_change_speed()
310 writel(val, port->membase + AML_UART_REG5); in meson_uart_change_speed()
313 static void meson_uart_set_termios(struct uart_port *port, in meson_uart_set_termios() argument
321 spin_lock_irqsave(&port->lock, flags); in meson_uart_set_termios()
326 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_set_termios()
365 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_set_termios()
367 baud = uart_get_baud_rate(port, termios, old, 50, 4000000); in meson_uart_set_termios()
368 meson_uart_change_speed(port, baud); in meson_uart_set_termios()
370 port->read_status_mask = AML_UART_TX_FIFO_WERR; in meson_uart_set_termios()
372 port->read_status_mask |= AML_UART_PARITY_ERR | in meson_uart_set_termios()
375 port->ignore_status_mask = 0; in meson_uart_set_termios()
377 port->ignore_status_mask |= AML_UART_PARITY_ERR | in meson_uart_set_termios()
380 uart_update_timeout(port, termios->c_cflag, baud); in meson_uart_set_termios()
381 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_set_termios()
384 static int meson_uart_verify_port(struct uart_port *port, in meson_uart_verify_port() argument
389 if (port->type != PORT_MESON) in meson_uart_verify_port()
391 if (port->irq != ser->irq) in meson_uart_verify_port()
398 static void meson_uart_release_port(struct uart_port *port) in meson_uart_release_port() argument
400 devm_iounmap(port->dev, port->membase); in meson_uart_release_port()
401 port->membase = NULL; in meson_uart_release_port()
402 devm_release_mem_region(port->dev, port->mapbase, port->mapsize); in meson_uart_release_port()
405 static int meson_uart_request_port(struct uart_port *port) in meson_uart_request_port() argument
407 if (!devm_request_mem_region(port->dev, port->mapbase, port->mapsize, in meson_uart_request_port()
408 dev_name(port->dev))) { in meson_uart_request_port()
409 dev_err(port->dev, "Memory region busy\n"); in meson_uart_request_port()
413 port->membase = devm_ioremap(port->dev, port->mapbase, in meson_uart_request_port()
414 port->mapsize); in meson_uart_request_port()
415 if (!port->membase) in meson_uart_request_port()
421 static void meson_uart_config_port(struct uart_port *port, int flags) in meson_uart_config_port() argument
424 port->type = PORT_MESON; in meson_uart_config_port()
425 meson_uart_request_port(port); in meson_uart_config_port()
435 static int meson_uart_poll_get_char(struct uart_port *port) in meson_uart_poll_get_char() argument
440 spin_lock_irqsave(&port->lock, flags); in meson_uart_poll_get_char()
442 if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY) in meson_uart_poll_get_char()
445 c = readl(port->membase + AML_UART_RFIFO); in meson_uart_poll_get_char()
447 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_poll_get_char()
452 static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c) in meson_uart_poll_put_char() argument
458 spin_lock_irqsave(&port->lock, flags); in meson_uart_poll_put_char()
461 ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, in meson_uart_poll_put_char()
466 dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); in meson_uart_poll_put_char()
471 writel(c, port->membase + AML_UART_WFIFO); in meson_uart_poll_put_char()
474 ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg, in meson_uart_poll_put_char()
479 dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n"); in meson_uart_poll_put_char()
482 spin_unlock_irqrestore(&port->lock, flags); in meson_uart_poll_put_char()
509 static void meson_uart_enable_tx_engine(struct uart_port *port) in meson_uart_enable_tx_engine() argument
513 val = readl(port->membase + AML_UART_CONTROL); in meson_uart_enable_tx_engine()
515 writel(val, port->membase + AML_UART_CONTROL); in meson_uart_enable_tx_engine()
518 static void meson_console_putchar(struct uart_port *port, int ch) in meson_console_putchar() argument
520 if (!port->membase) in meson_console_putchar()
523 while (readl(port->membase + AML_UART_STATUS) & AML_UART_TX_FULL) in meson_console_putchar()
525 writel(ch, port->membase + AML_UART_WFIFO); in meson_console_putchar()
528 static void meson_serial_port_write(struct uart_port *port, const char *s, in meson_serial_port_write() argument
536 if (port->sysrq) { in meson_serial_port_write()
539 locked = spin_trylock(&port->lock); in meson_serial_port_write()
541 spin_lock(&port->lock); in meson_serial_port_write()
545 val = readl(port->membase + AML_UART_CONTROL); in meson_serial_port_write()
547 writel(tmp, port->membase + AML_UART_CONTROL); in meson_serial_port_write()
549 uart_console_write(port, s, count, meson_console_putchar); in meson_serial_port_write()
550 writel(val, port->membase + AML_UART_CONTROL); in meson_serial_port_write()
553 spin_unlock(&port->lock); in meson_serial_port_write()
560 struct uart_port *port; in meson_serial_console_write() local
562 port = meson_ports[co->index]; in meson_serial_console_write()
563 if (!port) in meson_serial_console_write()
566 meson_serial_port_write(port, s, count); in meson_serial_console_write()
571 struct uart_port *port; in meson_serial_console_setup() local
580 port = meson_ports[co->index]; in meson_serial_console_setup()
581 if (!port || !port->membase) in meson_serial_console_setup()
584 meson_uart_enable_tx_engine(port); in meson_serial_console_setup()
589 return uart_set_options(port, co, baud, parity, bits, flow); in meson_serial_console_setup()
615 meson_serial_port_write(&dev->port, s, count); in meson_serial_early_console_write()
621 if (!device->port.membase) in meson_serial_early_console_setup()
624 meson_uart_enable_tx_engine(&device->port); in meson_serial_early_console_setup()
677 struct uart_port *port) in meson_uart_probe_clocks_legacy() argument
685 port->uartclk = clk_get_rate(clk); in meson_uart_probe_clocks_legacy()
691 struct uart_port *port) in meson_uart_probe_clocks() argument
709 port->uartclk = clk_get_rate(clk_baud); in meson_uart_probe_clocks()
717 struct uart_port *port; in meson_uart_probe() local
745 dev_err(&pdev->dev, "port %d already allocated\n", pdev->id); in meson_uart_probe()
749 port = devm_kzalloc(&pdev->dev, sizeof(struct uart_port), GFP_KERNEL); in meson_uart_probe()
750 if (!port) in meson_uart_probe()
755 ret = meson_uart_probe_clocks_legacy(pdev, port); in meson_uart_probe()
757 ret = meson_uart_probe_clocks(pdev, port); in meson_uart_probe()
762 port->iotype = UPIO_MEM; in meson_uart_probe()
763 port->mapbase = res_mem->start; in meson_uart_probe()
764 port->mapsize = resource_size(res_mem); in meson_uart_probe()
765 port->irq = res_irq->start; in meson_uart_probe()
766 port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY; in meson_uart_probe()
767 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE); in meson_uart_probe()
768 port->dev = &pdev->dev; in meson_uart_probe()
769 port->line = pdev->id; in meson_uart_probe()
770 port->type = PORT_MESON; in meson_uart_probe()
771 port->x_char = 0; in meson_uart_probe()
772 port->ops = &meson_uart_ops; in meson_uart_probe()
773 port->fifosize = 64; in meson_uart_probe()
775 meson_ports[pdev->id] = port; in meson_uart_probe()
776 platform_set_drvdata(pdev, port); in meson_uart_probe()
778 /* reset port before registering (and possibly registering console) */ in meson_uart_probe()
779 if (meson_uart_request_port(port) >= 0) { in meson_uart_probe()
780 meson_uart_reset(port); in meson_uart_probe()
781 meson_uart_release_port(port); in meson_uart_probe()
784 ret = uart_add_one_port(&meson_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_remove_one_port(&meson_uart_driver, port); in meson_uart_remove()
848 MODULE_DESCRIPTION("Amlogic Meson serial port driver");