From patchwork Tue Apr 2 10:00:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changhuang Liang X-Patchwork-Id: 13613637 Received: from CHN02-SH0-obe.outbound.protection.partner.outlook.cn (mail-sh0chn02on2136.outbound.protection.partner.outlook.cn [139.219.146.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 229175A4C0; Tue, 2 Apr 2024 10:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=139.219.146.136 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712052043; cv=fail; b=tyKtjPcTgEU1Y1zpGQcoN7dpijAUwDumUTiQ81aQ5tkooFFmhS1bysPElvwzXmJe5G/cOfPcv6SqkYSIklemz5KHXphKV2J7dOG7blmEzWUJfIXgTOyY3zJMIe+oDbMo7sLkoFRxv+yND7SvmXEbYsFtOh0Ln3Y8Fp5IFrTQ7v4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712052043; c=relaxed/simple; bh=0FDg1Dj4Neu94iKgf6Vq/84ghq2Tgp84xqp4AdbB87o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=cEQYTOvs9mklFVy/fZ6KDlh+s72Injf/3IL6IpiUE3/G3z8ikMyJzE+/1Fz43MXUmGOR8DzprtukLAunb4xtqMdFDQBno+CBXrXTJ5HyAOjAhfoPGvW3bDjXGuhut7/zrxx+5NAYfXP7y3EWmbQA3WaQsHLYAw8g+C/qmSGHDII= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=starfivetech.com; spf=pass smtp.mailfrom=starfivetech.com; arc=fail smtp.client-ip=139.219.146.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=starfivetech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=starfivetech.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SiSaYdrGZsfERfC28g9figfyDzXVbTLVzsWJX6wagjJjm8HENmpG4LNVft+vGpBs74vkhWyLX3jI/jmZdi2B3yvep9WxZlEreh1futbXHh4aBLC22RXGpWsX09xCGVC/QTfuJ/qVCWCrungtIbtFZws5W7XJaCSZxwjqZsOmXmWbSdcDptGITakBpR+2gT7B50UPX0O1AiNr8EkEj/xxi4tiLkQqgU6ientqK26/o6yh5QL+6rTjefD15MiALN/1izrGtsh3SebyLPtHYHiH6pTzqZT/sQDsFBWwQ4H8+AeXv2kYoifqPXxWAQRT56THEboD4pn7W1qVDFhQVG4PCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=thBwTr7qfYGt42akuCR7XIcF6Ei8+yjyc2yt/SHlfyE=; b=LRybeGzZRPgJr6s6KGRosNmMoEYZvH0Jecc6j8L45xBHAGRi+FYtTQMZJ2sXZ07pd71i2Td9jWkdONyOt5lkvS8lXiF9qPBvba37AXJpqb++bBIasIvxJl4Gh/F9jFlRJetLMmbaMH3x0y6mPREsunGijSVtRG++p+djH7MYKnXiQ3H0tRMBKwSn3eaiJkPxccYoI0LFlhcMfa6UcTCR/0ScfqibpKPr8iqRp0NRrTDRbugpXL2ST5F0GUAiF+mSCvKHDZ8VRUMwzqecQ9gbA1D2V5ER2UmmQbfw069sJfxBBhqvAEXdO+o3A96Ghq0YoBJx6mk4Px9FNwGpDpjn6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=starfivetech.com; dmarc=pass action=none header.from=starfivetech.com; dkim=pass header.d=starfivetech.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=starfivetech.com; Received: from SHXPR01MB0671.CHNPR01.prod.partner.outlook.cn (2406:e500:c311:25::10) by SHXPR01MB0669.CHNPR01.prod.partner.outlook.cn (2406:e500:c311:27::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.40; Tue, 2 Apr 2024 10:00:29 +0000 Received: from SHXPR01MB0671.CHNPR01.prod.partner.outlook.cn ([fe80::b0af:4c9d:2058:a344]) by SHXPR01MB0671.CHNPR01.prod.partner.outlook.cn ([fe80::b0af:4c9d:2058:a344%7]) with mapi id 15.20.7409.038; Tue, 2 Apr 2024 10:00:29 +0000 From: Changhuang Liang To: Mauro Carvalho Chehab , Greg Kroah-Hartman , Matthias Brugger , Hans Verkuil , Ming Qian , Laurent Pinchart , Nicolas Dufresne , Benjamin Gaignard , Tomi Valkeinen , Mingjia Zhang , Marvin Lin Cc: Jack Zhu , Changhuang Liang , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH v4 05/13] staging: media: starfive: Separate buffer from ISP hardware operation Date: Tue, 2 Apr 2024 03:00:03 -0700 Message-Id: <20240402100011.13480-6-changhuang.liang@starfivetech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240402100011.13480-1-changhuang.liang@starfivetech.com> References: <20240402100011.13480-1-changhuang.liang@starfivetech.com> X-ClientProxiedBy: ZQ0PR01CA0005.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:5::11) To SHXPR01MB0671.CHNPR01.prod.partner.outlook.cn (2406:e500:c311:25::10) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SHXPR01MB0671:EE_|SHXPR01MB0669:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c200a57-f78b-4c3a-80c6-08dc52fbba13 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A1vFuUABxnhbZlOQZujFOz61v4zBoV8kPfZiIi2+DQjKurR2Z9EKRPmFwV5vHk7XZGjPF66lIqbHaxLqusHplQFMfquzzDRCSfOMAh7HLeu+6E4mAzZKNcuhZpcY4S1EGJX1XSC7tKgro/OXxuLbHVJ1JpYpHFbt19dXp6GYmVjbPPYVjSvD2bidWIGLiCkRokO8tKgbXhpC+ns/I3HrmSLBOpWnwbSSb8hz8nVZXX3+MjYXH8xK0mLnROLTVBC2Be6YMMGnVc/S/02Qg9ZzXxR0X/zOVwoLi8pw6/rT5DanUIw9gFHAFhqr+AMHeVqlBgVGKwNfomU5EJ1WxrfIXuCZcKlH27KH8jeE9/weINqN0szpKzIOLG3+1gXevCBz8A2e7Axjn6/NjEcI84wxUaerakyjpd8PC/4az58WFpPof2az5aqf+amQtXhwEsCL4tnAG8NDwy8lIB0MAoxRAvAZco74E+lvUiRj0/faGVamjuyjYBcul1zsJ/o50otFplF495BuTorBEbyIOCm8riNLxuqjPwyPzFTwRYbmpdaY1/V8A3jkZz5xYjGqXT6avqsrmgKvE5ndUVVW30+/4YHj6FMqwGyz5CyGpQrRf0TBXvfZe0amacWVZp8+TpU/iKcLYhRmA1E5HQsS9rykdQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SHXPR01MB0671.CHNPR01.prod.partner.outlook.cn;PTR:;CAT:NONE;SFS:(13230031)(41320700004)(366007)(1800799015)(52116005)(7416005)(921011)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: opvNdLQ4q/EcEMbVgr0Hjcydx2SqeGqur8jLce6WB1U6LgYPHddRuFLWU+TR7mxf9aur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a6co4CLpGg+hPa6u7/aGi30miw2m1Sl1WTQ7mG6yv4jzrWC7rR4AxFqMZ4mEMKdKHnW/bjkirmdTFBJvNHhnbILLUPYwnfb/8vUQ5qfhlEaXJ5yfSyWHKzOHz2vFhICvbYCjNWwu7Ckm45P4mqIjvs0eElu8TQNsxqNguVT/fJAHXZ7FbM7ambGD+/mmHZAzXqMbAWBEBYshLw3CUOpwk7a4NzQFcgeQXRUS0qof56AorJFLOM2pE1n8NQ5EwW8XkrcmhjAabylYVncTtqORNPllfKrI44HpbkVrR00wOwVe4jHBpKUzHVw/WYZQR5OrQl1rdiaRmMGr7fu+C7y/uyfUZcC6v4NYjtqW9F7UFsvHqGCl2JIjcpBORyKQrnMXxSZh4M8ZrmpcLfJ2iSm3kOTQh4UDFgjuNUrQslgpKgDGYi9cwL/JH86zjvaVPC2bzkeQtBXe8OSEsam1BrylrXUCrH175T4MMZF9KlE2vKIXDCf0= X-OriginatorOrg: starfivetech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c200a57-f78b-4c3a-80c6-08dc52fbba13 X-MS-Exchange-CrossTenant-AuthSource: SHXPR01MB0671.CHNPR01.prod.partner.outlook.cn X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2024 10:00:29.2455 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 06fe3fa3-1221-43d3-861b-5a4ee687a85c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WKTcZDL4WKTTOd6QTfdyXpx2eS1j1cYnFqOE9qmf28dtJJ2qAc1L3/TED5Y1+VEOrarV3BxKAIimU0IfDq5ZgFtD35NtQeqnxVHjKtqxnQpOPaiB2r4nIMyy5oWfitmB X-MS-Exchange-Transport-CrossTenantHeadersStamped: SHXPR01MB0669 Separate buffer from ISP hardware operation. Convenient to extract the buffer be a common file. Replace "while" with "if" in stf_buf_done helper function because one interrupt signal only handle one video buffer. Signed-off-by: Changhuang Liang --- .../media/starfive/camss/stf-capture.c | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/drivers/staging/media/starfive/camss/stf-capture.c b/drivers/staging/media/starfive/camss/stf-capture.c index ec5169e7b391..494e56e731f0 100644 --- a/drivers/staging/media/starfive/camss/stf-capture.c +++ b/drivers/staging/media/starfive/camss/stf-capture.c @@ -368,7 +368,7 @@ static void stf_buf_flush(struct stf_v_buf *output, enum vb2_buffer_state state) } } -static void stf_buf_done(struct stf_v_buf *output) +static struct stfcamss_buffer *stf_buf_done(struct stf_v_buf *output) { struct stfcamss_buffer *ready_buf; u64 ts = ktime_get_ns(); @@ -376,27 +376,27 @@ static void stf_buf_done(struct stf_v_buf *output) if (output->state == STF_OUTPUT_OFF || output->state == STF_OUTPUT_RESERVED) - return; + return NULL; spin_lock_irqsave(&output->lock, flags); - while ((ready_buf = stf_buf_get_ready(output))) { + ready_buf = stf_buf_get_ready(output); + if (ready_buf) { ready_buf->vb.vb2_buf.timestamp = ts; ready_buf->vb.sequence = output->sequence++; - - vb2_buffer_done(&ready_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); } spin_unlock_irqrestore(&output->lock, flags); + + return ready_buf; } -static void stf_change_buffer(struct stf_v_buf *output) +static struct stfcamss_buffer *stf_change_buffer(struct stf_v_buf *output) { struct stf_capture *cap = container_of(output, struct stf_capture, buffers); struct stfcamss *stfcamss = cap->video.stfcamss; struct stfcamss_buffer *ready_buf; - dma_addr_t *new_addr; unsigned long flags; u32 active_index; @@ -404,7 +404,7 @@ static void stf_change_buffer(struct stf_v_buf *output) output->state == STF_OUTPUT_STOPPING || output->state == STF_OUTPUT_RESERVED || output->state == STF_OUTPUT_IDLE) - return; + return NULL; spin_lock_irqsave(&output->lock, flags); @@ -426,37 +426,37 @@ static void stf_change_buffer(struct stf_v_buf *output) /* Get next buffer */ output->buf[active_index] = stf_buf_get_pending(output); - if (!output->buf[active_index]) { - new_addr = ready_buf->addr; + if (!output->buf[active_index]) stf_buf_update_on_last(output); - } else { - new_addr = output->buf[active_index]->addr; + else stf_buf_update_on_next(output); - } - if (output->state == STF_OUTPUT_STOPPING) { + if (output->state == STF_OUTPUT_STOPPING) output->last_buffer = ready_buf; - } else { - if (cap->type == STF_CAPTURE_RAW) - stf_set_raw_addr(stfcamss, new_addr[0]); - else if (cap->type == STF_CAPTURE_YUV) - stf_set_yuv_addr(stfcamss, new_addr[0], new_addr[1]); - + else stf_buf_add_ready(output, ready_buf); - } out_unlock: spin_unlock_irqrestore(&output->lock, flags); + + return output->buf[active_index]; } irqreturn_t stf_wr_irq_handler(int irq, void *priv) { struct stfcamss *stfcamss = priv; struct stf_capture *cap = &stfcamss->captures[STF_CAPTURE_RAW]; + struct stfcamss_buffer *change_buf; + struct stfcamss_buffer *ready_buf; if (atomic_dec_if_positive(&cap->buffers.frame_skip) < 0) { - stf_change_buffer(&cap->buffers); - stf_buf_done(&cap->buffers); + change_buf = stf_change_buffer(&cap->buffers); + if (change_buf) + stf_set_raw_addr(stfcamss, change_buf->addr[0]); + + ready_buf = stf_buf_done(&cap->buffers); + if (ready_buf) + vb2_buffer_done(&ready_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); } stf_syscon_reg_set_bit(stfcamss, VIN_INRT_PIX_CFG, U0_VIN_INTR_CLEAN); @@ -469,12 +469,16 @@ irqreturn_t stf_isp_irq_handler(int irq, void *priv) { struct stfcamss *stfcamss = priv; struct stf_capture *cap = &stfcamss->captures[STF_CAPTURE_YUV]; + struct stfcamss_buffer *ready_buf; u32 status; status = stf_isp_reg_read(stfcamss, ISP_REG_ISP_CTRL_0); if (status & ISPC_ISP) { - if (status & ISPC_ENUO) - stf_buf_done(&cap->buffers); + if (status & ISPC_ENUO) { + ready_buf = stf_buf_done(&cap->buffers); + if (ready_buf) + vb2_buffer_done(&ready_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); + } stf_isp_reg_write(stfcamss, ISP_REG_ISP_CTRL_0, (status & ~ISPC_INT_ALL_MASK) | @@ -488,13 +492,18 @@ irqreturn_t stf_line_irq_handler(int irq, void *priv) { struct stfcamss *stfcamss = priv; struct stf_capture *cap = &stfcamss->captures[STF_CAPTURE_YUV]; + struct stfcamss_buffer *change_buf; u32 status; status = stf_isp_reg_read(stfcamss, ISP_REG_ISP_CTRL_0); if (status & ISPC_LINE) { if (atomic_dec_if_positive(&cap->buffers.frame_skip) < 0) { - if ((status & ISPC_ENUO)) - stf_change_buffer(&cap->buffers); + if ((status & ISPC_ENUO)) { + change_buf = stf_change_buffer(&cap->buffers); + if (change_buf) + stf_set_yuv_addr(stfcamss, change_buf->addr[0], + change_buf->addr[1]); + } } stf_isp_reg_set_bit(stfcamss, ISP_REG_CSIINTS,