From patchwork Wed Jan 31 10:26:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 10193823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B0C82603EE for ; Wed, 31 Jan 2018 10:26:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68A8C23B32 for ; Wed, 31 Jan 2018 10:26:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A49027DCD; Wed, 31 Jan 2018 10:26:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA29923B32 for ; Wed, 31 Jan 2018 10:26:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753877AbeAaK0n (ORCPT ); Wed, 31 Jan 2018 05:26:43 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:41585 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753780AbeAaK0f (ORCPT ); Wed, 31 Jan 2018 05:26:35 -0500 Received: by mail-pg0-f66.google.com with SMTP id 136so9678010pgd.8 for ; Wed, 31 Jan 2018 02:26:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=s7aCOGTMBFIRkpcBkpoaT/oVe3kEuTLmbPEsD1wFBvg=; b=Q9Ee3I5B7RPnV9iHOL68myYm7zjn8OfbQQ5J3AhdrmxJpEBFeFs+NvHkk6lnqpuZx/ I/TcgZqwrSwbbfQpzZ4sXcY4uBPbHt0HoZt9SIRdeJ9LecwK8sVc1DyIKTdjN7P62uJs p/b4ob/mmr1ZL+F8hMHuOBNOzrNHqVFNvAdGI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=s7aCOGTMBFIRkpcBkpoaT/oVe3kEuTLmbPEsD1wFBvg=; b=OQbHmIt5T3rJEKCKAHsj4BQ/SE2UvKY0qyCv8zkRLfqKkc+1Zz6lUByecdMeLL+mIF q6kCBrUc6J9SAVmiArbRAXAuPo70gPyiUyz0uuciN1GS53Rlz5QxIMUkUgqtN8Tr7g08 D2kMzFhz9jTuUzRaIW7Ucxfi7y1ig2ptif9YX9Zc0zMuZWHZCn7NiZUgLRJhbi0CtW9Y AuMfPef310YYcTT2zZP6RJVH/EgeamWH4QUlyJ01o4kJw1whnxzLtLrTsNBcvy1ta+pE Ce1q8c2jXORR5cm6irlBpKSenjhpt4fFJMMDw+b9wW8AXjVUmWxjkrmRPGjo2MelcJuT 4imw== X-Gm-Message-State: AKwxytfo1Ltz7yotMUMBisTNBZ6reIhKSGjoYCdglhzDlSKm143ZzgF9 toKoZ7bgiwXNvhVeQVZ3S20amw== X-Google-Smtp-Source: AH8x227p/EOLo07xQlIQUf+cTx0eOT04/6Pnk9HQb5G7lciL+wCyyLAKKPPCgdXqp67uMJE3X4DhAA== X-Received: by 10.98.157.26 with SMTP id i26mr33045817pfd.12.1517394395071; Wed, 31 Jan 2018 02:26:35 -0800 (PST) Received: from acourbot.tok.corp.google.com ([2401:fa00:4:1002:a6cd:a898:e07b:a331]) by smtp.gmail.com with ESMTPSA id 76sm39668996pfp.54.2018.01.31.02.26.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jan 2018 02:26:34 -0800 (PST) From: Alexandre Courbot To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Pawel Osciak , Marek Szyprowski , Tomasz Figa , Sakari Ailus , Gustavo Padovan Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Verkuil , Alexandre Courbot Subject: [RFCv2 11/17] v4l2-ctrls: add v4l2_ctrl_request_setup Date: Wed, 31 Jan 2018 19:26:19 +0900 Message-Id: <20180131102625.208021-2-acourbot@chromium.org> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog In-Reply-To: <20180131102625.208021-1-acourbot@chromium.org> References: <20180131102625.208021-1-acourbot@chromium.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil Add a helper function that can set controls from a request. Signed-off-by: Hans Verkuil Signed-off-by: Alexandre Courbot --- drivers/media/v4l2-core/v4l2-ctrls.c | 71 ++++++++++++++++++++++++++++++++++++ include/media/v4l2-ctrls.h | 2 + 2 files changed, 73 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c index e4d29cc76ca8..da3db6268e9c 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1652,6 +1652,14 @@ static void new_to_req(struct v4l2_ctrl_ref *ref) ptr_to_ptr(ref->ctrl, ref->ctrl->p_new, ref->p_req); } +/* Copy the request value to the new value */ +static void req_to_new(struct v4l2_ctrl_ref *ref) +{ + if (!ref) + return; + ptr_to_ptr(ref->ctrl, ref->p_req, ref->ctrl->p_new); +} + /* Return non-zero if one or more of the controls in the cluster has a new value that differs from the current value. */ static int cluster_changed(struct v4l2_ctrl *master) @@ -3423,6 +3431,69 @@ int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s) } EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_string); +void v4l2_ctrl_request_setup(struct v4l2_ctrl_handler *hdl) +{ + struct v4l2_ctrl_ref *ref; + + if (!hdl) + return; + + mutex_lock(hdl->lock); + + list_for_each_entry(ref, &hdl->ctrl_refs, node) + ref->done = false; + + list_for_each_entry(ref, &hdl->ctrl_refs, node) { + struct v4l2_ctrl *ctrl = ref->ctrl; + struct v4l2_ctrl *master = ctrl->cluster[0]; + int i; + + /* Skip if this control was already handled by a cluster. */ + /* Skip button controls and read-only controls. */ + if (ref->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON || + (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)) + continue; + + v4l2_ctrl_lock(master); + for (i = 0; i < master->ncontrols; i++) { + if (master->cluster[i]) { + struct v4l2_ctrl_ref *r = + find_ref(hdl, master->cluster[i]->id); + + req_to_new(r); + master->cluster[i]->is_new = 1; + r->done = true; + } + } + /* + * For volatile autoclusters that are currently in auto mode + * we need to discover if it will be set to manual mode. + * If so, then we have to copy the current volatile values + * first since those will become the new manual values (which + * may be overwritten by explicit new values from this set + * of controls). + */ + if (master->is_auto && master->has_volatiles && + !is_cur_manual(master)) { + s32 new_auto_val = *master->p_new.p_s32; + + /* + * If the new value == the manual value, then copy + * the current volatile values. + */ + if (new_auto_val == master->manual_mode_value) + update_from_auto_cluster(master); + } + + try_or_set_cluster(NULL, master, true, 0); + + v4l2_ctrl_unlock(master); + } + + mutex_unlock(hdl->lock); +} +EXPORT_SYMBOL(v4l2_ctrl_request_setup); + void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv) { if (ctrl == NULL) diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 24a60ca1a0dd..9cc9c242ed9d 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -252,6 +252,7 @@ struct v4l2_ctrl_ref { struct v4l2_ctrl *ctrl; struct v4l2_ctrl_helper *helper; union v4l2_ctrl_ptr p_req; + bool done; bool from_other_dev; }; @@ -1049,6 +1050,7 @@ int v4l2_ctrl_request_init(struct v4l2_ctrl_handler *hdl); int v4l2_ctrl_request_clone(struct v4l2_ctrl_handler *hdl, const struct v4l2_ctrl_handler *from, bool (*filter)(const struct v4l2_ctrl *ctrl)); +void v4l2_ctrl_request_setup(struct v4l2_ctrl_handler *hdl); void v4l2_ctrl_request_get(struct v4l2_ctrl_handler *hdl); void v4l2_ctrl_request_put(struct v4l2_ctrl_handler *hdl);