Skip to content

Commit 3aeeb13

Browse files
committed
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: Noralf Trønnes <noralf@tronnes.org> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Link: https://patchwork.freedesktop.org/patch/msgid/18443e0c3bdbbd16cea4ec63bc7f2079b820b43b.1560783090.git-series.maxime.ripard@bootlin.com
1 parent e08ab74 commit 3aeeb13

4 files changed

Lines changed: 59 additions & 17 deletions

File tree

‎drivers/gpu/drm/drm_client_modeset.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ drm_connector_pick_cmdline_mode(struct drm_connector *connector)
149149
prefer_non_interlace = !cmdline_mode->interlace;
150150
again:
151151
list_for_each_entry(mode, &connector->modes, head) {
152+
/* Check (optional) mode name first */
153+
if (!strcmp(mode->name, cmdline_mode->name))
154+
return mode;
155+
152156
/* check width/height */
153157
if (mode->hdisplay != cmdline_mode->xres ||
154158
mode->vdisplay != cmdline_mode->yres)

‎drivers/gpu/drm/drm_connector.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
139139
connector->force = mode->force;
140140
}
141141

142-
DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
142+
DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
143143
connector->name,
144+
mode->name ? mode->name : "",
144145
mode->xres, mode->yres,
145146
mode->refresh_specified ? mode->refresh : 60,
146147
mode->rb ? " reduced blanking" : "",

‎drivers/gpu/drm/drm_modes.c‎

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
15801580
struct drm_cmdline_mode *mode)
15811581
{
15821582
const char *name;
1583-
bool parse_extras = false;
1583+
bool named_mode = false, parse_extras = false;
15841584
unsigned int bpp_off = 0, refresh_off = 0;
15851585
unsigned int mode_end = 0;
15861586
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,
15991599

16001600
name = mode_option;
16011601

1602-
if (!isdigit(name[0]))
1603-
return false;
1602+
/*
1603+
* This is a bit convoluted. To differentiate between the
1604+
* named modes and poorly formatted resolutions, we need a
1605+
* bunch of things:
1606+
* - We need to make sure that the first character (which
1607+
* would be our resolution in X) is a digit.
1608+
* - However, if the X resolution is missing, then we end up
1609+
* with something like x<yres>, with our first character
1610+
* being an alpha-numerical character, which would be
1611+
* considered a named mode.
1612+
*
1613+
* If this isn't enough, we should add more heuristics here,
1614+
* and matching unit-tests.
1615+
*/
1616+
if (!isdigit(name[0]) && name[0] != 'x')
1617+
named_mode = true;
16041618

16051619
/* Try to locate the bpp and refresh specifiers, if any */
16061620
bpp_ptr = strchr(name, '-');
@@ -1611,6 +1625,9 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
16111625

16121626
refresh_ptr = strchr(name, '@');
16131627
if (refresh_ptr) {
1628+
if (named_mode)
1629+
return false;
1630+
16141631
refresh_off = refresh_ptr - name;
16151632
mode->refresh_specified = true;
16161633
}
@@ -1627,12 +1644,16 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
16271644
parse_extras = true;
16281645
}
16291646

1630-
ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
1631-
parse_extras,
1632-
connector,
1633-
mode);
1634-
if (ret)
1635-
return false;
1647+
if (named_mode) {
1648+
strncpy(mode->name, name, mode_end);
1649+
} else {
1650+
ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
1651+
parse_extras,
1652+
connector,
1653+
mode);
1654+
if (ret)
1655+
return false;
1656+
}
16361657
mode->specified = true;
16371658

16381659
if (bpp_ptr) {
@@ -1660,14 +1681,23 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
16601681
extra_ptr = refresh_end_ptr;
16611682

16621683
if (extra_ptr) {
1663-
int remaining = strlen(name) - (extra_ptr - name);
1684+
if (!named_mode) {
1685+
int len = strlen(name) - (extra_ptr - name);
16641686

1665-
/*
1666-
* We still have characters to process, while
1667-
* we shouldn't have any
1668-
*/
1669-
if (remaining > 0)
1670-
return false;
1687+
ret = drm_mode_parse_cmdline_extra(extra_ptr, len,
1688+
connector, mode);
1689+
if (ret)
1690+
return false;
1691+
} else {
1692+
int remaining = strlen(name) - (extra_ptr - name);
1693+
1694+
/*
1695+
* We still have characters to process, while
1696+
* we shouldn't have any
1697+
*/
1698+
if (remaining > 0)
1699+
return false;
1700+
}
16711701
}
16721702

16731703
return true;

‎include/drm/drm_connector.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,13 @@ struct drm_connector_funcs {
932932
* parser.
933933
*/
934934
struct drm_cmdline_mode {
935+
/**
936+
* @name:
937+
*
938+
* Name of the mode.
939+
*/
940+
char name[DRM_DISPLAY_MODE_LEN];
941+
935942
/**
936943
* @specified:
937944
*

0 commit comments

Comments
 (0)