4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
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
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.
17 #include <linux/string.h>
18 #include "pvrusb2-debugifc.h"
19 #include "pvrusb2-hdw.h"
20 #include "pvrusb2-debug.h"
22 struct debugifc_mask_item {
28 static unsigned int debugifc_count_whitespace(const char *buf,
34 for (scnt = 0; scnt < count; scnt++) {
36 if (ch == ' ') continue;
37 if (ch == '\t') continue;
38 if (ch == '\n') continue;
45 static unsigned int debugifc_count_nonwhitespace(const char *buf,
51 for (scnt = 0; scnt < count; scnt++) {
54 if (ch == '\t') break;
55 if (ch == '\n') break;
61 static unsigned int debugifc_isolate_word(const char *buf,unsigned int count,
63 unsigned int *wlenPtr)
66 unsigned int consume_cnt = 0;
72 scnt = debugifc_count_whitespace(buf,count);
73 consume_cnt += scnt; count -= scnt; buf += scnt;
74 if (!count) goto done;
76 scnt = debugifc_count_nonwhitespace(buf,count);
80 consume_cnt += scnt; count -= scnt; buf += scnt;
89 static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
94 if ((count >= 2) && (buf[0] == '0') &&
95 ((buf[1] == 'x') || (buf[1] == 'X'))) {
99 } else if ((count >= 1) && (buf[0] == '0')) {
104 int val = hex_to_bin(*buf++);
105 if (val < 0 || val >= radix)
115 static int debugifc_match_keyword(const char *buf,unsigned int count,
119 if (!keyword) return 0;
120 kl = strlen(keyword);
121 if (kl != count) return 0;
122 return !memcmp(buf,keyword,kl);
126 int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
130 ccnt = scnprintf(buf, acnt, "Driver hardware description: %s\n",
131 pvr2_hdw_get_desc(hdw));
132 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
133 ccnt = scnprintf(buf,acnt,"Driver state info:\n");
134 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
135 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
136 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
142 int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
143 char *buf,unsigned int acnt)
148 u32 gpio_dir,gpio_in,gpio_out;
149 struct pvr2_stream_stats stats;
150 struct pvr2_stream *sp;
152 ret = pvr2_hdw_is_hsm(hdw);
153 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
154 (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
155 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
157 gpio_dir = 0; gpio_in = 0; gpio_out = 0;
158 pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
159 pvr2_hdw_gpio_get_out(hdw,&gpio_out);
160 pvr2_hdw_gpio_get_in(hdw,&gpio_in);
161 ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
162 gpio_dir,gpio_in,gpio_out);
163 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
165 ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
166 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
167 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
170 sp = pvr2_hdw_get_video_stream(hdw);
172 pvr2_stream_get_stats(sp, &stats, 0);
175 "Bytes streamed=%u URBs: queued=%u idle=%u ready=%u processed=%u failed=%u\n",
176 stats.bytes_processed,
177 stats.buffers_in_queue,
178 stats.buffers_in_idle,
179 stats.buffers_in_ready,
180 stats.buffers_processed,
181 stats.buffers_failed);
182 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
189 static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
196 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
198 count -= scnt; buf += scnt;
201 pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
202 if (debugifc_match_keyword(wptr,wlen,"reset")) {
203 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
204 if (!scnt) return -EINVAL;
205 count -= scnt; buf += scnt;
206 if (!wptr) return -EINVAL;
207 if (debugifc_match_keyword(wptr,wlen,"cpu")) {
208 pvr2_hdw_cpureset_assert(hdw,!0);
209 pvr2_hdw_cpureset_assert(hdw,0);
211 } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
212 pvr2_hdw_device_reset(hdw);
213 } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
214 return pvr2_hdw_cmd_powerup(hdw);
215 } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
216 return pvr2_hdw_cmd_deep_reset(hdw);
217 } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
218 return pvr2_upload_firmware2(hdw);
219 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
220 return pvr2_hdw_cmd_decoder_reset(hdw);
221 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
222 return pvr2_hdw_untrip(hdw);
223 } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
224 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
229 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
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,"fetch")) {
235 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
237 count -= scnt; buf += scnt;
238 if (debugifc_match_keyword(wptr, wlen,
240 pvr2_hdw_cpufw_set_enabled(hdw, 2, !0);
241 } else if (debugifc_match_keyword(wptr, wlen,
243 pvr2_hdw_cpufw_set_enabled(hdw, 0, !0);
244 } else if (debugifc_match_keyword(wptr, wlen,
246 pvr2_hdw_cpufw_set_enabled(hdw, 1, !0);
251 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
253 } else if (debugifc_match_keyword(wptr,wlen,"done")) {
254 pvr2_hdw_cpufw_set_enabled(hdw,0,0);
259 } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
263 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
264 if (!scnt) return -EINVAL;
265 count -= scnt; buf += scnt;
266 if (!wptr) return -EINVAL;
267 if (debugifc_match_keyword(wptr,wlen,"dir")) {
269 } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
272 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
273 if (!scnt) return -EINVAL;
274 count -= scnt; buf += scnt;
275 if (!wptr) return -EINVAL;
276 ret = debugifc_parse_unsigned_number(wptr,wlen,&msk);
278 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
280 ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
287 ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
289 ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
293 pvr2_trace(PVR2_TRACE_DEBUGIFC,
294 "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
299 int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
302 unsigned int bcnt = 0;
306 for (bcnt = 0; bcnt < count; bcnt++) {
307 if (buf[bcnt] == '\n') break;
310 ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
311 if (ret < 0) return ret;
312 if (bcnt < count) bcnt++;