Skip to content

Commit 9cae81f

Browse files
committed
input: misc: add driver for max16150
MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller Signed-off-by: Marc Paolo Sosa <marcpaolo.sosa@analog.com>
1 parent 4d47af2 commit 9cae81f

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

drivers/input/misc/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ config INPUT_E3X0_BUTTON
150150
To compile this driver as a module, choose M here: the
151151
module will be called e3x0_button.
152152

153+
config INPUT_MAX16150_PWRBUTTON
154+
bool "MAX16150/MAX16169 Pushbutton driver"
155+
depends on OF_GPIO
156+
help
157+
This driver supports the MAX16150 and MAX16169 pushbutton
158+
controllers, which are low-power devices with a switch
159+
debouncer and built-in latch. Device bindings are specified
160+
in the device tree.
161+
153162
config INPUT_PCSPKR
154163
tristate "PC Speaker support"
155164
depends on PCSPKR_PLATFORM

drivers/input/misc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ obj-$(CONFIG_INPUT_IQS7222) += iqs7222.o
4949
obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o
5050
obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o
5151
obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o
52+
obj-$(CONFIG_INPUT_MAX16150_PWRBUTTON) += max16150.o
5253
obj-$(CONFIG_INPUT_MAX77650_ONKEY) += max77650-onkey.o
5354
obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o
5455
obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o

drivers/input/misc/max16150.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Analog Devices MAX16150/MAX16169 Pushbutton Driver
4+
*
5+
* Copyright 2024 Analog Devices Inc.
6+
*/
7+
8+
#include <linux/module.h>
9+
#include <linux/gpio.h>
10+
#include <linux/interrupt.h>
11+
#include <linux/input.h>
12+
#include <linux/of.h>
13+
#include <linux/platform_device.h>
14+
15+
#define GPIO_INT 17
16+
#define GPIO_CLR 27
17+
18+
static struct input_dev *max16150_input_dev;
19+
static int irq_number;
20+
static ktime_t last_time;
21+
static const ktime_t short_pulse = 32 * NSEC_PER_MSEC;
22+
static const ktime_t long_pulse = 128 * NSEC_PER_MSEC;
23+
24+
static irqreturn_t max16150_isr(int irq, void *dev_id)
25+
{
26+
ktime_t now = ktime_get();
27+
ktime_t duration = ktime_sub(now, last_time);
28+
29+
if (duration >= long_pulse) {
30+
gpio_set_value(GPIO_CLR, 0);
31+
}
32+
33+
last_time = now;
34+
return IRQ_HANDLED;
35+
}
36+
37+
static int max16150_probe(struct platform_device *pdev)
38+
{
39+
int ret;
40+
41+
max16150_input_dev = devm_input_allocate_device(&pdev->dev);
42+
if (!max16150_input_dev)
43+
return -ENOMEM;
44+
45+
max16150_input_dev->name = "max16150";
46+
max16150_input_dev->id.bustype = BUS_HOST;
47+
48+
ret = input_register_device(max16150_input_dev);
49+
if (ret)
50+
return ret;
51+
52+
ret = devm_gpio_request_one(&pdev->dev, GPIO_CLR, GPIOF_OUT_INIT_HIGH,
53+
"max16150_clr");
54+
if (ret)
55+
return ret;
56+
57+
irq_number = gpio_to_irq(GPIO_INT);
58+
ret = devm_request_irq(&pdev->dev, irq_number, max16150_isr,
59+
IRQF_TRIGGER_RISING, "max16150_irq", NULL);
60+
if (ret)
61+
return ret;
62+
63+
last_time = ktime_get();
64+
return 0;
65+
}
66+
67+
static int max16150_remove(struct platform_device *pdev)
68+
{
69+
input_unregister_device(max16150_input_dev);
70+
return 0;
71+
}
72+
73+
static const struct of_device_id max16150_of_match[] = {
74+
{ .compatible = "maxim,max16150", },
75+
{ }
76+
};
77+
MODULE_DEVICE_TABLE(of, max16150_of_match);
78+
79+
static struct platform_driver max16150_driver = {
80+
.probe = max16150_probe,
81+
.remove = max16150_remove,
82+
.driver = {
83+
.name = "max16150",
84+
.of_match_table = max16150_of_match,
85+
},
86+
};
87+
88+
module_platform_driver(max16150_driver);
89+
90+
MODULE_AUTHOR("Marc Paolo Sosa <marcpaolo.sosa@analog.com>");
91+
MODULE_DESCRIPTION("MAX16150/MAX16169 Pushbutton Driver");
92+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)