From patchwork Thu Oct 22 13:37:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 286125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E48B0C388F2 for ; Thu, 22 Oct 2020 13:38:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CF8424630 for ; Thu, 22 Oct 2020 13:38:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AKmlJVaT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2900254AbgJVNiP (ORCPT ); Thu, 22 Oct 2020 09:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900222AbgJVNiC (ORCPT ); Thu, 22 Oct 2020 09:38:02 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA2BBC0613CE for ; Thu, 22 Oct 2020 06:38:00 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id 13so2152624wmf.0 for ; Thu, 22 Oct 2020 06:38:00 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=8Hb+989JOofjjUh5aGhwd9WAuZ4cL+L7iJMxJ5IqyWA=; b=AKmlJVaT5Hrvhfka8Opvo4KGn4rXOOHMq018iYikKCOr5GKn74IR9yNWaWbyPpg+9Q 7nMmwl5Ts4ahYOEbBKa0G11DXK0YJ9dRIQS9GH+jEbSzijfTgJVA4CKybQn+cy7JwNcR +6r6dsEJXiwc6tHA55H55+gFsHOgYlOT44+HE= 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:mime-version:content-transfer-encoding; bh=8Hb+989JOofjjUh5aGhwd9WAuZ4cL+L7iJMxJ5IqyWA=; b=KJJ/+zZfeGvAxkJW3DaH2kuKCvgYNAw2f8WRBPwOkXoJO+LEO5oHElEWDFX5osrogS 1pUpMJEHnjGeOQbP9kK/DKVeamgSLOIPML1y8/3/J9jbMQQBMwCQjYtjBsdy4/UcNY/8 dlCa3aVUiZyEGXJsdKW42PtDesWKAAFSI1m5KNVcro1RDpgkpkes2wxSNydZOlEWaq8A LMOb5VLjmR1YI51jY49bcjhCB7twQEy5yWOCT16W6zg6B4/KI7loZC/4U7s3mRLKudre uYXlKFmH+mXagMhJvdPXz7hUj8wiWFIhGxI+2L75mpt4QzWDcHDt4DO3e2Sn2cVmD2wZ 8cwQ== X-Gm-Message-State: AOAM531G2n4zyhzntcUUNth/e0dOVbnR3TjKIUexfWOTh2IhONY1bVOv 13+fKXwboR/IrpZFQ+uWPySxjg== X-Google-Smtp-Source: ABdhPJwUGkUAkh6z5NDXNn1qijT3VBPtRSez3VFLz5/oC5CV9v2FsLKhesBZ0ALXzqnmqdA+0CjGaA== X-Received: by 2002:a1c:9d54:: with SMTP id g81mr2652082wme.102.1603373879643; Thu, 22 Oct 2020 06:37:59 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q10sm4094031wrp.83.2020.10.22.06.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:37:59 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tfiga@chromium.org, Ricardo Ribalda Subject: [PATCH 4/6] media: uvcvideo: Add Privacy control based on EXT_GPIO Date: Thu, 22 Oct 2020 15:37:51 +0200 Message-Id: <20201022133753.310506-5-ribalda@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022133753.310506-1-ribalda@chromium.org> References: <20201022133753.310506-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a new control and mapping for Privacy controls connected to UVC_GUID_EXT_GPIO_CONTROLLERs. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 20 ++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 913739915863..786498e66646 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -347,6 +347,16 @@ static const struct uvc_control_info uvc_ctrls[] = { | UVC_CTRL_FLAG_RESTORE | UVC_CTRL_FLAG_AUTO_UPDATE, }, + { + .entity = UVC_GUID_EXT_GPIO_CONTROLLER, + .selector = UVC_CT_PRIVACY_CONTROL, + .index = 0, + .size = 1, + .flags = UVC_CTRL_FLAG_GET_CUR + | UVC_CTRL_FLAG_AUTO_UPDATE + | UVC_CTRL_FLAG_ENTITY_GET_INFO + | UVC_CTRL_FLAG_ENTITY_GET_CUR, + }, }; static const struct uvc_menu_info power_line_frequency_controls[] = { @@ -735,6 +745,16 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, }, + { + .id = V4L2_CID_PRIVACY, + .name = "Privacy", + .entity = UVC_GUID_EXT_GPIO_CONTROLLER, + .selector = UVC_CT_PRIVACY_CONTROL, + .size = 1, + .offset = 0, + .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, + .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, + }, }; /* ------------------------------------------------------------------------ diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 8e5a9fc35820..a493bc383d3e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -58,7 +58,7 @@ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} #define UVC_GUID_EXT_GPIO_CONTROLLER \ {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf, \ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01} + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01} #define UVC_GUID_FORMAT_MJPEG \ { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ From patchwork Thu Oct 22 13:37:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 286126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43812C388F2 for ; Thu, 22 Oct 2020 13:38:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEF29222E9 for ; Thu, 22 Oct 2020 13:38:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="nbgJkYp6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507576AbgJVNiF (ORCPT ); Thu, 22 Oct 2020 09:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900229AbgJVNiE (ORCPT ); Thu, 22 Oct 2020 09:38:04 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9220C0613D2 for ; Thu, 22 Oct 2020 06:38:02 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id 13so2152755wmf.0 for ; Thu, 22 Oct 2020 06:38:02 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=xuazTAVuWOaGAhXcYUEHC2fhzgfRLU0vFOZpMsy8TBQ=; b=nbgJkYp63m4rmIhHmUxnHZj+Urg/MRZxffOXk3O+VNQTx7AnbH5zQUO+LjDfiC+Tp4 0GFB8MN7piN0yTl8NjYoY+R3Nm+YWKqdoMsvyqAoui0Tae8wwQz+GrCd/h9SYTeqyXsh b229ntFS+4rZoV8tVIw4IybIojU8U9PzrdkJk= 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:mime-version:content-transfer-encoding; bh=xuazTAVuWOaGAhXcYUEHC2fhzgfRLU0vFOZpMsy8TBQ=; b=j/AZuQEBHP5LPsxTNTiptKvh2sC9pOrPmbwxWEdnv6UNDgwRLBHVQsXGd4xAAAx9Kw BBju/M9uAQ7sT6JOFU2zweKOSrnVyh4IzP2sY2nH2zue7qkvBdGb1NWsNJkJdIwqow3C z6mrCvacnzO+ZxKYYI7qTx5z5+w9tLPiI5IVQKw1eQ1hi285izgnFzrb14C8gl1LJwDU GjjMgxL1NKTuPzz7NbW+Wp/S1q166ABxIiMFfQud508QXoUrHi62UtwEs5ifmwkjUE7e lYoB2KKPLqMvkJQZ5e6o9IHWPTAvZ7cvq+wqSgKARTpDEqJo4HWOAQkXGzvVNUzhtPNN D9Vg== X-Gm-Message-State: AOAM531C7Zoyd3js16FPDgNMDinyffpKMCJlognFctukxptpJDPT72fN ZFT5QfosrvxpNeFr3lpPCtxOvA== X-Google-Smtp-Source: ABdhPJyJdhp6mATJXrrc9AyS5uJUoaza7cixAKWOYcnAPxJWO5g8X1tkDeI83moKm80b8WSFXmVBnA== X-Received: by 2002:a1c:7c09:: with SMTP id x9mr2683433wmc.181.1603373881466; Thu, 22 Oct 2020 06:38:01 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q10sm4094031wrp.83.2020.10.22.06.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:38:01 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tfiga@chromium.org, Ricardo Ribalda Subject: [PATCH 6/6] media: uvcvideo: Handle IRQs from the privacy_pin Date: Thu, 22 Oct 2020 15:37:53 +0200 Message-Id: <20201022133753.310506-7-ribalda@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022133753.310506-1-ribalda@chromium.org> References: <20201022133753.310506-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If the privacy pin produces an IRQ, read the gpio and notify userspace via an event. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 3 +++ drivers/media/usb/uvc/uvc_driver.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 3a49a1326a90..00c41cba0f68 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1346,6 +1346,9 @@ static void uvc_ctrl_status_event_work(struct work_struct *work) mutex_unlock(&chain->ctrl_mutex); + if (!w->urb) + return; + /* Resubmit the URB. */ w->urb->interval = dev->int_ep->desc.bInterval; ret = usb_submit_urb(w->urb, GFP_KERNEL); diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 180e503e900f..d1260d131bd8 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1460,6 +1460,25 @@ static int uvc_gpio_get_info(struct uvc_entity *entity, u8 cs, u8 *caps) return 0; } +static irqreturn_t uvc_privacy_gpio_irq(int irq, void *data) +{ + struct uvc_device *dev = data; + struct uvc_video_chain *chain; + struct uvc_entity *term; + u8 value; + + list_for_each_entry(chain, &dev->chains, list) { + list_for_each_entry(term, &dev->entities, list) { + if (UVC_ENTITY_TYPE(term) == UVC_GPIO_UNIT) { + value = gpiod_get_value(term->gpio.gpio_privacy); + uvc_ctrl_status_event(NULL, chain, term->controls, &value); + } + } + } + + return IRQ_HANDLED; +} + static int uvc_parse_gpio(struct uvc_device *dev) { struct uvc_entity *unit; @@ -1490,6 +1509,17 @@ static int uvc_parse_gpio(struct uvc_device *dev) list_add_tail(&unit->list, &dev->entities); + irq = gpiod_to_irq(gpio_privacy); + + if (irq == -EPROBE_DEFER) + return -EPROBE_DEFER; + + if (irq < 0) + return 0; + + ret = devm_request_irq(&dev->udev->dev, irq, uvc_privacy_gpio_irq, IRQF_SHARED, + "uvc_privacy_gpio", dev); + return 0; }