[PATCH] Input: axp20x-pek - add support for AXP313A variant

Steven Feng posted 1 patch 4 days, 23 hours ago
drivers/input/misc/axp20x-pek.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
[PATCH] Input: axp20x-pek - add support for AXP313A variant
Posted by Steven Feng 4 days, 23 hours ago
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
Re: [PATCH] Input: axp20x-pek - add support for AXP313A variant
Posted by Chen-Yu Tsai 4 days, 18 hours ago
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
>