Lines Matching +full:port +full:-
1 // SPDX-License-Identifier: GPL-2.0
15 #define USIO_NAME "mlb-usio-uart"
65 static void mlb_usio_stop_tx(struct uart_port *port) in mlb_usio_stop_tx() argument
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()
73 static void mlb_usio_tx_chars(struct uart_port *port) in mlb_usio_tx_chars() argument
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()
90 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { in mlb_usio_tx_chars()
91 mlb_usio_stop_tx(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()
99 writew(xmit->buf[xmit->tail], port->membase + MLB_USIO_REG_DR); in mlb_usio_tx_chars()
101 uart_xmit_advance(port, 1); 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()
114 uart_write_wakeup(port); in mlb_usio_tx_chars()
117 mlb_usio_stop_tx(port); in mlb_usio_tx_chars()
120 static void mlb_usio_start_tx(struct uart_port *port) in mlb_usio_start_tx() argument
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()
132 mlb_usio_tx_chars(port); in mlb_usio_start_tx()
135 static void mlb_usio_stop_rx(struct uart_port *port) in mlb_usio_stop_rx() argument
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()
141 static void mlb_usio_enable_ms(struct uart_port *port) in mlb_usio_enable_ms() argument
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()
148 static void mlb_usio_rx_chars(struct uart_port *port) in mlb_usio_rx_chars() argument
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()
166 if (uart_handle_sysrq_char(port, ch)) in mlb_usio_rx_chars()
168 uart_insert_char(port, status, MLB_USIO_SSR_ORE, 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()
190 uart_insert_char(port, status, MLB_USIO_SSR_ORE, 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()
208 struct uart_port *port = dev_id; in mlb_usio_rx_irq() local
210 spin_lock(&port->lock); in mlb_usio_rx_irq()
211 mlb_usio_rx_chars(port); in mlb_usio_rx_irq()
212 spin_unlock(&port->lock); in mlb_usio_rx_irq()
219 struct uart_port *port = dev_id; in mlb_usio_tx_irq() local
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()
223 mlb_usio_tx_chars(port); in mlb_usio_tx_irq()
224 spin_unlock(&port->lock); in mlb_usio_tx_irq()
229 static unsigned int mlb_usio_tx_empty(struct uart_port *port) in mlb_usio_tx_empty() argument
231 return (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) ? in mlb_usio_tx_empty()
235 static void mlb_usio_set_mctrl(struct uart_port *port, unsigned int mctrl) in mlb_usio_set_mctrl() argument
239 static unsigned int mlb_usio_get_mctrl(struct uart_port *port) in mlb_usio_get_mctrl() argument
245 static void mlb_usio_break_ctl(struct uart_port *port, int break_state) in mlb_usio_break_ctl() argument
249 static int mlb_usio_startup(struct uart_port *port) in mlb_usio_startup() argument
251 const char *portname = to_platform_device(port->dev)->name; in mlb_usio_startup()
253 int ret, index = port->line; in mlb_usio_startup()
257 0, portname, port); in mlb_usio_startup()
261 0, portname, port); in mlb_usio_startup()
263 free_irq(mlb_usio_irq[index][RX], port); 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()
290 static void mlb_usio_shutdown(struct uart_port *port) in mlb_usio_shutdown() argument
292 int index = port->line; in mlb_usio_shutdown()
294 free_irq(mlb_usio_irq[index][RX], port); in mlb_usio_shutdown()
295 free_irq(mlb_usio_irq[index][TX], port); in mlb_usio_shutdown()
298 static void mlb_usio_set_termios(struct uart_port *port, in mlb_usio_set_termios() argument
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()
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()
373 static const char *mlb_usio_type(struct uart_port *port) in mlb_usio_type() argument
375 return ((port->type == PORT_MLB_USIO) ? USIO_NAME : NULL); in mlb_usio_type()
378 static void mlb_usio_config_port(struct uart_port *port, int flags) in mlb_usio_config_port() argument
381 port->type = PORT_MLB_USIO; in mlb_usio_config_port()
402 static void mlb_usio_console_putchar(struct uart_port *port, unsigned char c) in mlb_usio_console_putchar() argument
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() local
415 uart_console_write(port, s, count, mlb_usio_console_putchar); in mlb_usio_console_write()
420 struct uart_port *port; 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()
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()
499 struct uart_port *port; in mlb_usio_probe() local
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()
514 port = &mlb_usio_ports[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()
542 ret = uart_add_one_port(&mlb_usio_uart_driver, port); 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() local
558 struct clk *clk = port->private_data; in mlb_usio_remove()
560 uart_remove_one_port(&mlb_usio_uart_driver, port); in mlb_usio_remove()
567 { .compatible = "socionext,milbeaut-usio-uart" },