linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: Alice Guo <alice.guo@nxp.com>
Cc: devicetree@vger.kernel.org, peng.fan@nxp.com,
	s.hauer@pengutronix.de, linux-kernel@vger.kernel.org,
	robh+dt@kernel.org, linux-imx@nxp.com, shawnguo@kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3 4/4] soc: imx8m: change to use platform driver
Date: Sat, 14 Nov 2020 17:41:28 +0100	[thread overview]
Message-ID: <20201114164128.GD14989@kozik-lap> (raw)
In-Reply-To: <20201113110409.13546-4-alice.guo@nxp.com>

On Fri, Nov 13, 2020 at 07:04:09PM +0800, Alice Guo wrote:
> Directly reading ocotp register depends on that bootloader enables ocotp
> clk, which is not always effective, so change to use nvmem API. Using
> nvmem API requires to support driver defer probe and thus change
> soc-imx8m.c to use platform driver.
> 
> The other reason is that directly reading ocotp register causes kexec
> kernel hang because the 1st kernel running will disable unused clks
> after kernel boots up, and then ocotp clk will be disabled even if
> bootloader enables it. When kexec kernel, ocotp clk needs to be enabled
> before reading ocotp registers, and nvmem API with platform driver
> supported can accomplish this.
> 
> Old .dts files can also work.
> 
> Signed-off-by: Alice Guo <alice.guo@nxp.com>
> ---
>  drivers/soc/imx/soc-imx8m.c | 89 ++++++++++++++++++++++++++++++++-----
>  1 file changed, 79 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c
> index cc57a384d74d..af2c0dbe8291 100644
> --- a/drivers/soc/imx/soc-imx8m.c
> +++ b/drivers/soc/imx/soc-imx8m.c
> @@ -5,6 +5,8 @@
> 
>  #include <linux/init.h>
>  #include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-consumer.h>
>  #include <linux/of_address.h>
>  #include <linux/slab.h>
>  #include <linux/sys_soc.h>
> @@ -29,7 +31,7 @@
> 
>  struct imx8_soc_data {
>  	char *name;
> -	u32 (*soc_revision)(void);
> +	u32 (*soc_revision)(struct device *dev, int flag);
>  };
> 
>  static u64 soc_uid;
> @@ -50,7 +52,7 @@ static u32 imx8mq_soc_revision_from_atf(void)
>  static inline u32 imx8mq_soc_revision_from_atf(void) { return 0; };
>  #endif
> 
> -static u32 __init imx8mq_soc_revision(void)
> +static u32 __init imx8mq_soc_revision(struct device *dev, int flag)
>  {
>  	struct device_node *np;
>  	void __iomem *ocotp_base;
> @@ -75,9 +77,17 @@ static u32 __init imx8mq_soc_revision(void)
>  			rev = REV_B1;
>  	}
> 
> -	soc_uid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
> -	soc_uid <<= 32;
> -	soc_uid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
> +	if (flag) {
> +		int ret = 0;
> +
> +		ret = nvmem_cell_read_u64(dev, "soc_unique_id", &soc_uid);
> +		if (ret)
> +			return ret;
> +	} else {
> +		soc_uid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
> +		soc_uid <<= 32;
> +		soc_uid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
> +	}
> 
>  	iounmap(ocotp_base);
>  	of_node_put(np);
> @@ -107,7 +117,7 @@ static void __init imx8mm_soc_uid(void)
>  	of_node_put(np);
>  }
> 
> -static u32 __init imx8mm_soc_revision(void)
> +static u32 __init imx8mm_soc_revision(struct device *dev, int flag)
>  {
>  	struct device_node *np;
>  	void __iomem *anatop_base;
> @@ -125,7 +135,15 @@ static u32 __init imx8mm_soc_revision(void)
>  	iounmap(anatop_base);
>  	of_node_put(np);
> 
> -	imx8mm_soc_uid();
> +	if (flag) {
> +		int ret = 0;
> +
> +		ret = nvmem_cell_read_u64(dev, "soc_unique_id", &soc_uid);
> +		if (ret)
> +			return ret;
> +	} else {
> +		imx8mm_soc_uid();
> +	}
> 
>  	return rev;
>  }
> @@ -158,12 +176,21 @@ static __maybe_unused const struct of_device_id imx8_soc_match[] = {
>  	{ }
>  };
> 
> +static __maybe_unused const struct of_device_id imx8m_soc_match[] = {

Could this really be unused?

> +	{ .compatible = "fsl,imx8mq-soc", .data = &imx8mq_soc_data, },
> +	{ .compatible = "fsl,imx8mm-soc", .data = &imx8mm_soc_data, },
> +	{ .compatible = "fsl,imx8mn-soc", .data = &imx8mn_soc_data, },
> +	{ .compatible = "fsl,imx8mp-soc", .data = &imx8mp_soc_data, },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, imx8m_soc_match);

You already have "imx8_soc_match" which covers imx8m and now you add
"imx8m_soc_match" which also covers imx8m. Such naming is a pure
confusion.

> +
>  #define imx8_revision(soc_rev) \
>  	soc_rev ? \
>  	kasprintf(GFP_KERNEL, "%d.%d", (soc_rev >> 4) & 0xf,  soc_rev & 0xf) : \
>  	"unknown"
> 
> -static int __init imx8_soc_init(void)
> +static int imx8_soc_init_flag(struct platform_device *pdev, int flag)
>  {
>  	struct soc_device_attribute *soc_dev_attr;
>  	struct soc_device *soc_dev;
> @@ -182,7 +209,10 @@ static int __init imx8_soc_init(void)
>  	if (ret)
>  		goto free_soc;
> 
> -	id = of_match_node(imx8_soc_match, of_root);
> +	if (flag)
> +		id = of_match_node(imx8m_soc_match, pdev->dev.of_node);
> +	else
> +		id = of_match_node(imx8_soc_match, of_root);
>  	if (!id) {
>  		ret = -ENODEV;
>  		goto free_soc;
> @@ -192,7 +222,13 @@ static int __init imx8_soc_init(void)
>  	if (data) {
>  		soc_dev_attr->soc_id = data->name;
>  		if (data->soc_revision)
> -			soc_rev = data->soc_revision();
> +			soc_rev = data->soc_revision(&pdev->dev, flag);
> +
> +		if (flag) {
> +			ret = soc_rev;
> +			if (ret < 0)
> +				goto free_soc;
> +		}
>  	}
> 
>  	soc_dev_attr->revision = imx8_revision(soc_rev);
> @@ -230,4 +266,37 @@ static int __init imx8_soc_init(void)
>  	kfree(soc_dev_attr);
>  	return ret;
>  }
> +
> +static int __init imx8_soc_init(void)
> +{
> +	int ret = 0, flag = 0;
> +
> +	if (of_find_compatible_node(NULL, NULL, "fsl,imx8mm-soc") ||
> +	    of_find_compatible_node(NULL, NULL, "fsl,imx8mn-soc") ||
> +	    of_find_compatible_node(NULL, NULL, "fsl,imx8mp-soc") ||
> +	    of_find_compatible_node(NULL, NULL, "fsl,imx8mq-soc"))

Missing puts.

Don't duplicate the compatibles, iterate over existing structure... or
see comments below.  Maybe you could simplify it with something like
of_find_matching_node_and_match()... but check comments below.

> +		return 0;
> +
> +	ret = imx8_soc_init_flag(NULL, flag);
> +	return ret;
> +}
>  device_initcall(imx8_soc_init);

Where is the changelog? This was removed previously, now it stays...

After more thoughs, it looks you have kept it for the purpose of
supporting existing DTB, but it is not explained. Neither in the source
code (which after applying this patch looks confusing) nor in commit
message.

In case of old DTB without fsl,imx8mm-soc-like compatibles, it would be
better to still register a platform driver and create a device
(of_platform_device_create())). However still this won't solve the
problem of actually missing device node... so maybe this double entry
point is acceptable, if properly explained.

> +
> +static int imx8_soc_init_probe(struct platform_device *pdev)
> +{
> +	int ret = 0, flag = 1;
> +
> +	ret = imx8_soc_init_flag(pdev, flag);

Never name unspecified booleans like "flag". The same as string
variables should be named "string", integers should not be named
"number".

> +	return ret;
> +}
> +
> +static struct platform_driver imx8_soc_init_driver = {
> +	.probe = imx8_soc_init_probe,
> +	.driver = {
> +		.name = "imx8_soc_init",
> +		.of_match_table = of_match_ptr(imx8m_soc_match),

Can it bind without OF? Why it's a of_match_ptr()?

> +	},
> +};
> +
> +module_platform_driver(imx8_soc_init_driver);

Here and in all other places (including driver name) this is not a SoC
initialization (init) driver. You cannot initialize a SoC. This looks
like a SoC ID driver, so one name could be "imx8_soc_id".

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-11-14 16:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 11:04 [PATCH v3 1/4] dt-bindings: soc: imx8m: add DT Binding doc for soc unique ID Alice Guo
2020-11-13 11:04 ` [PATCH v3 2/4] arm64: dts: imx8m: add compatible string to .dtsi file Alice Guo
2020-11-14 15:57   ` Krzysztof Kozlowski
2020-11-16  7:12     ` [EXT] " Alice Guo
2020-11-13 11:04 ` [PATCH v3 3/4] arm64: dts: imx8m: add nvmem-cell related stuff Alice Guo
2020-11-14 16:00   ` Krzysztof Kozlowski
2020-11-16  7:16     ` [EXT] " Alice Guo
2020-11-13 11:04 ` [PATCH v3 4/4] soc: imx8m: change to use platform driver Alice Guo
2020-11-14 16:41   ` Krzysztof Kozlowski [this message]
2020-11-16  8:18     ` [EXT] " Alice Guo
2020-11-16 16:13       ` Krzysztof Kozlowski
2020-11-18 10:28         ` Alice Guo
2020-11-18 10:42           ` Krzysztof Kozlowski
2020-11-18 14:07             ` Alice Guo
2020-11-18 14:10               ` Krzysztof Kozlowski
2020-11-19  7:32                 ` Alice Guo
2020-11-19  9:42                   ` Krzysztof Kozlowski
2020-11-14 15:55 ` [PATCH v3 1/4] dt-bindings: soc: imx8m: add DT Binding doc for soc unique ID Krzysztof Kozlowski
2020-11-14 16:49 ` Krzysztof Kozlowski
2020-11-16  7:04   ` [EXT] " Alice Guo
2020-11-16 16:03     ` Krzysztof Kozlowski
2020-11-17  7:12       ` Alice Guo

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=20201114164128.GD14989@kozik-lap \
    --to=krzk@kernel.org \
    --cc=alice.guo@nxp.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=robh+dt@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).