* [PATCH] nvmem: imx-ocotp: read uniq CPU ID and export as system serial number
@ 2017-10-04 15:16 Marcus Folkesson
[not found] ` <20171004151616.2622-1-marcus.folkesson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Marcus Folkesson @ 2017-10-04 15:16 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Mark Rutland
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Marcus Folkesson
The uniq ID is usually exported as ATAG_SERIAL but in case of
devicetrees, this information is not passed.
The uniq ID is stored in OCOTP memory (bank 0, Word 1,2) on imx CPUs.
Read the ID and set as system serial number.
This function is activated by setting `read-system-serial`
dt property for the imx-ocotp node.
Signed-off-by: Marcus Folkesson <marcus.folkesson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
Comment:
I'm not sure if this functionality really should be in a device driver.
Maybe it should be in arch/arm/mach-imx/. However, it's not
completely wrong so I give it a shot.
.../devicetree/bindings/nvmem/imx-ocotp.txt | 1 +
drivers/nvmem/imx-ocotp.c | 38 ++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt b/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
index 70d791b03ea1..bf0cc9e5e50f 100644
--- a/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
+++ b/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
@@ -16,6 +16,7 @@ Required properties:
Optional properties:
- read-only: disable write access
+- read-system-serial: read uniq ID and export as system serial number. Available in /proc/cpuinfo
Example:
diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index 193ca8fd350a..574cab017611 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -28,10 +28,16 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/delay.h>
+#include <asm/system_info.h>
#define IMX_OCOTP_OFFSET_B0W0 0x400 /* Offset from base address of the
* OTP Bank0 Word0
*/
+
+/* Uniq ID used for Serial number */
+#define IMX_OCOTP_OFFSET_UID_LOW (IMX_OCOTP_OFFSET_B0W0 + 0x10)
+#define IMX_OCOTP_OFFSET_UID_HIGH (IMX_OCOTP_OFFSET_B0W0 + 0x20)
+
#define IMX_OCOTP_OFFSET_PER_WORD 0x10 /* Offset between the start addr
* of two consecutive OTP words.
*/
@@ -298,6 +304,34 @@ static int imx_ocotp_write(void *context, unsigned int offset, void *val,
return bytes;
}
+static int imx_ocotp_setserial(struct ocotp_priv *priv)
+{
+ int ret;
+
+ mutex_lock(&ocotp_mutex);
+
+ ret = clk_prepare_enable(priv->clk);
+ if (ret < 0) {
+ mutex_unlock(&ocotp_mutex);
+ dev_err(priv->dev, "failed to prepare/enable ocotp clk\n");
+ return ret;
+ }
+
+ ret = imx_ocotp_wait_for_busy(priv->base, 0);
+ if (ret < 0) {
+ dev_err(priv->dev, "timeout during read setup\n");
+ goto out;
+ }
+
+ system_serial_low = readl(priv->base + IMX_OCOTP_OFFSET_UID_LOW);
+ system_serial_high = readl(priv->base + IMX_OCOTP_OFFSET_UID_HIGH);
+
+out:
+ clk_disable_unprepare(priv->clk);
+ mutex_unlock(&ocotp_mutex);
+ return ret;
+}
+
static struct nvmem_config imx_ocotp_nvmem_config = {
.name = "imx-ocotp",
.read_only = false,
@@ -352,6 +386,10 @@ static int imx_ocotp_probe(struct platform_device *pdev)
if (IS_ERR(nvmem))
return PTR_ERR(nvmem);
+ if (of_property_read_bool(pdev->dev.of_node, "read-system-serial")) {
+ if (!imx_ocotp_setserial(priv))
+ dev_warn(&pdev->dev, "Could not read CPU uniq serial number");
+ }
platform_set_drvdata(pdev, nvmem);
return 0;
--
2.13.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] nvmem: imx-ocotp: read uniq CPU ID and export as system serial number
[not found] ` <20171004151616.2622-1-marcus.folkesson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2017-10-04 15:44 ` Mark Rutland
2017-10-04 19:41 ` Marcus Folkesson
2017-10-07 7:49 ` kbuild test robot
1 sibling, 1 reply; 4+ messages in thread
From: Mark Rutland @ 2017-10-04 15:44 UTC (permalink / raw)
To: Marcus Folkesson
Cc: Srinivas Kandagatla, Rob Herring,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Wed, Oct 04, 2017 at 05:16:16PM +0200, Marcus Folkesson wrote:
> The uniq ID is usually exported as ATAG_SERIAL but in case of
> devicetrees, this information is not passed.
>
> The uniq ID is stored in OCOTP memory (bank 0, Word 1,2) on imx CPUs.
> Read the ID and set as system serial number.
>
> This function is activated by setting `read-system-serial`
> dt property for the imx-ocotp node.
>
> Signed-off-by: Marcus Folkesson <marcus.folkesson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>
> Comment:
> I'm not sure if this functionality really should be in a device driver.
> Maybe it should be in arch/arm/mach-imx/. However, it's not
> completely wrong so I give it a shot.
>
> .../devicetree/bindings/nvmem/imx-ocotp.txt | 1 +
> drivers/nvmem/imx-ocotp.c | 38 ++++++++++++++++++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt b/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
> index 70d791b03ea1..bf0cc9e5e50f 100644
> --- a/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
> +++ b/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
> @@ -16,6 +16,7 @@ Required properties:
>
> Optional properties:
> - read-only: disable write access
> +- read-system-serial: read uniq ID and export as system serial number. Available in /proc/cpuinfo
As described, this is a pure SW option (
/proc/cpuinfo is a not a HW detail, and whether or not to export this
information there is a policy. So as described, this shouldn't be in the
DT.
Are you just trying to describe whether hte information is available in
the OCOTP memory?
e.g. maybe this should be something like:
- has-unique-id: OCOTP bank0, Words 1 & 2 contain a unique ID
identifying the system.
Thanks,
Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nvmem: imx-ocotp: read uniq CPU ID and export as system serial number
2017-10-04 15:44 ` Mark Rutland
@ 2017-10-04 19:41 ` Marcus Folkesson
0 siblings, 0 replies; 4+ messages in thread
From: Marcus Folkesson @ 2017-10-04 19:41 UTC (permalink / raw)
To: Mark Rutland; +Cc: Srinivas Kandagatla, Rob Herring, devicetree, linux-kernel
Hi Mark,
On Wed, Oct 04, 2017 at 04:44:29PM +0100, Mark Rutland wrote:
> On Wed, Oct 04, 2017 at 05:16:16PM +0200, Marcus Folkesson wrote:
> > The uniq ID is usually exported as ATAG_SERIAL but in case of
> > devicetrees, this information is not passed.
> >
> > The uniq ID is stored in OCOTP memory (bank 0, Word 1,2) on imx CPUs.
> > Read the ID and set as system serial number.
> >
> > This function is activated by setting `read-system-serial`
> > dt property for the imx-ocotp node.
> >
> > Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
> > ---
> >
> > Comment:
> > I'm not sure if this functionality really should be in a device driver.
> > Maybe it should be in arch/arm/mach-imx/. However, it's not
> > completely wrong so I give it a shot.
> >
> > .../devicetree/bindings/nvmem/imx-ocotp.txt | 1 +
> > drivers/nvmem/imx-ocotp.c | 38 ++++++++++++++++++++++
> > 2 files changed, 39 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt b/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
> > index 70d791b03ea1..bf0cc9e5e50f 100644
> > --- a/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
> > +++ b/Documentation/devicetree/bindings/nvmem/imx-ocotp.txt
> > @@ -16,6 +16,7 @@ Required properties:
> >
> > Optional properties:
> > - read-only: disable write access
> > +- read-system-serial: read uniq ID and export as system serial number. Available in /proc/cpuinfo
>
> As described, this is a pure SW option (
>
> /proc/cpuinfo is a not a HW detail, and whether or not to export this
> information there is a policy. So as described, this shouldn't be in the
> DT.
Ok, I agree with that.
>
> Are you just trying to describe whether hte information is available in
> the OCOTP memory?
No, the information is available for all concerned iMX CPUs what I can
tell. My intention was to flag if the driver should make use of it, but
the DT seems to be the wrong way to go.
>
> e.g. maybe this should be something like:
>
> - has-unique-id: OCOTP bank0, Words 1 & 2 contain a unique ID
> identifying the system.
>
> Thanks,
> Mark.
I will come up with an v2 where this is not configurable.
Thanks,
Marcus Folkesson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nvmem: imx-ocotp: read uniq CPU ID and export as system serial number
[not found] ` <20171004151616.2622-1-marcus.folkesson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-04 15:44 ` Mark Rutland
@ 2017-10-07 7:49 ` kbuild test robot
1 sibling, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2017-10-07 7:49 UTC (permalink / raw)
Cc: kbuild-all-JC7UmRfGjtg, Srinivas Kandagatla, Rob Herring,
Mark Rutland, devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Marcus Folkesson
[-- Attachment #1: Type: text/plain, Size: 1009 bytes --]
Hi Marcus,
[auto build test ERROR on linus/master]
[also build test ERROR on v4.14-rc3 next-20170929]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Marcus-Folkesson/nvmem-imx-ocotp-read-uniq-CPU-ID-and-export-as-system-serial-number/20171007-122234
config: i386-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All errors (new ones prefixed by >>):
>> drivers/nvmem/imx-ocotp.c:31:29: fatal error: asm/system_info.h: No such file or directory
#include <asm/system_info.h>
^
compilation terminated.
vim +31 drivers/nvmem/imx-ocotp.c
> 31 #include <asm/system_info.h>
32
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 61800 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-07 7:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-04 15:16 [PATCH] nvmem: imx-ocotp: read uniq CPU ID and export as system serial number Marcus Folkesson
[not found] ` <20171004151616.2622-1-marcus.folkesson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-04 15:44 ` Mark Rutland
2017-10-04 19:41 ` Marcus Folkesson
2017-10-07 7:49 ` kbuild test robot
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).