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