Skip to content

Commit c8cf6e2

Browse files
scosulag-linaro
authored andcommitted
Input: Add tps65219 interrupt driven powerbutton
TPS65219 has different interrupts compared to other TPS6521* chips. TPS65219 defines two interrupts for the powerbutton one for push and one for release. This driver is very simple in that it maps the push interrupt to a key input and the release interrupt to a key release. Signed-off-by: Markus Schneider-Pargmann <[email protected]> Signed-off-by: Jerome Neanne <[email protected]> Acked-by: Dmitry Torokhov <[email protected]> Signed-off-by: Lee Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 74c17a0 commit c8cf6e2

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

drivers/input/misc/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,16 @@ config INPUT_TPS65218_PWRBUTTON
468468
To compile this driver as a module, choose M here. The module will
469469
be called tps65218-pwrbutton.
470470

471+
config INPUT_TPS65219_PWRBUTTON
472+
tristate "TPS65219 Power button driver"
473+
depends on MFD_TPS65219
474+
help
475+
Say Y here if you want to enable power button reporting for
476+
TPS65219 Power Management IC devices.
477+
478+
To compile this driver as a module, choose M here. The module will
479+
be called tps65219-pwrbutton.
480+
471481
config INPUT_AXP20X_PEK
472482
tristate "X-Powers AXP20X power button driver"
473483
depends on MFD_AXP20X

drivers/input/misc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY) += soc_button_array.o
7979
obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o
8080
obj-$(CONFIG_INPUT_STPMIC1_ONKEY) += stpmic1_onkey.o
8181
obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o
82+
obj-$(CONFIG_INPUT_TPS65219_PWRBUTTON) += tps65219-pwrbutton.o
8283
obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o
8384
obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o
8485
obj-$(CONFIG_INPUT_TWL6040_VIBRA) += twl6040-vibra.o
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
//
3+
// Driver for TPS65219 Push Button
4+
//
5+
// Copyright (C) 2022 BayLibre Incorporated - https://www.baylibre.com/
6+
7+
#include <linux/init.h>
8+
#include <linux/input.h>
9+
#include <linux/interrupt.h>
10+
#include <linux/kernel.h>
11+
#include <linux/mfd/tps65219.h>
12+
#include <linux/module.h>
13+
#include <linux/of.h>
14+
#include <linux/platform_device.h>
15+
#include <linux/regmap.h>
16+
#include <linux/slab.h>
17+
18+
struct tps65219_pwrbutton {
19+
struct device *dev;
20+
struct input_dev *idev;
21+
char phys[32];
22+
};
23+
24+
static irqreturn_t tps65219_pb_push_irq(int irq, void *_pwr)
25+
{
26+
struct tps65219_pwrbutton *pwr = _pwr;
27+
28+
input_report_key(pwr->idev, KEY_POWER, 1);
29+
pm_wakeup_event(pwr->dev, 0);
30+
input_sync(pwr->idev);
31+
32+
return IRQ_HANDLED;
33+
}
34+
35+
static irqreturn_t tps65219_pb_release_irq(int irq, void *_pwr)
36+
{
37+
struct tps65219_pwrbutton *pwr = _pwr;
38+
39+
input_report_key(pwr->idev, KEY_POWER, 0);
40+
input_sync(pwr->idev);
41+
42+
return IRQ_HANDLED;
43+
}
44+
45+
static int tps65219_pb_probe(struct platform_device *pdev)
46+
{
47+
struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
48+
struct device *dev = &pdev->dev;
49+
struct tps65219_pwrbutton *pwr;
50+
struct input_dev *idev;
51+
int error;
52+
int push_irq;
53+
int release_irq;
54+
55+
pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL);
56+
if (!pwr)
57+
return -ENOMEM;
58+
59+
idev = devm_input_allocate_device(dev);
60+
if (!idev)
61+
return -ENOMEM;
62+
63+
idev->name = pdev->name;
64+
snprintf(pwr->phys, sizeof(pwr->phys), "%s/input0",
65+
pdev->name);
66+
idev->phys = pwr->phys;
67+
idev->id.bustype = BUS_I2C;
68+
69+
input_set_capability(idev, EV_KEY, KEY_POWER);
70+
71+
pwr->dev = dev;
72+
pwr->idev = idev;
73+
device_init_wakeup(dev, true);
74+
75+
push_irq = platform_get_irq(pdev, 0);
76+
if (push_irq < 0)
77+
return -EINVAL;
78+
79+
release_irq = platform_get_irq(pdev, 1);
80+
if (release_irq < 0)
81+
return -EINVAL;
82+
83+
error = devm_request_threaded_irq(dev, push_irq, NULL,
84+
tps65219_pb_push_irq,
85+
IRQF_ONESHOT,
86+
dev->init_name, pwr);
87+
if (error) {
88+
dev_err(dev, "failed to request push IRQ #%d: %d\n", push_irq,
89+
error);
90+
return error;
91+
}
92+
93+
error = devm_request_threaded_irq(dev, release_irq, NULL,
94+
tps65219_pb_release_irq,
95+
IRQF_ONESHOT,
96+
dev->init_name, pwr);
97+
if (error) {
98+
dev_err(dev, "failed to request release IRQ #%d: %d\n",
99+
release_irq, error);
100+
return error;
101+
}
102+
103+
error = input_register_device(idev);
104+
if (error) {
105+
dev_err(dev, "Can't register power button: %d\n", error);
106+
return error;
107+
}
108+
109+
/* Enable interrupts for the pushbutton */
110+
regmap_clear_bits(tps->regmap, TPS65219_REG_MASK_CONFIG,
111+
TPS65219_REG_MASK_INT_FOR_PB_MASK);
112+
113+
/* Set PB/EN/VSENSE pin to be a pushbutton */
114+
regmap_update_bits(tps->regmap, TPS65219_REG_MFP_2_CONFIG,
115+
TPS65219_MFP_2_EN_PB_VSENSE_MASK, TPS65219_MFP_2_PB);
116+
117+
return 0;
118+
}
119+
120+
static int tps65219_pb_remove(struct platform_device *pdev)
121+
{
122+
struct tps65219 *tps = dev_get_drvdata(pdev->dev.parent);
123+
124+
/* Disable interrupt for the pushbutton */
125+
return regmap_update_bits(tps->regmap, TPS65219_REG_MASK_CONFIG,
126+
TPS65219_REG_MASK_INT_FOR_PB_MASK,
127+
TPS65219_REG_MASK_INT_FOR_PB_MASK);
128+
}
129+
130+
static const struct platform_device_id tps65219_pwrbtn_id_table[] = {
131+
{ "tps65219-pwrbutton", },
132+
{ /* sentinel */ }
133+
};
134+
MODULE_DEVICE_TABLE(platform, tps65219_pwrbtn_id_table);
135+
136+
static struct platform_driver tps65219_pb_driver = {
137+
.probe = tps65219_pb_probe,
138+
.remove = tps65219_pb_remove,
139+
.driver = {
140+
.name = "tps65219_pwrbutton",
141+
},
142+
.id_table = tps65219_pwrbtn_id_table,
143+
};
144+
module_platform_driver(tps65219_pb_driver);
145+
146+
MODULE_DESCRIPTION("TPS65219 Power Button");
147+
MODULE_LICENSE("GPL");
148+
MODULE_AUTHOR("Markus Schneider-Pargmann <[email protected]");

0 commit comments

Comments
 (0)