musb_debugfs.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * MUSB OTG driver debugfs support
  3. *
  4. * Copyright 2010 Nokia Corporation
  5. * Contact: Felipe Balbi <felipe.balbi@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. *
  21. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  24. * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  27. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  28. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. #include <linux/module.h>
  34. #include <linux/kernel.h>
  35. #include <linux/init.h>
  36. #include <linux/debugfs.h>
  37. #include <linux/seq_file.h>
  38. #include <asm/uaccess.h>
  39. #include "musb_core.h"
  40. #include "musb_debug.h"
  41. struct musb_register_map {
  42. char *name;
  43. unsigned offset;
  44. unsigned size;
  45. };
  46. static const struct musb_register_map musb_regmap[] = {
  47. { "FAddr", 0x00, 8 },
  48. { "Power", 0x01, 8 },
  49. { "Frame", 0x0c, 16 },
  50. { "Index", 0x0e, 8 },
  51. { "Testmode", 0x0f, 8 },
  52. { "TxMaxPp", 0x10, 16 },
  53. { "TxCSRp", 0x12, 16 },
  54. { "RxMaxPp", 0x14, 16 },
  55. { "RxCSR", 0x16, 16 },
  56. { "RxCount", 0x18, 16 },
  57. { "ConfigData", 0x1f, 8 },
  58. { "DevCtl", 0x60, 8 },
  59. { "MISC", 0x61, 8 },
  60. { "TxFIFOsz", 0x62, 8 },
  61. { "RxFIFOsz", 0x63, 8 },
  62. { "TxFIFOadd", 0x64, 16 },
  63. { "RxFIFOadd", 0x66, 16 },
  64. { "VControl", 0x68, 32 },
  65. { "HWVers", 0x6C, 16 },
  66. { "EPInfo", 0x78, 8 },
  67. { "RAMInfo", 0x79, 8 },
  68. { "LinkInfo", 0x7A, 8 },
  69. { "VPLen", 0x7B, 8 },
  70. { "HS_EOF1", 0x7C, 8 },
  71. { "FS_EOF1", 0x7D, 8 },
  72. { "LS_EOF1", 0x7E, 8 },
  73. { "SOFT_RST", 0x7F, 8 },
  74. { "DMA_CNTLch0", 0x204, 16 },
  75. { "DMA_ADDRch0", 0x208, 32 },
  76. { "DMA_COUNTch0", 0x20C, 32 },
  77. { "DMA_CNTLch1", 0x214, 16 },
  78. { "DMA_ADDRch1", 0x218, 32 },
  79. { "DMA_COUNTch1", 0x21C, 32 },
  80. { "DMA_CNTLch2", 0x224, 16 },
  81. { "DMA_ADDRch2", 0x228, 32 },
  82. { "DMA_COUNTch2", 0x22C, 32 },
  83. { "DMA_CNTLch3", 0x234, 16 },
  84. { "DMA_ADDRch3", 0x238, 32 },
  85. { "DMA_COUNTch3", 0x23C, 32 },
  86. { "DMA_CNTLch4", 0x244, 16 },
  87. { "DMA_ADDRch4", 0x248, 32 },
  88. { "DMA_COUNTch4", 0x24C, 32 },
  89. { "DMA_CNTLch5", 0x254, 16 },
  90. { "DMA_ADDRch5", 0x258, 32 },
  91. { "DMA_COUNTch5", 0x25C, 32 },
  92. { "DMA_CNTLch6", 0x264, 16 },
  93. { "DMA_ADDRch6", 0x268, 32 },
  94. { "DMA_COUNTch6", 0x26C, 32 },
  95. { "DMA_CNTLch7", 0x274, 16 },
  96. { "DMA_ADDRch7", 0x278, 32 },
  97. { "DMA_COUNTch7", 0x27C, 32 },
  98. { } /* Terminating Entry */
  99. };
  100. static int musb_regdump_show(struct seq_file *s, void *unused)
  101. {
  102. struct musb *musb = s->private;
  103. unsigned i;
  104. seq_printf(s, "MUSB (M)HDRC Register Dump\n");
  105. for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
  106. switch (musb_regmap[i].size) {
  107. case 8:
  108. seq_printf(s, "%-12s: %02x\n", musb_regmap[i].name,
  109. musb_readb(musb->mregs, musb_regmap[i].offset));
  110. break;
  111. case 16:
  112. seq_printf(s, "%-12s: %04x\n", musb_regmap[i].name,
  113. musb_readw(musb->mregs, musb_regmap[i].offset));
  114. break;
  115. case 32:
  116. seq_printf(s, "%-12s: %08x\n", musb_regmap[i].name,
  117. musb_readl(musb->mregs, musb_regmap[i].offset));
  118. break;
  119. }
  120. }
  121. return 0;
  122. }
  123. static int musb_regdump_open(struct inode *inode, struct file *file)
  124. {
  125. return single_open(file, musb_regdump_show, inode->i_private);
  126. }
  127. static int musb_test_mode_show(struct seq_file *s, void *unused)
  128. {
  129. struct musb *musb = s->private;
  130. unsigned test;
  131. test = musb_readb(musb->mregs, MUSB_TESTMODE);
  132. if (test & MUSB_TEST_FORCE_HOST)
  133. seq_printf(s, "force host\n");
  134. if (test & MUSB_TEST_FIFO_ACCESS)
  135. seq_printf(s, "fifo access\n");
  136. if (test & MUSB_TEST_FORCE_FS)
  137. seq_printf(s, "force full-speed\n");
  138. if (test & MUSB_TEST_FORCE_HS)
  139. seq_printf(s, "force high-speed\n");
  140. if (test & MUSB_TEST_PACKET)
  141. seq_printf(s, "test packet\n");
  142. if (test & MUSB_TEST_K)
  143. seq_printf(s, "test K\n");
  144. if (test & MUSB_TEST_J)
  145. seq_printf(s, "test J\n");
  146. if (test & MUSB_TEST_SE0_NAK)
  147. seq_printf(s, "test SE0 NAK\n");
  148. return 0;
  149. }
  150. static const struct file_operations musb_regdump_fops = {
  151. .open = musb_regdump_open,
  152. .read = seq_read,
  153. .llseek = seq_lseek,
  154. .release = single_release,
  155. };
  156. static int musb_test_mode_open(struct inode *inode, struct file *file)
  157. {
  158. return single_open(file, musb_test_mode_show, inode->i_private);
  159. }
  160. static ssize_t musb_test_mode_write(struct file *file,
  161. const char __user *ubuf, size_t count, loff_t *ppos)
  162. {
  163. struct seq_file *s = file->private_data;
  164. struct musb *musb = s->private;
  165. u8 test = 0;
  166. char buf[18];
  167. memset(buf, 0x00, sizeof(buf));
  168. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  169. return -EFAULT;
  170. if (!strncmp(buf, "force host", 9))
  171. test = MUSB_TEST_FORCE_HOST;
  172. if (!strncmp(buf, "fifo access", 11))
  173. test = MUSB_TEST_FIFO_ACCESS;
  174. if (!strncmp(buf, "force full-speed", 15))
  175. test = MUSB_TEST_FORCE_FS;
  176. if (!strncmp(buf, "force high-speed", 15))
  177. test = MUSB_TEST_FORCE_HS;
  178. if (!strncmp(buf, "test packet", 10)) {
  179. test = MUSB_TEST_PACKET;
  180. musb_load_testpacket(musb);
  181. }
  182. if (!strncmp(buf, "test K", 6))
  183. test = MUSB_TEST_K;
  184. if (!strncmp(buf, "test J", 6))
  185. test = MUSB_TEST_J;
  186. if (!strncmp(buf, "test SE0 NAK", 12))
  187. test = MUSB_TEST_SE0_NAK;
  188. musb_writeb(musb->mregs, MUSB_TESTMODE, test);
  189. return count;
  190. }
  191. static const struct file_operations musb_test_mode_fops = {
  192. .open = musb_test_mode_open,
  193. .write = musb_test_mode_write,
  194. .read = seq_read,
  195. .llseek = seq_lseek,
  196. .release = single_release,
  197. };
  198. int musb_init_debugfs(struct musb *musb)
  199. {
  200. struct dentry *root;
  201. struct dentry *file;
  202. int ret;
  203. root = debugfs_create_dir(dev_name(musb->controller), NULL);
  204. if (!root) {
  205. ret = -ENOMEM;
  206. goto err0;
  207. }
  208. file = debugfs_create_file("regdump", S_IRUGO, root, musb,
  209. &musb_regdump_fops);
  210. if (!file) {
  211. ret = -ENOMEM;
  212. goto err1;
  213. }
  214. file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR,
  215. root, musb, &musb_test_mode_fops);
  216. if (!file) {
  217. ret = -ENOMEM;
  218. goto err1;
  219. }
  220. musb->debugfs_root = root;
  221. return 0;
  222. err1:
  223. debugfs_remove_recursive(root);
  224. err0:
  225. return ret;
  226. }
  227. void /* __init_or_exit */ musb_exit_debugfs(struct musb *musb)
  228. {
  229. debugfs_remove_recursive(musb->debugfs_root);
  230. }