Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5788159pxu; Wed, 23 Dec 2020 05:38:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFL7gk9WIQs3WgMwdfNcVBaljsVrcaMrmR7uIqKOxm4yF5C6PoRV8ptl3ckhu3/UoR+z9d X-Received: by 2002:a17:906:edc8:: with SMTP id sb8mr24214764ejb.247.1608730723946; Wed, 23 Dec 2020 05:38:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608730723; cv=none; d=google.com; s=arc-20160816; b=CExXFUieVUQZjvDdKcRMOUXk4Yjw+z8X7N72FiK5oNSdrlEuzR086BFTmWfF0q30SM 3u+ysIsOpsWp9aTIuSSTovlspNfEv5cF1wC7c0xsjsqQEgC5CTavMDsETjuclvtcNP6Z 6ZATOEFKHZgbemwSmD969CBGGozqmcwu8SwEnIXJdiDbz3qINAnJaC9p+yZJZ8V9WtgU sFX58oQGkA1BMxEBn0AXXseYCrMj/KPlIgvxJ6XKF45eeQXD2IAPIWob+MBAX+OrdgKd /8+7+/9uCiv/LENMoghD3vpqc42wk4kScEPZW+mbJBFQ3E6r/+x35R7Q0uQB2xSMVOZ6 A7IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5UDVhGAE7V5njhjBmj73xbdjwyTUWtm0VUTGNSFrvIA=; b=SMxFYd/G3KYWi+FknpQqd06DoL0hbnPzIO/61Js/vMYunWb/z52yW2ckEx30/8B5XA urD9uPD3Lcl3Dyz43/qKV8R2lbx1vQiaPpuz1H1mzK0r2cRm1u82LrY76B1U58mt+scc L6/RGzm5JMJ468C5mCgGZURN1ani+Hi2SD5HE3iddnkWbSQqn1zyLxygQYY6gRRAEgOs ICDV+j6/uGZ2R/WOE6HWUOR+jUAvYju4YvtYR0Cfny30yU00C891V/LshGRVACzN8H2c Bpq3sUxamYud2sp5QEEu0slEzOFfKhiDp3o8ZiXOq6h7H6MfHVVQp45FtKn8HYekiWHY h6zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dqxdmqPo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id h17si12311871ejd.473.2020.12.23.05.38.21; Wed, 23 Dec 2020 05:38:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dqxdmqPo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728812AbgLWNhR (ORCPT + 99 others); Wed, 23 Dec 2020 08:37:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728803AbgLWNhJ (ORCPT ); Wed, 23 Dec 2020 08:37:09 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A95E6C0619D8 for ; Wed, 23 Dec 2020 05:35:41 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id m5so18615574wrx.9 for ; Wed, 23 Dec 2020 05:35:41 -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 :mime-version:content-transfer-encoding; bh=5UDVhGAE7V5njhjBmj73xbdjwyTUWtm0VUTGNSFrvIA=; b=dqxdmqPoQUPR3p8cfifkew5nJuVMxuuavT1eLvSGCGSB1oSHEFsKiIz5M+chA2P0K4 /fvsnMwlwkEHmu8nFdwuVftoZNSu2TIE9J79AiMm+3uErsa8l6bsuhlmh+ZmX5feBl2o WmFllxm5piMEOEQEaZUS65GtMPLrURaqtpICQ= 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=5UDVhGAE7V5njhjBmj73xbdjwyTUWtm0VUTGNSFrvIA=; b=s42dRNadMyTH7SpnYzQOsHer+o5SxfY40G+YlkevlgC2r5yb/EVTrnbflZlLvuA8AJ KKI0Ak9i6uRzeXHlSK+45UwrhudbrNmR2IzmvCxbriDqvAW09k/UfuCUFwsiHM+ba8Q3 oFs5PZNXJXCGNNxX8WPG9D+NktZsM5QOLwWw8RKqFrQqV4Nn6BqjAfSSNQdGf0A7sBdF 9zY1NJPzX+zxZu63gX2Q6TDBYaPGYitccMd43FACja19l2anPwr3jvqxDUqfvVWtpAVp bmdgalaSZqvK5VEh+j3zM4tRJ17NJgb25YOuMKuUHbhJ68DGLpst7/1D1Mk0/SWikrot 7RhA== X-Gm-Message-State: AOAM533aRKBresb8YGMFOcvXwgqbJGrm3cEgiiZEwRstwe1WjUZOgPL8 SOHmN2eUU5+0u8fa+zF3SAFxFg== X-Received: by 2002:adf:ca0c:: with SMTP id o12mr29774100wrh.154.1608730540425; Wed, 23 Dec 2020 05:35:40 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q143sm31572247wme.28.2020.12.23.05.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 05:35:39 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v7 12/12] media: uvcvideo: Implement UVC_QUIRK_PRIVACY_DURING_STREAM Date: Wed, 23 Dec 2020 14:35:28 +0100 Message-Id: <20201223133528.55014-13-ribalda@chromium.org> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog In-Reply-To: <20201223133528.55014-1-ribalda@chromium.org> References: <20201223133528.55014-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some devices can only read the privacy_pin if the device is streaming. This patch implement a quirk for such devices, in order to avoid invalid reads and/or spurious events. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 55 +++++++++++++++++++++++++++--- drivers/media/usb/uvc/uvc_video.c | 27 +++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 7 ++++ 3 files changed, 84 insertions(+), 5 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index f1f6b9cfa676..4ec14c7fb5c4 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1478,7 +1479,7 @@ static int uvc_parse_control(struct uvc_device *dev) * Privacy GPIO */ -static void uvc_gpio_event(struct uvc_device *dev) +void uvc_gpio_event(struct uvc_device *dev) { struct uvc_entity *unit = dev->gpio_unit; struct uvc_video_chain *chain; @@ -1487,19 +1488,29 @@ static void uvc_gpio_event(struct uvc_device *dev) if (!unit) return; + mutex_lock(&unit->gpio.event_mutex); + new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + if (unit->gpio.last_event_val != new_val) { + /* GPIO entities are always on the first chain. */ + chain = list_first_entry(&dev->chains, + struct uvc_video_chain, list); + uvc_ctrl_status_event(chain, unit->controls, &new_val); + } + unit->gpio.last_event_val = new_val; - /* GPIO entities are always on the first chain. */ - chain = list_first_entry(&dev->chains, struct uvc_video_chain, list); - uvc_ctrl_status_event(chain, unit->controls, &new_val); + mutex_unlock(&unit->gpio.event_mutex); } static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity, u8 cs, void *data, u16 size) { - if (cs != UVC_CT_PRIVACY_CONTROL || size < 1) + if (cs != UVC_CT_PRIVACY_CONTROL || size < 1 || !dev->gpio_unit) return -EINVAL; + if (!dev->gpio_unit->gpio.is_gpio_ready) + return -EBUSY; + *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy); return 0; @@ -1519,10 +1530,31 @@ static irqreturn_t uvc_gpio_irq(int irq, void *data) { struct uvc_device *dev = data; + if (!dev->gpio_unit->gpio.is_gpio_ready) + return IRQ_HANDLED; + uvc_gpio_event(dev); return IRQ_HANDLED; } +static const struct dmi_system_id privacy_valid_during_streamon[] = { + { + .ident = "HP Elite c1030 Chromebook", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_PRODUCT_NAME, "Jinlon"), + }, + }, + { + .ident = "HP Pro c640 Chromebook", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_PRODUCT_NAME, "Dratini"), + }, + }, + { } /* terminate list */ +}; + static int uvc_gpio_parse(struct uvc_device *dev) { struct uvc_entity *unit; @@ -1547,6 +1579,7 @@ static int uvc_gpio_parse(struct uvc_device *dev) } unit->gpio.gpio_privacy = gpio_privacy; + unit->gpio.last_event_val = -1; unit->gpio.irq = irq; unit->gpio.bControlSize = 1; unit->gpio.bmControls = (u8 *)unit + sizeof(*unit); @@ -1554,6 +1587,18 @@ static int uvc_gpio_parse(struct uvc_device *dev) unit->get_cur = uvc_gpio_get_cur; unit->get_info = uvc_gpio_get_info; strncpy(unit->name, "GPIO", sizeof(unit->name) - 1); + mutex_init(&unit->gpio.event_mutex); + + /* + * Note: This quirk will not match external UVC cameras, + * as they will not have the corresponding ACPI GPIO entity. + */ + if (dmi_check_system(privacy_valid_during_streamon)) { + dev->quirks |= UVC_QUIRK_PRIVACY_DURING_STREAM; + unit->gpio.is_gpio_ready = false; + } else { + unit->gpio.is_gpio_ready = true; + } list_add_tail(&unit->list, &dev->entities); diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index f2f565281e63..b333c54d18c1 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -2083,6 +2083,29 @@ int uvc_video_init(struct uvc_streaming *stream) return 0; } +static void uvc_gpio_privacy_quirks(struct uvc_streaming *stream, bool enable) +{ + struct uvc_device *dev = stream->dev; + struct uvc_video_chain *first_chain; + + if (!(dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM)) + return; + + if (!dev->gpio_unit) + return; + + first_chain = list_first_entry(&dev->chains, + struct uvc_video_chain, list); + /* GPIO entities are always on the first chain. */ + if (stream->chain != first_chain) + return; + + dev->gpio_unit->gpio.is_gpio_ready = enable; + + if (enable) + uvc_gpio_event(stream->dev); +} + int uvc_video_start_streaming(struct uvc_streaming *stream) { int ret; @@ -2100,6 +2123,8 @@ int uvc_video_start_streaming(struct uvc_streaming *stream) if (ret < 0) goto error_video; + uvc_gpio_privacy_quirks(stream, true); + return 0; error_video: @@ -2112,6 +2137,8 @@ int uvc_video_start_streaming(struct uvc_streaming *stream) void uvc_video_stop_streaming(struct uvc_streaming *stream) { + uvc_gpio_privacy_quirks(stream, false); + uvc_video_stop_transfer(stream, 1); if (stream->intf->num_altsetting > 1) { diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 3273d03aca9a..a9290e2d1762 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -209,6 +209,7 @@ #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 #define UVC_QUIRK_FORCE_Y8 0x00000800 #define UVC_QUIRK_FORCE_BPP 0x00001000 +#define UVC_QUIRK_PRIVACY_DURING_STREAM 0x00002000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 @@ -366,6 +367,9 @@ struct uvc_entity { u8 *bmControls; struct gpio_desc *gpio_privacy; int irq; + struct mutex event_mutex; + int last_event_val; + bool is_gpio_ready; } gpio; }; @@ -831,6 +835,9 @@ extern const struct v4l2_file_operations uvc_fops; int uvc_mc_register_entities(struct uvc_video_chain *chain); void uvc_mc_cleanup_entity(struct uvc_entity *entity); +/* Privacy gpio */ +void uvc_gpio_event(struct uvc_device *dev); + /* Video */ int uvc_video_init(struct uvc_streaming *stream); int uvc_video_suspend(struct uvc_streaming *stream); -- 2.29.2.729.g45daf8777d-goog