[PATCH 3/4] media: i2c: ov2685: Add controls from fwnode

Luca Weiss posted 4 patches 2 years, 7 months ago
There is a newer version of this series
[PATCH 3/4] media: i2c: ov2685: Add controls from fwnode
Posted by Luca Weiss 2 years, 7 months ago
Add V4L2_CID_CAMERA_ORIENTATION and V4L2_CID_CAMERA_SENSOR_ROTATION
controls to the ov2685 driver by attempting to parse them from firmware.

Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
---
 drivers/media/i2c/ov2685.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/media/i2c/ov2685.c b/drivers/media/i2c/ov2685.c
index 844a91dbc8e5..bfced11b178b 100644
--- a/drivers/media/i2c/ov2685.c
+++ b/drivers/media/i2c/ov2685.c
@@ -17,6 +17,7 @@
 #include <media/media-entity.h>
 #include <media/v4l2-async.h>
 #include <media/v4l2-ctrls.h>
+#include <media/v4l2-fwnode.h>
 #include <media/v4l2-subdev.h>
 
 #define CHIP_ID				0x2685
@@ -613,6 +614,7 @@ static int ov2685_initialize_controls(struct ov2685 *ov2685)
 	const struct ov2685_mode *mode;
 	struct v4l2_ctrl_handler *handler;
 	struct v4l2_ctrl *ctrl;
+	struct v4l2_fwnode_device_properties props;
 	u64 exposure_max;
 	u32 pixel_rate, h_blank;
 	int ret;
@@ -661,6 +663,15 @@ static int ov2685_initialize_controls(struct ov2685 *ov2685)
 				ARRAY_SIZE(ov2685_test_pattern_menu) - 1,
 				0, 0, ov2685_test_pattern_menu);
 
+	/* set properties from fwnode (e.g. rotation, orientation) */
+	ret = v4l2_fwnode_device_parse(&ov2685->client->dev, &props);
+	if (ret)
+		goto err_free_handler;
+
+	ret = v4l2_ctrl_new_fwnode_properties(handler, &ov2685_ctrl_ops, &props);
+	if (ret)
+		goto err_free_handler;
+
 	if (handler->error) {
 		ret = handler->error;
 		dev_err(&ov2685->client->dev,

-- 
2.39.1
Re: [PATCH 3/4] media: i2c: ov2685: Add controls from fwnode
Posted by Jacopo Mondi 2 years, 7 months ago
Hi Luca,

On Sun, Jan 29, 2023 at 10:42:37AM +0100, Luca Weiss wrote:
> Add V4L2_CID_CAMERA_ORIENTATION and V4L2_CID_CAMERA_SENSOR_ROTATION
> controls to the ov2685 driver by attempting to parse them from firmware.
>
> Signed-off-by: Luca Weiss <luca@z3ntu.xyz>
> ---
>  drivers/media/i2c/ov2685.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/drivers/media/i2c/ov2685.c b/drivers/media/i2c/ov2685.c
> index 844a91dbc8e5..bfced11b178b 100644
> --- a/drivers/media/i2c/ov2685.c
> +++ b/drivers/media/i2c/ov2685.c
> @@ -17,6 +17,7 @@
>  #include <media/media-entity.h>
>  #include <media/v4l2-async.h>
>  #include <media/v4l2-ctrls.h>
> +#include <media/v4l2-fwnode.h>
>  #include <media/v4l2-subdev.h>
>
>  #define CHIP_ID				0x2685
> @@ -613,6 +614,7 @@ static int ov2685_initialize_controls(struct ov2685 *ov2685)
>  	const struct ov2685_mode *mode;
>  	struct v4l2_ctrl_handler *handler;
>  	struct v4l2_ctrl *ctrl;
> +	struct v4l2_fwnode_device_properties props;
>  	u64 exposure_max;
>  	u32 pixel_rate, h_blank;
>  	int ret;
> @@ -661,6 +663,15 @@ static int ov2685_initialize_controls(struct ov2685 *ov2685)
>  				ARRAY_SIZE(ov2685_test_pattern_menu) - 1,
>  				0, 0, ov2685_test_pattern_menu);
>

As the below function can register up to 2 controls, you should also
reserve space for them when initializing the control handler to avoid
relocations

-       ret = v4l2_ctrl_handler_init(handler, 8);
+       ret = v4l2_ctrl_handler_init(handler, 10);


> +	/* set properties from fwnode (e.g. rotation, orientation) */
> +	ret = v4l2_fwnode_device_parse(&ov2685->client->dev, &props);
> +	if (ret)
> +		goto err_free_handler;
> +
> +	ret = v4l2_ctrl_new_fwnode_properties(handler, &ov2685_ctrl_ops, &props);
> +	if (ret)
> +		goto err_free_handler;
> +
>  	if (handler->error) {
>  		ret = handler->error;
>  		dev_err(&ov2685->client->dev,
>
> --
> 2.39.1
>