1 From 48ad5b4677e14d36f047a7fb7e8c3b10ba658310 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@bootlin.com>
3 Date: Wed, 19 Jun 2019 12:17:51 +0200
4 Subject: [PATCH 735/782] drm/modes: Allow to specify rotation and reflection
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Commit 1bf4e09227c345e246062285eba4b8fe660e512e upstream.
11 Minor conflict resolution as upstream has moved functions
12 from drm_fb_helper.c to a new drm_client_modeset.c
14 Rotations and reflections setup are needed in some scenarios to initialise
15 properly the initial framebuffer. Some drivers already had a bunch of
16 quirks to deal with this, such as either a private kernel command line
17 parameter (omapdss) or on the device tree (various panels).
19 In order to accomodate this, let's create a video mode parameter to deal
20 with the rotation and reflexion.
22 Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
23 Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
24 Link: https://patchwork.freedesktop.org/patch/msgid/777da16e42db757c1f5b414b5ca34507097fed5c.1560783090.git-series.maxime.ripard@bootlin.com
26 Documentation/fb/modedb.txt | 12 ++++
27 drivers/gpu/drm/drm_fb_helper.c | 30 +++++++++
28 drivers/gpu/drm/drm_modes.c | 114 ++++++++++++++++++++++++++------
29 include/drm/drm_connector.h | 10 +++
30 4 files changed, 146 insertions(+), 20 deletions(-)
32 --- a/Documentation/fb/modedb.txt
33 +++ b/Documentation/fb/modedb.txt
34 @@ -51,6 +51,18 @@ To force the VGA output to be enabled an
35 Specifying the option multiple times for different ports is possible, e.g.:
36 video=LVDS-1:d video=HDMI-1:D
38 +Options can also be passed after the mode, using commas as separator.
40 + Sample usage: 720x480,rotate=180 - 720x480 mode, rotated by 180 degrees
44 + - reflect_x (boolean): Perform an axial symmetry on the X axis
45 + - reflect_y (boolean): Perform an axial symmetry on the Y axis
46 + - rotate (integer): Rotate the initial framebuffer by x
47 + degrees. Valid values are 0, 90, 180 and 270.
50 ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo *****
52 What is the VESA(TM) Coordinated Video Timings (CVT)?
53 --- a/drivers/gpu/drm/drm_fb_helper.c
54 +++ b/drivers/gpu/drm/drm_fb_helper.c
55 @@ -2464,6 +2464,7 @@ static void drm_setup_crtc_rotation(stru
56 struct drm_connector *connector)
58 struct drm_plane *plane = fb_crtc->mode_set.crtc->primary;
59 + struct drm_cmdline_mode *cmdline;
60 uint64_t valid_mask = 0;
63 @@ -2483,6 +2484,35 @@ static void drm_setup_crtc_rotation(stru
64 rotation = DRM_MODE_ROTATE_0;
68 + * The panel already defined the default rotation
69 + * through its orientation. Whatever has been provided
70 + * on the command line needs to be added to that.
72 + * Unfortunately, the rotations are at different bit
73 + * indices, so the math to add them up are not as
74 + * trivial as they could.
76 + * Reflections on the other hand are pretty trivial to deal with, a
77 + * simple XOR between the two handle the addition nicely.
79 + cmdline = &connector->cmdline_mode;
80 + if (cmdline->specified) {
81 + unsigned int cmdline_rest, panel_rest;
82 + unsigned int cmdline_rot, panel_rot;
83 + unsigned int sum_rot, sum_rest;
85 + panel_rot = ilog2(rotation & DRM_MODE_ROTATE_MASK);
86 + cmdline_rot = ilog2(cmdline->rotation_reflection & DRM_MODE_ROTATE_MASK);
87 + sum_rot = (panel_rot + cmdline_rot) % 4;
89 + panel_rest = rotation & ~DRM_MODE_ROTATE_MASK;
90 + cmdline_rest = cmdline->rotation_reflection & ~DRM_MODE_ROTATE_MASK;
91 + sum_rest = panel_rest ^ cmdline_rest;
93 + rotation = (1 << sum_rot) | sum_rest;
97 * TODO: support 90 / 270 degree hardware rotation,
98 * depending on the hardware this may require the framebuffer
99 --- a/drivers/gpu/drm/drm_modes.c
100 +++ b/drivers/gpu/drm/drm_modes.c
101 @@ -1560,6 +1560,71 @@ static int drm_mode_parse_cmdline_res_mo
105 +static int drm_mode_parse_cmdline_options(char *str, size_t len,
106 + struct drm_connector *connector,
107 + struct drm_cmdline_mode *mode)
109 + unsigned int rotation = 0;
112 + while ((sep = strchr(sep, ','))) {
113 + char *delim, *option;
116 + delim = strchr(option, '=');
118 + delim = strchr(option, ',');
124 + if (!strncmp(option, "rotate", delim - option)) {
125 + const char *value = delim + 1;
128 + deg = simple_strtol(value, &sep, 10);
130 + /* Make sure we have parsed something */
136 + rotation |= DRM_MODE_ROTATE_0;
140 + rotation |= DRM_MODE_ROTATE_90;
144 + rotation |= DRM_MODE_ROTATE_180;
148 + rotation |= DRM_MODE_ROTATE_270;
154 + } else if (!strncmp(option, "reflect_x", delim - option)) {
155 + rotation |= DRM_MODE_REFLECT_X;
157 + } else if (!strncmp(option, "reflect_y", delim - option)) {
158 + rotation |= DRM_MODE_REFLECT_Y;
165 + mode->rotation_reflection = rotation;
171 * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
172 * @mode_option: optional per connector mode option
173 @@ -1575,6 +1640,10 @@ static int drm_mode_parse_cmdline_res_mo
175 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
177 + * Additionals options can be provided following the mode, using a comma to
178 + * separate each option. Valid options can be found in
179 + * Documentation/fb/modedb.txt.
181 * The intermediate drm_cmdline_mode structure is required to store additional
182 * options from the command line modline like the force-enable/disable flag.
184 @@ -1587,9 +1656,10 @@ bool drm_mode_parse_command_line_for_con
187 bool named_mode = false, parse_extras = false;
188 - unsigned int bpp_off = 0, refresh_off = 0;
189 + unsigned int bpp_off = 0, refresh_off = 0, options_off = 0;
190 unsigned int mode_end = 0;
191 char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
192 + char *options_ptr = NULL;
193 char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
196 @@ -1638,13 +1708,18 @@ bool drm_mode_parse_command_line_for_con
197 mode->refresh_specified = true;
200 + /* Locate the start of named options */
201 + options_ptr = strchr(name, ',');
203 + options_off = options_ptr - name;
205 /* Locate the end of the name / resolution, and parse it */
206 - if (bpp_ptr && refresh_ptr) {
207 - mode_end = min(bpp_off, refresh_off);
208 - } else if (bpp_ptr) {
211 } else if (refresh_ptr) {
212 mode_end = refresh_off;
213 + } else if (options_ptr) {
214 + mode_end = options_off;
216 mode_end = strlen(name);
218 @@ -1686,24 +1761,23 @@ bool drm_mode_parse_command_line_for_con
219 else if (refresh_ptr)
220 extra_ptr = refresh_end_ptr;
224 - int len = strlen(name) - (extra_ptr - name);
226 - ret = drm_mode_parse_cmdline_extra(extra_ptr, len,
231 - int remaining = strlen(name) - (extra_ptr - name);
233 + extra_ptr != options_ptr) {
234 + int len = strlen(name) - (extra_ptr - name);
237 - * We still have characters to process, while
238 - * we shouldn't have any
243 + ret = drm_mode_parse_cmdline_extra(extra_ptr, len,
250 + int len = strlen(name) - (options_ptr - name);
252 + ret = drm_mode_parse_cmdline_options(options_ptr, len,
259 --- a/include/drm/drm_connector.h
260 +++ b/include/drm/drm_connector.h
261 @@ -857,6 +857,16 @@ struct drm_cmdline_mode {
262 * state to one of the DRM_FORCE_* values.
264 enum drm_connector_force force;
267 + * @rotation_reflection:
269 + * Initial rotation and reflection of the mode setup from the
270 + * command line. See DRM_MODE_ROTATE_* and
271 + * DRM_MODE_REFLECT_*. The only rotations supported are
272 + * DRM_MODE_ROTATE_0 and DRM_MODE_ROTATE_180.
274 + unsigned int rotation_reflection;