Lines Matching +full:auto +full:- +full:baud

1 // SPDX-License-Identifier: GPL-2.0
15 #define USIO_NAME "mlb-usio-uart"
67 writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FTIE, in mlb_usio_stop_tx()
68 port->membase + MLB_USIO_REG_FCR); in mlb_usio_stop_tx()
69 writeb(readb(port->membase + MLB_USIO_REG_SCR) & ~MLB_USIO_SCR_TBIE, in mlb_usio_stop_tx()
70 port->membase + MLB_USIO_REG_SCR); in mlb_usio_stop_tx()
75 struct tty_port *tport = &port->state->port; in mlb_usio_tx_chars()
78 writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FTIE, in mlb_usio_tx_chars()
79 port->membase + MLB_USIO_REG_FCR); in mlb_usio_tx_chars()
80 writeb(readb(port->membase + MLB_USIO_REG_SCR) & in mlb_usio_tx_chars()
82 port->membase + MLB_USIO_REG_SCR); in mlb_usio_tx_chars()
84 if (port->x_char) { in mlb_usio_tx_chars()
85 writew(port->x_char, port->membase + MLB_USIO_REG_DR); in mlb_usio_tx_chars()
86 port->icount.tx++; in mlb_usio_tx_chars()
87 port->x_char = 0; in mlb_usio_tx_chars()
90 if (kfifo_is_empty(&tport->xmit_fifo) || uart_tx_stopped(port)) { in mlb_usio_tx_chars()
95 count = port->fifosize - in mlb_usio_tx_chars()
96 (readw(port->membase + MLB_USIO_REG_FBYTE) & 0xff); in mlb_usio_tx_chars()
104 writew(ch, port->membase + MLB_USIO_REG_DR); in mlb_usio_tx_chars()
105 port->icount.tx++; in mlb_usio_tx_chars()
106 } while (--count > 0); in mlb_usio_tx_chars()
108 writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FDRQ, in mlb_usio_tx_chars()
109 port->membase + MLB_USIO_REG_FCR); in mlb_usio_tx_chars()
111 writeb(readb(port->membase + MLB_USIO_REG_SCR) | MLB_USIO_SCR_TBIE, in mlb_usio_tx_chars()
112 port->membase + MLB_USIO_REG_SCR); in mlb_usio_tx_chars()
114 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in mlb_usio_tx_chars()
117 if (kfifo_is_empty(&tport->xmit_fifo)) in mlb_usio_tx_chars()
123 u16 fcr = readw(port->membase + MLB_USIO_REG_FCR); in mlb_usio_start_tx()
125 writew(fcr | MLB_USIO_FCR_FTIE, port->membase + MLB_USIO_REG_FCR); in mlb_usio_start_tx()
129 writeb(readb(port->membase + MLB_USIO_REG_SCR) | MLB_USIO_SCR_TBIE, in mlb_usio_start_tx()
130 port->membase + MLB_USIO_REG_SCR); in mlb_usio_start_tx()
132 if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) in mlb_usio_start_tx()
138 writeb(readb(port->membase + MLB_USIO_REG_SCR) & ~MLB_USIO_SCR_RIE, in mlb_usio_stop_rx()
139 port->membase + MLB_USIO_REG_SCR); in mlb_usio_stop_rx()
144 writeb(readb(port->membase + MLB_USIO_REG_SCR) | in mlb_usio_enable_ms()
146 port->membase + MLB_USIO_REG_SCR); in mlb_usio_enable_ms()
151 struct tty_port *ttyport = &port->state->port; in mlb_usio_rx_chars()
156 while (max_count--) { in mlb_usio_rx_chars()
157 status = readb(port->membase + MLB_USIO_REG_SSR); in mlb_usio_rx_chars()
164 ch = readw(port->membase + MLB_USIO_REG_DR); in mlb_usio_rx_chars()
166 port->icount.rx++; in mlb_usio_rx_chars()
174 port->icount.parity++; in mlb_usio_rx_chars()
176 port->icount.overrun++; in mlb_usio_rx_chars()
177 status &= port->read_status_mask; in mlb_usio_rx_chars()
194 writeb(readb(port->membase + MLB_USIO_REG_SSR) | in mlb_usio_rx_chars()
196 port->membase + MLB_USIO_REG_SSR); in mlb_usio_rx_chars()
198 max_count = readw(port->membase + MLB_USIO_REG_FBYTE) >> 8; in mlb_usio_rx_chars()
199 writew(readw(port->membase + MLB_USIO_REG_FCR) | in mlb_usio_rx_chars()
201 port->membase + MLB_USIO_REG_FCR); in mlb_usio_rx_chars()
223 if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) in mlb_usio_tx_irq()
232 return (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) ? in mlb_usio_tx_empty()
252 const char *portname = to_platform_device(port->dev)->name; in mlb_usio_startup()
254 int ret, index = port->line; in mlb_usio_startup()
268 escr = readb(port->membase + MLB_USIO_REG_ESCR); in mlb_usio_startup()
269 if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) in mlb_usio_startup()
272 writeb(0, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
273 writeb(escr, port->membase + MLB_USIO_REG_ESCR); in mlb_usio_startup()
274 writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
275 writeb(MLB_USIO_SSR_REC, port->membase + MLB_USIO_REG_SSR); in mlb_usio_startup()
276 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
278 port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
280 port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
281 writew(0, port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_startup()
282 writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_startup()
285 MLB_USIO_SCR_RXE, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
293 int index = port->line; in mlb_usio_shutdown()
304 unsigned long flags, baud, quot; in mlb_usio_set_termios() local
306 switch (termios->c_cflag & CSIZE) { in mlb_usio_set_termios()
322 if (termios->c_cflag & CSTOPB) in mlb_usio_set_termios()
325 if (termios->c_cflag & PARENB) { in mlb_usio_set_termios()
327 if (termios->c_cflag & PARODD) in mlb_usio_set_termios()
331 if (of_property_read_bool(port->dev->of_node, "auto-flow-control") || in mlb_usio_set_termios()
332 (termios->c_cflag & CRTSCTS)) in mlb_usio_set_termios()
335 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk); in mlb_usio_set_termios()
336 if (baud > 1) in mlb_usio_set_termios()
337 quot = port->uartclk / baud - 1; in mlb_usio_set_termios()
342 uart_update_timeout(port, termios->c_cflag, baud); in mlb_usio_set_termios()
343 port->read_status_mask = MLB_USIO_SSR_ORE | MLB_USIO_SSR_RDRF | in mlb_usio_set_termios()
345 if (termios->c_iflag & INPCK) in mlb_usio_set_termios()
346 port->read_status_mask |= MLB_USIO_SSR_FRE | MLB_USIO_SSR_PE; in mlb_usio_set_termios()
348 port->ignore_status_mask = 0; in mlb_usio_set_termios()
349 if (termios->c_iflag & IGNPAR) in mlb_usio_set_termios()
350 port->ignore_status_mask |= MLB_USIO_SSR_FRE | MLB_USIO_SSR_PE; in mlb_usio_set_termios()
351 if ((termios->c_iflag & IGNBRK) && (termios->c_iflag & IGNPAR)) in mlb_usio_set_termios()
352 port->ignore_status_mask |= MLB_USIO_SSR_ORE; in mlb_usio_set_termios()
353 if ((termios->c_cflag & CREAD) == 0) in mlb_usio_set_termios()
354 port->ignore_status_mask |= MLB_USIO_SSR_RDRF; in mlb_usio_set_termios()
356 writeb(0, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
357 writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
358 writeb(MLB_USIO_SSR_REC, port->membase + MLB_USIO_REG_SSR); in mlb_usio_set_termios()
359 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
360 writeb(smr, port->membase + MLB_USIO_REG_SMR); in mlb_usio_set_termios()
361 writeb(escr, port->membase + MLB_USIO_REG_ESCR); in mlb_usio_set_termios()
362 writew(quot, port->membase + MLB_USIO_REG_BGR); in mlb_usio_set_termios()
363 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
366 port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
367 writew(0, port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_set_termios()
368 writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_set_termios()
370 MLB_USIO_SCR_TXE, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
376 return ((port->type == PORT_MLB_USIO) ? USIO_NAME : NULL); in mlb_usio_type()
382 port->type = PORT_MLB_USIO; in mlb_usio_config_port()
405 while (!(readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TDRE)) in mlb_usio_console_putchar()
408 writew(c, port->membase + MLB_USIO_REG_DR); in mlb_usio_console_putchar()
414 struct uart_port *port = &mlb_usio_ports[co->index]; in mlb_usio_console_write()
422 int baud = 115200; in mlb_usio_console_setup() local
427 if (co->index >= CONFIG_SERIAL_MILBEAUT_USIO_PORTS) in mlb_usio_console_setup()
428 return -ENODEV; in mlb_usio_console_setup()
430 port = &mlb_usio_ports[co->index]; in mlb_usio_console_setup()
431 if (!port->membase) in mlb_usio_console_setup()
432 return -ENODEV; in mlb_usio_console_setup()
436 uart_parse_options(options, &baud, &parity, &bits, &flow); in mlb_usio_console_setup()
438 if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) in mlb_usio_console_setup()
441 return uart_set_options(port, co, baud, parity, bits, flow); in mlb_usio_console_setup()
452 .index = -1,
467 struct earlycon_device *dev = co->data; in mlb_usio_early_console_write()
469 uart_console_write(&dev->port, s, count, mlb_usio_console_putchar); in mlb_usio_early_console_write()
475 if (!device->port.membase) in mlb_usio_early_console_setup()
476 return -ENODEV; in mlb_usio_early_console_setup()
477 device->con->write = mlb_usio_early_console_write; in mlb_usio_early_console_setup()
481 OF_EARLYCON_DECLARE(mlb_usio, "socionext,milbeaut-usio-uart",
499 struct clk *clk = devm_clk_get(&pdev->dev, NULL); in mlb_usio_probe()
506 dev_err(&pdev->dev, "Missing clock\n"); in mlb_usio_probe()
511 dev_err(&pdev->dev, "Clock enable failed: %d\n", ret); in mlb_usio_probe()
514 of_property_read_u32(pdev->dev.of_node, "index", &index); in mlb_usio_probe()
517 port->private_data = (void *)clk; in mlb_usio_probe()
520 dev_err(&pdev->dev, "Missing regs\n"); in mlb_usio_probe()
521 ret = -ENODEV; in mlb_usio_probe()
524 port->membase = devm_ioremap(&pdev->dev, res->start, in mlb_usio_probe()
533 port->irq = mlb_usio_irq[index][RX]; in mlb_usio_probe()
534 port->uartclk = clk_get_rate(clk); in mlb_usio_probe()
535 port->fifosize = 128; in mlb_usio_probe()
536 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MILBEAUT_USIO_CONSOLE); in mlb_usio_probe()
537 port->iotype = UPIO_MEM32; in mlb_usio_probe()
538 port->flags = UPF_BOOT_AUTOCONF | UPF_SPD_VHI; in mlb_usio_probe()
539 port->line = index; in mlb_usio_probe()
540 port->ops = &mlb_usio_ops; in mlb_usio_probe()
541 port->dev = &pdev->dev; in mlb_usio_probe()
545 dev_err(&pdev->dev, "Adding port failed: %d\n", ret); in mlb_usio_probe()
558 struct uart_port *port = &mlb_usio_ports[pdev->id]; in mlb_usio_remove()
559 struct clk *clk = port->private_data; in mlb_usio_remove()
566 { .compatible = "socionext,milbeaut-usio-uart" },