Lines Matching +full:ar9330 +full:- +full:uart

1 // SPDX-License-Identifier: GPL-2.0
3 * Atheros AR933X SoC built-in UART driver
31 #include <asm/mach-ath79/ar933x_uart.h>
35 #define DRIVER_NAME "ar933x-uart"
60 return readl(up->port.membase + offset); in ar933x_uart_read()
66 writel(value, up->port.membase + offset); in ar933x_uart_write()
98 up->ier |= AR933X_UART_INT_TX_EMPTY; in ar933x_uart_start_tx_interrupt()
99 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier); in ar933x_uart_start_tx_interrupt()
104 up->ier &= ~AR933X_UART_INT_TX_EMPTY; in ar933x_uart_stop_tx_interrupt()
105 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier); in ar933x_uart_stop_tx_interrupt()
110 up->ier |= AR933X_UART_INT_RX_VALID; in ar933x_uart_start_rx_interrupt()
111 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier); in ar933x_uart_start_rx_interrupt()
116 up->ier &= ~AR933X_UART_INT_RX_VALID; in ar933x_uart_stop_rx_interrupt()
117 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier); in ar933x_uart_stop_rx_interrupt()
136 spin_lock_irqsave(&up->port.lock, flags); in ar933x_uart_tx_empty()
138 spin_unlock_irqrestore(&up->port.lock, flags); in ar933x_uart_tx_empty()
149 mctrl_gpio_get(up->gpios, &ret); in ar933x_uart_get_mctrl()
159 mctrl_gpio_set(up->gpios, mctrl); in ar933x_uart_set_mctrl()
178 if (--timeout == 0) in ar933x_uart_wait_tx_complete()
184 dev_err(up->port.dev, "waiting for TX timed out\n"); in ar933x_uart_wait_tx_complete()
223 spin_lock_irqsave(&up->port.lock, flags); in ar933x_uart_break_ctl()
224 if (break_state == -1) in ar933x_uart_break_ctl()
230 spin_unlock_irqrestore(&up->port.lock, flags); in ar933x_uart_break_ctl()
275 diff = abs(ar933x_uart_get_baud(clk, tscale, tstep) - baud); in ar933x_uart_get_scale_step()
295 new->c_cflag &= ~CSIZE; in ar933x_uart_set_termios()
296 new->c_cflag |= CS8; in ar933x_uart_set_termios()
299 new->c_cflag &= ~CSTOPB; in ar933x_uart_set_termios()
302 if (new->c_cflag & PARENB) { in ar933x_uart_set_termios()
303 if (!(new->c_cflag & PARODD)) in ar933x_uart_set_termios()
312 new->c_cflag &= ~CMSPAR; in ar933x_uart_set_termios()
314 baud = uart_get_baud_rate(port, new, old, up->min_baud, up->max_baud); in ar933x_uart_set_termios()
315 ar933x_uart_get_scale_step(port->uartclk, baud, &scale, &step); in ar933x_uart_set_termios()
321 spin_lock_irqsave(&up->port.lock, flags); in ar933x_uart_set_termios()
323 /* disable the UART */ in ar933x_uart_set_termios()
327 /* Update the per-port timeout. */ in ar933x_uart_set_termios()
328 uart_update_timeout(port, new->c_cflag, baud); in ar933x_uart_set_termios()
330 up->port.ignore_status_mask = 0; in ar933x_uart_set_termios()
333 if ((new->c_cflag & CREAD) == 0) in ar933x_uart_set_termios()
334 up->port.ignore_status_mask |= AR933X_DUMMY_STATUS_RD; in ar933x_uart_set_termios()
350 /* reenable the UART */ in ar933x_uart_set_termios()
355 spin_unlock_irqrestore(&up->port.lock, flags); in ar933x_uart_set_termios()
363 struct tty_port *port = &up->port.state->port; in ar933x_uart_rx_chars()
378 up->port.icount.rx++; in ar933x_uart_rx_chars()
381 if (uart_handle_sysrq_char(&up->port, ch)) in ar933x_uart_rx_chars()
384 if ((up->port.ignore_status_mask & AR933X_DUMMY_STATUS_RD) == 0) in ar933x_uart_rx_chars()
386 } while (max_count-- > 0); in ar933x_uart_rx_chars()
393 struct circ_buf *xmit = &up->port.state->xmit; in ar933x_uart_tx_chars()
394 struct serial_rs485 *rs485conf = &up->port.rs485; in ar933x_uart_tx_chars()
398 if (uart_tx_stopped(&up->port)) in ar933x_uart_tx_chars()
401 if ((rs485conf->flags & SER_RS485_ENABLED) && in ar933x_uart_tx_chars()
402 (up->port.x_char || !uart_circ_empty(xmit))) { in ar933x_uart_tx_chars()
404 gpiod_set_value(up->rts_gpiod, !!(rs485conf->flags & SER_RS485_RTS_ON_SEND)); in ar933x_uart_tx_chars()
408 count = up->port.fifosize; in ar933x_uart_tx_chars()
416 if (up->port.x_char) { in ar933x_uart_tx_chars()
417 ar933x_uart_putc(up, up->port.x_char); in ar933x_uart_tx_chars()
418 up->port.icount.tx++; in ar933x_uart_tx_chars()
419 up->port.x_char = 0; in ar933x_uart_tx_chars()
426 ar933x_uart_putc(up, xmit->buf[xmit->tail]); in ar933x_uart_tx_chars()
428 uart_xmit_advance(&up->port, 1); in ar933x_uart_tx_chars()
429 } while (--count > 0); in ar933x_uart_tx_chars()
432 uart_write_wakeup(&up->port); in ar933x_uart_tx_chars()
440 gpiod_set_value(up->rts_gpiod, !!(rs485conf->flags & SER_RS485_RTS_AFTER_SEND)); in ar933x_uart_tx_chars()
453 spin_lock(&up->port.lock); in ar933x_uart_interrupt()
471 spin_unlock(&up->port.lock); in ar933x_uart_interrupt()
483 ret = request_irq(up->port.irq, ar933x_uart_interrupt, in ar933x_uart_startup()
484 up->port.irqflags, dev_name(up->port.dev), up); in ar933x_uart_startup()
488 spin_lock_irqsave(&up->port.lock, flags); in ar933x_uart_startup()
501 spin_unlock_irqrestore(&up->port.lock, flags); in ar933x_uart_startup()
512 up->ier = 0; in ar933x_uart_shutdown()
513 ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier); in ar933x_uart_shutdown()
519 free_irq(up->port.irq, up); in ar933x_uart_shutdown()
524 return (port->type == PORT_AR933X) ? "AR933X UART" : NULL; in ar933x_uart_type()
541 port->type = PORT_AR933X; in ar933x_uart_config_port()
550 if (ser->type != PORT_UNKNOWN && in ar933x_uart_verify_port()
551 ser->type != PORT_AR933X) in ar933x_uart_verify_port()
552 return -EINVAL; in ar933x_uart_verify_port()
554 if (ser->irq < 0 || ser->irq >= NR_IRQS) in ar933x_uart_verify_port()
555 return -EINVAL; in ar933x_uart_verify_port()
557 if (ser->baud_base < up->min_baud || in ar933x_uart_verify_port()
558 ser->baud_base > up->max_baud) in ar933x_uart_verify_port()
559 return -EINVAL; in ar933x_uart_verify_port()
588 if (port->rs485.flags & SER_RS485_ENABLED) in ar933x_config_rs485()
589 gpiod_set_value(up->rts_gpiod, in ar933x_config_rs485()
590 !!(rs485conf->flags & SER_RS485_RTS_AFTER_SEND)); in ar933x_config_rs485()
607 if (--timeout == 0) in ar933x_uart_wait_xmitr()
625 struct ar933x_uart_port *up = ar933x_console_ports[co->index]; in ar933x_uart_console_write()
632 if (up->port.sysrq) in ar933x_uart_console_write()
635 locked = spin_trylock(&up->port.lock); in ar933x_uart_console_write()
637 spin_lock(&up->port.lock); in ar933x_uart_console_write()
645 uart_console_write(&up->port, s, count, ar933x_uart_console_putchar); in ar933x_uart_console_write()
657 spin_unlock(&up->port.lock); in ar933x_uart_console_write()
670 if (co->index < 0 || co->index >= CONFIG_SERIAL_AR933X_NR_UARTS) in ar933x_uart_console_setup()
671 return -EINVAL; in ar933x_uart_console_setup()
673 up = ar933x_console_ports[co->index]; in ar933x_uart_console_setup()
675 return -ENODEV; in ar933x_uart_console_setup()
680 return uart_set_options(&up->port, co, baud, parity, bits, flow); in ar933x_uart_console_setup()
689 .index = -1,
718 np = pdev->dev.of_node; in ar933x_uart_probe()
722 dev_err(&pdev->dev, "unable to get alias id, err=%d\n", in ar933x_uart_probe()
727 id = pdev->id; in ar933x_uart_probe()
728 if (id == -1) in ar933x_uart_probe()
733 return -EINVAL; in ar933x_uart_probe()
739 up = devm_kzalloc(&pdev->dev, sizeof(struct ar933x_uart_port), in ar933x_uart_probe()
742 return -ENOMEM; in ar933x_uart_probe()
744 up->clk = devm_clk_get(&pdev->dev, "uart"); in ar933x_uart_probe()
745 if (IS_ERR(up->clk)) { in ar933x_uart_probe()
746 dev_err(&pdev->dev, "unable to get UART clock\n"); in ar933x_uart_probe()
747 return PTR_ERR(up->clk); in ar933x_uart_probe()
750 port = &up->port; in ar933x_uart_probe()
752 port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &mem_res); in ar933x_uart_probe()
753 if (IS_ERR(port->membase)) in ar933x_uart_probe()
754 return PTR_ERR(port->membase); in ar933x_uart_probe()
756 ret = clk_prepare_enable(up->clk); in ar933x_uart_probe()
760 port->uartclk = clk_get_rate(up->clk); in ar933x_uart_probe()
761 if (!port->uartclk) { in ar933x_uart_probe()
762 ret = -EINVAL; in ar933x_uart_probe()
766 port->mapbase = mem_res->start; in ar933x_uart_probe()
767 port->line = id; in ar933x_uart_probe()
768 port->irq = irq; in ar933x_uart_probe()
769 port->dev = &pdev->dev; in ar933x_uart_probe()
770 port->type = PORT_AR933X; in ar933x_uart_probe()
771 port->iotype = UPIO_MEM32; in ar933x_uart_probe()
773 port->regshift = 2; in ar933x_uart_probe()
774 port->fifosize = AR933X_UART_FIFO_SIZE; in ar933x_uart_probe()
775 port->ops = &ar933x_uart_ops; in ar933x_uart_probe()
776 port->rs485_config = ar933x_config_rs485; in ar933x_uart_probe()
777 port->rs485_supported = ar933x_rs485_supported; in ar933x_uart_probe()
779 baud = ar933x_uart_get_baud(port->uartclk, AR933X_UART_MAX_SCALE, 1); in ar933x_uart_probe()
780 up->min_baud = max_t(unsigned int, baud, AR933X_UART_MIN_BAUD); in ar933x_uart_probe()
782 baud = ar933x_uart_get_baud(port->uartclk, 0, AR933X_UART_MAX_STEP); in ar933x_uart_probe()
783 up->max_baud = min_t(unsigned int, baud, AR933X_UART_MAX_BAUD); in ar933x_uart_probe()
789 up->gpios = mctrl_gpio_init(port, 0); in ar933x_uart_probe()
790 if (IS_ERR(up->gpios) && PTR_ERR(up->gpios) != -ENOSYS) { in ar933x_uart_probe()
791 ret = PTR_ERR(up->gpios); in ar933x_uart_probe()
795 up->rts_gpiod = mctrl_gpio_to_gpiod(up->gpios, UART_GPIO_RTS); in ar933x_uart_probe()
797 if (!up->rts_gpiod) { in ar933x_uart_probe()
798 port->rs485_supported = ar933x_no_rs485; in ar933x_uart_probe()
799 if (port->rs485.flags & SER_RS485_ENABLED) { in ar933x_uart_probe()
800 dev_err(&pdev->dev, "lacking rts-gpio, disabling RS485\n"); in ar933x_uart_probe()
801 port->rs485.flags &= ~SER_RS485_ENABLED; in ar933x_uart_probe()
806 ar933x_console_ports[up->port.line] = up; in ar933x_uart_probe()
809 ret = uart_add_one_port(&ar933x_uart_driver, &up->port); in ar933x_uart_probe()
817 clk_disable_unprepare(up->clk); in ar933x_uart_probe()
828 uart_remove_one_port(&ar933x_uart_driver, &up->port); in ar933x_uart_remove()
829 clk_disable_unprepare(up->clk); in ar933x_uart_remove()
837 { .compatible = "qca,ar9330-uart" },
885 MODULE_DESCRIPTION("Atheros AR933X UART driver");