Skip to content

Commit 78ea1c9

Browse files
jmondipopcornmix
authored andcommitted
media: v4l2-ctrls: Add helper to register properties
Add an helper function to v4l2-ctrls to register controls associated with a device property. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Commit e0a3606 upstream Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
1 parent f82787a commit 78ea1c9

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

‎drivers/media/v4l2-core/v4l2-ctrls.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <media/v4l2-ctrls.h>
1818
#include <media/v4l2-event.h>
1919
#include <media/v4l2-dev.h>
20+
#include <media/v4l2-fwnode.h>
2021

2122
#define dprintk(vdev, fmt, arg...) do { \
2223
if (!WARN_ON(!(vdev)) && ((vdev)->dev_debug & V4L2_DEV_DEBUG_CTRL)) \
@@ -4627,3 +4628,42 @@ __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait)
46274628
return 0;
46284629
}
46294630
EXPORT_SYMBOL(v4l2_ctrl_poll);
4631+
4632+
int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
4633+
const struct v4l2_ctrl_ops *ctrl_ops,
4634+
const struct v4l2_fwnode_device_properties *p)
4635+
{
4636+
if (p->orientation != V4L2_FWNODE_PROPERTY_UNSET) {
4637+
u32 orientation_ctrl;
4638+
4639+
switch (p->orientation) {
4640+
case V4L2_FWNODE_ORIENTATION_FRONT:
4641+
orientation_ctrl = V4L2_CAMERA_ORIENTATION_FRONT;
4642+
break;
4643+
case V4L2_FWNODE_ORIENTATION_BACK:
4644+
orientation_ctrl = V4L2_CAMERA_ORIENTATION_BACK;
4645+
break;
4646+
case V4L2_FWNODE_ORIENTATION_EXTERNAL:
4647+
orientation_ctrl = V4L2_CAMERA_ORIENTATION_EXTERNAL;
4648+
break;
4649+
default:
4650+
return -EINVAL;
4651+
}
4652+
if (!v4l2_ctrl_new_std_menu(hdl, ctrl_ops,
4653+
V4L2_CID_CAMERA_ORIENTATION,
4654+
V4L2_CAMERA_ORIENTATION_EXTERNAL, 0,
4655+
orientation_ctrl))
4656+
return hdl->error;
4657+
}
4658+
4659+
if (p->rotation != V4L2_FWNODE_PROPERTY_UNSET) {
4660+
if (!v4l2_ctrl_new_std(hdl, ctrl_ops,
4661+
V4L2_CID_CAMERA_SENSOR_ROTATION,
4662+
p->rotation, p->rotation, 1,
4663+
p->rotation))
4664+
return hdl->error;
4665+
}
4666+
4667+
return hdl->error;
4668+
}
4669+
EXPORT_SYMBOL(v4l2_ctrl_new_fwnode_properties);

‎include/media/v4l2-ctrls.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct v4l2_ctrl_handler;
2929
struct v4l2_ctrl_helper;
3030
struct v4l2_ctrl;
3131
struct video_device;
32+
struct v4l2_fwnode_device_properties;
3233
struct v4l2_subdev;
3334
struct v4l2_subscribed_event;
3435
struct v4l2_fh;
@@ -1417,4 +1418,29 @@ int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
14171418
*/
14181419
int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
14191420

1421+
/**
1422+
* v4l2_ctrl_new_fwnode_properties() - Register controls for the device
1423+
* properties
1424+
*
1425+
* @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
1426+
* @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
1427+
* @p: pointer to &struct v4l2_fwnode_device_properties
1428+
*
1429+
* This function registers controls associated to device properties, using the
1430+
* property values contained in @p parameter, if the property has been set to
1431+
* a value.
1432+
*
1433+
* Currently the following v4l2 controls are parsed and registered:
1434+
* - V4L2_CID_CAMERA_ORIENTATION
1435+
* - V4L2_CID_CAMERA_SENSOR_ROTATION;
1436+
*
1437+
* Controls already registered by the caller with the @hdl control handler are
1438+
* not overwritten. Callers should register the controls they want to handle
1439+
* themselves before calling this function.
1440+
*
1441+
* Return: 0 on success, a negative error code on failure.
1442+
*/
1443+
int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
1444+
const struct v4l2_ctrl_ops *ctrl_ops,
1445+
const struct v4l2_fwnode_device_properties *p);
14201446
#endif

0 commit comments

Comments
 (0)