From patchwork Mon Nov 25 19:49:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13885208 Received: from mail-vs1-f50.google.com (mail-vs1-f50.google.com [209.85.217.50]) (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 0CD3E1B87E8 for ; Mon, 25 Nov 2024 19:49:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564155; cv=none; b=k2Axlb1fXmFBsb/0X4AOUjEolUfFZ7zyHy0DU/LvnJyvXNz/PmKiyYeUYeezTehkaYejTFjZTLbZaYT6wyRIV/6y+VtOtvlM11/SQhCjwXcad2PzQHzpS8Ju+R5lUONUYVEpTbUl5mhXbXoLHJ/18jRHyiPqKK6Yispzk2HhNlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564155; c=relaxed/simple; bh=lLyFcTzGusxxZ21/v0MWLEmZZoMBS5DH1ioIK8mdVvc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Txix6jwemNBzyU/E8IC512NiQoNrgFV6BSy0DdL7jJhcTr+e0weJ94MTfBp0lENeSiSO5saRBEUdPf0BQ1Q0J6NTYmIsClglwPyarhrpAEEKW6+7Y8bImWyEQxHb1+7nrQfMk322jHu2lvbpD/oU8idSNBIPkEVNL7b1sgzGZz8= 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=JHBY6daE; arc=none smtp.client-ip=209.85.217.50 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="JHBY6daE" Received: by mail-vs1-f50.google.com with SMTP id ada2fe7eead31-4af1578d288so453343137.3 for ; Mon, 25 Nov 2024 11:49:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732564152; x=1733168952; 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=py4Kjpl4jbTKIyOvWht4p3oY/tRKB4Qm/pLkP0cvLL0=; b=JHBY6daETy8Q7UiGJRsUAQTh8Tl99slpPu8pN95/j+DeXW8sDR83aB1LSnW1l0a6b+ 1NoZ8PAP0zY0gJIiNLWZDHg3nBnnoL3OsPQeXnip77/sHNDjPMsDOzQBIX/Y7Ne90Q5l zblRRpRKzihiNSiz9hxIP0SHJIkCDd9VMMtNk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732564152; x=1733168952; 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=py4Kjpl4jbTKIyOvWht4p3oY/tRKB4Qm/pLkP0cvLL0=; b=iEVIFJxvxQBHwi1zqwCayoPHxRS9e3G6ca+cARp3HsbUXsOQkyMMS2IzABCmu/pp9L aqijc4IJzDGM1Fcx2/XEbI/XeanHWdGKBegYKpFGA008xu3kgDgf//6YwEV8yC1vyeNa nlQZSqR/DkX7CZ08UPMzi9tpaLKxKjuawpY+g5EREVKuc4+jCTtFoBm/Q9Z6whbbM7yu XpkRwlupvokRe7G+s3B+SZeLKJZafh7Fm0NEk29MLk/qm4bx+p75wYP7Cz2H2vnhzmxG aPI7SPRkZqm1gfd5ic8GaJ9EPIYKSRoTLqp/ZtTZV7WC3s3clSJ6CAuQDMtIqhv3zEHB GP6w== X-Forwarded-Encrypted: i=1; AJvYcCWf/73+8pZwBv8jfTcWi4ERjnY2Sim2cs8WW+BTKVps9s219luuNYDkLgY3Y751Zw+zCUDxR2KLYhRf5Q==@vger.kernel.org X-Gm-Message-State: AOJu0YwjNFsFSwEOtC2OK+0dCF/s2WIohpGV5SR38/0j5/r95rINKP4C Ea1iJAwesWdGYkIfUKESisSRSX6JogFBu/RL+rDfxZ0PtoPRcZ2cWkaPCtDM6A== X-Gm-Gg: ASbGncucW71PwVUSsF+noGIZvd2bI6yy3De9fEbBTqDY0MIPVo4ULkK8UtczUP3c6wx ZP7L5E48T7FWmnu7Jn/q493c1Vg0WABEBpw2LuuvzehIDurCTPwzyJR+/g5ryIhD+upimwz3nYf i2qiKp5XmcYSz4jpOZtD06qqlKh7MytZSskjVt/K+koUKHSUmTGW++xS22XvAMx1YlsIlKv+3vs cMj4Otl3F65hPUjhHtDbLDciWloWw3Z8Xvt4cDbx5YEAX7/K/nuWcmrelXj1jzp/+k6zZGQfPq7 JnMxoxwATXc+q+uuOS+zMnBB X-Google-Smtp-Source: AGHT+IHfh1sCJDgpwH9FQG7v6MoIzU1s9FsJav5t2RwVsg04Z8JYUaPat8uKJz8SaNOSIJeURGbBwA== X-Received: by 2002:a05:6102:5093:b0:4af:15db:6cf2 with SMTP id ada2fe7eead31-4af15db6f6bmr6232541137.22.1732564151982; Mon, 25 Nov 2024 11:49:11 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4af358d2f9asm75324137.23.2024.11.25.11.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 11:49:11 -0800 (PST) From: Ricardo Ribalda Date: Mon, 25 Nov 2024 19:49:06 +0000 Subject: [PATCH v4 1/7] 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: <20241125-uvc-subdev-v4-1-51e040599f1a@chromium.org> References: <20241125-uvc-subdev-v4-0-51e040599f1a@chromium.org> In-Reply-To: <20241125-uvc-subdev-v4-0-51e040599f1a@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 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: 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 faf5386cb061..6d34c910a659 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 Mon Nov 25 19:49:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13885209 Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) (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 36A0C1C07F1 for ; Mon, 25 Nov 2024 19:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564157; cv=none; b=kSSXE1zUhAx0MhODkHhwLNU6RQLLzZJhDeeG/4qIc/JYCsXlMiYkydBCijiK+QoCi5uR5FRlAUx7eQjHaDyConr82YTR+eE+3iwpi7H1GF7m5QyFgTsnx58v9xxRUcp+Qrx5YcI1oWg0oiOY9J4DyasRnpz7WOjuAvIYdHO0H2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564157; c=relaxed/simple; bh=rkxPaYdXHGqxfJOHO5r158lYWCRJX4SpWGFNVeI33Tg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eDw/7xFLsYrt7zhDVMKE/OjUXmMRDLEDHqXcQ2Qclpl8yuuKbIlbYhsnfA/t/kb1f/L2GRAVgFj+dFVldjy/cO1QLeJrQDgY37GCavvoZXBfro4qclSIkaVU5XhJfCmm1bFwQpGzvQPb3lrgEu4L6s/VF78jvQN/ZNr8KfZaWww= 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=LqM8uqFB; arc=none smtp.client-ip=209.85.217.47 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="LqM8uqFB" Received: by mail-vs1-f47.google.com with SMTP id ada2fe7eead31-4af1ace57c7so702550137.0 for ; Mon, 25 Nov 2024 11:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732564154; x=1733168954; 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=MNkRUI2D4ZTXw4CmB2STFErzqoquptPhm1N/NMRAw7I=; b=LqM8uqFB5XxRxfN4FGq2woeAp6o3k69GMA6DPW+KmgfeneHwcyoq15CsGlgQhazMx6 vwlSGCfsgpMXa2DTACkbMpnyPj6cY/HKQub/X9oKF88Gk/dyEPAX01iDAFe3N/Z0M3RU u6p45nNya7q/pxQv4jfNaqoQ2pySMGAzxU3Rs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732564154; x=1733168954; 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=MNkRUI2D4ZTXw4CmB2STFErzqoquptPhm1N/NMRAw7I=; b=DqoynfbN3ttgcRH5bt+sKr9BAGSRQj4qzpRZ9c7QrM1xWZrTl7vMkJ4hj5ZHo5zUFF CS8JIpwXViw4x815JqQz/TNKTgUtOGqsDv1En1v9qgiZAZGRWEbP09PRGUTxTgfm4LwP UtX39SzCEs7PyQ17oahduiGdLHCjILMqV9NTadQ2FvM05gvdLVlONc9BjaENYlYhNpwk nYi6F7QS1OO2B6Ra22qxzzKCjFsuUIq64Fz4yWLEkQgkvjXumlkqhXP/MCbcp+73QC8h cDpu10W1OV3MExFJ9WtFr6t9Q+0uYF2eY2ayC4hQgvpezQIDrs4uSIfwae0flGgWJ/D8 Vtsw== X-Forwarded-Encrypted: i=1; AJvYcCXz+MdmXQTsoYKs0zQQqTGLOGdMdfa+oWpeNr06JWz7Evrwt79rpkGG5uZEQELHfVrOxniRU5A61fHzxA==@vger.kernel.org X-Gm-Message-State: AOJu0YzkKEFS5cGCR3MvdsaW4aqu8BjP+NbYqvte7YzksbGrAszcR9rS mHtn16KdpECvLf6lWlg1qH9hAitk9VQMfBWzBFA91S83fZNWEHWMXKQslbE22Q== X-Gm-Gg: ASbGncvkH0U5orN1E0EYcAtOPgJ8mYVGA3/1cIU6MyGRQpEI5zFRBSZ6FNb1Io+PItL C1NoFQ1snp5JF5g0DsChAAef8qkLKn1KbVrfGu07v68MXKrIKW6+A2EKY5VnBoj5MrUt5NQSgwk DSPuv1Enzem1lIxTfEY1a9F/bU5ilNoXJzod49pLt4Pan54z6wZgpMcI/Xw5Fr0btcHLZkSbbB6 7mO9LUD/yPMOrcFQKGV61LWsBx8HvlQk8eJ3PekH5Dj/bWqVaNgsCT274s4wycvsBySb1mX8bht YnILhhzJb5H8re6NyMgUUsvT X-Google-Smtp-Source: AGHT+IFw4r0pJxPsi4HR2ZjtMg6jgNCS9ulAehVcqVJSXpmzBFsZUst3LdIDlS4ju0WKRKwzvh/1kg== X-Received: by 2002:a67:f596:0:b0:4af:2d38:2232 with SMTP id ada2fe7eead31-4af35eb0df9mr847909137.6.1732564154195; Mon, 25 Nov 2024 11:49:14 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4af358d2f9asm75324137.23.2024.11.25.11.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 11:49:13 -0800 (PST) From: Ricardo Ribalda Date: Mon, 25 Nov 2024 19:49:07 +0000 Subject: [PATCH v4 2/7] 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: <20241125-uvc-subdev-v4-2-51e040599f1a@chromium.org> References: <20241125-uvc-subdev-v4-0-51e040599f1a@chromium.org> In-Reply-To: <20241125-uvc-subdev-v4-0-51e040599f1a@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 6d34c910a659..914f342f4aa3 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 Mon Nov 25 19:49:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13885210 Received: from mail-ua1-f49.google.com (mail-ua1-f49.google.com [209.85.222.49]) (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 5375E1C8FB4 for ; Mon, 25 Nov 2024 19:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564159; cv=none; b=DOT+IPp8OEcNlTLXXCD27O4KvUcNRwU++s/KljpWVNAtC4Odw9xcib/17FCCG1xf+Qtp94O0u81iKyRZZMGPBX7RraJBJBbCMscUd20KkwF6wbagbwk7f57YqM8cssZCmeGQEIl2GmW6KY0cdjmoXfOfd/0WIKyvMOt7Z/WApUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564159; c=relaxed/simple; bh=GX9trsdzPioO395Gg+CXhWOOnI33tO2p41ZGbit2xt4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=irZdvQLiLV9TIvYWnE6W2WrD79a7TQ7W5yhXEx+riI9sSQzbozZmRqS+v25CgKu1X3S53ABL3yaJrGGMWbfJfQnV+0pKX/pz3toPOkEq6hSI5W4zAj2PJ/yGgdyeJ2fjG+9CQ9uLs5oTEVFY9XEqFMyPXStbcOo3g08E9bh7GNg= 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=DwD382zJ; arc=none smtp.client-ip=209.85.222.49 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="DwD382zJ" Received: by mail-ua1-f49.google.com with SMTP id a1e0cc1a2514c-8574d696055so1008594241.2 for ; Mon, 25 Nov 2024 11:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732564156; x=1733168956; 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=A3hhHdUasNa76JNkJUeccOV8K9BEb0pXt/VGiDGL3kg=; b=DwD382zJU0ztTnt+H0Gho1vNr9utlaL1tGjagOyKy42MBJWTkyrgTUhSU7GecRxvNi pmQJs6xzmMOTpv7PFJW/QnATv/okOW3uYt+99TIwbEQyehAN+X+YbCJ87dO+pxnxVTJY fazo/GE48WnwGpQONA9lGJ/xJL8e41qx5zX6E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732564156; x=1733168956; 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=A3hhHdUasNa76JNkJUeccOV8K9BEb0pXt/VGiDGL3kg=; b=YUrSPqBRDrIrmyMcK9n8EaduWFN/IPmFCwcl3JlGqgMy4FpAZ7BHp2y1crd4WdJ3y0 GxAVcMuCMtsjlCpskt2+1Kzv+9dO9dV9FDVx1UZuJHLlgNQ3++BJNS/FdQaAGlGe2vxg lL/seEIUagWEBBMaFwVueDnI2FINn0zV+LM4ndJjp/7ireCJSzwOrJa4PKH8+rFTHtVS ftLB42DxrKsXB4Zzdud8YUZQp62gmi3bxsm+h5o4TCk7ztr7I/KvhfhafC3ILzv6Q+Q/ cMhPo2Yc0KG9iyoxwIkEjh2hKkUMXJx0GWjHQjtXMScqL6LKT80Q6eb+KWvAYouoyHi9 mg1w== X-Forwarded-Encrypted: i=1; AJvYcCVBjeys0dUOandjRETjCJ6q50Aly0WQQ6F1Qy5J68YKzZSGl2UjyFUpLcfuiCn85qK9ERbEK6as3NO27w==@vger.kernel.org X-Gm-Message-State: AOJu0YxgeHVx+y/Y87m/RTe5n3GWiS8zJ+t81SHEPvuxNxtR5tCYPgh0 /01i3CGYmFfs35Q/Zg2YXWXHkIEFD1IQ4SMTuXMa9SOkWpVCJnolXIVI2zZ7qjgUgqLqB42xJN8 = X-Gm-Gg: ASbGncvG0CjwBxuB6pQwq5Vam3IoXqE+1yG4qvEyaMXchIjvoVH/X6hocFGztp1WI0w XwuRo7uwQIG7Kc56udj3xXBHURaaV1L/7+m31u3pMp8MtwkYz9u5LUrbr6gKz5/BAn60JDdZQsm PdyhG3h3/EZktRDE6RnUV3dR/eXVAjTe1qWWbjNnN07UkWD7atcIYxL+Y+QM/XG5bX56iVcCIkw LlARCn8XHA2E1AU9HrFtI7RuNg8+uc7iFcX42X8OCSHFf9Day2xoyPwW5q34YKks+H/GcnY98Oj dPeCGoqeplei8j3wXAFNQ45B X-Google-Smtp-Source: AGHT+IH1ey2KteIhbabJrhphlQOy3xtxbpop+5KZHeknT32aOGcrv2p46SrPAjO5se9aH+KHzxNlsA== X-Received: by 2002:a05:6102:390c:b0:4af:2f95:4ae5 with SMTP id ada2fe7eead31-4af2f954e31mr3188034137.9.1732564156361; Mon, 25 Nov 2024 11:49:16 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4af358d2f9asm75324137.23.2024.11.25.11.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 11:49:15 -0800 (PST) From: Ricardo Ribalda Date: Mon, 25 Nov 2024 19:49:08 +0000 Subject: [PATCH v4 3/7] 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: <20241125-uvc-subdev-v4-3-51e040599f1a@chromium.org> References: <20241125-uvc-subdev-v4-0-51e040599f1a@chromium.org> In-Reply-To: <20241125-uvc-subdev-v4-0-51e040599f1a@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 914f342f4aa3..c34bfadce60c 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 Mon Nov 25 19:49:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13885211 Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (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 490F71CBE8B for ; Mon, 25 Nov 2024 19:49:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564160; cv=none; b=YCnHcSDGPjGglzCVI1spyae4tpNffeLsUMf0shutGG1VfYFVaCYeoSSMpJ+12OL1Ymwlkee6DOh9n6Kuuw2CAH56zaD5yhfjapaGex6gGn6Ltx681RrgbpuDWTRU6q6NSfJ3Jf6ab9iGeE6fFWTEtyX7newXTt5xT40F1FGUrvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564160; c=relaxed/simple; bh=vAAOYhnDuCS6QSDtHNvCZ/7V8wyms193hC/CkNF19gg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ERIGD+N/qdzDGzWhwTcJiEOu/nVXC1bapbQBaHRSJNxxmwcQit+LE7O6/loPWWt+1KdLruWctPCCSk2KRNs6Qlk2NuXjlLDR+qFBbPCp2ciaWc13y1Uc6z/Fag+NJgHRmgAzPpqgioeD6/mnG9KfG6D0oFSRzomJX/CQ7Zhm5h8= 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=I7tFM6IJ; arc=none smtp.client-ip=209.85.217.44 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="I7tFM6IJ" Received: by mail-vs1-f44.google.com with SMTP id ada2fe7eead31-4aefcb3242aso861029137.1 for ; Mon, 25 Nov 2024 11:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732564158; x=1733168958; 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=Qew2lSt6MOHSZhwSkHfFr6COKD1ZhgAt7ezEOaoydpo=; b=I7tFM6IJ4z1ud9N0cp5ha0k3yRHi0XUjo7ipQ+LJEkd3nMkgkh83zlQHsJf5vRE1wZ W0oJA9i+AeZXj4JoqBcQFpUnvVdx5Ks7w1E+B29rhe2naPsasUVv4DyreQnrfhm9NS55 d6P1xJxlK64LwCDEwQxB+Cya9JVKshX/zeW9Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732564158; x=1733168958; 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=Qew2lSt6MOHSZhwSkHfFr6COKD1ZhgAt7ezEOaoydpo=; b=YIgfpQeM0bBsj1wxDeOzg1XOZFLLqAHIl9Ybog8lqFOW8Sn3WNObDYLpQtx6vIIKDP HwjMMFitG1I5Y8bvuaLgt3YTmugaPiVUz/vqpFz8b3Rx+NKhtsfNtbbeMqXUV/wzNvET Wv7m5S8fsuqmTp8bo2dqUN2en8xf3k0J+m58fW7UPOjqL8u9xXUxjtiPKLrge6mCTrvG p3BaVrltC68D8AGTbR4ag5biQXM+YaCNq8pbj6VhiWybiu5x50gEDc4YspOnnv0FtM8H FBb9vmWCB+Vm4IMWQm++f5jCAuevuG0u4Wq9F81Dgj9g7g53YZ/mzjX/Pkwfsp+JW4Rg u4hA== X-Forwarded-Encrypted: i=1; AJvYcCVQZovTFA2pMS07dto7bhhb+3o1p2pDNEbC1xVoDKz1gPtcdpMj/Bt0s1WHZjqkSwnMx4PhZEtkOwE+4w==@vger.kernel.org X-Gm-Message-State: AOJu0YxZtTniFEUvWM0+nnHu6WzhodcxUKi88hgMoxYpSp46BhzNiVTy cvq/gTtTxxItqHv8yrQrzkcBtcshruYrfGTsGTJ2IokYAHu5yPlnClyFBhgkCw== X-Gm-Gg: ASbGncs/GGrFyAZw7+U7O3peUYW/UaCNrAOYXIanEqVa+Vd+Vy68rn2Py4ompg4+yhX vY41SG40ZHUFku3DXrnbx77jTqUxTKF4T/0lhr3gBSdKLP9h95r3uNDCkEvlsolJepo/AGKR2jb xh+04UieOVGldCWbJU1yhc+iPvtd5D4bCMQrJ/sv4Z2lkQotF0AIvv9DX+Q3VRZo8bSRhvX+rJl Br2i9a7PzkAb6KKEoGvzVxP8zQTeNrPavOVUHA5JCe0YwM/7V3JsADYxgLSFKhYpHWyjGaghX39 cf7YYRPKOkGh6w1ivGdIaIEa X-Google-Smtp-Source: AGHT+IEzOfjRUDJXkBH/ci9g+7icIZ8rpZbJ+DF/b16ADeDrCfZI2M6YFtGhhnhW1P+JjUvKqQBQpg== X-Received: by 2002:a05:6102:3f44:b0:493:de37:b3ef with SMTP id ada2fe7eead31-4addcbe4e47mr15581878137.13.1732564158359; Mon, 25 Nov 2024 11:49:18 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4af358d2f9asm75324137.23.2024.11.25.11.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 11:49:17 -0800 (PST) From: Ricardo Ribalda Date: Mon, 25 Nov 2024 19:49:09 +0000 Subject: [PATCH v4 4/7] 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: <20241125-uvc-subdev-v4-4-51e040599f1a@chromium.org> References: <20241125-uvc-subdev-v4-0-51e040599f1a@chromium.org> In-Reply-To: <20241125-uvc-subdev-v4-0-51e040599f1a@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 Mon Nov 25 19:49:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13885212 Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com [209.85.222.44]) (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 323D31CDA0B for ; Mon, 25 Nov 2024 19:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564164; cv=none; b=B8jyE19fqGchiHv7thxIHfKQ+zp52aCyTC35xf3pqtdAnu9PCPeON4UU6//sQBwmfN4VCzOxrHB9Y3dqcX22Z6UKzLh7l6vVGQ4UjXZBvQQbf2sO3NiTtrpXUM6JIqnqh17Ndyrd/coZ73Tix3snfZlarvRxa21vJpqmB8vEOWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564164; c=relaxed/simple; bh=fVuGaw1F+PMy4lVEqejt4Vp5RlNBADE5AOJUiE6ElSE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Rp3cvG2DYg7JQLdJAz/yIQl/kPdFMkCXWNxFr6xeQbUiZdlTkzmVl0nN6wkB5vnpAarYYNVn+AjIJv4WjADCI+pr9PWHAM9ub+zJoUaY/rWw83tsEUvy4A5Bu7PYunpiOsEe03JbDekRuTnF30Dkxd0l/IqkypRyOyhhMZOgOx4= 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=Qt9hhx9O; arc=none smtp.client-ip=209.85.222.44 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="Qt9hhx9O" Received: by mail-ua1-f44.google.com with SMTP id a1e0cc1a2514c-856a084088bso1324732241.0 for ; Mon, 25 Nov 2024 11:49:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732564161; x=1733168961; 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=I0D5Q+hYOq1ZPHGsr7NgS7GX1OqcPua9PPDDXDLVIPA=; b=Qt9hhx9OSwqE34yiwZ0qZZRjdWFlUCJx2C2jPjVbceI/lTHXfA8sZpnFs/fWDzCApD tD99sJL0N8t31zSNLg1UEpsfXmVUp7Du13xiZKcfsr9Riiwy5nB7rw9wIKFV6VhjvJiu OrsidDt+T7H+3SzyL8insVQdkFba97gk1DEMo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732564161; x=1733168961; 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=I0D5Q+hYOq1ZPHGsr7NgS7GX1OqcPua9PPDDXDLVIPA=; b=crB4q5FkkPxgD6hcB0B/DqhGSLYHRlV/VIEg+JWaUacBa+oFrCcXa0QWrc3QziZtx6 YUVm0kRRuvNcOxXSrgFrUkSKeETuLmbmBmJ7d1PNYI9yhFPiZJoTol0rHyy930wAJYv6 JKhc3jlWoTp79ILhFiN9Coz/gFrieK316UQXZYhqJSJOHCZEFntJdhv7f8BlSbkEhO+n F+7i6nD3m5kD+QxxlpkhgkbLP5EWyIupGizWwHVoq7CgZihZRIxjFsxItUEFdWrl2xQy fZhZrzhKin8eRxCu/GwB7f8Vud6r75StV/2amNeftImIjIXThNILjH4pLC7obqCEn8gR yGMw== X-Forwarded-Encrypted: i=1; AJvYcCUDchEmn6IEuj8fDFnbFArNzvWaAoNQ5r9boQYYrK66IYwnugMXiWRaoAQYmXJuEB15M82iABPdo81uQw==@vger.kernel.org X-Gm-Message-State: AOJu0YwvNMW8bkMI0Jns2Z1IoL11J6esZwG6ZfTOuj7FNnRwCeL6GM+2 A75x1Ckmzeix3xAdaH2t1iwheAFFSsqgAhecAHTMApCTQywhYrypYfmuTz+9uQ== X-Gm-Gg: ASbGncuoD/M83lKyTXdv2Os3+VDvRqclTa/QVS4u6W5peFe0HtRzqMZFNgKUrJ4WEmH hUNQBzW5rpzcONqvlYnwzTxP5+zKOPmg92S+VT9k/ASivA0Ye0HBHH6q9BqsqvTziT8xs9C7DUi N2QRJcUNldnjQmXgB3GypdAKdvrI874mt+XCpXneu8T5MhuUCygViXxfpZslFVRwF8undS6XnOL 0n1hbr9ijZNqzsqNhLAQ+xRcec2d47KiNCOedB6W2L2eNoap/iuewPDztpgYvhGjMUClmeAmXD2 UW/EzIK43eZNhdcOTfk76TI8 X-Google-Smtp-Source: AGHT+IFORfKuNSMeS8hZDVAV1JGG165wthWbApvkGS4fYQL7dck4HfDnA98H1BoQ7EjhoTfR6/qswA== X-Received: by 2002:a05:6102:e12:b0:4a5:b003:41bd with SMTP id ada2fe7eead31-4addcd1947amr13528500137.22.1732564160660; Mon, 25 Nov 2024 11:49:20 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4af358d2f9asm75324137.23.2024.11.25.11.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 11:49:19 -0800 (PST) From: Ricardo Ribalda Date: Mon, 25 Nov 2024 19:49:10 +0000 Subject: [PATCH v4 5/7] 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: <20241125-uvc-subdev-v4-5-51e040599f1a@chromium.org> References: <20241125-uvc-subdev-v4-0-51e040599f1a@chromium.org> In-Reply-To: <20241125-uvc-subdev-v4-0-51e040599f1a@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..e6fe1845bd01 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(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 e00f38dd07d9..6efff8a7aca5 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 From patchwork Mon Nov 25 19:49:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13885213 Received: from mail-vs1-f49.google.com (mail-vs1-f49.google.com [209.85.217.49]) (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 CDF381CDFB9 for ; Mon, 25 Nov 2024 19:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564165; cv=none; b=RJmeYYUZLd8CvNNiD0ixIOX38N5wA8W/ZA3XV+NNd02ksO+4+GQSYDQ6pWRVJ6T91rcnCV8hzjyGcrhhVb5KxttHqHEim65iop5uV+NFIGv788+XhnB5+w+25eq5njcRm68hiszD1ZwQwuCXVXjZwOHQ09ahHmomSi1sS+PKVVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564165; c=relaxed/simple; bh=LJwMS6MJ8Ltz6IYWDIRFRnplCJ9F2eVGdbiFdyt/WMc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qQhasnls1Ks1G7wY8CIzIHf9TYs+Vkcj3PkVGSzueymW2ctVFu0lTnFe1iEie9pBPpiSSGAHy4MKy7y0uX95zU9Ew58bPKhMDRlCZHAIlISbyovQKYxRhJjpRA0Yferyto/OCUOMrCNKtNiq2cAgDTTw6ghJhCitY2wfGH6xb/0= 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=VsyEFGDK; arc=none smtp.client-ip=209.85.217.49 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="VsyEFGDK" Received: by mail-vs1-f49.google.com with SMTP id ada2fe7eead31-4ad633f4cd9so1333347137.0 for ; Mon, 25 Nov 2024 11:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732564163; x=1733168963; 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=ImPJuXy1q7OulXoOIZvimBy9/1LlGfl5z3fyGupJqII=; b=VsyEFGDKspaTWTQcfOwoAlPhZOoIt4lQUKhLuG23My9RK56hKRXoM4LETAJ40oRDiO DG+gHabGKWsvaxtNXNp3nugIzLC3f4/9Mq51DDwAvFqkK0NwYpRYVModibUJUj1jij+b qEYTKD0/zMLAPr5UoVCNTt2Qj381DQYJgG70g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732564163; x=1733168963; 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=ImPJuXy1q7OulXoOIZvimBy9/1LlGfl5z3fyGupJqII=; b=cKWHmCK3tUamD8TZh9l8+2dRgF4coR1judPbFAcDsktLfJvqlagDsxIXBr6UwRszxE xC4cxPnJ5qZud4oni1dPcP5MKc1ub9lpgouto+MKvsSCpSdxNJEkFqlOffDk8YdGIH+b v5wLA08VaympfdYEzcdB7ki0at7y6d5Wkb7L3+vBsT3O3bJyqMi6g9256qMDkokikYuh FG/UqDcVVcLkLxQq88KcliblK1z2Wli41XYEW+J4V8DHHXgSSZifB3HKRjkHrWQSZM2i 0VVnW8J/eeTOI2LrQlAFb1AgLJqS17RYDi8K1lmZn/97xpm8ZvDxiglLJm/QEziwe2dI HFMQ== X-Forwarded-Encrypted: i=1; AJvYcCX7sKgwXgMWGRbdDHgVAlDWX89FMyZuPGa22rJGMoTWxtxuY9IZicJ/bf3QU3z5eR2EpOwneyrq5ohhrg==@vger.kernel.org X-Gm-Message-State: AOJu0YzTSuizwNlUkFuQPmJ9d4S/a7vEn/khPvEvVczAcEUPztC9l7AG hJixkiC06LzTL+wuUz6PGY3GiwqM38bauiJ5yujxOPKlIIrjmumsdt9yKyznCA== X-Gm-Gg: ASbGncscUf6GlpMiY1glfQ21cn1GWqL+J6zLpeWYai543A2hB9eIJXNH1BzzTHytI8B IdExkxFI0v+HH/cKjQw8piRJ/qLRAZMDp/p5NS1NsfqNqUOtdkUPidVfjl0jGl+II+POUMFNEB5 GCSQE50Td/ZAN0kONZAUHoe2Va8sDoq1Jvseex0/gum69TAnHzGzAZ4k0bIMsn6Co8bXpvT4DJg MF6C+FdMe+qlqL6s60QO/Yku152nu8FpYlimsAs3uNNRatHivabghTQCUdQPcUzwFfuAjPRpoFh hwAFnlzH7UsKsr4XivbqYG5C X-Google-Smtp-Source: AGHT+IGmPA/X88hhCinX2JdfqBivCFQ7s6RNh6d830PSDJ9V+HQ4CIYEu7z7dwlCqNiOvRpEMNaIpQ== X-Received: by 2002:a05:6102:3749:b0:4af:958:97d5 with SMTP id ada2fe7eead31-4af0958989bmr7687165137.25.1732564162778; Mon, 25 Nov 2024 11:49:22 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4af358d2f9asm75324137.23.2024.11.25.11.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 11:49:21 -0800 (PST) From: Ricardo Ribalda Date: Mon, 25 Nov 2024 19:49:11 +0000 Subject: [PATCH v4 6/7] media: uvcvideo: Make gpio_unit entity-less Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241125-uvc-subdev-v4-6-51e040599f1a@chromium.org> References: <20241125-uvc-subdev-v4-0-51e040599f1a@chromium.org> In-Reply-To: <20241125-uvc-subdev-v4-0-51e040599f1a@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 Now that we do not need to export a control there is no need to create an entity. Move the uvc_gpio structure to uvc_device. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 7 ------- drivers/media/usb/uvc/uvc_gpio.c | 40 ++++++++++++++------------------------ drivers/media/usb/uvc/uvc_status.c | 4 ++-- drivers/media/usb/uvc/uvcvideo.h | 2 +- 4 files changed, 18 insertions(+), 35 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index c34bfadce60c..ec07c74a5d26 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1750,13 +1750,6 @@ static int uvc_scan_device(struct uvc_device *dev) return -1; } - /* Add GPIO entity to the first chain. */ - if (dev->gpio_unit) { - chain = list_first_entry(&dev->chains, - struct uvc_video_chain, list); - list_add_tail(&dev->gpio_unit->chain, &chain->entities); - } - return 0; } diff --git a/drivers/media/usb/uvc/uvc_gpio.c b/drivers/media/usb/uvc/uvc_gpio.c index e6fe1845bd01..ad3716d0cf56 100644 --- a/drivers/media/usb/uvc/uvc_gpio.c +++ b/drivers/media/usb/uvc/uvc_gpio.c @@ -14,7 +14,7 @@ static irqreturn_t uvc_gpio_irq(int irq, void *data) { struct uvc_device *dev = data; - struct uvc_gpio *uvc_gpio = &dev->gpio_unit->gpio; + struct uvc_gpio *uvc_gpio = &dev->gpio_unit; int new_val; if (!uvc_gpio->gpio_ready) @@ -51,7 +51,6 @@ static const struct dmi_system_id privacy_valid_during_streamon[] = { int uvc_gpio_parse(struct uvc_device *dev) { struct gpio_desc *gpio_privacy; - struct uvc_entity *unit; int irq; gpio_privacy = devm_gpiod_get_optional(&dev->intf->dev, "privacy", @@ -64,11 +63,6 @@ int uvc_gpio_parse(struct uvc_device *dev) 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, 0); - 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. @@ -76,38 +70,33 @@ int uvc_gpio_parse(struct uvc_device *dev) 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)); - list_add_tail(&unit->list, &dev->entities); + dev->gpio_unit.gpio_ready = true; - dev->gpio_unit = unit; + dev->gpio_unit.gpio_privacy = gpio_privacy; + dev->gpio_unit.irq = irq; return 0; } void uvc_gpio_quirk(struct uvc_device *dev, bool stream_on) { - if (!dev->gpio_unit || !(dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM)) + if (!(dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM)) return; - dev->gpio_unit->gpio.gpio_ready = stream_on; + dev->gpio_unit.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; int init_val; int ret; - if (!unit || unit->gpio.irq < 0) + if (!dev->gpio_unit.gpio_privacy) return 0; - ret = request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, + ret = request_threaded_irq(dev->gpio_unit.irq, NULL, uvc_gpio_irq, IRQF_ONESHOT | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, "uvc_privacy_gpio", dev); @@ -118,11 +107,12 @@ int uvc_gpio_init(struct uvc_device *dev) uvc_gpio_quirk(dev, false); init_val = false; } else { - unit->gpio.gpio_ready = true; + dev->gpio_unit.gpio_ready = true; - init_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + init_val = + gpiod_get_value_cansleep(dev->gpio_unit.gpio_privacy); if (init_val < 0) { - free_irq(unit->gpio.irq, dev); + free_irq(dev->gpio_unit.irq, dev); return init_val; } } @@ -130,15 +120,15 @@ int uvc_gpio_init(struct uvc_device *dev) input_report_switch(dev->input, SW_CAMERA_LENS_COVER, init_val); input_sync(dev->input); - unit->gpio.initialized = true; + dev->gpio_unit.initialized = true; return 0; } void uvc_gpio_deinit(struct uvc_device *dev) { - if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) + if (!dev->gpio_unit.initialized) return; - free_irq(dev->gpio_unit->gpio.irq, dev); + free_irq(dev->gpio_unit.irq, dev); } diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c index 319f472213f6..e5ebac1e7093 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) && !dev->gpio_unit) + if (!uvc_input_has_button(dev) && !dev->gpio_unit.gpio_privacy) return 0; input = input_allocate_device(); @@ -64,7 +64,7 @@ static int uvc_input_init(struct uvc_device *dev) __set_bit(KEY_CAMERA, input->keybit); } - if (dev->gpio_unit) { + if (dev->gpio_unit.gpio_privacy) { __set_bit(EV_SW, input->evbit); __set_bit(SW_CAMERA_LENS_COVER, input->swbit); } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 1a784fb76ed7..642449acce1c 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -596,7 +596,7 @@ struct uvc_device { const void *data; } async_ctrl; - struct uvc_entity *gpio_unit; + struct uvc_gpio gpio_unit; }; enum uvc_handle_state { From patchwork Mon Nov 25 19:49:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13885214 Received: from mail-vk1-f170.google.com (mail-vk1-f170.google.com [209.85.221.170]) (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 032A51CEEAE for ; Mon, 25 Nov 2024 19:49:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564169; cv=none; b=JZUPr3BoYAmnvZPHkTMma1+iPVo7pHMAmZdiGc+9ls9KdoZnpHst1wdSSNfwEZJLHtAx9uoxIWAKcI6GLPi3oG7HM8LVQIVZC9aD/MYZEZK+Cbyp3NV4YQMAg+Ylmnfm+LXE8p58058Y44Mwm5jl+lqmMCWVBCnqqRoOja6JFe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732564169; c=relaxed/simple; bh=cEG8q7JwIhfvSJZ4SLtfR3SIICXk8+dsAPReT7UVOHs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A8dDeckrDlekkaq8QzCwVteFe2dswSBU4E1FFmmtihHcDjJHL1RTSLx4R2gg/BKX98dKqtIdYSlsSUZ+ry3k33XT3K1dZJJSvUMaQwXJZClD+f5Pq9SM48bGEiAAG8b/03cwarSsKTReotPSd4qGGJlpbzFgZx7OOqyJ+eqUGn8= 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=LonaoS9m; arc=none smtp.client-ip=209.85.221.170 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="LonaoS9m" Received: by mail-vk1-f170.google.com with SMTP id 71dfb90a1353d-51533f41c94so354469e0c.0 for ; Mon, 25 Nov 2024 11:49:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732564165; x=1733168965; 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=8yziQfukfCQ8tCuWUmt6FHkDaKYe54QyufD5J4OTJbE=; b=LonaoS9mJNf9HZmb5t/xbnLohI8N62UTwKaPUyhrpk/dIkASY/3bFpS0E8ryTwv//k ctDppn/CXRQHs5OE2CABJrREwfS6h8KeDiqINB+0Z0QCRiFSSKniJInAUzGuZwvFTxfy YHO6Tv0wlUbT5Pdt7dIbJgQbQtWR4y3h1wBc8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732564165; x=1733168965; 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=8yziQfukfCQ8tCuWUmt6FHkDaKYe54QyufD5J4OTJbE=; b=TxdVR6FM54F+NG3F1I1dYALXrtQgwVIEDBrnyMe/dCal48+ANyx50sQV9Pn/tzmwjK R7+f6cYVQ9TAfyxYJjQwV3aEGKmghrXyfydVXqDhzomtoo05FjgJUYbrgvI3Vt9ojRGi 5tua9c8gxm+hDn80ywa3MNlcsJKSlpHVaVRXuKW64xhzUPgRcUqB2umojih+3Tg+8CIH 2jNkaQ+T7sYdGYTsglGN0Ecc6lIbX4CESuBh9TkVYsM9pzZ708/smHnJjpsxGzodfvJX OA/LAZRabpcsa9B5u3KDpc23mlc8C8t0FqiY3nTEyBud3tqca97v0+WIaNjDEhaPyzey X6yA== X-Forwarded-Encrypted: i=1; AJvYcCUALL/vd2iWaffA2d9zfY406rOFMkjRqdrZCkBGB7ZUFC9dSwlcg6hUl+mH6J1UZ9QOdBg+iBdqWKWluA==@vger.kernel.org X-Gm-Message-State: AOJu0Yxqk0SWWjXHXuReO+rDjNco5N1VEUF4MDRy0u7jXPUdUm017s7s D5e+Vkeu/wtL3QW51F3faSmk1ZOGny6VbhZFbWYTy4WoxmHxA2ipt8GaEAPD7w== X-Gm-Gg: ASbGncvekcA5IKdAeidGU5zz6AsGDpQwabjk5SME7DAn0dBqXwifGPwwl8gVONSC6ci M8kkaX5ndV60kxpeCmgmTZ/2gzbpQz0YLzDuWuabWhqocjQKPYE1TiguaD001RgpXl+rTfezVrL Tm4ncCkFmc9a3dSvwYVtlEjRWMVijaHZ2UFuoXyCqwu1yjCcrFFL+f0CdBHgtCxu3x/fbeodPf1 fCzuFW55P2jN1LJLeehBxH8lJIuNoAiAKj4Q11fZF2VtaqZUaVUWS1EistU4XinsQb9thG0SM+o nJUR83pAwtPRW7Wbf5kqamYy X-Google-Smtp-Source: AGHT+IEgALvAdijAkIcRetk4zuNBzVe1drnMtsw5mI5v64sMgDPBNw61u2gMURnGyFwCjHjpcK36EQ== X-Received: by 2002:a05:6102:522:b0:4a4:97d1:aea0 with SMTP id ada2fe7eead31-4addcbefa12mr12046094137.11.1732564164881; Mon, 25 Nov 2024 11:49:24 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4af358d2f9asm75324137.23.2024.11.25.11.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 11:49:23 -0800 (PST) From: Ricardo Ribalda Date: Mon, 25 Nov 2024 19:49:12 +0000 Subject: [PATCH v4 7/7] media: uvcvideo: Remove UVC_EXT_GPIO entity Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241125-uvc-subdev-v4-7-51e040599f1a@chromium.org> References: <20241125-uvc-subdev-v4-0-51e040599f1a@chromium.org> In-Reply-To: <20241125-uvc-subdev-v4-0-51e040599f1a@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 The only implementation of this entity was the external privacy gpio, which now does not require to emulate an entity. Remove all the dead code. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 4 ---- drivers/media/usb/uvc/uvc_entity.c | 1 - drivers/media/usb/uvc/uvcvideo.h | 20 +++++++------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index ec07c74a5d26..936225c89182 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -769,7 +769,6 @@ static int uvc_parse_streaming(struct uvc_device *dev, } static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; -static const u8 uvc_gpio_guid[16] = UVC_GUID_EXT_GPIO_CONTROLLER; 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; @@ -814,9 +813,6 @@ struct uvc_entity *uvc_alloc_new_entity(struct uvc_device *dev, u16 type, * is initialized by the caller. */ switch (type) { - case UVC_EXT_GPIO_UNIT: - memcpy(entity->guid, uvc_gpio_guid, 16); - break; case UVC_ITT_CAMERA: memcpy(entity->guid, uvc_camera_guid, 16); break; diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c index c1b69f9eaa56..36121b111ed5 100644 --- a/drivers/media/usb/uvc/uvc_entity.c +++ b/drivers/media/usb/uvc/uvc_entity.c @@ -111,7 +111,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; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 642449acce1c..5dd9ec1668e6 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -39,9 +39,6 @@ (UVC_ENTITY_IS_TERM(entity) && \ ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) -#define UVC_EXT_GPIO_UNIT 0x7ffe -#define UVC_EXT_GPIO_UNIT_ID 0x100 - /* ------------------------------------------------------------------------ * Driver specific constants. */ @@ -180,8 +177,7 @@ struct uvc_entity { /* * Entities exposed by the UVC device use IDs 0-255, extra entities - * implemented by the driver (such as the GPIO entity) use IDs 256 and - * up. + * implemented by the driver use IDs 256 and up. */ u16 id; u16 type; @@ -230,13 +226,6 @@ struct uvc_entity { u8 *bmControls; u8 *bmControlsType; } extension; - - struct uvc_gpio { - int irq; - bool initialized; - bool gpio_ready; - struct gpio_desc *gpio_privacy; - } gpio; }; u8 bNrInPins; @@ -596,7 +585,12 @@ struct uvc_device { const void *data; } async_ctrl; - struct uvc_gpio gpio_unit; + struct uvc_gpio { + int irq; + bool initialized; + bool gpio_ready; + struct gpio_desc *gpio_privacy; + } gpio_unit; }; enum uvc_handle_state {