Lines Matching refs:mousedev
58 struct mousedev { struct
78 int (*open_device)(struct mousedev *mousedev); argument
79 void (*close_device)(struct mousedev *mousedev); argument
96 struct mousedev *mousedev; member
116 static struct mousedev *mousedev_mix;
119 #define fx(i) (mousedev->old_x[(mousedev->pkt_count - (i)) & 03])
120 #define fy(i) (mousedev->old_y[(mousedev->pkt_count - (i)) & 03])
123 struct mousedev *mousedev, in mousedev_touchpad_event() argument
134 if (mousedev->touch && mousedev->pkt_count >= 2) { in mousedev_touchpad_event()
141 tmp += mousedev->frac_dx; in mousedev_touchpad_event()
142 mousedev->packet.dx = tmp / FRACTION_DENOM; in mousedev_touchpad_event()
143 mousedev->frac_dx = in mousedev_touchpad_event()
144 tmp - mousedev->packet.dx * FRACTION_DENOM; in mousedev_touchpad_event()
150 if (mousedev->touch && mousedev->pkt_count >= 2) { in mousedev_touchpad_event()
158 tmp += mousedev->frac_dy; in mousedev_touchpad_event()
159 mousedev->packet.dy = tmp / FRACTION_DENOM; in mousedev_touchpad_event()
160 mousedev->frac_dy = tmp - in mousedev_touchpad_event()
161 mousedev->packet.dy * FRACTION_DENOM; in mousedev_touchpad_event()
167 static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev, in mousedev_abs_event() argument
184 mousedev->packet.x = ((value - min) * xres) / size; in mousedev_abs_event()
185 mousedev->packet.abs_event = 1; in mousedev_abs_event()
198 mousedev->packet.y = yres - ((value - min) * yres) / size; in mousedev_abs_event()
199 mousedev->packet.abs_event = 1; in mousedev_abs_event()
204 static void mousedev_rel_event(struct mousedev *mousedev, in mousedev_rel_event() argument
209 mousedev->packet.dx += value; in mousedev_rel_event()
213 mousedev->packet.dy -= value; in mousedev_rel_event()
217 mousedev->packet.dz -= value; in mousedev_rel_event()
222 static void mousedev_key_event(struct mousedev *mousedev, in mousedev_key_event() argument
253 set_bit(index, &mousedev->packet.buttons); in mousedev_key_event()
256 clear_bit(index, &mousedev->packet.buttons); in mousedev_key_event()
261 static void mousedev_notify_readers(struct mousedev *mousedev, in mousedev_notify_readers() argument
270 list_for_each_entry_rcu(client, &mousedev->client_list, node) { in mousedev_notify_readers()
276 if (client->ready && p->buttons != mousedev->packet.buttons) { in mousedev_notify_readers()
300 p->buttons = mousedev->packet.buttons; in mousedev_notify_readers()
316 wake_up_interruptible(&mousedev->wait); in mousedev_notify_readers()
319 static void mousedev_touchpad_touch(struct mousedev *mousedev, int value) in mousedev_touchpad_touch() argument
322 if (mousedev->touch && in mousedev_touchpad_touch()
324 mousedev->touch + msecs_to_jiffies(tap_time))) { in mousedev_touchpad_touch()
330 set_bit(0, &mousedev->packet.buttons); in mousedev_touchpad_touch()
332 mousedev_notify_readers(mousedev, &mousedev_mix->packet); in mousedev_touchpad_touch()
335 clear_bit(0, &mousedev->packet.buttons); in mousedev_touchpad_touch()
338 mousedev->touch = mousedev->pkt_count = 0; in mousedev_touchpad_touch()
339 mousedev->frac_dx = 0; in mousedev_touchpad_touch()
340 mousedev->frac_dy = 0; in mousedev_touchpad_touch()
342 } else if (!mousedev->touch) in mousedev_touchpad_touch()
343 mousedev->touch = jiffies; in mousedev_touchpad_touch()
349 struct mousedev *mousedev = handle->private; in mousedev_event() local
360 mousedev, code, value); in mousedev_event()
362 mousedev_abs_event(handle->dev, mousedev, code, value); in mousedev_event()
367 mousedev_rel_event(mousedev, code, value); in mousedev_event()
374 mousedev_touchpad_touch(mousedev, value); in mousedev_event()
376 mousedev_key_event(mousedev, code, value); in mousedev_event()
382 if (mousedev->touch) { in mousedev_event()
383 mousedev->pkt_count++; in mousedev_event()
393 mousedev_notify_readers(mousedev, &mousedev->packet); in mousedev_event()
394 mousedev_notify_readers(mousedev_mix, &mousedev->packet); in mousedev_event()
396 mousedev->packet.dx = mousedev->packet.dy = in mousedev_event()
397 mousedev->packet.dz = 0; in mousedev_event()
398 mousedev->packet.abs_event = 0; in mousedev_event()
413 struct mousedev *mousedev = container_of(dev, struct mousedev, dev); in mousedev_free() local
415 input_put_device(mousedev->handle.dev); in mousedev_free()
416 kfree(mousedev); in mousedev_free()
419 static int mousedev_open_device(struct mousedev *mousedev) in mousedev_open_device() argument
423 retval = mutex_lock_interruptible(&mousedev->mutex); in mousedev_open_device()
427 if (!mousedev->exist) in mousedev_open_device()
429 else if (!mousedev->open++) { in mousedev_open_device()
430 retval = input_open_device(&mousedev->handle); in mousedev_open_device()
432 mousedev->open--; in mousedev_open_device()
435 mutex_unlock(&mousedev->mutex); in mousedev_open_device()
439 static void mousedev_close_device(struct mousedev *mousedev) in mousedev_close_device() argument
441 mutex_lock(&mousedev->mutex); in mousedev_close_device()
443 if (mousedev->exist && !--mousedev->open) in mousedev_close_device()
444 input_close_device(&mousedev->handle); in mousedev_close_device()
446 mutex_unlock(&mousedev->mutex); in mousedev_close_device()
454 static int mixdev_open_devices(struct mousedev *mixdev) in mixdev_open_devices()
463 struct mousedev *mousedev; in mixdev_open_devices() local
465 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { in mixdev_open_devices()
466 if (!mousedev->opened_by_mixdev) { in mixdev_open_devices()
467 if (mousedev_open_device(mousedev)) in mixdev_open_devices()
470 mousedev->opened_by_mixdev = true; in mixdev_open_devices()
484 static void mixdev_close_devices(struct mousedev *mixdev) in mixdev_close_devices()
489 struct mousedev *mousedev; in mixdev_close_devices() local
491 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { in mixdev_close_devices()
492 if (mousedev->opened_by_mixdev) { in mixdev_close_devices()
493 mousedev->opened_by_mixdev = false; in mixdev_close_devices()
494 mousedev_close_device(mousedev); in mixdev_close_devices()
503 static void mousedev_attach_client(struct mousedev *mousedev, in mousedev_attach_client() argument
506 spin_lock(&mousedev->client_lock); in mousedev_attach_client()
507 list_add_tail_rcu(&client->node, &mousedev->client_list); in mousedev_attach_client()
508 spin_unlock(&mousedev->client_lock); in mousedev_attach_client()
511 static void mousedev_detach_client(struct mousedev *mousedev, in mousedev_detach_client() argument
514 spin_lock(&mousedev->client_lock); in mousedev_detach_client()
516 spin_unlock(&mousedev->client_lock); in mousedev_detach_client()
523 struct mousedev *mousedev = client->mousedev; in mousedev_release() local
525 mousedev_detach_client(mousedev, client); in mousedev_release()
528 mousedev->close_device(mousedev); in mousedev_release()
536 struct mousedev *mousedev; in mousedev_open() local
541 mousedev = mousedev_mix; in mousedev_open()
544 mousedev = container_of(inode->i_cdev, struct mousedev, cdev); in mousedev_open()
553 client->mousedev = mousedev; in mousedev_open()
554 mousedev_attach_client(mousedev, client); in mousedev_open()
556 error = mousedev->open_device(mousedev); in mousedev_open()
566 mousedev_detach_client(mousedev, client); in mousedev_open()
711 wake_up_interruptible(&client->mousedev->wait); in mousedev_write()
720 struct mousedev *mousedev = client->mousedev; in mousedev_read() local
724 if (!client->ready && !client->buffer && mousedev->exist && in mousedev_read()
728 retval = wait_event_interruptible(mousedev->wait, in mousedev_read()
729 !mousedev->exist || client->ready || client->buffer); in mousedev_read()
733 if (!mousedev->exist) in mousedev_read()
761 struct mousedev *mousedev = client->mousedev; in mousedev_poll() local
764 poll_wait(file, &mousedev->wait, wait); in mousedev_poll()
766 mask = mousedev->exist ? EPOLLOUT | EPOLLWRNORM : EPOLLHUP | EPOLLERR; in mousedev_poll()
789 static void mousedev_mark_dead(struct mousedev *mousedev) in mousedev_mark_dead() argument
791 mutex_lock(&mousedev->mutex); in mousedev_mark_dead()
792 mousedev->exist = false; in mousedev_mark_dead()
793 mutex_unlock(&mousedev->mutex); in mousedev_mark_dead()
800 static void mousedev_hangup(struct mousedev *mousedev) in mousedev_hangup() argument
804 spin_lock(&mousedev->client_lock); in mousedev_hangup()
805 list_for_each_entry(client, &mousedev->client_list, node) in mousedev_hangup()
807 spin_unlock(&mousedev->client_lock); in mousedev_hangup()
809 wake_up_interruptible(&mousedev->wait); in mousedev_hangup()
812 static void mousedev_cleanup(struct mousedev *mousedev) in mousedev_cleanup() argument
814 struct input_handle *handle = &mousedev->handle; in mousedev_cleanup()
816 mousedev_mark_dead(mousedev); in mousedev_cleanup()
817 mousedev_hangup(mousedev); in mousedev_cleanup()
820 if (mousedev->open) in mousedev_cleanup()
842 static struct mousedev *mousedev_create(struct input_dev *dev, in mousedev_create()
846 struct mousedev *mousedev; in mousedev_create() local
856 mousedev = kzalloc(sizeof(struct mousedev), GFP_KERNEL); in mousedev_create()
857 if (!mousedev) { in mousedev_create()
862 INIT_LIST_HEAD(&mousedev->client_list); in mousedev_create()
863 INIT_LIST_HEAD(&mousedev->mixdev_node); in mousedev_create()
864 spin_lock_init(&mousedev->client_lock); in mousedev_create()
865 mutex_init(&mousedev->mutex); in mousedev_create()
866 lockdep_set_subclass(&mousedev->mutex, in mousedev_create()
868 init_waitqueue_head(&mousedev->wait); in mousedev_create()
871 dev_set_name(&mousedev->dev, "mice"); in mousedev_create()
873 mousedev->open_device = mixdev_open_devices; in mousedev_create()
874 mousedev->close_device = mixdev_close_devices; in mousedev_create()
880 dev_set_name(&mousedev->dev, "mouse%d", dev_no); in mousedev_create()
882 mousedev->open_device = mousedev_open_device; in mousedev_create()
883 mousedev->close_device = mousedev_close_device; in mousedev_create()
886 mousedev->exist = true; in mousedev_create()
887 mousedev->handle.dev = input_get_device(dev); in mousedev_create()
888 mousedev->handle.name = dev_name(&mousedev->dev); in mousedev_create()
889 mousedev->handle.handler = handler; in mousedev_create()
890 mousedev->handle.private = mousedev; in mousedev_create()
892 mousedev->dev.class = &input_class; in mousedev_create()
894 mousedev->dev.parent = &dev->dev; in mousedev_create()
895 mousedev->dev.devt = MKDEV(INPUT_MAJOR, minor); in mousedev_create()
896 mousedev->dev.release = mousedev_free; in mousedev_create()
897 device_initialize(&mousedev->dev); in mousedev_create()
900 error = input_register_handle(&mousedev->handle); in mousedev_create()
905 cdev_init(&mousedev->cdev, &mousedev_fops); in mousedev_create()
907 error = cdev_device_add(&mousedev->cdev, &mousedev->dev); in mousedev_create()
911 return mousedev; in mousedev_create()
914 mousedev_cleanup(mousedev); in mousedev_create()
916 input_unregister_handle(&mousedev->handle); in mousedev_create()
918 put_device(&mousedev->dev); in mousedev_create()
925 static void mousedev_destroy(struct mousedev *mousedev) in mousedev_destroy() argument
927 cdev_device_del(&mousedev->cdev, &mousedev->dev); in mousedev_destroy()
928 mousedev_cleanup(mousedev); in mousedev_destroy()
929 input_free_minor(MINOR(mousedev->dev.devt)); in mousedev_destroy()
930 if (mousedev != mousedev_mix) in mousedev_destroy()
931 input_unregister_handle(&mousedev->handle); in mousedev_destroy()
932 put_device(&mousedev->dev); in mousedev_destroy()
935 static int mixdev_add_device(struct mousedev *mousedev) in mixdev_add_device() argument
944 retval = mousedev_open_device(mousedev); in mixdev_add_device()
948 mousedev->opened_by_mixdev = true; in mixdev_add_device()
951 get_device(&mousedev->dev); in mixdev_add_device()
952 list_add_tail(&mousedev->mixdev_node, &mousedev_mix_list); in mixdev_add_device()
959 static void mixdev_remove_device(struct mousedev *mousedev) in mixdev_remove_device() argument
963 if (mousedev->opened_by_mixdev) { in mixdev_remove_device()
964 mousedev->opened_by_mixdev = false; in mixdev_remove_device()
965 mousedev_close_device(mousedev); in mixdev_remove_device()
968 list_del_init(&mousedev->mixdev_node); in mixdev_remove_device()
971 put_device(&mousedev->dev); in mixdev_remove_device()
978 struct mousedev *mousedev; in mousedev_connect() local
981 mousedev = mousedev_create(dev, handler, false); in mousedev_connect()
982 if (IS_ERR(mousedev)) in mousedev_connect()
983 return PTR_ERR(mousedev); in mousedev_connect()
985 error = mixdev_add_device(mousedev); in mousedev_connect()
987 mousedev_destroy(mousedev); in mousedev_connect()
996 struct mousedev *mousedev = handle->private; in mousedev_disconnect() local
998 mixdev_remove_device(mousedev); in mousedev_disconnect()
999 mousedev_destroy(mousedev); in mousedev_disconnect()