The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sergey Khimich <serghox@gmail.com>
To: linux-media@vger.kernel.org
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-kernel@vger.kernel.org,
	Vladimir Yakovlev <vovchkir@gmail.com>,
	Maksim Turok <turok.m7@gmail.com>
Subject: [PATCH 15/18] media: coda: Use v4l2_ctrl to set gamma for h264enc
Date: Fri, 14 Mar 2025 18:29:36 +0300	[thread overview]
Message-ID: <20250314152939.2759573-16-serghox@gmail.com> (raw)
In-Reply-To: <20250314152939.2759573-1-serghox@gmail.com>

From: Vladimir Yakovlev <vovchkir@gmail.com>

We can use v4l2_ctrl (V4L2_CID_GAMMA) to set gamma for
configuration h.264 encoder.

Co-developed-by: Sergey Khimich <serghox@gmail.com>
Signed-off-by: Sergey Khimich <serghox@gmail.com>
Signed-off-by: Vladimir Yakovlev <vovchkir@gmail.com>
---
 .../platform/chips-media/coda/coda-bit.c      | 28 ++++++-------------
 .../platform/chips-media/coda/coda-common.c   |  7 +++++
 .../media/platform/chips-media/coda/coda.h    |  4 +++
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/media/platform/chips-media/coda/coda-bit.c b/drivers/media/platform/chips-media/coda/coda-bit.c
index 50350d657f91..782b299e9b12 100644
--- a/drivers/media/platform/chips-media/coda/coda-bit.c
+++ b/drivers/media/platform/chips-media/coda/coda-bit.c
@@ -35,9 +35,6 @@
 #define CODA7_PS_BUF_SIZE	0x28000
 #define CODA9_PS_SAVE_SIZE	(512 * 1024)
 
-#define CODA_DEFAULT_GAMMA	4096
-#define CODA9_DEFAULT_GAMMA	24576	/* 0.75 * 32768 */
-
 static void coda_free_bitstream_buffer(struct coda_ctx *ctx);
 
 static inline int coda_is_initialized(struct coda_dev *dev)
@@ -1065,7 +1062,7 @@ static int coda_start_encoding(struct coda_ctx *ctx)
 	struct coda_q_data *q_data_src, *q_data_dst;
 	u32 bitstream_buf, bitstream_size;
 	struct vb2_v4l2_buffer *buf;
-	int gamma, ret, value;
+	int ret, value;
 	u32 dst_fourcc;
 	int num_fb;
 	u32 stride;
@@ -1251,13 +1248,14 @@ static int coda_start_encoding(struct coda_ctx *ctx)
 
 
 	value = 0;
-	if (dev->devtype->product == CODA_960)
-		gamma = CODA9_DEFAULT_GAMMA;
-	else
-		gamma = CODA_DEFAULT_GAMMA;
-	if (gamma > 0) {
-		coda_write(dev, (gamma & CODA_GAMMA_MASK) << CODA_GAMMA_OFFSET,
-			   CODA_CMD_ENC_SEQ_RC_GAMMA);
+	if (ctx->params.gamma > 0) {
+		if (dev->devtype->product == CODA_960)
+			value |= 1 << CODA9_OPTION_GAMMA_OFFSET;
+		else if (dev->devtype->product == CODA_DX6)
+			value |= 1 << CODADX6_OPTION_GAMMA_OFFSET;
+		else
+			value |= 1 << CODA7_OPTION_GAMMA_OFFSET;
+		coda_write(dev, ctx->params.gamma, CODA_CMD_ENC_SEQ_RC_GAMMA);
 	}
 
 	if (ctx->params.h264_min_qp || ctx->params.h264_max_qp) {
@@ -1269,15 +1267,7 @@ static int coda_start_encoding(struct coda_ctx *ctx)
 	if (dev->devtype->product == CODA_960) {
 		if (ctx->params.h264_max_qp)
 			value |= 1 << CODA9_OPTION_RCQPMAX_OFFSET;
-		if (CODA_DEFAULT_GAMMA > 0)
-			value |= 1 << CODA9_OPTION_GAMMA_OFFSET;
 	} else {
-		if (CODA_DEFAULT_GAMMA > 0) {
-			if (dev->devtype->product == CODA_DX6)
-				value |= 1 << CODADX6_OPTION_GAMMA_OFFSET;
-			else
-				value |= 1 << CODA7_OPTION_GAMMA_OFFSET;
-		}
 		if (ctx->params.h264_min_qp)
 			value |= 1 << CODA7_OPTION_RCQPMIN_OFFSET;
 		if (ctx->params.h264_max_qp)
diff --git a/drivers/media/platform/chips-media/coda/coda-common.c b/drivers/media/platform/chips-media/coda/coda-common.c
index 9b443ddabeab..9ca459793050 100644
--- a/drivers/media/platform/chips-media/coda/coda-common.c
+++ b/drivers/media/platform/chips-media/coda/coda-common.c
@@ -2205,6 +2205,9 @@ static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
 		ctx->params.bitrate = ctrl->val / 1000;
 		ctx->params.bitrate_changed = true;
 		break;
+	case V4L2_CID_GAMMA:
+		ctx->params.gamma = ctrl->val;
+		break;
 	case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
 		ctx->params.gop_size = ctrl->val;
 		break;
@@ -2311,9 +2314,13 @@ static const struct v4l2_ctrl_ops coda_ctrl_ops = {
 static void coda_encode_ctrls(struct coda_ctx *ctx)
 {
 	int max_gop_size = (ctx->dev->devtype->product == CODA_DX6) ? 60 : 99;
+	u32 def_gamma = (ctx->dev->devtype->product == CODA_960) ?
+			 CODA9_DEFAULT_GAMMA : CODA_DEFAULT_GAMMA;
 
 	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
 		V4L2_CID_MPEG_VIDEO_BITRATE, 0, 32767000, 1000, 0);
+	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
+			  V4L2_CID_GAMMA, 0, 0x7FFFFFFF, 1, def_gamma);
 	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
 		V4L2_CID_MPEG_VIDEO_GOP_SIZE, 0, max_gop_size, 1, 16);
 	v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
diff --git a/drivers/media/platform/chips-media/coda/coda.h b/drivers/media/platform/chips-media/coda/coda.h
index ddfd0a32c653..007f56b24c61 100644
--- a/drivers/media/platform/chips-media/coda/coda.h
+++ b/drivers/media/platform/chips-media/coda/coda.h
@@ -29,6 +29,9 @@
 #define CODA_MAX_FRAMEBUFFERS	19
 #define FMO_SLICE_SAVE_BUF_SIZE	(32)
 
+#define CODA_DEFAULT_GAMMA	4096
+#define CODA9_DEFAULT_GAMMA	24576	/* 0.75 * 32768 */
+
 /*
  * This control allows applications to read the per-stream
  * (i.e. per-context) Macroblocks Error Count. This value
@@ -150,6 +153,7 @@ struct coda_params {
 	u32			vbv_size;
 	u32			slice_max_bits;
 	u32			slice_max_mb;
+	u32			gamma;
 	bool			force_ipicture;
 	bool			gop_size_changed;
 	bool			bitrate_changed;
-- 
2.30.2


  parent reply	other threads:[~2025-03-14 15:30 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 15:29 [PATCH 00/18] coda988 video codec support Sergey Khimich
2025-03-14 15:29 ` [PATCH 01/18] media: coda: Add print if irq isn't present Sergey Khimich
2025-05-23 23:40   ` Nicolas Dufresne
2025-05-23 23:43     ` Nicolas Dufresne
2025-03-14 15:29 ` [PATCH 02/18] media: coda: Use get_array to work use multiple reset Sergey Khimich
2025-03-16 11:44   ` Krzysztof Kozlowski
2025-03-14 15:29 ` [PATCH 03/18] dt-bindings: media: coda: Fix resets count Sergey Khimich
2025-03-16 11:42   ` Krzysztof Kozlowski
     [not found]     ` <CABd6DqVZiW4ybyfBi4qgkP7RjRLpaAc4G1n+nBJzTW8fLh3sVQ@mail.gmail.com>
2025-03-24 13:52       ` Krzysztof Kozlowski
2025-03-14 15:29 ` [PATCH 04/18] media: coda: Add check result after reset Sergey Khimich
2025-03-14 15:29 ` [PATCH 05/18] media: coda: using threaded_irq for 0 (bit) interrupt Sergey Khimich
2025-05-23 23:49   ` Nicolas Dufresne
2025-03-14 15:29 ` [PATCH 06/18] media: coda: Add reset device before getting interrupt Sergey Khimich
2025-03-14 15:29 ` [PATCH 07/18] media: coda: Add fake IRQ check Sergey Khimich
2025-05-23 23:57   ` Nicolas Dufresne
2025-03-14 15:29 ` [PATCH 08/18] media: coda: Add log to finish_encode if buffer is too small Sergey Khimich
2025-05-24  0:03   ` Nicolas Dufresne
2025-03-14 15:29 ` [PATCH 09/18] media: coda: Fix max h.264 level for CODA_DX6 Sergey Khimich
2025-05-24  0:07   ` Nicolas Dufresne
2025-03-14 15:29 ` [PATCH 10/18] media: coda: Remove double setting of stop flag Sergey Khimich
2025-03-14 15:29 ` [PATCH 11/18] media: coda: Print size of encoded buff in other place Sergey Khimich
2025-03-14 15:29 ` [PATCH 12/18] media: coda: Fix loglevel for seq mismatch print Sergey Khimich
2025-03-14 15:29 ` [PATCH 13/18] media: coda: Fix support for all mpeg4 levels Sergey Khimich
2025-03-14 15:29 ` [PATCH 14/18] media: coda: Fix handling wrong format in coda_try_fmt Sergey Khimich
2025-03-14 15:29 ` Sergey Khimich [this message]
2025-03-14 15:29 ` [PATCH 16/18] media: coda: Update default velues of QP for mpeg4 I/P Sergey Khimich
2025-03-14 15:29 ` [PATCH 17/18] media: coda: Use preferred usleep_range than udelay Sergey Khimich
2025-03-14 15:29 ` [PATCH 18/18] media: coda: add support coda988 enc and dec Sergey Khimich
2025-03-17  0:12 ` [PATCH 00/18] coda988 video codec support jackson.lee
2025-03-25  1:44   ` jackson.lee
2025-04-08 18:41 ` Nicolas Dufresne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250314152939.2759573-16-serghox@gmail.com \
    --to=serghox@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=turok.m7@gmail.com \
    --cc=vovchkir@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox