diff options
author | Felipe Balbi <balbi@ti.com> | 2014-12-27 23:37:37 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-12-27 23:43:03 -0500 |
commit | 5fafed3e5612e9f308d20dc94adf5fc3d4a1a2a8 (patch) | |
tree | 2d37cb7360ea3d970352eb11a75aada59dd12aea | |
parent | af6a5af8e8cc1566fc06636de02347825808650e (diff) |
Input: add tps65218 power button driver
With this driver, we can report KEY_POWER on AM437x SK. This patch has been
tested with said board.
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r-- | Documentation/devicetree/bindings/input/tps65218-pwrbutton.txt | 17 | ||||
-rw-r--r-- | drivers/input/misc/Kconfig | 10 | ||||
-rw-r--r-- | drivers/input/misc/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/misc/tps65218-pwrbutton.c | 126 |
4 files changed, 154 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/input/tps65218-pwrbutton.txt b/Documentation/devicetree/bindings/input/tps65218-pwrbutton.txt new file mode 100644 index 000000000000..e30e0b93f2b3 --- /dev/null +++ b/Documentation/devicetree/bindings/input/tps65218-pwrbutton.txt | |||
@@ -0,0 +1,17 @@ | |||
1 | Texas Instruments TPS65218 power button | ||
2 | |||
3 | This driver provides a simple power button event via an Interrupt. | ||
4 | |||
5 | Required properties: | ||
6 | - compatible: should be "ti,tps65218-pwrbutton" | ||
7 | - interrupts: should be one of the following | ||
8 | - <3 IRQ_TYPE_EDGE_BOTH>: For controllers compatible with tps65218 | ||
9 | |||
10 | Example: | ||
11 | |||
12 | &tps { | ||
13 | power-button { | ||
14 | compatible = "ti,tps65218-pwrbutton"; | ||
15 | interrupts = <3 IRQ_TYPE_EDGE_BOTH>; | ||
16 | }; | ||
17 | }; | ||
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 1da0a20c42ea..95919170795d 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
@@ -416,6 +416,16 @@ config INPUT_RETU_PWRBUTTON | |||
416 | To compile this driver as a module, choose M here. The module will | 416 | To compile this driver as a module, choose M here. The module will |
417 | be called retu-pwrbutton. | 417 | be called retu-pwrbutton. |
418 | 418 | ||
419 | config INPUT_TPS65218_PWRBUTTON | ||
420 | tristate "TPS65218 Power button driver" | ||
421 | depends on MFD_TPS65218 | ||
422 | help | ||
423 | Say Y here if you want to enable power buttong reporting for | ||
424 | the TPS65218 Power Management IC device. | ||
425 | |||
426 | To compile this driver as a module, choose M here. The module will | ||
427 | be called tps65218-pwrbutton. | ||
428 | |||
419 | config INPUT_TWL4030_PWRBUTTON | 429 | config INPUT_TWL4030_PWRBUTTON |
420 | tristate "TWL4030 Power button Driver" | 430 | tristate "TWL4030 Power button Driver" |
421 | depends on TWL4030_CORE | 431 | depends on TWL4030_CORE |
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 1f135af4af01..9a1083f78374 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile | |||
@@ -60,6 +60,7 @@ obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o | |||
60 | obj-$(CONFIG_INPUT_SIRFSOC_ONKEY) += sirfsoc-onkey.o | 60 | obj-$(CONFIG_INPUT_SIRFSOC_ONKEY) += sirfsoc-onkey.o |
61 | obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY) += soc_button_array.o | 61 | obj-$(CONFIG_INPUT_SOC_BUTTON_ARRAY) += soc_button_array.o |
62 | obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o | 62 | obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o |
63 | obj-$(CONFIG_INPUT_TPS65218_PWRBUTTON) += tps65218-pwrbutton.o | ||
63 | obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o | 64 | obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o |
64 | obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o | 65 | obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o |
65 | obj-$(CONFIG_INPUT_TWL6040_VIBRA) += twl6040-vibra.o | 66 | obj-$(CONFIG_INPUT_TWL6040_VIBRA) += twl6040-vibra.o |
diff --git a/drivers/input/misc/tps65218-pwrbutton.c b/drivers/input/misc/tps65218-pwrbutton.c new file mode 100644 index 000000000000..54508dec4eb3 --- /dev/null +++ b/drivers/input/misc/tps65218-pwrbutton.c | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | * Texas Instruments' TPS65218 Power Button Input Driver | ||
3 | * | ||
4 | * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ | ||
5 | * Author: Felipe Balbi <balbi@ti.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any | ||
12 | * kind, whether express or implied; without even the implied warranty | ||
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | */ | ||
16 | |||
17 | #include <linux/init.h> | ||
18 | #include <linux/input.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/mfd/tps65218.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/of.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/slab.h> | ||
26 | |||
27 | struct tps65218_pwrbutton { | ||
28 | struct device *dev; | ||
29 | struct tps65218 *tps; | ||
30 | struct input_dev *idev; | ||
31 | }; | ||
32 | |||
33 | static irqreturn_t tps65218_pwr_irq(int irq, void *_pwr) | ||
34 | { | ||
35 | struct tps65218_pwrbutton *pwr = _pwr; | ||
36 | unsigned int reg; | ||
37 | int error; | ||
38 | |||
39 | error = tps65218_reg_read(pwr->tps, TPS65218_REG_STATUS, ®); | ||
40 | if (error) { | ||
41 | dev_err(pwr->dev, "can't read register: %d\n", error); | ||
42 | goto out; | ||
43 | } | ||
44 | |||
45 | if (reg & TPS65218_STATUS_PB_STATE) { | ||
46 | input_report_key(pwr->idev, KEY_POWER, 1); | ||
47 | pm_wakeup_event(pwr->dev, 0); | ||
48 | } else { | ||
49 | input_report_key(pwr->idev, KEY_POWER, 0); | ||
50 | } | ||
51 | |||
52 | input_sync(pwr->idev); | ||
53 | |||
54 | out: | ||
55 | return IRQ_HANDLED; | ||
56 | } | ||
57 | |||
58 | static int tps65218_pwron_probe(struct platform_device *pdev) | ||
59 | { | ||
60 | struct tps65218 *tps = dev_get_drvdata(pdev->dev.parent); | ||
61 | struct device *dev = &pdev->dev; | ||
62 | struct tps65218_pwrbutton *pwr; | ||
63 | struct input_dev *idev; | ||
64 | int error; | ||
65 | int irq; | ||
66 | |||
67 | pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL); | ||
68 | if (!pwr) | ||
69 | return -ENOMEM; | ||
70 | |||
71 | idev = devm_input_allocate_device(dev); | ||
72 | if (!idev) | ||
73 | return -ENOMEM; | ||
74 | |||
75 | idev->name = "tps65218_pwrbutton"; | ||
76 | idev->phys = "tps65218_pwrbutton/input0"; | ||
77 | idev->dev.parent = dev; | ||
78 | idev->id.bustype = BUS_I2C; | ||
79 | |||
80 | input_set_capability(idev, EV_KEY, KEY_POWER); | ||
81 | |||
82 | pwr->tps = tps; | ||
83 | pwr->dev = dev; | ||
84 | pwr->idev = idev; | ||
85 | platform_set_drvdata(pdev, pwr); | ||
86 | device_init_wakeup(dev, true); | ||
87 | |||
88 | irq = platform_get_irq(pdev, 0); | ||
89 | error = devm_request_threaded_irq(dev, irq, NULL, tps65218_pwr_irq, | ||
90 | IRQF_TRIGGER_RISING | | ||
91 | IRQF_TRIGGER_FALLING | | ||
92 | IRQF_ONESHOT, | ||
93 | "tps65218-pwrbutton", pwr); | ||
94 | if (error) { | ||
95 | dev_err(dev, "failed to request IRQ #%d: %d\n", | ||
96 | irq, error); | ||
97 | return error; | ||
98 | } | ||
99 | |||
100 | error= input_register_device(idev); | ||
101 | if (error) { | ||
102 | dev_err(dev, "Can't register power button: %d\n", error); | ||
103 | return error; | ||
104 | } | ||
105 | |||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | static struct of_device_id of_tps65218_pwr_match[] = { | ||
110 | { .compatible = "ti,tps65218-pwrbutton" }, | ||
111 | { }, | ||
112 | }; | ||
113 | MODULE_DEVICE_TABLE(of, of_tps65218_pwr_match); | ||
114 | |||
115 | static struct platform_driver tps65218_pwron_driver = { | ||
116 | .probe = tps65218_pwron_probe, | ||
117 | .driver = { | ||
118 | .name = "tps65218_pwrbutton", | ||
119 | .of_match_table = of_tps65218_pwr_match, | ||
120 | }, | ||
121 | }; | ||
122 | module_platform_driver(tps65218_pwron_driver); | ||
123 | |||
124 | MODULE_DESCRIPTION("TPS65218 Power Button"); | ||
125 | MODULE_LICENSE("GPL v2"); | ||
126 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); | ||