Skip to contentSkip to conversation

Explicit CSI-2 LP-11 / LP-111 support

PATCH In review Sakari Ailus 2 participants 6 messages Jun 23, 2021 – Jul 8, 2021

Subsystems (3)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

cover Explicit CSI-2 LP-11 / LP-111 support

Hi all,

Some receiver devices requires explicit support for transitioning transmitters to LP-11 or LP-111 state before starting streaming. As there's currently a single operation (s_stream()) callback to do that, there's no way for the receiver driver to differentiate between the two things.

This set adds two more callbacks, pre_streamon and post_streamon, to do exactly that. The usage on CSI-2 is to set the transmitter state to LP-11 or LP-111 (depending on the PHY) and thus allow reliable receiver initialisation.

The set also adds support for this in the CCS driver.

Sakari Ailus (3):
Documentation: v4l: Rework LP-11 documentation, add callbacks
v4l: subdev: Add pre_streamon and post_streamoff callbacks
ccs: Implement support for manual LP control

 Documentation/driver-api/media/tx-rx.rst | 40 ++++++++++++++-------
 drivers/media/i2c/ccs/ccs-core.c         | 45 ++++++++++++++++++++++++
 include/media/v4l2-subdev.h              | 25 +++++++++++++
 3 files changed, 98 insertions(+), 12 deletions(-)
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 1/3 Documentation: v4l: Rework LP-11 documentation, add callbacks

Rework LP-11 and LP-111 mode documentation to make it more understandable and useful. This involves adding pre_streamon and post_streamon callbacks that make it possible to explicitly transition the transmitter to either mode.

---
 Documentation/driver-api/media/tx-rx.rst | 40 +++++++++++++++++-------
 1 file changed, 28 insertions(+), 12 deletions(-)
Documentation/driver-api/media/tx-rx.rst +28 -12
index 4ba274713a61..706e839e8cec 100644
@@ -93,18 +93,34 @@ where
 LP-11 and LP-111 modes
 ^^^^^^^^^^^^^^^^^^^^^^
 
-The transmitter drivers must, if possible, configure the CSI-2 transmitter to
-*LP-11 or LP-111 mode* whenever the transmitter is powered on but not active,
-and maintain *LP-11 or LP-111 mode* until stream on. Only at stream on time
-should the transmitter activate the clock on the clock lane and transition to
-*HS mode*.
-
-Some transmitters do this automatically but some have to be explicitly
-programmed to do so, and some are unable to do so altogether due to
-hardware constraints.
-
-The receiver thus need to be configured to expect LP-11 or LP-111 mode from the
-transmitter before the transmitter driver's ``.s_stream()`` op is called.
+As part of transitioning to high speed mode, a CSI-2 transmitter typically
+briefly sets the bus to LP-11 or LP-111 state, depending on the PHY. This period
+may be as short as 100 µs, during which the receiver observes this state and
+proceeds its own part of high speed mode transition.
+
+Most receivers are capable of autonomously handling this once the software has
+configured them to do so, but there are receivers which require software
+involvement in observing LP-11 or LP-111 state. 100 µs is a brief period to hit
+in software, especially when there is no interrupt telling something is
+happening.
+
+One way to address this is to configure the transmitter side explicitly to LP-11
+or LP-111 mode, which requires support from the transmitter hardware. This is
+not universally available. Many devices return to this state once streaming is
+stopped while the state after power-on is LP-00 or LP-000.
+
+The ``.pre_streamon()`` callback may be used to prepare a transmitter for
+transitioning to streaming state, but not yet start streaming. Similarly, the
+``.post_streamoff()`` callback is used to undo what was done by the
+``.pre_streamon()`` callback. The caller of ``.pre_streamon()`` is thus required
+to call ``.post_streamoff()`` for each successful call of ``.pre_streamon()``.
+
+In the context of CSI-2, the ``.pre_streamon()`` callback is used to transition
+the transmitter to the LP-11 or LP-111 mode. This also requires powering on the
+device, so this should be only done when it is needed.
+
+Receiver drivers that do not need explicit LP-11 or LP-111 mode setup are waived
+from calling the two callbacks.
 
 Stopping the transmitter
 ^^^^^^^^^^^^^^^^^^^^^^^^
Signature · 1 line
2.30.2
author maintainer
#2 lore raw

PATCH 2/3 v4l: subdev: Add pre_streamon and post_streamoff callbacks

In reply to Sakari Ailus

Add pre_streamon and post_streamoff callbacks that can be used to set a CSI-2 transmitter to LP-11 or LP-111 mode. This can be used by receiver drivers to reliably initialise the receiver when its initialisation requires software involvement.

---
 include/media/v4l2-subdev.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
include/media/v4l2-subdev.h +25 -0
index 5364e3a6ac9b..95ec18c2f49c 100644
@@ -354,6 +354,16 @@ struct v4l2_mbus_frame_desc {
 	unsigned short num_entries;
 };
 
+/**
+ * enum v4l2_subdev_pre_streamon_flags - Flags for pre_streamon subdev core op
+ *
+ * @V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP: Set the transmitter to either LP-11
+ *	or LP-111 mode before call to s_stream().
+ */
+enum v4l2_subdev_pre_streamon_flags {
+	V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP = BIT(0),
+};
+
 /**
  * struct v4l2_subdev_video_ops - Callbacks used when v4l device was opened
  *				  in video mode.
@@ -409,6 +419,19 @@ struct v4l2_mbus_frame_desc {
  * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev
  *	can adjust @size to a lower value and must not write more data to the
  *	buffer starting at @data than the original value of @size.
+ *
+ * @pre_streamon: May be called before streaming is actually started, to help
+ *	initialising the bus. Current usage is to set a CSI-2 transmitter to
+ *	LP-11 or LP-111 mode before streaming. See &enum
+ *	v4l2_subdev_pre_streamon_flags.
+ *
+ *	pre_streamon shall return error if it cannot perform the operation as
+ *	indicated by the flags argument. In particular, -EACCES indicates lack
+ *	of support for the operation. The caller shall call post_streamoff for
+ *	each successful call of pre_streamon.
+ *
+ * @post_streamoff: Called after streaming is stopped, but if and only if
+ *	pre_streamon was called earlier.
  */
 struct v4l2_subdev_video_ops {
 	int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
@@ -435,6 +458,8 @@ struct v4l2_subdev_video_ops {
 			struct v4l2_dv_timings *timings);
 	int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
 			   unsigned int *size);
+	int (*pre_streamon)(struct v4l2_subdev *sd, u32 flags);
+	int (*post_streamoff)(struct v4l2_subdev *sd);
 };
 
 /**
Signature · 1 line
2.30.2
author maintainer
#3 lore raw

PATCH 3/3 ccs: Implement support for manual LP control

In reply to Sakari Ailus

Use the pre_streamon callback to transition the transmitter to either LP-11 or LP-111 mode if supported by the sensor.

---
 drivers/media/i2c/ccs/ccs-core.c | 45 ++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +45 -0
index a9403a227c6b..918be5a020f2 100644
@@ -1943,6 +1943,49 @@ static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
 	return rval;
 }
 
+static int ccs_pre_streamon(struct v4l2_subdev *subdev, u32 flags)
+{
+	struct ccs_sensor *sensor = to_ccs_sensor(subdev);
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int rval;
+
+	switch (sensor->hwcfg.csi_signalling_mode) {
+	case CCS_CSI_SIGNALING_MODE_CSI_2_DPHY:
+		if (!(CCS_LIM(sensor, PHY_CTRL_CAPABILITY_2) &
+		      CCS_PHY_CTRL_CAPABILITY_2_MANUAL_LP_DPHY))
+			return -EACCES;
+		break;
+	case CCS_CSI_SIGNALING_MODE_CSI_2_CPHY:
+		if (!(CCS_LIM(sensor, PHY_CTRL_CAPABILITY_2) &
+		      CCS_PHY_CTRL_CAPABILITY_2_MANUAL_LP_CPHY))
+			return -EACCES;
+		break;
+	default:
+		return -EACCES;
+	}
+
+	rval = ccs_pm_get_init(sensor);
+	if (rval)
+		return rval;
+
+	if (flags & V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP) {
+		rval = ccs_write(sensor, MANUAL_LP_CTRL,
+				 CCS_MANUAL_LP_CTRL_ENABLE);
+		if (rval)
+			pm_runtime_put(&client->dev);
+	}
+
+	return rval;
+}
+
+static int ccs_post_streamoff(struct v4l2_subdev *subdev)
+{
+	struct ccs_sensor *sensor = to_ccs_sensor(subdev);
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+
+	return pm_runtime_put(&client->dev);
+}
+
 static int ccs_enum_mbus_code(struct v4l2_subdev *subdev,
 			      struct v4l2_subdev_state *sd_state,
 			      struct v4l2_subdev_mbus_code_enum *code)
@@ -3058,6 +3101,8 @@ static int ccs_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 
 static const struct v4l2_subdev_video_ops ccs_video_ops = {
 	.s_stream = ccs_set_stream,
+	.pre_streamon = ccs_pre_streamon,
+	.post_streamoff = ccs_post_streamoff,
 };
 
 static const struct v4l2_subdev_pad_ops ccs_pad_ops = {
Signature · 1 line
2.30.2
author maintainer
#4 lore raw

PATCH v2 3/3 ccs: Implement support for manual LP control

Use the pre_streamon callback to transition the transmitter to either LP-11 or LP-111 mode if supported by the sensor.

---
since v1:

- Only check sensor capabilities if manual LP control is requested.

 drivers/media/i2c/ccs/ccs-core.c | 47 ++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +47 -0
index 121cbe406fe4..5363f3bcafe3 100644
@@ -1943,6 +1943,51 @@ static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
 	return rval;
 }
 
+static int ccs_pre_streamon(struct v4l2_subdev *subdev, u32 flags)
+{
+	struct ccs_sensor *sensor = to_ccs_sensor(subdev);
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+	int rval;
+
+	if (flags & V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP) {
+		switch (sensor->hwcfg.csi_signalling_mode) {
+		case CCS_CSI_SIGNALING_MODE_CSI_2_DPHY:
+			if (!(CCS_LIM(sensor, PHY_CTRL_CAPABILITY_2) &
+			      CCS_PHY_CTRL_CAPABILITY_2_MANUAL_LP_DPHY))
+				return -EACCES;
+			break;
+		case CCS_CSI_SIGNALING_MODE_CSI_2_CPHY:
+			if (!(CCS_LIM(sensor, PHY_CTRL_CAPABILITY_2) &
+			      CCS_PHY_CTRL_CAPABILITY_2_MANUAL_LP_CPHY))
+				return -EACCES;
+			break;
+		default:
+			return -EACCES;
+		}
+	}
+
+	rval = ccs_pm_get_init(sensor);
+	if (rval)
+		return rval;
+
+	if (flags & V4L2_SUBDEV_PRE_STREAMON_FL_MANUAL_LP) {
+		rval = ccs_write(sensor, MANUAL_LP_CTRL,
+				 CCS_MANUAL_LP_CTRL_ENABLE);
+		if (rval)
+			pm_runtime_put(&client->dev);
+	}
+
+	return rval;
+}
+
+static int ccs_post_streamoff(struct v4l2_subdev *subdev)
+{
+	struct ccs_sensor *sensor = to_ccs_sensor(subdev);
+	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
+
+	return pm_runtime_put(&client->dev);
+}
+
 static int ccs_enum_mbus_code(struct v4l2_subdev *subdev,
 			      struct v4l2_subdev_state *sd_state,
 			      struct v4l2_subdev_mbus_code_enum *code)
@@ -3055,6 +3100,8 @@ static int ccs_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 
 static const struct v4l2_subdev_video_ops ccs_video_ops = {
 	.s_stream = ccs_set_stream,
+	.pre_streamon = ccs_pre_streamon,
+	.post_streamoff = ccs_post_streamoff,
 };
 
 static const struct v4l2_subdev_pad_ops ccs_pad_ops = {
Signature · 1 line
2.30.2
#5 lore raw
In reply to Sakari Ailus
Quoted 8 lines · Sakari Ailus

Hi all,

Some receiver devices requires explicit support for transitioning transmitters to LP-11 or LP-111 state before starting streaming. As there's currently a single operation (s_stream()) callback to do that, there's no way for the receiver driver to differentiate between the two things.

Quoted 6 lines

This set adds two more callbacks, pre_streamon and post_streamon, to do exactly that. The usage on CSI-2 is to set the transmitter state to LP-11 or LP-111 (depending on the PHY) and thus allow reliable receiver initialisation.

The set also adds support for this in the CCS driver.

I forgot to mention the set goes on top of my earlier patches I sent recently. This is all here:

https://git.linuxtv.org/sailus/media_tree.git/ camera-stuff

Signature · 1 line
Sakari Ailus