Lines Matching +full:up +full:- +full:to
1 // SPDX-License-Identifier: GPL-2.0+
11 * easier to add DMA support.
14 * If someone else wants to request an "official" allocation of major/minor
16 * to come from Intel might have more than 3 or 4 of those UARTs. Let's
18 * with the serial core maintainer satisfaction to appear soon.
52 static inline unsigned int serial_in(struct uart_pxa_port *up, int offset) in serial_in() argument
55 return readl(up->port.membase + offset); in serial_in()
58 static inline void serial_out(struct uart_pxa_port *up, int offset, int value) in serial_out() argument
61 writel(value, up->port.membase + offset); in serial_out()
66 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_enable_ms() local
68 up->ier |= UART_IER_MSI; in serial_pxa_enable_ms()
69 serial_out(up, UART_IER, up->ier); in serial_pxa_enable_ms()
74 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_stop_tx() local
76 if (up->ier & UART_IER_THRI) { in serial_pxa_stop_tx()
77 up->ier &= ~UART_IER_THRI; in serial_pxa_stop_tx()
78 serial_out(up, UART_IER, up->ier); in serial_pxa_stop_tx()
84 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_stop_rx() local
86 up->ier &= ~UART_IER_RLSI; in serial_pxa_stop_rx()
87 up->port.read_status_mask &= ~UART_LSR_DR; in serial_pxa_stop_rx()
88 serial_out(up, UART_IER, up->ier); in serial_pxa_stop_rx()
91 static inline void receive_chars(struct uart_pxa_port *up, int *status) in receive_chars() argument
97 /* work around Errata #20 according to in receive_chars()
104 up->ier &= ~UART_IER_RTOIE; in receive_chars()
105 serial_out(up, UART_IER, up->ier); in receive_chars()
107 ch = serial_in(up, UART_RX); in receive_chars()
109 up->port.icount.rx++; in receive_chars()
118 up->port.icount.brk++; in receive_chars()
125 if (uart_handle_break(&up->port)) in receive_chars()
128 up->port.icount.parity++; in receive_chars()
130 up->port.icount.frame++; in receive_chars()
132 up->port.icount.overrun++; in receive_chars()
137 *status &= up->port.read_status_mask; in receive_chars()
140 if (up->port.line == up->port.cons->index) { in receive_chars()
142 *status |= up->lsr_break_flag; in receive_chars()
143 up->lsr_break_flag = 0; in receive_chars()
154 if (uart_prepare_sysrq_char(&up->port, ch)) in receive_chars()
157 uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag); in receive_chars()
160 *status = serial_in(up, UART_LSR); in receive_chars()
161 } while ((*status & UART_LSR_DR) && (max_count-- > 0)); in receive_chars()
162 tty_flip_buffer_push(&up->port.state->port); in receive_chars()
164 /* work around Errata #20 according to in receive_chars()
169 * No more data in FIFO: Re-enable RTO interrupt via IER[RTOIE] in receive_chars()
171 up->ier |= UART_IER_RTOIE; in receive_chars()
172 serial_out(up, UART_IER, up->ier); in receive_chars()
175 static void transmit_chars(struct uart_pxa_port *up) in transmit_chars() argument
179 uart_port_tx_limited(&up->port, ch, up->port.fifosize / 2, in transmit_chars()
181 serial_out(up, UART_TX, ch), in transmit_chars()
187 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_start_tx() local
189 if (!(up->ier & UART_IER_THRI)) { in serial_pxa_start_tx()
190 up->ier |= UART_IER_THRI; in serial_pxa_start_tx()
191 serial_out(up, UART_IER, up->ier); in serial_pxa_start_tx()
195 /* should hold up->port.lock */
196 static inline void check_modem_status(struct uart_pxa_port *up) in check_modem_status() argument
200 status = serial_in(up, UART_MSR); in check_modem_status()
206 up->port.icount.rng++; in check_modem_status()
208 up->port.icount.dsr++; in check_modem_status()
210 uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); in check_modem_status()
212 uart_handle_cts_change(&up->port, status & UART_MSR_CTS); in check_modem_status()
214 wake_up_interruptible(&up->port.state->port.delta_msr_wait); in check_modem_status()
222 struct uart_pxa_port *up = dev_id; in serial_pxa_irq() local
225 iir = serial_in(up, UART_IIR); in serial_pxa_irq()
228 uart_port_lock(&up->port); in serial_pxa_irq()
229 lsr = serial_in(up, UART_LSR); in serial_pxa_irq()
231 receive_chars(up, &lsr); in serial_pxa_irq()
232 check_modem_status(up); in serial_pxa_irq()
234 transmit_chars(up); in serial_pxa_irq()
235 uart_unlock_and_check_sysrq(&up->port); in serial_pxa_irq()
241 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_tx_empty() local
245 uart_port_lock_irqsave(&up->port, &flags); in serial_pxa_tx_empty()
246 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; in serial_pxa_tx_empty()
247 uart_port_unlock_irqrestore(&up->port, flags); in serial_pxa_tx_empty()
254 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_get_mctrl() local
258 status = serial_in(up, UART_MSR); in serial_pxa_get_mctrl()
274 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_set_mctrl() local
288 mcr |= up->mcr; in serial_pxa_set_mctrl()
290 serial_out(up, UART_MCR, mcr); in serial_pxa_set_mctrl()
295 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_break_ctl() local
298 uart_port_lock_irqsave(&up->port, &flags); in serial_pxa_break_ctl()
299 if (break_state == -1) in serial_pxa_break_ctl()
300 up->lcr |= UART_LCR_SBC; in serial_pxa_break_ctl()
302 up->lcr &= ~UART_LCR_SBC; in serial_pxa_break_ctl()
303 serial_out(up, UART_LCR, up->lcr); in serial_pxa_break_ctl()
304 uart_port_unlock_irqrestore(&up->port, flags); in serial_pxa_break_ctl()
309 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_startup() local
313 if (port->line == 3) /* HWUART */ in serial_pxa_startup()
314 up->mcr |= UART_MCR_AFE; in serial_pxa_startup()
316 up->mcr = 0; in serial_pxa_startup()
318 up->port.uartclk = clk_get_rate(up->clk); in serial_pxa_startup()
323 retval = request_irq(up->port.irq, serial_pxa_irq, 0, up->name, up); in serial_pxa_startup()
331 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO); in serial_pxa_startup()
332 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | in serial_pxa_startup()
334 serial_out(up, UART_FCR, 0); in serial_pxa_startup()
339 (void) serial_in(up, UART_LSR); in serial_pxa_startup()
340 (void) serial_in(up, UART_RX); in serial_pxa_startup()
341 (void) serial_in(up, UART_IIR); in serial_pxa_startup()
342 (void) serial_in(up, UART_MSR); in serial_pxa_startup()
347 serial_out(up, UART_LCR, UART_LCR_WLEN8); in serial_pxa_startup()
349 uart_port_lock_irqsave(&up->port, &flags); in serial_pxa_startup()
350 up->port.mctrl |= TIOCM_OUT2; in serial_pxa_startup()
351 serial_pxa_set_mctrl(&up->port, up->port.mctrl); in serial_pxa_startup()
352 uart_port_unlock_irqrestore(&up->port, flags); in serial_pxa_startup()
359 up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE; in serial_pxa_startup()
360 serial_out(up, UART_IER, up->ier); in serial_pxa_startup()
365 (void) serial_in(up, UART_LSR); in serial_pxa_startup()
366 (void) serial_in(up, UART_RX); in serial_pxa_startup()
367 (void) serial_in(up, UART_IIR); in serial_pxa_startup()
368 (void) serial_in(up, UART_MSR); in serial_pxa_startup()
375 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_shutdown() local
378 free_irq(up->port.irq, up); in serial_pxa_shutdown()
383 up->ier = 0; in serial_pxa_shutdown()
384 serial_out(up, UART_IER, 0); in serial_pxa_shutdown()
386 uart_port_lock_irqsave(&up->port, &flags); in serial_pxa_shutdown()
387 up->port.mctrl &= ~TIOCM_OUT2; in serial_pxa_shutdown()
388 serial_pxa_set_mctrl(&up->port, up->port.mctrl); in serial_pxa_shutdown()
389 uart_port_unlock_irqrestore(&up->port, flags); in serial_pxa_shutdown()
394 serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC); in serial_pxa_shutdown()
395 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO | in serial_pxa_shutdown()
398 serial_out(up, UART_FCR, 0); in serial_pxa_shutdown()
405 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_set_termios() local
411 cval = UART_LCR_WLEN(tty_get_char_size(termios->c_cflag)); in serial_pxa_set_termios()
413 if (termios->c_cflag & CSTOPB) in serial_pxa_set_termios()
415 if (termios->c_cflag & PARENB) in serial_pxa_set_termios()
417 if (!(termios->c_cflag & PARODD)) in serial_pxa_set_termios()
421 * Ask the core to calculate the divisor for us. in serial_pxa_set_termios()
423 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); in serial_pxa_set_termios()
426 if ((up->port.uartclk / quot) < (2400 * 16)) in serial_pxa_set_termios()
428 else if ((up->port.uartclk / quot) < (230400 * 16)) in serial_pxa_set_termios()
437 uart_port_lock_irqsave(&up->port, &flags); in serial_pxa_set_termios()
443 up->ier |= UART_IER_UUE; in serial_pxa_set_termios()
446 * Update the per-port timeout. in serial_pxa_set_termios()
448 uart_update_timeout(port, termios->c_cflag, baud); in serial_pxa_set_termios()
450 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; in serial_pxa_set_termios()
451 if (termios->c_iflag & INPCK) in serial_pxa_set_termios()
452 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; in serial_pxa_set_termios()
453 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) in serial_pxa_set_termios()
454 up->port.read_status_mask |= UART_LSR_BI; in serial_pxa_set_termios()
457 * Characters to ignore in serial_pxa_set_termios()
459 up->port.ignore_status_mask = 0; in serial_pxa_set_termios()
460 if (termios->c_iflag & IGNPAR) in serial_pxa_set_termios()
461 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; in serial_pxa_set_termios()
462 if (termios->c_iflag & IGNBRK) { in serial_pxa_set_termios()
463 up->port.ignore_status_mask |= UART_LSR_BI; in serial_pxa_set_termios()
468 if (termios->c_iflag & IGNPAR) in serial_pxa_set_termios()
469 up->port.ignore_status_mask |= UART_LSR_OE; in serial_pxa_set_termios()
475 if ((termios->c_cflag & CREAD) == 0) in serial_pxa_set_termios()
476 up->port.ignore_status_mask |= UART_LSR_DR; in serial_pxa_set_termios()
481 up->ier &= ~UART_IER_MSI; in serial_pxa_set_termios()
482 if (UART_ENABLE_MS(&up->port, termios->c_cflag)) in serial_pxa_set_termios()
483 up->ier |= UART_IER_MSI; in serial_pxa_set_termios()
485 serial_out(up, UART_IER, up->ier); in serial_pxa_set_termios()
487 if (termios->c_cflag & CRTSCTS) in serial_pxa_set_termios()
488 up->mcr |= UART_MCR_AFE; in serial_pxa_set_termios()
490 up->mcr &= ~UART_MCR_AFE; in serial_pxa_set_termios()
492 serial_out(up, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */ in serial_pxa_set_termios()
493 serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */ in serial_pxa_set_termios()
496 * work around Errata #75 according to Intel(R) PXA27x Processor Family in serial_pxa_set_termios()
499 dll = serial_in(up, UART_DLL); in serial_pxa_set_termios()
502 serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */ in serial_pxa_set_termios()
503 serial_out(up, UART_LCR, cval); /* reset DLAB */ in serial_pxa_set_termios()
504 up->lcr = cval; /* Save LCR */ in serial_pxa_set_termios()
505 serial_pxa_set_mctrl(&up->port, up->port.mctrl); in serial_pxa_set_termios()
506 serial_out(up, UART_FCR, fcr); in serial_pxa_set_termios()
507 uart_port_unlock_irqrestore(&up->port, flags); in serial_pxa_set_termios()
514 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_pm() local
517 clk_prepare_enable(up->clk); in serial_pxa_pm()
519 clk_disable_unprepare(up->clk); in serial_pxa_pm()
533 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_config_port() local
534 up->port.type = PORT_PXA; in serial_pxa_config_port()
540 /* we don't want the core code to modify any port params */ in serial_pxa_verify_port()
541 return -EINVAL; in serial_pxa_verify_port()
547 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_type() local
548 return up->name; in serial_pxa_type()
557 * Wait for transmitter & holding register to empty
559 static void wait_for_xmitr(struct uart_pxa_port *up) in wait_for_xmitr() argument
563 /* Wait up to 10ms for the character(s) to be sent. */ in wait_for_xmitr()
565 status = serial_in(up, UART_LSR); in wait_for_xmitr()
568 up->lsr_break_flag = UART_LSR_BI; in wait_for_xmitr()
570 if (--tmout == 0) in wait_for_xmitr()
575 /* Wait up to 1s for flow control if necessary */ in wait_for_xmitr()
576 if (up->port.flags & UPF_CONS_FLOW) { in wait_for_xmitr()
578 while (--tmout && in wait_for_xmitr()
579 ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0)) in wait_for_xmitr()
586 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_console_putchar() local
588 wait_for_xmitr(up); in serial_pxa_console_putchar()
589 serial_out(up, UART_TX, ch); in serial_pxa_console_putchar()
593 * Print a string to the serial port trying not to disturb
601 struct uart_pxa_port *up = serial_pxa_ports[co->index]; in serial_pxa_console_write() local
606 clk_enable(up->clk); in serial_pxa_console_write()
608 locked = uart_port_trylock_irqsave(&up->port, &flags); in serial_pxa_console_write()
610 uart_port_lock_irqsave(&up->port, &flags); in serial_pxa_console_write()
615 ier = serial_in(up, UART_IER); in serial_pxa_console_write()
616 serial_out(up, UART_IER, UART_IER_UUE); in serial_pxa_console_write()
618 uart_console_write(&up->port, s, count, serial_pxa_console_putchar); in serial_pxa_console_write()
621 * Finally, wait for transmitter to become empty in serial_pxa_console_write()
624 wait_for_xmitr(up); in serial_pxa_console_write()
625 serial_out(up, UART_IER, ier); in serial_pxa_console_write()
628 uart_port_unlock_irqrestore(&up->port, flags); in serial_pxa_console_write()
629 clk_disable(up->clk); in serial_pxa_console_write()
640 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_get_poll_char() local
641 unsigned char lsr = serial_in(up, UART_LSR); in serial_pxa_get_poll_char()
644 lsr = serial_in(up, UART_LSR); in serial_pxa_get_poll_char()
646 return serial_in(up, UART_RX); in serial_pxa_get_poll_char()
654 struct uart_pxa_port *up = (struct uart_pxa_port *)port; in serial_pxa_put_poll_char() local
659 ier = serial_in(up, UART_IER); in serial_pxa_put_poll_char()
660 serial_out(up, UART_IER, UART_IER_UUE); in serial_pxa_put_poll_char()
662 wait_for_xmitr(up); in serial_pxa_put_poll_char()
666 serial_out(up, UART_TX, c); in serial_pxa_put_poll_char()
669 * Finally, wait for transmitter to become empty in serial_pxa_put_poll_char()
672 wait_for_xmitr(up); in serial_pxa_put_poll_char()
673 serial_out(up, UART_IER, ier); in serial_pxa_put_poll_char()
681 struct uart_pxa_port *up; in serial_pxa_console_setup() local
687 if (co->index == -1 || co->index >= serial_pxa_reg.nr) in serial_pxa_console_setup()
688 co->index = 0; in serial_pxa_console_setup()
689 up = serial_pxa_ports[co->index]; in serial_pxa_console_setup()
690 if (!up) in serial_pxa_console_setup()
691 return -ENODEV; in serial_pxa_console_setup()
696 return uart_set_options(&up->port, co, baud, parity, bits, flow); in serial_pxa_console_setup()
705 .index = -1,
754 uart_suspend_port(&serial_pxa_reg, &sport->port); in serial_pxa_suspend()
764 uart_resume_port(&serial_pxa_reg, &sport->port); in serial_pxa_resume()
776 { .compatible = "mrvl,pxa-uart", },
777 { .compatible = "mrvl,mmp-uart", },
784 struct device_node *np = pdev->dev.of_node; in serial_pxa_probe_dt()
792 dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); in serial_pxa_probe_dt()
795 sport->port.line = ret; in serial_pxa_probe_dt()
808 return -ENODEV; in serial_pxa_probe()
816 return -ENOMEM; in serial_pxa_probe()
818 sport->clk = clk_get(&dev->dev, NULL); in serial_pxa_probe()
819 if (IS_ERR(sport->clk)) { in serial_pxa_probe()
820 ret = PTR_ERR(sport->clk); in serial_pxa_probe()
824 ret = clk_prepare(sport->clk); in serial_pxa_probe()
826 clk_put(sport->clk); in serial_pxa_probe()
830 sport->port.type = PORT_PXA; in serial_pxa_probe()
831 sport->port.iotype = UPIO_MEM; in serial_pxa_probe()
832 sport->port.mapbase = mmres->start; in serial_pxa_probe()
833 sport->port.irq = irq; in serial_pxa_probe()
834 sport->port.fifosize = 64; in serial_pxa_probe()
835 sport->port.ops = &serial_pxa_pops; in serial_pxa_probe()
836 sport->port.dev = &dev->dev; in serial_pxa_probe()
837 sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; in serial_pxa_probe()
838 sport->port.uartclk = clk_get_rate(sport->clk); in serial_pxa_probe()
839 sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_PXA_CONSOLE); in serial_pxa_probe()
843 sport->port.line = dev->id; in serial_pxa_probe()
846 if (sport->port.line >= ARRAY_SIZE(serial_pxa_ports)) { in serial_pxa_probe()
847 dev_err(&dev->dev, "serial%d out of range\n", sport->port.line); in serial_pxa_probe()
848 ret = -EINVAL; in serial_pxa_probe()
851 snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1); in serial_pxa_probe()
853 sport->port.membase = ioremap(mmres->start, resource_size(mmres)); in serial_pxa_probe()
854 if (!sport->port.membase) { in serial_pxa_probe()
855 ret = -ENOMEM; in serial_pxa_probe()
859 serial_pxa_ports[sport->port.line] = sport; in serial_pxa_probe()
861 uart_add_one_port(&serial_pxa_reg, &sport->port); in serial_pxa_probe()
867 clk_unprepare(sport->clk); in serial_pxa_probe()
868 clk_put(sport->clk); in serial_pxa_probe()
878 .name = "pxa2xx-uart",