aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/vivi.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2007-12-10 07:33:52 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 16:03:22 -0500
commit543323bcf49422c76cf13755ec4a90564065bb60 (patch)
tree59ee3b1b7ec077c247d1fd4f7b4bd029b3b908c0 /drivers/media/video/vivi.c
parent025341d4f0caa58f0e5eddbffd11d44e37cff974 (diff)
V4L/DVB (6758): Miscelaneous cleanups
Manually fixed all pertinent checkpatch.pl errors inside the source code. Also removed some unused code at the driver and a few minor cleanups. Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/vivi.c')
-rw-r--r--drivers/media/video/vivi.c487
1 files changed, 246 insertions, 241 deletions
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index ea9ff8a9bfdf..2bbefd926256 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -44,16 +44,13 @@
44#define WAKE_DENOMINATOR 1001 44#define WAKE_DENOMINATOR 1001
45#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */ 45#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
46 46
47/* These timers are for 1 fps - used only for testing */
48//#define WAKE_DENOMINATOR 30 /* hack for testing purposes */
49//#define BUFFER_TIMEOUT msecs_to_jiffies(5000) /* 5 seconds */
50
51#include "font.h" 47#include "font.h"
52 48
53#define VIVI_MAJOR_VERSION 0 49#define VIVI_MAJOR_VERSION 0
54#define VIVI_MINOR_VERSION 4 50#define VIVI_MINOR_VERSION 4
55#define VIVI_RELEASE 0 51#define VIVI_RELEASE 0
56#define VIVI_VERSION KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE) 52#define VIVI_VERSION \
53 KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE)
57 54
58/* Declare static vars that will be used as parameters */ 55/* Declare static vars that will be used as parameters */
59static unsigned int vid_limit = 16; /* Video memory limit, in Mb */ 56static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
@@ -72,7 +69,7 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
72 .default_value = 65535, 69 .default_value = 65535,
73 .flags = 0, 70 .flags = 0,
74 .type = V4L2_CTRL_TYPE_INTEGER, 71 .type = V4L2_CTRL_TYPE_INTEGER,
75 },{ 72 }, {
76 .id = V4L2_CID_BRIGHTNESS, 73 .id = V4L2_CID_BRIGHTNESS,
77 .type = V4L2_CTRL_TYPE_INTEGER, 74 .type = V4L2_CTRL_TYPE_INTEGER,
78 .name = "Brightness", 75 .name = "Brightness",
@@ -113,7 +110,7 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
113 110
114static int qctl_regs[ARRAY_SIZE(vivi_qctrl)]; 111static int qctl_regs[ARRAY_SIZE(vivi_qctrl)];
115 112
116#define dprintk(level,fmt, arg...) \ 113#define dprintk(level, fmt, arg...) \
117 do { \ 114 do { \
118 if (vivi.debug >= (level)) \ 115 if (vivi.debug >= (level)) \
119 printk(KERN_DEBUG "vivi: " fmt , ## arg); \ 116 printk(KERN_DEBUG "vivi: " fmt , ## arg); \
@@ -176,7 +173,7 @@ struct vivi_dev {
176 struct vivi_dmaqueue vidq; 173 struct vivi_dmaqueue vidq;
177 174
178 /* Several counters */ 175 /* Several counters */
179 int h,m,s,us,jiffies; 176 int h, m, s, us, jiffies;
180 char timestr[13]; 177 char timestr[13];
181 178
182 int mv_count; /* Controls bars movement */ 179 int mv_count; /* Controls bars movement */
@@ -187,7 +184,7 @@ struct vivi_fh {
187 184
188 /* video capture */ 185 /* video capture */
189 struct vivi_fmt *fmt; 186 struct vivi_fmt *fmt;
190 unsigned int width,height; 187 unsigned int width, height;
191 struct videobuf_queue vb_vidq; 188 struct videobuf_queue vb_vidq;
192 189
193 enum v4l2_buf_type type; 190 enum v4l2_buf_type type;
@@ -206,109 +203,113 @@ enum colors {
206 GREEN, 203 GREEN,
207 MAGENTA, 204 MAGENTA,
208 RED, 205 RED,
209 BLUE 206 BLUE,
207 BLACK,
210}; 208};
211 209
212static u8 bars[8][3] = { 210static u8 bars[8][3] = {
213 /* R G B */ 211 /* R G B */
214 {204,204,204}, /* white */ 212 {204, 204, 204}, /* white */
215 {208,208, 0}, /* ambar */ 213 {208, 208, 0}, /* ambar */
216 { 0,206,206}, /* cyan */ 214 { 0, 206, 206}, /* cyan */
217 { 0,239, 0}, /* green */ 215 { 0, 239, 0}, /* green */
218 {239, 0,239}, /* magenta */ 216 {239, 0, 239}, /* magenta */
219 {205, 0, 0}, /* red */ 217 {205, 0, 0}, /* red */
220 { 0, 0,255}, /* blue */ 218 { 0, 0, 255}, /* blue */
221 { 0, 0, 0} 219 { 0, 0, 0}, /* black */
222}; 220};
223 221
224#define TO_Y(r,g,b) (((16829*r +33039*g +6416*b + 32768)>>16)+16) 222#define TO_Y(r, g, b) \
223 (((16829 * r + 33039 * g + 6416 * b + 32768) >> 16) + 16)
225/* RGB to V(Cr) Color transform */ 224/* RGB to V(Cr) Color transform */
226#define TO_V(r,g,b) (((28784*r -24103*g -4681*b + 32768)>>16)+128) 225#define TO_V(r, g, b) \
226 (((28784 * r - 24103 * g - 4681 * b + 32768) >> 16) + 128)
227/* RGB to U(Cb) Color transform */ 227/* RGB to U(Cb) Color transform */
228#define TO_U(r,g,b) (((-9714*r -19070*g +28784*b + 32768)>>16)+128) 228#define TO_U(r, g, b) \
229 (((-9714 * r - 19070 * g + 28784 * b + 32768) >> 16) + 128)
229 230
230#define TSTAMP_MIN_Y 24 231#define TSTAMP_MIN_Y 24
231#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15 232#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15
232#define TSTAMP_MIN_X 64 233#define TSTAMP_MIN_X 64
233 234
234static void gen_line(char *basep,int inipos,int wmax, 235static void gen_line(char *basep, int inipos, int wmax,
235 int hmax, int line, int count, char *timestr) 236 int hmax, int line, int count, char *timestr)
236{ 237{
237 int w,i,j,pos=inipos,y; 238 int w, i, j, y;
238 char *p,*s; 239 int pos = inipos;
239 u8 chr,r,g,b,color; 240 char *p, *s;
241 u8 chr, r, g, b, color;
240 242
241 /* We will just duplicate the second pixel at the packet */ 243 /* We will just duplicate the second pixel at the packet */
242 wmax/=2; 244 wmax /= 2;
243 245
244 /* Generate a standard color bar pattern */ 246 /* Generate a standard color bar pattern */
245 for (w=0;w<wmax;w++) { 247 for (w = 0; w < wmax; w++) {
246 int colorpos=((w+count)*8/(wmax+1)) % 8; 248 int colorpos = ((w + count) * 8/(wmax + 1)) % 8;
247 r=bars[colorpos][0]; 249 r = bars[colorpos][0];
248 g=bars[colorpos][1]; 250 g = bars[colorpos][1];
249 b=bars[colorpos][2]; 251 b = bars[colorpos][2];
250 252
251 for (color=0;color<4;color++) { 253 for (color = 0; color < 4; color++) {
252 p=basep+pos; 254 p = basep + pos;
253 255
254 switch (color) { 256 switch (color) {
255 case 0: 257 case 0:
256 case 2: 258 case 2:
257 *p=TO_Y(r,g,b); /* Luminance */ 259 *p = TO_Y(r, g, b); /* Luma */
258 break; 260 break;
259 case 1: 261 case 1:
260 *p=TO_U(r,g,b); /* Cb */ 262 *p = TO_U(r, g, b); /* Cb */
261 break; 263 break;
262 case 3: 264 case 3:
263 *p=TO_V(r,g,b); /* Cr */ 265 *p = TO_V(r, g, b); /* Cr */
264 break; 266 break;
265 } 267 }
266 pos++; 268 pos++;
267 } 269 }
268 } 270 }
269 271
270 /* Checks if it is possible to show timestamp */ 272 /* Checks if it is possible to show timestamp */
271 if (TSTAMP_MAX_Y>=hmax) 273 if (TSTAMP_MAX_Y >= hmax)
272 goto end; 274 goto end;
273 if (TSTAMP_MIN_X+strlen(timestr)>=wmax) 275 if (TSTAMP_MIN_X + strlen(timestr) >= wmax)
274 goto end; 276 goto end;
275 277
276 /* Print stream time */ 278 /* Print stream time */
277 if (line>=TSTAMP_MIN_Y && line<=TSTAMP_MAX_Y) { 279 if (line >= TSTAMP_MIN_Y && line <= TSTAMP_MAX_Y) {
278 j=TSTAMP_MIN_X; 280 j = TSTAMP_MIN_X;
279 for (s=timestr;*s;s++) { 281 for (s = timestr; *s; s++) {
280 chr=rom8x16_bits[(*s-0x30)*16+line-TSTAMP_MIN_Y]; 282 chr = rom8x16_bits[(*s-0x30)*16+line-TSTAMP_MIN_Y];
281 for (i=0;i<7;i++) { 283 for (i = 0; i < 7; i++) {
282 if (chr&1<<(7-i)) { /* Font color*/ 284 if (chr & 1 << (7 - i)) {
283 r=bars[BLUE][0]; 285 /* Font color*/
284 g=bars[BLUE][1]; 286 r = 0;
285 b=bars[BLUE][2]; 287 g = 198;
286 r=g=b=0; 288 b = 0;
287 g=198; 289 } else {
288 } else { /* Background color */ 290 /* Background color */
289 r=bars[WHITE][0]; 291 r = bars[BLACK][0];
290 g=bars[WHITE][1]; 292 g = bars[BLACK][1];
291 b=bars[WHITE][2]; 293 b = bars[BLACK][2];
292 r=g=b=0;
293 } 294 }
294 295
295 pos=inipos+j*2; 296 pos = inipos + j * 2;
296 for (color=0;color<4;color++) { 297 for (color = 0; color < 4; color++) {
297 p=basep+pos; 298 p = basep + pos;
298 299
299 y=TO_Y(r,g,b); 300 y = TO_Y(r, g, b);
300 301
301 switch (color) { 302 switch (color) {
302 case 0: 303 case 0:
303 case 2: 304 case 2:
304 *p=TO_Y(r,g,b); /* Luminance */ 305 *p = TO_Y(r, g, b); /* Luma */
305 break; 306 break;
306 case 1: 307 case 1:
307 *p=TO_U(r,g,b); /* Cb */ 308 *p = TO_U(r, g, b); /* Cb */
308 break; 309 break;
309 case 3: 310 case 3:
310 *p=TO_V(r,g,b); /* Cr */ 311 *p = TO_V(r, g, b); /* Cr */
311 break; 312 break;
312 } 313 }
313 pos++; 314 pos++;
314 } 315 }
@@ -317,28 +318,27 @@ static void gen_line(char *basep,int inipos,int wmax,
317 } 318 }
318 } 319 }
319 320
320
321end: 321end:
322 return; 322 return;
323} 323}
324static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf) 324static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
325{ 325{
326 int h,pos=0; 326 int h , pos = 0;
327 int hmax = buf->vb.height; 327 int hmax = buf->vb.height;
328 int wmax = buf->vb.width; 328 int wmax = buf->vb.width;
329 struct timeval ts; 329 struct timeval ts;
330 char *tmpbuf = kmalloc(wmax*2,GFP_KERNEL); 330 char *tmpbuf = kmalloc(wmax * 2, GFP_KERNEL);
331 void *vbuf=videobuf_to_vmalloc (&buf->vb); 331 void *vbuf = videobuf_to_vmalloc(&buf->vb);
332 332
333 if (!tmpbuf) 333 if (!tmpbuf)
334 return; 334 return;
335 335
336 for (h=0;h<hmax;h++) { 336 for (h = 0; h < hmax; h++) {
337 gen_line(tmpbuf, 0, wmax, hmax, h, dev->mv_count, 337 gen_line(tmpbuf, 0, wmax, hmax, h, dev->mv_count,
338 dev->timestr); 338 dev->timestr);
339 /* FIXME: replacing to __copy_to_user */ 339 /* FIXME: replacing to __copy_to_user */
340 if (copy_to_user(vbuf+pos,tmpbuf,wmax*2)!=0) 340 if (copy_to_user(vbuf + pos, tmpbuf, wmax * 2) != 0)
341 dprintk(2,"vivifill copy_to_user failed.\n"); 341 dprintk(2, "vivifill copy_to_user failed.\n");
342 pos += wmax*2; 342 pos += wmax*2;
343 } 343 }
344 344
@@ -348,27 +348,27 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
348 348
349 /* Updates stream time */ 349 /* Updates stream time */
350 350
351 dev->us+=jiffies_to_usecs(jiffies-dev->jiffies); 351 dev->us += jiffies_to_usecs(jiffies-dev->jiffies);
352 dev->jiffies=jiffies; 352 dev->jiffies = jiffies;
353 if (dev->us>=1000000) { 353 if (dev->us >= 1000000) {
354 dev->us-=1000000; 354 dev->us -= 1000000;
355 dev->s++; 355 dev->s++;
356 if (dev->s>=60) { 356 if (dev->s >= 60) {
357 dev->s-=60; 357 dev->s -= 60;
358 dev->m++; 358 dev->m++;
359 if (dev->m>60) { 359 if (dev->m > 60) {
360 dev->m-=60; 360 dev->m -= 60;
361 dev->h++; 361 dev->h++;
362 if (dev->h>24) 362 if (dev->h > 24)
363 dev->h-=24; 363 dev->h -= 24;
364 } 364 }
365 } 365 }
366 } 366 }
367 sprintf(dev->timestr,"%02d:%02d:%02d:%03d", 367 sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
368 dev->h,dev->m,dev->s,(dev->us+500)/1000); 368 dev->h, dev->m, dev->s, (dev->us + 500) / 1000);
369 369
370 dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr, 370 dprintk(2, "vivifill at %s: Buffer 0x%08lx size= %d\n", dev->timestr,
371 (unsigned long)tmpbuf,pos); 371 (unsigned long)tmpbuf, pos);
372 372
373 /* Advice that buffer was filled */ 373 /* Advice that buffer was filled */
374 buf->vb.state = VIDEOBUF_DONE; 374 buf->vb.state = VIDEOBUF_DONE;
@@ -385,14 +385,14 @@ static int restart_video_queue(struct vivi_dmaqueue *dma_q);
385static void vivi_thread_tick(struct vivi_dmaqueue *dma_q) 385static void vivi_thread_tick(struct vivi_dmaqueue *dma_q)
386{ 386{
387 struct vivi_buffer *buf; 387 struct vivi_buffer *buf;
388 struct vivi_dev *dev= container_of(dma_q,struct vivi_dev,vidq); 388 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
389 389
390 int bc; 390 int bc;
391 391
392 /* Announces videobuf that all went ok */ 392 /* Announces videobuf that all went ok */
393 for (bc = 0;; bc++) { 393 for (bc = 0;; bc++) {
394 if (list_empty(&dma_q->active)) { 394 if (list_empty(&dma_q->active)) {
395 dprintk(1,"No active queue to serve\n"); 395 dprintk(1, "No active queue to serve\n");
396 break; 396 break;
397 } 397 }
398 398
@@ -406,19 +406,20 @@ static void vivi_thread_tick(struct vivi_dmaqueue *dma_q)
406 } 406 }
407 407
408 do_gettimeofday(&buf->vb.ts); 408 do_gettimeofday(&buf->vb.ts);
409 dprintk(2,"[%p/%d] wakeup\n",buf,buf->vb.i); 409 dprintk(2, "[%p/%d] wakeup\n", buf, buf->vb. i);
410 410
411 /* Fill buffer */ 411 /* Fill buffer */
412 vivi_fillbuff(dev,buf); 412 vivi_fillbuff(dev, buf);
413 413
414 if (list_empty(&dma_q->active)) { 414 if (list_empty(&dma_q->active)) {
415 del_timer(&dma_q->timeout); 415 del_timer(&dma_q->timeout);
416 } else { 416 } else {
417 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 417 mod_timer(&dma_q->timeout, jiffies + BUFFER_TIMEOUT);
418 } 418 }
419 } 419 }
420 if (bc != 1) 420 if (bc != 1)
421 dprintk(1,"%s: %d buffers handled (should be 1)\n",__FUNCTION__,bc); 421 dprintk(1, "%s: %d buffers handled (should be 1)\n",
422 __FUNCTION__, bc);
422} 423}
423 424
424static void vivi_sleep(struct vivi_dmaqueue *dma_q) 425static void vivi_sleep(struct vivi_dmaqueue *dma_q)
@@ -426,30 +427,38 @@ static void vivi_sleep(struct vivi_dmaqueue *dma_q)
426 int timeout; 427 int timeout;
427 DECLARE_WAITQUEUE(wait, current); 428 DECLARE_WAITQUEUE(wait, current);
428 429
429 dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q); 430 dprintk(1, "%s dma_q=0x%08lx\n", __FUNCTION__, (unsigned long)dma_q);
430 431
431 add_wait_queue(&dma_q->wq, &wait); 432 add_wait_queue(&dma_q->wq, &wait);
432 if (!kthread_should_stop()) { 433 if (!kthread_should_stop()) {
433 dma_q->frame++; 434 dma_q->frame++;
434 435
435 /* Calculate time to wake up */ 436 /* Calculate time to wake up */
436 timeout=dma_q->ini_jiffies+msecs_to_jiffies((dma_q->frame*WAKE_NUMERATOR*1000)/WAKE_DENOMINATOR)-jiffies; 437 timeout = dma_q->ini_jiffies+
438 msecs_to_jiffies((dma_q->frame*WAKE_NUMERATOR * 1000)
439 / WAKE_DENOMINATOR) - jiffies;
437 440
438 if (timeout <= 0) { 441 if (timeout <= 0) {
439 int old=dma_q->frame; 442 int old = dma_q->frame;
440 dma_q->frame=(jiffies_to_msecs(jiffies-dma_q->ini_jiffies)*WAKE_DENOMINATOR)/(WAKE_NUMERATOR*1000)+1; 443 dma_q->frame = (jiffies_to_msecs(jiffies -
441 444 dma_q->ini_jiffies) *
442 timeout=dma_q->ini_jiffies+msecs_to_jiffies((dma_q->frame*WAKE_NUMERATOR*1000)/WAKE_DENOMINATOR)-jiffies; 445 WAKE_DENOMINATOR) /
443 446 (WAKE_NUMERATOR * 1000) + 1;
444 dprintk(1,"underrun, losed %d frames. " 447
445 "Now, frame is %d. Waking on %d jiffies\n", 448 timeout = dma_q->ini_jiffies+
446 dma_q->frame-old,dma_q->frame,timeout); 449 msecs_to_jiffies((dma_q->frame *
450 WAKE_NUMERATOR * 1000)
451 / WAKE_DENOMINATOR) - jiffies;
452
453 dprintk(1, "underrun, losed %d frames. "
454 "Now, frame is %d. Waking on %d jiffies\n",
455 dma_q->frame-old, dma_q->frame, timeout);
447 } else 456 } else
448 dprintk(1,"will sleep for %i jiffies\n",timeout); 457 dprintk(1, "will sleep for %i jiffies\n", timeout);
449 458
450 vivi_thread_tick(dma_q); 459 vivi_thread_tick(dma_q);
451 460
452 schedule_timeout_interruptible (timeout); 461 schedule_timeout_interruptible(timeout);
453 } 462 }
454 463
455 remove_wait_queue(&dma_q->wq, &wait); 464 remove_wait_queue(&dma_q->wq, &wait);
@@ -458,9 +467,9 @@ static void vivi_sleep(struct vivi_dmaqueue *dma_q)
458 467
459static int vivi_thread(void *data) 468static int vivi_thread(void *data)
460{ 469{
461 struct vivi_dmaqueue *dma_q=data; 470 struct vivi_dmaqueue *dma_q = data;
462 471
463 dprintk(1,"thread started\n"); 472 dprintk(1, "thread started\n");
464 473
465 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 474 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
466 set_freezable(); 475 set_freezable();
@@ -477,10 +486,10 @@ static int vivi_thread(void *data)
477 486
478static int vivi_start_thread(struct vivi_dmaqueue *dma_q) 487static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
479{ 488{
480 dma_q->frame=0; 489 dma_q->frame = 0;
481 dma_q->ini_jiffies=jiffies; 490 dma_q->ini_jiffies = jiffies;
482 491
483 dprintk(1,"%s\n",__FUNCTION__); 492 dprintk(1, "%s\n", __FUNCTION__);
484 493
485 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi"); 494 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi");
486 495
@@ -491,17 +500,17 @@ static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
491 /* Wakes thread */ 500 /* Wakes thread */
492 wake_up_interruptible(&dma_q->wq); 501 wake_up_interruptible(&dma_q->wq);
493 502
494 dprintk(1,"returning from %s\n",__FUNCTION__); 503 dprintk(1, "returning from %s\n", __FUNCTION__);
495 return 0; 504 return 0;
496} 505}
497 506
498static void vivi_stop_thread(struct vivi_dmaqueue *dma_q) 507static void vivi_stop_thread(struct vivi_dmaqueue *dma_q)
499{ 508{
500 dprintk(1,"%s\n",__FUNCTION__); 509 dprintk(1, "%s\n", __FUNCTION__);
501 /* shutdown control thread */ 510 /* shutdown control thread */
502 if (dma_q->kthread) { 511 if (dma_q->kthread) {
503 kthread_stop(dma_q->kthread); 512 kthread_stop(dma_q->kthread);
504 dma_q->kthread=NULL; 513 dma_q->kthread = NULL;
505 } 514 }
506} 515}
507 516
@@ -509,16 +518,16 @@ static int restart_video_queue(struct vivi_dmaqueue *dma_q)
509{ 518{
510 struct vivi_buffer *buf, *prev; 519 struct vivi_buffer *buf, *prev;
511 520
512 dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q); 521 dprintk(1, "%s dma_q=0x%08lx\n", __FUNCTION__, (unsigned long)dma_q);
513 522
514 if (!list_empty(&dma_q->active)) { 523 if (!list_empty(&dma_q->active)) {
515 buf = list_entry(dma_q->active.next, struct vivi_buffer, vb.queue); 524 buf = list_entry(dma_q->active.next,
516 dprintk(2,"restart_queue [%p/%d]: restart dma\n", 525 struct vivi_buffer, vb.queue);
526 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
517 buf, buf->vb.i); 527 buf, buf->vb.i);
518 528
519 dprintk(1,"Restarting video dma\n"); 529 dprintk(1, "Restarting video dma\n");
520 vivi_stop_thread(dma_q); 530 vivi_stop_thread(dma_q);
521// vivi_start_thread(dma_q);
522 531
523 /* cancel all outstanding capture / vbi requests */ 532 /* cancel all outstanding capture / vbi requests */
524 list_for_each_entry_safe(buf, prev, &dma_q->active, vb.queue) { 533 list_for_each_entry_safe(buf, prev, &dma_q->active, vb.queue) {
@@ -535,28 +544,29 @@ static int restart_video_queue(struct vivi_dmaqueue *dma_q)
535 for (;;) { 544 for (;;) {
536 if (list_empty(&dma_q->queued)) 545 if (list_empty(&dma_q->queued))
537 return 0; 546 return 0;
538 buf = list_entry(dma_q->queued.next, struct vivi_buffer, vb.queue); 547 buf = list_entry(dma_q->queued.next,
548 struct vivi_buffer, vb.queue);
539 if (NULL == prev) { 549 if (NULL == prev) {
540 list_del(&buf->vb.queue); 550 list_del(&buf->vb.queue);
541 list_add_tail(&buf->vb.queue,&dma_q->active); 551 list_add_tail(&buf->vb.queue, &dma_q->active);
542 552
543 dprintk(1,"Restarting video dma\n"); 553 dprintk(1, "Restarting video dma\n");
544 vivi_stop_thread(dma_q); 554 vivi_stop_thread(dma_q);
545 vivi_start_thread(dma_q); 555 vivi_start_thread(dma_q);
546 556
547 buf->vb.state = VIDEOBUF_ACTIVE; 557 buf->vb.state = VIDEOBUF_ACTIVE;
548 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 558 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
549 dprintk(2,"[%p/%d] restart_queue - first active\n", 559 dprintk(2, "[%p/%d] restart_queue - first active\n",
550 buf,buf->vb.i); 560 buf, buf->vb.i);
551 561
552 } else if (prev->vb.width == buf->vb.width && 562 } else if (prev->vb.width == buf->vb.width &&
553 prev->vb.height == buf->vb.height && 563 prev->vb.height == buf->vb.height &&
554 prev->fmt == buf->fmt) { 564 prev->fmt == buf->fmt) {
555 list_del(&buf->vb.queue); 565 list_del(&buf->vb.queue);
556 list_add_tail(&buf->vb.queue,&dma_q->active); 566 list_add_tail(&buf->vb.queue, &dma_q->active);
557 buf->vb.state = VIDEOBUF_ACTIVE; 567 buf->vb.state = VIDEOBUF_ACTIVE;
558 dprintk(2,"[%p/%d] restart_queue - move to active\n", 568 dprintk(2, "[%p/%d] restart_queue - move to active\n",
559 buf,buf->vb.i); 569 buf, buf->vb.i);
560 } else { 570 } else {
561 return 0; 571 return 0;
562 } 572 }
@@ -566,16 +576,17 @@ static int restart_video_queue(struct vivi_dmaqueue *dma_q)
566 576
567static void vivi_vid_timeout(unsigned long data) 577static void vivi_vid_timeout(unsigned long data)
568{ 578{
569 struct vivi_dev *dev = (struct vivi_dev*)data; 579 struct vivi_dev *dev = (struct vivi_dev *)data;
570 struct vivi_dmaqueue *vidq = &dev->vidq; 580 struct vivi_dmaqueue *vidq = &dev->vidq;
571 struct vivi_buffer *buf; 581 struct vivi_buffer *buf;
572 582
573 while (!list_empty(&vidq->active)) { 583 while (!list_empty(&vidq->active)) {
574 buf = list_entry(vidq->active.next, struct vivi_buffer, vb.queue); 584 buf = list_entry(vidq->active.next,
585 struct vivi_buffer, vb.queue);
575 list_del(&buf->vb.queue); 586 list_del(&buf->vb.queue);
576 buf->vb.state = VIDEOBUF_ERROR; 587 buf->vb.state = VIDEOBUF_ERROR;
577 wake_up(&buf->vb.done); 588 wake_up(&buf->vb.done);
578 printk("vivi/0: [%p/%d] timeout\n", buf, buf->vb.i); 589 printk(KERN_INFO "vivi/0: [%p/%d] timeout\n", buf, buf->vb.i);
579 } 590 }
580 591
581 restart_video_queue(vidq); 592 restart_video_queue(vidq);
@@ -597,19 +608,19 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
597 while (*size * *count > vid_limit * 1024 * 1024) 608 while (*size * *count > vid_limit * 1024 * 1024)
598 (*count)--; 609 (*count)--;
599 610
600 dprintk(1,"%s, count=%d, size=%d\n",__FUNCTION__,*count, *size); 611 dprintk(1, "%s, count=%d, size=%d\n", __FUNCTION__, *count, *size);
601 612
602 return 0; 613 return 0;
603} 614}
604 615
605static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf) 616static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
606{ 617{
607 dprintk(1,"%s\n",__FUNCTION__); 618 dprintk(1, "%s\n", __FUNCTION__);
608 619
609 if (in_interrupt()) 620 if (in_interrupt())
610 BUG(); 621 BUG();
611 622
612 videobuf_waiton(&buf->vb,0,0); 623 videobuf_waiton(&buf->vb, 0, 0);
613 videobuf_vmalloc_free(&buf->vb); 624 videobuf_vmalloc_free(&buf->vb);
614 buf->vb.state = VIDEOBUF_NEEDS_INIT; 625 buf->vb.state = VIDEOBUF_NEEDS_INIT;
615} 626}
@@ -621,10 +632,10 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
621 enum v4l2_field field) 632 enum v4l2_field field)
622{ 633{
623 struct vivi_fh *fh = vq->priv_data; 634 struct vivi_fh *fh = vq->priv_data;
624 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb); 635 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
625 int rc, init_buffer = 0; 636 int rc, init_buffer = 0;
626 637
627 dprintk(1,"%s, field=%d\n",__FUNCTION__,field); 638 dprintk(1, "%s, field=%d\n", __FUNCTION__, field);
628 639
629 BUG_ON(NULL == fh->fmt); 640 BUG_ON(NULL == fh->fmt);
630 if (fh->width < 48 || fh->width > norm_maxw() || 641 if (fh->width < 48 || fh->width > norm_maxw() ||
@@ -646,7 +657,8 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
646 } 657 }
647 658
648 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { 659 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
649 if (0 != (rc = videobuf_iolock(vq,&buf->vb,NULL))) 660 rc = videobuf_iolock(vq, &buf->vb, NULL);
661 if (rc < 0)
650 goto fail; 662 goto fail;
651 } 663 }
652 664
@@ -655,65 +667,68 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
655 return 0; 667 return 0;
656 668
657fail: 669fail:
658 free_buffer(vq,buf); 670 free_buffer(vq, buf);
659 return rc; 671 return rc;
660} 672}
661 673
662static void 674static void
663buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) 675buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
664{ 676{
665 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb); 677 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
666 struct vivi_fh *fh = vq->priv_data; 678 struct vivi_fh *fh = vq->priv_data;
667 struct vivi_dev *dev = fh->dev; 679 struct vivi_dev *dev = fh->dev;
668 struct vivi_dmaqueue *vidq = &dev->vidq; 680 struct vivi_dmaqueue *vidq = &dev->vidq;
669 struct vivi_buffer *prev; 681 struct vivi_buffer *prev;
670 682
671 if (!list_empty(&vidq->queued)) { 683 if (!list_empty(&vidq->queued)) {
672 dprintk(1,"adding vb queue=0x%08lx\n",(unsigned long)&buf->vb.queue); 684 dprintk(1, "adding vb queue=0x%08lx\n",
673 list_add_tail(&buf->vb.queue,&vidq->queued); 685 (unsigned long)&buf->vb.queue);
686 list_add_tail(&buf->vb.queue, &vidq->queued);
674 buf->vb.state = VIDEOBUF_QUEUED; 687 buf->vb.state = VIDEOBUF_QUEUED;
675 dprintk(2,"[%p/%d] buffer_queue - append to queued\n", 688 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
676 buf, buf->vb.i); 689 buf, buf->vb.i);
677 } else if (list_empty(&vidq->active)) { 690 } else if (list_empty(&vidq->active)) {
678 list_add_tail(&buf->vb.queue,&vidq->active); 691 list_add_tail(&buf->vb.queue, &vidq->active);
679 692
680 buf->vb.state = VIDEOBUF_ACTIVE; 693 buf->vb.state = VIDEOBUF_ACTIVE;
681 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT); 694 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
682 dprintk(2,"[%p/%d] buffer_queue - first active\n", 695 dprintk(2, "[%p/%d] buffer_queue - first active\n",
683 buf, buf->vb.i); 696 buf, buf->vb.i);
684 697
685 vivi_start_thread(vidq); 698 vivi_start_thread(vidq);
686 } else { 699 } else {
687 prev = list_entry(vidq->active.prev, struct vivi_buffer, vb.queue); 700 prev = list_entry(vidq->active.prev,
701 struct vivi_buffer, vb.queue);
688 if (prev->vb.width == buf->vb.width && 702 if (prev->vb.width == buf->vb.width &&
689 prev->vb.height == buf->vb.height && 703 prev->vb.height == buf->vb.height &&
690 prev->fmt == buf->fmt) { 704 prev->fmt == buf->fmt) {
691 list_add_tail(&buf->vb.queue,&vidq->active); 705 list_add_tail(&buf->vb.queue, &vidq->active);
692 buf->vb.state = VIDEOBUF_ACTIVE; 706 buf->vb.state = VIDEOBUF_ACTIVE;
693 dprintk(2,"[%p/%d] buffer_queue - append to active\n", 707 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
694 buf, buf->vb.i); 708 buf, buf->vb.i);
695 709
696 } else { 710 } else {
697 list_add_tail(&buf->vb.queue,&vidq->queued); 711 list_add_tail(&buf->vb.queue, &vidq->queued);
698 buf->vb.state = VIDEOBUF_QUEUED; 712 buf->vb.state = VIDEOBUF_QUEUED;
699 dprintk(2,"[%p/%d] buffer_queue - first queued\n", 713 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
700 buf, buf->vb.i); 714 buf, buf->vb.i);
701 } 715 }
702 } 716 }
703} 717}
704 718
705static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb) 719static void buffer_release(struct videobuf_queue *vq,
720 struct videobuf_buffer *vb)
706{ 721{
707 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb); 722 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
708 struct vivi_fh *fh = vq->priv_data; 723 struct vivi_fh *fh = vq->priv_data;
709 struct vivi_dev *dev = (struct vivi_dev*)fh->dev; 724 struct vivi_dev *dev = (struct vivi_dev *)fh->dev;
710 struct vivi_dmaqueue *vidq = &dev->vidq; 725 struct vivi_dmaqueue *vidq = &dev->vidq;
711 726
712 dprintk(1,"%s\n",__FUNCTION__); 727 dprintk(1, "%s\n", __FUNCTION__);
713 728
714 vivi_stop_thread(vidq); 729 vivi_stop_thread(vidq);
715 730
716 free_buffer(vq,buf); 731 free_buffer(vq, buf);
717} 732}
718 733
719static struct videobuf_queue_ops vivi_video_qops = { 734static struct videobuf_queue_ops vivi_video_qops = {
@@ -726,7 +741,7 @@ static struct videobuf_queue_ops vivi_video_qops = {
726/* ------------------------------------------------------------------ 741/* ------------------------------------------------------------------
727 IOCTL vidioc handling 742 IOCTL vidioc handling
728 ------------------------------------------------------------------*/ 743 ------------------------------------------------------------------*/
729static int vidioc_querycap (struct file *file, void *priv, 744static int vidioc_querycap(struct file *file, void *priv,
730 struct v4l2_capability *cap) 745 struct v4l2_capability *cap)
731{ 746{
732 strcpy(cap->driver, "vivi"); 747 strcpy(cap->driver, "vivi");
@@ -738,21 +753,21 @@ static int vidioc_querycap (struct file *file, void *priv,
738 return 0; 753 return 0;
739} 754}
740 755
741static int vidioc_enum_fmt_cap (struct file *file, void *priv, 756static int vidioc_enum_fmt_cap(struct file *file, void *priv,
742 struct v4l2_fmtdesc *f) 757 struct v4l2_fmtdesc *f)
743{ 758{
744 if (f->index > 0) 759 if (f->index > 0)
745 return -EINVAL; 760 return -EINVAL;
746 761
747 strlcpy(f->description,format.name,sizeof(f->description)); 762 strlcpy(f->description, format.name, sizeof(f->description));
748 f->pixelformat = format.fourcc; 763 f->pixelformat = format.fourcc;
749 return 0; 764 return 0;
750} 765}
751 766
752static int vidioc_g_fmt_cap (struct file *file, void *priv, 767static int vidioc_g_fmt_cap(struct file *file, void *priv,
753 struct v4l2_format *f) 768 struct v4l2_format *f)
754{ 769{
755 struct vivi_fh *fh=priv; 770 struct vivi_fh *fh = priv;
756 771
757 f->fmt.pix.width = fh->width; 772 f->fmt.pix.width = fh->width;
758 f->fmt.pix.height = fh->height; 773 f->fmt.pix.height = fh->height;
@@ -766,7 +781,7 @@ static int vidioc_g_fmt_cap (struct file *file, void *priv,
766 return (0); 781 return (0);
767} 782}
768 783
769static int vidioc_try_fmt_cap (struct file *file, void *priv, 784static int vidioc_try_fmt_cap(struct file *file, void *priv,
770 struct v4l2_format *f) 785 struct v4l2_format *f)
771{ 786{
772 struct vivi_fmt *fmt; 787 struct vivi_fmt *fmt;
@@ -774,18 +789,18 @@ static int vidioc_try_fmt_cap (struct file *file, void *priv,
774 unsigned int maxw, maxh; 789 unsigned int maxw, maxh;
775 790
776 if (format.fourcc != f->fmt.pix.pixelformat) { 791 if (format.fourcc != f->fmt.pix.pixelformat) {
777 dprintk(1,"Fourcc format (0x%08x) invalid. Driver accepts " 792 dprintk(1, "Fourcc format (0x%08x) invalid. Driver accepts "
778 "only 0x%08x\n",f->fmt.pix.pixelformat,format.fourcc); 793 "only 0x%08x\n", f->fmt.pix.pixelformat, format.fourcc);
779 return -EINVAL; 794 return -EINVAL;
780 } 795 }
781 fmt=&format; 796 fmt = &format;
782 797
783 field = f->fmt.pix.field; 798 field = f->fmt.pix.field;
784 799
785 if (field == V4L2_FIELD_ANY) { 800 if (field == V4L2_FIELD_ANY) {
786 field=V4L2_FIELD_INTERLACED; 801 field = V4L2_FIELD_INTERLACED;
787 } else if (V4L2_FIELD_INTERLACED != field) { 802 } else if (V4L2_FIELD_INTERLACED != field) {
788 dprintk(1,"Field type invalid.\n"); 803 dprintk(1, "Field type invalid.\n");
789 return -EINVAL; 804 return -EINVAL;
790 } 805 }
791 806
@@ -811,11 +826,11 @@ static int vidioc_try_fmt_cap (struct file *file, void *priv,
811} 826}
812 827
813/*FIXME: This seems to be generic enough to be at videodev2 */ 828/*FIXME: This seems to be generic enough to be at videodev2 */
814static int vidioc_s_fmt_cap (struct file *file, void *priv, 829static int vidioc_s_fmt_cap(struct file *file, void *priv,
815 struct v4l2_format *f) 830 struct v4l2_format *f)
816{ 831{
817 struct vivi_fh *fh=priv; 832 struct vivi_fh *fh = priv;
818 int ret = vidioc_try_fmt_cap(file,fh,f); 833 int ret = vidioc_try_fmt_cap(file, fh, f);
819 if (ret < 0) 834 if (ret < 0)
820 return (ret); 835 return (ret);
821 836
@@ -828,47 +843,48 @@ static int vidioc_s_fmt_cap (struct file *file, void *priv,
828 return (0); 843 return (0);
829} 844}
830 845
831static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p) 846static int vidioc_reqbufs(struct file *file, void *priv,
847 struct v4l2_requestbuffers *p)
832{ 848{
833 struct vivi_fh *fh=priv; 849 struct vivi_fh *fh = priv;
834 850
835 return (videobuf_reqbufs(&fh->vb_vidq, p)); 851 return (videobuf_reqbufs(&fh->vb_vidq, p));
836} 852}
837 853
838static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p) 854static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
839{ 855{
840 struct vivi_fh *fh=priv; 856 struct vivi_fh *fh = priv;
841 857
842 return (videobuf_querybuf(&fh->vb_vidq, p)); 858 return (videobuf_querybuf(&fh->vb_vidq, p));
843} 859}
844 860
845static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p) 861static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
846{ 862{
847 struct vivi_fh *fh=priv; 863 struct vivi_fh *fh = priv;
848 864
849 return (videobuf_qbuf(&fh->vb_vidq, p)); 865 return (videobuf_qbuf(&fh->vb_vidq, p));
850} 866}
851 867
852static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p) 868static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
853{ 869{
854 struct vivi_fh *fh=priv; 870 struct vivi_fh *fh = priv;
855 871
856 return (videobuf_dqbuf(&fh->vb_vidq, p, 872 return (videobuf_dqbuf(&fh->vb_vidq, p,
857 file->f_flags & O_NONBLOCK)); 873 file->f_flags & O_NONBLOCK));
858} 874}
859 875
860#ifdef CONFIG_VIDEO_V4L1_COMPAT 876#ifdef CONFIG_VIDEO_V4L1_COMPAT
861static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf) 877static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
862{ 878{
863 struct vivi_fh *fh=priv; 879 struct vivi_fh *fh = priv;
864 880
865 return videobuf_cgmbuf (&fh->vb_vidq, mbuf, 8); 881 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
866} 882}
867#endif 883#endif
868 884
869static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 885static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
870{ 886{
871 struct vivi_fh *fh=priv; 887 struct vivi_fh *fh = priv;
872 888
873 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 889 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
874 return -EINVAL; 890 return -EINVAL;
@@ -880,7 +896,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
880 896
881static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) 897static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
882{ 898{
883 struct vivi_fh *fh=priv; 899 struct vivi_fh *fh = priv;
884 900
885 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 901 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
886 return -EINVAL; 902 return -EINVAL;
@@ -890,13 +906,13 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
890 return videobuf_streamoff(&fh->vb_vidq); 906 return videobuf_streamoff(&fh->vb_vidq);
891} 907}
892 908
893static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *i) 909static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
894{ 910{
895 return 0; 911 return 0;
896} 912}
897 913
898/* only one input in this sample driver */ 914/* only one input in this sample driver */
899static int vidioc_enum_input (struct file *file, void *priv, 915static int vidioc_enum_input(struct file *file, void *priv,
900 struct v4l2_input *inp) 916 struct v4l2_input *inp)
901{ 917{
902 if (inp->index != 0) 918 if (inp->index != 0)
@@ -904,18 +920,18 @@ static int vidioc_enum_input (struct file *file, void *priv,
904 920
905 inp->type = V4L2_INPUT_TYPE_CAMERA; 921 inp->type = V4L2_INPUT_TYPE_CAMERA;
906 inp->std = V4L2_STD_NTSC_M; 922 inp->std = V4L2_STD_NTSC_M;
907 strcpy(inp->name,"Camera"); 923 strcpy(inp->name, "Camera");
908 924
909 return (0); 925 return (0);
910} 926}
911 927
912static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) 928static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
913{ 929{
914 *i = 0; 930 *i = 0;
915 931
916 return (0); 932 return (0);
917} 933}
918static int vidioc_s_input (struct file *file, void *priv, unsigned int i) 934static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
919{ 935{
920 if (i > 0) 936 if (i > 0)
921 return -EINVAL; 937 return -EINVAL;
@@ -924,8 +940,8 @@ static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
924} 940}
925 941
926 /* --- controls ---------------------------------------------- */ 942 /* --- controls ---------------------------------------------- */
927static int vidioc_queryctrl (struct file *file, void *priv, 943static int vidioc_queryctrl(struct file *file, void *priv,
928 struct v4l2_queryctrl *qc) 944 struct v4l2_queryctrl *qc)
929{ 945{
930 int i; 946 int i;
931 947
@@ -939,33 +955,31 @@ static int vidioc_queryctrl (struct file *file, void *priv,
939 return -EINVAL; 955 return -EINVAL;
940} 956}
941 957
942static int vidioc_g_ctrl (struct file *file, void *priv, 958static int vidioc_g_ctrl(struct file *file, void *priv,
943 struct v4l2_control *ctrl) 959 struct v4l2_control *ctrl)
944{ 960{
945 int i; 961 int i;
946 962
947 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) 963 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
948 if (ctrl->id == vivi_qctrl[i].id) { 964 if (ctrl->id == vivi_qctrl[i].id) {
949 ctrl->value=qctl_regs[i]; 965 ctrl->value = qctl_regs[i];
950 return (0); 966 return (0);
951 } 967 }
952 968
953 return -EINVAL; 969 return -EINVAL;
954} 970}
955static int vidioc_s_ctrl (struct file *file, void *priv, 971static int vidioc_s_ctrl(struct file *file, void *priv,
956 struct v4l2_control *ctrl) 972 struct v4l2_control *ctrl)
957{ 973{
958 int i; 974 int i;
959 975
960 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) 976 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
961 if (ctrl->id == vivi_qctrl[i].id) { 977 if (ctrl->id == vivi_qctrl[i].id) {
962 if (ctrl->value < 978 if (ctrl->value < vivi_qctrl[i].minimum
963 vivi_qctrl[i].minimum 979 || ctrl->value > vivi_qctrl[i].maximum) {
964 || ctrl->value >
965 vivi_qctrl[i].maximum) {
966 return (-ERANGE); 980 return (-ERANGE);
967 } 981 }
968 qctl_regs[i]=ctrl->value; 982 qctl_regs[i] = ctrl->value;
969 return (0); 983 return (0);
970 } 984 }
971 return -EINVAL; 985 return -EINVAL;
@@ -984,16 +998,14 @@ static int vivi_open(struct inode *inode, struct file *file)
984 struct vivi_fh *fh; 998 struct vivi_fh *fh;
985 int i; 999 int i;
986 1000
987 printk(KERN_DEBUG "vivi: open called (minor=%d)\n",minor); 1001 printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor);
988 1002
989 list_for_each_entry(dev, &vivi_devlist, vivi_devlist) 1003 list_for_each_entry(dev, &vivi_devlist, vivi_devlist)
990 if (dev->vfd->minor == minor) 1004 if (dev->vfd->minor == minor)
991 goto found; 1005 goto found;
992 return -ENODEV; 1006 return -ENODEV;
993found:
994
995
996 1007
1008found:
997 /* If more than one user, mutex should be added */ 1009 /* If more than one user, mutex should be added */
998 dev->users++; 1010 dev->users++;
999 1011
@@ -1001,7 +1013,7 @@ found:
1001 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users); 1013 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
1002 1014
1003 /* allocate + initialize per filehandle data */ 1015 /* allocate + initialize per filehandle data */
1004 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1016 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1005 if (NULL == fh) { 1017 if (NULL == fh) {
1006 dev->users--; 1018 dev->users--;
1007 return -ENOMEM; 1019 return -ENOMEM;
@@ -1017,27 +1029,21 @@ found:
1017 1029
1018 /* Put all controls at a sane state */ 1030 /* Put all controls at a sane state */
1019 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) 1031 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1020 qctl_regs[i] =vivi_qctrl[i].default_value; 1032 qctl_regs[i] = vivi_qctrl[i].default_value;
1021
1022 dprintk(1,"Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n",
1023 (unsigned long)fh,(unsigned long)dev,(unsigned long)&dev->vidq);
1024 dprintk(1,"Open: list_empty queued=%d\n",list_empty(&dev->vidq.queued));
1025 dprintk(1,"Open: list_empty active=%d\n",list_empty(&dev->vidq.active));
1026 1033
1027 /* Resets frame counters */ 1034 /* Resets frame counters */
1028 dev->h=0; 1035 dev->h = 0;
1029 dev->m=0; 1036 dev->m = 0;
1030 dev->s=0; 1037 dev->s = 0;
1031 dev->us=0; 1038 dev->us = 0;
1032 dev->jiffies=jiffies; 1039 dev->mv_count = 0;
1033 sprintf(dev->timestr,"%02d:%02d:%02d:%03d", 1040 dev->jiffies = jiffies;
1034 dev->h,dev->m,dev->s,(dev->us+500)/1000); 1041 sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
1042 dev->h, dev->m, dev->s, (dev->us + 500) / 1000);
1035 1043
1036 videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops, 1044 videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops,
1037 NULL, NULL, 1045 NULL, NULL, fh->type, V4L2_FIELD_INTERLACED,
1038 fh->type, 1046 sizeof(struct vivi_buffer), fh);
1039 V4L2_FIELD_INTERLACED,
1040 sizeof(struct vivi_buffer),fh);
1041 1047
1042 return 0; 1048 return 0;
1043} 1049}
@@ -1045,9 +1051,9 @@ found:
1045static ssize_t 1051static ssize_t
1046vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos) 1052vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1047{ 1053{
1048 struct vivi_fh *fh = file->private_data; 1054 struct vivi_fh *fh = file->private_data;
1049 1055
1050 if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1056 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1051 return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0, 1057 return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0,
1052 file->f_flags & O_NONBLOCK); 1058 file->f_flags & O_NONBLOCK);
1053 } 1059 }
@@ -1060,7 +1066,7 @@ vivi_poll(struct file *file, struct poll_table_struct *wait)
1060 struct vivi_fh *fh = file->private_data; 1066 struct vivi_fh *fh = file->private_data;
1061 struct videobuf_queue *q = &fh->vb_vidq; 1067 struct videobuf_queue *q = &fh->vb_vidq;
1062 1068
1063 dprintk(1,"%s\n",__FUNCTION__); 1069 dprintk(1, "%s\n", __FUNCTION__);
1064 1070
1065 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 1071 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1066 return POLLERR; 1072 return POLLERR;
@@ -1084,7 +1090,7 @@ static int vivi_close(struct inode *inode, struct file *file)
1084 1090
1085 dev->users--; 1091 dev->users--;
1086 1092
1087 printk(KERN_DEBUG "vivi: close called (minor=%d, users=%d)\n",minor,dev->users); 1093 dprintk(1, "close called (minor=%d, users=%d)\n", minor, dev->users);
1088 1094
1089 return 0; 1095 return 0;
1090} 1096}
@@ -1110,17 +1116,16 @@ static int vivi_release(void)
1110 return 0; 1116 return 0;
1111} 1117}
1112 1118
1113static int 1119static int vivi_mmap(struct file *file, struct vm_area_struct *vma)
1114vivi_mmap(struct file *file, struct vm_area_struct * vma)
1115{ 1120{
1116 struct vivi_fh *fh = file->private_data; 1121 struct vivi_fh *fh = file->private_data;
1117 int ret; 1122 int ret;
1118 1123
1119 dprintk (1,"mmap called, vma=0x%08lx\n",(unsigned long)vma); 1124 dprintk(1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
1120 1125
1121 ret=videobuf_mmap_mapper(&fh->vb_vidq, vma); 1126 ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1122 1127
1123 dprintk (1,"vma start=0x%08lx, size=%ld, ret=%d\n", 1128 dprintk(1, "vma start=0x%08lx, size=%ld, ret=%d\n",
1124 (unsigned long)vma->vm_start, 1129 (unsigned long)vma->vm_start,
1125 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, 1130 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
1126 ret); 1131 ret);