1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/input.h>
3 #include <linux/interrupt.h>
5 #include <linux/platform_device.h>
6 #include <linux/regmap.h>
8 #include <linux/mfd/88pm886.h>
11 struct input_dev
*idev
;
12 struct pm886_chip
*chip
;
15 static irqreturn_t
pm886_onkey_irq_handler(int irq
, void *data
)
17 struct pm886_onkey
*onkey
= data
;
18 struct regmap
*regmap
= onkey
->chip
->regmap
;
19 struct input_dev
*idev
= onkey
->idev
;
20 struct device
*parent
= idev
->dev
.parent
;
24 err
= regmap_read(regmap
, PM886_REG_STATUS1
, &val
);
26 dev_err(parent
, "Failed to read status: %d\n", err
);
29 val
&= PM886_ONKEY_STS1
;
31 input_report_key(idev
, KEY_POWER
, val
);
37 static int pm886_onkey_probe(struct platform_device
*pdev
)
39 struct pm886_chip
*chip
= dev_get_drvdata(pdev
->dev
.parent
);
40 struct device
*dev
= &pdev
->dev
;
41 struct pm886_onkey
*onkey
;
42 struct input_dev
*idev
;
45 onkey
= devm_kzalloc(dev
, sizeof(*onkey
), GFP_KERNEL
);
51 irq
= platform_get_irq(pdev
, 0);
53 return dev_err_probe(dev
, irq
, "Failed to get IRQ\n");
55 idev
= devm_input_allocate_device(dev
);
57 dev_err(dev
, "Failed to allocate input device\n");
62 idev
->name
= "88pm886-onkey";
63 idev
->phys
= "88pm886-onkey/input0";
64 idev
->id
.bustype
= BUS_I2C
;
66 input_set_capability(idev
, EV_KEY
, KEY_POWER
);
68 err
= devm_request_threaded_irq(dev
, irq
, NULL
, pm886_onkey_irq_handler
,
69 IRQF_ONESHOT
| IRQF_NO_SUSPEND
, "onkey",
72 return dev_err_probe(dev
, err
, "Failed to request IRQ\n");
74 err
= input_register_device(idev
);
76 return dev_err_probe(dev
, err
, "Failed to register input device\n");
81 static const struct platform_device_id pm886_onkey_id_table
[] = {
85 MODULE_DEVICE_TABLE(platform
, pm886_onkey_id_table
);
87 static struct platform_driver pm886_onkey_driver
= {
89 .name
= "88pm886-onkey",
91 .probe
= pm886_onkey_probe
,
92 .id_table
= pm886_onkey_id_table
,
94 module_platform_driver(pm886_onkey_driver
);
96 MODULE_DESCRIPTION("Marvell 88PM886 onkey driver");
97 MODULE_AUTHOR("Karel Balej <balejk@matfyz.cz>");
98 MODULE_LICENSE("GPL");