All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fbdev: fix the fb_find_nearest_mode() function
@ 2005-10-09  9:29 Michal Januszewski
  2005-10-10  8:21 ` Antonino A. Daplas
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Januszewski @ 2005-10-09  9:29 UTC (permalink / raw)
  To: linux-fbdev-devel

[-- Attachment #1: Type: text/plain, Size: 3897 bytes --]

Currently the fb_find_nearest_mode() function finds a mode with
screen resolution closest to that described by the 'var' argument
and with some arbitrary refresh rate (eg. in the following sequence
of refresh rates: 70 60 53 85 75, 53 is selected).

This patch fixes the function so that it looks for the closest mode as 
far as both resolution and refresh rate are concerned. The function's
first argument is changed to fb_videomode so that the refresh rate can
be specified by the caller, as fb_var_screeninfo doesn't have any fields
that could directly hold this data.

Signed-off-by: Michal Januszewski <spock@gentoo.org>
---

diff -Nurp fbdev-orig/drivers/video/console/fbcon.c fbdev/drivers/video/console/fbcon.c
--- fbdev-orig/drivers/video/console/fbcon.c	2005-10-08 23:14:29.000000000 +0200
+++ fbdev/drivers/video/console/fbcon.c	2005-10-09 01:03:22.000000000 +0200
@@ -2758,7 +2758,7 @@ static void fbcon_new_modelist(struct fb
 			continue;
 		vc = vc_cons[i].d;
 		display_to_var(&var, &fb_display[i]);
-		mode = fb_find_nearest_mode(&var, &info->modelist);
+		mode = fb_find_nearest_mode(fb_display[i].mode, &info->modelist);
 		fb_videomode_to_var(&var, mode);
 
 		if (vc)
diff -Nurp fbdev-orig/drivers/video/modedb.c fbdev/drivers/video/modedb.c
--- fbdev-orig/drivers/video/modedb.c	2005-10-08 23:14:29.000000000 +0200
+++ fbdev/drivers/video/modedb.c	2005-10-09 01:25:16.000000000 +0200
@@ -663,6 +663,7 @@ void fb_var_to_videomode(struct fb_video
 {
 	u32 pixclock, hfreq, htotal, vtotal;
 
+	mode->refresh = 0;
 	mode->name = NULL;
 	mode->xres = var->xres;
 	mode->yres = var->yres;
@@ -785,39 +786,39 @@ struct fb_videomode *fb_find_best_mode(s
 }
 
 /**
- * fb_find_nearest_mode - find mode closest video mode
+ * fb_find_nearest_mode - find closest videomode
  *
- * @var: pointer to struct fb_var_screeninfo
+ * @mode: pointer to struct fb_videomode
  * @head: pointer to modelist
  *
  * Finds best matching videomode, smaller or greater in dimension.
  * If more than 1 videomode is found, will return the videomode with
- * the closest refresh rate
+ * the closest refresh rate.
  */
-struct fb_videomode *fb_find_nearest_mode(struct fb_var_screeninfo *var,
+struct fb_videomode *fb_find_nearest_mode(struct fb_videomode *mode,
 					  struct list_head *head)
 {
 	struct list_head *pos;
 	struct fb_modelist *modelist;
-	struct fb_videomode *mode, *best = NULL;
+	struct fb_videomode *cmode, *best = NULL;
 	u32 diff = -1, diff_refresh = -1;
 
 	list_for_each(pos, head) {
 		u32 d;
 
 		modelist = list_entry(pos, struct fb_modelist, list);
-		mode = &modelist->mode;
+		cmode = &modelist->mode;
 
-		d = abs(mode->xres - var->xres) +
-			abs(mode->yres - var->yres);
+		d = abs(cmode->xres - mode->xres) +
+			abs(cmode->yres - mode->yres);
 		if (diff > d) {
 			diff = d;
-			best = mode;
+			best = cmode;
 		} else if (diff == d) {
-			d = abs(mode->refresh - best->refresh);
+			d = abs(cmode->refresh - mode->refresh);
 			if (diff_refresh > d) {
 				diff_refresh = d;
-				best = mode;
+				best = cmode;
 			}
 		}
 	}
diff -Nurp fbdev-orig/include/linux/fb.h fbdev/include/linux/fb.h
--- fbdev-orig/include/linux/fb.h	2005-10-08 23:14:40.000000000 +0200
+++ fbdev/include/linux/fb.h	2005-10-09 01:03:17.000000000 +0200
@@ -898,7 +898,7 @@ extern struct fb_videomode *fb_match_mod
 					  struct list_head *head);
 extern struct fb_videomode *fb_find_best_mode(struct fb_var_screeninfo *var,
 					      struct list_head *head);
-extern struct fb_videomode *fb_find_nearest_mode(struct fb_var_screeninfo *var,
+extern struct fb_videomode *fb_find_nearest_mode(struct fb_videomode *mode,
 						 struct list_head *head);
 extern void fb_destroy_modelist(struct list_head *head);
 extern void fb_videomode_to_modelist(struct fb_videomode *modedb, int num,


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-10-14 15:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-09  9:29 [PATCH] fbdev: fix the fb_find_nearest_mode() function Michal Januszewski
2005-10-10  8:21 ` Antonino A. Daplas
2005-10-13 19:36   ` Michal Januszewski
2005-10-14  0:18     ` Antonino A. Daplas
2005-10-14 15:04       ` Michal Januszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.