Skip to contentSkip to conversation

fbdev: make fb_find_mode look for a mode with the highest refresh rate

PATCH In review Michal Januszewski 3 participants 5 messages Jun 23, 2007 – Jul 12, 2007 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 fbdev: make fb_find_mode look for a mode with the highest refresh rate

If the refresh rate hasn't been explicitly specified, fd_find_mode currently returns the first mode with the requested resolution. Change it so that it returns a mode with the requested resolution and the highest refresh rate.

Also export fb_destroy_modelist, which is used in uvesafb.

---
drivers/video/modedb.c | 7 +++++--

 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/video/modedb.c +5 -2
index 3741ad7..98ee77b 100644
@@ -606,16 +606,18 @@ done:
 	DPRINTK("Trying specified video mode%s %ix%i\n",
 	    refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
 
+	if (!refresh_specified)
+		refresh = 200;
 	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)
+				if (refresh_specified && db[i].refresh == refresh)
 					return 1;
 				else {
-					if(diff > abs(db[i].refresh - refresh)) {
+					if (diff > abs(db[i].refresh - refresh)) {
 						diff = abs(db[i].refresh - refresh);
 						best = i;
 					}
@@ -938,6 +940,7 @@ void fb_destroy_modelist(struct list_head *head)
 		kfree(pos);
 	}
 }
+EXPORT_SYMBOL_GPL(fb_destroy_modelist);
 
 /**
  * fb_videomode_to_modelist: convert mode array to mode list

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

#1 lore raw
Quoted 38 lines · On Sat, 23 Jun 2007 12:50:46 +0200 Michal Januszewski <[email protected]> wrote:

If the refresh rate hasn't been explicitly specified, fd_find_mode currently returns the first mode with the requested resolution. Change it so that it returns a mode with the requested resolution and the highest refresh rate.

Also export fb_destroy_modelist, which is used in uvesafb.

---
drivers/video/modedb.c | 7 +++++--

 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/video/modedb.c +4 -2
index 3741ad7..98ee77b 100644
@@ -606,16 +606,18 @@ done:
 	DPRINTK("Trying specified video mode%s %ix%i\n",
 	    refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
 
+	if (!refresh_specified)
+		refresh = 200;
 	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)
+				if (refresh_specified && db[i].refresh == refresh)
 					return 1;
 				else {
-					if(diff > abs(db[i].refresh - refresh)) {
+					if (diff > abs(db[i].refresh - refresh)) {
 						diff = abs(db[i].refresh - refresh);
 						best = i;
 					}

drivers/video/modedb.c void fb_destroy_modelist(struct list_head *head) · line 944

Quoted 5 lines
drivers/video/modedb.c +1 -0
@@ -938,6 +940,7 @@ void fb_destroy_modelist(struct list_head *head)
 		kfree(pos);
 	}
 }
+EXPORT_SYMBOL_GPL(fb_destroy_modelist);
 

fbdev ignoramus asks: isn't this pretty risky? People who were previously relying upon (or at least using) the kernel's default resolution will find their displays coming up in a quite different resolution.

This change seems to be quite unrelated to the uvesafb stuff and should be in a separate patch from the export, which _is_ uvesafb-related. I think. If that's wrong then the changelog could do with some attention.

#2 lore raw
Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Sat, 23 Jun 2007 12:50:46 +0200 Michal Januszewski <[email protected]> wrote:
drivers/video/modedb.c +4 -2
+	if (!refresh_specified)
+		refresh = 200;
 	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)
+				if (refresh_specified && db[i].refresh == refresh)
 					return 1;
 				else {
-					if(diff > abs(db[i].refresh - refresh)) {
+					if (diff > abs(db[i].refresh - refresh)) {
 						diff = abs(db[i].refresh - refresh);
 						best = i;
 					}
@@ -938,6 +940,7 @@ void fb_destroy_modelist(struct list_head *head)
 		kfree(pos);
Quoted 8 lines

drivers/video/modedb.c void fb_destroy_modelist(struct list_head *head) · line 944

Quoted 4 lines
drivers/video/modedb.c +1 -0
 	}
 }
+EXPORT_SYMBOL_GPL(fb_destroy_modelist);
 

fbdev ignoramus asks: isn't this pretty risky? People who were previously relying upon (or at least using) the kernel's default resolution will find their displays coming up in a quite different resolution.

The resolution will be unchanged (this part of the code is only executed if either the name of the mode or the resolution are a match).

What can change is the refresh rate -- it can be set higher than what it used to be before. But since we're checking all modes with fb_try_mode(), (which calls fb_check_var()), I think that this change should be safe.

To avoid any side effects we could also do the following:

	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 (best != -1) {
		fb_try_mode(var, info, &db[best], bpp);
-		return 2;
+ 		return (refresh_specified) ? 2 : 1;
	}

which would ensure that 1 is returned if the refresh rate is not explicitly specified, just as it is done currently:

				if(!refresh_specified || db[i].refresh == refresh)
					return 1

I might be missing something here, so it would be nice if someone involved in the fb development could comment on the proposed change.

Quoted 3 lines

This change seems to be quite unrelated to the uvesafb stuff and should be in a separate patch from the export, which _is_ uvesafb-related. I think. If that's wrong then the changelog could do with some attention.

You're right, I'll split this into two patches in the next round.

Best regards,
Michal

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

#3 lore raw
In reply to Andrew Morton
Quoted 41 lines · Andrew Morton
Quoted 39 lines · On Sat, 23 Jun 2007 12:50:46 +0200 Michal Januszewski <[email protected]> wrote:

If the refresh rate hasn't been explicitly specified, fd_find_mode currently returns the first mode with the requested resolution. Change it so that it returns a mode with the requested resolution and the highest refresh rate.

Also export fb_destroy_modelist, which is used in uvesafb.

---
drivers/video/modedb.c | 7 +++++--

 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/video/modedb.c +4 -2
index 3741ad7..98ee77b 100644
@@ -606,16 +606,18 @@ done:
 	DPRINTK("Trying specified video mode%s %ix%i\n",
 	    refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
 
+	if (!refresh_specified)
+		refresh = 200;
 	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)
+				if (refresh_specified && db[i].refresh == refresh)
 					return 1;
 				else {
-					if(diff > abs(db[i].refresh - refresh)) {
+					if (diff > abs(db[i].refresh - refresh)) {
 						diff = abs(db[i].refresh - refresh);
 						best = i;
 					}
@@ -938,6 +940,7 @@ void fb_destroy_modelist(struct list_head *head)
 		kfree(pos);
Quoted 8 lines

drivers/video/modedb.c void fb_destroy_modelist(struct list_head *head) · line 944

Quoted 4 lines
drivers/video/modedb.c +1 -0
 	}
 }
+EXPORT_SYMBOL_GPL(fb_destroy_modelist);
 

fbdev ignoramus asks: isn't this pretty risky? People who were previously relying upon (or at least using) the kernel's default resolution will find their displays coming up in a quite different resolution.

It's only the refresh rate that will change. The current behavior is that a user can get near random results in terms of the vertical refresh rates. At least with this patch, we know what we get.

Quoted 5 lines

This change seems to be quite unrelated to the uvesafb stuff and should be in a separate patch from the export, which _is_ uvesafb-related. I think. If that's wrong then the changelog could do with some attention.

Tony

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

#4 lore raw
In reply to Michal Januszewski
Quoted 17 lines · Michal Januszewski

If the refresh rate hasn't been explicitly specified, fd_find_mode currently returns the first mode with the requested resolution. Change it so that it returns a mode with the requested resolution and the highest refresh rate.

Also export fb_destroy_modelist, which is used in uvesafb.

---
drivers/video/modedb.c | 7 +++++--

 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/video/modedb.c +0 -0
index 3741ad7..98ee77b 100644

drivers/video/modedb.c done: · line 611

Quoted 6 lines
drivers/video/modedb.c +2 -0
@@ -606,16 +606,18 @@ done:
 	DPRINTK("Trying specified video mode%s %ix%i\n",
 	    refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
 
+	if (!refresh_specified)
+		refresh = 200;
 	diff = refresh;

How about..?

	if (!refresh_specified)
		diff = 0;
	else
		diff = refresh;
Quoted 4 lines
drivers/video/modedb.c +0 -0
 	best = -1;
 	for (i = 0; i < dbsize; i++) {
 		if (name_matches(db[i], name, namelen) ||
 		    (res_specified && res_matches(db[i], xres, yres))) {

drivers/video/modedb.c done: · line 623

Quoted 10 lines
drivers/video/modedb.c +2 -2
 			if(!fb_try_mode(var, info, &db[i], bpp)) {
-				if(!refresh_specified || db[i].refresh == refresh)
+				if (refresh_specified && db[i].refresh == refresh)
 					return 1;
 				else {
-					if(diff > abs(db[i].refresh - refresh)) {
+					if (diff > abs(db[i].refresh - refresh)) {
 						diff = abs(db[i].refresh - refresh);
 						best = i;
 					}

then

					if (diff < db[i].refresh) {
						diff = db[i].refresh;
						best = i;
					}

Tony

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/