From patchwork Fri Nov 22 08:41:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13882880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1FE3E65D2F for ; Fri, 22 Nov 2024 08:44:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=su6tsEJry4BzuFP65MpXpBH51+aHQ+dE9vL6DxTxUwA=; b=LcamiLuNFX5pOaHcsXYAwM9BJg MexF04sKbhIXcGIHl1+Mq/K0F2uvzOKeDRTvVnelWHEfyZxnYn/Zbsy1/Q2yPz+WpXnvRC/Gy7Q8A RKAa7BngFVrRfLcjD1C7zRlh7mAwWrdNLcjJVh+puNK+J80DM9AQwwyUEa7GwfEuU0y5uvlfTCF2k Z8iBq7NX44raCptdRMaZwR4bmUd/WVPMXlavC5GzscYhToLk5c8/BcbY4OH1npadcDwPtUg0MZ4iS c1/QrnfARr2ij0xGFiIVbKr86lEQ/UhtzBIhNul2nbmnWSQVox7URWXspe+SGdLWLNca0BKwMoh/F jFk+ROZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tEPHJ-00000001xje-0Tse; Fri, 22 Nov 2024 08:44:37 +0000 Received: from mail-wm1-x363.google.com ([2a00:1450:4864:20::363]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tEPEr-00000001x3C-3rPr for linux-arm-kernel@lists.infradead.org; Fri, 22 Nov 2024 08:42:07 +0000 Received: by mail-wm1-x363.google.com with SMTP id 5b1f17b1804b1-432d9b8558aso16847445e9.0 for ; Fri, 22 Nov 2024 00:42:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732264924; x=1732869724; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=su6tsEJry4BzuFP65MpXpBH51+aHQ+dE9vL6DxTxUwA=; b=n4y68So96k0ZaWAee7kk+tDgGrqbxRoeFGpd0T5NRYWFlDLcxcMo1ezsuJlly66zN3 8OrGa0WzfNN/Dc3NWE6PM/khH4cjZpxtLsyzxtJIPc/8aF/x1nu6PXI3lzyTmcL7qTx8 dGgrxh2IM21Deefpbb7XVToWWf6rVn43Pmymwpzw2CLC0r1/i82iLi/Y38Ue2CmrnMGd SQVvuq6eEOscNir6eXa1wmOK2N0IVM8z5RAvNytZsoDFic2AxyIDUobomUCD1NQpo7Ot amK4pKRGCbZNq8gDS+OtOrc7LXz8m7aEYs7ipz3iMXQpx+Py6JwAlCwxzIKt0JWte7Dw 0SCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732264924; x=1732869724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=su6tsEJry4BzuFP65MpXpBH51+aHQ+dE9vL6DxTxUwA=; b=V815XljsTOC2/GnaeCzzkbySZil6OtywShyGjci+yc8/TdKdhy7m4qRg4fubP8p878 MNyT/BKmv8jT0Swia/oJFCheCZuzpDyf2zVehLG2yhzPP/zhsS+cfwIei8azuanO4VPp 6/FffiKruqJ1APjdLo1k7zUljADqNWuPh/j7J2v+rlM/WkD41SiDrPggql1eUgn+pp09 8tiOV/qSi5wOEpiUQOD62RkOz8KsrtMg9dnOlvGubRTmsZDxcmCYCRI52M5vRldShxR+ qQ9KU3PqNI/owcPB4u8/nlLRPtbcF/iF5hhEsA4TXpdEpljNFkN8XqeUPgAGMrBzEC56 cBIQ== X-Forwarded-Encrypted: i=1; AJvYcCWaqyU/kRCGiema4IGD0Hjo3Q8bezwkUhvsEoBk0MWcbZChOSSoG7ERPqj+jrQV+g3jvsHHIQcpvXJ3BchSi8Gf@lists.infradead.org X-Gm-Message-State: AOJu0Yzp3/cHmP4clc8EPTUAnx/apSaB1wkuvuqJ4rJUlWKpVBtvmB1W HK5kSEUyoozHAfAUIMD5iPcxk1qr0Acc8KVVxdZq3kXS9G1awAahzdJYEppeo9ggdChbgio6rUZ Ndh/nYw232ACBerB2RS1K4kKqL6hoAbUF X-Gm-Gg: ASbGncv7kRpOVEiQXr+469No51Yg8/5sxzZ99u8AemZAgZjzd+z4dRvkc+3TOy4u7Y8 /7BA5B+PPLr88P/v0O5+4foPB/hug/jy/cu2J+sw5LFSdkXGngX3D58vKcvHvZS8p1DbtfnR9fQ Kjc+g30ffV70zKh9GdDMkJLpajBhD0lY0gB7SaBFlbhYrAg2XVQmbqnWZubIzCVW7NAve3ocFq1 B6Mk79zHnmMudIj1uS/35qJNonA2XuwkzTOzLZnyo94IFGdLwswMP4LN3nir7+reg== X-Google-Smtp-Source: AGHT+IHzC1eCRwXGViTOOLSFM/PDCwUqY6DKBuYcoiYSQl4qaaz1QaEXL2O6o2F/GfgoK5RmaU1tu7qT3rGx X-Received: by 2002:a05:600c:5105:b0:431:15f1:421d with SMTP id 5b1f17b1804b1-433c5ceeb38mr52428355e9.16.1732264924132; Fri, 22 Nov 2024 00:42:04 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id 5b1f17b1804b1-433b45c428asm4064825e9.23.2024.11.22.00.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 00:42:04 -0800 (PST) X-Relaying-Domain: raspberrypi.com From: Naushir Patuck To: Raspberry Pi Kernel Maintenance , Mauro Carvalho Chehab , Florian Fainelli , Broadcom internal kernel review list , Ray Jui , Scott Branden Cc: linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, jacopo.mondi@ideasonboard.com, Dave Stevenson , Naushir Patuck Subject: [PATCH v1 1/5] drivers: media: bcm2835-unicam: Improve frame sequence count handling Date: Fri, 22 Nov 2024 08:41:48 +0000 Message-Id: <20241122084152.1841419-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241122084152.1841419-1-naush@raspberrypi.com> References: <20241122084152.1841419-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241122_004205_981962_660BDC52 X-CRM114-Status: GOOD ( 18.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Ensure that the frame sequence counter is incremented only if a previous frame start interrupt has occurred, or a frame start + frame end has occurred simultaneously. This corresponds the sequence number with the actual number of frames produced by the sensor, not the number of frame buffers dequeued back to userland. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- .../media/platform/broadcom/bcm2835-unicam.c | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/broadcom/bcm2835-unicam.c b/drivers/media/platform/broadcom/bcm2835-unicam.c index 3aed0e493c81..36fb186a0421 100644 --- a/drivers/media/platform/broadcom/bcm2835-unicam.c +++ b/drivers/media/platform/broadcom/bcm2835-unicam.c @@ -199,6 +199,7 @@ struct unicam_device { /* subdevice async notifier */ struct v4l2_async_notifier notifier; unsigned int sequence; + bool frame_started; /* Sensor node */ struct { @@ -742,6 +743,8 @@ static irqreturn_t unicam_isr(int irq, void *dev) * buffer forever. */ if (fe) { + bool inc_seq = unicam->frame_started; + /* * Ensure we have swapped buffers already as we can't * stop the peripheral. If no buffer is available, use a @@ -761,11 +764,24 @@ static irqreturn_t unicam_isr(int irq, void *dev) * + FS + LS). In this case, we cannot signal the buffer * as complete, as the HW will reuse that buffer. */ - if (node->cur_frm && node->cur_frm != node->next_frm) + if (node->cur_frm && node->cur_frm != node->next_frm) { unicam_process_buffer_complete(node, sequence); + inc_seq = true; + } node->cur_frm = node->next_frm; } - unicam->sequence++; + + /* + * Increment the sequence number conditionally on either a FS + * having already occurred, or in the FE + FS condition as + * caught in the FE handler above. This ensures the sequence + * number corresponds to the frames generated by the sensor, not + * the frames dequeued to userland. + */ + if (inc_seq) { + unicam->sequence++; + unicam->frame_started = false; + } } if (ista & UNICAM_FSI) { @@ -795,6 +811,7 @@ static irqreturn_t unicam_isr(int irq, void *dev) } unicam_queue_event_sof(unicam); + unicam->frame_started = true; } /* @@ -1413,6 +1430,7 @@ static int unicam_sd_enable_streams(struct v4l2_subdev *sd, if (unicam->pipe.nodes & BIT(UNICAM_METADATA_NODE)) unicam_start_metadata(unicam); + unicam->frame_started = false; unicam_start_rx(unicam, state); } From patchwork Fri Nov 22 08:41:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13882881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D707E65D34 for ; Fri, 22 Nov 2024 08:45:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8nGyAp1GyhYl2oD3HxN0dzLUQsgdlrr/vXHVyJmj6nM=; b=G8Xo5cCSfzgzkVcMqR9RsTj4Ag Ta5Vvak5mXZfzGy8cMj8VJ+3hJ2IdWixF88TiFW75Z9f+dB02ZsqkAhbErWqEYpwU3rILZe+t/62G KOVi/LfnwYfK2GhKLM4JM19g6gKGU2JxdhWaG3zptGKRfouwCxOtDErZhK1XP2ndx8lOXlmzzo2dL rOjQKkOiFCis1ST/dxMLUrKRsCZ+Czy/z5Tl2CgQz5WkGKXuZ3GvpPQXsGpuW9KNvgZuPGU90GMYj FOTgNdMCsYk0VJB/1aCJe9oVTMiTFRMwR8Il0ylMj42kSh9GHdy4Pg4sduQpQByZIePsCfwijM9b6 v3LEqGmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tEPIM-00000001xv7-2nnj; Fri, 22 Nov 2024 08:45:42 +0000 Received: from mail-wm1-x362.google.com ([2a00:1450:4864:20::362]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tEPEs-00000001x3E-1jBe for linux-arm-kernel@lists.infradead.org; Fri, 22 Nov 2024 08:42:08 +0000 Received: by mail-wm1-x362.google.com with SMTP id 5b1f17b1804b1-4314b316495so15824355e9.2 for ; Fri, 22 Nov 2024 00:42:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732264925; x=1732869725; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8nGyAp1GyhYl2oD3HxN0dzLUQsgdlrr/vXHVyJmj6nM=; b=khj8jb8I6LrwXjWABtAxm7IEBGaVbLToJoPicW3uBkAoTwqMEZHb+n66dsZeVkUydT THunQDgrzhgjZgAsr4pQSXI61JlKcubO/jAptv8v10MXVbI4b23ZxyR931px6Np63SK4 87oQdPApjHN/IbcNsLiR1qZqXfqz5Pw0OTC0MOZ867IN+caBciNfUA4qEa8OSmnWyCE5 wlaP3J0YNrbt/OdmtNTzxuQK63gzqzsZhUpBbYGhNurkGxd1tbKEgqeI3yTdZ3bGyMAi mqS/zNVsOrQrOgJ2Yinc7CYF2ia1+mqdZGMx+J93jD+/CtmadrEiFJy82NvCCqsuNiW7 iUfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732264925; x=1732869725; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8nGyAp1GyhYl2oD3HxN0dzLUQsgdlrr/vXHVyJmj6nM=; b=IcA4Io9Kb7xlZbdI4i0KHBTjXqgKl050ek1mD4zTWRCn3byL8x/8P++Ngu+TNcRRbX czu/XsnYxHwlx2f9ouoKsI8tLvdh2V7nLs4uo7wpnKSwD3h0gGUKMmX0mnyAuXOuYgzN q6q25IJ2aVEPSGLMAL5GsK3X9TkSZzexmQaQh8LEdEG4WkKy5E34MJdJ09YDOzpqvRA3 nQHZteKgpixzvm41sB3ktsMtGfrYbsqlXUcHLeWh4hk57oAEmEHRfk0aRWR87ukBR9QN aFNw9ci/QfHn5kZ45GzPSKJ7oaVwKLPqx5ZXA8IUAOyvU5Q/66uQ75W1HoyTqiVDQiCZ vAtw== X-Forwarded-Encrypted: i=1; AJvYcCVLX1n8EpXmBcAMnvtvfkksnSZmhxgm0PeXj9YlvmsTlVMjfVPW7iy4JRn7/YAurtfUnNnUEsXVzFJ7E17mzt1N@lists.infradead.org X-Gm-Message-State: AOJu0Yxfb31Qr42/Ge5L0M4Siw+wbZDT0X71RhERLRH3/CDvIEFHCGTI jmO2xUSeHLU7dPS+gc7XNHDjMUfkfuo9eR8MHo1jixumAilSIC+wTmdDG8fXlnrut/IisHtZ43u CiOOrHz8GVe7QkIzv4c/Rf8q42y2CQqU7 X-Gm-Gg: ASbGncvmqylFp595q20lzi4AgwuaHiH30sYeeoyeNmZus26o8/R5GJu9yVZ6c9T+zhb KwOR+qz84aVSHdWXhznK11QkDVG3xVEZRoZlBWeJPUKCNGZSHifmjfXJhFqihCpTznSG8z0zvmz 2ODfO1Y8nByNbYIi+zxJ2Y+LeS2J+T1i1HNdOAgBme10l6nJoXmtS59pL/BYk55NCrTrN8HZrKN VQ3JraiY3JDr9b6xY8jmUVd1fcSMuamnxo5O0o+ZW4hxVYnPmUHbADZ5OK08L4/uA== X-Google-Smtp-Source: AGHT+IGBo4ecTR47OQ69Kg2GI81fRJ/qHdvasgczFr52mJYtJ+jTJ0+xjnYcKX+CiPOYOl/EB0d0tWUhUZ4W X-Received: by 2002:a05:600c:1c09:b0:42c:bd4d:e8ba with SMTP id 5b1f17b1804b1-433ce4248f6mr14397525e9.8.1732264924627; Fri, 22 Nov 2024 00:42:04 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id 5b1f17b1804b1-433b45d1d3fsm3770515e9.25.2024.11.22.00.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 00:42:04 -0800 (PST) X-Relaying-Domain: raspberrypi.com From: Naushir Patuck To: Raspberry Pi Kernel Maintenance , Mauro Carvalho Chehab , Florian Fainelli , Broadcom internal kernel review list , Ray Jui , Scott Branden Cc: linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, jacopo.mondi@ideasonboard.com, Dave Stevenson , Naushir Patuck Subject: [PATCH v1 2/5] drivers: media: bcm2835-unicam: Allow setting of unpacked formats Date: Fri, 22 Nov 2024 08:41:49 +0000 Message-Id: <20241122084152.1841419-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241122084152.1841419-1-naush@raspberrypi.com> References: <20241122084152.1841419-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241122_004206_444207_088BAA9F X-CRM114-Status: GOOD ( 11.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When matching formats via try_fmt/set_fmt ioctls, test for the unpacked formats as well as packed formats. This allows userland clients setup unpacking to 16-bits from the 10/12/14-packed CSI2 formats. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- drivers/media/platform/broadcom/bcm2835-unicam.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/broadcom/bcm2835-unicam.c b/drivers/media/platform/broadcom/bcm2835-unicam.c index 36fb186a0421..d573d4d89881 100644 --- a/drivers/media/platform/broadcom/bcm2835-unicam.c +++ b/drivers/media/platform/broadcom/bcm2835-unicam.c @@ -547,7 +547,8 @@ unicam_find_format_by_fourcc(u32 fourcc, u32 pad) } for (i = 0; i < num_formats; ++i) { - if (formats[i].fourcc == fourcc) + if (formats[i].fourcc == fourcc || + formats[i].unpacked_fourcc == fourcc) return &formats[i]; } From patchwork Fri Nov 22 08:41:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13882882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 26278E65D2F for ; Fri, 22 Nov 2024 08:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nxccnoYuwLE+PxJ9V2hHsdBypkFSFevlZOlX7TLkWt4=; b=Vw4TM0o4QbTv7tdnTQQHpZ68b1 U2S/da2YVs7VJwQbsy9QqAqXWZRP0ZWAQ6nvPrgd1CMvmV2w/NxKIs5/WgHkbh8wfj91vR4DhYHwS CNoOTRFdsX32gBs0P5TirIbjnrOLoxj+iX4q0qMwZYII7yTQTVH5WgSYgEIlq83FITlH4jkJo1aCT JsZMNLG8Lz72FCvFa/7U5hWqG0xRKGLmJRBpk9x+M4mP9EIoYyZMa7AtH1PdYcEga6su1McYMxMtV e+mIJXqAKf0AGaBv+65TF49ufbUPDdVklrTGBPGdW+ZBVmCNAEsqn81y9AUin8WkOmbdXhUkfGlk1 SKboxVKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tEPJI-00000001y86-0pFo; Fri, 22 Nov 2024 08:46:40 +0000 Received: from mail-lf1-x161.google.com ([2a00:1450:4864:20::161]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tEPEt-00000001x3p-0qiN for linux-arm-kernel@lists.infradead.org; Fri, 22 Nov 2024 08:42:09 +0000 Received: by mail-lf1-x161.google.com with SMTP id 2adb3069b0e04-53da3545908so2125541e87.1 for ; Fri, 22 Nov 2024 00:42:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732264925; x=1732869725; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nxccnoYuwLE+PxJ9V2hHsdBypkFSFevlZOlX7TLkWt4=; b=ULwt8eMZL74/Lko62Ye+qpuLZVCGfduc09SmOeC24iG80oud6Nzi8iYqEkbn+jfjug 5SVfYFjNABk0mSnBQg6hCkxF9tKhXankxhufEqMUHtajQ8VUYB2LGNzuZUf3uUGxJLNG elrBHdTV28Ha3mIy3+Tq0Scl+VATWPdrxZKI2Aazr7pMQxxRl3HWaSHvL06vIelQ7LqY hZMGsoh5hf/PCdGyuStvdUNzKCxG++vhoJSBHkGCGaeMgfxLX1O0sPE6pTEsyJKHxzJ0 BeY9geXyqBpiueVR1cokizjXCfR8IwRjy3jNIeGR03nQGE7lByd+gM9JVc176DsehvDK ihyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732264925; x=1732869725; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nxccnoYuwLE+PxJ9V2hHsdBypkFSFevlZOlX7TLkWt4=; b=MJK3WgcTdFD2sjOmsv1pX3MR4Lthjsl5PX4LLqZRf4AQtkq1VJAekR7TdwuLvGilzo YZEfV3gI1ul2TTDmXwak/Kyf0BVZQQYE/P/6o6yNVYPdS1ZTkYikvaPWt/dACvZWd/pS eguHKsU5Obgurb3E6VZSerwPaQK/acq/R4vpbjsryWfoeTsB65CtqcHTAfLoYYKeQ9vO +L88/L6QgZ25Y2u3sB1qnoj9Pe7BDR+7DJEH3tztcVaTBbPut0uPBbPF4+SYA4wSRJHP PxszgvKeUWqXWRBd7ipMrTxL6R3uBvAXzZE1TbszOjYdvkzovonXnktKwO5y4ZGRgRZ4 qdGg== X-Forwarded-Encrypted: i=1; AJvYcCUwGJFFC8dTXro4VLnPQWfUXisLBpFEnsFCIICwhv1/a7ZdCqGvEgJ1rxmY8fZ3Bv71ZYxlZWrixraF9nSnqoTu@lists.infradead.org X-Gm-Message-State: AOJu0Yx/VkpUZeqPWb5Cys5TAQSGNHHgSdSBphc98ACEbpLFo0rmhQ0T /c6BJ943rKQAt2z15hDl/LHzE2TLjb712CP2aD7OpRtVv3teGcLPzd8tShGah5h/nXDGG2f6HR7 kPhr0CmFAk08Y9ZCA8ypocKBENyCWQxye X-Gm-Gg: ASbGncsOHcIp50yBFIgQgVv4zisVHDvqnD1sGNVZlSxld3kI7rsBOUDaxuNVO49BhCG +3sT841eoel3JC89whWny5wJjflnfWWh6JOrwhIXDScmeA5M8z0pJAHn+EnI/BIUy98YrJqsGul j8Dc7i6//MtVTV0OVmM4A33OSehclQ8Hg4HW8EaobPf2zgV7psdpF1T5rDDIGqvzdkXdyaDpxSV klazMBMb/Rt3ABv+Sln5jAV8PEJc/iYibg/PrVaRlOoDFJoVlIjEfk5xU7EJ2AElg== X-Google-Smtp-Source: AGHT+IHwAlWOag/sSwnY+xt8RVwblyGZ6BChTdlH0nZynOM3MgSiC7yPR98H0nrko8vSm39gGYDDmHy7pXJn X-Received: by 2002:a05:6512:b9a:b0:533:43e2:6ac4 with SMTP id 2adb3069b0e04-53dd3aaff94mr774659e87.49.1732264925192; Fri, 22 Nov 2024 00:42:05 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id 5b1f17b1804b1-433b45acd1csm3682485e9.17.2024.11.22.00.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 00:42:05 -0800 (PST) X-Relaying-Domain: raspberrypi.com From: Naushir Patuck To: Raspberry Pi Kernel Maintenance , Mauro Carvalho Chehab , Florian Fainelli , Broadcom internal kernel review list , Ray Jui , Scott Branden Cc: linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, jacopo.mondi@ideasonboard.com, Dave Stevenson , Naushir Patuck Subject: [PATCH v1 3/5] drivers: media: bcm2835-unicam: Disable trigger mode operation Date: Fri, 22 Nov 2024 08:41:50 +0000 Message-Id: <20241122084152.1841419-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241122084152.1841419-1-naush@raspberrypi.com> References: <20241122084152.1841419-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241122_004207_524092_E7FAB3C5 X-CRM114-Status: GOOD ( 12.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The imx219/imx708 sensors frequently generate a single corrupt frame (image or embedded data) when the sensor first starts. This can either be a missing line, or invalid samples within the line. This only occurrs using the upstream Unicam kernel driver. Disabling trigger mode elimiates this corruption. Since trigger mode is a legacy feature copied from the firmware driver and not expected to be needed, remove it. Tested on the Raspberry Pi cameras and shows no ill effects. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- drivers/media/platform/broadcom/bcm2835-unicam.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/media/platform/broadcom/bcm2835-unicam.c b/drivers/media/platform/broadcom/bcm2835-unicam.c index d573d4d89881..550eb1b064f1 100644 --- a/drivers/media/platform/broadcom/bcm2835-unicam.c +++ b/drivers/media/platform/broadcom/bcm2835-unicam.c @@ -834,11 +834,6 @@ static irqreturn_t unicam_isr(int irq, void *dev) } } - if (unicam_reg_read(unicam, UNICAM_ICTL) & UNICAM_FCM) { - /* Switch out of trigger mode if selected */ - unicam_reg_write_field(unicam, UNICAM_ICTL, 1, UNICAM_TFC); - unicam_reg_write_field(unicam, UNICAM_ICTL, 0, UNICAM_FCM); - } return IRQ_HANDLED; } @@ -1002,8 +997,7 @@ static void unicam_start_rx(struct unicam_device *unicam, unicam_reg_write_field(unicam, UNICAM_ANA, 0, UNICAM_DDL); - /* Always start in trigger frame capture mode (UNICAM_FCM set) */ - val = UNICAM_FSIE | UNICAM_FEIE | UNICAM_FCM | UNICAM_IBOB; + val = UNICAM_FSIE | UNICAM_FEIE | UNICAM_IBOB; line_int_freq = max(fmt->height >> 2, 128); unicam_set_field(&val, line_int_freq, UNICAM_LCIE_MASK); unicam_reg_write(unicam, UNICAM_ICTL, val); From patchwork Fri Nov 22 08:41:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13882883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DBCBEE65D2F for ; Fri, 22 Nov 2024 08:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=A3SPKEgnk0/CKlGg8ZlQK9CMOXwXblPgVAtkOWHzh5A=; b=flSGOW+EfT7XKZkxS7eOjlmvCC 4ngBktXXjhxU/5JgeK6qjizalFlyridHDnthBuH/FjEX/CB0Pf4u+ImhceisLZLUlKCxEJH96RrUU mV4LVbmNGOQVaEMYOKmzxE99Qb7o5l7J58KVaZNbiQUBeGPL3yw9R3feUQw5C8L30WZ8c7aX46UFC WCrBPtaMZ8ErRrsxfjyZHQBbWME6Q1Ugp8HPsulO+uQQ1zfYte/vlP0VFeGwP8HILoqQ0ms/durxX 8U73NL2sRrzmpgF0l483RwcLsg6vPNj9SVkdpRqWZYm/Gv6ARuH1MBluS71KpuXSGOFw6HDZ7xwCL 3SevdYFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tEPKD-00000001yLy-1829; Fri, 22 Nov 2024 08:47:37 +0000 Received: from mail-wr1-x462.google.com ([2a00:1450:4864:20::462]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tEPEt-00000001x4N-1usJ for linux-arm-kernel@lists.infradead.org; Fri, 22 Nov 2024 08:42:10 +0000 Received: by mail-wr1-x462.google.com with SMTP id ffacd0b85a97d-3824446d2bcso1579209f8f.2 for ; Fri, 22 Nov 2024 00:42:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732264926; x=1732869726; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A3SPKEgnk0/CKlGg8ZlQK9CMOXwXblPgVAtkOWHzh5A=; b=qK3SnXtEBkeJ4necz+v+QPW5ftOIoYtwGBq6UEeXIgl07z90sYFdvZL3YJNGwz7u/g D7SHOH9iEQOgYLWduX5V4YYwxgBzBfv92a1aFZPj1/zYxPbqVjeOct1Hkxbju7EaTj0F FwEl/f8KnE6Rz9D3afQnUdit9GdKXVQXGaYTo0SYn48XdlKI5sn6BeKUqgtlVPsD4Pvv MvslzdN/HNOnhFMc3MGFpq8GScA/MYinKBUfj+Hxt6whdBQx7JcFuRSxmNp5WV5iyvzb VE25W5TZlx2XGL9eCIRgALR+udu9nJ8oELbEtM7qnfW4d1TbC3AoliAfR+eMFNlSahtG Z7hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732264926; x=1732869726; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A3SPKEgnk0/CKlGg8ZlQK9CMOXwXblPgVAtkOWHzh5A=; b=ZGFij1HyWSPEEsny2vhx7svzD2BIJ6SyAqCVnHMLDtv0tsWWDwT0thaIRGZacQk004 XBft4uOm6SRaRTjorImuPWv/1/OEoda4aZwPg/guhjuqKeGYo3yhTfjW6xIT07SLf4tc 2SxZPA5mV0K72N+SkJ0Oh3JGqby26vCFGPVWWYQV5yThPpuGGxVDbMRcvEgKaMer1ckS mboXw5khkmrw0295DNgP2dxPzD6hStnMMf3bI/MYT3h8fYkYCpaHqQwlWDK72fFBDtdI 8pqN0AHRdLrQDAMKShA46P7Hs5N1YfE4GZ2JCagpxT5eagK9QraFkJCDydkYG8h4mEMI /pBw== X-Forwarded-Encrypted: i=1; AJvYcCUJKhPvmjGf5D7RF/DKc/v+tn/E2ys+WFe6QDOE4oYT81nRwDo3YiEXw0xfJ5euuXFwK9zzPS0AbVhDrspqn+5g@lists.infradead.org X-Gm-Message-State: AOJu0YyspTUNSVwNWZLdcpTFSIWEuJ46O48/DpFhd9PxO+Z92I1uIlXe W2EXGRO6dIarLwCkHNjwV0q8T/asGVxPsBQ7SB2YXzgPEUtl/M+IH6DDzO3ywu1bPG4fmKg99bj xlB1hVXEpxjDfeohxvXj3i1yz7F9qv/u3 X-Gm-Gg: ASbGncvP9effA9+y7rpsGR7wRmi58oRogIyl5f/a4WRj50a2u4v9iku8sv8soDeqo3s PuvLPPZesGx1STGrfgiv199XpfjkUuw/RmFXjoDDkW10PPlYiPmrP8cuQTe/6mU11kDrseYFvBH CgrJtd/QVBA0Ech0UVIgNBarjMcw99AMb2ARxBcWeU/Cwg4pUQ9wUXTxm8Wy0VZoo5jTPqnEI36 EsmA9rmH4KuKwb1M56Qs4ACmbBN66/0VlZ3zaLmsA0h0r3h81b8I6ycHPHwfLZOrg== X-Google-Smtp-Source: AGHT+IHmji/NlhW6PAvhLcBhuxCxYDetKytLXU6htY+yIaqQpm+gV+XdE8J9vax0xtcHo5/qC5bhqV9GxA4x X-Received: by 2002:a05:6000:4189:b0:382:40ad:44b2 with SMTP id ffacd0b85a97d-38260b8b4a4mr1324154f8f.34.1732264925767; Fri, 22 Nov 2024 00:42:05 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id 5b1f17b1804b1-433cde98a88sm1124745e9.36.2024.11.22.00.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 00:42:05 -0800 (PST) X-Relaying-Domain: raspberrypi.com From: Naushir Patuck To: Raspberry Pi Kernel Maintenance , Mauro Carvalho Chehab , Florian Fainelli , Broadcom internal kernel review list , Ray Jui , Scott Branden Cc: linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, jacopo.mondi@ideasonboard.com, Dave Stevenson , Naushir Patuck Subject: [PATCH v1 4/5] drivers: media: bcm2835-unicam: Fix for possible dummy buffer overrun Date: Fri, 22 Nov 2024 08:41:51 +0000 Message-Id: <20241122084152.1841419-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241122084152.1841419-1-naush@raspberrypi.com> References: <20241122084152.1841419-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241122_004207_566184_B08B74D2 X-CRM114-Status: GOOD ( 14.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The Unicam hardware has been observed to cause a buffer overrun when using the dummy buffer as a circular buffer. The conditions that cause the overrun are not fully known, but it seems to occur when the memory bus is heavily loaded. To avoid the overrun, program the hardware with a buffer size of 0 when using the dummy buffer. This will cause overrun into the allocated dummy buffer, but avoid out of bounds writes. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- drivers/media/platform/broadcom/bcm2835-unicam.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/broadcom/bcm2835-unicam.c b/drivers/media/platform/broadcom/bcm2835-unicam.c index 550eb1b064f1..f10064107d54 100644 --- a/drivers/media/platform/broadcom/bcm2835-unicam.c +++ b/drivers/media/platform/broadcom/bcm2835-unicam.c @@ -640,7 +640,14 @@ static inline void unicam_reg_write_field(struct unicam_device *unicam, u32 offs static void unicam_wr_dma_addr(struct unicam_node *node, struct unicam_buffer *buf) { - dma_addr_t endaddr = buf->dma_addr + buf->size; + /* + * Due to a HW bug causing buffer overruns in circular buffer mode under + * certain (not yet fully known) conditions, the dummy buffer allocation + * is set to a a single page size, but the hardware gets programmed with + * a buffer size of 0. + */ + dma_addr_t endaddr = buf->dma_addr + + (buf != &node->dummy_buf ? buf->size : 0); if (node->id == UNICAM_IMAGE_NODE) { unicam_reg_write(node->dev, UNICAM_IBSA0, buf->dma_addr); From patchwork Fri Nov 22 08:41:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13882884 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE964E65D34 for ; Fri, 22 Nov 2024 08:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YEuuR+8psNj062NlDHnckyMnQqgbbgHkJzIBccpjbSA=; b=wrsD8W8yTTpEgXLe0GBmUugb6L MFL/Kf5Wap6/vcvsaGNyT0jEza7ZYAZa7u8O4BFUgGkDgGXkoPW8zyhJ0yVhDo3uHPE3PG9+RExY6 EahaaR2wL30u02I5xZGcO9HdUkKZe32t0fmJx7jtoYkqsvc84JVgqmVBGHxFeye7mAxgKCf8ykTCM ymu2kinZ6O3qbMc++lWm6rdDptUnZ1+9xlUENXWhI9RI8+2coY0Z0UOAa3SfzlTe0xlgaTthv+6WK 25GWrfCfNzZUeNJG7w+Fxcc+5vRlL4LwOWL5mOiQ6EHOwae7IZGbjeLaA9Dcve8Tyaj5QRTbXvQ0D 1r4CoQEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tEPL9-00000001yeq-1tlM; Fri, 22 Nov 2024 08:48:35 +0000 Received: from mail-lj1-x261.google.com ([2a00:1450:4864:20::261]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tEPEw-00000001x6H-0Kck for linux-arm-kernel@lists.infradead.org; Fri, 22 Nov 2024 08:42:11 +0000 Received: by mail-lj1-x261.google.com with SMTP id 38308e7fff4ca-2f7657f9f62so19547731fa.3 for ; Fri, 22 Nov 2024 00:42:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732264928; x=1732869728; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YEuuR+8psNj062NlDHnckyMnQqgbbgHkJzIBccpjbSA=; b=JqF6JLjKMo28SXWI9aRn4uZFpAnKHXuLtinI0yxNQ/U0vWqpiWkhdCQ9oCrHSVYNoe 3Tvg8kO8yb4hr6dF8CWPRDfXkoAasWnC+x9aiF78OWyy45IpJrkKrdoTii3uxlqHUCSG 6Pwg2vWTasahlwUjjiZrpPsj27hBRhKNG15osZ88akuZXYi+do9Mm3CL0g94lfGUEa2I DcB+iYyMTb23l/KGCkbfcExIBfz9EVNfHSOSFt0skeznPywe16avBmBiJj2eX95rkwLJ IQlK8jnV6aScuuiRJdOfU+M3DkDr8rTFvK4VzmGHfZcME5GOUZqZi3hzLnNwNNmhTKjA yH+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732264928; x=1732869728; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YEuuR+8psNj062NlDHnckyMnQqgbbgHkJzIBccpjbSA=; b=DLMm0eI19e15QOeSeHdnKvarg08lD2lRrsNBSb2qOQcLdI2wtz85HcH5wuK2GwGC7c qXe9jFwcQSdcuZddZBL/DdQXR4zC8+Lno7XKkkXfmB4NPjfeMRAEzN28OagipEnB3cum WyhOcsbldAgsUuMOtkxuf8KvG9ZzDVzBV/T1oWYn6RdPrQYJSbzEGT52tNqbsMpgEMts BAZdPxdqIlop9f84coPBDPjKf5WHVwxqKITrRIrIE1J7nEUdLLX+EWHs3NtqKUPSd9jQ odd3KfP4mmXa4I1JAiLAU73fnNgROOFqmRf3WzvZ1xNmlJFtVwCB6iWSrr83rDJDUQO0 JmgQ== X-Forwarded-Encrypted: i=1; AJvYcCVp72vwEeJ+ztIxYdlInbgvdk9OpDQI2e/8f3TrqO0X02WzAOrAM+lJHfJOS0xHvbnXxtK+Nrt9P7CbVUQEzNVz@lists.infradead.org X-Gm-Message-State: AOJu0YzVMfaQNyBqbeH62nXB56W3ndTVcVd5zB8TJs07m5HaODw+V9r9 NmqPgVnJDhWaTnn90vZJRtLmZxxYse3fa+0admW9JJ0J/gFt5h9XRuwJAtO96+wYlcH7y+FSTBr rlnfSGfX5sukIkA+98TWIivMIpxrWybMw X-Gm-Gg: ASbGncujJfEzwadSggaj15Bu7MjHmeDDCC2wngd9f7WQd8UpnyOBWEq0Qi57lhgCEZ7 POIWE/jeoO5iA5A+p08kNqJLUVdrC9IOIvNPAiZAKX42G6RUyJOEtm05Y5ZAKHVHr+KtT8VQz1r F8m05CoUB3ps8SAAZF0peurFr7Gkpt+IL2FxJ79Ye6XMUuYWsU5QmVP7WMMdrKh2/ei5kLn7KW0 gelsRrNjcRGw0Avlr5QWetjyHqtZKzHu8s32RnybiUxBQL90rJDF0qfQU/hK3M1iA== X-Google-Smtp-Source: AGHT+IH59DQEKrXu+FgyMtFbQ1vxHpRwe3lqUuQy9ABiaFsiJEh89r7ztVYjLZAP7d2u3qmvDeDJw57zHVk6 X-Received: by 2002:a05:6512:10ce:b0:539:ea0f:cc43 with SMTP id 2adb3069b0e04-53dd36a0f38mr982109e87.19.1732264927961; Fri, 22 Nov 2024 00:42:07 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id 2adb3069b0e04-53dd243bb76sm31151e87.11.2024.11.22.00.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 00:42:07 -0800 (PST) X-Relaying-Domain: raspberrypi.com From: Naushir Patuck To: Raspberry Pi Kernel Maintenance , Mauro Carvalho Chehab , Florian Fainelli , Broadcom internal kernel review list , Ray Jui , Scott Branden Cc: linux-media@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, jacopo.mondi@ideasonboard.com, Dave Stevenson , Naushir Patuck Subject: [PATCH v1 5/5] drivers: media: bcm2835-unicam: Correctly handle FS + FE ISR condition Date: Fri, 22 Nov 2024 08:41:52 +0000 Message-Id: <20241122084152.1841419-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241122084152.1841419-1-naush@raspberrypi.com> References: <20241122084152.1841419-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241122_004210_114779_170CA1AA X-CRM114-Status: GOOD ( 18.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This change aligns the FS/FE interrupt handling with the Raspberry Pi kernel downstream Unicam driver. If we get a simultaneous FS + FE interrupt for the same frame, it cannot be marked as completed and returned to userland as the framebuffer will be refilled by Unicam on the next sensor frame. Additionally, the timestamp will be set to 0 as the FS interrupt handling code will not have run yet. To avoid these problems, the frame is considered dropped in the FE handler, and will be returned to userland on the subsequent sensor frame. Signed-off-by: Naushir Patuck --- .../media/platform/broadcom/bcm2835-unicam.c | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/broadcom/bcm2835-unicam.c b/drivers/media/platform/broadcom/bcm2835-unicam.c index f10064107d54..0d2aa25d483f 100644 --- a/drivers/media/platform/broadcom/bcm2835-unicam.c +++ b/drivers/media/platform/broadcom/bcm2835-unicam.c @@ -773,10 +773,26 @@ static irqreturn_t unicam_isr(int irq, void *dev) * as complete, as the HW will reuse that buffer. */ if (node->cur_frm && node->cur_frm != node->next_frm) { + /* + * This condition checks if FE + FS for the same + * frame has occurred. In such cases, we cannot + * return out the frame, as no buffer handling + * or timestamping has yet been done as part of + * the FS handler. + */ + if (!node->cur_frm->vb.vb2_buf.timestamp) { + dev_dbg(unicam->v4l2_dev.dev, + "ISR: FE without FS, dropping frame\n"); + continue; + } + unicam_process_buffer_complete(node, sequence); + node->cur_frm = node->next_frm; + node->next_frm = NULL; inc_seq = true; + } else { + node->cur_frm = node->next_frm; } - node->cur_frm = node->next_frm; } /* @@ -812,10 +828,25 @@ static irqreturn_t unicam_isr(int irq, void *dev) i); /* * Set the next frame output to go to a dummy frame - * if we have not managed to obtain another frame - * from the queue. + * if no buffer currently queued. */ - unicam_schedule_dummy_buffer(node); + if (!node->next_frm || + node->next_frm == node->cur_frm) { + unicam_schedule_dummy_buffer(node); + } else if (unicam->node[i].cur_frm) { + /* + * Repeated FS without FE. Hardware will have + * swapped buffers, but the cur_frm doesn't + * contain valid data. Return cur_frm to the + * queue. + */ + spin_lock(&node->dma_queue_lock); + list_add_tail(&node->cur_frm->list, + &node->dma_queue); + spin_unlock(&node->dma_queue_lock); + node->cur_frm = node->next_frm; + node->next_frm = NULL; + } } unicam_queue_event_sof(unicam);