Lines Matching refs:uhid
59 struct uhid_device *uhid = container_of(work, struct uhid_device, worker); in uhid_device_add_worker() local
62 ret = hid_add_device(uhid->hid); in uhid_device_add_worker()
64 hid_err(uhid->hid, "Cannot register HID device: error %d\n", ret); in uhid_device_add_worker()
66 hid_destroy_device(uhid->hid); in uhid_device_add_worker()
67 uhid->hid = NULL; in uhid_device_add_worker()
68 uhid->running = false; in uhid_device_add_worker()
72 static void uhid_queue(struct uhid_device *uhid, struct uhid_event *ev) in uhid_queue() argument
76 newhead = (uhid->head + 1) % UHID_BUFSIZE; in uhid_queue()
78 if (newhead != uhid->tail) { in uhid_queue()
79 uhid->outq[uhid->head] = ev; in uhid_queue()
80 uhid->head = newhead; in uhid_queue()
81 wake_up_interruptible(&uhid->waitq); in uhid_queue()
83 hid_warn(uhid->hid, "Output queue is full\n"); in uhid_queue()
88 static int uhid_queue_event(struct uhid_device *uhid, __u32 event) in uhid_queue_event() argument
99 spin_lock_irqsave(&uhid->qlock, flags); in uhid_queue_event()
100 uhid_queue(uhid, ev); in uhid_queue_event()
101 spin_unlock_irqrestore(&uhid->qlock, flags); in uhid_queue_event()
108 struct uhid_device *uhid = hid->driver_data; in uhid_hid_start() local
125 spin_lock_irqsave(&uhid->qlock, flags); in uhid_hid_start()
126 uhid_queue(uhid, ev); in uhid_hid_start()
127 spin_unlock_irqrestore(&uhid->qlock, flags); in uhid_hid_start()
134 struct uhid_device *uhid = hid->driver_data; in uhid_hid_stop() local
137 uhid_queue_event(uhid, UHID_STOP); in uhid_hid_stop()
142 struct uhid_device *uhid = hid->driver_data; in uhid_hid_open() local
144 return uhid_queue_event(uhid, UHID_OPEN); in uhid_hid_open()
149 struct uhid_device *uhid = hid->driver_data; in uhid_hid_close() local
151 uhid_queue_event(uhid, UHID_CLOSE); in uhid_hid_close()
156 struct uhid_device *uhid = hid->driver_data; in uhid_hid_parse() local
158 return hid_parse_report(hid, uhid->rd_data, uhid->rd_size); in uhid_hid_parse()
162 static int __uhid_report_queue_and_wait(struct uhid_device *uhid, in __uhid_report_queue_and_wait() argument
169 spin_lock_irqsave(&uhid->qlock, flags); in __uhid_report_queue_and_wait()
170 *report_id = ++uhid->report_id; in __uhid_report_queue_and_wait()
171 uhid->report_type = ev->type + 1; in __uhid_report_queue_and_wait()
172 uhid->report_running = true; in __uhid_report_queue_and_wait()
173 uhid_queue(uhid, ev); in __uhid_report_queue_and_wait()
174 spin_unlock_irqrestore(&uhid->qlock, flags); in __uhid_report_queue_and_wait()
176 ret = wait_event_interruptible_timeout(uhid->report_wait, in __uhid_report_queue_and_wait()
177 !uhid->report_running || !uhid->running, in __uhid_report_queue_and_wait()
179 if (!ret || !uhid->running || uhid->report_running) in __uhid_report_queue_and_wait()
186 uhid->report_running = false; in __uhid_report_queue_and_wait()
191 static void uhid_report_wake_up(struct uhid_device *uhid, u32 id, in uhid_report_wake_up() argument
196 spin_lock_irqsave(&uhid->qlock, flags); in uhid_report_wake_up()
199 if (uhid->report_type != ev->type || uhid->report_id != id) in uhid_report_wake_up()
201 if (!uhid->report_running) in uhid_report_wake_up()
204 memcpy(&uhid->report_buf, ev, sizeof(*ev)); in uhid_report_wake_up()
205 uhid->report_running = false; in uhid_report_wake_up()
206 wake_up_interruptible(&uhid->report_wait); in uhid_report_wake_up()
209 spin_unlock_irqrestore(&uhid->qlock, flags); in uhid_report_wake_up()
215 struct uhid_device *uhid = hid->driver_data; in uhid_hid_get_report() local
220 if (!uhid->running) in uhid_hid_get_report()
231 ret = mutex_lock_interruptible(&uhid->report_lock); in uhid_hid_get_report()
238 ret = __uhid_report_queue_and_wait(uhid, ev, &ev->u.get_report.id); in uhid_hid_get_report()
242 req = &uhid->report_buf.u.get_report_reply; in uhid_hid_get_report()
251 mutex_unlock(&uhid->report_lock); in uhid_hid_get_report()
258 struct uhid_device *uhid = hid->driver_data; in uhid_hid_set_report() local
262 if (!uhid->running || count > UHID_DATA_MAX) in uhid_hid_set_report()
275 ret = mutex_lock_interruptible(&uhid->report_lock); in uhid_hid_set_report()
282 ret = __uhid_report_queue_and_wait(uhid, ev, &ev->u.set_report.id); in uhid_hid_set_report()
286 if (uhid->report_buf.u.set_report_reply.err) in uhid_hid_set_report()
292 mutex_unlock(&uhid->report_lock); in uhid_hid_set_report()
329 struct uhid_device *uhid = hid->driver_data; in uhid_hid_output_raw() local
357 spin_lock_irqsave(&uhid->qlock, flags); in uhid_hid_output_raw()
358 uhid_queue(uhid, ev); in uhid_hid_output_raw()
359 spin_unlock_irqrestore(&uhid->qlock, flags); in uhid_hid_output_raw()
469 static int uhid_dev_create2(struct uhid_device *uhid, in uhid_dev_create2() argument
477 if (uhid->running) in uhid_dev_create2()
488 uhid->rd_size = rd_size; in uhid_dev_create2()
489 uhid->rd_data = rd_data; in uhid_dev_create2()
511 hid->driver_data = uhid; in uhid_dev_create2()
514 uhid->hid = hid; in uhid_dev_create2()
515 uhid->running = true; in uhid_dev_create2()
521 schedule_work(&uhid->worker); in uhid_dev_create2()
526 kfree(uhid->rd_data); in uhid_dev_create2()
527 uhid->rd_data = NULL; in uhid_dev_create2()
528 uhid->rd_size = 0; in uhid_dev_create2()
532 static int uhid_dev_create(struct uhid_device *uhid, in uhid_dev_create() argument
554 return uhid_dev_create2(uhid, ev); in uhid_dev_create()
557 static int uhid_dev_destroy(struct uhid_device *uhid) in uhid_dev_destroy() argument
559 if (!uhid->running) in uhid_dev_destroy()
562 uhid->running = false; in uhid_dev_destroy()
563 wake_up_interruptible(&uhid->report_wait); in uhid_dev_destroy()
565 cancel_work_sync(&uhid->worker); in uhid_dev_destroy()
567 hid_destroy_device(uhid->hid); in uhid_dev_destroy()
568 kfree(uhid->rd_data); in uhid_dev_destroy()
573 static int uhid_dev_input(struct uhid_device *uhid, struct uhid_event *ev) in uhid_dev_input() argument
575 if (!uhid->running) in uhid_dev_input()
578 hid_input_report(uhid->hid, HID_INPUT_REPORT, ev->u.input.data, in uhid_dev_input()
584 static int uhid_dev_input2(struct uhid_device *uhid, struct uhid_event *ev) in uhid_dev_input2() argument
586 if (!uhid->running) in uhid_dev_input2()
589 hid_input_report(uhid->hid, HID_INPUT_REPORT, ev->u.input2.data, in uhid_dev_input2()
595 static int uhid_dev_get_report_reply(struct uhid_device *uhid, in uhid_dev_get_report_reply() argument
598 if (!uhid->running) in uhid_dev_get_report_reply()
601 uhid_report_wake_up(uhid, ev->u.get_report_reply.id, ev); in uhid_dev_get_report_reply()
605 static int uhid_dev_set_report_reply(struct uhid_device *uhid, in uhid_dev_set_report_reply() argument
608 if (!uhid->running) in uhid_dev_set_report_reply()
611 uhid_report_wake_up(uhid, ev->u.set_report_reply.id, ev); in uhid_dev_set_report_reply()
617 struct uhid_device *uhid; in uhid_char_open() local
619 uhid = kzalloc(sizeof(*uhid), GFP_KERNEL); in uhid_char_open()
620 if (!uhid) in uhid_char_open()
623 mutex_init(&uhid->devlock); in uhid_char_open()
624 mutex_init(&uhid->report_lock); in uhid_char_open()
625 spin_lock_init(&uhid->qlock); in uhid_char_open()
626 init_waitqueue_head(&uhid->waitq); in uhid_char_open()
627 init_waitqueue_head(&uhid->report_wait); in uhid_char_open()
628 uhid->running = false; in uhid_char_open()
629 INIT_WORK(&uhid->worker, uhid_device_add_worker); in uhid_char_open()
631 file->private_data = uhid; in uhid_char_open()
639 struct uhid_device *uhid = file->private_data; in uhid_char_release() local
642 uhid_dev_destroy(uhid); in uhid_char_release()
645 kfree(uhid->outq[i]); in uhid_char_release()
647 kfree(uhid); in uhid_char_release()
655 struct uhid_device *uhid = file->private_data; in uhid_char_read() local
666 if (uhid->head == uhid->tail) in uhid_char_read()
669 ret = wait_event_interruptible(uhid->waitq, in uhid_char_read()
670 uhid->head != uhid->tail); in uhid_char_read()
675 ret = mutex_lock_interruptible(&uhid->devlock); in uhid_char_read()
679 if (uhid->head == uhid->tail) { in uhid_char_read()
680 mutex_unlock(&uhid->devlock); in uhid_char_read()
683 len = min(count, sizeof(**uhid->outq)); in uhid_char_read()
684 if (copy_to_user(buffer, uhid->outq[uhid->tail], len)) { in uhid_char_read()
687 kfree(uhid->outq[uhid->tail]); in uhid_char_read()
688 uhid->outq[uhid->tail] = NULL; in uhid_char_read()
690 spin_lock_irqsave(&uhid->qlock, flags); in uhid_char_read()
691 uhid->tail = (uhid->tail + 1) % UHID_BUFSIZE; in uhid_char_read()
692 spin_unlock_irqrestore(&uhid->qlock, flags); in uhid_char_read()
696 mutex_unlock(&uhid->devlock); in uhid_char_read()
703 struct uhid_device *uhid = file->private_data; in uhid_char_write() local
711 ret = mutex_lock_interruptible(&uhid->devlock); in uhid_char_write()
715 memset(&uhid->input_buf, 0, sizeof(uhid->input_buf)); in uhid_char_write()
716 len = min(count, sizeof(uhid->input_buf)); in uhid_char_write()
718 ret = uhid_event_from_user(buffer, len, &uhid->input_buf); in uhid_char_write()
722 switch (uhid->input_buf.type) { in uhid_char_write()
735 ret = uhid_dev_create(uhid, &uhid->input_buf); in uhid_char_write()
738 ret = uhid_dev_create2(uhid, &uhid->input_buf); in uhid_char_write()
741 ret = uhid_dev_destroy(uhid); in uhid_char_write()
744 ret = uhid_dev_input(uhid, &uhid->input_buf); in uhid_char_write()
747 ret = uhid_dev_input2(uhid, &uhid->input_buf); in uhid_char_write()
750 ret = uhid_dev_get_report_reply(uhid, &uhid->input_buf); in uhid_char_write()
753 ret = uhid_dev_set_report_reply(uhid, &uhid->input_buf); in uhid_char_write()
760 mutex_unlock(&uhid->devlock); in uhid_char_write()
768 struct uhid_device *uhid = file->private_data; in uhid_char_poll() local
771 poll_wait(file, &uhid->waitq, wait); in uhid_char_poll()
773 if (uhid->head != uhid->tail) in uhid_char_poll()