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"
20 static struct dentry *wilc_dir;
23 * ----------------------------------------------------------------------------
30 #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
31 static atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
32 EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL);
35 * ----------------------------------------------------------------------------
38 static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf,
39 size_t count, loff_t *ppos)
44 /* only allow read from start */
48 res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n",
49 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,
55 const char __user *buf, size_t count,
61 ret = kstrtouint_from_user(buf, count, 16, &flag);
65 if (flag > DBG_LEVEL_ALL) {
66 pr_info("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n",
67 __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
71 atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
74 pr_info("Debug-level disabled\n");
76 pr_info("Debug-level enabled\n");
82 * ----------------------------------------------------------------------------
85 #define FOPS(_open, _read, _write, _poll) { \
86 .owner = THIS_MODULE, \
93 struct wilc_debugfs_info_t {
97 const struct file_operations fops;
100 static struct wilc_debugfs_info_t debugfs_info[] = {
105 FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL),
109 static int __init wilc_debugfs_init(void)
112 struct wilc_debugfs_info_t *info;
114 wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
115 for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
116 info = &debugfs_info[i];
117 debugfs_create_file(info->name,
125 module_init(wilc_debugfs_init);
127 static void __exit wilc_debugfs_remove(void)
129 debugfs_remove_recursive(wilc_dir);
131 module_exit(wilc_debugfs_remove);