Skip to content

Commit

Permalink
HID: wiimote: Add write-register helpers
Browse files Browse the repository at this point in the history
Add helpers to synchronously write registers of the wiimote. This is heavily
used by initialization functions for wiimote peripherals.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
David Herrmann authored and Jiri Kosina committed Sep 7, 2011
1 parent 29d2806 commit 33e8401
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion drivers/hid/hid-wiimote.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct wiimote_state {
struct completion ready;
int cmd;
__u32 opt;

/* results of synchronous requests */
__u8 cmd_err;
};

struct wiimote_data {
Expand Down Expand Up @@ -394,6 +397,25 @@ static void wiiproto_req_wmem(struct wiimote_data *wdata, bool eeprom,
wiimote_queue(wdata, cmd, sizeof(cmd));
}

/* requries the cmd-mutex to be held */
static int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset,
const __u8 *wmem, __u8 size)
{
unsigned long flags;
int ret;

spin_lock_irqsave(&wdata->state.lock, flags);
wiimote_cmd_set(wdata, WIIPROTO_REQ_WMEM, 0);
wiiproto_req_wreg(wdata, offset, wmem, size);
spin_unlock_irqrestore(&wdata->state.lock, flags);

ret = wiimote_cmd_wait(wdata);
if (!ret && wdata->state.cmd_err)
ret = -EIO;

return ret;
}

static enum led_brightness wiimote_leds_get(struct led_classdev *led_dev)
{
struct wiimote_data *wdata;
Expand Down Expand Up @@ -635,9 +657,13 @@ static void handler_return(struct wiimote_data *wdata, const __u8 *payload)

handler_keys(wdata, payload);

if (err)
if (wiimote_cmd_pending(wdata, cmd, 0)) {
wdata->state.cmd_err = err;
wiimote_cmd_complete(wdata);
} else if (err) {
hid_warn(wdata->hdev, "Remote error %hhu on req %hhu\n", err,
cmd);
}
}

static void handler_drm_KA(struct wiimote_data *wdata, const __u8 *payload)
Expand Down

0 comments on commit 33e8401

Please sign in to comment.