musb_debugfs.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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 <linux/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", MUSB_FADDR, 8 },
  48. { "Power", MUSB_POWER, 8 },
  49. { "Frame", MUSB_FRAME, 16 },
  50. { "Index", MUSB_INDEX, 8 },
  51. { "Testmode", MUSB_TESTMODE, 8 },
  52. { "TxMaxPp", MUSB_TXMAXP, 16 },
  53. { "TxCSRp", MUSB_TXCSR, 16 },
  54. { "RxMaxPp", MUSB_RXMAXP, 16 },
  55. { "RxCSR", MUSB_RXCSR, 16 },
  56. { "RxCount", MUSB_RXCOUNT, 16 },
  57. { "IntrRxE", MUSB_INTRRXE, 16 },
  58. { "IntrTxE", MUSB_INTRTXE, 16 },
  59. { "IntrUsbE", MUSB_INTRUSBE, 8 },
  60. { "DevCtl", MUSB_DEVCTL, 8 },
  61. { "VControl", 0x68, 32 },
  62. { "HWVers", 0x69, 16 },
  63. { "LinkInfo", MUSB_LINKINFO, 8 },
  64. { "VPLen", MUSB_VPLEN, 8 },
  65. { "HS_EOF1", MUSB_HS_EOF1, 8 },
  66. { "FS_EOF1", MUSB_FS_EOF1, 8 },
  67. { "LS_EOF1", MUSB_LS_EOF1, 8 },
  68. { "SOFT_RST", 0x7F, 8 },
  69. { "DMA_CNTLch0", 0x204, 16 },
  70. { "DMA_ADDRch0", 0x208, 32 },
  71. { "DMA_COUNTch0", 0x20C, 32 },
  72. { "DMA_CNTLch1", 0x214, 16 },
  73. { "DMA_ADDRch1", 0x218, 32 },
  74. { "DMA_COUNTch1", 0x21C, 32 },
  75. { "DMA_CNTLch2", 0x224, 16 },
  76. { "DMA_ADDRch2", 0x228, 32 },
  77. { "DMA_COUNTch2", 0x22C, 32 },
  78. { "DMA_CNTLch3", 0x234, 16 },
  79. { "DMA_ADDRch3", 0x238, 32 },
  80. { "DMA_COUNTch3", 0x23C, 32 },
  81. { "DMA_CNTLch4", 0x244, 16 },
  82. { "DMA_ADDRch4", 0x248, 32 },
  83. { "DMA_COUNTch4", 0x24C, 32 },
  84. { "DMA_CNTLch5", 0x254, 16 },
  85. { "DMA_ADDRch5", 0x258, 32 },
  86. { "DMA_COUNTch5", 0x25C, 32 },
  87. { "DMA_CNTLch6", 0x264, 16 },
  88. { "DMA_ADDRch6", 0x268, 32 },
  89. { "DMA_COUNTch6", 0x26C, 32 },
  90. { "DMA_CNTLch7", 0x274, 16 },
  91. { "DMA_ADDRch7", 0x278, 32 },
  92. { "DMA_COUNTch7", 0x27C, 32 },
  93. #ifndef CONFIG_BLACKFIN
  94. { "ConfigData", MUSB_CONFIGDATA,8 },
  95. { "BabbleCtl", MUSB_BABBLE_CTL,8 },
  96. { "TxFIFOsz", MUSB_TXFIFOSZ, 8 },
  97. { "RxFIFOsz", MUSB_RXFIFOSZ, 8 },
  98. { "TxFIFOadd", MUSB_TXFIFOADD, 16 },
  99. { "RxFIFOadd", MUSB_RXFIFOADD, 16 },
  100. { "EPInfo", MUSB_EPINFO, 8 },
  101. { "RAMInfo", MUSB_RAMINFO, 8 },
  102. #endif
  103. { } /* Terminating Entry */
  104. };
  105. static int musb_regdump_show(struct seq_file *s, void *unused)
  106. {
  107. struct musb *musb = s->private;
  108. unsigned i;
  109. seq_printf(s, "MUSB (M)HDRC Register Dump\n");
  110. pm_runtime_get_sync(musb->controller);
  111. for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
  112. switch (musb_regmap[i].size) {
  113. case 8:
  114. seq_printf(s, "%-12s: %02x\n", musb_regmap[i].name,
  115. musb_readb(musb->mregs, musb_regmap[i].offset));
  116. break;
  117. case 16:
  118. seq_printf(s, "%-12s: %04x\n", musb_regmap[i].name,
  119. musb_readw(musb->mregs, musb_regmap[i].offset));
  120. break;
  121. case 32:
  122. seq_printf(s, "%-12s: %08x\n", musb_regmap[i].name,
  123. musb_readl(musb->mregs, musb_regmap[i].offset));
  124. break;
  125. }
  126. }
  127. pm_runtime_mark_last_busy(musb->controller);
  128. pm_runtime_put_autosuspend(musb->controller);
  129. return 0;
  130. }
  131. static int musb_regdump_open(struct inode *inode, struct file *file)
  132. {
  133. return single_open(file, musb_regdump_show, inode->i_private);
  134. }
  135. static int musb_test_mode_show(struct seq_file *s, void *unused)
  136. {
  137. struct musb *musb = s->private;
  138. unsigned test;
  139. pm_runtime_get_sync(musb->controller);
  140. test = musb_readb(musb->mregs, MUSB_TESTMODE);
  141. pm_runtime_mark_last_busy(musb->controller);
  142. pm_runtime_put_autosuspend(musb->controller);
  143. if (test == (MUSB_TEST_FORCE_HOST | MUSB_TEST_FORCE_FS))
  144. seq_printf(s, "force host full-speed\n");
  145. else if (test == (MUSB_TEST_FORCE_HOST | MUSB_TEST_FORCE_HS))
  146. seq_printf(s, "force host high-speed\n");
  147. else if (test == MUSB_TEST_FORCE_HOST)
  148. seq_printf(s, "force host\n");
  149. else if (test == MUSB_TEST_FIFO_ACCESS)
  150. seq_printf(s, "fifo access\n");
  151. else if (test == MUSB_TEST_FORCE_FS)
  152. seq_printf(s, "force full-speed\n");
  153. else if (test == MUSB_TEST_FORCE_HS)
  154. seq_printf(s, "force high-speed\n");
  155. else if (test == MUSB_TEST_PACKET)
  156. seq_printf(s, "test packet\n");
  157. else if (test == MUSB_TEST_K)
  158. seq_printf(s, "test K\n");
  159. else if (test == MUSB_TEST_J)
  160. seq_printf(s, "test J\n");
  161. else 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. return single_open(file, musb_test_mode_show, inode->i_private);
  174. }
  175. static ssize_t musb_test_mode_write(struct file *file,
  176. const char __user *ubuf, size_t count, loff_t *ppos)
  177. {
  178. struct seq_file *s = file->private_data;
  179. struct musb *musb = s->private;
  180. u8 test;
  181. char buf[24];
  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. pm_runtime_get_sync(musb->controller);
  186. test = musb_readb(musb->mregs, MUSB_TESTMODE);
  187. if (test) {
  188. dev_err(musb->controller, "Error: test mode is already set. "
  189. "Please do USB Bus Reset to start a new test.\n");
  190. goto ret;
  191. }
  192. if (strstarts(buf, "force host full-speed"))
  193. test = MUSB_TEST_FORCE_HOST | MUSB_TEST_FORCE_FS;
  194. else if (strstarts(buf, "force host high-speed"))
  195. test = MUSB_TEST_FORCE_HOST | MUSB_TEST_FORCE_HS;
  196. else if (strstarts(buf, "force host"))
  197. test = MUSB_TEST_FORCE_HOST;
  198. else if (strstarts(buf, "fifo access"))
  199. test = MUSB_TEST_FIFO_ACCESS;
  200. else if (strstarts(buf, "force full-speed"))
  201. test = MUSB_TEST_FORCE_FS;
  202. else if (strstarts(buf, "force high-speed"))
  203. test = MUSB_TEST_FORCE_HS;
  204. else if (strstarts(buf, "test packet")) {
  205. test = MUSB_TEST_PACKET;
  206. musb_load_testpacket(musb);
  207. }
  208. else if (strstarts(buf, "test K"))
  209. test = MUSB_TEST_K;
  210. else if (strstarts(buf, "test J"))
  211. test = MUSB_TEST_J;
  212. else if (strstarts(buf, "test SE0 NAK"))
  213. test = MUSB_TEST_SE0_NAK;
  214. musb_writeb(musb->mregs, MUSB_TESTMODE, test);
  215. ret:
  216. pm_runtime_mark_last_busy(musb->controller);
  217. pm_runtime_put_autosuspend(musb->controller);
  218. return count;
  219. }
  220. static const struct file_operations musb_test_mode_fops = {
  221. .open = musb_test_mode_open,
  222. .write = musb_test_mode_write,
  223. .read = seq_read,
  224. .llseek = seq_lseek,
  225. .release = single_release,
  226. };
  227. static int musb_softconnect_show(struct seq_file *s, void *unused)
  228. {
  229. struct musb *musb = s->private;
  230. u8 reg;
  231. int connect;
  232. switch (musb->xceiv->otg->state) {
  233. case OTG_STATE_A_HOST:
  234. case OTG_STATE_A_WAIT_BCON:
  235. pm_runtime_get_sync(musb->controller);
  236. reg = musb_readb(musb->mregs, MUSB_DEVCTL);
  237. connect = reg & MUSB_DEVCTL_SESSION ? 1 : 0;
  238. pm_runtime_mark_last_busy(musb->controller);
  239. pm_runtime_put_autosuspend(musb->controller);
  240. break;
  241. default:
  242. connect = -1;
  243. }
  244. seq_printf(s, "%d\n", connect);
  245. return 0;
  246. }
  247. static int musb_softconnect_open(struct inode *inode, struct file *file)
  248. {
  249. return single_open(file, musb_softconnect_show, inode->i_private);
  250. }
  251. static ssize_t musb_softconnect_write(struct file *file,
  252. const char __user *ubuf, size_t count, loff_t *ppos)
  253. {
  254. struct seq_file *s = file->private_data;
  255. struct musb *musb = s->private;
  256. char buf[2];
  257. u8 reg;
  258. memset(buf, 0x00, sizeof(buf));
  259. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  260. return -EFAULT;
  261. pm_runtime_get_sync(musb->controller);
  262. if (!strncmp(buf, "0", 1)) {
  263. switch (musb->xceiv->otg->state) {
  264. case OTG_STATE_A_HOST:
  265. musb_root_disconnect(musb);
  266. reg = musb_readb(musb->mregs, MUSB_DEVCTL);
  267. reg &= ~MUSB_DEVCTL_SESSION;
  268. musb_writeb(musb->mregs, MUSB_DEVCTL, reg);
  269. break;
  270. default:
  271. break;
  272. }
  273. } else if (!strncmp(buf, "1", 1)) {
  274. switch (musb->xceiv->otg->state) {
  275. case OTG_STATE_A_WAIT_BCON:
  276. /*
  277. * musb_save_context() called in musb_runtime_suspend()
  278. * might cache devctl with SESSION bit cleared during
  279. * soft-disconnect, so specifically set SESSION bit
  280. * here to preserve it for musb_runtime_resume().
  281. */
  282. musb->context.devctl |= MUSB_DEVCTL_SESSION;
  283. reg = musb_readb(musb->mregs, MUSB_DEVCTL);
  284. reg |= MUSB_DEVCTL_SESSION;
  285. musb_writeb(musb->mregs, MUSB_DEVCTL, reg);
  286. break;
  287. default:
  288. break;
  289. }
  290. }
  291. pm_runtime_mark_last_busy(musb->controller);
  292. pm_runtime_put_autosuspend(musb->controller);
  293. return count;
  294. }
  295. /*
  296. * In host mode, connect/disconnect the bus without physically
  297. * remove the devices.
  298. */
  299. static const struct file_operations musb_softconnect_fops = {
  300. .open = musb_softconnect_open,
  301. .write = musb_softconnect_write,
  302. .read = seq_read,
  303. .llseek = seq_lseek,
  304. .release = single_release,
  305. };
  306. int musb_init_debugfs(struct musb *musb)
  307. {
  308. struct dentry *root;
  309. struct dentry *file;
  310. int ret;
  311. root = debugfs_create_dir(dev_name(musb->controller), NULL);
  312. if (!root) {
  313. ret = -ENOMEM;
  314. goto err0;
  315. }
  316. file = debugfs_create_file("regdump", S_IRUGO, root, musb,
  317. &musb_regdump_fops);
  318. if (!file) {
  319. ret = -ENOMEM;
  320. goto err1;
  321. }
  322. file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR,
  323. root, musb, &musb_test_mode_fops);
  324. if (!file) {
  325. ret = -ENOMEM;
  326. goto err1;
  327. }
  328. file = debugfs_create_file("softconnect", S_IRUGO | S_IWUSR,
  329. root, musb, &musb_softconnect_fops);
  330. if (!file) {
  331. ret = -ENOMEM;
  332. goto err1;
  333. }
  334. musb->debugfs_root = root;
  335. return 0;
  336. err1:
  337. debugfs_remove_recursive(root);
  338. err0:
  339. return ret;
  340. }
  341. void /* __init_or_exit */ musb_exit_debugfs(struct musb *musb)
  342. {
  343. debugfs_remove_recursive(musb->debugfs_root);
  344. }