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

📄 mcf.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		port->x_char = 0;		port->icount.tx++;		return;	}	while (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY) {		if (xmit->head == xmit->tail)			break;		writeb(xmit->buf[xmit->tail], port->membase + MCFUART_UTB);		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE -1);		port->icount.tx++;	}	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)		uart_write_wakeup(port);	if (xmit->head == xmit->tail) {		pp->imr &= ~MCFUART_UIR_TXREADY;		writeb(pp->imr, port->membase + MCFUART_UIMR);	}}/****************************************************************************/static irqreturn_t mcf_interrupt(int irq, void *data){	struct uart_port *port = data;	struct mcf_uart *pp = (struct mcf_uart *) port;	unsigned int isr;	isr = readb(port->membase + MCFUART_UISR) & pp->imr;	if (isr & MCFUART_UIR_RXREADY)		mcf_rx_chars(pp);	if (isr & MCFUART_UIR_TXREADY)		mcf_tx_chars(pp);	return IRQ_HANDLED;}/****************************************************************************/static void mcf_config_port(struct uart_port *port, int flags){	port->type = PORT_MCF;	/* Clear mask, so no surprise interrupts. */	writeb(0, port->membase + MCFUART_UIMR);	if (request_irq(port->irq, mcf_interrupt, IRQF_DISABLED, "UART", port))		printk(KERN_ERR "MCF: unable to attach ColdFire UART %d "			"interrupt vector=%d\n", port->line, port->irq);}/****************************************************************************/static const char *mcf_type(struct uart_port *port){	return (port->type == PORT_MCF) ? "ColdFire UART" : NULL;}/****************************************************************************/static int mcf_request_port(struct uart_port *port){	/* UARTs always present */	return 0;}/****************************************************************************/static void mcf_release_port(struct uart_port *port){	/* Nothing to release... */}/****************************************************************************/static int mcf_verify_port(struct uart_port *port, struct serial_struct *ser){	if ((ser->type != PORT_UNKNOWN) && (ser->type != PORT_MCF))		return -EINVAL;	return 0;}/****************************************************************************//* *	Define the basic serial functions we support. */static struct uart_ops mcf_uart_ops = {	.tx_empty	= mcf_tx_empty,	.get_mctrl	= mcf_get_mctrl,	.set_mctrl	= mcf_set_mctrl,	.start_tx	= mcf_start_tx,	.stop_tx	= mcf_stop_tx,	.stop_rx	= mcf_stop_rx,	.enable_ms	= mcf_enable_ms,	.break_ctl	= mcf_break_ctl,	.startup	= mcf_startup,	.shutdown	= mcf_shutdown,	.set_termios	= mcf_set_termios,	.type		= mcf_type,	.request_port	= mcf_request_port,	.release_port	= mcf_release_port,	.config_port	= mcf_config_port,	.verify_port	= mcf_verify_port,};static struct mcf_uart mcf_ports[3];#define	MCF_MAXPORTS	(sizeof(mcf_ports) / sizeof(struct mcf_uart))/****************************************************************************/#if defined(CONFIG_SERIAL_MCF_CONSOLE)/****************************************************************************/int __init early_mcf_setup(struct mcf_platform_uart *platp){	struct uart_port *port;	int i;	for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {		port = &mcf_ports[i].port;		port->line = i;		port->type = PORT_MCF;		port->mapbase = platp[i].mapbase;		port->membase = (platp[i].membase) ? platp[i].membase :			(unsigned char __iomem *) port->mapbase;		port->iotype = SERIAL_IO_MEM;		port->irq = platp[i].irq;		port->uartclk = MCF_BUSCLK;		port->flags = ASYNC_BOOT_AUTOCONF;		port->ops = &mcf_uart_ops;	}	return 0;}/****************************************************************************/static void mcf_console_putc(struct console *co, const char c){	struct uart_port *port = &(mcf_ports + co->index)->port;	int i;	for (i = 0; (i < 0x10000); i++) {		if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)			break;	}	writeb(c, port->membase + MCFUART_UTB);	for (i = 0; (i < 0x10000); i++) {		if (readb(port->membase + MCFUART_USR) & MCFUART_USR_TXREADY)			break;	}}/****************************************************************************/static void mcf_console_write(struct console *co, const char *s, unsigned int count){	for (; (count); count--, s++) {		mcf_console_putc(co, *s);		if (*s == '\n')			mcf_console_putc(co, '\r');	}}/****************************************************************************/static int __init mcf_console_setup(struct console *co, char *options){	struct uart_port *port;	int baud = CONFIG_SERIAL_MCF_BAUDRATE;	int bits = 8;	int parity = 'n';	int flow = 'n';	if ((co->index >= 0) && (co->index <= MCF_MAXPORTS))		co->index = 0;	port = &mcf_ports[co->index].port;	if (port->membase == 0)		return -ENODEV;	if (options)		uart_parse_options(options, &baud, &parity, &bits, &flow);	return uart_set_options(port, co, baud, parity, bits, flow);}/****************************************************************************/static struct uart_driver mcf_driver;static struct console mcf_console = {	.name		= "ttyS",	.write		= mcf_console_write,	.device		= uart_console_device,	.setup		= mcf_console_setup,	.flags		= CON_PRINTBUFFER,	.index		= -1,	.data		= &mcf_driver,};static int __init mcf_console_init(void){	register_console(&mcf_console);	return 0;}console_initcall(mcf_console_init);#define	MCF_CONSOLE	&mcf_console/****************************************************************************/#else/****************************************************************************/#define	MCF_CONSOLE	NULL/****************************************************************************/#endif /* CONFIG_MCF_CONSOLE *//****************************************************************************//* *	Define the mcf UART driver structure. */static struct uart_driver mcf_driver = {	.owner		= THIS_MODULE,	.driver_name	= "mcf",	.dev_name	= "ttyS",	.major		= TTY_MAJOR,	.minor		= 64,	.nr		= MCF_MAXPORTS,	.cons		= MCF_CONSOLE,};/****************************************************************************/static int __devinit mcf_probe(struct platform_device *pdev){	struct mcf_platform_uart *platp = pdev->dev.platform_data;	struct uart_port *port;	int i;	for (i = 0; ((i < MCF_MAXPORTS) && (platp[i].mapbase)); i++) {		port = &mcf_ports[i].port;		port->line = i;		port->type = PORT_MCF;		port->mapbase = platp[i].mapbase;		port->membase = (platp[i].membase) ? platp[i].membase :			(unsigned char __iomem *) platp[i].mapbase;		port->iotype = SERIAL_IO_MEM;		port->irq = platp[i].irq;		port->uartclk = MCF_BUSCLK;		port->ops = &mcf_uart_ops;		port->flags = ASYNC_BOOT_AUTOCONF;		uart_add_one_port(&mcf_driver, port);	}	return 0;}/****************************************************************************/static int mcf_remove(struct platform_device *pdev){	struct uart_port *port;	int i;	for (i = 0; (i < MCF_MAXPORTS); i++) {		port = &mcf_ports[i].port;		if (port)			uart_remove_one_port(&mcf_driver, port);	}	return 0;}/****************************************************************************/static struct platform_driver mcf_platform_driver = {	.probe		= mcf_probe,	.remove		= __devexit_p(mcf_remove),	.driver		= {		.name	= "mcfuart",		.owner	= THIS_MODULE,	},};/****************************************************************************/static int __init mcf_init(void){	int rc;	printk("ColdFire internal UART serial driver\n");	rc = uart_register_driver(&mcf_driver);	if (rc)		return rc;	rc = platform_driver_register(&mcf_platform_driver);	if (rc)		return rc;	return 0;}/****************************************************************************/static void __exit mcf_exit(void){	platform_driver_unregister(&mcf_platform_driver);	uart_unregister_driver(&mcf_driver);}/****************************************************************************/module_init(mcf_init);module_exit(mcf_exit);MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");MODULE_DESCRIPTION("Freescale ColdFire UART driver");MODULE_LICENSE("GPL");/****************************************************************************/

⌨️ 快捷键说明

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