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