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

📄 68328serial.c

📁 这是一个SIGMA方案的PMP播放器的UCLINUX程序,可播放DVD,VCD,CD MP3...有很好的参考价值.
💻 C
📖 第 1 页 / 共 3 页
字号:
			if (error)				return error;			else			    return get_lsr_info(info, (unsigned int *) arg);		case TIOCSERGSTRUCT:			error = verify_area(VERIFY_WRITE, (void *) arg,						sizeof(struct m68k_serial));			if (error)				return error;			copy_to_user((struct m68k_serial *) arg,				    info, sizeof(struct m68k_serial));			return 0;					default:			return -ENOIOCTLCMD;		}	return 0;}static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios){	struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;	if (tty->termios->c_cflag == old_termios->c_cflag)		return;	change_speed(info);	if ((old_termios->c_cflag & CRTSCTS) &&	    !(tty->termios->c_cflag & CRTSCTS)) {		tty->hw_stopped = 0;		rs_start(tty);	}	}/* * ------------------------------------------------------------ * rs_close() *  * This routine is called when the serial port gets closed.  First, we * wait for the last remaining data to be sent.  Then, we unlink its * S structure from the interrupt chain if necessary, and we free * that IRQ if nothing is left in the chain. * ------------------------------------------------------------ */static void rs_close(struct tty_struct *tty, struct file * filp){	struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;	m68328_uart *uart = &uart_addr[info->line];	unsigned long flags;	if (!info || serial_paranoia_check(info, tty->device, "rs_close"))		return;		save_flags(flags); cli();		if (tty_hung_up_p(filp)) {		restore_flags(flags);		return;	}		if ((tty->count == 1) && (info->count != 1)) {		/*		 * Uh, oh.  tty->count is 1, which means that the tty		 * structure will be freed.  Info->count should always		 * be one in these conditions.  If it's greater than		 * one, we've got real problems, since it means the		 * serial port won't be shutdown.		 */		printk("rs_close: bad serial port count; tty->count is 1, "		       "info->count is %d\n", info->count);		info->count = 1;	}	if (--info->count < 0) {		printk("rs_close: bad serial port count for ttyS%d: %d\n",		       info->line, info->count);		info->count = 0;	}	if (info->count) {		restore_flags(flags);		return;	}	info->flags |= S_CLOSING;	/*	 * Save the termios structure, since this port may have	 * separate termios for callout and dialin.	 */	if (info->flags & S_NORMAL_ACTIVE)		info->normal_termios = *tty->termios;	if (info->flags & S_CALLOUT_ACTIVE)		info->callout_termios = *tty->termios;	/*	 * Now we wait for the transmit buffer to clear; and we notify 	 * the line discipline to only process XON/XOFF characters.	 */	tty->closing = 1;	if (info->closing_wait != S_CLOSING_WAIT_NONE)		tty_wait_until_sent(tty, info->closing_wait);	/*	 * At this point we stop accepting input.  To do this, we	 * disable the receive line status interrupts, and tell the	 * interrupt driver to stop checking the data ready bit in the	 * line status register.	 */	uart->ustcnt &= ~USTCNT_RXEN;	uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);	shutdown(info);	if (tty->driver.flush_buffer)		tty->driver.flush_buffer(tty);	if (tty->ldisc.flush_buffer)		tty->ldisc.flush_buffer(tty);	tty->closing = 0;	info->event = 0;	info->tty = 0;	if (tty->ldisc.num != ldiscs[N_TTY].num) {		if (tty->ldisc.close)			(tty->ldisc.close)(tty);		tty->ldisc = ldiscs[N_TTY];		tty->termios->c_line = N_TTY;		if (tty->ldisc.open)			(tty->ldisc.open)(tty);	}	if (info->blocked_open) {		if (info->close_delay) {			current->state = TASK_INTERRUPTIBLE;			schedule_timeout(info->close_delay);		}		wake_up_interruptible(&info->open_wait);	}	info->flags &= ~(S_NORMAL_ACTIVE|S_CALLOUT_ACTIVE|			 S_CLOSING);	wake_up_interruptible(&info->close_wait);	restore_flags(flags);}/* * rs_hangup() --- called by tty_hangup() when a hangup is signaled. */void rs_hangup(struct tty_struct *tty){	struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;		if (serial_paranoia_check(info, tty->device, "rs_hangup"))		return;		rs_flush_buffer(tty);	shutdown(info);	info->event = 0;	info->count = 0;	info->flags &= ~(S_NORMAL_ACTIVE|S_CALLOUT_ACTIVE);	info->tty = 0;	wake_up_interruptible(&info->open_wait);}/* * ------------------------------------------------------------ * rs_open() and friends * ------------------------------------------------------------ */static int block_til_ready(struct tty_struct *tty, struct file * filp,			   struct m68k_serial *info){	DECLARE_WAITQUEUE(wait, current);	int		retval;	int		do_clocal = 0;	/*	 * If the device is in the middle of being closed, then block	 * until it's done, and then try again.	 */	if (info->flags & S_CLOSING) {		interruptible_sleep_on(&info->close_wait);#ifdef SERIAL_DO_RESTART		if (info->flags & S_HUP_NOTIFY)			return -EAGAIN;		else			return -ERESTARTSYS;#else		return -EAGAIN;#endif	}	/*	 * If this is a callout device, then just make sure the normal	 * device isn't being used.	 */	if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {		if (info->flags & S_NORMAL_ACTIVE)			return -EBUSY;		if ((info->flags & S_CALLOUT_ACTIVE) &&		    (info->flags & S_SESSION_LOCKOUT) &&		    (info->session != current->session))		    return -EBUSY;		if ((info->flags & S_CALLOUT_ACTIVE) &&		    (info->flags & S_PGRP_LOCKOUT) &&		    (info->pgrp != current->pgrp))		    return -EBUSY;		info->flags |= S_CALLOUT_ACTIVE;		return 0;	}		/*	 * If non-blocking mode is set, or the port is not enabled,	 * then make the check up front and then exit.	 */	if ((filp->f_flags & O_NONBLOCK) ||	    (tty->flags & (1 << TTY_IO_ERROR))) {		if (info->flags & S_CALLOUT_ACTIVE)			return -EBUSY;		info->flags |= S_NORMAL_ACTIVE;		return 0;	}	if (info->flags & S_CALLOUT_ACTIVE) {		if (info->normal_termios.c_cflag & CLOCAL)			do_clocal = 1;	} else {		if (tty->termios->c_cflag & CLOCAL)			do_clocal = 1;	}		/*	 * Block waiting for the carrier detect and the line to become	 * free (i.e., not in use by the callout).  While we are in	 * this loop, info->count is dropped by one, so that	 * rs_close() knows when to free things.  We restore it upon	 * exit, either normal or abnormal.	 */	retval = 0;	add_wait_queue(&info->open_wait, &wait);	info->count--;	info->blocked_open++;	while (1) {		cli();		if (!(info->flags & S_CALLOUT_ACTIVE))			m68k_rtsdtr(info, 1);		sti();		current->state = TASK_INTERRUPTIBLE;		if (tty_hung_up_p(filp) ||		    !(info->flags & S_INITIALIZED)) {#ifdef SERIAL_DO_RESTART			if (info->flags & S_HUP_NOTIFY)				retval = -EAGAIN;			else				retval = -ERESTARTSYS;	#else			retval = -EAGAIN;#endif			break;		}		if (!(info->flags & S_CALLOUT_ACTIVE) &&		    !(info->flags & S_CLOSING) && do_clocal)			break;                if (signal_pending(current)) {			retval = -ERESTARTSYS;			break;		}		schedule();	}	current->state = TASK_RUNNING;	remove_wait_queue(&info->open_wait, &wait);	if (!tty_hung_up_p(filp))		info->count++;	info->blocked_open--;	if (retval)		return retval;	info->flags |= S_NORMAL_ACTIVE;	return 0;}	/* * This routine is called whenever a serial port is opened.  It * enables interrupts for a serial port, linking in its S structure into * the IRQ chain.   It also performs the serial-specific * initialization for the tty structure. */int rs_open(struct tty_struct *tty, struct file * filp){	struct m68k_serial	*info;	int 			retval, line;	line = MINOR(tty->device) - tty->driver.minor_start;		if (line >= NR_PORTS || line < 0) /* we have exactly one */		return -ENODEV;	info = &m68k_soft[line];	if (serial_paranoia_check(info, tty->device, "rs_open"))		return -ENODEV;	info->count++;	tty->driver_data = info;	info->tty = tty;	/*	 * Start up serial port	 */	retval = startup(info);	if (retval)		return retval;	retval = block_til_ready(tty, filp, info);	if (retval) {		return retval;	}	if ((info->count == 1) && (info->flags & S_SPLIT_TERMIOS)) {		if (tty->driver.subtype == SERIAL_TYPE_NORMAL)			*tty->termios = info->normal_termios;		else 			*tty->termios = info->callout_termios;		change_speed(info);	}	info->session = current->session;	info->pgrp = current->pgrp;	return 0;}/* Finally, routines used to initialize the serial driver. */static void show_serial_version(void){	printk("MC68328 serial driver version 1.00\n");}volatile int test_done;/* rs_init inits the driver */static int __initrs68328_init(void){	int flags, i;	struct m68k_serial *info;		/* Setup base handler, and timer table. */	init_bh(SERIAL_BH, do_serial_bh);	show_serial_version();	/* Initialize the tty_driver structure */	/* SPARC: Not all of this is exactly right for us. */		memset(&serial_driver, 0, sizeof(struct tty_driver));	serial_driver.magic = TTY_DRIVER_MAGIC;	serial_driver.name = "ttyS";	serial_driver.major = TTY_MAJOR;	serial_driver.minor_start = 64;	serial_driver.num = NR_PORTS;	serial_driver.type = TTY_DRIVER_TYPE_SERIAL;	serial_driver.subtype = SERIAL_TYPE_NORMAL;	serial_driver.init_termios = tty_std_termios;	serial_driver.init_termios.c_cflag = 			m68328_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;	serial_driver.flags = TTY_DRIVER_REAL_RAW;	serial_driver.refcount = &serial_refcount;	serial_driver.table = serial_table;	serial_driver.termios = serial_termios;	serial_driver.termios_locked = serial_termios_locked;	serial_driver.open = rs_open;	serial_driver.close = rs_close;	serial_driver.write = rs_write;	serial_driver.flush_chars = rs_flush_chars;	serial_driver.write_room = rs_write_room;	serial_driver.chars_in_buffer = rs_chars_in_buffer;	serial_driver.flush_buffer = rs_flush_buffer;	serial_driver.ioctl = rs_ioctl;	serial_driver.throttle = rs_throttle;	serial_driver.unthrottle = rs_unthrottle;	serial_driver.set_termios = rs_set_termios;	serial_driver.stop = rs_stop;	serial_driver.start = rs_start;	serial_driver.hangup = rs_hangup;	serial_driver.set_ldisc = rs_set_ldisc;	/*	 * The callout device is just like normal device except for	 * major number and the subtype code.	 */	callout_driver = serial_driver;	callout_driver.name = "cua";	callout_driver.major = TTYAUX_MAJOR;	callout_driver.subtype = SERIAL_TYPE_CALLOUT;	if (tty_register_driver(&serial_driver))		panic("Couldn't register serial driver\n");	if (tty_register_driver(&callout_driver))		panic("Couldn't register callout driver\n");		save_flags(flags); cli();	for(i=0;i<NR_PORTS;i++) {	    info = &m68k_soft[i];	    info->magic = SERIAL_MAGIC;	    info->port = &uart_addr[i];	    info->tty = 0;	    info->irq = uart_irqs[i];	    info->custom_divisor = 16;	    info->close_delay = 50;	    info->closing_wait = 3000;	    info->x_char = 0;	    info->event = 0;	    info->count = 0;	    info->blocked_open = 0;	    info->tqueue.routine = do_softint;	    info->tqueue.data = info;	    info->tqueue_hangup.routine = do_serial_hangup;	    info->tqueue_hangup.data = info;	    info->callout_termios =callout_driver.init_termios;	    info->normal_termios = serial_driver.init_termios;	    init_waitqueue_head(&info->open_wait);	    init_waitqueue_head(&info->close_wait);	    info->line = i;	    info->is_cons = 1; /* Means shortcuts work */	    	    printk("%s%d at 0x%08x (irq = %d)", serial_driver.name, info->line, 		   info->port, info->irq);	    printk(" is a builtin MC68328 UART\n");	    	    IRQ_ports[info->irq] = info;	/* waste of space */	    if (request_irq(uart_irqs[i],			    rs_interrupt,			    IRQ_FLG_STD,			    "M68328_UART", NULL))                panic("Unable to attach 68328 serial interrupt\n");	}	restore_flags(flags);	return 0;}/* * register_serial and unregister_serial allows for serial ports to be * configured at run-time, to support PCMCIA modems. *//* SPARC: Unused at this time, just here to make things link. */int register_serial(struct serial_struct *req){	return -1;}void unregister_serial(int line){	return;}	module_init(rs68328_init);/* DAVIDM module_exit(rs68328_fini); */static void m68328_set_baud(){	unsigned short ustcnt;	int	i;	ustcnt = USTCNT;	USTCNT = ustcnt & ~USTCNT_TXEN;again:	for (i = 0; i < sizeof(baud_table) / sizeof(baud_table[0]); i++)		if (baud_table[i] == m68328_console_baud)			break;	if (i >= sizeof(baud_table) / sizeof(baud_table[0])) {		m68328_console_baud = 9600;		goto again;	}	UBAUD = PUT_FIELD(UBAUD_DIVIDE,    hw_baud_table[i].divisor) | 		PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);	ustcnt &= ~(USTCNT_PARITYEN | USTCNT_ODD_EVEN | USTCNT_STOP | USTCNT_8_7);	ustcnt |= USTCNT_8_7;	ustcnt |= USTCNT_TXEN;	USTCNT = ustcnt;	m68328_console_initted = 1;	return;}int m68328_console_setup(struct console *cp, char *arg){	int		i, n = CONSOLE_BAUD_RATE;	if (!cp)		return(-1);	if (arg)		n = simple_strtoul(arg,NULL,0);	for (i = 0; i < BAUD_TABLE_SIZE; i++)		if (baud_table[i] == n)			break;	if (i < BAUD_TABLE_SIZE) {		m68328_console_baud = n;		m68328_console_cbaud = 0;		if (i > 15) {			m68328_console_cbaud |= CBAUDEX;			i -= 15;		}		m68328_console_cbaud |= i;	}	m68328_set_baud(); /* make sure baud rate changes */	return(0);}static kdev_t m68328_console_device(struct console *c){	return MKDEV(TTY_MAJOR, 64 + c->index);}void m68328_console_write (struct console *co, const char *str,			   unsigned int count){	if (!m68328_console_initted)		m68328_set_baud();    while (count--) {        if (*str == '\n')           rs_put_char('\r');        rs_put_char( *str++ );    }}static struct console m68328_driver = {	name:		"ttyS",	write:		m68328_console_write,	read:		NULL,	device:		m68328_console_device,	wait_key:	NULL,	unblank:	NULL,	setup:		m68328_console_setup,	flags:		CON_PRINTBUFFER,	index:		-1,	cflag:		0,	next:		NULL};void m68328_console_init(void){	register_console(&m68328_driver);}

⌨️ 快捷键说明

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