Skip to contentSkip to conversation

media: i2c: mt9m114: Add get_fwnode_pad operation for IFP

PATCH In review Svyatoslav Ryhel 2 participants 5 messages Oct 6 – Nov 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover media: i2c: mt9m114: Add get_fwnode_pad operation for IFP

Currently, the driver's binding exposes only one endpoint, which maps to the IFP subdevice's SOURCE pad. This configuration causes failures for many devices using this camera because both the DT binding and the one-to-one pad mapping logic map the endpoint to the wrong pad. Fix this by implementing the get_fwnode_pad operation for the IFP, which correctly matches the endpoint to the corresponding IFP pad.

---
Changes in v2:
- adjusted coding style as asked by Laurent Pinchart
---

Svyatoslav Ryhel (1):
media: i2c: mt9m114: Add get_fwnode_pad operation for IFP

 drivers/media/i2c/mt9m114.c | 39 +++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/1 media: i2c: mt9m114: Add get_fwnode_pad operation for IFP

Currently, the driver's binding exposes only one endpoint, which maps to the IFP subdevice's SOURCE pad. This configuration causes failures for many devices using this camera because both the DT binding and the one-to-one pad mapping logic map the endpoint to the wrong pad. Fix this by implementing the get_fwnode_pad operation for the IFP, which correctly matches the endpoint to the corresponding IFP pad.

---
 drivers/media/i2c/mt9m114.c | 39 +++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
drivers/media/i2c/mt9m114.c +29 -10
index c6c950d5c8f3d..583cf47aa652e 100644
@@ -9,6 +9,7 @@
  * itself based on work from Andrew Chew <[email protected]>.
  */
 
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
@@ -1019,14 +1020,6 @@ static int mt9m114_stop_streaming(struct mt9m114 *sensor)
 	return ret;
 }
 
-/* -----------------------------------------------------------------------------
- * Common Subdev Operations
- */
-
-static const struct media_entity_operations mt9m114_entity_ops = {
-	.link_validate = v4l2_subdev_link_validate,
-};
-
 /* -----------------------------------------------------------------------------
  * Pixel Array Control Operations
  */
@@ -1383,6 +1376,10 @@ static const struct v4l2_subdev_internal_ops mt9m114_pa_internal_ops = {
 	.init_state = mt9m114_pa_init_state,
 };
 
+static const struct media_entity_operations mt9m114_pa_entity_ops = {
+	.link_validate = v4l2_subdev_link_validate,
+};
+
 static int mt9m114_pa_init(struct mt9m114 *sensor)
 {
 	struct v4l2_ctrl_handler *hdl = &sensor->pa.hdl;
@@ -1405,7 +1402,7 @@ static int mt9m114_pa_init(struct mt9m114 *sensor)
 
 	/* Initialize the media entity. */
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-	sd->entity.ops = &mt9m114_entity_ops;
+	sd->entity.ops = &mt9m114_pa_entity_ops;
 	pads[0].flags = MEDIA_PAD_FL_SOURCE;
 	ret = media_entity_pads_init(&sd->entity, 1, pads);
 	if (ret < 0)
@@ -2097,6 +2094,23 @@ static int mt9m114_ifp_registered(struct v4l2_subdev *sd)
 	return 0;
 }
 
+/*
+ * The IFP has only one fwnode endpoint, which corresponds to the pad
+ * linked to the PA (PA SINK), while it should be the SOURCE for the
+ * next media device in the pipe.
+ */
+static int mt9m114_ifp_get_fwnode_pad(struct media_entity *entity,
+				      struct fwnode_endpoint *endpoint)
+{
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+	struct mt9m114 *sensor = ifp_to_mt9m114(sd);
+	struct fwnode_handle *fwnode = dev_fwnode(&sensor->client->dev);
+	struct fwnode_handle *ifp_ep __free(fwnode_handle) =
+		fwnode_graph_get_next_endpoint(fwnode, NULL);
+
+	return endpoint->local_fwnode == ifp_ep ? 1 : -ENXIO;
+}
+
 static const struct v4l2_subdev_video_ops mt9m114_ifp_video_ops = {
 	.s_stream = mt9m114_ifp_s_stream,
 };
@@ -2124,6 +2138,11 @@ static const struct v4l2_subdev_internal_ops mt9m114_ifp_internal_ops = {
 	.unregistered = mt9m114_ifp_unregistered,
 };
 
+static const struct media_entity_operations mt9m114_ifp_entity_ops = {
+	.link_validate = v4l2_subdev_link_validate,
+	.get_fwnode_pad = mt9m114_ifp_get_fwnode_pad,
+};
+
 static int mt9m114_ifp_init(struct mt9m114 *sensor)
 {
 	struct v4l2_subdev *sd = &sensor->ifp.sd;
@@ -2141,7 +2160,7 @@ static int mt9m114_ifp_init(struct mt9m114 *sensor)
 
 	/* Initialize the media entity. */
 	sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
-	sd->entity.ops = &mt9m114_entity_ops;
+	sd->entity.ops = &mt9m114_ifp_entity_ops;
 	pads[0].flags = MEDIA_PAD_FL_SINK;
 	pads[1].flags = MEDIA_PAD_FL_SOURCE;
 	ret = media_entity_pads_init(&sd->entity, 2, pads);
Signature · 1 line
2.53.0
maintainer
#2 lore raw
Quoted 6 lines · Svyatoslav Ryhel

Currently, the driver's binding exposes only one endpoint, which maps to the IFP subdevice's SOURCE pad. This configuration causes failures for many devices using this camera because both the DT binding and the one-to-one pad mapping logic map the endpoint to the wrong pad. Fix this by implementing the get_fwnode_pad operation for the IFP, which correctly matches the endpoint to the corresponding IFP pad.

The discussion in the review of v1 died out after my last reply. Let's continue it there.

https://lore.kernel.org/linux-media/[email protected]/

Quoted 100 lines
---
 drivers/media/i2c/mt9m114.c | 39 +++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
drivers/media/i2c/mt9m114.c +29 -10
index c6c950d5c8f3d..583cf47aa652e 100644
@@ -9,6 +9,7 @@
  * itself based on work from Andrew Chew <[email protected]>.
  */
 
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
@@ -1019,14 +1020,6 @@ static int mt9m114_stop_streaming(struct mt9m114 *sensor)
 	return ret;
 }
 
-/* -----------------------------------------------------------------------------
- * Common Subdev Operations
- */
-
-static const struct media_entity_operations mt9m114_entity_ops = {
-	.link_validate = v4l2_subdev_link_validate,
-};
-
 /* -----------------------------------------------------------------------------
  * Pixel Array Control Operations
  */
@@ -1383,6 +1376,10 @@ static const struct v4l2_subdev_internal_ops mt9m114_pa_internal_ops = {
 	.init_state = mt9m114_pa_init_state,
 };
 
+static const struct media_entity_operations mt9m114_pa_entity_ops = {
+	.link_validate = v4l2_subdev_link_validate,
+};
+
 static int mt9m114_pa_init(struct mt9m114 *sensor)
 {
 	struct v4l2_ctrl_handler *hdl = &sensor->pa.hdl;
@@ -1405,7 +1402,7 @@ static int mt9m114_pa_init(struct mt9m114 *sensor)
 
 	/* Initialize the media entity. */
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-	sd->entity.ops = &mt9m114_entity_ops;
+	sd->entity.ops = &mt9m114_pa_entity_ops;
 	pads[0].flags = MEDIA_PAD_FL_SOURCE;
 	ret = media_entity_pads_init(&sd->entity, 1, pads);
 	if (ret < 0)
@@ -2097,6 +2094,23 @@ static int mt9m114_ifp_registered(struct v4l2_subdev *sd)
 	return 0;
 }
 
+/*
+ * The IFP has only one fwnode endpoint, which corresponds to the pad
+ * linked to the PA (PA SINK), while it should be the SOURCE for the
+ * next media device in the pipe.
+ */
+static int mt9m114_ifp_get_fwnode_pad(struct media_entity *entity,
+				      struct fwnode_endpoint *endpoint)
+{
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+	struct mt9m114 *sensor = ifp_to_mt9m114(sd);
+	struct fwnode_handle *fwnode = dev_fwnode(&sensor->client->dev);
+	struct fwnode_handle *ifp_ep __free(fwnode_handle) =
+		fwnode_graph_get_next_endpoint(fwnode, NULL);
+
+	return endpoint->local_fwnode == ifp_ep ? 1 : -ENXIO;
+}
+
 static const struct v4l2_subdev_video_ops mt9m114_ifp_video_ops = {
 	.s_stream = mt9m114_ifp_s_stream,
 };
@@ -2124,6 +2138,11 @@ static const struct v4l2_subdev_internal_ops mt9m114_ifp_internal_ops = {
 	.unregistered = mt9m114_ifp_unregistered,
 };
 
+static const struct media_entity_operations mt9m114_ifp_entity_ops = {
+	.link_validate = v4l2_subdev_link_validate,
+	.get_fwnode_pad = mt9m114_ifp_get_fwnode_pad,
+};
+
 static int mt9m114_ifp_init(struct mt9m114 *sensor)
 {
 	struct v4l2_subdev *sd = &sensor->ifp.sd;
@@ -2141,7 +2160,7 @@ static int mt9m114_ifp_init(struct mt9m114 *sensor)
 
 	/* Initialize the media entity. */
 	sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
-	sd->entity.ops = &mt9m114_entity_ops;
+	sd->entity.ops = &mt9m114_ifp_entity_ops;
 	pads[0].flags = MEDIA_PAD_FL_SINK;
 	pads[1].flags = MEDIA_PAD_FL_SOURCE;
 	ret = media_entity_pads_init(&sd->entity, 2, pads);
Signature · 1 line
2.53.0
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

пт, 20 лист. 2026 р. о 23:31 Laurent Pinchart
<[email protected]> пише:

Quoted 9 lines · Svyatoslav Ryhel
Quoted 6 lines

Currently, the driver's binding exposes only one endpoint, which maps to the IFP subdevice's SOURCE pad. This configuration causes failures for many devices using this camera because both the DT binding and the one-to-one pad mapping logic map the endpoint to the wrong pad. Fix this by implementing the get_fwnode_pad operation for the IFP, which correctly matches the endpoint to the corresponding IFP pad.

Quoted 5 lines

The discussion in the review of v1 died out after my last reply. Let's continue it there.

https://lore.kernel.org/linux-media/[email protected]/

Yes, sure. Mt9m114 has only one fw endpoint which co-responds to pad 0 of IFP, pad 0 of IFP is sink. Implementing get_fwnode_pad() allows to map endpoint to source pad (pad 1), the sink pad is linked to PA internally.

Quoted 105 lines
Quoted 98 lines
---
 drivers/media/i2c/mt9m114.c | 39 +++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
drivers/media/i2c/mt9m114.c +29 -11
index c6c950d5c8f3d..583cf47aa652e 100644
@@ -9,6 +9,7 @@
  * itself based on work from Andrew Chew <[email protected]>.
  */
 
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
@@ -1019,14 +1020,6 @@ static int mt9m114_stop_streaming(struct mt9m114 *sensor)
      return ret;
 }
 
-/* -----------------------------------------------------------------------------
- * Common Subdev Operations
- */
-
-static const struct media_entity_operations mt9m114_entity_ops = {
-     .link_validate = v4l2_subdev_link_validate,
-};
-
 /* -----------------------------------------------------------------------------
  * Pixel Array Control Operations
  */
@@ -1383,6 +1376,10 @@ static const struct v4l2_subdev_internal_ops mt9m114_pa_internal_ops = {
      .init_state = mt9m114_pa_init_state,
 };
 
+static const struct media_entity_operations mt9m114_pa_entity_ops = {
+     .link_validate = v4l2_subdev_link_validate,
+};
+
 static int mt9m114_pa_init(struct mt9m114 *sensor)
 {
      struct v4l2_ctrl_handler *hdl = &sensor->pa.hdl;
@@ -1405,7 +1402,7 @@ static int mt9m114_pa_init(struct mt9m114 *sensor)
 
      /* Initialize the media entity. */
      sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-     sd->entity.ops = &mt9m114_entity_ops;
+     sd->entity.ops = &mt9m114_pa_entity_ops;
      pads[0].flags = MEDIA_PAD_FL_SOURCE;
      ret = media_entity_pads_init(&sd->entity, 1, pads);
      if (ret < 0)
@@ -2097,6 +2094,23 @@ static int mt9m114_ifp_registered(struct v4l2_subdev *sd)
      return 0;
 }
 
+/*
+ * The IFP has only one fwnode endpoint, which corresponds to the pad
+ * linked to the PA (PA SINK), while it should be the SOURCE for the
+ * next media device in the pipe.
+ */
+static int mt9m114_ifp_get_fwnode_pad(struct media_entity *entity,
+                                   struct fwnode_endpoint *endpoint)
+{
+     struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+     struct mt9m114 *sensor = ifp_to_mt9m114(sd);
+     struct fwnode_handle *fwnode = dev_fwnode(&sensor->client->dev);
+     struct fwnode_handle *ifp_ep __free(fwnode_handle) =
+             fwnode_graph_get_next_endpoint(fwnode, NULL);
+
+     return endpoint->local_fwnode == ifp_ep ? 1 : -ENXIO;
+}
+
 static const struct v4l2_subdev_video_ops mt9m114_ifp_video_ops = {
      .s_stream = mt9m114_ifp_s_stream,
 };
@@ -2124,6 +2138,11 @@ static const struct v4l2_subdev_internal_ops mt9m114_ifp_internal_ops = {
      .unregistered = mt9m114_ifp_unregistered,
 };
 
+static const struct media_entity_operations mt9m114_ifp_entity_ops = {
+     .link_validate = v4l2_subdev_link_validate,
+     .get_fwnode_pad = mt9m114_ifp_get_fwnode_pad,
+};
+
 static int mt9m114_ifp_init(struct mt9m114 *sensor)
 {
      struct v4l2_subdev *sd = &sensor->ifp.sd;
@@ -2141,7 +2160,7 @@ static int mt9m114_ifp_init(struct mt9m114 *sensor)
 
      /* Initialize the media entity. */
      sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_ISP;
-     sd->entity.ops = &mt9m114_entity_ops;
+     sd->entity.ops = &mt9m114_ifp_entity_ops;
      pads[0].flags = MEDIA_PAD_FL_SINK;
      pads[1].flags = MEDIA_PAD_FL_SOURCE;
      ret = media_entity_pads_init(&sd->entity, 2, pads);
--
Quoted 2 lines

2.53.0

--
Regards,

Laurent Pinchart

#4 lore raw
In reply to Svyatoslav Ryhel

вт, 6 жовт. 2026 р. о 18:36 Svyatoslav Ryhel <[email protected]> пише:

Quoted 13 lines

Currently, the driver's binding exposes only one endpoint, which maps to the IFP subdevice's SOURCE pad. This configuration causes failures for many devices using this camera because both the DT binding and the one-to-one pad mapping logic map the endpoint to the wrong pad. Fix this by implementing the get_fwnode_pad operation for the IFP, which correctly matches the endpoint to the corresponding IFP pad.

---
Changes in v2:
- adjusted coding style as asked by Laurent Pinchart
---

Quoted 9 lines

Svyatoslav Ryhel (1):
media: i2c: mt9m114: Add get_fwnode_pad operation for IFP

 drivers/media/i2c/mt9m114.c | 39 +++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

--
2.53.0

Hello there!

If everyone is fine with thins change, may it be applied?

Thank you!