Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HWMON: applesmc - convert to use 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>

+31 -53
+1
drivers/hwmon/Kconfig
··· 623 623 depends on INPUT && X86 624 624 select NEW_LEDS 625 625 select LEDS_CLASS 626 + select INPUT_POLLDEV 626 627 default n 627 628 help 628 629 This driver provides support for the Apple System Management
+30 -53
drivers/hwmon/applesmc.c
··· 28 28 29 29 #include <linux/delay.h> 30 30 #include <linux/platform_device.h> 31 - #include <linux/input.h> 31 + #include <linux/input-polldev.h> 32 32 #include <linux/kernel.h> 33 33 #include <linux/module.h> 34 34 #include <linux/timer.h> ··· 59 59 60 60 #define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6 bytes) */ 61 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 66 #define MOTION_SENSOR_X_KEY "MO_X" /* r-o sp78 (2 bytes) */ 67 67 #define MOTION_SENSOR_Y_KEY "MO_Y" /* r-o sp78 (2 bytes) */ ··· 99 99 #define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */ 100 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 103 #define APPLESMC_INPUT_FUZZ 4 /* input event threshold */ 104 104 #define APPLESMC_INPUT_FLAT 4 105 105 ··· 121 121 static struct platform_device *pdev; 122 122 static s16 rest_x; 123 123 static s16 rest_y; 124 - static struct timer_list applesmc_timer; 125 - static struct input_dev *applesmc_idev; 124 + static struct input_polled_dev *applesmc_idev; 126 125 static struct class_device *hwmon_class_dev; 127 126 128 127 /* Indicates whether this computer has an accelerometer. */ ··· 133 134 /* Indicates which temperature sensors set to use. */ 134 135 static unsigned int applesmc_temperature_set; 135 136 136 - static struct mutex applesmc_lock; 137 + static DEFINE_MUTEX(applesmc_lock); 137 138 138 139 /* 139 140 * Last index written to key_at_index sysfs file, and value to use for all other ··· 450 451 rest_x = -rest_x; 451 452 } 452 453 453 - static int applesmc_idev_open(struct input_dev *dev) 454 + static void applesmc_idev_poll(struct input_polled_dev *dev) 454 455 { 455 - add_timer(&applesmc_timer); 456 - 457 - return 0; 458 - } 459 - 460 - static void applesmc_idev_close(struct input_dev *dev) 461 - { 462 - del_timer_sync(&applesmc_timer); 463 - } 464 - 465 - static void applesmc_idev_poll(unsigned long unused) 466 - { 456 + struct input_dev *idev = dev->input; 467 457 s16 x, y; 468 458 469 - /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ 470 - if (!mutex_trylock(&applesmc_lock)) { 471 - mod_timer(&applesmc_timer, jiffies + APPLESMC_POLL_PERIOD); 472 - return; 473 - } 459 + mutex_lock(&applesmc_lock); 474 460 475 461 if (applesmc_read_motion_sensor(SENSOR_X, &x)) 476 462 goto out; ··· 463 479 goto out; 464 480 465 481 x = -x; 466 - input_report_abs(applesmc_idev, ABS_X, x - rest_x); 467 - input_report_abs(applesmc_idev, ABS_Y, y - rest_y); 468 - input_sync(applesmc_idev); 482 + input_report_abs(idev, ABS_X, x - rest_x); 483 + input_report_abs(idev, ABS_Y, y - rest_y); 484 + input_sync(idev); 469 485 470 486 out: 471 - mod_timer(&applesmc_timer, jiffies + APPLESMC_POLL_PERIOD); 472 - 473 487 mutex_unlock(&applesmc_lock); 474 488 } 475 489 ··· 799 817 800 818 if (!ret) { 801 819 return info[0]; 802 - } 803 - else { 820 + } else { 804 821 return ret; 805 822 } 806 823 } ··· 1070 1089 /* Create accelerometer ressources */ 1071 1090 static int applesmc_create_accelerometer(void) 1072 1091 { 1092 + struct input_dev *idev; 1073 1093 int ret; 1074 1094 1075 1095 ret = sysfs_create_group(&pdev->dev.kobj, ··· 1078 1096 if (ret) 1079 1097 goto out; 1080 1098 1081 - applesmc_idev = input_allocate_device(); 1099 + applesmc_idev = input_allocate_polled_device(); 1082 1100 if (!applesmc_idev) { 1083 1101 ret = -ENOMEM; 1084 1102 goto out_sysfs; 1085 1103 } 1086 1104 1105 + applesmc_idev->poll = applesmc_idev_poll; 1106 + applesmc_idev->poll_interval = APPLESMC_POLL_INTERVAL; 1107 + 1087 1108 /* initial calibrate for the input device */ 1088 1109 applesmc_calibrate(); 1089 1110 1090 - /* initialize the input class */ 1091 - applesmc_idev->name = "applesmc"; 1092 - applesmc_idev->id.bustype = BUS_HOST; 1093 - applesmc_idev->dev.parent = &pdev->dev; 1094 - applesmc_idev->evbit[0] = BIT(EV_ABS); 1095 - applesmc_idev->open = applesmc_idev_open; 1096 - applesmc_idev->close = applesmc_idev_close; 1097 - input_set_abs_params(applesmc_idev, ABS_X, 1111 + /* initialize the input device */ 1112 + idev = applesmc_idev->input; 1113 + idev->name = "applesmc"; 1114 + idev->id.bustype = BUS_HOST; 1115 + idev->dev.parent = &pdev->dev; 1116 + idev->evbit[0] = BIT(EV_ABS); 1117 + input_set_abs_params(idev, ABS_X, 1098 1118 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT); 1099 - input_set_abs_params(applesmc_idev, ABS_Y, 1119 + input_set_abs_params(idev, ABS_Y, 1100 1120 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT); 1101 1121 1102 - ret = input_register_device(applesmc_idev); 1122 + ret = input_register_polled_device(applesmc_idev); 1103 1123 if (ret) 1104 1124 goto out_idev; 1105 - 1106 - /* start up our timer for the input device */ 1107 - init_timer(&applesmc_timer); 1108 - applesmc_timer.function = applesmc_idev_poll; 1109 - applesmc_timer.expires = jiffies + APPLESMC_POLL_PERIOD; 1110 1125 1111 1126 return 0; 1112 1127 1113 1128 out_idev: 1114 - input_free_device(applesmc_idev); 1129 + input_free_polled_device(applesmc_idev); 1115 1130 1116 1131 out_sysfs: 1117 1132 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); ··· 1121 1142 /* Release all ressources used by the accelerometer */ 1122 1143 static void applesmc_release_accelerometer(void) 1123 1144 { 1124 - del_timer_sync(&applesmc_timer); 1125 - input_unregister_device(applesmc_idev); 1145 + input_unregister_polled_device(applesmc_idev); 1146 + input_free_polled_device(applesmc_idev); 1126 1147 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); 1127 1148 } 1128 1149 ··· 1158 1179 int ret; 1159 1180 int count; 1160 1181 int i; 1161 - 1162 - mutex_init(&applesmc_lock); 1163 1182 1164 1183 if (!dmi_check_system(applesmc_whitelist)) { 1165 1184 printk(KERN_WARNING "applesmc: supported laptop not found!\n");