/* RETURNS: Vertical refresh rate. It will be the result of actual value plus 0.5. If it is 70.288, it will return 70Hz. If it is 59.6, it will return 60Hz.  */
int drm_mode_vrefresh(struct drm_display_mode *mode)
/* RETURNS: Vertical refresh rate. It will be the result of actual value plus 0.5. If it is 70.288, it will return 70Hz. If it is 59.6, it will return 60Hz.  */
int drm_mode_vrefresh(struct drm_display_mode *mode)
{
	int refresh = 0;
	unsigned int calc_val;
	if (mode->vrefresh > 0)
		refresh = mode->vrefresh;
	else if (mode->htotal > 0 && mode->vtotal > 0) {
		int vtotal;
		vtotal = mode->vtotal;
		calc_val = (mode->clock * 1000);
		calc_val /= mode->htotal;
		refresh = (calc_val + vtotal / 2) / vtotal;
		if (mode->flags & DRM_MODE_FLAG_INTERLACE)
			refresh *= 2;
		if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
			refresh /= 2;
		if (mode->vscan > 1)
			refresh /= mode->vscan;
	}
	return refresh;
}