Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp96452pxb; Tue, 10 Nov 2020 21:21:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYwBajafyXl18UeY7p7hAWNTgxDRXMkjFyF6BQJfSD/f/ytO7MLVR1t6Gby7NNNxawDTYc X-Received: by 2002:a17:906:6409:: with SMTP id d9mr23250794ejm.344.1605072097615; Tue, 10 Nov 2020 21:21:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605072097; cv=none; d=google.com; s=arc-20160816; b=jwetcU4Dx9fCz7LO212s7Mw5pITqn6jz7KtNU9jUaf3YypVOyVzlFJ2cmSsnDmL/Dw tRqFL4SmzY64smJcn6GDMRlO9h6wL4k1nxswklV41+xx0QVph8ePgSJIUgLW1OylEx8k JoRdTcEcRtEZxOnDXhZt4SL7Hxt4f798WUeMCESiAtgsU3xNiQBE+ABQGZxaRAwn8w2a gpVq/a4k5KQOW0mjDbIrtoCOtdYuDAzjA0/R5rPH4X6yVgd7HjEI74y/uJugV8Zf6q1j VwK8g4WakEA6JmRLTv27goVZxvM9As58qlf46H+1o1yDqOFLgBPPjSuzrEFg7536n3QO qn3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3xHgO6xQjRtzCqJvgfsirBMsV6gq7sad2fSKmrTwmkk=; b=sPrf4P+ycDKV+xF9UNZ2RhRvy1g3rS+InqcEcXEAKOfCvNHzHOjC38b53zc7xAol9C ZkH3M5tPVJ16x7B8YiX/sFAeUQIjYZxk9yoLEAY3VuC7M1VTZ7ndr3d0/XSjuG1+K/Ls fEy56FXK6ZO2nIYMW9D2DKSCU+WDG20gMCAeO703/DuPL47th6lqtHwmH1eBC5acjTiL lz+EPUGjj/sXKJ2absY+gfKAllU6uxVaOxxfwwKhupaRGr/ZQhhWxfmcLLrayKf+JX0v TQyO9MHVQopX1DxeDh4szlBkHPexvn4r5MG6/dUkly7/BuME9g2l0+L2EfhLe2r7livJ EoOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wirenboard-ru.20150623.gappssmtp.com header.s=20150623 header.b=bEQ+m0X2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r7si593299ejr.8.2020.11.10.21.21.14; Tue, 10 Nov 2020 21:21:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@wirenboard-ru.20150623.gappssmtp.com header.s=20150623 header.b=bEQ+m0X2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726036AbgKKFTs (ORCPT + 99 others); Wed, 11 Nov 2020 00:19:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbgKKFTs (ORCPT ); Wed, 11 Nov 2020 00:19:48 -0500 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9256DC0613D1 for ; Tue, 10 Nov 2020 21:19:46 -0800 (PST) Received: by mail-lf1-x142.google.com with SMTP id j205so1485382lfj.6 for ; Tue, 10 Nov 2020 21:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wirenboard-ru.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3xHgO6xQjRtzCqJvgfsirBMsV6gq7sad2fSKmrTwmkk=; b=bEQ+m0X2CTWHLyFuF4wxigLJkCQRl1Rxh2Sjtj32Z0NJjEBbcMuMg9xVkLWdomzwcC pWqAGSn5CC4FjFjf9RGLMRaaT6lhL8dls7hngnhyhX/A/oW1+Et1Su2s/y1Cdbu7nZWy sg0MyMiqFkG431SPFAtoLTPdlYVEPaGchnl2/yF//gokU9vXLAh9LwWSjxqpLC8D3Y7k 0vcFoEk4BIv8YQF0N5c8SI1pcPb3H/giOpe93nzJk0ee/KKhKmFR+iI+oXYdQGjwmomw UMVBYeBk+tnB8LFf8u4bSFSEgtIzIhekXbRRdhV3gaXRAciyqIdRJvHmcMqG+NyCYl9w nqbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3xHgO6xQjRtzCqJvgfsirBMsV6gq7sad2fSKmrTwmkk=; b=rQLrAaUrt1NS9yvp+EGqgxQDmFF6LRHIIfdahXwcuSPvHgzv/eOzJ4QFGOXQotW7OA 8A96X2RDnIGtNmSNzzDIROfq7GlNGh4mi5UYjzcUQhRYbn17GSI9vgaKpuRtuoKgk5XY TRJijep4I66LUrWYexrFYrzTKggXNIaOOtDxkoSHd0r13JcSoyAXNxS1XiBi5ReGu3i4 jpqDb7TRIYkkN6l/ouApcJjuBBwyWmuNYBX7bvsjwADUef2KYc5I5/85SbdKIC9mNfxh ywhW6MywvVBcqB6CKr/6+/R+sNWZEQ7gxgFZrXgBQf8HrsQ0U91P0as8qixs9PQtCvv0 6Fmw== X-Gm-Message-State: AOAM5335fNjCqfgXdVW7h6/wmz9/o6PG5vJzf0GtW8d3G3+MxgP+KzpV w5auhixaP6PLlggWkdmFHzgXjQ== X-Received: by 2002:a19:8c7:: with SMTP id 190mr8297227lfi.74.1605071984759; Tue, 10 Nov 2020 21:19:44 -0800 (PST) Received: from localhost.localdomain (95-30-131-0.broadband.corbina.ru. [95.30.131.0]) by smtp.googlemail.com with ESMTPSA id x9sm109572lfg.93.2020.11.10.21.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 21:19:43 -0800 (PST) From: Ivan Zaentsev To: Russell King Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Ivan Zaentsev , Evgeny Boger , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] ARM: mxs: Add serial number support for i.MX23, i.MX28 SoCs Date: Wed, 11 Nov 2020 08:18:59 +0300 Message-Id: <20201111051859.2776-1-ivan.zaentsev@wirenboard.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Suggested-by: Evgeny Boger --- 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 #include #include +#include #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