Lines Matching +full:port +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0+
24 #include <linux/platform_data/serial-sccnxp.h>
27 #define SCCNXP_NAME "uart-sccnxp"
33 # define MR0_BAUD_EXT1 (1 << 0)
35 # define MR0_FIFO (1 << 3)
36 # define MR0_TXLVL (1 << 4)
38 # define MR1_BITS_6 (1 << 0)
42 # define MR1_PAR_ODD (1 << 2)
47 # define SR_RXRDY (1 << 0)
48 # define SR_FULL (1 << 1)
49 # define SR_TXRDY (1 << 2)
50 # define SR_TXEMT (1 << 3)
51 # define SR_OVR (1 << 4)
52 # define SR_PE (1 << 5)
53 # define SR_FE (1 << 6)
54 # define SR_BRK (1 << 7)
58 # define CR_RX_ENABLE (1 << 0)
59 # define CR_RX_DISABLE (1 << 1)
60 # define CR_TX_ENABLE (1 << 2)
61 # define CR_TX_DISABLE (1 << 3)
75 # define ACR_BAUD1 (1 << 7)
79 # define IMR_TXRDY (1 << 0)
80 # define IMR_RXRDY (1 << 1)
81 # define ISR_TXRDY(x) (1 << ((x * 4) + 0))
82 # define ISR_RXRDY(x) (1 << ((x * 4) + 1))
93 #define MCTRL_IBIT(cfg, sig) ((((cfg) >> (sig)) & 0xf) - LINE_IP0)
94 #define MCTRL_OBIT(cfg, sig) ((((cfg) >> (sig)) & 0xf) - LINE_OP0)
113 struct uart_port port[SCCNXP_MAX_UARTS]; member
148 .nr = 1,
170 .nr = 1,
223 static u8 sccnxp_read(struct uart_port *port, u8 reg) in sccnxp_read() argument
225 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_read()
228 ret = readb(port->membase + (reg << port->regshift)); in sccnxp_read()
230 ndelay(s->chip->trwd); in sccnxp_read()
235 static void sccnxp_write(struct uart_port *port, u8 reg, u8 v) in sccnxp_write() argument
237 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_write()
239 writeb(v, port->membase + (reg << port->regshift)); in sccnxp_write()
241 ndelay(s->chip->trwd); in sccnxp_write()
244 static u8 sccnxp_port_read(struct uart_port *port, u8 reg) in sccnxp_port_read() argument
246 return sccnxp_read(port, (port->line << 3) + reg); in sccnxp_port_read()
249 static void sccnxp_port_write(struct uart_port *port, u8 reg, u8 v) in sccnxp_port_write() argument
251 sccnxp_write(port, (port->line << 3) + reg, v); in sccnxp_port_write()
256 int err = abs(a - b); in sccnxp_update_best_err()
263 return 1; in sccnxp_update_best_err()
274 { 1, ACR_BAUD0, MR0_BAUD_NORMAL, 110, },
280 { 1, ACR_BAUD0, MR0_BAUD_EXT2, 880, },
303 static int sccnxp_set_baud(struct uart_port *port, int baud) in sccnxp_set_baud() argument
305 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_set_baud()
307 struct sccnxp_chip *chip = s->chip; in sccnxp_set_baud()
311 div_std = DIV_ROUND_CLOSEST(port->uartclk, 2 * 16 * baud); in sccnxp_set_baud()
313 bestbaud = DIV_ROUND_CLOSEST(port->uartclk, 2 * 16 * div_std); in sccnxp_set_baud()
316 sccnxp_port_write(port, SCCNXP_CTPU_REG, div_std >> 8); in sccnxp_set_baud()
317 sccnxp_port_write(port, SCCNXP_CTPL_REG, div_std); in sccnxp_set_baud()
319 sccnxp_port_read(port, SCCNXP_START_COUNTER_REG); in sccnxp_set_baud()
324 if (baud_std[i].mr0 && !(chip->flags & SCCNXP_HAVE_MR0)) in sccnxp_set_baud()
326 div_std = DIV_ROUND_CLOSEST(chip->freq_std, baud_std[i].baud); in sccnxp_set_baud()
327 tmp_baud = DIV_ROUND_CLOSEST(port->uartclk, div_std); in sccnxp_set_baud()
336 if (chip->flags & SCCNXP_HAVE_MR0) { in sccnxp_set_baud()
340 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_MRPTR0); in sccnxp_set_baud()
341 sccnxp_port_write(port, SCCNXP_MR_REG, mr0); in sccnxp_set_baud()
344 sccnxp_port_write(port, SCCNXP_ACR_REG, acr | ACR_TIMER_MODE); in sccnxp_set_baud()
345 sccnxp_port_write(port, SCCNXP_CSR_REG, (csr << 4) | csr); in sccnxp_set_baud()
348 dev_dbg(port->dev, "Baudrate desired: %i, calculated: %i\n", in sccnxp_set_baud()
354 static void sccnxp_enable_irq(struct uart_port *port, int mask) in sccnxp_enable_irq() argument
356 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_enable_irq()
358 s->imr |= mask << (port->line * 4); in sccnxp_enable_irq()
359 sccnxp_write(port, SCCNXP_IMR_REG, s->imr); in sccnxp_enable_irq()
362 static void sccnxp_disable_irq(struct uart_port *port, int mask) in sccnxp_disable_irq() argument
364 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_disable_irq()
366 s->imr &= ~(mask << (port->line * 4)); in sccnxp_disable_irq()
367 sccnxp_write(port, SCCNXP_IMR_REG, s->imr); in sccnxp_disable_irq()
370 static void sccnxp_set_bit(struct uart_port *port, int sig, int state) in sccnxp_set_bit() argument
373 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_set_bit()
375 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(sig)) { in sccnxp_set_bit()
376 bitmask = 1 << MCTRL_OBIT(s->pdata.mctrl_cfg[port->line], sig); in sccnxp_set_bit()
378 sccnxp_write(port, SCCNXP_SOP_REG, bitmask); in sccnxp_set_bit()
380 sccnxp_write(port, SCCNXP_ROP_REG, bitmask); in sccnxp_set_bit()
384 static void sccnxp_handle_rx(struct uart_port *port) in sccnxp_handle_rx() argument
390 sr = sccnxp_port_read(port, SCCNXP_SR_REG); in sccnxp_handle_rx()
395 ch = sccnxp_port_read(port, SCCNXP_RHR_REG); in sccnxp_handle_rx()
397 port->icount.rx++; in sccnxp_handle_rx()
402 port->icount.brk++; in sccnxp_handle_rx()
403 sccnxp_port_write(port, SCCNXP_CR_REG, in sccnxp_handle_rx()
405 if (uart_handle_break(port)) in sccnxp_handle_rx()
408 port->icount.parity++; in sccnxp_handle_rx()
410 port->icount.frame++; in sccnxp_handle_rx()
412 port->icount.overrun++; in sccnxp_handle_rx()
413 sccnxp_port_write(port, SCCNXP_CR_REG, in sccnxp_handle_rx()
417 sr &= port->read_status_mask; in sccnxp_handle_rx()
428 if (uart_handle_sysrq_char(port, ch)) in sccnxp_handle_rx()
431 if (sr & port->ignore_status_mask) in sccnxp_handle_rx()
434 uart_insert_char(port, sr, SR_OVR, ch, flag); in sccnxp_handle_rx()
437 tty_flip_buffer_push(&port->state->port); in sccnxp_handle_rx()
440 static void sccnxp_handle_tx(struct uart_port *port) in sccnxp_handle_tx() argument
443 struct circ_buf *xmit = &port->state->xmit; in sccnxp_handle_tx()
444 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_handle_tx()
446 if (unlikely(port->x_char)) { in sccnxp_handle_tx()
447 sccnxp_port_write(port, SCCNXP_THR_REG, port->x_char); in sccnxp_handle_tx()
448 port->icount.tx++; in sccnxp_handle_tx()
449 port->x_char = 0; in sccnxp_handle_tx()
453 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { in sccnxp_handle_tx()
455 if (sccnxp_port_read(port, SCCNXP_SR_REG) & SR_TXEMT) { in sccnxp_handle_tx()
456 sccnxp_disable_irq(port, IMR_TXRDY); in sccnxp_handle_tx()
459 if (s->chip->flags & SCCNXP_HAVE_IO) in sccnxp_handle_tx()
460 sccnxp_set_bit(port, DIR_OP, 0); in sccnxp_handle_tx()
466 sr = sccnxp_port_read(port, SCCNXP_SR_REG); in sccnxp_handle_tx()
470 sccnxp_port_write(port, SCCNXP_THR_REG, xmit->buf[xmit->tail]); in sccnxp_handle_tx()
471 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in sccnxp_handle_tx()
472 port->icount.tx++; in sccnxp_handle_tx()
476 uart_write_wakeup(port); in sccnxp_handle_tx()
485 isr = sccnxp_read(&s->port[0], SCCNXP_ISR_REG); in sccnxp_handle_events()
486 isr &= s->imr; in sccnxp_handle_events()
490 for (i = 0; i < s->uart.nr; i++) { in sccnxp_handle_events()
491 if (s->opened[i] && (isr & ISR_RXRDY(i))) in sccnxp_handle_events()
492 sccnxp_handle_rx(&s->port[i]); in sccnxp_handle_events()
493 if (s->opened[i] && (isr & ISR_TXRDY(i))) in sccnxp_handle_events()
494 sccnxp_handle_tx(&s->port[i]); in sccnxp_handle_events()
496 } while (1); in sccnxp_handle_events()
504 spin_lock_irqsave(&s->lock, flags); in sccnxp_timer()
506 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_timer()
508 mod_timer(&s->timer, jiffies + usecs_to_jiffies(s->pdata.poll_time_us)); in sccnxp_timer()
516 spin_lock_irqsave(&s->lock, flags); in sccnxp_ist()
518 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_ist()
523 static void sccnxp_start_tx(struct uart_port *port) in sccnxp_start_tx() argument
525 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_start_tx()
528 spin_lock_irqsave(&s->lock, flags); in sccnxp_start_tx()
531 if (s->chip->flags & SCCNXP_HAVE_IO) in sccnxp_start_tx()
532 sccnxp_set_bit(port, DIR_OP, 1); in sccnxp_start_tx()
534 sccnxp_enable_irq(port, IMR_TXRDY); in sccnxp_start_tx()
536 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_start_tx()
539 static void sccnxp_stop_tx(struct uart_port *port) in sccnxp_stop_tx() argument
544 static void sccnxp_stop_rx(struct uart_port *port) in sccnxp_stop_rx() argument
546 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_stop_rx()
549 spin_lock_irqsave(&s->lock, flags); in sccnxp_stop_rx()
550 sccnxp_port_write(port, SCCNXP_CR_REG, CR_RX_DISABLE); in sccnxp_stop_rx()
551 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_stop_rx()
554 static unsigned int sccnxp_tx_empty(struct uart_port *port) in sccnxp_tx_empty() argument
558 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_tx_empty()
560 spin_lock_irqsave(&s->lock, flags); in sccnxp_tx_empty()
561 val = sccnxp_port_read(port, SCCNXP_SR_REG); in sccnxp_tx_empty()
562 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_tx_empty()
567 static void sccnxp_set_mctrl(struct uart_port *port, unsigned int mctrl) in sccnxp_set_mctrl() argument
569 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_set_mctrl()
572 if (!(s->chip->flags & SCCNXP_HAVE_IO)) in sccnxp_set_mctrl()
575 spin_lock_irqsave(&s->lock, flags); in sccnxp_set_mctrl()
577 sccnxp_set_bit(port, DTR_OP, mctrl & TIOCM_DTR); in sccnxp_set_mctrl()
578 sccnxp_set_bit(port, RTS_OP, mctrl & TIOCM_RTS); in sccnxp_set_mctrl()
580 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_set_mctrl()
583 static unsigned int sccnxp_get_mctrl(struct uart_port *port) in sccnxp_get_mctrl() argument
587 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_get_mctrl()
590 if (!(s->chip->flags & SCCNXP_HAVE_IO)) in sccnxp_get_mctrl()
593 spin_lock_irqsave(&s->lock, flags); in sccnxp_get_mctrl()
595 ipr = ~sccnxp_read(port, SCCNXP_IPCR_REG); in sccnxp_get_mctrl()
597 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(DSR_IP)) { in sccnxp_get_mctrl()
598 bitmask = 1 << MCTRL_IBIT(s->pdata.mctrl_cfg[port->line], in sccnxp_get_mctrl()
603 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(CTS_IP)) { in sccnxp_get_mctrl()
604 bitmask = 1 << MCTRL_IBIT(s->pdata.mctrl_cfg[port->line], in sccnxp_get_mctrl()
609 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(DCD_IP)) { in sccnxp_get_mctrl()
610 bitmask = 1 << MCTRL_IBIT(s->pdata.mctrl_cfg[port->line], in sccnxp_get_mctrl()
615 if (s->pdata.mctrl_cfg[port->line] & MCTRL_MASK(RNG_IP)) { in sccnxp_get_mctrl()
616 bitmask = 1 << MCTRL_IBIT(s->pdata.mctrl_cfg[port->line], in sccnxp_get_mctrl()
622 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_get_mctrl()
627 static void sccnxp_break_ctl(struct uart_port *port, int break_state) in sccnxp_break_ctl() argument
629 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_break_ctl()
632 spin_lock_irqsave(&s->lock, flags); in sccnxp_break_ctl()
633 sccnxp_port_write(port, SCCNXP_CR_REG, break_state ? in sccnxp_break_ctl()
635 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_break_ctl()
638 static void sccnxp_set_termios(struct uart_port *port, in sccnxp_set_termios() argument
641 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_set_termios()
646 spin_lock_irqsave(&s->lock, flags); in sccnxp_set_termios()
649 termios->c_cflag &= ~CMSPAR; in sccnxp_set_termios()
652 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_RX_RESET | in sccnxp_set_termios()
654 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_TX_RESET); in sccnxp_set_termios()
655 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_STATUS_RESET); in sccnxp_set_termios()
656 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_BREAK_RESET); in sccnxp_set_termios()
659 switch (termios->c_cflag & CSIZE) { in sccnxp_set_termios()
676 if (termios->c_cflag & PARENB) { in sccnxp_set_termios()
677 if (termios->c_cflag & PARODD) in sccnxp_set_termios()
683 mr2 = (termios->c_cflag & CSTOPB) ? MR2_STOP2 : MR2_STOP1; in sccnxp_set_termios()
686 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_MRPTR1); in sccnxp_set_termios()
687 sccnxp_port_write(port, SCCNXP_MR_REG, mr1); in sccnxp_set_termios()
688 sccnxp_port_write(port, SCCNXP_MR_REG, mr2); in sccnxp_set_termios()
691 port->read_status_mask = SR_OVR; in sccnxp_set_termios()
692 if (termios->c_iflag & INPCK) in sccnxp_set_termios()
693 port->read_status_mask |= SR_PE | SR_FE; in sccnxp_set_termios()
694 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK)) in sccnxp_set_termios()
695 port->read_status_mask |= SR_BRK; in sccnxp_set_termios()
698 port->ignore_status_mask = 0; in sccnxp_set_termios()
699 if (termios->c_iflag & IGNBRK) in sccnxp_set_termios()
700 port->ignore_status_mask |= SR_BRK; in sccnxp_set_termios()
701 if (termios->c_iflag & IGNPAR) in sccnxp_set_termios()
702 port->ignore_status_mask |= SR_PE; in sccnxp_set_termios()
703 if (!(termios->c_cflag & CREAD)) in sccnxp_set_termios()
704 port->ignore_status_mask |= SR_PE | SR_OVR | SR_FE | SR_BRK; in sccnxp_set_termios()
707 baud = uart_get_baud_rate(port, termios, old, 50, in sccnxp_set_termios()
708 (s->chip->flags & SCCNXP_HAVE_MR0) ? in sccnxp_set_termios()
710 baud = sccnxp_set_baud(port, baud); in sccnxp_set_termios()
713 uart_update_timeout(port, termios->c_cflag, baud); in sccnxp_set_termios()
720 sccnxp_port_write(port, SCCNXP_CR_REG, CR_RX_ENABLE | CR_TX_ENABLE); in sccnxp_set_termios()
722 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_set_termios()
725 static int sccnxp_startup(struct uart_port *port) in sccnxp_startup() argument
727 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_startup()
730 spin_lock_irqsave(&s->lock, flags); in sccnxp_startup()
732 if (s->chip->flags & SCCNXP_HAVE_IO) { in sccnxp_startup()
734 sccnxp_write(port, SCCNXP_OPCR_REG, 0); in sccnxp_startup()
738 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_RX_RESET); in sccnxp_startup()
739 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_TX_RESET); in sccnxp_startup()
740 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_STATUS_RESET); in sccnxp_startup()
741 sccnxp_port_write(port, SCCNXP_CR_REG, CR_CMD_BREAK_RESET); in sccnxp_startup()
744 sccnxp_port_write(port, SCCNXP_CR_REG, CR_RX_ENABLE | CR_TX_ENABLE); in sccnxp_startup()
747 sccnxp_enable_irq(port, IMR_RXRDY); in sccnxp_startup()
749 s->opened[port->line] = 1; in sccnxp_startup()
751 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_startup()
756 static void sccnxp_shutdown(struct uart_port *port) in sccnxp_shutdown() argument
758 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_shutdown()
761 spin_lock_irqsave(&s->lock, flags); in sccnxp_shutdown()
763 s->opened[port->line] = 0; in sccnxp_shutdown()
766 sccnxp_disable_irq(port, IMR_TXRDY | IMR_RXRDY); in sccnxp_shutdown()
769 sccnxp_port_write(port, SCCNXP_CR_REG, CR_RX_DISABLE | CR_TX_DISABLE); in sccnxp_shutdown()
772 if (s->chip->flags & SCCNXP_HAVE_IO) in sccnxp_shutdown()
773 sccnxp_set_bit(port, DIR_OP, 0); in sccnxp_shutdown()
775 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_shutdown()
778 static const char *sccnxp_type(struct uart_port *port) in sccnxp_type() argument
780 struct sccnxp_port *s = dev_get_drvdata(port->dev); in sccnxp_type()
782 return (port->type == PORT_SC26XX) ? s->chip->name : NULL; in sccnxp_type()
785 static void sccnxp_release_port(struct uart_port *port) in sccnxp_release_port() argument
790 static int sccnxp_request_port(struct uart_port *port) in sccnxp_request_port() argument
796 static void sccnxp_config_port(struct uart_port *port, int flags) in sccnxp_config_port() argument
799 port->type = PORT_SC26XX; in sccnxp_config_port()
802 static int sccnxp_verify_port(struct uart_port *port, struct serial_struct *s) in sccnxp_verify_port() argument
804 if ((s->type == PORT_UNKNOWN) || (s->type == PORT_SC26XX)) in sccnxp_verify_port()
806 if (s->irq == port->irq) in sccnxp_verify_port()
809 return -EINVAL; in sccnxp_verify_port()
831 static void sccnxp_console_putchar(struct uart_port *port, int c) in sccnxp_console_putchar() argument
835 while (tryes--) { in sccnxp_console_putchar()
836 if (sccnxp_port_read(port, SCCNXP_SR_REG) & SR_TXRDY) { in sccnxp_console_putchar()
837 sccnxp_port_write(port, SCCNXP_THR_REG, c); in sccnxp_console_putchar()
846 struct sccnxp_port *s = (struct sccnxp_port *)co->data; in sccnxp_console_write()
847 struct uart_port *port = &s->port[co->index]; in sccnxp_console_write() local
850 spin_lock_irqsave(&s->lock, flags); in sccnxp_console_write()
851 uart_console_write(port, c, n, sccnxp_console_putchar); in sccnxp_console_write()
852 spin_unlock_irqrestore(&s->lock, flags); in sccnxp_console_write()
857 struct sccnxp_port *s = (struct sccnxp_port *)co->data; in sccnxp_console_setup()
858 struct uart_port *port = &s->port[(co->index > 0) ? co->index : 0]; in sccnxp_console_setup() local
864 return uart_set_options(port, co, baud, parity, bits, flow); in sccnxp_console_setup()
884 struct sccnxp_pdata *pdata = dev_get_platdata(&pdev->dev); in sccnxp_probe()
890 membase = devm_ioremap_resource(&pdev->dev, res); in sccnxp_probe()
894 s = devm_kzalloc(&pdev->dev, sizeof(struct sccnxp_port), GFP_KERNEL); in sccnxp_probe()
896 dev_err(&pdev->dev, "Error allocating port structure\n"); in sccnxp_probe()
897 return -ENOMEM; in sccnxp_probe()
901 spin_lock_init(&s->lock); in sccnxp_probe()
903 s->chip = (struct sccnxp_chip *)pdev->id_entry->driver_data; in sccnxp_probe()
905 s->regulator = devm_regulator_get(&pdev->dev, "vcc"); in sccnxp_probe()
906 if (!IS_ERR(s->regulator)) { in sccnxp_probe()
907 ret = regulator_enable(s->regulator); in sccnxp_probe()
909 dev_err(&pdev->dev, in sccnxp_probe()
913 } else if (PTR_ERR(s->regulator) == -EPROBE_DEFER) in sccnxp_probe()
914 return -EPROBE_DEFER; in sccnxp_probe()
916 clk = devm_clk_get(&pdev->dev, NULL); in sccnxp_probe()
919 if (ret == -EPROBE_DEFER) in sccnxp_probe()
927 ret = devm_add_action_or_reset(&pdev->dev, in sccnxp_probe()
937 dev_notice(&pdev->dev, "Using default clock frequency\n"); in sccnxp_probe()
938 uartclk = s->chip->freq_std; in sccnxp_probe()
942 if ((uartclk < s->chip->freq_min) || (uartclk > s->chip->freq_max)) { in sccnxp_probe()
943 dev_err(&pdev->dev, "Frequency out of bounds\n"); in sccnxp_probe()
944 ret = -EINVAL; in sccnxp_probe()
949 memcpy(&s->pdata, pdata, sizeof(struct sccnxp_pdata)); in sccnxp_probe()
951 if (s->pdata.poll_time_us) { in sccnxp_probe()
952 dev_info(&pdev->dev, "Using poll mode, resolution %u usecs\n", in sccnxp_probe()
953 s->pdata.poll_time_us); in sccnxp_probe()
954 s->poll = 1; in sccnxp_probe()
957 if (!s->poll) { in sccnxp_probe()
958 s->irq = platform_get_irq(pdev, 0); in sccnxp_probe()
959 if (s->irq < 0) { in sccnxp_probe()
960 ret = -ENXIO; in sccnxp_probe()
965 s->uart.owner = THIS_MODULE; in sccnxp_probe()
966 s->uart.dev_name = "ttySC"; in sccnxp_probe()
967 s->uart.major = SCCNXP_MAJOR; in sccnxp_probe()
968 s->uart.minor = SCCNXP_MINOR; in sccnxp_probe()
969 s->uart.nr = s->chip->nr; in sccnxp_probe()
971 s->uart.cons = &s->console; in sccnxp_probe()
972 s->uart.cons->device = uart_console_device; in sccnxp_probe()
973 s->uart.cons->write = sccnxp_console_write; in sccnxp_probe()
974 s->uart.cons->setup = sccnxp_console_setup; in sccnxp_probe()
975 s->uart.cons->flags = CON_PRINTBUFFER; in sccnxp_probe()
976 s->uart.cons->index = -1; in sccnxp_probe()
977 s->uart.cons->data = s; in sccnxp_probe()
978 strcpy(s->uart.cons->name, "ttySC"); in sccnxp_probe()
980 ret = uart_register_driver(&s->uart); in sccnxp_probe()
982 dev_err(&pdev->dev, "Registering UART driver failed\n"); in sccnxp_probe()
986 for (i = 0; i < s->uart.nr; i++) { in sccnxp_probe()
987 s->port[i].line = i; in sccnxp_probe()
988 s->port[i].dev = &pdev->dev; in sccnxp_probe()
989 s->port[i].irq = s->irq; in sccnxp_probe()
990 s->port[i].type = PORT_SC26XX; in sccnxp_probe()
991 s->port[i].fifosize = s->chip->fifosize; in sccnxp_probe()
992 s->port[i].flags = UPF_SKIP_TEST | UPF_FIXED_TYPE; in sccnxp_probe()
993 s->port[i].iotype = UPIO_MEM; in sccnxp_probe()
994 s->port[i].mapbase = res->start; in sccnxp_probe()
995 s->port[i].membase = membase; in sccnxp_probe()
996 s->port[i].regshift = s->pdata.reg_shift; in sccnxp_probe()
997 s->port[i].uartclk = uartclk; in sccnxp_probe()
998 s->port[i].ops = &sccnxp_ops; in sccnxp_probe()
999 s->port[i].has_sysrq = IS_ENABLED(CONFIG_SERIAL_SCCNXP_CONSOLE); in sccnxp_probe()
1000 uart_add_one_port(&s->uart, &s->port[i]); in sccnxp_probe()
1002 if (s->chip->flags & SCCNXP_HAVE_IO) in sccnxp_probe()
1003 sccnxp_set_bit(&s->port[i], DIR_OP, 0); in sccnxp_probe()
1007 s->imr = 0; in sccnxp_probe()
1008 sccnxp_write(&s->port[0], SCCNXP_IMR_REG, 0); in sccnxp_probe()
1010 if (!s->poll) { in sccnxp_probe()
1011 ret = devm_request_threaded_irq(&pdev->dev, s->irq, NULL, in sccnxp_probe()
1015 dev_name(&pdev->dev), s); in sccnxp_probe()
1019 dev_err(&pdev->dev, "Unable to reguest IRQ %i\n", s->irq); in sccnxp_probe()
1021 timer_setup(&s->timer, sccnxp_timer, 0); in sccnxp_probe()
1022 mod_timer(&s->timer, jiffies + in sccnxp_probe()
1023 usecs_to_jiffies(s->pdata.poll_time_us)); in sccnxp_probe()
1027 uart_unregister_driver(&s->uart); in sccnxp_probe()
1029 if (!IS_ERR(s->regulator)) in sccnxp_probe()
1030 regulator_disable(s->regulator); in sccnxp_probe()
1040 if (!s->poll) in sccnxp_remove()
1041 devm_free_irq(&pdev->dev, s->irq, s); in sccnxp_remove()
1043 del_timer_sync(&s->timer); in sccnxp_remove()
1045 for (i = 0; i < s->uart.nr; i++) in sccnxp_remove()
1046 uart_remove_one_port(&s->uart, &s->port[i]); in sccnxp_remove()
1048 uart_unregister_driver(&s->uart); in sccnxp_remove()
1050 if (!IS_ERR(s->regulator)) in sccnxp_remove()
1051 return regulator_disable(s->regulator); in sccnxp_remove()