From: David Herrmann <dh.herrmann@googlemail.com>
To: linux-input@vger.kernel.org
Cc: jkosina@suse.cz, David Herrmann <dh.herrmann@googlemail.com>
Subject: [PATCH v2 10/15] HID: wiimote: Add write-register helpers
Date: Tue, 6 Sep 2011 13:50:35 +0200 [thread overview]
Message-ID: <1315309840-4664-11-git-send-email-dh.herrmann@googlemail.com> (raw)
In-Reply-To: <1315309840-4664-1-git-send-email-dh.herrmann@googlemail.com>
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>
---
drivers/hid/hid-wiimote.c | 28 +++++++++++++++++++++++++++-
1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c
index 0a5e458..59a0893 100644
--- a/drivers/hid/hid-wiimote.c
+++ b/drivers/hid/hid-wiimote.c
@@ -39,6 +39,9 @@ struct wiimote_state {
struct completion ready;
int cmd;
__u32 opt;
+
+ /* results of synchronous requests */
+ __u8 cmd_err;
};
struct wiimote_data {
@@ -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;
@@ -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)
--
1.7.6.1
next prev parent reply other threads:[~2011-09-06 11:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-06 11:50 [PATCH v2 00/15] Extended Wiimote Support David Herrmann
2011-09-06 11:50 ` [PATCH v2 01/15] HID: wiimote: Support rumble device David Herrmann
2011-09-06 11:50 ` [PATCH v2 02/15] HID: wiimote: Add force-feedback support David Herrmann
2011-09-06 11:50 ` [PATCH v2 03/15] HID: wiimote: Add accelerometer input device David Herrmann
2011-09-06 11:50 ` [PATCH v2 04/15] HID: wiimote: Parse accelerometer data David Herrmann
2011-09-06 11:50 ` [PATCH v2 05/15] HID: wiimote: Add IR input device David Herrmann
2011-09-06 11:50 ` [PATCH v2 06/15] HID: wiimote: Parse IR data David Herrmann
2011-09-06 11:50 ` [PATCH v2 07/15] HID: wiimote: Add missing extension DRM handlers David Herrmann
2011-09-06 11:50 ` [PATCH v2 08/15] HID: wiimote: Add register/eeprom memory support David Herrmann
2011-09-06 11:50 ` [PATCH v2 09/15] HID: wiimote: Helper functions for synchronous requests David Herrmann
2011-09-06 11:50 ` David Herrmann [this message]
2011-09-06 11:50 ` [PATCH v2 11/15] HID: wiimote: Add IR initializer David Herrmann
2011-09-06 11:50 ` [PATCH v2 12/15] HID: wiimote: Initialize IR cam on request David Herrmann
2011-09-06 11:50 ` [PATCH v2 13/15] HID: wiimote: Add status request David Herrmann
2011-09-06 11:50 ` [PATCH v2 14/15] HID: wiimote: Read wiimote battery charge level David Herrmann
2011-09-06 11:50 ` [PATCH v2 15/15] HID: wiimote: Add MAINTAINERS entry David Herrmann
2011-09-07 11:29 ` [PATCH v2 00/15] Extended Wiimote Support Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1315309840-4664-11-git-send-email-dh.herrmann@googlemail.com \
--to=dh.herrmann@googlemail.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).