From patchwork Thu Dec 12 08:24:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13904801 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2045.outbound.protection.outlook.com [40.107.20.45]) (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 8F8E520E336 for ; Thu, 12 Dec 2024 08:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733991921; cv=fail; b=QVCEbQJ0OZahgtUfe6XZAu83jEOn3a2HevsU9v7ypb2Q/75dX+9GSJaWf7Rxn53OopaHJltXscOVX0/7xVSA9NBWesOoTinXHDtQELLnwc6QaaObOPf04JwaY7e3ibcOz4X6AEJfCttBOXx2oZSJlaVFF0UVflEV/jsfXd75Z2E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733991921; c=relaxed/simple; bh=TyGpyZTm37NXXz84SrttT6osI57F50HtEIRR9STVsZA=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=qpBYx8SITXkprsx2hAODA0GPJ8Djkea1TLihSVG2MU2PDlEozj5Npy0HvLS8vGUxiw0GrnQKzo/DD4DMAz3K6/W6wx3dqh5z0ihXpd6AQ0BSYoCGspjep92RSQY5pCgT6U6S7SeCYI9Ktpqp5+92Qyf1lpzMsy+YI7qZXUtSoiY= 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=lM6jTjgU; arc=fail smtp.client-ip=40.107.20.45 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="lM6jTjgU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rJ+pqdOWTzwD20YEzsQyAZmhn1bsrwjeTTZXqQLXPblesduHXSWRdZLBa649eGpTka88Bky0EIzVa5HwJNl1NFolafKSbMCGJiEF/Ut2fX+9Her563VySPSZA8wsF5ePKwZQl9xbsO2rVHcg0gA1Z9batryVqYMSLt8zrXLCPNqT7RKW+uQzk3qDSsLaRcNwtNSN6IPG1Wo076+JmHgy3OC1RfVD9FDxpjl/bpehwha2kizMwi3z2B8glsB8zEWTqn5/DF5xSDq62xFfmIfOIlggXhvYtpQKITWHHQnMaBkMQrVBkPfcQN2rjWNBvl0u7D0rQwRQNgKRl5jKBwCwJw== 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=9/GwGoEswcMwP6dImfpCh/5bROjzZhO2GB4Bj2W/jlo=; b=meTteteMdj5+hzNOtNC3KA7B3TZ6fFPROUgarcR6/3I4rjXmyAmlCOpQxidyoWpScFAsfZYHtpFep2N/bDveW7ys/b0F7/s3O9QAhnrxIJ3AQIl7svX5xJ6ZEjpi9C1jvyX3ehwSJj4dF0ieC4g5GXjJvP4qPv2M1FkjcsUWgzBuPM2MujxukaukE7dbO0e9nXwPiiUvjm3XFAwLCibEF2xm6Q2qk6/E+SPLdfVXi6ioSgGxd/twpetvQ2oGLWHBUSJdILQfmtpCcfK+kbTvpIjFDYRMYTJKdnZ3qIiCGaqHyLrfMvRzjVMTk8eOP38I1DO6vYhORWlV+X+MLzismg== 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=9/GwGoEswcMwP6dImfpCh/5bROjzZhO2GB4Bj2W/jlo=; b=lM6jTjgU0oz8H9xkynsFrsaG2tCH+iKI9u5r5wzAla8+OUXDtu923GWVDuYNTkIlqV6vFmbkoV6iNM8K2COtlyc0cpRj8zCplLri7g5cKd5Z5csIutyRbmEIFBpe97dfcHf7u/TizolYJmhlOgNS4pSM/owr6vf2i/rKt1woXS2X13ipXvSkeHp6AjPXCIv5BHjxCCVFocdgyFcgalT/MvQ55VF6m5Pyygsmf1PBCXBuRGVAPpA4X34nfQ1d7Q2tMDF4VBIIk9pvemd6G4TbnyrszaZtbEqaUec/BSLusTgJj+7RCCv8KYB3jWtGO363MSTK+DFrW9OMPPgGs0QRmg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by PR3PR04MB7323.eurprd04.prod.outlook.com (2603:10a6:102:88::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.16; Thu, 12 Dec 2024 08:25:16 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%5]) with mapi id 15.20.8251.015; Thu, 12 Dec 2024 08:25:16 +0000 From: "Peng Fan (OSS)" Date: Thu, 12 Dec 2024 16:24:42 +0800 Subject: [PATCH 2/2] nvmem: imx-ocotp-ele: Support accessing controller for i.MX9 Message-Id: <20241212-imx-ocotp-v1-2-198bb0af86a0@nxp.com> References: <20241212-imx-ocotp-v1-0-198bb0af86a0@nxp.com> In-Reply-To: <20241212-imx-ocotp-v1-0-198bb0af86a0@nxp.com> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Peng Fan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733991891; l=9171; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=VGXYDR2iua2/vwS9AThGTtVqrYdCN7AqMGAxlsDi9cU=; b=CsG0WjWARWk592cZJjm36SheQz5QUOMXSOIlZ2v/0BMSfBqGJ5maR0G6vRpygPO8Y6AKFUzWE 2GXHFUFFbW8CaItf0ucA3xxiC8GMJESpDqlbIuJYSc7ytvbCqG9+CPX X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI1PR02CA0033.apcprd02.prod.outlook.com (2603:1096:4:1f6::14) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|PR3PR04MB7323:EE_ X-MS-Office365-Filtering-Correlation-Id: 94a7a820-8829-4131-8b30-08dd1a8681c1 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?gBX4Am7NNMhnIYaCtQrKV1s9Zw8yHVV?= =?utf-8?q?+5Z3FqMt68wmxcQv2CoCzJ+b7/o01R0kPg+ZoB7s9JiUoCpSdjHO+m32Gyg9UDx8A?= =?utf-8?q?ej0KQUHuZ+6HjOrIdc3DjanUv+LVTTPWyrEEBlJN03H9FJEhLh7JxdMFTOolOCiPf?= =?utf-8?q?tk1NbbAk3KnPsxrqcT/VCv4bJJYIsQST9TOy46YwLqFq27V2+9pW+SjOlar2DAhTL?= =?utf-8?q?7aKxKsqt4PQA+QFfdVMLGgP1dF9Bfs9K/rlTtq/P+p14dmAG4yc+VXXfQt4HD7ggb?= =?utf-8?q?zEVyuklteHGYb1yYY+FTFfW7mBvbiCDlClhauLruiIlCkgEbS+eS0gFdgvOZDEF3m?= =?utf-8?q?aCdWPwI5BfldYRJ+yCj61X3ONPHvRgSTWS6Twg28LOKLABG1WBU92c7vzEF4E04q0?= =?utf-8?q?wGckeLgpcWg8yTZkfV7pkBzgT397d3S2/umxHqtxfOPa/+wEbCdlpIv/yLVUTfBgE?= =?utf-8?q?Has4no5uYLLvRiztca0kucMOhEfZBMeDNHa8bttL7uTQUgBQLV3NuIBbCl3R/z2+g?= =?utf-8?q?d723X5NJGgc1NIeyZD7hyoaQhhJVOMB1fCxljK2WMRcGvs7P3+g/JxlhXfb95YXdf?= =?utf-8?q?4yCQMPBtdObRreLY5YC9r1oZaBjOu1XYy+TEpeAIw0u4XxNwGPzJ7/bVRQBD8+izy?= =?utf-8?q?GYZap2FeO/RsARHpoWavm0Ag/hc16ehhchxGZOgkg2QSxiGYi6gfldfrYA3DT66zi?= =?utf-8?q?BoLHwFUVPoaZDGT36UcfZoGahbKSOljcPpMWQMBlXXaC1Jnlaj05/Z25tPQRqdLSl?= =?utf-8?q?ndxKptZQwbFN5o60DFrLdfrFJLZ1S13gZCX/tgvMOXrYVY8L5DIUk+IipIuNUzBzW?= =?utf-8?q?cvcu6/N/aVQhurpM5GlE7CUI0N64EHBO28qqniwgvjvbi0tDgGkFFgdUqSBT/6ovX?= =?utf-8?q?LeFpSmRY2dimwaEbXZHBALinPL5KFhZRXaCrZ3tmEtEgNQTL0zDqNVPGZmUzo/3ho?= =?utf-8?q?Yrf5t2beNG5rS9qaKnJr5kyQQJPvocZ3S6LHRXQPNKOp83XJNEdREgWz53EfKZ9a3?= =?utf-8?q?dye0twvQjkWLn4k00NXVCkBwYoWxoQJ/y1TgMv4p4uEh5k5EBFK4loRJ/diarkP25?= =?utf-8?q?AObcQPNbXOEJfixapyxDZXsvw5cOR1oiMA+pBxlMPBJ17hq9YleOAGGwp4dSncBGe?= =?utf-8?q?YMWpqB8nxz1pV/d0Rg5cT2iTdLsKPzVMSoN7bn2c8r7fndAd47SAv3yE+WVD3hrgm?= =?utf-8?q?/uz8+3pU1Nl17EoutAsOC7lf7Gjxz47X1P3vInRIk/VpF3jeWH022Xlt5GoQ6bbjb?= =?utf-8?q?98SmNxfFW0jSPvnk1QgfiwiiUpPNJNaPl1COVsWb3sDPjCGgEgi/+RNh+8WlUgWZG?= =?utf-8?q?KeDca5ejnI9Z0WMlHGiW6vVDn5RR8BY6ew=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8459.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?aQqsRR4JgAyJ9jftRNf6otS3eozQ?= =?utf-8?q?X15ao4YNk7+r3gdWmEzhWrdrNYfH9kXFTq/N5F6xeTwxZ5RFeoDc1hyhBDKBBKjmP?= =?utf-8?q?+81vXGrc4k9q9x7d36Cbd0qU3v47CHhLcE3oXjpSMyKi5umFgm+WfocnfUsvsX1yV?= =?utf-8?q?FTNU6++QzhSqetUZw3wBNEZ6CLsTINzY3JNk6M/34f39DLaml03HVIYFp9lsOAOJF?= =?utf-8?q?JWXuXJh8wztQcoijpUqOm8uPEiVrfnmLP/GF+2pVTu8u4U16+OaofQYd0UKt3Tjf9?= =?utf-8?q?U67imjIYf3ea7gLGh0zgAYj2V4vpf55c+CT1sd9MAXTUOYG9UV6mTRBCGKow+HJfT?= =?utf-8?q?gdBO363HkHGGuxnmwH/kRB6FWhW7Q2r/Kw9EPnHvhYfYE/4+bA3ra8zzSMU6R5xhZ?= =?utf-8?q?MfcejvKKFdhr5nJquZzFOJ25VoaUt2Fw+gpnp20rKZMcEQ9fqsmmkwx4wUQgiKTp3?= =?utf-8?q?uXv34aapNX5RiSL5w0LYI+htvDaEOpFBp4kxONQBT/PFr4lUsEuXLjiFL05w2NhQQ?= =?utf-8?q?lYxuYSs+kV7Tz/ouCtw8RLPRHlSxNw0nCUssyI2Vgy/54VmFQslUMUfjIyc3taHKn?= =?utf-8?q?SPNP+dqU0Fm/+uW6UuFQrVn7DkQ8AfNoKkHCcftMO9ujeJRj1D3WwhiDuS3hI8WBb?= =?utf-8?q?syowLNo7VSFYwneUg2I6ML2b/BqYFCimv1RXc8g2PCJpeiyxoj9E4W5eJxyfzxYf/?= =?utf-8?q?MuWNmsbjjfeLk1z5iZUjhYNHLfyzd1ScBuL6DcuDbtqzp8zNrdUmqDvHIi7Y0zIgH?= =?utf-8?q?i3JYqJLV/PBhUUea/lyS135rOVwcb6U3uHnNtvxgVyXu8pU4gKLWtL7Y8MhTu5b2y?= =?utf-8?q?6pd2dXRSnV/bmAxBxoP4pr5GbMB2L2thoOVPexmGo76KLwxDfl+U1hZ+hppSUTjwX?= =?utf-8?q?lsi//ajjQe6I+9Xe/nYz0WdOgTP1BYElJDzvw3cAMcVCj9Se0AajN1urrDycOvCU0?= =?utf-8?q?zBYy2eBuazpY1Y0noPK2T59aTkLH5qoK/2y/7umUChX4zIYf706ohc4B/TEZ+L+6n?= =?utf-8?q?zOMsHoDwGVw0hbc78T9vmxnfTw6ukE6W82qa2CasqYNnwCner0U1YIaeQwAEYAnj1?= =?utf-8?q?JJPH8Ez225ACQTIYcmt9I68my9BWQej7hnSLor7Ej7MPNjBkWVz+tP/OprBU44pjv?= =?utf-8?q?glIyRHIcyD1Q4CBVEM+sny6+ndYfPywqXbX/XkOLVbBffE1vxN1i0+ZHJdXoEPt3j?= =?utf-8?q?i0YIqmvXR7x57QNz17BIA6Lb5Z9tqU12sZizwys8cyyxMpRtMbtlj/rr79S6T/hyA?= =?utf-8?q?Jvgnbzs3VTmZGsyxvlvxBeJmfBwitJALuXeUIbpogyl1aUBGSW23JZTMv/X6AQIBx?= =?utf-8?q?Dz+g2XCBukakQe0bY2QRqR5Z9LTZkNDrpqzToq+MjJMlZvMbLeILxH8vxwhFRwh76?= =?utf-8?q?ix1PNopIfiSgDA33ofylhLK/ej2GbTC4P3BpNNOMwwjlFflGg8Ln6+KyJCsa73kG2?= =?utf-8?q?Fvz28nM0x0YE3ffMW6wZ7MJGBlHU6r/Bd3/SdAsr4Wq1I6XhmXl6ye47szB5i1VX+?= =?utf-8?q?mewXuiDZ/Axu?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94a7a820-8829-4131-8b30-08dd1a8681c1 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2024 08:25:16.2672 (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: oMQgxAaK/BnUEtTx8bUtR2HyODgjdNjEQ7e1pBNwa+hgIsMPp5dJ5d1RqMmiLjVgnT1eCmBpxOvDW1ge9lFAUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7323 From: Peng Fan i.MX9 OCOTP supports a specific peripheral or function being fused which means disabled, so - Introduce ocotp_access_gates to be container of efuse gate info - Iterate each node under '/soc' to check accessing permission. If not allowed to be accessed, detach the node Signed-off-by: Peng Fan --- drivers/nvmem/imx-ocotp-ele.c | 187 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 186 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index ca6dd71d8a2e29888c6e556aaea116c1a967cb5f..542539b86efd2d38be2903c1d0ea72f918ff5b75 100644 --- a/drivers/nvmem/imx-ocotp-ele.c +++ b/drivers/nvmem/imx-ocotp-ele.c @@ -5,6 +5,8 @@ * Copyright 2023 NXP */ +#include +#include #include #include #include @@ -27,6 +29,7 @@ struct ocotp_map_entry { }; struct ocotp_devtype_data { + const struct ocotp_access_gates *access_gates; u32 reg_off; char *name; u32 size; @@ -36,11 +39,26 @@ struct ocotp_devtype_data { struct ocotp_map_entry entry[]; }; +#define OCOTP_MAX_NUM_GATE_WORDS 4 +#define IMX93_OCOTP_NUM_GATES 17 +#define IMX95_OCOTP_NUM_GATES 36 + +struct ocotp_access_gates { + u32 num_words; + u32 words[OCOTP_MAX_NUM_GATE_WORDS]; + u32 num_gates; + struct access_gate { + u32 word; + u32 mask; + } gates[]; +}; + struct imx_ocotp_priv { struct device *dev; void __iomem *base; struct nvmem_config config; struct mutex lock; + u32 value[OCOTP_MAX_NUM_GATE_WORDS]; const struct ocotp_devtype_data *data; }; @@ -131,6 +149,100 @@ static void imx_ocotp_fixup_dt_cell_info(struct nvmem_device *nvmem, cell->read_post_process = imx_ocotp_cell_pp; } +static int imx_ele_ocotp_check_access(struct platform_device *pdev, u32 id) +{ + struct imx_ocotp_priv *priv = platform_get_drvdata(pdev); + const struct ocotp_access_gates *access_gates = priv->data->access_gates; + u32 word, mask; + + if (id >= access_gates->num_gates) { + dev_err(&pdev->dev, "Index %d too large\n", id); + return -EACCES; + } + + word = access_gates->gates[id].word; + mask = access_gates->gates[id].mask; + + dev_dbg(&pdev->dev, "id:%d word:%d mask:0x%08x\n", id, word, mask); + /* true means not allow access */ + if (priv->value[word] & mask) + return -EACCES; + + return 0; +} + +static int imx_ele_ocotp_grant_access(struct platform_device *pdev, struct device_node *parent) +{ + struct device_node *child; + struct device *dev = &pdev->dev; + + for_each_available_child_of_node(parent, child) { + struct of_phandle_iterator it; + int err; + u32 id; + + of_for_each_phandle(&it, err, child, "access-controllers", + "#access-controller-cells", 0) { + struct of_phandle_args provider_args; + struct device_node *provider = it.node; + + if (err) { + dev_err(dev, "Unable to get access-controllers property for node %s\n, err: %d", + child->full_name, err); + of_node_put(provider); + return err; + } + + /* Only support one cell */ + if (of_phandle_iterator_args(&it, provider_args.args, 1) != 1) { + dev_err(dev, "wrong args count\n"); + return -EINVAL; + } + + id = provider_args.args[0]; + + dev_dbg(dev, "Checking node: %s gate: %d\n", child->full_name, id); + + if (imx_ele_ocotp_check_access(pdev, id)) { + of_detach_node(child); + dev_err(dev, "%s: Not granted, device driver will not be probed\n", + child->full_name); + } + } + + imx_ele_ocotp_grant_access(pdev, child); + } + + return 0; +} + +static int imx_ele_ocotp_access_control(struct platform_device *pdev) +{ + struct imx_ocotp_priv *priv = platform_get_drvdata(pdev); + struct device_node *soc __free(device_node) = of_find_node_by_path("/soc"); + const struct ocotp_access_gates *access_gates = priv->data->access_gates; + void __iomem *reg = priv->base + priv->data->reg_off; + u32 off; + int i; + + if (!priv->data->access_gates) + return 0; + + if (!soc) + soc = of_find_node_by_path("/soc@0"); + + /* This should never happen */ + WARN_ON(!soc); + + for (i = 0; i < access_gates->num_words; i++) { + off = access_gates->words[i] << 2; + priv->value[i] = readl(reg + off); + dev_dbg(&pdev->dev, "word:%d 0x%08x\n", access_gates->words[i], priv->value[i]); + } + + return imx_ele_ocotp_grant_access(pdev, soc); +} + static int imx_ele_ocotp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -161,14 +273,43 @@ static int imx_ele_ocotp_probe(struct platform_device *pdev) priv->config.fixup_dt_cell_info = imx_ocotp_fixup_dt_cell_info; mutex_init(&priv->lock); + platform_set_drvdata(pdev, priv); + nvmem = devm_nvmem_register(dev, &priv->config); if (IS_ERR(nvmem)) return PTR_ERR(nvmem); - return 0; + + return imx_ele_ocotp_access_control(pdev); } +static const struct ocotp_access_gates imx93_access_gates = { + .num_words = 3, + .words = {19, 20, 21}, + .num_gates = IMX93_OCOTP_NUM_GATES, + .gates = { + [IMX93_OCOTP_NPU_GATE] = { .word = 19, .mask = BIT(13) }, + [IMX93_OCOTP_A550_GATE] = { .word = 19, .mask = BIT(14) }, + [IMX93_OCOTP_A551_GATE] = { .word = 19, .mask = BIT(15) }, + [IMX93_OCOTP_M33_GATE] = { .word = 19, .mask = BIT(24) }, + [IMX93_OCOTP_CAN1_FD_GATE] = { .word = 19, .mask = BIT(28) }, + [IMX93_OCOTP_CAN2_FD_GATE] = { .word = 19, .mask = BIT(29) }, + [IMX93_OCOTP_CAN1_GATE] = { .word = 19, .mask = BIT(30) }, + [IMX93_OCOTP_CAN2_GATE] = { .word = 19, .mask = BIT(31) }, + [IMX93_OCOTP_USB1_GATE] = { .word = 20, .mask = BIT(3) }, + [IMX93_OCOTP_USB2_GATE] = { .word = 20, .mask = BIT(4) }, + [IMX93_OCOTP_ENET1_GATE] = { .word = 20, .mask = BIT(5) }, + [IMX93_OCOTP_ENET2_GATE] = { .word = 20, .mask = BIT(6) }, + [IMX93_OCOTP_PXP_GATE] = { .word = 20, .mask = BIT(10) }, + [IMX93_OCOTP_MIPI_CSI1_GATE] = { .word = 20, .mask = BIT(17) }, + [IMX93_OCOTP_MIPI_DSI1_GATE] = { .word = 20, .mask = BIT(19) }, + [IMX93_OCOTP_LVDS1_GATE] = { .word = 20, .mask = BIT(24) }, + [IMX93_OCOTP_ADC1_GATE] = { .word = 21, .mask = BIT(7) }, + }, +}; + static const struct ocotp_devtype_data imx93_ocotp_data = { + .access_gates = &imx93_access_gates, .reg_off = 0x8000, .reg_read = imx_ocotp_reg_read, .size = 2048, @@ -183,7 +324,51 @@ static const struct ocotp_devtype_data imx93_ocotp_data = { }, }; +static const struct ocotp_access_gates imx95_access_gates = { + .num_words = 3, + .words = {17, 18, 19}, + .num_gates = IMX95_OCOTP_NUM_GATES, + .gates = { + [IMX95_OCOTP_CANFD1_GATE] = { .word = 17, .mask = BIT(20) }, + [IMX95_OCOTP_CANFD2_GATE] = { .word = 17, .mask = BIT(21) }, + [IMX95_OCOTP_CANFD3_GATE] = { .word = 17, .mask = BIT(22) }, + [IMX95_OCOTP_CANFD4_GATE] = { .word = 17, .mask = BIT(23) }, + [IMX95_OCOTP_CANFD5_GATE] = { .word = 17, .mask = BIT(24) }, + [IMX95_OCOTP_CAN1_GATE] = { .word = 17, .mask = BIT(25) }, + [IMX95_OCOTP_CAN2_GATE] = { .word = 17, .mask = BIT(26) }, + [IMX95_OCOTP_CAN3_GATE] = { .word = 17, .mask = BIT(27) }, + [IMX95_OCOTP_CAN4_GATE] = { .word = 17, .mask = BIT(28) }, + [IMX95_OCOTP_CAN5_GATE] = { .word = 17, .mask = BIT(29) }, + [IMX95_OCOTP_NPU_GATE] = { .word = 18, .mask = BIT(0) }, + [IMX95_OCOTP_A550_GATE] = { .word = 18, .mask = BIT(1) }, + [IMX95_OCOTP_A551_GATE] = { .word = 18, .mask = BIT(2) }, + [IMX95_OCOTP_A552_GATE] = { .word = 18, .mask = BIT(3) }, + [IMX95_OCOTP_A553_GATE] = { .word = 18, .mask = BIT(4) }, + [IMX95_OCOTP_A554_GATE] = { .word = 18, .mask = BIT(5) }, + [IMX95_OCOTP_A555_GATE] = { .word = 18, .mask = BIT(6) }, + [IMX95_OCOTP_M7_GATE] = { .word = 18, .mask = BIT(9) }, + [IMX95_OCOTP_DCSS_GATE] = { .word = 18, .mask = BIT(22) }, + [IMX95_OCOTP_LVDS1_GATE] = { .word = 18, .mask = BIT(27) }, + [IMX95_OCOTP_ISP_GATE] = { .word = 18, .mask = BIT(29) }, + [IMX95_OCOTP_USB1_GATE] = { .word = 19, .mask = BIT(2) }, + [IMX95_OCOTP_USB2_GATE] = { .word = 19, .mask = BIT(3) }, + [IMX95_OCOTP_NETC_GATE] = { .word = 19, .mask = BIT(4) }, + [IMX95_OCOTP_PCIE1_GATE] = { .word = 19, .mask = BIT(6) }, + [IMX95_OCOTP_PCIE2_GATE] = { .word = 19, .mask = BIT(7) }, + [IMX95_OCOTP_ADC1_GATE] = { .word = 19, .mask = BIT(8) }, + [IMX95_OCOTP_EARC_RX_GATE] = { .word = 19, .mask = BIT(11) }, + [IMX95_OCOTP_GPU3D_GATE] = { .word = 19, .mask = BIT(16) }, + [IMX95_OCOTP_VPU_GATE] = { .word = 19, .mask = BIT(17) }, + [IMX95_OCOTP_JPEG_ENC_GATE] = { .word = 19, .mask = BIT(18) }, + [IMX95_OCOTP_JPEG_DEC_GATE] = { .word = 19, .mask = BIT(19) }, + [IMX95_OCOTP_MIPI_CSI1_GATE] = { .word = 19, .mask = BIT(21) }, + [IMX95_OCOTP_MIPI_CSI2_GATE] = { .word = 19, .mask = BIT(22) }, + [IMX95_OCOTP_MIPI_DSI1_GATE] = { .word = 19, .mask = BIT(23) }, + } +}; + static const struct ocotp_devtype_data imx95_ocotp_data = { + .access_gates = &imx95_access_gates, .reg_off = 0x8000, .reg_read = imx_ocotp_reg_read, .size = 2048,