Skip to contentSkip to conversation

sunxi: video: Add extra modes and allow selecting the mode via hdmi_mode env

PATCH New Hans de Goede 2 participants 3 messages Nov 23, 2014 – Nov 25, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sunxi: video: Add extra modes and allow selecting the mode via hdmi_mode env

Add the following extra modes:

1280x720 at 50
1920x1080 at 60
1920x1200 at 60

And allow selecting them by setting (and then saving and rebooting) a hdmi_mode env variable to the name of the mode.

Also make the reserved fb mem slightly larger to allow 1920x1200 to work.

---
 drivers/video/sunxi_display.c  | 91 +++++++++++++++++++++++++++++++++++++-----
 include/configs/sunxi-common.h |  2 +-
 2 files changed, 81 insertions(+), 12 deletions(-)
drivers/video/sunxi_display.c +80 -11
index 3060bee..349e36c 100644
@@ -355,15 +355,14 @@ retry:
 	}
 }
 
-void *video_hw_init(void)
+static void video_get_mode(char *modestr, struct fb_videomode *mode)
 {
-	static GraphicDevice *graphic_device = &sunxi_display.graphic_device;
-	/*
-	 * Vesa standard 1024x768 at 60
-	 * 65.0  1024 1032 1176 1344  768 771 777 806  -hsync -vsync
-	 */
-	struct fb_videomode mode = {
-		.name = "1024x768",
+	const struct fb_videomode modes[] = { {
+		/*
+		 * Vesa standard 1024x768 at 60
+		 * 65.0  1024 1032 1176 1344  768 771 777 806  -hsync -vsync
+		 */
+		.name = "1024x768 at 60",
 		.refresh = 60,
 		.xres = 1024,
 		.yres = 768,
@@ -377,7 +376,76 @@ void *video_hw_init(void)
 		.sync = 0,
 		.vmode = 0,
 		.flag = 0,
-	};
+	} , {
+		.name = "1280x720 at 50",
+		.refresh = 50,
+		.xres = 1280,
+		.yres = 720,
+		.pixclock = 74250,
+		.left_margin = 440,
+		.right_margin = 220,
+		.upper_margin = 20,
+		.lower_margin = 5,
+		.hsync_len = 40,
+		.vsync_len = 5,
+		.sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+		.vmode = FB_VMODE_NONINTERLACED,
+		.flag = 0,
+	} , {
+		.name = "1920x1080 at 60",
+		.refresh = 60,
+		.xres = 1920,
+		.yres = 1080,
+		.pixclock = 148500,
+		.left_margin = 88,
+		.right_margin = 148,
+		.upper_margin = 36,
+		.lower_margin = 4,
+		.hsync_len = 44,
+		.vsync_len = 5,
+		.sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+		.vmode = FB_VMODE_NONINTERLACED,
+		.flag = 0,
+	} , {
+		.name = "1920x1200 at 60",
+		.refresh = 60,
+		.xres = 1920,
+		.yres = 1200,
+		.pixclock = 154000,
+		.left_margin = 48,
+		.right_margin = 80,
+		.upper_margin = 26,
+		.lower_margin = 3,
+		.hsync_len = 32,
+		.vsync_len = 6,
+		.sync = FB_SYNC_HOR_HIGH_ACT,
+		.vmode = FB_VMODE_NONINTERLACED,
+		.flag = 0,
+	} };
+	int i;
+
+	if (!modestr) {
+		*mode = modes[0];
+		return;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(modes); i++) {
+		if (strcmp(modes[i].name, modestr) == 0)
+			break;
+	}
+	if (i >= ARRAY_SIZE(modes)) {
+		eprintf("Mode %s not available, falling back to %s\n",
+			modestr, modes[0].name);
+		i = 0;
+	}
+
+	*mode = modes[i];
+}
+
+void *video_hw_init(void)
+{
+	static GraphicDevice *graphic_device = &sunxi_display.graphic_device;
+	struct fb_videomode mode;
 	int ret;
 
 	memset(&sunxi_display, 0, sizeof(struct sunxi_display));
@@ -390,10 +458,11 @@ void *video_hw_init(void)
 	if (!ret)
 		return NULL;
 
-	printf("HDMI connected.\n");
 	sunxi_display.enabled = true;
+	video_get_mode(getenv("hdmi_mode"), &mode);
+
+	printf("HDMI connected, setting up a %s console.\n", mode.name);
 
-	printf("Setting up a %s console.\n", mode.name);
 	sunxi_engines_init();
 	sunxi_mode_set(&mode, gd->fb_base - CONFIG_SYS_SDRAM_BASE);
 
include/configs/sunxi-common.h +1 -1
index 7b958f8..a6cdffb 100644
@@ -202,7 +202,7 @@
  * The amount of RAM that is reserved for the FB. This will not show up as
  * RAM to the kernel, but will be reclaimed by a KMS driver in future.
  */
-#define CONFIG_SUNXI_FB_SIZE (8 << 20)
+#define CONFIG_SUNXI_FB_SIZE (9 << 20)
 
 /* Do we want to initialize a simple FB? */
 #define CONFIG_VIDEO_DT_SIMPLEFB
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/1 sunxi: video: Add extra modes and allow selecting the mode via hdmi_mode env

Quoted 8 lines · Hans de Goede

Add the following extra modes:

1280x720 at 50
1920x1080 at 60
1920x1200 at 60

And allow selecting them by setting (and then saving and rebooting) a hdmi_mode env variable to the name of the mode.

Is there any u-boot side standard for the naming/format of such a variable? (adding Anatolij for input too).

I see a bunch of platforms apparently using video= (just from a grep on includes/configs for video=), likewise videomode= which is also described in README but doesn't look to cover the sort of things wanted here.

Is there note some centralise db of struct db_videomode we can use? Seems like not, oh well.

Ian.

#2 lore raw

PATCH 1/1 sunxi: video: Add extra modes and allow selecting the mode via hdmi_mode env

Hi,

Quoted 10 lines · Ian Campbell
Quoted 8 lines · Hans de Goede

Add the following extra modes:

1280x720 at 50
1920x1080 at 60
1920x1200 at 60

And allow selecting them by setting (and then saving and rebooting) a hdmi_mode env variable to the name of the mode.

Quoted 7 lines

Is there any u-boot side standard for the naming/format of such a variable? (adding Anatolij for input too).

I see a bunch of platforms apparently using video= (just from a grep on includes/configs for video=), likewise videomode= which is also described in README but doesn't look to cover the sort of things wanted here.

Ok, so I've been thinking a bit about this, I plan to also support lcd support one of these days, I was thinking using lcd_mode= for that, but probably having one mechanism is better.

So here is what I've been thinking, we add support for a video= environment variable, which is build up like this:

video=[auto:][<output>:]<modename>

So one could do:

video=auto:dvi:1280x720 at 50

Which would mean: auto-detect, if that fails then configure dvi out on 1280x720 at 50

This also works well with code I'm currently working on, our current hdmi support is actually dvi out, as we're not sending a hdmi avi info frame.

For some displays this is a problem, as they only work with proper hdmi data, so currently I'm working on making the sunxi display code (optionally) send proper hdmi data. Note we cannot always do this, as dvi monitors cannot deal with it. So people would be able to do:

video=hdmi:1920x1080 at 60

To force hdmi output format, or:

video=dvi:1920x1080 at 60

To force dvi output.

And for lcd people could use:

video=lcd:800x480 at 50

Or:

video=auto:lcd:800x480 at 50

Which would first try hdmi (see if a cable is attached) + edid, and if that does not work light up the lcd instead.

The exact behavior of auto would be board specific, but the basic video= parsing could live in generic code...

Quoted 2 lines

Is there note some centralise db of struct db_videomode we can use? Seems like not, oh well.

And use a shared mode database, and actually fill a fb_videomode struct for us.

Does that sound like a plan ?

Anatolij, what do you think about this ?

Regards,

Hans