Commit | Line | Data |
---|---|---|
c5c77ba1 JK |
1 | /* |
2 | * NewportMedia WiFi chipset driver test tools - wilc-debug | |
3 | * Copyright (c) 2012 NewportMedia Inc. | |
4 | * Author: SSW <sswd@wilcsemic.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | */ | |
11 | ||
12 | #if defined(WILC_DEBUGFS) | |
13 | #include <linux/module.h> | |
14 | #include <linux/debugfs.h> | |
15 | #include <linux/poll.h> | |
16 | #include <linux/sched.h> | |
17 | ||
18 | #include "wilc_wlan_if.h" | |
19 | ||
20 | ||
21 | static struct dentry *wilc_dir; | |
22 | ||
23 | /* | |
24 | * -------------------------------------------------------------------------------- | |
25 | */ | |
b331f159 CP |
26 | #define DEBUG BIT(0) |
27 | #define INFO BIT(1) | |
28 | #define WRN BIT(2) | |
29 | #define ERR BIT(3) | |
c5c77ba1 | 30 | |
c5c77ba1 | 31 | #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR) |
0e1af73d | 32 | atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR); |
750ffe9b | 33 | EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL); |
c5c77ba1 JK |
34 | |
35 | /* | |
36 | * -------------------------------------------------------------------------------- | |
37 | */ | |
38 | ||
39 | ||
40 | static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) | |
41 | { | |
42 | char buf[128]; | |
43 | int res = 0; | |
44 | ||
45 | /* only allow read from start */ | |
46 | if (*ppos > 0) | |
47 | return 0; | |
48 | ||
0e1af73d | 49 | res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n", atomic_read(&WILC_DEBUG_LEVEL)); |
c5c77ba1 JK |
50 | |
51 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | |
52 | } | |
53 | ||
6e3f05bf CG |
54 | static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf, |
55 | size_t count, loff_t *ppos) | |
c5c77ba1 | 56 | { |
c5c77ba1 | 57 | int flag = 0; |
6e3f05bf | 58 | int ret; |
c5c77ba1 | 59 | |
6e3f05bf CG |
60 | ret = kstrtouint_from_user(buf, count, 16, &flag); |
61 | if (ret) | |
62 | return ret; | |
c5c77ba1 JK |
63 | |
64 | if (flag > DBG_LEVEL_ALL) { | |
0e1af73d | 65 | printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&WILC_DEBUG_LEVEL)); |
6e3f05bf | 66 | return -EINVAL; |
c5c77ba1 JK |
67 | } |
68 | ||
0e1af73d | 69 | atomic_set(&WILC_DEBUG_LEVEL, (int)flag); |
c5c77ba1 | 70 | |
78174ada | 71 | if (flag == 0) |
f7b7f87d | 72 | printk(KERN_INFO "Debug-level disabled\n"); |
78174ada | 73 | else |
f7b7f87d | 74 | printk(KERN_INFO "Debug-level enabled\n"); |
6e3f05bf | 75 | |
c5c77ba1 JK |
76 | return count; |
77 | } | |
78 | ||
c5c77ba1 JK |
79 | /* |
80 | * -------------------------------------------------------------------------------- | |
81 | */ | |
82 | ||
83 | #define FOPS(_open, _read, _write, _poll) { \ | |
84 | .owner = THIS_MODULE, \ | |
85 | .open = (_open), \ | |
86 | .read = (_read), \ | |
87 | .write = (_write), \ | |
88 | .poll = (_poll), \ | |
89 | } | |
90 | ||
91 | struct wilc_debugfs_info_t { | |
92 | const char *name; | |
93 | int perm; | |
94 | unsigned int data; | |
8a7b2b18 | 95 | const struct file_operations fops; |
c5c77ba1 JK |
96 | }; |
97 | ||
98 | static struct wilc_debugfs_info_t debugfs_info[] = { | |
99 | { "wilc_debug_level", 0666, (DEBUG | ERR), FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL), }, | |
c5c77ba1 JK |
100 | }; |
101 | ||
c94f05ee | 102 | static int __init wilc_debugfs_init(void) |
c5c77ba1 JK |
103 | { |
104 | int i; | |
c5c77ba1 JK |
105 | struct wilc_debugfs_info_t *info; |
106 | ||
107 | wilc_dir = debugfs_create_dir("wilc_wifi", NULL); | |
c5c77ba1 JK |
108 | for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) { |
109 | info = &debugfs_info[i]; | |
ef6687c6 LB |
110 | debugfs_create_file(info->name, |
111 | info->perm, | |
112 | wilc_dir, | |
113 | &info->data, | |
114 | &info->fops); | |
c5c77ba1 JK |
115 | } |
116 | return 0; | |
117 | } | |
c94f05ee | 118 | module_init(wilc_debugfs_init); |
c5c77ba1 | 119 | |
c94f05ee | 120 | static void __exit wilc_debugfs_remove(void) |
c5c77ba1 JK |
121 | { |
122 | debugfs_remove_recursive(wilc_dir); | |
123 | } | |
c94f05ee | 124 | module_exit(wilc_debugfs_remove); |
c5c77ba1 JK |
125 | |
126 | #endif | |
127 |