| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for simulating a mouse on GPIO lines. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2007 Atmel Corporation |
|---|
| 5 | 6 | * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #include <linux/module.h> |
|---|
| 13 | 10 | #include <linux/platform_device.h> |
|---|
| 14 | | -#include <linux/input-polldev.h> |
|---|
| 11 | +#include <linux/input.h> |
|---|
| 15 | 12 | #include <linux/gpio/consumer.h> |
|---|
| 16 | 13 | #include <linux/property.h> |
|---|
| 17 | 14 | #include <linux/of.h> |
|---|
| .. | .. |
|---|
| 46 | 43 | * Timer function which is run every scan_ms ms when the device is opened. |
|---|
| 47 | 44 | * The dev input variable is set to the the input_dev pointer. |
|---|
| 48 | 45 | */ |
|---|
| 49 | | -static void gpio_mouse_scan(struct input_polled_dev *dev) |
|---|
| 46 | +static void gpio_mouse_scan(struct input_dev *input) |
|---|
| 50 | 47 | { |
|---|
| 51 | | - struct gpio_mouse *gpio = dev->private; |
|---|
| 52 | | - struct input_dev *input = dev->input; |
|---|
| 48 | + struct gpio_mouse *gpio = input_get_drvdata(input); |
|---|
| 53 | 49 | int x, y; |
|---|
| 54 | 50 | |
|---|
| 55 | 51 | if (gpio->bleft) |
|---|
| .. | .. |
|---|
| 74 | 70 | { |
|---|
| 75 | 71 | struct device *dev = &pdev->dev; |
|---|
| 76 | 72 | struct gpio_mouse *gmouse; |
|---|
| 77 | | - struct input_polled_dev *input_poll; |
|---|
| 78 | 73 | struct input_dev *input; |
|---|
| 79 | | - int ret; |
|---|
| 74 | + int error; |
|---|
| 80 | 75 | |
|---|
| 81 | 76 | gmouse = devm_kzalloc(dev, sizeof(*gmouse), GFP_KERNEL); |
|---|
| 82 | 77 | if (!gmouse) |
|---|
| 83 | 78 | return -ENOMEM; |
|---|
| 84 | 79 | |
|---|
| 85 | 80 | /* Assign some default scanning time */ |
|---|
| 86 | | - ret = device_property_read_u32(dev, "scan-interval-ms", |
|---|
| 87 | | - &gmouse->scan_ms); |
|---|
| 88 | | - if (ret || gmouse->scan_ms == 0) { |
|---|
| 81 | + error = device_property_read_u32(dev, "scan-interval-ms", |
|---|
| 82 | + &gmouse->scan_ms); |
|---|
| 83 | + if (error || gmouse->scan_ms == 0) { |
|---|
| 89 | 84 | dev_warn(dev, "invalid scan time, set to 50 ms\n"); |
|---|
| 90 | 85 | gmouse->scan_ms = 50; |
|---|
| 91 | 86 | } |
|---|
| .. | .. |
|---|
| 115 | 110 | if (IS_ERR(gmouse->bright)) |
|---|
| 116 | 111 | return PTR_ERR(gmouse->bright); |
|---|
| 117 | 112 | |
|---|
| 118 | | - input_poll = devm_input_allocate_polled_device(dev); |
|---|
| 119 | | - if (!input_poll) { |
|---|
| 120 | | - dev_err(dev, "not enough memory for input device\n"); |
|---|
| 113 | + input = devm_input_allocate_device(dev); |
|---|
| 114 | + if (!input) |
|---|
| 121 | 115 | return -ENOMEM; |
|---|
| 122 | | - } |
|---|
| 123 | 116 | |
|---|
| 124 | | - platform_set_drvdata(pdev, input_poll); |
|---|
| 125 | | - |
|---|
| 126 | | - /* set input-polldev handlers */ |
|---|
| 127 | | - input_poll->private = gmouse; |
|---|
| 128 | | - input_poll->poll = gpio_mouse_scan; |
|---|
| 129 | | - input_poll->poll_interval = gmouse->scan_ms; |
|---|
| 130 | | - |
|---|
| 131 | | - input = input_poll->input; |
|---|
| 132 | 117 | input->name = pdev->name; |
|---|
| 133 | 118 | input->id.bustype = BUS_HOST; |
|---|
| 134 | | - input->dev.parent = &pdev->dev; |
|---|
| 119 | + |
|---|
| 120 | + input_set_drvdata(input, gmouse); |
|---|
| 135 | 121 | |
|---|
| 136 | 122 | input_set_capability(input, EV_REL, REL_X); |
|---|
| 137 | 123 | input_set_capability(input, EV_REL, REL_Y); |
|---|
| .. | .. |
|---|
| 142 | 128 | if (gmouse->bright) |
|---|
| 143 | 129 | input_set_capability(input, EV_KEY, BTN_RIGHT); |
|---|
| 144 | 130 | |
|---|
| 145 | | - ret = input_register_polled_device(input_poll); |
|---|
| 146 | | - if (ret) { |
|---|
| 131 | + error = input_setup_polling(input, gpio_mouse_scan); |
|---|
| 132 | + if (error) |
|---|
| 133 | + return error; |
|---|
| 134 | + |
|---|
| 135 | + input_set_poll_interval(input, gmouse->scan_ms); |
|---|
| 136 | + |
|---|
| 137 | + error = input_register_device(input); |
|---|
| 138 | + if (error) { |
|---|
| 147 | 139 | dev_err(dev, "could not register input device\n"); |
|---|
| 148 | | - return ret; |
|---|
| 140 | + return error; |
|---|
| 149 | 141 | } |
|---|
| 150 | 142 | |
|---|
| 151 | 143 | dev_dbg(dev, "%d ms scan time, buttons: %s%s%s\n", |
|---|