From patchwork Thu Oct 22 13:37:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11851437 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8E2C14B7 for ; Thu, 22 Oct 2020 13:38:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EA59241A3 for ; Thu, 22 Oct 2020 13:38:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KIYVlz1d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2900273AbgJVNi2 (ORCPT ); Thu, 22 Oct 2020 09:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900193AbgJVNh6 (ORCPT ); Thu, 22 Oct 2020 09:37:58 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4508BC0613CE for ; Thu, 22 Oct 2020 06:37:58 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id d78so2138415wmd.3 for ; Thu, 22 Oct 2020 06:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WdKYKANqyDji6M6kylMPVeVh8pZvdLMVlAzAT/a7CSQ=; b=KIYVlz1dtTEMD20BXN2L33ew12vdB/3MM+nyziXAQ5KVCWgQeSNpbBYv0glYIYcLpN Wkgw7dc5YZPCpHX+38jXnfz3cEbPzF6e9aCQB/bfddTz6/dRTWdtIHHPJCbrZ6rIcATi xSFatDUf+2nkuYIVkL2svMcBCA8E38UBFcvzY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WdKYKANqyDji6M6kylMPVeVh8pZvdLMVlAzAT/a7CSQ=; b=C7zx6xqoNmEzdKwA++E7vjV5jGTxdXXn/r6WO5dtogEb0rZx6CIAv8S9a//FeekkCn 2KpfrZZBfsxeLx0bMo0YTtZ0V0BdLxdYP4iXrWpnQO6z98++T2T3GMf9wCl4acWoHcMQ QIZVWsmHNc1a8ObPYfQK3UFYwlh/p+0wMkJDw2NvoEVynGhfvrw9Kz888eK7GqAmCLpS z7WaZbRWah0UrEzs3YDUNuX0ip+hhZuHu9sb5rZnBpoNlsccSbRUdSH7sjRlFY349KuK I1YodQ2xfxl9/MBUwJO7LMQg6y/MTY3pGDyJ7flLpYYWhHaUOlmQONY4MpA70SLSVLFr 0UEw== X-Gm-Message-State: AOAM530wFeE3U6S5kUEZwHpUqsVWoOH5LO3681igWYBUaKIKOAVoIxuK zRkr2mn3hBTULGEwoXiIrIatqw== X-Google-Smtp-Source: ABdhPJxtG87peUAj9nUcOJZ6kJ3GfgLcVifZfsIilxdCmYeKjXrDcFn72DSZZaOVqn63oI0RNI6EWA== X-Received: by 2002:a1c:7707:: with SMTP id t7mr2777097wmi.54.1603373876961; Thu, 22 Oct 2020 06:37:56 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q10sm4094031wrp.83.2020.10.22.06.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:37:56 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tfiga@chromium.org, Ricardo Ribalda Subject: [PATCH 1/6] media: uvcvideo: Add UVC_CTRL_FLAG_ENTITY_GET_INFO Date: Thu, 22 Oct 2020 15:37:48 +0200 Message-Id: <20201022133753.310506-2-ribalda@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022133753.310506-1-ribalda@chromium.org> References: <20201022133753.310506-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This flag allows controls to get their properties from an entity defined function instead of via a query to the USB device. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 9 +++++++-- drivers/media/usb/uvc/uvcvideo.h | 3 +++ include/uapi/linux/uvcvideo.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index f479d8971dfb..7acdc055613b 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1708,8 +1708,13 @@ static int uvc_ctrl_get_flags(struct uvc_device *dev, if (data == NULL) return -ENOMEM; - ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, - info->selector, data, 1); + if (ctrl->info.flags & UVC_CTRL_FLAG_ENTITY_GET_INFO) + ret = ctrl->entity->get_info ? + ctrl->entity->get_info(ctrl->entity, ctrl->info.selector, data) : + -EINVAL; + else + ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, + info->selector, data, 1); if (!ret) info->flags |= (data[0] & UVC_CONTROL_CAP_GET ? UVC_CTRL_FLAG_GET_CUR : 0) diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index a3dfacf069c4..08922d889bb6 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -353,6 +353,9 @@ struct uvc_entity { u8 bNrInPins; u8 *baSourceID; + int (*get_info)(struct uvc_entity *entity, u8 cs, u8 *caps); + int (*get_cur)(struct uvc_entity *entity, u8 cs, void *data, u16 size); + unsigned int ncontrols; struct uvc_control *controls; }; diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h index f80f05b3c423..69b636290c31 100644 --- a/include/uapi/linux/uvcvideo.h +++ b/include/uapi/linux/uvcvideo.h @@ -30,6 +30,8 @@ #define UVC_CTRL_FLAG_AUTO_UPDATE (1 << 7) /* Control supports asynchronous reporting */ #define UVC_CTRL_FLAG_ASYNCHRONOUS (1 << 8) +/* Entity queries */ +#define UVC_CTRL_FLAG_ENTITY_GET_INFO (1 << 9) #define UVC_CTRL_FLAG_GET_RANGE \ (UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_GET_MIN | \ From patchwork Thu Oct 22 13:37:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11851429 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87D6961C for ; Thu, 22 Oct 2020 13:38:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E103241A3 for ; Thu, 22 Oct 2020 13:38:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="D0Ao1njO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2900215AbgJVNiB (ORCPT ); Thu, 22 Oct 2020 09:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900201AbgJVNh7 (ORCPT ); Thu, 22 Oct 2020 09:37:59 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D66FC0613CE for ; Thu, 22 Oct 2020 06:37:59 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id c194so2143980wme.2 for ; Thu, 22 Oct 2020 06:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zZZV4ffF4t+t01RKSJGPFAOGdVaSv3k/nLSd6l7lD08=; b=D0Ao1njOzjQ6IdZQAHxd1A84huIlTvUCJTXCAQhNoKuSjqoOsQF2f/oIMP2oHwGuUA aDTklkY3ju3qD/eM011me8bMYM2usafIifdwMqnqMbq5DcL/M8wKA++WpkYmJW87nuY6 eADppQQcJCeX+tzLYzbtrQ05sjeTG2S4SBWKs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zZZV4ffF4t+t01RKSJGPFAOGdVaSv3k/nLSd6l7lD08=; b=OWiKQf3dXtHnjZrpCS6EUTU0zpZyLJAo8+XlAhrGYg/RnMpRxJa7+uFw3XsrEEjEjx sZ7K1oCT7WxYuJI3xYcWchaYdCQvC40pacVrTeLonCv4qGa/kf4RQgKp6B9Igt3hVWjh EkLBio6SRgvmZvgvoSVkQNDQ9Bdq27s3u9u8wGGP67kDvN2QARHvhZNM7Jb5zh0xYLRm 0xKDXS0CC3aS1yw3XudS8tomVLm8kS+Ub080us+ez+rJH9yU4yy1f4R+0ZYM4iSnwTQo vJYiekeHhovvCsbNKPlm7h2LGKwyXtdRbAPsYFHge7GvrNcco+H26i4V7R4VYxCxq8B7 BUmg== X-Gm-Message-State: AOAM530VlNtWgBw5cDfynuk6wtpkDeVqtr2re1bLNQz0yU02pZbcDy40 7yv3ZIYooMDapBQEQrjhOKH1qg== X-Google-Smtp-Source: ABdhPJyj3CtaDwRNr3rjY7qm50rCEtFan9QRCWUmj128pucNzLwWUz5ZYLrfXEI1xi+6UeaA+I7HJQ== X-Received: by 2002:a1c:b657:: with SMTP id g84mr2589725wmf.0.1603373878059; Thu, 22 Oct 2020 06:37:58 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q10sm4094031wrp.83.2020.10.22.06.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:37:57 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tfiga@chromium.org, Ricardo Ribalda Subject: [PATCH 2/6] media: uvcvideo: Add UVC_CTRL_FLAG_ENTITY_GET_CUR Date: Thu, 22 Oct 2020 15:37:49 +0200 Message-Id: <20201022133753.310506-3-ribalda@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022133753.310506-1-ribalda@chromium.org> References: <20201022133753.310506-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This flag allows controls to get their current value from an entity defined function instead of via a query to the USB device. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 17 +++++++++++++---- include/uapi/linux/uvcvideo.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 7acdc055613b..0a8835742d49 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1001,10 +1001,19 @@ static int __uvc_ctrl_get(struct uvc_video_chain *chain, return -EACCES; if (!ctrl->loaded) { - ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, - chain->dev->intfnum, ctrl->info.selector, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), - ctrl->info.size); + if (ctrl->info.flags & UVC_CTRL_FLAG_ENTITY_GET_CUR) { + if (!ctrl->entity->get_cur) + return -EINVAL; + ret = ctrl->entity->get_cur(ctrl->entity, + ctrl->info.selector, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), + ctrl->info.size); + } else { + ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, ctrl->entity->id, + chain->dev->intfnum, ctrl->info.selector, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), + ctrl->info.size); + } if (ret < 0) return ret; diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h index 69b636290c31..cb91797d2a09 100644 --- a/include/uapi/linux/uvcvideo.h +++ b/include/uapi/linux/uvcvideo.h @@ -32,6 +32,7 @@ #define UVC_CTRL_FLAG_ASYNCHRONOUS (1 << 8) /* Entity queries */ #define UVC_CTRL_FLAG_ENTITY_GET_INFO (1 << 9) +#define UVC_CTRL_FLAG_ENTITY_GET_CUR (1 << 10) #define UVC_CTRL_FLAG_GET_RANGE \ (UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_GET_MIN | \ From patchwork Thu Oct 22 13:37:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11851433 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98DDD61C for ; Thu, 22 Oct 2020 13:38:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 725292463D for ; Thu, 22 Oct 2020 13:38:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="drgjWM3O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2900210AbgJVNiB (ORCPT ); Thu, 22 Oct 2020 09:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900206AbgJVNiA (ORCPT ); Thu, 22 Oct 2020 09:38:00 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC19CC0613CE for ; Thu, 22 Oct 2020 06:37:59 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id c194so2144020wme.2 for ; Thu, 22 Oct 2020 06:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+mHsFLlMVlL11cWsjoM3qFi8Cc1D8z4TpYaeydwCncs=; b=drgjWM3OlnhGwNGhZKErQKrd6uDvrnRJ4cMfZcyLAT9fOmev8q6RXok1j63AtmDCuZ dwG9X71FrdzL9rU/5deqOwGr0W5HZhk6YBNPNmohYHWz/mHBSgoVy954/xCtAQW8vW29 MmItJNGErIuT/74MhrGizN0j+db9hDONJd8/M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+mHsFLlMVlL11cWsjoM3qFi8Cc1D8z4TpYaeydwCncs=; b=srM+TzCuzmHvsk2GGXX643+W/CZ9Qk3he8LqVnSlCtnwP1oop3NT6DtHEVxTqMIlmP 6zJ4fOK/6tbvl28NbGWc8kBnzSramQY2Ef3VBF5EYjf5Eo9pOzFomYHeWVSVU7Pxiflp 1ENl1i7G6G30TB9A2Fffv94IyRbGymMbjHSg/uRdDKdFmovU3M2aBwP1PQPZBgWqXVed GxarKNPj4+xoFQc3gLSTe3P9oWeysyFDkja2+8w5xyh1HXnFNB0eVhwJB8XsihJzyN92 rm97tmtSBDn1oHGP28CbZSZaobhU9X1F6na9bcGHBNxIRU26Uw1jzjp5bVq6+n2LBVeI v+2Q== X-Gm-Message-State: AOAM533LKRPJJOlDAxmi17JQpXVM+NuAFme3o73tJVxv1a7OB3XzUh5K 8IEoVPm2TBbUUR0pSeD0zHrHkg== X-Google-Smtp-Source: ABdhPJyYtzaUhtFF8vMOUrH1wSrwhFdfj98FZ0qf9pSvkbkU+R6OHX9OvtFphu32JgwpBm5eQfElpg== X-Received: by 2002:a1c:dc8b:: with SMTP id t133mr2733099wmg.151.1603373878705; Thu, 22 Oct 2020 06:37:58 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q10sm4094031wrp.83.2020.10.22.06.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:37:58 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tfiga@chromium.org, Ricardo Ribalda Subject: [PATCH 3/6] media: uvcvideo: Add UVC_GUID_EXT_GPIO_CONTROLLER Date: Thu, 22 Oct 2020 15:37:50 +0200 Message-Id: <20201022133753.310506-4-ribalda@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022133753.310506-1-ribalda@chromium.org> References: <20201022133753.310506-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Create a new GUID for GPIO controller entities that do not belong to the USB video device. This GUID is selected on an address range completely different that the UVC standard to avoid collisions. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 4 ++++ drivers/media/usb/uvc/uvcvideo.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 0a8835742d49..913739915863 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -830,6 +830,7 @@ static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; static const u8 uvc_media_transport_input_guid[16] = UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; +static const u8 uvc_gpio_guid[16] = UVC_GUID_EXT_GPIO_CONTROLLER; static int uvc_entity_match_guid(const struct uvc_entity *entity, const u8 guid[16]) @@ -848,6 +849,9 @@ static int uvc_entity_match_guid(const struct uvc_entity *entity, return memcmp(entity->extension.guidExtensionCode, guid, 16) == 0; + case UVC_GPIO_UNIT: + return memcmp(uvc_gpio_guid, guid, 16) == 0; + default: return 0; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 08922d889bb6..8e5a9fc35820 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -56,6 +56,9 @@ #define UVC_GUID_UVC_SELECTOR \ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} +#define UVC_GUID_EXT_GPIO_CONTROLLER \ + {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf, \ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01} #define UVC_GUID_FORMAT_MJPEG \ { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ From patchwork Thu Oct 22 13:37:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11851431 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A575061C for ; Thu, 22 Oct 2020 13:38:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E2FD2463B for ; Thu, 22 Oct 2020 13:38:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AKmlJVaT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2900254AbgJVNiP (ORCPT ); Thu, 22 Oct 2020 09:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900222AbgJVNiC (ORCPT ); Thu, 22 Oct 2020 09:38:02 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA2BBC0613CE for ; Thu, 22 Oct 2020 06:38:00 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id 13so2152624wmf.0 for ; Thu, 22 Oct 2020 06:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8Hb+989JOofjjUh5aGhwd9WAuZ4cL+L7iJMxJ5IqyWA=; b=AKmlJVaT5Hrvhfka8Opvo4KGn4rXOOHMq018iYikKCOr5GKn74IR9yNWaWbyPpg+9Q 7nMmwl5Ts4ahYOEbBKa0G11DXK0YJ9dRIQS9GH+jEbSzijfTgJVA4CKybQn+cy7JwNcR +6r6dsEJXiwc6tHA55H55+gFsHOgYlOT44+HE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Hb+989JOofjjUh5aGhwd9WAuZ4cL+L7iJMxJ5IqyWA=; b=KJJ/+zZfeGvAxkJW3DaH2kuKCvgYNAw2f8WRBPwOkXoJO+LEO5oHElEWDFX5osrogS 1pUpMJEHnjGeOQbP9kK/DKVeamgSLOIPML1y8/3/J9jbMQQBMwCQjYtjBsdy4/UcNY/8 dlCa3aVUiZyEGXJsdKW42PtDesWKAAFSI1m5KNVcro1RDpgkpkes2wxSNydZOlEWaq8A LMOb5VLjmR1YI51jY49bcjhCB7twQEy5yWOCT16W6zg6B4/KI7loZC/4U7s3mRLKudre uYXlKFmH+mXagMhJvdPXz7hUj8wiWFIhGxI+2L75mpt4QzWDcHDt4DO3e2Sn2cVmD2wZ 8cwQ== X-Gm-Message-State: AOAM531G2n4zyhzntcUUNth/e0dOVbnR3TjKIUexfWOTh2IhONY1bVOv 13+fKXwboR/IrpZFQ+uWPySxjg== X-Google-Smtp-Source: ABdhPJwUGkUAkh6z5NDXNn1qijT3VBPtRSez3VFLz5/oC5CV9v2FsLKhesBZ0ALXzqnmqdA+0CjGaA== X-Received: by 2002:a1c:9d54:: with SMTP id g81mr2652082wme.102.1603373879643; Thu, 22 Oct 2020 06:37:59 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q10sm4094031wrp.83.2020.10.22.06.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:37:59 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tfiga@chromium.org, Ricardo Ribalda Subject: [PATCH 4/6] media: uvcvideo: Add Privacy control based on EXT_GPIO Date: Thu, 22 Oct 2020 15:37:51 +0200 Message-Id: <20201022133753.310506-5-ribalda@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022133753.310506-1-ribalda@chromium.org> References: <20201022133753.310506-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a new control and mapping for Privacy controls connected to UVC_GUID_EXT_GPIO_CONTROLLERs. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 20 ++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 913739915863..786498e66646 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -347,6 +347,16 @@ static const struct uvc_control_info uvc_ctrls[] = { | UVC_CTRL_FLAG_RESTORE | UVC_CTRL_FLAG_AUTO_UPDATE, }, + { + .entity = UVC_GUID_EXT_GPIO_CONTROLLER, + .selector = UVC_CT_PRIVACY_CONTROL, + .index = 0, + .size = 1, + .flags = UVC_CTRL_FLAG_GET_CUR + | UVC_CTRL_FLAG_AUTO_UPDATE + | UVC_CTRL_FLAG_ENTITY_GET_INFO + | UVC_CTRL_FLAG_ENTITY_GET_CUR, + }, }; static const struct uvc_menu_info power_line_frequency_controls[] = { @@ -735,6 +745,16 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, }, + { + .id = V4L2_CID_PRIVACY, + .name = "Privacy", + .entity = UVC_GUID_EXT_GPIO_CONTROLLER, + .selector = UVC_CT_PRIVACY_CONTROL, + .size = 1, + .offset = 0, + .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, + .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, + }, }; /* ------------------------------------------------------------------------ diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 8e5a9fc35820..a493bc383d3e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -58,7 +58,7 @@ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} #define UVC_GUID_EXT_GPIO_CONTROLLER \ {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf, \ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01} + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01} #define UVC_GUID_FORMAT_MJPEG \ { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ From patchwork Thu Oct 22 13:37:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11851425 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E07C561C for ; Thu, 22 Oct 2020 13:38:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9FE02465D for ; Thu, 22 Oct 2020 13:38:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SckECCy2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2900224AbgJVNiC (ORCPT ); Thu, 22 Oct 2020 09:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900219AbgJVNiC (ORCPT ); Thu, 22 Oct 2020 09:38:02 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA37EC0613CF for ; Thu, 22 Oct 2020 06:38:01 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id l15so2290786wmi.3 for ; Thu, 22 Oct 2020 06:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LQlAmo6BNhIFqjQ+zkGnWRNX5gpSqBwFOcKZJzUofPg=; b=SckECCy2+VsWIIftp+wBGjSx9MkI4JqmuoATkubZM79pWgywJLF5F3jwXzsdWYhBjL TNDE+aH0mmGaInlW8hc+EdlNsznMVGcwkUdedUMb5b8Z1q3X783cXdfOCv+/Ovb9Y85u huSzLzuCkY3UL2N1ocVMZdjQfhrEnZMyYmKcc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LQlAmo6BNhIFqjQ+zkGnWRNX5gpSqBwFOcKZJzUofPg=; b=lZvlksdhAjJj7t/+3duHp4ofSTkzUcBpaSOeSW1mEAO4a1dgmZMy3iNEkFKBW0jgyr 9VgnHclHwZZYjkGWL9EpO3dnsggpy3/DBI4W4sJ8vGol6WRnIRxX8mmgtxMZhpNYpq9M GGGByUhdI+dXY92E6nRNPUh6BHFsZ5m9ypVDugNkjX7DsU97PmKgGv2349xOWQweDr8s 8bwHtl1iBML34Qh+IvjpNOvpEdUYSFn4sgRdWGwfT3r87EWtJa1c/IaoStvnCPGHbX+/ ACJx62/fBlOAU8cC5QQfG7pzS5dOcw10Ka8n+HSYoFbM6l3FK0eP1cwY0OdLDIFs1dFN 34Wg== X-Gm-Message-State: AOAM531uPUjrBXn8I6RAtw5T+3PFFLe4LXnSrQZ8fHKSlq9IFY68Nfzj iE3BMzgsp6Lj2D8zLJ3jZFjgIw== X-Google-Smtp-Source: ABdhPJyH8dRWJldq/eGklfAVifq8/nLddWUt2x85UlqaF3RnfJ/ybzuVmssu1EkzKPJ/8O5pzgTxPg== X-Received: by 2002:a1c:a749:: with SMTP id q70mr2781440wme.117.1603373880532; Thu, 22 Oct 2020 06:38:00 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q10sm4094031wrp.83.2020.10.22.06.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:38:00 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tfiga@chromium.org, Ricardo Ribalda Subject: [PATCH 5/6] media: uvcvideo: Implement UVC_GPIO_UNIT Date: Thu, 22 Oct 2020 15:37:52 +0200 Message-Id: <20201022133753.310506-6-ribalda@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022133753.310506-1-ribalda@chromium.org> References: <20201022133753.310506-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Some devices can implement a physical switch to disable the input of the camera on demand. Think of it like an elegant privacy sticker. The system can read the status of the privacy switch via a GPIO. It is important to know the status of the switch, e.g. to notify the user when the camera will produce black frames and a videochat application is used. Since the uvc device is not aware of this pin (and it should't), we need to implement a virtual entity that can interact with such pin. The location of the GPIO is specified via acpi or DT. on the usb device Eg: Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings { GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\_SB.PCI0.GPIO", 0x00, ResourceConsumer, , ) { // Pin list 0x0064 } }) Name (_DSD, Package (0x02) // _DSD: Device-Specific Data { ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */, Package (0x01) { Package (0x02) { "privacy-gpio", Package (0x04) { \_SB.PCI0.XHCI.RHUB.HS07, Zero, Zero, One } } } }) Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 3 ++ drivers/media/usb/uvc/uvc_driver.c | 72 ++++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 8 ++++ 3 files changed, 83 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 786498e66646..3a49a1326a90 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2332,6 +2332,9 @@ int uvc_ctrl_init_device(struct uvc_device *dev) } else if (UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) { bmControls = entity->camera.bmControls; bControlSize = entity->camera.bControlSize; + } else if (UVC_ENTITY_TYPE(entity) == UVC_GPIO_UNIT) { + bmControls = entity->gpio.bmControls; + bControlSize = entity->gpio.bControlSize; } /* Remove bogus/blacklisted controls */ diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index ddb9eaa11be7..180e503e900f 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1440,6 +1441,58 @@ static int uvc_parse_control(struct uvc_device *dev) return 0; } +static int uvc_gpio_get_cur(struct uvc_entity *entity, u8 cs, void *data, u16 size) +{ + if ((cs != UVC_CT_PRIVACY_CONTROL) || (size < 1)) + return -EINVAL; + + *(uint8_t *)data = gpiod_get_value(entity->gpio.gpio_privacy); + return 0; +} + +static int uvc_gpio_get_info(struct uvc_entity *entity, u8 cs, u8 *caps) +{ + + if (cs != UVC_CT_PRIVACY_CONTROL) + return -EINVAL; + + *caps = UVC_CONTROL_CAP_GET | UVC_CONTROL_CAP_AUTOUPDATE; + return 0; +} + +static int uvc_parse_gpio(struct uvc_device *dev) +{ + struct uvc_entity *unit; + struct gpio_desc *gpio_privacy; + int irq; + int ret; + + gpio_privacy = devm_gpiod_get_optional(&dev->udev->dev, "privacy", GPIOD_IN); + + if (IS_ERR(gpio_privacy)) + return PTR_ERR(gpio_privacy); + + if (!gpio_privacy) + return 0; + + unit = uvc_alloc_entity(UVC_GPIO_UNIT, 0xff, 1, 2); + if (!unit) + return -ENOMEM; + + unit->gpio.gpio_privacy = gpio_privacy; + unit->gpio.bControlSize = 1; + unit->gpio.bmControls = (u8 *)unit + sizeof(*unit); + unit->gpio.bmControls[0] = 1; + unit->get_cur = uvc_gpio_get_cur; + unit->get_info = uvc_gpio_get_info; + + sprintf(unit->name, "GPIO Unit"); + + list_add_tail(&unit->list, &dev->entities); + + return 0; +} + /* ------------------------------------------------------------------------ * UVC device scan */ @@ -1532,6 +1585,12 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain, break; + case UVC_GPIO_UNIT: + if (uvc_trace_param & UVC_TRACE_PROBE) + printk(KERN_CONT " GPIO %d", entity->id); + + break; + case UVC_TT_STREAMING: if (UVC_ENTITY_IS_ITERM(entity)) { if (uvc_trace_param & UVC_TRACE_PROBE) @@ -1929,6 +1988,13 @@ static int uvc_scan_device(struct uvc_device *dev) return -1; } + /* Add GPIO entities to the first_chain */ + chain = list_first_entry(&dev->chains, struct uvc_video_chain, list); + list_for_each_entry(term, &dev->entities, list) { + if (UVC_ENTITY_TYPE(term) == UVC_GPIO_UNIT) + list_add_tail(&term->chain, &chain->entities); + } + return 0; } @@ -2261,6 +2327,12 @@ static int uvc_probe(struct usb_interface *intf, goto error; } + /* Parse the associated GPIOs */ + if (uvc_parse_gpio(dev) < 0) { + uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC GPIOs\n"); + goto error; + } + uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n", dev->uvc_version >> 8, dev->uvc_version & 0xff, udev->product ? udev->product : "", diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index a493bc383d3e..7ca78005b6a9 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -6,6 +6,7 @@ #error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead." #endif /* __KERNEL__ */ +#include #include #include #include @@ -37,6 +38,7 @@ (UVC_ENTITY_IS_TERM(entity) && \ ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) +#define UVC_GPIO_UNIT 0x7ffe /* ------------------------------------------------------------------------ * GUIDs @@ -351,6 +353,12 @@ struct uvc_entity { u8 *bmControls; u8 *bmControlsType; } extension; + + struct { + u8 bControlSize; + u8 *bmControls; + struct gpio_desc *gpio_privacy; + } gpio; }; u8 bNrInPins; From patchwork Thu Oct 22 13:37:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11851427 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42B1D61C for ; Thu, 22 Oct 2020 13:38:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15E262463F for ; Thu, 22 Oct 2020 13:38:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="nbgJkYp6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2507576AbgJVNiF (ORCPT ); Thu, 22 Oct 2020 09:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900229AbgJVNiE (ORCPT ); Thu, 22 Oct 2020 09:38:04 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9220C0613D2 for ; Thu, 22 Oct 2020 06:38:02 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id 13so2152755wmf.0 for ; Thu, 22 Oct 2020 06:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xuazTAVuWOaGAhXcYUEHC2fhzgfRLU0vFOZpMsy8TBQ=; b=nbgJkYp63m4rmIhHmUxnHZj+Urg/MRZxffOXk3O+VNQTx7AnbH5zQUO+LjDfiC+Tp4 0GFB8MN7piN0yTl8NjYoY+R3Nm+YWKqdoMsvyqAoui0Tae8wwQz+GrCd/h9SYTeqyXsh b229ntFS+4rZoV8tVIw4IybIojU8U9PzrdkJk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xuazTAVuWOaGAhXcYUEHC2fhzgfRLU0vFOZpMsy8TBQ=; b=j/AZuQEBHP5LPsxTNTiptKvh2sC9pOrPmbwxWEdnv6UNDgwRLBHVQsXGd4xAAAx9Kw BBju/M9uAQ7sT6JOFU2zweKOSrnVyh4IzP2sY2nH2zue7qkvBdGb1NWsNJkJdIwqow3C z6mrCvacnzO+ZxKYYI7qTx5z5+w9tLPiI5IVQKw1eQ1hi285izgnFzrb14C8gl1LJwDU GjjMgxL1NKTuPzz7NbW+Wp/S1q166ABxIiMFfQud508QXoUrHi62UtwEs5ifmwkjUE7e lYoB2KKPLqMvkJQZ5e6o9IHWPTAvZ7cvq+wqSgKARTpDEqJo4HWOAQkXGzvVNUzhtPNN D9Vg== X-Gm-Message-State: AOAM531C7Zoyd3js16FPDgNMDinyffpKMCJlognFctukxptpJDPT72fN ZFT5QfosrvxpNeFr3lpPCtxOvA== X-Google-Smtp-Source: ABdhPJyJdhp6mATJXrrc9AyS5uJUoaza7cixAKWOYcnAPxJWO5g8X1tkDeI83moKm80b8WSFXmVBnA== X-Received: by 2002:a1c:7c09:: with SMTP id x9mr2683433wmc.181.1603373881466; Thu, 22 Oct 2020 06:38:01 -0700 (PDT) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id q10sm4094031wrp.83.2020.10.22.06.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 06:38:01 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tfiga@chromium.org, Ricardo Ribalda Subject: [PATCH 6/6] media: uvcvideo: Handle IRQs from the privacy_pin Date: Thu, 22 Oct 2020 15:37:53 +0200 Message-Id: <20201022133753.310506-7-ribalda@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201022133753.310506-1-ribalda@chromium.org> References: <20201022133753.310506-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org If the privacy pin produces an IRQ, read the gpio and notify userspace via an event. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 3 +++ drivers/media/usb/uvc/uvc_driver.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 3a49a1326a90..00c41cba0f68 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1346,6 +1346,9 @@ static void uvc_ctrl_status_event_work(struct work_struct *work) mutex_unlock(&chain->ctrl_mutex); + if (!w->urb) + return; + /* Resubmit the URB. */ w->urb->interval = dev->int_ep->desc.bInterval; ret = usb_submit_urb(w->urb, GFP_KERNEL); diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 180e503e900f..d1260d131bd8 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1460,6 +1460,25 @@ static int uvc_gpio_get_info(struct uvc_entity *entity, u8 cs, u8 *caps) return 0; } +static irqreturn_t uvc_privacy_gpio_irq(int irq, void *data) +{ + struct uvc_device *dev = data; + struct uvc_video_chain *chain; + struct uvc_entity *term; + u8 value; + + list_for_each_entry(chain, &dev->chains, list) { + list_for_each_entry(term, &dev->entities, list) { + if (UVC_ENTITY_TYPE(term) == UVC_GPIO_UNIT) { + value = gpiod_get_value(term->gpio.gpio_privacy); + uvc_ctrl_status_event(NULL, chain, term->controls, &value); + } + } + } + + return IRQ_HANDLED; +} + static int uvc_parse_gpio(struct uvc_device *dev) { struct uvc_entity *unit; @@ -1490,6 +1509,17 @@ static int uvc_parse_gpio(struct uvc_device *dev) list_add_tail(&unit->list, &dev->entities); + irq = gpiod_to_irq(gpio_privacy); + + if (irq == -EPROBE_DEFER) + return -EPROBE_DEFER; + + if (irq < 0) + return 0; + + ret = devm_request_irq(&dev->udev->dev, irq, uvc_privacy_gpio_irq, IRQF_SHARED, + "uvc_privacy_gpio", dev); + return 0; }