| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Wistron laptop button driver |
|---|
| 3 | 4 | * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> |
|---|
| 4 | 5 | * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org> |
|---|
| 5 | 6 | * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru> |
|---|
| 6 | | - * |
|---|
| 7 | | - * You can redistribute and/or modify this program under the terms of the |
|---|
| 8 | | - * GNU General Public License version 2 as published by the Free Software |
|---|
| 9 | | - * Foundation. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 12 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|---|
| 14 | | - * Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License along |
|---|
| 17 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 18 | | - * 59 Temple Place Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | 7 | */ |
|---|
| 20 | 8 | #include <linux/io.h> |
|---|
| 21 | 9 | #include <linux/dmi.h> |
|---|
| 22 | 10 | #include <linux/init.h> |
|---|
| 23 | | -#include <linux/input-polldev.h> |
|---|
| 11 | +#include <linux/input.h> |
|---|
| 24 | 12 | #include <linux/input/sparse-keymap.h> |
|---|
| 25 | 13 | #include <linux/interrupt.h> |
|---|
| 26 | 14 | #include <linux/jiffies.h> |
|---|
| .. | .. |
|---|
| 1042 | 1030 | |
|---|
| 1043 | 1031 | /* Input layer interface */ |
|---|
| 1044 | 1032 | |
|---|
| 1045 | | -static struct input_polled_dev *wistron_idev; |
|---|
| 1033 | +static struct input_dev *wistron_idev; |
|---|
| 1046 | 1034 | static unsigned long jiffies_last_press; |
|---|
| 1047 | 1035 | static bool wifi_enabled; |
|---|
| 1048 | 1036 | static bool bluetooth_enabled; |
|---|
| .. | .. |
|---|
| 1126 | 1114 | static void handle_key(u8 code) |
|---|
| 1127 | 1115 | { |
|---|
| 1128 | 1116 | const struct key_entry *key = |
|---|
| 1129 | | - sparse_keymap_entry_from_scancode(wistron_idev->input, code); |
|---|
| 1117 | + sparse_keymap_entry_from_scancode(wistron_idev, code); |
|---|
| 1130 | 1118 | |
|---|
| 1131 | 1119 | if (key) { |
|---|
| 1132 | 1120 | switch (key->type) { |
|---|
| .. | .. |
|---|
| 1145 | 1133 | break; |
|---|
| 1146 | 1134 | |
|---|
| 1147 | 1135 | default: |
|---|
| 1148 | | - sparse_keymap_report_entry(wistron_idev->input, |
|---|
| 1149 | | - key, 1, true); |
|---|
| 1136 | + sparse_keymap_report_entry(wistron_idev, key, 1, true); |
|---|
| 1150 | 1137 | break; |
|---|
| 1151 | 1138 | } |
|---|
| 1152 | 1139 | jiffies_last_press = jiffies; |
|---|
| 1153 | | - } else |
|---|
| 1140 | + } else { |
|---|
| 1154 | 1141 | printk(KERN_NOTICE |
|---|
| 1155 | 1142 | "wistron_btns: Unknown key code %02X\n", code); |
|---|
| 1143 | + } |
|---|
| 1156 | 1144 | } |
|---|
| 1157 | 1145 | |
|---|
| 1158 | 1146 | static void poll_bios(bool discard) |
|---|
| .. | .. |
|---|
| 1170 | 1158 | } |
|---|
| 1171 | 1159 | } |
|---|
| 1172 | 1160 | |
|---|
| 1173 | | -static void wistron_flush(struct input_polled_dev *dev) |
|---|
| 1161 | +static int wistron_flush(struct input_dev *dev) |
|---|
| 1174 | 1162 | { |
|---|
| 1175 | 1163 | /* Flush stale event queue */ |
|---|
| 1176 | 1164 | poll_bios(true); |
|---|
| 1165 | + |
|---|
| 1166 | + return 0; |
|---|
| 1177 | 1167 | } |
|---|
| 1178 | 1168 | |
|---|
| 1179 | | -static void wistron_poll(struct input_polled_dev *dev) |
|---|
| 1169 | +static void wistron_poll(struct input_dev *dev) |
|---|
| 1180 | 1170 | { |
|---|
| 1181 | 1171 | poll_bios(false); |
|---|
| 1182 | 1172 | |
|---|
| 1183 | 1173 | /* Increase poll frequency if user is currently pressing keys (< 2s ago) */ |
|---|
| 1184 | 1174 | if (time_before(jiffies, jiffies_last_press + 2 * HZ)) |
|---|
| 1185 | | - dev->poll_interval = POLL_INTERVAL_BURST; |
|---|
| 1175 | + input_set_poll_interval(dev, POLL_INTERVAL_BURST); |
|---|
| 1186 | 1176 | else |
|---|
| 1187 | | - dev->poll_interval = POLL_INTERVAL_DEFAULT; |
|---|
| 1177 | + input_set_poll_interval(dev, POLL_INTERVAL_DEFAULT); |
|---|
| 1188 | 1178 | } |
|---|
| 1189 | 1179 | |
|---|
| 1190 | 1180 | static int wistron_setup_keymap(struct input_dev *dev, |
|---|
| .. | .. |
|---|
| 1220 | 1210 | |
|---|
| 1221 | 1211 | static int setup_input_dev(void) |
|---|
| 1222 | 1212 | { |
|---|
| 1223 | | - struct input_dev *input_dev; |
|---|
| 1224 | 1213 | int error; |
|---|
| 1225 | 1214 | |
|---|
| 1226 | | - wistron_idev = input_allocate_polled_device(); |
|---|
| 1215 | + wistron_idev = input_allocate_device(); |
|---|
| 1227 | 1216 | if (!wistron_idev) |
|---|
| 1228 | 1217 | return -ENOMEM; |
|---|
| 1229 | 1218 | |
|---|
| 1219 | + wistron_idev->name = "Wistron laptop buttons"; |
|---|
| 1220 | + wistron_idev->phys = "wistron/input0"; |
|---|
| 1221 | + wistron_idev->id.bustype = BUS_HOST; |
|---|
| 1222 | + wistron_idev->dev.parent = &wistron_device->dev; |
|---|
| 1223 | + |
|---|
| 1230 | 1224 | wistron_idev->open = wistron_flush; |
|---|
| 1231 | | - wistron_idev->poll = wistron_poll; |
|---|
| 1232 | | - wistron_idev->poll_interval = POLL_INTERVAL_DEFAULT; |
|---|
| 1233 | 1225 | |
|---|
| 1234 | | - input_dev = wistron_idev->input; |
|---|
| 1235 | | - input_dev->name = "Wistron laptop buttons"; |
|---|
| 1236 | | - input_dev->phys = "wistron/input0"; |
|---|
| 1237 | | - input_dev->id.bustype = BUS_HOST; |
|---|
| 1238 | | - input_dev->dev.parent = &wistron_device->dev; |
|---|
| 1239 | | - |
|---|
| 1240 | | - error = sparse_keymap_setup(input_dev, keymap, wistron_setup_keymap); |
|---|
| 1226 | + error = sparse_keymap_setup(wistron_idev, keymap, wistron_setup_keymap); |
|---|
| 1241 | 1227 | if (error) |
|---|
| 1242 | 1228 | goto err_free_dev; |
|---|
| 1243 | 1229 | |
|---|
| 1244 | | - error = input_register_polled_device(wistron_idev); |
|---|
| 1230 | + error = input_setup_polling(wistron_idev, wistron_poll); |
|---|
| 1231 | + if (error) |
|---|
| 1232 | + goto err_free_dev; |
|---|
| 1233 | + |
|---|
| 1234 | + input_set_poll_interval(wistron_idev, POLL_INTERVAL_DEFAULT); |
|---|
| 1235 | + |
|---|
| 1236 | + error = input_register_device(wistron_idev); |
|---|
| 1245 | 1237 | if (error) |
|---|
| 1246 | 1238 | goto err_free_dev; |
|---|
| 1247 | 1239 | |
|---|
| 1248 | 1240 | return 0; |
|---|
| 1249 | 1241 | |
|---|
| 1250 | 1242 | err_free_dev: |
|---|
| 1251 | | - input_free_polled_device(wistron_idev); |
|---|
| 1243 | + input_free_device(wistron_idev); |
|---|
| 1252 | 1244 | return error; |
|---|
| 1253 | 1245 | } |
|---|
| 1254 | 1246 | |
|---|
| .. | .. |
|---|
| 1297 | 1289 | static int wistron_remove(struct platform_device *dev) |
|---|
| 1298 | 1290 | { |
|---|
| 1299 | 1291 | wistron_led_remove(); |
|---|
| 1300 | | - input_unregister_polled_device(wistron_idev); |
|---|
| 1301 | | - input_free_polled_device(wistron_idev); |
|---|
| 1292 | + input_unregister_device(wistron_idev); |
|---|
| 1302 | 1293 | bios_detach(); |
|---|
| 1303 | 1294 | |
|---|
| 1304 | 1295 | return 0; |
|---|