btmrvl_debugfs.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. #include <linux/debugfs.h>
  21. #include <net/bluetooth/bluetooth.h>
  22. #include <net/bluetooth/hci_core.h>
  23. #include "btmrvl_drv.h"
  24. struct btmrvl_debugfs_data {
  25. struct dentry *root_dir, *config_dir, *status_dir;
  26. /* config */
  27. struct dentry *psmode;
  28. struct dentry *pscmd;
  29. struct dentry *hsmode;
  30. struct dentry *hscmd;
  31. struct dentry *gpiogap;
  32. struct dentry *hscfgcmd;
  33. /* status */
  34. struct dentry *curpsmode;
  35. struct dentry *hsstate;
  36. struct dentry *psstate;
  37. struct dentry *txdnldready;
  38. };
  39. static int btmrvl_open_generic(struct inode *inode, struct file *file)
  40. {
  41. file->private_data = inode->i_private;
  42. return 0;
  43. }
  44. static ssize_t btmrvl_hscfgcmd_write(struct file *file,
  45. const char __user *ubuf, size_t count, loff_t *ppos)
  46. {
  47. struct btmrvl_private *priv = file->private_data;
  48. char buf[16];
  49. long result, ret;
  50. memset(buf, 0, sizeof(buf));
  51. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  52. return -EFAULT;
  53. ret = strict_strtol(buf, 10, &result);
  54. priv->btmrvl_dev.hscfgcmd = result;
  55. if (priv->btmrvl_dev.hscfgcmd) {
  56. btmrvl_prepare_command(priv);
  57. wake_up_interruptible(&priv->main_thread.wait_q);
  58. }
  59. return count;
  60. }
  61. static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
  62. size_t count, loff_t *ppos)
  63. {
  64. struct btmrvl_private *priv = file->private_data;
  65. char buf[16];
  66. int ret;
  67. ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
  68. priv->btmrvl_dev.hscfgcmd);
  69. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  70. }
  71. static const struct file_operations btmrvl_hscfgcmd_fops = {
  72. .read = btmrvl_hscfgcmd_read,
  73. .write = btmrvl_hscfgcmd_write,
  74. .open = btmrvl_open_generic,
  75. };
  76. static ssize_t btmrvl_psmode_write(struct file *file, const char __user *ubuf,
  77. size_t count, loff_t *ppos)
  78. {
  79. struct btmrvl_private *priv = file->private_data;
  80. char buf[16];
  81. long result, ret;
  82. memset(buf, 0, sizeof(buf));
  83. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  84. return -EFAULT;
  85. ret = strict_strtol(buf, 10, &result);
  86. priv->btmrvl_dev.psmode = result;
  87. return count;
  88. }
  89. static ssize_t btmrvl_psmode_read(struct file *file, char __user *userbuf,
  90. size_t count, loff_t *ppos)
  91. {
  92. struct btmrvl_private *priv = file->private_data;
  93. char buf[16];
  94. int ret;
  95. ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
  96. priv->btmrvl_dev.psmode);
  97. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  98. }
  99. static const struct file_operations btmrvl_psmode_fops = {
  100. .read = btmrvl_psmode_read,
  101. .write = btmrvl_psmode_write,
  102. .open = btmrvl_open_generic,
  103. };
  104. static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
  105. size_t count, loff_t *ppos)
  106. {
  107. struct btmrvl_private *priv = file->private_data;
  108. char buf[16];
  109. long result, ret;
  110. memset(buf, 0, sizeof(buf));
  111. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  112. return -EFAULT;
  113. ret = strict_strtol(buf, 10, &result);
  114. priv->btmrvl_dev.pscmd = result;
  115. if (priv->btmrvl_dev.pscmd) {
  116. btmrvl_prepare_command(priv);
  117. wake_up_interruptible(&priv->main_thread.wait_q);
  118. }
  119. return count;
  120. }
  121. static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
  122. size_t count, loff_t *ppos)
  123. {
  124. struct btmrvl_private *priv = file->private_data;
  125. char buf[16];
  126. int ret;
  127. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);
  128. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  129. }
  130. static const struct file_operations btmrvl_pscmd_fops = {
  131. .read = btmrvl_pscmd_read,
  132. .write = btmrvl_pscmd_write,
  133. .open = btmrvl_open_generic,
  134. };
  135. static ssize_t btmrvl_gpiogap_write(struct file *file, const char __user *ubuf,
  136. size_t count, loff_t *ppos)
  137. {
  138. struct btmrvl_private *priv = file->private_data;
  139. char buf[16];
  140. long result, ret;
  141. memset(buf, 0, sizeof(buf));
  142. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  143. return -EFAULT;
  144. ret = strict_strtol(buf, 16, &result);
  145. priv->btmrvl_dev.gpio_gap = result;
  146. return count;
  147. }
  148. static ssize_t btmrvl_gpiogap_read(struct file *file, char __user *userbuf,
  149. size_t count, loff_t *ppos)
  150. {
  151. struct btmrvl_private *priv = file->private_data;
  152. char buf[16];
  153. int ret;
  154. ret = snprintf(buf, sizeof(buf) - 1, "0x%x\n",
  155. priv->btmrvl_dev.gpio_gap);
  156. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  157. }
  158. static const struct file_operations btmrvl_gpiogap_fops = {
  159. .read = btmrvl_gpiogap_read,
  160. .write = btmrvl_gpiogap_write,
  161. .open = btmrvl_open_generic,
  162. };
  163. static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
  164. size_t count, loff_t *ppos)
  165. {
  166. struct btmrvl_private *priv = (struct btmrvl_private *) file->private_data;
  167. char buf[16];
  168. long result, ret;
  169. memset(buf, 0, sizeof(buf));
  170. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  171. return -EFAULT;
  172. ret = strict_strtol(buf, 10, &result);
  173. priv->btmrvl_dev.hscmd = result;
  174. if (priv->btmrvl_dev.hscmd) {
  175. btmrvl_prepare_command(priv);
  176. wake_up_interruptible(&priv->main_thread.wait_q);
  177. }
  178. return count;
  179. }
  180. static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
  181. size_t count, loff_t *ppos)
  182. {
  183. struct btmrvl_private *priv = file->private_data;
  184. char buf[16];
  185. int ret;
  186. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);
  187. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  188. }
  189. static const struct file_operations btmrvl_hscmd_fops = {
  190. .read = btmrvl_hscmd_read,
  191. .write = btmrvl_hscmd_write,
  192. .open = btmrvl_open_generic,
  193. };
  194. static ssize_t btmrvl_hsmode_write(struct file *file, const char __user *ubuf,
  195. size_t count, loff_t *ppos)
  196. {
  197. struct btmrvl_private *priv = file->private_data;
  198. char buf[16];
  199. long result, ret;
  200. memset(buf, 0, sizeof(buf));
  201. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  202. return -EFAULT;
  203. ret = strict_strtol(buf, 10, &result);
  204. priv->btmrvl_dev.hsmode = result;
  205. return count;
  206. }
  207. static ssize_t btmrvl_hsmode_read(struct file *file, char __user * userbuf,
  208. size_t count, loff_t *ppos)
  209. {
  210. struct btmrvl_private *priv = file->private_data;
  211. char buf[16];
  212. int ret;
  213. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hsmode);
  214. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  215. }
  216. static const struct file_operations btmrvl_hsmode_fops = {
  217. .read = btmrvl_hsmode_read,
  218. .write = btmrvl_hsmode_write,
  219. .open = btmrvl_open_generic,
  220. };
  221. static ssize_t btmrvl_curpsmode_read(struct file *file, char __user *userbuf,
  222. size_t count, loff_t *ppos)
  223. {
  224. struct btmrvl_private *priv = file->private_data;
  225. char buf[16];
  226. int ret;
  227. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->psmode);
  228. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  229. }
  230. static const struct file_operations btmrvl_curpsmode_fops = {
  231. .read = btmrvl_curpsmode_read,
  232. .open = btmrvl_open_generic,
  233. };
  234. static ssize_t btmrvl_psstate_read(struct file *file, char __user * userbuf,
  235. size_t count, loff_t *ppos)
  236. {
  237. struct btmrvl_private *priv = file->private_data;
  238. char buf[16];
  239. int ret;
  240. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->ps_state);
  241. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  242. }
  243. static const struct file_operations btmrvl_psstate_fops = {
  244. .read = btmrvl_psstate_read,
  245. .open = btmrvl_open_generic,
  246. };
  247. static ssize_t btmrvl_hsstate_read(struct file *file, char __user *userbuf,
  248. size_t count, loff_t *ppos)
  249. {
  250. struct btmrvl_private *priv = file->private_data;
  251. char buf[16];
  252. int ret;
  253. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->hs_state);
  254. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  255. }
  256. static const struct file_operations btmrvl_hsstate_fops = {
  257. .read = btmrvl_hsstate_read,
  258. .open = btmrvl_open_generic,
  259. };
  260. static ssize_t btmrvl_txdnldready_read(struct file *file, char __user *userbuf,
  261. size_t count, loff_t *ppos)
  262. {
  263. struct btmrvl_private *priv = file->private_data;
  264. char buf[16];
  265. int ret;
  266. ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
  267. priv->btmrvl_dev.tx_dnld_rdy);
  268. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  269. }
  270. static const struct file_operations btmrvl_txdnldready_fops = {
  271. .read = btmrvl_txdnldready_read,
  272. .open = btmrvl_open_generic,
  273. };
  274. void btmrvl_debugfs_init(struct hci_dev *hdev)
  275. {
  276. struct btmrvl_private *priv = hdev->driver_data;
  277. struct btmrvl_debugfs_data *dbg;
  278. dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
  279. priv->debugfs_data = dbg;
  280. if (!dbg) {
  281. BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
  282. return;
  283. }
  284. dbg->root_dir = debugfs_create_dir("btmrvl", NULL);
  285. dbg->config_dir = debugfs_create_dir("config", dbg->root_dir);
  286. dbg->psmode = debugfs_create_file("psmode", 0644, dbg->config_dir,
  287. hdev->driver_data, &btmrvl_psmode_fops);
  288. dbg->pscmd = debugfs_create_file("pscmd", 0644, dbg->config_dir,
  289. hdev->driver_data, &btmrvl_pscmd_fops);
  290. dbg->gpiogap = debugfs_create_file("gpiogap", 0644, dbg->config_dir,
  291. hdev->driver_data, &btmrvl_gpiogap_fops);
  292. dbg->hsmode = debugfs_create_file("hsmode", 0644, dbg->config_dir,
  293. hdev->driver_data, &btmrvl_hsmode_fops);
  294. dbg->hscmd = debugfs_create_file("hscmd", 0644, dbg->config_dir,
  295. hdev->driver_data, &btmrvl_hscmd_fops);
  296. dbg->hscfgcmd = debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
  297. hdev->driver_data, &btmrvl_hscfgcmd_fops);
  298. dbg->status_dir = debugfs_create_dir("status", dbg->root_dir);
  299. dbg->curpsmode = debugfs_create_file("curpsmode", 0444,
  300. dbg->status_dir,
  301. hdev->driver_data,
  302. &btmrvl_curpsmode_fops);
  303. dbg->psstate = debugfs_create_file("psstate", 0444, dbg->status_dir,
  304. hdev->driver_data, &btmrvl_psstate_fops);
  305. dbg->hsstate = debugfs_create_file("hsstate", 0444, dbg->status_dir,
  306. hdev->driver_data, &btmrvl_hsstate_fops);
  307. dbg->txdnldready = debugfs_create_file("txdnldready", 0444,
  308. dbg->status_dir,
  309. hdev->driver_data,
  310. &btmrvl_txdnldready_fops);
  311. }
  312. void btmrvl_debugfs_remove(struct hci_dev *hdev)
  313. {
  314. struct btmrvl_private *priv = hdev->driver_data;
  315. struct btmrvl_debugfs_data *dbg = priv->debugfs_data;
  316. if (!dbg)
  317. return;
  318. debugfs_remove(dbg->psmode);
  319. debugfs_remove(dbg->pscmd);
  320. debugfs_remove(dbg->gpiogap);
  321. debugfs_remove(dbg->hsmode);
  322. debugfs_remove(dbg->hscmd);
  323. debugfs_remove(dbg->hscfgcmd);
  324. debugfs_remove(dbg->config_dir);
  325. debugfs_remove(dbg->curpsmode);
  326. debugfs_remove(dbg->psstate);
  327. debugfs_remove(dbg->hsstate);
  328. debugfs_remove(dbg->txdnldready);
  329. debugfs_remove(dbg->status_dir);
  330. debugfs_remove(dbg->root_dir);
  331. kfree(dbg);
  332. }