Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3023040ybg; Mon, 28 Oct 2019 06:16:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2ghk2c+IvZQLABWQT3ZN/R99FZWPkuH8B0NKYwM1HLfiq52dxxCXnh6LoXx5I8XKG85FI X-Received: by 2002:a05:6402:160a:: with SMTP id f10mr19549599edv.161.1572268598641; Mon, 28 Oct 2019 06:16:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572268598; cv=none; d=google.com; s=arc-20160816; b=IJTZnnL3Awkv7edyL6azY0RQ/e9D9Lx5+l99ZSZNB6c4KP0nDdrd2BO4tWLvtV9KUV jD20NzRx6ZtRKDdH19SSA3UuYcPGalKd8Pt9iOQtoJwC2yIVeLlK/OkFy4E1gLlnLAtf 6U+VxhvH8MYmft0XZUFZ99Wvn1skDNSMqnfhXDdpisPkEE1J5PPkhqmVn4FjS3lxpemh vIBcMu8VPik5tr7NvbsrPYNpCVWVq1XKODgob7xRjG/T4/IdKi7KMjNB8+4/2eS2Hw2P SlNCS0sbyIYNH4ANVn4yKbBuTf2MERY3g01vAbpMNL2ChVikzOpl73f0JgOVMrItD/U/ APNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=+HUZ2jr0j/eamsMeWV1PCfN/os0yS1GZoxXltOf/3wg=; b=f0xQwCLWCboCDSNKGE4wYsoEgXaAGp0pztJzHzvshbuGPMe8h1HGtNwYKDWpeVC2Ky 6dUVn3dzaNF17cFkQsv8vLHdrlIEUmeUhhTkWMLPHHdY4Kw5mm2snWYJJbKzDIlFt8K4 4iSadoae5G7jw/GhTwo6qpT6PpER752jRSQFkftbYdPSrVeq4gbxq4s5pBforPNZ1IfR U3ysz4X5doHMSzTuPhyWIEm5nxIhr4mfR8R6YL0EvYfPeDhO2j4488he+9j9hykZicwG 0+2LOBOJwl46FlHzjZ5DracHKM+5pTsIZSysW0EfhPSCq8BEuBwppJw3zGhlwi9nqJ/v e6Ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce11si8436443edb.391.2019.10.28.06.16.15; Mon, 28 Oct 2019 06:16:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726686AbfJ1DQK (ORCPT + 99 others); Sun, 27 Oct 2019 23:16:10 -0400 Received: from inva020.nxp.com ([92.121.34.13]:39558 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbfJ1DQJ (ORCPT ); Sun, 27 Oct 2019 23:16:09 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 5C4711A0A7B; Mon, 28 Oct 2019 04:16:07 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 1A9A91A0B05; Mon, 28 Oct 2019 04:16:03 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 8BF9D402FC; Mon, 28 Oct 2019 11:15:57 +0800 (SGT) From: Anson Huang To: linux@armlinux.org.uk, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, aisheng.dong@nxp.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Linux-imx@nxp.com Subject: [PATCH 1/9] ARM: imx: Add serial number support for i.MX6Q Date: Mon, 28 Oct 2019 11:12:42 +0800 Message-Id: <1572232370-31580-2-git-send-email-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1572232370-31580-1-git-send-email-Anson.Huang@nxp.com> References: <1572232370-31580-1-git-send-email-Anson.Huang@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org i.MX6Q has a 64-bit SoC unique ID stored in OCOTP, it can be used as SoC serial number, see below example: root@imx6qpdlsolox:~# cat /sys/devices/soc0/serial_number 240F31D4E1FDFCA7 Signed-off-by: Anson Huang --- arch/arm/mach-imx/cpu.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c index 0b137ee..3293c1d 100644 --- a/arch/arm/mach-imx/cpu.c +++ b/arch/arm/mach-imx/cpu.c @@ -1,15 +1,20 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include #include +#include #include #include #include "hardware.h" #include "common.h" +#define OCOTP_UID_H 0x420 +#define OCOTP_UID_L 0x410 + unsigned int __mxc_cpu_type; static unsigned int imx_soc_revision; @@ -76,9 +81,13 @@ void __init imx_aips_allow_unprivileged_access( struct device * __init imx_soc_device_init(void) { struct soc_device_attribute *soc_dev_attr; + const char *ocotp_compat = NULL; struct soc_device *soc_dev; struct device_node *root; + struct regmap *ocotp; const char *soc_id; + u64 soc_uid = 0; + u32 val; int ret; soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); @@ -128,6 +137,7 @@ struct device * __init imx_soc_device_init(void) soc_id = "i.MX6SX"; break; case MXC_CPU_IMX6Q: + ocotp_compat = "fsl,imx6q-ocotp"; soc_id = "i.MX6Q"; break; case MXC_CPU_IMX6UL: @@ -153,18 +163,36 @@ struct device * __init imx_soc_device_init(void) } soc_dev_attr->soc_id = soc_id; + if (ocotp_compat) { + ocotp = syscon_regmap_lookup_by_compatible(ocotp_compat); + if (IS_ERR(ocotp)) + pr_err("%s: failed to find %s regmap!\n", __func__, ocotp_compat); + + regmap_read(ocotp, OCOTP_UID_H, &val); + soc_uid = val; + regmap_read(ocotp, OCOTP_UID_L, &val); + soc_uid <<= 32; + soc_uid |= val; + } + soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d", (imx_soc_revision >> 4) & 0xf, imx_soc_revision & 0xf); if (!soc_dev_attr->revision) goto free_soc; + soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid); + if (!soc_dev_attr->serial_number) + goto free_rev; + soc_dev = soc_device_register(soc_dev_attr); if (IS_ERR(soc_dev)) - goto free_rev; + goto free_serial_number; return soc_device_to_device(soc_dev); +free_serial_number: + kfree(soc_dev_attr->serial_number); free_rev: kfree(soc_dev_attr->revision); free_soc: -- 2.7.4