Skip to content

Commit 0a593f7

Browse files
Rahi374pinchartl
authored andcommitted
media: rkisp1: Add UYVY as an output format
Add support for UYVY as an output format. The uv_swap bit in the MI_XTD_FORMAT_CTRL register that is used for the NV formats does not work for packed YUV formats. Thus, UYVY support is implemented via byte-swapping. This method clearly does not work for implementing support for YVYU and VYUY. Signed-off-by: Paul Elder <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Signed-off-by: Laurent Pinchart <[email protected]> Tested-by: Alexander Stein <[email protected]> Tested-by: Adam Ford <[email protected]>
1 parent fd62bd4 commit 0a593f7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_mp_fmts[] = {
9797
.uv_swap = 0,
9898
.write_format = RKISP1_MI_CTRL_MP_WRITE_YUVINT,
9999
.mbus = MEDIA_BUS_FMT_YUYV8_2X8,
100+
}, {
101+
.fourcc = V4L2_PIX_FMT_UYVY,
102+
.uv_swap = 0,
103+
.yc_swap = 1,
104+
.write_format = RKISP1_MI_CTRL_MP_WRITE_YUVINT,
105+
.mbus = MEDIA_BUS_FMT_YUYV8_2X8,
100106
}, {
101107
.fourcc = V4L2_PIX_FMT_YUV422P,
102108
.uv_swap = 0,
@@ -231,6 +237,13 @@ static const struct rkisp1_capture_fmt_cfg rkisp1_sp_fmts[] = {
231237
.write_format = RKISP1_MI_CTRL_SP_WRITE_INT,
232238
.output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
233239
.mbus = MEDIA_BUS_FMT_YUYV8_2X8,
240+
}, {
241+
.fourcc = V4L2_PIX_FMT_UYVY,
242+
.uv_swap = 0,
243+
.yc_swap = 1,
244+
.write_format = RKISP1_MI_CTRL_SP_WRITE_INT,
245+
.output_format = RKISP1_MI_CTRL_SP_OUTPUT_YUV422,
246+
.mbus = MEDIA_BUS_FMT_YUYV8_2X8,
234247
}, {
235248
.fourcc = V4L2_PIX_FMT_YUV422P,
236249
.uv_swap = 0,
@@ -464,6 +477,20 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap)
464477
rkisp1_write(rkisp1, RKISP1_CIF_MI_XTD_FORMAT_CTRL, reg);
465478
}
466479

480+
/*
481+
* U/V swapping with the MI_XTD_FORMAT_CTRL register only works for
482+
* NV12/NV21 and NV16/NV61, so instead use byte swap to support UYVY.
483+
* YVYU and VYUY cannot be supported with this method.
484+
*/
485+
if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) {
486+
reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT);
487+
if (cap->pix.cfg->yc_swap)
488+
reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES;
489+
else
490+
reg &= ~RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES;
491+
rkisp1_write(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT, reg);
492+
}
493+
467494
rkisp1_mi_config_ctrl(cap);
468495

469496
reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_CTRL);
@@ -507,6 +534,20 @@ static void rkisp1_sp_config(struct rkisp1_capture *cap)
507534
rkisp1_write(rkisp1, RKISP1_CIF_MI_XTD_FORMAT_CTRL, reg);
508535
}
509536

537+
/*
538+
* U/V swapping with the MI_XTD_FORMAT_CTRL register only works for
539+
* NV12/NV21 and NV16/NV61, so instead use byte swap to support UYVY.
540+
* YVYU and VYUY cannot be supported with this method.
541+
*/
542+
if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) {
543+
reg = rkisp1_read(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT);
544+
if (cap->pix.cfg->yc_swap)
545+
reg |= RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES;
546+
else
547+
reg &= ~RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES;
548+
rkisp1_write(rkisp1, RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT, reg);
549+
}
550+
510551
rkisp1_mi_config_ctrl(cap);
511552

512553
mi_ctrl = rkisp1_read(rkisp1, RKISP1_CIF_MI_CTRL);

0 commit comments

Comments
 (0)