2 * Debug support for HID Nintendo Wiimote devices
3 * Copyright (c) 2011 David Herrmann
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
13 #include <linux/debugfs.h>
14 #include <linux/module.h>
15 #include <linux/spinlock.h>
16 #include <linux/uaccess.h>
17 #include "hid-wiimote.h"
19 struct wiimote_debug
{
20 struct wiimote_data
*wdata
;
21 struct dentry
*eeprom
;
24 static int wiidebug_eeprom_open(struct inode
*i
, struct file
*f
)
26 f
->private_data
= i
->i_private
;
30 static ssize_t
wiidebug_eeprom_read(struct file
*f
, char __user
*u
, size_t s
,
33 struct wiimote_debug
*dbg
= f
->private_data
;
34 struct wiimote_data
*wdata
= dbg
->wdata
;
47 ret
= wiimote_cmd_acquire(wdata
);
51 spin_lock_irqsave(&wdata
->state
.lock
, flags
);
52 wdata
->state
.cmd_read_size
= s
;
53 wdata
->state
.cmd_read_buf
= buf
;
54 wiimote_cmd_set(wdata
, WIIPROTO_REQ_RMEM
, *off
& 0xffff);
55 wiiproto_req_reeprom(wdata
, *off
, s
);
56 spin_unlock_irqrestore(&wdata
->state
.lock
, flags
);
58 ret
= wiimote_cmd_wait(wdata
);
60 size
= wdata
->state
.cmd_read_size
;
62 spin_lock_irqsave(&wdata
->state
.lock
, flags
);
63 wdata
->state
.cmd_read_buf
= NULL
;
64 spin_unlock_irqrestore(&wdata
->state
.lock
, flags
);
66 wiimote_cmd_release(wdata
);
73 if (copy_to_user(u
, buf
, size
))
82 static const struct file_operations wiidebug_eeprom_fops
= {
84 .open
= wiidebug_eeprom_open
,
85 .read
= wiidebug_eeprom_read
,
86 .llseek
= generic_file_llseek
,
89 int wiidebug_init(struct wiimote_data
*wdata
)
91 struct wiimote_debug
*dbg
;
94 dbg
= kzalloc(sizeof(*dbg
), GFP_KERNEL
);
100 dbg
->eeprom
= debugfs_create_file("eeprom", S_IRUSR
,
101 dbg
->wdata
->hdev
->debug_dir
, dbg
, &wiidebug_eeprom_fops
);
107 spin_lock_irqsave(&wdata
->state
.lock
, flags
);
109 spin_unlock_irqrestore(&wdata
->state
.lock
, flags
);
114 void wiidebug_deinit(struct wiimote_data
*wdata
)
116 struct wiimote_debug
*dbg
= wdata
->debug
;
122 spin_lock_irqsave(&wdata
->state
.lock
, flags
);
124 spin_unlock_irqrestore(&wdata
->state
.lock
, flags
);
126 debugfs_remove(dbg
->eeprom
);