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,
98 if ((count >= 2) && (buf[0] == '0') &&
99 ((buf[1] == 'x') || (buf[1] == 'X'))) {
103 } else if ((count >= 1) && (buf[0] == '0')) {
108 int val = hex_to_bin(*buf++);
109 if (val < 0 || val >= radix)
119 static int debugifc_match_keyword(const char *buf,unsigned int count,
123 if (!keyword) return 0;
124 kl = strlen(keyword);
125 if (kl != count) return 0;
126 return !memcmp(buf,keyword,kl);
130 int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
134 ccnt = scnprintf(buf, acnt, "Driver hardware description: %s\n",
135 pvr2_hdw_get_desc(hdw));
136 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
137 ccnt = scnprintf(buf,acnt,"Driver state info:\n");
138 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
139 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
140 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
146 int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
147 char *buf,unsigned int acnt)
152 u32 gpio_dir,gpio_in,gpio_out;
153 struct pvr2_stream_stats stats;
154 struct pvr2_stream *sp;
156 ret = pvr2_hdw_is_hsm(hdw);
157 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
158 (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
159 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
161 gpio_dir = 0; gpio_in = 0; gpio_out = 0;
162 pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
163 pvr2_hdw_gpio_get_out(hdw,&gpio_out);
164 pvr2_hdw_gpio_get_in(hdw,&gpio_in);
165 ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
166 gpio_dir,gpio_in,gpio_out);
167 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
169 ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
170 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
171 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
174 sp = pvr2_hdw_get_video_stream(hdw);
176 pvr2_stream_get_stats(sp, &stats, 0);
180 " URBs: queued=%u idle=%u ready=%u"
181 " processed=%u failed=%u\n",
182 stats.bytes_processed,
183 stats.buffers_in_queue,
184 stats.buffers_in_idle,
185 stats.buffers_in_ready,
186 stats.buffers_processed,
187 stats.buffers_failed);
188 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
195 static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
202 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
204 count -= scnt; buf += scnt;
207 pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
208 if (debugifc_match_keyword(wptr,wlen,"reset")) {
209 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
210 if (!scnt) return -EINVAL;
211 count -= scnt; buf += scnt;
212 if (!wptr) return -EINVAL;
213 if (debugifc_match_keyword(wptr,wlen,"cpu")) {
214 pvr2_hdw_cpureset_assert(hdw,!0);
215 pvr2_hdw_cpureset_assert(hdw,0);
217 } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
218 pvr2_hdw_device_reset(hdw);
219 } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
220 return pvr2_hdw_cmd_powerup(hdw);
221 } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
222 return pvr2_hdw_cmd_deep_reset(hdw);
223 } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
224 return pvr2_upload_firmware2(hdw);
225 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
226 return pvr2_hdw_cmd_decoder_reset(hdw);
227 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
228 return pvr2_hdw_untrip(hdw);
229 } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
230 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
235 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
236 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
237 if (!scnt) return -EINVAL;
238 count -= scnt; buf += scnt;
239 if (!wptr) return -EINVAL;
240 if (debugifc_match_keyword(wptr,wlen,"fetch")) {
241 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
243 count -= scnt; buf += scnt;
244 if (debugifc_match_keyword(wptr, wlen,
246 pvr2_hdw_cpufw_set_enabled(hdw, 2, !0);
247 } else if (debugifc_match_keyword(wptr, wlen,
249 pvr2_hdw_cpufw_set_enabled(hdw, 0, !0);
250 } else if (debugifc_match_keyword(wptr, wlen,
252 pvr2_hdw_cpufw_set_enabled(hdw, 1, !0);
257 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
259 } else if (debugifc_match_keyword(wptr,wlen,"done")) {
260 pvr2_hdw_cpufw_set_enabled(hdw,0,0);
265 } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
269 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
270 if (!scnt) return -EINVAL;
271 count -= scnt; buf += scnt;
272 if (!wptr) return -EINVAL;
273 if (debugifc_match_keyword(wptr,wlen,"dir")) {
275 } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
278 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
279 if (!scnt) return -EINVAL;
280 count -= scnt; buf += scnt;
281 if (!wptr) return -EINVAL;
282 ret = debugifc_parse_unsigned_number(wptr,wlen,&msk);
284 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
286 ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
293 ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
295 ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
299 pvr2_trace(PVR2_TRACE_DEBUGIFC,
300 "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
305 int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
308 unsigned int bcnt = 0;
312 for (bcnt = 0; bcnt < count; bcnt++) {
313 if (buf[bcnt] == '\n') break;
316 ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
317 if (ret < 0) return ret;
318 if (bcnt < count) bcnt++;
328 Stuff for Emacs to see, in order to encourage consistent editing style:
329 *** Local Variables: ***
331 *** fill-column: 75 ***
333 *** c-basic-offset: 8 ***