btmrvl_debugfs.c 12 KB

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