提交 13938538 编写于 作者: D David Herrmann 提交者: Jiri Kosina

HID: wiimote: move queue handling into separate struct

The output queue is independent of the other wiimote modules and can run
on its own. Therefore, move its members into a separate struct so we don't
run into name collisions with other modules.

This is only a syntactic change that renames all queue members to queue.*.
Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: NJiri Kosina <jkosina@suse.cz>
上级 92eda7e4
...@@ -56,6 +56,8 @@ static enum power_supply_property wiimote_battery_props[] = { ...@@ -56,6 +56,8 @@ static enum power_supply_property wiimote_battery_props[] = {
POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_SCOPE,
}; };
/* output queue handling */
static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer,
size_t count) size_t count)
{ {
...@@ -75,24 +77,27 @@ static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, ...@@ -75,24 +77,27 @@ static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer,
return ret; return ret;
} }
static void wiimote_worker(struct work_struct *work) static void wiimote_queue_worker(struct work_struct *work)
{ {
struct wiimote_data *wdata = container_of(work, struct wiimote_data, struct wiimote_queue *queue = container_of(work, struct wiimote_queue,
worker); worker);
struct wiimote_data *wdata = container_of(queue, struct wiimote_data,
queue);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&wdata->qlock, flags); spin_lock_irqsave(&wdata->queue.lock, flags);
while (wdata->head != wdata->tail) { while (wdata->queue.head != wdata->queue.tail) {
spin_unlock_irqrestore(&wdata->qlock, flags); spin_unlock_irqrestore(&wdata->queue.lock, flags);
wiimote_hid_send(wdata->hdev, wdata->outq[wdata->tail].data, wiimote_hid_send(wdata->hdev,
wdata->outq[wdata->tail].size); wdata->queue.outq[wdata->queue.tail].data,
spin_lock_irqsave(&wdata->qlock, flags); wdata->queue.outq[wdata->queue.tail].size);
spin_lock_irqsave(&wdata->queue.lock, flags);
wdata->tail = (wdata->tail + 1) % WIIMOTE_BUFSIZE; wdata->queue.tail = (wdata->queue.tail + 1) % WIIMOTE_BUFSIZE;
} }
spin_unlock_irqrestore(&wdata->qlock, flags); spin_unlock_irqrestore(&wdata->queue.lock, flags);
} }
static void wiimote_queue(struct wiimote_data *wdata, const __u8 *buffer, static void wiimote_queue(struct wiimote_data *wdata, const __u8 *buffer,
...@@ -116,22 +121,22 @@ static void wiimote_queue(struct wiimote_data *wdata, const __u8 *buffer, ...@@ -116,22 +121,22 @@ static void wiimote_queue(struct wiimote_data *wdata, const __u8 *buffer,
* will reschedule itself until the queue is empty. * will reschedule itself until the queue is empty.
*/ */
spin_lock_irqsave(&wdata->qlock, flags); spin_lock_irqsave(&wdata->queue.lock, flags);
memcpy(wdata->outq[wdata->head].data, buffer, count); memcpy(wdata->queue.outq[wdata->queue.head].data, buffer, count);
wdata->outq[wdata->head].size = count; wdata->queue.outq[wdata->queue.head].size = count;
newhead = (wdata->head + 1) % WIIMOTE_BUFSIZE; newhead = (wdata->queue.head + 1) % WIIMOTE_BUFSIZE;
if (wdata->head == wdata->tail) { if (wdata->queue.head == wdata->queue.tail) {
wdata->head = newhead; wdata->queue.head = newhead;
schedule_work(&wdata->worker); schedule_work(&wdata->queue.worker);
} else if (newhead != wdata->tail) { } else if (newhead != wdata->queue.tail) {
wdata->head = newhead; wdata->queue.head = newhead;
} else { } else {
hid_warn(wdata->hdev, "Output queue is full"); hid_warn(wdata->hdev, "Output queue is full");
} }
spin_unlock_irqrestore(&wdata->qlock, flags); spin_unlock_irqrestore(&wdata->queue.lock, flags);
} }
/* /*
...@@ -1157,8 +1162,8 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev) ...@@ -1157,8 +1162,8 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev)
input_set_abs_params(wdata->ir, ABS_HAT3X, 0, 1023, 2, 4); input_set_abs_params(wdata->ir, ABS_HAT3X, 0, 1023, 2, 4);
input_set_abs_params(wdata->ir, ABS_HAT3Y, 0, 767, 2, 4); input_set_abs_params(wdata->ir, ABS_HAT3Y, 0, 767, 2, 4);
spin_lock_init(&wdata->qlock); spin_lock_init(&wdata->queue.lock);
INIT_WORK(&wdata->worker, wiimote_worker); INIT_WORK(&wdata->queue.worker, wiimote_queue_worker);
spin_lock_init(&wdata->state.lock); spin_lock_init(&wdata->state.lock);
init_completion(&wdata->state.ready); init_completion(&wdata->state.ready);
...@@ -1187,7 +1192,7 @@ static void wiimote_destroy(struct wiimote_data *wdata) ...@@ -1187,7 +1192,7 @@ static void wiimote_destroy(struct wiimote_data *wdata)
input_unregister_device(wdata->accel); input_unregister_device(wdata->accel);
input_unregister_device(wdata->ir); input_unregister_device(wdata->ir);
input_unregister_device(wdata->input); input_unregister_device(wdata->input);
cancel_work_sync(&wdata->worker); cancel_work_sync(&wdata->queue.worker);
hid_hw_stop(wdata->hdev); hid_hw_stop(wdata->hdev);
kfree(wdata); kfree(wdata);
......
...@@ -48,6 +48,14 @@ struct wiimote_buf { ...@@ -48,6 +48,14 @@ struct wiimote_buf {
size_t size; size_t size;
}; };
struct wiimote_queue {
spinlock_t lock;
struct work_struct worker;
__u8 head;
__u8 tail;
struct wiimote_buf outq[WIIMOTE_BUFSIZE];
};
struct wiimote_state { struct wiimote_state {
spinlock_t lock; spinlock_t lock;
__u8 flags; __u8 flags;
...@@ -77,12 +85,7 @@ struct wiimote_data { ...@@ -77,12 +85,7 @@ struct wiimote_data {
struct wiimote_ext *ext; struct wiimote_ext *ext;
struct wiimote_debug *debug; struct wiimote_debug *debug;
spinlock_t qlock; struct wiimote_queue queue;
__u8 head;
__u8 tail;
struct wiimote_buf outq[WIIMOTE_BUFSIZE];
struct work_struct worker;
struct wiimote_state state; struct wiimote_state state;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册