musb_debugfs.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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/sched.h>
  36. #include <linux/slab.h>
  37. #include <linux/init.h>
  38. #include <linux/list.h>
  39. #include <linux/kobject.h>
  40. #include <linux/platform_device.h>
  41. #include <linux/io.h>
  42. #include <linux/debugfs.h>
  43. #include <linux/seq_file.h>
  44. #ifdef CONFIG_ARM
  45. #include <mach/hardware.h>
  46. #include <mach/memory.h>
  47. #include <asm/mach-types.h>
  48. #endif
  49. #include <asm/uaccess.h>
  50. #include "musb_core.h"
  51. #include "musb_debug.h"
  52. #ifdef CONFIG_ARCH_DAVINCI
  53. #include "davinci.h"
  54. #endif
  55. struct musb_register_map {
  56. char *name;
  57. unsigned offset;
  58. unsigned size;
  59. };
  60. static const struct musb_register_map musb_regmap[] = {
  61. { "FAddr", 0x00, 8 },
  62. { "Power", 0x01, 8 },
  63. { "Frame", 0x0c, 16 },
  64. { "Index", 0x0e, 8 },
  65. { "Testmode", 0x0f, 8 },
  66. { "TxMaxPp", 0x10, 16 },
  67. { "TxCSRp", 0x12, 16 },
  68. { "RxMaxPp", 0x14, 16 },
  69. { "RxCSR", 0x16, 16 },
  70. { "RxCount", 0x18, 16 },
  71. { "ConfigData", 0x1f, 8 },
  72. { "DevCtl", 0x60, 8 },
  73. { "MISC", 0x61, 8 },
  74. { "TxFIFOsz", 0x62, 8 },
  75. { "RxFIFOsz", 0x63, 8 },
  76. { "TxFIFOadd", 0x64, 16 },
  77. { "RxFIFOadd", 0x66, 16 },
  78. { "VControl", 0x68, 32 },
  79. { "HWVers", 0x6C, 16 },
  80. { "EPInfo", 0x78, 8 },
  81. { "RAMInfo", 0x79, 8 },
  82. { "LinkInfo", 0x7A, 8 },
  83. { "VPLen", 0x7B, 8 },
  84. { "HS_EOF1", 0x7C, 8 },
  85. { "FS_EOF1", 0x7D, 8 },
  86. { "LS_EOF1", 0x7E, 8 },
  87. { "SOFT_RST", 0x7F, 8 },
  88. { "DMA_CNTLch0", 0x204, 16 },
  89. { "DMA_ADDRch0", 0x208, 16 },
  90. { "DMA_COUNTch0", 0x20C, 16 },
  91. { "DMA_CNTLch1", 0x214, 16 },
  92. { "DMA_ADDRch1", 0x218, 16 },
  93. { "DMA_COUNTch1", 0x21C, 16 },
  94. { "DMA_CNTLch2", 0x224, 16 },
  95. { "DMA_ADDRch2", 0x228, 16 },
  96. { "DMA_COUNTch2", 0x22C, 16 },
  97. { "DMA_CNTLch3", 0x234, 16 },
  98. { "DMA_ADDRch3", 0x238, 16 },
  99. { "DMA_COUNTch3", 0x23C, 16 },
  100. { "DMA_CNTLch4", 0x244, 16 },
  101. { "DMA_ADDRch4", 0x248, 16 },
  102. { "DMA_COUNTch4", 0x24C, 16 },
  103. { "DMA_CNTLch5", 0x254, 16 },
  104. { "DMA_ADDRch5", 0x258, 16 },
  105. { "DMA_COUNTch5", 0x25C, 16 },
  106. { "DMA_CNTLch6", 0x264, 16 },
  107. { "DMA_ADDRch6", 0x268, 16 },
  108. { "DMA_COUNTch6", 0x26C, 16 },
  109. { "DMA_CNTLch7", 0x274, 16 },
  110. { "DMA_ADDRch7", 0x278, 16 },
  111. { "DMA_COUNTch7", 0x27C, 16 },
  112. { } /* Terminating Entry */
  113. };
  114. static struct dentry *musb_debugfs_root;
  115. static int musb_regdump_show(struct seq_file *s, void *unused)
  116. {
  117. struct musb *musb = s->private;
  118. unsigned i;
  119. seq_printf(s, "MUSB (M)HDRC Register Dump\n");
  120. for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
  121. switch (musb_regmap[i].size) {
  122. case 8:
  123. seq_printf(s, "%-12s: %02x\n", musb_regmap[i].name,
  124. musb_readb(musb->mregs, musb_regmap[i].offset));
  125. break;
  126. case 16:
  127. seq_printf(s, "%-12s: %04x\n", musb_regmap[i].name,
  128. musb_readw(musb->mregs, musb_regmap[i].offset));
  129. break;
  130. case 32:
  131. seq_printf(s, "%-12s: %08x\n", musb_regmap[i].name,
  132. musb_readl(musb->mregs, musb_regmap[i].offset));
  133. break;
  134. }
  135. }
  136. return 0;
  137. }
  138. static int musb_regdump_open(struct inode *inode, struct file *file)
  139. {
  140. return single_open(file, musb_regdump_show, inode->i_private);
  141. }
  142. static int musb_test_mode_show(struct seq_file *s, void *unused)
  143. {
  144. struct musb *musb = s->private;
  145. unsigned test;
  146. test = musb_readb(musb->mregs, MUSB_TESTMODE);
  147. if (test & MUSB_TEST_FORCE_HOST)
  148. seq_printf(s, "force host\n");
  149. if (test & MUSB_TEST_FIFO_ACCESS)
  150. seq_printf(s, "fifo access\n");
  151. if (test & MUSB_TEST_FORCE_FS)
  152. seq_printf(s, "force full-speed\n");
  153. if (test & MUSB_TEST_FORCE_HS)
  154. seq_printf(s, "force high-speed\n");
  155. if (test & MUSB_TEST_PACKET)
  156. seq_printf(s, "test packet\n");
  157. if (test & MUSB_TEST_K)
  158. seq_printf(s, "test K\n");
  159. if (test & MUSB_TEST_J)
  160. seq_printf(s, "test J\n");
  161. if (test & MUSB_TEST_SE0_NAK)
  162. seq_printf(s, "test SE0 NAK\n");
  163. return 0;
  164. }
  165. static const struct file_operations musb_regdump_fops = {
  166. .open = musb_regdump_open,
  167. .read = seq_read,
  168. .llseek = seq_lseek,
  169. .release = single_release,
  170. };
  171. static int musb_test_mode_open(struct inode *inode, struct file *file)
  172. {
  173. file->private_data = inode->i_private;
  174. return single_open(file, musb_test_mode_show, inode->i_private);
  175. }
  176. static ssize_t musb_test_mode_write(struct file *file,
  177. const char __user *ubuf, size_t count, loff_t *ppos)
  178. {
  179. struct musb *musb = file->private_data;
  180. u8 test = 0;
  181. char buf[18];
  182. memset(buf, 0x00, sizeof(buf));
  183. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  184. return -EFAULT;
  185. if (!strncmp(buf, "force host", 9))
  186. test = MUSB_TEST_FORCE_HOST;
  187. if (!strncmp(buf, "fifo access", 11))
  188. test = MUSB_TEST_FIFO_ACCESS;
  189. if (!strncmp(buf, "force full-speed", 15))
  190. test = MUSB_TEST_FORCE_FS;
  191. if (!strncmp(buf, "force high-speed", 15))
  192. test = MUSB_TEST_FORCE_HS;
  193. if (!strncmp(buf, "test packet", 10)) {
  194. test = MUSB_TEST_PACKET;
  195. musb_load_testpacket(musb);
  196. }
  197. if (!strncmp(buf, "test K", 6))
  198. test = MUSB_TEST_K;
  199. if (!strncmp(buf, "test J", 6))
  200. test = MUSB_TEST_J;
  201. if (!strncmp(buf, "test SE0 NAK", 12))
  202. test = MUSB_TEST_SE0_NAK;
  203. musb_writeb(musb->mregs, MUSB_TESTMODE, test);
  204. return count;
  205. }
  206. static const struct file_operations musb_test_mode_fops = {
  207. .open = musb_test_mode_open,
  208. .write = musb_test_mode_write,
  209. .read = seq_read,
  210. .llseek = seq_lseek,
  211. .release = single_release,
  212. };
  213. int __init musb_init_debugfs(struct musb *musb)
  214. {
  215. struct dentry *root;
  216. struct dentry *file;
  217. int ret;
  218. root = debugfs_create_dir("musb", NULL);
  219. if (IS_ERR(root)) {
  220. ret = PTR_ERR(root);
  221. goto err0;
  222. }
  223. file = debugfs_create_file("regdump", S_IRUGO, root, musb,
  224. &musb_regdump_fops);
  225. if (IS_ERR(file)) {
  226. ret = PTR_ERR(file);
  227. goto err1;
  228. }
  229. file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR,
  230. root, musb, &musb_test_mode_fops);
  231. if (IS_ERR(file)) {
  232. ret = PTR_ERR(file);
  233. goto err1;
  234. }
  235. musb_debugfs_root = root;
  236. return 0;
  237. err1:
  238. debugfs_remove_recursive(root);
  239. err0:
  240. return ret;
  241. }
  242. void /* __init_or_exit */ musb_exit_debugfs(struct musb *musb)
  243. {
  244. debugfs_remove_recursive(musb_debugfs_root);
  245. }