2 * NewportMedia WiFi chipset driver test tools - wilc-debug
3 * Copyright (c) 2012 NewportMedia Inc.
4 * Author: SSW <sswd@wilcsemic.com>
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.
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>
18 #include "wilc_wlan_if.h"
21 static struct dentry *wilc_dir;
24 * --------------------------------------------------------------------------------
27 #define DBG_REGION_ALL (HOSTAPD_DBG | CFG80211_DBG | INIT_DBG)
28 #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
29 atomic_t WILC_REGION = ATOMIC_INIT(INIT_DBG | CFG80211_DBG |
31 EXPORT_SYMBOL_GPL(WILC_REGION);
32 atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
33 EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL);
36 * --------------------------------------------------------------------------------
40 static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos)
45 /* only allow read from start */
49 res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n", atomic_read(&WILC_DEBUG_LEVEL));
51 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
54 static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf,
55 size_t count, loff_t *ppos)
60 ret = kstrtouint_from_user(buf, count, 16, &flag);
64 if (flag > DBG_LEVEL_ALL) {
65 printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
69 atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
72 printk(KERN_INFO "Debug-level disabled\n");
74 printk(KERN_INFO "Debug-level enabled\n");
79 static ssize_t wilc_debug_region_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos)
84 /* only allow read from start */
88 res = scnprintf(buf, sizeof(buf), "Debug region: %x\n", atomic_read(&WILC_REGION));
90 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
93 static ssize_t wilc_debug_region_write(struct file *filp, const char __user *buf, size_t count, loff_t *ppos)
95 char buffer[128] = {};
98 if (count > sizeof(buffer))
101 if (copy_from_user(buffer, buf, count))
104 flag = buffer[0] - '0';
106 if (flag > DBG_REGION_ALL) {
107 printk("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n", __func__, flag, atomic_read(&WILC_REGION));
111 atomic_set(&WILC_REGION, (int)flag);
112 printk("new debug-region is %x\n", atomic_read(&WILC_REGION));
118 * --------------------------------------------------------------------------------
121 #define FOPS(_open, _read, _write, _poll) { \
122 .owner = THIS_MODULE, \
129 struct wilc_debugfs_info_t {
133 const struct file_operations fops;
136 static struct wilc_debugfs_info_t debugfs_info[] = {
137 { "wilc_debug_level", 0666, (DEBUG | ERR), FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL), },
138 { "wilc_debug_region", 0666, (INIT_DBG | CFG80211_DBG), FOPS(NULL, wilc_debug_region_read, wilc_debug_region_write, NULL), },
141 static int __init wilc_debugfs_init(void)
145 struct dentry *debugfs_files;
146 struct wilc_debugfs_info_t *info;
148 wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
149 if (wilc_dir == ERR_PTR(-ENODEV)) {
150 /* it's not error. the debugfs is just not being enabled. */
151 printk("ERR, kernel has built without debugfs support\n");
156 printk("ERR, debugfs create dir\n");
160 for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
161 info = &debugfs_info[i];
162 debugfs_files = debugfs_create_file(info->name,
168 if (!debugfs_files) {
169 printk("ERR fail to create the debugfs file, %s\n", info->name);
170 debugfs_remove_recursive(wilc_dir);
176 module_init(wilc_debugfs_init);
178 static void __exit wilc_debugfs_remove(void)
180 debugfs_remove_recursive(wilc_dir);
182 module_exit(wilc_debugfs_remove);