Skip to content

Commit 136b163

Browse files
committed
input: misc: add driver for max16150
MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller Signed-off-by: Marc Paolo Sosa <[email protected]>
1 parent 4d47af2 commit 136b163

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-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: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
last_time = now;
33+
return IRQ_HANDLED;
34+
}
35+
36+
static int max16150_probe(struct platform_device *pdev)
37+
{
38+
int ret;
39+
40+
max16150_input_dev = devm_input_allocate_device(&pdev->dev);
41+
if (!max16150_input_dev)
42+
return -ENOMEM;
43+
44+
max16150_input_dev->name = "max16150";
45+
max16150_input_dev->id.bustype = BUS_HOST;
46+
47+
ret = input_register_device(max16150_input_dev);
48+
if (ret)
49+
return ret;
50+
51+
ret = devm_gpio_request_one(&pdev->dev, GPIO_CLR, GPIOF_OUT_INIT_HIGH,
52+
"max16150_clr");
53+
if (ret)
54+
return ret;
55+
56+
irq_number = gpio_to_irq(GPIO_INT);
57+
ret = devm_request_irq(&pdev->dev, irq_number, max16150_isr,
58+
IRQF_TRIGGER_RISING, "max16150_irq", NULL);
59+
if (ret)
60+
return ret;
61+
62+
last_time = ktime_get();
63+
return 0;
64+
}
65+
66+
static int max16150_remove(struct platform_device *pdev)
67+
{
68+
input_unregister_device(max16150_input_dev);
69+
return 0;
70+
}
71+
72+
static const struct of_device_id max16150_of_match[] = {
73+
{ .compatible = "maxim,max16150", },
74+
{ }
75+
};
76+
MODULE_DEVICE_TABLE(of, max16150_of_match);
77+
78+
static struct platform_driver max16150_driver = {
79+
.probe = max16150_probe,
80+
.remove = max16150_remove,
81+
.driver = {
82+
.name = "max16150",
83+
.of_match_table = max16150_of_match,
84+
},
85+
};
86+
87+
module_platform_driver(max16150_driver);
88+
89+
MODULE_AUTHOR("Marc Paolo Sosa <[email protected]>");
90+
MODULE_DESCRIPTION("MAX16150/MAX16169 Pushbutton Driver");
91+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)