From patchwork Wed Nov 27 11:15:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13886902 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 56AA0D609D8 for ; Wed, 27 Nov 2024 11:21:03 +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=NDLmlhfFf3fKmWcDI3ja5XlaBhDY7yQ7y51lLCUjcJ4=; b=Umtqso/wKC1RFOfPTp1YyZSiTd 8hU0EhobTcSlPAHFkQS5r0w5gxnaBr0NE73DquKJ0Uu9EfPTIh8lQpIKMTcFfzcIqyR8FJXockOjT +bYuhbOhKGTA7c8UwWrCkLKE/DFuX+gXSxCZp1DAXELP7HsN4/V6m5QjQLR3o274cOXPQ2xVzLzqd P5c2tPP4BV0gwJgnim5hG0Y4lGi+3D5Do0sY/qOe7kkqgrF8Oqy8vI7MqPXsfVeNhla6mJ2In0Tl3 9w2rmp/FjX4UqIHiBYH3C4twadKMwXvOSUnQ4M76Un5hRA5OeW0aXJVNEIjkIupdEE9Re3FFKXLuC fyxb1EWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGG6C-0000000CzP6-2hmj; Wed, 27 Nov 2024 11:20:48 +0000 Received: from mail-lj1-x262.google.com ([2a00:1450:4864:20::262]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tGG0w-0000000CyHz-0PQn for linux-arm-kernel@lists.infradead.org; Wed, 27 Nov 2024 11:15:23 +0000 Received: by mail-lj1-x262.google.com with SMTP id 38308e7fff4ca-2f75c56f16aso75906351fa.0 for ; Wed, 27 Nov 2024 03:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732706120; x=1733310920; 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=NDLmlhfFf3fKmWcDI3ja5XlaBhDY7yQ7y51lLCUjcJ4=; b=ByN3U/ybDLN17nKgjnsldF+FJpVG31ERX5YY5nfea6KGA0U6t1jia/ELDCYpjMzObe DW7AWmDgLxbtqvZ8ntCPSxZtZvR4jqrb/zW2tmphl2Q34i/sn9jIyhcgjV4ccGspoktA uWHJf5I1LBLSabqtk0Yhn1Hxv6qOVLMW2K9FJmCmr+r9UhOUbm6zgiW+nDrQcUQQPC8e FGj350V6dMlcidRSJFUdXWI8XefF3+lW9DaIN5gMwn+tb28GaXJj0BV9Ubw2sZRXKQVz Qdx5eC49NgJWfmPd17WfzKFrKzgDda83CJn9vDGdJqy9yj3HD346fUCy4eN6eiy2jTHM HDnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732706120; x=1733310920; 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=NDLmlhfFf3fKmWcDI3ja5XlaBhDY7yQ7y51lLCUjcJ4=; b=lQerGaYG2ofrSb1jl92zBVd8oSGWSe2TH/f9xF609H3mG4qxQtYgrjjGZL10D4dhly wAa6H1l8nwiWsQGYBVDeXiu88xp5LF9GOtYoe2GsZQ/KrOwyHqIQ4XremFgZFsBRGEoh MorR8awErD0o3VK3WXFl1mihH9kpUUennJKehsCmbDID/EGXN/OC0fpxX429keZGq2Nr n8YWrL7C0PyZLXce8NWNspeZPjAEKUqthjBuG/7ctFM5f+y9yZ3Kz0ZGksBc+Lgz7Xvf 8KEMCpgmKPPbDwUeOX2GvsPNBooNUo2M5oUyqvjmzI1/qVXL9uyvC+NnOb86BPawNe/b DBpA== X-Forwarded-Encrypted: i=1; AJvYcCU+qfWgmY9YJBCXIb06xv2aJ2IMiohiufAR9BI8K5hIIWh+48xA3dwASaAkmoICMAfoAYREuV5ksFxf1IvKsAPn@lists.infradead.org X-Gm-Message-State: AOJu0YzMN6T2kF7y6VB/s8r3jomgl2DpM5Cub5uxeh0vbqxsM1feqnLt LOUoTYn67wwgmhVMDYRx6Rbxb4Qy2XvNhYaNJO+iRWK3KAdHjTR7rJIeUcjeV5f5YlFrNB94T52 S5bd116GoWiK0Vh2lGx25+sxSPoj21z8G X-Gm-Gg: ASbGncsWUvpLFzfKoyw0EYnwBD56+5X3W5bDRGEBvhTUMAOR6KTflAjuu/DM4VP9ziA SSpUIgt8fOmoLNz4eKf4N1IW3zUf7Iq4tobJ7umee/7Bl6hOjIztPB6DASaVfui/zafUwBbbQss pDkushtTgC61hRHnDWEvF9YFkpeYbAuwURSiuOicT/JM5P6t662BeAwEBOm02Ff6ptj2amDK8Xg n/rxpxfHJZe9aon6KuyliU6dR59X9n8g6MNzNs1cWx7Td9dyTKVJUVOA92FK5Q3vg== X-Google-Smtp-Source: AGHT+IGTwoCSNs5BBDwFG/AtnZDnL6h+6Oxq6PET6Ihsy3bf1ZEmlnpsnNPW65FRF37uJIGFAM/fVa2LEDdW X-Received: by 2002:a05:651c:211a:b0:2ff:c67f:5197 with SMTP id 38308e7fff4ca-2ffd605a257mr12586081fa.13.1732706119878; Wed, 27 Nov 2024 03:15:19 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id 38308e7fff4ca-2ffa5eddedcsm1274321fa.59.2024.11.27.03.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 03:15:19 -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 v2 1/4] drivers: media: bcm2835-unicam: Improve frame sequence count handling Date: Wed, 27 Nov 2024 11:15:12 +0000 Message-Id: <20241127111515.565992-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241127111515.565992-1-naush@raspberrypi.com> References: <20241127111515.565992-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241127_031522_144605_E1697D76 X-CRM114-Status: GOOD ( 18.88 ) 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 Wed Nov 27 11:15:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13886907 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 3CB3CD609D8 for ; Wed, 27 Nov 2024 11:25:07 +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=+2z95vIVxpdoEpIHV1Hs2li8opRkM10lvZmaKrYhPuQ=; b=4gKMVJlfUBShsm9y3rhbaDNMK4 YPoo3IJcRRvbkazzXk6jhuLdvpXw71aTtm220tRlQtX9KvW6fkFP8DXW+cPRvYPj++ZtwQ0vXleMC MbFSko4NLoc4Gv0ct+KWPfPzWrfVj7fZbg9rQx5ITOzhBuRsBhGTQIHBWDpOpYzALkJRtGdBcQFDU XJI/dY0yU8QsGFsm7pVc8upn3rjtft4wRL6lG0tcu5QSiP7N63j4U9l4Y0/SPJC5nY5Ozcw6AhfP6 pPGTORSGSsG3Acv9j1lqlSFD6lYRcCRV3PucHyIPp48ZLLdn5CjALJRX6WTRhfgAI9DImYlaYeoPM GpXKyMXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGGAE-0000000D0PG-0t5f; Wed, 27 Nov 2024 11:24:58 +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 1tGG0w-0000000CyI3-1lQz for linux-arm-kernel@lists.infradead.org; Wed, 27 Nov 2024 11:15:24 +0000 Received: by mail-wr1-x462.google.com with SMTP id ffacd0b85a97d-3823e45339bso4784827f8f.0 for ; Wed, 27 Nov 2024 03:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732706121; x=1733310921; 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=+2z95vIVxpdoEpIHV1Hs2li8opRkM10lvZmaKrYhPuQ=; b=jGPGZdUbBGvf/TnS+fcMkYPZTv7SBf2UwmB55X/gZz4V06OZL8QnDqAB0SYXmBc6OW iD4L6UALZsf24q8vv0guU0z0r+hK74TYNfe8HogfS2QGchvMvR27rq6sOq3rehAqzGwy a6NhX72Lx2eurGzLi8bRfkKx5fV/1X3Ya3rDKPlA7yVe0s2E0ugX+APJBnZCKKspsJpE 66t+Hqwzcxjek3cgMx1Ns5kPORDMun5m6EYhfIlD5jlw4YObe5w8rTZGEOM3Lgj5B1v7 hVLiY4ZmbnmSwRBlvITwMmSpVGkbRCvnP8g96VCUksi6mWbrHreUgAQMpAkt06DG9rYp bTxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732706121; x=1733310921; 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=+2z95vIVxpdoEpIHV1Hs2li8opRkM10lvZmaKrYhPuQ=; b=MX3lky0ZEpSUWXFxlv5GXB9ig7Wg4M/wrtgv0KMxTRNu8AIWNZjIvnLHo+OqEQQP3m 2daKtnqEvyTghK05/ff+bugVsy0fy9Clo7eAKMKV/hEwAAzEfI4eFQpG86NHrF9Iw7iG EaQpEGXWHF7eqrssXzdhRW5be1J8o9OAWQalDRz72d4E9IW/JK9KXtYO0QoB4QiJYql6 +gLXKdIaak7HFb1hmVslFj86UxRsYlyo1+pDUbMhHCtcJ8GsekU4BGshHzMouthmMmqm VB6I5khz1bSvndo/3mO4rISjnf/a8Wj6TWEYqJg7g87YgMt7SvHCr26z3KOSjw0asCx8 pUvQ== X-Forwarded-Encrypted: i=1; AJvYcCWkNlr49P3pF9zxwZ9Uzj2mfuu4dCVSk3dujLIh5fo5mz8ww8UZ+NAnaNCYSpFh00uYuk3zXcBJUVsBrY85dcuP@lists.infradead.org X-Gm-Message-State: AOJu0YwgjANPbcfIFSwCfIzd38T4olfSKnRGQaS6KAYdYCTTAuxarKjD X03MD3P7nyMWqKhet17czYpVYKiqkoR8rjnbkgC5u1BV/rgT/RBniGk5noOah5d2KZWUd5nw3uT M2/U8NaanDAXESlHvJMu4IEh77VA+vLD1 X-Gm-Gg: ASbGncsp0L4hmknBXv8hFuiNXJKutyY8ttbVH78qnyc3XNbQxRRYoxu8MFywcW8qGVb cadXcBkql/9am2JhhHx0/t8kRPWFNO7i6L5K/d/vmImrgBEwral6XYaxIna5N946gs2k/82qlUd iHilYyk9Qvcp/bWrh8iOv1Wr/PGHjA6jPYJzSsbczsFPivpOaHThfVMb97NlHPcVt75chNJ6bh1 NXqiZKtv39MZDhCf77Eq26s13UxCTFpq6zm5P/V5/idNxq4uyLouaqdW3Sx/7Ee+w== X-Google-Smtp-Source: AGHT+IFqYJhAmhFIs4MrJEK2DwK6ZnHRiHMIjhqtLKd1Q8gK+tAk+5Dr+yVE8hWUGs5AFt4Q0h739aNEfBbT X-Received: by 2002:a05:6000:18a5:b0:382:2349:5a7b with SMTP id ffacd0b85a97d-385c6ebba1cmr1732527f8f.16.1732706120527; Wed, 27 Nov 2024 03:15:20 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id ffacd0b85a97d-3825fd0041fsm441847f8f.95.2024.11.27.03.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 03:15:20 -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 v2 2/4] drivers: media: bcm2835-unicam: Allow setting of unpacked formats Date: Wed, 27 Nov 2024 11:15:13 +0000 Message-Id: <20241127111515.565992-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241127111515.565992-1-naush@raspberrypi.com> References: <20241127111515.565992-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241127_031522_474202_61FCE575 X-CRM114-Status: GOOD ( 11.74 ) 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 Wed Nov 27 11:15:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13886903 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 8B0CBD609DA for ; Wed, 27 Nov 2024 11:22:13 +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=E8u/tqgNbTDWlnzWRktGlQ9tYzEXbqX8e0KFyaCvDAo=; b=YcK6xwHsjZc4zS5aYOwx4dWCF1 YwSfgigpuFKcYGRcjYHhkp0W1vmj6JxUkf8PerasVxSStlOtwkEfv+6ykm9C65DPOmNO1R5IUd3zr GcN2C/nT1FyJvlDwKzd3Fa7YkoDZqkQjy5rew5IZQAECaRCnCAXQ12vz/anAX/MLuPjV8n1dC5G+V CI7ryqRwg33yfWQUuCA6XEAdQp6xTerSdJWJPfYE/E2/exv4Xf6UeNrpkl43T6ItwYbI9sh2TRB9I v9bgIgnxZQ02mLumYdD91Dd8OdO3DL6gAKubNIA1GglVAjhGZGzVHK0cK74DKo7V6IH+S4NZMvoeS 3g+R1n6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGG7O-0000000CzhV-2XkK; Wed, 27 Nov 2024 11:22:02 +0000 Received: from mail-wr1-x464.google.com ([2a00:1450:4864:20::464]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tGG0w-0000000CyIB-3lFG for linux-arm-kernel@lists.infradead.org; Wed, 27 Nov 2024 11:15:24 +0000 Received: by mail-wr1-x464.google.com with SMTP id ffacd0b85a97d-38246333e12so6524144f8f.1 for ; Wed, 27 Nov 2024 03:15:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732706121; x=1733310921; 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=E8u/tqgNbTDWlnzWRktGlQ9tYzEXbqX8e0KFyaCvDAo=; b=cA7UMZ7Wb3XpEaX5qEjpzAibvFoX9n2mGCYfiHGbUfXypCY07lGln0IsROhlDEMgDY 1nBr5G8jSeyKnAG9RpFCEyIRDFBIyXU30hDsr99k29ejIGX5WlGzbVXdCW0/dWNp/BuU n4De2mYcY/soqWnTgyCrxlYIRlLCbbzAk8rvZa5AZr6STfM6xCR+txsBF/lotFvUN8gN QLKzVIVtp8/cy67SJdo4MvpDYEP/3OUpiIeryjWJAmzT9M3JSQcySKbbvHjz2sIXnSGZ IDEpjzzTP5oVn4U8MLHDHljmwYzJPjfpBg4pg8mLqA8Kflsw6UuWc5VMO1pCQJFaS8AW X8KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732706121; x=1733310921; 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=E8u/tqgNbTDWlnzWRktGlQ9tYzEXbqX8e0KFyaCvDAo=; b=on7t97ODFPHCDt8YQRpgBQNGeUJwLWZcFStY1xg3styBKtqzNvY+SaFIprmXzN6Orl bKzzKXNnMZGZs/zY8Jyu+HaDoO7K3otPKx0j6CKRR/DGHTnIYNHTdQm1Ft+zc+dVDbqf OsX49LGZ0U5gigbOqKEm6WvH1/6daca9LDD5F105k0Y6lKtAUl820DGSf0MzOuA0BwOX APejAjRiinPXFzq/px6vQjbw5rtGHYQUwdHjSikBcXQUgI9LVt5UzHOPwEgkoIVAwfOt nmICQTA3ZunFOYUv+/EaMgVuWHyoyS/yFqVkAk5ebqGxdx16MVy/Q1TAiVo4GQcCDzkG PiPg== X-Forwarded-Encrypted: i=1; AJvYcCVidmJs/cfkjX3TyBA64JSJDn3SCFoG2XfrW/h0LS6DcthaG9KXIE4Qr8/CB0gdmdFQqYM3tInLQV91CWVW2zAr@lists.infradead.org X-Gm-Message-State: AOJu0Yx5pPPXTcxe6IYhImT6kxzrkmPIlBhhBnXCEDJc7fZ1wx41aW80 UhVcmq3z6YjBhaR5IqhdqpTrX3D4w1hUoCmS3iXSkL2607oJHW/kW3bj/3C81yzwCohijl2T4Pw XAyDrjlsK/VW+r5xWIN/6/KykOR05MJ8+ X-Gm-Gg: ASbGncvcok7o1Hyp5hHENLyS9fT7XfqX3CP1wNUoArHSO64+4KKn6lrsXdvvwpNOuWG yyc0jNQmASaTF35zgFnXa8WAGZ0GnJ1q6NvB7VKTNqNM0ZjQS4lyZDOBuQIAaKeQgMr+2iP+c4D KZhekPfFZ983K0z7dXGes/xad+mpNhAks81DRf4xgDWRi1OiXHneAf6JNWmlKklyHvzQzWiRQ3/ BzRu1QitbZHvlTEcEwHi7xzTgmTTn3dJIvOkBLUivIFEEwwD/JIIrq+fH3eUnP00Q== X-Google-Smtp-Source: AGHT+IF6UYuhlMZWwu6G6XRnHvnHedKpIlZ7ngLVPHb1A9KO+apfgpcWvh597QK+I/YFytjWK0k3yOJSuLhK X-Received: by 2002:a05:6000:389:b0:381:d890:b5b7 with SMTP id ffacd0b85a97d-385c6edd314mr2620035f8f.52.1732706121160; Wed, 27 Nov 2024 03:15:21 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id ffacd0b85a97d-3825fbee19dsm441144f8f.82.2024.11.27.03.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 03:15:21 -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 v2 3/4] drivers: media: bcm2835-unicam: Disable trigger mode operation Date: Wed, 27 Nov 2024 11:15:14 +0000 Message-Id: <20241127111515.565992-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241127111515.565992-1-naush@raspberrypi.com> References: <20241127111515.565992-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241127_031522_936696_98B6CF1F X-CRM114-Status: GOOD ( 12.71 ) 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 Wed Nov 27 11:15:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 13886904 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 9C391D609D8 for ; Wed, 27 Nov 2024 11:23:10 +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=5OeHJ5VmorUPFsKfp3L5ZEPCj51aQDOtY3qfB7PKLqU=; b=Q2zZM8jIhiJoaLARF39qPTWpmM apEqi7Rh5gpzOnmKHg9mLj1oRbZd8uhCwjYqZmo1X2UBaemudEhWn0vfzV026YuHMwDgtktfJK9Va AmdsagZCgOD9EkR9wyvW4HKuDT7jl/PhElf06u8DdhjEyIb9FWEiY8M0dv1v36alkeJyEG8+aOUx/ lGELMZKu76KXRp3gbI9BmsWb7OGYE3kPytp6XGZeYi9a95tcCbjfIeyGv6alWSI14isgHdjqo3dW8 FcS5/kE0jjveplGnEAqUt5Maqq7Gv4buCXl5Rzg9bxzh6FKeIFhkHQGfcQWMnyq7vqy+KpDelpCwh MHaRulvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tGG8L-0000000D02a-2fDm; Wed, 27 Nov 2024 11:23:01 +0000 Received: from mail-wm1-x361.google.com ([2a00:1450:4864:20::361]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tGG0x-0000000CyIm-2E2j for linux-arm-kernel@lists.infradead.org; Wed, 27 Nov 2024 11:15:25 +0000 Received: by mail-wm1-x361.google.com with SMTP id 5b1f17b1804b1-432d86a3085so60344625e9.2 for ; Wed, 27 Nov 2024 03:15:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1732706122; x=1733310922; 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=5OeHJ5VmorUPFsKfp3L5ZEPCj51aQDOtY3qfB7PKLqU=; b=GeXEyZ3n4K9aFQ2M63IyPLAeEQ6qJx4Cyc/ptZHwYzOkWwkiH2TK1mzk/Hbw8EGYLZ w7E95QU2pxGW4AZPr4VPadeiVxtWAjR85X7rNGJyo+Pu/3TPxQG7uVufmhuBJGnCqS9X J8/YsP7OIKMYgKlsVHNzU0CRQ/zNBuVF+Li3AoHYJBAkzCcfFOf6S2JycTGPLU0H+ySv BsC/YTM/n3hUwQLROaS+kqkBrwx2HP1JDlTL7YGACwtveD5BX/r6qLa6eGR+aHECbW47 t8FJkyxiNqK1nGIt8Wz3cuwVFBBQ2JeNVaUz6toGHQBBwNsCEJFdvHhWrDoSiPxxDbOK WOnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732706122; x=1733310922; 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=5OeHJ5VmorUPFsKfp3L5ZEPCj51aQDOtY3qfB7PKLqU=; b=fZoYnVmxHbgGg6qDeTJ59VUhKde7SETTRuNujBmV0HoUuyw4SPILLar29kxesVosd+ 4IKoiR4DamVETaixjCTjtNxf/MXdGZaeOgB0gZxHeTTgXZDb0faA+6biGJbzcag4r/v6 Z5cv61KgNhBqMvyNaPAEIdcYQ2P+TwY/K+zG+BoW0Pv7Np0HeQVeXLAXjxD1aDJ47lPM 6/dqXPrYyjBL+Tbvb5tRK5e7oHTICOfhsRvH3AXk0MywZ7uBKliQ95aKHUXk5t1AIMwG VVaILm+TBguSsHv45f+zULgHRAOxVnTVkzRcZgAuSfld0wL812lJebPoRhpYAxp5Hq77 O0mA== X-Forwarded-Encrypted: i=1; AJvYcCXO8rk6b9Q4ha0Kd985QNh9IsoXPdwFuLNMvpm0bt85Kp04P8iMstlUJU/L+JPo8/EQAMR0nCDM7vEvlin/d0us@lists.infradead.org X-Gm-Message-State: AOJu0YwLZWwWFFyKHz9SKPxi8QkW+UWJCGm2UnQbu/BnpgIWmDmv1FKf MMQ0Ygkbyn74tWeHLptUKIu7pBB3PgJpMdWh79QhIcVaXbYRjvxcgI77ciPMczXfr1zdXcZjvfW UfF0wAD6so70oQSEhgaGM0dIhMeVNI2N6 X-Gm-Gg: ASbGncsOXEjWTXKltI+8HaQNM3JjykXr2HenwIroSF/e8Eg6mL4Zkcp+POQbws2Hg/y vS88xqL7f8QY4pfTuHkUTg2aaG+t5kKZaBep65h8cDhnSA7Hj78SPZZtqdHWQAhXM/ZCb86nysJ fomE/apGqyQ8Qy5f9Vj4hTQ3C9ROPh6kuW55r9Q88pf9ultXU8aHFjMKydVav7bujinN5bCsjPE 6KljtLAS5zLbr4hsW9upAYmdRBzoK5JeBBqZ63lkX7FhcqVxrWSXjcdnWyaLBzMBw== X-Google-Smtp-Source: AGHT+IG8NIxF+WfvLMMyexhQ4F78Jja+ecK4xzKxkdy9lOD0O56mEG25LOMSGylsAkrpJskIxuI6TCXFkAK1 X-Received: by 2002:a5d:47a4:0:b0:382:5066:326f with SMTP id ffacd0b85a97d-385c6eb72bamr1917091f8f.17.1732706121697; Wed, 27 Nov 2024 03:15:21 -0800 (PST) Received: from raspberrypi.com ([93.93.133.154]) by smtp-relay.gmail.com with ESMTPS id ffacd0b85a97d-3825fae4853sm441870f8f.4.2024.11.27.03.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 03:15:21 -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 v2 4/4] drivers: media: bcm2835-unicam: Fix for possible dummy buffer overrun Date: Wed, 27 Nov 2024 11:15:15 +0000 Message-Id: <20241127111515.565992-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241127111515.565992-1-naush@raspberrypi.com> References: <20241127111515.565992-1-naush@raspberrypi.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241127_031523_575059_774D49A5 X-CRM114-Status: GOOD ( 14.93 ) 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);