Lines Matching +full:up +full:-

1 // SPDX-License-Identifier: GPL-2.0+
51 static inline unsigned int serial_in(struct uart_pxa_port *up, int offset) in serial_in() argument
54 return readl(up->port.membase + offset); in serial_in()
57 static inline void serial_out(struct uart_pxa_port *up, int offset, int value) in serial_out() argument
60 writel(value, up->port.membase + offset); in serial_out()
65 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_enable_ms() local
67 up->ier |= UART_IER_MSI; in serial_pxa_enable_ms()
68 serial_out(up, UART_IER, up->ier); in serial_pxa_enable_ms()
73 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_stop_tx() local
75 if (up->ier & UART_IER_THRI) { in serial_pxa_stop_tx()
76 up->ier &= ~UART_IER_THRI; in serial_pxa_stop_tx()
77 serial_out(up, UART_IER, up->ier); in serial_pxa_stop_tx()
83 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_stop_rx() local
85 up->ier &= ~UART_IER_RLSI; in serial_pxa_stop_rx()
86 up->port.read_status_mask &= ~UART_LSR_DR; in serial_pxa_stop_rx()
87 serial_out(up, UART_IER, up->ier); in serial_pxa_stop_rx()
90 static inline void receive_chars(struct uart_pxa_port *up, int *status) in receive_chars() argument
103 up->ier &= ~UART_IER_RTOIE; in receive_chars()
104 serial_out(up, UART_IER, up->ier); in receive_chars()
106 ch = serial_in(up, UART_RX); in receive_chars()
108 up->port.icount.rx++; in receive_chars()
117 up->port.icount.brk++; in receive_chars()
124 if (uart_handle_break(&up->port)) in receive_chars()
127 up->port.icount.parity++; in receive_chars()
129 up->port.icount.frame++; in receive_chars()
131 up->port.icount.overrun++; in receive_chars()
136 *status &= up->port.read_status_mask; in receive_chars()
139 if (up->port.line == up->port.cons->index) { in receive_chars()
141 *status |= up->lsr_break_flag; in receive_chars()
142 up->lsr_break_flag = 0; in receive_chars()
153 if (uart_handle_sysrq_char(&up->port, ch)) in receive_chars()
156 uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag); in receive_chars()
159 *status = serial_in(up, UART_LSR); in receive_chars()
160 } while ((*status & UART_LSR_DR) && (max_count-- > 0)); in receive_chars()
161 tty_flip_buffer_push(&up->port.state->port); in receive_chars()
168 * No more data in FIFO: Re-enable RTO interrupt via IER[RTOIE] in receive_chars()
170 up->ier |= UART_IER_RTOIE; in receive_chars()
171 serial_out(up, UART_IER, up->ier); in receive_chars()
174 static void transmit_chars(struct uart_pxa_port *up) in transmit_chars() argument
176 struct circ_buf *xmit = &up->port.state->xmit; in transmit_chars()
179 if (up->port.x_char) { in transmit_chars()
180 serial_out(up, UART_TX, up->port.x_char); in transmit_chars()
181 up->port.icount.tx++; in transmit_chars()
182 up->port.x_char = 0; in transmit_chars()
185 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { in transmit_chars()
186 serial_pxa_stop_tx(&up->port); in transmit_chars()
190 count = up->port.fifosize / 2; in transmit_chars()
192 serial_out(up, UART_TX, xmit->buf[xmit->tail]); in transmit_chars()
193 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in transmit_chars()
194 up->port.icount.tx++; in transmit_chars()
197 } while (--count > 0); in transmit_chars()
200 uart_write_wakeup(&up->port); in transmit_chars()
204 serial_pxa_stop_tx(&up->port); in transmit_chars()
209 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_start_tx() local
211 if (!(up->ier & UART_IER_THRI)) { in serial_pxa_start_tx()
212 up->ier |= UART_IER_THRI; in serial_pxa_start_tx()
213 serial_out(up, UART_IER, up->ier); in serial_pxa_start_tx()
217 /* should hold up->port.lock */
218 static inline void check_modem_status(struct uart_pxa_port *up) in check_modem_status() argument
222 status = serial_in(up, UART_MSR); in check_modem_status()
228 up->port.icount.rng++; in check_modem_status()
230 up->port.icount.dsr++; in check_modem_status()
232 uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); in check_modem_status()
234 uart_handle_cts_change(&up->port, status & UART_MSR_CTS); in check_modem_status()
236 wake_up_interruptible(&up->port.state->port.delta_msr_wait); in check_modem_status()
244 struct uart_pxa_port *up = dev_id; in serial_pxa_irq() local
247 iir = serial_in(up, UART_IIR); in serial_pxa_irq()
250 spin_lock(&up->port.lock); in serial_pxa_irq()
251 lsr = serial_in(up, UART_LSR); in serial_pxa_irq()
253 receive_chars(up, &lsr); in serial_pxa_irq()
254 check_modem_status(up); in serial_pxa_irq()
256 transmit_chars(up); in serial_pxa_irq()
257 spin_unlock(&up->port.lock); in serial_pxa_irq()
263 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_tx_empty() local
267 spin_lock_irqsave(&up->port.lock, flags); in serial_pxa_tx_empty()
268 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; in serial_pxa_tx_empty()
269 spin_unlock_irqrestore(&up->port.lock, flags); in serial_pxa_tx_empty()
276 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_get_mctrl() local
280 status = serial_in(up, UART_MSR); in serial_pxa_get_mctrl()
296 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_set_mctrl() local
310 mcr |= up->mcr; in serial_pxa_set_mctrl()
312 serial_out(up, UART_MCR, mcr); in serial_pxa_set_mctrl()
317 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_break_ctl() local
320 spin_lock_irqsave(&up->port.lock, flags); in serial_pxa_break_ctl()
321 if (break_state == -1) in serial_pxa_break_ctl()
322 up->lcr |= UART_LCR_SBC; in serial_pxa_break_ctl()
324 up->lcr &= ~UART_LCR_SBC; in serial_pxa_break_ctl()
325 serial_out(up, UART_LCR, up->lcr); in serial_pxa_break_ctl()
326 spin_unlock_irqrestore(&up->port.lock, flags); in serial_pxa_break_ctl()
331 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_startup() local
335 if (port->line == 3) /* HWUART */ in serial_pxa_startup()
336 up->mcr |= UART_MCR_AFE; in serial_pxa_startup()
338 up->mcr = 0; in serial_pxa_startup()
340 up->port.uartclk = clk_get_rate(up->clk); in serial_pxa_startup()
345 retval = request_irq(up->port.irq, serial_pxa_irq, 0, up->name, up); in serial_pxa_startup()
353 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); in serial_pxa_startup()
354 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | in serial_pxa_startup()
356 serial_out(up, UART_FCR, 0); in serial_pxa_startup()
361 (void) serial_in(up, UART_LSR); in serial_pxa_startup()
362 (void) serial_in(up, UART_RX); in serial_pxa_startup()
363 (void) serial_in(up, UART_IIR); in serial_pxa_startup()
364 (void) serial_in(up, UART_MSR); in serial_pxa_startup()
369 serial_out(up, UART_LCR, UART_LCR_WLEN8); in serial_pxa_startup()
371 spin_lock_irqsave(&up->port.lock, flags); in serial_pxa_startup()
372 up->port.mctrl |= TIOCM_OUT2; in serial_pxa_startup()
373 serial_pxa_set_mctrl(&up->port, up->port.mctrl); in serial_pxa_startup()
374 spin_unlock_irqrestore(&up->port.lock, flags); in serial_pxa_startup()
381 up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE; in serial_pxa_startup()
382 serial_out(up, UART_IER, up->ier); in serial_pxa_startup()
387 (void) serial_in(up, UART_LSR); in serial_pxa_startup()
388 (void) serial_in(up, UART_RX); in serial_pxa_startup()
389 (void) serial_in(up, UART_IIR); in serial_pxa_startup()
390 (void) serial_in(up, UART_MSR); in serial_pxa_startup()
397 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_shutdown() local
400 free_irq(up->port.irq, up); in serial_pxa_shutdown()
405 up->ier = 0; in serial_pxa_shutdown()
406 serial_out(up, UART_IER, 0); in serial_pxa_shutdown()
408 spin_lock_irqsave(&up->port.lock, flags); in serial_pxa_shutdown()
409 up->port.mctrl &= ~TIOCM_OUT2; in serial_pxa_shutdown()
410 serial_pxa_set_mctrl(&up->port, up->port.mctrl); in serial_pxa_shutdown()
411 spin_unlock_irqrestore(&up->port.lock, flags); in serial_pxa_shutdown()
416 serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC); in serial_pxa_shutdown()
417 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | in serial_pxa_shutdown()
420 serial_out(up, UART_FCR, 0); in serial_pxa_shutdown()
427 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_set_termios() local
433 switch (termios->c_cflag & CSIZE) { in serial_pxa_set_termios()
449 if (termios->c_cflag & CSTOPB) in serial_pxa_set_termios()
451 if (termios->c_cflag & PARENB) in serial_pxa_set_termios()
453 if (!(termios->c_cflag & PARODD)) in serial_pxa_set_termios()
459 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); in serial_pxa_set_termios()
462 if ((up->port.uartclk / quot) < (2400 * 16)) in serial_pxa_set_termios()
464 else if ((up->port.uartclk / quot) < (230400 * 16)) in serial_pxa_set_termios()
473 spin_lock_irqsave(&up->port.lock, flags); in serial_pxa_set_termios()
479 up->ier |= UART_IER_UUE; in serial_pxa_set_termios()
482 * Update the per-port timeout. in serial_pxa_set_termios()
484 uart_update_timeout(port, termios->c_cflag, baud); in serial_pxa_set_termios()
486 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; in serial_pxa_set_termios()
487 if (termios->c_iflag & INPCK) in serial_pxa_set_termios()
488 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; in serial_pxa_set_termios()
489 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) in serial_pxa_set_termios()
490 up->port.read_status_mask |= UART_LSR_BI; in serial_pxa_set_termios()
495 up->port.ignore_status_mask = 0; in serial_pxa_set_termios()
496 if (termios->c_iflag & IGNPAR) in serial_pxa_set_termios()
497 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; in serial_pxa_set_termios()
498 if (termios->c_iflag & IGNBRK) { in serial_pxa_set_termios()
499 up->port.ignore_status_mask |= UART_LSR_BI; in serial_pxa_set_termios()
504 if (termios->c_iflag & IGNPAR) in serial_pxa_set_termios()
505 up->port.ignore_status_mask |= UART_LSR_OE; in serial_pxa_set_termios()
511 if ((termios->c_cflag & CREAD) == 0) in serial_pxa_set_termios()
512 up->port.ignore_status_mask |= UART_LSR_DR; in serial_pxa_set_termios()
517 up->ier &= ~UART_IER_MSI; in serial_pxa_set_termios()
518 if (UART_ENABLE_MS(&up->port, termios->c_cflag)) in serial_pxa_set_termios()
519 up->ier |= UART_IER_MSI; in serial_pxa_set_termios()
521 serial_out(up, UART_IER, up->ier); in serial_pxa_set_termios()
523 if (termios->c_cflag & CRTSCTS) in serial_pxa_set_termios()
524 up->mcr |= UART_MCR_AFE; in serial_pxa_set_termios()
526 up->mcr &= ~UART_MCR_AFE; in serial_pxa_set_termios()
528 serial_out(up, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */ in serial_pxa_set_termios()
529 serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */ in serial_pxa_set_termios()
535 dll = serial_in(up, UART_DLL); in serial_pxa_set_termios()
538 serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */ in serial_pxa_set_termios()
539 serial_out(up, UART_LCR, cval); /* reset DLAB */ in serial_pxa_set_termios()
540 up->lcr = cval; /* Save LCR */ in serial_pxa_set_termios()
541 serial_pxa_set_mctrl(&up->port, up->port.mctrl); in serial_pxa_set_termios()
542 serial_out(up, UART_FCR, fcr); in serial_pxa_set_termios()
543 spin_unlock_irqrestore(&up->port.lock, flags); in serial_pxa_set_termios()
550 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_pm() local
553 clk_prepare_enable(up->clk); in serial_pxa_pm()
555 clk_disable_unprepare(up->clk); in serial_pxa_pm()
569 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_config_port() local
570 up->port.type = PORT_PXA; in serial_pxa_config_port()
577 return -EINVAL; in serial_pxa_verify_port()
583 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_type() local
584 return up->name; in serial_pxa_type()
597 static void wait_for_xmitr(struct uart_pxa_port *up) in wait_for_xmitr() argument
601 /* Wait up to 10ms for the character(s) to be sent. */ in wait_for_xmitr()
603 status = serial_in(up, UART_LSR); in wait_for_xmitr()
606 up->lsr_break_flag = UART_LSR_BI; in wait_for_xmitr()
608 if (--tmout == 0) in wait_for_xmitr()
613 /* Wait up to 1s for flow control if necessary */ in wait_for_xmitr()
614 if (up->port.flags & UPF_CONS_FLOW) { in wait_for_xmitr()
616 while (--tmout && in wait_for_xmitr()
617 ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0)) in wait_for_xmitr()
624 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_console_putchar() local
626 wait_for_xmitr(up); in serial_pxa_console_putchar()
627 serial_out(up, UART_TX, ch); in serial_pxa_console_putchar()
639 struct uart_pxa_port *up = serial_pxa_ports[co->index]; in serial_pxa_console_write() local
644 clk_enable(up->clk); in serial_pxa_console_write()
646 if (up->port.sysrq) in serial_pxa_console_write()
649 locked = spin_trylock(&up->port.lock); in serial_pxa_console_write()
651 spin_lock(&up->port.lock); in serial_pxa_console_write()
656 ier = serial_in(up, UART_IER); in serial_pxa_console_write()
657 serial_out(up, UART_IER, UART_IER_UUE); in serial_pxa_console_write()
659 uart_console_write(&up->port, s, count, serial_pxa_console_putchar); in serial_pxa_console_write()
665 wait_for_xmitr(up); in serial_pxa_console_write()
666 serial_out(up, UART_IER, ier); in serial_pxa_console_write()
669 spin_unlock(&up->port.lock); in serial_pxa_console_write()
671 clk_disable(up->clk); in serial_pxa_console_write()
683 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_get_poll_char() local
684 unsigned char lsr = serial_in(up, UART_LSR); in serial_pxa_get_poll_char()
687 lsr = serial_in(up, UART_LSR); in serial_pxa_get_poll_char()
689 return serial_in(up, UART_RX); in serial_pxa_get_poll_char()
697 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_put_poll_char() local
702 ier = serial_in(up, UART_IER); in serial_pxa_put_poll_char()
703 serial_out(up, UART_IER, UART_IER_UUE); in serial_pxa_put_poll_char()
705 wait_for_xmitr(up); in serial_pxa_put_poll_char()
709 serial_out(up, UART_TX, c); in serial_pxa_put_poll_char()
715 wait_for_xmitr(up); in serial_pxa_put_poll_char()
716 serial_out(up, UART_IER, ier); in serial_pxa_put_poll_char()
724 struct uart_pxa_port *up; in serial_pxa_console_setup() local
730 if (co->index == -1 || co->index >= serial_pxa_reg.nr) in serial_pxa_console_setup()
731 co->index = 0; in serial_pxa_console_setup()
732 up = serial_pxa_ports[co->index]; in serial_pxa_console_setup()
733 if (!up) in serial_pxa_console_setup()
734 return -ENODEV; in serial_pxa_console_setup()
739 return uart_set_options(&up->port, co, baud, parity, bits, flow); in serial_pxa_console_setup()
748 .index = -1,
797 uart_suspend_port(&serial_pxa_reg, &sport->port); in serial_pxa_suspend()
807 uart_resume_port(&serial_pxa_reg, &sport->port); in serial_pxa_resume()
819 { .compatible = "mrvl,pxa-uart", },
820 { .compatible = "mrvl,mmp-uart", },
827 struct device_node *np = pdev->dev.of_node; in serial_pxa_probe_dt()
835 dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); in serial_pxa_probe_dt()
838 sport->port.line = ret; in serial_pxa_probe_dt()
851 return -ENODEV; in serial_pxa_probe()
855 return -ENOMEM; in serial_pxa_probe()
857 sport->clk = clk_get(&dev->dev, NULL); in serial_pxa_probe()
858 if (IS_ERR(sport->clk)) { in serial_pxa_probe()
859 ret = PTR_ERR(sport->clk); in serial_pxa_probe()
863 ret = clk_prepare(sport->clk); in serial_pxa_probe()
865 clk_put(sport->clk); in serial_pxa_probe()
869 sport->port.type = PORT_PXA; in serial_pxa_probe()
870 sport->port.iotype = UPIO_MEM; in serial_pxa_probe()
871 sport->port.mapbase = mmres->start; in serial_pxa_probe()
872 sport->port.irq = irqres->start; in serial_pxa_probe()
873 sport->port.fifosize = 64; in serial_pxa_probe()
874 sport->port.ops = &serial_pxa_pops; in serial_pxa_probe()
875 sport->port.dev = &dev->dev; in serial_pxa_probe()
876 sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; in serial_pxa_probe()
877 sport->port.uartclk = clk_get_rate(sport->clk); in serial_pxa_probe()
878 sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_PXA_CONSOLE); in serial_pxa_probe()
882 sport->port.line = dev->id; in serial_pxa_probe()
885 if (sport->port.line >= ARRAY_SIZE(serial_pxa_ports)) { in serial_pxa_probe()
886 dev_err(&dev->dev, "serial%d out of range\n", sport->port.line); in serial_pxa_probe()
887 ret = -EINVAL; in serial_pxa_probe()
890 snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1); in serial_pxa_probe()
892 sport->port.membase = ioremap(mmres->start, resource_size(mmres)); in serial_pxa_probe()
893 if (!sport->port.membase) { in serial_pxa_probe()
894 ret = -ENOMEM; in serial_pxa_probe()
898 serial_pxa_ports[sport->port.line] = sport; in serial_pxa_probe()
900 uart_add_one_port(&serial_pxa_reg, &sport->port); in serial_pxa_probe()
906 clk_unprepare(sport->clk); in serial_pxa_probe()
907 clk_put(sport->clk); in serial_pxa_probe()
917 .name = "pxa2xx-uart",