btmrvl_debugfs.c 12 KB

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