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 xmit->tail = (xmit->tail + n) & (UART_XMIT_SIZE - 1); in men_z135_handle_tx()
357 iowrite32(n & 0x3ff, port->membase + MEN_Z135_TX_CTRL); in men_z135_handle_tx()
359 port->icount.tx += n; in men_z135_handle_tx()
366 men_z135_reg_set(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_TXCIEN); in men_z135_handle_tx()
368 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_TXCIEN); in men_z135_handle_tx()
376 * men_z135_intr() - Handle legacy IRQs
378 * @data: Pointer to UART port
387 struct men_z135_port *uart = (struct men_z135_port *)data; in men_z135_intr() local
388 struct uart_port *port = &uart->port; in men_z135_intr()
392 uart->stat_reg = ioread32(port->membase + MEN_Z135_STAT_REG); in men_z135_intr()
393 irq_id = IRQ_ID(uart->stat_reg); in men_z135_intr()
398 spin_lock(&port->lock); in men_z135_intr()
400 iowrite8(irq_id, port->membase + MEN_Z135_STAT_REG); in men_z135_intr()
403 men_z135_handle_lsr(uart); in men_z135_intr()
409 dev_dbg(&uart->mdev->dev, "Character Timeout Indication\n"); in men_z135_intr()
410 men_z135_handle_rx(uart); in men_z135_intr()
415 men_z135_handle_tx(uart); in men_z135_intr()
420 men_z135_handle_modem_status(uart); in men_z135_intr()
424 spin_unlock(&port->lock); in men_z135_intr()
430 * men_z135_request_irq() - Request IRQ for 16z135 core
431 * @uart: z135 private uart port structure
436 static int men_z135_request_irq(struct men_z135_port *uart) in men_z135_request_irq() argument
438 struct device *dev = &uart->mdev->dev; in men_z135_request_irq()
439 struct uart_port *port = &uart->port; in men_z135_request_irq()
442 err = request_irq(port->irq, men_z135_intr, IRQF_SHARED, in men_z135_request_irq()
443 "men_z135_intr", uart); in men_z135_request_irq()
451 * men_z135_tx_empty() - Handle tx_empty call
452 * @port: The UART port
462 wptr = ioread32(port->membase + MEN_Z135_TX_CTRL); in men_z135_tx_empty()
472 * men_z135_set_mctrl() - Set modem control lines
473 * @port: The UART port
484 conf_reg = old = ioread32(port->membase + MEN_Z135_CONF_REG); in men_z135_set_mctrl()
511 iowrite32(conf_reg, port->membase + MEN_Z135_CONF_REG); in men_z135_set_mctrl()
515 * men_z135_get_mctrl() - Get modem control lines
516 * @port: The UART port
525 msr = ioread8(port->membase + MEN_Z135_STAT_REG + 1); in men_z135_get_mctrl()
540 * men_z135_stop_tx() - Stop transmitting characters
541 * @port: The UART port
549 struct men_z135_port *uart = to_men_z135(port); in men_z135_stop_tx() local
551 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_TXCIEN); in men_z135_stop_tx()
555 * men_z135_disable_ms() - Disable Modem Status
556 * port: The UART port
562 struct men_z135_port *uart = to_men_z135(port); in men_z135_disable_ms() local
564 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_MSIEN); in men_z135_disable_ms()
568 * men_z135_start_tx() - Start transmitting characters
569 * @port: The UART port
576 struct men_z135_port *uart = to_men_z135(port); in men_z135_start_tx() local
578 if (uart->automode) in men_z135_start_tx()
581 men_z135_handle_tx(uart); in men_z135_start_tx()
585 * men_z135_stop_rx() - Stop receiving characters
586 * @port: The UART port
592 struct men_z135_port *uart = to_men_z135(port); in men_z135_stop_rx() local
594 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_RXCIEN); in men_z135_stop_rx()
598 * men_z135_enable_ms() - Enable Modem Status
605 struct men_z135_port *uart = to_men_z135(port); in men_z135_enable_ms() local
607 men_z135_reg_set(uart, MEN_Z135_CONF_REG, MEN_Z135_IER_MSIEN); in men_z135_enable_ms()
612 struct men_z135_port *uart = to_men_z135(port); in men_z135_startup() local
616 err = men_z135_request_irq(uart); in men_z135_startup()
618 return -ENODEV; in men_z135_startup()
620 conf_reg = ioread32(port->membase + MEN_Z135_CONF_REG); in men_z135_startup()
628 iowrite32(conf_reg, port->membase + MEN_Z135_CONF_REG); in men_z135_startup()
631 iowrite32(rx_timeout, port->membase + MEN_Z135_TIMEOUT); in men_z135_startup()
638 struct men_z135_port *uart = to_men_z135(port); in men_z135_shutdown() local
643 men_z135_reg_clr(uart, MEN_Z135_CONF_REG, conf_reg); in men_z135_shutdown()
645 free_irq(uart->port.irq, uart); in men_z135_shutdown()
652 struct men_z135_port *uart = to_men_z135(port); in men_z135_set_termios() local
659 conf_reg = ioread32(port->membase + MEN_Z135_CONF_REG); in men_z135_set_termios()
663 switch (termios->c_cflag & CSIZE) { in men_z135_set_termios()
679 if (termios->c_cflag & CSTOPB) in men_z135_set_termios()
683 if (termios->c_cflag & PARENB) { in men_z135_set_termios()
686 if (termios->c_cflag & PARODD) in men_z135_set_termios()
694 if (termios->c_cflag & CRTSCTS) { in men_z135_set_termios()
696 uart->automode = true; in men_z135_set_termios()
697 termios->c_cflag &= ~CLOCAL; in men_z135_set_termios()
700 uart->automode = false; in men_z135_set_termios()
703 termios->c_cflag &= ~CMSPAR; /* Mark/Space parity is not supported */ in men_z135_set_termios()
706 iowrite32(conf_reg, port->membase + MEN_Z135_CONF_REG); in men_z135_set_termios()
708 uart_freq = ioread32(port->membase + MEN_Z135_UART_FREQ); in men_z135_set_termios()
714 spin_lock_irq(&port->lock); in men_z135_set_termios()
719 iowrite32(bd_reg, port->membase + MEN_Z135_BAUD_REG); in men_z135_set_termios()
721 uart_update_timeout(port, termios->c_cflag, baud); in men_z135_set_termios()
722 spin_unlock_irq(&port->lock); in men_z135_set_termios()
732 struct men_z135_port *uart = to_men_z135(port); in men_z135_release_port() local
734 iounmap(port->membase); in men_z135_release_port()
735 port->membase = NULL; in men_z135_release_port()
737 mcb_release_mem(uart->mem); in men_z135_release_port()
742 struct men_z135_port *uart = to_men_z135(port); in men_z135_request_port() local
743 struct mcb_device *mdev = uart->mdev; in men_z135_request_port()
746 mem = mcb_request_mem(uart->mdev, dev_name(&mdev->dev)); in men_z135_request_port()
750 port->mapbase = mem->start; in men_z135_request_port()
751 uart->mem = mem; in men_z135_request_port()
753 port->membase = ioremap(mem->start, resource_size(mem)); in men_z135_request_port()
754 if (port->membase == NULL) { in men_z135_request_port()
756 return -ENOMEM; in men_z135_request_port()
764 port->type = PORT_MEN_Z135; in men_z135_config_port()
771 return -EINVAL; in men_z135_verify_port()
802 * men_z135_probe() - Probe a z135 instance
807 * new uart port to the tty layer.
812 struct men_z135_port *uart; in men_z135_probe() local
817 dev = &mdev->dev; in men_z135_probe()
819 uart = devm_kzalloc(dev, sizeof(struct men_z135_port), GFP_KERNEL); in men_z135_probe()
820 if (!uart) in men_z135_probe()
821 return -ENOMEM; in men_z135_probe()
823 uart->rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL); in men_z135_probe()
824 if (!uart->rxbuf) in men_z135_probe()
825 return -ENOMEM; in men_z135_probe()
827 mem = &mdev->mem; in men_z135_probe()
829 mcb_set_drvdata(mdev, uart); in men_z135_probe()
831 uart->port.uartclk = MEN_Z135_BASECLK * 16; in men_z135_probe()
832 uart->port.fifosize = MEN_Z135_FIFO_SIZE; in men_z135_probe()
833 uart->port.iotype = UPIO_MEM; in men_z135_probe()
834 uart->port.ops = &men_z135_ops; in men_z135_probe()
835 uart->port.irq = mcb_get_irq(mdev); in men_z135_probe()
836 uart->port.flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; in men_z135_probe()
837 uart->port.line = line++; in men_z135_probe()
838 uart->port.dev = dev; in men_z135_probe()
839 uart->port.type = PORT_MEN_Z135; in men_z135_probe()
840 uart->port.mapbase = mem->start; in men_z135_probe()
841 uart->port.membase = NULL; in men_z135_probe()
842 uart->mdev = mdev; in men_z135_probe()
844 spin_lock_init(&uart->lock); in men_z135_probe()
846 err = uart_add_one_port(&men_z135_driver, &uart->port); in men_z135_probe()
853 free_page((unsigned long) uart->rxbuf); in men_z135_probe()
854 dev_err(dev, "Failed to add UART: %d\n", err); in men_z135_probe()
860 * men_z135_remove() - Remove a z135 instance from the system
866 struct men_z135_port *uart = mcb_get_drvdata(mdev); in men_z135_remove() local
868 line--; in men_z135_remove()
869 uart_remove_one_port(&men_z135_driver, &uart->port); in men_z135_remove()
870 free_page((unsigned long) uart->rxbuf); in men_z135_remove()
881 .name = "z135-uart",
890 * men_z135_init() - Driver Registration Routine
901 pr_err("Failed to register UART: %d\n", err); in men_z135_init()
917 * men_z135_exit() - Driver Exit Routine
930 MODULE_DESCRIPTION("MEN 16z135 High Speed UART");