Add support for Exynox4x12 to the s5p-jpeg driver
Subsystems (2)
cover Add support for Exynox4x12 to the s5p-jpeg driver
The main aim of this series is to add support for Exynos4x12 SoC for the s5p-jpeg driver. Nonetheless, a room for couple of fixes and improvements has been found during development, which is reflected in the corresponding patches.
Thanks,
Jacek Anaszewski
Jacek Anaszewski (16):
s5p-jpeg: Reorder quantization tables
s5p-jpeg: Fix output YUV 4:2:0 fourcc for decoder
s5p-jpeg: Fix erroneous condition while validating bytesperline value
s5p-jpeg: Remove superfluous call to the jpeg_bound_align_image
function
s5p-jpeg: Rename functions specific to the S5PC210 SoC accordingly
s5p-jpeg: Fix clock resource management
s5p-jpeg: Fix lack of spin_lock protection
s5p-jpeg: Synchronize cached controls with V4L2 core
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 | 1049 ++++++++++++++++----
drivers/media/platform/s5p-jpeg/jpeg-core.h | 75 +-
drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c | 293 ++++++
drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h | 44 +
.../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 | 215 +++-
8 files changed, 1564 insertions(+), 259 deletions(-)
create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c
create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h
rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h => jpeg-hw-s5p.c} (71%)
create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.hSignature · 1 line
1.7.9.5
PATCH 1/16 s5p-jpeg: Reorder quantization tables
Reorder quantization tables so that their elements are arranged in the manner reflecting compression quality level that is in accordance with V4L2 documentation, i.e. the larger value of the V4L2_CID_JPEG_COMPRESSION_QUALITY control the better image quality, and thus lower compression quality. The modification allows also to get rid of reverse logic in the s_ctrl callback while assigning user space value to the ctx->compr_quality variable.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 116 +++++++++++++-------------- 1 file changed, 58 insertions(+), 58 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +58 -58
@@ -84,15 +84,25 @@ static struct s5p_jpeg_fmt formats_dec[] = {#define NUM_FORMATS_DEC ARRAY_SIZE(formats_dec)static const unsigned char qtbl_luminance[4 ][64 ] = { - {/* level 1 - high quality */ -8 ,6 ,6 ,8 ,12 ,14 ,16 ,17 , -6 ,6 ,6 ,8 ,10 ,13 ,12 ,15 , -6 ,6 ,7 ,8 ,13 ,14 ,18 ,24 , -8 ,8 ,8 ,14 ,13 ,19 ,24 ,35 , -12 ,10 ,13 ,13 ,20 ,26 ,34 ,39 , -14 ,13 ,14 ,19 ,26 ,34 ,39 ,39 , -16 ,12 ,18 ,24 ,34 ,39 ,39 ,39 , -17 ,15 ,24 ,35 ,39 ,39 ,39 ,39 + {/*level 0 - high compression quality */ +20 ,16 ,25 ,39 ,50 ,46 ,62 ,68 , +16 ,18 ,23 ,38 ,38 ,53 ,65 ,68 , +25 ,23 ,31 ,38 ,53 ,65 ,68 ,68 , +39 ,38 ,38 ,53 ,65 ,68 ,68 ,68 , +50 ,38 ,53 ,65 ,68 ,68 ,68 ,68 , +46 ,53 ,65 ,68 ,68 ,68 ,68 ,68 , +62 ,65 ,68 ,68 ,68 ,68 ,68 ,68 , +68 ,68 ,68 ,68 ,68 ,68 ,68 ,68 + }, + {/* level 1 */ +16 ,11 ,11 ,16 ,23 ,27 ,31 ,30 , +11 ,12 ,12 ,15 ,20 ,23 ,23 ,30 , +11 ,12 ,13 ,16 ,23 ,26 ,35 ,47 , +16 ,15 ,16 ,23 ,26 ,37 ,47 ,64 , +23 ,20 ,23 ,26 ,39 ,51 ,64 ,64 , +27 ,23 ,26 ,37 ,51 ,64 ,64 ,64 , +31 ,23 ,35 ,47 ,64 ,64 ,64 ,64 , +30 ,30 ,47 ,64 ,64 ,64 ,64 ,64 }, {/* level 2 */ 12 ,8 ,8 ,12 ,17 ,21 ,24 ,23 ,
@@ -104,38 +114,38 @@ static const unsigned char qtbl_luminance[4][64] = { 24, 18, 27, 36, 51, 59, 59, 59, 23, 23, 36, 53, 59, 59, 59, 59 }, - {/* level 3 */ - 16, 11, 11, 16, 23, 27, 31, 30, - 11, 12, 12, 15, 20, 23, 23, 30, - 11, 12, 13, 16, 23, 26, 35, 47, - 16, 15, 16, 23, 26, 37, 47, 64, - 23, 20, 23, 26, 39, 51, 64, 64, - 27, 23, 26, 37, 51, 64, 64, 64, - 31, 23, 35, 47, 64, 64, 64, 64, - 30, 30, 47, 64, 64, 64, 64, 64 - }, - {/*level 4 - low quality */ - 20, 16, 25, 39, 50, 46, 62, 68, - 16, 18, 23, 38, 38, 53, 65, 68, - 25, 23, 31, 38, 53, 65, 68, 68, - 39, 38, 38, 53, 65, 68, 68, 68, - 50, 38, 53, 65, 68, 68, 68, 68, - 46, 53, 65, 68, 68, 68, 68, 68, - 62, 65, 68, 68, 68, 68, 68, 68, - 68, 68, 68, 68, 68, 68, 68, 68 + {/* level 3 - low compression quality */ + 8, 6, 6, 8, 12, 14, 16, 17, + 6, 6, 6, 8, 10, 13, 12, 15, + 6, 6, 7, 8, 13, 14, 18, 24, + 8, 8, 8, 14, 13, 19, 24, 35, + 12, 10, 13, 13, 20, 26, 34, 39, + 14, 13, 14, 19, 26, 34, 39, 39, + 16, 12, 18, 24, 34, 39, 39, 39, + 17, 15, 24, 35, 39, 39, 39, 39 } }; static const unsigned char qtbl_chrominance[4][64] = { - {/* level 1 - high quality */ - 9, 8, 9, 11, 14, 17, 19, 24, - 8, 10, 9, 11, 14, 13, 17, 22, - 9, 9, 13, 14, 13, 15, 23, 26, - 11, 11, 14, 14, 15, 20, 26, 33, - 14, 14, 13, 15, 20, 24, 33, 39, - 17, 13, 15, 20, 24, 32, 39, 39, - 19, 17, 23, 26, 33, 39, 39, 39, - 24, 22, 26, 33, 39, 39, 39, 39 + {/*level 0 - high compression quality */ + 21, 25, 32, 38, 54, 68, 68, 68, + 25, 28, 24, 38, 54, 68, 68, 68, + 32, 24, 32, 43, 66, 68, 68, 68, + 38, 38, 43, 53, 68, 68, 68, 68, + 54, 54, 66, 68, 68, 68, 68, 68, + 68, 68, 68, 68, 68, 68, 68, 68, + 68, 68, 68, 68, 68, 68, 68, 68, + 68, 68, 68, 68, 68, 68, 68, 68 + }, + {/* level 1 */ + 17, 15, 17, 21, 20, 26, 38, 48, + 15, 19, 18, 17, 20, 26, 35, 43, + 17, 18, 20, 22, 26, 30, 46, 53, + 21, 17, 22, 28, 30, 39, 53, 64, + 20, 20, 26, 30, 39, 48, 64, 64, + 26, 26, 30, 39, 48, 63, 64, 64, + 38, 35, 46, 53, 64, 64, 64, 64, + 48, 43, 53, 64, 64, 64, 64, 64 }, {/* level 2 */ 13, 11, 13, 16, 20, 20, 29, 37,
@@ -147,25 +157,15 @@ static const unsigned char qtbl_chrominance[4][64] = { 29, 26, 35, 40, 50, 59, 59, 59, 37, 32, 40, 50, 59, 59, 59, 59 }, - {/* level 3 */ -17 ,15 ,17 ,21 ,20 ,26 ,38 ,48 , -15 ,19 ,18 ,17 ,20 ,26 ,35 ,43 , -17 ,18 ,20 ,22 ,26 ,30 ,46 ,53 , -21 ,17 ,22 ,28 ,30 ,39 ,53 ,64 , -20 ,20 ,26 ,30 ,39 ,48 ,64 ,64 , -26 ,26 ,30 ,39 ,48 ,63 ,64 ,64 , -38 ,35 ,46 ,53 ,64 ,64 ,64 ,64 , -48 ,43 ,53 ,64 ,64 ,64 ,64 ,64 - }, - {/*level 4 - low quality */ -21 ,25 ,32 ,38 ,54 ,68 ,68 ,68 , -25 ,28 ,24 ,38 ,54 ,68 ,68 ,68 , -32 ,24 ,32 ,43 ,66 ,68 ,68 ,68 , -38 ,38 ,43 ,53 ,68 ,68 ,68 ,68 , -54 ,54 ,66 ,68 ,68 ,68 ,68 ,68 , -68 ,68 ,68 ,68 ,68 ,68 ,68 ,68 , -68 ,68 ,68 ,68 ,68 ,68 ,68 ,68 , -68 ,68 ,68 ,68 ,68 ,68 ,68 ,68 + {/* level 3 - low compression quality */ +9 ,8 ,9 ,11 ,14 ,17 ,19 ,24 , +8 ,10 ,9 ,11 ,14 ,13 ,17 ,22 , +9 ,9 ,13 ,14 ,13 ,15 ,23 ,26 , +11 ,11 ,14 ,14 ,15 ,20 ,26 ,33 , +14 ,14 ,13 ,15 ,20 ,24 ,33 ,39 , +17 ,13 ,15 ,20 ,24 ,32 ,39 ,39 , +19 ,17 ,23 ,26 ,33 ,39 ,39 ,39 , +24 ,22 ,26 ,33 ,39 ,39 ,39 ,39 } };
@@ -834,7 +834,7 @@ static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case V4L2_CID_JPEG_COMPRESSION_QUALITY : - ctx->compr_quality =S5P_JPEG_COMPR_QUAL_WORST - ctrl->val; + ctx->compr_quality = ctrl->val;break ;case V4L2_CID_JPEG_RESTART_INTERVAL : ctx->restart_interval = ctrl->val;
@@ -863,7 +863,7 @@ static int s5p_jpeg_controls_create(struct s5p_jpeg_ctx *ctx)if (ctx->mode ==S5P_JPEG_ENCODE ) {v4l2_ctrl_new_std (&ctx->ctrl_handler, &s5p_jpeg_ctrl_ops,V4L2_CID_JPEG_COMPRESSION_QUALITY , -0 ,3 ,1 ,3 ); +0 ,3 ,1 ,S5P_JPEG_COMPR_QUAL_WORST ); v4l2_ctrl_new_std(&ctx->ctrl_handler, &s5p_jpeg_ctrl_ops, V4L2_CID_JPEG_RESTART_INTERVAL,
Signature · 1 line
1.7.9.5
PATCH 2/16 s5p-jpeg: Fix output YUV 4:2:0 fourcc for decoder
In reply to Jacek AnaszewskiOutput samples during decoding phase for the YUV 4:2:0 format are arranged in the manner compatible with 2-planar NV12, not 3-planar YUV420 fourcc.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +1 -1
@@ -58,7 +58,7 @@ static struct s5p_jpeg_fmt formats_enc[] = {static struct s5p_jpeg_fmt formats_dec[] = { { .name ="YUV 4:2:0 planar, YCbCr" , - .fourcc =V4L2_PIX_FMT_YUV420 , + .fourcc =V4L2_PIX_FMT_NV12 , .depth =12 , .colplanes =3 , .h_align =4 ,
Signature · 1 line
1.7.9.5
PATCH 3/16 s5p-jpeg: Fix erroneous condition while validating bytesperline value
In reply to Jacek AnaszewskiThe aim of the condition is ensuring that the bytesperline value set by the user space application is proper for the given format and adjusting it if isn't. As the depth value of the format description entry is expressed in bits then the bytesperline value needs to be divided, not multiplied, by that value to get the number of bytes required to store single line of image samples.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +1 -1
@@ -670,7 +670,7 @@ static int vidioc_try_fmt(struct v4l2_format *f, struct s5p_jpeg_fmt *fmt, bpl = pix->width;/* planar */ if (fmt->colplanes ==1 &&/* packed */ - (bpl <<3 ) * fmt->depth < pix->width) + (bpl <<3 ) / fmt->depth < pix->width) bpl = (pix->width * fmt->depth) >>3 ; pix->bytesperline = bpl;
Signature · 1 line
1.7.9.5
PATCH 4/16 s5p-jpeg: Remove superfluous call to the jpeg_bound_align_image function
In reply to Jacek AnaszewskiAligning capture queue image dimensions while enqueuing output queue doesn't make a sense as the S_FMT ioctl might have not been called for the capture queue until that moment, whereas it is required to know capture format as the type of alignment heavily depends on it.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +0 -7
@@ -1089,13 +1089,6 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb) q_data = &ctx->cap_q; q_data->w = tmp.w; q_data->h = tmp.h; - -jpeg_bound_align_image (&q_data->w,S5P_JPEG_MIN_WIDTH , -S5P_JPEG_MAX_WIDTH , q_data->fmt->h_align, - &q_data->h,S5P_JPEG_MIN_HEIGHT , -S5P_JPEG_MAX_HEIGHT , q_data->fmt->v_align - ); - q_data->size = q_data->w * q_data->h * q_data->fmt->depth >>3 ; }v4l2_m2m_buf_queue (ctx->fh.m2m_ctx, vb);
Signature · 1 line
1.7.9.5
PATCH 5/16 s5p-jpeg: Rename functions specific to the S5PC210 SoC accordingly
In reply to Jacek Anaszewski--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 58 ++++++++++++++++----------- 1 file changed, 34 insertions(+), 24 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +34 -24
@@ -213,8 +213,9 @@ static inline struct s5p_jpeg_ctx *fh_to_ctx(struct v4l2_fh *fh) return container_of(fh, struct s5p_jpeg_ctx, fh); } -static inline void jpeg_set_qtbl (void __iomem *regs,const unsigned char *qtbl, -unsigned long tab,int len) +static inline void s5p_jpeg_set_qtbl (void __iomem *regs, +const unsigned char *qtbl, +unsigned long tab,int len) {int i;
@@ -222,22 +223,25 @@ static inline void jpeg_set_qtbl(void __iomem *regs, const unsigned char *qtbl,writel ((unsigned int )qtbl[i], regs + tab + (i *0x04 )); } -static inline void jpeg_set_qtbl_lum (void __iomem *regs,int quality) +static inline void s5p_jpeg_set_qtbl_lum (void __iomem *regs,int quality) {/* this driver fills quantisation table 0 with data for luma */ -jpeg_set_qtbl (regs, qtbl_luminance[quality],S5P_JPG_QTBL_CONTENT (0 ), -ARRAY_SIZE (qtbl_luminance[quality])); +s5p_jpeg_set_qtbl (regs, qtbl_luminance[quality], +S5P_JPG_QTBL_CONTENT (0 ), +ARRAY_SIZE (qtbl_luminance[quality])); } -static inline void jpeg_set_qtbl_chr (void __iomem *regs,int quality) +static inline void s5p_jpeg_set_qtbl_chr (void __iomem *regs,int quality) {/* this driver fills quantisation table 1 with data for chroma */ -jpeg_set_qtbl (regs, qtbl_chrominance[quality],S5P_JPG_QTBL_CONTENT (1 ), -ARRAY_SIZE (qtbl_chrominance[quality])); +s5p_jpeg_set_qtbl (regs, qtbl_chrominance[quality], +S5P_JPG_QTBL_CONTENT (1 ), +ARRAY_SIZE (qtbl_chrominance[quality])); } -static inline void jpeg_set_htbl (void __iomem *regs,const unsigned char *htbl, -unsigned long tab,int len) +static inline void s5p_jpeg_set_htbl (void __iomem *regs, +const unsigned char *htbl, +unsigned long tab,int len) {int i;
@@ -245,28 +249,32 @@ static inline void jpeg_set_htbl(void __iomem *regs, const unsigned char *htbl,writel ((unsigned int )htbl[i], regs + tab + (i *0x04 )); } -static inline void jpeg_set_hdctbl (void __iomem *regs) +static inline void s5p_jpeg_set_hdctbl (void __iomem *regs) {/* this driver fills table 0 for this component */ -jpeg_set_htbl (regs, hdctbl0,S5P_JPG_HDCTBL (0 ),ARRAY_SIZE (hdctbl0)); +s5p_jpeg_set_htbl (regs, hdctbl0,S5P_JPG_HDCTBL (0 ), +ARRAY_SIZE (hdctbl0)); } -static inline void jpeg_set_hdctblg (void __iomem *regs) +static inline void s5p_jpeg_set_hdctblg (void __iomem *regs) {/* this driver fills table 0 for this component */ -jpeg_set_htbl (regs, hdctblg0,S5P_JPG_HDCTBLG (0 ),ARRAY_SIZE (hdctblg0)); +s5p_jpeg_set_htbl (regs, hdctblg0,S5P_JPG_HDCTBLG (0 ), +ARRAY_SIZE (hdctblg0)); } -static inline void jpeg_set_hactbl (void __iomem *regs) +static inline void s5p_jpeg_set_hactbl (void __iomem *regs) {/* this driver fills table 0 for this component */ -jpeg_set_htbl (regs, hactbl0,S5P_JPG_HACTBL (0 ),ARRAY_SIZE (hactbl0)); +s5p_jpeg_set_htbl (regs, hactbl0,S5P_JPG_HACTBL (0 ), +ARRAY_SIZE (hactbl0)); } -static inline void jpeg_set_hactblg (void __iomem *regs) +static inline void s5p_jpeg_set_hactblg (void __iomem *regs) {/* this driver fills table 0 for this component */ -jpeg_set_htbl (regs, hactblg0,S5P_JPG_HACTBLG (0 ),ARRAY_SIZE (hactblg0)); +s5p_jpeg_set_htbl (regs, hactblg0,S5P_JPG_HACTBLG (0 ), +ARRAY_SIZE (hactblg0)); }/*
@@ -962,8 +970,8 @@ static void s5p_jpeg_device_run(void *priv)* JPEG IP allows storing 4 quantization tables * We fill table 0 for luma and table 1 for chroma */ -jpeg_set_qtbl_lum (jpeg->regs, ctx->compr_quality); -jpeg_set_qtbl_chr (jpeg->regs, ctx->compr_quality); +s5p_jpeg_set_qtbl_lum (jpeg->regs, ctx->compr_quality); +s5p_jpeg_set_qtbl_chr (jpeg->regs, ctx->compr_quality);/* use table 0 for Y */ jpeg_qtbl (jpeg->regs,1 ,0 );/* use table 1 for Cb and Cr*/
@@ -1406,14 +1414,16 @@ static int s5p_jpeg_runtime_suspend(struct device *dev)static int s5p_jpeg_runtime_resume (struct device *dev) {struct s5p_jpeg *jpeg =dev_get_drvdata (dev); +/* * JPEG IP allows storing two Huffman tables for each component * We fill table 0 for each component */ -jpeg_set_hdctbl (jpeg->regs); -jpeg_set_hdctblg (jpeg->regs); -jpeg_set_hactbl (jpeg->regs); -jpeg_set_hactblg (jpeg->regs); +s5p_jpeg_set_hdctbl (jpeg->regs); +s5p_jpeg_set_hdctblg (jpeg->regs); +s5p_jpeg_set_hactbl (jpeg->regs); +s5p_jpeg_set_hactblg (jpeg->regs); +return 0 ; }
Signature · 1 line
1.7.9.5
PATCH 6/16 s5p-jpeg: Fix clock resource management
In reply to Jacek AnaszewskiStandard suspend/resume path is called after runtime resume of the given device, so suspend/resume callbacks must do all clock management done also by runtime pm to allow for proper power domain shutdown. Moreover, JPEG clock is enabled from probe function but is is not necessary. This patch also moves control of jpeg clock to runtime_pm callbacks.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 52 ++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +36 -16
@@ -1250,29 +1250,28 @@ static int s5p_jpeg_probe(struct platform_device *pdev)if (IS_ERR (jpeg->regs))return PTR_ERR (jpeg->regs); +/* clocks */ + jpeg->clk =clk_get (&pdev->dev,"jpeg" ); +if (IS_ERR (jpeg->clk)) { +dev_err (&pdev->dev,"cannot get clock\n" ); + ret =PTR_ERR (jpeg->clk); +return ret; + } +dev_dbg (&pdev->dev,"clock source %p\n" , jpeg->clk); +/* interrupt service routine registration */ jpeg->irq = ret =platform_get_irq (pdev,0 );if (ret <0 ) {dev_err (&pdev->dev,"cannot find IRQ\n" ); -return ret; + goto clk_get_rollback; } ret =devm_request_irq (&pdev->dev, jpeg->irq, s5p_jpeg_irq,0 ,dev_name (&pdev->dev), jpeg);if (ret) {dev_err (&pdev->dev,"cannot claim IRQ %d\n" , jpeg->irq); -return ret; - } - -/* clocks */ - jpeg->clk =clk_get (&pdev->dev,"jpeg" ); -if (IS_ERR (jpeg->clk)) { -dev_err (&pdev->dev,"cannot get clock\n" ); - ret =PTR_ERR (jpeg->clk); -return ret; + goto clk_get_rollback; } -dev_dbg (&pdev->dev,"clock source %p\n" , jpeg->clk); -clk_prepare_enable (jpeg->clk);/* v4l2 device */ ret =v4l2_device_register (&pdev->dev, &jpeg->v4l2_dev);
@@ -1380,7 +1379,6 @@ device_register_rollback:v4l2_device_unregister (&jpeg->v4l2_dev); clk_get_rollback: -clk_disable_unprepare (jpeg->clk);clk_put (jpeg->clk);return ret;
@@ -1400,7 +1398,9 @@ static int s5p_jpeg_remove(struct platform_device *pdev)v4l2_m2m_release (jpeg->m2m_dev);v4l2_device_unregister (&jpeg->v4l2_dev); -clk_disable_unprepare (jpeg->clk); +if (!pm_runtime_status_suspended (&pdev->dev)) +clk_disable_unprepare (jpeg->clk); +clk_put (jpeg->clk);return 0 ;
@@ -1408,6 +1408,10 @@ static int s5p_jpeg_remove(struct platform_device *pdev)static int s5p_jpeg_runtime_suspend (struct device *dev) { +struct s5p_jpeg *jpeg =dev_get_drvdata (dev); + +clk_disable_unprepare (jpeg->clk); +return 0 ; }
@@ -1415,6 +1419,8 @@ static int s5p_jpeg_runtime_resume(struct device *dev) {struct s5p_jpeg *jpeg =dev_get_drvdata (dev); +clk_prepare_enable (jpeg->clk); +/* * JPEG IP allows storing two Huffman tables for each component * We fill table 0 for each component
@@ -1427,9 +1433,23 @@ static int s5p_jpeg_runtime_resume(struct device *dev)return 0 ; } +static int s5p_jpeg_suspend (struct device *dev) +{ +s5p_jpeg_runtime_suspend (dev); + +return 0 ; +} + +static int s5p_jpeg_resume (struct device *dev) +{ +s5p_jpeg_runtime_resume (dev); + +return 0 ; +} +static const struct dev_pm_ops s5p_jpeg_pm_ops = { - .runtime_suspend = s5p_jpeg_runtime_suspend, - .runtime_resume = s5p_jpeg_runtime_resume, + SET_SYSTEM_SLEEP_PM_OPS(s5p_jpeg_suspend, s5p_jpeg_resume) +SET_RUNTIME_PM_OPS (s5p_jpeg_runtime_suspend, s5p_jpeg_runtime_resume,NULL ) };#ifdef CONFIG_OF
Signature · 1 line
1.7.9.5
PATCH 7/16 s5p-jpeg: Fix lack of spin_lock protection
In reply to Jacek Anaszewskis5p_jpeg_device_run and s5p_jpeg_runtime_resume callbacks should have spin_lock protection as they alter device registers.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +10 -1
@@ -930,7 +930,9 @@ static void s5p_jpeg_device_run(void *priv)struct s5p_jpeg_ctx *ctx = priv;struct s5p_jpeg *jpeg = ctx->jpeg;struct vb2_buffer *src_buf, *dst_buf; -unsigned long src_addr, dst_addr; +unsigned long src_addr, dst_addr, flags; + +spin_lock_irqsave (&ctx->jpeg->slock, flags); src_buf =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx);
@@ -998,6 +1000,8 @@ static void s5p_jpeg_device_run(void *priv) }jpeg_start (jpeg->regs); + +spin_unlock_irqrestore (&ctx->jpeg->slock, flags); }static int s5p_jpeg_job_ready (void *priv)
@@ -1418,9 +1422,12 @@ static int s5p_jpeg_runtime_suspend(struct device *dev)static int s5p_jpeg_runtime_resume (struct device *dev) {struct s5p_jpeg *jpeg =dev_get_drvdata (dev); +unsigned long flags;clk_prepare_enable (jpeg->clk); +spin_lock_irqsave (&jpeg->slock, flags); +/* * JPEG IP allows storing two Huffman tables for each component * We fill table 0 for each component
@@ -1430,6 +1437,8 @@ static int s5p_jpeg_runtime_resume(struct device *dev)s5p_jpeg_set_hactbl (jpeg->regs);s5p_jpeg_set_hactblg (jpeg->regs); +spin_unlock_irqrestore (&jpeg->slock, flags); +return 0 ; }
Signature · 1 line
1.7.9.5
PATCH 8/16 s5p-jpeg: Synchronize cached controls with V4L2 core
In reply to Jacek AnaszewskiThis patch adds proper initialization of the in-driver cached state of JPEG controls with V4L2 core.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/platform/s5p-jpeg/jpeg-core.c +3 -0
@@ -890,6 +890,9 @@ static int s5p_jpeg_controls_create(struct s5p_jpeg_ctx *ctx)if (ctx->mode ==S5P_JPEG_DECODE ) ctrl->flags |=V4L2_CTRL_FLAG_VOLATILE |V4L2_CTRL_FLAG_READ_ONLY ; + +v4l2_ctrl_handler_setup (&ctx->ctrl_handler); +return 0 ; }
Signature · 1 line
1.7.9.5
PATCH 9/16 s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c
In reply to Jacek AnaszewskiMove function definitions from jpeg-hw.h to jpeg-hw-s5p.c 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 | 2 +-
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, 104 insertions(+), 50 deletions(-)
rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h => jpeg-hw-s5p.c} (71%)
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 +1 -1
@@ -29,7 +29,7 @@#include <media/videobuf2-dma-contig.h> #include "jpeg-core.h" -#include "jpeg-hw.h" +#include "jpeg-hw-s5p.h" static struct s5p_jpeg_fmt formats_enc[] = { {
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 10/16 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 | 620 +++++++++++++++++++--- drivers/media/platform/s5p-jpeg/jpeg-core.h | 72 ++- drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c | 293 ++++++++++ drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h | 44 ++ drivers/media/platform/s5p-jpeg/jpeg-regs.h | 215 +++++++- 6 files changed, 1152 insertions(+), 94 deletions(-) create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.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-exynos.o jpeg-hw-s5p.o obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG) += s5p-jpeg.o
drivers/media/platform/s5p-jpeg/jpeg-core.c +533 -87
868 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-core.h +67 -5
114 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c new file +293 -0
293 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h new file +44 -0
44 lines not on this page · raw message
drivers/media/platform/s5p-jpeg/jpeg-regs.h +214 -1
235 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 11/16 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; }
@@ -1426,7 +1453,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 12/16 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 | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+)
drivers/media/platform/s5p-jpeg/jpeg-core.c +78 -0
@@ -941,6 +941,7 @@ 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; fmt = s5p_jpeg_find_format(ctx, f->fmt.pix.pixelformat,
@@ -952,6 +953,83 @@ 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 +* output 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)) { +switch (fmt->fourcc) { +case V4L2_PIX_FMT_NV24 : +switch (ctx->subsampling) { +case V4L2_JPEG_CHROMA_SUBSAMPLING_422 : + pix->pixelformat =V4L2_PIX_FMT_NV16 ; +break ; +case V4L2_JPEG_CHROMA_SUBSAMPLING_420 : + pix->pixelformat =V4L2_PIX_FMT_NV12 ; +break ; +case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY : + pix->pixelformat =V4L2_PIX_FMT_GREY ; +break ; +default : +return -EINVAL ; + } +break ; +case V4L2_PIX_FMT_NV42 : +switch (ctx->subsampling) { +case V4L2_JPEG_CHROMA_SUBSAMPLING_422 : + pix->pixelformat =V4L2_PIX_FMT_NV61 ; +break ; +case V4L2_JPEG_CHROMA_SUBSAMPLING_420 : + pix->pixelformat =V4L2_PIX_FMT_NV21 ; +break ; +case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY : + pix->pixelformat =V4L2_PIX_FMT_GREY ; +break ; +default : +return -EINVAL ; + } +break ; +case V4L2_PIX_FMT_YUYV : +case V4L2_PIX_FMT_NV16 : +case V4L2_PIX_FMT_YUV420 : +switch (ctx->subsampling) { +case V4L2_JPEG_CHROMA_SUBSAMPLING_420 : + pix->pixelformat =V4L2_PIX_FMT_NV12 ; +break ; +case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY : + pix->pixelformat =V4L2_PIX_FMT_GREY ; +break ; +default : +return -EINVAL ; + } +break ; +case V4L2_PIX_FMT_YVYU : +case V4L2_PIX_FMT_NV61 : +switch (ctx->subsampling) { +case V4L2_JPEG_CHROMA_SUBSAMPLING_420 : + pix->pixelformat =V4L2_PIX_FMT_NV21 ; +break ; +case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY : + pix->pixelformat =V4L2_PIX_FMT_GREY ; +break ; +default : +return -EINVAL ; + } +break ; +case V4L2_PIX_FMT_NV12 : +case V4L2_PIX_FMT_NV21 : + pix->pixelformat =V4L2_PIX_FMT_GREY ; +break ; +default : +return -EINVAL ; + } + } +return vidioc_try_fmt (f, fmt, ctx,FMT_TYPE_CAPTURE ); }
Signature · 1 line
1.7.9.5
PATCH 13/16 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
@@ -1210,7 +1210,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 14/16 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 | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/platform/s5p-jpeg/jpeg-core.c +5 -0
@@ -1038,6 +1038,7 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv, {struct s5p_jpeg_ctx *ctx =fh_to_ctx (priv);struct s5p_jpeg_fmt *fmt; +struct v4l2_control ctrl_subs; fmt =s5p_jpeg_find_format (ctx, f->fmt.pix.pixelformat,FMT_TYPE_OUTPUT );
@@ -1048,6 +1049,10 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv,return -EINVAL ; } + ctrl_subs.id =V4L2_CID_JPEG_CHROMA_SUBSAMPLING ; + ctrl_subs.value = fmt->subsampling; +v4l2_s_ctrl (priv, &ctx->ctrl_handler, &ctrl_subs); +return vidioc_try_fmt (f, fmt, ctx,FMT_TYPE_OUTPUT ); }
Signature · 1 line
1.7.9.5
PATCH 15/16 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 adds mechanism that prevents setting invalid value of the V4L2_CID_JPEG_CHROMA_SUBSAMPLING control.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +25 -2
@@ -1176,6 +1176,7 @@ static int s5p_jpeg_s_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);
@@ -1187,12 +1188,34 @@ static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl) ctx->restart_interval = ctrl->val;break ;case V4L2_CID_JPEG_CHROMA_SUBSAMPLING : - ctx->subsampling = ctrl->val; +if (ctx->jpeg->variant->version ==SJPEG_S5P ) { + ctx->subsampling = ctrl->val; +break ; + } +/* +* 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) + ctx->subsampling = ctx->out_q.fmt->subsampling; +else + ctx->subsampling = ctrl->val;break ; } +error_free:spin_unlock_irqrestore (&ctx->jpeg->slock, flags); -return 0 ; +return ret; }static const struct v4l2_ctrl_ops s5p_jpeg_ctrl_ops = {
Signature · 1 line
1.7.9.5
PATCH 16/16 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 decoded_subsampling_to_v4l2, which performs HW -> V4L2 translation.
--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 36 ++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +30 -6
@@ -358,6 +358,13 @@ static const unsigned char hactblg0[162] = {0xf9 ,0xfa }; +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);
@@ -368,6 +375,28 @@ static inline struct s5p_jpeg_ctx *fh_to_ctx(struct v4l2_fh *fh) return container_of(fh, struct s5p_jpeg_ctx, fh); } +static inline int decoded_subsampling_to_v4l2 (struct s5p_jpeg_ctx *ctx) +{ +int subsampling; + +WARN_ON (ctx->subsampling >3 ); + +if (ctx->jpeg->variant->version ==SJPEG_S5P ) { +if (ctx->subsampling >2 ) + subsampling =V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY ; +else + subsampling = ctx->subsampling; + }else { +if (ctx->subsampling >2 ) + subsampling =V4L2_JPEG_CHROMA_SUBSAMPLING_420 ; +else + subsampling = + exynos4x12_decoded_subsampling[ctx->subsampling]; + } + +return subsampling; +} +static inline void s5p_jpeg_set_qtbl (void __iomem *regs,const unsigned char *qtbl,unsigned long tab,int len)
@@ -1159,12 +1188,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 =decoded_subsampling_to_v4l2 (ctx);spin_unlock_irqrestore (&jpeg->slock, flags);break ; }
Signature · 1 line
1.7.9.5
Re: [PATCH 14/16] s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value
In reply to Jacek AnaszewskiQuoted 27 lines · Jacek Anaszewski
When output queue fourcc is set to any flavour of YUV, the
V4L2_CID_JPEG_CHROMA_SUBSAMPLINGcontrol 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.Signed-off-by Jacek Anaszewski <[email protected]>Signed-off-by Kyungmin Park <[email protected]>--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/media/platform/s5p-jpeg/jpeg-core.c +1
-0@@ -1038,6 +1038,7 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv, {struct s5p_jpeg_ctx *ctx =fh_to_ctx (priv);struct s5p_jpeg_fmt *fmt; +struct v4l2_control ctrl_subs; fmt =s5p_jpeg_find_format (ctx, f->fmt.pix.pixelformat,FMT_TYPE_OUTPUT );
drivers/media/platform/s5p-jpeg/jpeg-core.c static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv, · line 1054
Quoted 6 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c +3
-0@@ -1048,6 +1049,10 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv,return -EINVAL ; } + ctrl_subs.id =V4L2_CID_JPEG_CHROMA_SUBSAMPLING ; + ctrl_subs.value = fmt->subsampling; +v4l2_s_ctrl (priv, &ctx->ctrl_handler, &ctrl_subs);
TRY_FMT should never have side-effects, so this isn't the correct way of implementing this.
Also, don't use v4l2_s_ctrl, instead use v4l2_ctrl_s_ctrl. The v4l2_s_ctrl function is for core framework use only, not for use in drivers.
Regards,
Hans
Quoted 5 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c +1
-0+return vidioc_try_fmt (f, fmt, ctx,FMT_TYPE_OUTPUT ); }
Re: [PATCH 15/16] s5p-jpeg: Ensure setting correct value of the chroma subsampling control
In reply to Jacek AnaszewskiQuoted 42 lines · Jacek Anaszewski
Exynos4x12 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_GRAYoption the source image fourcc has to beV4L2_PIX_FMT_GREY. This patch adds mechanism that prevents setting invalid value of theV4L2_CID_JPEG_CHROMA_SUBSAMPLINGcontrol.Signed-off-by Jacek Anaszewski <[email protected]>Signed-off-by Kyungmin Park <[email protected]>--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)drivers/media/platform/s5p-jpeg/jpeg-core.c +13
-1@@ -1176,6 +1176,7 @@ static int s5p_jpeg_s_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);@@ -1187,12 +1188,34 @@ static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl) ctx->restart_interval = ctrl->val;break ;case V4L2_CID_JPEG_CHROMA_SUBSAMPLING : - ctx->subsampling = ctrl->val; +if (ctx->jpeg->variant->version ==SJPEG_S5P ) { + ctx->subsampling = ctrl->val; +break ; + } +/* +* 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 ;
drivers/media/platform/s5p-jpeg/jpeg-core.c static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl) · line 1212
Quoted 10 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c +10
-0+ 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) + ctx->subsampling = ctx->out_q.fmt->subsampling; +else + ctx->subsampling = ctrl->val;
I would do this in a try_ctrl op instead: that way VIDIOC_TRY_EXT_CTRLS will also be able to understand these restrictions.
Before the s_ctrl op is called the control framework will always call the try_ctrl op as well if it is present.
Regards,
Hans
Quoted 11 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c +2
-1break ; } +error_free:spin_unlock_irqrestore (&ctx->jpeg->slock, flags); -return 0 ; +return ret; }static const struct v4l2_ctrl_ops s5p_jpeg_ctrl_ops = {
Re: [PATCH 14/16] s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value
In reply to Hans VerkuilQuoted 31 lines · Hans Verkuil
Quoted 30 lines · Jacek Anaszewski
When output queue fourcc is set to any flavour of YUV, the
V4L2_CID_JPEG_CHROMA_SUBSAMPLINGcontrol 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.Signed-off-by Jacek Anaszewski <[email protected]>Signed-off-by Kyungmin Park <[email protected]>--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/media/platform/s5p-jpeg/jpeg-core.c +1
-0@@ -1038,6 +1038,7 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv, {struct s5p_jpeg_ctx *ctx =fh_to_ctx (priv);struct s5p_jpeg_fmt *fmt; +struct v4l2_control ctrl_subs; fmt =s5p_jpeg_find_format (ctx, f->fmt.pix.pixelformat,FMT_TYPE_OUTPUT );@@ -1048,6 +1049,10 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv,return -EINVAL ; }
Quoted 6 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv, · line 1054
Quoted 3 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c +3
-0+ ctrl_subs.id =V4L2_CID_JPEG_CHROMA_SUBSAMPLING ; + ctrl_subs.value = fmt->subsampling; +v4l2_s_ctrl (priv, &ctx->ctrl_handler, &ctrl_subs);
TRY_FMTshould never have side-effects, so this isn't the correct way of implementing this.
I am aware of it, but I couldn't have found more suitable place for implementing this. Below is the rationale standing behind such an implementation:
- Exynos4x12 device doesn't generate an eoc interrupt if the subsampling property of an output queue format is lower than the target jpeg subsampling (e.g. V4L2_PIX_FMT_YUYV [4:2:2 subsampling] and JPEG 4:4:4)
- It should be possible to inform the user space application that the subsampling it wants to set is not supported with the current output queue fourcc.
- It is possible that after calling S_EXT_CTRLS the application will call S_FMT on output queue with different fourcc which will change the allowed scope of JPEG subsampling settings. Let's assume the following flow of ioctls:
- S_FMT V4L2_PIX_FMT_YUYV (4:2:2)
- S_EXT_CTRLS V4L2_JPEG_CHROMA_SUBSAMPLING_422
- S_FMT V4L2_PIX_FMT_YUV420
Now the JPEG subsampling set is illegal as 4:2:2 is lower than 4:2:0 (lower refers here to the lower number of luma samples assigned to the single chroma sample). It is evident now that the change of output queue fourcc entails change of the allowed scope of JPEG subsampling settings. The way I implemented it reflects this constraint precisely. We could go for adjusting the JPEG subsampling e.g. in the device_run callback but the user space application wouldn't know about it unless it called G_EXT_CTRLS ioctl after end of conversion.
In view of the above it is clear that calling S_FMT in this case HAS side effect no matter whether we take it into account in the driver implementation or not. Nevertheless maybe there is some more elegant way of handling this problem I am not aware of. I am open to any interesting ideas.
Regards,
Jacek Anaszewski
Quoted 18 lines
Also, don't use
v4l2_s_ctrl, instead usev4l2_ctrl_s_ctrl. Thev4l2_s_ctrlfunction is for core framework use only, not for use in drivers.Regards,
Hans
drivers/media/platform/s5p-jpeg/jpeg-core.c static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv, · line 1058
Quoted 5 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c +1
-0+return vidioc_try_fmt (f, fmt, ctx,FMT_TYPE_OUTPUT ); }--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 14/16] s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value
Quoted 67 lines · Jacek Anaszewski
Quoted 31 lines · Hans Verkuil
Quoted 30 lines · Jacek Anaszewski
When output queue fourcc is set to any flavour of YUV, the
V4L2_CID_JPEG_CHROMA_SUBSAMPLINGcontrol 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.Signed-off-by Jacek Anaszewski <[email protected]>Signed-off-by Kyungmin Park <[email protected]>--- drivers/media/platform/s5p-jpeg/jpeg-core.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/media/platform/s5p-jpeg/jpeg-core.c +1
-0@@ -1038,6 +1038,7 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv, {struct s5p_jpeg_ctx *ctx =fh_to_ctx (priv);struct s5p_jpeg_fmt *fmt; +struct v4l2_control ctrl_subs; fmt =s5p_jpeg_find_format (ctx, f->fmt.pix.pixelformat,FMT_TYPE_OUTPUT );@@ -1048,6 +1049,10 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv,return -EINVAL ; }Quoted 6 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c static int s5p_jpeg_try_fmt_vid_out(struct file *file, void *priv, · line 1054
Quoted 3 lines
drivers/media/platform/s5p-jpeg/jpeg-core.c +3
-0+ ctrl_subs.id =V4L2_CID_JPEG_CHROMA_SUBSAMPLING ; + ctrl_subs.value = fmt->subsampling; +v4l2_s_ctrl (priv, &ctx->ctrl_handler, &ctrl_subs);
TRY_FMTshould never have side-effects, so this isn't the correct way of implementing this.I am aware of it, but I couldn't have found more suitable place for implementing this. Below is the rationale standing behind such an implementation:
- Exynos4x12 device doesn't generate an eoc interrupt if the subsampling property of an output queue format is lower than the target jpeg subsampling (e.g.
V4L2_PIX_FMT_YUYV[4:2:2 subsampling] and JPEG 4:4:4)
- It should be possible to inform the user space application that the subsampling it wants to set is not supported with the current output queue fourcc.
- It is possible that after callingS_EXT_CTRLSthe application will callS_FMTon output queue with different fourcc which will change the allowed scope of JPEG subsampling settings. Let's assume the following flow of ioctls:
-S_FMTV4L2_PIX_FMT_YUYV(4:2:2)
-S_EXT_CTRLSV4L2_JPEG_CHROMA_SUBSAMPLING_422
-S_FMTV4L2_PIX_FMT_YUV420
Now the JPEG subsampling set is illegal as 4:2:2 is lower than 4:2:0 (lower refers here to the lower number of luma samples assigned to the single chroma sample). It is evident now that the change of output queue fourcc entails change of the allowed scope of JPEG subsampling settings. The way I implemented it reflects this constraint precisely. We could go for adjusting the JPEG subsampling e.g. in thedevice_runcallback but the user space application wouldn't know about it unless it calledG_EXT_CTRLSioctl after end of conversion.
Quoted 5 lines
In view of the above it is clear that calling
S_FMTin this case HAS side effect no matter whether we take it into account in the driver implementation or not. Nevertheless maybe there is some more elegant way of handling this problem I am not aware of. I am open to any interesting ideas.
I think you misunderstood me. It is OK that S_FMT changes the control, but TRY_FMT shouldn't. So the code that changes the subsampling control should be moved to s5p_jpeg_s_fmt_vid_out.
Regards,
Hans