btmrvl_debugfs.c 11 KB

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