diff mbox series

[v4,2/6] media: imx335: Parse fwnode properties

Message ID 20240402140924.10009-3-umang.jain@ideasonboard.com (mailing list archive)
State Superseded
Headers show
Series media: imx335: 2/4 lane ops and improvements | expand

Commit Message

Umang Jain April 2, 2024, 2:09 p.m. UTC
From: Kieran Bingham <kieran.bingham@ideasonboard.com>

Call the V4L2 fwnode device parser to handle controls that are
standardised by the framework.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 drivers/media/i2c/imx335.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

Comments

Sakari Ailus April 12, 2024, 11:31 a.m. UTC | #1
Hi Umang, Kieran,

On Tue, Apr 02, 2024 at 07:39:20PM +0530, Umang Jain wrote:
> From: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> Call the V4L2 fwnode device parser to handle controls that are
> standardised by the framework.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>  drivers/media/i2c/imx335.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
> index c633ea1380e7..b8cf85984127 100644
> --- a/drivers/media/i2c/imx335.c
> +++ b/drivers/media/i2c/imx335.c
> @@ -1227,10 +1227,12 @@ static int imx335_init_controls(struct imx335 *imx335)
>  {
>  	struct v4l2_ctrl_handler *ctrl_hdlr = &imx335->ctrl_handler;
>  	const struct imx335_mode *mode = imx335->cur_mode;
> +	struct v4l2_fwnode_device_properties props;
>  	u32 lpfr;
>  	int ret;
>  
> -	ret = v4l2_ctrl_handler_init(ctrl_hdlr, 7);
> +	/* v4l2_fwnode_device_properties can add two more controls */
> +	ret = v4l2_ctrl_handler_init(ctrl_hdlr, 9);
>  	if (ret)
>  		return ret;
>  
> @@ -1296,15 +1298,27 @@ static int imx335_init_controls(struct imx335 *imx335)
>  		imx335->hblank_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>  
>  	if (ctrl_hdlr->error) {
> -		dev_err(imx335->dev, "control init failed: %d\n",
> -			ctrl_hdlr->error);
> -		v4l2_ctrl_handler_free(ctrl_hdlr);
> -		return ctrl_hdlr->error;
> +		ret = ctrl_hdlr->error;
> +		dev_err(imx335->dev, "control init failed: %d\n", ret);
> +		goto free_ctrl_hdlr;
>  	}
>  
> +	ret = v4l2_fwnode_device_parse(imx335->dev, &props);
> +	if (ret)
> +		goto free_ctrl_hdlr;
> +
> +	ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx335_ctrl_ops,
> +					      &props);
> +	if (ret)
> +		goto free_ctrl_hdlr;

This works but it'd be nice if v4l2_ctrl_new_fwnode_properties() behaved as
the control framework functions, i.e. bail out if the handler's state has
an error. Then you could have a single check for that, dropping the two
checks above.

Feel free to post a patch. :-)

> +
>  	imx335->sd.ctrl_handler = ctrl_hdlr;
>  
>  	return 0;
> +
> +free_ctrl_hdlr:
> +	v4l2_ctrl_handler_free(ctrl_hdlr);
> +	return ret;
>  }
>  
>  /**
diff mbox series

Patch

diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index c633ea1380e7..b8cf85984127 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -1227,10 +1227,12 @@  static int imx335_init_controls(struct imx335 *imx335)
 {
 	struct v4l2_ctrl_handler *ctrl_hdlr = &imx335->ctrl_handler;
 	const struct imx335_mode *mode = imx335->cur_mode;
+	struct v4l2_fwnode_device_properties props;
 	u32 lpfr;
 	int ret;
 
-	ret = v4l2_ctrl_handler_init(ctrl_hdlr, 7);
+	/* v4l2_fwnode_device_properties can add two more controls */
+	ret = v4l2_ctrl_handler_init(ctrl_hdlr, 9);
 	if (ret)
 		return ret;
 
@@ -1296,15 +1298,27 @@  static int imx335_init_controls(struct imx335 *imx335)
 		imx335->hblank_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
 	if (ctrl_hdlr->error) {
-		dev_err(imx335->dev, "control init failed: %d\n",
-			ctrl_hdlr->error);
-		v4l2_ctrl_handler_free(ctrl_hdlr);
-		return ctrl_hdlr->error;
+		ret = ctrl_hdlr->error;
+		dev_err(imx335->dev, "control init failed: %d\n", ret);
+		goto free_ctrl_hdlr;
 	}
 
+	ret = v4l2_fwnode_device_parse(imx335->dev, &props);
+	if (ret)
+		goto free_ctrl_hdlr;
+
+	ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx335_ctrl_ops,
+					      &props);
+	if (ret)
+		goto free_ctrl_hdlr;
+
 	imx335->sd.ctrl_handler = ctrl_hdlr;
 
 	return 0;
+
+free_ctrl_hdlr:
+	v4l2_ctrl_handler_free(ctrl_hdlr);
+	return ret;
 }
 
 /**