From patchwork Mon Dec 2 11:22:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 13890326 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 22A7CD7830D for ; Mon, 2 Dec 2024 11:33:26 +0000 (UTC) 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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gFcULvaTRSIVU4OrsVetXuBE0xHY6aiWfJVoJi5EFAY=; b=dc9CKo/ztqD6vPpG5pHZMm4UW6 AiWBVx8kkaiQ348pvTWLzyQ0dnIB8FT10wCDclFbJTPt5+9TZyRgdWC1ejAC203ZOyQ1FcAdDyyQ9 7EODKAswCtcY4FSl8UlSOLniKuxQKT6ESSNbuQ0dyq9+3fXPedswQnX+OOgmqiCgp8JbDYhtcogtB RqazPvGIL4uv1wCGOqp3YHkaP/vpguje7BCPVnrrPWZlQHT6m00YZyHMvxKzVcvxYXl1DGAFuBePb NH7aQoivfIFdIPCDg1/SJ5ruHK8UvX4e/bJ9v5sAQdZHn6Hz0y4DWJyv2j0Radjoj8orL0bWttlGv ih/ToAIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tI4g1-00000005ugY-0K12; Mon, 02 Dec 2024 11:33:17 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tI4Vg-00000005sEx-1QVF for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 11:22:37 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tI4Ve-0000UH-EB; Mon, 02 Dec 2024 12:22:34 +0100 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tI4Vc-001Hsx-3A; Mon, 02 Dec 2024 12:22:33 +0100 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1tI4Vd-003R1L-2A; Mon, 02 Dec 2024 12:22:33 +0100 From: Sascha Hauer Date: Mon, 02 Dec 2024 12:22:29 +0100 Subject: [PATCH v2 1/4] nvmem: imx-ocotp-ele: simplify read beyond device check MIME-Version: 1.0 Message-Id: <20241202-imx-ele-ocotp-fixes-v2-1-3c021a97eb5d@pengutronix.de> References: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> In-Reply-To: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam , Greg Kroah-Hartman , Peng Fan Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer , stable X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733138553; l=1029; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=P8t38gZgVtQGfHlRwL+12Evj7x6PEBaDv2Q4YuWoIQI=; b=DasEWzoF6ivaUdopeZSea2AgkEgyHZjhfiWd2ODse1tTTQJ7TQrl90n+TxlMZQthwA7kUTQ61 U/nxZmnN4mTAxLnoI8gz77cuGsFHOvvn+MW/dYwxfs+4R52WGpO/4Ca X-Developer-Key: i=s.hauer@pengutronix.de; a=ed25519; pk=4kuc9ocmECiBJKWxYgqyhtZOHj5AWi7+d0n/UjhkwTg= X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: s.hauer@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_032236_382285_B2994C5F X-CRM114-Status: GOOD ( 13.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Do the read beyond device check on function entry in bytes instead of 32bit words which is easier to follow. Fixes: 22e9e6fcfb504 ("nvmem: imx: support i.MX93 OCOTP") Signed-off-by: Sascha Hauer Cc: stable --- drivers/nvmem/imx-ocotp-ele.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index 1ba4944976987..2e186b7d3b040 100644 --- a/drivers/nvmem/imx-ocotp-ele.c +++ b/drivers/nvmem/imx-ocotp-ele.c @@ -72,13 +72,13 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz void *p; int i; + if (offset + bytes > priv->data->size) + bytes = priv->data->size - offset; + index = offset; num_bytes = round_up(bytes, 4); count = num_bytes >> 2; - if (count > ((priv->data->size >> 2) - index)) - count = (priv->data->size >> 2) - index; - p = kzalloc(num_bytes, GFP_KERNEL); if (!p) return -ENOMEM; From patchwork Mon Dec 2 11:22:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 13890330 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17FAED7830C for ; Mon, 2 Dec 2024 11:36:26 +0000 (UTC) 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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=47CdDctxRQB/vaCPOxPfxcy++Ca9MmaFslwiTKAmdrU=; b=D7mRWlgW56yXf+dErJvGQA3e77 X59AiTSAPM6hOuN7dPAg1hycMmQYzhuRHdswRBwX+h+tTj/+A+Giq4Q1hrxRwCUxHpHkrASO53gKF R11v+4w22i35cGKolYHd9NKA2oJxYxI+giRkP31V/gRn62H8YvbFsJX1tpDc9mzshzVi+DSHHyX3J M/DE8OHc6aNNhDcreEONR/Mn+wHrzjHaXFjYnXiMjgnRLpK9jbcxpEZ/st9nmpYzQ/2+xjXNiJFCM 9zWtarN/M9drGj6eDNvsg/MxnQ27Q8CX9wuD07JYbkqVFakouzAUG+Sn7tKUQfX1jW/OUtTAY1ACN qkzIxj+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tI4it-00000005vPs-3xmE; Mon, 02 Dec 2024 11:36:15 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tI4Vw-00000005sIg-10nO for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 11:22:53 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tI4Ve-0000UI-ED; Mon, 02 Dec 2024 12:22:34 +0100 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tI4Vd-001Ht0-00; Mon, 02 Dec 2024 12:22:33 +0100 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1tI4Vd-003R1L-2C; Mon, 02 Dec 2024 12:22:33 +0100 From: Sascha Hauer Date: Mon, 02 Dec 2024 12:22:30 +0100 Subject: [PATCH v2 2/4] nvmem: imx-ocotp-ele: fix reading from non zero offset MIME-Version: 1.0 Message-Id: <20241202-imx-ele-ocotp-fixes-v2-2-3c021a97eb5d@pengutronix.de> References: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> In-Reply-To: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam , Greg Kroah-Hartman , Peng Fan Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer , stable X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733138553; l=1630; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=13U0y1DundmGRi1xvon55DH1ztxxWp3gT5PczadoflU=; b=Aa2jpkZtQUeqa7jmm+aHcdZF/SSMt2EEoIoiHBLUGFZVDzWDKp3Vwr5I1vVqnIhaB7v+q40LY EgGwKihcNr9CFEt2D3C+NDZsbtklxiFYhfvbcamWaivc/F6D8NempLF X-Developer-Key: i=s.hauer@pengutronix.de; a=ed25519; pk=4kuc9ocmECiBJKWxYgqyhtZOHj5AWi7+d0n/UjhkwTg= X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: s.hauer@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_032252_280039_50B164B1 X-CRM114-Status: GOOD ( 14.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In imx_ocotp_reg_read() the offset comes in as bytes and not as words. This means we have to divide offset by 4 to get to the correct word offset. Also the incoming offset might not be word aligned. In order to read from the OCOTP the driver aligns down the previous word boundary and reads from there. This means we have to skip this alignment offset from the temporary buffer when copying the data to the output buffer. Fixes: 22e9e6fcfb504 ("nvmem: imx: support i.MX93 OCOTP") Signed-off-by: Sascha Hauer Cc: stable --- drivers/nvmem/imx-ocotp-ele.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index 2e186b7d3b040..b2d21a5f77bc1 100644 --- a/drivers/nvmem/imx-ocotp-ele.c +++ b/drivers/nvmem/imx-ocotp-ele.c @@ -71,12 +71,14 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz u32 *buf; void *p; int i; + u8 skipbytes; if (offset + bytes > priv->data->size) bytes = priv->data->size - offset; - index = offset; - num_bytes = round_up(bytes, 4); + index = offset >> 2; + skipbytes = offset - (index << 2); + num_bytes = round_up(bytes + skipbytes, 4); count = num_bytes >> 2; p = kzalloc(num_bytes, GFP_KERNEL); @@ -100,7 +102,7 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz *buf++ = readl_relaxed(reg + (i << 2)); } - memcpy(val, (u8 *)p, bytes); + memcpy(val, ((u8 *)p) + skipbytes, bytes); mutex_unlock(&priv->lock); From patchwork Mon Dec 2 11:22:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 13890328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 874A4D7830C for ; Mon, 2 Dec 2024 11:34:29 +0000 (UTC) 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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=g/aqj7uB1+y18vWI+5KwjXUQzVh7QnjbDtTuaioOAIs=; b=tvbbgJl4nNy8lBQZs/DzS+CR0Z DXhZwU2YT/h8KanXnzeSW5iH03+d1gOprtImJ5JXNDOmJEBVdL2Qg+Sh6+if9Yk22O4MBIVIi5+o4 Ji0hbvCfSUGfwvkTHyA3cDf6SWdRJPm9wx3j3m8oVibm2jIfmrgiRKH0pnFXTh8m838LHcncttKUh 3UI36oitfZJoe3DBXL5/Wax5unyzGooHA54tw2tetR9G1zbXG9snAAR3avBJ93+pqCgInA6qAOeqI efgdk+7h+0RmBN2rJUH76IOZ6zRgxj75VuQOPAAS6WLFmEeXRKU8kg/JHKW0kI5DtPVbEruSSgeNL 2knVmMWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tI4gy-00000005uuZ-3I1C; Mon, 02 Dec 2024 11:34:16 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tI4Vg-00000005sEy-1QQt for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 11:22:37 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tI4Ve-0000UF-EB; Mon, 02 Dec 2024 12:22:34 +0100 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tI4Vc-001Hsz-3C; Mon, 02 Dec 2024 12:22:33 +0100 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1tI4Vd-003R1L-2D; Mon, 02 Dec 2024 12:22:33 +0100 From: Sascha Hauer Date: Mon, 02 Dec 2024 12:22:31 +0100 Subject: [PATCH v2 3/4] nvmem: imx-ocotp-ele: fix MAC address byte order MIME-Version: 1.0 Message-Id: <20241202-imx-ele-ocotp-fixes-v2-3-3c021a97eb5d@pengutronix.de> References: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> In-Reply-To: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam , Greg Kroah-Hartman , Peng Fan Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer , stable X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733138553; l=2189; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=eaBnFcHNZLo3OeuGzxtNatkXfWA3lsNPb5dGh4kb3Fc=; b=W/yT87H/XRX9oubpp58Qy5bS2gg+BLJHfgTGsFRdR9Vk9Cre3kXLF78gBOhfKvktkwsyJivV8 DiGmIWGLJC8Dv0VjP/95hc0qzyw3MQJymEXnTmYoKUS8SQAxEDRCPUI X-Developer-Key: i=s.hauer@pengutronix.de; a=ed25519; pk=4kuc9ocmECiBJKWxYgqyhtZOHj5AWi7+d0n/UjhkwTg= X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: s.hauer@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_032236_380265_7D2D0A41 X-CRM114-Status: GOOD ( 16.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org According to the i.MX93 Fusemap the two MAC addresses are stored in words 315 to 317 like this: 315 MAC1_ADDR_31_0[31:0] 316 MAC1_ADDR_47_32[47:32] MAC2_ADDR_15_0[15:0] 317 MAC2_ADDR_47_16[31:0] This means the MAC addresses are stored in reverse byte order. We have to swap the bytes before passing them to the upper layers. The storage format is consistent to the one used on i.MX6 using imx-ocotp driver which does the same byte swapping as introduced here. With this patch the MAC address on my i.MX93 TQ board correctly reads as 00:d0:93:6b:27:b8 instead of b8:27:6b:93:d0:00. Fixes: 22e9e6fcfb504 ("nvmem: imx: support i.MX93 OCOTP") Signed-off-by: Sascha Hauer Cc: stable --- drivers/nvmem/imx-ocotp-ele.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index b2d21a5f77bc1..422a6d53b10ef 100644 --- a/drivers/nvmem/imx-ocotp-ele.c +++ b/drivers/nvmem/imx-ocotp-ele.c @@ -111,6 +111,26 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz return 0; }; +static int imx_ocotp_cell_pp(void *context, const char *id, int index, + unsigned int offset, void *data, size_t bytes) +{ + u8 *buf = data; + int i; + + /* Deal with some post processing of nvmem cell data */ + if (id && !strcmp(id, "mac-address")) + for (i = 0; i < bytes / 2; i++) + swap(buf[i], buf[bytes - i - 1]); + + return 0; +} + +static void imx_ocotp_fixup_dt_cell_info(struct nvmem_device *nvmem, + struct nvmem_cell_info *cell) +{ + cell->read_post_process = imx_ocotp_cell_pp; +} + static int imx_ele_ocotp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -137,6 +157,8 @@ static int imx_ele_ocotp_probe(struct platform_device *pdev) priv->config.stride = 1; priv->config.priv = priv; priv->config.read_only = true; + priv->config.add_legacy_fixed_of_cells = true; + priv->config.fixup_dt_cell_info = imx_ocotp_fixup_dt_cell_info; mutex_init(&priv->lock); nvmem = devm_nvmem_register(dev, &priv->config); From patchwork Mon Dec 2 11:22:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 13890331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BE755D7830E for ; Mon, 2 Dec 2024 11:37:24 +0000 (UTC) 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:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+WYTxBz3FZ4iEcEqusok9Zm2rtmF0i35gPXRcN2NUNA=; b=f4sHZj1Rd6r+2GDgqJdtrImzBk 5RFrQ7RxMX0JQp9tkH8wi6KnGyiMrdV+izj7lfdGyzqyVJe6zq18uKeS7Z4rlDtKP/dFkviOCc+Cg VH7HLpdnW4EZanYvBjOxZyEnyjqaSFQ06mjJ+JyBxII+7VLsriiERQXitXa9Mzea7tEuROkEgzp+k ZYCHIRVGsaKvgRwQQzuWbp33WuxEMdvl+0mwsIoV2DKZdJP5McOdIZkOkS4szSFnAYfpqAsM76HTt QgEcWdQO3LranMP7YMnBJwDysHyAxX+2nnqHCoZy1+9a/1lWcmT3hF9hxf1sH8kLhwuZ4N4YAdDqP 2jLUZGNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tI4jr-00000005vZI-2HNM; Mon, 02 Dec 2024 11:37:15 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tI4W4-00000005sK2-13iS for linux-arm-kernel@lists.infradead.org; Mon, 02 Dec 2024 11:23:01 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tI4Ve-0000UJ-EC; Mon, 02 Dec 2024 12:22:34 +0100 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tI4Vd-001Ht1-05; Mon, 02 Dec 2024 12:22:33 +0100 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1tI4Vd-003R1L-2E; Mon, 02 Dec 2024 12:22:33 +0100 From: Sascha Hauer Date: Mon, 02 Dec 2024 12:22:32 +0100 Subject: [PATCH v2 4/4] nvmem: imx-ocotp-ele: set word length to 1 MIME-Version: 1.0 Message-Id: <20241202-imx-ele-ocotp-fixes-v2-4-3c021a97eb5d@pengutronix.de> References: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> In-Reply-To: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam , Greg Kroah-Hartman , Peng Fan Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer , stable X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733138553; l=1541; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=ZPaXYv47e/WQG4obGp3rPX00hCB/gvGfq8LMT3XH96c=; b=5eU7lUWgrtgcrvC11GGxw98/t4z9jTOvrrvJztR35tRTHRnzL7ycIfw5wyjjSm/QbkFrm81FC nxc/gLkbVJ9Bjkiw12E7CkWNSqvRHmkKEmAtSXJ4EsUurRQCS+UiAQe X-Developer-Key: i=s.hauer@pengutronix.de; a=ed25519; pk=4kuc9ocmECiBJKWxYgqyhtZOHj5AWi7+d0n/UjhkwTg= X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: s.hauer@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241202_032300_291179_5097015D X-CRM114-Status: GOOD ( 17.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The ELE hardware internally has a word length of 4. However, among other things we store MAC addresses in the ELE OCOTP. With a length of 6 bytes these are naturally unaligned to the word length. Therefore we must support unaligned reads in reg_read() and indeed it works properly when reg_read() is called via nvmem_reg_read(). Setting the word size to 4 has the only visible effect that doing unaligned reads from userspace via bin_attr_nvmem_read() do not work because they are rejected by that function. Given that we have to abstract from word accesses to byte accesses in the driver, set the word size to 1. This allows bytewise accesses from userspace to be able to test what the driver has to support anyway. Fixes: 22e9e6fcfb504 ("nvmem: imx: support i.MX93 OCOTP") Signed-off-by: Sascha Hauer Cc: stable --- drivers/nvmem/imx-ocotp-ele.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index 422a6d53b10ef..ca6dd71d8a2e2 100644 --- a/drivers/nvmem/imx-ocotp-ele.c +++ b/drivers/nvmem/imx-ocotp-ele.c @@ -153,7 +153,7 @@ static int imx_ele_ocotp_probe(struct platform_device *pdev) priv->config.owner = THIS_MODULE; priv->config.size = priv->data->size; priv->config.reg_read = priv->data->reg_read; - priv->config.word_size = 4; + priv->config.word_size = 1; priv->config.stride = 1; priv->config.priv = priv; priv->config.read_only = true;