[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250914193723.10544-8-akurz@blala.de>
Date: Sun, 14 Sep 2025 19:37:22 +0000
From: Alexander Kurz <akurz@...la.de>
To: Lee Jones <lee@...nel.org>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Dmitry Torokhov <dmitry.torokhov@...il.com>,
Dzmitry Sankouski <dsankouski@...il.com>,
"Dr. David Alan Gilbert" <linux@...blig.org>,
Heiko Stuebner <heiko@...ech.de>,
Uwe Kleine-König <u.kleine-koenig@...libre.com>,
devicetree@...r.kernel.org, linux-input@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Alexander Kurz <akurz@...la.de>
Subject: [PATCH v4 7/8] Input: mc13783-pwrbutton: enable other mc13xxx PMIC
All three mc13xxx types feature two common power buttons referred in
the datasheets as ONOFD[12] (mc13783) and PWRON[12] (mc13892/mc34708).
A third button is available on the mc13783 and mc13892 models, which
however uses distinct interrupt register bits.
Add support for mc13892/mc34708 to support all available power buttons
in the mc13xxx series.
Signed-off-by: Alexander Kurz <akurz@...la.de>
---
drivers/input/misc/Kconfig | 4 +-
drivers/input/misc/mc13783-pwrbutton.c | 131 +++++++++++--------------
drivers/mfd/mc13xxx-core.c | 22 ++++-
include/linux/mfd/mc13783.h | 4 +-
include/linux/mfd/mc13892.h | 1 +
include/linux/mfd/mc13xxx.h | 2 +
6 files changed, 84 insertions(+), 80 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 2ee115d77b1c..08618c59197f 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -30,9 +30,16 @@
#include <linux/sched.h>
#include <linux/slab.h>
+struct mc13xxx_button_devtype {
+ int button_id_max;
+ const char *irq_name[3];
+ int irq_sense_reg[3];
+};
+
struct mc13783_pwrb {
struct input_dev *pwr;
struct mc13xxx *mc13783;
+ const struct mc13xxx_button_devtype *devtype;
int flags;
unsigned short keymap[3];
int irq[3];
@@ -43,9 +50,6 @@ struct mc13783_pwrb {
#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)
-#define MC13783_IRQSENSE1_ONOFD3S (1 << 5)
#define MC13783_REG_POWER_CONTROL_2 15
#define MC13783_POWER_CONTROL_2_ON1BDBNC 4
@@ -63,17 +67,17 @@ static irqreturn_t button_irq(int irq, void *_priv)
mc13xxx_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
if (irq == priv->irq[0]) {
- val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
+ val = val & (1 << priv->devtype->irq_sense_reg[0]) ? 1 : 0;
if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
val ^= 1;
input_report_key(priv->pwr, priv->keymap[0], val);
} else if (irq == priv->irq[1]) {
- val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
+ val = val & (1 << priv->devtype->irq_sense_reg[1]) ? 1 : 0;
if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
val ^= 1;
input_report_key(priv->pwr, priv->keymap[1], val);
- } else if (irq == priv->irq[2]) {
- val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
+ } else if (irq == priv->irq[2] && priv->devtype->button_id_max >= 2) {
+ val = val & (1 << priv->devtype->irq_sense_reg[2]) ? 1 : 0;
if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
val ^= 1;
input_report_key(priv->pwr, priv->keymap[2], val);
@@ -88,6 +92,8 @@ 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);
+ struct mc13xxx_button_devtype *devtype =
+ (struct mc13xxx_button_devtype *)pdev->id_entry->driver_data;
struct input_dev *pwr;
struct mc13783_pwrb *priv;
int err = 0;
@@ -108,54 +114,36 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
if (!priv)
return -ENOMEM;
+ if (devtype->button_id_max < 2 && pdata->b_on_flags[2] & 0x3) {
+ dev_err(&pdev->dev, "button not supported\n");
+ return -ENODEV;
+ }
+
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;
+ priv->devtype = devtype;
mc13xxx_lock(mc13783);
- 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);
+ for (int i = 0; i < devtype->button_id_max; i++) {
+ if ((pdata->b_on_flags[i] & MC13783_BUTTON_ENABLE) == 0)
+ continue;
- if (pdata->b_on_flags[0] & MC13783_BUTTON_POL_INVERT)
- priv->flags |= MC13783_PWRB_B1_POL_INVERT;
+ priv->keymap[i] = pdata->b_on_key[i];
+ if (pdata->b_on_key[i] != KEY_RESERVED)
+ __set_bit(pdata->b_on_key[i], pwr->keybit);
- if (pdata->b_on_flags[0] & MC13783_BUTTON_RESET_EN)
- reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
+ if (pdata->b_on_flags[i] & MC13783_BUTTON_POL_INVERT)
+ priv->flags |= (MC13783_PWRB_B1_POL_INVERT << i);
- irq = platform_get_irq_byname(pdev, "b1on");
+ if (pdata->b_on_flags[i] & MC13783_BUTTON_RESET_EN)
+ reg |= (MC13783_POWER_CONTROL_2_ON1BRSTEN << i);
- if (irq < 0) {
- dev_dbg(&pdev->dev, "Can't request irq\n");
- goto free_mc13xxx_lock;
- }
-
- err = devm_request_any_context_irq(&pdev->dev, irq, button_irq,
- IRQF_ONESHOT, "b1on",
- priv);
- if (err < 0)
- goto free_mc13xxx_lock;
-
- priv->irq[0] = irq;
- }
-
- 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->b_on_flags[1] & MC13783_BUTTON_POL_INVERT)
- priv->flags |= MC13783_PWRB_B2_POL_INVERT;
-
- if (pdata->b_on_flags[1] & MC13783_BUTTON_RESET_EN)
- reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
-
- irq = platform_get_irq_byname(pdev, "b2on");
+ irq = platform_get_irq_byname(pdev, devtype->irq_name[i]);
if (irq < 0) {
dev_dbg(&pdev->dev, "Can't request irq\n");
@@ -163,39 +151,12 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
}
err = devm_request_any_context_irq(&pdev->dev, irq, button_irq,
- IRQF_ONESHOT, "b2on",
- priv);
+ IRQF_ONESHOT, devtype->irq_name[i],
+ priv);
if (err < 0)
goto free_mc13xxx_lock;
- priv->irq[1] = irq;
- }
-
- if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE) {
- priv->keymap[2] = pdata->b_on_key[2];
- if (pdata->b_on_key[2] != KEY_RESERVED)
- __set_bit(pdata->b_on_key[2], pwr->keybit);
-
- if (pdata->b_on_flags[2] & MC13783_BUTTON_POL_INVERT)
- priv->flags |= MC13783_PWRB_B3_POL_INVERT;
-
- if (pdata->b_on_flags[2] & MC13783_BUTTON_RESET_EN)
- reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
-
- irq = platform_get_irq_byname(pdev, "b3on");
-
- if (irq < 0) {
- dev_dbg(&pdev->dev, "Can't request irq: %d\n", err);
- goto free_mc13xxx_lock;
- }
-
- err = devm_request_any_context_irq(&pdev->dev, irq, button_irq,
- IRQF_ONESHOT, "b3on",
- priv);
- if (err < 0)
- goto free_mc13xxx_lock;
-
- priv->irq[2] = irq;
+ priv->irq[i] = irq;
}
mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
@@ -226,7 +187,33 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
return err;
}
+static const struct mc13xxx_button_devtype mc13783_button_devtype = {
+ .button_id_max = 2,
+ .irq_name = { "b1on", "b2on", "b3on" },
+ .irq_sense_reg = { 3, 4, 5 },
+};
+
+static const struct mc13xxx_button_devtype mc13892_button_devtype = {
+ .button_id_max = 2,
+ .irq_name = { "b1on", "b2on", "b3on" },
+ .irq_sense_reg = { 3, 4, 2 },
+};
+
+static const struct mc13xxx_button_devtype mc34708_button_devtype = {
+ .button_id_max = 1,
+ .irq_name = { "b1on", "b2on" },
+ .irq_sense_reg = { 3, 4 },
+};
+
+static const struct platform_device_id mc13xxx_pwrbutton_idtable[] = {
+ { "mc13783-pwrbutton", (kernel_ulong_t)&mc13783_button_devtype },
+ { "mc13892-pwrbutton", (kernel_ulong_t)&mc13892_button_devtype },
+ { "mc34708-pwrbutton", (kernel_ulong_t)&mc34708_button_devtype },
+ { /* sentinel */ }
+};
+
static struct platform_driver mc13783_pwrbutton_driver = {
+ .id_table = mc13xxx_pwrbutton_idtable,
.probe = mc13783_pwrbutton_probe,
.driver = {
.name = "mc13783-pwrbutton",
diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index 0791d9b4dec3..a620edab432e 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -14,6 +14,7 @@
#include <linux/platform_device.h>
#include <linux/mfd/core.h>
#include <linux/mfd/mc13783.h>
+#include <linux/mfd/mc13892.h>
#include "mc13xxx.h"
@@ -48,11 +49,22 @@
#define MC13XXX_ADC2 45
static const struct resource mc13783_button_resources[] = {
- DEFINE_RES_IRQ_NAMED(MC13783_IRQ_ONOFD1, "b1on"),
- DEFINE_RES_IRQ_NAMED(MC13783_IRQ_ONOFD2, "b2on"),
+ DEFINE_RES_IRQ_NAMED(MC13XXX_IRQ_PWRON1, "b1on"),
+ DEFINE_RES_IRQ_NAMED(MC13XXX_IRQ_PWRON2, "b2on"),
DEFINE_RES_IRQ_NAMED(MC13783_IRQ_ONOFD3, "b3on"),
};
+static const struct resource mc13892_button_resources[] = {
+ DEFINE_RES_IRQ_NAMED(MC13XXX_IRQ_PWRON1, "b1on"),
+ DEFINE_RES_IRQ_NAMED(MC13XXX_IRQ_PWRON2, "b2on"),
+ DEFINE_RES_IRQ_NAMED(MC13892_IRQ_PWRON3, "b3on"),
+};
+
+static const struct resource mc34708_button_resources[] = {
+ DEFINE_RES_IRQ_NAMED(MC13XXX_IRQ_PWRON1, "b1on"),
+ DEFINE_RES_IRQ_NAMED(MC13XXX_IRQ_PWRON2, "b2on"),
+};
+
void mc13xxx_lock(struct mc13xxx *mc13xxx)
{
if (!mutex_trylock(&mc13xxx->lock)) {
@@ -216,14 +228,16 @@ EXPORT_SYMBOL_GPL(mc13xxx_variant_mc13783);
struct mc13xxx_variant mc13xxx_variant_mc13892 = {
.name = "mc13892",
- .button_resources_size = 0,
+ .button_resources = mc13892_button_resources,
+ .button_resources_size = ARRAY_SIZE(mc13892_button_resources),
.print_revision = mc13xxx_print_revision,
};
EXPORT_SYMBOL_GPL(mc13xxx_variant_mc13892);
struct mc13xxx_variant mc13xxx_variant_mc34708 = {
.name = "mc34708",
- .button_resources_size = 0,
+ .button_resources = mc34708_button_resources,
+ .button_resources_size = ARRAY_SIZE(mc34708_button_resources),
.print_revision = mc34708_print_revision,
};
EXPORT_SYMBOL_GPL(mc13xxx_variant_mc34708);
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/mc13892.h b/include/linux/mfd/mc13892.h
index 880cd949d12a..567d527825df 100644
--- a/include/linux/mfd/mc13892.h
+++ b/include/linux/mfd/mc13892.h
@@ -33,4 +33,5 @@
#define MC13892_PWGT2SPI 22
#define MC13892_VCOINCELL 23
+#define MC13892_IRQ_PWRON3 26
#endif
diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
index 4437ab80fcf8..71c7d3614d4c 100644
--- a/include/linux/mfd/mc13xxx.h
+++ b/include/linux/mfd/mc13xxx.h
@@ -61,6 +61,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
--
2.39.5
Powered by blists - more mailing lists