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 <linux/slab.h>
23 #include "pvrusb2-debugifc.h"
24 #include "pvrusb2-hdw.h"
25 #include "pvrusb2-debug.h"
27 struct debugifc_mask_item {
33 static unsigned int debugifc_count_whitespace(const char *buf,
39 for (scnt = 0; scnt < count; scnt++) {
41 if (ch == ' ') continue;
42 if (ch == '\t') continue;
43 if (ch == '\n') continue;
50 static unsigned int debugifc_count_nonwhitespace(const char *buf,
56 for (scnt = 0; scnt < count; scnt++) {
59 if (ch == '\t') break;
60 if (ch == '\n') break;
66 static unsigned int debugifc_isolate_word(const char *buf,unsigned int count,
68 unsigned int *wlenPtr)
71 unsigned int consume_cnt = 0;
77 scnt = debugifc_count_whitespace(buf,count);
78 consume_cnt += scnt; count -= scnt; buf += scnt;
79 if (!count) goto done;
81 scnt = debugifc_count_nonwhitespace(buf,count);
85 consume_cnt += scnt; count -= scnt; buf += scnt;
94 static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
101 if ((count >= 2) && (buf[0] == '0') &&
102 ((buf[1] == 'x') || (buf[1] == 'X'))) {
106 } else if ((count >= 1) && (buf[0] == '0')) {
112 if ((ch >= '0') && (ch <= '9')) {
114 } else if ((ch >= 'a') && (ch <= 'f')) {
116 } else if ((ch >= 'A') && (ch <= 'F')) {
121 if (val >= radix) return -EINVAL;
130 static int debugifc_match_keyword(const char *buf,unsigned int count,
134 if (!keyword) return 0;
135 kl = strlen(keyword);
136 if (kl != count) return 0;
137 return !memcmp(buf,keyword,kl);
141 int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
145 ccnt = scnprintf(buf, acnt, "Driver hardware description: %s\n",
146 pvr2_hdw_get_desc(hdw));
147 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
148 ccnt = scnprintf(buf,acnt,"Driver state info:\n");
149 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
150 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
151 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
157 int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
158 char *buf,unsigned int acnt)
163 u32 gpio_dir,gpio_in,gpio_out;
164 struct pvr2_stream_stats stats;
165 struct pvr2_stream *sp;
167 ret = pvr2_hdw_is_hsm(hdw);
168 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
169 (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
170 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
172 gpio_dir = 0; gpio_in = 0; gpio_out = 0;
173 pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
174 pvr2_hdw_gpio_get_out(hdw,&gpio_out);
175 pvr2_hdw_gpio_get_in(hdw,&gpio_in);
176 ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
177 gpio_dir,gpio_in,gpio_out);
178 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
180 ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
181 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
182 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
185 sp = pvr2_hdw_get_video_stream(hdw);
187 pvr2_stream_get_stats(sp, &stats, 0);
191 " URBs: queued=%u idle=%u ready=%u"
192 " processed=%u failed=%u\n",
193 stats.bytes_processed,
194 stats.buffers_in_queue,
195 stats.buffers_in_idle,
196 stats.buffers_in_ready,
197 stats.buffers_processed,
198 stats.buffers_failed);
199 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
206 static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
213 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
215 count -= scnt; buf += scnt;
218 pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
219 if (debugifc_match_keyword(wptr,wlen,"reset")) {
220 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
221 if (!scnt) return -EINVAL;
222 count -= scnt; buf += scnt;
223 if (!wptr) return -EINVAL;
224 if (debugifc_match_keyword(wptr,wlen,"cpu")) {
225 pvr2_hdw_cpureset_assert(hdw,!0);
226 pvr2_hdw_cpureset_assert(hdw,0);
228 } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
229 pvr2_hdw_device_reset(hdw);
230 } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
231 return pvr2_hdw_cmd_powerup(hdw);
232 } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
233 return pvr2_hdw_cmd_deep_reset(hdw);
234 } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
235 return pvr2_upload_firmware2(hdw);
236 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
237 return pvr2_hdw_cmd_decoder_reset(hdw);
238 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
239 return pvr2_hdw_untrip(hdw);
240 } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
241 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
246 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
247 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
248 if (!scnt) return -EINVAL;
249 count -= scnt; buf += scnt;
250 if (!wptr) return -EINVAL;
251 if (debugifc_match_keyword(wptr,wlen,"fetch")) {
252 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
254 count -= scnt; buf += scnt;
255 if (debugifc_match_keyword(wptr, wlen,
257 pvr2_hdw_cpufw_set_enabled(hdw, 2, !0);
258 } else if (debugifc_match_keyword(wptr, wlen,
260 pvr2_hdw_cpufw_set_enabled(hdw, 0, !0);
261 } else if (debugifc_match_keyword(wptr, wlen,
263 pvr2_hdw_cpufw_set_enabled(hdw, 1, !0);
268 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
270 } else if (debugifc_match_keyword(wptr,wlen,"done")) {
271 pvr2_hdw_cpufw_set_enabled(hdw,0,0);
276 } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
280 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
281 if (!scnt) return -EINVAL;
282 count -= scnt; buf += scnt;
283 if (!wptr) return -EINVAL;
284 if (debugifc_match_keyword(wptr,wlen,"dir")) {
286 } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
289 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
290 if (!scnt) return -EINVAL;
291 count -= scnt; buf += scnt;
292 if (!wptr) return -EINVAL;
293 ret = debugifc_parse_unsigned_number(wptr,wlen,&msk);
295 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
297 ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
304 ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
306 ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
310 pvr2_trace(PVR2_TRACE_DEBUGIFC,
311 "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
316 int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
319 unsigned int bcnt = 0;
323 for (bcnt = 0; bcnt < count; bcnt++) {
324 if (buf[bcnt] == '\n') break;
327 ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
328 if (ret < 0) return ret;
329 if (bcnt < count) bcnt++;
339 Stuff for Emacs to see, in order to encourage consistent editing style:
340 *** Local Variables: ***
342 *** fill-column: 75 ***
344 *** c-basic-offset: 8 ***