Lines Matching +full:milbeaut +full:- +full:usio +full:- +full:uart
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()
101 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in mlb_usio_tx_chars()
102 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()
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()
157 while (max_count--) { in mlb_usio_rx_chars()
158 status = readb(port->membase + MLB_USIO_REG_SSR); in mlb_usio_rx_chars()
165 ch = readw(port->membase + MLB_USIO_REG_DR); in mlb_usio_rx_chars()
167 port->icount.rx++; in mlb_usio_rx_chars()
175 port->icount.parity++; in mlb_usio_rx_chars()
177 port->icount.overrun++; in mlb_usio_rx_chars()
178 status &= port->read_status_mask; in mlb_usio_rx_chars()
195 writeb(readb(port->membase + MLB_USIO_REG_SSR) | in mlb_usio_rx_chars()
197 port->membase + MLB_USIO_REG_SSR); in mlb_usio_rx_chars()
199 max_count = readw(port->membase + MLB_USIO_REG_FBYTE) >> 8; in mlb_usio_rx_chars()
200 writew(readw(port->membase + MLB_USIO_REG_FCR) | in mlb_usio_rx_chars()
202 port->membase + MLB_USIO_REG_FCR); in mlb_usio_rx_chars()
212 spin_lock(&port->lock); in mlb_usio_rx_irq()
214 spin_unlock(&port->lock); in mlb_usio_rx_irq()
223 spin_lock(&port->lock); in mlb_usio_tx_irq()
224 if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) in mlb_usio_tx_irq()
226 spin_unlock(&port->lock); in mlb_usio_tx_irq()
233 return (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) ? in mlb_usio_tx_empty()
253 const char *portname = to_platform_device(port->dev)->name; in mlb_usio_startup()
255 int ret, index = port->line; in mlb_usio_startup()
269 escr = readb(port->membase + MLB_USIO_REG_ESCR); in mlb_usio_startup()
270 if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) in mlb_usio_startup()
272 spin_lock_irqsave(&port->lock, flags); in mlb_usio_startup()
273 writeb(0, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
274 writeb(escr, port->membase + MLB_USIO_REG_ESCR); in mlb_usio_startup()
275 writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
276 writeb(MLB_USIO_SSR_REC, port->membase + MLB_USIO_REG_SSR); in mlb_usio_startup()
277 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
279 port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
281 port->membase + MLB_USIO_REG_FCR); in mlb_usio_startup()
282 writew(0, port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_startup()
283 writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_startup()
286 MLB_USIO_SCR_RXE, port->membase + MLB_USIO_REG_SCR); in mlb_usio_startup()
287 spin_unlock_irqrestore(&port->lock, flags); in mlb_usio_startup()
294 int index = port->line; in mlb_usio_shutdown()
307 switch (termios->c_cflag & CSIZE) { in mlb_usio_set_termios()
323 if (termios->c_cflag & CSTOPB) in mlb_usio_set_termios()
326 if (termios->c_cflag & PARENB) { in mlb_usio_set_termios()
328 if (termios->c_cflag & PARODD) in mlb_usio_set_termios()
332 if (of_property_read_bool(port->dev->of_node, "auto-flow-control") || in mlb_usio_set_termios()
333 (termios->c_cflag & CRTSCTS)) in mlb_usio_set_termios()
336 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk); in mlb_usio_set_termios()
338 quot = port->uartclk / baud - 1; in mlb_usio_set_termios()
342 spin_lock_irqsave(&port->lock, flags); in mlb_usio_set_termios()
343 uart_update_timeout(port, termios->c_cflag, baud); in mlb_usio_set_termios()
344 port->read_status_mask = MLB_USIO_SSR_ORE | MLB_USIO_SSR_RDRF | in mlb_usio_set_termios()
346 if (termios->c_iflag & INPCK) in mlb_usio_set_termios()
347 port->read_status_mask |= MLB_USIO_SSR_FRE | MLB_USIO_SSR_PE; in mlb_usio_set_termios()
349 port->ignore_status_mask = 0; in mlb_usio_set_termios()
350 if (termios->c_iflag & IGNPAR) in mlb_usio_set_termios()
351 port->ignore_status_mask |= MLB_USIO_SSR_FRE | MLB_USIO_SSR_PE; in mlb_usio_set_termios()
352 if ((termios->c_iflag & IGNBRK) && (termios->c_iflag & IGNPAR)) in mlb_usio_set_termios()
353 port->ignore_status_mask |= MLB_USIO_SSR_ORE; in mlb_usio_set_termios()
354 if ((termios->c_cflag & CREAD) == 0) in mlb_usio_set_termios()
355 port->ignore_status_mask |= MLB_USIO_SSR_RDRF; in mlb_usio_set_termios()
357 writeb(0, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
358 writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
359 writeb(MLB_USIO_SSR_REC, port->membase + MLB_USIO_REG_SSR); in mlb_usio_set_termios()
360 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
361 writeb(smr, port->membase + MLB_USIO_REG_SMR); in mlb_usio_set_termios()
362 writeb(escr, port->membase + MLB_USIO_REG_ESCR); in mlb_usio_set_termios()
363 writew(quot, port->membase + MLB_USIO_REG_BGR); in mlb_usio_set_termios()
364 writew(0, port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
367 port->membase + MLB_USIO_REG_FCR); in mlb_usio_set_termios()
368 writew(0, port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_set_termios()
369 writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); in mlb_usio_set_termios()
371 MLB_USIO_SCR_TXE, port->membase + MLB_USIO_REG_SCR); in mlb_usio_set_termios()
372 spin_unlock_irqrestore(&port->lock, flags); in mlb_usio_set_termios()
377 return ((port->type == PORT_MLB_USIO) ? USIO_NAME : NULL); in mlb_usio_type()
383 port->type = PORT_MLB_USIO; in mlb_usio_config_port()
406 while (!(readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TDRE)) in mlb_usio_console_putchar()
409 writew(c, port->membase + MLB_USIO_REG_DR); in mlb_usio_console_putchar()
415 struct uart_port *port = &mlb_usio_ports[co->index]; in mlb_usio_console_write()
428 if (co->index >= CONFIG_SERIAL_MILBEAUT_USIO_PORTS) in mlb_usio_console_setup()
429 return -ENODEV; in mlb_usio_console_setup()
431 port = &mlb_usio_ports[co->index]; in mlb_usio_console_setup()
432 if (!port->membase) in mlb_usio_console_setup()
433 return -ENODEV; in mlb_usio_console_setup()
439 if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) in mlb_usio_console_setup()
453 .index = -1,
468 struct earlycon_device *dev = co->data; in mlb_usio_early_console_write()
470 uart_console_write(&dev->port, s, count, mlb_usio_console_putchar); in mlb_usio_early_console_write()
476 if (!device->port.membase) in mlb_usio_early_console_setup()
477 return -ENODEV; in mlb_usio_early_console_setup()
478 device->con->write = mlb_usio_early_console_write; in mlb_usio_early_console_setup()
482 OF_EARLYCON_DECLARE(mlb_usio, "socionext,milbeaut-usio-uart",
500 struct clk *clk = devm_clk_get(&pdev->dev, NULL); in mlb_usio_probe()
507 dev_err(&pdev->dev, "Missing clock\n"); in mlb_usio_probe()
512 dev_err(&pdev->dev, "Clock enable failed: %d\n", ret); in mlb_usio_probe()
515 of_property_read_u32(pdev->dev.of_node, "index", &index); in mlb_usio_probe()
518 port->private_data = (void *)clk; in mlb_usio_probe()
521 dev_err(&pdev->dev, "Missing regs\n"); in mlb_usio_probe()
522 ret = -ENODEV; in mlb_usio_probe()
525 port->membase = devm_ioremap(&pdev->dev, res->start, in mlb_usio_probe()
534 port->irq = mlb_usio_irq[index][RX]; in mlb_usio_probe()
535 port->uartclk = clk_get_rate(clk); in mlb_usio_probe()
536 port->fifosize = 128; in mlb_usio_probe()
537 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MILBEAUT_USIO_CONSOLE); in mlb_usio_probe()
538 port->iotype = UPIO_MEM32; in mlb_usio_probe()
539 port->flags = UPF_BOOT_AUTOCONF | UPF_SPD_VHI; in mlb_usio_probe()
540 port->line = index; in mlb_usio_probe()
541 port->ops = &mlb_usio_ops; in mlb_usio_probe()
542 port->dev = &pdev->dev; in mlb_usio_probe()
546 dev_err(&pdev->dev, "Adding port failed: %d\n", ret); in mlb_usio_probe()
559 struct uart_port *port = &mlb_usio_ports[pdev->id]; in mlb_usio_remove()
560 struct clk *clk = port->private_data; in mlb_usio_remove()
569 { .compatible = "socionext,milbeaut-usio-uart" },
588 pr_err("%s: uart registration failed: %d\n", __func__, ret); in mlb_usio_init()
611 MODULE_DESCRIPTION("MILBEAUT_USIO/UART Driver");