media: i2c: imx274: simplify probe function by adding local variable dev
PATCH 1/2 media: i2c: imx274: simplify probe function by adding local variable dev
Simplify probe function by adding a local variable dev instead of using &client->dev all the time.
--- drivers/media/i2c/imx274.c | 39 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-)
drivers/media/i2c/imx274.c +18 -21
@@ -1961,23 +1961,23 @@ static int imx274_probe(struct i2c_client *client) {struct v4l2_subdev *sd;struct stimx274 *imx274; +struct device *dev = &client->dev;int ret;/* initialize imx274 */ - imx274 =devm_kzalloc (&client->dev,sizeof (*imx274),GFP_KERNEL ); + imx274 =devm_kzalloc (dev,sizeof (*imx274),GFP_KERNEL );if (!imx274)return -ENOMEM ;mutex_init (&imx274->lock); - imx274->inck =devm_clk_get_optional (&client->dev,"inck" ); + imx274->inck =devm_clk_get_optional (dev,"inck" );if (IS_ERR (imx274->inck))return PTR_ERR (imx274->inck); - ret =imx274_regulators_get (&client->dev, imx274); + ret =imx274_regulators_get (dev, imx274);if (ret) { -dev_err (&client->dev, -"Failed to get power regulators, err: %d\n" , ret); +dev_err (dev,"Failed to get power regulators, err: %d\n" , ret);return ret; }
@@ -1996,7 +1996,7 @@ static int imx274_probe(struct i2c_client *client)/* initialize regmap */ imx274->regmap =devm_regmap_init_i2c (client, &imx274_regmap_config);if (IS_ERR (imx274->regmap)) { -dev_err (&client->dev, +dev_err (dev,"regmap init failed: %ld\n" ,PTR_ERR (imx274->regmap)); ret = -ENODEV ; goto err_regmap;
@@ -2013,34 +2013,32 @@ static int imx274_probe(struct i2c_client *client) sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; ret =media_entity_pads_init (&sd->entity,1 , &imx274->pad);if (ret <0 ) { -dev_err (&client->dev, +dev_err (dev,"%s : media entity init Failed %d\n" , __func__, ret); goto err_regmap; }/* initialize sensor reset gpio */ - imx274->reset_gpio =devm_gpiod_get_optional (&client->dev,"reset" , + imx274->reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH );if (IS_ERR (imx274->reset_gpio)) {if (PTR_ERR (imx274->reset_gpio) != -EPROBE_DEFER ) -dev_err (&client->dev,"Reset GPIO not setup in DT" ); +dev_err (dev,"Reset GPIO not setup in DT" ); ret =PTR_ERR (imx274->reset_gpio); goto err_me; }/* power on the sensor */ - ret =imx274_power_on (&client->dev); + ret =imx274_power_on (dev);if (ret <0 ) { -dev_err (&client->dev, -"%s : imx274 power on failed\n" , __func__); +dev_err (dev,"%s : imx274 power on failed\n" , __func__); goto err_me; }/* initialize controls */ ret =v4l2_ctrl_handler_init (&imx274->ctrls.handler,4 );if (ret <0 ) { -dev_err (&client->dev, -"%s : ctrl handler init Failed\n" , __func__); +dev_err (dev,"%s : ctrl handler init Failed\n" , __func__); goto err_power_off; }
@@ -2083,23 +2081,22 @@ static int imx274_probe(struct i2c_client *client)/* register subdevice */ ret =v4l2_async_register_subdev (sd);if (ret <0 ) { -dev_err (&client->dev, -"%s : v4l2_async_register_subdev failed %d\n" , +dev_err (dev,"%s : v4l2_async_register_subdev failed %d\n" , __func__, ret); goto err_ctrls; } -pm_runtime_set_active (&client->dev); -pm_runtime_enable (&client->dev); -pm_runtime_idle (&client->dev); +pm_runtime_set_active (dev); +pm_runtime_enable (dev); +pm_runtime_idle (dev); -dev_info (&client->dev,"imx274 : imx274 probe success !\n" ); +dev_info (dev,"imx274 : imx274 probe success !\n" );return 0 ; err_ctrls:v4l2_ctrl_handler_free (&imx274->ctrls.handler); err_power_off: -imx274_power_off (&client->dev); +imx274_power_off (dev); err_me:media_entity_cleanup (&sd->entity); err_regmap:
Signature · 1 line
2.25.1
PATCH 2/2 media: i2c: imx274: implement fwnode parsing
Implement fwnode parsing at probe time. Check if the bus and number of lanes are supported.
--- drivers/media/i2c/imx274.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
drivers/media/i2c/imx274.c +40 -0
@@ -27,6 +27,7 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> #include <media/v4l2-subdev.h> /*
@@ -1957,6 +1958,41 @@ static const struct i2c_device_id imx274_id[] = { };MODULE_DEVICE_TABLE (i2c, imx274_id); +static int imx274_fwnode_parse (struct device *dev) +{ +struct fwnode_handle *endpoint; +/* Only CSI2 is supported */ +struct v4l2_fwnode_endpoint ep = { + .bus_type =V4L2_MBUS_CSI2_DPHY + }; +int ret; + + endpoint =fwnode_graph_get_next_endpoint (dev_fwnode (dev),NULL ); +if (!endpoint) { +dev_err (dev,"Endpoint node not found\n" ); +return -EINVAL ; + } + + ret =v4l2_fwnode_endpoint_alloc_parse (endpoint, &ep); +fwnode_handle_put (endpoint); +if (ret == -ENXIO ) { +dev_err (dev,"Unsupported bus type, should be CSI2\n" ); +return ret; + }else if (ret) { +dev_err (dev,"Parsing endpoint node failed %d\n" , ret); +return ret; + } + +/* Check number of data lanes, only 4 lanes supported */ +if (ep.bus.mipi_csi2.num_data_lanes !=4 ) { +dev_err (dev,"Invalid data lanes: %d\n" , + ep.bus.mipi_csi2.num_data_lanes); +return -EINVAL ; + } + +return 0 ; +} +static int imx274_probe (struct i2c_client *client) {struct v4l2_subdev *sd;
@@ -1971,6 +2007,10 @@ static int imx274_probe(struct i2c_client *client)mutex_init (&imx274->lock); + ret =imx274_fwnode_parse (dev); +if (ret) +return ret; + imx274->inck =devm_clk_get_optional (dev,"inck" );if (IS_ERR (imx274->inck))return PTR_ERR (imx274->inck);
Signature · 1 line
2.25.1
Sakari Ailus
maintainerRe: [PATCH 2/2] media: i2c: imx274: implement fwnode parsing
Hi Eugen,
Quoted 30 lines · Eugen Hristev
Implement fwnode parsing at probe time. Check if the bus and number of lanes are supported.
Signed-off-by Eugen Hristev <[email protected]>--- drivers/media/i2c/imx274.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)drivers/media/i2c/imx274.c +7
-0@@ -27,6 +27,7 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> #include <media/v4l2-subdev.h> /* @@ -1957,6 +1958,41 @@ static const struct i2c_device_id imx274_id[] = { };MODULE_DEVICE_TABLE (i2c, imx274_id); +static int imx274_fwnode_parse (struct device *dev) +{ +struct fwnode_handle *endpoint; +/* Only CSI2 is supported */ +struct v4l2_fwnode_endpoint ep = { + .bus_type =V4L2_MBUS_CSI2_DPHY
drivers/media/i2c/imx274.c static const struct i2c_device_id imx274_id[] = { · line 1976
Quoted 10 lines
drivers/media/i2c/imx274.c +10
-0+ }; +int ret; + + endpoint =fwnode_graph_get_next_endpoint (dev_fwnode (dev),NULL ); +if (!endpoint) { +dev_err (dev,"Endpoint node not found\n" ); +return -EINVAL ; + } + + ret =v4l2_fwnode_endpoint_alloc_parse (endpoint, &ep);
This allocates memory for the link frequencies. It needs to be released at some point.
You could also use v4l1_fwnode_endpoint_parse() as the driver doesn't seem to use link frequencies (albeit it probably should, but that's another discussion).
Quoted 33 lines
drivers/media/i2c/imx274.c +23
-0+fwnode_handle_put (endpoint); +if (ret == -ENXIO ) { +dev_err (dev,"Unsupported bus type, should be CSI2\n" ); +return ret; + }else if (ret) { +dev_err (dev,"Parsing endpoint node failed %d\n" , ret); +return ret; + } + +/* Check number of data lanes, only 4 lanes supported */ +if (ep.bus.mipi_csi2.num_data_lanes !=4 ) { +dev_err (dev,"Invalid data lanes: %d\n" , + ep.bus.mipi_csi2.num_data_lanes); +return -EINVAL ; + } + +return 0 ; +} +static int imx274_probe (struct i2c_client *client) {struct v4l2_subdev *sd;@@ -1971,6 +2007,10 @@ static int imx274_probe(struct i2c_client *client)mutex_init (&imx274->lock); + ret =imx274_fwnode_parse (dev); +if (ret) +return ret; + imx274->inck =devm_clk_get_optional (dev,"inck" );if (IS_ERR (imx274->inck))return PTR_ERR (imx274->inck);
Signature · 3 lines
Kind regards, Sakari Ailus
Re: [PATCH 2/2] media: i2c: imx274: implement fwnode parsing
Quoted 47 lines · Sakari Ailus
Hi Eugen,
Quoted 30 lines · Eugen Hristev
Implement fwnode parsing at probe time. Check if the bus and number of lanes are supported.
Signed-off-by Eugen Hristev <[email protected]>--- drivers/media/i2c/imx274.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)drivers/media/i2c/imx274.c +7
-0@@ -27,6 +27,7 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> +#include <media/v4l2-fwnode.h> #include <media/v4l2-subdev.h> /* @@ -1957,6 +1958,41 @@ static const struct i2c_device_id imx274_id[] = { };MODULE_DEVICE_TABLE (i2c, imx274_id); +static int imx274_fwnode_parse (struct device *dev) +{ +struct fwnode_handle *endpoint; +/* Only CSI2 is supported */ +struct v4l2_fwnode_endpoint ep = { + .bus_type =V4L2_MBUS_CSI2_DPHY drivers/media/i2c/imx274.c static const struct i2c_device_id imx274_id[] = { · line 1976
Quoted 10 lines
drivers/media/i2c/imx274.c +10
-0+ }; +int ret; + + endpoint =fwnode_graph_get_next_endpoint (dev_fwnode (dev),NULL ); +if (!endpoint) { +dev_err (dev,"Endpoint node not found\n" ); +return -EINVAL ; + } + + ret =v4l2_fwnode_endpoint_alloc_parse (endpoint, &ep);This allocates memory for the link frequencies. It needs to be released at some point.
Quoted 3 lines
You could also use
v4l1_fwnode_endpoint_parse()as the driver doesn't seem to use link frequencies (albeit it probably should, but that's another discussion).
Okay, got it, I am changing, testing and resending.
Thanks
Quoted 40 lines
Quoted 24 lines
drivers/media/i2c/imx274.c +19
-0+fwnode_handle_put (endpoint); +if (ret == -ENXIO ) { +dev_err (dev,"Unsupported bus type, should be CSI2\n" ); +return ret; + }else if (ret) { +dev_err (dev,"Parsing endpoint node failed %d\n" , ret); +return ret; + } + +/* Check number of data lanes, only 4 lanes supported */ +if (ep.bus.mipi_csi2.num_data_lanes !=4 ) { +dev_err (dev,"Invalid data lanes: %d\n" , + ep.bus.mipi_csi2.num_data_lanes); +return -EINVAL ; + } + +return 0 ; +} +static int imx274_probe (struct i2c_client *client) {struct v4l2_subdev *sd;drivers/media/i2c/imx274.c static int imx274_probe(struct i2c_client *client) · line 2016
Quoted 10 lines
drivers/media/i2c/imx274.c +4
-0@@ -1971,6 +2007,10 @@ static int imx274_probe(struct i2c_client *client)mutex_init (&imx274->lock); + ret =imx274_fwnode_parse (dev); +if (ret) +return ret; + imx274->inck =devm_clk_get_optional (dev,"inck" );if (IS_ERR (imx274->inck))return PTR_ERR (imx274->inck);--
Kind regards,Sakari Ailus
Sakari Ailus
maintainerHi Eugen,
Quoted 4 lines · Eugen Hristev
Simplify probe function by adding a local variable dev instead of using
&client->devall the time.Signed-off-by Eugen Hristev <[email protected]>
It's not really wrong to do this, but is it useful?
You can't even unwrap a single line, the lines are just made a little bit shorter.
Signature · 3 lines
Kind regards, Sakari Ailus
Luca Ceresoli
Reviewed-byHi,
Quoted 9 lines · Sakari Ailus
Hi Eugen,
Quoted 4 lines · Eugen Hristev
Simplify probe function by adding a local variable dev instead of using
&client->devall the time.Signed-off-by Eugen Hristev <[email protected]>It's not really wrong to do this, but is it useful?
It is of course a matter of personal taste, but I also prefer a short name in cases such as this where the same member is accessed a lot of times. To me it makes code simpler to read and even to write.
Quoted 2 lines
You can't even unwrap a single line, the lines are just made a little bit shorter.
Let's be fair, he did unwrap 4. :)
As said, it is a matter of taste so I'll be OK it this patch is dropped. But since I like it and it looks correct:
Signature · 1 line
Luca
Sakari Ailus
maintainerHi Luca,
Quoted 12 lines · Luca Ceresoli
Hi,
Quoted 9 lines · Sakari Ailus
Hi Eugen,
Quoted 4 lines · Eugen Hristev
Simplify probe function by adding a local variable dev instead of using
&client->devall the time.Signed-off-by Eugen Hristev <[email protected]>It's not really wrong to do this, but is it useful?
Quoted 8 lines
It is of course a matter of personal taste, but I also prefer a short name in cases such as this where the same member is accessed a lot of times. To me it makes code simpler to read and even to write.
Quoted 2 lines
You can't even unwrap a single line, the lines are just made a little bit shorter.
Let's be fair, he did unwrap 4. :)
Ah, yes, you're right.
But at least one could have been wrapped without the change. :-)
Quoted 5 lines
As said, it is a matter of taste so I'll be OK it this patch is dropped. But since I like it and it looks correct:
Reviewed-by Luca Ceresoli <[email protected]>
Signature · 1 line
Sakari Ailus
Quoted 6 lines · Sakari Ailus
Hi Eugen,
Quoted 3 lines · Eugen Hristev
Simplify probe function by adding a local variable dev instead of using
&client->devall the time.
Quoted 6 lines
Quoted 1 line
Signed-off-by Eugen Hristev <[email protected]>It's not really wrong to do this, but is it useful?
You can't even unwrap a single line, the lines are just made a little bit shorter.
Hi,
I think there are a few (18 +, 21 -) ... but the idea was to make the probe function a little bit more easy to read.
Up to you if you want to take this patch.
Quoted 6 lines
--
Kind regards,Sakari Ailus
Sakari Ailus
maintainerQuoted 10 lines · On Tue, Nov 23, 2021 at 11:35:33AM +0000, [email protected] wrote:
Quoted 8 lines · Sakari Ailus
Hi Eugen,
Quoted 4 lines · Eugen Hristev
Simplify probe function by adding a local variable dev instead of using
&client->devall the time.Signed-off-by Eugen Hristev <[email protected]>
Quoted 8 lines
Quoted 4 lines
It's not really wrong to do this, but is it useful?
You can't even unwrap a single line, the lines are just made a little bit shorter.
Hi,
I think there are a few (18 +, 21 -) ... but the idea was to make the
Indeed you're right.
Quoted 2 lines
probe function a little bit more easy to read.
Up to you if you want to take this patch.
I'll take it.
Signature · 1 line
Sakari Ailus