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 state info:\n");
146 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
147 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
148 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
154 int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
155 char *buf,unsigned int acnt)
160 u32 gpio_dir,gpio_in,gpio_out;
161 struct pvr2_stream_stats stats;
162 struct pvr2_stream *sp;
164 ret = pvr2_hdw_is_hsm(hdw);
165 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
166 (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
167 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
169 gpio_dir = 0; gpio_in = 0; gpio_out = 0;
170 pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
171 pvr2_hdw_gpio_get_out(hdw,&gpio_out);
172 pvr2_hdw_gpio_get_in(hdw,&gpio_in);
173 ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
174 gpio_dir,gpio_in,gpio_out);
175 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
177 ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
178 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
179 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
182 sp = pvr2_hdw_get_video_stream(hdw);
184 pvr2_stream_get_stats(sp, &stats, 0);
188 " URBs: queued=%u idle=%u ready=%u"
189 " processed=%u failed=%u\n",
190 stats.bytes_processed,
191 stats.buffers_in_queue,
192 stats.buffers_in_idle,
193 stats.buffers_in_ready,
194 stats.buffers_processed,
195 stats.buffers_failed);
196 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
203 static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
210 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
212 count -= scnt; buf += scnt;
215 pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
216 if (debugifc_match_keyword(wptr,wlen,"reset")) {
217 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
218 if (!scnt) return -EINVAL;
219 count -= scnt; buf += scnt;
220 if (!wptr) return -EINVAL;
221 if (debugifc_match_keyword(wptr,wlen,"cpu")) {
222 pvr2_hdw_cpureset_assert(hdw,!0);
223 pvr2_hdw_cpureset_assert(hdw,0);
225 } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
226 pvr2_hdw_device_reset(hdw);
227 } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
228 return pvr2_hdw_cmd_powerup(hdw);
229 } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
230 return pvr2_hdw_cmd_deep_reset(hdw);
231 } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
232 return pvr2_upload_firmware2(hdw);
233 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
234 return pvr2_hdw_cmd_decoder_reset(hdw);
235 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
236 return pvr2_hdw_untrip(hdw);
237 } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
238 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
243 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
244 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
245 if (!scnt) return -EINVAL;
246 count -= scnt; buf += scnt;
247 if (!wptr) return -EINVAL;
248 if (debugifc_match_keyword(wptr,wlen,"fetch")) {
249 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
251 count -= scnt; buf += scnt;
252 if (debugifc_match_keyword(wptr,wlen,"prom")) {
253 pvr2_hdw_cpufw_set_enabled(hdw,!0,!0);
254 } else if (debugifc_match_keyword(wptr,wlen,
256 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
261 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
263 } else if (debugifc_match_keyword(wptr,wlen,"done")) {
264 pvr2_hdw_cpufw_set_enabled(hdw,0,0);
269 } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
273 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
274 if (!scnt) return -EINVAL;
275 count -= scnt; buf += scnt;
276 if (!wptr) return -EINVAL;
277 if (debugifc_match_keyword(wptr,wlen,"dir")) {
279 } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
282 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
283 if (!scnt) return -EINVAL;
284 count -= scnt; buf += scnt;
285 if (!wptr) return -EINVAL;
286 ret = debugifc_parse_unsigned_number(wptr,wlen,&msk);
288 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
290 ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
297 ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
299 ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
303 pvr2_trace(PVR2_TRACE_DEBUGIFC,
304 "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
309 int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
312 unsigned int bcnt = 0;
316 for (bcnt = 0; bcnt < count; bcnt++) {
317 if (buf[bcnt] == '\n') break;
320 ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
321 if (ret < 0) return ret;
322 if (bcnt < count) bcnt++;
332 Stuff for Emacs to see, in order to encourage consistent editing style:
333 *** Local Variables: ***
335 *** fill-column: 75 ***
337 *** c-basic-offset: 8 ***