cd = NULL; count = 0; max2 = 0; 
cd = NULL; count = 0; max2 = 0; 
static int msp3400c_thread(void *data){	struct i2c_client *client = data;	struct msp3400c *msp = i2c_get_clientdata(client);	struct CARRIER_DETECT *cd;	int count, max1,max2,val1,val2, val,this;	printk("msp3400: kthread started\n");	for (;;) {		d2printk("msp3400: thread: sleep\n");		msp34xx_sleep(msp,-1);		d2printk("msp3400: thread: wakeup\n");	restart:		dprintk("msp3410: thread: restart scan\n");		msp->restart = 0;		if (kthread_should_stop())			break;		if (VIDEO_MODE_RADIO == msp->norm ||		    MSP_MODE_EXTERN  == msp->mode) {			/* no carrier scan, just unmute */			printk("msp3400: thread: no carrier scan\n");			msp3400c_setvolume(client, msp->muted, msp->left, msp->right);			continue;		}		/* mute */		msp3400c_setvolume(client, msp->muted, 0, 0);		msp3400c_setmode(client, MSP_MODE_AM_DETECT /* +1 */ );		val1 = val2 = 0;		max1 = max2 = -1;		msp->watch_stereo = 0;		/* some time for the tuner to sync */		if (msp34xx_sleep(msp,200))			goto restart;		/* carrier detect pass #1 -- main carrier */		cd = carrier_detect_main; count = CARRIER_COUNT(carrier_detect_main);		if (amsound && (msp->norm == VIDEO_MODE_SECAM)) {			/* autodetect doesn't work well with AM ... */			max1 = 3;			count = 0;			dprintk("msp3400: AM sound override\n");		}		for (this = 0; this < count; this++) {			msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);			if (msp34xx_sleep(msp,100))				goto restart;			val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);			if (val > 32767)				val -= 65536;			if (val1 < val)				val1 = val, max1 = this;			dprintk("msp3400: carrier1 val: %5d / %s\n", val,cd[this].name);		}		/* carrier detect pass #2 -- second (stereo) carrier */		switch (max1) {		case 1: /* 5.5 */			cd = carrier_detect_55;			count = CARRIER_COUNT(carrier_detect_55);			break;		case 3: /* 6.5 */			cd = carrier_detect_65;			count = CARRIER_COUNT(carrier_detect_65);			break;		case 0: /* 4.5 */		case 2: /* 6.0 */		default:			cd = NULL; count = 0;			break;		}		if (amsound && (msp->norm == VIDEO_MODE_SECAM)) {			/* autodetect doesn't work well with AM ... */			cd = NULL; count = 0; max2 = 0;		}		for (this = 0; this < count; this++) {			msp3400c_setcarrier(client, cd[this].cdo,cd[this].cdo);			if (msp34xx_sleep(msp,100))				goto restart;			val = msp3400c_read(client, I2C_MSP3400C_DFP, 0x1b);			if (val > 32767)				val -= 65536;			if (val2 < val)				val2 = val, max2 = this;			dprintk("msp3400: carrier2 val: %5d / %s\n", val,cd[this].name);		}		/* programm the msp3400 according to the results */		msp->main   = carrier_detect_main[max1].cdo;		switch (max1) {		case 1: /* 5.5 */			if (max2 == 0) {				/* B/G FM-stereo */				msp->second = carrier_detect_55[max2].cdo;				msp3400c_setmode(client, MSP_MODE_FM_TERRA);				msp->nicam_on = 0;				msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);				msp->watch_stereo = 1;			} else if (max2 == 1 && HAVE_NICAM(msp)) {				/* B/G NICAM */				msp->second = carrier_detect_55[max2].cdo;				msp3400c_setmode(client, MSP_MODE_FM_NICAM1);				msp->nicam_on = 1;				msp3400c_setcarrier(client, msp->second, msp->main);				msp->watch_stereo = 1;			} else {				goto no_second;			}			break;		case 2: /* 6.0 */			/* PAL I NICAM */			msp->second = MSP_CARRIER(6.552);			msp3400c_setmode(client, MSP_MODE_FM_NICAM2);			msp->nicam_on = 1;			msp3400c_setcarrier(client, msp->second, msp->main);			msp->watch_stereo = 1;			break;		case 3: /* 6.5 */			if (max2 == 1 || max2 == 2) {				/* D/K FM-stereo */				msp->second = carrier_detect_65[max2].cdo;				msp3400c_setmode(client, MSP_MODE_FM_TERRA);				msp->nicam_on = 0;				msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);				msp->watch_stereo = 1;			} else if (max2 == 0 &&				   msp->norm == VIDEO_MODE_SECAM) {				/* L NICAM or AM-mono */				msp->second = carrier_detect_65[max2].cdo;				msp3400c_setmode(client, MSP_MODE_AM_NICAM);				msp->nicam_on = 0;				msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);				msp3400c_setcarrier(client, msp->second, msp->main);				/* volume prescale for SCART (AM mono input) */				msp3400c_write(client,I2C_MSP3400C_DFP, 0x000d, 0x1900);				msp->watch_stereo = 1;			} else if (max2 == 0 && HAVE_NICAM(msp)) {				/* D/K NICAM */				msp->second = carrier_detect_65[max2].cdo;				msp3400c_setmode(client, MSP_MODE_FM_NICAM1);				msp->nicam_on = 1;				msp3400c_setcarrier(client, msp->second, msp->main);				msp->watch_stereo = 1;			} else {				goto no_second;			}			break;		case 0: /* 4.5 */		default:		no_second:			msp->second = carrier_detect_main[max1].cdo;			msp3400c_setmode(client, MSP_MODE_FM_TERRA);			msp->nicam_on = 0;			msp3400c_setcarrier(client, msp->second, msp->main);			msp->rxsubchans = V4L2_TUNER_SUB_MONO;			msp3400c_setstereo(client, V4L2_TUNER_MODE_MONO);			break;		}		/* unmute */		msp3400c_setvolume(client, msp->muted, msp->left, msp->right);		if (debug)			msp3400c_print_mode(msp);		/* monitor tv audio mode */		while (msp->watch_stereo) {			if (msp34xx_sleep(msp,5000))				goto restart;			watch_stereo(client);		}	}	dprintk("msp3400: thread: exit\n");	return 0;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/18f47d10bc8076bb126a1a369b782e29cc91c824/msp3400.c/buggy/drivers/media/video/msp3400.c