From: Alexander Kurz <akurz@blala.de>
To: "Lee Jones" <lee@kernel.org>, "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Dzmitry Sankouski" <dsankouski@gmail.com>,
"Dr. David Alan Gilbert" <linux@treblig.org>,
"Heiko Stuebner" <heiko@sntech.de>,
"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
devicetree@vger.kernel.org, linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Alexander Kurz <akurz@blala.de>
Subject: [PATCH v4 8/8] Input: mc13783-pwrbutton: add OF support
Date: Sun, 14 Sep 2025 19:37:23 +0000 [thread overview]
Message-ID: <20250914193723.10544-9-akurz@blala.de> (raw)
In-Reply-To: <20250914193723.10544-1-akurz@blala.de>
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 | 82 ++++++++++++++++++++++++--
1 file changed, 76 insertions(+), 6 deletions(-)
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
index 08618c59197f..46bef0af46ee 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -27,6 +27,7 @@
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/mfd/mc13783.h>
+#include <linux/property.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -88,8 +89,74 @@ static irqreturn_t button_irq(int irq, void *_priv)
return IRQ_HANDLED;
}
-static int mc13783_pwrbutton_probe(struct platform_device *pdev)
+static struct mc13xxx_buttons_platform_data __init *mc13xxx_pwrbutton_probe_dt(
+ struct platform_device *pdev)
{
+ struct mc13xxx_buttons_platform_data *pdata;
+ struct fwnode_handle *child;
+ struct device *dev = &pdev->dev;
+ struct mc13xxx_button_devtype *devtype =
+ (struct mc13xxx_button_devtype *)platform_get_device_id(pdev)->driver_data;
+
+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return ERR_PTR(-ENOMEM);
+
+ struct fwnode_handle *parent __free(fwnode_handle) =
+ device_get_named_child_node(dev->parent, "buttons");
+ if (!parent)
+ return ERR_PTR(-ENODATA);
+
+ fwnode_for_each_named_child_node(parent, child, "onkey") {
+ u32 idx;
+ u8 dbnc = 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 = MC13783_BUTTON_DBNC_0MS;
+ break;
+ case 30:
+ dbnc = MC13783_BUTTON_DBNC_30MS;
+ break;
+ case 150:
+ dbnc = MC13783_BUTTON_DBNC_150MS;
+ break;
+ case 750:
+ dbnc = MC13783_BUTTON_DBNC_750MS;
+ break;
+ default:
+ dev_warn(dev, "invalid debounce-delay-ms value\n");
+ continue;
+ }
+
+ if (fwnode_property_read_u32(child, "linux,code", &pdata->b_on_key[idx]))
+ continue;
+
+ if (fwnode_property_read_bool(child, "active-low"))
+ pdata->b_on_flags[idx] |= MC13783_BUTTON_POL_INVERT;
+
+ if (fwnode_property_read_bool(child, "fsl,enable-reset"))
+ pdata->b_on_flags[idx] |= MC13783_BUTTON_RESET_EN;
+
+ pdata->b_on_flags[idx] |= MC13783_BUTTON_ENABLE | dbnc;
+ }
+
+ return pdata;
+}
+
+static int __init 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);
struct mc13xxx_button_devtype *devtype =
@@ -101,9 +168,13 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
int irq = 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);
@@ -214,13 +285,12 @@ static const struct platform_device_id mc13xxx_pwrbutton_idtable[] = {
static struct platform_driver mc13783_pwrbutton_driver = {
.id_table = mc13xxx_pwrbutton_idtable,
- .probe = mc13783_pwrbutton_probe,
.driver = {
.name = "mc13783-pwrbutton",
},
};
-module_platform_driver(mc13783_pwrbutton_driver);
+module_platform_driver_probe(mc13783_pwrbutton_driver, mc13783_pwrbutton_probe);
MODULE_ALIAS("platform:mc13783-pwrbutton");
MODULE_DESCRIPTION("MC13783 Power Button");
--
2.39.5
next prev parent reply other threads:[~2025-09-14 19:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-14 19:37 [PATCH v4 0/8] Fix, extend and support OF to mc13xxx pwrbutton Alexander Kurz
2025-09-14 19:37 ` [PATCH v4 1/8] dt-bindings: mfd: fsl,mc13xxx: convert txt to DT schema Alexander Kurz
2025-09-14 19:37 ` [PATCH v4 2/8] dt-bindings: mfd: fsl,mc13xxx: add buttons node Alexander Kurz
2025-09-14 19:37 ` [PATCH v4 3/8] Input: mc13783-pwrbutton: use managed resources Alexander Kurz
2025-09-14 19:37 ` [PATCH v4 4/8] mfd: mc13xxx: Use devm_mfd_add_devices and devm_regmap_add_irq_chip Alexander Kurz
2025-09-16 14:44 ` (subset) " Lee Jones
2025-09-16 18:09 ` Dmitry Torokhov
2025-09-17 10:04 ` Lee Jones
2025-09-18 7:25 ` Alexander Kurz
2025-09-14 19:37 ` [PATCH v4 5/8] Input: mc13783-pwrbutton: fix irq mixup and use resources Alexander Kurz
2025-09-14 19:37 ` [PATCH v4 6/8] Input: mc13783-pwrbutton: convert pdata members to array Alexander Kurz
2025-09-14 19:37 ` [PATCH v4 7/8] Input: mc13783-pwrbutton: enable other mc13xxx PMIC Alexander Kurz
2025-09-14 19:37 ` Alexander Kurz [this message]
2025-09-18 15:43 ` [PATCH v4 8/8] Input: mc13783-pwrbutton: add OF support Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250914193723.10544-9-akurz@blala.de \
--to=akurz@blala.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=dsankouski@gmail.com \
--cc=heiko@sntech.de \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@treblig.org \
--cc=robh@kernel.org \
--cc=u.kleine-koenig@baylibre.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®