Lines Matching full:adi
7 * Logitech ADI joystick family driver for Linux
19 #define DRIVER_DESC "Logitech ADI joystick family driver"
89 struct adi { struct
110 struct adi adi[2]; argument
116 * adi_read_packet() reads a Logitech ADI packet.
121 struct adi *adi = port->adi; in adi_read_packet() local
128 adi[i].ret = -1; in adi_read_packet()
144 if ((w & 0x30) < 0x30 && adi[i].ret < ADI_MAX_LENGTH && t[i] > 0) { in adi_read_packet()
145 adi[i].data[++adi[i].ret] = w; in adi_read_packet()
165 struct adi *adi = port->adi; in adi_move_bits() local
167 adi[0].idx = adi[1].idx = 0; in adi_move_bits()
169 if (adi[0].ret <= 0 || adi[1].ret <= 0) return; in adi_move_bits()
170 if (adi[0].data[0] & 0x20 || ~adi[1].data[0] & 0x20) return; in adi_move_bits()
172 for (i = 1; i <= adi[1].ret; i++) in adi_move_bits()
173 adi[0].data[((length - 1) >> 1) + i + 1] = adi[1].data[i]; in adi_move_bits()
175 adi[0].ret += adi[1].ret; in adi_move_bits()
176 adi[1].ret = -1; in adi_move_bits()
183 static inline int adi_get_bits(struct adi *adi, int count) in adi_get_bits() argument
187 if ((adi->idx += count) > adi->ret) return 0; in adi_get_bits()
189 bits |= ((adi->data[adi->idx - i] >> 5) & 1) << i; in adi_get_bits()
197 static int adi_decode(struct adi *adi) in adi_decode() argument
199 struct input_dev *dev = adi->dev; in adi_decode()
200 char *abs = adi->abs; in adi_decode()
201 short *key = adi->key; in adi_decode()
204 if (adi->ret < adi->length || adi->id != (adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4))) in adi_decode()
207 for (i = 0; i < adi->axes10; i++) in adi_decode()
208 input_report_abs(dev, *abs++, adi_get_bits(adi, 10)); in adi_decode()
210 for (i = 0; i < adi->axes8; i++) in adi_decode()
211 input_report_abs(dev, *abs++, adi_get_bits(adi, 8)); in adi_decode()
213 for (i = 0; i < adi->buttons && i < 63; i++) { in adi_decode()
214 if (i == adi->pad) { in adi_decode()
215 t = adi_get_bits(adi, 4); in adi_decode()
219 input_report_key(dev, *key++, adi_get_bits(adi, 1)); in adi_decode()
222 for (i = 0; i < adi->hats; i++) { in adi_decode()
223 if ((t = adi_get_bits(adi, 4)) > 8) t = 0; in adi_decode()
228 for (i = 63; i < adi->buttons; i++) in adi_decode()
229 input_report_key(dev, *key++, adi_get_bits(adi, 1)); in adi_decode()
246 adi_move_bits(port, port->adi[0].length); in adi_read()
249 if (port->adi[i].length) in adi_read()
250 result |= adi_decode(port->adi + i); in adi_read()
311 static void adi_id_decode(struct adi *adi, struct adi_port *port) in adi_id_decode() argument
315 if (adi->ret < ADI_MIN_ID_LENGTH) /* Minimum ID packet length */ in adi_id_decode()
318 if (adi->ret < (t = adi_get_bits(adi, 10))) { in adi_id_decode()
319 printk(KERN_WARNING "adi: Short ID packet: reported: %d != read: %d\n", t, adi->ret); in adi_id_decode()
323 adi->id = adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4); in adi_id_decode()
325 if ((t = adi_get_bits(adi, 4)) & ADI_FLAG_HAT) adi->hats++; in adi_id_decode()
327 adi->length = adi_get_bits(adi, 10); in adi_id_decode()
329 if (adi->length >= ADI_MAX_LENGTH || adi->length < ADI_MIN_LENGTH) { in adi_id_decode()
330 printk(KERN_WARNING "adi: Bad data packet length (%d).\n", adi->length); in adi_id_decode()
331 adi->length = 0; in adi_id_decode()
335 adi->axes8 = adi_get_bits(adi, 4); in adi_id_decode()
336 adi->buttons = adi_get_bits(adi, 6); in adi_id_decode()
338 if (adi_get_bits(adi, 6) != 8 && adi->hats) { in adi_id_decode()
339 printk(KERN_WARNING "adi: Other than 8-dir POVs not supported yet.\n"); in adi_id_decode()
340 adi->length = 0; in adi_id_decode()
344 adi->buttons += adi_get_bits(adi, 6); in adi_id_decode()
345 adi->hats += adi_get_bits(adi, 4); in adi_id_decode()
347 i = adi_get_bits(adi, 4); in adi_id_decode()
350 adi->axes10 = adi->axes8 - i; in adi_id_decode()
351 adi->axes8 = i; in adi_id_decode()
354 t = adi_get_bits(adi, 4); in adi_id_decode()
357 adi->cname[i] = adi_get_bits(adi, 8); in adi_id_decode()
358 adi->cname[i] = 0; in adi_id_decode()
360 t = 8 + adi->buttons + adi->axes10 * 10 + adi->axes8 * 8 + adi->hats * 4; in adi_id_decode()
361 if (adi->length != t && adi->length != t + (t & 1)) { in adi_id_decode()
362 printk(KERN_WARNING "adi: Expected length %d != data length %d\n", t, adi->length); in adi_id_decode()
363 adi->length = 0; in adi_id_decode()
367 switch (adi->id) { in adi_id_decode()
369 adi->pad = 4; in adi_id_decode()
370 adi->buttons -= 4; in adi_id_decode()
373 adi->pad = 0; in adi_id_decode()
374 adi->buttons -= 4; in adi_id_decode()
377 adi->pad = -1; in adi_id_decode()
382 static int adi_init_input(struct adi *adi, struct adi_port *port, int half) in adi_init_input() argument
388 adi->dev = input_dev = input_allocate_device(); in adi_init_input()
392 t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX; in adi_init_input()
394 snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id); in adi_init_input()
395 snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname); in adi_init_input()
396 snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half); in adi_init_input()
398 adi->abs = adi_abs[t]; in adi_init_input()
399 adi->key = adi_key[t]; in adi_init_input()
401 input_dev->name = adi->name; in adi_init_input()
402 input_dev->phys = adi->phys; in adi_init_input()
405 input_dev->id.product = adi->id; in adi_init_input()
416 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) in adi_init_input()
417 set_bit(adi->abs[i], input_dev->absbit); in adi_init_input()
419 for (i = 0; i < adi->buttons; i++) in adi_init_input()
420 set_bit(adi->key[i], input_dev->keybit); in adi_init_input()
425 static void adi_init_center(struct adi *adi) in adi_init_center() argument
429 if (!adi->length) in adi_init_center()
432 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) { in adi_init_center()
434 t = adi->abs[i]; in adi_init_center()
435 x = input_abs_get_val(adi->dev, t); in adi_init_center()
437 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE) in adi_init_center()
438 x = i < adi->axes10 ? 512 : 128; in adi_init_center()
440 if (i < adi->axes10) in adi_init_center()
441 input_set_abs_params(adi->dev, t, 64, x * 2 - 64, 2, 16); in adi_init_center()
442 else if (i < adi->axes10 + adi->axes8) in adi_init_center()
443 input_set_abs_params(adi->dev, t, 48, x * 2 - 48, 1, 16); in adi_init_center()
445 input_set_abs_params(adi->dev, t, -1, 1, 0, 0); in adi_init_center()
450 * adi_connect() probes for Logitech ADI joysticks.
474 if (port->adi[0].ret >= ADI_MIN_LEN_LENGTH) in adi_connect()
475 adi_move_bits(port, adi_get_bits(port->adi, 10)); in adi_connect()
478 adi_id_decode(port->adi + i, port); in adi_connect()
480 if (!port->adi[i].length) in adi_connect()
483 err = adi_init_input(port->adi + i, port, i); in adi_connect()
488 if (!port->adi[0].length && !port->adi[1].length) { in adi_connect()
503 if (port->adi[i].length > 0) { in adi_connect()
504 adi_init_center(port->adi + i); in adi_connect()
505 err = input_register_device(port->adi[i].dev); in adi_connect()
513 if (port->adi[i].length > 0) { in adi_connect()
514 input_unregister_device(port->adi[i].dev); in adi_connect()
515 port->adi[i].dev = NULL; in adi_connect()
519 input_free_device(port->adi[i].dev); in adi_connect()
532 if (port->adi[i].length > 0) in adi_disconnect()
533 input_unregister_device(port->adi[i].dev); in adi_disconnect()
541 .name = "adi",