btmrvl_debugfs.c 11 KB

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