diff options
Diffstat (limited to 'drivers/hwmon/applesmc.c')
-rw-r--r-- | drivers/hwmon/applesmc.c | 83 |
1 files changed, 30 insertions, 53 deletions
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index f37fd7ebf65a..4879125b4cdc 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) */ |
@@ -103,7 +103,7 @@ static const char* fan_speed_keys[] = { | |||
103 | #define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */ | 103 | #define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */ |
104 | #define INIT_WAIT_MSECS 50 /* ... in 50ms increments */ | 104 | #define INIT_WAIT_MSECS 50 /* ... in 50ms increments */ |
105 | 105 | ||
106 | #define APPLESMC_POLL_PERIOD (HZ/20) /* poll for input every 1/20s */ | 106 | #define APPLESMC_POLL_INTERVAL 50 /* msecs */ |
107 | #define APPLESMC_INPUT_FUZZ 4 /* input event threshold */ | 107 | #define APPLESMC_INPUT_FUZZ 4 /* input event threshold */ |
108 | #define APPLESMC_INPUT_FLAT 4 | 108 | #define APPLESMC_INPUT_FLAT 4 |
109 | 109 | ||
@@ -125,9 +125,8 @@ static const int debug; | |||
125 | static struct platform_device *pdev; | 125 | static struct platform_device *pdev; |
126 | static s16 rest_x; | 126 | static s16 rest_x; |
127 | static s16 rest_y; | 127 | static s16 rest_y; |
128 | static struct timer_list applesmc_timer; | ||
129 | static struct input_dev *applesmc_idev; | ||
130 | static struct device *hwmon_dev; | 128 | static struct device *hwmon_dev; |
129 | static struct input_polled_dev *applesmc_idev; | ||
131 | 130 | ||
132 | /* Indicates whether this computer has an accelerometer. */ | 131 | /* Indicates whether this computer has an accelerometer. */ |
133 | static unsigned int applesmc_accelerometer; | 132 | static unsigned int applesmc_accelerometer; |
@@ -138,7 +137,7 @@ static unsigned int applesmc_light; | |||
138 | /* Indicates which temperature sensors set to use. */ | 137 | /* Indicates which temperature sensors set to use. */ |
139 | static unsigned int applesmc_temperature_set; | 138 | static unsigned int applesmc_temperature_set; |
140 | 139 | ||
141 | static struct mutex applesmc_lock; | 140 | static DEFINE_MUTEX(applesmc_lock); |
142 | 141 | ||
143 | /* | 142 | /* |
144 | * Last index written to key_at_index sysfs file, and value to use for all other | 143 | * Last index written to key_at_index sysfs file, and value to use for all other |
@@ -455,27 +454,12 @@ static void applesmc_calibrate(void) | |||
455 | rest_x = -rest_x; | 454 | rest_x = -rest_x; |
456 | } | 455 | } |
457 | 456 | ||
458 | static int applesmc_idev_open(struct input_dev *dev) | 457 | static void applesmc_idev_poll(struct input_polled_dev *dev) |
459 | { | ||
460 | add_timer(&applesmc_timer); | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | static void applesmc_idev_close(struct input_dev *dev) | ||
466 | { | ||
467 | del_timer_sync(&applesmc_timer); | ||
468 | } | ||
469 | |||
470 | static void applesmc_idev_poll(unsigned long unused) | ||
471 | { | 458 | { |
459 | struct input_dev *idev = dev->input; | ||
472 | s16 x, y; | 460 | s16 x, y; |
473 | 461 | ||
474 | /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ | 462 | mutex_lock(&applesmc_lock); |
475 | if (!mutex_trylock(&applesmc_lock)) { | ||
476 | mod_timer(&applesmc_timer, jiffies + APPLESMC_POLL_PERIOD); | ||
477 | return; | ||
478 | } | ||
479 | 463 | ||
480 | if (applesmc_read_motion_sensor(SENSOR_X, &x)) | 464 | if (applesmc_read_motion_sensor(SENSOR_X, &x)) |
481 | goto out; | 465 | goto out; |
@@ -483,13 +467,11 @@ static void applesmc_idev_poll(unsigned long unused) | |||
483 | goto out; | 467 | goto out; |
484 | 468 | ||
485 | x = -x; | 469 | x = -x; |
486 | input_report_abs(applesmc_idev, ABS_X, x - rest_x); | 470 | input_report_abs(idev, ABS_X, x - rest_x); |
487 | input_report_abs(applesmc_idev, ABS_Y, y - rest_y); | 471 | input_report_abs(idev, ABS_Y, y - rest_y); |
488 | input_sync(applesmc_idev); | 472 | input_sync(idev); |
489 | 473 | ||
490 | out: | 474 | out: |
491 | mod_timer(&applesmc_timer, jiffies + APPLESMC_POLL_PERIOD); | ||
492 | |||
493 | mutex_unlock(&applesmc_lock); | 475 | mutex_unlock(&applesmc_lock); |
494 | } | 476 | } |
495 | 477 | ||
@@ -821,8 +803,7 @@ static ssize_t applesmc_key_at_index_read_show(struct device *dev, | |||
821 | 803 | ||
822 | if (!ret) { | 804 | if (!ret) { |
823 | return info[0]; | 805 | return info[0]; |
824 | } | 806 | } else { |
825 | else { | ||
826 | return ret; | 807 | return ret; |
827 | } | 808 | } |
828 | } | 809 | } |
@@ -1093,6 +1074,7 @@ static int applesmc_dmi_match(const struct dmi_system_id *id) | |||
1093 | /* Create accelerometer ressources */ | 1074 | /* Create accelerometer ressources */ |
1094 | static int applesmc_create_accelerometer(void) | 1075 | static int applesmc_create_accelerometer(void) |
1095 | { | 1076 | { |
1077 | struct input_dev *idev; | ||
1096 | int ret; | 1078 | int ret; |
1097 | 1079 | ||
1098 | ret = sysfs_create_group(&pdev->dev.kobj, | 1080 | ret = sysfs_create_group(&pdev->dev.kobj, |
@@ -1100,40 +1082,37 @@ static int applesmc_create_accelerometer(void) | |||
1100 | if (ret) | 1082 | if (ret) |
1101 | goto out; | 1083 | goto out; |
1102 | 1084 | ||
1103 | applesmc_idev = input_allocate_device(); | 1085 | applesmc_idev = input_allocate_polled_device(); |
1104 | if (!applesmc_idev) { | 1086 | if (!applesmc_idev) { |
1105 | ret = -ENOMEM; | 1087 | ret = -ENOMEM; |
1106 | goto out_sysfs; | 1088 | goto out_sysfs; |
1107 | } | 1089 | } |
1108 | 1090 | ||
1091 | applesmc_idev->poll = applesmc_idev_poll; | ||
1092 | applesmc_idev->poll_interval = APPLESMC_POLL_INTERVAL; | ||
1093 | |||
1109 | /* initial calibrate for the input device */ | 1094 | /* initial calibrate for the input device */ |
1110 | applesmc_calibrate(); | 1095 | applesmc_calibrate(); |
1111 | 1096 | ||
1112 | /* initialize the input class */ | 1097 | /* initialize the input device */ |
1113 | applesmc_idev->name = "applesmc"; | 1098 | idev = applesmc_idev->input; |
1114 | applesmc_idev->id.bustype = BUS_HOST; | 1099 | idev->name = "applesmc"; |
1115 | applesmc_idev->dev.parent = &pdev->dev; | 1100 | idev->id.bustype = BUS_HOST; |
1116 | applesmc_idev->evbit[0] = BIT(EV_ABS); | 1101 | idev->dev.parent = &pdev->dev; |
1117 | applesmc_idev->open = applesmc_idev_open; | 1102 | idev->evbit[0] = BIT(EV_ABS); |
1118 | applesmc_idev->close = applesmc_idev_close; | 1103 | input_set_abs_params(idev, ABS_X, |
1119 | input_set_abs_params(applesmc_idev, ABS_X, | ||
1120 | -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT); | 1104 | -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT); |
1121 | input_set_abs_params(applesmc_idev, ABS_Y, | 1105 | input_set_abs_params(idev, ABS_Y, |
1122 | -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT); | 1106 | -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT); |
1123 | 1107 | ||
1124 | ret = input_register_device(applesmc_idev); | 1108 | ret = input_register_polled_device(applesmc_idev); |
1125 | if (ret) | 1109 | if (ret) |
1126 | goto out_idev; | 1110 | goto out_idev; |
1127 | 1111 | ||
1128 | /* start up our timer for the input device */ | ||
1129 | init_timer(&applesmc_timer); | ||
1130 | applesmc_timer.function = applesmc_idev_poll; | ||
1131 | applesmc_timer.expires = jiffies + APPLESMC_POLL_PERIOD; | ||
1132 | |||
1133 | return 0; | 1112 | return 0; |
1134 | 1113 | ||
1135 | out_idev: | 1114 | out_idev: |
1136 | input_free_device(applesmc_idev); | 1115 | input_free_polled_device(applesmc_idev); |
1137 | 1116 | ||
1138 | out_sysfs: | 1117 | out_sysfs: |
1139 | sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); | 1118 | sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); |
@@ -1146,8 +1125,8 @@ out: | |||
1146 | /* Release all ressources used by the accelerometer */ | 1125 | /* Release all ressources used by the accelerometer */ |
1147 | static void applesmc_release_accelerometer(void) | 1126 | static void applesmc_release_accelerometer(void) |
1148 | { | 1127 | { |
1149 | del_timer_sync(&applesmc_timer); | 1128 | input_unregister_polled_device(applesmc_idev); |
1150 | input_unregister_device(applesmc_idev); | 1129 | input_free_polled_device(applesmc_idev); |
1151 | sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); | 1130 | sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); |
1152 | } | 1131 | } |
1153 | 1132 | ||
@@ -1184,8 +1163,6 @@ static int __init applesmc_init(void) | |||
1184 | int count; | 1163 | int count; |
1185 | int i; | 1164 | int i; |
1186 | 1165 | ||
1187 | mutex_init(&applesmc_lock); | ||
1188 | |||
1189 | if (!dmi_check_system(applesmc_whitelist)) { | 1166 | if (!dmi_check_system(applesmc_whitelist)) { |
1190 | printk(KERN_WARNING "applesmc: supported laptop not found!\n"); | 1167 | printk(KERN_WARNING "applesmc: supported laptop not found!\n"); |
1191 | ret = -ENODEV; | 1168 | ret = -ENODEV; |