2 * NewportMedia WiFi chipset driver test tools - wilc-debug
3 * Copyright (c) 2012 NewportMedia Inc.
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 * --------------------------------------------------------------------------------
31 #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
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");
80 * --------------------------------------------------------------------------------
83 #define FOPS(_open, _read, _write, _poll) { \
84 .owner = THIS_MODULE, \
91 struct wilc_debugfs_info_t {
95 const struct file_operations fops;
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), },
102 static int __init wilc_debugfs_init(void)
106 struct dentry *debugfs_files;
107 struct wilc_debugfs_info_t *info;
109 wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
110 if (wilc_dir == ERR_PTR(-ENODEV)) {
111 /* it's not error. the debugfs is just not being enabled. */
112 printk("ERR, kernel has built without debugfs support\n");
117 printk("ERR, debugfs create dir\n");
121 for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
122 info = &debugfs_info[i];
123 debugfs_files = debugfs_create_file(info->name,
129 if (!debugfs_files) {
130 printk("ERR fail to create the debugfs file, %s\n", info->name);
131 debugfs_remove_recursive(wilc_dir);
137 module_init(wilc_debugfs_init);
139 static void __exit wilc_debugfs_remove(void)
141 debugfs_remove_recursive(wilc_dir);
143 module_exit(wilc_debugfs_remove);