Lines Matching +full:- +full:uart
1 // SPDX-License-Identifier: GPL-2.0
3 * MEN 16z135 High Speed UART
104 MODULE_PARM_DESC(txlvl, "TX IRQ trigger level 0-7, default 5 (128 byte)");
108 MODULE_PARM_DESC(rxlvl, "RX IRQ trigger level 0-7, default 6 (256 byte)");
131 * men_z135_reg_set() - Set value in register
132 * @uart: The UART port
136 static inline void men_z135_reg_set(struct men_z135_port *uart, in men_z135_reg_set() argument
139 struct uart_port *port = &uart->port; in men_z135_reg_set()
143 spin_lock_irqsave(&uart->lock, flags); in men_z135_reg_set()
145 reg = ioread32(port->membase + addr); in men_z135_reg_set()
147 iowrite32(reg, port->membase + addr); in men_z135_reg_set()
149 spin_unlock_irqrestore(&uart->lock, flags); in men_z135_reg_set()
153 * men_z135_reg_clr() - Unset value in register
154 * @uart: The UART port
158 static void men_z135_reg_clr(struct men_z135_port *uart, in men_z135_reg_clr() argument
161 struct uart_port *port = &uart->port; in men_z135_reg_clr()
165 spin_lock_irqsave(&uart->lock, flags); in men_z135_reg_clr()
167 reg = ioread32(port->membase + addr); in men_z135_reg_clr()
169 iowrite32(reg, port->membase + addr); in men_z135_reg_clr()
171 spin_unlock_irqrestore(&uart->lock, flags); in men_z135_reg_clr()
175 * men_z135_handle_modem_status() - Handle change of modem status
176 * @uart: The UART port
181 static void men_z135_handle_modem_status(struct men_z135_port *uart) in men_z135_handle_modem_status() argument
185 msr = (uart->stat_reg >> 8) & 0xff; in men_z135_handle_modem_status()
188 uart_handle_dcd_change(&uart->port, in men_z135_handle_modem_status()
191 uart_handle_cts_change(&uart->port, in men_z135_handle_modem_status()
195 static void men_z135_handle_lsr(struct men_z135_port *uart) in men_z135_handle_lsr() argument
197 struct uart_port *port = &uart->port; in men_z135_handle_lsr()
200 lsr = (uart->stat_reg >> 16) & 0xff; in men_z135_handle_lsr()
203 port->icount.overrun++; in men_z135_handle_lsr()
205 port->icount.parity++; in men_z135_handle_lsr()
207 port->icount.frame++; in men_z135_handle_lsr()
209 port->icount.brk++; in men_z135_handle_lsr()
215 * get_rx_fifo_content() - Get the number of bytes in RX FIFO
216 * @uart: The UART port
220 static u16 get_rx_fifo_content(struct men_z135_port *uart) in get_rx_fifo_content() argument
222 struct uart_port *port = &uart->port; in get_rx_fifo_content()
228 stat_reg = ioread32(port->membase + MEN_Z135_STAT_REG); in get_rx_fifo_content()
238 * men_z135_handle_rx() - RX tasklet routine
239 * @uart: Pointer to struct men_z135_port
243 static void men_z135_handle_rx(struct men_z135_port *uart) in men_z135_handle_rx() argument
245 struct uart_port *port = &uart->port; in men_z135_handle_rx()
246 struct tty_port *tport = &port->state->port; in men_z135_handle_rx()
251 size = get_rx_fifo_content(uart); in men_z135_handle_rx()
257 * longword in RX FIFO cannot be read.(0x004-0x3FF) in men_z135_handle_rx()
264 dev_warn(&uart->mdev->dev, in men_z135_handle_rx()
271 memcpy_fromio(uart->rxbuf, port->membase + MEN_Z135_RX_RAM, room); in men_z135_handle_rx()
274 iowrite32(room, port->membase + MEN_Z135_RX_CTRL); in men_z135_handle_rx()
276 copied = tty_insert_flip_string(tport, uart->rxbuf, room); in men_z135_handle_rx()
278 dev_warn(&uart->mdev->dev, in men_z135_handle_rx()
282 port->icount.rx += copied; in men_z135_handle_rx()
289 * men_z135_handle_tx() - TX tasklet routine
290 * @uart: Pointer to struct men_z135_port
293 static void men_z135_handle_tx(struct men_z135_port *uart) in men_z135_handle_tx() argument
295 struct uart_port *port = &uart->port; in men_z135_handle_tx()
296 struct circ_buf *xmit = &port->state->xmit; in men_z135_handle_tx()
312 if (port->x_char) in men_z135_handle_tx()
320 wptr = ioread32(port->membase + MEN_Z135_TX_CTRL); in men_z135_handle_tx()
327 txfree = MEN_Z135_FIFO_WATERMARK - txc; in men_z135_handle_tx()
329 dev_err(&uart->mdev->dev, in men_z135_handle_tx()
339 n = 4 - BYTES_TO_ALIGN(wptr); in men_z135_handle_tx()
348 head = xmit->head & (UART_XMIT_SIZE - 1); in men_z135_handle_tx()
349 tail = xmit->tail & (UART_XMIT_SIZE - 1); in men_z135_handle_tx()
351 s = ((head >= tail) ? head : UART_XMIT_SIZE) - tail; in men_z135_handle_tx()
354 memcpy_toio(port->membase + MEN_Z135_TX_RAM, &xmit->buf[xmit->tail], n); in men_z135_handle_tx()
355 iowrite32(n & 0x3ff, port->membase + MEN_Z135_TX_CTRL); in men_z135_handle_tx()
363 men_z135_reg_set(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_TXCIEN); in men_z135_handle_tx()
365 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_TXCIEN); in men_z135_handle_tx()
373 * men_z135_intr() - Handle legacy IRQs
375 * @data: Pointer to UART port
384 struct men_z135_port *uart = (struct men_z135_port *)data; in men_z135_intr() local
385 struct uart_port *port = &uart->port; in men_z135_intr()
389 uart->stat_reg = ioread32(port->membase + MEN_Z135_STAT_REG); in men_z135_intr()
390 irq_id = IRQ_ID(uart->stat_reg); in men_z135_intr()
395 spin_lock(&port->lock); in men_z135_intr()
397 iowrite8(irq_id, port->membase + MEN_Z135_STAT_REG); in men_z135_intr()
400 men_z135_handle_lsr(uart); in men_z135_intr()
406 dev_dbg(&uart->mdev->dev, "Character Timeout Indication\n"); in men_z135_intr()
407 men_z135_handle_rx(uart); in men_z135_intr()
412 men_z135_handle_tx(uart); in men_z135_intr()
417 men_z135_handle_modem_status(uart); in men_z135_intr()
421 spin_unlock(&port->lock); in men_z135_intr()
427 * men_z135_request_irq() - Request IRQ for 16z135 core
428 * @uart: z135 private uart port structure
433 static int men_z135_request_irq(struct men_z135_port *uart) in men_z135_request_irq() argument
435 struct device *dev = &uart->mdev->dev; in men_z135_request_irq()
436 struct uart_port *port = &uart->port; in men_z135_request_irq()
439 err = request_irq(port->irq, men_z135_intr, IRQF_SHARED, in men_z135_request_irq()
440 "men_z135_intr", uart); in men_z135_request_irq()
448 * men_z135_tx_empty() - Handle tx_empty call
449 * @port: The UART port
459 wptr = ioread32(port->membase + MEN_Z135_TX_CTRL); in men_z135_tx_empty()
469 * men_z135_set_mctrl() - Set modem control lines
470 * @port: The UART port
481 conf_reg = old = ioread32(port->membase + MEN_Z135_CONF_REG); in men_z135_set_mctrl()
508 iowrite32(conf_reg, port->membase + MEN_Z135_CONF_REG); in men_z135_set_mctrl()
512 * men_z135_get_mctrl() - Get modem control lines
513 * @port: The UART port
522 msr = ioread8(port->membase + MEN_Z135_STAT_REG + 1); in men_z135_get_mctrl()
537 * men_z135_stop_tx() - Stop transmitting characters
538 * @port: The UART port
546 struct men_z135_port *uart = to_men_z135(port); in men_z135_stop_tx() local
548 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_TXCIEN); in men_z135_stop_tx()
552 * men_z135_disable_ms() - Disable Modem Status
553 * port: The UART port
559 struct men_z135_port *uart = to_men_z135(port); in men_z135_disable_ms() local
561 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_MSIEN); in men_z135_disable_ms()
565 * men_z135_start_tx() - Start transmitting characters
566 * @port: The UART port
573 struct men_z135_port *uart = to_men_z135(port); in men_z135_start_tx() local
575 if (uart->automode) in men_z135_start_tx()
578 men_z135_handle_tx(uart); in men_z135_start_tx()
582 * men_z135_stop_rx() - Stop receiving characters
583 * @port: The UART port
589 struct men_z135_port *uart = to_men_z135(port); in men_z135_stop_rx() local
591 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_RXCIEN); in men_z135_stop_rx()
595 * men_z135_enable_ms() - Enable Modem Status
602 struct men_z135_port *uart = to_men_z135(port); in men_z135_enable_ms() local
604 men_z135_reg_set(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_MSIEN); in men_z135_enable_ms()
609 struct men_z135_port *uart = to_men_z135(port); in men_z135_startup() local
613 err = men_z135_request_irq(uart); in men_z135_startup()
615 return -ENODEV; in men_z135_startup()
617 conf_reg = ioread32(port->membase + MEN_Z135_CONF_REG); in men_z135_startup()
625 iowrite32(conf_reg, port->membase + MEN_Z135_CONF_REG); in men_z135_startup()
628 iowrite32(rx_timeout, port->membase + MEN_Z135_TIMEOUT); in men_z135_startup()
635 struct men_z135_port *uart = to_men_z135(port); in men_z135_shutdown() local
640 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, conf_reg); in men_z135_shutdown()
642 free_irq(uart->port.irq, uart); in men_z135_shutdown()
649 struct men_z135_port *uart = to_men_z135(port); in men_z135_set_termios() local
656 conf_reg = ioread32(port->membase + MEN_Z135_CONF_REG); in men_z135_set_termios()
660 switch (termios->c_cflag & CSIZE) { in men_z135_set_termios()
676 if (termios->c_cflag & CSTOPB) in men_z135_set_termios()
680 if (termios->c_cflag & PARENB) { in men_z135_set_termios()
683 if (termios->c_cflag & PARODD) in men_z135_set_termios()
691 if (termios->c_cflag & CRTSCTS) { in men_z135_set_termios()
693 uart->automode = true; in men_z135_set_termios()
694 termios->c_cflag &= ~CLOCAL; in men_z135_set_termios()
697 uart->automode = false; in men_z135_set_termios()
700 termios->c_cflag &= ~CMSPAR; /* Mark/Space parity is not supported */ in men_z135_set_termios()
703 iowrite32(conf_reg, port->membase + MEN_Z135_CONF_REG); in men_z135_set_termios()
705 uart_freq = ioread32(port->membase + MEN_Z135_UART_FREQ); in men_z135_set_termios()
711 spin_lock_irq(&port->lock); in men_z135_set_termios()
716 iowrite32(bd_reg, port->membase + MEN_Z135_BAUD_REG); in men_z135_set_termios()
718 uart_update_timeout(port, termios->c_cflag, baud); in men_z135_set_termios()
719 spin_unlock_irq(&port->lock); in men_z135_set_termios()
729 struct men_z135_port *uart = to_men_z135(port); in men_z135_release_port() local
731 iounmap(port->membase); in men_z135_release_port()
732 port->membase = NULL; in men_z135_release_port()
734 mcb_release_mem(uart->mem); in men_z135_release_port()
739 struct men_z135_port *uart = to_men_z135(port); in men_z135_request_port() local
740 struct mcb_device *mdev = uart->mdev; in men_z135_request_port()
743 mem = mcb_request_mem(uart->mdev, dev_name(&mdev->dev)); in men_z135_request_port()
747 port->mapbase = mem->start; in men_z135_request_port()
748 uart->mem = mem; in men_z135_request_port()
750 port->membase = ioremap(mem->start, resource_size(mem)); in men_z135_request_port()
751 if (port->membase == NULL) { in men_z135_request_port()
753 return -ENOMEM; in men_z135_request_port()
761 port->type = PORT_MEN_Z135; in men_z135_config_port()
768 return -EINVAL; in men_z135_verify_port()
799 * men_z135_probe() - Probe a z135 instance
804 * new uart port to the tty layer.
809 struct men_z135_port *uart; in men_z135_probe() local
814 dev = &mdev->dev; in men_z135_probe()
816 uart = devm_kzalloc(dev, sizeof(struct men_z135_port), GFP_KERNEL); in men_z135_probe()
817 if (!uart) in men_z135_probe()
818 return -ENOMEM; in men_z135_probe()
820 uart->rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL); in men_z135_probe()
821 if (!uart->rxbuf) in men_z135_probe()
822 return -ENOMEM; in men_z135_probe()
824 mem = &mdev->mem; in men_z135_probe()
826 mcb_set_drvdata(mdev, uart); in men_z135_probe()
828 uart->port.uartclk = MEN_Z135_BASECLK * 16; in men_z135_probe()
829 uart->port.fifosize = MEN_Z135_FIFO_SIZE; in men_z135_probe()
830 uart->port.iotype = UPIO_MEM; in men_z135_probe()
831 uart->port.ops = &men_z135_ops; in men_z135_probe()
832 uart->port.irq = mcb_get_irq(mdev); in men_z135_probe()
833 uart->port.flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; in men_z135_probe()
834 uart->port.line = line++; in men_z135_probe()
835 uart->port.dev = dev; in men_z135_probe()
836 uart->port.type = PORT_MEN_Z135; in men_z135_probe()
837 uart->port.mapbase = mem->start; in men_z135_probe()
838 uart->port.membase = NULL; in men_z135_probe()
839 uart->mdev = mdev; in men_z135_probe()
841 spin_lock_init(&uart->lock); in men_z135_probe()
843 err = uart_add_one_port(&men_z135_driver, &uart->port); in men_z135_probe()
850 free_page((unsigned long) uart->rxbuf); in men_z135_probe()
851 dev_err(dev, "Failed to add UART: %d\n", err); in men_z135_probe()
857 * men_z135_remove() - Remove a z135 instance from the system
863 struct men_z135_port *uart = mcb_get_drvdata(mdev); in men_z135_remove() local
865 line--; in men_z135_remove()
866 uart_remove_one_port(&men_z135_driver, &uart->port); in men_z135_remove()
867 free_page((unsigned long) uart->rxbuf); in men_z135_remove()
878 .name = "z135-uart",
887 * men_z135_init() - Driver Registration Routine
898 pr_err("Failed to register UART: %d\n", err); in men_z135_init()
914 * men_z135_exit() - Driver Exit Routine
927 MODULE_DESCRIPTION("MEN 16z135 High Speed UART");