f9ba856c448b68ab94e522aff32bf8949f4efe9a
[openwrt/staging/ynezz.git] /
1 From 5a8ccd79b6bad32e52620a94199bf1af2e19708e 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] drm/modes: Allow to specify rotation and reflection
5 on the commandline
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
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
13
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).
18
19 In order to accomodate this, let's create a video mode parameter to deal
20 with the rotation and reflexion.
21
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
25 ---
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(-)
31
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
37
38 +Options can also be passed after the mode, using commas as separator.
39 +
40 + Sample usage: 720x480,rotate=180 - 720x480 mode, rotated by 180 degrees
41 +
42 +Valid options are:
43 +
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.
48 +
49 +
50 ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo ***** oOo *****
51
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)
57 {
58 struct drm_plane *plane = fb_crtc->mode_set.crtc->primary;
59 + struct drm_cmdline_mode *cmdline;
60 uint64_t valid_mask = 0;
61 int i, rotation;
62
63 @@ -2483,6 +2484,35 @@ static void drm_setup_crtc_rotation(stru
64 rotation = DRM_MODE_ROTATE_0;
65 }
66
67 + /**
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.
71 + *
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.
75 + *
76 + * Reflections on the other hand are pretty trivial to deal with, a
77 + * simple XOR between the two handle the addition nicely.
78 + */
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;
84 +
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;
88 +
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;
92 +
93 + rotation = (1 << sum_rot) | sum_rest;
94 + }
95 +
96 /*
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
102 return 0;
103 }
104
105 +static int drm_mode_parse_cmdline_options(char *str, size_t len,
106 + struct drm_connector *connector,
107 + struct drm_cmdline_mode *mode)
108 +{
109 + unsigned int rotation = 0;
110 + char *sep = str;
111 +
112 + while ((sep = strchr(sep, ','))) {
113 + char *delim, *option;
114 +
115 + option = sep + 1;
116 + delim = strchr(option, '=');
117 + if (!delim) {
118 + delim = strchr(option, ',');
119 +
120 + if (!delim)
121 + delim = str + len;
122 + }
123 +
124 + if (!strncmp(option, "rotate", delim - option)) {
125 + const char *value = delim + 1;
126 + unsigned int deg;
127 +
128 + deg = simple_strtol(value, &sep, 10);
129 +
130 + /* Make sure we have parsed something */
131 + if (sep == value)
132 + return -EINVAL;
133 +
134 + switch (deg) {
135 + case 0:
136 + rotation |= DRM_MODE_ROTATE_0;
137 + break;
138 +
139 + case 90:
140 + rotation |= DRM_MODE_ROTATE_90;
141 + break;
142 +
143 + case 180:
144 + rotation |= DRM_MODE_ROTATE_180;
145 + break;
146 +
147 + case 270:
148 + rotation |= DRM_MODE_ROTATE_270;
149 + break;
150 +
151 + default:
152 + return -EINVAL;
153 + }
154 + } else if (!strncmp(option, "reflect_x", delim - option)) {
155 + rotation |= DRM_MODE_REFLECT_X;
156 + sep = delim;
157 + } else if (!strncmp(option, "reflect_y", delim - option)) {
158 + rotation |= DRM_MODE_REFLECT_Y;
159 + sep = delim;
160 + } else {
161 + return -EINVAL;
162 + }
163 + }
164 +
165 + mode->rotation_reflection = rotation;
166 +
167 + return 0;
168 +}
169 +
170 /**
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
174 *
175 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
176 *
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.
180 + *
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.
183 *
184 @@ -1587,9 +1656,10 @@ bool drm_mode_parse_command_line_for_con
185 {
186 const char *name;
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;
194 int ret;
195
196 @@ -1638,13 +1708,18 @@ bool drm_mode_parse_command_line_for_con
197 mode->refresh_specified = true;
198 }
199
200 + /* Locate the start of named options */
201 + options_ptr = strchr(name, ',');
202 + if (options_ptr)
203 + options_off = options_ptr - name;
204 +
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) {
209 + if (bpp_ptr) {
210 mode_end = bpp_off;
211 } else if (refresh_ptr) {
212 mode_end = refresh_off;
213 + } else if (options_ptr) {
214 + mode_end = options_off;
215 } else {
216 mode_end = strlen(name);
217 parse_extras = true;
218 @@ -1686,24 +1761,23 @@ bool drm_mode_parse_command_line_for_con
219 else if (refresh_ptr)
220 extra_ptr = refresh_end_ptr;
221
222 - if (extra_ptr) {
223 - if (!named_mode) {
224 - int len = strlen(name) - (extra_ptr - name);
225 -
226 - ret = drm_mode_parse_cmdline_extra(extra_ptr, len,
227 - connector, mode);
228 - if (ret)
229 - return false;
230 - } else {
231 - int remaining = strlen(name) - (extra_ptr - name);
232 + if (extra_ptr &&
233 + extra_ptr != options_ptr) {
234 + int len = strlen(name) - (extra_ptr - name);
235
236 - /*
237 - * We still have characters to process, while
238 - * we shouldn't have any
239 - */
240 - if (remaining > 0)
241 - return false;
242 - }
243 + ret = drm_mode_parse_cmdline_extra(extra_ptr, len,
244 + connector, mode);
245 + if (ret)
246 + return false;
247 + }
248 +
249 + if (options_ptr) {
250 + int len = strlen(name) - (options_ptr - name);
251 +
252 + ret = drm_mode_parse_cmdline_options(options_ptr, len,
253 + connector, mode);
254 + if (ret)
255 + return false;
256 }
257
258 return true;
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.
263 */
264 enum drm_connector_force force;
265 +
266 + /**
267 + * @rotation_reflection:
268 + *
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.
273 + */
274 + unsigned int rotation_reflection;
275 };
276
277 /**