Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 264753
b: refs/heads/master
c: 29d2806
h: refs/heads/master
i:
  264751: d704372
v: v3
  • Loading branch information
David Herrmann authored and Jiri Kosina committed Sep 7, 2011
1 parent cf7bc1d commit 3639558
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: be1ecd62e619dae8d7c5b7f212333558fcc85d4d
refs/heads/master: 29d28064e27d11433c4249369f469fab86826d0c
56 changes: 56 additions & 0 deletions trunk/drivers/hid/hid-wiimote.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
* any later version.
*/

#include <linux/completion.h>
#include <linux/device.h>
#include <linux/hid.h>
#include <linux/input.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include "hid-ids.h"

Expand All @@ -31,6 +33,12 @@ struct wiimote_state {
spinlock_t lock;
__u8 flags;
__u8 accel_split[2];

/* synchronous cmd requests */
struct mutex sync;
struct completion ready;
int cmd;
__u32 opt;
};

struct wiimote_data {
Expand Down Expand Up @@ -118,6 +126,52 @@ static __u16 wiiproto_keymap[] = {
BTN_MODE, /* WIIPROTO_KEY_HOME */
};

/* requires the state.lock spinlock to be held */
static inline bool wiimote_cmd_pending(struct wiimote_data *wdata, int cmd,
__u32 opt)
{
return wdata->state.cmd == cmd && wdata->state.opt == opt;
}

/* requires the state.lock spinlock to be held */
static inline void wiimote_cmd_complete(struct wiimote_data *wdata)
{
wdata->state.cmd = WIIPROTO_REQ_NULL;
complete(&wdata->state.ready);
}

static inline int wiimote_cmd_acquire(struct wiimote_data *wdata)
{
return mutex_lock_interruptible(&wdata->state.sync) ? -ERESTARTSYS : 0;
}

/* requires the state.lock spinlock to be held */
static inline void wiimote_cmd_set(struct wiimote_data *wdata, int cmd,
__u32 opt)
{
INIT_COMPLETION(wdata->state.ready);
wdata->state.cmd = cmd;
wdata->state.opt = opt;
}

static inline void wiimote_cmd_release(struct wiimote_data *wdata)
{
mutex_unlock(&wdata->state.sync);
}

static inline int wiimote_cmd_wait(struct wiimote_data *wdata)
{
int ret;

ret = wait_for_completion_interruptible_timeout(&wdata->state.ready, HZ);
if (ret < 0)
return -ERESTARTSYS;
else if (ret == 0)
return -EIO;
else
return 0;
}

static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer,
size_t count)
{
Expand Down Expand Up @@ -875,6 +929,8 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev)
INIT_WORK(&wdata->worker, wiimote_worker);

spin_lock_init(&wdata->state.lock);
init_completion(&wdata->state.ready);
mutex_init(&wdata->state.sync);

return wdata;

Expand Down

0 comments on commit 3639558

Please sign in to comment.