LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] fbdev: find mode with highest refresh rate in fb_find_mode()
@ 2007-07-18  8:41 Michal Januszewski
  2007-07-18 14:38 ` Ondrej Zajicek
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Januszewski @ 2007-07-18  8:41 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: linux-kernel

Currently if the refresh rate is not specified fb_find_mode() returns
the first known video mode with the requested resoluion, which provides
no guarantees wrt the refresh rate.  Change this so that the mode with
the highest refresh rate is returned instead.

Signed-off-by: Michal Januszewski <spock@gentoo.org>
---
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 3741ad7..f70143a 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -606,26 +606,29 @@ done:
 	DPRINTK("Trying specified video mode%s %ix%i\n",
 	    refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
 
-	diff = refresh;
+	if (!refresh_specified)
+		diff = 0
+	else
+		diff = refresh;
+
 	best = -1;
 	for (i = 0; i < dbsize; i++) {
-		if (name_matches(db[i], name, namelen) ||
-		    (res_specified && res_matches(db[i], xres, yres))) {
-			if(!fb_try_mode(var, info, &db[i], bpp)) {
-				if(!refresh_specified || db[i].refresh == refresh)
-					return 1;
-				else {
-					if(diff > abs(db[i].refresh - refresh)) {
-						diff = abs(db[i].refresh - refresh);
-						best = i;
-					}
+		if ((name_matches(db[i], name, namelen) ||
+		    (res_specified && res_matches(db[i], xres, yres))) &&
+		    !fb_try_mode(var, info, &db[i], bpp)) {
+			if (refresh_specified && db[i].refresh == refresh) {
+				return 1;
+			} else {
+				if (diff < db[i].refresh) {
+					diff = db[i].refresh;
+					best = i;
 				}
 			}
 		}
 	}
 	if (best != -1) {
 		fb_try_mode(var, info, &db[best], bpp);
-		return 2;
+		return (refresh_specified) ? 2 : 1;
 	}
 
 	diff = xres + yres;



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

* Re: [PATCH] fbdev: find mode with highest refresh rate in fb_find_mode()
  2007-07-18  8:41 [PATCH] fbdev: find mode with highest refresh rate in fb_find_mode() Michal Januszewski
@ 2007-07-18 14:38 ` Ondrej Zajicek
  2007-07-18 15:18   ` [Linux-fbdev-devel] " Antonino A. Daplas
  0 siblings, 1 reply; 6+ messages in thread
From: Ondrej Zajicek @ 2007-07-18 14:38 UTC (permalink / raw)
  To: Michal Januszewski; +Cc: linux-fbdev-devel, linux-kernel

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

On Wed, Jul 18, 2007 at 10:41:02AM +0200, Michal Januszewski wrote:
> Currently if the refresh rate is not specified fb_find_mode() returns
> the first known video mode with the requested resoluion, which provides
> no guarantees wrt the refresh rate.  Change this so that the mode with
> the highest refresh rate is returned instead.

What refresh rate it sets when used on card or monitor without DDC?

-- 
Elen sila lumenn' omentielvo

Ondrej 'SanTiago' Zajicek (email: santiago@crfreenet.org, jabber: santiago@njs.netlab.cz)
OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
"To err is human -- to blame it on a computer is even more so."

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

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

* Re: [Linux-fbdev-devel] [PATCH] fbdev: find mode with highest refresh rate in fb_find_mode()
  2007-07-18 14:38 ` Ondrej Zajicek
@ 2007-07-18 15:18   ` Antonino A. Daplas
  2007-08-26 19:09     ` Michal Januszewski
  0 siblings, 1 reply; 6+ messages in thread
From: Antonino A. Daplas @ 2007-07-18 15:18 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: Michal Januszewski, linux-kernel, Ondrej Zajicek

On Wed, 2007-07-18 at 16:38 +0200, Ondrej Zajicek wrote:
> On Wed, Jul 18, 2007 at 10:41:02AM +0200, Michal Januszewski wrote:
> > Currently if the refresh rate is not specified fb_find_mode() returns
> > the first known video mode with the requested resoluion, which provides
> > no guarantees wrt the refresh rate.  Change this so that the mode with
> > the highest refresh rate is returned instead.
> 
> What refresh rate it sets when used on card or monitor without DDC?

Yes, I noted this also while reviewing patches.  fb_find_mode() is used
predominantly with the 'generic' modedb which contains modes that are
not specific to the card or monitor.  And fb_try_mode() is not a
guarantee that the returned refresh rate will be safe (we have a lot of
drivers that do not check the timings against the display capabilities).

It would be best that fb_find_mode() return the safest refresh rate
(60Hz) instead of the highest.

Tony


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

* Re: [Linux-fbdev-devel] [PATCH] fbdev: find mode with highest refresh rate in fb_find_mode()
  2007-07-18 15:18   ` [Linux-fbdev-devel] " Antonino A. Daplas
@ 2007-08-26 19:09     ` Michal Januszewski
  2007-08-26 22:49       ` Antonino A. Daplas
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Januszewski @ 2007-08-26 19:09 UTC (permalink / raw)
  To: Antonino A. Daplas; +Cc: linux-fbdev-devel, linux-kernel, Ondrej Zajicek

On Wed, Jul 18, 2007 at 11:18:15PM +0800, Antonino A. Daplas wrote:

> > > Currently if the refresh rate is not specified fb_find_mode() returns
> > > the first known video mode with the requested resoluion, which provides
> > > no guarantees wrt the refresh rate.  Change this so that the mode with
> > > the highest refresh rate is returned instead.
> > 
> > What refresh rate it sets when used on card or monitor without DDC?
>
> Yes, I noted this also while reviewing patches.  fb_find_mode() is used
> predominantly with the 'generic' modedb which contains modes that are
> not specific to the card or monitor.  And fb_try_mode() is not a
> guarantee that the returned refresh rate will be safe (we have a lot of
> drivers that do not check the timings against the display capabilities).
> 
> It would be best that fb_find_mode() return the safest refresh rate
> (60Hz) instead of the highest.

How about modifying it so that it looks for a mode with the highest
refresh rate if either a non-generic modedb is used or
info.monspecs.{vfmin,vfmax,hfmin,hfmax,dclkmax} are all non-zero,
and for a mode with refresh rate closest to 60 Hz otherwise?

I'm sorry for the delayed reply.

Best regards.
-- 
Michal Januszewski                              JID: spock@im.gentoo.org
Gentoo Linux Developer                    http://people.gentoo.org/spock


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

* Re: [Linux-fbdev-devel] [PATCH] fbdev: find mode with highest refresh rate in fb_find_mode()
  2007-08-26 19:09     ` Michal Januszewski
@ 2007-08-26 22:49       ` Antonino A. Daplas
  2007-08-29 22:41         ` [PATCH] fbdev: find mode with the highest/safest " Michal Januszewski
  0 siblings, 1 reply; 6+ messages in thread
From: Antonino A. Daplas @ 2007-08-26 22:49 UTC (permalink / raw)
  To: spock; +Cc: linux-fbdev-devel, linux-kernel, Ondrej Zajicek

On Sun, 2007-08-26 at 21:09 +0200, Michal Januszewski wrote:
> On Wed, Jul 18, 2007 at 11:18:15PM +0800, Antonino A. Daplas wrote:
> 
> How about modifying it so that it looks for a mode with the highest
> refresh rate if either a non-generic modedb is used or
> info.monspecs.{vfmin,vfmax,hfmin,hfmax,dclkmax} are all non-zero,
> and for a mode with refresh rate closest to 60 Hz otherwise?

I would opt for combining the two, return the highest refresh rate only
if the modedb was built by the driver and with the mode checked against
the display's operating limits.

Tony



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

* [PATCH] fbdev: find mode with the highest/safest refresh rate in fb_find_mode()
  2007-08-26 22:49       ` Antonino A. Daplas
@ 2007-08-29 22:41         ` Michal Januszewski
  0 siblings, 0 replies; 6+ messages in thread
From: Michal Januszewski @ 2007-08-29 22:41 UTC (permalink / raw)
  To: Antonino A. Daplas; +Cc: linux-fbdev-devel, linux-kernel, Ondrej Zajicek

Currently, if the refresh rate is not specified, fb_find_mode() returns
the first known video mode with the requested resolution, which provides
no guarantees wrt the refresh rate.  Change this so that the mode with
the highest refresh rate is returned when the driver provides a custom
video mode database and the monitor limits, and a mode with the safe
60 Hz refresh rate otherwise.

Signed-off-by: Michal Januszewski <spock@gentoo.org>
---
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 3741ad7..9598c46 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -606,26 +606,43 @@ done:
 	DPRINTK("Trying specified video mode%s %ix%i\n",
 	    refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
 
-	diff = refresh;
+	if (!refresh_specified) {
+		/*
+		 * If the caller has provided a custom mode database and a
+		 * valid monspecs structure, we look for the mode with the
+		 * highest refresh rate.  Otherwise we play it safe it and
+		 * try to find a mode with a refresh rate closest to the
+		 * standard 60 Hz.
+		 */
+		if (db != modedb &&
+		    info->monspecs.vfmin && info->monspecs.vfmax &&
+		    info->monspecs.hfmin && info->monspecs.hfmax &&
+		    info->monspecs.dclkmax) {
+			refresh = 1000;
+		} else {
+			refresh = 60;
+		}
+	}
+
+	diff = -1;
 	best = -1;
 	for (i = 0; i < dbsize; i++) {
-		if (name_matches(db[i], name, namelen) ||
-		    (res_specified && res_matches(db[i], xres, yres))) {
-			if(!fb_try_mode(var, info, &db[i], bpp)) {
-				if(!refresh_specified || db[i].refresh == refresh)
-					return 1;
-				else {
-					if(diff > abs(db[i].refresh - refresh)) {
-						diff = abs(db[i].refresh - refresh);
-						best = i;
-					}
+		if ((name_matches(db[i], name, namelen) ||
+		    (res_specified && res_matches(db[i], xres, yres))) &&
+		    !fb_try_mode(var, info, &db[i], bpp)) {
+			if (refresh_specified && db[i].refresh == refresh) {
+				return 1;
+			} else {
+				if (abs(db[i].refresh - refresh) < diff) {
+					diff = abs(db[i].refresh - refresh);
+					best = i;
 				}
 			}
 		}
 	}
 	if (best != -1) {
 		fb_try_mode(var, info, &db[best], bpp);
-		return 2;
+		return (refresh_specified) ? 2 : 1;
 	}
 
 	diff = xres + yres;


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

end of thread, other threads:[~2007-08-29 22:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-18  8:41 [PATCH] fbdev: find mode with highest refresh rate in fb_find_mode() Michal Januszewski
2007-07-18 14:38 ` Ondrej Zajicek
2007-07-18 15:18   ` [Linux-fbdev-devel] " Antonino A. Daplas
2007-08-26 19:09     ` Michal Januszewski
2007-08-26 22:49       ` Antonino A. Daplas
2007-08-29 22:41         ` [PATCH] fbdev: find mode with the highest/safest " Michal Januszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).