From patchwork Mon Dec 23 00:46:14 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: 13918326 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2083.outbound.protection.outlook.com [40.107.22.83]) (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 5B07BC8E0 for ; Mon, 23 Dec 2024 00:46:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734914817; cv=fail; b=b1NqiM5tCBQGyWcBBH//3PIDOQE2rK+DSlk7G1YGxO0Z8er01oBMQUO/sPfhtJLW+eQLKiVPElIIP3b1LvUM5T2nJkNiSJL+Mw/Lbx8hiPHGGJeeBTmku7YIz0n+ezW3sGYw3+sxGkMGMc8SUyO1PdusURo3+9M+VJyCf0BFlGM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734914817; c=relaxed/simple; bh=OyVAx8Ot2y1Looj3JKF0/XHgiGUdlY/P5wEoRUxP/wY=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=mz654KpMh3mqKow7CBKnZAbEYNAUPU9fJdPgM6ddCxR6huglDclJcSjP2T+EDrzgue5swzwuj/1nQjpyjoE47/atsIomuCe3GTuEGRbR6YMYzqbO1em1/xrV+aTQv6c/3vkWII16Ap/uldbttJ8f93WawV6nh5rZ17oDkWFng1c= 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=ekn9GRg7; arc=fail smtp.client-ip=40.107.22.83 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="ekn9GRg7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uMtDbJxh0Ul+7u7M12WHhZ2WcZLV+ZHnY27qAWF+TUfwWcnD2GE8rT1aUbOuab8y9ihIZqCH2lGv+m2oWKF86uSFpsK4GkpAHV7S3jO9CHGDddI2/CVFV1XxdNxU29bcUPigAHgYY1d88dJiinQUjPJ7B0+wzsq8f+kr2FJGPlMT0BdMcqpIOOkypl//q4eCK67TSit7ksBumI3gJug+B0rihrs4tm6e4yK8s9JU9QFiP6Bh0KkaGSHrq5YnoPG/L5h/61rCfiDlE2Sj9wohAqIRu07DMICZs0KR6yKdWSvNR1DLjkbg1n2NOnwtHobVISNuxfvcpCr+Kke5W1C2Kg== 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=8xVgXFE9hKcU+iNGR3SqhVUINRKr3uSZbjYMBjDK8EY=; b=KsrVjLqnN5RrWX7QwVFBGSm/NDFBnqB/2tSL4LP8ea5xw/8X1h7IaqJ851D4QFnw4ZDgFIzJQ8G0PCEMLDqY5TOn6Dm1cgxG4s7v9iFUeiN49NctLf+aamnjH4X2Rks0cjbygnSdtq1Q6/1YUDc0PqYyS3Nac1wXuUUrl76R166LWmmo0jFgf8XIfTS5Kir0xkLeY1gS5SI8hprAn7phROhmZrrRmejG7kgCT0bnTFbeiSMaO98v375CKzWc650PWNB1vSplRYqluUFpeX8Erwazqvm71e47vsiAK91yhEl4XWmTTG0BuJYupMc8pmvS/pX13OOcrm+xYNqjHeTLFA== 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=8xVgXFE9hKcU+iNGR3SqhVUINRKr3uSZbjYMBjDK8EY=; b=ekn9GRg7KaQWV2kh9FEj+8sDecE0DhwMdtO6F9etjK65RnIHbN1362IXJgu0SJ66GbDv4THX4yAzAHmDvIJ03Kn1rNuJ0G7uyMiaQBoJRwRVCnfRV3UWhV8k8WSsnq7m2C2qRb828kjMR5hux4a28S2HpNwhx2SiIN0I3LUC1HrcRv2wj0ca4H9JPswqTYRm5GCzaxyKLICzMdqALonAf3/vB0ou0zymDzP3u9rn0s8/4V/iGnNCdwybhRcsGhBr/uouOQb7TTGvyDZx/Dm7K/Ofokc1yN/h1zKtKNjp/EjJ2ns7ZxIknqywuavUO/c/EkISBFgVjGTXnSp2p5L+UA== 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 AS8PR04MB8995.eurprd04.prod.outlook.com (2603:10a6:20b:42e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8272.20; Mon, 23 Dec 2024 00:46:49 +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.013; Mon, 23 Dec 2024 00:46:49 +0000 From: "Peng Fan (OSS)" Date: Mon, 23 Dec 2024 08:46:14 +0800 Subject: [PATCH v4 2/2] nvmem: imx-ocotp-ele: Support accessing controller for i.MX9 Message-Id: <20241223-imx-ocotp-v4-2-f504c1420640@nxp.com> References: <20241223-imx-ocotp-v4-0-f504c1420640@nxp.com> In-Reply-To: <20241223-imx-ocotp-v4-0-f504c1420640@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=1734914780; l=9121; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=ZbEz389bjgOA+PRwzrpvSDmNxc+V7u6O/SazhmHSomY=; b=DIWvOqcmT1B1oEY9szC/adot0AFABTpoq6axzNos1Gfky9UjXT/VSJecf1v/epmFOOhom7MAU k/gHMDZpqjlCOOViyCNCN8RON9cGxvQJMfAnLoh6ireQSEl599zE4wB X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR02CA0033.apcprd02.prod.outlook.com (2603:1096:4:195::20) 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_|AS8PR04MB8995:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d4df582-f941-4e3e-d00d-08dd22eb492e 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|52116014|376014|7416014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?AdtLt200LbKH0e5Ia6YlNOHaBZNQgVj?= =?utf-8?q?Ux8TA1ryXFp38ihwYrWmJUuUkq6zm0EEDWyUn1P3sPbAQV0BKPTHC3EEKIJiNc3fe?= =?utf-8?q?VTTD0WqJNyCfxrt/gFVeB4KAMc1DFdVCqTrd+ub2HaOloOH60Oye5KW8Mx3EfcQ11?= =?utf-8?q?B1l/BODZW6mzBwFywLfuI+iSyorauvo5ydg/yZNNDWXfbc5Eb7hm1cjQZ4FPy7WbH?= =?utf-8?q?2P/Qua1uby2lMYNinqF11lF8BoYWpLEjpPmgNRO4Lfe1P3rDVLo0pIto9DJbx8gSc?= =?utf-8?q?aSNykVjMZtt9TEZykDOzpgdIy6oU995t8CDdw7XxwroiEc2uNzcm2aKO9wJPtK7Gg?= =?utf-8?q?l89wabPfD7KmFP3cqQxT8zpWHG35S4ebkV7OP2dUeP+VTZaq+1Hph+/n1wYRVEmYJ?= =?utf-8?q?fYX95rRjs5giNsQM3vx5KgHA5VG7TKaI9SY9YvixT8/Cxj157mgZ4W0L54jyCeQxL?= =?utf-8?q?Y4KbwODy2ScHYeng7q4FXwvFXv9jAT2vb4Dj93+3O6VQR8c32IW1X51Vea8QUK+s0?= =?utf-8?q?uiQG8UslIveBcJYkKpST6+0XvOAcW1nQ7vTvbeLWz8iXiNA0wOsAMWtuoiInYgwfM?= =?utf-8?q?H4RE5RyzgxgT9q0lJplZRZOfqLe/a4BwNxy2XMqR/3ujOiH1F+8cYQu8MjyeBjb5y?= =?utf-8?q?sm++gLnLb8Eb/HU9kgmTWBjM7gQsHPbtyvDoZ2gNmSQeyM1e3jZarEuiqjJj/AJrt?= =?utf-8?q?j9LQz3rzdnyYpzRokj+YpfBabSfNrMbgRnEc36FDuU6HIKtN5EQRc2sX4KxXt6D2x?= =?utf-8?q?zNVv1j56Lhi0m7aDQ5Zt4Akeye+ZcLi4FxBdFS3mFUuKc110JTRmGPMyMg+BGBnN9?= =?utf-8?q?UgHoelyJ5etcL2x/7IFGLDJSTD78f5tXZHPYoRY49vZDjsA5A6DhS8qlB+UoxpZBM?= =?utf-8?q?K/FflPgCbOfY18GWaKFlg2CskagIJt4dYgHWT8OnEhKUSVcGBFq/iWHzVNIpwU1oE?= =?utf-8?q?ySJN+95ndoGKZB2URqX86lhtUht8zkIffKnIrFXNSyn2zZ2mmPIK8UAEeVT3b5xj6?= =?utf-8?q?T0LWBudSfY/uW4LHkIY5K2tZbTuH/TI+gR/a1htwymqVGThlN/qpwbuJcQiA13iyh?= =?utf-8?q?UJwKSKRONe/A2jprA4TiAKz3sarYxT1bo2Rr/eQnbRPjsK5oK8PWPWxdSvpKzywOK?= =?utf-8?q?LNG5QaTgLKI/T9WupXdUeO6b2icbqtAk5J1Jw/cLm6gep4QqhJn5svZfmySz71N0g?= =?utf-8?q?k0e64voWUwaVItIgHT5EUaemlmLmGEGT3ua/roDyMMWdG6CobThKwyo7C6Xxc2m7u?= =?utf-8?q?93A1ANgfo/iYXQWm9UB7rUEuZI3vUOVYPfBExYlp9yjDD3zGxDW8lNu0Q3/U1RDkt?= =?utf-8?q?k9oIG6fOf74nZM1MSN40DfKCLZbm3cIP5UckPTA+vKkNR0Viere1hu8QaK4i6LgX8?= =?utf-8?q?9iqefti80KO?= 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)(52116014)(376014)(7416014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?jqQ5KzOR8PMr3Vvcvhk3i9jusRBw?= =?utf-8?q?Mk+JyxMaJMs9NxzRtKp+LpznRBQLXZsKu2dph27nyCIleOaJU3DUfsyWh9rjKQ5lx?= =?utf-8?q?lWHf7ol0w8wUl6oSOkachEs25PMMP0blJGr/P8ho16BCLmVHOpQoK5Ur3yROJ4kj3?= =?utf-8?q?574t2GDIXazGLqo56+/WH4OybswKwA4K0plop4Q/igi34RjiuqxEeZ8qEA6fBt+AD?= =?utf-8?q?SOLDOL0rka1TRmDd4Kvyppyen0pJ2dy2mQZSqGRQxvs21uev7ZUAtJ5qi3nceHsCu?= =?utf-8?q?ZFdvtSZoL5wOa+a8mSzt8MF8G28So9Gfz5cMWKS+FFZ3rbldDsNjavgoXf2MGtoTs?= =?utf-8?q?vKmUADjOZN8kCeWRX61lnZqi+ZH9XcinTqlBBRtYkfaswHNXwneIBx9/YTYYDwiBf?= =?utf-8?q?RDAAcuhy8kdYYuviP/ucS9gaOF5AElAsROKN+ZIuaH0V8IN8XWdggiZl8JXPuQydt?= =?utf-8?q?u1D+0QrQd402oDr5MdLpTCr625u74QkqkLk/8KwFcMunOUeFHvz2ArQfd3+WhbsFE?= =?utf-8?q?3LdscXwS6pd/CmS5uPA5sYayQF5kp8RyHNNkMVhcYoH5NDYUgVl8Z0zB+txK8lEUi?= =?utf-8?q?Jaq1J3mC2MKQQVV10Tx3nYC+2m/uI8UPDwoMlenHjqfxIgHCsX0zxH5k38xEFXaZy?= =?utf-8?q?BY8NP2ibIzO9vaCWHTT/ckaOMIruA1rNlVGK0fNjsRIRHgPD1pPQb4bVWtG7hnTy+?= =?utf-8?q?Z7rc94tp20UEzGePOsAV6IeTBLB6VnxmmOeFFGG7191d9xRcfIFq4av9sIvjLJf1J?= =?utf-8?q?WmflOUyMVbezVbqOwhDlcBn+UkCniMZ71FeAHDrttcuP+N0zgYDDtoImSek6nncVu?= =?utf-8?q?llIPHwoWwBPahfvTnru6joQlpfz/J5/PMUGI9iLspZ3qnd0Ctz/BU4+KcWF7p3r5o?= =?utf-8?q?5Y9mgTP4Ym1BNOEevu5y4jcHRPk+0bBIkYC7pPqtcKt5W8/KceaXs5QQk4P6R7uiE?= =?utf-8?q?qcAsyhaNOPU9895AVTBA3EiGWKqod1B/bngs8wU7P8ipSUuWHldTdDf6k96iHf1FN?= =?utf-8?q?9H5vwaFA2degUuXIeqYzqvFTCBLZnioDxcwNzCRULtLyCc6bPlGEOjRFhRDz5KIHe?= =?utf-8?q?t7WPdwm6zOpoQfCuDM/drOJqmlDMrd1tEcrhT6S+yUrG3bp2Az3HYdjWCK7ciLhsC?= =?utf-8?q?zNKdyslpye7Il8gKXDODvB82B/YHpytKEg3JtyvCKRzoNAIzR2zxHb1jcWZME5POI?= =?utf-8?q?xjcGYYcHPhcYpnWpZcxmHZv/9Qvbcj4VSbG2vJfIps/v5JXJeJvc9JQqPHMeY5wcO?= =?utf-8?q?B0jv/jm0JBpL1Eg2s+HBcc3wo6jn0IcIZF1kj0eB0t25Uthx3kPrXM4gq19NfqjZ2?= =?utf-8?q?bnyuIjdGXxXVZgIQES7OW4oupXUeU3E2THOrN3k/ac/OjBZLrNAfrZELSBy+X60rt?= =?utf-8?q?DmOrgfETUgqqmvSmr65Gbkp9CtCqElQs2feTDvTLEvTkc6JZ2/+1uKw3SmrHSB54g?= =?utf-8?q?NHEdvQ2LLboeYRlpgL1VO3ATLuAWMPbXCgMLtPhKrJJnyWOwaFpADBPBBKihGRAFd?= =?utf-8?q?Af5GKEYZNhXh?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d4df582-f941-4e3e-d00d-08dd22eb492e X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Dec 2024 00:46:49.7914 (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: WwqG/a1cHh1ZgmAQbEL9D/g49DN+t+2hjumsEeeqj1hV55ukMYh3L8t8jnHmekyaVBbH/YB7w+BwDIU0DXMhtg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8995 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 all nodes 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..5a07d8b780ecfc13874cff338d6926d0e2a87c8a 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 *dev = &pdev->dev; + + for_each_available_child_of_node_scoped(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"); + of_node_put(provider); + 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,