media: imx6-mipi-csi2: Call remote subdev get_mbus_config to get active lanes
PATCH v2 1/1 media: imx6-mipi-csi2: Call remote subdev get_mbus_config to get active lanes
Currently, the CSI2 subdevice is using the data-lanes from the neareast endpoint to config the CSI2 lanes.
While this may work, the proper way to configure the hardware is to obtain the remote subdevice in v4l2_async_notifier_operations.bound(), and then call get_mbus_config using the remote subdevice to get the active lanes.
--- drivers/staging/media/imx/TODO | 12 --- drivers/staging/media/imx/imx6-mipi-csi2.c | 99 +++++++++++++++++++--- 2 files changed, 87 insertions(+), 24 deletions(-)
drivers/staging/media/imx/TODO +0 -12
@@ -2,18 +2,6 @@ - The Frame Interval Monitor could be exported to v4l2-core for general use. -- The CSI subdevice parses its nearest upstream neighbor's device-tree - bus config in order to setup the CSI. Laurent Pinchart argues that - instead the CSI subdev should call its neighbor's g_mbus_config op - (which should be propagated if necessary) to get this info. However - Hans Verkuil is planning to remove the g_mbus_config op. For now this - driver uses the parsed DT bus config method until this issue is - resolved. - - 2020-06: g_mbus has been removed in favour of the get_mbus_config pad - operation which should be used to avoid parsing the remote endpoint - configuration. - - This media driver supports inheriting V4L2 controls to the video capture devices, from the subdevices in the capture device's pipeline. The controls for each capture device are updated in the
drivers/staging/media/imx/imx6-mipi-csi2.c +87 -12
159 lines not on this page · raw message
Signature · 1 line
2.29.2
Hi Ezequiel,
thank you for picking this up.
Quoted 10 lines · Ezequiel Garcia
Currently, the CSI2 subdevice is using the data-lanes from the neareast endpoint to config the CSI2 lanes.
While this may work, the proper way to configure the hardware is to obtain the remote subdevice in
v4l2_async_notifier_operations.bound(), and then callget_mbus_configusing the remote subdevice to get the active lanes.Signed-off-by Ezequiel Garcia <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>
Same comment as Laurent, csi2_get_active_lanes() looks to be the same as rcsi2_get_active_lanes() in rcar-csi2, so this could benefit from a common helper (later).
Quoted 32 lines
--- drivers/staging/media/imx/TODO | 12 --- drivers/staging/media/imx/imx6-mipi-csi2.c | 99 +++++++++++++++++++--- 2 files changed, 87 insertions(+), 24 deletions(-)drivers/staging/media/imx/TODO +0
-12@@ -2,18 +2,6 @@ - The Frame Interval Monitor could be exported to v4l2-core for general use. -- The CSI subdevice parses its nearest upstream neighbor's device-tree - bus config in order to setup the CSI. Laurent Pinchart argues that - instead the CSI subdev should call its neighbor's g_mbus_config op - (which should be propagated if necessary) to get this info. However - Hans Verkuil is planning to remove the g_mbus_config op. For now this - driver uses the parsed DT bus config method until this issue is - resolved. - - 2020-06: g_mbus has been removed in favour of the get_mbus_config pad - operation which should be used to avoid parsing the remote endpoint - configuration. - - This media driver supports inheriting V4L2 controls to the video capture devices, from the subdevices in the capture device's pipeline. The controls for each capture device are updated in thedrivers/staging/media/imx/imx6-mipi-csi2.c +0
-0
[...]
Quoted 28 lines
drivers/staging/media/imx/imx6-mipi-csi2.c +24
-0@@ -300,8 +300,56 @@ static void csi2ipu_gasket_init(struct csi2_dev *csi2)writel (reg, csi2->base +CSI2IPU_GASKET ); } +static int csi2_get_active_lanes (struct csi2_dev *csi2,unsigned int *lanes) +{ +struct v4l2_mbus_config mbus_config = {0 }; +unsigned int num_lanes =UINT_MAX ; +int ret; + + *lanes = csi2->data_lanes; + + ret =v4l2_subdev_call (csi2->remote, pad, get_mbus_config, + csi2->remote_pad, &mbus_config); +if (ret == -ENOIOCTLCMD ) { +dev_dbg (csi2->dev,"No remote mbus configuration available\n" ); +return 0 ; + } + +if (ret) { +dev_err (csi2->dev,"Failed to get remote mbus configuration\n" ); +return ret; + } + +if (mbus_config.type !=V4L2_MBUS_CSI2_DPHY ) { +dev_err (csi2->dev,"Unsupported media bus type %u\n" , + mbus_config.type); +return -EINVAL ;
drivers/staging/media/imx/imx6-mipi-csi2.c static void csi2ipu_gasket_init(struct csi2_dev *csi2) · line 336
Quoted 10 lines
drivers/staging/media/imx/imx6-mipi-csi2.c +10
-0+ } + +if (mbus_config.flags &V4L2_MBUS_CSI2_1_LANE ) + num_lanes =1 ; +else if (mbus_config.flags &V4L2_MBUS_CSI2_2_LANE ) + num_lanes =2 ; +else if (mbus_config.flags &V4L2_MBUS_CSI2_3_LANE ) + num_lanes =3 ; +else if (mbus_config.flags &V4L2_MBUS_CSI2_4_LANE ) + num_lanes =4 ;
I'd turn this into a
switch (mbus_config.flags & V4L2_MBUS_CSI2_LANES) { }to catch erroneous values of 0 or multiple bits set, as for those the following error message doesn't make much sense:
drivers/staging/media/imx/imx6-mipi-csi2.c static void csi2ipu_gasket_init(struct csi2_dev *csi2) · line 348
Quoted 11 lines
drivers/staging/media/imx/imx6-mipi-csi2.c +11
-0+if (num_lanes > csi2->data_lanes) { +dev_err (csi2->dev, +"Unsupported mbus config: too many data lanes %u\n" , + num_lanes); +return -EINVAL ; + } + + *lanes = num_lanes; + +return 0 ; +}
Still, this patch looks good to me.
regards
Philipp
Hi Philipp,
Quoted 4 lines · Philipp Zabel
Hi Ezequiel,
thank you for picking this up.
No problem.
Quoted 9 lines · Ezequiel Garcia
Quoted 8 lines
Currently, the CSI2 subdevice is using the data-lanes from the neareast endpoint to config the CSI2 lanes.
While this may work, the proper way to configure the hardware is to obtain the remote subdevice in
v4l2_async_notifier_operations.bound(), and then callget_mbus_configusing the remote subdevice to get the active lanes.
Quoted 9 lines
Quoted 2 lines
Signed-off-by Ezequiel Garcia <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Same comment as Laurent,
csi2_get_active_lanes()looks to be the same asrcsi2_get_active_lanes()in rcar-csi2, so this could benefit from a common helper (later).Reviewed-by Philipp Zabel <[email protected]>
Thanks for the review.
Quoted 68 lines
Quoted 32 lines
---
drivers/staging/media/imx/TODO | 12 ---drivers/staging/media/imx/imx6-mipi-csi2.c| 99 +++++++++++++++++++---2 files changed, 87 insertions(+), 24 deletions(-)drivers/staging/media/imx/TODO +0
-0@@ -2,18 +2,6 @@- The Frame Interval Monitor could be exported to v4l2-core for general use.
-- The CSI subdevice parses its nearest upstream neighbor's device-tree - bus config in order to setup the CSI. Laurent Pinchart argues that - instead the CSI subdev should call its neighbor'sg_mbus_configop - (which should be propagated if necessary) to get this info. However - Hans Verkuil is planning to remove theg_mbus_configop. For now this - driver uses the parsed DT bus config method until this issue is - resolved.drivers/staging/media/imx/TODO +0
-5- - 2020-06: g_mbus has been removed in favour of the get_mbus_config pad - operation which should be used to avoid parsing the remote endpoint - configuration. -- This media driver supports inheriting V4L2 controls to the video capture devices, from the subdevices in the capture device's pipeline. The controls for each capture device are updated in the
drivers/staging/media/imx/imx6-mipi-csi2.c +0
-0[...]
Quoted 35 lines
drivers/staging/media/imx/imx6-mipi-csi2.c +0
-0@@ -300,8 +300,56 @@ static void csi2ipu_gasket_init(struct csi2_dev *csi2) writel(reg, csi2->base + CSI2IPU_GASKET); }drivers/staging/media/imx/imx6-mipi-csi2.c +31
-0+static int csi2_get_active_lanes (struct csi2_dev *csi2,unsigned int *lanes) +{ + struct v4l2_mbus_config mbus_config = { 0 }; + unsigned int num_lanes = UINT_MAX; + int ret; + + *lanes = csi2->data_lanes; + + ret = v4l2_subdev_call(csi2->remote, pad, get_mbus_config, + csi2->remote_pad, &mbus_config); + if (ret == -ENOIOCTLCMD) { + dev_dbg(csi2->dev, "No remote mbus configuration available\n"); + return 0; + } + + if (ret) { + dev_err(csi2->dev, "Failed to get remote mbus configuration\n"); + return ret; + } + + if (mbus_config.type != V4L2_MBUS_CSI2_DPHY) { + dev_err(csi2->dev, "Unsupported media bus type %u\n", + mbus_config.type); + return -EINVAL; + } + + if (mbus_config.flags & V4L2_MBUS_CSI2_1_LANE) + num_lanes = 1; + else if (mbus_config.flags & V4L2_MBUS_CSI2_2_LANE) + num_lanes = 2; + else if (mbus_config.flags & V4L2_MBUS_CSI2_3_LANE)
Quoted 9 lines
Quoted 3 lines
+ num_lanes = 3;
+ else if (mbus_config.flags &V4L2_MBUS_CSI2_4_LANE) + num_lanes = 4;I'd turn this into a
switch (mbus_config.flags &V4L2_MBUS_CSI2_LANES) { } to catch erroneous values of 0 or multiple bits set, as for those the following error message doesn't make much sense:
Makes sense. We can do that later, once we move the function to the core.
Quoted 5 lines
Quoted 5 lines
+ if (
num_lanes>csi2->data_lanes) {
+ dev_err(csi2->dev,
+ "Unsupported mbus config: too many data lanes %u\n", + num_lanes);
+ return-EINVAL;
Quoted 9 lines
drivers/staging/media/imx/imx6-mipi-csi2.c static void csi2ipu_gasket_init(struct csi2_dev *csi2) · line 348
Quoted 6 lines
+ }
drivers/staging/media/imx/imx6-mipi-csi2.c +5
-0+ + *lanes = num_lanes; + + return 0; +}Still, this patch looks good to me.
Thanks,
Ezequiel