static void pnx8xxx_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) { struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; unsigned long flags; unsigned int lcr_fcr, old_ien, baud, quot; unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; while ((termios->c_cflag & CSIZE) != CS7 && (termios->c_cflag & CSIZE) != CS8) { termios->c_cflag &= ~CSIZE; termios->c_cflag |= old_csize; old_csize = CS8; } if ((termios->c_cflag & CSIZE) == CS8) lcr_fcr = PNX8XXX_UART_LCR_8BIT; else lcr_fcr = 0; if (termios->c_cflag & CSTOPB) lcr_fcr |= PNX8XXX_UART_LCR_2STOPB; if (termios->c_cflag & PARENB) { lcr_fcr |= PNX8XXX_UART_LCR_PAREN; if (!(termios->c_cflag & PARODD)) lcr_fcr |= PNX8XXX_UART_LCR_PAREVN; } baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); quot = uart_get_divisor(port, baud); spin_lock_irqsave(&sport->port.lock, flags); sport->port.read_status_mask = ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN) | ISTAT_TO_SM(PNX8XXX_UART_INT_EMPTY) | ISTAT_TO_SM(PNX8XXX_UART_INT_RX); if (termios->c_iflag & INPCK) sport->port.read_status_mask |= FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) | FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR); if (termios->c_iflag & (BRKINT | PARMRK)) sport->port.read_status_mask |= ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK); sport->port.ignore_status_mask = 0; if (termios->c_iflag & IGNPAR) sport->port.ignore_status_mask |= FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) | FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR); if (termios->c_iflag & IGNBRK) { sport->port.ignore_status_mask |= ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK); if (termios->c_iflag & IGNPAR) sport->port.ignore_status_mask |= ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN); } if ((termios->c_cflag & CREAD) == 0) sport->port.ignore_status_mask |= ISTAT_TO_SM(PNX8XXX_UART_INT_RX); del_timer_sync(&sport->timer); uart_update_timeout(port, termios->c_cflag, baud); old_ien = serial_in(sport, PNX8XXX_IEN); serial_out(sport, PNX8XXX_IEN, old_ien & ~(PNX8XXX_UART_INT_ALLTX | PNX8XXX_UART_INT_ALLRX)); while (serial_in(sport, PNX8XXX_FIFO) & PNX8XXX_UART_FIFO_TXFIFO_STA) barrier(); serial_out(sport, PNX8XXX_IEN, 0); lcr_fcr |= PNX8XXX_UART_LCR_TX_RST; lcr_fcr |= PNX8XXX_UART_LCR_RX_RST; serial_out(sport, PNX8XXX_LCR, lcr_fcr); quot -= 1; serial_out(sport, PNX8XXX_BAUD, quot); serial_out(sport, PNX8XXX_ICLR, -1); serial_out(sport, PNX8XXX_IEN, old_ien); if (UART_ENABLE_MS(&sport->port, termios->c_cflag)) pnx8xxx_enable_ms(&sport->port); spin_unlock_irqrestore(&sport->port.lock, flags); }
static void ip3106_rx_chars(struct ip3106_port *sport, struct pt_regs *regs) { struct tty_struct *tty = sport->port.info->tty; unsigned int status, ch, flg, ignored = 0; status = FIFO_TO_SM(serial_in(sport, IP3106_FIFO)) | ISTAT_TO_SM(serial_in(sport, IP3106_ISTAT)); while (status & FIFO_TO_SM(IP3106_UART_FIFO_RXFIFO)) { ch = serial_in(sport, IP3106_FIFO); if (tty->flip.count >= TTY_FLIPBUF_SIZE) goto ignore_char; sport->port.icount.rx++; flg = TTY_NORMAL; /* * note that the error handling code is * out of the main execution path */ if (status & FIFO_TO_SM(IP3106_UART_FIFO_RXFE | IP3106_UART_FIFO_RXPAR)) goto handle_error; if (uart_handle_sysrq_char(&sport->port, ch, regs)) goto ignore_char; error_return: tty_insert_flip_char(tty, ch, flg); ignore_char: serial_out(sport, IP3106_LCR, serial_in(sport, IP3106_LCR) | IP3106_UART_LCR_RX_NEXT); status = FIFO_TO_SM(serial_in(sport, IP3106_FIFO)) | ISTAT_TO_SM(serial_in(sport, IP3106_ISTAT)); } out: tty_flip_buffer_push(tty); return; handle_error: if (status & FIFO_TO_SM(IP3106_UART_FIFO_RXPAR)) sport->port.icount.parity++; else if (status & FIFO_TO_SM(IP3106_UART_FIFO_RXFE)) sport->port.icount.frame++; if (status & ISTAT_TO_SM(IP3106_UART_INT_RXOVRN)) sport->port.icount.overrun++; if (status & sport->port.ignore_status_mask) { if (++ignored > 100) goto out; goto ignore_char; } // status &= sport->port.read_status_mask; if (status & FIFO_TO_SM(IP3106_UART_FIFO_RXPAR)) flg = TTY_PARITY; else if (status & FIFO_TO_SM(IP3106_UART_FIFO_RXFE)) flg = TTY_FRAME; if (status & ISTAT_TO_SM(IP3106_UART_INT_RXOVRN)) { /* * overrun does *not* affect the character * we read from the FIFO */ tty_insert_flip_char(tty, ch, flg); ch = 0; flg = TTY_OVERRUN; } #ifdef SUPPORT_SYSRQ sport->port.sysrq = 0; #endif goto error_return; }
static void pnx8xxx_rx_chars(struct pnx8xxx_port *sport) { struct tty_struct *tty = sport->port.state->port.tty; unsigned int status, ch, flg; status = FIFO_TO_SM(serial_in(sport, PNX8XXX_FIFO)) | ISTAT_TO_SM(serial_in(sport, PNX8XXX_ISTAT)); while (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFIFO)) { ch = serial_in(sport, PNX8XXX_FIFO) & 0xff; sport->port.icount.rx++; flg = TTY_NORMAL; if (status & (FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE | PNX8XXX_UART_FIFO_RXPAR | PNX8XXX_UART_FIFO_RXBRK) | ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN))) { if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXBRK)) { status &= ~(FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) | FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR)); sport->port.icount.brk++; if (uart_handle_break(&sport->port)) goto ignore_char; } else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR)) sport->port.icount.parity++; else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE)) sport->port.icount.frame++; if (status & ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN)) sport->port.icount.overrun++; status &= sport->port.read_status_mask; if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR)) flg = TTY_PARITY; else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE)) flg = TTY_FRAME; #ifdef SUPPORT_SYSRQ sport->port.sysrq = 0; #endif } if (uart_handle_sysrq_char(&sport->port, ch)) goto ignore_char; uart_insert_char(&sport->port, status, ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN), ch, flg); ignore_char: serial_out(sport, PNX8XXX_LCR, serial_in(sport, PNX8XXX_LCR) | PNX8XXX_UART_LCR_RX_NEXT); status = FIFO_TO_SM(serial_in(sport, PNX8XXX_FIFO)) | ISTAT_TO_SM(serial_in(sport, PNX8XXX_ISTAT)); } tty_flip_buffer_push(tty); }
static void pnx8xxx_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) { struct pnx8xxx_port *sport = (struct pnx8xxx_port *)port; unsigned long flags; unsigned int lcr_fcr, old_ien, baud, quot; unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; /* * We only support CS7 and CS8. */ while ((termios->c_cflag & CSIZE) != CS7 && (termios->c_cflag & CSIZE) != CS8) { termios->c_cflag &= ~CSIZE; termios->c_cflag |= old_csize; old_csize = CS8; } if ((termios->c_cflag & CSIZE) == CS8) lcr_fcr = PNX8XXX_UART_LCR_8BIT; else lcr_fcr = 0; if (termios->c_cflag & CSTOPB) lcr_fcr |= PNX8XXX_UART_LCR_2STOPB; if (termios->c_cflag & PARENB) { lcr_fcr |= PNX8XXX_UART_LCR_PAREN; if (!(termios->c_cflag & PARODD)) lcr_fcr |= PNX8XXX_UART_LCR_PAREVN; } /* * Ask the core to calculate the divisor for us. */ baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); quot = uart_get_divisor(port, baud); spin_lock_irqsave(&sport->port.lock, flags); sport->port.read_status_mask = ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN) | ISTAT_TO_SM(PNX8XXX_UART_INT_EMPTY) | ISTAT_TO_SM(PNX8XXX_UART_INT_RX); if (termios->c_iflag & INPCK) sport->port.read_status_mask |= FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) | FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR); if (termios->c_iflag & (BRKINT | PARMRK)) sport->port.read_status_mask |= ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK); /* * Characters to ignore */ sport->port.ignore_status_mask = 0; if (termios->c_iflag & IGNPAR) sport->port.ignore_status_mask |= FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE) | FIFO_TO_SM(PNX8XXX_UART_FIFO_RXPAR); if (termios->c_iflag & IGNBRK) { sport->port.ignore_status_mask |= ISTAT_TO_SM(PNX8XXX_UART_INT_BREAK); /* * If we're ignoring parity and break indicators, * ignore overruns too (for real raw support). */ if (termios->c_iflag & IGNPAR) sport->port.ignore_status_mask |= ISTAT_TO_SM(PNX8XXX_UART_INT_RXOVRN); } /* * ignore all characters if CREAD is not set */ if ((termios->c_cflag & CREAD) == 0) sport->port.ignore_status_mask |= ISTAT_TO_SM(PNX8XXX_UART_INT_RX); del_timer_sync(&sport->timer); /* * Update the per-port timeout. */ uart_update_timeout(port, termios->c_cflag, baud); /* * disable interrupts and drain transmitter */ old_ien = serial_in(sport, PNX8XXX_IEN); serial_out(sport, PNX8XXX_IEN, old_ien & ~(PNX8XXX_UART_INT_ALLTX | PNX8XXX_UART_INT_ALLRX)); while (serial_in(sport, PNX8XXX_FIFO) & PNX8XXX_UART_FIFO_TXFIFO_STA) barrier(); /* then, disable everything */ serial_out(sport, PNX8XXX_IEN, 0); /* Reset the Rx and Tx FIFOs too */ lcr_fcr |= PNX8XXX_UART_LCR_TX_RST; lcr_fcr |= PNX8XXX_UART_LCR_RX_RST; /* set the parity, stop bits and data size */ serial_out(sport, PNX8XXX_LCR, lcr_fcr); /* set the baud rate */ quot -= 1; serial_out(sport, PNX8XXX_BAUD, quot); serial_out(sport, PNX8XXX_ICLR, -1); serial_out(sport, PNX8XXX_IEN, old_ien); if (UART_ENABLE_MS(&sport->port, termios->c_cflag)) pnx8xxx_enable_ms(&sport->port); spin_unlock_irqrestore(&sport->port.lock, flags); }