Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/4] nvmem: mtk-efuse: mt6572 support
@ 2026-11-23 21:02 Roman Vivchar via B4 Relay
  2026-11-23 21:02 ` [PATCH v6 1/4] dt-bindings: nvmem: mediatek: efuse: add mt6572 Roman Vivchar via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-11-23 21:02 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 cpu speedbin fixup.
Patch 4 adds platform data for mt6572 SoC.

Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
Changes in v6:
- Rename mtk_efuse_gpu_speedbin_pp() to mtk_efuse_speedbin_pp()
- Merge CPU and GPU fixup into one branch
- Link to v5: https://patch.msgid.link/20260930-6572-nvmem-v5-0-384d2a3a1770@protonmail.com

Changes in v5:
- Add new patch for CPU speedbin post-processing
- Set uses_post_processing to true in the mt6572 platform data
- Drop r-b tag on the patch 4 due to uses_post_processing changes
- Link to v4: https://patch.msgid.link/20260921-6572-nvmem-v4-0-e9c14156559a@protonmail.com

Changes in v4:
- Pick up Angelo's tags
- Rebase onto nvmem/for-next (2eda8d2a45ca ("Merge branches 'nvmem-fixes' and 'nvmem-for-v7.4' into nvnem-for-next"))
- Link to v3: https://patch.msgid.link/20260909-6572-nvmem-v3-0-c0c441656431@protonmail.com

Changes in v3:
- Pick up Rob's r-b tag for dt-bindings
- Patch 2 and 3 unchanged, for some reason cover letter and patch 1 were
missing on the web mirror...
- Link to v2: https://patch.msgid.link/20260724-6572-nvmem-v2-0-e58d16a29621@protonmail.com

Changes in v2:
- dt-bindings: make mediatek,mt6572-efuse standalone compatible
- Driver: add 'mtk_reg_read_aligned' helper instead of modifying 'mtk_reg_read'
- Link to v1: https://patch.msgid.link/20260715-6572-nvmem-v1-0-9c13be99d077@protonmail.com

---
Roman Vivchar (4):
      dt-bindings: nvmem: mediatek: efuse: add mt6572
      nvmem: mtk-efuse: add support for 32-bit aligned reads
      nvmem: mtk-efuse: add CPU speedbin post-processing
      nvmem: mtk-efuse: add mt6572 support

 .../devicetree/bindings/nvmem/mediatek,efuse.yaml  |  5 ++-
 drivers/nvmem/mtk-efuse.c                          | 52 +++++++++++++++++++---
 2 files changed, 50 insertions(+), 7 deletions(-)
---
base-commit: 2eda8d2a45caa955a5cb1d897bf6024d22041995
change-id: 20260710-6572-nvmem-eb98c7a73351

Best regards,
--  
Roman Vivchar <rva333@protonmail.com>




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v6 1/4] dt-bindings: nvmem: mediatek: efuse: add mt6572
  2026-11-23 21:02 [PATCH v6 0/4] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
@ 2026-11-23 21:02 ` Roman Vivchar via B4 Relay
  2026-11-23 21:02 ` [PATCH v6 2/4] nvmem: mtk-efuse: add support for 32-bit aligned reads Roman Vivchar via B4 Relay
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-11-23 21:02 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.

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
 Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
index f9323b3ecfc8..e10947164941 100644
--- a/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
+++ b/Documentation/devicetree/bindings/nvmem/mediatek,efuse.yaml
@@ -24,13 +24,16 @@ properties:
 
   compatible:
     oneOf:
+      - enum:
+          - mediatek,mt6572-efuse
+          - mediatek,mt8186-efuse
+
       - items:
           - enum:
               - mediatek,mt8188-efuse
               - mediatek,mt8189-efuse
               - mediatek,mt8196-efuse
           - const: mediatek,mt8186-efuse
-      - const: mediatek,mt8186-efuse
 
       - items:
           - enum:

-- 
2.56.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v6 2/4] nvmem: mtk-efuse: add support for 32-bit aligned reads
  2026-11-23 21:02 [PATCH v6 0/4] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
  2026-11-23 21:02 ` [PATCH v6 1/4] dt-bindings: nvmem: mediatek: efuse: add mt6572 Roman Vivchar via B4 Relay
@ 2026-11-23 21:02 ` Roman Vivchar via B4 Relay
  2026-11-23 21:02 ` [PATCH v6 3/4] nvmem: mtk-efuse: add CPU speedbin post-processing Roman Vivchar via B4 Relay
  2026-11-23 21:02 ` [PATCH v6 4/4] nvmem: mtk-efuse: add mt6572 support Roman Vivchar via B4 Relay
  3 siblings, 0 replies; 7+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-11-23 21:02 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 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 <angelogioacchino.delregno@collabora.com>
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
 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 <andrew-ct.chen@mediatek.com>
  */
 
+#include <linux/align.h>
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/io.h>
@@ -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.56.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v6 3/4] nvmem: mtk-efuse: add CPU speedbin post-processing
  2026-11-23 21:02 [PATCH v6 0/4] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
  2026-11-23 21:02 ` [PATCH v6 1/4] dt-bindings: nvmem: mediatek: efuse: add mt6572 Roman Vivchar via B4 Relay
  2026-11-23 21:02 ` [PATCH v6 2/4] nvmem: mtk-efuse: add support for 32-bit aligned reads Roman Vivchar via B4 Relay
@ 2026-11-23 21:02 ` Roman Vivchar via B4 Relay
  2026-11-30 20:11   ` Luca Leonardo Scorcia
  2026-11-23 21:02 ` [PATCH v6 4/4] nvmem: mtk-efuse: add mt6572 support Roman Vivchar via B4 Relay
  3 siblings, 1 reply; 7+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-11-23 21:02 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>

MediaTek SoCs are often released under the same marketing name, but with
different suffix for the speedbin. For example, mt6572m has 1 GHz limit,
mt6572a - 1.2 GHz, mt6572w - 1.4 GHz.

Since CPU speedbin is stored as a number in the efuse, similar to GPU,
rename mtk_efuse_gpu_speedbin_pp() to mtk_efuse_speedbin_pp() and add
check for cpu-speedbin node to fixup the value for supported-hw usage in
OPP tables.

Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
 drivers/nvmem/mtk-efuse.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/nvmem/mtk-efuse.c b/drivers/nvmem/mtk-efuse.c
index 980c29d01337..2c09649ce7f9 100644
--- a/drivers/nvmem/mtk-efuse.c
+++ b/drivers/nvmem/mtk-efuse.c
@@ -59,8 +59,8 @@ static int mtk_reg_read(void *context,
 	return 0;
 }
 
-static int mtk_efuse_gpu_speedbin_pp(void *context, const char *id, int index,
-				     unsigned int offset, void *data, size_t bytes)
+static int mtk_efuse_speedbin_pp(void *context, const char *id, int index,
+				 unsigned int offset, void *data, size_t bytes)
 {
 	u8 *val = data;
 
@@ -76,13 +76,14 @@ static void mtk_efuse_fixup_dt_cell_info(struct nvmem_device *nvmem,
 	size_t sz = strlen(cell->name);
 
 	/*
-	 * On some SoCs, the GPU speedbin is not read as bitmask but as
+	 * On some SoCs, the CPU/GPU speedbin is not read as bitmask but as
 	 * a number with range [0-7] (max 3 bits): post process to use
 	 * it in OPP tables to describe supported-hw.
 	 */
 	if (cell->nbits <= 3 &&
-	    strncmp(cell->name, "gpu-speedbin", min(sz, strlen("gpu-speedbin"))) == 0)
-		cell->read_post_process = mtk_efuse_gpu_speedbin_pp;
+	    (strncmp(cell->name, "gpu-speedbin", min(sz, strlen("gpu-speedbin"))) == 0 ||
+	     strncmp(cell->name, "cpu-speedbin", min(sz, strlen("cpu-speedbin"))) == 0))
+		cell->read_post_process = mtk_efuse_speedbin_pp;
 }
 
 static int mtk_efuse_probe(struct platform_device *pdev)

-- 
2.56.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v6 4/4] nvmem: mtk-efuse: add mt6572 support
  2026-11-23 21:02 [PATCH v6 0/4] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-23 21:02 ` [PATCH v6 3/4] nvmem: mtk-efuse: add CPU speedbin post-processing Roman Vivchar via B4 Relay
@ 2026-11-23 21:02 ` Roman Vivchar via B4 Relay
  3 siblings, 0 replies; 7+ messages in thread
From: Roman Vivchar via B4 Relay @ 2026-11-23 21:02 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.

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
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 2c09649ce7f9..88d84ec2f435 100644
--- a/drivers/nvmem/mtk-efuse.c
+++ b/drivers/nvmem/mtk-efuse.c
@@ -132,6 +132,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 = true,
+	.needs_aligned_read = true,
+};
+
 static const struct mtk_efuse_pdata mtk_mt8186_efuse_pdata = {
 	.uses_post_processing = true,
 	.needs_aligned_read = false,
@@ -143,6 +148,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.56.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v6 3/4] nvmem: mtk-efuse: add CPU speedbin post-processing
  2026-11-23 21:02 ` [PATCH v6 3/4] nvmem: mtk-efuse: add CPU speedbin post-processing Roman Vivchar via B4 Relay
@ 2026-11-30 20:11   ` Luca Leonardo Scorcia
  2026-11-30 20:54     ` Roman Vivchar
  0 siblings, 1 reply; 7+ messages in thread
From: Luca Leonardo Scorcia @ 2026-11-30 20:11 UTC (permalink / raw)
  To: devnull+rva333.protonmail.com
  Cc: andrew-ct.chen, angelogioacchino.delregno, conor+dt, devicetree,
	krzk+dt, lala.lin, linux-arm-kernel, linux-kernel, linux-mediatek,
	matthias.bgg, robh, rva333, srini

Hello, I am interested in this series as I have the same need to identify
the cpu variant for OPPs on MT8167A/S/D.

I have two questions:

1. Is post-processing really needed? It seems that nvmem cells can use
the bits property to retrieve only the necessary bits from the cell, e.g.:

  cpu_speed_bin: cpu-speed-bin@40 {
    reg = <0x40 0x4>;
    bits = <0 2>;
  };

To me this seems more intuitive than driver-based post-processing and
is already supported by device tree syntax. I did a quick test and it
seems to work, but I'm sure there's some step that I'm missing.

2. Am I correct in saying that at the moment there is no upstream support
for nvmem-cells references in the operating-points-v2 OPPs? How do you
plan to connect your new cpu-speedbin support to OPPs?

Thanks,
Luca


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v6 3/4] nvmem: mtk-efuse: add CPU speedbin post-processing
  2026-11-30 20:11   ` Luca Leonardo Scorcia
@ 2026-11-30 20:54     ` Roman Vivchar
  0 siblings, 0 replies; 7+ messages in thread
From: Roman Vivchar @ 2026-11-30 20:54 UTC (permalink / raw)
  To: Luca Leonardo Scorcia
  Cc: devnull+rva333.protonmail.com, andrew-ct.chen,
	angelogioacchino.delregno, conor+dt, devicetree, krzk+dt,
	lala.lin, linux-arm-kernel, linux-kernel, linux-mediatek,
	matthias.bgg, robh, srini

Hi Luca,

On Monday, November 30th, 2026 at 10:11 PM, Luca Leonardo Scorcia <l.scorcia@gmail.com> wrote:

> Hello, I am interested in this series as I have the same need to identify
> the cpu variant for OPPs on MT8167A/S/D.
> 
> I have two questions:
> 
> 1. Is post-processing really needed?

Yes.

> It seems that nvmem cells can use
> the bits property to retrieve only the necessary bits from the cell, e.g.:
> 
>   cpu_speed_bin: cpu-speed-bin@40 {
>     reg = <0x40 0x4>;
>     bits = <0 2>;
>   };
>
> To me this seems more intuitive than driver-based post-processing and
> is already supported by device tree syntax. I did a quick test and it
> seems to work, but I'm sure there's some step that I'm missing.

I guess you're missing how this links with OPP tables. In short, there's
opp-supported-hw property, which expects a *bitmask*.

Let's assume the mt8167 A/S/D is 0 (the worst), 1 (medium) and 2 (the
best) in the efuse. There's e.g. 16 OPPs, some of them are shared for
worst and medium, and some are exclusive to the best. If we simply take
raw numbers, we can't create a bitmask.

That's why there's post-processing - we apply BIT (so 1 << n) to
the raw number, so we can have opp-supported-hw = <0x03> (after
post-processing: BIT(0) and BIT(1) = 3) for the shared opp, and
opp-supported-hw = <0x04> for best-tier OPP.
(note you can also mix BIT(1) and BIT(2) to exclude the worst speedbin).

> 2. Am I correct in saying that at the moment there is no upstream support
> for nvmem-cells references in the operating-points-v2 OPPs? How do you
> plan to connect your new cpu-speedbin support to OPPs?

There's generic nvmem-cells and nvmem-cell-names = "speed_grade" for
device_type = "cpu". I've posted series for mediatek-cpufreq driver
support some time ago [1], but it's blocked by this one.

If you want to look at more complex example regarding speedbins
and maybe pick some patches (note they're not very upstream ready),
you can take a look at mt6768 fork [2].

[1] https://lore.kernel.org/linux-mediatek/20260923-6572-cpufreq-v1-1-41f7af6d6d1a@protonmail.com/
[2] https://github.com/mt6768-mainline/linux

Best regards,
Roman


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-30 20:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 21:02 [PATCH v6 0/4] nvmem: mtk-efuse: mt6572 support Roman Vivchar via B4 Relay
2026-11-23 21:02 ` [PATCH v6 1/4] dt-bindings: nvmem: mediatek: efuse: add mt6572 Roman Vivchar via B4 Relay
2026-11-23 21:02 ` [PATCH v6 2/4] nvmem: mtk-efuse: add support for 32-bit aligned reads Roman Vivchar via B4 Relay
2026-11-23 21:02 ` [PATCH v6 3/4] nvmem: mtk-efuse: add CPU speedbin post-processing Roman Vivchar via B4 Relay
2026-11-30 20:11   ` Luca Leonardo Scorcia
2026-11-30 20:54     ` Roman Vivchar
2026-11-23 21:02 ` [PATCH v6 4/4] nvmem: mtk-efuse: add mt6572 support Roman Vivchar via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox