KVM: PPC: Book3S HV: Don't use compound_order to determine host mapping size
[linux-2.6-microblaze.git] / drivers / staging / wilc1000 / wilc_debugfs.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
4  * All rights reserved.
5  */
6
7 #if defined(WILC_DEBUGFS)
8 #include <linux/module.h>
9 #include <linux/debugfs.h>
10
11 #include "wilc_wlan_if.h"
12
13 static struct dentry *wilc_dir;
14
15 #define DEBUG           BIT(0)
16 #define INFO            BIT(1)
17 #define WRN             BIT(2)
18 #define ERR             BIT(3)
19
20 #define DBG_LEVEL_ALL   (DEBUG | INFO | WRN | ERR)
21 static atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
22
23 static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf,
24                                      size_t count, loff_t *ppos)
25 {
26         char buf[128];
27         int res = 0;
28
29         /* only allow read from start */
30         if (*ppos > 0)
31                 return 0;
32
33         res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n",
34                         atomic_read(&WILC_DEBUG_LEVEL));
35
36         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
37 }
38
39 static ssize_t wilc_debug_level_write(struct file *filp,
40                                       const char __user *buf, size_t count,
41                                       loff_t *ppos)
42 {
43         int flag = 0;
44         int ret;
45
46         ret = kstrtouint_from_user(buf, count, 16, &flag);
47         if (ret)
48                 return ret;
49
50         if (flag > DBG_LEVEL_ALL) {
51                 pr_info("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n",
52                         __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
53                 return -EINVAL;
54         }
55
56         atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
57
58         if (flag == 0)
59                 pr_info("Debug-level disabled\n");
60         else
61                 pr_info("Debug-level enabled\n");
62
63         return count;
64 }
65
66 #define FOPS(_open, _read, _write, _poll) { \
67                 .owner  = THIS_MODULE, \
68                 .open   = (_open), \
69                 .read   = (_read), \
70                 .write  = (_write), \
71                 .poll           = (_poll), \
72 }
73
74 struct wilc_debugfs_info_t {
75         const char *name;
76         int perm;
77         unsigned int data;
78         const struct file_operations fops;
79 };
80
81 static struct wilc_debugfs_info_t debugfs_info[] = {
82         {
83                 "wilc_debug_level",
84                 0666,
85                 (DEBUG | ERR),
86                 FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL),
87         },
88 };
89
90 int wilc_debugfs_init(void)
91 {
92         int i;
93         struct wilc_debugfs_info_t *info;
94
95         wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
96         for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
97                 info = &debugfs_info[i];
98                 debugfs_create_file(info->name,
99                                     info->perm,
100                                     wilc_dir,
101                                     &info->data,
102                                     &info->fops);
103         }
104         return 0;
105 }
106
107 void wilc_debugfs_remove(void)
108 {
109         debugfs_remove_recursive(wilc_dir);
110 }
111
112 #endif