Skip to content

Commit 4618cb7

Browse files
committed
gpu: ipu-v3: Add Rec.709 limited range support to DP
Add YCbCr encoding and quantization range parameters to ipu_dp_setup_channel() and configure the CSC DP matrix accordingly. Signed-off-by: Philipp Zabel <[email protected]>
1 parent 17b9a94 commit 4618cb7

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

drivers/gpu/drm/imx/ipuv3-plane.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,14 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
651651
ics = ipu_drm_fourcc_to_colorspace(fb->format->format);
652652
switch (ipu_plane->dp_flow) {
653653
case IPU_DP_FLOW_SYNC_BG:
654-
ipu_dp_setup_channel(ipu_plane->dp, ics, IPUV3_COLORSPACE_RGB);
654+
ipu_dp_setup_channel(ipu_plane->dp, DRM_COLOR_YCBCR_BT601,
655+
DRM_COLOR_YCBCR_LIMITED_RANGE, ics,
656+
IPUV3_COLORSPACE_RGB);
655657
break;
656658
case IPU_DP_FLOW_SYNC_FG:
657-
ipu_dp_setup_channel(ipu_plane->dp, ics,
658-
IPUV3_COLORSPACE_UNKNOWN);
659+
ipu_dp_setup_channel(ipu_plane->dp, DRM_COLOR_YCBCR_BT601,
660+
DRM_COLOR_YCBCR_LIMITED_RANGE, ics,
661+
IPUV3_COLORSPACE_UNKNOWN);
659662
break;
660663
}
661664

drivers/gpu/ipu-v3/ipu-dp.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/io.h>
1111
#include <linux/err.h>
1212

13+
#include <drm/drm_color_mgmt.h>
1314
#include <video/imx-ipu-v3.h>
1415
#include "ipu-prv.h"
1516

@@ -125,6 +126,8 @@ int ipu_dp_set_window_pos(struct ipu_dp *dp, u16 x_pos, u16 y_pos)
125126
EXPORT_SYMBOL_GPL(ipu_dp_set_window_pos);
126127

127128
static void ipu_dp_csc_init(struct ipu_flow *flow,
129+
enum drm_color_encoding ycbcr_enc,
130+
enum drm_color_range range,
128131
enum ipu_color_space in,
129132
enum ipu_color_space out,
130133
u32 place)
@@ -148,7 +151,18 @@ static void ipu_dp_csc_init(struct ipu_flow *flow,
148151
flow->base + DP_CSC_0);
149152
writel(0x200 | (2 << 14) | (0x200 << 16) | (2 << 30),
150153
flow->base + DP_CSC_1);
154+
} else if (ycbcr_enc == DRM_COLOR_YCBCR_BT709) {
155+
/* Rec.709 limited range */
156+
writel(0x095 | (0x000 << 16), flow->base + DP_CSC_A_0);
157+
writel(0x0e5 | (0x095 << 16), flow->base + DP_CSC_A_1);
158+
writel(0x3e5 | (0x3bc << 16), flow->base + DP_CSC_A_2);
159+
writel(0x095 | (0x10e << 16), flow->base + DP_CSC_A_3);
160+
writel(0x000 | (0x3e10 << 16) | (1 << 30),
161+
flow->base + DP_CSC_0);
162+
writel(0x09a | (1 << 14) | (0x3dbe << 16) | (1 << 30),
163+
flow->base + DP_CSC_1);
151164
} else {
165+
/* BT.601 limited range */
152166
writel(0x095 | (0x000 << 16), flow->base + DP_CSC_A_0);
153167
writel(0x0cc | (0x095 << 16), flow->base + DP_CSC_A_1);
154168
writel(0x3ce | (0x398 << 16), flow->base + DP_CSC_A_2);
@@ -165,6 +179,8 @@ static void ipu_dp_csc_init(struct ipu_flow *flow,
165179
}
166180

167181
int ipu_dp_setup_channel(struct ipu_dp *dp,
182+
enum drm_color_encoding ycbcr_enc,
183+
enum drm_color_range range,
168184
enum ipu_color_space in,
169185
enum ipu_color_space out)
170186
{
@@ -183,7 +199,8 @@ int ipu_dp_setup_channel(struct ipu_dp *dp,
183199
* foreground and background are of same colorspace, put
184200
* colorspace converter after combining unit.
185201
*/
186-
ipu_dp_csc_init(flow, flow->foreground.in_cs, flow->out_cs,
202+
ipu_dp_csc_init(flow, ycbcr_enc, range,
203+
flow->foreground.in_cs, flow->out_cs,
187204
DP_COM_CONF_CSC_DEF_BOTH);
188205
} else {
189206
if (flow->foreground.in_cs == IPUV3_COLORSPACE_UNKNOWN ||
@@ -192,10 +209,12 @@ int ipu_dp_setup_channel(struct ipu_dp *dp,
192209
* foreground identical to output, apply color
193210
* conversion on background
194211
*/
195-
ipu_dp_csc_init(flow, flow->background.in_cs,
212+
ipu_dp_csc_init(flow, ycbcr_enc, range,
213+
flow->background.in_cs,
196214
flow->out_cs, DP_COM_CONF_CSC_DEF_BG);
197215
else
198-
ipu_dp_csc_init(flow, flow->foreground.in_cs,
216+
ipu_dp_csc_init(flow, ycbcr_enc, range,
217+
flow->foreground.in_cs,
199218
flow->out_cs, DP_COM_CONF_CSC_DEF_FG);
200219
}
201220

include/video/imx-ipu-v3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/bitmap.h>
1818
#include <linux/fb.h>
1919
#include <linux/of.h>
20+
#include <drm/drm_color_mgmt.h>
2021
#include <media/v4l2-mediabus.h>
2122
#include <video/videomode.h>
2223

@@ -330,6 +331,7 @@ int ipu_dp_enable_channel(struct ipu_dp *dp);
330331
void ipu_dp_disable_channel(struct ipu_dp *dp, bool sync);
331332
void ipu_dp_disable(struct ipu_soc *ipu);
332333
int ipu_dp_setup_channel(struct ipu_dp *dp,
334+
enum drm_color_encoding ycbcr_enc, enum drm_color_range range,
333335
enum ipu_color_space in, enum ipu_color_space out);
334336
int ipu_dp_set_window_pos(struct ipu_dp *, u16 x_pos, u16 y_pos);
335337
int ipu_dp_set_global_alpha(struct ipu_dp *dp, bool enable, u8 alpha,

0 commit comments

Comments
 (0)