Skip to content

Commit

Permalink
media: coda: jpeg: add CODA960 JPEG encoder support
Browse files Browse the repository at this point in the history
This patch adds JPEG encoding support for CODA960, handling the JPEG
hardware directly. A separate JPEG encoder video device is created due
to the separate hardware unit and different supported pixel formats.
While the hardware can not change subsampling on the fly, it can encode
4:2:2 subsampled images into JPEGs of the same subsampling.

There are two additional tracepoints added to the coda driver that can
be used together with the v4l2:v4l2_qbuf and v4l2:v4l2_dqbuf tracepoints
to to follow video frames through the mem2mem device when encoding or
decoding with the CODA960 JPEG codec:
    coda:coda_jpeg_run
    coda:coda_jpeg_done

Signed-off-by: Philipp Zabel <[email protected]>
Tested-by: Richard Leitner <[email protected]>
[[email protected]: removed unused k and q_data_dst variables]
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
pH5 authored and mchehab committed Dec 16, 2019
1 parent 3bf6883 commit 96f6f62
Show file tree
Hide file tree
Showing 4 changed files with 756 additions and 2 deletions.
39 changes: 37 additions & 2 deletions drivers/media/platform/coda/coda-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ static const struct coda_codec coda7_codecs[] = {
static const struct coda_codec coda9_codecs[] = {
CODA_CODEC(CODA9_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1920, 1088),
CODA_CODEC(CODA9_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1920, 1088),
CODA_CODEC(CODA9_MODE_ENCODE_MJPG, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_JPEG, 8192, 8192),
CODA_CODEC(CODA9_MODE_DECODE_H264, V4L2_PIX_FMT_H264, V4L2_PIX_FMT_YUV420, 1920, 1088),
CODA_CODEC(CODA9_MODE_DECODE_MP2, V4L2_PIX_FMT_MPEG2, V4L2_PIX_FMT_YUV420, 1920, 1088),
CODA_CODEC(CODA9_MODE_DECODE_MP4, V4L2_PIX_FMT_MPEG4, V4L2_PIX_FMT_YUV420, 1920, 1088),
Expand Down Expand Up @@ -235,6 +236,22 @@ static const struct coda_video_device coda_bit_jpeg_decoder = {
},
};

static const struct coda_video_device coda9_jpeg_encoder = {
.name = "coda-jpeg-encoder",
.type = CODA_INST_ENCODER,
.ops = &coda9_jpeg_encode_ops,
.direct = true,
.src_formats = {
V4L2_PIX_FMT_NV12,
V4L2_PIX_FMT_YUV420,
V4L2_PIX_FMT_YVU420,
V4L2_PIX_FMT_YUV422P,
},
.dst_formats = {
V4L2_PIX_FMT_JPEG,
},
};

static const struct coda_video_device *codadx6_video_devices[] = {
&coda_bit_encoder,
};
Expand All @@ -252,6 +269,7 @@ static const struct coda_video_device *coda7_video_devices[] = {
};

static const struct coda_video_device *coda9_video_devices[] = {
&coda9_jpeg_encoder,
&coda_bit_encoder,
&coda_bit_decoder,
};
Expand Down Expand Up @@ -721,7 +739,8 @@ static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f,
ctx->tiled_map_type = GDI_TILED_FRAME_MB_RASTER_MAP;
break;
case V4L2_PIX_FMT_NV12:
if (!disable_tiling && ctx->dev->devtype->product == CODA_960) {
if (!disable_tiling && ctx->use_bit &&
ctx->dev->devtype->product == CODA_960) {
ctx->tiled_map_type = GDI_TILED_FRAME_MB_RASTER_MAP;
break;
}
Expand Down Expand Up @@ -1787,7 +1806,7 @@ static void coda_buf_queue(struct vb2_buffer *vb)
coda_queue_source_change_event(ctx);
}
} else {
if (ctx->inst_type == CODA_INST_ENCODER &&
if ((ctx->inst_type == CODA_INST_ENCODER || !ctx->use_bit) &&
vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
vbuf->sequence = ctx->qsequence++;
v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
Expand Down Expand Up @@ -2996,6 +3015,22 @@ static int coda_probe(struct platform_device *pdev)
return ret;
}

/* JPEG IRQ */
if (dev->devtype->product == CODA_960) {
irq = platform_get_irq_byname(pdev, "jpeg");
if (irq < 0)
return irq;

ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
coda9_jpeg_irq_handler,
IRQF_ONESHOT, CODA_NAME " jpeg",
dev);
if (ret < 0) {
dev_err(&pdev->dev, "failed to request jpeg irq\n");
return ret;
}
}

dev->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev,
NULL);
if (IS_ERR(dev->rstc)) {
Expand Down
Loading

0 comments on commit 96f6f62

Please sign in to comment.