From nobody Mon Nov 25 02:57:35 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