From patchwork Thu Oct 31 06:54:38 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: 13857615 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 EC1DFE68956 for ; Thu, 31 Oct 2024 06:58:02 +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=4hDM8/lJ8rslfz5ctGZSvNTS5su6yZOHQ3L+ShCrRjs=; b=o5cNIlbjhXp7xkeEEHimjvszFu mnYgYxFdj0cbBbTlhqSntyHP9mmQxxaS7KxHSfwpKeRVi8lHbqSiqnnd9/DkqsOUKTVC92cmTGroe 9WggFoWorcjT5Z6zo2XTKolE3N3bUP8ThWMhal3GwpDuCcSPSECtbZ4kJj14EltSFC9G/sRGfVSIa w4NX6hdGNPV5Dd2sbZ4hX8Z/907t6wl2/018mjqR/veMGGGIzYtESdA/W3EPfcQ73apt1JD+74Itk HaplvJAuUDmrmWG8i9SBuduFUGQthPYKhm/dPWrtWMb5j3a9X4rgnEU3Vy3AsnO3tPe4H4zdiwJUj Qq83QS5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t6P7o-00000002jhX-1ZEf; Thu, 31 Oct 2024 06:57:44 +0000 Received: from mail-am6eur05on20612.outbound.protection.outlook.com ([2a01:111:f403:2612::612] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t6P63-00000002jIL-32xY for linux-arm-kernel@lists.infradead.org; Thu, 31 Oct 2024 06:55:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i7oSshkPdIonnY/Taqs/Knrqt2ApQ6nIrxHNYrkxOgVfel6dUHerjKkZHyRYv2i1XDlahJ6iBwnhnB3d51zzHny5BEhoOT+3j+DcMdzsYp1Qt4v4W8obtdgPduV8YYQrL2kYNZ7gjqEUjT/bSd2yvqR7f+cbqAKlBkss6P0iCMIY7yNw0K8K5JAtgAuCsc76Rg67EJwc0A23Wami+FiyukT4ekfO6ToMaVEJi8uCsUC9UdVwi8XZQQpM99/MuqZu0yAh2DMijdKzd4qQrERVibVllGJvGFK4jA7xUTCe0BA05ONZfQ5HK/AKk7YaOJlXFETp909YGgQZ35jP0miMOw== 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=4hDM8/lJ8rslfz5ctGZSvNTS5su6yZOHQ3L+ShCrRjs=; b=uX3XKzGTtNiQ/lSNm2/F9KuUVNYitYuf5SRRKR8lwG6jdUGDbFOPkaw6YRegP/Cq0HxWZFjgJvut6nOgM63xoRsxfGsxGtF9aJ8IK7nGCjEEkL+qIbTu5lXJE7LEljvQbNrLPkypkoNdPdPPbv+kPbgkrn0ExE65NCCmmMQ/Kq/b8LN13nCS3SjZMM3kgH+uMvfFl2n6Dzv4R3zKeWNqMxWvDOgZdOMXIDbDR6Lpe2pu4qDkjZ8gkVPujK8x2/FiPo4SdNpApgF/g4AzRKS/B/esIRNb4t07Q4gaH9ncUnVZq4Ri0la+4EkFCfb5sSHBu4/MbRoBfdlmvQbSO/udIA== 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=4hDM8/lJ8rslfz5ctGZSvNTS5su6yZOHQ3L+ShCrRjs=; b=OS/QHxWbPOSNtcUUaQdPDg2qm+ReHFdtVnrk0cKRU/a3vgK8EVVA/UWS+ncCPPZdPu4Rrx2ahfDLzOsLEp+7jyuiLoXTcadRRMdsrPL5XmCaCaVNHBxKRNDvpQEIKv+mQFTgMyHdZfFL/flHCCAYjZ5sWAK8yJFMWrx30AP+aA5SIvDZrciOb/1JU0un58Qnyvwrk26hH2pWG0CiOp1H1oemmZeExhzdYdT8zuj052MLhavHc5RQQGpBhHg0CZHDI28QOtgszrL/XoQzDsu0m4hBeAcSwJmMxvDTXSRcU0jccaP4U9EAFXav/ExdvlEpZAV1qhJd7z2zgNxfG41hvg== 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 AM9PR04MB8383.eurprd04.prod.outlook.com (2603:10a6:20b:3ed::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Thu, 31 Oct 2024 06:55:49 +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; Thu, 31 Oct 2024 06:55:48 +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 v4] soc: imx: Add SoC device register for i.MX9 Date: Thu, 31 Oct 2024 14:54:38 +0800 Message-Id: <20241031065438.3912960-1-alice.guo@oss.nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2PR01CA0050.apcprd01.prod.exchangelabs.com (2603:1096:4:193::21) 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_|AM9PR04MB8383:EE_ X-MS-Office365-Filtering-Correlation-Id: 68e1421d-7cd1-4570-91a2-08dcf9790d13 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|376014|366016|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: VBgBsx8IX1QAsSXVcfRTs6GU3EXMM05sF0wQf2Sloy1LklRrckEyz2ozL0ag8uEDG3Jk7iP8nPRmx5smYejl1aJ/LwDs+1PIgt1Nn8tOP2OpbjMyvmmkWEZIUcLw2r8JzG2o/GDvxZ+YIsv/5fjZl8ztqiExnp9DQ9dlNVjg39beVMLIxJ8XCDNYoUqzyE/0m9LN5pwzb438GctJPiYa7fTXsT7oNmq6SFeHvnSbo0P6cL6hpKiFsI1l7RBVU5Kr/ujJmYNUdp4oxwRvpQOdTMdaIlBuf9aedzoMetmIQRmfkEApJrH60/e0WsvA1zW+4B7u5tHc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.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9644.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(366016)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rx1/1nc2xS71rl6hGZm9AzgLT8CkQw2LGk9MfZME7zRJIFIVf3lwQryjJVXMtUF+wrtK2tBY+weaRNjBjvngeFO/chYpTDtFPpvAAk2w3gRAgqrxCPEObb1l/mMsFbVePnNyxwBxSDJTFtrpsIi8ZoFeW49levXkw2SXZwiEhmRqXeZ6eBWBX8MmfLscdu2k4iS/Epplmus6gb3EYy9/dhQEQIIis5VXgZIrp7t3d9HpmluYesGygPJ5MOF00QCelmqYd/S3eSTUwkA4zG94gRH2RRDxo0k9qoWWh3gXHCl9qpkcDPheZoBTljt8AjrkbvBV9Qf3C/v8YqMNrf5A40fSUu2B9nAVZdNlERFFjgdeiVN4vEPHKCDPAr9xLZoyP2usbgpVuPXgGih6ymAI6T3+xBtn+cb3qHQLfaf3mjfa6tle9wvNzyrltqm/EFXYMDy/1F6xc23JLD1sf6PWuuLcTWNuIi7QQMWYjwy46FMJOzjfTz0hXKcQeZRfYUL3GImEl2CgeA34pnionxfWVKr+C/J6M15ZmS6bm/BFCfE+XGdMz9qg2tmknSNZjY9lBwPto9yk8uHZkq1sr7X7JTR3qrb9SfxRbEh3KYXMDw3MykPdBKD+r40RZpcKaiu61zUTiKtumTQUxoRPIQDks2IMxWgOw5tphT2O+0goeRy0RwiBAoCy/rAbN+kWRgEwgcQCOx90p+E2/3koY2YY8DUjH6VltqtqNdg0CzFenSsuKrejPkBwcskxEnrENlKgQ57yXb44qPCtWuigUPNph9hR02A44/YkDqumRU3DNoxLovloEtpOplrChQRgt6fZzgXaDeMXVvwKNNqJJG8bhck4HI3WqwK3V+dhjQ7uacvhfuz9I5YcCYd30gokksuv87MEc4LeRC0NAeBAy+kMW2c1jDcFYXNhrjPa4eSr3ZpXHzEzA/KQEK/spZVvAph6Ah6MeDKhpaKuZjhteO/CclhJHy7drCcJUZaMF4aXG/uJvjBnrVjE1iyCo31NNaXFK9OULoY7mm5D6NRTMgFUb3lkwmqO1GJnZeG6JX8UfOSKip7FtL99rFKTBFjHcpp85zdy/1DlUmT4aIjR5zCVvJi9ofEvRaPZ+A2fEY2Fv1YkCZxzmt4DR2N80Qm1AJyriwZ1Vq9qqqx+j914/X5NgIWOId4ljxWAw0kRwKAqLJNvd0/FW9SSGPD6ZzG0oasK39pMNii/0s0yrMdJ2h4avIQpj2gLvnvxq3LJB3SQAvnBfiLYvbHIOJRV09q/ie5oA9UbSARwTZiqNzpniltJMi3C76OoU62etM8DR9hkphGezyv/v1l4KePaUzT2jeZuHqqegDWNC9WGG6EPFa+QCaKmLDiQ40xu6hYFDAvMWfTzGxnAijMUfP+S72bAuL8QV2vaJahyXoSoHl8ck1qQ+3ChrgrxvctLq9ZjFh5/1OyirtFXgAgF98rmng72o5ZrXGVGFiqd62Lk+IIlx/X/YWPHGJJWcntbe17yA4uFT+kZoBn09MCAH3VT7cF9p4aB3hax4uKGb7gM2fWsCOz6OrlO/3vNAGlTPfLhr4K8s+JSzrQartCpwrgtwLSB/cn2 X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68e1421d-7cd1-4570-91a2-08dcf9790d13 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9644.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2024 06:55:48.8776 (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: rgFOLBmlEviPFiUICwvr4t/kzWDbdk7Z9tYu18NCWVXggag8VU2PP0/WHUw3e1pu8N3OHxNXrRpTYVj48+Yw6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8383 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241030_235555_811803_8731448A X-CRM114-Status: GOOD ( 19.86 ) 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 Changes for v4: - fix the build warning: 'imx9_soc_match' defined but not used [-Wunused-const-variable=] - add Tested-by and Reviewed-by 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..3d5df479d8c0 --- /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 __maybe_unused 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");