5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/string.h>
23 #include <linux/slab.h>
24 #include "pvrusb2-debugifc.h"
25 #include "pvrusb2-hdw.h"
26 #include "pvrusb2-debug.h"
27 #include "pvrusb2-i2c-core.h"
29 struct debugifc_mask_item
{
35 static unsigned int debugifc_count_whitespace(const char *buf
,
41 for (scnt
= 0; scnt
< count
; scnt
++) {
43 if (ch
== ' ') continue;
44 if (ch
== '\t') continue;
45 if (ch
== '\n') continue;
52 static unsigned int debugifc_count_nonwhitespace(const char *buf
,
58 for (scnt
= 0; scnt
< count
; scnt
++) {
61 if (ch
== '\t') break;
62 if (ch
== '\n') break;
68 static unsigned int debugifc_isolate_word(const char *buf
,unsigned int count
,
70 unsigned int *wlenPtr
)
73 unsigned int consume_cnt
= 0;
79 scnt
= debugifc_count_whitespace(buf
,count
);
80 consume_cnt
+= scnt
; count
-= scnt
; buf
+= scnt
;
81 if (!count
) goto done
;
83 scnt
= debugifc_count_nonwhitespace(buf
,count
);
87 consume_cnt
+= scnt
; count
-= scnt
; buf
+= scnt
;
96 static int debugifc_parse_unsigned_number(const char *buf
,unsigned int count
,
103 if ((count
>= 2) && (buf
[0] == '0') &&
104 ((buf
[1] == 'x') || (buf
[1] == 'X'))) {
108 } else if ((count
>= 1) && (buf
[0] == '0')) {
114 if ((ch
>= '0') && (ch
<= '9')) {
116 } else if ((ch
>= 'a') && (ch
<= 'f')) {
118 } else if ((ch
>= 'A') && (ch
<= 'F')) {
123 if (val
>= radix
) return -EINVAL
;
132 static int debugifc_match_keyword(const char *buf
,unsigned int count
,
136 if (!keyword
) return 0;
137 kl
= strlen(keyword
);
138 if (kl
!= count
) return 0;
139 return !memcmp(buf
,keyword
,kl
);
143 int pvr2_debugifc_print_info(struct pvr2_hdw
*hdw
,char *buf
,unsigned int acnt
)
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
;
151 ccnt
= scnprintf(buf
,acnt
,"Attached I2C modules:\n");
152 bcnt
+= ccnt
; acnt
-= ccnt
; buf
+= ccnt
;
153 ccnt
= pvr2_i2c_report(hdw
,buf
,acnt
);
154 bcnt
+= ccnt
; acnt
-= ccnt
; buf
+= ccnt
;
160 int pvr2_debugifc_print_status(struct pvr2_hdw
*hdw
,
161 char *buf
,unsigned int acnt
)
166 u32 gpio_dir
,gpio_in
,gpio_out
;
167 struct pvr2_stream_stats stats
;
168 struct pvr2_stream
*sp
;
170 ret
= pvr2_hdw_is_hsm(hdw
);
171 ccnt
= scnprintf(buf
,acnt
,"USB link speed: %s\n",
172 (ret
< 0 ? "FAIL" : (ret
? "high" : "full")));
173 bcnt
+= ccnt
; acnt
-= ccnt
; buf
+= ccnt
;
175 gpio_dir
= 0; gpio_in
= 0; gpio_out
= 0;
176 pvr2_hdw_gpio_get_dir(hdw
,&gpio_dir
);
177 pvr2_hdw_gpio_get_out(hdw
,&gpio_out
);
178 pvr2_hdw_gpio_get_in(hdw
,&gpio_in
);
179 ccnt
= scnprintf(buf
,acnt
,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
180 gpio_dir
,gpio_in
,gpio_out
);
181 bcnt
+= ccnt
; acnt
-= ccnt
; buf
+= ccnt
;
183 ccnt
= scnprintf(buf
,acnt
,"Streaming is %s\n",
184 pvr2_hdw_get_streaming(hdw
) ? "on" : "off");
185 bcnt
+= ccnt
; acnt
-= ccnt
; buf
+= ccnt
;
188 sp
= pvr2_hdw_get_video_stream(hdw
);
190 pvr2_stream_get_stats(sp
, &stats
, 0);
194 " URBs: queued=%u idle=%u ready=%u"
195 " processed=%u failed=%u\n",
196 stats
.bytes_processed
,
197 stats
.buffers_in_queue
,
198 stats
.buffers_in_idle
,
199 stats
.buffers_in_ready
,
200 stats
.buffers_processed
,
201 stats
.buffers_failed
);
202 bcnt
+= ccnt
; acnt
-= ccnt
; buf
+= ccnt
;
209 static int pvr2_debugifc_do1cmd(struct pvr2_hdw
*hdw
,const char *buf
,
216 scnt
= debugifc_isolate_word(buf
,count
,&wptr
,&wlen
);
218 count
-= scnt
; buf
+= scnt
;
221 pvr2_trace(PVR2_TRACE_DEBUGIFC
,"debugifc cmd: \"%.*s\"",wlen
,wptr
);
222 if (debugifc_match_keyword(wptr
,wlen
,"reset")) {
223 scnt
= debugifc_isolate_word(buf
,count
,&wptr
,&wlen
);
224 if (!scnt
) return -EINVAL
;
225 count
-= scnt
; buf
+= scnt
;
226 if (!wptr
) return -EINVAL
;
227 if (debugifc_match_keyword(wptr
,wlen
,"cpu")) {
228 pvr2_hdw_cpureset_assert(hdw
,!0);
229 pvr2_hdw_cpureset_assert(hdw
,0);
231 } else if (debugifc_match_keyword(wptr
,wlen
,"bus")) {
232 pvr2_hdw_device_reset(hdw
);
233 } else if (debugifc_match_keyword(wptr
,wlen
,"soft")) {
234 return pvr2_hdw_cmd_powerup(hdw
);
235 } else if (debugifc_match_keyword(wptr
,wlen
,"deep")) {
236 return pvr2_hdw_cmd_deep_reset(hdw
);
237 } else if (debugifc_match_keyword(wptr
,wlen
,"firmware")) {
238 return pvr2_upload_firmware2(hdw
);
239 } else if (debugifc_match_keyword(wptr
,wlen
,"decoder")) {
240 return pvr2_hdw_cmd_decoder_reset(hdw
);
241 } else if (debugifc_match_keyword(wptr
,wlen
,"worker")) {
242 return pvr2_hdw_untrip(hdw
);
243 } else if (debugifc_match_keyword(wptr
,wlen
,"usbstats")) {
244 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw
),
249 } else if (debugifc_match_keyword(wptr
,wlen
,"cpufw")) {
250 scnt
= debugifc_isolate_word(buf
,count
,&wptr
,&wlen
);
251 if (!scnt
) return -EINVAL
;
252 count
-= scnt
; buf
+= scnt
;
253 if (!wptr
) return -EINVAL
;
254 if (debugifc_match_keyword(wptr
,wlen
,"fetch")) {
255 scnt
= debugifc_isolate_word(buf
,count
,&wptr
,&wlen
);
257 count
-= scnt
; buf
+= scnt
;
258 if (debugifc_match_keyword(wptr
,wlen
,"prom")) {
259 pvr2_hdw_cpufw_set_enabled(hdw
,!0,!0);
260 } else if (debugifc_match_keyword(wptr
,wlen
,
262 pvr2_hdw_cpufw_set_enabled(hdw
,0,!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 ***