Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] Input: axp20x-pek - add support for AXP313A variant
@ 2026-06-02  9:55 steven
  2026-06-02 10:10 ` sashiko-bot
  0 siblings, 1 reply; 6+ messages in thread
From: steven @ 2026-06-02  9:55 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Chen-Yu Tsai, linux-input, linux-kernel, Steven Feng

From: Steven Feng <steven@joint-cloud.com>

Add power button support for the AXP313A PMIC. The AXP313A uses
the same register layout and timing parameters as the AXP20X,
so we can reuse the existing axp20x_info structure.

Signed-off-by: Steven Feng <steven@joint-cloud.com>
---
 drivers/input/misc/axp20x-pek.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
index 24f9e9d893de..d4e2fc9a937f 100644
--- a/drivers/input/misc/axp20x-pek.c
+++ b/drivers/input/misc/axp20x-pek.c
@@ -393,6 +393,10 @@ static const struct platform_device_id axp_pek_id_match[] = {
 		.name = "axp221-pek",
 		.driver_data = (kernel_ulong_t)&axp221_info,
 	},
+	{
+		.name = "axp313a-pek",
+		.driver_data = (kernel_ulong_t)&axp20x_info,
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, axp_pek_id_match);
-- 
2.43.0


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

* Re: [PATCH] Input: axp20x-pek - add support for AXP313A variant
  2026-06-02  9:55 steven
@ 2026-06-02 10:10 ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-06-02 10:10 UTC (permalink / raw)
  To: steven; +Cc: dmitry.torokhov, linux-input

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] Sysfs attributes 'startup' and 'shutdown' are unconditionally broken for the newly added AXP313A device due to out-of-bounds regmap access.

Pre-existing issues:
- [High] Unconditional manipulation of uninitialized IRQ 0 during system suspend and resume when input device registration is bypassed.
--

commit 689d64caa4b9f21a0926e40a611d5111bfe37d22
Author: Steven Feng <steven@joint-cloud.com>

Input: axp20x-pek - add support for AXP313A variant

This commit adds power button support for the AXP313A PMIC. It reuses the
existing axp20x_info structure, noting that the AXP313A shares the same
register layout and timing parameters as the AXP20X.

> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
> index 24f9e9d893de3..d4e2fc9a937ff 100644
> --- a/drivers/input/misc/axp20x-pek.c
> +++ b/drivers/input/misc/axp20x-pek.c
> @@ -393,6 +393,10 @@ static const struct platform_device_id axp_pek_id_match[] = {
>  		.name = "axp221-pek",
>  		.driver_data = (kernel_ulong_t)&axp221_info,
>  	},
> +	{
> +		.name = "axp313a-pek",
> +		.driver_data = (kernel_ulong_t)&axp20x_info,

[Severity: Medium]
Will reusing axp20x_info for the AXP313A break the sysfs attributes?

The axp20x_info struct exposes the startup and shutdown sysfs attributes.
When these are accessed, the driver reads or updates AXP20X_PEK_KEY (0x36):

drivers/input/misc/axp20x-pek.c:axp20x_show_attr() {
...
	ret = regmap_read(axp20x_pek->axp20x->regmap, AXP20X_PEK_KEY, &val);
...
}

However, the AXP313A regmap configuration restricts max_register to 0x21
(AXP313A_IRQ_STATE). Won't the regmap core reject accesses to 0x36 with
-EINVAL, making these sysfs attributes non-functional for this device?

> +	},
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(platform, axp_pek_id_match);

[Severity: High]
This is a pre-existing issue, but could the suspend and resume handlers crash
the system if input device registration is skipped?

In axp20x_pek_suspend() and axp20x_pek_resume(), the driver unconditionally
calls disable_irq() and enable_irq():

drivers/input/misc/axp20x-pek.c:axp20x_pek_suspend() {
...
	if (device_may_wakeup(dev)) {
...
	} else {
		disable_irq(axp20x_pek->irq_dbf);
		disable_irq(axp20x_pek->irq_dbr);
	}
...
}

If axp20x_pek_should_register_input() returns false (for instance, on x86
systems where ACPI handles the power button), the IRQs are never initialized
and remain 0.

Does calling disable_irq(0) disable the system timer interrupt on x86,
potentially causing a system hang or panic during the suspend cycle?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_5F1FF80489E702360F352F889570656BF608@qq.com?part=1

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

* [PATCH] Input: axp20x-pek - add support for AXP313A variant
@ 2026-06-03  1:38 steven
  2026-06-03  2:25 ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: steven @ 2026-06-03  1:38 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: wens, linux-input, linux-kernel, steven

Add power button support for the AXP313A PMIC. The AXP313A does not
have the PEK_KEY register (0x36) used to configure startup and shutdown
timings, unlike AXP20X and AXP221. Create a dedicated axp313a_info
configuration with NULL time tables to prevent regmap out-of-bounds
access.

The sysfs attributes (startup/shutdown) will return -EOPNOTSUPP when
accessed on AXP313A devices.

Signed-off-by: steven <steven@joint-cloud.com>
---
Changes in v2:
- Fixed regmap out-of-bounds access issue reported by Sashiko AI
- Created dedicated axp313a_info with NULL time tables
- Added NULL pointer checks to prevent crashes
- AXP313A lacks PEK_KEY (0x36) per datasheet verification
- Power button still functional using hardware default timings

v1: https://lore.kernel.org/all/tencent_5F1FF80489E702360F352F889570656BF608@qq.com/
---
 drivers/input/misc/axp20x-pek.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
index d4e2fc9a937f..de43eef0c0ea 100644
--- a/drivers/input/misc/axp20x-pek.c
+++ b/drivers/input/misc/axp20x-pek.c
@@ -85,6 +85,13 @@ static const struct axp20x_info axp221_info = {
 	.shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK,
 };
 
+static const struct axp20x_info axp313a_info = {
+	.startup_time = NULL,
+	.startup_mask = 0,
+	.shutdown_time = NULL,
+	.shutdown_mask = 0,
+};
+
 static ssize_t axp20x_show_attr(struct device *dev,
 				const struct axp20x_time *time,
 				unsigned int mask, char *buf)
@@ -93,6 +100,9 @@ static ssize_t axp20x_show_attr(struct device *dev,
 	unsigned int val;
 	int ret, i;
 
+	if (!time)
+		return -EOPNOTSUPP;
+
 	ret = regmap_read(axp20x_pek->axp20x->regmap, AXP20X_PEK_KEY, &val);
 	if (ret != 0)
 		return ret;
@@ -137,6 +147,9 @@ static ssize_t axp20x_store_attr(struct device *dev,
 	unsigned int val, idx = 0;
 	unsigned int best_err = UINT_MAX;
 
+	if (!time)
+		return -EOPNOTSUPP;
+
 	ret = kstrtouint(buf, 10, &val);
 	if (ret)
 		return ret;
@@ -395,7 +408,7 @@ static const struct platform_device_id axp_pek_id_match[] = {
 	},
 	{
 		.name = "axp313a-pek",
-		.driver_data = (kernel_ulong_t)&axp20x_info,
+		.driver_data = (kernel_ulong_t)&axp313a_info,
 	},
 	{ /* sentinel */ }
 };
-- 
2.43.0


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

* Re: [PATCH] Input: axp20x-pek - add support for AXP313A variant
  2026-06-03  1:38 [PATCH] Input: axp20x-pek - add support for AXP313A variant steven
@ 2026-06-03  2:25 ` Dmitry Torokhov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2026-06-03  2:25 UTC (permalink / raw)
  To: steven; +Cc: wens, linux-input, linux-kernel

On Wed, Jun 03, 2026 at 09:38:54AM +0800, steven wrote:
> Add power button support for the AXP313A PMIC. The AXP313A does not
> have the PEK_KEY register (0x36) used to configure startup and shutdown
> timings, unlike AXP20X and AXP221. Create a dedicated axp313a_info
> configuration with NULL time tables to prevent regmap out-of-bounds
> access.
> 
> The sysfs attributes (startup/shutdown) will return -EOPNOTSUPP when
> accessed on AXP313A devices.
> 
> Signed-off-by: steven <steven@joint-cloud.com>
> ---
> Changes in v2:
> - Fixed regmap out-of-bounds access issue reported by Sashiko AI
> - Created dedicated axp313a_info with NULL time tables
> - Added NULL pointer checks to prevent crashes
> - AXP313A lacks PEK_KEY (0x36) per datasheet verification
> - Power button still functional using hardware default timings
> 
> v1: https://lore.kernel.org/all/tencent_5F1FF80489E702360F352F889570656BF608@qq.com/
> ---
>  drivers/input/misc/axp20x-pek.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
> index d4e2fc9a937f..de43eef0c0ea 100644
> --- a/drivers/input/misc/axp20x-pek.c
> +++ b/drivers/input/misc/axp20x-pek.c
> @@ -85,6 +85,13 @@ static const struct axp20x_info axp221_info = {
>  	.shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK,
>  };
>  
> +static const struct axp20x_info axp313a_info = {
> +	.startup_time = NULL,
> +	.startup_mask = 0,
> +	.shutdown_time = NULL,
> +	.shutdown_mask = 0,
> +};
> +
>  static ssize_t axp20x_show_attr(struct device *dev,
>  				const struct axp20x_time *time,
>  				unsigned int mask, char *buf)
> @@ -93,6 +100,9 @@ static ssize_t axp20x_show_attr(struct device *dev,
>  	unsigned int val;
>  	int ret, i;
>  
> +	if (!time)
> +		return -EOPNOTSUPP;


Use is_visible to control whether attributes are accessible.

Thanks.

-- 
Dmitry

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

* [PATCH] Input: axp20x-pek - add support for AXP313A variant
       [not found] <ZoMD9s0Xs_VBzIKC@google.com>
@ 2026-06-03  2:59 ` Steven Feng
  2026-06-03  7:23   ` Chen-Yu Tsai
  0 siblings, 1 reply; 6+ messages in thread
From: Steven Feng @ 2026-06-03  2:59 UTC (permalink / raw)
  To: dmitry.torokhov; +Cc: wens, linux-input, linux-kernel, Steven Feng

Add power button support for the AXP313A PMIC. The AXP313A does not
have the PEK_KEY register (0x36) used to configure startup and shutdown
timings, unlike AXP20X and AXP221. Create a dedicated axp313a_info
configuration with NULL time tables to prevent regmap out-of-bounds
access.

For AXP313A, the sysfs attributes (startup/shutdown) are hidden using
the is_visible callback, as they are not supported by the hardware.

Signed-off-by: Steven Feng <steven@joint-cloud.com>
---
Changes in v3:
- Use is_visible to hide attributes instead of returning -EOPNOTSUPP
- Corrected author name from "steven" to "Steven Feng"

Changes in v2:
- Fixed regmap out-of-bounds access issue reported by Sashiko AI
- Created dedicated axp313a_info with NULL time tables
- Added NULL pointer checks to prevent crashes
- AXP313A lacks PEK_KEY (0x36) per datasheet verification
- Power button still functional using hardware default timings

v2: https://lore.kernel.org/all/tencent_48A497E0CA81323CFB6C7CB84428019A8707@qq.com/
v1: https://lore.kernel.org/all/tencent_5F1FF80489E702360F352F889570656BF608@qq.com/
---
 drivers/input/misc/axp20x-pek.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
index d4e2fc9a937f..964b39817af9 100644
--- a/drivers/input/misc/axp20x-pek.c
+++ b/drivers/input/misc/axp20x-pek.c
@@ -85,6 +85,13 @@ static const struct axp20x_info axp221_info = {
 	.shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK,
 };
 
+static const struct axp20x_info axp313a_info = {
+	.startup_time = NULL,
+	.startup_mask = 0,
+	.shutdown_time = NULL,
+	.shutdown_mask = 0,
+};
+
 static ssize_t axp20x_show_attr(struct device *dev,
 				const struct axp20x_time *time,
 				unsigned int mask, char *buf)
@@ -193,7 +200,28 @@ static struct attribute *axp20x_attrs[] = {
 	&dev_attr_shutdown.attr,
 	NULL,
 };
-ATTRIBUTE_GROUPS(axp20x);
+
+static umode_t axp20x_attr_is_visible(struct kobject *kobj,
+				      struct attribute *attr, int n)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
+
+	if (!axp20x_pek->info->startup_time)
+		return 0;
+
+	return attr->mode;
+}
+
+static const struct attribute_group axp20x_group = {
+	.attrs = axp20x_attrs,
+	.is_visible = axp20x_attr_is_visible,
+};
+
+static const struct attribute_group *axp20x_groups[] = {
+	&axp20x_group,
+	NULL,
+};
 
 static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
 {
@@ -395,7 +423,7 @@ static const struct platform_device_id axp_pek_id_match[] = {
 	},
 	{
 		.name = "axp313a-pek",
-		.driver_data = (kernel_ulong_t)&axp20x_info,
+		.driver_data = (kernel_ulong_t)&axp313a_info,
 	},
 	{ /* sentinel */ }
 };
-- 
2.43.0


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

* Re: [PATCH] Input: axp20x-pek - add support for AXP313A variant
  2026-06-03  2:59 ` Steven Feng
@ 2026-06-03  7:23   ` Chen-Yu Tsai
  0 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2026-06-03  7:23 UTC (permalink / raw)
  To: Steven Feng; +Cc: dmitry.torokhov, linux-input, linux-kernel

On Wed, Jun 3, 2026 at 11:00 AM Steven Feng <steven@joint-cloud.com> wrote:
>
> Add power button support for the AXP313A PMIC. The AXP313A does not
> have the PEK_KEY register (0x36) used to configure startup and shutdown
> timings, unlike AXP20X and AXP221. Create a dedicated axp313a_info
> configuration with NULL time tables to prevent regmap out-of-bounds
> access.
>
> For AXP313A, the sysfs attributes (startup/shutdown) are hidden using
> the is_visible callback, as they are not supported by the hardware.
>
> Signed-off-by: Steven Feng <steven@joint-cloud.com>
> ---
> Changes in v3:
> - Use is_visible to hide attributes instead of returning -EOPNOTSUPP

Adding this should be a separate patch. In the commit message you can
say it is needed for a future device added in the next patch.

> - Corrected author name from "steven" to "Steven Feng"

Please label the version in the subject as well. The subject should
read "[PATCH v3]" for v3. `git format-patch -vN ...` will do the right
thing for you.

ChenYu

> Changes in v2:
> - Fixed regmap out-of-bounds access issue reported by Sashiko AI
> - Created dedicated axp313a_info with NULL time tables
> - Added NULL pointer checks to prevent crashes
> - AXP313A lacks PEK_KEY (0x36) per datasheet verification
> - Power button still functional using hardware default timings
>
> v2: https://lore.kernel.org/all/tencent_48A497E0CA81323CFB6C7CB84428019A8707@qq.com/
> v1: https://lore.kernel.org/all/tencent_5F1FF80489E702360F352F889570656BF608@qq.com/
> ---
>  drivers/input/misc/axp20x-pek.c | 32 ++++++++++++++++++++++++++++++--
>  1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
> index d4e2fc9a937f..964b39817af9 100644
> --- a/drivers/input/misc/axp20x-pek.c
> +++ b/drivers/input/misc/axp20x-pek.c
> @@ -85,6 +85,13 @@ static const struct axp20x_info axp221_info = {
>         .shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK,
>  };
>
> +static const struct axp20x_info axp313a_info = {
> +       .startup_time = NULL,
> +       .startup_mask = 0,
> +       .shutdown_time = NULL,
> +       .shutdown_mask = 0,
> +};
> +
>  static ssize_t axp20x_show_attr(struct device *dev,
>                                 const struct axp20x_time *time,
>                                 unsigned int mask, char *buf)
> @@ -193,7 +200,28 @@ static struct attribute *axp20x_attrs[] = {
>         &dev_attr_shutdown.attr,
>         NULL,
>  };
> -ATTRIBUTE_GROUPS(axp20x);
> +
> +static umode_t axp20x_attr_is_visible(struct kobject *kobj,
> +                                     struct attribute *attr, int n)
> +{
> +       struct device *dev = kobj_to_dev(kobj);
> +       struct axp20x_pek *axp20x_pek = dev_get_drvdata(dev);
> +
> +       if (!axp20x_pek->info->startup_time)
> +               return 0;
> +
> +       return attr->mode;
> +}
> +
> +static const struct attribute_group axp20x_group = {
> +       .attrs = axp20x_attrs,
> +       .is_visible = axp20x_attr_is_visible,
> +};
> +
> +static const struct attribute_group *axp20x_groups[] = {
> +       &axp20x_group,
> +       NULL,
> +};
>
>  static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
>  {
> @@ -395,7 +423,7 @@ static const struct platform_device_id axp_pek_id_match[] = {
>         },
>         {
>                 .name = "axp313a-pek",
> -               .driver_data = (kernel_ulong_t)&axp20x_info,
> +               .driver_data = (kernel_ulong_t)&axp313a_info,
>         },
>         { /* sentinel */ }
>  };
> --
> 2.43.0
>

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

end of thread, other threads:[~2026-06-03  7:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03  1:38 [PATCH] Input: axp20x-pek - add support for AXP313A variant steven
2026-06-03  2:25 ` Dmitry Torokhov
     [not found] <ZoMD9s0Xs_VBzIKC@google.com>
2026-06-03  2:59 ` Steven Feng
2026-06-03  7:23   ` Chen-Yu Tsai
  -- strict thread matches above, loose matches on Subject: below --
2026-06-02  9:55 steven
2026-06-02 10:10 ` sashiko-bot

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