Skip to content

Commit 5ef82a5

Browse files
mripardPhil Elwell
authored andcommitted
drm/modes: Support modes names on the command line
commit 3aeeb13 upstream. Minor conflict resolution as upstream has moved functions from drm_fb_helper.c to a new drm_client_modeset.c 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 b5bcd07 commit 5ef82a5

4 files changed

Lines changed: 59 additions & 17 deletions

File tree

‎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_fb_helper.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,10 @@ struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *f
21562156
prefer_non_interlace = !cmdline_mode->interlace;
21572157
again:
21582158
list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
2159+
/* Check (optional) mode name first */
2160+
if (!strcmp(mode->name, cmdline_mode->name))
2161+
return mode;
2162+
21592163
/* check width/height */
21602164
if (mode->hdisplay != cmdline_mode->xres ||
21612165
mode->vdisplay != cmdline_mode->yres)

‎drivers/gpu/drm/drm_modes.c‎

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
15771577
struct drm_cmdline_mode *mode)
15781578
{
15791579
const char *name;
1580-
bool parse_extras = false;
1580+
bool named_mode = false, parse_extras = false;
15811581
unsigned int bpp_off = 0, refresh_off = 0;
15821582
unsigned int mode_end = 0;
15831583
char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
@@ -1596,8 +1596,22 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
15961596

15971597
name = mode_option;
15981598

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

16021616
/* Try to locate the bpp and refresh specifiers, if any */
16031617
bpp_ptr = strchr(name, '-');
@@ -1608,6 +1622,9 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
16081622

16091623
refresh_ptr = strchr(name, '@');
16101624
if (refresh_ptr) {
1625+
if (named_mode)
1626+
return false;
1627+
16111628
refresh_off = refresh_ptr - name;
16121629
mode->refresh_specified = true;
16131630
}
@@ -1624,12 +1641,16 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
16241641
parse_extras = true;
16251642
}
16261643

1627-
ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
1628-
parse_extras,
1629-
connector,
1630-
mode);
1631-
if (ret)
1632-
return false;
1644+
if (named_mode) {
1645+
strncpy(mode->name, name, mode_end);
1646+
} else {
1647+
ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
1648+
parse_extras,
1649+
connector,
1650+
mode);
1651+
if (ret)
1652+
return false;
1653+
}
16331654
mode->specified = true;
16341655

16351656
if (bpp_ptr) {
@@ -1657,14 +1678,23 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
16571678
extra_ptr = refresh_end_ptr;
16581679

16591680
if (extra_ptr) {
1660-
int remaining = strlen(name) - (extra_ptr - name);
1681+
if (!named_mode) {
1682+
int len = strlen(name) - (extra_ptr - name);
16611683

1662-
/*
1663-
* We still have characters to process, while
1664-
* we shouldn't have any
1665-
*/
1666-
if (remaining > 0)
1667-
return false;
1684+
ret = drm_mode_parse_cmdline_extra(extra_ptr, len,
1685+
connector, mode);
1686+
if (ret)
1687+
return false;
1688+
} else {
1689+
int remaining = strlen(name) - (extra_ptr - name);
1690+
1691+
/*
1692+
* We still have characters to process, while
1693+
* we shouldn't have any
1694+
*/
1695+
if (remaining > 0)
1696+
return false;
1697+
}
16681698
}
16691699

16701700
return true;

‎include/drm/drm_connector.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,13 @@ struct drm_connector_funcs {
903903
* parser.
904904
*/
905905
struct drm_cmdline_mode {
906+
/**
907+
* @name:
908+
*
909+
* Name of the mode.
910+
*/
911+
char name[DRM_DISPLAY_MODE_LEN];
912+
906913
/**
907914
* @specified:
908915
*

0 commit comments

Comments
 (0)