From nobody Sat Nov 23 21:30:06 2024 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.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 A19901E22F3 for ; Fri, 8 Nov 2024 20:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097555; cv=none; b=VIJbjxCNqqbZa0mM++zQWQtFFZ/ayfAQ/o0/ig+6QgWqUXBDnUt5fm5xQSo3uG5SsTIMv+aKTWXz6a5fXDYoDi/KqU90nUVJXkt/W/MVzCVfV98k/TS1LqKn/vyyucB1T+t8uri3KraNmkt+utF9R/AVsHFr3OP+xQTER5Vaec8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097555; c=relaxed/simple; bh=RkrsccvEqQUhBk8Z1PddvWJhE1cp8KwJo0AXadlFoHU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AmA4EC943tt+7yiJnf64KxwIkSKx5TLC5YkSMccksurXcAZj2d93fpZpXsv288yCxVNaTrBwsDWdyAprzaKcVKH1miulFgZG1H1pGXvjcK7j8pk2H+rjZzoPNBaGi0mP28S3jgCem5UJ2AeVIuJXs20lD8quO4BWLRzRLtA8O6k= 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=gYS99ee1; arc=none smtp.client-ip=209.85.161.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="gYS99ee1" Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5ebc0992560so1566213eaf.0 for ; Fri, 08 Nov 2024 12:25:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731097553; x=1731702353; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=aTqnfrQkIAHFL33oi5aoABfM2DMERBuyBRyMEKrhpSg=; b=gYS99ee13fU73SLFFM+H9ecSUU3Qh+xnJahLav4CbL5RBDPiOywuwaHma5dMFxuvW2 /5y4Tw/287xCrGkzLHT+OJwTFszMB36kQMdd5FUoD/EhgR6gqcOrFR7TTf9zPY4/Eg5o Z4zKligX+0zkIIrtJMRt/9d7bBNjMnQx87unI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731097553; x=1731702353; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aTqnfrQkIAHFL33oi5aoABfM2DMERBuyBRyMEKrhpSg=; b=W1wAXe9/nnv0vzX7tnwzWtFETUMTb2AUyUv0m9b3hsC4dTXp5ViFupKDIvWjv0mNW4 8GkgzQs9SyCPAE96v8IYrxobn8zdJjKRmUKRrBhZmR1IqLc3tUAGtkO+p5IeNEtHQEX6 qVHbnF710vKLihKDZ1dJgvsdwgo6G3YDMzdrXlo3uMW9eGOkIwrv4Eek4waSO/HP9AAn YeKyHkcX5/aESQ8fHaS50jjehgKtL1DtfeQQFN+O3226N5xPXpCpgfBLUUZ7XifB6Ee6 cS97jRwRk6gJmgflP47iqZcPVwsD7Caz6f/Uc79Kj1LOvgNKrD882HAvjKCnZpAh5u5H oBGA== X-Gm-Message-State: AOJu0YzRjAEQ4t8OY3XHSHwkYwND2Vp5ZT+hWUsyq8J1cnOmCbqhbCxD r9biRvkiG65o3T8+KAYF4j7ksn/T7t+SJIVXkbDHRHNcfdXj8IVEJI/wAY1pfQ== X-Google-Smtp-Source: AGHT+IHmHYRy0E+sQthEgfdGj/TkGxFgaoIi6XIOBa1bTk+Jd+XHo+4m5D+wXbV70YzRd/iB3CQhoA== X-Received: by 2002:a05:6359:514a:b0:1c6:1d02:9be0 with SMTP id e5c5f4694b2df-1c641ea8956mr388148555d.7.1731097551160; Fri, 08 Nov 2024 12:25:51 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff46d440sm24207341cf.52.2024.11.08.12.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:25:50 -0800 (PST) From: Ricardo Ribalda Date: Fri, 08 Nov 2024 20:25:45 +0000 Subject: [PATCH v2 1/6] 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: <20241108-uvc-subdev-v2-1-85d8a051a3d3@chromium.org> References: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> In-Reply-To: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 This is just a refactor patch, no new functionality is added. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/Makefile | 3 +- drivers/media/usb/uvc/uvc_driver.c | 119 +--------------------------------= ---- drivers/media/usb/uvc/uvc_gpio.c | 118 +++++++++++++++++++++++++++++++++= +++ drivers/media/usb/uvc/uvcvideo.h | 8 +++ 4 files changed, 131 insertions(+), 117 deletions(-) diff --git a/drivers/media/usb/uvc/Makefile b/drivers/media/usb/uvc/Makefile index 4f9eee4f81ab..85514b6e538f 100644 --- a/drivers/media/usb/uvc/Makefile +++ b/drivers/media/usb/uvc/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 uvcvideo-objs :=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 cd13bf01265d..5b48768a4f7f 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,118 +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->intf->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->intf->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; - int ret; - - if (!unit || unit->gpio.irq < 0) - return 0; - - ret =3D request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, - IRQF_ONESHOT | IRQF_TRIGGER_FALLING | - IRQF_TRIGGER_RISING, - "uvc_privacy_gpio", dev); - - unit->gpio.initialized =3D !ret; - - return ret; -} - -static void uvc_gpio_deinit(struct uvc_device *dev) -{ - if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) - return; - - free_irq(dev->gpio_unit->gpio.irq, dev); -} - /* ------------------------------------------------------------------------ * UVC device scan */ diff --git a/drivers/media/usb/uvc/uvc_gpio.c b/drivers/media/usb/uvc/uvc_g= pio.c new file mode 100644 index 000000000000..453739acbe8f --- /dev/null +++ b/drivers/media/usb/uvc/uvc_gpio.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * uvc_gpio.c -- USB Video Class driver + * + * Copyright 2024 Google LLC + */ + +#include +#include +#include "uvcvideo.h" + +static void uvc_gpio_event(struct uvc_device *dev) +{ + struct uvc_entity *unit =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->intf->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; + int ret; + + if (!unit || unit->gpio.irq < 0) + return 0; + + ret =3D request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, + IRQF_ONESHOT | IRQF_TRIGGER_FALLING | + IRQF_TRIGGER_RISING, + "uvc_privacy_gpio", dev); + + unit->gpio.initialized =3D !ret; + + return ret; +} + +void uvc_gpio_deinit(struct uvc_device *dev) +{ + if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) + return; + + free_irq(dev->gpio_unit->gpio.irq, dev); +} diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 965a789ed03e..91ed59b54d9a 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -673,6 +673,9 @@ do { \ extern struct uvc_driver uvc_driver; =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, @@ -817,4 +820,9 @@ 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_parse(struct uvc_device *dev); +int uvc_gpio_init_irq(struct uvc_device *dev); +void uvc_gpio_deinit(struct uvc_device *dev); + #endif --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:30:06 2024 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C61B61D0E04 for ; Fri, 8 Nov 2024 20:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097554; cv=none; b=DCWEm4fIFHookQtOfDuV+2Vzec8c6Hn8k5n8ecBCTsCnM9jSWjQX1s7stEkj4KdXleC6FWLOK3/TJuMSqePHqvmk2kal1aA4sk5DvntM9JA7GbVIVI1eikyudVM3tP7tVzBOKxqYP9diwlDDzvzp584wLqxYWkcVEQ43iuBZNV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097554; c=relaxed/simple; bh=yPKYz/hddeimT0WKUPAUKGdG+sPhSfCtkdHHyL8Jc9Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iD6194XVTqqgiX9AfAtzHhvpq7DxtuNeVtXOMESjbnRrXz/Cyzg+6NKZSlCM1754z0GEECKdfELOWHg8998X/pf6Jd78WDo1G094gDXHZW0zMFnWV1y8W3Ei2TiK4eQegSSX5RCkaTEsXfKD6xc21ijv0voocGUfleNmQfjYxMU= 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=CcN+KPEh; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CcN+KPEh" Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5ebc0992560so1566207eaf.0 for ; Fri, 08 Nov 2024 12:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731097552; x=1731702352; 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=w4Vaj5JzGb6k86tSoIS6h1LsetC5KChYUtTpZZAf/u8=; b=CcN+KPEhn2pBDE2dQSSGjmJXRWKL9C7cQlW6HuI6s119tkxC9SJhYt9vDNWFPKayrR O/W5UVL7KBQuqWy5cMV5OnUD8jFm2FBjAgJZQTId1ZM33v5SBtPAwoTRYmGjOrZy0ext zPBxrOzd0sWQ+PGLNwuUlBLhz3GuQgZl6jug0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731097552; x=1731702352; 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=w4Vaj5JzGb6k86tSoIS6h1LsetC5KChYUtTpZZAf/u8=; b=i8qX0OzKg0on2IvPJWneIC0tNzldYUvV9FsDp9ZHx5iziPPbIdZjs7Xdh0cZaJb0XM h8AcfpSnO1uR8tKFMsYtTBvBq/C4FKDaxwdvDJAVHm84F5J2gKvwL/lZb7t0TXzTOjbN U5RzBNXFbXT8qEWTf42MydkGmpvq2pXbSsJGVIx6Xi5XfZg94c8beCuR7CVs68EPsq3H KMOhsl7wgTEU9tsMsPYvKlRH5e/XQ0bBlVsYFmP6xruwYIQNGXXbMD8Rn9vHaapRiFDf lwDvczI/JBiyyAEJuLev1BPewJqUi9mgrzJ0I+hZLiLNOCSi0sGi3wVcU1pe8uwsQSSl dCPg== X-Gm-Message-State: AOJu0Ywx7aQnx22JUrmhW9J7pMElswkg1hiHSusmzgvgG0ULKZs5HE/t qsQ7Z5ein9rgzwHyJYagFbFXR03+CmONPXMZsR9R4zYdqSK3AeU1iZ+u5r5T7s74/sspEmp2KQs = X-Google-Smtp-Source: AGHT+IEfFBPTdYt/LYc9fDKOshvJgoHOK95eB0z49jQWlrewsUhiqGrH2ZMzs1sQXG7vQ+NPMO93YA== X-Received: by 2002:a05:6358:5d84:b0:1bc:d0a4:3d3a with SMTP id e5c5f4694b2df-1c641ec23bcmr362536455d.12.1731097551888; Fri, 08 Nov 2024 12:25:51 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff46d440sm24207341cf.52.2024.11.08.12.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:25:51 -0800 (PST) From: Ricardo Ribalda Date: Fri, 08 Nov 2024 20:25:46 +0000 Subject: [PATCH v2 2/6] media: uvcvideo: Re-implement 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: <20241108-uvc-subdev-v2-2-85d8a051a3d3@chromium.org> References: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> In-Reply-To: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 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 | 4 +- drivers/media/usb/uvc/uvc_entity.c | 6 ++ drivers/media/usb/uvc/uvc_gpio.c | 111 ++++++++++++++++++++++-----------= ---- drivers/media/usb/uvc/uvcvideo.h | 20 ++++--- 5 files changed, 88 insertions(+), 73 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 5b48768a4f7f..fe5a53fd0e14 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1779,6 +1779,7 @@ static void uvc_delete(struct kref *kref) struct uvc_device *dev =3D container_of(kref, struct uvc_device, ref); struct list_head *p, *n; =20 + uvc_gpio_cleanup(dev); uvc_status_cleanup(dev); uvc_ctrl_cleanup_device(dev); =20 @@ -2171,6 +2172,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 @@ -2182,7 +2184,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); 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 453739acbe8f..af72df96bc57 100644 --- a/drivers/media/usb/uvc/uvc_gpio.c +++ b/drivers/media/usb/uvc/uvc_gpio.c @@ -7,57 +7,46 @@ =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; - - 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); -} + struct uvc_gpio *gpio =3D + container_of(ctrl->handler, struct uvc_gpio, hdl); + int ret; =20 -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; + ret =3D gpiod_get_value_cansleep(gpio->gpio_privacy); + if (ret < 0) + return ret; =20 - *(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->intf->dev, "privacy", @@ -67,23 +56,17 @@ int uvc_gpio_parse(struct uvc_device *dev) =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,21 +74,53 @@ 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 + 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 request_threaded_irq(unit->gpio.irq, NULL, uvc_gpio_irq, IRQF_ONESHOT | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, - "uvc_privacy_gpio", dev); + "uvc_privacy_gpio", &unit->gpio); + if (ret) + goto cleanup; =20 - unit->gpio.initialized =3D !ret; + unit->gpio.initialized =3D true; =20 + return 0; + +cleanup: + v4l2_ctrl_handler_free(&unit->gpio.hdl); return ret; } =20 @@ -114,5 +129,13 @@ void uvc_gpio_deinit(struct uvc_device *dev) if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) return; =20 - free_irq(dev->gpio_unit->gpio.irq, dev); + free_irq(dev->gpio_unit->gpio.irq, &dev->gpio_unit->gpio); +} + +void uvc_gpio_cleanup(struct uvc_device *dev) +{ + if (!dev->gpio_unit || !dev->gpio_unit->gpio.initialized) + return; + + v4l2_ctrl_handler_free(&dev->gpio_unit->gpio.hdl); } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 91ed59b54d9a..4a06db329aa9 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,14 @@ struct uvc_control { =20 #define UVC_ENTITY_FLAG_DEFAULT (1 << 0) =20 +struct uvc_gpio { + int irq; + bool initialized; + struct v4l2_ctrl_handler hdl; + struct v4l2_ctrl *privacy_ctrl; + struct gpio_desc *gpio_privacy; +}; + 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,13 +238,7 @@ struct uvc_entity { u8 *bmControlsType; } extension; =20 - struct { - u8 bControlSize; - u8 *bmControls; - struct gpio_desc *gpio_privacy; - int irq; - bool initialized; - } gpio; + struct uvc_gpio gpio; }; =20 u8 bNrInPins; @@ -822,7 +825,8 @@ size_t uvc_video_stats_dump(struct uvc_streaming *strea= m, char *buf, =20 /* gpio */ int uvc_gpio_parse(struct uvc_device *dev); -int uvc_gpio_init_irq(struct uvc_device *dev); +int uvc_gpio_init(struct uvc_device *dev); void uvc_gpio_deinit(struct uvc_device *dev); +void uvc_gpio_cleanup(struct uvc_device *dev); =20 #endif --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:30:06 2024 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.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 8CBD91EF09F for ; Fri, 8 Nov 2024 20:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097556; cv=none; b=FAuR1Tg+Rrz9EjbQccAoVRrMRyQwRSeMYNPKtEDfuvGs+UDOtti2K5oXXbyg9BAJgaA9FmVnAFtSWaLvvJ5fCQB4zsHMI/4ZLAT0Nrmsez4gP/zTGdiwyWIIsrdJcf//py9D9hnamoSwuA56bKxjxKXOnGhryFeVTGwo47ycClM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097556; c=relaxed/simple; bh=wJ4SvwiZLr0JP4Er3WjpeseQ8Gxn6OdzVEJCX2ygyPU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M2yQmYTaQN+9mGa/EW0YB07jeUCNuehZ2KlSti8BH98/QGxFREokGXSimIuY130LCST0RPPaQKySqf80DafYNmuSIfurBMRox/qmyZqp0tWJd5Eo+5UCOYb3OD+buAvRxlwEMGzemARh89heLkc+O4MqplrUqTS/qzp2eIN6ZyY= 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=F1KQArwS; arc=none smtp.client-ip=209.85.160.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="F1KQArwS" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-460ad98b043so22531501cf.1 for ; Fri, 08 Nov 2024 12:25:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731097553; x=1731702353; 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=+4ryCzSSqUh6W4Bx23m71ZTRER6+5bh5JI0THw5U6f0=; b=F1KQArwSfaVUXVhZEZnMoeyAY6FWt6c2NPbAUuHkFFJ9UG3cbyv+Sq7YeEPoyoYJyL 9aWK53/jdfmKcs5L970gLE3Jnbinxqs9vMxWoPz4SVsSF5XFWM6+/EH2LIE6u/6BSAvg HWk/FWSFnfw2PIVmbWT3/URDd4tZLf4WfViLA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731097553; x=1731702353; 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=+4ryCzSSqUh6W4Bx23m71ZTRER6+5bh5JI0THw5U6f0=; b=K6bMxt6IR75EReYqLDDo7F0w+mFfF1iILclhUK09vu0RWY2Jrc/gmQWwxD5oLLSOBy f8csTxMOoL21pgfKWu3I6XtwAzKG0/okhahNDS+PYHrlSJ4XLqllzyWNICngKMK5/mO6 tZx1wQ+lQAQfqEtQbcsPi/OaZ8X+Ffm8vosRgn30mQbgGn2W4bhIVntcaAvPek+09QVd mVjXnRwLoZz3+r/rdHJZEn+IldnGqNFfe6kSchpXkWR4ucwdR1dZJQ8edWJEENpKsOJz Z50MSY1vAtpsb9WuhpYXxXqAI5oa7ZMJvEofnAoBZRguxYSMUQTMEbkjcgWAXQk3e/LK 91Sg== X-Gm-Message-State: AOJu0Yyk4ZAHb316YOcWeXHBEWrBlJSWmlR7o3nK3i2fLNpm7MZgkrnQ ZsJ6D5wiuHU2UhVuneBLYVSAz0CizBen28I4H27Flc9utrvDC6ESSkO2DWNKTCJI6Kraq3ZK63s = X-Google-Smtp-Source: AGHT+IFixwVIvN4lcC0mBS5tbL30BusGxQLhgQLUnjLVIHxthBgA/ZZCylmDmjUXtm7iFY7s12f0uw== X-Received: by 2002:a05:622a:2594:b0:45d:7416:1636 with SMTP id d75a77b69052e-463085b7e3emr87548681cf.2.1731097553392; Fri, 08 Nov 2024 12:25:53 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff46d440sm24207341cf.52.2024.11.08.12.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:25:52 -0800 (PST) From: Ricardo Ribalda Date: Fri, 08 Nov 2024 20:25:47 +0000 Subject: [PATCH v2 3/6] 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: <20241108-uvc-subdev-v2-3-85d8a051a3d3@chromium.org> References: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> In-Reply-To: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 With the privacy gpio now handled as a 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 4a06db329aa9..1eeef2c12fbe 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -244,11 +244,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.277.g8800431eea-goog From nobody Sat Nov 23 21:30:06 2024 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.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 75D9E1F4702 for ; Fri, 8 Nov 2024 20:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097558; cv=none; b=DtVmeh30OkDWGLnm52E5YE5/6wxBuGZZ5Gr7lkVxM/LVboedoBx9e8AJBKqL+3HOvcZoxjAjJcEL+h9esfFJ2pbKDMg34EhARxqtp0m6BX2uPwdm+9t4FX1VGibGXsSHIc0UWHFR8EtQC3ffY2gBS5HWod0HJ8Y+37EwED2LH0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097558; c=relaxed/simple; bh=CEQbOGQ7MRdKXGHNLVjrKRQ53Dwr649n7vnBnnj8ctA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CNma9EoOKjP0RcKoN8PJdtYtAGMfg4bfYyVJH01HpYxlmd1rtnuClhCxT7IGIj/V/3cOeISr1ZlPsntmziurS0d6vHf4sHF2OKY1ancgfMpfp3C80UTS6N2bhK/wMqSWviVk5+xuADM3dSmTqoKeLmVMvGhCzOkZCCjt0FXORNY= 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=TNun1c5f; arc=none smtp.client-ip=209.85.160.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="TNun1c5f" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-460b04e4b1cso16122971cf.2 for ; Fri, 08 Nov 2024 12:25:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731097555; x=1731702355; 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=tkMMFzioKVFAa0nRKkB9RNN+8H7kOdLFjqp29pnighM=; b=TNun1c5fO/PpGMveSRkPiD1OPH0tF7NWeSRseoxVvPj5tIP++05Jq0DRTz2kklodwB idodLlAuT+2TCNRZy4niV7okbpJAR5C1lGaox5wPpBgHPb+YS0n1zhhdpEmP2Y1bw3jP vEA840b191t1MzsXs00r7aKE+FFzKrxMkXZC0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731097555; x=1731702355; 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=tkMMFzioKVFAa0nRKkB9RNN+8H7kOdLFjqp29pnighM=; b=kEEbTLWaGr+ipuI7bmnwRGpd7uqihZ8Y8LoHxoUWBiWZpVH6R5uKUPAkzqBA+JQigM xX4RcHSD10fQQKe4XtgAnJbOIPvui29jTLKrHOwggWWlU6N78N81nDyRakm0H9WCzxOP neCRr7zXT/0qMuJ5zA5XneTM0t3nEB18ae4s6ACyFQfp6FNoQ5CeLiLz1EEgWO1Qg/qY 293EoUgl/WYUmfsucSRzKS57li+/5DwYwq1gjulkJQGe9/kzmIN83WGrIRCrFdSyF1HU YXWfLuYKA6KtyOfCe3lLLBII0zuyg+u13ysYNu/F7ps+V0wgH9WGU3E8jW1DaLfFMZAF TwWg== X-Gm-Message-State: AOJu0YyJ8mxWb1CZ6tfmRuEqBKAj8SbekKkurFrIcT5/xUaz1nVEdgoM AKd7ynj0ARHGzTGG/g6KWlKjKpmgGHGmWRSmnGwevOJ0zknQxtc3VIxOPfuByQOe+OfECMERnWE = X-Google-Smtp-Source: AGHT+IHWOvV1IPVUo7h7yQ/dscufz+urxttXJhEzrF799ygWuSvfQI1Q+sg+Un/wfzS9P6xNNA9BQw== X-Received: by 2002:a05:622a:18a8:b0:461:48f9:44e2 with SMTP id d75a77b69052e-4630921aeddmr58442371cf.0.1731097555504; Fri, 08 Nov 2024 12:25:55 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff46d440sm24207341cf.52.2024.11.08.12.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:25:54 -0800 (PST) From: Ricardo Ribalda Date: Fri, 08 Nov 2024 20:25:48 +0000 Subject: [PATCH v2 4/6] 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: <20241108-uvc-subdev-v2-4-85d8a051a3d3@chromium.org> References: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> In-Reply-To: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 Make an ancillary 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.277.g8800431eea-goog From nobody Sat Nov 23 21:30:06 2024 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (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 843E320B7FA for ; Fri, 8 Nov 2024 20:25:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097559; cv=none; b=YDJE5IxhzBGx5WotMy8ZKnQlX7aTNDZ4rchh+LGij+kf7vW+ulBLN0ghviB9S/Xh/6ocu+GN8YmF/EYX3zkWrM4Lr/ncUSz3hPiqu+HhThXVj4FBvhpnQU89nlrBt1yOYjVKKJTNQzxJ8RSjEHLaYlZk+o1totFK/P4G3JGz3XQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097559; c=relaxed/simple; bh=PElbl8uW8Fa0oaZt4+kEmvtPpbNU7LixpWE5F/F/xAU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jrticl3ZzsPsOdOvqmxCdI8gxmhrsswXt97ewjFXkg39P4J0vSW8eqUXsDmbJGBoggfY8bXezCxnJxB4+Bv4SgDMUVdYX0RHOg92xwpgm/AQ2hZnUN2pJgTYeq4crBLcy3FT2zDuXK/DFj/DIOu34fm/jLJhFerW/rXd384TUm4= 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=QKkj6aG+; arc=none smtp.client-ip=209.85.210.43 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="QKkj6aG+" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-7187e0041d5so1692125a34.2 for ; Fri, 08 Nov 2024 12:25:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731097557; x=1731702357; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1P5DVRMjbEuaaQXC+PIiJu+9ELqOWJV7Errw4E0pPWQ=; b=QKkj6aG+9jU6O1E9Cx119PC58TO2h1aKA5anVqpXID6lZiZsPEHMET/qkoPBz3pHZS d/P5tDvleUTk9mm/9Kg8L9iFTh0GbgUXUPXaGwM/Ozq09fCa0hLSM4Ur4Xs/NLHb3pOL eUKo+56JlTwMRsL4LrhwhxiWJNHMj619W5VUQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731097557; x=1731702357; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1P5DVRMjbEuaaQXC+PIiJu+9ELqOWJV7Errw4E0pPWQ=; b=kxjlZqKgfn0cNLdKstmSAYmXHVYnCmLsJecrEEOq1NVOLgApWmQhFikf/ZxKQypwjx kReYF5Ti7ZreABzMTye8XLrqTSPZeH3wjQyTKzDEj9v5xaUfa5edUkns2q2SmCGXmr7g lnOKEisb3XVwTb9/kZYV5jiFpuz8qfznwQdJUN0YwSBCZ+4fhp/L6raK9NO0vjlZOk+L 06TfSRdXa8ZXtjYfXBQA5taIIzYlMeoq8/adGYT+AeqW6yq5R0gJkpS7dR+gORIb46ow FMoRH/IkezNqNQuCmp/qawVHAuHXa3I7z0r70CmYAESwiyAGLH3icdtLs+Q89R3LYhKA 8kcA== X-Gm-Message-State: AOJu0YzDhtTgS4mUeBuUq4QALabibXhgsAINeSUdxFYkFVJDhvS5HZda ScN6EcJ3hzcTqXxMdyu77HhkSDdxEZ1cPHXMwYMkBo8anEZWY8TAGW5Yye0GuQ== X-Google-Smtp-Source: AGHT+IGC/EK813LZkTWulIiITX2osqFqScFLwuEM4MPPYy5EEnhNBmWIUGoF8gCb/UExPoL+qBFbqQ== X-Received: by 2002:a05:6830:4890:b0:718:18d6:a447 with SMTP id 46e09a7af769-71a1c28b0cbmr4649836a34.24.1731097556736; Fri, 08 Nov 2024 12:25:56 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff46d440sm24207341cf.52.2024.11.08.12.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:25:56 -0800 (PST) From: Ricardo Ribalda Date: Fri, 08 Nov 2024 20:25:49 +0000 Subject: [PATCH v2 5/6] 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: <20241108-uvc-subdev-v2-5-85d8a051a3d3@chromium.org> References: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> In-Reply-To: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 Add a new media entity type to define a GPIO entity. This can be used to represent the privacy switch GPIO associated to a sensor. Signed-off-by: Ricardo Ribalda --- Documentation/userspace-api/media/mediactl/media-types.rst | 4 ++++ drivers/media/v4l2-core/v4l2-async.c | 3 ++- include/uapi/linux/media.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/mediactl/media-types.rst b/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..d3d045e52d78 100644 --- a/include/uapi/linux/media.h +++ b/include/uapi/linux/media.h @@ -84,6 +84,7 @@ struct media_device_info { #define MEDIA_ENT_F_CAM_SENSOR (MEDIA_ENT_F_OLD_SUBDEV_BASE + 1) #define MEDIA_ENT_F_FLASH (MEDIA_ENT_F_OLD_SUBDEV_BASE + 2) #define MEDIA_ENT_F_LENS (MEDIA_ENT_F_OLD_SUBDEV_BASE + 3) +#define MEDIA_ENT_F_GPIO (MEDIA_ENT_F_OLD_SUBDEV_BASE + 6) =20 /* * Digital TV, analog TV, radio and/or software defined radio tuner functi= ons. --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 21:30:06 2024 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.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 5DF3E20DD5F for ; Fri, 8 Nov 2024 20:25:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097561; cv=none; b=p9VMnfcmunVoGbD0vtEEwKfgn6YW+axKoCbkcQTXYmUSgKNU0Ujxfp2vDlmGOTS8J6PfznrQOZAtmwf8Vq8vwRC/qJ7c+FVJ54IILv2BhANfLg3fQQmTmWHeOAap8n5mKgXiiridFLjXcAHPA41Ud2Qp7VXgqmg3Ys1B+RDpobY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731097561; c=relaxed/simple; bh=bv2xpeEQjNLAp21efZpYAjV5xpc0pddIbvZdh95eckE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fgwzkuH3lBAVVWkS+tUGzVYkejKoYixDToClulU0kk36t5YbHjNDNUbeb2XxGljucRQFsqWQuCVKf/NGFivBbaLpa6LgdifZHUBytziF070PtEIR5oUVCc3YiATEPHAQI4N+DP/RRLP5O9OjmYTJCqN5gN37/QbJKi8TkI8X7r4= 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=oVPGNSog; arc=none smtp.client-ip=209.85.160.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="oVPGNSog" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-460ad0440ddso14541731cf.3 for ; Fri, 08 Nov 2024 12:25:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731097558; x=1731702358; 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=AJt80kpod+xHyChc26qzkMobFWguRBFXjCM77byxZYI=; b=oVPGNSogt+aeMWcfkYPTch2xVS/2TbxkLifs0VZMf8VbDpyKZkUFoQDj1bhuilA3E6 OfQLuqpJJlRI41c9i062iF/1pQCj9AwSIyQbnKqcz05GGc1TPsLxL3TLZmYkXuCdTJYl X4V7X9gQyfLwWvK9lKro4qkTm7avtI4JHoKOU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731097558; x=1731702358; 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=AJt80kpod+xHyChc26qzkMobFWguRBFXjCM77byxZYI=; b=pYxzYhg7iAaO5G+UEmXCD0proABTwykyRXTHrKnP+N8mvEw+o0ju8RM4RTCLkqZIO4 iUhlBLm4b6NIconnMYx8bHyKW6GwMIaz6skmqjm2jyC8fxQ0UzbNR9btwlXuw9YkidhU JylHCUIg+zPNi0egFS9H02tpI7oxz4kfwHv+fKM5bNpHGsknQyNWADfqJUnjQbqOjL1M qnjDTa3qghdewsJyiCTYMSuUEuoSJ7PZbSAJu6hYus6KHtsI04vZoqnKHIVGkVwbpjH6 GElXMQjOu0a3w9B29Cdmd3X1TwrrES5Kt6Xa+LXoBW9fmkRbeFf0Rit/gIHcXblocp56 F18Q== X-Gm-Message-State: AOJu0YyN60dOscfS9MvKQl+CpO57u1tAQppU/NZlRH0KlylKAa9lkHP5 HuW+U+S8BvC6nm/mZ0d0f+CZfnifIgqxVVn3NtZmDXhLvthpB82hNEoL7LoZ2g== X-Google-Smtp-Source: AGHT+IFrMsD49sco7THtDJddO2E5ypfxEJBg2QPMDiX35nTCJWi7xmGAeIZoTnyGQHomtHpXL0UJYw== X-Received: by 2002:a05:622a:2a0d:b0:458:3a34:b7b5 with SMTP id d75a77b69052e-46309370c73mr50476121cf.26.1731097558066; Fri, 08 Nov 2024 12:25:58 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-462ff46d440sm24207341cf.52.2024.11.08.12.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:25:57 -0800 (PST) From: Ricardo Ribalda Date: Fri, 08 Nov 2024 20:25:50 +0000 Subject: [PATCH v2 6/6] 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: <20241108-uvc-subdev-v2-6-85d8a051a3d3@chromium.org> References: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> In-Reply-To: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Yunke Cao , Hans Verkuil , Hans de Goede , Ricardo Ribalda X-Mailer: b4 0.13.0 Right now we are setting the entity type to unknown for the privacy GPIO entity. Which results in the following error in dmesg. uvcvideo 3-6:1.0: Entity type for entity GPIO was not initialized! Use the newly created type to fix this. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_entity.c | 4 +++- drivers/media/usb/uvc/uvc_gpio.c | 46 ++++++++++++++++++++++++++++++++++= ++++ drivers/media/usb/uvc/uvc_video.c | 4 ++++ drivers/media/usb/uvc/uvcvideo.h | 3 +++ 4 files changed, 56 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; diff --git a/drivers/media/usb/uvc/uvc_gpio.c b/drivers/media/usb/uvc/uvc_g= pio.c index af72df96bc57..b19ca222c9f2 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) container_of(ctrl->handler, struct uvc_gpio, hdl); int ret; =20 + if (!gpio->gpio_ready) + return -EBUSY; + ret =3D gpiod_get_value_cansleep(gpio->gpio_privacy); if (ret < 0) return ret; @@ -34,6 +38,9 @@ static irqreturn_t uvc_gpio_irq(int irq, void *data) struct uvc_gpio *uvc_gpio =3D data; int new_val; =20 + if (!uvc_gpio->gpio_ready) + return IRQ_HANDLED; + new_val =3D gpiod_get_value_cansleep(uvc_gpio->gpio_privacy); if (new_val < 0) return IRQ_HANDLED; @@ -43,6 +50,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 +89,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 +108,16 @@ 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) + uvc_gpio_irq(0, &dev->gpio_unit->gpio); +} + int uvc_gpio_init(struct uvc_device *dev) { struct uvc_entity *unit =3D dev->gpio_unit; @@ -97,6 +141,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 1eeef2c12fbe..b03152c9651b 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 @@ -175,6 +176,7 @@ struct uvc_control { struct uvc_gpio { int irq; bool initialized; + bool gpio_ready; struct v4l2_ctrl_handler hdl; struct v4l2_ctrl *privacy_ctrl; struct gpio_desc *gpio_privacy; @@ -823,5 +825,6 @@ int uvc_gpio_parse(struct uvc_device *dev); int uvc_gpio_init(struct uvc_device *dev); void uvc_gpio_deinit(struct uvc_device *dev); void uvc_gpio_cleanup(struct uvc_device *dev); +void uvc_gpio_quirk(struct uvc_device *dev, bool stream_on); =20 #endif --=20 2.47.0.277.g8800431eea-goog