All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@googlemail.com>
To: linux-input@vger.kernel.org
Cc: jkosina@suse.cz, padovan@profusion.mobi, dh.herrmann@googlemail.com
Subject: [PATCH 10/16] HID: wiimote: Add register/eeprom memory support
Date: Thu, 28 Jul 2011 18:08:30 +0200	[thread overview]
Message-ID: <1311869316-17128-11-git-send-email-dh.herrmann@googlemail.com> (raw)
In-Reply-To: <1311869316-17128-1-git-send-email-dh.herrmann@googlemail.com>

The wiimote allows direct access to its memory mapped registers and
internal eeprom. This adds support to access this memory and handle
memory events.

There are two macros which wrap up the memory access functions to avoid
accidentally overwriting sensitive eeprom data because a boolean value
was wrongly set.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
---
 drivers/hid/hid-wiimote.c |   71 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c
index 066beb5..7b59822 100644
--- a/drivers/hid/hid-wiimote.c
+++ b/drivers/hid/hid-wiimote.c
@@ -66,7 +66,10 @@ enum wiiproto_reqs {
 	WIIPROTO_REQ_RUMBLE = 0x10,
 	WIIPROTO_REQ_LED = 0x11,
 	WIIPROTO_REQ_DRM = 0x12,
+	WIIPROTO_REQ_WMEM = 0x16,
+	WIIPROTO_REQ_RMEM = 0x17,
 	WIIPROTO_REQ_STATUS = 0x20,
+	WIIPROTO_REQ_DATA = 0x21,
 	WIIPROTO_REQ_RETURN = 0x22,
 	WIIPROTO_REQ_DRM_K = 0x30,
 	WIIPROTO_REQ_DRM_KA = 0x31,
@@ -303,6 +306,68 @@ static void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel)
 	wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
 }
 
+#define wiiproto_req_wreg(wdata, os, buf, sz) \
+			wiiproto_req_wmem((wdata), false, (os), (buf), (sz))
+
+#define wiiproto_req_weeprom(wdata, os, buf, sz) \
+			wiiproto_req_wmem((wdata), true, (os), (buf), (sz))
+
+static void wiiproto_req_wmem(struct wiimote_data *wdata, bool eeprom,
+				__u32 offset, const __u8 *buf, __u8 size)
+{
+	__u8 cmd[22];
+
+	if (size > 16 || size == 0) {
+		hid_warn(wdata->hdev, "Invalid length %d wmem request\n", size);
+		return;
+	}
+
+	memset(cmd, 0, sizeof(cmd));
+	cmd[0] = WIIPROTO_REQ_WMEM;
+	cmd[2] = (offset >> 16) & 0xff;
+	cmd[3] = (offset >> 8) & 0xff;
+	cmd[4] = offset & 0xff;
+	cmd[5] = size;
+	memcpy(&cmd[6], buf, size);
+
+	if (!eeprom)
+		cmd[1] |= 0x04;
+
+	wiiproto_keep_rumble(wdata, &cmd[1]);
+	wiimote_queue(wdata, cmd, sizeof(cmd));
+}
+
+#define wiiproto_req_rreg(wdata, os, sz) \
+			wiiproto_req_rmem((wdata), false, (os), (sz))
+
+#define wiiproto_req_reeprom(wdata, os, sz) \
+			wiiproto_req_rmem((wdata), true, (os), (sz))
+
+static void wiiproto_req_rmem(struct wiimote_data *wdata, bool eeprom,
+						__u32 offset, __u16 size)
+{
+	__u8 cmd[7];
+
+	if (size == 0) {
+		hid_warn(wdata->hdev, "Invalid length %d rmem request\n", size);
+		return;
+	}
+
+	cmd[0] = WIIPROTO_REQ_RMEM;
+	cmd[1] = 0;
+	cmd[2] = (offset >> 16) & 0xff;
+	cmd[3] = (offset >> 8) & 0xff;
+	cmd[4] = offset & 0xff;
+	cmd[5] = (size >> 8) & 0xff;
+	cmd[6] = size & 0xff;
+
+	if (!eeprom)
+		cmd[1] |= 0x04;
+
+	wiiproto_keep_rumble(wdata, &cmd[1]);
+	wiimote_queue(wdata, cmd, sizeof(cmd));
+}
+
 #define wiifs_led_show_set(num)						\
 static ssize_t wiifs_led_show_##num(struct device *dev,			\
 			struct device_attribute *attr, char *buf)	\
@@ -533,6 +598,11 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload)
 	wiiproto_req_drm(wdata, 0);
 }
 
+static void handler_data(struct wiimote_data *wdata, const __u8 *payload)
+{
+	handler_keys(wdata, payload);
+}
+
 static void handler_return(struct wiimote_data *wdata, const __u8 *payload)
 {
 	__u8 err = payload[3];
@@ -640,6 +710,7 @@ struct wiiproto_handler {
 
 static struct wiiproto_handler handlers[] = {
 	{ .id = WIIPROTO_REQ_STATUS, .size = 6, .func = handler_status },
+	{ .id = WIIPROTO_REQ_DATA, .size = 21, .func = handler_data },
 	{ .id = WIIPROTO_REQ_RETURN, .size = 4, .func = handler_return },
 	{ .id = WIIPROTO_REQ_DRM_K, .size = 2, .func = handler_keys },
 	{ .id = WIIPROTO_REQ_DRM_KA, .size = 5, .func = handler_drm_KA },
-- 
1.7.6


  parent reply	other threads:[~2011-07-28 16:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-28 16:08 [PATCH 00/16] Extended wiimote support David Herrmann
2011-07-28 16:08 ` [PATCH 01/16] HID: wiimote: Support rumble device David Herrmann
2011-07-28 16:08 ` [PATCH 02/16] HID: wiimote: Add sysfs rumble attribute David Herrmann
2011-07-28 16:08 ` [PATCH 03/16] HID: wiimote: Add drm request David Herrmann
2011-07-28 18:05   ` Oliver Neukum
2011-07-28 18:41     ` David Herrmann
2011-07-28 18:47       ` Oliver Neukum
2011-07-28 16:08 ` [PATCH 04/16] HID: wiimote: Add status and return request handlers David Herrmann
2011-07-28 16:08 ` [PATCH 05/16] HID: wiimote: Reduce input syncs David Herrmann
2011-07-28 16:08 ` [PATCH 06/16] HID: wiimote: Enable accelerometer on request David Herrmann
2011-07-28 18:08   ` Oliver Neukum
2011-07-28 19:01     ` David Herrmann
2011-07-28 19:32       ` Oliver Neukum
2011-07-28 16:08 ` [PATCH 07/16] HID: wiimote: Parse accelerometer data David Herrmann
2011-07-28 18:12   ` Oliver Neukum
2011-07-28 18:51     ` David Herrmann
2011-08-10 11:55       ` Jiri Kosina
2011-07-28 16:08 ` [PATCH 08/16] HID: wiimote: Parse IR input and report to userspace David Herrmann
2011-07-28 16:08 ` [PATCH 09/16] HID: wiimote: Add missing extension DRM handlers David Herrmann
2011-07-28 16:08 ` David Herrmann [this message]
2011-07-28 16:08 ` [PATCH 11/16] HID: wiimote: Helper functions for synchronous requests David Herrmann
2011-07-28 16:08 ` [PATCH 12/16] HID: wiimote: Add write-register helpers David Herrmann
2011-07-28 16:08 ` [PATCH 13/16] HID: wiimote: Add IR initializer David Herrmann
2011-07-28 16:08 ` [PATCH 14/16] HID: wiimote: Allow userspace to control IR cam David Herrmann
2011-07-28 16:08 ` [PATCH 15/16] HID: wiimote: Read wiimote battery charge level David Herrmann
2011-07-28 16:08 ` [PATCH 16/16] HID: wiimote: Allow EEPROM debugfs access David Herrmann

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=1311869316-17128-11-git-send-email-dh.herrmann@googlemail.com \
    --to=dh.herrmann@googlemail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=padovan@profusion.mobi \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.