From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: wahrenst@gmx.net, shawnguo@kernel.org, s.hauer@pengutronix.de,
kernel@pengutronix.de, festevam@gmail.com,
linux-arm-kernel@lists.infradead.org
Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, "alice.guo" <alice.guo@nxp.com>,
alice.guo@oss.nxp.com
Subject: Re: [PATCH v2] soc: imx: Add SoC device register for i.MX9
Date: Tue, 29 Oct 2024 15:57:20 +0100 [thread overview]
Message-ID: <12544933.O9o76ZdvQC@steina-w> (raw)
In-Reply-To: <20241029083406.3888861-1-alice.guo@oss.nxp.com>
Hi Alice,
Am Dienstag, 29. Oktober 2024, 09:34:06 CET schrieb alice.guo@oss.nxp.com:
> From: "alice.guo" <alice.guo@nxp.com>
>
> 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 <alice.guo@nxp.com>
> ---
>
> Changes for v2:
> - refine error log print
>
> drivers/soc/imx/Makefile | 2 +-
> drivers/soc/imx/soc-imx9.c | 103 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 104 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..0722e69110f9
> --- /dev/null
> +++ b/drivers/soc/imx/soc-imx9.c
> @@ -0,0 +1,103 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright 2024 NXP
> + */
> +
> +#include <linux/arm-smccc.h>
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/slab.h>
> +#include <linux/sys_soc.h>
> +
> +#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: %d\n", __func__, res.a0);
> + err = res.a0;
> + 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);
> + goto soc_id;
> + }
> +
> + return 0;
> +
> +soc_id:
> + kfree(attr->soc_id);
> + kfree(attr->serial_number);
> + kfree(attr->revision);
Please free the memory in the reverse order of allocation.
Thanks
Alexander
> +family:
> + kfree(attr->family);
> +attr:
> + kfree(attr);
> + return err;
> +}
> +
> +static int __init imx9_soc_init(void)
> +{
> + int ret = 0;
> +
> + if (of_machine_is_compatible("fsl,imx91") ||
> + of_machine_is_compatible("fsl,imx93") ||
> + of_machine_is_compatible("fsl,imx95")) {
> + ret = imx9_soc_device_register();
> + if (ret) {
> + pr_err("%s failed to register SoC as a device: %d\n", __func__, ret);
> + return ret;
> + }
> + }
> +
> + return ret;
> +}
> +device_initcall(imx9_soc_init);
> +
> +MODULE_AUTHOR("NXP");
> +MODULE_DESCRIPTION("NXP i.MX9 SoC");
> +MODULE_LICENSE("GPL");
>
--
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
next prev parent reply other threads:[~2024-10-29 15:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 8:34 [PATCH v2] soc: imx: Add SoC device register for i.MX9 alice.guo
2024-10-29 9:13 ` Stefan Wahren
2024-10-29 14:57 ` Alexander Stein [this message]
2024-10-29 17:05 ` kernel test robot
2024-10-29 17:57 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12544933.O9o76ZdvQC@steina-w \
--to=alexander.stein@ew.tq-group.com \
--cc=alice.guo@nxp.com \
--cc=alice.guo@oss.nxp.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=wahrenst@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox