Skip to content

Commit e277adc

Browse files
leo-sunli1alexdeucher
authored andcommitted
drm/amd/display: Hookup color management functions
Hookup new color management functions into amdgpu_dm: - Notify DRM that we support CRTC color management during CRTC init - Call color management functions within atomic check to update dc states in preparation for a commit Signed-off-by: Leo (Sunpeng) Li <[email protected]> Reviewed-by: Harry Wentland <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 303afd2 commit e277adc

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

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

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
474474
DRM_DEBUG_DRIVER("amdgpu: freesync_module init done %p.\n",
475475
adev->dm.freesync_module);
476476

477+
amdgpu_dm_init_color_mod();
478+
477479
if (amdgpu_dm_initialize_drm_device(adev)) {
478480
DRM_ERROR(
479481
"amdgpu: failed to initialize sw for display support.\n");
@@ -1953,32 +1955,6 @@ static int fill_plane_attributes_from_fb(struct amdgpu_device *adev,
19531955

19541956
}
19551957

1956-
static void fill_gamma_from_crtc_state(const struct drm_crtc_state *crtc_state,
1957-
struct dc_plane_state *plane_state)
1958-
{
1959-
int i;
1960-
struct dc_gamma *gamma;
1961-
struct drm_color_lut *lut =
1962-
(struct drm_color_lut *) crtc_state->gamma_lut->data;
1963-
1964-
gamma = dc_create_gamma();
1965-
1966-
if (gamma == NULL) {
1967-
WARN_ON(1);
1968-
return;
1969-
}
1970-
1971-
gamma->type = GAMMA_RGB_256;
1972-
gamma->num_entries = GAMMA_RGB_256_ENTRIES;
1973-
for (i = 0; i < GAMMA_RGB_256_ENTRIES; i++) {
1974-
gamma->entries.red[i] = dal_fixed31_32_from_int(lut[i].red);
1975-
gamma->entries.green[i] = dal_fixed31_32_from_int(lut[i].green);
1976-
gamma->entries.blue[i] = dal_fixed31_32_from_int(lut[i].blue);
1977-
}
1978-
1979-
plane_state->gamma_correction = gamma;
1980-
}
1981-
19821958
static int fill_plane_attributes(struct amdgpu_device *adev,
19831959
struct dc_plane_state *dc_plane_state,
19841960
struct drm_plane_state *plane_state,
@@ -2006,14 +1982,13 @@ static int fill_plane_attributes(struct amdgpu_device *adev,
20061982
if (input_tf == NULL)
20071983
return -ENOMEM;
20081984

2009-
input_tf->type = TF_TYPE_PREDEFINED;
2010-
input_tf->tf = TRANSFER_FUNCTION_SRGB;
2011-
20121985
dc_plane_state->in_transfer_func = input_tf;
20131986

2014-
/* In case of gamma set, update gamma value */
2015-
if (crtc_state->gamma_lut)
2016-
fill_gamma_from_crtc_state(crtc_state, dc_plane_state);
1987+
/*
1988+
* Always set input transfer function, since plane state is refreshed
1989+
* every time.
1990+
*/
1991+
ret = amdgpu_dm_set_degamma_lut(crtc_state, dc_plane_state);
20171992

20181993
return ret;
20191994
}
@@ -3227,6 +3202,7 @@ static int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm,
32273202
acrtc->base.enabled = false;
32283203

32293204
dm->adev->mode_info.crtcs[crtc_index] = acrtc;
3205+
drm_crtc_enable_color_mgmt(&acrtc->base, 256, true, 256);
32303206
drm_mode_crtc_set_gamma_size(&acrtc->base, 256);
32313207

32323208
return 0;
@@ -4640,6 +4616,30 @@ static int dm_update_crtcs_state(struct dc *dc,
46404616
/* Release extra reference */
46414617
if (new_stream)
46424618
dc_stream_release(new_stream);
4619+
4620+
/*
4621+
* We want to do dc stream updates that do not require a
4622+
* full modeset below.
4623+
*/
4624+
if (!enable || !aconnector || modereset_required(new_crtc_state))
4625+
continue;
4626+
/*
4627+
* Given above conditions, the dc state cannot be NULL because:
4628+
* 1. We're attempting to enable a CRTC. Which has a...
4629+
* 2. Valid connector attached, and
4630+
* 3. User does not want to reset it (disable or mark inactive,
4631+
* which can happen on a CRTC that's already disabled).
4632+
* => It currently exists.
4633+
*/
4634+
BUG_ON(dm_new_crtc_state->stream == NULL);
4635+
4636+
/* Color managment settings */
4637+
if (dm_new_crtc_state->base.color_mgmt_changed) {
4638+
ret = amdgpu_dm_set_regamma_lut(dm_new_crtc_state);
4639+
if (ret)
4640+
goto fail;
4641+
amdgpu_dm_set_ctm(dm_new_crtc_state);
4642+
}
46434643
}
46444644

46454645
return ret;
@@ -4748,7 +4748,6 @@ static int dm_update_planes_state(struct dc *dc,
47484748
if (ret)
47494749
return ret;
47504750

4751-
47524751
if (!dc_add_plane_to_context(
47534752
dc,
47544753
dm_new_crtc_state->stream,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ void amdgpu_dm_crtc_handle_crc_irq(struct drm_crtc *crtc);
268268
#define amdgpu_dm_crtc_handle_crc_irq(x)
269269
#endif
270270

271+
void amdgpu_dm_init_color_mod(void);
271272
int amdgpu_dm_set_degamma_lut(struct drm_crtc_state *crtc_state,
272273
struct dc_plane_state *dc_plane_state);
273274
void amdgpu_dm_set_ctm(struct dm_crtc_state *crtc);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727
#include "amdgpu_dm.h"
2828
#include "modules/color/color_gamma.h"
2929

30+
/*
31+
* Initialize the color module.
32+
*
33+
* We're not using the full color module, only certain components.
34+
* Only call setup functions for components that we need.
35+
*/
36+
void amdgpu_dm_init_color_mod(void)
37+
{
38+
setup_x_points_distribution();
39+
}
40+
3041

3142
#define MAX_LUT_ENTRIES 256
3243

0 commit comments

Comments
 (0)