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 circ_buf *xmit = &port->state->xmit; 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()
95 count = port->fifosize - in mlb_usio_tx_chars()
96 (readw(port->membase + MLB_USIO_REG_FBYTE) & 0xff); in mlb_usio_tx_chars()
99 writew(xmit->buf[xmit->tail], port->membase + MLB_USIO_REG_DR); in mlb_usio_tx_chars()
105 } while (--count > 0); in mlb_usio_tx_chars()
107 writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FDRQ, in mlb_usio_tx_chars()
108 port->membase + MLB_USIO_REG_FCR); in mlb_usio_tx_chars()
110 writeb(readb(port->membase + MLB_USIO_REG_SCR) | MLB_USIO_SCR_TBIE, in mlb_usio_tx_chars()
111 port->membase + MLB_USIO_REG_SCR); in mlb_usio_tx_chars()
122 u16 fcr = readw(port->membase + MLB_USIO_REG_FCR); in mlb_usio_start_tx()
124 writew(fcr | MLB_USIO_FCR_FTIE, port->membase + MLB_USIO_REG_FCR); in mlb_usio_start_tx()
128 writeb(readb(port->membase + MLB_USIO_REG_SCR) | MLB_USIO_SCR_TBIE, in mlb_usio_start_tx()
129 port->membase + MLB_USIO_REG_SCR); in mlb_usio_start_tx()
131 if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) in mlb_usio_start_tx()
137 writeb(readb(port->membase + MLB_USIO_REG_SCR) & ~MLB_USIO_SCR_RIE, in mlb_usio_stop_rx()
138 port->membase + MLB_USIO_REG_SCR); in mlb_usio_stop_rx()
143 writeb(readb(port->membase + MLB_USIO_REG_SCR) | in mlb_usio_enable_ms()
145 port->membase + MLB_USIO_REG_SCR); in mlb_usio_enable_ms()
150 struct tty_port *ttyport = &port->state->port; in mlb_usio_rx_chars()
155 while (max_count--) { in mlb_usio_rx_chars()
156 status = readb(port->membase + MLB_USIO_REG_SSR); in mlb_usio_rx_chars()
163 ch = readw(port->membase + MLB_USIO_REG_DR); in mlb_usio_rx_chars()
165 port->icount.rx++; in mlb_usio_rx_chars()
173 port->icount.parity++; in mlb_usio_rx_chars()
175 port->icount.overrun++; in mlb_usio_rx_chars()
176 status &= port->read_status_mask; in mlb_usio_rx_chars()
193 writeb(readb(port->membase + MLB_USIO_REG_SSR) | in mlb_usio_rx_chars()
195 port->membase + MLB_USIO_REG_SSR); in mlb_usio_rx_chars()
197 max_count = readw(port->membase + MLB_USIO_REG_FBYTE) >> 8; in mlb_usio_rx_chars()
198 writew(readw(port->membase + MLB_USIO_REG_FCR) | in mlb_usio_rx_chars()
200 port->membase + MLB_USIO_REG_FCR); in mlb_usio_rx_chars()
210 spin_lock(&port->lock); in mlb_usio_rx_irq()
212 spin_unlock(&port->lock); in mlb_usio_rx_irq()
221 spin_lock(&port->lock); in mlb_usio_tx_irq()
222 if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) in mlb_usio_tx_irq()
224 spin_unlock(&port->lock); in mlb_usio_tx_irq()
231 return (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) ? in mlb_usio_tx_empty()
251 const char *portname = to_platform_device(port->dev)->name; in mlb_usio_startup()
253 int ret, index = port->line; in mlb_usio_startup()
267 escr = readb(port->membase + MLB_USIO_REG_ESCR); in mlb_usio_startup()
268 if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) in mlb_usio_startup()
270 spin_lock_irqsave(&port->lock, flags); in mlb_usio_startup()
271 writeb(0, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
272 writeb(escr, port->membase + MLB_USIO_REG_ESCR); in mlb_usio_startup()
273 writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
274 writeb(MLB_USIO_SSR_REC, port->membase + MLB_USIO_REG_SSR); in mlb_usio_startup()
275 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
277 port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
279 port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
280 writew(0, port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_startup()
281 writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_startup()
284 MLB_USIO_SCR_RXE, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
285 spin_unlock_irqrestore(&port->lock, flags); in mlb_usio_startup()
292 int index = port->line; in mlb_usio_shutdown()
303 unsigned long flags, baud, quot; in mlb_usio_set_termios() local
305 switch (termios->c_cflag & CSIZE) { in mlb_usio_set_termios()
321 if (termios->c_cflag & CSTOPB) in mlb_usio_set_termios()
324 if (termios->c_cflag & PARENB) { in mlb_usio_set_termios()
326 if (termios->c_cflag & PARODD) in mlb_usio_set_termios()
330 if (of_property_read_bool(port->dev->of_node, "auto-flow-control") || in mlb_usio_set_termios()
331 (termios->c_cflag & CRTSCTS)) in mlb_usio_set_termios()
334 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk); in mlb_usio_set_termios()
335 if (baud > 1) in mlb_usio_set_termios()
336 quot = port->uartclk / baud - 1; in mlb_usio_set_termios()
340 spin_lock_irqsave(&port->lock, flags); in mlb_usio_set_termios()
341 uart_update_timeout(port, termios->c_cflag, baud); in mlb_usio_set_termios()
342 port->read_status_mask = MLB_USIO_SSR_ORE | MLB_USIO_SSR_RDRF | in mlb_usio_set_termios()
344 if (termios->c_iflag & INPCK) in mlb_usio_set_termios()
345 port->read_status_mask |= MLB_USIO_SSR_FRE | MLB_USIO_SSR_PE; in mlb_usio_set_termios()
347 port->ignore_status_mask = 0; in mlb_usio_set_termios()
348 if (termios->c_iflag & IGNPAR) in mlb_usio_set_termios()
349 port->ignore_status_mask |= MLB_USIO_SSR_FRE | MLB_USIO_SSR_PE; in mlb_usio_set_termios()
350 if ((termios->c_iflag & IGNBRK) && (termios->c_iflag & IGNPAR)) in mlb_usio_set_termios()
351 port->ignore_status_mask |= MLB_USIO_SSR_ORE; in mlb_usio_set_termios()
352 if ((termios->c_cflag & CREAD) == 0) in mlb_usio_set_termios()
353 port->ignore_status_mask |= MLB_USIO_SSR_RDRF; in mlb_usio_set_termios()
355 writeb(0, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
356 writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
357 writeb(MLB_USIO_SSR_REC, port->membase + MLB_USIO_REG_SSR); in mlb_usio_set_termios()
358 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
359 writeb(smr, port->membase + MLB_USIO_REG_SMR); in mlb_usio_set_termios()
360 writeb(escr, port->membase + MLB_USIO_REG_ESCR); in mlb_usio_set_termios()
361 writew(quot, port->membase + MLB_USIO_REG_BGR); in mlb_usio_set_termios()
362 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
365 port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
366 writew(0, port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_set_termios()
367 writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_set_termios()
369 MLB_USIO_SCR_TXE, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
370 spin_unlock_irqrestore(&port->lock, flags); in mlb_usio_set_termios()
375 return ((port->type == PORT_MLB_USIO) ? USIO_NAME : NULL); in mlb_usio_type()
381 port->type = PORT_MLB_USIO; in mlb_usio_config_port()
404 while (!(readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TDRE)) in mlb_usio_console_putchar()
407 writew(c, port->membase + MLB_USIO_REG_DR); in mlb_usio_console_putchar()
413 struct uart_port *port = &mlb_usio_ports[co->index]; in mlb_usio_console_write()
421 int baud = 115200; in mlb_usio_console_setup() local
426 if (co->index >= CONFIG_SERIAL_MILBEAUT_USIO_PORTS) in mlb_usio_console_setup()
427 return -ENODEV; in mlb_usio_console_setup()
429 port = &mlb_usio_ports[co->index]; in mlb_usio_console_setup()
430 if (!port->membase) in mlb_usio_console_setup()
431 return -ENODEV; in mlb_usio_console_setup()
435 uart_parse_options(options, &baud, &parity, &bits, &flow); in mlb_usio_console_setup()
437 if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) in mlb_usio_console_setup()
440 return uart_set_options(port, co, baud, parity, bits, flow); in mlb_usio_console_setup()
451 .index = -1,
466 struct earlycon_device *dev = co->data; in mlb_usio_early_console_write()
468 uart_console_write(&dev->port, s, count, mlb_usio_console_putchar); in mlb_usio_early_console_write()
474 if (!device->port.membase) in mlb_usio_early_console_setup()
475 return -ENODEV; in mlb_usio_early_console_setup()
476 device->con->write = mlb_usio_early_console_write; in mlb_usio_early_console_setup()
480 OF_EARLYCON_DECLARE(mlb_usio, "socionext,milbeaut-usio-uart",
498 struct clk *clk = devm_clk_get(&pdev->dev, NULL); in mlb_usio_probe()
505 dev_err(&pdev->dev, "Missing clock\n"); in mlb_usio_probe()
510 dev_err(&pdev->dev, "Clock enable failed: %d\n", ret); in mlb_usio_probe()
513 of_property_read_u32(pdev->dev.of_node, "index", &index); in mlb_usio_probe()
516 port->private_data = (void *)clk; in mlb_usio_probe()
519 dev_err(&pdev->dev, "Missing regs\n"); in mlb_usio_probe()
520 ret = -ENODEV; in mlb_usio_probe()
523 port->membase = devm_ioremap(&pdev->dev, res->start, in mlb_usio_probe()
532 port->irq = mlb_usio_irq[index][RX]; in mlb_usio_probe()
533 port->uartclk = clk_get_rate(clk); in mlb_usio_probe()
534 port->fifosize = 128; in mlb_usio_probe()
535 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MILBEAUT_USIO_CONSOLE); in mlb_usio_probe()
536 port->iotype = UPIO_MEM32; in mlb_usio_probe()
537 port->flags = UPF_BOOT_AUTOCONF | UPF_SPD_VHI; in mlb_usio_probe()
538 port->line = index; in mlb_usio_probe()
539 port->ops = &mlb_usio_ops; in mlb_usio_probe()
540 port->dev = &pdev->dev; in mlb_usio_probe()
544 dev_err(&pdev->dev, "Adding port failed: %d\n", ret); in mlb_usio_probe()
557 struct uart_port *port = &mlb_usio_ports[pdev->id]; in mlb_usio_remove()
558 struct clk *clk = port->private_data; in mlb_usio_remove()
567 { .compatible = "socionext,milbeaut-usio-uart" },