Lines Matching +full:port +full:- +full:level
1 // SPDX-License-Identifier: GPL-2.0+
3 * SC16IS7xx tty serial driver - common code
50 #define SC16IS7XX_TXLVL_REG (0x08) /* TX FIFO level */
51 #define SC16IS7XX_RXLVL_REG (0x09) /* RX FIFO level */
53 * - only on 75x/76x
56 * - only on 75x/76x
59 * - only on 75x/76x
62 * - only on 75x/76x
68 #define SC16IS7XX_TLR_REG (0x07) /* Trigger level */
90 /* IER register bits - write only if (EFR[4] == 1) */
100 #define SC16IS7XX_FCR_RXLVLL_BIT BIT(6) /* RX Trigger level LSB */
101 #define SC16IS7XX_FCR_RXLVLH_BIT BIT(7) /* RX Trigger level MSB */
103 /* FCR register bits - write only if (EFR[4] == 1) */
104 #define SC16IS7XX_FCR_TXLVLL_BIT BIT(4) /* TX Trigger level LSB */
105 #define SC16IS7XX_FCR_TXLVLH_BIT BIT(5) /* TX Trigger level MSB */
113 #define SC16IS7XX_IIR_RTOI_SRC 0x0c /* RX time-out interrupt */
115 * - only on 75x/76x
118 * - only on 75x/76x
130 * 00 -> 5 bit words
131 * 01 -> 6 bit words
132 * 10 -> 7 bit words
133 * 11 -> 8 bit words
138 * 0 -> 1 stop bit
139 * 1 -> 1-1.5 stop bits if
145 #define SC16IS7XX_LCR_FORCEPARITY_BIT BIT(5) /* 9-bit multidrop parity */
159 * - only on 75x/76x
165 * - write enabled
169 * - write enabled
173 * - write enabled
197 * - only on 75x/76x
201 * - only on 75x/76x
205 * - only on 75x/76x
209 * - only on 75x/76x
212 * - only on 75x/76x
215 * - only on 75x/76x
223 * no built-in hardware check to make sure this condition is met. Also, the TCR
237 * When the trigger level setting in TLR is zero, the SC16IS74x/75x/76x uses the
238 * trigger level setting defined in FCR. If TLR has non-zero trigger level value
239 * the trigger level defined in FCR is discarded. This applies to both transmit
240 * FIFO and receive FIFO trigger level setting.
242 * When TLR is used for RX trigger level control, FCR[7:6] should be left at the
255 #define SC16IS7XX_EFCR_9BIT_MODE_BIT BIT(0) /* Enable 9-bit or Multidrop
263 * - Only 75x/76x
265 * - Only 76x
280 * 00 -> no transmitter flow
282 * 01 -> transmitter generates
284 * 10 -> transmitter generates
286 * 11 -> transmitter generates
294 * 00 -> no received flow
296 * 01 -> receiver compares
298 * 10 -> receiver compares
300 * 11 -> receiver compares
328 struct uart_port port; member
365 static u8 sc16is7xx_port_read(struct uart_port *port, u8 reg) in sc16is7xx_port_read() argument
367 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_port_read()
370 regmap_read(one->regmap, reg, &val); in sc16is7xx_port_read()
375 static void sc16is7xx_port_write(struct uart_port *port, u8 reg, u8 val) in sc16is7xx_port_write() argument
377 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_port_write()
379 regmap_write(one->regmap, reg, val); in sc16is7xx_port_write()
382 static void sc16is7xx_fifo_read(struct uart_port *port, u8 *rxbuf, unsigned int rxlen) in sc16is7xx_fifo_read() argument
384 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_fifo_read()
386 regmap_noinc_read(one->regmap, SC16IS7XX_RHR_REG, rxbuf, rxlen); in sc16is7xx_fifo_read()
389 static void sc16is7xx_fifo_write(struct uart_port *port, u8 *txbuf, u8 to_send) in sc16is7xx_fifo_write() argument
391 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_fifo_write()
394 * Don't send zero-length data, at least on SPI it confuses the chip in sc16is7xx_fifo_write()
400 regmap_noinc_write(one->regmap, SC16IS7XX_THR_REG, txbuf, to_send); in sc16is7xx_fifo_write()
403 static void sc16is7xx_port_update(struct uart_port *port, u8 reg, in sc16is7xx_port_update() argument
406 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_port_update()
408 regmap_update_bits(one->regmap, reg, mask, val); in sc16is7xx_port_update()
411 static void sc16is7xx_power(struct uart_port *port, int on) in sc16is7xx_power() argument
413 sc16is7xx_port_update(port, SC16IS7XX_IER_REG, in sc16is7xx_power()
432 static void sc16is7xx_efr_lock(struct uart_port *port) in sc16is7xx_efr_lock() argument
434 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_efr_lock()
436 mutex_lock(&one->efr_lock); in sc16is7xx_efr_lock()
439 one->old_lcr = sc16is7xx_port_read(port, SC16IS7XX_LCR_REG); in sc16is7xx_efr_lock()
442 sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, SC16IS7XX_LCR_CONF_MODE_B); in sc16is7xx_efr_lock()
445 regcache_cache_bypass(one->regmap, true); in sc16is7xx_efr_lock()
448 static void sc16is7xx_efr_unlock(struct uart_port *port) in sc16is7xx_efr_unlock() argument
450 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_efr_unlock()
452 /* Re-enable cache updates when writing to normal registers */ in sc16is7xx_efr_unlock()
453 regcache_cache_bypass(one->regmap, false); in sc16is7xx_efr_unlock()
456 sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, one->old_lcr); in sc16is7xx_efr_unlock()
458 mutex_unlock(&one->efr_lock); in sc16is7xx_efr_unlock()
461 static void sc16is7xx_ier_clear(struct uart_port *port, u8 bit) in sc16is7xx_ier_clear() argument
463 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); in sc16is7xx_ier_clear()
464 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_ier_clear()
466 lockdep_assert_held_once(&port->lock); in sc16is7xx_ier_clear()
468 one->config.flags |= SC16IS7XX_RECONF_IER; in sc16is7xx_ier_clear()
469 one->config.ier_mask |= bit; in sc16is7xx_ier_clear()
470 one->config.ier_val &= ~bit; in sc16is7xx_ier_clear()
471 kthread_queue_work(&s->kworker, &one->reg_work); in sc16is7xx_ier_clear()
474 static void sc16is7xx_ier_set(struct uart_port *port, u8 bit) in sc16is7xx_ier_set() argument
476 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); in sc16is7xx_ier_set()
477 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_ier_set()
479 lockdep_assert_held_once(&port->lock); in sc16is7xx_ier_set()
481 one->config.flags |= SC16IS7XX_RECONF_IER; in sc16is7xx_ier_set()
482 one->config.ier_mask |= bit; in sc16is7xx_ier_set()
483 one->config.ier_val |= bit; in sc16is7xx_ier_set()
484 kthread_queue_work(&s->kworker, &one->reg_work); in sc16is7xx_ier_set()
487 static void sc16is7xx_stop_tx(struct uart_port *port) in sc16is7xx_stop_tx() argument
489 sc16is7xx_ier_clear(port, SC16IS7XX_IER_THRI_BIT); in sc16is7xx_stop_tx()
492 static void sc16is7xx_stop_rx(struct uart_port *port) in sc16is7xx_stop_rx() argument
494 sc16is7xx_ier_clear(port, SC16IS7XX_IER_RDI_BIT); in sc16is7xx_stop_rx()
571 * -----------------------
573 * divisor = ---------------------------
574 * baud-rate x sampling-rate
576 static int sc16is7xx_set_baud(struct uart_port *port, int baud) in sc16is7xx_set_baud() argument
578 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_set_baud()
581 unsigned long clk = port->uartclk, div = clk / 16 / baud; in sc16is7xx_set_baud()
589 sc16is7xx_efr_lock(port); in sc16is7xx_set_baud()
590 sc16is7xx_port_update(port, SC16IS7XX_EFR_REG, in sc16is7xx_set_baud()
593 sc16is7xx_efr_unlock(port); in sc16is7xx_set_baud()
596 sc16is7xx_port_update(port, SC16IS7XX_MCR_REG, in sc16is7xx_set_baud()
600 mutex_lock(&one->efr_lock); in sc16is7xx_set_baud()
603 lcr = sc16is7xx_port_read(port, SC16IS7XX_LCR_REG); in sc16is7xx_set_baud()
604 sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, in sc16is7xx_set_baud()
608 regcache_cache_bypass(one->regmap, true); in sc16is7xx_set_baud()
609 sc16is7xx_port_write(port, SC16IS7XX_DLH_REG, div / 256); in sc16is7xx_set_baud()
610 sc16is7xx_port_write(port, SC16IS7XX_DLL_REG, div % 256); in sc16is7xx_set_baud()
611 regcache_cache_bypass(one->regmap, false); in sc16is7xx_set_baud()
614 sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, lcr); in sc16is7xx_set_baud()
616 mutex_unlock(&one->efr_lock); in sc16is7xx_set_baud()
621 static void sc16is7xx_handle_rx(struct uart_port *port, unsigned int rxlen, in sc16is7xx_handle_rx() argument
624 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_handle_rx()
629 if (unlikely(rxlen >= sizeof(one->buf))) { in sc16is7xx_handle_rx()
630 dev_warn_ratelimited(port->dev, in sc16is7xx_handle_rx()
632 port->line, rxlen); in sc16is7xx_handle_rx()
633 port->icount.buf_overrun++; in sc16is7xx_handle_rx()
634 /* Ensure sanity of RX level */ in sc16is7xx_handle_rx()
635 rxlen = sizeof(one->buf); in sc16is7xx_handle_rx()
641 lsr = sc16is7xx_port_read(port, SC16IS7XX_LSR_REG); in sc16is7xx_handle_rx()
648 one->buf[0] = sc16is7xx_port_read(port, SC16IS7XX_RHR_REG); in sc16is7xx_handle_rx()
651 sc16is7xx_fifo_read(port, one->buf, rxlen); in sc16is7xx_handle_rx()
657 port->icount.rx++; in sc16is7xx_handle_rx()
662 port->icount.brk++; in sc16is7xx_handle_rx()
663 if (uart_handle_break(port)) in sc16is7xx_handle_rx()
666 port->icount.parity++; in sc16is7xx_handle_rx()
668 port->icount.frame++; in sc16is7xx_handle_rx()
670 port->icount.overrun++; in sc16is7xx_handle_rx()
672 lsr &= port->read_status_mask; in sc16is7xx_handle_rx()
684 ch = one->buf[i]; in sc16is7xx_handle_rx()
685 if (uart_handle_sysrq_char(port, ch)) in sc16is7xx_handle_rx()
688 if (lsr & port->ignore_status_mask) in sc16is7xx_handle_rx()
691 uart_insert_char(port, lsr, SC16IS7XX_LSR_OE_BIT, ch, in sc16is7xx_handle_rx()
694 rxlen -= bytes_read; in sc16is7xx_handle_rx()
697 tty_flip_buffer_push(&port->state->port); in sc16is7xx_handle_rx()
700 static void sc16is7xx_handle_tx(struct uart_port *port) in sc16is7xx_handle_tx() argument
702 struct tty_port *tport = &port->state->port; in sc16is7xx_handle_tx()
707 if (unlikely(port->x_char)) { in sc16is7xx_handle_tx()
708 sc16is7xx_port_write(port, SC16IS7XX_THR_REG, port->x_char); in sc16is7xx_handle_tx()
709 port->icount.tx++; in sc16is7xx_handle_tx()
710 port->x_char = 0; in sc16is7xx_handle_tx()
714 if (kfifo_is_empty(&tport->xmit_fifo) || uart_tx_stopped(port)) { in sc16is7xx_handle_tx()
715 uart_port_lock_irqsave(port, &flags); in sc16is7xx_handle_tx()
716 sc16is7xx_stop_tx(port); in sc16is7xx_handle_tx()
717 uart_port_unlock_irqrestore(port, flags); in sc16is7xx_handle_tx()
722 txlen = sc16is7xx_port_read(port, SC16IS7XX_TXLVL_REG); in sc16is7xx_handle_tx()
724 dev_err_ratelimited(port->dev, in sc16is7xx_handle_tx()
730 txlen = kfifo_out_linear_ptr(&tport->xmit_fifo, &tail, txlen); in sc16is7xx_handle_tx()
731 sc16is7xx_fifo_write(port, tail, txlen); in sc16is7xx_handle_tx()
732 uart_xmit_advance(port, txlen); in sc16is7xx_handle_tx()
734 uart_port_lock_irqsave(port, &flags); in sc16is7xx_handle_tx()
735 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in sc16is7xx_handle_tx()
736 uart_write_wakeup(port); in sc16is7xx_handle_tx()
738 if (kfifo_is_empty(&tport->xmit_fifo)) in sc16is7xx_handle_tx()
739 sc16is7xx_stop_tx(port); in sc16is7xx_handle_tx()
741 sc16is7xx_ier_set(port, SC16IS7XX_IER_THRI_BIT); in sc16is7xx_handle_tx()
742 uart_port_unlock_irqrestore(port, flags); in sc16is7xx_handle_tx()
745 static unsigned int sc16is7xx_get_hwmctrl(struct uart_port *port) in sc16is7xx_get_hwmctrl() argument
747 u8 msr = sc16is7xx_port_read(port, SC16IS7XX_MSR_REG); in sc16is7xx_get_hwmctrl()
759 struct uart_port *port = &one->port; in sc16is7xx_update_mlines() local
763 lockdep_assert_held_once(&one->efr_lock); in sc16is7xx_update_mlines()
765 status = sc16is7xx_get_hwmctrl(port); in sc16is7xx_update_mlines()
766 changed = status ^ one->old_mctrl; in sc16is7xx_update_mlines()
771 one->old_mctrl = status; in sc16is7xx_update_mlines()
773 uart_port_lock_irqsave(port, &flags); in sc16is7xx_update_mlines()
775 port->icount.rng++; in sc16is7xx_update_mlines()
777 port->icount.dsr++; in sc16is7xx_update_mlines()
779 uart_handle_dcd_change(port, status & TIOCM_CAR); in sc16is7xx_update_mlines()
781 uart_handle_cts_change(port, status & TIOCM_CTS); in sc16is7xx_update_mlines()
783 wake_up_interruptible(&port->state->port.delta_msr_wait); in sc16is7xx_update_mlines()
784 uart_port_unlock_irqrestore(port, flags); in sc16is7xx_update_mlines()
791 struct uart_port *port = &s->p[portno].port; in sc16is7xx_port_irq() local
792 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_port_irq()
794 mutex_lock(&one->efr_lock); in sc16is7xx_port_irq()
796 iir = sc16is7xx_port_read(port, SC16IS7XX_IIR_REG); in sc16is7xx_port_irq()
809 rxlen = sc16is7xx_port_read(port, SC16IS7XX_RXLVL_REG); in sc16is7xx_port_irq()
813 * time-out interrupt but no data in the FIFO. This is in sc16is7xx_port_irq()
823 sc16is7xx_handle_rx(port, rxlen, iir); in sc16is7xx_port_irq()
831 sc16is7xx_handle_tx(port); in sc16is7xx_port_irq()
834 dev_err_ratelimited(port->dev, in sc16is7xx_port_irq()
836 port->line, iir); in sc16is7xx_port_irq()
841 mutex_unlock(&one->efr_lock); in sc16is7xx_port_irq()
857 for (i = 0; i < s->devtype->nr_uart; ++i) in sc16is7xx_irq()
866 struct uart_port *port = &(to_sc16is7xx_one(ws, tx_work)->port); in sc16is7xx_tx_proc() local
867 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_tx_proc()
869 if ((port->rs485.flags & SER_RS485_ENABLED) && in sc16is7xx_tx_proc()
870 (port->rs485.delay_rts_before_send > 0)) in sc16is7xx_tx_proc()
871 msleep(port->rs485.delay_rts_before_send); in sc16is7xx_tx_proc()
873 mutex_lock(&one->efr_lock); in sc16is7xx_tx_proc()
874 sc16is7xx_handle_tx(port); in sc16is7xx_tx_proc()
875 mutex_unlock(&one->efr_lock); in sc16is7xx_tx_proc()
878 static void sc16is7xx_reconf_rs485(struct uart_port *port) in sc16is7xx_reconf_rs485() argument
883 struct serial_rs485 *rs485 = &port->rs485; in sc16is7xx_reconf_rs485()
886 uart_port_lock_irqsave(port, &irqflags); in sc16is7xx_reconf_rs485()
887 if (rs485->flags & SER_RS485_ENABLED) { in sc16is7xx_reconf_rs485()
890 if (rs485->flags & SER_RS485_RTS_AFTER_SEND) in sc16is7xx_reconf_rs485()
893 uart_port_unlock_irqrestore(port, irqflags); in sc16is7xx_reconf_rs485()
895 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, mask, efcr); in sc16is7xx_reconf_rs485()
904 uart_port_lock_irqsave(&one->port, &irqflags); in sc16is7xx_reg_proc()
905 config = one->config; in sc16is7xx_reg_proc()
906 memset(&one->config, 0, sizeof(one->config)); in sc16is7xx_reg_proc()
907 uart_port_unlock_irqrestore(&one->port, irqflags); in sc16is7xx_reg_proc()
913 if (one->port.mctrl & TIOCM_RTS) in sc16is7xx_reg_proc()
916 if (one->port.mctrl & TIOCM_DTR) in sc16is7xx_reg_proc()
919 if (one->port.mctrl & TIOCM_LOOP) in sc16is7xx_reg_proc()
921 sc16is7xx_port_update(&one->port, SC16IS7XX_MCR_REG, in sc16is7xx_reg_proc()
929 sc16is7xx_port_update(&one->port, SC16IS7XX_IER_REG, in sc16is7xx_reg_proc()
933 sc16is7xx_reconf_rs485(&one->port); in sc16is7xx_reg_proc()
939 struct sc16is7xx_port *s = dev_get_drvdata(one->port.dev); in sc16is7xx_ms_proc()
941 if (one->port.state) { in sc16is7xx_ms_proc()
942 mutex_lock(&one->efr_lock); in sc16is7xx_ms_proc()
944 mutex_unlock(&one->efr_lock); in sc16is7xx_ms_proc()
946 kthread_queue_delayed_work(&s->kworker, &one->ms_work, HZ); in sc16is7xx_ms_proc()
950 static void sc16is7xx_enable_ms(struct uart_port *port) in sc16is7xx_enable_ms() argument
952 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_enable_ms()
953 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); in sc16is7xx_enable_ms()
955 lockdep_assert_held_once(&port->lock); in sc16is7xx_enable_ms()
957 kthread_queue_delayed_work(&s->kworker, &one->ms_work, 0); in sc16is7xx_enable_ms()
960 static void sc16is7xx_start_tx(struct uart_port *port) in sc16is7xx_start_tx() argument
962 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); in sc16is7xx_start_tx()
963 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_start_tx()
965 kthread_queue_work(&s->kworker, &one->tx_work); in sc16is7xx_start_tx()
968 static void sc16is7xx_throttle(struct uart_port *port) in sc16is7xx_throttle() argument
975 * AutoRTS feature will de-activate RTS output. in sc16is7xx_throttle()
977 uart_port_lock_irqsave(port, &flags); in sc16is7xx_throttle()
978 sc16is7xx_ier_clear(port, SC16IS7XX_IER_RDI_BIT); in sc16is7xx_throttle()
979 uart_port_unlock_irqrestore(port, flags); in sc16is7xx_throttle()
982 static void sc16is7xx_unthrottle(struct uart_port *port) in sc16is7xx_unthrottle() argument
986 uart_port_lock_irqsave(port, &flags); in sc16is7xx_unthrottle()
987 sc16is7xx_ier_set(port, SC16IS7XX_IER_RDI_BIT); in sc16is7xx_unthrottle()
988 uart_port_unlock_irqrestore(port, flags); in sc16is7xx_unthrottle()
991 static unsigned int sc16is7xx_tx_empty(struct uart_port *port) in sc16is7xx_tx_empty() argument
995 lsr = sc16is7xx_port_read(port, SC16IS7XX_LSR_REG); in sc16is7xx_tx_empty()
1000 static unsigned int sc16is7xx_get_mctrl(struct uart_port *port) in sc16is7xx_get_mctrl() argument
1002 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_get_mctrl()
1004 /* Called with port lock taken so we can only return cached value */ in sc16is7xx_get_mctrl()
1005 return one->old_mctrl; in sc16is7xx_get_mctrl()
1008 static void sc16is7xx_set_mctrl(struct uart_port *port, unsigned int mctrl) in sc16is7xx_set_mctrl() argument
1010 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); in sc16is7xx_set_mctrl()
1011 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_set_mctrl()
1013 one->config.flags |= SC16IS7XX_RECONF_MD; in sc16is7xx_set_mctrl()
1014 kthread_queue_work(&s->kworker, &one->reg_work); in sc16is7xx_set_mctrl()
1017 static void sc16is7xx_break_ctl(struct uart_port *port, int break_state) in sc16is7xx_break_ctl() argument
1019 sc16is7xx_port_update(port, SC16IS7XX_LCR_REG, in sc16is7xx_break_ctl()
1024 static void sc16is7xx_set_termios(struct uart_port *port, in sc16is7xx_set_termios() argument
1028 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_set_termios()
1033 kthread_cancel_delayed_work_sync(&one->ms_work); in sc16is7xx_set_termios()
1036 termios->c_cflag &= ~CMSPAR; in sc16is7xx_set_termios()
1039 switch (termios->c_cflag & CSIZE) { in sc16is7xx_set_termios()
1054 termios->c_cflag &= ~CSIZE; in sc16is7xx_set_termios()
1055 termios->c_cflag |= CS8; in sc16is7xx_set_termios()
1060 if (termios->c_cflag & PARENB) { in sc16is7xx_set_termios()
1062 if (!(termios->c_cflag & PARODD)) in sc16is7xx_set_termios()
1067 if (termios->c_cflag & CSTOPB) in sc16is7xx_set_termios()
1071 port->read_status_mask = SC16IS7XX_LSR_OE_BIT; in sc16is7xx_set_termios()
1072 if (termios->c_iflag & INPCK) in sc16is7xx_set_termios()
1073 port->read_status_mask |= SC16IS7XX_LSR_PE_BIT | in sc16is7xx_set_termios()
1075 if (termios->c_iflag & (BRKINT | PARMRK)) in sc16is7xx_set_termios()
1076 port->read_status_mask |= SC16IS7XX_LSR_BI_BIT; in sc16is7xx_set_termios()
1079 port->ignore_status_mask = 0; in sc16is7xx_set_termios()
1080 if (termios->c_iflag & IGNBRK) in sc16is7xx_set_termios()
1081 port->ignore_status_mask |= SC16IS7XX_LSR_BI_BIT; in sc16is7xx_set_termios()
1082 if (!(termios->c_cflag & CREAD)) in sc16is7xx_set_termios()
1083 port->ignore_status_mask |= SC16IS7XX_LSR_BRK_ERROR_MASK; in sc16is7xx_set_termios()
1086 port->status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS); in sc16is7xx_set_termios()
1087 if (termios->c_cflag & CRTSCTS) { in sc16is7xx_set_termios()
1090 port->status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; in sc16is7xx_set_termios()
1092 if (termios->c_iflag & IXON) in sc16is7xx_set_termios()
1094 if (termios->c_iflag & IXOFF) in sc16is7xx_set_termios()
1098 sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, lcr); in sc16is7xx_set_termios()
1101 sc16is7xx_efr_lock(port); in sc16is7xx_set_termios()
1102 sc16is7xx_port_write(port, SC16IS7XX_XON1_REG, termios->c_cc[VSTART]); in sc16is7xx_set_termios()
1103 sc16is7xx_port_write(port, SC16IS7XX_XOFF1_REG, termios->c_cc[VSTOP]); in sc16is7xx_set_termios()
1104 sc16is7xx_port_update(port, SC16IS7XX_EFR_REG, in sc16is7xx_set_termios()
1106 sc16is7xx_efr_unlock(port); in sc16is7xx_set_termios()
1109 baud = uart_get_baud_rate(port, termios, old, in sc16is7xx_set_termios()
1110 port->uartclk / 16 / 4 / 0xffff, in sc16is7xx_set_termios()
1111 port->uartclk / 16); in sc16is7xx_set_termios()
1114 baud = sc16is7xx_set_baud(port, baud); in sc16is7xx_set_termios()
1116 uart_port_lock_irqsave(port, &flags); in sc16is7xx_set_termios()
1119 uart_update_timeout(port, termios->c_cflag, baud); in sc16is7xx_set_termios()
1121 if (UART_ENABLE_MS(port, termios->c_cflag)) in sc16is7xx_set_termios()
1122 sc16is7xx_enable_ms(port); in sc16is7xx_set_termios()
1124 uart_port_unlock_irqrestore(port, flags); in sc16is7xx_set_termios()
1127 static int sc16is7xx_config_rs485(struct uart_port *port, struct ktermios *termios, in sc16is7xx_config_rs485() argument
1130 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); in sc16is7xx_config_rs485()
1131 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_config_rs485()
1133 if (rs485->flags & SER_RS485_ENABLED) { in sc16is7xx_config_rs485()
1139 if (rs485->delay_rts_after_send) in sc16is7xx_config_rs485()
1140 return -EINVAL; in sc16is7xx_config_rs485()
1143 one->config.flags |= SC16IS7XX_RECONF_RS485; in sc16is7xx_config_rs485()
1144 kthread_queue_work(&s->kworker, &one->reg_work); in sc16is7xx_config_rs485()
1149 static int sc16is7xx_startup(struct uart_port *port) in sc16is7xx_startup() argument
1151 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_startup()
1155 sc16is7xx_power(port, 1); in sc16is7xx_startup()
1159 sc16is7xx_port_write(port, SC16IS7XX_FCR_REG, val); in sc16is7xx_startup()
1161 sc16is7xx_port_write(port, SC16IS7XX_FCR_REG, in sc16is7xx_startup()
1165 sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, in sc16is7xx_startup()
1168 regcache_cache_bypass(one->regmap, true); in sc16is7xx_startup()
1171 sc16is7xx_port_update(port, SC16IS7XX_EFR_REG, in sc16is7xx_startup()
1176 sc16is7xx_port_update(port, SC16IS7XX_MCR_REG, in sc16is7xx_startup()
1181 /* Flow control halt level 48, resume level 24 */ in sc16is7xx_startup()
1182 sc16is7xx_port_write(port, SC16IS7XX_TCR_REG, in sc16is7xx_startup()
1186 regcache_cache_bypass(one->regmap, false); in sc16is7xx_startup()
1189 sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, SC16IS7XX_LCR_WORD_LEN_8); in sc16is7xx_startup()
1193 sc16is7xx_port_update(port, SC16IS7XX_MCR_REG, in sc16is7xx_startup()
1195 one->irda_mode ? in sc16is7xx_startup()
1199 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, in sc16is7xx_startup()
1207 sc16is7xx_port_write(port, SC16IS7XX_IER_REG, val); in sc16is7xx_startup()
1210 uart_port_lock_irqsave(port, &flags); in sc16is7xx_startup()
1211 sc16is7xx_enable_ms(port); in sc16is7xx_startup()
1212 uart_port_unlock_irqrestore(port, flags); in sc16is7xx_startup()
1217 static void sc16is7xx_shutdown(struct uart_port *port) in sc16is7xx_shutdown() argument
1219 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); in sc16is7xx_shutdown()
1220 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); in sc16is7xx_shutdown()
1222 kthread_cancel_delayed_work_sync(&one->ms_work); in sc16is7xx_shutdown()
1225 sc16is7xx_port_write(port, SC16IS7XX_IER_REG, 0); in sc16is7xx_shutdown()
1227 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, in sc16is7xx_shutdown()
1233 sc16is7xx_power(port, 0); in sc16is7xx_shutdown()
1235 kthread_flush_worker(&s->kworker); in sc16is7xx_shutdown()
1238 static const char *sc16is7xx_type(struct uart_port *port) in sc16is7xx_type() argument
1240 struct sc16is7xx_port *s = dev_get_drvdata(port->dev); in sc16is7xx_type()
1242 return (port->type == PORT_SC16IS7XX) ? s->devtype->name : NULL; in sc16is7xx_type()
1245 static int sc16is7xx_request_port(struct uart_port *port) in sc16is7xx_request_port() argument
1251 static void sc16is7xx_config_port(struct uart_port *port, int flags) in sc16is7xx_config_port() argument
1254 port->type = PORT_SC16IS7XX; in sc16is7xx_config_port()
1257 static int sc16is7xx_verify_port(struct uart_port *port, in sc16is7xx_verify_port() argument
1260 if ((s->type != PORT_UNKNOWN) && (s->type != PORT_SC16IS7XX)) in sc16is7xx_verify_port()
1261 return -EINVAL; in sc16is7xx_verify_port()
1262 if (s->irq != port->irq) in sc16is7xx_verify_port()
1263 return -EINVAL; in sc16is7xx_verify_port()
1268 static void sc16is7xx_pm(struct uart_port *port, unsigned int state, in sc16is7xx_pm() argument
1271 sc16is7xx_power(port, (state == UART_PM_STATE_ON) ? 1 : 0); in sc16is7xx_pm()
1274 static void sc16is7xx_null_void(struct uart_port *port) in sc16is7xx_null_void() argument
1306 struct uart_port *port = &s->p[0].port; in sc16is7xx_gpio_get() local
1308 val = sc16is7xx_port_read(port, SC16IS7XX_IOSTATE_REG); in sc16is7xx_gpio_get()
1316 struct uart_port *port = &s->p[0].port; in sc16is7xx_gpio_set() local
1318 sc16is7xx_port_update(port, SC16IS7XX_IOSTATE_REG, BIT(offset), in sc16is7xx_gpio_set()
1326 struct uart_port *port = &s->p[0].port; in sc16is7xx_gpio_direction_input() local
1328 sc16is7xx_port_update(port, SC16IS7XX_IODIR_REG, BIT(offset), 0); in sc16is7xx_gpio_direction_input()
1337 struct uart_port *port = &s->p[0].port; in sc16is7xx_gpio_direction_output() local
1338 u8 state = sc16is7xx_port_read(port, SC16IS7XX_IOSTATE_REG); in sc16is7xx_gpio_direction_output()
1353 sc16is7xx_port_update(port, SC16IS7XX_IODIR_REG, BIT(offset), in sc16is7xx_gpio_direction_output()
1355 sc16is7xx_port_write(port, SC16IS7XX_IOSTATE_REG, state); in sc16is7xx_gpio_direction_output()
1366 *valid_mask = s->gpio_valid_mask; in sc16is7xx_gpio_init_valid_mask()
1373 struct device *dev = s->p[0].port.dev; in sc16is7xx_setup_gpio_chip()
1375 if (!s->devtype->nr_gpio) in sc16is7xx_setup_gpio_chip()
1378 switch (s->mctrl_mask) { in sc16is7xx_setup_gpio_chip()
1380 s->gpio_valid_mask = GENMASK(7, 0); in sc16is7xx_setup_gpio_chip()
1383 s->gpio_valid_mask = GENMASK(3, 0); in sc16is7xx_setup_gpio_chip()
1386 s->gpio_valid_mask = GENMASK(7, 4); in sc16is7xx_setup_gpio_chip()
1392 if (s->gpio_valid_mask == 0) in sc16is7xx_setup_gpio_chip()
1395 s->gpio.owner = THIS_MODULE; in sc16is7xx_setup_gpio_chip()
1396 s->gpio.parent = dev; in sc16is7xx_setup_gpio_chip()
1397 s->gpio.label = dev_name(dev); in sc16is7xx_setup_gpio_chip()
1398 s->gpio.init_valid_mask = sc16is7xx_gpio_init_valid_mask; in sc16is7xx_setup_gpio_chip()
1399 s->gpio.direction_input = sc16is7xx_gpio_direction_input; in sc16is7xx_setup_gpio_chip()
1400 s->gpio.get = sc16is7xx_gpio_get; in sc16is7xx_setup_gpio_chip()
1401 s->gpio.direction_output = sc16is7xx_gpio_direction_output; in sc16is7xx_setup_gpio_chip()
1402 s->gpio.set = sc16is7xx_gpio_set; in sc16is7xx_setup_gpio_chip()
1403 s->gpio.base = -1; in sc16is7xx_setup_gpio_chip()
1404 s->gpio.ngpio = s->devtype->nr_gpio; in sc16is7xx_setup_gpio_chip()
1405 s->gpio.can_sleep = 1; in sc16is7xx_setup_gpio_chip()
1407 return gpiochip_add_data(&s->gpio, s); in sc16is7xx_setup_gpio_chip()
1417 struct device *dev = s->p[0].port.dev; in sc16is7xx_setup_irda_ports()
1419 count = device_property_count_u32(dev, "irda-mode-ports"); in sc16is7xx_setup_irda_ports()
1423 ret = device_property_read_u32_array(dev, "irda-mode-ports", in sc16is7xx_setup_irda_ports()
1429 if (irda_port[i] < s->devtype->nr_uart) in sc16is7xx_setup_irda_ports()
1430 s->p[irda_port[i]].irda_mode = true; in sc16is7xx_setup_irda_ports()
1444 struct device *dev = s->p[0].port.dev; in sc16is7xx_setup_mctrl_ports()
1446 count = device_property_count_u32(dev, "nxp,modem-control-line-ports"); in sc16is7xx_setup_mctrl_ports()
1450 ret = device_property_read_u32_array(dev, "nxp,modem-control-line-ports", in sc16is7xx_setup_mctrl_ports()
1455 s->mctrl_mask = 0; in sc16is7xx_setup_mctrl_ports()
1460 s->mctrl_mask |= SC16IS7XX_IOCONTROL_MODEM_A_BIT; in sc16is7xx_setup_mctrl_ports()
1462 s->mctrl_mask |= SC16IS7XX_IOCONTROL_MODEM_B_BIT; in sc16is7xx_setup_mctrl_ports()
1465 if (s->mctrl_mask) in sc16is7xx_setup_mctrl_ports()
1470 SC16IS7XX_IOCONTROL_MODEM_B_BIT, s->mctrl_mask); in sc16is7xx_setup_mctrl_ports()
1478 .delay_rts_after_send = 1, /* Not supported but keep returning -EINVAL */
1514 for (i = 0; i < devtype->nr_uart; i++) in sc16is7xx_probe()
1529 return -EPROBE_DEFER; in sc16is7xx_probe()
1531 /* Alloc port structure */ in sc16is7xx_probe()
1532 s = devm_kzalloc(dev, struct_size(s, p, devtype->nr_uart), GFP_KERNEL); in sc16is7xx_probe()
1534 dev_err(dev, "Error allocating port structure\n"); in sc16is7xx_probe()
1535 return -ENOMEM; in sc16is7xx_probe()
1539 device_property_read_u32(dev, "clock-frequency", &uartclk); in sc16is7xx_probe()
1541 s->clk = devm_clk_get_optional(dev, NULL); in sc16is7xx_probe()
1542 if (IS_ERR(s->clk)) in sc16is7xx_probe()
1543 return PTR_ERR(s->clk); in sc16is7xx_probe()
1545 ret = clk_prepare_enable(s->clk); in sc16is7xx_probe()
1549 freq = clk_get_rate(s->clk); in sc16is7xx_probe()
1558 return -EINVAL; in sc16is7xx_probe()
1561 s->devtype = devtype; in sc16is7xx_probe()
1564 kthread_init_worker(&s->kworker); in sc16is7xx_probe()
1565 s->kworker_task = kthread_run(kthread_worker_fn, &s->kworker, in sc16is7xx_probe()
1567 if (IS_ERR(s->kworker_task)) { in sc16is7xx_probe()
1568 ret = PTR_ERR(s->kworker_task); in sc16is7xx_probe()
1571 sched_set_fifo(s->kworker_task); in sc16is7xx_probe()
1577 /* Mark each port line and status as uninitialised. */ in sc16is7xx_probe()
1578 for (i = 0; i < devtype->nr_uart; ++i) { in sc16is7xx_probe()
1579 s->p[i].port.line = SC16IS7XX_MAX_DEVS; in sc16is7xx_probe()
1583 for (i = 0; i < devtype->nr_uart; ++i) { in sc16is7xx_probe()
1585 SC16IS7XX_MAX_DEVS - 1, GFP_KERNEL); in sc16is7xx_probe()
1589 s->p[i].port.line = ret; in sc16is7xx_probe()
1591 /* Initialize port data */ in sc16is7xx_probe()
1592 s->p[i].port.dev = dev; in sc16is7xx_probe()
1593 s->p[i].port.irq = irq; in sc16is7xx_probe()
1594 s->p[i].port.type = PORT_SC16IS7XX; in sc16is7xx_probe()
1595 s->p[i].port.fifosize = SC16IS7XX_FIFO_SIZE; in sc16is7xx_probe()
1596 s->p[i].port.flags = UPF_FIXED_TYPE | UPF_LOW_LATENCY; in sc16is7xx_probe()
1597 s->p[i].port.iobase = i; in sc16is7xx_probe()
1603 s->p[i].port.membase = (void __iomem *)~0; in sc16is7xx_probe()
1604 s->p[i].port.iotype = UPIO_PORT; in sc16is7xx_probe()
1605 s->p[i].port.uartclk = freq; in sc16is7xx_probe()
1606 s->p[i].port.rs485_config = sc16is7xx_config_rs485; in sc16is7xx_probe()
1607 s->p[i].port.rs485_supported = sc16is7xx_rs485_supported; in sc16is7xx_probe()
1608 s->p[i].port.ops = &sc16is7xx_ops; in sc16is7xx_probe()
1609 s->p[i].old_mctrl = 0; in sc16is7xx_probe()
1610 s->p[i].regmap = regmaps[i]; in sc16is7xx_probe()
1612 mutex_init(&s->p[i].efr_lock); in sc16is7xx_probe()
1614 ret = uart_get_rs485_mode(&s->p[i].port); in sc16is7xx_probe()
1619 sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_IER_REG, 0); in sc16is7xx_probe()
1621 sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_EFCR_REG, in sc16is7xx_probe()
1626 kthread_init_work(&s->p[i].tx_work, sc16is7xx_tx_proc); in sc16is7xx_probe()
1627 kthread_init_work(&s->p[i].reg_work, sc16is7xx_reg_proc); in sc16is7xx_probe()
1628 kthread_init_delayed_work(&s->p[i].ms_work, sc16is7xx_ms_proc); in sc16is7xx_probe()
1630 /* Register port */ in sc16is7xx_probe()
1631 ret = uart_add_one_port(&sc16is7xx_uart, &s->p[i].port); in sc16is7xx_probe()
1638 sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_LCR_REG, in sc16is7xx_probe()
1644 sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_EFR_REG, in sc16is7xx_probe()
1650 sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_LCR_REG, 0x00); in sc16is7xx_probe()
1653 sc16is7xx_power(&s->p[i].port, 0); in sc16is7xx_probe()
1669 * Setup interrupt. We first try to acquire the IRQ line as level IRQ. in sc16is7xx_probe()
1672 * back to a non-shared falling-edge trigger. in sc16is7xx_probe()
1688 if (s->gpio_valid_mask) in sc16is7xx_probe()
1689 gpiochip_remove(&s->gpio); in sc16is7xx_probe()
1693 for (i = 0; i < devtype->nr_uart; i++) { in sc16is7xx_probe()
1694 if (s->p[i].port.line < SC16IS7XX_MAX_DEVS) in sc16is7xx_probe()
1695 ida_free(&sc16is7xx_lines, s->p[i].port.line); in sc16is7xx_probe()
1697 uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port); in sc16is7xx_probe()
1701 kthread_stop(s->kworker_task); in sc16is7xx_probe()
1704 clk_disable_unprepare(s->clk); in sc16is7xx_probe()
1716 if (s->gpio_valid_mask) in sc16is7xx_remove()
1717 gpiochip_remove(&s->gpio); in sc16is7xx_remove()
1720 for (i = 0; i < s->devtype->nr_uart; i++) { in sc16is7xx_remove()
1721 kthread_cancel_delayed_work_sync(&s->p[i].ms_work); in sc16is7xx_remove()
1722 ida_free(&sc16is7xx_lines, s->p[i].port.line); in sc16is7xx_remove()
1723 uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port); in sc16is7xx_remove()
1724 sc16is7xx_power(&s->p[i].port, 0); in sc16is7xx_remove()
1727 kthread_flush_worker(&s->kworker); in sc16is7xx_remove()
1728 kthread_stop(s->kworker_task); in sc16is7xx_remove()
1730 clk_disable_unprepare(s->clk); in sc16is7xx_remove()