From patchwork Fri Jan 4 20:59:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 16124 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1TrENj-0007l8-PR; Fri, 04 Jan 2013 22:00:47 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-3) with esmtp id 1TrENj-0005CR-DD; Fri, 04 Jan 2013 22:00:47 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755056Ab3ADVAD (ORCPT + 1 other); Fri, 4 Jan 2013 16:00:03 -0500 Received: from mail-vc0-f170.google.com ([209.85.220.170]:49768 "EHLO mail-vc0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754949Ab3ADU76 (ORCPT ); Fri, 4 Jan 2013 15:59:58 -0500 Received: by mail-vc0-f170.google.com with SMTP id fl11so17071773vcb.1 for ; Fri, 04 Jan 2013 12:59:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=itcdwttYblo6bPze5qRVYdm1gfRuS9ixYR1+fKcNQH4=; b=YB9M45GMil1ItIqDAEgWiy8n/N+ZuD8Cm21AGsH/hshmQxXeI0ogvZC3Qt6jREDvzs e7pu9/JBXsuoMIae4/DxEfPIQRbgix1nzWCgH5dq6HNZwXfMlsdpVRHG3A7ZDFu3nXhV 7H6IYjOHcn9V9SBJxu78/Ca10kzfhshOh9X4K+HmddOa36J2bOq0WSHQx1BE8mv1TtSu J5KNLECbxfrGnwZ1Z+zgQCO1O2VnLVnTURXavaVQYuMSrwxDguUi+4Rd/i2Hv91FSpCr 2EgWU3djw+vY17CMI5PtHtJ6lkUhNnE8wpeRCyQMjbVPoPl/O6p08fFNa3XVU2QzJeaZ GegA== X-Received: by 10.58.239.162 with SMTP id vt2mr80457813vec.1.1357333197769; Fri, 04 Jan 2013 12:59:57 -0800 (PST) Received: from devin-ubuntu2.home (pool-108-54-72-165.nycmny.fios.verizon.net. [108.54.72.165]) by mx.google.com with ESMTPS id z20sm47278440vds.12.2013.01.04.12.59.56 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 Jan 2013 12:59:56 -0800 (PST) From: Devin Heitmueller To: linux-media@vger.kernel.org Cc: Devin Heitmueller , Hans Verkuil Subject: [PATCH 05/15] v4l2-ctrls: add a notify callback. Date: Fri, 4 Jan 2013 15:59:35 -0500 Message-Id: <1357333186-8466-6-git-send-email-dheitmueller@kernellabs.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1357333186-8466-1-git-send-email-dheitmueller@kernellabs.com> References: <1357333186-8466-1-git-send-email-dheitmueller@kernellabs.com> X-Gm-Message-State: ALoCoQmfpp9GKMl/ypnA0jEJoSXEc6/NcajLpLaSIOEtQjoM3zp4uVjhGmMuesOb6sZjTCZRE8a5 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2013.1.4.204815 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_6000_6999 0, BODY_SIZE_7000_LESS 0, DATE_TZ_NA 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' Sometimes platform/bridge drivers need to be notified when a control from a sub-device changes value. In order to support this a notify callback was added. djh - fix merge conflict in v4l2-ctrls.c Signed-off-by: Hans Verkuil Signed-off-by: Devin Heitmueller --- Documentation/video4linux/v4l2-controls.txt | 22 ++++++++++++++-------- drivers/media/v4l2-core/v4l2-ctrls.c | 18 ++++++++++++++++++ include/media/v4l2-ctrls.h | 25 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index cfe52c7..676f873 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt @@ -715,14 +715,20 @@ a control of this type whenever the first control belonging to a new control class is added. -Proposals for Extensions -======================== +Adding Notify Callbacks +======================= + +Sometimes the platform or bridge driver needs to be notified when a control +from a sub-device driver changes. You can set a notify callback by calling +this function: -Some ideas for future extensions to the spec: +void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, + void (*notify)(struct v4l2_ctrl *ctrl, void *priv), void *priv); -1) Add a V4L2_CTRL_FLAG_HEX to have values shown as hexadecimal instead of -decimal. Useful for e.g. video_mute_yuv. +Whenever the give control changes value the notify callback will be called +with a pointer to the control and the priv pointer that was passed with +v4l2_ctrl_notify. Note that the control's handler lock is held when the +notify function is called. -2) It is possible to mark in the controls array which controls have been -successfully written and which failed by for example adding a bit to the -control ID. Not sure if it is worth the effort, though. +There can be only one notify function per control handler. Any attempt +to set another notify function will cause a WARN_ON. diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index f6ee201..fa02363 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1204,6 +1204,8 @@ static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, send_event(fh, ctrl, (changed ? V4L2_EVENT_CTRL_CH_VALUE : 0) | (update_inactive ? V4L2_EVENT_CTRL_CH_FLAGS : 0)); + if (ctrl->call_notify && changed && ctrl->handler->notify) + ctrl->handler->notify(ctrl, ctrl->handler->notify_priv); } } @@ -2725,6 +2727,22 @@ int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val) } EXPORT_SYMBOL(v4l2_ctrl_s_ctrl_int64); +void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv) +{ + if (ctrl == NULL) + return; + if (notify == NULL) { + ctrl->call_notify = 0; + return; + } + if (WARN_ON(ctrl->handler->notify && ctrl->handler->notify != notify)) + return; + ctrl->handler->notify = notify; + ctrl->handler->notify_priv = priv; + ctrl->call_notify = 1; +} +EXPORT_SYMBOL(v4l2_ctrl_notify); + static int v4l2_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems) { struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 9650911..c4cc041 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -53,6 +53,8 @@ struct v4l2_ctrl_ops { int (*s_ctrl)(struct v4l2_ctrl *ctrl); }; +typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv); + /** struct v4l2_ctrl - The control structure. * @node: The list node. * @ev_subs: The list of control event subscriptions. @@ -72,6 +74,8 @@ struct v4l2_ctrl_ops { * set this flag directly. * @has_volatiles: If set, then one or more members of the cluster are volatile. * Drivers should never touch this flag. + * @call_notify: If set, then call the handler's notify function whenever the + * control's value changes. * @manual_mode_value: If the is_auto flag is set, then this is the value * of the auto control that determines if that control is in * manual mode. So if the value of the auto control equals this @@ -119,6 +123,7 @@ struct v4l2_ctrl { unsigned int is_private:1; unsigned int is_auto:1; unsigned int has_volatiles:1; + unsigned int call_notify:1; unsigned int manual_mode_value:8; const struct v4l2_ctrl_ops *ops; @@ -177,6 +182,10 @@ struct v4l2_ctrl_ref { * control is needed multiple times, so this is a simple * optimization. * @buckets: Buckets for the hashing. Allows for quick control lookup. + * @notify: A notify callback that is called whenever the control changes value. + * Note that the handler's lock is held when the notify function + * is called! + * @notify_priv: Passed as argument to the v4l2_ctrl notify callback. * @nr_of_buckets: Total number of buckets in the array. * @error: The error code of the first failed control addition. */ @@ -187,6 +196,8 @@ struct v4l2_ctrl_handler { struct list_head ctrl_refs; struct v4l2_ctrl_ref *cached; struct v4l2_ctrl_ref **buckets; + v4l2_ctrl_notify_fnc notify; + void *notify_priv; u16 nr_of_buckets; int error; }; @@ -525,6 +536,20 @@ static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) mutex_unlock(ctrl->handler->lock); } +/** v4l2_ctrl_notify() - Function to set a notify callback for a control. + * @ctrl: The control. + * @notify: The callback function. + * @priv: The callback private handle, passed as argument to the callback. + * + * This function sets a callback function for the control. If @ctrl is NULL, + * then it will do nothing. If @notify is NULL, then the notify callback will + * be removed. + * + * There can be only one notify. If another already exists, then a WARN_ON + * will be issued and the function will do nothing. + */ +void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv); + /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. * @ctrl: The control. *