aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/input.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2010-01-23 01:45:46 -0500
committerDavid S. Miller <davem@davemloft.net>2010-01-23 01:45:46 -0500
commit6be325719b3e54624397e413efd4b33a997e55a3 (patch)
tree57f321a56794cab2222e179b16731e0d76a4a68a /drivers/input/input.c
parent26d92f9276a56d55511a427fb70bd70886af647a (diff)
parent92dcffb916d309aa01778bf8963a6932e4014d07 (diff)
Merge branch 'master' of /home/davem/src/GIT/linux-2.6/
Diffstat (limited to 'drivers/input/input.c')
-rw-r--r--drivers/input/input.c96
1 files changed, 79 insertions, 17 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 5c16001959cc..30b503b8d67b 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -24,6 +24,7 @@
24#include <linux/mutex.h> 24#include <linux/mutex.h>
25#include <linux/rcupdate.h> 25#include <linux/rcupdate.h>
26#include <linux/smp_lock.h> 26#include <linux/smp_lock.h>
27#include "input-compat.h"
27 28
28MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 29MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
29MODULE_DESCRIPTION("Input core"); 30MODULE_DESCRIPTION("Input core");
@@ -296,9 +297,15 @@ static void input_handle_event(struct input_dev *dev,
296 * @value: value of the event 297 * @value: value of the event
297 * 298 *
298 * This function should be used by drivers implementing various input 299 * This function should be used by drivers implementing various input
299 * devices. See also input_inject_event(). 300 * devices to report input events. See also input_inject_event().
301 *
302 * NOTE: input_event() may be safely used right after input device was
303 * allocated with input_allocate_device(), even before it is registered
304 * with input_register_device(), but the event will not reach any of the
305 * input handlers. Such early invocation of input_event() may be used
306 * to 'seed' initial state of a switch or initial position of absolute
307 * axis, etc.
300 */ 308 */
301
302void input_event(struct input_dev *dev, 309void input_event(struct input_dev *dev,
303 unsigned int type, unsigned int code, int value) 310 unsigned int type, unsigned int code, int value)
304{ 311{
@@ -758,6 +765,40 @@ static int input_attach_handler(struct input_dev *dev, struct input_handler *han
758 return error; 765 return error;
759} 766}
760 767
768#ifdef CONFIG_COMPAT
769
770static int input_bits_to_string(char *buf, int buf_size,
771 unsigned long bits, bool skip_empty)
772{
773 int len = 0;
774
775 if (INPUT_COMPAT_TEST) {
776 u32 dword = bits >> 32;
777 if (dword || !skip_empty)
778 len += snprintf(buf, buf_size, "%x ", dword);
779
780 dword = bits & 0xffffffffUL;
781 if (dword || !skip_empty || len)
782 len += snprintf(buf + len, max(buf_size - len, 0),
783 "%x", dword);
784 } else {
785 if (bits || !skip_empty)
786 len += snprintf(buf, buf_size, "%lx", bits);
787 }
788
789 return len;
790}
791
792#else /* !CONFIG_COMPAT */
793
794static int input_bits_to_string(char *buf, int buf_size,
795 unsigned long bits, bool skip_empty)
796{
797 return bits || !skip_empty ?
798 snprintf(buf, buf_size, "%lx", bits) : 0;
799}
800
801#endif
761 802
762#ifdef CONFIG_PROC_FS 803#ifdef CONFIG_PROC_FS
763 804
@@ -826,14 +867,25 @@ static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
826 unsigned long *bitmap, int max) 867 unsigned long *bitmap, int max)
827{ 868{
828 int i; 869 int i;
829 870 bool skip_empty = true;
830 for (i = BITS_TO_LONGS(max) - 1; i > 0; i--) 871 char buf[18];
831 if (bitmap[i])
832 break;
833 872
834 seq_printf(seq, "B: %s=", name); 873 seq_printf(seq, "B: %s=", name);
835 for (; i >= 0; i--) 874
836 seq_printf(seq, "%lx%s", bitmap[i], i > 0 ? " " : ""); 875 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
876 if (input_bits_to_string(buf, sizeof(buf),
877 bitmap[i], skip_empty)) {
878 skip_empty = false;
879 seq_printf(seq, "%s%s", buf, i > 0 ? " " : "");
880 }
881 }
882
883 /*
884 * If no output was produced print a single 0.
885 */
886 if (skip_empty)
887 seq_puts(seq, "0");
888
837 seq_putc(seq, '\n'); 889 seq_putc(seq, '\n');
838} 890}
839 891
@@ -1122,14 +1174,23 @@ static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
1122{ 1174{
1123 int i; 1175 int i;
1124 int len = 0; 1176 int len = 0;
1177 bool skip_empty = true;
1178
1179 for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
1180 len += input_bits_to_string(buf + len, max(buf_size - len, 0),
1181 bitmap[i], skip_empty);
1182 if (len) {
1183 skip_empty = false;
1184 if (i > 0)
1185 len += snprintf(buf + len, max(buf_size - len, 0), " ");
1186 }
1187 }
1125 1188
1126 for (i = BITS_TO_LONGS(max) - 1; i > 0; i--) 1189 /*
1127 if (bitmap[i]) 1190 * If no output was produced print a single 0.
1128 break; 1191 */
1129 1192 if (len == 0)
1130 for (; i >= 0; i--) 1193 len = snprintf(buf, buf_size, "%d", 0);
1131 len += snprintf(buf + len, max(buf_size - len, 0),
1132 "%lx%s", bitmap[i], i > 0 ? " " : "");
1133 1194
1134 if (add_cr) 1195 if (add_cr)
1135 len += snprintf(buf + len, max(buf_size - len, 0), "\n"); 1196 len += snprintf(buf + len, max(buf_size - len, 0), "\n");
@@ -1144,7 +1205,8 @@ static ssize_t input_dev_show_cap_##bm(struct device *dev, \
1144{ \ 1205{ \
1145 struct input_dev *input_dev = to_input_dev(dev); \ 1206 struct input_dev *input_dev = to_input_dev(dev); \
1146 int len = input_print_bitmap(buf, PAGE_SIZE, \ 1207 int len = input_print_bitmap(buf, PAGE_SIZE, \
1147 input_dev->bm##bit, ev##_MAX, 1); \ 1208 input_dev->bm##bit, ev##_MAX, \
1209 true); \
1148 return min_t(int, len, PAGE_SIZE); \ 1210 return min_t(int, len, PAGE_SIZE); \
1149} \ 1211} \
1150static DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL) 1212static DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL)
@@ -1208,7 +1270,7 @@ static int input_add_uevent_bm_var(struct kobj_uevent_env *env,
1208 1270
1209 len = input_print_bitmap(&env->buf[env->buflen - 1], 1271 len = input_print_bitmap(&env->buf[env->buflen - 1],
1210 sizeof(env->buf) - env->buflen, 1272 sizeof(env->buf) - env->buflen,
1211 bitmap, max, 0); 1273 bitmap, max, false);
1212 if (len >= (sizeof(env->buf) - env->buflen)) 1274 if (len >= (sizeof(env->buf) - env->buflen))
1213 return -ENOMEM; 1275 return -ENOMEM;
1214 1276