jif = jiffies + (hertz / 10); while (time_before(jiffies, jif)) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(1); } 
msleep(100); 
static int ixj_selfprobe(IXJ *j){	unsigned short cmd;	unsigned long jif;	int cnt;	BYTES bytes;        init_waitqueue_head(&j->poll_q);        init_waitqueue_head(&j->read_q);        init_waitqueue_head(&j->write_q);	while(atomic_read(&j->DSPWrite) > 0)		atomic_dec(&j->DSPWrite);	if (ixjdebug & 0x0002)		printk(KERN_INFO "Write IDLE to Software Control Register\n");	ixj_WriteDSPCommand(0x0FE0, j);	/* Put the DSP in full power mode. */	if (ixj_WriteDSPCommand(0x0000, j))		/* Write IDLE to Software Control Register */		return -1;/* The read values of the SSR should be 0x00 for the IDLE command */	if (j->ssr.low || j->ssr.high)		return -1;	if (ixjdebug & 0x0002)		printk(KERN_INFO "Get Device ID Code\n");	if (ixj_WriteDSPCommand(0x3400, j))		/* Get Device ID Code */		return -1;	j->dsp.low = j->ssr.low;	j->dsp.high = j->ssr.high;	if (ixjdebug & 0x0002)		printk(KERN_INFO "Get Device Version Code\n");	if (ixj_WriteDSPCommand(0x3800, j))		/* Get Device Version Code */		return -1;	j->ver.low = j->ssr.low;	j->ver.high = j->ssr.high;	if (!j->cardtype) {		if (j->dsp.low == 0x21) {			bytes.high = bytes.low = inb_p(j->XILINXbase + 0x02);			outb_p(bytes.low ^ 0xFF, j->XILINXbase + 0x02);/* Test for Internet LineJACK or Internet PhoneJACK Lite */			bytes.low = inb_p(j->XILINXbase + 0x02);			if (bytes.low == bytes.high)	/*  Register is read only on */				/*  Internet PhoneJack Lite */			 {				j->cardtype = QTI_PHONEJACK_LITE;				if (!request_region(j->XILINXbase, 4, "ixj control")) {					printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);					return -1;				}				j->pld_slicw.pcib.e1 = 1;				outb_p(j->pld_slicw.byte, j->XILINXbase);			} else {				j->cardtype = QTI_LINEJACK;				if (!request_region(j->XILINXbase, 8, "ixj control")) {					printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);					return -1;				}			}		} else if (j->dsp.low == 0x22) {			j->cardtype = QTI_PHONEJACK_PCI;			request_region(j->XILINXbase, 4, "ixj control");			j->pld_slicw.pcib.e1 = 1;			outb_p(j->pld_slicw.byte, j->XILINXbase);		} else			j->cardtype = QTI_PHONEJACK;	} else {		switch (j->cardtype) {		case QTI_PHONEJACK:			if (!j->dsp.low != 0x20) {				j->dsp.high = 0x80;				j->dsp.low = 0x20;				ixj_WriteDSPCommand(0x3800, j);				j->ver.low = j->ssr.low;				j->ver.high = j->ssr.high;			}			break;		case QTI_LINEJACK:			if (!request_region(j->XILINXbase, 8, "ixj control")) {				printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);				return -1;			}			break;		case QTI_PHONEJACK_LITE:		case QTI_PHONEJACK_PCI:			if (!request_region(j->XILINXbase, 4, "ixj control")) {				printk(KERN_INFO "ixj: can't get I/O address 0x%x\n", j->XILINXbase);				return -1;			}			j->pld_slicw.pcib.e1 = 1;			outb_p(j->pld_slicw.byte, j->XILINXbase);			break;		case QTI_PHONECARD:			break;		}	}	if (j->dsp.low == 0x20 || j->cardtype == QTI_PHONEJACK_LITE || j->cardtype == QTI_PHONEJACK_PCI) {		if (ixjdebug & 0x0002)			printk(KERN_INFO "Write CODEC config to Software Control Register\n");		if (ixj_WriteDSPCommand(0xC462, j))		/* Write CODEC config to Software Control Register */			return -1;		if (ixjdebug & 0x0002)			printk(KERN_INFO "Write CODEC timing to Software Control Register\n");		if (j->cardtype == QTI_PHONEJACK) {			cmd = 0x9FF2;		} else {			cmd = 0x9FF5;		}		if (ixj_WriteDSPCommand(cmd, j))	/* Write CODEC timing to Software Control Register */			return -1;	} else {		if (set_base_frame(j, 30) != 30)			return -1;		if (ixjdebug & 0x0002)			printk(KERN_INFO "Write CODEC config to Software Control Register\n");		if (j->cardtype == QTI_PHONECARD) {			if (ixj_WriteDSPCommand(0xC528, j))		/* Write CODEC config to Software Control Register */				return -1;		}		if (j->cardtype == QTI_LINEJACK) {			if (ixj_WriteDSPCommand(0xC528, j))		/* Write CODEC config to Software Control Register */				return -1;			if (ixjdebug & 0x0002)				printk(KERN_INFO "Turn on the PLD Clock at 8Khz\n");			j->pld_clock.byte = 0;			outb_p(j->pld_clock.byte, j->XILINXbase + 0x04);		}	}	if (j->dsp.low == 0x20) {		if (ixjdebug & 0x0002)			printk(KERN_INFO "Configure GPIO pins\n");		j->gpio.bytes.high = 0x09;/*  bytes.low = 0xEF;  0xF7 */		j->gpio.bits.gpio1 = 1;		j->gpio.bits.gpio2 = 1;		j->gpio.bits.gpio3 = 0;		j->gpio.bits.gpio4 = 1;		j->gpio.bits.gpio5 = 1;		j->gpio.bits.gpio6 = 1;		j->gpio.bits.gpio7 = 1;		ixj_WriteDSPCommand(j->gpio.word, j);	/* Set GPIO pin directions */		if (ixjdebug & 0x0002)			printk(KERN_INFO "Enable SLIC\n");		j->gpio.bytes.high = 0x0B;		j->gpio.bytes.low = 0x00;		j->gpio.bits.gpio1 = 0;		j->gpio.bits.gpio2 = 1;		j->gpio.bits.gpio5 = 0;		ixj_WriteDSPCommand(j->gpio.word, j);	/* send the ring stop signal */		j->port = PORT_POTS;	} else {		if (j->cardtype == QTI_LINEJACK) {			LED_SetState(0x1, j);			jif = jiffies + (hertz / 10);			while (time_before(jiffies, jif)) {				set_current_state(TASK_INTERRUPTIBLE);				schedule_timeout(1);			}			LED_SetState(0x2, j);			jif = jiffies + (hertz / 10);			while (time_before(jiffies, jif)) {				set_current_state(TASK_INTERRUPTIBLE);				schedule_timeout(1);			}			LED_SetState(0x4, j);			jif = jiffies + (hertz / 10);			while (time_before(jiffies, jif)) {				set_current_state(TASK_INTERRUPTIBLE);				schedule_timeout(1);			}			LED_SetState(0x8, j);			jif = jiffies + (hertz / 10);			while (time_before(jiffies, jif)) {				set_current_state(TASK_INTERRUPTIBLE);				schedule_timeout(1);			}			LED_SetState(0x0, j);			daa_get_version(j);			if (ixjdebug & 0x0002)				printk("Loading DAA Coefficients\n");			DAA_Coeff_US(j);			if (!ixj_daa_write(j)) {				printk("DAA write failed on board %d\n", j->board);				return -1;			}			if(!ixj_daa_cid_reset(j)) {				printk("DAA CID reset failed on board %d\n", j->board);				return -1;			}			j->flags.pots_correct = 0;			j->flags.pstn_present = 0;			ixj_linetest(j);			if (j->flags.pots_correct) {				j->pld_scrw.bits.daafsyncen = 0;	/* Turn off DAA Frame Sync */				outb_p(j->pld_scrw.byte, j->XILINXbase);				j->pld_slicw.bits.rly1 = 1;				j->pld_slicw.bits.spken = 1;				outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);				SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);/*				SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */				j->port = PORT_POTS;			}			ixj_set_port(j, PORT_PSTN);			ixj_set_pots(j, 1);			if (ixjdebug & 0x0002)				printk(KERN_INFO "Enable Mixer\n");			ixj_mixer(0x0000, j);	/*Master Volume Left unmute 0db */			ixj_mixer(0x0100, j);	/*Master Volume Right unmute 0db */			ixj_mixer(0x0203, j);	/*Voice Left Volume unmute 6db */			ixj_mixer(0x0303, j);	/*Voice Right Volume unmute 6db */			ixj_mixer(0x0480, j);	/*FM Left mute */			ixj_mixer(0x0580, j);	/*FM Right mute */			ixj_mixer(0x0680, j);	/*CD Left mute */			ixj_mixer(0x0780, j);	/*CD Right mute */			ixj_mixer(0x0880, j);	/*Line Left mute */			ixj_mixer(0x0980, j);	/*Line Right mute */			ixj_mixer(0x0A80, j);	/*Aux left mute  */			ixj_mixer(0x0B80, j);	/*Aux right mute */			ixj_mixer(0x0C00, j);	/*Mono1 unmute 12db */			ixj_mixer(0x0D80, j);	/*Mono2 mute */			ixj_mixer(0x0E80, j);	/*Mic mute */			ixj_mixer(0x0F00, j);	/*Mono Out Volume unmute 0db */			ixj_mixer(0x1000, j);	/*Voice Left and Right out only */			ixj_mixer(0x110C, j);			ixj_mixer(0x1200, j);	/*Mono1 switch on mixer left */			ixj_mixer(0x1401, j);			ixj_mixer(0x1300, j);       /*Mono1 switch on mixer right */			ixj_mixer(0x1501, j);			ixj_mixer(0x1700, j);	/*Clock select */			ixj_mixer(0x1800, j);	/*ADC input from mixer */			ixj_mixer(0x1901, j);	/*Mic gain 30db */			if (ixjdebug & 0x0002)				printk(KERN_INFO "Setting Default US Ring Cadence Detection\n");			j->cadence_f[4].state = 0;			j->cadence_f[4].on1 = 0;	/*Cadence Filter 4 is used for PSTN ring cadence */			j->cadence_f[4].off1 = 0;			j->cadence_f[4].on2 = 0;			j->cadence_f[4].off2 = 0;			j->cadence_f[4].on3 = 0;			j->cadence_f[4].off3 = 0;	/* These should represent standard US ring pulse. */			j->pstn_last_rmr = jiffies;		} else {			if (j->cardtype == QTI_PHONECARD) {				ixj_WriteDSPCommand(0xCF07, j);				ixj_WriteDSPCommand(0x00B0, j);				ixj_set_port(j, PORT_SPEAKER);			} else {				ixj_set_port(j, PORT_POTS);				SLIC_SetState(PLD_SLIC_STATE_STANDBY, j);/*				SLIC_SetState(PLD_SLIC_STATE_ACTIVE, j); */			}		}	}	j->intercom = -1;	j->framesread = j->frameswritten = 0;	j->read_wait = j->write_wait = 0;	j->rxreadycheck = j->txreadycheck = 0;	/* initialise the DTMF prescale to a sensible value */	if (j->cardtype == QTI_LINEJACK) {		set_dtmf_prescale(j, 0x10); 	} else {		set_dtmf_prescale(j, 0x40); 	}	set_play_volume(j, 0x100);	set_rec_volume(j, 0x100);	if (ixj_WriteDSPCommand(0x0000, j))		/* Write IDLE to Software Control Register */		return -1;/* The read values of the SSR should be 0x00 for the IDLE command */	if (j->ssr.low || j->ssr.high)		return -1;	if (ixjdebug & 0x0002)		printk(KERN_INFO "Enable Line Monitor\n");	if (ixjdebug & 0x0002)		printk(KERN_INFO "Set Line Monitor to Asyncronous Mode\n");	if (ixj_WriteDSPCommand(0x7E01, j))		/* Asynchronous Line Monitor */		return -1;	if (ixjdebug & 0x002)		printk(KERN_INFO "Enable DTMF Detectors\n");	if (ixj_WriteDSPCommand(0x5151, j))		/* Enable DTMF detection */		return -1;	if (ixj_WriteDSPCommand(0x6E01, j))		/* Set Asyncronous Tone Generation */		return -1;	set_rec_depth(j, 2);	/* Set Record Channel Limit to 2 frames */	set_play_depth(j, 2);	/* Set Playback Channel Limit to 2 frames */	j->ex.bits.dtmf_ready = 0;	j->dtmf_state = 0;	j->dtmf_wp = j->dtmf_rp = 0;	j->rec_mode = j->play_mode = -1;	j->flags.ringing = 0;	j->maxrings = MAXRINGS;	j->ring_cadence = USA_RING_CADENCE;	j->drybuffer = 0;	j->winktime = 320;	j->flags.dtmf_oob = 0;	for (cnt = 0; cnt < 4; cnt++)		j->cadence_f[cnt].enable = 0;	/* must be a device on the specified address */	ixj_WriteDSPCommand(0x0FE3, j);	/* Put the DSP in 1/5 power mode. */	/* Set up the default signals for events */	for (cnt = 0; cnt < 35; cnt++)		j->ixj_signals[cnt] = SIGIO;	/* Set the excetion signal enable flags */	j->ex_sig.bits.dtmf_ready = j->ex_sig.bits.hookstate = j->ex_sig.bits.flash = j->ex_sig.bits.pstn_ring = 	j->ex_sig.bits.caller_id = j->ex_sig.bits.pstn_wink = j->ex_sig.bits.f0 = j->ex_sig.bits.f1 = j->ex_sig.bits.f2 = 	j->ex_sig.bits.f3 = j->ex_sig.bits.fc0 = j->ex_sig.bits.fc1 = j->ex_sig.bits.fc2 = j->ex_sig.bits.fc3 = 1;#ifdef IXJ_DYN_ALLOC	j->fskdata = NULL;#endif	j->fskdcnt = 0;	j->cidcw_wait = 0; 	/* Register with the Telephony for Linux subsystem */	j->p.f_op = &ixj_fops;	j->p.open = ixj_open;	j->p.board = j->board;	phone_register_device(&j->p, PHONE_UNIT_ANY);	ixj_init_timer(j);	ixj_add_timer(j);	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/f4c9925ccc185da68c2d42230711d017f222e420/ixj.c/buggy/drivers/telephony/ixj.c