* [PATCH 0/3] nvmem: mtk-efuse: mt6572 support
@ 2026-07-15 14:27 Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 1/3] dt-bindings: nvmem: mediatek: efuse: add mt6572 Roman Vivchar via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-07-15 14:27 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Andrew-CT Chen, Lala Lin
Cc: devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
Roman Vivchar
This patch series adds MediaTek mt6572 efuse support. Unlike newer SoCs,
its efuse controller doesn't work properly with 8-bit reads, leading to
invalid data with current mtk-efuse driver implementation.
This behavior can be observed with devmem (0x10009174 and 0x10009178 are
thermal calibration cells):
~ # devmem 0x10009174 32
0x00CDD4CD
~ # devmem 0x10009178 32
0x0F76865D
~ # devmem 0x10009174 8
0xCD
~ # devmem 0x10009175 8
0x00
~ # devmem 0x10009176 8
0x00
~ # devmem 0x10009177 8
0x00
~ # devmem 0x10009178 8
0x5D
~ # devmem 0x10009179 8
0x00
~ # devmem 0x1000917a 8
0x00
~ # devmem 0x1000917b 8
0x00
Patch 1 adds dt-bindings compatible for the mt6572,
Patch 2 adds platform data option to use aligned 32-bit reads instead
of plain readb().
Patch 3 adds platform data for mt6572 SoC.
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
Roman Vivchar (3):
dt-bindings: nvmem: mediatek: efuse: add mt6572
nvmem: mtk-efuse: add support for 32-bit aligned reads
nvmem: mtk-efuse: add mt6572 support
.../devicetree/bindings/nvmem/mediatek,efuse.yaml | 1 +
drivers/nvmem/mtk-efuse.c | 37 ++++++++++++++++++++--
2 files changed, 35 insertions(+), 3 deletions(-)
---
base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
change-id: 20260710-6572-nvmem-eb98c7a73351
Best regards,
--
Roman Vivchar <rva333@protonmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] dt-bindings: nvmem: mediatek: efuse: add mt6572
2026-07-15 14:27 [PATCH 0/3] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
@ 2026-07-15 14:27 ` Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 2/3] nvmem: mtk-efuse: add support for 32-bit aligned reads Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 3/3] nvmem: mtk-efuse: add mt6572 support Roman Vivchar via B4 Relay
2 siblings, 0 replies; 5+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-07-15 14:27 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Andrew-CT Chen, Lala Lin
Cc: devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
Roman Vivchar
From: Roman Vivchar <rva333@protonmail.com>
Add a compatible string for the mt6572 SoC efuse controller.
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
index f9323b3ecfc8..269e2b09f5c8 100644
--- a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
+++ b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
@@ -44,6 +44,7 @@ properties:
- items:
- enum:
+ - mediatek,mt6572-efuse
- mediatek,mt7622-efuse
- mediatek,mt7623-efuse
- mediatek,mt7981-efuse
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] nvmem: mtk-efuse: add support for 32-bit aligned reads
2026-07-15 14:27 [PATCH 0/3] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 1/3] dt-bindings: nvmem: mediatek: efuse: add mt6572 Roman Vivchar via B4 Relay
@ 2026-07-15 14:27 ` Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 3/3] nvmem: mtk-efuse: add mt6572 support Roman Vivchar via B4 Relay
2 siblings, 0 replies; 5+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-07-15 14:27 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Andrew-CT Chen, Lala Lin
Cc: devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
Roman Vivchar
From: Roman Vivchar <rva333@protonmail.com>
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 an 'needs_aligned_read' field to the platform data to enforce
32-bit aligned register access. All reads will be performed by reading
4-byte words and masking them.
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
drivers/nvmem/mtk-efuse.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c
index af953e1d9230..1462f2760818 100644
--- a/drivers/nvmem/mtk-efuse.c
+++ b/drivers/nvmem/mtk-efuse.c
@@ -4,6 +4,7 @@
* Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
*/
+#include <linux/align.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
@@ -14,10 +15,12 @@
struct mtk_efuse_pdata {
bool uses_post_processing;
+ bool needs_aligned_read;
};
struct mtk_efuse_priv {
void __iomem *base;
+ const struct mtk_efuse_pdata *data;
};
static int mtk_reg_read(void *context,
@@ -28,6 +31,26 @@ static int mtk_reg_read(void *context,
u8 *val = _val;
int i;
+ if (priv->data->needs_aligned_read) {
+ u32 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;
+ }
+
for (i = 0; i < bytes; i++, val++)
*val = readb(addr + i);
@@ -67,7 +90,6 @@ static int mtk_efuse_probe(struct platform_device *pdev)
struct nvmem_device *nvmem;
struct nvmem_config econfig = {};
struct mtk_efuse_priv *priv;
- const struct mtk_efuse_pdata *pdata;
struct platform_device *socinfo;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -78,7 +100,8 @@ static int mtk_efuse_probe(struct platform_device *pdev)
if (IS_ERR(priv->base))
return PTR_ERR(priv->base);
- pdata = device_get_match_data(dev);
+ priv->data = device_get_match_data(dev);
+
econfig.add_legacy_fixed_of_cells = true;
econfig.stride = 1;
econfig.word_size = 1;
@@ -86,7 +109,7 @@ static int mtk_efuse_probe(struct platform_device *pdev)
econfig.size = resource_size(res);
econfig.priv = priv;
econfig.dev = dev;
- if (pdata->uses_post_processing)
+ if (priv->data->uses_post_processing)
econfig.fixup_dt_cell_info = &mtk_efuse_fixup_dt_cell_info;
nvmem = devm_nvmem_register(dev, &econfig);
if (IS_ERR(nvmem))
@@ -103,10 +126,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.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] nvmem: mtk-efuse: add mt6572 support
2026-07-15 14:27 [PATCH 0/3] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 1/3] dt-bindings: nvmem: mediatek: efuse: add mt6572 Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 2/3] nvmem: mtk-efuse: add support for 32-bit aligned reads Roman Vivchar via B4 Relay
@ 2026-07-15 14:27 ` Roman Vivchar via B4 Relay
2026-07-15 14:45 ` sashiko-bot
2 siblings, 1 reply; 5+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-07-15 14:27 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Matthias Brugger, AngeloGioacchino Del Regno,
Andrew-CT Chen, Lala Lin
Cc: devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
Roman Vivchar
From: Roman Vivchar <rva333@protonmail.com>
Add a platform data struct for the efuse controller.
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
drivers/nvmem/mtk-efuse.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c
index 1462f2760818..a79434608465 100644
--- a/drivers/nvmem/mtk-efuse.c
+++ b/drivers/nvmem/mtk-efuse.c
@@ -124,6 +124,11 @@ static int mtk_efuse_probe(struct platform_device *pdev)
return 0;
}
+static const struct mtk_efuse_pdata mtk_mt6572_efuse_pdata = {
+ .uses_post_processing = false,
+ .needs_aligned_read = true,
+};
+
static const struct mtk_efuse_pdata mtk_mt8186_efuse_pdata = {
.uses_post_processing = true,
.needs_aligned_read = false,
@@ -135,6 +140,7 @@ static const struct mtk_efuse_pdata mtk_efuse_pdata = {
};
static const struct of_device_id mtk_efuse_of_match[] = {
+ { .compatible = "mediatek,mt6572-efuse", .data = &mtk_mt6572_efuse_pdata },
{ .compatible = "mediatek,mt8173-efuse", .data = &mtk_efuse_pdata },
{ .compatible = "mediatek,mt8186-efuse", .data = &mtk_mt8186_efuse_pdata },
{ .compatible = "mediatek,efuse", .data = &mtk_efuse_pdata },
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3] nvmem: mtk-efuse: add mt6572 support
2026-07-15 14:27 ` [PATCH 3/3] nvmem: mtk-efuse: add mt6572 support Roman Vivchar via B4 Relay
@ 2026-07-15 14:45 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-07-15 14:45 UTC (permalink / raw)
To: Roman Vivchar; +Cc: conor+dt, devicetree, robh
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incorrect string comparison logic erroneously matches any nvmem cell name that is a prefix of 'gpu-speedbin'.
--
--- Patch [3]: [PATCH 3/3] nvmem: mtk-efuse: add mt6572 support ---
commit 2c71c19eb8895343bae32ea1c4c07b25c01cd56c
Author: Roman Vivchar <rva333@protonmail.com>
nvmem: mtk-efuse: add mt6572 support
Add a platform data struct for the efuse controller.
> diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c
> index 1462f27608184..a794346084658 100644
> --- a/drivers/nvmem/mtk-efuse.c
> +++ b/drivers/nvmem/mtk-efuse.c
> @@ -124,6 +124,11 @@ static int mtk_efuse_probe(struct platform_device *pdev)
> return 0;
> }
>
> +static const struct mtk_efuse_pdata mtk_mt6572_efuse_pdata = {
> + .uses_post_processing = false,
[Severity: High]
This isn't a bug introduced by this patch, but there is a pre-existing issue
with the post-processing logic in this driver.
Looking at mtk_efuse_fixup_dt_cell_info(), the string comparison logic
erroneously matches any nvmem cell name that is a prefix of "gpu-speedbin":
drivers/nvmem/mtk-efuse.c:mtk_efuse_fixup_dt_cell_info() {
...
if (cell->nbits <= 3 &&
strncmp(cell->name, "gpu-speedbin", min(sz, strlen("gpu-speedbin"))) == 0)
cell->read_post_process = mtk_efuse_gpu_speedbin_pp;
...
}
Because strncmp() uses min(strlen(cell->name), strlen("gpu-speedbin")) for
the comparison length, it restricts the comparison to the shorter length.
If a device tree defines a cell with a name that is a substring of
"gpu-speedbin" (e.g., "gpu" or "gpu-speed") and has 3 or fewer bits, this
will evaluate to 0.
This incorrectly applies the post-processing fixup to completely unrelated
cells, which could cause silent data corruption.
Would it be possible to change this comparison to prevent short-prefix
matches?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260715-6572-nvmem-v1-0-9c13be99d077@protonmail.com?part=3
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-15 14:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15 14:27 [PATCH 0/3] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 1/3] dt-bindings: nvmem: mediatek: efuse: add mt6572 Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 2/3] nvmem: mtk-efuse: add support for 32-bit aligned reads Roman Vivchar via B4 Relay
2026-07-15 14:27 ` [PATCH 3/3] nvmem: mtk-efuse: add mt6572 support Roman Vivchar via B4 Relay
2026-07-15 14:45 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox