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: 845010 Received: from mail-wm1-f99.google.com (mail-wm1-f99.google.com [209.85.128.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE13018787D for ; Fri, 22 Nov 2024 08:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264927; cv=none; b=e0pNnr/zECKokTVTUb94Hcr4hitxL/LZvetRPdlnBSh8WIIyrwsWg5fCmi9+M+nWiZkhmTYOQ/Yt8tShU9zLemzEZPRKuEtQ6Wb/e8TgR51038xdH1nZYMTTMpSSSAVOLm2U+0Pfaj8YMqqG6AZtRtQemaOC8KXUC/dSgoCSylw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264927; c=relaxed/simple; bh=sP+4letafPvxfukJYV0UOYRRFVIebSXD/aQphVIz7qY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Vq6gLg7CNc/bJrZ+/j5/jo/BOamAG48JIWVxMiTD61OlzlmfyoMnNbV/SqX1QsNuVoli5orqzQwHxxwwyc0nPIsp1uX4rlo9zIzRMQ+Qw8Sj38TRZGnHF47rV2PJPMk/8akkuyDwBDgCL8YxijPHBG9wfN+anstsyddMDb/BJUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=W1yWkMS0; arc=none smtp.client-ip=209.85.128.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="W1yWkMS0" Received: by mail-wm1-f99.google.com with SMTP id 5b1f17b1804b1-432d9b8558aso16847425e9.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=vger.kernel.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=W1yWkMS0SYWzQ3zoKcv8xeYylwxBCCcQ84wuqbjQXHN5S77VQj8YbvVze7OCqOwrhj WRuhrjreTn0/oh+2t8DzuqNR2RjovzsYUdxFVF2ivjeezmSCp0DxK5PqMicoWAyecVtd 6RI3GfpJtkg3OSLmSdwgkdfEjMNaEigDx7gDBQCvWHJoUrEF4XY6vNroke2WC8y51dhq xxXPHb+RvgykV3IOwMmapN0u3aQe11Nyhhp+bol7BybuHdhwpAqrIGKqd/QSQUaxpLPm gSwRFoZDvwq98ZV7MPM6MGr1xHeGK2dwj6At+m5u0YIhMsHnABG9bQOeIP1+BjgrIXPt 51NQ== 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=fFmyj8IccLpajGUEy8gjgV0Q+uBQs69qxRKWKZRAs0Wm7CFyGmG4D0PqlUX9wUe1sy q54dCKUYG/8j2mi13I1Ii/ZBHkhxALQSkMiW8OcO0Gx9nQ2T1W2nlmLlnabWnriaLx2j 7WI7AaXGKMAo7FQDs48eUKi/tiP7xH+4fY1b6Ptvg3tl8isGCcbgDtzlgXdDS0tsiAFp D97f4nUOGxwSZ9T/13w2qUTvgCrUbZ+oFdooUEg/92S/yj51Fyu4QJtdNzX4YQNfDLQg b7ugxEJQ7Owx8NEAxTQtj7luPuPOVsxPu3xyCPBY5sSLyIjKVBYON9E+mUNn2IzX7AD6 f4zg== X-Gm-Message-State: AOJu0Yxjs+DwdtaZqzFVq+Ogw80rG1CZE7KXlPJCeH8yS8Qd+xRKZPOe bXrExabbd53u1XAGSCIGYMEcuXANlOEL/yEwCqw0Cmg9wogmWKztGKNhfrQMNZ1xDlhavW+tozW gjZZWWBn83+DONQtAKORWYn68pixs4KEv X-Gm-Gg: ASbGncvJsyaDNLjZgp9Km2iOWkkUfoNBbzQF263RQ1SGXEX8ofWdYuWcd1U8P0H3RTK gxgwXFXJ4EkmoVKaFDp9hW5OaTUu7vDvitNCAATTu0/aOjYJREm3DluDpv20caj8Jo4imV1oQmD Qkp22eQh5FGXAzkXxf5VQa1xhEKgCEWKrBJmpHlAh5IRhF1oJqNu/37EUp1ad02k7TOSsgya3IE /FtwwA738RVnkNjKoKEF3+e5+ZZK12a93xiuiqKYPhxuyRNyLMgyMVwYZPOroiQRg== 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> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- .../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: 845507 Received: from mail-wm1-f100.google.com (mail-wm1-f100.google.com [209.85.128.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64FCF188013 for ; Fri, 22 Nov 2024 08:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264928; cv=none; b=oj7crthFn9WTzdmmoXjQpbS1szIz9ykd884saUzr5kj5TE1yyG3xqyG308f5ig6ihATmNxL18UiKHugdCI0adNmNtaEKrMpja0vyIYy6x/dWKzL2ljNLZhQ4g9JASYxqDkMDGFYnnHBsG4ib/yyr3t6agP/Djhtfp/bK+8Cnq3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264928; c=relaxed/simple; bh=lbGB7IqyGqRJnbeGbuDSS1RlVZkgBlJN4RI9PK5cJOI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p/P/eqsgUvzqyWANUapyAw4j+NBzzEjFrapG1qqyErFHtZQmD36iTrCIGhNr9gV8m30osF96DQL0aWwoLsOa4m9GuC4IH9gen0MbXIjG4EG8Ab6LHjkuC5AcF+SpVONs6KBRCq2SdMb2/f0HkOf1PWfugkMNg0uGRfCsm8As95c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=fLWB6DLX; arc=none smtp.client-ip=209.85.128.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="fLWB6DLX" Received: by mail-wm1-f100.google.com with SMTP id 5b1f17b1804b1-4316a44d1bbso15811085e9.3 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=vger.kernel.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=fLWB6DLXO7fihsjt9Zuq1RK5T4Opm61IhBJkjHUyMwjJymGzpC6pnAA9E8rn7K395L HLEd2xKkHrlNF67pWE/Vqs16Fu0i0WixEPCVbI129wI3COObYjyjSxz2svaMwTJOKDxv G/plVqU4It0EllPDPXbG3MDhAbQEWqjSaabiKfUJtobvnbIOGjlRabzAzRBb1oDbYM+I diK1ndVVbNd5/yYeCmaHUlj/bvHNEtDhcYnixahh+OMDUMZoIrYEXtpFstqITCfLu/7f JdclFWWNAG2ChQGM04tlF+esR7WDyGrR94qYTFMoRj0QQo4dh7iL18JZ7n5g6vy0PT3w 5Low== 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=BWqdsudO/fNWCFjUpxFuB3ubvH9J97zqdsJLEdjM4iLfLI+kxWOfAt1o5zerxYVLeo bk7gaJeloILIW3m42hgO98hGZP+BUKeH3OwD1AzPPXV4lPnuy8jgSQDoFKEyKBWJA8H/ lwWO/oxccOPY4csSnfVUfeEt1DJYlp8rqH9Od/qEarNm8pKE0ItaXEejYM3aRLSEYl6Y xNl5h54beCjH1ma4AEmMnHLqWZPeRm0fDc77TfFJxVJrDzahS0xAr3rN4v6IY/nccTK/ WKwlS8lLsCxLIzIiXvdx7iyGe84hKL4mVOvHuJfNA5hqYVH/4m1CNgnDEvoHskIeYn9I jzPQ== X-Gm-Message-State: AOJu0YyE34lngEDGsQdgw2ZsQAHLz08kwfNO+GOH41/a5b5bSLIvDNti bjVblT6bUC6rn91ya79p8exHV4ISsOvVFJFS/+6OkWA9nqQPbkLxbC6u5n3ii3aekVP46WKe2/L cE0prtWG9qIftAcEKq0WAVqUWeEsoDsGH X-Gm-Gg: ASbGnctdfJOMjyUX0uMM9/+PmdDdmtSGPAQebHO+3vOQJy5tYTanYVj08sipnwHeqzK KLTPXybRcTieSRUtWOpoVlC5OIbbh7U8cLcIR38hAysRSmu7ITuJDyL42PsKqIBpe8sbvU6mawL goI1PFK0P6lQU2HBsL5uQxjZje7X+FP6rdVIbcFa8A9aSlsTnUOKLkhU/JbkJBqAi+fnTe2p5Q1 VgaMuHoE8rNEhaA3HQTvCSl3NBS5KoywDtd9Rxwr/hKGvAg7NYkOrRfTO+tvvptaA== 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> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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: 845506 Received: from mail-lf1-f98.google.com (mail-lf1-f98.google.com [209.85.167.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39D5118A6C8 for ; Fri, 22 Nov 2024 08:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264929; cv=none; b=I0+vT7IHEseavgffWgAxw1l79sHV61gRO02X/+dKVeFnF/j6LG9npadalbMi2evWVkt6R9PdG8AymcUdJX0bbHEsYbQMP/ias1AO0Hed6OjCRHsM7VbpeGAAXeoJDZkRZGiGHwm1Vehj0iofEoNiXFyGFSoiaiEnn+1QsSRa2tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264929; c=relaxed/simple; bh=dGEolcwuEISeHo+7O9hBTplgIF/4B00JAkeGfZf51eU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mpNdp0+WwxpjZ1/s8Jd6lBH4u429i3Gz35r2YPl26oY6l1P+MsDgdhULjLv9lqiICcKYD9TwkpjhLPKPQTjTWXI4bIhCBW2sxKExI5kQFWukLYGfVcak5Wsl1VtCji2q3sjtJj3PyKq9ch5DHuo7bSZJ2zx9xoYlny1N88+Frr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=goSbbh1t; arc=none smtp.client-ip=209.85.167.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="goSbbh1t" Received: by mail-lf1-f98.google.com with SMTP id 2adb3069b0e04-53da3545908so2125542e87.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=vger.kernel.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=goSbbh1tLBnWRD3/jZ6Adt82mkxSV4ieZlhqi8X6Th5r0f0T3rjyJ+nEUThBiEYA6M O4fqMwjZeoaiBESsyCDl3XmIyxz/tsD4T4AgZcBGBAZLVTNajISLSX52/pt0qs0YfZLs 1mj21miLULW+/UXIao8zo7YmUz1k7VwLh3dfZNUrCADOr0eOB/Nrrfb7ZBakVL1GbWv3 fgUbsuZZFoloJnErOXPOYS/WdjL3XmxMJH4Ytl2NMHgUuo/dnOD8NvqYCXhmsylqCg5I Rqwqze9DY+tjHiwlIV75KK7Fg4Vrmz383BGKueml6zUU7kLYeMmj3TMmvLh4l7kahh1H 8D8g== 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=EgZIF7c/lvNnDSLC8mfOV13AKpEFrJoH0B/LBCD34E5uLkX/wrpcqXyIjxe89gsPn/ R4As6kKbRN+WPw9cnPcdvJCqned7U1S7dwwnXBKwFeBCZvA5g0ivmNVFoGtHVIVWC9nv r8ICHho5lwoBeUi+yaK8MtNJC1YAq0PF7UGvLmDHyyDmLh/+veUSjZgdxH/MEBRf1tKV QAuvGTD16gbVfgZkb7hZh703WTQaX2wE71o+npbZNhyCCGzdKyJLw88/OeVF1UrDu2/V fGls89r2M3+llq4OKOwCa08SeZ5YKj675GnAZeX0oypr6xY0kEqhfEZL1ln95gr9FGsC 0jwQ== X-Gm-Message-State: AOJu0YwDAEwBPP054QA064WjygQEBXZiJRw4jZtQFjDfBR6zBWRwI5/q hQnXNIo6L+WquZXp3UWmWmePedzYGz5/arSzilLiG1Vsdupj82W1YP1lWTciF/YkJfEujfrR3RK dRQNbxUHXfYKlEn/CIFUsE+lYW/JAv/31 X-Gm-Gg: ASbGnctjd2ncihM2pMXE+ipYw9Zl6V8AY1iicIuB4CZyduZe2tnpn/R7U3UFbejUCQS z2W+GAxzAMPsawlbwuNly7HNHLA7FWxojHblB0Q8GHJPQ51aPCJYOHx+HBIpt1nJ+CVCE2Rn5xl 5FK/FzohAKiYySEwDCFJ5BOBX1TDqZfQsltGVZMvSyPWnK8gOaQCY0JWnewFgXTpX+j08UIBaUr Vn2MrjhLbnHJ81xlhvJu+SzoT1G/B7I2g3mHL+6DlIUjqPCpgfV4h9oTRgyvznM1w== 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> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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: 845008 Received: from mail-wr1-f97.google.com (mail-wr1-f97.google.com [209.85.221.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66F65189B95 for ; Fri, 22 Nov 2024 08:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264929; cv=none; b=nBa+BoFyjzNT6hTFBfTXy1//aeGALiqKJbKCsFImCgaIQn8Q6R92DLvYmU4MXrwlCAWo2zsJedOEFS0S1dQOuTMvFTQh2/JKecKFnlEJwPQohMEO2OcufxvXRhq9ACUB8setehrg1XfO6i2on5dES8pdiYJQgAB+640Ktz0B5Ec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264929; c=relaxed/simple; bh=Ot66rVNwD26UO/5YVx8cEhDAVFdsS6j0qnhs3PRBvE0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JxWO1ti/3iU9b/DnUi14v6yo9AaAGgPXK/LPhpBorHN3RnhZOMcg9Cy8gJfea+1FewXENEJPBCdlSzJaz/UtCzJV3lbsGnpTd6RlZDrpaoSRl9J5jOvamCZn3tQWByz017G9VdLxy1WHJl6YUvuu5D5Krdiua85WhvcxrJBVjyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=SeNbLyu3; arc=none smtp.client-ip=209.85.221.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="SeNbLyu3" Received: by mail-wr1-f97.google.com with SMTP id ffacd0b85a97d-38245e072e8so1680636f8f.0 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=vger.kernel.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=SeNbLyu3QnjiBOibbWGufpCV+O1IJs4wyge5FHAOQt4vqgQWglROLrmO0Z6tqPM9Y/ Y+igDc8fHRwwx4LeSga98kjoilJQhaWRaXTDZg5hu0wvU4/F7IpypUBonzr/cXKvRmHn e+XZo69v7OTDsqoZeMmqZNrgH8YNTcX1M7oGm2TOl1rftgm6N2SxWvPnQt9bgZmp6WWi QTc/JErh8duTZyawvKbbqAHKfvf+icHUaFIc3SVp+CcxcEnpMWK12nhXnqnkZGt0n/VK IaBwM0ReAPY1Vi3DMyIavq8/VX40IKZijMkiwdfJpenjuh7MsgxgY611rPZrlsYI8uZ7 jj9w== 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=NYbvwPZjuGg8tYxf1BR0CXfUAAky8mEIGgVpxVcGzP+ogm3b4JXIXASkeVEQzZEXRz /ELgas3p028KqUjC7BpvbqPZgTGfjKddyNU9MdpKZEBo311wn1sHrZp48kz8+0eS/f/e shFi05qE62yKwGryLZsfBDCopzaEhrIp5kXgUx3S9Wls5nP8KBrg0dv3ZoTRKndT4N38 5QphvdJ54odpbjMiEcTZkdn9uOg6XyygdHdHkFPOXWiqi3lMOqJpTj8qFTOqhOYA2X8N wVo8LX5SW/0yaKa3wbF55LA3oqsNeycJxk18N5m7QQmmASLTjZWVB2ZS4cswlMAS3EHH NW0w== X-Gm-Message-State: AOJu0Yzmd0+do1L4z47h+mVZ29FHSefT46M4CbASsrC78lFfYt+IyJtT mlkibhHFTe77NpuUVXmofKy9K3LwvewiBCJoc95bdMwS66Ke+KdRjH0pDOAiSlRQUKzpRVJy8sF LkmwtxtZQq9nFyD+FK00slr4cghQ02cHA X-Gm-Gg: ASbGncvgTJ1UAD+ssxznFMQ7zmvIw/eEhU1npASpGExsQeQX0dNYe1pQMWO5ZfP0KQV wc4EaklOoMJDxOvRfp+H6qfDYFpmVMsZtwrGwuHinkboRWTOBISqlxaROYhWmr649QUOgT8104+ jFg67PR7okG088CARQM/YwXhHsWZZ+BlirHAP2fUxH9aydhr4xha2wMs8g4bSLdTTMT+DvZtkEm BSccOmQgNCrSO8Y9REHXXP/kpMATkGcBVwvb254flHoE2SS/AyFqpKbesWspjhgAQ== 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> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 845505 Received: from mail-lj1-f225.google.com (mail-lj1-f225.google.com [209.85.208.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EE4E1C7B8D for ; Fri, 22 Nov 2024 08:42:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264931; cv=none; b=FNlooS+Q7MFsl3ux85O7zDjrFtrTEGGeSsp8+v8ISVGV5X1GV/UDl84Z3EBnYlM1SWxRWN1O4CuHzIZ+KBoGVk2BFZKhBnRZ84VfK/syIZnwfvOP8J9wEMzURHEgy7NqPXrIBM7Z6RAIrWFxjbzTVRVq+CqzgANDZUSDtjfL4KM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732264931; c=relaxed/simple; bh=5AKvefdb2FKkKG19uxXZOCMpFrT7SuQ7/tYup9Rr538=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tgx+IbWkElxWyW8BtPhD1AEqxjCyzXSi/FW35YNmt4hyl4yPUC4uH/dgDz1PR8pvf8biJOO7k79RLWBRI0lQwKH+TPE7QnvHZjgkXzdKhfb+HuVlcDrU+++3fYAKC4SQ2y1xeKEGQo85JD5j7/Hkpgwr8syMfbXb18zWZo9AAx0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=jumFb7s0; arc=none smtp.client-ip=209.85.208.225 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="jumFb7s0" Received: by mail-lj1-f225.google.com with SMTP id 38308e7fff4ca-2ff976ab0edso19522151fa.1 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=vger.kernel.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=jumFb7s0/s+0uX619lFsGR6mqHQyn0GZws9ZZ3pRtsTXSwwLcGyJYHaz5gebJBf6g4 Vgq5SoX/cf7sCDNSlSbSDQu4zVzUeYP2yfE0r6zqx1huDYta/jVDeIATlSjZbah49n7V fGWGX2MjdPGZN4uqFIzd7r27S5Y4gpemjbQnkxnPehkDgnCY/35LXV3CZC4aomLYGrgb VfrSbXTHXBhkCYUxcbHcp8130VQBzBJUoUnvXrpWjOfr9KQk40hqSmEulBsGs1ughQnv wyT2jpt3FhCCbjdyFvCGsuc2xAquoORCTj6j+ZMZCTydNAExIUUWr13d1rfmuQVoiH4w ZYKw== 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=bSQ2I1mKhkXqVFrdMUIw6FtUpcQE8miIUFDF4CZtftEp/mKKaF84YF/yknDOXkfKEl AdN9LkFhcudwkIRvtbslZCVPbDzhH+2gSlQTSqwplkHKj8KNOTs+ScLN+JQXHOUNy626 Q/0YNWCpkD2FhbHy47yTn/1aFdTkuf/w+YzB6SLuJPnOu8L/uF3TiulNftJnzbAap83g UkcUd1D824LJcPgZGXcghQS5dJej+TdLqaVp7rdXLZ6rGRYcI2598+53+ylY0l/7h4Sa 0ctzw2edH7WjFZjb7Vz6VP/jQ69DYRbSIZd5U5Ltawo4vs3RODn1WRV5QA+4ejQkZF8V FgAg== X-Gm-Message-State: AOJu0YwkNPcTyEpkLdGieIKFqnWprjXkoEE2Ar5MlBzRmLuFM2+oUpos EwRNBpnzWYwSZgPg8/INY7KocVmzb8r8QhLd2/27ehRmW+9dpedyNlu/nvIYo/1gAaYzptqWRfW LPqN19rZA0M5J5ePqhZx5lnEP5By7XuxY X-Gm-Gg: ASbGncssIZIGTFTNwMFPfxyI8QamRx8P3ejCUooe9dMSogRHx3cpFb64NUKGyw//0q1 zjc0w3BCL/BWGN/AA6h0s8/l2f4zhRn19wIsujvYvAjC6zYWlc5ptwoYLOzekYD+Rvt4h1HnOH+ jhWoY/qM0ycg37cnr4tmXtXh9t47GB897fbbqkk67Zn2VVkBNC8sCs7iBj7BlWdEFVua8BusV79 Lb+Mye037btxfn1vFx1uZ6aAUyj5ToRRAmeZ3JTjq/v9Op3ODEvujoLUTjx8IRs+Q== 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> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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);