From patchwork Fri Dec 2 17:02:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 29013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972249wrr; Fri, 2 Dec 2022 09:07:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf7cjVLimEaJhN94d4pGL7amN66+rht4u6szI34i7ySoL/D8jKKKFpB5TDUh9fi4wjILPPbw X-Received: by 2002:aa7:8493:0:b0:563:8d32:abdc with SMTP id u19-20020aa78493000000b005638d32abdcmr53405939pfn.47.1670000854741; Fri, 02 Dec 2022 09:07:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000854; cv=none; d=google.com; s=arc-20160816; b=DY+sug36P69DJUiQrl9NF2iCGwhW3o5V/suBFml0dtmslGdgh81lR2HptVMqURV5wM GNme+f32/GRvRluMLXWWgB3lIzf6B/k5dkemZtvqXVe1VX/tq6q170soAqFSbcF+liDD wIh6Tk+VnFeb8F7/dGe+oCYGczYkG4S/9a1aUY4b8iAncLbhCfao+qSZdVkW4D9eVdo6 0u0Jp85tMv65qo4brkG0vcwJlU+B0UcdUHbJbfIR1roKiLbnADbzdNiKI8/pXeZbuiON uM8PjcOTQM6apoZWW8iCttQGMCoTGiCLWKUm0nZo9GPm1Ld6bC0sDNsK+h5Xoi0f0T1D pg0g== 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=KTzGbELlKza/9kwevLALsVHryAN8WDcrHC7w5wg6Na4=; b=f7dKBYpkhObJWzV6eqSTjA21L2jO/SD95OHSBqlTVo+/gzHSfvWuN//vO6lwYgBRUe rQDKU0StS6Tn0iWPBeSDh33OfOYgnuLRKj9LyCwL3h60ZtBuOjEz8TaFJf643TfTYQhz fesziGtNU1PR7nK8OVJvoXKdOA+e50R0nXVQpxCb9nERucDgbxWlkG4zRvH2YXrBkKOy E98+63n30lVI21o82Vs5q273q1It9bSHBCEp4nlCmnP3toswcFeyPydBpcpnhBPI9JU2 OvFQIabNeOINPeyltTPH+uZcKWf6EMA3g+YuqGLmRTwOnHqT+WtprQBlP+zC8k36idwo Zzdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S1W+HURE; 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 a11-20020a170902eccb00b001891509807fsi8323711plh.575.2022.12.02.09.07.20; Fri, 02 Dec 2022 09:07:34 -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=S1W+HURE; 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 S234276AbiLBRDQ (ORCPT + 99 others); Fri, 2 Dec 2022 12:03:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234142AbiLBRDD (ORCPT ); Fri, 2 Dec 2022 12:03:03 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B70956403 for ; Fri, 2 Dec 2022 09:03:01 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id gu23so12919552ejb.10 for ; Fri, 02 Dec 2022 09:03:01 -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=KTzGbELlKza/9kwevLALsVHryAN8WDcrHC7w5wg6Na4=; b=S1W+HUREYDZKrxoEwQlXVCBdLqkRqdX82DIpktGpRdIUD37IVAzsh6+SFRkd53Gehp wrD3D9qdP8ZtQsarb+lyYS+HWHIa9Dc5HCWTWNabZZ4dOINTJeNiBDLfqhVW39NAc5j9 KwMeED/SfoGbr4LxJhamZkhandaEf2or7m48A= 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=KTzGbELlKza/9kwevLALsVHryAN8WDcrHC7w5wg6Na4=; b=3lIlJcMyxX7YwRVOjz6/c5AqAJM1NCUi8Eywe941+rjWOUfuMvQmzVIlu4yr+BaYWy XyFpLsz9a9Cq4p7OIN5TdiXWpchI6+WgOAi7aBValasBgNzquj/NFsr1sxUCfG9I5qoh EQ7g0V/b+5aArAX07D04hnUC2QBdxe8xzWSxHgTEHuTI3UiNpSeZ45ZQL1ZTFNN1N8Yq 31bfWj1Bmiz3KXnnbyFKB82592Cti+MKQ86uOpFS2wndm1RrkduRDSeYO4tzHiUB1IQP 0kyqn7zFyGp0JL7LyjckCZnndr/4RfrpqllR88lB1yGaj/TGd8ZyuxeQD6wUoJNMNhe9 4sqQ== X-Gm-Message-State: ANoB5plgv7JMSsuGxlNY83Ns5fulfjkjeOfV+SGXHjTm36RXBZyV7vdK xBSu79qTAuGP9pgi1neYAjwVXQ== X-Received: by 2002:a17:907:6744:b0:7c0:8d04:d1f1 with SMTP id qm4-20020a170907674400b007c08d04d1f1mr14711050ejc.208.1670000580335; Fri, 02 Dec 2022 09:03:00 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:02:59 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:02:41 +0100 Subject: [PATCH RESEND v2 1/8] media: uvc: Extend documentation of uvc_video_clock_decode() MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-1-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: "hn.chen" , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1083; i=ribalda@chromium.org; h=from:subject:message-id; bh=7/FBms1zVY/y54Npj9F3M2JJkIZ6gxgY9l354aVjRxo=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii+3/p+J4BSKRQ04UFfbXKbXXmgs+tPfyCpseQQV RMSUzwuJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovtwAKCRDRN9E+zzrEiDUBD/ 4xijQ+AnWrIOeimoMQ3X5ag4tK54eZT+YleK8V+KtwjkDWV0CKU+NO/1q1gnHw5F6Lo1e8Z1doB/cX i/COrdCCXiY5W3bWii+riMj9si4YupbU5L/xZpk9V5aVDrqS0yT5KDdboPm7I20/T5k6HcP/DNgR8p DaWbTWQpthqQk8yYnOjqL/7LsWISKFQZ5v5/zoIdnv9qT5iwiWn5owJ2Ba3BBvYZjk46gKVpVhUZqM a0bYJKvo7AMpS6coBbYSfsox7ob9+3KihZUyuTpt6xARPteYa8ltiXbY+E91LeI+ECzrklNLQ6Kj38 HJoIjsqqckzN/bfGY0tgGQsyA+hMudrXFOv1UjSdmP0RkFWUqcV1Nch2rThr21N7bBVut8W1WGuUeI dsqk9RIHvb0VYV5jc9HZCV/PLFIZ/jy9JjndXnQ7qRo+86gIfZBJqy9C9U6BgHfKyXis2l5HJa/TQt DQKCBYwwFmjLtUqw3dzx7VvFhe5zxl+hXwKLK1fABr8mRkJ0Yo+05a/voyD4WnySlNuewhxAaCDb9n XZe992z4le/DZq6Xt+LlrSkkTlqpFm1dJFxEVLw4c5BhODyJhMS39lbJLJkMyx/xqZAn0aKhY9CSTu x1cOQTBoFizuVkAGMqGCmCjvN3pdhMgvpd7kZIXlaeOS3VuTwbxU2aMVI/Rg== 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?1751122816484438078?= X-GMAIL-MSGID: =?utf-8?q?1751122816484438078?= 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 --- drivers/media/usb/uvc/uvc_video.c | 3 +++ 1 file changed, 3 insertions(+) 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 Fri Dec 2 17:02: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: 29014 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972534wrr; Fri, 2 Dec 2022 09:08:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6uTTBxByTDiLpA5djBxInR4Z+wI2vtCAq12uvLfq5YXbvPQwSfy/nZyFjPC3H+iGpWNUsP X-Received: by 2002:a17:906:fd57:b0:7be:5c6f:e63c with SMTP id wi23-20020a170906fd5700b007be5c6fe63cmr24848338ejb.253.1670000888011; Fri, 02 Dec 2022 09:08:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000888; cv=none; d=google.com; s=arc-20160816; b=PiI3Ej+pLQBeI9x49K9Nsepw1pizSY/Tr1y+Xam+qimDdqIQhwaCt4zpwy86dTz81i QAlTsBcUDL5qfzkWTWDDOrx4YYpuPyTt92s9H2G+uHHe3w+1NLPApXK2p9hT4kxfWX+B zwQHEx/DqM8nQ5DMcgOY+59NLym74PV+vnx+HYX1pUFWhplXv1AUx0KTuxO8kExw+fUb f3hcVj8iohBXqa/e+VRvTH6I3WK1HvIqn9CCzNqDcpiaJ/39rgIJWva3OrE1+MqHCnNf yfWbmAyppSLKjph4FE1npncQfZTJj7BvBULZPrgttirMvQ45R8y2nkQK5r/El/vD9ZV5 mWCA== 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=bNwN70fEkttO9/UpjS90pNFzNVmjhBb547h7/recR+g=; b=qRoqTmOw3q+Q4/XngmSjH3hHhyUR9O/7vtzmwqG9W+TmPBBiKzsg3wYscBjVm52R3g L9xsJpZ4vODaksQTr0VEC2x3/o0wYfXMCYI8RhsRQco45jyaYN+eK2rJUWAECYDWPXKg QctifUyTsQvMZQkn94ZTn6f4gTm7obkO0nDuVNkJOX0U5eMCa5xNYhD7uJb3BNiOmAX+ T22NgVemRfk7K2ZSdSScC1oBK4LcGZFyGwom4IABr8S+yhrvkf9jUhiXgi2jYPMZ0lGI jeVNiJfAmmFNuXj+linZEJUCeQkeJJkQA8B/YF3y235co3zO2tt8dhQnmOxSLcQtgejB 4EjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YMYF3FKL; 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 hd41-20020a17090796a900b0072b1964e54esi7219756ejc.1007.2022.12.02.09.07.43; Fri, 02 Dec 2022 09:08:08 -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=YMYF3FKL; 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 S234363AbiLBRDV (ORCPT + 99 others); Fri, 2 Dec 2022 12:03:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234220AbiLBRDD (ORCPT ); Fri, 2 Dec 2022 12:03:03 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ED5C13F15 for ; Fri, 2 Dec 2022 09:03:02 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id o13so12982462ejm.1 for ; Fri, 02 Dec 2022 09:03:02 -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=bNwN70fEkttO9/UpjS90pNFzNVmjhBb547h7/recR+g=; b=YMYF3FKLRKlD+VLDPSP4cm/n9VDbH+eOQhMJ4Ub0qET1/4YDbnMaYFow1EP3RGfI+m vyNQwoImPxvn4FEnFouVF4PoTlzo+tCYB4JJvcJyL2Jw440PlHUJbuIcJTc6gtRPIlbT 7m7jbmZvRpcEM+ytuQZkODS4ts/U3+6fqeuOc= 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=bNwN70fEkttO9/UpjS90pNFzNVmjhBb547h7/recR+g=; b=LOvTLoVPb2RVk7QXqnwbnsk6eYmb22hQTs6Gux95O/e6tnQFhUPEB3EQbdIBB4cByS 8ixfFVWsjQeIeG5zUA3whdLQv5Q++JzS+Yrr+ELa06drTWOUMB2Zg1bFhMmiBywdbsgq Hyn9rbNqOkWXKVeKuKxYFCmOnLwG1MUePFrcX9sxrl6GD1YyWOxyqJmHB8zQGp1FJ51M kk59d4WrOBJbUP+Q1sCZptdgc+1ffiRevzRCzxRYLt6JfqLFUfeMzQfsvE3hNnERkfsW H87SPEBCnQzVIP6jr4yDqY0wXUPk3rM1hHIyXWz30+7y+2xFvy/nbvpmSEv24FXDJc6b f4iQ== X-Gm-Message-State: ANoB5pk5SuWHvuejF+t8FFT7afrgFBF4fvWpxlYLnR0LGYVpuYQ0RVWM H6C0lj4PvHV/+fippKcruJRrfQ== X-Received: by 2002:a17:906:5586:b0:7ad:902c:d158 with SMTP id y6-20020a170906558600b007ad902cd158mr47425492ejp.121.1670000581051; Fri, 02 Dec 2022 09:03:01 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:03:00 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:02:42 +0100 Subject: [PATCH RESEND v2 2/8] media: uvc: Allow quirking by entity guid MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-2-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: "hn.chen" , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1791; i=ribalda@chromium.org; h=from:subject:message-id; bh=es8VifXL1MkLaxdmrIj9wvoFjqnH8ap0KliznPX0ArQ=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii+4UFyy5wEL7JacPovRxgY/wDg86ABUbzcK85TJ WJqFrIeJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovuAAKCRDRN9E+zzrEiHZ9D/ 4yXuaKvxm2kV9m+nvZzNTV1+awqBpG5QYMl05OQ1Oww/Pq5x7PBGr0GQgVM4IauG2bLsRv6BKdFSAs z/H+qXgVE6q+ObvX1yOphZgnRXAuYZv+Jfy5o3Q1gQNjgw0glnps8A/gHuRf7PEmq0aWuNYRKsEjMB gl/cT+EP8p9dSNX9e7mWK44C4z9dsWfmR12O8urSGzRzR98LOeEED1ywLmh4dklEJId4WjexIOmvhU gmBL9Ir+GUgGk5oVY3VwyzOi2RgVxVhb/WqgwVNe1VuRGINTN/bVE2ckUzey56teTB/+JJeNp7LBo1 WkxaGSUqVvACvKaNZEavwD6p9a7tP5Pyuk25zQrAhlT2DbljorwNyZa55B1b7K4lll7EzVBQ+HwBUd LRy893zuzDEWmtJGgcoK3dGXoaG2VSw9plEXXmSqFZbUQaK0pRDw8bPLhdlRitgpchX9WWcVNQCXsz t8FquJoH4sbmjRR2wxCWLeIFHiwTHTZwJ/eMQEWdjptRspwhpTyGqp2w9rjhxvM8wzrAgEepCNsS6a /3NMoA7ws+dnZ9urdLId4T+nCP70rUtzhB+9uuPKlcIoH77AQBac/aWleL+IjjjIxFGRJhakl9XHD0 7U+mdJMfjOq8KDm+v1elgwnafSKwNHNc7QQwICG6oMjE6VfMcpNT9kFzvt/w== 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?1751122851085675870?= X-GMAIL-MSGID: =?utf-8?q?1751122851085675870?= 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 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 Fri Dec 2 17:02: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: 29019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972977wrr; Fri, 2 Dec 2022 09:08:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf5d2OC4aDMbA+ogGL1/kSkI6EZPcL8ip3zC2r85DXnPD+nWHeSda1mXfqOslqjdz8igCr1O X-Received: by 2002:aa7:820e:0:b0:573:ab15:1d6f with SMTP id k14-20020aa7820e000000b00573ab151d6fmr59449965pfi.9.1670000933177; Fri, 02 Dec 2022 09:08:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000933; cv=none; d=google.com; s=arc-20160816; b=Hq/Xx5D/V0IroDdqNw/HAy1yG9Cz5vEIhPBl8reZgm2jANWGSeHL4vzM6ob3jWuAnf TIQBNtK+vmBztwugb+WsxIC+KhYMP/vYmXgaqfmU83uJmR5045bCe6giAjlDO6FS/zYE 0UBl8Gt8sYukPDs7RBJ14ttuFKlh1R++t8jwIXUGZJ1nUCILb+H9QR7X6Z9MAXQP1r1J wM6eIwQQy3mJBpk1TxMj64nGWYwkWPGLg+1T1t4IU7cQFzgr3XEBKhcpbs3Y0zB+3vHi JfQNU3JCc56YrvlsU570Xosh5KgOyhx8zYNHQzfI8trA1lHeT7QosECo+XveNRqFQg40 ZGhg== 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=z1b0nTFpIaI5p5ZE8W0YvdyyzRVBuMuYrq9RTuFJCfc=; b=zjZ0UA8ZM6yi9mvLJ+nH6Xg3aQjuf6gEHUD7ojkKyY7OitDq6WBjvGgAjMZTxOv4JF zf0U3mIcIyzgLrE7uj+4VvOWbD2NLw3qtBRuH6NdkPcSzYZ3UdOvyZCh4GG67N7YBsea t0NyiIs+RpzidmWXG6E7jsjeaUUxMky60u7XSfG7kWuPBMtIosug7SAkJNEwc5IBHqTT QyweY6D12kM2toUCO3X1A+GAvs5A+wEHHL2FZUDqjDaqbacoSWjqZG+35rOdeL3eHjQJ JZQbrwqHePGNjbT7tBkch1WNMsXcEFT3scDPVWhmY3ox0GBbGEil+LeidfPFByfibgld harw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OUpjWGMv; 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 k29-20020a634b5d000000b004786a8301c3si7077232pgl.586.2022.12.02.09.08.37; Fri, 02 Dec 2022 09:08:53 -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=OUpjWGMv; 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 S234324AbiLBRDh (ORCPT + 99 others); Fri, 2 Dec 2022 12:03:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234252AbiLBRDE (ORCPT ); Fri, 2 Dec 2022 12:03:04 -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 C91002E9 for ; Fri, 2 Dec 2022 09:03:02 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id z20so7212743edc.13 for ; Fri, 02 Dec 2022 09:03:02 -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=z1b0nTFpIaI5p5ZE8W0YvdyyzRVBuMuYrq9RTuFJCfc=; b=OUpjWGMvZnDcLn43zLuHuWVOV3ISdEtKowFcHWm0+5fGSDDSl/v63vR/WAh0TSM7eS Qeusd0VExamLNokTueTAxfUiw2NKAtZUKgbHuVONqUIyh1fx5iNlQaSVwoWbddgN/+mW 6ejuJt/TpHkPeV9fc5sGn6ZRggfSgT700uAvw= 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=z1b0nTFpIaI5p5ZE8W0YvdyyzRVBuMuYrq9RTuFJCfc=; b=vAiJ5m/82yuu97N2+vRGW1EM4XjnPPn9EjLufQeNpCpKzOVRCUCAkr5vpvXd6OkHPZ zUP0egPNfe4K65uxvleNQWjn5i42o6AXUgkzXbPa/dVN8kocfDpy6Xw6euPWpFGGtEEi uygEEcIwy2z5qbDcS+zYjWqt9l462gzrmgrBGeNQz96OcQ47KhBs0Z1TBWjRr/WwH2d+ UjQffUxtKfnhIOuAQMO3I5fnxRUt8dEoqOKbO7SvORr7lapHJfRdyZ1MTCErOzkNOGGR xl0ZtdwTid2m6OSx8GxQsM9y1ktW9+XfK4gQuAe4IQ9/Zy2ypzZRJCy7AMMSXeBB9kKs St3A== X-Gm-Message-State: ANoB5pnIxdoL17o9GQhl6KujnYyg4nTRZzEeetHNHrsdLJ0PrCtN5BTS QAsiPZ6VbTC3lIIdPhCaXeE4IQ== X-Received: by 2002:aa7:c78b:0:b0:467:97e4:6339 with SMTP id n11-20020aa7c78b000000b0046797e46339mr64809687eds.381.1670000582204; Fri, 02 Dec 2022 09:03:02 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:03:01 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:02:43 +0100 Subject: [PATCH RESEND v2 3/8] media: uvc: Create UVC_QUIRK_IGNORE_EMPTY_TS quirk MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-3-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: "hn.chen" , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=3835; i=ribalda@chromium.org; h=from:subject:message-id; bh=ThukGURKifBgx985aH8p0USOirI+IB7ilvRGG3W5Mrw=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii+5H1M58hm5+Na5JGlt2ZCvH5eHmrmhoH7sSZGE ZrQBkNyJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovuQAKCRDRN9E+zzrEiNx8D/ 9EncS+zAdR3hdqeACRDHKENTwfJGH6NYLWeUbbnK+NyO0eNPxeX7yBx0x1KM4Ytj3mAI3Ie83n0SjU mQdL01nH1MVySAJ7UQ1Kqf8xFW32/0aaV0pRJdG4X2ehFAbtypKorgCbTd5+jht2oMZPXWF1QIU62q 79UHEHPYu0s5RSQHWGyoxQhAAFJRgX1/dCwRGHkgWspTIHnTkiy1gn21lAST2dhAchbmOBHtXTu0jM kQwbeQTBGKIQ238AkqAB+EVwqsTsj1K9IMK1o4Lnncxl+asbwHQR8dAuJVS93VkV6CLGAb2pjwUHO6 jMMzTz8knQDV57+TBY6CO8uElX7NoMXl8aKDR6fyBcRpO8FOwIQd6pQ6haBNzT4ubVGRtqeSGt3rJq 36z0wkNDQfpc3MDhnrNPkpC6D+/WO2wvCaa2DNo6v1AEHSvR9+H4gMLfjlIvMCx0amMC5ijK54cbpS 1KDy6Dpyx43o7JR+FIs5s50T8hYD6BOHsz/MVRK0KIs3gVzEWg8ZPsVCnl3phLPWHIb5R73VZ79YqY cTHXWzmnqv/n0UhiqFB2MXrgGahp1yveVgWeRE1dOUphjh9z6ygw6FOk85ImeL167C2EAN/BzL6mPk 12eAnO2y9xgOWUlzq1p9itZUg/oad21SP6Ov1SXVr0gh4iHgcvNmnBnYEOEQ== 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?1751122898536282988?= X-GMAIL-MSGID: =?utf-8?q?1751122898536282988?= 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 --- drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++ drivers/media/usb/uvc/uvc_video.c | 8 ++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 20 insertions(+) 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 Fri Dec 2 17:02: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: 29016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972857wrr; Fri, 2 Dec 2022 09:08:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf6rWj9qZktl5uVLS7GIPQfNCgkuBRrvmIWcZTvf7Ijw95/wuorQYt7B4MHEaFSARuR5lSax X-Received: by 2002:a05:6402:f91:b0:469:82f7:5013 with SMTP id eh17-20020a0564020f9100b0046982f75013mr53211289edb.234.1670000923752; Fri, 02 Dec 2022 09:08:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000923; cv=none; d=google.com; s=arc-20160816; b=fGIPdXxQNypRE9tw4LuA6dYlg7qfDPW5Y7wJLVAJJoaHy6sE43iAoDc/+ZDJ+hj5jl 9ETwZL+j9rzARAl9hEmDV8iDeXzqPQ6iu9KhEjtBI0a0QucFL+j9DkVTN5YF36pHWkCf 4lJg5zbOxclGZISgUCi7hVDFJ1d45ewaxF5LM1QIwQqIJF7lOLewbcQU295KCeQyiFvd sJnNcfVf2+iContieRfl8m6Pf53xOXevQfIqefJIvhubDbRzVSOkayPSIcUYOTJg/b8z NQl7DLdo4OY4gspMf+6uo/3xvxT/vg/6TdTTSs30mgL0Ln3WgQ09jAfhiNf+wpMj5Qdz 35iA== 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=lx0RTwbeF07JW5ZW7wkjZkyoNyHqWh3JjIKMCtW0xFs=; b=YfsuyAG7+MoUcr9nOyUHYZFmq7Q2g/qwGFpcZEJCmHVCig8mYuwLb6rfS/13odOthO T5IZi5HaHc4NlhrEIP8/vR6bFp9y/psoXjR+LmfUOeQ38jrztFgi0yv5eD8GSmnp83cI opYpjK6SMgNE0TC+3JRpjLOofCwWwY1dOKCcgHPlcFvxI7BYZxbGn4CstEr01Tx9BupP hDuZNOW9cwKcxnnNAZorN7z7XfDNQDnEZjIoKzfNMVgFES182yf5FjqV4bbqO1QIPEGc c/slJLn6UEIcsDb5CkedSWKsbjgv3SOyL6xhcS7f22VwiMWz/2cK7IhGk7TS0/wuGBmb dPAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Q0BXyVxG; 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 d4-20020a05640208c400b0046b00a9ee8csi6466025edz.233.2022.12.02.09.08.17; Fri, 02 Dec 2022 09:08:43 -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=Q0BXyVxG; 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 S234391AbiLBRD2 (ORCPT + 99 others); Fri, 2 Dec 2022 12:03:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234263AbiLBRDG (ORCPT ); Fri, 2 Dec 2022 12:03:06 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB43B67217 for ; Fri, 2 Dec 2022 09:03:04 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id e13so7230923edj.7 for ; Fri, 02 Dec 2022 09:03:04 -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=lx0RTwbeF07JW5ZW7wkjZkyoNyHqWh3JjIKMCtW0xFs=; b=Q0BXyVxGC04ZBN43ZmgHVsV2ENEz3uNs5dN0tnRmaOqfDcdwgb1mIuFXyb1sTmKXMC 9UWDUYn9wSJfi3oRQuSgJFtf4CL8YicgTCkK6Q/LZgIwVe5Ifj5P0eHEj8We7j221b2o ekkFERis8zlYXF6hONPczkPBZgvS0Dla31oIc= 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=lx0RTwbeF07JW5ZW7wkjZkyoNyHqWh3JjIKMCtW0xFs=; b=5CD4erVa0REbrQlMeMr3jhg+Jv0LhdfrfKEyD1NNMupMM5qr5SNE/roFTBuu2iEUTz oMo+erawHjRpQ8pNPgYsuFhriiWdI/MAnoCpj/aVoaWX9uQKmQwYtErCw6kaTfhn2YW7 9I4v7BzoJpnDK7C1wRMSNdBM/Xk0KRWFcSph1D/lYUHBWG7SUztgQVJW9ttqj2IAmxEt iWTSidMiy6xaoA6znA2Wcrn6wOTz5tOgUawVJaFN7tHBgng4ppj/basBDDJUlu7jKSVo rfccVHNJy6WCL1142gQgdrHlE56PpZQntIJoT77/Z56Y7sRY5FUuqFkRO00SOgKapz6P 11/A== X-Gm-Message-State: ANoB5pn06FcmZNUg/mlA2PXxaBA2ylNo1Q2iBOzOs22tz0ECr59QFqBH 21tOCMLrQ1Ied0bQqqeMSha8dA== X-Received: by 2002:a05:6402:5519:b0:461:e3f2:38bc with SMTP id fi25-20020a056402551900b00461e3f238bcmr55588823edb.149.1670000583256; Fri, 02 Dec 2022 09:03:03 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:03:02 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:02:44 +0100 Subject: [PATCH RESEND v2 4/8] media: uvcvideo: Quirk for invalid dev_sof in Logi C922 MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-4-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: "hn.chen" , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=4938; i=ribalda@chromium.org; h=from:subject:message-id; bh=CXXqj68dbKHxKKYxVvCObfRHe2J96ojRxuGidUgj7F4=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii+7hkWADKT+kFyE0yUtny4/lV/mcvdYK9d63u6m ndKhSOGJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovuwAKCRDRN9E+zzrEiNkxEA CCRQKBg62it0U3/7hc9gW6lfXAWNdhksJcn/l0I99NsevhUmMPhWe9tREUHjlZhiBibsEf6wqNDqWD c3ZhdrRU6H4t4oBEi0EhmU6KXLs2MfZHnNAW3iF+yqYqzrNipqh/FP3HGjByPdsZuyhnaXtPMyhlpw PdvVFETjuEQlwpT1SRUYW0Mibal9x56jERM9tAVU8NMDVETUpX6o4lfaYH9W1IApWJ1MEa/c9M10ON 16qyJ2Jr6aoylbB5ji2bG0UDwrktJoOYRZB2ze7vCTJD2CVvvbIn5950+kbexh/gNYG7cNg2gMyqxz LRaVkVe04lUh7DxFaeoAgmqoLmCLFGCInYhuyG21SlSiFtpiooPHuThhuiv1wXlvOksEEnTcvY7Lr0 dFP8MFAmrWELd7Be5MvWRw3Iu/2VE8xGYQvbrJstaSrGSowhfh0xgzA+OpXI2UjTIw9J+Qp97hxEmS TiMxjb00faZFwnago/YfIr778vU4TXv2Pdxy2oI94jZWHLRgYbe1//nu1fa3rOrQcaGQrByHagN+7r JSVAE5ZI7x04VE90O+TqMX34Y8qSNhyNlhDgOfu28OpxbOp0Mymu9sC/14Jd2dEWuL4FBst2LKF5GM qh4bukTXXuiJRNjIrQVFvizT/q5BlpdSrQLuVoAJRLMNhwSDaDwWd3c7s2RQ== 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?1751122888755737438?= X-GMAIL-MSGID: =?utf-8?q?1751122888755737438?= 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 --- 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 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 Fri Dec 2 17:02: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: 29015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972622wrr; Fri, 2 Dec 2022 09:08:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7f9yIbQEEwQ9449IvTq7BeUDnbmFsHxbNqk689zwsfhi+Q+AXEJgenrpYAUEr8X8PzHZdT X-Received: by 2002:a17:907:7671:b0:7c0:a3f7:74fa with SMTP id kk17-20020a170907767100b007c0a3f774famr10364650ejc.616.1670000899044; Fri, 02 Dec 2022 09:08:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000899; cv=none; d=google.com; s=arc-20160816; b=lKksWmNSFZSrWSNZlXiwW/KbEx6YjUURewa7QpTulqtQjdd0kbkiIMcWUFA3+P5lDD +wGfikhylXJC178qcgsjyd/YVcDCSL/zKqw/SnwG6tqw9rhm0Hv/Ex2Sl4/C684QCmsF qGv7EFRJM2yaXcINZ2LRRdRdfd44vtThTdKW5qQQMZkE13K5Pg3PK0s8FpDQF/iSsFbX Z3D/SmHC14a12NkMqOI9dqoBWyDCmXK1Sb0XII/77xBLqffHEO84j1vzxW9IHcGDM75X 5k59CmTtHmOTtquQRzl97T5l0DGVIP3wv0MxhcUFiVc5yj3vdwVJH5hg/N+6lkKw+74y p/hw== 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=G9GzaUgP2dUy5ipTj5VK+ngXMm66U7fmrSGtTqAoH/4=; b=Ehd2Uriq3PtHdArUq0/o0SEEbrMSlMEvzxlLsNos5jfHRcN0ssbWtQ+HwzTUogy6CA nXiMpdYNDVzO8LIpL238sh8+DDN9j2S1VC7uH+1NNhBE4jWgII1vD4yJ+Hk+dbJEsTQF 6qpGcQbHEQjIjcDBcrwttJBp6839eh5cuZxsLgNel2w1njfCpkh5ZSAezErRrCukIfPE nsVnJGktHDcZVAsNnV9QrdsJPcV1TSjD4fpyYEp8s9NkFJuWSddG4bdfv4W+ofDEBphi ae3Soqj63p91PnTYW+Z/xq6MV8f6hMvWcnMwArSmhcY8/tlPDRsU63uK5lPoV5MOqikC EGOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GAX2TZTC; 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 m11-20020a056402430b00b004520e27e5b9si1334720edc.626.2022.12.02.09.07.55; Fri, 02 Dec 2022 09:08:19 -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=GAX2TZTC; 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 S234303AbiLBRDY (ORCPT + 99 others); Fri, 2 Dec 2022 12:03:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233495AbiLBRDH (ORCPT ); Fri, 2 Dec 2022 12:03:07 -0500 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 929DF1CB2B for ; Fri, 2 Dec 2022 09:03:05 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id x2so7322917edd.2 for ; Fri, 02 Dec 2022 09:03:05 -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=G9GzaUgP2dUy5ipTj5VK+ngXMm66U7fmrSGtTqAoH/4=; b=GAX2TZTChMhZiFD67BGJI41r0AzDoMd9LC5vF2rPwKDFoNwZtXlfFEHYWeSEbE6eVM oF5Lz1Bb0EgXKkEaecppdgNypI5MnqXlF3L0dK8bCzyoHNe9zOWKozkiv8qdto8TU320 PooQegpgKL9nwicmnN78WE56DL5DQvL/280aI= 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=G9GzaUgP2dUy5ipTj5VK+ngXMm66U7fmrSGtTqAoH/4=; b=sIVTF1TeEsHhCT5f1dI0S0Ayn6CWtPXBW/1Qf7sgmf1sh0iWjS6iZ7MpY6OaqjsQ2g eFWNh1UAEqFcNyYPFqwO7aqlD1XHYF9lG80sCTGVTdtnBTI2vwLf8F/aCS+9hmE4ZPTx 5Z6NFNhHTbXxfTI8tFyqoFeXIsJlN9mqrZBzLnkIE+uQORp10z+axmMVpE4We0u1WOgX LNfaz9LFLmdPJ0maWhvxLmyqurkI+OIzaIfAB+aMrY7q/fjsrpmA3mpWP/W+2GnWGa92 RT0LYA+Wx2wbWUMsTtEx5URpJecHcyb61v4QC6LiJbHO0JMEXyIdYu5rxVdvHYNKfsbo B/Ag== X-Gm-Message-State: ANoB5pmk+iUgngZ+3XmxZyMxdSTfUqw0AVhld6E125rxRrTax1Z3YHzE 0TsrbfWURCN3RM1iBuL2E7TjuQ== X-Received: by 2002:aa7:c94a:0:b0:46b:74e1:872c with SMTP id h10-20020aa7c94a000000b0046b74e1872cmr17010867edt.301.1670000584034; Fri, 02 Dec 2022 09:03:04 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:03:03 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:02:45 +0100 Subject: [PATCH RESEND v2 5/8] media: uvcvideo: Quirk for autosuspend in Logi C910 MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-5-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: "hn.chen" , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5268; i=ribalda@chromium.org; h=from:subject:message-id; bh=vMpFMRWWnesB/JKaCX8FLzASNm4eeK6jiVYT2ygmW8I=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii+8Yo31bNYjZttsorhUadWt28paNSHCekzMBfO9 4MT7IFCJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovvAAKCRDRN9E+zzrEiMhTD/ 9M1V3Q8NhJzc0K7i6zH28Aead4zTfGgJS6iPzaMJOZwixbybTKy0p1NDW78eREp4Z3BTLh34iSugpL DsbnWZtuRPx7zQisCQ8f3pWpZfIAFDn/9f2TIS9GkqqzM0maNn6tH/xpsrcXY36TcM+wDf2z5BfecN IwmG6NhmjPx/HzR+jYE5Gm6f++dvtzUKP4SkFDsEk3BviuR+ZNqYviJqW/3ghoWpPGLCCbN/YCHyUH vBxR+BOU0tqf/dPGmeBKrYtrY21PAUhoOOMNmlFfBtdDmX5on0MHzwfSQx0vSPNBFoGAJI0n9K/Y8N wCE/oZnMGYz+4Xsk/gtBpkehQmvmJ8devs1V1RtpUN2mpAK2dwyjCI+1chU9lEkMFC7t+KIuAmYHi1 VyeMPzlZ1Ib3GmNkviwSQzs+EFNqHL7wPN0gqmfhrezON/Z0sE//13kGrZuLC5QM3fhNAUy3ppaEAr ZR4ExcwbQcs4mxVMGCfgpv6I674ZomWF2U7gfQaPhNusnUeAbkKz57hAKIw1JWazklIQbTkJdjLbSP YFi3tMBVSD65aR4U+QPjMjqTfcdA1bYCZIBOYCiFelXyh/QUF8cuNKVhOWeRquT3TiegfhnLfO431c ZyLp2XQsLjBMsGZYu+wDQzCpO6Rpw3xOm3XksqZceCKtUJKwyTJ6ED6Xov8w== 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?1751122862344735461?= X-GMAIL-MSGID: =?utf-8?q?1751122862344735461?= 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 --- drivers/media/usb/uvc/uvc_driver.c | 18 ++++++++++++++++++ drivers/media/usb/uvc/uvc_video.c | 5 +++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 24 insertions(+) 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 Fri Dec 2 17:02: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: 29018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972972wrr; Fri, 2 Dec 2022 09:08:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf73yXdvbKADqSdX/cRjWsvCb0a1G8ebSZdYNLdYaR3F2rf/L758dPn+3CWzCd6Zb1ArHQgq X-Received: by 2002:a05:6a00:4009:b0:563:2ada:30a3 with SMTP id by9-20020a056a00400900b005632ada30a3mr54400205pfb.27.1670000933051; Fri, 02 Dec 2022 09:08:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000933; cv=none; d=google.com; s=arc-20160816; b=lzlpwqOkr47B2IBLx/wiuohd5ITnHCdML6M5yREpEdPe9Jwv9BlbnkmvmyqA+EhWGL 4OtHdmbiXN3MAicZ+CRHuYzcBBy8ShcC2m8floSWBxJNKBvOFN9cPIQbtsZy3NNx2prd rsGxo1fA3jAb1Zxf+zZVhzX83C5txfAgJBRN+lBlQYVfoXoTVVdGVCiEYvDgXEB1nOvU TZz691wqzzHxs/z45ZxghzkQUdqaHIv6t3hNV5MvRFENX22ZBQ5c0iGXo9h45hxGY3AN 39oY97f7ab5rOwWQxobOs/UWbr64httVDSe+d/GlIyCoWlQI8rsxxfs7Hw5z3HD6mG9h KByQ== 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=HzFzDnnX9pi7g8WQvEiGHdhzPZgy4R7i/X22w+LEdMI=; b=qL2LySacRKNmyp/hC0xwuW3tJ59n3p4sPm1LC4PlqiuGqebn1cI94wHszKHhYepKE0 hVLRDPZl8NoMTyP3XJ5DteikwDCAUMh4yeN2Ti9VyygFbk5BTR4jNY60scLl9XiR89Ip xm6zmpPuIZHyQg142plRPvpXuk0HTyc8QGhshIzu+ZH8y+RE3U3Otqvih/AA5DfspdsH DmtU36HLLxs3eb76zrSQyIN3//aDMr0vR8FYgdF6XkSh/x1FqEvKUCr5Khsuxl/b0StN I2Mn86gTtdshEIi0bZ5GeDgQ35hbVCbWldxu3v/xN1OmeMa+1cT1McqexYpZ/phaq5zR FzgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZJW37MUF; 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 x136-20020a63318e000000b0044034f2c3b8si8251715pgx.310.2022.12.02.09.08.37; Fri, 02 Dec 2022 09:08:53 -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=ZJW37MUF; 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 S232011AbiLBRDc (ORCPT + 99 others); Fri, 2 Dec 2022 12:03:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234275AbiLBRDH (ORCPT ); Fri, 2 Dec 2022 12:03:07 -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 3E70FBC27 for ; Fri, 2 Dec 2022 09:03:06 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id s5so7225451edc.12 for ; Fri, 02 Dec 2022 09:03:06 -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=HzFzDnnX9pi7g8WQvEiGHdhzPZgy4R7i/X22w+LEdMI=; b=ZJW37MUF8AZ6gWULeaZCcqG6uUEz6GiDhcUhr3cuJ0TXqjmGQGQ/KaERArPSMmZYVQ v5NuRaE9CAuAEJk4+fiZAb3B1M/Uhb+ROQ6H7e+5zjdE42H2+rFoSmDtlIcorXvviC/o BoTkA6Z7SzYy+iuJ9UYXh4+8sw3+x7MODEjyU= 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=HzFzDnnX9pi7g8WQvEiGHdhzPZgy4R7i/X22w+LEdMI=; b=ZQJhCQ1jDOqAgdEbgNMfZ/CUcU0eiDqxHxnlxcDd/mgUkeOU7nMdmE2f6CRPB+ykFL 6n5v2IGVFC1kLhySkBiUAPSPDwmnBjoHzBBQiDM68ZECtmYpcRwdLjAxjT79eqIhpx4M amRen/YLV0khnMtrWx/MWq8Ja6Q1Gdmrnm8yy5VMGuRwtM2yHazudI37piAZgXR1SNeb 4mkqQyy0QivArgns2K+3E3MgamwIIis/Me1LXasvn5kmhR2vcd/WvOv3OHv49ujDxpAD 94lImm0xYiJPti6bzE5fjaFCzwXZ5tF7/MfEv7tBUe5nJtQc4gtgXCcH6+a+J4I5tyLi HC/A== X-Gm-Message-State: ANoB5pkgiOhI4MquQPf6O/iJCptzaMWhKAvaSPnSs+5ph5jACawuWK5o Db/uT4W6QAzIUvYX+vMH2Yjhfw== X-Received: by 2002:a05:6402:5405:b0:468:4cd4:f133 with SMTP id ev5-20020a056402540500b004684cd4f133mr50745505edb.18.1670000584730; Fri, 02 Dec 2022 09:03:04 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:03:04 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:02:46 +0100 Subject: [PATCH RESEND v2 6/8] media: uvcvideo: Allow hw clock updates with buffers not full MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-6-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: "hn.chen" , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1769; i=ribalda@chromium.org; h=from:subject:message-id; bh=3Fs3H+ze+0F22wwrtRMwFmFB8rGrRyFOzQuhxGsMqbQ=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii++aFV/k9m1GdsfCWkMCRxITd6LDxE6DJa5Uc8e mePmB3eJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovvgAKCRDRN9E+zzrEiGCRD/ 9rwsjQhtVhBi0S2pt0k3Ny+IWzN/fublTh3yfjMsIAlrEucBUf88I9uq7z7D9OGqfqOs9R54/imZnS IRo1BrgKSqPK12ZuHcEDh/f2LP69JM9q9F9SYw2RN2mG8zi8YwO/BT5OP2qSFgLZLHTikUSuWoHuaF wUFN60AKltKKp48MCA/KTTH+XH28nx91yVyWJ5QaN2UzNIhOoA1U270tXxAsgwjxiw+68DghRTXqJ6 84ericULGTZtwenLdIlkHcw6ggOSIhJLTJPsT+J9aqizin7S/Dizv4pM8JaOlrynZHl/AWqc4+TT1F nC9h3DocTnNLizd3/vj/+hLFGnszvcZZJFwdhSrlDfkCNUXPBExLBTHn4s819WDGori6goKfZsj/zW vf7euVAUB3AcojasWJCoipCGIsGpT8fXw/24ko2BrSp4da1c9dm5QYItjdWE+nu5fHS9qNQZzAEhBx +x9750sF/rm7sAPW7IZ/uxRmrmLfHOYbkkCT/eAPUWVqzfFO0Xc3md0yuR6twJ1qX0LAjPzk5TT8Z8 F+ClhgplynV1MT0IVTeW/sO747rJZY1rRlu7gJGtpIV5dCkaFemOnlAy/+mxu3cEpSsoCw4JqFxtRf PUp4TWs3VGwSKH9rEs/pIAQIoZh0AFj/T7fpozfVUWYI8JMKAF1MxqRmsw0g== 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?1751122898482295724?= X-GMAIL-MSGID: =?utf-8?q?1751122898482295724?= 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 Fri Dec 2 17:02: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: 29020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972984wrr; Fri, 2 Dec 2022 09:08:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf7XvQUS85NnvIeriINFVofXJwegn29BE31BUsEjh5UNAGb6ygWPqZgOYJUH93NQkwPjV1+J X-Received: by 2002:a17:90b:2801:b0:200:2069:7702 with SMTP id qb1-20020a17090b280100b0020020697702mr77819447pjb.239.1670000934666; Fri, 02 Dec 2022 09:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000934; cv=none; d=google.com; s=arc-20160816; b=F0iBvEFXBEApEHEinT6WWNlewFrfqukCvtRtfwMg5MGE1ZFG+C4KbSHjwEMU7Fg07o mZeITriUYz6fgncA4taEJLxOUQnoEjg7QgDX8agi36ybt1TZEL6Gkq6W+Ml0XHanzV0a SEZ4/bP34fHTe2x1Oo/FYg/j02uSNDJMvjEDBDovqPViS6lVyod80dUNM50GPRaWBzyA McZAlmDQigFXVp6crg+HSFCn9kdG0ujFDqPaD2amnzdR/9Md1tPfXR8UTBHfY8wg+dML x5SWXnLOOjsc/8kDUIDvL1cSC7VN7ifgQyPCi52AnCsDDgrzBSxVpdrwEuZOcTwvMYNE W6fQ== 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=8wywY3bthMlLRlkHC9RULQaRSbA1/GpUZvI3tR65/Ow=; b=ks55QJ9/vwKbUh+DDsD33eexW5rmhEZiciQLf5IbBab35CA61WdAeAvD8x67p+cica 6EsQof2OR95AQJ5+UIYpVofIjP9zUQZ51i+wkG/BVDflZ/WpGRSH1o1Ir4txPkvMJtXB 3/oCHw4ssZ4Mcn3a2dHYZcDeKZPIhZKs+ayuaCQkTzdtnLajRAbGQsh00XJG74cgRGoy 99WGStyUlt/e2cpuKIPz6dxZLuymA3ROSi+JFeahyrxKiN1P2Saqswfq1y6UsDhxJcDM 1A/oJrQWLfUIP1sHNRSiWVDBIjI9jZPoMfLbURKSamIGi9gzGCUg17iK2yO9wLhUz+16 Y3XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fGc5xZMZ; 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 t189-20020a6381c6000000b0047846337046si7726327pgd.419.2022.12.02.09.08.40; Fri, 02 Dec 2022 09:08:54 -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=fGc5xZMZ; 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 S234239AbiLBRDk (ORCPT + 99 others); Fri, 2 Dec 2022 12:03:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234277AbiLBRDI (ORCPT ); Fri, 2 Dec 2022 12:03:08 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C1AA2BB for ; Fri, 2 Dec 2022 09:03:07 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id s5so7225537edc.12 for ; Fri, 02 Dec 2022 09:03:07 -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=8wywY3bthMlLRlkHC9RULQaRSbA1/GpUZvI3tR65/Ow=; b=fGc5xZMZuZ9U3eYxsjF36mFnj/PiUoC1WIEOBs1Gk9j+6Hbc2t0oyaXY/UGivhzNWu 7RdBD378GNMXA2kiiUncq7jsriqmlSucrSU7zvcv5xAjkucWXmooyqMaYutlw2HWJE8E lI2kIwKEyb32ejCGXQdgPZf7ozlwEP80tOqIk= 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=8wywY3bthMlLRlkHC9RULQaRSbA1/GpUZvI3tR65/Ow=; b=Lp+72Idfah5I4GXs8i5KEHkjk4GxXLFQQ915T4+T6bWbsMIWfpveM7cO9gInKjk5Wm vi/a78iu1Mp5l7kLNlQnP50TXp+S3Tb9jpa6xS3IVRGbe6uD176jnVnqXBXYJkGqLs7Q zxKcSIexrp8j7CrZn2tXjYalP7VxghSCmKYF0FkNK4EwkYsaABGZ52/5wFvWIPdqM/0i oC/SIFuUJ+qM5H6lzS6ziHkxntiwRyDuAB1KD8OHt72Yz8QvDH1UIaOh+3KH4TEpgdxp 1SmIvIhZRJhZWyd05rwwJM9fo++CPwbi8Yvm7OoT74HCprumFJDXUf1PnRI/wwPLOHF2 pYaQ== X-Gm-Message-State: ANoB5pkxGpAYMvAjOVkagbkPgh5ILMbAPicEVP6rBCz4Fr6L7xvZop/A Th944VOgZepIgW+ClnhBrZs76g== X-Received: by 2002:a05:6402:88c:b0:46c:4566:8d55 with SMTP id e12-20020a056402088c00b0046c45668d55mr1788049edy.339.1670000585855; Fri, 02 Dec 2022 09:03:05 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:03:05 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:02:47 +0100 Subject: [PATCH RESEND v2 7/8] media: uvcvideo: Refactor clock circular buffer MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-7-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: "hn.chen" , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5903; i=ribalda@chromium.org; h=from:subject:message-id; bh=B8RQISI4QMVIRkK5ckK4GQ2MSod4BIfdLdMm4WjWZ+w=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii/A+6W5+VkrSSGmnhCsQh0Wjp4PZmGObAH1P3uV m5i1MJaJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovwAAKCRDRN9E+zzrEiLGTD/ wLZ0Lq9uFUdk0uaRjEuCtXiC0CCNaJ84lM6enLotZEC0BOr+z5t3TvOX/O/og07+JPFavX+nsYMULb MnMv6/sCusO3EyAS3+VB//A3adfW7dM+pkvjT756JWueep8QL/XIV7FhjCYG6jCWnUfpiMA0YhXuYW KfPzzfkxQbTApUAzr0Ug01b5YmebVJ0aeT6odSVEfKFOFTBGhe2OjsYKiRN3psKKZBCPlOFb9fAtbr R6YIzhQr5uO27iwkTq+qWRRzBaElsnHcG8G6Sd+YjmRoVYGXZ8SJvIyYnE1G5pX65/gsSagh8Rim2g ply81CeyakKkUcLif/e8JbjpxZMY6YA5bkC5x8zlpU5R2wsQ4MMe3+AYJ0Nmn1/UNVWYbOy0fhyP01 mXNmBpaBqBYCsBmezl+3sdR3TQhvvampwOY9WyzNKoQe9TN9WZgcf3Fc1+LFhbkmXQHqZ9Xvr7Scn3 0dSjOhRbH1V97GQjjCc+BSOrtrdbOJp97g7ymQAmloVX8AcrGR5NRERZ2W6BLQYJ7Cza/6dTov/cDd diuf5y7HkgALuucebmrO9aPaCy52UbIpOm67B96xClu5EBl49UlqEFOA27E4qAtNEjBi/z8iu93BSc Z5vG9YwmSZkC0ozNWEx2RSOhwr8+CJHZZRzJ6AU6uTGEG5QEOOzor2QgT6xA== 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?1751122900253965472?= X-GMAIL-MSGID: =?utf-8?q?1751122900253965472?= 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 --- 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 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 Fri Dec 2 17:02: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: 29021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972992wrr; Fri, 2 Dec 2022 09:08:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf50EkkO4fZymttMETAdGvgEXUc2CEdnWsqy2a02omqsMdkfi0/pgii+ztamY0UJANp33lIz X-Received: by 2002:a63:1763:0:b0:476:d5be:4511 with SMTP id 35-20020a631763000000b00476d5be4511mr38545611pgx.139.1670000935819; Fri, 02 Dec 2022 09:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000935; cv=none; d=google.com; s=arc-20160816; b=CRSjTvXZ9YOA3s8acWFMrdMkTsq96C8t0JEXr9cOBDhHrsVIuAW/1qRS4pstpGb5NS TqCf/An8Qs7hWIE95dCPxCmg2uXocOQ7OwJie8Qh6eOnNkSynihktXhU85mrq56ZTFqX NnJWSi7ROE0FqJpdKLs3fpuamJbAeiK0JwbOKRhzW1HTf6cDrYLMAzNVehrNf+Jx1afp VzzVZPwof1l0cbW4pSpIQqEk63sEEzcT+tpi5lh4UBOFjt6PtmuJp8n4VlT/USX/zcsa pg7tGpKzZrfREFjRa2qu6AZ9B7eN+Mdg34L3gdxEivr6z06PG/nFZFcM+HBxLEH1UMrH 1QBQ== 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=/Z0mke9x4z8GIO16lOl+BgRgkcVeUrWg/yLKPpvbpk0=; b=rNXIOuONMj0DTyibXqjhqKim5lL+rEH/HUkmu7+eKFbJCgKdQjELh+ZxFjbmwkTFRq 8qMYwYrifVgo6VSKQBdwXuAAqZqKiUDx/DNgdS5lSo7sdyMeRoa0VKeesV9lHmlggzVW fGJK94U5bT316Buok4GsuZB6tLmJo6GFPIkfx6EnUTXEub/MD6KLBAiBsWdc00tCHZpZ KwEdTjd8078F7KDAbB7oZXYQLwfiL68yv16pptKjLjFbm59QASVv4zhVscZdm3cNuWjP ButjpfSbys0DHWpI5CKoxodxpS0b2TrDb5D8kniMVRQ5ENNSmZYfUJaCS73XRkikFLKW J2Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KRuFz2z0; 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 iy3-20020a170903130300b001869ba21491si7262957plb.8.2022.12.02.09.08.41; Fri, 02 Dec 2022 09:08:55 -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=KRuFz2z0; 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 S234417AbiLBRDm (ORCPT + 99 others); Fri, 2 Dec 2022 12:03:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234281AbiLBRDJ (ORCPT ); Fri, 2 Dec 2022 12:03:09 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F434A80A2 for ; Fri, 2 Dec 2022 09:03:08 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id n20so13045685ejh.0 for ; Fri, 02 Dec 2022 09:03:08 -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=/Z0mke9x4z8GIO16lOl+BgRgkcVeUrWg/yLKPpvbpk0=; b=KRuFz2z0S00H+Jjqi+ULpUWR9oqEccGYNJsAXZkGZBhcf65dYLS+1T60tut2/084H9 yFv8Ka0pIlw9bYdvYfPfIwQnaIMHbWOkBl+Jq/ice6ApLUxFH2OyJayzcbyfsoSRShMP mPkqZWZDlmcJ9vI5y6DfbmeuD9vPMDD0NZ0Ss= 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=/Z0mke9x4z8GIO16lOl+BgRgkcVeUrWg/yLKPpvbpk0=; b=wzv6m4zasEUIIXVzl4aD3YafKY9fXjYF0nXT7QCkUxIGK961Y1TVEdOAuvvWvWO27F 6uGwpOZAf+OoMxKQRjtGZXICYzTR0/7ZCEx8p+W4bfwFQTqaK3vsoudiCLfQNnXhzAUi fEZqK/1TODeKZAFBlDUh1JO1suaXAUtE5wWBGRhxcmjQYybRTSCzR95fbHNRZ+sN5QNJ mdosbbVrmsU3z8H4mrzPovoQOzYoierYyPkg9u84SW4wN2ipDrFs89K0e2TrmQZK5vH+ 7AWlTo6aaRg57X4TtEa7/ZdkJ4PJ7w1d/ZsaTdnLjBArMj7oTT3LdVFEWgIs3mq0+YfF xg1g== X-Gm-Message-State: ANoB5pms+fs8ruHBkfSfSoMNvYIwRjUc2AR00fYBoHDtImUBmRU5gmkK X08esyMmQTthBRS7+PJ6qGa12w== X-Received: by 2002:a17:906:706:b0:7ac:2e16:eb05 with SMTP id y6-20020a170906070600b007ac2e16eb05mr63176435ejb.26.1670000586670; Fri, 02 Dec 2022 09:03:06 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:03:06 -0800 (PST) From: Ricardo Ribalda Date: Fri, 02 Dec 2022 18:02:48 +0100 Subject: [PATCH RESEND v2 8/8] media: uvcvideo: Fix hw timestampt handling for slow FPS MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v2-8-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab , Laurent Pinchart Cc: "hn.chen" , linux-media@vger.kernel.org, Ricardo Ribalda , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2142; i=ribalda@chromium.org; h=from:subject:message-id; bh=ZqBE4dWRk0InSyAxEr/auCSM1bp+38IChW6qVFv0hng=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii/Bd0vLNfrMM135jh9PhB+8ydixKJHN5VNmGQ1w 6MdQC8WJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovwQAKCRDRN9E+zzrEiGdGD/ 9DoAVTWVQznsEgzOwpYpRyWMCIQBxtwlwKzaq1BnTIWye0goRJf5CjrA9bRJu+Z6+rx/+lp/RTMufc MVg5aMuukcsBzqLmyag5x0oDtpufG/8q8n2V/I+eejUQIFhJ/WgRBeRArQaT9Ib0AKH9ZXcZt/uMTa yGrm+vuxIPwgV1SuSPB5rIxtxwyUAfiq7qlxJArP79mrahtKd78OmPqqKX5q0h64kJzurNStsVKwbw qigdhxx3mcd8ABG20FwkR2+uV72DJqtQxmTcFtiNkThYx9dAVGxnF+hi70ALb9Dt0KpiB+eXme+mzQ xpLSqnfBKJ0kUOikWg+horEpNYRqVMGp5DWgZ6Z0FDz6JfeDzu5/MbrQwUfr8MocQajT2SS5/+S7OI PHexHL/gL++hSerdMcUMIX0G3RxG+sAJHjcA6G97N0Qinm/yb6WuYKEDAp/PtldnBNrbFCe9aCEIbJ UmRo+SfzDzWrRpf1gxmME/bl68ZyQzBIiZMhajxdBi7VazfWPFNfmNcOKR/94iaIn/S1wmMpFCZUZK TG3CY6KD/rbVr64gJDE/XQMagdmzJFdtwG2F0SGjMp621qyhW6nIA3ZFpAhJreZkPAdoKlHaet+tAm XP6RlzuWoO5Ab/c4qButbsLioCEdGQd1KqvgIlt3Z0r9bJEbSeajw8QWfEmg== 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?1751122901119602740?= X-GMAIL-MSGID: =?utf-8?q?1751122901119602740?= 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 --- 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 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;