From: David Herrmann <dh.herrmann@googlemail.com>
To: linux-input@vger.kernel.org
Cc: jkosina@suse.cz, oneukum@suse.de,
David Herrmann <dh.herrmann@googlemail.com>
Subject: [PATCH v2 06/17] HID: wiimote: Add extension initializers
Date: Thu, 17 Nov 2011 14:12:03 +0100 [thread overview]
Message-ID: <1321535534-7950-7-git-send-email-dh.herrmann@googlemail.com> (raw)
In-Reply-To: <1321535534-7950-1-git-send-email-dh.herrmann@googlemail.com>
The wiimote extension registers are not fully understood, so we always disable
all extensions on extension-port events. Then we reinitialize and reidentify
them and activate all requested extensions.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
---
drivers/hid/hid-wiimote-ext.c | 81 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 79 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-wiimote-ext.c b/drivers/hid/hid-wiimote-ext.c
index 3e3e1fc..233bdfe 100644
--- a/drivers/hid/hid-wiimote-ext.c
+++ b/drivers/hid/hid-wiimote-ext.c
@@ -37,30 +37,107 @@ enum wiiext_type {
static void ext_disable(struct wiimote_ext *ext)
{
unsigned long flags;
+ __u8 wmem = 0x55;
+
+ if (!wiimote_cmd_acquire(ext->wdata)) {
+ wiimote_cmd_write(ext->wdata, 0xa400f0, &wmem, sizeof(wmem));
+ wiimote_cmd_release(ext->wdata);
+ }
spin_lock_irqsave(&ext->wdata->state.lock, flags);
ext->motionp = false;
ext->ext_type = WIIEXT_NONE;
+ wiiproto_req_drm(ext->wdata, WIIPROTO_REQ_NULL);
spin_unlock_irqrestore(&ext->wdata->state.lock, flags);
}
static bool motionp_read(struct wiimote_ext *ext)
{
- return false;
+ __u8 rmem[2], wmem;
+ ssize_t ret;
+ bool avail = false;
+
+ if (wiimote_cmd_acquire(ext->wdata))
+ return false;
+
+ /* initialize motion plus */
+ wmem = 0x55;
+ ret = wiimote_cmd_write(ext->wdata, 0xa600f0, &wmem, sizeof(wmem));
+ if (ret)
+ goto error;
+
+ /* read motion plus ID */
+ ret = wiimote_cmd_read(ext->wdata, 0xa600fe, rmem, 2);
+ if (ret == 2 || rmem[1] == 0x5)
+ avail = true;
+
+error:
+ wiimote_cmd_release(ext->wdata);
+ return avail;
}
static __u8 ext_read(struct wiimote_ext *ext)
{
- return WIIEXT_NONE;
+ ssize_t ret;
+ __u8 rmem[2], wmem;
+ __u8 type = WIIEXT_NONE;
+
+ if (!ext->plugged)
+ return WIIEXT_NONE;
+
+ if (wiimote_cmd_acquire(ext->wdata))
+ return WIIEXT_NONE;
+
+ /* initialize extension */
+ wmem = 0x55;
+ ret = wiimote_cmd_write(ext->wdata, 0xa400f0, &wmem, sizeof(wmem));
+ if (!ret) {
+ /* disable encryption */
+ wmem = 0x0;
+ wiimote_cmd_write(ext->wdata, 0xa400fb, &wmem, sizeof(wmem));
+ }
+
+ /* read extension ID */
+ ret = wiimote_cmd_read(ext->wdata, 0xa400fe, rmem, 2);
+ if (ret == 2) {
+ if (rmem[0] == 0 && rmem[1] == 0)
+ type = WIIEXT_NUNCHUCK;
+ else if (rmem[0] == 0x01 && rmem[1] == 0x01)
+ type = WIIEXT_CLASSIC;
+ }
+
+ wiimote_cmd_release(ext->wdata);
+
+ return type;
}
static void ext_enable(struct wiimote_ext *ext, bool motionp, __u8 ext_type)
{
unsigned long flags;
+ __u8 wmem;
+ int ret;
+
+ if (motionp) {
+ if (wiimote_cmd_acquire(ext->wdata))
+ return;
+
+ if (ext_type == WIIEXT_CLASSIC)
+ wmem = 0x07;
+ else if (ext_type == WIIEXT_NUNCHUCK)
+ wmem = 0x05;
+ else
+ wmem = 0x04;
+
+ ret = wiimote_cmd_write(ext->wdata, 0xa600fe, &wmem, sizeof(wmem));
+ wiimote_cmd_release(ext->wdata);
+ if (ret)
+ return;
+ }
spin_lock_irqsave(&ext->wdata->state.lock, flags);
ext->motionp = motionp;
ext->ext_type = ext_type;
+ wiiproto_req_drm(ext->wdata, WIIPROTO_REQ_NULL);
spin_unlock_irqrestore(&ext->wdata->state.lock, flags);
}
--
1.7.7.3
next prev parent reply other threads:[~2011-11-17 13:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-17 13:11 [PATCH v2 00/17] HID: Wiimote Extension Support v2 David Herrmann
2011-11-17 13:11 ` [PATCH v2 01/17] HID: wiimote: Rename driver to allow multiple source files David Herrmann
2011-11-17 13:11 ` [PATCH v2 02/17] HID: wiimote: Move common symbols into header David Herrmann
2011-11-17 13:12 ` [PATCH v2 03/17] HID: wiimote: Add read-mem helpers David Herrmann
2011-11-17 13:12 ` [PATCH v2 04/17] HID: wiimote: Add extension support stub David Herrmann
2011-11-17 13:12 ` [PATCH v2 05/17] HID: wiimote: Add extension initializer stubs David Herrmann
2011-11-17 13:12 ` David Herrmann [this message]
2011-11-17 13:12 ` [PATCH v2 07/17] HID: wiimote: Add extension sysfs attribute David Herrmann
2011-11-17 13:12 ` [PATCH v2 08/17] HID: wiimote: Register input devices for extensions David Herrmann
2011-11-17 13:12 ` [PATCH v2 09/17] HID: wiimote: Add extension handler stubs David Herrmann
2011-11-17 13:12 ` [PATCH v2 10/17] HID: wiimote: Parse motion+ data David Herrmann
2011-11-17 13:12 ` [PATCH v2 11/17] HID: wiimote: Parse nunchuck data David Herrmann
2011-11-17 13:12 ` [PATCH v2 12/17] HID: wiimote: Parse classic controller data David Herrmann
2011-11-17 13:12 ` [PATCH v2 13/17] HID: wiimote: Add debugfs support stubs David Herrmann
2011-11-17 13:12 ` [PATCH v2 14/17] HID: wiimote: Allow direct eeprom access David Herrmann
2011-11-17 13:12 ` [PATCH v2 15/17] HID: wiimote: Allow direct DRM debug access David Herrmann
2011-11-17 13:12 ` [PATCH v2 16/17] HID: wiimote: Remove module version number David Herrmann
2011-11-17 13:12 ` [PATCH v2 17/17] HID: wiimote: Enable NO_INIT_REPORTS quirk David Herrmann
2011-11-22 22:19 ` [PATCH v2 00/17] HID: Wiimote Extension Support v2 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=1321535534-7950-7-git-send-email-dh.herrmann@googlemail.com \
--to=dh.herrmann@googlemail.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
--cc=oneukum@suse.de \
/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).