diff options
Diffstat (limited to 'drivers/input/joystick/spaceball.c')
-rw-r--r-- | drivers/input/joystick/spaceball.c | 82 |
1 files changed, 37 insertions, 45 deletions
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c index a436f2220856..d6f8db8ec3fd 100644 --- a/drivers/input/joystick/spaceball.c +++ b/drivers/input/joystick/spaceball.c | |||
@@ -70,8 +70,7 @@ static char *spaceball_names[] = { | |||
70 | */ | 70 | */ |
71 | 71 | ||
72 | struct spaceball { | 72 | struct spaceball { |
73 | struct input_dev dev; | 73 | struct input_dev *dev; |
74 | struct serio *serio; | ||
75 | int idx; | 74 | int idx; |
76 | int escape; | 75 | int escape; |
77 | unsigned char data[SPACEBALL_MAX_LENGTH]; | 76 | unsigned char data[SPACEBALL_MAX_LENGTH]; |
@@ -85,7 +84,7 @@ struct spaceball { | |||
85 | 84 | ||
86 | static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs) | 85 | static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs) |
87 | { | 86 | { |
88 | struct input_dev *dev = &spaceball->dev; | 87 | struct input_dev *dev = spaceball->dev; |
89 | unsigned char *data = spaceball->data; | 88 | unsigned char *data = spaceball->data; |
90 | int i; | 89 | int i; |
91 | 90 | ||
@@ -193,9 +192,9 @@ static void spaceball_disconnect(struct serio *serio) | |||
193 | { | 192 | { |
194 | struct spaceball* spaceball = serio_get_drvdata(serio); | 193 | struct spaceball* spaceball = serio_get_drvdata(serio); |
195 | 194 | ||
196 | input_unregister_device(&spaceball->dev); | ||
197 | serio_close(serio); | 195 | serio_close(serio); |
198 | serio_set_drvdata(serio, NULL); | 196 | serio_set_drvdata(serio, NULL); |
197 | input_unregister_device(spaceball->dev); | ||
199 | kfree(spaceball); | 198 | kfree(spaceball); |
200 | } | 199 | } |
201 | 200 | ||
@@ -208,69 +207,62 @@ static void spaceball_disconnect(struct serio *serio) | |||
208 | static int spaceball_connect(struct serio *serio, struct serio_driver *drv) | 207 | static int spaceball_connect(struct serio *serio, struct serio_driver *drv) |
209 | { | 208 | { |
210 | struct spaceball *spaceball; | 209 | struct spaceball *spaceball; |
211 | int i, t, id; | 210 | struct input_dev *input_dev; |
212 | int err; | 211 | int err = -ENOMEM; |
212 | int i, id; | ||
213 | 213 | ||
214 | if ((id = serio->id.id) > SPACEBALL_MAX_ID) | 214 | if ((id = serio->id.id) > SPACEBALL_MAX_ID) |
215 | return -ENODEV; | 215 | return -ENODEV; |
216 | 216 | ||
217 | if (!(spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL))) | 217 | spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL); |
218 | return - ENOMEM; | 218 | input_dev = input_allocate_device(); |
219 | if (!spaceball || !input_dev) | ||
220 | goto fail; | ||
219 | 221 | ||
220 | memset(spaceball, 0, sizeof(struct spaceball)); | 222 | spaceball->dev = input_dev; |
223 | sprintf(spaceball->phys, "%s/input0", serio->phys); | ||
224 | |||
225 | input_dev->name = spaceball_names[id]; | ||
226 | input_dev->phys = spaceball->phys; | ||
227 | input_dev->id.bustype = BUS_RS232; | ||
228 | input_dev->id.vendor = SERIO_SPACEBALL; | ||
229 | input_dev->id.product = id; | ||
230 | input_dev->id.version = 0x0100; | ||
231 | input_dev->cdev.dev = &serio->dev; | ||
232 | input_dev->private = spaceball; | ||
221 | 233 | ||
222 | spaceball->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 234 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
223 | 235 | ||
224 | switch (id) { | 236 | switch (id) { |
225 | case SPACEBALL_4000FLX: | 237 | case SPACEBALL_4000FLX: |
226 | case SPACEBALL_4000FLX_L: | 238 | case SPACEBALL_4000FLX_L: |
227 | spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_9); | 239 | input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_9); |
228 | spaceball->dev.keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE); | 240 | input_dev->keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE); |
229 | default: | 241 | default: |
230 | spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | 242 | input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) |
231 | | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8); | 243 | | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8); |
232 | case SPACEBALL_3003C: | 244 | case SPACEBALL_3003C: |
233 | spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8); | 245 | input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8); |
234 | } | 246 | } |
235 | 247 | ||
236 | for (i = 0; i < 6; i++) { | 248 | for (i = 0; i < 3; i++) { |
237 | t = spaceball_axes[i]; | 249 | input_set_abs_params(input_dev, ABS_X + i, -8000, 8000, 8, 40); |
238 | set_bit(t, spaceball->dev.absbit); | 250 | input_set_abs_params(input_dev, ABS_RX + i, -1600, 1600, 2, 8); |
239 | spaceball->dev.absmin[t] = i < 3 ? -8000 : -1600; | ||
240 | spaceball->dev.absmax[t] = i < 3 ? 8000 : 1600; | ||
241 | spaceball->dev.absflat[t] = i < 3 ? 40 : 8; | ||
242 | spaceball->dev.absfuzz[t] = i < 3 ? 8 : 2; | ||
243 | } | 251 | } |
244 | 252 | ||
245 | spaceball->serio = serio; | ||
246 | spaceball->dev.private = spaceball; | ||
247 | |||
248 | sprintf(spaceball->phys, "%s/input0", serio->phys); | ||
249 | |||
250 | init_input_dev(&spaceball->dev); | ||
251 | spaceball->dev.name = spaceball_names[id]; | ||
252 | spaceball->dev.phys = spaceball->phys; | ||
253 | spaceball->dev.id.bustype = BUS_RS232; | ||
254 | spaceball->dev.id.vendor = SERIO_SPACEBALL; | ||
255 | spaceball->dev.id.product = id; | ||
256 | spaceball->dev.id.version = 0x0100; | ||
257 | spaceball->dev.dev = &serio->dev; | ||
258 | |||
259 | serio_set_drvdata(serio, spaceball); | 253 | serio_set_drvdata(serio, spaceball); |
260 | 254 | ||
261 | err = serio_open(serio, drv); | 255 | err = serio_open(serio, drv); |
262 | if (err) { | 256 | if (err) |
263 | serio_set_drvdata(serio, NULL); | 257 | goto fail; |
264 | kfree(spaceball); | ||
265 | return err; | ||
266 | } | ||
267 | |||
268 | input_register_device(&spaceball->dev); | ||
269 | |||
270 | printk(KERN_INFO "input: %s on serio%s\n", | ||
271 | spaceball_names[id], serio->phys); | ||
272 | 258 | ||
259 | input_register_device(spaceball->dev); | ||
273 | return 0; | 260 | return 0; |
261 | |||
262 | fail: serio_set_drvdata(serio, NULL); | ||
263 | input_free_device(input_dev); | ||
264 | kfree(spaceball); | ||
265 | return err; | ||
274 | } | 266 | } |
275 | 267 | ||
276 | /* | 268 | /* |