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: 13886893 Received: from mail-lj1-f227.google.com (mail-lj1-f227.google.com [209.85.208.227]) (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 E46D91EF099 for ; Wed, 27 Nov 2024 11:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732706123; cv=none; b=jDRlROsl9Zskgf29cVcEE++m7XhTTYl6O5pVyMTiLFPnXZJK1JRO4DKvEdPzUOFmqtyd90wvw53v2uV4eh2XCorKpgG0iWMmJDzfj+J+u5LeqfhgAYrM3cMdILh0Y2PMcNmzvmfXeErelCJP1+pkuKgXfkB4DnTSB7rDtgm9VdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732706123; c=relaxed/simple; bh=wnthNX/wVIc0cJrqj82UcQ/NTxF5OCTEjQVgalgz04g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p8PH+OctdP0K4wGU1yrBmtCplSs0D8XE4Lg2Nj9B0W2WcuI8x+8fEYJgdgj3v0wKOhtEwAVOYWvvuorVgb4N3KROB6tYSZvRqsrs1XQOr6uagQW9hgL/+vUJngFeAuLioFOitZ/WXYGGb0FLxqlkDAmc0QzoCmyiQHrFmGf6u+Y= 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=GvFlc/eV; arc=none smtp.client-ip=209.85.208.227 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="GvFlc/eV" Received: by mail-lj1-f227.google.com with SMTP id 38308e7fff4ca-2ffa3e8e917so67315351fa.3 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=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=NDLmlhfFf3fKmWcDI3ja5XlaBhDY7yQ7y51lLCUjcJ4=; b=GvFlc/eVExxzD77pgreiWaDXtUAgGU142RVCehNvGc0t4aDDdxIFVb88ix1QtkxYvK 696J2bvfQKFeEAcuANqlUOjuXJlRd2Mud49J0n5Scw2U/pfAu/yZggLyZVxGHSrNsoK5 pvYA5UAJhGgLlQeWFjt0X2m8MMHaQIIZfHp7GHketMHBUEGgp3bQ9iVhVozj5TvF/tSN hDotuKg0s5R91uS5smnboBCAQRI3UbErGrGQnHen9rylmsFhdZKAGjlorhFVlhltmfDK VCJixSdP0Nq2/MdMnNsBcdrIB5E/viMmY+jKTwLB7rOO61cs+EAj8dS3VrC3hsHaLTry +hbQ== 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=OE80oMiyYj++YAKS0xZtOB4I53Wb7n/DaRbpQv5OAq6o3ZDiLrd/GkiLlJFVhUYtze 0YY4u9hlFtNugoozZLaMzoh6pdck0NqD/5+xNw24IHNC2NPWx8xBYOiePXNzVemBOEmW g8+D+W/VvwsP0mLCXJWzFbm2+h4WhHhcRsPsQxANOIQLSMCF5N6eR8hR6ZaxSlYPAqql 4ZOQBmLr0wLaNmoHYOS8zjcn72hNd+bP3iMbCm/HAtyTWbiy5sotmXYxJ0qj+kHmzKgg zdlnVPHCrPv7onngRnalpFlm9XzhmDvh+tJgwx5kmthz9h4H3qnAx60RgTyy53AxjH5b hLTQ== X-Gm-Message-State: AOJu0YxXwjGVhssw4iPFfrFWbfvp5oATzNN4TVyyAnk784Coq3vVvV/B oHkUvtNwrKmyjUD17ib0MP+K4atg5K1dbZdA/yPV2Gu5E+BG7X97A6RjOcpHNwj8GIL0Hbb5BKK 3NtUnWAnJQDESLq77EPAnVsT/MnG+tOcF X-Gm-Gg: ASbGncsux5bl+ZhJMRe2KMx6Iq/RM8WjsstAP4MfFh8sFakmMmIIdscLi8J2BJ5NhAo BSgraGOpitNpPQ0WevZ3HBV8KFTnaR9H5GTRgogehTjNllXpiJ9mqojz2/R0in/fnN/wBGzadzi Bu/cWFdnOYzCcUHKV+mwmSyx4VtL6IPifhHyTTTFaRy3SSinOykm3L6yzzRLmFYZxSnuknaL8gD oDId5F7Dm8Tp90Pc8u8DrgfkhkyAfybMMUfHTfkdELxUY72X1EjpLa5Qzxo0gK9tg== 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> 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 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: 13886895 Received: from mail-wr1-f100.google.com (mail-wr1-f100.google.com [209.85.221.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 9CA201EF0A8 for ; Wed, 27 Nov 2024 11:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732706124; cv=none; b=oi1N/c6hjbSkZoNe+XAmKERESmzoq0+iCVUOHkfc2xincAAeSGNxHcU1O1bWbBJmvMt+obAa+UFW8pWAmNBLyPbDeqgPy+tRKsWkfzFpLB96HAkYKnwlpzVjnpe8Ih1i4azhhui49KNeD8Hs885nCAt4hvwLrB17b74EshAII58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732706124; c=relaxed/simple; bh=PK2PHh+2gJf3de2h3H9Noa2ztPJEtrgRbPaRX2eG3SQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HeWzPoOusZ0eRtc4aBdkDVPn3nMPHeWsnE7TxQDWcJWIpKhO3bY9P6Hohcgq5cxZZLYYMmPKI52W/ozk1FMY5yIYAVIlT/PWmnCLnqYJJ5ZqkvBAOZX/5mtFGf/o5jDkml+c0IX/9c7HvivazAaXzIsmTCyXxpJHMdaJtgXFAg8= 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=Srf1O2gR; arc=none smtp.client-ip=209.85.221.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="Srf1O2gR" Received: by mail-wr1-f100.google.com with SMTP id ffacd0b85a97d-382442b7d9aso5048582f8f.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=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=+2z95vIVxpdoEpIHV1Hs2li8opRkM10lvZmaKrYhPuQ=; b=Srf1O2gRn+t2ltotUUHoW7a4uYg4cKjXRFB6ynUWmDdhQW3niqNk4CRiqn90Og8hK7 GjAh/x59oPmuPJg0b36cdDyqVh/DyQkfcfrG3qCXd4QJcKMDH1LnD8bH/qtmBvdmbAP/ yD5fFybx46GusOUmb5erxw1qvwfJdrJ9M506Sf0K2tLDtXtoaJndYs4wgU/7TJnXzcG9 88Ar88GoRZD8NNubQWvazv4wLE+KxAlLja1xMkoqzvy08eyKasbQhGmpHhGiQ+Z/pLlQ 76tobu3r0IDKOU6kQ71R+euauxq4g2HuNGDWl2tJgkqnRA8qTaMStDFjtoZVDkHDRf+G /wZA== 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=dISz90JB9Ev8TG9fsNhK0ThWKaEp2JNghO6mdsz7LOxRThE+c6wZl+3Kpt65dqlcqx Hw+YsAg7LdjDk2VzzKgytvfJPZlw+CFijJJXSoGpBxtLdqXF6RsfHoPDWZpPxb2BL4dS 1izhdzsSWT0drXyiwiHsg6msM1U92ASHaRO/UDwKKxITkPB9l9R49CeqeR0zh8ORjb3u hxuZfsnYAz7kZclDO40LCxBRaXw0S6v9F/8S5ob4PdiyT9In6BVfK5UGhzrfik6xRk1N U9zeDCXpdpiNj34kVf4lJNoLo++CaTWs/p0DVRdqHLc3nL9uzFhtIOdlOpE/9OTep7pY diig== X-Gm-Message-State: AOJu0Yxt39MXLJOwmeqWyA0UGp6t+2GoqbvOJ5/3MT9G1CoG8zaPDUsi crQnjYDCkYypVA4mBwREHU67hTaZeEZegICKd0rBvjITaV3aVX+dsmGtQN0gvPdHYAGepg5e9A4 P3yalGCsLc5G1lxt/rUU6zV1ocknlfPWN X-Gm-Gg: ASbGncuRJFVho2isqAgn7pX449j01c9Jc5I9a73lFYeuaQcAjAeupL2Y23xTgdW6Hh0 wF1ITRy7VIyy3sTfOQkFr998rgbo1NFHdfkMOENXOgRzy8bom4MyT8d1ss/cI8fFeOHZaV7DB7e rFH/xdOLu91wzOzVp3+Ykz25ROCymzO9hbBUSPRaIxCdxSNFGQ4qZnX+jxeWHNasyZbrEVskSxr BRoVCAGHa9zfOpWgMpC0Jv0kEpVRWm3byHnQxMxG8UhgxD2riWB0zy7B67YbZasxA== 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> 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 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: 13886894 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 BC62E1EF0AD for ; Wed, 27 Nov 2024 11:15:22 +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=1732706124; cv=none; b=jkaWaQWUyL9lBVBJRbvQI9Iiqf412WipJSg8DZRZ+aSqKdut92MO5d2TD6s+njpW2/ZCdliGjVv0PgpckyMJFtFiXlozGCFjw4MHkXOkX09QQUzJqRHiMg6E5QrRYNRNbVK5ChN62CiQWc6ubxJIv2yu8L/I6zWEjIc7fW1FbBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732706124; c=relaxed/simple; bh=6GnAB8AluBnog7NYl4+hJYVAAOZJGkmDUBrswi9xVtY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hy2yXWXIq+9eWWh0s9VUb9NDzehkabapEPUYXINQFkdxgZEOJutzhZu2rSYsxqLV3lZi3G0LIWgtrvdlujEr/Zaga7OXYMtX664YcB1ZJiKq5nBgm5W1epMUeozdNSvq+5575KNu2bkjqdTh6Bm4OOg5crAW1JzEbq5ODoMBQbs= 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=AobZesyZ; 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="AobZesyZ" Received: by mail-wm1-f99.google.com with SMTP id 5b1f17b1804b1-434a044dce2so33469075e9.2 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=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=E8u/tqgNbTDWlnzWRktGlQ9tYzEXbqX8e0KFyaCvDAo=; b=AobZesyZ8E7j3C71TYrOJAH7NDf1o5LrcepcRO3w580ZEYfIdebIP1hP/KD409sMJQ NfiWVntSB5ezBYpHSgfvJTVL5W8W4b3eylFzL4hCp4dDlhPZnHT5gjTh9IXr5BjZHs6+ LWdEaVJdSg4lbjuk4lAO4bh1lzdf4Sfh6KrF9kSvQgLf0lHfGo61tepnt9aFoDtSk/dP GFxxYjBCUDa1KwRzJk6OhMQipu0x5I5De+oqEZMpCvbX46jUpS/klBappqowMNEz7W2h kS/PjpDSibO2uhM6jtcfUVu6/g5TJYnAUcIZIEtikiTOFz5bI3kt/1ITh4b306OLuNu6 M/xw== 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=Gntj64OEKQcwSvpFt0z5OGRF7E0T3XCyjLMRgiTJxIxAq9D6RKWKIh5t4Cgl2rrEQP vl9622Zg+CuISqVH5jF2BHHmbBdiiZ60RFmH8k+uVdz+8SbdmcQTIOwX4x+IR/+RIAjm 71UorK6RuVrBE8IBGOlF+xVeYZvtH5w2LPR5em6KVfj1nr5zO0rCQtHK8RAJ09fRiith /CpOhkQyZ4tecwPfivKNhPleJhLl3lOVTiHKTi/6SYAJClFpcFdVYQdKd3gojaikFvs5 XPaGdlirqh+HF9RYSgg0qhkSK+IpWixFgi1Fvnx2yEd5Um1j/lQoWwjKhbvfNiatwXeR JldQ== X-Gm-Message-State: AOJu0Yzxll782LGGA42jVMwx/D+jiU1u+AlMdooBq6YF4Bo+68JFju7f AzoG+oEQPv3XQHQbwYw8BxnYK8LPrCW2ah7N2wOfy5L8FqRAkIHMnec+5e2iNZzHCuFGX6im/kk D9RP96Y3lxSJFDKa5hJu/mPzavIzgnyrk X-Gm-Gg: ASbGncuRskbK06sTixMHpJjzLK5b1N/d5nJ8xzh1FrDUCH9r+kFS7OAvCH/w2+gLPTY Jaho8bjTtJg6SVEprPyu5K+KssgulrMAZn1++ZZ9nt7rrgihFU8VEhDIG+vxyyK+e3vNfcdDCf1 WRohDOGpK2ZDbL9D62rLmDwvn0sAEG8g78xaLYFFiYGHKLCu6Er1og6YSZRar1uFNf+4G1Flc3u WqWMecqmlJGuUwa1oFnqi7jfV67v3mRXNjQSZU4xW2lKwpzSASZy4gW5R0LIaDVGA== 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> 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 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: 13886896 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 660781E1A16 for ; Wed, 27 Nov 2024 11:15:23 +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=1732706125; cv=none; b=uRYsu6080FaWX4VQWTNTJJqAMVJ1MT2R9hZSKp4u9Br86KE8RWe7vaLtufwkcDxurAUv/k3AMWWoSCKqThsz61U6STh2WNgm7myrZ81/Gobs0rERWviS5YUpGSSbDyhBeW5wRD28kr19zu9X079ccGs8w8MSBl+DDTdKhHMoqIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732706125; c=relaxed/simple; bh=2NOMVN6qGPtVqsDC17KQHFq1EI6laocjfEVCvcsOBBg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Sp57WpJl6bkYgTetQOJU9Yuj47B4C+Rmk5GxH9q9ao6case7sq8gmUZeElAjesKeZe+aOJCbQzBtFAvleDOBTi/iUS0B4cjxRLTNjIoBRzzc//CkD+10o9m//gvVYCziK3sLZYqc4ogymAh4mqGB82+QJBmPZXKcLY4GEDv4Z2I= 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=ZYOOX5Y+; 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="ZYOOX5Y+" Received: by mail-wr1-f97.google.com with SMTP id ffacd0b85a97d-3823cf963f1so4236213f8f.1 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=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=5OeHJ5VmorUPFsKfp3L5ZEPCj51aQDOtY3qfB7PKLqU=; b=ZYOOX5Y+se1tjjUYxEZHrGnY/yP9C2leTZbrej6Qztnuf88JZLSq6jFxCEpqfK1/KI HAsiLtv6QOtcmebU7wmnRx5SaxTVnyrasAw1siS0RAZFgkQrRSLsU624aD8HNa0lnxtO rI7A/8zC+6IonQy73W68FpT02Ol5uRLgt7clK6ZBeIRK/yhu2YS5JWSJ2bctiBDfjN89 pltH5kCFbfc3GarmzUbPr5JFdJx7PoYvE4jJ3SqZX8TkRSBtBYCQaXtwoyZfwZwhMqru GXWTkcJhMQZ7Mp6MeTm7YtiU7/ftN4OKGzLar9kfpbxvRXZ9LBRwXjOmeNTbM5pLrAYn BFCg== 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=HUILbNc5t1c1qHt6J0OMteBpg+WvSEztbWSilsVMNNWRNWQF7pApWYH2GFD9tzdFaZ WoFgNoRdEEHwqHWwa2GBem5FoOstYYtgOZ57J2XmEvcQndYDfs8yTc7OHcmG60xS2cVc /+F2N6usSys1eVwPg+XnrU5o+H4IxYj9cg+KtOGH0zRNSNSBjabMh6tiJGpzSFctFE6E t8jNBx8Xxv41PrGMowk4vJMVLOxayDfrLvLhADTDpPjRJkUDBG1ukP7bEcNS0jFA1Tfx Mxl0WoUmJ+EO7wwsg1tPfEsSeDwM/qiIz7g28kt7C82P7Wtg7PeL9fIbgGKifGQ9Kt84 YgbQ== X-Gm-Message-State: AOJu0YweNsu82qbp5gNJo0FZ9sIw0yaa6eDUKCC8qjEeewoIHHeQ5Fbs O1BmgvT6PDsIcKpiXR8bQ6DbqrNniLGZj/nxGELoWWQ6pqKTIshdgyf4RIqptpc2O/l6Zl6Zoeh a/LWel496P4PhkKUjuG2EngHRQlmA9/OS X-Gm-Gg: ASbGnctOvhWr/Mv9rDrdQFNMuA3jgzi7ety2q2wDw1F2w3tY86wHOsw3kzMd3IM6uTu 6U6OgfnfZOqrdl1CAWfwh9rrvHL/Hq2ec6VIhVwjsEdumKUAoFKZztGtF20yiKjLkiuU6prQ5S5 zOwjoLulsoEX+STFX/K4pc+BP2/s0jMtJhMFAb6GDXFqDkCprnHPiQVYDD+fxON9jjBycgAvBkK yEGwloWXHwH3ElN/6NRNM1auYuxRBQtO/YVIKq5Ia6+GyNvU6WYI9n3WvzxK/meyA== 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> 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);