From nobody Mon Nov 25 00:26:34 2024 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (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 05ED419E96B for ; Thu, 31 Oct 2024 13:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382203; cv=none; b=DSUAXi4r+KuPjhCXwRabP6D7ezLj8GkYeyRqmni498hpgRqjVI4e3CdqK2qLSSjgZg86di6ynq56AkrroQdcIzQZ/qvDD42+EbCtxfak5Mt1rxR8QqWtnvOiO/U97sxE7LWgO09CB9o1zw2gEXa2b4cI/rx0HWwHFvG6FoYTgiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382203; c=relaxed/simple; bh=MFSbzsC4qpSDjJpQBpgnBMJ9pfWpXmfF9LukJr0n+kU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kxDcIzL46c5yZxtxfTH4L3PJ3YjkBPajBNm3pS2VPTtkvAIQAhGboD8sE9WCSUpNLMfOnK6qW58okLgekw4hRdsCFkRuCS44Fl+K80oB3M1Gq90v+8C6F17Oek8NvO/+pvKKFXOAxqIoJH4RXUE0Ae/BKVEyD0vjB/Re7JlYcvY= 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.42 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-f42.google.com with SMTP id 6a1803df08f44-6cbe68f787dso5660056d6.2 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=qTDmO5OyfceBdUk3gZNEOEBvvuk7ikL33Ku5RYQhfK77VlVdjfQvOwN3PhGagJod0N DhQmQXkwwLnV+pJibEV3UobexBhUgYi4OSU/pxjfgbJGhxCCXs03ys+YHJpJEyxEcr83 pV1tWcHja9/+RnO6yOl5/GxUvAxA+adNjg39xUJiL9reSB5NNJZVTKZg73EnF3KBiqP0 yQ8SOeptiKUgzveP1YTIwIVUwcdiRuC1JV6N5D5Qcp/VO+YP8AiDiPXN6ja3Kp6+ZBP2 hXN5GD3HIkeRTMDsAeJOxfWJIFO0ugvM7Flk4JLbSubJVBJRLCOKgcYlxYHqrkW01hIk 94Ew== X-Gm-Message-State: AOJu0YyYtnnSolNVIc3kBfL0CMWorM0rXFTR1i2hlM8iQUAyrgTtKWpV FzK9u2In6qFk87xOoEialzpf5rv7WQOIwXEbPSz8nCusjvZi8v3WrZwI5yJTWmzlAF5/VEDcD0I = 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 :=3D uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ct= rl.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 +=3D 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 @@ =20 #include #include -#include #include #include #include @@ -775,9 +774,9 @@ static const u8 uvc_media_transport_input_guid[16] =3D UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; static const u8 uvc_processing_guid[16] =3D UVC_GUID_UVC_PROCESSING; =20 -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; } =20 -/* -----------------------------------------------------------------------= ------ - * Privacy GPIO - */ - -static void uvc_gpio_event(struct uvc_device *dev) -{ - struct uvc_entity *unit =3D dev->gpio_unit; - struct uvc_video_chain *chain; - u8 new_val; - - if (!unit) - return; - - new_val =3D gpiod_get_value_cansleep(unit->gpio.gpio_privacy); - - /* GPIO entities are always on the first chain. */ - chain =3D 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 *ent= ity, - u8 cs, void *data, u16 size) -{ - if (cs !=3D UVC_CT_PRIVACY_CONTROL || size < 1) - return -EINVAL; - - *(u8 *)data =3D gpiod_get_value_cansleep(entity->gpio.gpio_privacy); - - return 0; -} - -static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *en= tity, - u8 cs, u8 *caps) -{ - if (cs !=3D UVC_CT_PRIVACY_CONTROL) - return -EINVAL; - - *caps =3D UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; - return 0; -} - -static irqreturn_t uvc_gpio_irq(int irq, void *data) -{ - struct uvc_device *dev =3D 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 =3D 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 =3D gpiod_to_irq(gpio_privacy); - if (irq < 0) - return dev_err_probe(&dev->udev->dev, irq, - "No IRQ for privacy GPIO\n"); - - unit =3D 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 =3D gpio_privacy; - unit->gpio.irq =3D irq; - unit->gpio.bControlSize =3D 1; - unit->gpio.bmControls =3D (u8 *)unit + sizeof(*unit); - unit->gpio.bmControls[0] =3D 1; - unit->get_cur =3D uvc_gpio_get_cur; - unit->get_info =3D uvc_gpio_get_info; - strscpy(unit->name, "GPIO", sizeof(unit->name)); - - list_add_tail(&unit->list, &dev->entities); - - dev->gpio_unit =3D unit; - - return 0; -} - -static int uvc_gpio_init_irq(struct uvc_device *dev) -{ - struct uvc_entity *unit =3D 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_g= pio.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 =3D dev->gpio_unit; + struct uvc_video_chain *chain; + u8 new_val; + + if (!unit) + return; + + new_val =3D gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + + /* GPIO entities are always on the first chain. */ + chain =3D 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 *ent= ity, + u8 cs, void *data, u16 size) +{ + if (cs !=3D UVC_CT_PRIVACY_CONTROL || size < 1) + return -EINVAL; + + *(u8 *)data =3D gpiod_get_value_cansleep(entity->gpio.gpio_privacy); + + return 0; +} + +static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *en= tity, + u8 cs, u8 *caps) +{ + if (cs !=3D UVC_CT_PRIVACY_CONTROL) + return -EINVAL; + + *caps =3D UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; + return 0; +} + +static irqreturn_t uvc_gpio_irq(int irq, void *data) +{ + struct uvc_device *dev =3D 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 =3D 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 =3D gpiod_to_irq(gpio_privacy); + if (irq < 0) + return dev_err_probe(&dev->udev->dev, irq, + "No IRQ for privacy GPIO\n"); + + unit =3D 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 =3D gpio_privacy; + unit->gpio.irq =3D irq; + unit->gpio.bControlSize =3D 1; + unit->gpio.bmControls =3D (u8 *)unit + sizeof(*unit); + unit->gpio.bmControls[0] =3D 1; + unit->get_cur =3D uvc_gpio_get_cur; + unit->get_info =3D uvc_gpio_get_info; + strscpy(unit->name, "GPIO", sizeof(unit->name)); + + list_add_tail(&unit->list, &dev->entities); + + dev->gpio_unit =3D unit; + + return 0; +} + +int uvc_gpio_init_irq(struct uvc_device *dev) +{ + struct uvc_entity *unit =3D 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/uvcvi= deo.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; =20 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); =20 /* 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 *s= tream); size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf, size_t size); =20 +/* gpio */ +int uvc_gpio_init_irq(struct uvc_device *dev); +int uvc_gpio_parse(struct uvc_device *dev); + #endif --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 00:26:34 2024 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 A19FC19F110 for ; Thu, 31 Oct 2024 13:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382204; cv=none; b=cNbcfmL3q/c3rRHDfzfRcy6ErB5EgQLugIfSwfX6MJ+Fu/PdpfiZO+FFJjc1CFlDDykMEk6TJ/mCfP0UkDBFTAOejA/7ybO2ECoEaJBXpyk4XlPHB5cnEQa3l+aJGWl/Pi2WP+z/QoJP0n8mx3nAIrpKKijN4lIHffMzDMUyOpE= 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.174 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-f174.google.com with SMTP id af79cd13be357-7b1474b1377so65009785a.2 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=NjP2xsyj78GWoOY21eNHqtA6jBmCXyDSs6CTBqbwhceIvB4y2C8JxyLWcTeGzCnCMK ZcTiIoCMGchNwx0ogWr8LCQwH6pKH48Ra9r1WoZWO/mQO+uV0e1vcwAm6N1XNGsb9Y+R FMksJ15heG8q0pckaNAW5DgvhaoNRk6WPdqGkZ8eSAvmmKMpPqcUSTA8QSLm+sa0GV3S i23Epk/GhBisCOBoUEWli8kdloGIJYXEBosAjJU9o8fl7mLj+kWniqBwPUpLcmq0Bd3H U6A9BNukgB640M8xzErouQzhOiqqO9XosGOJbMTi22xuwYEgXTa5O0gzwGGJMhYFhRgO Bidw== X-Gm-Message-State: AOJu0Yxd39EZ8jjnefLauvRhfo3RIVIWnrJWcqSFBXyGMlCIIqfxrzK+ FUHdHVz2Aw2XJfQXcmeBDsADGzxapqTiWh+Zm1jb7KO4aTBwvI/zE2iTRHorxg== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_c= trl.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[] =3D { | UVC_CTRL_FLAG_RESTORE | UVC_CTRL_FLAG_AUTO_UPDATE, }, - { - .entity =3D UVC_GUID_EXT_GPIO_CONTROLLER, - .selector =3D UVC_CT_PRIVACY_CONTROL, - .index =3D 0, - .size =3D 1, - .flags =3D UVC_CTRL_FLAG_GET_CUR - | UVC_CTRL_FLAG_AUTO_UPDATE, - }, }; =20 static const u32 uvc_control_classes[] =3D { @@ -827,15 +819,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappi= ngs[] =3D { .v4l2_type =3D V4L2_CTRL_TYPE_BOOLEAN, .data_type =3D UVC_CTRL_DATA_TYPE_BOOLEAN, }, - { - .id =3D V4L2_CID_PRIVACY, - .entity =3D UVC_GUID_EXT_GPIO_CONTROLLER, - .selector =3D UVC_CT_PRIVACY_CONTROL, - .size =3D 1, - .offset =3D 0, - .v4l2_type =3D V4L2_CTRL_TYPE_BOOLEAN, - .data_type =3D UVC_CTRL_DATA_TYPE_BOOLEAN, - }, { .entity =3D UVC_GUID_UVC_PROCESSING, .selector =3D 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) =3D=3D UVC_ITT_CAMERA) { bmControls =3D entity->camera.bmControls; bControlSize =3D entity->camera.bControlSize; - } else if (UVC_ENTITY_TYPE(entity) =3D=3D UVC_EXT_GPIO_UNIT) { - bmControls =3D entity->gpio.bmControls; - bControlSize =3D entity->gpio.bControlSize; } =20 /* 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); =20 @@ -2180,7 +2181,7 @@ static int uvc_probe(struct usb_interface *intf, ret); } =20 - ret =3D uvc_gpio_init_irq(dev); + ret =3D 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 =3D usb_get_intfdata(intf); =20 + 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 *c= hain, return 0; } =20 +static const struct v4l2_subdev_core_ops uvc_subdev_core_ops =3D { + .subscribe_event =3D v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event =3D v4l2_event_subdev_unsubscribe, +}; + static const struct v4l2_subdev_ops uvc_subdev_ops =3D { + .core =3D &uvc_subdev_core_ops, }; =20 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_g= pio.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 @@ =20 #include #include +#include #include "uvcvideo.h" =20 -static void uvc_gpio_event(struct uvc_device *dev) +static int uvc_gpio_g_volatile_ctrl(struct v4l2_ctrl *ctrl) { - struct uvc_entity *unit =3D dev->gpio_unit; - struct uvc_video_chain *chain; - u8 new_val; - - if (!unit) - return; + int ret; + struct uvc_gpio *gpio =3D + container_of(ctrl->handler, struct uvc_gpio, hdl); =20 - new_val =3D gpiod_get_value_cansleep(unit->gpio.gpio_privacy); + ret =3D gpiod_get_value_cansleep(gpio->gpio_privacy); + if (ret < 0) + return ret; =20 - /* GPIO entities are always on the first chain. */ - chain =3D 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 *ent= ity, - u8 cs, void *data, u16 size) -{ - if (cs !=3D UVC_CT_PRIVACY_CONTROL || size < 1) - return -EINVAL; - - *(u8 *)data =3D gpiod_get_value_cansleep(entity->gpio.gpio_privacy); + ctrl->cur.val =3D ret; =20 return 0; } =20 -static int uvc_gpio_get_info(struct uvc_device *dev, struct uvc_entity *en= tity, - u8 cs, u8 *caps) -{ - if (cs !=3D UVC_CT_PRIVACY_CONTROL) - return -EINVAL; - - *caps =3D UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; - return 0; -} +static const struct v4l2_ctrl_ops uvc_gpio_ctrl_ops =3D { + .g_volatile_ctrl =3D uvc_gpio_g_volatile_ctrl, +}; =20 static irqreturn_t uvc_gpio_irq(int irq, void *data) { - struct uvc_device *dev =3D data; + struct uvc_gpio *uvc_gpio =3D data; + int new_val; + + new_val =3D 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); =20 - uvc_gpio_event(dev); return IRQ_HANDLED; } =20 int uvc_gpio_parse(struct uvc_device *dev) { - struct uvc_entity *unit; struct gpio_desc *gpio_privacy; + struct uvc_entity *unit; int irq; =20 - gpio_privacy =3D devm_gpiod_get_optional(&dev->udev->dev, "privacy", + gpio_privacy =3D devm_gpiod_get_optional(&dev->intf->dev, "privacy", GPIOD_IN); if (IS_ERR_OR_NULL(gpio_privacy)) return PTR_ERR_OR_ZERO(gpio_privacy); =20 irq =3D 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"); =20 unit =3D 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); =20 unit->gpio.gpio_privacy =3D gpio_privacy; unit->gpio.irq =3D irq; - unit->gpio.bControlSize =3D 1; - unit->gpio.bmControls =3D (u8 *)unit + sizeof(*unit); - unit->gpio.bmControls[0] =3D 1; - unit->get_cur =3D uvc_gpio_get_cur; - unit->get_info =3D uvc_gpio_get_info; strscpy(unit->name, "GPIO", sizeof(unit->name)); - list_add_tail(&unit->list, &dev->entities); =20 dev->gpio_unit =3D unit; @@ -91,17 +74,58 @@ int uvc_gpio_parse(struct uvc_device *dev) return 0; } =20 -int uvc_gpio_init_irq(struct uvc_device *dev) +int uvc_gpio_init(struct uvc_device *dev) { struct uvc_entity *unit =3D dev->gpio_unit; + int init_val; + int ret; =20 if (!unit || unit->gpio.irq < 0) return 0; =20 - 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 =3D 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 =3D 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 =3D unit->gpio.hdl.error; + goto cleanup; + } + + unit->gpio.privacy_ctrl->flags |=3D V4L2_CTRL_FLAG_VOLATILE | + V4L2_CTRL_FLAG_READ_ONLY; + + unit->subdev.flags |=3D V4L2_SUBDEV_FL_HAS_DEVNODE | + V4L2_SUBDEV_FL_HAS_EVENTS; + unit->subdev.ctrl_handler =3D &unit->gpio.hdl; + + ret =3D v4l2_device_register_subdev_nodes(&dev->vdev); + if (ret) + goto cleanup; + + ret =3D 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; } =20 +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/uvcvi= deo.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 { =20 #define UVC_ENTITY_FLAG_DEFAULT (1 << 0) =20 +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; =20 - struct { - u8 bControlSize; - u8 *bmControls; - struct gpio_desc *gpio_privacy; - int irq; - } gpio; + struct uvc_gpio gpio; }; =20 u8 bNrInPins; @@ -820,7 +823,8 @@ size_t uvc_video_stats_dump(struct uvc_streaming *strea= m, char *buf, size_t size); =20 /* 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); =20 #endif --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 00:26:34 2024 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (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 C3CA919F423 for ; Thu, 31 Oct 2024 13:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382204; cv=none; b=sC4jtFAWyagCVBwkDTS0K8kNEOXeZMW1dHLfEy/aNk6Jrvjyhfd28DGv5O7A1SKsorQqk/gy2VRWa6zj6nbFd687cguyo+eH021fp/2+HGJW9N79Pu2MmJuDPBo/bnIjQUdAHA+IFrAJU7+Bmik9Luls0sF8IBTYPU060zNS+yc= 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.219.53 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-qv1-f53.google.com with SMTP id 6a1803df08f44-6cbe9e8bbb1so6581486d6.1 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=H/4IYUliml6LM33VHqHpKlLHdCn/UYfnDu1SzDPZYAmrJ0LBaMVH/g/QA5/v/xpVYI gmegzPA7xpja0ZXxAFKAlQ/+WPdiTXsauh6TG6JsJ21v944X8faY6EZkVql39ec81wrc /e6B4xRicppzRsTN8D4k4k0GiUN+lmXboVZYqGYLd2eREjs0KhiPnOoJD9/acp4BAOgf MGVflHjabUTrmZ0QGx7GjoDPOwLk7kUATWWNrf/So4PIYdIjBqM+7o1tANec5x6P/sQp DzQ3tRQkG/zxLBiwnkKpJT7XyB6GqtfSSHjRlHbA2QW69gJddtY8L7DnRO/YG1gfHHIQ N9fA== X-Gm-Message-State: AOJu0Ywb0/7SjTlbY4GVPUGL0x0vaRyxhd31T7g5hnfOuz25TeLrRqTo 7Cz/qoyylTZ9jsx2guyLsK6KYKWzpmoDusFjupWKK+QozVbrb5dwwGzLTqGOPA== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_c= trl.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_chai= n *chain, return 0; } =20 - if (ctrl->entity->get_cur) - ret =3D ctrl->entity->get_cur(chain->dev, ctrl->entity, - ctrl->info.selector, data, - ctrl->info.size); - else - ret =3D uvc_query_ctrl(chain->dev, UVC_GET_CUR, - ctrl->entity->id, chain->dev->intfnum, - ctrl->info.selector, data, - ctrl->info.size); + ret =3D uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, data, + ctrl->info.size); =20 if (ret < 0) return ret; @@ -2055,12 +2049,8 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev, if (data =3D=3D NULL) return -ENOMEM; =20 - if (ctrl->entity->get_info) - ret =3D ctrl->entity->get_info(dev, ctrl->entity, - ctrl->info.selector, data); - else - ret =3D uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, - dev->intfnum, info->selector, data, 1); + ret =3D uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, + info->selector, data, 1); =20 if (!ret) { info->flags &=3D ~(UVC_CTRL_FLAG_GET_CUR | diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.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; =20 - 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; }; --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 00:26:34 2024 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEF7C1A00C9 for ; Thu, 31 Oct 2024 13:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382205; cv=none; b=cfTX4IXofONmee79Pe64uwcGlbsGxTO/pPVMhGfkBwgVcioI8m9eJfVfR3wjRIW9vHHotxIRlUE49ixjuVwX90edCdO5cUKfblg/yHGML1/MNxKUKCOdymRXhd74OpGidn+2JM7/foNy/ygl9ZB4JRh2CjB/BdrH5jyL2OViDRI= 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.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Zni4pja9" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-7b1474b1377so65011585a.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=rRh6rlfLKVvWpI9clas3Yvo7slxMeVLG/2T+lNy+adx5MpSkaCIeunTBZmKGIx3Baw aLbyJG6HVZNiR/l2/KXkd2ev83kgywXafODUkIvNZsCIxLxR/Uv6wIhVBMEt4wUxRic7 zZqsPgpbFz9nuDiiEwlaDu7elVozUbhvzwQPb6cLHoAilRMwW+TtDRtAY2+y4R3K2M0q 8c6T2MFRSvWzwexbaQsYTN0c9FSbfxM/sse8gJh2zgCsACze+WMCHhcXiL7gyUj7j4KL rlSGV0CJPKvlKUjAeHDgJKODHsVZHxtyYe8gL5Mag67tZbTQNLoUmbwJ6q7qPNzx2dQk qhEQ== X-Gm-Message-State: AOJu0Yzz62Pd5xHcbxHB4kHYbHZi4jpQUml/jJuSODZ9/easRm/Vh0dj 1vHqcai7m90JDC5OvH2JtE2nSupgLLlrNnUp1xkTwjb/P/sXvYtMVA/WL20nlQ== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 *c= hain, return ret; } =20 + /* Create ancillary link for the GPIO. */ + if (chain->dev->gpio_unit && UVC_ENTITY_TYPE(entity) =3D=3D UVC_ITT_CAMER= A) { + struct media_link *link; + + link =3D media_create_ancillary_link(sink, + &chain->dev->gpio_unit->subdev.entity); + if (IS_ERR(link)) + return PTR_ERR(link); + } + return 0; } =20 --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 00:26:34 2024 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (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 0928E1A073F for ; Thu, 31 Oct 2024 13:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382207; cv=none; b=KBY82p1CRDXsiraI96/ZBgz2jAzif/bIXrfbnJzosyW7iHCjblp13EWVeS+xjVGQ4jIi3BNYiWQ/q9z8dBZ9tc6S9A/VoSelXk7MaFeahegxZ3Hk4hJTBZJx1M7fOGFPWoriFvWijwNxbqwxzobR5cuIIlJ80wHMag2km4augjc= 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.53 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-f53.google.com with SMTP id 6a1803df08f44-6cbcc2bd800so8450376d6.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=QI3aFqq4yX5j256G4qDgQTfvQJvaCZz4A3BflsjKAhwfB7Bw5wY84KHM5Vs0vdeWMw +1MPkpdntRDra0Y3R2ZCslLhACkwSyVVtUZ0iN+fJND2N6pUc1mzPOzTP8IskILGLDlo 35RwAPVr/qAZJBHfKVdGqT02DRlA3jKG7u2pqTw69fIawnteR1JOv9ND7tWoUH4hgj66 Zx/RTbcKdtDosFkj7DMXvZ8+4D1Iv/Glgpxo83W4rCczE71b6RoFLPsHx/sPpOFUmPv8 YARhG5p9M0io5foWtc+EB1DokIF2qnM/meb2pSThJxYSkBI67F2ErlFG+GcMYmrqVXUH UXcg== X-Gm-Message-State: AOJu0Yy4UmD59XDgRaOoxLPCvYT0xl4rV6bVzBJCbyksNQvLv83ffcU8 zQNpaIfssNETVjiDvUAIwgBRuDf8CYdRtYc6A4UBXGp3OLD606APkYu66e+MaQ== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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/D= ocumentation/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 eleme= nts * - ``MEDIA_ENT_F_LENS`` - Lens controller entity. =20 + * - ``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 v4l= 2_async_notifier *n, struct media_link *link; =20 if (sd->entity.function !=3D MEDIA_ENT_F_LENS && - sd->entity.function !=3D MEDIA_ENT_F_FLASH) + sd->entity.function !=3D MEDIA_ENT_F_FLASH && + sd->entity.function !=3D MEDIA_ENT_F_GPIO) return 0; =20 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) =20 /* * Digital TV, analog TV, radio and/or software defined radio tuner functi= ons. --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 00:26:34 2024 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 E8B341A2550 for ; Thu, 31 Oct 2024 13:43:25 +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=1730382209; cv=none; b=Pkjxz0YLbysx6IZ+I44wqAPEG8a5aozJoFM1L1y881bpqhg+b6ap8h4jLyxkznedgp93ZGaI1FDby9an4Ci7A56LYmGFiCiry2eQL/dXVC+cRD5zIx1OT8dU6FEiG5gQC0tOeUccgOGAgrvliNAhL88TikjrlaVhsPh0JKzRtxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382209; c=relaxed/simple; bh=blJa50xw0lKvopXaZAiEuV1VgzhB5oNeTs67sGqviXE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sAiKWChRtUsGsq8ei5FOJKVoUQ0sJNc254XnVFInajiPai4sLJU976HNaf5Y90kevSS+zy9whTQ2GX3q+oTEanQe8fxYpeVg3iv+naTq8j5L6MZk/nkzLv9H/oQz/yQVjbFSiSAnWTwo4xGXHNEj7DI4g9ZL0FkCMLHqsLGNuT0= 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.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="Duepzyif" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b155da5b0cso66240485a.2 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=YU7oHnPiyMEbUdI0EV90Lsx63F3yf67+Zb+5gMuu9ebvuJMYjzL5dinMxvK7NmphuW AWsHmYm2t7Yq3FKjWz6lnUbmVkmQ+Rapks6qiJjLvxyAL4OhH0ZTx0Qm4/r2WXE5snnk 0WdAzQd6AbsBVvlDyL/yQ+QDVwz1aWmgKIhaUL23l8FmRc3dW0bN1e+0KBR/V4p53fPD FRbU2hNzw5AC2iZIuedBL5qUJhJzrU+SsAT8kJ8+jBhzehoX+KBHNXRdqPZEtD8lWwa6 76FwMGi/jvpba3VjPOQuQiI2TNZuIFn2H0+JvoxMhHHrMY8JcQSIYvDRmcIvmVNk5tvz KtcQ== X-Gm-Message-State: AOJu0YwuGtoWAIPOaycp9uvYqLnQ7hSjLxyHnmJSkk4Lm5MqXU7inZ7g 7NxkUSoeYuGOeHdnmBUQ7R5npKfV0LFEw38VPe0X+vB0Hq5oLhzsBV6S87+Akg== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 *c= hain, case UVC_ITT_CAMERA: function =3D MEDIA_ENT_F_CAM_SENSOR; break; + case UVC_EXT_GPIO_UNIT: + function =3D 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 *c= hain, case UVC_OTT_DISPLAY: case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: case UVC_EXTERNAL_VENDOR_SPECIFIC: - case UVC_EXT_GPIO_UNIT: default: function =3D MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN; break; --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 00:26:34 2024 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (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 148611A3031 for ; Thu, 31 Oct 2024 13:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730382210; cv=none; b=jN4a6Lcapa6GSFewGq+/7EtA18dGtOm5iGJM6JQPH2x6DKeLtOCa067OHF/HmmoS8RFEmTYDIPxmJb30EswEpX2Q/wIXNgTjI5QvHstujbHdebiXjIkBipeP/j4PHPPdXyzZTQKnMCtMTLVjIv1MSjp1P9LeNYWvqiP3ENddXeU= 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.219.41 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-qv1-f41.google.com with SMTP id 6a1803df08f44-6cc2ea27a50so17737446d6.0 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=pTQ2t3JpGEJcEb4WwrQ86rC4CXly4r3iJY2T1EeH1ei8rHuZ16wF07wwbWMOdBHO8y 3zyqyNVdBgT/LhWh9k81hM8i4wfrcFbSR0Mcalp4CSwuGG16VkXzdd9s5tGoCuTW+PR7 2yc58U8zdtiYzuF2JOakGRp9eCYtF2ArWBgWzWxLFqXji1kbGzWvGJfPUCYY0iOvgdWR nECdHCUTUqqTayUoo7OYOwxXUXbQ96X6j2vHMMRqwBgwWQ5e5DHLD0XOr57Df5yuOBDJ yQG+Lj95F1gwccjpQwdegtkAmc1EiKpuex7qd44H8u7nQLdvlKc/ObxlFPtBXHIzdVcN b8iw== X-Gm-Message-State: AOJu0YxOwi5QcSDyCETF6xD/fPCa3JHHnS9GZXFavNG6TCIcWTrUHBYv y+qZR7yKC1VvFDLZAZ+zEWlMxqOU9Wea59uL/BDgV9CebL49VDlKvPYB/fi20Q== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_g= pio.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 */ =20 +#include #include #include #include @@ -16,6 +17,9 @@ static int uvc_gpio_g_volatile_ctrl(struct v4l2_ctrl *ctr= l) struct uvc_gpio *gpio =3D container_of(ctrl->handler, struct uvc_gpio, hdl); =20 + if (!gpio->gpio_ready) + return -EBUSY; + ret =3D 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; } =20 +static const struct dmi_system_id privacy_valid_during_streamon[] =3D { + { + .ident =3D "HP Elite c1030 Chromebook", + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_PRODUCT_NAME, "Jinlon"), + }, + }, + { + .ident =3D "HP Pro c640 Chromebook", + .matches =3D { + 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); =20 + /* + * 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 |=3D UVC_QUIRK_PRIVACY_DURING_STREAM; + else + unit->gpio.gpio_ready =3D true; + unit->gpio.gpio_privacy =3D gpio_privacy; unit->gpio.irq =3D irq; strscpy(unit->name, "GPIO", sizeof(unit->name)); @@ -74,6 +105,20 @@ int uvc_gpio_parse(struct uvc_device *dev) return 0; } =20 +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 =3D 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 =3D dev->gpio_unit; @@ -97,6 +142,8 @@ int uvc_gpio_init(struct uvc_device *dev) goto cleanup; } =20 + uvc_gpio_quirk(dev, false); + unit->gpio.privacy_ctrl->flags |=3D V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY; =20 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 *s= tream) if (ret < 0) goto error_video; =20 + uvc_gpio_quirk(stream->dev, true); + return 0; =20 error_video: @@ -2308,6 +2310,8 @@ int uvc_video_start_streaming(struct uvc_streaming *s= tream) =20 void uvc_video_stop_streaming(struct uvc_streaming *stream) { + uvc_gpio_quirk(stream->dev, false); + uvc_video_stop_transfer(stream, 1); =20 if (stream->intf->num_altsetting > 1) { diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.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 =20 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 @@ -173,10 +174,11 @@ struct uvc_control { #define UVC_ENTITY_FLAG_DEFAULT (1 << 0) =20 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; }; =20 struct uvc_entity { @@ -821,5 +823,6 @@ size_t uvc_video_stats_dump(struct uvc_streaming *strea= m, 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); =20 #endif --=20 2.47.0.163.g1226f6d8fa-goog