.. | .. |
---|
1 | | - /* |
---|
2 | | - * drivers/input/sensors/hall/mh248.c |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
| 2 | +/* |
---|
| 3 | + * Copyright (c) 2020 Rockchip Electronics Co. Ltd. |
---|
3 | 4 | * |
---|
4 | | - * Copyright (C) 2012-2016 Rockchip Co.,Ltd. |
---|
5 | 5 | * 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 | | - * |
---|
16 | 6 | */ |
---|
| 7 | + |
---|
17 | 8 | |
---|
18 | 9 | #include <linux/platform_device.h> |
---|
19 | 10 | #include <linux/interrupt.h> |
---|
.. | .. |
---|
33 | 24 | #include <linux/fb.h> |
---|
34 | 25 | #include <linux/notifier.h> |
---|
35 | 26 | #include <linux/rk_keys.h> |
---|
| 27 | +#include <linux/input.h> |
---|
36 | 28 | |
---|
37 | 29 | struct mh248_para { |
---|
38 | 30 | struct device *dev; |
---|
39 | 31 | struct notifier_block fb_notif; |
---|
40 | 32 | struct mutex ops_lock; |
---|
| 33 | + struct input_dev *hall_input; |
---|
41 | 34 | int is_suspend; |
---|
42 | 35 | int gpio_pin; |
---|
43 | 36 | int irq; |
---|
.. | .. |
---|
52 | 45 | |
---|
53 | 46 | mh248 = container_of(self, struct mh248_para, fb_notif); |
---|
54 | 47 | |
---|
| 48 | + if (action != FB_EVENT_BLANK) |
---|
| 49 | + return NOTIFY_DONE; |
---|
| 50 | + |
---|
55 | 51 | 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; |
---|
72 | 59 | } |
---|
73 | 60 | mutex_unlock(&mh248->ops_lock); |
---|
74 | 61 | |
---|
.. | .. |
---|
81 | 68 | int gpio_value = 0; |
---|
82 | 69 | |
---|
83 | 70 | gpio_value = gpio_get_value(mh248->gpio_pin); |
---|
84 | | - |
---|
85 | 71 | if ((gpio_value != mh248->active_value) && |
---|
86 | 72 | (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); |
---|
89 | 77 | } else if ((gpio_value == mh248->active_value) && |
---|
90 | 78 | (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); |
---|
92 | 83 | } |
---|
93 | 84 | |
---|
94 | 85 | return IRQ_HANDLED; |
---|
.. | .. |
---|
100 | 91 | struct mh248_para *mh248; |
---|
101 | 92 | enum of_gpio_flags irq_flags; |
---|
102 | 93 | int hallactive = 0; |
---|
103 | | - int gpio_value = 0; |
---|
104 | 94 | int ret = 0; |
---|
105 | 95 | |
---|
106 | 96 | mh248 = devm_kzalloc(&pdev->dev, sizeof(*mh248), GFP_KERNEL); |
---|
.. | .. |
---|
110 | 100 | mh248->dev = &pdev->dev; |
---|
111 | 101 | |
---|
112 | 102 | mh248->gpio_pin = of_get_named_gpio_flags(np, "irq-gpio", |
---|
113 | | - 0, &irq_flags); |
---|
| 103 | + 0, &irq_flags); |
---|
114 | 104 | if (!gpio_is_valid(mh248->gpio_pin)) { |
---|
115 | 105 | dev_err(mh248->dev, "Can not read property irq-gpio\n"); |
---|
116 | 106 | return mh248->gpio_pin; |
---|
.. | .. |
---|
125 | 115 | ret = devm_gpio_request_one(mh248->dev, mh248->gpio_pin, |
---|
126 | 116 | GPIOF_DIR_IN, "hall_mh248"); |
---|
127 | 117 | 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); |
---|
130 | 119 | return ret; |
---|
131 | 120 | } |
---|
132 | | - gpio_value = gpio_get_value(mh248->gpio_pin); |
---|
133 | 121 | |
---|
134 | 122 | ret = devm_request_threaded_irq(mh248->dev, mh248->irq, |
---|
135 | 123 | NULL, hall_mh248_interrupt, |
---|
.. | .. |
---|
141 | 129 | return ret; |
---|
142 | 130 | } |
---|
143 | 131 | |
---|
| 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 | + |
---|
144 | 147 | enable_irq_wake(mh248->irq); |
---|
145 | 148 | mh248->fb_notif.notifier_call = hall_fb_notifier_callback; |
---|
146 | 149 | fb_register_client(&mh248->fb_notif); |
---|