diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2011-09-06 07:50:33 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-09-07 07:25:16 -0400 |
commit | be1ecd62e619dae8d7c5b7f212333558fcc85d4d (patch) | |
tree | 245618c541c20d91109f331aa948412d28ef7284 | |
parent | 7336b9f93a26082ecb068b5db42b2ed0dbf802bd (diff) |
HID: wiimote: Add register/eeprom memory support
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>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | drivers/hid/hid-wiimote.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index a99e058676fa..c811a7d14174 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c | |||
@@ -71,7 +71,10 @@ enum wiiproto_reqs { | |||
71 | WIIPROTO_REQ_RUMBLE = 0x10, | 71 | WIIPROTO_REQ_RUMBLE = 0x10, |
72 | WIIPROTO_REQ_LED = 0x11, | 72 | WIIPROTO_REQ_LED = 0x11, |
73 | WIIPROTO_REQ_DRM = 0x12, | 73 | WIIPROTO_REQ_DRM = 0x12, |
74 | WIIPROTO_REQ_WMEM = 0x16, | ||
75 | WIIPROTO_REQ_RMEM = 0x17, | ||
74 | WIIPROTO_REQ_STATUS = 0x20, | 76 | WIIPROTO_REQ_STATUS = 0x20, |
77 | WIIPROTO_REQ_DATA = 0x21, | ||
75 | WIIPROTO_REQ_RETURN = 0x22, | 78 | WIIPROTO_REQ_RETURN = 0x22, |
76 | WIIPROTO_REQ_DRM_K = 0x30, | 79 | WIIPROTO_REQ_DRM_K = 0x30, |
77 | WIIPROTO_REQ_DRM_KA = 0x31, | 80 | WIIPROTO_REQ_DRM_KA = 0x31, |
@@ -306,6 +309,37 @@ static void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel) | |||
306 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); | 309 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); |
307 | } | 310 | } |
308 | 311 | ||
312 | #define wiiproto_req_wreg(wdata, os, buf, sz) \ | ||
313 | wiiproto_req_wmem((wdata), false, (os), (buf), (sz)) | ||
314 | |||
315 | #define wiiproto_req_weeprom(wdata, os, buf, sz) \ | ||
316 | wiiproto_req_wmem((wdata), true, (os), (buf), (sz)) | ||
317 | |||
318 | static void wiiproto_req_wmem(struct wiimote_data *wdata, bool eeprom, | ||
319 | __u32 offset, const __u8 *buf, __u8 size) | ||
320 | { | ||
321 | __u8 cmd[22]; | ||
322 | |||
323 | if (size > 16 || size == 0) { | ||
324 | hid_warn(wdata->hdev, "Invalid length %d wmem request\n", size); | ||
325 | return; | ||
326 | } | ||
327 | |||
328 | memset(cmd, 0, sizeof(cmd)); | ||
329 | cmd[0] = WIIPROTO_REQ_WMEM; | ||
330 | cmd[2] = (offset >> 16) & 0xff; | ||
331 | cmd[3] = (offset >> 8) & 0xff; | ||
332 | cmd[4] = offset & 0xff; | ||
333 | cmd[5] = size; | ||
334 | memcpy(&cmd[6], buf, size); | ||
335 | |||
336 | if (!eeprom) | ||
337 | cmd[1] |= 0x04; | ||
338 | |||
339 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
340 | wiimote_queue(wdata, cmd, sizeof(cmd)); | ||
341 | } | ||
342 | |||
309 | static enum led_brightness wiimote_leds_get(struct led_classdev *led_dev) | 343 | static enum led_brightness wiimote_leds_get(struct led_classdev *led_dev) |
310 | { | 344 | { |
311 | struct wiimote_data *wdata; | 345 | struct wiimote_data *wdata; |
@@ -535,6 +569,11 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload) | |||
535 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); | 569 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); |
536 | } | 570 | } |
537 | 571 | ||
572 | static void handler_data(struct wiimote_data *wdata, const __u8 *payload) | ||
573 | { | ||
574 | handler_keys(wdata, payload); | ||
575 | } | ||
576 | |||
538 | static void handler_return(struct wiimote_data *wdata, const __u8 *payload) | 577 | static void handler_return(struct wiimote_data *wdata, const __u8 *payload) |
539 | { | 578 | { |
540 | __u8 err = payload[3]; | 579 | __u8 err = payload[3]; |
@@ -647,6 +686,7 @@ struct wiiproto_handler { | |||
647 | 686 | ||
648 | static struct wiiproto_handler handlers[] = { | 687 | static struct wiiproto_handler handlers[] = { |
649 | { .id = WIIPROTO_REQ_STATUS, .size = 6, .func = handler_status }, | 688 | { .id = WIIPROTO_REQ_STATUS, .size = 6, .func = handler_status }, |
689 | { .id = WIIPROTO_REQ_DATA, .size = 21, .func = handler_data }, | ||
650 | { .id = WIIPROTO_REQ_RETURN, .size = 4, .func = handler_return }, | 690 | { .id = WIIPROTO_REQ_RETURN, .size = 4, .func = handler_return }, |
651 | { .id = WIIPROTO_REQ_DRM_K, .size = 2, .func = handler_keys }, | 691 | { .id = WIIPROTO_REQ_DRM_K, .size = 2, .func = handler_keys }, |
652 | { .id = WIIPROTO_REQ_DRM_KA, .size = 5, .func = handler_drm_KA }, | 692 | { .id = WIIPROTO_REQ_DRM_KA, .size = 5, .func = handler_drm_KA }, |