aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/misc')
-rw-r--r--drivers/input/misc/Kconfig23
-rw-r--r--drivers/input/misc/Makefile28
-rw-r--r--drivers/input/misc/ati_remote2.c277
-rw-r--r--drivers/input/misc/rb532_button.c120
-rw-r--r--drivers/input/misc/rotary_encoder.c221
5 files changed, 640 insertions, 29 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 67e5553f699a..203abac1e23e 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -227,4 +227,27 @@ config INPUT_PCF50633_PMU
227 Say Y to include support for delivering PMU events via input 227 Say Y to include support for delivering PMU events via input
228 layer on NXP PCF50633. 228 layer on NXP PCF50633.
229 229
230config INPUT_GPIO_ROTARY_ENCODER
231 tristate "Rotary encoders connected to GPIO pins"
232 depends on GPIOLIB && GENERIC_GPIO
233 help
234 Say Y here to add support for rotary encoders connected to GPIO lines.
235 Check file:Documentation/incput/rotary_encoder.txt for more
236 information.
237
238 To compile this driver as a module, choose M here: the
239 module will be called rotary_encoder.
240
241config INPUT_RB532_BUTTON
242 tristate "Mikrotik Routerboard 532 button interface"
243 depends on MIKROTIK_RB532
244 depends on GPIOLIB && GENERIC_GPIO
245 select INPUT_POLLDEV
246 help
247 Say Y here if you want support for the S1 button built into
248 Mikrotik's Routerboard 532.
249
250 To compile this driver as a module, choose M here: the
251 module will be called rb532_button.
252
230endif 253endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index bb62e6efacf3..eb3f407baedf 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -4,21 +4,23 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o 7obj-$(CONFIG_INPUT_APANEL) += apanel.o
8obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o
9obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o
10obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o
11obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o
12obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
13obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o
14obj-$(CONFIG_INPUT_ATI_REMOTE) += ati_remote.o 8obj-$(CONFIG_INPUT_ATI_REMOTE) += ati_remote.o
15obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o 9obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o
16obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o 10obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o
17obj-$(CONFIG_INPUT_POWERMATE) += powermate.o
18obj-$(CONFIG_INPUT_YEALINK) += yealink.o
19obj-$(CONFIG_INPUT_CM109) += cm109.o 11obj-$(CONFIG_INPUT_CM109) += cm109.o
12obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o
20obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o 13obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
21obj-$(CONFIG_INPUT_UINPUT) += uinput.o 14obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o
22obj-$(CONFIG_INPUT_APANEL) += apanel.o 15obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o
23obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o 16obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o
24obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o 17obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
18obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o
19obj-$(CONFIG_INPUT_POWERMATE) += powermate.o
20obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o
21obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o
22obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
23obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o
24obj-$(CONFIG_INPUT_UINPUT) += uinput.o
25obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
26obj-$(CONFIG_INPUT_YEALINK) += yealink.o
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index 3c9988dc0e9f..922c05141585 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -31,12 +31,73 @@ MODULE_LICENSE("GPL");
31 * newly configured "channel". 31 * newly configured "channel".
32 */ 32 */
33 33
34static unsigned int channel_mask = 0xFFFF; 34enum {
35module_param(channel_mask, uint, 0644); 35 ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF,
36 ATI_REMOTE2_MAX_MODE_MASK = 0x1F,
37};
38
39static int ati_remote2_set_mask(const char *val,
40 struct kernel_param *kp, unsigned int max)
41{
42 unsigned long mask;
43 int ret;
44
45 if (!val)
46 return -EINVAL;
47
48 ret = strict_strtoul(val, 0, &mask);
49 if (ret)
50 return ret;
51
52 if (mask & ~max)
53 return -EINVAL;
54
55 *(unsigned int *)kp->arg = mask;
56
57 return 0;
58}
59
60static int ati_remote2_set_channel_mask(const char *val,
61 struct kernel_param *kp)
62{
63 pr_debug("%s()\n", __func__);
64
65 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
66}
67
68static int ati_remote2_get_channel_mask(char *buffer, struct kernel_param *kp)
69{
70 pr_debug("%s()\n", __func__);
71
72 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
73}
74
75static int ati_remote2_set_mode_mask(const char *val, struct kernel_param *kp)
76{
77 pr_debug("%s()\n", __func__);
78
79 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
80}
81
82static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp)
83{
84 pr_debug("%s()\n", __func__);
85
86 return sprintf(buffer, "0x%02x", *(unsigned int *)kp->arg);
87}
88
89static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
90#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
91#define param_set_channel_mask ati_remote2_set_channel_mask
92#define param_get_channel_mask ati_remote2_get_channel_mask
93module_param(channel_mask, channel_mask, 0644);
36MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); 94MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
37 95
38static unsigned int mode_mask = 0x1F; 96static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
39module_param(mode_mask, uint, 0644); 97#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
98#define param_set_mode_mask ati_remote2_set_mode_mask
99#define param_get_mode_mask ati_remote2_get_mode_mask
100module_param(mode_mask, mode_mask, 0644);
40MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); 101MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
41 102
42static struct usb_device_id ati_remote2_id_table[] = { 103static struct usb_device_id ati_remote2_id_table[] = {
@@ -133,12 +194,18 @@ struct ati_remote2 {
133 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)]; 194 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
134 195
135 unsigned int flags; 196 unsigned int flags;
197
198 unsigned int channel_mask;
199 unsigned int mode_mask;
136}; 200};
137 201
138static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id); 202static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
139static void ati_remote2_disconnect(struct usb_interface *interface); 203static void ati_remote2_disconnect(struct usb_interface *interface);
140static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message); 204static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
141static int ati_remote2_resume(struct usb_interface *interface); 205static int ati_remote2_resume(struct usb_interface *interface);
206static int ati_remote2_reset_resume(struct usb_interface *interface);
207static int ati_remote2_pre_reset(struct usb_interface *interface);
208static int ati_remote2_post_reset(struct usb_interface *interface);
142 209
143static struct usb_driver ati_remote2_driver = { 210static struct usb_driver ati_remote2_driver = {
144 .name = "ati_remote2", 211 .name = "ati_remote2",
@@ -147,6 +214,9 @@ static struct usb_driver ati_remote2_driver = {
147 .id_table = ati_remote2_id_table, 214 .id_table = ati_remote2_id_table,
148 .suspend = ati_remote2_suspend, 215 .suspend = ati_remote2_suspend,
149 .resume = ati_remote2_resume, 216 .resume = ati_remote2_resume,
217 .reset_resume = ati_remote2_reset_resume,
218 .pre_reset = ati_remote2_pre_reset,
219 .post_reset = ati_remote2_post_reset,
150 .supports_autosuspend = 1, 220 .supports_autosuspend = 1,
151}; 221};
152 222
@@ -238,7 +308,7 @@ static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
238 308
239 channel = data[0] >> 4; 309 channel = data[0] >> 4;
240 310
241 if (!((1 << channel) & channel_mask)) 311 if (!((1 << channel) & ar2->channel_mask))
242 return; 312 return;
243 313
244 mode = data[0] & 0x0F; 314 mode = data[0] & 0x0F;
@@ -250,7 +320,7 @@ static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
250 return; 320 return;
251 } 321 }
252 322
253 if (!((1 << mode) & mode_mask)) 323 if (!((1 << mode) & ar2->mode_mask))
254 return; 324 return;
255 325
256 input_event(idev, EV_REL, REL_X, (s8) data[1]); 326 input_event(idev, EV_REL, REL_X, (s8) data[1]);
@@ -277,7 +347,7 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
277 347
278 channel = data[0] >> 4; 348 channel = data[0] >> 4;
279 349
280 if (!((1 << channel) & channel_mask)) 350 if (!((1 << channel) & ar2->channel_mask))
281 return; 351 return;
282 352
283 mode = data[0] & 0x0F; 353 mode = data[0] & 0x0F;
@@ -305,7 +375,7 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
305 ar2->mode = mode; 375 ar2->mode = mode;
306 } 376 }
307 377
308 if (!((1 << mode) & mode_mask)) 378 if (!((1 << mode) & ar2->mode_mask))
309 return; 379 return;
310 380
311 index = ati_remote2_lookup(hw_code); 381 index = ati_remote2_lookup(hw_code);
@@ -410,7 +480,7 @@ static int ati_remote2_getkeycode(struct input_dev *idev,
410 int index, mode; 480 int index, mode;
411 481
412 mode = scancode >> 8; 482 mode = scancode >> 8;
413 if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask)) 483 if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask))
414 return -EINVAL; 484 return -EINVAL;
415 485
416 index = ati_remote2_lookup(scancode & 0xFF); 486 index = ati_remote2_lookup(scancode & 0xFF);
@@ -427,7 +497,7 @@ static int ati_remote2_setkeycode(struct input_dev *idev, int scancode, int keyc
427 int index, mode, old_keycode; 497 int index, mode, old_keycode;
428 498
429 mode = scancode >> 8; 499 mode = scancode >> 8;
430 if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask)) 500 if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask))
431 return -EINVAL; 501 return -EINVAL;
432 502
433 index = ati_remote2_lookup(scancode & 0xFF); 503 index = ati_remote2_lookup(scancode & 0xFF);
@@ -550,7 +620,7 @@ static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
550 } 620 }
551} 621}
552 622
553static int ati_remote2_setup(struct ati_remote2 *ar2) 623static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask)
554{ 624{
555 int r, i, channel; 625 int r, i, channel;
556 626
@@ -565,8 +635,8 @@ static int ati_remote2_setup(struct ati_remote2 *ar2)
565 635
566 channel = 0; 636 channel = 0;
567 for (i = 0; i < 16; i++) { 637 for (i = 0; i < 16; i++) {
568 if ((1 << i) & channel_mask) { 638 if ((1 << i) & ch_mask) {
569 if (!(~(1 << i) & 0xFFFF & channel_mask)) 639 if (!(~(1 << i) & ch_mask))
570 channel = i + 1; 640 channel = i + 1;
571 break; 641 break;
572 } 642 }
@@ -585,6 +655,99 @@ static int ati_remote2_setup(struct ati_remote2 *ar2)
585 return 0; 655 return 0;
586} 656}
587 657
658static ssize_t ati_remote2_show_channel_mask(struct device *dev,
659 struct device_attribute *attr,
660 char *buf)
661{
662 struct usb_device *udev = to_usb_device(dev);
663 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
664 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
665
666 return sprintf(buf, "0x%04x\n", ar2->channel_mask);
667}
668
669static ssize_t ati_remote2_store_channel_mask(struct device *dev,
670 struct device_attribute *attr,
671 const char *buf, size_t count)
672{
673 struct usb_device *udev = to_usb_device(dev);
674 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
675 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
676 unsigned long mask;
677 int r;
678
679 if (strict_strtoul(buf, 0, &mask))
680 return -EINVAL;
681
682 if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK)
683 return -EINVAL;
684
685 r = usb_autopm_get_interface(ar2->intf[0]);
686 if (r) {
687 dev_err(&ar2->intf[0]->dev,
688 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
689 return r;
690 }
691
692 mutex_lock(&ati_remote2_mutex);
693
694 if (mask != ar2->channel_mask && !ati_remote2_setup(ar2, mask))
695 ar2->channel_mask = mask;
696
697 mutex_unlock(&ati_remote2_mutex);
698
699 usb_autopm_put_interface(ar2->intf[0]);
700
701 return count;
702}
703
704static ssize_t ati_remote2_show_mode_mask(struct device *dev,
705 struct device_attribute *attr,
706 char *buf)
707{
708 struct usb_device *udev = to_usb_device(dev);
709 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
710 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
711
712 return sprintf(buf, "0x%02x\n", ar2->mode_mask);
713}
714
715static ssize_t ati_remote2_store_mode_mask(struct device *dev,
716 struct device_attribute *attr,
717 const char *buf, size_t count)
718{
719 struct usb_device *udev = to_usb_device(dev);
720 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
721 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
722 unsigned long mask;
723
724 if (strict_strtoul(buf, 0, &mask))
725 return -EINVAL;
726
727 if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
728 return -EINVAL;
729
730 ar2->mode_mask = mask;
731
732 return count;
733}
734
735static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask,
736 ati_remote2_store_channel_mask);
737
738static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask,
739 ati_remote2_store_mode_mask);
740
741static struct attribute *ati_remote2_attrs[] = {
742 &dev_attr_channel_mask.attr,
743 &dev_attr_mode_mask.attr,
744 NULL,
745};
746
747static struct attribute_group ati_remote2_attr_group = {
748 .attrs = ati_remote2_attrs,
749};
750
588static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id) 751static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
589{ 752{
590 struct usb_device *udev = interface_to_usbdev(interface); 753 struct usb_device *udev = interface_to_usbdev(interface);
@@ -615,7 +778,10 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d
615 if (r) 778 if (r)
616 goto fail2; 779 goto fail2;
617 780
618 r = ati_remote2_setup(ar2); 781 ar2->channel_mask = channel_mask;
782 ar2->mode_mask = mode_mask;
783
784 r = ati_remote2_setup(ar2, ar2->channel_mask);
619 if (r) 785 if (r)
620 goto fail2; 786 goto fail2;
621 787
@@ -624,19 +790,24 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d
624 790
625 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name)); 791 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
626 792
627 r = ati_remote2_input_init(ar2); 793 r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group);
628 if (r) 794 if (r)
629 goto fail2; 795 goto fail2;
630 796
797 r = ati_remote2_input_init(ar2);
798 if (r)
799 goto fail3;
800
631 usb_set_intfdata(interface, ar2); 801 usb_set_intfdata(interface, ar2);
632 802
633 interface->needs_remote_wakeup = 1; 803 interface->needs_remote_wakeup = 1;
634 804
635 return 0; 805 return 0;
636 806
807 fail3:
808 sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group);
637 fail2: 809 fail2:
638 ati_remote2_urb_cleanup(ar2); 810 ati_remote2_urb_cleanup(ar2);
639
640 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]); 811 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
641 fail1: 812 fail1:
642 kfree(ar2); 813 kfree(ar2);
@@ -657,6 +828,8 @@ static void ati_remote2_disconnect(struct usb_interface *interface)
657 828
658 input_unregister_device(ar2->idev); 829 input_unregister_device(ar2->idev);
659 830
831 sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group);
832
660 ati_remote2_urb_cleanup(ar2); 833 ati_remote2_urb_cleanup(ar2);
661 834
662 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]); 835 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
@@ -715,6 +888,78 @@ static int ati_remote2_resume(struct usb_interface *interface)
715 return r; 888 return r;
716} 889}
717 890
891static int ati_remote2_reset_resume(struct usb_interface *interface)
892{
893 struct ati_remote2 *ar2;
894 struct usb_host_interface *alt = interface->cur_altsetting;
895 int r = 0;
896
897 if (alt->desc.bInterfaceNumber)
898 return 0;
899
900 ar2 = usb_get_intfdata(interface);
901
902 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
903
904 mutex_lock(&ati_remote2_mutex);
905
906 r = ati_remote2_setup(ar2, ar2->channel_mask);
907 if (r)
908 goto out;
909
910 if (ar2->flags & ATI_REMOTE2_OPENED)
911 r = ati_remote2_submit_urbs(ar2);
912
913 if (!r)
914 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
915
916 out:
917 mutex_unlock(&ati_remote2_mutex);
918
919 return r;
920}
921
922static int ati_remote2_pre_reset(struct usb_interface *interface)
923{
924 struct ati_remote2 *ar2;
925 struct usb_host_interface *alt = interface->cur_altsetting;
926
927 if (alt->desc.bInterfaceNumber)
928 return 0;
929
930 ar2 = usb_get_intfdata(interface);
931
932 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
933
934 mutex_lock(&ati_remote2_mutex);
935
936 if (ar2->flags == ATI_REMOTE2_OPENED)
937 ati_remote2_kill_urbs(ar2);
938
939 return 0;
940}
941
942static int ati_remote2_post_reset(struct usb_interface *interface)
943{
944 struct ati_remote2 *ar2;
945 struct usb_host_interface *alt = interface->cur_altsetting;
946 int r = 0;
947
948 if (alt->desc.bInterfaceNumber)
949 return 0;
950
951 ar2 = usb_get_intfdata(interface);
952
953 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
954
955 if (ar2->flags == ATI_REMOTE2_OPENED)
956 r = ati_remote2_submit_urbs(ar2);
957
958 mutex_unlock(&ati_remote2_mutex);
959
960 return r;
961}
962
718static int __init ati_remote2_init(void) 963static int __init ati_remote2_init(void)
719{ 964{
720 int r; 965 int r;
diff --git a/drivers/input/misc/rb532_button.c b/drivers/input/misc/rb532_button.c
new file mode 100644
index 000000000000..e2c7f622a0b5
--- /dev/null
+++ b/drivers/input/misc/rb532_button.c
@@ -0,0 +1,120 @@
1/*
2 * Support for the S1 button on Routerboard 532
3 *
4 * Copyright (C) 2009 Phil Sutter <n0-1@freewrt.org>
5 */
6
7#include <linux/input-polldev.h>
8#include <linux/module.h>
9#include <linux/platform_device.h>
10
11#include <asm/mach-rc32434/gpio.h>
12#include <asm/mach-rc32434/rb.h>
13
14#define DRV_NAME "rb532-button"
15
16#define RB532_BTN_RATE 100 /* msec */
17#define RB532_BTN_KSYM BTN_0
18
19/* The S1 button state is provided by GPIO pin 1. But as this
20 * pin is also used for uart input as alternate function, the
21 * operational modes must be switched first:
22 * 1) disable uart using set_latch_u5()
23 * 2) turn off alternate function implicitly through
24 * gpio_direction_input()
25 * 3) read the GPIO's current value
26 * 4) undo step 2 by enabling alternate function (in this
27 * mode the GPIO direction is fixed, so no change needed)
28 * 5) turn on uart again
29 * The GPIO value occurs to be inverted, so pin high means
30 * button is not pressed.
31 */
32static bool rb532_button_pressed(void)
33{
34 int val;
35
36 set_latch_u5(0, LO_FOFF);
37 gpio_direction_input(GPIO_BTN_S1);
38
39 val = gpio_get_value(GPIO_BTN_S1);
40
41 rb532_gpio_set_func(GPIO_BTN_S1);
42 set_latch_u5(LO_FOFF, 0);
43
44 return !val;
45}
46
47static void rb532_button_poll(struct input_polled_dev *poll_dev)
48{
49 input_report_key(poll_dev->input, RB532_BTN_KSYM,
50 rb532_button_pressed());
51 input_sync(poll_dev->input);
52}
53
54static int __devinit rb532_button_probe(struct platform_device *pdev)
55{
56 struct input_polled_dev *poll_dev;
57 int error;
58
59 poll_dev = input_allocate_polled_device();
60 if (!poll_dev)
61 return -ENOMEM;
62
63 poll_dev->poll = rb532_button_poll;
64 poll_dev->poll_interval = RB532_BTN_RATE;
65
66 poll_dev->input->name = "rb532 button";
67 poll_dev->input->phys = "rb532/button0";
68 poll_dev->input->id.bustype = BUS_HOST;
69 poll_dev->input->dev.parent = &pdev->dev;
70
71 dev_set_drvdata(&pdev->dev, poll_dev);
72
73 input_set_capability(poll_dev->input, EV_KEY, RB532_BTN_KSYM);
74
75 error = input_register_polled_device(poll_dev);
76 if (error) {
77 input_free_polled_device(poll_dev);
78 return error;
79 }
80
81 return 0;
82}
83
84static int __devexit rb532_button_remove(struct platform_device *pdev)
85{
86 struct input_polled_dev *poll_dev = dev_get_drvdata(&pdev->dev);
87
88 input_unregister_polled_device(poll_dev);
89 input_free_polled_device(poll_dev);
90 dev_set_drvdata(&pdev->dev, NULL);
91
92 return 0;
93}
94
95static struct platform_driver rb532_button_driver = {
96 .probe = rb532_button_probe,
97 .remove = __devexit_p(rb532_button_remove),
98 .driver = {
99 .name = DRV_NAME,
100 .owner = THIS_MODULE,
101 },
102};
103
104static int __init rb532_button_init(void)
105{
106 return platform_driver_register(&rb532_button_driver);
107}
108
109static void __exit rb532_button_exit(void)
110{
111 platform_driver_unregister(&rb532_button_driver);
112}
113
114module_init(rb532_button_init);
115module_exit(rb532_button_exit);
116
117MODULE_AUTHOR("Phil Sutter <n0-1@freewrt.org>");
118MODULE_LICENSE("GPL");
119MODULE_DESCRIPTION("Support for S1 button on Routerboard 532");
120MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c
new file mode 100644
index 000000000000..5bb3ab51b8c6
--- /dev/null
+++ b/drivers/input/misc/rotary_encoder.c
@@ -0,0 +1,221 @@
1/*
2 * rotary_encoder.c
3 *
4 * (c) 2009 Daniel Mack <daniel@caiaq.de>
5 *
6 * state machine code inspired by code from Tim Ruetz
7 *
8 * A generic driver for rotary encoders connected to GPIO lines.
9 * See file:Documentation/input/rotary_encoder.txt for more information
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/interrupt.h>
20#include <linux/input.h>
21#include <linux/device.h>
22#include <linux/platform_device.h>
23#include <linux/gpio.h>
24#include <linux/rotary_encoder.h>
25
26#define DRV_NAME "rotary-encoder"
27
28struct rotary_encoder {
29 unsigned int irq_a;
30 unsigned int irq_b;
31 unsigned int pos;
32 unsigned int armed;
33 unsigned int dir;
34 struct input_dev *input;
35 struct rotary_encoder_platform_data *pdata;
36};
37
38static irqreturn_t rotary_encoder_irq(int irq, void *dev_id)
39{
40 struct rotary_encoder *encoder = dev_id;
41 struct rotary_encoder_platform_data *pdata = encoder->pdata;
42 int a = !!gpio_get_value(pdata->gpio_a);
43 int b = !!gpio_get_value(pdata->gpio_b);
44 int state;
45
46 a ^= pdata->inverted_a;
47 b ^= pdata->inverted_b;
48 state = (a << 1) | b;
49
50 switch (state) {
51
52 case 0x0:
53 if (!encoder->armed)
54 break;
55
56 if (encoder->dir) {
57 /* turning counter-clockwise */
58 encoder->pos += pdata->steps;
59 encoder->pos--;
60 encoder->pos %= pdata->steps;
61 } else {
62 /* turning clockwise */
63 encoder->pos++;
64 encoder->pos %= pdata->steps;
65 }
66
67 input_report_abs(encoder->input, pdata->axis, encoder->pos);
68 input_sync(encoder->input);
69
70 encoder->armed = 0;
71 break;
72
73 case 0x1:
74 case 0x2:
75 if (encoder->armed)
76 encoder->dir = state - 1;
77 break;
78
79 case 0x3:
80 encoder->armed = 1;
81 break;
82 }
83
84 return IRQ_HANDLED;
85}
86
87static int __devinit rotary_encoder_probe(struct platform_device *pdev)
88{
89 struct rotary_encoder_platform_data *pdata = pdev->dev.platform_data;
90 struct rotary_encoder *encoder;
91 struct input_dev *input;
92 int err;
93
94 if (!pdata || !pdata->steps) {
95 dev_err(&pdev->dev, "invalid platform data\n");
96 return -ENOENT;
97 }
98
99 encoder = kzalloc(sizeof(struct rotary_encoder), GFP_KERNEL);
100 input = input_allocate_device();
101 if (!encoder || !input) {
102 dev_err(&pdev->dev, "failed to allocate memory for device\n");
103 err = -ENOMEM;
104 goto exit_free_mem;
105 }
106
107 encoder->input = input;
108 encoder->pdata = pdata;
109 encoder->irq_a = gpio_to_irq(pdata->gpio_a);
110 encoder->irq_b = gpio_to_irq(pdata->gpio_b);
111
112 /* create and register the input driver */
113 input->name = pdev->name;
114 input->id.bustype = BUS_HOST;
115 input->dev.parent = &pdev->dev;
116 input->evbit[0] = BIT_MASK(EV_ABS);
117 input_set_abs_params(encoder->input,
118 pdata->axis, 0, pdata->steps, 0, 1);
119
120 err = input_register_device(input);
121 if (err) {
122 dev_err(&pdev->dev, "failed to register input device\n");
123 goto exit_free_mem;
124 }
125
126 /* request the GPIOs */
127 err = gpio_request(pdata->gpio_a, DRV_NAME);
128 if (err) {
129 dev_err(&pdev->dev, "unable to request GPIO %d\n",
130 pdata->gpio_a);
131 goto exit_unregister_input;
132 }
133
134 err = gpio_request(pdata->gpio_b, DRV_NAME);
135 if (err) {
136 dev_err(&pdev->dev, "unable to request GPIO %d\n",
137 pdata->gpio_b);
138 goto exit_free_gpio_a;
139 }
140
141 /* request the IRQs */
142 err = request_irq(encoder->irq_a, &rotary_encoder_irq,
143 IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
144 DRV_NAME, encoder);
145 if (err) {
146 dev_err(&pdev->dev, "unable to request IRQ %d\n",
147 encoder->irq_a);
148 goto exit_free_gpio_b;
149 }
150
151 err = request_irq(encoder->irq_b, &rotary_encoder_irq,
152 IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
153 DRV_NAME, encoder);
154 if (err) {
155 dev_err(&pdev->dev, "unable to request IRQ %d\n",
156 encoder->irq_b);
157 goto exit_free_irq_a;
158 }
159
160 platform_set_drvdata(pdev, encoder);
161
162 return 0;
163
164exit_free_irq_a:
165 free_irq(encoder->irq_a, encoder);
166exit_free_gpio_b:
167 gpio_free(pdata->gpio_b);
168exit_free_gpio_a:
169 gpio_free(pdata->gpio_a);
170exit_unregister_input:
171 input_unregister_device(input);
172 input = NULL; /* so we don't try to free it */
173exit_free_mem:
174 input_free_device(input);
175 kfree(encoder);
176 return err;
177}
178
179static int __devexit rotary_encoder_remove(struct platform_device *pdev)
180{
181 struct rotary_encoder *encoder = platform_get_drvdata(pdev);
182 struct rotary_encoder_platform_data *pdata = pdev->dev.platform_data;
183
184 free_irq(encoder->irq_a, encoder);
185 free_irq(encoder->irq_b, encoder);
186 gpio_free(pdata->gpio_a);
187 gpio_free(pdata->gpio_b);
188 input_unregister_device(encoder->input);
189 platform_set_drvdata(pdev, NULL);
190 kfree(encoder);
191
192 return 0;
193}
194
195static struct platform_driver rotary_encoder_driver = {
196 .probe = rotary_encoder_probe,
197 .remove = __devexit_p(rotary_encoder_remove),
198 .driver = {
199 .name = DRV_NAME,
200 .owner = THIS_MODULE,
201 }
202};
203
204static int __init rotary_encoder_init(void)
205{
206 return platform_driver_register(&rotary_encoder_driver);
207}
208
209static void __exit rotary_encoder_exit(void)
210{
211 platform_driver_unregister(&rotary_encoder_driver);
212}
213
214module_init(rotary_encoder_init);
215module_exit(rotary_encoder_exit);
216
217MODULE_ALIAS("platform:" DRV_NAME);
218MODULE_DESCRIPTION("GPIO rotary encoder driver");
219MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
220MODULE_LICENSE("GPL v2");
221