2 * Marvell Bluetooth driver: debugfs related functions
4 * Copyright (C) 2009, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
15 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
17 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
18 * this warranty disclaimer.
21 #include <linux/debugfs.h>
23 #include <net/bluetooth/bluetooth.h>
24 #include <net/bluetooth/hci_core.h>
26 #include "btmrvl_drv.h"
28 struct btmrvl_debugfs_data
{
29 struct dentry
*root_dir
, *config_dir
, *status_dir
;
32 struct dentry
*psmode
;
34 struct dentry
*hsmode
;
36 struct dentry
*gpiogap
;
37 struct dentry
*hscfgcmd
;
40 struct dentry
*curpsmode
;
41 struct dentry
*hsstate
;
42 struct dentry
*psstate
;
43 struct dentry
*txdnldready
;
46 static int btmrvl_open_generic(struct inode
*inode
, struct file
*file
)
48 file
->private_data
= inode
->i_private
;
52 static ssize_t
btmrvl_hscfgcmd_write(struct file
*file
,
53 const char __user
*ubuf
, size_t count
, loff_t
*ppos
)
55 struct btmrvl_private
*priv
= file
->private_data
;
59 memset(buf
, 0, sizeof(buf
));
61 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
64 ret
= strict_strtol(buf
, 10, &result
);
66 priv
->btmrvl_dev
.hscfgcmd
= result
;
68 if (priv
->btmrvl_dev
.hscfgcmd
) {
69 btmrvl_prepare_command(priv
);
70 wake_up_interruptible(&priv
->main_thread
.wait_q
);
76 static ssize_t
btmrvl_hscfgcmd_read(struct file
*file
, char __user
*userbuf
,
77 size_t count
, loff_t
*ppos
)
79 struct btmrvl_private
*priv
= file
->private_data
;
83 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n",
84 priv
->btmrvl_dev
.hscfgcmd
);
86 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
89 static const struct file_operations btmrvl_hscfgcmd_fops
= {
90 .read
= btmrvl_hscfgcmd_read
,
91 .write
= btmrvl_hscfgcmd_write
,
92 .open
= btmrvl_open_generic
,
95 static ssize_t
btmrvl_psmode_write(struct file
*file
, const char __user
*ubuf
,
96 size_t count
, loff_t
*ppos
)
98 struct btmrvl_private
*priv
= file
->private_data
;
102 memset(buf
, 0, sizeof(buf
));
104 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
107 ret
= strict_strtol(buf
, 10, &result
);
109 priv
->btmrvl_dev
.psmode
= result
;
114 static ssize_t
btmrvl_psmode_read(struct file
*file
, char __user
*userbuf
,
115 size_t count
, loff_t
*ppos
)
117 struct btmrvl_private
*priv
= file
->private_data
;
121 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n",
122 priv
->btmrvl_dev
.psmode
);
124 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
127 static const struct file_operations btmrvl_psmode_fops
= {
128 .read
= btmrvl_psmode_read
,
129 .write
= btmrvl_psmode_write
,
130 .open
= btmrvl_open_generic
,
133 static ssize_t
btmrvl_pscmd_write(struct file
*file
, const char __user
*ubuf
,
134 size_t count
, loff_t
*ppos
)
136 struct btmrvl_private
*priv
= file
->private_data
;
140 memset(buf
, 0, sizeof(buf
));
142 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
145 ret
= strict_strtol(buf
, 10, &result
);
147 priv
->btmrvl_dev
.pscmd
= result
;
149 if (priv
->btmrvl_dev
.pscmd
) {
150 btmrvl_prepare_command(priv
);
151 wake_up_interruptible(&priv
->main_thread
.wait_q
);
158 static ssize_t
btmrvl_pscmd_read(struct file
*file
, char __user
*userbuf
,
159 size_t count
, loff_t
*ppos
)
161 struct btmrvl_private
*priv
= file
->private_data
;
165 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n", priv
->btmrvl_dev
.pscmd
);
167 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
170 static const struct file_operations btmrvl_pscmd_fops
= {
171 .read
= btmrvl_pscmd_read
,
172 .write
= btmrvl_pscmd_write
,
173 .open
= btmrvl_open_generic
,
176 static ssize_t
btmrvl_gpiogap_write(struct file
*file
, const char __user
*ubuf
,
177 size_t count
, loff_t
*ppos
)
179 struct btmrvl_private
*priv
= file
->private_data
;
183 memset(buf
, 0, sizeof(buf
));
185 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
188 ret
= strict_strtol(buf
, 16, &result
);
190 priv
->btmrvl_dev
.gpio_gap
= result
;
195 static ssize_t
btmrvl_gpiogap_read(struct file
*file
, char __user
*userbuf
,
196 size_t count
, loff_t
*ppos
)
198 struct btmrvl_private
*priv
= file
->private_data
;
202 ret
= snprintf(buf
, sizeof(buf
) - 1, "0x%x\n",
203 priv
->btmrvl_dev
.gpio_gap
);
205 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
208 static const struct file_operations btmrvl_gpiogap_fops
= {
209 .read
= btmrvl_gpiogap_read
,
210 .write
= btmrvl_gpiogap_write
,
211 .open
= btmrvl_open_generic
,
214 static ssize_t
btmrvl_hscmd_write(struct file
*file
, const char __user
*ubuf
,
215 size_t count
, loff_t
*ppos
)
217 struct btmrvl_private
*priv
= (struct btmrvl_private
*) file
->private_data
;
221 memset(buf
, 0, sizeof(buf
));
223 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
226 ret
= strict_strtol(buf
, 10, &result
);
228 priv
->btmrvl_dev
.hscmd
= result
;
229 if (priv
->btmrvl_dev
.hscmd
) {
230 btmrvl_prepare_command(priv
);
231 wake_up_interruptible(&priv
->main_thread
.wait_q
);
237 static ssize_t
btmrvl_hscmd_read(struct file
*file
, char __user
*userbuf
,
238 size_t count
, loff_t
*ppos
)
240 struct btmrvl_private
*priv
= file
->private_data
;
244 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n", priv
->btmrvl_dev
.hscmd
);
246 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
249 static const struct file_operations btmrvl_hscmd_fops
= {
250 .read
= btmrvl_hscmd_read
,
251 .write
= btmrvl_hscmd_write
,
252 .open
= btmrvl_open_generic
,
255 static ssize_t
btmrvl_hsmode_write(struct file
*file
, const char __user
*ubuf
,
256 size_t count
, loff_t
*ppos
)
258 struct btmrvl_private
*priv
= file
->private_data
;
262 memset(buf
, 0, sizeof(buf
));
264 if (copy_from_user(&buf
, ubuf
, min_t(size_t, sizeof(buf
) - 1, count
)))
267 ret
= strict_strtol(buf
, 10, &result
);
269 priv
->btmrvl_dev
.hsmode
= result
;
274 static ssize_t
btmrvl_hsmode_read(struct file
*file
, char __user
* userbuf
,
275 size_t count
, loff_t
*ppos
)
277 struct btmrvl_private
*priv
= file
->private_data
;
281 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n", priv
->btmrvl_dev
.hsmode
);
283 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
286 static const struct file_operations btmrvl_hsmode_fops
= {
287 .read
= btmrvl_hsmode_read
,
288 .write
= btmrvl_hsmode_write
,
289 .open
= btmrvl_open_generic
,
292 static ssize_t
btmrvl_curpsmode_read(struct file
*file
, char __user
*userbuf
,
293 size_t count
, loff_t
*ppos
)
295 struct btmrvl_private
*priv
= file
->private_data
;
299 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n", priv
->adapter
->psmode
);
301 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
304 static const struct file_operations btmrvl_curpsmode_fops
= {
305 .read
= btmrvl_curpsmode_read
,
306 .open
= btmrvl_open_generic
,
309 static ssize_t
btmrvl_psstate_read(struct file
*file
, char __user
* userbuf
,
310 size_t count
, loff_t
*ppos
)
312 struct btmrvl_private
*priv
= file
->private_data
;
316 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n", priv
->adapter
->ps_state
);
318 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
321 static const struct file_operations btmrvl_psstate_fops
= {
322 .read
= btmrvl_psstate_read
,
323 .open
= btmrvl_open_generic
,
326 static ssize_t
btmrvl_hsstate_read(struct file
*file
, char __user
*userbuf
,
327 size_t count
, loff_t
*ppos
)
329 struct btmrvl_private
*priv
= file
->private_data
;
333 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n", priv
->adapter
->hs_state
);
335 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
338 static const struct file_operations btmrvl_hsstate_fops
= {
339 .read
= btmrvl_hsstate_read
,
340 .open
= btmrvl_open_generic
,
343 static ssize_t
btmrvl_txdnldready_read(struct file
*file
, char __user
*userbuf
,
344 size_t count
, loff_t
*ppos
)
346 struct btmrvl_private
*priv
= file
->private_data
;
350 ret
= snprintf(buf
, sizeof(buf
) - 1, "%d\n",
351 priv
->btmrvl_dev
.tx_dnld_rdy
);
353 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, ret
);
356 static const struct file_operations btmrvl_txdnldready_fops
= {
357 .read
= btmrvl_txdnldready_read
,
358 .open
= btmrvl_open_generic
,
361 void btmrvl_debugfs_init(struct hci_dev
*hdev
)
363 struct btmrvl_private
*priv
= hdev
->driver_data
;
364 struct btmrvl_debugfs_data
*dbg
;
366 dbg
= kzalloc(sizeof(*dbg
), GFP_KERNEL
);
367 priv
->debugfs_data
= dbg
;
370 BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
374 dbg
->root_dir
= debugfs_create_dir("btmrvl", NULL
);
376 dbg
->config_dir
= debugfs_create_dir("config", dbg
->root_dir
);
378 dbg
->psmode
= debugfs_create_file("psmode", 0644, dbg
->config_dir
,
379 hdev
->driver_data
, &btmrvl_psmode_fops
);
380 dbg
->pscmd
= debugfs_create_file("pscmd", 0644, dbg
->config_dir
,
381 hdev
->driver_data
, &btmrvl_pscmd_fops
);
382 dbg
->gpiogap
= debugfs_create_file("gpiogap", 0644, dbg
->config_dir
,
383 hdev
->driver_data
, &btmrvl_gpiogap_fops
);
384 dbg
->hsmode
= debugfs_create_file("hsmode", 0644, dbg
->config_dir
,
385 hdev
->driver_data
, &btmrvl_hsmode_fops
);
386 dbg
->hscmd
= debugfs_create_file("hscmd", 0644, dbg
->config_dir
,
387 hdev
->driver_data
, &btmrvl_hscmd_fops
);
388 dbg
->hscfgcmd
= debugfs_create_file("hscfgcmd", 0644, dbg
->config_dir
,
389 hdev
->driver_data
, &btmrvl_hscfgcmd_fops
);
391 dbg
->status_dir
= debugfs_create_dir("status", dbg
->root_dir
);
392 dbg
->curpsmode
= debugfs_create_file("curpsmode", 0444,
395 &btmrvl_curpsmode_fops
);
396 dbg
->psstate
= debugfs_create_file("psstate", 0444, dbg
->status_dir
,
397 hdev
->driver_data
, &btmrvl_psstate_fops
);
398 dbg
->hsstate
= debugfs_create_file("hsstate", 0444, dbg
->status_dir
,
399 hdev
->driver_data
, &btmrvl_hsstate_fops
);
400 dbg
->txdnldready
= debugfs_create_file("txdnldready", 0444,
403 &btmrvl_txdnldready_fops
);
406 void btmrvl_debugfs_remove(struct hci_dev
*hdev
)
408 struct btmrvl_private
*priv
= hdev
->driver_data
;
409 struct btmrvl_debugfs_data
*dbg
= priv
->debugfs_data
;
414 debugfs_remove(dbg
->psmode
);
415 debugfs_remove(dbg
->pscmd
);
416 debugfs_remove(dbg
->gpiogap
);
417 debugfs_remove(dbg
->hsmode
);
418 debugfs_remove(dbg
->hscmd
);
419 debugfs_remove(dbg
->hscfgcmd
);
420 debugfs_remove(dbg
->config_dir
);
422 debugfs_remove(dbg
->curpsmode
);
423 debugfs_remove(dbg
->psstate
);
424 debugfs_remove(dbg
->hsstate
);
425 debugfs_remove(dbg
->txdnldready
);
426 debugfs_remove(dbg
->status_dir
);
428 debugfs_remove(dbg
->root_dir
);