All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs
@ 2020-11-11  5:18 ` Ivan Zaentsev
  0 siblings, 0 replies; 6+ messages in thread
From: Ivan Zaentsev @ 2020-11-11  5:18 UTC (permalink / raw)
  To: Russell King
  Cc: Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Ivan Zaentsev, Evgeny Boger, linux-arm-kernel,
	linux-kernel

i.MX23 and i.MX28 SoCs unique identifiers are factory-programmed
in On-Chip OTP memory. i.MX28's 64-bit unique id is in
HW_OCOTP_OPS2:HW_OCOTP_OPS3 (see MCIMX28 Ref. Man., sec. 20.4.22-23).

i.MX23 provides 32-bit long unique id in HW_OCOTP_OPS3.
Though not clearly documented, there is a clue in sec. 35.9.3.

The unique id is reported in /sys/devices/soc0/serial_number
and in /proc/cpuinfo

Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Suggested-by: Evgeny Boger <boger@wirenboard.com>
---
 arch/arm/mach-mxs/mach-mxs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index c109f47e9cbc..af96368cc16a 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -23,6 +23,7 @@
 #include <asm/mach/map.h>
 #include <asm/mach/time.h>
 #include <asm/system_misc.h>
+#include <asm/system_info.h>
 
 #include "pm.h"
 
@@ -51,6 +52,9 @@
 #define MXS_CLR_ADDR		0x8
 #define MXS_TOG_ADDR		0xc
 
+#define HW_OCOTP_OPS2       19	/* offset 0x150 */
+#define HW_OCOTP_OPS3       20	/* offset 0x160 */
+
 static u32 chipid;
 static u32 socid;
 
@@ -379,6 +383,8 @@ static void __init mxs_machine_init(void)
 	struct device *parent;
 	struct soc_device *soc_dev;
 	struct soc_device_attribute *soc_dev_attr;
+	u64 soc_uid = 0;
+	const u32 *ocotp = mxs_get_ocotp();
 	int ret;
 
 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
@@ -394,8 +400,22 @@ static void __init mxs_machine_init(void)
 	soc_dev_attr->soc_id = mxs_get_soc_id();
 	soc_dev_attr->revision = mxs_get_revision();
 
+	if (socid == HW_DIGCTL_CHIPID_MX23) {
+		soc_uid = system_serial_low = ocotp[HW_OCOTP_OPS3];
+	} else if (socid == HW_DIGCTL_CHIPID_MX28) {
+		soc_uid = system_serial_high = ocotp[HW_OCOTP_OPS2];
+		soc_uid <<= 32;
+		system_serial_low = ocotp[HW_OCOTP_OPS3];
+		soc_uid |= system_serial_low;
+	}
+
+	if (soc_uid)
+		soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid);
+
 	soc_dev = soc_device_register(soc_dev_attr);
+
 	if (IS_ERR(soc_dev)) {
+		kfree(soc_dev_attr->serial_number);
 		kfree(soc_dev_attr->revision);
 		kfree(soc_dev_attr);
 		return;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs
@ 2020-11-11  5:18 ` Ivan Zaentsev
  0 siblings, 0 replies; 6+ messages in thread
From: Ivan Zaentsev @ 2020-11-11  5:18 UTC (permalink / raw)
  To: Russell King
  Cc: Shawn Guo, Sascha Hauer, Evgeny Boger, linux-kernel,
	NXP Linux Team, Pengutronix Kernel Team, Ivan Zaentsev,
	Fabio Estevam, linux-arm-kernel

i.MX23 and i.MX28 SoCs unique identifiers are factory-programmed
in On-Chip OTP memory. i.MX28's 64-bit unique id is in
HW_OCOTP_OPS2:HW_OCOTP_OPS3 (see MCIMX28 Ref. Man., sec. 20.4.22-23).

i.MX23 provides 32-bit long unique id in HW_OCOTP_OPS3.
Though not clearly documented, there is a clue in sec. 35.9.3.

The unique id is reported in /sys/devices/soc0/serial_number
and in /proc/cpuinfo

Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
Suggested-by: Evgeny Boger <boger@wirenboard.com>
---
 arch/arm/mach-mxs/mach-mxs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index c109f47e9cbc..af96368cc16a 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -23,6 +23,7 @@
 #include <asm/mach/map.h>
 #include <asm/mach/time.h>
 #include <asm/system_misc.h>
+#include <asm/system_info.h>
 
 #include "pm.h"
 
@@ -51,6 +52,9 @@
 #define MXS_CLR_ADDR		0x8
 #define MXS_TOG_ADDR		0xc
 
+#define HW_OCOTP_OPS2       19	/* offset 0x150 */
+#define HW_OCOTP_OPS3       20	/* offset 0x160 */
+
 static u32 chipid;
 static u32 socid;
 
@@ -379,6 +383,8 @@ static void __init mxs_machine_init(void)
 	struct device *parent;
 	struct soc_device *soc_dev;
 	struct soc_device_attribute *soc_dev_attr;
+	u64 soc_uid = 0;
+	const u32 *ocotp = mxs_get_ocotp();
 	int ret;
 
 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
@@ -394,8 +400,22 @@ static void __init mxs_machine_init(void)
 	soc_dev_attr->soc_id = mxs_get_soc_id();
 	soc_dev_attr->revision = mxs_get_revision();
 
+	if (socid == HW_DIGCTL_CHIPID_MX23) {
+		soc_uid = system_serial_low = ocotp[HW_OCOTP_OPS3];
+	} else if (socid == HW_DIGCTL_CHIPID_MX28) {
+		soc_uid = system_serial_high = ocotp[HW_OCOTP_OPS2];
+		soc_uid <<= 32;
+		system_serial_low = ocotp[HW_OCOTP_OPS3];
+		soc_uid |= system_serial_low;
+	}
+
+	if (soc_uid)
+		soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid);
+
 	soc_dev = soc_device_register(soc_dev_attr);
+
 	if (IS_ERR(soc_dev)) {
+		kfree(soc_dev_attr->serial_number);
 		kfree(soc_dev_attr->revision);
 		kfree(soc_dev_attr);
 		return;
-- 
2.25.1


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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs
  2020-11-11  5:18 ` Ivan Zaentsev
@ 2020-11-11 19:46   ` Fabio Estevam
  -1 siblings, 0 replies; 6+ messages in thread
From: Fabio Estevam @ 2020-11-11 19:46 UTC (permalink / raw)
  To: Ivan Zaentsev
  Cc: Russell King, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	NXP Linux Team, Evgeny Boger,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-kernel

Hi Ivan,

On Wed, Nov 11, 2020 at 2:19 AM Ivan Zaentsev
<ivan.zaentsev@wirenboard.ru> wrote:
>
> i.MX23 and i.MX28 SoCs unique identifiers are factory-programmed
> in On-Chip OTP memory. i.MX28's 64-bit unique id is in
> HW_OCOTP_OPS2:HW_OCOTP_OPS3 (see MCIMX28 Ref. Man., sec. 20.4.22-23).
>
> i.MX23 provides 32-bit long unique id in HW_OCOTP_OPS3.
> Though not clearly documented, there is a clue in sec. 35.9.3.
>
> The unique id is reported in /sys/devices/soc0/serial_number
> and in /proc/cpuinfo
>
> Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
> Suggested-by: Evgeny Boger <boger@wirenboard.com>

It looks good, thanks:

Reviewed-by: Fabio Estevam <festevam@gmail.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs
@ 2020-11-11 19:46   ` Fabio Estevam
  0 siblings, 0 replies; 6+ messages in thread
From: Fabio Estevam @ 2020-11-11 19:46 UTC (permalink / raw)
  To: Ivan Zaentsev
  Cc: Sascha Hauer, Evgeny Boger, Russell King, linux-kernel,
	NXP Linux Team, Pengutronix Kernel Team, Shawn Guo,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE

Hi Ivan,

On Wed, Nov 11, 2020 at 2:19 AM Ivan Zaentsev
<ivan.zaentsev@wirenboard.ru> wrote:
>
> i.MX23 and i.MX28 SoCs unique identifiers are factory-programmed
> in On-Chip OTP memory. i.MX28's 64-bit unique id is in
> HW_OCOTP_OPS2:HW_OCOTP_OPS3 (see MCIMX28 Ref. Man., sec. 20.4.22-23).
>
> i.MX23 provides 32-bit long unique id in HW_OCOTP_OPS3.
> Though not clearly documented, there is a clue in sec. 35.9.3.
>
> The unique id is reported in /sys/devices/soc0/serial_number
> and in /proc/cpuinfo
>
> Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
> Suggested-by: Evgeny Boger <boger@wirenboard.com>

It looks good, thanks:

Reviewed-by: Fabio Estevam <festevam@gmail.com>

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs
  2020-11-11  5:18 ` Ivan Zaentsev
@ 2020-11-16  8:10   ` Shawn Guo
  -1 siblings, 0 replies; 6+ messages in thread
From: Shawn Guo @ 2020-11-16  8:10 UTC (permalink / raw)
  To: Ivan Zaentsev
  Cc: Russell King, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, NXP Linux Team, Evgeny Boger, linux-arm-kernel,
	linux-kernel

On Wed, Nov 11, 2020 at 08:18:59AM +0300, Ivan Zaentsev wrote:
> i.MX23 and i.MX28 SoCs unique identifiers are factory-programmed
> in On-Chip OTP memory. i.MX28's 64-bit unique id is in
> HW_OCOTP_OPS2:HW_OCOTP_OPS3 (see MCIMX28 Ref. Man., sec. 20.4.22-23).
> 
> i.MX23 provides 32-bit long unique id in HW_OCOTP_OPS3.
> Though not clearly documented, there is a clue in sec. 35.9.3.
> 
> The unique id is reported in /sys/devices/soc0/serial_number
> and in /proc/cpuinfo
> 
> Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
> Suggested-by: Evgeny Boger <boger@wirenboard.com>
> ---
>  arch/arm/mach-mxs/mach-mxs.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
> index c109f47e9cbc..af96368cc16a 100644
> --- a/arch/arm/mach-mxs/mach-mxs.c
> +++ b/arch/arm/mach-mxs/mach-mxs.c
> @@ -23,6 +23,7 @@
>  #include <asm/mach/map.h>
>  #include <asm/mach/time.h>
>  #include <asm/system_misc.h>
> +#include <asm/system_info.h>

Can we move it above <asm/system_misc.h> to get them alphabetically
sorted?

>  
>  #include "pm.h"
>  
> @@ -51,6 +52,9 @@
>  #define MXS_CLR_ADDR		0x8
>  #define MXS_TOG_ADDR		0xc
>  
> +#define HW_OCOTP_OPS2       19	/* offset 0x150 */
> +#define HW_OCOTP_OPS3       20	/* offset 0x160 */

Use tabs instead of spaces for indent.

> +
>  static u32 chipid;
>  static u32 socid;
>  
> @@ -379,6 +383,8 @@ static void __init mxs_machine_init(void)
>  	struct device *parent;
>  	struct soc_device *soc_dev;
>  	struct soc_device_attribute *soc_dev_attr;
> +	u64 soc_uid = 0;
> +	const u32 *ocotp = mxs_get_ocotp();
>  	int ret;
>  
>  	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
> @@ -394,8 +400,22 @@ static void __init mxs_machine_init(void)
>  	soc_dev_attr->soc_id = mxs_get_soc_id();
>  	soc_dev_attr->revision = mxs_get_revision();
>  
> +	if (socid == HW_DIGCTL_CHIPID_MX23) {
> +		soc_uid = system_serial_low = ocotp[HW_OCOTP_OPS3];
> +	} else if (socid == HW_DIGCTL_CHIPID_MX28) {
> +		soc_uid = system_serial_high = ocotp[HW_OCOTP_OPS2];
> +		soc_uid <<= 32;
> +		system_serial_low = ocotp[HW_OCOTP_OPS3];
> +		soc_uid |= system_serial_low;
> +	}
> +
> +	if (soc_uid)
> +		soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid);
> +
>  	soc_dev = soc_device_register(soc_dev_attr);
> +

Unnecessary newline.

Shawn

>  	if (IS_ERR(soc_dev)) {
> +		kfree(soc_dev_attr->serial_number);
>  		kfree(soc_dev_attr->revision);
>  		kfree(soc_dev_attr);
>  		return;
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs
@ 2020-11-16  8:10   ` Shawn Guo
  0 siblings, 0 replies; 6+ messages in thread
From: Shawn Guo @ 2020-11-16  8:10 UTC (permalink / raw)
  To: Ivan Zaentsev
  Cc: Sascha Hauer, Evgeny Boger, Russell King, linux-kernel,
	NXP Linux Team, Pengutronix Kernel Team, Fabio Estevam,
	linux-arm-kernel

On Wed, Nov 11, 2020 at 08:18:59AM +0300, Ivan Zaentsev wrote:
> i.MX23 and i.MX28 SoCs unique identifiers are factory-programmed
> in On-Chip OTP memory. i.MX28's 64-bit unique id is in
> HW_OCOTP_OPS2:HW_OCOTP_OPS3 (see MCIMX28 Ref. Man., sec. 20.4.22-23).
> 
> i.MX23 provides 32-bit long unique id in HW_OCOTP_OPS3.
> Though not clearly documented, there is a clue in sec. 35.9.3.
> 
> The unique id is reported in /sys/devices/soc0/serial_number
> and in /proc/cpuinfo
> 
> Signed-off-by: Ivan Zaentsev <ivan.zaentsev@wirenboard.ru>
> Suggested-by: Evgeny Boger <boger@wirenboard.com>
> ---
>  arch/arm/mach-mxs/mach-mxs.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
> index c109f47e9cbc..af96368cc16a 100644
> --- a/arch/arm/mach-mxs/mach-mxs.c
> +++ b/arch/arm/mach-mxs/mach-mxs.c
> @@ -23,6 +23,7 @@
>  #include <asm/mach/map.h>
>  #include <asm/mach/time.h>
>  #include <asm/system_misc.h>
> +#include <asm/system_info.h>

Can we move it above <asm/system_misc.h> to get them alphabetically
sorted?

>  
>  #include "pm.h"
>  
> @@ -51,6 +52,9 @@
>  #define MXS_CLR_ADDR		0x8
>  #define MXS_TOG_ADDR		0xc
>  
> +#define HW_OCOTP_OPS2       19	/* offset 0x150 */
> +#define HW_OCOTP_OPS3       20	/* offset 0x160 */

Use tabs instead of spaces for indent.

> +
>  static u32 chipid;
>  static u32 socid;
>  
> @@ -379,6 +383,8 @@ static void __init mxs_machine_init(void)
>  	struct device *parent;
>  	struct soc_device *soc_dev;
>  	struct soc_device_attribute *soc_dev_attr;
> +	u64 soc_uid = 0;
> +	const u32 *ocotp = mxs_get_ocotp();
>  	int ret;
>  
>  	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
> @@ -394,8 +400,22 @@ static void __init mxs_machine_init(void)
>  	soc_dev_attr->soc_id = mxs_get_soc_id();
>  	soc_dev_attr->revision = mxs_get_revision();
>  
> +	if (socid == HW_DIGCTL_CHIPID_MX23) {
> +		soc_uid = system_serial_low = ocotp[HW_OCOTP_OPS3];
> +	} else if (socid == HW_DIGCTL_CHIPID_MX28) {
> +		soc_uid = system_serial_high = ocotp[HW_OCOTP_OPS2];
> +		soc_uid <<= 32;
> +		system_serial_low = ocotp[HW_OCOTP_OPS3];
> +		soc_uid |= system_serial_low;
> +	}
> +
> +	if (soc_uid)
> +		soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid);
> +
>  	soc_dev = soc_device_register(soc_dev_attr);
> +

Unnecessary newline.

Shawn

>  	if (IS_ERR(soc_dev)) {
> +		kfree(soc_dev_attr->serial_number);
>  		kfree(soc_dev_attr->revision);
>  		kfree(soc_dev_attr);
>  		return;
> -- 
> 2.25.1
> 

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-16  8:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11  5:18 [PATCH] ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs Ivan Zaentsev
2020-11-11  5:18 ` Ivan Zaentsev
2020-11-11 19:46 ` Fabio Estevam
2020-11-11 19:46   ` Fabio Estevam
2020-11-16  8:10 ` Shawn Guo
2020-11-16  8:10   ` Shawn Guo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.