[media] saa7146: move vbi fields from saa7146_fh to saa7146_vv
[deliverable/linux.git] / drivers / media / common / saa7146_fops.c
CommitLineData
44d0b80e
JP
1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2
1da177e4 3#include <media/saa7146_vv.h>
7a707b89 4#include <linux/module.h>
1da177e4 5
1da177e4
LT
6/****************************************************************************/
7/* resource management functions, shamelessly stolen from saa7134 driver */
8
9int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit)
10{
11 struct saa7146_dev *dev = fh->dev;
12 struct saa7146_vv *vv = dev->vv_data;
13
14 if (fh->resources & bit) {
44d0b80e
JP
15 DEB_D("already allocated! want: 0x%02x, cur:0x%02x\n",
16 bit, vv->resources);
1da177e4
LT
17 /* have it already allocated */
18 return 1;
19 }
20
21 /* is it free? */
1da177e4 22 if (vv->resources & bit) {
44d0b80e
JP
23 DEB_D("locked! vv->resources:0x%02x, we want:0x%02x\n",
24 vv->resources, bit);
1da177e4 25 /* no, someone else uses it */
1da177e4
LT
26 return 0;
27 }
28 /* it's free, grab it */
44d0b80e 29 fh->resources |= bit;
1da177e4 30 vv->resources |= bit;
44d0b80e 31 DEB_D("res: get 0x%02x, cur:0x%02x\n", bit, vv->resources);
1da177e4
LT
32 return 1;
33}
34
35void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
36{
37 struct saa7146_dev *dev = fh->dev;
38 struct saa7146_vv *vv = dev->vv_data;
39
ae24601b 40 BUG_ON((fh->resources & bits) != bits);
1da177e4 41
44d0b80e 42 fh->resources &= ~bits;
1da177e4 43 vv->resources &= ~bits;
44d0b80e 44 DEB_D("res: put 0x%02x, cur:0x%02x\n", bits, vv->resources);
1da177e4
LT
45}
46
47
48/********************************************************************************/
49/* common dma functions */
50
c7b0ac05
MCC
51void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
52 struct saa7146_buf *buf)
1da177e4 53{
c1accaa2 54 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
44d0b80e 55 DEB_EE("dev:%p, buf:%p\n", dev, buf);
1da177e4 56
ae24601b 57 BUG_ON(in_interrupt());
1da177e4 58
0e0809a5 59 videobuf_waiton(q, &buf->vb, 0, 0);
95268403 60 videobuf_dma_unmap(q->dev, dma);
c1accaa2 61 videobuf_dma_free(dma);
0fc0686e 62 buf->vb.state = VIDEOBUF_NEEDS_INIT;
1da177e4
LT
63}
64
65
66/********************************************************************************/
67/* common buffer functions */
68
69int saa7146_buffer_queue(struct saa7146_dev *dev,
70 struct saa7146_dmaqueue *q,
71 struct saa7146_buf *buf)
72{
73 assert_spin_locked(&dev->slock);
44d0b80e 74 DEB_EE("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf);
1da177e4
LT
75
76 BUG_ON(!q);
77
78 if (NULL == q->curr) {
79 q->curr = buf;
44d0b80e 80 DEB_D("immediately activating buffer %p\n", buf);
1da177e4
LT
81 buf->activate(dev,buf,NULL);
82 } else {
83 list_add_tail(&buf->vb.queue,&q->queue);
0fc0686e 84 buf->vb.state = VIDEOBUF_QUEUED;
44d0b80e
JP
85 DEB_D("adding buffer %p to queue. (active buffer present)\n",
86 buf);
1da177e4
LT
87 }
88 return 0;
89}
90
91void saa7146_buffer_finish(struct saa7146_dev *dev,
92 struct saa7146_dmaqueue *q,
93 int state)
94{
95 assert_spin_locked(&dev->slock);
44d0b80e
JP
96 DEB_EE("dev:%p, dmaq:%p, state:%d\n", dev, q, state);
97 DEB_EE("q->curr:%p\n", q->curr);
1da177e4
LT
98
99 BUG_ON(!q->curr);
100
101 /* finish current buffer */
102 if (NULL == q->curr) {
44d0b80e 103 DEB_D("aiii. no current buffer\n");
afd1a0c9 104 return;
1da177e4 105 }
afd1a0c9 106
1da177e4
LT
107 q->curr->vb.state = state;
108 do_gettimeofday(&q->curr->vb.ts);
109 wake_up(&q->curr->vb.done);
110
111 q->curr = NULL;
112}
113
114void saa7146_buffer_next(struct saa7146_dev *dev,
115 struct saa7146_dmaqueue *q, int vbi)
116{
117 struct saa7146_buf *buf,*next = NULL;
118
119 BUG_ON(!q);
120
44d0b80e 121 DEB_INT("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi);
1da177e4
LT
122
123 assert_spin_locked(&dev->slock);
124 if (!list_empty(&q->queue)) {
125 /* activate next one from queue */
126 buf = list_entry(q->queue.next,struct saa7146_buf,vb.queue);
127 list_del(&buf->vb.queue);
128 if (!list_empty(&q->queue))
129 next = list_entry(q->queue.next,struct saa7146_buf, vb.queue);
130 q->curr = buf;
44d0b80e
JP
131 DEB_INT("next buffer: buf:%p, prev:%p, next:%p\n",
132 buf, q->queue.prev, q->queue.next);
1da177e4
LT
133 buf->activate(dev,buf,next);
134 } else {
44d0b80e 135 DEB_INT("no next buffer. stopping.\n");
1da177e4
LT
136 if( 0 != vbi ) {
137 /* turn off video-dma3 */
138 saa7146_write(dev,MC1, MASK_20);
139 } else {
140 /* nothing to do -- just prevent next video-dma1 transfer
141 by lowering the protection address */
142
143 // fixme: fix this for vflip != 0
144
145 saa7146_write(dev, PROT_ADDR1, 0);
afd1a0c9 146 saa7146_write(dev, MC2, (MASK_02|MASK_18));
1da177e4
LT
147
148 /* write the address of the rps-program */
149 saa7146_write(dev, RPS_ADDR0, dev->d_rps0.dma_handle);
150 /* turn on rps */
151 saa7146_write(dev, MC1, (MASK_12 | MASK_28));
afd1a0c9 152
1da177e4
LT
153/*
154 printk("vdma%d.base_even: 0x%08x\n", 1,saa7146_read(dev,BASE_EVEN1));
155 printk("vdma%d.base_odd: 0x%08x\n", 1,saa7146_read(dev,BASE_ODD1));
156 printk("vdma%d.prot_addr: 0x%08x\n", 1,saa7146_read(dev,PROT_ADDR1));
157 printk("vdma%d.base_page: 0x%08x\n", 1,saa7146_read(dev,BASE_PAGE1));
158 printk("vdma%d.pitch: 0x%08x\n", 1,saa7146_read(dev,PITCH1));
159 printk("vdma%d.num_line_byte: 0x%08x\n", 1,saa7146_read(dev,NUM_LINE_BYTE1));
160*/
161 }
162 del_timer(&q->timeout);
163 }
164}
165
166void saa7146_buffer_timeout(unsigned long data)
167{
168 struct saa7146_dmaqueue *q = (struct saa7146_dmaqueue*)data;
169 struct saa7146_dev *dev = q->dev;
170 unsigned long flags;
171
44d0b80e 172 DEB_EE("dev:%p, dmaq:%p\n", dev, q);
1da177e4
LT
173
174 spin_lock_irqsave(&dev->slock,flags);
175 if (q->curr) {
44d0b80e 176 DEB_D("timeout on %p\n", q->curr);
0fc0686e 177 saa7146_buffer_finish(dev,q,VIDEOBUF_ERROR);
1da177e4
LT
178 }
179
180 /* we don't restart the transfer here like other drivers do. when
181 a streaming capture is disabled, the timeout function will be
182 called for the current buffer. if we activate the next buffer now,
183 we mess up our capture logic. if a timeout occurs on another buffer,
184 then something is seriously broken before, so no need to buffer the
185 next capture IMHO... */
186/*
187 saa7146_buffer_next(dev,q);
188*/
189 spin_unlock_irqrestore(&dev->slock,flags);
190}
191
192/********************************************************************************/
193/* file operations */
194
bec43661 195static int fops_open(struct file *file)
1da177e4 196{
63b0d5ad
LP
197 struct video_device *vdev = video_devdata(file);
198 struct saa7146_dev *dev = video_drvdata(file);
1da177e4
LT
199 struct saa7146_fh *fh = NULL;
200 int result = 0;
201
63b0d5ad 202 enum v4l2_buf_type type;
1da177e4 203
44d0b80e 204 DEB_EE("file:%p, dev:%s\n", file, video_device_node_name(vdev));
1da177e4 205
3593cab5 206 if (mutex_lock_interruptible(&saa7146_devices_lock))
1da177e4
LT
207 return -ERESTARTSYS;
208
44d0b80e 209 DEB_D("using: %p\n", dev);
1da177e4 210
63b0d5ad
LP
211 type = vdev->vfl_type == VFL_TYPE_GRABBER
212 ? V4L2_BUF_TYPE_VIDEO_CAPTURE
213 : V4L2_BUF_TYPE_VBI_CAPTURE;
214
1da177e4
LT
215 /* check if an extension is registered */
216 if( NULL == dev->ext ) {
44d0b80e 217 DEB_S("no extension registered for this device\n");
1da177e4
LT
218 result = -ENODEV;
219 goto out;
220 }
221
222 /* allocate per open data */
7408187d 223 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1da177e4 224 if (NULL == fh) {
44d0b80e 225 DEB_S("cannot allocate memory for per open data\n");
1da177e4
LT
226 result = -ENOMEM;
227 goto out;
228 }
afd1a0c9 229
1da177e4
LT
230 file->private_data = fh;
231 fh->dev = dev;
232 fh->type = type;
233
234 if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
44d0b80e 235 DEB_S("initializing vbi...\n");
5b0fa4ff
OE
236 if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
237 result = saa7146_vbi_uops.open(dev,file);
238 if (dev->ext_vv_data->vbi_fops.open)
bec43661 239 dev->ext_vv_data->vbi_fops.open(file);
1da177e4 240 } else {
44d0b80e 241 DEB_S("initializing video...\n");
1da177e4
LT
242 result = saa7146_video_uops.open(dev,file);
243 }
244
245 if (0 != result) {
246 goto out;
247 }
248
249 if( 0 == try_module_get(dev->ext->module)) {
250 result = -EINVAL;
251 goto out;
252 }
253
254 result = 0;
255out:
5fa1247a 256 if (fh && result != 0) {
1da177e4
LT
257 kfree(fh);
258 file->private_data = NULL;
259 }
3593cab5 260 mutex_unlock(&saa7146_devices_lock);
afd1a0c9 261 return result;
1da177e4
LT
262}
263
bec43661 264static int fops_release(struct file *file)
1da177e4
LT
265{
266 struct saa7146_fh *fh = file->private_data;
267 struct saa7146_dev *dev = fh->dev;
268
44d0b80e 269 DEB_EE("file:%p\n", file);
1da177e4 270
3593cab5 271 if (mutex_lock_interruptible(&saa7146_devices_lock))
1da177e4
LT
272 return -ERESTARTSYS;
273
274 if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
5b0fa4ff
OE
275 if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
276 saa7146_vbi_uops.release(dev,file);
277 if (dev->ext_vv_data->vbi_fops.release)
bec43661 278 dev->ext_vv_data->vbi_fops.release(file);
1da177e4
LT
279 } else {
280 saa7146_video_uops.release(dev,file);
281 }
282
283 module_put(dev->ext->module);
284 file->private_data = NULL;
285 kfree(fh);
286
3593cab5 287 mutex_unlock(&saa7146_devices_lock);
1da177e4
LT
288
289 return 0;
290}
291
1da177e4
LT
292static int fops_mmap(struct file *file, struct vm_area_struct * vma)
293{
294 struct saa7146_fh *fh = file->private_data;
295 struct videobuf_queue *q;
296
297 switch (fh->type) {
298 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
44d0b80e
JP
299 DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, vma:%p\n",
300 file, vma);
1da177e4
LT
301 q = &fh->video_q;
302 break;
303 }
304 case V4L2_BUF_TYPE_VBI_CAPTURE: {
44d0b80e
JP
305 DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, vma:%p\n",
306 file, vma);
1da177e4
LT
307 q = &fh->vbi_q;
308 break;
309 }
310 default:
311 BUG();
312 return 0;
313 }
50c25fff 314
1da177e4
LT
315 return videobuf_mmap_mapper(q,vma);
316}
317
318static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait)
319{
320 struct saa7146_fh *fh = file->private_data;
321 struct videobuf_buffer *buf = NULL;
322 struct videobuf_queue *q;
323
44d0b80e 324 DEB_EE("file:%p, poll:%p\n", file, wait);
1da177e4
LT
325
326 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
327 if( 0 == fh->vbi_q.streaming )
328 return videobuf_poll_stream(file, &fh->vbi_q, wait);
329 q = &fh->vbi_q;
330 } else {
44d0b80e 331 DEB_D("using video queue\n");
1da177e4
LT
332 q = &fh->video_q;
333 }
334
335 if (!list_empty(&q->stream))
336 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
337
338 if (!buf) {
44d0b80e 339 DEB_D("buf == NULL!\n");
1da177e4
LT
340 return POLLERR;
341 }
342
343 poll_wait(file, &buf->done, wait);
0fc0686e 344 if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR) {
44d0b80e 345 DEB_D("poll succeeded!\n");
1da177e4
LT
346 return POLLIN|POLLRDNORM;
347 }
348
44d0b80e 349 DEB_D("nothing to poll for, buf->state:%d\n", buf->state);
1da177e4
LT
350 return 0;
351}
352
353static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
354{
355 struct saa7146_fh *fh = file->private_data;
356
357 switch (fh->type) {
44d0b80e
JP
358 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
359/*
360 DEB_EE("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, data:%p, count:%lun",
361 file, data, (unsigned long)count);
362*/
1da177e4 363 return saa7146_video_uops.read(file,data,count,ppos);
44d0b80e
JP
364 case V4L2_BUF_TYPE_VBI_CAPTURE:
365/*
366 DEB_EE("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n",
367 file, data, (unsigned long)count);
368*/
5b0fa4ff
OE
369 if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
370 return saa7146_vbi_uops.read(file,data,count,ppos);
44d0b80e 371 return -EINVAL;
1da177e4
LT
372 default:
373 BUG();
374 return 0;
375 }
376}
377
5b0fa4ff
OE
378static ssize_t fops_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
379{
380 struct saa7146_fh *fh = file->private_data;
381
382 switch (fh->type) {
383 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
384 return -EINVAL;
385 case V4L2_BUF_TYPE_VBI_CAPTURE:
386 if (fh->dev->ext_vv_data->vbi_fops.write)
387 return fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos);
388 else
389 return -EINVAL;
390 default:
391 BUG();
392 return -EINVAL;
393 }
394}
395
bec43661 396static const struct v4l2_file_operations video_fops =
1da177e4
LT
397{
398 .owner = THIS_MODULE,
399 .open = fops_open,
400 .release = fops_release,
401 .read = fops_read,
5b0fa4ff 402 .write = fops_write,
1da177e4
LT
403 .poll = fops_poll,
404 .mmap = fops_mmap,
9af39713 405 .unlocked_ioctl = video_ioctl2,
1da177e4
LT
406};
407
52c1da39 408static void vv_callback(struct saa7146_dev *dev, unsigned long status)
1da177e4
LT
409{
410 u32 isr = status;
afd1a0c9 411
44d0b80e 412 DEB_INT("dev:%p, isr:0x%08x\n", dev, (u32)status);
1da177e4
LT
413
414 if (0 != (isr & (MASK_27))) {
44d0b80e 415 DEB_INT("irq: RPS0 (0x%08x)\n", isr);
1da177e4
LT
416 saa7146_video_uops.irq_done(dev,isr);
417 }
418
419 if (0 != (isr & (MASK_28))) {
420 u32 mc2 = saa7146_read(dev, MC2);
421 if( 0 != (mc2 & MASK_15)) {
44d0b80e 422 DEB_INT("irq: RPS1 vbi workaround (0x%08x)\n", isr);
1da177e4
LT
423 wake_up(&dev->vv_data->vbi_wq);
424 saa7146_write(dev,MC2, MASK_31);
425 return;
426 }
44d0b80e 427 DEB_INT("irq: RPS1 (0x%08x)\n", isr);
1da177e4
LT
428 saa7146_vbi_uops.irq_done(dev,isr);
429 }
430}
431
6e65ca94
HV
432static const struct v4l2_ctrl_ops saa7146_ctrl_ops = {
433 .s_ctrl = saa7146_s_ctrl,
434};
435
1da177e4
LT
436int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
437{
6e65ca94 438 struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
5da545ad 439 struct v4l2_pix_format *fmt;
fca3469a 440 struct v4l2_vbi_format *vbi;
230b65f9 441 struct saa7146_vv *vv;
03b1930e
HV
442 int err;
443
444 err = v4l2_device_register(&dev->pci->dev, &dev->v4l2_dev);
445 if (err)
446 return err;
230b65f9 447
6e65ca94
HV
448 v4l2_ctrl_handler_init(hdl, 6);
449 v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
450 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
451 v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
452 V4L2_CID_CONTRAST, 0, 127, 1, 64);
453 v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
454 V4L2_CID_SATURATION, 0, 127, 1, 64);
455 v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
456 V4L2_CID_VFLIP, 0, 1, 1, 0);
457 v4l2_ctrl_new_std(hdl, &saa7146_ctrl_ops,
458 V4L2_CID_HFLIP, 0, 1, 1, 0);
459 if (hdl->error) {
460 err = hdl->error;
461 v4l2_ctrl_handler_free(hdl);
462 return err;
463 }
464 dev->v4l2_dev.ctrl_handler = hdl;
465
230b65f9 466 vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL);
b960074f 467 if (vv == NULL) {
44d0b80e 468 ERR("out of memory. aborting.\n");
6e65ca94 469 v4l2_ctrl_handler_free(hdl);
230b65f9 470 return -ENOMEM;
1da177e4 471 }
b960074f
HV
472 ext_vv->ops = saa7146_video_ioctl_ops;
473 ext_vv->core_ops = &saa7146_video_ioctl_ops;
1da177e4 474
44d0b80e 475 DEB_EE("dev:%p\n", dev);
1da177e4
LT
476
477 /* set default values for video parts of the saa7146 */
478 saa7146_write(dev, BCS_CTRL, 0x80400040);
479
480 /* enable video-port pins */
481 saa7146_write(dev, MC1, (MASK_10 | MASK_26));
482
483 /* save per-device extension data (one extension can
484 handle different devices that might need different
485 configuration data) */
486 dev->ext_vv_data = ext_vv;
afd1a0c9 487
afd1a0c9 488 vv->d_clipping.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, &vv->d_clipping.dma_handle);
1da177e4 489 if( NULL == vv->d_clipping.cpu_addr ) {
44d0b80e 490 ERR("out of memory. aborting.\n");
1da177e4 491 kfree(vv);
6e65ca94 492 v4l2_ctrl_handler_free(hdl);
1da177e4
LT
493 return -1;
494 }
495 memset(vv->d_clipping.cpu_addr, 0x0, SAA7146_CLIPPING_MEM);
496
497 saa7146_video_uops.init(dev,vv);
5b0fa4ff
OE
498 if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
499 saa7146_vbi_uops.init(dev,vv);
afd1a0c9 500
5da545ad
HV
501 fmt = &vv->ov_fb.fmt;
502 fmt->width = vv->standard->h_max_out;
503 fmt->height = vv->standard->v_max_out;
504 fmt->pixelformat = V4L2_PIX_FMT_RGB565;
505 fmt->bytesperline = 2 * fmt->width;
506 fmt->sizeimage = fmt->bytesperline * fmt->height;
507 fmt->colorspace = V4L2_COLORSPACE_SRGB;
fd74d6eb
HV
508
509 fmt = &vv->video_fmt;
510 fmt->width = 384;
511 fmt->height = 288;
512 fmt->pixelformat = V4L2_PIX_FMT_BGR24;
513 fmt->field = V4L2_FIELD_ANY;
514 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
515 fmt->bytesperline = 3 * fmt->width;
516 fmt->sizeimage = fmt->bytesperline * fmt->height;
517
fca3469a
HV
518 vbi = &vv->vbi_fmt;
519 vbi->sampling_rate = 27000000;
520 vbi->offset = 248; /* todo */
521 vbi->samples_per_line = 720 * 2;
522 vbi->sample_format = V4L2_PIX_FMT_GREY;
523
524 /* fixme: this only works for PAL */
525 vbi->start[0] = 5;
526 vbi->count[0] = 16;
527 vbi->start[1] = 312;
528 vbi->count[1] = 16;
529
530 init_timer(&vv->vbi_read_timeout);
531
5da545ad
HV
532 vv->ov_fb.capability = V4L2_FBUF_CAP_LIST_CLIPPING;
533 vv->ov_fb.flags = V4L2_FBUF_FLAG_PRIMARY;
1da177e4
LT
534 dev->vv_data = vv;
535 dev->vv_callback = &vv_callback;
536
537 return 0;
538}
5d7dc8c4 539EXPORT_SYMBOL_GPL(saa7146_vv_init);
1da177e4
LT
540
541int saa7146_vv_release(struct saa7146_dev* dev)
542{
543 struct saa7146_vv *vv = dev->vv_data;
544
44d0b80e 545 DEB_EE("dev:%p\n", dev);
afd1a0c9 546
230b65f9 547 v4l2_device_unregister(&dev->v4l2_dev);
58af0045 548 pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
6e65ca94 549 v4l2_ctrl_handler_free(&dev->ctrl_handler);
afd1a0c9 550 kfree(vv);
1da177e4
LT
551 dev->vv_data = NULL;
552 dev->vv_callback = NULL;
afd1a0c9 553
1da177e4
LT
554 return 0;
555}
5d7dc8c4 556EXPORT_SYMBOL_GPL(saa7146_vv_release);
1da177e4
LT
557
558int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
559 char *name, int type)
560{
1da177e4 561 struct video_device *vfd;
b960074f 562 int err;
d0852ed2 563 int i;
1da177e4 564
44d0b80e 565 DEB_EE("dev:%p, name:'%s', type:%d\n", dev, name, type);
1da177e4
LT
566
567 // released by vfd->release
afd1a0c9 568 vfd = video_device_alloc();
1da177e4
LT
569 if (vfd == NULL)
570 return -ENOMEM;
571
b960074f 572 vfd->fops = &video_fops;
d0852ed2 573 vfd->ioctl_ops = &dev->ext_vv_data->ops;
1da177e4 574 vfd->release = video_device_release;
5126f259
HV
575 /* Locking in file operations other than ioctl should be done by
576 the driver, not the V4L2 core.
577 This driver needs auditing so that this flag can be removed. */
578 set_bit(V4L2_FL_LOCK_ALL_FOPS, &vfd->flags);
9af39713 579 vfd->lock = &dev->v4l2_lock;
6e65ca94 580 vfd->v4l2_dev = &dev->v4l2_dev;
d0852ed2
HV
581 vfd->tvnorms = 0;
582 for (i = 0; i < dev->ext_vv_data->num_stds; i++)
583 vfd->tvnorms |= dev->ext_vv_data->stds[i].id;
b960074f 584 strlcpy(vfd->name, name, sizeof(vfd->name));
601e9444 585 video_set_drvdata(vfd, dev);
1da177e4 586
b960074f
HV
587 err = video_register_device(vfd, type, -1);
588 if (err < 0) {
44d0b80e 589 ERR("cannot register v4l2 device. skipping.\n");
a2a9b1ec 590 video_device_release(vfd);
b960074f 591 return err;
1da177e4
LT
592 }
593
44d0b80e
JP
594 pr_info("%s: registered device %s [v4l2]\n",
595 dev->name, video_device_node_name(vfd));
1da177e4
LT
596
597 *vid = vfd;
598 return 0;
599}
5d7dc8c4 600EXPORT_SYMBOL_GPL(saa7146_register_device);
1da177e4
LT
601
602int saa7146_unregister_device(struct video_device **vid, struct saa7146_dev* dev)
603{
44d0b80e 604 DEB_EE("dev:%p\n", dev);
1da177e4 605
1da177e4
LT
606 video_unregister_device(*vid);
607 *vid = NULL;
608
609 return 0;
610}
5d7dc8c4 611EXPORT_SYMBOL_GPL(saa7146_unregister_device);
1da177e4
LT
612
613static int __init saa7146_vv_init_module(void)
614{
615 return 0;
616}
617
618
619static void __exit saa7146_vv_cleanup_module(void)
620{
621}
622
623module_init(saa7146_vv_init_module);
624module_exit(saa7146_vv_cleanup_module);
625
626MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
627MODULE_DESCRIPTION("video4linux driver for saa7146-based hardware");
628MODULE_LICENSE("GPL");
This page took 0.693357 seconds and 5 git commands to generate.