From nobody Mon Nov 25 02:31:48 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