debugfs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. /**
  2. * debugfs.c - DesignWare USB3 DRD Controller DebugFS file
  3. *
  4. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
  5. *
  6. * Authors: Felipe Balbi <balbi@ti.com>,
  7. * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 of
  11. * the License as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/slab.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/types.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/debugfs.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/delay.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/usb/ch9.h>
  28. #include "core.h"
  29. #include "gadget.h"
  30. #include "io.h"
  31. #include "debug.h"
  32. #define dump_register(nm) \
  33. { \
  34. .name = __stringify(nm), \
  35. .offset = DWC3_ ##nm, \
  36. }
  37. #define dump_ep_register_set(n) \
  38. { \
  39. .name = "DEPCMDPAR2("__stringify(n)")", \
  40. .offset = DWC3_DEP_BASE(n) + \
  41. DWC3_DEPCMDPAR2, \
  42. }, \
  43. { \
  44. .name = "DEPCMDPAR1("__stringify(n)")", \
  45. .offset = DWC3_DEP_BASE(n) + \
  46. DWC3_DEPCMDPAR1, \
  47. }, \
  48. { \
  49. .name = "DEPCMDPAR0("__stringify(n)")", \
  50. .offset = DWC3_DEP_BASE(n) + \
  51. DWC3_DEPCMDPAR0, \
  52. }, \
  53. { \
  54. .name = "DEPCMD("__stringify(n)")", \
  55. .offset = DWC3_DEP_BASE(n) + \
  56. DWC3_DEPCMD, \
  57. }
  58. static const struct debugfs_reg32 dwc3_regs[] = {
  59. dump_register(GSBUSCFG0),
  60. dump_register(GSBUSCFG1),
  61. dump_register(GTXTHRCFG),
  62. dump_register(GRXTHRCFG),
  63. dump_register(GCTL),
  64. dump_register(GEVTEN),
  65. dump_register(GSTS),
  66. dump_register(GUCTL1),
  67. dump_register(GSNPSID),
  68. dump_register(GGPIO),
  69. dump_register(GUID),
  70. dump_register(GUCTL),
  71. dump_register(GBUSERRADDR0),
  72. dump_register(GBUSERRADDR1),
  73. dump_register(GPRTBIMAP0),
  74. dump_register(GPRTBIMAP1),
  75. dump_register(GHWPARAMS0),
  76. dump_register(GHWPARAMS1),
  77. dump_register(GHWPARAMS2),
  78. dump_register(GHWPARAMS3),
  79. dump_register(GHWPARAMS4),
  80. dump_register(GHWPARAMS5),
  81. dump_register(GHWPARAMS6),
  82. dump_register(GHWPARAMS7),
  83. dump_register(GDBGFIFOSPACE),
  84. dump_register(GDBGLTSSM),
  85. dump_register(GPRTBIMAP_HS0),
  86. dump_register(GPRTBIMAP_HS1),
  87. dump_register(GPRTBIMAP_FS0),
  88. dump_register(GPRTBIMAP_FS1),
  89. dump_register(GUSB2PHYCFG(0)),
  90. dump_register(GUSB2PHYCFG(1)),
  91. dump_register(GUSB2PHYCFG(2)),
  92. dump_register(GUSB2PHYCFG(3)),
  93. dump_register(GUSB2PHYCFG(4)),
  94. dump_register(GUSB2PHYCFG(5)),
  95. dump_register(GUSB2PHYCFG(6)),
  96. dump_register(GUSB2PHYCFG(7)),
  97. dump_register(GUSB2PHYCFG(8)),
  98. dump_register(GUSB2PHYCFG(9)),
  99. dump_register(GUSB2PHYCFG(10)),
  100. dump_register(GUSB2PHYCFG(11)),
  101. dump_register(GUSB2PHYCFG(12)),
  102. dump_register(GUSB2PHYCFG(13)),
  103. dump_register(GUSB2PHYCFG(14)),
  104. dump_register(GUSB2PHYCFG(15)),
  105. dump_register(GUSB2I2CCTL(0)),
  106. dump_register(GUSB2I2CCTL(1)),
  107. dump_register(GUSB2I2CCTL(2)),
  108. dump_register(GUSB2I2CCTL(3)),
  109. dump_register(GUSB2I2CCTL(4)),
  110. dump_register(GUSB2I2CCTL(5)),
  111. dump_register(GUSB2I2CCTL(6)),
  112. dump_register(GUSB2I2CCTL(7)),
  113. dump_register(GUSB2I2CCTL(8)),
  114. dump_register(GUSB2I2CCTL(9)),
  115. dump_register(GUSB2I2CCTL(10)),
  116. dump_register(GUSB2I2CCTL(11)),
  117. dump_register(GUSB2I2CCTL(12)),
  118. dump_register(GUSB2I2CCTL(13)),
  119. dump_register(GUSB2I2CCTL(14)),
  120. dump_register(GUSB2I2CCTL(15)),
  121. dump_register(GUSB2PHYACC(0)),
  122. dump_register(GUSB2PHYACC(1)),
  123. dump_register(GUSB2PHYACC(2)),
  124. dump_register(GUSB2PHYACC(3)),
  125. dump_register(GUSB2PHYACC(4)),
  126. dump_register(GUSB2PHYACC(5)),
  127. dump_register(GUSB2PHYACC(6)),
  128. dump_register(GUSB2PHYACC(7)),
  129. dump_register(GUSB2PHYACC(8)),
  130. dump_register(GUSB2PHYACC(9)),
  131. dump_register(GUSB2PHYACC(10)),
  132. dump_register(GUSB2PHYACC(11)),
  133. dump_register(GUSB2PHYACC(12)),
  134. dump_register(GUSB2PHYACC(13)),
  135. dump_register(GUSB2PHYACC(14)),
  136. dump_register(GUSB2PHYACC(15)),
  137. dump_register(GUSB3PIPECTL(0)),
  138. dump_register(GUSB3PIPECTL(1)),
  139. dump_register(GUSB3PIPECTL(2)),
  140. dump_register(GUSB3PIPECTL(3)),
  141. dump_register(GUSB3PIPECTL(4)),
  142. dump_register(GUSB3PIPECTL(5)),
  143. dump_register(GUSB3PIPECTL(6)),
  144. dump_register(GUSB3PIPECTL(7)),
  145. dump_register(GUSB3PIPECTL(8)),
  146. dump_register(GUSB3PIPECTL(9)),
  147. dump_register(GUSB3PIPECTL(10)),
  148. dump_register(GUSB3PIPECTL(11)),
  149. dump_register(GUSB3PIPECTL(12)),
  150. dump_register(GUSB3PIPECTL(13)),
  151. dump_register(GUSB3PIPECTL(14)),
  152. dump_register(GUSB3PIPECTL(15)),
  153. dump_register(GTXFIFOSIZ(0)),
  154. dump_register(GTXFIFOSIZ(1)),
  155. dump_register(GTXFIFOSIZ(2)),
  156. dump_register(GTXFIFOSIZ(3)),
  157. dump_register(GTXFIFOSIZ(4)),
  158. dump_register(GTXFIFOSIZ(5)),
  159. dump_register(GTXFIFOSIZ(6)),
  160. dump_register(GTXFIFOSIZ(7)),
  161. dump_register(GTXFIFOSIZ(8)),
  162. dump_register(GTXFIFOSIZ(9)),
  163. dump_register(GTXFIFOSIZ(10)),
  164. dump_register(GTXFIFOSIZ(11)),
  165. dump_register(GTXFIFOSIZ(12)),
  166. dump_register(GTXFIFOSIZ(13)),
  167. dump_register(GTXFIFOSIZ(14)),
  168. dump_register(GTXFIFOSIZ(15)),
  169. dump_register(GTXFIFOSIZ(16)),
  170. dump_register(GTXFIFOSIZ(17)),
  171. dump_register(GTXFIFOSIZ(18)),
  172. dump_register(GTXFIFOSIZ(19)),
  173. dump_register(GTXFIFOSIZ(20)),
  174. dump_register(GTXFIFOSIZ(21)),
  175. dump_register(GTXFIFOSIZ(22)),
  176. dump_register(GTXFIFOSIZ(23)),
  177. dump_register(GTXFIFOSIZ(24)),
  178. dump_register(GTXFIFOSIZ(25)),
  179. dump_register(GTXFIFOSIZ(26)),
  180. dump_register(GTXFIFOSIZ(27)),
  181. dump_register(GTXFIFOSIZ(28)),
  182. dump_register(GTXFIFOSIZ(29)),
  183. dump_register(GTXFIFOSIZ(30)),
  184. dump_register(GTXFIFOSIZ(31)),
  185. dump_register(GRXFIFOSIZ(0)),
  186. dump_register(GRXFIFOSIZ(1)),
  187. dump_register(GRXFIFOSIZ(2)),
  188. dump_register(GRXFIFOSIZ(3)),
  189. dump_register(GRXFIFOSIZ(4)),
  190. dump_register(GRXFIFOSIZ(5)),
  191. dump_register(GRXFIFOSIZ(6)),
  192. dump_register(GRXFIFOSIZ(7)),
  193. dump_register(GRXFIFOSIZ(8)),
  194. dump_register(GRXFIFOSIZ(9)),
  195. dump_register(GRXFIFOSIZ(10)),
  196. dump_register(GRXFIFOSIZ(11)),
  197. dump_register(GRXFIFOSIZ(12)),
  198. dump_register(GRXFIFOSIZ(13)),
  199. dump_register(GRXFIFOSIZ(14)),
  200. dump_register(GRXFIFOSIZ(15)),
  201. dump_register(GRXFIFOSIZ(16)),
  202. dump_register(GRXFIFOSIZ(17)),
  203. dump_register(GRXFIFOSIZ(18)),
  204. dump_register(GRXFIFOSIZ(19)),
  205. dump_register(GRXFIFOSIZ(20)),
  206. dump_register(GRXFIFOSIZ(21)),
  207. dump_register(GRXFIFOSIZ(22)),
  208. dump_register(GRXFIFOSIZ(23)),
  209. dump_register(GRXFIFOSIZ(24)),
  210. dump_register(GRXFIFOSIZ(25)),
  211. dump_register(GRXFIFOSIZ(26)),
  212. dump_register(GRXFIFOSIZ(27)),
  213. dump_register(GRXFIFOSIZ(28)),
  214. dump_register(GRXFIFOSIZ(29)),
  215. dump_register(GRXFIFOSIZ(30)),
  216. dump_register(GRXFIFOSIZ(31)),
  217. dump_register(GEVNTADRLO(0)),
  218. dump_register(GEVNTADRHI(0)),
  219. dump_register(GEVNTSIZ(0)),
  220. dump_register(GEVNTCOUNT(0)),
  221. dump_register(GHWPARAMS8),
  222. dump_register(DCFG),
  223. dump_register(DCTL),
  224. dump_register(DEVTEN),
  225. dump_register(DSTS),
  226. dump_register(DGCMDPAR),
  227. dump_register(DGCMD),
  228. dump_register(DALEPENA),
  229. dump_ep_register_set(0),
  230. dump_ep_register_set(1),
  231. dump_ep_register_set(2),
  232. dump_ep_register_set(3),
  233. dump_ep_register_set(4),
  234. dump_ep_register_set(5),
  235. dump_ep_register_set(6),
  236. dump_ep_register_set(7),
  237. dump_ep_register_set(8),
  238. dump_ep_register_set(9),
  239. dump_ep_register_set(10),
  240. dump_ep_register_set(11),
  241. dump_ep_register_set(12),
  242. dump_ep_register_set(13),
  243. dump_ep_register_set(14),
  244. dump_ep_register_set(15),
  245. dump_ep_register_set(16),
  246. dump_ep_register_set(17),
  247. dump_ep_register_set(18),
  248. dump_ep_register_set(19),
  249. dump_ep_register_set(20),
  250. dump_ep_register_set(21),
  251. dump_ep_register_set(22),
  252. dump_ep_register_set(23),
  253. dump_ep_register_set(24),
  254. dump_ep_register_set(25),
  255. dump_ep_register_set(26),
  256. dump_ep_register_set(27),
  257. dump_ep_register_set(28),
  258. dump_ep_register_set(29),
  259. dump_ep_register_set(30),
  260. dump_ep_register_set(31),
  261. dump_register(OCFG),
  262. dump_register(OCTL),
  263. dump_register(OEVT),
  264. dump_register(OEVTEN),
  265. dump_register(OSTS),
  266. };
  267. static int dwc3_mode_show(struct seq_file *s, void *unused)
  268. {
  269. struct dwc3 *dwc = s->private;
  270. unsigned long flags;
  271. u32 reg;
  272. spin_lock_irqsave(&dwc->lock, flags);
  273. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  274. spin_unlock_irqrestore(&dwc->lock, flags);
  275. switch (DWC3_GCTL_PRTCAP(reg)) {
  276. case DWC3_GCTL_PRTCAP_HOST:
  277. seq_printf(s, "host\n");
  278. break;
  279. case DWC3_GCTL_PRTCAP_DEVICE:
  280. seq_printf(s, "device\n");
  281. break;
  282. case DWC3_GCTL_PRTCAP_OTG:
  283. seq_printf(s, "OTG\n");
  284. break;
  285. default:
  286. seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
  287. }
  288. return 0;
  289. }
  290. static int dwc3_mode_open(struct inode *inode, struct file *file)
  291. {
  292. return single_open(file, dwc3_mode_show, inode->i_private);
  293. }
  294. static ssize_t dwc3_mode_write(struct file *file,
  295. const char __user *ubuf, size_t count, loff_t *ppos)
  296. {
  297. struct seq_file *s = file->private_data;
  298. struct dwc3 *dwc = s->private;
  299. unsigned long flags;
  300. u32 mode = 0;
  301. char buf[32];
  302. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  303. return -EFAULT;
  304. if (!strncmp(buf, "host", 4))
  305. mode |= DWC3_GCTL_PRTCAP_HOST;
  306. if (!strncmp(buf, "device", 6))
  307. mode |= DWC3_GCTL_PRTCAP_DEVICE;
  308. if (!strncmp(buf, "otg", 3))
  309. mode |= DWC3_GCTL_PRTCAP_OTG;
  310. if (mode) {
  311. spin_lock_irqsave(&dwc->lock, flags);
  312. dwc3_set_mode(dwc, mode);
  313. spin_unlock_irqrestore(&dwc->lock, flags);
  314. }
  315. return count;
  316. }
  317. static const struct file_operations dwc3_mode_fops = {
  318. .open = dwc3_mode_open,
  319. .write = dwc3_mode_write,
  320. .read = seq_read,
  321. .llseek = seq_lseek,
  322. .release = single_release,
  323. };
  324. static int dwc3_testmode_show(struct seq_file *s, void *unused)
  325. {
  326. struct dwc3 *dwc = s->private;
  327. unsigned long flags;
  328. u32 reg;
  329. spin_lock_irqsave(&dwc->lock, flags);
  330. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  331. reg &= DWC3_DCTL_TSTCTRL_MASK;
  332. reg >>= 1;
  333. spin_unlock_irqrestore(&dwc->lock, flags);
  334. switch (reg) {
  335. case 0:
  336. seq_printf(s, "no test\n");
  337. break;
  338. case TEST_J:
  339. seq_printf(s, "test_j\n");
  340. break;
  341. case TEST_K:
  342. seq_printf(s, "test_k\n");
  343. break;
  344. case TEST_SE0_NAK:
  345. seq_printf(s, "test_se0_nak\n");
  346. break;
  347. case TEST_PACKET:
  348. seq_printf(s, "test_packet\n");
  349. break;
  350. case TEST_FORCE_EN:
  351. seq_printf(s, "test_force_enable\n");
  352. break;
  353. default:
  354. seq_printf(s, "UNKNOWN %d\n", reg);
  355. }
  356. return 0;
  357. }
  358. static int dwc3_testmode_open(struct inode *inode, struct file *file)
  359. {
  360. return single_open(file, dwc3_testmode_show, inode->i_private);
  361. }
  362. static ssize_t dwc3_testmode_write(struct file *file,
  363. const char __user *ubuf, size_t count, loff_t *ppos)
  364. {
  365. struct seq_file *s = file->private_data;
  366. struct dwc3 *dwc = s->private;
  367. unsigned long flags;
  368. u32 testmode = 0;
  369. char buf[32];
  370. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  371. return -EFAULT;
  372. if (!strncmp(buf, "test_j", 6))
  373. testmode = TEST_J;
  374. else if (!strncmp(buf, "test_k", 6))
  375. testmode = TEST_K;
  376. else if (!strncmp(buf, "test_se0_nak", 12))
  377. testmode = TEST_SE0_NAK;
  378. else if (!strncmp(buf, "test_packet", 11))
  379. testmode = TEST_PACKET;
  380. else if (!strncmp(buf, "test_force_enable", 17))
  381. testmode = TEST_FORCE_EN;
  382. else
  383. testmode = 0;
  384. spin_lock_irqsave(&dwc->lock, flags);
  385. dwc3_gadget_set_test_mode(dwc, testmode);
  386. spin_unlock_irqrestore(&dwc->lock, flags);
  387. return count;
  388. }
  389. static const struct file_operations dwc3_testmode_fops = {
  390. .open = dwc3_testmode_open,
  391. .write = dwc3_testmode_write,
  392. .read = seq_read,
  393. .llseek = seq_lseek,
  394. .release = single_release,
  395. };
  396. static int dwc3_link_state_show(struct seq_file *s, void *unused)
  397. {
  398. struct dwc3 *dwc = s->private;
  399. unsigned long flags;
  400. enum dwc3_link_state state;
  401. u32 reg;
  402. spin_lock_irqsave(&dwc->lock, flags);
  403. reg = dwc3_readl(dwc->regs, DWC3_DSTS);
  404. state = DWC3_DSTS_USBLNKST(reg);
  405. spin_unlock_irqrestore(&dwc->lock, flags);
  406. switch (state) {
  407. case DWC3_LINK_STATE_U0:
  408. seq_printf(s, "U0\n");
  409. break;
  410. case DWC3_LINK_STATE_U1:
  411. seq_printf(s, "U1\n");
  412. break;
  413. case DWC3_LINK_STATE_U2:
  414. seq_printf(s, "U2\n");
  415. break;
  416. case DWC3_LINK_STATE_U3:
  417. seq_printf(s, "U3\n");
  418. break;
  419. case DWC3_LINK_STATE_SS_DIS:
  420. seq_printf(s, "SS.Disabled\n");
  421. break;
  422. case DWC3_LINK_STATE_RX_DET:
  423. seq_printf(s, "Rx.Detect\n");
  424. break;
  425. case DWC3_LINK_STATE_SS_INACT:
  426. seq_printf(s, "SS.Inactive\n");
  427. break;
  428. case DWC3_LINK_STATE_POLL:
  429. seq_printf(s, "Poll\n");
  430. break;
  431. case DWC3_LINK_STATE_RECOV:
  432. seq_printf(s, "Recovery\n");
  433. break;
  434. case DWC3_LINK_STATE_HRESET:
  435. seq_printf(s, "HRESET\n");
  436. break;
  437. case DWC3_LINK_STATE_CMPLY:
  438. seq_printf(s, "Compliance\n");
  439. break;
  440. case DWC3_LINK_STATE_LPBK:
  441. seq_printf(s, "Loopback\n");
  442. break;
  443. case DWC3_LINK_STATE_RESET:
  444. seq_printf(s, "Reset\n");
  445. break;
  446. case DWC3_LINK_STATE_RESUME:
  447. seq_printf(s, "Resume\n");
  448. break;
  449. default:
  450. seq_printf(s, "UNKNOWN %d\n", state);
  451. }
  452. return 0;
  453. }
  454. static int dwc3_link_state_open(struct inode *inode, struct file *file)
  455. {
  456. return single_open(file, dwc3_link_state_show, inode->i_private);
  457. }
  458. static ssize_t dwc3_link_state_write(struct file *file,
  459. const char __user *ubuf, size_t count, loff_t *ppos)
  460. {
  461. struct seq_file *s = file->private_data;
  462. struct dwc3 *dwc = s->private;
  463. unsigned long flags;
  464. enum dwc3_link_state state = 0;
  465. char buf[32];
  466. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  467. return -EFAULT;
  468. if (!strncmp(buf, "SS.Disabled", 11))
  469. state = DWC3_LINK_STATE_SS_DIS;
  470. else if (!strncmp(buf, "Rx.Detect", 9))
  471. state = DWC3_LINK_STATE_RX_DET;
  472. else if (!strncmp(buf, "SS.Inactive", 11))
  473. state = DWC3_LINK_STATE_SS_INACT;
  474. else if (!strncmp(buf, "Recovery", 8))
  475. state = DWC3_LINK_STATE_RECOV;
  476. else if (!strncmp(buf, "Compliance", 10))
  477. state = DWC3_LINK_STATE_CMPLY;
  478. else if (!strncmp(buf, "Loopback", 8))
  479. state = DWC3_LINK_STATE_LPBK;
  480. else
  481. return -EINVAL;
  482. spin_lock_irqsave(&dwc->lock, flags);
  483. dwc3_gadget_set_link_state(dwc, state);
  484. spin_unlock_irqrestore(&dwc->lock, flags);
  485. return count;
  486. }
  487. static const struct file_operations dwc3_link_state_fops = {
  488. .open = dwc3_link_state_open,
  489. .write = dwc3_link_state_write,
  490. .read = seq_read,
  491. .llseek = seq_lseek,
  492. .release = single_release,
  493. };
  494. struct dwc3_ep_file_map {
  495. char name[25];
  496. int (*show)(struct seq_file *s, void *unused);
  497. };
  498. static int dwc3_tx_fifo_queue_show(struct seq_file *s, void *unused)
  499. {
  500. struct dwc3_ep *dep = s->private;
  501. struct dwc3 *dwc = dep->dwc;
  502. unsigned long flags;
  503. u32 val;
  504. spin_lock_irqsave(&dwc->lock, flags);
  505. val = dwc3_core_fifo_space(dep, DWC3_TXFIFOQ);
  506. seq_printf(s, "%u\n", val);
  507. spin_unlock_irqrestore(&dwc->lock, flags);
  508. return 0;
  509. }
  510. static int dwc3_rx_fifo_queue_show(struct seq_file *s, void *unused)
  511. {
  512. struct dwc3_ep *dep = s->private;
  513. struct dwc3 *dwc = dep->dwc;
  514. unsigned long flags;
  515. u32 val;
  516. spin_lock_irqsave(&dwc->lock, flags);
  517. val = dwc3_core_fifo_space(dep, DWC3_RXFIFOQ);
  518. seq_printf(s, "%u\n", val);
  519. spin_unlock_irqrestore(&dwc->lock, flags);
  520. return 0;
  521. }
  522. static int dwc3_tx_request_queue_show(struct seq_file *s, void *unused)
  523. {
  524. struct dwc3_ep *dep = s->private;
  525. struct dwc3 *dwc = dep->dwc;
  526. unsigned long flags;
  527. u32 val;
  528. spin_lock_irqsave(&dwc->lock, flags);
  529. val = dwc3_core_fifo_space(dep, DWC3_TXREQQ);
  530. seq_printf(s, "%u\n", val);
  531. spin_unlock_irqrestore(&dwc->lock, flags);
  532. return 0;
  533. }
  534. static int dwc3_rx_request_queue_show(struct seq_file *s, void *unused)
  535. {
  536. struct dwc3_ep *dep = s->private;
  537. struct dwc3 *dwc = dep->dwc;
  538. unsigned long flags;
  539. u32 val;
  540. spin_lock_irqsave(&dwc->lock, flags);
  541. val = dwc3_core_fifo_space(dep, DWC3_RXREQQ);
  542. seq_printf(s, "%u\n", val);
  543. spin_unlock_irqrestore(&dwc->lock, flags);
  544. return 0;
  545. }
  546. static int dwc3_rx_info_queue_show(struct seq_file *s, void *unused)
  547. {
  548. struct dwc3_ep *dep = s->private;
  549. struct dwc3 *dwc = dep->dwc;
  550. unsigned long flags;
  551. u32 val;
  552. spin_lock_irqsave(&dwc->lock, flags);
  553. val = dwc3_core_fifo_space(dep, DWC3_RXINFOQ);
  554. seq_printf(s, "%u\n", val);
  555. spin_unlock_irqrestore(&dwc->lock, flags);
  556. return 0;
  557. }
  558. static int dwc3_descriptor_fetch_queue_show(struct seq_file *s, void *unused)
  559. {
  560. struct dwc3_ep *dep = s->private;
  561. struct dwc3 *dwc = dep->dwc;
  562. unsigned long flags;
  563. u32 val;
  564. spin_lock_irqsave(&dwc->lock, flags);
  565. val = dwc3_core_fifo_space(dep, DWC3_DESCFETCHQ);
  566. seq_printf(s, "%u\n", val);
  567. spin_unlock_irqrestore(&dwc->lock, flags);
  568. return 0;
  569. }
  570. static int dwc3_event_queue_show(struct seq_file *s, void *unused)
  571. {
  572. struct dwc3_ep *dep = s->private;
  573. struct dwc3 *dwc = dep->dwc;
  574. unsigned long flags;
  575. u32 val;
  576. spin_lock_irqsave(&dwc->lock, flags);
  577. val = dwc3_core_fifo_space(dep, DWC3_EVENTQ);
  578. seq_printf(s, "%u\n", val);
  579. spin_unlock_irqrestore(&dwc->lock, flags);
  580. return 0;
  581. }
  582. static int dwc3_ep_transfer_type_show(struct seq_file *s, void *unused)
  583. {
  584. struct dwc3_ep *dep = s->private;
  585. struct dwc3 *dwc = dep->dwc;
  586. unsigned long flags;
  587. spin_lock_irqsave(&dwc->lock, flags);
  588. if (!(dep->flags & DWC3_EP_ENABLED) ||
  589. !dep->endpoint.desc) {
  590. seq_printf(s, "--\n");
  591. goto out;
  592. }
  593. switch (usb_endpoint_type(dep->endpoint.desc)) {
  594. case USB_ENDPOINT_XFER_CONTROL:
  595. seq_printf(s, "control\n");
  596. break;
  597. case USB_ENDPOINT_XFER_ISOC:
  598. seq_printf(s, "isochronous\n");
  599. break;
  600. case USB_ENDPOINT_XFER_BULK:
  601. seq_printf(s, "bulk\n");
  602. break;
  603. case USB_ENDPOINT_XFER_INT:
  604. seq_printf(s, "interrupt\n");
  605. break;
  606. default:
  607. seq_printf(s, "--\n");
  608. }
  609. out:
  610. spin_unlock_irqrestore(&dwc->lock, flags);
  611. return 0;
  612. }
  613. static inline const char *dwc3_trb_type_string(struct dwc3_trb *trb)
  614. {
  615. switch (DWC3_TRBCTL_TYPE(trb->ctrl)) {
  616. case DWC3_TRBCTL_NORMAL:
  617. return "normal";
  618. case DWC3_TRBCTL_CONTROL_SETUP:
  619. return "control-setup";
  620. case DWC3_TRBCTL_CONTROL_STATUS2:
  621. return "control-status2";
  622. case DWC3_TRBCTL_CONTROL_STATUS3:
  623. return "control-status3";
  624. case DWC3_TRBCTL_CONTROL_DATA:
  625. return "control-data";
  626. case DWC3_TRBCTL_ISOCHRONOUS_FIRST:
  627. return "isoc-first";
  628. case DWC3_TRBCTL_ISOCHRONOUS:
  629. return "isoc";
  630. case DWC3_TRBCTL_LINK_TRB:
  631. return "link";
  632. default:
  633. return "UNKNOWN";
  634. }
  635. }
  636. static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused)
  637. {
  638. struct dwc3_ep *dep = s->private;
  639. struct dwc3 *dwc = dep->dwc;
  640. unsigned long flags;
  641. int i;
  642. spin_lock_irqsave(&dwc->lock, flags);
  643. if (dep->number <= 1) {
  644. seq_printf(s, "--\n");
  645. goto out;
  646. }
  647. seq_printf(s, "enqueue pointer %d\n", dep->trb_enqueue);
  648. seq_printf(s, "dequeue pointer %d\n", dep->trb_dequeue);
  649. seq_printf(s, "\n--------------------------------------------------\n\n");
  650. seq_printf(s, "buffer_addr,size,type,ioc,isp_imi,csp,chn,lst,hwo\n");
  651. for (i = 0; i < DWC3_TRB_NUM; i++) {
  652. struct dwc3_trb *trb = &dep->trb_pool[i];
  653. seq_printf(s, "%08x%08x,%d,%s,%d,%d,%d,%d,%d,%d\n",
  654. trb->bph, trb->bpl, trb->size,
  655. dwc3_trb_type_string(trb),
  656. !!(trb->ctrl & DWC3_TRB_CTRL_IOC),
  657. !!(trb->ctrl & DWC3_TRB_CTRL_ISP_IMI),
  658. !!(trb->ctrl & DWC3_TRB_CTRL_CSP),
  659. !!(trb->ctrl & DWC3_TRB_CTRL_CHN),
  660. !!(trb->ctrl & DWC3_TRB_CTRL_LST),
  661. !!(trb->ctrl & DWC3_TRB_CTRL_HWO));
  662. }
  663. out:
  664. spin_unlock_irqrestore(&dwc->lock, flags);
  665. return 0;
  666. }
  667. static struct dwc3_ep_file_map map[] = {
  668. { "tx_fifo_queue", dwc3_tx_fifo_queue_show, },
  669. { "rx_fifo_queue", dwc3_rx_fifo_queue_show, },
  670. { "tx_request_queue", dwc3_tx_request_queue_show, },
  671. { "rx_request_queue", dwc3_rx_request_queue_show, },
  672. { "rx_info_queue", dwc3_rx_info_queue_show, },
  673. { "descriptor_fetch_queue", dwc3_descriptor_fetch_queue_show, },
  674. { "event_queue", dwc3_event_queue_show, },
  675. { "transfer_type", dwc3_ep_transfer_type_show, },
  676. { "trb_ring", dwc3_ep_trb_ring_show, },
  677. };
  678. static int dwc3_endpoint_open(struct inode *inode, struct file *file)
  679. {
  680. const char *file_name = file_dentry(file)->d_iname;
  681. struct dwc3_ep_file_map *f_map;
  682. int i;
  683. for (i = 0; i < ARRAY_SIZE(map); i++) {
  684. f_map = &map[i];
  685. if (strcmp(f_map->name, file_name) == 0)
  686. break;
  687. }
  688. return single_open(file, f_map->show, inode->i_private);
  689. }
  690. static const struct file_operations dwc3_endpoint_fops = {
  691. .open = dwc3_endpoint_open,
  692. .read = seq_read,
  693. .llseek = seq_lseek,
  694. .release = single_release,
  695. };
  696. static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep *dep,
  697. struct dentry *parent, int type)
  698. {
  699. struct dentry *file;
  700. struct dwc3_ep_file_map *ep_file = &map[type];
  701. file = debugfs_create_file(ep_file->name, S_IRUGO, parent, dep,
  702. &dwc3_endpoint_fops);
  703. }
  704. static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
  705. struct dentry *parent)
  706. {
  707. int i;
  708. for (i = 0; i < ARRAY_SIZE(map); i++)
  709. dwc3_debugfs_create_endpoint_file(dep, parent, i);
  710. }
  711. static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep,
  712. struct dentry *parent)
  713. {
  714. struct dentry *dir;
  715. dir = debugfs_create_dir(dep->name, parent);
  716. if (IS_ERR_OR_NULL(dir))
  717. return;
  718. dwc3_debugfs_create_endpoint_files(dep, dir);
  719. }
  720. static void dwc3_debugfs_create_endpoint_dirs(struct dwc3 *dwc,
  721. struct dentry *parent)
  722. {
  723. int i;
  724. for (i = 0; i < dwc->num_in_eps; i++) {
  725. u8 epnum = (i << 1) | 1;
  726. struct dwc3_ep *dep = dwc->eps[epnum];
  727. if (!dep)
  728. continue;
  729. dwc3_debugfs_create_endpoint_dir(dep, parent);
  730. }
  731. for (i = 0; i < dwc->num_out_eps; i++) {
  732. u8 epnum = (i << 1);
  733. struct dwc3_ep *dep = dwc->eps[epnum];
  734. if (!dep)
  735. continue;
  736. dwc3_debugfs_create_endpoint_dir(dep, parent);
  737. }
  738. }
  739. void dwc3_debugfs_init(struct dwc3 *dwc)
  740. {
  741. struct dentry *root;
  742. struct dentry *file;
  743. root = debugfs_create_dir(dev_name(dwc->dev), NULL);
  744. if (IS_ERR_OR_NULL(root)) {
  745. if (!root)
  746. dev_err(dwc->dev, "Can't create debugfs root\n");
  747. return;
  748. }
  749. dwc->root = root;
  750. dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
  751. if (!dwc->regset) {
  752. debugfs_remove_recursive(root);
  753. return;
  754. }
  755. dwc->regset->regs = dwc3_regs;
  756. dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
  757. dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START;
  758. file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
  759. if (!file)
  760. dev_dbg(dwc->dev, "Can't create debugfs regdump\n");
  761. if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
  762. file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
  763. dwc, &dwc3_mode_fops);
  764. if (!file)
  765. dev_dbg(dwc->dev, "Can't create debugfs mode\n");
  766. }
  767. if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
  768. IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
  769. file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
  770. dwc, &dwc3_testmode_fops);
  771. if (!file)
  772. dev_dbg(dwc->dev, "Can't create debugfs testmode\n");
  773. file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR,
  774. root, dwc, &dwc3_link_state_fops);
  775. if (!file)
  776. dev_dbg(dwc->dev, "Can't create debugfs link_state\n");
  777. dwc3_debugfs_create_endpoint_dirs(dwc, root);
  778. }
  779. }
  780. void dwc3_debugfs_exit(struct dwc3 *dwc)
  781. {
  782. debugfs_remove_recursive(dwc->root);
  783. kfree(dwc->regset);
  784. }