From patchwork Thu Oct 31 13:43:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13857944 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 E6E5919DF60 for ; Thu, 31 Oct 2024 13:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382202; cv=none; b=nJnynogxbWYAeeBV5usk8zXDWB91zHx2GLcE44llpITXGZKY8wOurNuPyFKMVg1lrFdT7ui+gmB5kfsxRFq6y0fH71Rua28QAEJ+TBt2YEQzChDvRI5mvio3Ht42x8b/0+qIIjZ8Sdi5f6AkSoLcuGE5+ncA+si7LiRUOCywThU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382202; c=relaxed/simple; bh=MFSbzsC4qpSDjJpQBpgnBMJ9pfWpXmfF9LukJr0n+kU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fvUcbx+q5zxd+kzVghCUgGzaxQ1QZmMWGoO7cf5zzulmBPUtuBxUU0WMnNkFrgI03J6WKayRsvspUkF1s/k+L+yH41Gr1FbJWqY7dZKxlIwdKXtT9f2mzM7ByLNuuXpPQJ9RLtDGldVjyOJt1bU/4+ezFu6dnFyn/MYdGBb0Rrw= 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=QPJHoA1R; arc=none smtp.client-ip=209.85.219.54 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="QPJHoA1R" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6ce3fc4e58bso5668656d6.0 for ; Thu, 31 Oct 2024 06:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730382199; x=1730986999; 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=OakYK1PNX0QAwWEi796q2AZXJN6/BZIoR2BwFEbcznk=; b=QPJHoA1RTHuPspoA84DEU4UvpXq/aHbB1/pKL2yz5mA6ISiF/BPSEMbPxUaerfvZmp Yan/csuOVPdEjZ5l8JX2H90e/RHGLC88+3eST7Gu4gfp3CVON/1By+6AQSiubIAvnBq2 7o7G6s5zzbhaXFgGfscVuZJf8PGpjPXBbebA0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730382199; x=1730986999; 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=OakYK1PNX0QAwWEi796q2AZXJN6/BZIoR2BwFEbcznk=; b=fP4gsPlebC0WeO2s9kAmJu+G0QVnR5yjuQQHfIpEYDEBAzGnNUssHh78TEC9nY+cQh 3CGvDMlyVOktDQPVX/hYCylKuk/Z1vnjIp2WnoWX8aGWYseGp9NbizpNOjF78MGtIYRj rZUb6juCeqnfvUMXOfTgwFRldM1wH04Ko6JSMLsFsfa/yp3wj+N5JlcoEcAJo8U64z5Y f03wlAZ0FnAJDaCTa+qqyJCTljXwQmFySDQkJcCLc+ZnLkKN3842vlNLUzFIvxQPwr45 DmlBz/KFHuToUzwQ4bJCd6IQQJd3bApo2emNY2hf5tF8T6ZZ7XJlPD/r+uv4P3YjXZwd mlvQ== X-Forwarded-Encrypted: i=1; AJvYcCWHy7UWOHSCw0A4uw5NXp6dnVPYrONrgV7LQgDCEoznCDNrPK7jlddsCffsuzY3hD6khXVtTC7nVXiByw==@vger.kernel.org X-Gm-Message-State: AOJu0YzJoyim2on//IxDmlDgyw2V7y3DjhFY7PknR93NzleFGiYaUycw 7hmB1SfzcPvDFB8qPdX4WLKTcupu6F9qB5cjJTGrox6E3nlWC2WLIj78xYEP4g== X-Google-Smtp-Source: AGHT+IFpQLWpV5A+qH3RHM465CbtXgg+GdcRa4Dne3VABdfXEoRAUwc9lj74kFrk0PTSc6TUVlJpNw== X-Received: by 2002:a05:6214:5c89:b0:6d3:55ee:35d with SMTP id 6a1803df08f44-6d355ee0410mr29414286d6.7.1730382198885; Thu, 31 Oct 2024 06:43:18 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d354177d2fsm7837776d6.107.2024.10.31.06.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 06:43:17 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 31 Oct 2024 13:43:14 +0000 Subject: [PATCH 1/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: <20241031-uvc-subdev-v1-1-a68331cedd72@chromium.org> References: <20241031-uvc-subdev-v1-0-a68331cedd72@chromium.org> In-Reply-To: <20241031-uvc-subdev-v1-0-a68331cedd72@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 , 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 | 107 ++----------------------------------- drivers/media/usb/uvc/uvc_gpio.c | 107 +++++++++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 7 +++ 4 files changed, 119 insertions(+), 105 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 a96f6ca0889f..94fb8e50a50c 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,106 +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->udev->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; -} - -static int uvc_gpio_init_irq(struct uvc_device *dev) -{ - struct uvc_entity *unit = dev->gpio_unit; - - 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); -} - /* ------------------------------------------------------------------------ * 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..5b74131795c5 --- /dev/null +++ b/drivers/media/usb/uvc/uvc_gpio.c @@ -0,0 +1,107 @@ +// 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->udev->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; + + 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); +} + diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 07f9921d83f2..c7519d59d611 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -672,6 +672,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, @@ -816,4 +819,8 @@ 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_init_irq(struct uvc_device *dev); +int uvc_gpio_parse(struct uvc_device *dev); + #endif From patchwork Thu Oct 31 13:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13857945 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 B7B4919F119 for ; Thu, 31 Oct 2024 13:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382204; cv=none; b=AshFpH2OlDTyuB6UiWD1toBEe4Yet6qhnVlK2B0ZaXZdLD7jTDSNtIz3zCNKicxzA32UYRuK93SKpeBV9rjtBHtpIh1RhPbV4SYnb9R/nFL5w1FZTg/zFMV9e9+pu8rftq4G1h0gLslWtPw7iWrzLAKFyYQsBNGAR6lrIviUXJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382204; c=relaxed/simple; bh=o5SZwy+JWp69unv8PlJuuFqc1ODe+O2YZdNzS7VcWDY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CTep7t/EyjtOpcFL8rB1WC3UtMBSMm8aA27iXiN2lgPXVODUsZdN6a2jgcIiQxhBK2rn2VShqO90YbArIwFMM0PDnbcHS+7RNimO+R3NV+KCBtjpc0LJgIwEY+WNH+7B6pv/Jvwp4klENz8CR1IbZNGFig+j0XaxpO4XC5tAle0= 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=hJsYHpkN; arc=none smtp.client-ip=209.85.222.181 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="hJsYHpkN" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b15d330ce1so65903385a.1 for ; Thu, 31 Oct 2024 06:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730382200; x=1730987000; 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=rdTwYT/n8XLy4Tkx8QW4bUUa3rFfFATFk6EQx2or3es=; b=hJsYHpkNsy8dmiAxUdawSPmFZ6ou5Vme0jsDcGuDjyGtXZ/GGpUBboYcDS1os7zB/q oMQUfta0bQwfPFRfXgn1vCyWM63QrQis4rCnm8opZEkvXSqu0L10fiOkhsHk0tCvM8iB S/i4Y12TXE7t6NehwknMBfQ3QI+mHVkCimL4c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730382200; x=1730987000; 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=rdTwYT/n8XLy4Tkx8QW4bUUa3rFfFATFk6EQx2or3es=; b=WFLPC78udoYVnnekBM0GHIKD6CDBZCb6WUAcKFIStLQCCz6JNNvaiAtxR00wxFcUQe aNYE8nazPljW043yu+IqYTVBpKBNeS3owSU6QWnYQJgGT0rgB+MDPLrxpxUs1G0d7ugQ rhT5D+Lx26gcaPybjSCP6uuO/HZxHzmzKw5VJ/Z8fNci5h4kFProduwYItH9xe9K6z5e 8CcevMgyG32YlllcEop1JanOn7+xulLYfAWWqIWz8DtvRR03dHMN1657G/eqflHELCS8 mQx4hyl9i/XzL9NOAC892V2+NpF/b9/hr8RYpgnDmvdyHrVuD2YVXSwovmnsKMVxlHp+ DD3w== X-Forwarded-Encrypted: i=1; AJvYcCWJ7WAUSdtTkwEmyGXsDjlud7FNYaA4Q7BVQfHnUuVm8Ei1mcvNe4a78oe9x5AlnTO8G3WQm2H6UTtUGQ==@vger.kernel.org X-Gm-Message-State: AOJu0YydRdbkyYgV6NGrUi7peDRGKq6NApegOj2TyaCovN4VaB8Og4Kl o4W2M4I4aj1FVGnRijA9hZizHwD0C+Wj5KC8ySaiS9dgyuaGwTQ3M21NjV0fTA== X-Google-Smtp-Source: AGHT+IFuOP0NJ3O68Rs09w04OGn1q9iQGQkF+HFaYsKydi7l8Zy/IZKkdKMMxKMZtUPSgU4T4Lp3dg== X-Received: by 2002:a05:6214:5683:b0:6c7:c5b5:a78d with SMTP id 6a1803df08f44-6d351ac1649mr56293456d6.18.1730382200185; Thu, 31 Oct 2024 06:43:20 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d354177d2fsm7837776d6.107.2024.10.31.06.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 06:43:19 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 31 Oct 2024 13:43:15 +0000 Subject: [PATCH 2/7] media: uvcvideo: reimplement privacy GPIO as a separate subdevice Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-uvc-subdev-v1-2-a68331cedd72@chromium.org> References: <20241031-uvc-subdev-v1-0-a68331cedd72@chromium.org> In-Reply-To: <20241031-uvc-subdev-v1-0-a68331cedd72@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 , Ricardo Ribalda X-Mailer: b4 0.13.0 From: Yunke Cao Reimplement privacy GPIO as a v4l2 subdev with a volatile privacy control. A v4l2 control event is sent in irq when privacy control value changes. The behavior matches the original implementation, except that the control is of a separate subdevice. V4L2 control kAPI is used for simplicity. Signed-off-by: Ricardo Ribalda Signed-off-by: Yunke Cao --- drivers/media/usb/uvc/uvc_ctrl.c | 20 ------- drivers/media/usb/uvc/uvc_driver.c | 5 +- drivers/media/usb/uvc/uvc_entity.c | 6 ++ drivers/media/usb/uvc/uvc_gpio.c | 118 ++++++++++++++++++++++--------------- drivers/media/usb/uvc/uvcvideo.h | 18 +++--- 5 files changed, 92 insertions(+), 75 deletions(-) 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 94fb8e50a50c..8dacb0783eb1 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2169,6 +2169,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); @@ -2180,7 +2181,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); @@ -2207,6 +2208,8 @@ static void uvc_disconnect(struct usb_interface *intf) { struct uvc_device *dev = usb_get_intfdata(intf); + uvc_gpio_cleanup(dev->gpio_unit); + /* * Set the USB interface data to NULL. This can be done outside the * lock, as there's no other reader. 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 5b74131795c5..e02d46ef9566 100644 --- a/drivers/media/usb/uvc/uvc_gpio.c +++ b/drivers/media/usb/uvc/uvc_gpio.c @@ -7,83 +7,66 @@ #include #include +#include #include "uvcvideo.h" -static void uvc_gpio_event(struct uvc_device *dev) +static int uvc_gpio_g_volatile_ctrl(struct v4l2_ctrl *ctrl) { - struct uvc_entity *unit = dev->gpio_unit; - struct uvc_video_chain *chain; - u8 new_val; - - if (!unit) - return; + int ret; + struct uvc_gpio *gpio = + container_of(ctrl->handler, struct uvc_gpio, hdl); - new_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + ret = gpiod_get_value_cansleep(gpio->gpio_privacy); + if (ret < 0) + return ret; - /* 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); + ctrl->cur.val = ret; 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 const struct v4l2_ctrl_ops uvc_gpio_ctrl_ops = { + .g_volatile_ctrl = uvc_gpio_g_volatile_ctrl, +}; static irqreturn_t uvc_gpio_irq(int irq, void *data) { - struct uvc_device *dev = data; + struct uvc_gpio *uvc_gpio = data; + int new_val; + + new_val = gpiod_get_value_cansleep(uvc_gpio->gpio_privacy); + if (new_val < 0) + return IRQ_HANDLED; + + v4l2_ctrl_s_ctrl(uvc_gpio->privacy_ctrl, new_val); - 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->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, - 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,17 +74,58 @@ 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; - 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); + init_val = gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + if (init_val < 0) + return init_val; + + v4l2_ctrl_handler_init(&unit->gpio.hdl, 1); + unit->gpio.privacy_ctrl = v4l2_ctrl_new_std(&unit->gpio.hdl, + &uvc_gpio_ctrl_ops, + V4L2_CID_PRIVACY, + 0, 1, 1, init_val); + if (!unit->gpio.privacy_ctrl) { + ret = unit->gpio.hdl.error; + goto cleanup; + } + + unit->gpio.privacy_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE | + V4L2_CTRL_FLAG_READ_ONLY; + + unit->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | + V4L2_SUBDEV_FL_HAS_EVENTS; + unit->subdev.ctrl_handler = &unit->gpio.hdl; + + ret = v4l2_device_register_subdev_nodes(&dev->vdev); + if (ret) + goto cleanup; + + ret = devm_request_threaded_irq(&dev->intf->dev, unit->gpio.irq, NULL, + uvc_gpio_irq, + IRQF_ONESHOT | IRQF_TRIGGER_FALLING | + IRQF_TRIGGER_RISING, + "uvc_privacy_gpio", &unit->gpio); + if (ret) + goto cleanup; + return 0; + +cleanup: + v4l2_ctrl_handler_free(&unit->gpio.hdl); + return ret; } +void uvc_gpio_cleanup(struct uvc_entity *entity) +{ + if (!entity) + return; + + v4l2_ctrl_handler_free(&entity->gpio.hdl); +} diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index c7519d59d611..1827f4048f5a 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 @@ -171,6 +172,13 @@ struct uvc_control { #define UVC_ENTITY_FLAG_DEFAULT (1 << 0) +struct uvc_gpio { + struct gpio_desc *gpio_privacy; + int irq; + struct v4l2_ctrl_handler hdl; + struct v4l2_ctrl *privacy_ctrl; +}; + struct uvc_entity { struct list_head list; /* Entity as part of a UVC device. */ struct list_head chain; /* Entity as part of a video device chain. */ @@ -229,12 +237,7 @@ struct uvc_entity { u8 *bmControlsType; } extension; - struct { - u8 bControlSize; - u8 *bmControls; - struct gpio_desc *gpio_privacy; - int irq; - } gpio; + struct uvc_gpio gpio; }; u8 bNrInPins; @@ -820,7 +823,8 @@ size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, size_t size); /* gpio */ -int uvc_gpio_init_irq(struct uvc_device *dev); +int uvc_gpio_init(struct uvc_device *dev); int uvc_gpio_parse(struct uvc_device *dev); +void uvc_gpio_cleanup(struct uvc_entity *entity); #endif From patchwork Thu Oct 31 13:43:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13857946 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 B82FF19F41D for ; Thu, 31 Oct 2024 13:43:22 +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=1730382204; cv=none; b=QjV5RgAcjUhJ1/bxXxAYNxk7ScwqASo2C46oXX2FxhU8JoTjQA9jSrnayqy5ROncFrnk/8Fist6CDvlchQYxVyq0bHwXkPPAJzOltLcsoEbzcDcOWXOoNRsQf13+OhaDKALMIt0nEAEGvZzkDZBfjgaVIN/FxJ2yxe78Ms2RH+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382204; c=relaxed/simple; bh=r3cKMGuzvlyf7oZXpFVuSyLONf4V4QntadWBkgpHKW4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pGhsG+skRWaUsL39WiIjp9kyTA4CLmzQjmZRHDa03ltH0g1VKVj56H4Wz51/KfNrGxk91OHaHrlfit9lZ+N4ebXIC0n8pa+umwz6E59hpw7Z5QbEXRzNSVrYVEMAwX3aE2GaG5fT3cgtfNmgxmuUy+pzvT5XI3Af6sp1cBWLiA8= 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=VsGkBYlh; 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="VsGkBYlh" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b175e059bdso62885385a.0 for ; Thu, 31 Oct 2024 06:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730382202; x=1730987002; 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=4hyFrzunuXID7p8XmCUxXoJYk5Y1+TQzbwxm4l0OgWU=; b=VsGkBYlh7Yay80iNsY667lKvYz8v4Rz/pIywqFMfoc7wnpPg1cJyLQyTmJWDJhCDhh HphflXg5eN4TeEhK+3WwrQnarFAKQKXaHdgQuvUzN/jahM517JnlcYBNUYJ/lEIljhjn tR6EzjaHpdLswNkH+uLLgotPLAn5F4qv5oV7Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730382202; x=1730987002; 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=4hyFrzunuXID7p8XmCUxXoJYk5Y1+TQzbwxm4l0OgWU=; b=DNOT8GwVSY+mhHErIEu8WnI2rtZAljS1QvnS05PyV6e2AoJUqmc6VHOCD8YRCGbvwu YBTbTfATh6kDVVB5RvwzJiMxSO4oDweM/sIiRFqL+IN1M+M3FvhkMA1WuhUsYDZJFWbI pL979dpoC8Wyds9WY2qlCUK2WaXaFiIgr/+FL2MrLC0uGqU/Uh4bN9T+IhAAkCXaU+f9 XYZhar5f13MzAu6tEkDtpsshUcA4FFuqerRhK3Jb6l8OzoUqCy5vAiznFtEaxbS8vgwY um98oXKRFr164AGl8AVe9xrmdcZrqTPdbXQYo3JeeYUpikLsxr5Z01c4rXh6pwmNGVwY 8o0A== X-Forwarded-Encrypted: i=1; AJvYcCXb9gAwgdlQ+3tmiSlCPjWadrvNFWUtiZRSu4kWbeh7ahLFboJoMhaIeWdEl4tdQpKbNGJlfY54svHhdw==@vger.kernel.org X-Gm-Message-State: AOJu0YzyaXDGc2YnCBZVrr96iYOwL3pPS4WnbuWlhzkQzlgS3p+T0Yd2 3hHMIqCUPMrjJ8IJDnaqhnmua8CPbM3UyBNcSqkUzUE1L2CvNlKc8lUFe+175Q== X-Google-Smtp-Source: AGHT+IFQBhegKb92TUDsGHpJ1V5uuBp+Av0If9F1wL4bXo0VO6kBdOYFLyoOZMHLmRmjD+urxE18NA== X-Received: by 2002:a05:6214:2c07:b0:6cb:ee38:1bf8 with SMTP id 6a1803df08f44-6d1856b1236mr311999496d6.13.1730382201749; Thu, 31 Oct 2024 06:43:21 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d354177d2fsm7837776d6.107.2024.10.31.06.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 06:43:20 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 31 Oct 2024 13:43:16 +0000 Subject: [PATCH 3/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: <20241031-uvc-subdev-v1-3-a68331cedd72@chromium.org> References: <20241031-uvc-subdev-v1-0-a68331cedd72@chromium.org> In-Reply-To: <20241031-uvc-subdev-v1-0-a68331cedd72@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 , Ricardo Ribalda X-Mailer: b4 0.13.0 With the privacy gpio now handled as a subdevice, 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 1827f4048f5a..37991d35088c 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -243,11 +243,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 Thu Oct 31 13:43:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13857947 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (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 A1E8019FA93 for ; Thu, 31 Oct 2024 13:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382205; cv=none; b=jIa0ySD0YN4DGy85oXxuYfJsfaUQLDrtuAe7bpZxBTzZTZgV97pE2TS4wJ5e/x9pSgHfpCcqiLmHP0aLQvBUCD1vXCtI4+HpXm7IW09JpJ+i30MPpfmYidhJg37EWmcL3LV27vSjjbEzDMv8qGe9v6/C9VR6r0Z8a6IVy4L84Yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382205; c=relaxed/simple; bh=Cmze8r3g0v2icURj4HJAeixp7Fu1vBhNkAGZdpuZMkc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TQJQLLK5P/P+VN8e5w6P007jWQ9J5MaMy11Q5+sC1jSiZ+MSeC+vToTQMqVFRlNwiOJn6jHpQQCvlo9Vq3CO8rKVhIZ81Dc59GsliSM8W1W64F4n7nljSn9neuFQPk991lU2Tb0Pgn7szx9o7kyDf1ok7Tzll59shyO4dxYAxYk= 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=Zni4pja9; arc=none smtp.client-ip=209.85.219.48 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="Zni4pja9" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6cc250bbc9eso6523296d6.2 for ; Thu, 31 Oct 2024 06:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730382202; x=1730987002; 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=zJ+e6C6+GSrAnIb1/5IVMUrH4LpoM+FfmfvDlsPOksU=; b=Zni4pja99y5+L1/OLEQsfYmP7JwhYxDiqM+kGxWE/2Rfv/cZu1EwazYLQf/oDSZrem im1kgRxCpnUcdROvQK7k3ii7O1uFIGCeL4OCD01lCeueMWLCZ9AvTJCXD+uTX9TCLViZ 6XMKjGazx5TtsLW5DJKooqeJffcOKE/oSSEfQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730382202; x=1730987002; 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=zJ+e6C6+GSrAnIb1/5IVMUrH4LpoM+FfmfvDlsPOksU=; b=mV/dhJ2BEvNGcOrDIeXJsmlF79lhePsQWT0DHwFXyE2YEwVpCSkJpbfBHOq7Han6Z7 Ew1MX2qImNToSFkwfHFBnKtEy/qNB+MIp1Y04uQbxvZXhr2vHC4gIM9ZzSjXVzDCwJa8 IuNtK4zytpR43HAt9H6SKN/7pYuttQv2F5p7Gus/B+PFsnondgUHcndZq6mgwWte+VA8 O7Kt+46fRKD4MYdVGEcLFLK4Sf08lab8silLAxhecTlRSp5isVbxXh5JijeVTApLRAxH cFSC28ppS/m0XuuqxPCqtaD9BDtutrqDyow940AVUi+3fVDY/RiMkedxJHtSUT62GHZ1 VIvA== X-Forwarded-Encrypted: i=1; AJvYcCXK9qxrxNcBFVDqB4sG9oxQJ0EzimjJMtYRMYzugb7X6r77v7Qh8Swl2w5wX+PD9JGUJQy2I4rcTjyWSA==@vger.kernel.org X-Gm-Message-State: AOJu0YzrbljeNR7ATRQkVLAqyfPPtfcfk7G/+lSp5k7FDJ/GCYjTrsJS KL6DVlKkvj491OkjAJBtntApRiL/KQBLROsdmS1bqVMOjP0G7Swc2yE15/GTSQ== X-Google-Smtp-Source: AGHT+IFYV2lrgriqNv8NBVIjXACfwQqoXY3hpb9ZeqjxeP58kyKKudAiPp5NbglODhq91Oqx814v8g== X-Received: by 2002:a05:6214:590c:b0:6cd:ef7a:8c82 with SMTP id 6a1803df08f44-6d351b24ffemr20012896d6.41.1730382202571; Thu, 31 Oct 2024 06:43:22 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d354177d2fsm7837776d6.107.2024.10.31.06.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 06:43:22 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 31 Oct 2024 13:43:17 +0000 Subject: [PATCH 4/7] media: uvcvideo: Create ancillary link for GPIO subdevice Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-uvc-subdev-v1-4-a68331cedd72@chromium.org> References: <20241031-uvc-subdev-v1-0-a68331cedd72@chromium.org> In-Reply-To: <20241031-uvc-subdev-v1-0-a68331cedd72@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 , Ricardo Ribalda X-Mailer: b4 0.13.0 Make an ancillary device between the streaming subdevice and the GPIO subdevice. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_entity.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c index c1b69f9eaa56..dad77b96fe16 100644 --- a/drivers/media/usb/uvc/uvc_entity.c +++ b/drivers/media/usb/uvc/uvc_entity.c @@ -53,6 +53,16 @@ static int uvc_mc_create_links(struct uvc_video_chain *chain, return ret; } + /* Create ancillary link for the GPIO. */ + if (chain->dev->gpio_unit && UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) { + struct media_link *link; + + link = media_create_ancillary_link(sink, + &chain->dev->gpio_unit->subdev.entity); + if (IS_ERR(link)) + return PTR_ERR(link); + } + return 0; } From patchwork Thu Oct 31 13:43:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13857948 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 016871A0730 for ; Thu, 31 Oct 2024 13:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382207; cv=none; b=XQQMe33hYsDtssZQ5DxaQVYHUkXsLHzA7tG9oTxMmRmi6z6CystcI6wHo2GeJRyFwmSaCT3JAbFaqmoubvEkQNZIJfeGE96VhGkZMAqG2OdgmJLvqEI5NM/h6sgkdtADUX7ynGQw/dAehMNAPBu9Uw92tMHCn/LBDN3W0ZDS2a4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382207; c=relaxed/simple; bh=kmfBVkJEZgyP7qLVgVd5KbUMONRw5aQJxZxokPMJLFw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GtGR/KOVmhwNMnTUFVpQ5wEObcACd3Z3Xawwmq4JMkMl99mZ3qiddfTIbGm4Bx0qS/+rgPtEhARqvp22Qtru5lMAF9Zg+RFz+AcnoruLIAvlDEqwjm6Qgih4eD5m8JDHWb3Mm1O+kOOYcTy6S20CWBf7el84Mb5Ie3lspARAKq8= 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=H7SpPBNg; arc=none smtp.client-ip=209.85.219.54 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="H7SpPBNg" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6cbcc2bd800so8450386d6.0 for ; Thu, 31 Oct 2024 06:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730382204; x=1730987004; 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=3GhYJZf/q/jt/6wnYwOt5+9I5pH5dgpUegwqN2iEcvw=; b=H7SpPBNgU9TMsu+zXHXWO3Qn+HKDCYZHa+XodK716h2FkncDYixA9DyQxD7W6/oA32 9A2asQZnYxycd2mj7Jrhmlxfu+6637A3DOs6WpiIWr5YY9+Qrwj2SjGLDJWJxLnT3M1r Hm4Puv77K9b2IuHyjmz3uFOT4FqFG9xvgLLmY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730382204; x=1730987004; 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=3GhYJZf/q/jt/6wnYwOt5+9I5pH5dgpUegwqN2iEcvw=; b=DIBwb4enWI/Kk/+ozpHPkctpCUATc+2LVMyxSw84GwDGNHb+SFjF5zwBvlFjip0Bww Bf50hNVagyGHnm2jpENs80lZ3Od/1tz9Bia/0Bn6POwIASkE3zWTh05WN4CfVN+207sl CiSqr3/yxinL46ISksi+dp587qfi4+ZGbynWWflF7/PJ2VmkKJ9cJFkG9eEl1dmjJguT u3A7RnUTA/+iSWvPm+rFjkzroJwdFcCaolk47fBzLkPpmB7fC9yeND4Q96RdMuPjETUe CWhGwrvl76+x3T+aNk0IuictPqUQiAduh7SKGp5MPzfWQ7voZagr1hwV1VlrMQ5udXZO az/Q== X-Forwarded-Encrypted: i=1; AJvYcCVhytG2ZVuplFPLcad2Y4xER5RrvzfIqIjz7p+K1asM/1dd6HbWch5Iap1Pt32GtXc6oyJAs1HxnJ3wUw==@vger.kernel.org X-Gm-Message-State: AOJu0Yx4IPSiFKjAl0slpckohVbHclAs2fvykxWzD/lsWgjAiDQ0JevJ PpbDKbUVm7VmE3Y8jJQs1q3ovJbD3H8Zr9exZb0vIrcoSBHvFqNXO1O5VOSGsA== X-Google-Smtp-Source: AGHT+IEpMT1+deQAzIFiMeh++cnIKQpHIxRIybIRfqhA/h9vWt47DlYMoffk71eSJSfu2319SnPmfQ== X-Received: by 2002:a05:6214:3f92:b0:6cd:efb4:2efe with SMTP id 6a1803df08f44-6d354318a30mr44058766d6.24.1730382204026; Thu, 31 Oct 2024 06:43:24 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d354177d2fsm7837776d6.107.2024.10.31.06.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 06:43:22 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 31 Oct 2024 13:43:18 +0000 Subject: [PATCH 5/7] 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: <20241031-uvc-subdev-v1-5-a68331cedd72@chromium.org> References: <20241031-uvc-subdev-v1-0-a68331cedd72@chromium.org> In-Reply-To: <20241031-uvc-subdev-v1-0-a68331cedd72@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 , 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..62fc4691923b 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 + 4) /* * Digital TV, analog TV, radio and/or software defined radio tuner functions. From patchwork Thu Oct 31 13:43:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13857949 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 E74551A254F for ; Thu, 31 Oct 2024 13:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382208; cv=none; b=h2NP2FpOgkUyHtsrouushD7wVhnzqJi1/imnTaKcTKX0ESCPttx6tWBmGP8N6LKv5xKlfAHej28WGuGEsOmo3Hy+poSLQxsCGyToEAHx4fllD7oXnBY7/TeWrnIBbAlOpDc3Sr1cNXlH4cUhFxd5dtzXL4WPSwFildFQIt+DFts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382208; c=relaxed/simple; bh=blJa50xw0lKvopXaZAiEuV1VgzhB5oNeTs67sGqviXE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nGnSxcm6fRp9fpsGFy/fBW01wIc4L5ZgAdiZ4e+OKzeEOeTYnivEqR3xveohzl6S+lFXMTnZpjjBDDgAoszrO423sOXqaqGfrcrIfeW79nJtztOUodSrWm2tXIsjFXulLVqbqiblA0WfbOcFN1C+qRq/e5hQAqlwToLc8sG3Kw0= 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=Duepzyif; arc=none smtp.client-ip=209.85.222.171 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="Duepzyif" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7b1467af9dbso64963185a.0 for ; Thu, 31 Oct 2024 06:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730382205; x=1730987005; 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=daIxjktyxuG2VDq53N9YeRfidBwsAYBDLHTz0c0/NdA=; b=DuepzyifCKYIt2owSji5xtsnqHJL8zeESEqtekpBWyqEN1G56Vub10z3rSZi/WkqAX 4QTzhUTd1ufhJ/Yjp3f5E2cY1UpwYcDJM9EKmXA3KBLyxn47x88wgBSVQNpiWbWh4RSh XEsvoMotnO+HNJ2cTMeXuavr2z6lUeH1hE+yM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730382205; x=1730987005; 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=daIxjktyxuG2VDq53N9YeRfidBwsAYBDLHTz0c0/NdA=; b=hd2O9VfWIJosVIv1GdJ4FTky5yttVDaemytYTAMuV3vyj5c9Zgisx0yeE8ufV6qGxe PTo6KxagkyOAB68BVKpsxBcAe/VZa/TXgeKiBQHxGXBTbgoHOdkiID+dLBFwzdDoFuz0 2C4JtTz1Vs/sQsaNn6bLVhicD8a4YF308CCioMLrmLayovC5G+q/rqxFnqj15YMf9ojD f2DdRhkRFmsU2wi/b2/SCLchrCIQ3Ak6b64zVpIHDzh60M7gCDzbB33eyFTjoHX9hjwd YKlA3Wc9hBy0z01INQ67DUXq1OHwkmcbyeJ8rLq5baH4jMa0XwurkXACvPLCFgsJRopW vjWw== X-Forwarded-Encrypted: i=1; AJvYcCUjvTwtR9pHAbPl/htwl/CoDJh0IrUz1moCYbhaoQPRR0w34TbvnLU0zh2fKKchhtK706y33DUkVrOvbA==@vger.kernel.org X-Gm-Message-State: AOJu0YwRloveDFCnJNXx9stIwquBi6/D2IMdN4Ej37V8YsQq8kkz29YG WB6OJ2fso09QC077ChGvH5asSVkP02oiUrJtE5tjr37eafZ3y1IenNFMuwICNQ== X-Google-Smtp-Source: AGHT+IG7Pr+EQGs4svOdqXUCFGOmSkeTMmvCRbqYTY2HIOLnsdesNRsmZ1TW0g4y8DD6bLq9qYnE3A== X-Received: by 2002:a05:6214:3bc9:b0:6cd:eeb4:4f73 with SMTP id 6a1803df08f44-6d345fc8799mr93692756d6.14.1730382204713; Thu, 31 Oct 2024 06:43:24 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d354177d2fsm7837776d6.107.2024.10.31.06.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 06:43:24 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 31 Oct 2024 13:43:19 +0000 Subject: [PATCH 6/7] media: uvcvideo: Use MEDIA_ENT_F_GPIO for the GPIO entity Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-uvc-subdev-v1-6-a68331cedd72@chromium.org> References: <20241031-uvc-subdev-v1-0-a68331cedd72@chromium.org> In-Reply-To: <20241031-uvc-subdev-v1-0-a68331cedd72@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 , Ricardo Ribalda X-Mailer: b4 0.13.0 Right now we are setting the entity type to unknown for the privacy GPIO entity. Which results in the following error in dmesg. uvcvideo 3-6:1.0: Entity type for entity GPIO was not initialized! Use the newly created type to fix this. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_entity.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c index dad77b96fe16..3cb95df1f670 100644 --- a/drivers/media/usb/uvc/uvc_entity.c +++ b/drivers/media/usb/uvc/uvc_entity.c @@ -114,6 +114,9 @@ static int uvc_mc_init_entity(struct uvc_video_chain *chain, case UVC_ITT_CAMERA: function = MEDIA_ENT_F_CAM_SENSOR; break; + case UVC_EXT_GPIO_UNIT: + function = MEDIA_ENT_F_GPIO; + break; case UVC_TT_VENDOR_SPECIFIC: case UVC_ITT_VENDOR_SPECIFIC: case UVC_ITT_MEDIA_TRANSPORT_INPUT: @@ -121,7 +124,6 @@ static int uvc_mc_init_entity(struct uvc_video_chain *chain, case UVC_OTT_DISPLAY: case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: case UVC_EXTERNAL_VENDOR_SPECIFIC: - case UVC_EXT_GPIO_UNIT: default: function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN; break; From patchwork Thu Oct 31 13:43:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13857950 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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 1E6F019F105 for ; Thu, 31 Oct 2024 13:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382210; cv=none; b=IcwgoRc1HRA8e6G8oMTmlZVQL4Mjchyx7vDtjNdg/bLCBGIJO6BTboLoCdPagQvn4ixgbBKPXIqz31qRv6D8KTVSbwpJbOKJnsnzZKSJ9GsyThL7CJfFB1Eg0wIB7YJc6P/RPwpyxcdKxk5klS/0FjyPa9f8UN7YRmBwYKQdNP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382210; c=relaxed/simple; bh=XAuQri7r83r7UrrPiZpMw36VK0lmC8P7Lm6jAuq7hQY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CNvWogtuJHXm6a/AomXyP85AdHfAHCn2ySdKeaUbzbOhhjQe3u7vuAfJ5X30Vo+XswQMzBxamd86ZdKx9HhArGtA4RgoosTvGny8wECJBGq423lzHDj5gAv9hGIlEcTOdZlEK2vCOtSaWYBdSlwyZVwG3FRHgjW8sSF9o/QZJXY= 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=k4cRaQxm; arc=none smtp.client-ip=209.85.222.175 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="k4cRaQxm" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7b14077ec5aso186237185a.1 for ; Thu, 31 Oct 2024 06:43:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730382206; x=1730987006; 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=mdfYX4pDnMcuiGGGMc2I3sYePXU0/ipv/UNJ6CbzEgg=; b=k4cRaQxmvi/ZmxaVNGduwSHBPClLr91T6DsldnxXYcTfh9BCQpcIEx2GCgaXI/sAg/ YCw/ovUSLm5vhxMUUWjahJVkaDKPeRdXW6Lxz/2kr4BNtYRrBk51apqKDFJ1HVrTsQ9i LJdGC5Pbkg18ySyp41yAZSwNsKmNCRHDyViUw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730382206; x=1730987006; 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=mdfYX4pDnMcuiGGGMc2I3sYePXU0/ipv/UNJ6CbzEgg=; b=FT2zBBdZH0KSRyv/q+3K92XFF9XY+Jey5DmYBAUD4RvzJtZekD8rGIj1RyFieZD8Tp TxSJYz/T9VJ0uf7ZgXgDFvTc2Ig1T9URLgKuDDxL2y60HdVq4nuFTlHrwZpdCLX3AJq7 d/atIcUIwwUEW2wBmrQg5aADQP2XHmdinPNtyPkUbJQvL/i4CLyJD4P/ad9sP2xSMtMR MjJMYHj+Z7vNSCps78sm6U3ORbTaNFLi4w4611TNbyFiluB1xGBZD22oV5+/96SJRPbM l2tVAk+iJVpX3iMm0s+OUzgJzDKKpcAd+OouayBJijKM1BVsn+AHjckPtyzQ+XcG9T1a 6QXA== X-Forwarded-Encrypted: i=1; AJvYcCUA1kJhh848C/JbzOJvobMBHweJrr3qOGkTBir3+SwHY8wIi11y+v1vcNWNcjYqnqCOgkw8AvaoDU3Yrw==@vger.kernel.org X-Gm-Message-State: AOJu0YyPp5jZvc5jLd9yO2w0AZ3Y3GUfvMOIPB0ckXYMorw7fLikjp4R lrN3uWvMPmlEFPqqHuO4JbvQVyfDlyJl2ttu0AKk3KHi/v13SwvZPrxnUUzs5g== X-Google-Smtp-Source: AGHT+IFVLV7yvPMMB7uMkf5gM87MCX9H9id1mCqPzY7DKuqs39zQEJrBzuTMVcPV3lfquCXZJIgu3g== X-Received: by 2002:a05:6214:1308:b0:6cb:c845:ed0f with SMTP id 6a1803df08f44-6d35b9529afmr402756d6.17.1730382206036; Thu, 31 Oct 2024 06:43:26 -0700 (PDT) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d354177d2fsm7837776d6.107.2024.10.31.06.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 06:43:25 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 31 Oct 2024 13:43:20 +0000 Subject: [PATCH 7/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: <20241031-uvc-subdev-v1-7-a68331cedd72@chromium.org> References: <20241031-uvc-subdev-v1-0-a68331cedd72@chromium.org> In-Reply-To: <20241031-uvc-subdev-v1-0-a68331cedd72@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 , 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 | 47 +++++++++++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_video.c | 4 ++++ drivers/media/usb/uvc/uvcvideo.h | 7 ++++-- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_gpio.c b/drivers/media/usb/uvc/uvc_gpio.c index e02d46ef9566..b49a7fbd5adf 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 int uvc_gpio_g_volatile_ctrl(struct v4l2_ctrl *ctrl) struct uvc_gpio *gpio = container_of(ctrl->handler, struct uvc_gpio, hdl); + if (!gpio->gpio_ready) + return -EBUSY; + ret = gpiod_get_value_cansleep(gpio->gpio_privacy); if (ret < 0) return ret; @@ -43,6 +47,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; @@ -64,6 +86,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)); @@ -74,6 +105,20 @@ 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) { + enable_irq(dev->gpio_unit->gpio.irq); + uvc_gpio_irq(0, &dev->gpio_unit->gpio); + } else { + disable_irq(dev->gpio_unit->gpio.irq); + } +} + int uvc_gpio_init(struct uvc_device *dev) { struct uvc_entity *unit = dev->gpio_unit; @@ -97,6 +142,8 @@ int uvc_gpio_init(struct uvc_device *dev) goto cleanup; } + uvc_gpio_quirk(dev, false); + unit->gpio.privacy_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY; 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 37991d35088c..f154cb2932a0 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 @@ -173,10 +174,11 @@ struct uvc_control { #define UVC_ENTITY_FLAG_DEFAULT (1 << 0) struct uvc_gpio { - struct gpio_desc *gpio_privacy; + bool gpio_ready; int irq; - struct v4l2_ctrl_handler hdl; struct v4l2_ctrl *privacy_ctrl; + struct v4l2_ctrl_handler hdl; + struct gpio_desc *gpio_privacy; }; struct uvc_entity { @@ -821,5 +823,6 @@ size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, int uvc_gpio_init(struct uvc_device *dev); int uvc_gpio_parse(struct uvc_device *dev); void uvc_gpio_cleanup(struct uvc_entity *entity); +void uvc_gpio_quirk(struct uvc_device *dev, bool stream_on); #endif