📄 cyclades.c
字号:
/* Check to see that the previous command has completed */ for(i = 0 ; i < 100 ; i++){ if (cy_readb(base_addr+(CyCCR<<index)) == 0){ break; } udelay(10L); } /* if the CCR never cleared, the previous command didn't finish within the "reasonable time" */ if (i == 100) return (-1); /* Issue the new command */ cy_writeb((u_long)base_addr+(CyCCR<<index), cmd); return(0);} /* cyy_issue_cmd */#ifdef CONFIG_ISA/* ISA interrupt detection code */static unsigned detect_isa_irq (volatile ucchar *address){ int irq; unsigned long irqs, flags; int save_xir, save_car; int index = 0; /* IRQ probing is only for ISA */ /* forget possible initially masked and pending IRQ */ irq = probe_irq_off(probe_irq_on()); /* Clear interrupts on the board first */ cy_writeb((u_long)address + (Cy_ClrIntr<<index), 0); /* Cy_ClrIntr is 0x1800 */ irqs = probe_irq_on(); /* Wait ... */ udelay(5000L); /* Enable the Tx interrupts on the CD1400 */ save_flags(flags); cli(); cy_writeb((u_long)address + (CyCAR<<index), 0); cyy_issue_cmd(address, CyCHAN_CTL|CyENB_XMTR, index); cy_writeb((u_long)address + (CyCAR<<index), 0); cy_writeb((u_long)address + (CySRER<<index), cy_readb(address + (CySRER<<index)) | CyTxRdy); restore_flags(flags); /* Wait ... */ udelay(5000L); /* Check which interrupt is in use */ irq = probe_irq_off(irqs); /* Clean up */ save_xir = (u_char) cy_readb(address + (CyTIR<<index)); save_car = cy_readb(address + (CyCAR<<index)); cy_writeb((u_long)address + (CyCAR<<index), (save_xir & 0x3)); cy_writeb((u_long)address + (CySRER<<index), cy_readb(address + (CySRER<<index)) & ~CyTxRdy); cy_writeb((u_long)address + (CyTIR<<index), (save_xir & 0x3f)); cy_writeb((u_long)address + (CyCAR<<index), (save_car)); cy_writeb((u_long)address + (Cy_ClrIntr<<index), 0); /* Cy_ClrIntr is 0x1800 */ return (irq > 0)? irq : 0;}#endif /* CONFIG_ISA *//* The real interrupt service routine is called whenever the card wants its hand held--chars received, out buffer empty, modem change, etc. */static voidcyy_interrupt(int irq, void *dev_id, struct pt_regs *regs){ struct tty_struct *tty; int status; struct cyclades_card *cinfo; struct cyclades_port *info; volatile unsigned char *base_addr, *card_base_addr; int chip; int save_xir, channel, save_car; char data; volatile int char_count; int outch; int i,j,index; int too_many; int had_work; int mdm_change; int mdm_status; if((cinfo = (struct cyclades_card *)dev_id) == 0){#ifdef CY_DEBUG_INTERRUPTS printk("cyy_interrupt: spurious interrupt %d\n\r", irq);#endif return; /* spurious interrupt */ } card_base_addr = (unsigned char *)cinfo->base_addr; index = cinfo->bus_index; /* This loop checks all chips in the card. Make a note whenever _any_ chip had some work to do, as this is considered an indication that there will be more to do. Only when no chip has any work does this outermost loop exit. */ do{ had_work = 0; for ( chip = 0 ; chip < cinfo->num_chips ; chip ++) { base_addr = (unsigned char *) (cinfo->base_addr + (cy_chip_offset[chip]<<index)); too_many = 0; while ( (status = cy_readb(base_addr+(CySVRR<<index))) != 0x00) { had_work++; /* The purpose of the following test is to ensure that no chip can monopolize the driver. This forces the chips to be checked in a round-robin fashion (after draining each of a bunch (1000) of characters). */ if(1000<too_many++){ break; } if (status & CySRReceive) { /* reception interrupt */#ifdef CY_DEBUG_INTERRUPTS printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip);#endif /* determine the channel & change to that context */ spin_lock(&cinfo->card_lock); save_xir = (u_char) cy_readb(base_addr+(CyRIR<<index)); channel = (u_short ) (save_xir & CyIRChannel); i = channel + chip * 4 + cinfo->first_line; info = &cy_port[i]; info->last_active = jiffies; save_car = cy_readb(base_addr+(CyCAR<<index)); cy_writeb((u_long)base_addr+(CyCAR<<index), save_xir); /* if there is nowhere to put the data, discard it */ if(info->tty == 0){ j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask); if ( j == CyIVRRxEx ) { /* exception */ data = cy_readb(base_addr+(CyRDSR<<index)); } else { /* normal character reception */ char_count = cy_readb(base_addr+(CyRDCR<<index)); while(char_count--){ data = cy_readb(base_addr+(CyRDSR<<index)); } } }else{ /* there is an open port for this data */ tty = info->tty; j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask); if ( j == CyIVRRxEx ) { /* exception */ data = cy_readb(base_addr+(CyRDSR<<index)); /* For statistics only */ if (data & CyBREAK) info->icount.brk++; else if(data & CyFRAME) info->icount.frame++; else if(data & CyPARITY) info->icount.parity++; else if(data & CyOVERRUN) info->icount.overrun++; if(data & info->ignore_status_mask){ info->icount.rx++; continue; } if (tty->flip.count < TTY_FLIPBUF_SIZE){ tty->flip.count++; if (data & info->read_status_mask){ if(data & CyBREAK){ *tty->flip.flag_buf_ptr++ = TTY_BREAK; *tty->flip.char_buf_ptr++ = cy_readb(base_addr+(CyRDSR<<index)); info->icount.rx++; if (info->flags & ASYNC_SAK){ do_SAK(tty); } }else if(data & CyFRAME){ *tty->flip.flag_buf_ptr++ = TTY_FRAME; *tty->flip.char_buf_ptr++ = cy_readb(base_addr+(CyRDSR<<index)); info->icount.rx++; info->idle_stats.frame_errs++; }else if(data & CyPARITY){ *tty->flip.flag_buf_ptr++ = TTY_PARITY; *tty->flip.char_buf_ptr++ = cy_readb(base_addr+(CyRDSR<<index)); info->icount.rx++; info->idle_stats.parity_errs++; }else if(data & CyOVERRUN){ *tty->flip.flag_buf_ptr++ = TTY_OVERRUN; *tty->flip.char_buf_ptr++ = 0; info->icount.rx++; /* If the flip buffer itself is overflowing, we still lose the next incoming character. */ if(tty->flip.count < TTY_FLIPBUF_SIZE){ tty->flip.count++; *tty->flip.flag_buf_ptr++ = TTY_NORMAL; *tty->flip.char_buf_ptr++ = cy_readb(base_addr+(CyRDSR<<index)); info->icount.rx++; } info->idle_stats.overruns++; /* These two conditions may imply */ /* a normal read should be done. */ /* }else if(data & CyTIMEOUT){ */ /* }else if(data & CySPECHAR){ */ }else{ *tty->flip.flag_buf_ptr++ = 0; *tty->flip.char_buf_ptr++ = 0; info->icount.rx++; } }else{ *tty->flip.flag_buf_ptr++ = 0; *tty->flip.char_buf_ptr++ = 0; info->icount.rx++; } }else{ /* there was a software buffer overrun and nothing could be done about it!!! */ info->icount.buf_overrun++; info->idle_stats.overruns++; } } else { /* normal character reception */ /* load # chars available from the chip */ char_count = cy_readb(base_addr+(CyRDCR<<index));#ifdef CY_ENABLE_MONITORING ++info->mon.int_count; info->mon.char_count += char_count; if (char_count > info->mon.char_max) info->mon.char_max = char_count; info->mon.char_last = char_count;#endif info->idle_stats.recv_bytes += char_count; info->idle_stats.recv_idle = jiffies; while(char_count--){ if (tty->flip.count >= TTY_FLIPBUF_SIZE){ break; } tty->flip.count++; data = cy_readb(base_addr+(CyRDSR<<index)); *tty->flip.flag_buf_ptr++ = TTY_NORMAL; *tty->flip.char_buf_ptr++ = data; info->icount.rx++;#ifdef CY_16Y_HACK udelay(10L);#endif } } queue_task(&tty->flip.tqueue, &tq_timer); } /* end of service */ cy_writeb((u_long)base_addr+(CyRIR<<index), (save_xir & 0x3f)); cy_writeb((u_long)base_addr+(CyCAR<<index), (save_car)); spin_unlock(&cinfo->card_lock); } if (status & CySRTransmit) { /* transmission interrupt */ /* Since we only get here when the transmit buffer is empty, we know we can always stuff a dozen characters. */#ifdef CY_DEBUG_INTERRUPTS printk("cyy_interrupt: xmit intr, chip %d\n\r", chip);#endif /* determine the channel & change to that context */ spin_lock(&cinfo->card_lock); save_xir = (u_char) cy_readb(base_addr+(CyTIR<<index)); channel = (u_short ) (save_xir & CyIRChannel); i = channel + chip * 4 + cinfo->first_line; save_car = cy_readb(base_addr+(CyCAR<<index)); cy_writeb((u_long)base_addr+(CyCAR<<index), save_xir); /* validate the port# (as configured and open) */ if( (i < 0) || (NR_PORTS <= i) ){ cy_writeb((u_long)base_addr+(CySRER<<index), cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy); goto txend; } info = &cy_port[i]; info->last_active = jiffies; if(info->tty == 0){ cy_writeb((u_long)base_addr+(CySRER<<index), cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy); goto txdone; } /* load the on-chip space for outbound data */ char_count = info->xmit_fifo_size; if(info->x_char) { /* send special char */ outch = info->x_char; cy_writeb((u_long)base_addr+(CyTDR<<index), outch); char_count--; info->icount.tx++; info->x_char = 0; } if (info->breakon || info->breakoff) { if (info->breakon) { cy_writeb((u_long)base_addr + (CyTDR<<index), 0); cy_writeb((u_long)base_addr + (CyTDR<<index), 0x81); info->breakon = 0; char_count -= 2; } if (info->breakoff) { cy_writeb((u_long)base_addr + (CyTDR<<index), 0); cy_writeb((u_long)base_addr + (CyTDR<<index), 0x83); info->breakoff = 0; char_count -= 2; } } while (char_count-- > 0){ if (!info->xmit_cnt){ if (cy_readb(base_addr+(CySRER<<index))&CyTxMpty) { cy_writeb((u_long)base_addr+(CySRER<<index), cy_readb(base_addr+(CySRER<<index)) & ~CyTxMpty); } else { cy_writeb((u_long)base_addr+(CySRER<<index), ((cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy) | CyTxMpty)); } goto txdone; } if (info->xmit_buf == 0){ cy_writeb((u_long)base_addr+(CySRER<<index),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -