Skip to contentSkip to conversation

soc: imx8: Add i.MX8MQ UID(unique identifier) support

PATCH Applied [email protected] 2 participants 3 messages Jun 26, 2019 – Jul 18, 2019 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 soc: imx8: Add i.MX8MQ UID(unique identifier) support

From: Anson Huang <[email protected]>

Add i.MX8MQ SoC UID(unique identifier) support, user can read it from sysfs:

root@imx8mqevk:~# cat /sys/devices/soc0/soc_uid
D56911D6F060954B
---
 drivers/soc/imx/soc-imx8.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/soc/imx/soc-imx8.c +22 -0
index f924ae8..c19ef4b 100644
@@ -16,6 +16,9 @@
 #define IMX8MQ_SW_INFO_B1		0x40
 #define IMX8MQ_SW_MAGIC_B1		0xff0055aa
 
+#define OCOTP_UID_LOW			0x410
+#define OCOTP_UID_HIGH			0x420
+
 /* Same as ANADIG_DIGPROG_IMX7D */
 #define ANADIG_DIGPROG_IMX8MM	0x800
 
@@ -24,6 +27,16 @@ struct imx8_soc_data {
 	u32 (*soc_revision)(void);
 };
 
+static u64 soc_uid;
+
+static ssize_t soc_uid_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%016llX\n", soc_uid);
+}
+
+static DEVICE_ATTR_RO(soc_uid);
+
 static u32 __init imx8mq_soc_revision(void)
 {
 	struct device_node *np;
@@ -42,6 +55,10 @@ static u32 __init imx8mq_soc_revision(void)
 	if (magic == IMX8MQ_SW_MAGIC_B1)
 		rev = REV_B1;
 
+	soc_uid = readl_relaxed(ocotp_base + OCOTP_UID_HIGH);
+	soc_uid <<= 32;
+	soc_uid |= readl_relaxed(ocotp_base + OCOTP_UID_LOW);
+
 	iounmap(ocotp_base);
 
 out:
@@ -140,6 +157,11 @@ static int __init imx8_soc_init(void)
 		goto free_rev;
 	}
 
+	ret = device_create_file(soc_device_to_device(soc_dev),
+				 &dev_attr_soc_uid);
+	if (ret)
+		goto free_rev;
+
 	if (IS_ENABLED(CONFIG_ARM_IMX_CPUFREQ_DT))
 		platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 soc: imx8: Add i.MX8MM UID(unique identifier) support

From: Anson Huang <[email protected]>

Add i.MX8MM SoC UID(unique identifier) support, user can read it from sysfs:

root@imx8mmevk:~# cat /sys/devices/soc0/soc_uid
B365FA0A5C85D6EE
---
 drivers/soc/imx/soc-imx8.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/soc/imx/soc-imx8.c +23 -0
index c19ef4b..b9831576 100644
@@ -66,6 +66,26 @@ static u32 __init imx8mq_soc_revision(void)
 	return rev;
 }
 
+static void __init imx8mm_soc_uid(void)
+{
+	void __iomem *ocotp_base;
+	struct device_node *np;
+
+	np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp");
+	if (!np)
+		return;
+
+	ocotp_base = of_iomap(np, 0);
+	WARN_ON(!ocotp_base);
+
+	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);
+}
+
 static u32 __init imx8mm_soc_revision(void)
 {
 	struct device_node *np;
@@ -83,6 +103,9 @@ static u32 __init imx8mm_soc_revision(void)
 
 	iounmap(anatop_base);
 	of_node_put(np);
+
+	imx8mm_soc_uid();
+
 	return rev;
 }
 
Signature · 1 line
2.7.4