Lines Matching +full:cts +full:- +full:override

1 // SPDX-License-Identifier: GPL-2.0+
3 * altera_uart.c -- Altera UART driver
5 * Based on mcf.c -- Freescale ColdFire UART driver
7 * (C) Copyright 2003-2007, Greg Ungerer <gerg@snapgear.com>
54 #define ALTERA_UART_STATUS_DCTS_MSK 0x0400 /* CTS logic-level change */
55 #define ALTERA_UART_STATUS_CTS_MSK 0x0800 /* CTS logic state */
70 #define ALTERA_UART_CONTROL_DCTS_MSK 0x0400 /* Interrupt on CTS change */
75 * Local per-uart structure.
86 return readl(port->membase + (reg << port->regshift)); in altera_uart_readl()
91 writel(dat, port->membase + (reg << port->regshift)); in altera_uart_writel()
107 sigs |= (pp->sigs & TIOCM_RTS); in altera_uart_get_mctrl()
114 unsigned short imr = pp->imr; in altera_uart_update_ctrl_reg()
120 if (!pp->port.irq) in altera_uart_update_ctrl_reg()
123 altera_uart_writel(&pp->port, imr, ALTERA_UART_CONTROL_REG); in altera_uart_update_ctrl_reg()
130 pp->sigs = sigs; in altera_uart_set_mctrl()
132 pp->imr |= ALTERA_UART_CONTROL_RTS_MSK; in altera_uart_set_mctrl()
134 pp->imr &= ~ALTERA_UART_CONTROL_RTS_MSK; in altera_uart_set_mctrl()
142 pp->imr |= ALTERA_UART_CONTROL_TRDY_MSK; in altera_uart_start_tx()
150 pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK; in altera_uart_stop_tx()
158 pp->imr &= ~ALTERA_UART_CONTROL_RRDY_MSK; in altera_uart_stop_rx()
167 spin_lock_irqsave(&port->lock, flags); in altera_uart_break_ctl()
168 if (break_state == -1) in altera_uart_break_ctl()
169 pp->imr |= ALTERA_UART_CONTROL_TRBK_MSK; in altera_uart_break_ctl()
171 pp->imr &= ~ALTERA_UART_CONTROL_TRBK_MSK; in altera_uart_break_ctl()
173 spin_unlock_irqrestore(&port->lock, flags); in altera_uart_break_ctl()
184 baudclk = port->uartclk / baud; in altera_uart_set_termios()
190 spin_lock_irqsave(&port->lock, flags); in altera_uart_set_termios()
191 uart_update_timeout(port, termios->c_cflag, baud); in altera_uart_set_termios()
193 spin_unlock_irqrestore(&port->lock, flags); in altera_uart_set_termios()
196 * FIXME: port->read_status_mask and port->ignore_status_mask in altera_uart_set_termios()
204 struct uart_port *port = &pp->port; in altera_uart_rx_chars()
212 port->icount.rx++; in altera_uart_rx_chars()
219 port->icount.brk++; in altera_uart_rx_chars()
223 port->icount.parity++; in altera_uart_rx_chars()
225 port->icount.overrun++; in altera_uart_rx_chars()
227 port->icount.frame++; in altera_uart_rx_chars()
230 status &= port->read_status_mask; in altera_uart_rx_chars()
246 spin_unlock(&port->lock); in altera_uart_rx_chars()
247 tty_flip_buffer_push(&port->state->port); in altera_uart_rx_chars()
248 spin_lock(&port->lock); in altera_uart_rx_chars()
253 struct uart_port *port = &pp->port; in altera_uart_tx_chars()
254 struct circ_buf *xmit = &port->state->xmit; in altera_uart_tx_chars()
256 if (port->x_char) { in altera_uart_tx_chars()
257 /* Send special char - probably flow control */ in altera_uart_tx_chars()
258 altera_uart_writel(port, port->x_char, ALTERA_UART_TXDATA_REG); in altera_uart_tx_chars()
259 port->x_char = 0; in altera_uart_tx_chars()
260 port->icount.tx++; in altera_uart_tx_chars()
266 if (xmit->head == xmit->tail) in altera_uart_tx_chars()
268 altera_uart_writel(port, xmit->buf[xmit->tail], in altera_uart_tx_chars()
270 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in altera_uart_tx_chars()
271 port->icount.tx++; in altera_uart_tx_chars()
277 if (xmit->head == xmit->tail) { in altera_uart_tx_chars()
278 pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK; in altera_uart_tx_chars()
289 isr = altera_uart_readl(port, ALTERA_UART_STATUS_REG) & pp->imr; in altera_uart_interrupt()
291 spin_lock(&port->lock); in altera_uart_interrupt()
296 spin_unlock(&port->lock); in altera_uart_interrupt()
304 struct uart_port *port = &pp->port; in altera_uart_timer()
307 mod_timer(&pp->tmr, jiffies + uart_poll_timeout(port)); in altera_uart_timer()
312 port->type = PORT_ALTERA_UART; in altera_uart_config_port()
325 if (!port->irq) { in altera_uart_startup()
326 timer_setup(&pp->tmr, altera_uart_timer, 0); in altera_uart_startup()
327 mod_timer(&pp->tmr, jiffies + uart_poll_timeout(port)); in altera_uart_startup()
331 ret = request_irq(port->irq, altera_uart_interrupt, 0, in altera_uart_startup()
335 "interrupt vector=%d\n", port->line, port->irq); in altera_uart_startup()
340 spin_lock_irqsave(&port->lock, flags); in altera_uart_startup()
343 pp->imr = ALTERA_UART_CONTROL_RRDY_MSK; in altera_uart_startup()
346 spin_unlock_irqrestore(&port->lock, flags); in altera_uart_startup()
356 spin_lock_irqsave(&port->lock, flags); in altera_uart_shutdown()
359 pp->imr = 0; in altera_uart_shutdown()
362 spin_unlock_irqrestore(&port->lock, flags); in altera_uart_shutdown()
364 if (port->irq) in altera_uart_shutdown()
365 free_irq(port->irq, port); in altera_uart_shutdown()
367 del_timer_sync(&pp->tmr); in altera_uart_shutdown()
372 return (port->type == PORT_ALTERA_UART) ? "Altera UART" : NULL; in altera_uart_type()
389 if ((ser->type != PORT_UNKNOWN) && (ser->type != PORT_ALTERA_UART)) in altera_uart_verify_port()
390 return -EINVAL; in altera_uart_verify_port()
455 struct uart_port *port = &(altera_uart_ports + co->index)->port; in altera_uart_console_write()
468 if (co->index < 0 || co->index >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS) in altera_uart_console_setup()
469 return -EINVAL; in altera_uart_console_setup()
470 port = &altera_uart_ports[co->index].port; in altera_uart_console_setup()
471 if (!port->membase) in altera_uart_console_setup()
472 return -ENODEV; in altera_uart_console_setup()
488 .index = -1,
505 struct earlycon_device *dev = co->data; in altera_uart_earlycon_write()
507 uart_console_write(&dev->port, s, count, altera_uart_console_putc); in altera_uart_earlycon_write()
513 struct uart_port *port = &dev->port; in altera_uart_earlycon_setup()
515 if (!port->membase) in altera_uart_earlycon_setup()
516 return -ENODEV; in altera_uart_earlycon_setup()
522 if (dev->baud) { in altera_uart_earlycon_setup()
523 unsigned int baudclk = port->uartclk / dev->baud; in altera_uart_earlycon_setup()
528 dev->con->write = altera_uart_earlycon_write; in altera_uart_earlycon_setup()
532 OF_EARLYCON_DECLARE(uart, "altr,uart-1.0", altera_uart_earlycon_setup);
555 struct altera_uart_platform_uart *platp = dev_get_platdata(&pdev->dev); in altera_uart_probe()
559 int i = pdev->id; in altera_uart_probe()
562 /* if id is -1 scan for a free id and use that one */ in altera_uart_probe()
563 if (i == -1) { in altera_uart_probe()
570 return -EINVAL; in altera_uart_probe()
576 port->mapbase = res_mem->start; in altera_uart_probe()
578 port->mapbase = platp->mapbase; in altera_uart_probe()
580 return -EINVAL; in altera_uart_probe()
584 port->irq = res_irq->start; in altera_uart_probe()
586 port->irq = platp->irq; in altera_uart_probe()
588 /* Check platform data first so we can override device node data */ in altera_uart_probe()
590 port->uartclk = platp->uartclk; in altera_uart_probe()
592 ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency", in altera_uart_probe()
593 &port->uartclk); in altera_uart_probe()
598 port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE); in altera_uart_probe()
599 if (!port->membase) in altera_uart_probe()
600 return -ENOMEM; in altera_uart_probe()
603 port->regshift = platp->bus_shift; in altera_uart_probe()
605 port->regshift = 0; in altera_uart_probe()
607 port->line = i; in altera_uart_probe()
608 port->type = PORT_ALTERA_UART; in altera_uart_probe()
609 port->iotype = SERIAL_IO_MEM; in altera_uart_probe()
610 port->ops = &altera_uart_ops; in altera_uart_probe()
611 port->flags = UPF_BOOT_AUTOCONF; in altera_uart_probe()
612 port->dev = &pdev->dev; in altera_uart_probe()
627 port->mapbase = 0; in altera_uart_remove()
628 iounmap(port->membase); in altera_uart_remove()
636 { .compatible = "ALTR,uart-1.0", },
637 { .compatible = "altr,uart-1.0", },