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

📄 vme_scc.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * drivers/char/vme_scc.c: MVME147, MVME162, BVME6000 SCC serial ports * implementation. * Copyright 1999 Richard Hirst <richard@sleepie.demon.co.uk> * * Based on atari_SCC.c which was *   Copyright 1994-95 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> *   Partially based on PC-Linux serial.c by Linus Torvalds and Theodore Ts'o * * This file is subject to the terms and conditions of the GNU General Public * License.  See the file COPYING in the main directory of this archive * for more details. * */#include <linux/module.h>#include <linux/config.h>#include <linux/kdev_t.h>#include <asm/io.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/ioport.h>#include <linux/interrupt.h>#include <linux/errno.h>#include <linux/tty.h>#include <linux/tty_flip.h>#include <linux/mm.h>#include <linux/serial.h>#include <linux/fcntl.h>#include <linux/major.h>#include <linux/delay.h>#include <linux/tqueue.h>#include <linux/version.h>#include <linux/malloc.h>#include <linux/miscdevice.h>#include <linux/console.h>#include <linux/init.h>#include <asm/setup.h>#include <asm/bootinfo.h>#ifdef CONFIG_MVME147_SCC#include <asm/mvme147hw.h>#endif#ifdef CONFIG_MVME162_SCC#include <asm/mvme16xhw.h>#endif#ifdef CONFIG_BVME6000_SCC#include <asm/bvme6000hw.h>#endif#include <linux/generic_serial.h>#include "scc.h"#define CHANNEL_A	0#define CHANNEL_B	1#define SCC_MINOR_BASE	64/* Shadows for all SCC write registers */static unsigned char scc_shadow[2][16];/* Location to access for SCC register access delay */static volatile unsigned char *scc_del = NULL;/* To keep track of STATUS_REG state for detection of Ext/Status int source */static unsigned char scc_last_status_reg[2];/***************************** Prototypes *****************************//* Function prototypes */static void scc_disable_tx_interrupts(void * ptr);static void scc_enable_tx_interrupts(void * ptr);static void scc_disable_rx_interrupts(void * ptr);static void scc_enable_rx_interrupts(void * ptr);static int  scc_get_CD(void * ptr);static void scc_shutdown_port(void * ptr);static int scc_set_real_termios(void  *ptr);static void scc_hungup(void  *ptr);static void scc_close(void  *ptr);static int scc_chars_in_buffer(void * ptr);static int scc_open(struct tty_struct * tty, struct file * filp);static int scc_ioctl(struct tty_struct * tty, struct file * filp,                     unsigned int cmd, unsigned long arg);static void scc_throttle(struct tty_struct *tty);static void scc_unthrottle(struct tty_struct *tty);static void scc_tx_int(int irq, void *data, struct pt_regs *fp);static void scc_rx_int(int irq, void *data, struct pt_regs *fp);static void scc_stat_int(int irq, void *data, struct pt_regs *fp);static void scc_spcond_int(int irq, void *data, struct pt_regs *fp);static void scc_setsignals(struct scc_port *port, int dtr, int rts);static void scc_break_ctl(struct tty_struct *tty, int break_state);static struct tty_driver scc_driver, scc_callout_driver;static struct tty_struct *scc_table[2] = { NULL, };static struct termios * scc_termios[2];static struct termios * scc_termios_locked[2];struct scc_port scc_ports[2];int scc_refcount;int scc_initialized = 0;/*--------------------------------------------------------------------------- * Interface from generic_serial.c back here *--------------------------------------------------------------------------*/static struct real_driver scc_real_driver = {        scc_disable_tx_interrupts,        scc_enable_tx_interrupts,        scc_disable_rx_interrupts,        scc_enable_rx_interrupts,        scc_get_CD,        scc_shutdown_port,        scc_set_real_termios,        scc_chars_in_buffer,        scc_close,        scc_hungup,        NULL};/*---------------------------------------------------------------------------- * vme_scc_init() and support functions *---------------------------------------------------------------------------*/static int scc_init_drivers(void){	int error;	memset(&scc_driver, 0, sizeof(scc_driver));	scc_driver.magic = TTY_DRIVER_MAGIC;	scc_driver.driver_name = "scc";	scc_driver.name = "ttyS";	scc_driver.major = TTY_MAJOR;	scc_driver.minor_start = SCC_MINOR_BASE;	scc_driver.num = 2;	scc_driver.type = TTY_DRIVER_TYPE_SERIAL;	scc_driver.subtype = SERIAL_TYPE_NORMAL;	scc_driver.init_termios = tty_std_termios;	scc_driver.init_termios.c_cflag =	  B9600 | CS8 | CREAD | HUPCL | CLOCAL;	scc_driver.flags = TTY_DRIVER_REAL_RAW;	scc_driver.refcount = &scc_refcount;	scc_driver.table = scc_table;	scc_driver.termios = scc_termios;	scc_driver.termios_locked = scc_termios_locked;	scc_driver.open	= scc_open;	scc_driver.close = gs_close;	scc_driver.write = gs_write;	scc_driver.put_char = gs_put_char;	scc_driver.flush_chars = gs_flush_chars;	scc_driver.write_room = gs_write_room;	scc_driver.chars_in_buffer = gs_chars_in_buffer;	scc_driver.flush_buffer = gs_flush_buffer;	scc_driver.ioctl = scc_ioctl;	scc_driver.throttle = scc_throttle;	scc_driver.unthrottle = scc_unthrottle;	scc_driver.set_termios = gs_set_termios;	scc_driver.stop = gs_stop;	scc_driver.start = gs_start;	scc_driver.hangup = gs_hangup;	scc_driver.break_ctl = scc_break_ctl;	scc_callout_driver = scc_driver;	scc_callout_driver.name = "cua";	scc_callout_driver.major = TTYAUX_MAJOR;	scc_callout_driver.subtype = SERIAL_TYPE_CALLOUT;	if ((error = tty_register_driver(&scc_driver))) {		printk(KERN_ERR "scc: Couldn't register scc driver, error = %d\n",		       error);		return 1;	}	if ((error = tty_register_driver(&scc_callout_driver))) {		tty_unregister_driver(&scc_driver);		printk(KERN_ERR "scc: Couldn't register scc callout driver, error = %d\n",		       error);		return 1;	}	return 0;}/* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1). */static void scc_init_portstructs(void){	struct scc_port *port;	int i;	for (i = 0; i < 2; i++) {		port = scc_ports + i;		port->gs.callout_termios = tty_std_termios;		port->gs.normal_termios = tty_std_termios;		port->gs.magic = SCC_MAGIC;		port->gs.close_delay = HZ/2;		port->gs.closing_wait = 30 * HZ;		port->gs.rd = &scc_real_driver;#ifdef NEW_WRITE_LOCKING		port->gs.port_write_sem = MUTEX;#endif		init_waitqueue_head(&port->gs.open_wait);		init_waitqueue_head(&port->gs.close_wait);	}}#ifdef CONFIG_MVME147_SCCstatic int mvme147_scc_init(void){	struct scc_port *port;	printk("SCC: MVME147 Serial Driver\n");	/* Init channel A */	port = &scc_ports[0];	port->channel = CHANNEL_A;	port->ctrlp = (volatile unsigned char *)M147_SCC_A_ADDR;	port->datap = port->ctrlp + 1;	port->port_a = &scc_ports[0];	port->port_b = &scc_ports[1];	request_irq(MVME147_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,		            "SCC-A TX", port);	request_irq(MVME147_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,		            "SCC-A status", port);	request_irq(MVME147_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,		            "SCC-A RX", port);	request_irq(MVME147_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,		            "SCC-A special cond", port);	{		SCC_ACCESS_INIT(port);		/* disable interrupts for this channel */		SCCwrite(INT_AND_DMA_REG, 0);		/* Set the interrupt vector */		SCCwrite(INT_VECTOR_REG, MVME147_IRQ_SCC_BASE);		/* Interrupt parameters: vector includes status, status low */		SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);		SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);	}	/* Init channel B */	port = &scc_ports[1];	port->channel = CHANNEL_B;	port->ctrlp = (volatile unsigned char *)M147_SCC_B_ADDR;	port->datap = port->ctrlp + 1;	port->port_a = &scc_ports[0];	port->port_b = &scc_ports[1];	request_irq(MVME147_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,		            "SCC-B TX", port);	request_irq(MVME147_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,		            "SCC-B status", port);	request_irq(MVME147_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,		            "SCC-B RX", port);	request_irq(MVME147_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,		            "SCC-B special cond", port);	{		SCC_ACCESS_INIT(port);		/* disable interrupts for this channel */		SCCwrite(INT_AND_DMA_REG, 0);	}        /* Ensure interrupts are enabled in the PCC chip */        m147_pcc->serial_cntrl=PCC_LEVEL_SERIAL|PCC_INT_ENAB;	/* Initialise the tty driver structures and register */	scc_init_portstructs();	scc_init_drivers();	return 0;}#endif#ifdef CONFIG_MVME162_SCCstatic int mvme162_scc_init(void){	struct scc_port *port;	if (!(mvme16x_config & MVME16x_CONFIG_GOT_SCCA))		return (-ENODEV);	printk("SCC: MVME162 Serial Driver\n");	/* Init channel A */	port = &scc_ports[0];	port->channel = CHANNEL_A;	port->ctrlp = (volatile unsigned char *)MVME_SCC_A_ADDR;	port->datap = port->ctrlp + 2;	port->port_a = &scc_ports[0];	port->port_b = &scc_ports[1];	request_irq(MVME162_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,		            "SCC-A TX", port);	request_irq(MVME162_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,		            "SCC-A status", port);	request_irq(MVME162_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,		            "SCC-A RX", port);	request_irq(MVME162_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,		            "SCC-A special cond", port);	{		SCC_ACCESS_INIT(port);		/* disable interrupts for this channel */		SCCwrite(INT_AND_DMA_REG, 0);		/* Set the interrupt vector */		SCCwrite(INT_VECTOR_REG, MVME162_IRQ_SCC_BASE);		/* Interrupt parameters: vector includes status, status low */		SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);		SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);	}	/* Init channel B */	port = &scc_ports[1];	port->channel = CHANNEL_B;	port->ctrlp = (volatile unsigned char *)MVME_SCC_B_ADDR;	port->datap = port->ctrlp + 2;	port->port_a = &scc_ports[0];	port->port_b = &scc_ports[1];	request_irq(MVME162_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,		            "SCC-B TX", port);	request_irq(MVME162_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,		            "SCC-B status", port);	request_irq(MVME162_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,		            "SCC-B RX", port);	request_irq(MVME162_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,		            "SCC-B special cond", port);	{		SCC_ACCESS_INIT(port);	/* Either channel will do */		/* disable interrupts for this channel */		SCCwrite(INT_AND_DMA_REG, 0);	}        /* Ensure interrupts are enabled in the MC2 chip */        *(volatile char *)0xfff4201d = 0x14;	/* Initialise the tty driver structures and register */	scc_init_portstructs();	scc_init_drivers();	return 0;}#endif#ifdef CONFIG_BVME6000_SCCstatic int bvme6000_scc_init(void){	struct scc_port *port;	printk("SCC: BVME6000 Serial Driver\n");	/* Init channel A */	port = &scc_ports[0];	port->channel = CHANNEL_A;	port->ctrlp = (volatile unsigned char *)BVME_SCC_A_ADDR;	port->datap = port->ctrlp + 4;	port->port_a = &scc_ports[0];	port->port_b = &scc_ports[1];	request_irq(BVME_IRQ_SCCA_TX, scc_tx_int, SA_INTERRUPT,		            "SCC-A TX", port);	request_irq(BVME_IRQ_SCCA_STAT, scc_stat_int, SA_INTERRUPT,		            "SCC-A status", port);	request_irq(BVME_IRQ_SCCA_RX, scc_rx_int, SA_INTERRUPT,		            "SCC-A RX", port);	request_irq(BVME_IRQ_SCCA_SPCOND, scc_spcond_int, SA_INTERRUPT,		            "SCC-A special cond", port);	{		SCC_ACCESS_INIT(port);		/* disable interrupts for this channel */		SCCwrite(INT_AND_DMA_REG, 0);		/* Set the interrupt vector */		SCCwrite(INT_VECTOR_REG, BVME_IRQ_SCC_BASE);		/* Interrupt parameters: vector includes status, status low */		SCCwrite(MASTER_INT_CTRL, MIC_VEC_INCL_STAT);		SCCmod(MASTER_INT_CTRL, 0xff, MIC_MASTER_INT_ENAB);	}	/* Init channel B */	port = &scc_ports[1];	port->channel = CHANNEL_B;	port->ctrlp = (volatile unsigned char *)BVME_SCC_B_ADDR;	port->datap = port->ctrlp + 4;	port->port_a = &scc_ports[0];	port->port_b = &scc_ports[1];	request_irq(BVME_IRQ_SCCB_TX, scc_tx_int, SA_INTERRUPT,		            "SCC-B TX", port);	request_irq(BVME_IRQ_SCCB_STAT, scc_stat_int, SA_INTERRUPT,		            "SCC-B status", port);	request_irq(BVME_IRQ_SCCB_RX, scc_rx_int, SA_INTERRUPT,		            "SCC-B RX", port);	request_irq(BVME_IRQ_SCCB_SPCOND, scc_spcond_int, SA_INTERRUPT,		            "SCC-B special cond", port);	{		SCC_ACCESS_INIT(port);	/* Either channel will do */		/* disable interrupts for this channel */		SCCwrite(INT_AND_DMA_REG, 0);	}	/* Initialise the tty driver structures and register */	scc_init_portstructs();	scc_init_drivers();	return 0;}#endifint vme_scc_init(void){	int res = -ENODEV;	static int called = 0;	if (called)		return res;	called = 1;#ifdef CONFIG_MVME147_SCC	if (MACH_IS_MVME147)		res = mvme147_scc_init();#endif#ifdef CONFIG_MVME162_SCC	if (MACH_IS_MVME16x)		res = mvme162_scc_init();#endif#ifdef CONFIG_BVME6000_SCC	if (MACH_IS_BVME6000)		res = bvme6000_scc_init();#endif	return res;}/*--------------------------------------------------------------------------- * Interrupt handlers *--------------------------------------------------------------------------*/static void scc_rx_int(int irq, void *data, struct pt_regs *fp){	unsigned char	ch;	struct scc_port *port = data;	struct tty_struct *tty = port->gs.tty;	SCC_ACCESS_INIT(port);	ch = SCCread_NB(RX_DATA_REG);	if (!tty) {		printk ("scc_rx_int with NULL tty!\n");		SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);		return;	}	if (tty->flip.count < TTY_FLIPBUF_SIZE) {		*tty->flip.char_buf_ptr = ch;		*tty->flip.flag_buf_ptr = 0;		tty->flip.flag_buf_ptr++;		tty->flip.char_buf_ptr++;		tty->flip.count++;	}	/* Check if another character is already ready; in that case, the	 * spcond_int() function must be used, because this character may have an	 * error condition that isn't signalled by the interrupt vector used!	 */	if (SCCread(INT_PENDING_REG) &	    (port->channel == CHANNEL_A ? IPR_A_RX : IPR_B_RX)) {		scc_spcond_int (irq, data, fp);		return;	}	SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);	tty_flip_buffer_push(tty);}static void scc_spcond_int(int irq, void *data, struct pt_regs *fp){	struct scc_port *port = data;	struct tty_struct *tty = port->gs.tty;	unsigned char	stat, ch, err;	int		int_pending_mask = port->channel == CHANNEL_A ?			                   IPR_A_RX : IPR_B_RX;	SCC_ACCESS_INIT(port);		if (!tty) {		printk ("scc_spcond_int with NULL tty!\n");		SCCwrite(COMMAND_REG, CR_ERROR_RESET);		SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);		return;	}	do {		stat = SCCread(SPCOND_STATUS_REG);		ch = SCCread_NB(RX_DATA_REG);		if (stat & SCSR_RX_OVERRUN)			err = TTY_OVERRUN;		else if (stat & SCSR_PARITY_ERR)			err = TTY_PARITY;		else if (stat & SCSR_CRC_FRAME_ERR)			err = TTY_FRAME;		else			err = 0;		if (tty->flip.count < TTY_FLIPBUF_SIZE) {			*tty->flip.char_buf_ptr = ch;			*tty->flip.flag_buf_ptr = err;			tty->flip.flag_buf_ptr++;			tty->flip.char_buf_ptr++;			tty->flip.count++;		}		/* ++TeSche: *All* errors have to be cleared manually,		 * else the condition persists for the next chars		 */		if (err)		  SCCwrite(COMMAND_REG, CR_ERROR_RESET);	} while(SCCread(INT_PENDING_REG) & int_pending_mask);	SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);	tty_flip_buffer_push(tty);}static void scc_tx_int(int irq, void *data, struct pt_regs *fp){	struct scc_port *port = data;	SCC_ACCESS_INIT(port);	if (!port->gs.tty) {		printk ("scc_tx_int with NULL tty!\n");		SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);		SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);		SCCwrite_NB(COMMAND_REG, CR_HIGHEST_IUS_RESET);		return;	}	while ((SCCread_NB(STATUS_REG) & SR_TX_BUF_EMPTY)) {		if (port->x_char) {			SCCwrite(TX_DATA_REG, port->x_char);			port->x_char = 0;		}		else if ((port->gs.xmit_cnt <= 0) || port->gs.tty->stopped ||				port->gs.tty->hw_stopped)			break;		else {			SCCwrite(TX_DATA_REG, port->gs.xmit_buf[port->gs.xmit_tail++]);			port->gs.xmit_tail = port->gs.xmit_tail & (SERIAL_XMIT_SIZE-1);			if (--port->gs.xmit_cnt <= 0)				break;		}	}	if ((port->gs.xmit_cnt <= 0) || port->gs.tty->stopped ||			port->gs.tty->hw_stopped) {		/* disable tx interrupts */		SCCmod (INT_AND_DMA_REG, ~IDR_TX_INT_ENAB, 0);		SCCwrite(COMMAND_REG, CR_TX_PENDING_RESET);   /* disable tx_int on next tx underrun? */		port->gs.flags &= ~GS_TX_INTEN;	}	if (port->gs.tty && port->gs.xmit_cnt <= port->gs.wakeup_chars) {		if ((port->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&				port->gs.tty->ldisc.write_wakeup)			(port->gs.tty->ldisc.write_wakeup)(port->gs.tty);		wake_up_interruptible(&port->gs.tty->write_wait);

⌨️ 快捷键说明

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