Lines Matching +full:rs485 +full:- +full:rts +full:- +full:active +full:- +full:low

1 // SPDX-License-Identifier: GPL-2.0
9 * associated with the registers and bits of 16550 compatible UARTS -
126 * ------------------------------------------------------------
129 * This routines are called before setting or resetting tty->flow.stopped.
131 * ------------------------------------------------------------
135 struct serial_state *info = tty->driver_data; in rs_stop()
139 if (info->IER & UART_IER_THRI) { in rs_stop()
140 info->IER &= ~UART_IER_THRI; in rs_stop()
152 struct serial_state *info = tty->driver_data; in rs_start()
156 if (info->xmit.head != info->xmit.tail in rs_start()
157 && info->xmit.buf in rs_start()
158 && !(info->IER & UART_IER_THRI)) { in rs_start()
159 info->IER |= UART_IER_THRI; in rs_start()
170 * ----------------------------------------------------------------------
174 * -----------------------------------------------------------------------
185 icount = &info->icount; in receive_chars()
199 icount->rx++; in receive_chars()
207 * We don't handle parity or frame errors - but I have left in receive_chars()
219 icount->brk++; in receive_chars()
221 icount->parity++; in receive_chars()
223 icount->frame++; in receive_chars()
225 icount->overrun++; in receive_chars()
232 if (status & info->ignore_status_mask) in receive_chars()
235 status &= info->read_status_mask; in receive_chars()
242 if (info->tport.flags & ASYNC_SAK) in receive_chars()
243 do_SAK(info->tport.tty); in receive_chars()
257 tty_insert_flip_char(&info->tport, ch, flag); in receive_chars()
259 tty_insert_flip_char(&info->tport, 0, TTY_OVERRUN); in receive_chars()
260 tty_flip_buffer_push(&info->tport); in receive_chars()
269 if (info->x_char) { in transmit_chars()
270 amiga_custom.serdat = info->x_char | 0x100; in transmit_chars()
272 info->icount.tx++; in transmit_chars()
273 info->x_char = 0; in transmit_chars()
276 if (info->xmit.head == info->xmit.tail in transmit_chars()
277 || info->tport.tty->flow.stopped in transmit_chars()
278 || info->tport.tty->hw_stopped) { in transmit_chars()
279 info->IER &= ~UART_IER_THRI; in transmit_chars()
285 amiga_custom.serdat = info->xmit.buf[info->xmit.tail++] | 0x100; in transmit_chars()
287 info->xmit.tail = info->xmit.tail & (UART_XMIT_SIZE - 1); in transmit_chars()
288 info->icount.tx++; in transmit_chars()
290 if (CIRC_CNT(info->xmit.head, in transmit_chars()
291 info->xmit.tail, in transmit_chars()
293 tty_wakeup(info->tport.tty); in transmit_chars()
298 if (info->xmit.head == info->xmit.tail) { in transmit_chars()
301 info->IER &= ~UART_IER_THRI; in transmit_chars()
307 struct tty_port *port = &info->tport; in check_modem_status()
317 icount = &info->icount; in check_modem_status()
320 icount->dsr++; in check_modem_status()
322 icount->dcd++; in check_modem_status()
325 icount->cts++; in check_modem_status()
326 wake_up_interruptible(&port->delta_msr_wait); in check_modem_status()
331 printk("ttyS%d CD now %s...", info->line, in check_modem_status()
335 wake_up_interruptible(&port->open_wait); in check_modem_status()
340 if (port->tty) in check_modem_status()
341 tty_hangup(port->tty); in check_modem_status()
345 if (port->tty->hw_stopped) { in check_modem_status()
350 port->tty->hw_stopped = false; in check_modem_status()
351 info->IER |= UART_IER_THRI; in check_modem_status()
357 tty_wakeup(port->tty); in check_modem_status()
365 port->tty->hw_stopped = true; in check_modem_status()
366 info->IER &= ~UART_IER_THRI; in check_modem_status()
382 * TBD - is it better to unregister from this interrupt or to in ser_vbl_int()
385 if(info->IER & UART_IER_MSI) in ser_vbl_int()
398 if (!info->tport.tty) in ser_rx_int()
417 if (!info->tport.tty) in ser_tx_int()
429 * -------------------------------------------------------------------
431 * -------------------------------------------------------------------
435 * ---------------------------------------------------------------
436 * Low level utility subroutines for the serial driver: routines to
440 * ---------------------------------------------------------------
445 struct tty_port *port = &info->tport; in startup()
452 return -ENOMEM; in startup()
461 if (info->xmit.buf) in startup()
464 info->xmit.buf = (unsigned char *) page; in startup()
467 printk("starting up ttys%d ...", info->line); in startup()
478 set_bit(TTY_IO_ERROR, &tty->flags); in startup()
487 info->IER = UART_IER_MSI; in startup()
492 info->MCR = 0; in startup()
494 info->MCR = SER_DTR | SER_RTS; in startup()
495 rtsdtr_ctrl(info->MCR); in startup()
497 clear_bit(TTY_IO_ERROR, &tty->flags); in startup()
498 info->xmit.head = info->xmit.tail = 0; in startup()
522 if (!tty_port_initialized(&info->tport)) in shutdown()
526 printk("Shutting down serial port %d ....\n", info->line); in shutdown()
535 wake_up_interruptible(&info->tport.delta_msr_wait); in shutdown()
542 free_page((unsigned long)info->xmit.buf); in shutdown()
543 info->xmit.buf = NULL; in shutdown()
545 info->IER = 0; in shutdown()
554 info->MCR &= ~(SER_DTR|SER_RTS); in shutdown()
555 rtsdtr_ctrl(info->MCR); in shutdown()
557 set_bit(TTY_IO_ERROR, &tty->flags); in shutdown()
559 tty_port_set_initialized(&info->tport, false); in shutdown()
571 struct tty_port *port = &info->tport; in change_speed()
577 cflag = tty->termios.c_cflag; in change_speed()
599 baud_base = info->baud_base; in change_speed()
600 if (baud == 38400 && (port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) in change_speed()
601 quot = info->custom_divisor; in change_speed()
612 tty->termios.c_cflag &= ~CBAUD; in change_speed()
613 tty->termios.c_cflag |= (old_termios->c_cflag & CBAUD); in change_speed()
618 (port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) in change_speed()
619 quot = info->custom_divisor; in change_speed()
631 info->quot = quot; in change_speed()
632 info->timeout = (XMIT_FIFO_SIZE*HZ*bits*quot) / baud_base; in change_speed()
633 info->timeout += HZ/50; /* Add .02 seconds of slop */ in change_speed()
636 info->IER &= ~UART_IER_MSI; in change_speed()
637 if (port->flags & ASYNC_HARDPPS_CD) in change_speed()
638 info->IER |= UART_IER_MSI; in change_speed()
641 info->IER |= UART_IER_MSI; in change_speed()
644 info->IER |= UART_IER_MSI; in change_speed()
653 info->read_status_mask = UART_LSR_OE | UART_LSR_DR; in change_speed()
655 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE; in change_speed()
657 info->read_status_mask |= UART_LSR_BI; in change_speed()
662 info->ignore_status_mask = 0; in change_speed()
664 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; in change_speed()
666 info->ignore_status_mask |= UART_LSR_BI; in change_speed()
672 info->ignore_status_mask |= UART_LSR_OE; in change_speed()
678 info->ignore_status_mask |= UART_LSR_DR; in change_speed()
685 serper = quot - 1; in change_speed()
704 info = tty->driver_data; in rs_put_char()
706 if (!info->xmit.buf) in rs_put_char()
710 if (CIRC_SPACE(info->xmit.head, in rs_put_char()
711 info->xmit.tail, in rs_put_char()
717 info->xmit.buf[info->xmit.head++] = ch; in rs_put_char()
718 info->xmit.head &= UART_XMIT_SIZE - 1; in rs_put_char()
725 struct serial_state *info = tty->driver_data; in rs_flush_chars()
728 if (info->xmit.head == info->xmit.tail in rs_flush_chars()
729 || tty->flow.stopped in rs_flush_chars()
730 || tty->hw_stopped in rs_flush_chars()
731 || !info->xmit.buf) in rs_flush_chars()
735 info->IER |= UART_IER_THRI; in rs_flush_chars()
747 struct serial_state *info = tty->driver_data; in rs_write()
750 if (!info->xmit.buf) in rs_write()
755 c = CIRC_SPACE_TO_END(info->xmit.head, in rs_write()
756 info->xmit.tail, in rs_write()
763 memcpy(info->xmit.buf + info->xmit.head, buf, c); in rs_write()
764 info->xmit.head = (info->xmit.head + c) & (UART_XMIT_SIZE - 1); in rs_write()
766 count -= c; in rs_write()
771 if (info->xmit.head != info->xmit.tail in rs_write()
772 && !tty->flow.stopped in rs_write()
773 && !tty->hw_stopped in rs_write()
774 && !(info->IER & UART_IER_THRI)) { in rs_write()
775 info->IER |= UART_IER_THRI; in rs_write()
789 struct serial_state *info = tty->driver_data; in rs_write_room()
791 return CIRC_SPACE(info->xmit.head, info->xmit.tail, UART_XMIT_SIZE); in rs_write_room()
796 struct serial_state *info = tty->driver_data; in rs_chars_in_buffer()
798 return CIRC_CNT(info->xmit.head, info->xmit.tail, UART_XMIT_SIZE); in rs_chars_in_buffer()
803 struct serial_state *info = tty->driver_data; in rs_flush_buffer()
807 info->xmit.head = info->xmit.tail = 0; in rs_flush_buffer()
813 * This function is used to send a high-priority XON/XOFF character to
818 struct serial_state *info = tty->driver_data; in rs_send_xchar()
821 info->x_char = ch; in rs_send_xchar()
836 info->IER |= UART_IER_THRI; in rs_send_xchar()
841 * ------------------------------------------------------------
844 * This routine is called by the upper-layer tty layer to signal that
846 * ------------------------------------------------------------
850 struct serial_state *info = tty->driver_data; in rs_throttle()
860 info->MCR &= ~SER_RTS; in rs_throttle()
863 rtsdtr_ctrl(info->MCR); in rs_throttle()
869 struct serial_state *info = tty->driver_data; in rs_unthrottle()
876 if (info->x_char) in rs_unthrottle()
877 info->x_char = 0; in rs_unthrottle()
882 info->MCR |= SER_RTS; in rs_unthrottle()
884 rtsdtr_ctrl(info->MCR); in rs_unthrottle()
889 * ------------------------------------------------------------
891 * ------------------------------------------------------------
896 struct serial_state *state = tty->driver_data; in get_serial_info()
900 close_delay = jiffies_to_msecs(state->tport.close_delay) / 10; in get_serial_info()
901 closing_wait = state->tport.closing_wait; in get_serial_info()
905 ss->line = tty->index; in get_serial_info()
906 ss->port = state->port; in get_serial_info()
907 ss->flags = state->tport.flags; in get_serial_info()
908 ss->xmit_fifo_size = XMIT_FIFO_SIZE; in get_serial_info()
909 ss->baud_base = state->baud_base; in get_serial_info()
910 ss->close_delay = close_delay; in get_serial_info()
911 ss->closing_wait = closing_wait; in get_serial_info()
912 ss->custom_divisor = state->custom_divisor; in get_serial_info()
919 struct serial_state *state = tty->driver_data; in set_serial_info()
920 struct tty_port *port = &state->tport; in set_serial_info()
926 change_spd = ((ss->flags ^ port->flags) & ASYNC_SPD_MASK) || in set_serial_info()
927 ss->custom_divisor != state->custom_divisor; in set_serial_info()
928 if (ss->irq || ss->port != state->port || in set_serial_info()
929 ss->xmit_fifo_size != XMIT_FIFO_SIZE) { in set_serial_info()
931 return -EINVAL; in set_serial_info()
934 close_delay = msecs_to_jiffies(ss->close_delay * 10); in set_serial_info()
935 closing_wait = ss->closing_wait; in set_serial_info()
940 if ((ss->baud_base != state->baud_base) || in set_serial_info()
941 (close_delay != port->close_delay) || in set_serial_info()
942 (closing_wait != port->closing_wait) || in set_serial_info()
943 ((ss->flags & ~ASYNC_USR_MASK) != in set_serial_info()
944 (port->flags & ~ASYNC_USR_MASK))) { in set_serial_info()
946 return -EPERM; in set_serial_info()
948 port->flags = ((port->flags & ~ASYNC_USR_MASK) | in set_serial_info()
949 (ss->flags & ASYNC_USR_MASK)); in set_serial_info()
950 state->custom_divisor = ss->custom_divisor; in set_serial_info()
954 if (ss->baud_base < 9600) { in set_serial_info()
956 return -EINVAL; in set_serial_info()
964 state->baud_base = ss->baud_base; in set_serial_info()
965 port->flags = ((port->flags & ~ASYNC_FLAGS) | in set_serial_info()
966 (ss->flags & ASYNC_FLAGS)); in set_serial_info()
967 state->custom_divisor = ss->custom_divisor; in set_serial_info()
968 port->close_delay = close_delay; in set_serial_info()
969 port->closing_wait = closing_wait; in set_serial_info()
975 if (ss->flags & ASYNC_SPD_MASK) in set_serial_info()
976 dev_warn_ratelimited(tty->dev, "use of SPD flags is deprecated\n"); in set_serial_info()
986 * get_lsr_info - get line status register info
989 * is emptied. On bus types like RS485, the transmitter must
993 * allows an RS485 driver to be written in user space.
1007 return -EFAULT; in get_lsr_info()
1014 struct serial_state *info = tty->driver_data; in rs_tiocmget()
1019 return -EIO; in rs_tiocmget()
1021 control = info->MCR; in rs_tiocmget()
1035 struct serial_state *info = tty->driver_data; in rs_tiocmset()
1039 return -EIO; in rs_tiocmset()
1043 info->MCR |= SER_RTS; in rs_tiocmset()
1045 info->MCR |= SER_DTR; in rs_tiocmset()
1047 info->MCR &= ~SER_RTS; in rs_tiocmset()
1049 info->MCR &= ~SER_DTR; in rs_tiocmset()
1050 rtsdtr_ctrl(info->MCR); in rs_tiocmset()
1056 * rs_break() --- routine which turns the break handling on or off
1063 if (break_state == -1) in rs_break()
1075 * NB: both 1->0 and 0->1 transitions are counted except for
1076 * RI where only 0->1 is counted.
1081 struct serial_state *info = tty->driver_data; in rs_get_icount()
1086 cnow = info->icount; in rs_get_icount()
1088 icount->cts = cnow.cts; in rs_get_icount()
1089 icount->dsr = cnow.dsr; in rs_get_icount()
1090 icount->rng = cnow.rng; in rs_get_icount()
1091 icount->dcd = cnow.dcd; in rs_get_icount()
1092 icount->rx = cnow.rx; in rs_get_icount()
1093 icount->tx = cnow.tx; in rs_get_icount()
1094 icount->frame = cnow.frame; in rs_get_icount()
1095 icount->overrun = cnow.overrun; in rs_get_icount()
1096 icount->parity = cnow.parity; in rs_get_icount()
1097 icount->brk = cnow.brk; in rs_get_icount()
1098 icount->buf_overrun = cnow.buf_overrun; in rs_get_icount()
1106 struct serial_state *info = tty->driver_data; in rs_ioctl()
1116 return -EIO; in rs_ioctl()
1128 * - mask passed in arg for lines of interest in rs_ioctl()
1135 cprev = info->icount; in rs_ioctl()
1138 prepare_to_wait(&info->tport.delta_msr_wait, in rs_ioctl()
1141 cnow = info->icount; /* atomic copy */ in rs_ioctl()
1145 ret = -EIO; /* no change => error */ in rs_ioctl()
1158 ret = -ERESTARTSYS; in rs_ioctl()
1163 finish_wait(&info->tport.delta_msr_wait, &wait); in rs_ioctl()
1167 return -ENOIOCTLCMD; in rs_ioctl()
1174 struct serial_state *info = tty->driver_data; in rs_set_termios()
1176 unsigned int cflag = tty->termios.c_cflag; in rs_set_termios()
1181 if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) { in rs_set_termios()
1182 info->MCR &= ~(SER_DTR|SER_RTS); in rs_set_termios()
1184 rtsdtr_ctrl(info->MCR); in rs_set_termios()
1189 if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) { in rs_set_termios()
1190 info->MCR |= SER_DTR; in rs_set_termios()
1192 info->MCR |= SER_RTS; in rs_set_termios()
1194 rtsdtr_ctrl(info->MCR); in rs_set_termios()
1199 if ((old_termios->c_cflag & CRTSCTS) && !C_CRTSCTS(tty)) { in rs_set_termios()
1200 tty->hw_stopped = false; in rs_set_termios()
1211 if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty)) in rs_set_termios()
1212 wake_up_interruptible(&info->open_wait); in rs_set_termios()
1217 * ------------------------------------------------------------
1224 * ------------------------------------------------------------
1228 struct serial_state *state = tty->driver_data; in rs_close()
1229 struct tty_port *port = &state->tport; in rs_close()
1240 state->read_status_mask &= ~UART_LSR_DR; in rs_close()
1254 rs_wait_until_sent(tty, state->timeout); in rs_close()
1260 port->tty = NULL; in rs_close()
1266 * rs_wait_until_sent() --- wait until the transmitter is empty
1270 struct serial_state *info = tty->driver_data; in rs_wait_until_sent()
1282 * the NIST-PCTS. in rs_wait_until_sent()
1284 char_time = (info->timeout - HZ/50) / XMIT_FIFO_SIZE; in rs_wait_until_sent()
1295 * takes longer than info->timeout, this is probably due to a in rs_wait_until_sent()
1297 * 2*info->timeout. in rs_wait_until_sent()
1299 if (!timeout || timeout > 2*info->timeout) in rs_wait_until_sent()
1300 timeout = 2*info->timeout; in rs_wait_until_sent()
1323 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1327 struct serial_state *info = tty->driver_data; in rs_hangup()
1331 info->tport.count = 0; in rs_hangup()
1332 tty_port_set_active(&info->tport, false); in rs_hangup()
1333 info->tport.tty = NULL; in rs_hangup()
1334 wake_up_interruptible(&info->tport.open_wait); in rs_hangup()
1340 * the IRQ chain. It also performs the serial-specific
1345 struct tty_port *port = tty->port; in rs_open()
1350 port->count++; in rs_open()
1351 port->tty = tty; in rs_open()
1352 tty->driver_data = info; in rs_open()
1376 control = tty_port_initialized(&state->tport) ? state->MCR : status; in line_info()
1382 strcat(stat_buf, "|RTS"); in line_info()
1392 if (state->quot) in line_info()
1393 seq_printf(m, " baud:%d", state->baud_base / state->quot); in line_info()
1395 seq_printf(m, " tx:%d rx:%d", state->icount.tx, state->icount.rx); in line_info()
1397 if (state->icount.frame) in line_info()
1398 seq_printf(m, " fe:%d", state->icount.frame); in line_info()
1400 if (state->icount.parity) in line_info()
1401 seq_printf(m, " pe:%d", state->icount.parity); in line_info()
1403 if (state->icount.brk) in line_info()
1404 seq_printf(m, " brk:%d", state->icount.brk); in line_info()
1406 if (state->icount.overrun) in line_info()
1407 seq_printf(m, " oe:%d", state->icount.overrun); in line_info()
1410 * Last thing is the RS-232 status lines in line_info()
1423 * ---------------------------------------------------------------------
1426 * rs_init() is called at boot-time to initialize the serial driver.
1427 * ---------------------------------------------------------------------
1462 static void amiga_dtr_rts(struct tty_port *port, bool active) in amiga_dtr_rts() argument
1468 if (active) in amiga_dtr_rts()
1469 info->MCR |= SER_DTR|SER_RTS; in amiga_dtr_rts()
1471 info->MCR &= ~(SER_DTR|SER_RTS); in amiga_dtr_rts()
1474 rtsdtr_ctrl(info->MCR); in amiga_dtr_rts()
1484 * The serial driver boot-time initialization code!
1499 driver->driver_name = "amiserial"; in amiga_serial_probe()
1500 driver->name = "ttyS"; in amiga_serial_probe()
1501 driver->major = TTY_MAJOR; in amiga_serial_probe()
1502 driver->minor_start = 64; in amiga_serial_probe()
1503 driver->type = TTY_DRIVER_TYPE_SERIAL; in amiga_serial_probe()
1504 driver->subtype = SERIAL_TYPE_NORMAL; in amiga_serial_probe()
1505 driver->init_termios = tty_std_termios; in amiga_serial_probe()
1506 driver->init_termios.c_cflag = in amiga_serial_probe()
1511 state->port = (int)&amiga_custom.serdatr; /* Just to give it a value */ in amiga_serial_probe()
1512 tty_port_init(&state->tport); in amiga_serial_probe()
1513 state->tport.ops = &amiga_port_ops; in amiga_serial_probe()
1514 tty_port_link_device(&state->tport, driver, 0); in amiga_serial_probe()
1524 state->baud_base = amiga_colorclock; in amiga_serial_probe()
1550 * and clear RTS and DTR in amiga_serial_probe()
1566 tty_port_destroy(&state->tport); in amiga_serial_probe()
1577 tty_port_destroy(&state->tport); in amiga_serial_remove()
1588 .name = "amiga-serial",
1598 * ------------------------------------------------------------
1600 * ------------------------------------------------------------
1623 while (count--) { in serial_console_write()
1643 .index = -1,
1652 return -ENODEV; in amiserial_console_init()
1662 MODULE_ALIAS("platform:amiga-serial");