Received: by 10.223.185.116 with SMTP id b49csp220357wrg; Mon, 19 Feb 2018 20:50:46 -0800 (PST) X-Google-Smtp-Source: AH8x225dxIBKccvVs1CZRxS+K3c1k9U4+4U4Dw4HKzvA6UqSUkdLAkzsidhjqxc77vLlVVrCoG5s X-Received: by 10.99.1.206 with SMTP id 197mr14044343pgb.179.1519102246457; Mon, 19 Feb 2018 20:50:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519102246; cv=none; d=google.com; s=arc-20160816; b=Jj2WOEaMM5uyZtzMGWlscOuF+ZSVLye7U9rDmYPTkOV9TRa82r6KiuX7lzgxzMckXq 9ItjD5pku7qb24aeGbX0F6YGadLl2naVtfoxif68jo2P4hKChNP/7r4CZoKftwqU/Utx PZTEv5wz1gK+NAp4ZV2e1lDxGO718JdqENnBm0R6zdPo5Xg63NGzAwyVcp2nEJKtQtwr KGdC6FIvlSWuQNu6+oPJi6QQy9yTV+B62Ws+FHU4B3aDbCsf2sCwKWJE+30ICNfyPtBL YwVA6nS9Ye16EVgnIbZL/IgrQbbphNCtQiJltCpOCD/4SeDj3OsTB7aB7OKHUI08ey4M rP4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=qDcdXitz9ebyO7i/NVFDjhcV1KxJtB85qSNljWzPeiY=; b=KSDRrRtQ9MLSdV3Q8a3vTWfujFkkWNDuQgRb2HoBoySiobdB2qyzH4q4dEInN53ezB AxcRYN+yIudAqxdqtdTBJn7lOWYAwX8cFOvnjx15oA3TY3EPZ6xTnRGsBhB0ZJIf8w2M R7KJZv3OOxU8KU9V+OUsAbn+guCEwbKGSTHN78f4Zyr7g2bjotHqLxO9J7UQX6/BjX7y 4sFIevZnPx0H2zVm4QcY2WW3kmZOVPo5ZGV84X8V7hhF1RlXyHs5Z17Xfm7oDWsSxXZl ojyHN3rYp1yiWkbhMGN6JRojhfMxvh4KpBZJoJZxoftYWuCQqZnzkEnW13kM2RCYn4d+ CzNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lxTg3XQL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k136si4490714pga.44.2018.02.19.20.50.32; Mon, 19 Feb 2018 20:50:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lxTg3XQL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751571AbeBTEso (ORCPT + 99 others); Mon, 19 Feb 2018 23:48:44 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:42270 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751359AbeBTEpC (ORCPT ); Mon, 19 Feb 2018 23:45:02 -0500 Received: by mail-pl0-f68.google.com with SMTP id 31so6835986ple.9 for ; Mon, 19 Feb 2018 20:45:02 -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=qDcdXitz9ebyO7i/NVFDjhcV1KxJtB85qSNljWzPeiY=; b=lxTg3XQL9zjbzi4z9aLGUJXdLGWyO5IbX519qzr4BQMuDcJVEMdOuLZN01XUsRhe0c /YynHj09cIHTxr5Vx392eW27zCMiHyX1Bey+mMrrkPfHXZy5r/jYwsRv+DzykW4/UOdo SDJNC6rbns8zfZ0nRENpLQNN5EySxj6WU9HOM= 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=qDcdXitz9ebyO7i/NVFDjhcV1KxJtB85qSNljWzPeiY=; b=p1hwTOkryVeaFpvDJAnos6tkKZUbZJHk6W7xF8ozgiXRTHpOElVbFxO8Pj1rIhUG9b fFMC0fWLcoF4IHY1PUGOy0Bs45Qr9lHy33/d/YCHLCvypq8srh4QhemIxM60G+nfJsbp 9Yq/n5MxIiZVU3aHBAND4YsbCKr7+LY7XBiLgsDT9FO+uP0gJFnkvQyAGu/QsIIwQ9QJ IiEAiNV2hEqq1Ju7lTzfaitnXH/esBwIBPmLv8WaDUI6izt/cASA/7rkXrR2H0IcvBvn 0DbRpSIwmy5pAnKUt4UsS7sIBNAtRFZZIt7SgKMLb2JW3ecG0Lkod7EQ/WEHZFKIokL/ ayuw== X-Gm-Message-State: APf1xPC76heosJT2sz4WQubjClApFZin/2QgKFVdXifjxez228eJoQoV zpuOte21k1mRe3s1aKLCzsSjUg== X-Received: by 2002:a17:902:bd4b:: with SMTP id b11-v6mr16268936plx.313.1519101901976; Mon, 19 Feb 2018 20:45:01 -0800 (PST) Received: from acourbot.tok.corp.google.com ([2401:fa00:4:1002:a6cd:a898:e07b:a331]) by smtp.gmail.com with ESMTPSA id q9sm783397pgs.28.2018.02.19.20.44.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2018 20:45:01 -0800 (PST) From: Alexandre Courbot To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Pawel Osciak , Marek Szyprowski , Tomasz Figa , Sakari Ailus Cc: Gustavo Padovan , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Verkuil , Alexandre Courbot Subject: [RFCv4 07/21] v4l2-ctrls: add v4l2_ctrl_request_setup Date: Tue, 20 Feb 2018 13:44:11 +0900 Message-Id: <20180220044425.169493-8-acourbot@chromium.org> X-Mailer: git-send-email 2.16.1.291.g4437f3f132-goog In-Reply-To: <20180220044425.169493-1-acourbot@chromium.org> References: <20180220044425.169493-1-acourbot@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 00c4488ca1da..166647817efb 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls.c +++ b/drivers/media/v4l2-core/v4l2-ctrls.c @@ -1662,6 +1662,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) @@ -3427,6 +3435,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 c51e1cacc09d..3a10fb3419e3 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -259,6 +259,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; }; @@ -1056,6 +1057,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); -- 2.16.1.291.g4437f3f132-goog