[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
<PAXPR04MB9644C81E428A2AD90F7E5E6EE25B2@PAXPR04MB9644.eurprd04.prod.outlook.com>
Date: Thu, 14 Nov 2024 07:58:15 +0000
From: "Alice Guo (OSS)" <alice.guo@....nxp.com>
To: Stefan Wahren <wahrenst@....net>
CC: "imx@...ts.linux.dev" <imx@...ts.linux.dev>, "s.hauer@...gutronix.de"
<s.hauer@...gutronix.de>, "festevam@...il.com" <festevam@...il.com>,
"shawnguo@...nel.org" <shawnguo@...nel.org>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, Alice Guo <alice.guo@....com>,
"alexander.stein@...tq-group.com" <alexander.stein@...tq-group.com>,
"kernel@...gutronix.de" <kernel@...gutronix.de>, Peng Fan <peng.fan@....com>
Subject:
回复: [EXT] Re: [PATCH v5] soc: imx: Add SoC device register for i.MX9
Hi Stefan,
There is no device node which is bound to this driver in DTS file so that I did not use module_platform_driver. This method is the same with drivers/soc/imx/soc-imx8m.c.
Best Regards,
Alice Guo
> -----邮件原件-----
> 发件人: Stefan Wahren <wahrenst@....net>
> 发送时间: 2024年11月12日 1:38
> 收件人: Alice Guo (OSS) <alice.guo@....nxp.com>
> 抄送: imx@...ts.linux.dev; s.hauer@...gutronix.de; festevam@...il.com;
> shawnguo@...nel.org; linux-arm-kernel@...ts.infradead.org;
> linux-kernel@...r.kernel.org; Alice Guo <alice.guo@....com>;
> alexander.stein@...tq-group.com; kernel@...gutronix.de
> 主题: [EXT] Re: [PATCH v5] soc: imx: Add SoC device register for i.MX9
>
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report this
> email' button
>
>
> Hi Alice,
>
> Am 11.11.24 um 04:23 schrieb alice.guo@....nxp.com:
> > From: "alice.guo" <alice.guo@....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@....com>
> > Tested-by: Alexander Stein <alexander.stein@...tq-group.com>
> > Reviewed-by: Stefan Wahren <wahrenst@....net>
> > ---
> >
> > 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
> > Changes for v5:
> > - probe imx9 soc driver as a platform driver
> >
> > drivers/soc/imx/Makefile | 2 +-
> > drivers/soc/imx/soc-imx9.c | 124
> +++++++++++++++++++++++++++++++++++++
> > 2 files changed, 125 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..4ef92260e8f9
> > --- /dev/null
> > +++ b/drivers/soc/imx/soc-imx9.c
> > @@ -0,0 +1,124 @@
> > +// 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/platform_device.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_probe(struct platform_device *pdev) {
> > + 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[] = {
> In case everything is correct, "__maybe_unused" can be dropped
> > + { .compatible = "fsl,imx93", },
> > + { .compatible = "fsl,imx95", },
> > + { }
> > +};
> MODULE_DEVICE_TABLE is missing
> > +
> > +static struct platform_driver imx9_soc_driver = {
> > + .probe = imx9_soc_probe,
> > + .driver.name = "imx9-soc",
> .of_match_table is missing
> > +};
> > +
> > +static int __init imx9_soc_init(void) {
> > + int ret;
> > + struct platform_device *pdev;
> > +
> > + /* 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 = platform_driver_register(&imx9_soc_driver);
> > + if (ret) {
> > + pr_err("failed to register imx9_soc platform driver: %d\n",
> ret);
> > + return ret;
> > + }
> > +
> > + pdev = platform_device_register_simple("imx9-soc", -1, NULL, 0);
> > + if (IS_ERR(pdev)) {
> > + pr_err("failed to register imx9_soc platform device: %ld\n",
> PTR_ERR(pdev));
> > + platform_driver_unregister(&imx9_soc_driver);
> > + return PTR_ERR(pdev);
> > + }
> > +
> > + return 0;
> > +}
> From my understand all these stuff belongs in the probe function now, so
> maybe the existing one should be renamed.
> > +device_initcall(imx9_soc_init);
> I think this should be replace by
>
> module_platform_driver(imx9_soc_driver);
>
> Regards
> > +
> > +MODULE_AUTHOR("NXP");
> > +MODULE_DESCRIPTION("NXP i.MX9 SoC");
> > +MODULE_LICENSE("GPL");
Powered by blists - more mailing lists