Lines Matching +full:flow +full:- +full:controlled
1 // SPDX-License-Identifier: GPL-2.0+
3 * st-asc.c: ST Asynchronous serial controller (ASC) driver
5 * Copyright (C) 2003-2013 STMicroelectronics (R&D) Limited
26 #define DRIVER_NAME "st-asc"
48 /*---- UART Register definitions ------------------------------*/
144 /*---- Inline function definitions ---------------------------*/
154 return readl_relaxed(port->membase + offset); in asc_in()
156 return readl(port->membase + offset); in asc_in()
163 writel_relaxed(value, port->membase + offset); in asc_out()
165 writel(value, port->membase + offset); in asc_out()
211 return to_platform_device(port->dev)->name; in asc_port_name()
214 /*----------------------------------------------------------------------*/
226 return port->fifosize / 2; in asc_hw_txroom()
250 struct tty_port *tport = &port->state->port; in asc_receive_chars()
257 * Datasheet states: If the MODE field selects an 8-bit frame then in asc_receive_chars()
259 * bit when reading 8-bit frames. in asc_receive_chars()
265 if (irqd_is_wakeup_set(irq_get_irq_data(port->irq))) in asc_receive_chars()
266 pm_wakeup_event(tport->tty->dev, 0); in asc_receive_chars()
271 port->icount.rx++; in asc_receive_chars()
278 port->icount.brk++; in asc_receive_chars()
283 port->icount.frame++; in asc_receive_chars()
286 port->icount.parity++; in asc_receive_chars()
293 port->icount.overrun++; in asc_receive_chars()
297 c &= port->read_status_mask; in asc_receive_chars()
342 /*----------------------------------------------------------------------*/
359 * We use ASC's hardware for CTS/RTS when hardware flow-control is in asc_set_mctrl()
361 * commonly controlled using HUP from userspace, then we need to toggle in asc_set_mctrl()
368 if (!ascport->rts) in asc_set_mctrl()
371 /* If HW flow-control is enabled, we can't fiddle with the RTS line */ in asc_set_mctrl()
375 gpiod_set_value(ascport->rts, mctrl & TIOCM_RTS); in asc_set_mctrl()
390 struct tty_port *tport = &port->state->port; in asc_start_tx()
392 if (!kfifo_is_empty(&tport->xmit_fifo)) in asc_start_tx()
408 /* Handle breaks - ignored by us */
419 if (request_irq(port->irq, asc_interrupt, 0, in asc_startup()
421 dev_err(port->dev, "cannot allocate irq.\n"); in asc_startup()
422 return -ENODEV; in asc_startup()
435 free_irq(port->irq, port); in asc_shutdown()
447 clk_prepare_enable(ascport->clk); in asc_pm()
459 clk_disable_unprepare(ascport->clk); in asc_pm()
476 termios->c_cflag &= ~(CMSPAR | in asc_set_termios()
477 (ascport->hw_flow_control ? 0 : CRTSCTS)); in asc_set_termios()
479 port->uartclk = clk_get_rate(ascport->clk); in asc_set_termios()
481 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); in asc_set_termios()
482 cflag = termios->c_cflag; in asc_set_termios()
507 termios->c_cflag = cflag; in asc_set_termios()
516 /* hardware flow control */ in asc_set_termios()
520 /* If flow-control selected, stop handling RTS manually */ in asc_set_termios()
521 if (ascport->rts) { in asc_set_termios()
526 /* If flow-control disabled, it's safe to handle RTS manually */ in asc_set_termios()
527 if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) in asc_set_termios()
531 if ((baud < 19200) && !ascport->force_m1) { in asc_set_termios()
532 asc_out(port, ASC_BAUDRATE, (port->uartclk / (16 * baud))); in asc_set_termios()
538 * ASCBaudRate = ------------------------ in asc_set_termios()
545 do_div(dividend, port->uartclk / 16); in asc_set_termios()
552 ascport->port.read_status_mask = ASC_RXBUF_DUMMY_OE; in asc_set_termios()
553 if (termios->c_iflag & INPCK) in asc_set_termios()
554 ascport->port.read_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE; in asc_set_termios()
555 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) in asc_set_termios()
556 ascport->port.read_status_mask |= ASC_RXBUF_DUMMY_BE; in asc_set_termios()
561 ascport->port.ignore_status_mask = 0; in asc_set_termios()
562 if (termios->c_iflag & IGNPAR) in asc_set_termios()
563 ascport->port.ignore_status_mask |= ASC_RXBUF_FE | ASC_RXBUF_PE; in asc_set_termios()
564 if (termios->c_iflag & IGNBRK) { in asc_set_termios()
565 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_BE; in asc_set_termios()
570 if (termios->c_iflag & IGNPAR) in asc_set_termios()
571 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_OE; in asc_set_termios()
577 if (!(termios->c_cflag & CREAD)) in asc_set_termios()
578 ascport->port.ignore_status_mask |= ASC_RXBUF_DUMMY_RX; in asc_set_termios()
590 pinctrl_select_state(ascport->pinctrl, in asc_set_termios()
591 ascport->states[NO_HW_FLOWCTRL]); in asc_set_termios()
593 gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW); in asc_set_termios()
596 port->dev->of_node->name); in asc_set_termios()
597 ascport->rts = gpiod; in asc_set_termios()
600 devm_gpiod_put(port->dev, ascport->rts); in asc_set_termios()
601 ascport->rts = NULL; in asc_set_termios()
602 pinctrl_select_state(ascport->pinctrl, in asc_set_termios()
603 ascport->states[DEFAULT]); in asc_set_termios()
610 return (port->type == PORT_ASC) ? DRIVER_NAME : NULL; in asc_type()
629 port->type = PORT_ASC; in asc_config_port()
636 return -EINVAL; in asc_verify_port()
662 /*---------------------------------------------------------------------*/
690 struct uart_port *port = &ascport->port; in asc_init_port()
694 port->iotype = UPIO_MEM; in asc_init_port()
695 port->flags = UPF_BOOT_AUTOCONF; in asc_init_port()
696 port->ops = &asc_uart_ops; in asc_init_port()
697 port->fifosize = ASC_FIFO_SIZE; in asc_init_port()
698 port->dev = &pdev->dev; in asc_init_port()
699 port->irq = platform_get_irq(pdev, 0); in asc_init_port()
700 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ST_ASC_CONSOLE); in asc_init_port()
702 port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in asc_init_port()
703 if (IS_ERR(port->membase)) in asc_init_port()
704 return PTR_ERR(port->membase); in asc_init_port()
705 port->mapbase = res->start; in asc_init_port()
707 spin_lock_init(&port->lock); in asc_init_port()
709 ascport->clk = devm_clk_get(&pdev->dev, NULL); in asc_init_port()
711 if (WARN_ON(IS_ERR(ascport->clk))) in asc_init_port()
712 return -EINVAL; in asc_init_port()
714 ret = clk_prepare_enable(ascport->clk); in asc_init_port()
717 ascport->port.uartclk = clk_get_rate(ascport->clk); in asc_init_port()
718 WARN_ON(ascport->port.uartclk == 0); in asc_init_port()
719 clk_disable_unprepare(ascport->clk); in asc_init_port()
721 ascport->pinctrl = devm_pinctrl_get(&pdev->dev); in asc_init_port()
722 if (IS_ERR(ascport->pinctrl)) { in asc_init_port()
723 ret = PTR_ERR(ascport->pinctrl); in asc_init_port()
724 dev_err(&pdev->dev, "Failed to get Pinctrl: %d\n", ret); in asc_init_port()
728 ascport->states[DEFAULT] = in asc_init_port()
729 pinctrl_lookup_state(ascport->pinctrl, "default"); in asc_init_port()
730 if (IS_ERR(ascport->states[DEFAULT])) { in asc_init_port()
731 ret = PTR_ERR(ascport->states[DEFAULT]); in asc_init_port()
732 dev_err(&pdev->dev, in asc_init_port()
737 /* "no-hw-flowctrl" state is optional */ in asc_init_port()
738 ascport->states[NO_HW_FLOWCTRL] = in asc_init_port()
739 pinctrl_lookup_state(ascport->pinctrl, "no-hw-flowctrl"); in asc_init_port()
740 if (IS_ERR(ascport->states[NO_HW_FLOWCTRL])) in asc_init_port()
741 ascport->states[NO_HW_FLOWCTRL] = NULL; in asc_init_port()
748 struct device_node *np = pdev->dev.of_node; in asc_of_get_asc_port()
765 "uart-has-rtscts"); in asc_of_get_asc_port()
766 asc_ports[id].force_m1 = of_property_read_bool(np, "st,force-m1"); in asc_of_get_asc_port()
789 return -ENODEV; in asc_serial_probe()
795 ret = uart_add_one_port(&asc_uart_driver, &ascport->port); in asc_serial_probe()
799 platform_set_drvdata(pdev, &ascport->port); in asc_serial_probe()
825 /*----------------------------------------------------------------------*/
832 /* Wait for upto 1 second in case flow control is stopping us. */ in asc_console_putchar()
833 while (--timeout && !asc_txfifo_is_half_empty(port)) in asc_console_putchar()
846 struct uart_port *port = &asc_ports[co->index].port; in asc_console_write()
852 if (port->sysrq) in asc_console_write()
869 while (--timeout && !asc_txfifo_is_empty(port)) in asc_console_write()
884 int flow = 'n'; in asc_console_setup() local
886 if (co->index >= ASC_MAX_PORTS) in asc_console_setup()
887 return -ENODEV; in asc_console_setup()
889 ascport = &asc_ports[co->index]; in asc_console_setup()
897 if (ascport->port.mapbase == 0 || ascport->port.membase == NULL) in asc_console_setup()
898 return -ENXIO; in asc_console_setup()
901 uart_parse_options(options, &baud, &parity, &bits, &flow); in asc_console_setup()
903 return uart_set_options(&ascport->port, co, baud, parity, bits, flow); in asc_console_setup()
912 .index = -1,