diff options
-rw-r--r-- | drivers/char/keyboard.c | 31 | ||||
-rw-r--r-- | drivers/input/evdev.c | 100 | ||||
-rw-r--r-- | drivers/input/input.c | 192 | ||||
-rw-r--r-- | include/linux/input.h | 55 |
4 files changed, 292 insertions, 86 deletions
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c index a7ca75212bfe..e95d7876ca6b 100644 --- a/drivers/char/keyboard.c +++ b/drivers/char/keyboard.c | |||
@@ -175,8 +175,7 @@ EXPORT_SYMBOL_GPL(unregister_keyboard_notifier); | |||
175 | */ | 175 | */ |
176 | 176 | ||
177 | struct getset_keycode_data { | 177 | struct getset_keycode_data { |
178 | unsigned int scancode; | 178 | struct input_keymap_entry ke; |
179 | unsigned int keycode; | ||
180 | int error; | 179 | int error; |
181 | }; | 180 | }; |
182 | 181 | ||
@@ -184,32 +183,50 @@ static int getkeycode_helper(struct input_handle *handle, void *data) | |||
184 | { | 183 | { |
185 | struct getset_keycode_data *d = data; | 184 | struct getset_keycode_data *d = data; |
186 | 185 | ||
187 | d->error = input_get_keycode(handle->dev, d->scancode, &d->keycode); | 186 | d->error = input_get_keycode(handle->dev, &d->ke); |
188 | 187 | ||
189 | return d->error == 0; /* stop as soon as we successfully get one */ | 188 | return d->error == 0; /* stop as soon as we successfully get one */ |
190 | } | 189 | } |
191 | 190 | ||
192 | int getkeycode(unsigned int scancode) | 191 | int getkeycode(unsigned int scancode) |
193 | { | 192 | { |
194 | struct getset_keycode_data d = { scancode, 0, -ENODEV }; | 193 | struct getset_keycode_data d = { |
194 | .ke = { | ||
195 | .flags = 0, | ||
196 | .len = sizeof(scancode), | ||
197 | .keycode = 0, | ||
198 | }, | ||
199 | .error = -ENODEV, | ||
200 | }; | ||
201 | |||
202 | memcpy(d.ke.scancode, &scancode, sizeof(scancode)); | ||
195 | 203 | ||
196 | input_handler_for_each_handle(&kbd_handler, &d, getkeycode_helper); | 204 | input_handler_for_each_handle(&kbd_handler, &d, getkeycode_helper); |
197 | 205 | ||
198 | return d.error ?: d.keycode; | 206 | return d.error ?: d.ke.keycode; |
199 | } | 207 | } |
200 | 208 | ||
201 | static int setkeycode_helper(struct input_handle *handle, void *data) | 209 | static int setkeycode_helper(struct input_handle *handle, void *data) |
202 | { | 210 | { |
203 | struct getset_keycode_data *d = data; | 211 | struct getset_keycode_data *d = data; |
204 | 212 | ||
205 | d->error = input_set_keycode(handle->dev, d->scancode, d->keycode); | 213 | d->error = input_set_keycode(handle->dev, &d->ke); |
206 | 214 | ||
207 | return d->error == 0; /* stop as soon as we successfully set one */ | 215 | return d->error == 0; /* stop as soon as we successfully set one */ |
208 | } | 216 | } |
209 | 217 | ||
210 | int setkeycode(unsigned int scancode, unsigned int keycode) | 218 | int setkeycode(unsigned int scancode, unsigned int keycode) |
211 | { | 219 | { |
212 | struct getset_keycode_data d = { scancode, keycode, -ENODEV }; | 220 | struct getset_keycode_data d = { |
221 | .ke = { | ||
222 | .flags = 0, | ||
223 | .len = sizeof(scancode), | ||
224 | .keycode = keycode, | ||
225 | }, | ||
226 | .error = -ENODEV, | ||
227 | }; | ||
228 | |||
229 | memcpy(d.ke.scancode, &scancode, sizeof(scancode)); | ||
213 | 230 | ||
214 | input_handler_for_each_handle(&kbd_handler, &d, setkeycode_helper); | 231 | input_handler_for_each_handle(&kbd_handler, &d, setkeycode_helper); |
215 | 232 | ||
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index c908c5f83645..1ce9bf663206 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c | |||
@@ -534,6 +534,80 @@ static int handle_eviocgbit(struct input_dev *dev, | |||
534 | } | 534 | } |
535 | #undef OLD_KEY_MAX | 535 | #undef OLD_KEY_MAX |
536 | 536 | ||
537 | static int evdev_handle_get_keycode(struct input_dev *dev, | ||
538 | void __user *p, size_t size) | ||
539 | { | ||
540 | struct input_keymap_entry ke; | ||
541 | int error; | ||
542 | |||
543 | memset(&ke, 0, sizeof(ke)); | ||
544 | |||
545 | if (size == sizeof(unsigned int[2])) { | ||
546 | /* legacy case */ | ||
547 | int __user *ip = (int __user *)p; | ||
548 | |||
549 | if (copy_from_user(ke.scancode, p, sizeof(unsigned int))) | ||
550 | return -EFAULT; | ||
551 | |||
552 | ke.len = sizeof(unsigned int); | ||
553 | ke.flags = 0; | ||
554 | |||
555 | error = input_get_keycode(dev, &ke); | ||
556 | if (error) | ||
557 | return error; | ||
558 | |||
559 | if (put_user(ke.keycode, ip + 1)) | ||
560 | return -EFAULT; | ||
561 | |||
562 | } else { | ||
563 | size = min(size, sizeof(ke)); | ||
564 | |||
565 | if (copy_from_user(&ke, p, size)) | ||
566 | return -EFAULT; | ||
567 | |||
568 | error = input_get_keycode(dev, &ke); | ||
569 | if (error) | ||
570 | return error; | ||
571 | |||
572 | if (copy_to_user(p, &ke, size)) | ||
573 | return -EFAULT; | ||
574 | } | ||
575 | return 0; | ||
576 | } | ||
577 | |||
578 | static int evdev_handle_set_keycode(struct input_dev *dev, | ||
579 | void __user *p, size_t size) | ||
580 | { | ||
581 | struct input_keymap_entry ke; | ||
582 | |||
583 | memset(&ke, 0, sizeof(ke)); | ||
584 | |||
585 | if (size == sizeof(unsigned int[2])) { | ||
586 | /* legacy case */ | ||
587 | int __user *ip = (int __user *)p; | ||
588 | |||
589 | if (copy_from_user(ke.scancode, p, sizeof(unsigned int))) | ||
590 | return -EFAULT; | ||
591 | |||
592 | if (get_user(ke.keycode, ip + 1)) | ||
593 | return -EFAULT; | ||
594 | |||
595 | ke.len = sizeof(unsigned int); | ||
596 | ke.flags = 0; | ||
597 | |||
598 | } else { | ||
599 | size = min(size, sizeof(ke)); | ||
600 | |||
601 | if (copy_from_user(&ke, p, size)) | ||
602 | return -EFAULT; | ||
603 | |||
604 | if (ke.len > sizeof(ke.scancode)) | ||
605 | return -EINVAL; | ||
606 | } | ||
607 | |||
608 | return input_set_keycode(dev, &ke); | ||
609 | } | ||
610 | |||
537 | static long evdev_do_ioctl(struct file *file, unsigned int cmd, | 611 | static long evdev_do_ioctl(struct file *file, unsigned int cmd, |
538 | void __user *p, int compat_mode) | 612 | void __user *p, int compat_mode) |
539 | { | 613 | { |
@@ -580,25 +654,6 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd, | |||
580 | 654 | ||
581 | return 0; | 655 | return 0; |
582 | 656 | ||
583 | case EVIOCGKEYCODE: | ||
584 | if (get_user(t, ip)) | ||
585 | return -EFAULT; | ||
586 | |||
587 | error = input_get_keycode(dev, t, &v); | ||
588 | if (error) | ||
589 | return error; | ||
590 | |||
591 | if (put_user(v, ip + 1)) | ||
592 | return -EFAULT; | ||
593 | |||
594 | return 0; | ||
595 | |||
596 | case EVIOCSKEYCODE: | ||
597 | if (get_user(t, ip) || get_user(v, ip + 1)) | ||
598 | return -EFAULT; | ||
599 | |||
600 | return input_set_keycode(dev, t, v); | ||
601 | |||
602 | case EVIOCRMFF: | 657 | case EVIOCRMFF: |
603 | return input_ff_erase(dev, (int)(unsigned long) p, file); | 658 | return input_ff_erase(dev, (int)(unsigned long) p, file); |
604 | 659 | ||
@@ -620,7 +675,6 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd, | |||
620 | 675 | ||
621 | /* Now check variable-length commands */ | 676 | /* Now check variable-length commands */ |
622 | #define EVIOC_MASK_SIZE(nr) ((nr) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT)) | 677 | #define EVIOC_MASK_SIZE(nr) ((nr) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT)) |
623 | |||
624 | switch (EVIOC_MASK_SIZE(cmd)) { | 678 | switch (EVIOC_MASK_SIZE(cmd)) { |
625 | 679 | ||
626 | case EVIOCGKEY(0): | 680 | case EVIOCGKEY(0): |
@@ -654,6 +708,12 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd, | |||
654 | return -EFAULT; | 708 | return -EFAULT; |
655 | 709 | ||
656 | return error; | 710 | return error; |
711 | |||
712 | case EVIOC_MASK_SIZE(EVIOCGKEYCODE): | ||
713 | return evdev_handle_get_keycode(dev, p, size); | ||
714 | |||
715 | case EVIOC_MASK_SIZE(EVIOCSKEYCODE): | ||
716 | return evdev_handle_set_keycode(dev, p, size); | ||
657 | } | 717 | } |
658 | 718 | ||
659 | /* Multi-number variable-length handlers */ | 719 | /* Multi-number variable-length handlers */ |
diff --git a/drivers/input/input.c b/drivers/input/input.c index acb3c8095c65..832771e73663 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -634,78 +634,141 @@ static void input_disconnect_device(struct input_dev *dev) | |||
634 | spin_unlock_irq(&dev->event_lock); | 634 | spin_unlock_irq(&dev->event_lock); |
635 | } | 635 | } |
636 | 636 | ||
637 | static int input_fetch_keycode(struct input_dev *dev, int scancode) | 637 | /** |
638 | * input_scancode_to_scalar() - converts scancode in &struct input_keymap_entry | ||
639 | * @ke: keymap entry containing scancode to be converted. | ||
640 | * @scancode: pointer to the location where converted scancode should | ||
641 | * be stored. | ||
642 | * | ||
643 | * This function is used to convert scancode stored in &struct keymap_entry | ||
644 | * into scalar form understood by legacy keymap handling methods. These | ||
645 | * methods expect scancodes to be represented as 'unsigned int'. | ||
646 | */ | ||
647 | int input_scancode_to_scalar(const struct input_keymap_entry *ke, | ||
648 | unsigned int *scancode) | ||
649 | { | ||
650 | switch (ke->len) { | ||
651 | case 1: | ||
652 | *scancode = *((u8 *)ke->scancode); | ||
653 | break; | ||
654 | |||
655 | case 2: | ||
656 | *scancode = *((u16 *)ke->scancode); | ||
657 | break; | ||
658 | |||
659 | case 4: | ||
660 | *scancode = *((u32 *)ke->scancode); | ||
661 | break; | ||
662 | |||
663 | default: | ||
664 | return -EINVAL; | ||
665 | } | ||
666 | |||
667 | return 0; | ||
668 | } | ||
669 | EXPORT_SYMBOL(input_scancode_to_scalar); | ||
670 | |||
671 | /* | ||
672 | * Those routines handle the default case where no [gs]etkeycode() is | ||
673 | * defined. In this case, an array indexed by the scancode is used. | ||
674 | */ | ||
675 | |||
676 | static unsigned int input_fetch_keycode(struct input_dev *dev, | ||
677 | unsigned int index) | ||
638 | { | 678 | { |
639 | switch (dev->keycodesize) { | 679 | switch (dev->keycodesize) { |
640 | case 1: | 680 | case 1: |
641 | return ((u8 *)dev->keycode)[scancode]; | 681 | return ((u8 *)dev->keycode)[index]; |
642 | 682 | ||
643 | case 2: | 683 | case 2: |
644 | return ((u16 *)dev->keycode)[scancode]; | 684 | return ((u16 *)dev->keycode)[index]; |
645 | 685 | ||
646 | default: | 686 | default: |
647 | return ((u32 *)dev->keycode)[scancode]; | 687 | return ((u32 *)dev->keycode)[index]; |
648 | } | 688 | } |
649 | } | 689 | } |
650 | 690 | ||
651 | static int input_default_getkeycode(struct input_dev *dev, | 691 | static int input_default_getkeycode(struct input_dev *dev, |
652 | unsigned int scancode, | 692 | struct input_keymap_entry *ke) |
653 | unsigned int *keycode) | ||
654 | { | 693 | { |
694 | unsigned int index; | ||
695 | int error; | ||
696 | |||
655 | if (!dev->keycodesize) | 697 | if (!dev->keycodesize) |
656 | return -EINVAL; | 698 | return -EINVAL; |
657 | 699 | ||
658 | if (scancode >= dev->keycodemax) | 700 | if (ke->flags & INPUT_KEYMAP_BY_INDEX) |
701 | index = ke->index; | ||
702 | else { | ||
703 | error = input_scancode_to_scalar(ke, &index); | ||
704 | if (error) | ||
705 | return error; | ||
706 | } | ||
707 | |||
708 | if (index >= dev->keycodemax) | ||
659 | return -EINVAL; | 709 | return -EINVAL; |
660 | 710 | ||
661 | *keycode = input_fetch_keycode(dev, scancode); | 711 | ke->keycode = input_fetch_keycode(dev, index); |
712 | ke->index = index; | ||
713 | ke->len = sizeof(index); | ||
714 | memcpy(ke->scancode, &index, sizeof(index)); | ||
662 | 715 | ||
663 | return 0; | 716 | return 0; |
664 | } | 717 | } |
665 | 718 | ||
666 | static int input_default_setkeycode(struct input_dev *dev, | 719 | static int input_default_setkeycode(struct input_dev *dev, |
667 | unsigned int scancode, | 720 | const struct input_keymap_entry *ke, |
668 | unsigned int keycode) | 721 | unsigned int *old_keycode) |
669 | { | 722 | { |
670 | int old_keycode; | 723 | unsigned int index; |
724 | int error; | ||
671 | int i; | 725 | int i; |
672 | 726 | ||
673 | if (scancode >= dev->keycodemax) | 727 | if (!dev->keycodesize) |
674 | return -EINVAL; | 728 | return -EINVAL; |
675 | 729 | ||
676 | if (!dev->keycodesize) | 730 | if (ke->flags & INPUT_KEYMAP_BY_INDEX) { |
731 | index = ke->index; | ||
732 | } else { | ||
733 | error = input_scancode_to_scalar(ke, &index); | ||
734 | if (error) | ||
735 | return error; | ||
736 | } | ||
737 | |||
738 | if (index >= dev->keycodemax) | ||
677 | return -EINVAL; | 739 | return -EINVAL; |
678 | 740 | ||
679 | if (dev->keycodesize < sizeof(keycode) && (keycode >> (dev->keycodesize * 8))) | 741 | if (dev->keycodesize < sizeof(dev->keycode) && |
742 | (ke->keycode >> (dev->keycodesize * 8))) | ||
680 | return -EINVAL; | 743 | return -EINVAL; |
681 | 744 | ||
682 | switch (dev->keycodesize) { | 745 | switch (dev->keycodesize) { |
683 | case 1: { | 746 | case 1: { |
684 | u8 *k = (u8 *)dev->keycode; | 747 | u8 *k = (u8 *)dev->keycode; |
685 | old_keycode = k[scancode]; | 748 | *old_keycode = k[index]; |
686 | k[scancode] = keycode; | 749 | k[index] = ke->keycode; |
687 | break; | 750 | break; |
688 | } | 751 | } |
689 | case 2: { | 752 | case 2: { |
690 | u16 *k = (u16 *)dev->keycode; | 753 | u16 *k = (u16 *)dev->keycode; |
691 | old_keycode = k[scancode]; | 754 | *old_keycode = k[index]; |
692 | k[scancode] = keycode; | 755 | k[index] = ke->keycode; |
693 | break; | 756 | break; |
694 | } | 757 | } |
695 | default: { | 758 | default: { |
696 | u32 *k = (u32 *)dev->keycode; | 759 | u32 *k = (u32 *)dev->keycode; |
697 | old_keycode = k[scancode]; | 760 | *old_keycode = k[index]; |
698 | k[scancode] = keycode; | 761 | k[index] = ke->keycode; |
699 | break; | 762 | break; |
700 | } | 763 | } |
701 | } | 764 | } |
702 | 765 | ||
703 | __clear_bit(old_keycode, dev->keybit); | 766 | __clear_bit(*old_keycode, dev->keybit); |
704 | __set_bit(keycode, dev->keybit); | 767 | __set_bit(ke->keycode, dev->keybit); |
705 | 768 | ||
706 | for (i = 0; i < dev->keycodemax; i++) { | 769 | for (i = 0; i < dev->keycodemax; i++) { |
707 | if (input_fetch_keycode(dev, i) == old_keycode) { | 770 | if (input_fetch_keycode(dev, i) == *old_keycode) { |
708 | __set_bit(old_keycode, dev->keybit); | 771 | __set_bit(*old_keycode, dev->keybit); |
709 | break; /* Setting the bit twice is useless, so break */ | 772 | break; /* Setting the bit twice is useless, so break */ |
710 | } | 773 | } |
711 | } | 774 | } |
@@ -716,53 +779,86 @@ static int input_default_setkeycode(struct input_dev *dev, | |||
716 | /** | 779 | /** |
717 | * input_get_keycode - retrieve keycode currently mapped to a given scancode | 780 | * input_get_keycode - retrieve keycode currently mapped to a given scancode |
718 | * @dev: input device which keymap is being queried | 781 | * @dev: input device which keymap is being queried |
719 | * @scancode: scancode (or its equivalent for device in question) for which | 782 | * @ke: keymap entry |
720 | * keycode is needed | ||
721 | * @keycode: result | ||
722 | * | 783 | * |
723 | * This function should be called by anyone interested in retrieving current | 784 | * This function should be called by anyone interested in retrieving current |
724 | * keymap. Presently keyboard and evdev handlers use it. | 785 | * keymap. Presently evdev handlers use it. |
725 | */ | 786 | */ |
726 | int input_get_keycode(struct input_dev *dev, | 787 | int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke) |
727 | unsigned int scancode, unsigned int *keycode) | ||
728 | { | 788 | { |
729 | unsigned long flags; | 789 | unsigned long flags; |
730 | int retval; | 790 | int retval; |
731 | 791 | ||
732 | spin_lock_irqsave(&dev->event_lock, flags); | 792 | spin_lock_irqsave(&dev->event_lock, flags); |
733 | retval = dev->getkeycode(dev, scancode, keycode); | ||
734 | spin_unlock_irqrestore(&dev->event_lock, flags); | ||
735 | 793 | ||
794 | if (dev->getkeycode) { | ||
795 | /* | ||
796 | * Support for legacy drivers, that don't implement the new | ||
797 | * ioctls | ||
798 | */ | ||
799 | u32 scancode = ke->index; | ||
800 | |||
801 | memcpy(ke->scancode, &scancode, sizeof(scancode)); | ||
802 | ke->len = sizeof(scancode); | ||
803 | retval = dev->getkeycode(dev, scancode, &ke->keycode); | ||
804 | } else { | ||
805 | retval = dev->getkeycode_new(dev, ke); | ||
806 | } | ||
807 | |||
808 | spin_unlock_irqrestore(&dev->event_lock, flags); | ||
736 | return retval; | 809 | return retval; |
737 | } | 810 | } |
738 | EXPORT_SYMBOL(input_get_keycode); | 811 | EXPORT_SYMBOL(input_get_keycode); |
739 | 812 | ||
740 | /** | 813 | /** |
741 | * input_get_keycode - assign new keycode to a given scancode | 814 | * input_set_keycode - attribute a keycode to a given scancode |
742 | * @dev: input device which keymap is being updated | 815 | * @dev: input device which keymap is being updated |
743 | * @scancode: scancode (or its equivalent for device in question) | 816 | * @ke: new keymap entry |
744 | * @keycode: new keycode to be assigned to the scancode | ||
745 | * | 817 | * |
746 | * This function should be called by anyone needing to update current | 818 | * This function should be called by anyone needing to update current |
747 | * keymap. Presently keyboard and evdev handlers use it. | 819 | * keymap. Presently keyboard and evdev handlers use it. |
748 | */ | 820 | */ |
749 | int input_set_keycode(struct input_dev *dev, | 821 | int input_set_keycode(struct input_dev *dev, |
750 | unsigned int scancode, unsigned int keycode) | 822 | const struct input_keymap_entry *ke) |
751 | { | 823 | { |
752 | unsigned long flags; | 824 | unsigned long flags; |
753 | unsigned int old_keycode; | 825 | unsigned int old_keycode; |
754 | int retval; | 826 | int retval; |
755 | 827 | ||
756 | if (keycode > KEY_MAX) | 828 | if (ke->keycode > KEY_MAX) |
757 | return -EINVAL; | 829 | return -EINVAL; |
758 | 830 | ||
759 | spin_lock_irqsave(&dev->event_lock, flags); | 831 | spin_lock_irqsave(&dev->event_lock, flags); |
760 | 832 | ||
761 | retval = dev->getkeycode(dev, scancode, &old_keycode); | 833 | if (dev->setkeycode) { |
762 | if (retval) | 834 | /* |
763 | goto out; | 835 | * Support for legacy drivers, that don't implement the new |
836 | * ioctls | ||
837 | */ | ||
838 | unsigned int scancode; | ||
839 | |||
840 | retval = input_scancode_to_scalar(ke, &scancode); | ||
841 | if (retval) | ||
842 | goto out; | ||
843 | |||
844 | /* | ||
845 | * We need to know the old scancode, in order to generate a | ||
846 | * keyup effect, if the set operation happens successfully | ||
847 | */ | ||
848 | if (!dev->getkeycode) { | ||
849 | retval = -EINVAL; | ||
850 | goto out; | ||
851 | } | ||
852 | |||
853 | retval = dev->getkeycode(dev, scancode, &old_keycode); | ||
854 | if (retval) | ||
855 | goto out; | ||
856 | |||
857 | retval = dev->setkeycode(dev, scancode, ke->keycode); | ||
858 | } else { | ||
859 | retval = dev->setkeycode_new(dev, ke, &old_keycode); | ||
860 | } | ||
764 | 861 | ||
765 | retval = dev->setkeycode(dev, scancode, keycode); | ||
766 | if (retval) | 862 | if (retval) |
767 | goto out; | 863 | goto out; |
768 | 864 | ||
@@ -1759,11 +1855,11 @@ int input_register_device(struct input_dev *dev) | |||
1759 | dev->rep[REP_PERIOD] = 33; | 1855 | dev->rep[REP_PERIOD] = 33; |
1760 | } | 1856 | } |
1761 | 1857 | ||
1762 | if (!dev->getkeycode) | 1858 | if (!dev->getkeycode && !dev->getkeycode_new) |
1763 | dev->getkeycode = input_default_getkeycode; | 1859 | dev->getkeycode_new = input_default_getkeycode; |
1764 | 1860 | ||
1765 | if (!dev->setkeycode) | 1861 | if (!dev->setkeycode && !dev->setkeycode_new) |
1766 | dev->setkeycode = input_default_setkeycode; | 1862 | dev->setkeycode_new = input_default_setkeycode; |
1767 | 1863 | ||
1768 | dev_set_name(&dev->dev, "input%ld", | 1864 | dev_set_name(&dev->dev, "input%ld", |
1769 | (unsigned long) atomic_inc_return(&input_no) - 1); | 1865 | (unsigned long) atomic_inc_return(&input_no) - 1); |
diff --git a/include/linux/input.h b/include/linux/input.h index 789265123531..0057698fd975 100644 --- a/include/linux/input.h +++ b/include/linux/input.h | |||
@@ -34,7 +34,7 @@ struct input_event { | |||
34 | * Protocol version. | 34 | * Protocol version. |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #define EV_VERSION 0x010000 | 37 | #define EV_VERSION 0x010001 |
38 | 38 | ||
39 | /* | 39 | /* |
40 | * IOCTLs (0x00 - 0x7f) | 40 | * IOCTLs (0x00 - 0x7f) |
@@ -56,12 +56,37 @@ struct input_absinfo { | |||
56 | __s32 resolution; | 56 | __s32 resolution; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | /** | ||
60 | * struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls | ||
61 | * @scancode: scancode represented in machine-endian form. | ||
62 | * @len: length of the scancode that resides in @scancode buffer. | ||
63 | * @index: index in the keymap, may be used instead of scancode | ||
64 | * @flags: allows to specify how kernel should handle the request. For | ||
65 | * example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel | ||
66 | * should perform lookup in keymap by @index instead of @scancode | ||
67 | * @keycode: key code assigned to this scancode | ||
68 | * | ||
69 | * The structure is used to retrieve and modify keymap data. Users have | ||
70 | * option of performing lookup either by @scancode itself or by @index | ||
71 | * in keymap entry. EVIOCGKEYCODE will also return scancode or index | ||
72 | * (depending on which element was used to perform lookup). | ||
73 | */ | ||
74 | struct input_keymap_entry { | ||
75 | #define INPUT_KEYMAP_BY_INDEX (1 << 0) | ||
76 | __u8 flags; | ||
77 | __u8 len; | ||
78 | __u16 index; | ||
79 | __u32 keycode; | ||
80 | __u8 scancode[32]; | ||
81 | }; | ||
82 | |||
59 | #define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ | 83 | #define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */ |
60 | #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ | 84 | #define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */ |
61 | #define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */ | 85 | #define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */ |
62 | #define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */ | 86 | #define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */ |
63 | #define EVIOCGKEYCODE _IOR('E', 0x04, unsigned int[2]) /* get keycode */ | 87 | |
64 | #define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */ | 88 | #define EVIOCGKEYCODE _IOR('E', 0x04, struct input_keymap_entry) /* get keycode */ |
89 | #define EVIOCSKEYCODE _IOW('E', 0x04, struct input_keymap_entry) /* set keycode */ | ||
65 | 90 | ||
66 | #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ | 91 | #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */ |
67 | #define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */ | 92 | #define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */ |
@@ -73,8 +98,8 @@ struct input_absinfo { | |||
73 | #define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */ | 98 | #define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */ |
74 | 99 | ||
75 | #define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */ | 100 | #define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + ev, len) /* get event bits */ |
76 | #define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */ | 101 | #define EVIOCGABS(abs) _IOR('E', 0x40 + abs, struct input_absinfo) /* get abs value/limits */ |
77 | #define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */ | 102 | #define EVIOCSABS(abs) _IOW('E', 0xc0 + abs, struct input_absinfo) /* set abs value/limits */ |
78 | 103 | ||
79 | #define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */ | 104 | #define EVIOCSFF _IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect)) /* send a force effect to a force feedback device */ |
80 | #define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */ | 105 | #define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */ |
@@ -1088,13 +1113,13 @@ struct input_mt_slot { | |||
1088 | * @keycodemax: size of keycode table | 1113 | * @keycodemax: size of keycode table |
1089 | * @keycodesize: size of elements in keycode table | 1114 | * @keycodesize: size of elements in keycode table |
1090 | * @keycode: map of scancodes to keycodes for this device | 1115 | * @keycode: map of scancodes to keycodes for this device |
1116 | * @getkeycode: optional legacy method to retrieve current keymap. | ||
1091 | * @setkeycode: optional method to alter current keymap, used to implement | 1117 | * @setkeycode: optional method to alter current keymap, used to implement |
1092 | * sparse keymaps. If not supplied default mechanism will be used. | 1118 | * sparse keymaps. If not supplied default mechanism will be used. |
1093 | * The method is being called while holding event_lock and thus must | 1119 | * The method is being called while holding event_lock and thus must |
1094 | * not sleep | 1120 | * not sleep |
1095 | * @getkeycode: optional method to retrieve current keymap. If not supplied | 1121 | * @getkeycode_new: transition method |
1096 | * default mechanism will be used. The method is being called while | 1122 | * @setkeycode_new: transition method |
1097 | * holding event_lock and thus must not sleep | ||
1098 | * @ff: force feedback structure associated with the device if device | 1123 | * @ff: force feedback structure associated with the device if device |
1099 | * supports force feedback effects | 1124 | * supports force feedback effects |
1100 | * @repeat_key: stores key code of the last key pressed; used to implement | 1125 | * @repeat_key: stores key code of the last key pressed; used to implement |
@@ -1168,10 +1193,16 @@ struct input_dev { | |||
1168 | unsigned int keycodemax; | 1193 | unsigned int keycodemax; |
1169 | unsigned int keycodesize; | 1194 | unsigned int keycodesize; |
1170 | void *keycode; | 1195 | void *keycode; |
1196 | |||
1171 | int (*setkeycode)(struct input_dev *dev, | 1197 | int (*setkeycode)(struct input_dev *dev, |
1172 | unsigned int scancode, unsigned int keycode); | 1198 | unsigned int scancode, unsigned int keycode); |
1173 | int (*getkeycode)(struct input_dev *dev, | 1199 | int (*getkeycode)(struct input_dev *dev, |
1174 | unsigned int scancode, unsigned int *keycode); | 1200 | unsigned int scancode, unsigned int *keycode); |
1201 | int (*setkeycode_new)(struct input_dev *dev, | ||
1202 | const struct input_keymap_entry *ke, | ||
1203 | unsigned int *old_keycode); | ||
1204 | int (*getkeycode_new)(struct input_dev *dev, | ||
1205 | struct input_keymap_entry *ke); | ||
1175 | 1206 | ||
1176 | struct ff_device *ff; | 1207 | struct ff_device *ff; |
1177 | 1208 | ||
@@ -1478,10 +1509,12 @@ INPUT_GENERATE_ABS_ACCESSORS(fuzz, fuzz) | |||
1478 | INPUT_GENERATE_ABS_ACCESSORS(flat, flat) | 1509 | INPUT_GENERATE_ABS_ACCESSORS(flat, flat) |
1479 | INPUT_GENERATE_ABS_ACCESSORS(res, resolution) | 1510 | INPUT_GENERATE_ABS_ACCESSORS(res, resolution) |
1480 | 1511 | ||
1481 | int input_get_keycode(struct input_dev *dev, | 1512 | int input_scancode_to_scalar(const struct input_keymap_entry *ke, |
1482 | unsigned int scancode, unsigned int *keycode); | 1513 | unsigned int *scancode); |
1514 | |||
1515 | int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke); | ||
1483 | int input_set_keycode(struct input_dev *dev, | 1516 | int input_set_keycode(struct input_dev *dev, |
1484 | unsigned int scancode, unsigned int keycode); | 1517 | const struct input_keymap_entry *ke); |
1485 | 1518 | ||
1486 | extern struct class input_class; | 1519 | extern struct class input_class; |
1487 | 1520 | ||