kernel: bump 5.10 to 5.10.71
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.10 / 950-0689-drm-automatic-legacy-gamma-support.patch
1 From 88dea782ac45343b039ee1b6ee15b55e63a5f835 Mon Sep 17 00:00:00 2001
2 From: Tomi Valkeinen <tomi.valkeinen@ti.com>
3 Date: Fri, 11 Dec 2020 13:42:36 +0200
4 Subject: [PATCH] drm: automatic legacy gamma support
5
6 To support legacy gamma ioctls the drivers need to set
7 drm_crtc_funcs.gamma_set either to a custom implementation or to
8 drm_atomic_helper_legacy_gamma_set. Most of the atomic drivers do the
9 latter.
10
11 We can simplify this by making the core handle it automatically.
12
13 Move the drm_atomic_helper_legacy_gamma_set() functionality into
14 drm_color_mgmt.c to make drm_mode_gamma_set_ioctl() use
15 drm_crtc_funcs.gamma_set if set or GAMMA_LUT property if not.
16
17 Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
18 Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
19 Reviewed-by: Philippe Cornu <philippe.cornu@st.com>
20 Link: https://patchwork.freedesktop.org/patch/msgid/20201211114237.213288-2-tomi.valkeinen@ti.com
21 ---
22 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 1 -
23 .../gpu/drm/arm/display/komeda/komeda_crtc.c | 1 -
24 drivers/gpu/drm/arm/malidp_crtc.c | 1 -
25 drivers/gpu/drm/armada/armada_crtc.c | 1 -
26 drivers/gpu/drm/ast/ast_mode.c | 1 -
27 .../gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c | 1 -
28 drivers/gpu/drm/drm_atomic_helper.c | 70 -----------
29 drivers/gpu/drm/drm_color_mgmt.c | 111 ++++++++++++++++--
30 drivers/gpu/drm/i915/display/intel_display.c | 1 -
31 drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 -
32 drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 1 -
33 drivers/gpu/drm/nouveau/dispnv50/head.c | 2 -
34 drivers/gpu/drm/omapdrm/omap_crtc.c | 1 -
35 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 1 -
36 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 1 -
37 drivers/gpu/drm/stm/ltdc.c | 1 -
38 drivers/gpu/drm/vc4/vc4_crtc.c | 1 -
39 drivers/gpu/drm/vc4/vc4_txp.c | 1 -
40 include/drm/drm_atomic_helper.h | 4 -
41 19 files changed, 102 insertions(+), 101 deletions(-)
42
43 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
44 +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
45 @@ -4989,7 +4989,6 @@ static void dm_disable_vblank(struct drm
46 static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs = {
47 .reset = dm_crtc_reset_state,
48 .destroy = amdgpu_dm_crtc_destroy,
49 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
50 .set_config = drm_atomic_helper_set_config,
51 .page_flip = drm_atomic_helper_page_flip,
52 .atomic_duplicate_state = dm_crtc_duplicate_state,
53 --- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
54 +++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
55 @@ -548,7 +548,6 @@ static void komeda_crtc_vblank_disable(s
56 }
57
58 static const struct drm_crtc_funcs komeda_crtc_funcs = {
59 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
60 .destroy = drm_crtc_cleanup,
61 .set_config = drm_atomic_helper_set_config,
62 .page_flip = drm_atomic_helper_page_flip,
63 --- a/drivers/gpu/drm/arm/malidp_crtc.c
64 +++ b/drivers/gpu/drm/arm/malidp_crtc.c
65 @@ -510,7 +510,6 @@ static void malidp_crtc_disable_vblank(s
66 }
67
68 static const struct drm_crtc_funcs malidp_crtc_funcs = {
69 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
70 .destroy = drm_crtc_cleanup,
71 .set_config = drm_atomic_helper_set_config,
72 .page_flip = drm_atomic_helper_page_flip,
73 --- a/drivers/gpu/drm/armada/armada_crtc.c
74 +++ b/drivers/gpu/drm/armada/armada_crtc.c
75 @@ -816,7 +816,6 @@ static const struct drm_crtc_funcs armad
76 .cursor_set = armada_drm_crtc_cursor_set,
77 .cursor_move = armada_drm_crtc_cursor_move,
78 .destroy = armada_drm_crtc_destroy,
79 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
80 .set_config = drm_atomic_helper_set_config,
81 .page_flip = drm_atomic_helper_page_flip,
82 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
83 --- a/drivers/gpu/drm/ast/ast_mode.c
84 +++ b/drivers/gpu/drm/ast/ast_mode.c
85 @@ -898,7 +898,6 @@ static void ast_crtc_atomic_destroy_stat
86
87 static const struct drm_crtc_funcs ast_crtc_funcs = {
88 .reset = ast_crtc_reset,
89 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
90 .destroy = drm_crtc_cleanup,
91 .set_config = drm_atomic_helper_set_config,
92 .page_flip = drm_atomic_helper_page_flip,
93 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c
94 +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c
95 @@ -473,7 +473,6 @@ static const struct drm_crtc_funcs atmel
96 .atomic_destroy_state = atmel_hlcdc_crtc_destroy_state,
97 .enable_vblank = atmel_hlcdc_crtc_enable_vblank,
98 .disable_vblank = atmel_hlcdc_crtc_disable_vblank,
99 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
100 };
101
102 int atmel_hlcdc_crtc_create(struct drm_device *dev)
103 --- a/drivers/gpu/drm/drm_atomic_helper.c
104 +++ b/drivers/gpu/drm/drm_atomic_helper.c
105 @@ -3500,76 +3500,6 @@ fail:
106 EXPORT_SYMBOL(drm_atomic_helper_page_flip_target);
107
108 /**
109 - * drm_atomic_helper_legacy_gamma_set - set the legacy gamma correction table
110 - * @crtc: CRTC object
111 - * @red: red correction table
112 - * @green: green correction table
113 - * @blue: green correction table
114 - * @size: size of the tables
115 - * @ctx: lock acquire context
116 - *
117 - * Implements support for legacy gamma correction table for drivers
118 - * that support color management through the DEGAMMA_LUT/GAMMA_LUT
119 - * properties. See drm_crtc_enable_color_mgmt() and the containing chapter for
120 - * how the atomic color management and gamma tables work.
121 - */
122 -int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,
123 - u16 *red, u16 *green, u16 *blue,
124 - uint32_t size,
125 - struct drm_modeset_acquire_ctx *ctx)
126 -{
127 - struct drm_device *dev = crtc->dev;
128 - struct drm_atomic_state *state;
129 - struct drm_crtc_state *crtc_state;
130 - struct drm_property_blob *blob = NULL;
131 - struct drm_color_lut *blob_data;
132 - int i, ret = 0;
133 - bool replaced;
134 -
135 - state = drm_atomic_state_alloc(crtc->dev);
136 - if (!state)
137 - return -ENOMEM;
138 -
139 - blob = drm_property_create_blob(dev,
140 - sizeof(struct drm_color_lut) * size,
141 - NULL);
142 - if (IS_ERR(blob)) {
143 - ret = PTR_ERR(blob);
144 - blob = NULL;
145 - goto fail;
146 - }
147 -
148 - /* Prepare GAMMA_LUT with the legacy values. */
149 - blob_data = blob->data;
150 - for (i = 0; i < size; i++) {
151 - blob_data[i].red = red[i];
152 - blob_data[i].green = green[i];
153 - blob_data[i].blue = blue[i];
154 - }
155 -
156 - state->acquire_ctx = ctx;
157 - crtc_state = drm_atomic_get_crtc_state(state, crtc);
158 - if (IS_ERR(crtc_state)) {
159 - ret = PTR_ERR(crtc_state);
160 - goto fail;
161 - }
162 -
163 - /* Reset DEGAMMA_LUT and CTM properties. */
164 - replaced = drm_property_replace_blob(&crtc_state->degamma_lut, NULL);
165 - replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL);
166 - replaced |= drm_property_replace_blob(&crtc_state->gamma_lut, blob);
167 - crtc_state->color_mgmt_changed |= replaced;
168 -
169 - ret = drm_atomic_commit(state);
170 -
171 -fail:
172 - drm_atomic_state_put(state);
173 - drm_property_blob_put(blob);
174 - return ret;
175 -}
176 -EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set);
177 -
178 -/**
179 * drm_atomic_helper_bridge_propagate_bus_fmt() - Propagate output format to
180 * the input end of a bridge
181 * @bridge: bridge control structure
182 --- a/drivers/gpu/drm/drm_color_mgmt.c
183 +++ b/drivers/gpu/drm/drm_color_mgmt.c
184 @@ -22,6 +22,7 @@
185
186 #include <linux/uaccess.h>
187
188 +#include <drm/drm_atomic.h>
189 #include <drm/drm_color_mgmt.h>
190 #include <drm/drm_crtc.h>
191 #include <drm/drm_device.h>
192 @@ -89,9 +90,8 @@
193 * modes) appropriately.
194 *
195 * There is also support for a legacy gamma table, which is set up by calling
196 - * drm_mode_crtc_set_gamma_size(). Drivers which support both should use
197 - * drm_atomic_helper_legacy_gamma_set() to alias the legacy gamma ramp with the
198 - * "GAMMA_LUT" property above.
199 + * drm_mode_crtc_set_gamma_size(). The DRM core will then alias the legacy gamma
200 + * ramp with "GAMMA_LUT".
201 *
202 * Support for different non RGB color encodings is controlled through
203 * &drm_plane specific COLOR_ENCODING and COLOR_RANGE properties. They
204 @@ -156,9 +156,6 @@ EXPORT_SYMBOL(drm_color_ctm_s31_32_to_qm
205 * optional. The gamma and degamma properties are only attached if
206 * their size is not 0 and ctm_property is only attached if has_ctm is
207 * true.
208 - *
209 - * Drivers should use drm_atomic_helper_legacy_gamma_set() to implement the
210 - * legacy &drm_crtc_funcs.gamma_set callback.
211 */
212 void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
213 uint degamma_lut_size,
214 @@ -232,6 +229,102 @@ int drm_mode_crtc_set_gamma_size(struct
215 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
216
217 /**
218 + * drm_crtc_supports_legacy_gamma - does the crtc support legacy gamma correction table
219 + * @crtc: CRTC object
220 + *
221 + * Returns true/false if the given crtc supports setting the legacy gamma
222 + * correction table.
223 + */
224 +static bool drm_crtc_supports_legacy_gamma(struct drm_crtc *crtc)
225 +{
226 + u32 gamma_id = crtc->dev->mode_config.gamma_lut_property->base.id;
227 +
228 + if (!crtc->gamma_size)
229 + return false;
230 +
231 + if (crtc->funcs->gamma_set)
232 + return true;
233 +
234 + return !!drm_mode_obj_find_prop_id(&crtc->base, gamma_id);
235 +}
236 +
237 +/**
238 + * drm_crtc_legacy_gamma_set - set the legacy gamma correction table
239 + * @crtc: CRTC object
240 + * @red: red correction table
241 + * @green: green correction table
242 + * @blue: green correction table
243 + * @size: size of the tables
244 + * @ctx: lock acquire context
245 + *
246 + * Implements support for legacy gamma correction table for drivers
247 + * that have set drm_crtc_funcs.gamma_set or that support color management
248 + * through the DEGAMMA_LUT/GAMMA_LUT properties. See
249 + * drm_crtc_enable_color_mgmt() and the containing chapter for
250 + * how the atomic color management and gamma tables work.
251 + *
252 + * This function sets the gamma using drm_crtc_funcs.gamma_set if set, or
253 + * alternatively using crtc color management properties.
254 + */
255 +static int drm_crtc_legacy_gamma_set(struct drm_crtc *crtc,
256 + u16 *red, u16 *green, u16 *blue,
257 + u32 size,
258 + struct drm_modeset_acquire_ctx *ctx)
259 +{
260 + struct drm_device *dev = crtc->dev;
261 + struct drm_atomic_state *state;
262 + struct drm_crtc_state *crtc_state;
263 + struct drm_property_blob *blob;
264 + struct drm_color_lut *blob_data;
265 + int i, ret = 0;
266 + bool replaced;
267 +
268 + if (crtc->funcs->gamma_set)
269 + return crtc->funcs->gamma_set(crtc, red, green, blue, size, ctx);
270 +
271 + state = drm_atomic_state_alloc(crtc->dev);
272 + if (!state)
273 + return -ENOMEM;
274 +
275 + blob = drm_property_create_blob(dev,
276 + sizeof(struct drm_color_lut) * size,
277 + NULL);
278 + if (IS_ERR(blob)) {
279 + ret = PTR_ERR(blob);
280 + blob = NULL;
281 + goto fail;
282 + }
283 +
284 + /* Prepare GAMMA_LUT with the legacy values. */
285 + blob_data = blob->data;
286 + for (i = 0; i < size; i++) {
287 + blob_data[i].red = red[i];
288 + blob_data[i].green = green[i];
289 + blob_data[i].blue = blue[i];
290 + }
291 +
292 + state->acquire_ctx = ctx;
293 + crtc_state = drm_atomic_get_crtc_state(state, crtc);
294 + if (IS_ERR(crtc_state)) {
295 + ret = PTR_ERR(crtc_state);
296 + goto fail;
297 + }
298 +
299 + /* Set GAMMA_LUT and reset DEGAMMA_LUT and CTM */
300 + replaced = drm_property_replace_blob(&crtc_state->degamma_lut, NULL);
301 + replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL);
302 + replaced |= drm_property_replace_blob(&crtc_state->gamma_lut, blob);
303 + crtc_state->color_mgmt_changed |= replaced;
304 +
305 + ret = drm_atomic_commit(state);
306 +
307 +fail:
308 + drm_atomic_state_put(state);
309 + drm_property_blob_put(blob);
310 + return ret;
311 +}
312 +
313 +/**
314 * drm_mode_gamma_set_ioctl - set the gamma table
315 * @dev: DRM device
316 * @data: ioctl data
317 @@ -262,7 +355,7 @@ int drm_mode_gamma_set_ioctl(struct drm_
318 if (!crtc)
319 return -ENOENT;
320
321 - if (crtc->funcs->gamma_set == NULL)
322 + if (!drm_crtc_supports_legacy_gamma(crtc))
323 return -ENOSYS;
324
325 /* memcpy into gamma store */
326 @@ -290,8 +383,8 @@ int drm_mode_gamma_set_ioctl(struct drm_
327 goto out;
328 }
329
330 - ret = crtc->funcs->gamma_set(crtc, r_base, g_base, b_base,
331 - crtc->gamma_size, &ctx);
332 + ret = drm_crtc_legacy_gamma_set(crtc, r_base, g_base, b_base,
333 + crtc->gamma_size, &ctx);
334
335 out:
336 DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
337 --- a/drivers/gpu/drm/i915/display/intel_display.c
338 +++ b/drivers/gpu/drm/i915/display/intel_display.c
339 @@ -16562,7 +16562,6 @@ fail:
340 }
341
342 #define INTEL_CRTC_FUNCS \
343 - .gamma_set = drm_atomic_helper_legacy_gamma_set, \
344 .set_config = drm_atomic_helper_set_config, \
345 .destroy = intel_crtc_destroy, \
346 .page_flip = drm_atomic_helper_page_flip, \
347 --- a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
348 +++ b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
349 @@ -647,8 +647,6 @@ static const struct drm_crtc_funcs ingen
350
351 .enable_vblank = ingenic_drm_enable_vblank,
352 .disable_vblank = ingenic_drm_disable_vblank,
353 -
354 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
355 };
356
357 static const struct drm_plane_helper_funcs ingenic_drm_plane_helper_funcs = {
358 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
359 +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
360 @@ -614,7 +614,6 @@ static const struct drm_crtc_funcs mtk_c
361 .reset = mtk_drm_crtc_reset,
362 .atomic_duplicate_state = mtk_drm_crtc_duplicate_state,
363 .atomic_destroy_state = mtk_drm_crtc_destroy_state,
364 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
365 .enable_vblank = mtk_drm_crtc_enable_vblank,
366 .disable_vblank = mtk_drm_crtc_disable_vblank,
367 };
368 --- a/drivers/gpu/drm/nouveau/dispnv50/head.c
369 +++ b/drivers/gpu/drm/nouveau/dispnv50/head.c
370 @@ -506,7 +506,6 @@ nv50_head_destroy(struct drm_crtc *crtc)
371 static const struct drm_crtc_funcs
372 nv50_head_func = {
373 .reset = nv50_head_reset,
374 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
375 .destroy = nv50_head_destroy,
376 .set_config = drm_atomic_helper_set_config,
377 .page_flip = drm_atomic_helper_page_flip,
378 @@ -521,7 +520,6 @@ nv50_head_func = {
379 static const struct drm_crtc_funcs
380 nvd9_head_func = {
381 .reset = nv50_head_reset,
382 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
383 .destroy = nv50_head_destroy,
384 .set_config = drm_atomic_helper_set_config,
385 .page_flip = drm_atomic_helper_page_flip,
386 --- a/drivers/gpu/drm/omapdrm/omap_crtc.c
387 +++ b/drivers/gpu/drm/omapdrm/omap_crtc.c
388 @@ -741,7 +741,6 @@ static const struct drm_crtc_funcs omap_
389 .set_config = drm_atomic_helper_set_config,
390 .destroy = omap_crtc_destroy,
391 .page_flip = drm_atomic_helper_page_flip,
392 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
393 .atomic_duplicate_state = omap_crtc_duplicate_state,
394 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
395 .atomic_set_property = omap_crtc_atomic_set_property,
396 --- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
397 +++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
398 @@ -1138,7 +1138,6 @@ static const struct drm_crtc_funcs crtc_
399 .set_crc_source = rcar_du_crtc_set_crc_source,
400 .verify_crc_source = rcar_du_crtc_verify_crc_source,
401 .get_crc_sources = rcar_du_crtc_get_crc_sources,
402 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
403 };
404
405 /* -----------------------------------------------------------------------------
406 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
407 +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
408 @@ -1642,7 +1642,6 @@ static const struct drm_crtc_funcs vop_c
409 .disable_vblank = vop_crtc_disable_vblank,
410 .set_crc_source = vop_crtc_set_crc_source,
411 .verify_crc_source = vop_crtc_verify_crc_source,
412 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
413 };
414
415 static void vop_fb_unref_worker(struct drm_flip_work *work, void *val)
416 --- a/drivers/gpu/drm/stm/ltdc.c
417 +++ b/drivers/gpu/drm/stm/ltdc.c
418 @@ -742,7 +742,6 @@ static const struct drm_crtc_funcs ltdc_
419 .enable_vblank = ltdc_crtc_enable_vblank,
420 .disable_vblank = ltdc_crtc_disable_vblank,
421 .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp,
422 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
423 };
424
425 /*
426 --- a/drivers/gpu/drm/vc4/vc4_crtc.c
427 +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
428 @@ -937,7 +937,6 @@ static const struct drm_crtc_funcs vc4_c
429 .reset = vc4_crtc_reset,
430 .atomic_duplicate_state = vc4_crtc_duplicate_state,
431 .atomic_destroy_state = vc4_crtc_destroy_state,
432 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
433 .enable_vblank = vc4_enable_vblank,
434 .disable_vblank = vc4_disable_vblank,
435 .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp,
436 --- a/drivers/gpu/drm/vc4/vc4_txp.c
437 +++ b/drivers/gpu/drm/vc4/vc4_txp.c
438 @@ -380,7 +380,6 @@ static const struct drm_crtc_funcs vc4_t
439 .reset = vc4_crtc_reset,
440 .atomic_duplicate_state = vc4_crtc_duplicate_state,
441 .atomic_destroy_state = vc4_crtc_destroy_state,
442 - .gamma_set = drm_atomic_helper_legacy_gamma_set,
443 .enable_vblank = vc4_txp_enable_vblank,
444 .disable_vblank = vc4_txp_disable_vblank,
445 };
446 --- a/include/drm/drm_atomic_helper.h
447 +++ b/include/drm/drm_atomic_helper.h
448 @@ -147,10 +147,6 @@ int drm_atomic_helper_page_flip_target(
449 uint32_t flags,
450 uint32_t target,
451 struct drm_modeset_acquire_ctx *ctx);
452 -int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,
453 - u16 *red, u16 *green, u16 *blue,
454 - uint32_t size,
455 - struct drm_modeset_acquire_ctx *ctx);
456
457 /**
458 * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC