]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/staging/wilc1000/wilc_debugfs.c
staging: board: Migrate away from __pm_genpd_name_add_device()
[mirror_ubuntu-zesty-kernel.git] / drivers / staging / wilc1000 / wilc_debugfs.c
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 */
26
27 #define DBG_REGION_ALL (GENERIC_DBG | HOSTAPD_DBG | HOSTINF_DBG | CORECONFIG_DBG | CFG80211_DBG | INT_DBG | TX_DBG | RX_DBG | LOCK_DBG | INIT_DBG | BUS_DBG | MEM_DBG)
28 #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
29 atomic_t REGION = ATOMIC_INIT(INIT_DBG | GENERIC_DBG | CFG80211_DBG | FIRM_DBG | HOSTAPD_DBG);
30 atomic_t DEBUG_LEVEL = ATOMIC_INIT(ERR);
31
32 /*
33 * --------------------------------------------------------------------------------
34 */
35
36
37 static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos)
38 {
39 char buf[128];
40 int res = 0;
41
42 /* only allow read from start */
43 if (*ppos > 0)
44 return 0;
45
46 res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n", atomic_read(&DEBUG_LEVEL));
47
48 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
49 }
50
51 static ssize_t wilc_debug_level_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
52 {
53 char buffer[128] = {};
54 int flag = 0;
55
56 if (count > sizeof(buffer))
57 return -EINVAL;
58
59 if (copy_from_user(buffer, buf, count)) {
60 return -EFAULT;
61 }
62
63 flag = buffer[0] - '0';
64
65 if (flag > 0) {
66 flag = DEBUG | ERR;
67 } else if (flag < 0) {
68 flag = 100;
69 }
70
71 if (flag > DBG_LEVEL_ALL) {
72 printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&DEBUG_LEVEL));
73 return -EFAULT;
74 }
75
76 atomic_set(&DEBUG_LEVEL, (int)flag);
77
78 if (flag == 0) {
79 printk("Debug-level disabled\n");
80 } else {
81 printk("Debug-level enabled\n");
82 }
83 return count;
84 }
85
86 static ssize_t wilc_debug_region_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos)
87 {
88 char buf[128];
89 int res = 0;
90
91 /* only allow read from start */
92 if (*ppos > 0)
93 return 0;
94
95 res = scnprintf(buf, sizeof(buf), "Debug region: %x\n", atomic_read(&REGION));
96
97 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
98 }
99
100 static ssize_t wilc_debug_region_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
101 {
102 char buffer[128] = {};
103 int flag;
104
105 if (count > sizeof(buffer))
106 return -EINVAL;
107
108 if (copy_from_user(buffer, buf, count)) {
109 return -EFAULT;
110 }
111
112 flag = buffer[0] - '0';
113
114 if (flag > DBG_REGION_ALL) {
115 printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&REGION));
116 return -EFAULT;
117 }
118
119 atomic_set(&REGION, (int)flag);
120 printk("new debug-region is %x\n", atomic_read(&REGION));
121
122 return count;
123 }
124
125 /*
126 * --------------------------------------------------------------------------------
127 */
128
129 #define FOPS(_open, _read, _write, _poll) { \
130 .owner = THIS_MODULE, \
131 .open = (_open), \
132 .read = (_read), \
133 .write = (_write), \
134 .poll = (_poll), \
135 }
136
137 struct wilc_debugfs_info_t {
138 const char *name;
139 int perm;
140 unsigned int data;
141 struct file_operations fops;
142 };
143
144 static struct wilc_debugfs_info_t debugfs_info[] = {
145 { "wilc_debug_level", 0666, (DEBUG | ERR), FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL), },
146 { "wilc_debug_region", 0666, (INIT_DBG | GENERIC_DBG | CFG80211_DBG), FOPS(NULL, wilc_debug_region_read, wilc_debug_region_write, NULL), },
147 };
148
149 int wilc_debugfs_init(void)
150 {
151 int i;
152
153 struct dentry *debugfs_files;
154 struct wilc_debugfs_info_t *info;
155
156 wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
157 if (wilc_dir == ERR_PTR(-ENODEV)) {
158 /* it's not error. the debugfs is just not being enabled. */
159 printk("ERR, kernel has built without debugfs support\n");
160 return 0;
161 }
162
163 if (!wilc_dir) {
164 printk("ERR, debugfs create dir\n");
165 return -1;
166 }
167
168 for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
169 info = &debugfs_info[i];
170 debugfs_files = debugfs_create_file(info->name,
171 info->perm,
172 wilc_dir,
173 &info->data,
174 &info->fops);
175
176 if (!debugfs_files) {
177 printk("ERR fail to create the debugfs file, %s\n", info->name);
178 debugfs_remove_recursive(wilc_dir);
179 return -1;
180 }
181 }
182 return 0;
183 }
184
185 void wilc_debugfs_remove(void)
186 {
187 debugfs_remove_recursive(wilc_dir);
188 }
189
190 #endif
191