linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Jacopo Mondi <jacopo@jmondi.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	tfiga@google.com, pavel@ucw.cz,
	"open list:MEDIA INPUT INFRASTRUCTURE (V4L/DVB)" 
	<linux-media@vger.kernel.org>
Subject: Re: [PATCH v4 06/11] media: v4l2-fwnode: Add helper to parse device properties
Date: Fri, 18 Oct 2019 22:36:40 +0300	[thread overview]
Message-ID: <20191018193640.GE3712@kekkonen.localdomain> (raw)
In-Reply-To: <20191007162913.250743-7-jacopo@jmondi.org>

Hi Jacopo,

On Mon, Oct 07, 2019 at 06:29:08PM +0200, Jacopo Mondi wrote:
> Add an helper function to parse common device properties in the same
> way as v4l2_fwnode_endpoint_parse() parses common endpoint properties.
> 
> Parse the 'rotation' and 'location' properties from the firmware
> interface.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  drivers/media/v4l2-core/v4l2-fwnode.c | 42 +++++++++++++++++++++++
>  include/media/v4l2-fwnode.h           | 48 +++++++++++++++++++++++++++
>  2 files changed, 90 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
> index 192cac076761..8af4174a2bbf 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -596,6 +596,48 @@ void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link)
>  }
>  EXPORT_SYMBOL_GPL(v4l2_fwnode_put_link);
>  
> +int v4l2_fwnode_device_parse(struct device *dev,
> +			     struct v4l2_fwnode_device_properties *props)
> +{
> +	struct fwnode_handle *fwnode = dev_fwnode(dev);
> +	u32 val;
> +	int ret;
> +
> +	memset(props, 0, sizeof(*props));
> +
> +	props->location = V4L2_FWNODE_PROPERTY_UNSET;

How about adding V4L2_FWNODE_LOCATION_UNDEFINED instead? Same for the
rotation. I'd use 0 for that value, so memset above already sets it.

> +	ret = fwnode_property_read_u32(fwnode, "location", &val);
> +	if (!ret) {
> +		switch (val) {
> +		case V4L2_FWNODE_LOCATION_FRONT:
> +		case V4L2_FWNODE_LOCATION_BACK:
> +		case V4L2_FWNODE_LOCATION_EXTERNAL:
> +			break;
> +		default:
> +			dev_warn(dev, "Unsupported device location: %u\n", val);
> +			return -EINVAL;
> +		}
> +
> +		props->location = val;
> +		dev_dbg(dev, "device location: %u\n", val);
> +	}
> +
> +	props->rotation = V4L2_FWNODE_PROPERTY_UNSET;
> +	ret = fwnode_property_read_u32(fwnode, "rotation", &val);
> +	if (!ret) {
> +		if (val >= 360 || val % 90) {
> +			dev_warn(dev, "Unsupported device rotation: %u\n", val);

I think it should be up to the caller to determine what's supported.

> +			return -EINVAL;
> +		}
> +
> +		props->rotation = val;
> +		dev_dbg(dev, "device rotation: %u\n", val);
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_fwnode_device_parse);
> +
>  static int
>  v4l2_async_notifier_fwnode_parse_endpoint(struct device *dev,
>  					  struct v4l2_async_notifier *notifier,
> diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
> index f6a7bcd13197..6d46d6fc3007 100644
> --- a/include/media/v4l2-fwnode.h
> +++ b/include/media/v4l2-fwnode.h
> @@ -109,6 +109,36 @@ struct v4l2_fwnode_endpoint {
>  	unsigned int nr_of_link_frequencies;
>  };
>  
> +/**
> + * v4l2_fwnode_location - identify a non initialized property.
> + *
> + * All properties in &struct v4l2_fwnode_device_properties are initialized
> + * to this value.
> + */
> +#define V4L2_FWNODE_PROPERTY_UNSET   (-1U)
> +
> +/**
> + * enum v4l2_fwnode_location - possible device locations
> + * @V4L2_FWNODE_LOCATION_FRONT: device installed on the front side
> + * @V4L2_FWNODE_LOCATION_BACK: device installed on the back side
> + * @V4L2_FWNODE_LOCATION_EXTERNAL: device externally located
> + */
> +enum v4l2_fwnode_location {
> +	V4L2_FWNODE_LOCATION_FRONT,
> +	V4L2_FWNODE_LOCATION_BACK,
> +	V4L2_FWNODE_LOCATION_EXTERNAL
> +};
> +
> +/**
> + * struct v4l2_fwnode_device_properties - fwnode device properties
> + * @location: device location. See &enum v4l2_fwnode_location
> + * @rotation: device rotation
> + */
> +struct v4l2_fwnode_device_properties {
> +	enum v4l2_fwnode_location location;
> +	unsigned int rotation;
> +};
> +
>  /**
>   * struct v4l2_fwnode_link - a link between two endpoints
>   * @local_node: pointer to device_node of this endpoint
> @@ -233,6 +263,24 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,
>   */
>  void v4l2_fwnode_put_link(struct v4l2_fwnode_link *link);
>  
> +/**
> + * v4l2_fwnode_device_parse() - parse fwnode device properties
> + * @dev: pointer to &struct device
> + * @props: pointer to &struct v4l2_fwnode_device_properties where to store the
> + *	   parsed properties values
> + *
> + * This function parses and validates the V4L2 fwnode device properties from
> + * the firmware interface. It is responsibility of the caller to allocate a
> + * valid @struct v4l2_fwnode_device_properties structure and provide a pointer
> + * to it in the @props parameter.
> + *
> + * Return:
> + *	% 0 on success
> + *	%-EINVAL if a parsed property value is not valid
> + */
> +int v4l2_fwnode_device_parse(struct device *dev,
> +			     struct v4l2_fwnode_device_properties *props);
> +
>  /**
>   * typedef parse_endpoint_func - Driver's callback function to be called on
>   *	each V4L2 fwnode endpoint.

-- 
Kind regards,

Sakari Ailus
sakari.ailus@linux.intel.com

  reply	other threads:[~2019-10-18 19:40 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-07 16:29 [PATCH v4 00/11] media: Report camera sensor properties Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 01/11] dt-bindings: video-interfaces: Document 'location' property Jacopo Mondi
2019-10-08  7:40   ` Pavel Machek
2019-10-08  7:58     ` Jacopo Mondi
2019-10-08  8:06       ` Pavel Machek
2019-10-08  8:20         ` Jacopo Mondi
2019-10-22 14:27           ` Hans Verkuil
2019-10-23 14:27             ` Pavel Machek
2019-10-25  6:29               ` Tomasz Figa
2019-10-26 20:48                 ` Laurent Pinchart
2019-11-18 11:32                   ` Tomasz Figa
2019-11-21 16:02                     ` Jacopo Mondi
2019-11-22  4:53                       ` Tomasz Figa
2019-10-26 11:23               ` Jacopo Mondi
2019-10-18 19:40   ` Sakari Ailus
2019-10-07 16:29 ` [PATCH v4 02/11] media: v4l2-ctrl: Document V4L2_CID_CAMERA_SENSOR_LOCATION Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 03/11] dt-bindings: video-interface: Expand rotation description Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 04/11] media: v4l2-ctrl: Document V4L2_CID_CAMERA_SENSOR_ROTATION Jacopo Mondi
2019-10-22 14:14   ` Hans Verkuil
2019-10-07 16:29 ` [PATCH v4 05/11] media: v4l2-ctrls: Add camera location and rotation Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 06/11] media: v4l2-fwnode: Add helper to parse device properties Jacopo Mondi
2019-10-18 19:36   ` Sakari Ailus [this message]
2019-11-08  9:20     ` Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 07/11] include: v4l2-ctrl: Sort forward declarations Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 08/11] media: v4l2-ctrls: Sort includes alphabetically Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 09/11] media: v4l2-ctrls: Add helper to register properties Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 10/11] media: i2c: ov5670: Parse and " Jacopo Mondi
2019-10-07 16:29 ` [PATCH v4 11/11] media: i2c: ov13858: " Jacopo Mondi
2019-10-18 19:10 ` [PATCH v4 00/11] media: Report camera sensor properties 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=20191018193640.GE3712@kekkonen.localdomain \
    --to=sakari.ailus@linux.intel.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jacopo@jmondi.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=tfiga@google.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;
as well as URLs for NNTP newsgroup(s).