aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/applesmc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/applesmc.c')
-rw-r--r--drivers/hwmon/applesmc.c83
1 files changed, 30 insertions, 53 deletions
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index fd1281f4220..eb81a6430fe 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -28,7 +28,7 @@
28 28
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/input.h> 31#include <linux/input-polldev.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/timer.h> 34#include <linux/timer.h>
@@ -59,9 +59,9 @@
59 59
60#define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6 bytes) */ 60#define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6 bytes) */
61#define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6 bytes) */ 61#define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6 bytes) */
62#define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */ 62#define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */
63 63
64#define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */ 64#define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */
65 65
66#define MOTION_SENSOR_X_KEY "MO_X" /* r-o sp78 (2 bytes) */ 66#define MOTION_SENSOR_X_KEY "MO_X" /* r-o sp78 (2 bytes) */
67#define MOTION_SENSOR_Y_KEY "MO_Y" /* r-o sp78 (2 bytes) */ 67#define MOTION_SENSOR_Y_KEY "MO_Y" /* r-o sp78 (2 bytes) */
@@ -99,7 +99,7 @@ static const char* fan_speed_keys[] = {
99#define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */ 99#define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */
100#define INIT_WAIT_MSECS 50 /* ... in 50ms increments */ 100#define INIT_WAIT_MSECS 50 /* ... in 50ms increments */
101 101
102#define APPLESMC_POLL_PERIOD (HZ/20) /* poll for input every 1/20s */ 102#define APPLESMC_POLL_INTERVAL 50 /* msecs */
103#define APPLESMC_INPUT_FUZZ 4 /* input event threshold */ 103#define APPLESMC_INPUT_FUZZ 4 /* input event threshold */
104#define APPLESMC_INPUT_FLAT 4 104#define APPLESMC_INPUT_FLAT 4
105 105
@@ -121,8 +121,7 @@ static const int debug;
121static struct platform_device *pdev; 121static struct platform_device *pdev;
122static s16 rest_x; 122static s16 rest_x;
123static s16 rest_y; 123static s16 rest_y;
124static struct timer_list applesmc_timer; 124static struct input_polled_dev *applesmc_idev;
125static struct input_dev *applesmc_idev;
126static struct class_device *hwmon_class_dev; 125static struct class_device *hwmon_class_dev;
127 126
128/* Indicates whether this computer has an accelerometer. */ 127/* Indicates whether this computer has an accelerometer. */
@@ -134,7 +133,7 @@ static unsigned int applesmc_light;
134/* Indicates which temperature sensors set to use. */ 133/* Indicates which temperature sensors set to use. */
135static unsigned int applesmc_temperature_set; 134static unsigned int applesmc_temperature_set;
136 135
137static struct mutex applesmc_lock; 136static DEFINE_MUTEX(applesmc_lock);
138 137
139/* 138/*
140 * Last index written to key_at_index sysfs file, and value to use for all other 139 * Last index written to key_at_index sysfs file, and value to use for all other
@@ -451,27 +450,12 @@ static void applesmc_calibrate(void)
451 rest_x = -rest_x; 450 rest_x = -rest_x;
452} 451}
453 452
454static int applesmc_idev_open(struct input_dev *dev) 453static void applesmc_idev_poll(struct input_polled_dev *dev)
455{
456 add_timer(&applesmc_timer);
457
458 return 0;
459}
460
461static void applesmc_idev_close(struct input_dev *dev)
462{
463 del_timer_sync(&applesmc_timer);
464}
465
466static void applesmc_idev_poll(unsigned long unused)
467{ 454{
455 struct input_dev *idev = dev->input;
468 s16 x, y; 456 s16 x, y;
469 457
470 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ 458 mutex_lock(&applesmc_lock);
471 if (!mutex_trylock(&applesmc_lock)) {
472 mod_timer(&applesmc_timer, jiffies + APPLESMC_POLL_PERIOD);
473 return;
474 }
475 459
476 if (applesmc_read_motion_sensor(SENSOR_X, &x)) 460 if (applesmc_read_motion_sensor(SENSOR_X, &x))
477 goto out; 461 goto out;
@@ -479,13 +463,11 @@ static void applesmc_idev_poll(unsigned long unused)
479 goto out; 463 goto out;
480 464
481 x = -x; 465 x = -x;
482 input_report_abs(applesmc_idev, ABS_X, x - rest_x); 466 input_report_abs(idev, ABS_X, x - rest_x);
483 input_report_abs(applesmc_idev, ABS_Y, y - rest_y); 467 input_report_abs(idev, ABS_Y, y - rest_y);
484 input_sync(applesmc_idev); 468 input_sync(idev);
485 469
486out: 470out:
487 mod_timer(&applesmc_timer, jiffies + APPLESMC_POLL_PERIOD);
488
489 mutex_unlock(&applesmc_lock); 471 mutex_unlock(&applesmc_lock);
490} 472}
491 473
@@ -817,8 +799,7 @@ static ssize_t applesmc_key_at_index_read_show(struct device *dev,
817 799
818 if (!ret) { 800 if (!ret) {
819 return info[0]; 801 return info[0];
820 } 802 } else {
821 else {
822 return ret; 803 return ret;
823 } 804 }
824} 805}
@@ -1089,6 +1070,7 @@ static int applesmc_dmi_match(struct dmi_system_id *id)
1089/* Create accelerometer ressources */ 1070/* Create accelerometer ressources */
1090static int applesmc_create_accelerometer(void) 1071static int applesmc_create_accelerometer(void)
1091{ 1072{
1073 struct input_dev *idev;
1092 int ret; 1074 int ret;
1093 1075
1094 ret = sysfs_create_group(&pdev->dev.kobj, 1076 ret = sysfs_create_group(&pdev->dev.kobj,
@@ -1096,40 +1078,37 @@ static int applesmc_create_accelerometer(void)
1096 if (ret) 1078 if (ret)
1097 goto out; 1079 goto out;
1098 1080
1099 applesmc_idev = input_allocate_device(); 1081 applesmc_idev = input_allocate_polled_device();
1100 if (!applesmc_idev) { 1082 if (!applesmc_idev) {
1101 ret = -ENOMEM; 1083 ret = -ENOMEM;
1102 goto out_sysfs; 1084 goto out_sysfs;
1103 } 1085 }
1104 1086
1087 applesmc_idev->poll = applesmc_idev_poll;
1088 applesmc_idev->poll_interval = APPLESMC_POLL_INTERVAL;
1089
1105 /* initial calibrate for the input device */ 1090 /* initial calibrate for the input device */
1106 applesmc_calibrate(); 1091 applesmc_calibrate();
1107 1092
1108 /* initialize the input class */ 1093 /* initialize the input device */
1109 applesmc_idev->name = "applesmc"; 1094 idev = applesmc_idev->input;
1110 applesmc_idev->id.bustype = BUS_HOST; 1095 idev->name = "applesmc";
1111 applesmc_idev->dev.parent = &pdev->dev; 1096 idev->id.bustype = BUS_HOST;
1112 applesmc_idev->evbit[0] = BIT(EV_ABS); 1097 idev->dev.parent = &pdev->dev;
1113 applesmc_idev->open = applesmc_idev_open; 1098 idev->evbit[0] = BIT(EV_ABS);
1114 applesmc_idev->close = applesmc_idev_close; 1099 input_set_abs_params(idev, ABS_X,
1115 input_set_abs_params(applesmc_idev, ABS_X,
1116 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT); 1100 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT);
1117 input_set_abs_params(applesmc_idev, ABS_Y, 1101 input_set_abs_params(idev, ABS_Y,
1118 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT); 1102 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT);
1119 1103
1120 ret = input_register_device(applesmc_idev); 1104 ret = input_register_polled_device(applesmc_idev);
1121 if (ret) 1105 if (ret)
1122 goto out_idev; 1106 goto out_idev;
1123 1107
1124 /* start up our timer for the input device */
1125 init_timer(&applesmc_timer);
1126 applesmc_timer.function = applesmc_idev_poll;
1127 applesmc_timer.expires = jiffies + APPLESMC_POLL_PERIOD;
1128
1129 return 0; 1108 return 0;
1130 1109
1131out_idev: 1110out_idev:
1132 input_free_device(applesmc_idev); 1111 input_free_polled_device(applesmc_idev);
1133 1112
1134out_sysfs: 1113out_sysfs:
1135 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); 1114 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group);
@@ -1142,8 +1121,8 @@ out:
1142/* Release all ressources used by the accelerometer */ 1121/* Release all ressources used by the accelerometer */
1143static void applesmc_release_accelerometer(void) 1122static void applesmc_release_accelerometer(void)
1144{ 1123{
1145 del_timer_sync(&applesmc_timer); 1124 input_unregister_polled_device(applesmc_idev);
1146 input_unregister_device(applesmc_idev); 1125 input_free_polled_device(applesmc_idev);
1147 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); 1126 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group);
1148} 1127}
1149 1128
@@ -1180,8 +1159,6 @@ static int __init applesmc_init(void)
1180 int count; 1159 int count;
1181 int i; 1160 int i;
1182 1161
1183 mutex_init(&applesmc_lock);
1184
1185 if (!dmi_check_system(applesmc_whitelist)) { 1162 if (!dmi_check_system(applesmc_whitelist)) {
1186 printk(KERN_WARNING "applesmc: supported laptop not found!\n"); 1163 printk(KERN_WARNING "applesmc: supported laptop not found!\n");
1187 ret = -ENODEV; 1164 ret = -ENODEV;