Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 1 | /** |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 23 | |
| 24 | #include <net/bluetooth/bluetooth.h> |
| 25 | #include <net/bluetooth/hci_core.h> |
| 26 | |
| 27 | #include "btmrvl_drv.h" |
| 28 | |
| 29 | struct btmrvl_debugfs_data { |
Marcel Holtmann | b914a25 | 2010-02-08 16:47:04 +0100 | [diff] [blame] | 30 | struct dentry *config_dir; |
| 31 | struct dentry *status_dir; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 32 | |
| 33 | /* config */ |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 34 | struct dentry *psmode; |
| 35 | struct dentry *pscmd; |
| 36 | struct dentry *hsmode; |
| 37 | struct dentry *hscmd; |
| 38 | struct dentry *gpiogap; |
| 39 | struct dentry *hscfgcmd; |
| 40 | |
| 41 | /* status */ |
| 42 | struct dentry *curpsmode; |
| 43 | struct dentry *hsstate; |
| 44 | struct dentry *psstate; |
| 45 | struct dentry *txdnldready; |
| 46 | }; |
| 47 | |
| 48 | static int btmrvl_open_generic(struct inode *inode, struct file *file) |
| 49 | { |
| 50 | file->private_data = inode->i_private; |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static ssize_t btmrvl_hscfgcmd_write(struct file *file, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 55 | const char __user *ubuf, size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 56 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 57 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 58 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 59 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 60 | |
| 61 | memset(buf, 0, sizeof(buf)); |
| 62 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 63 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 64 | return -EFAULT; |
| 65 | |
| 66 | ret = strict_strtol(buf, 10, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 67 | if (ret) |
| 68 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 69 | |
| 70 | priv->btmrvl_dev.hscfgcmd = result; |
| 71 | |
| 72 | if (priv->btmrvl_dev.hscfgcmd) { |
| 73 | btmrvl_prepare_command(priv); |
| 74 | wake_up_interruptible(&priv->main_thread.wait_q); |
| 75 | } |
| 76 | |
| 77 | return count; |
| 78 | } |
| 79 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 80 | static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf, |
| 81 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 82 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 83 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 84 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 85 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 86 | |
| 87 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 88 | priv->btmrvl_dev.hscfgcmd); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 89 | |
| 90 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 91 | } |
| 92 | |
| 93 | static const struct file_operations btmrvl_hscfgcmd_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 94 | .read = btmrvl_hscfgcmd_read, |
| 95 | .write = btmrvl_hscfgcmd_write, |
| 96 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 97 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | static ssize_t btmrvl_psmode_write(struct file *file, const char __user *ubuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 101 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 102 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 103 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 104 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 105 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 106 | |
| 107 | memset(buf, 0, sizeof(buf)); |
| 108 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 109 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 110 | return -EFAULT; |
| 111 | |
| 112 | ret = strict_strtol(buf, 10, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 113 | if (ret) |
| 114 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 115 | |
| 116 | priv->btmrvl_dev.psmode = result; |
| 117 | |
| 118 | return count; |
| 119 | } |
| 120 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 121 | static ssize_t btmrvl_psmode_read(struct file *file, char __user *userbuf, |
| 122 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 123 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 124 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 125 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 126 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 127 | |
| 128 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 129 | priv->btmrvl_dev.psmode); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 130 | |
| 131 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 132 | } |
| 133 | |
| 134 | static const struct file_operations btmrvl_psmode_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 135 | .read = btmrvl_psmode_read, |
| 136 | .write = btmrvl_psmode_write, |
| 137 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 138 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 142 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 143 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 144 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 145 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 146 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 147 | |
| 148 | memset(buf, 0, sizeof(buf)); |
| 149 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 150 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 151 | return -EFAULT; |
| 152 | |
| 153 | ret = strict_strtol(buf, 10, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 154 | if (ret) |
| 155 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 156 | |
| 157 | priv->btmrvl_dev.pscmd = result; |
| 158 | |
| 159 | if (priv->btmrvl_dev.pscmd) { |
| 160 | btmrvl_prepare_command(priv); |
| 161 | wake_up_interruptible(&priv->main_thread.wait_q); |
| 162 | } |
| 163 | |
| 164 | return count; |
| 165 | |
| 166 | } |
| 167 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 168 | static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf, |
| 169 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 170 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 171 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 172 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 173 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 174 | |
| 175 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd); |
| 176 | |
| 177 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 178 | } |
| 179 | |
| 180 | static const struct file_operations btmrvl_pscmd_fops = { |
| 181 | .read = btmrvl_pscmd_read, |
| 182 | .write = btmrvl_pscmd_write, |
| 183 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 184 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | static ssize_t btmrvl_gpiogap_write(struct file *file, const char __user *ubuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 188 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 189 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 190 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 191 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 192 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 193 | |
| 194 | memset(buf, 0, sizeof(buf)); |
| 195 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 196 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 197 | return -EFAULT; |
| 198 | |
| 199 | ret = strict_strtol(buf, 16, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 200 | if (ret) |
| 201 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 202 | |
| 203 | priv->btmrvl_dev.gpio_gap = result; |
| 204 | |
| 205 | return count; |
| 206 | } |
| 207 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 208 | static ssize_t btmrvl_gpiogap_read(struct file *file, char __user *userbuf, |
| 209 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 210 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 211 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 212 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 213 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 214 | |
| 215 | ret = snprintf(buf, sizeof(buf) - 1, "0x%x\n", |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 216 | priv->btmrvl_dev.gpio_gap); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 217 | |
| 218 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 219 | } |
| 220 | |
| 221 | static const struct file_operations btmrvl_gpiogap_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 222 | .read = btmrvl_gpiogap_read, |
| 223 | .write = btmrvl_gpiogap_write, |
| 224 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 225 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 229 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 230 | { |
Joe Perches | be60b94 | 2010-07-12 13:49:57 -0700 | [diff] [blame] | 231 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 232 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 233 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 234 | |
| 235 | memset(buf, 0, sizeof(buf)); |
| 236 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 237 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 238 | return -EFAULT; |
| 239 | |
| 240 | ret = strict_strtol(buf, 10, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 241 | if (ret) |
| 242 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 243 | |
| 244 | priv->btmrvl_dev.hscmd = result; |
| 245 | if (priv->btmrvl_dev.hscmd) { |
| 246 | btmrvl_prepare_command(priv); |
| 247 | wake_up_interruptible(&priv->main_thread.wait_q); |
| 248 | } |
| 249 | |
| 250 | return count; |
| 251 | } |
| 252 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 253 | static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf, |
| 254 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 255 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 256 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 257 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 258 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 259 | |
| 260 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd); |
| 261 | |
| 262 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 263 | } |
| 264 | |
| 265 | static const struct file_operations btmrvl_hscmd_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 266 | .read = btmrvl_hscmd_read, |
| 267 | .write = btmrvl_hscmd_write, |
| 268 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 269 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | static ssize_t btmrvl_hsmode_write(struct file *file, const char __user *ubuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 273 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 274 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 275 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 276 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 277 | long result, ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 278 | |
| 279 | memset(buf, 0, sizeof(buf)); |
| 280 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 281 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 282 | return -EFAULT; |
| 283 | |
| 284 | ret = strict_strtol(buf, 10, &result); |
David Miller | 26e7acf | 2011-05-19 17:37:45 -0400 | [diff] [blame] | 285 | if (ret) |
| 286 | return ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 287 | |
| 288 | priv->btmrvl_dev.hsmode = result; |
| 289 | |
| 290 | return count; |
| 291 | } |
| 292 | |
| 293 | static ssize_t btmrvl_hsmode_read(struct file *file, char __user * userbuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 294 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 295 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 296 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 297 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 298 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 299 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 300 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hsmode); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 301 | |
| 302 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 303 | } |
| 304 | |
| 305 | static const struct file_operations btmrvl_hsmode_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 306 | .read = btmrvl_hsmode_read, |
| 307 | .write = btmrvl_hsmode_write, |
| 308 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 309 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 310 | }; |
| 311 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 312 | static ssize_t btmrvl_curpsmode_read(struct file *file, char __user *userbuf, |
| 313 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 314 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 315 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 316 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 317 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 318 | |
| 319 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->psmode); |
| 320 | |
| 321 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 322 | } |
| 323 | |
| 324 | static const struct file_operations btmrvl_curpsmode_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 325 | .read = btmrvl_curpsmode_read, |
| 326 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 327 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | static ssize_t btmrvl_psstate_read(struct file *file, char __user * userbuf, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 331 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 332 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 333 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 334 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 335 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 336 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 337 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->ps_state); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 338 | |
| 339 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 340 | } |
| 341 | |
| 342 | static const struct file_operations btmrvl_psstate_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 343 | .read = btmrvl_psstate_read, |
| 344 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 345 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 346 | }; |
| 347 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 348 | static ssize_t btmrvl_hsstate_read(struct file *file, char __user *userbuf, |
| 349 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 350 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 351 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 352 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 353 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 354 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 355 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->hs_state); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 356 | |
| 357 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 358 | } |
| 359 | |
| 360 | static const struct file_operations btmrvl_hsstate_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 361 | .read = btmrvl_hsstate_read, |
| 362 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 363 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 364 | }; |
| 365 | |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 366 | static ssize_t btmrvl_txdnldready_read(struct file *file, char __user *userbuf, |
| 367 | size_t count, loff_t *ppos) |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 368 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 369 | struct btmrvl_private *priv = file->private_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 370 | char buf[16]; |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 371 | int ret; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 372 | |
| 373 | ret = snprintf(buf, sizeof(buf) - 1, "%d\n", |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 374 | priv->btmrvl_dev.tx_dnld_rdy); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 375 | |
| 376 | return simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 377 | } |
| 378 | |
| 379 | static const struct file_operations btmrvl_txdnldready_fops = { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 380 | .read = btmrvl_txdnldready_read, |
| 381 | .open = btmrvl_open_generic, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 382 | .llseek = default_llseek, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | void btmrvl_debugfs_init(struct hci_dev *hdev) |
| 386 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 387 | struct btmrvl_private *priv = hdev->driver_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 388 | struct btmrvl_debugfs_data *dbg; |
| 389 | |
Marcel Holtmann | b914a25 | 2010-02-08 16:47:04 +0100 | [diff] [blame] | 390 | if (!hdev->debugfs) |
| 391 | return; |
| 392 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 393 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 394 | priv->debugfs_data = dbg; |
| 395 | |
| 396 | if (!dbg) { |
| 397 | BT_ERR("Can not allocate memory for btmrvl_debugfs_data."); |
| 398 | return; |
| 399 | } |
| 400 | |
Marcel Holtmann | b914a25 | 2010-02-08 16:47:04 +0100 | [diff] [blame] | 401 | dbg->config_dir = debugfs_create_dir("config", hdev->debugfs); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 402 | |
| 403 | dbg->psmode = debugfs_create_file("psmode", 0644, dbg->config_dir, |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 404 | hdev->driver_data, &btmrvl_psmode_fops); |
| 405 | dbg->pscmd = debugfs_create_file("pscmd", 0644, dbg->config_dir, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 406 | hdev->driver_data, &btmrvl_pscmd_fops); |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 407 | dbg->gpiogap = debugfs_create_file("gpiogap", 0644, dbg->config_dir, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 408 | hdev->driver_data, &btmrvl_gpiogap_fops); |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 409 | dbg->hsmode = debugfs_create_file("hsmode", 0644, dbg->config_dir, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 410 | hdev->driver_data, &btmrvl_hsmode_fops); |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 411 | dbg->hscmd = debugfs_create_file("hscmd", 0644, dbg->config_dir, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 412 | hdev->driver_data, &btmrvl_hscmd_fops); |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 413 | dbg->hscfgcmd = debugfs_create_file("hscfgcmd", 0644, dbg->config_dir, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 414 | hdev->driver_data, &btmrvl_hscfgcmd_fops); |
| 415 | |
Marcel Holtmann | b914a25 | 2010-02-08 16:47:04 +0100 | [diff] [blame] | 416 | dbg->status_dir = debugfs_create_dir("status", hdev->debugfs); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 417 | dbg->curpsmode = debugfs_create_file("curpsmode", 0444, |
| 418 | dbg->status_dir, |
| 419 | hdev->driver_data, |
| 420 | &btmrvl_curpsmode_fops); |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 421 | dbg->psstate = debugfs_create_file("psstate", 0444, dbg->status_dir, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 422 | hdev->driver_data, &btmrvl_psstate_fops); |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 423 | dbg->hsstate = debugfs_create_file("hsstate", 0444, dbg->status_dir, |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 424 | hdev->driver_data, &btmrvl_hsstate_fops); |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 425 | dbg->txdnldready = debugfs_create_file("txdnldready", 0444, |
| 426 | dbg->status_dir, |
| 427 | hdev->driver_data, |
| 428 | &btmrvl_txdnldready_fops); |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | void btmrvl_debugfs_remove(struct hci_dev *hdev) |
| 432 | { |
Marcel Holtmann | 5423990 | 2009-06-09 15:48:35 +0200 | [diff] [blame] | 433 | struct btmrvl_private *priv = hdev->driver_data; |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 434 | struct btmrvl_debugfs_data *dbg = priv->debugfs_data; |
| 435 | |
| 436 | if (!dbg) |
| 437 | return; |
| 438 | |
| 439 | debugfs_remove(dbg->psmode); |
| 440 | debugfs_remove(dbg->pscmd); |
| 441 | debugfs_remove(dbg->gpiogap); |
| 442 | debugfs_remove(dbg->hsmode); |
| 443 | debugfs_remove(dbg->hscmd); |
| 444 | debugfs_remove(dbg->hscfgcmd); |
| 445 | debugfs_remove(dbg->config_dir); |
| 446 | |
| 447 | debugfs_remove(dbg->curpsmode); |
| 448 | debugfs_remove(dbg->psstate); |
| 449 | debugfs_remove(dbg->hsstate); |
| 450 | debugfs_remove(dbg->txdnldready); |
| 451 | debugfs_remove(dbg->status_dir); |
| 452 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 453 | kfree(dbg); |
| 454 | } |