Linux-Media Archive on lore.kernel.org
 help / color / Atom feed
From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: Jacopo Mondi <jacopo@jmondi.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	tfiga@google.com, pavel@ucw.cz
Cc: "open list:MEDIA INPUT INFRASTRUCTURE (V4L/DVB)" 
	<linux-media@vger.kernel.org>
Subject: Re: [PATCH v3 09/11] media: v4l2-ctrls: Add helper to register properties
Date: Fri, 13 Sep 2019 16:25:24 +0200
Message-ID: <1ec2fbb1-0173-83e8-e82b-bf521f26a044@xs4all.nl> (raw)
In-Reply-To: <20190912201055.13964-10-jacopo@jmondi.org>

On 9/12/19 10:10 PM, Jacopo Mondi wrote:
> Add an helper function to v4l2-ctrls to register controls associated
> with a device property. Add an UNSET flag to the device properties to
> distinguish uninitialized properties from properties with an actual
> value at control registration time.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  drivers/media/v4l2-core/v4l2-ctrls.c  | 42 +++++++++++++++++++++++++++
>  drivers/media/v4l2-core/v4l2-fwnode.c |  2 ++
>  include/media/v4l2-ctrls.h            | 28 ++++++++++++++++++
>  include/media/v4l2-fwnode.h           |  2 ++
>  4 files changed, 74 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> index 6fb94968a98d..46e170f04aed 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -16,6 +16,7 @@
>  #include <media/v4l2-dev.h>
>  #include <media/v4l2-device.h>
>  #include <media/v4l2-event.h>
> +#include <media/v4l2-fwnode.h>
>  #include <media/v4l2-ioctl.h>
>  
>  #define dprintk(vdev, fmt, arg...) do {					\
> @@ -4417,3 +4418,44 @@ __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait)
>  	return 0;
>  }
>  EXPORT_SYMBOL(v4l2_ctrl_poll);
> +
> +int v4l2_ctrl_register_properties(struct v4l2_ctrl_handler *hdl,

Hmm, let's call this:

v4l2_ctrl_new_fwnode_properties().

You don't register properties, you add new controls representing properties.

And v4l2_ctrl_new_ is in line with existing functions that create controls.

> +				  const struct v4l2_ctrl_ops *ctrl_ops,
> +				  const struct v4l2_fwnode_device_properties *p)
> +{
> +	if (p->location != V4L2_FWNODE_PROPERTY_UNSET &&
> +	    !v4l2_ctrl_find(hdl, V4L2_CID_CAMERA_SENSOR_LOCATION)) {

No need for v4l2_ctrl_find: if the control already exists, then the
control framework will automatically ignore the duplicate control.

> +		u32 location_ctrl;
> +
> +		switch (p->location) {
> +		case V4L2_FWNODE_LOCATION_FRONT:
> +			location_ctrl = V4L2_LOCATION_FRONT;
> +			break;
> +		case V4L2_FWNODE_LOCATION_BACK:
> +			location_ctrl = V4L2_LOCATION_BACK;
> +			break;
> +		case V4L2_FWNODE_LOCATION_EXTERNAL:
> +			location_ctrl = V4L2_LOCATION_EXTERNAL;
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +		if (!v4l2_ctrl_new_std(hdl, ctrl_ops,
> +				       V4L2_CID_CAMERA_SENSOR_LOCATION,
> +				       location_ctrl, location_ctrl, 1,
> +				       location_ctrl))
> +			return hdl->error;
> +	}
> +
> +	if (p->rotation != V4L2_FWNODE_PROPERTY_UNSET &&
> +	    !v4l2_ctrl_find(hdl, V4L2_CID_CAMERA_SENSOR_ROTATION)) {

Ditto.

> +		if (!v4l2_ctrl_new_std(hdl, ctrl_ops,
> +				       V4L2_CID_CAMERA_SENSOR_ROTATION,
> +				       p->rotation, p->rotation, 1,
> +				       p->rotation))
> +			return hdl->error;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(v4l2_ctrl_register_properties);

I like this split into one fwnode parse function and one ctrl function
much better.

> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
> index d325a2d5c088..e4fed288e498 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -605,6 +605,7 @@ int v4l2_fwnode_device_parse(struct device *dev,
>  	memset(props, 0, sizeof(*props));
>  
>  	dev_dbg(dev, "===== begin V4L2 device properties parsing\n");
> +	props->location = V4L2_FWNODE_PROPERTY_UNSET;
>  	ret = fwnode_property_read_u32(fwnode, "location", &val);
>  	if (!ret) {
>  		switch (val) {
> @@ -621,6 +622,7 @@ int v4l2_fwnode_device_parse(struct device *dev,
>  		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) {
> diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> index 95b4fa6243d1..ce73911f180b 100644
> --- a/include/media/v4l2-ctrls.h
> +++ b/include/media/v4l2-ctrls.h
> @@ -29,6 +29,7 @@ struct v4l2_ctrl;
>  struct v4l2_ctrl_handler;
>  struct v4l2_ctrl_helper;
>  struct v4l2_fh;
> +struct v4l2_fwnode_device_properties;
>  struct v4l2_subdev;
>  struct v4l2_subscribed_event;
>  struct video_device;
> @@ -1330,4 +1331,31 @@ int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
>   */
>  int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
>  
> +/**
> + * v4l2_ctrl_register_properties() - Register controls for the device properties
> + *
> + * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
> + * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
> + * @p: pointer to &struct v4l2_fwnode_device_properties
> + *
> + * This function registers controls associated to device properties, using the
> + * property values contained in @p parameter, if the property has been set to
> + * a value.
> + *
> + * Currently the following v4l2 controls are parsed and registered:
> + * - V4L2_CID_CAMERA_SENSOR_LOCATION;
> + * - V4L2_CID_CAMERA_SENSOR_ROTATION;
> + *
> + * Controls already registered by the caller with the @hdl control handler are
> + * not overwritten. Callers should register the controls they want to handle
> + * themselves before calling this function.
> + *
> + * NOTE: This function locks the @hdl control handler mutex, the caller shall
> + * not hold the lock when calling this function.
> + *
> + * Return: 0 on success, a negative error code on failure.
> + */
> +int v4l2_ctrl_register_properties(struct v4l2_ctrl_handler *hdl,
> +				  const struct v4l2_ctrl_ops *ctrl_ops,
> +				  const struct v4l2_fwnode_device_properties *p);
>  #endif
> diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
> index 86af6d9d11fe..ae02db22c70e 100644
> --- a/include/media/v4l2-fwnode.h
> +++ b/include/media/v4l2-fwnode.h
> @@ -109,6 +109,8 @@ struct v4l2_fwnode_endpoint {
>  	unsigned int nr_of_link_frequencies;
>  };
>  
> +#define V4L2_FWNODE_PROPERTY_UNSET	(-1U)
> +

Ah, that answers my previous question about unset properties.

I think this fwnode addition should be done in a separate earlier patch.

And it needs a comment.

Regards,

	Hans

>  /**
>   * enum v4l2_fwnode_location - possible device locations
>   * @V4L2_FWNODE_LOCATION_FRONT: device installed on the front side
> 


  reply index

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 20:10 [PATCH v3 00/11] media: Report camera sensor properties Jacopo Mondi
2019-09-12 20:10 ` [PATCH v3 01/11] dt-bindings: video-interfaces: Document 'location' property Jacopo Mondi
2019-09-13 13:45   ` Hans Verkuil
2019-09-12 20:10 ` [PATCH v3 02/11] media: v4l2-ctrl: Document V4L2_CID_CAMERA_SENSOR_LOCATION Jacopo Mondi
2019-09-13 13:48   ` Hans Verkuil
2019-09-12 20:10 ` [PATCH v3 03/11] dt-bindings: video-interfaces: Expand rotation description Jacopo Mondi
2019-09-13 13:50   ` Hans Verkuil
2019-09-12 20:10 ` [PATCH v3 04/11] media: v4l2-ctrl: Document V4L2_CID_CAMERA_SENSOR_ROTATION Jacopo Mondi
2019-09-13 14:02   ` Hans Verkuil
2019-09-13 18:49     ` Jacopo Mondi
2019-09-12 20:10 ` [PATCH v3 05/11] media: v4l2-ctrls: Add camera location and rotation Jacopo Mondi
2019-09-12 20:10 ` [PATCH v3 06/11] media: v4l2-fwnode: Add helper to parse device properties Jacopo Mondi
2019-09-13 14:08   ` Hans Verkuil
2019-09-13 19:04     ` Jacopo Mondi
2019-09-12 20:10 ` [PATCH v3 07/11] include: v4l2-ctrl: Sort forward declarations Jacopo Mondi
2019-09-12 20:10 ` [PATCH v3 08/11] media: v4l2-ctrls: Sort includes alphabetically Jacopo Mondi
2019-09-12 20:10 ` [PATCH v3 09/11] media: v4l2-ctrls: Add helper to register properties Jacopo Mondi
2019-09-13 14:25   ` Hans Verkuil [this message]
2019-09-12 20:10 ` [PATCH v3 10/11] media: i2c: ov5670: Parse and " Jacopo Mondi
2019-09-12 20:10 ` [PATCH v3 11/11] media: i2c: ov13858: " Jacopo Mondi

Reply instructions:

You may reply publically 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=1ec2fbb1-0173-83e8-e82b-bf521f26a044@xs4all.nl \
    --to=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=sakari.ailus@linux.intel.com \
    --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

Linux-Media Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-media/0 linux-media/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-media linux-media/ https://lore.kernel.org/linux-media \
		linux-media@vger.kernel.org linux-media@archiver.kernel.org
	public-inbox-index linux-media


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-media


AGPL code for this site: git clone https://public-inbox.org/ public-inbox