⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8250.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 4 页
字号:
		serial_outp(up, UART_LCR, 0xE0);		status2 = serial_in(up, 0x02); /* EXCR1 */		serial_outp(up, UART_LCR, 0);		serial_outp(up, UART_MCR, status1);		if ((status2 ^ status1) & UART_MCR_LOOP) {#ifndef CONFIG_PPC			serial_outp(up, UART_LCR, 0xE0);			status1 = serial_in(up, 0x04); /* EXCR1 */			status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */			status1 |= 0x10;  /* 1.625 divisor for baud_base --> 921600 */			serial_outp(up, 0x04, status1);			serial_outp(up, UART_LCR, 0);			up->port.uartclk = 921600*16;#endif			up->port.type = PORT_NS16550A;			return;		}	}	/*	 * No EFR.  Try to detect a TI16750, which only sets bit 5 of	 * the IIR when 64 byte FIFO mode is enabled when DLAB is set.	 * Try setting it with and without DLAB set.  Cheap clones	 * set bit 5 without DLAB set.	 */	serial_outp(up, UART_LCR, 0);	serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);	status1 = serial_in(up, UART_IIR) >> 5;	serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);	serial_outp(up, UART_LCR, UART_LCR_DLAB);	serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);	status2 = serial_in(up, UART_IIR) >> 5;	serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);	DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);	if (status1 == 6 && status2 == 7) {		up->port.type = PORT_16750;		return;	}}/* * This routine is called by rs_init() to initialize a specific serial * port.  It determines what type of UART chip this serial port is * using: 8250, 16450, 16550, 16550A.  The important question is * whether or not this UART is a 16550A or not, since this will * determine whether or not we can use its FIFO features or not. */static void autoconfig(struct uart_8250_port *up, unsigned int probeflags){	unsigned char status1, scratch, scratch2, scratch3;	unsigned char save_lcr, save_mcr;	unsigned long flags;	if (!up->port.iobase && !up->port.mapbase && !up->port.membase)		return;	DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ",			up->port.line, up->port.iobase, up->port.membase);	/*	 * We really do need global IRQs disabled here - we're going to	 * be frobbing the chips IRQ enable register to see if it exists.	 */	spin_lock_irqsave(&up->port.lock, flags);//	save_flags(flags); cli();	if (!(up->port.flags & UPF_BUGGY_UART)) {		/*		 * Do a simple existence test first; if we fail this,		 * there's no point trying anything else.		 * 		 * 0x80 is used as a nonsense port to prevent against		 * false positives due to ISA bus float.  The		 * assumption is that 0x80 is a non-existent port;		 * which should be safe since include/asm/io.h also		 * makes this assumption.		 *		 * Note: this is safe as long as MCR bit 4 is clear		 * and the device is in "PC" mode.		 */		scratch = serial_inp(up, UART_IER);		serial_outp(up, UART_IER, 0);#ifdef __i386__		outb(0xff, 0x080);#endif		scratch2 = serial_inp(up, UART_IER);		serial_outp(up, UART_IER, 0x0F);#ifdef __i386__		outb(0, 0x080);#endif		scratch3 = serial_inp(up, UART_IER);		serial_outp(up, UART_IER, scratch);		if (scratch2 != 0 || scratch3 != 0x0F) {			/*			 * We failed; there's nothing here			 */			DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",				       scratch2, scratch3);			goto out;		}	}	save_mcr = serial_in(up, UART_MCR);	save_lcr = serial_in(up, UART_LCR);	/* 	 * Check to see if a UART is really there.  Certain broken	 * internal modems based on the Rockwell chipset fail this	 * test, because they apparently don't implement the loopback	 * test mode.  So this test is skipped on the COM 1 through	 * COM 4 ports.  This *should* be safe, since no board	 * manufacturer would be stupid enough to design a board	 * that conflicts with COM 1-4 --- we hope!	 */	if (!(up->port.flags & UPF_SKIP_TEST)) {		serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);		status1 = serial_inp(up, UART_MSR) & 0xF0;		serial_outp(up, UART_MCR, save_mcr);		if (status1 != 0x90) {			DEBUG_AUTOCONF("LOOP test failed (%02x) ",				       status1);			goto out;		}	}	/*	 * We're pretty sure there's a port here.  Lets find out what	 * type of port it is.  The IIR top two bits allows us to find	 * out if its 8250 or 16450, 16550, 16550A or later.  This	 * determines what we test for next.	 *	 * We also initialise the EFR (if any) to zero for later.  The	 * EFR occupies the same register location as the FCR and IIR.	 */	serial_outp(up, UART_LCR, 0xBF);	serial_outp(up, UART_EFR, 0);	serial_outp(up, UART_LCR, 0);	serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);	scratch = serial_in(up, UART_IIR) >> 6;	DEBUG_AUTOCONF("iir=%d ", scratch);	switch (scratch) {	case 0:		autoconfig_8250(up);		break;	case 1:		up->port.type = PORT_UNKNOWN;		break;	case 2:		up->port.type = PORT_16550;		break;	case 3:		autoconfig_16550a(up);		break;	}#ifdef CONFIG_SERIAL_8250_RSA	/*	 * Only probe for RSA ports if we got the region.	 */	if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) {		int i;		for (i = 0 ; i < probe_rsa_count; ++i) {			if (probe_rsa[i] == up->port.iobase &&			    __enable_rsa(up)) {				up->port.type = PORT_RSA;				break;			}		}	}#endif	serial_outp(up, UART_LCR, save_lcr);	up->port.fifosize = uart_config[up->port.type].fifo_size;	up->capabilities = uart_config[up->port.type].flags;	up->tx_loadsz = uart_config[up->port.type].tx_loadsz;	if (up->port.type == PORT_UNKNOWN)		goto out;	/*	 * Reset the UART.	 */#ifdef CONFIG_SERIAL_8250_RSA	if (up->port.type == PORT_RSA)		serial_outp(up, UART_RSA_FRR, 0);#endif	serial_outp(up, UART_MCR, save_mcr);	serial8250_clear_fifos(up);	(void)serial_in(up, UART_RX);	serial_outp(up, UART_IER, 0); out:		spin_unlock_irqrestore(&up->port.lock, flags);//	restore_flags(flags);	DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name);}static void autoconfig_irq(struct uart_8250_port *up){	unsigned char save_mcr, save_ier;	unsigned char save_ICP = 0;	unsigned int ICP = 0;	unsigned long irqs;	int irq;	if (up->port.flags & UPF_FOURPORT) {		ICP = (up->port.iobase & 0xfe0) | 0x1f;		save_ICP = inb_p(ICP);		outb_p(0x80, ICP);		(void) inb_p(ICP);	}	/* forget possible initially masked and pending IRQ */	probe_irq_off(probe_irq_on());	save_mcr = serial_inp(up, UART_MCR);	save_ier = serial_inp(up, UART_IER);	serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);		irqs = probe_irq_on();	serial_outp(up, UART_MCR, 0);	udelay (10);	if (up->port.flags & UPF_FOURPORT)  {		serial_outp(up, UART_MCR,			    UART_MCR_DTR | UART_MCR_RTS);	} else {		serial_outp(up, UART_MCR,			    UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);	}	serial_outp(up, UART_IER, 0x0f);	/* enable all intrs */	(void)serial_inp(up, UART_LSR);	(void)serial_inp(up, UART_RX);	(void)serial_inp(up, UART_IIR);	(void)serial_inp(up, UART_MSR);	serial_outp(up, UART_TX, 0xFF);	udelay (20);	irq = probe_irq_off(irqs);	serial_outp(up, UART_MCR, save_mcr);	serial_outp(up, UART_IER, save_ier);	if (up->port.flags & UPF_FOURPORT)		outb_p(save_ICP, ICP);	up->port.irq = (irq > 0) ? irq : 0;}static void serial8250_stop_tx(struct uart_port *port, unsigned int tty_stop){	struct uart_8250_port *up = (struct uart_8250_port *)port;	if (up->ier & UART_IER_THRI) {		up->ier &= ~UART_IER_THRI;		serial_out(up, UART_IER, up->ier);	}	if (up->port.type == PORT_16C950 && tty_stop) {		up->acr |= UART_ACR_TXDIS;		serial_icr_write(up, UART_ACR, up->acr);	}}static void serial8250_start_tx(struct uart_port *port, unsigned int tty_start){	struct uart_8250_port *up = (struct uart_8250_port *)port;	if (!(up->ier & UART_IER_THRI)) {		up->ier |= UART_IER_THRI;		serial_out(up, UART_IER, up->ier);	}	/*	 * We only do this from uart_start	 */	if (tty_start && up->port.type == PORT_16C950) {		up->acr &= ~UART_ACR_TXDIS;		serial_icr_write(up, UART_ACR, up->acr);	}}static void serial8250_stop_rx(struct uart_port *port){	struct uart_8250_port *up = (struct uart_8250_port *)port;	up->ier &= ~UART_IER_RLSI;	up->port.read_status_mask &= ~UART_LSR_DR;	serial_out(up, UART_IER, up->ier);}static void serial8250_enable_ms(struct uart_port *port){	struct uart_8250_port *up = (struct uart_8250_port *)port;	up->ier |= UART_IER_MSI;	serial_out(up, UART_IER, up->ier);}static _INLINE_ voidreceive_chars(struct uart_8250_port *up, int *status, struct pt_regs *regs){	struct tty_struct *tty = up->port.info->tty;	unsigned char ch;	int max_count = 256;	do {		if (unlikely(tty->flip.count >= TTY_FLIPBUF_SIZE)) {			tty->flip.work.func((void *)tty);			if (tty->flip.count >= TTY_FLIPBUF_SIZE)				return; // if TTY_DONT_FLIP is set		}		ch = serial_inp(up, UART_RX);		*tty->flip.char_buf_ptr = ch;		*tty->flip.flag_buf_ptr = TTY_NORMAL;		up->port.icount.rx++;		if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |				       UART_LSR_FE | UART_LSR_OE))) {			/*			 * For statistics only			 */			if (*status & UART_LSR_BI) {				*status &= ~(UART_LSR_FE | UART_LSR_PE);				up->port.icount.brk++;				/*				 * We do the SysRQ and SAK checking				 * here because otherwise the break				 * may get masked by ignore_status_mask				 * or read_status_mask.				 */				if (uart_handle_break(&up->port))					goto ignore_char;			} else if (*status & UART_LSR_PE)				up->port.icount.parity++;			else if (*status & UART_LSR_FE)				up->port.icount.frame++;			if (*status & UART_LSR_OE)				up->port.icount.overrun++;			/*			 * Mask off conditions which should be ingored.			 */			*status &= up->port.read_status_mask;#ifdef CONFIG_SERIAL_8250_CONSOLE			if (up->port.line == up->port.cons->index) {				/* Recover the break flag from console xmit */				*status |= up->lsr_break_flag;				up->lsr_break_flag = 0;			}#endif			if (*status & UART_LSR_BI) {				DEBUG_INTR("handling break....");				*tty->flip.flag_buf_ptr = TTY_BREAK;			} else if (*status & UART_LSR_PE)				*tty->flip.flag_buf_ptr = TTY_PARITY;			else if (*status & UART_LSR_FE)				*tty->flip.flag_buf_ptr = TTY_FRAME;		}		if (uart_handle_sysrq_char(&up->port, ch, regs))			goto ignore_char;		if ((*status & up->port.ignore_status_mask) == 0) {			tty->flip.flag_buf_ptr++;			tty->flip.char_buf_ptr++;			tty->flip.count++;		}		if ((*status & UART_LSR_OE) &&		    tty->flip.count < TTY_FLIPBUF_SIZE) {			/*			 * Overrun is special, since it's reported			 * immediately, and doesn't affect the current			 * character.			 */			*tty->flip.flag_buf_ptr = TTY_OVERRUN;			tty->flip.flag_buf_ptr++;			tty->flip.char_buf_ptr++;			tty->flip.count++;		}	ignore_char:		*status = serial_inp(up, UART_LSR);	} while ((*status & UART_LSR_DR) && (max_count-- > 0));	tty_flip_buffer_push(tty);}static _INLINE_ void transmit_chars(struct uart_8250_port *up){	struct circ_buf *xmit = &up->port.info->xmit;	int count;	if (up->port.x_char) {		serial_outp(up, UART_TX, up->port.x_char);		up->port.icount.tx++;		up->port.x_char = 0;		return;	}	if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {		serial8250_stop_tx(&up->port, 0);		return;	}	count = up->tx_loadsz;	do {		serial_out(up, UART_TX, xmit->buf[xmit->tail]);		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);		up->port.icount.tx++;		if (uart_circ_empty(xmit))			break;	} while (--count > 0);	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)		uart_write_wakeup(&up->port);	DEBUG_INTR("THRE...");	if (uart_circ_empty(xmit))		serial8250_stop_tx(&up->port, 0);}static _INLINE_ void check_modem_status(struct uart_8250_port *up){	int status;	status = serial_in(up, UART_MSR);	if ((status & UART_MSR_ANY_DELTA) == 0)		return;	if (status & UART_MSR_TERI)		up->port.icount.rng++;	if (status & UART_MSR_DDSR)		up->port.icount.dsr++;	if (status & UART_MSR_DDCD)		uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);	if (status & UART_MSR_DCTS)		uart_handle_cts_change(&up->port, status & UART_MSR_CTS);	wake_up_interruptible(&up->port.info->delta_msr_wait);}/* * This handles the interrupt from one port. */static inline voidserial8250_handle_port(struct uart_8250_port *up, struct pt_regs *regs){	unsigned int status = serial_inp(up, UART_LSR);	DEBUG_INTR("status = %x...", status);	if (status & UART_LSR_DR)		receive_chars(up, &status, regs);	check_modem_status(up);	if (status & UART_LSR_THRE)		transmit_chars(up);}/* * This is the serial driver's interrupt routine. * * Arjan thinks the old way was overly complex, so it got simplified. * Alan disagrees, saying that need the complexity to handle the weird * nature of ISA shared interrupts.  (This is a special exception.) * * In order to handle ISA shared interrupts properly, we need to check * that all ports have been serviced, and therefore the ISA interrupt * line has been de-asserted. * * This means we need to loop through all ports. checking that they * don't have an interrupt pending. */static irqreturn_t serial8250_interrupt(int irq, void *dev_id, struct pt_regs *regs){	struct irq_info *i = dev_id;	struct list_head *l, *end = NULL;	int pass_counter = 0;	DEBUG_INTR("serial8250_interrupt(%d)...", irq);	spin_lock(&i->lock);	l = i->head;	do {		struct uart_8250_port *up;		unsigned int iir;		up = list_entry(l, struct uart_8250_port, list);		iir = serial_in(up, UART_IIR);		if (!(iir & UART_IIR_NO_INT)) {			spin_lock(&up->port.lock);			serial8250_handle_port(up, regs);			spin_unlock(&up->port.lock);			end = NULL;		} else if (end == NULL)			end = l;		l = l->next;		if (l == i->head && pass_counter++ > PASS_LIMIT) {			/* If we hit this, we're dead. */			printk(KERN_ERR "serial8250: too much work for "				"irq%d\n", irq);			break;		}	} while (l != end);	spin_unlock(&i->lock);	DEBUG_INTR("end.\n");	/* FIXME! Was it really ours? */	return IRQ_HANDLED;}/* * To support ISA shared interrupts, we need to have one interrupt * handler that ensures that the IRQ line has been deasserted * before returning.  Failing to do this will result in the IRQ * line being stuck active, and, since ISA irqs are edge triggered, * no more IRQs will be seen. */static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up){	spin_lock_irq(&i->lock);	if (!list_empty(i->head)) {		if (i->head == &up->list)			i->head = i->head->next;		list_del(&up->list);	} else {		BUG_ON(i->head != &up->list);		i->head = NULL;	}	spin_unlock_irq(&i->lock);}static int serial_link_irq_chain(struct uart_8250_port *up){	struct irq_info *i = irq_lists + up->port.irq;	int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? SA_SHIRQ : 0;	spin_lock_irq(&i->lock);	if (i->head) {		list_add(&up->list, i->head);		spin_unlock_irq(&i->lock);		ret = 0;	} else {		INIT_LIST_HEAD(&up->list);		i->head = &up->list;		spin_unlock_irq(&i->lock);		ret = request_irq(up->port.irq, serial8250_interrupt,				  irq_flags, "serial", i);		if (ret < 0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -