All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
	"Jacopo Mondi" <jacopo@jmondi.org>,
	"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
	"Thomas Nizan" <tnizan@witekio.com>
Subject: [PATCH v2 05/11] media: i2c: max9286: Support manual framesync operation
Date: Sat,  1 Jan 2022 20:28:00 +0200	[thread overview]
Message-ID: <20220101182806.19311-6-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <20220101182806.19311-1-laurent.pinchart+renesas@ideasonboard.com>

The MAX9286 can generate a framesync signal to synchronize the cameras,
using an internal timer. Support this mode of operation and configure it
through the .s_frameinterval() operation. If the frame interval is not
0, framesync is switched to manual mode with the specified interval,
otherwise automatic mode is used.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
Changes since v1:

- Use pixel rate to calculate frame sync counter
---
 drivers/media/i2c/max9286.c | 84 +++++++++++++++++++++++++++++++++----
 1 file changed, 75 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index 15c80034e3a4..75374034724f 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -170,9 +170,11 @@ struct max9286_priv {
 	u32 rev_chan_mv;
 
 	struct v4l2_ctrl_handler ctrls;
-	struct v4l2_ctrl *pixelrate;
+	struct v4l2_ctrl *pixelrate_ctrl;
+	unsigned int pixelrate;
 
 	struct v4l2_mbus_framefmt fmt[MAX9286_N_SINKS];
+	struct v4l2_fract interval;
 
 	/* Protects controls and fmt structures */
 	struct mutex mutex;
@@ -473,6 +475,40 @@ static int max9286_check_config_link(struct max9286_priv *priv,
 	return 0;
 }
 
+static void max9286_set_fsync_period(struct max9286_priv *priv)
+{
+	u32 fsync;
+
+	if (!priv->interval.numerator || !priv->interval.denominator) {
+		/*
+		 * Special case, a null interval enables automatic FRAMESYNC
+		 * mode. FRAMESYNC is taken from the slowest link.
+		 */
+		max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_HIZ |
+			      MAX9286_FSYNCMETH_AUTO);
+		return;
+	}
+
+	/*
+	 * Manual FRAMESYNC
+	 *
+	 * The FRAMESYNC generator is configured with a period expressed as a
+	 * number of PCLK periods.
+	 */
+	fsync = div_u64((u64)priv->pixelrate * priv->interval.numerator,
+			priv->interval.denominator);
+
+	dev_dbg(&priv->client->dev, "fsync period %u (pclk %u)\n", fsync,
+		priv->pixelrate);
+
+	max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_OUT |
+		      MAX9286_FSYNCMETH_MANUAL);
+
+	max9286_write(priv, 0x06, (fsync >> 0) & 0xff);
+	max9286_write(priv, 0x07, (fsync >> 8) & 0xff);
+	max9286_write(priv, 0x08, (fsync >> 16) & 0xff);
+}
+
 /* -----------------------------------------------------------------------------
  * V4L2 Subdev
  */
@@ -511,11 +547,13 @@ static int max9286_set_pixelrate(struct max9286_priv *priv)
 		return -EINVAL;
 	}
 
+	priv->pixelrate = pixelrate;
+
 	/*
 	 * The CSI-2 transmitter pixel rate is the single source rate multiplied
 	 * by the number of available sources.
 	 */
-	return v4l2_ctrl_s_ctrl_int64(priv->pixelrate,
+	return v4l2_ctrl_s_ctrl_int64(priv->pixelrate_ctrl,
 				      pixelrate * priv->nsources);
 }
 
@@ -655,6 +693,8 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
+		max9286_set_fsync_period(priv);
+
 		/*
 		 * The frame sync between cameras is transmitted across the
 		 * reverse channel as GPIO. We must open all channels while
@@ -714,6 +754,32 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	return 0;
 }
 
+static int max9286_g_frame_interval(struct v4l2_subdev *sd,
+				    struct v4l2_subdev_frame_interval *interval)
+{
+	struct max9286_priv *priv = sd_to_max9286(sd);
+
+	if (interval->pad != MAX9286_SRC_PAD)
+		return -EINVAL;
+
+	interval->interval = priv->interval;
+
+	return 0;
+}
+
+static int max9286_s_frame_interval(struct v4l2_subdev *sd,
+				    struct v4l2_subdev_frame_interval *interval)
+{
+	struct max9286_priv *priv = sd_to_max9286(sd);
+
+	if (interval->pad != MAX9286_SRC_PAD)
+		return -EINVAL;
+
+	priv->interval = interval->interval;
+
+	return 0;
+}
+
 static int max9286_enum_mbus_code(struct v4l2_subdev *sd,
 				  struct v4l2_subdev_state *sd_state,
 				  struct v4l2_subdev_mbus_code_enum *code)
@@ -805,6 +871,8 @@ static int max9286_get_fmt(struct v4l2_subdev *sd,
 
 static const struct v4l2_subdev_video_ops max9286_video_ops = {
 	.s_stream	= max9286_s_stream,
+	.g_frame_interval = max9286_g_frame_interval,
+	.s_frame_interval = max9286_s_frame_interval,
 };
 
 static const struct v4l2_subdev_pad_ops max9286_pad_ops = {
@@ -885,10 +953,10 @@ static int max9286_v4l2_register(struct max9286_priv *priv)
 	priv->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 
 	v4l2_ctrl_handler_init(&priv->ctrls, 1);
-	priv->pixelrate = v4l2_ctrl_new_std(&priv->ctrls,
-					    &max9286_ctrl_ops,
-					    V4L2_CID_PIXEL_RATE,
-					    1, INT_MAX, 1, 50000000);
+	priv->pixelrate_ctrl = v4l2_ctrl_new_std(&priv->ctrls,
+						 &max9286_ctrl_ops,
+						 V4L2_CID_PIXEL_RATE,
+						 1, INT_MAX, 1, 50000000);
 
 	priv->sd.ctrl_handler = &priv->ctrls;
 	ret = priv->ctrls.error;
@@ -997,9 +1065,7 @@ static int max9286_setup(struct max9286_priv *priv)
 		      MAX9286_CSILANECNT(priv->csi2_data_lanes) |
 		      MAX9286_DATATYPE_YUV422_8BIT);
 
-	/* Automatic: FRAMESYNC taken from the slowest Link. */
-	max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_HIZ |
-		      MAX9286_FSYNCMETH_AUTO);
+	max9286_set_fsync_period(priv);
 
 	/* Enable HS/VS encoding, use D14/15 for HS/VS, invert VS. */
 	max9286_write(priv, 0x0c, MAX9286_HVEN | MAX9286_INVVS |
-- 
Regards,

Laurent Pinchart


  parent reply	other threads:[~2022-01-01 18:28 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-01 18:27 [PATCH v2 00/11] media: i2c: max9286: Small new features Laurent Pinchart
2022-01-01 18:27 ` [PATCH v2 01/11] dt-bindings: media: i2c: max9286: Add support for per-port supplies Laurent Pinchart
2022-01-09 11:48   ` Jacopo Mondi
2022-01-10 20:47   ` Rob Herring
2022-01-01 18:27 ` [PATCH v2 02/11] dt-bindings: media: i2c: max9286: Add property to select I2C speed Laurent Pinchart
2022-01-01 22:01   ` Rob Herring
2022-01-04 15:56   ` Rob Herring
2022-01-01 18:27 ` [PATCH v2 03/11] dt-bindings: media: i2c: max9286: Add property to select bus width Laurent Pinchart
2022-01-09 11:47   ` Jacopo Mondi
2022-01-10 20:53   ` Rob Herring
2022-01-10 21:24   ` [PATCH v2.1 " Laurent Pinchart
2022-01-22  0:28     ` Rob Herring
2022-01-01 18:27 ` [PATCH v2 04/11] media: i2c: max9286: Add support for port regulators Laurent Pinchart
2022-01-09 10:04   ` Jacopo Mondi
2022-01-09 23:16     ` Laurent Pinchart
2022-01-01 18:28 ` Laurent Pinchart [this message]
2022-01-09 10:26   ` [PATCH v2 05/11] media: i2c: max9286: Support manual framesync operation Jacopo Mondi
2022-01-01 18:28 ` [PATCH v2 06/11] media: i2c: max9286: Rename MAX9286_DATATYPE_RAW11 to RAW12 Laurent Pinchart
2022-01-09 10:26   ` Jacopo Mondi
2022-01-01 18:28 ` [PATCH v2 07/11] media: i2c: max9286: Support 12-bit raw bayer formats Laurent Pinchart
2022-01-09 10:34   ` Jacopo Mondi
2022-01-09 23:19     ` Laurent Pinchart
2022-01-01 18:28 ` [PATCH v2 08/11] media: i2c: max9286: Define macros for all bits of register 0x15 Laurent Pinchart
2022-01-09 10:37   ` Jacopo Mondi
2022-01-09 23:21     ` Laurent Pinchart
2022-01-10 10:37       ` Sergey Shtylyov
2022-01-10 11:32         ` Laurent Pinchart
2022-01-01 18:28 ` [PATCH v2 09/11] media: i2c: max9286: Configure remote I2C speed from device tree Laurent Pinchart
2022-01-09 10:43   ` Jacopo Mondi
2022-01-09 23:29     ` Laurent Pinchart
2022-01-01 18:28 ` [PATCH v2 10/11] media: i2c: max9286: Configure bus width " Laurent Pinchart
2022-01-09 10:56   ` Jacopo Mondi
2022-01-09 23:32     ` Laurent Pinchart
2022-01-01 18:28 ` [PATCH v2 11/11] media: i2c: max9286: Select HS as data enable signal Laurent Pinchart
2022-01-09 11:42   ` Jacopo Mondi
2022-01-01 23:26 ` [PATCH v2 12/11] media: i2c: max9286: Print power-up GMSL link configuration Laurent Pinchart
2022-01-09 11:44   ` Jacopo Mondi

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=20220101182806.19311-6-laurent.pinchart+renesas@ideasonboard.com \
    --to=laurent.pinchart+renesas@ideasonboard.com \
    --cc=jacopo@jmondi.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=tnizan@witekio.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.