From patchwork Tue Jul 9 08:38:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changhuang Liang X-Patchwork-Id: 13727440 Received: from CHN02-SH0-obe.outbound.protection.partner.outlook.cn (mail-sh0chn02on2111.outbound.protection.partner.outlook.cn [139.219.146.111]) (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 4136D154426; Tue, 9 Jul 2024 08:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=139.219.146.111 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720514401; cv=fail; b=pobBi2p5t5pF+vRtR2wCE3vsODAINoCwoULc1JsOqnk0GZyTWrtSSDtqzz7QLf1wZuBX/cn5Bzet4gYaeOoklAnsw4K8u7RZw/2KeLbWmrnalk1IIBgCXcMcObPnbCLfkVKmxkEAGZCsw4KZu8+Os/8A9vjshl40uhiRYHZWLvY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720514401; c=relaxed/simple; bh=0FDg1Dj4Neu94iKgf6Vq/84ghq2Tgp84xqp4AdbB87o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=TnUBfj3HV2QJGAZiRXD35wQZCjJagZwpCjyJmwJcGBWyuFGVj223+deduxiaib7Zgq02qoruPVjCIs8nMwMHT5HYRbCFtnHvYNIzaUQVkXslDpYIBp7F+TcNtkJlJr0Nn+k01rmQkFat2R8AS1vAyV2K9Zs1sBs5jhK2xwh1dNA= 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.111 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=QrHot2MMCuKAEFCHUn9WpF7+MxpxfrztbppNDJ2qjxJLrJXOUODzFLPcfssMinY5kz6EDJeT7XtAXrz1km2HNV/ZL/kzY2DlR7C7jHpKN5YKnkSdsPHMRVXBf7oS646xh4bI05xIarrYv9MOdyYbdAJ9d2q6KN30XZLxVsxk+0Z1wBkKlzsKsEtrn1JMrPfqxPSvGAxg1nMcGU1Nn3GW+IO9hK5tAvfRbQSKzS19Gi7UrhT8iLtyThf6n9mMAMRv57cUEqgk7Od7t69VJKiFMQaZfShIGxoltG0mseUq9Kgqwpn1AiilJFObynkmsr3kazWou2EdC0SvLmRrsF3dUw== 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=Lyzsk52CyY0SmKnb/sYckLhqNCS/bT4cukVB1N2p1WJD+EUE0TOFaDPtYKE47y3ddAcqQ4Wpf8KtRO4Fr/FrDqS0BOSRGdFNOcpXqLvbhWlb9rfKtUrHwj+gDKybnyhCAyeS/4sEqIfHmnF4Hv3nFBJynLuyap4B3NPiJsUoVJRbD/OsNWP2XmIuEd8hA8pv1T3f4MEI/p7IzmzoYQog/dJvVWcXZfkpoBMZ08XL0bb7vsITeHb+KEgQosGeDEU/BPh647ov4nIDPuvo4TLGpW9I1U/Cx4dlC41qoC0zz+q3G75CNCqp0P0MfU3guRIA+X9z0/hKrm5/Lj2ovr61Yg== 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 ZQ0PR01MB1302.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:1b::9) by ZQ0PR01MB1271.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:18::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.37; Tue, 9 Jul 2024 08:38:38 +0000 Received: from ZQ0PR01MB1302.CHNPR01.prod.partner.outlook.cn ([fe80::64c5:50d8:4f2c:59aa]) by ZQ0PR01MB1302.CHNPR01.prod.partner.outlook.cn ([fe80::64c5:50d8:4f2c:59aa%6]) with mapi id 15.20.7741.033; Tue, 9 Jul 2024 08:38:37 +0000 From: Changhuang Liang To: Mauro Carvalho Chehab , Greg Kroah-Hartman , Sakari Ailus , Hans Verkuil , Laurent Pinchart , Jean-Michel Hautbois , Benjamin Gaignard , Tomi Valkeinen , Mingjia Zhang Cc: Jack Zhu , Keith Zhao , Changhuang Liang , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH v5 05/14] staging: media: starfive: Separate buffer from ISP hardware operation Date: Tue, 9 Jul 2024 01:38:15 -0700 Message-Id: <20240709083824.430473-6-changhuang.liang@starfivetech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240709083824.430473-1-changhuang.liang@starfivetech.com> References: <20240709083824.430473-1-changhuang.liang@starfivetech.com> X-ClientProxiedBy: ZQ0PR01CA0031.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:2::16) To ZQ0PR01MB1302.CHNPR01.prod.partner.outlook.cn (2406:e500:c550:1b::9) 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: ZQ0PR01MB1302:EE_|ZQ0PR01MB1271:EE_ X-MS-Office365-Filtering-Correlation-Id: 7337e719-7f54-4e8b-c18a-08dc9ff28727 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|41320700013|366016|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: yeHI6/WXXV2HG1dOqFy7lwDILtUzd/WKICIqk5xSQ2Y4naWo01xW/Mu7YfQ15vKbPsJgwRLMVie/rDNuHbmNuD/L1se0xxYUc7sdWY1iOQXrUTfnjq56gZClQNLLZxYctWGTB4mvbXyjF4ZzBWc5jYFLpU090U6c1WZnHve/e3bxDCrBS9QtywoG6MZZ2AbI/1/KOacYDlSKx9vS7EJwQw014tKdso9+Io25yevTaxjH+e27FXDk1Xxn0crZnzj9ol/paJRlVyIfqqlPa2aoHa/+UHAhQ+GnGq5f0OBOyioVp2lxovNNcsXqM5RC8GgDccuI0TePpmw2dRAyw4GPmcp1JoUgmUNME2LSBqTPEVSQvWxZzekZqYaLs/QSFcV55+/aID86rc1a4ycSP/C+M7ToP6wbzRzk3PgaCEz4MHreeuK1ttLB7e7raK8ts5RS71nNvUxb9kAiK3NKXaefoVYvglyG+L+pQR379BadbIO5Ce13I3Q0RkohffZXerCCeMFFSmGkWyHW6tn3gPScmkhoHhCw4kmq8D2noyKmFx1qSc9XOepapQYZ3XEBn3MLXOgmz5kHo4hKpfPTe8+gOdyKOsKnv1HK5J9zXixJ9ISfCzUmsJNeSfy4PqJjBoN8 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:ZQ0PR01MB1302.CHNPR01.prod.partner.outlook.cn;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(41320700013)(366016)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XeAeDfOWDP3ODFJcdEjZ3qTs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Bu1mwA9HabRqChJS3Vy+j4dGEBtEHwtMhQG346J3Cg6ut3+B71/vot/P9n/ajj0nGSTxi+jQZcBJ9NuJU6EE0ja682RBSZ1io6H9vXc+sAESOzd3Edxy7sSuxrpoQjF4uzIh2ZsqDDBDorMGzIKji4+dR43lcUXwSkFNO7IOwfOcxtWMVJ1oFuLfYo48Pi0LWBccHDUrIFXGoSa9R8r4A8Oce81dZMe+q/8xZVNB6iRAy0OLUQtQLFQr+uYUQ74VDtDym29xlBDvu8znsqghN+QVtRUDFlFzTwCvYEQ1z+cElpgJnEguC4T0HFEYZsLd6vLUXek1NUFwrKK7KKij7TNcdM5aa9uO8t+nm+2r+1YJsCLnFm7LxNdSeJDLTF6Q9aOMHh5bWOyXdyREQzCr/xJ/mzLq6srSDF67BydRigT7HU0iCfQ/sBgX/MBXTU1qyaEkXpP30pTwK4PPLhY2qTBad6hU5AeUVpOLY2lRmwk+6CwfpkFAsu4WvvYnCYz0CDg+ArZAExcdJDJC37by5gY0+Yuou4= X-OriginatorOrg: starfivetech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7337e719-7f54-4e8b-c18a-08dc9ff28727 X-MS-Exchange-CrossTenant-AuthSource: ZQ0PR01MB1302.CHNPR01.prod.partner.outlook.cn X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2024 08:38:37.9544 (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: bVJn9V9c8i4vMP/mGzPaHNje1YtvDeeP3GL1u3Zwefol+f+00auLdVEhRstpeNQZrhMxwsJVDTeegBAUtvmqLIXTpD/4al32wPx/vDUA+ihx09zxWDtJTGx2kFqZ5PSt X-MS-Exchange-Transport-CrossTenantHeadersStamped: ZQ0PR01MB1271 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,