From: Ricardo Ribalda <ribalda@chromium.org>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Ricardo Ribalda <ribalda@chromium.org>
Subject: [PATCH v6 08/11] media: uvcvideo: Implement UVC_QUIRK_PRIVACY_DURING_STREAM
Date: Wed, 23 Dec 2020 00:04:43 +0100 [thread overview]
Message-ID: <20201222230446.1027916-9-ribalda@chromium.org> (raw)
In-Reply-To: <20201222230446.1027916-1-ribalda@chromium.org>
Some devices can only read the privacy_pin if the device is
streaming.
This patch implement a quirk for such devices, in order to avoid invalid
reads and/or spurious events.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/usb/uvc/uvc_driver.c | 37 ++++++++++++++++++++++++++++--
drivers/media/usb/uvc/uvc_video.c | 27 ++++++++++++++++++++++
drivers/media/usb/uvc/uvcvideo.h | 5 ++++
3 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 5873237bbfa8..15f7ec7d7e9b 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -7,6 +7,7 @@
*/
#include <linux/atomic.h>
+#include <linux/dmi.h>
#include <linux/gpio/consumer.h>
#include <linux/kernel.h>
#include <linux/list.h>
@@ -1473,7 +1474,7 @@ static int uvc_parse_control(struct uvc_device *dev)
* Privacy GPIO
*/
-static u8 uvc_gpio_update_value(struct uvc_device *dev)
+u8 uvc_gpio_update_value(struct uvc_device *dev)
{
struct uvc_entity *unit = dev->gpio_unit;
struct uvc_video_chain *chain;
@@ -1498,6 +1499,9 @@ static int uvc_gpio_get_cur(struct uvc_device *dev, struct uvc_entity *entity,
if (cs != UVC_CT_PRIVACY_CONTROL || size < 1 || !dev->gpio_unit)
return -EINVAL;
+ if (!dev->gpio_unit->gpio.is_gpio_ready)
+ return -EBUSY;
+
*(u8 *)data = uvc_gpio_update_value(dev);
return 0;
@@ -1517,13 +1521,31 @@ static irqreturn_t uvc_gpio_irq(int irq, void *data)
{
struct uvc_device *dev = data;
- if (!dev->gpio_unit)
+ if (!dev->gpio_unit || !dev->gpio_unit->gpio.is_gpio_ready)
return IRQ_HANDLED;
uvc_gpio_update_value(dev);
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 */
+};
+
static int uvc_gpio_parse(struct uvc_device *dev)
{
struct uvc_entity *unit;
@@ -1557,6 +1579,17 @@ static int uvc_gpio_parse(struct uvc_device *dev)
unit->get_info = uvc_gpio_get_info;
strncpy(unit->name, "GPIO", sizeof(unit->name) - 1);
+ /*
+ * 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;
+ unit->gpio.is_gpio_ready = false;
+ } else {
+ unit->gpio.is_gpio_ready = true;
+ }
+
list_add_tail(&unit->list, &dev->entities);
dev->gpio_unit = unit;
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index a6a441d92b94..03d6ed7fc8ed 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -2077,6 +2077,29 @@ int uvc_video_init(struct uvc_streaming *stream)
return 0;
}
+static void uvc_gpio_privacy_quirks(struct uvc_streaming *stream, bool enable)
+{
+ struct uvc_device *dev = stream->dev;
+ struct uvc_video_chain *first_chain;
+
+ if (!(dev->quirks & UVC_QUIRK_PRIVACY_DURING_STREAM))
+ return;
+
+ if (!dev->gpio_unit)
+ return;
+
+ first_chain = list_first_entry(&dev->chains,
+ struct uvc_video_chain, list);
+ /* GPIO entities are always on the first chain. */
+ if (stream->chain != first_chain)
+ return;
+
+ dev->gpio_unit->gpio.is_gpio_ready = enable;
+
+ if (enable)
+ uvc_gpio_update_value(stream->dev);
+}
+
int uvc_video_start_streaming(struct uvc_streaming *stream)
{
int ret;
@@ -2094,6 +2117,8 @@ int uvc_video_start_streaming(struct uvc_streaming *stream)
if (ret < 0)
goto error_video;
+ uvc_gpio_privacy_quirks(stream, true);
+
return 0;
error_video:
@@ -2106,6 +2131,8 @@ int uvc_video_start_streaming(struct uvc_streaming *stream)
void uvc_video_stop_streaming(struct uvc_streaming *stream)
{
+ uvc_gpio_privacy_quirks(stream, 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 132513a66ee5..58422c99f05f 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -209,6 +209,7 @@
#define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400
#define UVC_QUIRK_FORCE_Y8 0x00000800
#define UVC_QUIRK_FORCE_BPP 0x00001000
+#define UVC_QUIRK_PRIVACY_DURING_STREAM 0x00002000
/* Format flags */
#define UVC_FMT_FLAG_COMPRESSED 0x00000001
@@ -367,6 +368,7 @@ struct uvc_entity {
struct gpio_desc *gpio_privacy;
int irq;
atomic_t gpio_privacy_value;
+ bool is_gpio_ready;
} gpio;
};
@@ -822,6 +824,9 @@ extern const struct v4l2_file_operations uvc_fops;
int uvc_mc_register_entities(struct uvc_video_chain *chain);
void uvc_mc_cleanup_entity(struct uvc_entity *entity);
+/* Privacy gpio */
+u8 uvc_gpio_update_value(struct uvc_device *dev);
+
/* Video */
int uvc_video_init(struct uvc_streaming *stream);
int uvc_video_suspend(struct uvc_streaming *stream);
--
2.29.2.729.g45daf8777d-goog
next prev parent reply other threads:[~2020-12-22 23:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-22 23:04 [PATCH v6 00/11] Show privacy_gpio as a v4l2_ctrl Ricardo Ribalda
2020-12-22 23:04 ` [PATCH v6 01/11] media: uvcvideo: Move guid to entity Ricardo Ribalda
2020-12-22 23:04 ` [PATCH v6 02/11] media: uvcvideo: Allow extra entities Ricardo Ribalda
2020-12-22 23:04 ` [PATCH v6 03/11] media: uvcvideo: Allow entities with no pads Ricardo Ribalda
2020-12-22 23:04 ` [PATCH v6 04/11] media: uvcvideo: Add uvc_ctrl_status_event_direct Ricardo Ribalda
2020-12-23 8:53 ` Laurent Pinchart
2020-12-22 23:04 ` [PATCH v6 05/11] media: uvcvideo: Allow entity-defined get_info and get_cur Ricardo Ribalda
2020-12-22 23:04 ` [PATCH v6 06/11] media: uvcvideo: Implement UVC_EXT_GPIO_UNIT Ricardo Ribalda
2020-12-23 11:15 ` Laurent Pinchart
2020-12-22 23:04 ` [PATCH v6 07/11] media: uvcvideo: Add Privacy control based on EXT_GPIO Ricardo Ribalda
2020-12-22 23:04 ` Ricardo Ribalda [this message]
2020-12-22 23:04 ` [PATCH v6 09/11] media: uvcvideo: Use dev_ printk aliases Ricardo Ribalda
2020-12-22 23:04 ` [PATCH v6 10/11] media: uvcvideo: New macro uvc_trace_cont Ricardo Ribalda
2020-12-22 23:04 ` [PATCH v6 11/11] media: uvcvideo: use dev_printk() for uvc_trace() Ricardo Ribalda
2020-12-23 11:29 ` Joe Perches
2020-12-23 13:39 ` Ricardo Ribalda
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=20201222230446.1027916-9-ribalda@chromium.org \
--to=ribalda@chromium.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.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;
as well as URLs for NNTP newsgroup(s).