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: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: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: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