From nobody Sat Nov 23 23:39:57 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