diff options
Diffstat (limited to 'drivers/misc/iwmc3200top/debugfs.c')
-rw-r--r-- | drivers/misc/iwmc3200top/debugfs.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/drivers/misc/iwmc3200top/debugfs.c b/drivers/misc/iwmc3200top/debugfs.c new file mode 100644 index 000000000000..0c8ea0a1c8a3 --- /dev/null +++ b/drivers/misc/iwmc3200top/debugfs.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * iwmc3200top - Intel Wireless MultiCom 3200 Top Driver | ||
3 | * drivers/misc/iwmc3200top/debufs.c | ||
4 | * | ||
5 | * Copyright (C) 2009 Intel Corporation. All rights reserved. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License version | ||
9 | * 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
19 | * 02110-1301, USA. | ||
20 | * | ||
21 | * | ||
22 | * Author Name: Maxim Grabarnik <maxim.grabarnink@intel.com> | ||
23 | * - | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/string.h> | ||
29 | #include <linux/ctype.h> | ||
30 | #include <linux/mmc/sdio_func.h> | ||
31 | #include <linux/mmc/sdio.h> | ||
32 | #include <linux/debugfs.h> | ||
33 | |||
34 | #include "iwmc3200top.h" | ||
35 | #include "fw-msg.h" | ||
36 | #include "log.h" | ||
37 | #include "debugfs.h" | ||
38 | |||
39 | |||
40 | |||
41 | /* Constants definition */ | ||
42 | #define HEXADECIMAL_RADIX 16 | ||
43 | |||
44 | /* Functions definition */ | ||
45 | |||
46 | |||
47 | #define DEBUGFS_ADD(name, parent) do { \ | ||
48 | dbgfs->dbgfs_##parent##_files.file_##name = \ | ||
49 | debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \ | ||
50 | &iwmct_dbgfs_##name##_ops); \ | ||
51 | } while (0) | ||
52 | |||
53 | #define DEBUGFS_RM(name) do { \ | ||
54 | debugfs_remove(name); \ | ||
55 | name = NULL; \ | ||
56 | } while (0) | ||
57 | |||
58 | #define DEBUGFS_READ_FUNC(name) \ | ||
59 | ssize_t iwmct_dbgfs_##name##_read(struct file *file, \ | ||
60 | char __user *user_buf, \ | ||
61 | size_t count, loff_t *ppos); | ||
62 | |||
63 | #define DEBUGFS_WRITE_FUNC(name) \ | ||
64 | ssize_t iwmct_dbgfs_##name##_write(struct file *file, \ | ||
65 | const char __user *user_buf, \ | ||
66 | size_t count, loff_t *ppos); | ||
67 | |||
68 | #define DEBUGFS_READ_FILE_OPS(name) \ | ||
69 | DEBUGFS_READ_FUNC(name) \ | ||
70 | static const struct file_operations iwmct_dbgfs_##name##_ops = { \ | ||
71 | .read = iwmct_dbgfs_##name##_read, \ | ||
72 | .open = iwmct_dbgfs_open_file_generic, \ | ||
73 | }; | ||
74 | |||
75 | #define DEBUGFS_WRITE_FILE_OPS(name) \ | ||
76 | DEBUGFS_WRITE_FUNC(name) \ | ||
77 | static const struct file_operations iwmct_dbgfs_##name##_ops = { \ | ||
78 | .write = iwmct_dbgfs_##name##_write, \ | ||
79 | .open = iwmct_dbgfs_open_file_generic, \ | ||
80 | }; | ||
81 | |||
82 | #define DEBUGFS_READ_WRITE_FILE_OPS(name) \ | ||
83 | DEBUGFS_READ_FUNC(name) \ | ||
84 | DEBUGFS_WRITE_FUNC(name) \ | ||
85 | static const struct file_operations iwmct_dbgfs_##name##_ops = {\ | ||
86 | .write = iwmct_dbgfs_##name##_write, \ | ||
87 | .read = iwmct_dbgfs_##name##_read, \ | ||
88 | .open = iwmct_dbgfs_open_file_generic, \ | ||
89 | }; | ||
90 | |||
91 | |||
92 | /* Debugfs file ops definitions */ | ||
93 | |||
94 | /* | ||
95 | * Create the debugfs files and directories | ||
96 | * | ||
97 | */ | ||
98 | void iwmct_dbgfs_register(struct iwmct_priv *priv, const char *name) | ||
99 | { | ||
100 | struct iwmct_debugfs *dbgfs; | ||
101 | |||
102 | dbgfs = kzalloc(sizeof(struct iwmct_debugfs), GFP_KERNEL); | ||
103 | if (!dbgfs) { | ||
104 | LOG_ERROR(priv, DEBUGFS, "failed to allocate %zd bytes\n", | ||
105 | sizeof(struct iwmct_debugfs)); | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | priv->dbgfs = dbgfs; | ||
110 | dbgfs->name = name; | ||
111 | dbgfs->dir_drv = debugfs_create_dir(name, NULL); | ||
112 | if (!dbgfs->dir_drv) { | ||
113 | LOG_ERROR(priv, DEBUGFS, "failed to create debugfs dir\n"); | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | return; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * Remove the debugfs files and directories | ||
122 | * | ||
123 | */ | ||
124 | void iwmct_dbgfs_unregister(struct iwmct_debugfs *dbgfs) | ||
125 | { | ||
126 | if (!dbgfs) | ||
127 | return; | ||
128 | |||
129 | DEBUGFS_RM(dbgfs->dir_drv); | ||
130 | kfree(dbgfs); | ||
131 | dbgfs = NULL; | ||
132 | } | ||
133 | |||