HID: input: avoid polling stylus battery on Chromebook Pompom
[sfrench/cifs-2.6.git] / drivers / staging / vc04_services / interface / vchiq_arm / vchiq_debugfs.c
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
4  * Copyright (c) 2010-2012 Broadcom. All rights reserved.
5  */
6
7 #include <linux/debugfs.h>
8 #include "vchiq_core.h"
9 #include "vchiq_arm.h"
10 #include "vchiq_debugfs.h"
11
12 #ifdef CONFIG_DEBUG_FS
13
14 #define DEBUGFS_WRITE_BUF_SIZE 256
15
16 /* Global 'vchiq' debugfs and clients entry used by all instances */
17 static struct dentry *vchiq_dbg_dir;
18 static struct dentry *vchiq_dbg_clients;
19
20 static int debugfs_usecount_show(struct seq_file *f, void *offset)
21 {
22         struct vchiq_instance *instance = f->private;
23         int use_count;
24
25         use_count = vchiq_instance_get_use_count(instance);
26         seq_printf(f, "%d\n", use_count);
27
28         return 0;
29 }
30 DEFINE_SHOW_ATTRIBUTE(debugfs_usecount);
31
32 static int debugfs_trace_show(struct seq_file *f, void *offset)
33 {
34         struct vchiq_instance *instance = f->private;
35         int trace;
36
37         trace = vchiq_instance_get_trace(instance);
38         seq_printf(f, "%s\n", trace ? "Y" : "N");
39
40         return 0;
41 }
42
43 static int debugfs_trace_open(struct inode *inode, struct file *file)
44 {
45         return single_open(file, debugfs_trace_show, inode->i_private);
46 }
47
48 static ssize_t debugfs_trace_write(struct file *file,
49         const char __user *buffer,
50         size_t count, loff_t *ppos)
51 {
52         struct seq_file *f = (struct seq_file *)file->private_data;
53         struct vchiq_instance *instance = f->private;
54         char firstchar;
55
56         if (copy_from_user(&firstchar, buffer, 1))
57                 return -EFAULT;
58
59         switch (firstchar) {
60         case 'Y':
61         case 'y':
62         case '1':
63                 vchiq_instance_set_trace(instance, 1);
64                 break;
65         case 'N':
66         case 'n':
67         case '0':
68                 vchiq_instance_set_trace(instance, 0);
69                 break;
70         default:
71                 break;
72         }
73
74         *ppos += count;
75
76         return count;
77 }
78
79 static const struct file_operations debugfs_trace_fops = {
80         .owner          = THIS_MODULE,
81         .open           = debugfs_trace_open,
82         .write          = debugfs_trace_write,
83         .read           = seq_read,
84         .llseek         = seq_lseek,
85         .release        = single_release,
86 };
87
88 /* add an instance (process) to the debugfs entries */
89 void vchiq_debugfs_add_instance(struct vchiq_instance *instance)
90 {
91         char pidstr[16];
92         struct dentry *top;
93
94         snprintf(pidstr, sizeof(pidstr), "%d",
95                  vchiq_instance_get_pid(instance));
96
97         top = debugfs_create_dir(pidstr, vchiq_dbg_clients);
98
99         debugfs_create_file("use_count", 0444, top, instance,
100                             &debugfs_usecount_fops);
101         debugfs_create_file("trace", 0644, top, instance, &debugfs_trace_fops);
102
103         vchiq_instance_get_debugfs_node(instance)->dentry = top;
104 }
105
106 void vchiq_debugfs_remove_instance(struct vchiq_instance *instance)
107 {
108         struct vchiq_debugfs_node *node =
109                                 vchiq_instance_get_debugfs_node(instance);
110
111         debugfs_remove_recursive(node->dentry);
112 }
113
114 void vchiq_debugfs_init(void)
115 {
116         vchiq_dbg_dir = debugfs_create_dir("vchiq", NULL);
117         vchiq_dbg_clients = debugfs_create_dir("clients", vchiq_dbg_dir);
118 }
119
120 /* remove all the debugfs entries */
121 void vchiq_debugfs_deinit(void)
122 {
123         debugfs_remove_recursive(vchiq_dbg_dir);
124 }
125
126 #else /* CONFIG_DEBUG_FS */
127
128 void vchiq_debugfs_init(void)
129 {
130 }
131
132 void vchiq_debugfs_deinit(void)
133 {
134 }
135
136 void vchiq_debugfs_add_instance(struct vchiq_instance *instance)
137 {
138 }
139
140 void vchiq_debugfs_remove_instance(struct vchiq_instance *instance)
141 {
142 }
143
144 #endif /* CONFIG_DEBUG_FS */