btmrvl_debugfs.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. };
  29. static ssize_t btmrvl_hscfgcmd_write(struct file *file,
  30. const char __user *ubuf, size_t count, loff_t *ppos)
  31. {
  32. struct btmrvl_private *priv = file->private_data;
  33. long result, ret;
  34. ret = kstrtol_from_user(ubuf, count, 10, &result);
  35. if (ret)
  36. return ret;
  37. priv->btmrvl_dev.hscfgcmd = result;
  38. if (priv->btmrvl_dev.hscfgcmd) {
  39. btmrvl_prepare_command(priv);
  40. wake_up_interruptible(&priv->main_thread.wait_q);
  41. }
  42. return count;
  43. }
  44. static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user *userbuf,
  45. size_t count, loff_t *ppos)
  46. {
  47. struct btmrvl_private *priv = file->private_data;
  48. char buf[16];
  49. int ret;
  50. ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
  51. priv->btmrvl_dev.hscfgcmd);
  52. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  53. }
  54. static const struct file_operations btmrvl_hscfgcmd_fops = {
  55. .read = btmrvl_hscfgcmd_read,
  56. .write = btmrvl_hscfgcmd_write,
  57. .open = simple_open,
  58. .llseek = default_llseek,
  59. };
  60. static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
  61. size_t count, loff_t *ppos)
  62. {
  63. struct btmrvl_private *priv = file->private_data;
  64. long result, ret;
  65. ret = kstrtol_from_user(ubuf, count, 10, &result);
  66. if (ret)
  67. return ret;
  68. priv->btmrvl_dev.pscmd = result;
  69. if (priv->btmrvl_dev.pscmd) {
  70. btmrvl_prepare_command(priv);
  71. wake_up_interruptible(&priv->main_thread.wait_q);
  72. }
  73. return count;
  74. }
  75. static ssize_t btmrvl_pscmd_read(struct file *file, char __user *userbuf,
  76. size_t count, loff_t *ppos)
  77. {
  78. struct btmrvl_private *priv = file->private_data;
  79. char buf[16];
  80. int ret;
  81. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);
  82. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  83. }
  84. static const struct file_operations btmrvl_pscmd_fops = {
  85. .read = btmrvl_pscmd_read,
  86. .write = btmrvl_pscmd_write,
  87. .open = simple_open,
  88. .llseek = default_llseek,
  89. };
  90. static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
  91. size_t count, loff_t *ppos)
  92. {
  93. struct btmrvl_private *priv = file->private_data;
  94. long result, ret;
  95. ret = kstrtol_from_user(ubuf, count, 10, &result);
  96. if (ret)
  97. return ret;
  98. priv->btmrvl_dev.hscmd = result;
  99. if (priv->btmrvl_dev.hscmd) {
  100. btmrvl_prepare_command(priv);
  101. wake_up_interruptible(&priv->main_thread.wait_q);
  102. }
  103. return count;
  104. }
  105. static ssize_t btmrvl_hscmd_read(struct file *file, char __user *userbuf,
  106. size_t count, loff_t *ppos)
  107. {
  108. struct btmrvl_private *priv = file->private_data;
  109. char buf[16];
  110. int ret;
  111. ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);
  112. return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  113. }
  114. static const struct file_operations btmrvl_hscmd_fops = {
  115. .read = btmrvl_hscmd_read,
  116. .write = btmrvl_hscmd_write,
  117. .open = simple_open,
  118. .llseek = default_llseek,
  119. };
  120. void btmrvl_debugfs_init(struct hci_dev *hdev)
  121. {
  122. struct btmrvl_private *priv = hci_get_drvdata(hdev);
  123. struct btmrvl_debugfs_data *dbg;
  124. if (!hdev->debugfs)
  125. return;
  126. dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
  127. priv->debugfs_data = dbg;
  128. if (!dbg) {
  129. BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
  130. return;
  131. }
  132. dbg->config_dir = debugfs_create_dir("config", hdev->debugfs);
  133. debugfs_create_u8("psmode", 0644, dbg->config_dir,
  134. &priv->btmrvl_dev.psmode);
  135. debugfs_create_file("pscmd", 0644, dbg->config_dir,
  136. priv, &btmrvl_pscmd_fops);
  137. debugfs_create_x16("gpiogap", 0644, dbg->config_dir,
  138. &priv->btmrvl_dev.gpio_gap);
  139. debugfs_create_u8("hsmode", 0644, dbg->config_dir,
  140. &priv->btmrvl_dev.hsmode);
  141. debugfs_create_file("hscmd", 0644, dbg->config_dir,
  142. priv, &btmrvl_hscmd_fops);
  143. debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
  144. priv, &btmrvl_hscfgcmd_fops);
  145. dbg->status_dir = debugfs_create_dir("status", hdev->debugfs);
  146. debugfs_create_u8("curpsmode", 0444, dbg->status_dir,
  147. &priv->adapter->psmode);
  148. debugfs_create_u8("psstate", 0444, dbg->status_dir,
  149. &priv->adapter->ps_state);
  150. debugfs_create_u8("hsstate", 0444, dbg->status_dir,
  151. &priv->adapter->hs_state);
  152. debugfs_create_u8("txdnldready", 0444, dbg->status_dir,
  153. &priv->btmrvl_dev.tx_dnld_rdy);
  154. }
  155. void btmrvl_debugfs_remove(struct hci_dev *hdev)
  156. {
  157. struct btmrvl_private *priv = hci_get_drvdata(hdev);
  158. struct btmrvl_debugfs_data *dbg = priv->debugfs_data;
  159. if (!dbg)
  160. return;
  161. debugfs_remove_recursive(dbg->config_dir);
  162. debugfs_remove_recursive(dbg->status_dir);
  163. kfree(dbg);
  164. }