diff options
-rw-r--r-- | drivers/input/joystick/Kconfig | 12 | ||||
-rw-r--r-- | drivers/input/joystick/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/joystick/maplecontrol.c | 193 |
3 files changed, 206 insertions, 0 deletions
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig index 268dd3fef0ab..b11419590cfe 100644 --- a/drivers/input/joystick/Kconfig +++ b/drivers/input/joystick/Kconfig | |||
@@ -306,4 +306,16 @@ config JOYSTICK_WALKERA0701 | |||
306 | To compile this driver as a module, choose M here: the | 306 | To compile this driver as a module, choose M here: the |
307 | module will be called walkera0701. | 307 | module will be called walkera0701. |
308 | 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 | |||
309 | endif | 321 | endif |
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile index 723036295685..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 |
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); | ||