Blame view

drivers/bluetooth/btmrvl_debugfs.c 5.45 KB
fb784f050   Bing Zhao   Bluetooth: Add de...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  /**
   * Marvell Bluetooth driver: debugfs related functions
   *
   * Copyright (C) 2009, Marvell International Ltd.
   *
   * This software file (the "File") is distributed by Marvell International
   * Ltd. under the terms of the GNU General Public License Version 2, June 1991
   * (the "License").  You may use, redistribute and/or modify this File in
   * accordance with the terms and conditions of the License, a copy of which
   * is available by writing to the Free Software Foundation, Inc.,
   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
   * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
   *
   *
   * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
   * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
   * this warranty disclaimer.
   **/
  
  #include <linux/debugfs.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
22
  #include <linux/slab.h>
fb784f050   Bing Zhao   Bluetooth: Add de...
23
24
25
26
27
28
29
  
  #include <net/bluetooth/bluetooth.h>
  #include <net/bluetooth/hci_core.h>
  
  #include "btmrvl_drv.h"
  
  struct btmrvl_debugfs_data {
b914a250e   Marcel Holtmann   Bluetooth: Conver...
30
31
  	struct dentry *config_dir;
  	struct dentry *status_dir;
fb784f050   Bing Zhao   Bluetooth: Add de...
32
  };
fb784f050   Bing Zhao   Bluetooth: Add de...
33
  static ssize_t btmrvl_hscfgcmd_write(struct file *file,
542399037   Marcel Holtmann   Bluetooth: Remove...
34
  			const char __user *ubuf, size_t count, loff_t *ppos)
fb784f050   Bing Zhao   Bluetooth: Add de...
35
  {
542399037   Marcel Holtmann   Bluetooth: Remove...
36
  	struct btmrvl_private *priv = file->private_data;
542399037   Marcel Holtmann   Bluetooth: Remove...
37
  	long result, ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
38

c2e7f5dee   Andy Shevchenko   Bluetooth: btmrvl...
39
  	ret = kstrtol_from_user(ubuf, count, 10, &result);
26e7acf31   David Miller   Bluetooth: Do not...
40
41
  	if (ret)
  		return ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
42
43
44
45
46
47
48
49
50
51
  
  	priv->btmrvl_dev.hscfgcmd = result;
  
  	if (priv->btmrvl_dev.hscfgcmd) {
  		btmrvl_prepare_command(priv);
  		wake_up_interruptible(&priv->main_thread.wait_q);
  	}
  
  	return count;
  }
542399037   Marcel Holtmann   Bluetooth: Remove...
52
53
  static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
  						size_t count, loff_t *ppos)
fb784f050   Bing Zhao   Bluetooth: Add de...
54
  {
542399037   Marcel Holtmann   Bluetooth: Remove...
55
  	struct btmrvl_private *priv = file->private_data;
fb784f050   Bing Zhao   Bluetooth: Add de...
56
  	char buf[16];
542399037   Marcel Holtmann   Bluetooth: Remove...
57
  	int ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
58
59
60
  
  	ret = snprintf(buf, sizeof(buf) - 1, "%d
  ",
542399037   Marcel Holtmann   Bluetooth: Remove...
61
  						priv->btmrvl_dev.hscfgcmd);
fb784f050   Bing Zhao   Bluetooth: Add de...
62
63
64
65
66
  
  	return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  }
  
  static const struct file_operations btmrvl_hscfgcmd_fops = {
542399037   Marcel Holtmann   Bluetooth: Remove...
67
68
  	.read	= btmrvl_hscfgcmd_read,
  	.write	= btmrvl_hscfgcmd_write,
234e34058   Stephen Boyd   simple_open: auto...
69
  	.open	= simple_open,
6038f373a   Arnd Bergmann   llseek: automatic...
70
  	.llseek = default_llseek,
fb784f050   Bing Zhao   Bluetooth: Add de...
71
  };
fb784f050   Bing Zhao   Bluetooth: Add de...
72
  static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
542399037   Marcel Holtmann   Bluetooth: Remove...
73
  						size_t count, loff_t *ppos)
fb784f050   Bing Zhao   Bluetooth: Add de...
74
  {
542399037   Marcel Holtmann   Bluetooth: Remove...
75
  	struct btmrvl_private *priv = file->private_data;
542399037   Marcel Holtmann   Bluetooth: Remove...
76
  	long result, ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
77

c2e7f5dee   Andy Shevchenko   Bluetooth: btmrvl...
78
  	ret = kstrtol_from_user(ubuf, count, 10, &result);
26e7acf31   David Miller   Bluetooth: Do not...
79
80
  	if (ret)
  		return ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
81
82
83
84
85
86
87
88
89
90
91
  
  	priv->btmrvl_dev.pscmd = result;
  
  	if (priv->btmrvl_dev.pscmd) {
  		btmrvl_prepare_command(priv);
  		wake_up_interruptible(&priv->main_thread.wait_q);
  	}
  
  	return count;
  
  }
542399037   Marcel Holtmann   Bluetooth: Remove...
92
93
  static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
  						size_t count, loff_t *ppos)
fb784f050   Bing Zhao   Bluetooth: Add de...
94
  {
542399037   Marcel Holtmann   Bluetooth: Remove...
95
  	struct btmrvl_private *priv = file->private_data;
fb784f050   Bing Zhao   Bluetooth: Add de...
96
  	char buf[16];
542399037   Marcel Holtmann   Bluetooth: Remove...
97
  	int ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
98
99
100
101
102
103
104
105
106
107
  
  	ret = snprintf(buf, sizeof(buf) - 1, "%d
  ", priv->btmrvl_dev.pscmd);
  
  	return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  }
  
  static const struct file_operations btmrvl_pscmd_fops = {
  	.read = btmrvl_pscmd_read,
  	.write = btmrvl_pscmd_write,
234e34058   Stephen Boyd   simple_open: auto...
108
  	.open = simple_open,
6038f373a   Arnd Bergmann   llseek: automatic...
109
  	.llseek = default_llseek,
fb784f050   Bing Zhao   Bluetooth: Add de...
110
  };
fb784f050   Bing Zhao   Bluetooth: Add de...
111
  static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
542399037   Marcel Holtmann   Bluetooth: Remove...
112
  						size_t count, loff_t *ppos)
fb784f050   Bing Zhao   Bluetooth: Add de...
113
  {
be60b9403   Joe Perches   Bluetooth: Remove...
114
  	struct btmrvl_private *priv = file->private_data;
542399037   Marcel Holtmann   Bluetooth: Remove...
115
  	long result, ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
116

c2e7f5dee   Andy Shevchenko   Bluetooth: btmrvl...
117
  	ret = kstrtol_from_user(ubuf, count, 10, &result);
26e7acf31   David Miller   Bluetooth: Do not...
118
119
  	if (ret)
  		return ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
120
121
122
123
124
125
126
127
128
  
  	priv->btmrvl_dev.hscmd = result;
  	if (priv->btmrvl_dev.hscmd) {
  		btmrvl_prepare_command(priv);
  		wake_up_interruptible(&priv->main_thread.wait_q);
  	}
  
  	return count;
  }
542399037   Marcel Holtmann   Bluetooth: Remove...
129
130
  static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
  						size_t count, loff_t *ppos)
fb784f050   Bing Zhao   Bluetooth: Add de...
131
  {
542399037   Marcel Holtmann   Bluetooth: Remove...
132
  	struct btmrvl_private *priv = file->private_data;
fb784f050   Bing Zhao   Bluetooth: Add de...
133
  	char buf[16];
542399037   Marcel Holtmann   Bluetooth: Remove...
134
  	int ret;
fb784f050   Bing Zhao   Bluetooth: Add de...
135
136
137
138
139
140
141
142
  
  	ret = snprintf(buf, sizeof(buf) - 1, "%d
  ", priv->btmrvl_dev.hscmd);
  
  	return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  }
  
  static const struct file_operations btmrvl_hscmd_fops = {
542399037   Marcel Holtmann   Bluetooth: Remove...
143
144
  	.read	= btmrvl_hscmd_read,
  	.write	= btmrvl_hscmd_write,
234e34058   Stephen Boyd   simple_open: auto...
145
  	.open	= simple_open,
6038f373a   Arnd Bergmann   llseek: automatic...
146
  	.llseek = default_llseek,
fb784f050   Bing Zhao   Bluetooth: Add de...
147
  };
fb784f050   Bing Zhao   Bluetooth: Add de...
148
149
  void btmrvl_debugfs_init(struct hci_dev *hdev)
  {
155961e80   David Herrmann   Bluetooth: Remove...
150
  	struct btmrvl_private *priv = hci_get_drvdata(hdev);
fb784f050   Bing Zhao   Bluetooth: Add de...
151
  	struct btmrvl_debugfs_data *dbg;
b914a250e   Marcel Holtmann   Bluetooth: Conver...
152
153
  	if (!hdev->debugfs)
  		return;
fb784f050   Bing Zhao   Bluetooth: Add de...
154
155
156
157
158
159
160
  	dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
  	priv->debugfs_data = dbg;
  
  	if (!dbg) {
  		BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
  		return;
  	}
b914a250e   Marcel Holtmann   Bluetooth: Conver...
161
  	dbg->config_dir = debugfs_create_dir("config", hdev->debugfs);
fb784f050   Bing Zhao   Bluetooth: Add de...
162

9da226c79   Andy Shevchenko   Bluetooth: btmrvl...
163
164
165
166
167
168
169
170
171
172
173
174
  	debugfs_create_u8("psmode", 0644, dbg->config_dir,
  			  &priv->btmrvl_dev.psmode);
  	debugfs_create_file("pscmd", 0644, dbg->config_dir,
  			    priv, &btmrvl_pscmd_fops);
  	debugfs_create_x16("gpiogap", 0644, dbg->config_dir,
  			   &priv->btmrvl_dev.gpio_gap);
  	debugfs_create_u8("hsmode", 0644, dbg->config_dir,
  			  &priv->btmrvl_dev.hsmode);
  	debugfs_create_file("hscmd", 0644, dbg->config_dir,
  			    priv, &btmrvl_hscmd_fops);
  	debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
  			    priv, &btmrvl_hscfgcmd_fops);
fb784f050   Bing Zhao   Bluetooth: Add de...
175

b914a250e   Marcel Holtmann   Bluetooth: Conver...
176
  	dbg->status_dir = debugfs_create_dir("status", hdev->debugfs);
9da226c79   Andy Shevchenko   Bluetooth: btmrvl...
177
178
179
180
181
182
183
184
  	debugfs_create_u8("curpsmode", 0444, dbg->status_dir,
  			  &priv->adapter->psmode);
  	debugfs_create_u8("psstate", 0444, dbg->status_dir,
  			  &priv->adapter->ps_state);
  	debugfs_create_u8("hsstate", 0444, dbg->status_dir,
  			  &priv->adapter->hs_state);
  	debugfs_create_u8("txdnldready", 0444, dbg->status_dir,
  			  &priv->btmrvl_dev.tx_dnld_rdy);
fb784f050   Bing Zhao   Bluetooth: Add de...
185
186
187
188
  }
  
  void btmrvl_debugfs_remove(struct hci_dev *hdev)
  {
155961e80   David Herrmann   Bluetooth: Remove...
189
  	struct btmrvl_private *priv = hci_get_drvdata(hdev);
fb784f050   Bing Zhao   Bluetooth: Add de...
190
191
192
193
  	struct btmrvl_debugfs_data *dbg = priv->debugfs_data;
  
  	if (!dbg)
  		return;
9da226c79   Andy Shevchenko   Bluetooth: btmrvl...
194
195
  	debugfs_remove_recursive(dbg->config_dir);
  	debugfs_remove_recursive(dbg->status_dir);
fb784f050   Bing Zhao   Bluetooth: Add de...
196

fb784f050   Bing Zhao   Bluetooth: Add de...
197
198
  	kfree(dbg);
  }