aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/0245-drm-amd-display-Use-atomic-helpers-for-gamma.patch
blob: 780cc544b222a98ae6ff6605b5e56ad2c4a2ea78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
From e6c5cd43d18b792b184362f7d6e70e19b8d89e02 Mon Sep 17 00:00:00 2001
From: Harry Wentland <harry.wentland@amd.com>
Date: Sat, 14 Jan 2017 10:00:37 -0500
Subject: [PATCH 0245/4131] drm/amd/display: Use atomic helpers for gamma

We were using set_properties and gamma in a weird way.
This change aligns the properties with other drivers
and allows us to remove a private gamma flag and reuse
atomic helpers for most of this.

Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Acked-by: Harry Wentland <Harry.Wentland@amd.com>
Reviewed-by: Tony Cheng <Tony.Cheng@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 .../drm/amd/display/amdgpu_dm/amdgpu_dm_types.c    | 89 +++++-----------------
 1 file changed, 21 insertions(+), 68 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c
index 470bba51..2f771ea 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c
@@ -60,7 +60,6 @@ struct dm_connector_state {
 #define to_dm_connector_state(x)\
 	container_of((x), struct dm_connector_state, base)
 
-#define AMDGPU_CRTC_MODE_PRIVATE_FLAGS_GAMMASET 1
 
 void amdgpu_dm_encoder_destroy(struct drm_encoder *encoder)
 {
@@ -552,23 +551,18 @@ static void fill_gamma_from_crtc(
 {
 	int i;
 	struct dc_gamma *gamma;
-	uint16_t *red, *green, *blue;
-	int end = (crtc->gamma_size > NUM_OF_RAW_GAMMA_RAMP_RGB_256) ?
-			NUM_OF_RAW_GAMMA_RAMP_RGB_256 : crtc->gamma_size;
-
-	red = crtc->gamma_store;
-	green = red + crtc->gamma_size;
-	blue = green + crtc->gamma_size;
+	struct drm_crtc_state *state = crtc->state;
+	struct drm_color_lut *lut = (struct drm_color_lut *) state->gamma_lut->data;
 
 	gamma = dc_create_gamma();
 
 	if (gamma == NULL)
 		return;
 
-	for (i = 0; i < end; i++) {
-		gamma->red[i] = (unsigned short) red[i];
-		gamma->green[i] = (unsigned short) green[i];
-		gamma->blue[i] = (unsigned short) blue[i];
+	for (i = 0; i < NUM_OF_RAW_GAMMA_RAMP_RGB_256; i++) {
+		gamma->red[i] = lut[i].red;
+		gamma->green[i] = lut[i].green;
+		gamma->blue[i] = lut[i].blue;
 	}
 
 	dc_surface->gamma_correction = gamma;
@@ -602,8 +596,7 @@ static void fill_plane_attributes(
 	surface->in_transfer_func = input_tf;
 
 	/* In case of gamma set, update gamma value */
-	if (crtc->mode.private_flags &
-		AMDGPU_CRTC_MODE_PRIVATE_FLAGS_GAMMASET) {
+	if (state->crtc->state->gamma_lut) {
 		fill_gamma_from_crtc(crtc, surface);
 	}
 }
@@ -720,12 +713,6 @@ static void dm_dc_surface_commit(
 			dc_surface,
 			crtc->primary->state,
 			true);
-	if (crtc->mode.private_flags &
-		AMDGPU_CRTC_MODE_PRIVATE_FLAGS_GAMMASET) {
-		/* reset trigger of gamma */
-		crtc->mode.private_flags &=
-			~AMDGPU_CRTC_MODE_PRIVATE_FLAGS_GAMMASET;
-	}
 
 	dc_surfaces[0] = dc_surface;
 
@@ -1050,50 +1037,6 @@ void amdgpu_dm_crtc_destroy(struct drm_crtc *crtc)
 	kfree(crtc);
 }
 
-static int amdgpu_dm_atomic_crtc_gamma_set(
-		struct drm_crtc *crtc,
-		u16 *red,
-		u16 *green,
-		u16 *blue,
-		uint32_t size)
-{
-	struct drm_device *dev = crtc->dev;
-	struct drm_property *prop = dev->mode_config.prop_crtc_id;
-
-	crtc->state->mode.private_flags |= AMDGPU_CRTC_MODE_PRIVATE_FLAGS_GAMMASET;
-
-	return drm_atomic_helper_crtc_set_property(crtc, prop, 0);
-}
-
-static int dm_crtc_funcs_atomic_set_property(
-	struct drm_crtc *crtc,
-	struct drm_crtc_state *crtc_state,
-	struct drm_property *property,
-	uint64_t val)
-{
-	struct drm_plane_state *plane_state;
-
-	crtc_state->planes_changed = true;
-
-	/*
-	 * Bit of magic done here. We need to ensure
-	 * that planes get update after mode is set.
-	 * So, we need to add primary plane to state,
-	 * and this way atomic_update would be called
-	 * for it
-	 */
-	plane_state =
-		drm_atomic_get_plane_state(
-			crtc_state->state,
-			crtc->primary);
-
-	if (!plane_state)
-		return -EINVAL;
-
-	return 0;
-}
-
-
 static int amdgpu_atomic_helper_page_flip(struct drm_crtc *crtc,
 				struct drm_framebuffer *fb,
 				struct drm_pending_vblank_event *event,
@@ -1177,12 +1120,12 @@ static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs = {
 	.cursor_set = dm_crtc_cursor_set,
 	.cursor_move = dm_crtc_cursor_move,
 	.destroy = amdgpu_dm_crtc_destroy,
-	.gamma_set = amdgpu_dm_atomic_crtc_gamma_set,
+	.gamma_set = drm_atomic_helper_legacy_gamma_set,
 	.set_config = drm_atomic_helper_set_config,
+	.set_property = drm_atomic_helper_crtc_set_property,
 	.page_flip = amdgpu_atomic_helper_page_flip,
 	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
-	.atomic_set_property = dm_crtc_funcs_atomic_set_property
 };
 
 static enum drm_connector_status
@@ -2752,8 +2695,7 @@ int amdgpu_dm_atomic_commit(
 		struct dm_connector_state *dm_state = NULL;
 		enum dm_commit_action action;
 
-		if (!fb || !crtc || !crtc->state->planes_changed ||
-			!crtc->state->active)
+		if (!fb || !crtc || !crtc->state->active)
 			continue;
 
 		action = get_dm_commit_action(crtc->state);
@@ -3187,6 +3129,17 @@ int amdgpu_dm_atomic_check(struct drm_device *dev,
 			}
 			break;
 		}
+
+		/*
+		 * TODO revisit when removing commit action
+		 * and looking at atomic flags directly
+		 */
+
+		/* commit needs planes right now (for gamma, eg.) */
+		/* TODO rework commit to chack crtc for gamma change */
+		ret = drm_atomic_add_affected_planes(state, crtc);
+		if (ret)
+			return ret;
 	}
 
 	for (i = 0; i < set_count; i++) {
-- 
2.7.4