From patchwork Thu Nov 3 13:40:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14888 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp544131wru; Thu, 3 Nov 2022 06:52:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4LLPuiX0+IF1pShGMY9BGnHCE3hWRVOFhRsnpT34850lNe24BbrEW5DYCZoJySWe9Wlmrs X-Received: by 2002:a05:6402:510c:b0:462:51ad:2af5 with SMTP id m12-20020a056402510c00b0046251ad2af5mr30735281edd.257.1667483573723; Thu, 03 Nov 2022 06:52:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667483573; cv=none; d=google.com; s=arc-20160816; b=PDJCBS/wDoTlRW5MplyXdQxeysPWSO0KRbOKiehSkR4zc+Kq8y8qM1GyB+CMb0x0OL 9ulo/Jr7P9tOflBxaKMF18ql8Afz2R8XTXCRUTciaof6orJ3SuL8ilS7+et6pcM4Athv LqGq2JwFm+DRMTygZ9JaVg9v3qn3Z6awjVm3QyQmc5/PwB5BTotCN+UjFQR2rm//H90+ 02Pick3Zi+tCKW2SG5LEaYW/olBY9DdbUF2avEcnzsQP72CBkBcVjmGc4SOtrwucEm1c kKrbc0EIRvZMMAkQnkXdE2bPMK+sPh0NepgRDgtomqYXqiQwq6s2eZLkfDvrxkC9B7UQ zaZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=hAg+4sE8YWXZby15NLt6b6O/GKFL5SevR49ad/qG3jk=; b=EzeuaB/dv6wA52PyfaywHcoxPpGoTUqQwezz30h4F9vzzMAjG9jxl6gLeP2uXPkm4s 7JVWvcxyuaVh3Myi0Igq5t7Qaern8cBgWWph7nK+tGCGLxVGFwqTzJRyX+HREvN/7ST0 /57O3lrIeilNT9t2Rhu6IP2Li7lczJrjgbcaFOtAXNATJsJ5NMfIC3QxRBZPiNawwZWp 3/P/DSKridQ5vA0L8oprY1WfQf4n5Tvu13ZBYSMLggn97wbRgguxHa9qgZJzCMaaAo7+ Bzl7EkMoCN0lDRFXw4mlFYxfK4U3FaXl7J/5CGxtCTyqnrAtAs3NN7wOH6zPRc5f3Nc2 V1oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SMyq39jz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c17-20020aa7c751000000b004634dd8b6edsi1091309eds.296.2022.11.03.06.52.29; Thu, 03 Nov 2022 06:52:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SMyq39jz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbiKCNlU (ORCPT + 99 others); Thu, 3 Nov 2022 09:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231626AbiKCNlL (ORCPT ); Thu, 3 Nov 2022 09:41:11 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A891E14D08 for ; Thu, 3 Nov 2022 06:41:08 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id t25so5283291ejb.8 for ; Thu, 03 Nov 2022 06:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=hAg+4sE8YWXZby15NLt6b6O/GKFL5SevR49ad/qG3jk=; b=SMyq39jz27v0UrDE6kGVfxQdShfBOpq10vZia79dqcfy27jOmkJO/FvC3wfsnPq6u8 UB17Yu/BHFm7jD/SGZMYnaCS/9EC6FGBdn3KUsUkwf8c0Da4TNRULlmUsEdqq6cTKFlE rZU2PZSKMGhTZsEsfs9H22Qnw96dRctJqzMsI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=hAg+4sE8YWXZby15NLt6b6O/GKFL5SevR49ad/qG3jk=; b=R6uAiZ+0skaRdCbUE8QM2vRZQAU0osBktsuLNBClrxbP0HnPKcWddgD6mA8+p7DrIt 9iSQeRcox6ECAw/T+q6XrejRxrdsIvzCXDfvRG3T9z+gM4CCW2TUns7+rVcAoja9oId1 Xc8SVzqH5I5OMrggP25I2mb4ny9kDMsZcdPFCYJRbg9RIVpTEJd5v2rrTx2hIWIEtok1 gNSl3eWzdB/3SudMTCAeh6icN904ji8d/BDDQDRD8rFBVJo3S32XIqPRskI/EkpxuiWi sDn8kSIZ3vd18yg6TQYvgBlAGdjQSyiEM+4wdcm7srqMBGiE8uSt29pLhHBsJLFJChfn vnnQ== X-Gm-Message-State: ACrzQf0Ass0h8iuHl5GrGCS1BknLq/OejjkzAukpgftzkT6L2luUkf3T 7DdG1fA/XqTFL9o0Ra9abdCixXmBYsq8BwK4 X-Received: by 2002:a17:907:7fa5:b0:791:9a5f:101a with SMTP id qk37-20020a1709077fa500b007919a5f101amr29207930ejc.453.1667482867070; Thu, 03 Nov 2022 06:41:07 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:c1a3:5bc:2068:8f2c]) by smtp.gmail.com with ESMTPSA id j1-20020a17090623e100b0078d46aa3b82sm521948ejg.21.2022.11.03.06.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:41:06 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Nov 2022 14:40:42 +0100 Subject: [PATCH v2 1/8] media: uvc: Extend documentation of uvc_video_clock_decode() MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-1-d8d0616bb612@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: HungNien Chen , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=968; i=ribalda@chromium.org; h=from:subject:message-id; bh=gsofO9f2SLuiO/HN5/Ipi1+oiVUCCXFoWuwu7SisXO0=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjY8Tkf8fp0z5WECCeQG2bF7AvURn7F3S2iH2qhsIO knUeB0WJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2PE5AAKCRDRN9E+zzrEiAC4D/ 0eMu92YYKKbxptcTPKn7A0zBrhc5nLaRpFtHdgj0lDQy1Q20fJkEjfq1JycRlpuPG/uhdQkNbC/JxK RvNX+hxKjfeS0HWHONZ+SKPeCTPc8QqaG0l/wevvVP/xOEiO/sMkI4w/eXg8/DVyMuqXsBRENQsqoW LlrAHGKG0z6GMcq4CdhN3K3pfggU2cBDJDYWlVFjYXEzAIUQArDFBhelOpq0EhQ8KDP8I3N8e4Jnvh pcNdHlLz3BJlPkJV0P5pls6JDsO5vjtk9n0DFAMYNueD/mF+atg3DbmtPP2AFktMgj0PthWOElLbUN gwcytbgmDRWAfpJQj/sxn+wJqlo6RE6JtjnLMYqjHqjEvjEOQkYPy4YYsLWu6eW/TvUNDHY7pQLM2P tJkYuc9RyMXe/MlhrE407oMErfEio+l77pdlKTkbepSzwp7YnU+UOkiFRD19mTOrfmvR5Cn0kNjMUw k3XsrT5WkRfZbFR9k9lNi5rxFkbw+Eq39ubp5UwOjZOJ61Nhgvr7YBDk9euV9xXbAbzF+PWkS0nN5A Q9sBFyRpFCpyp4fiNUvI7D2maHxha9mzxxvzcquAldn77Lk/qXLHjHLNvXE8k/BFXV4U0WYtNCJrWg P9jKnplmbPLZ+OkyeWhv/S+M8tqianWhBZXKqUY1pCMoBBv+CPg111q2Uy/g== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748483255588065141?= X-GMAIL-MSGID: =?utf-8?q?1748483255588065141?= Make a explicit reference to uvc 1.5, explaining how the algorithm supports the different behaviour of uvc 1.1 and 1.5. Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 170a008f4006..ab56e65ca324 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -517,6 +517,9 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, /* * To limit the amount of data, drop SCRs with an SOF identical to the * previous one. + * This filtering is also needed for supporting UVC 1.5. Where all the + * data packages of the same frame contains the same sof. In that case + * only the first one will match the host_sof. */ dev_sof = get_unaligned_le16(&data[header_size - 2]); if (dev_sof == stream->clock.last_sof) From patchwork Thu Nov 3 13:40:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp543314wru; Thu, 3 Nov 2022 06:51:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/ZkZ+FU3qvcOxzOTejmXCaujojkeu/kBRcE18D3D/3kN+ZzPGZAfIreJPypMttmbTOGXb X-Received: by 2002:a17:902:f685:b0:186:fa9c:2fdc with SMTP id l5-20020a170902f68500b00186fa9c2fdcmr30542002plg.25.1667483474403; Thu, 03 Nov 2022 06:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667483474; cv=none; d=google.com; s=arc-20160816; b=DqsiWWVORW/FIyeUNIKfVNwMxBIz0bcC1nNB0jHMlsnCJNUkFkQ+FnhXC24kBc7k/A xI7Q6xOTYpyIsVi7xNyDSSwgd67X13tEdp6I7GTid0xu7ApNlQUpRKdltTbydgzCXfMY 7kxNIDuCxM6lmLCNg7eQyRWBjG7Q4fQ96ul/Z3UlBRPN/RzdUZRI/DQjMfd9IU6/hLsi xWgK+EoAXkECfM1ymD31XHerlT4aHDjmz6Dp6upO087RHYoLG0ajFAWdOnydDeFsA2k2 wN+ZNiQ4NiQrt3q6zMHZPgM6viWXAMhrB9zxqeHWvbromsoajcE+sfiB3WMqQ566vLxS B/LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=hoS0akrQ6TeQveFfFSMyc13cjNtaNvtsE6SeYOBvOEk=; b=QZJ13rWn3UvNK3xYjq+nKuRJpRrFNeAs1Bdzj/fkX2+AmFAd2At2XFXrb+sFiDpRhg vxVwrzKMM8hs029Mmnbf+6X0p6cxHmcPiw0uh7WGYDptMGw1nm0oQJhFcN7r8VfORRp8 puRpwAbDPM9DnEMrPJkKoSLvHlER3Ex0seGUGc8krgluy0T4BgmkRfrLkt06n7pESxhm DxWxVkLL2kLTm8Qeebv736PRcHcHj4R6qb05zbOKFVn66NDRmHYJGsPw2zjSTqlkYAaw SJWUN22V/ylNJmidyujJbc9/YWsSLRQSHYVhZMKLLngd4G92C5R0hY3MuySe0UdCj/a1 XV0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MLQgHUyI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a656915000000b0045706a2a5f3si1231522pgq.439.2022.11.03.06.51.01; Thu, 03 Nov 2022 06:51:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MLQgHUyI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbiKCNl0 (ORCPT + 99 others); Thu, 3 Nov 2022 09:41:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231645AbiKCNlM (ORCPT ); Thu, 3 Nov 2022 09:41:12 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8A31BE3E for ; Thu, 3 Nov 2022 06:41:09 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id i21so3020233edj.10 for ; Thu, 03 Nov 2022 06:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=hoS0akrQ6TeQveFfFSMyc13cjNtaNvtsE6SeYOBvOEk=; b=MLQgHUyIriV6RdPmja4T9uFEXXUXFwshLRPcoh7SpM0CnJu+5+LRheI4aIQ62WzYhQ yhDTQnx6sZ7KkjIZVCqpxpXZ/6cdNic0kN5q9FHvCIuCdIrg9Bod2vt5FBq1nBFqJz+o HkiHnMNb+5qZJ9Css6/W4xpFWXEdZmzPNdMbI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=hoS0akrQ6TeQveFfFSMyc13cjNtaNvtsE6SeYOBvOEk=; b=SZxoN4hd1I6BAWpk7c+Ln4Pv/2nQKygL361FRL/1AsBhrWVN78zsUCB+G7o9kneI7S R76pd742WnW0r6MNQhW9nlRaAP9nPE7ODfdY+GxtT3Y/opbUrQ1zgnzTRrpFCWyVCzs3 Jk1LuhvDG0Tak3ncvpSZxW9r5c8Bnp+MEG6+urHuKCWCE4swQW+tbg99L49r6Wm7seyV a5GF1mjuI7X0K7PJeBLCJDM/mb/rt0cYcwQaRZZaKayC9UpHfbpSr0FJZdsx0a/J90XD 3SPEMsz9FA+AoDbYH/Zjp/Ddvdat3SEcFZgUA6c61wLVVHQGGctAB+KD29bY4jgImIII gqiw== X-Gm-Message-State: ACrzQf2kBkwwXtRQS8RzN2Qv9sXH4Lb7HYIK6Op5QA0oJ5QxXaFwp4lE EODD2boB4Z7wSkmIPb1g496YEPE7LhvjgKvf X-Received: by 2002:aa7:c389:0:b0:463:5926:7254 with SMTP id k9-20020aa7c389000000b0046359267254mr22814190edq.255.1667482868053; Thu, 03 Nov 2022 06:41:08 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:c1a3:5bc:2068:8f2c]) by smtp.gmail.com with ESMTPSA id j1-20020a17090623e100b0078d46aa3b82sm521948ejg.21.2022.11.03.06.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:41:07 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Nov 2022 14:40:43 +0100 Subject: [PATCH v2 2/8] media: uvc: Allow quirking by entity guid MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-2-d8d0616bb612@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: HungNien Chen , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1651; i=ribalda@chromium.org; h=from:subject:message-id; bh=anGRVDFD85vsGKk21Uxm3s9uLgr7IvjTjJHKWEWi0Pg=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjY8Tl5NZFMLDHqMroQzfNDlU9yRplmkVU67bnePXf eTV/5fOJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2PE5QAKCRDRN9E+zzrEiGpFD/ 9JX3HaPi2suJ4GMvYRHsf+hbBMWhA9OH0IkPyeM3mB/c6+94JJoamvLRpBEyIYJvrahKiEUCivgLre +owtY12LRuklzovJs6d24N8TqaT0Amp++llLv+ekx4aSMiaZa/pvjze+lX3g2Z+kjETUYR2p0YlrG4 HdV22s3MrTFXTHwr5/MrXj8soPClS1XnwpXCD7F3qjBxTOxx7M+cRr0jZxlQdnbhqHFUHKGS1+1hmf m26KCbQpt9kN+4bh30tNIWZOlyGJKNLmjSbPl9Cc4Ftfd5HU98M8rbpjcG07HmNZj9xOTo4vU26KGq vI0fwRWLEkhMLq4Ae42P5wvjkS+xssX6WKVbiImGDM30SCvu66uSLTMtAtUTeDxHP6c1QqUaTO+yiA 54bceNWIGSa4VwIsjr41CLtnkKUvLs+fpRgPnymyarx6KEm3xykLuDh3Azavy5Wq2VlTGylVLQZM9P aLs6ZP2Ga5ERGBnfko6I8mEO6oMRpfdpiBoZidfnQLqWOsPTQym7CfF8tsGTv+8HjMGtUssyZ7JlEK QnUcspRv9pGALRYSoiE/d001PiSsKBQ9rCl1GGE/i4WPDclTqF8m2JKfYvjgNEFbt9XE2GOfdM9lpp Xzy2wXju3H1HaVudS8tOltB7kXLCGMrJU8SsZhYMyBvmh+AU8+rw5+XhxUFA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748483151525751068?= X-GMAIL-MSGID: =?utf-8?q?1748483151525751068?= When an IP is shared by multiple devices its erratas will be shared by all of them. Instead of creating a long list of device quirks, or waiting for the users to report errors in their hardware lets add a routine to add quirks based on the entity guid. Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 9c05776f11d1..c63ecfd4617d 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1493,6 +1493,28 @@ static int uvc_parse_control(struct uvc_device *dev) return 0; } +static const struct uvc_entity_quirk { + u8 guid[16]; + u32 quirks; +} uvc_entity_quirk[] = { +}; + +static void uvc_entity_quirks(struct uvc_device *dev) +{ + struct uvc_entity *entity; + int i; + + list_for_each_entry(entity, &dev->entities, list) { + for (i = 0; i < ARRAY_SIZE(uvc_entity_quirk); i++) { + if (memcmp(entity->guid, uvc_entity_quirk[i].guid, + sizeof(entity->guid)) == 0) { + dev->quirks |= uvc_entity_quirk[i].quirks; + break; + } + } + } +} + /* ----------------------------------------------------------------------------- * Privacy GPIO */ @@ -2452,6 +2474,9 @@ static int uvc_probe(struct usb_interface *intf, goto error; } + /* Apply entity based quirks */ + uvc_entity_quirks(dev); + dev_info(&dev->udev->dev, "Found UVC %u.%02x device %s (%04x:%04x)\n", dev->uvc_version >> 8, dev->uvc_version & 0xff, udev->product ? udev->product : "", From patchwork Thu Nov 3 13:40:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp543044wru; Thu, 3 Nov 2022 06:50:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7SsnRsM2o0lgu9jDOk+C2/YTnCH8qCAc9lr/zjZmx+DvQDeZsn+QGLcMC300TkL8rzDBmy X-Received: by 2002:a17:903:2411:b0:184:7159:dce6 with SMTP id e17-20020a170903241100b001847159dce6mr30743934plo.101.1667483448631; Thu, 03 Nov 2022 06:50:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667483448; cv=none; d=google.com; s=arc-20160816; b=zuuqosnGuEwl5SwSE47cSZ0B6T7Sq0n6S0lXtmJtFAKzJk/EuJx5OVkpTvujeKIhTK 1pwsraUQ/l0z/Wud8DaUXy8qtPz43NpZHaU3wxfxQzNrgHPRtq/UnINEpCKzIJUHWZ/p 556PUclth8bTjWZ0FiHzNZl51YzsBNJutcpZQAicZoEb020zQszQJsOpR0A6Yekp9WSq BlLC8FToVET8PbT3RZzS9ySgKkwfvS7tpG1M3DUkoBT7Y7WU4F/lpZrYreQ57EQ9Dlp9 a2LO8o7N09kGAoOz0zJvZjXDguerHJwdNKcxgy3mUI+tNffD7u9gSaDMa0qdNzhkWQ66 c8Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=5Wu8BcX+LtOapPOEw3vPoa18UbkrEIbxPoLO/ZmY1CQ=; b=0pdSHLoMCB28AcSyOzOdCSRh2GuJGMoWAZN8FgIDT+6yHViowPMHVTL+f3uLbXrgYo mOjtgb/5ILeRP6cSkbkinTGG+WdaWwnjkJuzZdBBCcmDPf4hGpuBSOyQazhpKea3mee5 b4lvKatXtsQAjsSjIZyYxHlstl4QVif3mLVRKnr0p0ppM6SmmRcTp/UB2PXhj7AfrYUU NqmgifUBvW5lL95h1hT6F0Fh7MkhMhZ4dRj4RtP7UFHHHUddKzXAZQjJHTL6cNCzU8YB DO0XpzVo/JybDpeCnP4CYu+PIQN9u9aEzrD7A2MTE6fbTWhL+9gGqolFa8PccFybBZpT JAUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Uv1wGYuY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x4-20020a63db44000000b00439494dfd20si1244633pgi.202.2022.11.03.06.50.34; Thu, 03 Nov 2022 06:50:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Uv1wGYuY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbiKCNlb (ORCPT + 99 others); Thu, 3 Nov 2022 09:41:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231244AbiKCNlM (ORCPT ); Thu, 3 Nov 2022 09:41:12 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7453D140B3 for ; Thu, 3 Nov 2022 06:41:10 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id t25so5283520ejb.8 for ; Thu, 03 Nov 2022 06:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=5Wu8BcX+LtOapPOEw3vPoa18UbkrEIbxPoLO/ZmY1CQ=; b=Uv1wGYuYcuyLg8QWPSohzH4gS3DjtTEtvJovvUfDFPdy5YcU+0EncxqSIpr4WnrJ5h EsNidk14sUzNxMg/1nX/C5AuhteBqVDt6vpichldtuo6oG4+5HUy+LMyO9nyuYmXg9Pc 2GD1lPQOFnSTm6U4LF8NHXUqR6NTLroG5/NUg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=5Wu8BcX+LtOapPOEw3vPoa18UbkrEIbxPoLO/ZmY1CQ=; b=zIhLhi54+P3nfIDhid5LXZZUrztq5aB4T1D+Y8r6OwOLcNBrrQvnU5FlPw8uV7Wfgj XY9w3F+gTz1HJ42OgNuMkZaR1hK4FC2JkIRPyVhIzKmI7J7oPUDULDH9M7VyH3BVggxX Izd6EbcHcIQk6XH4ZrEJsCwDZGB82Scgl/O56yuQsIiPr8R2fCLhWTAy4Y27h4HlvOD3 EaUl5++zA9YWQ0mfBciE/bsTGwSnr8pkPoylJsQuIZ2+tLUpj9PJ1LqIDO37osVvuUZs Ur4pv9HEzwfcaZjvQi45GXC+hW+lTaGgQEzPThnKUper6+AftTYWuKgtAf+Oep0nBahc UZkw== X-Gm-Message-State: ACrzQf2doLIqWEHE08qa/khorCFwgzzRVXiTlUTUC3LNGpWUTmdGDrex PXnC2MBdOf7OQ+iqqpvU6cuzrI8tABq4xyNi X-Received: by 2002:a17:906:f854:b0:7ad:d196:9df with SMTP id ks20-20020a170906f85400b007add19609dfmr21666369ejb.295.1667482868838; Thu, 03 Nov 2022 06:41:08 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:c1a3:5bc:2068:8f2c]) by smtp.gmail.com with ESMTPSA id j1-20020a17090623e100b0078d46aa3b82sm521948ejg.21.2022.11.03.06.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:41:08 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Nov 2022 14:40:44 +0100 Subject: [PATCH v2 3/8] media: uvc: Create UVC_QUIRK_IGNORE_EMPTY_TS quirk MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-3-d8d0616bb612@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: HungNien Chen , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=3613; i=ribalda@chromium.org; h=from:subject:message-id; bh=0bJquUAr1GQDJ5Ewl4+qXLbtcOxjrXI9YYkj/sI1K0g=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjY8Tnt39PtqZ4zreEzOG9DHH7gYyJ7Arn3p5KYk0e wGJyNnKJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2PE5wAKCRDRN9E+zzrEiBXdD/ 0TLnzkGCTgRzIO9SyYCS65akzC8irTwLBgRwKIutQlf85gbi1Ev9eeTL2AnA+kCjgTvfmjDrhgBKiJ hcuDXDEc4j2DMRDSWskXY6WbQPGKkEmvLs45/Dd+Gcgfexezr/ka87S1y3VFwpFStLMu4vY5Y3RSan xifI1I2vqAVBUgGSqfn5dObXWi/p8Mooe9lZkqOz1inZ9HUnywXcNGiOycw7GBWFLjWVEjthOiunAA QOld16GiDbB8eLC+SXn4yBNi+jWXaAtQW3k2xOhX2NzrRd/kDGRYCkazb1SduY2lVF9DMxReJaPkAt y+3n824wPhugjL34DrZdnFMeyxxWfMhr7H48vUykQ9W95+QOjA+w90gY8CadPZKvF4iQGQ5bwXW0Fv xH+K1fkPyrpWM0i52exJkGmzWa9phdGsR/yEOeeU08cWfhJtnvNjFy3kx8oyDZvaY7XKof9FYqie+j ULc7SbGZaAxX+YVCnCr6PCiQ2NfvqRzessOKaeuIWG9YRyn0HMqw9Djdm4yoliOCHr+tiGEyPf2WbI sATTrb7CPIlyKDP9cvmJk7dk4pVuZCJ5xcg/KwN+/9iYmnn/bvByBAPxZZ5+95gWlyPBRV8QoasHnf IJRqn3N4aVSPDTvU0+wP/0ZS04RZyFMDRXtNinjmkNgcgrvqORNB22ulM1CQ== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748483124350037359?= X-GMAIL-MSGID: =?utf-8?q?1748483124350037359?= Some Sunplus cameras took a borderline interpretation of the UVC 1.5 standard, and fill the PTS and SCR fields with invalid data if the package does not contain data. "STC must be captured when the first video data of a video frame is put on the USB bus." Eg: buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 buffer: 0xa7755c00 len 000668 header:0x8c stc 73779dba sof 070c pts 7376d37a This borderline/buggy interpretation has been implemented in a variety of devices, from directly Sunplus and from other OEMs that rebrand Sunplus products. Luckily we can identify the affected modules by looking at the guid of one of the extension units: VideoControl Interface Descriptor: guidExtensionCode {82066163-7050-ab49-b8cc-b3855e8d221d} This patch adds a new quirk to take care of this. Complete lsusb of one of the affected cameras: Bus 001 Device 003: ID 1bcf:2a01 Sunplus Innovation Technology Inc. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.01 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 ? bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x1bcf Sunplus Innovation Technology Inc. idProduct 0x2a01 bcdDevice 0.02 iManufacturer 1 SunplusIT Inc iProduct 2 HanChen Wise Camera iSerial 3 01.00.00 bNumConfigurations 1 Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index c63ecfd4617d..80ef0f0e04b0 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1497,6 +1497,17 @@ static const struct uvc_entity_quirk { u8 guid[16]; u32 quirks; } uvc_entity_quirk[] = { + /* + * Some SunPlus uvc 1.5 device firmware expects that packages with + * no frame data are ignored by the host. + * Therefore it does not clear the PTS/SCR bits in the header, and + * breaks the timestamp decode algorithm. + */ + { + .guid = {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, + 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1d}, + .quirks = UVC_QUIRK_IGNORE_EMPTY_TS, + }, }; static void uvc_entity_quirks(struct uvc_device *dev) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index ab56e65ca324..a5b184e71ad7 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -500,6 +500,14 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, if (len < header_size) return; + /* + * Ignore the hardware timestamp on frames with no data on + * miss-behaving devices. + */ + if (stream->dev->quirks & UVC_QUIRK_IGNORE_EMPTY_TS && + len == header_size) + return; + /* * Extract the timestamps: * diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 24c911aeebce..f395b67fe95a 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -212,6 +212,7 @@ #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 #define UVC_QUIRK_FORCE_Y8 0x00000800 #define UVC_QUIRK_FORCE_BPP 0x00001000 +#define UVC_QUIRK_IGNORE_EMPTY_TS 0x00002000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 From patchwork Thu Nov 3 13:40:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp543059wru; Thu, 3 Nov 2022 06:50:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Twxy2kd86/iI8ZxDsUrQ9lDzheN+Gi9TT/sD21cDF+qdk/Upc1xueJrzkDqidzgz0MisU X-Received: by 2002:a63:e158:0:b0:464:8d6:8b91 with SMTP id h24-20020a63e158000000b0046408d68b91mr25502246pgk.124.1667483449806; Thu, 03 Nov 2022 06:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667483449; cv=none; d=google.com; s=arc-20160816; b=DHva//AuhphkQ5BMUoLDI0b3DBqHI3ejT2E7fguI+5uOzV9+/BVsGiYO/6pR9av5NE c9dsiaOMboPrPelXZVCQvsqWu+OGed09h64OZN3kal4Fw02rGTn479LfNaqHrcGs2t3E vQEn+K0iDGeaE2Ar1TRV+FYbGMY9r6R2BQqV2LbM8NPxLHjW14Mf9NUemNEC3aXhTGcd lg9kgNxuFoavQBFqw4YQnWnqc2h99h9PJGVkH6ath9846PZgucyakEOT/pScTQwTJus0 FYcXdBQ/UcrrDNa3p/CxjqvDLOUrw+gNjz5J53xCg0KL0POR0cfz7Zaa7cTq3xImbsEb xAuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=htk03ZXZ6BAf5SUnfWVl749nCIvhsf9YeaZoa0SoAPM=; b=e8FiqaT7erpq00HfrVvGy5X3hUTScXOK4FiiVxKjFxNI46Xt7y2v4CJhMBCk3MKPhO +mscUHUEJL5eTlUskp77B9mO0ez9h3/7IFE/h6NFLdYiZSZVSt0zavypYOCOLcvz6azJ FZ0hNNTI/2Tto7o/szjRFp+bHVc2CQgnWkBP2fxkDQb3CK9S4dT3y1etbXh+x2IbwWl7 xdXuyWGGhDsIPEfuI6Bk/sY91UviMIrwNqYwmPNVEES6/1SyQTQo3NYTi4N60R5owO0J Y+DQZ073ECWbrOxtn9ht1810dC6zbtPnAd4oAyOW/JX9p8slcrB4bFnH6Bvm0JghQedg StfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SjFd9Ern; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a631946000000b0041cefab5b61si1063560pgz.719.2022.11.03.06.50.36; Thu, 03 Nov 2022 06:50:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SjFd9Ern; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231626AbiKCNlg (ORCPT + 99 others); Thu, 3 Nov 2022 09:41:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbiKCNlM (ORCPT ); Thu, 3 Nov 2022 09:41:12 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4173A15706 for ; Thu, 3 Nov 2022 06:41:11 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id kt23so5297750ejc.7 for ; Thu, 03 Nov 2022 06:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=htk03ZXZ6BAf5SUnfWVl749nCIvhsf9YeaZoa0SoAPM=; b=SjFd9ErndYOjcXEk0hTpVzTdyHToxYaYTpA7l0bvcx5tVKdkFEwHQWt0I+DU6VKBwg u19E4eiKwpnbggLVhsrNZHYg6qaFzuX4T09nsiKLCGU2V8+4neVBAC6y+EGyfL5e8GK0 lAkvyraOPgRHT/3dsOnFxAdrLlyZVk0zlC5OE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=htk03ZXZ6BAf5SUnfWVl749nCIvhsf9YeaZoa0SoAPM=; b=eybDIcwYAtdmj7X1Oy3tjo60dIegAtgY565FVLqGbsZO9g0B2c7Cq9Rdjjyj9G5ACb g+XtyIDFRM60fP9ad99V/WXyOIICYQdUOP3q6fNs4gebTgV0/JLe7e2XypBveifXcocX BhnHx1v2l83tPHvXT1wb8GHxSTSIBtZ0/9nhumsHyEr82hpjCKeJBy6hEF4zv3bSictK 81Qcr03jQLnZC8H97a0ixzBEeY1/9MpVhyEjPAB0S/4IFgYWpgD52/wDroqyNXGnTi3M HyRrGzXTEdiYUSy6ea0SEIxrp0y+7M0OUwOP1jRwDA74ApFsCYBoPaDEuMgiy73Uw0+X JDDw== X-Gm-Message-State: ACrzQf0NqpLNWpNk9YrUv66Md731atggrK3IsqragG+9+N5LZsz3fjOf XPioxfZYr5OLnaIC0m1qS5MxYbtEtIiQZpYH X-Received: by 2002:a17:907:94c3:b0:78e:2866:f89f with SMTP id dn3-20020a17090794c300b0078e2866f89fmr28346552ejc.617.1667482869589; Thu, 03 Nov 2022 06:41:09 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:c1a3:5bc:2068:8f2c]) by smtp.gmail.com with ESMTPSA id j1-20020a17090623e100b0078d46aa3b82sm521948ejg.21.2022.11.03.06.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:41:09 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Nov 2022 14:40:45 +0100 Subject: [PATCH v2 4/8] media: uvcvideo: Quirk for invalid dev_sof in Logi C922 MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-4-d8d0616bb612@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: HungNien Chen , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=4699; i=ribalda@chromium.org; h=from:subject:message-id; bh=BG95FdUi6it8kGTXeYjcquehpttCvGOKYvHHKrrROlo=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjY8TpMd8hENvZhIksVT+BMQIwXHICRbtXZQlg/ANe 5f2aF62JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2PE6QAKCRDRN9E+zzrEiP3GD/ 44LZUefEi9TAgPcvJWUpPaQziUvRkG6Z0rdcqBKg9yt9UM8alMthgngLuhTSmJoJRKpJGVuIr9wGGo ROc9ld/ZXMJnsODJ4NbWLAHdldF6JEgQTKn2j+TpMG4mkqo0jW9ayOLqLEST2vdJaTvF/2dA8Cmm2h Ns/S/U/D6p0XrM2yBFhJK1SRmx6j4a8eFUhe3Pr2UBo+ZuVgAaQJ1N9Mc1REdGrth0lvEjdUiyv1dO g8DXleuHo83/kIbQnZY2W5Az0n78ec6jPhqt+CSJnynm6Jb8xQ2/8yxvXEj7DRyqxBD2lHfap38fmk L5KyLDHASkeadmcleLtOU1PTFWi+3aQuOWVOpp8vqykHxQgvugqvaqzp1/YG+kfobvJMAtUF9Pivk3 O91Sbg8YlrglmI8V0yW8WPfeMt2jHUzjfPn2fmLSZ+JTvE5Z295S/tBWSsN68LptSR26x+aarInDlY 123VT9VNxgmQHzWJWhEyhmfU6txLsoWvJrQcm+3CZjoJBgGbAkKrXxCB9flBO9sYgKi+PhocaKrkBv vwF/CnAl3cUUGuoXLVHsIUUiZPDYERHa/+0lDej3KYOEwoK/dirnFpUs0DG7FwcT/5Lccq8yTtePN2 uQAUMPJ7uuSKX+XruL6rjDBZoaoVDK70k/gN8jhGBHQzITrCgt2S7HJCjA1Q== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748483125755699861?= X-GMAIL-MSGID: =?utf-8?q?1748483125755699861?= Logitech C922 internal sof does not increases at a stable rate of 1KHz. This causes that the device_sof and the host_sof run at different rates, breaking the clock domain conversion algorithm. Eg: 30 (6) [-] none 30 614400 B 21.245557 21.395214 34.133 fps ts mono/SoE 31 (7) [-] none 31 614400 B 21.275327 21.427246 33.591 fps ts mono/SoE 32 (0) [-] none 32 614400 B 21.304739 21.459256 34.000 fps ts mono/SoE 33 (1) [-] none 33 614400 B 21.334324 21.495274 33.801 fps ts mono/SoE * 34 (2) [-] none 34 614400 B 21.529237 21.527297 5.130 fps ts mono/SoE * 35 (3) [-] none 35 614400 B 21.649416 21.559306 8.321 fps ts mono/SoE 36 (4) [-] none 36 614400 B 21.678789 21.595320 34.045 fps ts mono/SoE ... 99 (3) [-] none 99 614400 B 23.542226 23.696352 33.541 fps ts mono/SoE 100 (4) [-] none 100 614400 B 23.571578 23.728404 34.069 fps ts mono/SoE 101 (5) [-] none 101 614400 B 23.601425 23.760420 33.504 fps ts mono/SoE * 102 (6) [-] none 102 614400 B 23.798324 23.796428 5.079 fps ts mono/SoE * 103 (7) [-] none 103 614400 B 23.916271 23.828450 8.478 fps ts mono/SoE 104 (0) [-] none 104 614400 B 23.945720 23.860479 33.957 fps ts mono/SoE Instead of disabling completely the hardware timestamping for such hardware we take the assumption that the package handling jitter is under 2ms and use the host_sof as dev_sof. For the hardware tested, it provides a much better timestamping than a pure software solution: https://ibb.co/D1HJJ4x https://ibb.co/8s9dBdk https://ibb.co/QC9MgVK This bug in the camera firmware has been confirmed by the vendor. lsusb -v Bus 001 Device 044: ID 046d:085c Logitech, Inc. C922 Pro Stream Webcam Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x046d Logitech, Inc. idProduct 0x085c C922 Pro Stream Webcam bcdDevice 0.16 iManufacturer 0 iProduct 2 C922 Pro Stream Webcam iSerial 1 80B912DF bNumConfigurations 1 Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 80ef0f0e04b0..4512316c8748 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2880,6 +2880,15 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_RESTORE_CTRLS_ON_INIT) }, + /* Logitech HD Pro Webcam C922 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x046d, + .idProduct = 0x085c, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_INVALID_DEVICE_SOF) }, /* Chicony CNF7129 (Asus EEE 100HE) */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index a5b184e71ad7..d387d6335344 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -529,13 +529,20 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, * data packages of the same frame contains the same sof. In that case * only the first one will match the host_sof. */ - dev_sof = get_unaligned_le16(&data[header_size - 2]); + if (stream->dev->quirks & UVC_QUIRK_INVALID_DEVICE_SOF) + dev_sof = usb_get_current_frame_number(stream->dev->udev); + else + dev_sof = get_unaligned_le16(&data[header_size - 2]); + if (dev_sof == stream->clock.last_sof) return; stream->clock.last_sof = dev_sof; - host_sof = usb_get_current_frame_number(stream->dev->udev); + if (stream->dev->quirks & UVC_QUIRK_INVALID_DEVICE_SOF) + host_sof = dev_sof; + else + host_sof = usb_get_current_frame_number(stream->dev->udev); time = uvc_video_get_time(); /* diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index f395b67fe95a..e41289605d0e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -213,6 +213,7 @@ #define UVC_QUIRK_FORCE_Y8 0x00000800 #define UVC_QUIRK_FORCE_BPP 0x00001000 #define UVC_QUIRK_IGNORE_EMPTY_TS 0x00002000 +#define UVC_QUIRK_INVALID_DEVICE_SOF 0x00004000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 From patchwork Thu Nov 3 13:40:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp543182wru; Thu, 3 Nov 2022 06:51:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7P0ZBMhL7zDRAJihHjJzIi7siLWaiUmU1jjno0SE84XASraJPiex7aJzYt+pQVeyttVRHQ X-Received: by 2002:aa7:de81:0:b0:461:2122:a807 with SMTP id j1-20020aa7de81000000b004612122a807mr30880339edv.382.1667483461632; Thu, 03 Nov 2022 06:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667483461; cv=none; d=google.com; s=arc-20160816; b=xmDKcehBGjk0bqnpnfBrAn40Wic6ZmnFR8aMFjBJDoDQcyYN1X7ScjyfJYmvTZ7Z2i Qt0NV0wV1ShV6fEqYpK6bnskBcOzFPNNuHH81BQmx7PALhCiyowV3A1BUnupadGWzhP+ nGqFIQeLGQDoLIeBiO6sYdHfEiN0UV0HO1nDuakKUQP+yT2DsOhbnu4jkni6PtTcBcvD DXuRiH2PNXz7Vg8P22nQIBwB/RDI9fTF3ukTEwsMN3JkOU3M5z/bpXl+TYIQlzQIlu0A oy+qZACEyszGDWx4TuffP8Cx6WLEhvKipqm+Tn2prXf1qesWXUMbMAVih9AYhsHqsVZa BT1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Hb1TxXDYCX0UbT1M38Hz0enEs7BzEgUeFcPg+yYlJ6w=; b=LugFOUC0j+sws1YikmD8MObFUnE8/cv6JydiEpyMhW7oWzR/ffr2eKLhIcFW+Qnlxh wraHn1wA9bU92Prflv11/UGSaQcwjpsdHTuevjlU2arubeTRvh7MlPQHvw28pERyHaKI ttABVZEypMCNH6poBX1GfKzIHVhCE9PCSZm55xe2OeZ0Es6/bvrTKEEnAWg2zsJEENxw kcDaTYJJtrEn0mwb4HK9yxQQtzttY4T4/fTmEJYSpPIwWhGPb98ygGEfDF5UEMYSjRdb M3n8/bFDyUpnnbj/QEo9/wTRkSAwGIXJ+2ODfxA9vqHBRwkySADEJn7z1lwTvdIjK/It SgbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kLhZUsoS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw7-20020a170906478700b007800b181a0csi1374138ejc.300.2022.11.03.06.50.37; Thu, 03 Nov 2022 06:51:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kLhZUsoS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231583AbiKCNlm (ORCPT + 99 others); Thu, 3 Nov 2022 09:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231669AbiKCNlN (ORCPT ); Thu, 3 Nov 2022 09:41:13 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB34C2DD5 for ; Thu, 3 Nov 2022 06:41:11 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id i21so3020356edj.10 for ; Thu, 03 Nov 2022 06:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=Hb1TxXDYCX0UbT1M38Hz0enEs7BzEgUeFcPg+yYlJ6w=; b=kLhZUsoSFfKQYvK52/kjuDEMQB1JDq4BWYE0o42OoJPvIQMiu5ZPysXw6Wq07eV341 u7mDgIs4wk3nCKhrANUjEe+H8stg+MKmF2ugx8FrRr0em5UOu1L+2VS8W9/luhktWi6e 4jMPqBOLm19n1IXPkANB0k6/HLQaw+MPe37YQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Hb1TxXDYCX0UbT1M38Hz0enEs7BzEgUeFcPg+yYlJ6w=; b=ndilHV65jvdc/LVprH3LeLF+SOimVjwS+9RQXK4NcE64uMl1tkGGMy4yK4kzjJcvcJ M5Ac8gLKvEtG8IxfJusfxiCaFK7iJQ8a5M04Z4ZPhp3L3FmoGVWj4aA61lGkAK/v+wA2 sYxHwGExdgUs6fF4Y+juTD+t6is8mNNkC0y6R7p0sEKHQIh8i68U9v0c3pBi5LPJY3vd aAvxiGcpoONb4PQSoweEpu3t8pgYfDBOE/VSGpWjPdaIdORDWYPvnAxCxONPmtw1Japa xTriCHRpPBLTR+9bNN6WBvUNHOyAmLB0aSqQiAB4YZBy5fWxWpI1ZWXx/B2v4LGPlLMA vpFQ== X-Gm-Message-State: ACrzQf2Rs/em49s+CsNJBKMAosGRG8eYWxvg9Tq1NMXig07vVusPz1k1 d42IVy9/ZaCR47V23sA9BXzqjGomciMendiP X-Received: by 2002:a05:6402:43cb:b0:461:912d:90f with SMTP id p11-20020a05640243cb00b00461912d090fmr30596229edc.375.1667482870369; Thu, 03 Nov 2022 06:41:10 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:c1a3:5bc:2068:8f2c]) by smtp.gmail.com with ESMTPSA id j1-20020a17090623e100b0078d46aa3b82sm521948ejg.21.2022.11.03.06.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:41:10 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Nov 2022 14:40:46 +0100 Subject: [PATCH v2 5/8] media: uvcvideo: Quirk for autosuspend in Logi C910 MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-5-d8d0616bb612@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: HungNien Chen , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=5042; i=ribalda@chromium.org; h=from:subject:message-id; bh=p5RvX3qCD6ce/qxL1IUoFKUNaigRS5GrgVXMbIb+exc=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjY8Trzytar6o1bQWtJTgzygKQJY3iYq25SFyNEg7F 7AXerJCJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2PE6wAKCRDRN9E+zzrEiL1uD/ 9INbxsQfAugyW/dDD7Arryz5CdtC+aFrFkYLj0W30dZmXTV5zfLvkN8Yk/mL+JxegV7mYLUOqbYKWc DxYG5JdoeZGzqBATRkw4xsjDNhYi0o6TAU0tSnkE8fTRfphsSn5IblfYiouBlJIdhJ+qJIo7y+FDLH 7eT5ryczjyDjCAELfR2Jw4rIy1FaAp8AquNaO82L1wGfEG2/jwKTKydiFvl12oK+caP0wqIr6hhnFH Qu/jmR1M5ghtctI3ttpfd8PET9RM/8hzc6Hc5i8kgMDY82mjzcZ6hVYu61rhpaICuNPYn1zkvNgOws aDZUvVE2epBHvUcfE2Zbrcdi4eUw/GAHi4vxMd6opK6y6ztSH2o5E9NfHov3U/J7SSLmmuzib4Qg4d 9kmQSOOi4bCHe1DX+TMtMZ63bTOL9qAMqMn6wTw9pvxHhlDZ0QzMS4moZdcFte67h9Dt3j48/jUB99 4TftHw7OAnT2cPmj45lRtSBxU4cD4tGA5xC3kxn4yMAXDelBcv5p6H90UBnE2GCxMtcBwV2k4V7mcM 2s/WWdTCQgQOLwxXuQsyvGWsRr1wS0V/LUjMuQnetyqWnJkq9XOF+1DeQ/2Krr6xnTo5H7Om7+3wYY jauExlXK6iqsGl+TkpSOh0sJhQ4fp10c4/2GcSHP+rHqXAgJ1rdTa+dyYO7w== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748483138086554298?= X-GMAIL-MSGID: =?utf-8?q?1748483138086554298?= Logitech C910 firmware is unable to recover from a usb autosuspend. When it resumes, the device is in a state where it only produces invalid frames. Eg: $ echo 0xFFFF > /sys/module/uvcvideo/parameters/trace # enable verbose log $ yavta -c1 -n1 --file='frame#.jpg' --format MJPEG --size=1920x1080 /dev/video1 [350438.435219] uvcvideo: uvc_v4l2_open [350438.529794] uvcvideo: Resuming interface 2 [350438.529801] uvcvideo: Resuming interface 3 [350438.529991] uvcvideo: Trying format 0x47504a4d (MJPG): 1920x1080. [350438.529996] uvcvideo: Using default frame interval 33333.3 us (30.0 fps). [350438.551496] uvcvideo: uvc_v4l2_mmap [350438.555890] uvcvideo: Device requested 3060 B/frame bandwidth. [350438.555896] uvcvideo: Selecting alternate setting 11 (3060 B/frame bandwidth). [350438.556362] uvcvideo: Allocated 5 URB buffers of 32x3060 bytes each. [350439.316468] uvcvideo: Marking buffer as bad (error bit set). [350439.316475] uvcvideo: Frame complete (EOF found). [350439.316477] uvcvideo: EOF in empty payload. [350439.316484] uvcvideo: frame 1 stats: 149/261/417 packets, 1/149/417 pts (early initial), 416/417 scr, last pts/stc/sof 2976325734/2978107243/249 [350439.384510] uvcvideo: Marking buffer as bad (error bit set). [350439.384516] uvcvideo: Frame complete (EOF found). [350439.384518] uvcvideo: EOF in empty payload. [350439.384525] uvcvideo: frame 2 stats: 265/379/533 packets, 1/265/533 pts (early initial), 532/533 scr, last pts/stc/sof 2979524454/2981305193/316 [350439.448472] uvcvideo: Marking buffer as bad (error bit set). [350439.448478] uvcvideo: Frame complete (EOF found). [350439.448480] uvcvideo: EOF in empty payload. [350439.448487] uvcvideo: frame 3 stats: 265/377/533 packets, 1/265/533 pts (early initial), 532/533 scr, last pts/stc/sof 2982723174/2984503144/382 ...(loop)... The devices can leave this invalid state if its altstate is toggled. This patch addes a quirk for this device so it can be autosuspended properly. lsusb -v: Bus 001 Device 049: ID 046d:0821 Logitech, Inc. HD Webcam C910 Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x046d Logitech, Inc. idProduct 0x0821 HD Webcam C910 bcdDevice 0.10 iManufacturer 0 iProduct 0 iSerial 1 390022B0 bNumConfigurations 1 Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 4512316c8748..d2a158a1ce35 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2823,6 +2823,24 @@ static const struct usb_device_id uvc_ids[] = { .bInterfaceSubClass = 1, .bInterfaceProtocol = 0, .driver_info = (kernel_ulong_t)&uvc_quirk_probe_minmax }, + /* Logitech, Webcam C910 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x046d, + .idProduct = 0x0821, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)}, + /* Logitech, Webcam B910 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x046d, + .idProduct = 0x0823, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_QUIRK(UVC_QUIRK_WAKE_AUTOSUSPEND)}, /* Logitech Quickcam Fusion */ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_INFO, diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index d387d6335344..75c32e232f5d 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1983,6 +1983,11 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, "Selecting alternate setting %u (%u B/frame bandwidth)\n", altsetting, best_psize); + if (stream->dev->quirks & UVC_QUIRK_WAKE_AUTOSUSPEND) { + usb_set_interface(stream->dev->udev, intfnum, + altsetting); + usb_set_interface(stream->dev->udev, intfnum, 0); + } ret = usb_set_interface(stream->dev->udev, intfnum, altsetting); if (ret < 0) return ret; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index e41289605d0e..14daa7111953 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -214,6 +214,7 @@ #define UVC_QUIRK_FORCE_BPP 0x00001000 #define UVC_QUIRK_IGNORE_EMPTY_TS 0x00002000 #define UVC_QUIRK_INVALID_DEVICE_SOF 0x00004000 +#define UVC_QUIRK_WAKE_AUTOSUSPEND 0x00008000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 From patchwork Thu Nov 3 13:40:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp543238wru; Thu, 3 Nov 2022 06:51:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4HPIM5XCIiT640eUD/DMs98FYmfO0nQS8lj7pje13QpECZuOTJ0A8fauu0RTuDm9T1OPYl X-Received: by 2002:a05:6402:5159:b0:462:3e9f:a0a4 with SMTP id n25-20020a056402515900b004623e9fa0a4mr29633493edd.313.1667483467343; Thu, 03 Nov 2022 06:51:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667483467; cv=none; d=google.com; s=arc-20160816; b=ReACTTdg2uf+5YtLyDu0wMx/i1ZmXhOBotw+4mzQ2I0NLMe4nD+kAxiDdXaL5I2OEw qtX/BnoImN1REL4Tlngax3fLJmhwwca5of0lTYNYmCIqZtjS1zAIpBWtP/bMyNQoWwwL c0fkcAQkmEqDeKe2vcydAuzFrlexym2qa1dKpIdRuS4jjMSm9c8dHjFhPicNRCfH4QLC HPT36mwB30BOAt5gbZphTf28lFC66c5fFcXLOwA9nSH53GP/xS4IklIBx1pOiPXobslg dnm+VXgkBZDnzlovxbjZ1v2yC1ZR95MrXS2/2FIIzS740y+V8/TkQq21XYJD4xyW12FH diQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=MD4SwW/08TmbG3Vp1P7f9CQbz5/bFAEy8m9eJlUaWww=; b=Nf0dRVzHRoi7blunzlV0BYBAuTcsFuF8NcYgdp57UEcT72akV0jfRrF75y4+s3B3OU B3ptsERiI9IFZrisZoF30pB/gK4jTJ0Xw3FwAtnqElst+16QV5iUCy7eYsYc/aBqUUY6 oQLJulZHpiJ6x+NInld0qpYr1Ksei7X7bofsmYf77elE7sBwQcgLJJ2KiGqBjwnI/ksh k4HQ50k+lr2/v8ci/Tf9ACnxFcQhij0Zo0AnAWM7bsBd9WBkXfy2MFHCNOrQJ1EuPMdY apr7HDq10vIBlUqA4jLmWvKNK8Kum2aefNy8hhLlPfCuJq7hiTAyBSJGkJYbR6gqJxXD zw/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Qr9h6PEn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a056402520900b00461d3757956si1673656edd.326.2022.11.03.06.50.43; Thu, 03 Nov 2022 06:51:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Qr9h6PEn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231779AbiKCNlr (ORCPT + 99 others); Thu, 3 Nov 2022 09:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231599AbiKCNlM (ORCPT ); Thu, 3 Nov 2022 09:41:12 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9C17E8 for ; Thu, 3 Nov 2022 06:41:11 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id i21so3020432edj.10 for ; Thu, 03 Nov 2022 06:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=MD4SwW/08TmbG3Vp1P7f9CQbz5/bFAEy8m9eJlUaWww=; b=Qr9h6PEnZlcu+XDMmTzhhYTvomnhPQ9Q5ly8uYSeLXTt4hXyNuwsP0KthXzhUM5E7a GtJg9RRizND0RQKwpTVv3qyBsyY1gQwakebOUAfyO2jW1Iv2dkydwut9fDwVMq59LaFQ ZpuqzbxEB2gaL1FwiNJxFiLvkURhAXu5lIpS0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=MD4SwW/08TmbG3Vp1P7f9CQbz5/bFAEy8m9eJlUaWww=; b=pvxuO9PNuIyLF38XBmsBCyK7ABmWoqT7v873BmmKyuTxXVSUYfTnB0kZrUHxPE9Rf+ EKikI6CCsSVz7LZBm3BZ92IBFJ6Yy+CHi0FF3m2GjKY9WpvjQQ24NqBfDsa5aYEFRtIY coUHUoQY7qe5bAy2hwbBx5Ftn791KWmj0mWZj44hS3pO/Pd46D5grLdTwcuMwmykIK2Z nqT31YhvDTYFcKhgsKi39ULCFGKbSuJ0xcbbULztY3TA4SwXY2kvoHQFbBhg7RDMgAkj tDzUC356wYpoMveYoaJ3Rtu5ErvK/jI9ersf4Brpfu/YrDKQzVagCt430FJkerx8Gv7s U7fA== X-Gm-Message-State: ACrzQf00MCYSfZbe8kCXCDfy1OHqrz+596qn/bdlmoPDgmoAXyEUTn0T DYEthV5Ey6jGLOz1rQea5uRbzIkblUiQdWrn X-Received: by 2002:a05:6402:22c7:b0:463:cc1:42a2 with SMTP id dm7-20020a05640222c700b004630cc142a2mr26917506edb.217.1667482871219; Thu, 03 Nov 2022 06:41:11 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:c1a3:5bc:2068:8f2c]) by smtp.gmail.com with ESMTPSA id j1-20020a17090623e100b0078d46aa3b82sm521948ejg.21.2022.11.03.06.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:41:10 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Nov 2022 14:40:47 +0100 Subject: [PATCH v2 6/8] media: uvcvideo: Allow hw clock updates with buffers not full MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-6-d8d0616bb612@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: HungNien Chen , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1627; i=ribalda@chromium.org; h=from:subject:message-id; bh=BH9PcY7Nw7PbJJTAOdY6AwyTSedyQ+9jvfKW8fLkjJo=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjY8TsRxi5Vy9wQ2nxxtG48pDSu6Z6ueZod4h/Px6r cobTdYWJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2PE7AAKCRDRN9E+zzrEiIWiD/ 9MI3xwHTwNC0n6AVmEkxTioQNbbXrXLYUtOfYpxt+Vku0wLgCx3rO17nNMWONCGdTOJhviIIydnDX6 8qwXc158BX8d1PAtGE+7Gcvdr4B5w8whE2Qbgp6cbE0mBJzW28uzLMj8Ja7nLREBXxKCmvyArIy5gs M5khQl5peJrQU8C3KnJufMuGPeBepFdgentCuWyK2r4BtHervXB4s7whVt2ho7Mc01YgMBNf84rWTu icDld4uSn6XYZZfnY9yABC5XWExub6kM1MYLfOX5x+fF2JKJPG1BG8oLFsSxWQ16BbyAPmH3pX9YKg dI2Jkg7owGCzAraNbt77wx5Q1ec3NefFP18Mo713MWUX7XH6f9OOTK+dKaf8UktUv8JmxRH/vhBWFR uNeJz0AK5USbYJelnz2mVrdMxVGZ/a1rZVY2Idw7Li4AuQhBZvCqVHQr0BM+I9eI0iBhP7L21WnElr NYUryHWyU+LaRJXjPDrbm+NYHkz89oUJbTkQCKRgUhbyoM9ON2hn0LTkcPBKOS2N00zqiVAWzkKJEU F8CwD0wpTLxM0Jzeyh/Xwnnd1ve3ewvQpgbyg0igJhY7gyIb/wrjFEYZQ5A+gtR8nCZfv5DusK7zu4 SsTnJv9QMRkI63/zuBnUvuATOG7xFjK2xvEv4wCDpohdYVpwydJE+kOSHmyA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748483144274005266?= X-GMAIL-MSGID: =?utf-8?q?1748483144274005266?= With UVC 1.5 we get as little as one clock sample per frame. Which means that it takes 32 frames to move from the software timestamp to the hardware timestamp method. This results in abrupt changes in the timestamping after 32 frames (~1 second), resulting in noticeable artifacts when used for encoding. With this patch we modify the update algorithm to work with whatever amount of values are available. Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 75c32e232f5d..7c6448c6d706 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -742,10 +742,10 @@ void uvc_video_clock_update(struct uvc_streaming *stream, spin_lock_irqsave(&clock->lock, flags); - if (clock->count < clock->size) + if (clock->count < 2) goto done; - first = &clock->samples[clock->head]; + first = &clock->samples[(clock->head - clock->count) % clock->size]; last = &clock->samples[(clock->head - 1) % clock->size]; /* First step, PTS to SOF conversion. */ @@ -760,6 +760,14 @@ void uvc_video_clock_update(struct uvc_streaming *stream, if (y2 < y1) y2 += 2048 << 16; + /* + * Have at least 1/4 of a second of timestamps before we + * try to do any calculation. Otherwise we do not have enough + * precission. + */ + if ((y2 - y1) < (256 << 16)) + goto done; + y = (u64)(y2 - y1) * (1ULL << 31) + (u64)y1 * (u64)x2 - (u64)y2 * (u64)x1; y = div_u64(y, x2 - x1); From patchwork Thu Nov 3 13:40:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp543394wru; Thu, 3 Nov 2022 06:51:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6QHyKk5Ut55txf6J39xFj6Du9HZshqnp/7MASwsdXRrylsTbpZze2VbuQ011pQxadcA3jT X-Received: by 2002:a17:906:9bee:b0:7ad:c4a1:b8e4 with SMTP id de46-20020a1709069bee00b007adc4a1b8e4mr25029557ejc.283.1667483485784; Thu, 03 Nov 2022 06:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667483485; cv=none; d=google.com; s=arc-20160816; b=u85HQnpmmv66/O/M0G45vAAkHrTP8rfzNJQtDFBWFAkpABCzTu2EEMis41/GSH3MGI dfQP+WXwfThLGGyItd4Y/two0oQ71ZjMp6bW58jew8gIZHaCOGTzYFR1dNm8Xliqa5rp 6IYHk95WCyJ2rc0Irq4sBAJxqZQoIztK76ijj0fdNz8IZC7xBbUugCT3l8KVjgQSfiaI mFhy99aV6o6jU+DZsMOybXR9NJTS21zALE33ZYUn4RxL4qPZgKTvgfhMfAdCXTHOSooX 80rCv5yNa+ixDnhn8GzcitfAL/XVBpcwf9hDE4F3HywUZ4Q/LHZ33mgz4Cy+UpqKIpai TgtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=psoRMtYNQ67Qjhdcr6Qino20QujIYk2bcuQnFUuY+cM=; b=yZ9NZNsmTVGjo2gZtcuhdy/mDyhY015WbnhS10RXdJbFn6UD6IfzdhG9izgXE/jMHG qmNpYnrlbrUJ3cD91jFR7I7JDhbW/ZkCsXyC3FNVLFGIJqnIjiSaL6A5WZWlZlhhaXC1 NkFovrGopdsB/PAtSqBe2C0TkLylCBl1qLp9m87TtU/+0WwzIKZCS5ceCgPI8OVhrXyT kPREkxbZXJcVT/IEAabH6V8MES/yGUC00fKd+EjoAXUdnCF65CNg7eK2iGOkeRsJu01G Y/oKXpF6sl8QbShAXjUO2wrK+EA8+uItVsf//LludwPIQi70kBUIzocJF0wKK8hZkKFL Z7DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=h2qCos2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv12-20020a17090760cc00b0076f061ffab4si1630472ejc.51.2022.11.03.06.51.01; Thu, 03 Nov 2022 06:51:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=h2qCos2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231795AbiKCNly (ORCPT + 99 others); Thu, 3 Nov 2022 09:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbiKCNlP (ORCPT ); Thu, 3 Nov 2022 09:41:15 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E558DB4A8 for ; Thu, 3 Nov 2022 06:41:13 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id v27so3087674eda.1 for ; Thu, 03 Nov 2022 06:41:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=psoRMtYNQ67Qjhdcr6Qino20QujIYk2bcuQnFUuY+cM=; b=h2qCos2vriedJW0565u21lOIDK2ZXT5CCnGPJl414YMJ70OF6mdre0wcsNWip00EJK +VdgkIjiL7h2IsmFTUXwESgwAL+sF+BbBIU+giGCvmWdWFZtg/yBef8oE0v0noasB2fL YMszHZJc6WGNgzp8eCqHh7uS36aLaB+dFLj10= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=psoRMtYNQ67Qjhdcr6Qino20QujIYk2bcuQnFUuY+cM=; b=K/4Dd1xh50pB619biHDy963Fi0yPo+I7oNqFoQg63okCpyRaZJYF7eB3uLqx7gCNDg 68IRgvNcTkwpInVkNi/oZI/0lnot6MyGvD5lw6lU59Eyavu8IjkRjKPdjJTtXHM5h2IP 4VQdbeaj2XR+ys3JcHLV5IpY9avselBUZQz7t5tFkycq/a58W0DjLVGOhi/F1U5Kq0fh CaogcsIMU/fji28xrOXVduzTSi4+ACnjZp4774rrhNOzNwSAujlUm9UNd/s7ZlrPrETq rFT+ytCSvxSs7q/FJ7GX1ujb+z2xWK6a0Rz9PJHG8Tl0ra7MtsAsKvtN1xIPodh5M5jm soSQ== X-Gm-Message-State: ACrzQf1+72A8a7OLBwgusdFEy6F0dRSC6juwqKbF/bT7lTcp2yo6jNxx zVvTiUPUHj6BgnOOPSHdHsuZ7pHTfbzQtWG+ X-Received: by 2002:a50:ed82:0:b0:461:ab45:df1a with SMTP id h2-20020a50ed82000000b00461ab45df1amr30226646edr.295.1667482872297; Thu, 03 Nov 2022 06:41:12 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:c1a3:5bc:2068:8f2c]) by smtp.gmail.com with ESMTPSA id j1-20020a17090623e100b0078d46aa3b82sm521948ejg.21.2022.11.03.06.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:41:12 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Nov 2022 14:40:48 +0100 Subject: [PATCH v2 7/8] media: uvcvideo: Refactor clock circular buffer MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-7-d8d0616bb612@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: HungNien Chen , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=5733; i=ribalda@chromium.org; h=from:subject:message-id; bh=jKLEhWOw50KCtY3geJta/+rFLohqmF2gBH8KzE83PQA=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjY8Tv47RijJ+yGizQXGOfNQ8/ZeH569iaM4vQ+yoE t9mQGl+JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2PE7wAKCRDRN9E+zzrEiCipD/ 4+sgbPvtCjP4KFkF9Aw6yYFYZVZRR7jLD6vlhTeTkQCxU5SQ48w+nH/7mBahAyKP1etMVa2abI9rzF BiumH0x7Q0TSnlRVs2Zz0jguw5mgN/a+b1DiQdjuoOK1ugT1D0q1Hx9G4/ku0fpEVnzmlJwLsYNaxh Tvoe8+IKd4cQgctZmTLH8uLTVK/sLyz9BAHLDORUCz6uJRmxc4BcaO/NEYcMIq9XUDZjiIStCPuZAD FZRFvPIN/5/iYxmV/UjLCpt3D0ZZBnzgV9XE9f45DFUO1MuiaZ4GAEnWvkFd7uv4TcVca4EJHK6nh0 Ak5o/pxczaqgFvIF9r4A951AqqdhMl42joBIFN7qP1erW4Zdbdg/fzmCeox+J+mYtVL/ri4+IVIst0 RGKmlkOMpdLAFcJzSxJnGqbxAJZpVEhoinpWRktqMw1NhqrG3nze/NPSYpB86+2PJTLufVMTDY617M bK4q6N0kkN3jcJ2HKUav6z7MHMN+5lT7W13I1pOCfDwhezsOpCOF3xX00BsvUOv7JVgDtaPU6gmPLr Vb9QW4X1DEASoMqGh7pvoWH6x0Lw00TQ6Om51eCZozg+68QaxNdp7Op3/lxO0fNAFbImHZQObCGXRk 1a9d8mu5qIDLHMQRSE2x8MyzNU7zhPq06Rvnzsmnbu9OHwmUU6hVUxa4LfNQ== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748483163797919167?= X-GMAIL-MSGID: =?utf-8?q?1748483163797919167?= Move the addition to the buffer into its own function and remove the stream dependency to all the clock functions. Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 7c6448c6d706..c81a8362d582 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -464,18 +464,29 @@ static inline ktime_t uvc_video_get_time(void) return ktime_get_real(); } +static void uvc_video_clock_add_sample(struct uvc_clock *clock, + const struct uvc_clock_sample *sample) +{ + unsigned long flags; + + spin_lock_irqsave(&clock->lock, flags); + + memcpy(&clock->samples[clock->head], sample, sizeof(*sample)); + clock->last_sof = sample->dev_sof; + clock->head = (clock->head + 1) % clock->size; + clock->count = min(clock->count + 1, clock->size); + + spin_unlock_irqrestore(&clock->lock, flags); +} + static void uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, const u8 *data, int len) { - struct uvc_clock_sample *sample; + struct uvc_clock_sample sample; unsigned int header_size; bool has_pts = false; bool has_scr = false; - unsigned long flags; - ktime_t time; - u16 host_sof; - u16 dev_sof; switch (data[1] & (UVC_STREAM_PTS | UVC_STREAM_SCR)) { case UVC_STREAM_PTS | UVC_STREAM_SCR: @@ -530,20 +541,19 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, * only the first one will match the host_sof. */ if (stream->dev->quirks & UVC_QUIRK_INVALID_DEVICE_SOF) - dev_sof = usb_get_current_frame_number(stream->dev->udev); + sample.dev_sof = + usb_get_current_frame_number(stream->dev->udev); else - dev_sof = get_unaligned_le16(&data[header_size - 2]); + sample.dev_sof = get_unaligned_le16(&data[header_size - 2]); - if (dev_sof == stream->clock.last_sof) + if (sample.dev_sof == stream->clock.last_sof) return; - stream->clock.last_sof = dev_sof; - if (stream->dev->quirks & UVC_QUIRK_INVALID_DEVICE_SOF) - host_sof = dev_sof; + sample.host_sof = sample.dev_sof; else - host_sof = usb_get_current_frame_number(stream->dev->udev); - time = uvc_video_get_time(); + sample.host_sof = usb_get_current_frame_number(stream->dev->udev); + sample.host_time = uvc_video_get_time(); /* * The UVC specification allows device implementations that can't obtain @@ -566,46 +576,29 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, * the 8 LSBs of the delta are kept. */ if (stream->clock.sof_offset == (u16)-1) { - u16 delta_sof = (host_sof - dev_sof) & 255; + u16 delta_sof = (sample.host_sof - sample.dev_sof) & 255; if (delta_sof >= 10) stream->clock.sof_offset = delta_sof; else stream->clock.sof_offset = 0; } - dev_sof = (dev_sof + stream->clock.sof_offset) & 2047; - - spin_lock_irqsave(&stream->clock.lock, flags); - - sample = &stream->clock.samples[stream->clock.head]; - sample->dev_stc = get_unaligned_le32(&data[header_size - 6]); - sample->dev_sof = dev_sof; - sample->host_sof = host_sof; - sample->host_time = time; - - /* Update the sliding window head and count. */ - stream->clock.head = (stream->clock.head + 1) % stream->clock.size; + sample.dev_sof = (sample.dev_sof + stream->clock.sof_offset) & 2047; + sample.dev_stc = get_unaligned_le32(&data[header_size - 6]); - if (stream->clock.count < stream->clock.size) - stream->clock.count++; - - spin_unlock_irqrestore(&stream->clock.lock, flags); + uvc_video_clock_add_sample(&stream->clock, &sample); } -static void uvc_video_clock_reset(struct uvc_streaming *stream) +static void uvc_video_clock_reset(struct uvc_clock *clock) { - struct uvc_clock *clock = &stream->clock; - clock->head = 0; clock->count = 0; clock->last_sof = -1; clock->sof_offset = -1; } -static int uvc_video_clock_init(struct uvc_streaming *stream) +static int uvc_video_clock_init(struct uvc_clock *clock) { - struct uvc_clock *clock = &stream->clock; - spin_lock_init(&clock->lock); clock->size = 32; @@ -614,15 +607,15 @@ static int uvc_video_clock_init(struct uvc_streaming *stream) if (clock->samples == NULL) return -ENOMEM; - uvc_video_clock_reset(stream); + uvc_video_clock_reset(clock); return 0; } -static void uvc_video_clock_cleanup(struct uvc_streaming *stream) +static void uvc_video_clock_cleanup(struct uvc_clock *clock) { - kfree(stream->clock.samples); - stream->clock.samples = NULL; + kfree(clock->samples); + clock->samples = NULL; } /* @@ -2085,7 +2078,7 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset) stream->frozen = 0; - uvc_video_clock_reset(stream); + uvc_video_clock_reset(&stream->clock); if (!uvc_queue_streaming(&stream->queue)) return 0; @@ -2219,7 +2212,7 @@ int uvc_video_start_streaming(struct uvc_streaming *stream) { int ret; - ret = uvc_video_clock_init(stream); + ret = uvc_video_clock_init(&stream->clock); if (ret < 0) return ret; @@ -2237,7 +2230,7 @@ int uvc_video_start_streaming(struct uvc_streaming *stream) error_video: usb_set_interface(stream->dev->udev, stream->intfnum, 0); error_commit: - uvc_video_clock_cleanup(stream); + uvc_video_clock_cleanup(&stream->clock); return ret; } @@ -2265,5 +2258,5 @@ void uvc_video_stop_streaming(struct uvc_streaming *stream) usb_clear_halt(stream->dev->udev, pipe); } - uvc_video_clock_cleanup(stream); + uvc_video_clock_cleanup(&stream->clock); } From patchwork Thu Nov 3 13:40:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp543427wru; Thu, 3 Nov 2022 06:51:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6AK16V5CNFtqEhLS2bxECV8Wg0qqLVs7FF0OS3CFfWEOGSbSZFNPSozTMmm7rVO+t2QyI3 X-Received: by 2002:a17:906:8470:b0:7ad:aeda:f47d with SMTP id hx16-20020a170906847000b007adaedaf47dmr27612057ejc.139.1667483489450; Thu, 03 Nov 2022 06:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667483489; cv=none; d=google.com; s=arc-20160816; b=IuZa81Ze5B5sTMy5Z8mOYCTUVGhxI9H7wI1tRI19+6xtpZ678d96q2c6prTsJibqN2 XRXxAvSjpIuPSWIqaGK9m0H03z+q1+/PtdBNGK68beqkENCFWovCfaXGuYEUjb91ilq0 McrxGT0qo4j7diiNiw1sacGEQb1zI+05YU76CXJ3x0i65JSwmj1k7LHCAoqwNYTHrfXE ayd74UDYazKp0JCCW/UWhoVwUDK60l84wnVBxrK1VFWYYyG6S1DSB1C3sacuzrR3/oaL 6EJiYLsVkdV7qudsLyumy7lyENr15w5TMPJ5WLqLMD2dOVQkIZSgG8yHxpM2VulNIFor UlXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=QBTXj0Mo20+lqPJvJbV07DHgoZv0TgJ6xnkWV3WDOVo=; b=Fu+hb582o3UaFohMW7+S5tXl+XecuW73M7uQZa7dhSi3hlo6CKhwLRsr5u4I+yleUK DvZ4wnTlqKa48n2FOsNX2xIoV4SQn7Dl6pZDYE0JbAjJ5UqZb5gnDDJPS7eeKTNwrBs7 f0GBfV+Pbbkz9UHebkBfXQZ+cTw1/BYmvA16oVBSfe9uF97eWHI9/bCYbXDzqUrlhWJw fh2zjIpfGwcokqfprRtzIW9GwAClLWuYwmkk8zwAENoD+8MwpCKJtzgJYZWhL84jhWoU vKl6Wm9EAKRO/yPxY0mLFAOiV2UI+rimSLHEsN9qxI/J4vFLmn9N5duZLemPTPlqIYYe Ibng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kpJ+DF6P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 7-20020a508e07000000b00458b71488bdsi1041137edw.388.2022.11.03.06.51.05; Thu, 03 Nov 2022 06:51:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kpJ+DF6P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231881AbiKCNmD (ORCPT + 99 others); Thu, 3 Nov 2022 09:42:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231697AbiKCNlP (ORCPT ); Thu, 3 Nov 2022 09:41:15 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA35A13F47 for ; Thu, 3 Nov 2022 06:41:14 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id x2so3080056edd.2 for ; Thu, 03 Nov 2022 06:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=QBTXj0Mo20+lqPJvJbV07DHgoZv0TgJ6xnkWV3WDOVo=; b=kpJ+DF6PjVbaFJFClIwC2LT+GMwpgkrYik0GCWpQWnEDyK5RHeaEmgpN1H1m4pbPO7 iukhRLpcj8n97CqE4Q7s2Ho/Kzw1UDSm6WdoUl9u7ERHkMtxySQqCpCXMFwVduVwX5Qj ucny/W6XGe89qBRpKfMowg/k6LTpMzF00Z1Mw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=QBTXj0Mo20+lqPJvJbV07DHgoZv0TgJ6xnkWV3WDOVo=; b=qZLEMbarZl5b18imtW77lqJE9StEmZdpt8Z9ERyU59CwVf47Nm8jb98LYzjCn7YwI7 BpeKPiG3AsOu84FMflbKi42yn17ZpZ3FKWOs2ON6PRbdhM7wxA24rN6a7dlvsA60dIZq M+r4yzk0+JpAhPo4z6yXDRVoryEAZv3YLMPMEm+fvQK/2seivNBizZAOsK14jTtJo/Fb UvftyHpi/uhIjgDhkVwCpg4FpZ0JLPlhje87TrXueYq0KTC8bYJNxFsdQtC17ODY7Elc hmfOpK02Pl3FYlvtRTdMQuQrELUzkJcb66LvPLMg/JpRZgbP0qSoJbYKcZzPMj5wSAyD rHjg== X-Gm-Message-State: ACrzQf3kjt+FJQ6+PnxU+digiH19gZB6ojMNmtK68PzDbC2UJ4WNRm7k KQLbOJrIXohmyzX/3e8U9Wu4SzHGCZ7xsKgI X-Received: by 2002:a05:6402:274c:b0:461:9921:60cf with SMTP id z12-20020a056402274c00b00461992160cfmr31079740edd.353.1667482873385; Thu, 03 Nov 2022 06:41:13 -0700 (PDT) Received: from alco.roam.corp.google.com ([2620:0:1059:10:c1a3:5bc:2068:8f2c]) by smtp.gmail.com with ESMTPSA id j1-20020a17090623e100b0078d46aa3b82sm521948ejg.21.2022.11.03.06.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:41:13 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Nov 2022 14:40:49 +0100 Subject: [PATCH v2 8/8] media: uvcvideo: Fix hw timestampt handling for slow FPS MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-8-d8d0616bb612@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-d8d0616bb612@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: HungNien Chen , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=1969; i=ribalda@chromium.org; h=from:subject:message-id; bh=pNerfrtBJbE7z0e3sYuUA+5U9LQzvOcTp5yM8ujyuVs=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjY8TwN3zXisLOmlBMSPM91NI1ZKp/+UQ2K81uRsDG O4RuhOeJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2PE8AAKCRDRN9E+zzrEiDeXD/ 9II30l2x2EBLHN1QVJa5o/1HeUqhrKrd81xF7n/aHdzfnYDRZnyNZ477pPsKiLmvjWhf/9hzCl5Z21 NCgJXb6jHEaegZPKkVuIFjidXdx2NW1UPAYBNfk/fPH35+FxX8cVnTKFfna10nIb5OjAQ5133ksSKn jMgF5tvLQzL1/+9XMRTBOru1sXl9QF1sP1QrPRyCc5+KueXH0cNelcomv8L9PDQLpSCXy1WRVbJgzm Z/KJEqsnvW/ERAJpT46Rx8MJP97Xi2lokEtvGGGhA0a9tDP0Zn/IXm8k99kMniK02qt3pZ3OVmi05F aadaxwSOBus9ZD8BTYmrVqX1ruw+grTT+KuZ0dP+zWMk4juMkbqoWoxqkYz2sjAdN6wKG74ZT/hdnI MrTFEs5BQl5P90SI3SBdEa5iV3uZ/IfLqzF31qpegSxzDWqERNjNgT7j7RFAQl5eaWSZtJK9s7Bz2U 7YXwt+i0h4NItmLSorZUqn0M7bpT3cWPkCvcw+0c4j41M8FysjckCgHnlBdraFpQawANbSmsX1l0Pj iLsc4FMZQq66GQKq87BODBJ3KDMs8kj1YHT9pTCs3KJifowILFBmA2GS/N8cOHLO6O3DqJnC+6WsUm kwujlSEBPKCnr1uIcVzzZLXgCum1ZErNMqG/JF+O9YS9XLsyNJ5LfdXMN+wA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748483167534655358?= X-GMAIL-MSGID: =?utf-8?q?1748483167534655358?= In UVC 1.5, when working with FPS under 32, there is a chance that the circular buffer contains two dev_sof overflows, but the clock interpolator is only capable of handle a single overflow. Remove all the samples from the circular buffer that are two overflows old. Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index c81a8362d582..6b6bd521d6c2 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -471,6 +471,20 @@ static void uvc_video_clock_add_sample(struct uvc_clock *clock, spin_lock_irqsave(&clock->lock, flags); + /* Delete last overflows */ + if (clock->head == clock->last_sof_overflow) + clock->last_sof_overflow = -1; + + /* Handle overflows */ + if (clock->count > 0 && clock->last_sof > sample->dev_sof) { + /* Remove data from the last^2 overflows */ + if (clock->last_sof_overflow != -1) + clock->count = (clock->head - clock->last_sof_overflow) + % clock->count; + clock->last_sof_overflow = clock->head; + } + + /* Add sample */ memcpy(&clock->samples[clock->head], sample, sizeof(*sample)); clock->last_sof = sample->dev_sof; clock->head = (clock->head + 1) % clock->size; @@ -594,6 +608,7 @@ static void uvc_video_clock_reset(struct uvc_clock *clock) clock->head = 0; clock->count = 0; clock->last_sof = -1; + clock->last_sof_overflow = -1; clock->sof_offset = -1; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 14daa7111953..d8c520ce5a86 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -647,6 +647,7 @@ struct uvc_streaming { unsigned int head; unsigned int count; unsigned int size; + unsigned int last_sof_overflow; u16 last_sof; u16 sof_offset;