diff mbox series

media: ti-vpe: cal: Handle multiple PHYs

Message ID 20200617114432.923165-1-kieran.bingham@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series media: ti-vpe: cal: Handle multiple PHYs | expand

Commit Message

Kieran Bingham June 17, 2020, 11:44 a.m. UTC
There can be multiple PHY devices supported by the CAL, however if either
has no device connected, the current code will fail to complete probe.

Update the code paths to support a PHY with no device connected, and fix
up code loops which iterate the PHY devices to ensure they are NULL
safe.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 drivers/media/platform/ti-vpe/cal-camerarx.c | 14 +++++++++-----
 drivers/media/platform/ti-vpe/cal.c          | 13 +++++++++++--
 2 files changed, 20 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/drivers/media/platform/ti-vpe/cal-camerarx.c b/drivers/media/platform/ti-vpe/cal-camerarx.c
index 97b95973004f..14674634d882 100644
--- a/drivers/media/platform/ti-vpe/cal-camerarx.c
+++ b/drivers/media/platform/ti-vpe/cal-camerarx.c
@@ -526,7 +526,7 @@  static int cal_camerarx_parse_dt(struct cal_camerarx *phy)
 						phy->instance, 0);
 	if (!ep_node) {
 		phy_dbg(3, phy, "Can't get endpoint\n");
-		return -EINVAL;
+		return -ENODEV;
 	}
 
 	endpoint->bus_type = V4L2_MBUS_CSI2_DPHY;
@@ -803,6 +803,14 @@  struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
 	phy->cal = cal;
 	phy->instance = instance;
 
+	ret = cal_camerarx_parse_dt(phy);
+	if (ret) {
+		if (ret == -ENODEV)
+			ret = NULL;
+
+		goto error;
+	}
+
 	phy->res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
 						(instance == 0) ?
 						"cal_rx_core0" :
@@ -821,10 +829,6 @@  struct cal_camerarx *cal_camerarx_create(struct cal_dev *cal,
 	if (ret)
 		goto error;
 
-	ret = cal_camerarx_parse_dt(phy);
-	if (ret)
-		goto error;
-
 	/* Initialize the V4L2 subdev and media entity. */
 	sd = &phy->subdev;
 	v4l2_subdev_init(sd, &cal_camerarx_subdev_ops);
diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
index 21206c3ed68e..842197f97b3b 100644
--- a/drivers/media/platform/ti-vpe/cal.c
+++ b/drivers/media/platform/ti-vpe/cal.c
@@ -275,6 +275,9 @@  void cal_quickdump_regs(struct cal_dev *cal)
 	for (i = 0; i < cal_data_get_num_csi2_phy(cal); ++i) {
 		struct cal_camerarx *phy = cal->phy[i];
 
+		if (!phy)
+			continue;
+
 		cal_info(cal, "CSI2 Core %u Registers @ %pa:\n", i,
 			 &phy->res->start);
 		print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 4,
@@ -696,6 +699,9 @@  static int cal_async_notifier_register(struct cal_dev *cal)
 		struct v4l2_async_subdev *asd;
 		struct fwnode_handle *fwnode;
 
+		if (!phy)
+			continue;
+
 		fwnode = of_fwnode_handle(phy->sensor_node);
 		asd = v4l2_async_notifier_add_fwnode_subdev(&cal->notifier,
 							    fwnode,
@@ -1033,13 +1039,15 @@  static int cal_probe(struct platform_device *pdev)
 		cal->phy[i] = cal_camerarx_create(cal, i);
 		if (IS_ERR(cal->phy[i])) {
 			ret = PTR_ERR(cal->phy[i]);
+			cal->phy[i] = NULL;
 			goto error_media;
 		}
 	}
 
 	/* Create contexts. */
 	for (i = 0; i < cal_data_get_num_csi2_phy(cal); ++i)
-		cal->ctx[i] = cal_ctx_create(cal, i);
+		if (cal->phy[i])
+			cal->ctx[i] = cal_ctx_create(cal, i);
 
 	if (!cal->ctx[0] && !cal->ctx[1]) {
 		cal_err(cal, "Neither port is configured, no point in staying up\n");
@@ -1110,7 +1118,8 @@  static int cal_runtime_resume(struct device *dev)
 		 * the clock
 		 */
 		for (i = 0; i < cal_data_get_num_csi2_phy(cal); i++)
-			cal_camerarx_i913_errata(cal->phy[i]);
+			if (cal->phy[i])
+				cal_camerarx_i913_errata(cal->phy[i]);
 	}
 
 	/*