Re: [PATCH] media: i2c: imx258: Parse and register properties

From: Robert Mader
Date: Tue Jan 03 2023 - 09:12:20 EST


On 02.01.23 15:06, Jacopo Mondi wrote:
Hi Robert

On Sun, Dec 25, 2022 at 04:42:34PM +0100, Robert Mader wrote:
Analogous to e.g. the imx219. This enables propagating
V4L2_CID_CAMERA_SENSOR_ROTATION values so that libcamera
can detect the correct rotation from the device tree
and propagate it further to e.g. Pipewire.

Signed-off-by: Robert Mader <robert.mader@xxxxxxxxxxxxx>
---
drivers/media/i2c/imx258.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index eab5fc1ee2f7..85819043d1e3 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -9,6 +9,7 @@
#include <linux/pm_runtime.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
+#include <media/v4l2-fwnode.h>
#include <asm/unaligned.h>

#define IMX258_REG_VALUE_08BIT 1
@@ -1149,6 +1150,7 @@ static int imx258_init_controls(struct imx258 *imx258)
{
struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd);
struct v4l2_ctrl_handler *ctrl_hdlr;
+ struct v4l2_fwnode_device_properties props;
Might be nicer to move this one line up

 Can you say what's your reasoning? I personally slightly prefer alphabetical order, but no strong opinion :)

s64 vblank_def;
s64 vblank_min;
s64 pixel_rate_min;
@@ -1156,7 +1158,7 @@ static int imx258_init_controls(struct imx258 *imx258)
int ret;

ctrl_hdlr = &imx258->ctrl_handler;
- ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
+ ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10);
I count 9 controls being registered before this patch, not 8. Do I
count them right ?

If that's case, as v4l2_ctrl_new_fwnode_properties()
can register up to two controls (V4L2_CID_ROTATION and
V4L2_CID_ORIENTATION) I would pre-reserve 11 controls not 10 to avoid
relocations.

Indeed, looks like bumping this was forgotten in c6f9d67e2ac625e331f6a7f5715d2f809ff0a922

if (ret)
return ret;

@@ -1232,6 +1234,15 @@ static int imx258_init_controls(struct imx258 *imx258)
goto error;
}

+ ret = v4l2_fwnode_device_parse(&client->dev, &props);
+ if (ret)
+ goto error;
+
+ ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx258_ctrl_ops,
+ &props);
+ if (ret)
+ goto error;
+
The rest looks good to me!

Thanks
j
Thanks!

--
Robert Mader
Consultant Software Developer

Collabora Ltd.
Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK
Registered in England & Wales, no. 5513718