From patchwork Tue Dec 17 08:43:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 13911398 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2089.outbound.protection.outlook.com [40.107.21.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 857AA1DE4E4 for ; Tue, 17 Dec 2024 08:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734425061; cv=fail; b=UIMTYJZb8HKrsIBHoS1842mGJt+rbZC70dt9jj2UVfQCW+XMrqgNlJWJdtyrPPkuspHm57J1gNlQruFuPU7EVwOn5GBAUYxQ5goPma8ts/khSoBWvVmF+9PaNE+F6cHJlCR+MG8qI6e2awdn60UO9ePTuYFf2EVoYZ5ZlyhdZy4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734425061; c=relaxed/simple; bh=5MOyojSpqwX11IxVjOOF9R2GXBqPmMiF2EXNPK+MRjw=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=KLDtGsYMRJrjmJP5UaqXzh9rtMMOCSv9Vp+0hnlwPAGHCLEx/wEjm0wyaj/a5GZQPlXGWpIY5sT1/iX2cMWVIK3qinSIwCcyzuRRdMTd889bnqrSUYmEmw8KYi5gpaHHcZSZe7MBEWjUq+47GGGqt51y1a5WI2Au2/farNo+XVU= 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=R6qu6BQA; arc=fail smtp.client-ip=40.107.21.89 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="R6qu6BQA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BwfK/m5+XntlAXsSFZehDrQykky7ePIQMybzj4/pSmtfW9iaQSPslo7eujb0dkFrRXmMsDylUYvrZ8HpIuzT67Ej/mRTgh+2IIEJ6BTQgdIR6XbLB4Lbd5oJwzy+Y7sM/pwWWz2rUJl6YsijOqziwebux8GvTzJse9cynJqx+vcobkvxi9DoxUNx0DSiCGvjw5zfKirR8VDTVAuwaU3MIAP+qX+VScwA64+fo6rk4u0SZLDSp4REJIn0eFftwJgWH6DKXSNTYjW0QMoezN7dMe61cIRiXvehrQgApkV2O/je/6t64DZKk/jK/vG8pFDC8GTzqPRPb8NqozJjJ3AQbw== 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=GKqYYMZ0dll4o/xlOunswmWr380CZWxAgBUCCt5iNNQ=; b=mTM5KjJ2mkiJ3eIAfDhFBZnbGNf2s+iNGVg63SByuZOYk/c5247bZ9jnpoucDdgD+N+M9aNgcMrITRZ1IGR1AT6tTAi2kidFuwubldk9bKXeuUWcMARw5v0ZVCvKU/dpS9JfGRUuRzPTR/rwGECBGe0ouJEKtUFBvzJO2m5DEXJeAjISs/bRfnv00DK+SPm31tQEgUuDlSTjsP0kGw5UNcV7cK9yAtajealsEG4T/n4Zxs+2XxOyfGAzQbuXW/pTC/B9aSUDRIpgBHz/TMU2f/4dHvj1ap8KLb03/p7KYFKbXh9ksGo14NW3wB9Tf1sFidec/lwWmhijpZMnYX56Ig== 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=GKqYYMZ0dll4o/xlOunswmWr380CZWxAgBUCCt5iNNQ=; b=R6qu6BQA0E4lTCDK7J+NEHqEUd12geavQuPe7s59mD/AZ0gqPv2lnrGV2G18IDDQfwMDSOLrHxLsPf4wkUJjeLEQuAwePst8eEplN+eaWW8sMglcDPd8bfX5kXXwVjO6QCwkK505KQy0ARGDa51Z1hFc/HX/vLU2wjuFG1/ftmyN46anwwt8c8/U9IvJXb9rK+McdSICcRcI0rsEjkns18wyq/972qTrX5D2zm+FnxruPpkX+LPh64Wv/3hdYylTMfEw6k6zuEaRwWs8KGBDKFxwLfexhn8cmYsFLR/Sg4MCi0Z5mVBuO/LQYwCUDuAwG313H6c9PBl4am0V0gSfbQ== 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 DU4PR04MB11054.eurprd04.prod.outlook.com (2603:10a6:10:581::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Tue, 17 Dec 2024 08:44: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.8272.005; Tue, 17 Dec 2024 08:44:16 +0000 From: "Peng Fan (OSS)" Date: Tue, 17 Dec 2024 16:43:37 +0800 Subject: [PATCH v2 2/2] nvmem: imx-ocotp-ele: Support accessing controller for i.MX9 Message-Id: <20241217-imx-ocotp-v2-2-3faa6cbff41b@nxp.com> References: <20241217-imx-ocotp-v2-0-3faa6cbff41b@nxp.com> In-Reply-To: <20241217-imx-ocotp-v2-0-3faa6cbff41b@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=1734425027; l=9112; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=Piq5sVdSYED7IC9ZoL2zyr8SbeoLnUS3/Uj4YKL+I/Q=; b=8YC/hCOExDRy9NMJVOiQc3ikw5yJ4NVB90QaDnT7diUdsN3WCnhGPiC0BFQN3UredBaUr9aof RrCalOAjU0AAMrTIqSI+wWAg/mUXvPWHzoUioN2anUevROkcE9HSVmD X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR02CA0101.apcprd02.prod.outlook.com (2603:1096:4:92::17) 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_|DU4PR04MB11054:EE_ X-MS-Office365-Filtering-Correlation-Id: 95b1b9eb-0918-474b-a349-08dd1e76fd99 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|7416014|376014|1800799024|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?acc3unHYZf/F9BDJObLggukPtHHdBYm?= =?utf-8?q?hJvLvG+7Qbz+SQ12SwOjeBFkKus1LR0+h4+Tue5FaYEI5xf7JJLyohmXAR1ubbjkt?= =?utf-8?q?V4KRNQoSzrIiaSg89KhxZjnIMdHrAGZnK+gk+XZTuXO6FRovLOepZLhe9MLWkeRgx?= =?utf-8?q?igt3RZ5+5Y613AKpK3nCP0EEiPKr+dkCZF0dbkW1lKosBdWmntSpt/+IJc8nXgqFm?= =?utf-8?q?33cJ407o27mmVrrD7Z/JxDrK9f+xVFus2Ulubh7KS5+K4FT/+ZyxSR9zc53gCT1Tf?= =?utf-8?q?+HqC38yNjKz76oSc4BPq7McbYvsBHsRQoD/U/kUxKfW+1H9D44JJR9LLGRPvigayI?= =?utf-8?q?J4XlTEPkWhjQO/ejBFbgnHet5u8avo6/l8oSD9s4EPzxoAH0vmQXTBMXj0yH4WUuH?= =?utf-8?q?Dkxn0EeidYHEJfzg54xU3VGOY6MiJ+uwOIM+GeM41HFNz1CnMzgbePPzKuu6+WQAB?= =?utf-8?q?G0D6VOzgE6wnWhP+uEavLISn7Zx7CfBDv4YNxefWY9LUyW3UX4tXXHnNjJHKrClZI?= =?utf-8?q?Nvo/gAFSBsyIXgIfLYWT8wZEhmGQGFID9YsO3FDjNjjvx5dThHDnXgEPnz5sXjfhY?= =?utf-8?q?eYTE+h7RWOnc5eK+0OVFvA45Nc3BYhkN45npQso6wQKKbQn11Fge8tSS5uscqvfND?= =?utf-8?q?jWPK8pdFEueMdTgC8VkDBOerGgL4qBjAGxRxO7sKqPwzPrtX5IHLLLkqo8JpLDasY?= =?utf-8?q?rob0GC7ClAZxtULyVnZbYemo2M21jwcQinGx3Txg6NL1Bm7ZlhhWyX0WomrEJIHZC?= =?utf-8?q?1CBuynBTvkrncUreJAeS3UnaxTric9/k8eVJ+oQMU/SdAz2BxTObbSv04X8EeM+Go?= =?utf-8?q?o6bEl5bdvOFDwqNBu+wG3xzYLbhiYshbBVYPFpPMY6mFCPZktlz4pii2p1B85sAr2?= =?utf-8?q?pQk5e1y+J1EC6w1668QmBoYjLUU6pGnUnz3HEkg+LupWE8rKfkpnb1iy4yd0s7+w5?= =?utf-8?q?hBrP2KfyUt+8hsINSo+SRA/wvvXxu2gNR1fxq2xktXQ8JVgWXe3zDJVk0YF7nkZ4C?= =?utf-8?q?ydwl0ETO2irbI5fuj0ygIogAVomXOuB0zWO3YrA/RLak910uns+1y2FpcKgR9yOK1?= =?utf-8?q?s2tdksrCOz/6fHsBI1yaAOVkZ3TAPHEf5lXrwVK4o9t07TAybuaVNcyqJ+i0EsCdj?= =?utf-8?q?Gamiv39d8bVBwAgqWEwKYDAEzSgV5yj8FXhdLIp9l6Zv5OfugYLF9IInMJKkkbnt7?= =?utf-8?q?xwDTK+WJ8oKpgYTkxIHmcoVOb97oOWJxJYVNiXJfcscNRT4SfRkC+em8ijfoO/uIr?= =?utf-8?q?BgERR1tSmdl9BErKKHE49sIAhIPGYSsVX5OgRPcfX3FU+Ip8df7NfZLKGwVgzz7X2?= =?utf-8?q?AsF1+Z/DfV561ngtK0iaXyAJKCHG+3yD5TInRHVFs6uV8+EOtiYM3WB5u6BhlBq8r?= =?utf-8?q?hY4oLXHECo+?= 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)(7416014)(376014)(1800799024)(366016)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?DyWjh/7PWw1MxIY5eoSUkuemNLDh?= =?utf-8?q?h6l8CG7KB6mvfzb0c2weY5BFGLF3IrzNbMAJ+6DimGFI5qyuhMikVxD45rJHq4A99?= =?utf-8?q?rPispkhJ0JbR0mbP6Fj1I3jxJ2aZepss5dHcLiq7HENXysaVM8Ki+vQswcn5Bskfa?= =?utf-8?q?Jq7BfKPJTfVlKEzsfxATcnV5O3AIga4XBtPQ5oF4csMR92ZUlBxQWGfLeqq3Is6VW?= =?utf-8?q?BKb/A5lfcNu4hUqppW7CwG1DtWvjVnwZiuZLGEHPOblpcFFXiB1dCjXFuB0se7go6?= =?utf-8?q?ozpefIEAblVg8QZJCfveo5vMpoTrDAa7TL9DEiUuUsmbEbRi/sW0E9CMB5gdWCdqR?= =?utf-8?q?eDkm+jqoLxWRt6p/U54U5JihXHdfjm8kPSCGanGgC7ITKmrWvVTHHU3QXMAlVv8DO?= =?utf-8?q?sjXJnJiN3dFGIep4n2Tyrnw0Sg3UkAYFdjx1U+YG5IarvPWbV3r0lq/RDfn4DQ/ZD?= =?utf-8?q?DLFf3So3DB1DwDhI6Rqx9duzmRpVRx7KMwGvK/ryXj2NSNOKzYfrMsF6dsw5xczeD?= =?utf-8?q?Gc273y2IX+lq9ILa/On15Z9bbpNgWdTsRGj7UvqoR+Jy4ob3OSN/3I4Kcq3YAMzmg?= =?utf-8?q?RUM+D5HaAAtRQGkcx5E9Q/mapW7iqWNVdGK+9XqMBfZgowBEocw+RlYNF6ofHUlK0?= =?utf-8?q?8+vHwGaDtJtX/SsGP+4Ne3voyZHRqMVGL2ADObLAQF9tu/X2QRQP4LiLKEXqrWKSA?= =?utf-8?q?YHnDu1XDaEttAJAFf0m2r5c6jHqEvR6ry/AiJAWx2tw67Xu3CC9/sg98AdfSNh4cR?= =?utf-8?q?I+3ChDYVZ///YNcFofPP/lCFXdrgToLtB9ha83b6iIPDBBSYtLgNocbOR8ZizhD2L?= =?utf-8?q?OfBr4wbBehLrI1nl46HS8KPW1u4bUQBnyx/XoffK9mDWD4I/iW377KjF6w3D+IWlN?= =?utf-8?q?t3yOuxIHeIFK7/cP3T89tgwU76puas+7+mqgTv6/L455p7ys1Fedyi0nUWO68skDz?= =?utf-8?q?Pi/9JXyFsXFI8kpvJ7KNBziQVn6l4hkez3ksRTtUtvVo9DWRzhiNCb8ZZo6N+Aq1J?= =?utf-8?q?34K5IDHcWpmOFd9iMbs19d6/knf/yADl6CoLAk18od4L4gjeFrSefYmdUvY+ET0zq?= =?utf-8?q?GRmKwBAQSrWzFDag/BmuTf6ibVGa18T8H9tHW1v5QFYqRJrlLqOIqrB+AZN4Dej17?= =?utf-8?q?VHpYShVBdc/MvFhNznxMZS8Zt+o4lgA5u/ohGU7m/IzS5EMP3QuC79XlVTqm+vmvg?= =?utf-8?q?/0kJlSozH8V1Jg5/vwIqn0B1nLWMWDMXQZ/VNBk/elv97s5quVPr+yPdDLgg+Av18?= =?utf-8?q?t+LHLSZeE0qj+VfoYDV6Pjs05VQth68+PUbSNIO31vS+ftPkSpFPm6WGUG6iBJGQc?= =?utf-8?q?RfrjtcrxkDqlpfzACqOAUaumFc+/ugnZ6mC6Klg4A6/ACftbl9FGivmUlSC5fXOUd?= =?utf-8?q?wro13s+6gFKQuXJjmOOahvpPoAXDZkvUj/YHnyWAR+8jOUMyJPZOiwTNUmEXfwUmL?= =?utf-8?q?u6cUPziRDqYiCXHVW1JEzT/GJi+c93KdOrTn7K+mXaVVEet8kn16lg7huqrDQrKrx?= =?utf-8?q?7QE2OHDFakIj?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95b1b9eb-0918-474b-a349-08dd1e76fd99 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 08:44:16.7753 (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: 5asnvvcSVRa8o8vgOdX4Kri9UnBD8FFXQHhWRKK2sNv2GOcoty8VIvb/k/2b1fGVW9mk7GtgxnHzHFWyeWVxnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR04MB11054 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 | 184 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 183 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index ca6dd71d8a2e29888c6e556aaea116c1a967cb5f..2c7b698ae4da0ec22eeeabf4ed35d1b703771f6c 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,97 @@ 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 *root __free(device_node) = of_find_node_by_path("/"); + 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; + + /* This should never happen */ + WARN_ON(!root); + + 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, root); +} + static int imx_ele_ocotp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -161,14 +270,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 +321,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,