]> git.dujemihanovic.xyz Git - linux.git/commitdiff
input: add onkey driver for Marvell 88PM88X PMICs
authorKarel Balej <balejk@matfyz.cz>
Sun, 17 Dec 2023 12:00:53 +0000 (13:00 +0100)
committerDuje Mihanović <duje.mihanovic@skole.hr>
Sat, 20 Jan 2024 19:52:01 +0000 (20:52 +0100)
The Marvell 88PM88X PMICs provide onkey among other things. Add client
driver to handle it. The driver currently only provides a basic support
omitting additional functions found in the vendor version, such as long
onkey and GPIO integration.

Signed-off-by: Karel Balej <balejk@matfyz.cz>
drivers/input/misc/88pm88x-onkey.c [new file with mode: 0644]
drivers/input/misc/Kconfig
drivers/input/misc/Makefile

diff --git a/drivers/input/misc/88pm88x-onkey.c b/drivers/input/misc/88pm88x-onkey.c
new file mode 100644 (file)
index 0000000..0d6056a
--- /dev/null
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/kernel.h>
+#include <linux/input.h>
+#include <linux/regmap.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+
+#include <linux/mfd/88pm88x.h>
+
+struct pm88x_onkey {
+       struct input_dev *idev;
+       struct pm88x_chip *chip;
+       int irq;
+};
+
+static irqreturn_t pm88x_onkey_irq_handler(int irq, void *data)
+{
+       struct pm88x_onkey *onkey = data;
+       unsigned int val;
+       int ret = 0;
+
+       ret = regmap_read(onkey->chip->regmaps[PM88X_REGMAP_BASE], PM88X_REG_STATUS1, &val);
+       if (ret) {
+               dev_err(onkey->idev->dev.parent, "Failed to read status: %d\n", ret);
+               return IRQ_NONE;
+       }
+       val &= PM88X_ONKEY_STS1;
+
+       input_report_key(onkey->idev, KEY_POWER, val);
+       input_sync(onkey->idev);
+
+       return IRQ_HANDLED;
+}
+
+static int pm88x_onkey_probe(struct platform_device *pdev)
+{
+       struct pm88x_chip *chip = dev_get_drvdata(pdev->dev.parent);
+       struct pm88x_onkey *onkey;
+       int err;
+
+       onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL);
+       if (!onkey)
+               return -ENOMEM;
+
+       onkey->chip = chip;
+
+       onkey->irq = platform_get_irq(pdev, 0);
+       if (onkey->irq < 0) {
+               dev_err(&pdev->dev, "Failed to get IRQ\n");
+               return -EINVAL;
+       }
+
+       onkey->idev = devm_input_allocate_device(&pdev->dev);
+       if (!onkey->idev) {
+               dev_err(&pdev->dev, "Failed to allocate input device\n");
+               return -ENOMEM;
+       }
+
+       onkey->idev->name = "88pm88x-onkey";
+       onkey->idev->phys = "88pm88x-onkey/input0";
+       onkey->idev->id.bustype = BUS_I2C;
+       onkey->idev->dev.parent = &pdev->dev;
+       onkey->idev->evbit[0] = BIT_MASK(EV_KEY);
+       onkey->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
+
+       err = devm_request_threaded_irq(&pdev->dev, onkey->irq, NULL, pm88x_onkey_irq_handler,
+                       IRQF_ONESHOT | IRQF_NO_SUSPEND, "onkey", onkey);
+       if (err) {
+               dev_err(&pdev->dev, "Failed to request IRQ: %d\n", err);
+               return err;
+       }
+
+       err = input_register_device(onkey->idev);
+       if (err) {
+               dev_err(&pdev->dev, "Failed to register input device: %d\n", err);
+               return err;
+       }
+
+       device_init_wakeup(&pdev->dev, 1);
+
+       return 0;
+}
+
+static const struct of_device_id pm88x_onkey_of_match[] = {
+       { .compatible = "marvell,88pm88x-onkey", },
+       { },
+};
+MODULE_DEVICE_TABLE(of, pm88x_onkey_of_match);
+
+static struct platform_driver pm88x_onkey_driver = {
+       .driver = {
+               .name = "88pm88x-onkey",
+               .of_match_table = of_match_ptr(pm88x_onkey_of_match),
+       },
+       .probe = pm88x_onkey_probe,
+};
+module_platform_driver(pm88x_onkey_driver);
+
+MODULE_DESCRIPTION("Marvell 88PM88X onkey driver");
+MODULE_AUTHOR("Karel Balej <balejk@matfyz.cz>");
+MODULE_LICENSE("GPL");
index 6ba984d7f0b18694f48160c4628575af1c8ea252..fdfa3e23c3cfb943018674b32a4db03e2f0ee0b0 100644 (file)
@@ -33,6 +33,16 @@ config INPUT_88PM80X_ONKEY
          To compile this driver as a module, choose M here: the module
          will be called 88pm80x_onkey.
 
+config INPUT_88PM88X_ONKEY
+       tristate "Marvell 88PM88X onkey support"
+       depends on MFD_88PM88X
+       help
+         Support the onkey of Marvell 88PM88X PMICs as an input device
+         reporting power button status.
+
+         To compile this driver as a module, choose M here: the module
+         will be called 88pm88x-onkey.
+
 config INPUT_AB8500_PONKEY
        tristate "AB8500 Pon (PowerOn) Key"
        depends on AB8500_CORE
index 04296a4abe8e87ac41873d4451abc8e3c00d02a5..eab7a364188cd3751b8a76f910c385c213d17a84 100644 (file)
@@ -7,6 +7,7 @@
 
 obj-$(CONFIG_INPUT_88PM860X_ONKEY)     += 88pm860x_onkey.o
 obj-$(CONFIG_INPUT_88PM80X_ONKEY)      += 88pm80x_onkey.o
+obj-$(CONFIG_INPUT_88PM88X_ONKEY)      += 88pm88x-onkey.o
 obj-$(CONFIG_INPUT_AB8500_PONKEY)      += ab8500-ponkey.o
 obj-$(CONFIG_INPUT_AD714X)             += ad714x.o
 obj-$(CONFIG_INPUT_AD714X_I2C)         += ad714x-i2c.o