diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-05-05 17:12:46 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-06-03 05:06:58 -0400 |
commit | 139385383267de547f5dbdbd2049d3a9c996c85e (patch) | |
tree | fda36e038e466cfa56863b1d9e5909d7964896ba /drivers/hid/hid-wiimote-core.c | |
parent | 92eda7e4e5f9728e643553b378f55c75739554c2 (diff) |
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: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-wiimote-core.c')
-rw-r--r-- | drivers/hid/hid-wiimote-core.c | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c index 119dc56ec0c3..2d85d3a8b60a 100644 --- a/drivers/hid/hid-wiimote-core.c +++ b/drivers/hid/hid-wiimote-core.c | |||
@@ -56,6 +56,8 @@ static enum power_supply_property wiimote_battery_props[] = { | |||
56 | POWER_SUPPLY_PROP_SCOPE, | 56 | POWER_SUPPLY_PROP_SCOPE, |
57 | }; | 57 | }; |
58 | 58 | ||
59 | /* output queue handling */ | ||
60 | |||
59 | static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, | 61 | static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, |
60 | size_t count) | 62 | size_t count) |
61 | { | 63 | { |
@@ -75,24 +77,27 @@ static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, | |||
75 | return ret; | 77 | return ret; |
76 | } | 78 | } |
77 | 79 | ||
78 | static void wiimote_worker(struct work_struct *work) | 80 | static void wiimote_queue_worker(struct work_struct *work) |
79 | { | 81 | { |
80 | struct wiimote_data *wdata = container_of(work, struct wiimote_data, | 82 | struct wiimote_queue *queue = container_of(work, struct wiimote_queue, |
81 | worker); | 83 | worker); |
84 | struct wiimote_data *wdata = container_of(queue, struct wiimote_data, | ||
85 | queue); | ||
82 | unsigned long flags; | 86 | unsigned long flags; |
83 | 87 | ||
84 | spin_lock_irqsave(&wdata->qlock, flags); | 88 | spin_lock_irqsave(&wdata->queue.lock, flags); |
85 | 89 | ||
86 | while (wdata->head != wdata->tail) { | 90 | while (wdata->queue.head != wdata->queue.tail) { |
87 | spin_unlock_irqrestore(&wdata->qlock, flags); | 91 | spin_unlock_irqrestore(&wdata->queue.lock, flags); |
88 | wiimote_hid_send(wdata->hdev, wdata->outq[wdata->tail].data, | 92 | wiimote_hid_send(wdata->hdev, |
89 | wdata->outq[wdata->tail].size); | 93 | wdata->queue.outq[wdata->queue.tail].data, |
90 | spin_lock_irqsave(&wdata->qlock, flags); | 94 | wdata->queue.outq[wdata->queue.tail].size); |
95 | spin_lock_irqsave(&wdata->queue.lock, flags); | ||
91 | 96 | ||
92 | wdata->tail = (wdata->tail + 1) % WIIMOTE_BUFSIZE; | 97 | wdata->queue.tail = (wdata->queue.tail + 1) % WIIMOTE_BUFSIZE; |
93 | } | 98 | } |
94 | 99 | ||
95 | spin_unlock_irqrestore(&wdata->qlock, flags); | 100 | spin_unlock_irqrestore(&wdata->queue.lock, flags); |
96 | } | 101 | } |
97 | 102 | ||
98 | static void wiimote_queue(struct wiimote_data *wdata, const __u8 *buffer, | 103 | 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 | * will reschedule itself until the queue is empty. | 121 | * will reschedule itself until the queue is empty. |
117 | */ | 122 | */ |
118 | 123 | ||
119 | spin_lock_irqsave(&wdata->qlock, flags); | 124 | spin_lock_irqsave(&wdata->queue.lock, flags); |
120 | 125 | ||
121 | memcpy(wdata->outq[wdata->head].data, buffer, count); | 126 | memcpy(wdata->queue.outq[wdata->queue.head].data, buffer, count); |
122 | wdata->outq[wdata->head].size = count; | 127 | wdata->queue.outq[wdata->queue.head].size = count; |
123 | newhead = (wdata->head + 1) % WIIMOTE_BUFSIZE; | 128 | newhead = (wdata->queue.head + 1) % WIIMOTE_BUFSIZE; |
124 | 129 | ||
125 | if (wdata->head == wdata->tail) { | 130 | if (wdata->queue.head == wdata->queue.tail) { |
126 | wdata->head = newhead; | 131 | wdata->queue.head = newhead; |
127 | schedule_work(&wdata->worker); | 132 | schedule_work(&wdata->queue.worker); |
128 | } else if (newhead != wdata->tail) { | 133 | } else if (newhead != wdata->queue.tail) { |
129 | wdata->head = newhead; | 134 | wdata->queue.head = newhead; |
130 | } else { | 135 | } else { |
131 | hid_warn(wdata->hdev, "Output queue is full"); | 136 | hid_warn(wdata->hdev, "Output queue is full"); |
132 | } | 137 | } |
133 | 138 | ||
134 | spin_unlock_irqrestore(&wdata->qlock, flags); | 139 | spin_unlock_irqrestore(&wdata->queue.lock, flags); |
135 | } | 140 | } |
136 | 141 | ||
137 | /* | 142 | /* |
@@ -1157,8 +1162,8 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev) | |||
1157 | input_set_abs_params(wdata->ir, ABS_HAT3X, 0, 1023, 2, 4); | 1162 | input_set_abs_params(wdata->ir, ABS_HAT3X, 0, 1023, 2, 4); |
1158 | input_set_abs_params(wdata->ir, ABS_HAT3Y, 0, 767, 2, 4); | 1163 | input_set_abs_params(wdata->ir, ABS_HAT3Y, 0, 767, 2, 4); |
1159 | 1164 | ||
1160 | spin_lock_init(&wdata->qlock); | 1165 | spin_lock_init(&wdata->queue.lock); |
1161 | INIT_WORK(&wdata->worker, wiimote_worker); | 1166 | INIT_WORK(&wdata->queue.worker, wiimote_queue_worker); |
1162 | 1167 | ||
1163 | spin_lock_init(&wdata->state.lock); | 1168 | spin_lock_init(&wdata->state.lock); |
1164 | init_completion(&wdata->state.ready); | 1169 | init_completion(&wdata->state.ready); |
@@ -1187,7 +1192,7 @@ static void wiimote_destroy(struct wiimote_data *wdata) | |||
1187 | input_unregister_device(wdata->accel); | 1192 | input_unregister_device(wdata->accel); |
1188 | input_unregister_device(wdata->ir); | 1193 | input_unregister_device(wdata->ir); |
1189 | input_unregister_device(wdata->input); | 1194 | input_unregister_device(wdata->input); |
1190 | cancel_work_sync(&wdata->worker); | 1195 | cancel_work_sync(&wdata->queue.worker); |
1191 | hid_hw_stop(wdata->hdev); | 1196 | hid_hw_stop(wdata->hdev); |
1192 | 1197 | ||
1193 | kfree(wdata); | 1198 | kfree(wdata); |