diff options
author | Thomas Bogendoerfer <tsbogend@alpha.franken.de> | 2008-07-07 09:07:31 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2008-07-07 09:08:07 -0400 |
commit | 3bee2a04cf14f599e094a37445f2eb4e6bb316bc (patch) | |
tree | 4f89e4915ced3cd3fa89f218ac220dc248490062 | |
parent | b4ecda3e965a87881a94017cb0cd484d65799261 (diff) |
Input: new driver for SGI O2 volume buttons
This driver adds support for the volume buttons on the front of every
SGI O2 workstation.
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
-rw-r--r-- | drivers/input/misc/Kconfig | 10 | ||||
-rw-r--r-- | drivers/input/misc/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/misc/sgio2_btns.c | 156 |
3 files changed, 167 insertions, 0 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 432699d61c58..e33d7cbcb1df 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig | |||
@@ -189,6 +189,16 @@ config INPUT_UINPUT | |||
189 | To compile this driver as a module, choose M here: the | 189 | To compile this driver as a module, choose M here: the |
190 | module will be called uinput. | 190 | module will be called uinput. |
191 | 191 | ||
192 | config INPUT_SGIO2_BTNS | ||
193 | tristate "SGI O2 volume button interface" | ||
194 | depends on SGI_IP32 | ||
195 | select INPUT_POLLDEV | ||
196 | help | ||
197 | Say Y here if you want to support SGI O2 volume button interface. | ||
198 | |||
199 | To compile this driver as a module, choose M here: the | ||
200 | module will be called sgio_btns. | ||
201 | |||
192 | config HP_SDC_RTC | 202 | config HP_SDC_RTC |
193 | tristate "HP SDC Real Time Clock" | 203 | tristate "HP SDC Real Time Clock" |
194 | depends on GSC || HP300 | 204 | depends on GSC || HP300 |
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index ebd39f291d25..0e274f19bcb3 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile | |||
@@ -19,3 +19,4 @@ obj-$(CONFIG_INPUT_YEALINK) += yealink.o | |||
19 | obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o | 19 | obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o |
20 | obj-$(CONFIG_INPUT_UINPUT) += uinput.o | 20 | obj-$(CONFIG_INPUT_UINPUT) += uinput.o |
21 | obj-$(CONFIG_INPUT_APANEL) += apanel.o | 21 | obj-$(CONFIG_INPUT_APANEL) += apanel.o |
22 | obj-$(CONFIG_INPUT_SGIO2_BTNS) += sgio2_btns.o | ||
diff --git a/drivers/input/misc/sgio2_btns.c b/drivers/input/misc/sgio2_btns.c new file mode 100644 index 000000000000..b1ab43d903dd --- /dev/null +++ b/drivers/input/misc/sgio2_btns.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * SGI O2 Volume Button interface driver | ||
3 | * | ||
4 | * Copyright (C) 2008 Thomas Bogendoerfer <tsbogend@alpha.franken.de> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/input-polldev.h> | ||
22 | #include <linux/ioport.h> | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | |||
26 | #include <asm/ip32/mace.h> | ||
27 | |||
28 | #define BUTTONS_POLL_INTERVAL 30 /* msec */ | ||
29 | #define BUTTONS_COUNT_THRESHOLD 3 | ||
30 | |||
31 | static const unsigned short sgio2_map[] = { | ||
32 | KEY_VOLUMEUP, | ||
33 | KEY_VOLUMEDOWN | ||
34 | }; | ||
35 | |||
36 | struct buttons_dev { | ||
37 | struct input_polled_dev *poll_dev; | ||
38 | unsigned short keymap[ARRAY_SIZE(sgio2_map)]; | ||
39 | int count[ARRAY_SIZE(sgio2_map)]; | ||
40 | void __iomem *reg; | ||
41 | }; | ||
42 | |||
43 | static void handle_buttons(struct input_polled_dev *dev) | ||
44 | { | ||
45 | struct buttons_dev *bdev = dev->private; | ||
46 | struct input_dev *input = dev->input; | ||
47 | u64 status; | ||
48 | int i; | ||
49 | |||
50 | status = (readq(&mace->perif.audio.control) >> 23) & 3; | ||
51 | |||
52 | for (i = 0; i < ARRAY_SIZE(bdev->keymap); i++) { | ||
53 | if (status & (1U << i)) { | ||
54 | writeq(status & ~(1U << i), &mace->perif.audio.control); | ||
55 | if (++bdev->count[i] == BUTTONS_COUNT_THRESHOLD) { | ||
56 | input_event(input, EV_MSC, MSC_SCAN, i); | ||
57 | input_report_key(input, bdev->keymap[i], 1); | ||
58 | input_sync(input); | ||
59 | } | ||
60 | } else { | ||
61 | if (bdev->count[i] >= BUTTONS_COUNT_THRESHOLD) { | ||
62 | input_event(input, EV_MSC, MSC_SCAN, i); | ||
63 | input_report_key(input, bdev->keymap[i], 0); | ||
64 | input_sync(input); | ||
65 | } | ||
66 | bdev->count[i] = 0; | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | static int __devinit sgio2_buttons_probe(struct platform_device *pdev) | ||
72 | { | ||
73 | struct buttons_dev *bdev; | ||
74 | struct input_polled_dev *poll_dev; | ||
75 | struct input_dev *input; | ||
76 | int error, i; | ||
77 | |||
78 | bdev = kzalloc(sizeof(struct buttons_dev), GFP_KERNEL); | ||
79 | poll_dev = input_allocate_polled_device(); | ||
80 | if (!bdev || !poll_dev) { | ||
81 | error = -ENOMEM; | ||
82 | goto err_free_mem; | ||
83 | } | ||
84 | |||
85 | memcpy(bdev->keymap, sgio2_map, sizeof(bdev->keymap)); | ||
86 | |||
87 | poll_dev->private = bdev; | ||
88 | poll_dev->poll = handle_buttons; | ||
89 | poll_dev->poll_interval = BUTTONS_POLL_INTERVAL; | ||
90 | |||
91 | input = poll_dev->input; | ||
92 | input->name = "SGI O2 buttons"; | ||
93 | input->phys = "sgio2/input0"; | ||
94 | input->id.bustype = BUS_HOST; | ||
95 | input->dev.parent = &pdev->dev; | ||
96 | |||
97 | input->keycode = bdev->keymap; | ||
98 | input->keycodemax = ARRAY_SIZE(bdev->keymap); | ||
99 | input->keycodesize = sizeof(unsigned short); | ||
100 | |||
101 | input_set_capability(input, EV_MSC, MSC_SCAN); | ||
102 | __set_bit(EV_KEY, input->evbit); | ||
103 | for (i = 0; i < ARRAY_SIZE(sgio2_map); i++) | ||
104 | __set_bit(bdev->keymap[i], input->keybit); | ||
105 | __clear_bit(KEY_RESERVED, input->keybit); | ||
106 | |||
107 | bdev->poll_dev = poll_dev; | ||
108 | dev_set_drvdata(&pdev->dev, bdev); | ||
109 | |||
110 | error = input_register_polled_device(poll_dev); | ||
111 | if (error) | ||
112 | goto err_free_mem; | ||
113 | |||
114 | return 0; | ||
115 | |||
116 | err_free_mem: | ||
117 | input_free_polled_device(poll_dev); | ||
118 | kfree(bdev); | ||
119 | dev_set_drvdata(&pdev->dev, NULL); | ||
120 | return error; | ||
121 | } | ||
122 | |||
123 | static int __devexit sgio2_buttons_remove(struct platform_device *pdev) | ||
124 | { | ||
125 | struct device *dev = &pdev->dev; | ||
126 | struct buttons_dev *bdev = dev_get_drvdata(dev); | ||
127 | |||
128 | input_unregister_polled_device(bdev->poll_dev); | ||
129 | input_free_polled_device(bdev->poll_dev); | ||
130 | kfree(bdev); | ||
131 | dev_set_drvdata(dev, NULL); | ||
132 | |||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | static struct platform_driver sgio2_buttons_driver = { | ||
137 | .probe = sgio2_buttons_probe, | ||
138 | .remove = __devexit_p(sgio2_buttons_remove), | ||
139 | .driver = { | ||
140 | .name = "sgio2btns", | ||
141 | .owner = THIS_MODULE, | ||
142 | }, | ||
143 | }; | ||
144 | |||
145 | static int __init sgio2_buttons_init(void) | ||
146 | { | ||
147 | return platform_driver_register(&sgio2_buttons_driver); | ||
148 | } | ||
149 | |||
150 | static void __exit sgio2_buttons_exit(void) | ||
151 | { | ||
152 | platform_driver_unregister(&sgio2_buttons_driver); | ||
153 | } | ||
154 | |||
155 | module_init(sgio2_buttons_init); | ||
156 | module_exit(sgio2_buttons_exit); | ||