]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/media/video/pvrusb2/pvrusb2-debugifc.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[net-next-2.6.git] / drivers / media / video / pvrusb2 / pvrusb2-debugifc.c
CommitLineData
d855497e
MI
1/*
2 *
d855497e
MI
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 *
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
9 *
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.
14 *
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
18 *
19 */
20
21#include <linux/string.h>
d855497e
MI
22#include "pvrusb2-debugifc.h"
23#include "pvrusb2-hdw.h"
24#include "pvrusb2-debug.h"
d855497e
MI
25
26struct debugifc_mask_item {
27 const char *name;
28 unsigned long msk;
29};
30
d855497e
MI
31
32static unsigned int debugifc_count_whitespace(const char *buf,
33 unsigned int count)
34{
35 unsigned int scnt;
36 char ch;
37
38 for (scnt = 0; scnt < count; scnt++) {
39 ch = buf[scnt];
40 if (ch == ' ') continue;
41 if (ch == '\t') continue;
42 if (ch == '\n') continue;
43 break;
44 }
45 return scnt;
46}
47
48
49static unsigned int debugifc_count_nonwhitespace(const char *buf,
50 unsigned int count)
51{
52 unsigned int scnt;
53 char ch;
54
55 for (scnt = 0; scnt < count; scnt++) {
56 ch = buf[scnt];
57 if (ch == ' ') break;
58 if (ch == '\t') break;
59 if (ch == '\n') break;
60 }
61 return scnt;
62}
63
64
65static unsigned int debugifc_isolate_word(const char *buf,unsigned int count,
66 const char **wstrPtr,
67 unsigned int *wlenPtr)
68{
69 const char *wptr;
70 unsigned int consume_cnt = 0;
71 unsigned int wlen;
72 unsigned int scnt;
73
a0fd1cb1 74 wptr = NULL;
d855497e
MI
75 wlen = 0;
76 scnt = debugifc_count_whitespace(buf,count);
77 consume_cnt += scnt; count -= scnt; buf += scnt;
78 if (!count) goto done;
79
80 scnt = debugifc_count_nonwhitespace(buf,count);
81 if (!scnt) goto done;
82 wptr = buf;
83 wlen = scnt;
84 consume_cnt += scnt; count -= scnt; buf += scnt;
85
86 done:
87 *wstrPtr = wptr;
88 *wlenPtr = wlen;
89 return consume_cnt;
90}
91
92
93static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
94 u32 *num_ptr)
95{
96 u32 result = 0;
97 u32 val;
98 int ch;
99 int radix = 10;
100 if ((count >= 2) && (buf[0] == '0') &&
101 ((buf[1] == 'x') || (buf[1] == 'X'))) {
102 radix = 16;
103 count -= 2;
104 buf += 2;
105 } else if ((count >= 1) && (buf[0] == '0')) {
106 radix = 8;
107 }
108
109 while (count--) {
110 ch = *buf++;
111 if ((ch >= '0') && (ch <= '9')) {
112 val = ch - '0';
113 } else if ((ch >= 'a') && (ch <= 'f')) {
114 val = ch - 'a' + 10;
115 } else if ((ch >= 'A') && (ch <= 'F')) {
116 val = ch - 'A' + 10;
117 } else {
118 return -EINVAL;
119 }
120 if (val >= radix) return -EINVAL;
121 result *= radix;
122 result += val;
123 }
124 *num_ptr = result;
125 return 0;
126}
127
128
129static int debugifc_match_keyword(const char *buf,unsigned int count,
130 const char *keyword)
131{
132 unsigned int kl;
133 if (!keyword) return 0;
134 kl = strlen(keyword);
135 if (kl != count) return 0;
136 return !memcmp(buf,keyword,kl);
137}
138
139
d855497e
MI
140int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
141{
142 int bcnt = 0;
143 int ccnt;
aa976ca1
MI
144 ccnt = scnprintf(buf, acnt, "Driver hardware description: %s\n",
145 pvr2_hdw_get_desc(hdw));
146 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
681c7399 147 ccnt = scnprintf(buf,acnt,"Driver state info:\n");
d855497e 148 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
681c7399 149 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
d855497e 150 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
d855497e
MI
151
152 return bcnt;
153}
154
155
156int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
157 char *buf,unsigned int acnt)
158{
159 int bcnt = 0;
160 int ccnt;
d855497e
MI
161 int ret;
162 u32 gpio_dir,gpio_in,gpio_out;
ad0992e9
MI
163 struct pvr2_stream_stats stats;
164 struct pvr2_stream *sp;
d855497e
MI
165
166 ret = pvr2_hdw_is_hsm(hdw);
167 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
168 (ret < 0 ? "FAIL" : (ret ? "high" : "full")));
169 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
170
171 gpio_dir = 0; gpio_in = 0; gpio_out = 0;
172 pvr2_hdw_gpio_get_dir(hdw,&gpio_dir);
173 pvr2_hdw_gpio_get_out(hdw,&gpio_out);
174 pvr2_hdw_gpio_get_in(hdw,&gpio_in);
175 ccnt = scnprintf(buf,acnt,"GPIO state: dir=0x%x in=0x%x out=0x%x\n",
176 gpio_dir,gpio_in,gpio_out);
177 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
178
179 ccnt = scnprintf(buf,acnt,"Streaming is %s\n",
180 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
181 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
182
ad0992e9
MI
183
184 sp = pvr2_hdw_get_video_stream(hdw);
185 if (sp) {
186 pvr2_stream_get_stats(sp, &stats, 0);
187 ccnt = scnprintf(
188 buf,acnt,
189 "Bytes streamed=%u"
190 " URBs: queued=%u idle=%u ready=%u"
191 " processed=%u failed=%u\n",
192 stats.bytes_processed,
193 stats.buffers_in_queue,
194 stats.buffers_in_idle,
195 stats.buffers_in_ready,
196 stats.buffers_processed,
197 stats.buffers_failed);
198 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
199 }
200
d855497e
MI
201 return bcnt;
202}
203
204
07e337ee
AB
205static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
206 unsigned int count)
d855497e
MI
207{
208 const char *wptr;
209 unsigned int wlen;
210 unsigned int scnt;
211
212 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
213 if (!scnt) return 0;
214 count -= scnt; buf += scnt;
215 if (!wptr) return 0;
216
217 pvr2_trace(PVR2_TRACE_DEBUGIFC,"debugifc cmd: \"%.*s\"",wlen,wptr);
218 if (debugifc_match_keyword(wptr,wlen,"reset")) {
219 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
220 if (!scnt) return -EINVAL;
221 count -= scnt; buf += scnt;
222 if (!wptr) return -EINVAL;
223 if (debugifc_match_keyword(wptr,wlen,"cpu")) {
224 pvr2_hdw_cpureset_assert(hdw,!0);
225 pvr2_hdw_cpureset_assert(hdw,0);
226 return 0;
227 } else if (debugifc_match_keyword(wptr,wlen,"bus")) {
228 pvr2_hdw_device_reset(hdw);
229 } else if (debugifc_match_keyword(wptr,wlen,"soft")) {
230 return pvr2_hdw_cmd_powerup(hdw);
231 } else if (debugifc_match_keyword(wptr,wlen,"deep")) {
232 return pvr2_hdw_cmd_deep_reset(hdw);
233 } else if (debugifc_match_keyword(wptr,wlen,"firmware")) {
234 return pvr2_upload_firmware2(hdw);
235 } else if (debugifc_match_keyword(wptr,wlen,"decoder")) {
236 return pvr2_hdw_cmd_decoder_reset(hdw);
681c7399
MI
237 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
238 return pvr2_hdw_untrip(hdw);
ad0992e9
MI
239 } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
240 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
241 NULL, !0);
242 return 0;
d855497e
MI
243 }
244 return -EINVAL;
d855497e
MI
245 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
246 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
247 if (!scnt) return -EINVAL;
248 count -= scnt; buf += scnt;
249 if (!wptr) return -EINVAL;
250 if (debugifc_match_keyword(wptr,wlen,"fetch")) {
4db666cc
MI
251 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
252 if (scnt && wptr) {
253 count -= scnt; buf += scnt;
568efaa2
MI
254 if (debugifc_match_keyword(wptr, wlen,
255 "prom")) {
256 pvr2_hdw_cpufw_set_enabled(hdw, 2, !0);
257 } else if (debugifc_match_keyword(wptr, wlen,
258 "ram8k")) {
259 pvr2_hdw_cpufw_set_enabled(hdw, 0, !0);
260 } else if (debugifc_match_keyword(wptr, wlen,
261 "ram16k")) {
262 pvr2_hdw_cpufw_set_enabled(hdw, 1, !0);
4db666cc
MI
263 } else {
264 return -EINVAL;
265 }
266 }
267 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
d855497e
MI
268 return 0;
269 } else if (debugifc_match_keyword(wptr,wlen,"done")) {
4db666cc 270 pvr2_hdw_cpufw_set_enabled(hdw,0,0);
d855497e
MI
271 return 0;
272 } else {
273 return -EINVAL;
274 }
275 } else if (debugifc_match_keyword(wptr,wlen,"gpio")) {
276 int dir_fl = 0;
277 int ret;
278 u32 msk,val;
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")) {
284 dir_fl = !0;
285 } else if (!debugifc_match_keyword(wptr,wlen,"out")) {
286 return -EINVAL;
287 }
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);
293 if (ret) return ret;
294 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
295 if (wptr) {
296 ret = debugifc_parse_unsigned_number(wptr,wlen,&val);
297 if (ret) return ret;
298 } else {
299 val = msk;
300 msk = 0xffffffff;
301 }
302 if (dir_fl) {
303 ret = pvr2_hdw_gpio_chg_dir(hdw,msk,val);
304 } else {
305 ret = pvr2_hdw_gpio_chg_out(hdw,msk,val);
306 }
307 return ret;
308 }
309 pvr2_trace(PVR2_TRACE_DEBUGIFC,
310 "debugifc failed to recognize cmd: \"%.*s\"",wlen,wptr);
311 return -EINVAL;
312}
313
314
315int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
316 unsigned int count)
317{
318 unsigned int bcnt = 0;
319 int ret;
320
321 while (count) {
322 for (bcnt = 0; bcnt < count; bcnt++) {
323 if (buf[bcnt] == '\n') break;
324 }
325
326 ret = pvr2_debugifc_do1cmd(hdw,buf,bcnt);
327 if (ret < 0) return ret;
328 if (bcnt < count) bcnt++;
329 buf += bcnt;
330 count -= bcnt;
331 }
332
333 return 0;
334}
335
336
337/*
338 Stuff for Emacs to see, in order to encourage consistent editing style:
339 *** Local Variables: ***
340 *** mode: c ***
341 *** fill-column: 75 ***
342 *** tab-width: 8 ***
343 *** c-basic-offset: 8 ***
344 *** End: ***
345 */