forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/misc/lis3lv02d/lis3lv02d.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * lis3lv02d.c - ST LIS3LV02DL accelerometer driver
34 *
45 * Copyright (C) 2007-2008 Yan Burman
56 * Copyright (C) 2008 Eric Piel
67 * Copyright (C) 2008-2009 Pavel Machek
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
218 */
229
2310 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -29,7 +16,7 @@
2916 #include <linux/types.h>
3017 #include <linux/platform_device.h>
3118 #include <linux/interrupt.h>
32
-#include <linux/input-polldev.h>
19
+#include <linux/input.h>
3320 #include <linux/delay.h>
3421 #include <linux/wait.h>
3522 #include <linux/poll.h>
....@@ -455,23 +442,23 @@
455442 EXPORT_SYMBOL_GPL(lis3lv02d_poweron);
456443
457444
458
-static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev)
445
+static void lis3lv02d_joystick_poll(struct input_dev *input)
459446 {
460
- struct lis3lv02d *lis3 = pidev->private;
447
+ struct lis3lv02d *lis3 = input_get_drvdata(input);
461448 int x, y, z;
462449
463450 mutex_lock(&lis3->mutex);
464451 lis3lv02d_get_xyz(lis3, &x, &y, &z);
465
- input_report_abs(pidev->input, ABS_X, x);
466
- input_report_abs(pidev->input, ABS_Y, y);
467
- input_report_abs(pidev->input, ABS_Z, z);
468
- input_sync(pidev->input);
452
+ input_report_abs(input, ABS_X, x);
453
+ input_report_abs(input, ABS_Y, y);
454
+ input_report_abs(input, ABS_Z, z);
455
+ input_sync(input);
469456 mutex_unlock(&lis3->mutex);
470457 }
471458
472
-static void lis3lv02d_joystick_open(struct input_polled_dev *pidev)
459
+static int lis3lv02d_joystick_open(struct input_dev *input)
473460 {
474
- struct lis3lv02d *lis3 = pidev->private;
461
+ struct lis3lv02d *lis3 = input_get_drvdata(input);
475462
476463 if (lis3->pm_dev)
477464 pm_runtime_get_sync(lis3->pm_dev);
....@@ -482,12 +469,14 @@
482469 * Update coordinates for the case where poll interval is 0 and
483470 * the chip in running purely under interrupt control
484471 */
485
- lis3lv02d_joystick_poll(pidev);
472
+ lis3lv02d_joystick_poll(input);
473
+
474
+ return 0;
486475 }
487476
488
-static void lis3lv02d_joystick_close(struct input_polled_dev *pidev)
477
+static void lis3lv02d_joystick_close(struct input_dev *input)
489478 {
490
- struct lis3lv02d *lis3 = pidev->private;
479
+ struct lis3lv02d *lis3 = input_get_drvdata(input);
491480
492481 atomic_set(&lis3->wake_thread, 0);
493482 if (lis3->pm_dev)
....@@ -518,7 +507,7 @@
518507
519508 static void lis302dl_interrupt_handle_click(struct lis3lv02d *lis3)
520509 {
521
- struct input_dev *dev = lis3->idev->input;
510
+ struct input_dev *dev = lis3->idev;
522511 u8 click_src;
523512
524513 mutex_lock(&lis3->mutex);
....@@ -698,18 +687,9 @@
698687 if (lis3->idev)
699688 return -EINVAL;
700689
701
- lis3->idev = input_allocate_polled_device();
702
- if (!lis3->idev)
690
+ input_dev = input_allocate_device();
691
+ if (!input_dev)
703692 return -ENOMEM;
704
-
705
- lis3->idev->poll = lis3lv02d_joystick_poll;
706
- lis3->idev->open = lis3lv02d_joystick_open;
707
- lis3->idev->close = lis3lv02d_joystick_close;
708
- lis3->idev->poll_interval = MDPS_POLL_INTERVAL;
709
- lis3->idev->poll_interval_min = MDPS_POLL_MIN;
710
- lis3->idev->poll_interval_max = MDPS_POLL_MAX;
711
- lis3->idev->private = lis3;
712
- input_dev = lis3->idev->input;
713693
714694 input_dev->name = "ST LIS3LV02DL Accelerometer";
715695 input_dev->phys = DRIVER_NAME "/input0";
....@@ -717,7 +697,9 @@
717697 input_dev->id.vendor = 0;
718698 input_dev->dev.parent = &lis3->pdev->dev;
719699
720
- set_bit(EV_ABS, input_dev->evbit);
700
+ input_dev->open = lis3lv02d_joystick_open;
701
+ input_dev->close = lis3lv02d_joystick_close;
702
+
721703 max_val = (lis3->mdps_max_val * lis3->scale) / LIS3_ACCURACY;
722704 if (lis3->whoami == WAI_12B) {
723705 fuzz = LIS3_DEFAULT_FUZZ_12B;
....@@ -733,17 +715,32 @@
733715 input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat);
734716 input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat);
735717
718
+ input_set_drvdata(input_dev, lis3);
719
+ lis3->idev = input_dev;
720
+
721
+ err = input_setup_polling(input_dev, lis3lv02d_joystick_poll);
722
+ if (err)
723
+ goto err_free_input;
724
+
725
+ input_set_poll_interval(input_dev, MDPS_POLL_INTERVAL);
726
+ input_set_min_poll_interval(input_dev, MDPS_POLL_MIN);
727
+ input_set_max_poll_interval(input_dev, MDPS_POLL_MAX);
728
+
736729 lis3->mapped_btns[0] = lis3lv02d_get_axis(abs(lis3->ac.x), btns);
737730 lis3->mapped_btns[1] = lis3lv02d_get_axis(abs(lis3->ac.y), btns);
738731 lis3->mapped_btns[2] = lis3lv02d_get_axis(abs(lis3->ac.z), btns);
739732
740
- err = input_register_polled_device(lis3->idev);
741
- if (err) {
742
- input_free_polled_device(lis3->idev);
743
- lis3->idev = NULL;
744
- }
733
+ err = input_register_device(lis3->idev);
734
+ if (err)
735
+ goto err_free_input;
745736
737
+ return 0;
738
+
739
+err_free_input:
740
+ input_free_device(input_dev);
741
+ lis3->idev = NULL;
746742 return err;
743
+
747744 }
748745 EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable);
749746
....@@ -759,8 +756,7 @@
759756
760757 if (lis3->irq)
761758 misc_deregister(&lis3->miscdev);
762
- input_unregister_polled_device(lis3->idev);
763
- input_free_polled_device(lis3->idev);
759
+ input_unregister_device(lis3->idev);
764760 lis3->idev = NULL;
765761 }
766762 EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable);
....@@ -919,10 +915,9 @@
919915 (p->click_thresh_y << 4));
920916
921917 if (lis3->idev) {
922
- struct input_dev *input_dev = lis3->idev->input;
923
- input_set_capability(input_dev, EV_KEY, BTN_X);
924
- input_set_capability(input_dev, EV_KEY, BTN_Y);
925
- input_set_capability(input_dev, EV_KEY, BTN_Z);
918
+ input_set_capability(lis3->idev, EV_KEY, BTN_X);
919
+ input_set_capability(lis3->idev, EV_KEY, BTN_Y);
920
+ input_set_capability(lis3->idev, EV_KEY, BTN_Z);
926921 }
927922 }
928923