From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3DEB606A31A for ; Wed, 2 Dec 2026 07:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=v0exzrN6; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=Sl5QEP9a DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=5x/yYxoWubl/bbAOZ8CB9rKEx0RjNOLDbjWdCobMb0c=; b=v0exzrN6taDe24qAm5ZUiKFV2h IkSFRtD+oRSml0XW/deXTnvM2pX21vr8a2dB4c+myRYwOIKkDfsaluKDNm+FITi/7uZB6My/NVacv VnenVTD1B0Bcwv8VKGjP/tlxg4EIYYXgrKVWxPl91ctPoIQkuDOcaiIY2f6lbVSeLZiJPdXEd3ymZ DY29XoSZm+gr/BAz8iXKXi1xjpHDhdOUeY58g/Jm96TA1kOMFTf+iZdxcwbpJNKcruWNSNt4FkalC T8E7LdoKd0CfZRwJ7aaT7lhYN02ZAwC2EQHDwRaJctVD1MyV9WXEmqidffP69tWqFMV7+zXq/8rJD L2/Nzh6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYerC-0000000AXcJ-2p0h; Wed, 02 Dec 2026 07:34:26 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYeqx-0000000AXGB-2CQ6 for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 07:34:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1796196851; x=1827732851; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mB5zufQu92uwEMG7w0/zb4Rk1zlPZb1BwJ5zGCxdF20=; b=Sl5QEP9aSl0XZtkp/nA474GbxRJ3Zi+raDfLhudEntZkDLS4HOxx95z9 bqlzwIQ0Iv40+LxmeYhc8UEo79xDLFtgC9N87MwaFBe2+2r7m1mKHvB62 ukD2GIWCn+CgUAkjpeV1HwjFmUZ6gtO6tXLrQs6gtygHfSM6j+xg3LZZy NnnKV8ruhaSGLmEF1Ouvwog6KahS9HcgbwWRG6McJ7LbECJIurPt1CHpx Vk/mTzh8c8u70XxZD8/NPd7Q4poWYZ5ZZ1etSdcsoBqS3n9BEYDZ5ZOoz 5N1hx6XMpgCZqhPHrOv9zJQYldefY0SQmdU99846igdiV+W8J093V4jFP Q==; X-CSE-ConnectionGUID: CqQj0UqLTjWwe5xi5zbeaQ== X-CSE-MsgGUID: 28VBbqgqRgiWeVrcXSlSuw== X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="67333608" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 02 Dec 2026 00:06:03 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Wed, 2 Dec 2026 00:06:01 -0700 Received: from che-ll-i67070a.microchip.com (10.10.85.11) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Wed, 2 Dec 2026 00:05:56 -0700 From: Varshini Rajendran To: Jonathan Cameron , Srinivas Kandagatla , Claudiu Beznea CC: Eugen Hristev , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Rob Herring , "Krzysztof Kozlowski" , Conor Dooley , "Nicolas Ferre" , Alexandre Belloni , , , , , Subject: [PATCH v7 10/18] nvmem: microchip-otpc: add tag-based packet lookup Date: Wed, 2 Dec 2026 12:34:48 +0530 Message-ID: <20261202070458.87970-11-varshini.rajendran@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202070458.87970-1-varshini.rajendran@microchip.com> References: <20261202070458.87970-1-varshini.rajendran@microchip.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_233411_617251_86378682 X-CRM114-Status: GOOD ( 30.86 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Add support for accessing OTP packets by their tag which is a FourCC while preserving backward compatibility with the existing ID-based lookup. The OTP memory layout can vary across devices and may change over time, making the packet ID approach unreliable when the memory map is not known in advance. The packet tag provides a reliable way to identify and access packets without prior knowledge of the OTP memory layout. Two offset encodings are now supported: 1. Legacy ID-based: offset = OTP_PKT(id) = id * 4 Used in DT as: reg = ; 2. TAG-based: offset = 4-byte ASCII packet tag (FourCC) Used in DT as: reg = <0x41435354 0x4c>; (tag "ACST") The driver resolves offsets matching valid legacy selectors (multiples of 4 within the packet count) through ID lookup, falling back to tag lookup for other valid values. This ensures existing device trees continue to work while enabling new tag-based access. During probe, packet meta data including the tag is read and cached. The stride of the nvmem memory is set to 1 in order to support tag based offsets, comment in the header file is updated accordingly. Signed-off-by: Varshini Rajendran --- drivers/nvmem/microchip-otpc.c | 98 +++++++++++++++++-- .../nvmem/microchip,sama7g5-otpc.h | 4 +- 2 files changed, 91 insertions(+), 11 deletions(-) diff --git a/drivers/nvmem/microchip-otpc.c b/drivers/nvmem/microchip-otpc.c index 92524016a8fb..d51944faf58b 100644 --- a/drivers/nvmem/microchip-otpc.c +++ b/drivers/nvmem/microchip-otpc.c @@ -23,6 +23,8 @@ #define MCHP_OTPC_SR_READ BIT(6) #define MCHP_OTPC_HR (0x20) #define MCHP_OTPC_HR_SIZE GENMASK(15, 8) +#define MCHP_OTPC_HR_PACKET GENMASK(2, 0) +#define MCHP_OTPC_HR_PACKET_REGULAR 1 #define MCHP_OTPC_DR (0x24) #define MCHP_OTPC_NAME "mchp-otpc" @@ -47,11 +49,13 @@ struct mchp_otpc { * @list: list head * @id: packet ID * @offset: packet offset (in words) in OTP memory + * @tag: 4-byte ASCII (FourCC) tag of the packet */ struct mchp_otpc_packet { struct list_head list; u32 id; u32 offset; + u32 tag; }; static struct mchp_otpc_packet *mchp_otpc_id_to_packet(struct mchp_otpc *otpc, @@ -70,6 +74,50 @@ static struct mchp_otpc_packet *mchp_otpc_id_to_packet(struct mchp_otpc *otpc, return NULL; } +static struct mchp_otpc_packet *mchp_otpc_tag_to_packet(struct mchp_otpc *otpc, u32 tag) +{ + struct mchp_otpc_packet *packet; + + list_for_each_entry(packet, &otpc->packets, list) { + if (packet->tag == tag) + return packet; + } + + return NULL; +} + +static bool mchp_otpc_is_valid_fourcc(u32 tag) +{ + for (unsigned int i = 0; i < sizeof(tag); i++) { + u8 c = (tag >> (i * 8)) & 0xff; + + if (c < 0x20 || c > 0x7e) + return false; + } + + return true; +} + +static struct mchp_otpc_packet *mchp_otpc_resolve_packet(struct mchp_otpc *otpc, u32 off) +{ + /* + * Legacy id based packet access: offset = id * 4 + * Inside the driver we use continuous unsigned integer numbers + * for packet id, thus divide off by 4 before passing it to + * mchp_otpc_id_to_packet(). + */ + u32 remainder = off % 4; + u32 id = off / 4; + + if (!remainder && id < otpc->npackets) + return mchp_otpc_id_to_packet(otpc, id); + + /* + * TAG-based packet access: offset is a 4-byte ASCII tag (FourCC) + */ + return mchp_otpc_tag_to_packet(otpc, off); +} + static int mchp_otpc_prepare_read(struct mchp_otpc *otpc, unsigned int offset) { @@ -140,8 +188,29 @@ static int mchp_otpc_prepare_read(struct mchp_otpc *otpc, * offset returned by hardware. * * For this, the read function will return the first requested bytes in the - * packet. The user will have to be aware of the memory footprint before doing - * the read request. + * packet. + * + * Two offset encodings are supported: + * + * 1. Legacy ID-based: offset = OTP_PKT(id) = id * 4 + * Used in DT as: reg = ; + * 2. TAG-based: offset = 4-byte ASCII packet tag (FourCC) + * Used in DT as: reg = <0x41435354 0x4c>; (tag "ACST") + * + * To use the legacy ID based packet lookup the user will have to be aware of + * the memory footprint before doing the read request. + * + * But by using the TAG based packet lookup, the user won't have to be aware + * of the memory footprint before doing the read request since this driver has + * it abstracted and taken care of. + * + * Practically, there is no way of knowing the mapping of the OTP memory table + * in advance for every device. But by using the packet tag - the identifier + * ASCII value (FourCC), the packets can be recognized without being aware of the + * flashed OTP memory map table and the payload can be acquired reliably. + * + * While the legacy ID based lookup is still supported, TAG based approach is + * recommended. */ static int mchp_otpc_read(void *priv, unsigned int off, void *val, size_t bytes) @@ -154,12 +223,11 @@ static int mchp_otpc_read(void *priv, unsigned int off, void *val, int ret, payload_size; /* - * We reach this point with off being multiple of stride = 4 to - * be able to cross the subsystem. Inside the driver we use continuous - * unsigned integer numbers for packet id, thus divide off by 4 - * before passing it to mchp_otpc_id_to_packet(). + * From this point the offset has to be translated into the actual + * packet. For this we traverse the table of contents stored in a list + * "packet" based on the access type - packet id or tag. */ - packet = mchp_otpc_id_to_packet(otpc, off / 4); + packet = mchp_otpc_resolve_packet(otpc, off); if (!packet) return -EINVAL; offset = packet->offset; @@ -193,7 +261,7 @@ static int mchp_otpc_read(void *priv, unsigned int off, void *val, static int mchp_otpc_init_packets_list(struct mchp_otpc *otpc, u32 *size) { struct mchp_otpc_packet *packet; - u32 word, word_pos = 0, id = 0, npackets = 0, payload_size; + u32 word, word_pos = 0, id = 0, npackets = 0, payload_size, type; int ret; INIT_LIST_HEAD(&otpc->packets); @@ -215,6 +283,18 @@ static int mchp_otpc_init_packets_list(struct mchp_otpc *otpc, u32 *size) packet->id = id++; packet->offset = word_pos; + type = FIELD_GET(MCHP_OTPC_HR_PACKET, word); + + if (type == MCHP_OTPC_HR_PACKET_REGULAR) { + u32 tag; + + writel_relaxed(0, otpc->base + MCHP_OTPC_AR); + tag = readl_relaxed(otpc->base + MCHP_OTPC_DR); + + if (mchp_otpc_is_valid_fourcc(tag)) + packet->tag = tag; + } + INIT_LIST_HEAD(&packet->list); list_add_tail(&packet->list, &otpc->packets); @@ -236,7 +316,7 @@ static struct nvmem_config mchp_nvmem_config = { .type = NVMEM_TYPE_OTP, .read_only = true, .word_size = 4, - .stride = 4, + .stride = 1, .reg_read = mchp_otpc_read, }; diff --git a/include/dt-bindings/nvmem/microchip,sama7g5-otpc.h b/include/dt-bindings/nvmem/microchip,sama7g5-otpc.h index f570b23165a2..5f72e75ad091 100644 --- a/include/dt-bindings/nvmem/microchip,sama7g5-otpc.h +++ b/include/dt-bindings/nvmem/microchip,sama7g5-otpc.h @@ -4,8 +4,8 @@ #define _DT_BINDINGS_NVMEM_MICROCHIP_OTPC_H /* - * Need to have it as a multiple of 4 as NVMEM memory is registered with - * stride = 4. + * Need to have it as a multiple of 4 for the legacy id based packet + * access. */ #define OTP_PKT(id) ((id) * 4) -- 2.43.0