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

📄 macserial.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 5 页
字号:
}static void rs_flush_chars(struct tty_struct *tty){	struct mac_serial *info = (struct mac_serial *)tty->driver_data;	if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))		return;	if (info->xmit_cnt <= 0 || tty->stopped || info->tx_stopped ||	    !info->xmit_buf)		return;	/* Enable transmitter */	transmit_chars(info);}static int rs_write(struct tty_struct * tty, int from_user,		    const unsigned char *buf, int count){	int	c, ret = 0;	struct mac_serial *info = (struct mac_serial *)tty->driver_data;	unsigned long flags;	if (serial_paranoia_check(info, tty->device, "rs_write"))		return 0;	if (!tty || !info->xmit_buf || !tmp_buf)		return 0;	if (from_user) {		down(&tmp_buf_sem);		while (1) {			c = MIN(count,				MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,				    SERIAL_XMIT_SIZE - info->xmit_head));			if (c <= 0)				break;			c -= copy_from_user(tmp_buf, buf, c);			if (!c) {				if (!ret)					ret = -EFAULT;				break;			}			save_flags(flags);			cli();			c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,				       SERIAL_XMIT_SIZE - info->xmit_head));			memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);			info->xmit_head = ((info->xmit_head + c) &					   (SERIAL_XMIT_SIZE-1));			info->xmit_cnt += c;			restore_flags(flags);			buf += c;			count -= c;			ret += c;		}		up(&tmp_buf_sem);	} else {		while (1) {			save_flags(flags);			cli();			c = MIN(count,				MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,				    SERIAL_XMIT_SIZE - info->xmit_head));			if (c <= 0) {				restore_flags(flags);				break;			}			memcpy(info->xmit_buf + info->xmit_head, buf, c);			info->xmit_head = ((info->xmit_head + c) &					   (SERIAL_XMIT_SIZE-1));			info->xmit_cnt += c;			restore_flags(flags);			buf += c;			count -= c;			ret += c;		}	}	if (info->xmit_cnt && !tty->stopped && !info->tx_stopped	    && !info->tx_active)		transmit_chars(info);	return ret;}static int rs_write_room(struct tty_struct *tty){	struct mac_serial *info = (struct mac_serial *)tty->driver_data;	int	ret;	if (serial_paranoia_check(info, tty->device, "rs_write_room"))		return 0;	ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;	if (ret < 0)		ret = 0;	return ret;}static int rs_chars_in_buffer(struct tty_struct *tty){	struct mac_serial *info = (struct mac_serial *)tty->driver_data;	if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))		return 0;	return info->xmit_cnt;}static void rs_flush_buffer(struct tty_struct *tty){	struct mac_serial *info = (struct mac_serial *)tty->driver_data;	unsigned long flags;	if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))		return;	save_flags(flags); cli();	info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;	restore_flags(flags);	wake_up_interruptible(&tty->write_wait);	if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&	    tty->ldisc.write_wakeup)		(tty->ldisc.write_wakeup)(tty);}/* * ------------------------------------------------------------ * rs_throttle() *  * This routine is called by the upper-layer tty layer to signal that * incoming characters should be throttled. * ------------------------------------------------------------ */static void rs_throttle(struct tty_struct * tty){	struct mac_serial *info = (struct mac_serial *)tty->driver_data;	unsigned long flags;#ifdef SERIAL_DEBUG_THROTTLE	printk(KERN_DEBUG "throttle %ld....\n",tty->ldisc.chars_in_buffer(tty));#endif	if (serial_paranoia_check(info, tty->device, "rs_throttle"))		return;	if (I_IXOFF(tty)) {		save_flags(flags); cli();		info->x_char = STOP_CHAR(tty);		if (!info->tx_active)			transmit_chars(info);		restore_flags(flags);	}	if (C_CRTSCTS(tty)) {		/*		 * Here we want to turn off the RTS line.  On Macintoshes,		 * the external serial ports using a DIN-8 or DIN-9		 * connector only have the DTR line (which is usually		 * wired to both RTS and DTR on an external modem in		 * the cable).  RTS doesn't go out to the serial port		 * socket, it acts as an output enable for the transmit		 * data line.  So in this case we don't drop RTS.		 *		 * Macs with internal modems generally do have both RTS		 * and DTR wired to the modem, so in that case we do		 * drop RTS.		 */		if (info->is_internal_modem) {			save_flags(flags); cli();			info->curregs[5] &= ~RTS;			info->pendregs[5] &= ~RTS;			write_zsreg(info->zs_channel, 5, info->curregs[5]);			restore_flags(flags);		}	}	#ifdef CDTRCTS	if (tty->termios->c_cflag & CDTRCTS) {		save_flags(flags); cli();		info->curregs[5] &= ~DTR;		info->pendregs[5] &= ~DTR;		write_zsreg(info->zs_channel, 5, info->curregs[5]);		restore_flags(flags);	}#endif /* CDTRCTS */}static void rs_unthrottle(struct tty_struct * tty){	struct mac_serial *info = (struct mac_serial *)tty->driver_data;	unsigned long flags;#ifdef SERIAL_DEBUG_THROTTLE	printk(KERN_DEBUG "unthrottle %s: %d....\n",			tty->ldisc.chars_in_buffer(tty));#endif	if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))		return;	if (I_IXOFF(tty)) {		save_flags(flags); cli();		if (info->x_char)			info->x_char = 0;		else {			info->x_char = START_CHAR(tty);			if (!info->tx_active)				transmit_chars(info);		}		restore_flags(flags);	}	if (C_CRTSCTS(tty) && info->is_internal_modem) {		/* Assert RTS line */		save_flags(flags); cli();		info->curregs[5] |= RTS;		info->pendregs[5] |= RTS;		write_zsreg(info->zs_channel, 5, info->curregs[5]);		restore_flags(flags);	}#ifdef CDTRCTS	if (tty->termios->c_cflag & CDTRCTS) {		/* Assert DTR line */		save_flags(flags); cli();		info->curregs[5] |= DTR;		info->pendregs[5] |= DTR;		write_zsreg(info->zs_channel, 5, info->curregs[5]);		restore_flags(flags);	}#endif}/* * ------------------------------------------------------------ * rs_ioctl() and friends * ------------------------------------------------------------ */static int get_serial_info(struct mac_serial * info,			   struct serial_struct * retinfo){	struct serial_struct tmp;  	if (!retinfo)		return -EFAULT;	memset(&tmp, 0, sizeof(tmp));	tmp.type = info->type;	tmp.line = info->line;	tmp.port = info->port;	tmp.irq = info->irq;	tmp.flags = info->flags;	tmp.baud_base = info->baud_base;	tmp.close_delay = info->close_delay;	tmp.closing_wait = info->closing_wait;	tmp.custom_divisor = info->custom_divisor;	if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))		return -EFAULT;	return 0;}static int set_serial_info(struct mac_serial * info,			   struct serial_struct * new_info){	struct serial_struct new_serial;	struct mac_serial old_info;	int 			retval = 0;	if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))		return -EFAULT;	old_info = *info;	if (!capable(CAP_SYS_ADMIN)) {		if ((new_serial.baud_base != info->baud_base) ||		    (new_serial.type != info->type) ||		    (new_serial.close_delay != info->close_delay) ||		    ((new_serial.flags & ~ZILOG_USR_MASK) !=		     (info->flags & ~ZILOG_USR_MASK)))			return -EPERM;		info->flags = ((info->flags & ~ZILOG_USR_MASK) |			       (new_serial.flags & ZILOG_USR_MASK));		info->custom_divisor = new_serial.custom_divisor;		goto check_and_exit;	}	if (info->count > 1)		return -EBUSY;	/*	 * OK, past this point, all the error checking has been done.	 * At this point, we start making changes.....	 */	info->baud_base = new_serial.baud_base;	info->flags = ((info->flags & ~ZILOG_FLAGS) |			(new_serial.flags & ZILOG_FLAGS));	info->type = new_serial.type;	info->close_delay = new_serial.close_delay;	info->closing_wait = new_serial.closing_wait;check_and_exit:	if (info->flags & ZILOG_INITIALIZED)		retval = setup_scc(info);	return retval;}/* * get_lsr_info - get line status register info * * Purpose: Let user call ioctl() to get info when the UART physically * 	    is emptied.  On bus types like RS485, the transmitter must * 	    release the bus after transmitting. This must be done when * 	    the transmit shift register is empty, not be done when the * 	    transmit holding register is empty.  This functionality * 	    allows an RS485 driver to be written in user space.  */static int get_lsr_info(struct mac_serial * info, unsigned int *value){	unsigned char status;	unsigned long flags;	save_flags(flags); cli();	status = read_zsreg(info->zs_channel, 0);	restore_flags(flags);	status = (status & Tx_BUF_EMP)? TIOCSER_TEMT: 0;	return put_user(status,value);}static int get_modem_info(struct mac_serial *info, unsigned int *value){	unsigned char control, status;	unsigned int result;	unsigned long flags;	save_flags(flags); cli();	control = info->curregs[5];	status = read_zsreg(info->zs_channel, 0);	restore_flags(flags);	result =  ((control & RTS) ? TIOCM_RTS: 0)		| ((control & DTR) ? TIOCM_DTR: 0)		| ((status  & DCD) ? TIOCM_CAR: 0)		| ((status  & CTS) ? 0: TIOCM_CTS);	return put_user(result,value);}static int set_modem_info(struct mac_serial *info, unsigned int cmd,			  unsigned int *value){	unsigned int arg, bits;	unsigned long flags;	if (get_user(arg, value))		return -EFAULT;	bits = (arg & TIOCM_RTS? RTS: 0) + (arg & TIOCM_DTR? DTR: 0);	save_flags(flags); cli();	switch (cmd) {	case TIOCMBIS:		info->curregs[5] |= bits;		break;	case TIOCMBIC:		info->curregs[5] &= ~bits;		break;	case TIOCMSET:		info->curregs[5] = (info->curregs[5] & ~(DTR | RTS)) | bits;		break;	default:		restore_flags(flags);		return -EINVAL;	}	info->pendregs[5] = info->curregs[5];	write_zsreg(info->zs_channel, 5, info->curregs[5]);	restore_flags(flags);	return 0;}/* * rs_break - turn transmit break condition on/off */static void rs_break(struct tty_struct *tty, int break_state){	struct mac_serial *info = (struct mac_serial *) tty->driver_data;	unsigned long flags;	if (serial_paranoia_check(info, tty->device, "rs_break"))		return;	save_flags(flags); cli();	if (break_state == -1)		info->curregs[5] |= SND_BRK;	else		info->curregs[5] &= ~SND_BRK;	write_zsreg(info->zs_channel, 5, info->curregs[5]);	restore_flags(flags);}static int rs_ioctl(struct tty_struct *tty, struct file * file,		    unsigned int cmd, unsigned long arg){	struct mac_serial * info = (struct mac_serial *)tty->driver_data;#ifdef CONFIG_KGDB	if (info->kgdb_channel)		return -ENODEV;#endif	if (serial_paranoia_check(info, tty->device, "rs_ioctl"))		return -ENODEV;	if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&	    (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT)) {		if (tty->flags & (1 << TTY_IO_ERROR))		    return -EIO;	}	switch (cmd) {		case TIOCMGET:			return get_modem_info(info, (unsigned int *) arg);		case TIOCMBIS:		case TIOCMBIC:		case TIOCMSET:			return set_modem_info(info, cmd, (unsigned int *) arg);		case TIOCGSERIAL:			return get_serial_info(info,					       (struct serial_struct *) arg);		case TIOCSSERIAL:			return set_serial_info(info,					       (struct serial_struct *) arg);		case TIOCSERGETLSR: /* Get line status register */			return get_lsr_info(info, (unsigned int *) arg);		case TIOCSERGSTRUCT:			if (copy_to_user((struct mac_serial *) arg,					 info, sizeof(struct mac_serial)))				return -EFAULT;			return 0;		default:			return -ENOIOCTLCMD;		}	return 0;}static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios){	struct mac_serial *info = (struct mac_serial *)tty->driver_data;	int was_stopped;	if (tty->termios->c_cflag == old_termios->c_cflag)		return;	was_stopped = info->tx_stopped;	change_speed(info, old_termios);	if (was_stopped && !info->tx_stopped) {		tty->hw_stopped = 0;		rs_start(tty);	}}/* * ------------------------------------------------------------ * rs_close() *  * This routine is called when the serial port gets closed. * Wait for the last remaining data to be sent. * ------------------------------------------------------------ */static void rs_close(struct tty_struct *tty, struct file * filp){	struct mac_serial * info = (struct mac_serial *)tty->driver_data;	unsigned long flags;	if (!info || serial_paranoia_check(info, tty->device, "rs_close"))		return;	save_flags(flags); cli();	if (tty_hung_up_p(filp)) {		MOD_DEC_USE_COUNT;		restore_flags(flags);		return;	}	OPNDBG("rs_close ttyS%d, count = %d\n", info->line, info->count);	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(KERN_ERR "rs_close: bad serial port count; tty->count "				"is 1, info->count is %d\n", info->count);		info->count = 1;	}	if (--info->count < 0) {

⌨️ 快捷键说明

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