From nobody Sun Feb 8 09:12:49 2026 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 5AE3F19DF62; Wed, 8 Oct 2025 06:45:29 +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=1759905933; cv=none; b=cZclw+elGCozFEG5yEhKtR+l2wgLuVRnSKomHxgBxbF+KPkTHnOuS+SqNA5tSid7hZ07M5W1PH9OwVaJGFHj8gCW1/x4PjUQlbdzBg/YHhypLYgDn7DRFotnCtE0Kvjx+Xv7WhGsBPPlImbcV/+g0nUzorXQ8O3IpnvShnhTJxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759905933; c=relaxed/simple; bh=G0xQgQyrwSJHVmBE1CSnLN/FrJeKs1BASiMsyj5D/lo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eH97TFbVjp7lkwpLUwUwazZ5CwzbHWEhvq9KIZnBdosaplE9L+546yox0QTwgob6bPrTuiX5ey/XU6n0AA6yT4LNqbT4CYYgdgkHLyP6U7Z/le3I+H7pn3tgPu3UHGcL3hCLSQOE1bUtovtQjTI+HCgUtPlQqVMH76ZEHJ1hX7k= 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 5986i3Vv013914; Wed, 8 Oct 2025 06:44:03 GMT Received: (from akurz@localhost) by blala.de (8.15.2/8.15.2/Submit) id 5986i3b3013909; Wed, 8 Oct 2025 06:44:03 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 v5 1/5] Input: mc13783-pwrbutton: use managed resources Date: Wed, 8 Oct 2025 06:43:57 +0000 Message-Id: <20251008064401.13863-2-akurz@blala.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20251008064401.13863-1-akurz@blala.de> References: <20251008064401.13863-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" Use devres functionality to simplify resource freeing, dev.parent will be set by devm_input_allocate_device(). Signed-off-by: Alexander Kurz --- 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/mc= 13783-pwrbutton.c index b83d762ae2e9..82434ea9cca5 100644 --- a/drivers/input/misc/mc13783-pwrbutton.c +++ b/drivers/input/misc/mc13783-pwrbutton.c @@ -21,6 +21,7 @@ =20 #include #include +#include #include #include #include @@ -102,18 +103,13 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) return -ENODEV; } =20 - pwr =3D input_allocate_device(); - if (!pwr) { - dev_dbg(&pdev->dev, "Can't allocate power button\n"); + pwr =3D devm_input_allocate_device(&pdev->dev); + if (!pwr) return -ENOMEM; - } =20 - priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - err =3D -ENOMEM; - dev_dbg(&pdev->dev, "Can't allocate power button\n"); - goto free_input_dev; - } + priv =3D devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; =20 reg |=3D (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC; reg |=3D (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC; @@ -139,7 +135,7 @@ static int mc13783_pwrbutton_probe(struct platform_devi= ce *pdev) button_irq, "b1on", priv); if (err) { dev_dbg(&pdev->dev, "Can't request irq\n"); - goto free_priv; + goto free_mc13xxx_lock; } } =20 @@ -187,7 +183,6 @@ static int mc13783_pwrbutton_probe(struct platform_devi= ce *pdev) =20 pwr->name =3D "mc13783_pwrbutton"; pwr->phys =3D "mc13783_pwrbutton/input0"; - pwr->dev.parent =3D &pdev->dev; =20 pwr->keycode =3D priv->keymap; pwr->keycodemax =3D ARRAY_SIZE(priv->keymap); @@ -218,12 +213,8 @@ static int mc13783_pwrbutton_probe(struct platform_dev= ice *pdev) if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv); =20 -free_priv: +free_mc13xxx_lock: mc13xxx_unlock(mc13783); - kfree(priv); - -free_input_dev: - input_free_device(pwr); =20 return err; } @@ -245,9 +236,6 @@ static void mc13783_pwrbutton_remove(struct platform_de= vice *pdev) mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv); =20 mc13xxx_unlock(priv->mc13783); - - input_unregister_device(priv->pwr); - kfree(priv); } =20 static struct platform_driver mc13783_pwrbutton_driver =3D { --=20 2.39.5 From nobody Sun Feb 8 09:12:49 2026 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 51B0B2E92B7; Wed, 8 Oct 2025 06:45:41 +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=1759905943; cv=none; b=AfQp0iH2vLQyCssRPiEl41FImxbNKLd64A0kmqV7Yrsyk+YkxLXzACARL8swkeRGpQXFWkYDG/IHCpmHKlGneTvaNdsn/y33m0q2e/0PG03yDnCJ5I493td3W/quJ/95X4Q5cwkDqBKenqqBH+ycq3EDW4WtlcKvBFE6tbfrEqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759905943; c=relaxed/simple; bh=YUcyedh+Ntez3IQlxuY7679Cka78QeSfCB23BV2KlBQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nRg7FeTcfZgKQvVaH11QC2wx+/8BHwu+WPtU8AToYa6XhugDLSgBwOExHrNNI5ycbiYLUTq/5mFjbWQyhOmVnlk1WduFexSRxUFA5vf+z4Lbnnjt8u37ebEkVa1BqBLEba1ysIUXfsJb85qFHp9DodCw8KS6Pcc3IyePlHotlOQ= 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 5986i3JJ013922; Wed, 8 Oct 2025 06:44:03 GMT Received: (from akurz@localhost) by blala.de (8.15.2/8.15.2/Submit) id 5986i3ih013917; Wed, 8 Oct 2025 06:44:03 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 v5 2/5] Input: mc13783-pwrbutton: fix irq mixup and use resources Date: Wed, 8 Oct 2025 06:43:58 +0000 Message-Id: <20251008064401.13863-3-akurz@blala.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20251008064401.13863-1-akurz@blala.de> References: <20251008064401.13863-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" 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() got get called with virtual irq instead of chip-internal irq. Make use of mfd_cell resources to pass interrupts from mfd so that platform_get_irq_byname() can be used in mc13783-pwrbutton. The amount of required interrupt related cleanup can be reduced this way. Note, that mc13783-pwrbutton is still considered to support only the model mc13783. Signed-off-by: Alexander Kurz --- drivers/input/misc/mc13783-pwrbutton.c | 103 +++++++++++-------------- drivers/mfd/mc13xxx-core.c | 39 ++++++++-- drivers/mfd/mc13xxx.h | 2 + 3 files changed, 79 insertions(+), 65 deletions(-) diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc= 13783-pwrbutton.c index 82434ea9cca5..20f68aab6edf 100644 --- a/drivers/input/misc/mc13783-pwrbutton.c +++ b/drivers/input/misc/mc13783-pwrbutton.c @@ -33,13 +33,15 @@ 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]; + int irq[3]; }; =20 +#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) @@ -60,27 +62,21 @@ static irqreturn_t button_irq(int irq, void *_priv) =20 mc13xxx_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val); =20 - switch (irq) { - case MC13783_IRQ_ONOFD1: + if (irq =3D=3D priv->irq[0]) { val =3D val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0; if (priv->flags & MC13783_PWRB_B1_POL_INVERT) val ^=3D 1; input_report_key(priv->pwr, priv->keymap[0], val); - break; - - case MC13783_IRQ_ONOFD2: + } else if (irq =3D=3D priv->irq[1]) { val =3D val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0; if (priv->flags & MC13783_PWRB_B2_POL_INVERT) val ^=3D 1; input_report_key(priv->pwr, priv->keymap[1], val); - break; - - case MC13783_IRQ_ONOFD3: + } else if (irq =3D=3D priv->irq[2]) { val =3D val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0; if (priv->flags & MC13783_PWRB_B3_POL_INVERT) val ^=3D 1; input_report_key(priv->pwr, priv->keymap[2], val); - break; } =20 input_sync(priv->pwr); @@ -96,6 +92,7 @@ static int mc13783_pwrbutton_probe(struct platform_device= *pdev) struct mc13783_pwrb *priv; int err =3D 0; int reg =3D 0; + int irq =3D 0; =20 pdata =3D dev_get_platdata(&pdev->dev); if (!pdata) { @@ -131,12 +128,20 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN) reg |=3D MC13783_POWER_CONTROL_2_ON1BRSTEN; =20 - err =3D mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1, - button_irq, "b1on", priv); - if (err) { + irq =3D platform_get_irq_byname(pdev, "b1on"); + + 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; } =20 if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) { @@ -150,12 +155,20 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN) reg |=3D MC13783_POWER_CONTROL_2_ON2BRSTEN; =20 - err =3D mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2, - button_irq, "b2on", priv); - if (err) { + irq =3D platform_get_irq_byname(pdev, "b2on"); + + if (irq < 0) { dev_dbg(&pdev->dev, "Can't request irq\n"); - goto free_irq_b1; + goto free_mc13xxx_lock; } + + err =3D devm_request_any_context_irq(&pdev->dev, irq, button_irq, + IRQF_ONESHOT, "b2on", + priv); + if (err < 0) + goto free_mc13xxx_lock; + + priv->irq[1] =3D irq; } =20 if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) { @@ -169,12 +182,20 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN) reg |=3D MC13783_POWER_CONTROL_2_ON3BRSTEN; =20 - err =3D mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3, - button_irq, "b3on", priv); - if (err) { + irq =3D platform_get_irq_byname(pdev, "b3on"); + + if (irq < 0) { dev_dbg(&pdev->dev, "Can't request irq: %d\n", err); - goto free_irq_b2; + 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; } =20 mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg); @@ -192,55 +213,21 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) err =3D input_register_device(pwr); if (err) { dev_dbg(&pdev->dev, "Can't register power button: %d\n", err); - goto free_irq; + return err; } =20 platform_set_drvdata(pdev, priv); =20 return 0; =20 -free_irq: - mc13xxx_lock(mc13783); - - if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) - mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv); - -free_irq_b2: - if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) - mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv); - -free_irq_b1: - if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) - mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv); - free_mc13xxx_lock: mc13xxx_unlock(mc13783); =20 return err; } =20 -static void mc13783_pwrbutton_remove(struct platform_device *pdev) -{ - struct mc13783_pwrb *priv =3D platform_get_drvdata(pdev); - const struct mc13xxx_buttons_platform_data *pdata; - - pdata =3D dev_get_platdata(&pdev->dev); - - mc13xxx_lock(priv->mc13783); - - if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) - mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv); - if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) - mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv); - if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) - mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv); - - mc13xxx_unlock(priv->mc13783); -} - static struct platform_driver mc13783_pwrbutton_driver =3D { .probe =3D mc13783_pwrbutton_probe, - .remove =3D mc13783_pwrbutton_remove, .driver =3D { .name =3D "mc13783-pwrbutton", }, diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c index 920797b806ce..1756c8d47d5e 100644 --- a/drivers/mfd/mc13xxx-core.c +++ b/drivers/mfd/mc13xxx-core.c @@ -13,6 +13,7 @@ #include #include #include +#include =20 #include "mc13xxx.h" =20 @@ -46,6 +47,12 @@ =20 #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(MC13783_IRQ_ONOFD3, "b3on"), +}; + void mc13xxx_lock(struct mc13xxx *mc13xxx) { if (!mutex_trylock(&mc13xxx->lock)) { @@ -201,18 +208,22 @@ static void mc34708_print_revision(struct mc13xxx *mc= 13xxx, u32 revision) /* These are only exported for mc13xxx-i2c and mc13xxx-spi */ struct mc13xxx_variant mc13xxx_variant_mc13783 =3D { .name =3D "mc13783", + .button_resources =3D mc13783_button_resources, + .button_resources_size =3D ARRAY_SIZE(mc13783_button_resources), .print_revision =3D mc13xxx_print_revision, }; EXPORT_SYMBOL_GPL(mc13xxx_variant_mc13783); =20 struct mc13xxx_variant mc13xxx_variant_mc13892 =3D { .name =3D "mc13892", + .button_resources_size =3D 0, .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, .print_revision =3D mc34708_print_revision, }; EXPORT_SYMBOL_GPL(mc13xxx_variant_mc34708); @@ -362,15 +373,18 @@ int mc13xxx_adc_do_conversion(struct mc13xxx *mc13xxx= , unsigned int mode, } EXPORT_SYMBOL_GPL(mc13xxx_adc_do_conversion); =20 -static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, - const char *format, void *pdata, size_t pdata_size) +static int mc13xxx_add_subdevice_pdata_res(struct mc13xxx *mc13xxx, + const char *format, void *pdata, size_t pdata_size, + const struct resource *resources, int num_resources) { char buf[30]; const char *name =3D mc13xxx_get_chipname(mc13xxx); =20 struct mfd_cell cell =3D { - .platform_data =3D pdata, - .pdata_size =3D pdata_size, + .platform_data =3D pdata, + .pdata_size =3D pdata_size, + .resources =3D resources, + .num_resources =3D num_resources, }; =20 /* there is no asnprintf in the kernel :-( */ @@ -385,6 +399,12 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx = *mc13xxx, regmap_irq_get_domain(mc13xxx->irq_data)); } =20 +static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, + const char *format, void *pdata, size_t pdata_size) +{ + return mc13xxx_add_subdevice_pdata_res(mc13xxx, format, pdata, pdata_size= , NULL, 0); +} + static int mc13xxx_add_subdevice(struct mc13xxx *mc13xxx, const char *form= at) { return mc13xxx_add_subdevice_pdata(mc13xxx, format, NULL, 0); @@ -470,8 +490,10 @@ int mc13xxx_common_init(struct device *dev) &pdata->regulators, sizeof(pdata->regulators)); mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led", pdata->leds, sizeof(*pdata->leds)); - mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton", - pdata->buttons, sizeof(*pdata->buttons)); + mc13xxx_add_subdevice_pdata_res(mc13xxx, "%s-pwrbutton", + pdata->buttons, sizeof(*pdata->buttons), + mc13xxx->variant->button_resources, + mc13xxx->variant->button_resources_size); if (mc13xxx->flags & MC13XXX_USE_CODEC) mc13xxx_add_subdevice_pdata(mc13xxx, "%s-codec", pdata->codec, sizeof(*pdata->codec)); @@ -481,7 +503,10 @@ int mc13xxx_common_init(struct device *dev) } else { mc13xxx_add_subdevice(mc13xxx, "%s-regulator"); mc13xxx_add_subdevice(mc13xxx, "%s-led"); - mc13xxx_add_subdevice(mc13xxx, "%s-pwrbutton"); + mc13xxx_add_subdevice_pdata_res(mc13xxx, "%s-pwrbutton", + NULL, 0, + mc13xxx->variant->button_resources, + mc13xxx->variant->button_resources_size); if (mc13xxx->flags & MC13XXX_USE_CODEC) mc13xxx_add_subdevice(mc13xxx, "%s-codec"); if (mc13xxx->flags & MC13XXX_USE_TOUCHSCREEN) diff --git a/drivers/mfd/mc13xxx.h b/drivers/mfd/mc13xxx.h index bd5ba9a0e14f..b13ae652f4ec 100644 --- a/drivers/mfd/mc13xxx.h +++ b/drivers/mfd/mc13xxx.h @@ -18,6 +18,8 @@ struct mc13xxx; =20 struct mc13xxx_variant { const char *name; + const struct resource *button_resources; + int button_resources_size; void (*print_revision)(struct mc13xxx *mc13xxx, u32 revision); }; =20 --=20 2.39.5 From nobody Sun Feb 8 09:12:49 2026 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 265E22E92B7; Wed, 8 Oct 2025 06:45:35 +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=1759905938; cv=none; b=aqQzrkYvvg+Jw4AwYyBJgX9V/Sneh6qvRuo6m4sh0cXNtNCrmzrbqZOBTOhIknZ06MlbIZuPwznhyuSBvYU2CvSLx8m8P+i+JcgtIknPR6hzCgUxAshIQ3WQVj3/SDdDsJPL1YsWpoMevQLlX5/tLcdyPXAA2qNiZHoy7lUftZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759905938; c=relaxed/simple; bh=f3nk6RtA5IYDVa82v6LnaN3lzAk1OrTgcNHp4zY+tDk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GsuZ+vVMBSGf8I+Totq1en4+2Tuw1aTgpTH1ipnrlegLMhabPHzuBetYiv95MlnbIu8NJYczUE5eyEzF9IQL1H6Go0DIJVtD7ta3EdXlGUKDginHXyld718ZQvB2JXPYu3iQX1dS9I2v6ZQAP9Dfph+lo1qGggCEbPkbYIwvZuY= 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 5986i3Sv013930; Wed, 8 Oct 2025 06:44:03 GMT Received: (from akurz@localhost) by blala.de (8.15.2/8.15.2/Submit) id 5986i3gu013926; Wed, 8 Oct 2025 06:44:03 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 v5 3/5] Input: mc13783-pwrbutton: convert pdata members to array Date: Wed, 8 Oct 2025 06:43:59 +0000 Message-Id: <20251008064401.13863-4-akurz@blala.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20251008064401.13863-1-akurz@blala.de> References: <20251008064401.13863-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" As preparation for the extension of support for all three mc13xxx variants, convert the members of mc13xxx_buttons_platform_data to arrays to allow index access within the next commit. Signed-off-by: Alexander Kurz --- drivers/input/misc/mc13783-pwrbutton.c | 42 +++++++++++++------------- include/linux/mfd/mc13xxx.h | 8 ++--- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc= 13783-pwrbutton.c index 20f68aab6edf..2ee115d77b1c 100644 --- a/drivers/input/misc/mc13783-pwrbutton.c +++ b/drivers/input/misc/mc13783-pwrbutton.c @@ -108,24 +108,24 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) if (!priv) return -ENOMEM; =20 - reg |=3D (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC; - reg |=3D (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC; - reg |=3D (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC; + 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; =20 mc13xxx_lock(mc13783); =20 - if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) { - priv->keymap[0] =3D pdata->b1on_key; - if (pdata->b1on_key !=3D KEY_RESERVED) - __set_bit(pdata->b1on_key, pwr->keybit); + 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); =20 - if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT) + if (pdata->b_on_flags[0] & MC13783_BUTTON_POL_INVERT) priv->flags |=3D MC13783_PWRB_B1_POL_INVERT; =20 - if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN) + if (pdata->b_on_flags[0] & MC13783_BUTTON_RESET_EN) reg |=3D MC13783_POWER_CONTROL_2_ON1BRSTEN; =20 irq =3D platform_get_irq_byname(pdev, "b1on"); @@ -144,15 +144,15 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) priv->irq[0] =3D irq; } =20 - if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) { - priv->keymap[1] =3D pdata->b2on_key; - if (pdata->b2on_key !=3D KEY_RESERVED) - __set_bit(pdata->b2on_key, pwr->keybit); + 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); =20 - if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT) + if (pdata->b_on_flags[1] & MC13783_BUTTON_POL_INVERT) priv->flags |=3D MC13783_PWRB_B2_POL_INVERT; =20 - if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN) + if (pdata->b_on_flags[1] & MC13783_BUTTON_RESET_EN) reg |=3D MC13783_POWER_CONTROL_2_ON2BRSTEN; =20 irq =3D platform_get_irq_byname(pdev, "b2on"); @@ -171,15 +171,15 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) priv->irq[1] =3D irq; } =20 - if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) { - priv->keymap[2] =3D pdata->b3on_key; - if (pdata->b3on_key !=3D KEY_RESERVED) - __set_bit(pdata->b3on_key, pwr->keybit); + 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); =20 - if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT) + if (pdata->b_on_flags[2] & MC13783_BUTTON_POL_INVERT) priv->flags |=3D MC13783_PWRB_B3_POL_INVERT; =20 - if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN) + if (pdata->b_on_flags[2] & MC13783_BUTTON_RESET_EN) reg |=3D MC13783_POWER_CONTROL_2_ON3BRSTEN; =20 irq =3D platform_get_irq_byname(pdev, "b3on"); diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h index dd46fe424a80..4437ab80fcf8 100644 --- a/include/linux/mfd/mc13xxx.h +++ b/include/linux/mfd/mc13xxx.h @@ -181,12 +181,8 @@ struct mc13xxx_leds_platform_data { #define MC13783_BUTTON_RESET_EN (1 << 4) =20 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]; }; =20 #define MC13783_TS_ATO_FIRST false --=20 2.39.5 From nobody Sun Feb 8 09:12:49 2026 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 EDE572EACFB; Wed, 8 Oct 2025 06:45:43 +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=1759905946; cv=none; b=p36WiNwUo9/puoQH8XgmUV7e0yERGHJ+cM0T/rzhdGyGoXfDCOmiO63bhhoDB3qs8XbuTjbZquq33y0Ic12O2UfyG/CkNWsK2FiTnNu6NHA9OivF+Kap2s/0wi+vRPN3w9Y9waWx5v10FvBzoKLbyL5Og1/CpKLSXhoc+2pgCvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759905946; c=relaxed/simple; bh=/+GETeLQjjLscAF7KRcPnmg2AU1mx2FJb5U3/C8fEbI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IqssqRW5Iu/qYpxG5aU0UYEWlnCOW2r4QZXynmxof5idXxr5i2gbWp9CkcWcAy8balNfDTQpsTlx7IN6u8zfM83VmU7ERwkspp+zd20/1KBFET3MxfuRV9O0pmv53FOKl42N9OMb5tPBA2ndQpqis6bILR38a5onHRHrNYijxdQ= 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 5986i3Nd013938; Wed, 8 Oct 2025 06:44:03 GMT Received: (from akurz@localhost) by blala.de (8.15.2/8.15.2/Submit) id 5986i39M013934; Wed, 8 Oct 2025 06:44:03 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 v5 4/5] Input: mc13783-pwrbutton: enable other mc13xxx PMIC Date: Wed, 8 Oct 2025 06:44:00 +0000 Message-Id: <20251008064401.13863-5-akurz@blala.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20251008064401.13863-1-akurz@blala.de> References: <20251008064401.13863-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 0e6b49fb54bc..c36c575f11e5 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -286,8 +286,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 1756c8d47d5e..c29974722704 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 From nobody Sun Feb 8 09:12:49 2026 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 E09EB2E9722; Wed, 8 Oct 2025 06:45:38 +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=1759905940; cv=none; b=PnEyD7RKR5AWUf/wDT4Nzcx3awaSG6tfgiTwdBw+rvTsXjKE/cSasg0YMLEsrQ23G39MQcvtWUxVvY14GCD+b5BMdkeH3h7LCiRmVkSNcUNB+UYWXx82oACBBlUjSTmKsFNIECLu92t/weAqP7JHiNBeVFrXmNExeRBHc7cJb3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759905940; c=relaxed/simple; bh=r+b3tjTeJV3KjwgBwxOoZF/b85zoSUZhDlvxxf/bruY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mEsf/VQZ7lrCi++PEpilFdgZGDB9C2Ca39eqLCyeusn/4s6JOYHIY4MPuiHmGvlN4pLH+W3F5TV6EGTJ1oBa5fa8c10AMtR6rUN65ntiqtEv6H4qmF7kPOdbJVJ2inpb8r2nf+a4fc4szIMoeKz+eZgysJjyPok7qPw7y+VdGYY= 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 5986i3HT013946; Wed, 8 Oct 2025 06:44:03 GMT Received: (from akurz@localhost) by blala.de (8.15.2/8.15.2/Submit) id 5986i3Nj013941; Wed, 8 Oct 2025 06:44:03 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 v5 5/5] Input: mc13783-pwrbutton: add OF support and drop platform_data Date: Wed, 8 Oct 2025 06:44:01 +0000 Message-Id: <20251008064401.13863-6-akurz@blala.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20251008064401.13863-1-akurz@blala.de> References: <20251008064401.13863-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" Add OF support for the mc13783-pwrbutton so that it can be used with modern DT based systems, dropping support for platform_data. Signed-off-by: Alexander Kurz --- drivers/input/misc/mc13783-pwrbutton.c | 104 +++++++++++++++++++++---- drivers/mfd/mc13xxx-core.c | 4 - include/linux/mfd/mc13xxx.h | 14 ---- 3 files changed, 88 insertions(+), 34 deletions(-) diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc= 13783-pwrbutton.c index 08618c59197f..0fa630adff19 100644 --- a/drivers/input/misc/mc13783-pwrbutton.c +++ b/drivers/input/misc/mc13783-pwrbutton.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include =20 @@ -41,10 +42,20 @@ struct mc13783_pwrb { struct mc13xxx *mc13783; const struct mc13xxx_button_devtype *devtype; int flags; + int b_on_flags[3]; + unsigned int b_on_key[3]; unsigned short keymap[3]; int irq[3]; }; =20 +#define MC13783_BUTTON_DBNC_0MS 0 +#define MC13783_BUTTON_DBNC_30MS 1 +#define MC13783_BUTTON_DBNC_150MS 2 +#define MC13783_BUTTON_DBNC_750MS 3 +#define MC13783_BUTTON_ENABLE (1 << 2) +#define MC13783_BUTTON_POL_INVERT (1 << 3) +#define MC13783_BUTTON_RESET_EN (1 << 4) + #define MC13783_PWRB_B1_POL_INVERT (1 << 0) #define MC13783_PWRB_B2_POL_INVERT (1 << 1) #define MC13783_PWRB_B3_POL_INVERT (1 << 2) @@ -88,9 +99,69 @@ static irqreturn_t button_irq(int irq, void *_priv) return IRQ_HANDLED; } =20 +static int mc13xxx_pwrbutton_parse_properties(struct platform_device *pdev, + struct mc13783_pwrb *priv) +{ + struct fwnode_handle *child; + struct device *dev =3D &pdev->dev; + struct mc13xxx_button_devtype *devtype =3D + (struct mc13xxx_button_devtype *)platform_get_device_id(pdev)->driver_da= ta; + + struct fwnode_handle *parent __free(fwnode_handle) =3D + device_get_named_child_node(dev->parent, "buttons"); + if (!parent) + return -ENODATA; + + fwnode_for_each_named_child_node(parent, child, "onkey") { + u32 idx; + u8 dbnc =3D MC13783_BUTTON_DBNC_30MS; + u16 dbnc_ms; + + if (fwnode_property_read_u32(child, "reg", &idx)) + continue; + + if (idx > devtype->button_id_max) { + dev_warn(dev, "reg out of range\n"); + continue; + } + + fwnode_property_read_u16(child, "debounce-delay-ms", &dbnc_ms); + switch (dbnc_ms) { + case 0: + dbnc =3D MC13783_BUTTON_DBNC_0MS; + break; + case 30: + dbnc =3D MC13783_BUTTON_DBNC_30MS; + break; + case 150: + dbnc =3D MC13783_BUTTON_DBNC_150MS; + break; + case 750: + dbnc =3D MC13783_BUTTON_DBNC_750MS; + break; + default: + dev_warn(dev, "invalid debounce-delay-ms value\n"); + continue; + } + + if (fwnode_property_read_u32(child, "linux,code", &priv->b_on_key[idx])) + continue; + + if (fwnode_property_read_bool(child, "active-low")) + priv->b_on_flags[idx] |=3D MC13783_BUTTON_POL_INVERT; + + if (fwnode_property_read_bool(child, "fsl,enable-reset")) + priv->b_on_flags[idx] |=3D MC13783_BUTTON_RESET_EN; + + priv->b_on_flags[idx] |=3D MC13783_BUTTON_ENABLE | dbnc; + } + + return 0; +} + static int mc13783_pwrbutton_probe(struct platform_device *pdev) { - const struct mc13xxx_buttons_platform_data *pdata; + struct device *dev =3D &pdev->dev; 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; @@ -100,11 +171,8 @@ static int mc13783_pwrbutton_probe(struct platform_dev= ice *pdev) int reg =3D 0; int irq =3D 0; =20 - pdata =3D dev_get_platdata(&pdev->dev); - if (!pdata) { - dev_err(&pdev->dev, "missing platform data\n"); - return -ENODEV; - } + if (!dev->parent->of_node) + return -ENODATA; =20 pwr =3D devm_input_allocate_device(&pdev->dev); if (!pwr) @@ -114,14 +182,18 @@ 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) { + err =3D mc13xxx_pwrbutton_parse_properties(pdev, priv); + if (err) + return err; + + if (devtype->button_id_max < 2 && priv->b_on_flags[2] & 0x3) { dev_err(&pdev->dev, "button not supported\n"); return -ENODEV; } =20 - 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; + reg |=3D (priv->b_on_flags[0] & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC; + reg |=3D (priv->b_on_flags[1] & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC; + reg |=3D (priv->b_on_flags[2] & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC; =20 priv->pwr =3D pwr; priv->mc13783 =3D mc13783; @@ -130,17 +202,17 @@ static int mc13783_pwrbutton_probe(struct platform_de= vice *pdev) mc13xxx_lock(mc13783); =20 for (int i =3D 0; i < devtype->button_id_max; i++) { - if ((pdata->b_on_flags[i] & MC13783_BUTTON_ENABLE) =3D=3D 0) + if ((priv->b_on_flags[i] & MC13783_BUTTON_ENABLE) =3D=3D 0) continue; =20 - 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); + priv->keymap[i] =3D priv->b_on_key[i]; + if (priv->b_on_key[i] !=3D KEY_RESERVED) + __set_bit(priv->b_on_key[i], pwr->keybit); =20 - if (pdata->b_on_flags[i] & MC13783_BUTTON_POL_INVERT) + if (priv->b_on_flags[i] & MC13783_BUTTON_POL_INVERT) priv->flags |=3D (MC13783_PWRB_B1_POL_INVERT << i); =20 - if (pdata->b_on_flags[i] & MC13783_BUTTON_RESET_EN) + if (priv->b_on_flags[i] & MC13783_BUTTON_RESET_EN) reg |=3D (MC13783_POWER_CONTROL_2_ON1BRSTEN << i); =20 irq =3D platform_get_irq_byname(pdev, devtype->irq_name[i]); diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c index c29974722704..9512136e821b 100644 --- a/drivers/mfd/mc13xxx-core.c +++ b/drivers/mfd/mc13xxx-core.c @@ -504,10 +504,6 @@ int mc13xxx_common_init(struct device *dev) &pdata->regulators, sizeof(pdata->regulators)); mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led", pdata->leds, sizeof(*pdata->leds)); - mc13xxx_add_subdevice_pdata_res(mc13xxx, "%s-pwrbutton", - pdata->buttons, sizeof(*pdata->buttons), - mc13xxx->variant->button_resources, - mc13xxx->variant->button_resources_size); if (mc13xxx->flags & MC13XXX_USE_CODEC) mc13xxx_add_subdevice_pdata(mc13xxx, "%s-codec", pdata->codec, sizeof(*pdata->codec)); diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h index 71c7d3614d4c..ac3765df341d 100644 --- a/include/linux/mfd/mc13xxx.h +++ b/include/linux/mfd/mc13xxx.h @@ -174,19 +174,6 @@ struct mc13xxx_leds_platform_data { u32 led_control[MAX_LED_CONTROL_REGS]; }; =20 -#define MC13783_BUTTON_DBNC_0MS 0 -#define MC13783_BUTTON_DBNC_30MS 1 -#define MC13783_BUTTON_DBNC_150MS 2 -#define MC13783_BUTTON_DBNC_750MS 3 -#define MC13783_BUTTON_ENABLE (1 << 2) -#define MC13783_BUTTON_POL_INVERT (1 << 3) -#define MC13783_BUTTON_RESET_EN (1 << 4) - -struct mc13xxx_buttons_platform_data { - int b_on_flags[3]; - unsigned int b_on_key[3]; -}; - #define MC13783_TS_ATO_FIRST false #define MC13783_TS_ATO_EACH true =20 @@ -219,7 +206,6 @@ struct mc13xxx_platform_data { =20 struct mc13xxx_regulator_platform_data regulators; struct mc13xxx_leds_platform_data *leds; - struct mc13xxx_buttons_platform_data *buttons; struct mc13xxx_ts_platform_data touch; struct mc13xxx_codec_platform_data *codec; }; --=20 2.39.5