pvrusb2-debugifc.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. *
  3. *
  4. * Copyright (C) 2005 Mike Isely <isely@pobox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/string.h>
  17. #include "pvrusb2-debugifc.h"
  18. #include "pvrusb2-hdw.h"
  19. #include "pvrusb2-debug.h"
  20. struct debugifc_mask_item {
  21. const char *name;
  22. unsigned long msk;
  23. };
  24. static unsigned int debugifc_count_whitespace(const char *buf,
  25. unsigned int count)
  26. {
  27. unsigned int scnt;
  28. char ch;
  29. for (scnt = 0; scnt < count; scnt++) {
  30. ch = buf[scnt];
  31. if (ch == ' ') continue;
  32. if (ch == '\t') continue;
  33. if (ch == '\n') continue;
  34. break;
  35. }
  36. return scnt;
  37. }
  38. static unsigned int debugifc_count_nonwhitespace(const char *buf,
  39. unsigned int count)
  40. {
  41. unsigned int scnt;
  42. char ch;
  43. for (scnt = 0; scnt < count; scnt++) {
  44. ch = buf[scnt];
  45. if (ch == ' ') break;
  46. if (ch == '\t') break;
  47. if (ch == '\n') break;
  48. }
  49. return scnt;
  50. }
  51. static unsigned int debugifc_isolate_word(const char *buf,unsigned int count,
  52. const char **wstrPtr,
  53. unsigned int *wlenPtr)
  54. {
  55. const char *wptr;
  56. unsigned int consume_cnt = 0;
  57. unsigned int wlen;
  58. unsigned int scnt;
  59. wptr = NULL;
  60. wlen = 0;
  61. scnt = debugifc_count_whitespace(buf,count);
  62. consume_cnt += scnt; count -= scnt; buf += scnt;
  63. if (!count) goto done;
  64. scnt = debugifc_count_nonwhitespace(buf,count);
  65. if (!scnt) goto done;
  66. wptr = buf;
  67. wlen = scnt;
  68. consume_cnt += scnt; count -= scnt; buf += scnt;
  69. done:
  70. *wstrPtr = wptr;
  71. *wlenPtr = wlen;
  72. return consume_cnt;
  73. }
  74. static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
  75. u32 *num_ptr)
  76. {
  77. u32 result = 0;
  78. int radix = 10;
  79. if ((count >= 2) && (buf[0] == '0') &&
  80. ((buf[1] == 'x') || (buf[1] == 'X'))) {
  81. radix = 16;
  82. count -= 2;
  83. buf += 2;
  84. } else if ((count >= 1) && (buf[0] == '0')) {
  85. radix = 8;
  86. }
  87. while (count--) {
  88. int val = hex_to_bin(*buf++);
  89. if (val < 0 || val >= radix)
  90. return -EINVAL;
  91. result *= radix;
  92. result += val;
  93. }
  94. *num_ptr = result;
  95. return 0;
  96. }
  97. static int debugifc_match_keyword(const char *buf,unsigned int count,
  98. const char *keyword)
  99. {
  100. unsigned int kl;
  101. if (!keyword) return 0;
  102. kl = strlen(keyword);
  103. if (kl != count) return 0;
  104. return !memcmp(buf,keyword,kl);
  105. }
  106. int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
  107. {
  108. int bcnt = 0;
  109. int ccnt;
  110. ccnt = scnprintf(buf, acnt, "Driver hardware description: %s\n",
  111. pvr2_hdw_get_desc(hdw));
  112. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  113. ccnt = scnprintf(buf,acnt,"Driver state info:\n");
  114. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  115. ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
  116. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  117. return bcnt;
  118. }
  119. int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
  120. char *buf,unsigned int acnt)
  121. {
  122. int bcnt = 0;
  123. int ccnt;
  124. int ret;
  125. u32 gpio_dir,gpio_in,gpio_out;
  126. struct pvr2_stream_stats stats;
  127. struct pvr2_stream *sp;
  128. ret = pvr2_hdw_is_hsm(hdw);
  129. ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
  130. (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
  131. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  132. gpio_dir = 0; gpio_in = 0; gpio_out = 0;
  133. pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
  134. pvr2_hdw_gpio_get_out(hdw,&gpio_out);
  135. pvr2_hdw_gpio_get_in(hdw,&gpio_in);
  136. ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
  137. gpio_dir,gpio_in,gpio_out);
  138. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  139. ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
  140. pvr2_hdw_get_streaming(hdw) ? "on" : "off");
  141. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  142. sp = pvr2_hdw_get_video_stream(hdw);
  143. if (sp) {
  144. pvr2_stream_get_stats(sp, &stats, 0);
  145. ccnt = scnprintf(
  146. buf,acnt,
  147. "Bytes streamed=%u URBs: queued=%u idle=%u ready=%u processed=%u failed=%u\n",
  148. stats.bytes_processed,
  149. stats.buffers_in_queue,
  150. stats.buffers_in_idle,
  151. stats.buffers_in_ready,
  152. stats.buffers_processed,
  153. stats.buffers_failed);
  154. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  155. }
  156. return bcnt;
  157. }
  158. static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
  159. unsigned int count)
  160. {
  161. const char *wptr;
  162. unsigned int wlen;
  163. unsigned int scnt;
  164. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  165. if (!scnt) return 0;
  166. count -= scnt; buf += scnt;
  167. if (!wptr) return 0;
  168. pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
  169. if (debugifc_match_keyword(wptr,wlen,"reset")) {
  170. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  171. if (!scnt) return -EINVAL;
  172. count -= scnt; buf += scnt;
  173. if (!wptr) return -EINVAL;
  174. if (debugifc_match_keyword(wptr,wlen,"cpu")) {
  175. pvr2_hdw_cpureset_assert(hdw,!0);
  176. pvr2_hdw_cpureset_assert(hdw,0);
  177. return 0;
  178. } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
  179. pvr2_hdw_device_reset(hdw);
  180. } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
  181. return pvr2_hdw_cmd_powerup(hdw);
  182. } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
  183. return pvr2_hdw_cmd_deep_reset(hdw);
  184. } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
  185. return pvr2_upload_firmware2(hdw);
  186. } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
  187. return pvr2_hdw_cmd_decoder_reset(hdw);
  188. } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
  189. return pvr2_hdw_untrip(hdw);
  190. } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
  191. pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
  192. NULL, !0);
  193. return 0;
  194. }
  195. return -EINVAL;
  196. } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
  197. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  198. if (!scnt) return -EINVAL;
  199. count -= scnt; buf += scnt;
  200. if (!wptr) return -EINVAL;
  201. if (debugifc_match_keyword(wptr,wlen,"fetch")) {
  202. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  203. if (scnt && wptr) {
  204. count -= scnt; buf += scnt;
  205. if (debugifc_match_keyword(wptr, wlen,
  206. "prom")) {
  207. pvr2_hdw_cpufw_set_enabled(hdw, 2, !0);
  208. } else if (debugifc_match_keyword(wptr, wlen,
  209. "ram8k")) {
  210. pvr2_hdw_cpufw_set_enabled(hdw, 0, !0);
  211. } else if (debugifc_match_keyword(wptr, wlen,
  212. "ram16k")) {
  213. pvr2_hdw_cpufw_set_enabled(hdw, 1, !0);
  214. } else {
  215. return -EINVAL;
  216. }
  217. }
  218. pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
  219. return 0;
  220. } else if (debugifc_match_keyword(wptr,wlen,"done")) {
  221. pvr2_hdw_cpufw_set_enabled(hdw,0,0);
  222. return 0;
  223. } else {
  224. return -EINVAL;
  225. }
  226. } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
  227. int dir_fl = 0;
  228. int ret;
  229. u32 msk,val;
  230. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  231. if (!scnt) return -EINVAL;
  232. count -= scnt; buf += scnt;
  233. if (!wptr) return -EINVAL;
  234. if (debugifc_match_keyword(wptr,wlen,"dir")) {
  235. dir_fl = !0;
  236. } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
  237. return -EINVAL;
  238. }
  239. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  240. if (!scnt) return -EINVAL;
  241. count -= scnt; buf += scnt;
  242. if (!wptr) return -EINVAL;
  243. ret = debugifc_parse_unsigned_number(wptr,wlen,&msk);
  244. if (ret) return ret;
  245. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  246. if (wptr) {
  247. ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
  248. if (ret) return ret;
  249. } else {
  250. val = msk;
  251. msk = 0xffffffff;
  252. }
  253. if (dir_fl) {
  254. ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
  255. } else {
  256. ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
  257. }
  258. return ret;
  259. }
  260. pvr2_trace(PVR2_TRACE_DEBUGIFC,
  261. "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
  262. return -EINVAL;
  263. }
  264. int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
  265. unsigned int count)
  266. {
  267. unsigned int bcnt = 0;
  268. int ret;
  269. while (count) {
  270. for (bcnt = 0; bcnt < count; bcnt++) {
  271. if (buf[bcnt] == '\n') break;
  272. }
  273. ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
  274. if (ret < 0) return ret;
  275. if (bcnt < count) bcnt++;
  276. buf += bcnt;
  277. count -= bcnt;
  278. }
  279. return 0;
  280. }