Re: [PATCH 3/5] media: platform: Add jpeg enc feature

2019-08-12 Thread Hans Verkuil
Hi Xia,

Some review comments below:

On 7/17/19 11:30 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.
> add EXIF enable control for jpeg encode.
> 
> Change-Id: I38bf86a372f69d42a4680c4d772b64a30e81d7be

Please don't include Change-Id tags, these do not belong in the kernel repo.

> Signed-off-by: Xia Jiang 
> ---
>  drivers/media/platform/mtk-jpeg/Makefile  |   5 +-
>  .../media/platform/mtk-jpeg/mtk_jpeg_core.c   | 740 ++
>  .../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 ++
>  drivers/media/v4l2-core/v4l2-ctrls.c  |   1 +
>  include/uapi/linux/v4l2-controls.h|   2 +
>  9 files changed, 986 insertions(+), 167 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 994fcd66069c..c2d7774e59fb 100644
> --- a/drivers/media/platform/mtk-jpeg/Makefile
> +++ b/drivers/media/platform/mtk-jpeg/Makefile
> @@ -1,2 +1,5 @@
> -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 49e3b5284006..b2d6537e8c34 100644
> --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> @@ -2,6 +2,7 @@
>   * Copyright (c) 2016 MediaTek Inc.
>   * Author: Ming Hsiu Tsai 
>   * Rick Chang 
> + * Xia Jiang 
>   *
>   * This program is free software; you can redistribute it and/or modify
>   * it under the terms of the GNU General Public License version 2 as
> @@ -31,6 +32,7 @@
>  #include 
>  #include 
>  
> +#include "mtk_jpeg_enc_hw.h"
>  #include "mtk_jpeg_dec_hw.h"
>  #include "mtk_jpeg_core.h"
>  #include "mtk_jpeg_dec_parse.h"
> @@ -39,7 +41,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,
> @@ -59,6 +62,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)
> @@ -73,11 +112,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 

[PATCH 3/5] media: platform: Add jpeg enc feature

2019-07-17 Thread Xia Jiang
Add mtk jpeg encode v4l2 driver based on jpeg decode, because that jpeg
decode and encode have great similarities with function operation.
add EXIF enable control for jpeg encode.

Change-Id: I38bf86a372f69d42a4680c4d772b64a30e81d7be
Signed-off-by: Xia Jiang 
---
 drivers/media/platform/mtk-jpeg/Makefile  |   5 +-
 .../media/platform/mtk-jpeg/mtk_jpeg_core.c   | 740 ++
 .../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 ++
 drivers/media/v4l2-core/v4l2-ctrls.c  |   1 +
 include/uapi/linux/v4l2-controls.h|   2 +
 9 files changed, 986 insertions(+), 167 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 994fcd66069c..c2d7774e59fb 100644
--- a/drivers/media/platform/mtk-jpeg/Makefile
+++ b/drivers/media/platform/mtk-jpeg/Makefile
@@ -1,2 +1,5 @@
-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 49e3b5284006..b2d6537e8c34 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2016 MediaTek Inc.
  * Author: Ming Hsiu Tsai 
  * Rick Chang 
+ * Xia Jiang 
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -31,6 +32,7 @@
 #include 
 #include 
 
+#include "mtk_jpeg_enc_hw.h"
 #include "mtk_jpeg_dec_hw.h"
 #include "mtk_jpeg_core.h"
 #include "mtk_jpeg_dec_parse.h"
@@ -39,7 +41,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,
@@ -59,6 +62,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)
@@ -73,11 +112,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);
@@ -94,10 +141,81 @@ static int mtk_jpeg_querycap(struct file *file, void *priv,
 {
struct 

[PATCH 3/5] media: platform: Add jpeg enc feature

2019-07-08 Thread Xia Jiang
Add mtk jpeg encode v4l2 driver based on jpeg decode, because that jpeg
decode and encode have great similarities with function operation.
add EXIF enable control for jpeg encode.

Signed-off-by: Xia Jiang 
---
 drivers/media/platform/mtk-jpeg/Makefile  |   5 +-
 .../media/platform/mtk-jpeg/mtk_jpeg_core.c   | 733 ++
 .../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 ++
 drivers/media/v4l2-core/v4l2-ctrls.c  |   1 +
 include/uapi/linux/v4l2-controls.h|   2 +
 9 files changed, 979 insertions(+), 167 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 994fcd66069c..c2d7774e59fb 100644
--- a/drivers/media/platform/mtk-jpeg/Makefile
+++ b/drivers/media/platform/mtk-jpeg/Makefile
@@ -1,2 +1,5 @@
-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 49e3b5284006..ef54802bd813 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -2,6 +2,7 @@
  * Copyright (c) 2016 MediaTek Inc.
  * Author: Ming Hsiu Tsai 
  * Rick Chang 
+ * Xia Jiang 
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -31,6 +32,7 @@
 #include 
 #include 
 
+#include "mtk_jpeg_enc_hw.h"
 #include "mtk_jpeg_dec_hw.h"
 #include "mtk_jpeg_core.h"
 #include "mtk_jpeg_dec_parse.h"
@@ -39,7 +41,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,
@@ -59,6 +62,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)
@@ -73,11 +112,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);
@@ -94,10 +141,81 @@ static int mtk_jpeg_querycap(struct file *file, void *priv,
 {
struct mtk_jpeg_dev *jpeg = video_drvdata(file);
 
-