Skip to content

Commit 0f5afa1

Browse files
melissawenalexdeucher
authored andcommitted
drm/amd/display: add CRTC gamma TF driver-specific property
Add AMD pre-defined transfer function property to default DRM CRTC gamma to convert to wire encoding with or without a user gamma LUT. There is no post-blending regamma ROM for pre-defined TF. When setting Gamma TF (!= Identity) and LUT at the same time, the color module will combine the pre-defined TF and the custom LUT values into the LUT that's actually programmed. v2: - enable CRTC prop in the end of driver-specific prop sequence - define inverse EOTFs as supported regamma TFs - reword driver-specific function doc to remove shaper/3D LUT v3: - spell out TF+LUT behavior in the commit and comments (Harry) Reviewed-by: Harry Wentland <[email protected]> Co-developed-by: Joshua Ashton <[email protected]> Signed-off-by: Joshua Ashton <[email protected]> Signed-off-by: Melissa Wen <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 0ef4745 commit 0f5afa1

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ struct amdgpu_mode_info {
425425
* from a combination of pre-defined TF and the custom 1D LUT).
426426
*/
427427
struct drm_property *plane_blend_tf_property;
428+
/* @regamma_tf_property: Transfer function for CRTC regamma
429+
* (post-blending). Possible values are defined by `enum
430+
* amdgpu_transfer_function`. There is no regamma ROM, but we can use
431+
* AMD color modules to program LUT parameters from predefined TF (or
432+
* from a combination of pre-defined TF and the custom 1D LUT).
433+
*/
434+
struct drm_property *regamma_tf_property;
428435
};
429436

430437
#define AMDGPU_MAX_BL_LEVEL 0xFF

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,14 @@ struct dm_crtc_state {
836836
struct dc_info_packet vrr_infopacket;
837837

838838
int abm_level;
839+
840+
/**
841+
* @regamma_tf:
842+
*
843+
* Pre-defined transfer function for converting internal FB -> wire
844+
* encoding.
845+
*/
846+
enum amdgpu_transfer_function regamma_tf;
839847
};
840848

841849
#define to_dm_crtc_state(x) container_of(x, struct dm_crtc_state, base)

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ amdgpu_dm_create_color_properties(struct amdgpu_device *adev)
295295
return -ENOMEM;
296296
adev->mode_info.plane_blend_tf_property = prop;
297297

298+
prop = amdgpu_create_tf_property(adev_to_drm(adev),
299+
"AMD_CRTC_REGAMMA_TF",
300+
amdgpu_inv_eotf);
301+
if (!prop)
302+
return -ENOMEM;
303+
adev->mode_info.regamma_tf_property = prop;
304+
298305
return 0;
299306
}
300307
#endif

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ static struct drm_crtc_state *amdgpu_dm_crtc_duplicate_state(struct drm_crtc *cr
260260
state->freesync_config = cur->freesync_config;
261261
state->cm_has_degamma = cur->cm_has_degamma;
262262
state->cm_is_degamma_srgb = cur->cm_is_degamma_srgb;
263+
state->regamma_tf = cur->regamma_tf;
263264
state->crc_skip_count = cur->crc_skip_count;
264265
state->mpo_requested = cur->mpo_requested;
265266
/* TODO Duplicate dc_stream after objects are stream object is flattened */
@@ -296,6 +297,70 @@ static int amdgpu_dm_crtc_late_register(struct drm_crtc *crtc)
296297
}
297298
#endif
298299

300+
#ifdef AMD_PRIVATE_COLOR
301+
/**
302+
* drm_crtc_additional_color_mgmt - enable additional color properties
303+
* @crtc: DRM CRTC
304+
*
305+
* This function lets the driver enable post-blending CRTC regamma transfer
306+
* function property in addition to DRM CRTC gamma LUT. Default value means
307+
* linear transfer function, which is the default CRTC gamma LUT behaviour
308+
* without this property.
309+
*/
310+
static void
311+
dm_crtc_additional_color_mgmt(struct drm_crtc *crtc)
312+
{
313+
struct amdgpu_device *adev = drm_to_adev(crtc->dev);
314+
315+
if(adev->dm.dc->caps.color.mpc.ogam_ram)
316+
drm_object_attach_property(&crtc->base,
317+
adev->mode_info.regamma_tf_property,
318+
AMDGPU_TRANSFER_FUNCTION_DEFAULT);
319+
}
320+
321+
static int
322+
amdgpu_dm_atomic_crtc_set_property(struct drm_crtc *crtc,
323+
struct drm_crtc_state *state,
324+
struct drm_property *property,
325+
uint64_t val)
326+
{
327+
struct amdgpu_device *adev = drm_to_adev(crtc->dev);
328+
struct dm_crtc_state *acrtc_state = to_dm_crtc_state(state);
329+
330+
if (property == adev->mode_info.regamma_tf_property) {
331+
if (acrtc_state->regamma_tf != val) {
332+
acrtc_state->regamma_tf = val;
333+
acrtc_state->base.color_mgmt_changed |= 1;
334+
}
335+
} else {
336+
drm_dbg_atomic(crtc->dev,
337+
"[CRTC:%d:%s] unknown property [PROP:%d:%s]]\n",
338+
crtc->base.id, crtc->name,
339+
property->base.id, property->name);
340+
return -EINVAL;
341+
}
342+
343+
return 0;
344+
}
345+
346+
static int
347+
amdgpu_dm_atomic_crtc_get_property(struct drm_crtc *crtc,
348+
const struct drm_crtc_state *state,
349+
struct drm_property *property,
350+
uint64_t *val)
351+
{
352+
struct amdgpu_device *adev = drm_to_adev(crtc->dev);
353+
struct dm_crtc_state *acrtc_state = to_dm_crtc_state(state);
354+
355+
if (property == adev->mode_info.regamma_tf_property)
356+
*val = acrtc_state->regamma_tf;
357+
else
358+
return -EINVAL;
359+
360+
return 0;
361+
}
362+
#endif
363+
299364
/* Implemented only the options currently available for the driver */
300365
static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs = {
301366
.reset = amdgpu_dm_crtc_reset_state,
@@ -314,6 +379,10 @@ static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs = {
314379
#if defined(CONFIG_DEBUG_FS)
315380
.late_register = amdgpu_dm_crtc_late_register,
316381
#endif
382+
#ifdef AMD_PRIVATE_COLOR
383+
.atomic_set_property = amdgpu_dm_atomic_crtc_set_property,
384+
.atomic_get_property = amdgpu_dm_atomic_crtc_get_property,
385+
#endif
317386
};
318387

319388
static void amdgpu_dm_crtc_helper_disable(struct drm_crtc *crtc)
@@ -489,6 +558,9 @@ int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm,
489558

490559
drm_mode_crtc_set_gamma_size(&acrtc->base, MAX_COLOR_LEGACY_LUT_ENTRIES);
491560

561+
#ifdef AMD_PRIVATE_COLOR
562+
dm_crtc_additional_color_mgmt(&acrtc->base);
563+
#endif
492564
return 0;
493565

494566
fail:

0 commit comments

Comments
 (0)