View | Details | Raw Unified | Return to bug 112672
Collapse All | Expand All

(-)a/drivers/input/input.c (-55 / +150 lines)
Lines 47-52 static LIST_HEAD(input_dev_list); Link Here
47
static LIST_HEAD(input_handler_list);
47
static LIST_HEAD(input_handler_list);
48
48
49
static struct input_handler *input_table[8];
49
static struct input_handler *input_table[8];
50
static atomic_t input_device_num = ATOMIC_INIT(0);
50
51
51
#ifdef CONFIG_PROC_FS
52
#ifdef CONFIG_PROC_FS
52
static struct proc_dir_entry *proc_bus_input_dir;
53
static struct proc_dir_entry *proc_bus_input_dir;
Lines 325-376 static struct input_device_id *input_mat Link Here
325
			SPRINTF_BIT_A(bit, name, max); \
326
			SPRINTF_BIT_A(bit, name, max); \
326
	} while (0)
327
	} while (0)
327
328
328
static void input_call_hotplug(char *verb, struct input_dev *dev)
329
static int __input_hotplug(struct input_dev *dev, char **envp, int num_envp,
330
			   char *buffer, int buffer_size)
329
{
331
{
330
	char *argv[3], **envp, *buf, *scratch;
332
	char *scratch;
331
	int i = 0, j, value;
333
	int i = 0, j;
334
	scratch = buffer;
332
335
333
	if (!hotplug_path[0]) {
336
	if (!dev)
334
		printk(KERN_ERR "input.c: calling hotplug without a hotplug agent defined\n");
337
		return -ENODEV;
335
		return;
336
	}
337
	if (in_interrupt()) {
338
		printk(KERN_ERR "input.c: calling hotplug from interrupt\n");
339
		return;
340
	}
341
	if (!current->fs->root) {
342
		printk(KERN_WARNING "input.c: calling hotplug without valid filesystem\n");
343
		return;
344
	}
345
	if (!(envp = (char **) kmalloc(20 * sizeof(char *), GFP_KERNEL))) {
346
		printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n");
347
		return;
348
	}
349
	if (!(buf = kmalloc(1024, GFP_KERNEL))) {
350
		kfree (envp);
351
		printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n");
352
		return;
353
	}
354
355
	argv[0] = hotplug_path;
356
	argv[1] = "input";
357
	argv[2] = NULL;
358
359
	envp[i++] = "HOME=/";
360
	envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
361
362
	scratch = buf;
363
364
	envp[i++] = scratch;
365
	scratch += sprintf(scratch, "ACTION=%s", verb) + 1;
366
338
367
	envp[i++] = scratch;
339
	envp[i++] = scratch;
368
	scratch += sprintf(scratch, "PRODUCT=%x/%x/%x/%x",
340
	scratch += sprintf(scratch, "PRODUCT=%x/%x/%x/%x",
369
		dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version) + 1;
341
		dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version) + 1;
370
342
343
#ifdef INPUT_DEBUG
344
	printk(KERN_DEBUG "%s: PRODUCT %x/%x/%x/%x\n", __FUNCTION__,
345
	       dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
346
#endif
371
	if (dev->name) {
347
	if (dev->name) {
372
		envp[i++] = scratch;
348
		envp[i++] = scratch;
373
		scratch += sprintf(scratch, "NAME=%s", dev->name) + 1;
349
		scratch += sprintf(scratch, "NAME=\"%s\"", dev->name) + 1;
374
	}
350
	}
375
351
376
	if (dev->phys) {
352
	if (dev->phys) {
Lines 389-411 static void input_call_hotplug(char *ver Link Here
389
365
390
	envp[i++] = NULL;
366
	envp[i++] = NULL;
391
367
368
	return 0;
369
}
370
371
int input_hotplug(struct class_device *cdev, char **envp, int num_envp,
372
		  char *buffer, int buffer_size)
373
{
374
	struct input_dev *dev;
375
376
	if (!cdev)
377
		return -ENODEV;
392
#ifdef INPUT_DEBUG
378
#ifdef INPUT_DEBUG
393
	printk(KERN_DEBUG "input.c: calling %s %s [%s %s %s %s %s]\n",
379
	printk(KERN_DEBUG "%s: entered for dev %p\n", __FUNCTION__, 
394
		argv[0], argv[1], envp[0], envp[1], envp[2], envp[3], envp[4]);
380
	       &cdev->dev);
395
#endif
381
#endif
396
382
397
	value = call_usermodehelper(argv [0], argv, envp, 0);
383
	dev = container_of(cdev,struct input_dev,cdev);
398
384
399
	kfree(buf);
385
	return __input_hotplug(dev, envp, num_envp, buffer, buffer_size);
400
	kfree(envp);
386
}
401
387
402
#ifdef INPUT_DEBUG
388
#else
403
	if (value != 0)
389
int input_hotplug(struct class_device *cdev, char **envp, int num_envp,
404
		printk(KERN_DEBUG "input.c: hotplug returned %d\n", value);
390
		  char *buffer, int buffer_size)
405
#endif
391
{
392
    return 0;
406
}
393
}
394
#endif /* CONFIG_HOTPLUG */
407
395
408
#endif
396
#define INPUT_ATTR_BIT_B(bit, max) \
397
	do { \
398
		for (i = NBITS(max) - 1; i >= 0; i--) \
399
			if (dev->bit[i]) break; \
400
		for (; i >= 0; i--) \
401
			len += sprintf(buf + len, "%lx ", dev->bit[i]); \
402
		if (len) len += sprintf(buf + len, "\n"); \
403
	} while (0)
404
405
#define INPUT_ATTR_BIT_B2(bit, max, ev) \
406
	do { \
407
		if (test_bit(ev, dev->evbit)) \
408
			INPUT_ATTR_BIT_B(bit, max); \
409
	} while (0)
410
411
412
static ssize_t input_class_show_ev(struct class_device *class_dev, char *buf)
413
{
414
	struct input_dev *dev = container_of(class_dev, struct input_dev,cdev);
415
	int i, len = 0;
416
417
	INPUT_ATTR_BIT_B(evbit, EV_MAX);
418
	return len;
419
}
420
421
#define INPUT_CLASS_ATTR_BIT(_name,_bit) \
422
static ssize_t input_class_show_##_bit(struct class_device *class_dev, \
423
				       char *buf) \
424
{ \
425
	struct input_dev *dev = container_of(class_dev,struct input_dev,cdev); \
426
        int i, len = 0; \
427
\
428
	INPUT_ATTR_BIT_B2(_bit##bit, _name##_MAX, EV_##_name); \
429
	return len; \
430
}
431
432
INPUT_CLASS_ATTR_BIT(KEY,key)
433
INPUT_CLASS_ATTR_BIT(REL,rel)
434
INPUT_CLASS_ATTR_BIT(ABS,abs)
435
INPUT_CLASS_ATTR_BIT(MSC,msc)
436
INPUT_CLASS_ATTR_BIT(LED,led)
437
INPUT_CLASS_ATTR_BIT(SND,snd)
438
INPUT_CLASS_ATTR_BIT(FF,ff)
439
440
static ssize_t input_class_show_phys(struct class_device *class_dev, char *buf)
441
{
442
	struct input_dev *dev = container_of(class_dev,struct input_dev,cdev);
443
444
	return sprintf(buf, "%s\n", dev->phys ? dev->phys : "(none)" );
445
}
446
447
static ssize_t input_class_show_name(struct class_device *class_dev, char *buf)
448
{
449
	struct input_dev *dev = container_of(class_dev,struct input_dev,cdev);
450
451
	return sprintf(buf, "%s\n", dev->name ? dev->name : "(none)" );
452
}
453
454
static ssize_t input_class_show_product(struct class_device *class_dev, char *buf)
455
{
456
	struct input_dev *dev = container_of(class_dev,struct input_dev,cdev);
457
458
	return sprintf(buf, "%x/%x/%x/%x\n", dev->id.bustype, dev->id.vendor, 
459
		       dev->id.product, dev->id.version);
460
}
461
462
static struct class_device_attribute input_device_class_attrs[] = {
463
	__ATTR( product, S_IRUGO, input_class_show_product, NULL) ,
464
	__ATTR( phys, S_IRUGO, input_class_show_phys, NULL ),
465
	__ATTR( name, S_IRUGO, input_class_show_name, NULL) ,
466
	__ATTR( ev, S_IRUGO, input_class_show_ev, NULL) ,
467
	__ATTR( key, S_IRUGO, input_class_show_key, NULL) ,
468
	__ATTR( rel, S_IRUGO, input_class_show_rel, NULL) ,
469
	__ATTR( abs, S_IRUGO, input_class_show_abs, NULL) ,
470
	__ATTR( msc, S_IRUGO, input_class_show_msc, NULL) ,
471
	__ATTR( led, S_IRUGO, input_class_show_led, NULL) ,
472
	__ATTR( snd, S_IRUGO, input_class_show_snd, NULL) ,
473
	__ATTR( ff, S_IRUGO, input_class_show_ff, NULL) ,
474
	__ATTR_NULL,
475
};
476
477
static void input_device_class_release( struct class_device *class_dev )
478
{
479
	put_device(class_dev->dev);
480
}
481
482
static struct class input_device_class = {
483
	.name =		"input_device",
484
	.hotplug = 	input_hotplug,
485
	.release = 	input_device_class_release,
486
	.class_dev_attrs = input_device_class_attrs,
487
};
409
488
410
void input_register_device(struct input_dev *dev)
489
void input_register_device(struct input_dev *dev)
411
{
490
{
Lines 413-418 void input_register_device(struct input_ Link Here
413
	struct input_handler *handler;
492
	struct input_handler *handler;
414
	struct input_device_id *id;
493
	struct input_device_id *id;
415
494
495
	dev->cdev.class = &input_device_class;
496
	
497
	dev->cdev.dev = get_device(dev->dev);
498
	sprintf(dev->cdev.class_id, "input%d", 
499
		atomic_inc_return(&input_device_num));
500
501
	if (class_device_register(&dev->cdev)) {
502
		if (dev->dev)
503
			put_device(dev->dev);
504
		return;
505
	}
506
416
	set_bit(EV_SYN, dev->evbit);
507
	set_bit(EV_SYN, dev->evbit);
417
508
418
	/*
509
	/*
Lines 437-446 void input_register_device(struct input_ Link Here
437
				if ((handle = handler->connect(handler, dev, id)))
528
				if ((handle = handler->connect(handler, dev, id)))
438
					input_link_handle(handle);
529
					input_link_handle(handle);
439
530
440
#ifdef CONFIG_HOTPLUG
441
	input_call_hotplug("add", dev);
442
#endif
443
444
#ifdef CONFIG_PROC_FS
531
#ifdef CONFIG_PROC_FS
445
	input_devices_state++;
532
	input_devices_state++;
446
	wake_up(&input_devices_poll_wait);
533
	wake_up(&input_devices_poll_wait);
Lines 462-473 void input_unregister_device(struct inpu Link Here
462
		handle->handler->disconnect(handle);
549
		handle->handler->disconnect(handle);
463
	}
550
	}
464
551
465
#ifdef CONFIG_HOTPLUG
466
	input_call_hotplug("remove", dev);
467
#endif
468
469
	list_del_init(&dev->node);
552
	list_del_init(&dev->node);
470
553
554
	class_device_unregister(&dev->cdev);
555
471
#ifdef CONFIG_PROC_FS
556
#ifdef CONFIG_PROC_FS
472
	input_devices_state++;
557
	input_devices_state++;
473
	wake_up(&input_devices_poll_wait);
558
	wake_up(&input_devices_poll_wait);
Lines 711-716 static int __init input_init(void) Link Here
711
	input_class = class_simple_create(THIS_MODULE, "input");
796
	input_class = class_simple_create(THIS_MODULE, "input");
712
	if (IS_ERR(input_class))
797
	if (IS_ERR(input_class))
713
		return PTR_ERR(input_class);
798
		return PTR_ERR(input_class);
799
800
	retval = class_register(&input_device_class);
801
	if (retval) {
802
		class_simple_destroy(input_class);
803
		return retval;
804
	}
805
714
	input_proc_init();
806
	input_proc_init();
715
	retval = register_chrdev(INPUT_MAJOR, "input", &input_fops);
807
	retval = register_chrdev(INPUT_MAJOR, "input", &input_fops);
716
	if (retval) {
808
	if (retval) {
Lines 718-723 static int __init input_init(void) Link Here
718
		remove_proc_entry("devices", proc_bus_input_dir);
810
		remove_proc_entry("devices", proc_bus_input_dir);
719
		remove_proc_entry("handlers", proc_bus_input_dir);
811
		remove_proc_entry("handlers", proc_bus_input_dir);
720
		remove_proc_entry("input", proc_bus);
812
		remove_proc_entry("input", proc_bus);
813
		class_unregister(&input_device_class);
721
		class_simple_destroy(input_class);
814
		class_simple_destroy(input_class);
722
		return retval;
815
		return retval;
723
	}
816
	}
Lines 728-733 static int __init input_init(void) Link Here
728
		remove_proc_entry("handlers", proc_bus_input_dir);
821
		remove_proc_entry("handlers", proc_bus_input_dir);
729
		remove_proc_entry("input", proc_bus);
822
		remove_proc_entry("input", proc_bus);
730
		unregister_chrdev(INPUT_MAJOR, "input");
823
		unregister_chrdev(INPUT_MAJOR, "input");
824
		class_unregister(&input_device_class);
731
		class_simple_destroy(input_class);
825
		class_simple_destroy(input_class);
732
	}
826
	}
733
	return retval;
827
	return retval;
Lines 741-746 static void __exit input_exit(void) Link Here
741
835
742
	devfs_remove("input");
836
	devfs_remove("input");
743
	unregister_chrdev(INPUT_MAJOR, "input");
837
	unregister_chrdev(INPUT_MAJOR, "input");
838
	class_unregister(&input_device_class);
744
	class_simple_destroy(input_class);
839
	class_simple_destroy(input_class);
745
}
840
}
746
841
(-)a/include/linux/input.h (+2 lines)
Lines 12-17 Link Here
12
#ifdef __KERNEL__
12
#ifdef __KERNEL__
13
#include <linux/time.h>
13
#include <linux/time.h>
14
#include <linux/list.h>
14
#include <linux/list.h>
15
#include <linux/device.h>
15
#else
16
#else
16
#include <sys/time.h>
17
#include <sys/time.h>
17
#include <sys/ioctl.h>
18
#include <sys/ioctl.h>
Lines 860-865 struct input_dev { Link Here
860
861
861
	struct input_handle *grab;
862
	struct input_handle *grab;
862
	struct device *dev;
863
	struct device *dev;
864
	struct class_device cdev;
863
865
864
	struct list_head	h_list;
866
	struct list_head	h_list;
865
	struct list_head	node;
867
	struct list_head	node;

Return to bug 112672