1 // SPDX-License-Identifier: GPL-2.0
3 * NewportMedia WiFi chipset driver test tools - wilc-debug
4 * Copyright (c) 2012 NewportMedia Inc.
5 * Author: SSW <sswd@wilcsemic.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #if defined(WILC_DEBUGFS)
14 #include <linux/module.h>
15 #include <linux/debugfs.h>
16 #include <linux/poll.h>
17 #include <linux/sched.h>
19 #include "wilc_wlan_if.h"
21 static struct dentry *wilc_dir;
24 * ----------------------------------------------------------------------------
31 #define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
32 static atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
33 EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL);
36 * ----------------------------------------------------------------------------
39 static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf,
40 size_t count, loff_t *ppos)
45 /* only allow read from start */
49 res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n",
50 atomic_read(&WILC_DEBUG_LEVEL));
52 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
55 static ssize_t wilc_debug_level_write(struct file *filp,
56 const char __user *buf, size_t count,
62 ret = kstrtouint_from_user(buf, count, 16, &flag);
66 if (flag > DBG_LEVEL_ALL) {
67 pr_info("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n",
68 __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
72 atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
75 pr_info("Debug-level disabled\n");
77 pr_info("Debug-level enabled\n");
83 * ----------------------------------------------------------------------------
86 #define FOPS(_open, _read, _write, _poll) { \
87 .owner = THIS_MODULE, \
94 struct wilc_debugfs_info_t {
98 const struct file_operations fops;
101 static struct wilc_debugfs_info_t debugfs_info[] = {
106 FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL),
110 static int __init wilc_debugfs_init(void)
113 struct wilc_debugfs_info_t *info;
115 wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
116 for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
117 info = &debugfs_info[i];
118 debugfs_create_file(info->name,
126 module_init(wilc_debugfs_init);
128 static void __exit wilc_debugfs_remove(void)
130 debugfs_remove_recursive(wilc_dir);
132 module_exit(wilc_debugfs_remove);