All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
To: linux-renesas-soc@vger.kernel.org,
	"Jacopo Mondi" <jacopo@jmondi.org>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>
Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Subject: [PATCH 2/2] max9286: Collect all V4L2 registrations
Date: Wed, 12 Feb 2020 17:37:27 +0000	[thread overview]
Message-ID: <20200212173727.19476-3-kieran.bingham+renesas@ideasonboard.com> (raw)
In-Reply-To: <20200212173727.19476-1-kieran.bingham+renesas@ideasonboard.com>

Move all interactions with V4L2 to a dedicated pair of functions
for register and unregister to improve readability of the code.

Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
 drivers/media/i2c/max9286.c | 139 +++++++++++++++++++++---------------
 1 file changed, 83 insertions(+), 56 deletions(-)

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index 03c5fa232b6d..b1366f122a8a 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -735,6 +735,80 @@ static const struct v4l2_subdev_internal_ops max9286_subdev_internal_ops = {
 	.open = max9286_open,
 };
 
+static int max9286_v4l2_register(struct max9286_priv *priv)
+{
+	struct device *dev = &priv->client->dev;
+	struct fwnode_handle *ep;
+	int ret;
+	int i;
+
+	/* Register v4l2 async notifiers for connected Camera subdevices */
+	ret = max9286_v4l2_async_register(priv);
+	if (ret) {
+		dev_err(dev, "Unable to register V4L2 async notifiers\n");
+		return ret;
+	}
+
+	/* Configure V4L2 for the MAX9286 itself */
+
+	v4l2_i2c_subdev_init(&priv->sd, priv->client, &max9286_subdev_ops);
+	priv->sd.internal_ops = &max9286_subdev_internal_ops;
+	priv->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+
+	v4l2_ctrl_handler_init(&priv->ctrls, 1);
+	/*
+	 * FIXME: Compute the real pixel rate. The 50 MP/s value comes from the
+	 * hardcoded frequency in the BSP CSI-2 receiver driver.
+	 */
+	v4l2_ctrl_new_std(&priv->ctrls, NULL, V4L2_CID_PIXEL_RATE,
+			  50000000, 50000000, 1, 50000000);
+	priv->sd.ctrl_handler = &priv->ctrls;
+	ret = priv->ctrls.error;
+	if (ret)
+		goto err_async;
+
+	priv->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
+
+	priv->pads[MAX9286_SRC_PAD].flags = MEDIA_PAD_FL_SOURCE;
+	for (i = 0; i < MAX9286_SRC_PAD; i++)
+		priv->pads[i].flags = MEDIA_PAD_FL_SINK;
+	ret = media_entity_pads_init(&priv->sd.entity, MAX9286_N_PADS,
+				     priv->pads);
+	if (ret)
+		goto err_async;
+
+	ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), MAX9286_SRC_PAD,
+					     0, 0);
+	if (!ep) {
+		dev_err(dev, "Unable to retrieve endpoint on \"port@4\"\n");
+		ret = -ENOENT;
+		goto err_async;
+	}
+	priv->sd.fwnode = ep;
+
+	ret = v4l2_async_register_subdev(&priv->sd);
+	if (ret < 0) {
+		dev_err(dev, "Unable to register subdevice\n");
+		goto err_put_node;
+	}
+
+	return 0;
+
+err_put_node:
+	fwnode_handle_put(ep);
+err_async:
+	max9286_v4l2_async_unregister(priv);
+
+	return ret;
+}
+
+static void max9286_v4l2_unregister(struct max9286_priv *priv)
+{
+	fwnode_handle_put(priv->sd.fwnode);
+	v4l2_async_unregister_subdev(&priv->sd);
+	max9286_v4l2_async_unregister(priv);
+}
+
 /* -----------------------------------------------------------------------------
  * Probe/Remove
  */
@@ -887,8 +961,6 @@ static int max9286_init(struct device *dev)
 {
 	struct max9286_priv *priv;
 	struct i2c_client *client;
-	struct fwnode_handle *ep;
-	unsigned int i;
 	int ret;
 
 	/* Skip non-max9286 devices. */
@@ -913,58 +985,20 @@ static int max9286_init(struct device *dev)
 		goto err_regulator;
 	}
 
-	/* Register v4l2 async notifiers */
-	ret = max9286_v4l2_async_register(priv);
-	if (ret) {
-		dev_err(dev, "Unable to register V4L2 async notifiers\n");
-		goto err_regulator;
-	}
-
-	v4l2_i2c_subdev_init(&priv->sd, client, &max9286_subdev_ops);
-	priv->sd.internal_ops = &max9286_subdev_internal_ops;
-	priv->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
-
-	v4l2_ctrl_handler_init(&priv->ctrls, 1);
 	/*
-	 * FIXME: Compute the real pixel rate. The 50 MP/s value comes from the
-	 * hardcoded frequency in the BSP CSI-2 receiver driver.
+	 * Register all V4L2 interactions for the MAX9286 and notifiers for
+	 * any subdevices connected.
 	 */
-	v4l2_ctrl_new_std(&priv->ctrls, NULL, V4L2_CID_PIXEL_RATE,
-			  50000000, 50000000, 1, 50000000);
-	priv->sd.ctrl_handler = &priv->ctrls;
-	ret = priv->ctrls.error;
-	if (ret)
-		goto err_async;
-
-	priv->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
-
-	priv->pads[MAX9286_SRC_PAD].flags = MEDIA_PAD_FL_SOURCE;
-	for (i = 0; i < MAX9286_SRC_PAD; i++)
-		priv->pads[i].flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_pads_init(&priv->sd.entity, MAX9286_N_PADS,
-				     priv->pads);
-	if (ret)
-		goto err_regulator;
-
-	ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), MAX9286_SRC_PAD,
-					     0, 0);
-	if (!ep) {
-		dev_err(dev, "Unable to retrieve endpoint on \"port@4\"\n");
-		ret = -ENOENT;
+	ret = max9286_v4l2_register(priv);
+	if (ret) {
+		dev_err(dev, "Failed to register with V4L2\n");
 		goto err_regulator;
 	}
-	priv->sd.fwnode = ep;
-
-	ret = v4l2_async_register_subdev(&priv->sd);
-	if (ret < 0) {
-		dev_err(dev, "Unable to register subdevice\n");
-		goto err_put_node;
-	}
 
 	ret = max9286_i2c_mux_init(priv);
 	if (ret) {
 		dev_err(dev, "Unable to initialize I2C multiplexer\n");
-		goto err_subdev_unregister;
+		goto err_v4l2_register;
 	}
 
 	/* Leave the mux channels disabled until they are selected. */
@@ -972,13 +1006,8 @@ static int max9286_init(struct device *dev)
 
 	return 0;
 
-err_subdev_unregister:
-	v4l2_async_unregister_subdev(&priv->sd);
-	max9286_i2c_mux_close(priv);
-err_put_node:
-	fwnode_handle_put(ep);
-err_async:
-	max9286_v4l2_async_unregister(priv);
+err_v4l2_register:
+	max9286_v4l2_unregister(priv);
 err_regulator:
 	regulator_disable(priv->regulator);
 	priv->poc_enabled = false;
@@ -1201,9 +1230,7 @@ static int max9286_remove(struct i2c_client *client)
 
 	i2c_mux_del_adapters(priv->mux);
 
-	fwnode_handle_put(priv->sd.fwnode);
-	v4l2_async_unregister_subdev(&priv->sd);
-	max9286_v4l2_async_unregister(priv);
+	max9286_v4l2_unregister(priv);
 
 	if (priv->poc_enabled)
 		regulator_disable(priv->regulator);
-- 
2.20.1


  parent reply	other threads:[~2020-02-12 17:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12 17:37 [PATCH 0/2] max9286: Refactor V4L2 support to prevent EPROBE_DEFER failures Kieran Bingham
2020-02-12 17:37 ` [PATCH 1/2] max9286: Split out async registration Kieran Bingham
2020-02-12 17:39   ` Kieran Bingham
2020-02-13  9:46   ` Jacopo Mondi
2020-02-13 10:07     ` Kieran Bingham
2020-02-13 10:15       ` Kieran Bingham
2020-02-13 10:20       ` Jacopo Mondi
2020-02-13 10:27         ` Kieran Bingham
2020-02-13 11:41           ` Jacopo Mondi
2020-02-12 17:37 ` Kieran Bingham [this message]
2020-02-13 10:21 ` [PATCH] max9286: balance v4l2_async refcnting Kieran Bingham
2020-02-13 13:06   ` Kieran Bingham
2020-02-13 13:11     ` Jacopo Mondi
2020-02-13 13:28       ` Kieran Bingham

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