Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jlbec...
[deliverable/linux.git] / drivers / bluetooth / btmrvl_debugfs.c
1 /**
2 * Marvell Bluetooth driver: debugfs related functions
3 *
4 * Copyright (C) 2009, Marvell International Ltd.
5 *
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.
13 *
14 *
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.
19 **/
20
21 #include <linux/debugfs.h>
22
23 #include <net/bluetooth/bluetooth.h>
24 #include <net/bluetooth/hci_core.h>
25
26 #include "btmrvl_drv.h"
27
28 struct btmrvl_debugfs_data {
29 struct dentry *config_dir;
30 struct dentry *status_dir;
31
32 /* config */
33 struct dentry *psmode;
34 struct dentry *pscmd;
35 struct dentry *hsmode;
36 struct dentry *hscmd;
37 struct dentry *gpiogap;
38 struct dentry *hscfgcmd;
39
40 /* status */
41 struct dentry *curpsmode;
42 struct dentry *hsstate;
43 struct dentry *psstate;
44 struct dentry *txdnldready;
45 };
46
47 static int btmrvl_open_generic(struct inode *inode, struct file *file)
48 {
49 file->private_data = inode->i_private;
50 return 0;
51 }
52
53 static ssize_t btmrvl_hscfgcmd_write(struct file *file,
54 const char __user *ubuf, size_t count, loff_t *ppos)
55 {
56 struct btmrvl_private *priv = file->private_data;
57 char buf[16];
58 long result, ret;
59
60 memset(buf, 0, sizeof(buf));
61
62 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
63 return -EFAULT;
64
65 ret = strict_strtol(buf, 10, &result);
66
67 priv->btmrvl_dev.hscfgcmd = result;
68
69 if (priv->btmrvl_dev.hscfgcmd) {
70 btmrvl_prepare_command(priv);
71 wake_up_interruptible(&priv->main_thread.wait_q);
72 }
73
74 return count;
75 }
76
77 static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
78 size_t count, loff_t *ppos)
79 {
80 struct btmrvl_private *priv = file->private_data;
81 char buf[16];
82 int ret;
83
84 ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
85 priv->btmrvl_dev.hscfgcmd);
86
87 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
88 }
89
90 static const struct file_operations btmrvl_hscfgcmd_fops = {
91 .read = btmrvl_hscfgcmd_read,
92 .write = btmrvl_hscfgcmd_write,
93 .open = btmrvl_open_generic,
94 };
95
96 static ssize_t btmrvl_psmode_write(struct file *file, const char __user *ubuf,
97 size_t count, loff_t *ppos)
98 {
99 struct btmrvl_private *priv = file->private_data;
100 char buf[16];
101 long result, ret;
102
103 memset(buf, 0, sizeof(buf));
104
105 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
106 return -EFAULT;
107
108 ret = strict_strtol(buf, 10, &result);
109
110 priv->btmrvl_dev.psmode = result;
111
112 return count;
113 }
114
115 static ssize_t btmrvl_psmode_read(struct file *file, char __user *userbuf,
116 size_t count, loff_t *ppos)
117 {
118 struct btmrvl_private *priv = file->private_data;
119 char buf[16];
120 int ret;
121
122 ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
123 priv->btmrvl_dev.psmode);
124
125 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
126 }
127
128 static const struct file_operations btmrvl_psmode_fops = {
129 .read = btmrvl_psmode_read,
130 .write = btmrvl_psmode_write,
131 .open = btmrvl_open_generic,
132 };
133
134 static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
135 size_t count, loff_t *ppos)
136 {
137 struct btmrvl_private *priv = file->private_data;
138 char buf[16];
139 long result, ret;
140
141 memset(buf, 0, sizeof(buf));
142
143 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
144 return -EFAULT;
145
146 ret = strict_strtol(buf, 10, &result);
147
148 priv->btmrvl_dev.pscmd = result;
149
150 if (priv->btmrvl_dev.pscmd) {
151 btmrvl_prepare_command(priv);
152 wake_up_interruptible(&priv->main_thread.wait_q);
153 }
154
155 return count;
156
157 }
158
159 static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
160 size_t count, loff_t *ppos)
161 {
162 struct btmrvl_private *priv = file->private_data;
163 char buf[16];
164 int ret;
165
166 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);
167
168 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
169 }
170
171 static const struct file_operations btmrvl_pscmd_fops = {
172 .read = btmrvl_pscmd_read,
173 .write = btmrvl_pscmd_write,
174 .open = btmrvl_open_generic,
175 };
176
177 static ssize_t btmrvl_gpiogap_write(struct file *file, const char __user *ubuf,
178 size_t count, loff_t *ppos)
179 {
180 struct btmrvl_private *priv = file->private_data;
181 char buf[16];
182 long result, ret;
183
184 memset(buf, 0, sizeof(buf));
185
186 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
187 return -EFAULT;
188
189 ret = strict_strtol(buf, 16, &result);
190
191 priv->btmrvl_dev.gpio_gap = result;
192
193 return count;
194 }
195
196 static ssize_t btmrvl_gpiogap_read(struct file *file, char __user *userbuf,
197 size_t count, loff_t *ppos)
198 {
199 struct btmrvl_private *priv = file->private_data;
200 char buf[16];
201 int ret;
202
203 ret = snprintf(buf, sizeof(buf) - 1, "0x%x\n",
204 priv->btmrvl_dev.gpio_gap);
205
206 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
207 }
208
209 static const struct file_operations btmrvl_gpiogap_fops = {
210 .read = btmrvl_gpiogap_read,
211 .write = btmrvl_gpiogap_write,
212 .open = btmrvl_open_generic,
213 };
214
215 static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
216 size_t count, loff_t *ppos)
217 {
218 struct btmrvl_private *priv = (struct btmrvl_private *) file->private_data;
219 char buf[16];
220 long result, ret;
221
222 memset(buf, 0, sizeof(buf));
223
224 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
225 return -EFAULT;
226
227 ret = strict_strtol(buf, 10, &result);
228
229 priv->btmrvl_dev.hscmd = result;
230 if (priv->btmrvl_dev.hscmd) {
231 btmrvl_prepare_command(priv);
232 wake_up_interruptible(&priv->main_thread.wait_q);
233 }
234
235 return count;
236 }
237
238 static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
239 size_t count, loff_t *ppos)
240 {
241 struct btmrvl_private *priv = file->private_data;
242 char buf[16];
243 int ret;
244
245 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);
246
247 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
248 }
249
250 static const struct file_operations btmrvl_hscmd_fops = {
251 .read = btmrvl_hscmd_read,
252 .write = btmrvl_hscmd_write,
253 .open = btmrvl_open_generic,
254 };
255
256 static ssize_t btmrvl_hsmode_write(struct file *file, const char __user *ubuf,
257 size_t count, loff_t *ppos)
258 {
259 struct btmrvl_private *priv = file->private_data;
260 char buf[16];
261 long result, ret;
262
263 memset(buf, 0, sizeof(buf));
264
265 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
266 return -EFAULT;
267
268 ret = strict_strtol(buf, 10, &result);
269
270 priv->btmrvl_dev.hsmode = result;
271
272 return count;
273 }
274
275 static ssize_t btmrvl_hsmode_read(struct file *file, char __user * userbuf,
276 size_t count, loff_t *ppos)
277 {
278 struct btmrvl_private *priv = file->private_data;
279 char buf[16];
280 int ret;
281
282 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hsmode);
283
284 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
285 }
286
287 static const struct file_operations btmrvl_hsmode_fops = {
288 .read = btmrvl_hsmode_read,
289 .write = btmrvl_hsmode_write,
290 .open = btmrvl_open_generic,
291 };
292
293 static ssize_t btmrvl_curpsmode_read(struct file *file, char __user *userbuf,
294 size_t count, loff_t *ppos)
295 {
296 struct btmrvl_private *priv = file->private_data;
297 char buf[16];
298 int ret;
299
300 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->psmode);
301
302 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
303 }
304
305 static const struct file_operations btmrvl_curpsmode_fops = {
306 .read = btmrvl_curpsmode_read,
307 .open = btmrvl_open_generic,
308 };
309
310 static ssize_t btmrvl_psstate_read(struct file *file, char __user * userbuf,
311 size_t count, loff_t *ppos)
312 {
313 struct btmrvl_private *priv = file->private_data;
314 char buf[16];
315 int ret;
316
317 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->ps_state);
318
319 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
320 }
321
322 static const struct file_operations btmrvl_psstate_fops = {
323 .read = btmrvl_psstate_read,
324 .open = btmrvl_open_generic,
325 };
326
327 static ssize_t btmrvl_hsstate_read(struct file *file, char __user *userbuf,
328 size_t count, loff_t *ppos)
329 {
330 struct btmrvl_private *priv = file->private_data;
331 char buf[16];
332 int ret;
333
334 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->hs_state);
335
336 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
337 }
338
339 static const struct file_operations btmrvl_hsstate_fops = {
340 .read = btmrvl_hsstate_read,
341 .open = btmrvl_open_generic,
342 };
343
344 static ssize_t btmrvl_txdnldready_read(struct file *file, char __user *userbuf,
345 size_t count, loff_t *ppos)
346 {
347 struct btmrvl_private *priv = file->private_data;
348 char buf[16];
349 int ret;
350
351 ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
352 priv->btmrvl_dev.tx_dnld_rdy);
353
354 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
355 }
356
357 static const struct file_operations btmrvl_txdnldready_fops = {
358 .read = btmrvl_txdnldready_read,
359 .open = btmrvl_open_generic,
360 };
361
362 void btmrvl_debugfs_init(struct hci_dev *hdev)
363 {
364 struct btmrvl_private *priv = hdev->driver_data;
365 struct btmrvl_debugfs_data *dbg;
366
367 if (!hdev->debugfs)
368 return;
369
370 dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
371 priv->debugfs_data = dbg;
372
373 if (!dbg) {
374 BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
375 return;
376 }
377
378 dbg->config_dir = debugfs_create_dir("config", hdev->debugfs);
379
380 dbg->psmode = debugfs_create_file("psmode", 0644, dbg->config_dir,
381 hdev->driver_data, &btmrvl_psmode_fops);
382 dbg->pscmd = debugfs_create_file("pscmd", 0644, dbg->config_dir,
383 hdev->driver_data, &btmrvl_pscmd_fops);
384 dbg->gpiogap = debugfs_create_file("gpiogap", 0644, dbg->config_dir,
385 hdev->driver_data, &btmrvl_gpiogap_fops);
386 dbg->hsmode = debugfs_create_file("hsmode", 0644, dbg->config_dir,
387 hdev->driver_data, &btmrvl_hsmode_fops);
388 dbg->hscmd = debugfs_create_file("hscmd", 0644, dbg->config_dir,
389 hdev->driver_data, &btmrvl_hscmd_fops);
390 dbg->hscfgcmd = debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
391 hdev->driver_data, &btmrvl_hscfgcmd_fops);
392
393 dbg->status_dir = debugfs_create_dir("status", hdev->debugfs);
394 dbg->curpsmode = debugfs_create_file("curpsmode", 0444,
395 dbg->status_dir,
396 hdev->driver_data,
397 &btmrvl_curpsmode_fops);
398 dbg->psstate = debugfs_create_file("psstate", 0444, dbg->status_dir,
399 hdev->driver_data, &btmrvl_psstate_fops);
400 dbg->hsstate = debugfs_create_file("hsstate", 0444, dbg->status_dir,
401 hdev->driver_data, &btmrvl_hsstate_fops);
402 dbg->txdnldready = debugfs_create_file("txdnldready", 0444,
403 dbg->status_dir,
404 hdev->driver_data,
405 &btmrvl_txdnldready_fops);
406 }
407
408 void btmrvl_debugfs_remove(struct hci_dev *hdev)
409 {
410 struct btmrvl_private *priv = hdev->driver_data;
411 struct btmrvl_debugfs_data *dbg = priv->debugfs_data;
412
413 if (!dbg)
414 return;
415
416 debugfs_remove(dbg->psmode);
417 debugfs_remove(dbg->pscmd);
418 debugfs_remove(dbg->gpiogap);
419 debugfs_remove(dbg->hsmode);
420 debugfs_remove(dbg->hscmd);
421 debugfs_remove(dbg->hscfgcmd);
422 debugfs_remove(dbg->config_dir);
423
424 debugfs_remove(dbg->curpsmode);
425 debugfs_remove(dbg->psstate);
426 debugfs_remove(dbg->hsstate);
427 debugfs_remove(dbg->txdnldready);
428 debugfs_remove(dbg->status_dir);
429
430 kfree(dbg);
431 }
This page took 0.057406 seconds and 5 git commands to generate.