All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	tomi.valkeinen@ideasonboard.com, bingbu.cao@intel.com,
	hongju.wang@intel.com, hverkuil@xs4all.nl,
	Andrey Konovalov <andrey.konovalov@linaro.org>,
	Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	Dmitry Perchanov <dmitry.perchanov@intel.com>,
	"Ng, Khai Wen" <khai.wen.ng@intel.com>,
	Alain Volmat <alain.volmat@foss.st.com>
Subject: [PATCH v9 33/46] media: ccs: Compute binning configuration from sub-device state
Date: Tue, 16 Apr 2024 22:33:06 +0300	[thread overview]
Message-ID: <20240416193319.778192-34-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20240416193319.778192-1-sakari.ailus@linux.intel.com>

Calculate binning configuration from sub-device state so the state related
configuration can be removed from the driver's device context struct.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/ccs/ccs-core.c | 56 +++++++++++++++++++-------------
 drivers/media/i2c/ccs/ccs.h      |  3 --
 2 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/drivers/media/i2c/ccs/ccs-core.c b/drivers/media/i2c/ccs/ccs-core.c
index f82f3ec37c7c..08e719d611fb 100644
--- a/drivers/media/i2c/ccs/ccs-core.c
+++ b/drivers/media/i2c/ccs/ccs-core.c
@@ -511,13 +511,36 @@ static int ccs_pll_try(struct ccs_sensor *sensor, struct ccs_pll *pll)
 	return ccs_pll_calculate(&client->dev, &lim, pll);
 }
 
+static void
+ccs_get_binning(struct ccs_sensor *sensor, u8 *binning_mode, u8 *binh, u8 *binv)
+{
+	struct v4l2_subdev_state *state =
+		v4l2_subdev_get_locked_active_state(&sensor->binner->sd);
+	const struct v4l2_rect *sink_crop =
+		v4l2_subdev_state_get_crop(state, CCS_PAD_SINK,
+					   CCS_STREAM_PIXEL);
+	const struct v4l2_rect *sink_comp =
+		v4l2_subdev_state_get_compose(state, CCS_PAD_SINK,
+					      CCS_STREAM_PIXEL);
+
+	if (binning_mode)
+		*binning_mode =	sink_crop->width == sink_comp->width &&
+				sink_crop->height == sink_comp->height ? 0 : 1;
+
+	*binh = sink_crop->width / sink_comp->width;
+	*binv = sink_crop->height / sink_comp->height;
+}
+
 static int ccs_pll_update(struct ccs_sensor *sensor)
 {
 	struct ccs_pll *pll = &sensor->pll;
+	u8 binh, binv;
 	int rval;
 
-	pll->binning_horizontal = sensor->binning_horizontal;
-	pll->binning_vertical = sensor->binning_vertical;
+	ccs_get_binning(sensor, NULL, &binh, &binv);
+
+	pll->binning_horizontal = binh;
+	pll->binning_vertical = binv;
 	pll->link_freq =
 		sensor->link_freq->qmenu_int[sensor->link_freq->val];
 	pll->scale_m = sensor->scale_m;
@@ -1241,8 +1264,11 @@ static void ccs_update_blanking(struct ccs_sensor *sensor,
 	struct v4l2_ctrl *hblank = sensor->hblank;
 	u16 min_fll, max_fll, min_llp, max_llp, min_lbp;
 	int min, max;
+	u8 binh, binv;
+
+	ccs_get_binning(sensor, NULL, &binh, &binv);
 
-	if (sensor->binning_vertical > 1 || sensor->binning_horizontal > 1) {
+	if (binv > 1 || binh > 1) {
 		min_fll = CCS_LIM(sensor, MIN_FRAME_LENGTH_LINES_BIN);
 		max_fll = CCS_LIM(sensor, MAX_FRAME_LENGTH_LINES_BIN);
 		min_llp = CCS_LIM(sensor, MIN_LINE_LENGTH_PCK_BIN);
@@ -1814,7 +1840,7 @@ static int ccs_enable_streams(struct v4l2_subdev *subdev,
 		v4l2_subdev_state_get_crop(src_state, CCS_PAD_SRC,
 					   CCS_STREAM_PIXEL);
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
-	unsigned int binning_mode;
+	u8 binning_mode, binh, binv;
 	int rval;
 
 	if (pad != CCS_PAD_SRC)
@@ -1836,19 +1862,12 @@ static int ccs_enable_streams(struct v4l2_subdev *subdev,
 		goto err_pm_put;
 
 	/* Binning configuration */
-	if (sensor->binning_horizontal == 1 &&
-	    sensor->binning_vertical == 1) {
-		binning_mode = 0;
-	} else {
-		u8 binning_type =
-			(sensor->binning_horizontal << 4)
-			| sensor->binning_vertical;
+	ccs_get_binning(sensor,	&binning_mode, &binh, &binv);
 
-		rval = ccs_write(sensor, BINNING_TYPE, binning_type);
+	if (binning_mode) {
+		rval = ccs_write(sensor, BINNING_TYPE, (binh << 4) | binv);
 		if (rval < 0)
 			goto err_pm_put;
-
-		binning_mode = 1;
 	}
 	rval = ccs_write(sensor, BINNING_MODE, binning_mode);
 	if (rval < 0)
@@ -2254,9 +2273,6 @@ static void ccs_propagate(struct v4l2_subdev *subdev,
 				sensor->scale_m = CCS_LIM(sensor, SCALER_N_MIN);
 				sensor->scaling_mode =
 					CCS_SCALING_MODE_NO_SCALING;
-			} else if (ssd == sensor->binner) {
-				sensor->binning_horizontal = 1;
-				sensor->binning_vertical = 1;
 			}
 		}
 		fallthrough;
@@ -2530,10 +2546,6 @@ static void ccs_set_compose_binner(struct v4l2_subdev *subdev,
 			best = this;
 		}
 	}
-	if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
-		sensor->binning_vertical = binv;
-		sensor->binning_horizontal = binh;
-	}
 
 	sel->r.width = (sink_crop->width / binh) & ~1;
 	sel->r.height = (sink_crop->height / binv) & ~1;
@@ -3715,8 +3727,6 @@ static int ccs_probe(struct i2c_client *client)
 				sensor->binning_subtypes[i].vertical);
 		}
 	}
-	sensor->binning_horizontal = 1;
-	sensor->binning_vertical = 1;
 
 	if (device_create_file(&client->dev, &dev_attr_ident) != 0) {
 		dev_err(&client->dev, "sysfs ident entry creation failed\n");
diff --git a/drivers/media/i2c/ccs/ccs.h b/drivers/media/i2c/ccs/ccs.h
index dcca3f88ea67..aadbd4302607 100644
--- a/drivers/media/i2c/ccs/ccs.h
+++ b/drivers/media/i2c/ccs/ccs.h
@@ -237,9 +237,6 @@ struct ccs_sensor {
 	u32 embedded_mbus_code;
 	u8 emb_data_ctrl;
 
-	u8 binning_horizontal;
-	u8 binning_vertical;
-
 	u8 scale_m;
 	u8 scaling_mode;
 
-- 
2.39.2


  parent reply	other threads:[~2024-04-16 19:34 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16 19:32 [PATCH v9 00/46] Generic line based metadata support, internal pads Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 01/46] media: v4l2-subdev: Fix stream handling for crop API Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 02/46] media: v4l2-subdev: Clearly document that the crop API won't be extended Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 03/46] media: Documentation: Add "stream" into glossary Sakari Ailus
2024-04-19 16:02   ` Laurent Pinchart
2024-04-16 19:32 ` [PATCH v9 04/46] media: uapi: Add generic serial metadata mbus formats Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 05/46] media: uapi: Document which mbus format fields are valid for metadata Sakari Ailus
2024-04-19 16:05   ` Laurent Pinchart
2024-04-16 19:32 ` [PATCH v9 06/46] media: uapi: v4l: Add generic 8-bit metadata format definitions Sakari Ailus
2024-04-19 16:26   ` Laurent Pinchart
2024-04-23  7:04     ` Sakari Ailus
2024-04-23  7:32       ` Laurent Pinchart
2024-04-23  9:54         ` Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 07/46] media: v4l: Support line-based metadata capture Sakari Ailus
2024-04-19 16:30   ` Laurent Pinchart
2024-04-23  7:31     ` Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 08/46] media: Documentation: Additional streams generally don't harm capture Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 09/46] media: Documentation: Document embedded data guidelines for camera sensors Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 10/46] media: Documentation: v4l: Document internal sink pads Sakari Ailus
2024-04-19 18:49   ` Laurent Pinchart
2024-04-23 10:27     ` Sakari Ailus
2024-04-23 12:56       ` Laurent Pinchart
2024-04-23 16:06         ` Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 11/46] media: Documentation: Document S_ROUTING behaviour Sakari Ailus
2024-04-19 17:17   ` Laurent Pinchart
2024-04-23 10:08     ` Sakari Ailus
2024-04-23 12:59       ` Laurent Pinchart
2024-04-23 13:33         ` Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 12/46] media: v4l: subdev: Add a function to lock two sub-device states, use it Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 13/46] media: v4l: subdev: Move G_ROUTING handling below S_ROUTING Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 14/46] media: v4l: subdev: Copy argument back to user also for S_ROUTING Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 15/46] media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing Sakari Ailus
2024-04-19 22:45   ` Laurent Pinchart
2024-04-23 10:45     ` Sakari Ailus
2024-04-23 12:54       ` Laurent Pinchart
2024-04-23 16:05         ` Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 16/46] media: v4l: subdev: Return routes set using S_ROUTING Sakari Ailus
2024-04-19 22:55   ` Laurent Pinchart
2024-04-23 10:49     ` Sakari Ailus
2024-04-23 11:41       ` Laurent Pinchart
2024-04-16 19:32 ` [PATCH v9 17/46] media: v4l: subdev: Add trivial set_routing support Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 18/46] media: ccs: No need to set streaming to false in power off Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 19/46] media: ccs: Move ccs_pm_get_init function up Sakari Ailus
2024-04-20  7:53   ` Laurent Pinchart
2024-04-16 19:32 ` [PATCH v9 20/46] media: ccs: Rename out label of ccs_start_streaming Sakari Ailus
2024-04-20  8:01   ` Laurent Pinchart
2024-04-16 19:32 ` [PATCH v9 21/46] media: ccs: Use {enable,disable}_streams operations Sakari Ailus
2024-04-20  7:57   ` Laurent Pinchart
2024-04-16 19:32 ` [PATCH v9 22/46] media: ccs: Track streaming state Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 23/46] media: ccs: Move ccs_validate_csi_data_format up Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 24/46] media: ccs: Support frame descriptors Sakari Ailus
2024-04-20  8:00   ` Laurent Pinchart
2024-04-16 19:32 ` [PATCH v9 25/46] media: uapi: v4l: subdev: Enable streams API Sakari Ailus
2024-04-16 19:32 ` [PATCH v9 26/46] media: mc: Add INTERNAL pad flag Sakari Ailus
2024-04-16 19:33 ` [PATCH v9 27/46] media: uapi: ccs: Add media bus code for MIPI CCS embedded data Sakari Ailus
2024-04-20  8:10   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 28/46] media: Documentation: Document non-CCS use of CCS embedded data format Sakari Ailus
2024-04-20  8:12   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 29/46] media: Documentation: ccs: Document routing Sakari Ailus
2024-04-20  8:31   ` Laurent Pinchart
2024-04-23 11:06     ` Sakari Ailus
2024-04-16 19:33 ` [PATCH v9 30/46] media: ccs: Add support for embedded data stream Sakari Ailus
2024-04-20  8:59   ` Laurent Pinchart
2024-04-23 12:33     ` Sakari Ailus
2024-04-23 12:50       ` Laurent Pinchart
2024-04-23 13:29         ` Sakari Ailus
2024-04-16 19:33 ` [PATCH v9 31/46] media: ccs: Remove ccs_get_crop_compose helper Sakari Ailus
2024-04-20  9:04   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 32/46] media: ccs: Rely on sub-device state locking Sakari Ailus
2024-04-20  9:16   ` Laurent Pinchart
2024-04-16 19:33 ` Sakari Ailus [this message]
2024-04-20  9:19   ` [PATCH v9 33/46] media: ccs: Compute binning configuration from sub-device state Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 34/46] media: ccs: Compute scaling " Sakari Ailus
2024-04-20  9:24   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 35/46] media: ccs: Remove which parameter from ccs_propagate Sakari Ailus
2024-04-16 19:33 ` [PATCH v9 36/46] media: uapi: Add media bus code for ov2740 embedded data Sakari Ailus
2024-04-20  9:29   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 37/46] media: ov2740: Fix LINK_FREQ and PIXEL_RATE control value reporting Sakari Ailus
2024-04-20  9:42   ` Laurent Pinchart
2024-04-24  9:15     ` Sakari Ailus
2024-04-16 19:33 ` [PATCH v9 38/46] media: ov2740: Remove shorthand variables Sakari Ailus
2024-04-20  9:30   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 39/46] media: ov2740: Switch to {enable,disable}_streams Sakari Ailus
2024-04-16 19:33 ` [PATCH v9 40/46] media: ov2740: Track streaming state Sakari Ailus
2024-04-16 19:33 ` [PATCH v9 41/46] media: ov2740: Add support for embedded data Sakari Ailus
2024-04-20  9:38   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 42/46] media: ov2740: Add generic sensor fwnode properties as controls Sakari Ailus
2024-04-20  9:40   ` Laurent Pinchart
2024-04-23 16:17     ` Sakari Ailus
2024-04-24  8:51       ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 43/46] media: ov2740: Add support for G_SELECTION IOCTL Sakari Ailus
2024-04-20  9:43   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 44/46] media: v4l: Add V4L2_SUBDEV_ROUTE_FL_IMMUTABLE sub-device routing flag Sakari Ailus
2024-04-20  9:49   ` Laurent Pinchart
2024-04-16 19:33 ` [PATCH v9 45/46] media: ccs: Add IMMUTABLE route flag Sakari Ailus
2024-04-16 19:33 ` [PATCH v9 46/46] media: ov2740: " Sakari Ailus
2024-04-20 10:05 ` [PATCH v9 00/46] Generic line based metadata support, internal pads Laurent Pinchart

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=20240416193319.778192-34-sakari.ailus@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=alain.volmat@foss.st.com \
    --cc=andrey.konovalov@linaro.org \
    --cc=bingbu.cao@intel.com \
    --cc=dmitry.perchanov@intel.com \
    --cc=hongju.wang@intel.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=khai.wen.ng@intel.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=tomi.valkeinen@ideasonboard.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.