* [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
@ 2019-09-24 7:43 ` Xia Jiang
0 siblings, 0 replies; 30+ messages in thread
From: Xia Jiang @ 2019-09-24 7:43 UTC (permalink / raw)
To: Hans Verkuil, Mauro Carvalho Chehab, Rob Herring,
Matthias Brugger, Rick Chang
Cc: Xia Jiang, devicetree, srv_heupstream, linux-kernel, Tomasz Figa,
linux-mediatek, linux-media, linux-arm-kernel, Marek Szyprowski
Add mtk jpeg encode v4l2 driver based on jpeg decode, because that jpeg
decode and encode have great similarities with function operation.
Signed-off-by: Xia Jiang <xia.jiang@mediatek.com>
---
v3: delete Change-Id
only test once handler->error after the last v4l2_ctrl_new_std()
seperate changes of v4l2-ctrls.c and v4l2-controls.h to new patch
v2: fix compliance test fail, check created buffer size in driver
---
drivers/media/platform/mtk-jpeg/Makefile | 5 +-
.../media/platform/mtk-jpeg/mtk_jpeg_core.c | 735 ++++++++++++++----
.../media/platform/mtk-jpeg/mtk_jpeg_core.h | 114 ++-
.../media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h | 7 +-
.../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c | 175 +++++
.../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h | 60 ++
.../platform/mtk-jpeg/mtk_jpeg_enc_reg.h | 49 ++
7 files changed, 975 insertions(+), 170 deletions(-)
create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c
create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h
create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h
diff --git a/drivers/media/platform/mtk-jpeg/Makefile b/drivers/media/platform/mtk-jpeg/Makefile
index 48516dcf96e6..76c33aad0f3f 100644
--- a/drivers/media/platform/mtk-jpeg/Makefile
+++ b/drivers/media/platform/mtk-jpeg/Makefile
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
-mtk_jpeg-objs := mtk_jpeg_core.o mtk_jpeg_dec_hw.o mtk_jpeg_dec_parse.o
+mtk_jpeg-objs := mtk_jpeg_core.o \
+ mtk_jpeg_dec_hw.o \
+ mtk_jpeg_dec_parse.o \
+ mtk_jpeg_enc_hw.o
obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index 5f0990fce8ef..aa18b01802ed 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -3,6 +3,7 @@
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
+ * Xia Jiang <xia.jiang@mediatek.com>
*/
#include <linux/clk.h>
@@ -23,6 +24,7 @@
#include <media/videobuf2-dma-contig.h>
#include <soc/mediatek/smi.h>
+#include "mtk_jpeg_enc_hw.h"
#include "mtk_jpeg_dec_hw.h"
#include "mtk_jpeg_core.h"
#include "mtk_jpeg_dec_parse.h"
@@ -31,7 +33,8 @@ static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
{
.fourcc = V4L2_PIX_FMT_JPEG,
.colplanes = 1,
- .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT,
+ .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT |
+ MTK_JPEG_FMT_FLAG_ENC_CAPTURE,
},
{
.fourcc = V4L2_PIX_FMT_YUV420M,
@@ -51,6 +54,42 @@ static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
.v_align = 3,
.flags = MTK_JPEG_FMT_FLAG_DEC_CAPTURE,
},
+ {
+ .fourcc = V4L2_PIX_FMT_NV12M,
+ .h_sample = {4, 2, 2},
+ .v_sample = {4, 2, 2},
+ .colplanes = 2,
+ .h_align = 4,
+ .v_align = 4,
+ .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
+ },
+ {
+ .fourcc = V4L2_PIX_FMT_NV21M,
+ .h_sample = {4, 2, 2},
+ .v_sample = {4, 2, 2},
+ .colplanes = 2,
+ .h_align = 4,
+ .v_align = 4,
+ .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
+ },
+ {
+ .fourcc = V4L2_PIX_FMT_YUYV,
+ .h_sample = {4, 2, 2},
+ .v_sample = {4, 4, 4},
+ .colplanes = 1,
+ .h_align = 4,
+ .v_align = 3,
+ .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
+ },
+ {
+ .fourcc = V4L2_PIX_FMT_YVYU,
+ .h_sample = {4, 2, 2},
+ .v_sample = {4, 4, 4},
+ .colplanes = 1,
+ .h_align = 4,
+ .v_align = 3,
+ .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
+ },
};
#define MTK_JPEG_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_formats)
@@ -65,11 +104,19 @@ struct mtk_jpeg_src_buf {
struct list_head list;
int flags;
struct mtk_jpeg_dec_param dec_param;
+ struct mtk_jpeg_enc_param enc_param;
};
+#define MTK_MAX_CTRLS_HINT 20
+
static int debug;
module_param(debug, int, 0644);
+static inline struct mtk_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *ctrl)
+{
+ return container_of(ctrl->handler, struct mtk_jpeg_ctx, ctrl_hdl);
+}
+
static inline struct mtk_jpeg_ctx *mtk_jpeg_fh_to_ctx(struct v4l2_fh *fh)
{
return container_of(fh, struct mtk_jpeg_ctx, fh);
@@ -86,10 +133,70 @@ static int mtk_jpeg_querycap(struct file *file, void *priv,
{
struct mtk_jpeg_dev *jpeg = video_drvdata(file);
- strscpy(cap->driver, MTK_JPEG_NAME " decoder", sizeof(cap->driver));
- strscpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
- snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
- dev_name(jpeg->dev));
+ strscpy(cap->driver, MTK_JPEG_NAME, sizeof(cap->driver));
+ if (jpeg->mode == MTK_JPEG_ENC)
+ strscpy(cap->card, MTK_JPEG_NAME " encoder", sizeof(cap->card));
+ else
+ strscpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
+ snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
+ dev_name(jpeg->dev));
+
+ return 0;
+}
+
+static int vidioc_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct mtk_jpeg_ctx *ctx = ctrl_to_ctx(ctrl);
+ struct jpeg_enc_param *p = &ctx->jpeg_param;
+ struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+ int ret = 0;
+
+ switch (ctrl->id) {
+ case V4L2_CID_JPEG_RESTART_INTERVAL:
+ p->restart_interval = ctrl->val;
+ break;
+ case V4L2_CID_JPEG_COMPRESSION_QUALITY:
+ p->enc_quality = ctrl->val;
+ break;
+ case V4L2_CID_JPEG_ENABLE_EXIF:
+ p->enable_exif = ctrl->val;
+ break;
+ }
+
+ v4l2_dbg(2, debug, &jpeg->v4l2_dev, "%s val = %d",
+ v4l2_ctrl_get_name(ctrl->id), ctrl->val);
+
+ return ret;
+}
+
+static const struct v4l2_ctrl_ops mtk_jpeg_ctrl_ops = {
+ .s_ctrl = vidioc_jpeg_s_ctrl,
+};
+
+int mtk_jpeg_ctrls_setup(struct mtk_jpeg_ctx *ctx)
+{
+ const struct v4l2_ctrl_ops *ops = &mtk_jpeg_ctrl_ops;
+ struct v4l2_ctrl_handler *handler = &ctx->ctrl_hdl;
+ struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+
+ v4l2_ctrl_handler_init(handler, MTK_MAX_CTRLS_HINT);
+
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ v4l2_ctrl_new_std(handler, ops, V4L2_CID_JPEG_RESTART_INTERVAL,
+ 0, 100, 1, 0);
+ v4l2_ctrl_new_std(handler, ops,
+ V4L2_CID_JPEG_COMPRESSION_QUALITY, 48, 100, 1,
+ 90);
+ v4l2_ctrl_new_std(handler, ops, V4L2_CID_JPEG_ENABLE_EXIF, 0,
+ 1, 1, 0);
+
+ if (handler->error) {
+ v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
+ return handler->error;
+ }
+ }
+
+ v4l2_ctrl_handler_setup(&ctx->ctrl_hdl);
return 0;
}
@@ -118,23 +225,29 @@ static int mtk_jpeg_enum_fmt(struct mtk_jpeg_fmt *mtk_jpeg_formats, int n,
static int mtk_jpeg_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
+ struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
+
return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
+ ctx->jpeg->mode == MTK_JPEG_ENC ?
+ MTK_JPEG_FMT_FLAG_ENC_CAPTURE :
MTK_JPEG_FMT_FLAG_DEC_CAPTURE);
}
static int mtk_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
+ struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
+
return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
+ ctx->jpeg->mode == MTK_JPEG_ENC ?
+ MTK_JPEG_FMT_FLAG_ENC_OUTPUT :
MTK_JPEG_FMT_FLAG_DEC_OUTPUT);
}
-static struct mtk_jpeg_q_data *mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx,
- enum v4l2_buf_type type)
+static struct mtk_jpeg_q_data *
+mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx, enum v4l2_buf_type type)
{
- if (V4L2_TYPE_IS_OUTPUT(type))
- return &ctx->out_q;
- return &ctx->cap_q;
+ return V4L2_TYPE_IS_OUTPUT(type) ? &ctx->out_q : &ctx->cap_q;
}
static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
@@ -143,9 +256,14 @@ static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
{
unsigned int k, fmt_flag;
- fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
- MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
- MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
+ if (ctx->jpeg->mode == MTK_JPEG_ENC)
+ fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
+ MTK_JPEG_FMT_FLAG_ENC_OUTPUT :
+ MTK_JPEG_FMT_FLAG_ENC_CAPTURE;
+ else
+ fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
+ MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
+ MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
for (k = 0; k < MTK_JPEG_NUM_FORMATS; k++) {
struct mtk_jpeg_fmt *fmt = &mtk_jpeg_formats[k];
@@ -202,7 +320,7 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
{
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
struct mtk_jpeg_dev *jpeg = ctx->jpeg;
- int i;
+ int i, align_w, align_h;
memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
pix_mp->field = V4L2_FIELD_NONE;
@@ -216,36 +334,111 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
pix_mp->pixelformat = fmt->fourcc;
if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
- struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0];
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ pix_mp->height = clamp(pix_mp->height,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT);
+ pix_mp->width = clamp(pix_mp->width,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH);
+ align_w = pix_mp->width;
+ align_h = pix_mp->height;
+ align_w = round_up(align_w, 2);
+ if (pix_mp->num_planes == 1U) {
+ align_w = align_w << 1;
+ mtk_jpeg_bound_align_image(&align_w,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH,
+ 5, &align_h,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT,
+ 3);
+ pix_mp->plane_fmt[0].bytesperline = align_w;
+ pix_mp->plane_fmt[0].sizeimage =
+ align_w * align_h;
+ } else if (pix_mp->num_planes == 2U) {
+ mtk_jpeg_bound_align_image(&align_w,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH,
+ 4, &align_h,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT,
+ 4);
+ pix_mp->plane_fmt[0].bytesperline = align_w;
+ pix_mp->plane_fmt[0].sizeimage =
+ align_w * align_h;
+ pix_mp->plane_fmt[1].bytesperline = align_w;
+ pix_mp->plane_fmt[1].sizeimage =
+ (align_w * align_h) / 2;
+ } else {
+ v4l2_err(&ctx->jpeg->v4l2_dev,
+ "Unsupport num planes = %d\n",
+ pix_mp->num_planes);
+ }
+ goto end;
+ } else {
+ struct v4l2_plane_pix_format *pfmt =
+ &pix_mp->plane_fmt[0];
+
+ mtk_jpeg_bound_align_image(&pix_mp->width,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH, 0,
+ &pix_mp->height,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT, 0);
+
+ pfmt->bytesperline = 0;
+ /* Source size must be aligned to 128 */
+ pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
+ if (pfmt->sizeimage == 0)
+ pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
+
+ goto end;
+ }
+ }
+ /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
+ if (jpeg->mode == MTK_JPEG_ENC) {
mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
MTK_JPEG_MAX_WIDTH, 0,
&pix_mp->height, MTK_JPEG_MIN_HEIGHT,
MTK_JPEG_MAX_HEIGHT, 0);
- memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
- pfmt->bytesperline = 0;
- /* Source size must be aligned to 128 */
- pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
- if (pfmt->sizeimage == 0)
- pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
- goto end;
+ if (fmt->fourcc == V4L2_PIX_FMT_JPEG) {
+ pix_mp->plane_fmt[0].bytesperline = 0;
+ pix_mp->plane_fmt[0].sizeimage =
+ mtk_jpeg_align(pix_mp->plane_fmt[0].sizeimage,
+ 128);
+ if (pix_mp->plane_fmt[0].sizeimage == 0)
+ pix_mp->plane_fmt[0].sizeimage =
+ MTK_JPEG_DEFAULT_SIZEIMAGE;
+ }
+ } else {
+ pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT);
+ pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH);
+ mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH, fmt->h_align,
+ &pix_mp->height,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT, fmt->v_align);
+
+ for (i = 0; i < fmt->colplanes; i++) {
+ struct v4l2_plane_pix_format *pfmt =
+ &pix_mp->plane_fmt[i];
+ u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
+ u32 h = pix_mp->height * fmt->v_sample[i] / 4;
+
+ pfmt->bytesperline = stride;
+ pfmt->sizeimage = stride * h;
+ }
}
- /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
- mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
- MTK_JPEG_MAX_WIDTH, fmt->h_align,
- &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
- MTK_JPEG_MAX_HEIGHT, fmt->v_align);
-
for (i = 0; i < fmt->colplanes; i++) {
- struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[i];
- u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
- u32 h = pix_mp->height * fmt->v_sample[i] / 4;
-
+ struct v4l2_plane_pix_format *pfmt =
+ &pix_mp->plane_fmt[i];
memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
- pfmt->bytesperline = stride;
- pfmt->sizeimage = stride * h;
}
end:
v4l2_dbg(2, debug, &jpeg->v4l2_dev, "wxh:%ux%u\n",
@@ -446,9 +639,9 @@ static int mtk_jpeg_subscribe_event(struct v4l2_fh *fh,
switch (sub->type) {
case V4L2_EVENT_SOURCE_CHANGE:
return v4l2_src_change_event_subscribe(fh, sub);
- default:
- return -EINVAL;
}
+
+ return v4l2_ctrl_subscribe_event(fh, sub);
}
static int mtk_jpeg_g_selection(struct file *file, void *priv,
@@ -571,6 +764,13 @@ static int mtk_jpeg_queue_setup(struct vb2_queue *q,
if (!q_data)
return -EINVAL;
+ if (*num_planes) {
+ for (i = 0; i < *num_planes; i++)
+ if (sizes[i] < q_data->sizeimage[i])
+ return -EINVAL;
+ return 0;
+ }
+
*num_planes = q_data->fmt->colplanes;
for (i = 0; i < q_data->fmt->colplanes; i++) {
sizes[i] = q_data->sizeimage[i];
@@ -651,10 +851,92 @@ static void mtk_jpeg_set_queue_data(struct mtk_jpeg_ctx *ctx,
param->dec_w, param->dec_h);
}
+static void mtk_jpeg_set_param(struct mtk_jpeg_ctx *ctx,
+ struct mtk_jpeg_enc_param *param)
+{
+ struct mtk_jpeg_q_data *q_data_src = &ctx->out_q;
+ struct jpeg_enc_param *jpeg_params = &ctx->jpeg_param;
+ struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+ u32 width_even;
+ u32 is_420;
+ u32 padding_width;
+ u32 padding_height;
+
+ switch (q_data_src->fmt->fourcc) {
+ case V4L2_PIX_FMT_YUYV:
+ param->enc_format = JPEG_YUV_FORMAT_YUYV;
+ break;
+ case V4L2_PIX_FMT_YVYU:
+ param->enc_format = JPEG_YUV_FORMAT_YVYU;
+ break;
+ case V4L2_PIX_FMT_NV12M:
+ param->enc_format = JPEG_YUV_FORMAT_NV12;
+ break;
+ case V4L2_PIX_FMT_NV21M:
+ param->enc_format = JPEG_YUV_FORMAT_NV12;
+ break;
+ default:
+ v4l2_err(&jpeg->v4l2_dev, "Unsupport fourcc =%d\n",
+ q_data_src->fmt->fourcc);
+ break;
+ }
+ param->enc_w = q_data_src->w;
+ param->enc_h = q_data_src->h;
+
+ if (jpeg_params->enc_quality >= 97)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q97;
+ else if (jpeg_params->enc_quality >= 95)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q95;
+ else if (jpeg_params->enc_quality >= 92)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q92;
+ else if (jpeg_params->enc_quality >= 90)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q90;
+ else if (jpeg_params->enc_quality >= 87)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q87;
+ else if (jpeg_params->enc_quality >= 84)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q84;
+ else if (jpeg_params->enc_quality >= 80)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q80;
+ else if (jpeg_params->enc_quality >= 74)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q74;
+ else if (jpeg_params->enc_quality >= 64)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q64;
+ else if (jpeg_params->enc_quality >= 60)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q60;
+ else
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q48;
+
+ param->enable_exif = jpeg_params->enable_exif;
+ param->restart_interval = jpeg_params->restart_interval;
+
+ width_even = ((param->enc_w + 1) >> 1) << 1;
+ is_420 = (param->enc_format == JPEG_YUV_FORMAT_NV12 ||
+ param->enc_format == JPEG_YUV_FORMAT_NV12) ? 1 : 0;
+ padding_width = mtk_jpeg_align(param->enc_w, 16);
+ padding_height = mtk_jpeg_align(param->enc_h, is_420 ? 16 : 8);
+ if (!is_420)
+ width_even = width_even << 1;
+
+ param->img_stride = mtk_jpeg_align(width_even, (is_420 ? 16 : 32));
+ param->mem_stride = mtk_jpeg_align(width_even, (is_420 ? 16 : 32));
+ param->total_encdu =
+ ((padding_width >> 4) * (padding_height >> (is_420 ? 4 : 3)) *
+ (is_420 ? 6 : 4)) - 1;
+
+ v4l2_dbg(0, 2, &jpeg->v4l2_dev, "fmt %d, w,h %d,%d, enable_exif %d,",
+ "enc_quality %d, restart_interval %d,img_stride %d,",
+ "mem_stride %d,totalEncDu %d\n",
+ param->enc_format, param->enc_w, param->enc_h,
+ param->enable_exif, param->enc_quality,
+ param->restart_interval, param->img_stride,
+ param->mem_stride, param->total_encdu);
+}
+
static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
{
struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct mtk_jpeg_dec_param *param;
+ struct mtk_jpeg_enc_param *enc_param;
struct mtk_jpeg_dev *jpeg = ctx->jpeg;
struct mtk_jpeg_src_buf *jpeg_src_buf;
bool header_valid;
@@ -666,29 +948,45 @@ static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
goto end;
jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb);
- param = &jpeg_src_buf->dec_param;
- memset(param, 0, sizeof(*param));
-
- if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
- v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
- goto end;
- }
- header_valid = mtk_jpeg_parse(param, (u8 *)vb2_plane_vaddr(vb, 0),
- vb2_get_plane_payload(vb, 0));
- if (!header_valid) {
- v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
- vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
- return;
- }
-
- if (ctx->state == MTK_JPEG_INIT) {
- struct vb2_queue *dst_vq = v4l2_m2m_get_vq(
- ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ enc_param = &jpeg_src_buf->enc_param;
+ memset(enc_param, 0, sizeof(*enc_param));
+ mtk_jpeg_set_param(ctx, enc_param);
+ if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
+ v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos");
+ goto end;
+ }
+ if (ctx->state == MTK_JPEG_INIT)
+ ctx->state = MTK_JPEG_RUNNING;
+ } else {
+ param = &jpeg_src_buf->dec_param;
+ memset(param, 0, sizeof(*param));
+
+ if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
+ v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
+ goto end;
+ }
+ header_valid = mtk_jpeg_parse(param,
+ (u8 *)vb2_plane_vaddr(vb, 0),
+ vb2_get_plane_payload(vb, 0));
+ if (!header_valid) {
+ v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
+ vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+ return;
+ }
- mtk_jpeg_queue_src_chg_event(ctx);
- mtk_jpeg_set_queue_data(ctx, param);
- ctx->state = vb2_is_streaming(dst_vq) ?
- MTK_JPEG_SOURCE_CHANGE : MTK_JPEG_RUNNING;
+ if (ctx->state == MTK_JPEG_INIT) {
+ struct vb2_queue *dst_vq;
+
+ dst_vq = v4l2_m2m_get_vq
+ (ctx->fh.m2m_ctx,
+ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+ mtk_jpeg_queue_src_chg_event(ctx);
+ mtk_jpeg_set_queue_data(ctx, param);
+ ctx->state = vb2_is_streaming(dst_vq) ?
+ MTK_JPEG_SOURCE_CHANGE :
+ MTK_JPEG_RUNNING;
+ }
}
end:
v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, to_vb2_v4l2_buffer(vb));
@@ -731,16 +1029,16 @@ static void mtk_jpeg_stop_streaming(struct vb2_queue *q)
* subsampling. Update capture queue when the stream is off.
*/
if (ctx->state == MTK_JPEG_SOURCE_CHANGE &&
- !V4L2_TYPE_IS_OUTPUT(q->type)) {
+ !V4L2_TYPE_IS_OUTPUT(q->type) &&
+ ctx->jpeg->mode == MTK_JPEG_DEC) {
struct mtk_jpeg_src_buf *src_buf;
vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
src_buf = mtk_jpeg_vb2_to_srcbuf(&vb->vb2_buf);
mtk_jpeg_set_queue_data(ctx, &src_buf->dec_param);
ctx->state = MTK_JPEG_RUNNING;
- } else if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+ } else if (V4L2_TYPE_IS_OUTPUT(q->type))
ctx->state = MTK_JPEG_INIT;
- }
while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
@@ -795,6 +1093,28 @@ static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,
return 0;
}
+static void mtk_jpeg_set_enc_dst(struct mtk_jpeg_ctx *ctx,
+ struct vb2_buffer *dst_buf,
+ struct mtk_jpeg_enc_bs *bs)
+{
+ bs->dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0) &
+ (~JPEG_ENC_DST_ADDR_OFFSET_MASK);
+ bs->dma_addr_offset = 0;
+ bs->dma_addr_offsetmask = bs->dma_addr & JPEG_ENC_DST_ADDR_OFFSET_MASK;
+ bs->size = mtk_jpeg_align(vb2_plane_size(dst_buf, 0), 128);
+}
+
+static void mtk_jpeg_set_enc_src(struct mtk_jpeg_ctx *ctx,
+ struct vb2_buffer *src_buf,
+ struct mtk_jpeg_enc_fb *fb)
+{
+ int i;
+
+ for (i = 0; i < src_buf->num_planes; i++)
+ fb->fb_addr[i].dma_addr =
+ vb2_dma_contig_plane_dma_addr(src_buf, i);
+}
+
static void mtk_jpeg_device_run(void *priv)
{
struct mtk_jpeg_ctx *ctx = priv;
@@ -805,6 +1125,8 @@ static void mtk_jpeg_device_run(void *priv)
struct mtk_jpeg_src_buf *jpeg_src_buf;
struct mtk_jpeg_bs bs;
struct mtk_jpeg_fb fb;
+ struct mtk_jpeg_enc_bs enc_bs;
+ struct mtk_jpeg_enc_fb enc_fb;
int i;
src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
@@ -815,30 +1137,45 @@ static void mtk_jpeg_device_run(void *priv)
for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
vb2_set_plane_payload(&dst_buf->vb2_buf, i, 0);
buf_state = VB2_BUF_STATE_DONE;
- goto dec_end;
+ goto device_run_end;
}
- if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) {
- mtk_jpeg_queue_src_chg_event(ctx);
- ctx->state = MTK_JPEG_SOURCE_CHANGE;
- v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
- return;
- }
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ mtk_jpeg_set_enc_dst(ctx, &dst_buf->vb2_buf, &enc_bs);
+ mtk_jpeg_set_enc_src(ctx, &src_buf->vb2_buf, &enc_fb);
+
+ spin_lock_irqsave(&jpeg->hw_lock, flags);
+ mtk_jpeg_enc_reset(jpeg->reg_base);
+ mtk_jpeg_enc_set_config(jpeg->reg_base,
+ &jpeg_src_buf->enc_param, &enc_bs,
+ &enc_fb);
+
+ mtk_jpeg_enc_start(jpeg->reg_base);
+ } else {
+ if (mtk_jpeg_check_resolution_change
+ (ctx, &jpeg_src_buf->dec_param)) {
+ mtk_jpeg_queue_src_chg_event(ctx);
+ ctx->state = MTK_JPEG_SOURCE_CHANGE;
+ v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+ return;
+ }
- mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
- if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, &dst_buf->vb2_buf, &fb))
- goto dec_end;
+ mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
+ if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param,
+ &dst_buf->vb2_buf, &fb))
+ goto device_run_end;
- spin_lock_irqsave(&jpeg->hw_lock, flags);
- mtk_jpeg_dec_reset(jpeg->dec_reg_base);
- mtk_jpeg_dec_set_config(jpeg->dec_reg_base,
- &jpeg_src_buf->dec_param, &bs, &fb);
+ spin_lock_irqsave(&jpeg->hw_lock, flags);
+ mtk_jpeg_dec_reset(jpeg->reg_base);
+ mtk_jpeg_dec_set_config(jpeg->reg_base,
+ &jpeg_src_buf->dec_param, &bs, &fb);
- mtk_jpeg_dec_start(jpeg->dec_reg_base);
+ mtk_jpeg_dec_start(jpeg->reg_base);
+ }
spin_unlock_irqrestore(&jpeg->hw_lock, flags);
return;
-dec_end:
+device_run_end:
v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
v4l2_m2m_buf_done(src_buf, buf_state);
@@ -898,30 +1235,30 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
ret = mtk_smi_larb_get(jpeg->larb);
if (ret)
dev_err(jpeg->dev, "mtk_smi_larb_get larbvdec fail %d\n", ret);
- clk_prepare_enable(jpeg->clk_jdec_smi);
- clk_prepare_enable(jpeg->clk_jdec);
+ if (jpeg->mode == MTK_JPEG_DEC)
+ clk_prepare_enable(jpeg->clk_jpeg_smi);
+ clk_prepare_enable(jpeg->clk_jpeg);
}
static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg)
{
- clk_disable_unprepare(jpeg->clk_jdec);
- clk_disable_unprepare(jpeg->clk_jdec_smi);
+ clk_disable_unprepare(jpeg->clk_jpeg);
+ if (jpeg->mode == MTK_JPEG_DEC)
+ clk_disable_unprepare(jpeg->clk_jpeg_smi);
mtk_smi_larb_put(jpeg->larb);
}
-static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
+static irqreturn_t mtk_jpeg_irq(int irq, void *priv)
{
struct mtk_jpeg_dev *jpeg = priv;
struct mtk_jpeg_ctx *ctx;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct mtk_jpeg_src_buf *jpeg_src_buf;
enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
- u32 dec_irq_ret;
- u32 dec_ret;
+ u32 irq_ret;
+ u32 ret, result_size;
int i;
- dec_ret = mtk_jpeg_dec_get_int_status(jpeg->dec_reg_base);
- dec_irq_ret = mtk_jpeg_dec_enum_result(dec_ret);
ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev);
if (!ctx) {
v4l2_err(&jpeg->v4l2_dev, "Context is NULL\n");
@@ -932,21 +1269,42 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
- if (dec_irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
- mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ ret = mtk_jpeg_enc_get_int_status(jpeg->reg_base);
+ irq_ret = mtk_jpeg_enc_enum_result(jpeg->reg_base, ret,
+ &result_size);
- if (dec_irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
- dev_err(jpeg->dev, "decode failed\n");
- goto dec_end;
- }
+ if (irq_ret >= MTK_JPEG_ENC_RESULT_STALL)
+ mtk_jpeg_enc_reset(jpeg->reg_base);
+
+ if (irq_ret != MTK_JPEG_ENC_RESULT_DONE) {
+ dev_err(jpeg->dev, "encode failed\n");
+ goto irq_end;
+ }
- for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
- vb2_set_plane_payload(&dst_buf->vb2_buf, i,
- jpeg_src_buf->dec_param.comp_size[i]);
+ vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
+ result_size);
+ } else {
+ ret = mtk_jpeg_dec_get_int_status(jpeg->reg_base);
+ irq_ret = mtk_jpeg_dec_enum_result(ret);
+
+ if (irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
+ mtk_jpeg_dec_reset(jpeg->reg_base);
+
+ if (irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
+ dev_err(jpeg->dev, "decode failed\n");
+ goto irq_end;
+ }
+
+ for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
+ vb2_set_plane_payload
+ (&dst_buf->vb2_buf, i,
+ jpeg_src_buf->dec_param.comp_size[i]);
+ }
buf_state = VB2_BUF_STATE_DONE;
-dec_end:
+irq_end:
v4l2_m2m_buf_done(src_buf, buf_state);
v4l2_m2m_buf_done(dst_buf, buf_state);
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
@@ -956,32 +1314,72 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
static void mtk_jpeg_set_default_params(struct mtk_jpeg_ctx *ctx)
{
struct mtk_jpeg_q_data *q = &ctx->out_q;
- int i;
+ int i, align_w, align_h;
+
+ ctx->fh.ctrl_handler = &ctx->ctrl_hdl;
ctx->colorspace = V4L2_COLORSPACE_JPEG,
ctx->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
ctx->quantization = V4L2_QUANTIZATION_DEFAULT;
ctx->xfer_func = V4L2_XFER_FUNC_DEFAULT;
- q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
+ if (ctx->jpeg->mode == MTK_JPEG_ENC) {
+ q->w = MTK_JPEG_MIN_WIDTH;
+ q->h = MTK_JPEG_MIN_HEIGHT;
+
+ q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUYV,
MTK_JPEG_FMT_TYPE_OUTPUT);
- q->w = MTK_JPEG_MIN_WIDTH;
- q->h = MTK_JPEG_MIN_HEIGHT;
- q->bytesperline[0] = 0;
- q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
+
+ align_w = q->w;
+ align_h = q->h;
+ align_w = round_up(align_w, 2);
+ align_w = align_w << 1;
+ v4l_bound_align_image(&align_w,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH, 5,
+ &align_h,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT, 3, 0);
+
+ if (align_w < MTK_JPEG_MIN_WIDTH &&
+ (align_w + 32) <= MTK_JPEG_MAX_WIDTH)
+ align_w += 32;
+ if (align_h < MTK_JPEG_MIN_HEIGHT &&
+ (align_h + 8) <= MTK_JPEG_MAX_HEIGHT)
+ align_h += 8;
+
+ q->sizeimage[0] = align_w * align_h;
+ q->bytesperline[0] = align_w;
+ } else {
+ q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
+ MTK_JPEG_FMT_TYPE_OUTPUT);
+ q->w = MTK_JPEG_MIN_WIDTH;
+ q->h = MTK_JPEG_MIN_HEIGHT;
+ q->bytesperline[0] = 0;
+ q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
+ }
q = &ctx->cap_q;
- q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
+ if (ctx->jpeg->mode == MTK_JPEG_ENC) {
+ q->w = MTK_JPEG_MIN_WIDTH;
+ q->h = MTK_JPEG_MIN_HEIGHT;
+ q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
+ MTK_JPEG_FMT_TYPE_CAPTURE);
+ q->bytesperline[0] = 0;
+ q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
+ } else {
+ q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
MTK_JPEG_FMT_TYPE_CAPTURE);
- q->w = MTK_JPEG_MIN_WIDTH;
- q->h = MTK_JPEG_MIN_HEIGHT;
+ q->w = MTK_JPEG_MIN_WIDTH;
+ q->h = MTK_JPEG_MIN_HEIGHT;
- for (i = 0; i < q->fmt->colplanes; i++) {
- u32 stride = q->w * q->fmt->h_sample[i] / 4;
- u32 h = q->h * q->fmt->v_sample[i] / 4;
+ for (i = 0; i < q->fmt->colplanes; i++) {
+ u32 stride = q->w * q->fmt->h_sample[i] / 4;
+ u32 h = q->h * q->fmt->v_sample[i] / 4;
- q->bytesperline[i] = stride;
- q->sizeimage[i] = stride * h;
+ q->bytesperline[i] = stride;
+ q->sizeimage[i] = stride * h;
+ }
}
}
@@ -1013,6 +1411,13 @@ static int mtk_jpeg_open(struct file *file)
goto error;
}
+ ret = mtk_jpeg_ctrls_setup(ctx);
+ if (ret) {
+ v4l2_err(&jpeg->v4l2_dev, "Failed to setup controls() (%d)\n",
+ ret);
+ goto error;
+ }
+
mtk_jpeg_set_default_params(ctx);
mutex_unlock(&jpeg->lock);
return 0;
@@ -1033,6 +1438,7 @@ static int mtk_jpeg_release(struct file *file)
mutex_lock(&jpeg->lock);
v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
+ v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
v4l2_fh_del(&ctx->fh);
v4l2_fh_exit(&ctx->fh);
kfree(ctx);
@@ -1057,6 +1463,7 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
node = of_parse_phandle(jpeg->dev->of_node, "mediatek,larb", 0);
if (!node)
return -EINVAL;
+
pdev = of_find_device_by_node(node);
if (WARN_ON(!pdev)) {
of_node_put(node);
@@ -1066,19 +1473,24 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
jpeg->larb = &pdev->dev;
- jpeg->clk_jdec = devm_clk_get(jpeg->dev, "jpgdec");
- if (IS_ERR(jpeg->clk_jdec))
- return PTR_ERR(jpeg->clk_jdec);
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ jpeg->clk_jpeg = devm_clk_get(jpeg->dev, "jpgenc");
+ return PTR_ERR_OR_ZERO(jpeg->clk_jpeg);
+ }
+
+ jpeg->clk_jpeg = devm_clk_get(jpeg->dev, "jpgdec");
+ if (IS_ERR(jpeg->clk_jpeg))
+ return PTR_ERR(jpeg->clk_jpeg);
- jpeg->clk_jdec_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
- return PTR_ERR_OR_ZERO(jpeg->clk_jdec_smi);
+ jpeg->clk_jpeg_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
+ return PTR_ERR_OR_ZERO(jpeg->clk_jpeg_smi);
}
static int mtk_jpeg_probe(struct platform_device *pdev)
{
struct mtk_jpeg_dev *jpeg;
struct resource *res;
- int dec_irq;
+ int jpeg_irq;
int ret;
jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL);
@@ -1088,28 +1500,26 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
mutex_init(&jpeg->lock);
spin_lock_init(&jpeg->hw_lock);
jpeg->dev = &pdev->dev;
+ jpeg->mode = (enum mtk_jpeg_mode)of_device_get_match_data(jpeg->dev);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- jpeg->dec_reg_base = devm_ioremap_resource(&pdev->dev, res);
- if (IS_ERR(jpeg->dec_reg_base)) {
- ret = PTR_ERR(jpeg->dec_reg_base);
+ jpeg->reg_base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(jpeg->reg_base)) {
+ ret = PTR_ERR(jpeg->reg_base);
return ret;
}
- res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- dec_irq = platform_get_irq(pdev, 0);
- if (!res || dec_irq < 0) {
- dev_err(&pdev->dev, "Failed to get dec_irq %d.\n", dec_irq);
- ret = -EINVAL;
- return ret;
+ jpeg_irq = platform_get_irq(pdev, 0);
+ if (jpeg_irq < 0) {
+ dev_err(&pdev->dev, "Failed to get jpeg_irq %d.\n", jpeg_irq);
+ return jpeg_irq;
}
- ret = devm_request_irq(&pdev->dev, dec_irq, mtk_jpeg_dec_irq, 0,
+ ret = devm_request_irq(&pdev->dev, jpeg_irq, mtk_jpeg_irq, 0,
pdev->name, jpeg);
if (ret) {
- dev_err(&pdev->dev, "Failed to request dec_irq %d (%d)\n",
- dec_irq, ret);
- ret = -EINVAL;
+ dev_err(&pdev->dev, "Failed to request jpeg_irq %d (%d)\n",
+ jpeg_irq, ret);
goto err_req_irq;
}
@@ -1133,33 +1543,35 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
goto err_m2m_init;
}
- jpeg->dec_vdev = video_device_alloc();
- if (!jpeg->dec_vdev) {
+ jpeg->vfd_jpeg = video_device_alloc();
+ if (!jpeg->vfd_jpeg) {
ret = -ENOMEM;
- goto err_dec_vdev_alloc;
+ goto err_vfd_jpeg_alloc;
}
- snprintf(jpeg->dec_vdev->name, sizeof(jpeg->dec_vdev->name),
- "%s-dec", MTK_JPEG_NAME);
- jpeg->dec_vdev->fops = &mtk_jpeg_fops;
- jpeg->dec_vdev->ioctl_ops = &mtk_jpeg_ioctl_ops;
- jpeg->dec_vdev->minor = -1;
- jpeg->dec_vdev->release = video_device_release;
- jpeg->dec_vdev->lock = &jpeg->lock;
- jpeg->dec_vdev->v4l2_dev = &jpeg->v4l2_dev;
- jpeg->dec_vdev->vfl_dir = VFL_DIR_M2M;
- jpeg->dec_vdev->device_caps = V4L2_CAP_STREAMING |
+ snprintf(jpeg->vfd_jpeg->name, sizeof(jpeg->vfd_jpeg->name),
+ "%s-%s", MTK_JPEG_NAME,
+ jpeg->mode == MTK_JPEG_ENC ? "enc" : "dec");
+ jpeg->vfd_jpeg->fops = &mtk_jpeg_fops;
+ jpeg->vfd_jpeg->ioctl_ops = &mtk_jpeg_ioctl_ops;
+ jpeg->vfd_jpeg->minor = -1;
+ jpeg->vfd_jpeg->release = video_device_release;
+ jpeg->vfd_jpeg->lock = &jpeg->lock;
+ jpeg->vfd_jpeg->v4l2_dev = &jpeg->v4l2_dev;
+ jpeg->vfd_jpeg->vfl_dir = VFL_DIR_M2M;
+ jpeg->vfd_jpeg->device_caps = V4L2_CAP_STREAMING |
V4L2_CAP_VIDEO_M2M_MPLANE;
- ret = video_register_device(jpeg->dec_vdev, VFL_TYPE_GRABBER, 3);
+ ret = video_register_device(jpeg->vfd_jpeg, VFL_TYPE_GRABBER, -1);
if (ret) {
v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n");
- goto err_dec_vdev_register;
+ goto err_vfd_jpeg_register;
}
- video_set_drvdata(jpeg->dec_vdev, jpeg);
+ video_set_drvdata(jpeg->vfd_jpeg, jpeg);
v4l2_info(&jpeg->v4l2_dev,
- "decoder device registered as /dev/video%d (%d,%d)\n",
- jpeg->dec_vdev->num, VIDEO_MAJOR, jpeg->dec_vdev->minor);
+ "jpeg device %d registered as /dev/video%d (%d,%d)\n",
+ jpeg->mode, jpeg->vfd_jpeg->num, VIDEO_MAJOR,
+ jpeg->vfd_jpeg->minor);
platform_set_drvdata(pdev, jpeg);
@@ -1167,10 +1579,10 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
return 0;
-err_dec_vdev_register:
- video_device_release(jpeg->dec_vdev);
+err_vfd_jpeg_register:
+ video_device_release(jpeg->vfd_jpeg);
-err_dec_vdev_alloc:
+err_vfd_jpeg_alloc:
v4l2_m2m_release(jpeg->m2m_dev);
err_m2m_init:
@@ -1190,8 +1602,8 @@ static int mtk_jpeg_remove(struct platform_device *pdev)
struct mtk_jpeg_dev *jpeg = platform_get_drvdata(pdev);
pm_runtime_disable(&pdev->dev);
- video_unregister_device(jpeg->dec_vdev);
- video_device_release(jpeg->dec_vdev);
+ video_unregister_device(jpeg->vfd_jpeg);
+ video_device_release(jpeg->vfd_jpeg);
v4l2_m2m_release(jpeg->m2m_dev);
v4l2_device_unregister(&jpeg->v4l2_dev);
@@ -1202,7 +1614,11 @@ static __maybe_unused int mtk_jpeg_pm_suspend(struct device *dev)
{
struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
- mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+ if (jpeg->mode == MTK_JPEG_ENC)
+ mtk_jpeg_enc_reset(jpeg->reg_base);
+ else
+ mtk_jpeg_dec_reset(jpeg->reg_base);
+
mtk_jpeg_clk_off(jpeg);
return 0;
@@ -1213,7 +1629,10 @@ static __maybe_unused int mtk_jpeg_pm_resume(struct device *dev)
struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
mtk_jpeg_clk_on(jpeg);
- mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+ if (jpeg->mode == MTK_JPEG_ENC)
+ mtk_jpeg_enc_reset(jpeg->reg_base);
+ else
+ mtk_jpeg_dec_reset(jpeg->reg_base);
return 0;
}
@@ -1249,11 +1668,15 @@ static const struct dev_pm_ops mtk_jpeg_pm_ops = {
static const struct of_device_id mtk_jpeg_match[] = {
{
.compatible = "mediatek,mt8173-jpgdec",
- .data = NULL,
+ .data = (void *)MTK_JPEG_DEC,
},
{
.compatible = "mediatek,mt2701-jpgdec",
- .data = NULL,
+ .data = (void *)MTK_JPEG_DEC,
+ },
+ {
+ .compatible = "mediatek,mtk-jpgenc",
+ .data = (void *)MTK_JPEG_ENC,
},
{},
};
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
index 999bd1427809..9fbf0373971b 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
@@ -3,6 +3,7 @@
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
+ * Xia Jiang <xia.jiang@mediatek.com>
*/
#ifndef _MTK_JPEG_CORE_H
@@ -17,6 +18,8 @@
#define MTK_JPEG_FMT_FLAG_DEC_OUTPUT BIT(0)
#define MTK_JPEG_FMT_FLAG_DEC_CAPTURE BIT(1)
+#define MTK_JPEG_FMT_FLAG_ENC_OUTPUT BIT(2)
+#define MTK_JPEG_FMT_FLAG_ENC_CAPTURE BIT(3)
#define MTK_JPEG_FMT_TYPE_OUTPUT 1
#define MTK_JPEG_FMT_TYPE_CAPTURE 2
@@ -28,12 +31,63 @@
#define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024)
+#define MTK_JPEG_ENCODE 0
+#define MTK_JPEG_DECODE 1
+
+/**
+ * enum mtk_jpeg_ctx_state - contex state of jpeg
+ */
enum mtk_jpeg_ctx_state {
MTK_JPEG_INIT = 0,
MTK_JPEG_RUNNING,
MTK_JPEG_SOURCE_CHANGE,
};
+/**
+ * enum mtk_jpeg_mode - mode of jpeg
+ */
+enum mtk_jpeg_mode {
+ MTK_JPEG_ENC,
+ MTK_JPEG_DEC,
+};
+
+/**
+ * enum jpeg_enc_yuv_fmt - yuv format of jpeg enc
+ */
+enum jpeg_enc_yuv_fmt {
+ JPEG_YUV_FORMAT_YUYV = 0,
+ JPEG_YUV_FORMAT_YVYU = 1,
+ JPEG_YUV_FORMAT_NV12 = 2,
+ JEPG_YUV_FORMAT_NV21 = 3,
+};
+
+/**
+ * enum JPEG_ENCODE_QUALITY_ENUM - number of jpeg encoder quality
+ */
+enum JPEG_ENCODE_QUALITY_ENUM {
+ JPEG_ENCODE_QUALITY_Q60 = 0x0,
+ JPEG_ENCODE_QUALITY_Q80 = 0x1,
+ JPEG_ENCODE_QUALITY_Q90 = 0x2,
+ JPEG_ENCODE_QUALITY_Q95 = 0x3,
+
+ JPEG_ENCODE_QUALITY_Q39 = 0x4,
+ JPEG_ENCODE_QUALITY_Q68 = 0x5,
+ JPEG_ENCODE_QUALITY_Q84 = 0x6,
+ JPEG_ENCODE_QUALITY_Q92 = 0x7,
+
+ JPEG_ENCODE_QUALITY_Q48 = 0x8,
+ JPEG_ENCODE_QUALITY_Q74 = 0xA,
+ JPEG_ENCODE_QUALITY_Q87 = 0xB,
+
+ JPEG_ENCODE_QUALITY_Q34 = 0xC,
+ JPEG_ENCODE_QUALITY_Q64 = 0xE,
+ JPEG_ENCODE_QUALITY_Q82 = 0xF,
+
+ JPEG_ENCODE_QUALITY_Q97 = 0x10,
+
+ JPEG_ENCODE_QUALITY_ALL = 0xFFFFFFFF
+};
+
/**
* struct mt_jpeg - JPEG IP abstraction
* @lock: the mutex protecting this structure
@@ -43,11 +97,12 @@ enum mtk_jpeg_ctx_state {
* @v4l2_dev: v4l2 device for mem2mem mode
* @m2m_dev: v4l2 mem2mem device data
* @alloc_ctx: videobuf2 memory allocator's context
- * @dec_vdev: video device node for decoder mem2mem mode
- * @dec_reg_base: JPEG registers mapping
- * @clk_jdec: JPEG hw working clock
- * @clk_jdec_smi: JPEG SMI bus clock
+ * @vfd_jpeg: video device node for jpeg mem2mem mode
+ * @reg_base: JPEG registers mapping
+ * @clk_jpeg: JPEG hw working clock
+ * @clk_jpeg_smi: JPEG SMI bus clock
* @larb: SMI device
+ * @mode: compression (encode) operation or decompression (decode)
*/
struct mtk_jpeg_dev {
struct mutex lock;
@@ -57,11 +112,12 @@ struct mtk_jpeg_dev {
struct v4l2_device v4l2_dev;
struct v4l2_m2m_dev *m2m_dev;
void *alloc_ctx;
- struct video_device *dec_vdev;
- void __iomem *dec_reg_base;
- struct clk *clk_jdec;
- struct clk *clk_jdec_smi;
+ struct video_device *vfd_jpeg;
+ void __iomem *reg_base;
+ struct clk *clk_jpeg;
+ struct clk *clk_jpeg_smi;
struct device *larb;
+ enum mtk_jpeg_mode mode;
};
/**
@@ -101,15 +157,51 @@ struct mtk_jpeg_q_data {
u32 sizeimage[VIDEO_MAX_PLANES];
};
+/**
+ * jpeg_enc_param - parameters of jpeg encode control
+ * @enable_exif: EXIF enable for jpeg encode mode
+ * @enc_quality: destination image quality in encode mode
+ * @restart_interval: JPEG restart interval for JPEG encoding
+ */
+struct jpeg_enc_param {
+ u32 enable_exif;
+ u32 enc_quality;
+ u32 restart_interval;
+};
+
+/**
+ * mtk_jpeg_enc_param: General jpeg encoding parameters
+ * @enc_w: image width
+ * @enc_h: image height
+ * @enable_exif: EXIF enable for jpeg encode mode
+ * @enc_quality: destination image quality in encode mode
+ * @enc_format: input image format
+ * @restart_interval: JPEG restart interval for JPEG encoding
+ * @img_stride: jpeg encoder image stride
+ * @mem_stride: jpeg encoder memory stride
+ * @total_encdu: total 8x8 block number
+ */
+struct mtk_jpeg_enc_param {
+ u32 enc_w;
+ u32 enc_h;
+ u32 enable_exif;
+ u32 enc_quality;
+ u32 enc_format;
+ u32 restart_interval;
+ u32 img_stride;
+ u32 mem_stride;
+ u32 total_encdu;
+};
+
/**
* mtk_jpeg_ctx - the device context data
* @jpeg: JPEG IP device for this context
* @out_q: source (output) queue information
* @cap_q: destination (capture) queue queue information
* @fh: V4L2 file handle
- * @dec_param parameters for HW decoding
* @state: state of the context
- * @header_valid: set if header has been parsed and valid
+ * @jpeg_param: jpeg encode parameters
+ * @ctrl_hdl: controls handler
* @colorspace: enum v4l2_colorspace; supplemental to pixelformat
* @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
* @quantization: enum v4l2_quantization, colorspace quantization
@@ -121,6 +213,8 @@ struct mtk_jpeg_ctx {
struct mtk_jpeg_q_data cap_q;
struct v4l2_fh fh;
enum mtk_jpeg_ctx_state state;
+ struct jpeg_enc_param jpeg_param;
+ struct v4l2_ctrl_handler ctrl_hdl;
enum v4l2_colorspace colorspace;
enum v4l2_ycbcr_encoding ycbcr_enc;
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h
index a37be1a48415..39d743fb572f 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h
@@ -3,10 +3,11 @@
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
+ * Xia Jiang <xia.jiang@mediatek.com>
*/
-#ifndef _MTK_JPEG_HW_H
-#define _MTK_JPEG_HW_H
+#ifndef _MTK_JPEG_DEC_HW_H
+#define _MTK_JPEG_DEC_HW_H
#include <media/videobuf2-core.h>
@@ -80,4 +81,4 @@ void mtk_jpeg_dec_set_config(void __iomem *base,
void mtk_jpeg_dec_reset(void __iomem *dec_reg_base);
void mtk_jpeg_dec_start(void __iomem *dec_reg_base);
-#endif /* _MTK_JPEG_HW_H */
+#endif /* _MTK_JPEG_DEC_HW_H */
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c
new file mode 100644
index 000000000000..ac27774ccfed
--- /dev/null
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c
@@ -0,0 +1,175 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ * Author: Xia Jiang <xia.jiang@mediatek.com>
+ *
+ */
+
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <media/videobuf2-core.h>
+
+#include "mtk_jpeg_enc_hw.h"
+
+void mtk_jpeg_enc_reset(void __iomem *base)
+{
+ writel(0x00, base + JPGENC_RSTB);
+ writel(JPEG_ENC_RESET_BIT, base + JPGENC_RSTB);
+ writel(0x00, base + JPGENC_CODEC_SEL);
+}
+
+u32 mtk_jpeg_enc_get_int_status(void __iomem *base)
+{
+ u32 ret;
+
+ ret = readl(base + JPGENC_INT_STS) &
+ JPEG_DRV_ENC_INT_STATUS_MASK_ALLIRQ;
+ if (ret)
+ writel(0, base + JPGENC_INT_STS);
+
+ return ret;
+}
+
+u32 mtk_jpeg_enc_get_file_size(void __iomem *base)
+{
+ return readl(base + JPGENC_DMA_ADDR0) - readl(base + JPGENC_DST_ADDR0);
+}
+
+u32 mtk_jpeg_enc_enum_result(void __iomem *base, u32 irq_status, u32 *file_size)
+{
+ *file_size = mtk_jpeg_enc_get_file_size(base);
+ if (irq_status & JPEG_DRV_ENC_INT_STATUS_DONE)
+ return MTK_JPEG_ENC_RESULT_DONE;
+ else if (irq_status & JPEG_DRV_ENC_INT_STATUS_STALL)
+ return MTK_JPEG_ENC_RESULT_STALL;
+ else if (irq_status & JPEG_DRV_ENC_INT_STATUS_VCODEC_IRQ)
+ return MTK_JPEG_ENC_RESULT_VCODEC_IRQ;
+ return MTK_JPEG_ENC_RESULT_ERROR_UNKNOWN;
+}
+
+static void mtk_jpeg_enc_set_blk_num(void __iomem *base, u32 blk_num)
+{
+ writel(blk_num, base + JPGENC_BLK_NUM);
+}
+
+static void mtk_jpeg_enc_set_encFormat(void __iomem *base, u32 enc_format)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_CTRL);
+ value &= ~JPEG_ENC_CTRL_YUV_BIT;
+ value |= JPGENC_FORMAT(enc_format);
+ writel(value, base + JPGENC_CTRL);
+}
+
+static void mtk_jpeg_enc_set_img_size(void __iomem *base, u32 width, u32 height)
+{
+ u32 value;
+
+ value = JPGENC_WIDTH_HEIGHT(width, height);
+ writel(value, base + JPGENC_IMG_SIZE);
+}
+
+static void mtk_jpeg_enc_set_src_img(void __iomem *base, u32 width,
+ u32 height, u32 yuv_format,
+ u32 total_encdu)
+{
+ mtk_jpeg_enc_set_img_size(base, width, height);
+ mtk_jpeg_enc_set_encFormat(base, yuv_format);
+ mtk_jpeg_enc_set_blk_num(base, total_encdu);
+}
+
+static void mtk_jpeg_enc_set_src_buf(void __iomem *base, u32 img_stride,
+ u32 mem_stride, u32 src_addr,
+ u32 src_addr_c)
+{
+ writel(img_stride, base + JPGENC_IMG_STRIDE);
+ writel(mem_stride, base + JPGENC_STRIDE);
+ writel(src_addr, base + JPGENC_SRC_LUMA_ADDR);
+ writel(src_addr_c, base + JPGENC_SRC_CHROMA_ADDR);
+}
+
+static void mtk_jpeg_enc_set_dst_buf(void __iomem *base, u32 dst_addr,
+ u32 stall_size, u32 init_offset,
+ u32 offset_mask)
+{
+ writel(JPGENC_INIT_OFFSET(init_offset), base + JPGENC_OFFSET_ADDR);
+ writel(JPGENC_OFFSET_MASK(offset_mask), base + JPGENC_BYTE_OFFSET_MASK);
+ writel(JPGENC_DST_ADDR(dst_addr), base + JPGENC_DST_ADDR0);
+ writel(JPGENC_STALL_ADDR(dst_addr, stall_size),
+ base + JPGENC_STALL_ADDR0);
+}
+
+static void mtk_jpeg_enc_set_quality(void __iomem *base, u32 quality)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_QUALITY);
+ value = JPGENC_SET_QUALITY(value, quality);
+ writel(value, base + JPGENC_QUALITY);
+}
+
+static void mtk_jpeg_enc_set_restart_interval(void __iomem *base,
+ u32 restart_interval)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_CTRL);
+ if (restart_interval)
+ value |= JPEG_ENC_CTRL_RESTART_EN_BIT;
+ else
+ value &= ~JPEG_ENC_CTRL_RESTART_EN_BIT;
+ writel(value, base + JPGENC_CTRL);
+ writel(restart_interval, base + JPGENC_RST_MCU_NUM);
+}
+
+static void mtk_jpeg_enc_set_encode_mode(void __iomem *base, u32 exif_en)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_CTRL);
+ value &= ~JPEG_ENC_CTRL_FILE_FORMAT_BIT;
+ writel(value, base + JPGENC_CTRL);
+
+ if (exif_en) {
+ value = readl(base + JPGENC_CTRL);
+ value |= JPEG_ENC_EN_JFIF_EXIF;
+ writel(value, base + JPGENC_CTRL);
+ }
+}
+
+static void mtk_jpeg_enc_set_ctrl_cfg(void __iomem *base, u32 exif_en,
+ u32 quality, u32 restart_interval)
+{
+ mtk_jpeg_enc_set_quality(base, quality);
+
+ mtk_jpeg_enc_set_restart_interval(base, restart_interval);
+
+ mtk_jpeg_enc_set_encode_mode(base, exif_en);
+}
+
+void mtk_jpeg_enc_start(void __iomem *base)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_CTRL);
+ value |= JPEG_ENC_CTRL_INT_EN_BIT | JPEG_ENC_CTRL_ENABLE_BIT;
+ writel(value, base + JPGENC_CTRL);
+}
+
+void mtk_jpeg_enc_set_config(void __iomem *base,
+ struct mtk_jpeg_enc_param *config,
+ struct mtk_jpeg_enc_bs *bs,
+ struct mtk_jpeg_enc_fb *fb)
+{
+ mtk_jpeg_enc_set_src_img(base, config->enc_w, config->enc_h,
+ config->enc_format, config->total_encdu);
+ mtk_jpeg_enc_set_src_buf(base, config->img_stride, config->mem_stride,
+ fb->fb_addr[0].dma_addr,
+ fb->fb_addr[1].dma_addr);
+ mtk_jpeg_enc_set_dst_buf(base, bs->dma_addr, bs->size,
+ bs->dma_addr_offset, bs->dma_addr_offsetmask);
+ mtk_jpeg_enc_set_ctrl_cfg(base, config->enable_exif,
+ config->enc_quality,
+ config->restart_interval);
+}
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h
new file mode 100644
index 000000000000..7080240f6dac
--- /dev/null
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ * Author: Xia Jiang <xia.jiang@mediatek.com>
+ *
+ */
+
+#ifndef _MTK_JPEG_ENC_HW_H
+#define _MTK_JPEG_ENC_HW_H
+
+#include <media/videobuf2-core.h>
+
+#include "mtk_jpeg_core.h"
+#include "mtk_jpeg_enc_reg.h"
+
+#define JPEG_ENC_DST_ADDR_OFFSET_MASK GENMASK(3, 0)
+
+#define JPEG_ENC_CTRL_YUV_BIT 0x18
+#define JPEG_ENC_CTRL_RESTART_EN_BIT BIT(10)
+#define JPEG_ENC_CTRL_FILE_FORMAT_BIT BIT(5)
+#define JPEG_ENC_EN_JFIF_EXIF BIT(5)
+#define JPEG_ENC_CTRL_INT_EN_BIT BIT(2)
+#define JPEG_ENC_CTRL_ENABLE_BIT BIT(0)
+#define JPEG_ENC_RESET_BIT BIT(0)
+
+enum {
+ MTK_JPEG_ENC_RESULT_DONE = 0,
+ MTK_JPEG_ENC_RESULT_STALL,
+ MTK_JPEG_ENC_RESULT_VCODEC_IRQ,
+ MTK_JPEG_ENC_RESULT_ERROR_UNKNOWN
+};
+
+struct mtk_jpeg_enc_bs {
+ dma_addr_t dma_addr;
+ size_t size;
+ u32 dma_addr_offset;
+ u32 dma_addr_offsetmask;
+};
+
+struct mtk_jpeg_mem {
+ dma_addr_t dma_addr;
+ size_t size;
+};
+
+struct mtk_jpeg_enc_fb {
+ struct mtk_jpeg_mem fb_addr[MTK_JPEG_COMP_MAX];
+ u32 num_planes;
+};
+
+void mtk_jpeg_enc_reset(void __iomem *base);
+u32 mtk_jpeg_enc_get_int_status(void __iomem *base);
+u32 mtk_jpeg_enc_get_file_size(void __iomem *base);
+u32 mtk_jpeg_enc_enum_result(void __iomem *base, u32 irq_status,
+ u32 *file_size);
+void mtk_jpeg_enc_start(void __iomem *enc_reg_base);
+void mtk_jpeg_enc_set_config(void __iomem *base,
+ struct mtk_jpeg_enc_param *config,
+ struct mtk_jpeg_enc_bs *bs,
+ struct mtk_jpeg_enc_fb *fb);
+#endif /* _MTK_JPEG_ENC_HW_H */
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h
new file mode 100644
index 000000000000..d785621cb4c6
--- /dev/null
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ * Author: Xia Jiang <xia.jiang@mediatek.com>
+ *
+ */
+#ifndef _MTK_JPEG_ENC_REG_H
+#define _MTK_JPEG_ENC_REG_H
+#define MTK_JPEG_COMP_MAX 3
+
+#define JPEG_DRV_ENC_INT_STATUS_DONE BIT(0)
+#define JPEG_DRV_ENC_INT_STATUS_STALL BIT(1)
+#define JPEG_DRV_ENC_INT_STATUS_VCODEC_IRQ BIT(4)
+#define JPEG_DRV_ENC_INT_STATUS_MASK_ALLIRQ 0x13
+
+#define JPGENC_RSTB 0x100
+#define JPGENC_CTRL 0x104
+#define JPGENC_QUALITY 0x108
+#define JPGENC_BLK_NUM 0x10C
+#define JPGENC_BLK_CNT 0x110
+#define JPGENC_INT_STS 0x11C
+#define JPGENC_DST_ADDR0 0x120
+#define JPGENC_DMA_ADDR0 0x124
+#define JPGENC_STALL_ADDR0 0x128
+#define JPGENC_OFFSET_ADDR 0x138
+#define JPGENC_RST_MCU_NUM 0x150
+#define JPGENC_IMG_SIZE 0x154
+#define JPGENC_DEBUG_INFO0 0x160
+#define JPGENC_DEBUG_INFO1 0x164
+#define JPGENC_TOTAL_CYCLE 0x168
+#define JPGENC_BYTE_OFFSET_MASK 0x16C
+#define JPGENC_SRC_LUMA_ADDR 0x170
+#define JPGENC_SRC_CHROMA_ADDR 0x174
+#define JPGENC_STRIDE 0x178
+#define JPGENC_IMG_STRIDE 0x17C
+#define JPGENC_DCM_CTRL 0x300
+#define JPGENC_CODEC_SEL 0x314
+#define JPGENC_ULTRA_THRES 0x318
+
+#define JPGENC_FORMAT(x) (((x) & 3) << 3)
+#define JPGENC_WIDTH_HEIGHT(w, h) (((w) << 16) | (h))
+#define JPGENC_INIT_OFFSET(x) ((x) & (~0xF))
+#define JPGENC_OFFSET_MASK(x) ((x) & 0xF)
+#define JPGENC_DST_ADDR(x) ((x) & (~0xF))
+#define JPGENC_STALL_ADDR(x, y) (((x) + (y)) & (~0xF))
+#define JPGENC_QUALITY_MASK 0xFFFF0000
+#define JPGENC_SET_QUALITY(x, y) (((x) & JPGENC_QUALITY_MASK) | (y))
+
+#endif /* _MTK_JPEG_ENC_REG_H */
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
@ 2019-09-24 7:43 ` Xia Jiang
0 siblings, 0 replies; 30+ messages in thread
From: Xia Jiang @ 2019-09-24 7:43 UTC (permalink / raw)
To: Hans Verkuil, Mauro Carvalho Chehab, Rob Herring,
Matthias Brugger, Rick Chang
Cc: linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, Marek Szyprowski, Tomasz Figa, srv_heupstream,
Xia Jiang
Add mtk jpeg encode v4l2 driver based on jpeg decode, because that jpeg
decode and encode have great similarities with function operation.
Signed-off-by: Xia Jiang <xia.jiang@mediatek.com>
---
v3: delete Change-Id
only test once handler->error after the last v4l2_ctrl_new_std()
seperate changes of v4l2-ctrls.c and v4l2-controls.h to new patch
v2: fix compliance test fail, check created buffer size in driver
---
drivers/media/platform/mtk-jpeg/Makefile | 5 +-
.../media/platform/mtk-jpeg/mtk_jpeg_core.c | 735 ++++++++++++++----
.../media/platform/mtk-jpeg/mtk_jpeg_core.h | 114 ++-
.../media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h | 7 +-
.../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c | 175 +++++
.../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h | 60 ++
.../platform/mtk-jpeg/mtk_jpeg_enc_reg.h | 49 ++
7 files changed, 975 insertions(+), 170 deletions(-)
create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c
create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h
create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h
diff --git a/drivers/media/platform/mtk-jpeg/Makefile b/drivers/media/platform/mtk-jpeg/Makefile
index 48516dcf96e6..76c33aad0f3f 100644
--- a/drivers/media/platform/mtk-jpeg/Makefile
+++ b/drivers/media/platform/mtk-jpeg/Makefile
@@ -1,3 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-only
-mtk_jpeg-objs := mtk_jpeg_core.o mtk_jpeg_dec_hw.o mtk_jpeg_dec_parse.o
+mtk_jpeg-objs := mtk_jpeg_core.o \
+ mtk_jpeg_dec_hw.o \
+ mtk_jpeg_dec_parse.o \
+ mtk_jpeg_enc_hw.o
obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index 5f0990fce8ef..aa18b01802ed 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -3,6 +3,7 @@
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
+ * Xia Jiang <xia.jiang@mediatek.com>
*/
#include <linux/clk.h>
@@ -23,6 +24,7 @@
#include <media/videobuf2-dma-contig.h>
#include <soc/mediatek/smi.h>
+#include "mtk_jpeg_enc_hw.h"
#include "mtk_jpeg_dec_hw.h"
#include "mtk_jpeg_core.h"
#include "mtk_jpeg_dec_parse.h"
@@ -31,7 +33,8 @@ static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
{
.fourcc = V4L2_PIX_FMT_JPEG,
.colplanes = 1,
- .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT,
+ .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT |
+ MTK_JPEG_FMT_FLAG_ENC_CAPTURE,
},
{
.fourcc = V4L2_PIX_FMT_YUV420M,
@@ -51,6 +54,42 @@ static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
.v_align = 3,
.flags = MTK_JPEG_FMT_FLAG_DEC_CAPTURE,
},
+ {
+ .fourcc = V4L2_PIX_FMT_NV12M,
+ .h_sample = {4, 2, 2},
+ .v_sample = {4, 2, 2},
+ .colplanes = 2,
+ .h_align = 4,
+ .v_align = 4,
+ .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
+ },
+ {
+ .fourcc = V4L2_PIX_FMT_NV21M,
+ .h_sample = {4, 2, 2},
+ .v_sample = {4, 2, 2},
+ .colplanes = 2,
+ .h_align = 4,
+ .v_align = 4,
+ .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
+ },
+ {
+ .fourcc = V4L2_PIX_FMT_YUYV,
+ .h_sample = {4, 2, 2},
+ .v_sample = {4, 4, 4},
+ .colplanes = 1,
+ .h_align = 4,
+ .v_align = 3,
+ .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
+ },
+ {
+ .fourcc = V4L2_PIX_FMT_YVYU,
+ .h_sample = {4, 2, 2},
+ .v_sample = {4, 4, 4},
+ .colplanes = 1,
+ .h_align = 4,
+ .v_align = 3,
+ .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
+ },
};
#define MTK_JPEG_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_formats)
@@ -65,11 +104,19 @@ struct mtk_jpeg_src_buf {
struct list_head list;
int flags;
struct mtk_jpeg_dec_param dec_param;
+ struct mtk_jpeg_enc_param enc_param;
};
+#define MTK_MAX_CTRLS_HINT 20
+
static int debug;
module_param(debug, int, 0644);
+static inline struct mtk_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *ctrl)
+{
+ return container_of(ctrl->handler, struct mtk_jpeg_ctx, ctrl_hdl);
+}
+
static inline struct mtk_jpeg_ctx *mtk_jpeg_fh_to_ctx(struct v4l2_fh *fh)
{
return container_of(fh, struct mtk_jpeg_ctx, fh);
@@ -86,10 +133,70 @@ static int mtk_jpeg_querycap(struct file *file, void *priv,
{
struct mtk_jpeg_dev *jpeg = video_drvdata(file);
- strscpy(cap->driver, MTK_JPEG_NAME " decoder", sizeof(cap->driver));
- strscpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
- snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
- dev_name(jpeg->dev));
+ strscpy(cap->driver, MTK_JPEG_NAME, sizeof(cap->driver));
+ if (jpeg->mode == MTK_JPEG_ENC)
+ strscpy(cap->card, MTK_JPEG_NAME " encoder", sizeof(cap->card));
+ else
+ strscpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
+ snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
+ dev_name(jpeg->dev));
+
+ return 0;
+}
+
+static int vidioc_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct mtk_jpeg_ctx *ctx = ctrl_to_ctx(ctrl);
+ struct jpeg_enc_param *p = &ctx->jpeg_param;
+ struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+ int ret = 0;
+
+ switch (ctrl->id) {
+ case V4L2_CID_JPEG_RESTART_INTERVAL:
+ p->restart_interval = ctrl->val;
+ break;
+ case V4L2_CID_JPEG_COMPRESSION_QUALITY:
+ p->enc_quality = ctrl->val;
+ break;
+ case V4L2_CID_JPEG_ENABLE_EXIF:
+ p->enable_exif = ctrl->val;
+ break;
+ }
+
+ v4l2_dbg(2, debug, &jpeg->v4l2_dev, "%s val = %d",
+ v4l2_ctrl_get_name(ctrl->id), ctrl->val);
+
+ return ret;
+}
+
+static const struct v4l2_ctrl_ops mtk_jpeg_ctrl_ops = {
+ .s_ctrl = vidioc_jpeg_s_ctrl,
+};
+
+int mtk_jpeg_ctrls_setup(struct mtk_jpeg_ctx *ctx)
+{
+ const struct v4l2_ctrl_ops *ops = &mtk_jpeg_ctrl_ops;
+ struct v4l2_ctrl_handler *handler = &ctx->ctrl_hdl;
+ struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+
+ v4l2_ctrl_handler_init(handler, MTK_MAX_CTRLS_HINT);
+
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ v4l2_ctrl_new_std(handler, ops, V4L2_CID_JPEG_RESTART_INTERVAL,
+ 0, 100, 1, 0);
+ v4l2_ctrl_new_std(handler, ops,
+ V4L2_CID_JPEG_COMPRESSION_QUALITY, 48, 100, 1,
+ 90);
+ v4l2_ctrl_new_std(handler, ops, V4L2_CID_JPEG_ENABLE_EXIF, 0,
+ 1, 1, 0);
+
+ if (handler->error) {
+ v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
+ return handler->error;
+ }
+ }
+
+ v4l2_ctrl_handler_setup(&ctx->ctrl_hdl);
return 0;
}
@@ -118,23 +225,29 @@ static int mtk_jpeg_enum_fmt(struct mtk_jpeg_fmt *mtk_jpeg_formats, int n,
static int mtk_jpeg_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
+ struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
+
return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
+ ctx->jpeg->mode == MTK_JPEG_ENC ?
+ MTK_JPEG_FMT_FLAG_ENC_CAPTURE :
MTK_JPEG_FMT_FLAG_DEC_CAPTURE);
}
static int mtk_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
+ struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
+
return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
+ ctx->jpeg->mode == MTK_JPEG_ENC ?
+ MTK_JPEG_FMT_FLAG_ENC_OUTPUT :
MTK_JPEG_FMT_FLAG_DEC_OUTPUT);
}
-static struct mtk_jpeg_q_data *mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx,
- enum v4l2_buf_type type)
+static struct mtk_jpeg_q_data *
+mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx, enum v4l2_buf_type type)
{
- if (V4L2_TYPE_IS_OUTPUT(type))
- return &ctx->out_q;
- return &ctx->cap_q;
+ return V4L2_TYPE_IS_OUTPUT(type) ? &ctx->out_q : &ctx->cap_q;
}
static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
@@ -143,9 +256,14 @@ static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
{
unsigned int k, fmt_flag;
- fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
- MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
- MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
+ if (ctx->jpeg->mode == MTK_JPEG_ENC)
+ fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
+ MTK_JPEG_FMT_FLAG_ENC_OUTPUT :
+ MTK_JPEG_FMT_FLAG_ENC_CAPTURE;
+ else
+ fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
+ MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
+ MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
for (k = 0; k < MTK_JPEG_NUM_FORMATS; k++) {
struct mtk_jpeg_fmt *fmt = &mtk_jpeg_formats[k];
@@ -202,7 +320,7 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
{
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
struct mtk_jpeg_dev *jpeg = ctx->jpeg;
- int i;
+ int i, align_w, align_h;
memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
pix_mp->field = V4L2_FIELD_NONE;
@@ -216,36 +334,111 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
pix_mp->pixelformat = fmt->fourcc;
if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
- struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0];
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ pix_mp->height = clamp(pix_mp->height,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT);
+ pix_mp->width = clamp(pix_mp->width,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH);
+ align_w = pix_mp->width;
+ align_h = pix_mp->height;
+ align_w = round_up(align_w, 2);
+ if (pix_mp->num_planes == 1U) {
+ align_w = align_w << 1;
+ mtk_jpeg_bound_align_image(&align_w,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH,
+ 5, &align_h,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT,
+ 3);
+ pix_mp->plane_fmt[0].bytesperline = align_w;
+ pix_mp->plane_fmt[0].sizeimage =
+ align_w * align_h;
+ } else if (pix_mp->num_planes == 2U) {
+ mtk_jpeg_bound_align_image(&align_w,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH,
+ 4, &align_h,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT,
+ 4);
+ pix_mp->plane_fmt[0].bytesperline = align_w;
+ pix_mp->plane_fmt[0].sizeimage =
+ align_w * align_h;
+ pix_mp->plane_fmt[1].bytesperline = align_w;
+ pix_mp->plane_fmt[1].sizeimage =
+ (align_w * align_h) / 2;
+ } else {
+ v4l2_err(&ctx->jpeg->v4l2_dev,
+ "Unsupport num planes = %d\n",
+ pix_mp->num_planes);
+ }
+ goto end;
+ } else {
+ struct v4l2_plane_pix_format *pfmt =
+ &pix_mp->plane_fmt[0];
+
+ mtk_jpeg_bound_align_image(&pix_mp->width,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH, 0,
+ &pix_mp->height,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT, 0);
+
+ pfmt->bytesperline = 0;
+ /* Source size must be aligned to 128 */
+ pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
+ if (pfmt->sizeimage == 0)
+ pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
+
+ goto end;
+ }
+ }
+ /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
+ if (jpeg->mode == MTK_JPEG_ENC) {
mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
MTK_JPEG_MAX_WIDTH, 0,
&pix_mp->height, MTK_JPEG_MIN_HEIGHT,
MTK_JPEG_MAX_HEIGHT, 0);
- memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
- pfmt->bytesperline = 0;
- /* Source size must be aligned to 128 */
- pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
- if (pfmt->sizeimage == 0)
- pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
- goto end;
+ if (fmt->fourcc == V4L2_PIX_FMT_JPEG) {
+ pix_mp->plane_fmt[0].bytesperline = 0;
+ pix_mp->plane_fmt[0].sizeimage =
+ mtk_jpeg_align(pix_mp->plane_fmt[0].sizeimage,
+ 128);
+ if (pix_mp->plane_fmt[0].sizeimage == 0)
+ pix_mp->plane_fmt[0].sizeimage =
+ MTK_JPEG_DEFAULT_SIZEIMAGE;
+ }
+ } else {
+ pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT);
+ pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH);
+ mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH, fmt->h_align,
+ &pix_mp->height,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT, fmt->v_align);
+
+ for (i = 0; i < fmt->colplanes; i++) {
+ struct v4l2_plane_pix_format *pfmt =
+ &pix_mp->plane_fmt[i];
+ u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
+ u32 h = pix_mp->height * fmt->v_sample[i] / 4;
+
+ pfmt->bytesperline = stride;
+ pfmt->sizeimage = stride * h;
+ }
}
- /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
- mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
- MTK_JPEG_MAX_WIDTH, fmt->h_align,
- &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
- MTK_JPEG_MAX_HEIGHT, fmt->v_align);
-
for (i = 0; i < fmt->colplanes; i++) {
- struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[i];
- u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
- u32 h = pix_mp->height * fmt->v_sample[i] / 4;
-
+ struct v4l2_plane_pix_format *pfmt =
+ &pix_mp->plane_fmt[i];
memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
- pfmt->bytesperline = stride;
- pfmt->sizeimage = stride * h;
}
end:
v4l2_dbg(2, debug, &jpeg->v4l2_dev, "wxh:%ux%u\n",
@@ -446,9 +639,9 @@ static int mtk_jpeg_subscribe_event(struct v4l2_fh *fh,
switch (sub->type) {
case V4L2_EVENT_SOURCE_CHANGE:
return v4l2_src_change_event_subscribe(fh, sub);
- default:
- return -EINVAL;
}
+
+ return v4l2_ctrl_subscribe_event(fh, sub);
}
static int mtk_jpeg_g_selection(struct file *file, void *priv,
@@ -571,6 +764,13 @@ static int mtk_jpeg_queue_setup(struct vb2_queue *q,
if (!q_data)
return -EINVAL;
+ if (*num_planes) {
+ for (i = 0; i < *num_planes; i++)
+ if (sizes[i] < q_data->sizeimage[i])
+ return -EINVAL;
+ return 0;
+ }
+
*num_planes = q_data->fmt->colplanes;
for (i = 0; i < q_data->fmt->colplanes; i++) {
sizes[i] = q_data->sizeimage[i];
@@ -651,10 +851,92 @@ static void mtk_jpeg_set_queue_data(struct mtk_jpeg_ctx *ctx,
param->dec_w, param->dec_h);
}
+static void mtk_jpeg_set_param(struct mtk_jpeg_ctx *ctx,
+ struct mtk_jpeg_enc_param *param)
+{
+ struct mtk_jpeg_q_data *q_data_src = &ctx->out_q;
+ struct jpeg_enc_param *jpeg_params = &ctx->jpeg_param;
+ struct mtk_jpeg_dev *jpeg = ctx->jpeg;
+ u32 width_even;
+ u32 is_420;
+ u32 padding_width;
+ u32 padding_height;
+
+ switch (q_data_src->fmt->fourcc) {
+ case V4L2_PIX_FMT_YUYV:
+ param->enc_format = JPEG_YUV_FORMAT_YUYV;
+ break;
+ case V4L2_PIX_FMT_YVYU:
+ param->enc_format = JPEG_YUV_FORMAT_YVYU;
+ break;
+ case V4L2_PIX_FMT_NV12M:
+ param->enc_format = JPEG_YUV_FORMAT_NV12;
+ break;
+ case V4L2_PIX_FMT_NV21M:
+ param->enc_format = JPEG_YUV_FORMAT_NV12;
+ break;
+ default:
+ v4l2_err(&jpeg->v4l2_dev, "Unsupport fourcc =%d\n",
+ q_data_src->fmt->fourcc);
+ break;
+ }
+ param->enc_w = q_data_src->w;
+ param->enc_h = q_data_src->h;
+
+ if (jpeg_params->enc_quality >= 97)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q97;
+ else if (jpeg_params->enc_quality >= 95)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q95;
+ else if (jpeg_params->enc_quality >= 92)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q92;
+ else if (jpeg_params->enc_quality >= 90)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q90;
+ else if (jpeg_params->enc_quality >= 87)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q87;
+ else if (jpeg_params->enc_quality >= 84)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q84;
+ else if (jpeg_params->enc_quality >= 80)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q80;
+ else if (jpeg_params->enc_quality >= 74)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q74;
+ else if (jpeg_params->enc_quality >= 64)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q64;
+ else if (jpeg_params->enc_quality >= 60)
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q60;
+ else
+ param->enc_quality = JPEG_ENCODE_QUALITY_Q48;
+
+ param->enable_exif = jpeg_params->enable_exif;
+ param->restart_interval = jpeg_params->restart_interval;
+
+ width_even = ((param->enc_w + 1) >> 1) << 1;
+ is_420 = (param->enc_format == JPEG_YUV_FORMAT_NV12 ||
+ param->enc_format == JPEG_YUV_FORMAT_NV12) ? 1 : 0;
+ padding_width = mtk_jpeg_align(param->enc_w, 16);
+ padding_height = mtk_jpeg_align(param->enc_h, is_420 ? 16 : 8);
+ if (!is_420)
+ width_even = width_even << 1;
+
+ param->img_stride = mtk_jpeg_align(width_even, (is_420 ? 16 : 32));
+ param->mem_stride = mtk_jpeg_align(width_even, (is_420 ? 16 : 32));
+ param->total_encdu =
+ ((padding_width >> 4) * (padding_height >> (is_420 ? 4 : 3)) *
+ (is_420 ? 6 : 4)) - 1;
+
+ v4l2_dbg(0, 2, &jpeg->v4l2_dev, "fmt %d, w,h %d,%d, enable_exif %d,",
+ "enc_quality %d, restart_interval %d,img_stride %d,",
+ "mem_stride %d,totalEncDu %d\n",
+ param->enc_format, param->enc_w, param->enc_h,
+ param->enable_exif, param->enc_quality,
+ param->restart_interval, param->img_stride,
+ param->mem_stride, param->total_encdu);
+}
+
static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
{
struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct mtk_jpeg_dec_param *param;
+ struct mtk_jpeg_enc_param *enc_param;
struct mtk_jpeg_dev *jpeg = ctx->jpeg;
struct mtk_jpeg_src_buf *jpeg_src_buf;
bool header_valid;
@@ -666,29 +948,45 @@ static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
goto end;
jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb);
- param = &jpeg_src_buf->dec_param;
- memset(param, 0, sizeof(*param));
-
- if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
- v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
- goto end;
- }
- header_valid = mtk_jpeg_parse(param, (u8 *)vb2_plane_vaddr(vb, 0),
- vb2_get_plane_payload(vb, 0));
- if (!header_valid) {
- v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
- vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
- return;
- }
-
- if (ctx->state == MTK_JPEG_INIT) {
- struct vb2_queue *dst_vq = v4l2_m2m_get_vq(
- ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ enc_param = &jpeg_src_buf->enc_param;
+ memset(enc_param, 0, sizeof(*enc_param));
+ mtk_jpeg_set_param(ctx, enc_param);
+ if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
+ v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos");
+ goto end;
+ }
+ if (ctx->state == MTK_JPEG_INIT)
+ ctx->state = MTK_JPEG_RUNNING;
+ } else {
+ param = &jpeg_src_buf->dec_param;
+ memset(param, 0, sizeof(*param));
+
+ if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
+ v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
+ goto end;
+ }
+ header_valid = mtk_jpeg_parse(param,
+ (u8 *)vb2_plane_vaddr(vb, 0),
+ vb2_get_plane_payload(vb, 0));
+ if (!header_valid) {
+ v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
+ vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+ return;
+ }
- mtk_jpeg_queue_src_chg_event(ctx);
- mtk_jpeg_set_queue_data(ctx, param);
- ctx->state = vb2_is_streaming(dst_vq) ?
- MTK_JPEG_SOURCE_CHANGE : MTK_JPEG_RUNNING;
+ if (ctx->state == MTK_JPEG_INIT) {
+ struct vb2_queue *dst_vq;
+
+ dst_vq = v4l2_m2m_get_vq
+ (ctx->fh.m2m_ctx,
+ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+ mtk_jpeg_queue_src_chg_event(ctx);
+ mtk_jpeg_set_queue_data(ctx, param);
+ ctx->state = vb2_is_streaming(dst_vq) ?
+ MTK_JPEG_SOURCE_CHANGE :
+ MTK_JPEG_RUNNING;
+ }
}
end:
v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, to_vb2_v4l2_buffer(vb));
@@ -731,16 +1029,16 @@ static void mtk_jpeg_stop_streaming(struct vb2_queue *q)
* subsampling. Update capture queue when the stream is off.
*/
if (ctx->state == MTK_JPEG_SOURCE_CHANGE &&
- !V4L2_TYPE_IS_OUTPUT(q->type)) {
+ !V4L2_TYPE_IS_OUTPUT(q->type) &&
+ ctx->jpeg->mode == MTK_JPEG_DEC) {
struct mtk_jpeg_src_buf *src_buf;
vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
src_buf = mtk_jpeg_vb2_to_srcbuf(&vb->vb2_buf);
mtk_jpeg_set_queue_data(ctx, &src_buf->dec_param);
ctx->state = MTK_JPEG_RUNNING;
- } else if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+ } else if (V4L2_TYPE_IS_OUTPUT(q->type))
ctx->state = MTK_JPEG_INIT;
- }
while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
@@ -795,6 +1093,28 @@ static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,
return 0;
}
+static void mtk_jpeg_set_enc_dst(struct mtk_jpeg_ctx *ctx,
+ struct vb2_buffer *dst_buf,
+ struct mtk_jpeg_enc_bs *bs)
+{
+ bs->dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0) &
+ (~JPEG_ENC_DST_ADDR_OFFSET_MASK);
+ bs->dma_addr_offset = 0;
+ bs->dma_addr_offsetmask = bs->dma_addr & JPEG_ENC_DST_ADDR_OFFSET_MASK;
+ bs->size = mtk_jpeg_align(vb2_plane_size(dst_buf, 0), 128);
+}
+
+static void mtk_jpeg_set_enc_src(struct mtk_jpeg_ctx *ctx,
+ struct vb2_buffer *src_buf,
+ struct mtk_jpeg_enc_fb *fb)
+{
+ int i;
+
+ for (i = 0; i < src_buf->num_planes; i++)
+ fb->fb_addr[i].dma_addr =
+ vb2_dma_contig_plane_dma_addr(src_buf, i);
+}
+
static void mtk_jpeg_device_run(void *priv)
{
struct mtk_jpeg_ctx *ctx = priv;
@@ -805,6 +1125,8 @@ static void mtk_jpeg_device_run(void *priv)
struct mtk_jpeg_src_buf *jpeg_src_buf;
struct mtk_jpeg_bs bs;
struct mtk_jpeg_fb fb;
+ struct mtk_jpeg_enc_bs enc_bs;
+ struct mtk_jpeg_enc_fb enc_fb;
int i;
src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
@@ -815,30 +1137,45 @@ static void mtk_jpeg_device_run(void *priv)
for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
vb2_set_plane_payload(&dst_buf->vb2_buf, i, 0);
buf_state = VB2_BUF_STATE_DONE;
- goto dec_end;
+ goto device_run_end;
}
- if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) {
- mtk_jpeg_queue_src_chg_event(ctx);
- ctx->state = MTK_JPEG_SOURCE_CHANGE;
- v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
- return;
- }
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ mtk_jpeg_set_enc_dst(ctx, &dst_buf->vb2_buf, &enc_bs);
+ mtk_jpeg_set_enc_src(ctx, &src_buf->vb2_buf, &enc_fb);
+
+ spin_lock_irqsave(&jpeg->hw_lock, flags);
+ mtk_jpeg_enc_reset(jpeg->reg_base);
+ mtk_jpeg_enc_set_config(jpeg->reg_base,
+ &jpeg_src_buf->enc_param, &enc_bs,
+ &enc_fb);
+
+ mtk_jpeg_enc_start(jpeg->reg_base);
+ } else {
+ if (mtk_jpeg_check_resolution_change
+ (ctx, &jpeg_src_buf->dec_param)) {
+ mtk_jpeg_queue_src_chg_event(ctx);
+ ctx->state = MTK_JPEG_SOURCE_CHANGE;
+ v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+ return;
+ }
- mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
- if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, &dst_buf->vb2_buf, &fb))
- goto dec_end;
+ mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
+ if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param,
+ &dst_buf->vb2_buf, &fb))
+ goto device_run_end;
- spin_lock_irqsave(&jpeg->hw_lock, flags);
- mtk_jpeg_dec_reset(jpeg->dec_reg_base);
- mtk_jpeg_dec_set_config(jpeg->dec_reg_base,
- &jpeg_src_buf->dec_param, &bs, &fb);
+ spin_lock_irqsave(&jpeg->hw_lock, flags);
+ mtk_jpeg_dec_reset(jpeg->reg_base);
+ mtk_jpeg_dec_set_config(jpeg->reg_base,
+ &jpeg_src_buf->dec_param, &bs, &fb);
- mtk_jpeg_dec_start(jpeg->dec_reg_base);
+ mtk_jpeg_dec_start(jpeg->reg_base);
+ }
spin_unlock_irqrestore(&jpeg->hw_lock, flags);
return;
-dec_end:
+device_run_end:
v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
v4l2_m2m_buf_done(src_buf, buf_state);
@@ -898,30 +1235,30 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
ret = mtk_smi_larb_get(jpeg->larb);
if (ret)
dev_err(jpeg->dev, "mtk_smi_larb_get larbvdec fail %d\n", ret);
- clk_prepare_enable(jpeg->clk_jdec_smi);
- clk_prepare_enable(jpeg->clk_jdec);
+ if (jpeg->mode == MTK_JPEG_DEC)
+ clk_prepare_enable(jpeg->clk_jpeg_smi);
+ clk_prepare_enable(jpeg->clk_jpeg);
}
static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg)
{
- clk_disable_unprepare(jpeg->clk_jdec);
- clk_disable_unprepare(jpeg->clk_jdec_smi);
+ clk_disable_unprepare(jpeg->clk_jpeg);
+ if (jpeg->mode == MTK_JPEG_DEC)
+ clk_disable_unprepare(jpeg->clk_jpeg_smi);
mtk_smi_larb_put(jpeg->larb);
}
-static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
+static irqreturn_t mtk_jpeg_irq(int irq, void *priv)
{
struct mtk_jpeg_dev *jpeg = priv;
struct mtk_jpeg_ctx *ctx;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct mtk_jpeg_src_buf *jpeg_src_buf;
enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
- u32 dec_irq_ret;
- u32 dec_ret;
+ u32 irq_ret;
+ u32 ret, result_size;
int i;
- dec_ret = mtk_jpeg_dec_get_int_status(jpeg->dec_reg_base);
- dec_irq_ret = mtk_jpeg_dec_enum_result(dec_ret);
ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev);
if (!ctx) {
v4l2_err(&jpeg->v4l2_dev, "Context is NULL\n");
@@ -932,21 +1269,42 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
- if (dec_irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
- mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ ret = mtk_jpeg_enc_get_int_status(jpeg->reg_base);
+ irq_ret = mtk_jpeg_enc_enum_result(jpeg->reg_base, ret,
+ &result_size);
- if (dec_irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
- dev_err(jpeg->dev, "decode failed\n");
- goto dec_end;
- }
+ if (irq_ret >= MTK_JPEG_ENC_RESULT_STALL)
+ mtk_jpeg_enc_reset(jpeg->reg_base);
+
+ if (irq_ret != MTK_JPEG_ENC_RESULT_DONE) {
+ dev_err(jpeg->dev, "encode failed\n");
+ goto irq_end;
+ }
- for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
- vb2_set_plane_payload(&dst_buf->vb2_buf, i,
- jpeg_src_buf->dec_param.comp_size[i]);
+ vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
+ result_size);
+ } else {
+ ret = mtk_jpeg_dec_get_int_status(jpeg->reg_base);
+ irq_ret = mtk_jpeg_dec_enum_result(ret);
+
+ if (irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
+ mtk_jpeg_dec_reset(jpeg->reg_base);
+
+ if (irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
+ dev_err(jpeg->dev, "decode failed\n");
+ goto irq_end;
+ }
+
+ for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
+ vb2_set_plane_payload
+ (&dst_buf->vb2_buf, i,
+ jpeg_src_buf->dec_param.comp_size[i]);
+ }
buf_state = VB2_BUF_STATE_DONE;
-dec_end:
+irq_end:
v4l2_m2m_buf_done(src_buf, buf_state);
v4l2_m2m_buf_done(dst_buf, buf_state);
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
@@ -956,32 +1314,72 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
static void mtk_jpeg_set_default_params(struct mtk_jpeg_ctx *ctx)
{
struct mtk_jpeg_q_data *q = &ctx->out_q;
- int i;
+ int i, align_w, align_h;
+
+ ctx->fh.ctrl_handler = &ctx->ctrl_hdl;
ctx->colorspace = V4L2_COLORSPACE_JPEG,
ctx->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
ctx->quantization = V4L2_QUANTIZATION_DEFAULT;
ctx->xfer_func = V4L2_XFER_FUNC_DEFAULT;
- q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
+ if (ctx->jpeg->mode == MTK_JPEG_ENC) {
+ q->w = MTK_JPEG_MIN_WIDTH;
+ q->h = MTK_JPEG_MIN_HEIGHT;
+
+ q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUYV,
MTK_JPEG_FMT_TYPE_OUTPUT);
- q->w = MTK_JPEG_MIN_WIDTH;
- q->h = MTK_JPEG_MIN_HEIGHT;
- q->bytesperline[0] = 0;
- q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
+
+ align_w = q->w;
+ align_h = q->h;
+ align_w = round_up(align_w, 2);
+ align_w = align_w << 1;
+ v4l_bound_align_image(&align_w,
+ MTK_JPEG_MIN_WIDTH,
+ MTK_JPEG_MAX_WIDTH, 5,
+ &align_h,
+ MTK_JPEG_MIN_HEIGHT,
+ MTK_JPEG_MAX_HEIGHT, 3, 0);
+
+ if (align_w < MTK_JPEG_MIN_WIDTH &&
+ (align_w + 32) <= MTK_JPEG_MAX_WIDTH)
+ align_w += 32;
+ if (align_h < MTK_JPEG_MIN_HEIGHT &&
+ (align_h + 8) <= MTK_JPEG_MAX_HEIGHT)
+ align_h += 8;
+
+ q->sizeimage[0] = align_w * align_h;
+ q->bytesperline[0] = align_w;
+ } else {
+ q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
+ MTK_JPEG_FMT_TYPE_OUTPUT);
+ q->w = MTK_JPEG_MIN_WIDTH;
+ q->h = MTK_JPEG_MIN_HEIGHT;
+ q->bytesperline[0] = 0;
+ q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
+ }
q = &ctx->cap_q;
- q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
+ if (ctx->jpeg->mode == MTK_JPEG_ENC) {
+ q->w = MTK_JPEG_MIN_WIDTH;
+ q->h = MTK_JPEG_MIN_HEIGHT;
+ q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
+ MTK_JPEG_FMT_TYPE_CAPTURE);
+ q->bytesperline[0] = 0;
+ q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
+ } else {
+ q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
MTK_JPEG_FMT_TYPE_CAPTURE);
- q->w = MTK_JPEG_MIN_WIDTH;
- q->h = MTK_JPEG_MIN_HEIGHT;
+ q->w = MTK_JPEG_MIN_WIDTH;
+ q->h = MTK_JPEG_MIN_HEIGHT;
- for (i = 0; i < q->fmt->colplanes; i++) {
- u32 stride = q->w * q->fmt->h_sample[i] / 4;
- u32 h = q->h * q->fmt->v_sample[i] / 4;
+ for (i = 0; i < q->fmt->colplanes; i++) {
+ u32 stride = q->w * q->fmt->h_sample[i] / 4;
+ u32 h = q->h * q->fmt->v_sample[i] / 4;
- q->bytesperline[i] = stride;
- q->sizeimage[i] = stride * h;
+ q->bytesperline[i] = stride;
+ q->sizeimage[i] = stride * h;
+ }
}
}
@@ -1013,6 +1411,13 @@ static int mtk_jpeg_open(struct file *file)
goto error;
}
+ ret = mtk_jpeg_ctrls_setup(ctx);
+ if (ret) {
+ v4l2_err(&jpeg->v4l2_dev, "Failed to setup controls() (%d)\n",
+ ret);
+ goto error;
+ }
+
mtk_jpeg_set_default_params(ctx);
mutex_unlock(&jpeg->lock);
return 0;
@@ -1033,6 +1438,7 @@ static int mtk_jpeg_release(struct file *file)
mutex_lock(&jpeg->lock);
v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
+ v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
v4l2_fh_del(&ctx->fh);
v4l2_fh_exit(&ctx->fh);
kfree(ctx);
@@ -1057,6 +1463,7 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
node = of_parse_phandle(jpeg->dev->of_node, "mediatek,larb", 0);
if (!node)
return -EINVAL;
+
pdev = of_find_device_by_node(node);
if (WARN_ON(!pdev)) {
of_node_put(node);
@@ -1066,19 +1473,24 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
jpeg->larb = &pdev->dev;
- jpeg->clk_jdec = devm_clk_get(jpeg->dev, "jpgdec");
- if (IS_ERR(jpeg->clk_jdec))
- return PTR_ERR(jpeg->clk_jdec);
+ if (jpeg->mode == MTK_JPEG_ENC) {
+ jpeg->clk_jpeg = devm_clk_get(jpeg->dev, "jpgenc");
+ return PTR_ERR_OR_ZERO(jpeg->clk_jpeg);
+ }
+
+ jpeg->clk_jpeg = devm_clk_get(jpeg->dev, "jpgdec");
+ if (IS_ERR(jpeg->clk_jpeg))
+ return PTR_ERR(jpeg->clk_jpeg);
- jpeg->clk_jdec_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
- return PTR_ERR_OR_ZERO(jpeg->clk_jdec_smi);
+ jpeg->clk_jpeg_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
+ return PTR_ERR_OR_ZERO(jpeg->clk_jpeg_smi);
}
static int mtk_jpeg_probe(struct platform_device *pdev)
{
struct mtk_jpeg_dev *jpeg;
struct resource *res;
- int dec_irq;
+ int jpeg_irq;
int ret;
jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL);
@@ -1088,28 +1500,26 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
mutex_init(&jpeg->lock);
spin_lock_init(&jpeg->hw_lock);
jpeg->dev = &pdev->dev;
+ jpeg->mode = (enum mtk_jpeg_mode)of_device_get_match_data(jpeg->dev);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- jpeg->dec_reg_base = devm_ioremap_resource(&pdev->dev, res);
- if (IS_ERR(jpeg->dec_reg_base)) {
- ret = PTR_ERR(jpeg->dec_reg_base);
+ jpeg->reg_base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(jpeg->reg_base)) {
+ ret = PTR_ERR(jpeg->reg_base);
return ret;
}
- res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- dec_irq = platform_get_irq(pdev, 0);
- if (!res || dec_irq < 0) {
- dev_err(&pdev->dev, "Failed to get dec_irq %d.\n", dec_irq);
- ret = -EINVAL;
- return ret;
+ jpeg_irq = platform_get_irq(pdev, 0);
+ if (jpeg_irq < 0) {
+ dev_err(&pdev->dev, "Failed to get jpeg_irq %d.\n", jpeg_irq);
+ return jpeg_irq;
}
- ret = devm_request_irq(&pdev->dev, dec_irq, mtk_jpeg_dec_irq, 0,
+ ret = devm_request_irq(&pdev->dev, jpeg_irq, mtk_jpeg_irq, 0,
pdev->name, jpeg);
if (ret) {
- dev_err(&pdev->dev, "Failed to request dec_irq %d (%d)\n",
- dec_irq, ret);
- ret = -EINVAL;
+ dev_err(&pdev->dev, "Failed to request jpeg_irq %d (%d)\n",
+ jpeg_irq, ret);
goto err_req_irq;
}
@@ -1133,33 +1543,35 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
goto err_m2m_init;
}
- jpeg->dec_vdev = video_device_alloc();
- if (!jpeg->dec_vdev) {
+ jpeg->vfd_jpeg = video_device_alloc();
+ if (!jpeg->vfd_jpeg) {
ret = -ENOMEM;
- goto err_dec_vdev_alloc;
+ goto err_vfd_jpeg_alloc;
}
- snprintf(jpeg->dec_vdev->name, sizeof(jpeg->dec_vdev->name),
- "%s-dec", MTK_JPEG_NAME);
- jpeg->dec_vdev->fops = &mtk_jpeg_fops;
- jpeg->dec_vdev->ioctl_ops = &mtk_jpeg_ioctl_ops;
- jpeg->dec_vdev->minor = -1;
- jpeg->dec_vdev->release = video_device_release;
- jpeg->dec_vdev->lock = &jpeg->lock;
- jpeg->dec_vdev->v4l2_dev = &jpeg->v4l2_dev;
- jpeg->dec_vdev->vfl_dir = VFL_DIR_M2M;
- jpeg->dec_vdev->device_caps = V4L2_CAP_STREAMING |
+ snprintf(jpeg->vfd_jpeg->name, sizeof(jpeg->vfd_jpeg->name),
+ "%s-%s", MTK_JPEG_NAME,
+ jpeg->mode == MTK_JPEG_ENC ? "enc" : "dec");
+ jpeg->vfd_jpeg->fops = &mtk_jpeg_fops;
+ jpeg->vfd_jpeg->ioctl_ops = &mtk_jpeg_ioctl_ops;
+ jpeg->vfd_jpeg->minor = -1;
+ jpeg->vfd_jpeg->release = video_device_release;
+ jpeg->vfd_jpeg->lock = &jpeg->lock;
+ jpeg->vfd_jpeg->v4l2_dev = &jpeg->v4l2_dev;
+ jpeg->vfd_jpeg->vfl_dir = VFL_DIR_M2M;
+ jpeg->vfd_jpeg->device_caps = V4L2_CAP_STREAMING |
V4L2_CAP_VIDEO_M2M_MPLANE;
- ret = video_register_device(jpeg->dec_vdev, VFL_TYPE_GRABBER, 3);
+ ret = video_register_device(jpeg->vfd_jpeg, VFL_TYPE_GRABBER, -1);
if (ret) {
v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n");
- goto err_dec_vdev_register;
+ goto err_vfd_jpeg_register;
}
- video_set_drvdata(jpeg->dec_vdev, jpeg);
+ video_set_drvdata(jpeg->vfd_jpeg, jpeg);
v4l2_info(&jpeg->v4l2_dev,
- "decoder device registered as /dev/video%d (%d,%d)\n",
- jpeg->dec_vdev->num, VIDEO_MAJOR, jpeg->dec_vdev->minor);
+ "jpeg device %d registered as /dev/video%d (%d,%d)\n",
+ jpeg->mode, jpeg->vfd_jpeg->num, VIDEO_MAJOR,
+ jpeg->vfd_jpeg->minor);
platform_set_drvdata(pdev, jpeg);
@@ -1167,10 +1579,10 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
return 0;
-err_dec_vdev_register:
- video_device_release(jpeg->dec_vdev);
+err_vfd_jpeg_register:
+ video_device_release(jpeg->vfd_jpeg);
-err_dec_vdev_alloc:
+err_vfd_jpeg_alloc:
v4l2_m2m_release(jpeg->m2m_dev);
err_m2m_init:
@@ -1190,8 +1602,8 @@ static int mtk_jpeg_remove(struct platform_device *pdev)
struct mtk_jpeg_dev *jpeg = platform_get_drvdata(pdev);
pm_runtime_disable(&pdev->dev);
- video_unregister_device(jpeg->dec_vdev);
- video_device_release(jpeg->dec_vdev);
+ video_unregister_device(jpeg->vfd_jpeg);
+ video_device_release(jpeg->vfd_jpeg);
v4l2_m2m_release(jpeg->m2m_dev);
v4l2_device_unregister(&jpeg->v4l2_dev);
@@ -1202,7 +1614,11 @@ static __maybe_unused int mtk_jpeg_pm_suspend(struct device *dev)
{
struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
- mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+ if (jpeg->mode == MTK_JPEG_ENC)
+ mtk_jpeg_enc_reset(jpeg->reg_base);
+ else
+ mtk_jpeg_dec_reset(jpeg->reg_base);
+
mtk_jpeg_clk_off(jpeg);
return 0;
@@ -1213,7 +1629,10 @@ static __maybe_unused int mtk_jpeg_pm_resume(struct device *dev)
struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
mtk_jpeg_clk_on(jpeg);
- mtk_jpeg_dec_reset(jpeg->dec_reg_base);
+ if (jpeg->mode == MTK_JPEG_ENC)
+ mtk_jpeg_enc_reset(jpeg->reg_base);
+ else
+ mtk_jpeg_dec_reset(jpeg->reg_base);
return 0;
}
@@ -1249,11 +1668,15 @@ static const struct dev_pm_ops mtk_jpeg_pm_ops = {
static const struct of_device_id mtk_jpeg_match[] = {
{
.compatible = "mediatek,mt8173-jpgdec",
- .data = NULL,
+ .data = (void *)MTK_JPEG_DEC,
},
{
.compatible = "mediatek,mt2701-jpgdec",
- .data = NULL,
+ .data = (void *)MTK_JPEG_DEC,
+ },
+ {
+ .compatible = "mediatek,mtk-jpgenc",
+ .data = (void *)MTK_JPEG_ENC,
},
{},
};
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
index 999bd1427809..9fbf0373971b 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h
@@ -3,6 +3,7 @@
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
+ * Xia Jiang <xia.jiang@mediatek.com>
*/
#ifndef _MTK_JPEG_CORE_H
@@ -17,6 +18,8 @@
#define MTK_JPEG_FMT_FLAG_DEC_OUTPUT BIT(0)
#define MTK_JPEG_FMT_FLAG_DEC_CAPTURE BIT(1)
+#define MTK_JPEG_FMT_FLAG_ENC_OUTPUT BIT(2)
+#define MTK_JPEG_FMT_FLAG_ENC_CAPTURE BIT(3)
#define MTK_JPEG_FMT_TYPE_OUTPUT 1
#define MTK_JPEG_FMT_TYPE_CAPTURE 2
@@ -28,12 +31,63 @@
#define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024)
+#define MTK_JPEG_ENCODE 0
+#define MTK_JPEG_DECODE 1
+
+/**
+ * enum mtk_jpeg_ctx_state - contex state of jpeg
+ */
enum mtk_jpeg_ctx_state {
MTK_JPEG_INIT = 0,
MTK_JPEG_RUNNING,
MTK_JPEG_SOURCE_CHANGE,
};
+/**
+ * enum mtk_jpeg_mode - mode of jpeg
+ */
+enum mtk_jpeg_mode {
+ MTK_JPEG_ENC,
+ MTK_JPEG_DEC,
+};
+
+/**
+ * enum jpeg_enc_yuv_fmt - yuv format of jpeg enc
+ */
+enum jpeg_enc_yuv_fmt {
+ JPEG_YUV_FORMAT_YUYV = 0,
+ JPEG_YUV_FORMAT_YVYU = 1,
+ JPEG_YUV_FORMAT_NV12 = 2,
+ JEPG_YUV_FORMAT_NV21 = 3,
+};
+
+/**
+ * enum JPEG_ENCODE_QUALITY_ENUM - number of jpeg encoder quality
+ */
+enum JPEG_ENCODE_QUALITY_ENUM {
+ JPEG_ENCODE_QUALITY_Q60 = 0x0,
+ JPEG_ENCODE_QUALITY_Q80 = 0x1,
+ JPEG_ENCODE_QUALITY_Q90 = 0x2,
+ JPEG_ENCODE_QUALITY_Q95 = 0x3,
+
+ JPEG_ENCODE_QUALITY_Q39 = 0x4,
+ JPEG_ENCODE_QUALITY_Q68 = 0x5,
+ JPEG_ENCODE_QUALITY_Q84 = 0x6,
+ JPEG_ENCODE_QUALITY_Q92 = 0x7,
+
+ JPEG_ENCODE_QUALITY_Q48 = 0x8,
+ JPEG_ENCODE_QUALITY_Q74 = 0xA,
+ JPEG_ENCODE_QUALITY_Q87 = 0xB,
+
+ JPEG_ENCODE_QUALITY_Q34 = 0xC,
+ JPEG_ENCODE_QUALITY_Q64 = 0xE,
+ JPEG_ENCODE_QUALITY_Q82 = 0xF,
+
+ JPEG_ENCODE_QUALITY_Q97 = 0x10,
+
+ JPEG_ENCODE_QUALITY_ALL = 0xFFFFFFFF
+};
+
/**
* struct mt_jpeg - JPEG IP abstraction
* @lock: the mutex protecting this structure
@@ -43,11 +97,12 @@ enum mtk_jpeg_ctx_state {
* @v4l2_dev: v4l2 device for mem2mem mode
* @m2m_dev: v4l2 mem2mem device data
* @alloc_ctx: videobuf2 memory allocator's context
- * @dec_vdev: video device node for decoder mem2mem mode
- * @dec_reg_base: JPEG registers mapping
- * @clk_jdec: JPEG hw working clock
- * @clk_jdec_smi: JPEG SMI bus clock
+ * @vfd_jpeg: video device node for jpeg mem2mem mode
+ * @reg_base: JPEG registers mapping
+ * @clk_jpeg: JPEG hw working clock
+ * @clk_jpeg_smi: JPEG SMI bus clock
* @larb: SMI device
+ * @mode: compression (encode) operation or decompression (decode)
*/
struct mtk_jpeg_dev {
struct mutex lock;
@@ -57,11 +112,12 @@ struct mtk_jpeg_dev {
struct v4l2_device v4l2_dev;
struct v4l2_m2m_dev *m2m_dev;
void *alloc_ctx;
- struct video_device *dec_vdev;
- void __iomem *dec_reg_base;
- struct clk *clk_jdec;
- struct clk *clk_jdec_smi;
+ struct video_device *vfd_jpeg;
+ void __iomem *reg_base;
+ struct clk *clk_jpeg;
+ struct clk *clk_jpeg_smi;
struct device *larb;
+ enum mtk_jpeg_mode mode;
};
/**
@@ -101,15 +157,51 @@ struct mtk_jpeg_q_data {
u32 sizeimage[VIDEO_MAX_PLANES];
};
+/**
+ * jpeg_enc_param - parameters of jpeg encode control
+ * @enable_exif: EXIF enable for jpeg encode mode
+ * @enc_quality: destination image quality in encode mode
+ * @restart_interval: JPEG restart interval for JPEG encoding
+ */
+struct jpeg_enc_param {
+ u32 enable_exif;
+ u32 enc_quality;
+ u32 restart_interval;
+};
+
+/**
+ * mtk_jpeg_enc_param: General jpeg encoding parameters
+ * @enc_w: image width
+ * @enc_h: image height
+ * @enable_exif: EXIF enable for jpeg encode mode
+ * @enc_quality: destination image quality in encode mode
+ * @enc_format: input image format
+ * @restart_interval: JPEG restart interval for JPEG encoding
+ * @img_stride: jpeg encoder image stride
+ * @mem_stride: jpeg encoder memory stride
+ * @total_encdu: total 8x8 block number
+ */
+struct mtk_jpeg_enc_param {
+ u32 enc_w;
+ u32 enc_h;
+ u32 enable_exif;
+ u32 enc_quality;
+ u32 enc_format;
+ u32 restart_interval;
+ u32 img_stride;
+ u32 mem_stride;
+ u32 total_encdu;
+};
+
/**
* mtk_jpeg_ctx - the device context data
* @jpeg: JPEG IP device for this context
* @out_q: source (output) queue information
* @cap_q: destination (capture) queue queue information
* @fh: V4L2 file handle
- * @dec_param parameters for HW decoding
* @state: state of the context
- * @header_valid: set if header has been parsed and valid
+ * @jpeg_param: jpeg encode parameters
+ * @ctrl_hdl: controls handler
* @colorspace: enum v4l2_colorspace; supplemental to pixelformat
* @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
* @quantization: enum v4l2_quantization, colorspace quantization
@@ -121,6 +213,8 @@ struct mtk_jpeg_ctx {
struct mtk_jpeg_q_data cap_q;
struct v4l2_fh fh;
enum mtk_jpeg_ctx_state state;
+ struct jpeg_enc_param jpeg_param;
+ struct v4l2_ctrl_handler ctrl_hdl;
enum v4l2_colorspace colorspace;
enum v4l2_ycbcr_encoding ycbcr_enc;
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h
index a37be1a48415..39d743fb572f 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h
@@ -3,10 +3,11 @@
* Copyright (c) 2016 MediaTek Inc.
* Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
* Rick Chang <rick.chang@mediatek.com>
+ * Xia Jiang <xia.jiang@mediatek.com>
*/
-#ifndef _MTK_JPEG_HW_H
-#define _MTK_JPEG_HW_H
+#ifndef _MTK_JPEG_DEC_HW_H
+#define _MTK_JPEG_DEC_HW_H
#include <media/videobuf2-core.h>
@@ -80,4 +81,4 @@ void mtk_jpeg_dec_set_config(void __iomem *base,
void mtk_jpeg_dec_reset(void __iomem *dec_reg_base);
void mtk_jpeg_dec_start(void __iomem *dec_reg_base);
-#endif /* _MTK_JPEG_HW_H */
+#endif /* _MTK_JPEG_DEC_HW_H */
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c
new file mode 100644
index 000000000000..ac27774ccfed
--- /dev/null
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c
@@ -0,0 +1,175 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ * Author: Xia Jiang <xia.jiang@mediatek.com>
+ *
+ */
+
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <media/videobuf2-core.h>
+
+#include "mtk_jpeg_enc_hw.h"
+
+void mtk_jpeg_enc_reset(void __iomem *base)
+{
+ writel(0x00, base + JPGENC_RSTB);
+ writel(JPEG_ENC_RESET_BIT, base + JPGENC_RSTB);
+ writel(0x00, base + JPGENC_CODEC_SEL);
+}
+
+u32 mtk_jpeg_enc_get_int_status(void __iomem *base)
+{
+ u32 ret;
+
+ ret = readl(base + JPGENC_INT_STS) &
+ JPEG_DRV_ENC_INT_STATUS_MASK_ALLIRQ;
+ if (ret)
+ writel(0, base + JPGENC_INT_STS);
+
+ return ret;
+}
+
+u32 mtk_jpeg_enc_get_file_size(void __iomem *base)
+{
+ return readl(base + JPGENC_DMA_ADDR0) - readl(base + JPGENC_DST_ADDR0);
+}
+
+u32 mtk_jpeg_enc_enum_result(void __iomem *base, u32 irq_status, u32 *file_size)
+{
+ *file_size = mtk_jpeg_enc_get_file_size(base);
+ if (irq_status & JPEG_DRV_ENC_INT_STATUS_DONE)
+ return MTK_JPEG_ENC_RESULT_DONE;
+ else if (irq_status & JPEG_DRV_ENC_INT_STATUS_STALL)
+ return MTK_JPEG_ENC_RESULT_STALL;
+ else if (irq_status & JPEG_DRV_ENC_INT_STATUS_VCODEC_IRQ)
+ return MTK_JPEG_ENC_RESULT_VCODEC_IRQ;
+ return MTK_JPEG_ENC_RESULT_ERROR_UNKNOWN;
+}
+
+static void mtk_jpeg_enc_set_blk_num(void __iomem *base, u32 blk_num)
+{
+ writel(blk_num, base + JPGENC_BLK_NUM);
+}
+
+static void mtk_jpeg_enc_set_encFormat(void __iomem *base, u32 enc_format)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_CTRL);
+ value &= ~JPEG_ENC_CTRL_YUV_BIT;
+ value |= JPGENC_FORMAT(enc_format);
+ writel(value, base + JPGENC_CTRL);
+}
+
+static void mtk_jpeg_enc_set_img_size(void __iomem *base, u32 width, u32 height)
+{
+ u32 value;
+
+ value = JPGENC_WIDTH_HEIGHT(width, height);
+ writel(value, base + JPGENC_IMG_SIZE);
+}
+
+static void mtk_jpeg_enc_set_src_img(void __iomem *base, u32 width,
+ u32 height, u32 yuv_format,
+ u32 total_encdu)
+{
+ mtk_jpeg_enc_set_img_size(base, width, height);
+ mtk_jpeg_enc_set_encFormat(base, yuv_format);
+ mtk_jpeg_enc_set_blk_num(base, total_encdu);
+}
+
+static void mtk_jpeg_enc_set_src_buf(void __iomem *base, u32 img_stride,
+ u32 mem_stride, u32 src_addr,
+ u32 src_addr_c)
+{
+ writel(img_stride, base + JPGENC_IMG_STRIDE);
+ writel(mem_stride, base + JPGENC_STRIDE);
+ writel(src_addr, base + JPGENC_SRC_LUMA_ADDR);
+ writel(src_addr_c, base + JPGENC_SRC_CHROMA_ADDR);
+}
+
+static void mtk_jpeg_enc_set_dst_buf(void __iomem *base, u32 dst_addr,
+ u32 stall_size, u32 init_offset,
+ u32 offset_mask)
+{
+ writel(JPGENC_INIT_OFFSET(init_offset), base + JPGENC_OFFSET_ADDR);
+ writel(JPGENC_OFFSET_MASK(offset_mask), base + JPGENC_BYTE_OFFSET_MASK);
+ writel(JPGENC_DST_ADDR(dst_addr), base + JPGENC_DST_ADDR0);
+ writel(JPGENC_STALL_ADDR(dst_addr, stall_size),
+ base + JPGENC_STALL_ADDR0);
+}
+
+static void mtk_jpeg_enc_set_quality(void __iomem *base, u32 quality)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_QUALITY);
+ value = JPGENC_SET_QUALITY(value, quality);
+ writel(value, base + JPGENC_QUALITY);
+}
+
+static void mtk_jpeg_enc_set_restart_interval(void __iomem *base,
+ u32 restart_interval)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_CTRL);
+ if (restart_interval)
+ value |= JPEG_ENC_CTRL_RESTART_EN_BIT;
+ else
+ value &= ~JPEG_ENC_CTRL_RESTART_EN_BIT;
+ writel(value, base + JPGENC_CTRL);
+ writel(restart_interval, base + JPGENC_RST_MCU_NUM);
+}
+
+static void mtk_jpeg_enc_set_encode_mode(void __iomem *base, u32 exif_en)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_CTRL);
+ value &= ~JPEG_ENC_CTRL_FILE_FORMAT_BIT;
+ writel(value, base + JPGENC_CTRL);
+
+ if (exif_en) {
+ value = readl(base + JPGENC_CTRL);
+ value |= JPEG_ENC_EN_JFIF_EXIF;
+ writel(value, base + JPGENC_CTRL);
+ }
+}
+
+static void mtk_jpeg_enc_set_ctrl_cfg(void __iomem *base, u32 exif_en,
+ u32 quality, u32 restart_interval)
+{
+ mtk_jpeg_enc_set_quality(base, quality);
+
+ mtk_jpeg_enc_set_restart_interval(base, restart_interval);
+
+ mtk_jpeg_enc_set_encode_mode(base, exif_en);
+}
+
+void mtk_jpeg_enc_start(void __iomem *base)
+{
+ u32 value;
+
+ value = readl(base + JPGENC_CTRL);
+ value |= JPEG_ENC_CTRL_INT_EN_BIT | JPEG_ENC_CTRL_ENABLE_BIT;
+ writel(value, base + JPGENC_CTRL);
+}
+
+void mtk_jpeg_enc_set_config(void __iomem *base,
+ struct mtk_jpeg_enc_param *config,
+ struct mtk_jpeg_enc_bs *bs,
+ struct mtk_jpeg_enc_fb *fb)
+{
+ mtk_jpeg_enc_set_src_img(base, config->enc_w, config->enc_h,
+ config->enc_format, config->total_encdu);
+ mtk_jpeg_enc_set_src_buf(base, config->img_stride, config->mem_stride,
+ fb->fb_addr[0].dma_addr,
+ fb->fb_addr[1].dma_addr);
+ mtk_jpeg_enc_set_dst_buf(base, bs->dma_addr, bs->size,
+ bs->dma_addr_offset, bs->dma_addr_offsetmask);
+ mtk_jpeg_enc_set_ctrl_cfg(base, config->enable_exif,
+ config->enc_quality,
+ config->restart_interval);
+}
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h
new file mode 100644
index 000000000000..7080240f6dac
--- /dev/null
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ * Author: Xia Jiang <xia.jiang@mediatek.com>
+ *
+ */
+
+#ifndef _MTK_JPEG_ENC_HW_H
+#define _MTK_JPEG_ENC_HW_H
+
+#include <media/videobuf2-core.h>
+
+#include "mtk_jpeg_core.h"
+#include "mtk_jpeg_enc_reg.h"
+
+#define JPEG_ENC_DST_ADDR_OFFSET_MASK GENMASK(3, 0)
+
+#define JPEG_ENC_CTRL_YUV_BIT 0x18
+#define JPEG_ENC_CTRL_RESTART_EN_BIT BIT(10)
+#define JPEG_ENC_CTRL_FILE_FORMAT_BIT BIT(5)
+#define JPEG_ENC_EN_JFIF_EXIF BIT(5)
+#define JPEG_ENC_CTRL_INT_EN_BIT BIT(2)
+#define JPEG_ENC_CTRL_ENABLE_BIT BIT(0)
+#define JPEG_ENC_RESET_BIT BIT(0)
+
+enum {
+ MTK_JPEG_ENC_RESULT_DONE = 0,
+ MTK_JPEG_ENC_RESULT_STALL,
+ MTK_JPEG_ENC_RESULT_VCODEC_IRQ,
+ MTK_JPEG_ENC_RESULT_ERROR_UNKNOWN
+};
+
+struct mtk_jpeg_enc_bs {
+ dma_addr_t dma_addr;
+ size_t size;
+ u32 dma_addr_offset;
+ u32 dma_addr_offsetmask;
+};
+
+struct mtk_jpeg_mem {
+ dma_addr_t dma_addr;
+ size_t size;
+};
+
+struct mtk_jpeg_enc_fb {
+ struct mtk_jpeg_mem fb_addr[MTK_JPEG_COMP_MAX];
+ u32 num_planes;
+};
+
+void mtk_jpeg_enc_reset(void __iomem *base);
+u32 mtk_jpeg_enc_get_int_status(void __iomem *base);
+u32 mtk_jpeg_enc_get_file_size(void __iomem *base);
+u32 mtk_jpeg_enc_enum_result(void __iomem *base, u32 irq_status,
+ u32 *file_size);
+void mtk_jpeg_enc_start(void __iomem *enc_reg_base);
+void mtk_jpeg_enc_set_config(void __iomem *base,
+ struct mtk_jpeg_enc_param *config,
+ struct mtk_jpeg_enc_bs *bs,
+ struct mtk_jpeg_enc_fb *fb);
+#endif /* _MTK_JPEG_ENC_HW_H */
diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h
new file mode 100644
index 000000000000..d785621cb4c6
--- /dev/null
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ * Author: Xia Jiang <xia.jiang@mediatek.com>
+ *
+ */
+#ifndef _MTK_JPEG_ENC_REG_H
+#define _MTK_JPEG_ENC_REG_H
+#define MTK_JPEG_COMP_MAX 3
+
+#define JPEG_DRV_ENC_INT_STATUS_DONE BIT(0)
+#define JPEG_DRV_ENC_INT_STATUS_STALL BIT(1)
+#define JPEG_DRV_ENC_INT_STATUS_VCODEC_IRQ BIT(4)
+#define JPEG_DRV_ENC_INT_STATUS_MASK_ALLIRQ 0x13
+
+#define JPGENC_RSTB 0x100
+#define JPGENC_CTRL 0x104
+#define JPGENC_QUALITY 0x108
+#define JPGENC_BLK_NUM 0x10C
+#define JPGENC_BLK_CNT 0x110
+#define JPGENC_INT_STS 0x11C
+#define JPGENC_DST_ADDR0 0x120
+#define JPGENC_DMA_ADDR0 0x124
+#define JPGENC_STALL_ADDR0 0x128
+#define JPGENC_OFFSET_ADDR 0x138
+#define JPGENC_RST_MCU_NUM 0x150
+#define JPGENC_IMG_SIZE 0x154
+#define JPGENC_DEBUG_INFO0 0x160
+#define JPGENC_DEBUG_INFO1 0x164
+#define JPGENC_TOTAL_CYCLE 0x168
+#define JPGENC_BYTE_OFFSET_MASK 0x16C
+#define JPGENC_SRC_LUMA_ADDR 0x170
+#define JPGENC_SRC_CHROMA_ADDR 0x174
+#define JPGENC_STRIDE 0x178
+#define JPGENC_IMG_STRIDE 0x17C
+#define JPGENC_DCM_CTRL 0x300
+#define JPGENC_CODEC_SEL 0x314
+#define JPGENC_ULTRA_THRES 0x318
+
+#define JPGENC_FORMAT(x) (((x) & 3) << 3)
+#define JPGENC_WIDTH_HEIGHT(w, h) (((w) << 16) | (h))
+#define JPGENC_INIT_OFFSET(x) ((x) & (~0xF))
+#define JPGENC_OFFSET_MASK(x) ((x) & 0xF)
+#define JPGENC_DST_ADDR(x) ((x) & (~0xF))
+#define JPGENC_STALL_ADDR(x, y) (((x) + (y)) & (~0xF))
+#define JPGENC_QUALITY_MASK 0xFFFF0000
+#define JPGENC_SET_QUALITY(x, y) (((x) & JPGENC_QUALITY_MASK) | (y))
+
+#endif /* _MTK_JPEG_ENC_REG_H */
--
2.18.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
2019-09-24 7:43 ` Xia Jiang
@ 2019-09-24 10:11 ` kbuild test robot
-1 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2019-09-24 10:11 UTC (permalink / raw)
To: Xia Jiang
Cc: kbuild-all, Hans Verkuil, Mauro Carvalho Chehab, Rob Herring,
Matthias Brugger, Rick Chang, linux-media, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek, Marek Szyprowski,
Tomasz Figa, srv_heupstream, Xia Jiang
[-- Attachment #1: Type: text/plain, Size: 35849 bytes --]
Hi Xia,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linuxtv-media/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Xia-Jiang/Add-support-for-mt2701-JPEG-ENC-support/20190924-161234
base: git://linuxtv.org/media_tree.git master
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c: In function 'mtk_jpeg_querycap':
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:139:2: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
else
^~~~
drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:141:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
^~~~~~~~
In file included from include/linux/clk.h:13:0,
from drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:9:
drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c: In function 'mtk_jpeg_try_fmt_mplane':
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:829:48: note: in definition of macro '__is_constexpr'
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
^
>> include/linux/kernel.h:835:25: note: in expansion of macro '__no_side_effects'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:27: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:40: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:840:10: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:840:25: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
--
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c: In function 'mtk_jpeg_querycap':
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:139:2: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
else
^~~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:141:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
^~~~~~~~
In file included from include/linux/clk.h:13:0,
from drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:9:
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c: In function 'mtk_jpeg_try_fmt_mplane':
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:829:48: note: in definition of macro '__is_constexpr'
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
^
>> include/linux/kernel.h:835:25: note: in expansion of macro '__no_side_effects'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:27: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:40: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:840:10: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:840:25: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:20: note: in expansion of macro 'clamp'
pix_mp->width = clamp(pix_mp->width,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:20: note: in expansion of macro 'clamp'
pix_mp->width = clamp(pix_mp->width,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:829:48: note: in definition of macro '__is_constexpr'
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
^
>> include/linux/kernel.h:835:25: note: in expansion of macro '__no_side_effects'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:20: note: in expansion of macro 'clamp'
pix_mp->width = clamp(pix_mp->width,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:27: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
vim +/min +898 include/linux/kernel.h
526211bc58c4b3 Ingo Molnar 2009-03-05 807
^1da177e4c3f41 Linus Torvalds 2005-04-16 808 /*
3c8ba0d61d04ce Kees Cook 2018-03-30 809 * min()/max()/clamp() macros must accomplish three things:
3c8ba0d61d04ce Kees Cook 2018-03-30 810 *
3c8ba0d61d04ce Kees Cook 2018-03-30 811 * - avoid multiple evaluations of the arguments (so side-effects like
3c8ba0d61d04ce Kees Cook 2018-03-30 812 * "x++" happen only once) when non-constant.
3c8ba0d61d04ce Kees Cook 2018-03-30 813 * - perform strict type-checking (to generate warnings instead of
3c8ba0d61d04ce Kees Cook 2018-03-30 814 * nasty runtime surprises). See the "unnecessary" pointer comparison
3c8ba0d61d04ce Kees Cook 2018-03-30 815 * in __typecheck().
3c8ba0d61d04ce Kees Cook 2018-03-30 816 * - retain result as a constant expressions when called with only
3c8ba0d61d04ce Kees Cook 2018-03-30 817 * constant expressions (to avoid tripping VLA warnings in stack
3c8ba0d61d04ce Kees Cook 2018-03-30 818 * allocation usage).
3c8ba0d61d04ce Kees Cook 2018-03-30 819 */
3c8ba0d61d04ce Kees Cook 2018-03-30 820 #define __typecheck(x, y) \
3c8ba0d61d04ce Kees Cook 2018-03-30 @821 (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
3c8ba0d61d04ce Kees Cook 2018-03-30 822
3c8ba0d61d04ce Kees Cook 2018-03-30 823 /*
3c8ba0d61d04ce Kees Cook 2018-03-30 824 * This returns a constant expression while determining if an argument is
3c8ba0d61d04ce Kees Cook 2018-03-30 825 * a constant expression, most importantly without evaluating the argument.
3c8ba0d61d04ce Kees Cook 2018-03-30 826 * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de>
^1da177e4c3f41 Linus Torvalds 2005-04-16 827 */
3c8ba0d61d04ce Kees Cook 2018-03-30 828 #define __is_constexpr(x) \
3c8ba0d61d04ce Kees Cook 2018-03-30 829 (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
3c8ba0d61d04ce Kees Cook 2018-03-30 830
3c8ba0d61d04ce Kees Cook 2018-03-30 831 #define __no_side_effects(x, y) \
3c8ba0d61d04ce Kees Cook 2018-03-30 832 (__is_constexpr(x) && __is_constexpr(y))
3c8ba0d61d04ce Kees Cook 2018-03-30 833
3c8ba0d61d04ce Kees Cook 2018-03-30 834 #define __safe_cmp(x, y) \
3c8ba0d61d04ce Kees Cook 2018-03-30 @835 (__typecheck(x, y) && __no_side_effects(x, y))
3c8ba0d61d04ce Kees Cook 2018-03-30 836
3c8ba0d61d04ce Kees Cook 2018-03-30 837 #define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
3c8ba0d61d04ce Kees Cook 2018-03-30 838
e9092d0d979611 Linus Torvalds 2018-04-09 839 #define __cmp_once(x, y, unique_x, unique_y, op) ({ \
e9092d0d979611 Linus Torvalds 2018-04-09 840 typeof(x) unique_x = (x); \
e9092d0d979611 Linus Torvalds 2018-04-09 841 typeof(y) unique_y = (y); \
e9092d0d979611 Linus Torvalds 2018-04-09 842 __cmp(unique_x, unique_y, op); })
3c8ba0d61d04ce Kees Cook 2018-03-30 843
3c8ba0d61d04ce Kees Cook 2018-03-30 844 #define __careful_cmp(x, y, op) \
3c8ba0d61d04ce Kees Cook 2018-03-30 845 __builtin_choose_expr(__safe_cmp(x, y), \
e9092d0d979611 Linus Torvalds 2018-04-09 846 __cmp(x, y, op), \
e9092d0d979611 Linus Torvalds 2018-04-09 847 __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op))
e8c97af0c1f23d Randy Dunlap 2017-10-13 848
e8c97af0c1f23d Randy Dunlap 2017-10-13 849 /**
e8c97af0c1f23d Randy Dunlap 2017-10-13 850 * min - return minimum of two values of the same or compatible types
e8c97af0c1f23d Randy Dunlap 2017-10-13 851 * @x: first value
e8c97af0c1f23d Randy Dunlap 2017-10-13 852 * @y: second value
e8c97af0c1f23d Randy Dunlap 2017-10-13 853 */
3c8ba0d61d04ce Kees Cook 2018-03-30 854 #define min(x, y) __careful_cmp(x, y, <)
e8c97af0c1f23d Randy Dunlap 2017-10-13 855
e8c97af0c1f23d Randy Dunlap 2017-10-13 856 /**
e8c97af0c1f23d Randy Dunlap 2017-10-13 857 * max - return maximum of two values of the same or compatible types
e8c97af0c1f23d Randy Dunlap 2017-10-13 858 * @x: first value
e8c97af0c1f23d Randy Dunlap 2017-10-13 859 * @y: second value
e8c97af0c1f23d Randy Dunlap 2017-10-13 860 */
3c8ba0d61d04ce Kees Cook 2018-03-30 861 #define max(x, y) __careful_cmp(x, y, >)
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 862
e8c97af0c1f23d Randy Dunlap 2017-10-13 863 /**
e8c97af0c1f23d Randy Dunlap 2017-10-13 864 * min3 - return minimum of three values
e8c97af0c1f23d Randy Dunlap 2017-10-13 865 * @x: first value
e8c97af0c1f23d Randy Dunlap 2017-10-13 866 * @y: second value
e8c97af0c1f23d Randy Dunlap 2017-10-13 867 * @z: third value
e8c97af0c1f23d Randy Dunlap 2017-10-13 868 */
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 869 #define min3(x, y, z) min((typeof(x))min(x, y), z)
e8c97af0c1f23d Randy Dunlap 2017-10-13 870
e8c97af0c1f23d Randy Dunlap 2017-10-13 871 /**
e8c97af0c1f23d Randy Dunlap 2017-10-13 872 * max3 - return maximum of three values
e8c97af0c1f23d Randy Dunlap 2017-10-13 873 * @x: first value
e8c97af0c1f23d Randy Dunlap 2017-10-13 874 * @y: second value
e8c97af0c1f23d Randy Dunlap 2017-10-13 875 * @z: third value
e8c97af0c1f23d Randy Dunlap 2017-10-13 876 */
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 877 #define max3(x, y, z) max((typeof(x))max(x, y), z)
f27c85c56b32c4 Hagen Paul Pfeifer 2010-10-26 878
c8bf1336824ebd Martin K. Petersen 2010-09-10 879 /**
c8bf1336824ebd Martin K. Petersen 2010-09-10 880 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
c8bf1336824ebd Martin K. Petersen 2010-09-10 881 * @x: value1
c8bf1336824ebd Martin K. Petersen 2010-09-10 882 * @y: value2
c8bf1336824ebd Martin K. Petersen 2010-09-10 883 */
c8bf1336824ebd Martin K. Petersen 2010-09-10 884 #define min_not_zero(x, y) ({ \
c8bf1336824ebd Martin K. Petersen 2010-09-10 885 typeof(x) __x = (x); \
c8bf1336824ebd Martin K. Petersen 2010-09-10 886 typeof(y) __y = (y); \
c8bf1336824ebd Martin K. Petersen 2010-09-10 887 __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
c8bf1336824ebd Martin K. Petersen 2010-09-10 888
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 889 /**
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 890 * clamp - return a value clamped to a given range with strict typechecking
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 891 * @val: current value
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 892 * @lo: lowest allowable value
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 893 * @hi: highest allowable value
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 894 *
e8c97af0c1f23d Randy Dunlap 2017-10-13 895 * This macro does strict typechecking of @lo/@hi to make sure they are of the
e8c97af0c1f23d Randy Dunlap 2017-10-13 896 * same type as @val. See the unnecessary pointer comparisons.
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 897 */
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 @898 #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^1da177e4c3f41 Linus Torvalds 2005-04-16 899
:::::: The code at line 898 was first introduced by commit
:::::: 2e1d06e1c05af9dbe8a3bfddeefbf041ca637fff include/linux/kernel.h: rewrite min3, max3 and clamp using min and max
:::::: TO: Michal Nazarewicz <mina86@mina86.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 58654 bytes --]
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
@ 2019-09-24 10:11 ` kbuild test robot
0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2019-09-24 10:11 UTC (permalink / raw)
Cc: kbuild-all, Hans Verkuil, Mauro Carvalho Chehab, Rob Herring,
Matthias Brugger, Rick Chang, linux-media, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek, Marek Szyprowski,
Tomasz Figa, srv_heupstream, Xia Jiang
[-- Attachment #1: Type: text/plain, Size: 35849 bytes --]
Hi Xia,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linuxtv-media/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Xia-Jiang/Add-support-for-mt2701-JPEG-ENC-support/20190924-161234
base: git://linuxtv.org/media_tree.git master
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c: In function 'mtk_jpeg_querycap':
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:139:2: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
else
^~~~
drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:141:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
^~~~~~~~
In file included from include/linux/clk.h:13:0,
from drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:9:
drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c: In function 'mtk_jpeg_try_fmt_mplane':
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:829:48: note: in definition of macro '__is_constexpr'
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
^
>> include/linux/kernel.h:835:25: note: in expansion of macro '__no_side_effects'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:27: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:40: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:840:10: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
>> drivers/media//platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:840:25: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
--
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c: In function 'mtk_jpeg_querycap':
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:139:2: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
else
^~~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:141:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
^~~~~~~~
In file included from include/linux/clk.h:13:0,
from drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:9:
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c: In function 'mtk_jpeg_try_fmt_mplane':
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:829:48: note: in definition of macro '__is_constexpr'
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
^
>> include/linux/kernel.h:835:25: note: in expansion of macro '__no_side_effects'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:27: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:40: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:840:10: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:840:25: note: in definition of macro '__cmp_once'
typeof(x) unique_x = (x); \
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:21: note: in expansion of macro 'clamp'
pix_mp->height = clamp(pix_mp->height,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:20: note: in expansion of macro 'clamp'
pix_mp->width = clamp(pix_mp->width,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:20: note: in expansion of macro 'clamp'
pix_mp->width = clamp(pix_mp->width,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:829:48: note: in definition of macro '__is_constexpr'
(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
^
>> include/linux/kernel.h:835:25: note: in expansion of macro '__no_side_effects'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:28: note: in expansion of macro 'min'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
include/linux/kernel.h:835:4: note: in expansion of macro '__typecheck'
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
include/linux/kernel.h:845:24: note: in expansion of macro '__safe_cmp'
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
include/linux/kernel.h:861:19: note: in expansion of macro '__careful_cmp'
#define max(x, y) __careful_cmp(x, y, >)
^~~~~~~~~~~~~
>> include/linux/kernel.h:898:45: note: in expansion of macro 'max'
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^~~
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:20: note: in expansion of macro 'clamp'
pix_mp->width = clamp(pix_mp->width,
^~~~~
include/linux/kernel.h:821:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
include/linux/kernel.h:837:27: note: in definition of macro '__cmp'
#define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
^
include/linux/kernel.h:854:19: note: in expansion of macro '__careful_cmp'
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
vim +/min +898 include/linux/kernel.h
526211bc58c4b3 Ingo Molnar 2009-03-05 807
^1da177e4c3f41 Linus Torvalds 2005-04-16 808 /*
3c8ba0d61d04ce Kees Cook 2018-03-30 809 * min()/max()/clamp() macros must accomplish three things:
3c8ba0d61d04ce Kees Cook 2018-03-30 810 *
3c8ba0d61d04ce Kees Cook 2018-03-30 811 * - avoid multiple evaluations of the arguments (so side-effects like
3c8ba0d61d04ce Kees Cook 2018-03-30 812 * "x++" happen only once) when non-constant.
3c8ba0d61d04ce Kees Cook 2018-03-30 813 * - perform strict type-checking (to generate warnings instead of
3c8ba0d61d04ce Kees Cook 2018-03-30 814 * nasty runtime surprises). See the "unnecessary" pointer comparison
3c8ba0d61d04ce Kees Cook 2018-03-30 815 * in __typecheck().
3c8ba0d61d04ce Kees Cook 2018-03-30 816 * - retain result as a constant expressions when called with only
3c8ba0d61d04ce Kees Cook 2018-03-30 817 * constant expressions (to avoid tripping VLA warnings in stack
3c8ba0d61d04ce Kees Cook 2018-03-30 818 * allocation usage).
3c8ba0d61d04ce Kees Cook 2018-03-30 819 */
3c8ba0d61d04ce Kees Cook 2018-03-30 820 #define __typecheck(x, y) \
3c8ba0d61d04ce Kees Cook 2018-03-30 @821 (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
3c8ba0d61d04ce Kees Cook 2018-03-30 822
3c8ba0d61d04ce Kees Cook 2018-03-30 823 /*
3c8ba0d61d04ce Kees Cook 2018-03-30 824 * This returns a constant expression while determining if an argument is
3c8ba0d61d04ce Kees Cook 2018-03-30 825 * a constant expression, most importantly without evaluating the argument.
3c8ba0d61d04ce Kees Cook 2018-03-30 826 * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de>
^1da177e4c3f41 Linus Torvalds 2005-04-16 827 */
3c8ba0d61d04ce Kees Cook 2018-03-30 828 #define __is_constexpr(x) \
3c8ba0d61d04ce Kees Cook 2018-03-30 829 (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
3c8ba0d61d04ce Kees Cook 2018-03-30 830
3c8ba0d61d04ce Kees Cook 2018-03-30 831 #define __no_side_effects(x, y) \
3c8ba0d61d04ce Kees Cook 2018-03-30 832 (__is_constexpr(x) && __is_constexpr(y))
3c8ba0d61d04ce Kees Cook 2018-03-30 833
3c8ba0d61d04ce Kees Cook 2018-03-30 834 #define __safe_cmp(x, y) \
3c8ba0d61d04ce Kees Cook 2018-03-30 @835 (__typecheck(x, y) && __no_side_effects(x, y))
3c8ba0d61d04ce Kees Cook 2018-03-30 836
3c8ba0d61d04ce Kees Cook 2018-03-30 837 #define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
3c8ba0d61d04ce Kees Cook 2018-03-30 838
e9092d0d979611 Linus Torvalds 2018-04-09 839 #define __cmp_once(x, y, unique_x, unique_y, op) ({ \
e9092d0d979611 Linus Torvalds 2018-04-09 840 typeof(x) unique_x = (x); \
e9092d0d979611 Linus Torvalds 2018-04-09 841 typeof(y) unique_y = (y); \
e9092d0d979611 Linus Torvalds 2018-04-09 842 __cmp(unique_x, unique_y, op); })
3c8ba0d61d04ce Kees Cook 2018-03-30 843
3c8ba0d61d04ce Kees Cook 2018-03-30 844 #define __careful_cmp(x, y, op) \
3c8ba0d61d04ce Kees Cook 2018-03-30 845 __builtin_choose_expr(__safe_cmp(x, y), \
e9092d0d979611 Linus Torvalds 2018-04-09 846 __cmp(x, y, op), \
e9092d0d979611 Linus Torvalds 2018-04-09 847 __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op))
e8c97af0c1f23d Randy Dunlap 2017-10-13 848
e8c97af0c1f23d Randy Dunlap 2017-10-13 849 /**
e8c97af0c1f23d Randy Dunlap 2017-10-13 850 * min - return minimum of two values of the same or compatible types
e8c97af0c1f23d Randy Dunlap 2017-10-13 851 * @x: first value
e8c97af0c1f23d Randy Dunlap 2017-10-13 852 * @y: second value
e8c97af0c1f23d Randy Dunlap 2017-10-13 853 */
3c8ba0d61d04ce Kees Cook 2018-03-30 854 #define min(x, y) __careful_cmp(x, y, <)
e8c97af0c1f23d Randy Dunlap 2017-10-13 855
e8c97af0c1f23d Randy Dunlap 2017-10-13 856 /**
e8c97af0c1f23d Randy Dunlap 2017-10-13 857 * max - return maximum of two values of the same or compatible types
e8c97af0c1f23d Randy Dunlap 2017-10-13 858 * @x: first value
e8c97af0c1f23d Randy Dunlap 2017-10-13 859 * @y: second value
e8c97af0c1f23d Randy Dunlap 2017-10-13 860 */
3c8ba0d61d04ce Kees Cook 2018-03-30 861 #define max(x, y) __careful_cmp(x, y, >)
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 862
e8c97af0c1f23d Randy Dunlap 2017-10-13 863 /**
e8c97af0c1f23d Randy Dunlap 2017-10-13 864 * min3 - return minimum of three values
e8c97af0c1f23d Randy Dunlap 2017-10-13 865 * @x: first value
e8c97af0c1f23d Randy Dunlap 2017-10-13 866 * @y: second value
e8c97af0c1f23d Randy Dunlap 2017-10-13 867 * @z: third value
e8c97af0c1f23d Randy Dunlap 2017-10-13 868 */
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 869 #define min3(x, y, z) min((typeof(x))min(x, y), z)
e8c97af0c1f23d Randy Dunlap 2017-10-13 870
e8c97af0c1f23d Randy Dunlap 2017-10-13 871 /**
e8c97af0c1f23d Randy Dunlap 2017-10-13 872 * max3 - return maximum of three values
e8c97af0c1f23d Randy Dunlap 2017-10-13 873 * @x: first value
e8c97af0c1f23d Randy Dunlap 2017-10-13 874 * @y: second value
e8c97af0c1f23d Randy Dunlap 2017-10-13 875 * @z: third value
e8c97af0c1f23d Randy Dunlap 2017-10-13 876 */
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 877 #define max3(x, y, z) max((typeof(x))max(x, y), z)
f27c85c56b32c4 Hagen Paul Pfeifer 2010-10-26 878
c8bf1336824ebd Martin K. Petersen 2010-09-10 879 /**
c8bf1336824ebd Martin K. Petersen 2010-09-10 880 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
c8bf1336824ebd Martin K. Petersen 2010-09-10 881 * @x: value1
c8bf1336824ebd Martin K. Petersen 2010-09-10 882 * @y: value2
c8bf1336824ebd Martin K. Petersen 2010-09-10 883 */
c8bf1336824ebd Martin K. Petersen 2010-09-10 884 #define min_not_zero(x, y) ({ \
c8bf1336824ebd Martin K. Petersen 2010-09-10 885 typeof(x) __x = (x); \
c8bf1336824ebd Martin K. Petersen 2010-09-10 886 typeof(y) __y = (y); \
c8bf1336824ebd Martin K. Petersen 2010-09-10 887 __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
c8bf1336824ebd Martin K. Petersen 2010-09-10 888
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 889 /**
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 890 * clamp - return a value clamped to a given range with strict typechecking
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 891 * @val: current value
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 892 * @lo: lowest allowable value
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 893 * @hi: highest allowable value
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 894 *
e8c97af0c1f23d Randy Dunlap 2017-10-13 895 * This macro does strict typechecking of @lo/@hi to make sure they are of the
e8c97af0c1f23d Randy Dunlap 2017-10-13 896 * same type as @val. See the unnecessary pointer comparisons.
bdf4bbaaee3d4b Harvey Harrison 2008-04-30 897 */
2e1d06e1c05af9 Michal Nazarewicz 2014-10-09 @898 #define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
^1da177e4c3f41 Linus Torvalds 2005-04-16 899
:::::: The code at line 898 was first introduced by commit
:::::: 2e1d06e1c05af9dbe8a3bfddeefbf041ca637fff include/linux/kernel.h: rewrite min3, max3 and clamp using min and max
:::::: TO: Michal Nazarewicz <mina86@mina86.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 58654 bytes --]
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
2019-09-24 7:43 ` Xia Jiang
(?)
@ 2019-09-24 10:56 ` kbuild test robot
-1 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2019-09-24 10:56 UTC (permalink / raw)
To: Xia Jiang
Cc: kbuild-all, Hans Verkuil, Mauro Carvalho Chehab, Rob Herring,
Matthias Brugger, Rick Chang, linux-media, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek, Marek Szyprowski,
Tomasz Figa, srv_heupstream, Xia Jiang
Hi Xia,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linuxtv-media/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Xia-Jiang/Add-support-for-mt2701-JPEG-ENC-support/20190924-161234
base: git://linuxtv.org/media_tree.git master
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-rc1-7-g2b96cd8-dirty
make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
sparse warnings: (new ones prefixed by >>)
include/linux/sched.h:609:43: sparse: sparse: bad integer constant expression
include/linux/sched.h:609:73: sparse: sparse: invalid named zero-width bitfield `value'
include/linux/sched.h:610:43: sparse: sparse: bad integer constant expression
include/linux/sched.h:610:67: sparse: sparse: invalid named zero-width bitfield `bucket_id'
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
vim +338 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
316
317 static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
318 struct mtk_jpeg_fmt *fmt,
319 struct mtk_jpeg_ctx *ctx, int q_type)
320 {
321 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
322 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
323 int i, align_w, align_h;
324
325 memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
326 pix_mp->field = V4L2_FIELD_NONE;
327
328 if (ctx->state != MTK_JPEG_INIT) {
329 mtk_jpeg_adjust_fmt_mplane(ctx, f);
330 goto end;
331 }
332
333 pix_mp->num_planes = fmt->colplanes;
334 pix_mp->pixelformat = fmt->fourcc;
335
336 if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
337 if (jpeg->mode == MTK_JPEG_ENC) {
> 338 pix_mp->height = clamp(pix_mp->height,
339 MTK_JPEG_MIN_HEIGHT,
340 MTK_JPEG_MAX_HEIGHT);
341 pix_mp->width = clamp(pix_mp->width,
342 MTK_JPEG_MIN_WIDTH,
343 MTK_JPEG_MAX_WIDTH);
344 align_w = pix_mp->width;
345 align_h = pix_mp->height;
346 align_w = round_up(align_w, 2);
347 if (pix_mp->num_planes == 1U) {
348 align_w = align_w << 1;
349 mtk_jpeg_bound_align_image(&align_w,
350 MTK_JPEG_MIN_WIDTH,
351 MTK_JPEG_MAX_WIDTH,
352 5, &align_h,
353 MTK_JPEG_MIN_HEIGHT,
354 MTK_JPEG_MAX_HEIGHT,
355 3);
356 pix_mp->plane_fmt[0].bytesperline = align_w;
357 pix_mp->plane_fmt[0].sizeimage =
358 align_w * align_h;
359 } else if (pix_mp->num_planes == 2U) {
360 mtk_jpeg_bound_align_image(&align_w,
361 MTK_JPEG_MIN_WIDTH,
362 MTK_JPEG_MAX_WIDTH,
363 4, &align_h,
364 MTK_JPEG_MIN_HEIGHT,
365 MTK_JPEG_MAX_HEIGHT,
366 4);
367 pix_mp->plane_fmt[0].bytesperline = align_w;
368 pix_mp->plane_fmt[0].sizeimage =
369 align_w * align_h;
370 pix_mp->plane_fmt[1].bytesperline = align_w;
371 pix_mp->plane_fmt[1].sizeimage =
372 (align_w * align_h) / 2;
373 } else {
374 v4l2_err(&ctx->jpeg->v4l2_dev,
375 "Unsupport num planes = %d\n",
376 pix_mp->num_planes);
377 }
378 goto end;
379 } else {
380 struct v4l2_plane_pix_format *pfmt =
381 &pix_mp->plane_fmt[0];
382
383 mtk_jpeg_bound_align_image(&pix_mp->width,
384 MTK_JPEG_MIN_WIDTH,
385 MTK_JPEG_MAX_WIDTH, 0,
386 &pix_mp->height,
387 MTK_JPEG_MIN_HEIGHT,
388 MTK_JPEG_MAX_HEIGHT, 0);
389
390 pfmt->bytesperline = 0;
391 /* Source size must be aligned to 128 */
392 pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
393 if (pfmt->sizeimage == 0)
394 pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
395
396 goto end;
397 }
398 }
399
400 /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
401 if (jpeg->mode == MTK_JPEG_ENC) {
402 mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
403 MTK_JPEG_MAX_WIDTH, 0,
404 &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
405 MTK_JPEG_MAX_HEIGHT, 0);
406
407 if (fmt->fourcc == V4L2_PIX_FMT_JPEG) {
408 pix_mp->plane_fmt[0].bytesperline = 0;
409 pix_mp->plane_fmt[0].sizeimage =
410 mtk_jpeg_align(pix_mp->plane_fmt[0].sizeimage,
411 128);
412 if (pix_mp->plane_fmt[0].sizeimage == 0)
413 pix_mp->plane_fmt[0].sizeimage =
414 MTK_JPEG_DEFAULT_SIZEIMAGE;
415 }
416 } else {
417 pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
418 MTK_JPEG_MAX_HEIGHT);
419 pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
420 MTK_JPEG_MAX_WIDTH);
421 mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
422 MTK_JPEG_MAX_WIDTH, fmt->h_align,
423 &pix_mp->height,
424 MTK_JPEG_MIN_HEIGHT,
425 MTK_JPEG_MAX_HEIGHT, fmt->v_align);
426
427 for (i = 0; i < fmt->colplanes; i++) {
428 struct v4l2_plane_pix_format *pfmt =
429 &pix_mp->plane_fmt[i];
430 u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
431 u32 h = pix_mp->height * fmt->v_sample[i] / 4;
432
433 pfmt->bytesperline = stride;
434 pfmt->sizeimage = stride * h;
435 }
436 }
437
438 for (i = 0; i < fmt->colplanes; i++) {
439 struct v4l2_plane_pix_format *pfmt =
440 &pix_mp->plane_fmt[i];
441 memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
442 }
443 end:
444 v4l2_dbg(2, debug, &jpeg->v4l2_dev, "wxh:%ux%u\n",
445 pix_mp->width, pix_mp->height);
446 for (i = 0; i < pix_mp->num_planes; i++) {
447 v4l2_dbg(2, debug, &jpeg->v4l2_dev,
448 "plane[%d] bpl=%u, size=%u\n",
449 i,
450 pix_mp->plane_fmt[i].bytesperline,
451 pix_mp->plane_fmt[i].sizeimage);
452 }
453 return 0;
454 }
455
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
@ 2019-09-24 10:56 ` kbuild test robot
0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2019-09-24 10:56 UTC (permalink / raw)
To: Xia Jiang
Cc: Xia Jiang, devicetree, srv_heupstream, Rick Chang, linux-kernel,
Tomasz Figa, Mauro Carvalho Chehab, Rob Herring,
Matthias Brugger, kbuild-all, Hans Verkuil, linux-mediatek,
Marek Szyprowski, linux-arm-kernel, linux-media
Hi Xia,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linuxtv-media/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Xia-Jiang/Add-support-for-mt2701-JPEG-ENC-support/20190924-161234
base: git://linuxtv.org/media_tree.git master
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-rc1-7-g2b96cd8-dirty
make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
sparse warnings: (new ones prefixed by >>)
include/linux/sched.h:609:43: sparse: sparse: bad integer constant expression
include/linux/sched.h:609:73: sparse: sparse: invalid named zero-width bitfield `value'
include/linux/sched.h:610:43: sparse: sparse: bad integer constant expression
include/linux/sched.h:610:67: sparse: sparse: invalid named zero-width bitfield `bucket_id'
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
vim +338 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
316
317 static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
318 struct mtk_jpeg_fmt *fmt,
319 struct mtk_jpeg_ctx *ctx, int q_type)
320 {
321 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
322 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
323 int i, align_w, align_h;
324
325 memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
326 pix_mp->field = V4L2_FIELD_NONE;
327
328 if (ctx->state != MTK_JPEG_INIT) {
329 mtk_jpeg_adjust_fmt_mplane(ctx, f);
330 goto end;
331 }
332
333 pix_mp->num_planes = fmt->colplanes;
334 pix_mp->pixelformat = fmt->fourcc;
335
336 if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
337 if (jpeg->mode == MTK_JPEG_ENC) {
> 338 pix_mp->height = clamp(pix_mp->height,
339 MTK_JPEG_MIN_HEIGHT,
340 MTK_JPEG_MAX_HEIGHT);
341 pix_mp->width = clamp(pix_mp->width,
342 MTK_JPEG_MIN_WIDTH,
343 MTK_JPEG_MAX_WIDTH);
344 align_w = pix_mp->width;
345 align_h = pix_mp->height;
346 align_w = round_up(align_w, 2);
347 if (pix_mp->num_planes == 1U) {
348 align_w = align_w << 1;
349 mtk_jpeg_bound_align_image(&align_w,
350 MTK_JPEG_MIN_WIDTH,
351 MTK_JPEG_MAX_WIDTH,
352 5, &align_h,
353 MTK_JPEG_MIN_HEIGHT,
354 MTK_JPEG_MAX_HEIGHT,
355 3);
356 pix_mp->plane_fmt[0].bytesperline = align_w;
357 pix_mp->plane_fmt[0].sizeimage =
358 align_w * align_h;
359 } else if (pix_mp->num_planes == 2U) {
360 mtk_jpeg_bound_align_image(&align_w,
361 MTK_JPEG_MIN_WIDTH,
362 MTK_JPEG_MAX_WIDTH,
363 4, &align_h,
364 MTK_JPEG_MIN_HEIGHT,
365 MTK_JPEG_MAX_HEIGHT,
366 4);
367 pix_mp->plane_fmt[0].bytesperline = align_w;
368 pix_mp->plane_fmt[0].sizeimage =
369 align_w * align_h;
370 pix_mp->plane_fmt[1].bytesperline = align_w;
371 pix_mp->plane_fmt[1].sizeimage =
372 (align_w * align_h) / 2;
373 } else {
374 v4l2_err(&ctx->jpeg->v4l2_dev,
375 "Unsupport num planes = %d\n",
376 pix_mp->num_planes);
377 }
378 goto end;
379 } else {
380 struct v4l2_plane_pix_format *pfmt =
381 &pix_mp->plane_fmt[0];
382
383 mtk_jpeg_bound_align_image(&pix_mp->width,
384 MTK_JPEG_MIN_WIDTH,
385 MTK_JPEG_MAX_WIDTH, 0,
386 &pix_mp->height,
387 MTK_JPEG_MIN_HEIGHT,
388 MTK_JPEG_MAX_HEIGHT, 0);
389
390 pfmt->bytesperline = 0;
391 /* Source size must be aligned to 128 */
392 pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
393 if (pfmt->sizeimage == 0)
394 pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
395
396 goto end;
397 }
398 }
399
400 /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
401 if (jpeg->mode == MTK_JPEG_ENC) {
402 mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
403 MTK_JPEG_MAX_WIDTH, 0,
404 &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
405 MTK_JPEG_MAX_HEIGHT, 0);
406
407 if (fmt->fourcc == V4L2_PIX_FMT_JPEG) {
408 pix_mp->plane_fmt[0].bytesperline = 0;
409 pix_mp->plane_fmt[0].sizeimage =
410 mtk_jpeg_align(pix_mp->plane_fmt[0].sizeimage,
411 128);
412 if (pix_mp->plane_fmt[0].sizeimage == 0)
413 pix_mp->plane_fmt[0].sizeimage =
414 MTK_JPEG_DEFAULT_SIZEIMAGE;
415 }
416 } else {
417 pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
418 MTK_JPEG_MAX_HEIGHT);
419 pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
420 MTK_JPEG_MAX_WIDTH);
421 mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
422 MTK_JPEG_MAX_WIDTH, fmt->h_align,
423 &pix_mp->height,
424 MTK_JPEG_MIN_HEIGHT,
425 MTK_JPEG_MAX_HEIGHT, fmt->v_align);
426
427 for (i = 0; i < fmt->colplanes; i++) {
428 struct v4l2_plane_pix_format *pfmt =
429 &pix_mp->plane_fmt[i];
430 u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
431 u32 h = pix_mp->height * fmt->v_sample[i] / 4;
432
433 pfmt->bytesperline = stride;
434 pfmt->sizeimage = stride * h;
435 }
436 }
437
438 for (i = 0; i < fmt->colplanes; i++) {
439 struct v4l2_plane_pix_format *pfmt =
440 &pix_mp->plane_fmt[i];
441 memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
442 }
443 end:
444 v4l2_dbg(2, debug, &jpeg->v4l2_dev, "wxh:%ux%u\n",
445 pix_mp->width, pix_mp->height);
446 for (i = 0; i < pix_mp->num_planes; i++) {
447 v4l2_dbg(2, debug, &jpeg->v4l2_dev,
448 "plane[%d] bpl=%u, size=%u\n",
449 i,
450 pix_mp->plane_fmt[i].bytesperline,
451 pix_mp->plane_fmt[i].sizeimage);
452 }
453 return 0;
454 }
455
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
@ 2019-09-24 10:56 ` kbuild test robot
0 siblings, 0 replies; 30+ messages in thread
From: kbuild test robot @ 2019-09-24 10:56 UTC (permalink / raw)
Cc: kbuild-all, Hans Verkuil, Mauro Carvalho Chehab, Rob Herring,
Matthias Brugger, Rick Chang, linux-media, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek, Marek Szyprowski,
Tomasz Figa, srv_heupstream, Xia Jiang
Hi Xia,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linuxtv-media/master]
[cannot apply to v5.3 next-20190920]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Xia-Jiang/Add-support-for-mt2701-JPEG-ENC-support/20190924-161234
base: git://linuxtv.org/media_tree.git master
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-rc1-7-g2b96cd8-dirty
make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>
sparse warnings: (new ones prefixed by >>)
include/linux/sched.h:609:43: sparse: sparse: bad integer constant expression
include/linux/sched.h:609:73: sparse: sparse: invalid named zero-width bitfield `value'
include/linux/sched.h:610:43: sparse: sparse: bad integer constant expression
include/linux/sched.h:610:67: sparse: sparse: invalid named zero-width bitfield `bucket_id'
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: incompatible types in comparison expression (different signedness):
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: unsigned int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: int *
>> drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:338:42: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:341:41: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:417:34: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: incompatible types in comparison expression (different signedness):
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: unsigned int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: int *
drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c:419:33: sparse: sparse: cast from unknown type
vim +338 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
316
317 static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
318 struct mtk_jpeg_fmt *fmt,
319 struct mtk_jpeg_ctx *ctx, int q_type)
320 {
321 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
322 struct mtk_jpeg_dev *jpeg = ctx->jpeg;
323 int i, align_w, align_h;
324
325 memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
326 pix_mp->field = V4L2_FIELD_NONE;
327
328 if (ctx->state != MTK_JPEG_INIT) {
329 mtk_jpeg_adjust_fmt_mplane(ctx, f);
330 goto end;
331 }
332
333 pix_mp->num_planes = fmt->colplanes;
334 pix_mp->pixelformat = fmt->fourcc;
335
336 if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
337 if (jpeg->mode == MTK_JPEG_ENC) {
> 338 pix_mp->height = clamp(pix_mp->height,
339 MTK_JPEG_MIN_HEIGHT,
340 MTK_JPEG_MAX_HEIGHT);
341 pix_mp->width = clamp(pix_mp->width,
342 MTK_JPEG_MIN_WIDTH,
343 MTK_JPEG_MAX_WIDTH);
344 align_w = pix_mp->width;
345 align_h = pix_mp->height;
346 align_w = round_up(align_w, 2);
347 if (pix_mp->num_planes == 1U) {
348 align_w = align_w << 1;
349 mtk_jpeg_bound_align_image(&align_w,
350 MTK_JPEG_MIN_WIDTH,
351 MTK_JPEG_MAX_WIDTH,
352 5, &align_h,
353 MTK_JPEG_MIN_HEIGHT,
354 MTK_JPEG_MAX_HEIGHT,
355 3);
356 pix_mp->plane_fmt[0].bytesperline = align_w;
357 pix_mp->plane_fmt[0].sizeimage =
358 align_w * align_h;
359 } else if (pix_mp->num_planes == 2U) {
360 mtk_jpeg_bound_align_image(&align_w,
361 MTK_JPEG_MIN_WIDTH,
362 MTK_JPEG_MAX_WIDTH,
363 4, &align_h,
364 MTK_JPEG_MIN_HEIGHT,
365 MTK_JPEG_MAX_HEIGHT,
366 4);
367 pix_mp->plane_fmt[0].bytesperline = align_w;
368 pix_mp->plane_fmt[0].sizeimage =
369 align_w * align_h;
370 pix_mp->plane_fmt[1].bytesperline = align_w;
371 pix_mp->plane_fmt[1].sizeimage =
372 (align_w * align_h) / 2;
373 } else {
374 v4l2_err(&ctx->jpeg->v4l2_dev,
375 "Unsupport num planes = %d\n",
376 pix_mp->num_planes);
377 }
378 goto end;
379 } else {
380 struct v4l2_plane_pix_format *pfmt =
381 &pix_mp->plane_fmt[0];
382
383 mtk_jpeg_bound_align_image(&pix_mp->width,
384 MTK_JPEG_MIN_WIDTH,
385 MTK_JPEG_MAX_WIDTH, 0,
386 &pix_mp->height,
387 MTK_JPEG_MIN_HEIGHT,
388 MTK_JPEG_MAX_HEIGHT, 0);
389
390 pfmt->bytesperline = 0;
391 /* Source size must be aligned to 128 */
392 pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
393 if (pfmt->sizeimage == 0)
394 pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
395
396 goto end;
397 }
398 }
399
400 /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
401 if (jpeg->mode == MTK_JPEG_ENC) {
402 mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
403 MTK_JPEG_MAX_WIDTH, 0,
404 &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
405 MTK_JPEG_MAX_HEIGHT, 0);
406
407 if (fmt->fourcc == V4L2_PIX_FMT_JPEG) {
408 pix_mp->plane_fmt[0].bytesperline = 0;
409 pix_mp->plane_fmt[0].sizeimage =
410 mtk_jpeg_align(pix_mp->plane_fmt[0].sizeimage,
411 128);
412 if (pix_mp->plane_fmt[0].sizeimage == 0)
413 pix_mp->plane_fmt[0].sizeimage =
414 MTK_JPEG_DEFAULT_SIZEIMAGE;
415 }
416 } else {
417 pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
418 MTK_JPEG_MAX_HEIGHT);
419 pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
420 MTK_JPEG_MAX_WIDTH);
421 mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
422 MTK_JPEG_MAX_WIDTH, fmt->h_align,
423 &pix_mp->height,
424 MTK_JPEG_MIN_HEIGHT,
425 MTK_JPEG_MAX_HEIGHT, fmt->v_align);
426
427 for (i = 0; i < fmt->colplanes; i++) {
428 struct v4l2_plane_pix_format *pfmt =
429 &pix_mp->plane_fmt[i];
430 u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
431 u32 h = pix_mp->height * fmt->v_sample[i] / 4;
432
433 pfmt->bytesperline = stride;
434 pfmt->sizeimage = stride * h;
435 }
436 }
437
438 for (i = 0; i < fmt->colplanes; i++) {
439 struct v4l2_plane_pix_format *pfmt =
440 &pix_mp->plane_fmt[i];
441 memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
442 }
443 end:
444 v4l2_dbg(2, debug, &jpeg->v4l2_dev, "wxh:%ux%u\n",
445 pix_mp->width, pix_mp->height);
446 for (i = 0; i < pix_mp->num_planes; i++) {
447 v4l2_dbg(2, debug, &jpeg->v4l2_dev,
448 "plane[%d] bpl=%u, size=%u\n",
449 i,
450 pix_mp->plane_fmt[i].bytesperline,
451 pix_mp->plane_fmt[i].sizeimage);
452 }
453 return 0;
454 }
455
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
2019-09-24 7:43 ` Xia Jiang
@ 2019-09-26 9:46 ` Hans Verkuil
-1 siblings, 0 replies; 30+ messages in thread
From: Hans Verkuil @ 2019-09-26 9:46 UTC (permalink / raw)
To: Xia Jiang, Mauro Carvalho Chehab, Rob Herring, Matthias Brugger,
Rick Chang
Cc: linux-media, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, Marek Szyprowski, Tomasz Figa, srv_heupstream
On 9/24/19 9:43 AM, Xia Jiang wrote:
> Add mtk jpeg encode v4l2 driver based on jpeg decode, because that jpeg
> decode and encode have great similarities with function operation.
>
> Signed-off-by: Xia Jiang <xia.jiang@mediatek.com>
> ---
> v3: delete Change-Id
> only test once handler->error after the last v4l2_ctrl_new_std()
> seperate changes of v4l2-ctrls.c and v4l2-controls.h to new patch
> v2: fix compliance test fail, check created buffer size in driver
> ---
> drivers/media/platform/mtk-jpeg/Makefile | 5 +-
> .../media/platform/mtk-jpeg/mtk_jpeg_core.c | 735 ++++++++++++++----
> .../media/platform/mtk-jpeg/mtk_jpeg_core.h | 114 ++-
> .../media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h | 7 +-
> .../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c | 175 +++++
> .../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h | 60 ++
> .../platform/mtk-jpeg/mtk_jpeg_enc_reg.h | 49 ++
> 7 files changed, 975 insertions(+), 170 deletions(-)
> create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c
> create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h
> create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h
>
> diff --git a/drivers/media/platform/mtk-jpeg/Makefile b/drivers/media/platform/mtk-jpeg/Makefile
> index 48516dcf96e6..76c33aad0f3f 100644
> --- a/drivers/media/platform/mtk-jpeg/Makefile
> +++ b/drivers/media/platform/mtk-jpeg/Makefile
> @@ -1,3 +1,6 @@
> # SPDX-License-Identifier: GPL-2.0-only
> -mtk_jpeg-objs := mtk_jpeg_core.o mtk_jpeg_dec_hw.o mtk_jpeg_dec_parse.o
> +mtk_jpeg-objs := mtk_jpeg_core.o \
> + mtk_jpeg_dec_hw.o \
> + mtk_jpeg_dec_parse.o \
> + mtk_jpeg_enc_hw.o
> obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o
> diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> index 5f0990fce8ef..aa18b01802ed 100644
> --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> @@ -3,6 +3,7 @@
> * Copyright (c) 2016 MediaTek Inc.
> * Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
> * Rick Chang <rick.chang@mediatek.com>
> + * Xia Jiang <xia.jiang@mediatek.com>
> */
>
> #include <linux/clk.h>
> @@ -23,6 +24,7 @@
> #include <media/videobuf2-dma-contig.h>
> #include <soc/mediatek/smi.h>
>
> +#include "mtk_jpeg_enc_hw.h"
> #include "mtk_jpeg_dec_hw.h"
> #include "mtk_jpeg_core.h"
> #include "mtk_jpeg_dec_parse.h"
> @@ -31,7 +33,8 @@ static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
> {
> .fourcc = V4L2_PIX_FMT_JPEG,
> .colplanes = 1,
> - .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT,
> + .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT |
> + MTK_JPEG_FMT_FLAG_ENC_CAPTURE,
> },
> {
> .fourcc = V4L2_PIX_FMT_YUV420M,
> @@ -51,6 +54,42 @@ static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
> .v_align = 3,
> .flags = MTK_JPEG_FMT_FLAG_DEC_CAPTURE,
> },
> + {
> + .fourcc = V4L2_PIX_FMT_NV12M,
> + .h_sample = {4, 2, 2},
> + .v_sample = {4, 2, 2},
> + .colplanes = 2,
> + .h_align = 4,
> + .v_align = 4,
> + .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_NV21M,
> + .h_sample = {4, 2, 2},
> + .v_sample = {4, 2, 2},
> + .colplanes = 2,
> + .h_align = 4,
> + .v_align = 4,
> + .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_YUYV,
> + .h_sample = {4, 2, 2},
> + .v_sample = {4, 4, 4},
> + .colplanes = 1,
> + .h_align = 4,
> + .v_align = 3,
> + .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_YVYU,
> + .h_sample = {4, 2, 2},
> + .v_sample = {4, 4, 4},
> + .colplanes = 1,
> + .h_align = 4,
> + .v_align = 3,
> + .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
> + },
> };
>
> #define MTK_JPEG_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_formats)
> @@ -65,11 +104,19 @@ struct mtk_jpeg_src_buf {
> struct list_head list;
> int flags;
> struct mtk_jpeg_dec_param dec_param;
> + struct mtk_jpeg_enc_param enc_param;
> };
>
> +#define MTK_MAX_CTRLS_HINT 20
> +
> static int debug;
> module_param(debug, int, 0644);
>
> +static inline struct mtk_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *ctrl)
> +{
> + return container_of(ctrl->handler, struct mtk_jpeg_ctx, ctrl_hdl);
> +}
> +
> static inline struct mtk_jpeg_ctx *mtk_jpeg_fh_to_ctx(struct v4l2_fh *fh)
> {
> return container_of(fh, struct mtk_jpeg_ctx, fh);
> @@ -86,10 +133,70 @@ static int mtk_jpeg_querycap(struct file *file, void *priv,
> {
> struct mtk_jpeg_dev *jpeg = video_drvdata(file);
>
> - strscpy(cap->driver, MTK_JPEG_NAME " decoder", sizeof(cap->driver));
> - strscpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
> - snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
> - dev_name(jpeg->dev));
> + strscpy(cap->driver, MTK_JPEG_NAME, sizeof(cap->driver));
> + if (jpeg->mode == MTK_JPEG_ENC)
> + strscpy(cap->card, MTK_JPEG_NAME " encoder", sizeof(cap->card));
> + else
> + strscpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
> + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
> + dev_name(jpeg->dev));
> +
> + return 0;
> +}
> +
> +static int vidioc_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
> +{
> + struct mtk_jpeg_ctx *ctx = ctrl_to_ctx(ctrl);
> + struct jpeg_enc_param *p = &ctx->jpeg_param;
> + struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> + int ret = 0;
> +
> + switch (ctrl->id) {
> + case V4L2_CID_JPEG_RESTART_INTERVAL:
> + p->restart_interval = ctrl->val;
> + break;
> + case V4L2_CID_JPEG_COMPRESSION_QUALITY:
> + p->enc_quality = ctrl->val;
> + break;
> + case V4L2_CID_JPEG_ENABLE_EXIF:
> + p->enable_exif = ctrl->val;
> + break;
> + }
> +
> + v4l2_dbg(2, debug, &jpeg->v4l2_dev, "%s val = %d",
> + v4l2_ctrl_get_name(ctrl->id), ctrl->val);
> +
> + return ret;
> +}
> +
> +static const struct v4l2_ctrl_ops mtk_jpeg_ctrl_ops = {
> + .s_ctrl = vidioc_jpeg_s_ctrl,
> +};
> +
> +int mtk_jpeg_ctrls_setup(struct mtk_jpeg_ctx *ctx)
> +{
> + const struct v4l2_ctrl_ops *ops = &mtk_jpeg_ctrl_ops;
> + struct v4l2_ctrl_handler *handler = &ctx->ctrl_hdl;
> + struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> +
> + v4l2_ctrl_handler_init(handler, MTK_MAX_CTRLS_HINT);
> +
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + v4l2_ctrl_new_std(handler, ops, V4L2_CID_JPEG_RESTART_INTERVAL,
> + 0, 100, 1, 0);
> + v4l2_ctrl_new_std(handler, ops,
> + V4L2_CID_JPEG_COMPRESSION_QUALITY, 48, 100, 1,
> + 90);
> + v4l2_ctrl_new_std(handler, ops, V4L2_CID_JPEG_ENABLE_EXIF, 0,
> + 1, 1, 0);
> +
> + if (handler->error) {
> + v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
> + return handler->error;
> + }
> + }
> +
> + v4l2_ctrl_handler_setup(&ctx->ctrl_hdl);
>
> return 0;
> }
> @@ -118,23 +225,29 @@ static int mtk_jpeg_enum_fmt(struct mtk_jpeg_fmt *mtk_jpeg_formats, int n,
> static int mtk_jpeg_enum_fmt_vid_cap(struct file *file, void *priv,
> struct v4l2_fmtdesc *f)
> {
> + struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
> +
> return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
> + ctx->jpeg->mode == MTK_JPEG_ENC ?
> + MTK_JPEG_FMT_FLAG_ENC_CAPTURE :
> MTK_JPEG_FMT_FLAG_DEC_CAPTURE);
> }
>
> static int mtk_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
> struct v4l2_fmtdesc *f)
> {
> + struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
> +
> return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
> + ctx->jpeg->mode == MTK_JPEG_ENC ?
> + MTK_JPEG_FMT_FLAG_ENC_OUTPUT :
> MTK_JPEG_FMT_FLAG_DEC_OUTPUT);
> }
>
> -static struct mtk_jpeg_q_data *mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx,
> - enum v4l2_buf_type type)
> +static struct mtk_jpeg_q_data *
> +mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx, enum v4l2_buf_type type)
> {
> - if (V4L2_TYPE_IS_OUTPUT(type))
> - return &ctx->out_q;
> - return &ctx->cap_q;
> + return V4L2_TYPE_IS_OUTPUT(type) ? &ctx->out_q : &ctx->cap_q;
> }
>
> static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
> @@ -143,9 +256,14 @@ static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
> {
> unsigned int k, fmt_flag;
>
> - fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
> - MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
> - MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
> + if (ctx->jpeg->mode == MTK_JPEG_ENC)
> + fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
> + MTK_JPEG_FMT_FLAG_ENC_OUTPUT :
> + MTK_JPEG_FMT_FLAG_ENC_CAPTURE;
> + else
> + fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
> + MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
> + MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
>
> for (k = 0; k < MTK_JPEG_NUM_FORMATS; k++) {
> struct mtk_jpeg_fmt *fmt = &mtk_jpeg_formats[k];
> @@ -202,7 +320,7 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
> {
> struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
> struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> - int i;
> + int i, align_w, align_h;
>
> memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
> pix_mp->field = V4L2_FIELD_NONE;
> @@ -216,36 +334,111 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
> pix_mp->pixelformat = fmt->fourcc;
>
> if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
> - struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0];
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + pix_mp->height = clamp(pix_mp->height,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT);
> + pix_mp->width = clamp(pix_mp->width,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH);
> + align_w = pix_mp->width;
> + align_h = pix_mp->height;
> + align_w = round_up(align_w, 2);
> + if (pix_mp->num_planes == 1U) {
> + align_w = align_w << 1;
> + mtk_jpeg_bound_align_image(&align_w,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH,
> + 5, &align_h,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT,
> + 3);
> + pix_mp->plane_fmt[0].bytesperline = align_w;
> + pix_mp->plane_fmt[0].sizeimage =
> + align_w * align_h;
> + } else if (pix_mp->num_planes == 2U) {
> + mtk_jpeg_bound_align_image(&align_w,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH,
> + 4, &align_h,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT,
> + 4);
> + pix_mp->plane_fmt[0].bytesperline = align_w;
> + pix_mp->plane_fmt[0].sizeimage =
> + align_w * align_h;
> + pix_mp->plane_fmt[1].bytesperline = align_w;
> + pix_mp->plane_fmt[1].sizeimage =
> + (align_w * align_h) / 2;
> + } else {
> + v4l2_err(&ctx->jpeg->v4l2_dev,
> + "Unsupport num planes = %d\n",
> + pix_mp->num_planes);
> + }
> + goto end;
> + } else {
> + struct v4l2_plane_pix_format *pfmt =
> + &pix_mp->plane_fmt[0];
> +
> + mtk_jpeg_bound_align_image(&pix_mp->width,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH, 0,
> + &pix_mp->height,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT, 0);
> +
> + pfmt->bytesperline = 0;
> + /* Source size must be aligned to 128 */
> + pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
> + if (pfmt->sizeimage == 0)
> + pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
> +
> + goto end;
> + }
> + }
The differences between capture and output are too large IMHO. I would
recommend splitting this into different functions, one for the encoder,
one for the decoder.
>
> + /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
> + if (jpeg->mode == MTK_JPEG_ENC) {
> mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
> MTK_JPEG_MAX_WIDTH, 0,
> &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
> MTK_JPEG_MAX_HEIGHT, 0);
>
> - memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
> - pfmt->bytesperline = 0;
> - /* Source size must be aligned to 128 */
> - pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
> - if (pfmt->sizeimage == 0)
> - pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
> - goto end;
> + if (fmt->fourcc == V4L2_PIX_FMT_JPEG) {
> + pix_mp->plane_fmt[0].bytesperline = 0;
> + pix_mp->plane_fmt[0].sizeimage =
> + mtk_jpeg_align(pix_mp->plane_fmt[0].sizeimage,
> + 128);
> + if (pix_mp->plane_fmt[0].sizeimage == 0)
> + pix_mp->plane_fmt[0].sizeimage =
> + MTK_JPEG_DEFAULT_SIZEIMAGE;
> + }
> + } else {
> + pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT);
> + pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH);
> + mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH, fmt->h_align,
> + &pix_mp->height,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT, fmt->v_align);
> +
> + for (i = 0; i < fmt->colplanes; i++) {
> + struct v4l2_plane_pix_format *pfmt =
> + &pix_mp->plane_fmt[i];
> + u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
> + u32 h = pix_mp->height * fmt->v_sample[i] / 4;
> +
> + pfmt->bytesperline = stride;
> + pfmt->sizeimage = stride * h;
> + }
> }
>
> - /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
> - mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
> - MTK_JPEG_MAX_WIDTH, fmt->h_align,
> - &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
> - MTK_JPEG_MAX_HEIGHT, fmt->v_align);
> -
> for (i = 0; i < fmt->colplanes; i++) {
> - struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[i];
> - u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
> - u32 h = pix_mp->height * fmt->v_sample[i] / 4;
> -
> + struct v4l2_plane_pix_format *pfmt =
> + &pix_mp->plane_fmt[i];
> memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
> - pfmt->bytesperline = stride;
> - pfmt->sizeimage = stride * h;
> }
> end:
> v4l2_dbg(2, debug, &jpeg->v4l2_dev, "wxh:%ux%u\n",
> @@ -446,9 +639,9 @@ static int mtk_jpeg_subscribe_event(struct v4l2_fh *fh,
> switch (sub->type) {
> case V4L2_EVENT_SOURCE_CHANGE:
> return v4l2_src_change_event_subscribe(fh, sub);
> - default:
> - return -EINVAL;
> }
> +
> + return v4l2_ctrl_subscribe_event(fh, sub);
> }
This appears to be a bug fix. Please put this in a separate patch.
>
> static int mtk_jpeg_g_selection(struct file *file, void *priv,
> @@ -571,6 +764,13 @@ static int mtk_jpeg_queue_setup(struct vb2_queue *q,
> if (!q_data)
> return -EINVAL;
>
> + if (*num_planes) {
> + for (i = 0; i < *num_planes; i++)
> + if (sizes[i] < q_data->sizeimage[i])
> + return -EINVAL;
> + return 0;
> + }
> +
> *num_planes = q_data->fmt->colplanes;
> for (i = 0; i < q_data->fmt->colplanes; i++) {
> sizes[i] = q_data->sizeimage[i];
Also appears to be a bug fix.
> @@ -651,10 +851,92 @@ static void mtk_jpeg_set_queue_data(struct mtk_jpeg_ctx *ctx,
> param->dec_w, param->dec_h);
> }
>
> +static void mtk_jpeg_set_param(struct mtk_jpeg_ctx *ctx,
> + struct mtk_jpeg_enc_param *param)
> +{
> + struct mtk_jpeg_q_data *q_data_src = &ctx->out_q;
> + struct jpeg_enc_param *jpeg_params = &ctx->jpeg_param;
> + struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> + u32 width_even;
> + u32 is_420;
> + u32 padding_width;
> + u32 padding_height;
> +
> + switch (q_data_src->fmt->fourcc) {
> + case V4L2_PIX_FMT_YUYV:
> + param->enc_format = JPEG_YUV_FORMAT_YUYV;
> + break;
> + case V4L2_PIX_FMT_YVYU:
> + param->enc_format = JPEG_YUV_FORMAT_YVYU;
> + break;
> + case V4L2_PIX_FMT_NV12M:
> + param->enc_format = JPEG_YUV_FORMAT_NV12;
> + break;
> + case V4L2_PIX_FMT_NV21M:
> + param->enc_format = JPEG_YUV_FORMAT_NV12;
> + break;
> + default:
> + v4l2_err(&jpeg->v4l2_dev, "Unsupport fourcc =%d\n",
> + q_data_src->fmt->fourcc);
> + break;
> + }
> + param->enc_w = q_data_src->w;
> + param->enc_h = q_data_src->h;
> +
> + if (jpeg_params->enc_quality >= 97)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q97;
> + else if (jpeg_params->enc_quality >= 95)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q95;
> + else if (jpeg_params->enc_quality >= 92)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q92;
> + else if (jpeg_params->enc_quality >= 90)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q90;
> + else if (jpeg_params->enc_quality >= 87)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q87;
> + else if (jpeg_params->enc_quality >= 84)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q84;
> + else if (jpeg_params->enc_quality >= 80)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q80;
> + else if (jpeg_params->enc_quality >= 74)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q74;
> + else if (jpeg_params->enc_quality >= 64)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q64;
> + else if (jpeg_params->enc_quality >= 60)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q60;
> + else
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q48;
> +
> + param->enable_exif = jpeg_params->enable_exif;
> + param->restart_interval = jpeg_params->restart_interval;
> +
> + width_even = ((param->enc_w + 1) >> 1) << 1;
> + is_420 = (param->enc_format == JPEG_YUV_FORMAT_NV12 ||
> + param->enc_format == JPEG_YUV_FORMAT_NV12) ? 1 : 0;
> + padding_width = mtk_jpeg_align(param->enc_w, 16);
> + padding_height = mtk_jpeg_align(param->enc_h, is_420 ? 16 : 8);
> + if (!is_420)
> + width_even = width_even << 1;
> +
> + param->img_stride = mtk_jpeg_align(width_even, (is_420 ? 16 : 32));
> + param->mem_stride = mtk_jpeg_align(width_even, (is_420 ? 16 : 32));
> + param->total_encdu =
> + ((padding_width >> 4) * (padding_height >> (is_420 ? 4 : 3)) *
> + (is_420 ? 6 : 4)) - 1;
> +
> + v4l2_dbg(0, 2, &jpeg->v4l2_dev, "fmt %d, w,h %d,%d, enable_exif %d,",
> + "enc_quality %d, restart_interval %d,img_stride %d,",
> + "mem_stride %d,totalEncDu %d\n",
> + param->enc_format, param->enc_w, param->enc_h,
> + param->enable_exif, param->enc_quality,
> + param->restart_interval, param->img_stride,
> + param->mem_stride, param->total_encdu);
> +}
> +
> static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
> {
> struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
> struct mtk_jpeg_dec_param *param;
> + struct mtk_jpeg_enc_param *enc_param;
> struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> struct mtk_jpeg_src_buf *jpeg_src_buf;
> bool header_valid;
> @@ -666,29 +948,45 @@ static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
> goto end;
>
> jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb);
> - param = &jpeg_src_buf->dec_param;
> - memset(param, 0, sizeof(*param));
> -
> - if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
> - v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
> - goto end;
> - }
> - header_valid = mtk_jpeg_parse(param, (u8 *)vb2_plane_vaddr(vb, 0),
> - vb2_get_plane_payload(vb, 0));
> - if (!header_valid) {
> - v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
> - vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
> - return;
> - }
> -
> - if (ctx->state == MTK_JPEG_INIT) {
> - struct vb2_queue *dst_vq = v4l2_m2m_get_vq(
> - ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + enc_param = &jpeg_src_buf->enc_param;
> + memset(enc_param, 0, sizeof(*enc_param));
> + mtk_jpeg_set_param(ctx, enc_param);
> + if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
> + v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos");
> + goto end;
> + }
> + if (ctx->state == MTK_JPEG_INIT)
> + ctx->state = MTK_JPEG_RUNNING;
> + } else {
> + param = &jpeg_src_buf->dec_param;
> + memset(param, 0, sizeof(*param));
> +
> + if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
> + v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
> + goto end;
> + }
> + header_valid = mtk_jpeg_parse(param,
> + (u8 *)vb2_plane_vaddr(vb, 0),
> + vb2_get_plane_payload(vb, 0));
> + if (!header_valid) {
> + v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
> + vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
> + return;
> + }
>
> - mtk_jpeg_queue_src_chg_event(ctx);
> - mtk_jpeg_set_queue_data(ctx, param);
> - ctx->state = vb2_is_streaming(dst_vq) ?
> - MTK_JPEG_SOURCE_CHANGE : MTK_JPEG_RUNNING;
> + if (ctx->state == MTK_JPEG_INIT) {
> + struct vb2_queue *dst_vq;
> +
> + dst_vq = v4l2_m2m_get_vq
> + (ctx->fh.m2m_ctx,
> + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
> + mtk_jpeg_queue_src_chg_event(ctx);
> + mtk_jpeg_set_queue_data(ctx, param);
> + ctx->state = vb2_is_streaming(dst_vq) ?
> + MTK_JPEG_SOURCE_CHANGE :
> + MTK_JPEG_RUNNING;
> + }
> }
> end:
> v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, to_vb2_v4l2_buffer(vb));
> @@ -731,16 +1029,16 @@ static void mtk_jpeg_stop_streaming(struct vb2_queue *q)
> * subsampling. Update capture queue when the stream is off.
> */
> if (ctx->state == MTK_JPEG_SOURCE_CHANGE &&
> - !V4L2_TYPE_IS_OUTPUT(q->type)) {
> + !V4L2_TYPE_IS_OUTPUT(q->type) &&
> + ctx->jpeg->mode == MTK_JPEG_DEC) {
> struct mtk_jpeg_src_buf *src_buf;
>
> vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> src_buf = mtk_jpeg_vb2_to_srcbuf(&vb->vb2_buf);
> mtk_jpeg_set_queue_data(ctx, &src_buf->dec_param);
> ctx->state = MTK_JPEG_RUNNING;
> - } else if (V4L2_TYPE_IS_OUTPUT(q->type)) {
> + } else if (V4L2_TYPE_IS_OUTPUT(q->type))
> ctx->state = MTK_JPEG_INIT;
> - }
>
> while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
> v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
> @@ -795,6 +1093,28 @@ static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,
> return 0;
> }
>
> +static void mtk_jpeg_set_enc_dst(struct mtk_jpeg_ctx *ctx,
> + struct vb2_buffer *dst_buf,
> + struct mtk_jpeg_enc_bs *bs)
> +{
> + bs->dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0) &
> + (~JPEG_ENC_DST_ADDR_OFFSET_MASK);
> + bs->dma_addr_offset = 0;
> + bs->dma_addr_offsetmask = bs->dma_addr & JPEG_ENC_DST_ADDR_OFFSET_MASK;
> + bs->size = mtk_jpeg_align(vb2_plane_size(dst_buf, 0), 128);
> +}
> +
> +static void mtk_jpeg_set_enc_src(struct mtk_jpeg_ctx *ctx,
> + struct vb2_buffer *src_buf,
> + struct mtk_jpeg_enc_fb *fb)
> +{
> + int i;
> +
> + for (i = 0; i < src_buf->num_planes; i++)
> + fb->fb_addr[i].dma_addr =
> + vb2_dma_contig_plane_dma_addr(src_buf, i);
> +}
> +
> static void mtk_jpeg_device_run(void *priv)
> {
> struct mtk_jpeg_ctx *ctx = priv;
> @@ -805,6 +1125,8 @@ static void mtk_jpeg_device_run(void *priv)
> struct mtk_jpeg_src_buf *jpeg_src_buf;
> struct mtk_jpeg_bs bs;
> struct mtk_jpeg_fb fb;
> + struct mtk_jpeg_enc_bs enc_bs;
> + struct mtk_jpeg_enc_fb enc_fb;
> int i;
>
> src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -815,30 +1137,45 @@ static void mtk_jpeg_device_run(void *priv)
> for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
> vb2_set_plane_payload(&dst_buf->vb2_buf, i, 0);
> buf_state = VB2_BUF_STATE_DONE;
> - goto dec_end;
> + goto device_run_end;
> }
>
> - if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) {
> - mtk_jpeg_queue_src_chg_event(ctx);
> - ctx->state = MTK_JPEG_SOURCE_CHANGE;
> - v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> - return;
> - }
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + mtk_jpeg_set_enc_dst(ctx, &dst_buf->vb2_buf, &enc_bs);
> + mtk_jpeg_set_enc_src(ctx, &src_buf->vb2_buf, &enc_fb);
> +
> + spin_lock_irqsave(&jpeg->hw_lock, flags);
> + mtk_jpeg_enc_reset(jpeg->reg_base);
> + mtk_jpeg_enc_set_config(jpeg->reg_base,
> + &jpeg_src_buf->enc_param, &enc_bs,
> + &enc_fb);
> +
> + mtk_jpeg_enc_start(jpeg->reg_base);
> + } else {
> + if (mtk_jpeg_check_resolution_change
> + (ctx, &jpeg_src_buf->dec_param)) {
> + mtk_jpeg_queue_src_chg_event(ctx);
> + ctx->state = MTK_JPEG_SOURCE_CHANGE;
> + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> + return;
> + }
>
> - mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
> - if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, &dst_buf->vb2_buf, &fb))
> - goto dec_end;
> + mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
> + if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param,
> + &dst_buf->vb2_buf, &fb))
> + goto device_run_end;
>
> - spin_lock_irqsave(&jpeg->hw_lock, flags);
> - mtk_jpeg_dec_reset(jpeg->dec_reg_base);
> - mtk_jpeg_dec_set_config(jpeg->dec_reg_base,
> - &jpeg_src_buf->dec_param, &bs, &fb);
> + spin_lock_irqsave(&jpeg->hw_lock, flags);
> + mtk_jpeg_dec_reset(jpeg->reg_base);
> + mtk_jpeg_dec_set_config(jpeg->reg_base,
> + &jpeg_src_buf->dec_param, &bs, &fb);
>
> - mtk_jpeg_dec_start(jpeg->dec_reg_base);
> + mtk_jpeg_dec_start(jpeg->reg_base);
> + }
> spin_unlock_irqrestore(&jpeg->hw_lock, flags);
> return;
>
> -dec_end:
> +device_run_end:
> v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
> v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
> v4l2_m2m_buf_done(src_buf, buf_state);
> @@ -898,30 +1235,30 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
> ret = mtk_smi_larb_get(jpeg->larb);
> if (ret)
> dev_err(jpeg->dev, "mtk_smi_larb_get larbvdec fail %d\n", ret);
> - clk_prepare_enable(jpeg->clk_jdec_smi);
> - clk_prepare_enable(jpeg->clk_jdec);
> + if (jpeg->mode == MTK_JPEG_DEC)
> + clk_prepare_enable(jpeg->clk_jpeg_smi);
> + clk_prepare_enable(jpeg->clk_jpeg);
> }
>
> static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg)
> {
> - clk_disable_unprepare(jpeg->clk_jdec);
> - clk_disable_unprepare(jpeg->clk_jdec_smi);
> + clk_disable_unprepare(jpeg->clk_jpeg);
> + if (jpeg->mode == MTK_JPEG_DEC)
> + clk_disable_unprepare(jpeg->clk_jpeg_smi);
> mtk_smi_larb_put(jpeg->larb);
> }
>
> -static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
> +static irqreturn_t mtk_jpeg_irq(int irq, void *priv)
> {
> struct mtk_jpeg_dev *jpeg = priv;
> struct mtk_jpeg_ctx *ctx;
> struct vb2_v4l2_buffer *src_buf, *dst_buf;
> struct mtk_jpeg_src_buf *jpeg_src_buf;
> enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
> - u32 dec_irq_ret;
> - u32 dec_ret;
> + u32 irq_ret;
> + u32 ret, result_size;
> int i;
>
> - dec_ret = mtk_jpeg_dec_get_int_status(jpeg->dec_reg_base);
> - dec_irq_ret = mtk_jpeg_dec_enum_result(dec_ret);
> ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev);
> if (!ctx) {
> v4l2_err(&jpeg->v4l2_dev, "Context is NULL\n");
> @@ -932,21 +1269,42 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
> dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
> jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
>
> - if (dec_irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
> - mtk_jpeg_dec_reset(jpeg->dec_reg_base);
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + ret = mtk_jpeg_enc_get_int_status(jpeg->reg_base);
> + irq_ret = mtk_jpeg_enc_enum_result(jpeg->reg_base, ret,
> + &result_size);
>
> - if (dec_irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
> - dev_err(jpeg->dev, "decode failed\n");
> - goto dec_end;
> - }
> + if (irq_ret >= MTK_JPEG_ENC_RESULT_STALL)
> + mtk_jpeg_enc_reset(jpeg->reg_base);
> +
> + if (irq_ret != MTK_JPEG_ENC_RESULT_DONE) {
> + dev_err(jpeg->dev, "encode failed\n");
> + goto irq_end;
> + }
>
> - for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
> - vb2_set_plane_payload(&dst_buf->vb2_buf, i,
> - jpeg_src_buf->dec_param.comp_size[i]);
> + vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
> + result_size);
> + } else {
> + ret = mtk_jpeg_dec_get_int_status(jpeg->reg_base);
> + irq_ret = mtk_jpeg_dec_enum_result(ret);
> +
> + if (irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
> + mtk_jpeg_dec_reset(jpeg->reg_base);
> +
> + if (irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
> + dev_err(jpeg->dev, "decode failed\n");
> + goto irq_end;
> + }
> +
> + for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
> + vb2_set_plane_payload
> + (&dst_buf->vb2_buf, i,
> + jpeg_src_buf->dec_param.comp_size[i]);
> + }
>
> buf_state = VB2_BUF_STATE_DONE;
>
> -dec_end:
> +irq_end:
> v4l2_m2m_buf_done(src_buf, buf_state);
> v4l2_m2m_buf_done(dst_buf, buf_state);
> v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> @@ -956,32 +1314,72 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
> static void mtk_jpeg_set_default_params(struct mtk_jpeg_ctx *ctx)
> {
> struct mtk_jpeg_q_data *q = &ctx->out_q;
> - int i;
> + int i, align_w, align_h;
> +
> + ctx->fh.ctrl_handler = &ctx->ctrl_hdl;
>
> ctx->colorspace = V4L2_COLORSPACE_JPEG,
> ctx->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
> ctx->quantization = V4L2_QUANTIZATION_DEFAULT;
> ctx->xfer_func = V4L2_XFER_FUNC_DEFAULT;
>
> - q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
> + if (ctx->jpeg->mode == MTK_JPEG_ENC) {
> + q->w = MTK_JPEG_MIN_WIDTH;
> + q->h = MTK_JPEG_MIN_HEIGHT;
> +
> + q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUYV,
> MTK_JPEG_FMT_TYPE_OUTPUT);
> - q->w = MTK_JPEG_MIN_WIDTH;
> - q->h = MTK_JPEG_MIN_HEIGHT;
> - q->bytesperline[0] = 0;
> - q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
> +
> + align_w = q->w;
> + align_h = q->h;
> + align_w = round_up(align_w, 2);
> + align_w = align_w << 1;
> + v4l_bound_align_image(&align_w,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH, 5,
> + &align_h,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT, 3, 0);
> +
> + if (align_w < MTK_JPEG_MIN_WIDTH &&
> + (align_w + 32) <= MTK_JPEG_MAX_WIDTH)
> + align_w += 32;
> + if (align_h < MTK_JPEG_MIN_HEIGHT &&
> + (align_h + 8) <= MTK_JPEG_MAX_HEIGHT)
> + align_h += 8;
> +
> + q->sizeimage[0] = align_w * align_h;
> + q->bytesperline[0] = align_w;
> + } else {
> + q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
> + MTK_JPEG_FMT_TYPE_OUTPUT);
> + q->w = MTK_JPEG_MIN_WIDTH;
> + q->h = MTK_JPEG_MIN_HEIGHT;
> + q->bytesperline[0] = 0;
> + q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
> + }
>
> q = &ctx->cap_q;
> - q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
> + if (ctx->jpeg->mode == MTK_JPEG_ENC) {
> + q->w = MTK_JPEG_MIN_WIDTH;
> + q->h = MTK_JPEG_MIN_HEIGHT;
> + q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
> + MTK_JPEG_FMT_TYPE_CAPTURE);
> + q->bytesperline[0] = 0;
> + q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
> + } else {
> + q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
> MTK_JPEG_FMT_TYPE_CAPTURE);
> - q->w = MTK_JPEG_MIN_WIDTH;
> - q->h = MTK_JPEG_MIN_HEIGHT;
> + q->w = MTK_JPEG_MIN_WIDTH;
> + q->h = MTK_JPEG_MIN_HEIGHT;
>
> - for (i = 0; i < q->fmt->colplanes; i++) {
> - u32 stride = q->w * q->fmt->h_sample[i] / 4;
> - u32 h = q->h * q->fmt->v_sample[i] / 4;
> + for (i = 0; i < q->fmt->colplanes; i++) {
> + u32 stride = q->w * q->fmt->h_sample[i] / 4;
> + u32 h = q->h * q->fmt->v_sample[i] / 4;
>
> - q->bytesperline[i] = stride;
> - q->sizeimage[i] = stride * h;
> + q->bytesperline[i] = stride;
> + q->sizeimage[i] = stride * h;
> + }
> }
> }
This is another function were there appears to be little overlap between
encoder and decoder. A candidate to split up?
>
> @@ -1013,6 +1411,13 @@ static int mtk_jpeg_open(struct file *file)
> goto error;
> }
>
> + ret = mtk_jpeg_ctrls_setup(ctx);
> + if (ret) {
> + v4l2_err(&jpeg->v4l2_dev, "Failed to setup controls() (%d)\n",
> + ret);
> + goto error;
> + }
> +
> mtk_jpeg_set_default_params(ctx);
> mutex_unlock(&jpeg->lock);
> return 0;
> @@ -1033,6 +1438,7 @@ static int mtk_jpeg_release(struct file *file)
>
> mutex_lock(&jpeg->lock);
> v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
> + v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
> v4l2_fh_del(&ctx->fh);
> v4l2_fh_exit(&ctx->fh);
> kfree(ctx);
> @@ -1057,6 +1463,7 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
> node = of_parse_phandle(jpeg->dev->of_node, "mediatek,larb", 0);
> if (!node)
> return -EINVAL;
> +
> pdev = of_find_device_by_node(node);
> if (WARN_ON(!pdev)) {
> of_node_put(node);
> @@ -1066,19 +1473,24 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
>
> jpeg->larb = &pdev->dev;
>
> - jpeg->clk_jdec = devm_clk_get(jpeg->dev, "jpgdec");
> - if (IS_ERR(jpeg->clk_jdec))
> - return PTR_ERR(jpeg->clk_jdec);
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + jpeg->clk_jpeg = devm_clk_get(jpeg->dev, "jpgenc");
> + return PTR_ERR_OR_ZERO(jpeg->clk_jpeg);
> + }
> +
> + jpeg->clk_jpeg = devm_clk_get(jpeg->dev, "jpgdec");
> + if (IS_ERR(jpeg->clk_jpeg))
> + return PTR_ERR(jpeg->clk_jpeg);
>
> - jpeg->clk_jdec_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
> - return PTR_ERR_OR_ZERO(jpeg->clk_jdec_smi);
> + jpeg->clk_jpeg_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
> + return PTR_ERR_OR_ZERO(jpeg->clk_jpeg_smi);
> }
>
> static int mtk_jpeg_probe(struct platform_device *pdev)
> {
> struct mtk_jpeg_dev *jpeg;
> struct resource *res;
> - int dec_irq;
> + int jpeg_irq;
> int ret;
>
> jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL);
> @@ -1088,28 +1500,26 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
> mutex_init(&jpeg->lock);
> spin_lock_init(&jpeg->hw_lock);
> jpeg->dev = &pdev->dev;
> + jpeg->mode = (enum mtk_jpeg_mode)of_device_get_match_data(jpeg->dev);
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - jpeg->dec_reg_base = devm_ioremap_resource(&pdev->dev, res);
> - if (IS_ERR(jpeg->dec_reg_base)) {
> - ret = PTR_ERR(jpeg->dec_reg_base);
> + jpeg->reg_base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(jpeg->reg_base)) {
> + ret = PTR_ERR(jpeg->reg_base);
> return ret;
> }
>
> - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> - dec_irq = platform_get_irq(pdev, 0);
> - if (!res || dec_irq < 0) {
> - dev_err(&pdev->dev, "Failed to get dec_irq %d.\n", dec_irq);
> - ret = -EINVAL;
> - return ret;
> + jpeg_irq = platform_get_irq(pdev, 0);
> + if (jpeg_irq < 0) {
> + dev_err(&pdev->dev, "Failed to get jpeg_irq %d.\n", jpeg_irq);
> + return jpeg_irq;
> }
>
> - ret = devm_request_irq(&pdev->dev, dec_irq, mtk_jpeg_dec_irq, 0,
> + ret = devm_request_irq(&pdev->dev, jpeg_irq, mtk_jpeg_irq, 0,
> pdev->name, jpeg);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to request dec_irq %d (%d)\n",
> - dec_irq, ret);
> - ret = -EINVAL;
> + dev_err(&pdev->dev, "Failed to request jpeg_irq %d (%d)\n",
> + jpeg_irq, ret);
> goto err_req_irq;
> }
>
> @@ -1133,33 +1543,35 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
> goto err_m2m_init;
> }
>
> - jpeg->dec_vdev = video_device_alloc();
> - if (!jpeg->dec_vdev) {
> + jpeg->vfd_jpeg = video_device_alloc();
> + if (!jpeg->vfd_jpeg) {
> ret = -ENOMEM;
> - goto err_dec_vdev_alloc;
> + goto err_vfd_jpeg_alloc;
> }
> - snprintf(jpeg->dec_vdev->name, sizeof(jpeg->dec_vdev->name),
> - "%s-dec", MTK_JPEG_NAME);
> - jpeg->dec_vdev->fops = &mtk_jpeg_fops;
> - jpeg->dec_vdev->ioctl_ops = &mtk_jpeg_ioctl_ops;
> - jpeg->dec_vdev->minor = -1;
> - jpeg->dec_vdev->release = video_device_release;
> - jpeg->dec_vdev->lock = &jpeg->lock;
> - jpeg->dec_vdev->v4l2_dev = &jpeg->v4l2_dev;
> - jpeg->dec_vdev->vfl_dir = VFL_DIR_M2M;
> - jpeg->dec_vdev->device_caps = V4L2_CAP_STREAMING |
> + snprintf(jpeg->vfd_jpeg->name, sizeof(jpeg->vfd_jpeg->name),
> + "%s-%s", MTK_JPEG_NAME,
> + jpeg->mode == MTK_JPEG_ENC ? "enc" : "dec");
> + jpeg->vfd_jpeg->fops = &mtk_jpeg_fops;
> + jpeg->vfd_jpeg->ioctl_ops = &mtk_jpeg_ioctl_ops;
> + jpeg->vfd_jpeg->minor = -1;
> + jpeg->vfd_jpeg->release = video_device_release;
> + jpeg->vfd_jpeg->lock = &jpeg->lock;
> + jpeg->vfd_jpeg->v4l2_dev = &jpeg->v4l2_dev;
> + jpeg->vfd_jpeg->vfl_dir = VFL_DIR_M2M;
> + jpeg->vfd_jpeg->device_caps = V4L2_CAP_STREAMING |
> V4L2_CAP_VIDEO_M2M_MPLANE;
>
> - ret = video_register_device(jpeg->dec_vdev, VFL_TYPE_GRABBER, 3);
> + ret = video_register_device(jpeg->vfd_jpeg, VFL_TYPE_GRABBER, -1);
> if (ret) {
> v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n");
> - goto err_dec_vdev_register;
> + goto err_vfd_jpeg_register;
> }
>
> - video_set_drvdata(jpeg->dec_vdev, jpeg);
> + video_set_drvdata(jpeg->vfd_jpeg, jpeg);
> v4l2_info(&jpeg->v4l2_dev,
> - "decoder device registered as /dev/video%d (%d,%d)\n",
> - jpeg->dec_vdev->num, VIDEO_MAJOR, jpeg->dec_vdev->minor);
> + "jpeg device %d registered as /dev/video%d (%d,%d)\n",
> + jpeg->mode, jpeg->vfd_jpeg->num, VIDEO_MAJOR,
> + jpeg->vfd_jpeg->minor);
>
> platform_set_drvdata(pdev, jpeg);
>
> @@ -1167,10 +1579,10 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
>
> return 0;
>
> -err_dec_vdev_register:
> - video_device_release(jpeg->dec_vdev);
> +err_vfd_jpeg_register:
> + video_device_release(jpeg->vfd_jpeg);
>
> -err_dec_vdev_alloc:
> +err_vfd_jpeg_alloc:
> v4l2_m2m_release(jpeg->m2m_dev);
>
> err_m2m_init:
> @@ -1190,8 +1602,8 @@ static int mtk_jpeg_remove(struct platform_device *pdev)
> struct mtk_jpeg_dev *jpeg = platform_get_drvdata(pdev);
>
> pm_runtime_disable(&pdev->dev);
> - video_unregister_device(jpeg->dec_vdev);
> - video_device_release(jpeg->dec_vdev);
> + video_unregister_device(jpeg->vfd_jpeg);
> + video_device_release(jpeg->vfd_jpeg);
> v4l2_m2m_release(jpeg->m2m_dev);
> v4l2_device_unregister(&jpeg->v4l2_dev);
>
> @@ -1202,7 +1614,11 @@ static __maybe_unused int mtk_jpeg_pm_suspend(struct device *dev)
> {
> struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
>
> - mtk_jpeg_dec_reset(jpeg->dec_reg_base);
> + if (jpeg->mode == MTK_JPEG_ENC)
> + mtk_jpeg_enc_reset(jpeg->reg_base);
> + else
> + mtk_jpeg_dec_reset(jpeg->reg_base);
> +
> mtk_jpeg_clk_off(jpeg);
>
> return 0;
> @@ -1213,7 +1629,10 @@ static __maybe_unused int mtk_jpeg_pm_resume(struct device *dev)
> struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
>
> mtk_jpeg_clk_on(jpeg);
> - mtk_jpeg_dec_reset(jpeg->dec_reg_base);
> + if (jpeg->mode == MTK_JPEG_ENC)
> + mtk_jpeg_enc_reset(jpeg->reg_base);
> + else
> + mtk_jpeg_dec_reset(jpeg->reg_base);
>
> return 0;
> }
> @@ -1249,11 +1668,15 @@ static const struct dev_pm_ops mtk_jpeg_pm_ops = {
> static const struct of_device_id mtk_jpeg_match[] = {
> {
> .compatible = "mediatek,mt8173-jpgdec",
> - .data = NULL,
> + .data = (void *)MTK_JPEG_DEC,
> },
> {
> .compatible = "mediatek,mt2701-jpgdec",
> - .data = NULL,
> + .data = (void *)MTK_JPEG_DEC,
> + },
> + {
> + .compatible = "mediatek,mtk-jpgenc",
> + .data = (void *)MTK_JPEG_ENC,
> },
> {},
> };
The g/s_selection ioctls are unchanged: that can't be right.
The decoder supports composing, but that's not valid for an encoder:
I expect cropping support for an encoder.
Regards,
Hans
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v3 5/5] media: platform: Add jpeg dec/enc feature
@ 2019-09-26 9:46 ` Hans Verkuil
0 siblings, 0 replies; 30+ messages in thread
From: Hans Verkuil @ 2019-09-26 9:46 UTC (permalink / raw)
To: Xia Jiang, Mauro Carvalho Chehab, Rob Herring, Matthias Brugger,
Rick Chang
Cc: devicetree, srv_heupstream, linux-kernel, Tomasz Figa,
linux-mediatek, linux-media, linux-arm-kernel, Marek Szyprowski
On 9/24/19 9:43 AM, Xia Jiang wrote:
> Add mtk jpeg encode v4l2 driver based on jpeg decode, because that jpeg
> decode and encode have great similarities with function operation.
>
> Signed-off-by: Xia Jiang <xia.jiang@mediatek.com>
> ---
> v3: delete Change-Id
> only test once handler->error after the last v4l2_ctrl_new_std()
> seperate changes of v4l2-ctrls.c and v4l2-controls.h to new patch
> v2: fix compliance test fail, check created buffer size in driver
> ---
> drivers/media/platform/mtk-jpeg/Makefile | 5 +-
> .../media/platform/mtk-jpeg/mtk_jpeg_core.c | 735 ++++++++++++++----
> .../media/platform/mtk-jpeg/mtk_jpeg_core.h | 114 ++-
> .../media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h | 7 +-
> .../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c | 175 +++++
> .../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h | 60 ++
> .../platform/mtk-jpeg/mtk_jpeg_enc_reg.h | 49 ++
> 7 files changed, 975 insertions(+), 170 deletions(-)
> create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c
> create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h
> create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_reg.h
>
> diff --git a/drivers/media/platform/mtk-jpeg/Makefile b/drivers/media/platform/mtk-jpeg/Makefile
> index 48516dcf96e6..76c33aad0f3f 100644
> --- a/drivers/media/platform/mtk-jpeg/Makefile
> +++ b/drivers/media/platform/mtk-jpeg/Makefile
> @@ -1,3 +1,6 @@
> # SPDX-License-Identifier: GPL-2.0-only
> -mtk_jpeg-objs := mtk_jpeg_core.o mtk_jpeg_dec_hw.o mtk_jpeg_dec_parse.o
> +mtk_jpeg-objs := mtk_jpeg_core.o \
> + mtk_jpeg_dec_hw.o \
> + mtk_jpeg_dec_parse.o \
> + mtk_jpeg_enc_hw.o
> obj-$(CONFIG_VIDEO_MEDIATEK_JPEG) += mtk_jpeg.o
> diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> index 5f0990fce8ef..aa18b01802ed 100644
> --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> @@ -3,6 +3,7 @@
> * Copyright (c) 2016 MediaTek Inc.
> * Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
> * Rick Chang <rick.chang@mediatek.com>
> + * Xia Jiang <xia.jiang@mediatek.com>
> */
>
> #include <linux/clk.h>
> @@ -23,6 +24,7 @@
> #include <media/videobuf2-dma-contig.h>
> #include <soc/mediatek/smi.h>
>
> +#include "mtk_jpeg_enc_hw.h"
> #include "mtk_jpeg_dec_hw.h"
> #include "mtk_jpeg_core.h"
> #include "mtk_jpeg_dec_parse.h"
> @@ -31,7 +33,8 @@ static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
> {
> .fourcc = V4L2_PIX_FMT_JPEG,
> .colplanes = 1,
> - .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT,
> + .flags = MTK_JPEG_FMT_FLAG_DEC_OUTPUT |
> + MTK_JPEG_FMT_FLAG_ENC_CAPTURE,
> },
> {
> .fourcc = V4L2_PIX_FMT_YUV420M,
> @@ -51,6 +54,42 @@ static struct mtk_jpeg_fmt mtk_jpeg_formats[] = {
> .v_align = 3,
> .flags = MTK_JPEG_FMT_FLAG_DEC_CAPTURE,
> },
> + {
> + .fourcc = V4L2_PIX_FMT_NV12M,
> + .h_sample = {4, 2, 2},
> + .v_sample = {4, 2, 2},
> + .colplanes = 2,
> + .h_align = 4,
> + .v_align = 4,
> + .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_NV21M,
> + .h_sample = {4, 2, 2},
> + .v_sample = {4, 2, 2},
> + .colplanes = 2,
> + .h_align = 4,
> + .v_align = 4,
> + .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_YUYV,
> + .h_sample = {4, 2, 2},
> + .v_sample = {4, 4, 4},
> + .colplanes = 1,
> + .h_align = 4,
> + .v_align = 3,
> + .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_YVYU,
> + .h_sample = {4, 2, 2},
> + .v_sample = {4, 4, 4},
> + .colplanes = 1,
> + .h_align = 4,
> + .v_align = 3,
> + .flags = MTK_JPEG_FMT_FLAG_ENC_OUTPUT,
> + },
> };
>
> #define MTK_JPEG_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_formats)
> @@ -65,11 +104,19 @@ struct mtk_jpeg_src_buf {
> struct list_head list;
> int flags;
> struct mtk_jpeg_dec_param dec_param;
> + struct mtk_jpeg_enc_param enc_param;
> };
>
> +#define MTK_MAX_CTRLS_HINT 20
> +
> static int debug;
> module_param(debug, int, 0644);
>
> +static inline struct mtk_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *ctrl)
> +{
> + return container_of(ctrl->handler, struct mtk_jpeg_ctx, ctrl_hdl);
> +}
> +
> static inline struct mtk_jpeg_ctx *mtk_jpeg_fh_to_ctx(struct v4l2_fh *fh)
> {
> return container_of(fh, struct mtk_jpeg_ctx, fh);
> @@ -86,10 +133,70 @@ static int mtk_jpeg_querycap(struct file *file, void *priv,
> {
> struct mtk_jpeg_dev *jpeg = video_drvdata(file);
>
> - strscpy(cap->driver, MTK_JPEG_NAME " decoder", sizeof(cap->driver));
> - strscpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
> - snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
> - dev_name(jpeg->dev));
> + strscpy(cap->driver, MTK_JPEG_NAME, sizeof(cap->driver));
> + if (jpeg->mode == MTK_JPEG_ENC)
> + strscpy(cap->card, MTK_JPEG_NAME " encoder", sizeof(cap->card));
> + else
> + strscpy(cap->card, MTK_JPEG_NAME " decoder", sizeof(cap->card));
> + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
> + dev_name(jpeg->dev));
> +
> + return 0;
> +}
> +
> +static int vidioc_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
> +{
> + struct mtk_jpeg_ctx *ctx = ctrl_to_ctx(ctrl);
> + struct jpeg_enc_param *p = &ctx->jpeg_param;
> + struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> + int ret = 0;
> +
> + switch (ctrl->id) {
> + case V4L2_CID_JPEG_RESTART_INTERVAL:
> + p->restart_interval = ctrl->val;
> + break;
> + case V4L2_CID_JPEG_COMPRESSION_QUALITY:
> + p->enc_quality = ctrl->val;
> + break;
> + case V4L2_CID_JPEG_ENABLE_EXIF:
> + p->enable_exif = ctrl->val;
> + break;
> + }
> +
> + v4l2_dbg(2, debug, &jpeg->v4l2_dev, "%s val = %d",
> + v4l2_ctrl_get_name(ctrl->id), ctrl->val);
> +
> + return ret;
> +}
> +
> +static const struct v4l2_ctrl_ops mtk_jpeg_ctrl_ops = {
> + .s_ctrl = vidioc_jpeg_s_ctrl,
> +};
> +
> +int mtk_jpeg_ctrls_setup(struct mtk_jpeg_ctx *ctx)
> +{
> + const struct v4l2_ctrl_ops *ops = &mtk_jpeg_ctrl_ops;
> + struct v4l2_ctrl_handler *handler = &ctx->ctrl_hdl;
> + struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> +
> + v4l2_ctrl_handler_init(handler, MTK_MAX_CTRLS_HINT);
> +
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + v4l2_ctrl_new_std(handler, ops, V4L2_CID_JPEG_RESTART_INTERVAL,
> + 0, 100, 1, 0);
> + v4l2_ctrl_new_std(handler, ops,
> + V4L2_CID_JPEG_COMPRESSION_QUALITY, 48, 100, 1,
> + 90);
> + v4l2_ctrl_new_std(handler, ops, V4L2_CID_JPEG_ENABLE_EXIF, 0,
> + 1, 1, 0);
> +
> + if (handler->error) {
> + v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
> + return handler->error;
> + }
> + }
> +
> + v4l2_ctrl_handler_setup(&ctx->ctrl_hdl);
>
> return 0;
> }
> @@ -118,23 +225,29 @@ static int mtk_jpeg_enum_fmt(struct mtk_jpeg_fmt *mtk_jpeg_formats, int n,
> static int mtk_jpeg_enum_fmt_vid_cap(struct file *file, void *priv,
> struct v4l2_fmtdesc *f)
> {
> + struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
> +
> return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
> + ctx->jpeg->mode == MTK_JPEG_ENC ?
> + MTK_JPEG_FMT_FLAG_ENC_CAPTURE :
> MTK_JPEG_FMT_FLAG_DEC_CAPTURE);
> }
>
> static int mtk_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
> struct v4l2_fmtdesc *f)
> {
> + struct mtk_jpeg_ctx *ctx = mtk_jpeg_fh_to_ctx(priv);
> +
> return mtk_jpeg_enum_fmt(mtk_jpeg_formats, MTK_JPEG_NUM_FORMATS, f,
> + ctx->jpeg->mode == MTK_JPEG_ENC ?
> + MTK_JPEG_FMT_FLAG_ENC_OUTPUT :
> MTK_JPEG_FMT_FLAG_DEC_OUTPUT);
> }
>
> -static struct mtk_jpeg_q_data *mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx,
> - enum v4l2_buf_type type)
> +static struct mtk_jpeg_q_data *
> +mtk_jpeg_get_q_data(struct mtk_jpeg_ctx *ctx, enum v4l2_buf_type type)
> {
> - if (V4L2_TYPE_IS_OUTPUT(type))
> - return &ctx->out_q;
> - return &ctx->cap_q;
> + return V4L2_TYPE_IS_OUTPUT(type) ? &ctx->out_q : &ctx->cap_q;
> }
>
> static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
> @@ -143,9 +256,14 @@ static struct mtk_jpeg_fmt *mtk_jpeg_find_format(struct mtk_jpeg_ctx *ctx,
> {
> unsigned int k, fmt_flag;
>
> - fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
> - MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
> - MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
> + if (ctx->jpeg->mode == MTK_JPEG_ENC)
> + fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
> + MTK_JPEG_FMT_FLAG_ENC_OUTPUT :
> + MTK_JPEG_FMT_FLAG_ENC_CAPTURE;
> + else
> + fmt_flag = (fmt_type == MTK_JPEG_FMT_TYPE_OUTPUT) ?
> + MTK_JPEG_FMT_FLAG_DEC_OUTPUT :
> + MTK_JPEG_FMT_FLAG_DEC_CAPTURE;
>
> for (k = 0; k < MTK_JPEG_NUM_FORMATS; k++) {
> struct mtk_jpeg_fmt *fmt = &mtk_jpeg_formats[k];
> @@ -202,7 +320,7 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
> {
> struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
> struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> - int i;
> + int i, align_w, align_h;
>
> memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
> pix_mp->field = V4L2_FIELD_NONE;
> @@ -216,36 +334,111 @@ static int mtk_jpeg_try_fmt_mplane(struct v4l2_format *f,
> pix_mp->pixelformat = fmt->fourcc;
>
> if (q_type == MTK_JPEG_FMT_TYPE_OUTPUT) {
> - struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[0];
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + pix_mp->height = clamp(pix_mp->height,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT);
> + pix_mp->width = clamp(pix_mp->width,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH);
> + align_w = pix_mp->width;
> + align_h = pix_mp->height;
> + align_w = round_up(align_w, 2);
> + if (pix_mp->num_planes == 1U) {
> + align_w = align_w << 1;
> + mtk_jpeg_bound_align_image(&align_w,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH,
> + 5, &align_h,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT,
> + 3);
> + pix_mp->plane_fmt[0].bytesperline = align_w;
> + pix_mp->plane_fmt[0].sizeimage =
> + align_w * align_h;
> + } else if (pix_mp->num_planes == 2U) {
> + mtk_jpeg_bound_align_image(&align_w,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH,
> + 4, &align_h,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT,
> + 4);
> + pix_mp->plane_fmt[0].bytesperline = align_w;
> + pix_mp->plane_fmt[0].sizeimage =
> + align_w * align_h;
> + pix_mp->plane_fmt[1].bytesperline = align_w;
> + pix_mp->plane_fmt[1].sizeimage =
> + (align_w * align_h) / 2;
> + } else {
> + v4l2_err(&ctx->jpeg->v4l2_dev,
> + "Unsupport num planes = %d\n",
> + pix_mp->num_planes);
> + }
> + goto end;
> + } else {
> + struct v4l2_plane_pix_format *pfmt =
> + &pix_mp->plane_fmt[0];
> +
> + mtk_jpeg_bound_align_image(&pix_mp->width,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH, 0,
> + &pix_mp->height,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT, 0);
> +
> + pfmt->bytesperline = 0;
> + /* Source size must be aligned to 128 */
> + pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
> + if (pfmt->sizeimage == 0)
> + pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
> +
> + goto end;
> + }
> + }
The differences between capture and output are too large IMHO. I would
recommend splitting this into different functions, one for the encoder,
one for the decoder.
>
> + /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
> + if (jpeg->mode == MTK_JPEG_ENC) {
> mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
> MTK_JPEG_MAX_WIDTH, 0,
> &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
> MTK_JPEG_MAX_HEIGHT, 0);
>
> - memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
> - pfmt->bytesperline = 0;
> - /* Source size must be aligned to 128 */
> - pfmt->sizeimage = mtk_jpeg_align(pfmt->sizeimage, 128);
> - if (pfmt->sizeimage == 0)
> - pfmt->sizeimage = MTK_JPEG_DEFAULT_SIZEIMAGE;
> - goto end;
> + if (fmt->fourcc == V4L2_PIX_FMT_JPEG) {
> + pix_mp->plane_fmt[0].bytesperline = 0;
> + pix_mp->plane_fmt[0].sizeimage =
> + mtk_jpeg_align(pix_mp->plane_fmt[0].sizeimage,
> + 128);
> + if (pix_mp->plane_fmt[0].sizeimage == 0)
> + pix_mp->plane_fmt[0].sizeimage =
> + MTK_JPEG_DEFAULT_SIZEIMAGE;
> + }
> + } else {
> + pix_mp->height = clamp(pix_mp->height, MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT);
> + pix_mp->width = clamp(pix_mp->width, MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH);
> + mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH, fmt->h_align,
> + &pix_mp->height,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT, fmt->v_align);
> +
> + for (i = 0; i < fmt->colplanes; i++) {
> + struct v4l2_plane_pix_format *pfmt =
> + &pix_mp->plane_fmt[i];
> + u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
> + u32 h = pix_mp->height * fmt->v_sample[i] / 4;
> +
> + pfmt->bytesperline = stride;
> + pfmt->sizeimage = stride * h;
> + }
> }
>
> - /* type is MTK_JPEG_FMT_TYPE_CAPTURE */
> - mtk_jpeg_bound_align_image(&pix_mp->width, MTK_JPEG_MIN_WIDTH,
> - MTK_JPEG_MAX_WIDTH, fmt->h_align,
> - &pix_mp->height, MTK_JPEG_MIN_HEIGHT,
> - MTK_JPEG_MAX_HEIGHT, fmt->v_align);
> -
> for (i = 0; i < fmt->colplanes; i++) {
> - struct v4l2_plane_pix_format *pfmt = &pix_mp->plane_fmt[i];
> - u32 stride = pix_mp->width * fmt->h_sample[i] / 4;
> - u32 h = pix_mp->height * fmt->v_sample[i] / 4;
> -
> + struct v4l2_plane_pix_format *pfmt =
> + &pix_mp->plane_fmt[i];
> memset(pfmt->reserved, 0, sizeof(pfmt->reserved));
> - pfmt->bytesperline = stride;
> - pfmt->sizeimage = stride * h;
> }
> end:
> v4l2_dbg(2, debug, &jpeg->v4l2_dev, "wxh:%ux%u\n",
> @@ -446,9 +639,9 @@ static int mtk_jpeg_subscribe_event(struct v4l2_fh *fh,
> switch (sub->type) {
> case V4L2_EVENT_SOURCE_CHANGE:
> return v4l2_src_change_event_subscribe(fh, sub);
> - default:
> - return -EINVAL;
> }
> +
> + return v4l2_ctrl_subscribe_event(fh, sub);
> }
This appears to be a bug fix. Please put this in a separate patch.
>
> static int mtk_jpeg_g_selection(struct file *file, void *priv,
> @@ -571,6 +764,13 @@ static int mtk_jpeg_queue_setup(struct vb2_queue *q,
> if (!q_data)
> return -EINVAL;
>
> + if (*num_planes) {
> + for (i = 0; i < *num_planes; i++)
> + if (sizes[i] < q_data->sizeimage[i])
> + return -EINVAL;
> + return 0;
> + }
> +
> *num_planes = q_data->fmt->colplanes;
> for (i = 0; i < q_data->fmt->colplanes; i++) {
> sizes[i] = q_data->sizeimage[i];
Also appears to be a bug fix.
> @@ -651,10 +851,92 @@ static void mtk_jpeg_set_queue_data(struct mtk_jpeg_ctx *ctx,
> param->dec_w, param->dec_h);
> }
>
> +static void mtk_jpeg_set_param(struct mtk_jpeg_ctx *ctx,
> + struct mtk_jpeg_enc_param *param)
> +{
> + struct mtk_jpeg_q_data *q_data_src = &ctx->out_q;
> + struct jpeg_enc_param *jpeg_params = &ctx->jpeg_param;
> + struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> + u32 width_even;
> + u32 is_420;
> + u32 padding_width;
> + u32 padding_height;
> +
> + switch (q_data_src->fmt->fourcc) {
> + case V4L2_PIX_FMT_YUYV:
> + param->enc_format = JPEG_YUV_FORMAT_YUYV;
> + break;
> + case V4L2_PIX_FMT_YVYU:
> + param->enc_format = JPEG_YUV_FORMAT_YVYU;
> + break;
> + case V4L2_PIX_FMT_NV12M:
> + param->enc_format = JPEG_YUV_FORMAT_NV12;
> + break;
> + case V4L2_PIX_FMT_NV21M:
> + param->enc_format = JPEG_YUV_FORMAT_NV12;
> + break;
> + default:
> + v4l2_err(&jpeg->v4l2_dev, "Unsupport fourcc =%d\n",
> + q_data_src->fmt->fourcc);
> + break;
> + }
> + param->enc_w = q_data_src->w;
> + param->enc_h = q_data_src->h;
> +
> + if (jpeg_params->enc_quality >= 97)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q97;
> + else if (jpeg_params->enc_quality >= 95)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q95;
> + else if (jpeg_params->enc_quality >= 92)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q92;
> + else if (jpeg_params->enc_quality >= 90)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q90;
> + else if (jpeg_params->enc_quality >= 87)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q87;
> + else if (jpeg_params->enc_quality >= 84)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q84;
> + else if (jpeg_params->enc_quality >= 80)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q80;
> + else if (jpeg_params->enc_quality >= 74)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q74;
> + else if (jpeg_params->enc_quality >= 64)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q64;
> + else if (jpeg_params->enc_quality >= 60)
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q60;
> + else
> + param->enc_quality = JPEG_ENCODE_QUALITY_Q48;
> +
> + param->enable_exif = jpeg_params->enable_exif;
> + param->restart_interval = jpeg_params->restart_interval;
> +
> + width_even = ((param->enc_w + 1) >> 1) << 1;
> + is_420 = (param->enc_format == JPEG_YUV_FORMAT_NV12 ||
> + param->enc_format == JPEG_YUV_FORMAT_NV12) ? 1 : 0;
> + padding_width = mtk_jpeg_align(param->enc_w, 16);
> + padding_height = mtk_jpeg_align(param->enc_h, is_420 ? 16 : 8);
> + if (!is_420)
> + width_even = width_even << 1;
> +
> + param->img_stride = mtk_jpeg_align(width_even, (is_420 ? 16 : 32));
> + param->mem_stride = mtk_jpeg_align(width_even, (is_420 ? 16 : 32));
> + param->total_encdu =
> + ((padding_width >> 4) * (padding_height >> (is_420 ? 4 : 3)) *
> + (is_420 ? 6 : 4)) - 1;
> +
> + v4l2_dbg(0, 2, &jpeg->v4l2_dev, "fmt %d, w,h %d,%d, enable_exif %d,",
> + "enc_quality %d, restart_interval %d,img_stride %d,",
> + "mem_stride %d,totalEncDu %d\n",
> + param->enc_format, param->enc_w, param->enc_h,
> + param->enable_exif, param->enc_quality,
> + param->restart_interval, param->img_stride,
> + param->mem_stride, param->total_encdu);
> +}
> +
> static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
> {
> struct mtk_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
> struct mtk_jpeg_dec_param *param;
> + struct mtk_jpeg_enc_param *enc_param;
> struct mtk_jpeg_dev *jpeg = ctx->jpeg;
> struct mtk_jpeg_src_buf *jpeg_src_buf;
> bool header_valid;
> @@ -666,29 +948,45 @@ static void mtk_jpeg_buf_queue(struct vb2_buffer *vb)
> goto end;
>
> jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb);
> - param = &jpeg_src_buf->dec_param;
> - memset(param, 0, sizeof(*param));
> -
> - if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
> - v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
> - goto end;
> - }
> - header_valid = mtk_jpeg_parse(param, (u8 *)vb2_plane_vaddr(vb, 0),
> - vb2_get_plane_payload(vb, 0));
> - if (!header_valid) {
> - v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
> - vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
> - return;
> - }
> -
> - if (ctx->state == MTK_JPEG_INIT) {
> - struct vb2_queue *dst_vq = v4l2_m2m_get_vq(
> - ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + enc_param = &jpeg_src_buf->enc_param;
> + memset(enc_param, 0, sizeof(*enc_param));
> + mtk_jpeg_set_param(ctx, enc_param);
> + if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
> + v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos");
> + goto end;
> + }
> + if (ctx->state == MTK_JPEG_INIT)
> + ctx->state = MTK_JPEG_RUNNING;
> + } else {
> + param = &jpeg_src_buf->dec_param;
> + memset(param, 0, sizeof(*param));
> +
> + if (jpeg_src_buf->flags & MTK_JPEG_BUF_FLAGS_LAST_FRAME) {
> + v4l2_dbg(1, debug, &jpeg->v4l2_dev, "Got eos\n");
> + goto end;
> + }
> + header_valid = mtk_jpeg_parse(param,
> + (u8 *)vb2_plane_vaddr(vb, 0),
> + vb2_get_plane_payload(vb, 0));
> + if (!header_valid) {
> + v4l2_err(&jpeg->v4l2_dev, "Header invalid.\n");
> + vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
> + return;
> + }
>
> - mtk_jpeg_queue_src_chg_event(ctx);
> - mtk_jpeg_set_queue_data(ctx, param);
> - ctx->state = vb2_is_streaming(dst_vq) ?
> - MTK_JPEG_SOURCE_CHANGE : MTK_JPEG_RUNNING;
> + if (ctx->state == MTK_JPEG_INIT) {
> + struct vb2_queue *dst_vq;
> +
> + dst_vq = v4l2_m2m_get_vq
> + (ctx->fh.m2m_ctx,
> + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
> + mtk_jpeg_queue_src_chg_event(ctx);
> + mtk_jpeg_set_queue_data(ctx, param);
> + ctx->state = vb2_is_streaming(dst_vq) ?
> + MTK_JPEG_SOURCE_CHANGE :
> + MTK_JPEG_RUNNING;
> + }
> }
> end:
> v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, to_vb2_v4l2_buffer(vb));
> @@ -731,16 +1029,16 @@ static void mtk_jpeg_stop_streaming(struct vb2_queue *q)
> * subsampling. Update capture queue when the stream is off.
> */
> if (ctx->state == MTK_JPEG_SOURCE_CHANGE &&
> - !V4L2_TYPE_IS_OUTPUT(q->type)) {
> + !V4L2_TYPE_IS_OUTPUT(q->type) &&
> + ctx->jpeg->mode == MTK_JPEG_DEC) {
> struct mtk_jpeg_src_buf *src_buf;
>
> vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> src_buf = mtk_jpeg_vb2_to_srcbuf(&vb->vb2_buf);
> mtk_jpeg_set_queue_data(ctx, &src_buf->dec_param);
> ctx->state = MTK_JPEG_RUNNING;
> - } else if (V4L2_TYPE_IS_OUTPUT(q->type)) {
> + } else if (V4L2_TYPE_IS_OUTPUT(q->type))
> ctx->state = MTK_JPEG_INIT;
> - }
>
> while ((vb = mtk_jpeg_buf_remove(ctx, q->type)))
> v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
> @@ -795,6 +1093,28 @@ static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx,
> return 0;
> }
>
> +static void mtk_jpeg_set_enc_dst(struct mtk_jpeg_ctx *ctx,
> + struct vb2_buffer *dst_buf,
> + struct mtk_jpeg_enc_bs *bs)
> +{
> + bs->dma_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0) &
> + (~JPEG_ENC_DST_ADDR_OFFSET_MASK);
> + bs->dma_addr_offset = 0;
> + bs->dma_addr_offsetmask = bs->dma_addr & JPEG_ENC_DST_ADDR_OFFSET_MASK;
> + bs->size = mtk_jpeg_align(vb2_plane_size(dst_buf, 0), 128);
> +}
> +
> +static void mtk_jpeg_set_enc_src(struct mtk_jpeg_ctx *ctx,
> + struct vb2_buffer *src_buf,
> + struct mtk_jpeg_enc_fb *fb)
> +{
> + int i;
> +
> + for (i = 0; i < src_buf->num_planes; i++)
> + fb->fb_addr[i].dma_addr =
> + vb2_dma_contig_plane_dma_addr(src_buf, i);
> +}
> +
> static void mtk_jpeg_device_run(void *priv)
> {
> struct mtk_jpeg_ctx *ctx = priv;
> @@ -805,6 +1125,8 @@ static void mtk_jpeg_device_run(void *priv)
> struct mtk_jpeg_src_buf *jpeg_src_buf;
> struct mtk_jpeg_bs bs;
> struct mtk_jpeg_fb fb;
> + struct mtk_jpeg_enc_bs enc_bs;
> + struct mtk_jpeg_enc_fb enc_fb;
> int i;
>
> src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -815,30 +1137,45 @@ static void mtk_jpeg_device_run(void *priv)
> for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
> vb2_set_plane_payload(&dst_buf->vb2_buf, i, 0);
> buf_state = VB2_BUF_STATE_DONE;
> - goto dec_end;
> + goto device_run_end;
> }
>
> - if (mtk_jpeg_check_resolution_change(ctx, &jpeg_src_buf->dec_param)) {
> - mtk_jpeg_queue_src_chg_event(ctx);
> - ctx->state = MTK_JPEG_SOURCE_CHANGE;
> - v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> - return;
> - }
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + mtk_jpeg_set_enc_dst(ctx, &dst_buf->vb2_buf, &enc_bs);
> + mtk_jpeg_set_enc_src(ctx, &src_buf->vb2_buf, &enc_fb);
> +
> + spin_lock_irqsave(&jpeg->hw_lock, flags);
> + mtk_jpeg_enc_reset(jpeg->reg_base);
> + mtk_jpeg_enc_set_config(jpeg->reg_base,
> + &jpeg_src_buf->enc_param, &enc_bs,
> + &enc_fb);
> +
> + mtk_jpeg_enc_start(jpeg->reg_base);
> + } else {
> + if (mtk_jpeg_check_resolution_change
> + (ctx, &jpeg_src_buf->dec_param)) {
> + mtk_jpeg_queue_src_chg_event(ctx);
> + ctx->state = MTK_JPEG_SOURCE_CHANGE;
> + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> + return;
> + }
>
> - mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
> - if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, &dst_buf->vb2_buf, &fb))
> - goto dec_end;
> + mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs);
> + if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param,
> + &dst_buf->vb2_buf, &fb))
> + goto device_run_end;
>
> - spin_lock_irqsave(&jpeg->hw_lock, flags);
> - mtk_jpeg_dec_reset(jpeg->dec_reg_base);
> - mtk_jpeg_dec_set_config(jpeg->dec_reg_base,
> - &jpeg_src_buf->dec_param, &bs, &fb);
> + spin_lock_irqsave(&jpeg->hw_lock, flags);
> + mtk_jpeg_dec_reset(jpeg->reg_base);
> + mtk_jpeg_dec_set_config(jpeg->reg_base,
> + &jpeg_src_buf->dec_param, &bs, &fb);
>
> - mtk_jpeg_dec_start(jpeg->dec_reg_base);
> + mtk_jpeg_dec_start(jpeg->reg_base);
> + }
> spin_unlock_irqrestore(&jpeg->hw_lock, flags);
> return;
>
> -dec_end:
> +device_run_end:
> v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
> v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
> v4l2_m2m_buf_done(src_buf, buf_state);
> @@ -898,30 +1235,30 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)
> ret = mtk_smi_larb_get(jpeg->larb);
> if (ret)
> dev_err(jpeg->dev, "mtk_smi_larb_get larbvdec fail %d\n", ret);
> - clk_prepare_enable(jpeg->clk_jdec_smi);
> - clk_prepare_enable(jpeg->clk_jdec);
> + if (jpeg->mode == MTK_JPEG_DEC)
> + clk_prepare_enable(jpeg->clk_jpeg_smi);
> + clk_prepare_enable(jpeg->clk_jpeg);
> }
>
> static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg)
> {
> - clk_disable_unprepare(jpeg->clk_jdec);
> - clk_disable_unprepare(jpeg->clk_jdec_smi);
> + clk_disable_unprepare(jpeg->clk_jpeg);
> + if (jpeg->mode == MTK_JPEG_DEC)
> + clk_disable_unprepare(jpeg->clk_jpeg_smi);
> mtk_smi_larb_put(jpeg->larb);
> }
>
> -static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
> +static irqreturn_t mtk_jpeg_irq(int irq, void *priv)
> {
> struct mtk_jpeg_dev *jpeg = priv;
> struct mtk_jpeg_ctx *ctx;
> struct vb2_v4l2_buffer *src_buf, *dst_buf;
> struct mtk_jpeg_src_buf *jpeg_src_buf;
> enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR;
> - u32 dec_irq_ret;
> - u32 dec_ret;
> + u32 irq_ret;
> + u32 ret, result_size;
> int i;
>
> - dec_ret = mtk_jpeg_dec_get_int_status(jpeg->dec_reg_base);
> - dec_irq_ret = mtk_jpeg_dec_enum_result(dec_ret);
> ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev);
> if (!ctx) {
> v4l2_err(&jpeg->v4l2_dev, "Context is NULL\n");
> @@ -932,21 +1269,42 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
> dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
> jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
>
> - if (dec_irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
> - mtk_jpeg_dec_reset(jpeg->dec_reg_base);
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + ret = mtk_jpeg_enc_get_int_status(jpeg->reg_base);
> + irq_ret = mtk_jpeg_enc_enum_result(jpeg->reg_base, ret,
> + &result_size);
>
> - if (dec_irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
> - dev_err(jpeg->dev, "decode failed\n");
> - goto dec_end;
> - }
> + if (irq_ret >= MTK_JPEG_ENC_RESULT_STALL)
> + mtk_jpeg_enc_reset(jpeg->reg_base);
> +
> + if (irq_ret != MTK_JPEG_ENC_RESULT_DONE) {
> + dev_err(jpeg->dev, "encode failed\n");
> + goto irq_end;
> + }
>
> - for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
> - vb2_set_plane_payload(&dst_buf->vb2_buf, i,
> - jpeg_src_buf->dec_param.comp_size[i]);
> + vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
> + result_size);
> + } else {
> + ret = mtk_jpeg_dec_get_int_status(jpeg->reg_base);
> + irq_ret = mtk_jpeg_dec_enum_result(ret);
> +
> + if (irq_ret >= MTK_JPEG_DEC_RESULT_UNDERFLOW)
> + mtk_jpeg_dec_reset(jpeg->reg_base);
> +
> + if (irq_ret != MTK_JPEG_DEC_RESULT_EOF_DONE) {
> + dev_err(jpeg->dev, "decode failed\n");
> + goto irq_end;
> + }
> +
> + for (i = 0; i < dst_buf->vb2_buf.num_planes; i++)
> + vb2_set_plane_payload
> + (&dst_buf->vb2_buf, i,
> + jpeg_src_buf->dec_param.comp_size[i]);
> + }
>
> buf_state = VB2_BUF_STATE_DONE;
>
> -dec_end:
> +irq_end:
> v4l2_m2m_buf_done(src_buf, buf_state);
> v4l2_m2m_buf_done(dst_buf, buf_state);
> v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> @@ -956,32 +1314,72 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv)
> static void mtk_jpeg_set_default_params(struct mtk_jpeg_ctx *ctx)
> {
> struct mtk_jpeg_q_data *q = &ctx->out_q;
> - int i;
> + int i, align_w, align_h;
> +
> + ctx->fh.ctrl_handler = &ctx->ctrl_hdl;
>
> ctx->colorspace = V4L2_COLORSPACE_JPEG,
> ctx->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
> ctx->quantization = V4L2_QUANTIZATION_DEFAULT;
> ctx->xfer_func = V4L2_XFER_FUNC_DEFAULT;
>
> - q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
> + if (ctx->jpeg->mode == MTK_JPEG_ENC) {
> + q->w = MTK_JPEG_MIN_WIDTH;
> + q->h = MTK_JPEG_MIN_HEIGHT;
> +
> + q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUYV,
> MTK_JPEG_FMT_TYPE_OUTPUT);
> - q->w = MTK_JPEG_MIN_WIDTH;
> - q->h = MTK_JPEG_MIN_HEIGHT;
> - q->bytesperline[0] = 0;
> - q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
> +
> + align_w = q->w;
> + align_h = q->h;
> + align_w = round_up(align_w, 2);
> + align_w = align_w << 1;
> + v4l_bound_align_image(&align_w,
> + MTK_JPEG_MIN_WIDTH,
> + MTK_JPEG_MAX_WIDTH, 5,
> + &align_h,
> + MTK_JPEG_MIN_HEIGHT,
> + MTK_JPEG_MAX_HEIGHT, 3, 0);
> +
> + if (align_w < MTK_JPEG_MIN_WIDTH &&
> + (align_w + 32) <= MTK_JPEG_MAX_WIDTH)
> + align_w += 32;
> + if (align_h < MTK_JPEG_MIN_HEIGHT &&
> + (align_h + 8) <= MTK_JPEG_MAX_HEIGHT)
> + align_h += 8;
> +
> + q->sizeimage[0] = align_w * align_h;
> + q->bytesperline[0] = align_w;
> + } else {
> + q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
> + MTK_JPEG_FMT_TYPE_OUTPUT);
> + q->w = MTK_JPEG_MIN_WIDTH;
> + q->h = MTK_JPEG_MIN_HEIGHT;
> + q->bytesperline[0] = 0;
> + q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
> + }
>
> q = &ctx->cap_q;
> - q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
> + if (ctx->jpeg->mode == MTK_JPEG_ENC) {
> + q->w = MTK_JPEG_MIN_WIDTH;
> + q->h = MTK_JPEG_MIN_HEIGHT;
> + q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_JPEG,
> + MTK_JPEG_FMT_TYPE_CAPTURE);
> + q->bytesperline[0] = 0;
> + q->sizeimage[0] = MTK_JPEG_DEFAULT_SIZEIMAGE;
> + } else {
> + q->fmt = mtk_jpeg_find_format(ctx, V4L2_PIX_FMT_YUV420M,
> MTK_JPEG_FMT_TYPE_CAPTURE);
> - q->w = MTK_JPEG_MIN_WIDTH;
> - q->h = MTK_JPEG_MIN_HEIGHT;
> + q->w = MTK_JPEG_MIN_WIDTH;
> + q->h = MTK_JPEG_MIN_HEIGHT;
>
> - for (i = 0; i < q->fmt->colplanes; i++) {
> - u32 stride = q->w * q->fmt->h_sample[i] / 4;
> - u32 h = q->h * q->fmt->v_sample[i] / 4;
> + for (i = 0; i < q->fmt->colplanes; i++) {
> + u32 stride = q->w * q->fmt->h_sample[i] / 4;
> + u32 h = q->h * q->fmt->v_sample[i] / 4;
>
> - q->bytesperline[i] = stride;
> - q->sizeimage[i] = stride * h;
> + q->bytesperline[i] = stride;
> + q->sizeimage[i] = stride * h;
> + }
> }
> }
This is another function were there appears to be little overlap between
encoder and decoder. A candidate to split up?
>
> @@ -1013,6 +1411,13 @@ static int mtk_jpeg_open(struct file *file)
> goto error;
> }
>
> + ret = mtk_jpeg_ctrls_setup(ctx);
> + if (ret) {
> + v4l2_err(&jpeg->v4l2_dev, "Failed to setup controls() (%d)\n",
> + ret);
> + goto error;
> + }
> +
> mtk_jpeg_set_default_params(ctx);
> mutex_unlock(&jpeg->lock);
> return 0;
> @@ -1033,6 +1438,7 @@ static int mtk_jpeg_release(struct file *file)
>
> mutex_lock(&jpeg->lock);
> v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
> + v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
> v4l2_fh_del(&ctx->fh);
> v4l2_fh_exit(&ctx->fh);
> kfree(ctx);
> @@ -1057,6 +1463,7 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
> node = of_parse_phandle(jpeg->dev->of_node, "mediatek,larb", 0);
> if (!node)
> return -EINVAL;
> +
> pdev = of_find_device_by_node(node);
> if (WARN_ON(!pdev)) {
> of_node_put(node);
> @@ -1066,19 +1473,24 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg)
>
> jpeg->larb = &pdev->dev;
>
> - jpeg->clk_jdec = devm_clk_get(jpeg->dev, "jpgdec");
> - if (IS_ERR(jpeg->clk_jdec))
> - return PTR_ERR(jpeg->clk_jdec);
> + if (jpeg->mode == MTK_JPEG_ENC) {
> + jpeg->clk_jpeg = devm_clk_get(jpeg->dev, "jpgenc");
> + return PTR_ERR_OR_ZERO(jpeg->clk_jpeg);
> + }
> +
> + jpeg->clk_jpeg = devm_clk_get(jpeg->dev, "jpgdec");
> + if (IS_ERR(jpeg->clk_jpeg))
> + return PTR_ERR(jpeg->clk_jpeg);
>
> - jpeg->clk_jdec_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
> - return PTR_ERR_OR_ZERO(jpeg->clk_jdec_smi);
> + jpeg->clk_jpeg_smi = devm_clk_get(jpeg->dev, "jpgdec-smi");
> + return PTR_ERR_OR_ZERO(jpeg->clk_jpeg_smi);
> }
>
> static int mtk_jpeg_probe(struct platform_device *pdev)
> {
> struct mtk_jpeg_dev *jpeg;
> struct resource *res;
> - int dec_irq;
> + int jpeg_irq;
> int ret;
>
> jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL);
> @@ -1088,28 +1500,26 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
> mutex_init(&jpeg->lock);
> spin_lock_init(&jpeg->hw_lock);
> jpeg->dev = &pdev->dev;
> + jpeg->mode = (enum mtk_jpeg_mode)of_device_get_match_data(jpeg->dev);
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - jpeg->dec_reg_base = devm_ioremap_resource(&pdev->dev, res);
> - if (IS_ERR(jpeg->dec_reg_base)) {
> - ret = PTR_ERR(jpeg->dec_reg_base);
> + jpeg->reg_base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(jpeg->reg_base)) {
> + ret = PTR_ERR(jpeg->reg_base);
> return ret;
> }
>
> - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> - dec_irq = platform_get_irq(pdev, 0);
> - if (!res || dec_irq < 0) {
> - dev_err(&pdev->dev, "Failed to get dec_irq %d.\n", dec_irq);
> - ret = -EINVAL;
> - return ret;
> + jpeg_irq = platform_get_irq(pdev, 0);
> + if (jpeg_irq < 0) {
> + dev_err(&pdev->dev, "Failed to get jpeg_irq %d.\n", jpeg_irq);
> + return jpeg_irq;
> }
>
> - ret = devm_request_irq(&pdev->dev, dec_irq, mtk_jpeg_dec_irq, 0,
> + ret = devm_request_irq(&pdev->dev, jpeg_irq, mtk_jpeg_irq, 0,
> pdev->name, jpeg);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to request dec_irq %d (%d)\n",
> - dec_irq, ret);
> - ret = -EINVAL;
> + dev_err(&pdev->dev, "Failed to request jpeg_irq %d (%d)\n",
> + jpeg_irq, ret);
> goto err_req_irq;
> }
>
> @@ -1133,33 +1543,35 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
> goto err_m2m_init;
> }
>
> - jpeg->dec_vdev = video_device_alloc();
> - if (!jpeg->dec_vdev) {
> + jpeg->vfd_jpeg = video_device_alloc();
> + if (!jpeg->vfd_jpeg) {
> ret = -ENOMEM;
> - goto err_dec_vdev_alloc;
> + goto err_vfd_jpeg_alloc;
> }
> - snprintf(jpeg->dec_vdev->name, sizeof(jpeg->dec_vdev->name),
> - "%s-dec", MTK_JPEG_NAME);
> - jpeg->dec_vdev->fops = &mtk_jpeg_fops;
> - jpeg->dec_vdev->ioctl_ops = &mtk_jpeg_ioctl_ops;
> - jpeg->dec_vdev->minor = -1;
> - jpeg->dec_vdev->release = video_device_release;
> - jpeg->dec_vdev->lock = &jpeg->lock;
> - jpeg->dec_vdev->v4l2_dev = &jpeg->v4l2_dev;
> - jpeg->dec_vdev->vfl_dir = VFL_DIR_M2M;
> - jpeg->dec_vdev->device_caps = V4L2_CAP_STREAMING |
> + snprintf(jpeg->vfd_jpeg->name, sizeof(jpeg->vfd_jpeg->name),
> + "%s-%s", MTK_JPEG_NAME,
> + jpeg->mode == MTK_JPEG_ENC ? "enc" : "dec");
> + jpeg->vfd_jpeg->fops = &mtk_jpeg_fops;
> + jpeg->vfd_jpeg->ioctl_ops = &mtk_jpeg_ioctl_ops;
> + jpeg->vfd_jpeg->minor = -1;
> + jpeg->vfd_jpeg->release = video_device_release;
> + jpeg->vfd_jpeg->lock = &jpeg->lock;
> + jpeg->vfd_jpeg->v4l2_dev = &jpeg->v4l2_dev;
> + jpeg->vfd_jpeg->vfl_dir = VFL_DIR_M2M;
> + jpeg->vfd_jpeg->device_caps = V4L2_CAP_STREAMING |
> V4L2_CAP_VIDEO_M2M_MPLANE;
>
> - ret = video_register_device(jpeg->dec_vdev, VFL_TYPE_GRABBER, 3);
> + ret = video_register_device(jpeg->vfd_jpeg, VFL_TYPE_GRABBER, -1);
> if (ret) {
> v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n");
> - goto err_dec_vdev_register;
> + goto err_vfd_jpeg_register;
> }
>
> - video_set_drvdata(jpeg->dec_vdev, jpeg);
> + video_set_drvdata(jpeg->vfd_jpeg, jpeg);
> v4l2_info(&jpeg->v4l2_dev,
> - "decoder device registered as /dev/video%d (%d,%d)\n",
> - jpeg->dec_vdev->num, VIDEO_MAJOR, jpeg->dec_vdev->minor);
> + "jpeg device %d registered as /dev/video%d (%d,%d)\n",
> + jpeg->mode, jpeg->vfd_jpeg->num, VIDEO_MAJOR,
> + jpeg->vfd_jpeg->minor);
>
> platform_set_drvdata(pdev, jpeg);
>
> @@ -1167,10 +1579,10 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
>
> return 0;
>
> -err_dec_vdev_register:
> - video_device_release(jpeg->dec_vdev);
> +err_vfd_jpeg_register:
> + video_device_release(jpeg->vfd_jpeg);
>
> -err_dec_vdev_alloc:
> +err_vfd_jpeg_alloc:
> v4l2_m2m_release(jpeg->m2m_dev);
>
> err_m2m_init:
> @@ -1190,8 +1602,8 @@ static int mtk_jpeg_remove(struct platform_device *pdev)
> struct mtk_jpeg_dev *jpeg = platform_get_drvdata(pdev);
>
> pm_runtime_disable(&pdev->dev);
> - video_unregister_device(jpeg->dec_vdev);
> - video_device_release(jpeg->dec_vdev);
> + video_unregister_device(jpeg->vfd_jpeg);
> + video_device_release(jpeg->vfd_jpeg);
> v4l2_m2m_release(jpeg->m2m_dev);
> v4l2_device_unregister(&jpeg->v4l2_dev);
>
> @@ -1202,7 +1614,11 @@ static __maybe_unused int mtk_jpeg_pm_suspend(struct device *dev)
> {
> struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
>
> - mtk_jpeg_dec_reset(jpeg->dec_reg_base);
> + if (jpeg->mode == MTK_JPEG_ENC)
> + mtk_jpeg_enc_reset(jpeg->reg_base);
> + else
> + mtk_jpeg_dec_reset(jpeg->reg_base);
> +
> mtk_jpeg_clk_off(jpeg);
>
> return 0;
> @@ -1213,7 +1629,10 @@ static __maybe_unused int mtk_jpeg_pm_resume(struct device *dev)
> struct mtk_jpeg_dev *jpeg = dev_get_drvdata(dev);
>
> mtk_jpeg_clk_on(jpeg);
> - mtk_jpeg_dec_reset(jpeg->dec_reg_base);
> + if (jpeg->mode == MTK_JPEG_ENC)
> + mtk_jpeg_enc_reset(jpeg->reg_base);
> + else
> + mtk_jpeg_dec_reset(jpeg->reg_base);
>
> return 0;
> }
> @@ -1249,11 +1668,15 @@ static const struct dev_pm_ops mtk_jpeg_pm_ops = {
> static const struct of_device_id mtk_jpeg_match[] = {
> {
> .compatible = "mediatek,mt8173-jpgdec",
> - .data = NULL,
> + .data = (void *)MTK_JPEG_DEC,
> },
> {
> .compatible = "mediatek,mt2701-jpgdec",
> - .data = NULL,
> + .data = (void *)MTK_JPEG_DEC,
> + },
> + {
> + .compatible = "mediatek,mtk-jpgenc",
> + .data = (void *)MTK_JPEG_ENC,
> },
> {},
> };
The g/s_selection ioctls are unchanged: that can't be right.
The decoder supports composing, but that's not valid for an encoder:
I expect cropping support for an encoder.
Regards,
Hans
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 30+ messages in thread