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"
26 #include "pvrusb2-i2c-core.h"
28 struct debugifc_mask_item {
34 static unsigned int debugifc_count_whitespace(const char *buf,
40 for (scnt = 0; scnt < count; scnt++) {
42 if (ch == ' ') continue;
43 if (ch == '\t') continue;
44 if (ch == '\n') continue;
51 static unsigned int debugifc_count_nonwhitespace(const char *buf,
57 for (scnt = 0; scnt < count; scnt++) {
60 if (ch == '\t') break;
61 if (ch == '\n') break;
67 static unsigned int debugifc_isolate_word(const char *buf,unsigned int count,
69 unsigned int *wlenPtr)
72 unsigned int consume_cnt = 0;
78 scnt = debugifc_count_whitespace(buf,count);
79 consume_cnt += scnt; count -= scnt; buf += scnt;
80 if (!count) goto done;
82 scnt = debugifc_count_nonwhitespace(buf,count);
86 consume_cnt += scnt; count -= scnt; buf += scnt;
95 static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
102 if ((count >= 2) && (buf[0] == '0') &&
103 ((buf[1] == 'x') || (buf[1] == 'X'))) {
107 } else if ((count >= 1) && (buf[0] == '0')) {
113 if ((ch >= '0') && (ch <= '9')) {
115 } else if ((ch >= 'a') && (ch <= 'f')) {
117 } else if ((ch >= 'A') && (ch <= 'F')) {
122 if (val >= radix) return -EINVAL;
131 static int debugifc_match_keyword(const char *buf,unsigned int count,
135 if (!keyword) return 0;
136 kl = strlen(keyword);
137 if (kl != count) return 0;
138 return !memcmp(buf,keyword,kl);
142 int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
146 ccnt = scnprintf(buf,acnt,"Driver state info:\n");
147 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
148 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
149 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
150 ccnt = scnprintf(buf,acnt,"Attached I2C modules:\n");
151 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
152 ccnt = pvr2_i2c_report(hdw,buf,acnt);
153 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
159 int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
160 char *buf,unsigned int acnt)
165 u32 gpio_dir,gpio_in,gpio_out;
166 struct pvr2_stream_stats stats;
167 struct pvr2_stream *sp;
169 ret = pvr2_hdw_is_hsm(hdw);
170 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
171 (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
172 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
174 gpio_dir = 0; gpio_in = 0; gpio_out = 0;
175 pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
176 pvr2_hdw_gpio_get_out(hdw,&gpio_out);
177 pvr2_hdw_gpio_get_in(hdw,&gpio_in);
178 ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
179 gpio_dir,gpio_in,gpio_out);
180 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
182 ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
183 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
184 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
187 sp = pvr2_hdw_get_video_stream(hdw);
189 pvr2_stream_get_stats(sp, &stats, 0);
193 " URBs: queued=%u idle=%u ready=%u"
194 " processed=%u failed=%u\n",
195 stats.bytes_processed,
196 stats.buffers_in_queue,
197 stats.buffers_in_idle,
198 stats.buffers_in_ready,
199 stats.buffers_processed,
200 stats.buffers_failed);
201 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
208 static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
215 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
217 count -= scnt; buf += scnt;
220 pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
221 if (debugifc_match_keyword(wptr,wlen,"reset")) {
222 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
223 if (!scnt) return -EINVAL;
224 count -= scnt; buf += scnt;
225 if (!wptr) return -EINVAL;
226 if (debugifc_match_keyword(wptr,wlen,"cpu")) {
227 pvr2_hdw_cpureset_assert(hdw,!0);
228 pvr2_hdw_cpureset_assert(hdw,0);
230 } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
231 pvr2_hdw_device_reset(hdw);
232 } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
233 return pvr2_hdw_cmd_powerup(hdw);
234 } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
235 return pvr2_hdw_cmd_deep_reset(hdw);
236 } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
237 return pvr2_upload_firmware2(hdw);
238 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
239 return pvr2_hdw_cmd_decoder_reset(hdw);
240 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
241 return pvr2_hdw_untrip(hdw);
242 } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
243 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
248 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
249 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
250 if (!scnt) return -EINVAL;
251 count -= scnt; buf += scnt;
252 if (!wptr) return -EINVAL;
253 if (debugifc_match_keyword(wptr,wlen,"fetch")) {
254 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
256 count -= scnt; buf += scnt;
257 if (debugifc_match_keyword(wptr,wlen,"prom")) {
258 pvr2_hdw_cpufw_set_enabled(hdw,!0,!0);
259 } else if (debugifc_match_keyword(wptr,wlen,
261 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
266 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
268 } else if (debugifc_match_keyword(wptr,wlen,"done")) {
269 pvr2_hdw_cpufw_set_enabled(hdw,0,0);
274 } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
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 if (debugifc_match_keyword(wptr,wlen,"dir")) {
284 } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
287 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
288 if (!scnt) return -EINVAL;
289 count -= scnt; buf += scnt;
290 if (!wptr) return -EINVAL;
291 ret = debugifc_parse_unsigned_number(wptr,wlen,&msk);
293 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
295 ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
302 ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
304 ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
308 pvr2_trace(PVR2_TRACE_DEBUGIFC,
309 "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
314 int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
317 unsigned int bcnt = 0;
321 for (bcnt = 0; bcnt < count; bcnt++) {
322 if (buf[bcnt] == '\n') break;
325 ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
326 if (ret < 0) return ret;
327 if (bcnt < count) bcnt++;
337 Stuff for Emacs to see, in order to encourage consistent editing style:
338 *** Local Variables: ***
340 *** fill-column: 75 ***
342 *** c-basic-offset: 8 ***