From patchwork Wed Oct 30 09:13:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alice Guo (OSS)" X-Patchwork-Id: 13856139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BCCA4D2AB2C for ; Wed, 30 Oct 2024 09:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=XV72DHgs8T/L6w8FCEEKiJy9I1sRnA8ztHbCci/nsvg=; b=q1uqVXthaXNN0Xp+5+l+wTjuHP AiLl7lmHuU6yw+9GNO0W0WNH3rOfnbgHhvwZlyAvNnELBFnymH034X1WNh48kdPJTybYjVmbjsKH0 j69BfGX/b03HnLEfMA6KdnXHwZ+DfJEOGAYiaYqQEnsSH/QNN0V5g5aSPz8sFtQN7OR2aObPgQi7j QvAl7U41gO8TPx03xDJTcU+DyvyLjyu3vh3vI0evyTOxr5BTlczC9wY2ovSpR5PrqVcpTkJFgdhFZ aSv7AZatWW40j4IvS3zI+E2Tb5Z+QTfaOD2yhc5t+YKtz+nH1OWndyB7Op86BaHeh24LsZKYpu87j ufmSqhXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t64pe-0000000HN8D-2PWg; Wed, 30 Oct 2024 09:17:38 +0000 Received: from mail-db8eur05on2060f.outbound.protection.outlook.com ([2a01:111:f403:2614::60f] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t64n0-0000000HMuN-2B9Q for linux-arm-kernel@lists.infradead.org; Wed, 30 Oct 2024 09:14:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q5MawZ1qO1+8+pj9Mynzlx5cuJYDsjA9TGgftM/m4UWnPkg6fCRSWK3klD9q+m35MW5+U2wJoPKIp6RZJrnDjQe87WM1Nnw3i8zLcvwTy7H0HsdSvZ2iPVy+Kg7HNvCVBoWJJds7JlIxOxWzxYHLteIVMsoPJEwQ0Sj5sOqXdCtE5AHRuC6QD2t/baLobQp6LvOtNv0DhpJoUVWRzKf8wwy56ZFyt7EztFxfCQhcU78mqXXwpTZq+BaNHTSuc+1f42+rdqQenat7TgbgiWeHi/wNl27xw/MaR/HrKi215BynVRLUuE8FnFIiXDNA4anLjrtBVjEVT8r4s3g61t/BrA== 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=XV72DHgs8T/L6w8FCEEKiJy9I1sRnA8ztHbCci/nsvg=; b=M16kmMJJurhsJU5qamdq+vWwGBDdro2V8Elk9Vr0B7Srnl/5v5XbzRhCQS97iqPNnFyNj+L9jZkmYjJl8wmzQqeHpvy5yeE57GZD2ddL58tmVm2/MRaHnnUkdjZDz449CvpvbUK39UoTnYO39/crqy50F09uD1lM8Bj9eOTcRuju6NeiRNPVYSrkH+uloO9/ULHCVxfW2w1vf2Xy2CYglbYoQRrsnCBFwFF8JYZBzVZiVHzlZI3GiK/4OCfudWxN7p8jif3rl+AYmrPRF/uToTtxyO9hjUXFS0Z/vkdNTCu/HE1bhyVOF+ifbXz0o1WgEv9bLvuSCnkwE7wKePT6mQ== 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=XV72DHgs8T/L6w8FCEEKiJy9I1sRnA8ztHbCci/nsvg=; b=LmE0fSpepImb+vo/EAxQFcu/SeQWGtg75pfy4AuBE4RDEXhbOu3OhunXiyl9EBHnrY+ZslzG8qQhuCjmyJp0Vk6RnAZEe12k1ZBYup3x06i+kDwwICymh+rAUWohw7Ijz8of3uYZ8Xlf2/abnYKqhIHX13HtQDjO86SmdXBdmru0/jJVThZDQk0B6iNf+OsUzWcFEjzAB/ysD0+P+zkGat5va6q/MRiutYyu8fGYfXrxJpaoklwWtnaeNR3otwxYXLTysImpbQU7aw6ePyHEnI16cQvYANWUkIjSUJysllkF7Qy6ZRIohrHhkXFMYINuRu7m2ro4DFoqT79qOemJ3Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB9644.eurprd04.prod.outlook.com (2603:10a6:102:242::11) by AS5PR04MB9854.eurprd04.prod.outlook.com (2603:10a6:20b:673::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Wed, 30 Oct 2024 09:14:47 +0000 Received: from PAXPR04MB9644.eurprd04.prod.outlook.com ([fe80::6979:311a:bf0c:1a49]) by PAXPR04MB9644.eurprd04.prod.outlook.com ([fe80::6979:311a:bf0c:1a49%5]) with mapi id 15.20.8093.027; Wed, 30 Oct 2024 09:14:47 +0000 From: alice.guo@oss.nxp.com To: alexander.stein@ew.tq-group.com, wahrenst@gmx.net, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "alice.guo" Subject: [PATCH v3] soc: imx: Add SoC device register for i.MX9 Date: Wed, 30 Oct 2024 17:13:36 +0800 Message-Id: <20241030091336.3901440-1-alice.guo@oss.nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2PR01CA0019.apcprd01.prod.exchangelabs.com (2603:1096:4:192::12) To PAXPR04MB9644.eurprd04.prod.outlook.com (2603:10a6:102:242::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9644:EE_|AS5PR04MB9854:EE_ X-MS-Office365-Filtering-Correlation-Id: 99228ab5-1e50-4135-aad1-08dcf8c34ce6 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|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: WmppfJxU16UG9aqCbRl99CuOOgsIAIGw1ohYjQFrjXZNINN2OKhlsT8v6LLVqfrphvH2FrEQHIb9j0z7O4wUogsCKf7Tjchi8KR2XBKnjWZXBR7OTnYqXSKi5SAocldvXWIG4AwUKO7Zpt7Wi1g6MJN6A5C8kSpoiLEfjaa+0ekwGgAOQ8Lm53fjJ+c+seksSDz8BM9aPDhW/LIVRFCT3Axu7pS52rsaCp3b9j/ya40utZhA7hswifLEOhoxE5CRGXQe/cN55yAcVENB5AlG+kn+m1djOYa6DQZBGg0EYlJetgIhGBsHI8V1R4UsPHncUrfmvBuMKzu1EXfkDusGxjd+Rd3jKk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:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9644.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mpR1oTFXLqBwcjOyQYgI/rob8dreTpHXoagTLVl67ZoNXs+em1rtjZNYTtr2FiEg1l6lg15X/J5kq01Fbjxu67l/oqnXuUo3KdSgsNo/ZMUJt48VnABDcXWs3Ycqg61AB6kxqqCoWoNOEZ6sx0anBGtxmlaRo7KKW1+K8ZubPJJM4048dPMzfdAyYYzSRJ6vfi3wt51/4Yv81Dp3LELP1m0c+ZvqtL5sMLZ93AUItMbR1BQLvBspsLc7KFS0p2/tTCmrQr/GDGFpAWN6pFzOdedqdxM4PBNVuEld2t1P7d0u0XQS8rC4bHTxul4CnFDWp8N1RQ1RysebRnc6bgZ7PFEgOGeC3GqyCmW5txvVfUO6MNjgqla8Oxyw98awf6R4lD06D2jWAWkIVdz5cthXdeH/REbCx4PiA6YV2+so5RxNGYiAAS8hPlXOqUgtj1S/pwPi+dU0PDPNMBXEGutR/Jt6pIe+30+rvrX+hS1jkAFUwPJA9ynRQZkvjy6F+XPR02tWJVeEDaPW0nKbmTD3FKj0eP4hVbaIyK8lDNoWYk0Sw1eC5vTBpKVw05vlLjAx74Wh+2yEKXuSl2KK6NBfwRNWO7qWYQzHWpOd1kueobTyeixfI92QtoMwb1hJ54yK96tBGaquHT6eyU/xrTnmbIunNOSTRWJp52JrVIbgqKbslO4VNMH5tG1U/O6VCiIHM2GTc5Db3Q4WsGCRSS6KO0fAsDdgunDW5U2z3iGnxhpqK0op3tkSXcx5nlEivJF3I9QP3jTF4U47IP1s3x15+pPMSUsaio8Nk83AmuxweBzTHqJDVHcc1SiPsqczfcd08hnzq+geQrQr5G/cyBUxemtvqOm20/pvWOqFycetHTVSkRfnDxDhZvGDusLAZjf31LVKCLAFBek3ea7R0MiJyzuCXbpuqLl0JCzENXENxfmozGb/wz8irJrpSnBSg9cZ7m3e3kDAyAmMVmm1qugFLJ0qq+5SQuySMRIm/xz9wHW2Msv7Oxrjs2geG0+fi6LDD5iXnckmYkB/FegRP+2hfuRtV9Kxk6VfM3P1wtcX0VywcZVZ0C5sHjLaR+yhPsYigUIepqAPJGPOlzB9o/5meKmp0CATbANzbrwzFaKnu1+t6cKBC6y9t5Vzm8UskuHbiTTJtbbOVGXtU3gD5nndUoe2kB17aopmmsYf4o0DRLs32grvwi79IGG2jZTBHAmFbZInFmSBukfMf8LsUFAA97kkcXCdbClFUuFDrOA2nYNhjFOYglitABYiyaxtzcxRRMntB0E16cuiTRKM+PWcWth8BX4s3gaJVFKSlPWOugkT+eYenXvbL5KhTQ26J/p0pn2AiqBNlHnfXAV2ON1+kvq6HaIOmTidizyVghGAPl6h7ugPcbKXlSnuqgA0E01+D9ATQX4qKle5oPaANtlwLaTjE4PGjqMIWIayOV/Rw3E3gwx+siWzBtfVBpt+LM2BNI798T+OI5O3kZ2LqKdvijn9PhYOlLfU/wsZiLipJrgPz5v0a/ytEchRuHDO7yT0WIUKKM+jRmx+p6L+zoSWnj4wZ3I3q7HIVjD8amU0e9h2A7maQmLMnN46ZBqchEZL X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99228ab5-1e50-4135-aad1-08dcf8c34ce6 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9644.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 09:14:47.6316 (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: XfVPUf2to0LvMXhHwqBFf9tCfBV1Tn6VDPe5bNlMr6mLdpE7NZFL+NwJUC5zXl3kWENbL4ThgN9LnqqscL2s9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS5PR04MB9854 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241030_021454_593932_76DB478A X-CRM114-Status: GOOD ( 19.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "alice.guo" i.MX9 SoCs have SoC ID, SoC revision number and chip unique identifier which are provided by the corresponding ARM trusted firmware API. This patch intends to use SMC call to obtain these information and then register i.MX9 SoC as a device. Signed-off-by: alice.guo Tested-by: Alexander Stein Reviewed-by: Stefan Wahren --- Changes for v2: - refine error log print Changes for v3: - return -EINVAL when arm_smccc_smc failed - fix the build warning caused by pr_err("%s: SMC failed: %d\n", __func__, res.a0); - drop the pr_err in imx9_soc_init - free the memory in the reverse order of allocation - use of_match_node instead of of_machine_is_compatible drivers/soc/imx/Makefile | 2 +- drivers/soc/imx/soc-imx9.c | 106 +++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/imx/soc-imx9.c diff --git a/drivers/soc/imx/Makefile b/drivers/soc/imx/Makefile index 3ad321ca608a..ca6a5fa1618f 100644 --- a/drivers/soc/imx/Makefile +++ b/drivers/soc/imx/Makefile @@ -3,4 +3,4 @@ ifeq ($(CONFIG_ARM),y) obj-$(CONFIG_ARCH_MXC) += soc-imx.o endif obj-$(CONFIG_SOC_IMX8M) += soc-imx8m.o -obj-$(CONFIG_SOC_IMX9) += imx93-src.o +obj-$(CONFIG_SOC_IMX9) += imx93-src.o soc-imx9.o diff --git a/drivers/soc/imx/soc-imx9.c b/drivers/soc/imx/soc-imx9.c new file mode 100644 index 000000000000..823395584533 --- /dev/null +++ b/drivers/soc/imx/soc-imx9.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP + */ + +#include +#include +#include +#include +#include +#include + +#define IMX_SIP_GET_SOC_INFO 0xc2000006 +#define SOC_ID(x) (((x) & 0xFFFF) >> 8) +#define SOC_REV_MAJOR(x) ((((x) >> 28) & 0xF) - 0x9) +#define SOC_REV_MINOR(x) (((x) >> 24) & 0xF) + +static int imx9_soc_device_register(void) +{ + struct soc_device_attribute *attr; + struct arm_smccc_res res; + struct soc_device *sdev; + u32 soc_id, rev_major, rev_minor; + u64 uid127_64, uid63_0; + int err; + + attr = kzalloc(sizeof(*attr), GFP_KERNEL); + if (!attr) + return -ENOMEM; + + err = of_property_read_string(of_root, "model", &attr->machine); + if (err) { + pr_err("%s: missing model property: %d\n", __func__, err); + goto attr; + } + + attr->family = kasprintf(GFP_KERNEL, "Freescale i.MX"); + + /* + * Retrieve the soc id, rev & uid info: + * res.a1[31:16]: soc revision; + * res.a1[15:0]: soc id; + * res.a2: uid[127:64]; + * res.a3: uid[63:0]; + */ + arm_smccc_smc(IMX_SIP_GET_SOC_INFO, 0, 0, 0, 0, 0, 0, 0, &res); + if (res.a0 != SMCCC_RET_SUCCESS) { + pr_err("%s: SMC failed: 0x%lx\n", __func__, res.a0); + err = -EINVAL; + goto family; + } + + soc_id = SOC_ID(res.a1); + rev_major = SOC_REV_MAJOR(res.a1); + rev_minor = SOC_REV_MINOR(res.a1); + + attr->soc_id = kasprintf(GFP_KERNEL, "i.MX%2x", soc_id); + attr->revision = kasprintf(GFP_KERNEL, "%d.%d", rev_major, rev_minor); + + uid127_64 = res.a2; + uid63_0 = res.a3; + attr->serial_number = kasprintf(GFP_KERNEL, "%016llx%016llx", uid127_64, uid63_0); + + sdev = soc_device_register(attr); + if (IS_ERR(sdev)) { + err = PTR_ERR(sdev); + pr_err("%s failed to register SoC as a device: %d\n", __func__, err); + goto serial_number; + } + + return 0; + +serial_number: + kfree(attr->serial_number); + kfree(attr->revision); + kfree(attr->soc_id); +family: + kfree(attr->family); +attr: + kfree(attr); + return err; +} + +static const struct of_device_id imx9_soc_match[] = { + { .compatible = "fsl,imx93", }, + { .compatible = "fsl,imx95", }, + { } +}; + +static int __init imx9_soc_init(void) +{ + int ret; + + /* No match means it is not an i.MX 9 series SoC, do nothing. */ + if (!of_match_node(imx9_soc_match, of_root)) + return 0; + + ret = imx9_soc_device_register(); + + return ret; +} +device_initcall(imx9_soc_init); + +MODULE_AUTHOR("NXP"); +MODULE_DESCRIPTION("NXP i.MX9 SoC"); +MODULE_LICENSE("GPL");