From patchwork Wed Nov 4 18:07:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11881847 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 81884697 for ; Wed, 4 Nov 2020 18:07:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A3B1206FA for ; Wed, 4 Nov 2020 18:07:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aah+dx1A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732212AbgKDSHt (ORCPT ); Wed, 4 Nov 2020 13:07:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbgKDSHs (ORCPT ); Wed, 4 Nov 2020 13:07:48 -0500 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 2CED8C0613D4 for ; Wed, 4 Nov 2020 10:07:48 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id k18so3190324wmj.5 for ; Wed, 04 Nov 2020 10:07:48 -0800 (PST) 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=KBJdPJKhHMcEG3i3MssFQOTFq5qAUMX15kP0Cu1fqHY=; b=aah+dx1Av5pM+VYV1e9dWE3ehzZ6Vmsu1Py6GgjJk9e/aROc4f5UfmfHeDQljhQN0T CPV7o4E/YzYf8QX6LU01ji019CT/C7s/u1/H4j2x4vCoxvoYL22c2SbuoIr14llnow1u y8+QEf5Ij4uChguyvnyIkeaDyb7U0V0gYQyfY= 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=KBJdPJKhHMcEG3i3MssFQOTFq5qAUMX15kP0Cu1fqHY=; b=YVDKJGdElqMHs7usLLi2Rdfo+Y09jGQ273WM1YfhRMbENZOX7E2YgyZ1euj6qV5biC xbjjMKOs52W9/mZrFeww4i4pJL2hH13UsLBRr087t7d7PBC6DAMw0gsK2EADQo8Ay1CM DjwfZxBRvUQUWzu13ecJseDcDLCY0gCv0th25cmVqFBZtatQ1SZZ9qUriFdCpcNshrvE zmXg0hJMT87zKVNyV4YY1jhEBl8gzl0SAIo1H+3X0T6PFvIM6QC2TruL6xRUSOF9LOtK pipfmOrB+9WL6azVVZLLRJ7v6qjvpGpmYolOA/OUjcm0AR5FvMjqNkwnXoyqW8oCmj03 MQRQ== X-Gm-Message-State: AOAM530aqdF1IAzWX0vDWnMrKNWmDcPTPN7mZ6lbea+aQs6Ld8vaEPPz tZjTX7XH6MqFyk/TJQUUIa3EDA== X-Google-Smtp-Source: ABdhPJyBKEK/HrrERt5hZuIKNep/zDOG7j7Egm92CqgQtPbFdEAPD53XzUWv6ghn9iwHxfvKVG9DRA== X-Received: by 2002:a1c:4b04:: with SMTP id y4mr5985826wma.93.1604513266866; Wed, 04 Nov 2020 10:07:46 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id y10sm3801841wru.94.2020.11.04.10.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:07:46 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v2 1/7] media: uvcvideo: Use pr_cont() macro Date: Wed, 4 Nov 2020 19:07:28 +0100 Message-Id: <20201104180734.286789-2-ribalda@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104180734.286789-1-ribalda@chromium.org> References: <20201104180734.286789-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Replace all the uses of printk(KERN_CONT ... with pr_cont(). Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index ddb9eaa11be7..9fc0b600eab1 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1476,7 +1476,7 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain, switch (UVC_ENTITY_TYPE(entity)) { case UVC_VC_EXTENSION_UNIT: if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " <- XU %d", entity->id); + pr_cont(" <- XU %d", entity->id); if (entity->bNrInPins != 1) { uvc_trace(UVC_TRACE_DESCR, "Extension unit %d has more " @@ -1488,7 +1488,7 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain, case UVC_VC_PROCESSING_UNIT: if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " <- PU %d", entity->id); + pr_cont(" <- PU %d", entity->id); if (chain->processing != NULL) { uvc_trace(UVC_TRACE_DESCR, "Found multiple " @@ -1501,7 +1501,7 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain, case UVC_VC_SELECTOR_UNIT: if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " <- SU %d", entity->id); + pr_cont(" <- SU %d", entity->id); /* Single-input selector units are ignored. */ if (entity->bNrInPins == 1) @@ -1520,7 +1520,7 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain, case UVC_ITT_CAMERA: case UVC_ITT_MEDIA_TRANSPORT_INPUT: if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " <- IT %d\n", entity->id); + pr_cont(" <- IT %d\n", entity->id); break; @@ -1528,17 +1528,17 @@ static int uvc_scan_chain_entity(struct uvc_video_chain *chain, case UVC_OTT_DISPLAY: case UVC_OTT_MEDIA_TRANSPORT_OUTPUT: if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " OT %d", entity->id); + pr_cont(" OT %d", entity->id); break; case UVC_TT_STREAMING: if (UVC_ENTITY_IS_ITERM(entity)) { if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " <- IT %d\n", entity->id); + pr_cont(" <- IT %d\n", entity->id); } else { if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " OT %d", entity->id); + pr_cont(" OT %d", entity->id); } break; @@ -1588,9 +1588,9 @@ static int uvc_scan_chain_forward(struct uvc_video_chain *chain, list_add_tail(&forward->chain, &chain->entities); if (uvc_trace_param & UVC_TRACE_PROBE) { if (!found) - printk(KERN_CONT " (->"); + pr_cont(" (->"); - printk(KERN_CONT " XU %d", forward->id); + pr_cont(" XU %d", forward->id); found = 1; } break; @@ -1608,16 +1608,16 @@ static int uvc_scan_chain_forward(struct uvc_video_chain *chain, list_add_tail(&forward->chain, &chain->entities); if (uvc_trace_param & UVC_TRACE_PROBE) { if (!found) - printk(KERN_CONT " (->"); + pr_cont(" (->"); - printk(KERN_CONT " OT %d", forward->id); + pr_cont(" OT %d", forward->id); found = 1; } break; } } if (found) - printk(KERN_CONT ")"); + pr_cont(")"); return 0; } @@ -1643,7 +1643,7 @@ static int uvc_scan_chain_backward(struct uvc_video_chain *chain, } if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " <- IT"); + pr_cont(" <- IT"); chain->selector = entity; for (i = 0; i < entity->bNrInPins; ++i) { @@ -1664,14 +1664,14 @@ static int uvc_scan_chain_backward(struct uvc_video_chain *chain, } if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT " %d", term->id); + pr_cont(" %d", term->id); list_add_tail(&term->chain, &chain->entities); uvc_scan_chain_forward(chain, term, entity); } if (uvc_trace_param & UVC_TRACE_PROBE) - printk(KERN_CONT "\n"); + pr_cont("\n"); id = 0; break; From patchwork Wed Nov 4 18:07:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11881851 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 C48BA16C1 for ; Wed, 4 Nov 2020 18:07:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D9D22087D for ; Wed, 4 Nov 2020 18:07:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ZK73jgWM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732255AbgKDSHy (ORCPT ); Wed, 4 Nov 2020 13:07:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732204AbgKDSHu (ORCPT ); Wed, 4 Nov 2020 13:07:50 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16713C0613D4 for ; Wed, 4 Nov 2020 10:07:49 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id k18so3190353wmj.5 for ; Wed, 04 Nov 2020 10:07:49 -0800 (PST) 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=09aDl4ZmShm7ZTcFx/xGgLsr6c/hfG/TYOh2Eo8wu1E=; b=ZK73jgWMRs9RG//Hq3zS8gfLp23l99spVZhcpaaoAXOjTW+xZ8wZjyZcUxU4kXftJe JSqMUJizqIo9rK/tcCf5qBDuIpvM40+seOC6/Bd38VSbwb3AfZHWiqvsOYcLamrh67io pfMl7ZXyWX+9ybint8oh1Owvz1ikKCh+4IC2I= 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=09aDl4ZmShm7ZTcFx/xGgLsr6c/hfG/TYOh2Eo8wu1E=; b=TiB3R/UYglFlJeFmebvYNTQZAFjqbTHGg64d1VIz0iqC582fZzfIhDjaawMPmGOtxk cdMjqrastNwgAH2Vc03CMm2dUDZ1Pi/Tl9vWSTlLndf7osKduquLUDS6NCKBI/Qacj9e BjWBSkEDEu7MGTJGsny3zzBmFG8GkQV9LgnDF86mlM+CH4s+syCwImuwKpfHFeqFanCS y+NprcYtChfvVXnSwnUSLkxLaRldnHn/jSs9Irajnr8+5/TYthEeQZP8gHk8kaDh8wAT 7u6xzbXq2D4ZHHWZDTJ9IZf3R1YpQJ0+idWUpyXSRd8Y/hHZva7wLH3MZZUnQ+qk9BhC 0h0w== X-Gm-Message-State: AOAM530znLV1LiiK0biHWuJHk1TLHtaOog4FygdhfbrltdXaeeKE59Eg oaIIOJVl4m+7xMjioss8FLkaPA== X-Google-Smtp-Source: ABdhPJzufMPX2mGMtpxpxncJqaX/J71zkjGVYhYI2ZnRmXcsLl80pCF7ixko3HUzhQbKqT8p0EoYOQ== X-Received: by 2002:a05:600c:210:: with SMTP id 16mr5794857wmi.122.1604513267660; Wed, 04 Nov 2020 10:07:47 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id y10sm3801841wru.94.2020.11.04.10.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:07:47 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v2 2/7] media: uvcvideo: Move guid to entity Date: Wed, 4 Nov 2020 19:07:29 +0100 Message-Id: <20201104180734.286789-3-ribalda@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104180734.286789-1-ribalda@chromium.org> References: <20201104180734.286789-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Instead of having multiple copies of the entity guid on the code, move it to the entity structure. Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 30 ++++-------------------------- drivers/media/usb/uvc/uvc_driver.c | 21 +++++++++++++++++++-- drivers/media/usb/uvc/uvcvideo.h | 2 +- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index f479d8971dfb..0e480b75e724 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -826,31 +826,10 @@ static void uvc_set_le_value(struct uvc_control_mapping *mapping, * Terminal and unit management */ -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 int uvc_entity_match_guid(const struct uvc_entity *entity, - const u8 guid[16]) + const u8 guid[16]) { - switch (UVC_ENTITY_TYPE(entity)) { - case UVC_ITT_CAMERA: - return memcmp(uvc_camera_guid, guid, 16) == 0; - - case UVC_ITT_MEDIA_TRANSPORT_INPUT: - return memcmp(uvc_media_transport_input_guid, guid, 16) == 0; - - case UVC_VC_PROCESSING_UNIT: - return memcmp(uvc_processing_guid, guid, 16) == 0; - - case UVC_VC_EXTENSION_UNIT: - return memcmp(entity->extension.guidExtensionCode, - guid, 16) == 0; - - default: - return 0; - } + return memcmp(entity->guid, guid, sizeof(entity->guid)) == 0; } /* ------------------------------------------------------------------------ @@ -1776,8 +1755,7 @@ static int uvc_ctrl_fill_xu_info(struct uvc_device *dev, if (data == NULL) return -ENOMEM; - memcpy(info->entity, ctrl->entity->extension.guidExtensionCode, - sizeof(info->entity)); + memcpy(info->entity, ctrl->entity->guid, sizeof(info->entity)); info->index = ctrl->index; info->selector = ctrl->index + 1; @@ -1883,7 +1861,7 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain, if (!found) { uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u not found.\n", - entity->extension.guidExtensionCode, xqry->selector); + entity->guid, xqry->selector); return -ENOENT; } diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 9fc0b600eab1..77fea26faa9a 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1019,6 +1019,11 @@ static int uvc_parse_streaming(struct uvc_device *dev, return ret; } +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_processing_guid[16] = UVC_GUID_UVC_PROCESSING; + static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id, unsigned int num_pads, unsigned int extra_size) { @@ -1038,6 +1043,18 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id, entity->id = id; entity->type = type; + switch (type) { + case UVC_ITT_CAMERA: + memcpy(entity->guid, uvc_camera_guid, 16); + break; + case UVC_ITT_MEDIA_TRANSPORT_INPUT: + memcpy(entity->guid, uvc_media_transport_input_guid, 16); + break; + case UVC_VC_PROCESSING_UNIT: + memcpy(entity->guid, uvc_processing_guid, 16); + break; + } + entity->num_links = 0; entity->num_pads = num_pads; entity->pads = ((void *)(entity + 1)) + extra_size; @@ -1109,7 +1126,7 @@ static int uvc_parse_vendor_control(struct uvc_device *dev, if (unit == NULL) return -ENOMEM; - memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); + memcpy(unit->guid, &buffer[4], 16); unit->extension.bNumControls = buffer[20]; memcpy(unit->baSourceID, &buffer[22], p); unit->extension.bControlSize = buffer[22+p]; @@ -1368,7 +1385,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev, if (unit == NULL) return -ENOMEM; - memcpy(unit->extension.guidExtensionCode, &buffer[4], 16); + memcpy(unit->guid, &buffer[4], 16); unit->extension.bNumControls = buffer[20]; memcpy(unit->baSourceID, &buffer[22], p); unit->extension.bControlSize = buffer[22+p]; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index a3dfacf069c4..df7bf2d104a3 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -304,6 +304,7 @@ struct uvc_entity { u8 id; u16 type; char name[64]; + u8 guid[16]; /* Media controller-related fields. */ struct video_device *vdev; @@ -342,7 +343,6 @@ struct uvc_entity { } selector; struct { - u8 guidExtensionCode[16]; u8 bNumControls; u8 bControlSize; u8 *bmControls; From patchwork Wed Nov 4 18:07:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11881857 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 4FCAB697 for ; Wed, 4 Nov 2020 18:08:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AA8120825 for ; Wed, 4 Nov 2020 18:08:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ACgVABxV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732246AbgKDSHx (ORCPT ); Wed, 4 Nov 2020 13:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732228AbgKDSHv (ORCPT ); Wed, 4 Nov 2020 13:07:51 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD1A2C061A4D for ; Wed, 4 Nov 2020 10:07:49 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id w1so23110491wrm.4 for ; Wed, 04 Nov 2020 10:07:49 -0800 (PST) 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=d3yal1NPjyXYa+Lww+W7he31FAQCpjt9AFpTy83XXP4=; b=ACgVABxVnSQoCwu/ik/Mj1Ugn0BE388tkndbp6DYWRoaN+I2DhX72YaXkq76rUxAYN OMF2vNJX67B+O8JZ0EaYk7Qhyml/0drDeaL3g4Njnmta6C6cPkVFiR3jTm4Ns6yJ2L5C oA+upDgPWipTUA4HfLrdY7JeG753mRtFUoPYQ= 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=d3yal1NPjyXYa+Lww+W7he31FAQCpjt9AFpTy83XXP4=; b=oKIjRndyXM556Z2h6wF+YKpBuv+NbYkQd4HyAIZzwx53u+SLDik06x7mnWmr7vgW89 F8CnrduJs4zdV854HduwptTG65LJ+b1VGkx1tcRmhd2LImr/rG37Nx2I7ZkVywOYDmgS kwj7dw7b398lU+TvdEkCf9tD6GUus/wexZ6hhX6Qwbi/8lgZwQZ5K2RIgxnc9vCgCW8i wAqYHGyHZfkyMU73dCZIifmdU4SXf/pUIMQ3wuZ1ruqlUBm2wJ+OWRc9sKX7rDONpKPz svjtgWdnxEOHlxgPmp3Q0HmKjnfYHMFN91j+mnmYO2Yr4k2+GyzmGzUY1rU7mC8ouGyQ 85Xw== X-Gm-Message-State: AOAM531LsRq2jo1y2K/cUMv18wz1JCgF3D3xdCQN2UQMwflTqt5edUoH rT5Li8LqsYbPNsx5Bkfpb2kTLA== X-Google-Smtp-Source: ABdhPJwPT8KhxLmALamllLMYJJmBdpDMzjsFUeGmAeQ7Fqt++EYBbuSBNXrWY+Opc7oiAfqQuu3AjQ== X-Received: by 2002:adf:e4ca:: with SMTP id v10mr35571120wrm.53.1604513268606; Wed, 04 Nov 2020 10:07:48 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id y10sm3801841wru.94.2020.11.04.10.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:07:48 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v2 3/7] media: uvcvideo: Allow external entities Date: Wed, 4 Nov 2020 19:07:30 +0100 Message-Id: <20201104180734.286789-4-ribalda@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104180734.286789-1-ribalda@chromium.org> References: <20201104180734.286789-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Increase the size of the id, to avoid collisions with external entities. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 2 +- drivers/media/usb/uvc/uvcvideo.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 77fea26faa9a..7a1b2decccc8 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1024,7 +1024,7 @@ static const u8 uvc_media_transport_input_guid[16] = UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; -static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id, +static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, unsigned int num_pads, unsigned int extra_size) { struct uvc_entity *entity; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index df7bf2d104a3..00f985001c1d 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -301,7 +301,7 @@ struct uvc_entity { * chain. */ unsigned int flags; - u8 id; + u16 id; /* 0-255: usb entity. 256-65535: external entities */ u16 type; char name[64]; u8 guid[16]; From patchwork Wed Nov 4 18:07:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11881859 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 DF66D139F for ; Wed, 4 Nov 2020 18:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB5A520759 for ; Wed, 4 Nov 2020 18:08:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CsTUsHFo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732239AbgKDSHx (ORCPT ); Wed, 4 Nov 2020 13:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732225AbgKDSHv (ORCPT ); Wed, 4 Nov 2020 13:07:51 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86159C040203 for ; Wed, 4 Nov 2020 10:07:50 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id k10so21746930wrw.13 for ; Wed, 04 Nov 2020 10:07:50 -0800 (PST) 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=VfhCDV/n9idjZ/d3QJ4jFPIhhk5FgusiEPH5kI39Shw=; b=CsTUsHFoi2cq5mlqNEg6Q8YdypKf+v8flbBmVvC2TFeHrP3SPfIp00pkrgMBBt4FL0 a9Ulz06vG3ReIa2RC9wMhRau8jI1CF6/TBPVfn51WDviXxUh9+5mAUZoPRC2/2ENB082 bXrjXU1J7l4yKtg6v2T6u8LZcWbh5J6f3b998= 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=VfhCDV/n9idjZ/d3QJ4jFPIhhk5FgusiEPH5kI39Shw=; b=R9cVytKtXlDt3WNujebIUjLGLUCcpRHHEa4b6ULmqwaQN4VdI8D9x16HvqqLcVw+Kv gnLjLa+/SZ1oEg6DhkXZVYNMno/LtMWoBY7hru83ngaMJ99BlR1l7349DiWJQzrLdiu1 +8bqHn16qm1UZgc6TTHs/eVlwWcM0D/ScqZANWrkS5S0ZTVfzzMiLyWKC0IvWC81mpks /myAsiDFfZ9aPjlMjrYZVL410yZtuSpFjb1V0WJfpp+Q1Tw/mZqO7S66/uUPkRTzCQEp 5QhDe7UsgnlcNolSbnx0jcwgCnkeIqDLToqD+GOPtQbgsBnpQfsVxLxajsAgovu+WkKY IEOQ== X-Gm-Message-State: AOAM533RzRr2q+cW0dtc477BdSWgy19qR9okEeWBtIh4plrcQnXKTWQS DbPr9Y5ciWGBC70VzLpLoVnlWg== X-Google-Smtp-Source: ABdhPJzzX85rrIcPc4D40s3Cht5BnMBvX0o1FGEgI1vk1Pl239321KjQC0eOL7x62pZeYBZOv4XeLg== X-Received: by 2002:a5d:6cc9:: with SMTP id c9mr36246646wrc.276.1604513269347; Wed, 04 Nov 2020 10:07:49 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id y10sm3801841wru.94.2020.11.04.10.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:07:49 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v2 4/7] media: uvcvideo: Allow entities with no pads Date: Wed, 4 Nov 2020 19:07:31 +0100 Message-Id: <20201104180734.286789-5-ribalda@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104180734.286789-1-ribalda@chromium.org> References: <20201104180734.286789-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Avoid an underflow while calculating the number of inputs for entities with zero pads. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 7a1b2decccc8..27acc221f0d6 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1033,7 +1033,11 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, unsigned int i; extra_size = roundup(extra_size, sizeof(*entity->pads)); - num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1; + if (num_pads) + num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : + num_pads - 1; + else + num_inputs = 0; size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads + num_inputs; entity = kzalloc(size, GFP_KERNEL); @@ -1061,7 +1065,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, for (i = 0; i < num_inputs; ++i) entity->pads[i].flags = MEDIA_PAD_FL_SINK; - if (!UVC_ENTITY_IS_OTERM(entity)) + if (!UVC_ENTITY_IS_OTERM(entity) && num_pads) entity->pads[num_pads-1].flags = MEDIA_PAD_FL_SOURCE; entity->bNrInPins = num_inputs; From patchwork Wed Nov 4 18:07:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11881849 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 2C438697 for ; Wed, 4 Nov 2020 18:07:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00193206CB for ; Wed, 4 Nov 2020 18:07:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XQy+ahFQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732253AbgKDSHy (ORCPT ); Wed, 4 Nov 2020 13:07:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732231AbgKDSHw (ORCPT ); Wed, 4 Nov 2020 13:07:52 -0500 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 393EEC0401C1 for ; Wed, 4 Nov 2020 10:07:51 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id h2so651140wmm.0 for ; Wed, 04 Nov 2020 10:07:51 -0800 (PST) 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=JTfpViGp/YAR6eiRBzwI3JOg4O3Heq9bwynk1bWiaJc=; b=XQy+ahFQF4UaoqmnsYHhsBvX6grINJ8mOqmb4n3whQ2VJAH53HkpDJ+t7dS4NjvG65 dwFnIlBMu3R0Ze6S6qDLXK2EZAux7WO/B1/F4Z6ByveOBpDvRT3Myadt9+lc+Eup1K6q szK3NmINoG4MX7QNVVbqHOVGDew8/s8D+sShg= 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=JTfpViGp/YAR6eiRBzwI3JOg4O3Heq9bwynk1bWiaJc=; b=ruFVSBHuS7AsFrimDr01x2TdQzUAWoCCeb6D+ES8X0T0/vW1Cc/zayoNcpn5Hlyeoe 72LEzvs4pCHzliagEySDYzdnUUdbJxM0DN+SuV1P5rB0RkWiEM6DJzkOMAFH7NdkbRMF rAGld2lTsIDAvbNJI6z0QnaOceHnex50+vRkUw8MHV7dPvGXXAbZ6pXc4+gB+6ThKAb1 fnwifrIzU9Ctj/FXIvioKmoCbcUau2WyAP2C+7jSN8GO1Mn1JdZX1NLhxiqS+yw3WsjH gIfmMocXHdDnRoqlAaYKOPnHyTt8WFQ5ZFCnqgNpP52jCu7WASzda2mUH51z+UGkbacK uuhA== X-Gm-Message-State: AOAM530/efEjYXJORRQsZTiD/Cv6a6uBOtchi8IjuG/PHLtMBFw4BZrA e9a2Ix2YWWniCscQGiSXH7l1FQ== X-Google-Smtp-Source: ABdhPJw6gti+ZBgjhBtFsUallZansd5igSs/VbMB/P6MMiDr5Df+oTbk5CEoHdkq4s9PnLcfQ8ynWw== X-Received: by 2002:a1c:9ec9:: with SMTP id h192mr5908044wme.8.1604513270005; Wed, 04 Nov 2020 10:07:50 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id y10sm3801841wru.94.2020.11.04.10.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:07:49 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v2 5/7] media: uvcvideo: Entity defined get_info and get_cur Date: Wed, 4 Nov 2020 19:07:32 +0100 Message-Id: <20201104180734.286789-6-ribalda@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104180734.286789-1-ribalda@chromium.org> References: <20201104180734.286789-1-ribalda@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Allows controls to get their properties and 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 | 21 +++++++++++++++++---- drivers/media/usb/uvc/uvcvideo.h | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 0e480b75e724..076f63af1031 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -980,10 +980,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, + if (ctrl->entity->get_cur) { + 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; @@ -1687,8 +1696,12 @@ 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->entity->get_info) + ret = ctrl->entity->get_info(ctrl->entity, ctrl->info.selector, + data); + 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 00f985001c1d..776b083ed466 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; }; From patchwork Wed Nov 4 18:07:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11881855 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 2E825139F for ; Wed, 4 Nov 2020 18:08:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECDCD20936 for ; Wed, 4 Nov 2020 18:08:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Zs+We18F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732344AbgKDSIJ (ORCPT ); Wed, 4 Nov 2020 13:08:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732228AbgKDSHy (ORCPT ); Wed, 4 Nov 2020 13:07:54 -0500 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 0163EC0401C4 for ; Wed, 4 Nov 2020 10:07:52 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id h62so3211691wme.3 for ; Wed, 04 Nov 2020 10:07:51 -0800 (PST) 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=RJh2fYDvOJ5ldvaxv73K3rFq8dcfyeUCeQ9u9mUrnFQ=; b=Zs+We18Ffmjwoj6BNEKSWXq69LCB/hg65EupRsPE6yDvoEeU5+zwn/xaFHQL6fjv84 vchkzIwjCVSxq4O2/4PhIMVQ6qfiLE1VRLIMc5R5Zo8ertwFkMBshXg26ETyK21BFK01 izN0gzx3Z8vk+QxugiEml6bd1y2TlzSNyZUyI= 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=RJh2fYDvOJ5ldvaxv73K3rFq8dcfyeUCeQ9u9mUrnFQ=; b=YHz6BYqYST/6kGNDC4651+JcfT23AJbdLsvI3SVJf6UuztQR3LJ02JthpB4+X0kFlw i2qqTWfEhjzl5NIqe1UcTo2HNpL6OUxMH1CBJXsrqfeIyt8O9HEeaKjSWFdYZGSWhi3z 6qconcDRT61V5JuuUqY2Mfl4V1sMT3+EBXJyBgLZXrqJijn0N/vBTUmna0jwwD748DuR KINMnEBiQLfwhj+0en46GS6u2YbNnTbAen3KVpJ3xlMyYO9VooxUHnwWw2p+h48nwvwa 0+dSTinzxSOH6xcSV0zZjl8AEuu65gMEOwIGnz8/HVqdnwnoB5k8SmT10nuYr0F3+1/b 1ADw== X-Gm-Message-State: AOAM533hodEwI7Z174hbMp2X7xZ5cxdypBsMN5DwH4TULJGmVpLXsQ+k UW4L2ygs3zu7sqSVoXHtbyXrKg== X-Google-Smtp-Source: ABdhPJy9YWuM2YBOLxZkoV/vVdDG4dlBXQMW2ikusfmDHzxLXTp8SIVytRXe09XgYMRvIYQIIHwx0A== X-Received: by 2002:a7b:cb09:: with SMTP id u9mr5915017wmj.49.1604513270665; Wed, 04 Nov 2020 10:07:50 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id y10sm3801841wru.94.2020.11.04.10.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:07:50 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v2 6/7] media: uvcvideo: Implement UVC_EXT_GPIO_UNIT Date: Wed, 4 Nov 2020 19:07:33 +0100 Message-Id: <20201104180734.286789-7-ribalda@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104180734.286789-1-ribalda@chromium.org> References: <20201104180734.286789-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: Scope (\_SB.PCI0.XHCI.RHUB.HS07) { /.../ 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 | 6 ++ drivers/media/usb/uvc/uvc_driver.c | 105 +++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 12 ++++ 3 files changed, 123 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 076f63af1031..f9382f8c10a8 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1301,6 +1301,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); @@ -2285,6 +2288,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_EXT_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 27acc221f0d6..bb977b333752 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 @@ -1020,6 +1021,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, } static const u8 uvc_camera_guid[16] = UVC_GUID_UVC_CAMERA; +static const u8 uvc_gpio_guid[16] = UVC_GUID_EXT_GPIO_CONTROLLER; static const u8 uvc_media_transport_input_guid[16] = UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT; static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; @@ -1048,6 +1050,9 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, entity->type = type; switch (type) { + case UVC_EXT_GPIO_UNIT: + memcpy(entity->guid, uvc_gpio_guid, 16); + break; case UVC_ITT_CAMERA: memcpy(entity->guid, uvc_camera_guid, 16); break; @@ -1461,6 +1466,92 @@ 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 irqreturn_t uvc_privacy_gpio_irq(int irq, void *data) +{ + struct uvc_device *dev = data; + struct uvc_video_chain *chain; + struct uvc_entity *unit; + u8 value; + + /* GPIO entities are always on the first chain */ + chain = list_first_entry(&dev->chains, struct uvc_video_chain, list); + list_for_each_entry(unit, &dev->entities, list) { + if (UVC_ENTITY_TYPE(unit) != UVC_EXT_GPIO_UNIT) + continue; + value = gpiod_get_value(unit->gpio.gpio_privacy); + uvc_ctrl_status_event(NULL, chain, unit->controls, &value); + return IRQ_HANDLED; + } + + return IRQ_HANDLED; +} + +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_EXT_GPIO_UNIT, UVC_EXT_GPIO_UNIT_ID, 0, 1); + 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); + + 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_TRIGGER_FALLING | IRQF_TRIGGER_RISING, + "uvc_privacy_gpio", dev); + if (ret < 0) + dev_warn(&dev->udev->dev, + "Unable to request uvc_privacy_gpio irq. Continuing\n"); + + return 0; +} + /* ------------------------------------------------------------------------ * UVC device scan */ @@ -1912,6 +2003,7 @@ static int uvc_scan_device(struct uvc_device *dev) { struct uvc_video_chain *chain; struct uvc_entity *term; + struct uvc_entity *unit; list_for_each_entry(term, &dev->entities, list) { if (!UVC_ENTITY_IS_OTERM(term)) @@ -1950,6 +2042,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(unit, &dev->entities, list) { + if (UVC_ENTITY_TYPE(unit) == UVC_EXT_GPIO_UNIT) + list_add_tail(&unit->chain, &chain->entities); + } + return 0; } @@ -2282,6 +2381,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 776b083ed466..689f95ff4f12 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,8 @@ (UVC_ENTITY_IS_TERM(entity) && \ ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) +#define UVC_EXT_GPIO_UNIT 0x7ffe +#define UVC_EXT_GPIO_UNIT_ID 0x100 /* ------------------------------------------------------------------------ * GUIDs @@ -56,6 +59,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 \ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03} #define UVC_GUID_FORMAT_MJPEG \ { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \ @@ -348,6 +354,12 @@ struct uvc_entity { u8 *bmControls; u8 *bmControlsType; } extension; + + struct { + u8 bControlSize; + u8 *bmControls; + struct gpio_desc *gpio_privacy; + } gpio; }; u8 bNrInPins; From patchwork Wed Nov 4 18:07:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 11881853 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 832C4139F for ; Wed, 4 Nov 2020 18:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A1D22083B for ; Wed, 4 Nov 2020 18:08:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IBYm2Gr8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732261AbgKDSHz (ORCPT ); Wed, 4 Nov 2020 13:07:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732236AbgKDSHx (ORCPT ); Wed, 4 Nov 2020 13:07:53 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3D10C0613D4 for ; Wed, 4 Nov 2020 10:07:52 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id x7so23089232wrl.3 for ; Wed, 04 Nov 2020 10:07:52 -0800 (PST) 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=Nmto78jsH6BP6EX0aLno4Xjo3zNTYMaOPlWvmD+y/wA=; b=IBYm2Gr8EXSUOYL6JJZjaMkyyFYG6BPmGFxxSeNIp9Nf5XEOxreKOMsN0y2MlluiND nnGl5AoNkXTonVo+vPsF9HBVvcCFU/TLq4qK+FyvMQNX9rEcjciurjcaIP5cW6vFJLg/ yJ52SUEbHyyO1YelKxpa/piYskUD+jI35yF0k= 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=Nmto78jsH6BP6EX0aLno4Xjo3zNTYMaOPlWvmD+y/wA=; b=fWMTvsgFYAqnne0UMFmBBEz9yAFmx6GRQ35ZKaqT5cyBn2lLWHzzdmDjahn5RrxcE/ bfWOpUgiyI7pHt2Zk47mwDSdiqxe4Ujb573WN0/+f8pqKOIrzlwOPJpA3k4oQJMGBNvS o6ihXMIxINofHTDRVJYDMo3+j8vM6N2YAiwNA/hRkZ+cXjejmW6i0EuVGXn14o6gCn6N 3+UAOGz+0r/gaW7bxcnzy/pDZaT+6RQTw7f3HfreaKzBMeP0PCw9db8C66qhv/QOsFxv IV5dS7F8ZwC666BvG8D0ACefCisLhG9PJKgNPUfxxIyEAYuU7+J3kZqaCgqla9BR2WFc TjPA== X-Gm-Message-State: AOAM532AjIOmYKBUY1YeZv1e/841CLg+akHs8xFjLaX/zzGFKk96QSXq w+rJGiFCMqHHGdOEgwJS5FeacQ== X-Google-Smtp-Source: ABdhPJzuXIR9p1qoOh6D+1lieXOhk8pgGbPZS4owSlNy7AgFeX0GWLwWa8ZjCqRdgD0pzH57cb0j9g== X-Received: by 2002:a5d:6ac6:: with SMTP id u6mr24341534wrw.145.1604513271613; Wed, 04 Nov 2020 10:07:51 -0800 (PST) Received: from alco.lan ([80.71.134.83]) by smtp.gmail.com with ESMTPSA id y10sm3801841wru.94.2020.11.04.10.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:07:51 -0800 (PST) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH v2 7/7] media: uvcvideo: Add Privacy control based on EXT_GPIO Date: Wed, 4 Nov 2020 19:07:34 +0100 Message-Id: <20201104180734.286789-8-ribalda@chromium.org> X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog In-Reply-To: <20201104180734.286789-1-ribalda@chromium.org> References: <20201104180734.286789-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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index f9382f8c10a8..285a7a5e15d2 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -347,6 +347,14 @@ 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, + }, }; static const struct uvc_menu_info power_line_frequency_controls[] = { @@ -735,6 +743,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, + }, }; /* ------------------------------------------------------------------------