From patchwork Tue Nov 12 17:30:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 844039 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90543213ED5 for ; Tue, 12 Nov 2024 17:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432665; cv=none; b=f9HxH3siqGtF91+XsX0aT1VjL+LNKMgXhVoZ0GOYZ0yWrvN3JtkYP2Ne/U4BEkfTSZZOYvJAxTVZoDEaaiRB9iEUph++TtnWYR8hx3FKCq8s3d9y3tdS4cZod1FW4RO4OeWHqu2BPyg07VIiaSMuMZs1RxyKABmkh3pCl8Uj1oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432665; c=relaxed/simple; bh=SoqOVgZtfk6qflS1R+7nVDeCXG8YVZzmCjVvn+44Tbg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=okGUbLyVaL3qYrptkQApVDAiJMiM2cyrCggUyKK0EgHSCI0PFGVySTSohT27SEMvffo30+5UtdjaciyyyNXLifovRZaraH4kNI3ROv2yhDEpVPyevUZCSCsL0/dvofV44+vdh8OVchez5GAKy7hhOEAan9QE5sr+k2vJHW59X1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=TgP5/+xi; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TgP5/+xi" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b14554468fso407769685a.1 for ; Tue, 12 Nov 2024 09:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731432661; x=1732037461; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=/CEQ1hc/dVUjfVi3Dxzg24dI3YBe1UVLQm5inRUtpP0=; b=TgP5/+xiiYAinb3EGlSscynjb+OIcZxjWaZyoxxoOSfvX0/589bq2tNEACH3/GjQJT wJyXXqfAGffCT+iqfX85PPfhYzRdxASFRshbCUX29ndfXTazF+qfTHegnV0i2TM7vrM9 QhOdbmWG2CGrxzUS8HK7srTMTWDQ6cUoSYHy8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731432661; x=1732037461; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/CEQ1hc/dVUjfVi3Dxzg24dI3YBe1UVLQm5inRUtpP0=; b=PA2dKXQ9rQ5Gu5h0+ML77skbGsOVa3SpqDhMb2AhVEuXqCjOMuhCBxTjkN/0+8/Srs 0G07xKq2GbQvB5d2m26PE4QWgj978EdIe7sV1pyZ00oUOZP32GX+sjT0hW5JPHJwWvk+ AFFPT1aRhd1+nVWVzzprrRhfcN7TijthFeYtbZMTO750DuAsCzTk0W6XeQV2ZAeK2CbC oqrNzH9aUtE4QwCFrYtmnF4boynzg3V2N/U7phXx/7+zBcwFTJ2HiOXmqx+/99XSopMm e0/t2U/y1Tg44lAiSn7GauROOF7MRlx2pp7D9cxNe6nsx73+7OPRpkizF2nX0PQv1OJY /RQQ== X-Forwarded-Encrypted: i=1; AJvYcCXBjedPEi8hWJOf2GfEWjbRgnItnzrPPR0zoB8TiAqAORGdAEm5hQpu0WgJBAaz108J/Y8Xtc3orlt2aA==@vger.kernel.org X-Gm-Message-State: AOJu0YwBeR1lcLSWsrHJfp+q6bGthKEtssrEGEVZGdsF+TH9s2hjNfd+ YQZ3wrBdpRbRSDGCF3NaYYS0etYzA6f3QftA/CO6o4X49d1sjYgivj8kx2dQxQ== X-Google-Smtp-Source: AGHT+IHiWxBPVjEaTLN3awzQ+PvRvVnCssskW5MGI97Bk2RZNJBYbg7ngLO1E1nGrjTeCIqEqGnsIw== X-Received: by 2002:a05:620a:1a02:b0:7b1:5311:468a with SMTP id af79cd13be357-7b331eb4186mr2371784685a.19.1731432661409; Tue, 12 Nov 2024 09:31:01 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac2dcebsm608292285a.7.2024.11.12.09.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:31:00 -0800 (PST) From: Ricardo Ribalda Date: Tue, 12 Nov 2024 17:30:44 +0000 Subject: [PATCH v3 1/8] media: uvcvideo: Fix crash during unbind if gpio unit is in use Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241112-uvc-subdev-v3-1-0ea573d41a18@chromium.org> References: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> In-Reply-To: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda , stable@vger.kernel.org, Sergey Senozhatsky X-Mailer: b4 0.13.0 We used the wrong device for the device managed functions. We used the usb device, when we should be using the interface device. If we unbind the driver from the usb interface, the cleanup functions are never called. In our case, the IRQ is never disabled. If an IRQ is triggered, it will try to access memory sections that are already free, causing an OOPS. We cannot use the function devm_request_threaded_irq here. The devm_* clean functions may be called after the main structure is released by uvc_delete. Luckily this bug has small impact, as it is only affected by devices with gpio units and the user has to unbind the device, a disconnect will not trigger this error. Cc: stable@vger.kernel.org Fixes: 2886477ff987 ("media: uvcvideo: Implement UVC_EXT_GPIO_UNIT") Reviewed-by: Sergey Senozhatsky Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 28 +++++++++++++++++++++------- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index a96f6ca0889f..cd13bf01265d 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1295,14 +1295,14 @@ static int uvc_gpio_parse(struct uvc_device *dev) struct gpio_desc *gpio_privacy; int irq; - gpio_privacy = devm_gpiod_get_optional(&dev->udev->dev, "privacy", + gpio_privacy = devm_gpiod_get_optional(&dev->intf->dev, "privacy", GPIOD_IN); if (IS_ERR_OR_NULL(gpio_privacy)) return PTR_ERR_OR_ZERO(gpio_privacy); irq = gpiod_to_irq(gpio_privacy); if (irq < 0) - return dev_err_probe(&dev->udev->dev, irq, + return dev_err_probe(&dev->intf->dev, irq, "No IRQ for privacy GPIO\n"); unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT, @@ -1329,15 +1329,27 @@ static int uvc_gpio_parse(struct uvc_device *dev) static int uvc_gpio_init_irq(struct uvc_device *dev) { struct uvc_entity *unit = dev->gpio_unit; + int ret; if (!unit || unit->gpio.irq < 0) return 0; - return devm_request_threaded_irq(&dev->udev->dev, unit->gpio.irq, NULL, - uvc_gpio_irq, - IRQF_ONESHOT | IRQF_TRIGGER_FALLING | - IRQF_TRIGGER_RISING, - "uvc_privacy_gpio", dev); + ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, + IRQF_ONESHOT | IRQF_TRIGGER_FALLING | + IRQF_TRIGGER_RISING, + "uvc_privacy_gpio", dev); + + unit->gpio.initialized = !ret; + + return ret; +} + +static void uvc_gpio_deinit(struct uvc_device *dev) +{ + if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) + return; + + free_irq(dev->gpio_unit->gpio.irq, dev); } /* ------------------------------------------------------------------------ @@ -1934,6 +1946,8 @@ static void uvc_unregister_video(struct uvc_device *dev) { struct uvc_streaming *stream; + uvc_gpio_deinit(dev); + list_for_each_entry(stream, &dev->streams, list) { /* Nothing to do here, continue. */ if (!video_is_registered(&stream->vdev)) diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 07f9921d83f2..965a789ed03e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -234,6 +234,7 @@ struct uvc_entity { u8 *bmControls; struct gpio_desc *gpio_privacy; int irq; + bool initialized; } gpio; }; From patchwork Tue Nov 12 17:30:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 842796 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8AB9214430 for ; Tue, 12 Nov 2024 17:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432665; cv=none; b=MdqGhmfmEcbRJuw9myQxhp6BenFd7TQqIQxrbAs/eH918bF+AIRmUlDU2qrvjat3csFK4/D9oZVGzRMVoUX+NjcwMR7RsAUjZKnODzaKbSYlnR2yrLmlVie4BQfFtJX0l8J8NrPBXs7guw277OAiuvaInnhA6ykD0s7uvc82fV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432665; c=relaxed/simple; bh=RkrsccvEqQUhBk8Z1PddvWJhE1cp8KwJo0AXadlFoHU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T87pdHl4N/Iyh5os4MA/Rd1FDRKgYjZtg5kO72i2h4eOur9zMUu+0HV1/Bv+yRE12Ii7fnVofw53jkl7MdE6WdgmKCA5NPTC/zP0t1H3h8koElSN7GbhnPzKROV93SkCH/Hhilo+qxlSwPPvKBV9547uTfi3PyzQfUXOFPQN3nM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=De3eogHB; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="De3eogHB" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7b152a923a3so394021485a.3 for ; Tue, 12 Nov 2024 09:31:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731432662; x=1732037462; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=aTqnfrQkIAHFL33oi5aoABfM2DMERBuyBRyMEKrhpSg=; b=De3eogHBvnUGKjGc/l9LUsC6VWWX/+i3IdwW/TIllREoVotN9KO89Qe2BkXgJJS313 IrG4njT+QumDWWe4EOYAOQfMF+3u31LvbgVSbaU5MV6jG+lJ4m9xHH9hI0qNsn4yCkT3 gG43HNADg3kQyezWgOH220/c6jseoR0HwTTXk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731432662; x=1732037462; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aTqnfrQkIAHFL33oi5aoABfM2DMERBuyBRyMEKrhpSg=; b=K0Z8NxM3Ds+508AeRfSEWXesk9iBlF3Fdmd2sq1GquPywABNjpsZsNQqm/47mXX54r shVsA0MbRIFDch/iQhIJR6UED35o9GxWO32K1gSsLSHlSyJ1zG4nMZe+bLFa6OWecq/g c5SiShxhrh+wayw3hSeGbfvh32w2e/WDGka/Vjpb1GpH88QXOZ+x+fKktW4Q7pV7hOdg X6JvnSp0uVEe+JXAm+RvM+ByGvnWWyXgxIbVEpcsThaFTBtZcmU6R/e/qoBTcrUKTP37 jdvlQMtif8wp/9ap6vyQ0OqcswaiPGmr7cJm+g13Yd3BvtxZ7FoDrBzv0PqtJISSWlFT haGQ== X-Forwarded-Encrypted: i=1; AJvYcCVm79xBkcbaKNxuXfT4c6740LYu6qVkWWdPpl5NFDl9X0DDYj48abRDHu1yXI0CjNUce0Yz3/lUwTxwsQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yy84oAycYqF72b8r/BEWZOQCMgDktNytfPvjIlhGthUkKJ6t3lB AzG4GJ0m+UA0JX/W0o/47bBIySFF5fjxoar/P1FS1q9LqbuW6PMVWwMlgWWJzA== X-Google-Smtp-Source: AGHT+IE9kdu3Gzes05PmnEG4b059qYyNhUbylI8yfpfxqRx4sEa+C7N2A17wBYMcr/rW478BGstZHA== X-Received: by 2002:a05:620a:31a2:b0:7a9:b456:c5e6 with SMTP id af79cd13be357-7b331e48153mr2345718685a.42.1731432662381; Tue, 12 Nov 2024 09:31:02 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac2dcebsm608292285a.7.2024.11.12.09.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:31:01 -0800 (PST) From: Ricardo Ribalda Date: Tue, 12 Nov 2024 17:30:45 +0000 Subject: [PATCH v3 2/8] media: uvcvideo: Factor out gpio functions to its own file Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241112-uvc-subdev-v3-2-0ea573d41a18@chromium.org> References: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> In-Reply-To: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 This is just a refactor patch, no new functionality is added. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/Makefile | 3 +- drivers/media/usb/uvc/uvc_driver.c | 119 +------------------------------------ drivers/media/usb/uvc/uvc_gpio.c | 118 ++++++++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 8 +++ 4 files changed, 131 insertions(+), 117 deletions(-) diff --git a/drivers/media/usb/uvc/Makefile b/drivers/media/usb/uvc/Makefile index 4f9eee4f81ab..85514b6e538f 100644 --- a/drivers/media/usb/uvc/Makefile +++ b/drivers/media/usb/uvc/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 uvcvideo-objs := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \ - uvc_status.o uvc_isight.o uvc_debugfs.o uvc_metadata.o + uvc_status.o uvc_isight.o uvc_debugfs.o uvc_metadata.o \ + uvc_gpio.o ifeq ($(CONFIG_MEDIA_CONTROLLER),y) uvcvideo-objs += uvc_entity.o endif diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index cd13bf01265d..5b48768a4f7f 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -775,9 +774,9 @@ static const u8 uvc_media_transport_input_guid[16] = UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; -static struct uvc_entity *uvc_alloc_new_entity(struct uvc_device *dev, u16 type, - u16 id, unsigned int num_pads, - unsigned int extra_size) +struct uvc_entity *uvc_alloc_new_entity(struct uvc_device *dev, u16 type, + u16 id, unsigned int num_pads, + unsigned int extra_size) { struct uvc_entity *entity; unsigned int num_inputs; @@ -1240,118 +1239,6 @@ static int uvc_parse_control(struct uvc_device *dev) return 0; } -/* ----------------------------------------------------------------------------- - * Privacy GPIO - */ - -static void uvc_gpio_event(struct uvc_device *dev) -{ - struct uvc_entity *unit = dev->gpio_unit; - struct uvc_video_chain *chain; - u8 new_val; - - if (!unit) - return; - - new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); - - /* 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); -} - -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) - return -EINVAL; - - *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy); - - return 0; -} - -static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity, - u8 cs, u8 *caps) -{ - if (cs != UVC_CT_PRIVACY_CONTROL) - return -EINVAL; - - *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; - return 0; -} - -static irqreturn_t uvc_gpio_irq(int irq, void *data) -{ - struct uvc_device *dev = data; - - uvc_gpio_event(dev); - return IRQ_HANDLED; -} - -static int uvc_gpio_parse(struct uvc_device *dev) -{ - struct uvc_entity *unit; - struct gpio_desc *gpio_privacy; - int irq; - - gpio_privacy = devm_gpiod_get_optional(&dev->intf->dev, "privacy", - GPIOD_IN); - if (IS_ERR_OR_NULL(gpio_privacy)) - return PTR_ERR_OR_ZERO(gpio_privacy); - - irq = gpiod_to_irq(gpio_privacy); - if (irq < 0) - return dev_err_probe(&dev->intf->dev, irq, - "No IRQ for privacy GPIO\n"); - - unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT, - UVC_EXT_GPIO_UNIT_ID, 0, 1); - if (IS_ERR(unit)) - return PTR_ERR(unit); - - unit->gpio.gpio_privacy = gpio_privacy; - unit->gpio.irq = irq; - unit->gpio.bControlSize = 1; - unit->gpio.bmControls = (u8 *)unit + sizeof(*unit); - unit->gpio.bmControls[0] = 1; - unit->get_cur = uvc_gpio_get_cur; - unit->get_info = uvc_gpio_get_info; - strscpy(unit->name, "GPIO", sizeof(unit->name)); - - list_add_tail(&unit->list, &dev->entities); - - dev->gpio_unit = unit; - - return 0; -} - -static int uvc_gpio_init_irq(struct uvc_device *dev) -{ - struct uvc_entity *unit = dev->gpio_unit; - int ret; - - if (!unit || unit->gpio.irq < 0) - return 0; - - ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, - IRQF_ONESHOT | IRQF_TRIGGER_FALLING | - IRQF_TRIGGER_RISING, - "uvc_privacy_gpio", dev); - - unit->gpio.initialized = !ret; - - return ret; -} - -static void uvc_gpio_deinit(struct uvc_device *dev) -{ - if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) - return; - - free_irq(dev->gpio_unit->gpio.irq, dev); -} - /* ------------------------------------------------------------------------ * UVC device scan */ diff --git a/drivers/media/usb/uvc/uvc_gpio.c b/drivers/media/usb/uvc/uvc_gpio.c new file mode 100644 index 000000000000..453739acbe8f --- /dev/null +++ b/drivers/media/usb/uvc/uvc_gpio.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * uvc_gpio.c -- USB Video Class driver + * + * Copyright 2024 Google LLC + */ + +#include +#include +#include "uvcvideo.h" + +static void uvc_gpio_event(struct uvc_device *dev) +{ + struct uvc_entity *unit = dev->gpio_unit; + struct uvc_video_chain *chain; + u8 new_val; + + if (!unit) + return; + + new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + + /* 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); +} + +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) + return -EINVAL; + + *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy); + + return 0; +} + +static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity, + u8 cs, u8 *caps) +{ + if (cs != UVC_CT_PRIVACY_CONTROL) + return -EINVAL; + + *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; + return 0; +} + +static irqreturn_t uvc_gpio_irq(int irq, void *data) +{ + struct uvc_device *dev = data; + + uvc_gpio_event(dev); + return IRQ_HANDLED; +} + +int uvc_gpio_parse(struct uvc_device *dev) +{ + struct uvc_entity *unit; + struct gpio_desc *gpio_privacy; + int irq; + + gpio_privacy = devm_gpiod_get_optional(&dev->intf->dev, "privacy", + GPIOD_IN); + if (IS_ERR_OR_NULL(gpio_privacy)) + return PTR_ERR_OR_ZERO(gpio_privacy); + + irq = gpiod_to_irq(gpio_privacy); + if (irq < 0) + return dev_err_probe(&dev->udev->dev, irq, + "No IRQ for privacy GPIO\n"); + + unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT, + UVC_EXT_GPIO_UNIT_ID, 0, 1); + if (IS_ERR(unit)) + return PTR_ERR(unit); + + unit->gpio.gpio_privacy = gpio_privacy; + unit->gpio.irq = irq; + unit->gpio.bControlSize = 1; + unit->gpio.bmControls = (u8 *)unit + sizeof(*unit); + unit->gpio.bmControls[0] = 1; + unit->get_cur = uvc_gpio_get_cur; + unit->get_info = uvc_gpio_get_info; + strscpy(unit->name, "GPIO", sizeof(unit->name)); + + list_add_tail(&unit->list, &dev->entities); + + dev->gpio_unit = unit; + + return 0; +} + +int uvc_gpio_init_irq(struct uvc_device *dev) +{ + struct uvc_entity *unit = dev->gpio_unit; + int ret; + + if (!unit || unit->gpio.irq < 0) + return 0; + + ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, + IRQF_ONESHOT | IRQF_TRIGGER_FALLING | + IRQF_TRIGGER_RISING, + "uvc_privacy_gpio", dev); + + unit->gpio.initialized = !ret; + + return ret; +} + +void uvc_gpio_deinit(struct uvc_device *dev) +{ + if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) + return; + + free_irq(dev->gpio_unit->gpio.irq, dev); +} diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 965a789ed03e..91ed59b54d9a 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -673,6 +673,9 @@ do { \ extern struct uvc_driver uvc_driver; struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id); +struct uvc_entity *uvc_alloc_new_entity(struct uvc_device *dev, u16 type, + u16 id, unsigned int num_pads, + unsigned int extra_size); /* Video buffers queue management. */ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, @@ -817,4 +820,9 @@ void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream); size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, size_t size); +/* gpio */ +int uvc_gpio_parse(struct uvc_device *dev); +int uvc_gpio_init_irq(struct uvc_device *dev); +void uvc_gpio_deinit(struct uvc_device *dev); + #endif From patchwork Tue Nov 12 17:30:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 844038 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B692E2144CE for ; Tue, 12 Nov 2024 17:31:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432666; cv=none; b=XgMV/d06nvVxgwcba5+QvaenBeeB7j9qXuqSHOS9AnHiPvqClqGDuJB/3VJgZ87ceThZProIEell0iJirSk5+JkLwp+KYzIGoMIndCbF0XEoPwr9nXNK/6NzsU3NOLSq3DUxMCMZ7rGXxeSbWVRbPc8B/iQteCw5JhgjtNi8bWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432666; c=relaxed/simple; bh=ARE05qnYrbG1PaurfMt4sWTURGohFvkDjj+xaPdokqc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tlBTJasY/sGQQi4cJ1a8SxYmXq2Q+aHSoVdxJj5TwXKu4LtubVCRtBQUJZ8eRDcfUz85x/5Jd/O1xLJXe18MhWPPW08eRaV3GOUgPuxM1yGZj+8wEXsT+GB7iZkZcKhCbswaqAugVdo/WpWoLbPxIgUlWgGB1NkKP1l8yh84RtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=hDcS1nLj; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hDcS1nLj" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7b15416303aso425399485a.1 for ; Tue, 12 Nov 2024 09:31:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731432664; x=1732037464; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2vaVDRM1V2OFL5Lfp0Tp3fV8e2l0lPm3Um6LzAvGga4=; b=hDcS1nLjvJL051sV9jI6NIwcChetZa+6iPVRhLK3y9FWSZBAoFk3CcjfwMiVIFmADL N6rGVuX3/1GH+GMuLsjWnZ1Iax+LgdM+Kb/m/rxTLUI/PxdEhaac9tnI0pTy5474H7J7 8BOjCodnjkPWU+GWrvPjKUHiArbVlF2tVSeno= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731432664; x=1732037464; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2vaVDRM1V2OFL5Lfp0Tp3fV8e2l0lPm3Um6LzAvGga4=; b=PwsJSX48cpsGrfaKc0jWoLwaSQA2Bo3s88iRyIZ1Z0xq6+0vkHEOaoKkbmGZT5yFFa BnHtRgpQYFoJ8KzP2gAupFl6Iu0f/3VkE5v/1DTQ8dA6cuRCxjgtfe8i1XWByRZPU6Sa NlG46HLS7dg/pXB2AMbFh2okuJK72cU+uXymMqtI4mm5/P5kopfKo5OPV/c+Wyn4whz9 3dh6wkUT06XegptKdkNAYPZwxXbzF3+Ks5qtkNIoTWXbljBMhqWlISDylcHsCaViV9Ik pdXAyJMcw0Zcx2gxLZhkZyi76GxNiAA9F3HKuypAsXQSKSYLeyY2/fCr7LVIe41MK/cw FoOA== X-Forwarded-Encrypted: i=1; AJvYcCUiC7r+XSlyx4fPHR91kFA4Ca20xlTEHwx1UcLZTwDeZXiPXfIvewWycYvD/NStIXibqsH/MF0yZnqBmg==@vger.kernel.org X-Gm-Message-State: AOJu0YyYkidK7NGIv9r0XlCnafWC7+HySPukOmr5NiQkLDVk6HBPZxqh JBcQW4DCJGfH4J9fvhrPF9jgRWMnukACg5oKeL4s740HZdLmD6zBxrZ+xUUh1A== X-Google-Smtp-Source: AGHT+IGUTjDChRDa1wzOvaVmFTddH5hipHL9tXZqCooGO5Ga3pReVfa85TjuhqS2jvbpEsS9IJI3eg== X-Received: by 2002:a05:620a:1a25:b0:7ab:3ec9:f4c7 with SMTP id af79cd13be357-7b331eafd8fmr2426728285a.35.1731432663499; Tue, 12 Nov 2024 09:31:03 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac2dcebsm608292285a.7.2024.11.12.09.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:31:02 -0800 (PST) From: Ricardo Ribalda Date: Tue, 12 Nov 2024 17:30:46 +0000 Subject: [PATCH v3 3/8] media: uvcvideo: Re-implement privacy GPIO as an input device Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241112-uvc-subdev-v3-3-0ea573d41a18@chromium.org> References: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> In-Reply-To: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 Reimplement privacy GPIO as an input device. This is an attempt to unify how we notify userspace about a camera that is covered. Replace the previous V4L2_CID_PRIVACY control with evdev SW_CAMERA_LENS_COVER. This has some main benefits: - It unifies behaviour with other drivers. - It allows reading the privacy events without powering up the camera. - It allows reading the privacy gpio and the internal gpio control (if present). Although this introduces an ABI change, we have only seen ChromeOS using this feature. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/Kconfig | 2 +- drivers/media/usb/uvc/Makefile | 6 ++- drivers/media/usb/uvc/uvc_ctrl.c | 20 ---------- drivers/media/usb/uvc/uvc_driver.c | 3 +- drivers/media/usb/uvc/uvc_entity.c | 6 +++ drivers/media/usb/uvc/uvc_gpio.c | 76 +++++++++++++------------------------- drivers/media/usb/uvc/uvc_status.c | 13 +++++-- drivers/media/usb/uvc/uvcvideo.h | 15 +++++--- 8 files changed, 59 insertions(+), 82 deletions(-) diff --git a/drivers/media/usb/uvc/Kconfig b/drivers/media/usb/uvc/Kconfig index 579532272fd6..cdbba7fd5bee 100644 --- a/drivers/media/usb/uvc/Kconfig +++ b/drivers/media/usb/uvc/Kconfig @@ -17,6 +17,6 @@ config USB_VIDEO_CLASS_INPUT_EVDEV depends on USB_VIDEO_CLASS=INPUT || INPUT=y help This option makes USB Video Class devices register an input device - to report button events. + to report button events and privacy GPIO. If you are in doubt, say Y. diff --git a/drivers/media/usb/uvc/Makefile b/drivers/media/usb/uvc/Makefile index 85514b6e538f..b36b124da7a8 100644 --- a/drivers/media/usb/uvc/Makefile +++ b/drivers/media/usb/uvc/Makefile @@ -1,8 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 uvcvideo-objs := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \ - uvc_status.o uvc_isight.o uvc_debugfs.o uvc_metadata.o \ - uvc_gpio.o + uvc_status.o uvc_isight.o uvc_debugfs.o uvc_metadata.o ifeq ($(CONFIG_MEDIA_CONTROLLER),y) uvcvideo-objs += uvc_entity.o endif +ifeq ($(CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV),y) +uvcvideo-objs += uvc_gpio.o +endif obj-$(CONFIG_USB_VIDEO_CLASS) += uvcvideo.o diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 4fe26e82e3d1..b98f4778d8aa 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -350,14 +350,6 @@ 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, - }, }; static const u32 uvc_control_classes[] = { @@ -827,15 +819,6 @@ 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, - .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, - }, { .entity = UVC_GUID_UVC_PROCESSING, .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, @@ -2718,9 +2701,6 @@ static int uvc_ctrl_init_chain(struct uvc_video_chain *chain) } else if (UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) { bmControls = entity->camera.bmControls; bControlSize = entity->camera.bControlSize; - } else if (UVC_ENTITY_TYPE(entity) == UVC_EXT_GPIO_UNIT) { - bmControls = entity->gpio.bmControls; - bControlSize = entity->gpio.bControlSize; } /* Remove bogus/blacklisted controls */ diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 5b48768a4f7f..d6c12be49b5c 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2171,6 +2171,7 @@ static int uvc_probe(struct usb_interface *intf, if (media_device_register(&dev->mdev) < 0) goto error; #endif + /* Save our data pointer in the interface data. */ usb_set_intfdata(intf, dev); @@ -2182,7 +2183,7 @@ static int uvc_probe(struct usb_interface *intf, ret); } - ret = uvc_gpio_init_irq(dev); + ret = uvc_gpio_init(dev); if (ret < 0) { dev_err(&dev->udev->dev, "Unable to request privacy GPIO IRQ (%d)\n", ret); diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c index cc68dd24eb42..c1b69f9eaa56 100644 --- a/drivers/media/usb/uvc/uvc_entity.c +++ b/drivers/media/usb/uvc/uvc_entity.c @@ -56,7 +56,13 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain, return 0; } +static const struct v4l2_subdev_core_ops uvc_subdev_core_ops = { + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event = v4l2_event_subdev_unsubscribe, +}; + static const struct v4l2_subdev_ops uvc_subdev_ops = { + .core = &uvc_subdev_core_ops, }; void uvc_mc_cleanup_entity(struct uvc_entity *entity) diff --git a/drivers/media/usb/uvc/uvc_gpio.c b/drivers/media/usb/uvc/uvc_gpio.c index 453739acbe8f..80096022ad08 100644 --- a/drivers/media/usb/uvc/uvc_gpio.c +++ b/drivers/media/usb/uvc/uvc_gpio.c @@ -7,57 +7,29 @@ #include #include +#include #include "uvcvideo.h" -static void uvc_gpio_event(struct uvc_device *dev) -{ - struct uvc_entity *unit = dev->gpio_unit; - struct uvc_video_chain *chain; - u8 new_val; - - if (!unit) - return; - - new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); - - /* 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); -} - -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) - return -EINVAL; - - *(u8 *)data = gpiod_get_value_cansleep(entity->gpio.gpio_privacy); - - return 0; -} - -static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *entity, - u8 cs, u8 *caps) -{ - if (cs != UVC_CT_PRIVACY_CONTROL) - return -EINVAL; - - *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; - return 0; -} - static irqreturn_t uvc_gpio_irq(int irq, void *data) { struct uvc_device *dev = data; + struct uvc_gpio *uvc_gpio = &dev->gpio_unit->gpio; + int new_val; + + new_val = gpiod_get_value_cansleep(uvc_gpio->gpio_privacy); + if (new_val < 0) + return IRQ_HANDLED; + + input_report_switch(dev->input, SW_CAMERA_LENS_COVER, new_val); + input_sync(dev->input); - uvc_gpio_event(dev); return IRQ_HANDLED; } int uvc_gpio_parse(struct uvc_device *dev) { - struct uvc_entity *unit; struct gpio_desc *gpio_privacy; + struct uvc_entity *unit; int irq; gpio_privacy = devm_gpiod_get_optional(&dev->intf->dev, "privacy", @@ -67,23 +39,17 @@ int uvc_gpio_parse(struct uvc_device *dev) irq = gpiod_to_irq(gpio_privacy); if (irq < 0) - return dev_err_probe(&dev->udev->dev, irq, + return dev_err_probe(&dev->intf->dev, irq, "No IRQ for privacy GPIO\n"); unit = uvc_alloc_new_entity(dev, UVC_EXT_GPIO_UNIT, - UVC_EXT_GPIO_UNIT_ID, 0, 1); + UVC_EXT_GPIO_UNIT_ID, 0, 0); if (IS_ERR(unit)) return PTR_ERR(unit); unit->gpio.gpio_privacy = gpio_privacy; unit->gpio.irq = irq; - unit->gpio.bControlSize = 1; - unit->gpio.bmControls = (u8 *)unit + sizeof(*unit); - unit->gpio.bmControls[0] = 1; - unit->get_cur = uvc_gpio_get_cur; - unit->get_info = uvc_gpio_get_info; strscpy(unit->name, "GPIO", sizeof(unit->name)); - list_add_tail(&unit->list, &dev->entities); dev->gpio_unit = unit; @@ -91,22 +57,32 @@ int uvc_gpio_parse(struct uvc_device *dev) return 0; } -int uvc_gpio_init_irq(struct uvc_device *dev) +int uvc_gpio_init(struct uvc_device *dev) { struct uvc_entity *unit = dev->gpio_unit; + int init_val; int ret; if (!unit || unit->gpio.irq < 0) return 0; + init_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + if (init_val < 0) + return init_val; + ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, IRQF_ONESHOT | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, "uvc_privacy_gpio", dev); + if (ret) + return ret; + + input_report_switch(dev->input, SW_CAMERA_LENS_COVER, init_val); + input_sync(dev->input); - unit->gpio.initialized = !ret; + unit->gpio.initialized = true; - return ret; + return 0; } void uvc_gpio_deinit(struct uvc_device *dev) diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c index 06c867510c8f..319f472213f6 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -44,7 +44,7 @@ static int uvc_input_init(struct uvc_device *dev) struct input_dev *input; int ret; - if (!uvc_input_has_button(dev)) + if (!uvc_input_has_button(dev) && !dev->gpio_unit) return 0; input = input_allocate_device(); @@ -59,8 +59,15 @@ static int uvc_input_init(struct uvc_device *dev) usb_to_input_id(dev->udev, &input->id); input->dev.parent = &dev->intf->dev; - __set_bit(EV_KEY, input->evbit); - __set_bit(KEY_CAMERA, input->keybit); + if (uvc_input_has_button(dev)) { + __set_bit(EV_KEY, input->evbit); + __set_bit(KEY_CAMERA, input->keybit); + } + + if (dev->gpio_unit) { + __set_bit(EV_SW, input->evbit); + __set_bit(SW_CAMERA_LENS_COVER, input->swbit); + } if ((ret = input_register_device(input)) < 0) goto error; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 91ed59b54d9a..06c4d514d02c 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -229,12 +230,10 @@ struct uvc_entity { u8 *bmControlsType; } extension; - struct { - u8 bControlSize; - u8 *bmControls; - struct gpio_desc *gpio_privacy; + struct uvc_gpio { int irq; bool initialized; + struct gpio_desc *gpio_privacy; } gpio; }; @@ -821,8 +820,14 @@ size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, size_t size); /* gpio */ +#ifdef CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV int uvc_gpio_parse(struct uvc_device *dev); -int uvc_gpio_init_irq(struct uvc_device *dev); +int uvc_gpio_init(struct uvc_device *dev); void uvc_gpio_deinit(struct uvc_device *dev); +#else +static inline int uvc_gpio_parse(struct uvc_device *dev) {return 0; } +static inline int uvc_gpio_init(struct uvc_device *dev) {return 0; } +static inline void uvc_gpio_deinit(struct uvc_device *dev) {}; +#endif #endif From patchwork Tue Nov 12 17:30:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 842795 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16A0121502E for ; Tue, 12 Nov 2024 17:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432667; cv=none; b=SHqq0Gx40q1WYsY9/dvMicEv5fuPNgJO9ZGre8pBUvVWByeFTDQRMD+CdfJ5bm2/B6aQYQnN5+nGYMdUDgVkK+U1CGC+wgLNPcRCPlrjeOhi4k04ZOSzGzNKn3JwEtoB/gUQTLCbOzMCpRNIcFKbrmLylP0o7JL5u4smCOgfHyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432667; c=relaxed/simple; bh=E17kbtXRsRfcdSPkrY+rNCC2i3rDAnsvyr4zp1CZtMU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RS2izVf495/Q84b6tocxqo5++f7DvpynCq1nREEiWW1Z64dz5dvk9lj/X93NayLhsDxOjouzTAzI7sr7g0hqcWNLnHq8fHyIOd1CkV0Z7OQExBRAq4l4o+AMxckMY0F2M9CBFw2MkBhkUfq5ONKvl9qGMV8OZIMY/5mdlmeXDLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=jfa9G3P1; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jfa9G3P1" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7b15416303aso425401585a.1 for ; Tue, 12 Nov 2024 09:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731432665; x=1732037465; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RqZQPsCIYOn8pJkWFSJPCD0PspSusOPrE3O05rrigFM=; b=jfa9G3P1pvyRg0jMeD47qazXZkBS1UDmLgIwRI+joHWmZHXprsqygNAvU2WD8Na5Ya ywG8Ir2Yp5qg8zsV1IRoPRzOT+yLFddG9vIcqcV/1LBG95QrmKOSmAW1Um+xUD7gaqSc qQJZZKmaXPzfaqxOFG4q+xsvfAgX/kSndxT8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731432665; x=1732037465; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RqZQPsCIYOn8pJkWFSJPCD0PspSusOPrE3O05rrigFM=; b=SUs5rCQ+YLsksrH20+SCgrm/HeEyoiV+zNmVgrZADmAlU9Z+AxEu8VCvOP/8d0u+MA 9xNdeZ6gueJnfLG6DJRtWPCaBOSNYkx5MmIs8QcPvaVfJO8z9WZVL7O7Z2QtgiMYtwR3 NGw2QduXX1HagnyMh/ds1GGndbdPGV6B0UQOfw3YomgwcEcoJF1i7Mc3ZFA0j3ONN6Bg enDK/e5J81EDGeZucuvHhNp5EP7pcMbC/s7UMh+YCvtpfSsbahC9vq91oeedF9DqjuIt vlT1YPNTnZgWGuGE7Xf/192o/rD9eYoGptWz6vbWjX+t20mYNkSC8yCHbdPSFL/SNU9+ F4pw== X-Forwarded-Encrypted: i=1; AJvYcCVMtRDOd+xgI52RktWZxdNWkx+XR+VJC2g4vludZ2RVCMV5zYfPSC5Bn/pRoyiF2EWty+JxzTQghoHabQ==@vger.kernel.org X-Gm-Message-State: AOJu0YyGGAqP7vEJ+BuoVdUkI4ZvHfym7FWpuQhQ0CvNJ1gQiwPSCVs7 Mc+ulB2QtgYRLLp+ZKcRNfJb89Q3RhoQzJT/vkM5Efq15yYXkE0yJ3V5s9/QgQ== X-Google-Smtp-Source: AGHT+IGf8yPShJH+1DZ5FLZFiWVPiFYITT8lUprWPFqP6pNzp5dpZgWT6O1GD6oa8mKqfg1kEHyLBg== X-Received: by 2002:a05:620a:191e:b0:7a9:acd5:1b21 with SMTP id af79cd13be357-7b331ef8588mr2517962885a.50.1731432664935; Tue, 12 Nov 2024 09:31:04 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac2dcebsm608292285a.7.2024.11.12.09.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:31:03 -0800 (PST) From: Ricardo Ribalda Date: Tue, 12 Nov 2024 17:30:47 +0000 Subject: [PATCH v3 4/8] Revert "media: uvcvideo: Allow entity-defined get_info and get_cur" Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241112-uvc-subdev-v3-4-0ea573d41a18@chromium.org> References: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> In-Reply-To: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 With the privacy gpio now handled as a evdev, there is no more need for this. This reverts commit 65900c581d014499f0f8ceabfc02c652e9a88771. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 20 +++++--------------- drivers/media/usb/uvc/uvcvideo.h | 5 ----- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index b98f4778d8aa..90bc2132d8d5 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1087,15 +1087,9 @@ static int __uvc_ctrl_load_cur(struct uvc_video_chain *chain, return 0; } - if (ctrl->entity->get_cur) - ret = ctrl->entity->get_cur(chain->dev, ctrl->entity, - ctrl->info.selector, data, - ctrl->info.size); - else - ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, - ctrl->entity->id, chain->dev->intfnum, - ctrl->info.selector, data, - ctrl->info.size); + ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, data, + ctrl->info.size); if (ret < 0) return ret; @@ -2055,12 +2049,8 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev, if (data == NULL) return -ENOMEM; - if (ctrl->entity->get_info) - ret = ctrl->entity->get_info(dev, ctrl->entity, - ctrl->info.selector, data); - else - ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, - dev->intfnum, info->selector, data, 1); + ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, + info->selector, data, 1); if (!ret) { info->flags &= ~(UVC_CTRL_FLAG_GET_CUR | diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 06c4d514d02c..6002f1c43b69 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -240,11 +240,6 @@ struct uvc_entity { u8 bNrInPins; u8 *baSourceID; - int (*get_info)(struct uvc_device *dev, struct uvc_entity *entity, - u8 cs, u8 *caps); - int (*get_cur)(struct uvc_device *dev, struct uvc_entity *entity, - u8 cs, void *data, u16 size); - unsigned int ncontrols; struct uvc_control *controls; }; From patchwork Tue Nov 12 17:30:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 844037 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F27E9215C73 for ; Tue, 12 Nov 2024 17:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432668; cv=none; b=V42I2/2cqbhHKHcdRExBKPVWuOelbOvWIHeHvGY+8hiJ/5pqJlu8ZBHSsiWj7eQ18SsrOdv/xKPNy2lOiDSIHvFwsxptERyPcbcWTX+8B8oI/2smaPFwF2buuZscJDkFBtFKEUy4XJ3wNNlV1MugcXG+MXIwockweEVpkm0soTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432668; c=relaxed/simple; bh=aNTUZZhZyqVU9gy8l8yK7jgccZ+2XSUjodsCiy8OgCY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CeV0ia6XfJCV6//g0smqpktydgr4CP7Fy8xbvE6oieQy/eqDY/l4GyOxGh1mUcBfDuryEomc+DwTH+ZSKnoivGGdFnBkDdrfUTmWCXMb1xdOydTiTFrLguACTn0KsnZN47iQI5CXstfBtneg2Z/+31uTprCHWU48o1/DOutaf50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=EYkR0ynE; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="EYkR0ynE" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b154f71885so471959485a.0 for ; Tue, 12 Nov 2024 09:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731432666; x=1732037466; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=/mtTXn3udpu62k3Atn4vt+FxsonuY7lt9lS81AKORGg=; b=EYkR0ynEli2+3e3OFpywcuIUZJ1YAnWx+QLl0GZI4lsqRKajq0YgXe+vP3VwX5qBzo fvAG/jxAwRuGzcscyuqZY5o0i6B0kPpsQRBKm7Yb79zkEpglOm91sm8rW7NCVxyxHyGp mNRRyOVpBBkvbB508eQw46kYcGoMPThGMqqr4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731432666; x=1732037466; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/mtTXn3udpu62k3Atn4vt+FxsonuY7lt9lS81AKORGg=; b=VkYPitUXlJ9nRIDoV/WBFwOHhL2gs3YW7kJnC7dzCbXh+XpEFcP3v+W41eTYaOLNJd zpqBDobBtCAQYd43pdt0hI65uyx5AH7XuNcCIgqrRu4eXRxuJmdFB7/OdNtK75SftcBr ohWCeX/kCEgIFr+t5MP0WcTnzBhR8eQRfxSzE+EU5bjU0q/nxp2NhPTsGblBGTsVJ4iH SLvy9qlK17PgLZvfDgVf44uZPhofgqR0DUXhOcKPbWrfqAUxS1qcAAU5ocpvqii3Asoj xDhQLpESncU929eHveFSqPnCSwRvz4ZkrvSMylbabY4HpzMfKB+3BvhGI/wBwGNKSXi7 ysRA== X-Forwarded-Encrypted: i=1; AJvYcCUvE/L+/EyjX/LbGC7Fv0b3vjWeaOL2qFuKlbGor1uue4urfDVDRu8RgZ0BvQKuNRkEsvpJWIBnYDT/Dw==@vger.kernel.org X-Gm-Message-State: AOJu0YzuMOtCOGBEfJIb3QYzT6dQiOtARosKbBYEZ8il0d6OzLBywTQb sVzzcCQd08QPy0tpqk0MSZ8Z04y5xATnUjUsiyJH1NEzks6KxAde2KfBThJMnw== X-Google-Smtp-Source: AGHT+IE6DeF9yyQEoLuMSjlzOxCp8Mz1HxU1DGwfXvz8Qk3lJu0bxx+avH9OkExkGfDmegsKe4Wd4Q== X-Received: by 2002:a05:620a:290f:b0:7a9:b2dc:99a6 with SMTP id af79cd13be357-7b331eb6d20mr2147972285a.24.1731432665768; Tue, 12 Nov 2024 09:31:05 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac2dcebsm608292285a.7.2024.11.12.09.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:31:05 -0800 (PST) From: Ricardo Ribalda Date: Tue, 12 Nov 2024 17:30:48 +0000 Subject: [PATCH v3 5/8] media: uvcvideo: Create ancillary link for GPIO subdevice Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241112-uvc-subdev-v3-5-0ea573d41a18@chromium.org> References: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> In-Reply-To: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 Make an ancillary lik between the streaming subdev and the GPIO subdev. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_entity.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c index c1b69f9eaa56..7b8fb85d8c03 100644 --- a/drivers/media/usb/uvc/uvc_entity.c +++ b/drivers/media/usb/uvc/uvc_entity.c @@ -53,6 +53,17 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain, return ret; } + /* Create ancillary link for the GPIO. */ + if (chain->dev->gpio_unit && + UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) { + struct media_link *link; + + link = media_create_ancillary_link(sink, + &chain->dev->gpio_unit->subdev.entity); + if (IS_ERR(link)) + return PTR_ERR(link); + } + return 0; } From patchwork Tue Nov 12 17:30:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 842794 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC324216459 for ; Tue, 12 Nov 2024 17:31:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432669; cv=none; b=urI4iXAjexE2MOccASV/6roYN/u8H0OxihgF4lC/cBpq+bsKfj5hbC/G+lvw5O1U4CN4bcDisK7+4EnMr5I9nkA24gs1ZYKQEaYLy45k+nxD/JotEwOFPfh5r4RUbRtHbQYlHa9PhoceO9LJZFC5I03l2z6XtxMWap68x5flmPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432669; c=relaxed/simple; bh=PElbl8uW8Fa0oaZt4+kEmvtPpbNU7LixpWE5F/F/xAU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rJw1uW2q95XAE3CPr09Fh1ghUqVc1Y8a3dwF8/8+9jJXiDDHaH1Vv9jeF7oEteMo+rpEfWXy295lOoxEoqyRzWYAi5JbBJWpjiNgnaZ68QpV+x+9j38DNqRenNtPmW9PgfGBw/7cFkwMDTq29c2PMhMW1zthiNyz6twLqQVknco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=GMMPzQtx; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="GMMPzQtx" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b1467af9dbso405187985a.0 for ; Tue, 12 Nov 2024 09:31:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731432666; x=1732037466; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1P5DVRMjbEuaaQXC+PIiJu+9ELqOWJV7Errw4E0pPWQ=; b=GMMPzQtx5jeo66Sffyt8xdT3OfgAfVyUhH0oS1fb84n6oy8N5/PUkSOKcKNZRItFrI NsS30kudoPtF8SQdP6aQaZR0dhzAu43fmecp32HS09NWqKgcT+Hugxw0e+flndcd2SY4 I1MpZRkQwTM03Ca4+mKuzpx08K5vRH1eaCqME= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731432666; x=1732037466; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1P5DVRMjbEuaaQXC+PIiJu+9ELqOWJV7Errw4E0pPWQ=; b=dX3FpJG2Fi+SIJtCxfKNEiPRGtHAjspHe2KJ04PqLZ/rQeL0PUMaSyWklrXaav0sy/ g+UuxmQx3AHKdvcHnkMaoiQ3+LtTDzT9gR0kg4CHJWS1onZqhPsHSx5a4PR47SJ5Dnkt TCC6G2VON5fyyxPcmI4H2Z8wtlUJaibNFSg+MTIdn4PJrD4kdPKztVjXOAFx7iHoa+R5 b7urY6v3tySnfTfcJSMbBO2IivWkSSK+WxZZt2tnnCTGJ6ciKK2LOx9l8twcmgtsjH5h /Rb+39eYFOy5S+6loSM1+u64eX+nsxsBWL7/Y5KmjiGbjNKD5a+HvOkR8istomS2JPvM SOlA== X-Forwarded-Encrypted: i=1; AJvYcCUGDs08uTAjjO5OQv9kkupBxBqTguSGpiQEsz4nyI32UYRHBscogHeNSdpBHX+nCCllLwJr878/7c36HA==@vger.kernel.org X-Gm-Message-State: AOJu0YzrylrPWt9lP7SxnFQs//TN4G1dC3JdAe+sn5SjbV5d0OiZgQk/ nNlmRLrQGVkRmndSA3F4Fm5Y4Qm9J24TbPi6GHS94o0M6e3dvrwL+wLSUndKzA== X-Google-Smtp-Source: AGHT+IEcAtMGtdgkDsLT0VyNL58SyBI46+EinyYYZVvqJr9WyHwssspAfr3QBpctZQDfTxZjHPLGXQ== X-Received: by 2002:a05:620a:2a06:b0:7b1:51e9:ed77 with SMTP id af79cd13be357-7b34baf0ef3mr325476585a.10.1731432666627; Tue, 12 Nov 2024 09:31:06 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac2dcebsm608292285a.7.2024.11.12.09.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:31:06 -0800 (PST) From: Ricardo Ribalda Date: Tue, 12 Nov 2024 17:30:49 +0000 Subject: [PATCH v3 6/8] media: v4l2-core: Add new MEDIA_ENT_F_GPIO Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241112-uvc-subdev-v3-6-0ea573d41a18@chromium.org> References: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> In-Reply-To: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 Add a new media entity type to define a GPIO entity. This can be used to represent the privacy switch GPIO associated to a sensor. Signed-off-by: Ricardo Ribalda --- Documentation/userspace-api/media/mediactl/media-types.rst | 4 ++++ drivers/media/v4l2-core/v4l2-async.c | 3 ++- include/uapi/linux/media.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/mediactl/media-types.rst b/Documentation/userspace-api/media/mediactl/media-types.rst index 6332e8395263..7ede3954a96a 100644 --- a/Documentation/userspace-api/media/mediactl/media-types.rst +++ b/Documentation/userspace-api/media/mediactl/media-types.rst @@ -24,6 +24,7 @@ Types and flags used to represent the media graph elements .. _MEDIA-ENT-F-CAM-SENSOR: .. _MEDIA-ENT-F-FLASH: .. _MEDIA-ENT-F-LENS: +.. _MEDIA-ENT-F-GPIO: .. _MEDIA-ENT-F-ATV-DECODER: .. _MEDIA-ENT-F-TUNER: .. _MEDIA-ENT-F-IF-VID-DECODER: @@ -100,6 +101,9 @@ Types and flags used to represent the media graph elements * - ``MEDIA_ENT_F_LENS`` - Lens controller entity. + * - ``MEDIA_ENT_F_GPIO`` + - GPIO controller entity. + * - ``MEDIA_ENT_F_ATV_DECODER`` - Analog video decoder, the basic function of the video decoder is to accept analogue video from a wide variety of sources such as diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index ee884a8221fb..8a902fc897d1 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -320,7 +320,8 @@ static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n, struct media_link *link; if (sd->entity.function != MEDIA_ENT_F_LENS && - sd->entity.function != MEDIA_ENT_F_FLASH) + sd->entity.function != MEDIA_ENT_F_FLASH && + sd->entity.function != MEDIA_ENT_F_GPIO) return 0; if (!n->sd) { diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h index 1c80b1d6bbaf..d3d045e52d78 100644 --- a/include/uapi/linux/media.h +++ b/include/uapi/linux/media.h @@ -84,6 +84,7 @@ struct media_device_info { #define MEDIA_ENT_F_CAM_SENSOR (MEDIA_ENT_F_OLD_SUBDEV_BASE + 1) #define MEDIA_ENT_F_FLASH (MEDIA_ENT_F_OLD_SUBDEV_BASE + 2) #define MEDIA_ENT_F_LENS (MEDIA_ENT_F_OLD_SUBDEV_BASE + 3) +#define MEDIA_ENT_F_GPIO (MEDIA_ENT_F_OLD_SUBDEV_BASE + 6) /* * Digital TV, analog TV, radio and/or software defined radio tuner functions. From patchwork Tue Nov 12 17:30:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 844036 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C531217649 for ; Tue, 12 Nov 2024 17:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432671; cv=none; b=d1P7D40XghUXEyrbgjw0MPROlCrSMzFxm6s4/jM9Lw7jaUOYBFQdfSg9QNpcRNMQHPQQz0ARwdQflYVS8KV1fm0/pKY95E280Lk4Z5e6vEcm/wVZ9r4UJbqq0T4JqX0RHolpovMZYn+AXfkA2CvC3/dzPzpcSuauxgS5aFt7nIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432671; c=relaxed/simple; bh=CF0PcVCnTua4M04sLWha6j2QMeo+m4ojdywmuELEY+0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uzYZwxO+5aYDOSmCxsMbffUu66LANUk1zt59NDpHTrVACx7I7jrAMizZc7I+4GWYr68P3B0qXyiDqQsI+Edi247XtkYScfxvGXbprEr5q/ODbBeXQwPRXwo2KUdk6W7n7fwf0yknldfFo4A7z+6CNIezI0GriTlsLBa6dbPpxc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=XPRopHlI; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XPRopHlI" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7b147a2ff04so444980485a.3 for ; Tue, 12 Nov 2024 09:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731432668; x=1732037468; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3/+vpzJAvr8wgPjhYiRpNY0/4wAsydMrSlnQmD5XDqE=; b=XPRopHlILGUwgfbzx24q+sYkVTRymVYtYevErZZ4zIOgGIPPVuxno9mfLwX6f+Qt0o Kwfex3Un8pvySCaviItqi793AXN6bDIh/BWpcpIShLflIg+WEHwt/2dmxwAe5AoMFgu3 EPabbSkJN6COW38nrJDQ8p0m7wsSJEWCEcjDU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731432668; x=1732037468; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3/+vpzJAvr8wgPjhYiRpNY0/4wAsydMrSlnQmD5XDqE=; b=vZ9Yg/o3BIJ3HCvscA7677dwgFcR3rVUUrrYw9Cj6WQPI2SiPSzfT9oJEAgj8Kd191 Ql8/kG4aN6dAVPS+XVOaecKduxb1ooCaUsxZpMpXtUwT/P/NgSJKVF0AkQcvvplE5b/N ICBQLYzgLqZFRFmxojFhBj54MqbfkedyRKb/a9MMoBUfAT2gTX6ZkZP3SJllQAXFuwMi rizyjKqtTvTLLY9sogdA5Tq2Lcyyuy2iEQ283say5JdJ4tsTtxncC8qSY//XjDN6tbXN ANv/PLPkzBykn6WuCadQKxIrm7QrnzUJkV6gY5rmU+FBMX6TNgxNIoqrPTQSR4D4Uol5 BSXw== X-Forwarded-Encrypted: i=1; AJvYcCWjzABiPqddObY1QToM6bBB/G72sbdjHAu+KzqdPc8+3CJrIE/iL5eUIIHpgeWA07a6yOQn9zd1zuFqtQ==@vger.kernel.org X-Gm-Message-State: AOJu0Ywfn7Wz9b8udQh+/DfEj3iUGK92b4yiHDbOyqsVqlnkyBG7K+PZ Rwb8MIFW7ZTIzj6uNTCaK/XW6Zmt61NX65ZC/edjP78i5r9sNy/BO4B5Pp/OwQ== X-Google-Smtp-Source: AGHT+IH47lPfRefXpsfqCtb8zXDS8+9Rg/9lO7LpzcLke+uf/oVeQcswjQI8bKQiqG3nUIp8e2h89A== X-Received: by 2002:a05:620a:468f:b0:7b1:4a48:56ae with SMTP id af79cd13be357-7b331eb6c2amr2339676585a.22.1731432668214; Tue, 12 Nov 2024 09:31:08 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac2dcebsm608292285a.7.2024.11.12.09.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:31:06 -0800 (PST) From: Ricardo Ribalda Date: Tue, 12 Nov 2024 17:30:50 +0000 Subject: [PATCH v3 7/8] media: uvcvideo: Use MEDIA_ENT_F_GPIO for the GPIO entity Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241112-uvc-subdev-v3-7-0ea573d41a18@chromium.org> References: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> In-Reply-To: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 Right now we are setting the entity type to unknown for the privacy GPIO entity. Which results in the following error in dmesg. uvcvideo 3-6:1.0: Entity type for entity GPIO was not initialized! Use the newly created type to fix this. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_entity.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c index 7b8fb85d8c03..c9f806bc03c4 100644 --- a/drivers/media/usb/uvc/uvc_entity.c +++ b/drivers/media/usb/uvc/uvc_entity.c @@ -115,6 +115,9 @@ static int uvc_mc_init_entity(struct uvc_video_chain *chain, case UVC_ITT_CAMERA: function = MEDIA_ENT_F_CAM_SENSOR; break; + case UVC_EXT_GPIO_UNIT: + function = MEDIA_ENT_F_GPIO; + break; case UVC_TT_VENDOR_SPECIFIC: case UVC_ITT_VENDOR_SPECIFIC: case UVC_ITT_MEDIA_TRANSPORT_INPUT: @@ -122,7 +125,6 @@ static int uvc_mc_init_entity(struct uvc_video_chain *chain, case UVC_OTT_DISPLAY: case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: case UVC_EXTERNAL_VENDOR_SPECIFIC: - case UVC_EXT_GPIO_UNIT: default: function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN; break; From patchwork Tue Nov 12 17:30:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 842793 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA0F521893D for ; Tue, 12 Nov 2024 17:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432672; cv=none; b=UdsBIYpRuS1V7gGcvLVGUwbgOwAarfsK1gHOYfVfx23lrxUeNih6/ApSLN4yKgFwuSu6UCLPim5KhH+JMKoUVLxqsPkO/6lRR9hW2iacMEJC0+CTqK2d7YPh9e8ayii8RsqtuHy82vhgAReEKiefgq1Fjzydto60HviulMQU79k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731432672; c=relaxed/simple; bh=dKNSbt6Oq25hjXQq50l/hgHRO5f2QAmn2XqN3q2lQ5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xe5sbwVM6D2DoYfBmZ2k70t1dI3i4cM6hnH12jUC0vw69NJD9r3qdOUUgY53sXK5bI0TuRH/hVJFuqgrWPltWVoyIUeeQyc8tOFkzBK5juhhtKE2xN4WBfH7F2nM/vSSDna1MjkZNLZ7H+3Q/wmtcSUp5o5FNQ6u3/kiGS7+KNM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=TpsLUFlE; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TpsLUFlE" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7b154f71885so471964685a.0 for ; Tue, 12 Nov 2024 09:31:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731432669; x=1732037469; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=4jnHw1Y8c4yE4dBcUpY3EUHfdIRMlQ2qG4+v0lq76ss=; b=TpsLUFlEkbognWazm/8sudosVJ5j+C9UjtYE6cff6ETUxmtwk3W1D6B3idF4CSPMng R/03vwzMqM4vi0vIU4Qj81+9FxN9h8GOaACdpRINw3LLb1t24tMeewh87q1jxzjCwxmW uU4doHHaiqc4NhV4zC4A2BBo9UqyayM/q91xM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731432669; x=1732037469; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4jnHw1Y8c4yE4dBcUpY3EUHfdIRMlQ2qG4+v0lq76ss=; b=wEbb10NGvBOZJqR6diU7TfHiUnvk3PNfYga/VKjpRcVeSLo9amvyxyCSmWD/cKdwQ2 tnnpeT51PdBLZUc+VQqi9jXwKr9hibDEz4G226Y4caykfVnOI+zl7UB5fopve/4VvxYs UmGFUl9aj4WxLL9ENF0lEIQxuxEXL48CoivJ5h4NWJmHGs8XR2kNE5s8Tj3nU8N7utFK Q+t8ARtlWxXNwuxmRZ9IBp2NIiw5G6GTs5DliqAJ2p4XtDgRMxAh4p+UniRg9AMleE5c JJAdP04QFGxHt2HIckDMB73a4kUcD1b9rf+h99tpbA7wRxRvfXE6KGBGrVG6rrh7+D9p XU7w== X-Forwarded-Encrypted: i=1; AJvYcCWwOECx+QThzqjtQ4Kr374gMy7lVJlU89v7ucLFr/ddDQN4EtII7ALBOecUhuaZFCfs6GuOmuMCfV57yw==@vger.kernel.org X-Gm-Message-State: AOJu0YwjuTm+6JlkEEtiu3zs8H/5Lb2JsGDldFhhrMtv/ta3iXrIf1jZ Kb+YZ1615wVK9bejFCcVjvpiZLoIVjFVq+Ikr1dgGZ7oypdSWXozaumCeA6CpHwFte4aVW/Eqd4 = X-Google-Smtp-Source: AGHT+IHGdaxihdxWgBKnNf5Sppk6z77xKHWY+whPXuVzDPdvi+N0u/EkrwaH8qJFQf/FzKb9kRKWzA== X-Received: by 2002:a05:620a:31a0:b0:7b1:184f:caba with SMTP id af79cd13be357-7b331f20181mr2066510685a.40.1731432669650; Tue, 12 Nov 2024 09:31:09 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b32ac2dcebsm608292285a.7.2024.11.12.09.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:31:08 -0800 (PST) From: Ricardo Ribalda Date: Tue, 12 Nov 2024 17:30:51 +0000 Subject: [PATCH v3 8/8] media: uvcvideo: Introduce UVC_QUIRK_PRIVACY_DURING_STREAM Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241112-uvc-subdev-v3-8-0ea573d41a18@chromium.org> References: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> In-Reply-To: <20241112-uvc-subdev-v3-0-0ea573d41a18@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 Some devices power the GPIO pull-up with the same power-supply as the camera. Avoid reading the GPIO if the device is not streaming. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_gpio.c | 58 ++++++++++++++++++++++++++++++++++++--- drivers/media/usb/uvc/uvc_video.c | 4 +++ drivers/media/usb/uvc/uvcvideo.h | 4 +++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_gpio.c b/drivers/media/usb/uvc/uvc_gpio.c index 80096022ad08..8cab27c9d90d 100644 --- a/drivers/media/usb/uvc/uvc_gpio.c +++ b/drivers/media/usb/uvc/uvc_gpio.c @@ -5,6 +5,7 @@ * Copyright 2024 Google LLC */ +#include #include #include #include @@ -16,6 +17,9 @@ static irqreturn_t uvc_gpio_irq(int irq, void *data) struct uvc_gpio *uvc_gpio = &dev->gpio_unit->gpio; int new_val; + if (!uvc_gpio->gpio_ready) + return IRQ_HANDLED; + new_val = gpiod_get_value_cansleep(uvc_gpio->gpio_privacy); if (new_val < 0) return IRQ_HANDLED; @@ -26,6 +30,24 @@ static irqreturn_t uvc_gpio_irq(int irq, void *data) 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 */ +}; + int uvc_gpio_parse(struct uvc_device *dev) { struct gpio_desc *gpio_privacy; @@ -47,6 +69,15 @@ int uvc_gpio_parse(struct uvc_device *dev) if (IS_ERR(unit)) return PTR_ERR(unit); + /* + * 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; + else + unit->gpio.gpio_ready = true; + unit->gpio.gpio_privacy = gpio_privacy; unit->gpio.irq = irq; strscpy(unit->name, "GPIO", sizeof(unit->name)); @@ -57,6 +88,16 @@ int uvc_gpio_parse(struct uvc_device *dev) return 0; } +void uvc_gpio_quirk(struct uvc_device *dev, bool stream_on) +{ + if (!dev->gpio_unit || !(dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM)) + return; + + dev->gpio_unit->gpio.gpio_ready = stream_on; + if (stream_on) + uvc_gpio_irq(0, dev); +} + int uvc_gpio_init(struct uvc_device *dev) { struct uvc_entity *unit = dev->gpio_unit; @@ -66,10 +107,6 @@ int uvc_gpio_init(struct uvc_device *dev) if (!unit || unit->gpio.irq < 0) return 0; - init_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); - if (init_val < 0) - return init_val; - ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, IRQF_ONESHOT | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, @@ -77,6 +114,19 @@ int uvc_gpio_init(struct uvc_device *dev) if (ret) return ret; + if ((dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM)) { + uvc_gpio_quirk(dev, false); + init_val = false; + } else { + unit->gpio.gpio_ready = true; + + init_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + if (init_val < 0) { + free_irq(dev->gpio_unit->gpio.irq, dev); + return init_val; + } + } + input_report_switch(dev->input, SW_CAMERA_LENS_COVER, init_val); input_sync(dev->input); diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index cd9c29532fb0..0d542176ccde 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -2296,6 +2296,8 @@ int uvc_video_start_streaming(struct uvc_streaming *stream) if (ret < 0) goto error_video; + uvc_gpio_quirk(stream->dev, true); + return 0; error_video: @@ -2308,6 +2310,8 @@ int uvc_video_start_streaming(struct uvc_streaming *stream) void uvc_video_stop_streaming(struct uvc_streaming *stream) { + uvc_gpio_quirk(stream->dev, 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 6002f1c43b69..1a784fb76ed7 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -77,6 +77,7 @@ #define UVC_QUIRK_NO_RESET_RESUME 0x00004000 #define UVC_QUIRK_DISABLE_AUTOSUSPEND 0x00008000 #define UVC_QUIRK_INVALID_DEVICE_SOF 0x00010000 +#define UVC_QUIRK_PRIVACY_DURING_STREAM 0x00020000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 @@ -233,6 +234,7 @@ struct uvc_entity { struct uvc_gpio { int irq; bool initialized; + bool gpio_ready; struct gpio_desc *gpio_privacy; } gpio; }; @@ -819,10 +821,12 @@ size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, int uvc_gpio_parse(struct uvc_device *dev); int uvc_gpio_init(struct uvc_device *dev); void uvc_gpio_deinit(struct uvc_device *dev); +void uvc_gpio_quirk(struct uvc_device *dev, bool stream_on); #else static inline int uvc_gpio_parse(struct uvc_device *dev) {return 0; } static inline int uvc_gpio_init(struct uvc_device *dev) {return 0; } static inline void uvc_gpio_deinit(struct uvc_device *dev) {}; +static inline void uvc_gpio_quirk(struct uvc_device *dev, bool stream_on) {}; #endif #endif