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

📄 68360serial.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	/* Check to see if there is room in the tty buffer for	 * the break.  If not, we exit now, losing the break.  FIXME	 */	tty_insert_flip_char(tty, 0, TTY_BREAK);	tty_schedule_flip(tty);}static _INLINE_ void transmit_chars(ser_info_t *info){	if ((info->flags & TX_WAKEUP) ||	    (info->tty->flags & (1 << TTY_DO_WRITE_WAKEUP))) {		schedule_work(&info->tqueue);	}#ifdef SERIAL_DEBUG_INTR	printk("THRE...");#endif}#ifdef notdef	/* I need to do this for the SCCs, so it is left as a reminder.	*/static _INLINE_ void check_modem_status(struct async_struct *info){	int	status;	/* struct	async_icount *icount; */	struct	async_icount_24 *icount;		status = serial_in(info, UART_MSR);	if (status & UART_MSR_ANY_DELTA) {		icount = &info->state->icount;		/* update input line counters */		if (status & UART_MSR_TERI)			icount->rng++;		if (status & UART_MSR_DDSR)			icount->dsr++;		if (status & UART_MSR_DDCD) {			icount->dcd++;#ifdef CONFIG_HARD_PPS			if ((info->flags & ASYNC_HARDPPS_CD) &&			    (status & UART_MSR_DCD))				hardpps();#endif		}		if (status & UART_MSR_DCTS)			icount->cts++;		wake_up_interruptible(&info->delta_msr_wait);	}	if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))		printk("ttys%d CD now %s...", info->line,		       (status & UART_MSR_DCD) ? "on" : "off");#endif				if (status & UART_MSR_DCD)			wake_up_interruptible(&info->open_wait);		else {#ifdef SERIAL_DEBUG_OPEN			printk("scheduling hangup...");#endif			queue_task(&info->tqueue_hangup,					   &tq_scheduler);		}	}	if (info->flags & ASYNC_CTS_FLOW) {		if (info->tty->hw_stopped) {			if (status & UART_MSR_CTS) {#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))				printk("CTS tx start...");#endif				info->tty->hw_stopped = 0;				info->IER |= UART_IER_THRI;				serial_out(info, UART_IER, info->IER);				rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);				return;			}		} else {			if (!(status & UART_MSR_CTS)) {#if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))				printk("CTS tx stop...");#endif				info->tty->hw_stopped = 1;				info->IER &= ~UART_IER_THRI;				serial_out(info, UART_IER, info->IER);			}		}	}}#endif/* * This is the serial driver's interrupt routine for a single port *//* static void rs_360_interrupt(void *dev_id) */ /* until and if we start servicing irqs here */static void rs_360_interrupt(int vec, void *dev_id){	u_char	events;	int	idx;	ser_info_t *info;	volatile struct smc_regs *smcp;	volatile struct scc_regs *sccp;		info = dev_id;	idx = PORT_NUM(info->state->smc_scc_num);	if (info->state->smc_scc_num & NUM_IS_SCC) {		sccp = &pquicc->scc_regs[idx];		events = sccp->scc_scce;		if (events & SCCM_RX)			receive_chars(info);		if (events & SCCM_TX)			transmit_chars(info);		sccp->scc_scce = events;	} else {		smcp = &pquicc->smc_regs[idx];		events = smcp->smc_smce;		if (events & SMCM_BRKE)			receive_break(info);		if (events & SMCM_RX)			receive_chars(info);		if (events & SMCM_TX)			transmit_chars(info);		smcp->smc_smce = events;	}	#ifdef SERIAL_DEBUG_INTR	printk("rs_interrupt_single(%d, %x)...",					info->state->smc_scc_num, events);#endif#ifdef modem_control	check_modem_status(info);#endif	info->last_active = jiffies;#ifdef SERIAL_DEBUG_INTR	printk("end.\n");#endif}/* * ------------------------------------------------------------------- * Here ends the serial interrupt routines. * ------------------------------------------------------------------- */static void do_softint(void *private_){	ser_info_t	*info = (ser_info_t *) private_;	struct tty_struct	*tty;		tty = info->tty;	if (!tty)		return;	if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))		tty_wakeup(tty);}/* * This routine is called from the scheduler tqueue when the interrupt * routine has signalled that a hangup has occurred.  The path of * hangup processing is: * * 	serial interrupt routine -> (scheduler tqueue) -> * 	do_serial_hangup() -> tty->hangup() -> rs_hangup() *  */static void do_serial_hangup(void *private_){	struct async_struct	*info = (struct async_struct *) private_;	struct tty_struct	*tty;		tty = info->tty;	if (!tty)		return;	tty_hangup(tty);}static int startup(ser_info_t *info){	unsigned long flags;	int	retval=0;	int	idx;	/*struct serial_state *state = info->state;*/	volatile struct smc_regs *smcp;	volatile struct scc_regs *sccp;	volatile struct smc_uart_pram	*up;	volatile struct uart_pram	    *scup;	local_irq_save(flags);	if (info->flags & ASYNC_INITIALIZED) {		goto errout;	}#ifdef maybe	if (!state->port || !state->type) {		if (info->tty)			set_bit(TTY_IO_ERROR, &info->tty->flags);		goto errout;	}#endif#ifdef SERIAL_DEBUG_OPEN	printk("starting up ttys%d (irq %d)...", info->line, state->irq);#endif#ifdef modem_control	info->MCR = 0;	if (info->tty->termios->c_cflag & CBAUD)		info->MCR = UART_MCR_DTR | UART_MCR_RTS;#endif		if (info->tty)		clear_bit(TTY_IO_ERROR, &info->tty->flags);	/*	 * and set the speed of the serial port	 */	change_speed(info);	idx = PORT_NUM(info->state->smc_scc_num);	if (info->state->smc_scc_num & NUM_IS_SCC) {		sccp = &pquicc->scc_regs[idx];		scup = &pquicc->pram[info->state->port].scc.pscc.u;		scup->mrblr = RX_BUF_SIZE;		scup->max_idl = RX_BUF_SIZE;		sccp->scc_sccm |= (UART_SCCM_TX | UART_SCCM_RX);		sccp->scc_gsmr.w.low |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);	} else {		smcp = &pquicc->smc_regs[idx];		/* Enable interrupts and I/O.		*/		smcp->smc_smcm |= (SMCM_RX | SMCM_TX);		smcp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);		/* We can tune the buffer length and idle characters		 * to take advantage of the entire incoming buffer size.		 * If mrblr is something other than 1, maxidl has to be		 * non-zero or we never get an interrupt.  The maxidl		 * is the number of character times we wait after reception		 * of the last character before we decide no more characters		 * are coming.		 */		/* up = (smc_uart_t *)&pquicc->cp_dparam[state->port]; */		/* holy unionized structures, Batman: */		up = &pquicc->pram[info->state->port].scc.pothers.idma_smc.psmc.u;		up->mrblr = RX_BUF_SIZE;		up->max_idl = RX_BUF_SIZE;		up->brkcr = 1;	/* number of break chars */	}	info->flags |= ASYNC_INITIALIZED;	local_irq_restore(flags);	return 0;	errout:	local_irq_restore(flags);	return retval;}/* * This routine will shutdown a serial port; interrupts are disabled, and * DTR is dropped if the hangup on close termio flag is on. */static void shutdown(ser_info_t *info){	unsigned long	flags;	struct serial_state *state;	int		idx;	volatile struct smc_regs	*smcp;	volatile struct scc_regs	*sccp;	if (!(info->flags & ASYNC_INITIALIZED))		return;	state = info->state;#ifdef SERIAL_DEBUG_OPEN	printk("Shutting down serial port %d (irq %d)....", info->line,	       state->irq);#endif		local_irq_save(flags);	idx = PORT_NUM(state->smc_scc_num);	if (state->smc_scc_num & NUM_IS_SCC) {		sccp = &pquicc->scc_regs[idx];		sccp->scc_gsmr.w.low &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);#ifdef CONFIG_SERIAL_CONSOLE		/* We can't disable the transmitter if this is the		 * system console.		 */		if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)#endif		sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);	} else {		smcp = &pquicc->smc_regs[idx];		/* Disable interrupts and I/O.		 */		smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);#ifdef CONFIG_SERIAL_CONSOLE		/* We can't disable the transmitter if this is the		 * system console.		 */		if ((state - rs_table) != CONFIG_SERIAL_CONSOLE_PORT)#endif			smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);	}		if (info->tty)		set_bit(TTY_IO_ERROR, &info->tty->flags);	info->flags &= ~ASYNC_INITIALIZED;	local_irq_restore(flags);}/* * This routine is called to set the UART divisor registers to match * the specified baud rate for a serial port. */static void change_speed(ser_info_t *info){	int	baud_rate;	unsigned cflag, cval, scval, prev_mode;	int	i, bits, sbits, idx;	unsigned long	flags;	struct serial_state *state;	volatile struct smc_regs	*smcp;	volatile struct scc_regs	*sccp;	if (!info->tty || !info->tty->termios)		return;	cflag = info->tty->termios->c_cflag;	state = info->state;	/* Character length programmed into the mode register is the	 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,	 * 1 or 2 stop bits, minus 1.	 * The value 'bits' counts this for us.	 */	cval = 0;	scval = 0;	/* byte size and parity */	switch (cflag & CSIZE) {	      case CS5: bits = 5; break;	      case CS6: bits = 6; break;	      case CS7: bits = 7; break;	      case CS8: bits = 8; break;	      /* Never happens, but GCC is too dumb to figure it out */	      default:  bits = 8; break;	}	sbits = bits - 5;	if (cflag & CSTOPB) {		cval |= SMCMR_SL;	/* Two stops */		scval |= SCU_PMSR_SL;		bits++;	}	if (cflag & PARENB) {		cval |= SMCMR_PEN;		scval |= SCU_PMSR_PEN;		bits++;	}	if (!(cflag & PARODD)) {		cval |= SMCMR_PM_EVEN;		scval |= (SCU_PMSR_REVP | SCU_PMSR_TEVP);	}	/* Determine divisor based on baud rate */	i = cflag & CBAUD;	if (i >= (sizeof(baud_table)/sizeof(int)))		baud_rate = 9600;	else		baud_rate = baud_table[i];	info->timeout = (TX_BUF_SIZE*HZ*bits);	info->timeout += HZ/50;		/* Add .02 seconds of slop */#ifdef modem_control	/* CTS flow control flag and modem status interrupts */	info->IER &= ~UART_IER_MSI;	if (info->flags & ASYNC_HARDPPS_CD)		info->IER |= UART_IER_MSI;	if (cflag & CRTSCTS) {		info->flags |= ASYNC_CTS_FLOW;		info->IER |= UART_IER_MSI;	} else		info->flags &= ~ASYNC_CTS_FLOW;	if (cflag & CLOCAL)		info->flags &= ~ASYNC_CHECK_CD;	else {		info->flags |= ASYNC_CHECK_CD;		info->IER |= UART_IER_MSI;	}	serial_out(info, UART_IER, info->IER);#endif	/*	 * Set up parity check flag	 */	info->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);	if (I_INPCK(info->tty))		info->read_status_mask |= BD_SC_FR | BD_SC_PR;	if (I_BRKINT(info->tty) || I_PARMRK(info->tty))		info->read_status_mask |= BD_SC_BR;		/*	 * Characters to ignore	 */	info->ignore_status_mask = 0;	if (I_IGNPAR(info->tty))		info->ignore_status_mask |= BD_SC_PR | BD_SC_FR;	if (I_IGNBRK(info->tty)) {		info->ignore_status_mask |= BD_SC_BR;		/*		 * If we're ignore parity and break indicators, ignore 		 * overruns too.  (For real raw support).		 */		if (I_IGNPAR(info->tty))			info->ignore_status_mask |= BD_SC_OV;	}	/*	 * !!! ignore all characters if CREAD is not set	 */	if ((cflag & CREAD) == 0)	 info->read_status_mask &= ~BD_SC_EMPTY;	 local_irq_save(flags);	 /* Start bit has not been added (so don't, because we would just	  * subtract it later), and we need to add one for the number of	  * stops bits (there is always at least one).	  */	 bits++;	 idx = PORT_NUM(state->smc_scc_num);	 if (state->smc_scc_num & NUM_IS_SCC) {         sccp = &pquicc->scc_regs[idx];         sccp->scc_psmr = (sbits << 12) | scval;     } else {         smcp = &pquicc->smc_regs[idx];		/* Set the mode register.  We want to keep a copy of the		 * enables, because we want to put them back if they were		 * present.		 */		prev_mode = smcp->smc_smcmr;		smcp->smc_smcmr = smcr_mk_clen(bits) | cval |  SMCMR_SM_UART;		smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));	}	m360_cpm_setbrg((state - rs_table), baud_rate);	local_irq_restore(flags);}static void rs_360_put_char(struct tty_struct *tty, unsigned char ch){	ser_info_t *info = (ser_info_t *)tty->driver_data;	volatile QUICC_BD	*bdp;	if (serial_paranoia_check(info, tty->name, "rs_put_char"))		return;	if (!tty)		return;	bdp = info->tx_cur;	while (bdp->status & BD_SC_READY);	/* *((char *)__va(bdp->buf)) = ch; */	*((char *)bdp->buf) = ch;	bdp->length = 1;	bdp->status |= BD_SC_READY;	/* Get next BD.	*/	if (bdp->status & BD_SC_WRAP)		bdp = info->tx_bd_base;	else		bdp++;	info->tx_cur = (QUICC_BD *)bdp;}static int rs_360_write(struct tty_struct * tty,		    const unsigned char *buf, int count){	int	c, ret = 0;	ser_info_t *info = (ser_info_t *)tty->driver_data;	volatile QUICC_BD *bdp;#ifdef CONFIG_KGDB	/* Try to let stub handle output. Returns true if it did. */ 	if (kgdb_output_string(buf, count))		return ret;#endif	if (serial_paranoia_check(info, tty->name, "rs_write"))		return 0;

⌨️ 快捷键说明

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