Add support for Exynos4x12 device to the s5p-jpeg driver
Subsystems (2)
v3 cover Add support for Exynos4x12 device to the s5p-jpeg driver
This is the third version of the series that adds support for the Exynos4x12 device to the s5p_jpeg driver. It includes following changes (Mauro - thanks for the review):
- renamed all occurrences of "exynos" to more precise "exynos4"
- added "s5p" and "exynos4" prefixes to the HW API functions
Thanks,
Jacek Anaszewski
Jacek Anaszewski (8):
s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c
s5p-jpeg: Add hardware API for the exynos4x12 JPEG codec.
s5p-jpeg: Retrieve "YCbCr subsampling" field from the jpeg header
s5p-jpeg: Ensure correct capture format for Exynos4x12
s5p-jpeg: Allow for wider JPEG subsampling scope for Exynos4x12
encoder
s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value
s5p-jpeg: Ensure setting correct value of the chroma subsampling
control
s5p-jpeg: Adjust g_volatile_ctrl callback to Exynos4x12 needs
drivers/media/platform/s5p-jpeg/Makefile | 2 +-
drivers/media/platform/s5p-jpeg/jpeg-core.c | 946 +++++++++++++++++---
drivers/media/platform/s5p-jpeg/jpeg-core.h | 67 +-
drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c | 279 ++++++
drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h | 42 +
.../platform/s5p-jpeg/{jpeg-hw.h => jpeg-hw-s5p.c} | 82 +-
drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h | 63 ++
drivers/media/platform/s5p-jpeg/jpeg-regs.h | 209 ++++-
8 files changed, 1490 insertions(+), 200 deletions(-)
create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c
create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h
rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h => jpeg-hw-s5p.c} (70%)
create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.hSignature · 1 line
1.7.9.5
PATCH v3 1/8 s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c
Move function definitions from jpeg-hw.h to jpeg-hw-s5p.c, add "s5p" prefix and put function declarations in the jpeg-hw-s5p.h.
---
drivers/media/platform/s5p-jpeg/Makefile | 2 +-
drivers/media/platform/s5p-jpeg/jpeg-core.c | 99 ++++++++++----------
drivers/media/platform/s5p-jpeg/jpeg-core.h | 5 +
.../platform/s5p-jpeg/{jpeg-hw.h => jpeg-hw-s5p.c} | 82 +++++++---------
drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h | 63 +++++++++++++
5 files changed, 154 insertions(+), 97 deletions(-)
rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h => jpeg-hw-s5p.c} (70%)
create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.hdrivers/media/platform/s5p-jpeg/Makefile +1 -1
@@ -1,2 +1,2 @@ -s5p-jpeg-objs := jpeg-core.o +s5p-jpeg-objs := jpeg-core.o jpeg-hw-s5p.o obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG) += s5p-jpeg.o
drivers/media/platform/s5p-jpeg/jpeg-core.c +51 -48
155 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-core.h +5 -0
@@ -42,10 +42,15 @@#define EOI 0xd9#define DHP 0xde +#define S5P_JPEG_ENCODE 0 +#define S5P_JPEG_DECODE 1 +/* Flags that indicate a format can be used for capture/output */ #define MEM2MEM_CAPTURE (1 << 0)#define MEM2MEM_OUTPUT (1 << 1) + +/** * struct s5p_jpeg - JPEG IP abstraction * @lock: the mutex protecting this structure
drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.c renamed from drivers/media/platform/s5p-jpeg/jpeg-hw.h +34 -48
269 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 2/8 s5p-jpeg: Add hardware API for the exynos4x12 JPEG codec.
In reply to Jacek Anaszewski--- drivers/media/platform/s5p-jpeg/Makefile | 2 +- drivers/media/platform/s5p-jpeg/jpeg-core.c | 621 ++++++++++++++++++--- drivers/media/platform/s5p-jpeg/jpeg-core.h | 64 ++- drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c | 279 +++++++++ drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h | 42 ++ drivers/media/platform/s5p-jpeg/jpeg-regs.h | 209 ++++++- 6 files changed, 1123 insertions(+), 94 deletions(-) create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h
drivers/media/platform/s5p-jpeg/Makefile +1 -1
@@ -1,2 +1,2 @@ -s5p-jpeg-objs := jpeg-core.o jpeg-hw-s5p.o +s5p-jpeg-objs := jpeg-core.o jpeg-hw-exynos4.o jpeg-hw-s5p.o obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG) += s5p-jpeg.o
drivers/media/platform/s5p-jpeg/jpeg-core.c +534 -87
869 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-core.h +59 -5
108 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c new file +279 -0
279 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h new file +42 -0
42 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-regs.h +208 -1
229 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 3/8 s5p-jpeg: Retrieve "YCbCr subsampling" field from the jpeg header
In reply to Jacek AnaszewskiMake s5p_jpeg_parse_hdr function capable of parsing "YCbCr subsampling" field of a jpeg file header. Store the parsed value in the context. The information about source JPEG subsampling is required to make validation of destination format possible, which must be conducted for exynos4x12 device as the decoding process will not succeed if the destination format is set to YUV with subsampling lower than the one of the source JPEG image. With this knowledge the driver can adjust the destination format appropriately.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 35 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +31 -4
@@ -624,10 +624,11 @@ static void skip(struct s5p_jpeg_buffer *buf, long len) }static bool s5p_jpeg_parse_hdr (struct s5p_jpeg_q_data *result, -unsigned long buffer,unsigned long size) +unsigned long buffer,unsigned long size, +struct s5p_jpeg_ctx *ctx) {int c, components, notfound; -unsigned int height, width, word; +unsigned int height, width, word, subsampling =0 ;long length;struct s5p_jpeg_buffer jpeg_buffer;
@@ -666,7 +667,15 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result,break ; notfound =0 ; -skip (&jpeg_buffer, components *3 ); +if (components ==1 ) { + subsampling =0x33 ; + }else { +skip (&jpeg_buffer,1 ); + subsampling =get_byte (&jpeg_buffer); +skip (&jpeg_buffer,1 ); + } + +skip (&jpeg_buffer, components *2 );break ;/* skip payload-less markers */
@@ -688,6 +697,24 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result, result->w = width; result->h = height; result->size = components; + +switch (subsampling) { +case 0x11 : + ctx->subsampling =V4L2_JPEG_CHROMA_SUBSAMPLING_444 ; +break ; +case 0x21 : + ctx->subsampling =V4L2_JPEG_CHROMA_SUBSAMPLING_422 ; +break ; +case 0x22 : + ctx->subsampling =V4L2_JPEG_CHROMA_SUBSAMPLING_420 ; +break ; +case 0x33 : + ctx->subsampling =V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY ; +break ; +default : +return false; + } +return !notfound; }
@@ -1438,7 +1465,7 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb) ctx->hdr_parsed =s5p_jpeg_parse_hdr (&tmp, (unsigned long )vb2_plane_vaddr (vb,0 ),min ((unsigned long )ctx->out_q.size, -vb2_get_plane_payload (vb,0 ))); +vb2_get_plane_payload (vb,0 )), ctx);if (!ctx->hdr_parsed) {vb2_buffer_done (vb,VB2_BUF_STATE_ERROR );return ;
Signature · 1 line
1.7.9.5
PATCH v3 4/8 s5p-jpeg: Ensure correct capture format for Exynos4x12
In reply to Jacek AnaszewskiAdjust capture format to the Exynos4x12 device limitations, according to the subsampling value parsed from the source JPEG image header. If the capture format was set to YUV with subsampling lower than the one of the source JPEG image the decoding process would not succeed.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 116 +++++++++++++++++++++++++++ 1 file changed, 116 insertions(+)
drivers/media/platform/s5p-jpeg/jpeg-core.c +116 -0
@@ -358,6 +358,99 @@ static const unsigned char hactblg0[162] = {0xf9 ,0xfa }; +/* +* Fourcc downgrade schema lookup tables for 422 and 420 +* chroma subsampling - fourcc on each position maps on the +* fourcc from the table fourcc_to_dwngrd_schema_id which allows +* to get the most suitable fourcc counterpart for the given +* downgraded subsampling property. +*/ +static const u32 subs422_fourcc_dwngrd_schema[] = { +V4L2_PIX_FMT_NV16 , +V4L2_PIX_FMT_NV61 , +}; + +static const u32 subs420_fourcc_dwngrd_schema[] = { +V4L2_PIX_FMT_NV12 , +V4L2_PIX_FMT_NV21 , +V4L2_PIX_FMT_NV12 , +V4L2_PIX_FMT_NV21 , +V4L2_PIX_FMT_NV12 , +V4L2_PIX_FMT_NV21 , +V4L2_PIX_FMT_GREY , +V4L2_PIX_FMT_GREY , +V4L2_PIX_FMT_GREY , +V4L2_PIX_FMT_GREY , +}; + +/* +* Lookup table for translation of a fourcc to the position +* of its downgraded counterpart in the *fourcc_dwngrd_schema +* tables. +*/ +static const u32 fourcc_to_dwngrd_schema_id[] = { +V4L2_PIX_FMT_NV24 , +V4L2_PIX_FMT_NV42 , +V4L2_PIX_FMT_NV16 , +V4L2_PIX_FMT_NV61 , +V4L2_PIX_FMT_YUYV , +V4L2_PIX_FMT_YVYU , +V4L2_PIX_FMT_NV12 , +V4L2_PIX_FMT_NV21 , +V4L2_PIX_FMT_YUV420 , +V4L2_PIX_FMT_GREY , +}; + +static int s5p_jpeg_get_dwngrd_sch_id_by_fourcc (u32 fourcc) +{ +int i; +for (i =0 ; i <ARRAY_SIZE (fourcc_to_dwngrd_schema_id); ++i) { +if (fourcc_to_dwngrd_schema_id[i] == fourcc) +return i; + } + +return -EINVAL ; +} + +static int s5p_jpeg_adjust_fourcc_to_subsampling ( +enum v4l2_jpeg_chroma_subsampling subs, +u32 in_fourcc, +u32 *out_fourcc, +struct s5p_jpeg_ctx *ctx) +{ +int dwngrd_sch_id; + +if (ctx->subsampling !=V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY ) { + dwngrd_sch_id = +s5p_jpeg_get_dwngrd_sch_id_by_fourcc (in_fourcc); +if (dwngrd_sch_id <0 ) +return -EINVAL ; + } + +switch (ctx->subsampling) { +case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY : + *out_fourcc =V4L2_PIX_FMT_GREY ; +break ; +case V4L2_JPEG_CHROMA_SUBSAMPLING_420 : +if (dwngrd_sch_id > +ARRAY_SIZE (subs420_fourcc_dwngrd_schema) -1 ) +return -EINVAL ; + *out_fourcc = subs420_fourcc_dwngrd_schema[dwngrd_sch_id]; +break ; +case V4L2_JPEG_CHROMA_SUBSAMPLING_422 : +if (dwngrd_sch_id > +ARRAY_SIZE (subs422_fourcc_dwngrd_schema) -1 ) +return -EINVAL ; + *out_fourcc = subs422_fourcc_dwngrd_schema[dwngrd_sch_id]; +break ; +default : + *out_fourcc =V4L2_PIX_FMT_GREY ; +break ; + } + +return 0 ; +} +static inline struct s5p_jpeg_ctx *ctrl_to_ctx (struct v4l2_ctrl *c) { return container_of(c->handler, struct s5p_jpeg_ctx, ctrl_handler);
@@ -941,7 +1034,9 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) {struct s5p_jpeg_ctx *ctx =fh_to_ctx (priv); +struct v4l2_pix_format *pix = &f->fmt.pix;struct s5p_jpeg_fmt *fmt; +int ret; fmt =s5p_jpeg_find_format (ctx, f->fmt.pix.pixelformat,FMT_TYPE_CAPTURE );
@@ -952,6 +1047,27 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, void *priv,return -EINVAL ; } +/* +* The exynos4x12 device requires resulting YUV image +* subsampling not to be lower than the input jpeg subsampling. +* If this requirement is not met then downgrade the requested +* capture format to the one with subsampling equal to the input jpeg. +*/ +if ((ctx->jpeg->variant->version !=SJPEG_S5P ) && + (ctx->mode ==S5P_JPEG_DECODE ) && + (fmt->flags &SJPEG_FMT_NON_RGB ) && + (fmt->subsampling < ctx->subsampling)) { + ret =s5p_jpeg_adjust_fourcc_to_subsampling (ctx->subsampling, + fmt->fourcc, + &pix->pixelformat, + ctx); +if (ret <0 ) + pix->pixelformat =V4L2_PIX_FMT_GREY ; + + fmt =s5p_jpeg_find_format (ctx, pix->pixelformat, +FMT_TYPE_CAPTURE ); + } +return vidioc_try_fmt (f, fmt, ctx,FMT_TYPE_CAPTURE ); }
Signature · 1 line
1.7.9.5
PATCH v3 5/8 s5p-jpeg: Allow for wider JPEG subsampling scope for Exynos4x12 encoder
In reply to Jacek AnaszewskiExynos4x12 supports wider scope of subsampling modes than S5PC210. Adjust corresponding mask accordingly.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +2 -1
@@ -1249,7 +1249,8 @@ static int s5p_jpeg_controls_create(struct s5p_jpeg_ctx *ctx)v4l2_ctrl_new_std (&ctx->ctrl_handler, &s5p_jpeg_ctrl_ops,V4L2_CID_JPEG_RESTART_INTERVAL ,0 ,3 ,0xffff ,0 ); - mask = ~0x06 ;/* 422, 420 */ +if (ctx->jpeg->variant->version ==SJPEG_S5P ) + mask = ~0x06 ;/* 422, 420 */ } ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &s5p_jpeg_ctrl_ops,
Signature · 1 line
1.7.9.5
PATCH v3 6/8 s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value
In reply to Jacek AnaszewskiWhen output queue fourcc is set to any flavour of YUV, the V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value as well as its in-driver cached counterpart have to be updated with the subsampling property of the format so as to be able to provide correct information to the user space and preclude setting an illegal subsampling mode for Exynos4x12 encoder.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/platform/s5p-jpeg/jpeg-core.c +8 -0
@@ -1094,6 +1094,7 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, struct v4l2_format *f)struct vb2_queue *vq;struct s5p_jpeg_q_data *q_data =NULL ;struct v4l2_pix_format *pix = &f->fmt.pix; +struct v4l2_ctrl *ctrl_subs;unsigned int f_type; vq =v4l2_m2m_get_vq (ct->fh.m2m_ctx, f->type);
@@ -1119,6 +1120,13 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, struct v4l2_format *f)else q_data->size = pix->sizeimage; +if (f_type ==FMT_TYPE_OUTPUT ) { + ctrl_subs =v4l2_ctrl_find (&ct->ctrl_handler, +V4L2_CID_JPEG_CHROMA_SUBSAMPLING ); +if (ctrl_subs) +v4l2_ctrl_s_ctrl (ctrl_subs, q_data->fmt->subsampling); + } +return 0 ; }
Signature · 1 line
1.7.9.5
PATCH v3 7/8 s5p-jpeg: Ensure setting correct value of the chroma subsampling control
In reply to Jacek AnaszewskiExynos4x12 has limitations regarding setting chroma subsampling of an output JPEG image. It cannot be lower than the subsampling of the raw source image. Also in case of V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY option the source image fourcc has to be V4L2_PIX_FMT_GREY. This patch implements try_ctrl callback containing mechanism that prevents setting invalid value of the V4L2_CID_JPEG_CHROMA_SUBSAMPLING control.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
drivers/media/platform/s5p-jpeg/jpeg-core.c +35 -0
@@ -1213,6 +1213,40 @@ static int s5p_jpeg_g_volatile_ctrl(struct v4l2_ctrl *ctrl)return 0 ; } +static int s5p_jpeg_try_ctrl (struct v4l2_ctrl *ctrl) +{ +struct s5p_jpeg_ctx *ctx =ctrl_to_ctx (ctrl); +unsigned long flags; +int ret =0 ; + +spin_lock_irqsave (&ctx->jpeg->slock, flags); + +if (ctrl->id ==V4L2_CID_JPEG_CHROMA_SUBSAMPLING ) { +if (ctx->jpeg->variant->version ==SJPEG_S5P ) + goto error_free; +/* +* The exynos4x12 device requires input raw image fourcc +* to be V4L2_PIX_FMT_GREY if gray jpeg format +* is to be set. +*/ +if (ctx->out_q.fmt->fourcc !=V4L2_PIX_FMT_GREY && + ctrl->val ==V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY ) { + ret = -EINVAL ; + goto error_free; + } +/* +* The exynos4x12 device requires resulting jpeg subsampling +* not to be lower than the input raw image subsampling. +*/ +if (ctx->out_q.fmt->subsampling > ctrl->val) + ctrl->val = ctx->out_q.fmt->subsampling; + } + +error_free: +spin_unlock_irqrestore (&ctx->jpeg->slock, flags); +return ret; +} +static int s5p_jpeg_s_ctrl (struct v4l2_ctrl *ctrl) {struct s5p_jpeg_ctx *ctx =ctrl_to_ctx (ctrl);
@@ -1238,6 +1272,7 @@ static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)static const struct v4l2_ctrl_ops s5p_jpeg_ctrl_ops = { .g_volatile_ctrl = s5p_jpeg_g_volatile_ctrl, + .try_ctrl = s5p_jpeg_try_ctrl, .s_ctrl = s5p_jpeg_s_ctrl, };
Signature · 1 line
1.7.9.5
PATCH v3 8/8 s5p-jpeg: Adjust g_volatile_ctrl callback to Exynos4x12 needs
In reply to Jacek AnaszewskiWhereas S5PC210 device produces decoded JPEG subsampling values that map on V4L2_JPEG_CHROMA_SUBSAMPLNG values, the Exynos4x12 device doesn't. This patch adds helper function s5p_jpeg_to_user_subsampling, which performs suitable translation.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +23 -6
@@ -451,6 +451,13 @@ static int s5p_jpeg_adjust_fourcc_to_subsampling(return 0 ; } +static int exynos4x12_decoded_subsampling[] = { +V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY , +V4L2_JPEG_CHROMA_SUBSAMPLING_444 , +V4L2_JPEG_CHROMA_SUBSAMPLING_422 , +V4L2_JPEG_CHROMA_SUBSAMPLING_420 , +}; +static inline struct s5p_jpeg_ctx *ctrl_to_ctx (struct v4l2_ctrl *c) { return container_of(c->handler, struct s5p_jpeg_ctx, ctrl_handler);
@@ -461,6 +468,21 @@ static inline struct s5p_jpeg_ctx *fh_to_ctx(struct v4l2_fh *fh) return container_of(fh, struct s5p_jpeg_ctx, fh); } +static int s5p_jpeg_to_user_subsampling (struct s5p_jpeg_ctx *ctx) +{ +WARN_ON (ctx->subsampling >3 ); + +if (ctx->jpeg->variant->version ==SJPEG_S5P ) { +if (ctx->subsampling >2 ) +return V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY ; +return ctx->subsampling; + }else { +if (ctx->subsampling >2 ) +return V4L2_JPEG_CHROMA_SUBSAMPLING_420 ; +return exynos4x12_decoded_subsampling[ctx->subsampling]; + } +} +static inline void s5p_jpeg_set_qtbl (void __iomem *regs,const unsigned char *qtbl,unsigned long tab,int len)
@@ -1200,12 +1222,7 @@ static int s5p_jpeg_g_volatile_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case V4L2_CID_JPEG_CHROMA_SUBSAMPLING :spin_lock_irqsave (&jpeg->slock, flags); - -WARN_ON (ctx->subsampling >S5P_SUBSAMPLING_MODE_GRAY ); -if (ctx->subsampling >2 ) - ctrl->val =V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY ; -else - ctrl->val = ctx->subsampling; + ctrl->val =s5p_jpeg_to_user_subsampling (ctx);spin_unlock_irqrestore (&jpeg->slock, flags);break ; }
Signature · 1 line
1.7.9.5