From nobody Thu Oct 2 18:08:29 2025 Received: from vs81.iboxed.net (vs10.datenmanufaktur-hosting.net [213.160.73.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9E252E2DC4; Sun, 14 Sep 2025 19:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.160.73.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757878559; cv=none; b=RBxEF0XWvNEyly6Nq8pS61nTVwOuUld1DlKb7kNIMEAQqvDrYF6eZ6FKnwGRF+v8wOr6t1hIberDM1QaDJ2J+JeO79gBtpH5PV2+q06q0bteSuu6HJDqtjTtyx3+brZFiK0X7FKp00tDlkuoeBbUr08NnAc6Iul8wWEuoEpfxek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757878559; c=relaxed/simple; bh=Xm7JSBgKfHMkXzX8LVvdjw7HSVFlIMZc13DONmV0JJs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AddvTrVhJHAGLFZXBWGEAw4QckziR38O2RvpFLmg580rimQAn3i2OEznbHY+LCldMsmGI61le5L9b8lSG9OgCqls4v7fQ+eOeRLwgL1C/8NmHBuGMN/Va5xEdBkk2lYHWURJ65FZErT9oAqayX0/5oYBNVcsR4QYXy8eeg7m7hA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blala.de; spf=pass smtp.mailfrom=blala.de; arc=none smtp.client-ip=213.160.73.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blala.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blala.de Received: from blala.de (localhost [127.0.0.1]) by vs81.iboxed.net (8.15.2/8.15.2/Debian-14~deb10u1) with ESMTP id 58EJbQkO010643; Sun, 14 Sep 2025 19:37:26 GMT Received: (from akurz@localhost) by blala.de (8.15.2/8.15.2/Submit) id 58EJbQ8V010638; Sun, 14 Sep 2025 19:37:26 GMT From: Alexander Kurz To: Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Dmitry Torokhov , Dzmitry Sankouski , "Dr. David Alan Gilbert" , Heiko Stuebner , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , devicetree@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexander Kurz Subject: [PATCH v4 7/8] Input: mc13783-pwrbutton: enable other mc13xxx PMIC Date: Sun, 14 Sep 2025 19:37:22 +0000 Message-Id: <20250914193723.10544-8-akurz@blala.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250914193723.10544-1-akurz@blala.de> References: <20250914193723.10544-1-akurz@blala.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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. =20 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/mc= 13783-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 #include =20 +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) =20 #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) =20 #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); =20 if (irq =3D=3D priv->irq[0]) { - val =3D val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0; + val =3D val & (1 << priv->devtype->irq_sense_reg[0]) ? 1 : 0; if (priv->flags & MC13783_PWRB_B1_POL_INVERT) val ^=3D 1; input_report_key(priv->pwr, priv->keymap[0], val); } else if (irq =3D=3D priv->irq[1]) { - val =3D val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0; + val =3D val & (1 << priv->devtype->irq_sense_reg[1]) ? 1 : 0; if (priv->flags & MC13783_PWRB_B2_POL_INVERT) val ^=3D 1; input_report_key(priv->pwr, priv->keymap[1], val); - } else if (irq =3D=3D priv->irq[2]) { - val =3D val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0; + } else if (irq =3D=3D priv->irq[2] && priv->devtype->button_id_max >=3D 2= ) { + val =3D val & (1 << priv->devtype->irq_sense_reg[2]) ? 1 : 0; if (priv->flags & MC13783_PWRB_B3_POL_INVERT) val ^=3D 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 =3D dev_get_drvdata(pdev->dev.parent); + struct mc13xxx_button_devtype *devtype =3D + (struct mc13xxx_button_devtype *)pdev->id_entry->driver_data; struct input_dev *pwr; struct mc13783_pwrb *priv; int err =3D 0; @@ -108,54 +114,36 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) if (!priv) return -ENOMEM; =20 + if (devtype->button_id_max < 2 && pdata->b_on_flags[2] & 0x3) { + dev_err(&pdev->dev, "button not supported\n"); + return -ENODEV; + } + reg |=3D (pdata->b_on_flags[0] & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC; reg |=3D (pdata->b_on_flags[1] & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC; reg |=3D (pdata->b_on_flags[2] & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC; =20 priv->pwr =3D pwr; priv->mc13783 =3D mc13783; + priv->devtype =3D devtype; =20 mc13xxx_lock(mc13783); =20 - if (pdata->b_on_flags[0] & MC13783_BUTTON_ENABLE) { - priv->keymap[0] =3D pdata->b_on_key[0]; - if (pdata->b_on_key[0] !=3D KEY_RESERVED) - __set_bit(pdata->b_on_key[0], pwr->keybit); + for (int i =3D 0; i < devtype->button_id_max; i++) { + if ((pdata->b_on_flags[i] & MC13783_BUTTON_ENABLE) =3D=3D 0) + continue; =20 - if (pdata->b_on_flags[0] & MC13783_BUTTON_POL_INVERT) - priv->flags |=3D MC13783_PWRB_B1_POL_INVERT; + priv->keymap[i] =3D pdata->b_on_key[i]; + if (pdata->b_on_key[i] !=3D KEY_RESERVED) + __set_bit(pdata->b_on_key[i], pwr->keybit); =20 - if (pdata->b_on_flags[0] & MC13783_BUTTON_RESET_EN) - reg |=3D MC13783_POWER_CONTROL_2_ON1BRSTEN; + if (pdata->b_on_flags[i] & MC13783_BUTTON_POL_INVERT) + priv->flags |=3D (MC13783_PWRB_B1_POL_INVERT << i); =20 - irq =3D platform_get_irq_byname(pdev, "b1on"); + if (pdata->b_on_flags[i] & MC13783_BUTTON_RESET_EN) + reg |=3D (MC13783_POWER_CONTROL_2_ON1BRSTEN << i); =20 - if (irq < 0) { - dev_dbg(&pdev->dev, "Can't request irq\n"); - goto free_mc13xxx_lock; - } - - err =3D devm_request_any_context_irq(&pdev->dev, irq, button_irq, - IRQF_ONESHOT, "b1on", - priv); - if (err < 0) - goto free_mc13xxx_lock; - - priv->irq[0] =3D irq; - } - - if (pdata->b_on_flags[1] & MC13783_BUTTON_ENABLE) { - priv->keymap[1] =3D pdata->b_on_key[1]; - if (pdata->b_on_key[1] !=3D KEY_RESERVED) - __set_bit(pdata->b_on_key[1], pwr->keybit); - - if (pdata->b_on_flags[1] & MC13783_BUTTON_POL_INVERT) - priv->flags |=3D MC13783_PWRB_B2_POL_INVERT; - - if (pdata->b_on_flags[1] & MC13783_BUTTON_RESET_EN) - reg |=3D MC13783_POWER_CONTROL_2_ON2BRSTEN; - - irq =3D platform_get_irq_byname(pdev, "b2on"); + irq =3D platform_get_irq_byname(pdev, devtype->irq_name[i]); =20 if (irq < 0) { dev_dbg(&pdev->dev, "Can't request irq\n"); @@ -163,39 +151,12 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) } =20 err =3D 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; =20 - priv->irq[1] =3D irq; - } - - if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE) { - priv->keymap[2] =3D pdata->b_on_key[2]; - if (pdata->b_on_key[2] !=3D KEY_RESERVED) - __set_bit(pdata->b_on_key[2], pwr->keybit); - - if (pdata->b_on_flags[2] & MC13783_BUTTON_POL_INVERT) - priv->flags |=3D MC13783_PWRB_B3_POL_INVERT; - - if (pdata->b_on_flags[2] & MC13783_BUTTON_RESET_EN) - reg |=3D MC13783_POWER_CONTROL_2_ON3BRSTEN; - - irq =3D 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 =3D devm_request_any_context_irq(&pdev->dev, irq, button_irq, - IRQF_ONESHOT, "b3on", - priv); - if (err < 0) - goto free_mc13xxx_lock; - - priv->irq[2] =3D irq; + priv->irq[i] =3D irq; } =20 mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg); @@ -226,7 +187,33 @@ static int mc13783_pwrbutton_probe(struct platform_dev= ice *pdev) return err; } =20 +static const struct mc13xxx_button_devtype mc13783_button_devtype =3D { + .button_id_max =3D 2, + .irq_name =3D { "b1on", "b2on", "b3on" }, + .irq_sense_reg =3D { 3, 4, 5 }, +}; + +static const struct mc13xxx_button_devtype mc13892_button_devtype =3D { + .button_id_max =3D 2, + .irq_name =3D { "b1on", "b2on", "b3on" }, + .irq_sense_reg =3D { 3, 4, 2 }, +}; + +static const struct mc13xxx_button_devtype mc34708_button_devtype =3D { + .button_id_max =3D 1, + .irq_name =3D { "b1on", "b2on" }, + .irq_sense_reg =3D { 3, 4 }, +}; + +static const struct platform_device_id mc13xxx_pwrbutton_idtable[] =3D { + { "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 =3D { + .id_table =3D mc13xxx_pwrbutton_idtable, .probe =3D mc13783_pwrbutton_probe, .driver =3D { .name =3D "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 #include #include +#include =20 #include "mc13xxx.h" =20 @@ -48,11 +49,22 @@ #define MC13XXX_ADC2 45 =20 static const struct resource mc13783_button_resources[] =3D { - 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"), }; =20 +static const struct resource mc13892_button_resources[] =3D { + 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[] =3D { + 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); =20 struct mc13xxx_variant mc13xxx_variant_mc13892 =3D { .name =3D "mc13892", - .button_resources_size =3D 0, + .button_resources =3D mc13892_button_resources, + .button_resources_size =3D ARRAY_SIZE(mc13892_button_resources), .print_revision =3D mc13xxx_print_revision, }; EXPORT_SYMBOL_GPL(mc13xxx_variant_mc13892); =20 struct mc13xxx_variant mc13xxx_variant_mc34708 =3D { .name =3D "mc34708", - .button_resources_size =3D 0, + .button_resources =3D mc34708_button_resources, + .button_resources_size =3D ARRAY_SIZE(mc34708_button_resources), .print_revision =3D 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 =20 +#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 --=20 2.39.5