From nobody Thu Oct 2 20:44:48 2025 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2089.outbound.protection.outlook.com [40.107.92.89]) (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 38F3330F94A; Thu, 11 Sep 2025 10:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585368; cv=fail; b=jHZWlWNGh3YDUCCcNPFDtdyYJz4ML0RwWJIMcULUD7wpRM6BfvsFYhdk08vK01GlZaxqD8+sFZ3mX/B+R0xJl7yB7K6tp7zJsWeOn6Jt63oS9RRpVY85Ch/SXleMegz37WY4GH+k8WLEbwUCUrjam7r8KzgkZqWs32HHzJLo6wg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585368; c=relaxed/simple; bh=JYzHkygedXBa56AGC/7+Bl1vSwIH3/Rj/rK/ZL+/yg8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GAAZGps5QfbH5f5fY7OgSg2fppfaRy1eYmO6Qq70d3EDyI1tyk65R11qwC1uemPm9Gi3cGd8rlM1kjRf/c2IXuMJq1ahtsN83OA7cHnKLvQvN2ZEoQ4bAENrIOe4c9L6mgbh4Z/v3QI7A45wzX6AdzhlthxT2qjka5C5nXKek+o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=1imfEQw9; arc=fail smtp.client-ip=40.107.92.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="1imfEQw9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tmkNRuu9UZj1ofc9VzWn9FdLLkoEEFUSIsD/BppMi58k+TvIkOH/tBZqImOQb9H9Jo1Qj7dgPtMTP2N87eKMVLMfUTdBQEU3a65JTtnv4WKsPuqbccpJN3M0Vx8D/HIbG3U08kMvWVJYMP97Wt4RACPEu8G7BDQz7v23hERPPFNGS0iIC4gudQ3p2CmwhOA+a7QezIgJf10XPiUmGEAQWoRH8/lSov9N2YwsbdgpQVnUZfOkhgRoXjxWLWMvnnIvthof9SyADg1aYJegifmpTscY/G2Oubm1G7MOhnl6Bi4LuzRlzMfLDBgu8O9ZJz9/SntMrmnbPxLPzaw7oPsImg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=pQ060zuH9/cvSck7FBxtcklV9wOYJBzlbtOeiK/ofKI=; b=KPQlcocn4sZPgM/se8eJE9PdLo4ZgUUh1YMsU13f7fScngqYLje3sJwbtaMwqj/WdtQzL5dK65HWaX/Q40UCi/7fUgZlfT7oC9RfR0NdmtRibrph1UPADGXVrS7USIEqr6VVoLWsBSG0eOY1gOsppS+xZ47H9drEHchun8qk5ib/aWiBkyC5mRx2fMpCYqdPHwBkJGxHA1J1rCOJK6r24QoHTCXrqHLuV9EJuHizT4gsXVppbLYzBDUk/fnXDCoSUX4gH5HoMsl1mjNGNoLNKb+lr/FxfxxThWbVN0nNhGD1NPEZPM26ZwYJhWUnqUh17rlwHaQt98m+BXO6hy/EZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pQ060zuH9/cvSck7FBxtcklV9wOYJBzlbtOeiK/ofKI=; b=1imfEQw974T+ll08tURSHswMKT2tFQmBx1XHy+8H7dCYfZFJbjO7Uv5THL1No14bnImvPAYk5GW+AWFMHbwM0neVxpspIpnJvymDgDL/XKG3NWV3A7eUohDrbqCm1lcFvkTWzhXUd6ET61DMXeo2m5GVB7YJV14rTiUpMKk90H0= Received: from BL1PR13CA0405.namprd13.prod.outlook.com (2603:10b6:208:2c2::20) by PH7PR12MB7425.namprd12.prod.outlook.com (2603:10b6:510:200::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Thu, 11 Sep 2025 10:09:18 +0000 Received: from MN1PEPF0000ECDB.namprd02.prod.outlook.com (2603:10b6:208:2c2:cafe::4d) by BL1PR13CA0405.outlook.office365.com (2603:10b6:208:2c2::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9137.6 via Frontend Transport; Thu, 11 Sep 2025 10:09:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MN1PEPF0000ECDB.mail.protection.outlook.com (10.167.242.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Thu, 11 Sep 2025 10:09:17 +0000 Received: from 555e2b870847.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 11 Sep 2025 03:09:12 -0700 From: Bin Du To: , , , , , , , , CC: , , , , , , , , , , Bin Du , Svetoslav Stoilov , "Mario Limonciello" , Alexey Zagorodnikov Subject: [PATCH v4 1/7] media: platform: amd: Introduce amd isp4 capture driver Date: Thu, 11 Sep 2025 18:08:41 +0800 Message-ID: <20250911100847.277408-2-Bin.Du@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911100847.277408-1-Bin.Du@amd.com> References: <20250911100847.277408-1-Bin.Du@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECDB:EE_|PH7PR12MB7425:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c888465-57b7-463a-6cd3-08ddf11b44e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Lz0LVVj5oqUGgRt+OCGJR3FIEMrL7i98EhZbvJBkbc6W1DmkHy+3CyHHO255?= =?us-ascii?Q?pZs0g1G8fFF6GmKmCLjMeCWVawLYaMJii+Ny1708/pXrVm7gti3b9z89H6tC?= =?us-ascii?Q?6VTDx/36tng2+ieNlxftZxTLtP6xVuCh8KF+xm2KJvWF8EJFc4pLHYwVtPQE?= =?us-ascii?Q?Uhtos5QroafF0YSTDXhtR2xW014u/n1ETOxL4b5Ca/m54vQTZQcWHuSlF0yR?= =?us-ascii?Q?9FRD1cssEtSdY/z5IB4ZaIoxhgJ3Jxhn+dRSPNW+5GxLUmASa29w67bcAaPn?= =?us-ascii?Q?eOzRFsCUr0yQm7PTo88WJ36X5j/HAiH+uMlM949eG+hQaSEo++8t4/BIrARj?= =?us-ascii?Q?E7LeaCBhM6Pe+pSc49msRZOxkgmn+I2a/gmt8Y8g+0BgpNJv0oA6qxichajL?= =?us-ascii?Q?Vz8K2a2ZlEkx9L7kD9uoV8tk51CpVLHaCN7SAgUhNnDtgbwgJaLLHiTI4PLI?= =?us-ascii?Q?8STr+JaMUFXdQEAz1MwAi1RFYOVEghgwCelqVGjYk11wmQK5E11B1/7AFMXg?= =?us-ascii?Q?DjKHTuUHlFDpw+8tMeqOagLvnpfX9X6uoCKQHV6XXHekPL+qdmYMey02poW+?= =?us-ascii?Q?DwP7g/rQm0OA91FGGJ0kpJ3tiBwJFkxBpVWHUvQhrIfwHNiMC8zbPiWbSnpj?= =?us-ascii?Q?MAofrWBkJnRyAafdVCcQGA8Lssbg8XhHQV+PjWPf51+xo2keceOA//cgQKfG?= =?us-ascii?Q?uTrqqDBs+CjFGwqGluIoiFAuF3jRPHRW1alyzRk8hqLF0etOr+64l6DNzcrB?= =?us-ascii?Q?DBPMiYe78lWkm8LX9i9hKurwXqCZWMFC2tbUpQr5VjUEDX++7EcbPESDhXSV?= =?us-ascii?Q?8lMUBJVn96AE6bXggKWEUMRPww3A8eAAnQmSRfhoDrr4OZhHk/Iky8a3yseg?= =?us-ascii?Q?oMzahPXHdWHmyO9FmqMt/dUj6OHhfg/vMkibCUFIZIwPyjxl3RoK/OvTJ9El?= =?us-ascii?Q?G4NZpdgwMuuRof1ntuCyXqcbdI0D2VT6YoxmZ4WY8CXCUZmiwAusk7iGdQLo?= =?us-ascii?Q?ATSpV/JoQP5fbUs2bTBlPJpijqHjWBg7Ai8OCpfs+VIA8fOCcA4yScFJXlGj?= =?us-ascii?Q?2Kbcgv2MVkTLFpKMo45/97/WGlsVOogPt1KD9Llaw5mjhGbIMsltvgxtNRos?= =?us-ascii?Q?YWEMBSsP7k+GmpCtSEk/DQFi8taffPOiBxeceQmZ/80sfuoOhOBacUm4uuQi?= =?us-ascii?Q?hZJ9Zg3nQbWJ/xsPM10hN2Zqcd1BaeztwSBeJLG81HlL9BqyqWsdBVFWHx22?= =?us-ascii?Q?vVRLixxbFBckPyqyL+zk0agr2VriB1K8H3nJ2R6HJ9fUqCLZXvHHJYd56wZM?= =?us-ascii?Q?5pe/vdlubqEED7BfNZk/ajBMtJF332PwUiGZ/mKSaFf9vP/owTfOKil0M8/7?= =?us-ascii?Q?eVnpfYttfFOjvPkYl3jw9T9oGQgdUd19L0lTmwe6+7Dy3fXXJ/NjD3X4Y4pe?= =?us-ascii?Q?hjticHbLd8dKZ/OybD3CG1DF51CA/9wigZ+F5G/UByny6QLZhfZxB4o8ef95?= =?us-ascii?Q?TqAVapUClD8MFEh/m2/7wDW20epPs+xRZ7+G?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2025 10:09:17.8024 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c888465-57b7-463a-6cd3-08ddf11b44e0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECDB.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7425 Content-Type: text/plain; charset="utf-8" AMD isp4 capture is a v4l2 media device which implements media controller interface. It has one sub-device (AMD ISP4 sub-device) endpoint which can be connected to a remote CSI2 TX endpoint. It supports only one physical interface for now. Also add ISP4 driver related entry info into the MAINTAINERS file Co-developed-by: Svetoslav Stoilov Signed-off-by: Svetoslav Stoilov Signed-off-by: Bin Du Reviewed-by: Mario Limonciello (AMD) Tested-by: Alexey Zagorodnikov --- MAINTAINERS | 13 +++ drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/amd/Kconfig | 3 + drivers/media/platform/amd/Makefile | 3 + drivers/media/platform/amd/isp4/Kconfig | 13 +++ drivers/media/platform/amd/isp4/Makefile | 6 ++ drivers/media/platform/amd/isp4/isp4.c | 121 +++++++++++++++++++++++ drivers/media/platform/amd/isp4/isp4.h | 24 +++++ 9 files changed, 185 insertions(+) create mode 100644 drivers/media/platform/amd/Kconfig create mode 100644 drivers/media/platform/amd/Makefile create mode 100644 drivers/media/platform/amd/isp4/Kconfig create mode 100644 drivers/media/platform/amd/isp4/Makefile create mode 100644 drivers/media/platform/amd/isp4/isp4.c create mode 100644 drivers/media/platform/amd/isp4/isp4.h diff --git a/MAINTAINERS b/MAINTAINERS index cd7ff55b5d32..3640a1e3262c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1133,6 +1133,19 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git= /iommu/linux.git F: drivers/iommu/amd/ F: include/linux/amd-iommu.h =20 +AMD ISP4 DRIVER +M: Bin Du +M: Nirujogi Pratap +L: linux-media@vger.kernel.org +S: Maintained +T: git git://linuxtv.org/media.git +F: drivers/media/platform/amd/Kconfig +F: drivers/media/platform/amd/Makefile +F: drivers/media/platform/amd/isp4/Kconfig +F: drivers/media/platform/amd/isp4/Makefile +F: drivers/media/platform/amd/isp4/isp4.c +F: drivers/media/platform/amd/isp4/isp4.h + AMD KFD M: Felix Kuehling L: amd-gfx@lists.freedesktop.org diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index 9287faafdce5..772c70665510 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -63,6 +63,7 @@ config VIDEO_MUX =20 # Platform drivers - Please keep it alphabetically sorted source "drivers/media/platform/allegro-dvt/Kconfig" +source "drivers/media/platform/amd/Kconfig" source "drivers/media/platform/amlogic/Kconfig" source "drivers/media/platform/amphion/Kconfig" source "drivers/media/platform/aspeed/Kconfig" diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makef= ile index 6fd7db0541c7..b207bd8d8022 100644 --- a/drivers/media/platform/Makefile +++ b/drivers/media/platform/Makefile @@ -6,6 +6,7 @@ # Place here, alphabetically sorted by directory # (e. g. LC_ALL=3DC sort Makefile) obj-y +=3D allegro-dvt/ +obj-y +=3D amd/ obj-y +=3D amlogic/ obj-y +=3D amphion/ obj-y +=3D aspeed/ diff --git a/drivers/media/platform/amd/Kconfig b/drivers/media/platform/am= d/Kconfig new file mode 100644 index 000000000000..25af49f246b2 --- /dev/null +++ b/drivers/media/platform/amd/Kconfig @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +source "drivers/media/platform/amd/isp4/Kconfig" diff --git a/drivers/media/platform/amd/Makefile b/drivers/media/platform/a= md/Makefile new file mode 100644 index 000000000000..8bfc1955f22e --- /dev/null +++ b/drivers/media/platform/amd/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y +=3D isp4/ diff --git a/drivers/media/platform/amd/isp4/Kconfig b/drivers/media/platfo= rm/amd/isp4/Kconfig new file mode 100644 index 000000000000..52962eee8564 --- /dev/null +++ b/drivers/media/platform/amd/isp4/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0+ + +config AMD_ISP4 + tristate "AMD ISP4 and camera driver" + depends on VIDEO_DEV && VIDEO_V4L2_SUBDEV_API && DRM_AMD_ISP + select VIDEOBUF2_CORE + select VIDEOBUF2_V4L2 + select VIDEOBUF2_MEMOPS + help + This is support for AMD ISP4 and camera subsystem driver. + Say Y here to enable the ISP4 and camera device for video capture. + To compile this driver as a module, choose M here. The module will + be called amd_capture. diff --git a/drivers/media/platform/amd/isp4/Makefile b/drivers/media/platf= orm/amd/isp4/Makefile new file mode 100644 index 000000000000..de0092dad26f --- /dev/null +++ b/drivers/media/platform/amd/isp4/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2025 Advanced Micro Devices, Inc. + +obj-$(CONFIG_AMD_ISP4) +=3D amd_capture.o +amd_capture-objs :=3D isp4.o diff --git a/drivers/media/platform/amd/isp4/isp4.c b/drivers/media/platfor= m/amd/isp4/isp4.c new file mode 100644 index 000000000000..6ff3ded4310a --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#include +#include +#include + +#include "isp4.h" + +#define VIDEO_BUF_NUM 5 + +#define ISP4_DRV_NAME "amd_isp_capture" + +/* interrupt num */ +static const u32 isp4_ringbuf_interrupt_num[] =3D { + 0, /* ISP_4_1__SRCID__ISP_RINGBUFFER_WPT9 */ + 1, /* ISP_4_1__SRCID__ISP_RINGBUFFER_WPT10 */ + 3, /* ISP_4_1__SRCID__ISP_RINGBUFFER_WPT11 */ + 4, /* ISP_4_1__SRCID__ISP_RINGBUFFER_WPT12 */ +}; + +#define to_isp4_device(dev) \ + ((struct isp4_device *)container_of(dev, struct isp4_device, v4l2_dev)) + +static irqreturn_t isp4_irq_handler(int irq, void *arg) +{ + return IRQ_HANDLED; +} + +static int isp4_capture_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct isp4_device *isp_dev; + int i, irq, ret; + + isp_dev =3D devm_kzalloc(&pdev->dev, sizeof(*isp_dev), GFP_KERNEL); + if (!isp_dev) + return -ENOMEM; + + isp_dev->pdev =3D pdev; + dev->init_name =3D ISP4_DRV_NAME; + + for (i =3D 0; i < ARRAY_SIZE(isp4_ringbuf_interrupt_num); i++) { + irq =3D platform_get_irq(pdev, isp4_ringbuf_interrupt_num[i]); + if (irq < 0) + return dev_err_probe(dev, -ENODEV, + "fail to get irq %d\n", + isp4_ringbuf_interrupt_num[i]); + ret =3D devm_request_irq(&pdev->dev, irq, isp4_irq_handler, 0, + "ISP_IRQ", &pdev->dev); + if (ret) + return dev_err_probe(dev, ret, "fail to req irq %d\n", + irq); + } + + /* Link the media device within the v4l2_device */ + isp_dev->v4l2_dev.mdev =3D &isp_dev->mdev; + + /* Initialize media device */ + strscpy(isp_dev->mdev.model, "amd_isp41_mdev", + sizeof(isp_dev->mdev.model)); + snprintf(isp_dev->mdev.bus_info, sizeof(isp_dev->mdev.bus_info), + "platform:%s", ISP4_DRV_NAME); + isp_dev->mdev.dev =3D &pdev->dev; + media_device_init(&isp_dev->mdev); + + /* register v4l2 device */ + snprintf(isp_dev->v4l2_dev.name, sizeof(isp_dev->v4l2_dev.name), + "AMD-V4L2-ROOT"); + ret =3D v4l2_device_register(&pdev->dev, &isp_dev->v4l2_dev); + if (ret) + return dev_err_probe(dev, ret, + "fail register v4l2 device\n"); + + ret =3D media_device_register(&isp_dev->mdev); + if (ret) { + dev_err(dev, "fail to register media device %d\n", ret); + goto err_unreg_v4l2; + } + + platform_set_drvdata(pdev, isp_dev); + + pm_runtime_set_suspended(dev); + pm_runtime_enable(dev); + + return 0; + +err_unreg_v4l2: + v4l2_device_unregister(&isp_dev->v4l2_dev); + + return dev_err_probe(dev, ret, "isp probe fail\n"); +} + +static void isp4_capture_remove(struct platform_device *pdev) +{ + struct isp4_device *isp_dev =3D platform_get_drvdata(pdev); + + media_device_unregister(&isp_dev->mdev); + v4l2_device_unregister(&isp_dev->v4l2_dev); +} + +static struct platform_driver isp4_capture_drv =3D { + .probe =3D isp4_capture_probe, + .remove =3D isp4_capture_remove, + .driver =3D { + .name =3D ISP4_DRV_NAME, + .owner =3D THIS_MODULE, + } +}; + +module_platform_driver(isp4_capture_drv); + +MODULE_ALIAS("platform:" ISP4_DRV_NAME); +MODULE_IMPORT_NS("DMA_BUF"); + +MODULE_DESCRIPTION("AMD ISP4 Driver"); +MODULE_AUTHOR("Bin Du "); +MODULE_AUTHOR("Pratap Nirujogi "); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/platform/amd/isp4/isp4.h b/drivers/media/platfor= m/amd/isp4/isp4.h new file mode 100644 index 000000000000..8535f662ab49 --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _ISP4_H_ +#define _ISP4_H_ + +#include +#include +#include +#include + +#define ISP4_GET_ISP_REG_BASE(isp4sd) (((isp4sd))->mmio) + +struct isp4_device { + struct v4l2_device v4l2_dev; + struct media_device mdev; + + struct platform_device *pdev; + struct notifier_block i2c_nb; +}; + +#endif /* _ISP4_H_ */ --=20 2.34.1 From nobody Thu Oct 2 20:44:48 2025 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2077.outbound.protection.outlook.com [40.107.95.77]) (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 7832630EF70; Thu, 11 Sep 2025 10:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585369; cv=fail; b=cuxWRQ8TLSAVY5LNRwPQl4ANt9+xkceTbmWeqnkT0U9dH9qfRg/bXbBh/Do9uk+3DLynPkptOz0Zur0hla4OLSeuh0PvfC2K85xFao2DRrZdSwCXe4AUwMiIw65r4cjpQRxXlgmKre8Lvpa+EG8FRaWpJjWMmWMr3G+BqZUk0m0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585369; c=relaxed/simple; bh=dKu/k3uvtpuWFq9994JpTX1LniiZY2ShZhMnR91aSt8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HKBlW33WQDAxTS/X/HcJy8k7cljuxWcK6jKmaFcsePxTT1+K/7u8yfwTFH26VcIStJyxpCpfPu5GNq1/SnfIK5H0Mfk8vT3L3m7siUF6/z8TlcajFONdlNLI2C3X+YMQ4kbNtKrgYSaJ6X2TdvJLHvfOzJL8zfIDRxZktfW2a7E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=IXAkflKa; arc=fail smtp.client-ip=40.107.95.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="IXAkflKa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ozKDOenB3ssKYrrqshpfJMTY9DRRiviqHSZq7lEfAkR2tjGEr/ROkt1g8nX2+wRRRWyLGPqg24DDta8lEBqRcAyyIMk66RhxMYgyLMARp6Zknzy4ceCnvh1NgJILNnRR8hglhDUQJwMDnEmzj8Am2OesMa/LbXhFbgVeTOMoUzJ4FcyLBTV5vTuim0oSRO5ea3/GLhsPs2rP7dcyjKdj9/8e8JGeNmK5jUtd/F2OIc4epUm4B4aUZYjLDu4G86UegcEOxWkfzJaNBqRnChwhcckhUv7QZA10VkrPkQ0tLlQkpdq/EaDdLIFgOz3qeq4F/OhSKde5V4bKWtKUDu+F5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=HNPk2+8B81P4NHO0b/nYlc5JvqoouBFx003jKYZKPV0=; b=zVBz422Eh1bmbelqO6atjdalB4cMh0h5r1nHLy2Sz79Grs100j51SfiIT8gx4E4bYA7X1UwCc6Lc837BkTVSdo/hILj9hAnsVQKNvlweNwyXkY9qwyKE6WeFMpVjAqod7qZ0JQU5XBJ58MZsmrM/T1xh8L7zYHe3VMakfTGG1wVIb/AhIC/CLILmhLsnwzR/+rULicv6YHr23Bt4oVNXssIIQkqSHX0y6+co+tKQ9B9Z17PuPdzkEZ5NF9wREuzzl0ZiEVUBqDsvPoIYC0JoLlllzX4Y/dj0egT9j9u+Bckg2xSg43aPvZH/FODDyb/b6FxwSvy+onV6wb41iaYmCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HNPk2+8B81P4NHO0b/nYlc5JvqoouBFx003jKYZKPV0=; b=IXAkflKa4l5hxdcGawFJyQp+vq5lJGhIQO7qwXc8a64tk3U1xVADKFbDJIeru9PaVzvCs4WZdgQe4Aaw5+/hgSr5xAzfZ6wxz/kHLwLZXfeBgQjeFtdrsJI8kQuKVtPJ5nJGEMl82F9Y8RuL+AKgxtZrp9lS+B0yXo/dufnVIWQ= Received: from BL1PR13CA0398.namprd13.prod.outlook.com (2603:10b6:208:2c2::13) by SJ0PR12MB8615.namprd12.prod.outlook.com (2603:10b6:a03:484::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Thu, 11 Sep 2025 10:09:23 +0000 Received: from MN1PEPF0000ECDB.namprd02.prod.outlook.com (2603:10b6:208:2c2:cafe::5e) by BL1PR13CA0398.outlook.office365.com (2603:10b6:208:2c2::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9137.6 via Frontend Transport; Thu, 11 Sep 2025 10:09:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MN1PEPF0000ECDB.mail.protection.outlook.com (10.167.242.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Thu, 11 Sep 2025 10:09:22 +0000 Received: from 555e2b870847.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 11 Sep 2025 03:09:17 -0700 From: Bin Du To: , , , , , , , , CC: , , , , , , , , , , Bin Du , Svetoslav Stoilov , "Alexey Zagorodnikov" Subject: [PATCH v4 2/7] media: platform: amd: low level support for isp4 firmware Date: Thu, 11 Sep 2025 18:08:42 +0800 Message-ID: <20250911100847.277408-3-Bin.Du@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911100847.277408-1-Bin.Du@amd.com> References: <20250911100847.277408-1-Bin.Du@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECDB:EE_|SJ0PR12MB8615:EE_ X-MS-Office365-Filtering-Correlation-Id: d65e4e60-31c4-4ca0-3905-08ddf11b47ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?xuENYkQvD2i3Sj2O/SEWGqF19ToFS9dLfusPKPv8mClnAYo+4PvK9DxHvyT7?= =?us-ascii?Q?7zDI0cwqICociFzjwQQK8hurBrVZLNgqwuVAlW2ae7e++yOrkkEw6jruRWoE?= =?us-ascii?Q?jowZ4zZKGPl5Oc/rTTQYHDmjdsWwlFaUogKs+aECmBaCCBEmLyl/XVgoYKbU?= =?us-ascii?Q?jvHICWZ8DJKqWr6d1kMBratFem0YJ8BrCSOEzWl99WlYcHMI6y4G0r9Gcvh3?= =?us-ascii?Q?gnQIYDnSybRD5sYFhtB4gsF5bsqvTn+bWdSPNnZ+fXpLWOEUGEv1g3uTqQj7?= =?us-ascii?Q?KtNZ/1adBiJFdXNRMbW3bxO7EXAkKoZGeoo0cEqCrVw16vXrztJK9smgCbu/?= =?us-ascii?Q?Wm3C0QHtOD8GBXElLBmLimlEUM5bfi1eZbCt2RifMiLli8iPwLABiJ51e4Q+?= =?us-ascii?Q?ZuhqkiaO0MXCKHt0lg/Q3j8hMs2Qcp5Q+x2k6LszxAO1Z8KryQAFcKflDUyD?= =?us-ascii?Q?7pEHfQcO5Q3RCPGx8buoZEa7zokLxpYb/GyCYTR5ppuMXp8z4UyXAYhxer5w?= =?us-ascii?Q?ohVcS1Ha+oMG+carLjPI0CLGM1cKvBzrMIgRu0p5Z92r4OmzprC4mgfyaiDT?= =?us-ascii?Q?VIhg8lIIAcX5+gmAnaWqtkte2Lo8nxL8qRFQRB/ybN7/1DQHwGQdSPGNjpFf?= =?us-ascii?Q?ty3MKnKaFCnfwuNOKCbd+1PLAtt/tQ9AalzKmHOxIDSzWVTR9HuxI5dWujV8?= =?us-ascii?Q?IIwFdDAogqNhdi2HP9cHhX5yU2qJMWEIOK8y5+jzbKw9lgWHs8Y7qA9OIgse?= =?us-ascii?Q?LHTyDoyDY89jQ6uheqApr5Qta3u/GOfl7UaibP4z7qVg0Gnga0dAZz457RLU?= =?us-ascii?Q?Flz3znMU9ZLUXI9cOc+v5GoTCYFybuCKMiayuMqbvGMC7VCgbttjQap0jfvY?= =?us-ascii?Q?1kmDqKEDw5i5/bthWdc4yD8Y+EuezK4B9hp36vF3WI8bWDez5tPDRLEA5md6?= =?us-ascii?Q?8YqRSPMQaUBgtjLrFQdp0a6A1LywRJfJ3PgWuLdxurHcU4aLflP7aNP7qHqi?= =?us-ascii?Q?E/M7c0btd2ZlReDvWtX9FPY1SNLnle4paTVVp/8mMd9BbEGjtNtVDUuHPel6?= =?us-ascii?Q?x7hO0mYDnROBByDbHHcEf9oV16j1nXzNVTgXTgnSUZXr/2QlWpjnGARPohFo?= =?us-ascii?Q?0iZFgBabGXUc8CABm0U5fRZKNgpO0HAUsCIdMGdhXDEEjK51lRcxPdB0Kd1V?= =?us-ascii?Q?nRaIC5fpYno8/cRX2nYxydY3n5J+mzREvxGqpEbDixYUEPGXaJoJfFqa6Akm?= =?us-ascii?Q?szMjroCamDGtolXQZNc1x6ejH29nnX2KUkLzoryBoWuCYfPD5gC3fqBENT80?= =?us-ascii?Q?tNS9162uKf8HhKq/3va7r92hkhpssfTLfqEWIzHFA9Zf9ReWOp19NeYluMbn?= =?us-ascii?Q?ZHo+YiSPSYHfRDl6wnIm0toTqZWxOx3SR/+spt3v3XtQduNAWqf0crQfB6Ou?= =?us-ascii?Q?VfChFeKJBqh85BHKNpMiaE8JTR6O6JjroqdcJbfBJ8HRRCOeQ4rYpKLIJj2R?= =?us-ascii?Q?NJpKnNTjx8YELMd6Uom5wx6weenLScHY3U2t?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2025 10:09:22.7165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d65e4e60-31c4-4ca0-3905-08ddf11b47ce X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECDB.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB8615 Content-Type: text/plain; charset="utf-8" Low level functions for accessing the registers and mapping to their ranges. This change also includes register definitions for ring buffer used to communicate with ISP Firmware. Ring buffer is the communication interface between driver and ISP Firmware. Command and responses are exchanged through the ring buffer. Co-developed-by: Svetoslav Stoilov Signed-off-by: Svetoslav Stoilov Signed-off-by: Bin Du Tested-by: Alexey Zagorodnikov --- MAINTAINERS | 1 + drivers/media/platform/amd/isp4/Makefile | 2 +- drivers/media/platform/amd/isp4/isp4_hw_reg.h | 125 ++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 drivers/media/platform/amd/isp4/isp4_hw_reg.h diff --git a/MAINTAINERS b/MAINTAINERS index 3640a1e3262c..7aa17c7e71d6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1145,6 +1145,7 @@ F: drivers/media/platform/amd/isp4/Kconfig F: drivers/media/platform/amd/isp4/Makefile F: drivers/media/platform/amd/isp4/isp4.c F: drivers/media/platform/amd/isp4/isp4.h +F: drivers/media/platform/amd/isp4/isp4_hw_reg.h =20 AMD KFD M: Felix Kuehling diff --git a/drivers/media/platform/amd/isp4/Makefile b/drivers/media/platf= orm/amd/isp4/Makefile index de0092dad26f..eb130647fbe2 100644 --- a/drivers/media/platform/amd/isp4/Makefile +++ b/drivers/media/platform/amd/isp4/Makefile @@ -3,4 +3,4 @@ # Copyright (C) 2025 Advanced Micro Devices, Inc. =20 obj-$(CONFIG_AMD_ISP4) +=3D amd_capture.o -amd_capture-objs :=3D isp4.o +amd_capture-objs :=3D isp4.o \ diff --git a/drivers/media/platform/amd/isp4/isp4_hw_reg.h b/drivers/media/= platform/amd/isp4/isp4_hw_reg.h new file mode 100644 index 000000000000..16a02a14d985 --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_hw_reg.h @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _ISP4_HW_REG_H_ +#define _ISP4_HW_REG_H_ + +#include +#include + +#define ISP_SOFT_RESET 0x62000 +#define ISP_SYS_INT0_EN 0x62010 +#define ISP_SYS_INT0_STATUS 0x62014 +#define ISP_SYS_INT0_ACK 0x62018 +#define ISP_CCPU_CNTL 0x62054 +#define ISP_STATUS 0x62058 +#define ISP_LOG_RB_BASE_LO0 0x62148 +#define ISP_LOG_RB_BASE_HI0 0x6214c +#define ISP_LOG_RB_SIZE0 0x62150 +#define ISP_LOG_RB_RPTR0 0x62154 +#define ISP_LOG_RB_WPTR0 0x62158 +#define ISP_RB_BASE_LO1 0x62170 +#define ISP_RB_BASE_HI1 0x62174 +#define ISP_RB_SIZE1 0x62178 +#define ISP_RB_RPTR1 0x6217c +#define ISP_RB_WPTR1 0x62180 +#define ISP_RB_BASE_LO2 0x62184 +#define ISP_RB_BASE_HI2 0x62188 +#define ISP_RB_SIZE2 0x6218c +#define ISP_RB_RPTR2 0x62190 +#define ISP_RB_WPTR2 0x62194 +#define ISP_RB_BASE_LO3 0x62198 +#define ISP_RB_BASE_HI3 0x6219c +#define ISP_RB_SIZE3 0x621a0 +#define ISP_RB_RPTR3 0x621a4 +#define ISP_RB_WPTR3 0x621a8 +#define ISP_RB_BASE_LO4 0x621ac +#define ISP_RB_BASE_HI4 0x621b0 +#define ISP_RB_SIZE4 0x621b4 +#define ISP_RB_RPTR4 0x621b8 +#define ISP_RB_WPTR4 0x621bc +#define ISP_RB_BASE_LO5 0x621c0 +#define ISP_RB_BASE_HI5 0x621c4 +#define ISP_RB_SIZE5 0x621c8 +#define ISP_RB_RPTR5 0x621cc +#define ISP_RB_WPTR5 0x621d0 +#define ISP_RB_BASE_LO6 0x621d4 +#define ISP_RB_BASE_HI6 0x621d8 +#define ISP_RB_SIZE6 0x621dc +#define ISP_RB_RPTR6 0x621e0 +#define ISP_RB_WPTR6 0x621e4 +#define ISP_RB_BASE_LO7 0x621e8 +#define ISP_RB_BASE_HI7 0x621ec +#define ISP_RB_SIZE7 0x621f0 +#define ISP_RB_RPTR7 0x621f4 +#define ISP_RB_WPTR7 0x621f8 +#define ISP_RB_BASE_LO8 0x621fc +#define ISP_RB_BASE_HI8 0x62200 +#define ISP_RB_SIZE8 0x62204 +#define ISP_RB_RPTR8 0x62208 +#define ISP_RB_WPTR8 0x6220c +#define ISP_RB_BASE_LO9 0x62210 +#define ISP_RB_BASE_HI9 0x62214 +#define ISP_RB_SIZE9 0x62218 +#define ISP_RB_RPTR9 0x6221c +#define ISP_RB_WPTR9 0x62220 +#define ISP_RB_BASE_LO10 0x62224 +#define ISP_RB_BASE_HI10 0x62228 +#define ISP_RB_SIZE10 0x6222c +#define ISP_RB_RPTR10 0x62230 +#define ISP_RB_WPTR10 0x62234 +#define ISP_RB_BASE_LO11 0x62238 +#define ISP_RB_BASE_HI11 0x6223c +#define ISP_RB_SIZE11 0x62240 +#define ISP_RB_RPTR11 0x62244 +#define ISP_RB_WPTR11 0x62248 +#define ISP_RB_BASE_LO12 0x6224c +#define ISP_RB_BASE_HI12 0x62250 +#define ISP_RB_SIZE12 0x62254 +#define ISP_RB_RPTR12 0x62258 +#define ISP_RB_WPTR12 0x6225c + +#define ISP_POWER_STATUS 0x60000 + +/* ISP_SOFT_RESET */ +#define ISP_SOFT_RESET__CCPU_SOFT_RESET_MASK 0x00000001UL + +/* ISP_CCPU_CNTL */ +#define ISP_CCPU_CNTL__CCPU_HOST_SOFT_RST_MASK 0x00040000UL + +/* ISP_STATUS */ +#define ISP_STATUS__CCPU_REPORT_MASK 0x000000feUL + +/* ISP_SYS_INT0_STATUS */ +#define ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT9_INT_MASK 0x00010000UL +#define ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT10_INT_MASK 0x00040000UL +#define ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT11_INT_MASK 0x00100000UL +#define ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT12_INT_MASK 0x00400000UL + +/* ISP_SYS_INT0_EN */ +#define ISP_SYS_INT0_EN__SYS_INT_RINGBUFFER_WPT9_EN_MASK 0x00010000UL +#define ISP_SYS_INT0_EN__SYS_INT_RINGBUFFER_WPT10_EN_MASK 0x00040000UL +#define ISP_SYS_INT0_EN__SYS_INT_RINGBUFFER_WPT11_EN_MASK 0x00100000UL +#define ISP_SYS_INT0_EN__SYS_INT_RINGBUFFER_WPT12_EN_MASK 0x00400000UL + +/* ISP_SYS_INT0_ACK */ +#define ISP_SYS_INT0_ACK__SYS_INT_RINGBUFFER_WPT9_ACK_MASK 0x00010000UL +#define ISP_SYS_INT0_ACK__SYS_INT_RINGBUFFER_WPT10_ACK_MASK 0x00040000UL +#define ISP_SYS_INT0_ACK__SYS_INT_RINGBUFFER_WPT11_ACK_MASK 0x00100000UL +#define ISP_SYS_INT0_ACK__SYS_INT_RINGBUFFER_WPT12_ACK_MASK 0x00400000UL + +/* Helper functions for reading isp registers */ +static inline u32 isp4hw_rreg(void __iomem *base, u32 reg) +{ + return readl(base + reg); +} + +/* Helper functions for writing isp registers */ +static inline void isp4hw_wreg(void __iomem *base, u32 reg, u32 val) +{ + return writel(val, base + reg); +} + +#endif --=20 2.34.1 From nobody Thu Oct 2 20:44:48 2025 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2055.outbound.protection.outlook.com [40.107.237.55]) (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 49BAD30F7F6; Thu, 11 Sep 2025 10:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585382; cv=fail; b=rmDfo6hDm/fcVvU6VUIbRco4n/j9iFCIWjC4IbCs/xo2D67dy711mklQ4p08sGb9DYtQDnfA2bAHIaS5T6UZr7hONQfUl4OJFNZC+ik+1voEVIO5eNoxVFTcLL3i8cQQYvcHZgUCnvUkwl8SBXYL2rqAFaaTc+3wsTfl1Sz/LKE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585382; c=relaxed/simple; bh=EgiqayW3dbFdZx1RAUcLp75jZGLq645sm0BwS9rJxS4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qnHk6Rwt9d+FLpXmi2lkVkHhVAw3Hw6KWM7HftPnqPclDTA5jjUWwDdkFIadTWjXbpGISLaKuVe86RbRM11QIweo16Fwv5XTGpmeRLRM2srhHrrD/juONkEVJiOcsFBi7cOGbFjdvREzAI+2Ofu56rXk7bwpHe/RaQXEANIPTMo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=rEdQME7W; arc=fail smtp.client-ip=40.107.237.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="rEdQME7W" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Wv8e0o3DsgVtvzb147vWFDXrlDAwEmg8th/LW+LrCui1FWaYf7EOyVnqMBY46J2b8dzIOTZZEy06DWT+sSnL2UwcvrYsV76PGzxGLEUInMi+rmEVPgzaT5SkYClmaGX97VzernHH7EK8c4lfLzDRILX7KiD34fjduvX+6+uEz+EytTcwLoBcvBFOfCW0TgAwddTWwA+d1Hdu/VBtp7a8qDPlHDrEAfT4yOUvqlQfoYwyEiJQWBugS19mpbwB2NUpYaOoI+9tnxyJ+rG4I3Nl/Ig0BzsD9Y480Lyg6ke/RLQmy+/zA4UX/hZ0Hxqb3L16hRYxbJMglRBjEbUhwH5rVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=oW1i9cYBSAD7KOc99eNt6N4uD0Hi9v8BZsm9mf1fq98=; b=BKmbtfzeWbrSp88FWte9RU044PrBvWqT4dMhmVznIXVl2afns3FrwRhpwnLoRZjuff//amQbDoyBQ9JndZfkWzTGsCJ3FBDceJtD99nELGZ1qeSH3vwGVSLEA2g/J6+TFeoYw0wuJTVoG2f5V8hVrgZwIMz6t9lh6jIYu73UlfMQleqdSHHo3Qxo0nXFF1m5uXbVAsxM30X/SZthUPaV63a9vjeG3H5xyFC8wxa+oHqSi9eZKhvuMthH0JpR75KKphqlSPHjzt12I2LV+kCCgbTDL56KsfbT2N7Ls2hqCcr124FAeGpfjpoMab0F5y3srPkX1tWA8+i32H6USX00GQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oW1i9cYBSAD7KOc99eNt6N4uD0Hi9v8BZsm9mf1fq98=; b=rEdQME7WmLzCxkyfV5oV6f3D+skZ3Qf7H15tx3WFBTVsE50+9ezR9AyvyqOX4UGCNKtdUrjChd0lNE1mHQb2haju09UWRKKT9a9EZFWVdmTwa1y8WusNQNz5WoQRd0YMYTVZIytwd6QE3XwdieGKjGfSJVJwGlq3vT9Ihz7MTTQ= Received: from BL1PR13CA0417.namprd13.prod.outlook.com (2603:10b6:208:2c2::32) by DM4PR12MB6207.namprd12.prod.outlook.com (2603:10b6:8:a6::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Thu, 11 Sep 2025 10:09:28 +0000 Received: from MN1PEPF0000ECDB.namprd02.prod.outlook.com (2603:10b6:208:2c2:cafe::10) by BL1PR13CA0417.outlook.office365.com (2603:10b6:208:2c2::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9137.6 via Frontend Transport; Thu, 11 Sep 2025 10:09:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MN1PEPF0000ECDB.mail.protection.outlook.com (10.167.242.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Thu, 11 Sep 2025 10:09:28 +0000 Received: from 555e2b870847.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 11 Sep 2025 03:09:22 -0700 From: Bin Du To: , , , , , , , , CC: , , , , , , , , , , Bin Du , Svetoslav Stoilov , "Alexey Zagorodnikov" Subject: [PATCH v4 3/7] media: platform: amd: Add isp4 fw and hw interface Date: Thu, 11 Sep 2025 18:08:43 +0800 Message-ID: <20250911100847.277408-4-Bin.Du@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911100847.277408-1-Bin.Du@amd.com> References: <20250911100847.277408-1-Bin.Du@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECDB:EE_|DM4PR12MB6207:EE_ X-MS-Office365-Filtering-Correlation-Id: 543853ac-3999-4bd1-c09c-08ddf11b4b48 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|7416014|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?S+A5kFscY/qb+pz3xV+v6uvIfQzLzataauPc2kd6Ii5du4lLHxmslN9EI7Ut?= =?us-ascii?Q?z5INtcKLNtN4imwQ6M8pxZS0jpP4EdyUnT/SBcy9shlszS1oUhcCoaMVsF9F?= =?us-ascii?Q?Z1Y0B465eubPb3NnW0mLPFz2u68QQh7ZEVb9r8dccOpdR9G9M2MW7/9MQaul?= =?us-ascii?Q?ysYAACdlCi43uArmeoZJALsIHX18/xSrIRgg0klpyuOovjV5/WN/sUGUMVf3?= =?us-ascii?Q?K+FCIQiTdN1bbkHQHAkg4GSfByTJKeejQCN8KaX8Ca7yZtzDJWd0l9SLH7sS?= =?us-ascii?Q?RJ/NGfhYyvq5Qt7psHgjJiWIFcRZHeJY4imkXzruMLeSBrzRRq3djX+2OSRA?= =?us-ascii?Q?MGSGkztifuE+gz/TyTPzbjv0mt/7OOWwwRhH18HSjPw442TvLYAc4N+qpKYS?= =?us-ascii?Q?0h5ougILw48u1cZ5lEr+ZvRvDOcN7PtLO0CErZmZ6DT4Dz3A9kWLoDtXYHkn?= =?us-ascii?Q?YZ4YCFpDXGuS9d5sBH2NMQYkGkMFkaF+PaRv/siY2shsf6oRutjpMbn2iA2O?= =?us-ascii?Q?80y8TnXKTrlPzXhqAJHkWSEa5upAgUzRjisc3qYb/1VS14M1AS3n0h4Ew/+S?= =?us-ascii?Q?1GMTUA3T0aLWBRn52V8K3oYNEq0FzSMbsEqUnjhIo9XB/fo3pf8B2NU2XZ6s?= =?us-ascii?Q?/4amNIstSgze0yKYz8qnD+VB12K4tq8dyKj6QzXqFLtfyjoLKgshnMcDe3OP?= =?us-ascii?Q?0Ti0AU1Yb3gcWybyPLGQ+P+aPOlpuMsYlrzIqrfgD4Jrfp2RtPGfmr8iz/MG?= =?us-ascii?Q?5hibkHYB4E9XfDdZ8GppANzgBl+O80ta+XkffldJyR7NwelRRZ7oz21IEsMp?= =?us-ascii?Q?KaVu88AtDhZ9/FeS9Kud/F0shyL4ujohD2p/v9dVYAWxOCzQRGW4muMlGFz8?= =?us-ascii?Q?6d8VGjmTAgurr/kyefE9dwXOKc6TU3mPQ1qvLzb6uteQbDMxO/5BlRpR4E/Q?= =?us-ascii?Q?KDgkvw933b+chrIvhxhjNsv6upsf0vg41yug+xX5IO6wugRNqFA8NO4MDouM?= =?us-ascii?Q?k2QVzoyRqZ6kQFObBdn65fe6jFdYvvDLpCy0yMsq38Jp4vsbH5LSEvmahDt1?= =?us-ascii?Q?BqK9qeUjbzYAVIdBUh9virf4cfI+gK1/yzfSA+/DAIVcHo5mbgrxsFNeMK5N?= =?us-ascii?Q?dewkIv1cvff81IYdUCGCS6mR+c1BPWbqiZ40n4Zxc974FJlMZcaFHLyV9VDi?= =?us-ascii?Q?kqvAnpBK20KRPTIGJ7QArtAhVKa2v8tY0vjTZgP3nDx61Y+/3Ax2Wg0fJQYn?= =?us-ascii?Q?+kTvrzoUaWs7rrhEbeG2y3aJ63VfqKyzgr/MinjDFBRSjWAo2gEzGXV9mSVj?= =?us-ascii?Q?Y40OvKvxO7u6ZUEvLKamFCI88tSEAJQywHtLj4tVbNwA+119SLRGgvOlp3tu?= =?us-ascii?Q?FnUzdpXhv/lND96jHW+TrN4TYCuUHfOfgbmEpM4kqwpLM42KvnitLsmRgKrW?= =?us-ascii?Q?HjsAPK1g7PMOy0OOD8diET6J66rgpR8jl1WFMP2WVs/RtfyG4ysFBKzX6iMQ?= =?us-ascii?Q?Nb6UrJ18tm2ltGvUILQR97jyqQMIkTCB3GoW?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(376014)(7416014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2025 10:09:28.5524 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 543853ac-3999-4bd1-c09c-08ddf11b4b48 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECDB.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6207 Content-Type: text/plain; charset="utf-8" ISP firmware controls ISP HW pipeline using dedicated embedded processor called ccpu. The communication between ISP FW and driver is using commands and response messages sent through the ring buffer. Command buffers support either global setting that is not specific to the steam and support stream specific parameters. Response buffers contain ISP FW notification information such as frame buffer done and command done. IRQ is used for receiving response buffer from ISP firmware, which is handled in the main isp4 media device. ISP ccpu is booted up through the firmware loading helper function prior to stream start. Memory used for command buffer and response buffer needs to be allocated from amdgpu buffer manager because isp4 is a child device of amdgpu. Co-developed-by: Svetoslav Stoilov Signed-off-by: Svetoslav Stoilov Signed-off-by: Bin Du Tested-by: Alexey Zagorodnikov --- MAINTAINERS | 3 + drivers/media/platform/amd/isp4/Makefile | 1 + .../platform/amd/isp4/isp4_fw_cmd_resp.h | 314 ++++++ .../media/platform/amd/isp4/isp4_interface.c | 955 ++++++++++++++++++ .../media/platform/amd/isp4/isp4_interface.h | 149 +++ 5 files changed, 1422 insertions(+) create mode 100644 drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h create mode 100644 drivers/media/platform/amd/isp4/isp4_interface.c create mode 100644 drivers/media/platform/amd/isp4/isp4_interface.h diff --git a/MAINTAINERS b/MAINTAINERS index 7aa17c7e71d6..cccae369c876 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1145,7 +1145,10 @@ F: drivers/media/platform/amd/isp4/Kconfig F: drivers/media/platform/amd/isp4/Makefile F: drivers/media/platform/amd/isp4/isp4.c F: drivers/media/platform/amd/isp4/isp4.h +F: drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h F: drivers/media/platform/amd/isp4/isp4_hw_reg.h +F: drivers/media/platform/amd/isp4/isp4_interface.c +F: drivers/media/platform/amd/isp4/isp4_interface.h =20 AMD KFD M: Felix Kuehling diff --git a/drivers/media/platform/amd/isp4/Makefile b/drivers/media/platf= orm/amd/isp4/Makefile index eb130647fbe2..327ed1157076 100644 --- a/drivers/media/platform/amd/isp4/Makefile +++ b/drivers/media/platform/amd/isp4/Makefile @@ -4,3 +4,4 @@ =20 obj-$(CONFIG_AMD_ISP4) +=3D amd_capture.o amd_capture-objs :=3D isp4.o \ + isp4_interface.o \ diff --git a/drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h b/drivers/m= edia/platform/amd/isp4/isp4_fw_cmd_resp.h new file mode 100644 index 000000000000..2a21cc4b80e9 --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h @@ -0,0 +1,314 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _ISP4_CMD_RESP_H_ +#define _ISP4_CMD_RESP_H_ + +/* + * @brief Host and Firmware command & response channel. + * Two types of command/response channel. + * Type Global Command has one command/response channel. + * Type Stream Command has one command/response channel. + *----------- ------------ + *| | --------------------------- | | + *| | ---->| Global Command |----> | | + *| | --------------------------- | | + *| | | | + *| | | | + *| | --------------------------- | | + *| | ---->| Stream Command |----> | | + *| | --------------------------- | | + *| | | | + *| | | | + *| | | | + *| HOST | | Firmware | + *| | | | + *| | | | + *| | -------------------------- | | + *| | <----| Global Response |<---- | | + *| | -------------------------- | | + *| | | | + *| | | | + *| | -------------------------- | | + *| | <----| Stream Response |<---- | | + *| | -------------------------- | | + *| | | | + *| | | | + *----------- ------------ + */ + +/* + * @brief command ID format + * cmd_id is in the format of following type: + * type: indicate command type, global/stream commands. + * group: indicate the command group. + * id: A unique command identification in one type and group. + * |<-Bit31 ~ Bit24->|<-Bit23 ~ Bit16->|<-Bit15 ~ Bit0->| + * | type | group | id | + */ + +#define CMD_TYPE_SHIFT 24 +#define CMD_GROUP_SHIFT 16 +#define CMD_TYPE_STREAM_CTRL (0x2U << CMD_TYPE_SHIFT) + +#define CMD_GROUP_STREAM_CTRL (0x1U << CMD_GROUP_SHIFT) +#define CMD_GROUP_STREAM_BUFFER (0x4U << CMD_GROUP_SHIFT) + +/* Stream Command */ +#define CMD_ID_SET_STREAM_CONFIG (CMD_TYPE_STREAM_CTRL | CMD_GROUP_= STREAM_CTRL | 0x1) +#define CMD_ID_SET_OUT_CHAN_PROP (CMD_TYPE_STREAM_CTRL | CMD_GROUP_= STREAM_CTRL | 0x3) +#define CMD_ID_ENABLE_OUT_CHAN (CMD_TYPE_STREAM_CTRL | CMD_GROUP_= STREAM_CTRL | 0x5) +#define CMD_ID_START_STREAM (CMD_TYPE_STREAM_CTRL | CMD_GROUP_= STREAM_CTRL | 0x7) +#define CMD_ID_STOP_STREAM (CMD_TYPE_STREAM_CTRL | CMD_GROUP_= STREAM_CTRL | 0x8) + +/* Stream Buffer Command */ +#define CMD_ID_SEND_BUFFER (CMD_TYPE_STREAM_CTRL | CMD_GROUP_= STREAM_BUFFER | 0x1) + +/* + * @brief response ID format + * resp_id is in the format of following type: + * type: indicate command type, global/stream commands. + * group: indicate the command group. + * id: A unique command identification in one type and group. + * |<-Bit31 ~ Bit24->|<-Bit23 ~ Bit16->|<-Bit15 ~ Bit0->| + * | type | group | id | + */ + +#define RESP_GROUP_SHIFT 16 +#define RESP_GROUP_MASK (0xff << RESP_GROUP_SHIFT) + +#define GET_RESP_GROUP_VALUE(resp_id) (((resp_id) & RESP_GROUP_MASK) >> = RESP_GROUP_SHIFT) +#define GET_RESP_ID_VALUE(resp_id) ((resp_id) & 0xffff) + +#define RESP_GROUP_GENERAL (0x1 << RESP_GROUP_SHIFT) +#define RESP_GROUP_NOTIFICATION (0x3 << RESP_GROUP_SHIFT) + +/* General Response */ +#define RESP_ID_CMD_DONE (RESP_GROUP_GENERAL | 0x1) + +/* Notification */ +#define RESP_ID_NOTI_FRAME_DONE (RESP_GROUP_NOTIFICATION | 0x1) + +#define CMD_STATUS_SUCCESS 0 +#define CMD_STATUS_FAIL 1 +#define CMD_STATUS_SKIPPED 2 + +#define ADDR_SPACE_TYPE_GPU_VA 4 + +#define FW_MEMORY_POOL_SIZE (200 * 1024 * 1024) + +/* + * standard ISP mipicsi=3D>isp + */ +#define MIPI0_ISP_PIPELINE_ID 0x5f91 + +enum isp4fw_sensor_id { + SENSOR_ID_ON_MIPI0 =3D 0, /* Sensor id for ISP input from MIPI port 0 */ +}; + +enum isp4fw_stream_id { + STREAM_ID_INVALID =3D -1, /* STREAM_ID_INVALID. */ + STREAM_ID_1 =3D 0, /* STREAM_ID_1. */ + STREAM_ID_2 =3D 1, /* STREAM_ID_2. */ + STREAM_ID_3 =3D 2, /* STREAM_ID_3. */ + STREAM_ID_MAXIMUM /* STREAM_ID_MAXIMUM. */ +}; + +enum isp4fw_image_format { + IMAGE_FORMAT_NV12 =3D 1, /* 4:2:0,semi-planar, 8-bit */ + IMAGE_FORMAT_YUV422INTERLEAVED =3D 7, /* interleave, 4:2:2, 8-bit */ +}; + +enum isp4fw_pipe_out_ch { + ISP_PIPE_OUT_CH_PREVIEW =3D 0, +}; + +enum isp4fw_yuv_range { + ISP_YUV_RANGE_FULL =3D 0, /* YUV value range in 0~255 */ + ISP_YUV_RANGE_NARROW =3D 1, /* YUV value range in 16~235 */ + ISP_YUV_RANGE_MAX +}; + +enum isp4fw_buffer_type { + BUFFER_TYPE_PREVIEW =3D 8, + BUFFER_TYPE_META_INFO =3D 10, + BUFFER_TYPE_MEM_POOL =3D 15, +}; + +enum isp4fw_buffer_status { + BUFFER_STATUS_INVALID, /* The buffer is INVALID */ + BUFFER_STATUS_SKIPPED, /* The buffer is not filled with image data */ + BUFFER_STATUS_EXIST, /* The buffer is exist and waiting for filled */ + BUFFER_STATUS_DONE, /* The buffer is filled with image data */ + BUFFER_STATUS_LACK, /* The buffer is unavailable */ + BUFFER_STATUS_DIRTY, /* The buffer is dirty, probably caused by + * LMI leakage + */ + BUFFER_STATUS_MAX /* The buffer STATUS_MAX */ +}; + +enum isp4fw_buffer_source { + /* The buffer is from the stream buffer queue */ + BUFFER_SOURCE_STREAM, +}; + +struct isp4fw_error_code { + u32 code1; + u32 code2; + u32 code3; + u32 code4; + u32 code5; +}; + +/* + * Command Structure for FW + */ + +struct isp4fw_cmd { + u32 cmd_seq_num; + u32 cmd_id; + u32 cmd_param[12]; + u16 cmd_stream_id; + u8 cmd_silent_resp; + u8 reserved; + u32 cmd_check_sum; +}; + +struct isp4fw_resp_cmd_done { + /* + * The host2fw command seqNum. + * To indicate which command this response refers to. + */ + u32 cmd_seq_num; + /* The host2fw command id for host double check. */ + u32 cmd_id; + /* + * Indicate the command process status. + * 0 means success. 1 means fail. 2 means skipped + */ + u16 cmd_status; + /* + * If the cmd_status is 1, that means the command is processed fail, + * host can check the isp4fw_error_code to get the details + * error information + */ + u16 isp4fw_error_code; + /* The response payload will be in different struct type */ + /* according to different cmd done response. */ + u8 payload[36]; +}; + +struct isp4fw_resp_param_package { + u32 package_addr_lo; /* The low 32 bit addr of the pkg address. */ + u32 package_addr_hi; /* The high 32 bit addr of the pkg address. */ + u32 package_size; /* The total pkg size in bytes. */ + u32 package_check_sum; /* The byte sum of the pkg. */ +}; + +struct isp4fw_resp { + u32 resp_seq_num; + u32 resp_id; + union { + struct isp4fw_resp_cmd_done cmd_done; + struct isp4fw_resp_param_package frame_done; + u32 resp_param[12]; + } param; + u8 reserved[4]; + u32 resp_check_sum; +}; + +struct isp4fw_mipi_pipe_path_cfg { + u32 b_enable; + enum isp4fw_sensor_id isp4fw_sensor_id; +}; + +struct isp4fw_isp_pipe_path_cfg { + u32 isp_pipe_id; /* pipe ids for pipeline construction */ +}; + +struct isp4fw_isp_stream_cfg { + /* Isp mipi path */ + struct isp4fw_mipi_pipe_path_cfg mipi_pipe_path_cfg; + /* Isp pipe path */ + struct isp4fw_isp_pipe_path_cfg isp_pipe_path_cfg; + /* enable TNR */ + u32 b_enable_tnr; + /* + * number of frame rta per-processing, + * set to 0 to use fw default value + */ + u32 rta_frames_per_proc; +}; + +struct isp4fw_image_prop { + enum isp4fw_image_format image_format; /* Image format */ + u32 width; /* Width */ + u32 height; /* Height */ + u32 luma_pitch; /* Luma pitch */ + u32 chroma_pitch; /* Chrom pitch */ + enum isp4fw_yuv_range yuv_range; /* YUV value range */ +}; + +struct isp4fw_buffer { + /* A check num for debug usage, host need to */ + /* set the buf_tags to different number */ + u32 buf_tags; + union { + u32 value; + struct { + u32 space : 16; + u32 vmid : 16; + } bit; + } vmid_space; + u32 buf_base_a_lo; /* Low address of buffer A */ + u32 buf_base_a_hi; /* High address of buffer A */ + u32 buf_size_a; /* Buffer size of buffer A */ + + u32 buf_base_b_lo; /* Low address of buffer B */ + u32 buf_base_b_hi; /* High address of buffer B */ + u32 buf_size_b; /* Buffer size of buffer B */ + + u32 buf_base_c_lo; /* Low address of buffer C */ + u32 buf_base_c_hi; /* High address of buffer C */ + u32 buf_size_c; /* Buffer size of buffer C */ +}; + +struct isp4fw_buffer_meta_info { + u32 enabled; /* enabled flag */ + enum isp4fw_buffer_status status; /* BufferStatus */ + struct isp4fw_error_code err; /* err code */ + enum isp4fw_buffer_source source; /* BufferSource */ + struct isp4fw_image_prop image_prop; /* image_prop */ + struct isp4fw_buffer buffer; /* buffer */ +}; + +struct isp4fw_meta_info { + u32 poc; /* frame id */ + u32 fc_id; /* frame ctl id */ + u32 time_stamp_lo; /* time_stamp_lo */ + u32 time_stamp_hi; /* time_stamp_hi */ + struct isp4fw_buffer_meta_info preview; /* preview BufferMetaInfo */ +}; + +struct isp4fw_cmd_send_buffer { + enum isp4fw_buffer_type buffer_type; /* buffer Type */ + struct isp4fw_buffer buffer; /* buffer info */ +}; + +struct isp4fw_cmd_set_out_ch_prop { + enum isp4fw_pipe_out_ch ch; /* ISP pipe out channel */ + struct isp4fw_image_prop image_prop; /* image property */ +}; + +struct isp4fw_cmd_enable_out_ch { + enum isp4fw_pipe_out_ch ch; /* ISP pipe out channel */ + u32 is_enable; /* If enable channel or not */ +}; + +struct isp4fw_cmd_set_stream_cfg { + struct isp4fw_isp_stream_cfg stream_cfg; /* stream path config */ +}; + +#endif diff --git a/drivers/media/platform/amd/isp4/isp4_interface.c b/drivers/med= ia/platform/amd/isp4/isp4_interface.c new file mode 100644 index 000000000000..52dcca57ce2e --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_interface.c @@ -0,0 +1,955 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include + +#include "isp4_fw_cmd_resp.h" +#include "isp4_hw_reg.h" +#include "isp4_interface.h" + +#define ISP4IF_FW_RESP_RB_IRQ_EN_MASK \ + (ISP_SYS_INT0_EN__SYS_INT_RINGBUFFER_WPT9_EN_MASK | \ + ISP_SYS_INT0_EN__SYS_INT_RINGBUFFER_WPT10_EN_MASK | \ + ISP_SYS_INT0_EN__SYS_INT_RINGBUFFER_WPT11_EN_MASK | \ + ISP_SYS_INT0_EN__SYS_INT_RINGBUFFER_WPT12_EN_MASK) + +struct isp4if_rb_config { + const char *name; + u32 index; + u32 reg_rptr; + u32 reg_wptr; + u32 reg_base_lo; + u32 reg_base_hi; + u32 reg_size; + u32 val_size; + u64 base_mc_addr; + void *base_sys_addr; +}; + +/* FW cmd ring buffer configuration */ +static struct isp4if_rb_config + isp4if_cmd_rb_config[ISP4IF_STREAM_ID_MAX] =3D { + { + .name =3D "CMD_RB_GBL0", + .index =3D 3, + .reg_rptr =3D ISP_RB_RPTR4, + .reg_wptr =3D ISP_RB_WPTR4, + .reg_base_lo =3D ISP_RB_BASE_LO4, + .reg_base_hi =3D ISP_RB_BASE_HI4, + .reg_size =3D ISP_RB_SIZE4, + }, + { + .name =3D "CMD_RB_STR1", + .index =3D 0, + .reg_rptr =3D ISP_RB_RPTR1, + .reg_wptr =3D ISP_RB_WPTR1, + .reg_base_lo =3D ISP_RB_BASE_LO1, + .reg_base_hi =3D ISP_RB_BASE_HI1, + .reg_size =3D ISP_RB_SIZE1, + }, + { + .name =3D "CMD_RB_STR2", + .index =3D 1, + .reg_rptr =3D ISP_RB_RPTR2, + .reg_wptr =3D ISP_RB_WPTR2, + .reg_base_lo =3D ISP_RB_BASE_LO2, + .reg_base_hi =3D ISP_RB_BASE_HI2, + .reg_size =3D ISP_RB_SIZE2, + }, + { + .name =3D "CMD_RB_STR3", + .index =3D 2, + .reg_rptr =3D ISP_RB_RPTR3, + .reg_wptr =3D ISP_RB_WPTR3, + .reg_base_lo =3D ISP_RB_BASE_LO3, + .reg_base_hi =3D ISP_RB_BASE_HI3, + .reg_size =3D ISP_RB_SIZE3, + }, +}; + +/* FW resp ring buffer configuration */ +static struct isp4if_rb_config + isp4if_resp_rb_config[ISP4IF_STREAM_ID_MAX] =3D { + { + .name =3D "RES_RB_GBL0", + .index =3D 3, + .reg_rptr =3D ISP_RB_RPTR12, + .reg_wptr =3D ISP_RB_WPTR12, + .reg_base_lo =3D ISP_RB_BASE_LO12, + .reg_base_hi =3D ISP_RB_BASE_HI12, + .reg_size =3D ISP_RB_SIZE12, + }, + { + .name =3D "RES_RB_STR1", + .index =3D 0, + .reg_rptr =3D ISP_RB_RPTR9, + .reg_wptr =3D ISP_RB_WPTR9, + .reg_base_lo =3D ISP_RB_BASE_LO9, + .reg_base_hi =3D ISP_RB_BASE_HI9, + .reg_size =3D ISP_RB_SIZE9, + }, + { + .name =3D "RES_RB_STR2", + .index =3D 1, + .reg_rptr =3D ISP_RB_RPTR10, + .reg_wptr =3D ISP_RB_WPTR10, + .reg_base_lo =3D ISP_RB_BASE_LO10, + .reg_base_hi =3D ISP_RB_BASE_HI10, + .reg_size =3D ISP_RB_SIZE10, + }, + { + .name =3D "RES_RB_STR3", + .index =3D 2, + .reg_rptr =3D ISP_RB_RPTR11, + .reg_wptr =3D ISP_RB_WPTR11, + .reg_base_lo =3D ISP_RB_BASE_LO11, + .reg_base_hi =3D ISP_RB_BASE_HI11, + .reg_size =3D ISP_RB_SIZE11, + }, +}; + +/* FW log ring buffer configuration */ +static struct isp4if_rb_config isp4if_log_rb_config =3D { + .name =3D "LOG_RB", + .index =3D 0, + .reg_rptr =3D ISP_LOG_RB_RPTR0, + .reg_wptr =3D ISP_LOG_RB_WPTR0, + .reg_base_lo =3D ISP_LOG_RB_BASE_LO0, + .reg_base_hi =3D ISP_LOG_RB_BASE_HI0, + .reg_size =3D ISP_LOG_RB_SIZE0, +}; + +static struct isp4if_gpu_mem_info *isp4if_gpu_mem_alloc(struct isp4_interf= ace *ispif, u32 mem_size) +{ + struct isp4if_gpu_mem_info *mem_info; + struct device *dev =3D ispif->dev; + int ret; + + if (!mem_size) + return NULL; + + mem_info =3D kzalloc(sizeof(*mem_info), GFP_KERNEL); + if (!mem_info) + return NULL; + + mem_info->mem_size =3D mem_size; + ret =3D isp_kernel_buffer_alloc(dev, mem_info->mem_size, &mem_info->mem_h= andle, + &mem_info->gpu_mc_addr, &mem_info->sys_addr); + if (ret) { + kfree(mem_info); + return NULL; + } + + return mem_info; +} + +static int isp4if_gpu_mem_free(struct isp4_interface *ispif, struct isp4if= _gpu_mem_info *mem_info) +{ + struct device *dev =3D ispif->dev; + + if (!mem_info) { + dev_err(dev, "invalid mem_info\n"); + return -EINVAL; + } + + isp_kernel_buffer_free(&mem_info->mem_handle, &mem_info->gpu_mc_addr, &me= m_info->sys_addr); + + kfree(mem_info); + + return 0; +} + +static int isp4if_dealloc_fw_gpumem(struct isp4_interface *ispif) +{ + int i; + + if (ispif->fw_mem_pool) { + isp4if_gpu_mem_free(ispif, ispif->fw_mem_pool); + ispif->fw_mem_pool =3D NULL; + } + + if (ispif->fw_cmd_resp_buf) { + isp4if_gpu_mem_free(ispif, ispif->fw_cmd_resp_buf); + ispif->fw_cmd_resp_buf =3D NULL; + } + + if (ispif->fw_log_buf) { + isp4if_gpu_mem_free(ispif, ispif->fw_log_buf); + ispif->fw_log_buf =3D NULL; + } + + for (i =3D 0; i < ISP4IF_MAX_STREAM_BUF_COUNT; i++) { + if (ispif->metainfo_buf_pool[i]) { + isp4if_gpu_mem_free(ispif, ispif->metainfo_buf_pool[i]); + ispif->metainfo_buf_pool[i] =3D NULL; + } + } + + return 0; +} + +static int isp4if_alloc_fw_gpumem(struct isp4_interface *ispif) +{ + struct device *dev =3D ispif->dev; + unsigned int i; + + ispif->fw_mem_pool =3D isp4if_gpu_mem_alloc(ispif, FW_MEMORY_POOL_SIZE); + if (!ispif->fw_mem_pool) + goto error_no_memory; + + ispif->fw_cmd_resp_buf =3D + isp4if_gpu_mem_alloc(ispif, ISP4IF_RB_PMBMAP_MEM_SIZE); + if (!ispif->fw_cmd_resp_buf) + goto error_no_memory; + + ispif->fw_log_buf =3D + isp4if_gpu_mem_alloc(ispif, ISP4IF_FW_LOG_RINGBUF_SIZE); + if (!ispif->fw_log_buf) + goto error_no_memory; + + for (i =3D 0; i < ISP4IF_MAX_STREAM_BUF_COUNT; i++) { + ispif->metainfo_buf_pool[i] =3D + isp4if_gpu_mem_alloc(ispif, + ISP4IF_META_INFO_BUF_SIZE); + if (!ispif->metainfo_buf_pool[i]) + goto error_no_memory; + } + + return 0; + +error_no_memory: + dev_err(dev, "failed to allocate gpu memory\n"); + return -ENOMEM; +} + +static u32 isp4if_compute_check_sum(u8 *buf, u32 buf_size) +{ + u32 checksum =3D 0; + u8 *surplus_ptr; + u32 *buffer; + u32 i; + + buffer =3D (u32 *)buf; + for (i =3D 0; i < buf_size / sizeof(u32); i++) + checksum +=3D buffer[i]; + + surplus_ptr =3D (u8 *)&buffer[i]; + /* add surplus data crc checksum */ + for (i =3D 0; i < buf_size % sizeof(u32); i++) + checksum +=3D surplus_ptr[i]; + + return checksum; +} + +void isp4if_clear_cmdq(struct isp4_interface *ispif) +{ + struct isp4if_cmd_element *buf_node =3D NULL; + struct isp4if_cmd_element *tmp_node =3D NULL; + + guard(mutex)(&ispif->cmdq_mutex); + + list_for_each_entry_safe(buf_node, tmp_node, &ispif->cmdq, list) { + list_del(&buf_node->list); + kfree(buf_node); + } +} + +static bool isp4if_is_cmdq_rb_full(struct isp4_interface *ispif, enum isp4= if_stream_id cmd_buf_idx) +{ + struct isp4if_rb_config *rb_config; + u32 rd_ptr, wr_ptr; + u32 new_wr_ptr; + u32 rreg; + u32 wreg; + u32 len; + + rb_config =3D &isp4if_cmd_rb_config[cmd_buf_idx]; + rreg =3D rb_config->reg_rptr; + wreg =3D rb_config->reg_wptr; + len =3D rb_config->val_size; + + rd_ptr =3D isp4hw_rreg(ispif->mmio, rreg); + wr_ptr =3D isp4hw_rreg(ispif->mmio, wreg); + + new_wr_ptr =3D wr_ptr + sizeof(struct isp4fw_cmd); + + if (wr_ptr >=3D rd_ptr) { + if (new_wr_ptr < len) { + return false; + } else if (new_wr_ptr =3D=3D len) { + if (rd_ptr =3D=3D 0) + return true; + + return false; + } + + new_wr_ptr -=3D len; + if (new_wr_ptr < rd_ptr) + return false; + + return true; + } + + if (new_wr_ptr < rd_ptr) + return false; + + return true; +} + +static struct isp4if_cmd_element *isp4if_append_cmd_2_cmdq(struct isp4_int= erface *ispif, + struct isp4if_cmd_element *cmd_ele) +{ + struct isp4if_cmd_element *copy_command =3D NULL; + + copy_command =3D kmemdup(cmd_ele, sizeof(*cmd_ele), GFP_KERNEL); + if (!copy_command) + return NULL; + + guard(mutex)(&ispif->cmdq_mutex); + + list_add_tail(©_command->list, &ispif->cmdq); + + return copy_command; +} + +struct isp4if_cmd_element *isp4if_rm_cmd_from_cmdq(struct isp4_interface *= ispif, u32 seq_num, + u32 cmd_id) +{ + struct isp4if_cmd_element *buf_node =3D NULL; + struct isp4if_cmd_element *tmp_node =3D NULL; + + guard(mutex)(&ispif->cmdq_mutex); + + list_for_each_entry_safe(buf_node, tmp_node, &ispif->cmdq, list) { + if (buf_node->seq_num =3D=3D seq_num && + buf_node->cmd_id =3D=3D cmd_id) { + list_del(&buf_node->list); + return buf_node; + } + } + + return NULL; +} + +static int isp4if_insert_isp_fw_cmd(struct isp4_interface *ispif, enum isp= 4if_stream_id stream, + struct isp4fw_cmd *cmd) +{ + struct isp4if_rb_config *rb_config; + struct device *dev =3D ispif->dev; + u8 *mem_sys; + u32 wr_ptr; + u32 rd_ptr; + u32 rreg; + u32 wreg; + u32 len; + + rb_config =3D &isp4if_cmd_rb_config[stream]; + rreg =3D rb_config->reg_rptr; + wreg =3D rb_config->reg_wptr; + mem_sys =3D (u8 *)rb_config->base_sys_addr; + len =3D rb_config->val_size; + + if (isp4if_is_cmdq_rb_full(ispif, stream)) { + dev_err(dev, "fail no cmdslot (%d)\n", stream); + return -EINVAL; + } + + wr_ptr =3D isp4hw_rreg(ispif->mmio, wreg); + rd_ptr =3D isp4hw_rreg(ispif->mmio, rreg); + + if (rd_ptr > len) { + dev_err(dev, "fail (%u),rd_ptr %u(should<=3D%u),wr_ptr %u\n", + stream, rd_ptr, len, wr_ptr); + return -EINVAL; + } + + if (wr_ptr > len) { + dev_err(dev, "fail (%u),wr_ptr %u(should<=3D%u), rd_ptr %u\n", + stream, wr_ptr, len, rd_ptr); + return -EINVAL; + } + + if (wr_ptr < rd_ptr) { + memcpy((mem_sys + wr_ptr), + (u8 *)cmd, sizeof(struct isp4fw_cmd)); + } else { + if ((len - wr_ptr) >=3D (sizeof(struct isp4fw_cmd))) { + memcpy((mem_sys + wr_ptr), + (u8 *)cmd, sizeof(struct isp4fw_cmd)); + } else { + u32 size; + u8 *src; + + src =3D (u8 *)cmd; + size =3D len - wr_ptr; + + memcpy((mem_sys + wr_ptr), src, size); + + src +=3D size; + size =3D sizeof(struct isp4fw_cmd) - size; + memcpy((mem_sys), src, size); + } + } + + wr_ptr +=3D sizeof(struct isp4fw_cmd); + if (wr_ptr >=3D len) + wr_ptr -=3D len; + + isp4hw_wreg(ispif->mmio, wreg, wr_ptr); + + return 0; +} + +static inline enum isp4if_stream_id isp4if_get_fw_stream(u32 cmd_id) +{ + return ISP4IF_STREAM_ID_1; +} + +static int isp4if_send_fw_cmd(struct isp4_interface *ispif, u32 cmd_id, vo= id *package, + u32 package_size, wait_queue_head_t *wq, u32 *wq_cond, u32 *seq) +{ + enum isp4if_stream_id stream =3D isp4if_get_fw_stream(cmd_id); + struct isp4if_cmd_element command_element =3D {}; + struct isp4if_gpu_mem_info *gpu_mem =3D NULL; + struct isp4if_cmd_element *cmd_ele =3D NULL; + struct isp4if_rb_config *rb_config; + struct device *dev =3D ispif->dev; + struct isp4fw_cmd cmd =3D {}; + u64 package_base =3D 0; + u32 seq_num; + u32 rreg; + u32 wreg; + int ret; + + if (package_size > sizeof(cmd.cmd_param)) { + dev_err(dev, "fail pkgsize(%u)>%zu cmd:0x%x,stream %d\n", + package_size, sizeof(cmd.cmd_param), cmd_id, stream); + return -EINVAL; + } + + rb_config =3D &isp4if_resp_rb_config[stream]; + rreg =3D rb_config->reg_rptr; + wreg =3D rb_config->reg_wptr; + + guard(mutex)(&ispif->isp4if_mutex); + + ret =3D read_poll_timeout(isp4if_is_cmdq_rb_full, ret, !ret, ISP4IF_MAX_S= LEEP_TIME * 1000, + ISP4IF_MAX_SLEEP_COUNT * ISP4IF_MAX_SLEEP_TIME * 1000, false, + ispif, stream); + + if (ret) { + u32 rd_ptr =3D isp4hw_rreg(ispif->mmio, rreg); + u32 wr_ptr =3D isp4hw_rreg(ispif->mmio, wreg); + + dev_err(dev, + "failed to get free cmdq slot, stream (%d),rd %u, wr %u\n", + stream, rd_ptr, wr_ptr); + return -ETIMEDOUT; + } + + cmd.cmd_id =3D cmd_id; + switch (stream) { + case ISP4IF_STREAM_ID_GLOBAL: + cmd.cmd_stream_id =3D STREAM_ID_INVALID; + break; + case ISP4IF_STREAM_ID_1: + cmd.cmd_stream_id =3D STREAM_ID_1; + break; + default: + dev_err(dev, "fail bad stream id %d\n", stream); + return -EINVAL; + } + + if (package && package_size) + memcpy(cmd.cmd_param, package, package_size); + + seq_num =3D ispif->host2fw_seq_num++; + cmd.cmd_seq_num =3D seq_num; + cmd.cmd_check_sum =3D + isp4if_compute_check_sum((u8 *)&cmd, sizeof(cmd) - 4); + + if (seq) + *seq =3D seq_num; + command_element.seq_num =3D seq_num; + command_element.cmd_id =3D cmd_id; + command_element.mc_addr =3D package_base; + command_element.wq =3D wq; + command_element.wq_cond =3D wq_cond; + command_element.gpu_pkg =3D gpu_mem; + command_element.stream =3D stream; + /* + * only append the fw cmd to queue when its response needs to be waited f= or, + * currently there are only two such commands, disable channel and stop s= tream + * which are only sent after close camera + */ + if (wq && wq_cond) { + cmd_ele =3D isp4if_append_cmd_2_cmdq(ispif, &command_element); + if (!cmd_ele) { + dev_err(dev, "fail for isp_append_cmd_2_cmdq\n"); + return -ENOMEM; + } + } + + ret =3D isp4if_insert_isp_fw_cmd(ispif, stream, &cmd); + if (ret) { + dev_err(dev, "fail for insert_isp_fw_cmd camId (0x%08x)\n", cmd_id); + if (cmd_ele) { + isp4if_rm_cmd_from_cmdq(ispif, cmd_ele->seq_num, cmd_ele->cmd_id); + kfree(cmd_ele); + } + } + + return ret; +} + +static int isp4if_send_buffer(struct isp4_interface *ispif, struct isp4if_= img_buf_info *buf_info) +{ + struct isp4fw_cmd_send_buffer cmd =3D {}; + + cmd.buffer_type =3D BUFFER_TYPE_PREVIEW; + cmd.buffer.vmid_space.bit.vmid =3D 0; + cmd.buffer.vmid_space.bit.space =3D ADDR_SPACE_TYPE_GPU_VA; + isp4if_split_addr64(buf_info->planes[0].mc_addr, + &cmd.buffer.buf_base_a_lo, + &cmd.buffer.buf_base_a_hi); + cmd.buffer.buf_size_a =3D buf_info->planes[0].len; + + isp4if_split_addr64(buf_info->planes[1].mc_addr, + &cmd.buffer.buf_base_b_lo, + &cmd.buffer.buf_base_b_hi); + cmd.buffer.buf_size_b =3D buf_info->planes[1].len; + + isp4if_split_addr64(buf_info->planes[2].mc_addr, + &cmd.buffer.buf_base_c_lo, + &cmd.buffer.buf_base_c_hi); + cmd.buffer.buf_size_c =3D buf_info->planes[2].len; + + return isp4if_send_fw_cmd(ispif, CMD_ID_SEND_BUFFER, &cmd, + sizeof(cmd), NULL, NULL, NULL); +} + +static void isp4if_init_rb_config(struct isp4_interface *ispif, struct isp= 4if_rb_config *rb_config) +{ + u32 lo; + u32 hi; + + isp4if_split_addr64(rb_config->base_mc_addr, &lo, &hi); + + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), + rb_config->reg_rptr, 0x0); + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), + rb_config->reg_wptr, 0x0); + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), + rb_config->reg_base_lo, lo); + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), + rb_config->reg_base_hi, hi); + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), + rb_config->reg_size, rb_config->val_size); +} + +static int isp4if_fw_init(struct isp4_interface *ispif) +{ + struct isp4if_rb_config *rb_config; + u32 offset; + int i; + + /* initialize CMD_RB streams */ + for (i =3D 0; i < ISP4IF_STREAM_ID_MAX; i++) { + rb_config =3D (isp4if_cmd_rb_config + i); + offset =3D ispif->aligned_rb_chunk_size * + (rb_config->index + ispif->cmd_rb_base_index); + + rb_config->val_size =3D ISP4IF_FW_CMD_BUF_SIZE; + rb_config->base_sys_addr =3D + (u8 *)ispif->fw_cmd_resp_buf->sys_addr + offset; + rb_config->base_mc_addr =3D + ispif->fw_cmd_resp_buf->gpu_mc_addr + offset; + + isp4if_init_rb_config(ispif, rb_config); + } + + /* initialize RESP_RB streams */ + for (i =3D 0; i < ISP4IF_STREAM_ID_MAX; i++) { + rb_config =3D (isp4if_resp_rb_config + i); + offset =3D ispif->aligned_rb_chunk_size * + (rb_config->index + ispif->resp_rb_base_index); + + rb_config->val_size =3D ISP4IF_FW_CMD_BUF_SIZE; + rb_config->base_sys_addr =3D + (u8 *)ispif->fw_cmd_resp_buf->sys_addr + offset; + rb_config->base_mc_addr =3D + ispif->fw_cmd_resp_buf->gpu_mc_addr + offset; + + isp4if_init_rb_config(ispif, rb_config); + } + + /* initialize LOG_RB stream */ + rb_config =3D &isp4if_log_rb_config; + rb_config->val_size =3D ISP4IF_FW_LOG_RINGBUF_SIZE; + rb_config->base_mc_addr =3D ispif->fw_log_buf->gpu_mc_addr; + rb_config->base_sys_addr =3D ispif->fw_log_buf->sys_addr; + + isp4if_init_rb_config(ispif, rb_config); + + return 0; +} + +static int isp4if_wait_fw_ready(struct isp4_interface *ispif, u32 isp_stat= us_addr) +{ + struct device *dev =3D ispif->dev; + u32 timeout_ms =3D 100; + u32 interval_ms =3D 1; + u32 reg_val; + + /* wait for FW initialize done! */ + if (!read_poll_timeout(isp4hw_rreg, reg_val, reg_val & ISP_STATUS__CCPU_R= EPORT_MASK, + interval_ms * 1000, timeout_ms * 1000, false, + GET_ISP4IF_REG_BASE(ispif), isp_status_addr)) + return 0; + + dev_err(dev, "ISP CCPU FW boot failed\n"); + + return -ETIME; +} + +static void isp4if_enable_ccpu(struct isp4_interface *ispif) +{ + u32 reg_val; + + reg_val =3D isp4hw_rreg(GET_ISP4IF_REG_BASE(ispif), ISP_SOFT_RESET); + reg_val &=3D (~ISP_SOFT_RESET__CCPU_SOFT_RESET_MASK); + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), ISP_SOFT_RESET, reg_val); + + usleep_range(100, 150); + + reg_val =3D isp4hw_rreg(GET_ISP4IF_REG_BASE(ispif), ISP_CCPU_CNTL); + reg_val &=3D (~ISP_CCPU_CNTL__CCPU_HOST_SOFT_RST_MASK); + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), ISP_CCPU_CNTL, reg_val); +} + +static void isp4if_disable_ccpu(struct isp4_interface *ispif) +{ + u32 reg_val; + + reg_val =3D isp4hw_rreg(GET_ISP4IF_REG_BASE(ispif), ISP_CCPU_CNTL); + reg_val |=3D ISP_CCPU_CNTL__CCPU_HOST_SOFT_RST_MASK; + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), ISP_CCPU_CNTL, reg_val); + + usleep_range(100, 150); + + reg_val =3D isp4hw_rreg(GET_ISP4IF_REG_BASE(ispif), ISP_SOFT_RESET); + reg_val |=3D ISP_SOFT_RESET__CCPU_SOFT_RESET_MASK; + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), ISP_SOFT_RESET, reg_val); +} + +static int isp4if_fw_boot(struct isp4_interface *ispif) +{ + struct device *dev =3D ispif->dev; + + if (ispif->status !=3D ISP4IF_STATUS_PWR_ON) { + dev_err(dev, "invalid isp power status %d\n", ispif->status); + return -EINVAL; + } + + isp4if_disable_ccpu(ispif); + + isp4if_fw_init(ispif); + + /* clear ccpu status */ + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), ISP_STATUS, 0x0); + + isp4if_enable_ccpu(ispif); + + if (isp4if_wait_fw_ready(ispif, ISP_STATUS)) { + isp4if_disable_ccpu(ispif); + return -EINVAL; + } + + /* enable interrupts */ + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), ISP_SYS_INT0_EN, + ISP4IF_FW_RESP_RB_IRQ_EN_MASK); + + ispif->status =3D ISP4IF_STATUS_FW_RUNNING; + + dev_dbg(dev, "ISP CCPU FW boot success\n"); + + return 0; +} + +int isp4if_f2h_resp(struct isp4_interface *ispif, enum isp4if_stream_id st= ream, void *resp) +{ + struct isp4fw_resp *response =3D resp; + struct isp4if_rb_config *rb_config; + struct device *dev =3D ispif->dev; + u32 rd_ptr_dbg; + u32 wr_ptr_dbg; + void *mem_sys; + u64 mem_addr; + u32 checksum; + u32 rd_ptr; + u32 wr_ptr; + u32 rreg; + u32 wreg; + u32 len; + + rb_config =3D &isp4if_resp_rb_config[stream]; + rreg =3D rb_config->reg_rptr; + wreg =3D rb_config->reg_wptr; + mem_sys =3D rb_config->base_sys_addr; + mem_addr =3D rb_config->base_mc_addr; + len =3D rb_config->val_size; + + rd_ptr =3D isp4hw_rreg(GET_ISP4IF_REG_BASE(ispif), rreg); + wr_ptr =3D isp4hw_rreg(GET_ISP4IF_REG_BASE(ispif), wreg); + rd_ptr_dbg =3D rd_ptr; + wr_ptr_dbg =3D wr_ptr; + + if (rd_ptr > len) { + dev_err(dev, "fail (%u),rd_ptr %u(should<=3D%u),wr_ptr %u\n", + stream, rd_ptr, len, wr_ptr); + return -EINVAL; + } + + if (wr_ptr > len) { + dev_err(dev, "fail (%u),wr_ptr %u(should<=3D%u), rd_ptr %u\n", + stream, wr_ptr, len, rd_ptr); + return -EINVAL; + } + + if (rd_ptr < wr_ptr) { + if ((wr_ptr - rd_ptr) >=3D (sizeof(struct isp4fw_resp))) { + memcpy((u8 *)response, (u8 *)mem_sys + rd_ptr, + sizeof(struct isp4fw_resp)); + + rd_ptr +=3D sizeof(struct isp4fw_resp); + if (rd_ptr < len) { + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), + rreg, rd_ptr); + } else { + dev_err(dev, "(%u),rd %u(should<=3D%u),wr %u\n", + stream, rd_ptr, len, wr_ptr); + return -EINVAL; + } + + } else { + dev_err(dev, "sth wrong with wptr and rptr\n"); + return -EINVAL; + } + } else if (rd_ptr > wr_ptr) { + u32 size; + u8 *dst; + + dst =3D (u8 *)response; + + size =3D len - rd_ptr; + if (size > sizeof(struct isp4fw_resp)) { + mem_addr +=3D rd_ptr; + memcpy((u8 *)response, + (u8 *)(mem_sys) + rd_ptr, + sizeof(struct isp4fw_resp)); + rd_ptr +=3D sizeof(struct isp4fw_resp); + if (rd_ptr < len) { + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), + rreg, rd_ptr); + } else { + dev_err(dev, "(%u),rd %u(should<=3D%u),wr %u\n", + stream, rd_ptr, len, wr_ptr); + return -EINVAL; + } + + } else { + if ((size + wr_ptr) < (sizeof(struct isp4fw_resp))) { + dev_err(dev, "sth wrong with wptr and rptr1\n"); + return -EINVAL; + } + + memcpy(dst, (u8 *)(mem_sys) + rd_ptr, size); + + dst +=3D size; + size =3D sizeof(struct isp4fw_resp) - size; + if (size) + memcpy(dst, (u8 *)(mem_sys), size); + rd_ptr =3D size; + if (rd_ptr < len) { + isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), + rreg, rd_ptr); + } else { + dev_err(dev, "(%u),rd %u(should<=3D%u),wr %u\n", + stream, rd_ptr, len, wr_ptr); + return -EINVAL; + } + } + } else { + return -ETIME; + } + + checksum =3D isp4if_compute_check_sum((u8 *)response, sizeof(struct isp4f= w_resp) - 4); + + if (checksum !=3D response->resp_check_sum) { + dev_err(dev, "resp checksum 0x%x,should 0x%x,rptr %u,wptr %u\n", + checksum, response->resp_check_sum, rd_ptr_dbg, wr_ptr_dbg); + + dev_err(dev, "(%u), seqNo %u, resp_id (0x%x)\n", stream, + response->resp_seq_num, + response->resp_id); + + return -EINVAL; + } + + return 0; +} + +int isp4if_send_command(struct isp4_interface *ispif, u32 cmd_id, void *pa= ckage, u32 package_size) +{ + return isp4if_send_fw_cmd(ispif, cmd_id, package, package_size, NULL, NUL= L, NULL); +} + +int isp4if_send_command_sync(struct isp4_interface *ispif, u32 cmd_id, voi= d *package, + u32 package_size, u32 timeout) +{ + struct device *dev =3D ispif->dev; + DECLARE_WAIT_QUEUE_HEAD(cmd_wq); + u32 wq_cond =3D 0; + int ret; + u32 seq; + + ret =3D isp4if_send_fw_cmd(ispif, cmd_id, package, package_size, &cmd_wq,= &wq_cond, &seq); + + if (ret) { + dev_err(dev, "send fw cmd fail %d\n", ret); + return ret; + } + + ret =3D wait_event_timeout(cmd_wq, wq_cond !=3D 0, msecs_to_jiffies(timeo= ut)); + if (ret =3D=3D 0) { + struct isp4if_cmd_element *ele; + + ele =3D isp4if_rm_cmd_from_cmdq(ispif, seq, cmd_id); + kfree(ele); + return -ETIMEDOUT; + } + + return 0; +} + +void isp4if_clear_bufq(struct isp4_interface *ispif) +{ + struct isp4if_img_buf_node *buf_node =3D NULL; + struct isp4if_img_buf_node *tmp_node =3D NULL; + + guard(mutex)(&ispif->bufq_mutex); + + list_for_each_entry_safe(buf_node, tmp_node, &ispif->bufq, node) { + list_del(&buf_node->node); + kfree(buf_node); + } +} + +void isp4if_dealloc_buffer_node(struct isp4if_img_buf_node *buf_node) +{ + kfree(buf_node); +} + +struct isp4if_img_buf_node *isp4if_alloc_buffer_node(struct isp4if_img_buf= _info *buf_info) +{ + struct isp4if_img_buf_node *node =3D NULL; + + node =3D kmalloc(sizeof(*node), GFP_KERNEL); + if (node) + node->buf_info =3D *buf_info; + + return node; +}; + +struct isp4if_img_buf_node *isp4if_dequeue_buffer(struct isp4_interface *i= spif) +{ + struct isp4if_img_buf_node *buf_node =3D NULL; + + guard(mutex)(&ispif->bufq_mutex); + + buf_node =3D list_first_entry_or_null(&ispif->bufq, typeof(*buf_node), no= de); + if (buf_node) + list_del(&buf_node->node); + + return buf_node; +} + +int isp4if_queue_buffer(struct isp4_interface *ispif, struct isp4if_img_bu= f_node *buf_node) +{ + int ret; + + ret =3D isp4if_send_buffer(ispif, &buf_node->buf_info); + if (ret) + return ret; + + guard(mutex)(&ispif->bufq_mutex); + + list_add_tail(&buf_node->node, &ispif->bufq); + + return 0; +} + +int isp4if_stop(struct isp4_interface *ispif) +{ + isp4if_disable_ccpu(ispif); + + isp4if_dealloc_fw_gpumem(ispif); + + return 0; +} + +int isp4if_start(struct isp4_interface *ispif) +{ + int ret; + + ret =3D isp4if_alloc_fw_gpumem(ispif); + if (ret) + return -ENOMEM; + + ret =3D isp4if_fw_boot(ispif); + if (ret) + goto failed_fw_boot; + + return 0; + +failed_fw_boot: + isp4if_dealloc_fw_gpumem(ispif); + return ret; +} + +int isp4if_deinit(struct isp4_interface *ispif) +{ + isp4if_clear_cmdq(ispif); + + isp4if_clear_bufq(ispif); + + mutex_destroy(&ispif->cmdq_mutex); + mutex_destroy(&ispif->bufq_mutex); + mutex_destroy(&ispif->isp4if_mutex); + + return 0; +} + +int isp4if_init(struct isp4_interface *ispif, struct device *dev, void __i= omem *isp_mmip) +{ + ispif->dev =3D dev; + ispif->mmio =3D isp_mmip; + + ispif->cmd_rb_base_index =3D 0; + ispif->resp_rb_base_index =3D ISP4IF_RESP_CHAN_TO_RB_OFFSET - 1; + ispif->aligned_rb_chunk_size =3D ISP4IF_RB_PMBMAP_MEM_CHUNK & 0xffffffc0; + + mutex_init(&ispif->cmdq_mutex); /* used for cmdq access */ + mutex_init(&ispif->bufq_mutex); /* used for bufq access */ + mutex_init(&ispif->isp4if_mutex); /* used for commands sent to ispfw */ + + INIT_LIST_HEAD(&ispif->cmdq); + INIT_LIST_HEAD(&ispif->bufq); + + return 0; +} diff --git a/drivers/media/platform/amd/isp4/isp4_interface.h b/drivers/med= ia/platform/amd/isp4/isp4_interface.h new file mode 100644 index 000000000000..5b94985cdc44 --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_interface.h @@ -0,0 +1,149 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _ISP4_INTERFACE_ +#define _ISP4_INTERFACE_ + +#define ISP4IF_RB_MAX (25) +#define ISP4IF_RESP_CHAN_TO_RB_OFFSET (9) +#define ISP4IF_RB_PMBMAP_MEM_SIZE (16 * 1024 * 1024 - 1) +#define ISP4IF_RB_PMBMAP_MEM_CHUNK (ISP4IF_RB_PMBMAP_MEM_SIZE \ + / (ISP4IF_RB_MAX - 1)) +#define ISP4IF_HOST2FW_COMMAND_SIZE (sizeof(struct isp4fw_cmd)) +#define ISP4IF_FW_CMD_BUF_COUNT 4 +#define ISP4IF_FW_RESP_BUF_COUNT 4 +#define ISP4IF_MAX_NUM_HOST2FW_COMMAND (40) +#define ISP4IF_FW_CMD_BUF_SIZE (ISP4IF_MAX_NUM_HOST2FW_COMMAND \ + * ISP4IF_HOST2FW_COMMAND_SIZE) +#define ISP4IF_MAX_SLEEP_COUNT (10) +#define ISP4IF_MAX_SLEEP_TIME (33) + +#define ISP4IF_META_INFO_BUF_SIZE ALIGN(sizeof(struct isp4fw_meta_info), 0= x8000) +#define ISP4IF_MAX_STREAM_BUF_COUNT 8 + +#define ISP4IF_FW_LOG_RINGBUF_SIZE (2 * 1024 * 1024) + +#define ISP4IF_MAX_CMD_RESPONSE_BUF_SIZE (4 * 1024) + +#define GET_ISP4IF_REG_BASE(ispif) (((ispif))->mmio) + +enum isp4if_stream_id { + ISP4IF_STREAM_ID_GLOBAL =3D 0, + ISP4IF_STREAM_ID_1 =3D 1, + ISP4IF_STREAM_ID_MAX =3D 4 +}; + +enum isp4if_status { + ISP4IF_STATUS_PWR_OFF, + ISP4IF_STATUS_PWR_ON, + ISP4IF_STATUS_FW_RUNNING, + ISP4IF_FSM_STATUS_MAX +}; + +struct isp4if_gpu_mem_info { + u32 mem_domain; + u64 mem_size; + u32 mem_align; + u64 gpu_mc_addr; + void *sys_addr; + void *mem_handle; +}; + +struct isp4if_img_buf_info { + struct { + void *sys_addr; + u64 mc_addr; + u32 len; + } planes[3]; +}; + +struct isp4if_img_buf_node { + struct list_head node; + struct isp4if_img_buf_info buf_info; +}; + +struct isp4if_cmd_element { + struct list_head list; + u32 seq_num; + u32 cmd_id; + enum isp4if_stream_id stream; + u64 mc_addr; + wait_queue_head_t *wq; + u32 *wq_cond; + struct isp4if_gpu_mem_info *gpu_pkg; +}; + +struct isp4_interface { + struct device *dev; + void __iomem *mmio; + + struct mutex cmdq_mutex; /* used for cmdq access */ + struct mutex bufq_mutex; /* used for bufq access */ + struct mutex isp4if_mutex; /* used to send fw cmd and read fw log */ + + struct list_head cmdq; /* commands sent to fw */ + struct list_head bufq; /* buffers sent to fw */ + + enum isp4if_status status; + u32 host2fw_seq_num; + + /* FW ring buffer configs */ + u32 cmd_rb_base_index; + u32 resp_rb_base_index; + u32 aligned_rb_chunk_size; + + /* ISP fw buffers */ + struct isp4if_gpu_mem_info *fw_log_buf; + struct isp4if_gpu_mem_info *fw_cmd_resp_buf; + struct isp4if_gpu_mem_info *fw_mem_pool; + struct isp4if_gpu_mem_info * + metainfo_buf_pool[ISP4IF_MAX_STREAM_BUF_COUNT]; +}; + +static inline void isp4if_split_addr64(u64 addr, u32 *lo, u32 *hi) +{ + if (lo) + *lo =3D addr & 0xffffffff; + if (hi) + *hi =3D addr >> 32; +} + +static inline u64 isp4if_join_addr64(u32 lo, u32 hi) +{ + return (((u64)hi) << 32) | (u64)lo; +} + +int isp4if_f2h_resp(struct isp4_interface *ispif, enum isp4if_stream_id st= ream, void *response); + +int isp4if_send_command(struct isp4_interface *ispif, u32 cmd_id, void *pa= ckage, + u32 package_size); + +int isp4if_send_command_sync(struct isp4_interface *ispif, u32 cmd_id, voi= d *package, + u32 package_size, u32 timeout); + +struct isp4if_cmd_element *isp4if_rm_cmd_from_cmdq(struct isp4_interface *= ispif, u32 seq_num, + u32 cmd_id); + +void isp4if_clear_cmdq(struct isp4_interface *ispif); + +void isp4if_clear_bufq(struct isp4_interface *ispif); + +void isp4if_dealloc_buffer_node(struct isp4if_img_buf_node *buf_node); + +struct isp4if_img_buf_node *isp4if_alloc_buffer_node(struct isp4if_img_buf= _info *buf_info); + +struct isp4if_img_buf_node *isp4if_dequeue_buffer(struct isp4_interface *i= spif); + +int isp4if_queue_buffer(struct isp4_interface *ispif, struct isp4if_img_bu= f_node *buf_node); + +int isp4if_stop(struct isp4_interface *ispif); + +int isp4if_start(struct isp4_interface *ispif); + +int isp4if_deinit(struct isp4_interface *ispif); + +int isp4if_init(struct isp4_interface *ispif, struct device *dev, void __i= omem *isp_mmip); + +#endif --=20 2.34.1 From nobody Thu Oct 2 20:44:48 2025 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2053.outbound.protection.outlook.com [40.107.212.53]) (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 3FA13299A94; Thu, 11 Sep 2025 10:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585382; cv=fail; b=G864VPzgf/6t5G9JcnkjOajl7RKZ4303cESTgfNLxrqZa80cbGsKhxu80t4QExlxwdGYdEydduhCmH90lIHaqZMCmxU24U5Iip/DdO/Sgsl7YuEIUXdZkbTu/rdw9/9EpPCjPpKOuMoQc1WL0Tltf0CHEAmLQ+knQBFW5wKB8y4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585382; c=relaxed/simple; bh=+KbeBRrmRaLjMzOxoY//R7FZpN6ri6EEDbkXg9tkskM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TRVqqavTWb0QSt807tsvsBvEKXJDNmeSE5o9Z+NrkoCnZt7kLbKDhH4CyjRwpogSUL3HrYkVVlzYLM6mr9LmFZmYSR+G0dcvd2EDR+ZpNhqvVdgij5v2jI+pgJ3iLlgGrLFzNHxSucNMPooSlT3r8ycfS35k0a+xMo9+2fX73qI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=YLlTRgK4; arc=fail smtp.client-ip=40.107.212.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="YLlTRgK4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wEr1ZhVb6MOm2jXQ1hRwu1WYy9bqAS4w+/1Q+UWcU3/lzbvKux3A003UJt8X24jqK/GqDnvxe7ld3RzqxQriIX6L6F3T0uJQUmvCuGlJWar3NVzrogRAvj8AVXOrzlqa2IkewPMmiT0Hsu8qgqxiHVc+1qjwG9ICnNHrzKxa/ksBFZuWl1LBNqVpwsYr2+Cbu9fjJc/cknC/asMgTRg3D/ymGjuv5nD3abLHFV/smILjytOeKUCfsAnUAPa9drGDDFLFBoZks4NeuBxs1vEFZPeW4vVq6ZCWfm/3TfIJFLJxBkfS8ndcJRfwvXsEOWEvKO63RIyJva6FzNJEp4RIkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Ark42XYuitZI0mDSsJ0g5IOWWxssWr9Ou+z+65TNPCQ=; b=spwz1MZQeocAdx5++1Vg7Ea0M5AfmCMyoGtGEm5h8blIXaGeeXW3OsbPYClVivUBB1io2Dn/B9BUTWzMklDs2bhGa8xn4tUJakAfLOA5+pjOysqhIHx85McP1tScHsN+vK9/YOJM7jYFtAKLP06iBOFUdWggJTHdW84eqSA7fneyjCHMvJr80z/Qvj88eBO7Qh/Wi1RSRKwy98xJsfcJjznSYvQGBDBQnfzgdWrRYaJ3yGti7oiSStUZjJXuk90Al0791jiSHUwiFwNGXobqEyLiG0LQRAqk6M4LmJc16LkorhcR8sp2L07h+1YLsme/LAMIFJvzEDIRysdhaSjIwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ark42XYuitZI0mDSsJ0g5IOWWxssWr9Ou+z+65TNPCQ=; b=YLlTRgK4afj0FTNfaChi1Nt6L0dOtTaiQGXzU/GC8l6u9pQaiL1yIhUAtvyuaefZLrX8WpfEhHsAkmC27GWrVoX1xZrXeMCJNPrX3GmJB/NzUE1k1YstIE3VqulR51kNIe31RPqn/0AuJSR2A8I7Jn0DehENp9W2TKXqStVpPfU= Received: from MN2PR04CA0028.namprd04.prod.outlook.com (2603:10b6:208:d4::41) by DS7PR12MB8081.namprd12.prod.outlook.com (2603:10b6:8:e6::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Thu, 11 Sep 2025 10:09:33 +0000 Received: from MN1PEPF0000ECD9.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::f7) by MN2PR04CA0028.outlook.office365.com (2603:10b6:208:d4::41) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9094.22 via Frontend Transport; Thu, 11 Sep 2025 10:09:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MN1PEPF0000ECD9.mail.protection.outlook.com (10.167.242.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Thu, 11 Sep 2025 10:09:33 +0000 Received: from 555e2b870847.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 11 Sep 2025 03:09:28 -0700 From: Bin Du To: , , , , , , , , CC: , , , , , , , , , , Bin Du , Svetoslav Stoilov , "Alexey Zagorodnikov" Subject: [PATCH v4 4/7] media: platform: amd: isp4 subdev and firmware loading handling added Date: Thu, 11 Sep 2025 18:08:44 +0800 Message-ID: <20250911100847.277408-5-Bin.Du@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911100847.277408-1-Bin.Du@amd.com> References: <20250911100847.277408-1-Bin.Du@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD9:EE_|DS7PR12MB8081:EE_ X-MS-Office365-Filtering-Correlation-Id: a533b1ec-b5e8-4216-c08d-08ddf11b4e15 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?XZJxGCHu2Py7i1g8VBFTRexRsY24sSe6SIhm1u4GJQqFKBhVnsBd12QYYiH6?= =?us-ascii?Q?IDPdLRnKjuzSzTYdvvJVfsKGGIAvd57QbNleNwaM4d46WyN9eNQD1MlQiy90?= =?us-ascii?Q?7arHMIYBqeaB8EKE6rSOI2nhSFOmA0EbNd+KSyh+gguA9caxL3K6FCl8yu/u?= =?us-ascii?Q?IHQMLa/7kbn04bImR4D/l2jCzo/mDCZLuAZtgzjfAZDc7/Kl9DMBY1sYQI35?= =?us-ascii?Q?YG/xcOKB1xuJ9w2IdVaXCh3nDa/tOYXoQlXirjJIQYa/6gtLh8uqET3R5Q2R?= =?us-ascii?Q?i2KC5eodcFPiEp4Psfs2CQ1PZGyLdGasxwI6mVNaOzDXnzQSgGPaLxr6k2lX?= =?us-ascii?Q?TN9BVr5JWiIaiHoIzumucdOSDwKli0VwNgUwqwkwNOGwqM8t8aD9ogaB2IVw?= =?us-ascii?Q?UJN91x1dr51lVOmZQSD4cZpsxp+/eeFkC85UJ5Wm5i3ybyOBr9/XXhpr4atH?= =?us-ascii?Q?Eu/NOyHRnllPdIhy9xPiSgrq3Im+L8Q7Lu0NyAB7VjnUVYU0lq6fEGULyizx?= =?us-ascii?Q?JBuc30EfjJY5lJLCPCqxhXM32ENL5ZsRt7lPPP6wDbs4b/KS3yOGIokWmw+y?= =?us-ascii?Q?5Gh07pZOcbAU9Q17PhIyqOPcC4bMBnGZ0jSuqYT445rhxMr+HWOkkoloPwUk?= =?us-ascii?Q?TTxGE2TrwhON8hpHsv39rrWo0enPXMGV1HzRkQaBAfyxI2I+ZTa1wsl+F0Wf?= =?us-ascii?Q?qz+H/qtT4ZOJgV+VGjxBPa+pW3BZbGZByD4ty28eLiKbMw3lSTG+IDi09c0L?= =?us-ascii?Q?7P2a9UOpBraqrOTeP9mWKH/qNSS0zHzU7TVN8kBQ9Xl1r+YYJ71KX6L7kVhx?= =?us-ascii?Q?pIuFa5LCq1pccs1PVTe1NF90YJ1K81ZnDDwt3cSbiZHB7rKMq4H345v98SW1?= =?us-ascii?Q?4RkJZsS4tUKdKYodzzAhYkz0BT3AixTQ0LJXAhdERQwvZG22hSe1hmmC8Qux?= =?us-ascii?Q?ubYGvspO6VEIVY3IIt7XLb4oomWRF7zpFU6bYJG5IN+x/gkpkUt6UvELIsx3?= =?us-ascii?Q?bYYu2FL+g19JrEEvb8dqKxiW7QxhuunTb9cPTd1Kyd0E71x30gbVHjwX5l8s?= =?us-ascii?Q?GBTbbnC3lZgXv5f2yvIf60HfXH2DS3kt8Vh1Su27em+MVlGnCnyLfkYXk4O/?= =?us-ascii?Q?1X9fdyCyGxfiw9s3XSKC8VaaVZSA4oGEAPnPW2R3/MZ8OBrp/QeNnQMD/GAZ?= =?us-ascii?Q?0DQ6OsWC91LJbCgEp4UQ/szBy2vDDS1Msu+1S/R7NFiv36BVYTSvzDuPBMG6?= =?us-ascii?Q?srRk2hCzhYLYDgA9WxIzbicdsTeqlofnTqvvuozJjnIo+Cj+NP0ZUNtlUNkV?= =?us-ascii?Q?LKWulp40DnFpEQIfSuZg830l+7HKcqSwPZnnEiJjeXwsk2pI17uVHC1EQpH/?= =?us-ascii?Q?3gj/1XH3LF+trHQIl0kGdMqLYFUGH/NXAAjx1vDIH4dWwpAslYKLAoVVtcfp?= =?us-ascii?Q?FyL1+A5+lZiA0LPTUkAVjnQMP8ycPjxlmZOsF0PdGbfW8Ji5HzZSWZ7GUlzQ?= =?us-ascii?Q?3MGEv16LU9X/WWzEOXpywCXbS7qM+8/rqcTx?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(82310400026)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2025 10:09:33.2507 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a533b1ec-b5e8-4216-c08d-08ddf11b4e15 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECD9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8081 Content-Type: text/plain; charset="utf-8" Isp4 sub-device is implementing v4l2 sub-device interface. It has one capture video node, and supports only preview stream. It manages firmware states, stream configuration. Add interrupt handling and notification for isp firmware to isp-subdevice. Co-developed-by: Svetoslav Stoilov Signed-off-by: Svetoslav Stoilov Signed-off-by: Bin Du Tested-by: Alexey Zagorodnikov --- MAINTAINERS | 2 + drivers/media/platform/amd/isp4/Makefile | 3 +- drivers/media/platform/amd/isp4/isp4.c | 120 +- drivers/media/platform/amd/isp4/isp4.h | 8 +- drivers/media/platform/amd/isp4/isp4_subdev.c | 1095 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_subdev.h | 131 ++ 6 files changed, 1346 insertions(+), 13 deletions(-) create mode 100644 drivers/media/platform/amd/isp4/isp4_subdev.c create mode 100644 drivers/media/platform/amd/isp4/isp4_subdev.h diff --git a/MAINTAINERS b/MAINTAINERS index cccae369c876..48ffc8bbdcee 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1149,6 +1149,8 @@ F: drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h F: drivers/media/platform/amd/isp4/isp4_hw_reg.h F: drivers/media/platform/amd/isp4/isp4_interface.c F: drivers/media/platform/amd/isp4/isp4_interface.h +F: drivers/media/platform/amd/isp4/isp4_subdev.c +F: drivers/media/platform/amd/isp4/isp4_subdev.h =20 AMD KFD M: Felix Kuehling diff --git a/drivers/media/platform/amd/isp4/Makefile b/drivers/media/platf= orm/amd/isp4/Makefile index 327ed1157076..905788bc6a1e 100644 --- a/drivers/media/platform/amd/isp4/Makefile +++ b/drivers/media/platform/amd/isp4/Makefile @@ -3,5 +3,6 @@ # Copyright (C) 2025 Advanced Micro Devices, Inc. =20 obj-$(CONFIG_AMD_ISP4) +=3D amd_capture.o -amd_capture-objs :=3D isp4.o \ +amd_capture-objs :=3D isp4_subdev.o \ isp4_interface.o \ + isp4.o \ diff --git a/drivers/media/platform/amd/isp4/isp4.c b/drivers/media/platfor= m/amd/isp4/isp4.c index 6ff3ded4310a..8cec27228710 100644 --- a/drivers/media/platform/amd/isp4/isp4.c +++ b/drivers/media/platform/amd/isp4/isp4.c @@ -5,13 +5,19 @@ =20 #include #include + +#include #include =20 #include "isp4.h" - -#define VIDEO_BUF_NUM 5 +#include "isp4_hw_reg.h" =20 #define ISP4_DRV_NAME "amd_isp_capture" +#define ISP4_FW_RESP_RB_IRQ_STATUS_MASK \ + (ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT9_INT_MASK | \ + ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT10_INT_MASK | \ + ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT11_INT_MASK | \ + ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT12_INT_MASK) =20 /* interrupt num */ static const u32 isp4_ringbuf_interrupt_num[] =3D { @@ -21,19 +27,95 @@ static const u32 isp4_ringbuf_interrupt_num[] =3D { 4, /* ISP_4_1__SRCID__ISP_RINGBUFFER_WPT12 */ }; =20 -#define to_isp4_device(dev) \ - ((struct isp4_device *)container_of(dev, struct isp4_device, v4l2_dev)) +#define to_isp4_device(dev) container_of(dev, struct isp4_device, v4l2_dev) + +static void isp4_wake_up_resp_thread(struct isp4_subdev *isp, u32 index) +{ + if (isp && index < ISP4SD_MAX_FW_RESP_STREAM_NUM) { + struct isp4sd_thread_handler *thread_ctx =3D + &isp->fw_resp_thread[index]; + + thread_ctx->wq_cond =3D 1; + wake_up_interruptible(&thread_ctx->waitq); + } +} + +static void isp4_resp_interrupt_notify(struct isp4_subdev *isp, u32 intr_s= tatus) +{ + bool wake =3D (isp->ispif.status =3D=3D ISP4IF_STATUS_FW_RUNNING); + + u32 intr_ack =3D 0; + + /* global response */ + if (intr_status & + ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT12_INT_MASK) { + if (wake) + isp4_wake_up_resp_thread(isp, 0); + + intr_ack |=3D ISP_SYS_INT0_ACK__SYS_INT_RINGBUFFER_WPT12_ACK_MASK; + } + + /* stream 1 response */ + if (intr_status & + ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT9_INT_MASK) { + if (wake) + isp4_wake_up_resp_thread(isp, 1); + + intr_ack |=3D ISP_SYS_INT0_ACK__SYS_INT_RINGBUFFER_WPT9_ACK_MASK; + } + + /* stream 2 response */ + if (intr_status & + ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT10_INT_MASK) { + if (wake) + isp4_wake_up_resp_thread(isp, 2); + + intr_ack |=3D ISP_SYS_INT0_ACK__SYS_INT_RINGBUFFER_WPT10_ACK_MASK; + } + + /* stream 3 response */ + if (intr_status & + ISP_SYS_INT0_STATUS__SYS_INT_RINGBUFFER_WPT11_INT_MASK) { + if (wake) + isp4_wake_up_resp_thread(isp, 3); + + intr_ack |=3D ISP_SYS_INT0_ACK__SYS_INT_RINGBUFFER_WPT11_ACK_MASK; + } + + /* clear ISP_SYS interrupts */ + isp4hw_wreg(ISP4_GET_ISP_REG_BASE(isp), ISP_SYS_INT0_ACK, intr_ack); +} =20 static irqreturn_t isp4_irq_handler(int irq, void *arg) { + struct isp4_device *isp_dev =3D dev_get_drvdata(arg); + struct isp4_subdev *isp =3D NULL; + u32 isp_sys_irq_status =3D 0x0; + u32 r1; + + if (!isp_dev) + goto error_drv_data; + + isp =3D &isp_dev->isp_sdev; + /* check ISP_SYS interrupts status */ + r1 =3D isp4hw_rreg(ISP4_GET_ISP_REG_BASE(isp), ISP_SYS_INT0_STATUS); + + isp_sys_irq_status =3D r1 & ISP4_FW_RESP_RB_IRQ_STATUS_MASK; + + isp4_resp_interrupt_notify(isp, isp_sys_irq_status); + +error_drv_data: return IRQ_HANDLED; } =20 static int isp4_capture_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; + struct isp4_subdev *isp_sdev; struct isp4_device *isp_dev; - int i, irq, ret; + size_t i; + int irq; + int ret; =20 isp_dev =3D devm_kzalloc(&pdev->dev, sizeof(*isp_dev), GFP_KERNEL); if (!isp_dev) @@ -42,6 +124,12 @@ static int isp4_capture_probe(struct platform_device *p= dev) isp_dev->pdev =3D pdev; dev->init_name =3D ISP4_DRV_NAME; =20 + isp_sdev =3D &isp_dev->isp_sdev; + isp_sdev->mmio =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(isp_sdev->mmio)) + return dev_err_probe(dev, PTR_ERR(isp_sdev->mmio), + "isp ioremap fail\n"); + for (i =3D 0; i < ARRAY_SIZE(isp4_ringbuf_interrupt_num); i++) { irq =3D platform_get_irq(pdev, isp4_ringbuf_interrupt_num[i]); if (irq < 0) @@ -55,6 +143,8 @@ static int isp4_capture_probe(struct platform_device *pd= ev) irq); } =20 + isp_dev->pltf_data =3D pdev->dev.platform_data; + /* Link the media device within the v4l2_device */ isp_dev->v4l2_dev.mdev =3D &isp_dev->mdev; =20 @@ -66,6 +156,8 @@ static int isp4_capture_probe(struct platform_device *pd= ev) isp_dev->mdev.dev =3D &pdev->dev; media_device_init(&isp_dev->mdev); =20 + pm_runtime_set_suspended(dev); + pm_runtime_enable(dev); /* register v4l2 device */ snprintf(isp_dev->v4l2_dev.name, sizeof(isp_dev->v4l2_dev.name), "AMD-V4L2-ROOT"); @@ -74,19 +166,24 @@ static int isp4_capture_probe(struct platform_device *= pdev) return dev_err_probe(dev, ret, "fail register v4l2 device\n"); =20 + ret =3D isp4sd_init(&isp_dev->isp_sdev, &isp_dev->v4l2_dev); + if (ret) { + dev_err(dev, "fail init isp4 sub dev %d\n", ret); + goto err_unreg_v4l2; + } + ret =3D media_device_register(&isp_dev->mdev); if (ret) { dev_err(dev, "fail to register media device %d\n", ret); - goto err_unreg_v4l2; + goto err_isp4_deinit; } =20 platform_set_drvdata(pdev, isp_dev); =20 - pm_runtime_set_suspended(dev); - pm_runtime_enable(dev); - return 0; =20 +err_isp4_deinit: + isp4sd_deinit(&isp_dev->isp_sdev); err_unreg_v4l2: v4l2_device_unregister(&isp_dev->v4l2_dev); =20 @@ -97,8 +194,13 @@ static void isp4_capture_remove(struct platform_device = *pdev) { struct isp4_device *isp_dev =3D platform_get_drvdata(pdev); =20 + v4l2_device_unregister_subdev(&isp_dev->isp_sdev.sdev); + media_device_unregister(&isp_dev->mdev); + media_entity_cleanup(&isp_dev->isp_sdev.sdev.entity); v4l2_device_unregister(&isp_dev->v4l2_dev); + + isp4sd_deinit(&isp_dev->isp_sdev); } =20 static struct platform_driver isp4_capture_drv =3D { diff --git a/drivers/media/platform/amd/isp4/isp4.h b/drivers/media/platfor= m/amd/isp4/isp4.h index 8535f662ab49..00ac11ed8fb0 100644 --- a/drivers/media/platform/amd/isp4/isp4.h +++ b/drivers/media/platform/amd/isp4/isp4.h @@ -6,19 +6,21 @@ #ifndef _ISP4_H_ #define _ISP4_H_ =20 +#include #include -#include -#include -#include +#include "isp4_subdev.h" =20 #define ISP4_GET_ISP_REG_BASE(isp4sd) (((isp4sd))->mmio) =20 struct isp4_device { struct v4l2_device v4l2_dev; + struct isp4_subdev isp_sdev; struct media_device mdev; =20 + struct isp_platform_data *pltf_data; struct platform_device *pdev; struct notifier_block i2c_nb; + struct v4l2_async_notifier notifier; }; =20 #endif /* _ISP4_H_ */ diff --git a/drivers/media/platform/amd/isp4/isp4_subdev.c b/drivers/media/= platform/amd/isp4/isp4_subdev.c new file mode 100644 index 000000000000..a9cb14de04ca --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_subdev.c @@ -0,0 +1,1095 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#include +#include +#include + +#include "isp4_fw_cmd_resp.h" +#include "isp4_interface.h" +#include "isp4_subdev.h" +#include + +#define ISP4SD_MAX_CMD_RESP_BUF_SIZE (4 * 1024) +#define ISP4SD_MIN_BUF_CNT_BEF_START_STREAM 4 + +#define ISP4SD_PERFORMANCE_STATE_LOW 0 +#define ISP4SD_PERFORMANCE_STATE_HIGH 1 + +#define ISP4SD_FW_CMD_TIMEOUT_IN_MS 500 +#define ISP4SD_WAIT_RESP_IRQ_TIMEOUT 5 /* ms */ +/* align 32KB */ +#define ISP4SD_META_BUF_SIZE ALIGN(sizeof(struct isp4fw_meta_info), 0x8000) + +#define to_isp4_subdev(v4l2_sdev) \ + container_of(v4l2_sdev, struct isp4_subdev, sdev) + +static const char *isp4sd_entity_name =3D "amd isp4"; + +static void isp4sd_module_enable(struct isp4_subdev *isp_subdev, bool enab= le) +{ + if (isp_subdev->enable_gpio) { + gpiod_set_value(isp_subdev->enable_gpio, enable ? 1 : 0); + dev_dbg(isp_subdev->dev, "%s isp_subdev module\n", + enable ? "enable" : "disable"); + } +} + +static int isp4sd_setup_fw_mem_pool(struct isp4_subdev *isp_subdev) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4fw_cmd_send_buffer buf_type =3D {}; + struct device *dev =3D isp_subdev->dev; + int ret; + + if (!ispif->fw_mem_pool) { + dev_err(dev, "fail to alloc mem pool\n"); + return -ENOMEM; + } + + buf_type.buffer_type =3D BUFFER_TYPE_MEM_POOL; + buf_type.buffer.buf_tags =3D 0; + buf_type.buffer.vmid_space.bit.vmid =3D 0; + buf_type.buffer.vmid_space.bit.space =3D ADDR_SPACE_TYPE_GPU_VA; + isp4if_split_addr64(ispif->fw_mem_pool->gpu_mc_addr, + &buf_type.buffer.buf_base_a_lo, + &buf_type.buffer.buf_base_a_hi); + buf_type.buffer.buf_size_a =3D (u32)ispif->fw_mem_pool->mem_size; + + ret =3D isp4if_send_command(ispif, CMD_ID_SEND_BUFFER, + &buf_type, sizeof(buf_type)); + if (ret) { + dev_err(dev, "send fw mem pool 0x%llx(%u) fail %d\n", + ispif->fw_mem_pool->gpu_mc_addr, + buf_type.buffer.buf_size_a, + ret); + return ret; + } + + dev_dbg(dev, "send fw mem pool 0x%llx(%u) suc\n", + ispif->fw_mem_pool->gpu_mc_addr, + buf_type.buffer.buf_size_a); + + return 0; +}; + +static int isp4sd_set_stream_path(struct isp4_subdev *isp_subdev) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4fw_cmd_set_stream_cfg cmd =3D {}; + struct device *dev =3D isp_subdev->dev; + + cmd.stream_cfg.mipi_pipe_path_cfg.isp4fw_sensor_id =3D SENSOR_ID_ON_MIPI0; + cmd.stream_cfg.mipi_pipe_path_cfg.b_enable =3D true; + cmd.stream_cfg.isp_pipe_path_cfg.isp_pipe_id =3D MIPI0_ISP_PIPELINE_ID; + + cmd.stream_cfg.b_enable_tnr =3D true; + dev_dbg(dev, "isp4fw_sensor_id %d, pipeId 0x%x EnableTnr %u\n", + cmd.stream_cfg.mipi_pipe_path_cfg.isp4fw_sensor_id, + cmd.stream_cfg.isp_pipe_path_cfg.isp_pipe_id, + cmd.stream_cfg.b_enable_tnr); + + return isp4if_send_command(ispif, CMD_ID_SET_STREAM_CONFIG, + &cmd, sizeof(cmd)); +} + +static int isp4sd_send_meta_buf(struct isp4_subdev *isp_subdev) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4fw_cmd_send_buffer buf_type =3D {}; + struct isp4sd_sensor_info *sensor_info; + struct device *dev =3D isp_subdev->dev; + u32 i; + + sensor_info =3D &isp_subdev->sensor_info; + for (i =3D 0; i < ISP4IF_MAX_STREAM_BUF_COUNT; i++) { + int ret; + + if (!sensor_info->meta_info_buf[i]) { + dev_err(dev, "fail for no meta info buf(%u)\n", i); + return -ENOMEM; + } + buf_type.buffer_type =3D BUFFER_TYPE_META_INFO; + buf_type.buffer.buf_tags =3D 0; + buf_type.buffer.vmid_space.bit.vmid =3D 0; + buf_type.buffer.vmid_space.bit.space =3D ADDR_SPACE_TYPE_GPU_VA; + isp4if_split_addr64(sensor_info->meta_info_buf[i]->gpu_mc_addr, + &buf_type.buffer.buf_base_a_lo, + &buf_type.buffer.buf_base_a_hi); + buf_type.buffer.buf_size_a =3D + (u32)sensor_info->meta_info_buf[i]->mem_size; + ret =3D isp4if_send_command(ispif, CMD_ID_SEND_BUFFER, + &buf_type, + sizeof(buf_type)); + if (ret) { + dev_err(dev, "send meta info(%u) fail\n", i); + return ret; + } + } + + dev_dbg(dev, "send meta info suc\n"); + return 0; +} + +static bool isp4sd_get_str_out_prop(struct isp4_subdev *isp_subdev, + struct isp4fw_image_prop *out_prop, + struct v4l2_subdev_state *state, u32 pad) +{ + struct v4l2_mbus_framefmt *format =3D NULL; + struct device *dev =3D isp_subdev->dev; + bool ret; + + format =3D v4l2_subdev_state_get_format(state, pad, 0); + if (!format) { + dev_err(dev, "fail get subdev state format\n"); + return false; + } + + switch (format->code) { + case MEDIA_BUS_FMT_YUYV8_1_5X8: + out_prop->image_format =3D IMAGE_FORMAT_NV12; + out_prop->width =3D format->width; + out_prop->height =3D format->height; + out_prop->luma_pitch =3D format->width; + out_prop->chroma_pitch =3D out_prop->width; + ret =3D true; + break; + case MEDIA_BUS_FMT_YUYV8_1X16: + out_prop->image_format =3D IMAGE_FORMAT_YUV422INTERLEAVED; + out_prop->width =3D format->width; + out_prop->height =3D format->height; + out_prop->luma_pitch =3D format->width * 2; + out_prop->chroma_pitch =3D 0; + ret =3D true; + break; + default: + dev_err(dev, "fail for bad image format:0x%x\n", + format->code); + ret =3D false; + break; + } + + if (!out_prop->width || !out_prop->height) + ret =3D false; + return ret; +} + +static int isp4sd_kickoff_stream(struct isp4_subdev *isp_subdev, u32 w, u3= 2 h) +{ + struct isp4sd_sensor_info *sensor_info =3D &isp_subdev->sensor_info; + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct device *dev =3D isp_subdev->dev; + + if (sensor_info->status =3D=3D ISP4SD_START_STATUS_STARTED) { + return 0; + } else if (sensor_info->status =3D=3D ISP4SD_START_STATUS_START_FAIL) { + dev_err(dev, "fail for previous start fail\n"); + return -EINVAL; + } + + dev_dbg(dev, "w:%u,h:%u\n", w, h); + + sensor_info->status =3D ISP4SD_START_STATUS_START_FAIL; + + if (isp4sd_send_meta_buf(isp_subdev)) { + dev_err(dev, "fail to send meta buf\n"); + return -EINVAL; + }; + + sensor_info->status =3D ISP4SD_START_STATUS_NOT_START; + + if (!sensor_info->start_stream_cmd_sent && + sensor_info->buf_sent_cnt >=3D + ISP4SD_MIN_BUF_CNT_BEF_START_STREAM) { + int ret =3D isp4if_send_command(ispif, CMD_ID_START_STREAM, + NULL, 0); + if (ret) { + dev_err(dev, "fail to start stream\n"); + return ret; + } + + sensor_info->start_stream_cmd_sent =3D true; + } else { + dev_dbg(dev, + "no send START_STREAM, start_sent %u, buf_sent %u\n", + sensor_info->start_stream_cmd_sent, + sensor_info->buf_sent_cnt); + } + + return 0; +} + +static int isp4sd_setup_output(struct isp4_subdev *isp_subdev, + struct v4l2_subdev_state *state, u32 pad) +{ + struct isp4sd_sensor_info *sensor_info =3D &isp_subdev->sensor_info; + struct isp4sd_output_info *output_info =3D + &isp_subdev->sensor_info.output_info; + struct isp4fw_cmd_set_out_ch_prop cmd_ch_prop =3D {}; + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4fw_cmd_enable_out_ch cmd_ch_en =3D {}; + struct device *dev =3D isp_subdev->dev; + struct isp4fw_image_prop *out_prop; + int ret; + + if (output_info->start_status =3D=3D ISP4SD_START_STATUS_STARTED) + return 0; + + if (output_info->start_status =3D=3D ISP4SD_START_STATUS_START_FAIL) { + dev_err(dev, "fail for previous start fail\n"); + return -EINVAL; + } + + out_prop =3D &cmd_ch_prop.image_prop; + cmd_ch_prop.ch =3D ISP_PIPE_OUT_CH_PREVIEW; + cmd_ch_en.ch =3D ISP_PIPE_OUT_CH_PREVIEW; + cmd_ch_en.is_enable =3D true; + + if (!isp4sd_get_str_out_prop(isp_subdev, out_prop, state, pad)) { + dev_err(dev, "fail to get out prop\n"); + return -EINVAL; + } + + dev_dbg(dev, "channel: w:h=3D%u:%u,lp:%u,cp%u\n", + cmd_ch_prop.image_prop.width, cmd_ch_prop.image_prop.height, + cmd_ch_prop.image_prop.luma_pitch, + cmd_ch_prop.image_prop.chroma_pitch); + + ret =3D isp4if_send_command(ispif, CMD_ID_SET_OUT_CHAN_PROP, + &cmd_ch_prop, + sizeof(cmd_ch_prop)); + if (ret) { + output_info->start_status =3D ISP4SD_START_STATUS_START_FAIL; + dev_err(dev, "fail to set out prop\n"); + return ret; + }; + + ret =3D isp4if_send_command(ispif, CMD_ID_ENABLE_OUT_CHAN, + &cmd_ch_en, sizeof(cmd_ch_en)); + + if (ret) { + output_info->start_status =3D ISP4SD_START_STATUS_START_FAIL; + dev_err(dev, "fail to enable channel\n"); + return ret; + } + + if (!sensor_info->start_stream_cmd_sent) { + ret =3D isp4sd_kickoff_stream(isp_subdev, out_prop->width, + out_prop->height); + if (ret) { + dev_err(dev, "kickoff stream fail %d\n", ret); + return ret; + } + /* + * sensor_info->start_stream_cmd_sent will be set to true + * 1. in isp4sd_kickoff_stream, if app first send buffer then + * start stream + * 2. in isp_set_stream_buf, if app first start stream, then + * send buffer + * because ISP FW has the requirement, host needs to send buffer + * before send start stream cmd + */ + if (sensor_info->start_stream_cmd_sent) { + sensor_info->status =3D ISP4SD_START_STATUS_STARTED; + output_info->start_status =3D ISP4SD_START_STATUS_STARTED; + dev_dbg(dev, "kickoff stream suc,start cmd sent\n"); + } + } else { + dev_dbg(dev, "stream running, no need kickoff\n"); + output_info->start_status =3D ISP4SD_START_STATUS_STARTED; + } + + dev_dbg(dev, "setup output suc\n"); + return 0; +} + +static int isp4sd_init_meta_buf(struct isp4_subdev *isp_subdev) +{ + struct isp4sd_sensor_info *sensor_info =3D &isp_subdev->sensor_info; + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct device *dev =3D isp_subdev->dev; + u32 i; + + for (i =3D 0; i < ISP4IF_MAX_STREAM_BUF_COUNT; i++) { + if (!sensor_info->meta_info_buf[i]) { + sensor_info->meta_info_buf[i] =3D ispif->metainfo_buf_pool[i]; + if (!sensor_info->meta_info_buf[i]) { + dev_err(dev, "invalid %u meta_info_buf fail\n", i); + return -ENOMEM; + } + } + } + + return 0; +} + +static int isp4sd_init_stream(struct isp4_subdev *isp_subdev) +{ + struct device *dev =3D isp_subdev->dev; + int ret; + + ret =3D isp4sd_setup_fw_mem_pool(isp_subdev); + if (ret) { + dev_err(dev, "fail to setup fw mem pool\n"); + return ret; + } + + ret =3D isp4sd_init_meta_buf(isp_subdev); + if (ret) { + dev_err(dev, "fail to alloc fw driver shared buf\n"); + return ret; + } + + ret =3D isp4sd_set_stream_path(isp_subdev); + if (ret) { + dev_err(dev, "fail to setup stream path\n"); + return ret; + } + + return 0; +} + +static void isp4sd_reset_stream_info(struct isp4_subdev *isp_subdev, + struct v4l2_subdev_state *state, u32 pad) +{ + struct isp4sd_sensor_info *sensor_info =3D &isp_subdev->sensor_info; + struct v4l2_mbus_framefmt *format =3D NULL; + struct isp4sd_output_info *str_info; + int i; + + format =3D v4l2_subdev_state_get_format(state, pad, 0); + + if (!format) { + dev_err(isp_subdev->dev, "fail to setup stream path\n"); + } else { + memset(format, 0, sizeof(*format)); + format->code =3D MEDIA_BUS_FMT_YUYV8_1_5X8; + } + + for (i =3D 0; i < ISP4IF_MAX_STREAM_BUF_COUNT; i++) + sensor_info->meta_info_buf[i] =3D NULL; + + str_info =3D &sensor_info->output_info; + str_info->start_status =3D ISP4SD_START_STATUS_NOT_START; +} + +static bool isp4sd_is_stream_running(struct isp4_subdev *isp_subdev) +{ + struct isp4sd_sensor_info *sif; + enum isp4sd_start_status stat; + + sif =3D &isp_subdev->sensor_info; + stat =3D sif->output_info.start_status; + if (stat =3D=3D ISP4SD_START_STATUS_STARTED) + return true; + + return false; +} + +static void isp4sd_reset_camera_info(struct isp4_subdev *isp_subdev, + struct v4l2_subdev_state *state, u32 pad) +{ + struct isp4sd_sensor_info *info =3D &isp_subdev->sensor_info; + + info->status =3D ISP4SD_START_STATUS_NOT_START; + isp4sd_reset_stream_info(isp_subdev, state, pad); + + info->start_stream_cmd_sent =3D false; +} + +static int isp4sd_uninit_stream(struct isp4_subdev *isp_subdev, + struct v4l2_subdev_state *state, u32 pad) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct device *dev =3D isp_subdev->dev; + bool running; + + running =3D isp4sd_is_stream_running(isp_subdev); + + if (running) { + dev_dbg(dev, "fail for stream is still running\n"); + return -EINVAL; + } + + isp4sd_reset_camera_info(isp_subdev, state, pad); + + isp4if_clear_cmdq(ispif); + return 0; +} + +static void isp4sd_fw_resp_cmd_done(struct isp4_subdev *isp_subdev, + enum isp4if_stream_id stream_id, + struct isp4fw_resp_cmd_done *para) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4if_cmd_element *ele =3D + isp4if_rm_cmd_from_cmdq(ispif, para->cmd_seq_num, para->cmd_id); + struct device *dev =3D isp_subdev->dev; + + dev_dbg(dev, "stream %d,cmd (0x%08x)(%d),seq %u, ele %p\n", + stream_id, + para->cmd_id, para->cmd_status, para->cmd_seq_num, + ele); + + if (!ele) + return; + + if (ele->wq) { + dev_dbg(dev, "signal event %p\n", ele->wq); + if (ele->wq_cond) + *ele->wq_cond =3D 1; + wake_up(ele->wq); + } + + kfree(ele); +} + +static struct isp4fw_meta_info * +isp4sd_get_meta_by_mc(struct isp4_subdev *isp_subdev, + u64 mc) +{ + u32 i; + + for (i =3D 0; i < ISP4IF_MAX_STREAM_BUF_COUNT; i++) { + struct isp4if_gpu_mem_info *meta_info_buf =3D + isp_subdev->sensor_info.meta_info_buf[i]; + + if (meta_info_buf) { + if (mc =3D=3D meta_info_buf->gpu_mc_addr) + return meta_info_buf->sys_addr; + } + } + return NULL; +}; + +static struct isp4if_img_buf_node * +isp4sd_preview_done(struct isp4_subdev *isp_subdev, + struct isp4fw_meta_info *meta) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4if_img_buf_node *prev =3D NULL; + struct device *dev =3D isp_subdev->dev; + + if (meta->preview.enabled && + (meta->preview.status =3D=3D BUFFER_STATUS_SKIPPED || + meta->preview.status =3D=3D BUFFER_STATUS_DONE || + meta->preview.status =3D=3D BUFFER_STATUS_DIRTY)) { + prev =3D isp4if_dequeue_buffer(ispif); + if (!prev) + dev_err(dev, "fail null prev buf\n"); + + } else if (meta->preview.enabled) { + dev_err(dev, "fail bad preview status %u\n", + meta->preview.status); + } + + return prev; +} + +static void isp4sd_send_meta_info(struct isp4_subdev *isp_subdev, + u64 meta_info_mc) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4fw_cmd_send_buffer buf_type =3D {}; + struct device *dev =3D isp_subdev->dev; + + if (isp_subdev->sensor_info.status !=3D ISP4SD_START_STATUS_STARTED) { + dev_warn(dev, "not working status %i, meta_info 0x%llx\n", + isp_subdev->sensor_info.status, meta_info_mc); + return; + } + + if (meta_info_mc) { + buf_type.buffer_type =3D BUFFER_TYPE_META_INFO; + buf_type.buffer.buf_tags =3D 0; + buf_type.buffer.vmid_space.bit.vmid =3D 0; + buf_type.buffer.vmid_space.bit.space =3D ADDR_SPACE_TYPE_GPU_VA; + isp4if_split_addr64(meta_info_mc, + &buf_type.buffer.buf_base_a_lo, + &buf_type.buffer.buf_base_a_hi); + + buf_type.buffer.buf_size_a =3D ISP4SD_META_BUF_SIZE; + if (isp4if_send_command(ispif, CMD_ID_SEND_BUFFER, + &buf_type, sizeof(buf_type))) { + dev_err(dev, "fail send meta_info 0x%llx\n", + meta_info_mc); + } else { + dev_dbg(dev, "resend meta_info 0x%llx\n", meta_info_mc); + } + } +} + +static void isp4sd_fw_resp_frame_done(struct isp4_subdev *isp_subdev, + enum isp4if_stream_id stream_id, + struct isp4fw_resp_param_package *para) +{ + struct isp4if_img_buf_node *prev =3D NULL; + struct device *dev =3D isp_subdev->dev; + struct isp4fw_meta_info *meta; + u64 mc =3D 0; + + mc =3D isp4if_join_addr64(para->package_addr_lo, para->package_addr_hi); + meta =3D isp4sd_get_meta_by_mc(isp_subdev, mc); + if (mc =3D=3D 0 || !meta) { + dev_err(dev, "fail to get meta from mc %llx\n", mc); + return; + } + + dev_dbg(dev, "ts:%llu,streamId:%d,poc:%u,preview_en:%u,(%i)\n", + ktime_get_ns(), stream_id, meta->poc, + meta->preview.enabled, + meta->preview.status); + + prev =3D isp4sd_preview_done(isp_subdev, meta); + + isp4if_dealloc_buffer_node(prev); + + if (isp_subdev->sensor_info.status =3D=3D ISP4SD_START_STATUS_STARTED) + isp4sd_send_meta_info(isp_subdev, mc); + + dev_dbg(dev, "stream_id:%d, status:%d\n", stream_id, + isp_subdev->sensor_info.status); +} + +static void isp4sd_fw_resp_func(struct isp4_subdev *isp_subdev, + enum isp4if_stream_id stream_id) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct device *dev =3D isp_subdev->dev; + struct isp4fw_resp resp; + + if (ispif->status < ISP4IF_STATUS_FW_RUNNING) + return; + + while (true) { + s32 ret; + + ret =3D isp4if_f2h_resp(ispif, stream_id, &resp); + if (ret) + break; + + switch (resp.resp_id) { + case RESP_ID_CMD_DONE: + isp4sd_fw_resp_cmd_done(isp_subdev, stream_id, + &resp.param.cmd_done); + break; + case RESP_ID_NOTI_FRAME_DONE: + isp4sd_fw_resp_frame_done(isp_subdev, stream_id, + &resp.param.frame_done); + break; + default: + dev_err(dev, "-><- fail respid (0x%x)\n", + resp.resp_id); + break; + } + } +} + +static s32 isp4sd_fw_resp_thread_wrapper(void *context) +{ + struct isp4_subdev_thread_param *para =3D context; + struct isp4sd_thread_handler *thread_ctx; + enum isp4if_stream_id stream_id; + + struct isp4_subdev *isp_subdev; + struct device *dev; + u64 timeout; + + if (!para) + return -EINVAL; + + isp_subdev =3D para->isp_subdev; + dev =3D isp_subdev->dev; + + switch (para->idx) { + case 0: + stream_id =3D ISP4IF_STREAM_ID_GLOBAL; + break; + case 1: + stream_id =3D ISP4IF_STREAM_ID_1; + break; + default: + dev_err(dev, "fail invalid %d\n", para->idx); + return -EINVAL; + } + + thread_ctx =3D &isp_subdev->fw_resp_thread[para->idx]; + + thread_ctx->wq_cond =3D 0; + mutex_init(&thread_ctx->mutex); + init_waitqueue_head(&thread_ctx->waitq); + timeout =3D msecs_to_jiffies(ISP4SD_WAIT_RESP_IRQ_TIMEOUT); + + dev_dbg(dev, "[%u] started\n", para->idx); + + while (true) { + wait_event_interruptible_timeout(thread_ctx->waitq, + thread_ctx->wq_cond !=3D 0, + timeout); + thread_ctx->wq_cond =3D 0; + + if (kthread_should_stop()) { + dev_dbg(dev, "[%u] quit\n", para->idx); + break; + } + + guard(mutex)(&thread_ctx->mutex); + isp4sd_fw_resp_func(isp_subdev, stream_id); + } + + mutex_destroy(&thread_ctx->mutex); + + return 0; +} + +static int isp4sd_start_resp_proc_threads(struct isp4_subdev *isp_subdev) +{ + struct device *dev =3D isp_subdev->dev; + int i; + + for (i =3D 0; i < ISP4SD_MAX_FW_RESP_STREAM_NUM; i++) { + struct isp4sd_thread_handler *thread_ctx =3D + &isp_subdev->fw_resp_thread[i]; + + isp_subdev->isp_resp_para[i].idx =3D i; + isp_subdev->isp_resp_para[i].isp_subdev =3D isp_subdev; + + thread_ctx->thread =3D kthread_run(isp4sd_fw_resp_thread_wrapper, + &isp_subdev->isp_resp_para[i], + "amd_isp4_thread"); + if (IS_ERR(thread_ctx->thread)) { + dev_err(dev, "create thread [%d] fail\n", i); + return -EINVAL; + } + } + + return 0; +} + +static int isp4sd_stop_resp_proc_threads(struct isp4_subdev *isp_subdev) +{ + int i; + + for (i =3D 0; i < ISP4SD_MAX_FW_RESP_STREAM_NUM; i++) { + struct isp4sd_thread_handler *thread_ctx =3D + &isp_subdev->fw_resp_thread[i]; + + if (thread_ctx->thread) { + kthread_stop(thread_ctx->thread); + thread_ctx->thread =3D NULL; + } + } + + return 0; +} + +static u32 isp4sd_get_started_stream_count(struct isp4_subdev *isp_subdev) +{ + u32 cnt =3D 0; + + if (isp_subdev->sensor_info.status =3D=3D ISP4SD_START_STATUS_STARTED) + cnt++; + return cnt; +} + +static int isp4sd_pwroff_and_deinit(struct isp4_subdev *isp_subdev) +{ + struct isp4sd_sensor_info *sensor_info =3D &isp_subdev->sensor_info; + unsigned int perf_state =3D ISP4SD_PERFORMANCE_STATE_LOW; + struct isp4_interface *ispif =3D &isp_subdev->ispif; + + struct device *dev =3D isp_subdev->dev; + u32 cnt; + int ret; + + mutex_lock(&isp_subdev->ops_mutex); + + if (sensor_info->status =3D=3D ISP4SD_START_STATUS_STARTED) { + dev_err(dev, "fail for stream still running\n"); + mutex_unlock(&isp_subdev->ops_mutex); + return -EINVAL; + } + + sensor_info->status =3D ISP4SD_START_STATUS_NOT_START; + cnt =3D isp4sd_get_started_stream_count(isp_subdev); + if (cnt > 0) { + dev_dbg(dev, "no need power off isp_subdev\n"); + mutex_unlock(&isp_subdev->ops_mutex); + return 0; + } + + isp4if_stop(ispif); + + ret =3D dev_pm_genpd_set_performance_state(dev, perf_state); + if (ret) + dev_err(dev, + "fail to set isp_subdev performance state %u,ret %d\n", + perf_state, ret); + isp4sd_stop_resp_proc_threads(isp_subdev); + dev_dbg(dev, "isp_subdev stop resp proc streads suc"); + /* hold ccpu reset */ + isp4hw_wreg(isp_subdev->mmio, ISP_SOFT_RESET, 0x0); + isp4hw_wreg(isp_subdev->mmio, ISP_POWER_STATUS, 0); + ret =3D pm_runtime_put_sync(dev); + if (ret) + dev_err(dev, "power off isp_subdev fail %d\n", ret); + else + dev_dbg(dev, "power off isp_subdev suc\n"); + + ispif->status =3D ISP4IF_STATUS_PWR_OFF; + isp4if_clear_cmdq(ispif); + isp4sd_module_enable(isp_subdev, false); + + msleep(20); + + mutex_unlock(&isp_subdev->ops_mutex); + + return 0; +} + +static int isp4sd_pwron_and_init(struct isp4_subdev *isp_subdev) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct device *dev =3D isp_subdev->dev; + int ret; + + if (ispif->status =3D=3D ISP4IF_STATUS_FW_RUNNING) { + dev_dbg(dev, "camera already opened, do nothing\n"); + return 0; + } + + mutex_lock(&isp_subdev->ops_mutex); + + isp4sd_module_enable(isp_subdev, true); + + isp_subdev->sensor_info.start_stream_cmd_sent =3D false; + isp_subdev->sensor_info.buf_sent_cnt =3D 0; + + if (ispif->status < ISP4IF_STATUS_PWR_ON) { + unsigned int perf_state =3D ISP4SD_PERFORMANCE_STATE_HIGH; + + ret =3D pm_runtime_resume_and_get(dev); + if (ret) { + dev_err(dev, "fail to power on isp_subdev ret %d\n", + ret); + goto err_unlock_and_close; + } + + /* ISPPG ISP Power Status */ + isp4hw_wreg(isp_subdev->mmio, ISP_POWER_STATUS, 0x7FF); + ret =3D dev_pm_genpd_set_performance_state(dev, perf_state); + if (ret) { + dev_err(dev, + "fail to set performance state %u, ret %d\n", + perf_state, ret); + goto err_unlock_and_close; + } + + ispif->status =3D ISP4IF_STATUS_PWR_ON; + + if (isp4sd_start_resp_proc_threads(isp_subdev)) { + dev_err(dev, "isp_start_resp_proc_threads fail"); + goto err_unlock_and_close; + } else { + dev_dbg(dev, "create resp threads ok"); + } + } + + isp_subdev->sensor_info.start_stream_cmd_sent =3D false; + isp_subdev->sensor_info.buf_sent_cnt =3D 0; + + ret =3D isp4if_start(ispif); + if (ret) { + dev_err(dev, "fail to start isp_subdev interface\n"); + goto err_unlock_and_close; + } + + mutex_unlock(&isp_subdev->ops_mutex); + return 0; +err_unlock_and_close: + mutex_unlock(&isp_subdev->ops_mutex); + isp4sd_pwroff_and_deinit(isp_subdev); + return -EINVAL; +} + +static int isp4sd_stop_stream(struct isp4_subdev *isp_subdev, + struct v4l2_subdev_state *state, u32 pad) +{ + struct isp4sd_output_info *output_info =3D + &isp_subdev->sensor_info.output_info; + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct device *dev =3D isp_subdev->dev; + int ret =3D 0; + + dev_dbg(dev, "status %i\n", output_info->start_status); + mutex_lock(&isp_subdev->ops_mutex); + + if (output_info->start_status =3D=3D ISP4SD_START_STATUS_STARTED) { + struct isp4fw_cmd_enable_out_ch cmd_ch_disable; + + cmd_ch_disable.ch =3D ISP_PIPE_OUT_CH_PREVIEW; + cmd_ch_disable.is_enable =3D false; + ret =3D isp4if_send_command_sync(ispif, + CMD_ID_ENABLE_OUT_CHAN, + &cmd_ch_disable, + sizeof(cmd_ch_disable), + ISP4SD_FW_CMD_TIMEOUT_IN_MS); + if (ret) + dev_err(dev, "fail to disable stream\n"); + else + dev_dbg(dev, "wait disable stream suc\n"); + + ret =3D isp4if_send_command_sync(ispif, CMD_ID_STOP_STREAM, + NULL, + 0, + ISP4SD_FW_CMD_TIMEOUT_IN_MS); + if (ret) + dev_err(dev, "fail to stop steam\n"); + else + dev_dbg(dev, "wait stop stream suc\n"); + } + + isp4if_clear_bufq(ispif); + + output_info->start_status =3D ISP4SD_START_STATUS_NOT_START; + isp4sd_reset_stream_info(isp_subdev, state, pad); + + mutex_unlock(&isp_subdev->ops_mutex); + + isp4sd_uninit_stream(isp_subdev, state, pad); + + return ret; +} + +static int isp4sd_start_stream(struct isp4_subdev *isp_subdev, + struct v4l2_subdev_state *state, u32 pad) +{ + struct isp4sd_output_info *output_info =3D + &isp_subdev->sensor_info.output_info; + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct device *dev =3D isp_subdev->dev; + int ret; + + mutex_lock(&isp_subdev->ops_mutex); + + if (ispif->status !=3D ISP4IF_STATUS_FW_RUNNING) { + mutex_unlock(&isp_subdev->ops_mutex); + dev_err(dev, "fail, bad fsm %d", ispif->status); + return -EINVAL; + } + + ret =3D isp4sd_init_stream(isp_subdev); + + if (ret) { + dev_err(dev, "fail to init isp_subdev stream\n"); + ret =3D -EINVAL; + goto unlock_and_check_ret; + } + + if (output_info->start_status =3D=3D ISP4SD_START_STATUS_STARTED) { + ret =3D 0; + dev_dbg(dev, "stream started, do nothing\n"); + goto unlock_and_check_ret; + } else if (output_info->start_status =3D=3D + ISP4SD_START_STATUS_START_FAIL) { + ret =3D -EINVAL; + dev_err(dev, "stream fail to start before\n"); + goto unlock_and_check_ret; + } + + if (isp4sd_setup_output(isp_subdev, state, pad)) { + dev_err(dev, "fail to setup output\n"); + ret =3D -EINVAL; + } else { + ret =3D 0; + dev_dbg(dev, "suc to setup out\n"); + } + +unlock_and_check_ret: + mutex_unlock(&isp_subdev->ops_mutex); + if (ret) { + isp4sd_stop_stream(isp_subdev, state, pad); + dev_err(dev, "start stream fail\n"); + } + + return ret; +} + +static int isp4sd_set_power(struct v4l2_subdev *sd, int on) +{ + struct isp4_subdev *ispsd =3D to_isp4_subdev(sd); + + if (on) + return isp4sd_pwron_and_init(ispsd); + else + return isp4sd_pwroff_and_deinit(ispsd); +}; + +static const struct v4l2_subdev_core_ops isp4sd_core_ops =3D { + .s_power =3D isp4sd_set_power, +}; + +static const struct v4l2_subdev_video_ops isp4sd_video_ops =3D { + .s_stream =3D v4l2_subdev_s_stream_helper, +}; + +static int isp4sd_set_pad_format(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *fmt) +{ + struct isp4sd_output_info *steam_info =3D + &(to_isp4_subdev(sd)->sensor_info.output_info); + struct v4l2_mbus_framefmt *format; + + format =3D v4l2_subdev_state_get_format(sd_state, fmt->pad); + + if (!format) { + dev_err(sd->dev, "fail to get state format\n"); + return -EINVAL; + } + + *format =3D fmt->format; + switch (format->code) { + case MEDIA_BUS_FMT_YUYV8_1_5X8: + steam_info->image_size =3D format->width * format->height * 3 / 2; + break; + case MEDIA_BUS_FMT_YUYV8_1X16: + steam_info->image_size =3D format->width * format->height * 2; + break; + default: + steam_info->image_size =3D 0; + break; + } + if (!steam_info->image_size) { + dev_err(sd->dev, + "fail set pad format,code 0x%x,width %u, height %u\n", + format->code, format->width, format->height); + return -EINVAL; + } + dev_dbg(sd->dev, + "set pad format suc, code:%x w:%u h:%u size:%u\n", format->code, + format->width, format->height, steam_info->image_size); + + return 0; +} + +static int isp4sd_enable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, u32 pad, + u64 streams_mask) +{ + struct isp4_subdev *ispsd =3D to_isp4_subdev(sd); + + return isp4sd_start_stream(ispsd, state, pad); +} + +static int isp4sd_disable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, u32 pad, + u64 streams_mask) +{ + struct isp4_subdev *ispsd =3D to_isp4_subdev(sd); + + return isp4sd_stop_stream(ispsd, state, pad); +} + +static const struct v4l2_subdev_pad_ops isp4sd_pad_ops =3D { + .get_fmt =3D v4l2_subdev_get_fmt, + .set_fmt =3D isp4sd_set_pad_format, + .enable_streams =3D isp4sd_enable_streams, + .disable_streams =3D isp4sd_disable_streams, +}; + +static const struct v4l2_subdev_ops isp4sd_subdev_ops =3D { + .core =3D &isp4sd_core_ops, + .video =3D &isp4sd_video_ops, + .pad =3D &isp4sd_pad_ops, +}; + +static int isp4sd_sdev_link_validate(struct media_link *link) +{ + return 0; +} + +static const struct media_entity_operations isp4sd_sdev_ent_ops =3D { + .link_validate =3D isp4sd_sdev_link_validate, +}; + +int isp4sd_init(struct isp4_subdev *isp_subdev, + struct v4l2_device *v4l2_dev) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4sd_sensor_info *sensor_info; + struct device *dev =3D v4l2_dev->dev; + int ret; + + isp_subdev->dev =3D dev; + v4l2_subdev_init(&isp_subdev->sdev, &isp4sd_subdev_ops); + isp_subdev->sdev.owner =3D THIS_MODULE; + isp_subdev->sdev.dev =3D dev; + snprintf(isp_subdev->sdev.name, sizeof(isp_subdev->sdev.name), "%s", + dev_name(dev)); + + isp_subdev->sdev.entity.name =3D isp4sd_entity_name; + isp_subdev->sdev.entity.function =3D MEDIA_ENT_F_PROC_VIDEO_ISP; + isp_subdev->sdev.entity.ops =3D &isp4sd_sdev_ent_ops; + isp_subdev->sdev_pad.flags =3D MEDIA_PAD_FL_SOURCE; + ret =3D media_entity_pads_init(&isp_subdev->sdev.entity, 1, + &isp_subdev->sdev_pad); + if (ret) { + dev_err(dev, "fail to init isp4 subdev entity pad %d\n", ret); + return ret; + } + ret =3D v4l2_subdev_init_finalize(&isp_subdev->sdev); + if (ret < 0) { + dev_err(dev, "fail to init finalize isp4 subdev %d\n", + ret); + return ret; + } + ret =3D v4l2_device_register_subdev(v4l2_dev, &isp_subdev->sdev); + if (ret) { + dev_err(dev, "fail to register isp4 subdev to V4L2 device %d\n", + ret); + goto err_media_clean_up; + } + + sensor_info =3D &isp_subdev->sensor_info; + + isp4if_init(ispif, dev, isp_subdev->mmio); + + mutex_init(&isp_subdev->ops_mutex); + sensor_info->start_stream_cmd_sent =3D false; + sensor_info->status =3D ISP4SD_START_STATUS_NOT_START; + + /* create ISP enable gpio control */ + isp_subdev->enable_gpio =3D devm_gpiod_get(isp_subdev->dev, + "enable_isp", + GPIOD_OUT_LOW); + if (IS_ERR(isp_subdev->enable_gpio)) { + dev_err(dev, "fail to get gpiod %d\n", ret); + media_entity_cleanup(&isp_subdev->sdev.entity); + return PTR_ERR(isp_subdev->enable_gpio); + } + + isp_subdev->host2fw_seq_num =3D 1; + ispif->status =3D ISP4IF_STATUS_PWR_OFF; + + if (ret) + goto err_media_clean_up; + return ret; + +err_media_clean_up: + media_entity_cleanup(&isp_subdev->sdev.entity); + return ret; +} + +void isp4sd_deinit(struct isp4_subdev *isp_subdev) +{ + struct isp4_interface *ispif =3D &isp_subdev->ispif; + + media_entity_cleanup(&isp_subdev->sdev.entity); + isp4if_deinit(ispif); + isp4sd_module_enable(isp_subdev, false); + + ispif->status =3D ISP4IF_STATUS_PWR_OFF; +} diff --git a/drivers/media/platform/amd/isp4/isp4_subdev.h b/drivers/media/= platform/amd/isp4/isp4_subdev.h new file mode 100644 index 000000000000..524a8de5e18d --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_subdev.h @@ -0,0 +1,131 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _ISP4_CONTEXT_H_ +#define _ISP4_CONTEXT_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include "isp4_fw_cmd_resp.h" +#include "isp4_hw_reg.h" +#include "isp4_interface.h" + +/* + * one is for none sesnor specefic response which is not used now + * another is for sensor specific response + */ +#define ISP4SD_MAX_FW_RESP_STREAM_NUM 2 + +/* + * cmd used to register frame done callback, parameter is + * struct isp4sd_register_framedone_cb_param * + * when a image buffer is filled by ISP, ISP will call the registered call= back. + * callback func prototype is isp4sd_framedone_cb, cb_ctx can be anything + * provided by caller which will be provided back as the first parameter o= f the + * callback function. + * both cb_func and cb_ctx are provide by caller, set cb_func to NULL to + * unregister the callback + */ + +/* used to indicate the ISP status */ +enum isp4sd_status { + ISP4SD_STATUS_PWR_OFF, + ISP4SD_STATUS_PWR_ON, + ISP4SD_STATUS_FW_RUNNING, + ISP4SD_STATUS_MAX +}; + +/* used to indicate the status of sensor, output stream */ +enum isp4sd_start_status { + ISP4SD_START_STATUS_NOT_START, + ISP4SD_START_STATUS_STARTED, + ISP4SD_START_STATUS_START_FAIL, +}; + +struct isp4sd_img_buf_node { + struct list_head node; + struct isp4if_img_buf_info buf_info; +}; + +/* this is isp output after processing bayer raw input from sensor */ +struct isp4sd_output_info { + enum isp4sd_start_status start_status; + u32 image_size; +}; + +/* + * This struct represents the sensor info which is input or source of ISP, + * meta_info_buf is the buffer store the fw to driver metainfo response + * status is the sensor status + * output_info is the isp output info after ISP processing the sensor inpu= t, + * start_stream_cmd_sent mean if CMD_ID_START_STREAM has sent to fw. + * buf_sent_cnt is buffer count app has sent to receive the images + */ +struct isp4sd_sensor_info { + struct isp4if_gpu_mem_info * + meta_info_buf[ISP4IF_MAX_STREAM_BUF_COUNT]; + struct isp4sd_output_info output_info; + enum isp4sd_start_status status; + bool start_stream_cmd_sent; + u32 buf_sent_cnt; +}; + +/* + * Thread created by driver to receive fw response + * thread will be wakeup by fw to driver response interrupt + */ +struct isp4sd_thread_handler { + struct task_struct *thread; + struct mutex mutex; /* mutex */ + wait_queue_head_t waitq; + int wq_cond; +}; + +struct isp4_subdev_thread_param { + u32 idx; + struct isp4_subdev *isp_subdev; +}; + +struct isp4_subdev { + struct v4l2_subdev sdev; + struct isp4_interface ispif; + + struct media_pad sdev_pad; + + enum isp4sd_status isp_status; + struct mutex ops_mutex; /* ops_mutex */ + + /* Used to store fw cmds sent to FW whose response driver needs to wait f= or */ + struct isp4sd_thread_handler + fw_resp_thread[ISP4SD_MAX_FW_RESP_STREAM_NUM]; + + u32 host2fw_seq_num; + + struct isp4sd_sensor_info sensor_info; + + /* gpio descriptor */ + struct gpio_desc *enable_gpio; + struct device *dev; + void __iomem *mmio; + struct isp4_subdev_thread_param + isp_resp_para[ISP4SD_MAX_FW_RESP_STREAM_NUM]; +#ifdef CONFIG_DEBUG_FS + struct dentry *debugfs_dir; + bool enable_fw_log; + char *fw_log_output; +#endif +}; + +int isp4sd_init(struct isp4_subdev *isp_subdev, + struct v4l2_device *v4l2_dev); +void isp4sd_deinit(struct isp4_subdev *isp_subdev); + +#endif --=20 2.34.1 From nobody Thu Oct 2 20:44:48 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2042.outbound.protection.outlook.com [40.107.93.42]) (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 2AB1630EF86; Thu, 11 Sep 2025 10:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585395; cv=fail; b=BeESbkDhbTMc3MOi0HHaekq5IXHuTpK+ZdAwZMajn2TtN5pZ8se1i3Wr6c2+ZtXU4WguYFuaI2Hzy4RZaYtYWW+BN65ZVnS+sLAwuLmdtMBDfWt9yyPXEUSz9QvUqfmcXegyVmS1PTMRb93AHik0VPw79zdrO8lqu0/WVj0SaBg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585395; c=relaxed/simple; bh=t4Jn/1G4TsgNuOPOkS+EWqXYzxbfjFPQmJieaTdoXLE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JyFUewwPweoKiR3rlQKbw12EsZyLu7xhByzoLIinn9JHY1e1iBfCEeU3YCBw3+X5ew9BEBDb9lP7P8iTQlclCLinX1l65zlJRwb7dD0DTpvNrvHWZJFJy8KrbAla/UJhh0DsblgLobtkPWp5aB+pxf2VIDhd6EUXXWCWtmLIj40= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=FabgaN7z; arc=fail smtp.client-ip=40.107.93.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="FabgaN7z" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=J2HB4/PXUEPjy9If6AevAyJKivkn8gr80nmYqMg2QCV3o0DLKT6uMInxn0jgAkAHY9ApGLjwzH+AbCo9/lAggrleZgXe1TsXcbqxJG5Q/eaz5zPwcaqaKrxII8Ahu2selOTzhyGW4yxs1uDke/EYOe4uxeMtk2prMgU14Gf4N9qfHhqZg39VvrU4Trd53g0b6q4QbNX0yri2ZywoI3DI17PoycHwU2hNQnnUYb57Q/9lQaGtxlM4pXWZaqofF0CV8Zplz5d6jyQviAxfmKubKyJp6T8FM1C0O+iU5S4OqhaLcNL6yVR2X5la9+L4m5K6tJsnPOTQd5RH+LCtdClRhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=nrMl2UFD/ju1YQn4A+XBzJJmUgFywgLETGv8sKTaZcM=; b=weDwFHVzY24aaeA77B1Xw0NEOb4CBRipnzoR1REOqdTJ9zFFhLg3oPBYbY6TxSf1s9bV1ZGybW3mec7WOf7iFdZ1MqMV0J/LN4HZ6tQsERM687KoXhu9MIUza575vMq4RphQM190u3hKqNmlMfnkf68Z3DtZSbtVX3YTs9m8dlgK5WEtuifTLLvamqEKgAxoOg5FblF0aCh1vetI+3GWQW0njs7iY9vFKBO2K+RrUS4FrTkRSEnDgvnDTs8CEaSDHKeOmH/1QCB5XHCxn5zDdOuyUe/pwXpovTV89M/ow6BJQZgzm1g4Cvk/s3N785HwLuUAGXzCVYaa0WqsGPaMJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nrMl2UFD/ju1YQn4A+XBzJJmUgFywgLETGv8sKTaZcM=; b=FabgaN7zhBzfg2KR0j1jf11RUfKQ7Ai6Mvp+R7K6OB2QygY1V01iq2PqjA0VLH7aHe2tEw+twVLIRrZyAad1k6yxIX8QGHKyCqCDi4w8auiyQhg2P6tpL67fBzyRTaGG+CB9ZU/w9ZnHcw8tL+jhKEVz4o82ovKhUN9lNcGaSr8= Received: from MN2PR04CA0011.namprd04.prod.outlook.com (2603:10b6:208:d4::24) by DS0PR12MB7728.namprd12.prod.outlook.com (2603:10b6:8:13a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Thu, 11 Sep 2025 10:09:38 +0000 Received: from MN1PEPF0000ECD9.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::9d) by MN2PR04CA0011.outlook.office365.com (2603:10b6:208:d4::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9115.15 via Frontend Transport; Thu, 11 Sep 2025 10:09:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MN1PEPF0000ECD9.mail.protection.outlook.com (10.167.242.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Thu, 11 Sep 2025 10:09:38 +0000 Received: from 555e2b870847.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 11 Sep 2025 03:09:33 -0700 From: Bin Du To: , , , , , , , , CC: , , , , , , , , , , Bin Du , Svetoslav Stoilov , "Alexey Zagorodnikov" Subject: [PATCH v4 5/7] media: platform: amd: isp4 video node and buffers handling added Date: Thu, 11 Sep 2025 18:08:45 +0800 Message-ID: <20250911100847.277408-6-Bin.Du@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911100847.277408-1-Bin.Du@amd.com> References: <20250911100847.277408-1-Bin.Du@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD9:EE_|DS0PR12MB7728:EE_ X-MS-Office365-Filtering-Correlation-Id: 150b6b6c-9ace-4ae0-63a4-08ddf11b511f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|1800799024|36860700013|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MlXpQtzzFZwF3KDjX6p3L94aICRR8j5CPV/pOQFCpiWWFQp0LEduUnM7tzN0?= =?us-ascii?Q?BRkIzfJAGSgd/H31rcj/w4wOaZP7TotC3p0ga59WNVDkR1wMkUczOSk6O+Rq?= =?us-ascii?Q?rRkGbkvUOxH10IqEZwYhQzjCDLUAjQCdlfEBM1o3CKAArD5NEkGaQ6YPB1Vg?= =?us-ascii?Q?03KRQPpKxs7lirjv22NHXPsv05B5l3sf+6ppupLlp9LaYNXpLOJqOjU+19uH?= =?us-ascii?Q?zUEH3BNAzjzgJTqm9WvfbHGDZro/mFog66RoMTt65VYpkEIoHwWVXZwg0q7i?= =?us-ascii?Q?dRL8Y+rZRk4JB3dEyshUMJSzFzGw6WBAdPU+vZKeT1mhnIZ+5ozIBebDZCmd?= =?us-ascii?Q?tFBCF/Fg9m8zpkzJeKBULk4hRdzaC/RrzAAbRpMkqC2CRcz0GrE13h+t1pMv?= =?us-ascii?Q?+XVoO/9WMC29d1sIivVn2UpAjlThUt0seRRBEFzIhQlV8bzmG87UqTybjr+v?= =?us-ascii?Q?jUSZbV5yE2lYegB/6Cg35UeMdt9iwkO3dO2Cp2djphoeMwD8koON5SBOcaOc?= =?us-ascii?Q?6A1+xZjmYaaFsqzIPa2FwWy/aCyaVoTQbpAHuldKG9yNMqeT/+6jJcVe2qZY?= =?us-ascii?Q?6QKp/7jGX2Du9H7jAfG+MEpStVJsFT9RltcxYDqen9r6tOpBysJhsLHwBqkw?= =?us-ascii?Q?htU7iWUpF1CNG5LRM0XJCKPi6H2ktdBWN5wTzMxZQ2DZWUZcEPWAspzsCxFe?= =?us-ascii?Q?CccN80VEoyQXgj54XK40hwmNaQojMzIvUIv2JaVm6Xmup5yFjzqZW/TlC3Yv?= =?us-ascii?Q?zMJk8glGxzZFI3WgZKwPLnt5/eyulMfLX/lFsJ1hQstZwubmokcbPEEExBpa?= =?us-ascii?Q?+NKXp50OvRET61/8dqr8s1ybhsqPPNIwXyP0YKxfm7XZ3c/8QIhvUY+M77Rq?= =?us-ascii?Q?Q6b5lTmf3qhiZLSJ2TdUeojWL5ewkLI4jx2VQz3XSuEaqPx40TtdjRGjkUiO?= =?us-ascii?Q?3duZbwxzWKxp/BSGl9ubNZ5bRGKPOYSuUeJ7dPe/HyPbLYDXXQZ8pq2y+TR3?= =?us-ascii?Q?SheLqM0ll8emsrZ9zvDMv2CDt6KIMEMwJYIyY1I+UXzmsRGikq/UhuOyNwza?= =?us-ascii?Q?5I20I2X+yC0cvsJnKLWI5gq6WVcX7/uVjoDPCHRmN/1Rcac48pjWq+yqFXVN?= =?us-ascii?Q?rS+8oB5mxXvmFQLlDqW/ly1A+3CEfWPwLuisZoR5BlDfmRA+DnhLx13gkMEq?= =?us-ascii?Q?Q136EsXBmUDMF4Iw/ohGwDTq732TOepChBEOU7ockG1pfNqHoszZ4mejYXo+?= =?us-ascii?Q?uEgmk60LCHEiDGSJfK8xIETGGg+2DRiwe7scUe+AkZEDnfb1qDHJFGVMIi6k?= =?us-ascii?Q?dAJPLoE/NRzYFkPokNteVvUc10O9Ys5FguzyDtS1pnvkmCLslGKiJ0ezkuWi?= =?us-ascii?Q?WfYh/7TEe8xFxTvlJ6sK5w0tkEvf3decZqIZrNGg1tdUFtVOAggZWQ64hX/6?= =?us-ascii?Q?b6yElWONwCC3o0m3rk5LDRKY299pmnDW//alolZMI3x06BAzgyA+Qwhzf7uS?= =?us-ascii?Q?NtZOwUOubWFT3C4QaIkn/ZUXp5WfxF1c0w3AMrWDXGkbR8FlC+S4Wu4A0A?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(1800799024)(36860700013)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2025 10:09:38.3467 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 150b6b6c-9ace-4ae0-63a4-08ddf11b511f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECD9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7728 Content-Type: text/plain; charset="utf-8" Isp video implements v4l2 video interface and supports NV12 and YUYV. It manages buffers, pipeline power and state. Cherry-picked Sultan's DMA buffer related fix from branch v6.16-drm-tip-isp4-for-amd on https://github.com/kerneltoast/kernel_x86_laptop.git Co-developed-by: Sultan Alsawaf Signed-off-by: Sultan Alsawaf Co-developed-by: Svetoslav Stoilov Signed-off-by: Svetoslav Stoilov Signed-off-by: Bin Du Tested-by: Alexey Zagorodnikov --- MAINTAINERS | 2 + drivers/media/platform/amd/isp4/Makefile | 1 + drivers/media/platform/amd/isp4/isp4.c | 10 + drivers/media/platform/amd/isp4/isp4_subdev.c | 95 +- drivers/media/platform/amd/isp4/isp4_subdev.h | 2 + drivers/media/platform/amd/isp4/isp4_video.c | 1207 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_video.h | 87 ++ 7 files changed, 1400 insertions(+), 4 deletions(-) create mode 100644 drivers/media/platform/amd/isp4/isp4_video.c create mode 100644 drivers/media/platform/amd/isp4/isp4_video.h diff --git a/MAINTAINERS b/MAINTAINERS index 48ffc8bbdcee..80c966fde0b4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1151,6 +1151,8 @@ F: drivers/media/platform/amd/isp4/isp4_interface.c F: drivers/media/platform/amd/isp4/isp4_interface.h F: drivers/media/platform/amd/isp4/isp4_subdev.c F: drivers/media/platform/amd/isp4/isp4_subdev.h +F: drivers/media/platform/amd/isp4/isp4_video.c +F: drivers/media/platform/amd/isp4/isp4_video.h =20 AMD KFD M: Felix Kuehling diff --git a/drivers/media/platform/amd/isp4/Makefile b/drivers/media/platf= orm/amd/isp4/Makefile index 905788bc6a1e..33589091ca96 100644 --- a/drivers/media/platform/amd/isp4/Makefile +++ b/drivers/media/platform/amd/isp4/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_AMD_ISP4) +=3D amd_capture.o amd_capture-objs :=3D isp4_subdev.o \ isp4_interface.o \ isp4.o \ + isp4_video.o \ No newline at end of file diff --git a/drivers/media/platform/amd/isp4/isp4.c b/drivers/media/platfor= m/amd/isp4/isp4.c index 8cec27228710..a46e110a396f 100644 --- a/drivers/media/platform/amd/isp4/isp4.c +++ b/drivers/media/platform/amd/isp4/isp4.c @@ -178,6 +178,16 @@ static int isp4_capture_probe(struct platform_device *= pdev) goto err_isp4_deinit; } =20 + ret =3D media_create_pad_link(&isp_dev->isp_sdev.sdev.entity, + 0, &isp_dev->isp_sdev.isp_vdev.vdev.entity, + 0, + MEDIA_LNK_FL_ENABLED | + MEDIA_LNK_FL_IMMUTABLE); + if (ret) { + dev_err(dev, "fail to create pad link %d\n", ret); + goto err_isp4_deinit; + } + platform_set_drvdata(pdev, isp_dev); =20 return 0; diff --git a/drivers/media/platform/amd/isp4/isp4_subdev.c b/drivers/media/= platform/amd/isp4/isp4_subdev.c index a9cb14de04ca..7d3339c915eb 100644 --- a/drivers/media/platform/amd/isp4/isp4_subdev.c +++ b/drivers/media/platform/amd/isp4/isp4_subdev.c @@ -466,20 +466,25 @@ isp4sd_get_meta_by_mc(struct isp4_subdev *isp_subdev, =20 static struct isp4if_img_buf_node * isp4sd_preview_done(struct isp4_subdev *isp_subdev, - struct isp4fw_meta_info *meta) + struct isp4fw_meta_info *meta, + struct isp4vid_framedone_param *pcb) { struct isp4_interface *ispif =3D &isp_subdev->ispif; struct isp4if_img_buf_node *prev =3D NULL; struct device *dev =3D isp_subdev->dev; =20 + pcb->preview.status =3D ISP4VID_BUF_DONE_STATUS_ABSENT; if (meta->preview.enabled && (meta->preview.status =3D=3D BUFFER_STATUS_SKIPPED || meta->preview.status =3D=3D BUFFER_STATUS_DONE || meta->preview.status =3D=3D BUFFER_STATUS_DIRTY)) { prev =3D isp4if_dequeue_buffer(ispif); - if (!prev) + if (!prev) { dev_err(dev, "fail null prev buf\n"); - + } else { + pcb->preview.buf =3D prev->buf_info; + pcb->preview.status =3D ISP4VID_BUF_DONE_STATUS_SUCCESS; + } } else if (meta->preview.enabled) { dev_err(dev, "fail bad preview status %u\n", meta->preview.status); @@ -525,6 +530,7 @@ static void isp4sd_fw_resp_frame_done(struct isp4_subde= v *isp_subdev, enum isp4if_stream_id stream_id, struct isp4fw_resp_param_package *para) { + struct isp4vid_framedone_param pcb =3D {}; struct isp4if_img_buf_node *prev =3D NULL; struct device *dev =3D isp_subdev->dev; struct isp4fw_meta_info *meta; @@ -537,12 +543,17 @@ static void isp4sd_fw_resp_frame_done(struct isp4_sub= dev *isp_subdev, return; } =20 + pcb.poc =3D meta->poc; + pcb.cam_id =3D 0; + dev_dbg(dev, "ts:%llu,streamId:%d,poc:%u,preview_en:%u,(%i)\n", ktime_get_ns(), stream_id, meta->poc, meta->preview.enabled, meta->preview.status); =20 - prev =3D isp4sd_preview_done(isp_subdev, meta); + prev =3D isp4sd_preview_done(isp_subdev, meta, &pcb); + if (pcb.preview.status !=3D ISP4VID_BUF_DONE_STATUS_ABSENT) + isp4vid_notify(&isp_subdev->isp_vdev, &pcb); =20 isp4if_dealloc_buffer_node(prev); =20 @@ -917,6 +928,75 @@ static int isp4sd_start_stream(struct isp4_subdev *isp= _subdev, return ret; } =20 +static int isp4sd_ioc_send_img_buf(struct v4l2_subdev *sd, + struct isp4if_img_buf_info *buf_info) +{ + struct isp4_subdev *isp_subdev =3D to_isp4_subdev(sd); + struct isp4_interface *ispif =3D &isp_subdev->ispif; + struct isp4if_img_buf_node *buf_node =3D NULL; + struct device *dev =3D isp_subdev->dev; + int ret =3D -EINVAL; + + mutex_lock(&isp_subdev->ops_mutex); + /* TODO: remove isp_status */ + if (ispif->status !=3D ISP4IF_STATUS_FW_RUNNING) { + dev_err(dev, "fail send img buf for bad fsm %d\n", + ispif->status); + mutex_unlock(&isp_subdev->ops_mutex); + return -EINVAL; + } + + buf_node =3D isp4if_alloc_buffer_node(buf_info); + if (!buf_node) { + dev_err(dev, "fail alloc sys img buf info node\n"); + ret =3D -ENOMEM; + goto unlock_and_return; + } + + ret =3D isp4if_queue_buffer(ispif, buf_node); + if (ret) { + dev_err(dev, "fail to queue image buf, %d\n", ret); + goto error_release_buf_node; + } + + if (!isp_subdev->sensor_info.start_stream_cmd_sent) { + isp_subdev->sensor_info.buf_sent_cnt++; + + if (isp_subdev->sensor_info.buf_sent_cnt >=3D + ISP4SD_MIN_BUF_CNT_BEF_START_STREAM) { + ret =3D isp4if_send_command(ispif, CMD_ID_START_STREAM, + NULL, 0); + + if (ret) { + dev_err(dev, "fail to START_STREAM"); + goto error_release_buf_node; + } + isp_subdev->sensor_info.start_stream_cmd_sent =3D true; + isp_subdev->sensor_info.output_info.start_status =3D + ISP4SD_START_STATUS_STARTED; + isp_subdev->sensor_info.status =3D + ISP4SD_START_STATUS_STARTED; + } else { + dev_dbg(dev, + "no send start,required %u,buf sent %u\n", + ISP4SD_MIN_BUF_CNT_BEF_START_STREAM, + isp_subdev->sensor_info.buf_sent_cnt); + } + } + + mutex_unlock(&isp_subdev->ops_mutex); + + return 0; + +error_release_buf_node: + isp4if_dealloc_buffer_node(buf_node); + +unlock_and_return: + mutex_unlock(&isp_subdev->ops_mutex); + + return ret; +} + static int isp4sd_set_power(struct v4l2_subdev *sd, int on) { struct isp4_subdev *ispsd =3D to_isp4_subdev(sd); @@ -1015,6 +1095,10 @@ static const struct media_entity_operations isp4sd_s= dev_ent_ops =3D { .link_validate =3D isp4sd_sdev_link_validate, }; =20 +static const struct isp4vid_ops isp4sd_isp4vid_ops =3D { + .send_buffer =3D isp4sd_ioc_send_img_buf, +}; + int isp4sd_init(struct isp4_subdev *isp_subdev, struct v4l2_device *v4l2_dev) { @@ -1074,6 +1158,8 @@ int isp4sd_init(struct isp4_subdev *isp_subdev, isp_subdev->host2fw_seq_num =3D 1; ispif->status =3D ISP4IF_STATUS_PWR_OFF; =20 + ret =3D isp4vid_dev_init(&isp_subdev->isp_vdev, &isp_subdev->sdev, + &isp4sd_isp4vid_ops); if (ret) goto err_media_clean_up; return ret; @@ -1087,6 +1173,7 @@ void isp4sd_deinit(struct isp4_subdev *isp_subdev) { struct isp4_interface *ispif =3D &isp_subdev->ispif; =20 + isp4vid_dev_deinit(&isp_subdev->isp_vdev); media_entity_cleanup(&isp_subdev->sdev.entity); isp4if_deinit(ispif); isp4sd_module_enable(isp_subdev, false); diff --git a/drivers/media/platform/amd/isp4/isp4_subdev.h b/drivers/media/= platform/amd/isp4/isp4_subdev.h index 524a8de5e18d..322bd990bbaa 100644 --- a/drivers/media/platform/amd/isp4/isp4_subdev.h +++ b/drivers/media/platform/amd/isp4/isp4_subdev.h @@ -17,6 +17,7 @@ #include "isp4_fw_cmd_resp.h" #include "isp4_hw_reg.h" #include "isp4_interface.h" +#include "isp4_video.h" =20 /* * one is for none sesnor specefic response which is not used now @@ -97,6 +98,7 @@ struct isp4_subdev_thread_param { struct isp4_subdev { struct v4l2_subdev sdev; struct isp4_interface ispif; + struct isp4vid_dev isp_vdev; =20 struct media_pad sdev_pad; =20 diff --git a/drivers/media/platform/amd/isp4/isp4_video.c b/drivers/media/p= latform/amd/isp4/isp4_video.c new file mode 100644 index 000000000000..38252854012e --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_video.c @@ -0,0 +1,1207 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#include +#include +#include +#include +#include + +#include "isp4_interface.h" +#include "isp4_subdev.h" +#include "isp4_video.h" + +#define ISP4VID_ISP_DRV_NAME "amd_isp_capture" +#define ISP4VID_MAX_PREVIEW_FPS 30 +#define ISP4VID_DEFAULT_FMT isp4vid_formats[0] + +#define ISP4VID_PAD_VIDEO_OUTPUT 0 + +/* timeperframe default */ +#define ISP4VID_ISP_TPF_DEFAULT isp4vid_tpfs[0] + +/* amdisp buffer for vb2 operations */ +struct isp4vid_vb2_buf { + struct device *dev; + void *vaddr; + unsigned long size; + refcount_t refcount; + struct dma_buf *dbuf; + void *bo; + u64 gpu_addr; + struct vb2_vmarea_handler handler; +}; + +static int isp4vid_vb2_mmap(void *buf_priv, struct vm_area_struct *vma); + +static void isp4vid_vb2_put(void *buf_priv); + +static const char *isp4vid_video_dev_name =3D "Preview"; + +/* Sizes must be in increasing order */ +static const struct v4l2_frmsize_discrete isp4vid_frmsize[] =3D { + {640, 360}, + {640, 480}, + {1280, 720}, + {1280, 960}, + {1920, 1080}, + {1920, 1440}, + {2560, 1440}, + {2880, 1620}, + {2880, 1624}, + {2888, 1808}, +}; + +static const u32 isp4vid_formats[] =3D { + V4L2_PIX_FMT_NV12, + V4L2_PIX_FMT_YUYV +}; + +/* timeperframe list */ +static const struct v4l2_fract isp4vid_tpfs[] =3D { + {.numerator =3D 1, .denominator =3D ISP4VID_MAX_PREVIEW_FPS} +}; + +static void isp4vid_handle_frame_done(struct isp4vid_dev *isp_vdev, + const struct isp4if_img_buf_info *img_buf, + bool done_suc) +{ + struct isp4vid_capture_buffer *isp4vid_buf; + enum vb2_buffer_state state; + void *vbuf; + + mutex_lock(&isp_vdev->buf_list_lock); + + /* Get the first entry of the list */ + isp4vid_buf =3D list_first_entry_or_null(&isp_vdev->buf_list, typeof(*isp= 4vid_buf), list); + if (!isp4vid_buf) { + mutex_unlock(&isp_vdev->buf_list_lock); + return; + } + + vbuf =3D vb2_plane_vaddr(&isp4vid_buf->vb2.vb2_buf, 0); + + if (vbuf !=3D img_buf->planes[0].sys_addr) { + dev_err(isp_vdev->dev, "Invalid vbuf"); + mutex_unlock(&isp_vdev->buf_list_lock); + return; + } + + /* Remove this entry from the list */ + list_del(&isp4vid_buf->list); + + mutex_unlock(&isp_vdev->buf_list_lock); + + /* Fill the buffer */ + isp4vid_buf->vb2.vb2_buf.timestamp =3D ktime_get_ns(); + isp4vid_buf->vb2.sequence =3D isp_vdev->sequence++; + isp4vid_buf->vb2.field =3D V4L2_FIELD_ANY; + + /* at most 2 planes */ + vb2_set_plane_payload(&isp4vid_buf->vb2.vb2_buf, + 0, isp_vdev->format.sizeimage); + + state =3D done_suc ? VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR; + vb2_buffer_done(&isp4vid_buf->vb2.vb2_buf, state); + + dev_dbg(isp_vdev->dev, "call vb2_buffer_done(size=3D%u)\n", + isp_vdev->format.sizeimage); +} + +s32 isp4vid_notify(void *cb_ctx, struct isp4vid_framedone_param *evt_param) +{ + struct isp4vid_dev *isp4vid_vdev =3D cb_ctx; + + if (evt_param->preview.status !=3D ISP4VID_BUF_DONE_STATUS_ABSENT) { + bool suc; + + suc =3D (evt_param->preview.status =3D=3D + ISP4VID_BUF_DONE_STATUS_SUCCESS); + isp4vid_handle_frame_done(isp4vid_vdev, + &evt_param->preview.buf, + suc); + } + + return 0; +} + +static unsigned int isp4vid_vb2_num_users(void *buf_priv) +{ + struct isp4vid_vb2_buf *buf =3D buf_priv; + + return refcount_read(&buf->refcount); +} + +static int isp4vid_vb2_mmap(void *buf_priv, struct vm_area_struct *vma) +{ + struct isp4vid_vb2_buf *buf =3D buf_priv; + int ret; + + if (!buf) { + pr_err("fail no memory to map\n"); + return -EINVAL; + } + + ret =3D remap_vmalloc_range(vma, buf->vaddr, 0); + if (ret) { + dev_err(buf->dev, "fail remap vmalloc mem, %d\n", ret); + return ret; + } + + /* + * Make sure that vm_areas for 2 buffers won't be merged together + */ + vm_flags_set(vma, VM_DONTEXPAND); + + /* + * Use common vm_area operations to track buffer refcount. + */ + vma->vm_private_data =3D &buf->handler; + vma->vm_ops =3D &vb2_common_vm_ops; + + vma->vm_ops->open(vma); + + dev_dbg(buf->dev, "mmap isp user bo 0x%llx size %ld refcount %d\n", + buf->gpu_addr, buf->size, refcount_read(&buf->refcount)); + + return 0; +} + +static void *isp4vid_vb2_vaddr(struct vb2_buffer *vb, void *buf_priv) +{ + struct isp4vid_vb2_buf *buf =3D buf_priv; + + if (!buf->vaddr) { + dev_err(buf->dev, + "fail for buf vaddr is null\n"); + return NULL; + } + return buf->vaddr; +} + +static void isp4vid_vb2_detach_dmabuf(void *mem_priv) +{ + struct isp4vid_vb2_buf *buf =3D mem_priv; + + dev_dbg(buf->dev, "detach dmabuf of isp user bo 0x%llx size %ld", + buf->gpu_addr, buf->size); + + kfree(buf); +} + +static void *isp4vid_vb2_attach_dmabuf(struct vb2_buffer *vb, struct devic= e *dev, + struct dma_buf *dbuf, + unsigned long size) +{ + struct isp4vid_vb2_buf *buf; + + if (dbuf->size < size) { + dev_err(dev, "Invalid dmabuf size %zu %lu", dbuf->size, size); + return ERR_PTR(-EFAULT); + } + + buf =3D kzalloc(sizeof(*buf), GFP_KERNEL); + if (!buf) + return ERR_PTR(-ENOMEM); + + struct isp4vid_vb2_buf *dbg_buf =3D dbuf->priv; + + buf->dev =3D dev; + buf->dbuf =3D dbuf; + buf->size =3D size; + + dev_dbg(dev, "attach dmabuf of isp user bo 0x%llx size %ld", + dbg_buf->gpu_addr, dbg_buf->size); + + return buf; +} + +static void isp4vid_vb2_unmap_dmabuf(void *mem_priv) +{ + struct isp4vid_vb2_buf *buf =3D mem_priv; + struct iosys_map map =3D IOSYS_MAP_INIT_VADDR(buf->vaddr); + + dev_dbg(buf->dev, "unmap dmabuf of isp user bo 0x%llx size %ld", + buf->gpu_addr, buf->size); + + dma_buf_vunmap_unlocked(buf->dbuf, &map); + buf->vaddr =3D NULL; +} + +static int isp4vid_vb2_map_dmabuf(void *mem_priv) +{ + struct isp4vid_vb2_buf *mmap_buf =3D NULL; + struct isp4vid_vb2_buf *buf =3D mem_priv; + struct iosys_map map =3D {}; + int ret; + + ret =3D dma_buf_vmap_unlocked(buf->dbuf, &map); + if (ret) { + dev_err(buf->dev, "vmap_unlocked fail"); + return -EFAULT; + } + buf->vaddr =3D map.vaddr; + + mmap_buf =3D buf->dbuf->priv; + buf->gpu_addr =3D mmap_buf->gpu_addr; + + dev_dbg(buf->dev, "map dmabuf of isp user bo 0x%llx size %ld", + buf->gpu_addr, buf->size); + + return 0; +} + +#ifdef CONFIG_HAS_DMA +struct isp4vid_vb2_amdgpu_attachment { + struct sg_table sgt; + enum dma_data_direction dma_dir; +}; + +static int isp4vid_dmabuf_ops_attach(struct dma_buf *dbuf, + struct dma_buf_attachment *dbuf_attach) +{ + struct isp4vid_vb2_buf *buf =3D dbuf->priv; + int num_pages =3D PAGE_ALIGN(buf->size) / PAGE_SIZE; + struct isp4vid_vb2_amdgpu_attachment *attach; + void *vaddr =3D buf->vaddr; + struct scatterlist *sg; + struct sg_table *sgt; + int ret; + int i; + + attach =3D kzalloc(sizeof(*attach), GFP_KERNEL); + if (!attach) + return -ENOMEM; + + sgt =3D &attach->sgt; + ret =3D sg_alloc_table(sgt, num_pages, GFP_KERNEL); + if (ret) { + kfree(attach); + return ret; + } + for_each_sgtable_sg(sgt, sg, i) { + struct page *page =3D vmalloc_to_page(vaddr); + + if (!page) { + sg_free_table(sgt); + kfree(attach); + return -ENOMEM; + } + sg_set_page(sg, page, PAGE_SIZE, 0); + vaddr =3D ((char *)vaddr) + PAGE_SIZE; + } + + attach->dma_dir =3D DMA_NONE; + dbuf_attach->priv =3D attach; + + return 0; +} + +static void isp4vid_dmabuf_ops_detach(struct dma_buf *dbuf, + struct dma_buf_attachment *dbuf_attach) +{ + struct isp4vid_vb2_amdgpu_attachment *attach =3D dbuf_attach->priv; + struct sg_table *sgt; + + if (!attach) { + pr_err("fail invalid attach handler\n"); + return; + } + + sgt =3D &attach->sgt; + + /* release the scatterlist cache */ + if (attach->dma_dir !=3D DMA_NONE) + dma_unmap_sgtable(dbuf_attach->dev, sgt, attach->dma_dir, 0); + sg_free_table(sgt); + kfree(attach); + dbuf_attach->priv =3D NULL; +} + +static struct sg_table *isp4vid_dmabuf_ops_map(struct dma_buf_attachment *= dbuf_attach, + enum dma_data_direction dma_dir) +{ + struct isp4vid_vb2_amdgpu_attachment *attach =3D dbuf_attach->priv; + struct sg_table *sgt; + + sgt =3D &attach->sgt; + /* return previously mapped sg table */ + if (attach->dma_dir =3D=3D dma_dir) + return sgt; + + /* release any previous cache */ + if (attach->dma_dir !=3D DMA_NONE) { + dma_unmap_sgtable(dbuf_attach->dev, sgt, attach->dma_dir, 0); + attach->dma_dir =3D DMA_NONE; + } + + /* mapping to the client with new direction */ + if (dma_map_sgtable(dbuf_attach->dev, sgt, dma_dir, 0)) { + dev_err(dbuf_attach->dev, "fail to map scatterlist"); + return ERR_PTR(-EIO); + } + + attach->dma_dir =3D dma_dir; + + return sgt; +} + +static void isp4vid_dmabuf_ops_unmap(struct dma_buf_attachment *dbuf_attac= h, + struct sg_table *sgt, + enum dma_data_direction dma_dir) +{ + /* nothing to be done here */ +} + +static int isp4vid_dmabuf_ops_vmap(struct dma_buf *dbuf, + struct iosys_map *map) +{ + struct isp4vid_vb2_buf *buf =3D dbuf->priv; + + iosys_map_set_vaddr(map, buf->vaddr); + + return 0; +} + +static void isp4vid_dmabuf_ops_release(struct dma_buf *dbuf) +{ + struct isp4vid_vb2_buf *buf =3D dbuf->priv; + + /* drop reference obtained in isp4vid_vb2_get_dmabuf */ + if (dbuf !=3D buf->dbuf) + isp4vid_vb2_put(buf); + else + kfree(buf); +} + +static int isp4vid_dmabuf_ops_mmap(struct dma_buf *dbuf, struct vm_area_st= ruct *vma) +{ + return isp4vid_vb2_mmap(dbuf->priv, vma); +} + +static const struct dma_buf_ops isp4vid_dmabuf_ops =3D { + .attach =3D isp4vid_dmabuf_ops_attach, + .detach =3D isp4vid_dmabuf_ops_detach, + .map_dma_buf =3D isp4vid_dmabuf_ops_map, + .unmap_dma_buf =3D isp4vid_dmabuf_ops_unmap, + .vmap =3D isp4vid_dmabuf_ops_vmap, + .mmap =3D isp4vid_dmabuf_ops_mmap, + .release =3D isp4vid_dmabuf_ops_release, +}; + +static struct dma_buf *isp4vid_get_dmabuf(struct isp4vid_vb2_buf *buf, uns= igned long flags) +{ + DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct dma_buf *dbuf; + + if (WARN_ON(!buf->vaddr)) + return NULL; + + exp_info.ops =3D &isp4vid_dmabuf_ops; + exp_info.size =3D buf->size; + exp_info.flags =3D flags; + exp_info.priv =3D buf; + + dbuf =3D dma_buf_export(&exp_info); + if (IS_ERR(dbuf)) + return NULL; + + return dbuf; +} + +static struct dma_buf *isp4vid_vb2_get_dmabuf(struct vb2_buffer *vb, void = *buf_priv, + unsigned long flags) +{ + struct isp4vid_vb2_buf *buf =3D buf_priv; + struct dma_buf *dbuf; + + dbuf =3D isp4vid_get_dmabuf(buf, flags); + if (!dbuf) { + dev_err(buf->dev, "fail to get isp dma buffer\n"); + return NULL; + } + + refcount_inc(&buf->refcount); + + dev_dbg(buf->dev, "buf exported, refcount %d\n", + refcount_read(&buf->refcount)); + + return dbuf; +} +#endif /* CONFIG_HAS_DMA */ + +static void isp4vid_vb2_put(void *buf_priv) +{ + struct isp4vid_vb2_buf *buf =3D buf_priv; + + dev_dbg(buf->dev, + "release isp user bo 0x%llx size %ld refcount %d", + buf->gpu_addr, buf->size, + refcount_read(&buf->refcount)); + + if (refcount_dec_and_test(&buf->refcount)) { + isp_user_buffer_free(buf->bo); + vfree(buf->vaddr); + /* + * Putting the implicit dmabuf frees `buf`. Freeing `buf` must + * be done from the dmabuf release callback since dma_buf_put() + * isn't always synchronous; it's just an fput(), which may be + * deferred. Since the dmabuf release callback needs to access + * `buf`, this means `buf` cannot be freed until then. + */ + dma_buf_put(buf->dbuf); + } +} + +static void *isp4vid_vb2_alloc(struct vb2_buffer *vb, struct device *dev, = unsigned long size) +{ + struct isp4vid_vb2_buf *buf; + u64 gpu_addr; + void *bo; + int ret; + + buf =3D kzalloc(sizeof(*buf), GFP_KERNEL | vb->vb2_queue->gfp_flags); + if (!buf) + return ERR_PTR(-ENOMEM); + + buf->dev =3D dev; + buf->size =3D size; + buf->vaddr =3D vmalloc_user(buf->size); + if (!buf->vaddr) { + dev_err(dev, "fail to vmalloc buffer\n"); + goto free_buf; + } + + buf->handler.refcount =3D &buf->refcount; + buf->handler.put =3D isp4vid_vb2_put; + buf->handler.arg =3D buf; + + /* get implicit dmabuf */ + buf->dbuf =3D isp4vid_get_dmabuf(buf, 0); + if (!buf->dbuf) { + dev_err(dev, "fail to get implicit dmabuf\n"); + goto free_user_vmem; + } + + /* create isp user BO and obtain gpu_addr */ + ret =3D isp_user_buffer_alloc(dev, buf->dbuf, &bo, &gpu_addr); + if (ret) { + dev_err(dev, "fail to create isp user BO\n"); + goto put_dmabuf; + } + + buf->bo =3D bo; + buf->gpu_addr =3D gpu_addr; + + refcount_set(&buf->refcount, 1); + + dev_dbg(dev, "allocated isp user bo 0x%llx size %ld refcount %d\n", + buf->gpu_addr, buf->size, refcount_read(&buf->refcount)); + + return buf; + +put_dmabuf: + dma_buf_put(buf->dbuf); +free_user_vmem: + vfree(buf->vaddr); +free_buf: + ret =3D buf->vaddr ? -EINVAL : -ENOMEM; + kfree(buf); + return ERR_PTR(ret); +} + +static const struct vb2_mem_ops isp4vid_vb2_memops =3D { + .alloc =3D isp4vid_vb2_alloc, + .put =3D isp4vid_vb2_put, +#ifdef CONFIG_HAS_DMA + .get_dmabuf =3D isp4vid_vb2_get_dmabuf, +#endif + .map_dmabuf =3D isp4vid_vb2_map_dmabuf, + .unmap_dmabuf =3D isp4vid_vb2_unmap_dmabuf, + .attach_dmabuf =3D isp4vid_vb2_attach_dmabuf, + .detach_dmabuf =3D isp4vid_vb2_detach_dmabuf, + .vaddr =3D isp4vid_vb2_vaddr, + .mmap =3D isp4vid_vb2_mmap, + .num_users =3D isp4vid_vb2_num_users, +}; + +static const struct v4l2_pix_format isp4vid_fmt_default =3D { + .width =3D 1920, + .height =3D 1080, + .pixelformat =3D V4L2_PIX_FMT_NV12, + .field =3D V4L2_FIELD_NONE, + .colorspace =3D V4L2_COLORSPACE_SRGB, +}; + +static void isp4vid_capture_return_all_buffers(struct isp4vid_dev *isp_vde= v, + enum vb2_buffer_state state) +{ + struct isp4vid_capture_buffer *vbuf, *node; + + mutex_lock(&isp_vdev->buf_list_lock); + + list_for_each_entry_safe(vbuf, node, &isp_vdev->buf_list, list) { + list_del(&vbuf->list); + vb2_buffer_done(&vbuf->vb2.vb2_buf, state); + } + mutex_unlock(&isp_vdev->buf_list_lock); + + dev_dbg(isp_vdev->dev, "call vb2_buffer_done(%d)\n", state); +} + +static int isp4vid_vdev_link_validate(struct media_link *link) +{ + return 0; +} + +static const struct media_entity_operations isp4vid_vdev_ent_ops =3D { + .link_validate =3D isp4vid_vdev_link_validate, +}; + +static const struct v4l2_file_operations isp4vid_vdev_fops =3D { + .owner =3D THIS_MODULE, + .open =3D v4l2_fh_open, + .release =3D vb2_fop_release, + .read =3D vb2_fop_read, + .poll =3D vb2_fop_poll, + .unlocked_ioctl =3D video_ioctl2, + .mmap =3D vb2_fop_mmap, +}; + +static int isp4vid_ioctl_querycap(struct file *file, void *fh, struct v4l2= _capability *cap) +{ + struct isp4vid_dev *isp_vdev =3D video_drvdata(file); + + strscpy(cap->driver, ISP4VID_ISP_DRV_NAME, sizeof(cap->driver)); + snprintf(cap->card, sizeof(cap->card), "%s", ISP4VID_ISP_DRV_NAME); + cap->capabilities |=3D V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE; + + dev_dbg(isp_vdev->dev, "%s|capabilities=3D0x%X", isp_vdev->vdev.name, cap= ->capabilities); + + return 0; +} + +static int isp4vid_g_fmt_vid_cap(struct file *file, void *priv, struct v4l= 2_format *f) +{ + struct isp4vid_dev *isp_vdev =3D video_drvdata(file); + + f->fmt.pix =3D isp_vdev->format; + + return 0; +} + +static int isp4vid_try_fmt_vid_cap(struct file *file, void *priv, struct v= 4l2_format *f) +{ + struct isp4vid_dev *isp_vdev =3D video_drvdata(file); + struct v4l2_pix_format *format =3D &f->fmt.pix; + unsigned int i; + + if (f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + /* + * Check if the hardware supports the requested format, use the default + * format otherwise. + */ + for (i =3D 0; i < ARRAY_SIZE(isp4vid_formats); i++) + if (isp4vid_formats[i] =3D=3D format->pixelformat) + break; + + if (i =3D=3D ARRAY_SIZE(isp4vid_formats)) + format->pixelformat =3D ISP4VID_DEFAULT_FMT; + + switch (format->pixelformat) { + case V4L2_PIX_FMT_NV12: { + const struct v4l2_frmsize_discrete *fsz =3D + v4l2_find_nearest_size(isp4vid_frmsize, + ARRAY_SIZE(isp4vid_frmsize), + width, height, + format->width, format->height); + + format->width =3D fsz->width; + format->height =3D fsz->height; + + format->bytesperline =3D format->width; + format->sizeimage =3D format->bytesperline * + format->height * 3 / 2; + } + break; + case V4L2_PIX_FMT_YUYV: { + const struct v4l2_frmsize_discrete *fsz =3D + v4l2_find_nearest_size(isp4vid_frmsize, + ARRAY_SIZE(isp4vid_frmsize), + width, height, + format->width, format->height); + + format->width =3D fsz->width; + format->height =3D fsz->height; + + format->bytesperline =3D format->width * 2; + format->sizeimage =3D format->bytesperline * format->height; + } + break; + default: + dev_err(isp_vdev->dev, "%s|unsupported fmt=3D%u", + isp_vdev->vdev.name, format->pixelformat); + return -EINVAL; + } + + if (format->field =3D=3D V4L2_FIELD_ANY) + format->field =3D isp4vid_fmt_default.field; + + if (format->colorspace =3D=3D V4L2_COLORSPACE_DEFAULT) + format->colorspace =3D isp4vid_fmt_default.colorspace; + + return 0; +} + +static int isp4vid_set_fmt_2_isp(struct v4l2_subdev *sdev, struct v4l2_pix= _format *pix_fmt) +{ + struct v4l2_subdev_format fmt =3D {}; + + switch (pix_fmt->pixelformat) { + case V4L2_PIX_FMT_NV12: + fmt.format.code =3D MEDIA_BUS_FMT_YUYV8_1_5X8; + break; + case V4L2_PIX_FMT_YUYV: + fmt.format.code =3D MEDIA_BUS_FMT_YUYV8_1X16; + break; + default: + return -EINVAL; + }; + fmt.which =3D V4L2_SUBDEV_FORMAT_ACTIVE; + fmt.pad =3D ISP4VID_PAD_VIDEO_OUTPUT; + fmt.format.width =3D pix_fmt->width; + fmt.format.height =3D pix_fmt->height; + return v4l2_subdev_call(sdev, pad, set_fmt, NULL, &fmt); +} + +static int isp4vid_s_fmt_vid_cap(struct file *file, void *priv, struct v4l= 2_format *f) +{ + struct isp4vid_dev *isp_vdev =3D video_drvdata(file); + int ret; + + /* Do not change the format while stream is on */ + if (vb2_is_busy(&isp_vdev->vbq)) + return -EBUSY; + + if (f->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + ret =3D isp4vid_try_fmt_vid_cap(file, priv, f); + if (ret) + return ret; + + dev_dbg(isp_vdev->dev, "%s|width height:%ux%u->%ux%u", + isp_vdev->vdev.name, + isp_vdev->format.width, isp_vdev->format.height, + f->fmt.pix.width, f->fmt.pix.height); + dev_dbg(isp_vdev->dev, "%s|pixelformat:0x%x-0x%x", + isp_vdev->vdev.name, isp_vdev->format.pixelformat, + f->fmt.pix.pixelformat); + dev_dbg(isp_vdev->dev, "%s|bytesperline:%u->%u", + isp_vdev->vdev.name, isp_vdev->format.bytesperline, + f->fmt.pix.bytesperline); + dev_dbg(isp_vdev->dev, "%s|sizeimage:%u->%u", + isp_vdev->vdev.name, isp_vdev->format.sizeimage, + f->fmt.pix.sizeimage); + + isp_vdev->format =3D f->fmt.pix; + ret =3D isp4vid_set_fmt_2_isp(isp_vdev->isp_sdev, &isp_vdev->format); + + return ret; +} + +static int isp4vid_enum_fmt_vid_cap(struct file *file, void *priv, struct = v4l2_fmtdesc *f) +{ + struct isp4vid_dev *isp_vdev =3D video_drvdata(file); + + switch (f->index) { + case 0: + f->pixelformat =3D V4L2_PIX_FMT_NV12; + break; + case 1: + f->pixelformat =3D V4L2_PIX_FMT_YUYV; + break; + default: + return -EINVAL; + } + + dev_dbg(isp_vdev->dev, "%s|index=3D%d, pixelformat=3D0x%X", + isp_vdev->vdev.name, f->index, f->pixelformat); + + return 0; +} + +static int isp4vid_enum_framesizes(struct file *file, void *fh, struct v4l= 2_frmsizeenum *fsize) +{ + struct isp4vid_dev *isp_vdev =3D video_drvdata(file); + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(isp4vid_formats); i++) { + if (isp4vid_formats[i] =3D=3D fsize->pixel_format) + break; + } + if (i =3D=3D ARRAY_SIZE(isp4vid_formats)) + return -EINVAL; + + if (fsize->index < ARRAY_SIZE(isp4vid_frmsize)) { + fsize->type =3D V4L2_FRMSIZE_TYPE_DISCRETE; + fsize->discrete =3D isp4vid_frmsize[fsize->index]; + dev_dbg(isp_vdev->dev, "%s|size[%d]=3D%dx%d", + isp_vdev->vdev.name, fsize->index, + fsize->discrete.width, fsize->discrete.height); + } else { + return -EINVAL; + } + + return 0; +} + +static int isp4vid_ioctl_enum_frameintervals(struct file *file, void *priv, + struct v4l2_frmivalenum *fival) +{ + struct isp4vid_dev *isp_vdev =3D video_drvdata(file); + int i; + + if (fival->index >=3D ARRAY_SIZE(isp4vid_tpfs)) + return -EINVAL; + + for (i =3D 0; i < ARRAY_SIZE(isp4vid_formats); i++) + if (isp4vid_formats[i] =3D=3D fival->pixel_format) + break; + if (i =3D=3D ARRAY_SIZE(isp4vid_formats)) + return -EINVAL; + + for (i =3D 0; i < ARRAY_SIZE(isp4vid_frmsize); i++) + if (isp4vid_frmsize[i].width =3D=3D fival->width && + isp4vid_frmsize[i].height =3D=3D fival->height) + break; + if (i =3D=3D ARRAY_SIZE(isp4vid_frmsize)) + return -EINVAL; + + fival->type =3D V4L2_FRMIVAL_TYPE_DISCRETE; + fival->discrete =3D isp4vid_tpfs[fival->index]; + v4l2_simplify_fraction(&fival->discrete.numerator, + &fival->discrete.denominator, 8, 333); + + dev_dbg(isp_vdev->dev, "%s|interval[%d]=3D%d/%d", + isp_vdev->vdev.name, fival->index, + fival->discrete.numerator, + fival->discrete.denominator); + + return 0; +} + +static int isp4vid_ioctl_g_param(struct file *file, void *priv, struct v4l= 2_streamparm *param) +{ + struct v4l2_captureparm *capture =3D ¶m->parm.capture; + struct isp4vid_dev *isp_vdev =3D video_drvdata(file); + + if (param->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + capture->capability =3D V4L2_CAP_TIMEPERFRAME; + capture->timeperframe =3D isp_vdev->timeperframe; + capture->readbuffers =3D 0; + + dev_dbg(isp_vdev->dev, "%s|timeperframe=3D%d/%d", isp_vdev->vdev.name, + capture->timeperframe.numerator, + capture->timeperframe.denominator); + + return 0; +} + +static const struct v4l2_ioctl_ops isp4vid_vdev_ioctl_ops =3D { + /* VIDIOC_QUERYCAP handler */ + .vidioc_querycap =3D isp4vid_ioctl_querycap, + + /* VIDIOC_ENUM_FMT handlers */ + .vidioc_enum_fmt_vid_cap =3D isp4vid_enum_fmt_vid_cap, + + /* VIDIOC_G_FMT handlers */ + .vidioc_g_fmt_vid_cap =3D isp4vid_g_fmt_vid_cap, + + /* VIDIOC_S_FMT handlers */ + .vidioc_s_fmt_vid_cap =3D isp4vid_s_fmt_vid_cap, + + /* VIDIOC_TRY_FMT handlers */ + .vidioc_try_fmt_vid_cap =3D isp4vid_try_fmt_vid_cap, + + /* Buffer handlers */ + .vidioc_reqbufs =3D vb2_ioctl_reqbufs, + .vidioc_querybuf =3D vb2_ioctl_querybuf, + .vidioc_qbuf =3D vb2_ioctl_qbuf, + .vidioc_expbuf =3D vb2_ioctl_expbuf, + .vidioc_dqbuf =3D vb2_ioctl_dqbuf, + .vidioc_create_bufs =3D vb2_ioctl_create_bufs, + .vidioc_prepare_buf =3D vb2_ioctl_prepare_buf, + + /* Stream on/off */ + .vidioc_streamon =3D vb2_ioctl_streamon, + .vidioc_streamoff =3D vb2_ioctl_streamoff, + + /* Stream type-dependent parameter ioctls */ + .vidioc_g_parm =3D isp4vid_ioctl_g_param, + .vidioc_s_parm =3D isp4vid_ioctl_g_param, + + .vidioc_enum_framesizes =3D isp4vid_enum_framesizes, + .vidioc_enum_frameintervals =3D isp4vid_ioctl_enum_frameintervals, + +}; + +static unsigned int isp4vid_get_image_size(struct v4l2_pix_format *fmt) +{ + switch (fmt->pixelformat) { + case V4L2_PIX_FMT_NV12: + return fmt->width * fmt->height * 3 / 2; + case V4L2_PIX_FMT_YUYV: + return fmt->width * fmt->height * 2; + default: + return 0; + } +}; + +static int isp4vid_qops_queue_setup(struct vb2_queue *vq, unsigned int *nb= uffers, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) +{ + struct isp4vid_dev *isp_vdev =3D vb2_get_drv_priv(vq); + unsigned int q_num_bufs =3D vb2_get_num_buffers(vq); + + if (*nplanes > 1) { + dev_err(isp_vdev->dev, + "fail to setup queue, no mplane supported %u\n", + *nplanes); + return -EINVAL; + }; + + if (*nplanes =3D=3D 1) { + unsigned int size; + + size =3D isp4vid_get_image_size(&isp_vdev->format); + if (sizes[0] < size) { + dev_err(isp_vdev->dev, + "fail for small plane size %u, %u expected\n", + sizes[0], size); + return -EINVAL; + } + } + + if (q_num_bufs + *nbuffers < ISP4IF_MAX_STREAM_BUF_COUNT) + *nbuffers =3D ISP4IF_MAX_STREAM_BUF_COUNT - q_num_bufs; + + switch (isp_vdev->format.pixelformat) { + case V4L2_PIX_FMT_NV12: + case V4L2_PIX_FMT_YUYV: { + *nplanes =3D 1; + sizes[0] =3D max(sizes[0], isp_vdev->format.sizeimage); + isp_vdev->format.sizeimage =3D sizes[0]; + } + break; + default: + dev_err(isp_vdev->dev, "%s|unsupported fmt=3D%u\n", + isp_vdev->vdev.name, isp_vdev->format.pixelformat); + return -EINVAL; + } + + dev_dbg(isp_vdev->dev, "%s|*nbuffers=3D%u *nplanes=3D%u sizes[0]=3D%u\n", + isp_vdev->vdev.name, + *nbuffers, *nplanes, sizes[0]); + + return 0; +} + +static void isp4vid_qops_buffer_queue(struct vb2_buffer *vb) +{ + struct isp4vid_capture_buffer *buf =3D + container_of(vb, struct isp4vid_capture_buffer, vb2.vb2_buf); + struct isp4vid_dev *isp_vdev =3D vb2_get_drv_priv(vb->vb2_queue); + + struct isp4vid_vb2_buf *priv_buf =3D vb->planes[0].mem_priv; + struct isp4if_img_buf_info *img_buf =3D &buf->img_buf; + + dev_dbg(isp_vdev->dev, "%s|index=3D%u", isp_vdev->vdev.name, vb->index); + + dev_dbg(isp_vdev->dev, "queue isp user bo 0x%llx size=3D%lu", + priv_buf->gpu_addr, + priv_buf->size); + + switch (isp_vdev->format.pixelformat) { + case V4L2_PIX_FMT_NV12: { + u32 y_size =3D isp_vdev->format.sizeimage / 3 * 2; + u32 uv_size =3D isp_vdev->format.sizeimage / 3; + + img_buf->planes[0].len =3D y_size; + img_buf->planes[0].sys_addr =3D priv_buf->vaddr; + img_buf->planes[0].mc_addr =3D priv_buf->gpu_addr; + + dev_dbg(isp_vdev->dev, "img_buf[0]: mc=3D0x%llx size=3D%u", + img_buf->planes[0].mc_addr, + img_buf->planes[0].len); + + img_buf->planes[1].len =3D uv_size; + img_buf->planes[1].sys_addr =3D ((u8 *)priv_buf->vaddr + y_size); + img_buf->planes[1].mc_addr =3D priv_buf->gpu_addr + y_size; + + dev_dbg(isp_vdev->dev, "img_buf[1]: mc=3D0x%llx size=3D%u", + img_buf->planes[1].mc_addr, + img_buf->planes[1].len); + + img_buf->planes[2].len =3D 0; + } + break; + case V4L2_PIX_FMT_YUYV: { + img_buf->planes[0].len =3D isp_vdev->format.sizeimage; + img_buf->planes[0].sys_addr =3D priv_buf->vaddr; + img_buf->planes[0].mc_addr =3D priv_buf->gpu_addr; + + dev_dbg(isp_vdev->dev, "img_buf[0]: mc=3D0x%llx size=3D%u", + img_buf->planes[0].mc_addr, + img_buf->planes[0].len); + + img_buf->planes[1].len =3D 0; + img_buf->planes[2].len =3D 0; + } + break; + default: + dev_err(isp_vdev->dev, "%s|unsupported fmt=3D%u", + isp_vdev->vdev.name, isp_vdev->format.pixelformat); + return; + } + + if (isp_vdev->stream_started) + isp_vdev->ops->send_buffer(isp_vdev->isp_sdev, img_buf); + + mutex_lock(&isp_vdev->buf_list_lock); + list_add_tail(&buf->list, &isp_vdev->buf_list); + mutex_unlock(&isp_vdev->buf_list_lock); +} + +static int isp4vid_qops_start_streaming(struct vb2_queue *vq, unsigned int= count) +{ + struct isp4vid_dev *isp_vdev =3D vb2_get_drv_priv(vq); + struct isp4vid_capture_buffer *isp_buf; + struct media_entity *entity; + struct v4l2_subdev *subdev; + struct media_pad *pad; + int ret =3D 0; + + isp_vdev->sequence =3D 0; + ret =3D v4l2_pipeline_pm_get(&isp_vdev->vdev.entity); + if (ret) { + dev_err(isp_vdev->dev, "power up isp fail %d\n", ret); + goto release_buffers; + } + + entity =3D &isp_vdev->vdev.entity; + while (1) { + pad =3D &entity->pads[0]; + if (!(pad->flags & MEDIA_PAD_FL_SINK)) + break; + + pad =3D media_pad_remote_pad_first(pad); + if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) + break; + + entity =3D pad->entity; + subdev =3D media_entity_to_v4l2_subdev(entity); + + ret =3D v4l2_subdev_call(subdev, video, s_stream, 1); + if (ret < 0 && ret !=3D -ENOIOCTLCMD) { + dev_dbg(isp_vdev->dev, "fail start streaming: %s %d\n", + subdev->name, ret); + goto release_buffers; + } + } + + list_for_each_entry(isp_buf, &isp_vdev->buf_list, list) { + isp_vdev->ops->send_buffer(isp_vdev->isp_sdev, + &isp_buf->img_buf); + } + + /* Start the media pipeline */ + ret =3D video_device_pipeline_start(&isp_vdev->vdev, &isp_vdev->pipe); + if (ret) { + dev_err(isp_vdev->dev, "video_device_pipeline_start fail:%d", + ret); + goto release_buffers; + } + isp_vdev->stream_started =3D true; + + return 0; + +release_buffers: + isp4vid_capture_return_all_buffers(isp_vdev, VB2_BUF_STATE_QUEUED); + return ret; +} + +static void isp4vid_qops_stop_streaming(struct vb2_queue *vq) +{ + struct isp4vid_dev *isp_vdev =3D vb2_get_drv_priv(vq); + struct v4l2_subdev *subdev; + struct media_entity *entity; + struct media_pad *pad; + int ret; + + entity =3D &isp_vdev->vdev.entity; + while (1) { + pad =3D &entity->pads[0]; + if (!(pad->flags & MEDIA_PAD_FL_SINK)) + break; + + pad =3D media_pad_remote_pad_first(pad); + if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) + break; + + entity =3D pad->entity; + subdev =3D media_entity_to_v4l2_subdev(entity); + + ret =3D v4l2_subdev_call(subdev, video, s_stream, 0); + + if (ret < 0 && ret !=3D -ENOIOCTLCMD) + dev_dbg(isp_vdev->dev, "fail stop streaming: %s %d\n", + subdev->name, ret); + } + + isp_vdev->stream_started =3D false; + v4l2_pipeline_pm_put(&isp_vdev->vdev.entity); + + /* Stop the media pipeline */ + video_device_pipeline_stop(&isp_vdev->vdev); + + /* Release all active buffers */ + isp4vid_capture_return_all_buffers(isp_vdev, VB2_BUF_STATE_ERROR); +} + +static int isp4vid_fill_buffer_size(struct isp4vid_dev *isp_vdev) +{ + int ret =3D 0; + + switch (isp_vdev->format.pixelformat) { + case V4L2_PIX_FMT_NV12: + isp_vdev->format.bytesperline =3D isp_vdev->format.width; + isp_vdev->format.sizeimage =3D isp_vdev->format.bytesperline * + isp_vdev->format.height * 3 / 2; + break; + case V4L2_PIX_FMT_YUYV: + isp_vdev->format.bytesperline =3D isp_vdev->format.width; + isp_vdev->format.sizeimage =3D isp_vdev->format.bytesperline * + isp_vdev->format.height * 2; + break; + default: + dev_err(isp_vdev->dev, "fail for invalid default format 0x%x", + isp_vdev->format.pixelformat); + ret =3D -EINVAL; + break; + } + + return ret; +} + +static const struct vb2_ops isp4vid_qops =3D { + .queue_setup =3D isp4vid_qops_queue_setup, + .buf_queue =3D isp4vid_qops_buffer_queue, + .start_streaming =3D isp4vid_qops_start_streaming, + .stop_streaming =3D isp4vid_qops_stop_streaming, + .wait_prepare =3D vb2_ops_wait_prepare, + .wait_finish =3D vb2_ops_wait_finish, +}; + +int isp4vid_dev_init(struct isp4vid_dev *isp_vdev, struct v4l2_subdev *isp= _sdev, + const struct isp4vid_ops *ops) +{ + const char *vdev_name =3D isp4vid_video_dev_name; + struct v4l2_device *v4l2_dev; + struct video_device *vdev; + struct vb2_queue *q; + int ret; + + if (!isp_vdev || !isp_sdev || !isp_sdev->v4l2_dev) + return -EINVAL; + + v4l2_dev =3D isp_sdev->v4l2_dev; + vdev =3D &isp_vdev->vdev; + + isp_vdev->isp_sdev =3D isp_sdev; + isp_vdev->dev =3D v4l2_dev->dev; + isp_vdev->ops =3D ops; + + /* Initialize the vb2_queue struct */ + mutex_init(&isp_vdev->vbq_lock); + q =3D &isp_vdev->vbq; + q->type =3D V4L2_BUF_TYPE_VIDEO_CAPTURE; + q->io_modes =3D VB2_MMAP | VB2_DMABUF; + q->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->buf_struct_size =3D sizeof(struct isp4vid_capture_buffer); + q->min_queued_buffers =3D 2; + q->ops =3D &isp4vid_qops; + q->drv_priv =3D isp_vdev; + q->mem_ops =3D &isp4vid_vb2_memops; + q->lock =3D &isp_vdev->vbq_lock; + q->dev =3D v4l2_dev->dev; + ret =3D vb2_queue_init(q); + if (ret) { + dev_err(v4l2_dev->dev, "vb2_queue_init error:%d", ret); + return ret; + } + /* Initialize buffer list and its lock */ + mutex_init(&isp_vdev->buf_list_lock); + INIT_LIST_HEAD(&isp_vdev->buf_list); + + /* Set default frame format */ + isp_vdev->format =3D isp4vid_fmt_default; + isp_vdev->timeperframe =3D ISP4VID_ISP_TPF_DEFAULT; + v4l2_simplify_fraction(&isp_vdev->timeperframe.numerator, + &isp_vdev->timeperframe.denominator, 8, 333); + + ret =3D isp4vid_fill_buffer_size(isp_vdev); + if (ret) { + dev_err(v4l2_dev->dev, "fail to fill buffer size: %d\n", ret); + return ret; + } + + ret =3D isp4vid_set_fmt_2_isp(isp_sdev, &isp_vdev->format); + if (ret) { + dev_err(v4l2_dev->dev, "fail init format :%d\n", ret); + return ret; + } + + /* Initialize the video_device struct */ + isp_vdev->vdev.entity.name =3D vdev_name; + isp_vdev->vdev.entity.function =3D MEDIA_ENT_F_IO_V4L; + isp_vdev->vdev_pad.flags =3D MEDIA_PAD_FL_SINK; + ret =3D media_entity_pads_init(&isp_vdev->vdev.entity, 1, + &isp_vdev->vdev_pad); + + if (ret) { + dev_err(v4l2_dev->dev, "init media entity pad fail:%d\n", ret); + return ret; + } + + vdev->device_caps =3D V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_STREAMING | V4L2_CAP_IO_MC; + vdev->entity.ops =3D &isp4vid_vdev_ent_ops; + vdev->release =3D video_device_release_empty; + vdev->fops =3D &isp4vid_vdev_fops; + vdev->ioctl_ops =3D &isp4vid_vdev_ioctl_ops; + vdev->lock =3D NULL; + vdev->queue =3D q; + vdev->v4l2_dev =3D v4l2_dev; + vdev->vfl_dir =3D VFL_DIR_RX; + strscpy(vdev->name, vdev_name, sizeof(vdev->name)); + video_set_drvdata(vdev, isp_vdev); + + ret =3D video_register_device(vdev, VFL_TYPE_VIDEO, -1); + if (ret) + dev_err(v4l2_dev->dev, "register video device fail:%d\n", ret); + + return ret; +} + +void isp4vid_dev_deinit(struct isp4vid_dev *isp_vdev) +{ + video_unregister_device(&isp_vdev->vdev); +} diff --git a/drivers/media/platform/amd/isp4/isp4_video.h b/drivers/media/p= latform/amd/isp4/isp4_video.h new file mode 100644 index 000000000000..fae7dbdedd18 --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_video.h @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _ISP4_VIDEO_H_ +#define _ISP4_VIDEO_H_ + +#include +#include +#include +#include "isp4_interface.h" + +enum isp4vid_buf_done_status { + /* It means no corresponding image buf in fw response */ + ISP4VID_BUF_DONE_STATUS_ABSENT, + ISP4VID_BUF_DONE_STATUS_SUCCESS, + ISP4VID_BUF_DONE_STATUS_FAILED +}; + +struct isp4vid_buf_done_info { + enum isp4vid_buf_done_status status; + struct isp4if_img_buf_info buf; +}; + +/* call back parameter for CB_EVT_ID_FRAME_DONE */ +struct isp4vid_framedone_param { + s32 poc; + s32 cam_id; + s64 time_stamp; + struct isp4vid_buf_done_info preview; +}; + +struct isp4vid_capture_buffer { + /* + * struct vb2_v4l2_buffer must be the first element + * the videobuf2 framework will allocate this struct based on + * buf_struct_size and use the first sizeof(struct vb2_buffer) bytes of + * memory as a vb2_buffer + */ + struct vb2_v4l2_buffer vb2; + struct isp4if_img_buf_info img_buf; + struct list_head list; +}; + +struct isp4vid_dev; + +struct isp4vid_ops { + int (*send_buffer)(struct v4l2_subdev *sd, + struct isp4if_img_buf_info *img_buf); +}; + +struct isp4vid_dev { + struct video_device vdev; + struct media_pad vdev_pad; + struct v4l2_pix_format format; + + /* mutex that protects vbq */ + struct mutex vbq_lock; + struct vb2_queue vbq; + + /* mutex that protects buf_list */ + struct mutex buf_list_lock; + struct list_head buf_list; + + u32 sequence; + bool stream_started; + struct task_struct *kthread; + + struct media_pipeline pipe; + struct device *dev; + struct v4l2_subdev *isp_sdev; + struct v4l2_fract timeperframe; + + /* Callback operations */ + const struct isp4vid_ops *ops; +}; + +int isp4vid_dev_init(struct isp4vid_dev *isp_vdev, + struct v4l2_subdev *isp_sdev, + const struct isp4vid_ops *ops); + +void isp4vid_dev_deinit(struct isp4vid_dev *isp_vdev); + +s32 isp4vid_notify(void *cb_ctx, struct isp4vid_framedone_param *evt_param= ); + +#endif --=20 2.34.1 From nobody Thu Oct 2 20:44:48 2025 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2061.outbound.protection.outlook.com [40.107.237.61]) (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 2FE743101A2; Thu, 11 Sep 2025 10:09:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585397; cv=fail; b=GGHBOGZp7UfpA4QUHTj13Gnd5IesXhHBx2rOnTVXe0BraI75y23mNO/gkEcRCHOvi+bWdF6NH1ENoc/fZsbX6mObob2wVRz4jgnOv/fUx7xYrO/bRkHOcndr8O7bYhsytpaqWHapxQIitzbrfTOpzsTTmZj+w4Dz7qjJAW20O6c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585397; c=relaxed/simple; bh=wmh5L7RAg70a29vEtj/HgzEuqg+zNHckICTzEfrvGqY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cMcLaaLuxvrGaMEhRHnH+bqrq/LWEdSJZtAevwIbSl2UpgRRlJ+QeGCQ3U0X+rtJSbfKKN8VH5Fi4th+V0Nueyn81DT2HbxiamVAP0m55o4bi9Fu07jwrvpHQcgnDhaL1ya2b1hy/X+bwklcreERw5pLBlKReXuAltUVi6aFCD8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=FVcgi0+v; arc=fail smtp.client-ip=40.107.237.61 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="FVcgi0+v" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JsmwXAStwmENO8xnZH0gWS36eKtxA3fp1Co5CRa3NQ8u0ud31zy3feUxdajsDwFGLGWD40u7VB3wEt6BehZ4FPCYw1M2IknwMfB3JEXRyaiqyHd6+IQ/oA4Dxsv30UvVMQvGNZd99Zye9macXbswazdhOMvMbSBLNl2HEzJ6SrLXLBrZVk/SB1gnPdAO82ZBySYc52OG2hP7n24kNul9RZE+pNy9W4wGboaZfFgXTOuyp37rbywSeM0t6AKKPvqTqDJtJstMB/alioBKGrZwCDFhfFNkcNrInPCGtNn4VnIOGHeRrbmd6c6EIgyFuAYwsAuuSEjd8VwlDNIcKhP4uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Sjf+1hAj+9q1rv5RtuyJQgCUI13V5fx2ALUPxcoFmg4=; b=LzQXA8tBjkdLJGZU0dvQxv4wJF/LQYe5EaOKo0NcuvZLh6wbSdCOd1b7N0WPhUMoOAydLLlwrIJJnyd94hPw5n8VdB+f5BUy3t2mqZyK37kjFaDkKXUySduQXTChc7Ll01JeBXx0kkeaRVlKzRVyxXp88i9RUjEfpOVPylefb+59M1sJ6iL5zJpHuT5eBy0PJkeeqBKX8a0Q9hVVKEZ/ouAijskVqS1eXiPFJaqR9VOTI/95z9FiynG/GucuEepHNjZawO03fZAuYZ2oQGc3/8j1Cw/Oi5Nlafr7J70lLDu/CIIjraAM17Gkc0FG1nklWLISbIsZRv5PlY9VFTt+7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sjf+1hAj+9q1rv5RtuyJQgCUI13V5fx2ALUPxcoFmg4=; b=FVcgi0+v1VT1Pi2yTn+7iUlwaWumhbklJrfquEOTVIw3wEpH9q0cAFaqsW6qXKizechS6KdC6aRJrf5+tGhBF3QUu59VRMbXOjc0uNWExghIIIMitqRwqNzNCYFJ8h0f9grI7NwqrLAEHe6XEw3ltTbISOdyaYos094uHMgxPOM= Received: from MN2PR04CA0027.namprd04.prod.outlook.com (2603:10b6:208:d4::40) by DS7PR12MB5839.namprd12.prod.outlook.com (2603:10b6:8:7a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Thu, 11 Sep 2025 10:09:47 +0000 Received: from MN1PEPF0000ECD9.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::92) by MN2PR04CA0027.outlook.office365.com (2603:10b6:208:d4::40) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9094.18 via Frontend Transport; Thu, 11 Sep 2025 10:09:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MN1PEPF0000ECD9.mail.protection.outlook.com (10.167.242.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Thu, 11 Sep 2025 10:09:47 +0000 Received: from 555e2b870847.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 11 Sep 2025 03:09:38 -0700 From: Bin Du To: , , , , , , , , CC: , , , , , , , , , , Bin Du , Svetoslav Stoilov , "Alexey Zagorodnikov" Subject: [PATCH v4 6/7] media: platform: amd: isp4 debug fs logging and more descriptive errors Date: Thu, 11 Sep 2025 18:08:46 +0800 Message-ID: <20250911100847.277408-7-Bin.Du@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911100847.277408-1-Bin.Du@amd.com> References: <20250911100847.277408-1-Bin.Du@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD9:EE_|DS7PR12MB5839:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c1b2cda-a339-4730-32a9-08ddf11b564d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?T99bhCQKmaXoiXwujZX9q84pmEa+Atjk6kPExpsWRG+yj6hkEZsoJ6VgBowW?= =?us-ascii?Q?tOp2jYu91DbsQKhxeTwPooErksjO3Km/zYDzSvzwaBU8S/Uak4sxV1SWDkCi?= =?us-ascii?Q?1Iz9hmhCsMpiISx0yL0wRiBP2abT7et9Ykp2Te6UtIcRBDEHI0cVNcWq6JF2?= =?us-ascii?Q?Ncgcqh6olc1J1H4LUPrY3v0kd0hp+LSxh4DjGhTim2pJAyFHGKA7JSlkzSa6?= =?us-ascii?Q?ZVTJ8IkpwT+HE/z60+ME630ATjJ8lL0oZ+5i3mXQYO2/DDBNstrugAwdApCe?= =?us-ascii?Q?g0zbE9GhjltOHP2/XFUEDGoqeErk1P3Fv8K+4exp19gHSSz25sJs1uvmZeV/?= =?us-ascii?Q?ZmuXiWRxCy+zKlXu2dXK3Jr31f8xnmjgXH4XaCQenmnq6PkZzFJrlCcxpeRd?= =?us-ascii?Q?lA6318rX8a9/y6OEnToVyCNoOr7R6ZHhGKxL1ZnWBuWti1k+ry+jcgH0URTA?= =?us-ascii?Q?vlzJg5jNn9tFV/iTk6TaJWsohq+MKpZ8oLtWHqy4O/ixwEdJVx+BASc/8cZw?= =?us-ascii?Q?s96yIMx3S2fgaaJNx27dTqGUTuh2elovMdjn3HPIOzxi0Jijpvwjgih1BtLR?= =?us-ascii?Q?dneyvWn7tI05lA8Oupv9DbK+zf64kRsIwDJXoFJ2jvZsTPZUAWpBK6A4z0xj?= =?us-ascii?Q?biQ+erFAaA4cRh9I6lwVlHpA+6G/EMo8vAlSZZT8pbrW3jLBhKCbGCATfp2g?= =?us-ascii?Q?KUB2bBD/ZfUYCrhOsNV4jEUt1VjRHEjniwIN2i33nXMtFEcvCKYdOnqwZ5Cr?= =?us-ascii?Q?KH53/kHWsg2Kv72GKRWIEW2RFQRrX7OipRzTQkCAVedLNPnEqtTgR7S5wFdB?= =?us-ascii?Q?5cZF/+NvK9KTkNPsLxt6SbBHLAXUAayTsKfEP+MqkEHOFGxQH+zv+aDP7Ph0?= =?us-ascii?Q?KM5vskecrQXt5pGT7N6mG+ujtNJL0E1FPO5R33L/662r2v7/Zds9NzXlkM+F?= =?us-ascii?Q?kzgThwev381M0teEMhzNnLWAgyDIU78ejofFZCOtYe+IwZeaOqZkv3R8kKOC?= =?us-ascii?Q?sXyEctxhULErreKSRcYJ487Ysj7pAV7p66S3PEGTS8ZgF+NDXZ5+jUA6eI4u?= =?us-ascii?Q?wf/2fQcVOlTpoLfnTEuA32CKom9q0bIdf9ieED37STtcIVZkOG2RALMDAic1?= =?us-ascii?Q?/On/fVIShLZqBUTRAwcpPYHTwwehPn+IzeW0Mg+p4S/PAZg+fWfDdgCbgcdD?= =?us-ascii?Q?GVXMLql3TKBJEAeIg2F6gm2V8MC7XzloCAI1DUp9Jiw2CqHMcyMEF3GjLV2H?= =?us-ascii?Q?ztFdoOlw1NufmxeRlGaSlZFUtzFCC9TrosGtqCR/Zbox93El9n6OUoN8szNz?= =?us-ascii?Q?+3lMBr6kK1WhO0qq/mBdvx7GuaZykSmG3YqWUBJMFybtTryu76L+Q7rj/Z0H?= =?us-ascii?Q?jeqibghc1pZDsZrc7yuSbNyd0+7vpU6Ho7JCMZMywkiMDrtaWR65G+/lbrXA?= =?us-ascii?Q?8s84M0yQxDE5V7CLVjRchKk5G4Q1R6o92BPBc6YagtJeZ2u7yeWTmTn5QUne?= =?us-ascii?Q?lgpndjD7JuwEqim2x0GYZy//IbHkS9n5Pvi6?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2025 10:09:47.0352 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c1b2cda-a339-4730-32a9-08ddf11b564d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECD9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5839 Content-Type: text/plain; charset="utf-8" Add debug fs for isp4 driver and add more detailed descriptive error info to some of the log message Co-developed-by: Svetoslav Stoilov Signed-off-by: Svetoslav Stoilov Signed-off-by: Bin Du Tested-by: Alexey Zagorodnikov --- MAINTAINERS | 2 + drivers/media/platform/amd/isp4/Makefile | 1 + drivers/media/platform/amd/isp4/isp4.c | 4 + drivers/media/platform/amd/isp4/isp4_debug.c | 272 ++++++++++++++++++ drivers/media/platform/amd/isp4/isp4_debug.h | 41 +++ .../media/platform/amd/isp4/isp4_interface.c | 41 ++- drivers/media/platform/amd/isp4/isp4_subdev.c | 29 +- 7 files changed, 368 insertions(+), 22 deletions(-) create mode 100644 drivers/media/platform/amd/isp4/isp4_debug.c create mode 100644 drivers/media/platform/amd/isp4/isp4_debug.h diff --git a/MAINTAINERS b/MAINTAINERS index 80c966fde0b4..8478789ac265 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1145,6 +1145,8 @@ F: drivers/media/platform/amd/isp4/Kconfig F: drivers/media/platform/amd/isp4/Makefile F: drivers/media/platform/amd/isp4/isp4.c F: drivers/media/platform/amd/isp4/isp4.h +F: drivers/media/platform/amd/isp4/isp4_debug.c +F: drivers/media/platform/amd/isp4/isp4_debug.h F: drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h F: drivers/media/platform/amd/isp4/isp4_hw_reg.h F: drivers/media/platform/amd/isp4/isp4_interface.c diff --git a/drivers/media/platform/amd/isp4/Makefile b/drivers/media/platf= orm/amd/isp4/Makefile index 33589091ca96..c89355fb2374 100644 --- a/drivers/media/platform/amd/isp4/Makefile +++ b/drivers/media/platform/amd/isp4/Makefile @@ -4,6 +4,7 @@ =20 obj-$(CONFIG_AMD_ISP4) +=3D amd_capture.o amd_capture-objs :=3D isp4_subdev.o \ + isp4_debug.o \ isp4_interface.o \ isp4.o \ isp4_video.o \ No newline at end of file diff --git a/drivers/media/platform/amd/isp4/isp4.c b/drivers/media/platfor= m/amd/isp4/isp4.c index a46e110a396f..f129a9fbf315 100644 --- a/drivers/media/platform/amd/isp4/isp4.c +++ b/drivers/media/platform/amd/isp4/isp4.c @@ -10,6 +10,7 @@ #include =20 #include "isp4.h" +#include "isp4_debug.h" #include "isp4_hw_reg.h" =20 #define ISP4_DRV_NAME "amd_isp_capture" @@ -189,6 +190,7 @@ static int isp4_capture_probe(struct platform_device *p= dev) } =20 platform_set_drvdata(pdev, isp_dev); + isp_debugfs_create(isp_dev); =20 return 0; =20 @@ -204,6 +206,8 @@ static void isp4_capture_remove(struct platform_device = *pdev) { struct isp4_device *isp_dev =3D platform_get_drvdata(pdev); =20 + isp_debugfs_remove(isp_dev); + v4l2_device_unregister_subdev(&isp_dev->isp_sdev.sdev); =20 media_device_unregister(&isp_dev->mdev); diff --git a/drivers/media/platform/amd/isp4/isp4_debug.c b/drivers/media/p= latform/amd/isp4/isp4_debug.c new file mode 100644 index 000000000000..cc99b357df27 --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_debug.c @@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#include "isp4.h" +#include "isp4_debug.h" +#include "isp4_hw_reg.h" +#include "isp4_interface.h" + +#define ISP4DBG_FW_LOG_RINGBUF_SIZE (2 * 1024 * 1024) +#define ISP4DBG_MACRO_2_STR(X) #X +#define ISP4DBG_MAX_ONE_TIME_LOG_LEN 510 + +#ifdef CONFIG_DEBUG_FS + +void isp_debugfs_create(struct isp4_device *isp_dev) +{ + isp_dev->isp_sdev.debugfs_dir =3D debugfs_create_dir("amd_isp", NULL); + debugfs_create_bool("fw_log_enable", 0644, + isp_dev->isp_sdev.debugfs_dir, + &isp_dev->isp_sdev.enable_fw_log); + isp_dev->isp_sdev.fw_log_output =3D + devm_kzalloc(&isp_dev->pdev->dev, + ISP4DBG_FW_LOG_RINGBUF_SIZE + 32, + GFP_KERNEL); +} + +void isp_debugfs_remove(struct isp4_device *isp_dev) +{ + debugfs_remove_recursive(isp_dev->isp_sdev.debugfs_dir); + isp_dev->isp_sdev.debugfs_dir =3D NULL; +} + +static u32 isp_fw_fill_rb_log(struct isp4_subdev *isp, u8 *sys, u32 rb_siz= e) +{ + struct isp4_interface *ispif =3D &isp->ispif; + struct device *dev =3D isp->dev; + u8 *buf =3D isp->fw_log_output; + u32 rd_ptr, wr_ptr; + u32 total_cnt =3D 0; + u32 offset =3D 0; + u32 cnt; + + if (!sys || rb_size =3D=3D 0) + return 0; + + mutex_lock(&ispif->isp4if_mutex); + + rd_ptr =3D isp4hw_rreg(ISP4_GET_ISP_REG_BASE(isp), ISP_LOG_RB_RPTR0); + wr_ptr =3D isp4hw_rreg(ISP4_GET_ISP_REG_BASE(isp), ISP_LOG_RB_WPTR0); + + do { + if (wr_ptr > rd_ptr) + cnt =3D wr_ptr - rd_ptr; + else if (wr_ptr < rd_ptr) + cnt =3D rb_size - rd_ptr; + else + goto unlock_and_quit; + + if (cnt > rb_size) { + dev_err(dev, "fail bad fw log size %u\n", cnt); + goto unlock_and_quit; + } + + memcpy(buf + offset, (u8 *)(sys + rd_ptr), cnt); + + offset +=3D cnt; + total_cnt +=3D cnt; + rd_ptr =3D (rd_ptr + cnt) % rb_size; + } while (rd_ptr < wr_ptr); + + isp4hw_wreg(ISP4_GET_ISP_REG_BASE(isp), ISP_LOG_RB_RPTR0, rd_ptr); + +unlock_and_quit: + mutex_unlock(&ispif->isp4if_mutex); + return total_cnt; +} + +void isp_fw_log_print(struct isp4_subdev *isp) +{ + struct isp4_interface *ispif =3D &isp->ispif; + char *fw_log_buf =3D isp->fw_log_output; + u32 cnt; + + if (!isp->enable_fw_log || !fw_log_buf) + return; + + cnt =3D isp_fw_fill_rb_log(isp, ispif->fw_log_buf->sys_addr, + ispif->fw_log_buf->mem_size); + + if (cnt) { + char *line_end; + char temp_ch; + char *str; + char *end; + + str =3D (char *)fw_log_buf; + end =3D ((char *)fw_log_buf + cnt); + fw_log_buf[cnt] =3D 0; + + while (str < end) { + line_end =3D strchr(str, 0x0A); + if ((line_end && (str + ISP4DBG_MAX_ONE_TIME_LOG_LEN) >=3D line_end) || + (!line_end && (str + ISP4DBG_MAX_ONE_TIME_LOG_LEN) >=3D end)) { + if (line_end) + *line_end =3D 0; + + if (*str !=3D '\0') + dev_dbg(isp->dev, + "%s", str); + + if (line_end) { + *line_end =3D 0x0A; + str =3D line_end + 1; + } else { + break; + } + } else { + u32 tmp_len =3D ISP4DBG_MAX_ONE_TIME_LOG_LEN; + + temp_ch =3D str[tmp_len]; + str[tmp_len] =3D 0; + dev_dbg(isp->dev, "%s", str); + str[tmp_len] =3D temp_ch; + str =3D &str[tmp_len]; + } + } + } +} +#endif + +char *isp4dbg_get_buf_src_str(u32 src) +{ + switch (src) { + case BUFFER_SOURCE_STREAM: + return ISP4DBG_MACRO_2_STR(BUFFER_SOURCE_STREAM); + default: + return "Unknown buf source"; + } +} + +char *isp4dbg_get_buf_done_str(u32 status) +{ + switch (status) { + case BUFFER_STATUS_INVALID: + return ISP4DBG_MACRO_2_STR(BUFFER_STATUS_INVALID); + case BUFFER_STATUS_SKIPPED: + return ISP4DBG_MACRO_2_STR(BUFFER_STATUS_SKIPPED); + case BUFFER_STATUS_EXIST: + return ISP4DBG_MACRO_2_STR(BUFFER_STATUS_EXIST); + case BUFFER_STATUS_DONE: + return ISP4DBG_MACRO_2_STR(BUFFER_STATUS_DONE); + case BUFFER_STATUS_LACK: + return ISP4DBG_MACRO_2_STR(BUFFER_STATUS_LACK); + case BUFFER_STATUS_DIRTY: + return ISP4DBG_MACRO_2_STR(BUFFER_STATUS_DIRTY); + case BUFFER_STATUS_MAX: + return ISP4DBG_MACRO_2_STR(BUFFER_STATUS_MAX); + default: + return "Unknown Buf Done Status"; + } +}; + +char *isp4dbg_get_img_fmt_str(int fmt /* enum isp4fw_image_format * */) +{ + switch (fmt) { + case IMAGE_FORMAT_NV12: + return "NV12"; + case IMAGE_FORMAT_YUV422INTERLEAVED: + return "YUV422INTERLEAVED"; + default: + return "unknown fmt"; + } +} + +void isp4dbg_show_bufmeta_info(struct device *dev, char *pre, + void *in, void *orig_buf) +{ + struct isp4fw_buffer_meta_info *p; + struct isp4if_img_buf_info *orig; + + if (!in) + return; + + if (!pre) + pre =3D ""; + + p =3D in; + orig =3D orig_buf; + + dev_dbg(dev, "%s(%s) en:%d,stat:%s(%u),src:%s\n", pre, + isp4dbg_get_img_fmt_str(p->image_prop.image_format), + p->enabled, isp4dbg_get_buf_done_str(p->status), p->status, + isp4dbg_get_buf_src_str(p->source)); + + dev_dbg(dev, "%p,0x%llx(%u) %p,0x%llx(%u) %p,0x%llx(%u)\n", + orig->planes[0].sys_addr, orig->planes[0].mc_addr, + orig->planes[0].len, orig->planes[1].sys_addr, + orig->planes[1].mc_addr, orig->planes[1].len, + orig->planes[2].sys_addr, orig->planes[2].mc_addr, + orig->planes[2].len); +} + +char *isp4dbg_get_buf_type(u32 type) +{ + /* enum isp4fw_buffer_type */ + switch (type) { + case BUFFER_TYPE_PREVIEW: + return ISP4DBG_MACRO_2_STR(BUFFER_TYPE_PREVIEW); + case BUFFER_TYPE_META_INFO: + return ISP4DBG_MACRO_2_STR(BUFFER_TYPE_META_INFO); + case BUFFER_TYPE_MEM_POOL: + return ISP4DBG_MACRO_2_STR(BUFFER_TYPE_MEM_POOL); + default: + return "unknown type"; + } +} + +char *isp4dbg_get_cmd_str(u32 cmd) +{ + switch (cmd) { + case CMD_ID_START_STREAM: + return ISP4DBG_MACRO_2_STR(CMD_ID_START_STREAM); + case CMD_ID_STOP_STREAM: + return ISP4DBG_MACRO_2_STR(CMD_ID_STOP_STREAM); + case CMD_ID_SEND_BUFFER: + return ISP4DBG_MACRO_2_STR(CMD_ID_SEND_BUFFER); + case CMD_ID_SET_STREAM_CONFIG: + return ISP4DBG_MACRO_2_STR(CMD_ID_SET_STREAM_CONFIG); + case CMD_ID_SET_OUT_CHAN_PROP: + return ISP4DBG_MACRO_2_STR(CMD_ID_SET_OUT_CHAN_PROP); + case CMD_ID_ENABLE_OUT_CHAN: + return ISP4DBG_MACRO_2_STR(CMD_ID_ENABLE_OUT_CHAN); + default: + return "unknown cmd"; + }; +} + +char *isp4dbg_get_resp_str(u32 cmd) +{ + switch (cmd) { + case RESP_ID_CMD_DONE: + return ISP4DBG_MACRO_2_STR(RESP_ID_CMD_DONE); + case RESP_ID_NOTI_FRAME_DONE: + return ISP4DBG_MACRO_2_STR(RESP_ID_NOTI_FRAME_DONE); + default: + return "unknown respid"; + }; +} + +char *isp4dbg_get_if_stream_str(u32 stream /* enum fw_cmd_resp_stream_id *= /) +{ + switch (stream) { + case ISP4IF_STREAM_ID_GLOBAL: + return "STREAM_GLOBAL"; + case ISP4IF_STREAM_ID_1: + return "STREAM1"; + default: + return "unknown streamID"; + } +} + +char *isp4dbg_get_out_ch_str(int ch /* enum isp4fw_pipe_out_ch */) +{ + switch ((enum isp4fw_pipe_out_ch)ch) { + case ISP_PIPE_OUT_CH_PREVIEW: + return "prev"; + default: + return "unknown channel"; + } +} diff --git a/drivers/media/platform/amd/isp4/isp4_debug.h b/drivers/media/p= latform/amd/isp4/isp4_debug.h new file mode 100644 index 000000000000..0c75ddae4882 --- /dev/null +++ b/drivers/media/platform/amd/isp4/isp4_debug.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2025 Advanced Micro Devices, Inc. + */ + +#ifndef _ISP4_DEBUG_H_ +#define _ISP4_DEBUG_H_ + +#include +#include + +#include "isp4_subdev.h" + +#ifdef CONFIG_DEBUG_FS +struct isp4_device; + +void isp_debugfs_create(struct isp4_device *isp_dev); +void isp_debugfs_remove(struct isp4_device *isp_dev); +void isp_fw_log_print(struct isp4_subdev *isp); + +#else + +/* to avoid checkpatch warning */ +#define isp_debugfs_create(cam) ((void)(cam)) +#define isp_debugfs_remove(cam) ((void)(cam)) +#define isp_fw_log_print(isp) ((void)(isp)) + +#endif /* CONFIG_DEBUG_FS */ + +void isp4dbg_show_bufmeta_info(struct device *dev, char *pre, void *p, + void *orig_buf /* struct sys_img_buf_handle */); +char *isp4dbg_get_img_fmt_str(int fmt /* enum _image_format_t */); +char *isp4dbg_get_out_ch_str(int ch /* enum _isp_pipe_out_ch_t */); +char *isp4dbg_get_cmd_str(u32 cmd); +char *isp4dbg_get_buf_type(u32 type);/* enum _buffer_type_t */ +char *isp4dbg_get_resp_str(u32 resp); +char *isp4dbg_get_buf_src_str(u32 src); +char *isp4dbg_get_buf_done_str(u32 status); +char *isp4dbg_get_if_stream_str(u32 stream); + +#endif diff --git a/drivers/media/platform/amd/isp4/isp4_interface.c b/drivers/med= ia/platform/amd/isp4/isp4_interface.c index 52dcca57ce2e..914bd02a26e6 100644 --- a/drivers/media/platform/amd/isp4/isp4_interface.c +++ b/drivers/media/platform/amd/isp4/isp4_interface.c @@ -6,8 +6,8 @@ #include #include #include -#include =20 +#include "isp4_debug.h" #include "isp4_fw_cmd_resp.h" #include "isp4_hw_reg.h" #include "isp4_interface.h" @@ -355,7 +355,8 @@ static int isp4if_insert_isp_fw_cmd(struct isp4_interfa= ce *ispif, enum isp4if_st len =3D rb_config->val_size; =20 if (isp4if_is_cmdq_rb_full(ispif, stream)) { - dev_err(dev, "fail no cmdslot (%d)\n", stream); + dev_err(dev, "fail no cmdslot %s(%d)\n", + isp4dbg_get_if_stream_str(stream), stream); return -EINVAL; } =20 @@ -363,13 +364,15 @@ static int isp4if_insert_isp_fw_cmd(struct isp4_inter= face *ispif, enum isp4if_st rd_ptr =3D isp4hw_rreg(ispif->mmio, rreg); =20 if (rd_ptr > len) { - dev_err(dev, "fail (%u),rd_ptr %u(should<=3D%u),wr_ptr %u\n", + dev_err(dev, "fail %s(%u),rd_ptr %u(should<=3D%u),wr_ptr %u\n", + isp4dbg_get_if_stream_str(stream), stream, rd_ptr, len, wr_ptr); return -EINVAL; } =20 if (wr_ptr > len) { - dev_err(dev, "fail (%u),wr_ptr %u(should<=3D%u), rd_ptr %u\n", + dev_err(dev, "fail %s(%u),wr_ptr %u(should<=3D%u), rd_ptr %u\n", + isp4dbg_get_if_stream_str(stream), stream, wr_ptr, len, rd_ptr); return -EINVAL; } @@ -447,7 +450,8 @@ static int isp4if_send_fw_cmd(struct isp4_interface *is= pif, u32 cmd_id, void *pa u32 wr_ptr =3D isp4hw_rreg(ispif->mmio, wreg); =20 dev_err(dev, - "failed to get free cmdq slot, stream (%d),rd %u, wr %u\n", + "failed to get free cmdq slot, stream %s(%d),rd %u, wr %u\n", + isp4dbg_get_if_stream_str(stream), stream, rd_ptr, wr_ptr); return -ETIMEDOUT; } @@ -497,9 +501,11 @@ static int isp4if_send_fw_cmd(struct isp4_interface *i= spif, u32 cmd_id, void *pa =20 ret =3D isp4if_insert_isp_fw_cmd(ispif, stream, &cmd); if (ret) { - dev_err(dev, "fail for insert_isp_fw_cmd camId (0x%08x)\n", cmd_id); + dev_err(dev, "fail for insert_isp_fw_cmd camId %s(0x%08x)\n", + isp4dbg_get_cmd_str(cmd_id), cmd_id); if (cmd_ele) { - isp4if_rm_cmd_from_cmdq(ispif, cmd_ele->seq_num, cmd_ele->cmd_id); + isp4if_rm_cmd_from_cmdq(ispif, cmd_ele->seq_num, + cmd_ele->cmd_id); kfree(cmd_ele); } } @@ -710,13 +716,15 @@ int isp4if_f2h_resp(struct isp4_interface *ispif, enu= m isp4if_stream_id stream, wr_ptr_dbg =3D wr_ptr; =20 if (rd_ptr > len) { - dev_err(dev, "fail (%u),rd_ptr %u(should<=3D%u),wr_ptr %u\n", + dev_err(dev, "fail %s(%u),rd_ptr %u(should<=3D%u),wr_ptr %u\n", + isp4dbg_get_if_stream_str(stream), stream, rd_ptr, len, wr_ptr); return -EINVAL; } =20 if (wr_ptr > len) { - dev_err(dev, "fail (%u),wr_ptr %u(should<=3D%u), rd_ptr %u\n", + dev_err(dev, "fail %s(%u),wr_ptr %u(should<=3D%u), rd_ptr %u\n", + isp4dbg_get_if_stream_str(stream), stream, wr_ptr, len, rd_ptr); return -EINVAL; } @@ -731,7 +739,8 @@ int isp4if_f2h_resp(struct isp4_interface *ispif, enum = isp4if_stream_id stream, isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), rreg, rd_ptr); } else { - dev_err(dev, "(%u),rd %u(should<=3D%u),wr %u\n", + dev_err(dev, "%s(%u),rd %u(should<=3D%u),wr %u\n", + isp4dbg_get_if_stream_str(stream), stream, rd_ptr, len, wr_ptr); return -EINVAL; } @@ -757,7 +766,8 @@ int isp4if_f2h_resp(struct isp4_interface *ispif, enum = isp4if_stream_id stream, isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), rreg, rd_ptr); } else { - dev_err(dev, "(%u),rd %u(should<=3D%u),wr %u\n", + dev_err(dev, "%s(%u),rd %u(should<=3D%u),wr %u\n", + isp4dbg_get_if_stream_str(stream), stream, rd_ptr, len, wr_ptr); return -EINVAL; } @@ -779,7 +789,8 @@ int isp4if_f2h_resp(struct isp4_interface *ispif, enum = isp4if_stream_id stream, isp4hw_wreg(GET_ISP4IF_REG_BASE(ispif), rreg, rd_ptr); } else { - dev_err(dev, "(%u),rd %u(should<=3D%u),wr %u\n", + dev_err(dev, "%s(%u),rd %u(should<=3D%u),wr %u\n", + isp4dbg_get_if_stream_str(stream), stream, rd_ptr, len, wr_ptr); return -EINVAL; } @@ -794,9 +805,9 @@ int isp4if_f2h_resp(struct isp4_interface *ispif, enum = isp4if_stream_id stream, dev_err(dev, "resp checksum 0x%x,should 0x%x,rptr %u,wptr %u\n", checksum, response->resp_check_sum, rd_ptr_dbg, wr_ptr_dbg); =20 - dev_err(dev, "(%u), seqNo %u, resp_id (0x%x)\n", stream, - response->resp_seq_num, - response->resp_id); + dev_err(dev, "%s(%u), seqNo %u, resp_id %s(0x%x)\n", + isp4dbg_get_if_stream_str(stream), stream, response->resp_seq_num, + isp4dbg_get_resp_str(response->resp_id), response->resp_id); =20 return -EINVAL; } diff --git a/drivers/media/platform/amd/isp4/isp4_subdev.c b/drivers/media/= platform/amd/isp4/isp4_subdev.c index 7d3339c915eb..bc63311c2490 100644 --- a/drivers/media/platform/amd/isp4/isp4_subdev.c +++ b/drivers/media/platform/amd/isp4/isp4_subdev.c @@ -7,6 +7,7 @@ #include #include =20 +#include "isp4_debug.h" #include "isp4_fw_cmd_resp.h" #include "isp4_interface.h" #include "isp4_subdev.h" @@ -252,7 +253,9 @@ static int isp4sd_setup_output(struct isp4_subdev *isp_= subdev, return -EINVAL; } =20 - dev_dbg(dev, "channel: w:h=3D%u:%u,lp:%u,cp%u\n", + dev_dbg(dev, "channel:%s,fmt %s,w:h=3D%u:%u,lp:%u,cp%u\n", + isp4dbg_get_out_ch_str(cmd_ch_prop.ch), + isp4dbg_get_img_fmt_str(cmd_ch_prop.image_prop.image_format), cmd_ch_prop.image_prop.width, cmd_ch_prop.image_prop.height, cmd_ch_prop.image_prop.luma_pitch, cmd_ch_prop.image_prop.chroma_pitch); @@ -275,6 +278,9 @@ static int isp4sd_setup_output(struct isp4_subdev *isp_= subdev, return ret; } =20 + dev_dbg(dev, "enable channel %s\n", + isp4dbg_get_out_ch_str(cmd_ch_en.ch)); + if (!sensor_info->start_stream_cmd_sent) { ret =3D isp4sd_kickoff_stream(isp_subdev, out_prop->width, out_prop->height); @@ -428,8 +434,9 @@ static void isp4sd_fw_resp_cmd_done(struct isp4_subdev = *isp_subdev, isp4if_rm_cmd_from_cmdq(ispif, para->cmd_seq_num, para->cmd_id); struct device *dev =3D isp_subdev->dev; =20 - dev_dbg(dev, "stream %d,cmd (0x%08x)(%d),seq %u, ele %p\n", + dev_dbg(dev, "stream %d,cmd %s(0x%08x)(%d),seq %u, ele %p\n", stream_id, + isp4dbg_get_cmd_str(para->cmd_id), para->cmd_id, para->cmd_status, para->cmd_seq_num, ele); =20 @@ -486,8 +493,9 @@ isp4sd_preview_done(struct isp4_subdev *isp_subdev, pcb->preview.status =3D ISP4VID_BUF_DONE_STATUS_SUCCESS; } } else if (meta->preview.enabled) { - dev_err(dev, "fail bad preview status %u\n", - meta->preview.status); + dev_err(dev, "fail bad preview status %u(%s)\n", + meta->preview.status, + isp4dbg_get_buf_done_str(meta->preview.status)); } =20 return prev; @@ -546,14 +554,18 @@ static void isp4sd_fw_resp_frame_done(struct isp4_sub= dev *isp_subdev, pcb.poc =3D meta->poc; pcb.cam_id =3D 0; =20 - dev_dbg(dev, "ts:%llu,streamId:%d,poc:%u,preview_en:%u,(%i)\n", + dev_dbg(dev, "ts:%llu,streamId:%d,poc:%u,preview_en:%u,%s(%i)\n", ktime_get_ns(), stream_id, meta->poc, meta->preview.enabled, + isp4dbg_get_buf_done_str(meta->preview.status), meta->preview.status); =20 prev =3D isp4sd_preview_done(isp_subdev, meta, &pcb); - if (pcb.preview.status !=3D ISP4VID_BUF_DONE_STATUS_ABSENT) + if (pcb.preview.status !=3D ISP4VID_BUF_DONE_STATUS_ABSENT) { + isp4dbg_show_bufmeta_info(dev, "prev", &meta->preview, + &pcb.preview.buf); isp4vid_notify(&isp_subdev->isp_vdev, &pcb); + } =20 isp4if_dealloc_buffer_node(prev); =20 @@ -574,6 +586,8 @@ static void isp4sd_fw_resp_func(struct isp4_subdev *isp= _subdev, if (ispif->status < ISP4IF_STATUS_FW_RUNNING) return; =20 + isp_fw_log_print(isp_subdev); + while (true) { s32 ret; =20 @@ -591,7 +605,8 @@ static void isp4sd_fw_resp_func(struct isp4_subdev *isp= _subdev, &resp.param.frame_done); break; default: - dev_err(dev, "-><- fail respid (0x%x)\n", + dev_err(dev, "-><- fail respid %s(0x%x)\n", + isp4dbg_get_resp_str(resp.resp_id), resp.resp_id); break; } --=20 2.34.1 From nobody Thu Oct 2 20:44:48 2025 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2084.outbound.protection.outlook.com [40.107.237.84]) (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 4CEB33112DB; Thu, 11 Sep 2025 10:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585396; cv=fail; b=V9Uaw5X6x9KyHiFOsGBnSkWL1gVggg/M0+Ic5iB3fwMwIzmmBsQCviie2gHBVg8hB1QfZ4MUxIL6th96sLptLI8PbPmfbGlj5WSmobv8Brw2iGuQhbE2J5Ka5Dt4kwBRMXcit6rNxCIp18tygOTAJKKPhUexd4xmwvGX1VDSz5k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757585396; c=relaxed/simple; bh=VqaKGs5GC4+VwSwomfOLfAZcdY3RTwKr9xADgAF+dOM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mxKJ8Fmc/nOitsZ10oGEZJHdgDwFPpmLWnAY7C9ur+NrwkT0zRLqnwvcfsv9Q4AbWTmCcQI30Sh9I08rXtKgLDKcyP5cHapv3sBhX4S1mk+J/1r65tMWUm02J1OYe5llSdDwZP0uUvI8nuNpvDSGeYCUwpNIRxZHbwiIb8YdEa0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=TMluVeZ2; arc=fail smtp.client-ip=40.107.237.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="TMluVeZ2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LKhpYtlQcOE1XHciLcxvwzxMdZ7seL6IHLEKI3lY+nvI5rT931kASrp1ABbyaFyZ37YIJb8nm4f/rSZQRo03J9XDfcdYiMXwHqMm0JdP+YpRu5phyNzJBlgUP+rZ382kvQGYapUpr5egRfclIChoz/hrP26kykw3PukT8S7JfB1UITEFiqZOT/zSgeGpGVY9YXZHTJ13EnEzr99q0e/pEstzwboqgx244+n1UtKk9rGDsHtGMAqENBR4cTZJM9VH3gqskTEsaPPiJGVn9RoxN4ws9ze/EAQcjhyCFhIellg5bYbKzBC3MwuBNTTfkn73I/SU32n+ExHFzAwLKIdrhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=vD5/tvLCzDURBVoq9TkyCVI5Tx6gEsa6IHDU+rSUyWo=; b=a9EUCOg/qtPYX5Jp2gYfwgP0rePZcPCiSuyQT1pOVtFS0dD7WJz2oGIgAiR/EJQOg2HJ/JNBWkzV74od+4O6jepg2yv9+n9KGltWP4PGVKPgI91sKSG/2in1hDQwKUTjRuhxFPRy9zLNoAM/c1ic3bWE9oLrKrUwlbXFCb/vtpDDZxGRamtySIwJttRBsYWZ9Eg/G98ATeHroKgYQM7IaW+2UqIZStMl82qdwEQ0bbN3CgcHStHG3PCm6+bZ4ultIKLbgZ2Rsy+Ms5pym7f2WvuPJyfdoSmn4XVHmabVAfRiRd86sVUzVuPFgAYgvsnC8iHVFMtWWmtJS8w5I4tqDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vD5/tvLCzDURBVoq9TkyCVI5Tx6gEsa6IHDU+rSUyWo=; b=TMluVeZ2qNW1Qh6/zEUQYMbtPmh00OcMoq+rOu2nxNeKppWj/GTpV5N/oQKkuaqQcsvDqm+y/7HlooD8+CmM8FH/SuNDFSEi3e3e6/XgPHWuMVpfzmHBz1laLNGsq1yMOP9BDY0Eai2jPriD+k1hSgnnUa4m4d57GFyk0ENhR4Q= Received: from MN2PR04CA0020.namprd04.prod.outlook.com (2603:10b6:208:d4::33) by SJ5PPF01781787B.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::986) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9094.22; Thu, 11 Sep 2025 10:09:49 +0000 Received: from MN1PEPF0000ECD9.namprd02.prod.outlook.com (2603:10b6:208:d4:cafe::c2) by MN2PR04CA0020.outlook.office365.com (2603:10b6:208:d4::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9094.22 via Frontend Transport; Thu, 11 Sep 2025 10:09:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by MN1PEPF0000ECD9.mail.protection.outlook.com (10.167.242.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.13 via Frontend Transport; Thu, 11 Sep 2025 10:09:49 +0000 Received: from 555e2b870847.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 11 Sep 2025 03:09:43 -0700 From: Bin Du To: , , , , , , , , CC: , , , , , , , , , , Bin Du , Svetoslav Stoilov , "Mario Limonciello" , Alexey Zagorodnikov Subject: [PATCH v4 7/7] Documentation: add documentation of AMD isp 4 driver Date: Thu, 11 Sep 2025 18:08:47 +0800 Message-ID: <20250911100847.277408-8-Bin.Du@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911100847.277408-1-Bin.Du@amd.com> References: <20250911100847.277408-1-Bin.Du@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD9:EE_|SJ5PPF01781787B:EE_ X-MS-Office365-Filtering-Correlation-Id: f78feaa1-32ee-4ee0-1e71-08ddf11b57a9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?L3M1OryZ5pSi44pFzqP9V5QyJ68Mz9xvOVhpc9AbkLqnX/91JI4fy/YOj2iq?= =?us-ascii?Q?m7oMPhlVdFvJrKqYiKTkaxK+bJT7S2XcGUewH1w2wDuEPBTiMNlp/6u09u8V?= =?us-ascii?Q?vYxfweDdO5zQ/6h8stE0oF1+o7vyhvRQpqaNSADGsy4dgsjMewK3cidRWk52?= =?us-ascii?Q?GMGwaI8PWbM+hE2lBkdCZnZoHIbetHTFUPLDyTawRQSGsJ6PUy7O3Kl/EK+U?= =?us-ascii?Q?vvvcQoiXhnxuTKOrtjhy057qKKXt6zzUJIj9oefQSuDE2sWX3tPtWsyEfsw3?= =?us-ascii?Q?hwEiSM9WxKG8LLnYtUfADbkvVZ7JEx2uGa7apT8+DKked1I2ZV4WAE4T/meh?= =?us-ascii?Q?HDm4tDXKS+c/+AZS2peegLGvUoVUl8PAykoIHDXBs8+2Hy82vzhcG1wD0O8B?= =?us-ascii?Q?0X1aLh2qIJg1ho/nhJiOaulysYfs8e/ru5FyEpEpZqHzVt1TWXRmnl0c3J47?= =?us-ascii?Q?OMAt8kkJlOj27f8kndsqQgHCK7HoZlIvJlIzSaQCcsgRm+MKkVE5uSlyzkoe?= =?us-ascii?Q?eDRhng1spPQJsT9050RosUwhvndb83PndNEV3+mg4GRCTeruyXAG09j2S4WL?= =?us-ascii?Q?IDXn2hmjgPn5bzWsID4pf6jmAdjXT74ClqhkK0Qna+0yvn6+Zs7LOutadrKG?= =?us-ascii?Q?hOpJgHLidkJZVmUvlfHeR/4/F102JRa5siIz02G/P1KxK78kyoRcVHWGk7kT?= =?us-ascii?Q?MJnW+qLNVVnQN/ccLVDMU1/drV6p0p8PTEOYwB8IgkNaAcFyJTalP/voGm7Y?= =?us-ascii?Q?ocqHixqVo2Uh7am0HIo4gUIH479qN/uWBjcbvYYQlreHEXf3eoJgrHXIwIz4?= =?us-ascii?Q?ZjyeO6CwFuznq8SfRTstkwj8Sl6Im7pfq0D0n+gtWIyBBvMVPwS3eWP+qvHs?= =?us-ascii?Q?QxgtIiSnF/YDyEBFhYUfnqRt2ngafqaWWcPWQ0ww33SZD15h0g+ltkLUcI1I?= =?us-ascii?Q?tT9lpuRfrTTi+DbCUJM/dm2AoKQzjZjDNPczWvuCdenPzU21lp8gIXJDEqF3?= =?us-ascii?Q?xNv5XuJCg2coT4XshKvdAGOwX1GlAWAZMwskk6Z21hkx1JMbHgNXbqPjubfR?= =?us-ascii?Q?etBKpYjrFG/7PdRZeQBQk1MFVHjIlXnjHV6bYZByzU2FEDsG0ZPuRv9xDqtQ?= =?us-ascii?Q?kyen/pqU2WwGHVzw+jdHVRAAKqbHO3kFE0+FcnvVhorIuSX4TZ/P9kiwm5wc?= =?us-ascii?Q?stmmXbORPr4ohklkg+AEmCvuRZRpjLV6dcZ1F/ETLC/O6NDqn0oQJll8IS/3?= =?us-ascii?Q?4mHsVNaDHrIfQkxpPmv6HqcFbZ6jfEiH4NX3q+cab6m1+oGB6CgPAU0cJ64O?= =?us-ascii?Q?u5KhzrKs6F/SjV/NU6fHeYat3Ap10v17r6e0AjBd7K+qP4Texrug/lhT1vIo?= =?us-ascii?Q?3lhnxM/ozf00bovN4c9JeMUSI/zvW8ZhXoP0nPfRhPLqMxyAxRRATmZH6dgO?= =?us-ascii?Q?t1nrrbliY9dUuQvyZe8S8kWXHjLcz8+aexXMa1UdMiDkrYy2WSerwg5PrViM?= =?us-ascii?Q?Tj7FX5ZHg/q/Tx4n5pJ2PywrTIJ0yBX+QwVQ?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(82310400026)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2025 10:09:49.3169 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f78feaa1-32ee-4ee0-1e71-08ddf11b57a9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECD9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPF01781787B Content-Type: text/plain; charset="utf-8" Add documentation for AMD ISP 4 and describe the main components Co-developed-by: Svetoslav Stoilov Signed-off-by: Svetoslav Stoilov Signed-off-by: Bin Du Reviewed-by: Mario Limonciello (AMD) Tested-by: Alexey Zagorodnikov --- Documentation/admin-guide/media/amdisp4-1.rst | 63 +++++++++++++++++++ Documentation/admin-guide/media/amdisp4.dot | 6 ++ .../admin-guide/media/v4l-drivers.rst | 1 + MAINTAINERS | 2 + 4 files changed, 72 insertions(+) create mode 100644 Documentation/admin-guide/media/amdisp4-1.rst create mode 100644 Documentation/admin-guide/media/amdisp4.dot diff --git a/Documentation/admin-guide/media/amdisp4-1.rst b/Documentation/= admin-guide/media/amdisp4-1.rst new file mode 100644 index 000000000000..878141154f96 --- /dev/null +++ b/Documentation/admin-guide/media/amdisp4-1.rst @@ -0,0 +1,63 @@ +.. SPDX-License-Identifier: GPL-2.0 + +.. include:: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +AMD Image Signal Processor (amdisp4) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Introduction +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This file documents the driver for the AMD ISP4 that is part of +AMD Ryzen AI Max 300 Series. + +The driver is located under drivers/media/platform/amd/isp4 and uses +the Media-Controller API. + +The driver exposes one video capture device to userspace and provide +web camera like interface. Internally the video device is connected +to the isp4 sub-device responsible for communication with the CCPU FW. + +Topology +=3D=3D=3D=3D=3D=3D=3D=3D + +.. _amdisp4_topology_graph: + +.. kernel-figure:: amdisp4.dot + :alt: Diagram of the media pipeline topology + :align: center + + + +The driver has 1 sub-device: Representing isp4 image signal processor. +The driver has 1 video device: Capture device for retrieving images. + +- ISP4 Image Signal Processing Subdevice Node + +--------------------------------------------- + +The isp4 is represented as a single V4L2 subdev, the sub-device does not +provide interface to the user space. The sub-device is connected to one vi= deo node +(isp4_capture) with immutable active link. The sub-device represents ISP w= ith +connected sensor similar to smart cameras (sensors with integrated ISP). +sub-device has only one link to the video device for capturing the frames. +The sub-device communicates with CCPU FW for streaming configuration and +buffer management. + + +- isp4_capture - Frames Capture Video Node + +------------------------------------------ + +Isp4_capture is a capture device to capture frames to memory. +The entity is connected to isp4 sub-device. The video device +provides web camera like interface to userspace. It supports +mmap and dma buf types of memory. + +Capturing Video Frames Example +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D + +.. code-block:: bash + + v4l2-ctl "-d" "/dev/video0" "--set-fmt-video=3Dwidth=3D1920,heigh= t=3D1080,pixelformat=3DNV12" "--stream-mmap" "--stream-count=3D10" diff --git a/Documentation/admin-guide/media/amdisp4.dot b/Documentation/ad= min-guide/media/amdisp4.dot new file mode 100644 index 000000000000..978f30c1a31a --- /dev/null +++ b/Documentation/admin-guide/media/amdisp4.dot @@ -0,0 +1,6 @@ +digraph board { + rankdir=3DTB + n00000001 [label=3D"{{} | amd isp4\n | { 0}}", shape=3DMrecord, st= yle=3Dfilled, fillcolor=3Dgreen] + n00000001:port0 -> n00000003 [style=3Dbold] + n00000003 [label=3D"Preview\n/dev/video0", shape=3Dbox, style=3Dfilled, f= illcolor=3Dyellow] +} diff --git a/Documentation/admin-guide/media/v4l-drivers.rst b/Documentatio= n/admin-guide/media/v4l-drivers.rst index 3bac5165b134..6027416e5373 100644 --- a/Documentation/admin-guide/media/v4l-drivers.rst +++ b/Documentation/admin-guide/media/v4l-drivers.rst @@ -9,6 +9,7 @@ Video4Linux (V4L) driver-specific documentation .. toctree:: :maxdepth: 2 =20 + amdisp4-1 bttv c3-isp cafe_ccic diff --git a/MAINTAINERS b/MAINTAINERS index 8478789ac265..c34137e27b55 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1139,6 +1139,8 @@ M: Nirujogi Pratap L: linux-media@vger.kernel.org S: Maintained T: git git://linuxtv.org/media.git +F: Documentation/admin-guide/media/amdisp4-1.rst +F: Documentation/admin-guide/media/amdisp4.dot F: drivers/media/platform/amd/Kconfig F: drivers/media/platform/amd/Makefile F: drivers/media/platform/amd/isp4/Kconfig --=20 2.34.1