int refresh_rate, search_idx; 
int refresh_rate, search_idx, tidx; 
sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info){	struct sis_video_info *ivideo = (struct sis_video_info *)info->par;	unsigned int htotal = 0, vtotal = 0, myrateindex = 0;	unsigned int drate = 0, hrate = 0, maxyres;	int found_mode = 0;	int refresh_rate, search_idx;	BOOLEAN recalc_clock = FALSE;	u32 pixclock;	htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len;	vtotal = var->upper_margin + var->lower_margin + var->vsync_len;	pixclock = var->pixclock;	if((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED) {		vtotal += var->yres;		vtotal <<= 1;	} else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {		vtotal += var->yres;		vtotal <<= 2;	} else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {		vtotal += var->yres;		vtotal <<= 1;	} else 	vtotal += var->yres;	if(!(htotal) || !(vtotal)) {		SISFAIL("sisfb: no valid timing data");	}	search_idx = 0;	while( (sisbios_mode[search_idx].mode_no[0] != 0) &&	       (sisbios_mode[search_idx].xres <= var->xres) ) {		if( (sisbios_mode[search_idx].xres == var->xres) &&		    (sisbios_mode[search_idx].yres == var->yres) &&		    (sisbios_mode[search_idx].bpp == var->bits_per_pixel)) {		        if(sisfb_validate_mode(ivideo, search_idx, ivideo->currentvbflags) > 0) {			   found_mode = 1;			   break;			}		}		search_idx++;	}	if(!found_mode) {                search_idx = 0;		while(sisbios_mode[search_idx].mode_no[0] != 0) {		   if( (var->xres <= sisbios_mode[search_idx].xres) &&		       (var->yres <= sisbios_mode[search_idx].yres) &&		       (var->bits_per_pixel == sisbios_mode[search_idx].bpp) ) {		          if(sisfb_validate_mode(ivideo,search_idx, ivideo->currentvbflags) > 0) {			     found_mode = 1;			     break;			  }		   }		   search_idx++;	        }		if(found_mode) {			printk(KERN_DEBUG "sisfb: Adapted from %dx%dx%d to %dx%dx%d\n",		   		var->xres, var->yres, var->bits_per_pixel,				sisbios_mode[search_idx].xres,				sisbios_mode[search_idx].yres,				var->bits_per_pixel);			var->xres = sisbios_mode[search_idx].xres;		      	var->yres = sisbios_mode[search_idx].yres;		} else {		   	printk(KERN_ERR "sisfb: Failed to find supported mode near %dx%dx%d\n",				var->xres, var->yres, var->bits_per_pixel);		   	return -EINVAL;		}	}	if( ((ivideo->vbflags & VB_LVDS) ||			/* Slave modes on LVDS and 301B-DH */	     ((ivideo->vbflags & VB_30xBDH) && (ivideo->currentvbflags & CRT2_LCD))) &&	    (var->bits_per_pixel == 8) ) {	    	refresh_rate = 60;		recalc_clock = TRUE;	} else if( (ivideo->current_htotal == htotal) &&	/* x=x & y=y & c=c -> assume depth change */	    	   (ivideo->current_vtotal == vtotal) &&	    	   (ivideo->current_pixclock == pixclock) ) {		drate = 1000000000 / pixclock;	        hrate = (drate * 1000) / htotal;	        refresh_rate = (unsigned int) (hrate * 2 / vtotal);	} else if( ( (ivideo->current_htotal != htotal) ||	/* x!=x | y!=y & c=c -> invalid pixclock */	    	     (ivideo->current_vtotal != vtotal) ) &&	    	   (ivideo->current_pixclock == var->pixclock) ) {		if(ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]]) {			refresh_rate = ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]];		} else if(ivideo->sisfb_parm_rate != -1) {			/* Sic, sisfb_parm_rate - want to know originally desired rate here */			refresh_rate = ivideo->sisfb_parm_rate;		} else {			refresh_rate = 60;		}		recalc_clock = TRUE;	} else if((pixclock) && (htotal) && (vtotal)) {		drate = 1000000000 / pixclock;	   	hrate = (drate * 1000) / htotal;	   	refresh_rate = (unsigned int) (hrate * 2 / vtotal);	} else if(ivideo->current_refresh_rate) {		refresh_rate = ivideo->current_refresh_rate;		recalc_clock = TRUE;	} else {		refresh_rate = 60;		recalc_clock = TRUE;	}	myrateindex = sisfb_search_refresh_rate(ivideo, refresh_rate, search_idx);	/* Eventually recalculate timing and clock */	if(recalc_clock) {	   if(!myrateindex) myrateindex = sisbios_mode[search_idx].rate_idx;	   var->pixclock = (u32) (1000000000 / sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr,	   					&ivideo->sishw_ext,						sisbios_mode[search_idx].mode_no[ivideo->mni],						myrateindex));	   sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr, &ivideo->sishw_ext,		 		    sisbios_mode[search_idx].mode_no[ivideo->mni], myrateindex,	var);	   if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {	      var->pixclock <<= 1;	   }	}	if(ivideo->sisfb_thismonitor.datavalid) {	   if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, search_idx,	                         myrateindex, refresh_rate)) {	      printk(KERN_INFO "sisfb: WARNING: Refresh rate exceeds monitor specs!\n");	   }	}	/* Adapt RGB settings */	sisfb_bpp_to_var(ivideo, var);		/* Sanity check for offsets */	if(var->xoffset < 0) var->xoffset = 0;	if(var->yoffset < 0) var->yoffset = 0;	if(var->xres > var->xres_virtual) {	   var->xres_virtual = var->xres;	}	if(ivideo->sisfb_ypan) {	   maxyres = sisfb_calc_maxyres(ivideo, var);	   if(ivideo->sisfb_max) {	      var->yres_virtual = maxyres;	   } else {	      if(var->yres_virtual > maxyres) {	         var->yres_virtual = maxyres;	      }	   }	   if(var->yres_virtual <= var->yres) {	      var->yres_virtual = var->yres;	   }	} else {	   if(var->yres != var->yres_virtual) {	      var->yres_virtual = var->yres;	   }	   var->xoffset = 0;	   var->yoffset = 0;	}		/* Truncate offsets to maximum if too high */	if(var->xoffset > var->xres_virtual - var->xres) {	   var->xoffset = var->xres_virtual - var->xres - 1;	}	if(var->yoffset > var->yres_virtual - var->yres) {	   var->yoffset = var->yres_virtual - var->yres - 1;	}		/* Set everything else to 0 */	var->red.msb_right = 	var->green.msb_right =	var->blue.msb_right =	var->transp.offset =	var->transp.length =	var->transp.msb_right = 0;	return 0;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/544393fe584d333480659a4bed30f5295355df11/sis_main.c/clean/drivers/video/sis/sis_main.c