Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH 0/2] Input: mtk-pmic-keys - fix TOP_RST_MISC layout on MT6357/MT6358
@ 2026-11-26  0:07 Ilia Snezhkov via B4 Relay
  2026-11-26  0:07 ` [PATCH 1/2] Input: mtk-pmic-keys - fix MT6358 long-press reset bits Ilia Snezhkov via B4 Relay
  2026-11-26  0:07 ` [PATCH 2/2] Input: mtk-pmic-keys - fix MT6357 " Ilia Snezhkov via B4 Relay
  0 siblings, 2 replies; 3+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26  0:07 UTC (permalink / raw)
  To: dmitry.torokhov
  Cc: matthias.bgg, angelogioacchino.delregno, linux-input,
	linux-mediatek, linux-arm-kernel, linux-kernel

The long-press reset setup of mtk-pmic-keys programs TOP_RST_MISC of
MT6357 and MT6358/MT6366 with the MT6397 bit layout. On these PMICs the
reset enable is bit 9, the home key mode bit 8 and the time bits 13:12,
while bits 0, 1 and 5 hold the PMIC watchdog reset setup done by the
boot firmware. MT6357 additionally passes the array index
MTK_PMIC_HOMEKEY_INDEX as its home key mask.

Patch 1 fixes MT6358 (also used by MT6366), with a register read from an
MT6366 board as evidence. Patch 2 fixes MT6357 from public sources only.

Sources (all public):
 - coreboot: src/soc/mediatek/mt8183/mt6358.c, src/soc/mediatek/mt8186/mt6366.c
   and src/soc/mediatek/common/mt6359p.c, pmic_wdt_set()
 - MediaTek LK2 as published by Gigaset (github.com/Gigaset-dev/lk2):
   platform/mediatek/common/pmic/mt6358/mt6358_psc.c
 - MediaTek's downstream drivers/input/keyboard/mtk-pmic-keys.c as
   published in vendor GPL releases (e.g. OnePlusOSS
   android_kernel_oneplus_mt6789, MotorolaMobilityLLC
   kernel-kernel_device_modules-6.6)

Not addressed here: MT6359. MediaTek's downstream driver uses the same
layout for it, but MediaTek's MT6359P header and coreboot place
TOP_RST_MISC at 0x14a with 0x14c being its _SET alias, while
include/linux/mfd/mt6359/registers.h has 0x14c. Someone with MT6359
hardware should check mt6359_regs separately.

Found and drafted with an AI coding assistant by comparing the driver
against the sources above. Not compile-tested in this form
(both patches only change constants); not run on MT6357 or MT6358
hardware with the mainline driver.

Ilia Snezhkov (2):
  Input: mtk-pmic-keys - fix MT6358 long-press reset bits
  Input: mtk-pmic-keys - fix MT6357 long-press reset bits

 drivers/input/keyboard/mtk-pmic-keys.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

base-commit: 2800868f63227c8237d70c41e70d441c919620d6
-- 
2.54.0 (Apple Git-157)




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

* [PATCH 1/2] Input: mtk-pmic-keys - fix MT6358 long-press reset bits
  2026-11-26  0:07 [PATCH 0/2] Input: mtk-pmic-keys - fix TOP_RST_MISC layout on MT6357/MT6358 Ilia Snezhkov via B4 Relay
@ 2026-11-26  0:07 ` Ilia Snezhkov via B4 Relay
  2026-11-26  0:07 ` [PATCH 2/2] Input: mtk-pmic-keys - fix MT6357 " Ilia Snezhkov via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26  0:07 UTC (permalink / raw)
  To: dmitry.torokhov
  Cc: matthias.bgg, angelogioacchino.delregno, linux-input,
	linux-mediatek, linux-arm-kernel, linux-kernel

From: Ilia Snezhkov <iasnezhkov@gmail.com>

mt6358_regs reuses the MT6397 layout of TOP_RST_MISC: BIT(6) for the
power key reset, BIT(5) for the home key reset and GENMASK(9, 8) for
the long-press time. MT6358 and MT6366, which uses the
"mediatek,mt6358-keys" compatible, lay this register out differently:

  bit 0      RG_WDTRSTB_EN    (PMIC watchdog reset enable)
  bit 1      RG_WDTRSTB_MODE
  bit 5      RG_WDTRSTB_DEB   (PMIC watchdog reset debounce)
  bit 8      home key takes part in the long-press reset
  bit 9      RG_PWRKEY_RST_EN
  bits 13:12 long-press reset time

The watchdog bits are set by the boot firmware in coreboot's
pmic_wdt_set() for MT6358 (mt8183) and MT6366 (mt8186). MediaTek's LK2
names bit 8 RG_PWRKEY_KEY_MODE and bit 9 RG_PWRKEY_RST_EN of
MT6358_TOP_RST_MISC, and MediaTek's downstream mtk-pmic-keys driver
uses reset shifts 9 (power), 8 (home) and 12 (two-bit time) for MT6358
and MT6366.

With the default mediatek,long-press-mode = <0> the probe clears
bits 9:8, 6 and 5. That clears the long-press reset enable as intended,
but only by accident, and also clears RG_WDTRSTB_DEB. With modes 1
and 2, power-off-time-sec is written into the reset enable and key
mode bits, while the enable bits land on bit 6 and on bit 5
(RG_WDTRSTB_DEB).

On an MT6366 board (an MT6789 phone) TOP_RST_MISC reads 0x0225 after
the boot firmware: bits 0 and 5 (watchdog reset enable and debounce)
and bit 9 (power key reset enable). Under the MT6397 layout this would
decode as a home key reset without a power key reset, which the driver
itself can never configure.

Use the MT6358 layout. Its values equal the MT6331 ones, but the
fields are defined separately for this PMIC family.

Found and drafted with an AI coding assistant while bringing up MT6789.

Fixes: 994673dc6657 ("Input: mtk-pmic-keys - add support for MT6358")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---

Notes:
    Tested: TOP_RST_MISC read back on an MT6366 board (MT6789 phone) running
    MediaTek's downstream driver, which programs the MT6358 layout: 0x0225.
    The mainline driver with this change has not been run on hardware and
    was not compile-tested in this form; the change only swaps constants.

 drivers/input/keyboard/mtk-pmic-keys.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
index 6f14318..422a1f4 100644
--- a/drivers/input/keyboard/mtk-pmic-keys.c
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -29,6 +29,10 @@
 #define MTK_PMIC_MT6331_PWRKEY_RST	BIT(9)
 #define MTK_PMIC_MT6331_HOMEKEY_RST	BIT(8)
 
+#define MTK_PMIC_MT6358_RST_DU_MASK	GENMASK(13, 12)
+#define MTK_PMIC_MT6358_PWRKEY_RST	BIT(9)
+#define MTK_PMIC_MT6358_HOMEKEY_RST	BIT(8)
+
 #define MTK_PMIC_PWRKEY_INDEX	0
 #define MTK_PMIC_HOMEKEY_INDEX	1
 #define MTK_PMIC_MAX_KEY_COUNT	2
@@ -110,13 +114,13 @@ static const struct mtk_pmic_regs mt6358_regs = {
 	.keys_regs[MTK_PMIC_PWRKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS,
 				   0x2, MT6358_PSC_TOP_INT_CON0, 0x5,
-				   MTK_PMIC_PWRKEY_RST),
+				   MTK_PMIC_MT6358_PWRKEY_RST),
 	.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6358_TOPSTATUS,
 				   0x8, MT6358_PSC_TOP_INT_CON0, 0xa,
-				   MTK_PMIC_HOMEKEY_RST),
+				   MTK_PMIC_MT6358_HOMEKEY_RST),
 	.pmic_rst_reg = MT6358_TOP_RST_MISC,
-	.rst_lprst_mask = MTK_PMIC_RST_DU_MASK,
+	.rst_lprst_mask = MTK_PMIC_MT6358_RST_DU_MASK,
 	.key_release_irq = true,
 };
 
-- 
2.54.0 (Apple Git-157)




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

* [PATCH 2/2] Input: mtk-pmic-keys - fix MT6357 long-press reset bits
  2026-11-26  0:07 [PATCH 0/2] Input: mtk-pmic-keys - fix TOP_RST_MISC layout on MT6357/MT6358 Ilia Snezhkov via B4 Relay
  2026-11-26  0:07 ` [PATCH 1/2] Input: mtk-pmic-keys - fix MT6358 long-press reset bits Ilia Snezhkov via B4 Relay
@ 2026-11-26  0:07 ` Ilia Snezhkov via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Ilia Snezhkov via B4 Relay @ 2026-11-26  0:07 UTC (permalink / raw)
  To: dmitry.torokhov
  Cc: matthias.bgg, angelogioacchino.delregno, linux-input,
	linux-mediatek, linux-arm-kernel, linux-kernel

From: Ilia Snezhkov <iasnezhkov@gmail.com>

The home key entry of mt6357_regs passes MTK_PMIC_HOMEKEY_INDEX, the
array index 1, as its reset enable mask, so the driver writes BIT(0) of
TOP_RST_MISC for the home key. The other two bits come from the MT6397
layout: BIT(6) for the power key and GENMASK(9, 8) for the long-press
time.

MT6357 shares TOP_RST_MISC at 0x14c with MT6358, and MediaTek's
downstream mtk-pmic-keys driver programs it with the same layout as
MT6358: power key reset enable at bit 9, home key at bit 8 and a two-bit
long-press time at bits 13:12. On MT6358 and MT6366, bit 0 of this
register is RG_WDTRSTB_EN, the PMIC watchdog reset enable (coreboot
pmic_wdt_set()), so with the default mediatek,long-press-mode = <0>
the probe very likely disables the PMIC watchdog reset on MT6357 too.

Use the MT6358 layout for MT6357.

Found and drafted with an AI coding assistant while bringing up MT6789.

Fixes: 297770ec5c93 ("Input: mtk-pmic-keys: add MT6357 support")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---

Notes:
    Not tested on MT6357 hardware: the layout comes from MediaTek's
    downstream driver and from the MT6358/MT6366 sources cited in 1/2.
    Not compile-tested in this form; the change only swaps constants.

 drivers/input/keyboard/mtk-pmic-keys.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/input/keyboard/mtk-pmic-keys.c b/drivers/input/keyboard/mtk-pmic-keys.c
index 422a1f4..39cdb50 100644
--- a/drivers/input/keyboard/mtk-pmic-keys.c
+++ b/drivers/input/keyboard/mtk-pmic-keys.c
@@ -101,13 +101,13 @@ static const struct mtk_pmic_regs mt6357_regs = {
 	.keys_regs[MTK_PMIC_PWRKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6357_TOPSTATUS,
 				   0x2, MT6357_PSC_TOP_INT_CON0, 0x5,
-				   MTK_PMIC_PWRKEY_RST),
+				   MTK_PMIC_MT6358_PWRKEY_RST),
 	.keys_regs[MTK_PMIC_HOMEKEY_INDEX] =
 		MTK_PMIC_KEYS_REGS(MT6357_TOPSTATUS,
 				   0x8, MT6357_PSC_TOP_INT_CON0, 0xa,
-				   MTK_PMIC_HOMEKEY_INDEX),
+				   MTK_PMIC_MT6358_HOMEKEY_RST),
 	.pmic_rst_reg = MT6357_TOP_RST_MISC,
-	.rst_lprst_mask = MTK_PMIC_RST_DU_MASK,
+	.rst_lprst_mask = MTK_PMIC_MT6358_RST_DU_MASK,
 };
 
 static const struct mtk_pmic_regs mt6358_regs = {
-- 
2.54.0 (Apple Git-157)




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

end of thread, other threads:[~2026-11-26  0:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  0:07 [PATCH 0/2] Input: mtk-pmic-keys - fix TOP_RST_MISC layout on MT6357/MT6358 Ilia Snezhkov via B4 Relay
2026-11-26  0:07 ` [PATCH 1/2] Input: mtk-pmic-keys - fix MT6358 long-press reset bits Ilia Snezhkov via B4 Relay
2026-11-26  0:07 ` [PATCH 2/2] Input: mtk-pmic-keys - fix MT6357 " Ilia Snezhkov 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