diff mbox series

[v2,2/8] media: i2c: ds90ub953: Use v4l2_fwnode_endpoint_parse()

Message ID 20230720-fpdlink-additions-v2-2-b91b1eca2ad3@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series media: i2c: ds90ub9xx: Misc improvements | expand

Commit Message

Tomi Valkeinen July 20, 2023, 10:30 a.m. UTC
Use v4l2_fwnode_endpoint_parse() to parse the sink endpoint parameters.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/i2c/ds90ub953.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Laurent Pinchart July 25, 2023, 4:30 p.m. UTC | #1
Hi Tomi,

Thank you for the patch.

On Thu, Jul 20, 2023 at 01:30:33PM +0300, Tomi Valkeinen wrote:
> Use v4l2_fwnode_endpoint_parse() to parse the sink endpoint parameters.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  drivers/media/i2c/ds90ub953.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c
> index 591b52bf71c2..ad964bd6c7eb 100644
> --- a/drivers/media/i2c/ds90ub953.c
> +++ b/drivers/media/i2c/ds90ub953.c
> @@ -25,6 +25,8 @@
>  #include <media/i2c/ds90ub9xx.h>
>  #include <media/v4l2-ctrls.h>
>  #include <media/v4l2-event.h>
> +#include <media/v4l2-fwnode.h>
> +#include <media/v4l2-mediabus.h>
>  #include <media/v4l2-subdev.h>
>  
>  #define UB953_PAD_SINK			0
> @@ -1111,7 +1113,9 @@ static const struct regmap_config ub953_regmap_config = {
>  static int ub953_parse_dt(struct ub953_data *priv)
>  {
>  	struct device *dev = &priv->client->dev;
> +	struct v4l2_fwnode_endpoint vep = {};
>  	struct fwnode_handle *ep_fwnode;
> +	unsigned char nlanes;
>  	int ret;
>  
>  	ep_fwnode = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev),
> @@ -1119,19 +1123,21 @@ static int ub953_parse_dt(struct ub953_data *priv)
>  	if (!ep_fwnode)
>  		return dev_err_probe(dev, -ENOENT, "no endpoint found\n");
>  
> -	ret = fwnode_property_count_u32(ep_fwnode, "data-lanes");
> +	vep.bus_type = V4L2_MBUS_CSI2_DPHY;

I would initialize .bus_type when declaring the variable.

> +	ret = v4l2_fwnode_endpoint_parse(ep_fwnode, &vep);
>  
>  	fwnode_handle_put(ep_fwnode);
>  
> -	if (ret < 0)
> +	if (ret)
>  		return dev_err_probe(dev, ret,
> -				     "failed to parse property 'data-lanes'\n");
> +				     "failed to parse sink endpoint data\n");
>  
> -	if (ret != 1 && ret != 2 && ret != 4)
> +	nlanes = vep.bus.mipi_csi2.num_data_lanes;
> +	if (nlanes != 1 && nlanes != 2 && nlanes != 4)
>  		return dev_err_probe(dev, -EINVAL,
> -				     "bad number of data-lanes: %d\n", ret);
> +				     "bad number of data-lanes: %d\n", nlanes);

%u as nlanes is now unsigned.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  
> -	priv->num_data_lanes = ret;
> +	priv->num_data_lanes = nlanes;
>  
>  	return 0;
>  }
>
diff mbox series

Patch

diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c
index 591b52bf71c2..ad964bd6c7eb 100644
--- a/drivers/media/i2c/ds90ub953.c
+++ b/drivers/media/i2c/ds90ub953.c
@@ -25,6 +25,8 @@ 
 #include <media/i2c/ds90ub9xx.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-event.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-mediabus.h>
 #include <media/v4l2-subdev.h>
 
 #define UB953_PAD_SINK			0
@@ -1111,7 +1113,9 @@  static const struct regmap_config ub953_regmap_config = {
 static int ub953_parse_dt(struct ub953_data *priv)
 {
 	struct device *dev = &priv->client->dev;
+	struct v4l2_fwnode_endpoint vep = {};
 	struct fwnode_handle *ep_fwnode;
+	unsigned char nlanes;
 	int ret;
 
 	ep_fwnode = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev),
@@ -1119,19 +1123,21 @@  static int ub953_parse_dt(struct ub953_data *priv)
 	if (!ep_fwnode)
 		return dev_err_probe(dev, -ENOENT, "no endpoint found\n");
 
-	ret = fwnode_property_count_u32(ep_fwnode, "data-lanes");
+	vep.bus_type = V4L2_MBUS_CSI2_DPHY;
+	ret = v4l2_fwnode_endpoint_parse(ep_fwnode, &vep);
 
 	fwnode_handle_put(ep_fwnode);
 
-	if (ret < 0)
+	if (ret)
 		return dev_err_probe(dev, ret,
-				     "failed to parse property 'data-lanes'\n");
+				     "failed to parse sink endpoint data\n");
 
-	if (ret != 1 && ret != 2 && ret != 4)
+	nlanes = vep.bus.mipi_csi2.num_data_lanes;
+	if (nlanes != 1 && nlanes != 2 && nlanes != 4)
 		return dev_err_probe(dev, -EINVAL,
-				     "bad number of data-lanes: %d\n", ret);
+				     "bad number of data-lanes: %d\n", nlanes);
 
-	priv->num_data_lanes = ret;
+	priv->num_data_lanes = nlanes;
 
 	return 0;
 }