usb20_phy_debugfs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/debugfs.h>
  5. #include <linux/seq_file.h>
  6. #include <asm/uaccess.h>
  7. #include "musb_core.h"
  8. #include "mtk-phy.h"
  9. #define USBPHY_READ8(offset) U3PhyReadReg8((u3phy_addr_t)u3_sif2_base+0x800+offset)
  10. #define USBPHY_WRITE8(offset, value) U3PhyWriteReg8((u3phy_addr_t)u3_sif2_base+0x800+offset, value)
  11. #define USBPHY_SET8(offset, mask) \
  12. U3PhyWriteReg8((u3phy_addr_t)u3_sif2_base+0x800+offset, U3PhyReadReg8((u3phy_addr_t)u3_sif2_base+0x800+offset)|(mask))
  13. #define USBPHY_CLR8(offset, mask) \
  14. U3PhyWriteReg8((u3phy_addr_t)u3_sif2_base+0x800+offset, U3PhyReadReg8((u3phy_addr_t)u3_sif2_base+0x800+offset)&(~mask))
  15. #define MYDBG(fmt, args...) pr_warn("MTK_ICUSB [DBG], <%s(), %d> " fmt, __func__, __LINE__, ## args)
  16. /* general */
  17. #define BIT_WIDTH_1 1
  18. #define MSK_WIDTH_1 0x1
  19. #define VAL_MAX_WDITH_1 0x1
  20. #define VAL_0_WIDTH_1 0x0
  21. #define VAL_1_WIDTH_1 0x1
  22. #define STRNG_0_WIDTH_1 "0"
  23. #define STRNG_1_WIDTH_1 "1"
  24. #define BIT_WIDTH_3 3
  25. #define MSK_WIDTH_3 0x7
  26. #define VAL_MAX_WDITH_3 0x7
  27. #define VAL_0_WIDTH_3 0x0
  28. #define VAL_1_WIDTH_3 0x1
  29. #define VAL_2_WIDTH_3 0x2
  30. #define VAL_3_WIDTH_3 0x3
  31. #define VAL_4_WIDTH_3 0x4
  32. #define VAL_5_WIDTH_3 0x5
  33. #define VAL_6_WIDTH_3 0x6
  34. #define VAL_7_WIDTH_3 0x7
  35. #define STRNG_0_WIDTH_3 "000"
  36. #define STRNG_1_WIDTH_3 "001"
  37. #define STRNG_2_WIDTH_3 "010"
  38. #define STRNG_3_WIDTH_3 "011"
  39. #define STRNG_4_WIDTH_3 "100"
  40. #define STRNG_5_WIDTH_3 "101"
  41. #define STRNG_6_WIDTH_3 "110"
  42. #define STRNG_7_WIDTH_3 "111"
  43. /* specific */
  44. #define FILE_USB_DRIVING_CAPABILITY "USB_DRIVING_CAPABILITY"
  45. #define FILE_RG_USB20_TERM_VREF_SEL "RG_USB20_TERM_VREF_SEL"
  46. #define MSK_RG_USB20_TERM_VREF_SEL MSK_WIDTH_3
  47. #define SHFT_RG_USB20_TERM_VREF_SEL 0
  48. #define OFFSET_RG_USB20_TERM_VREF_SEL 0x5
  49. #define FILE_RG_USB20_HSTX_SRCTRL "RG_USB20_HSTX_SRCTRL"
  50. #define MSK_RG_USB20_HSTX_SRCTRL MSK_WIDTH_3
  51. #define SHFT_RG_USB20_HSTX_SRCTRL 4
  52. #define OFFSET_RG_USB20_HSTX_SRCTRL 0x15
  53. #define FILE_RG_USB20_VRT_VREF_SEL "RG_USB20_VRT_VREF_SEL"
  54. #define MSK_RG_USB20_VRT_VREF_SEL MSK_WIDTH_3
  55. #define SHFT_RG_USB20_VRT_VREF_SEL 4
  56. #define OFFSET_RG_USB20_VRT_VREF_SEL 0x5
  57. #define FILE_RG_USB20_INTR_EN "RG_USB20_INTR_EN"
  58. #define MSK_RG_USB20_INTR_EN MSK_WIDTH_1
  59. #define SHFT_RG_USB20_INTR_EN 5
  60. #define OFFSET_RG_USB20_INTR_EN 0x0
  61. static struct dentry *usb20_phy_debugfs_root;
  62. void usb20_phy_debugfs_write_width1(u8 offset, u8 shift, char *buf)
  63. {
  64. u8 clr_val = 0, set_val = 0;
  65. MYDBG("s(%s)\n", buf);
  66. if (!strncmp(buf, STRNG_0_WIDTH_1, BIT_WIDTH_1)) {
  67. MYDBG("%s case\n", STRNG_0_WIDTH_1);
  68. clr_val = VAL_1_WIDTH_1;
  69. }
  70. if (!strncmp(buf, STRNG_1_WIDTH_1, BIT_WIDTH_1)) {
  71. MYDBG("%s case\n", STRNG_1_WIDTH_1);
  72. set_val = VAL_1_WIDTH_1;
  73. }
  74. if (clr_val || set_val) {
  75. clr_val = VAL_MAX_WDITH_1 - set_val;
  76. MYDBG("offset:%x, clr_val:%x, set_val:%x, before shft\n", offset, clr_val, set_val);
  77. clr_val <<= shift;
  78. set_val <<= shift;
  79. MYDBG("offset:%x, clr_val:%x, set_val:%x, after shft\n", offset, clr_val, set_val);
  80. USBPHY_CLR8(offset, clr_val);
  81. USBPHY_SET8(offset, set_val);
  82. } else {
  83. MYDBG("do nothing\n");
  84. }
  85. }
  86. void usb20_phy_debugfs_write_width3(u8 offset, u8 shift, char *buf)
  87. {
  88. u8 clr_val = 0, set_val = 0;
  89. MYDBG("s(%s)\n", buf);
  90. if (!strncmp(buf, STRNG_0_WIDTH_3, BIT_WIDTH_3)) {
  91. MYDBG("%s case\n", STRNG_0_WIDTH_3);
  92. clr_val = VAL_7_WIDTH_3;
  93. }
  94. if (!strncmp(buf, STRNG_1_WIDTH_3, BIT_WIDTH_3)) {
  95. MYDBG("%s case\n", STRNG_1_WIDTH_3);
  96. set_val = VAL_1_WIDTH_3;
  97. }
  98. if (!strncmp(buf, STRNG_2_WIDTH_3, BIT_WIDTH_3)) {
  99. MYDBG("%s case\n", STRNG_2_WIDTH_3);
  100. set_val = VAL_2_WIDTH_3;
  101. }
  102. if (!strncmp(buf, STRNG_3_WIDTH_3, BIT_WIDTH_3)) {
  103. MYDBG("%s case\n", STRNG_3_WIDTH_3);
  104. set_val = VAL_3_WIDTH_3;
  105. }
  106. if (!strncmp(buf, STRNG_4_WIDTH_3, BIT_WIDTH_3)) {
  107. MYDBG("%s case\n", STRNG_4_WIDTH_3);
  108. set_val = VAL_4_WIDTH_3;
  109. }
  110. if (!strncmp(buf, STRNG_5_WIDTH_3, BIT_WIDTH_3)) {
  111. MYDBG("%s case\n", STRNG_5_WIDTH_3);
  112. set_val = VAL_5_WIDTH_3;
  113. }
  114. if (!strncmp(buf, STRNG_6_WIDTH_3, BIT_WIDTH_3)) {
  115. MYDBG("%s case\n", STRNG_6_WIDTH_3);
  116. set_val = VAL_6_WIDTH_3;
  117. }
  118. if (!strncmp(buf, STRNG_7_WIDTH_3, BIT_WIDTH_3)) {
  119. MYDBG("%s case\n", STRNG_7_WIDTH_3);
  120. set_val = VAL_7_WIDTH_3;
  121. }
  122. /* HS_100U_U3_EN = 0x50 */
  123. USBPHY_WRITE8(0x15, 0x50);
  124. msleep(50);
  125. /* MYDBG("PHY Register 0x%x = 0x%x\n", 0x800+0x15, USBPHY_READ8(0x15)); */
  126. if (clr_val || set_val) {
  127. clr_val = VAL_MAX_WDITH_3 - set_val;
  128. MYDBG("offset:%x, clr_val:%x, set_val:%x, before shft\n", offset, clr_val, set_val);
  129. clr_val <<= shift;
  130. set_val <<= shift;
  131. MYDBG("offset:%x, clr_val:%x, set_val:%x, after shft\n", offset, clr_val, set_val);
  132. USBPHY_CLR8(offset, clr_val);
  133. USBPHY_SET8(offset, set_val);
  134. MYDBG("PHY Register 0x%x = 0x%x\n", 0x800+offset, USBPHY_READ8(offset));
  135. } else {
  136. MYDBG("do nothing\n");
  137. }
  138. }
  139. u8 usb20_phy_debugfs_read_val(u8 offset, u8 shft, u8 msk, u8 width, char *str)
  140. {
  141. u8 val;
  142. int i, temp;
  143. val = USBPHY_READ8(offset);
  144. MYDBG("offset:%x, val:%x, shft:%x, msk:%x\n", offset, val, shft, msk);
  145. val = val >> shft;
  146. MYDBG("offset:%x, val:%x, shft:%x, msk:%x\n", offset, val, shft, msk);
  147. val = val & msk;
  148. MYDBG("offset:%x, val:%x, shft:%x, msk:%x\n", offset, val, shft, msk);
  149. temp = val;
  150. str[width] = '\0';
  151. for (i = (width - 1); i >= 0; i--) {
  152. if (val % 2)
  153. str[i] = '1';
  154. else
  155. str[i] = '0';
  156. MYDBG("str[%d]:%c\n", i, str[i]);
  157. val /= 2;
  158. }
  159. MYDBG("str(%s)\n", str);
  160. return val;
  161. }
  162. static int usb_driving_capability_show(struct seq_file *s, void *unused)
  163. {
  164. u8 val;
  165. char str[16];
  166. u8 combined_val, tmp_val = 0xff;
  167. val = usb20_phy_debugfs_read_val(OFFSET_RG_USB20_TERM_VREF_SEL, SHFT_RG_USB20_TERM_VREF_SEL,
  168. MSK_RG_USB20_TERM_VREF_SEL, BIT_WIDTH_3, str);
  169. if (!strncmp(str, STRNG_0_WIDTH_3, BIT_WIDTH_3)) {
  170. MYDBG("%s case\n", STRNG_0_WIDTH_3);
  171. tmp_val = VAL_0_WIDTH_3;
  172. }
  173. if (!strncmp(str, STRNG_1_WIDTH_3, BIT_WIDTH_3)) {
  174. MYDBG("%s case\n", STRNG_1_WIDTH_3);
  175. tmp_val = VAL_1_WIDTH_3;
  176. }
  177. if (!strncmp(str, STRNG_2_WIDTH_3, BIT_WIDTH_3)) {
  178. MYDBG("%s case\n", STRNG_2_WIDTH_3);
  179. tmp_val = VAL_2_WIDTH_3;
  180. }
  181. if (!strncmp(str, STRNG_3_WIDTH_3, BIT_WIDTH_3)) {
  182. MYDBG("%s case\n", STRNG_3_WIDTH_3);
  183. tmp_val = VAL_3_WIDTH_3;
  184. }
  185. if (!strncmp(str, STRNG_4_WIDTH_3, BIT_WIDTH_3)) {
  186. MYDBG("%s case\n", STRNG_4_WIDTH_3);
  187. tmp_val = VAL_4_WIDTH_3;
  188. }
  189. if (!strncmp(str, STRNG_5_WIDTH_3, BIT_WIDTH_3)) {
  190. MYDBG("%s case\n", STRNG_5_WIDTH_3);
  191. tmp_val = VAL_5_WIDTH_3;
  192. }
  193. if (!strncmp(str, STRNG_6_WIDTH_3, BIT_WIDTH_3)) {
  194. MYDBG("%s case\n", STRNG_6_WIDTH_3);
  195. tmp_val = VAL_6_WIDTH_3;
  196. }
  197. if (!strncmp(str, STRNG_7_WIDTH_3, BIT_WIDTH_3)) {
  198. MYDBG("%s case\n", STRNG_7_WIDTH_3);
  199. tmp_val = VAL_7_WIDTH_3;
  200. }
  201. combined_val = tmp_val;
  202. val = usb20_phy_debugfs_read_val(OFFSET_RG_USB20_VRT_VREF_SEL, SHFT_RG_USB20_VRT_VREF_SEL,
  203. MSK_RG_USB20_VRT_VREF_SEL, BIT_WIDTH_3, str);
  204. if (!strncmp(str, STRNG_0_WIDTH_3, BIT_WIDTH_3)) {
  205. MYDBG("%s case\n", STRNG_0_WIDTH_3);
  206. tmp_val = VAL_0_WIDTH_3;
  207. }
  208. if (!strncmp(str, STRNG_1_WIDTH_3, BIT_WIDTH_3)) {
  209. MYDBG("%s case\n", STRNG_1_WIDTH_3);
  210. tmp_val = VAL_1_WIDTH_3;
  211. }
  212. if (!strncmp(str, STRNG_2_WIDTH_3, BIT_WIDTH_3)) {
  213. MYDBG("%s case\n", STRNG_2_WIDTH_3);
  214. tmp_val = VAL_2_WIDTH_3;
  215. }
  216. if (!strncmp(str, STRNG_3_WIDTH_3, BIT_WIDTH_3)) {
  217. MYDBG("%s case\n", STRNG_3_WIDTH_3);
  218. tmp_val = VAL_3_WIDTH_3;
  219. }
  220. if (!strncmp(str, STRNG_4_WIDTH_3, BIT_WIDTH_3)) {
  221. MYDBG("%s case\n", STRNG_4_WIDTH_3);
  222. tmp_val = VAL_4_WIDTH_3;
  223. }
  224. if (!strncmp(str, STRNG_5_WIDTH_3, BIT_WIDTH_3)) {
  225. MYDBG("%s case\n", STRNG_5_WIDTH_3);
  226. tmp_val = VAL_5_WIDTH_3;
  227. }
  228. if (!strncmp(str, STRNG_6_WIDTH_3, BIT_WIDTH_3)) {
  229. MYDBG("%s case\n", STRNG_6_WIDTH_3);
  230. tmp_val = VAL_6_WIDTH_3;
  231. }
  232. if (!strncmp(str, STRNG_7_WIDTH_3, BIT_WIDTH_3)) {
  233. MYDBG("%s case\n", STRNG_7_WIDTH_3);
  234. tmp_val = VAL_7_WIDTH_3;
  235. }
  236. MYDBG("combined_val(%d), tmp_val(%d)\n", combined_val, tmp_val);
  237. if ((tmp_val == (combined_val - 1)) || (tmp_val == combined_val))
  238. combined_val += tmp_val;
  239. else
  240. combined_val = tmp_val * (VAL_MAX_WDITH_3 + 1) + combined_val;
  241. MYDBG("combined_val(%d), tmp_val(%d)\n", combined_val, tmp_val);
  242. seq_printf(s, "%d", combined_val);
  243. return 0;
  244. }
  245. static int rg_usb20_term_vref_sel_show(struct seq_file *s, void *unused)
  246. {
  247. u8 val;
  248. char str[16];
  249. val =
  250. usb20_phy_debugfs_read_val(OFFSET_RG_USB20_TERM_VREF_SEL, SHFT_RG_USB20_TERM_VREF_SEL,
  251. MSK_RG_USB20_TERM_VREF_SEL, BIT_WIDTH_3, str);
  252. seq_printf(s, "%s", str);
  253. return 0;
  254. }
  255. static int rg_usb20_hstx_srctrl_show(struct seq_file *s, void *unused)
  256. {
  257. u8 val;
  258. char str[16];
  259. val =
  260. usb20_phy_debugfs_read_val(OFFSET_RG_USB20_HSTX_SRCTRL, SHFT_RG_USB20_HSTX_SRCTRL,
  261. MSK_RG_USB20_HSTX_SRCTRL, BIT_WIDTH_3, str);
  262. seq_printf(s, "%s", str);
  263. return 0;
  264. }
  265. static int rg_usb20_vrt_vref_sel_show(struct seq_file *s, void *unused)
  266. {
  267. u8 val;
  268. char str[16];
  269. val =
  270. usb20_phy_debugfs_read_val(OFFSET_RG_USB20_VRT_VREF_SEL, SHFT_RG_USB20_VRT_VREF_SEL,
  271. MSK_RG_USB20_VRT_VREF_SEL, BIT_WIDTH_3, str);
  272. seq_printf(s, "%s", str);
  273. return 0;
  274. }
  275. static int rg_usb20_intr_en_show(struct seq_file *s, void *unused)
  276. {
  277. u8 val;
  278. char str[16];
  279. val =
  280. usb20_phy_debugfs_read_val(OFFSET_RG_USB20_INTR_EN, SHFT_RG_USB20_INTR_EN,
  281. MSK_RG_USB20_INTR_EN, BIT_WIDTH_1, str);
  282. seq_printf(s, "%s", str);
  283. return 0;
  284. }
  285. static int usb_driving_capability_open(struct inode *inode, struct file *file)
  286. {
  287. return single_open(file, usb_driving_capability_show, inode->i_private);
  288. }
  289. static int rg_usb20_term_vref_sel_open(struct inode *inode, struct file *file)
  290. {
  291. return single_open(file, rg_usb20_term_vref_sel_show, inode->i_private);
  292. }
  293. static int rg_usb20_hstx_srctrl_open(struct inode *inode, struct file *file)
  294. {
  295. return single_open(file, rg_usb20_hstx_srctrl_show, inode->i_private);
  296. }
  297. static int rg_usb20_vrt_vref_sel_open(struct inode *inode, struct file *file)
  298. {
  299. return single_open(file, rg_usb20_vrt_vref_sel_show, inode->i_private);
  300. }
  301. static int rg_usb20_intr_en_open(struct inode *inode, struct file *file)
  302. {
  303. return single_open(file, rg_usb20_intr_en_show, inode->i_private);
  304. }
  305. void val_to_bstring_width3(u8 val, char *str)
  306. {
  307. if (val == VAL_0_WIDTH_3)
  308. memcpy(str, STRNG_0_WIDTH_3, BIT_WIDTH_3 + 1);
  309. if (val == VAL_1_WIDTH_3)
  310. memcpy(str, STRNG_1_WIDTH_3, BIT_WIDTH_3 + 1);
  311. if (val == VAL_2_WIDTH_3)
  312. memcpy(str, STRNG_2_WIDTH_3, BIT_WIDTH_3 + 1);
  313. if (val == VAL_3_WIDTH_3)
  314. memcpy(str, STRNG_3_WIDTH_3, BIT_WIDTH_3 + 1);
  315. if (val == VAL_4_WIDTH_3)
  316. memcpy(str, STRNG_4_WIDTH_3, BIT_WIDTH_3 + 1);
  317. if (val == VAL_5_WIDTH_3)
  318. memcpy(str, STRNG_5_WIDTH_3, BIT_WIDTH_3 + 1);
  319. if (val == VAL_6_WIDTH_3)
  320. memcpy(str, STRNG_6_WIDTH_3, BIT_WIDTH_3 + 1);
  321. if (val == VAL_7_WIDTH_3)
  322. memcpy(str, STRNG_7_WIDTH_3, BIT_WIDTH_3 + 1);
  323. MYDBG("val(%d), str(%s)\n", val, str);
  324. }
  325. static ssize_t usb_driving_capability_write(struct file *file,
  326. const char __user *ubuf, size_t count, loff_t *ppos)
  327. {
  328. char buf[18];
  329. u8 val, tmp_val;
  330. char str_rg_usb20_term_vref_sel[18], str_rg_usb20_vrt_vref_sel[18];
  331. memset(buf, 0x00, sizeof(buf));
  332. MYDBG("\n");
  333. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  334. return -EFAULT;
  335. if (kstrtol(buf, 10, (long *)&val) != 0) {
  336. MYDBG("kstrtol, err(%d)\n", kstrtol(buf, 10, (long *)&val));
  337. return count;
  338. }
  339. MYDBG("kstrtol, val(%d)\n", val);
  340. if (val > VAL_7_WIDTH_3 * 2) {
  341. MYDBG("wrong val set(%d), direct return\n", val);
  342. return count;
  343. }
  344. tmp_val = val;
  345. val /= 2;
  346. MYDBG("val(%d), tmp_val(%d)\n", val, tmp_val);
  347. val_to_bstring_width3(tmp_val - val, str_rg_usb20_term_vref_sel);
  348. val_to_bstring_width3(val, str_rg_usb20_vrt_vref_sel);
  349. MYDBG("Config TERM_VREF_SEL %s\n", str_rg_usb20_term_vref_sel);
  350. usb20_phy_debugfs_write_width3(OFFSET_RG_USB20_TERM_VREF_SEL, SHFT_RG_USB20_TERM_VREF_SEL,
  351. str_rg_usb20_term_vref_sel);
  352. MYDBG("Config VRT_VREF_SEL %s\n", str_rg_usb20_vrt_vref_sel);
  353. usb20_phy_debugfs_write_width3(OFFSET_RG_USB20_VRT_VREF_SEL, SHFT_RG_USB20_VRT_VREF_SEL,
  354. str_rg_usb20_vrt_vref_sel);
  355. return count;
  356. }
  357. static ssize_t rg_usb20_term_vref_sel_write(struct file *file,
  358. const char __user *ubuf, size_t count, loff_t *ppos)
  359. {
  360. char buf[18];
  361. memset(buf, 0x00, sizeof(buf));
  362. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  363. return -EFAULT;
  364. usb20_phy_debugfs_write_width3(OFFSET_RG_USB20_TERM_VREF_SEL, SHFT_RG_USB20_TERM_VREF_SEL,
  365. buf);
  366. return count;
  367. }
  368. static ssize_t rg_usb20_hstx_srctrl_write(struct file *file,
  369. const char __user *ubuf, size_t count, loff_t *ppos)
  370. {
  371. char buf[18];
  372. memset(buf, 0x00, sizeof(buf));
  373. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  374. return -EFAULT;
  375. usb20_phy_debugfs_write_width3(OFFSET_RG_USB20_HSTX_SRCTRL, SHFT_RG_USB20_HSTX_SRCTRL, buf);
  376. return count;
  377. }
  378. static ssize_t rg_usb20_vrt_vref_sel_write(struct file *file,
  379. const char __user *ubuf, size_t count, loff_t *ppos)
  380. {
  381. char buf[18];
  382. memset(buf, 0x00, sizeof(buf));
  383. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  384. return -EFAULT;
  385. usb20_phy_debugfs_write_width3(OFFSET_RG_USB20_VRT_VREF_SEL, SHFT_RG_USB20_VRT_VREF_SEL,
  386. buf);
  387. return count;
  388. }
  389. static ssize_t rg_usb20_intr_en_write(struct file *file,
  390. const char __user *ubuf, size_t count, loff_t *ppos)
  391. {
  392. char buf[18];
  393. memset(buf, 0x00, sizeof(buf));
  394. if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
  395. return -EFAULT;
  396. usb20_phy_debugfs_write_width1(OFFSET_RG_USB20_INTR_EN, SHFT_RG_USB20_INTR_EN, buf);
  397. return count;
  398. }
  399. static const struct file_operations usb_driving_capability_fops = {
  400. .open = usb_driving_capability_open,
  401. .write = usb_driving_capability_write,
  402. .read = seq_read,
  403. .llseek = seq_lseek,
  404. .release = single_release,
  405. };
  406. static const struct file_operations rg_usb20_term_vref_sel_fops = {
  407. .open = rg_usb20_term_vref_sel_open,
  408. .write = rg_usb20_term_vref_sel_write,
  409. .read = seq_read,
  410. .llseek = seq_lseek,
  411. .release = single_release,
  412. };
  413. static const struct file_operations rg_usb20_hstx_srctrl_fops = {
  414. .open = rg_usb20_hstx_srctrl_open,
  415. .write = rg_usb20_hstx_srctrl_write,
  416. .read = seq_read,
  417. .llseek = seq_lseek,
  418. .release = single_release,
  419. };
  420. static const struct file_operations rg_usb20_vrt_vref_sel_fops = {
  421. .open = rg_usb20_vrt_vref_sel_open,
  422. .write = rg_usb20_vrt_vref_sel_write,
  423. .read = seq_read,
  424. .llseek = seq_lseek,
  425. .release = single_release,
  426. };
  427. static const struct file_operations rg_usb20_intr_en_fops = {
  428. .open = rg_usb20_intr_en_open,
  429. .write = rg_usb20_intr_en_write,
  430. .read = seq_read,
  431. .llseek = seq_lseek,
  432. .release = single_release,
  433. };
  434. int usb20_phy_init_debugfs(void)
  435. {
  436. struct dentry *root;
  437. struct dentry *file;
  438. int ret;
  439. root = debugfs_create_dir("usb20_phy", NULL);
  440. if (!root) {
  441. ret = -ENOMEM;
  442. goto err0;
  443. }
  444. file = debugfs_create_file(FILE_USB_DRIVING_CAPABILITY, S_IRUGO | S_IWUSR,
  445. root, NULL, &usb_driving_capability_fops);
  446. if (!file) {
  447. ret = -ENOMEM;
  448. goto err1;
  449. }
  450. file = debugfs_create_file(FILE_RG_USB20_TERM_VREF_SEL, S_IRUGO | S_IWUSR,
  451. root, NULL, &rg_usb20_term_vref_sel_fops);
  452. if (!file) {
  453. ret = -ENOMEM;
  454. goto err1;
  455. }
  456. file = debugfs_create_file(FILE_RG_USB20_HSTX_SRCTRL, S_IRUGO | S_IWUSR,
  457. root, NULL, &rg_usb20_hstx_srctrl_fops);
  458. if (!file) {
  459. ret = -ENOMEM;
  460. goto err1;
  461. }
  462. file = debugfs_create_file(FILE_RG_USB20_VRT_VREF_SEL, S_IRUGO | S_IWUSR,
  463. root, NULL, &rg_usb20_vrt_vref_sel_fops);
  464. if (!file) {
  465. ret = -ENOMEM;
  466. goto err1;
  467. }
  468. file = debugfs_create_file(FILE_RG_USB20_INTR_EN, S_IRUGO | S_IWUSR,
  469. root, NULL, &rg_usb20_intr_en_fops);
  470. if (!file) {
  471. ret = -ENOMEM;
  472. goto err1;
  473. }
  474. usb20_phy_debugfs_root = root;
  475. return 0;
  476. err1:
  477. debugfs_remove_recursive(root);
  478. err0:
  479. return ret;
  480. }
  481. void /* __init_or_exit */ usb20_phy_exit_debugfs(struct musb *musb)
  482. {
  483. debugfs_remove_recursive(usb20_phy_debugfs_root);
  484. }