* [PATCH 1/6] Input: mc13783-pwrbutton: fix irq mixup
2025-08-17 10:27 [PATCH 0/6] Fix, extend and upport OF to mc13xxx pwrbutton Alexander Kurz
@ 2025-08-17 10:27 ` Alexander Kurz
2025-08-17 10:27 ` [PATCH 2/6] Input: mc13783-pwrbutton: use managed resources Alexander Kurz
` (4 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Alexander Kurz @ 2025-08-17 10:27 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Dmitry Torokhov, Dzmitry Sankouski, Dr. David Alan Gilbert,
Heiko Stuebner, Uwe Kleine-König, devicetree, linux-input
Cc: linux-kernel, Alexander Kurz
The mfd mc13xxx interrupt handling was migrated to regmap with commit
10f9edaeaa30 ("mfd: mc13xxx: Use regmap irq framework for interrupts").
As a consequence, button_irq() will get called with virtual irq instead
of chip-internal irq now. Add wrappers for the three supported interrupts.
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
drivers/input/misc/mc13783-pwrbutton.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
index 1c7faa9b7afe..4765b25bc9f6 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -88,6 +88,21 @@ static irqreturn_t button_irq(int irq, void *_priv)
return IRQ_HANDLED;
}
+static irqreturn_t button1_irq(int irq, void *_priv)
+{
+ return button_irq(MC13783_IRQ_ONOFD1, _priv);
+}
+
+static irqreturn_t button2_irq(int irq, void *_priv)
+{
+ return button_irq(MC13783_IRQ_ONOFD2, _priv);
+}
+
+static irqreturn_t button3_irq(int irq, void *_priv)
+{
+ return button_irq(MC13783_IRQ_ONOFD3, _priv);
+}
+
static int mc13783_pwrbutton_probe(struct platform_device *pdev)
{
const struct mc13xxx_buttons_platform_data *pdata;
@@ -137,7 +152,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1,
- button_irq, "b1on", priv);
+ button1_irq, "b1on", priv);
if (err) {
dev_dbg(&pdev->dev, "Can't request irq\n");
goto free_priv;
@@ -156,7 +171,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2,
- button_irq, "b2on", priv);
+ button2_irq, "b2on", priv);
if (err) {
dev_dbg(&pdev->dev, "Can't request irq\n");
goto free_irq_b1;
@@ -175,7 +190,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3,
- button_irq, "b3on", priv);
+ button3_irq, "b3on", priv);
if (err) {
dev_dbg(&pdev->dev, "Can't request irq: %d\n", err);
goto free_irq_b2;
--
2.39.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 2/6] Input: mc13783-pwrbutton: use managed resources
2025-08-17 10:27 [PATCH 0/6] Fix, extend and upport OF to mc13xxx pwrbutton Alexander Kurz
2025-08-17 10:27 ` [PATCH 1/6] Input: mc13783-pwrbutton: fix irq mixup Alexander Kurz
@ 2025-08-17 10:27 ` Alexander Kurz
2025-08-17 10:27 ` [PATCH 3/6] Input: mc13783-pwrbutton: enable other mc13xxx PMIC Alexander Kurz
` (3 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Alexander Kurz @ 2025-08-17 10:27 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Dmitry Torokhov, Dzmitry Sankouski, Dr. David Alan Gilbert,
Heiko Stuebner, Uwe Kleine-König, devicetree, linux-input
Cc: linux-kernel, Alexander Kurz
Use devres functionality to simplify resource freeing, dev.parent will
be set by devm_input_allocate_device().
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
drivers/input/misc/mc13783-pwrbutton.c | 28 ++++++++------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
index 4765b25bc9f6..9fd84b8d163d 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -21,6 +21,7 @@
#include <linux/module.h>
#include <linux/kernel.h>
+#include <linux/device.h>
#include <linux/errno.h>
#include <linux/input.h>
#include <linux/interrupt.h>
@@ -118,18 +119,13 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
return -ENODEV;
}
- pwr = input_allocate_device();
- if (!pwr) {
- dev_dbg(&pdev->dev, "Can't allocate power button\n");
+ pwr = devm_input_allocate_device(&pdev->dev);
+ if (!pwr)
return -ENOMEM;
- }
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
- if (!priv) {
- err = -ENOMEM;
- dev_dbg(&pdev->dev, "Can't allocate power button\n");
- goto free_input_dev;
- }
+ priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
@@ -155,7 +151,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
button1_irq, "b1on", priv);
if (err) {
dev_dbg(&pdev->dev, "Can't request irq\n");
- goto free_priv;
+ goto free_mc13xxx_lock;
}
}
@@ -203,7 +199,6 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
pwr->name = "mc13783_pwrbutton";
pwr->phys = "mc13783_pwrbutton/input0";
- pwr->dev.parent = &pdev->dev;
pwr->keycode = priv->keymap;
pwr->keycodemax = ARRAY_SIZE(priv->keymap);
@@ -234,12 +229,8 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
-free_priv:
+free_mc13xxx_lock:
mc13xxx_unlock(mc13783);
- kfree(priv);
-
-free_input_dev:
- input_free_device(pwr);
return err;
}
@@ -261,9 +252,6 @@ static void mc13783_pwrbutton_remove(struct platform_device *pdev)
mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
mc13xxx_unlock(priv->mc13783);
-
- input_unregister_device(priv->pwr);
- kfree(priv);
}
static struct platform_driver mc13783_pwrbutton_driver = {
--
2.39.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 3/6] Input: mc13783-pwrbutton: enable other mc13xxx PMIC
2025-08-17 10:27 [PATCH 0/6] Fix, extend and upport OF to mc13xxx pwrbutton Alexander Kurz
2025-08-17 10:27 ` [PATCH 1/6] Input: mc13783-pwrbutton: fix irq mixup Alexander Kurz
2025-08-17 10:27 ` [PATCH 2/6] Input: mc13783-pwrbutton: use managed resources Alexander Kurz
@ 2025-08-17 10:27 ` Alexander Kurz
2025-09-02 13:43 ` Lee Jones
2025-08-17 10:27 ` [PATCH 4/6] Input: mc13783-pwrbutton: convert members to array Alexander Kurz
` (2 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Alexander Kurz @ 2025-08-17 10:27 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Dmitry Torokhov, Dzmitry Sankouski, Dr. David Alan Gilbert,
Heiko Stuebner, Uwe Kleine-König, devicetree, linux-input
Cc: linux-kernel, Alexander Kurz
All three mc13xxx types do feature two common power buttons while mc13783
and mc13892 provide one extra button each that differs unfortunately.
The common buttons are ONOFD[12] (mc13783) and PWRON[12] (mc13892/mc34708).
ONOFD3 on mc13783 will still be supported while support for PWRON3 for
mc13892 will be left unsupported for simplicity.
Add the similarities to the header files for reference, extend the
platform_driver struct with the id table to support all three types.
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
drivers/input/misc/Kconfig | 4 ++--
drivers/input/misc/mc13783-pwrbutton.c | 21 ++++++++++++++++++---
include/linux/mfd/mc13783.h | 4 ++--
include/linux/mfd/mc13xxx.h | 9 +++++++++
4 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 0fb21c99a5e3..b66e920369f2 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -276,8 +276,8 @@ config INPUT_MC13783_PWRBUTTON
tristate "MC13783 ON buttons"
depends on MFD_MC13XXX
help
- Support the ON buttons of MC13783 PMIC as an input device
- reporting power button status.
+ Support the ON buttons of MC13783/MC13892/MC34708 PMIC as an input
+ device reporting power button status.
To compile this driver as a module, choose M here: the module
will be called mc13783-pwrbutton.
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
index 9fd84b8d163d..cb2f25a1a757 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -33,13 +33,14 @@
struct mc13783_pwrb {
struct input_dev *pwr;
struct mc13xxx *mc13783;
-#define MC13783_PWRB_B1_POL_INVERT (1 << 0)
-#define MC13783_PWRB_B2_POL_INVERT (1 << 1)
-#define MC13783_PWRB_B3_POL_INVERT (1 << 2)
int flags;
unsigned short keymap[3];
};
+#define MC13783_PWRB_B1_POL_INVERT (1 << 0)
+#define MC13783_PWRB_B2_POL_INVERT (1 << 1)
+#define MC13783_PWRB_B3_POL_INVERT (1 << 2)
+
#define MC13783_REG_INTERRUPT_SENSE_1 5
#define MC13783_IRQSENSE1_ONOFD1S (1 << 3)
#define MC13783_IRQSENSE1_ONOFD2S (1 << 4)
@@ -108,6 +109,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
{
const struct mc13xxx_buttons_platform_data *pdata;
struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
+ enum mc13xxx_chip_type chip = platform_get_device_id(pdev)->driver_data;
struct input_dev *pwr;
struct mc13783_pwrb *priv;
int err = 0;
@@ -127,6 +129,11 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
if (!priv)
return -ENOMEM;
+ /* ONOFD3 is only supported for MC13783. */
+ if (pdata->b3on_flags & MC13783_BUTTON_ENABLE &&
+ chip != MC13XXX_CHIP_TYPE_MC13783)
+ return -ENODEV;
+
reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
@@ -254,7 +261,15 @@ static void mc13783_pwrbutton_remove(struct platform_device *pdev)
mc13xxx_unlock(priv->mc13783);
}
+static const struct platform_device_id mc13xxx_pwrbutton_idtable[] = {
+ { "mc13783-pwrbutton", MC13XXX_CHIP_TYPE_MC13783 },
+ { "mc13892-pwrbutton", MC13XXX_CHIP_TYPE_MC13892 },
+ { "mc34708-pwrbutton", MC13XXX_CHIP_TYPE_MC34708 },
+ { /* sentinel */ }
+};
+
static struct platform_driver mc13783_pwrbutton_driver = {
+ .id_table = mc13xxx_pwrbutton_idtable,
.probe = mc13783_pwrbutton_probe,
.remove = mc13783_pwrbutton_remove,
.driver = {
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
index c25b1676741b..ab6db774e1fa 100644
--- a/include/linux/mfd/mc13783.h
+++ b/include/linux/mfd/mc13783.h
@@ -65,8 +65,8 @@
#define MC13783_IRQ_UDM 23
#define MC13783_IRQ_1HZ MC13XXX_IRQ_1HZ
#define MC13783_IRQ_TODA MC13XXX_IRQ_TODA
-#define MC13783_IRQ_ONOFD1 27
-#define MC13783_IRQ_ONOFD2 28
+#define MC13783_IRQ_ONOFD1 MC13XXX_IRQ_PWRON1
+#define MC13783_IRQ_ONOFD2 MC13XXX_IRQ_PWRON2
#define MC13783_IRQ_ONOFD3 29
#define MC13783_IRQ_SYSRST MC13XXX_IRQ_SYSRST
#define MC13783_IRQ_RTCRST MC13XXX_IRQ_RTCRST
diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
index f372926d5894..6984ea69db3e 100644
--- a/include/linux/mfd/mc13xxx.h
+++ b/include/linux/mfd/mc13xxx.h
@@ -67,6 +67,8 @@ int mc13xxx_irq_unmask(struct mc13xxx *mc13xxx, int irq);
#define MC13XXX_IRQ_LOBATH 14
#define MC13XXX_IRQ_1HZ 24
#define MC13XXX_IRQ_TODA 25
+#define MC13XXX_IRQ_PWRON1 27
+#define MC13XXX_IRQ_PWRON2 28
#define MC13XXX_IRQ_SYSRST 30
#define MC13XXX_IRQ_RTCRST 31
#define MC13XXX_IRQ_PC 32
@@ -78,6 +80,13 @@ int mc13xxx_irq_unmask(struct mc13xxx *mc13xxx, int irq);
struct regulator_init_data;
+enum mc13xxx_chip_type {
+ MC13XXX_CHIP_TYPE_MC13783,
+ MC13XXX_CHIP_TYPE_MC13892,
+ MC13XXX_CHIP_TYPE_MC34708,
+ MC13XXX_CHIP_TYPE_AMOUNT
+};
+
struct mc13xxx_regulator_init_data {
int id;
struct regulator_init_data *init_data;
--
2.39.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 3/6] Input: mc13783-pwrbutton: enable other mc13xxx PMIC
2025-08-17 10:27 ` [PATCH 3/6] Input: mc13783-pwrbutton: enable other mc13xxx PMIC Alexander Kurz
@ 2025-09-02 13:43 ` Lee Jones
0 siblings, 0 replies; 14+ messages in thread
From: Lee Jones @ 2025-09-02 13:43 UTC (permalink / raw)
To: Alexander Kurz
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Dmitry Torokhov,
Dzmitry Sankouski, Dr. David Alan Gilbert, Heiko Stuebner,
Uwe Kleine-König, devicetree, linux-input, linux-kernel
On Sun, 17 Aug 2025, Alexander Kurz wrote:
> All three mc13xxx types do feature two common power buttons while mc13783
> and mc13892 provide one extra button each that differs unfortunately.
> The common buttons are ONOFD[12] (mc13783) and PWRON[12] (mc13892/mc34708).
> ONOFD3 on mc13783 will still be supported while support for PWRON3 for
> mc13892 will be left unsupported for simplicity.
> Add the similarities to the header files for reference, extend the
> platform_driver struct with the id table to support all three types.
>
> Signed-off-by: Alexander Kurz <akurz@blala.de>
> ---
> drivers/input/misc/Kconfig | 4 ++--
> drivers/input/misc/mc13783-pwrbutton.c | 21 ++++++++++++++++++---
> include/linux/mfd/mc13783.h | 4 ++--
> include/linux/mfd/mc13xxx.h | 9 +++++++++
Acked-by: Lee Jones <lee@kernel.org>
> 4 files changed, 31 insertions(+), 7 deletions(-)
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/6] Input: mc13783-pwrbutton: convert members to array
2025-08-17 10:27 [PATCH 0/6] Fix, extend and upport OF to mc13xxx pwrbutton Alexander Kurz
` (2 preceding siblings ...)
2025-08-17 10:27 ` [PATCH 3/6] Input: mc13783-pwrbutton: enable other mc13xxx PMIC Alexander Kurz
@ 2025-08-17 10:27 ` Alexander Kurz
2025-08-17 10:27 ` [PATCH 5/6] dt-bindings: mfd: mc13xxx: add pwrbutton dt support Alexander Kurz
2025-08-17 10:27 ` [PATCH 6/6] Input: mc13783-pwrbutton: add OF support Alexander Kurz
5 siblings, 0 replies; 14+ messages in thread
From: Alexander Kurz @ 2025-08-17 10:27 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Dmitry Torokhov, Dzmitry Sankouski, Dr. David Alan Gilbert,
Heiko Stuebner, Uwe Kleine-König, devicetree, linux-input
Cc: linux-kernel, Alexander Kurz
As preparation for mc13783-pwrbutton OF support, convert the members of
mc13xxx_buttons_platform_data to arrays to allow index access within
the next commit.
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
drivers/input/misc/mc13783-pwrbutton.c | 56 +++++++++++++-------------
include/linux/mfd/mc13xxx.h | 8 +---
2 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
index cb2f25a1a757..49bc5d25f098 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -130,28 +130,28 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
return -ENOMEM;
/* ONOFD3 is only supported for MC13783. */
- if (pdata->b3on_flags & MC13783_BUTTON_ENABLE &&
+ if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE &&
chip != MC13XXX_CHIP_TYPE_MC13783)
return -ENODEV;
- reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
- reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
- reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
+ reg |= (pdata->b_on_flags[0] & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
+ reg |= (pdata->b_on_flags[1] & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
+ reg |= (pdata->b_on_flags[2] & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
priv->pwr = pwr;
priv->mc13783 = mc13783;
mc13xxx_lock(mc13783);
- if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
- priv->keymap[0] = pdata->b1on_key;
- if (pdata->b1on_key != KEY_RESERVED)
- __set_bit(pdata->b1on_key, pwr->keybit);
+ if (pdata->b_on_flags[0] & MC13783_BUTTON_ENABLE) {
+ priv->keymap[0] = pdata->b_on_key[0];
+ if (pdata->b_on_key[0] != KEY_RESERVED)
+ __set_bit(pdata->b_on_key[0], pwr->keybit);
- if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
+ if (pdata->b_on_flags[0] & MC13783_BUTTON_POL_INVERT)
priv->flags |= MC13783_PWRB_B1_POL_INVERT;
- if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
+ if (pdata->b_on_flags[0] & MC13783_BUTTON_RESET_EN)
reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1,
@@ -162,15 +162,15 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
}
}
- if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
- priv->keymap[1] = pdata->b2on_key;
- if (pdata->b2on_key != KEY_RESERVED)
- __set_bit(pdata->b2on_key, pwr->keybit);
+ if (pdata->b_on_flags[1] & MC13783_BUTTON_ENABLE) {
+ priv->keymap[1] = pdata->b_on_key[1];
+ if (pdata->b_on_key[1] != KEY_RESERVED)
+ __set_bit(pdata->b_on_key[1], pwr->keybit);
- if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
+ if (pdata->b_on_flags[1] & MC13783_BUTTON_POL_INVERT)
priv->flags |= MC13783_PWRB_B2_POL_INVERT;
- if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
+ if (pdata->b_on_flags[1] & MC13783_BUTTON_RESET_EN)
reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2,
@@ -181,15 +181,15 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
}
}
- if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
- priv->keymap[2] = pdata->b3on_key;
- if (pdata->b3on_key != KEY_RESERVED)
- __set_bit(pdata->b3on_key, pwr->keybit);
+ if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE) {
+ priv->keymap[2] = pdata->b_on_key[3];
+ if (pdata->b_on_key[3] != KEY_RESERVED)
+ __set_bit(pdata->b_on_key[3], pwr->keybit);
- if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
+ if (pdata->b_on_flags[2] & MC13783_BUTTON_POL_INVERT)
priv->flags |= MC13783_PWRB_B3_POL_INVERT;
- if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
+ if (pdata->b_on_flags[2] & MC13783_BUTTON_RESET_EN)
reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3,
@@ -225,15 +225,15 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
free_irq:
mc13xxx_lock(mc13783);
- if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+ if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
free_irq_b2:
- if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+ if (pdata->b_on_flags[1] & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
free_irq_b1:
- if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+ if (pdata->b_on_flags[0] & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
free_mc13xxx_lock:
@@ -251,11 +251,11 @@ static void mc13783_pwrbutton_remove(struct platform_device *pdev)
mc13xxx_lock(priv->mc13783);
- if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+ if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
- if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+ if (pdata->b_on_flags[1] & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
- if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+ if (pdata->b_on_flags[0] & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
mc13xxx_unlock(priv->mc13783);
diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
index 6984ea69db3e..8bd25b0532ba 100644
--- a/include/linux/mfd/mc13xxx.h
+++ b/include/linux/mfd/mc13xxx.h
@@ -196,12 +196,8 @@ struct mc13xxx_leds_platform_data {
#define MC13783_BUTTON_RESET_EN (1 << 4)
struct mc13xxx_buttons_platform_data {
- int b1on_flags;
- unsigned short b1on_key;
- int b2on_flags;
- unsigned short b2on_key;
- int b3on_flags;
- unsigned short b3on_key;
+ int b_on_flags[3];
+ unsigned int b_on_key[3];
};
#define MC13783_TS_ATO_FIRST false
--
2.39.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 5/6] dt-bindings: mfd: mc13xxx: add pwrbutton dt support
2025-08-17 10:27 [PATCH 0/6] Fix, extend and upport OF to mc13xxx pwrbutton Alexander Kurz
` (3 preceding siblings ...)
2025-08-17 10:27 ` [PATCH 4/6] Input: mc13783-pwrbutton: convert members to array Alexander Kurz
@ 2025-08-17 10:27 ` Alexander Kurz
2025-08-17 11:20 ` Krzysztof Kozlowski
2025-08-17 10:27 ` [PATCH 6/6] Input: mc13783-pwrbutton: add OF support Alexander Kurz
5 siblings, 1 reply; 14+ messages in thread
From: Alexander Kurz @ 2025-08-17 10:27 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Dmitry Torokhov, Dzmitry Sankouski, Dr. David Alan Gilbert,
Heiko Stuebner, Uwe Kleine-König, devicetree, linux-input
Cc: linux-kernel, Alexander Kurz
The mc13xxx series features two or three power buttons that may be used
as input device. OF support will be added in a different commit.
Add a short documentation for it according to the reference- and User-
manuals of the mc13xxx series.
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
.../devicetree/bindings/mfd/mc13xxx.txt | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/Documentation/devicetree/bindings/mfd/mc13xxx.txt b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
index 8261ea73278a..3c7bad07858f 100644
--- a/Documentation/devicetree/bindings/mfd/mc13xxx.txt
+++ b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
@@ -24,6 +24,15 @@ Sub-nodes:
Documentation/devicetree/bindings/leds/common.txt.
- regulators : Contain the regulator nodes. The regulators are bound using
their names as listed below with their registers and bits for enabling.
+- pwrbuttons : Contains the onoff input button nodes.
+ - #address-cells: Must be 1.
+ - #size-cells: Must be 0.
+ - reg: Contains the BUTTON ID (see below)
+ - linux,code
+ - debounce-delay-value: debouncing selection of 0 (0ms), 1 (default 30ms),
+ 2(150ms) or 3 (750ms).
+ - active-low
+ - enable-reset
MC13783 LED IDs:
0 : Main display
@@ -110,6 +119,20 @@ MC13892 regulators:
The bindings details of individual regulator device can be found in:
Documentation/devicetree/bindings/regulator/regulator.txt
+MC13783 BUTTON IDs:
+ 0 : ONOFD1
+ 1 : ONOFD2
+ 2 : ONOFD3
+
+MC13892 BUTTON IDs:
+ 0 : PWRON1
+ 1 : PWRON2
+ 2 : <not supported>
+
+MC34708 BUTTON IDs:
+ 0 : PWRON1
+ 1 : PWRON2
+
Examples:
ecspi@70010000 { /* ECSPI1 */
@@ -152,5 +175,17 @@ ecspi@70010000 { /* ECSPI1 */
regulator-always-on;
};
};
+
+ pwrbuttons {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ pwrbutton@0 {
+ reg = <0>;
+ linux,code = <KEY_POWER>;
+ debounce-delay-value = <2>;
+ active-low;
+ enable-reset;
+ };
+ };
};
};
--
2.39.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 5/6] dt-bindings: mfd: mc13xxx: add pwrbutton dt support
2025-08-17 10:27 ` [PATCH 5/6] dt-bindings: mfd: mc13xxx: add pwrbutton dt support Alexander Kurz
@ 2025-08-17 11:20 ` Krzysztof Kozlowski
0 siblings, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2025-08-17 11:20 UTC (permalink / raw)
To: Alexander Kurz, Lee Jones, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Dmitry Torokhov, Dzmitry Sankouski,
Dr. David Alan Gilbert, Heiko Stuebner, Uwe Kleine-König,
devicetree, linux-input
Cc: linux-kernel
On 17/08/2025 12:27, Alexander Kurz wrote:
> diff --git a/Documentation/devicetree/bindings/mfd/mc13xxx.txt b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
> index 8261ea73278a..3c7bad07858f 100644
> --- a/Documentation/devicetree/bindings/mfd/mc13xxx.txt
> +++ b/Documentation/devicetree/bindings/mfd/mc13xxx.txt
> @@ -24,6 +24,15 @@ Sub-nodes:
> Documentation/devicetree/bindings/leds/common.txt.
> - regulators : Contain the regulator nodes. The regulators are bound using
> their names as listed below with their registers and bits for enabling.
> +- pwrbuttons : Contains the onoff input button nodes.
> + - #address-cells: Must be 1.
> + - #size-cells: Must be 0.
> + - reg: Contains the BUTTON ID (see below)
> + - linux,code
> + - debounce-delay-value: debouncing selection of 0 (0ms), 1 (default 30ms),
> + 2(150ms) or 3 (750ms).
> + - active-low
> + - enable-reset
We do not take new properties in TXT format, especially entire device nodes.
Please convert the binding to DT schema first and then extend it.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 6/6] Input: mc13783-pwrbutton: add OF support
2025-08-17 10:27 [PATCH 0/6] Fix, extend and upport OF to mc13xxx pwrbutton Alexander Kurz
` (4 preceding siblings ...)
2025-08-17 10:27 ` [PATCH 5/6] dt-bindings: mfd: mc13xxx: add pwrbutton dt support Alexander Kurz
@ 2025-08-17 10:27 ` Alexander Kurz
2025-08-17 11:24 ` Krzysztof Kozlowski
` (2 more replies)
5 siblings, 3 replies; 14+ messages in thread
From: Alexander Kurz @ 2025-08-17 10:27 UTC (permalink / raw)
To: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Dmitry Torokhov, Dzmitry Sankouski, Dr. David Alan Gilbert,
Heiko Stuebner, Uwe Kleine-König, devicetree, linux-input
Cc: linux-kernel, Alexander Kurz
Add OF support for the mc13783-pwrbutton so that it can be used with
modern DT based systems.
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
drivers/input/misc/mc13783-pwrbutton.c | 78 +++++++++++++++++++++++++-
1 file changed, 75 insertions(+), 3 deletions(-)
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
index 49bc5d25f098..11a97ce070a5 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -29,6 +29,7 @@
#include <linux/mfd/mc13783.h>
#include <linux/sched.h>
#include <linux/slab.h>
+#include <linux/of.h>
struct mc13783_pwrb {
struct input_dev *pwr;
@@ -105,8 +106,75 @@ static irqreturn_t button3_irq(int irq, void *_priv)
return button_irq(MC13783_IRQ_ONOFD3, _priv);
}
+#ifdef CONFIG_OF
+static inline struct mc13xxx_buttons_platform_data __init *mc13xxx_pwrbutton_probe_dt(
+ struct platform_device *pdev)
+{
+ struct mc13xxx_buttons_platform_data *pdata;
+ struct device_node *parent, *child;
+ struct device *dev = &pdev->dev;
+ enum mc13xxx_chip_type chip = platform_get_device_id(pdev)->driver_data;
+ int ret = -ENODATA;
+
+ /* ONOFD3 is only supported for MC13783. */
+ int max_idx = chip != MC13XXX_CHIP_TYPE_MC13783 ? 2 : 1;
+
+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return ERR_PTR(-ENOMEM);
+
+ parent = of_get_child_by_name(dev->parent->of_node, "pwrbuttons");
+ if (!parent)
+ goto out_node_put;
+
+ for_each_child_of_node(parent, child) {
+ u32 idx;
+ u8 dbnc = MC13783_BUTTON_DBNC_30MS;
+
+ if (of_property_read_u32(child, "reg", &idx))
+ continue;
+
+ if (idx > max_idx) {
+ dev_warn(dev, "reg out of range\n");
+ continue;
+ }
+
+ of_property_read_u8(child, "debounce-delay-value", &dbnc);
+ if (dbnc > MC13783_BUTTON_DBNC_750MS) {
+ dev_warn(dev, "debounce-delay-value out of range\n");
+ continue;
+ }
+
+ if (of_property_read_u32(child, "linux,code", &pdata->b_on_key[idx]))
+ continue;
+
+ if (of_property_read_bool(child, "active-low"))
+ pdata->b_on_flags[idx] |= MC13783_BUTTON_POL_INVERT;
+
+ if (of_property_read_bool(child, "enable-reset"))
+ pdata->b_on_flags[idx] |= MC13783_BUTTON_RESET_EN;
+
+ pdata->b_on_flags[idx] |= MC13783_BUTTON_ENABLE | dbnc;
+ }
+
+ ret = 0;
+
+out_node_put:
+ of_node_put(parent);
+
+ return ret ? ERR_PTR(ret) : pdata;
+}
+#else
+static inline struct mc13xxx_buttons_platform_data __init *mc13xxx_pwrbutton_probe_dt(
+ struct platform_device *pdev)
+{
+ return ERR_PTR(-ENODEV);
+}
+#endif
+
static int mc13783_pwrbutton_probe(struct platform_device *pdev)
{
+ struct device *dev = &pdev->dev;
const struct mc13xxx_buttons_platform_data *pdata;
struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
enum mc13xxx_chip_type chip = platform_get_device_id(pdev)->driver_data;
@@ -116,9 +184,13 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
int reg = 0;
pdata = dev_get_platdata(&pdev->dev);
- if (!pdata) {
- dev_err(&pdev->dev, "missing platform data\n");
- return -ENODEV;
+ if (dev->parent->of_node) {
+ pdata = mc13xxx_pwrbutton_probe_dt(pdev);
+ if (IS_ERR(pdata))
+ return PTR_ERR(pdata);
+ } else if (!pdata) {
+ dev_err(dev, "missing platform data\n");
+ return -ENODATA;
}
pwr = devm_input_allocate_device(&pdev->dev);
--
2.39.5
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 6/6] Input: mc13783-pwrbutton: add OF support
2025-08-17 10:27 ` [PATCH 6/6] Input: mc13783-pwrbutton: add OF support Alexander Kurz
@ 2025-08-17 11:24 ` Krzysztof Kozlowski
2025-08-17 16:41 ` kernel test robot
2025-08-18 1:03 ` Dmitry Torokhov
2 siblings, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2025-08-17 11:24 UTC (permalink / raw)
To: Alexander Kurz, Lee Jones, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Dmitry Torokhov, Dzmitry Sankouski,
Dr. David Alan Gilbert, Heiko Stuebner, Uwe Kleine-König,
devicetree, linux-input
Cc: linux-kernel
On 17/08/2025 12:27, Alexander Kurz wrote:
> Add OF support for the mc13783-pwrbutton so that it can be used with
> modern DT based systems.
>
> Signed-off-by: Alexander Kurz <akurz@blala.de>
> ---
> drivers/input/misc/mc13783-pwrbutton.c | 78 +++++++++++++++++++++++++-
> 1 file changed, 75 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
> index 49bc5d25f098..11a97ce070a5 100644
> --- a/drivers/input/misc/mc13783-pwrbutton.c
> +++ b/drivers/input/misc/mc13783-pwrbutton.c
> @@ -29,6 +29,7 @@
> #include <linux/mfd/mc13783.h>
> #include <linux/sched.h>
> #include <linux/slab.h>
> +#include <linux/of.h>
>
> struct mc13783_pwrb {
> struct input_dev *pwr;
> @@ -105,8 +106,75 @@ static irqreturn_t button3_irq(int irq, void *_priv)
> return button_irq(MC13783_IRQ_ONOFD3, _priv);
> }
>
> +#ifdef CONFIG_OF
> +static inline struct mc13xxx_buttons_platform_data __init *mc13xxx_pwrbutton_probe_dt(
> + struct platform_device *pdev)
> +{
> + struct mc13xxx_buttons_platform_data *pdata;
> + struct device_node *parent, *child;
> + struct device *dev = &pdev->dev;
> + enum mc13xxx_chip_type chip = platform_get_device_id(pdev)->driver_data;
> + int ret = -ENODATA;
> +
No blank lines between declarations.
> + /* ONOFD3 is only supported for MC13783. */
> + int max_idx = chip != MC13XXX_CHIP_TYPE_MC13783 ? 2 : 1;
Ternary operator is hardly readable. Just store the number of buttons in
device match data
> +
> + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
> + if (!pdata)
> + return ERR_PTR(-ENOMEM);
> +
> + parent = of_get_child_by_name(dev->parent->of_node, "pwrbuttons");
Node name: buttons or keys instead
> + if (!parent)
> + goto out_node_put;
> +
> + for_each_child_of_node(parent, child) {
> + u32 idx;
> + u8 dbnc = MC13783_BUTTON_DBNC_30MS;
> +
> + if (of_property_read_u32(child, "reg", &idx))
> + continue;
> +
> + if (idx > max_idx) {
> + dev_warn(dev, "reg out of range\n");
> + continue;
> + }
> +
> + of_property_read_u8(child, "debounce-delay-value", &dbnc);
> + if (dbnc > MC13783_BUTTON_DBNC_750MS) {
> + dev_warn(dev, "debounce-delay-value out of range\n");
> + continue;
> + }
> +
> + if (of_property_read_u32(child, "linux,code", &pdata->b_on_key[idx]))
> + continue;
> +
> + if (of_property_read_bool(child, "active-low"))
> + pdata->b_on_flags[idx] |= MC13783_BUTTON_POL_INVERT;
> +
> + if (of_property_read_bool(child, "enable-reset"))
> + pdata->b_on_flags[idx] |= MC13783_BUTTON_RESET_EN;
> +
> + pdata->b_on_flags[idx] |= MC13783_BUTTON_ENABLE | dbnc;
> + }
> +
> + ret = 0;
> +
> +out_node_put:
> + of_node_put(parent);
> +
> + return ret ? ERR_PTR(ret) : pdata;
> +}
> +#else
> +static inline struct mc13xxx_buttons_platform_data __init *mc13xxx_pwrbutton_probe_dt(
Section mismatch. Build your code with proper DEBUG options for section
mismatch check.
> + struct platform_device *pdev)
> +{
> + return ERR_PTR(-ENODEV);
> +}
> +#endif
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 6/6] Input: mc13783-pwrbutton: add OF support
2025-08-17 10:27 ` [PATCH 6/6] Input: mc13783-pwrbutton: add OF support Alexander Kurz
2025-08-17 11:24 ` Krzysztof Kozlowski
@ 2025-08-17 16:41 ` kernel test robot
2025-08-18 1:03 ` Dmitry Torokhov
2 siblings, 0 replies; 14+ messages in thread
From: kernel test robot @ 2025-08-17 16:41 UTC (permalink / raw)
To: Alexander Kurz, Lee Jones, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Dmitry Torokhov, Dzmitry Sankouski,
Dr. David Alan Gilbert, Heiko Stuebner, Uwe Kleine-König,
devicetree, linux-input
Cc: oe-kbuild-all, linux-kernel, Alexander Kurz
Hi Alexander,
kernel test robot noticed the following build warnings:
[auto build test WARNING on dtor-input/next]
[also build test WARNING on dtor-input/for-linus lee-mfd/for-mfd-next lee-mfd/for-mfd-fixes robh/for-next linus/master v6.17-rc1 next-20250815]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Alexander-Kurz/Input-mc13783-pwrbutton-fix-irq-mixup/20250817-182649
base: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
patch link: https://lore.kernel.org/r/20250817102751.29709-7-akurz%40blala.de
patch subject: [PATCH 6/6] Input: mc13783-pwrbutton: add OF support
config: arm-randconfig-001-20250817 (https://download.01.org/0day-ci/archive/20250818/202508180010.aF8jhqrQ-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 14.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250818/202508180010.aF8jhqrQ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508180010.aF8jhqrQ-lkp@intel.com/
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux: section mismatch in reference: mc13783_pwrbutton_probe+0x243 (section: .text.mc13783_pwrbutton_probe) -> mc13xxx_pwrbutton_probe_dt (section: .init.text)
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 6/6] Input: mc13783-pwrbutton: add OF support
2025-08-17 10:27 ` [PATCH 6/6] Input: mc13783-pwrbutton: add OF support Alexander Kurz
2025-08-17 11:24 ` Krzysztof Kozlowski
2025-08-17 16:41 ` kernel test robot
@ 2025-08-18 1:03 ` Dmitry Torokhov
2 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2025-08-18 1:03 UTC (permalink / raw)
To: Alexander Kurz
Cc: Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Dzmitry Sankouski, Dr. David Alan Gilbert, Heiko Stuebner,
Uwe Kleine-König, devicetree, linux-input, linux-kernel
Hi Alexander,
On Sun, Aug 17, 2025 at 10:27:50AM +0000, Alexander Kurz wrote:
> Add OF support for the mc13783-pwrbutton so that it can be used with
> modern DT based systems.
>
> Signed-off-by: Alexander Kurz <akurz@blala.de>
> ---
> drivers/input/misc/mc13783-pwrbutton.c | 78 +++++++++++++++++++++++++-
> 1 file changed, 75 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
> index 49bc5d25f098..11a97ce070a5 100644
> --- a/drivers/input/misc/mc13783-pwrbutton.c
> +++ b/drivers/input/misc/mc13783-pwrbutton.c
> @@ -29,6 +29,7 @@
> #include <linux/mfd/mc13783.h>
> #include <linux/sched.h>
> #include <linux/slab.h>
> +#include <linux/of.h>
Please use generic device properties API (device_property_read_XX()).
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 14+ messages in thread