debugfs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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 - DWC3_GLOBALS_REGS_START, \
  36. }
  37. static const struct debugfs_reg32 dwc3_regs[] = {
  38. dump_register(GSBUSCFG0),
  39. dump_register(GSBUSCFG1),
  40. dump_register(GTXTHRCFG),
  41. dump_register(GRXTHRCFG),
  42. dump_register(GCTL),
  43. dump_register(GEVTEN),
  44. dump_register(GSTS),
  45. dump_register(GSNPSID),
  46. dump_register(GGPIO),
  47. dump_register(GUID),
  48. dump_register(GUCTL),
  49. dump_register(GBUSERRADDR0),
  50. dump_register(GBUSERRADDR1),
  51. dump_register(GPRTBIMAP0),
  52. dump_register(GPRTBIMAP1),
  53. dump_register(GHWPARAMS0),
  54. dump_register(GHWPARAMS1),
  55. dump_register(GHWPARAMS2),
  56. dump_register(GHWPARAMS3),
  57. dump_register(GHWPARAMS4),
  58. dump_register(GHWPARAMS5),
  59. dump_register(GHWPARAMS6),
  60. dump_register(GHWPARAMS7),
  61. dump_register(GDBGFIFOSPACE),
  62. dump_register(GDBGLTSSM),
  63. dump_register(GPRTBIMAP_HS0),
  64. dump_register(GPRTBIMAP_HS1),
  65. dump_register(GPRTBIMAP_FS0),
  66. dump_register(GPRTBIMAP_FS1),
  67. dump_register(GUSB2PHYCFG(0)),
  68. dump_register(GUSB2PHYCFG(1)),
  69. dump_register(GUSB2PHYCFG(2)),
  70. dump_register(GUSB2PHYCFG(3)),
  71. dump_register(GUSB2PHYCFG(4)),
  72. dump_register(GUSB2PHYCFG(5)),
  73. dump_register(GUSB2PHYCFG(6)),
  74. dump_register(GUSB2PHYCFG(7)),
  75. dump_register(GUSB2PHYCFG(8)),
  76. dump_register(GUSB2PHYCFG(9)),
  77. dump_register(GUSB2PHYCFG(10)),
  78. dump_register(GUSB2PHYCFG(11)),
  79. dump_register(GUSB2PHYCFG(12)),
  80. dump_register(GUSB2PHYCFG(13)),
  81. dump_register(GUSB2PHYCFG(14)),
  82. dump_register(GUSB2PHYCFG(15)),
  83. dump_register(GUSB2I2CCTL(0)),
  84. dump_register(GUSB2I2CCTL(1)),
  85. dump_register(GUSB2I2CCTL(2)),
  86. dump_register(GUSB2I2CCTL(3)),
  87. dump_register(GUSB2I2CCTL(4)),
  88. dump_register(GUSB2I2CCTL(5)),
  89. dump_register(GUSB2I2CCTL(6)),
  90. dump_register(GUSB2I2CCTL(7)),
  91. dump_register(GUSB2I2CCTL(8)),
  92. dump_register(GUSB2I2CCTL(9)),
  93. dump_register(GUSB2I2CCTL(10)),
  94. dump_register(GUSB2I2CCTL(11)),
  95. dump_register(GUSB2I2CCTL(12)),
  96. dump_register(GUSB2I2CCTL(13)),
  97. dump_register(GUSB2I2CCTL(14)),
  98. dump_register(GUSB2I2CCTL(15)),
  99. dump_register(GUSB2PHYACC(0)),
  100. dump_register(GUSB2PHYACC(1)),
  101. dump_register(GUSB2PHYACC(2)),
  102. dump_register(GUSB2PHYACC(3)),
  103. dump_register(GUSB2PHYACC(4)),
  104. dump_register(GUSB2PHYACC(5)),
  105. dump_register(GUSB2PHYACC(6)),
  106. dump_register(GUSB2PHYACC(7)),
  107. dump_register(GUSB2PHYACC(8)),
  108. dump_register(GUSB2PHYACC(9)),
  109. dump_register(GUSB2PHYACC(10)),
  110. dump_register(GUSB2PHYACC(11)),
  111. dump_register(GUSB2PHYACC(12)),
  112. dump_register(GUSB2PHYACC(13)),
  113. dump_register(GUSB2PHYACC(14)),
  114. dump_register(GUSB2PHYACC(15)),
  115. dump_register(GUSB3PIPECTL(0)),
  116. dump_register(GUSB3PIPECTL(1)),
  117. dump_register(GUSB3PIPECTL(2)),
  118. dump_register(GUSB3PIPECTL(3)),
  119. dump_register(GUSB3PIPECTL(4)),
  120. dump_register(GUSB3PIPECTL(5)),
  121. dump_register(GUSB3PIPECTL(6)),
  122. dump_register(GUSB3PIPECTL(7)),
  123. dump_register(GUSB3PIPECTL(8)),
  124. dump_register(GUSB3PIPECTL(9)),
  125. dump_register(GUSB3PIPECTL(10)),
  126. dump_register(GUSB3PIPECTL(11)),
  127. dump_register(GUSB3PIPECTL(12)),
  128. dump_register(GUSB3PIPECTL(13)),
  129. dump_register(GUSB3PIPECTL(14)),
  130. dump_register(GUSB3PIPECTL(15)),
  131. dump_register(GTXFIFOSIZ(0)),
  132. dump_register(GTXFIFOSIZ(1)),
  133. dump_register(GTXFIFOSIZ(2)),
  134. dump_register(GTXFIFOSIZ(3)),
  135. dump_register(GTXFIFOSIZ(4)),
  136. dump_register(GTXFIFOSIZ(5)),
  137. dump_register(GTXFIFOSIZ(6)),
  138. dump_register(GTXFIFOSIZ(7)),
  139. dump_register(GTXFIFOSIZ(8)),
  140. dump_register(GTXFIFOSIZ(9)),
  141. dump_register(GTXFIFOSIZ(10)),
  142. dump_register(GTXFIFOSIZ(11)),
  143. dump_register(GTXFIFOSIZ(12)),
  144. dump_register(GTXFIFOSIZ(13)),
  145. dump_register(GTXFIFOSIZ(14)),
  146. dump_register(GTXFIFOSIZ(15)),
  147. dump_register(GTXFIFOSIZ(16)),
  148. dump_register(GTXFIFOSIZ(17)),
  149. dump_register(GTXFIFOSIZ(18)),
  150. dump_register(GTXFIFOSIZ(19)),
  151. dump_register(GTXFIFOSIZ(20)),
  152. dump_register(GTXFIFOSIZ(21)),
  153. dump_register(GTXFIFOSIZ(22)),
  154. dump_register(GTXFIFOSIZ(23)),
  155. dump_register(GTXFIFOSIZ(24)),
  156. dump_register(GTXFIFOSIZ(25)),
  157. dump_register(GTXFIFOSIZ(26)),
  158. dump_register(GTXFIFOSIZ(27)),
  159. dump_register(GTXFIFOSIZ(28)),
  160. dump_register(GTXFIFOSIZ(29)),
  161. dump_register(GTXFIFOSIZ(30)),
  162. dump_register(GTXFIFOSIZ(31)),
  163. dump_register(GRXFIFOSIZ(0)),
  164. dump_register(GRXFIFOSIZ(1)),
  165. dump_register(GRXFIFOSIZ(2)),
  166. dump_register(GRXFIFOSIZ(3)),
  167. dump_register(GRXFIFOSIZ(4)),
  168. dump_register(GRXFIFOSIZ(5)),
  169. dump_register(GRXFIFOSIZ(6)),
  170. dump_register(GRXFIFOSIZ(7)),
  171. dump_register(GRXFIFOSIZ(8)),
  172. dump_register(GRXFIFOSIZ(9)),
  173. dump_register(GRXFIFOSIZ(10)),
  174. dump_register(GRXFIFOSIZ(11)),
  175. dump_register(GRXFIFOSIZ(12)),
  176. dump_register(GRXFIFOSIZ(13)),
  177. dump_register(GRXFIFOSIZ(14)),
  178. dump_register(GRXFIFOSIZ(15)),
  179. dump_register(GRXFIFOSIZ(16)),
  180. dump_register(GRXFIFOSIZ(17)),
  181. dump_register(GRXFIFOSIZ(18)),
  182. dump_register(GRXFIFOSIZ(19)),
  183. dump_register(GRXFIFOSIZ(20)),
  184. dump_register(GRXFIFOSIZ(21)),
  185. dump_register(GRXFIFOSIZ(22)),
  186. dump_register(GRXFIFOSIZ(23)),
  187. dump_register(GRXFIFOSIZ(24)),
  188. dump_register(GRXFIFOSIZ(25)),
  189. dump_register(GRXFIFOSIZ(26)),
  190. dump_register(GRXFIFOSIZ(27)),
  191. dump_register(GRXFIFOSIZ(28)),
  192. dump_register(GRXFIFOSIZ(29)),
  193. dump_register(GRXFIFOSIZ(30)),
  194. dump_register(GRXFIFOSIZ(31)),
  195. dump_register(GEVNTADRLO(0)),
  196. dump_register(GEVNTADRHI(0)),
  197. dump_register(GEVNTSIZ(0)),
  198. dump_register(GEVNTCOUNT(0)),
  199. dump_register(GHWPARAMS8),
  200. dump_register(DCFG),
  201. dump_register(DCTL),
  202. dump_register(DEVTEN),
  203. dump_register(DSTS),
  204. dump_register(DGCMDPAR),
  205. dump_register(DGCMD),
  206. dump_register(DALEPENA),
  207. dump_register(DEPCMDPAR2(0)),
  208. dump_register(DEPCMDPAR2(1)),
  209. dump_register(DEPCMDPAR2(2)),
  210. dump_register(DEPCMDPAR2(3)),
  211. dump_register(DEPCMDPAR2(4)),
  212. dump_register(DEPCMDPAR2(5)),
  213. dump_register(DEPCMDPAR2(6)),
  214. dump_register(DEPCMDPAR2(7)),
  215. dump_register(DEPCMDPAR2(8)),
  216. dump_register(DEPCMDPAR2(9)),
  217. dump_register(DEPCMDPAR2(10)),
  218. dump_register(DEPCMDPAR2(11)),
  219. dump_register(DEPCMDPAR2(12)),
  220. dump_register(DEPCMDPAR2(13)),
  221. dump_register(DEPCMDPAR2(14)),
  222. dump_register(DEPCMDPAR2(15)),
  223. dump_register(DEPCMDPAR2(16)),
  224. dump_register(DEPCMDPAR2(17)),
  225. dump_register(DEPCMDPAR2(18)),
  226. dump_register(DEPCMDPAR2(19)),
  227. dump_register(DEPCMDPAR2(20)),
  228. dump_register(DEPCMDPAR2(21)),
  229. dump_register(DEPCMDPAR2(22)),
  230. dump_register(DEPCMDPAR2(23)),
  231. dump_register(DEPCMDPAR2(24)),
  232. dump_register(DEPCMDPAR2(25)),
  233. dump_register(DEPCMDPAR2(26)),
  234. dump_register(DEPCMDPAR2(27)),
  235. dump_register(DEPCMDPAR2(28)),
  236. dump_register(DEPCMDPAR2(29)),
  237. dump_register(DEPCMDPAR2(30)),
  238. dump_register(DEPCMDPAR2(31)),
  239. dump_register(DEPCMDPAR1(0)),
  240. dump_register(DEPCMDPAR1(1)),
  241. dump_register(DEPCMDPAR1(2)),
  242. dump_register(DEPCMDPAR1(3)),
  243. dump_register(DEPCMDPAR1(4)),
  244. dump_register(DEPCMDPAR1(5)),
  245. dump_register(DEPCMDPAR1(6)),
  246. dump_register(DEPCMDPAR1(7)),
  247. dump_register(DEPCMDPAR1(8)),
  248. dump_register(DEPCMDPAR1(9)),
  249. dump_register(DEPCMDPAR1(10)),
  250. dump_register(DEPCMDPAR1(11)),
  251. dump_register(DEPCMDPAR1(12)),
  252. dump_register(DEPCMDPAR1(13)),
  253. dump_register(DEPCMDPAR1(14)),
  254. dump_register(DEPCMDPAR1(15)),
  255. dump_register(DEPCMDPAR1(16)),
  256. dump_register(DEPCMDPAR1(17)),
  257. dump_register(DEPCMDPAR1(18)),
  258. dump_register(DEPCMDPAR1(19)),
  259. dump_register(DEPCMDPAR1(20)),
  260. dump_register(DEPCMDPAR1(21)),
  261. dump_register(DEPCMDPAR1(22)),
  262. dump_register(DEPCMDPAR1(23)),
  263. dump_register(DEPCMDPAR1(24)),
  264. dump_register(DEPCMDPAR1(25)),
  265. dump_register(DEPCMDPAR1(26)),
  266. dump_register(DEPCMDPAR1(27)),
  267. dump_register(DEPCMDPAR1(28)),
  268. dump_register(DEPCMDPAR1(29)),
  269. dump_register(DEPCMDPAR1(30)),
  270. dump_register(DEPCMDPAR1(31)),
  271. dump_register(DEPCMDPAR0(0)),
  272. dump_register(DEPCMDPAR0(1)),
  273. dump_register(DEPCMDPAR0(2)),
  274. dump_register(DEPCMDPAR0(3)),
  275. dump_register(DEPCMDPAR0(4)),
  276. dump_register(DEPCMDPAR0(5)),
  277. dump_register(DEPCMDPAR0(6)),
  278. dump_register(DEPCMDPAR0(7)),
  279. dump_register(DEPCMDPAR0(8)),
  280. dump_register(DEPCMDPAR0(9)),
  281. dump_register(DEPCMDPAR0(10)),
  282. dump_register(DEPCMDPAR0(11)),
  283. dump_register(DEPCMDPAR0(12)),
  284. dump_register(DEPCMDPAR0(13)),
  285. dump_register(DEPCMDPAR0(14)),
  286. dump_register(DEPCMDPAR0(15)),
  287. dump_register(DEPCMDPAR0(16)),
  288. dump_register(DEPCMDPAR0(17)),
  289. dump_register(DEPCMDPAR0(18)),
  290. dump_register(DEPCMDPAR0(19)),
  291. dump_register(DEPCMDPAR0(20)),
  292. dump_register(DEPCMDPAR0(21)),
  293. dump_register(DEPCMDPAR0(22)),
  294. dump_register(DEPCMDPAR0(23)),
  295. dump_register(DEPCMDPAR0(24)),
  296. dump_register(DEPCMDPAR0(25)),
  297. dump_register(DEPCMDPAR0(26)),
  298. dump_register(DEPCMDPAR0(27)),
  299. dump_register(DEPCMDPAR0(28)),
  300. dump_register(DEPCMDPAR0(29)),
  301. dump_register(DEPCMDPAR0(30)),
  302. dump_register(DEPCMDPAR0(31)),
  303. dump_register(DEPCMD(0)),
  304. dump_register(DEPCMD(1)),
  305. dump_register(DEPCMD(2)),
  306. dump_register(DEPCMD(3)),
  307. dump_register(DEPCMD(4)),
  308. dump_register(DEPCMD(5)),
  309. dump_register(DEPCMD(6)),
  310. dump_register(DEPCMD(7)),
  311. dump_register(DEPCMD(8)),
  312. dump_register(DEPCMD(9)),
  313. dump_register(DEPCMD(10)),
  314. dump_register(DEPCMD(11)),
  315. dump_register(DEPCMD(12)),
  316. dump_register(DEPCMD(13)),
  317. dump_register(DEPCMD(14)),
  318. dump_register(DEPCMD(15)),
  319. dump_register(DEPCMD(16)),
  320. dump_register(DEPCMD(17)),
  321. dump_register(DEPCMD(18)),
  322. dump_register(DEPCMD(19)),
  323. dump_register(DEPCMD(20)),
  324. dump_register(DEPCMD(21)),
  325. dump_register(DEPCMD(22)),
  326. dump_register(DEPCMD(23)),
  327. dump_register(DEPCMD(24)),
  328. dump_register(DEPCMD(25)),
  329. dump_register(DEPCMD(26)),
  330. dump_register(DEPCMD(27)),
  331. dump_register(DEPCMD(28)),
  332. dump_register(DEPCMD(29)),
  333. dump_register(DEPCMD(30)),
  334. dump_register(DEPCMD(31)),
  335. dump_register(OCFG),
  336. dump_register(OCTL),
  337. dump_register(OEVT),
  338. dump_register(OEVTEN),
  339. dump_register(OSTS),
  340. };
  341. static int dwc3_mode_show(struct seq_file *s, void *unused)
  342. {
  343. struct dwc3 *dwc = s->private;
  344. unsigned long flags;
  345. u32 reg;
  346. spin_lock_irqsave(&dwc->lock, flags);
  347. reg = dwc3_readl(dwc->regs, DWC3_GCTL);
  348. spin_unlock_irqrestore(&dwc->lock, flags);
  349. switch (DWC3_GCTL_PRTCAP(reg)) {
  350. case DWC3_GCTL_PRTCAP_HOST:
  351. seq_printf(s, "host\n");
  352. break;
  353. case DWC3_GCTL_PRTCAP_DEVICE:
  354. seq_printf(s, "device\n");
  355. break;
  356. case DWC3_GCTL_PRTCAP_OTG:
  357. seq_printf(s, "OTG\n");
  358. break;
  359. default:
  360. seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
  361. }
  362. return 0;
  363. }
  364. static int dwc3_mode_open(struct inode *inode, struct file *file)
  365. {
  366. return single_open(file, dwc3_mode_show, inode->i_private);
  367. }
  368. static ssize_t dwc3_mode_write(struct file *file,
  369. const char __user *ubuf, size_t count, loff_t *ppos)
  370. {
  371. struct seq_file *s = file->private_data;
  372. struct dwc3 *dwc = s->private;
  373. unsigned long flags;
  374. u32 mode = 0;
  375. char buf[32];
  376. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  377. return -EFAULT;
  378. if (!strncmp(buf, "host", 4))
  379. mode |= DWC3_GCTL_PRTCAP_HOST;
  380. if (!strncmp(buf, "device", 6))
  381. mode |= DWC3_GCTL_PRTCAP_DEVICE;
  382. if (!strncmp(buf, "otg", 3))
  383. mode |= DWC3_GCTL_PRTCAP_OTG;
  384. if (mode) {
  385. spin_lock_irqsave(&dwc->lock, flags);
  386. dwc3_set_mode(dwc, mode);
  387. spin_unlock_irqrestore(&dwc->lock, flags);
  388. }
  389. return count;
  390. }
  391. static const struct file_operations dwc3_mode_fops = {
  392. .open = dwc3_mode_open,
  393. .write = dwc3_mode_write,
  394. .read = seq_read,
  395. .llseek = seq_lseek,
  396. .release = single_release,
  397. };
  398. static int dwc3_testmode_show(struct seq_file *s, void *unused)
  399. {
  400. struct dwc3 *dwc = s->private;
  401. unsigned long flags;
  402. u32 reg;
  403. spin_lock_irqsave(&dwc->lock, flags);
  404. reg = dwc3_readl(dwc->regs, DWC3_DCTL);
  405. reg &= DWC3_DCTL_TSTCTRL_MASK;
  406. reg >>= 1;
  407. spin_unlock_irqrestore(&dwc->lock, flags);
  408. switch (reg) {
  409. case 0:
  410. seq_printf(s, "no test\n");
  411. break;
  412. case TEST_J:
  413. seq_printf(s, "test_j\n");
  414. break;
  415. case TEST_K:
  416. seq_printf(s, "test_k\n");
  417. break;
  418. case TEST_SE0_NAK:
  419. seq_printf(s, "test_se0_nak\n");
  420. break;
  421. case TEST_PACKET:
  422. seq_printf(s, "test_packet\n");
  423. break;
  424. case TEST_FORCE_EN:
  425. seq_printf(s, "test_force_enable\n");
  426. break;
  427. default:
  428. seq_printf(s, "UNKNOWN %d\n", reg);
  429. }
  430. return 0;
  431. }
  432. static int dwc3_testmode_open(struct inode *inode, struct file *file)
  433. {
  434. return single_open(file, dwc3_testmode_show, inode->i_private);
  435. }
  436. static ssize_t dwc3_testmode_write(struct file *file,
  437. const char __user *ubuf, size_t count, loff_t *ppos)
  438. {
  439. struct seq_file *s = file->private_data;
  440. struct dwc3 *dwc = s->private;
  441. unsigned long flags;
  442. u32 testmode = 0;
  443. char buf[32];
  444. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  445. return -EFAULT;
  446. if (!strncmp(buf, "test_j", 6))
  447. testmode = TEST_J;
  448. else if (!strncmp(buf, "test_k", 6))
  449. testmode = TEST_K;
  450. else if (!strncmp(buf, "test_se0_nak", 12))
  451. testmode = TEST_SE0_NAK;
  452. else if (!strncmp(buf, "test_packet", 11))
  453. testmode = TEST_PACKET;
  454. else if (!strncmp(buf, "test_force_enable", 17))
  455. testmode = TEST_FORCE_EN;
  456. else
  457. testmode = 0;
  458. spin_lock_irqsave(&dwc->lock, flags);
  459. dwc3_gadget_set_test_mode(dwc, testmode);
  460. spin_unlock_irqrestore(&dwc->lock, flags);
  461. return count;
  462. }
  463. static const struct file_operations dwc3_testmode_fops = {
  464. .open = dwc3_testmode_open,
  465. .write = dwc3_testmode_write,
  466. .read = seq_read,
  467. .llseek = seq_lseek,
  468. .release = single_release,
  469. };
  470. static int dwc3_link_state_show(struct seq_file *s, void *unused)
  471. {
  472. struct dwc3 *dwc = s->private;
  473. unsigned long flags;
  474. enum dwc3_link_state state;
  475. u32 reg;
  476. spin_lock_irqsave(&dwc->lock, flags);
  477. reg = dwc3_readl(dwc->regs, DWC3_DSTS);
  478. state = DWC3_DSTS_USBLNKST(reg);
  479. spin_unlock_irqrestore(&dwc->lock, flags);
  480. switch (state) {
  481. case DWC3_LINK_STATE_U0:
  482. seq_printf(s, "U0\n");
  483. break;
  484. case DWC3_LINK_STATE_U1:
  485. seq_printf(s, "U1\n");
  486. break;
  487. case DWC3_LINK_STATE_U2:
  488. seq_printf(s, "U2\n");
  489. break;
  490. case DWC3_LINK_STATE_U3:
  491. seq_printf(s, "U3\n");
  492. break;
  493. case DWC3_LINK_STATE_SS_DIS:
  494. seq_printf(s, "SS.Disabled\n");
  495. break;
  496. case DWC3_LINK_STATE_RX_DET:
  497. seq_printf(s, "Rx.Detect\n");
  498. break;
  499. case DWC3_LINK_STATE_SS_INACT:
  500. seq_printf(s, "SS.Inactive\n");
  501. break;
  502. case DWC3_LINK_STATE_POLL:
  503. seq_printf(s, "Poll\n");
  504. break;
  505. case DWC3_LINK_STATE_RECOV:
  506. seq_printf(s, "Recovery\n");
  507. break;
  508. case DWC3_LINK_STATE_HRESET:
  509. seq_printf(s, "HRESET\n");
  510. break;
  511. case DWC3_LINK_STATE_CMPLY:
  512. seq_printf(s, "Compliance\n");
  513. break;
  514. case DWC3_LINK_STATE_LPBK:
  515. seq_printf(s, "Loopback\n");
  516. break;
  517. case DWC3_LINK_STATE_RESET:
  518. seq_printf(s, "Reset\n");
  519. break;
  520. case DWC3_LINK_STATE_RESUME:
  521. seq_printf(s, "Resume\n");
  522. break;
  523. default:
  524. seq_printf(s, "UNKNOWN %d\n", state);
  525. }
  526. return 0;
  527. }
  528. static int dwc3_link_state_open(struct inode *inode, struct file *file)
  529. {
  530. return single_open(file, dwc3_link_state_show, inode->i_private);
  531. }
  532. static ssize_t dwc3_link_state_write(struct file *file,
  533. const char __user *ubuf, size_t count, loff_t *ppos)
  534. {
  535. struct seq_file *s = file->private_data;
  536. struct dwc3 *dwc = s->private;
  537. unsigned long flags;
  538. enum dwc3_link_state state = 0;
  539. char buf[32];
  540. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  541. return -EFAULT;
  542. if (!strncmp(buf, "SS.Disabled", 11))
  543. state = DWC3_LINK_STATE_SS_DIS;
  544. else if (!strncmp(buf, "Rx.Detect", 9))
  545. state = DWC3_LINK_STATE_RX_DET;
  546. else if (!strncmp(buf, "SS.Inactive", 11))
  547. state = DWC3_LINK_STATE_SS_INACT;
  548. else if (!strncmp(buf, "Recovery", 8))
  549. state = DWC3_LINK_STATE_RECOV;
  550. else if (!strncmp(buf, "Compliance", 10))
  551. state = DWC3_LINK_STATE_CMPLY;
  552. else if (!strncmp(buf, "Loopback", 8))
  553. state = DWC3_LINK_STATE_LPBK;
  554. else
  555. return -EINVAL;
  556. spin_lock_irqsave(&dwc->lock, flags);
  557. dwc3_gadget_set_link_state(dwc, state);
  558. spin_unlock_irqrestore(&dwc->lock, flags);
  559. return count;
  560. }
  561. static const struct file_operations dwc3_link_state_fops = {
  562. .open = dwc3_link_state_open,
  563. .write = dwc3_link_state_write,
  564. .read = seq_read,
  565. .llseek = seq_lseek,
  566. .release = single_release,
  567. };
  568. int dwc3_debugfs_init(struct dwc3 *dwc)
  569. {
  570. struct dentry *root;
  571. struct dentry *file;
  572. int ret;
  573. root = debugfs_create_dir(dev_name(dwc->dev), NULL);
  574. if (!root) {
  575. ret = -ENOMEM;
  576. goto err0;
  577. }
  578. dwc->root = root;
  579. dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
  580. if (!dwc->regset) {
  581. ret = -ENOMEM;
  582. goto err1;
  583. }
  584. dwc->regset->regs = dwc3_regs;
  585. dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
  586. dwc->regset->base = dwc->regs;
  587. file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
  588. if (!file) {
  589. ret = -ENOMEM;
  590. goto err1;
  591. }
  592. if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
  593. file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
  594. dwc, &dwc3_mode_fops);
  595. if (!file) {
  596. ret = -ENOMEM;
  597. goto err1;
  598. }
  599. }
  600. if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
  601. IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
  602. file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
  603. dwc, &dwc3_testmode_fops);
  604. if (!file) {
  605. ret = -ENOMEM;
  606. goto err1;
  607. }
  608. file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
  609. dwc, &dwc3_link_state_fops);
  610. if (!file) {
  611. ret = -ENOMEM;
  612. goto err1;
  613. }
  614. }
  615. return 0;
  616. err1:
  617. debugfs_remove_recursive(root);
  618. err0:
  619. return ret;
  620. }
  621. void dwc3_debugfs_exit(struct dwc3 *dwc)
  622. {
  623. debugfs_remove_recursive(dwc->root);
  624. dwc->root = NULL;
  625. }