Linux Media Controller development
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Eugen Hristev <eugen.hristev@microchip.com>
Cc: leonl@leopardimaging.com, linux-media@vger.kernel.org,
	skomatineni@nvidia.com, luca@lucaceresoli.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] media: i2c: imx274: implement fwnode parsing
Date: Tue, 23 Nov 2021 13:23:24 +0200	[thread overview]
Message-ID: <YZzPLOv2RBuj+zoS@paasikivi.fi.intel.com> (raw)
In-Reply-To: <20211123111521.593863-2-eugen.hristev@microchip.com>

Hi Eugen,

On Tue, Nov 23, 2021 at 01:15:21PM +0200, Eugen Hristev wrote:
> Implement fwnode parsing at probe time.
> Check if the bus and number of lanes are supported.
> 
> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
> ---
>  drivers/media/i2c/imx274.c | 40 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/drivers/media/i2c/imx274.c b/drivers/media/i2c/imx274.c
> index e31f006b10d9..774912f44efe 100644
> --- a/drivers/media/i2c/imx274.c
> +++ b/drivers/media/i2c/imx274.c
> @@ -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);

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).

> +	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);

-- 
Kind regards,

Sakari Ailus

  reply	other threads:[~2021-11-23 11:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-23 11:15 [PATCH 1/2] media: i2c: imx274: simplify probe function by adding local variable dev Eugen Hristev
2021-11-23 11:15 ` [PATCH 2/2] media: i2c: imx274: implement fwnode parsing Eugen Hristev
2021-11-23 11:23   ` Sakari Ailus [this message]
2021-11-23 11:37     ` Eugen.Hristev
2021-11-23 11:25 ` [PATCH 1/2] media: i2c: imx274: simplify probe function by adding local variable dev Sakari Ailus
2021-11-23 11:35   ` Eugen.Hristev
2021-11-23 11:51     ` Sakari Ailus
2021-11-23 11:35   ` Luca Ceresoli
2021-11-23 11:50     ` Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YZzPLOv2RBuj+zoS@paasikivi.fi.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=eugen.hristev@microchip.com \
    --cc=leonl@leopardimaging.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=luca@lucaceresoli.net \
    --cc=skomatineni@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox