pvrusb2-debugifc.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. #include <linux/string.h>
  21. #include "pvrusb2-debugifc.h"
  22. #include "pvrusb2-hdw.h"
  23. #include "pvrusb2-debug.h"
  24. struct debugifc_mask_item {
  25. const char *name;
  26. unsigned long msk;
  27. };
  28. static unsigned int debugifc_count_whitespace(const char *buf,
  29. unsigned int count)
  30. {
  31. unsigned int scnt;
  32. char ch;
  33. for (scnt = 0; scnt < count; scnt++) {
  34. ch = buf[scnt];
  35. if (ch == ' ') continue;
  36. if (ch == '\t') continue;
  37. if (ch == '\n') continue;
  38. break;
  39. }
  40. return scnt;
  41. }
  42. static unsigned int debugifc_count_nonwhitespace(const char *buf,
  43. unsigned int count)
  44. {
  45. unsigned int scnt;
  46. char ch;
  47. for (scnt = 0; scnt < count; scnt++) {
  48. ch = buf[scnt];
  49. if (ch == ' ') break;
  50. if (ch == '\t') break;
  51. if (ch == '\n') break;
  52. }
  53. return scnt;
  54. }
  55. static unsigned int debugifc_isolate_word(const char *buf,unsigned int count,
  56. const char **wstrPtr,
  57. unsigned int *wlenPtr)
  58. {
  59. const char *wptr;
  60. unsigned int consume_cnt = 0;
  61. unsigned int wlen;
  62. unsigned int scnt;
  63. wptr = NULL;
  64. wlen = 0;
  65. scnt = debugifc_count_whitespace(buf,count);
  66. consume_cnt += scnt; count -= scnt; buf += scnt;
  67. if (!count) goto done;
  68. scnt = debugifc_count_nonwhitespace(buf,count);
  69. if (!scnt) goto done;
  70. wptr = buf;
  71. wlen = scnt;
  72. consume_cnt += scnt; count -= scnt; buf += scnt;
  73. done:
  74. *wstrPtr = wptr;
  75. *wlenPtr = wlen;
  76. return consume_cnt;
  77. }
  78. static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
  79. u32 *num_ptr)
  80. {
  81. u32 result = 0;
  82. u32 val;
  83. int ch;
  84. int radix = 10;
  85. if ((count >= 2) && (buf[0] == '0') &&
  86. ((buf[1] == 'x') || (buf[1] == 'X'))) {
  87. radix = 16;
  88. count -= 2;
  89. buf += 2;
  90. } else if ((count >= 1) && (buf[0] == '0')) {
  91. radix = 8;
  92. }
  93. while (count--) {
  94. ch = *buf++;
  95. if ((ch >= '0') && (ch <= '9')) {
  96. val = ch - '0';
  97. } else if ((ch >= 'a') && (ch <= 'f')) {
  98. val = ch - 'a' + 10;
  99. } else if ((ch >= 'A') && (ch <= 'F')) {
  100. val = ch - 'A' + 10;
  101. } else {
  102. return -EINVAL;
  103. }
  104. if (val >= radix) return -EINVAL;
  105. result *= radix;
  106. result += val;
  107. }
  108. *num_ptr = result;
  109. return 0;
  110. }
  111. static int debugifc_match_keyword(const char *buf,unsigned int count,
  112. const char *keyword)
  113. {
  114. unsigned int kl;
  115. if (!keyword) return 0;
  116. kl = strlen(keyword);
  117. if (kl != count) return 0;
  118. return !memcmp(buf,keyword,kl);
  119. }
  120. int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
  121. {
  122. int bcnt = 0;
  123. int ccnt;
  124. ccnt = scnprintf(buf, acnt, "Driver hardware description: %s\n",
  125. pvr2_hdw_get_desc(hdw));
  126. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  127. ccnt = scnprintf(buf,acnt,"Driver state info:\n");
  128. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  129. ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
  130. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  131. return bcnt;
  132. }
  133. int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
  134. char *buf,unsigned int acnt)
  135. {
  136. int bcnt = 0;
  137. int ccnt;
  138. int ret;
  139. u32 gpio_dir,gpio_in,gpio_out;
  140. struct pvr2_stream_stats stats;
  141. struct pvr2_stream *sp;
  142. ret = pvr2_hdw_is_hsm(hdw);
  143. ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
  144. (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
  145. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  146. gpio_dir = 0; gpio_in = 0; gpio_out = 0;
  147. pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
  148. pvr2_hdw_gpio_get_out(hdw,&gpio_out);
  149. pvr2_hdw_gpio_get_in(hdw,&gpio_in);
  150. ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
  151. gpio_dir,gpio_in,gpio_out);
  152. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  153. ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
  154. pvr2_hdw_get_streaming(hdw) ? "on" : "off");
  155. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  156. sp = pvr2_hdw_get_video_stream(hdw);
  157. if (sp) {
  158. pvr2_stream_get_stats(sp, &stats, 0);
  159. ccnt = scnprintf(
  160. buf,acnt,
  161. "Bytes streamed=%u"
  162. " URBs: queued=%u idle=%u ready=%u"
  163. " processed=%u failed=%u\n",
  164. stats.bytes_processed,
  165. stats.buffers_in_queue,
  166. stats.buffers_in_idle,
  167. stats.buffers_in_ready,
  168. stats.buffers_processed,
  169. stats.buffers_failed);
  170. bcnt += ccnt; acnt -= ccnt; buf += ccnt;
  171. }
  172. return bcnt;
  173. }
  174. static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
  175. unsigned int count)
  176. {
  177. const char *wptr;
  178. unsigned int wlen;
  179. unsigned int scnt;
  180. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  181. if (!scnt) return 0;
  182. count -= scnt; buf += scnt;
  183. if (!wptr) return 0;
  184. pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
  185. if (debugifc_match_keyword(wptr,wlen,"reset")) {
  186. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  187. if (!scnt) return -EINVAL;
  188. count -= scnt; buf += scnt;
  189. if (!wptr) return -EINVAL;
  190. if (debugifc_match_keyword(wptr,wlen,"cpu")) {
  191. pvr2_hdw_cpureset_assert(hdw,!0);
  192. pvr2_hdw_cpureset_assert(hdw,0);
  193. return 0;
  194. } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
  195. pvr2_hdw_device_reset(hdw);
  196. } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
  197. return pvr2_hdw_cmd_powerup(hdw);
  198. } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
  199. return pvr2_hdw_cmd_deep_reset(hdw);
  200. } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
  201. return pvr2_upload_firmware2(hdw);
  202. } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
  203. return pvr2_hdw_cmd_decoder_reset(hdw);
  204. } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
  205. return pvr2_hdw_untrip(hdw);
  206. } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
  207. pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
  208. NULL, !0);
  209. return 0;
  210. }
  211. return -EINVAL;
  212. } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
  213. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  214. if (!scnt) return -EINVAL;
  215. count -= scnt; buf += scnt;
  216. if (!wptr) return -EINVAL;
  217. if (debugifc_match_keyword(wptr,wlen,"fetch")) {
  218. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  219. if (scnt && wptr) {
  220. count -= scnt; buf += scnt;
  221. if (debugifc_match_keyword(wptr, wlen,
  222. "prom")) {
  223. pvr2_hdw_cpufw_set_enabled(hdw, 2, !0);
  224. } else if (debugifc_match_keyword(wptr, wlen,
  225. "ram8k")) {
  226. pvr2_hdw_cpufw_set_enabled(hdw, 0, !0);
  227. } else if (debugifc_match_keyword(wptr, wlen,
  228. "ram16k")) {
  229. pvr2_hdw_cpufw_set_enabled(hdw, 1, !0);
  230. } else {
  231. return -EINVAL;
  232. }
  233. }
  234. pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
  235. return 0;
  236. } else if (debugifc_match_keyword(wptr,wlen,"done")) {
  237. pvr2_hdw_cpufw_set_enabled(hdw,0,0);
  238. return 0;
  239. } else {
  240. return -EINVAL;
  241. }
  242. } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
  243. int dir_fl = 0;
  244. int ret;
  245. u32 msk,val;
  246. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  247. if (!scnt) return -EINVAL;
  248. count -= scnt; buf += scnt;
  249. if (!wptr) return -EINVAL;
  250. if (debugifc_match_keyword(wptr,wlen,"dir")) {
  251. dir_fl = !0;
  252. } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
  253. return -EINVAL;
  254. }
  255. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  256. if (!scnt) return -EINVAL;
  257. count -= scnt; buf += scnt;
  258. if (!wptr) return -EINVAL;
  259. ret = debugifc_parse_unsigned_number(wptr,wlen,&msk);
  260. if (ret) return ret;
  261. scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
  262. if (wptr) {
  263. ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
  264. if (ret) return ret;
  265. } else {
  266. val = msk;
  267. msk = 0xffffffff;
  268. }
  269. if (dir_fl) {
  270. ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
  271. } else {
  272. ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
  273. }
  274. return ret;
  275. }
  276. pvr2_trace(PVR2_TRACE_DEBUGIFC,
  277. "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
  278. return -EINVAL;
  279. }
  280. int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
  281. unsigned int count)
  282. {
  283. unsigned int bcnt = 0;
  284. int ret;
  285. while (count) {
  286. for (bcnt = 0; bcnt < count; bcnt++) {
  287. if (buf[bcnt] == '\n') break;
  288. }
  289. ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
  290. if (ret < 0) return ret;
  291. if (bcnt < count) bcnt++;
  292. buf += bcnt;
  293. count -= bcnt;
  294. }
  295. return 0;
  296. }
  297. /*
  298. Stuff for Emacs to see, in order to encourage consistent editing style:
  299. *** Local Variables: ***
  300. *** mode: c ***
  301. *** fill-column: 75 ***
  302. *** tab-width: 8 ***
  303. *** c-basic-offset: 8 ***
  304. *** End: ***
  305. */