.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * lis3lv02d.c - ST LIS3LV02DL accelerometer driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2007-2008 Yan Burman |
---|
5 | 6 | * Copyright (C) 2008 Eric Piel |
---|
6 | 7 | * 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 |
---|
21 | 8 | */ |
---|
22 | 9 | |
---|
23 | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
.. | .. |
---|
29 | 16 | #include <linux/types.h> |
---|
30 | 17 | #include <linux/platform_device.h> |
---|
31 | 18 | #include <linux/interrupt.h> |
---|
32 | | -#include <linux/input-polldev.h> |
---|
| 19 | +#include <linux/input.h> |
---|
33 | 20 | #include <linux/delay.h> |
---|
34 | 21 | #include <linux/wait.h> |
---|
35 | 22 | #include <linux/poll.h> |
---|
.. | .. |
---|
455 | 442 | EXPORT_SYMBOL_GPL(lis3lv02d_poweron); |
---|
456 | 443 | |
---|
457 | 444 | |
---|
458 | | -static void lis3lv02d_joystick_poll(struct input_polled_dev *pidev) |
---|
| 445 | +static void lis3lv02d_joystick_poll(struct input_dev *input) |
---|
459 | 446 | { |
---|
460 | | - struct lis3lv02d *lis3 = pidev->private; |
---|
| 447 | + struct lis3lv02d *lis3 = input_get_drvdata(input); |
---|
461 | 448 | int x, y, z; |
---|
462 | 449 | |
---|
463 | 450 | mutex_lock(&lis3->mutex); |
---|
464 | 451 | 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); |
---|
469 | 456 | mutex_unlock(&lis3->mutex); |
---|
470 | 457 | } |
---|
471 | 458 | |
---|
472 | | -static void lis3lv02d_joystick_open(struct input_polled_dev *pidev) |
---|
| 459 | +static int lis3lv02d_joystick_open(struct input_dev *input) |
---|
473 | 460 | { |
---|
474 | | - struct lis3lv02d *lis3 = pidev->private; |
---|
| 461 | + struct lis3lv02d *lis3 = input_get_drvdata(input); |
---|
475 | 462 | |
---|
476 | 463 | if (lis3->pm_dev) |
---|
477 | 464 | pm_runtime_get_sync(lis3->pm_dev); |
---|
.. | .. |
---|
482 | 469 | * Update coordinates for the case where poll interval is 0 and |
---|
483 | 470 | * the chip in running purely under interrupt control |
---|
484 | 471 | */ |
---|
485 | | - lis3lv02d_joystick_poll(pidev); |
---|
| 472 | + lis3lv02d_joystick_poll(input); |
---|
| 473 | + |
---|
| 474 | + return 0; |
---|
486 | 475 | } |
---|
487 | 476 | |
---|
488 | | -static void lis3lv02d_joystick_close(struct input_polled_dev *pidev) |
---|
| 477 | +static void lis3lv02d_joystick_close(struct input_dev *input) |
---|
489 | 478 | { |
---|
490 | | - struct lis3lv02d *lis3 = pidev->private; |
---|
| 479 | + struct lis3lv02d *lis3 = input_get_drvdata(input); |
---|
491 | 480 | |
---|
492 | 481 | atomic_set(&lis3->wake_thread, 0); |
---|
493 | 482 | if (lis3->pm_dev) |
---|
.. | .. |
---|
518 | 507 | |
---|
519 | 508 | static void lis302dl_interrupt_handle_click(struct lis3lv02d *lis3) |
---|
520 | 509 | { |
---|
521 | | - struct input_dev *dev = lis3->idev->input; |
---|
| 510 | + struct input_dev *dev = lis3->idev; |
---|
522 | 511 | u8 click_src; |
---|
523 | 512 | |
---|
524 | 513 | mutex_lock(&lis3->mutex); |
---|
.. | .. |
---|
698 | 687 | if (lis3->idev) |
---|
699 | 688 | return -EINVAL; |
---|
700 | 689 | |
---|
701 | | - lis3->idev = input_allocate_polled_device(); |
---|
702 | | - if (!lis3->idev) |
---|
| 690 | + input_dev = input_allocate_device(); |
---|
| 691 | + if (!input_dev) |
---|
703 | 692 | 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; |
---|
713 | 693 | |
---|
714 | 694 | input_dev->name = "ST LIS3LV02DL Accelerometer"; |
---|
715 | 695 | input_dev->phys = DRIVER_NAME "/input0"; |
---|
.. | .. |
---|
717 | 697 | input_dev->id.vendor = 0; |
---|
718 | 698 | input_dev->dev.parent = &lis3->pdev->dev; |
---|
719 | 699 | |
---|
720 | | - set_bit(EV_ABS, input_dev->evbit); |
---|
| 700 | + input_dev->open = lis3lv02d_joystick_open; |
---|
| 701 | + input_dev->close = lis3lv02d_joystick_close; |
---|
| 702 | + |
---|
721 | 703 | max_val = (lis3->mdps_max_val * lis3->scale) / LIS3_ACCURACY; |
---|
722 | 704 | if (lis3->whoami == WAI_12B) { |
---|
723 | 705 | fuzz = LIS3_DEFAULT_FUZZ_12B; |
---|
.. | .. |
---|
733 | 715 | input_set_abs_params(input_dev, ABS_Y, -max_val, max_val, fuzz, flat); |
---|
734 | 716 | input_set_abs_params(input_dev, ABS_Z, -max_val, max_val, fuzz, flat); |
---|
735 | 717 | |
---|
| 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 | + |
---|
736 | 729 | lis3->mapped_btns[0] = lis3lv02d_get_axis(abs(lis3->ac.x), btns); |
---|
737 | 730 | lis3->mapped_btns[1] = lis3lv02d_get_axis(abs(lis3->ac.y), btns); |
---|
738 | 731 | lis3->mapped_btns[2] = lis3lv02d_get_axis(abs(lis3->ac.z), btns); |
---|
739 | 732 | |
---|
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; |
---|
745 | 736 | |
---|
| 737 | + return 0; |
---|
| 738 | + |
---|
| 739 | +err_free_input: |
---|
| 740 | + input_free_device(input_dev); |
---|
| 741 | + lis3->idev = NULL; |
---|
746 | 742 | return err; |
---|
| 743 | + |
---|
747 | 744 | } |
---|
748 | 745 | EXPORT_SYMBOL_GPL(lis3lv02d_joystick_enable); |
---|
749 | 746 | |
---|
.. | .. |
---|
759 | 756 | |
---|
760 | 757 | if (lis3->irq) |
---|
761 | 758 | misc_deregister(&lis3->miscdev); |
---|
762 | | - input_unregister_polled_device(lis3->idev); |
---|
763 | | - input_free_polled_device(lis3->idev); |
---|
| 759 | + input_unregister_device(lis3->idev); |
---|
764 | 760 | lis3->idev = NULL; |
---|
765 | 761 | } |
---|
766 | 762 | EXPORT_SYMBOL_GPL(lis3lv02d_joystick_disable); |
---|
.. | .. |
---|
919 | 915 | (p->click_thresh_y << 4)); |
---|
920 | 916 | |
---|
921 | 917 | 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); |
---|
926 | 921 | } |
---|
927 | 922 | } |
---|
928 | 923 | |
---|