diff mbox

[U-Boot] sunxi: video: Add extra modes and allow selecting the mode via hdmi_mode env

Message ID 1416759129-13711-1-git-send-email-hdegoede@redhat.com
State Changes Requested
Delegated to: Ian Campbell
Headers show

Commit Message

Hans de Goede Nov. 23, 2014, 4:12 p.m. UTC
Add the following extra modes:

1280x720@50
1920x1080@60
1920x1200@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.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/video/sunxi_display.c  | 91 +++++++++++++++++++++++++++++++++++++-----
 include/configs/sunxi-common.h |  2 +-
 2 files changed, 81 insertions(+), 12 deletions(-)

Comments

Ian Campbell Nov. 25, 2014, 8:53 a.m. UTC | #1
On Sun, 2014-11-23 at 17:12 +0100, Hans de Goede wrote:
> Add the following extra modes:
> 
> 1280x720@50
> 1920x1080@60
> 1920x1200@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.
Hans de Goede Nov. 25, 2014, 10:13 a.m. UTC | #2
Hi,

On 11/25/2014 09:53 AM, Ian Campbell wrote:
> On Sun, 2014-11-23 at 17:12 +0100, Hans de Goede wrote:
>> Add the following extra modes:
>>
>> 1280x720@50
>> 1920x1080@60
>> 1920x1200@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.

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@50

Which would mean: auto-detect, if that fails then configure
dvi out on 1280x720@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@60

To force hdmi output format, or:

video=dvi:1920x1080@60

To force dvi output.

And for lcd people could use:

video=lcd:800x480@50

Or:

video=auto:lcd:800x480@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...

> 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
diff mbox

Patch

diff --git a/drivers/video/sunxi_display.c b/drivers/video/sunxi_display.c
index 3060bee..349e36c 100644
--- a/drivers/video/sunxi_display.c
+++ b/drivers/video/sunxi_display.c
@@ -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@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@60
+		 * 65.0  1024 1032 1176 1344  768 771 777 806  -hsync -vsync
+		 */
+		.name = "1024x768@60",
 		.refresh = 60,
 		.xres = 1024,
 		.yres = 768,
@@ -377,7 +376,76 @@  void *video_hw_init(void)
 		.sync = 0,
 		.vmode = 0,
 		.flag = 0,
-	};
+	} , {
+		.name = "1280x720@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@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@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);
 
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index 7b958f8..a6cdffb 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -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