hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/input/sensors/hall/mh248.c
....@@ -1,19 +1,10 @@
1
- /*
2
- * drivers/input/sensors/hall/mh248.c
1
+// SPDX-License-Identifier: GPL-2.0
2
+/*
3
+ * Copyright (c) 2020 Rockchip Electronics Co. Ltd.
34 *
4
- * Copyright (C) 2012-2016 Rockchip Co.,Ltd.
55 * Author: Bin Yang <yangbin@rock-chips.com>
6
- *
7
- * This software is licensed under the terms of the GNU General Public
8
- * License version 2, as published by the Free Software Foundation, and
9
- * may be copied, distributed, and modified under those terms.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
166 */
7
+
178
189 #include <linux/platform_device.h>
1910 #include <linux/interrupt.h>
....@@ -33,11 +24,13 @@
3324 #include <linux/fb.h>
3425 #include <linux/notifier.h>
3526 #include <linux/rk_keys.h>
27
+#include <linux/input.h>
3628
3729 struct mh248_para {
3830 struct device *dev;
3931 struct notifier_block fb_notif;
4032 struct mutex ops_lock;
33
+ struct input_dev *hall_input;
4134 int is_suspend;
4235 int gpio_pin;
4336 int irq;
....@@ -52,23 +45,17 @@
5245
5346 mh248 = container_of(self, struct mh248_para, fb_notif);
5447
48
+ if (action != FB_EVENT_BLANK)
49
+ return NOTIFY_DONE;
50
+
5551 mutex_lock(&mh248->ops_lock);
56
- if (action == FB_EARLY_EVENT_BLANK) {
57
- switch (*((int *)event->data)) {
58
- case FB_BLANK_UNBLANK:
59
- break;
60
- default:
61
- mh248->is_suspend = 1;
62
- break;
63
- }
64
- } else if (action == FB_EVENT_BLANK) {
65
- switch (*((int *)event->data)) {
66
- case FB_BLANK_UNBLANK:
67
- mh248->is_suspend = 0;
68
- break;
69
- default:
70
- break;
71
- }
52
+ switch (*((int *)event->data)) {
53
+ case FB_BLANK_UNBLANK:
54
+ mh248->is_suspend = 0;
55
+ break;
56
+ default:
57
+ mh248->is_suspend = 1;
58
+ break;
7259 }
7360 mutex_unlock(&mh248->ops_lock);
7461
....@@ -81,14 +68,18 @@
8168 int gpio_value = 0;
8269
8370 gpio_value = gpio_get_value(mh248->gpio_pin);
84
-
8571 if ((gpio_value != mh248->active_value) &&
8672 (mh248->is_suspend == 0)) {
87
- rk_send_power_key(1);
88
- rk_send_power_key(0);
73
+ input_report_key(mh248->hall_input, KEY_POWER, 1);
74
+ input_sync(mh248->hall_input);
75
+ input_report_key(mh248->hall_input, KEY_POWER, 0);
76
+ input_sync(mh248->hall_input);
8977 } else if ((gpio_value == mh248->active_value) &&
9078 (mh248->is_suspend == 1)) {
91
- rk_send_wakeup_key();
79
+ input_report_key(mh248->hall_input, KEY_WAKEUP, 1);
80
+ input_sync(mh248->hall_input);
81
+ input_report_key(mh248->hall_input, KEY_WAKEUP, 0);
82
+ input_sync(mh248->hall_input);
9283 }
9384
9485 return IRQ_HANDLED;
....@@ -100,7 +91,6 @@
10091 struct mh248_para *mh248;
10192 enum of_gpio_flags irq_flags;
10293 int hallactive = 0;
103
- int gpio_value = 0;
10494 int ret = 0;
10595
10696 mh248 = devm_kzalloc(&pdev->dev, sizeof(*mh248), GFP_KERNEL);
....@@ -110,7 +100,7 @@
110100 mh248->dev = &pdev->dev;
111101
112102 mh248->gpio_pin = of_get_named_gpio_flags(np, "irq-gpio",
113
- 0, &irq_flags);
103
+ 0, &irq_flags);
114104 if (!gpio_is_valid(mh248->gpio_pin)) {
115105 dev_err(mh248->dev, "Can not read property irq-gpio\n");
116106 return mh248->gpio_pin;
....@@ -125,11 +115,9 @@
125115 ret = devm_gpio_request_one(mh248->dev, mh248->gpio_pin,
126116 GPIOF_DIR_IN, "hall_mh248");
127117 if (ret < 0) {
128
- dev_err(mh248->dev, "fail to request gpio:%d\n",
129
- mh248->gpio_pin);
118
+ dev_err(mh248->dev, "fail to request gpio:%d\n", mh248->gpio_pin);
130119 return ret;
131120 }
132
- gpio_value = gpio_get_value(mh248->gpio_pin);
133121
134122 ret = devm_request_threaded_irq(mh248->dev, mh248->irq,
135123 NULL, hall_mh248_interrupt,
....@@ -141,6 +129,21 @@
141129 return ret;
142130 }
143131
132
+ mh248->hall_input = devm_input_allocate_device(&pdev->dev);
133
+ if (!mh248->hall_input) {
134
+ dev_err(&pdev->dev, "Can't allocate hall input dev\n");
135
+ return -ENOMEM;
136
+ }
137
+ mh248->hall_input->name = "hall wake key";
138
+ input_set_capability(mh248->hall_input, EV_KEY, KEY_POWER);
139
+ input_set_capability(mh248->hall_input, EV_KEY, KEY_WAKEUP);
140
+
141
+ ret = input_register_device(mh248->hall_input);
142
+ if (ret) {
143
+ dev_err(&pdev->dev, "Unable to register input device, error: %d\n", ret);
144
+ return ret;
145
+ }
146
+
144147 enable_irq_wake(mh248->irq);
145148 mh248->fb_notif.notifier_call = hall_fb_notifier_callback;
146149 fb_register_client(&mh248->fb_notif);