sunsu.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,741 行 · 第 1/3 页

C
1,741
字号
	spin_unlock_irqrestore(&up->port.lock, flags);	ret = 0;	if (status & UART_MSR_DCD)		ret |= TIOCM_CAR;	if (status & UART_MSR_RI)		ret |= TIOCM_RNG;	if (status & UART_MSR_DSR)		ret |= TIOCM_DSR;	if (status & UART_MSR_CTS)		ret |= TIOCM_CTS;	return ret;}static void sunsu_set_mctrl(struct uart_port *port, unsigned int mctrl){	struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;	unsigned char mcr = 0;	if (mctrl & TIOCM_RTS)		mcr |= UART_MCR_RTS;	if (mctrl & TIOCM_DTR)		mcr |= UART_MCR_DTR;	if (mctrl & TIOCM_OUT1)		mcr |= UART_MCR_OUT1;	if (mctrl & TIOCM_OUT2)		mcr |= UART_MCR_OUT2;	if (mctrl & TIOCM_LOOP)		mcr |= UART_MCR_LOOP;	serial_out(up, UART_MCR, mcr);}static void sunsu_break_ctl(struct uart_port *port, int break_state){	struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;	unsigned long flags;	spin_lock_irqsave(&up->port.lock, flags);	if (break_state == -1)		up->lcr |= UART_LCR_SBC;	else		up->lcr &= ~UART_LCR_SBC;	serial_out(up, UART_LCR, up->lcr);	spin_unlock_irqrestore(&up->port.lock, flags);}static int sunsu_startup(struct uart_port *port){	struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;	unsigned long flags;	int retval;	if (up->port.type == PORT_16C950) {		/* Wake up and initialize UART */		up->acr = 0;		serial_outp(up, UART_LCR, 0xBF);		serial_outp(up, UART_EFR, UART_EFR_ECB);		serial_outp(up, UART_IER, 0);		serial_outp(up, UART_LCR, 0);		serial_icr_write(up, UART_CSR, 0); /* Reset the UART */		serial_outp(up, UART_LCR, 0xBF);		serial_outp(up, UART_EFR, UART_EFR_ECB);		serial_outp(up, UART_LCR, 0);	}#ifdef CONFIG_SERIAL_8250_RSA	/*	 * If this is an RSA port, see if we can kick it up to the	 * higher speed clock.	 */	enable_rsa(up);#endif	/*	 * Clear the FIFO buffers and disable them.	 * (they will be reeanbled in set_termios())	 */	if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) {		serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);		serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |				UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);		serial_outp(up, UART_FCR, 0);	}	/*	 * Clear the interrupt registers.	 */	(void) serial_inp(up, UART_LSR);	(void) serial_inp(up, UART_RX);	(void) serial_inp(up, UART_IIR);	(void) serial_inp(up, UART_MSR);	/*	 * At this point, there's no way the LSR could still be 0xff;	 * if it is, then bail out, because there's likely no UART	 * here.	 */	if (!(up->port.flags & ASYNC_BUGGY_UART) &&	    (serial_inp(up, UART_LSR) == 0xff)) {		printk("ttyS%d: LSR safety check engaged!\n", up->port.line);		return -ENODEV;	}	if (up->su_type != SU_PORT_PORT) {		retval = request_irq(up->irq, sunsu_kbd_ms_interrupt,				     SA_SHIRQ, su_typev[up->su_type], up);	} else {		retval = request_irq(up->irq, sunsu_serial_interrupt,				     SA_SHIRQ, su_typev[up->su_type], up);	}	if (retval) {		printk("su: Cannot register IRQ %d\n", up->irq);		return retval;	}	/*	 * Now, initialize the UART	 */	serial_outp(up, UART_LCR, UART_LCR_WLEN8);	spin_lock_irqsave(&up->port.lock, flags);	up->port.mctrl |= TIOCM_OUT2;	sunsu_set_mctrl(&up->port, up->port.mctrl);	spin_unlock_irqrestore(&up->port.lock, flags);	/*	 * Finally, enable interrupts.  Note: Modem status interrupts	 * are set via set_termios(), which will be occurring imminently	 * anyway, so we don't enable them here.	 */	up->ier = UART_IER_RLSI | UART_IER_RDI;	serial_outp(up, UART_IER, up->ier);	if (up->port.flags & ASYNC_FOURPORT) {		unsigned int icp;		/*		 * Enable interrupts on the AST Fourport board		 */		icp = (up->port.iobase & 0xfe0) | 0x01f;		outb_p(0x80, icp);		(void) inb_p(icp);	}	/*	 * And clear the interrupt registers again for luck.	 */	(void) serial_inp(up, UART_LSR);	(void) serial_inp(up, UART_RX);	(void) serial_inp(up, UART_IIR);	(void) serial_inp(up, UART_MSR);	return 0;}static void sunsu_shutdown(struct uart_port *port){	struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;	unsigned long flags;	/*	 * Disable interrupts from this port	 */	up->ier = 0;	serial_outp(up, UART_IER, 0);	spin_lock_irqsave(&up->port.lock, flags);	if (up->port.flags & ASYNC_FOURPORT) {		/* reset interrupts on the AST Fourport board */		inb((up->port.iobase & 0xfe0) | 0x1f);		up->port.mctrl |= TIOCM_OUT1;	} else		up->port.mctrl &= ~TIOCM_OUT2;	sunsu_set_mctrl(&up->port, up->port.mctrl);	spin_unlock_irqrestore(&up->port.lock, flags);	/*	 * Disable break condition and FIFOs	 */	serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);	serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |				  UART_FCR_CLEAR_RCVR |				  UART_FCR_CLEAR_XMIT);	serial_outp(up, UART_FCR, 0);#ifdef CONFIG_SERIAL_8250_RSA	/*	 * Reset the RSA board back to 115kbps compat mode.	 */	disable_rsa(up);#endif	/*	 * Read data port to reset things.	 */	(void) serial_in(up, UART_RX);	free_irq(up->irq, up);}static voidsunsu_change_speed(struct uart_port *port, unsigned int cflag,		   unsigned int iflag, unsigned int quot){	struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;	unsigned char cval, fcr = 0;	unsigned long flags;	switch (cflag & CSIZE) {	case CS5:		cval = 0x00;		break;	case CS6:		cval = 0x01;		break;	case CS7:		cval = 0x02;		break;	default:	case CS8:		cval = 0x03;		break;	}	if (cflag & CSTOPB)		cval |= 0x04;	if (cflag & PARENB)		cval |= UART_LCR_PARITY;	if (!(cflag & PARODD))		cval |= UART_LCR_EPAR;#ifdef CMSPAR	if (cflag & CMSPAR)		cval |= UART_LCR_SPAR;#endif	/*	 * Work around a bug in the Oxford Semiconductor 952 rev B	 * chip which causes it to seriously miscalculate baud rates	 * when DLL is 0.	 */	if ((quot & 0xff) == 0 && up->port.type == PORT_16C950 &&	    up->rev == 0x5201)		quot ++;	if (uart_config[up->port.type].flags & UART_USE_FIFO) {		if ((up->port.uartclk / quot) < (2400 * 16))			fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;#ifdef CONFIG_SERIAL_8250_RSA		else if (up->port.type == PORT_RSA)			fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_14;#endif		else			fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;	}	if (up->port.type == PORT_16750)		fcr |= UART_FCR7_64BYTE;	/*	 * Ok, we're now changing the port state.  Do it with	 * interrupts disabled.	 */	spin_lock_irqsave(&up->port.lock, flags);	/*	 * Update the per-port timeout.	 */	uart_update_timeout(port, cflag, (port->uartclk / (16 * quot)));	up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;	if (iflag & INPCK)		up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;	if (iflag & (BRKINT | PARMRK))		up->port.read_status_mask |= UART_LSR_BI;	/*	 * Characteres to ignore	 */	up->port.ignore_status_mask = 0;	if (iflag & IGNPAR)		up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;	if (iflag & IGNBRK) {		up->port.ignore_status_mask |= UART_LSR_BI;		/*		 * If we're ignoring parity and break indicators,		 * ignore overruns too (for real raw support).		 */		if (iflag & IGNPAR)			up->port.ignore_status_mask |= UART_LSR_OE;	}	/*	 * ignore all characters if CREAD is not set	 */	if ((cflag & CREAD) == 0)		up->port.ignore_status_mask |= UART_LSR_DR;	/*	 * CTS flow control flag and modem status interrupts	 */	up->ier &= ~UART_IER_MSI;	if (UART_ENABLE_MS(&up->port, cflag))		up->ier |= UART_IER_MSI;	serial_out(up, UART_IER, up->ier);	if (uart_config[up->port.type].flags & UART_STARTECH) {		serial_outp(up, UART_LCR, 0xBF);		serial_outp(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0);	}	serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */	serial_outp(up, UART_DLL, quot & 0xff);		/* LS of divisor */	serial_outp(up, UART_DLM, quot >> 8);		/* MS of divisor */	if (up->port.type == PORT_16750)		serial_outp(up, UART_FCR, fcr);		/* set fcr */	serial_outp(up, UART_LCR, cval);		/* reset DLAB */	up->lcr = cval;					/* Save LCR */	if (up->port.type != PORT_16750) {		if (fcr & UART_FCR_ENABLE_FIFO) {			/* emulated UARTs (Lucent Venus 167x) need two steps */			serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);		}		serial_outp(up, UART_FCR, fcr);		/* set fcr */	}	up->cflag = cflag;	spin_unlock_irqrestore(&up->port.lock, flags);}static voidsunsu_set_termios(struct uart_port *port, struct termios *termios,		  struct termios *old){	unsigned int baud, quot;	/*	 * 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);	sunsu_change_speed(port, termios->c_cflag, termios->c_iflag, quot);}static void sunsu_release_port(struct uart_port *port){}static int sunsu_request_port(struct uart_port *port){	return 0;}static void sunsu_config_port(struct uart_port *port, int flags){	struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;	if (flags & UART_CONFIG_TYPE) {		/*		 * We are supposed to call autoconfig here, but this requires		 * splitting all the OBP probing crap from the UART probing.		 * We'll do it when we kill sunsu.c altogether.		 */		port->type = up->type_probed;	/* XXX */	}}static intsunsu_verify_port(struct uart_port *port, struct serial_struct *ser){	return -EINVAL;}static const char *sunsu_type(struct uart_port *port){	int type = port->type;	if (type >= ARRAY_SIZE(uart_config))		type = 0;	return uart_config[type].name;}static struct uart_ops sunsu_pops = {	.tx_empty	= sunsu_tx_empty,	.set_mctrl	= sunsu_set_mctrl,	.get_mctrl	= sunsu_get_mctrl,	.stop_tx	= sunsu_stop_tx,	.start_tx	= sunsu_start_tx,	.stop_rx	= sunsu_stop_rx,	.enable_ms	= sunsu_enable_ms,	.break_ctl	= sunsu_break_ctl,	.startup	= sunsu_startup,	.shutdown	= sunsu_shutdown,	.set_termios	= sunsu_set_termios,	.type		= sunsu_type,	.release_port	= sunsu_release_port,	.request_port	= sunsu_request_port,	.config_port	= sunsu_config_port,	.verify_port	= sunsu_verify_port,};#define UART_NR	4static struct uart_sunsu_port sunsu_ports[UART_NR];#ifdef CONFIG_SERIOstatic spinlock_t sunsu_serio_lock = SPIN_LOCK_UNLOCKED;static int sunsu_serio_write(struct serio *serio, unsigned char ch){	struct uart_sunsu_port *up = serio->port_data;	unsigned long flags;	int lsr;	spin_lock_irqsave(&sunsu_serio_lock, flags);	do {		lsr = serial_in(up, UART_LSR);	} while (!(lsr & UART_LSR_THRE));	/* Send the character out. */	serial_out(up, UART_TX, ch);	spin_unlock_irqrestore(&sunsu_serio_lock, flags);	return 0;}static int sunsu_serio_open(struct serio *serio){	struct uart_sunsu_port *up = serio->port_data;	unsigned long flags;	int ret;	spin_lock_irqsave(&sunsu_serio_lock, flags);	if (!up->serio_open) {		up->serio_open = 1;		ret = 0;	} else		ret = -EBUSY;	spin_unlock_irqrestore(&sunsu_serio_lock, flags);	return ret;}static void sunsu_serio_close(struct serio *serio){	struct uart_sunsu_port *up = serio->port_data;	unsigned long flags;	spin_lock_irqsave(&sunsu_serio_lock, flags);	up->serio_open = 0;	spin_unlock_irqrestore(&sunsu_serio_lock, flags);}#endif /* CONFIG_SERIO */static void sunsu_autoconfig(struct uart_sunsu_port *up){	unsigned char status1, status2, scratch, scratch2, scratch3;	unsigned char save_lcr, save_mcr;	struct linux_ebus_device *dev = NULL;	struct linux_ebus *ebus;#ifdef CONFIG_SPARC64	struct sparc_isa_bridge *isa_br;	struct sparc_isa_device *isa_dev;#endif#ifndef CONFIG_SPARC64	struct linux_prom_registers reg0;#endif	unsigned long flags;	if (!up->port_node || !up->su_type)		return;	up->type_probed = PORT_UNKNOWN;	up->port.iotype = SERIAL_IO_MEM;	/*	 * First we look for Ebus-bases su's	 */	for_each_ebus(ebus) {		for_each_ebusdev(dev, ebus) {			if (dev->prom_node == up->port_node) {				/*				 * The EBus is broken on sparc; it delivers				 * virtual addresses in resources. Oh well...				 * This is correct on sparc64, though.				 */				up->port.membase = (char *) dev->resource[0].start;				/*				 * This is correct on both architectures.				 */				up->port.mapbase = dev->resource[0].start;				up->irq = dev->irqs[0];				goto ebus_done;			}		}	}#ifdef CONFIG_SPARC64	for_each_isa(isa_br) {		for_each_isadev(isa_dev, isa_br) {			if (isa_dev->prom_node == up->port_node) {				/* Same on sparc64. Cool architecure... */				up->port.membase = (char *) isa_dev->resource.start;				up->port.mapbase = isa_dev->resource.start;				up->irq = isa_dev->irq;				goto ebus_done;			}		}	}#endif#ifdef CONFIG_SPARC64	/*	 * Not on Ebus, bailing.	 */	return;#else	/*	 * Not on Ebus, must be OBIO.	 */	if (prom_getproperty(up->port_node, "reg",			     (char *)&reg0, sizeof(reg0)) == -1) {		prom_printf("sunsu: no \"reg\" property\n");		return;	}	prom_apply_obio_ranges(&reg0, 1);	if (reg0.which_io != 0) {	/* Just in case... */		prom_printf("sunsu: bus number nonzero: 0x%x:%x\n",		    reg0.which_io, reg0.phys_addr);		return;	}	up->port.mapbase = reg0.phys_addr;	if ((up->port.membase = ioremap(reg0.phys_addr, reg0.reg_size)) == 0) {		prom_printf("sunsu: Cannot map registers.\n");		return;	}	/*	 * 0x20 is sun4m thing, Dave Redman heritage.	 * See arch/sparc/kernel/irq.c.	 */#define IRQ_4M(n)	((n)|0x20)	/*	 * There is no intr property on MrCoffee, so hardwire it.	 */	up->irq = IRQ_4M(13);#endifebus_done:	spin_lock_irqsave(&up->port.lock, flags);	if (!(up->port.flags & ASYNC_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.		 */		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

⌨️ 快捷键说明

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