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.
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
21 #include <linux/string.h>
22 #include "pvrusb2-debugifc.h"
23 #include "pvrusb2-hdw.h"
24 #include "pvrusb2-debug.h"
26 struct debugifc_mask_item {
32 static unsigned int debugifc_count_whitespace(const char *buf,
38 for (scnt = 0; scnt < count; scnt++) {
40 if (ch == ' ') continue;
41 if (ch == '\t') continue;
42 if (ch == '\n') continue;
49 static unsigned int debugifc_count_nonwhitespace(const char *buf,
55 for (scnt = 0; scnt < count; scnt++) {
58 if (ch == '\t') break;
59 if (ch == '\n') break;
65 static unsigned int debugifc_isolate_word(const char *buf,unsigned int count,
67 unsigned int *wlenPtr)
70 unsigned int consume_cnt = 0;
76 scnt = debugifc_count_whitespace(buf,count);
77 consume_cnt += scnt; count -= scnt; buf += scnt;
78 if (!count) goto done;
80 scnt = debugifc_count_nonwhitespace(buf,count);
84 consume_cnt += scnt; count -= scnt; buf += scnt;
93 static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
100 if ((count >= 2) && (buf[0] == '0') &&
101 ((buf[1] == 'x') || (buf[1] == 'X'))) {
105 } else if ((count >= 1) && (buf[0] == '0')) {
111 if ((ch >= '0') && (ch <= '9')) {
113 } else if ((ch >= 'a') && (ch <= 'f')) {
115 } else if ((ch >= 'A') && (ch <= 'F')) {
120 if (val >= radix) return -EINVAL;
129 static int debugifc_match_keyword(const char *buf,unsigned int count,
133 if (!keyword) return 0;
134 kl = strlen(keyword);
135 if (kl != count) return 0;
136 return !memcmp(buf,keyword,kl);
140 int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
144 ccnt = scnprintf(buf, acnt, "Driver hardware description: %s\n",
145 pvr2_hdw_get_desc(hdw));
146 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
147 ccnt = scnprintf(buf,acnt,"Driver state info:\n");
148 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
149 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
150 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
156 int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
157 char *buf,unsigned int acnt)
162 u32 gpio_dir,gpio_in,gpio_out;
163 struct pvr2_stream_stats stats;
164 struct pvr2_stream *sp;
166 ret = pvr2_hdw_is_hsm(hdw);
167 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
168 (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
169 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
171 gpio_dir = 0; gpio_in = 0; gpio_out = 0;
172 pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
173 pvr2_hdw_gpio_get_out(hdw,&gpio_out);
174 pvr2_hdw_gpio_get_in(hdw,&gpio_in);
175 ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
176 gpio_dir,gpio_in,gpio_out);
177 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
179 ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
180 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
181 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
184 sp = pvr2_hdw_get_video_stream(hdw);
186 pvr2_stream_get_stats(sp, &stats, 0);
190 " URBs: queued=%u idle=%u ready=%u"
191 " processed=%u failed=%u\n",
192 stats.bytes_processed,
193 stats.buffers_in_queue,
194 stats.buffers_in_idle,
195 stats.buffers_in_ready,
196 stats.buffers_processed,
197 stats.buffers_failed);
198 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
205 static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
212 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
214 count -= scnt; buf += scnt;
217 pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
218 if (debugifc_match_keyword(wptr,wlen,"reset")) {
219 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
220 if (!scnt) return -EINVAL;
221 count -= scnt; buf += scnt;
222 if (!wptr) return -EINVAL;
223 if (debugifc_match_keyword(wptr,wlen,"cpu")) {
224 pvr2_hdw_cpureset_assert(hdw,!0);
225 pvr2_hdw_cpureset_assert(hdw,0);
227 } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
228 pvr2_hdw_device_reset(hdw);
229 } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
230 return pvr2_hdw_cmd_powerup(hdw);
231 } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
232 return pvr2_hdw_cmd_deep_reset(hdw);
233 } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
234 return pvr2_upload_firmware2(hdw);
235 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
236 return pvr2_hdw_cmd_decoder_reset(hdw);
237 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
238 return pvr2_hdw_untrip(hdw);
239 } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
240 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
245 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
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,"fetch")) {
251 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
253 count -= scnt; buf += scnt;
254 if (debugifc_match_keyword(wptr, wlen,
256 pvr2_hdw_cpufw_set_enabled(hdw, 2, !0);
257 } else if (debugifc_match_keyword(wptr, wlen,
259 pvr2_hdw_cpufw_set_enabled(hdw, 0, !0);
260 } else if (debugifc_match_keyword(wptr, wlen,
262 pvr2_hdw_cpufw_set_enabled(hdw, 1, !0);
267 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
269 } else if (debugifc_match_keyword(wptr,wlen,"done")) {
270 pvr2_hdw_cpufw_set_enabled(hdw,0,0);
275 } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
279 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
280 if (!scnt) return -EINVAL;
281 count -= scnt; buf += scnt;
282 if (!wptr) return -EINVAL;
283 if (debugifc_match_keyword(wptr,wlen,"dir")) {
285 } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
288 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
289 if (!scnt) return -EINVAL;
290 count -= scnt; buf += scnt;
291 if (!wptr) return -EINVAL;
292 ret = debugifc_parse_unsigned_number(wptr,wlen,&msk);
294 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
296 ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
303 ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
305 ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
309 pvr2_trace(PVR2_TRACE_DEBUGIFC,
310 "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
315 int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
318 unsigned int bcnt = 0;
322 for (bcnt = 0; bcnt < count; bcnt++) {
323 if (buf[bcnt] == '\n') break;
326 ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
327 if (ret < 0) return ret;
328 if (bcnt < count) bcnt++;
338 Stuff for Emacs to see, in order to encourage consistent editing style:
339 *** Local Variables: ***
341 *** fill-column: 75 ***
343 *** c-basic-offset: 8 ***