From mboxrd@z Thu Jan 1 00:00:00 1970 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 38CEBC982E6 for ; Mon, 21 Sep 2026 14:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To: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:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=u2o7YK7nL39OOEo1FByNdZwcEbXFW/jHzb3v51U7b7o=; b=QRJluEJADANqiGPNz4WmV6onHB xHMWi+7gCJC8mZ4pE/9mq83J9/BW0lu0z/8zeddogqLjOy7C/LGyEq5lx1mzfbGicPzShedOKYYL+ 4LPplgP0ckNAGEsG6Ua7hphrwXn43HrOGjxxsdaSgQspjr6XXVinEO98yj7SdV1zwcVwWxorzWBZP +0UpjUW3J9tHZsl1hEY++VBDraWGBWaZI3sZ/zpr3+OK68guMgkIWl0MPUyDOQ4hOqU+jD6rkKa5T 9XWV6Min9kKPY1Y7s3hOe8g0xSwGGY+pgwbEcY5HzJd67kKYkAtw7gh2UBQ1aCXBcfO1TNuIppavl sHaa6Bvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8f85-00000002Pst-0o9t; Mon, 21 Sep 2026 14:36:25 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8f7s-00000002Pko-0Ven; Mon, 21 Sep 2026 14:36:12 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 56DB7601F9; Mon, 21 Sep 2026 14:36:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id E8769C2BCF7; Mon, 21 Sep 2026 14:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1790001371; bh=dVWdIA6jcIe0iWHDTwaO7naqquNUBOM3dPKEaK1Eh+U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=YMmg3fZ1903PF9HgBUicrLFLMtXM6N16h6/lvcpSDxXbGmlSzqwawT6KIeeBhIdYE F0rVpmFUp7v519M3a2KDysh2wrjy4b5HeWQ6lEwlSe9lp3aobh8VxLltvxWkTStTQD /L92ybg++iSJ/dtExWnPqivRxPAktksULPYhaXGPdugiHkzC+xWGKPn+g3gq4ldRLj p5qhM+qXsb18onuL+zpzhFXj1VZIXeN86NK7Lb0KteD3KT0o3gE+4j4c4YKgzHIsp+ lzSjHk/xx0y2/JXImt8qOfHjoLftdEa1vvQG9MQZ87WCxFrmi3z/ewAodALKj6yFI9 R/vv+ySr/XiWQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6769C982E6; Mon, 21 Sep 2026 14:36:10 +0000 (UTC) From: Roman Vivchar via B4 Relay Date: Mon, 21 Sep 2026 17:35:48 +0300 Subject: [PATCH v4 2/3] nvmem: mtk-efuse: add support for 32-bit aligned reads MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260921-6572-nvmem-v4-2-e9c14156559a@protonmail.com> References: <20260921-6572-nvmem-v4-0-e9c14156559a@protonmail.com> In-Reply-To: <20260921-6572-nvmem-v4-0-e9c14156559a@protonmail.com> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Andrew-CT Chen , Lala Lin Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Roman Vivchar X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1790001369; l=2576; i=rva333@protonmail.com; s=20260510; h=from:subject:message-id; bh=PlUtOStRK66yTGiZ19W5bDjNAyxn6+b3O2rJne7Jc/o=; b=paCcPUNM7D8m/r78mYsodol2oWP6+5d0pxEOjysIBr6yNg5qAECkrDINSFhtEcZOVWpkfGmzS w9Cou12BZIZDz3nSCOD/s74M67rmCbGbi+IQEM8ucVDGCkWzapEs4X6 X-Developer-Key: i=rva333@protonmail.com; a=ed25519; pk=zww/nWjBGoQ4POXCG0BV6fx2iuXK6jx77rsKPA5YK5Y= X-Endpoint-Received: by B4 Relay for rva333@protonmail.com/20260510 with auth_id=777 X-Original-From: Roman Vivchar 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: , Reply-To: rva333@protonmail.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Roman Vivchar Some MediaTek SoCs, such as mt6572, don't support 8-bit reads, leading to zeroes or garbage data. 32-bit aligned reads must be used instead. Introduce a 'mtk_reg_read_aligned' helper to enforce 32-bit aligned register access. All reads will be performed by reading 4-byte words and masking them. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Roman Vivchar --- drivers/nvmem/mtk-efuse.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c index 00a84ea963a8..980c29d01337 100644 --- a/drivers/nvmem/mtk-efuse.c +++ b/drivers/nvmem/mtk-efuse.c @@ -4,6 +4,7 @@ * Author: Andrew-CT Chen */ +#include #include #include #include @@ -13,12 +14,37 @@ struct mtk_efuse_pdata { bool uses_post_processing; + bool needs_aligned_read; }; struct mtk_efuse_priv { void __iomem *base; }; +static int mtk_reg_read_aligned(void *context, + unsigned int reg, void *_val, size_t bytes) +{ + struct mtk_efuse_priv *priv = context; + u8 *val = _val; + u32 i, pos, shift, val32; + + for (i = 0; i < bytes; i++, val++) { + pos = reg + i; + + /* + * Read on 32-bit word boundary or if it's the first + * iteration + */ + if (i == 0 || IS_ALIGNED(pos, 4)) + val32 = readl(priv->base + (pos & ~3)); + + shift = (pos & 3) * 8; + *val = (val32 >> shift) & 0xff; + } + + return 0; +} + static int mtk_reg_read(void *context, unsigned int reg, void *_val, size_t bytes) { @@ -81,7 +107,12 @@ static int mtk_efuse_probe(struct platform_device *pdev) econfig.add_legacy_fixed_of_cells = true; econfig.stride = 1; econfig.word_size = 1; - econfig.reg_read = mtk_reg_read; + + if (pdata->needs_aligned_read) + econfig.reg_read = mtk_reg_read_aligned; + else + econfig.reg_read = mtk_reg_read; + econfig.size = resource_size(res); econfig.priv = priv; econfig.dev = dev; @@ -102,10 +133,12 @@ static int mtk_efuse_probe(struct platform_device *pdev) static const struct mtk_efuse_pdata mtk_mt8186_efuse_pdata = { .uses_post_processing = true, + .needs_aligned_read = false, }; static const struct mtk_efuse_pdata mtk_efuse_pdata = { .uses_post_processing = false, + .needs_aligned_read = false, }; static const struct of_device_id mtk_efuse_of_match[] = { -- 2.55.0