HWMON: hdaps - switch to using input-polldev

Switch to using input-polldev skeleton instead of implementing polling loop
by itself.  This also fixes problem with trylock on a mutex in atomic
context.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
This commit is contained in:
Dmitry Torokhov 2007-10-12 21:30:36 -04:00 committed by Dmitry Torokhov
parent b981d8b3f5
commit aefca8ba5f
2 changed files with 25 additions and 31 deletions

View File

@ -645,6 +645,7 @@ config SENSORS_W83627EHF
config SENSORS_HDAPS config SENSORS_HDAPS
tristate "IBM Hard Drive Active Protection System (hdaps)" tristate "IBM Hard Drive Active Protection System (hdaps)"
depends on INPUT && X86 depends on INPUT && X86
select INPUT_POLLDEV
default n default n
help help
This driver provides support for the IBM Hard Drive Active Protection This driver provides support for the IBM Hard Drive Active Protection

View File

@ -28,7 +28,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/input.h> #include <linux/input-polldev.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/module.h> #include <linux/module.h>
@ -61,13 +61,12 @@
#define INIT_TIMEOUT_MSECS 4000 /* wait up to 4s for device init ... */ #define INIT_TIMEOUT_MSECS 4000 /* wait up to 4s for device init ... */
#define INIT_WAIT_MSECS 200 /* ... in 200ms increments */ #define INIT_WAIT_MSECS 200 /* ... in 200ms increments */
#define HDAPS_POLL_PERIOD (HZ/20) /* poll for input every 1/20s */ #define HDAPS_POLL_INTERVAL 50 /* poll for input every 1/20s (50 ms)*/
#define HDAPS_INPUT_FUZZ 4 /* input event threshold */ #define HDAPS_INPUT_FUZZ 4 /* input event threshold */
#define HDAPS_INPUT_FLAT 4 #define HDAPS_INPUT_FLAT 4
static struct timer_list hdaps_timer;
static struct platform_device *pdev; static struct platform_device *pdev;
static struct input_dev *hdaps_idev; static struct input_polled_dev *hdaps_idev;
static unsigned int hdaps_invert; static unsigned int hdaps_invert;
static u8 km_activity; static u8 km_activity;
static int rest_x; static int rest_x;
@ -323,24 +322,19 @@ static void hdaps_calibrate(void)
__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &rest_x, &rest_y); __hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &rest_x, &rest_y);
} }
static void hdaps_mousedev_poll(unsigned long unused) static void hdaps_mousedev_poll(struct input_polled_dev *dev)
{ {
struct input_dev *input_dev = dev->input;
int x, y; int x, y;
/* Cannot sleep. Try nonblockingly. If we fail, try again later. */ mutex_lock(&hdaps_mtx);
if (mutex_trylock(&hdaps_mtx)) {
mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
return;
}
if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y)) if (__hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y))
goto out; goto out;
input_report_abs(hdaps_idev, ABS_X, x - rest_x); input_report_abs(input_dev, ABS_X, x - rest_x);
input_report_abs(hdaps_idev, ABS_Y, y - rest_y); input_report_abs(input_dev, ABS_Y, y - rest_y);
input_sync(hdaps_idev); input_sync(input_dev);
mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
out: out:
mutex_unlock(&hdaps_mtx); mutex_unlock(&hdaps_mtx);
@ -536,6 +530,7 @@ static struct dmi_system_id __initdata hdaps_whitelist[] = {
static int __init hdaps_init(void) static int __init hdaps_init(void)
{ {
struct input_dev *idev;
int ret; int ret;
if (!dmi_check_system(hdaps_whitelist)) { if (!dmi_check_system(hdaps_whitelist)) {
@ -563,39 +558,37 @@ static int __init hdaps_init(void)
if (ret) if (ret)
goto out_device; goto out_device;
hdaps_idev = input_allocate_device(); hdaps_idev = input_allocate_polled_device();
if (!hdaps_idev) { if (!hdaps_idev) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_group; goto out_group;
} }
hdaps_idev->poll = hdaps_mousedev_poll;
hdaps_idev->poll_interval = HDAPS_POLL_INTERVAL;
/* initial calibrate for the input device */ /* initial calibrate for the input device */
hdaps_calibrate(); hdaps_calibrate();
/* initialize the input class */ /* initialize the input class */
hdaps_idev->name = "hdaps"; idev = hdaps_idev->input;
hdaps_idev->dev.parent = &pdev->dev; idev->name = "hdaps";
hdaps_idev->evbit[0] = BIT(EV_ABS); idev->dev.parent = &pdev->dev;
input_set_abs_params(hdaps_idev, ABS_X, idev->evbit[0] = BIT(EV_ABS);
input_set_abs_params(idev, ABS_X,
-256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
input_set_abs_params(hdaps_idev, ABS_Y, input_set_abs_params(idev, ABS_Y,
-256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
ret = input_register_device(hdaps_idev); ret = input_register_polled_device(hdaps_idev);
if (ret) if (ret)
goto out_idev; goto out_idev;
/* start up our timer for the input device */
init_timer(&hdaps_timer);
hdaps_timer.function = hdaps_mousedev_poll;
hdaps_timer.expires = jiffies + HDAPS_POLL_PERIOD;
add_timer(&hdaps_timer);
printk(KERN_INFO "hdaps: driver successfully loaded.\n"); printk(KERN_INFO "hdaps: driver successfully loaded.\n");
return 0; return 0;
out_idev: out_idev:
input_free_device(hdaps_idev); input_free_polled_device(hdaps_idev);
out_group: out_group:
sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group); sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
out_device: out_device:
@ -611,8 +604,8 @@ static int __init hdaps_init(void)
static void __exit hdaps_exit(void) static void __exit hdaps_exit(void)
{ {
del_timer_sync(&hdaps_timer); input_unregister_polled_device(hdaps_idev);
input_unregister_device(hdaps_idev); input_free_polled_device(hdaps_idev);
sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group); sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
platform_device_unregister(pdev); platform_device_unregister(pdev);
platform_driver_unregister(&hdaps_driver); platform_driver_unregister(&hdaps_driver);