hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/input/joystick/psxpad-spi.c
....@@ -1,8 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * PlayStation 1/2 joypads via SPI interface Driver
34 *
45 * Copyright (C) 2017 Tomohiro Yoshidomi <sylph23k@gmail.com>
5
- * Licensed under the GPL-2 or later.
66 *
77 * PlayStation 1/2 joypad's plug (not socket)
88 * 123 456 789
....@@ -22,7 +22,6 @@
2222 #include <linux/kernel.h>
2323 #include <linux/device.h>
2424 #include <linux/input.h>
25
-#include <linux/input-polldev.h>
2625 #include <linux/module.h>
2726 #include <linux/spi/spi.h>
2827 #include <linux/types.h>
....@@ -60,7 +59,7 @@
6059
6160 struct psxpad {
6261 struct spi_device *spi;
63
- struct input_polled_dev *pdev;
62
+ struct input_dev *idev;
6463 char phys[0x20];
6564 bool motor1enable;
6665 bool motor2enable;
....@@ -140,8 +139,7 @@
140139 static int psxpad_spi_play_effect(struct input_dev *idev,
141140 void *data, struct ff_effect *effect)
142141 {
143
- struct input_polled_dev *pdev = input_get_drvdata(idev);
144
- struct psxpad *pad = pdev->private;
142
+ struct psxpad *pad = input_get_drvdata(idev);
145143
146144 switch (effect->type) {
147145 case FF_RUMBLE:
....@@ -158,10 +156,9 @@
158156 {
159157 int err;
160158
161
- input_set_capability(pad->pdev->input, EV_FF, FF_RUMBLE);
159
+ input_set_capability(pad->idev, EV_FF, FF_RUMBLE);
162160
163
- err = input_ff_create_memless(pad->pdev->input, NULL,
164
- psxpad_spi_play_effect);
161
+ err = input_ff_create_memless(pad->idev, NULL, psxpad_spi_play_effect);
165162 if (err) {
166163 dev_err(&pad->spi->dev,
167164 "input_ff_create_memless() failed: %d\n", err);
....@@ -189,24 +186,25 @@
189186 }
190187 #endif /* CONFIG_JOYSTICK_PSXPAD_SPI_FF */
191188
192
-static void psxpad_spi_poll_open(struct input_polled_dev *pdev)
189
+static int psxpad_spi_poll_open(struct input_dev *input)
193190 {
194
- struct psxpad *pad = pdev->private;
191
+ struct psxpad *pad = input_get_drvdata(input);
195192
196193 pm_runtime_get_sync(&pad->spi->dev);
194
+
195
+ return 0;
197196 }
198197
199
-static void psxpad_spi_poll_close(struct input_polled_dev *pdev)
198
+static void psxpad_spi_poll_close(struct input_dev *input)
200199 {
201
- struct psxpad *pad = pdev->private;
200
+ struct psxpad *pad = input_get_drvdata(input);
202201
203202 pm_runtime_put_sync(&pad->spi->dev);
204203 }
205204
206
-static void psxpad_spi_poll(struct input_polled_dev *pdev)
205
+static void psxpad_spi_poll(struct input_dev *input)
207206 {
208
- struct psxpad *pad = pdev->private;
209
- struct input_dev *input = pdev->input;
207
+ struct psxpad *pad = input_get_drvdata(input);
210208 u8 b_rsp3, b_rsp4;
211209 int err;
212210
....@@ -284,7 +282,6 @@
284282 static int psxpad_spi_probe(struct spi_device *spi)
285283 {
286284 struct psxpad *pad;
287
- struct input_polled_dev *pdev;
288285 struct input_dev *idev;
289286 int err;
290287
....@@ -292,30 +289,25 @@
292289 if (!pad)
293290 return -ENOMEM;
294291
295
- pdev = devm_input_allocate_polled_device(&spi->dev);
296
- if (!pdev) {
292
+ idev = devm_input_allocate_device(&spi->dev);
293
+ if (!idev) {
297294 dev_err(&spi->dev, "failed to allocate input device\n");
298295 return -ENOMEM;
299296 }
300297
301298 /* input poll device settings */
302
- pad->pdev = pdev;
299
+ pad->idev = idev;
303300 pad->spi = spi;
304301
305
- pdev->private = pad;
306
- pdev->open = psxpad_spi_poll_open;
307
- pdev->close = psxpad_spi_poll_close;
308
- pdev->poll = psxpad_spi_poll;
309
- /* poll interval is about 60fps */
310
- pdev->poll_interval = 16;
311
- pdev->poll_interval_min = 8;
312
- pdev->poll_interval_max = 32;
313
-
314302 /* input device settings */
315
- idev = pdev->input;
303
+ input_set_drvdata(idev, pad);
304
+
316305 idev->name = "PlayStation 1/2 joypad";
317306 snprintf(pad->phys, sizeof(pad->phys), "%s/input", dev_name(&spi->dev));
318307 idev->id.bustype = BUS_SPI;
308
+
309
+ idev->open = psxpad_spi_poll_open;
310
+ idev->close = psxpad_spi_poll_close;
319311
320312 /* key/value map settings */
321313 input_set_abs_params(idev, ABS_X, 0, 255, 0, 0);
....@@ -354,11 +346,23 @@
354346 /* pad settings */
355347 psxpad_set_motor_level(pad, 0, 0);
356348
349
+
350
+ err = input_setup_polling(idev, psxpad_spi_poll);
351
+ if (err) {
352
+ dev_err(&spi->dev, "failed to set up polling: %d\n", err);
353
+ return err;
354
+ }
355
+
356
+ /* poll interval is about 60fps */
357
+ input_set_poll_interval(idev, 16);
358
+ input_set_min_poll_interval(idev, 8);
359
+ input_set_max_poll_interval(idev, 32);
360
+
357361 /* register input poll device */
358
- err = input_register_polled_device(pdev);
362
+ err = input_register_device(idev);
359363 if (err) {
360364 dev_err(&spi->dev,
361
- "failed to register input poll device: %d\n", err);
365
+ "failed to register input device: %d\n", err);
362366 return err;
363367 }
364368