Lines Matching +full:auto +full:- +full:baud
1 // SPDX-License-Identifier: GPL-2.0+
36 /* MA35_IER_REG - Interrupt Enable Register */
40 #define MA35_IER_RTO_IEN BIT(4) /* RX Time-out Interrupt Enable */
42 #define MA35_IER_TIME_OUT_EN BIT(11) /* RX Buffer Time-out Counter Enable */
43 #define MA35_IER_AUTO_RTS BIT(12) /* nRTS Auto-flow Control Enable */
44 #define MA35_IER_AUTO_CTS BIT(13) /* nCTS Auto-flow Control Enable */
46 /* MA35_FCR_REG - FIFO Control Register */
62 /* MA35_LCR_REG - Line Control Register */
74 /* MA35_MCR_REG - Modem Control Register */
79 /* MA35_MSR_REG - Modem Status Register */
84 /* MA35_FSR_REG - FIFO Status Register */
98 /* MA35_ISR_REG - Interrupt Status Register */
103 #define MA35_ISR_RXTO_IF BIT(4) /* RX Time-out Interrupt Flag */
105 #define MA35_ISR_WK_IF BIT(6) /* UART Wake-up Interrupt Flag */
110 /* MA35_BAUD_REG - Baud Rate Divider Register */
117 /* MA35_ALTCTL_REG - Alternate Control/Status Register */
118 #define MA35_ALTCTL_RS485AUD BIT(10) /* RS-485 Auto Direction Function */
120 /* MA35_FUN_SEL_REG - Function Select Register */
125 /* The constrain for MA35D1 UART baud rate divider */
170 return readl_relaxed(p->port.membase + offset); in serial_in()
175 writel_relaxed(value, p->port.membase + offset); in serial_out()
199 if (uart_tx_stopped(&up->port)) { in transmit_chars()
200 ma35d1serial_stop_tx(&up->port); in transmit_chars()
203 count = MA35_UART_FIFO_DEPTH - FIELD_GET(MA35_FSR_TXPTR_MSK, in transmit_chars()
205 uart_port_tx_limited(&up->port, ch, count, in transmit_chars()
241 up->port.icount.rx++; in receive_chars()
246 up->port.icount.brk++; in receive_chars()
247 if (uart_handle_break(&up->port)) in receive_chars()
251 up->port.icount.frame++; in receive_chars()
253 up->port.icount.parity++; in receive_chars()
255 up->port.icount.overrun++; in receive_chars()
269 if (uart_handle_sysrq_char(&up->port, ch)) in receive_chars()
272 uart_port_lock(&up->port); in receive_chars()
273 uart_insert_char(&up->port, fsr, MA35_FSR_RX_OVER_IF, ch, flag); in receive_chars()
274 uart_port_unlock(&up->port); in receive_chars()
277 } while (!(fsr & MA35_FSR_RX_EMPTY) && (max_count-- > 0)); in receive_chars()
279 uart_port_lock(&up->port); in receive_chars()
280 tty_flip_buffer_push(&up->port.state->port); in receive_chars()
281 uart_port_unlock(&up->port); in receive_chars()
343 if (up->mcr & UART_MCR_AFE) { in ma35d1serial_set_mctrl()
347 up->port.flags |= UPF_HARD_FLOW; in ma35d1serial_set_mctrl()
352 up->port.flags &= ~UPF_HARD_FLOW; in ma35d1serial_set_mctrl()
367 uart_port_lock_irqsave(&up->port, &flags); in ma35d1serial_break_ctl()
374 uart_port_unlock_irqrestore(&up->port, flags); in ma35d1serial_break_ctl()
389 retval = request_irq(port->irq, ma35d1serial_interrupt, 0, in ma35d1serial_startup()
390 dev_name(port->dev), port); in ma35d1serial_startup()
392 dev_err(up->port.dev, "request irq failed.\n"); in ma35d1serial_startup()
410 free_irq(port->irq, port); in ma35d1serial_shutdown()
419 u32 baud, quot; in ma35d1serial_set_termios() local
422 lcr = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag)); in ma35d1serial_set_termios()
424 if (termios->c_cflag & CSTOPB) in ma35d1serial_set_termios()
426 if (termios->c_cflag & PARENB) in ma35d1serial_set_termios()
428 if (!(termios->c_cflag & PARODD)) in ma35d1serial_set_termios()
430 if (termios->c_cflag & CMSPAR) in ma35d1serial_set_termios()
433 baud = uart_get_baud_rate(port, termios, old, in ma35d1serial_set_termios()
434 port->uartclk / MA35_BAUD_DIV_MAX, in ma35d1serial_set_termios()
435 port->uartclk / MA35_BAUD_DIV_MIN); in ma35d1serial_set_termios()
437 /* MA35D1 UART baud rate equation: baudrate = UART_CLK / (quot + 2) */ in ma35d1serial_set_termios()
438 quot = (port->uartclk / baud) - 2; in ma35d1serial_set_termios()
444 uart_port_lock_irqsave(&up->port, &flags); in ma35d1serial_set_termios()
446 up->port.read_status_mask = MA35_FSR_RX_OVER_IF; in ma35d1serial_set_termios()
447 if (termios->c_iflag & INPCK) in ma35d1serial_set_termios()
448 up->port.read_status_mask |= MA35_FSR_FEF | MA35_FSR_PEF; in ma35d1serial_set_termios()
449 if (termios->c_iflag & (BRKINT | PARMRK)) in ma35d1serial_set_termios()
450 up->port.read_status_mask |= MA35_FSR_BIF; in ma35d1serial_set_termios()
453 up->port.ignore_status_mask = 0; in ma35d1serial_set_termios()
454 if (termios->c_iflag & IGNPAR) in ma35d1serial_set_termios()
455 up->port.ignore_status_mask |= MA35_FSR_FEF | MA35_FSR_PEF; in ma35d1serial_set_termios()
456 if (termios->c_iflag & IGNBRK) { in ma35d1serial_set_termios()
457 up->port.ignore_status_mask |= MA35_FSR_BIF; in ma35d1serial_set_termios()
462 if (termios->c_iflag & IGNPAR) in ma35d1serial_set_termios()
463 up->port.ignore_status_mask |= MA35_FSR_RX_OVER_IF; in ma35d1serial_set_termios()
465 if (termios->c_cflag & CRTSCTS) in ma35d1serial_set_termios()
466 up->mcr |= UART_MCR_AFE; in ma35d1serial_set_termios()
468 up->mcr &= ~UART_MCR_AFE; in ma35d1serial_set_termios()
470 uart_update_timeout(port, termios->c_cflag, baud); in ma35d1serial_set_termios()
472 ma35d1serial_set_mctrl(&up->port, up->port.mctrl); in ma35d1serial_set_termios()
478 uart_port_unlock_irqrestore(&up->port, flags); in ma35d1serial_set_termios()
483 return "ma35d1-uart"; in ma35d1serial_type()
489 * Driver core for serial ports forces a non-zero value for port type. in ma35d1serial_config_port()
493 port->type = 1; in ma35d1serial_config_port()
498 if (port->type != PORT_UNKNOWN && ser->type != 1) in ma35d1serial_verify_port()
499 return -EINVAL; in ma35d1serial_verify_port()
521 { .compatible = "nuvoton,ma35d1-uart" },
560 if ((co->index < 0) || (co->index >= MA35_UART_NR)) { in ma35d1serial_console_write()
562 co->index); in ma35d1serial_console_write()
566 up = &ma35d1serial_ports[co->index]; in ma35d1serial_console_write()
568 if (up->port.sysrq) in ma35d1serial_console_write()
571 locked = uart_port_trylock_irqsave(&up->port, &flags); in ma35d1serial_console_write()
573 uart_port_lock_irqsave(&up->port, &flags); in ma35d1serial_console_write()
581 uart_console_write(&up->port, s, count, ma35d1serial_console_putchar); in ma35d1serial_console_write()
587 uart_port_unlock_irqrestore(&up->port, flags); in ma35d1serial_console_write()
596 int baud = 115200; in ma35d1serial_console_setup() local
601 if ((co->index < 0) || (co->index >= MA35_UART_NR)) { in ma35d1serial_console_setup()
602 pr_debug("Console Port%x out of range\n", co->index); in ma35d1serial_console_setup()
603 return -EINVAL; in ma35d1serial_console_setup()
606 np = ma35d1serial_uart_nodes[co->index]; in ma35d1serial_console_setup()
607 p = &ma35d1serial_ports[co->index]; in ma35d1serial_console_setup()
609 return -ENODEV; in ma35d1serial_console_setup()
612 return -EINVAL; in ma35d1serial_console_setup()
614 p->port.iobase = val32[1]; in ma35d1serial_console_setup()
615 p->port.membase = ioremap(p->port.iobase, MA35_UART_REG_SIZE); in ma35d1serial_console_setup()
616 if (!p->port.membase) in ma35d1serial_console_setup()
617 return -ENOMEM; in ma35d1serial_console_setup()
619 p->port.ops = &ma35d1serial_ops; in ma35d1serial_console_setup()
620 p->port.line = 0; in ma35d1serial_console_setup()
621 p->port.uartclk = MA35_UART_CONSOLE_CLK; in ma35d1serial_console_setup()
623 port = &ma35d1serial_ports[co->index].port; in ma35d1serial_console_setup()
626 uart_parse_options(options, &baud, &parity, &bits, &flow); in ma35d1serial_console_setup()
628 return uart_set_options(port, co, baud, parity, bits, flow); in ma35d1serial_console_setup()
637 .index = -1,
691 if (!pdev->dev.of_node) in ma35d1serial_probe()
692 return -ENODEV; in ma35d1serial_probe()
694 ret = of_alias_get_id(pdev->dev.of_node, "serial"); in ma35d1serial_probe()
696 dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", ret); in ma35d1serial_probe()
700 up->port.line = ret; in ma35d1serial_probe()
703 return -ENODEV; in ma35d1serial_probe()
705 up->port.iobase = res_mem->start; in ma35d1serial_probe()
706 up->port.membase = ioremap(up->port.iobase, MA35_UART_REG_SIZE); in ma35d1serial_probe()
707 if (!up->port.membase) in ma35d1serial_probe()
708 return -ENOMEM; in ma35d1serial_probe()
710 up->port.ops = &ma35d1serial_ops; in ma35d1serial_probe()
712 spin_lock_init(&up->port.lock); in ma35d1serial_probe()
714 up->clk = of_clk_get(pdev->dev.of_node, 0); in ma35d1serial_probe()
715 if (IS_ERR(up->clk)) { in ma35d1serial_probe()
716 ret = PTR_ERR(up->clk); in ma35d1serial_probe()
717 dev_err(&pdev->dev, "failed to get core clk: %d\n", ret); in ma35d1serial_probe()
721 ret = clk_prepare_enable(up->clk); in ma35d1serial_probe()
725 if (up->port.line != 0) in ma35d1serial_probe()
726 up->port.uartclk = clk_get_rate(up->clk); in ma35d1serial_probe()
732 up->port.irq = ret; in ma35d1serial_probe()
733 up->port.dev = &pdev->dev; in ma35d1serial_probe()
734 up->port.flags = UPF_BOOT_AUTOCONF; in ma35d1serial_probe()
738 ret = uart_add_one_port(&ma35d1serial_reg, &up->port); in ma35d1serial_probe()
745 free_irq(up->port.irq, &up->port); in ma35d1serial_probe()
748 clk_disable_unprepare(up->clk); in ma35d1serial_probe()
751 iounmap(up->port.membase); in ma35d1serial_probe()
764 clk_disable_unprepare(up->clk); in ma35d1serial_remove()
772 uart_suspend_port(&ma35d1serial_reg, &up->port); in ma35d1serial_suspend()
773 if (up->port.line == 0) { in ma35d1serial_suspend()
774 up->console_baud_rate = serial_in(up, MA35_BAUD_REG); in ma35d1serial_suspend()
775 up->console_line = serial_in(up, MA35_LCR_REG); in ma35d1serial_suspend()
776 up->console_int = serial_in(up, MA35_IER_REG); in ma35d1serial_suspend()
786 if (up->port.line == 0) { in ma35d1serial_resume()
787 serial_out(up, MA35_BAUD_REG, up->console_baud_rate); in ma35d1serial_resume()
788 serial_out(up, MA35_LCR_REG, up->console_line); in ma35d1serial_resume()
789 serial_out(up, MA35_IER_REG, up->console_int); in ma35d1serial_resume()
791 uart_resume_port(&ma35d1serial_reg, &up->port); in ma35d1serial_resume()
801 .name = "ma35d1-uart",