aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/cx25821/cx25821-video.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/cx25821/cx25821-video.c')
-rw-r--r--drivers/staging/cx25821/cx25821-video.c694
1 files changed, 347 insertions, 347 deletions
diff --git a/drivers/staging/cx25821/cx25821-video.c b/drivers/staging/cx25821/cx25821-video.c
index 512cbe3bae8..ba8115b6e0a 100644
--- a/drivers/staging/cx25821/cx25821-video.c
+++ b/drivers/staging/cx25821/cx25821-video.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the Conexant CX25821 PCIe bridge 2 * Driver for the Conexant CX25821 PCIe bridge
3 * 3 *
4 * Copyright (C) 2009 Conexant Systems Inc. 4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com> 5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver 6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
7 * 7 *
@@ -54,30 +54,30 @@ static void init_controls(struct cx25821_dev *dev, int chan_num);
54 54
55struct cx25821_fmt formats[] = { 55struct cx25821_fmt formats[] = {
56 { 56 {
57 .name = "8 bpp, gray", 57 .name = "8 bpp, gray",
58 .fourcc = V4L2_PIX_FMT_GREY, 58 .fourcc = V4L2_PIX_FMT_GREY,
59 .depth = 8, 59 .depth = 8,
60 .flags = FORMAT_FLAGS_PACKED, 60 .flags = FORMAT_FLAGS_PACKED,
61 }, { 61 }, {
62 .name = "4:1:1, packed, Y41P", 62 .name = "4:1:1, packed, Y41P",
63 .fourcc = V4L2_PIX_FMT_Y41P, 63 .fourcc = V4L2_PIX_FMT_Y41P,
64 .depth = 12, 64 .depth = 12,
65 .flags = FORMAT_FLAGS_PACKED, 65 .flags = FORMAT_FLAGS_PACKED,
66 }, { 66 }, {
67 .name = "4:2:2, packed, YUYV", 67 .name = "4:2:2, packed, YUYV",
68 .fourcc = V4L2_PIX_FMT_YUYV, 68 .fourcc = V4L2_PIX_FMT_YUYV,
69 .depth = 16, 69 .depth = 16,
70 .flags = FORMAT_FLAGS_PACKED, 70 .flags = FORMAT_FLAGS_PACKED,
71 }, { 71 }, {
72 .name = "4:2:2, packed, UYVY", 72 .name = "4:2:2, packed, UYVY",
73 .fourcc = V4L2_PIX_FMT_UYVY, 73 .fourcc = V4L2_PIX_FMT_UYVY,
74 .depth = 16, 74 .depth = 16,
75 .flags = FORMAT_FLAGS_PACKED, 75 .flags = FORMAT_FLAGS_PACKED,
76 },{ 76 },{
77 .name = "4:2:0, YUV", 77 .name = "4:2:0, YUV",
78 .fourcc = V4L2_PIX_FMT_YUV420, 78 .fourcc = V4L2_PIX_FMT_YUV420,
79 .depth = 12, 79 .depth = 12,
80 .flags = FORMAT_FLAGS_PACKED, 80 .flags = FORMAT_FLAGS_PACKED,
81 }, 81 },
82}; 82};
83 83
@@ -94,12 +94,12 @@ struct cx25821_fmt *format_by_fourcc(unsigned int fourcc)
94 94
95 if( fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P ) 95 if( fourcc == V4L2_PIX_FMT_Y41P || fourcc == V4L2_PIX_FMT_YUV411P )
96 { 96 {
97 return formats+1; 97 return formats+1;
98 } 98 }
99 99
100 for (i = 0; i < ARRAY_SIZE(formats); i++) 100 for (i = 0; i < ARRAY_SIZE(formats); i++)
101 if (formats[i].fourcc == fourcc) 101 if (formats[i].fourcc == fourcc)
102 return formats+i; 102 return formats+i;
103 103
104 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc); 104 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc);
105 return NULL; 105 return NULL;
@@ -112,14 +112,14 @@ void dump_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue *q)
112 dprintk(1, "%s()\n", __func__); 112 dprintk(1, "%s()\n", __func__);
113 113
114 if (!list_empty(&q->active)) { 114 if (!list_empty(&q->active)) {
115 list_for_each(item, &q->active) 115 list_for_each(item, &q->active)
116 buf = list_entry(item, struct cx25821_buffer, vb.queue); 116 buf = list_entry(item, struct cx25821_buffer, vb.queue);
117 } 117 }
118 118
119 if (!list_empty(&q->queued)) 119 if (!list_empty(&q->queued))
120 { 120 {
121 list_for_each(item, &q->queued) 121 list_for_each(item, &q->queued)
122 buf = list_entry(item, struct cx25821_buffer, vb.queue); 122 buf = list_entry(item, struct cx25821_buffer, vb.queue);
123 } 123 }
124 124
125} 125}
@@ -131,63 +131,63 @@ void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q, u
131 int bc; 131 int bc;
132 132
133 for (bc = 0;; bc++) { 133 for (bc = 0;; bc++) {
134 if (list_empty(&q->active)) 134 if (list_empty(&q->active))
135 { 135 {
136 dprintk(1, "bc=%d (=0: active empty)\n", bc); 136 dprintk(1, "bc=%d (=0: active empty)\n", bc);
137 break; 137 break;
138 } 138 }
139 139
140 buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue); 140 buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue);
141 141
142 /* count comes from the hw and it is 16bit wide -- 142 /* count comes from the hw and it is 16bit wide --
143 * this trick handles wrap-arounds correctly for 143 * this trick handles wrap-arounds correctly for
144 * up to 32767 buffers in flight... */ 144 * up to 32767 buffers in flight... */
145 if ((s16) (count - buf->count) < 0) 145 if ((s16) (count - buf->count) < 0)
146 { 146 {
147 break; 147 break;
148 } 148 }
149 149
150 do_gettimeofday(&buf->vb.ts); 150 do_gettimeofday(&buf->vb.ts);
151 buf->vb.state = VIDEOBUF_DONE; 151 buf->vb.state = VIDEOBUF_DONE;
152 list_del(&buf->vb.queue); 152 list_del(&buf->vb.queue);
153 wake_up(&buf->vb.done); 153 wake_up(&buf->vb.done);
154 } 154 }
155 155
156 if (list_empty(&q->active)) 156 if (list_empty(&q->active))
157 del_timer(&q->timeout); 157 del_timer(&q->timeout);
158 else 158 else
159 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 159 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
160 if (bc != 1) 160 if (bc != 1)
161 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n", __func__, bc); 161 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n", __func__, bc);
162} 162}
163 163
164#ifdef TUNER_FLAG 164#ifdef TUNER_FLAG
165int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm) 165int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm)
166{ 166{
167 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", __func__, 167 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", __func__,
168 (unsigned int)norm, 168 (unsigned int)norm,
169 v4l2_norm_to_name(norm)); 169 v4l2_norm_to_name(norm));
170 170
171 dev->tvnorm = norm; 171 dev->tvnorm = norm;
172 172
173 /* Tell the internal A/V decoder */ 173 /* Tell the internal A/V decoder */
174 cx25821_call_all(dev, core, s_std, norm); 174 cx25821_call_all(dev, core, s_std, norm);
175 175
176 return 0; 176 return 0;
177} 177}
178#endif 178#endif
179 179
180struct video_device *cx25821_vdev_init(struct cx25821_dev *dev, 180struct video_device *cx25821_vdev_init(struct cx25821_dev *dev,
181 struct pci_dev *pci, 181 struct pci_dev *pci,
182 struct video_device *template, 182 struct video_device *template,
183 char *type) 183 char *type)
184{ 184{
185 struct video_device *vfd; 185 struct video_device *vfd;
186 dprintk(1, "%s()\n", __func__); 186 dprintk(1, "%s()\n", __func__);
187 187
188 vfd = video_device_alloc(); 188 vfd = video_device_alloc();
189 if (NULL == vfd) 189 if (NULL == vfd)
190 return NULL; 190 return NULL;
191 *vfd = *template; 191 *vfd = *template;
192 vfd->minor = -1; 192 vfd->minor = -1;
193 vfd->v4l2_dev = &dev->v4l2_dev; 193 vfd->v4l2_dev = &dev->v4l2_dev;
@@ -202,13 +202,13 @@ static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
202 int i; 202 int i;
203 203
204 if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1) 204 if (qctrl->id < V4L2_CID_BASE || qctrl->id >= V4L2_CID_LASTP1)
205 return -EINVAL; 205 return -EINVAL;
206 for (i = 0; i < CX25821_CTLS; i++) 206 for (i = 0; i < CX25821_CTLS; i++)
207 if (cx25821_ctls[i].v.id == qctrl->id) 207 if (cx25821_ctls[i].v.id == qctrl->id)
208 break; 208 break;
209 if (i == CX25821_CTLS) { 209 if (i == CX25821_CTLS) {
210 *qctrl = no_ctl; 210 *qctrl = no_ctl;
211 return 0; 211 return 0;
212 } 212 }
213 *qctrl = cx25821_ctls[i].v; 213 *qctrl = cx25821_ctls[i].v;
214 return 0; 214 return 0;
@@ -220,15 +220,15 @@ int res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit)
220{ 220{
221 dprintk(1, "%s()\n", __func__); 221 dprintk(1, "%s()\n", __func__);
222 if (fh->resources & bit) 222 if (fh->resources & bit)
223 /* have it already allocated */ 223 /* have it already allocated */
224 return 1; 224 return 1;
225 225
226 /* is it free? */ 226 /* is it free? */
227 mutex_lock(&dev->lock); 227 mutex_lock(&dev->lock);
228 if (dev->resources & bit) { 228 if (dev->resources & bit) {
229 /* no, someone else uses it */ 229 /* no, someone else uses it */
230 mutex_unlock(&dev->lock); 230 mutex_unlock(&dev->lock);
231 return 0; 231 return 0;
232 } 232 }
233 /* it's free, grab it */ 233 /* it's free, grab it */
234 fh->resources |= bit; 234 fh->resources |= bit;
@@ -266,23 +266,23 @@ int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input)
266 memset(&route, 0, sizeof(route)); 266 memset(&route, 0, sizeof(route));
267 267
268 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n", __func__, 268 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n", __func__,
269 input, INPUT(input)->vmux, 269 input, INPUT(input)->vmux,
270 INPUT(input)->gpio0, INPUT(input)->gpio1, 270 INPUT(input)->gpio0, INPUT(input)->gpio1,
271 INPUT(input)->gpio2, INPUT(input)->gpio3); 271 INPUT(input)->gpio2, INPUT(input)->gpio3);
272 dev->input = input; 272 dev->input = input;
273 273
274 route.input = INPUT(input)->vmux; 274 route.input = INPUT(input)->vmux;
275 275
276 /* Tell the internal A/V decoder */ 276 /* Tell the internal A/V decoder */
277 cx25821_call_all(dev, video, s_routing, INPUT(input)->vmux, 0, 0); 277 cx25821_call_all(dev, video, s_routing, INPUT(input)->vmux, 0, 0);
278 278
279 return 0; 279 return 0;
280} 280}
281 281
282int cx25821_start_video_dma(struct cx25821_dev *dev, 282int cx25821_start_video_dma(struct cx25821_dev *dev,
283 struct cx25821_dmaqueue *q, 283 struct cx25821_dmaqueue *q,
284 struct cx25821_buffer *buf, 284 struct cx25821_buffer *buf,
285 struct sram_channel *channel) 285 struct sram_channel *channel)
286{ 286{
287 int tmp = 0; 287 int tmp = 0;
288 288
@@ -302,7 +302,7 @@ int cx25821_start_video_dma(struct cx25821_dev *dev,
302 302
303 /* make sure upstream setting if any is reversed */ 303 /* make sure upstream setting if any is reversed */
304 tmp = cx_read( VID_CH_MODE_SEL ); 304 tmp = cx_read( VID_CH_MODE_SEL );
305 cx_write( VID_CH_MODE_SEL, tmp & 0xFFFFFE00); 305 cx_write( VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
306 306
307 return 0; 307 return 0;
308} 308}
@@ -314,44 +314,44 @@ int cx25821_restart_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue
314 struct list_head *item; 314 struct list_head *item;
315 315
316 if (!list_empty(&q->active)) { 316 if (!list_empty(&q->active)) {
317 buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue); 317 buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue);
318 318
319 cx25821_start_video_dma(dev, q, buf, channel); 319 cx25821_start_video_dma(dev, q, buf, channel);
320 320
321 list_for_each(item, &q->active) { 321 list_for_each(item, &q->active) {
322 buf = list_entry(item, struct cx25821_buffer, vb.queue); 322 buf = list_entry(item, struct cx25821_buffer, vb.queue);
323 buf->count = q->count++; 323 buf->count = q->count++;
324 } 324 }
325 325
326 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 326 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
327 return 0; 327 return 0;
328 } 328 }
329 329
330 prev = NULL; 330 prev = NULL;
331 for (;;) { 331 for (;;) {
332 if (list_empty(&q->queued)) 332 if (list_empty(&q->queued))
333 return 0; 333 return 0;
334 334
335 buf = list_entry(q->queued.next, struct cx25821_buffer, vb.queue); 335 buf = list_entry(q->queued.next, struct cx25821_buffer, vb.queue);
336 336
337 if (NULL == prev) { 337 if (NULL == prev) {
338 list_move_tail(&buf->vb.queue, &q->active); 338 list_move_tail(&buf->vb.queue, &q->active);
339 cx25821_start_video_dma(dev, q, buf, channel); 339 cx25821_start_video_dma(dev, q, buf, channel);
340 buf->vb.state = VIDEOBUF_ACTIVE; 340 buf->vb.state = VIDEOBUF_ACTIVE;
341 buf->count = q->count++; 341 buf->count = q->count++;
342 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 342 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
343 } else if (prev->vb.width == buf->vb.width && 343 } else if (prev->vb.width == buf->vb.width &&
344 prev->vb.height == buf->vb.height && 344 prev->vb.height == buf->vb.height &&
345 prev->fmt == buf->fmt) { 345 prev->fmt == buf->fmt) {
346 list_move_tail(&buf->vb.queue, &q->active); 346 list_move_tail(&buf->vb.queue, &q->active);
347 buf->vb.state = VIDEOBUF_ACTIVE; 347 buf->vb.state = VIDEOBUF_ACTIVE;
348 buf->count = q->count++; 348 buf->count = q->count++;
349 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 349 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
350 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */ 350 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
351 } else { 351 } else {
352 return 0; 352 return 0;
353 } 353 }
354 prev = buf; 354 prev = buf;
355 } 355 }
356} 356}
357 357
@@ -369,11 +369,11 @@ void cx25821_vid_timeout(unsigned long data)
369 369
370 spin_lock_irqsave(&dev->slock, flags); 370 spin_lock_irqsave(&dev->slock, flags);
371 while (!list_empty(&q->active)) { 371 while (!list_empty(&q->active)) {
372 buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue); 372 buf = list_entry(q->active.next, struct cx25821_buffer, vb.queue);
373 list_del(&buf->vb.queue); 373 list_del(&buf->vb.queue);
374 374
375 buf->vb.state = VIDEOBUF_ERROR; 375 buf->vb.state = VIDEOBUF_ERROR;
376 wake_up(&buf->vb.done); 376 wake_up(&buf->vb.done);
377 } 377 }
378 378
379 cx25821_restart_video_queue(dev, q, channel); 379 cx25821_restart_video_queue(dev, q, channel);
@@ -389,33 +389,33 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
389 389
390 mask = cx_read(channel->int_msk); 390 mask = cx_read(channel->int_msk);
391 if (0 == (status & mask)) 391 if (0 == (status & mask))
392 return handled; 392 return handled;
393 393
394 cx_write(channel->int_stat, status); 394 cx_write(channel->int_stat, status);
395 395
396 /* risc op code error */ 396 /* risc op code error */
397 if (status & (1 << 16)) { 397 if (status & (1 << 16)) {
398 printk(KERN_WARNING "%s, %s: video risc op code error\n", dev->name, channel->name); 398 printk(KERN_WARNING "%s, %s: video risc op code error\n", dev->name, channel->name);
399 cx_clear(channel->dma_ctl, 0x11); 399 cx_clear(channel->dma_ctl, 0x11);
400 cx25821_sram_channel_dump(dev, channel); 400 cx25821_sram_channel_dump(dev, channel);
401 } 401 }
402 402
403 /* risc1 y */ 403 /* risc1 y */
404 if (status & FLD_VID_DST_RISC1) { 404 if (status & FLD_VID_DST_RISC1) {
405 spin_lock(&dev->slock); 405 spin_lock(&dev->slock);
406 count = cx_read(channel->gpcnt); 406 count = cx_read(channel->gpcnt);
407 cx25821_video_wakeup(dev, &dev->vidq[channel->i], count); 407 cx25821_video_wakeup(dev, &dev->vidq[channel->i], count);
408 spin_unlock(&dev->slock); 408 spin_unlock(&dev->slock);
409 handled++; 409 handled++;
410 } 410 }
411 411
412 /* risc2 y */ 412 /* risc2 y */
413 if (status & 0x10) { 413 if (status & 0x10) {
414 dprintk(2, "stopper video\n"); 414 dprintk(2, "stopper video\n");
415 spin_lock(&dev->slock); 415 spin_lock(&dev->slock);
416 cx25821_restart_video_queue(dev, &dev->vidq[channel->i], channel); 416 cx25821_restart_video_queue(dev, &dev->vidq[channel->i], channel);
417 spin_unlock(&dev->slock); 417 spin_unlock(&dev->slock);
418 handled++; 418 handled++;
419 } 419 }
420 return handled; 420 return handled;
421} 421}
@@ -424,30 +424,30 @@ void cx25821_videoioctl_unregister(struct cx25821_dev *dev)
424{ 424{
425 if( dev->ioctl_dev ) 425 if( dev->ioctl_dev )
426 { 426 {
427 if (dev->ioctl_dev->minor != -1) 427 if (dev->ioctl_dev->minor != -1)
428 video_unregister_device(dev->ioctl_dev); 428 video_unregister_device(dev->ioctl_dev);
429 else 429 else
430 video_device_release(dev->ioctl_dev); 430 video_device_release(dev->ioctl_dev);
431 431
432 dev->ioctl_dev = NULL; 432 dev->ioctl_dev = NULL;
433 } 433 }
434} 434}
435 435
436void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num) 436void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
437{ 437{
438 cx_clear(PCI_INT_MSK, 1); 438 cx_clear(PCI_INT_MSK, 1);
439 439
440 if (dev->video_dev[chan_num]) { 440 if (dev->video_dev[chan_num]) {
441 if (-1 != dev->video_dev[chan_num]->minor) 441 if (-1 != dev->video_dev[chan_num]->minor)
442 video_unregister_device(dev->video_dev[chan_num]); 442 video_unregister_device(dev->video_dev[chan_num]);
443 else 443 else
444 video_device_release(dev->video_dev[chan_num]); 444 video_device_release(dev->video_dev[chan_num]);
445 445
446 dev->video_dev[chan_num] = NULL; 446 dev->video_dev[chan_num] = NULL;
447 447
448 btcx_riscmem_free(dev->pci, &dev->vidq[chan_num].stopper); 448 btcx_riscmem_free(dev->pci, &dev->vidq[chan_num].stopper);
449 449
450 printk(KERN_WARNING "device %d released!\n", chan_num); 450 printk(KERN_WARNING "device %d released!\n", chan_num);
451 } 451 }
452 452
453} 453}
@@ -475,13 +475,13 @@ int cx25821_video_register(struct cx25821_dev *dev, int chan_num, struct video_d
475 init_timer(&dev->vidq[chan_num].timeout); 475 init_timer(&dev->vidq[chan_num].timeout);
476 cx25821_risc_stopper(dev->pci, &dev->vidq[chan_num].stopper, dev->sram_channels[chan_num].dma_ctl, 0x11, 0); 476 cx25821_risc_stopper(dev->pci, &dev->vidq[chan_num].stopper, dev->sram_channels[chan_num].dma_ctl, 0x11, 0);
477 477
478 478
479 /* register v4l devices */ 479 /* register v4l devices */
480 dev->video_dev[chan_num] = cx25821_vdev_init(dev, dev->pci, video_template, "video"); 480 dev->video_dev[chan_num] = cx25821_vdev_init(dev, dev->pci, video_template, "video");
481 err = video_register_device(dev->video_dev[chan_num], VFL_TYPE_GRABBER, video_nr[dev->nr]); 481 err = video_register_device(dev->video_dev[chan_num], VFL_TYPE_GRABBER, video_nr[dev->nr]);
482 482
483 if (err < 0) { 483 if (err < 0) {
484 goto fail_unreg; 484 goto fail_unreg;
485 } 485 }
486 486
487 //set PCI interrupt 487 //set PCI interrupt
@@ -512,10 +512,10 @@ int buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *si
512 512
513 513
514 if (0 == *count) 514 if (0 == *count)
515 *count = 32; 515 *count = 32;
516 516
517 while (*size * *count > vid_limit * 1024 * 1024) 517 while (*size * *count > vid_limit * 1024 * 1024)
518 (*count)--; 518 (*count)--;
519 519
520 return 0; 520 return 0;
521} 521}
@@ -534,114 +534,114 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, enum v4
534 534
535 BUG_ON(NULL == fh->fmt); 535 BUG_ON(NULL == fh->fmt);
536 if (fh->width < 48 || fh->width > 720 || 536 if (fh->width < 48 || fh->width > 720 ||
537 fh->height < 32 || fh->height > 576) 537 fh->height < 32 || fh->height > 576)
538 return -EINVAL; 538 return -EINVAL;
539 539
540 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3; 540 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
541 541
542 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 542 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
543 return -EINVAL; 543 return -EINVAL;
544 544
545 545
546 if (buf->fmt != fh->fmt || 546 if (buf->fmt != fh->fmt ||
547 buf->vb.width != fh->width || 547 buf->vb.width != fh->width ||
548 buf->vb.height != fh->height || 548 buf->vb.height != fh->height ||
549 buf->vb.field != field) { 549 buf->vb.field != field) {
550 buf->fmt = fh->fmt; 550 buf->fmt = fh->fmt;
551 buf->vb.width = fh->width; 551 buf->vb.width = fh->width;
552 buf->vb.height = fh->height; 552 buf->vb.height = fh->height;
553 buf->vb.field = field; 553 buf->vb.field = field;
554 init_buffer = 1; 554 init_buffer = 1;
555 } 555 }
556 556
557 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { 557 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
558 init_buffer = 1; 558 init_buffer = 1;
559 rc = videobuf_iolock(q, &buf->vb, NULL); 559 rc = videobuf_iolock(q, &buf->vb, NULL);
560 if (0 != rc) 560 if (0 != rc)
561 { 561 {
562 printk(KERN_DEBUG "videobuf_iolock failed!\n"); 562 printk(KERN_DEBUG "videobuf_iolock failed!\n");
563 goto fail; 563 goto fail;
564 } 564 }
565 } 565 }
566 566
567 dprintk(1, "init_buffer=%d\n", init_buffer); 567 dprintk(1, "init_buffer=%d\n", init_buffer);
568 568
569 if (init_buffer) { 569 if (init_buffer) {
570 570
571 channel_opened = dev->channel_opened; 571 channel_opened = dev->channel_opened;
572 channel_opened = (channel_opened < 0 || channel_opened > 7) ? 7 : channel_opened; 572 channel_opened = (channel_opened < 0 || channel_opened > 7) ? 7 : channel_opened;
573 573
574 if( dev->pixel_formats[channel_opened] == PIXEL_FRMT_411 ) 574 if( dev->pixel_formats[channel_opened] == PIXEL_FRMT_411 )
575 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; 575 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3;
576 else 576 else
577 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); 577 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width);
578 578
579 579
580 if( dev->pixel_formats[channel_opened] == PIXEL_FRMT_411 ) 580 if( dev->pixel_formats[channel_opened] == PIXEL_FRMT_411 )
581 { 581 {
582 bpl_local = buf->bpl; 582 bpl_local = buf->bpl;
583 } 583 }
584 else 584 else
585 { 585 {
586 bpl_local = buf->bpl; //Default 586 bpl_local = buf->bpl; //Default
587 587
588 if( channel_opened >= 0 && channel_opened <= 7 ) 588 if( channel_opened >= 0 && channel_opened <= 7 )
589 { 589 {
590 if( dev->use_cif_resolution[channel_opened] ) 590 if( dev->use_cif_resolution[channel_opened] )
591 { 591 {
592 if( dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK ) 592 if( dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK )
593 bpl_local = 352 << 1; 593 bpl_local = 352 << 1;
594 else 594 else
595 bpl_local = dev->cif_width[channel_opened] << 1; 595 bpl_local = dev->cif_width[channel_opened] << 1;
596 } 596 }
597 } 597 }
598 } 598 }
599 599
600 600
601 switch (buf->vb.field) { 601 switch (buf->vb.field) {
602 case V4L2_FIELD_TOP: 602 case V4L2_FIELD_TOP:
603 cx25821_risc_buffer(dev->pci, &buf->risc, 603 cx25821_risc_buffer(dev->pci, &buf->risc,
604 dma->sglist, 0, UNSET, 604 dma->sglist, 0, UNSET,
605 buf->bpl, 0, buf->vb.height); 605 buf->bpl, 0, buf->vb.height);
606 break; 606 break;
607 case V4L2_FIELD_BOTTOM: 607 case V4L2_FIELD_BOTTOM:
608 cx25821_risc_buffer(dev->pci, &buf->risc, 608 cx25821_risc_buffer(dev->pci, &buf->risc,
609 dma->sglist, UNSET, 0, 609 dma->sglist, UNSET, 0,
610 buf->bpl, 0, buf->vb.height); 610 buf->bpl, 0, buf->vb.height);
611 break; 611 break;
612 case V4L2_FIELD_INTERLACED: 612 case V4L2_FIELD_INTERLACED:
613 /* All other formats are top field first */ 613 /* All other formats are top field first */
614 line0_offset = 0; 614 line0_offset = 0;
615 line1_offset = buf->bpl; 615 line1_offset = buf->bpl;
616 dprintk(1, "top field first\n"); 616 dprintk(1, "top field first\n");
617 617
618 cx25821_risc_buffer(dev->pci, &buf->risc, 618 cx25821_risc_buffer(dev->pci, &buf->risc,
619 dma->sglist, line0_offset, 619 dma->sglist, line0_offset,
620 bpl_local, bpl_local, bpl_local, 620 bpl_local, bpl_local, bpl_local,
621 buf->vb.height >> 1); 621 buf->vb.height >> 1);
622 break; 622 break;
623 case V4L2_FIELD_SEQ_TB: 623 case V4L2_FIELD_SEQ_TB:
624 cx25821_risc_buffer(dev->pci, &buf->risc, 624 cx25821_risc_buffer(dev->pci, &buf->risc,
625 dma->sglist, 625 dma->sglist,
626 0, buf->bpl * (buf->vb.height >> 1), 626 0, buf->bpl * (buf->vb.height >> 1),
627 buf->bpl, 0, 627 buf->bpl, 0,
628 buf->vb.height >> 1); 628 buf->vb.height >> 1);
629 break; 629 break;
630 case V4L2_FIELD_SEQ_BT: 630 case V4L2_FIELD_SEQ_BT:
631 cx25821_risc_buffer(dev->pci, &buf->risc, 631 cx25821_risc_buffer(dev->pci, &buf->risc,
632 dma->sglist, 632 dma->sglist,
633 buf->bpl * (buf->vb.height >> 1), 0, 633 buf->bpl * (buf->vb.height >> 1), 0,
634 buf->bpl, 0, 634 buf->bpl, 0,
635 buf->vb.height >> 1); 635 buf->vb.height >> 1);
636 break; 636 break;
637 default: 637 default:
638 BUG(); 638 BUG();
639 } 639 }
640 } 640 }
641 641
642 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", 642 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
643 buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth, fh->fmt->name, 643 buf, buf->vb.i, fh->width, fh->height, fh->fmt->depth, fh->fmt->name,
644 (unsigned long)buf->risc.dma); 644 (unsigned long)buf->risc.dma);
645 645
646 buf->vb.state = VIDEOBUF_PREPARED; 646 buf->vb.state = VIDEOBUF_PREPARED;
647 647
@@ -665,10 +665,10 @@ struct videobuf_queue *get_queue(struct cx25821_fh *fh)
665{ 665{
666 switch (fh->type) { 666 switch (fh->type) {
667 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 667 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
668 return &fh->vidq; 668 return &fh->vidq;
669 default: 669 default:
670 BUG(); 670 BUG();
671 return NULL; 671 return NULL;
672 } 672 }
673} 673}
674 674
@@ -676,10 +676,10 @@ int get_resource(struct cx25821_fh *fh, int resource)
676{ 676{
677 switch (fh->type) { 677 switch (fh->type) {
678 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 678 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
679 return resource; 679 return resource;
680 default: 680 default:
681 BUG(); 681 BUG();
682 return 0; 682 return 0;
683 } 683 }
684} 684}
685 685
@@ -714,38 +714,38 @@ int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
714 714
715 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 715 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
716 if (NULL == fmt) 716 if (NULL == fmt)
717 return -EINVAL; 717 return -EINVAL;
718 718
719 field = f->fmt.pix.field; 719 field = f->fmt.pix.field;
720 maxw = 720; 720 maxw = 720;
721 maxh = 576; 721 maxh = 576;
722 722
723 if (V4L2_FIELD_ANY == field) { 723 if (V4L2_FIELD_ANY == field) {
724 field = (f->fmt.pix.height > maxh/2) 724 field = (f->fmt.pix.height > maxh/2)
725 ? V4L2_FIELD_INTERLACED 725 ? V4L2_FIELD_INTERLACED
726 : V4L2_FIELD_TOP; 726 : V4L2_FIELD_TOP;
727 } 727 }
728 728
729 switch (field) { 729 switch (field) {
730 case V4L2_FIELD_TOP: 730 case V4L2_FIELD_TOP:
731 case V4L2_FIELD_BOTTOM: 731 case V4L2_FIELD_BOTTOM:
732 maxh = maxh / 2; 732 maxh = maxh / 2;
733 break; 733 break;
734 case V4L2_FIELD_INTERLACED: 734 case V4L2_FIELD_INTERLACED:
735 break; 735 break;
736 default: 736 default:
737 return -EINVAL; 737 return -EINVAL;
738 } 738 }
739 739
740 f->fmt.pix.field = field; 740 f->fmt.pix.field = field;
741 if (f->fmt.pix.height < 32) 741 if (f->fmt.pix.height < 32)
742 f->fmt.pix.height = 32; 742 f->fmt.pix.height = 32;
743 if (f->fmt.pix.height > maxh) 743 if (f->fmt.pix.height > maxh)
744 f->fmt.pix.height = maxh; 744 f->fmt.pix.height = maxh;
745 if (f->fmt.pix.width < 48) 745 if (f->fmt.pix.width < 48)
746 f->fmt.pix.width = 48; 746 f->fmt.pix.width = 48;
747 if (f->fmt.pix.width > maxw) 747 if (f->fmt.pix.width > maxw)
748 f->fmt.pix.width = maxw; 748 f->fmt.pix.width = maxw;
749 f->fmt.pix.width &= ~0x03; 749 f->fmt.pix.width &= ~0x03;
750 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; 750 f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
751 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 751 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
@@ -764,18 +764,18 @@ int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)
764 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); 764 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci));
765 cap->version = CX25821_VERSION_CODE; 765 cap->version = CX25821_VERSION_CODE;
766 cap->capabilities = 766 cap->capabilities =
767 V4L2_CAP_VIDEO_CAPTURE | 767 V4L2_CAP_VIDEO_CAPTURE |
768 V4L2_CAP_READWRITE | 768 V4L2_CAP_READWRITE |
769 V4L2_CAP_STREAMING; 769 V4L2_CAP_STREAMING;
770 if (UNSET != dev->tuner_type) 770 if (UNSET != dev->tuner_type)
771 cap->capabilities |= V4L2_CAP_TUNER; 771 cap->capabilities |= V4L2_CAP_TUNER;
772 return 0; 772 return 0;
773} 773}
774 774
775int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *f) 775int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *f)
776{ 776{
777 if (unlikely(f->index >= ARRAY_SIZE(formats))) 777 if (unlikely(f->index >= ARRAY_SIZE(formats)))
778 return -EINVAL; 778 return -EINVAL;
779 779
780 strlcpy(f->description, formats[f->index].name, sizeof(f->description)); 780 strlcpy(f->description, formats[f->index].name, sizeof(f->description));
781 f->pixelformat = formats[f->index].fourcc; 781 f->pixelformat = formats[f->index].fourcc;
@@ -799,13 +799,13 @@ int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
799 req.memory = V4L2_MEMORY_MMAP; 799 req.memory = V4L2_MEMORY_MMAP;
800 err = videobuf_reqbufs(q, &req); 800 err = videobuf_reqbufs(q, &req);
801 if (err < 0) 801 if (err < 0)
802 return err; 802 return err;
803 803
804 mbuf->frames = req.count; 804 mbuf->frames = req.count;
805 mbuf->size = 0; 805 mbuf->size = 0;
806 for (i = 0; i < mbuf->frames; i++) { 806 for (i = 0; i < mbuf->frames; i++) {
807 mbuf->offsets[i] = q->bufs[i]->boff; 807 mbuf->offsets[i] = q->bufs[i]->boff;
808 mbuf->size += q->bufs[i]->bsize; 808 mbuf->size += q->bufs[i]->bsize;
809 } 809 }
810 return 0; 810 return 0;
811} 811}
@@ -856,17 +856,17 @@ int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
856 int err; 856 int err;
857 857
858 dprintk(1, "%s()\n", __func__); 858 dprintk(1, "%s()\n", __func__);
859 859
860 if (fh) 860 if (fh)
861 { 861 {
862 err = v4l2_prio_check(&dev->prio, &fh->prio); 862 err = v4l2_prio_check(&dev->prio, &fh->prio);
863 if (0 != err) 863 if (0 != err)
864 return err; 864 return err;
865 } 865 }
866 866
867 if( dev->tvnorm == *tvnorms ) 867 if( dev->tvnorm == *tvnorms )
868 { 868 {
869 return 0; 869 return 0;
870 } 870 }
871 871
872 mutex_lock(&dev->lock); 872 mutex_lock(&dev->lock);
@@ -882,19 +882,19 @@ int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
882int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i) 882int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i)
883{ 883{
884 static const char *iname[] = { 884 static const char *iname[] = {
885 [CX25821_VMUX_COMPOSITE] = "Composite", 885 [CX25821_VMUX_COMPOSITE] = "Composite",
886 [CX25821_VMUX_SVIDEO] = "S-Video", 886 [CX25821_VMUX_SVIDEO] = "S-Video",
887 [CX25821_VMUX_DEBUG] = "for debug only", 887 [CX25821_VMUX_DEBUG] = "for debug only",
888 }; 888 };
889 unsigned int n; 889 unsigned int n;
890 dprintk(1, "%s()\n", __func__); 890 dprintk(1, "%s()\n", __func__);
891 891
892 n = i->index; 892 n = i->index;
893 if (n > 2) 893 if (n > 2)
894 return -EINVAL; 894 return -EINVAL;
895 895
896 if (0 == INPUT(n)->type) 896 if (0 == INPUT(n)->type)
897 return -EINVAL; 897 return -EINVAL;
898 898
899 memset(i, 0, sizeof(*i)); 899 memset(i, 0, sizeof(*i));
900 i->index = n; 900 i->index = n;
@@ -913,9 +913,9 @@ int vidioc_enum_input(struct file *file, void *priv, struct v4l2_input *i)
913} 913}
914 914
915int vidioc_g_input(struct file *file, void *priv, unsigned int *i) 915int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
916{ 916{
917 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 917 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
918 918
919 *i = dev->input; 919 *i = dev->input;
920 dprintk(1, "%s() returns %d\n", __func__, *i); 920 dprintk(1, "%s() returns %d\n", __func__, *i);
921 return 0; 921 return 0;
@@ -930,16 +930,16 @@ int vidioc_s_input(struct file *file, void *priv, unsigned int i)
930 930
931 dprintk(1, "%s(%d)\n", __func__, i); 931 dprintk(1, "%s(%d)\n", __func__, i);
932 932
933 if (fh) 933 if (fh)
934 { 934 {
935 err = v4l2_prio_check(&dev->prio, &fh->prio); 935 err = v4l2_prio_check(&dev->prio, &fh->prio);
936 if (0 != err) 936 if (0 != err)
937 return err; 937 return err;
938 } 938 }
939 939
940 if (i > 2) { 940 if (i > 2) {
941 dprintk(1, "%s() -EINVAL\n", __func__); 941 dprintk(1, "%s() -EINVAL\n", __func__);
942 return -EINVAL; 942 return -EINVAL;
943 } 943 }
944 944
945 mutex_lock(&dev->lock); 945 mutex_lock(&dev->lock);
@@ -982,11 +982,11 @@ int vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f)
982 struct cx25821_dev *dev = fh->dev; 982 struct cx25821_dev *dev = fh->dev;
983 int err; 983 int err;
984 984
985 if (fh) 985 if (fh)
986 { 986 {
987 err = v4l2_prio_check(&dev->prio, &fh->prio); 987 err = v4l2_prio_check(&dev->prio, &fh->prio);
988 if (0 != err) 988 if (0 != err)
989 return err; 989 return err;
990 } 990 }
991 991
992 return cx25821_set_freq(dev, f); 992 return cx25821_set_freq(dev, f);
@@ -995,12 +995,12 @@ int vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f)
995 995
996#ifdef CONFIG_VIDEO_ADV_DEBUG 996#ifdef CONFIG_VIDEO_ADV_DEBUG
997int vidioc_g_register(struct file *file, void *fh, 997int vidioc_g_register(struct file *file, void *fh,
998 struct v4l2_dbg_register *reg) 998 struct v4l2_dbg_register *reg)
999{ 999{
1000 struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev; 1000 struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev;
1001 1001
1002 if (!v4l2_chip_match_host(&reg->match)) 1002 if (!v4l2_chip_match_host(&reg->match))
1003 return -EINVAL; 1003 return -EINVAL;
1004 1004
1005 cx25821_call_all(dev, core, g_register, reg); 1005 cx25821_call_all(dev, core, g_register, reg);
1006 1006
@@ -1008,12 +1008,12 @@ int vidioc_g_register(struct file *file, void *fh,
1008} 1008}
1009 1009
1010int vidioc_s_register(struct file *file, void *fh, 1010int vidioc_s_register(struct file *file, void *fh,
1011 struct v4l2_dbg_register *reg) 1011 struct v4l2_dbg_register *reg)
1012{ 1012{
1013 struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev; 1013 struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev;
1014 1014
1015 if (!v4l2_chip_match_host(&reg->match)) 1015 if (!v4l2_chip_match_host(&reg->match))
1016 return -EINVAL; 1016 return -EINVAL;
1017 1017
1018 cx25821_call_all(dev, core, s_register, reg); 1018 cx25821_call_all(dev, core, s_register, reg);
1019 1019
@@ -1029,9 +1029,9 @@ int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1029 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 1029 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1030 1030
1031 if (unlikely(UNSET == dev->tuner_type)) 1031 if (unlikely(UNSET == dev->tuner_type))
1032 return -EINVAL; 1032 return -EINVAL;
1033 if (0 != t->index) 1033 if (0 != t->index)
1034 return -EINVAL; 1034 return -EINVAL;
1035 1035
1036 strcpy(t->name, "Television"); 1036 strcpy(t->name, "Television");
1037 t->type = V4L2_TUNER_ANALOG_TV; 1037 t->type = V4L2_TUNER_ANALOG_TV;
@@ -1043,24 +1043,24 @@ int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1043} 1043}
1044 1044
1045int vidioc_s_tuner(struct file *file, void *priv, 1045int vidioc_s_tuner(struct file *file, void *priv,
1046 struct v4l2_tuner *t) 1046 struct v4l2_tuner *t)
1047{ 1047{
1048 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 1048 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1049 struct cx25821_fh *fh = priv; 1049 struct cx25821_fh *fh = priv;
1050 int err; 1050 int err;
1051 1051
1052 if (fh) 1052 if (fh)
1053 { 1053 {
1054 err = v4l2_prio_check(&dev->prio, &fh->prio); 1054 err = v4l2_prio_check(&dev->prio, &fh->prio);
1055 if (0 != err) 1055 if (0 != err)
1056 return err; 1056 return err;
1057 } 1057 }
1058 1058
1059 dprintk(1, "%s()\n", __func__); 1059 dprintk(1, "%s()\n", __func__);
1060 if (UNSET == dev->tuner_type) 1060 if (UNSET == dev->tuner_type)
1061 return -EINVAL; 1061 return -EINVAL;
1062 if (0 != t->index) 1062 if (0 != t->index)
1063 return -EINVAL; 1063 return -EINVAL;
1064 1064
1065 return 0; 1065 return 0;
1066} 1066}
@@ -1130,7 +1130,7 @@ static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
1130 1130
1131int vidioc_queryctrl(struct file *file, void *priv, 1131int vidioc_queryctrl(struct file *file, void *priv,
1132 struct v4l2_queryctrl *qctrl) 1132 struct v4l2_queryctrl *qctrl)
1133{ 1133{
1134 return cx25821_ctrl_query(qctrl); 1134 return cx25821_ctrl_query(qctrl);
1135} 1135}
1136 1136
@@ -1147,20 +1147,20 @@ static const struct v4l2_queryctrl* ctrl_by_id(unsigned int id)
1147 return NULL; 1147 return NULL;
1148} 1148}
1149 1149
1150int vidioc_g_ctrl(struct file *file, 1150int vidioc_g_ctrl(struct file *file,
1151 void *priv, 1151 void *priv,
1152 struct v4l2_control *ctl) 1152 struct v4l2_control *ctl)
1153{ 1153{
1154 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 1154 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1155 1155
1156 const struct v4l2_queryctrl* ctrl; 1156 const struct v4l2_queryctrl* ctrl;
1157 1157
1158 ctrl = ctrl_by_id(ctl->id); 1158 ctrl = ctrl_by_id(ctl->id);
1159 1159
1160 if (NULL == ctrl) 1160 if (NULL == ctrl)
1161 return -EINVAL; 1161 return -EINVAL;
1162 switch (ctl->id) 1162 switch (ctl->id)
1163 { 1163 {
1164 case V4L2_CID_BRIGHTNESS: 1164 case V4L2_CID_BRIGHTNESS:
1165 ctl->value = dev->ctl_bright; 1165 ctl->value = dev->ctl_bright;
1166 break; 1166 break;
@@ -1173,25 +1173,25 @@ int vidioc_g_ctrl(struct file *file,
1173 case V4L2_CID_SATURATION: 1173 case V4L2_CID_SATURATION:
1174 ctl->value = dev->ctl_saturation; 1174 ctl->value = dev->ctl_saturation;
1175 break; 1175 break;
1176 } 1176 }
1177 return 0; 1177 return 0;
1178} 1178}
1179 1179
1180int cx25821_set_control(struct cx25821_dev *dev, 1180int cx25821_set_control(struct cx25821_dev *dev,
1181 struct v4l2_control *ctl, int chan_num) 1181 struct v4l2_control *ctl, int chan_num)
1182{ 1182{
1183 int err; 1183 int err;
1184 const struct v4l2_queryctrl* ctrl; 1184 const struct v4l2_queryctrl* ctrl;
1185 1185
1186 err = -EINVAL; 1186 err = -EINVAL;
1187 1187
1188 ctrl = ctrl_by_id(ctl->id); 1188 ctrl = ctrl_by_id(ctl->id);
1189 1189
1190 if (NULL == ctrl) 1190 if (NULL == ctrl)
1191 return err; 1191 return err;
1192 1192
1193 switch (ctrl->type) 1193 switch (ctrl->type)
1194 { 1194 {
1195 case V4L2_CTRL_TYPE_BOOLEAN: 1195 case V4L2_CTRL_TYPE_BOOLEAN:
1196 case V4L2_CTRL_TYPE_MENU: 1196 case V4L2_CTRL_TYPE_MENU:
1197 case V4L2_CTRL_TYPE_INTEGER: 1197 case V4L2_CTRL_TYPE_INTEGER:
@@ -1204,8 +1204,8 @@ int cx25821_set_control(struct cx25821_dev *dev,
1204 /* nothing */; 1204 /* nothing */;
1205 }; 1205 };
1206 1206
1207 switch (ctl->id) 1207 switch (ctl->id)
1208 { 1208 {
1209 case V4L2_CID_BRIGHTNESS: 1209 case V4L2_CID_BRIGHTNESS:
1210 dev->ctl_bright = ctl->value; 1210 dev->ctl_bright = ctl->value;
1211 medusa_set_brightness(dev, ctl->value, chan_num); 1211 medusa_set_brightness(dev, ctl->value, chan_num);
@@ -1222,9 +1222,9 @@ int cx25821_set_control(struct cx25821_dev *dev,
1222 dev->ctl_saturation = ctl->value; 1222 dev->ctl_saturation = ctl->value;
1223 medusa_set_saturation(dev, ctl->value, chan_num); 1223 medusa_set_saturation(dev, ctl->value, chan_num);
1224 break; 1224 break;
1225 } 1225 }
1226 1226
1227 err = 0; 1227 err = 0;
1228 1228
1229 return err; 1229 return err;
1230} 1230}
@@ -1241,12 +1241,12 @@ static void init_controls(struct cx25821_dev *dev, int chan_num)
1241 } 1241 }
1242} 1242}
1243 1243
1244int vidioc_cropcap(struct file *file, 1244int vidioc_cropcap(struct file *file,
1245 void *priv, 1245 void *priv,
1246 struct v4l2_cropcap *cropcap) 1246 struct v4l2_cropcap *cropcap)
1247{ 1247{
1248 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 1248 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1249 1249
1250 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1250 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1251 return -EINVAL; 1251 return -EINVAL;
1252 cropcap->bounds.top = cropcap->bounds.left = 0; 1252 cropcap->bounds.top = cropcap->bounds.left = 0;
@@ -1258,34 +1258,34 @@ int vidioc_cropcap(struct file *file,
1258 return 0; 1258 return 0;
1259} 1259}
1260 1260
1261int vidioc_s_crop(struct file *file, 1261int vidioc_s_crop(struct file *file,
1262 void *priv, 1262 void *priv,
1263 struct v4l2_crop *crop) 1263 struct v4l2_crop *crop)
1264{ 1264{
1265 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 1265 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1266 struct cx25821_fh *fh = priv; 1266 struct cx25821_fh *fh = priv;
1267 int err; 1267 int err;
1268 1268
1269 if (fh) 1269 if (fh)
1270 { 1270 {
1271 err = v4l2_prio_check(&dev->prio, &fh->prio); 1271 err = v4l2_prio_check(&dev->prio, &fh->prio);
1272 if (0 != err) 1272 if (0 != err)
1273 return err; 1273 return err;
1274 } 1274 }
1275 // vidioc_s_crop not supported 1275 // vidioc_s_crop not supported
1276 return -EINVAL; 1276 return -EINVAL;
1277} 1277}
1278 1278
1279int vidioc_g_crop(struct file *file, 1279int vidioc_g_crop(struct file *file,
1280 void *priv, 1280 void *priv,
1281 struct v4l2_crop *crop) 1281 struct v4l2_crop *crop)
1282{ 1282{
1283 // vidioc_g_crop not supported 1283 // vidioc_g_crop not supported
1284 return -EINVAL; 1284 return -EINVAL;
1285} 1285}
1286 1286
1287int vidioc_querystd(struct file *file, 1287int vidioc_querystd(struct file *file,
1288 void *priv, 1288 void *priv,
1289 v4l2_std_id *norm) 1289 v4l2_std_id *norm)
1290{ 1290{
1291 // medusa does not support video standard sensing of current input 1291 // medusa does not support video standard sensing of current input
@@ -1299,17 +1299,17 @@ int is_valid_width(u32 width, v4l2_std_id tvnorm)
1299 if(tvnorm == V4L2_STD_PAL_BG) 1299 if(tvnorm == V4L2_STD_PAL_BG)
1300 { 1300 {
1301 if (width == 352 || width == 720) 1301 if (width == 352 || width == 720)
1302 return 1; 1302 return 1;
1303 else 1303 else
1304 return 0; 1304 return 0;
1305 } 1305 }
1306 1306
1307 if(tvnorm == V4L2_STD_NTSC_M) 1307 if(tvnorm == V4L2_STD_NTSC_M)
1308 { 1308 {
1309 if (width == 320 || width == 352 || width == 720) 1309 if (width == 320 || width == 352 || width == 720)
1310 return 1; 1310 return 1;
1311 else 1311 else
1312 return 0; 1312 return 0;
1313 } 1313 }
1314 return 0; 1314 return 0;
1315} 1315}
@@ -1317,19 +1317,19 @@ int is_valid_width(u32 width, v4l2_std_id tvnorm)
1317int is_valid_height(u32 height, v4l2_std_id tvnorm) 1317int is_valid_height(u32 height, v4l2_std_id tvnorm)
1318{ 1318{
1319 if(tvnorm == V4L2_STD_PAL_BG) 1319 if(tvnorm == V4L2_STD_PAL_BG)
1320 { 1320 {
1321 if (height == 576 || height == 288) 1321 if (height == 576 || height == 288)
1322 return 1; 1322 return 1;
1323 else 1323 else
1324 return 0; 1324 return 0;
1325 } 1325 }
1326 1326
1327 if(tvnorm == V4L2_STD_NTSC_M) 1327 if(tvnorm == V4L2_STD_NTSC_M)
1328 { 1328 {
1329 if (height == 480 || height == 240) 1329 if (height == 480 || height == 240)
1330 return 1; 1330 return 1;
1331 else 1331 else
1332 return 0; 1332 return 0;
1333 } 1333 }
1334 1334
1335 return 0; 1335 return 0;