From patchwork Wed Jan 4 10:45:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38852 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5076297wrt; Wed, 4 Jan 2023 02:47:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXu8GIpXdhQjugHwwmgtjcDj0lbA3Zh4lnXjpiYbWsQ+wZ6iyvHvfYd8uTItN5yMEnIf79EZ X-Received: by 2002:a17:902:c193:b0:190:cd21:1ebe with SMTP id d19-20020a170902c19300b00190cd211ebemr51497192pld.1.1672829243572; Wed, 04 Jan 2023 02:47:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672829243; cv=none; d=google.com; s=arc-20160816; b=cAzprirQOXkeEldjlfOHk619r5L2Q+ReX8lL3m3VGtQ0XJM5Ou9BE+90Fdwu+vj5Sk xqUsH6DP1ajDg87k4i2qVRH7/sQGgpd+/Qpjk9cHeW4Cmy5zwD2ubJcnsAcsmtGiRSU+ JLX3TkXRpmOnfuauoVMYl9Z44Y7awheQWuwq0os4Viz63/csUisxbqoQye2oWR87DNhz bq7hdaZFmAtv1miAnRVhBIgZYPWPnDtIVU9I/Q0mccAHMv1S42zGUWvq+CH34zCyHKvC PflKdbfoprArLPFk2hnEEsDXyAemt2+paflm5TX28K6lvk/twKePjuDPK1+OiqHduCzs 2lpA== 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=eP05S7oAYieh5bsYhS+hlRcyIQXVRRrXBen8HZvF0wQ=; b=y1hX0VJbNpRWMFYR9UU+n4ONaCYIRUOhNkbgoetF6ymC7VmfKZk/VDtZ8rN210/9NS uAx5dJ5DXTpxmffyxf0OTV2E4o2dxKqTltd1mOnda/YBHolz7s5wocdAZ2+2Yt1aLupm zE3ZKmvrae5FyLPyUfA+rLesFGT2sQw1p6TlrUstNFOYI1jNbZzpIjAA60f32oz/x5Wz Jjv6xfCl+DpUIJ9FG9sBGUcLI/z8eh/fvS/5jOzq5YaYE/Qy9a0cepfm4pr4bXMLMbay mZtCtHXoAt4OVGX/7uSroDaMPxvwHf41xWw+6X7mkoVeb9VLmNCUoP7CdSr25o9m2RHC tcAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TYUlwgGU; 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 m4-20020a170902768400b00189e2b9e630si32718518pll.270.2023.01.04.02.47.11; Wed, 04 Jan 2023 02:47:23 -0800 (PST) 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=TYUlwgGU; 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 S234946AbjADKqI (ORCPT + 99 others); Wed, 4 Jan 2023 05:46:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234871AbjADKpx (ORCPT ); Wed, 4 Jan 2023 05:45:53 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 528A713D6E for ; Wed, 4 Jan 2023 02:45:52 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id b88so40703703edf.6 for ; Wed, 04 Jan 2023 02:45:52 -0800 (PST) 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=eP05S7oAYieh5bsYhS+hlRcyIQXVRRrXBen8HZvF0wQ=; b=TYUlwgGUYxQtBfQgr6HAF4WRrUCCs6+Q0x3+s33syXNwAyHgUx7MmRNnZfoFphJsO0 giJw/1wEtflygRfp6kGmlMJDw0homhhm1lP9eBOGsSi3lviMr8vlVOAWJRvLfG29jOsg po0ua4KgiALWE8geDkbcEIRjGDq71eMrpXthk= 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=eP05S7oAYieh5bsYhS+hlRcyIQXVRRrXBen8HZvF0wQ=; b=uMDO0hQ0Z1+1CFtXnXggyh6GQi7R/8F/aHgcNHjPLkz7V2EqR5PcelgfSYNacnTnh8 vLYtfcQQ3abc+j4V9XxMMGLgqZjpouFav8kPgIK2AJ/uPmkzFR0NURFGuYA/R+/qWqiu 8qgVJMtw5Kpn6HFMOTayL9x6So3p3kFIFqSUi5oRVQZstX/AFV4y9//ESOapTxiyHEte bF7xeQc9xMvu9W7sDQck2boexY5YFkLHOSBD2bRaj640RkCjOY8/Sqlh8a2aFEvujusy KihUPMoG/HZJSvfBZRIx0Q1+Mx1KPlQH1QR2afbGxviqe5qUA27Ih6TYEsxaFEZnUO4B bPFA== X-Gm-Message-State: AFqh2krQtI80EgHVVAvCsLMEyzVGWRrSObHJ9piFxt5S7M8jA9j6ntYa i/cmu2qclRS7lMceApSh49VLXA== X-Received: by 2002:a05:6402:104d:b0:486:ac69:b9e4 with SMTP id e13-20020a056402104d00b00486ac69b9e4mr24243186edu.4.1672829150883; Wed, 04 Jan 2023 02:45:50 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:6531:9bb0:b3f7:86a8]) by smtp.gmail.com with ESMTPSA id g32-20020a056402322000b0048c85c5ad30sm4754971eda.83.2023.01.04.02.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 02:45:50 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 11:45:19 +0100 Subject: [PATCH v3 1/8] media: uvcvideo: Extend documentation of uvc_video_clock_decode() MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v3-1-db9faee7f47d@chromium.org> References: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, "hn.chen" , Ricardo Ribalda , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1176; i=ribalda@chromium.org; h=from:subject:message-id; bh=uQh57Ft7V9nCoa2uBX998qypJtqw/WiItNoLfzr8WTk=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtVjPU3f5Z2E9svRZE/BWIO4lXtzruJFEEjK/8sH6 EOknXiiJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7VYzwAKCRDRN9E+zzrEiLUTD/ sGwSgyt23Hqu3cs30g8YGANyD6AaaRfERUnK4WLltA5EAVO8D1bab/irnj6GJhQDRXxO4nIGlB4XRc +0PsAYCMV9axdVIaNuLR7416mKF8eV/yCVrBN1KDbAH/9UkW+YQA8YAdDw9hUPJDAgukr9Y+B0E95w zrOkB5+o3TLiPXZiJ9eQXg//iOP2OEvJlxirJBDMXCNUX7ajl86WuMZAnDNhD0D5rFAk2UpP4SKJF5 MaNc0uIvYZhhjqYyLYiKOX5QawWqoGnsMza4unUGUxiil+tRpYoiqs7Uuz+t6TpWw6H/wciwm337in JqDChnNCGVn6lrg6parvA6l4xoCpEHedrm8R4noQtpCO4SO9lxB4QxruJmYzMU4Qmr4vNYL9eaIFR2 /y8tS1ZDt/dcKCUemWtMeuS2zJs4p9BrTneYpOGq7R+8LnbHpzah8tvJ9H3ytwHC7LK2ec5za8aCB7 HkiUx8c2cmP4iIKD7My9Zg8LzDIKb8FTJ7PB2i9RK/UXZfQfLuB2JyXqSTkUE2o4IOZDmvFbGO08r/ lzpZjb3rrWmw8NQQdq6a5odzPqbsc6jMveYNyTlsMqVjjjAbenmR75obHlP2RVsgfetnErHOeReOgz RLrrFZngMRK6YLqc0l3+bklN0NFKE67ARUQB6+Fvn6GZzHD0aEYLWpDsw1CA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.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?1754088597129181141?= X-GMAIL-MSGID: =?utf-8?q?1754088597129181141?= Make an explicit reference to UVC 1.5, explaining how the algorithm supports the different behaviour of UVC 1.1 and 1.5. Reviewed-by: Laurent Pinchart Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index d2eb9066e4dc..def079c7a6fd 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -516,7 +516,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. + * previous one. This filtering is also needed to support UVC 1.5, where + * all the data packets 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 Wed Jan 4 10:45:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5076252wrt; Wed, 4 Jan 2023 02:47:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXuITdm1QP4DkJVR+2rIpyZAciVlPFeE4j20kzMVLiPWamBJpsCTqQBKoCkjzMSq3w+j+Kv1 X-Received: by 2002:a05:6a00:438c:b0:582:9f43:2c7b with SMTP id bt12-20020a056a00438c00b005829f432c7bmr7902201pfb.17.1672829233838; Wed, 04 Jan 2023 02:47:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672829233; cv=none; d=google.com; s=arc-20160816; b=is0HAXj6JKgGIKjjTf6HGERwBjPYMwjxSaSgXbknSREMPsqwT8ZH0gOQPP7hdwBH5p YwkBeSyypwMJgfzlJm/3B0wjBmbBC8a2IvRthcJVtG0quy2y2y6lbCLOw3/M75kgD9Gr MEi6pVIcsTFPtJ5KnJyS6DmGN0fPdUyzCtlO5cZkpuM5fhMmIfL3m+qzGMvhgRBB8IvC qto5rbQ1WEyQVELJQMDxVoqun64DfJN0h33ICXlSkEkZorn//pt9tZWi9paAXJjqfbuy dWufByvqgtTSv7kTEtynPxScBWNAkDuF8qnTj7woDmcKAKxGDlVXn30dt1CNoZ5wu3zW BW7Q== 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=KyBrI1RwfXQizMxJ8rnnrBo4q45UrKGn2OI35vCZsYY=; b=M/8tK6Q0tKHSZcwYIWy3Ume/cwv5D0gBvwLf+OlBdu0wOeR6H90AWe4qSFgcCVjPKl QHVASebr+mB0RU124maJluHcMnywRGCVFbpckZSfkS0QsCZathO2yeMB05Zyi6+n3FyT I/7hnPXb/MyeemgxrItyHIkBK5XCrRDW8etrzn7sGNyYk5aGTCDzZ0GnHC3wYMRIuCJQ HrfqgiyOAUolbDpZdee1MK9boMZY/8nTKk5gi7HO2NeTdSN6RdNtooBozJAwMSFyXPxJ p0DhTaJjmC6EPgUR+ZvpMNlQpVFYxL7rpnF9Wuy/zxvMV7jagcCyERg2b7df15BDqRxa GTiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Uep3phL5; 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 f5-20020a056a00228500b00580eb840b53si30184367pfe.343.2023.01.04.02.47.01; Wed, 04 Jan 2023 02:47:13 -0800 (PST) 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=Uep3phL5; 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 S239089AbjADKqT (ORCPT + 99 others); Wed, 4 Jan 2023 05:46:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234902AbjADKpy (ORCPT ); Wed, 4 Jan 2023 05:45:54 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E13A13E27 for ; Wed, 4 Jan 2023 02:45:53 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id fy8so17561797ejc.13 for ; Wed, 04 Jan 2023 02:45:53 -0800 (PST) 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=KyBrI1RwfXQizMxJ8rnnrBo4q45UrKGn2OI35vCZsYY=; b=Uep3phL55FIMMwa37576Z/9XYaU7Cjh/iSkuW19M9vpAiL+74bvM1KKqyQMnfC5vO1 2/ANgpV/Fvb0SiM+laEYOILg+QbE0pSwYEdxLv26eD+7k9FRRQJA23cVPxX1Ou6UfxYj FfZTQ9PbbKeBDGGS3JYlBg8ew6fyphoje1Hok= 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=KyBrI1RwfXQizMxJ8rnnrBo4q45UrKGn2OI35vCZsYY=; b=kqSV4dWLPxgRGFx+ABgiLamZjg2ZcMPoBSXL6fU+7pdJPbcgT4KEZLc8OFYJ2pCdfE X2NGt0Wn+24fDpSg1jR/YO2N/9GZP8IBYG+Le029+URigedKlQ0I3OIzw8gHrwjHojbT 7iZ4pxe/a4UujrpDAzIfANFhEcHNUM29e+ouE/OWCC7hogjFnj+k9ZOT8lDgRpKJgEhV ot3+K2q3oPoygwoge+OIfY2LizEttHzwbYbwq+bc6AJSCbEGogGbzcOOAgZipMtB2BEm stvvpkmg5MO0Ewug6gm3xUg0sEMqgGlJ7WaKjQ1u19k30JhlTOYYm6chWR0HCTVyGsum YdtQ== X-Gm-Message-State: AFqh2krBZfjCr5f8q9lCFpGVUgXjZLZ2zAY0YtShRisbOWpVGKFPXCXS 8nJjfZHtz21zjSlmAbjUOCo7ww== X-Received: by 2002:a17:906:5619:b0:7c0:faca:52c with SMTP id f25-20020a170906561900b007c0faca052cmr40663884ejq.37.1672829151931; Wed, 04 Jan 2023 02:45:51 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:6531:9bb0:b3f7:86a8]) by smtp.gmail.com with ESMTPSA id g32-20020a056402322000b0048c85c5ad30sm4754971eda.83.2023.01.04.02.45.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 02:45:51 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 11:45:20 +0100 Subject: [PATCH v3 2/8] media: uvc: Allow quirking by entity guid MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v3-2-db9faee7f47d@chromium.org> References: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, "hn.chen" , Ricardo Ribalda , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1797; i=ribalda@chromium.org; h=from:subject:message-id; bh=FoOybSKY0S3eTj4qt7v1f6DB//nxdb92ZYxbnB6L0cM=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtVjRUGIm+ptCBoYbh0RSttvX3gody0gvY/pWZOUo z25/ILuJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7VY0QAKCRDRN9E+zzrEiJyED/ 4smqXXbUx0OhCo1Gk2G1q5NSxcv/gZhUPIrEp2CohBfmROuHc6K1uWFI1PSWxodXVZi2w/hOugVSCN ptF8H4UiBgG0CRwz/UMibCVCYQ5/ODjGYOvcqlieVFr9wvog+Pahb2fzfCXzw/Up1qVUUynedr9WXj PZUOovW8NBWkos2NsAIE8qZ6oj8QRFiHck2hdqxpHrJsENA4NbHVrNldoVOFsf/VrGi5RCempnU4aL L7QwrwiA8A3YVK+6tTdRFnkEKD9ZCDD2FEyyHPj0TqG+HxVFDmxlDfo1IJ9uHS0h6Sc/pgjMMUNl4C 20esCE33VIUp+jT4j2mC6EL+AEe8txMbzavnbHbVRL1BshNFl5EgmoNO72p7peoCS8ZfbSTXBXz1Wg gI0xVENtpBIQ0A64LjlAGM/sqOCAj/j0JkgwK/S6rLPeWbLRWgizLqXfnV4kvz9TV7CjWBVO2KcgAu OBZ7V4kB8YvO0zh+VvOc6QbsTjoSm/sLzqu3jPqAPk9PmrOY/Z0fWAqx5UZEbuSUIuoZe3bZeYW5DX OGiv1eBKLAVISJ1toBBYhwbQIHcNF6pqipBUmfpdN6HOPiwLvHZDDrCOaSA9I6RkkKmJfHF+5nog8e N6unuSrLBaSDn2KDvWYkEVIZU5086LK9v44mMuZH1TeJSKe54wgDHAcCeyQg== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.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?1754088586706069971?= X-GMAIL-MSGID: =?utf-8?q?1754088586706069971?= 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 --- drivers/media/usb/uvc/uvc_driver.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index bd3716a359b0..5448576a8413 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1195,6 +1195,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; + unsigned 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 */ @@ -2154,6 +2176,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 Wed Jan 4 10:45:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5076545wrt; Wed, 4 Jan 2023 02:48:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXt22k/H9K/mcGalzd49MEcMeKIHceeju0CKQ535fM4UXrGlS9mikhhf1z4gKZnEkys6hK9E X-Received: by 2002:aa7:842a:0:b0:581:8755:4953 with SMTP id q10-20020aa7842a000000b0058187554953mr27338950pfn.23.1672829283767; Wed, 04 Jan 2023 02:48:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672829283; cv=none; d=google.com; s=arc-20160816; b=e/d7XbEkGyWY5j6q6X3+z96VV4rkdkEABk3trDIvEp487grPe9874Lbh59wgZUPcqm 4u6tYHOf27+LbeZ1EkUN8K+KFK3rB0CcN0ZSmysDZ9zeGzE1jQaH+4DH48r+cOMQk++L HVPVAbOe6vhNv8Tl35kyH7XmcBdV3KsSrrqU4mtBj280yA5HA6zlcqlDG7sDlsbYTsk5 4CMAfDXM9AN7d+zOvzY8EM6B0fPs2W90ZkddrgeyqaKA5s4coCb/+Rf05FgwmVbN4gyD FxiuokXEDdSmquwZXbd+EXlTcr50AJvL5Zuayuy3U4mgqt+v0eM5DILctGWP2kesGCV5 JF9w== 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=LJWDrSRhEFhfGsFyYK0V6BHpJWAjFj2NsvQbNJQkprs=; b=NyuvGXa1wVSJD6WShtSdpUKYjGJwGjyBxVlKYFYAB7u3NS9oa7x2eWKVXkiBpfnUmO mr4FAM/Nq0Lq0xivv74mMivU0Pk9T59RX0ieVLB5CUSSCmEUcjUl8Amf6cFNZIb17E1N 6eDuII5RkNWs1CLOVNxdRAn5/Gi7c8DGyvm1T1ilUxhyFqJyn3dUui+Smm0LbZ1CJsUQ YiHGJE8IN+YlsPT9P+mx6cBrUODo8lV/VRHpjkZVJFbOQTqVp+fdKzvfkdQggoToYVTE HrO5AU1LETacBjOh0+hRRbeYJ2X2TpksvWHdwq9TC2pDu2MoVc1+sCP66S5czvVGJnCC gc8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gJi0oHoP; 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 p8-20020a056a000a0800b00580439e00fasi35656875pfh.45.2023.01.04.02.47.51; Wed, 04 Jan 2023 02:48:03 -0800 (PST) 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=gJi0oHoP; 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 S239068AbjADKqP (ORCPT + 99 others); Wed, 4 Jan 2023 05:46:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234693AbjADKpy (ORCPT ); Wed, 4 Jan 2023 05:45:54 -0500 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 2DFC813E0C for ; Wed, 4 Jan 2023 02:45:53 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id u28so43181898edd.10 for ; Wed, 04 Jan 2023 02:45:53 -0800 (PST) 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=LJWDrSRhEFhfGsFyYK0V6BHpJWAjFj2NsvQbNJQkprs=; b=gJi0oHoP2yFg0MctdLdpqE2ESdF2cHoQkqWB66CMsRRLkx7Q4QcBm7En77HJmkBgFL Izg676PvTW3XeZPahl4WF8CF/bP+GLi9KfSdZh+ABN6xGgZlawamckeOJk4ph6cCN5PG 4i8B81JkqAThkZHqUJd26IiL1i4wbcNfWbzZ4= 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=LJWDrSRhEFhfGsFyYK0V6BHpJWAjFj2NsvQbNJQkprs=; b=3w7ZLe54fsxW2RQpBSSX9iEP53+VIso04bg32Sw/o0PsLM/fxMAgtVULVgEI/qe29A N5kLnlGjMhvC+MJkMIgvY+/k8IgovA7nxd9so4Fh3dQm2JAHC6GIDT562YSdmKHabr4t VdIlX1J8nIR/WWpAQVP1gt8svhLKSuAroUvirDU4f1k3cd+oPkQaMstgxfvdGkTWceZZ ejt5ClVQCu5oC7aurz1tdb3d/dwrCLZ4cntstrKRHCcjW5nI9HWH88Wz7EEVrOMG6aRO T3h8eIwh6y438Hd/s8ILXLv7Kbzh2nSM28+LvMXPfEpASx1rxZ0ecZmH9iaNf6oBjJwS SGEQ== X-Gm-Message-State: AFqh2kq7Hc+q0inmrmJWxukW7p5UTMJQohYzbY2H7NY6xa77nIVQey1u odlLWQf8qwtPKMMeQSG0hsFMgA== X-Received: by 2002:a05:6402:3807:b0:47e:eb84:c598 with SMTP id es7-20020a056402380700b0047eeb84c598mr39079345edb.30.1672829152764; Wed, 04 Jan 2023 02:45:52 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:6531:9bb0:b3f7:86a8]) by smtp.gmail.com with ESMTPSA id g32-20020a056402322000b0048c85c5ad30sm4754971eda.83.2023.01.04.02.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 02:45:52 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 11:45:21 +0100 Subject: [PATCH v3 3/8] media: uvc: Create UVC_QUIRK_IGNORE_EMPTY_TS quirk MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v3-3-db9faee7f47d@chromium.org> References: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, "hn.chen" , Ricardo Ribalda , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=3974; i=ribalda@chromium.org; h=from:subject:message-id; bh=BJkG5vQwJjJAWQiYn2AnT8oOmSykPtFRv62ZOzP7kUA=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtVjT3benz16nMI5QBuxLX89IhlFS3jj70mLziY7U 2sKTeoKJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7VY0wAKCRDRN9E+zzrEiAA8D/ 49aOWCU5C/qlUPltX1KrAh75mVvc1R54PVqNns8jIVP6/vUO8mqFoeD0Ox3MdmyvrRQYoYp1Zh+tNV vHCmFS5HcDZd9IYDTQfQ6aFrstJS1pOhWO+vo5Ed9eksrydvvPYtjKfOj6KtW0SBL5MBzMe6iJIXrd TOotq9qlhu8B6n+L1C0fJbw3GOfjsW7KtdPV+HbpBEW9V5GUl0GeDY6tr+/b5mwq87gr4z++dpg7ig TbNOByRJXeI2An/RrUg+qhPlT3jhQszJcJYIvtR+4z0MZJqs+T1qo/10LybboyeL1GZGZoB8vFxQAa dwSPFPFmQTzckc99NivjZq+gwBQV/pex40z7Af7nwboemFTfWKhUMxI3inwV75qRsbADvBF8AZBq+o 7ATjhHfL5WCaq3/fia1wROy3yBAEdDmh2Yv+RHKBoG8y5/TW/oz2VcITIiDgRmu7ZOg66YkLQakjTv EIM1Jj+EDE509i/sX1lSnj5oz9I4gKGnSRdnA3/4CtkJ1ZHceN8+OgxHGzxps8P68MmKKL2TFos7fO Mg+kdIoo65ANupzDpmMCf/Cj6jE/yJF3FMyJprKtHgSiup8PalkiySFmkPfhoIk55WPY9h8TvZ2QcZ ZRNN3FlDieDn8JIBD82/sJeRDsLeZIg2X9cbre8Ey7R2tv524Ii1i/fwWZeA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.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?1754088639004416927?= X-GMAIL-MSGID: =?utf-8?q?1754088639004416927?= Some SunplusIT 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 SunplusIT and from other OEMs that rebrand SunplusIT 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. 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 --- drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++ drivers/media/usb/uvc/uvc_video.c | 10 ++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 22 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 5448576a8413..c5ab6e2d24c3 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1199,6 +1199,17 @@ static const struct uvc_entity_quirk { u8 guid[16]; u32 quirks; } uvc_entity_quirk[] = { + /* + * Some SunPlusIT 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 def079c7a6fd..f469c62bedca 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -500,6 +500,16 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, if (len < header_size) return; + /* + * Some devices make a borderline interpreation of the UVC 1.5 standard + * and the packets with no data contain undefined timestamps. Ignore + * such packages to avoid interfering with the clock interpolation + * algorithm. + */ + 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 df93db259312..c3424ae29339 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -74,6 +74,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 Wed Jan 4 10:45:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5076534wrt; Wed, 4 Jan 2023 02:48:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXvvdLXiY/FX0h9m81Co5H0SeXg62rScZ5Vs7PNGH8DBz6oVGbiLqLbr3qrZxWl/VE7zg3a0 X-Received: by 2002:a17:90a:4094:b0:219:c691:9925 with SMTP id l20-20020a17090a409400b00219c6919925mr52757651pjg.7.1672829282695; Wed, 04 Jan 2023 02:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672829282; cv=none; d=google.com; s=arc-20160816; b=RH78nG6C7CiHc3GnrisDuMKrj8METIP4UK/jsx8Km9Lg35L+KsGtLzPQyyBTPY0haZ 31lBCp0HWKd0yEVApECxMw2FtK/j9r6ayTWFq+mI5+TphPQuL8TzzR28mnLl/2ivm1lt pmHN2ET4gQrQ++vF8NHA5iqSgUO7FKddbhMuqpzohD0gejGqZXRWLs4ITLUruSlz4AR/ 9Nwbk/CQ8zyvB6DXhckcE3dxThV4pbbBy0/iPTLh7tCHU3K86SG71afmksaItwZvNHxx r2BlWpsjUlBxGAeaGCUdxtm9y6ITl2sVuTicsZED1ypPM/bb0JNlb9Au0ejq7O9c3YQp LNVg== 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=5iccy1mOhkEmE1PLN3U2ExlldVmSVxYcFcoIeCsEwlQ=; b=DmbV52HirAvxokuqVRFr20k+ZHbiDlcSxiRPOHSdpW+V6LTv0mVtb3UmJZzt2Voc8p 8q23bR+cBjqkeGA9mskeSAMsPIoKd0wPCa22qUKtPkNhDE5GAe9uA3HC2zAhP1Yjs1PH fl1N4wsloEgPT2bvxPLwDvr+0RE/9NM5tU9vStLLxiIqvY/Q1LveJc51foMFszQTd3Zb fSxl5RIBJFzX7aJ4YWLB9ImfUW7q6G/dv8Wast4NI9i9A5YF+ULqimWUSfE+yNlEMp50 MSorNcXn0r+ZOdvuezYnsklV98zBPl4vyXjrw1QfPZbGqltWERgfSnfUZKxFYN9G8luf 9NgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=f2Fztr7J; 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 mw6-20020a17090b4d0600b00226bafac3d0si726541pjb.34.2023.01.04.02.47.50; Wed, 04 Jan 2023 02:48:02 -0800 (PST) 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=f2Fztr7J; 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 S230249AbjADKqY (ORCPT + 99 others); Wed, 4 Jan 2023 05:46:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238902AbjADKp4 (ORCPT ); Wed, 4 Jan 2023 05:45:56 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF71C1743F for ; Wed, 4 Jan 2023 02:45:54 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id l29so40935347edj.7 for ; Wed, 04 Jan 2023 02:45:54 -0800 (PST) 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=5iccy1mOhkEmE1PLN3U2ExlldVmSVxYcFcoIeCsEwlQ=; b=f2Fztr7JuvNC7senkDZqqw01nLMiialjzNpFdhL3P35iDCjDHMI2FmyvKXBrPFUooa ELqmg5MgZh+7/nlB5Gcp3EpFR1PMKZpp5xxxdnAzm6i5O08c4OFWD9p9MJokT9Zi7EJZ Z/XAjglDNpQVaSXdi9XDNgNYcRM31UEEOB1hI= 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=5iccy1mOhkEmE1PLN3U2ExlldVmSVxYcFcoIeCsEwlQ=; b=FuP5jVjIjKJGt5e+hcUiHLkPlf1AQFRhFodlsW8GfkEKJ7LGt8ZvvMnWKbhWyv4N+u +tlyaGNPu2+E5vP94/RB8zKhxfsFZWqM1MSSOTICvV7+1yHfBiyO9+bqKb7f4vSIdDEi aJ6zh+Bn/Rsxoqddl2s1DDKWi1Z5O5cTVyBLhIc9v0bO9YDKNixVFropMmUa5/UZyQAE naWlTloIPVhk2ayLM5edaDWBATl6nkt7yWz+Tx7paOG1QbbBRBqUwWZHaYTMDFVDG8bp LL/h/H0IiAFgG+68vNji+xQ7ghYrJvTXcweueknRNiQmfFOZ7biYEbeexrcOLFmDF5uQ UIqw== X-Gm-Message-State: AFqh2koSQOiPBZWaRf5DXYPkQ1ph8H0DraZPCpbm7nkjpIZsEO16JjGm 86XCVUK0mpG+Oj15+79Mgwolgw== X-Received: by 2002:aa7:d04d:0:b0:47d:b4e6:a631 with SMTP id n13-20020aa7d04d000000b0047db4e6a631mr40858113edo.7.1672829153476; Wed, 04 Jan 2023 02:45:53 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:6531:9bb0:b3f7:86a8]) by smtp.gmail.com with ESMTPSA id g32-20020a056402322000b0048c85c5ad30sm4754971eda.83.2023.01.04.02.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 02:45:53 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 11:45:22 +0100 Subject: [PATCH v3 4/8] media: uvcvideo: Quirk for invalid dev_sof in Logitech C922 MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v3-4-db9faee7f47d@chromium.org> References: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, "hn.chen" , Ricardo Ribalda , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5538; i=ribalda@chromium.org; h=from:subject:message-id; bh=Wsf1Wp3a/Huhnb++hUSQ1p3B//D9EJZrjWECEqWLm0k=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtVjUSO1A2pI3RH/4ObqEKNarKdcbkJdUKk8m9h3T UVYHYxeJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7VY1AAKCRDRN9E+zzrEiK27D/ 41498SeqsUC94w2LA7j36W6bwiDzLolqi+vDLu9sI5fzW/YDVWnyEQxf0nEEtJdtxQg5qtjBMyt7ik IvQYYLBAc2fWYpvXs8RUtWknNERPgnF2iSnLHMziVxkhYWbYZ0RMD+jEh+gtrAidA/GbBQ2jhDq5HS pey2zMubFZLlcULTvsL57dYcfuYIBahWJ+qI+XN0f4GNBDZh5g8Nw6mMAlDjRarcONkIYHlaI+AbNB mIrIb8/yhBwtanTC2NYqV20jvHTls5EFuzV2Ssgp/gZtnzW9BmsHOPoXK5BFEYSrhitsyRBJhM8GWx 5lF2ml+hzKd1m4moijHq0i0aFfJXpBt0IzCFOr5shOfAS6kGscyVOuX5gsqYx9A1bQYeoBPNm4acXQ rhyPxYGICyo131Z6ggez62DcBAQJ0fwOXCepoZsYZmDHUB6/UBb/kVlzklyUfoxK5ZbUy579Y+8bYm JZBanaR3mKIO2TJS7+YaLDShtRulvvnZssfNtYSwMPRgZczXvoVENKnR/e7xk2dO7W9jUSJcTrUEAd yH7F2Hp+9fZp9ynTW1qWCM0Q4eD/I3YV7Jg0UjMGwY5LQC394Pfv9QbRjhzoQVFzrziwvAMcDtuc4H gQDF3fCwYDjT3lNG40ASuJm23GJE4SWASbqbtqpZyKzFOT0ZcEt50ElAaPEw== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.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?1754088638057651533?= X-GMAIL-MSGID: =?utf-8?q?1754088638057651533?= 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 packet handling jitter is under 2ms and use the host_sof as dev_sof. We can think of the UVC hardware clock as a system with a coarse clock (the SOF) and a fine clock (the PTS). The coarse clock can be replaced with a clock on the same frequency, if the jitter of such clock is smaller than its sampling rate. That way we can save some of the precision of the fine clock. To probe this point we have run three experiments on the Logitech C922. On that experiment we run the camera at 33fps and we analyse the difference in msec between a frame and its predecessor. If we display the histogram of that value, a thinner histogram will mean a better meassurement. The results for: - original hw timestamp: https://ibb.co/D1HJJ4x - pure software timestamp: https://ibb.co/QC9MgVK - modified hw timestamp: https://ibb.co/8s9dBdk 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 --- drivers/media/usb/uvc/uvc_driver.c | 9 +++++++++ drivers/media/usb/uvc/uvc_video.c | 11 +++++++++-- drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index c5ab6e2d24c3..c89a1eebe91c 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2582,6 +2582,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 f469c62bedca..bc75c7c40251 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -530,13 +530,20 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, * all the data packets 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 c3424ae29339..88d1790e6695 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -75,6 +75,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 Wed Jan 4 10:45:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5076253wrt; Wed, 4 Jan 2023 02:47:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXvM3X1r5XWleqIQlEJx9RFOORyxD788E11Z/4/TSzm17tWT8pyQSsgB8kDk1sDgukx3KbO4 X-Received: by 2002:a05:6a20:c1a5:b0:b4:833b:7f03 with SMTP id bg37-20020a056a20c1a500b000b4833b7f03mr12374081pzb.32.1672829233901; Wed, 04 Jan 2023 02:47:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672829233; cv=none; d=google.com; s=arc-20160816; b=gPwuxMJeOOHBgYg+f1w4BPP7+KrDpSxRrdgmXYyFY5KfogWRMcAQfdaTOzzxulsxsx sVNIprQMBXFWcsKDS1d3mDUgF/F+bg8lmc+0nW3o5SeBcrcYhKtvzuFBCILtebP4kYcM GehLeL2RYrIVJaoC2D/4JX9QPK6kalcpy9bMWcCinRPS8udpv5Hafnfjad5m2JWrPe5I BxC+Sjx6eIO7Ja0Vpf0cNdEwRdkpCYDVtU34NRzPwaIIwVDa9WyfI4T2D8F2JVK1FP2/ pTs/e6CKLqGkjdS5rFxTTOaJ4lDMUlDDvMXyGNye/u6vbKHivWeofVL9kwJCwVEESXUU 5rLg== 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=gRp2ESW5K70RCahtEssFSxztB7FTiNHqVBi6bMAAfN0=; b=haJySKadTlgos7leLTbl42kCfzBS23KxWGa//CQkMcUMk7BiZf//8y8zubZ6uSSo/W 0CrshjBt+EMhzXlPQIpyoDZq72F1krfgZ3yaZLy7ZFxfXo+cnDorlDYZKptexBSlcxj6 0V4qfn3dOnnzS0dALKiEjmcg95ndfGzvKK8g1Oyl4iHug0Etqv55F+clnFKBnJ+/0f3J B5MXJ5fMo08pOcbTNO+9KlWvAIyyiI0ox71l7xLGze1tqQfSGqzxDZJooRVzTZFa6f4/ 5bGYcxAE1Mil85DRj8/fqJ1JAzYoz+xeFBd4ug9DNpiIB/tr3HOvo2bv6l+S0JwC8jts sTCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=goF6AiDv; 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 v22-20020a056a00149600b0057e857295adsi2231860pfu.236.2023.01.04.02.47.01; Wed, 04 Jan 2023 02:47:13 -0800 (PST) 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=goF6AiDv; 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 S239114AbjADKq2 (ORCPT + 99 others); Wed, 4 Jan 2023 05:46:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238971AbjADKp6 (ORCPT ); Wed, 4 Jan 2023 05:45:58 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1649F1DDEC for ; Wed, 4 Jan 2023 02:45:55 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id qk9so81383048ejc.3 for ; Wed, 04 Jan 2023 02:45:55 -0800 (PST) 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=gRp2ESW5K70RCahtEssFSxztB7FTiNHqVBi6bMAAfN0=; b=goF6AiDvnYbQdClvRAdQ8ZRJtb29M81IkMrW8uWcNGwo/bkrFOzzOJXIUDVAxPREWw 1S6W1sbAt/vCPsPF2sr8vThV4OG+IJPoE/h7ZlurDsZ1XvPsvcZ7lnwzsAn1Zs+cJhiK l0xKX5drhYqI+MPgCWwwptAwlTGs8pSC21dm8= 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=gRp2ESW5K70RCahtEssFSxztB7FTiNHqVBi6bMAAfN0=; b=KMT1qpls46s3oWPcX9v1Dsmy9srCpZMPcdkbOa6dUFRmWfIpc5Q5NAcpJFLacH/cs1 hdCmF88AFlBkUSctN0bkrAStDE3XFhoae/NP8Ezb1n/Lss4scD0ZkaASLL/E+d6egYEU mwc1A836h8pFAwf0qm56DatNNLACUKZABNKm0pnDgycKsoEM51bQffRo9eiuEbeVab+F Ca0Tp/1BXIpOZnIx9OqvF+vy1EV4Nu46i0cF93n3Rbx2ujhppyA09beGjOxXOg6z4wzR 6OGtasDr0XIV7UGwPC8mrNv4ZrauLjiaJ9bDLF0DTn+TCwDrmAHvRvR2nXCJ2/kqfZvm F52A== X-Gm-Message-State: AFqh2koxYFEBIuZLmUC4Ucv82RwzkXcC1Pkwdqb2lx5dEepLy1D6RY/p YGqXVsevucszr4yhnYbqALt/IQ== X-Received: by 2002:a17:907:3e26:b0:839:74cf:7c4f with SMTP id hp38-20020a1709073e2600b0083974cf7c4fmr54279545ejc.8.1672829154194; Wed, 04 Jan 2023 02:45:54 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:6531:9bb0:b3f7:86a8]) by smtp.gmail.com with ESMTPSA id g32-20020a056402322000b0048c85c5ad30sm4754971eda.83.2023.01.04.02.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 02:45:53 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 11:45:23 +0100 Subject: [PATCH v3 5/8] media: uvcvideo: Quirk for autosuspend in Logitech B910 and C910 MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v3-5-db9faee7f47d@chromium.org> References: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, "hn.chen" , Ricardo Ribalda , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5515; i=ribalda@chromium.org; h=from:subject:message-id; bh=d2H8jjlMxjzySDZwcfIgLwXk3Cr5F/h5s+x9I3bWE88=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtVjXz8kkXnHCmaWyDVSboiRLq0QT5Ep169Pi7gyL TJXvml+JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7VY1wAKCRDRN9E+zzrEiNIeD/ 9rKtvE53i8gHnZbPspMqCE+Y84MThWbpgpi1DDnNk3/JdQfNeQoE2PxEowHC9MiuX1P3jatlI7+q5X qFJ8FdHyfdkSbHlOHRTAlREru5ocoKV92thfQAoK9mPFhsQNRJkwnbClm6UzMUuv6Gza6IAtKCMRxO WtOYjjKy5KF2AnDIv0o4/bc0Tgk8jMUlX9FJd5gOgvu7Url6gAJjY8A0ZD5SSVK5qrShwPoc5s64VG 0AorD0b/rDyquKmz5pZRFjv7wqc3tz9p2S0lQcLK4csIZb94ZgG6OfjjfSeGBAF2IQwNZ+09ZyMOqm jKORQM1xnO6fd0k2QRcKUI5WZd81UOZaaWA6PdwVT7vzgptYI1lxNBKsFt/zEaN27/djwYQugQYB8C Hza/ehEBthDavNQAAkiVTrSQvqhzc6ULiqYEc4tfFeIIj+mKz/fHThmKzcLliyePxkf3KYLoLC+TQ+ A/wu75vwwyIlZxRZYV7EJFo0nj48GNAOZda3AMW76gUuTCSGvpxsk1QEXijJ93vIDiKCHyQszaUxQv Cx7sjCz8MUrUPi7JrP12v79C9L5CLXnr3alfijHkOtVupcI7oEsc6IDzdjTdFseO35WFT9vw7f0ATH GIfo9YtOHDVmu+gQRQ1zpHuvxDyNLQztsjffC2FrM/uTTtq1b+5iuGIgIGrQ== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.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?1754088586531419390?= X-GMAIL-MSGID: =?utf-8?q?1754088586531419390?= Logitech B910 and C910 firmware are unable to recover from an 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 the alternate setting of the streaming interface is toggled. This patch adds 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 Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_driver.c | 18 ++++++++++++++++++ drivers/media/usb/uvc/uvc_video.c | 10 ++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 29 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index c89a1eebe91c..be6ad9b732a2 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2525,6 +2525,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 bc75c7c40251..fe5c7b465adf 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1984,6 +1984,16 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream, "Selecting alternate setting %u (%u B/frame bandwidth)\n", altsetting, best_psize); + /* + * Some devices, namely the Logitech C910 and B910, are unable + * to recover from an USB autosuspend, unless the alternate + * setting of the streaming interface is toggled. + */ + 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 88d1790e6695..24c3e9411415 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -76,6 +76,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 Wed Jan 4 10:45:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5076627wrt; Wed, 4 Jan 2023 02:48:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXt29Qvcp/dU5jnnomVxp5izGiV8f7Oh5inQw1NjJ1QouDj77TWpaR9Z+sv0fjTwg5iTz66y X-Received: by 2002:a05:6a20:3ba7:b0:b2:3174:d2b2 with SMTP id b39-20020a056a203ba700b000b23174d2b2mr49611711pzh.28.1672829296725; Wed, 04 Jan 2023 02:48:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672829296; cv=none; d=google.com; s=arc-20160816; b=A3NUfKYHfRuDD4M7caTS0teURP9l7/GU1AqzD/xcq3qwkdtvIlC1bnvHaNC3pEy3j/ Tpzm6Bu3t+OfQvq3sh4A58Oq9eMn+3tSneChTrtaSSg4gntAFai7LeTUQuKc/JTEd4KZ fvAsLEtwQmbJOzyIfR+RU4JzGxXDb7o69YXAzk7C9pfH+9FPiuz4FD7ajmeCkjYBLKwa kZQUKlZt5lWhF80fjtzybVbEaI3tzHKeoDavtwt6eIlYi+Vvq3NSaLo5iYsBBTLGhmNd 3Z9p9Gb8o7oNKkoLdUNa9Oyo78Io5Owczbh08RbWAU6l1G+qHOR+EkPHKwvhBfC6dNLA Qrng== 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=Fi0DwAZll32eIad2Imhk1W2tOAIqK4+yUvq5hehYizE=; b=rMeki+glmKlTJ/7ZOPN9zHJ/hbjYtll7XODpNvBaaYaRW7zXRViSN3ZhwStWchtziE 2ZssZVstWfh12zlsn1aYIYAaSjN+T7vLOMKw9tMtgXxzkJnw30DUp3wKC+rSOnV/S/nD E2l6J41wHJVbu8h2HtT+f7Vf8G+hN0Hu7K8bq6Q2At8d63jdQHbUKPSiqzfJTNGz2uu1 hS17G2D+XyqKeeE3HBmvsM5+NrRf84sui2b26IegHUstc5s5ZTciVJXfVppBmdG/Sfwm fMzXYXW8ObRbtxiKR/yWnSAjkAOglGikKx2h1BIFUmaGhernTlCfXoaQC9FFXs1gJGnJ ZeLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XUGMCvUZ; 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 y191-20020a638ac8000000b00484b0f15cbbsi36283166pgd.32.2023.01.04.02.48.04; Wed, 04 Jan 2023 02:48:16 -0800 (PST) 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=XUGMCvUZ; 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 S234435AbjADKql (ORCPT + 99 others); Wed, 4 Jan 2023 05:46:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234749AbjADKqA (ORCPT ); Wed, 4 Jan 2023 05:46:00 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1D819C0F for ; Wed, 4 Jan 2023 02:45:56 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id l29so40935428edj.7 for ; Wed, 04 Jan 2023 02:45:56 -0800 (PST) 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=Fi0DwAZll32eIad2Imhk1W2tOAIqK4+yUvq5hehYizE=; b=XUGMCvUZpPHu5JfUsPHIp5UtuySYQQ3ZfTycNgzh4mj/V20ITnQtNomVDsuiaGJaT1 oyXvqyxXOzPSCjI19RAp1geECA+s+BlCE4fESF9UnhdxUtljbZ6F0XRdnfRq2SLJUfo3 pEh1nr6/VLLy05jXwqcFO3AOWX0vYQpAwjwB0= 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=Fi0DwAZll32eIad2Imhk1W2tOAIqK4+yUvq5hehYizE=; b=Jbx09rKiyB3dc1PeGuU/XgQ84newufL5cNQ605BNIEXXYdZ0M2QeJqSYro/ePq3YhL UrwiAfLW+mXbTknnCXzcr0V29Up8Vm/momRCYhO/1r7XZ0YsI2lPf0lr7QhPmBdrEKKn lQyN7v0iF08BDEo2JDfWq0cZ+5PZ2rivvYCsgCX859skjBTBjTH91JWSaQukm7Q2N08l H9WFw/XP9tAcIpYYtlS4UDeJCPYvU8hfGRlDMQi57CxBEQjNHq/h1fxtm+RvAvJzJQET +d4H/sQenlagRbym5uS9ljHiW+jdj7pM+WpUg1uAN9wkfBwHzssIWYHMndeLj14EejW2 PfVA== X-Gm-Message-State: AFqh2kqRZxiJ1Gcpkm1qs0QUmGmumrFlI00PVg9t6zkVJ9OEMcu4SX4n SPPe3RJcBrhWy1AyOWaqubNs4fAUYer28Id4ht4= X-Received: by 2002:a05:6402:538d:b0:487:2ce6:2b80 with SMTP id ew13-20020a056402538d00b004872ce62b80mr25256957edb.8.1672829155133; Wed, 04 Jan 2023 02:45:55 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:6531:9bb0:b3f7:86a8]) by smtp.gmail.com with ESMTPSA id g32-20020a056402322000b0048c85c5ad30sm4754971eda.83.2023.01.04.02.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 02:45:54 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 11:45:24 +0100 Subject: [PATCH v3 6/8] media: uvcvideo: Allow hw clock updates with buffers not full MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v3-6-db9faee7f47d@chromium.org> References: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, "hn.chen" , Ricardo Ribalda , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1843; i=ribalda@chromium.org; h=from:subject:message-id; bh=A2mJudG+6/05Ux5SJhclsJyARWI+ebtKxr7o7Rpc9H0=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtVjYRSolvHGNsAlK8u96MVXslFe5ioZa0X5tQYeg GorUlXmJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7VY2AAKCRDRN9E+zzrEiICuD/ sHUGrAeWicUm6+W27wgC2bTF9F1cAqj5AXqQ3hu4pmQK+0BSNSMIMxUWPLfp0VeT6BgeSsTkrf+MeJ THid/fK4hxg9E2JIYOLYRAa1FK9H/bUbLBl5UlJr2/p74Q9AsF+CuPBFbiOMIHXyLug9hKPzQ0FhaB 82T33bbRv/p2zlaZ6GyAWafawsT3d/4xZH/Evd+2oW/u0SKSINCcdIW8RtZQeDkEM/W4/W0CbPNt2R AkjLHTgG2MO/KQx6Yo4/SIiEbTI38VR/l61+hct7UDdf3n+BliR3cLaljBfgili9qjSK33T31FC+HB IX+MjqA/7XMUy+VUpC4xIBu+i4BuHEvsDiPXHIKUOVPi2kZa6iNy8UMdDapJ/eHe2hLlisGfb1illj SSf8Nbmc/7HSDgvKEZYTAfqizaEa+JxN5Uxir1q5FS0vlvnea9164Vw/aqIPbhPwEx7oRYPC3Uk7WZ 3Wy3AbLEucFFFNB6iSDVhbNlBvmCN7jJjzBirgUIUrSY+mt9f1Pk010/hlcI3K2FZWAOPsqXP4jzXR GkOqa1/oQkXwLz3sC45FE/zNQsDSTrU83mbG0ka8f0Aq7tdd5IDfUy7NlrocgKB6A3Ap6YI+pI//fv TFrzNcXbjAmoWDG5RcekvZRgQU+HRRCp2wpkksqvE6cTo8uLc+nWDnjTgnyQ== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.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?1754088653034768107?= X-GMAIL-MSGID: =?utf-8?q?1754088653034768107?= 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 --- drivers/media/usb/uvc/uvc_video.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index fe5c7b465adf..5c37b080e0c6 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -743,10 +743,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. */ @@ -761,6 +761,15 @@ 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 + * precision. This value was determined by running Android CTS + * on different devices. + */ + 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 Wed Jan 4 10:45:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5076558wrt; Wed, 4 Jan 2023 02:48:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXtF/OThLjAYNhxx4We7GuCqn/uNq/roAEap/xJ7MLVf1K54x4FZooMrw5DfbrU8FstDZtE9 X-Received: by 2002:a17:903:40cd:b0:180:f32c:7501 with SMTP id t13-20020a17090340cd00b00180f32c7501mr53435347pld.0.1672829286623; Wed, 04 Jan 2023 02:48:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672829286; cv=none; d=google.com; s=arc-20160816; b=oq97xg41yoZf/GeER+YI++bl0fwE+5dwf2nJ28T7qXhzSRYteVoltitcmxCTTHdHFC WaWwzJdRB5MWXaMgTMF4vm+K7d7W2A11KcztKaWoiw5xLLg/n99kSD4ARL/2GHVY5Pwa xaexckYF4powwsoB0C6xHL5n/HzqIdd5iFGR9l5sa/lCHBoJ3Ecrr2KxIE1cP7o7HWpf ZTi16UQxoSu9fVkli1LfN2Z/1jWouGyzVNf8gTt08VdFazJ2p8UH6y+7P1XJRQSQFm6C 6rAo7A7t7yDitlIht/CDzXDJOc10anwiZhcYSP9SG+qbU7fgFwRwHk6CV1GKjguJNu0C BhGQ== 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=FDgPA71BB6P36oy/yaWrNwP2I0p7AiHxv3mHi9TEYCk=; b=VJbedxGAI2ga+9SacGm8kH/sCG4c2IgPNaFfP7eJ+ccMlWlwijUxoyIt/1qwsnEZn9 m85UF/+eG6605CXJQ/Amy16ZgDWzuKK6a3YRn8qToFVRAYGqFNZFVIU3B5Kc+DA79ypV UX56PsUehJgnWowftOLeFXVbYb8QK3fdki/kDsYVNddAq8Af4kbv2A77+RT7OGqz95+G hTo8qnw3mKpstI3q0GYV1Pszmp1W/Zsh4OwFACzqK+oMeoECTeCHGiSIlXbamJBSH8g5 jX1ezOgUCjTYsHuJ+v0/RtAm6chw21+HicQJHyPdUHAQMD6/3nFogDdS8yBghmutwVlF qIPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="XtrsS/1U"; 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 x8-20020a170902ec8800b001899dca65b5si38933555plg.272.2023.01.04.02.47.54; Wed, 04 Jan 2023 02:48:06 -0800 (PST) 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="XtrsS/1U"; 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 S239090AbjADKqe (ORCPT + 99 others); Wed, 4 Jan 2023 05:46:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238993AbjADKqA (ORCPT ); Wed, 4 Jan 2023 05:46:00 -0500 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 7C808F5B for ; Wed, 4 Jan 2023 02:45:57 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id c34so41414035edf.0 for ; Wed, 04 Jan 2023 02:45:57 -0800 (PST) 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=FDgPA71BB6P36oy/yaWrNwP2I0p7AiHxv3mHi9TEYCk=; b=XtrsS/1UZK81LaeViHHnmVT6dYQWNOCIPPq6upkTAESvZJtiphcvlwCMmvfFqNqnCG EjEGBS9DFN8QEhPzyZZJxLrhNGHcocY/twTOBwFSZmg24iJn0g1QGeOEh8SmvhPlxip+ Y8BnVpUJw+IqyVLAoGVia6OIv4gIZhAGjUMB8= 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=FDgPA71BB6P36oy/yaWrNwP2I0p7AiHxv3mHi9TEYCk=; b=T6oopitQP7Qh42vAFTSr71qvQW56nwc4kkH1sgnXdIReGgoT/Jf63SL5AuGyfZ028y YzHD5OaAKylxLn0cy/Ratc2el6k+fbYwLtz261Ne1Gi1v5nn5Z31i+Ly4efn5+yfGzY+ +/17eFo6x8bq2Onl/Zi5bFY0FWP0lBugk5p8smj86OfVd+MXe2oT7PiRwVo/0WPFpRRq kBbgBm5fH7MZT/njNGag9cPOqvnQL85xJfrunteSEiVeHiFrmcw1oTZyTk7J/qvifF8R YO1BToCWcD9v6xjKcZefDHvkaB8hoW3VZxTAWSak5Vx9dPAvkSe3VeSb3FDHquWrvrfV YQsQ== X-Gm-Message-State: AFqh2kqSSP8anazkmzr/O2M5R0lJybLk/1UmybUa9Hvt/8q0XR58oGdh R05tEazCtvGA54RpV0Z+GhmAXA== X-Received: by 2002:a05:6402:1f06:b0:46f:a6ea:202 with SMTP id b6-20020a0564021f0600b0046fa6ea0202mr51524811edb.37.1672829156072; Wed, 04 Jan 2023 02:45:56 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:6531:9bb0:b3f7:86a8]) by smtp.gmail.com with ESMTPSA id g32-20020a056402322000b0048c85c5ad30sm4754971eda.83.2023.01.04.02.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 02:45:55 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 11:45:25 +0100 Subject: [PATCH v3 7/8] media: uvcvideo: Refactor clock circular buffer MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v3-7-db9faee7f47d@chromium.org> References: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, "hn.chen" , Ricardo Ribalda , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=6103; i=ribalda@chromium.org; h=from:subject:message-id; bh=Y+RBkriXzItA9F9XcVh0gDzU4cduaikhSaZRnYLxgS8=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtVjatQTNxFXCouiEcpNU0Ctlaqn2ejx6qCnliSKl Eo4FayWJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7VY2gAKCRDRN9E+zzrEiLF5D/ 9EE4FYXMWbulzY9cMNWC8FcsUF07yEeuJ9Xk64XToqjtLg7WinkcTdQgCFaO2N+QLFVb01Q67WHwqZ 8x9aDyjmelxrGLSziyZcoHsnUmWUYCvU7oj6pce8rMZ4DGNIwBuD/LKVRleJQyshig6x8CV1TdrWXW lmT0cU29Hvn9cGGlKXrUnZEgvvUZsNgPLoLBDlJ1jhyISx3h5huo74Xl3/WzK069o2hkkjF1y0eGl5 Y8WegAHOoL2xV9HtMkNXrSfxdHSl+eUeXLoDHCwW6zGnKkC2V53ish2ujMiMVXmRaoD/i5dpCF35AP jBpxKYQ1OEZr2+kJe5BUmxtnxLaJ8vq3umSy+3HdG8hE6cBhU/QyJ095XTg+zS598lXW6T1DNbrZtG OCJneNrly/gZUvGaXGZy6Et8PvG9ND/hAX0F1ADaCunm73Mi9a1ODedunHMSRCHsBR1I6c9y67DSaJ ubDPWiZr4iEdz7sUo4mfUkV/vIYtvvWoIYRORobKkIzV7XddImx3rbondYfwNLvrdcDuXCZodU9hDc k6y6IQkViLd+YmKXYsbpcAEGjfBN3NswDCSS+vRRdOLwWpkkQ5YFFebqdH5CgoKlcnSK/ntavwsems EYDXmlj62UKiKd9DDLqFEpHuaG9AndtoEuEbDBTbYV5YshkI344nHVp0TN9w== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.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?1754088642233889084?= X-GMAIL-MSGID: =?utf-8?q?1754088642233889084?= Isolate all the changes related to the clock circular buffer to its own function, that way we can make changes easier to the buffer logic. Also simplify the lock, by removing the circular buffer clock handling from uvc_video_clock_decode(). And now that we are at it, unify the API of the clock functions. Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 81 ++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 5c37b080e0c6..2c6da49ff84b 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: @@ -531,20 +542,19 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, * case 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 @@ -567,46 +577,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; @@ -615,15 +608,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; } /* @@ -2092,7 +2085,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; @@ -2226,7 +2219,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; @@ -2244,7 +2237,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; } @@ -2272,5 +2265,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 Wed Jan 4 10:45:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5076432wrt; Wed, 4 Jan 2023 02:47:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXtC4u7gsZsNfbM83rqiz6RpYvv9JkgYtOYjSrd/vzmsyu/IbgvA3RvPklbGFDc+na0ICXLu X-Received: by 2002:a17:902:9a0b:b0:185:441f:709c with SMTP id v11-20020a1709029a0b00b00185441f709cmr55697965plp.33.1672829265082; Wed, 04 Jan 2023 02:47:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672829265; cv=none; d=google.com; s=arc-20160816; b=IJFNeBMiFZrlZTNGKtVAXkhiwT54AZkhhBeumatr3f6Q3IWxuiI3pOleiT2iwtfyvB 61ecQKJj2qIiOWSPrH9X1FBqq7LrKedZMmO22gtTzaF9Hq4Yf+Yjr/LUSXl7RNjG5OIF xGfbrqx7HBoGG35bUoWFxFlrv5osWmWyNCwuZDd38CBd8FdmKc9+W5xHyJNHfIYt+Fhk vYIoVluwKewoC1TEdKxIemHWL95lBcTvPTZiqbOFkHT2hecRy3mAGEWspcS25lQwE9d9 F3JsP7EazeDi3iCQJvhLDYa5bwCxFitmCPdY7sqGe5i/FoUrSaKOiUlDdYescI1L26P1 9u6Q== 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=nvhfEUmWAxT7YLgkjs7oKY+EYBIYLwJw8UyNAJpHRQo=; b=JodXYhwXKyhh8te9RBQwS/0uDEQEwcEGhFKFlJIj4u003Q2qJWLKbAAm8v2MHDSNCn TjPCTLfKZN8Np8M6DiCHTjJrfINdJ7dfyoEbzsn+SiyjC55A0hqxbVNOKhEioR5K/Uxr GCZ7db2H2OPbuK9TeAoIqlUMGrcbWpjV+HWuO9JIpPT8ItI6dOTD/UGSPl2PHQDikAX6 QnYYgeX7zl5V5OJ0L88lNJVOi4eBpQ1ZVg5C2Wipj26G7wT7/jjRXL8wGgIMP/bsB1IN g3ZasRp4Ffy1/c8JaqU8xj/Fwkl65v8YKwS5jwy7VKp02VEL/d/ZBj7jKnXC2eo8KAo8 fcmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dISK5CQL; 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 p4-20020a170902e74400b0018890a7e9b5si37106506plf.287.2023.01.04.02.47.32; Wed, 04 Jan 2023 02:47:45 -0800 (PST) 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=dISK5CQL; 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 S239129AbjADKqp (ORCPT + 99 others); Wed, 4 Jan 2023 05:46:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239015AbjADKqA (ORCPT ); Wed, 4 Jan 2023 05:46:00 -0500 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 8D6A5E68 for ; Wed, 4 Jan 2023 02:45:58 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id z11so32155461ede.1 for ; Wed, 04 Jan 2023 02:45:58 -0800 (PST) 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=nvhfEUmWAxT7YLgkjs7oKY+EYBIYLwJw8UyNAJpHRQo=; b=dISK5CQL6NuEAor3u8/gYBexo7B1bhbMOVEmYZZpAoY5p1A/rUPYMT62DxJMx90Npx 7rXQ7lCO+LPb/N0a54iJvyLbDia1pfLndow16zI2lueMd7ZvNURImkDJfvnVfuV0tz8B BiM9S7QYLRWy1MzNC1hV6N7ho/LSBWnBX6ktM= 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=nvhfEUmWAxT7YLgkjs7oKY+EYBIYLwJw8UyNAJpHRQo=; b=BV2QEQskl3U2+gENIABUtJGuIP42y6QnRCMNSb/UAgR9L1ky5qUoANsxRdl/kvD4Lm s73G459n2/xfp82SmkYnwWQawVNpDH3YIY2BvBIT4cdU72xkR0Sj3vBy3u+De1EfyR/J u2spb4w93RQcFC7IqP+Wyb7LjILQ6TuGvx7bMu+7nkN6ndxHVZBTCOgrEiwp+cWpupv7 ECSzqweIa2qAfPF2c7kIlV/X0jmmdjQCRqRvIUaf8ufY0lj4ud7244CKOMO4YWT0eWFh 1eX/0UkUIpVNmewDbQnjjrtwwOnbDC5+VQS5V6zw+rW5o3ERERQyC41IkW9h/ldECLvU K5IQ== X-Gm-Message-State: AFqh2krfcVMFkIGBb50bBDa8V+Iy+TeHUQl5IbOG4jgXzJwTt6B17Pj+ IJfmLx0MTOGYl8CYzaEdJNWxOg== X-Received: by 2002:a05:6402:2932:b0:47e:bdb8:9133 with SMTP id ee50-20020a056402293200b0047ebdb89133mr46484720edb.38.1672829156878; Wed, 04 Jan 2023 02:45:56 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:6531:9bb0:b3f7:86a8]) by smtp.gmail.com with ESMTPSA id g32-20020a056402322000b0048c85c5ad30sm4754971eda.83.2023.01.04.02.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 02:45:56 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 11:45:26 +0100 Subject: [PATCH v3 8/8] media: uvcvideo: Fix hw timestamp handling for slow FPS MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v3-8-db9faee7f47d@chromium.org> References: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v3-0-db9faee7f47d@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-kernel@vger.kernel.org, "hn.chen" , Ricardo Ribalda , linux-media@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2413; i=ribalda@chromium.org; h=from:subject:message-id; bh=tXnPsHtSlRO20+xxBqG21iV1cCKWm3KfmKl4+olKPes=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtVjb523K5wvvjKlkHqfOBA3pdJuwddqB6BwLexTj vGE39kGJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7VY2wAKCRDRN9E+zzrEiKnpD/ 4uI3pEVUaMQ/JFUCpFt+c9XzJcropqqB0VOrgtG/fXURnKGs1j6GDsXgAtvOn2QxdUsoGaTD6E4hz9 9Am7G8HYbalb7qr/C3+9vk8+oFDx3KurgkXqv2vt/W3rLFg+QwOtU50Dkj5xz9E5xcwa0C487LmVrA QsW8i/rVc/Y0n6UUa/nAOYsSKJAGbtjOnhhTmdQNRgELSJpbuRJ7I6ZwrM2JYuaJx1+zU1zpjsiyoL yceYVrSYI0Z/EZYliOn+SZ402dhYEoSwlWjvSRFLTIbYHy6qXIl+XiAVuqC82nxXXcKEtBYGcmRLfW L8IIdihEI7llbp06mYaT7BXkn33P2x4Io+9abzUcqiYLeL7/MVtyUO7XQhA+0SbAOVDkqiiPesARON 7TAS+8G2u3o6PmoFwEaPcTcCgi5rZb1SDYgmMXB9nORZFIrXioAUZi21Hk3Ii5H7QdVLydpJlcI5HT 5aWWv0vhy7do7RWiWXerW9vVzuprZm5Zr7WXQd6j2xm869vM/gaoIGpT+Uw9/8sUKVxq4/iLQKK+i3 mrJj0BoBRgLvjkkyeanNOeJgvfycD0SPpgRY6J/13D4FGO5ImLuJoxPTJWLUagCbgG9zqK0/pIP8Yr k3YnrNzt7kwAlv4xk93YjItVzm0Jz9oOVQS0fIYlEw2AQpSUgV8DzqEg+hhg== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.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?1754088619487510014?= X-GMAIL-MSGID: =?utf-8?q?1754088619487510014?= In UVC 1.5 we get a single clock value per frame. With the current buffer size of 32, FPS slowers than 32 might roll-over twice. The current code cannot handle two roll-over and provide invalid timestamps. Revome all the samples from the circular buffer that are more than two rollovers old, so the algorithm always provides good timestamps. Note that we are removing values that are more than one second old, which means that there is enough distance between the two points that we use for the interpolation to provide good values. Tested-by: HungNien Chen Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 15 +++++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 16 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index 2c6da49ff84b..b0b93e218288 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; @@ -595,6 +609,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 24c3e9411415..6dc015754e99 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -503,6 +503,7 @@ struct uvc_streaming { unsigned int head; unsigned int count; unsigned int size; + unsigned int last_sof_overflow; u16 last_sof; u16 sof_offset;