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