From: Ricardo Ribalda <ribalda@chromium.org>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
Yunke Cao <yunkec@chromium.org>,
Hans Verkuil <hverkuil@xs4all.nl>,
Hans de Goede <hdegoede@redhat.com>,
Ricardo Ribalda <ribalda@chromium.org>
Subject: [PATCH v2 6/6] media: uvcvideo: Use MEDIA_ENT_F_GPIO for the GPIO entity
Date: Fri, 08 Nov 2024 20:25:50 +0000 [thread overview]
Message-ID: <20241108-uvc-subdev-v2-6-85d8a051a3d3@chromium.org> (raw)
In-Reply-To: <20241108-uvc-subdev-v2-0-85d8a051a3d3@chromium.org>
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 <ribalda@chromium.org>
---
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 *chain,
case UVC_ITT_CAMERA:
function = MEDIA_ENT_F_CAM_SENSOR;
break;
+ case UVC_EXT_GPIO_UNIT:
+ function = MEDIA_ENT_F_GPIO;
+ break;
case UVC_TT_VENDOR_SPECIFIC:
case UVC_ITT_VENDOR_SPECIFIC:
case UVC_ITT_MEDIA_TRANSPORT_INPUT:
@@ -121,7 +124,6 @@ static int uvc_mc_init_entity(struct uvc_video_chain *chain,
case UVC_OTT_DISPLAY:
case UVC_OTT_MEDIA_TRANSPORT_OUTPUT:
case UVC_EXTERNAL_VENDOR_SPECIFIC:
- case UVC_EXT_GPIO_UNIT:
default:
function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
break;
diff --git a/drivers/media/usb/uvc/uvc_gpio.c b/drivers/media/usb/uvc/uvc_gpio.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
*/
+#include <linux/dmi.h>
#include <linux/kernel.h>
#include <linux/gpio/consumer.h>
#include <media/v4l2-ctrls.h>
@@ -16,6 +17,9 @@ static int uvc_gpio_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
container_of(ctrl->handler, struct uvc_gpio, hdl);
int ret;
+ if (!gpio->gpio_ready)
+ return -EBUSY;
+
ret = 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 = data;
int new_val;
+ if (!uvc_gpio->gpio_ready)
+ return IRQ_HANDLED;
+
new_val = gpiod_get_value_cansleep(uvc_gpio->gpio_privacy);
if (new_val < 0)
return IRQ_HANDLED;
@@ -43,6 +50,24 @@ static irqreturn_t uvc_gpio_irq(int irq, void *data)
return IRQ_HANDLED;
}
+static const struct dmi_system_id privacy_valid_during_streamon[] = {
+ {
+ .ident = "HP Elite c1030 Chromebook",
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "HP"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "Jinlon"),
+ },
+ },
+ {
+ .ident = "HP Pro c640 Chromebook",
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "HP"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "Dratini"),
+ },
+ },
+ { } /* terminate list */
+};
+
int uvc_gpio_parse(struct uvc_device *dev)
{
struct gpio_desc *gpio_privacy;
@@ -64,6 +89,15 @@ int uvc_gpio_parse(struct uvc_device *dev)
if (IS_ERR(unit))
return PTR_ERR(unit);
+ /*
+ * Note: This quirk will not match external UVC cameras,
+ * as they will not have the corresponding ACPI GPIO entity.
+ */
+ if (dmi_check_system(privacy_valid_during_streamon))
+ dev->quirks |= UVC_QUIRK_PRIVACY_DURING_STREAM;
+ else
+ unit->gpio.gpio_ready = true;
+
unit->gpio.gpio_privacy = gpio_privacy;
unit->gpio.irq = irq;
strscpy(unit->name, "GPIO", sizeof(unit->name));
@@ -74,6 +108,16 @@ int uvc_gpio_parse(struct uvc_device *dev)
return 0;
}
+void uvc_gpio_quirk(struct uvc_device *dev, bool stream_on)
+{
+ if (!dev->gpio_unit || !(dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM))
+ return;
+
+ dev->gpio_unit->gpio.gpio_ready = stream_on;
+ if (stream_on)
+ uvc_gpio_irq(0, &dev->gpio_unit->gpio);
+}
+
int uvc_gpio_init(struct uvc_device *dev)
{
struct uvc_entity *unit = dev->gpio_unit;
@@ -97,6 +141,8 @@ int uvc_gpio_init(struct uvc_device *dev)
goto cleanup;
}
+ uvc_gpio_quirk(dev, false);
+
unit->gpio.privacy_ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE |
V4L2_CTRL_FLAG_READ_ONLY;
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index cd9c29532fb0..0d542176ccde 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -2296,6 +2296,8 @@ int uvc_video_start_streaming(struct uvc_streaming *stream)
if (ret < 0)
goto error_video;
+ uvc_gpio_quirk(stream->dev, true);
+
return 0;
error_video:
@@ -2308,6 +2310,8 @@ int uvc_video_start_streaming(struct uvc_streaming *stream)
void uvc_video_stop_streaming(struct uvc_streaming *stream)
{
+ uvc_gpio_quirk(stream->dev, false);
+
uvc_video_stop_transfer(stream, 1);
if (stream->intf->num_altsetting > 1) {
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 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
/* 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);
#endif
--
2.47.0.277.g8800431eea-goog
next prev parent reply other threads:[~2024-11-08 20:25 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-08 20:25 [PATCH v2 0/6] media: uvcvideo: Implement the Privacy GPIO as a subdevice Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 1/6] media: uvcvideo: Factor out gpio functions to its own file Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 2/6] media: uvcvideo: Re-implement privacy GPIO as a separate subdevice Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 3/6] Revert "media: uvcvideo: Allow entity-defined get_info and get_cur" Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 4/6] media: uvcvideo: Create ancillary link for GPIO subdevice Ricardo Ribalda
2024-11-10 10:05 ` Sakari Ailus
2024-11-08 20:25 ` [PATCH v2 5/6] media: v4l2-core: Add new MEDIA_ENT_F_GPIO Ricardo Ribalda
2024-11-08 20:25 ` Ricardo Ribalda [this message]
2024-11-09 14:04 ` [PATCH v2 0/6] media: uvcvideo: Implement the Privacy GPIO as a subdevice Mauro Carvalho Chehab
2024-11-09 14:57 ` Ricardo Ribalda
2024-11-09 15:37 ` Hans de Goede
2024-11-09 16:29 ` Ricardo Ribalda
2024-11-10 10:02 ` Mauro Carvalho Chehab
2024-11-10 10:29 ` Hans Verkuil
2024-11-10 10:37 ` Ricardo Ribalda
2024-11-10 10:47 ` Hans Verkuil
2024-11-10 12:48 ` Mauro Carvalho Chehab
2024-11-10 10:32 ` Ricardo Ribalda
2024-11-10 10:59 ` Ricardo Ribalda
2024-11-10 12:46 ` Mauro Carvalho Chehab
2024-11-10 16:01 ` Ricardo Ribalda
2024-11-10 15:14 ` Laurent Pinchart
2024-11-10 16:04 ` Ricardo Ribalda
2024-11-25 12:31 ` Hans de Goede
2024-11-25 12:56 ` Laurent Pinchart
2024-11-25 13:35 ` Hans de Goede
2024-11-10 16:07 ` Ricardo Ribalda
2024-11-25 12:39 ` Hans de Goede
2024-11-25 12:58 ` Laurent Pinchart
2024-11-25 13:44 ` Hans de Goede
2024-11-25 13:50 ` Ricardo Ribalda
2024-11-11 12:03 ` Hans de Goede
2024-11-25 12:25 ` Hans de Goede
2024-11-25 12:49 ` Laurent Pinchart
2024-11-25 13:29 ` Hans de Goede
2024-11-26 17:22 ` Laurent Pinchart
2024-11-25 13:39 ` Ricardo Ribalda
2024-11-25 14:02 ` Hans de Goede
2024-11-26 16:22 ` Ricardo Ribalda
2024-11-26 17:18 ` Laurent Pinchart
2024-11-26 17:29 ` Ricardo Ribalda
2024-11-10 15:08 ` Laurent Pinchart
2024-11-11 12:59 ` Hans de Goede
2024-11-11 14:35 ` Hans de Goede
2024-11-12 17:31 ` Ricardo Ribalda
2024-11-13 15:19 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241108-uvc-subdev-v2-6-85d8a051a3d3@chromium.org \
--to=ribalda@chromium.org \
--cc=hdegoede@redhat.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=yunkec@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox