blob: 3870fa948cc08356a5ec1a8a5bed2b7eadbb941d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <media/saa7146_vv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -08003#define BOARD_CAN_DO_VBI(dev) (dev->revision != 0 && dev->vv_data->vbi_minor != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
5/****************************************************************************/
6/* resource management functions, shamelessly stolen from saa7134 driver */
7
8int saa7146_res_get(struct saa7146_fh *fh, unsigned int bit)
9{
10 struct saa7146_dev *dev = fh->dev;
11 struct saa7146_vv *vv = dev->vv_data;
12
13 if (fh->resources & bit) {
14 DEB_D(("already allocated! want: 0x%02x, cur:0x%02x\n",bit,vv->resources));
15 /* have it already allocated */
16 return 1;
17 }
18
19 /* is it free? */
Ingo Molnar3593cab2006-02-07 06:49:14 -020020 mutex_lock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 if (vv->resources & bit) {
22 DEB_D(("locked! vv->resources:0x%02x, we want:0x%02x\n",vv->resources,bit));
23 /* no, someone else uses it */
Ingo Molnar3593cab2006-02-07 06:49:14 -020024 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 return 0;
26 }
27 /* it's free, grab it */
28 fh->resources |= bit;
29 vv->resources |= bit;
30 DEB_D(("res: get 0x%02x, cur:0x%02x\n",bit,vv->resources));
Ingo Molnar3593cab2006-02-07 06:49:14 -020031 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 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
Eric Sesterhennae246012006-03-13 13:17:11 -030040 BUG_ON((fh->resources & bits) != bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Ingo Molnar3593cab2006-02-07 06:49:14 -020042 mutex_lock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 fh->resources &= ~bits;
44 vv->resources &= ~bits;
45 DEB_D(("res: put 0x%02x, cur:0x%02x\n",bits,vv->resources));
Ingo Molnar3593cab2006-02-07 06:49:14 -020046 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
49
50/********************************************************************************/
51/* common dma functions */
52
53void saa7146_dma_free(struct saa7146_dev *dev,struct saa7146_buf *buf)
54{
55 DEB_EE(("dev:%p, buf:%p\n",dev,buf));
56
Eric Sesterhennae246012006-03-13 13:17:11 -030057 BUG_ON(in_interrupt());
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 videobuf_waiton(&buf->vb,0,0);
60 videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma);
61 videobuf_dma_free(&buf->vb.dma);
62 buf->vb.state = STATE_NEEDS_INIT;
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);
74 DEB_EE(("dev:%p, dmaq:%p, buf:%p\n", dev, q, buf));
75
76 BUG_ON(!q);
77
78 if (NULL == q->curr) {
79 q->curr = buf;
80 DEB_D(("immediately activating buffer %p\n", buf));
81 buf->activate(dev,buf,NULL);
82 } else {
83 list_add_tail(&buf->vb.queue,&q->queue);
84 buf->vb.state = STATE_QUEUED;
85 DEB_D(("adding buffer %p to queue. (active buffer present)\n", buf));
86 }
87 return 0;
88}
89
90void saa7146_buffer_finish(struct saa7146_dev *dev,
91 struct saa7146_dmaqueue *q,
92 int state)
93{
94 assert_spin_locked(&dev->slock);
95 DEB_EE(("dev:%p, dmaq:%p, state:%d\n", dev, q, state));
96 DEB_EE(("q->curr:%p\n",q->curr));
97
98 BUG_ON(!q->curr);
99
100 /* finish current buffer */
101 if (NULL == q->curr) {
102 DEB_D(("aiii. no current buffer\n"));
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800103 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 q->curr->vb.state = state;
107 do_gettimeofday(&q->curr->vb.ts);
108 wake_up(&q->curr->vb.done);
109
110 q->curr = NULL;
111}
112
113void saa7146_buffer_next(struct saa7146_dev *dev,
114 struct saa7146_dmaqueue *q, int vbi)
115{
116 struct saa7146_buf *buf,*next = NULL;
117
118 BUG_ON(!q);
119
120 DEB_INT(("dev:%p, dmaq:%p, vbi:%d\n", dev, q, vbi));
121
122 assert_spin_locked(&dev->slock);
123 if (!list_empty(&q->queue)) {
124 /* activate next one from queue */
125 buf = list_entry(q->queue.next,struct saa7146_buf,vb.queue);
126 list_del(&buf->vb.queue);
127 if (!list_empty(&q->queue))
128 next = list_entry(q->queue.next,struct saa7146_buf, vb.queue);
129 q->curr = buf;
130 DEB_INT(("next buffer: buf:%p, prev:%p, next:%p\n", buf, q->queue.prev,q->queue.next));
131 buf->activate(dev,buf,next);
132 } else {
133 DEB_INT(("no next buffer. stopping.\n"));
134 if( 0 != vbi ) {
135 /* turn off video-dma3 */
136 saa7146_write(dev,MC1, MASK_20);
137 } else {
138 /* nothing to do -- just prevent next video-dma1 transfer
139 by lowering the protection address */
140
141 // fixme: fix this for vflip != 0
142
143 saa7146_write(dev, PROT_ADDR1, 0);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800144 saa7146_write(dev, MC2, (MASK_02|MASK_18));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* write the address of the rps-program */
147 saa7146_write(dev, RPS_ADDR0, dev->d_rps0.dma_handle);
148 /* turn on rps */
149 saa7146_write(dev, MC1, (MASK_12 | MASK_28));
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151/*
152 printk("vdma%d.base_even: 0x%08x\n", 1,saa7146_read(dev,BASE_EVEN1));
153 printk("vdma%d.base_odd: 0x%08x\n", 1,saa7146_read(dev,BASE_ODD1));
154 printk("vdma%d.prot_addr: 0x%08x\n", 1,saa7146_read(dev,PROT_ADDR1));
155 printk("vdma%d.base_page: 0x%08x\n", 1,saa7146_read(dev,BASE_PAGE1));
156 printk("vdma%d.pitch: 0x%08x\n", 1,saa7146_read(dev,PITCH1));
157 printk("vdma%d.num_line_byte: 0x%08x\n", 1,saa7146_read(dev,NUM_LINE_BYTE1));
158*/
159 }
160 del_timer(&q->timeout);
161 }
162}
163
164void saa7146_buffer_timeout(unsigned long data)
165{
166 struct saa7146_dmaqueue *q = (struct saa7146_dmaqueue*)data;
167 struct saa7146_dev *dev = q->dev;
168 unsigned long flags;
169
170 DEB_EE(("dev:%p, dmaq:%p\n", dev, q));
171
172 spin_lock_irqsave(&dev->slock,flags);
173 if (q->curr) {
174 DEB_D(("timeout on %p\n", q->curr));
175 saa7146_buffer_finish(dev,q,STATE_ERROR);
176 }
177
178 /* we don't restart the transfer here like other drivers do. when
179 a streaming capture is disabled, the timeout function will be
180 called for the current buffer. if we activate the next buffer now,
181 we mess up our capture logic. if a timeout occurs on another buffer,
182 then something is seriously broken before, so no need to buffer the
183 next capture IMHO... */
184/*
185 saa7146_buffer_next(dev,q);
186*/
187 spin_unlock_irqrestore(&dev->slock,flags);
188}
189
190/********************************************************************************/
191/* file operations */
192
193static int fops_open(struct inode *inode, struct file *file)
194{
195 unsigned int minor = iminor(inode);
196 struct saa7146_dev *h = NULL, *dev = NULL;
197 struct list_head *list;
198 struct saa7146_fh *fh = NULL;
199 int result = 0;
200
201 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
202
203 DEB_EE(("inode:%p, file:%p, minor:%d\n",inode,file,minor));
204
Ingo Molnar3593cab2006-02-07 06:49:14 -0200205 if (mutex_lock_interruptible(&saa7146_devices_lock))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return -ERESTARTSYS;
207
208 list_for_each(list,&saa7146_devices) {
209 h = list_entry(list, struct saa7146_dev, item);
210 if( NULL == h->vv_data ) {
211 DEB_D(("device %p has not registered video devices.\n",h));
212 continue;
213 }
214 DEB_D(("trying: %p @ major %d,%d\n",h,h->vv_data->video_minor,h->vv_data->vbi_minor));
215
216 if (h->vv_data->video_minor == minor) {
217 dev = h;
218 }
219 if (h->vv_data->vbi_minor == minor) {
220 type = V4L2_BUF_TYPE_VBI_CAPTURE;
221 dev = h;
222 }
223 }
224 if (NULL == dev) {
225 DEB_S(("no such video device.\n"));
226 result = -ENODEV;
227 goto out;
228 }
229
230 DEB_D(("using: %p\n",dev));
231
232 /* check if an extension is registered */
233 if( NULL == dev->ext ) {
234 DEB_S(("no extension registered for this device.\n"));
235 result = -ENODEV;
236 goto out;
237 }
238
239 /* allocate per open data */
Panagiotis Issaris74081872006-01-11 19:40:56 -0200240 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (NULL == fh) {
242 DEB_S(("cannot allocate memory for per open data.\n"));
243 result = -ENOMEM;
244 goto out;
245 }
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 file->private_data = fh;
248 fh->dev = dev;
249 fh->type = type;
250
251 if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
252 DEB_S(("initializing vbi...\n"));
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200253 if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
254 result = saa7146_vbi_uops.open(dev,file);
255 if (dev->ext_vv_data->vbi_fops.open)
256 dev->ext_vv_data->vbi_fops.open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 } else {
258 DEB_S(("initializing video...\n"));
259 result = saa7146_video_uops.open(dev,file);
260 }
261
262 if (0 != result) {
263 goto out;
264 }
265
266 if( 0 == try_module_get(dev->ext->module)) {
267 result = -EINVAL;
268 goto out;
269 }
270
271 result = 0;
272out:
273 if( fh != 0 && result != 0 ) {
274 kfree(fh);
275 file->private_data = NULL;
276 }
Ingo Molnar3593cab2006-02-07 06:49:14 -0200277 mutex_unlock(&saa7146_devices_lock);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800278 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
281static int fops_release(struct inode *inode, struct file *file)
282{
283 struct saa7146_fh *fh = file->private_data;
284 struct saa7146_dev *dev = fh->dev;
285
286 DEB_EE(("inode:%p, file:%p\n",inode,file));
287
Ingo Molnar3593cab2006-02-07 06:49:14 -0200288 if (mutex_lock_interruptible(&saa7146_devices_lock))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 return -ERESTARTSYS;
290
291 if( fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200292 if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
293 saa7146_vbi_uops.release(dev,file);
294 if (dev->ext_vv_data->vbi_fops.release)
295 dev->ext_vv_data->vbi_fops.release(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 } else {
297 saa7146_video_uops.release(dev,file);
298 }
299
300 module_put(dev->ext->module);
301 file->private_data = NULL;
302 kfree(fh);
303
Ingo Molnar3593cab2006-02-07 06:49:14 -0200304 mutex_unlock(&saa7146_devices_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 return 0;
307}
308
309int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg);
310static int fops_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
311{
312/*
313 DEB_EE(("inode:%p, file:%p, cmd:%d, arg:%li\n",inode, file, cmd, arg));
314*/
315 return video_usercopy(inode, file, cmd, arg, saa7146_video_do_ioctl);
316}
317
318static int fops_mmap(struct file *file, struct vm_area_struct * vma)
319{
320 struct saa7146_fh *fh = file->private_data;
321 struct videobuf_queue *q;
322
323 switch (fh->type) {
324 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
325 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, vma:%p\n",file, vma));
326 q = &fh->video_q;
327 break;
328 }
329 case V4L2_BUF_TYPE_VBI_CAPTURE: {
330 DEB_EE(("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, vma:%p\n",file, vma));
331 q = &fh->vbi_q;
332 break;
333 }
334 default:
335 BUG();
336 return 0;
337 }
Michael Krufky50c25ff2006-01-09 15:25:34 -0200338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 return videobuf_mmap_mapper(q,vma);
340}
341
342static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait)
343{
344 struct saa7146_fh *fh = file->private_data;
345 struct videobuf_buffer *buf = NULL;
346 struct videobuf_queue *q;
347
348 DEB_EE(("file:%p, poll:%p\n",file, wait));
349
350 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
351 if( 0 == fh->vbi_q.streaming )
352 return videobuf_poll_stream(file, &fh->vbi_q, wait);
353 q = &fh->vbi_q;
354 } else {
355 DEB_D(("using video queue.\n"));
356 q = &fh->video_q;
357 }
358
359 if (!list_empty(&q->stream))
360 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
361
362 if (!buf) {
363 DEB_D(("buf == NULL!\n"));
364 return POLLERR;
365 }
366
367 poll_wait(file, &buf->done, wait);
368 if (buf->state == STATE_DONE || buf->state == STATE_ERROR) {
369 DEB_D(("poll succeeded!\n"));
370 return POLLIN|POLLRDNORM;
371 }
372
373 DEB_D(("nothing to poll for, buf->state:%d\n",buf->state));
374 return 0;
375}
376
377static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
378{
379 struct saa7146_fh *fh = file->private_data;
380
381 switch (fh->type) {
382 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
383// DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: file:%p, data:%p, count:%lun", file, data, (unsigned long)count));
384 return saa7146_video_uops.read(file,data,count,ppos);
385 }
386 case V4L2_BUF_TYPE_VBI_CAPTURE: {
387// DEB_EE(("V4L2_BUF_TYPE_VBI_CAPTURE: file:%p, data:%p, count:%lu\n", file, data, (unsigned long)count));
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200388 if (fh->dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
389 return saa7146_vbi_uops.read(file,data,count,ppos);
390 else
391 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
393 break;
394 default:
395 BUG();
396 return 0;
397 }
398}
399
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200400static ssize_t fops_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
401{
402 struct saa7146_fh *fh = file->private_data;
403
404 switch (fh->type) {
405 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
406 return -EINVAL;
407 case V4L2_BUF_TYPE_VBI_CAPTURE:
408 if (fh->dev->ext_vv_data->vbi_fops.write)
409 return fh->dev->ext_vv_data->vbi_fops.write(file, data, count, ppos);
410 else
411 return -EINVAL;
412 default:
413 BUG();
414 return -EINVAL;
415 }
416}
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418static struct file_operations video_fops =
419{
420 .owner = THIS_MODULE,
421 .open = fops_open,
422 .release = fops_release,
423 .read = fops_read,
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200424 .write = fops_write,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .poll = fops_poll,
426 .mmap = fops_mmap,
427 .ioctl = fops_ioctl,
428 .llseek = no_llseek,
429};
430
Adrian Bunk52c1da32005-06-23 22:05:33 -0700431static void vv_callback(struct saa7146_dev *dev, unsigned long status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 u32 isr = status;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 DEB_INT(("dev:%p, isr:0x%08x\n",dev,(u32)status));
436
437 if (0 != (isr & (MASK_27))) {
438 DEB_INT(("irq: RPS0 (0x%08x).\n",isr));
439 saa7146_video_uops.irq_done(dev,isr);
440 }
441
442 if (0 != (isr & (MASK_28))) {
443 u32 mc2 = saa7146_read(dev, MC2);
444 if( 0 != (mc2 & MASK_15)) {
445 DEB_INT(("irq: RPS1 vbi workaround (0x%08x).\n",isr));
446 wake_up(&dev->vv_data->vbi_wq);
447 saa7146_write(dev,MC2, MASK_31);
448 return;
449 }
450 DEB_INT(("irq: RPS1 (0x%08x).\n",isr));
451 saa7146_vbi_uops.irq_done(dev,isr);
452 }
453}
454
455static struct video_device device_template =
456{
457 .hardware = VID_HARDWARE_SAA7146,
458 .fops = &video_fops,
459 .minor = -1,
460};
461
462int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
463{
Panagiotis Issaris74081872006-01-11 19:40:56 -0200464 struct saa7146_vv *vv = kzalloc (sizeof(struct saa7146_vv),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 if( NULL == vv ) {
466 ERR(("out of memory. aborting.\n"));
467 return -1;
468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 DEB_EE(("dev:%p\n",dev));
471
472 /* set default values for video parts of the saa7146 */
473 saa7146_write(dev, BCS_CTRL, 0x80400040);
474
475 /* enable video-port pins */
476 saa7146_write(dev, MC1, (MASK_10 | MASK_26));
477
478 /* save per-device extension data (one extension can
479 handle different devices that might need different
480 configuration data) */
481 dev->ext_vv_data = ext_vv;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 vv->video_minor = -1;
484 vv->vbi_minor = -1;
485
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800486 vv->d_clipping.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_CLIPPING_MEM, &vv->d_clipping.dma_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 if( NULL == vv->d_clipping.cpu_addr ) {
488 ERR(("out of memory. aborting.\n"));
489 kfree(vv);
490 return -1;
491 }
492 memset(vv->d_clipping.cpu_addr, 0x0, SAA7146_CLIPPING_MEM);
493
494 saa7146_video_uops.init(dev,vv);
Oliver Endriss5b0fa4f2006-01-09 18:21:37 -0200495 if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
496 saa7146_vbi_uops.init(dev,vv);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 dev->vv_data = vv;
499 dev->vv_callback = &vv_callback;
500
501 return 0;
502}
503
504int saa7146_vv_release(struct saa7146_dev* dev)
505{
506 struct saa7146_vv *vv = dev->vv_data;
507
508 DEB_EE(("dev:%p\n",dev));
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 pci_free_consistent(dev->pci, SAA7146_RPS_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800511 kfree(vv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 dev->vv_data = NULL;
513 dev->vv_callback = NULL;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 return 0;
516}
517
518int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
519 char *name, int type)
520{
521 struct saa7146_vv *vv = dev->vv_data;
522 struct video_device *vfd;
523
524 DEB_EE(("dev:%p, name:'%s', type:%d\n",dev,name,type));
525
526 // released by vfd->release
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800527 vfd = video_device_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 if (vfd == NULL)
529 return -ENOMEM;
530
531 memcpy(vfd, &device_template, sizeof(struct video_device));
532 strlcpy(vfd->name, name, sizeof(vfd->name));
533 vfd->release = video_device_release;
534 vfd->priv = dev;
535
536 // fixme: -1 should be an insmod parameter *for the extension* (like "video_nr");
537 if (video_register_device(vfd, type, -1) < 0) {
538 ERR(("cannot register v4l2 device. skipping.\n"));
539 return -1;
540 }
541
542 if( VFL_TYPE_GRABBER == type ) {
543 vv->video_minor = vfd->minor;
544 INFO(("%s: registered device video%d [v4l2]\n",
545 dev->name, vfd->minor & 0x1f));
546 } else {
547 vv->vbi_minor = vfd->minor;
548 INFO(("%s: registered device vbi%d [v4l2]\n",
549 dev->name, vfd->minor & 0x1f));
550 }
551
552 *vid = vfd;
553 return 0;
554}
555
556int saa7146_unregister_device(struct video_device **vid, struct saa7146_dev* dev)
557{
558 struct saa7146_vv *vv = dev->vv_data;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 DEB_EE(("dev:%p\n",dev));
561
562 if( VFL_TYPE_GRABBER == (*vid)->type ) {
563 vv->video_minor = -1;
564 } else {
565 vv->vbi_minor = -1;
566 }
567
568 video_unregister_device(*vid);
569 *vid = NULL;
570
571 return 0;
572}
573
574static int __init saa7146_vv_init_module(void)
575{
576 return 0;
577}
578
579
580static void __exit saa7146_vv_cleanup_module(void)
581{
582}
583
584module_init(saa7146_vv_init_module);
585module_exit(saa7146_vv_cleanup_module);
586
587MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
588MODULE_DESCRIPTION("video4linux driver for saa7146-based hardware");
589MODULE_LICENSE("GPL");