From nobody Sat Jun 13 02:57:43 2026 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012053.outbound.protection.outlook.com [52.101.66.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 9D1483BED24; Mon, 11 May 2026 09:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778492472; cv=fail; b=gXCkLB58toazojx/i22rzy5lS71ykjj3Uo7uW7mPHlxR5yPKV2J1dGJ5iGHzGuIQ30zXZxhOZe7eUhaBWct3zSLiicBM6zJwhFmnDaTZobyVpJ84x4YL9AUq7i/2EsaCOxSERKoeHWp1DADWtLQIccVPvrvfu//86fKS1LvAhqo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778492472; c=relaxed/simple; bh=BVHG3uWR6afl1Jbo1VG28HHr/BEBpBG85yMrjztWWF4=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=qLThfGdRKdvGuMBY1qpZD6jS0q0bekf1NAFtsfcucFIXZ6ttuAo6L45aVTs5u46OSu6duI+9solHYHQkn6Dqd/Fkk7OnlfZvjGFAAW4IQNtdsUhDdm6H5B+9bH+Gxqu41i4J65SZTLHbppthfnsXtYynkRt3eyw/i9CNni1FYsw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=G3c0YZe6; arc=fail smtp.client-ip=52.101.66.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="G3c0YZe6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hhnuDDKk6eK5EKjpqzTj2q/SuHAAZ6RKNWD4GmAY676bacADsHq5zv3Up1RCZGOMBedDX9C++vJHeskUaWQXI04GdIWGnE2oFayBp0s1vyKlxokalPbTljUTnHT4evw7eypFWvUe/MCnlzXrCWK36BvKv0Q0Xt/C5iLQK48xLtLTF58Ps/UdcKTeX3dVZkjrF/8lkdpBfaeSOuniAEXyosTGGkWlvMgIt4cXw1kCNWry3r/g0h7PM2pTO+S+/eR0BgkKFoR10XAvMapR831Mj64rMXfzpi7CuP/jy4Z62xFqv2PXO1hka6Tsc8vHaqpWf4YEr5jsMx3SLXsKAyTDGw== 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=4UJ71kl2EAYE6qOEWGz7RKAhCNmQRE2s0LDohEzSp+w=; b=fqkFgJRoC1aVdFE5NsvGYUMQ9kL9g9sTm5x2NDnUTGS2NQhKYXwLMjVqo4BMs7aH0DlG1QslmMGLjI4HRJx814P5nfK/4w2ue/h0ZXp5Hbs0OAe5tc1Q16Q2sYWfyCzXY4hg1/raQHfo8Lh5/4EJqOybYwJOeQ1AfUS+0kO6QdLtoWOmRKjCqh8zAYttu4UhfC9kMnxUi+kySf96I367BjO5eK9AgSDj8kxX2CWFLQkWAF5zMCQD1xRAq4rurzX59Qyj8JrsAlBlqJFzSvKo0XnPRREHfuyfXrYcJT3sNoT86m5RXMI9P6qMBdB7KQA5+b7ECvhadcSIoFyoVtlnZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4UJ71kl2EAYE6qOEWGz7RKAhCNmQRE2s0LDohEzSp+w=; b=G3c0YZe6UzsaqeCejzKME/PKNPemvUlngZvzZJJ7Fej7q/bRKQDgxASE3dVocAf/eK+moCMIjxxutY6LPtxURMrR2/3NJSryTFvayBNqcBAAEcxVhpqRq8Ek93MmctczH4tjy0296l9HHssrE2mFtU73zfEB9QDE1ssoBqH9Z7iqL2YPQ2c77Y7QCXtSFBSMF3FNnzAOMtQ77yQpm0PrGL6dytP6xyf4roRu03dDJneuVKcfok5jsDnSQ/o1eKJ+9DBJkiZN+VpY5Pe5s9+R2suFR+9eJmDmFVwK5i8FaBctPt0G4h9hENIWgaJe9hgGJV0gTXvZ4FB/CU33C5eleQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AS8PR04MB9080.eurprd04.prod.outlook.com (2603:10a6:20b:447::16) by PAWPR04MB10030.eurprd04.prod.outlook.com (2603:10a6:102:387::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.22; Mon, 11 May 2026 09:41:06 +0000 Received: from AS8PR04MB9080.eurprd04.prod.outlook.com ([fe80::92c2:2e03:bf99:68eb]) by AS8PR04MB9080.eurprd04.prod.outlook.com ([fe80::92c2:2e03:bf99:68eb%6]) with mapi id 15.20.9891.021; Mon, 11 May 2026 09:41:06 +0000 From: Guoniu Zhou Date: Mon, 11 May 2026 17:43:41 +0800 Subject: [PATCH v6 1/2] media: dt-bindings: Add CSI Pixel Formatter DT bindings Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260511-csi_formatter-v6-1-01028e312e2b@oss.nxp.com> References: <20260511-csi_formatter-v6-0-01028e312e2b@oss.nxp.com> In-Reply-To: <20260511-csi_formatter-v6-0-01028e312e2b@oss.nxp.com> To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Laurent Pinchart , Frank Li Cc: imx@lists.linux.dev, linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Guoniu Zhou , Frank Li , Krzysztof Kozlowski X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778492631; l=2828; i=guoniu.zhou@oss.nxp.com; s=20250815; h=from:subject:message-id; bh=kmJKrwKN0R/LWrPeMaVm+Cbjo5g+tbVw7z3HYWXQFNI=; b=3V/Dp1Us62NnyvTbaCKACXprgVoXXslwaIXM8UP3IMmjN/CAZjguus5/HwpYqElONqBoXJzOc JIUIzhe7kUBCXSa3HdSWU6Nbw1O0cWx+S46FG66/ev8U8oErkhC5mmX X-Developer-Key: i=guoniu.zhou@oss.nxp.com; a=ed25519; pk=MM+/XICg5S78/gs+f9wtGP6yIvkyjTdZwfaxXeu5rlo= X-ClientProxiedBy: SI2PR01CA0004.apcprd01.prod.exchangelabs.com (2603:1096:4:191::22) To AS8PR04MB9080.eurprd04.prod.outlook.com (2603:10a6:20b:447::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB9080:EE_|PAWPR04MB10030:EE_ X-MS-Office365-Filtering-Correlation-Id: d552a4b4-1036-47e5-907b-08deaf416c58 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|52116014|366016|19092799006|1800799024|18002099003|3023799003|921020|38350700014|56012099003|22082099003; X-Microsoft-Antispam-Message-Info: PTzU/dIxF3BZVjqPthZgcUTBmozVT4J0zS1gjAcj6Tdq3Qodd4I8hXL9NzntcEWqyC5PkrVwexKItNoY3JbJXJgm51X3wRbggvENgeeRf7YeIwjGuvW8/96NtyN2XjgFP1WbEUmyeys1CKZTOpRK/XfFETgm6NeKtm+sr+5YZXdTnhbeml0BTVwwTecnLgSEX5FFwyrYkMFmrECcHVRbbY6emlDKZ6/8pOyMpGU6ZkdDGdRABYhxnyUEVkI+5uXpC4vmlrZRsKxFGflYodMBlBHLYfnUqFVS7zZCQjz7+caxt9jSvn67b8eLxLVpR2iDQbYtAKNiimRdAaKpZiOPx3KxJRbFl6vyIrxc+8HLPFMOksuc9Af8kyvyY+V5wSsWjE51vLXBQzMLRrMmNH1BOObfR3JzaTh9bfUqRS+PwtBcZSCd4jXigHtVrkDkhKTMu9TdKlu/oVRd82dpqyQCa9HXNJ7MencYOy400Nin0Mc+hUmJe7dzz5VhWlSwstMLDsRnwgXxGX5xkgT5VMeOJUC8m3LjS5hoJCNGbcaREkeI7jdqYIF/imvKLtGT1UuvZHx7n2bEDa0a4NFebm3l2n+xw620RAGnmLvakXVZMBW7WDy7csyghsky3K6scoC91EIlaTK4QLRiZEvVvrhnrI2BffMiFSbUGHzOelzH/88idAO4Pgc2ppUfYbjloDgkWNH4RZ8NUTn1lbk9q5QBDA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB9080.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(52116014)(366016)(19092799006)(1800799024)(18002099003)(3023799003)(921020)(38350700014)(56012099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YnpZelJRaWI3WEl5U202YVJDVXM0aStFWXdILzFlN1pXb290cnVjU01uLzJN?= =?utf-8?B?ckFwVkZjNHdmTng1RkZhQSt6RTYzT01DUlVxbGZ4L1NxengrSmpLWDV0aGpk?= =?utf-8?B?QlRHWWRSZjdWN1pBNFVjZUYxaWNHTWtvWEZRMjVEZ2EzQkFBZGhBR0xYeWV5?= =?utf-8?B?ZUpJcFd6Ly95MHozZ0lScCtvdHdEamdQQzFQY2RqdDA4aWFyVVFYdm14K2Rz?= =?utf-8?B?cmtadloxZ0dkeWN4TVpINk5SeXBxeWdEamF2aDZKSURYbHc0UWNKaHg3akhH?= =?utf-8?B?U01nSFlJRDZCMEVseHVNM2pRRHY4YWxMbWJXelpJbk9NRkpMdWNrM29US00w?= =?utf-8?B?OFZzYS85c2k0N2s1YnQ5U3NnWFhHTFBVVlRsK0JPSFVOUWh5cmJDVWw3c3Y1?= =?utf-8?B?dCs0WExiV3FlaDJ2b1lHdlRCZ2c3Q3B5anl2TzA3VUlMZm1tckNWOURNQzQ5?= =?utf-8?B?NmsrY3JpMXVOSHRuYkRGRlZ0QkdEVjhjRk5uazR2UE13UlVPT3RtUGNzM0U2?= =?utf-8?B?d3NsT3N0UEdtZDJGQWdQazJmMDZNaUU4TmJxcXF4KzhPam9xem1SL2EybVYz?= =?utf-8?B?dG5CZjJBL0Q3ak5UWFR3d2tIcUZ0R2JMTzFBSVlWamJFZmJRY3dPQm5Xcytr?= =?utf-8?B?dFpvcXhkWlpEdVJ3VlNwN1QvRHBMV28vK1V2cEdxaWRHLzRzSndvWUdYNkNs?= =?utf-8?B?eStkb2VjNExXK0R0d1c2QTVZSDZOSTEyUjB3cEE5THA2YnlIaVAzM0ZuOG9V?= =?utf-8?B?NUUvVmpGRXlJcStlbEpTMkpmdnNwM2F1TVFMVVRGMnQ2TkVyeVNKVGpJNUw5?= =?utf-8?B?T05aSG5hdkpmTmN6QjVFRS8vVCtJZHhCRkNRdlJDZ29YTmxSTnVkek1nUHAr?= =?utf-8?B?NnY0c21RZnZBbXFZVWF5Nis2N1ViK3VmYm9ybmlXREFTbEJCKy9VZFowM3hh?= =?utf-8?B?OXR1RHBzVFdJT3NhQ1lwZU5rRlhkVmNKM2V6dG5YQ0VqWnNkNkN1NCtMVFZZ?= =?utf-8?B?WUhrSzQrcVlzcGhrc09HS0srYng1NEFxaFhmK3RYRHpmV2dPeHdGY2I4dGpS?= =?utf-8?B?b0JVQjFFSC9lc05tL1ZYbTB3L0Q1Q0pLVUZRMUNYc3R4Unl6WGNua0tIdnJq?= =?utf-8?B?QUlySjBvQnpZbkhlbGVMYWZyRURoU0pSQks2QlIzTHFMS3dJc1lCTktnQU45?= =?utf-8?B?MnFyVVhPcVZOS1pHZCs5amJMbFo1Z081OWx1NGQ1ejNNRkUvRjRNUDA1cmFY?= =?utf-8?B?ZE5rQ01NQkdQTE80cmJuZGtLMi9CUHM1REs2Zm5MS2FLS1hTSzg3bDN2S3NW?= =?utf-8?B?Njl6elgrUU15YUhxazNpK0lNZ0dmTFUvcWgxN21qTEFKL2IvVHpBR0p1c0lv?= =?utf-8?B?dXMvb3BaY3VuQTU1NzdPekdDSUh1aThMZ2J6WGFZbG9iQzNtYUNHZ1FxWDBt?= =?utf-8?B?N2ZodUxubzN0Y2NaallseVlhdHFLWFF6NE96cVN6bHRWV25JbEM4OXhuSkJK?= =?utf-8?B?NG5ZSjcxSmpIM3Rma1NRUitJbnVpVVdDSE1SNzlFU01BcDNsUXVlb3U4T2hk?= =?utf-8?B?SXVrQ2dsZ3lRbk04bWUrdHNEOVZNNU44OTM2TGUzWlVZazVUdUNuODR5M2FS?= =?utf-8?B?MUdyN2E3MEU2VVFOVGdmU3Uwa0hRNm9sRGl2YVdaMDJ3Zm9BTE1NNTM5dnkr?= =?utf-8?B?Q2xIL0pZd1lqaWNoM3RGYU8yaDlvV09uaGppT2pBcklZQnFyWUZMcEpmb213?= =?utf-8?B?RGhPVEhsRVRBdjZaTVFFejhOOEw3UGdSdTJvOVZvb3Q1ODhwdnhPWURhbm8r?= =?utf-8?B?OFk3dnZQN0tmOEFCWHZIbUNHR1ZHKzVjYUF5Ymc4UDVibTNsR0VTTzVRTXRm?= =?utf-8?B?WTlkZ3BQSlhEOG4vUDlsU1oyOHRnTjRxSFNKUWd1ODcyZEQ0cEh3SEtKckRk?= =?utf-8?B?TU1nUkduUlorcG9lVXQ1dS8xeGVhZ1JWQUs0UTdzQjFuNlRVTk1tanYxaVFp?= =?utf-8?B?dmpIRFRnUjBZV3FOY3h6MGozNkVuczBCV3I4SFNweGpxNENwTGlIMzEzL1Zv?= =?utf-8?B?S0JvNEM5WVIyRDRPcnh1Vzd1c1FEbml2UzB3dTQzS2NXQnVGQ24wK3FXUUpz?= =?utf-8?B?TUtBZmNZSGdpKy9SSS9OTUQ0T21JaUtEbi85OFE0R1pTMnE0SEgzODlONUZR?= =?utf-8?B?ajIrMXJSbXBYcW5hdG81YmFFcW4xMjQ4S1A3aDRoZ01uQ2pwVjNPdGtnY1M0?= =?utf-8?B?V09DL3VVSGJJUis5bmdoTm16UG0wUTloNi90SlhEaVFqMU1Rc1pFeThQRkYz?= =?utf-8?B?NEJrWmM4eURLNTQvcU9iSEE5LzVwd2pzZUdLdTM3VlpvaFE5Um5KQT09?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d552a4b4-1036-47e5-907b-08deaf416c58 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB9080.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2026 09:41:06.0371 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ugafwQ0kKa/66mLow3fC07lT+/DRwPPPb0SFa268u4aRR6lzfIt2VY/klxXjz82otpFQbkjPv2dVwdtbOGk5OA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR04MB10030 From: Guoniu Zhou The i.MX9 CSI pixel formatting module uses packet info, pixel and non-pixel data from the CSI-2 host controller and reformat them to match Pixel Link(PL) definition. Reviewed-by: Frank Li Reviewed-by: Krzysztof Kozlowski Signed-off-by: Guoniu Zhou --- .../bindings/media/fsl,imx9-csi-formatter.yaml | 87 ++++++++++++++++++= ++++ 1 file changed, 87 insertions(+) diff --git a/Documentation/devicetree/bindings/media/fsl,imx9-csi-formatter= .yaml b/Documentation/devicetree/bindings/media/fsl,imx9-csi-formatter.yaml new file mode 100644 index 000000000000..774d37d2b987 --- /dev/null +++ b/Documentation/devicetree/bindings/media/fsl,imx9-csi-formatter.yaml @@ -0,0 +1,87 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/fsl,imx9-csi-formatter.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: i.MX9 CSI Pixel Formatter + +maintainers: + - Guoniu Zhou + +description: + The CSI pixel formatting module uses packet info, pixel and non-pixel + data from the CSI-2 host controller and reformat them to match Pixel + Link(PL) definition. + +properties: + compatible: + const: fsl,imx9-csi-formatter + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + power-domains: + maxItems: 1 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: MIPI CSI-2 RX IDI interface + + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Pixel Link Interface + +required: + - compatible + - reg + - clocks + - power-domains + - ports + +additionalProperties: false + +examples: + - | + #include + + formatter@20 { + compatible =3D "fsl,imx9-csi-formatter"; + reg =3D <0x20 0x100>; + clocks =3D <&cameramix_csr IMX95_CLK_CAMBLK_CSI2_FOR0>; + power-domains =3D <&scmi_devpd 3>; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + + endpoint { + remote-endpoint =3D <&mipi_csi_0_out>; + }; + }; + + port@1 { + reg =3D <1>; + + endpoint { + remote-endpoint =3D <&isi_in_2>; + }; + }; + }; + }; --=20 2.34.1 From nobody Sat Jun 13 02:57:43 2026 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012033.outbound.protection.outlook.com [52.101.66.33]) (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 5CCD93BE644; Mon, 11 May 2026 09:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.33 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778492484; cv=fail; b=UgkxSOMa/De+n3vecnPV9FLMrQPdJgKpQSQ8sg4ggIII7HPX7y8BSBb12vL1527b070/tP/uAbJ8HGRrauia+CwtxLHBdWG1rME+idsLeADdQYWI8qmnxzrZPiB3jV1AUSUU2IszbVHoEVd85+wvgca75sG4iAfTwYbbyYYn3HY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778492484; c=relaxed/simple; bh=dfCmNI4EA0kx8BPJqkW8Z66QCK5TQdCiEe7LtloMptU=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=O6UJ24xUc/cZtk0iXmNFfrLq6Yj7QE/v/s6g74JMO1EuemqZZtK2JgClS0PlMpxTiytbjPDcdMhTCB7Yfis0cM2y97fGzw63vXXQfswFHxA110PpVHA6IJFUXWgspNewPvsRuMr1gcZzf30RdLWeffZi+IBkNV9+d6faLgft0Ss= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=D6wbCAuK; arc=fail smtp.client-ip=52.101.66.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="D6wbCAuK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BJHeQMM4NE0p02UQTfbKmC1Z8A4SSQd/zuDsflfHCb86KEHjcmIR1vECcyeLkf9lBrMVprlHbJF2BbB0zRu2jVt7M26p1VL+1yn6Hjog1aAUW4klC2ROaHOlCH7TKJQBPwmpv4MVYYcgBB14iXDp99+zI/usmfQoCHkC2r7DlpxnEyfOz606F9nDEKajbbFTyBaHq/qRiZy3nimP68WnYyOQh/kh910AyEc95wouaeONyZvoKLETP9CNUECIzwlVvMMN9XSXIhiqEMpCQ6CIC9iAS0XcQxSTajXXOocZQqOvh47LjJLFg/Ae/hJjy5HiQN8+CH8VOqhl/E/qhCv9Vw== 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=80ipE9PKSkYyK5hr5uojM19L4XRE9XGEFcBgx9wno4Q=; b=Y1B9nQEgxeyEhvE2CDCiv/lCpcUYrZDWZcT0cNB3rbEmXCwzPxWcnJu/w51abIbyXIHXs7pEFR077L5gLdU1Ef7QLXBo4yQjlA6wVwo/agHZ2RrFPpc6An1LO73CBxXRfKQJZFhlNk5D6z8iLva6wS2DhE8hFio79a0kYKkvG1Ttv0Mv0HpB0AdvllKJqWFe79fNe6YoJf2vbG31r5Klub/l/1HSzZ6rxs3dE+9h4MbBv99B5rRTOjvPEDfITcJPIfQctB1ZALeL0009MacSPgoOOr36CYSXbShSW6RuC2012IpLosJuAZzBThvg+s08eCihupMq+4n/j468EFQG2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=80ipE9PKSkYyK5hr5uojM19L4XRE9XGEFcBgx9wno4Q=; b=D6wbCAuKM8v//WcREppzev1AbaM8KkMK52/TrTUzjpzKXISlnloQe9u2bjR0J5tBJ12HiV9JCwy6obSSKQSpBhxGcOGYUu/V0BarrZ/utTt48lxrlABIN7orRFlEzdgnZD6GgQLmsJBnO7kI0wH3n1TgCNH46EEsNTi8LBPnPrC31pEPEu6H2Bf72pWHY9RlaWPAv8c67gmypGVIUgK20kdDJB4rKT67+f/3bFRAK8oSiYAKEuJtbmlfk5pQ4eiWAPQ3dvBitMTM5JtZr/r9LqvG1Je0zewkuDHr2hHjqn67lExzyX2s9KhPECJZqBNz7RcvBFQIBPTY9MOYuVNygQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AS8PR04MB9080.eurprd04.prod.outlook.com (2603:10a6:20b:447::16) by PAWPR04MB10030.eurprd04.prod.outlook.com (2603:10a6:102:387::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.22; Mon, 11 May 2026 09:41:10 +0000 Received: from AS8PR04MB9080.eurprd04.prod.outlook.com ([fe80::92c2:2e03:bf99:68eb]) by AS8PR04MB9080.eurprd04.prod.outlook.com ([fe80::92c2:2e03:bf99:68eb%6]) with mapi id 15.20.9891.021; Mon, 11 May 2026 09:41:10 +0000 From: Guoniu Zhou Date: Mon, 11 May 2026 17:43:42 +0800 Subject: [PATCH v6 2/2] media: nxp: Add i.MX9 CSI pixel formatter v4l2 driver Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260511-csi_formatter-v6-2-01028e312e2b@oss.nxp.com> References: <20260511-csi_formatter-v6-0-01028e312e2b@oss.nxp.com> In-Reply-To: <20260511-csi_formatter-v6-0-01028e312e2b@oss.nxp.com> To: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Laurent Pinchart , Frank Li Cc: imx@lists.linux.dev, linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Guoniu Zhou , Frank Li X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778492631; l=26829; i=guoniu.zhou@oss.nxp.com; s=20250815; h=from:subject:message-id; bh=s2OrUlRrKt5l2KTr8do1re+Ka6PPwWMk9X4K9uK1zAc=; b=+4L1HmLs251mJdSjSaeDukW7DbQGniwv4Q0m5RsvG6/RKr2myvcbAcmAHHxThTVb8WKkF+YeA hhfIkZOfxSgBwTk5w5PL/GSdeXQFcSCdYZE4XcxIsrC9HZ3XJtPYS9t X-Developer-Key: i=guoniu.zhou@oss.nxp.com; a=ed25519; pk=MM+/XICg5S78/gs+f9wtGP6yIvkyjTdZwfaxXeu5rlo= X-ClientProxiedBy: SI2PR01CA0004.apcprd01.prod.exchangelabs.com (2603:1096:4:191::22) To AS8PR04MB9080.eurprd04.prod.outlook.com (2603:10a6:20b:447::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB9080:EE_|PAWPR04MB10030:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d007577-de1c-47a2-b7af-08deaf416f37 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|52116014|366016|19092799006|1800799024|18002099003|3023799003|921020|38350700014|56012099003|22082099003; X-Microsoft-Antispam-Message-Info: ylKMDUBsxUMno6As39r08YNOYxWjgVPKzWS1nzGRgnh3j06OgvB/71amjH0SV7g6+3ZBB5YLnneYyaubiT5RXbZdFUAn5LTJg06v16PbLbZZpVCSEXegc/kV+lALCgJdFZRBIbH2CwoE3+v1FL/qYAhy/FEYgdeja4McmCzkQM4a4+euq6mKE7COc1W1W4FB9LF7wAr7K4oobDNQKzHtc/XaVSvPHe20Z+NcxArn258WJnM1RlpSJufLamjbO34UtyGHs7zHXYOvzALLf6kmopvxlN9WqfYRyAe3YsU7FRN5ZTXTJnMvvOrcuy/Wb2Khl4jEiODmiImMK6E4LpPBZtG6OfX4w+TalsaM5X4U2WOMx7AFAQa70gfhrqN4z1QZF4nZo1a6ZH+vzzZjfji3Qnbj9wBvTIXet5bPppfDL/jG/b2GSHRhzmOxMqhcVVsiCTF2U0ww8UTofcUIjaU0yFyt88elVBh4aLYAGbQ87xkFMqpR16PuFS7f2muUifgsTvmOTNU9K4Lvt9uufZFQ4rfUQCvOmvszQLWJcHU3cWOaDvk/kaaRLy65cXVg7L7qiZD+VTmvoNexwFYqFgiXhNkOQzUcGBBDeUjAgvnEzAreffg9AI/mL224mou/FezUCAhCSqCz3yj5F4tBX/KmfnNS99UePFvU2t6aIAaHl0FT6cnZkDMoaI7m9MoxJXlmzYNGm+27noOtGK/mkQ1yGQOSJ0ct6q7ulXPcrLb8uWlub4hIbJCxgFGO1UXifgtlhw7sJjvN6VUdPY3UltHhTw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB9080.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(52116014)(366016)(19092799006)(1800799024)(18002099003)(3023799003)(921020)(38350700014)(56012099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bExYcHhjc3NNczVjU3VSM1JNb0VtaDkwRktSbGxnUUUxaXpYNXg2c0VoNHZ0?= =?utf-8?B?UEI3bUVUbnlYMHFlL2RBTytjV3hjL0IyNmlGa0J0bFQ4aG9JTTIxWjZaNTRS?= =?utf-8?B?Q0UvTTR0bnpHUFBmVDh0NEZPb0RHbkR2N2NUcU1jcXNnZVJRZGxPK0N0UFA3?= =?utf-8?B?eFNRTk9Ocm9DbXBMVGhIMUVWUndPdEdRZlQ0LzIraWZjREhEV0YyWllTcGYy?= =?utf-8?B?SVJzZE54eHdpZ1UwMlR0bVlRZmJDd3hXbVNSYUQxTFEwc2ZCQzYwOGN2SXdG?= =?utf-8?B?ck8yQm1MNEI0bFZSOXJoSUlia2x1ejJRblhRU1BWVHo2Y0QxYTFReWk0Ym9J?= =?utf-8?B?c1plRVNtRU9HSWtDT00vNi9HMUkyZG91dVROZWxGcWZ0TS85RTdqSGVpcStz?= =?utf-8?B?WGt3UndBcFo3VnJLZ2FMMk11MHZDZ0dPNnVieXYzU1hpaXJtT3dLa24vVHp1?= =?utf-8?B?OUUwVHNQSUo1RElYRVhCRnZWekVqK1pUcnd5SVcyVXNTRVhnUUtxTUNPUG9M?= =?utf-8?B?WUdiS1JDdkIraXc0RVI1ajZ0ZFRoejhYNDlFSnJtTGc4VUY1ZmhKWWdwSm54?= =?utf-8?B?aVovenl6VWVQczNCRlB1TlJ4Y1JRM201bTJKWWpneDRTYWIySE5YS3BpY29m?= =?utf-8?B?RkMwQTNyZ2NPQWdVSmtnZVMyL3FDUUg1enJ5VmhKODMyL1J5MU5xWEVRUGJD?= =?utf-8?B?c2xPNTJCckVicEFQNmNoWDFTbDBUWmE1cWNaL0xrL0kyN21pZFdlRm9CL05l?= =?utf-8?B?dnNHWHpzRHBKZkdGNzRCdW1PdWd3YkVUM2pRSXZJOEZhcVRVOTNxUFY0Q055?= =?utf-8?B?ckM2b1ZMd2N3dk55R3Zub3A5S0k3bytHRnhFWlJDQTdQMDFSaXF1YjFQV0p3?= =?utf-8?B?Q2o2aG43VjRUa2xORnlSbnUxbkJjenplWGM0Wi9jMUJTZjFJakEvN1hucm5m?= =?utf-8?B?NmVDa2J1MGtTMUUvWUJkL0ZlVjQrOXNqV0tpakUvUHl2MEFvMzd1Y2drUzAr?= =?utf-8?B?NFcxMVc2c01TNHBvMjlyc1ZLcjRwTGkzcHJUU0xpZG45Y3dXcmQ0U2dlSFVx?= =?utf-8?B?U2ZPLytIL0tra25RQmxqNjJ3OEpoOFpxbVVzaXhEZ1NkOTNFRmdUTTRscW5r?= =?utf-8?B?UHVVWDA0dlROMTFmL2I1YW9mNWpRb0xqQk1mc2MzS3ptYzV1M055V2V1eUdk?= =?utf-8?B?aGdGZUdXazgxTFF0Y3ZLWnpEcXBBcTM1RTV2OENtUnJkQ1FmaGdERkQxVmVR?= =?utf-8?B?bFVqVGRPQ3NUb212VWpsRmxZbEtRSEZ5cDlISXMreUxESSs3dkNCSzROaVZR?= =?utf-8?B?L3lxMFlqUjdlZDN6S1Buck1sdXZSTVBtZGRwRzFLb3lnZlhUNEdIbElJcnhC?= =?utf-8?B?aUo0eHRJdkgzaWxqSm1iNUluNE9IeEoxVU1DS3R1Qm00UVg5cFIyQ0YrK3pE?= =?utf-8?B?ZVl3bjdNSnVBSklvVDl3Y2JYK3BiYkRhN1hDNGhDdFNaRzNZVEhoWE1PYnZU?= =?utf-8?B?VU9UYjZDTUlNT2hMNzZuNFZOM1krTi9zK2srZDZxNGFhTGt2bCtJUVhiT00z?= =?utf-8?B?L3JPL3BBc1NQaVBRWk5pMktVS3RIVmNyc2RDRmFITUIzZUVLZDBvT0d5MmlU?= =?utf-8?B?NVl1YWRmUzJSeDVGeUFEaTQ4dXR2c3FMU3h1UEtraVRrbklIYVlDMU1NWXox?= =?utf-8?B?QVNMaXByZmkyQUtNcWoxWnFCYW1kc0R1TG9NbEVxRzFFVU1MVkQ3NWFnb0Nw?= =?utf-8?B?L2FCWEttUk1VZElTZGhHQzByc1Rpa0FnNllvMlZLWFZucE8vTVJWMzNNK3pZ?= =?utf-8?B?cko2TDdZNXVWbGdJNFcrSzkyeVc3eXltRlVTUkhOVUF5bnluRXQ5enpKNVNN?= =?utf-8?B?ajhNRStsNzJKVzZHVTlDaHJFbnQwRzJ0b0FjakE4dGkvZHk3dVR0SjFCcmFB?= =?utf-8?B?OXBaL0VBV0VuY0Q2K2NNd08zRnZ1QTVLbmE4aG5PYkR3Vjk5MndNTXB4SVYz?= =?utf-8?B?Y0w5N0FOcTYra0pid1BQUTFUbkoyR1pYM1ErWlNaOHNOb3RxMFpiNWdpK0tn?= =?utf-8?B?UjVSRHNzMFB0bWhnbzVNQ0VLcmQrZnhaT1Y3aGJONmNiV3JFUlA0c3FzaVlp?= =?utf-8?B?RnlIWXNnWVUzT3pxZ3p6SE4yZS9uZnBHVUt1VnN1R200UUE0RUZLMWgyeVEw?= =?utf-8?B?Sk42aGpRa3JLL041azEzZVBLclRrZk5zVUdSUGM1ZHB0YlNWK1RBMmxZQ1Fz?= =?utf-8?B?N293ck51clh4SHdGeWdNRDVGUFdPVnB6RHR6NmtBNENqT3ZyWS9WS2ttSTdK?= =?utf-8?B?NE01eU1OSWNWYWFLdHdqS3ZBUlVZNm1SUzd3bjFEVnN5VlN5cndYQT09?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d007577-de1c-47a2-b7af-08deaf416f37 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB9080.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2026 09:41:10.8548 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EFTVS8aFqJ+KkHKfjJ3magZIiwnSCyACqUaiefoUjkxSBD0Z08XQ+sAEYE0O8rtNsAz7bjxC8ZyirPaSRgjG0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR04MB10030 From: Guoniu Zhou The CSI pixel formatter is a module found on i.MX95 used to reformat packet info, pixel and non-pixel data from CSI-2 host controller to match Pixel Link(PL) definition. Add data formatting support. Reviewed-by: Frank Li Signed-off-by: Guoniu Zhou --- Changes in v6: - Remove unused header includes - Unify macro naming: VCx/VCX -> VC and parameter x -> vc - Remove unused format field from csi_formatter struct - Use compact initialization for formats array - Make find_csi_format() return NULL instead of default format - Use unsigned int for array index in find_csi_format() - Add err_ prefix to error handling labels - Add v4l2_subdev_cleanup() and reorder cleanup sequence - Update enable_streams debug output format - Rename VC_MAX to VC_NUM and fix boundary check - Update CSI formatter Kconfig description - Use v4l2_subdev_get_frame_desc_passthrough() helper - Fix error paths in async registration and probe - Add mutex to protect enabled_streams - Switch to devm_pm_runtime_enable() - Remove redundant num_routes check in set_routing - Optimize get_index_by_dt() and add warning for unsupported type - csi_formatter_start/stop_stream: Process all streams in mask --- MAINTAINERS | 8 + drivers/media/platform/nxp/Kconfig | 14 + drivers/media/platform/nxp/Makefile | 1 + drivers/media/platform/nxp/imx9-csi-formatter.c | 776 ++++++++++++++++++++= ++++ 4 files changed, 799 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 81d53481d3f7..096361682b23 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19265,6 +19265,14 @@ S: Maintained F: Documentation/devicetree/bindings/media/nxp,imx8-jpeg.yaml F: drivers/media/platform/nxp/imx-jpeg =20 +NXP i.MX 9 CSI PIXEL FORMATTER V4L2 DRIVER +M: Guoniu Zhou +L: imx@lists.linux.dev +L: linux-media@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/media/fsl,imx9-csi-formatter.yaml +F: drivers/media/platform/nxp/imx9-csi-formatter.c + NXP i.MX CLOCK DRIVERS M: Abel Vesa R: Peng Fan diff --git a/drivers/media/platform/nxp/Kconfig b/drivers/media/platform/nx= p/Kconfig index 40e3436669e2..952deb3b81c1 100644 --- a/drivers/media/platform/nxp/Kconfig +++ b/drivers/media/platform/nxp/Kconfig @@ -28,6 +28,20 @@ config VIDEO_IMX8MQ_MIPI_CSI2 Video4Linux2 driver for the MIPI CSI-2 receiver found on the i.MX8MQ SoC. =20 +config VIDEO_IMX9_CSI_FORMATTER + tristate "NXP i.MX9 CSI Pixel Formatter driver" + depends on ARCH_MXC || COMPILE_TEST + depends on VIDEO_DEV + select MEDIA_CONTROLLER + select V4L2_FWNODE + select VIDEO_V4L2_SUBDEV_API + help + This driver provides support for the CSI Pixel Formatter found on + i.MX9 series SoCs. This module unpacks the pixels received from the + CSI-2 interface and reformats them to meet pixel link requirements. + + Say Y here to enable CSI Pixel Formater module for i.MX9 SoC. + config VIDEO_IMX_MIPI_CSIS tristate "NXP MIPI CSI-2 CSIS receiver found on i.MX7 and i.MX8 models" depends on ARCH_MXC || COMPILE_TEST diff --git a/drivers/media/platform/nxp/Makefile b/drivers/media/platform/n= xp/Makefile index 4d90eb713652..39ba5660ba92 100644 --- a/drivers/media/platform/nxp/Makefile +++ b/drivers/media/platform/nxp/Makefile @@ -6,6 +6,7 @@ obj-y +=3D imx8-isi/ =20 obj-$(CONFIG_VIDEO_IMX7_CSI) +=3D imx7-media-csi.o obj-$(CONFIG_VIDEO_IMX8MQ_MIPI_CSI2) +=3D imx8mq-mipi-csi2.o +obj-$(CONFIG_VIDEO_IMX9_CSI_FORMATTER) +=3D imx9-csi-formatter.o obj-$(CONFIG_VIDEO_IMX_MIPI_CSIS) +=3D imx-mipi-csis.o obj-$(CONFIG_VIDEO_IMX_PXP) +=3D imx-pxp.o obj-$(CONFIG_VIDEO_MX2_EMMAPRP) +=3D mx2_emmaprp.o diff --git a/drivers/media/platform/nxp/imx9-csi-formatter.c b/drivers/medi= a/platform/nxp/imx9-csi-formatter.c new file mode 100644 index 000000000000..aca04de8e0ed --- /dev/null +++ b/drivers/media/platform/nxp/imx9-csi-formatter.c @@ -0,0 +1,776 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2025 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* CSI Pixel Formatter registers map */ + +#define CSI_VC_INTERLACED_LINE_CNT(vc) (0x00 + (vc) * 0x04) +#define INTERLACED_ODD_LINE_CNT_SET(x) FIELD_PREP(GENMASK(13, 0), (x)) +#define INTERLACED_EVEN_LINE_CNT_SET(x) FIELD_PREP(GENMASK(29, 16), (x)) + +#define CSI_VC_INTERLACED_CTRL 0x20 + +#define CSI_VC_INTERLACED_ERR 0x24 +#define CSI_VC_ERR_MASK GENMASK(7, 0) +#define CSI_VC_ERR(vc) BIT((vc)) + +#define CSI_VC_YUV420_FIRST_LINE_EVEN 0x28 +#define YUV420_FIRST_LINE_EVEN(vc) BIT((vc)) + +#define CSI_RAW32_CTRL 0x30 +#define CSI_VC_RAW32_MODE(vc) BIT((vc)) +#define CSI_VC_RAW32_SWAP_MODE(vc) BIT((vc) + 8) + +#define STREAM_FENCING_CTRL 0x34 +#define CSI_VC_STREAM_FENCING(vc) BIT((vc)) +#define CSI_VC_STREAM_FENCING_RST(vc) BIT((vc) + 8) + +#define STREAM_FENCING_STS 0x38 +#define STREAM_FENCING_STS_MASK GENMASK(7, 0) + +#define CSI_VC_NON_PIXEL_DATA_TYPE(vc) (0x40 + (vc) * 0x04) + +#define CSI_VC_PIXEL_DATA_CTRL(vc) (0x60 + (vc) * 0x04) +#define NEW_VC(vc) FIELD_PREP(GENMASK(3, 1), vc) +#define REROUTE_VC_ENABLE BIT(0) + +#define CSI_VC_ROUTE_PIXEL_DATA_TYPE(vc) (0x80 + (vc) * 0x04) + +#define CSI_VC_NON_PIXEL_DATA_CTRL(vc) (0xa0 + (vc) * 0x04) + +#define CSI_VC_PIXEL_DATA_TYPE(vc) (0xc0 + (vc) * 0x04) + +#define CSI_VC_PIXEL_DATA_TYPE_ERR(vc) (0xe0 + (vc) * 0x04) + +#define CSI_FORMATTER_PAD_SINK 0 +#define CSI_FORMATTER_PAD_SOURCE 1 +#define CSI_FORMATTER_PAD_NUM 2 + +#define CSI_FORMATTER_VC_NUM 8 /* Number of virtual channels */ + +struct formatter_pix_format { + u32 code; + u32 data_type; +}; + +struct csi_formatter { + struct device *dev; + struct regmap *regs; + struct clk *clk; + + struct v4l2_subdev sd; + struct v4l2_subdev *csi_sd; + struct v4l2_async_notifier notifier; + struct media_pad pads[CSI_FORMATTER_PAD_NUM]; + const struct formatter_pix_format *fmt; + + u32 remote_pad; + u32 reg_offset; + + /* Protects enabled_streams */ + struct mutex lock; + u64 enabled_streams; +}; + +struct dt_index { + u8 dtype; + u8 index; +}; + +/* + * The index should correspond to the bit index define in register + * which enable the data type of pixel data transported by Formatter. + */ +static const struct dt_index formatter_dt_to_index_map[] =3D { + { .dtype =3D MIPI_CSI2_DT_YUV420_8B, .index =3D 0 }, + { .dtype =3D MIPI_CSI2_DT_YUV420_8B_LEGACY, .index =3D 2 }, + { .dtype =3D MIPI_CSI2_DT_YUV422_8B, .index =3D 6 }, + { .dtype =3D MIPI_CSI2_DT_RGB444, .index =3D 8 }, + { .dtype =3D MIPI_CSI2_DT_RGB555, .index =3D 9 }, + { .dtype =3D MIPI_CSI2_DT_RGB565, .index =3D 10 }, + { .dtype =3D MIPI_CSI2_DT_RGB666, .index =3D 11 }, + { .dtype =3D MIPI_CSI2_DT_RGB888, .index =3D 12 }, + { .dtype =3D MIPI_CSI2_DT_RAW6, .index =3D 16 }, + { .dtype =3D MIPI_CSI2_DT_RAW7, .index =3D 17 }, + { .dtype =3D MIPI_CSI2_DT_RAW8, .index =3D 18 }, + { .dtype =3D MIPI_CSI2_DT_RAW10, .index =3D 19 }, + { .dtype =3D MIPI_CSI2_DT_RAW12, .index =3D 20 }, + { .dtype =3D MIPI_CSI2_DT_RAW14, .index =3D 21 }, + { .dtype =3D MIPI_CSI2_DT_RAW16, .index =3D 22 }, +}; + +static const struct formatter_pix_format formats[] =3D { + /* YUV formats */ + { MEDIA_BUS_FMT_UYVY8_1X16, MIPI_CSI2_DT_YUV422_8B }, + /* RGB formats */ + { MEDIA_BUS_FMT_RGB565_1X16, MIPI_CSI2_DT_RGB565 }, + { MEDIA_BUS_FMT_RGB888_1X24, MIPI_CSI2_DT_RGB888 }, + /* RAW (Bayer and greyscale) formats */ + { MEDIA_BUS_FMT_SBGGR8_1X8, MIPI_CSI2_DT_RAW8 }, + { MEDIA_BUS_FMT_SGBRG8_1X8, MIPI_CSI2_DT_RAW8 }, + { MEDIA_BUS_FMT_SGRBG8_1X8, MIPI_CSI2_DT_RAW8 }, + { MEDIA_BUS_FMT_SRGGB8_1X8, MIPI_CSI2_DT_RAW8 }, + { MEDIA_BUS_FMT_Y8_1X8, MIPI_CSI2_DT_RAW8 }, + { MEDIA_BUS_FMT_SBGGR10_1X10, MIPI_CSI2_DT_RAW10 }, + { MEDIA_BUS_FMT_SGBRG10_1X10, MIPI_CSI2_DT_RAW10 }, + { MEDIA_BUS_FMT_SGRBG10_1X10, MIPI_CSI2_DT_RAW10 }, + { MEDIA_BUS_FMT_SRGGB10_1X10, MIPI_CSI2_DT_RAW10 }, + { MEDIA_BUS_FMT_Y10_1X10, MIPI_CSI2_DT_RAW10 }, + { MEDIA_BUS_FMT_SBGGR12_1X12, MIPI_CSI2_DT_RAW12 }, + { MEDIA_BUS_FMT_SGBRG12_1X12, MIPI_CSI2_DT_RAW12 }, + { MEDIA_BUS_FMT_SGRBG12_1X12, MIPI_CSI2_DT_RAW12 }, + { MEDIA_BUS_FMT_SRGGB12_1X12, MIPI_CSI2_DT_RAW12 }, + { MEDIA_BUS_FMT_Y12_1X12, MIPI_CSI2_DT_RAW12 }, + { MEDIA_BUS_FMT_SBGGR14_1X14, MIPI_CSI2_DT_RAW14 }, + { MEDIA_BUS_FMT_SGBRG14_1X14, MIPI_CSI2_DT_RAW14 }, + { MEDIA_BUS_FMT_SGRBG14_1X14, MIPI_CSI2_DT_RAW14 }, + { MEDIA_BUS_FMT_SRGGB14_1X14, MIPI_CSI2_DT_RAW14 }, + { MEDIA_BUS_FMT_SBGGR16_1X16, MIPI_CSI2_DT_RAW16 }, + { MEDIA_BUS_FMT_SGBRG16_1X16, MIPI_CSI2_DT_RAW16 }, + { MEDIA_BUS_FMT_SGRBG16_1X16, MIPI_CSI2_DT_RAW16 }, + { MEDIA_BUS_FMT_SRGGB16_1X16, MIPI_CSI2_DT_RAW16 }, +}; + +static const struct v4l2_mbus_framefmt formatter_default_fmt =3D { + .code =3D MEDIA_BUS_FMT_UYVY8_1X16, + .width =3D 1920U, + .height =3D 1080U, + .field =3D V4L2_FIELD_NONE, + .colorspace =3D V4L2_COLORSPACE_SMPTE170M, + .xfer_func =3D V4L2_MAP_XFER_FUNC_DEFAULT(V4L2_COLORSPACE_SMPTE170M), + .ycbcr_enc =3D V4L2_MAP_YCBCR_ENC_DEFAULT(V4L2_COLORSPACE_SMPTE170M), + .quantization =3D V4L2_QUANTIZATION_LIM_RANGE, +}; + +static const struct formatter_pix_format *find_csi_format(u32 code) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(formats); i++) + if (code =3D=3D formats[i].code) + return &formats[i]; + + return NULL; +} + +/* -----------------------------------------------------------------------= ------ + * V4L2 subdev operations + */ + +static inline struct csi_formatter *sd_to_formatter(struct v4l2_subdev *sd= ev) +{ + return container_of(sdev, struct csi_formatter, sd); +} + +static int __formatter_subdev_set_routing(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_krouting *routing) +{ + int ret; + + ret =3D v4l2_subdev_routing_validate(sd, routing, + V4L2_SUBDEV_ROUTING_ONLY_1_TO_1); + if (ret) + return ret; + + return v4l2_subdev_set_routing_with_fmt(sd, state, routing, + &formatter_default_fmt); +} + +static int formatter_subdev_init_state(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state) +{ + struct v4l2_subdev_route routes[] =3D { + { + .sink_pad =3D CSI_FORMATTER_PAD_SINK, + .sink_stream =3D 0, + .source_pad =3D CSI_FORMATTER_PAD_SOURCE, + .source_stream =3D 0, + .flags =3D V4L2_SUBDEV_ROUTE_FL_ACTIVE, + }, + }; + + struct v4l2_subdev_krouting routing =3D { + .num_routes =3D ARRAY_SIZE(routes), + .routes =3D routes, + }; + + return __formatter_subdev_set_routing(sd, sd_state, &routing); +} + +static int formatter_subdev_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_mbus_code_enum *code) +{ + if (code->pad =3D=3D CSI_FORMATTER_PAD_SOURCE) { + struct v4l2_mbus_framefmt *fmt; + + if (code->index > 0) + return -EINVAL; + + fmt =3D v4l2_subdev_state_get_format(sd_state, code->pad, + code->stream); + code->code =3D fmt->code; + return 0; + } + + if (code->index >=3D ARRAY_SIZE(formats)) + return -EINVAL; + + code->code =3D formats[code->index].code; + + return 0; +} + +static int formatter_subdev_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *sdformat) +{ + struct csi_formatter *formatter =3D sd_to_formatter(sd); + struct formatter_pix_format const *format; + struct v4l2_mbus_framefmt *fmt; + + if (sdformat->pad =3D=3D CSI_FORMATTER_PAD_SOURCE) + return v4l2_subdev_get_fmt(sd, sd_state, sdformat); + + /* + * Validate the media bus code and clamp and align the size. + * + * The total number of bits per line must be a multiple of 8. We thus + * need to align the width for formats that are not multiples of 8 + * bits. + */ + format =3D find_csi_format(sdformat->format.code); + if (!format) + format =3D &formats[0]; + + v4l_bound_align_image(&sdformat->format.width, 1, 0xffff, 2, + &sdformat->format.height, 1, 0xffff, 0, 0); + + fmt =3D v4l2_subdev_state_get_format(sd_state, sdformat->pad, + sdformat->stream); + *fmt =3D sdformat->format; + + /* Set default code if user set an invalid value */ + fmt->code =3D format->code; + + /* Propagate the format from sink stream to source stream */ + fmt =3D v4l2_subdev_state_get_opposite_stream_format(sd_state, sdformat->= pad, + sdformat->stream); + if (!fmt) + return -EINVAL; + + *fmt =3D sdformat->format; + + /* Store the CSIS format descriptor for active formats. */ + if (sdformat->which =3D=3D V4L2_SUBDEV_FORMAT_ACTIVE) + formatter->fmt =3D format; + + return 0; +} + +static int formatter_subdev_set_routing(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + enum v4l2_subdev_format_whence which, + struct v4l2_subdev_krouting *routing) +{ + if (which =3D=3D V4L2_SUBDEV_FORMAT_ACTIVE && + media_entity_is_streaming(&sd->entity)) + return -EBUSY; + + return __formatter_subdev_set_routing(sd, state, routing); +} + +static inline void formatter_write(struct csi_formatter *formatter, + unsigned int reg, unsigned int value) +{ + u32 offset =3D formatter->reg_offset; + + regmap_write(formatter->regs, reg + offset, value); +} + +static u8 get_index_by_dt(u8 data_type) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(formatter_dt_to_index_map); ++i) { + const struct dt_index *entry =3D &formatter_dt_to_index_map[i]; + + if (data_type =3D=3D entry->dtype) + return entry->index; + } + + pr_warn_once("Unsupported data type 0x%x, using default\n", data_type); + + return formatter_dt_to_index_map[0].index; +} + +static int get_vc(struct csi_formatter *formatter, unsigned int stream) +{ + struct v4l2_mbus_frame_desc source_fd; + struct v4l2_mbus_frame_desc_entry *entry =3D NULL; + unsigned int i; + int vc; + int ret; + + /* + * Return virtual channel 0 as default value when remote subdev + * don't implement .get_frame_desc subdev callback + */ + ret =3D v4l2_subdev_call(formatter->csi_sd, pad, get_frame_desc, + formatter->remote_pad, &source_fd); + if (ret < 0) + return (ret =3D=3D -ENOIOCTLCMD) ? 0 : ret; + + for (i =3D 0; i < source_fd.num_entries; ++i) { + if (source_fd.entry[i].stream =3D=3D stream) { + entry =3D &source_fd.entry[i]; + break; + } + } + + if (!entry) { + dev_err(formatter->dev, + "Can't find valid frame desc corresponding to stream %d\n", stream); + return -EPIPE; + } + + vc =3D entry->bus.csi2.vc; + + if (vc < 0 || vc >=3D CSI_FORMATTER_VC_NUM) { + dev_err(formatter->dev, "Invalid virtual channel %d\n", vc); + return -EINVAL; + } + + return vc; +} + +static void csi_formatter_stop_stream(struct csi_formatter *formatter, + u64 stream_mask) +{ + unsigned int i; + int ret; + int vc; + + for (i =3D 0; i < V4L2_FRAME_DESC_ENTRY_MAX; ++i) { + if (!(stream_mask & BIT(i))) + continue; + + ret =3D get_vc(formatter, i); + if (WARN_ON(ret < 0)) { + dev_err(formatter->dev, + "Failed to get VC for stream %d: %d\n", i, ret); + continue; + } + + vc =3D ret; + + formatter_write(formatter, CSI_VC_PIXEL_DATA_TYPE(vc), 0); + } +} + +static int csi_formatter_start_stream(struct csi_formatter *formatter, + u64 stream_mask) +{ + const struct formatter_pix_format *fmt =3D formatter->fmt; + u64 configured_streams =3D 0; + unsigned int i; + u32 val; + int ret; + int vc; + + for (i =3D 0; i < V4L2_FRAME_DESC_ENTRY_MAX; ++i) { + if (!(stream_mask & BIT(i))) + continue; + + val =3D BIT(get_index_by_dt(fmt->data_type)); + + ret =3D get_vc(formatter, i); + if (ret < 0) + goto err_cleanup; + + vc =3D ret; + + formatter_write(formatter, CSI_VC_PIXEL_DATA_TYPE(vc), val); + configured_streams |=3D BIT(i); + } + + return 0; + +err_cleanup: + csi_formatter_stop_stream(formatter, configured_streams); + return ret; +} + +static int formatter_subdev_enable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + u32 pad, u64 streams_mask) +{ + struct csi_formatter *formatter =3D sd_to_formatter(sd); + struct device *dev =3D formatter->dev; + u64 sink_streams; + int ret; + + sink_streams =3D v4l2_subdev_state_xlate_streams(state, + CSI_FORMATTER_PAD_SOURCE, + CSI_FORMATTER_PAD_SINK, + &streams_mask); + if (!sink_streams || !streams_mask) + return -EINVAL; + + dev_dbg(dev, "Enable streams: pad=3D%u sink=3D0x%llx source=3D0x%llx\n", + formatter->remote_pad, sink_streams, streams_mask); + + if (!formatter->csi_sd) { + dev_err(dev, "CSI controller not linked with formatter\n"); + return -EPIPE; + } + + guard(mutex)(&formatter->lock); + + if (!formatter->enabled_streams) { + ret =3D pm_runtime_resume_and_get(formatter->dev); + if (ret < 0) { + dev_err(dev, "Failed to resume runtime PM: %d\n", ret); + return ret; + } + } + + ret =3D csi_formatter_start_stream(formatter, streams_mask); + if (ret) + goto err_runtime_put; + + ret =3D v4l2_subdev_enable_streams(formatter->csi_sd, + formatter->remote_pad, + sink_streams); + if (ret) + goto err_stop_stream; + + formatter->enabled_streams |=3D streams_mask; + + return 0; + +err_stop_stream: + csi_formatter_stop_stream(formatter, streams_mask); +err_runtime_put: + if (!formatter->enabled_streams) + pm_runtime_put(formatter->dev); + return ret; +} + +static int formatter_subdev_disable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + u32 pad, u64 streams_mask) +{ + struct csi_formatter *formatter =3D sd_to_formatter(sd); + u64 sink_streams; + int ret; + + sink_streams =3D v4l2_subdev_state_xlate_streams(state, + CSI_FORMATTER_PAD_SOURCE, + CSI_FORMATTER_PAD_SINK, + &streams_mask); + if (!sink_streams || !streams_mask) + return -EINVAL; + + guard(mutex)(&formatter->lock); + + ret =3D v4l2_subdev_disable_streams(formatter->csi_sd, formatter->remote_= pad, + sink_streams); + if (ret) + dev_err(formatter->dev, "Failed to disable streams: %d\n", ret); + + csi_formatter_stop_stream(formatter, streams_mask); + + formatter->enabled_streams &=3D ~streams_mask; + + if (!formatter->enabled_streams) + pm_runtime_put(formatter->dev); + + return ret; +} + +static const struct v4l2_subdev_pad_ops formatter_subdev_pad_ops =3D { + .enum_mbus_code =3D formatter_subdev_enum_mbus_code, + .get_fmt =3D v4l2_subdev_get_fmt, + .set_fmt =3D formatter_subdev_set_fmt, + .get_frame_desc =3D v4l2_subdev_get_frame_desc_passthrough, + .set_routing =3D formatter_subdev_set_routing, + .enable_streams =3D formatter_subdev_enable_streams, + .disable_streams =3D formatter_subdev_disable_streams, +}; + +static const struct v4l2_subdev_ops formatter_subdev_ops =3D { + .pad =3D &formatter_subdev_pad_ops, +}; + +static const struct v4l2_subdev_internal_ops formatter_internal_ops =3D { + .init_state =3D formatter_subdev_init_state, +}; + +/* -----------------------------------------------------------------------= ------ + * Media entity operations + */ + +static const struct media_entity_operations formatter_entity_ops =3D { + .link_validate =3D v4l2_subdev_link_validate, + .get_fwnode_pad =3D v4l2_subdev_get_fwnode_pad_1_to_1, +}; + +static int csi_formatter_subdev_init(struct csi_formatter *formatter) +{ + struct v4l2_subdev *sd =3D &formatter->sd; + int ret; + + v4l2_subdev_init(sd, &formatter_subdev_ops); + + snprintf(sd->name, sizeof(sd->name), "%s", dev_name(formatter->dev)); + sd->internal_ops =3D &formatter_internal_ops; + + sd->flags |=3D V4L2_SUBDEV_FL_HAS_DEVNODE | + V4L2_SUBDEV_FL_HAS_EVENTS | + V4L2_SUBDEV_FL_STREAMS; + sd->entity.function =3D MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER; + sd->entity.ops =3D &formatter_entity_ops; + sd->dev =3D formatter->dev; + + formatter->pads[CSI_FORMATTER_PAD_SINK].flags =3D MEDIA_PAD_FL_SINK; + formatter->pads[CSI_FORMATTER_PAD_SOURCE].flags =3D MEDIA_PAD_FL_SOURCE; + + ret =3D media_entity_pads_init(&sd->entity, CSI_FORMATTER_PAD_NUM, + formatter->pads); + if (ret) { + dev_err(formatter->dev, "Failed to init pads\n"); + return ret; + } + + ret =3D v4l2_subdev_init_finalize(sd); + if (ret) + media_entity_cleanup(&sd->entity); + + return ret; +} + +static inline struct csi_formatter * +notifier_to_formatter(struct v4l2_async_notifier *n) +{ + return container_of(n, struct csi_formatter, notifier); +} + +static int csi_formatter_notify_bound(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *sd, + struct v4l2_async_connection *asc) +{ + const unsigned int link_flags =3D MEDIA_LNK_FL_IMMUTABLE + | MEDIA_LNK_FL_ENABLED; + struct csi_formatter *formatter =3D notifier_to_formatter(notifier); + struct v4l2_subdev *sdev =3D &formatter->sd; + struct media_pad *sink =3D &sdev->entity.pads[CSI_FORMATTER_PAD_SINK]; + struct media_pad *remote_pad; + int ret; + + formatter->csi_sd =3D sd; + + dev_dbg(formatter->dev, "Bound subdev: %s pad\n", sd->name); + + ret =3D v4l2_create_fwnode_links_to_pad(sd, sink, link_flags); + if (ret < 0) + return ret; + + remote_pad =3D media_pad_remote_pad_first(sink); + if (!remote_pad) { + dev_err(formatter->dev, "Pipe not setup correctly\n"); + return -EPIPE; + } + formatter->remote_pad =3D remote_pad->index; + + return 0; +} + +static const struct v4l2_async_notifier_operations formatter_notify_ops = =3D { + .bound =3D csi_formatter_notify_bound, +}; + +static int csi_formatter_async_register(struct csi_formatter *formatter) +{ + struct device *dev =3D formatter->dev; + struct v4l2_async_connection *asc; + int ret; + + struct fwnode_handle *ep __free(fwnode_handle) =3D + fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, + FWNODE_GRAPH_ENDPOINT_NEXT); + if (!ep) + return -ENOTCONN; + + v4l2_async_subdev_nf_init(&formatter->notifier, &formatter->sd); + + asc =3D v4l2_async_nf_add_fwnode_remote(&formatter->notifier, ep, + struct v4l2_async_connection); + if (IS_ERR(asc)) { + ret =3D PTR_ERR(asc); + goto err_cleanup_notifier; + } + + formatter->notifier.ops =3D &formatter_notify_ops; + + ret =3D v4l2_async_nf_register(&formatter->notifier); + if (ret) + goto err_cleanup_notifier; + + ret =3D v4l2_async_register_subdev(&formatter->sd); + if (ret) + goto err_unregister_notifier; + + return 0; + +err_unregister_notifier: + v4l2_async_nf_unregister(&formatter->notifier); +err_cleanup_notifier: + v4l2_async_nf_cleanup(&formatter->notifier); + return ret; +} + +static void csi_formatter_async_unregister(struct csi_formatter *formatter) +{ + v4l2_async_unregister_subdev(&formatter->sd); + v4l2_async_nf_unregister(&formatter->notifier); + v4l2_async_nf_cleanup(&formatter->notifier); +} + +/* -----------------------------------------------------------------------= ------ + * Suspend/resume + */ + +static int csi_formatter_runtime_suspend(struct device *dev) +{ + struct v4l2_subdev *sd =3D dev_get_drvdata(dev); + struct csi_formatter *formatter =3D sd_to_formatter(sd); + + clk_disable_unprepare(formatter->clk); + + return 0; +} + +static int csi_formatter_runtime_resume(struct device *dev) +{ + struct v4l2_subdev *sd =3D dev_get_drvdata(dev); + struct csi_formatter *formatter =3D sd_to_formatter(sd); + + return clk_prepare_enable(formatter->clk); +} + +static DEFINE_RUNTIME_DEV_PM_OPS(csi_formatter_pm_ops, + csi_formatter_runtime_suspend, + csi_formatter_runtime_resume, NULL); + +static int csi_formatter_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct csi_formatter *formatter; + u32 val; + int ret; + + formatter =3D devm_kzalloc(dev, sizeof(*formatter), GFP_KERNEL); + if (!formatter) + return -ENOMEM; + + formatter->dev =3D dev; + + ret =3D devm_mutex_init(dev, &formatter->lock); + if (ret) + return ret; + + formatter->regs =3D syscon_node_to_regmap(dev->parent->of_node); + if (IS_ERR(formatter->regs)) + return dev_err_probe(dev, PTR_ERR(formatter->regs), + "Failed to get csi formatter regmap\n"); + + ret =3D of_property_read_u32(dev->of_node, "reg", &val); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to get csi formatter reg property= \n"); + + formatter->reg_offset =3D val; + + formatter->clk =3D devm_clk_get(dev, NULL); + if (IS_ERR(formatter->clk)) + return dev_err_probe(dev, PTR_ERR(formatter->clk), + "Failed to get pixel clock\n"); + + ret =3D csi_formatter_subdev_init(formatter); + if (ret < 0) + return dev_err_probe(dev, ret, "formatter subdev init fail\n"); + + /* Initialize formatter pixel format */ + formatter->fmt =3D &formats[0]; + + ret =3D csi_formatter_async_register(formatter); + if (ret < 0) + goto err_cleanup_subdev; + + platform_set_drvdata(pdev, &formatter->sd); + + /* Enable runtime PM. */ + ret =3D devm_pm_runtime_enable(dev); + if (ret) + goto err_async_unregister; + + return 0; + +err_async_unregister: + csi_formatter_async_unregister(formatter); +err_cleanup_subdev: + v4l2_subdev_cleanup(&formatter->sd); + media_entity_cleanup(&formatter->sd.entity); + return ret; +} + +static void csi_formatter_remove(struct platform_device *pdev) +{ + struct v4l2_subdev *sd =3D platform_get_drvdata(pdev); + struct csi_formatter *formatter =3D sd_to_formatter(sd); + + csi_formatter_async_unregister(formatter); + + v4l2_subdev_cleanup(&formatter->sd); + media_entity_cleanup(&formatter->sd.entity); +} + +static const struct of_device_id csi_formatter_of_match[] =3D { + { .compatible =3D "fsl,imx9-csi-formatter" }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, csi_formatter_of_match); + +static struct platform_driver csi_formatter_device_driver =3D { + .driver =3D { + .name =3D "csi-pixel-formatter", + .of_match_table =3D csi_formatter_of_match, + .pm =3D pm_ptr(&csi_formatter_pm_ops), + }, + .probe =3D csi_formatter_probe, + .remove =3D csi_formatter_remove, +}; + +module_platform_driver(csi_formatter_device_driver); + +MODULE_AUTHOR("NXP Semiconductor, Inc."); +MODULE_DESCRIPTION("NXP i.MX9 CSI Pixel Formatter driver"); +MODULE_LICENSE("GPL"); --=20 2.34.1