From patchwork Mon Dec 3 12:03:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10709379 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7686516B1 for ; Mon, 3 Dec 2018 12:03:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6901428837 for ; Mon, 3 Dec 2018 12:03:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D148288B5; Mon, 3 Dec 2018 12:03:40 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 C8E6C28837 for ; Mon, 3 Dec 2018 12:03:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726199AbeLCMEX (ORCPT ); Mon, 3 Dec 2018 07:04:23 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:39664 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725883AbeLCMEX (ORCPT ); Mon, 3 Dec 2018 07:04:23 -0500 Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0FC84553; Mon, 3 Dec 2018 13:03:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1543838615; bh=MhsiskXH6ma5WwtOHxdIt9Z/xNulgOgbY7bmYaBic3Q=; h=From:To:Cc:Subject:Date:From; b=ex36DQb9cpAbhSSWtKnoxViRR000GyoWo+Y0/H4EkkIsT7fMmtRujPBfmv02y+WKx FfAR5fj9hMuK7HnDkF8zP17y6l4kQIHkkN7DnkyVt5bRRQiXNUaJUXBXBw5Ir3R44a Ed+w5E1h51CCCbKhaUq8cSxygmA1kLcB9Kr0V9D8= From: Kieran Bingham To: Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Kieran Bingham Subject: [PATCH] Add support to reset device controls Date: Mon, 3 Dec 2018 12:03:31 +0000 Message-Id: <20181203120331.4097-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.17.1 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide a new option '--reset-controls' which will enumerate the available controls on a device or sub-device, and re-initialise them to defaults. Signed-off-by: Kieran Bingham --- This 'extends' the video_list_controls() function with an extra bool flag for 'reset' to prevent duplicating the iteration functionality. The patch could also pass the same flag into 'video_print_control()' rather than implementing 'video_reset_control()' which necessitates calling query_control() a second time. I have chosen to add the extra call, as I feel it makes the code cleaner, and pollutes the existing implementation less. The cost of the extra query, while a little redundant should be minimal and produces a simple function to reset the control independently. --- yavta.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/yavta.c b/yavta.c index c7986bd9e031..30022c45ed5b 100644 --- a/yavta.c +++ b/yavta.c @@ -1186,7 +1186,28 @@ static int video_print_control(struct device *dev, unsigned int id, bool full) return query.id; } -static void video_list_controls(struct device *dev) +static int video_reset_control(struct device *dev, unsigned int id) +{ + struct v4l2_queryctrl query; + int ret; + + ret = query_control(dev, id, &query); + if (ret < 0) + return ret; + + if (query.flags & V4L2_CTRL_FLAG_DISABLED) + return query.id; + + if (query.type == V4L2_CTRL_TYPE_CTRL_CLASS) + return query.id; + + printf("Reset control 0x%08x to %d:\n", query.id, query.default_value); + set_control(dev, query.id, query.default_value); + + return query.id; +} + +static void video_list_controls(struct device *dev, bool reset) { unsigned int nctrls = 0; unsigned int id; @@ -1207,6 +1228,12 @@ static void video_list_controls(struct device *dev) if (ret < 0) break; + if (reset) { + ret = video_reset_control(dev, id); + if (ret < 0) + break; + } + id = ret; nctrls++; } @@ -1837,6 +1864,7 @@ static void usage(const char *argv0) printf(" --offset User pointer buffer offset from page start\n"); printf(" --premultiplied Color components are premultiplied by alpha value\n"); printf(" --queue-late Queue buffers after streamon, not before\n"); + printf(" --reset-controls Enumerate available controls and reset to defaults\n"); printf(" --requeue-last Requeue the last buffers before streamoff\n"); printf(" --timestamp-source Set timestamp source on output buffers [eof, soe]\n"); printf(" --skip n Skip the first n frames\n"); @@ -1860,6 +1888,7 @@ static void usage(const char *argv0) #define OPT_PREMULTIPLIED 269 #define OPT_QUEUE_LATE 270 #define OPT_DATA_PREFIX 271 +#define OPT_RESET_CONTROLS 272 static struct option opts[] = { {"buffer-size", 1, 0, OPT_BUFFER_SIZE}, @@ -1888,6 +1917,7 @@ static struct option opts[] = { {"queue-late", 0, 0, OPT_QUEUE_LATE}, {"get-control", 1, 0, 'r'}, {"requeue-last", 0, 0, OPT_REQUEUE_LAST}, + {"reset-controls", 0, 0, OPT_RESET_CONTROLS}, {"realtime", 2, 0, 'R'}, {"size", 1, 0, 's'}, {"set-control", 1, 0, 'w'}, @@ -1915,6 +1945,7 @@ int main(int argc, char *argv[]) int do_enum_formats = 0, do_set_format = 0; int do_enum_inputs = 0, do_set_input = 0; int do_list_controls = 0, do_get_control = 0, do_set_control = 0; + int do_reset_controls = 0; int do_sleep_forever = 0, do_requeue_last = 0; int do_rt = 0, do_log_status = 0; int no_query = 0, do_queue_late = 0; @@ -2107,6 +2138,9 @@ int main(int argc, char *argv[]) case OPT_QUEUE_LATE: do_queue_late = 1; break; + case OPT_RESET_CONTROLS: + do_reset_controls = 1; + break; case OPT_REQUEUE_LAST: do_requeue_last = 1; break; @@ -2185,7 +2219,10 @@ int main(int argc, char *argv[]) set_control(&dev, ctrl_name, ctrl_value); if (do_list_controls) - video_list_controls(&dev); + video_list_controls(&dev, false); + + if (do_reset_controls) + video_list_controls(&dev, true); if (do_enum_formats) { printf("- Available formats:\n");