sa1100.c

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

C
958
字号
	sport->port.read_status_mask &= UTSR0_TO_SM(UTSR0_TFS);	sport->port.read_status_mask |= UTSR1_TO_SM(UTSR1_ROR);	if (termios->c_iflag & INPCK)		sport->port.read_status_mask |=				UTSR1_TO_SM(UTSR1_FRE | UTSR1_PRE);	if (termios->c_iflag & (BRKINT | PARMRK))		sport->port.read_status_mask |=				UTSR0_TO_SM(UTSR0_RBB | UTSR0_REB);	/*	 * Characters to ignore	 */	sport->port.ignore_status_mask = 0;	if (termios->c_iflag & IGNPAR)		sport->port.ignore_status_mask |=				UTSR1_TO_SM(UTSR1_FRE | UTSR1_PRE);	if (termios->c_iflag & IGNBRK) {		sport->port.ignore_status_mask |=				UTSR0_TO_SM(UTSR0_RBB | UTSR0_REB);		/*		 * 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 |=				UTSR1_TO_SM(UTSR1_ROR);	}	del_timer_sync(&sport->timer);	/*	 * Update the per-port timeout.	 */	uart_update_timeout(port, termios->c_cflag, baud);	/*	 * disable interrupts and drain transmitter	 */	old_utcr3 = UART_GET_UTCR3(sport);	UART_PUT_UTCR3(sport, old_utcr3 & ~(UTCR3_RIE | UTCR3_TIE));	while (UART_GET_UTSR1(sport) & UTSR1_TBY)		barrier();	/* then, disable everything */	UART_PUT_UTCR3(sport, 0);	/* set the parity, stop bits and data size */	UART_PUT_UTCR0(sport, utcr0);	/* set the baud rate */	quot -= 1;	UART_PUT_UTCR1(sport, ((quot & 0xf00) >> 8));	UART_PUT_UTCR2(sport, (quot & 0xff));	UART_PUT_UTSR0(sport, -1);	UART_PUT_UTCR3(sport, old_utcr3);	if (UART_ENABLE_MS(&sport->port, termios->c_cflag))		sa1100_enable_ms(&sport->port);	spin_unlock_irqrestore(&sport->port.lock, flags);}static const char *sa1100_type(struct uart_port *port){	struct sa1100_port *sport = (struct sa1100_port *)port;	return sport->port.type == PORT_SA1100 ? "SA1100" : NULL;}/* * Release the memory region(s) being used by 'port'. */static void sa1100_release_port(struct uart_port *port){	struct sa1100_port *sport = (struct sa1100_port *)port;	release_mem_region(sport->port.mapbase, UART_PORT_SIZE);}/* * Request the memory region(s) being used by 'port'. */static int sa1100_request_port(struct uart_port *port){	struct sa1100_port *sport = (struct sa1100_port *)port;	return request_mem_region(sport->port.mapbase, UART_PORT_SIZE,			"sa11x0-uart") != NULL ? 0 : -EBUSY;}/* * Configure/autoconfigure the port. */static void sa1100_config_port(struct uart_port *port, int flags){	struct sa1100_port *sport = (struct sa1100_port *)port;	if (flags & UART_CONFIG_TYPE &&	    sa1100_request_port(&sport->port) == 0)		sport->port.type = PORT_SA1100;}/* * Verify the new serial_struct (for TIOCSSERIAL). * The only change we allow are to the flags and type, and * even then only between PORT_SA1100 and PORT_UNKNOWN */static intsa1100_verify_port(struct uart_port *port, struct serial_struct *ser){	struct sa1100_port *sport = (struct sa1100_port *)port;	int ret = 0;	if (ser->type != PORT_UNKNOWN && ser->type != PORT_SA1100)		ret = -EINVAL;	if (sport->port.irq != ser->irq)		ret = -EINVAL;	if (ser->io_type != SERIAL_IO_MEM)		ret = -EINVAL;	if (sport->port.uartclk / 16 != ser->baud_base)		ret = -EINVAL;	if ((void *)sport->port.mapbase != ser->iomem_base)		ret = -EINVAL;	if (sport->port.iobase != ser->port)		ret = -EINVAL;	if (ser->hub6 != 0)		ret = -EINVAL;	return ret;}static struct uart_ops sa1100_pops = {	.tx_empty	= sa1100_tx_empty,	.set_mctrl	= sa1100_set_mctrl,	.get_mctrl	= sa1100_get_mctrl,	.stop_tx	= sa1100_stop_tx,	.start_tx	= sa1100_start_tx,	.stop_rx	= sa1100_stop_rx,	.enable_ms	= sa1100_enable_ms,	.break_ctl	= sa1100_break_ctl,	.startup	= sa1100_startup,	.shutdown	= sa1100_shutdown,	.set_termios	= sa1100_set_termios,	.type		= sa1100_type,	.release_port	= sa1100_release_port,	.request_port	= sa1100_request_port,	.config_port	= sa1100_config_port,	.verify_port	= sa1100_verify_port,};static struct sa1100_port sa1100_ports[NR_PORTS];/* * Setup the SA1100 serial ports.  Note that we don't include the IrDA * port here since we have our own SIR/FIR driver (see drivers/net/irda) * * Note also that we support "console=ttySAx" where "x" is either 0 or 1. * Which serial port this ends up being depends on the machine you're * running this kernel on.  I'm not convinced that this is a good idea, * but that's the way it traditionally works. * * Note that NanoEngine UART3 becomes UART2, and UART2 is no longer * used here. */static void __init sa1100_init_ports(void){	static int first = 1;	int i;	if (!first)		return;	first = 0;	for (i = 0; i < NR_PORTS; i++) {		sa1100_ports[i].port.uartclk   = 3686400;		sa1100_ports[i].port.ops       = &sa1100_pops;		sa1100_ports[i].port.fifosize  = 8;		sa1100_ports[i].port.line      = i;		sa1100_ports[i].port.iotype    = SERIAL_IO_MEM;		init_timer(&sa1100_ports[i].timer);		sa1100_ports[i].timer.function = sa1100_timeout;		sa1100_ports[i].timer.data     = (unsigned long)&sa1100_ports[i];	}	/*	 * make transmit lines outputs, so that when the port	 * is closed, the output is in the MARK state.	 */	PPDR |= PPC_TXD1 | PPC_TXD3;	PPSR |= PPC_TXD1 | PPC_TXD3;}void __init sa1100_register_uart_fns(struct sa1100_port_fns *fns){	if (fns->get_mctrl)		sa1100_pops.get_mctrl = fns->get_mctrl;	if (fns->set_mctrl)		sa1100_pops.set_mctrl = fns->set_mctrl;	sa1100_pops.pm       = fns->pm;	sa1100_pops.set_wake = fns->set_wake;}void __init sa1100_register_uart(int idx, int port){	if (idx >= NR_PORTS) {		printk(KERN_ERR "%s: bad index number %d\n", __FUNCTION__, idx);		return;	}	switch (port) {	case 1:		sa1100_ports[idx].port.membase = (void *)&Ser1UTCR0;		sa1100_ports[idx].port.mapbase = _Ser1UTCR0;		sa1100_ports[idx].port.irq     = IRQ_Ser1UART;		sa1100_ports[idx].port.flags   = ASYNC_BOOT_AUTOCONF;		break;	case 2:		sa1100_ports[idx].port.membase = (void *)&Ser2UTCR0;		sa1100_ports[idx].port.mapbase = _Ser2UTCR0;		sa1100_ports[idx].port.irq     = IRQ_Ser2ICP;		sa1100_ports[idx].port.flags   = ASYNC_BOOT_AUTOCONF;		break;	case 3:		sa1100_ports[idx].port.membase = (void *)&Ser3UTCR0;		sa1100_ports[idx].port.mapbase = _Ser3UTCR0;		sa1100_ports[idx].port.irq     = IRQ_Ser3UART;		sa1100_ports[idx].port.flags   = ASYNC_BOOT_AUTOCONF;		break;	default:		printk(KERN_ERR "%s: bad port number %d\n", __FUNCTION__, port);	}}#ifdef CONFIG_SERIAL_SA1100_CONSOLE/* * Interrupts are disabled on entering */static voidsa1100_console_write(struct console *co, const char *s, unsigned int count){	struct sa1100_port *sport = &sa1100_ports[co->index];	unsigned int old_utcr3, status, i;	/*	 *	First, save UTCR3 and then disable interrupts	 */	old_utcr3 = UART_GET_UTCR3(sport);	UART_PUT_UTCR3(sport, (old_utcr3 & ~(UTCR3_RIE | UTCR3_TIE)) |				UTCR3_TXE);	/*	 *	Now, do each character	 */	for (i = 0; i < count; i++) {		do {			status = UART_GET_UTSR1(sport);		} while (!(status & UTSR1_TNF));		UART_PUT_CHAR(sport, s[i]);		if (s[i] == '\n') {			do {				status = UART_GET_UTSR1(sport);			} while (!(status & UTSR1_TNF));			UART_PUT_CHAR(sport, '\r');		}	}	/*	 *	Finally, wait for transmitter to become empty	 *	and restore UTCR3	 */	do {		status = UART_GET_UTSR1(sport);	} while (status & UTSR1_TBY);	UART_PUT_UTCR3(sport, old_utcr3);}/* * If the port was already initialised (eg, by a boot loader), * try to determine the current setup. */static void __initsa1100_console_get_options(struct sa1100_port *sport, int *baud,			   int *parity, int *bits){	unsigned int utcr3;	utcr3 = UART_GET_UTCR3(sport) & (UTCR3_RXE | UTCR3_TXE);	if (utcr3 == (UTCR3_RXE | UTCR3_TXE)) {		/* ok, the port was enabled */		unsigned int utcr0, quot;		utcr0 = UART_GET_UTCR0(sport);		*parity = 'n';		if (utcr0 & UTCR0_PE) {			if (utcr0 & UTCR0_OES)				*parity = 'e';			else				*parity = 'o';		}		if (utcr0 & UTCR0_DSS)			*bits = 8;		else			*bits = 7;		quot = UART_GET_UTCR2(sport) | UART_GET_UTCR1(sport) << 8;		quot &= 0xfff;		*baud = sport->port.uartclk / (16 * (quot + 1));	}}static int __initsa1100_console_setup(struct console *co, char *options){	struct sa1100_port *sport;	int baud = 9600;	int bits = 8;	int parity = 'n';	int flow = 'n';	/*	 * Check whether an invalid uart number has been specified, and	 * if so, search for the first available port that does have	 * console support.	 */	if (co->index == -1 || co->index >= NR_PORTS)		co->index = 0;	sport = &sa1100_ports[co->index];	if (options)		uart_parse_options(options, &baud, &parity, &bits, &flow);	else		sa1100_console_get_options(sport, &baud, &parity, &bits);	return uart_set_options(&sport->port, co, baud, parity, bits, flow);}extern struct uart_driver sa1100_reg;static struct console sa1100_console = {	.name		= "ttySA",	.write		= sa1100_console_write,	.device		= uart_console_device,	.setup		= sa1100_console_setup,	.flags		= CON_PRINTBUFFER,	.index		= -1,	.data		= &sa1100_reg,};static int __init sa1100_rs_console_init(void){	sa1100_init_ports();	register_console(&sa1100_console);	return 0;}console_initcall(sa1100_rs_console_init);#define SA1100_CONSOLE	&sa1100_console#else#define SA1100_CONSOLE	NULL#endifstatic struct uart_driver sa1100_reg = {	.owner			= THIS_MODULE,	.driver_name		= "ttySA",	.dev_name		= "ttySA",	.devfs_name		= "ttySA",	.major			= SERIAL_SA1100_MAJOR,	.minor			= MINOR_START,	.nr			= NR_PORTS,	.cons			= SA1100_CONSOLE,};static int sa1100_serial_suspend(struct device *_dev, u32 state, u32 level){	struct sa1100_port *sport = dev_get_drvdata(_dev);	if (sport && level == SUSPEND_DISABLE)		uart_suspend_port(&sa1100_reg, &sport->port);	return 0;}static int sa1100_serial_resume(struct device *_dev, u32 level){	struct sa1100_port *sport = dev_get_drvdata(_dev);	if (sport && level == RESUME_ENABLE)		uart_resume_port(&sa1100_reg, &sport->port);	return 0;}static int sa1100_serial_probe(struct device *_dev){	struct platform_device *dev = to_platform_device(_dev);	struct resource *res = dev->resource;	int i;	for (i = 0; i < dev->num_resources; i++, res++)		if (res->flags & IORESOURCE_MEM)			break;	if (i < dev->num_resources) {		for (i = 0; i < NR_PORTS; i++) {			if (sa1100_ports[i].port.mapbase != res->start)				continue;			sa1100_ports[i].port.dev = _dev;			uart_add_one_port(&sa1100_reg, &sa1100_ports[i].port);			dev_set_drvdata(_dev, &sa1100_ports[i]);			break;		}	}	return 0;}static int sa1100_serial_remove(struct device *_dev){	struct sa1100_port *sport = dev_get_drvdata(_dev);	dev_set_drvdata(_dev, NULL);	if (sport)		uart_remove_one_port(&sa1100_reg, &sport->port);	return 0;}static struct device_driver sa11x0_serial_driver = {	.name		= "sa11x0-uart",	.bus		= &platform_bus_type,	.probe		= sa1100_serial_probe,	.remove		= sa1100_serial_remove,	.suspend	= sa1100_serial_suspend,	.resume		= sa1100_serial_resume,};static int __init sa1100_serial_init(void){	int ret;	printk(KERN_INFO "Serial: SA11x0 driver $Revision: 1.50 $\n");	sa1100_init_ports();	ret = uart_register_driver(&sa1100_reg);	if (ret == 0) {		ret = driver_register(&sa11x0_serial_driver);		if (ret)			uart_unregister_driver(&sa1100_reg);	}	return ret;}static void __exit sa1100_serial_exit(void){	driver_unregister(&sa11x0_serial_driver);	uart_unregister_driver(&sa1100_reg);}module_init(sa1100_serial_init);module_exit(sa1100_serial_exit);MODULE_AUTHOR("Deep Blue Solutions Ltd");MODULE_DESCRIPTION("SA1100 generic serial port driver $Revision: 1.50 $");MODULE_LICENSE("GPL");MODULE_ALIAS_CHARDEV_MAJOR(SERIAL_SA1100_MAJOR);

⌨️ 快捷键说明

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