]>
Commit | Line | Data |
---|---|---|
0376148f | 1 | // SPDX-License-Identifier: GPL-2.0-only |
77686517 SI |
2 | /* |
3 | * Copyright (C) ST-Ericsson SA 2010 | |
4 | * | |
77686517 SI |
5 | * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson |
6 | * | |
7 | * AB8500 Power-On Key handler | |
8 | */ | |
9 | ||
7b961d5b | 10 | #include <linux/device.h> |
77686517 SI |
11 | #include <linux/kernel.h> |
12 | #include <linux/module.h> | |
13 | #include <linux/platform_device.h> | |
14 | #include <linux/input.h> | |
15 | #include <linux/interrupt.h> | |
ee66e653 | 16 | #include <linux/mfd/abx500/ab8500.h> |
03ecd229 | 17 | #include <linux/of.h> |
77686517 SI |
18 | #include <linux/slab.h> |
19 | ||
20 | /** | |
21 | * struct ab8500_ponkey - ab8500 ponkey information | |
22 | * @input_dev: pointer to input device | |
23 | * @ab8500: ab8500 parent | |
24 | * @irq_dbf: irq number for falling transition | |
25 | * @irq_dbr: irq number for rising transition | |
26 | */ | |
27 | struct ab8500_ponkey { | |
28 | struct input_dev *idev; | |
29 | struct ab8500 *ab8500; | |
30 | int irq_dbf; | |
31 | int irq_dbr; | |
32 | }; | |
33 | ||
34 | /* AB8500 gives us an interrupt when ONKEY is held */ | |
35 | static irqreturn_t ab8500_ponkey_handler(int irq, void *data) | |
36 | { | |
37 | struct ab8500_ponkey *ponkey = data; | |
38 | ||
39 | if (irq == ponkey->irq_dbf) | |
40 | input_report_key(ponkey->idev, KEY_POWER, true); | |
41 | else if (irq == ponkey->irq_dbr) | |
42 | input_report_key(ponkey->idev, KEY_POWER, false); | |
43 | ||
44 | input_sync(ponkey->idev); | |
45 | ||
46 | return IRQ_HANDLED; | |
47 | } | |
48 | ||
5298cc4c | 49 | static int ab8500_ponkey_probe(struct platform_device *pdev) |
77686517 SI |
50 | { |
51 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); | |
52 | struct ab8500_ponkey *ponkey; | |
53 | struct input_dev *input; | |
54 | int irq_dbf, irq_dbr; | |
55 | int error; | |
56 | ||
57 | irq_dbf = platform_get_irq_byname(pdev, "ONKEY_DBF"); | |
0bec8b7e | 58 | if (irq_dbf < 0) |
77686517 | 59 | return irq_dbf; |
77686517 SI |
60 | |
61 | irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR"); | |
0bec8b7e | 62 | if (irq_dbr < 0) |
77686517 | 63 | return irq_dbr; |
77686517 | 64 | |
7b961d5b HS |
65 | ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey), |
66 | GFP_KERNEL); | |
67 | if (!ponkey) | |
68 | return -ENOMEM; | |
69 | ||
70 | input = devm_input_allocate_device(&pdev->dev); | |
71 | if (!input) | |
72 | return -ENOMEM; | |
77686517 SI |
73 | |
74 | ponkey->idev = input; | |
75 | ponkey->ab8500 = ab8500; | |
527df5fa DT |
76 | ponkey->irq_dbf = irq_dbf; |
77 | ponkey->irq_dbr = irq_dbr; | |
77686517 SI |
78 | |
79 | input->name = "AB8500 POn(PowerOn) Key"; | |
80 | input->dev.parent = &pdev->dev; | |
81 | ||
82 | input_set_capability(input, EV_KEY, KEY_POWER); | |
83 | ||
7b961d5b HS |
84 | error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf, |
85 | ab8500_ponkey_handler, 0, | |
86 | "ab8500-ponkey-dbf", ponkey); | |
77686517 SI |
87 | if (error < 0) { |
88 | dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n", | |
89 | ponkey->irq_dbf, error); | |
7b961d5b | 90 | return error; |
77686517 SI |
91 | } |
92 | ||
7b961d5b HS |
93 | error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr, |
94 | ab8500_ponkey_handler, 0, | |
95 | "ab8500-ponkey-dbr", ponkey); | |
77686517 SI |
96 | if (error < 0) { |
97 | dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n", | |
98 | ponkey->irq_dbr, error); | |
7b961d5b | 99 | return error; |
77686517 SI |
100 | } |
101 | ||
102 | error = input_register_device(ponkey->idev); | |
103 | if (error) { | |
104 | dev_err(ab8500->dev, "Can't register input device: %d\n", error); | |
7b961d5b | 105 | return error; |
77686517 SI |
106 | } |
107 | ||
77686517 | 108 | return 0; |
77686517 SI |
109 | } |
110 | ||
03ecd229 LJ |
111 | #ifdef CONFIG_OF |
112 | static const struct of_device_id ab8500_ponkey_match[] = { | |
113 | { .compatible = "stericsson,ab8500-ponkey", }, | |
114 | {} | |
115 | }; | |
e4dbe796 | 116 | MODULE_DEVICE_TABLE(of, ab8500_ponkey_match); |
03ecd229 LJ |
117 | #endif |
118 | ||
77686517 SI |
119 | static struct platform_driver ab8500_ponkey_driver = { |
120 | .driver = { | |
121 | .name = "ab8500-poweron-key", | |
03ecd229 | 122 | .of_match_table = of_match_ptr(ab8500_ponkey_match), |
77686517 SI |
123 | }, |
124 | .probe = ab8500_ponkey_probe, | |
77686517 | 125 | }; |
840a746b | 126 | module_platform_driver(ab8500_ponkey_driver); |
77686517 SI |
127 | |
128 | MODULE_LICENSE("GPL v2"); | |
129 | MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>"); | |
130 | MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver"); |