Skip to content

Commit 2dc6f75

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 3a603d9 commit 2dc6f75

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-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: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
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/platform_device.h>
13+
14+
#define GPIO_INT 17
15+
#define GPIO_CLR 27
16+
17+
static struct input_dev *max16150_input_dev;
18+
static int irq_number;
19+
static ktime_t last_time;
20+
static const ktime_t short_pulse = 32 * NSEC_PER_MSEC;
21+
static const ktime_t long_pulse = 128 * NSEC_PER_MSEC;
22+
23+
static irqreturn_t max16150_isr(int irq, void *dev_id)
24+
{
25+
ktime_t now = ktime_get();
26+
ktime_t duration = ktime_sub(now, last_time);
27+
28+
if (duration >= long_pulse)
29+
gpio_set_value(GPIO_CLR, 0);
30+
31+
last_time = now;
32+
return IRQ_HANDLED;
33+
}
34+
35+
static int max16150_probe(struct platform_device *pdev)
36+
{
37+
struct input_dev *button;
38+
int ret;
39+
40+
button = devm_input_allocate_device(&pdev->dev);
41+
if (!button) {
42+
dev_err(&pdev->dev, "Can't allocate power button\n");
43+
return -ENOMEM;
44+
}
45+
46+
button->name = "max16150";
47+
button->phys = "max16150/input0";
48+
button->id.bustype = BUS_HOST;
49+
input_set_capability(button, EV_KEY, KEY_POWER);
50+
51+
ret = input_register_device(button);
52+
if (ret) {
53+
dev_err(&pdev->dev, "Can't register power button: %d\n", ret);
54+
return ret;
55+
}
56+
57+
ret = devm_gpio_request_one(&pdev->dev, GPIO_CLR, GPIOF_OUT_INIT_HIGH,
58+
"max16150_clr");
59+
if (ret)
60+
return ret;
61+
62+
irq_number = gpio_to_irq(GPIO_INT);
63+
ret = devm_request_irq(&pdev->dev, irq_number, max16150_isr,
64+
IRQF_TRIGGER_RISING, "max16150_irq", NULL);
65+
if (ret)
66+
return ret;
67+
68+
last_time = ktime_get();
69+
platform_set_drvdata(pdev, button);
70+
device_init_wakeup(&pdev->dev, true);
71+
72+
return 0;
73+
}
74+
75+
static int max16150_remove(struct platform_device *pdev)
76+
{
77+
input_unregister_device(max16150_input_dev);
78+
return 0;
79+
}
80+
81+
static struct platform_driver max16150_driver = {
82+
.probe = max16150_probe,
83+
.remove = max16150_remove,
84+
.driver = {
85+
.name = "max16150",
86+
},
87+
};
88+
89+
module_platform_driver(max16150_driver);
90+
91+
MODULE_AUTHOR("Marc Paolo Sosa <marcpaolo.sosa@analog.com>");
92+
MODULE_DESCRIPTION("MAX16150/MAX16169 Pushbutton Driver");
93+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)