Commit 3aeeb13d authored by Maxime Ripard's avatar Maxime Ripard

drm/modes: Support modes names on the command line

The drm subsystem also uses the video= kernel parameter, and in the
documentation refers to the fbdev documentation for that parameter.

However, that documentation also says that instead of giving the mode using
its resolution we can also give a name. However, DRM doesn't handle that
case at the moment. Even though in most case it shouldn't make any
difference, it might be useful for analog modes, where different standards
might have the same resolution, but still have a few different parameters
that are not encoded in the modes (NTSC vs NTSC-J vs PAL-M for example).
Reviewed-by: default avatarNoralf Trønnes <noralf@tronnes.org>
Signed-off-by: default avatarMaxime Ripard <maxime.ripard@bootlin.com>
Link: https://patchwork.freedesktop.org/patch/msgid/18443e0c3bdbbd16cea4ec63bc7f2079b820b43b.1560783090.git-series.maxime.ripard@bootlin.com
parent e08ab74b
...@@ -149,6 +149,10 @@ drm_connector_pick_cmdline_mode(struct drm_connector *connector) ...@@ -149,6 +149,10 @@ drm_connector_pick_cmdline_mode(struct drm_connector *connector)
prefer_non_interlace = !cmdline_mode->interlace; prefer_non_interlace = !cmdline_mode->interlace;
again: again:
list_for_each_entry(mode, &connector->modes, head) { list_for_each_entry(mode, &connector->modes, head) {
/* Check (optional) mode name first */
if (!strcmp(mode->name, cmdline_mode->name))
return mode;
/* check width/height */ /* check width/height */
if (mode->hdisplay != cmdline_mode->xres || if (mode->hdisplay != cmdline_mode->xres ||
mode->vdisplay != cmdline_mode->yres) mode->vdisplay != cmdline_mode->yres)
......
...@@ -139,8 +139,9 @@ static void drm_connector_get_cmdline_mode(struct drm_connector *connector) ...@@ -139,8 +139,9 @@ static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
connector->force = mode->force; connector->force = mode->force;
} }
DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
connector->name, connector->name,
mode->name ? mode->name : "",
mode->xres, mode->yres, mode->xres, mode->yres,
mode->refresh_specified ? mode->refresh : 60, mode->refresh_specified ? mode->refresh : 60,
mode->rb ? " reduced blanking" : "", mode->rb ? " reduced blanking" : "",
......
...@@ -1580,7 +1580,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, ...@@ -1580,7 +1580,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
struct drm_cmdline_mode *mode) struct drm_cmdline_mode *mode)
{ {
const char *name; const char *name;
bool parse_extras = false; bool named_mode = false, parse_extras = false;
unsigned int bpp_off = 0, refresh_off = 0; unsigned int bpp_off = 0, refresh_off = 0;
unsigned int mode_end = 0; unsigned int mode_end = 0;
char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL; char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
...@@ -1599,8 +1599,22 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, ...@@ -1599,8 +1599,22 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
name = mode_option; name = mode_option;
if (!isdigit(name[0])) /*
return false; * This is a bit convoluted. To differentiate between the
* named modes and poorly formatted resolutions, we need a
* bunch of things:
* - We need to make sure that the first character (which
* would be our resolution in X) is a digit.
* - However, if the X resolution is missing, then we end up
* with something like x<yres>, with our first character
* being an alpha-numerical character, which would be
* considered a named mode.
*
* If this isn't enough, we should add more heuristics here,
* and matching unit-tests.
*/
if (!isdigit(name[0]) && name[0] != 'x')
named_mode = true;
/* Try to locate the bpp and refresh specifiers, if any */ /* Try to locate the bpp and refresh specifiers, if any */
bpp_ptr = strchr(name, '-'); bpp_ptr = strchr(name, '-');
...@@ -1611,6 +1625,9 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, ...@@ -1611,6 +1625,9 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
refresh_ptr = strchr(name, '@'); refresh_ptr = strchr(name, '@');
if (refresh_ptr) { if (refresh_ptr) {
if (named_mode)
return false;
refresh_off = refresh_ptr - name; refresh_off = refresh_ptr - name;
mode->refresh_specified = true; mode->refresh_specified = true;
} }
...@@ -1627,12 +1644,16 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, ...@@ -1627,12 +1644,16 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
parse_extras = true; parse_extras = true;
} }
ret = drm_mode_parse_cmdline_res_mode(name, mode_end, if (named_mode) {
parse_extras, strncpy(mode->name, name, mode_end);
connector, } else {
mode); ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
if (ret) parse_extras,
return false; connector,
mode);
if (ret)
return false;
}
mode->specified = true; mode->specified = true;
if (bpp_ptr) { if (bpp_ptr) {
...@@ -1660,14 +1681,23 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option, ...@@ -1660,14 +1681,23 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
extra_ptr = refresh_end_ptr; extra_ptr = refresh_end_ptr;
if (extra_ptr) { if (extra_ptr) {
int remaining = strlen(name) - (extra_ptr - name); if (!named_mode) {
int len = strlen(name) - (extra_ptr - name);
/* ret = drm_mode_parse_cmdline_extra(extra_ptr, len,
* We still have characters to process, while connector, mode);
* we shouldn't have any if (ret)
*/ return false;
if (remaining > 0) } else {
return false; int remaining = strlen(name) - (extra_ptr - name);
/*
* We still have characters to process, while
* we shouldn't have any
*/
if (remaining > 0)
return false;
}
} }
return true; return true;
......
...@@ -932,6 +932,13 @@ struct drm_connector_funcs { ...@@ -932,6 +932,13 @@ struct drm_connector_funcs {
* parser. * parser.
*/ */
struct drm_cmdline_mode { struct drm_cmdline_mode {
/**
* @name:
*
* Name of the mode.
*/
char name[DRM_DISPLAY_MODE_LEN];
/** /**
* @specified: * @specified:
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment