From nobody Tue Nov 26 01:37:51 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B8F3158533 for ; Wed, 23 Oct 2024 08:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729671164; cv=none; b=BdmY8d4zWxTIbNKVhkSW16Xgl/X73N7obDILMFA73qWqfR3sL4QyzYXiADUI2ddnb/aKDCT/eKC51wu7hNCCRe8UmM27eb/NDBsSNINb1XtcSF+Px91DqIAvIEso+vc1w95LM3uTr5znQBRhHcRZVJpQwWpdX6J3hAlFHDCC/hg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729671164; c=relaxed/simple; bh=TcTBNj7+iYOpxE3v9b4DJqZG6L5zlKG1LkB0qWPMVnM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IQ6sX2cGq7kJO4Ray1HJ3VwW1JNNe5EDKSU1npYMPMDvZvkJeakYGleZg5lXiydEO657N46FA9MPcBYqScIUvAJB4C1Xp2yUe4//bMTcUpfiMzSCZYHZn5YhYrhGdrxKnMs918P/MUSuECC7pOl4r3jOaJr02vB887UEnDOiIfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de 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 1t3WTv-0004YQ-3C; Wed, 23 Oct 2024 10:12:39 +0200 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 1t3WTu-0010Hi-1W; Wed, 23 Oct 2024 10:12:38 +0200 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1t3WTu-00FrPY-1K; Wed, 23 Oct 2024 10:12:38 +0200 From: Sascha Hauer Date: Wed, 23 Oct 2024 10:12:28 +0200 Subject: [PATCH 1/4] nvmem: imx-ocotp-ele: simplify read beyond device check Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-imx-ele-ocotp-fixes-v1-1-4adc00ce288f@pengutronix.de> References: <20241023-imx-ele-ocotp-fixes-v1-0-4adc00ce288f@pengutronix.de> In-Reply-To: <20241023-imx-ele-ocotp-fixes-v1-0-4adc00ce288f@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729671158; l=938; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=TcTBNj7+iYOpxE3v9b4DJqZG6L5zlKG1LkB0qWPMVnM=; b=ZUec58O0Z2WMBmVreT/O9n4WGnFhNX4RcR81wyRt8p73ZbJqxufTkPLPL17TFzk9T9zeHpBLT wvXATQ7a4QJBdIDkCLmh/nU7OXvzM6jspOa5lHL2fA7UN7oPvN/KaRX 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-kernel@vger.kernel.org Do the read beyond device check on function entry in bytes instead of 32bit words which is easier to follow. Signed-off-by: Sascha Hauer --- 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 i= nt offset, void *val, siz void *p; int i; =20 + if (offset + bytes > priv->data->size) + bytes =3D priv->data->size - offset; + index =3D offset; num_bytes =3D round_up(bytes, 4); count =3D num_bytes >> 2; =20 - if (count > ((priv->data->size >> 2) - index)) - count =3D (priv->data->size >> 2) - index; - p =3D kzalloc(num_bytes, GFP_KERNEL); if (!p) return -ENOMEM; --=20 2.39.5 From nobody Tue Nov 26 01:37:51 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35A29158536 for ; Wed, 23 Oct 2024 08:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729671170; cv=none; b=mOYdEGiviGEE79arc/ioxcXUeJfgz1MbmrgwXCMgqe0tClstcgga5tzSdQsPYZ8x6ggyZcM5k31SAZUyMr6N4y9s/4qTY57UJBqpNPVI2XZesTu/E2cktVDwSG5mH1IDSFXl6f5yk5ylnBAj553GYsTClmqwhItFmhLZQ8TeeiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729671170; c=relaxed/simple; bh=2dzT+4V3anUSTonFUQwRZ1afjSpm37Cgi2apV/tBjys=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dZ4bVv3tEqMNxJbkDcARdkccLiM5ln+cQ6e39qKYXGnkmVptJYJt+2w06qtNBxbAcaSWYmSE7lrJ7HlnkwKgz+Zy8woBK0J8r44yXkEAt0uD+iMjBY6Xj5fl0dGkIlyYuMk1b+66ZFoVMwiAHLfXzl6ItcS9J1ytH3ifgRSHPNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de 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 1t3WTv-0004YS-3D; Wed, 23 Oct 2024 10:12:39 +0200 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 1t3WTu-0010Hj-1a; Wed, 23 Oct 2024 10:12:38 +0200 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1t3WTu-00FrPY-1L; Wed, 23 Oct 2024 10:12:38 +0200 From: Sascha Hauer Date: Wed, 23 Oct 2024 10:12:29 +0200 Subject: [PATCH 2/4] nvmem: imx-ocotp-ele: fix reading from non zero offset Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-imx-ele-ocotp-fixes-v1-2-4adc00ce288f@pengutronix.de> References: <20241023-imx-ele-ocotp-fixes-v1-0-4adc00ce288f@pengutronix.de> In-Reply-To: <20241023-imx-ele-ocotp-fixes-v1-0-4adc00ce288f@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729671158; l=1539; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=2dzT+4V3anUSTonFUQwRZ1afjSpm37Cgi2apV/tBjys=; b=7prRp4qpJxbkuHDdgv6wN7sAUBZi2LQrMBEj5MObAO9ROLxK4YxfqqK15Nt9mlum/gg4UFhCu x9OwzC/J5BXBsHmceLUppFjZ4wU4BUH6U7SBe97/Hifyru1EI+yZnsk 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-kernel@vger.kernel.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. Signed-off-by: Sascha Hauer --- 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 i= nt offset, void *val, siz u32 *buf; void *p; int i; + u8 skipbytes; =20 if (offset + bytes > priv->data->size) bytes =3D priv->data->size - offset; =20 - index =3D offset; - num_bytes =3D round_up(bytes, 4); + index =3D offset >> 2; + skipbytes =3D offset - (index << 2); + num_bytes =3D round_up(bytes + skipbytes, 4); count =3D num_bytes >> 2; =20 p =3D kzalloc(num_bytes, GFP_KERNEL); @@ -100,7 +102,7 @@ static int imx_ocotp_reg_read(void *context, unsigned i= nt offset, void *val, siz *buf++ =3D readl_relaxed(reg + (i << 2)); } =20 - memcpy(val, (u8 *)p, bytes); + memcpy(val, ((u8 *)p) + skipbytes, bytes); =20 mutex_unlock(&priv->lock); =20 --=20 2.39.5 From nobody Tue Nov 26 01:37:51 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B95F158534 for ; Wed, 23 Oct 2024 08:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729671164; cv=none; b=V6cE6nVLWvyPqPYsc0Gqgo7hC2lEPDjbDyrj8Anf16QivT7c4SP8avOIrj6GdafhM3GU7jTGFKHXzdPSGjCvYLpQqK0yp0Qq1KyIySY+8C/IRptNh8wZoRfTHoe/z7PkZHfgziYXpqOu5mA7XNmbY1rYZ5SwHMrtoJPsfadSC1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729671164; c=relaxed/simple; bh=Ss44dTfozznrGkGw5ypZa27kr0ux3PCowUrrQmM38eM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RcU5afHZ2XjHaxk6Oti64VEpHo6M1bAjTeQ5x+dKcXd081TduPLrV5UURyujqqNrefe9+nZtEm5f8Uk58gc9/6dFTyfWRTpG6y8NPPnYvTFmDgQp5Q+1L8aF+iTJKtNLLa0Qoo9cKi54J/09ScbonXpUwiyFUbfnlLkixyHC7M4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de 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 1t3WTv-0004YU-3E; Wed, 23 Oct 2024 10:12:39 +0200 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 1t3WTu-0010Hk-1f; Wed, 23 Oct 2024 10:12:38 +0200 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1t3WTu-00FrPY-1M; Wed, 23 Oct 2024 10:12:38 +0200 From: Sascha Hauer Date: Wed, 23 Oct 2024 10:12:30 +0200 Subject: [PATCH 3/4] nvmem: imx-ocotp-ele: fix MAC address byte order Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-imx-ele-ocotp-fixes-v1-3-4adc00ce288f@pengutronix.de> References: <20241023-imx-ele-ocotp-fixes-v1-0-4adc00ce288f@pengutronix.de> In-Reply-To: <20241023-imx-ele-ocotp-fixes-v1-0-4adc00ce288f@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729671158; l=2098; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=Ss44dTfozznrGkGw5ypZa27kr0ux3PCowUrrQmM38eM=; b=gvNFy2NDPhoLC81Bwz3lLc0+TPlOsd2dBi01QS7ETe3QHj/VSMS+9Ug99BfKgd+O5V7tlWgzO ZyIROFX9HUPBYm1kMFshH032+PEDiJcxTnowwxSUwkt23rTBUsrHCId 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-kernel@vger.kernel.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. Signed-off-by: Sascha Hauer --- 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; }; =20 +static int imx_ocotp_cell_pp(void *context, const char *id, int index, + unsigned int offset, void *data, size_t bytes) +{ + u8 *buf =3D data; + int i; + + /* Deal with some post processing of nvmem cell data */ + if (id && !strcmp(id, "mac-address")) + for (i =3D 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 =3D imx_ocotp_cell_pp; +} + static int imx_ele_ocotp_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -137,6 +157,8 @@ static int imx_ele_ocotp_probe(struct platform_device *= pdev) priv->config.stride =3D 1; priv->config.priv =3D priv; priv->config.read_only =3D true; + priv->config.add_legacy_fixed_of_cells =3D true; + priv->config.fixup_dt_cell_info =3D imx_ocotp_fixup_dt_cell_info; mutex_init(&priv->lock); =20 nvmem =3D devm_nvmem_register(dev, &priv->config); --=20 2.39.5 From nobody Tue Nov 26 01:37:51 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A3CD158848 for ; Wed, 23 Oct 2024 08:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729671164; cv=none; b=ctm5GHQ2cLc0ZEsGFhSAxZcm5fcxFPPrIdzpzWQt09MJ2UNUoms2vy8F9pGzuKeiEs/wmVVbjYXeX9ds7ad+paWulUPiMqlrbLwT4cO3AG+g81EtGDr1U2+U8D+JBIix9GIfuGyzhoiKjJpS0MKGlqFmFelKlwW4QFuq68uRNp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729671164; c=relaxed/simple; bh=TDF4ZD9quQMr6fYXShZTAO/88aFocRLfhFV/zvO8TZE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d0CZLA7gkZZsBC+OD5928VATz1TCnYsXD7rqipNAyCpPQ/cGNIG/6i6pDmcUh+7S+8uQ5MWifFFWtVfbs/tVtz6lPZjaqTEebPm4OkRloUZEXFIA8UwxZZAB4tmXKkuAliQj0XfyYfy7CAbDe/jgClRbA2WOLkl/ikzoJ6emhgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de 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 1t3WTv-0004YT-3L; Wed, 23 Oct 2024 10:12:39 +0200 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 1t3WTu-0010Hl-1Z; Wed, 23 Oct 2024 10:12:38 +0200 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1t3WTu-00FrPY-1N; Wed, 23 Oct 2024 10:12:38 +0200 From: Sascha Hauer Date: Wed, 23 Oct 2024 10:12:31 +0200 Subject: [PATCH 4/4] nvmem: imx-ocotp-ele: set word length to 1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241023-imx-ele-ocotp-fixes-v1-4-4adc00ce288f@pengutronix.de> References: <20241023-imx-ele-ocotp-fixes-v1-0-4adc00ce288f@pengutronix.de> In-Reply-To: <20241023-imx-ele-ocotp-fixes-v1-0-4adc00ce288f@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1729671158; l=1450; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=TDF4ZD9quQMr6fYXShZTAO/88aFocRLfhFV/zvO8TZE=; b=Z1RtZosGsmcHRf6t7dv8eE+gTAbA1O8/9iPJob1gBFvD0FwYioU/ZCMoj9ElB2t5Uk/++R21z dKSjq/YuRZ4AlXMOziffB6IgtqSDaG29ZmIDYHWRWBvSkIK5D36uKz4 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-kernel@vger.kernel.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. Signed-off-by: Sascha Hauer --- 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 =3D THIS_MODULE; priv->config.size =3D priv->data->size; priv->config.reg_read =3D priv->data->reg_read; - priv->config.word_size =3D 4; + priv->config.word_size =3D 1; priv->config.stride =3D 1; priv->config.priv =3D priv; priv->config.read_only =3D true; --=20 2.39.5