blob: 023d35e3c7a75b573a52d99cbda5bd98c64e017f [file] [log] [blame]
Bing Zhaofb784f02009-06-02 14:29:37 -07001/**
2 * Marvell Bluetooth driver: debugfs related functions
3 *
4 * Copyright (C) 2009, Marvell International Ltd.
5 *
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13 *
14 *
15 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
17 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
18 * this warranty disclaimer.
19 **/
20
21#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Bing Zhaofb784f02009-06-02 14:29:37 -070023
24#include <net/bluetooth/bluetooth.h>
25#include <net/bluetooth/hci_core.h>
26
27#include "btmrvl_drv.h"
28
29struct btmrvl_debugfs_data {
Marcel Holtmannb914a252010-02-08 16:47:04 +010030 struct dentry *config_dir;
31 struct dentry *status_dir;
Bing Zhaofb784f02009-06-02 14:29:37 -070032};
33
Bing Zhaofb784f02009-06-02 14:29:37 -070034static ssize_t btmrvl_hscfgcmd_write(struct file *file,
Marcel Holtmann54239902009-06-09 15:48:35 +020035 const char __user *ubuf, size_t count, loff_t *ppos)
Bing Zhaofb784f02009-06-02 14:29:37 -070036{
Marcel Holtmann54239902009-06-09 15:48:35 +020037 struct btmrvl_private *priv = file->private_data;
Bing Zhaofb784f02009-06-02 14:29:37 -070038 char buf[16];
Marcel Holtmann54239902009-06-09 15:48:35 +020039 long result, ret;
Bing Zhaofb784f02009-06-02 14:29:37 -070040
41 memset(buf, 0, sizeof(buf));
42
Marcel Holtmann54239902009-06-09 15:48:35 +020043 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
Bing Zhaofb784f02009-06-02 14:29:37 -070044 return -EFAULT;
45
Jingoo Han473c1312013-07-19 16:09:38 +090046 ret = kstrtol(buf, 10, &result);
David Miller26e7acf2011-05-19 17:37:45 -040047 if (ret)
48 return ret;
Bing Zhaofb784f02009-06-02 14:29:37 -070049
50 priv->btmrvl_dev.hscfgcmd = result;
51
52 if (priv->btmrvl_dev.hscfgcmd) {
53 btmrvl_prepare_command(priv);
54 wake_up_interruptible(&priv->main_thread.wait_q);
55 }
56
57 return count;
58}
59
Marcel Holtmann54239902009-06-09 15:48:35 +020060static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
61 size_t count, loff_t *ppos)
Bing Zhaofb784f02009-06-02 14:29:37 -070062{
Marcel Holtmann54239902009-06-09 15:48:35 +020063 struct btmrvl_private *priv = file->private_data;
Bing Zhaofb784f02009-06-02 14:29:37 -070064 char buf[16];
Marcel Holtmann54239902009-06-09 15:48:35 +020065 int ret;
Bing Zhaofb784f02009-06-02 14:29:37 -070066
67 ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
Marcel Holtmann54239902009-06-09 15:48:35 +020068 priv->btmrvl_dev.hscfgcmd);
Bing Zhaofb784f02009-06-02 14:29:37 -070069
70 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
71}
72
73static const struct file_operations btmrvl_hscfgcmd_fops = {
Marcel Holtmann54239902009-06-09 15:48:35 +020074 .read = btmrvl_hscfgcmd_read,
75 .write = btmrvl_hscfgcmd_write,
Stephen Boyd234e3402012-04-05 14:25:11 -070076 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +020077 .llseek = default_llseek,
Bing Zhaofb784f02009-06-02 14:29:37 -070078};
79
Bing Zhaofb784f02009-06-02 14:29:37 -070080static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
Marcel Holtmann54239902009-06-09 15:48:35 +020081 size_t count, loff_t *ppos)
Bing Zhaofb784f02009-06-02 14:29:37 -070082{
Marcel Holtmann54239902009-06-09 15:48:35 +020083 struct btmrvl_private *priv = file->private_data;
Bing Zhaofb784f02009-06-02 14:29:37 -070084 char buf[16];
Marcel Holtmann54239902009-06-09 15:48:35 +020085 long result, ret;
Bing Zhaofb784f02009-06-02 14:29:37 -070086
87 memset(buf, 0, sizeof(buf));
88
Marcel Holtmann54239902009-06-09 15:48:35 +020089 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
Bing Zhaofb784f02009-06-02 14:29:37 -070090 return -EFAULT;
91
Jingoo Han473c1312013-07-19 16:09:38 +090092 ret = kstrtol(buf, 10, &result);
David Miller26e7acf2011-05-19 17:37:45 -040093 if (ret)
94 return ret;
Bing Zhaofb784f02009-06-02 14:29:37 -070095
96 priv->btmrvl_dev.pscmd = result;
97
98 if (priv->btmrvl_dev.pscmd) {
99 btmrvl_prepare_command(priv);
100 wake_up_interruptible(&priv->main_thread.wait_q);
101 }
102
103 return count;
104
105}
106
Marcel Holtmann54239902009-06-09 15:48:35 +0200107static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
108 size_t count, loff_t *ppos)
Bing Zhaofb784f02009-06-02 14:29:37 -0700109{
Marcel Holtmann54239902009-06-09 15:48:35 +0200110 struct btmrvl_private *priv = file->private_data;
Bing Zhaofb784f02009-06-02 14:29:37 -0700111 char buf[16];
Marcel Holtmann54239902009-06-09 15:48:35 +0200112 int ret;
Bing Zhaofb784f02009-06-02 14:29:37 -0700113
114 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);
115
116 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
117}
118
119static const struct file_operations btmrvl_pscmd_fops = {
120 .read = btmrvl_pscmd_read,
121 .write = btmrvl_pscmd_write,
Stephen Boyd234e3402012-04-05 14:25:11 -0700122 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200123 .llseek = default_llseek,
Bing Zhaofb784f02009-06-02 14:29:37 -0700124};
125
Bing Zhaofb784f02009-06-02 14:29:37 -0700126static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
Marcel Holtmann54239902009-06-09 15:48:35 +0200127 size_t count, loff_t *ppos)
Bing Zhaofb784f02009-06-02 14:29:37 -0700128{
Joe Perchesbe60b942010-07-12 13:49:57 -0700129 struct btmrvl_private *priv = file->private_data;
Bing Zhaofb784f02009-06-02 14:29:37 -0700130 char buf[16];
Marcel Holtmann54239902009-06-09 15:48:35 +0200131 long result, ret;
Bing Zhaofb784f02009-06-02 14:29:37 -0700132
133 memset(buf, 0, sizeof(buf));
134
Marcel Holtmann54239902009-06-09 15:48:35 +0200135 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
Bing Zhaofb784f02009-06-02 14:29:37 -0700136 return -EFAULT;
137
Jingoo Han473c1312013-07-19 16:09:38 +0900138 ret = kstrtol(buf, 10, &result);
David Miller26e7acf2011-05-19 17:37:45 -0400139 if (ret)
140 return ret;
Bing Zhaofb784f02009-06-02 14:29:37 -0700141
142 priv->btmrvl_dev.hscmd = result;
143 if (priv->btmrvl_dev.hscmd) {
144 btmrvl_prepare_command(priv);
145 wake_up_interruptible(&priv->main_thread.wait_q);
146 }
147
148 return count;
149}
150
Marcel Holtmann54239902009-06-09 15:48:35 +0200151static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
152 size_t count, loff_t *ppos)
Bing Zhaofb784f02009-06-02 14:29:37 -0700153{
Marcel Holtmann54239902009-06-09 15:48:35 +0200154 struct btmrvl_private *priv = file->private_data;
Bing Zhaofb784f02009-06-02 14:29:37 -0700155 char buf[16];
Marcel Holtmann54239902009-06-09 15:48:35 +0200156 int ret;
Bing Zhaofb784f02009-06-02 14:29:37 -0700157
158 ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);
159
160 return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
161}
162
163static const struct file_operations btmrvl_hscmd_fops = {
Marcel Holtmann54239902009-06-09 15:48:35 +0200164 .read = btmrvl_hscmd_read,
165 .write = btmrvl_hscmd_write,
Stephen Boyd234e3402012-04-05 14:25:11 -0700166 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200167 .llseek = default_llseek,
Bing Zhaofb784f02009-06-02 14:29:37 -0700168};
169
Bing Zhaofb784f02009-06-02 14:29:37 -0700170void btmrvl_debugfs_init(struct hci_dev *hdev)
171{
David Herrmann155961e2012-02-09 21:58:32 +0100172 struct btmrvl_private *priv = hci_get_drvdata(hdev);
Bing Zhaofb784f02009-06-02 14:29:37 -0700173 struct btmrvl_debugfs_data *dbg;
174
Marcel Holtmannb914a252010-02-08 16:47:04 +0100175 if (!hdev->debugfs)
176 return;
177
Bing Zhaofb784f02009-06-02 14:29:37 -0700178 dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
179 priv->debugfs_data = dbg;
180
181 if (!dbg) {
182 BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
183 return;
184 }
185
Marcel Holtmannb914a252010-02-08 16:47:04 +0100186 dbg->config_dir = debugfs_create_dir("config", hdev->debugfs);
Bing Zhaofb784f02009-06-02 14:29:37 -0700187
Andy Shevchenko9da226c2013-04-23 12:53:46 +0300188 debugfs_create_u8("psmode", 0644, dbg->config_dir,
189 &priv->btmrvl_dev.psmode);
190 debugfs_create_file("pscmd", 0644, dbg->config_dir,
191 priv, &btmrvl_pscmd_fops);
192 debugfs_create_x16("gpiogap", 0644, dbg->config_dir,
193 &priv->btmrvl_dev.gpio_gap);
194 debugfs_create_u8("hsmode", 0644, dbg->config_dir,
195 &priv->btmrvl_dev.hsmode);
196 debugfs_create_file("hscmd", 0644, dbg->config_dir,
197 priv, &btmrvl_hscmd_fops);
198 debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
199 priv, &btmrvl_hscfgcmd_fops);
Bing Zhaofb784f02009-06-02 14:29:37 -0700200
Marcel Holtmannb914a252010-02-08 16:47:04 +0100201 dbg->status_dir = debugfs_create_dir("status", hdev->debugfs);
Andy Shevchenko9da226c2013-04-23 12:53:46 +0300202 debugfs_create_u8("curpsmode", 0444, dbg->status_dir,
203 &priv->adapter->psmode);
204 debugfs_create_u8("psstate", 0444, dbg->status_dir,
205 &priv->adapter->ps_state);
206 debugfs_create_u8("hsstate", 0444, dbg->status_dir,
207 &priv->adapter->hs_state);
208 debugfs_create_u8("txdnldready", 0444, dbg->status_dir,
209 &priv->btmrvl_dev.tx_dnld_rdy);
Bing Zhaofb784f02009-06-02 14:29:37 -0700210}
211
212void btmrvl_debugfs_remove(struct hci_dev *hdev)
213{
David Herrmann155961e2012-02-09 21:58:32 +0100214 struct btmrvl_private *priv = hci_get_drvdata(hdev);
Bing Zhaofb784f02009-06-02 14:29:37 -0700215 struct btmrvl_debugfs_data *dbg = priv->debugfs_data;
216
217 if (!dbg)
218 return;
219
Andy Shevchenko9da226c2013-04-23 12:53:46 +0300220 debugfs_remove_recursive(dbg->config_dir);
221 debugfs_remove_recursive(dbg->status_dir);
Bing Zhaofb784f02009-06-02 14:29:37 -0700222
Bing Zhaofb784f02009-06-02 14:29:37 -0700223 kfree(dbg);
224}