diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-06 20:14:01 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-06 20:14:01 -0500 |
commit | db30c70575822cc84d87b5613c19cac24734b99f (patch) | |
tree | 82945ad5813bfe6633698233981d270b5f0a310b /drivers/input/joystick | |
parent | c861ea2cb2c25c1698734d9b0540a09e253690a1 (diff) | |
parent | 9334e90d5ac5ee1fa6d8b75acb7c64a8907787d1 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (29 commits)
Input: i8042 - add Dell Vostro 1510 to nomux list
Input: gtco - use USB endpoint API
Input: add support for Maple controller as a joystick
Input: atkbd - broaden the Dell DMI signatures
Input: HIL drivers - add MODULE_ALIAS()
Input: map_to_7segment.h - convert to __inline__ for userspace
Input: add support for enhanced rotary controller on pxa930 and pxa935
Input: add support for trackball on pxa930 and pxa935
Input: add da9034 touchscreen support
Input: ads7846 - strict_strtoul takes unsigned long
Input: make some variables and functions static
Input: add tsc2007 based touchscreen driver
Input: psmouse - add module parameters to control OLPC touchpad delays
Input: i8042 - add Gigabyte M912 netbook to noloop exception table
Input: atkbd - Samsung NC10 key repeat fix
Input: atkbd - add keyboard quirk for HP Pavilion ZV6100 laptop
Input: libps2 - handle 0xfc responses from devices
Input: add support for Wacom W8001 penabled serial touchscreen
Input: synaptics - report multi-taps only if supported by the device
Input: add joystick driver for Walkera WK-0701 RC transmitter
...
Diffstat (limited to 'drivers/input/joystick')
-rw-r--r-- | drivers/input/joystick/Kconfig | 24 | ||||
-rw-r--r-- | drivers/input/joystick/Makefile | 2 | ||||
-rw-r--r-- | drivers/input/joystick/maplecontrol.c | 193 | ||||
-rw-r--r-- | drivers/input/joystick/walkera0701.c | 292 |
4 files changed, 511 insertions, 0 deletions
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig index be5c14a5a0a4..b11419590cfe 100644 --- a/drivers/input/joystick/Kconfig +++ b/drivers/input/joystick/Kconfig | |||
@@ -294,4 +294,28 @@ config JOYSTICK_XPAD_LEDS | |||
294 | This option enables support for the LED which surrounds the Big X on | 294 | This option enables support for the LED which surrounds the Big X on |
295 | XBox 360 controller. | 295 | XBox 360 controller. |
296 | 296 | ||
297 | config JOYSTICK_WALKERA0701 | ||
298 | tristate "Walkera WK-0701 RC transmitter" | ||
299 | depends on HIGH_RES_TIMERS && PARPORT | ||
300 | help | ||
301 | Say Y or M here if you have a Walkera WK-0701 transmitter which is | ||
302 | supplied with a ready to fly Walkera helicopters such as HM36, | ||
303 | HM37, HM60 and want to use it via parport as a joystick. More | ||
304 | information is available: <file:Documentation/input/walkera0701.txt> | ||
305 | |||
306 | To compile this driver as a module, choose M here: the | ||
307 | module will be called walkera0701. | ||
308 | |||
309 | config JOYSTICK_MAPLE | ||
310 | tristate "Dreamcast control pad" | ||
311 | depends on MAPLE | ||
312 | help | ||
313 | Say Y here if you have a SEGA Dreamcast and want to use your | ||
314 | controller as a joystick. | ||
315 | |||
316 | Most Dreamcast users will say Y. | ||
317 | |||
318 | To compile this as a module choose M here: the module will be called | ||
319 | maplecontrol. | ||
320 | |||
297 | endif | 321 | endif |
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile index fdbf8c4c2876..f3a8cbe2abb6 100644 --- a/drivers/input/joystick/Makefile +++ b/drivers/input/joystick/Makefile | |||
@@ -19,6 +19,7 @@ obj-$(CONFIG_JOYSTICK_IFORCE) += iforce/ | |||
19 | obj-$(CONFIG_JOYSTICK_INTERACT) += interact.o | 19 | obj-$(CONFIG_JOYSTICK_INTERACT) += interact.o |
20 | obj-$(CONFIG_JOYSTICK_JOYDUMP) += joydump.o | 20 | obj-$(CONFIG_JOYSTICK_JOYDUMP) += joydump.o |
21 | obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o | 21 | obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o |
22 | obj-$(CONFIG_JOYSTICK_MAPLE) += maplecontrol.o | ||
22 | obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o | 23 | obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o |
23 | obj-$(CONFIG_JOYSTICK_SPACEBALL) += spaceball.o | 24 | obj-$(CONFIG_JOYSTICK_SPACEBALL) += spaceball.o |
24 | obj-$(CONFIG_JOYSTICK_SPACEORB) += spaceorb.o | 25 | obj-$(CONFIG_JOYSTICK_SPACEORB) += spaceorb.o |
@@ -29,4 +30,5 @@ obj-$(CONFIG_JOYSTICK_TWIDJOY) += twidjoy.o | |||
29 | obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o | 30 | obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o |
30 | obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o | 31 | obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o |
31 | obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o | 32 | obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o |
33 | obj-$(CONFIG_JOYSTICK_WALKERA0701) += walkera0701.o | ||
32 | 34 | ||
diff --git a/drivers/input/joystick/maplecontrol.c b/drivers/input/joystick/maplecontrol.c new file mode 100644 index 000000000000..e50047bfe938 --- /dev/null +++ b/drivers/input/joystick/maplecontrol.c | |||
@@ -0,0 +1,193 @@ | |||
1 | /* | ||
2 | * SEGA Dreamcast controller driver | ||
3 | * Based on drivers/usb/iforce.c | ||
4 | * | ||
5 | * Copyright Yaegashi Takeshi, 2001 | ||
6 | * Adrian McMenamin, 2008 | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/slab.h> | ||
11 | #include <linux/input.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/timer.h> | ||
15 | #include <linux/maple.h> | ||
16 | |||
17 | MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>"); | ||
18 | MODULE_DESCRIPTION("SEGA Dreamcast controller driver"); | ||
19 | MODULE_LICENSE("GPL"); | ||
20 | |||
21 | struct dc_pad { | ||
22 | struct input_dev *dev; | ||
23 | struct maple_device *mdev; | ||
24 | }; | ||
25 | |||
26 | static void dc_pad_callback(struct mapleq *mq) | ||
27 | { | ||
28 | unsigned short buttons; | ||
29 | struct maple_device *mapledev = mq->dev; | ||
30 | struct dc_pad *pad = maple_get_drvdata(mapledev); | ||
31 | struct input_dev *dev = pad->dev; | ||
32 | unsigned char *res = mq->recvbuf; | ||
33 | |||
34 | buttons = ~le16_to_cpup((__le16 *)(res + 8)); | ||
35 | |||
36 | input_report_abs(dev, ABS_HAT0Y, | ||
37 | (buttons & 0x0010 ? -1 : 0) + (buttons & 0x0020 ? 1 : 0)); | ||
38 | input_report_abs(dev, ABS_HAT0X, | ||
39 | (buttons & 0x0040 ? -1 : 0) + (buttons & 0x0080 ? 1 : 0)); | ||
40 | input_report_abs(dev, ABS_HAT1Y, | ||
41 | (buttons & 0x1000 ? -1 : 0) + (buttons & 0x2000 ? 1 : 0)); | ||
42 | input_report_abs(dev, ABS_HAT1X, | ||
43 | (buttons & 0x4000 ? -1 : 0) + (buttons & 0x8000 ? 1 : 0)); | ||
44 | |||
45 | input_report_key(dev, BTN_C, buttons & 0x0001); | ||
46 | input_report_key(dev, BTN_B, buttons & 0x0002); | ||
47 | input_report_key(dev, BTN_A, buttons & 0x0004); | ||
48 | input_report_key(dev, BTN_START, buttons & 0x0008); | ||
49 | input_report_key(dev, BTN_Z, buttons & 0x0100); | ||
50 | input_report_key(dev, BTN_Y, buttons & 0x0200); | ||
51 | input_report_key(dev, BTN_X, buttons & 0x0400); | ||
52 | input_report_key(dev, BTN_SELECT, buttons & 0x0800); | ||
53 | |||
54 | input_report_abs(dev, ABS_GAS, res[10]); | ||
55 | input_report_abs(dev, ABS_BRAKE, res[11]); | ||
56 | input_report_abs(dev, ABS_X, res[12]); | ||
57 | input_report_abs(dev, ABS_Y, res[13]); | ||
58 | input_report_abs(dev, ABS_RX, res[14]); | ||
59 | input_report_abs(dev, ABS_RY, res[15]); | ||
60 | } | ||
61 | |||
62 | static int dc_pad_open(struct input_dev *dev) | ||
63 | { | ||
64 | struct dc_pad *pad = dev->dev.platform_data; | ||
65 | |||
66 | maple_getcond_callback(pad->mdev, dc_pad_callback, HZ/20, | ||
67 | MAPLE_FUNC_CONTROLLER); | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static void dc_pad_close(struct input_dev *dev) | ||
73 | { | ||
74 | struct dc_pad *pad = dev->dev.platform_data; | ||
75 | |||
76 | maple_getcond_callback(pad->mdev, dc_pad_callback, 0, | ||
77 | MAPLE_FUNC_CONTROLLER); | ||
78 | } | ||
79 | |||
80 | /* allow the controller to be used */ | ||
81 | static int __devinit probe_maple_controller(struct device *dev) | ||
82 | { | ||
83 | static const short btn_bit[32] = { | ||
84 | BTN_C, BTN_B, BTN_A, BTN_START, -1, -1, -1, -1, | ||
85 | BTN_Z, BTN_Y, BTN_X, BTN_SELECT, -1, -1, -1, -1, | ||
86 | -1, -1, -1, -1, -1, -1, -1, -1, | ||
87 | -1, -1, -1, -1, -1, -1, -1, -1, | ||
88 | }; | ||
89 | |||
90 | static const short abs_bit[32] = { | ||
91 | -1, -1, -1, -1, ABS_HAT0Y, ABS_HAT0Y, ABS_HAT0X, ABS_HAT0X, | ||
92 | -1, -1, -1, -1, ABS_HAT1Y, ABS_HAT1Y, ABS_HAT1X, ABS_HAT1X, | ||
93 | ABS_GAS, ABS_BRAKE, ABS_X, ABS_Y, ABS_RX, ABS_RY, -1, -1, | ||
94 | -1, -1, -1, -1, -1, -1, -1, -1, | ||
95 | }; | ||
96 | |||
97 | struct maple_device *mdev = to_maple_dev(dev); | ||
98 | struct maple_driver *mdrv = to_maple_driver(dev->driver); | ||
99 | int i, error; | ||
100 | struct dc_pad *pad; | ||
101 | struct input_dev *idev; | ||
102 | unsigned long data = be32_to_cpu(mdev->devinfo.function_data[0]); | ||
103 | |||
104 | pad = kzalloc(sizeof(struct dc_pad), GFP_KERNEL); | ||
105 | idev = input_allocate_device(); | ||
106 | if (!pad || !idev) { | ||
107 | error = -ENOMEM; | ||
108 | goto fail; | ||
109 | } | ||
110 | |||
111 | pad->dev = idev; | ||
112 | pad->mdev = mdev; | ||
113 | |||
114 | idev->open = dc_pad_open; | ||
115 | idev->close = dc_pad_close; | ||
116 | |||
117 | for (i = 0; i < 32; i++) { | ||
118 | if (data & (1 << i)) { | ||
119 | if (btn_bit[i] >= 0) | ||
120 | __set_bit(btn_bit[i], idev->keybit); | ||
121 | else if (abs_bit[i] >= 0) | ||
122 | __set_bit(abs_bit[i], idev->absbit); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | if (idev->keybit[BIT_WORD(BTN_JOYSTICK)]) | ||
127 | idev->evbit[0] |= BIT_MASK(EV_KEY); | ||
128 | |||
129 | if (idev->absbit[0]) | ||
130 | idev->evbit[0] |= BIT_MASK(EV_ABS); | ||
131 | |||
132 | for (i = ABS_X; i <= ABS_BRAKE; i++) | ||
133 | input_set_abs_params(idev, i, 0, 255, 0, 0); | ||
134 | |||
135 | for (i = ABS_HAT0X; i <= ABS_HAT3Y; i++) | ||
136 | input_set_abs_params(idev, i, 1, -1, 0, 0); | ||
137 | |||
138 | idev->dev.platform_data = pad; | ||
139 | idev->dev.parent = &mdev->dev; | ||
140 | idev->name = mdev->product_name; | ||
141 | idev->id.bustype = BUS_HOST; | ||
142 | input_set_drvdata(idev, pad); | ||
143 | |||
144 | error = input_register_device(idev); | ||
145 | if (error) | ||
146 | goto fail; | ||
147 | |||
148 | mdev->driver = mdrv; | ||
149 | maple_set_drvdata(mdev, pad); | ||
150 | |||
151 | return 0; | ||
152 | |||
153 | fail: | ||
154 | input_free_device(idev); | ||
155 | kfree(pad); | ||
156 | maple_set_drvdata(mdev, NULL); | ||
157 | return error; | ||
158 | } | ||
159 | |||
160 | static int __devexit remove_maple_controller(struct device *dev) | ||
161 | { | ||
162 | struct maple_device *mdev = to_maple_dev(dev); | ||
163 | struct dc_pad *pad = maple_get_drvdata(mdev); | ||
164 | |||
165 | mdev->callback = NULL; | ||
166 | input_unregister_device(pad->dev); | ||
167 | maple_set_drvdata(mdev, NULL); | ||
168 | kfree(pad); | ||
169 | |||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | static struct maple_driver dc_pad_driver = { | ||
174 | .function = MAPLE_FUNC_CONTROLLER, | ||
175 | .drv = { | ||
176 | .name = "Dreamcast_controller", | ||
177 | .probe = probe_maple_controller, | ||
178 | .remove = __devexit_p(remove_maple_controller), | ||
179 | }, | ||
180 | }; | ||
181 | |||
182 | static int __init dc_pad_init(void) | ||
183 | { | ||
184 | return maple_driver_register(&dc_pad_driver); | ||
185 | } | ||
186 | |||
187 | static void __exit dc_pad_exit(void) | ||
188 | { | ||
189 | maple_driver_unregister(&dc_pad_driver); | ||
190 | } | ||
191 | |||
192 | module_init(dc_pad_init); | ||
193 | module_exit(dc_pad_exit); | ||
diff --git a/drivers/input/joystick/walkera0701.c b/drivers/input/joystick/walkera0701.c new file mode 100644 index 000000000000..4dfa1eed4b7c --- /dev/null +++ b/drivers/input/joystick/walkera0701.c | |||
@@ -0,0 +1,292 @@ | |||
1 | /* | ||
2 | * Parallel port to Walkera WK-0701 TX joystick | ||
3 | * | ||
4 | * Copyright (c) 2008 Peter Popovec | ||
5 | * | ||
6 | * More about driver: <file:Documentation/input/walkera0701.txt> | ||
7 | */ | ||
8 | |||
9 | /* | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License version 2 as published by | ||
12 | * the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | /* #define WK0701_DEBUG */ | ||
16 | |||
17 | #define RESERVE 20000 | ||
18 | #define SYNC_PULSE 1306000 | ||
19 | #define BIN0_PULSE 288000 | ||
20 | #define BIN1_PULSE 438000 | ||
21 | |||
22 | #define ANALOG_MIN_PULSE 318000 | ||
23 | #define ANALOG_MAX_PULSE 878000 | ||
24 | #define ANALOG_DELTA 80000 | ||
25 | |||
26 | #define BIN_SAMPLE ((BIN0_PULSE + BIN1_PULSE) / 2) | ||
27 | |||
28 | #define NO_SYNC 25 | ||
29 | |||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/parport.h> | ||
33 | #include <linux/input.h> | ||
34 | #include <linux/hrtimer.h> | ||
35 | |||
36 | MODULE_AUTHOR("Peter Popovec <popovec@fei.tuke.sk>"); | ||
37 | MODULE_DESCRIPTION("Walkera WK-0701 TX as joystick"); | ||
38 | MODULE_LICENSE("GPL"); | ||
39 | |||
40 | static unsigned int walkera0701_pp_no; | ||
41 | module_param_named(port, walkera0701_pp_no, int, 0); | ||
42 | MODULE_PARM_DESC(port, | ||
43 | "Parallel port adapter for Walkera WK-0701 TX (default is 0)"); | ||
44 | |||
45 | /* | ||
46 | * For now, only one device is supported, if somebody need more devices, code | ||
47 | * can be expanded, one struct walkera_dev per device must be allocated and | ||
48 | * set up by walkera0701_connect (release of device by walkera0701_disconnect) | ||
49 | */ | ||
50 | |||
51 | struct walkera_dev { | ||
52 | unsigned char buf[25]; | ||
53 | u64 irq_time, irq_lasttime; | ||
54 | int counter; | ||
55 | int ack; | ||
56 | |||
57 | struct input_dev *input_dev; | ||
58 | struct hrtimer timer; | ||
59 | |||
60 | struct parport *parport; | ||
61 | struct pardevice *pardevice; | ||
62 | }; | ||
63 | |||
64 | static struct walkera_dev w_dev; | ||
65 | |||
66 | static inline void walkera0701_parse_frame(struct walkera_dev *w) | ||
67 | { | ||
68 | int i; | ||
69 | int val1, val2, val3, val4, val5, val6, val7, val8; | ||
70 | int crc1, crc2; | ||
71 | |||
72 | for (crc1 = crc2 = i = 0; i < 10; i++) { | ||
73 | crc1 += w->buf[i] & 7; | ||
74 | crc2 += (w->buf[i] & 8) >> 3; | ||
75 | } | ||
76 | if ((w->buf[10] & 7) != (crc1 & 7)) | ||
77 | return; | ||
78 | if (((w->buf[10] & 8) >> 3) != (((crc1 >> 3) + crc2) & 1)) | ||
79 | return; | ||
80 | for (crc1 = crc2 = 0, i = 11; i < 23; i++) { | ||
81 | crc1 += w->buf[i] & 7; | ||
82 | crc2 += (w->buf[i] & 8) >> 3; | ||
83 | } | ||
84 | if ((w->buf[23] & 7) != (crc1 & 7)) | ||
85 | return; | ||
86 | if (((w->buf[23] & 8) >> 3) != (((crc1 >> 3) + crc2) & 1)) | ||
87 | return; | ||
88 | val1 = ((w->buf[0] & 7) * 256 + w->buf[1] * 16 + w->buf[2]) >> 2; | ||
89 | val1 *= ((w->buf[0] >> 2) & 2) - 1; /* sign */ | ||
90 | val2 = (w->buf[2] & 1) << 8 | (w->buf[3] << 4) | w->buf[4]; | ||
91 | val2 *= (w->buf[2] & 2) - 1; /* sign */ | ||
92 | val3 = ((w->buf[5] & 7) * 256 + w->buf[6] * 16 + w->buf[7]) >> 2; | ||
93 | val3 *= ((w->buf[5] >> 2) & 2) - 1; /* sign */ | ||
94 | val4 = (w->buf[7] & 1) << 8 | (w->buf[8] << 4) | w->buf[9]; | ||
95 | val4 *= (w->buf[7] & 2) - 1; /* sign */ | ||
96 | val5 = ((w->buf[11] & 7) * 256 + w->buf[12] * 16 + w->buf[13]) >> 2; | ||
97 | val5 *= ((w->buf[11] >> 2) & 2) - 1; /* sign */ | ||
98 | val6 = (w->buf[13] & 1) << 8 | (w->buf[14] << 4) | w->buf[15]; | ||
99 | val6 *= (w->buf[13] & 2) - 1; /* sign */ | ||
100 | val7 = ((w->buf[16] & 7) * 256 + w->buf[17] * 16 + w->buf[18]) >> 2; | ||
101 | val7 *= ((w->buf[16] >> 2) & 2) - 1; /*sign */ | ||
102 | val8 = (w->buf[18] & 1) << 8 | (w->buf[19] << 4) | w->buf[20]; | ||
103 | val8 *= (w->buf[18] & 2) - 1; /*sign */ | ||
104 | |||
105 | #ifdef WK0701_DEBUG | ||
106 | { | ||
107 | int magic, magic_bit; | ||
108 | magic = (w->buf[21] << 4) | w->buf[22]; | ||
109 | magic_bit = (w->buf[24] & 8) >> 3; | ||
110 | printk(KERN_DEBUG | ||
111 | "walkera0701: %4d %4d %4d %4d %4d %4d %4d %4d (magic %2x %d)\n", | ||
112 | val1, val2, val3, val4, val5, val6, val7, val8, magic, | ||
113 | magic_bit); | ||
114 | } | ||
115 | #endif | ||
116 | input_report_abs(w->input_dev, ABS_X, val2); | ||
117 | input_report_abs(w->input_dev, ABS_Y, val1); | ||
118 | input_report_abs(w->input_dev, ABS_Z, val6); | ||
119 | input_report_abs(w->input_dev, ABS_THROTTLE, val3); | ||
120 | input_report_abs(w->input_dev, ABS_RUDDER, val4); | ||
121 | input_report_abs(w->input_dev, ABS_MISC, val7); | ||
122 | input_report_key(w->input_dev, BTN_GEAR_DOWN, val5 > 0); | ||
123 | } | ||
124 | |||
125 | static inline int read_ack(struct pardevice *p) | ||
126 | { | ||
127 | return parport_read_status(p->port) & 0x40; | ||
128 | } | ||
129 | |||
130 | /* falling edge, prepare to BIN value calculation */ | ||
131 | static void walkera0701_irq_handler(void *handler_data) | ||
132 | { | ||
133 | u64 pulse_time; | ||
134 | struct walkera_dev *w = handler_data; | ||
135 | |||
136 | w->irq_time = ktime_to_ns(ktime_get()); | ||
137 | pulse_time = w->irq_time - w->irq_lasttime; | ||
138 | w->irq_lasttime = w->irq_time; | ||
139 | |||
140 | /* cancel timer, if in handler or active do resync */ | ||
141 | if (unlikely(0 != hrtimer_try_to_cancel(&w->timer))) { | ||
142 | w->counter = NO_SYNC; | ||
143 | return; | ||
144 | } | ||
145 | |||
146 | if (w->counter < NO_SYNC) { | ||
147 | if (w->ack) { | ||
148 | pulse_time -= BIN1_PULSE; | ||
149 | w->buf[w->counter] = 8; | ||
150 | } else { | ||
151 | pulse_time -= BIN0_PULSE; | ||
152 | w->buf[w->counter] = 0; | ||
153 | } | ||
154 | if (w->counter == 24) { /* full frame */ | ||
155 | walkera0701_parse_frame(w); | ||
156 | w->counter = NO_SYNC; | ||
157 | if (abs(pulse_time - SYNC_PULSE) < RESERVE) /* new frame sync */ | ||
158 | w->counter = 0; | ||
159 | } else { | ||
160 | if ((pulse_time > (ANALOG_MIN_PULSE - RESERVE) | ||
161 | && (pulse_time < (ANALOG_MAX_PULSE + RESERVE)))) { | ||
162 | pulse_time -= (ANALOG_MIN_PULSE - RESERVE); | ||
163 | pulse_time = (u32) pulse_time / ANALOG_DELTA; /* overtiping is safe, pulsetime < s32.. */ | ||
164 | w->buf[w->counter++] |= (pulse_time & 7); | ||
165 | } else | ||
166 | w->counter = NO_SYNC; | ||
167 | } | ||
168 | } else if (abs(pulse_time - SYNC_PULSE - BIN0_PULSE) < | ||
169 | RESERVE + BIN1_PULSE - BIN0_PULSE) /* frame sync .. */ | ||
170 | w->counter = 0; | ||
171 | |||
172 | hrtimer_start(&w->timer, ktime_set(0, BIN_SAMPLE), HRTIMER_MODE_REL); | ||
173 | } | ||
174 | |||
175 | static enum hrtimer_restart timer_handler(struct hrtimer | ||
176 | *handle) | ||
177 | { | ||
178 | struct walkera_dev *w; | ||
179 | |||
180 | w = container_of(handle, struct walkera_dev, timer); | ||
181 | w->ack = read_ack(w->pardevice); | ||
182 | |||
183 | return HRTIMER_NORESTART; | ||
184 | } | ||
185 | |||
186 | static int walkera0701_open(struct input_dev *dev) | ||
187 | { | ||
188 | struct walkera_dev *w = input_get_drvdata(dev); | ||
189 | |||
190 | parport_enable_irq(w->parport); | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static void walkera0701_close(struct input_dev *dev) | ||
195 | { | ||
196 | struct walkera_dev *w = input_get_drvdata(dev); | ||
197 | |||
198 | parport_disable_irq(w->parport); | ||
199 | } | ||
200 | |||
201 | static int walkera0701_connect(struct walkera_dev *w, int parport) | ||
202 | { | ||
203 | int err = -ENODEV; | ||
204 | |||
205 | w->parport = parport_find_number(parport); | ||
206 | if (w->parport == NULL) | ||
207 | return -ENODEV; | ||
208 | |||
209 | if (w->parport->irq == -1) { | ||
210 | printk(KERN_ERR "walkera0701: parport without interrupt\n"); | ||
211 | goto init_err; | ||
212 | } | ||
213 | |||
214 | err = -EBUSY; | ||
215 | w->pardevice = parport_register_device(w->parport, "walkera0701", | ||
216 | NULL, NULL, walkera0701_irq_handler, | ||
217 | PARPORT_DEV_EXCL, w); | ||
218 | if (!w->pardevice) | ||
219 | goto init_err; | ||
220 | |||
221 | if (parport_negotiate(w->pardevice->port, IEEE1284_MODE_COMPAT)) | ||
222 | goto init_err1; | ||
223 | |||
224 | if (parport_claim(w->pardevice)) | ||
225 | goto init_err1; | ||
226 | |||
227 | w->input_dev = input_allocate_device(); | ||
228 | if (!w->input_dev) | ||
229 | goto init_err2; | ||
230 | |||
231 | input_set_drvdata(w->input_dev, w); | ||
232 | w->input_dev->name = "Walkera WK-0701 TX"; | ||
233 | w->input_dev->phys = w->parport->name; | ||
234 | w->input_dev->id.bustype = BUS_PARPORT; | ||
235 | |||
236 | /* TODO what id vendor/product/version ? */ | ||
237 | w->input_dev->id.vendor = 0x0001; | ||
238 | w->input_dev->id.product = 0x0001; | ||
239 | w->input_dev->id.version = 0x0100; | ||
240 | w->input_dev->open = walkera0701_open; | ||
241 | w->input_dev->close = walkera0701_close; | ||
242 | |||
243 | w->input_dev->evbit[0] = BIT(EV_ABS) | BIT_MASK(EV_KEY); | ||
244 | w->input_dev->keybit[BIT_WORD(BTN_GEAR_DOWN)] = BIT_MASK(BTN_GEAR_DOWN); | ||
245 | |||
246 | input_set_abs_params(w->input_dev, ABS_X, -512, 512, 0, 0); | ||
247 | input_set_abs_params(w->input_dev, ABS_Y, -512, 512, 0, 0); | ||
248 | input_set_abs_params(w->input_dev, ABS_Z, -512, 512, 0, 0); | ||
249 | input_set_abs_params(w->input_dev, ABS_THROTTLE, -512, 512, 0, 0); | ||
250 | input_set_abs_params(w->input_dev, ABS_RUDDER, -512, 512, 0, 0); | ||
251 | input_set_abs_params(w->input_dev, ABS_MISC, -512, 512, 0, 0); | ||
252 | |||
253 | err = input_register_device(w->input_dev); | ||
254 | if (err) | ||
255 | goto init_err3; | ||
256 | |||
257 | hrtimer_init(&w->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
258 | w->timer.function = timer_handler; | ||
259 | return 0; | ||
260 | |||
261 | init_err3: | ||
262 | input_free_device(w->input_dev); | ||
263 | init_err2: | ||
264 | parport_release(w->pardevice); | ||
265 | init_err1: | ||
266 | parport_unregister_device(w->pardevice); | ||
267 | init_err: | ||
268 | parport_put_port(w->parport); | ||
269 | return err; | ||
270 | } | ||
271 | |||
272 | static void walkera0701_disconnect(struct walkera_dev *w) | ||
273 | { | ||
274 | hrtimer_cancel(&w->timer); | ||
275 | input_unregister_device(w->input_dev); | ||
276 | parport_release(w->pardevice); | ||
277 | parport_unregister_device(w->pardevice); | ||
278 | parport_put_port(w->parport); | ||
279 | } | ||
280 | |||
281 | static int __init walkera0701_init(void) | ||
282 | { | ||
283 | return walkera0701_connect(&w_dev, walkera0701_pp_no); | ||
284 | } | ||
285 | |||
286 | static void __exit walkera0701_exit(void) | ||
287 | { | ||
288 | walkera0701_disconnect(&w_dev); | ||
289 | } | ||
290 | |||
291 | module_init(walkera0701_init); | ||
292 | module_exit(walkera0701_exit); | ||