From: Ricardo Ribalda Delgado <ribalda@kernel.org>
To: Philipp Zabel <p.zabel@pengutronix.de>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Jacopo Mondi <jacopo@jmondi.org>
Cc: Ricardo Ribalda Delgado <ribalda@kernel.org>
Subject: [PATCH v3 5/7] media: v4l2-core: Add new helper for area controls
Date: Fri, 23 Aug 2019 14:37:35 +0200 [thread overview]
Message-ID: <20190823123737.7774-5-ribalda@kernel.org> (raw)
In-Reply-To: <20190823123737.7774-1-ribalda@kernel.org>
Adding a V4L2_CID_UNIT_CELL_SIZE control requires a lot of boilerplate,
try to minimize it by adding a new helper.
Suggested-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
---
drivers/media/v4l2-core/v4l2-ctrls.c | 25 ++++++++++++++++++++++++-
include/media/v4l2-ctrls.h | 16 ++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index b3bf458df7f7..33e48f0aec1a 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -2660,7 +2660,6 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
}
EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items);
-/* Helper function for standard integer menu controls */
struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops,
u32 id, u8 _max, u8 _def, const s64 *qmenu_int)
@@ -2684,6 +2683,30 @@ struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
}
EXPORT_SYMBOL(v4l2_ctrl_new_int_menu);
+static void area_init(const struct v4l2_ctrl *ctrl, u32 idx,
+ union v4l2_ctrl_ptr ptr)
+{
+ memcpy(ptr.p_area, ctrl->priv, sizeof(*ptr.p_area));
+}
+
+static const struct v4l2_ctrl_type_ops area_ops = {
+ .init = area_init,
+};
+
+struct v4l2_ctrl *v4l2_ctrl_new_area(struct v4l2_ctrl_handler *hdl,
+ const struct v4l2_ctrl_ops *ops,
+ u32 id, const struct v4l2_area *area)
+{
+ static struct v4l2_ctrl_config ctrl = {
+ .id = V4L2_CID_UNIT_CELL_SIZE,
+ .type_ops = &area_ops,
+ };
+
+ return v4l2_ctrl_new_custom(hdl, &ctrl, (void *)area);
+}
+EXPORT_SYMBOL(v4l2_ctrl_new_area);
+
+/* Helper function for standard integer menu controls */
/* Add the controls from another handler to our own. */
int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl_handler *add,
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 9a3d11350e67..36f0712ea6dd 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -669,6 +669,22 @@ struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
u32 id, u8 max, u8 def,
const s64 *qmenu_int);
+/**
+ * v4l2_ctrl_new_area() - Allocate and initialize a V4L2_CTRL_TYPE_AREA control.
+ *
+ * @hdl: The control handler.
+ * @ops: The control ops.
+ * @id: The control ID.
+ * @area: The width and height of the area in a struct v4l2_area.
+ *
+ * If the &v4l2_ctrl struct could not be allocated then NULL is returned
+ * and @hdl->error is set to the error code (if it wasn't set already).
+ */
+
+struct v4l2_ctrl *v4l2_ctrl_new_area(struct v4l2_ctrl_handler *hdl,
+ const struct v4l2_ctrl_ops *ops,
+ u32 id, const struct v4l2_area *area);
+
/**
* typedef v4l2_ctrl_filter - Typedef to define the filter function to be
* used when adding a control handler.
--
2.23.0.rc1
next prev parent reply other threads:[~2019-08-23 12:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-23 12:37 [PATCH v3 1/7] media: add V4L2_CID_UNIT_CELL_SIZE control Ricardo Ribalda Delgado
2019-08-23 12:37 ` [PATCH v3 2/7] Documentation: media: Describe V4L2_CID_UNIT_CELL_SIZE Ricardo Ribalda Delgado
2019-08-23 12:56 ` Philipp Zabel
2019-08-23 12:37 ` [PATCH v3 3/7] Documentation: media: Document V4L2_CTRL_TYPE_AREA Ricardo Ribalda Delgado
2019-08-23 12:56 ` Philipp Zabel
2019-08-26 7:40 ` Jacopo Mondi
2019-09-12 10:51 ` Ricardo Ribalda Delgado
2019-09-12 11:00 ` Hans Verkuil
2019-08-23 12:37 ` [PATCH v3 4/7] media: imx214: Add new control with V4L2_CID_UNIT_CELL_SIZE Ricardo Ribalda Delgado
2019-08-23 12:56 ` Philipp Zabel
2019-08-23 12:37 ` Ricardo Ribalda Delgado [this message]
2019-08-23 12:56 ` [PATCH v3 5/7] media: v4l2-core: Add new helper for area controls Philipp Zabel
2019-08-23 13:05 ` Ricardo Ribalda Delgado
2019-08-23 13:13 ` Philipp Zabel
2019-08-26 7:43 ` Jacopo Mondi
2019-08-29 10:57 ` Hans Verkuil
2019-08-23 12:37 ` [PATCH v3 6/7] Documentation: Document v4l2_ctrl_new area Ricardo Ribalda Delgado
2019-08-26 7:46 ` Jacopo Mondi
2019-08-23 12:37 ` [PATCH v3 7/7] imx214: Use v4l2_ctrl_new_area helper Ricardo Ribalda Delgado
2019-08-26 7:54 ` Jacopo Mondi
2019-08-26 7:12 ` [PATCH v3 1/7] media: add V4L2_CID_UNIT_CELL_SIZE control Jacopo Mondi
2019-08-26 7:30 ` Jacopo Mondi
2019-08-29 10:39 ` Hans Verkuil
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=20190823123737.7774-5-ribalda@kernel.org \
--to=ribalda@kernel.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jacopo@jmondi.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=sakari.ailus@linux.intel.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).