]>
Commit | Line | Data |
---|---|---|
d42bffb8 MM |
1 | #include <media/v4l2-dev.h> |
2 | #include <media/videobuf-core.h> | |
3 | #include <media/v4l2-ioctl.h> | |
4 | #include <linux/pci.h> | |
5 | #include <linux/version.h> | |
6 | #include <linux/stringify.h> | |
7ec21181 | 7 | #include <linux/delay.h> |
d42bffb8 MM |
8 | #include <media/videobuf-dma-contig.h> |
9 | #include <linux/kthread.h> | |
10 | ||
11 | #include "dt3155v4l.h" | |
12 | #include "dt3155-bufs.h" | |
13 | ||
14 | #define DT3155_VENDOR_ID 0x8086 | |
15 | #define DT3155_DEVICE_ID 0x1223 | |
16 | ||
17 | /* global initializers (for all boards) */ | |
18 | #ifdef CONFIG_DT3155_CCIR | |
19 | static const u8 csr2_init = VT_50HZ; | |
20 | #define DT3155_CURRENT_NORM V4L2_STD_625_50 | |
21 | static const unsigned int img_width = 768; | |
22 | static const unsigned int img_height = 576; | |
23 | static const unsigned int frames_per_sec = 25; | |
24 | static const struct v4l2_fmtdesc frame_std[] = { | |
25 | { | |
26 | .index = 0, | |
27 | .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, | |
28 | .flags = 0, | |
29 | .description = "CCIR/50Hz 8 bits gray", | |
30 | .pixelformat = V4L2_PIX_FMT_GREY, | |
31 | }, | |
32 | }; | |
33 | #else | |
34 | static const u8 csr2_init = VT_60HZ; | |
35 | #define DT3155_CURRENT_NORM V4L2_STD_525_60 | |
36 | static const unsigned int img_width = 640; | |
37 | static const unsigned int img_height = 480; | |
38 | static const unsigned int frames_per_sec = 30; | |
39 | static const struct v4l2_fmtdesc frame_std[] = { | |
40 | { | |
41 | .index = 0, | |
42 | .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, | |
43 | .flags = 0, | |
44 | .description = "RS-170/60Hz 8 bits gray", | |
45 | .pixelformat = V4L2_PIX_FMT_GREY, | |
46 | }, | |
47 | }; | |
48 | #endif | |
49 | ||
50 | #define NUM_OF_FORMATS ARRAY_SIZE(frame_std) | |
51 | ||
52 | static u8 config_init = ACQ_MODE_EVEN; | |
53 | ||
54 | /** | |
55 | * read_i2c_reg - reads an internal i2c register | |
56 | * | |
57 | * @addr: dt3155 mmio base address | |
58 | * @index: index (internal address) of register to read | |
59 | * @data: pointer to byte the read data will be placed in | |
60 | * | |
61 | * returns: zero on success or error code | |
62 | * | |
63 | * This function starts reading the specified (by index) register | |
64 | * and busy waits for the process to finish. The result is placed | |
65 | * in a byte pointed by data. | |
66 | */ | |
67 | static int | |
2342df0e | 68 | read_i2c_reg(void __iomem *addr, u8 index, u8 *data) |
d42bffb8 MM |
69 | { |
70 | u32 tmp = index; | |
71 | ||
72 | iowrite32((tmp<<17) | IIC_READ, addr + IIC_CSR2); | |
73 | mmiowb(); | |
74 | udelay(45); /* wait at least 43 usec for NEW_CYCLE to clear */ | |
75 | if (ioread32(addr + IIC_CSR2) & NEW_CYCLE) { | |
76 | /* error: NEW_CYCLE not cleared */ | |
77 | printk(KERN_ERR "dt3155: NEW_CYCLE not cleared\n"); | |
78 | return -EIO; | |
79 | } | |
80 | tmp = ioread32(addr + IIC_CSR1); | |
81 | if (tmp & DIRECT_ABORT) { | |
82 | /* error: DIRECT_ABORT set */ | |
83 | printk(KERN_ERR "dt3155: DIRECT_ABORT set\n"); | |
84 | /* reset DIRECT_ABORT bit */ | |
85 | iowrite32(DIRECT_ABORT, addr + IIC_CSR1); | |
86 | return -EIO; | |
87 | } | |
88 | *data = tmp>>24; | |
89 | return 0; | |
90 | } | |
91 | ||
92 | /** | |
93 | * write_i2c_reg - writes to an internal i2c register | |
94 | * | |
95 | * @addr: dt3155 mmio base address | |
96 | * @index: index (internal address) of register to read | |
97 | * @data: data to be written | |
98 | * | |
99 | * returns: zero on success or error code | |
100 | * | |
101 | * This function starts writting the specified (by index) register | |
102 | * and busy waits for the process to finish. | |
103 | */ | |
104 | static int | |
2342df0e | 105 | write_i2c_reg(void __iomem *addr, u8 index, u8 data) |
d42bffb8 MM |
106 | { |
107 | u32 tmp = index; | |
108 | ||
109 | iowrite32((tmp<<17) | IIC_WRITE | data, addr + IIC_CSR2); | |
110 | mmiowb(); | |
111 | udelay(65); /* wait at least 63 usec for NEW_CYCLE to clear */ | |
112 | if (ioread32(addr + IIC_CSR2) & NEW_CYCLE) { | |
113 | /* error: NEW_CYCLE not cleared */ | |
114 | printk(KERN_ERR "dt3155: NEW_CYCLE not cleared\n"); | |
115 | return -EIO; | |
116 | } | |
117 | if (ioread32(addr + IIC_CSR1) & DIRECT_ABORT) { | |
118 | /* error: DIRECT_ABORT set */ | |
119 | printk(KERN_ERR "dt3155: DIRECT_ABORT set\n"); | |
120 | /* reset DIRECT_ABORT bit */ | |
121 | iowrite32(DIRECT_ABORT, addr + IIC_CSR1); | |
122 | return -EIO; | |
123 | } | |
124 | return 0; | |
125 | } | |
126 | ||
127 | /** | |
128 | * write_i2c_reg_nowait - writes to an internal i2c register | |
129 | * | |
130 | * @addr: dt3155 mmio base address | |
131 | * @index: index (internal address) of register to read | |
132 | * @data: data to be written | |
133 | * | |
134 | * This function starts writting the specified (by index) register | |
135 | * and then returns. | |
136 | */ | |
2342df0e | 137 | static void write_i2c_reg_nowait(void __iomem *addr, u8 index, u8 data) |
d42bffb8 MM |
138 | { |
139 | u32 tmp = index; | |
140 | ||
141 | iowrite32((tmp<<17) | IIC_WRITE | data, addr + IIC_CSR2); | |
142 | mmiowb(); | |
143 | } | |
144 | ||
145 | /** | |
146 | * wait_i2c_reg - waits the read/write to finish | |
147 | * | |
148 | * @addr: dt3155 mmio base address | |
149 | * | |
150 | * returns: zero on success or error code | |
151 | * | |
152 | * This function waits reading/writting to finish. | |
153 | */ | |
2342df0e | 154 | static int wait_i2c_reg(void __iomem *addr) |
d42bffb8 MM |
155 | { |
156 | if (ioread32(addr + IIC_CSR2) & NEW_CYCLE) | |
157 | udelay(65); /* wait at least 63 usec for NEW_CYCLE to clear */ | |
158 | if (ioread32(addr + IIC_CSR2) & NEW_CYCLE) { | |
159 | /* error: NEW_CYCLE not cleared */ | |
160 | printk(KERN_ERR "dt3155: NEW_CYCLE not cleared\n"); | |
161 | return -EIO; | |
162 | } | |
163 | if (ioread32(addr + IIC_CSR1) & DIRECT_ABORT) { | |
164 | /* error: DIRECT_ABORT set */ | |
165 | printk(KERN_ERR "dt3155: DIRECT_ABORT set\n"); | |
166 | /* reset DIRECT_ABORT bit */ | |
167 | iowrite32(DIRECT_ABORT, addr + IIC_CSR1); | |
168 | return -EIO; | |
169 | } | |
170 | return 0; | |
171 | } | |
172 | ||
173 | /* | |
174 | * global pointers to a list of 4MB chunks reserved at driver | |
175 | * load, broken down to contiguous buffers of 768 * 576 bytes | |
176 | * each to form a pool of buffers for allocations | |
177 | * FIXME: add spinlock to protect moves between alloc/free lists | |
178 | */ | |
179 | static struct dt3155_fifo *dt3155_chunks; /* list of 4MB chuncks */ | |
180 | static struct dt3155_fifo *dt3155_free_bufs; /* list of free buffers */ | |
181 | static struct dt3155_fifo *dt3155_alloc_bufs; /* list of allocated buffers */ | |
182 | ||
183 | /* same as in <drivers/media/video/videobuf-dma-contig.c> */ | |
184 | struct videobuf_dma_contig_memory { | |
185 | u32 magic; | |
186 | void *vaddr; | |
187 | dma_addr_t dma_handle; | |
188 | unsigned long size; | |
189 | int is_userptr; | |
190 | }; | |
191 | ||
192 | #define MAGIC_DC_MEM 0x0733ac61 | |
193 | #define MAGIC_CHECK(is, should) \ | |
194 | if (unlikely((is) != (should))) { \ | |
195 | pr_err("magic mismatch: %x expected %x\n", (is), (should)); \ | |
196 | BUG(); \ | |
197 | } | |
198 | ||
199 | /* helper functions to allocate/free buffers from the pool */ | |
200 | static void * | |
201 | dt3155_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle, | |
202 | gfp_t flag) | |
203 | { | |
204 | struct dt3155_buf *buf; | |
205 | ||
206 | if (size > DT3155_BUF_SIZE) | |
207 | return NULL; | |
208 | size = DT3155_BUF_SIZE; /* same for CCIR & RS-170 */ | |
209 | buf = dt3155_get_buf(dt3155_free_bufs); | |
210 | if (!buf) | |
211 | return NULL; | |
212 | buf->dma = dma_map_single(dev, buf->cpu, size, DMA_FROM_DEVICE); | |
213 | if (dma_mapping_error(dev, buf->dma)) { | |
214 | dt3155_put_buf(buf, dt3155_free_bufs); | |
215 | return NULL; | |
216 | } | |
217 | dt3155_put_buf(buf, dt3155_alloc_bufs); | |
218 | *dma_handle = buf->dma; | |
219 | return buf->cpu; | |
220 | } | |
221 | ||
222 | static void | |
223 | dt3155_free_buffer(struct device *dev, size_t size, void *cpu_addr, | |
224 | dma_addr_t dma_handle) | |
225 | { | |
226 | struct dt3155_buf *buf, *last; | |
227 | int found = 0; | |
228 | ||
229 | if (!cpu_addr) /* to free NULL is OK */ | |
230 | return; | |
231 | last = dt3155_get_buf(dt3155_alloc_bufs); | |
232 | if (!last) { | |
233 | printk(KERN_ERR "dt3155: %s(): no alloc buffers\n", __func__); | |
234 | return; | |
235 | } | |
236 | dt3155_put_buf(last, dt3155_alloc_bufs); | |
237 | do { | |
238 | buf = dt3155_get_buf(dt3155_alloc_bufs); | |
239 | if (buf->cpu == cpu_addr && buf->dma == dma_handle) { | |
240 | found = 1; | |
241 | break; | |
242 | } | |
243 | dt3155_put_buf(buf, dt3155_alloc_bufs); | |
244 | } while (buf != last); | |
245 | if (!found) { | |
246 | printk(KERN_ERR "dt3155: %s(): buffer not found\n", __func__); | |
247 | return; | |
248 | } | |
249 | size = DT3155_BUF_SIZE; /* same for CCIR & RS-170 */ | |
250 | dma_unmap_single(dev, dma_handle, size, DMA_FROM_DEVICE); | |
251 | dt3155_put_buf(buf, dt3155_free_bufs); | |
252 | } | |
253 | ||
254 | /* same as videobuf_dma_contig_user_get() */ | |
255 | static int | |
256 | dt3155_dma_contig_user_get(struct videobuf_dma_contig_memory *mem, | |
257 | struct videobuf_buffer *vb) | |
258 | { | |
259 | struct mm_struct *mm = current->mm; | |
260 | struct vm_area_struct *vma; | |
261 | unsigned long prev_pfn, this_pfn; | |
262 | unsigned long pages_done, user_address; | |
263 | int ret; | |
264 | ||
265 | mem->size = PAGE_ALIGN(vb->size); | |
266 | mem->is_userptr = 0; | |
267 | ret = -EINVAL; | |
268 | ||
269 | down_read(&mm->mmap_sem); | |
270 | ||
271 | vma = find_vma(mm, vb->baddr); | |
272 | if (!vma) | |
273 | goto out_up; | |
274 | ||
275 | if ((vb->baddr + mem->size) > vma->vm_end) | |
276 | goto out_up; | |
277 | ||
278 | pages_done = 0; | |
279 | prev_pfn = 0; /* kill warning */ | |
280 | user_address = vb->baddr; | |
281 | ||
282 | while (pages_done < (mem->size >> PAGE_SHIFT)) { | |
283 | ret = follow_pfn(vma, user_address, &this_pfn); | |
284 | if (ret) | |
285 | break; | |
286 | ||
287 | if (pages_done == 0) | |
288 | mem->dma_handle = this_pfn << PAGE_SHIFT; | |
289 | else if (this_pfn != (prev_pfn + 1)) | |
290 | ret = -EFAULT; | |
291 | ||
292 | if (ret) | |
293 | break; | |
294 | ||
295 | prev_pfn = this_pfn; | |
296 | user_address += PAGE_SIZE; | |
297 | pages_done++; | |
298 | } | |
299 | ||
300 | if (!ret) | |
301 | mem->is_userptr = 1; | |
302 | ||
303 | out_up: | |
304 | up_read(¤t->mm->mmap_sem); | |
305 | ||
306 | return ret; | |
307 | } | |
308 | ||
309 | /* same as videobuf_dma_contig_user_put() */ | |
310 | static void | |
311 | dt3155_dma_contig_user_put(struct videobuf_dma_contig_memory *mem) | |
312 | { | |
313 | mem->is_userptr = 0; | |
314 | mem->dma_handle = 0; | |
315 | mem->size = 0; | |
316 | } | |
317 | ||
318 | /* same as videobuf_iolock() but uses allocations from the pool */ | |
319 | static int | |
320 | dt3155_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb, | |
321 | struct v4l2_framebuffer *fbuf) | |
322 | { | |
323 | struct videobuf_dma_contig_memory *mem = vb->priv; | |
324 | ||
325 | BUG_ON(!mem); | |
326 | MAGIC_CHECK(mem->magic, MAGIC_DC_MEM); | |
327 | ||
328 | switch (vb->memory) { | |
329 | case V4L2_MEMORY_MMAP: | |
330 | dev_dbg(q->dev, "%s memory method MMAP\n", __func__); | |
331 | ||
332 | /* All handling should be done by __videobuf_mmap_mapper() */ | |
333 | if (!mem->vaddr) { | |
334 | dev_err(q->dev, "memory is not alloced/mmapped.\n"); | |
335 | return -EINVAL; | |
336 | } | |
337 | break; | |
338 | case V4L2_MEMORY_USERPTR: | |
339 | dev_dbg(q->dev, "%s memory method USERPTR\n", __func__); | |
340 | ||
341 | /* handle pointer from user space */ | |
342 | if (vb->baddr) | |
343 | return dt3155_dma_contig_user_get(mem, vb); | |
344 | ||
345 | /* allocate memory for the read() method */ | |
346 | mem->size = PAGE_ALIGN(vb->size); | |
347 | mem->vaddr = dt3155_alloc_buffer(q->dev, mem->size, | |
348 | &mem->dma_handle, GFP_KERNEL); | |
349 | if (!mem->vaddr) { | |
350 | dev_err(q->dev, "dma_alloc_coherent %ld failed\n", | |
351 | mem->size); | |
352 | return -ENOMEM; | |
353 | } | |
354 | ||
355 | dev_dbg(q->dev, "dma_alloc_coherent data is at %p (%ld)\n", | |
356 | mem->vaddr, mem->size); | |
357 | break; | |
358 | case V4L2_MEMORY_OVERLAY: | |
359 | default: | |
360 | dev_dbg(q->dev, "%s memory method OVERLAY/unknown\n", | |
361 | __func__); | |
362 | return -EINVAL; | |
363 | } | |
364 | ||
365 | return 0; | |
366 | } | |
367 | ||
368 | /* same as videobuf_dma_contig_free() but uses the pool */ | |
369 | void | |
370 | dt3155_dma_contig_free(struct videobuf_queue *q, struct videobuf_buffer *buf) | |
371 | { | |
372 | struct videobuf_dma_contig_memory *mem = buf->priv; | |
373 | ||
374 | /* mmapped memory can't be freed here, otherwise mmapped region | |
375 | would be released, while still needed. In this case, the memory | |
376 | release should happen inside videobuf_vm_close(). | |
377 | So, it should free memory only if the memory were allocated for | |
378 | read() operation. | |
379 | */ | |
380 | if (buf->memory != V4L2_MEMORY_USERPTR) | |
381 | return; | |
382 | ||
383 | if (!mem) | |
384 | return; | |
385 | ||
386 | MAGIC_CHECK(mem->magic, MAGIC_DC_MEM); | |
387 | ||
388 | /* handle user space pointer case */ | |
389 | if (buf->baddr) { | |
390 | dt3155_dma_contig_user_put(mem); | |
391 | return; | |
392 | } | |
393 | ||
394 | /* read() method */ | |
395 | dt3155_free_buffer(q->dev, mem->size, mem->vaddr, mem->dma_handle); | |
396 | mem->vaddr = NULL; | |
397 | } | |
398 | ||
399 | /* same as videobuf_vm_open() */ | |
400 | static void | |
401 | dt3155_vm_open(struct vm_area_struct *vma) | |
402 | { | |
403 | struct videobuf_mapping *map = vma->vm_private_data; | |
404 | ||
405 | dev_dbg(map->q->dev, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", | |
406 | map, map->count, vma->vm_start, vma->vm_end); | |
407 | ||
408 | map->count++; | |
409 | } | |
410 | ||
411 | /* same as videobuf_vm_close(), but free to the pool */ | |
412 | static void | |
413 | dt3155_vm_close(struct vm_area_struct *vma) | |
414 | { | |
415 | struct videobuf_mapping *map = vma->vm_private_data; | |
416 | struct videobuf_queue *q = map->q; | |
417 | int i; | |
418 | ||
419 | dev_dbg(map->q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", | |
420 | map, map->count, vma->vm_start, vma->vm_end); | |
421 | ||
422 | map->count--; | |
423 | if (0 == map->count) { | |
424 | struct videobuf_dma_contig_memory *mem; | |
425 | ||
426 | dev_dbg(map->q->dev, "munmap %p q=%p\n", map, q); | |
427 | mutex_lock(&q->vb_lock); | |
428 | ||
429 | /* We need first to cancel streams, before unmapping */ | |
430 | if (q->streaming) | |
431 | videobuf_queue_cancel(q); | |
432 | ||
433 | for (i = 0; i < VIDEO_MAX_FRAME; i++) { | |
434 | if (NULL == q->bufs[i]) | |
435 | continue; | |
436 | ||
437 | if (q->bufs[i]->map != map) | |
438 | continue; | |
439 | ||
440 | mem = q->bufs[i]->priv; | |
441 | if (mem) { | |
442 | /* This callback is called only if kernel has | |
443 | allocated memory and this memory is mmapped. | |
444 | In this case, memory should be freed, | |
445 | in order to do memory unmap. | |
446 | */ | |
447 | ||
448 | MAGIC_CHECK(mem->magic, MAGIC_DC_MEM); | |
449 | ||
450 | /* vfree is not atomic - can't be | |
451 | called with IRQ's disabled | |
452 | */ | |
453 | dev_dbg(map->q->dev, "buf[%d] freeing %p\n", | |
454 | i, mem->vaddr); | |
455 | ||
456 | dt3155_free_buffer(q->dev, mem->size, | |
457 | mem->vaddr, mem->dma_handle); | |
458 | mem->vaddr = NULL; | |
459 | } | |
460 | ||
461 | q->bufs[i]->map = NULL; | |
462 | q->bufs[i]->baddr = 0; | |
463 | } | |
464 | ||
465 | kfree(map); | |
466 | ||
467 | mutex_unlock(&q->vb_lock); | |
468 | } | |
469 | } | |
470 | ||
471 | static const struct vm_operations_struct dt3155_vm_ops = { | |
472 | .open = dt3155_vm_open, | |
473 | .close = dt3155_vm_close, | |
474 | }; | |
475 | ||
476 | /* same as videobuf_mmap_mapper(), but allocates from the pool */ | |
477 | static int | |
478 | dt3155_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma) | |
479 | { | |
480 | struct videobuf_dma_contig_memory *mem; | |
481 | struct videobuf_mapping *map; | |
482 | unsigned int first; | |
483 | int retval; | |
484 | unsigned long size, offset = vma->vm_pgoff << PAGE_SHIFT; | |
485 | ||
486 | dev_dbg(q->dev, "%s\n", __func__); | |
487 | if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED)) | |
488 | return -EINVAL; | |
489 | ||
490 | /* look for first buffer to map */ | |
491 | for (first = 0; first < VIDEO_MAX_FRAME; first++) { | |
492 | if (!q->bufs[first]) | |
493 | continue; | |
494 | ||
495 | if (V4L2_MEMORY_MMAP != q->bufs[first]->memory) | |
496 | continue; | |
497 | if (q->bufs[first]->boff == offset) | |
498 | break; | |
499 | } | |
500 | if (VIDEO_MAX_FRAME == first) { | |
501 | dev_dbg(q->dev, "invalid user space offset [offset=0x%lx]\n", | |
502 | offset); | |
503 | return -EINVAL; | |
504 | } | |
505 | ||
506 | /* create mapping + update buffer list */ | |
507 | map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL); | |
508 | if (!map) | |
509 | return -ENOMEM; | |
510 | ||
511 | q->bufs[first]->map = map; | |
512 | map->start = vma->vm_start; | |
513 | map->end = vma->vm_end; | |
514 | map->q = q; | |
515 | ||
516 | q->bufs[first]->baddr = vma->vm_start; | |
517 | ||
518 | mem = q->bufs[first]->priv; | |
519 | BUG_ON(!mem); | |
520 | MAGIC_CHECK(mem->magic, MAGIC_DC_MEM); | |
521 | ||
522 | mem->size = PAGE_ALIGN(q->bufs[first]->bsize); | |
523 | mem->vaddr = dt3155_alloc_buffer(q->dev, mem->size, | |
524 | &mem->dma_handle, GFP_KERNEL); | |
525 | if (!mem->vaddr) { | |
526 | dev_err(q->dev, "dma_alloc_coherent size %ld failed\n", | |
527 | mem->size); | |
528 | goto error; | |
529 | } | |
530 | dev_dbg(q->dev, "dma_alloc_coherent data is at addr %p (size %ld)\n", | |
531 | mem->vaddr, mem->size); | |
532 | ||
533 | /* Try to remap memory */ | |
534 | ||
535 | size = vma->vm_end - vma->vm_start; | |
536 | size = (size < mem->size) ? size : mem->size; | |
537 | ||
538 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); | |
539 | retval = remap_pfn_range(vma, vma->vm_start, | |
540 | mem->dma_handle >> PAGE_SHIFT, | |
541 | size, vma->vm_page_prot); | |
542 | if (retval) { | |
543 | dev_err(q->dev, "mmap: remap failed with error %d. ", retval); | |
544 | dt3155_free_buffer(q->dev, mem->size, | |
545 | mem->vaddr, mem->dma_handle); | |
546 | goto error; | |
547 | } | |
548 | ||
549 | vma->vm_ops = &dt3155_vm_ops; | |
550 | vma->vm_flags |= VM_DONTEXPAND; | |
551 | vma->vm_private_data = map; | |
552 | ||
553 | dev_dbg(q->dev, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n", | |
554 | map, q, vma->vm_start, vma->vm_end, | |
555 | (long int) q->bufs[first]->bsize, | |
556 | vma->vm_pgoff, first); | |
557 | ||
558 | dt3155_vm_open(vma); | |
559 | ||
560 | return 0; | |
561 | ||
562 | error: | |
563 | kfree(map); | |
564 | return -ENOMEM; | |
565 | } | |
566 | ||
567 | static int | |
568 | dt3155_sync_for_cpu(struct videobuf_queue *q, struct videobuf_buffer *vb) | |
569 | { | |
570 | struct dt3155_priv *pd = q->priv_data; | |
571 | struct videobuf_dma_contig_memory *mem = vb->priv; | |
572 | ||
573 | BUG_ON(!mem); | |
574 | MAGIC_CHECK(mem->magic, MAGIC_DC_MEM); | |
575 | ||
576 | pci_dma_sync_single_for_cpu(pd->pdev, mem->dma_handle, | |
577 | mem->size, PCI_DMA_FROMDEVICE); | |
578 | return 0; | |
579 | } | |
580 | ||
581 | static int | |
582 | dt3155_sync_for_device(struct videobuf_queue *q, struct videobuf_buffer *vb) | |
583 | { | |
584 | struct dt3155_priv *pd = q->priv_data; | |
585 | struct videobuf_dma_contig_memory *mem = vb->priv; | |
586 | ||
587 | BUG_ON(!mem); | |
588 | MAGIC_CHECK(mem->magic, MAGIC_DC_MEM); | |
589 | ||
590 | pci_dma_sync_single_for_device(pd->pdev, mem->dma_handle, | |
591 | mem->size, PCI_DMA_FROMDEVICE); | |
592 | return 0; | |
593 | } | |
594 | ||
595 | /* | |
596 | * same as videobuf_queue_dma_contig_init(), but after | |
597 | * initialisation overwrites videobuf_iolock() and | |
598 | * videobuf_mmap_mapper() with our customized versions | |
599 | * as well as adds sync() method | |
600 | */ | |
601 | static void | |
602 | dt3155_queue_dma_contig_init(struct videobuf_queue *q, | |
603 | struct videobuf_queue_ops *ops, | |
604 | struct device *dev, | |
605 | spinlock_t *irqlock, | |
606 | enum v4l2_buf_type type, | |
607 | enum v4l2_field field, | |
608 | unsigned int msize, | |
609 | void *priv) | |
610 | { | |
611 | videobuf_queue_dma_contig_init(q, ops, dev, irqlock, | |
612 | type, field, msize, priv); | |
613 | /* overwrite with our methods */ | |
614 | q->int_ops->iolock = dt3155_iolock; | |
615 | q->int_ops->mmap_mapper = dt3155_mmap_mapper; | |
616 | q->int_ops->sync = dt3155_sync_for_cpu; | |
617 | } | |
618 | ||
619 | static int | |
620 | dt3155_start_acq(struct dt3155_priv *pd) | |
621 | { | |
622 | struct videobuf_buffer *vb = pd->curr_buf; | |
623 | dma_addr_t dma_addr; | |
624 | ||
625 | dma_addr = videobuf_to_dma_contig(vb); | |
626 | iowrite32(dma_addr, pd->regs + EVEN_DMA_START); | |
627 | iowrite32(dma_addr + vb->width, pd->regs + ODD_DMA_START); | |
628 | iowrite32(vb->width, pd->regs + EVEN_DMA_STRIDE); | |
629 | iowrite32(vb->width, pd->regs + ODD_DMA_STRIDE); | |
630 | /* enable interrupts, clear all irq flags */ | |
631 | iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START | | |
632 | FLD_END_EVEN | FLD_END_ODD, pd->regs + INT_CSR); | |
633 | iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN | | |
634 | FLD_DN_ODD | FLD_DN_EVEN | CAP_CONT_EVEN | CAP_CONT_ODD, | |
635 | pd->regs + CSR1); | |
636 | wait_i2c_reg(pd->regs); | |
637 | write_i2c_reg(pd->regs, CONFIG, pd->config); | |
638 | write_i2c_reg(pd->regs, EVEN_CSR, CSR_ERROR | CSR_DONE); | |
639 | write_i2c_reg(pd->regs, ODD_CSR, CSR_ERROR | CSR_DONE); | |
640 | ||
641 | /* start the board */ | |
642 | write_i2c_reg(pd->regs, CSR2, pd->csr2 | BUSY_EVEN | BUSY_ODD); | |
643 | return 0; /* success */ | |
644 | } | |
645 | ||
646 | static int | |
647 | dt3155_stop_acq(struct dt3155_priv *pd) | |
648 | { | |
649 | int tmp; | |
650 | ||
651 | /* stop the board */ | |
652 | wait_i2c_reg(pd->regs); | |
653 | write_i2c_reg(pd->regs, CSR2, pd->csr2); | |
654 | ||
655 | /* disable all irqs, clear all irq flags */ | |
656 | iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD, pd->regs + INT_CSR); | |
657 | write_i2c_reg(pd->regs, EVEN_CSR, CSR_ERROR | CSR_DONE); | |
658 | write_i2c_reg(pd->regs, ODD_CSR, CSR_ERROR | CSR_DONE); | |
659 | tmp = ioread32(pd->regs + CSR1) & (FLD_CRPT_EVEN | FLD_CRPT_ODD); | |
660 | if (tmp) | |
661 | printk(KERN_ERR "dt3155: corrupted field %u\n", tmp); | |
662 | iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN | | |
663 | FLD_DN_ODD | FLD_DN_EVEN | CAP_CONT_EVEN | CAP_CONT_ODD, | |
664 | pd->regs + CSR1); | |
665 | return 0; | |
666 | } | |
667 | ||
668 | /* Locking: Caller holds q->vb_lock */ | |
669 | static int | |
670 | dt3155_buf_setup(struct videobuf_queue *q, unsigned int *count, | |
671 | unsigned int *size) | |
672 | { | |
673 | *size = img_width * img_height; | |
674 | return 0; | |
675 | } | |
676 | ||
677 | /* Locking: Caller holds q->vb_lock */ | |
678 | static int | |
679 | dt3155_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, | |
680 | enum v4l2_field field) | |
681 | { | |
682 | int ret = 0; | |
683 | ||
684 | vb->width = img_width; | |
685 | vb->height = img_height; | |
686 | vb->size = img_width * img_height; | |
687 | vb->field = field; | |
688 | if (vb->state == VIDEOBUF_NEEDS_INIT) | |
689 | ret = videobuf_iolock(q, vb, NULL); | |
690 | if (ret) { | |
691 | vb->state = VIDEOBUF_ERROR; | |
692 | printk(KERN_ERR "ERROR: videobuf_iolock() failed\n"); | |
693 | videobuf_dma_contig_free(q, vb); | |
694 | } else | |
695 | vb->state = VIDEOBUF_PREPARED; | |
696 | return ret; | |
697 | } | |
698 | ||
699 | /* Locking: Caller holds q->vb_lock & q->irqlock */ | |
700 | static void | |
701 | dt3155_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) | |
702 | { | |
703 | struct dt3155_priv *pd = q->priv_data; | |
704 | ||
705 | if (vb->state != VIDEOBUF_NEEDS_INIT) { | |
706 | vb->state = VIDEOBUF_QUEUED; | |
707 | dt3155_sync_for_device(q, vb); | |
708 | list_add_tail(&vb->queue, &pd->dmaq); | |
709 | wake_up_interruptible_sync(&pd->do_dma); | |
710 | } else | |
711 | vb->state = VIDEOBUF_ERROR; | |
712 | } | |
713 | ||
714 | /* Locking: Caller holds q->vb_lock */ | |
715 | static void | |
716 | dt3155_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) | |
717 | { | |
718 | if (vb->state == VIDEOBUF_ACTIVE) | |
719 | videobuf_waiton(vb, 0, 0); /* FIXME: cannot be interrupted */ | |
720 | dt3155_dma_contig_free(q, vb); | |
721 | vb->state = VIDEOBUF_NEEDS_INIT; | |
722 | } | |
723 | ||
724 | static struct videobuf_queue_ops vbq_ops = { | |
725 | .buf_setup = dt3155_buf_setup, | |
726 | .buf_prepare = dt3155_buf_prepare, | |
727 | .buf_queue = dt3155_buf_queue, | |
728 | .buf_release = dt3155_buf_release, | |
729 | }; | |
730 | ||
731 | static irqreturn_t | |
732 | dt3155_irq_handler_even(int irq, void *dev_id) | |
733 | { | |
734 | struct dt3155_priv *ipd = dev_id; | |
735 | struct videobuf_buffer *ivb; | |
736 | dma_addr_t dma_addr; | |
737 | u32 tmp; | |
738 | ||
739 | tmp = ioread32(ipd->regs + INT_CSR) & (FLD_START | FLD_END_ODD); | |
740 | if (!tmp) | |
741 | return IRQ_NONE; /* not our irq */ | |
742 | if ((tmp & FLD_START) && !(tmp & FLD_END_ODD)) { | |
743 | iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START, | |
744 | ipd->regs + INT_CSR); | |
745 | ipd->field_count++; | |
746 | return IRQ_HANDLED; /* start of field irq */ | |
747 | } | |
748 | if ((tmp & FLD_START) && (tmp & FLD_END_ODD)) { | |
749 | if (!ipd->stats.start_before_end++) | |
750 | printk(KERN_ERR "dt3155: irq: START before END\n"); | |
751 | } | |
752 | /* check for corrupted fields */ | |
753 | /* write_i2c_reg(ipd->regs, EVEN_CSR, CSR_ERROR | CSR_DONE); */ | |
754 | /* write_i2c_reg(ipd->regs, ODD_CSR, CSR_ERROR | CSR_DONE); */ | |
755 | tmp = ioread32(ipd->regs + CSR1) & (FLD_CRPT_EVEN | FLD_CRPT_ODD); | |
756 | if (tmp) { | |
757 | if (!ipd->stats.corrupted_fields++) | |
758 | printk(KERN_ERR "dt3155: corrupted field %u\n", tmp); | |
759 | iowrite32(FIFO_EN | SRST | FLD_CRPT_ODD | FLD_CRPT_EVEN | | |
760 | FLD_DN_ODD | FLD_DN_EVEN | | |
761 | CAP_CONT_EVEN | CAP_CONT_ODD, | |
762 | ipd->regs + CSR1); | |
763 | mmiowb(); | |
764 | } | |
765 | ||
766 | spin_lock(&ipd->lock); | |
767 | if (ipd->curr_buf && ipd->curr_buf->state == VIDEOBUF_ACTIVE) { | |
768 | if (waitqueue_active(&ipd->curr_buf->done)) { | |
769 | do_gettimeofday(&ipd->curr_buf->ts); | |
770 | ipd->curr_buf->field_count = ipd->field_count; | |
771 | ipd->curr_buf->state = VIDEOBUF_DONE; | |
772 | wake_up(&ipd->curr_buf->done); | |
773 | } else { | |
774 | ivb = ipd->curr_buf; | |
775 | goto load_dma; | |
776 | } | |
777 | } else | |
778 | goto stop_dma; | |
779 | if (list_empty(&ipd->dmaq)) | |
780 | goto stop_dma; | |
781 | ivb = list_first_entry(&ipd->dmaq, typeof(*ivb), queue); | |
782 | list_del(&ivb->queue); | |
783 | if (ivb->state == VIDEOBUF_QUEUED) { | |
784 | ivb->state = VIDEOBUF_ACTIVE; | |
785 | ipd->curr_buf = ivb; | |
786 | } else | |
787 | goto stop_dma; | |
788 | load_dma: | |
789 | dma_addr = videobuf_to_dma_contig(ivb); | |
790 | iowrite32(dma_addr, ipd->regs + EVEN_DMA_START); | |
791 | iowrite32(dma_addr + ivb->width, ipd->regs + ODD_DMA_START); | |
792 | iowrite32(ivb->width, ipd->regs + EVEN_DMA_STRIDE); | |
793 | iowrite32(ivb->width, ipd->regs + ODD_DMA_STRIDE); | |
794 | mmiowb(); | |
795 | /* enable interrupts, clear all irq flags */ | |
796 | iowrite32(FLD_START_EN | FLD_END_ODD_EN | FLD_START | | |
797 | FLD_END_EVEN | FLD_END_ODD, ipd->regs + INT_CSR); | |
798 | spin_unlock(&ipd->lock); | |
799 | return IRQ_HANDLED; | |
800 | ||
801 | stop_dma: | |
802 | ipd->curr_buf = NULL; | |
803 | /* stop the board */ | |
804 | write_i2c_reg_nowait(ipd->regs, CSR2, ipd->csr2); | |
805 | /* disable interrupts, clear all irq flags */ | |
806 | iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD, ipd->regs + INT_CSR); | |
807 | spin_unlock(&ipd->lock); | |
808 | return IRQ_HANDLED; | |
809 | } | |
810 | ||
811 | static int | |
812 | dt3155_threadfn(void *arg) | |
813 | { | |
814 | struct dt3155_priv *pd = arg; | |
815 | struct videobuf_buffer *vb; | |
816 | unsigned long flags; | |
817 | ||
818 | while (1) { | |
819 | wait_event_interruptible(pd->do_dma, | |
820 | kthread_should_stop() || !list_empty(&pd->dmaq)); | |
821 | if (kthread_should_stop()) | |
822 | break; | |
823 | ||
824 | spin_lock_irqsave(&pd->lock, flags); | |
825 | if (pd->curr_buf) /* dma is active */ | |
826 | goto done; | |
827 | if (list_empty(&pd->dmaq)) /* no empty biffers */ | |
828 | goto done; | |
829 | vb = list_first_entry(&pd->dmaq, typeof(*vb), queue); | |
830 | list_del(&vb->queue); | |
831 | if (vb->state == VIDEOBUF_QUEUED) { | |
832 | vb->state = VIDEOBUF_ACTIVE; | |
833 | pd->curr_buf = vb; | |
834 | spin_unlock_irqrestore(&pd->lock, flags); | |
835 | /* start dma */ | |
836 | dt3155_start_acq(pd); | |
837 | continue; | |
838 | } else | |
839 | printk(KERN_DEBUG "%s(): This is a BUG\n", __func__); | |
840 | done: | |
841 | spin_unlock_irqrestore(&pd->lock, flags); | |
842 | } | |
843 | return 0; | |
844 | } | |
845 | ||
846 | static int | |
847 | dt3155_open(struct file *filp) | |
848 | { | |
849 | int ret = 0; | |
850 | struct dt3155_priv *pd = video_drvdata(filp); | |
851 | ||
852 | printk(KERN_INFO "dt3155: open(): minor: %i\n", pd->vdev->minor); | |
853 | ||
854 | if (mutex_lock_interruptible(&pd->mux) == -EINTR) | |
855 | return -ERESTARTSYS; | |
856 | if (!pd->users) { | |
857 | pd->vidq = kzalloc(sizeof(*pd->vidq), GFP_KERNEL); | |
858 | if (!pd->vidq) { | |
859 | printk(KERN_ERR "dt3155: error: alloc queue\n"); | |
860 | ret = -ENOMEM; | |
861 | goto err_alloc_queue; | |
862 | } | |
863 | dt3155_queue_dma_contig_init(pd->vidq, &vbq_ops, | |
864 | &pd->pdev->dev, &pd->lock, | |
865 | V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, | |
866 | sizeof(struct videobuf_buffer), pd); | |
867 | /* disable all irqs, clear all irq flags */ | |
868 | iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD, | |
869 | pd->regs + INT_CSR); | |
870 | pd->irq_handler = dt3155_irq_handler_even; | |
871 | ret = request_irq(pd->pdev->irq, pd->irq_handler, | |
872 | IRQF_SHARED, DT3155_NAME, pd); | |
873 | if (ret) { | |
874 | printk(KERN_ERR "dt3155: error: request_irq\n"); | |
875 | goto err_request_irq; | |
876 | } | |
877 | pd->curr_buf = NULL; | |
878 | pd->thread = kthread_run(dt3155_threadfn, pd, | |
879 | "dt3155_thread_%i", pd->vdev->minor); | |
880 | if (IS_ERR(pd->thread)) { | |
881 | printk(KERN_ERR "dt3155: kthread_run() failed\n"); | |
882 | ret = PTR_ERR(pd->thread); | |
883 | goto err_thread; | |
884 | } | |
885 | pd->field_count = 0; | |
886 | } | |
887 | pd->users++; | |
888 | goto done; | |
889 | err_thread: | |
890 | free_irq(pd->pdev->irq, pd); | |
891 | err_request_irq: | |
892 | kfree(pd->vidq); | |
893 | pd->vidq = NULL; | |
894 | err_alloc_queue: | |
895 | done: | |
896 | mutex_unlock(&pd->mux); | |
897 | return ret; | |
898 | } | |
899 | ||
900 | static int | |
901 | dt3155_release(struct file *filp) | |
902 | { | |
903 | struct dt3155_priv *pd = video_drvdata(filp); | |
904 | struct videobuf_buffer *tmp; | |
905 | unsigned long flags; | |
906 | int ret = 0; | |
907 | ||
908 | printk(KERN_INFO "dt3155: release(): minor: %i\n", pd->vdev->minor); | |
909 | ||
910 | if (mutex_lock_interruptible(&pd->mux) == -EINTR) | |
911 | return -ERESTARTSYS; | |
912 | pd->users--; | |
913 | BUG_ON(pd->users < 0); | |
914 | if (pd->acq_fp == filp) { | |
915 | spin_lock_irqsave(&pd->lock, flags); | |
916 | INIT_LIST_HEAD(&pd->dmaq); /* queue is emptied */ | |
917 | tmp = pd->curr_buf; | |
918 | spin_unlock_irqrestore(&pd->lock, flags); | |
919 | if (tmp) | |
920 | videobuf_waiton(tmp, 0, 1); /* block, interruptible */ | |
921 | dt3155_stop_acq(pd); | |
922 | videobuf_stop(pd->vidq); | |
923 | pd->acq_fp = NULL; | |
924 | } | |
925 | if (!pd->users) { | |
926 | kthread_stop(pd->thread); | |
927 | free_irq(pd->pdev->irq, pd); | |
928 | kfree(pd->vidq); | |
929 | pd->vidq = NULL; | |
930 | } | |
931 | mutex_unlock(&pd->mux); | |
932 | return ret; | |
933 | } | |
934 | ||
935 | static ssize_t | |
936 | dt3155_read(struct file *filp, char __user *user, size_t size, loff_t *loff) | |
937 | { | |
938 | struct dt3155_priv *pd = video_drvdata(filp); | |
939 | int ret; | |
940 | ||
941 | if (mutex_lock_interruptible(&pd->mux) == -EINTR) | |
942 | return -ERESTARTSYS; | |
943 | if (!pd->acq_fp) | |
944 | pd->acq_fp = filp; | |
945 | else if (pd->acq_fp != filp) { | |
946 | ret = -EBUSY; | |
947 | goto done; | |
948 | } | |
949 | ret = videobuf_read_stream(pd->vidq, user, size, loff, 0, | |
950 | filp->f_flags & O_NONBLOCK); | |
951 | done: | |
952 | mutex_unlock(&pd->mux); | |
953 | return ret; | |
954 | } | |
955 | ||
956 | static unsigned int | |
957 | dt3155_poll(struct file *filp, struct poll_table_struct *polltbl) | |
958 | { | |
959 | struct dt3155_priv *pd = video_drvdata(filp); | |
960 | ||
961 | return videobuf_poll_stream(filp, pd->vidq, polltbl); | |
962 | } | |
963 | ||
964 | static int | |
965 | dt3155_mmap(struct file *filp, struct vm_area_struct *vma) | |
966 | { | |
967 | struct dt3155_priv *pd = video_drvdata(filp); | |
968 | ||
969 | return videobuf_mmap_mapper(pd->vidq, vma); | |
970 | } | |
971 | ||
972 | static const struct v4l2_file_operations dt3155_fops = { | |
973 | .owner = THIS_MODULE, | |
974 | .open = dt3155_open, | |
975 | .release = dt3155_release, | |
976 | .read = dt3155_read, | |
977 | .poll = dt3155_poll, | |
978 | .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */ | |
979 | .mmap = dt3155_mmap, | |
980 | }; | |
981 | ||
982 | static int | |
983 | dt3155_ioc_streamon(struct file *filp, void *p, enum v4l2_buf_type type) | |
984 | { | |
985 | struct dt3155_priv *pd = video_drvdata(filp); | |
986 | int ret = -ERESTARTSYS; | |
987 | ||
988 | if (mutex_lock_interruptible(&pd->mux) == -EINTR) | |
989 | return ret; | |
990 | if (!pd->acq_fp) { | |
991 | ret = videobuf_streamon(pd->vidq); | |
992 | if (ret) | |
993 | goto unlock; | |
994 | pd->acq_fp = filp; | |
995 | wake_up_interruptible_sync(&pd->do_dma); | |
996 | } else if (pd->acq_fp == filp) { | |
997 | ret = videobuf_streamon(pd->vidq); | |
998 | if (!ret) | |
999 | wake_up_interruptible_sync(&pd->do_dma); | |
1000 | } else | |
1001 | ret = -EBUSY; | |
1002 | unlock: | |
1003 | mutex_unlock(&pd->mux); | |
1004 | return ret; | |
1005 | } | |
1006 | ||
1007 | static int | |
1008 | dt3155_ioc_streamoff(struct file *filp, void *p, enum v4l2_buf_type type) | |
1009 | { | |
1010 | struct dt3155_priv *pd = video_drvdata(filp); | |
1011 | struct videobuf_buffer *tmp; | |
1012 | unsigned long flags; | |
1013 | int ret; | |
1014 | ||
1015 | ret = videobuf_streamoff(pd->vidq); | |
1016 | if (ret) | |
1017 | return ret; | |
1018 | spin_lock_irqsave(&pd->lock, flags); | |
1019 | tmp = pd->curr_buf; | |
1020 | spin_unlock_irqrestore(&pd->lock, flags); | |
1021 | if (tmp) | |
1022 | videobuf_waiton(tmp, 0, 1); /* block, interruptible */ | |
1023 | return ret; | |
1024 | } | |
1025 | ||
1026 | static int | |
1027 | dt3155_ioc_querycap(struct file *filp, void *p, struct v4l2_capability *cap) | |
1028 | { | |
1029 | struct dt3155_priv *pd = video_drvdata(filp); | |
1030 | ||
1031 | strcpy(cap->driver, DT3155_NAME); | |
1032 | strcpy(cap->card, DT3155_NAME " frame grabber"); | |
1033 | sprintf(cap->bus_info, "PCI:%s", pci_name(pd->pdev)); | |
1034 | cap->version = | |
1035 | KERNEL_VERSION(DT3155_VER_MAJ, DT3155_VER_MIN, DT3155_VER_EXT); | |
1036 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | | |
1037 | #ifdef CONFIG_DT3155_STREAMING | |
1038 | V4L2_CAP_STREAMING; | |
1039 | #else | |
1040 | V4L2_CAP_READWRITE; | |
1041 | #endif | |
1042 | return 0; | |
1043 | } | |
1044 | ||
1045 | static int | |
1046 | dt3155_ioc_enum_fmt_vid_cap(struct file *filp, void *p, struct v4l2_fmtdesc *f) | |
1047 | { | |
1048 | if (f->index >= NUM_OF_FORMATS) | |
1049 | return -EINVAL; | |
1050 | *f = frame_std[f->index]; | |
1051 | return 0; | |
1052 | } | |
1053 | ||
1054 | static int | |
1055 | dt3155_ioc_g_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f) | |
1056 | { | |
1057 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1058 | return -EINVAL; | |
1059 | f->fmt.pix.width = img_width; | |
1060 | f->fmt.pix.height = img_height; | |
1061 | f->fmt.pix.pixelformat = V4L2_PIX_FMT_GREY; | |
1062 | f->fmt.pix.field = V4L2_FIELD_NONE; | |
1063 | f->fmt.pix.bytesperline = f->fmt.pix.width; | |
1064 | f->fmt.pix.sizeimage = f->fmt.pix.width * f->fmt.pix.height; | |
1065 | f->fmt.pix.colorspace = 0; | |
1066 | f->fmt.pix.priv = 0; | |
1067 | return 0; | |
1068 | } | |
1069 | ||
1070 | static int | |
1071 | dt3155_ioc_try_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f) | |
1072 | { | |
1073 | if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1074 | return -EINVAL; | |
1075 | if (f->fmt.pix.width == img_width && | |
1076 | f->fmt.pix.height == img_height && | |
1077 | f->fmt.pix.pixelformat == V4L2_PIX_FMT_GREY && | |
1078 | f->fmt.pix.field == V4L2_FIELD_NONE && | |
1079 | f->fmt.pix.bytesperline == f->fmt.pix.width && | |
1080 | f->fmt.pix.sizeimage == f->fmt.pix.width * f->fmt.pix.height) | |
1081 | return 0; | |
1082 | else | |
1083 | return -EINVAL; | |
1084 | } | |
1085 | ||
1086 | static int | |
1087 | dt3155_ioc_s_fmt_vid_cap(struct file *filp, void *p, struct v4l2_format *f) | |
1088 | { | |
1089 | return dt3155_ioc_g_fmt_vid_cap(filp, p, f); | |
1090 | } | |
1091 | ||
1092 | static int | |
1093 | dt3155_ioc_reqbufs(struct file *filp, void *p, struct v4l2_requestbuffers *b) | |
1094 | { | |
1095 | struct dt3155_priv *pd = video_drvdata(filp); | |
1096 | struct videobuf_queue *q = pd->vidq; | |
1097 | ||
1098 | if (b->memory != V4L2_MEMORY_MMAP) | |
1099 | return -EINVAL; | |
1100 | if (b->count) | |
1101 | return videobuf_reqbufs(q, b); | |
1102 | else { /* FIXME: is it necessary? */ | |
1103 | printk(KERN_DEBUG "dt3155: request to free buffers\n"); | |
1104 | return videobuf_mmap_free(q); | |
1105 | } | |
1106 | } | |
1107 | ||
1108 | static int | |
1109 | dt3155_ioc_querybuf(struct file *filp, void *p, struct v4l2_buffer *b) | |
1110 | { | |
1111 | struct dt3155_priv *pd = video_drvdata(filp); | |
1112 | struct videobuf_queue *q = pd->vidq; | |
1113 | ||
1114 | return videobuf_querybuf(q, b); | |
1115 | } | |
1116 | ||
1117 | static int | |
1118 | dt3155_ioc_qbuf(struct file *filp, void *p, struct v4l2_buffer *b) | |
1119 | { | |
1120 | struct dt3155_priv *pd = video_drvdata(filp); | |
1121 | struct videobuf_queue *q = pd->vidq; | |
1122 | ||
1123 | return videobuf_qbuf(q, b); | |
1124 | } | |
1125 | ||
1126 | static int | |
1127 | dt3155_ioc_dqbuf(struct file *filp, void *p, struct v4l2_buffer *b) | |
1128 | { | |
1129 | struct dt3155_priv *pd = video_drvdata(filp); | |
1130 | struct videobuf_queue *q = pd->vidq; | |
1131 | ||
1132 | return videobuf_dqbuf(q, b, filp->f_flags & O_NONBLOCK); | |
1133 | } | |
1134 | ||
1135 | static int | |
1136 | dt3155_ioc_querystd(struct file *filp, void *p, v4l2_std_id *norm) | |
1137 | { | |
1138 | *norm = DT3155_CURRENT_NORM; | |
1139 | return 0; | |
1140 | } | |
1141 | ||
1142 | static int | |
1143 | dt3155_ioc_g_std(struct file *filp, void *p, v4l2_std_id *norm) | |
1144 | { | |
1145 | *norm = DT3155_CURRENT_NORM; | |
1146 | return 0; | |
1147 | } | |
1148 | ||
1149 | static int | |
1150 | dt3155_ioc_s_std(struct file *filp, void *p, v4l2_std_id *norm) | |
1151 | { | |
1152 | if (*norm & DT3155_CURRENT_NORM) | |
1153 | return 0; | |
1154 | return -EINVAL; | |
1155 | } | |
1156 | ||
1157 | static int | |
1158 | dt3155_ioc_enum_input(struct file *filp, void *p, struct v4l2_input *input) | |
1159 | { | |
1160 | if (input->index) | |
1161 | return -EINVAL; | |
1162 | strcpy(input->name, "Coax in"); | |
1163 | input->type = V4L2_INPUT_TYPE_CAMERA; | |
1164 | input->std = V4L2_STD_ALL; | |
1165 | input->status = 0;/* FIXME: add sync detection & V4L2_IN_ST_NO_H_LOCK */ | |
1166 | return 0; | |
1167 | } | |
1168 | ||
1169 | static int | |
1170 | dt3155_ioc_g_input(struct file *filp, void *p, unsigned int *i) | |
1171 | { | |
1172 | *i = 0; | |
1173 | return 0; | |
1174 | } | |
1175 | ||
1176 | static int | |
1177 | dt3155_ioc_s_input(struct file *filp, void *p, unsigned int i) | |
1178 | { | |
1179 | if (i) | |
1180 | return -EINVAL; | |
1181 | return 0; | |
1182 | } | |
1183 | ||
1184 | static int | |
1185 | dt3155_ioc_g_parm(struct file *filp, void *p, struct v4l2_streamparm *parms) | |
1186 | { | |
1187 | if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1188 | return -EINVAL; | |
1189 | parms->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; | |
1190 | parms->parm.capture.capturemode = 0; | |
1191 | parms->parm.capture.timeperframe.numerator = 1001; | |
1192 | parms->parm.capture.timeperframe.denominator = frames_per_sec * 1000; | |
1193 | parms->parm.capture.extendedmode = 0; | |
1194 | parms->parm.capture.readbuffers = 1; | |
1195 | return 0; | |
1196 | } | |
1197 | ||
1198 | static int | |
1199 | dt3155_ioc_s_parm(struct file *filp, void *p, struct v4l2_streamparm *parms) | |
1200 | { | |
1201 | if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | |
1202 | return -EINVAL; | |
1203 | parms->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; | |
1204 | parms->parm.capture.capturemode = 0; | |
1205 | parms->parm.capture.timeperframe.numerator = 1001; | |
1206 | parms->parm.capture.timeperframe.denominator = frames_per_sec * 1000; | |
1207 | parms->parm.capture.extendedmode = 0; | |
1208 | parms->parm.capture.readbuffers = 1; | |
1209 | return 0; | |
1210 | } | |
1211 | ||
1212 | static const struct v4l2_ioctl_ops dt3155_ioctl_ops = { | |
1213 | .vidioc_streamon = dt3155_ioc_streamon, | |
1214 | .vidioc_streamoff = dt3155_ioc_streamoff, | |
1215 | .vidioc_querycap = dt3155_ioc_querycap, | |
1216 | /* | |
1217 | .vidioc_g_priority = dt3155_ioc_g_priority, | |
1218 | .vidioc_s_priority = dt3155_ioc_s_priority, | |
1219 | */ | |
1220 | .vidioc_enum_fmt_vid_cap = dt3155_ioc_enum_fmt_vid_cap, | |
1221 | .vidioc_try_fmt_vid_cap = dt3155_ioc_try_fmt_vid_cap, | |
1222 | .vidioc_g_fmt_vid_cap = dt3155_ioc_g_fmt_vid_cap, | |
1223 | .vidioc_s_fmt_vid_cap = dt3155_ioc_s_fmt_vid_cap, | |
1224 | .vidioc_reqbufs = dt3155_ioc_reqbufs, | |
1225 | .vidioc_querybuf = dt3155_ioc_querybuf, | |
1226 | .vidioc_qbuf = dt3155_ioc_qbuf, | |
1227 | .vidioc_dqbuf = dt3155_ioc_dqbuf, | |
1228 | .vidioc_querystd = dt3155_ioc_querystd, | |
1229 | .vidioc_g_std = dt3155_ioc_g_std, | |
1230 | .vidioc_s_std = dt3155_ioc_s_std, | |
1231 | .vidioc_enum_input = dt3155_ioc_enum_input, | |
1232 | .vidioc_g_input = dt3155_ioc_g_input, | |
1233 | .vidioc_s_input = dt3155_ioc_s_input, | |
1234 | /* | |
1235 | .vidioc_queryctrl = dt3155_ioc_queryctrl, | |
1236 | .vidioc_g_ctrl = dt3155_ioc_g_ctrl, | |
1237 | .vidioc_s_ctrl = dt3155_ioc_s_ctrl, | |
1238 | .vidioc_querymenu = dt3155_ioc_querymenu, | |
1239 | .vidioc_g_ext_ctrls = dt3155_ioc_g_ext_ctrls, | |
1240 | .vidioc_s_ext_ctrls = dt3155_ioc_s_ext_ctrls, | |
1241 | */ | |
1242 | .vidioc_g_parm = dt3155_ioc_g_parm, | |
1243 | .vidioc_s_parm = dt3155_ioc_s_parm, | |
1244 | /* | |
1245 | .vidioc_cropcap = dt3155_ioc_cropcap, | |
1246 | .vidioc_g_crop = dt3155_ioc_g_crop, | |
1247 | .vidioc_s_crop = dt3155_ioc_s_crop, | |
1248 | .vidioc_enum_framesizes = dt3155_ioc_enum_framesizes, | |
1249 | .vidioc_enum_frameintervals = dt3155_ioc_enum_frameintervals, | |
1250 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | |
1251 | .vidiocgmbuf = iocgmbuf, | |
1252 | #endif | |
1253 | */ | |
1254 | }; | |
1255 | ||
1256 | static int __devinit | |
1257 | dt3155_init_board(struct pci_dev *dev) | |
1258 | { | |
1259 | int i; | |
1260 | u8 tmp; | |
1261 | struct dt3155_buf *buf; | |
1262 | struct dt3155_priv *pd = pci_get_drvdata(dev); | |
1263 | pci_set_master(dev); /* dt3155 needs it */ | |
1264 | ||
1265 | /* resetting the adapter */ | |
1266 | iowrite32(FLD_CRPT_ODD | FLD_CRPT_EVEN | FLD_DN_ODD | FLD_DN_EVEN, | |
1267 | pd->regs + CSR1); | |
1268 | mmiowb(); | |
1269 | msleep(10); | |
1270 | ||
1271 | /* initializing adaper registers */ | |
1272 | iowrite32(FIFO_EN | SRST, pd->regs + CSR1); | |
1273 | mmiowb(); | |
1274 | iowrite32(0xEEEEEE01, pd->regs + EVEN_PIXEL_FMT); | |
1275 | iowrite32(0xEEEEEE01, pd->regs + ODD_PIXEL_FMT); | |
1276 | iowrite32(0x00000020, pd->regs + FIFO_TRIGER); | |
1277 | iowrite32(0x00000103, pd->regs + XFER_MODE); | |
1278 | iowrite32(0, pd->regs + RETRY_WAIT_CNT); | |
1279 | iowrite32(0, pd->regs + INT_CSR); | |
1280 | iowrite32(1, pd->regs + EVEN_FLD_MASK); | |
1281 | iowrite32(1, pd->regs + ODD_FLD_MASK); | |
1282 | iowrite32(0, pd->regs + MASK_LENGTH); | |
1283 | iowrite32(0x0005007C, pd->regs + FIFO_FLAG_CNT); | |
1284 | iowrite32(0x01010101, pd->regs + IIC_CLK_DUR); | |
1285 | mmiowb(); | |
1286 | ||
1287 | /* verifying that we have a DT3155 board (not just a SAA7116 chip) */ | |
1288 | read_i2c_reg(pd->regs, DT_ID, &tmp); | |
1289 | if (tmp != DT3155_ID) | |
1290 | return -ENODEV; | |
1291 | ||
1292 | /* initialize AD LUT */ | |
1293 | write_i2c_reg(pd->regs, AD_ADDR, 0); | |
1294 | for (i = 0; i < 256; i++) | |
1295 | write_i2c_reg(pd->regs, AD_LUT, i); | |
1296 | ||
1297 | /* initialize ADC references */ | |
1298 | /* FIXME: pos_ref & neg_ref depend on VT_50HZ */ | |
1299 | write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG); | |
1300 | write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3); | |
1301 | write_i2c_reg(pd->regs, AD_ADDR, AD_POS_REF); | |
1302 | write_i2c_reg(pd->regs, AD_CMD, 34); | |
1303 | write_i2c_reg(pd->regs, AD_ADDR, AD_NEG_REF); | |
1304 | write_i2c_reg(pd->regs, AD_CMD, 0); | |
1305 | ||
1306 | /* initialize PM LUT */ | |
1307 | write_i2c_reg(pd->regs, CONFIG, pd->config | PM_LUT_PGM); | |
1308 | for (i = 0; i < 256; i++) { | |
1309 | write_i2c_reg(pd->regs, PM_LUT_ADDR, i); | |
1310 | write_i2c_reg(pd->regs, PM_LUT_DATA, i); | |
1311 | } | |
1312 | write_i2c_reg(pd->regs, CONFIG, pd->config | PM_LUT_PGM | PM_LUT_SEL); | |
1313 | for (i = 0; i < 256; i++) { | |
1314 | write_i2c_reg(pd->regs, PM_LUT_ADDR, i); | |
1315 | write_i2c_reg(pd->regs, PM_LUT_DATA, i); | |
1316 | } | |
1317 | write_i2c_reg(pd->regs, CONFIG, pd->config); /* ACQ_MODE_EVEN */ | |
1318 | ||
1319 | /* select chanel 1 for input and set sync level */ | |
1320 | write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG); | |
1321 | write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3); | |
1322 | ||
1323 | /* allocate and pci_map memory, and initialize the DMA machine */ | |
1324 | buf = dt3155_get_buf(dt3155_free_bufs); | |
1325 | if (!buf) { | |
1326 | printk(KERN_ERR "dt3155: dt3155_get_buf " | |
1327 | "(in dt3155_init_board) failed\n"); | |
1328 | return -ENOMEM; | |
1329 | } | |
1330 | buf->dma = pci_map_single(dev, buf->cpu, | |
1331 | DT3155_BUF_SIZE, PCI_DMA_FROMDEVICE); | |
1332 | if (pci_dma_mapping_error(dev, buf->dma)) { | |
1333 | printk(KERN_ERR "dt3155: pci_map_single failed\n"); | |
1334 | dt3155_put_buf(buf, dt3155_free_bufs); | |
1335 | return -ENOMEM; | |
1336 | } | |
1337 | iowrite32(buf->dma, pd->regs + EVEN_DMA_START); | |
1338 | iowrite32(buf->dma, pd->regs + ODD_DMA_START); | |
1339 | iowrite32(0, pd->regs + EVEN_DMA_STRIDE); | |
1340 | iowrite32(0, pd->regs + ODD_DMA_STRIDE); | |
1341 | ||
1342 | /* Perform a pseudo even field acquire */ | |
1343 | iowrite32(FIFO_EN | SRST | CAP_CONT_ODD, pd->regs + CSR1); | |
1344 | write_i2c_reg(pd->regs, CSR2, pd->csr2 | SYNC_SNTL); | |
1345 | write_i2c_reg(pd->regs, CONFIG, pd->config); | |
1346 | write_i2c_reg(pd->regs, EVEN_CSR, CSR_SNGL); | |
1347 | write_i2c_reg(pd->regs, CSR2, pd->csr2 | BUSY_EVEN | SYNC_SNTL); | |
1348 | msleep(100); | |
1349 | read_i2c_reg(pd->regs, CSR2, &tmp); | |
1350 | write_i2c_reg(pd->regs, EVEN_CSR, CSR_ERROR | CSR_SNGL | CSR_DONE); | |
1351 | write_i2c_reg(pd->regs, ODD_CSR, CSR_ERROR | CSR_SNGL | CSR_DONE); | |
1352 | write_i2c_reg(pd->regs, CSR2, pd->csr2); | |
1353 | iowrite32(FIFO_EN | SRST | FLD_DN_EVEN | FLD_DN_ODD, pd->regs + CSR1); | |
1354 | ||
1355 | /* pci_unmap and deallocate memory */ | |
1356 | pci_unmap_single(dev, buf->dma, DT3155_BUF_SIZE, PCI_DMA_FROMDEVICE); | |
1357 | dt3155_put_buf(buf, dt3155_free_bufs); | |
1358 | if (tmp & BUSY_EVEN) { | |
1359 | printk(KERN_ERR "dt3155: BUSY_EVEN not cleared\n"); | |
1360 | return -EIO; | |
1361 | } | |
1362 | return 0; | |
1363 | } | |
1364 | ||
1365 | static struct video_device dt3155_vdev = { | |
1366 | .name = DT3155_NAME, | |
1367 | .fops = &dt3155_fops, | |
1368 | .ioctl_ops = &dt3155_ioctl_ops, | |
1369 | .minor = -1, | |
1370 | .release = video_device_release, | |
1371 | .tvnorms = V4L2_STD_ALL, | |
1372 | .current_norm = DT3155_CURRENT_NORM, | |
1373 | }; | |
1374 | ||
1375 | static int __devinit | |
1376 | dt3155_probe(struct pci_dev *dev, const struct pci_device_id *id) | |
1377 | { | |
1378 | int err = -ENODEV; | |
1379 | struct dt3155_priv *pd; | |
1380 | ||
1381 | printk(KERN_INFO "dt3155: probe()\n"); | |
1382 | if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) { | |
1383 | printk(KERN_ERR "dt3155: cannot set dma_mask\n"); | |
1384 | return -ENODEV; | |
1385 | } | |
1386 | pd = kzalloc(sizeof(*pd), GFP_KERNEL); | |
1387 | if (!pd) { | |
1388 | printk(KERN_ERR "dt3155: cannot allocate dt3155_priv\n"); | |
1389 | return -ENOMEM; | |
1390 | } | |
1391 | pd->vdev = video_device_alloc(); | |
1392 | if (!pd->vdev) { | |
1393 | printk(KERN_ERR "dt3155: cannot allocate vdp structure\n"); | |
1394 | goto err_video_device_alloc; | |
1395 | } | |
1396 | *pd->vdev = dt3155_vdev; | |
1397 | pci_set_drvdata(dev, pd); /* for use in dt3155_remove() */ | |
1398 | video_set_drvdata(pd->vdev, pd); /* for use in video_fops */ | |
1399 | pd->users = 0; | |
1400 | pd->acq_fp = NULL; | |
1401 | pd->pdev = dev; | |
1402 | INIT_LIST_HEAD(&pd->dmaq); | |
1403 | init_waitqueue_head(&pd->do_dma); | |
1404 | mutex_init(&pd->mux); | |
1405 | pd->csr2 = csr2_init; | |
1406 | pd->config = config_init; | |
1407 | err = pci_enable_device(pd->pdev); | |
1408 | if (err) { | |
1409 | printk(KERN_ERR "dt3155: pci_dev not enabled\n"); | |
1410 | goto err_enable_dev; | |
1411 | } | |
1412 | err = pci_request_region(pd->pdev, 0, pci_name(pd->pdev)); | |
1413 | if (err) | |
1414 | goto err_req_region; | |
1415 | pd->regs = pci_iomap(pd->pdev, 0, pci_resource_len(pd->pdev, 0)); | |
1416 | if (!pd->regs) { | |
1417 | err = -ENOMEM; | |
1418 | printk(KERN_ERR "dt3155: pci_iomap failed\n"); | |
1419 | goto err_pci_iomap; | |
1420 | } | |
1421 | err = dt3155_init_board(pd->pdev); | |
1422 | if (err) { | |
1423 | printk(KERN_ERR "dt3155: dt3155_init_board failed\n"); | |
1424 | goto err_init_board; | |
1425 | } | |
1426 | err = video_register_device(pd->vdev, VFL_TYPE_GRABBER, -1); | |
1427 | if (err) { | |
1428 | printk(KERN_ERR "dt3155: Cannot register video device\n"); | |
1429 | goto err_init_board; | |
1430 | } | |
1431 | printk(KERN_INFO "dt3155: /dev/video%i is ready\n", pd->vdev->minor); | |
1432 | return 0; /* success */ | |
1433 | ||
1434 | err_init_board: | |
1435 | pci_iounmap(pd->pdev, pd->regs); | |
1436 | err_pci_iomap: | |
1437 | pci_release_region(pd->pdev, 0); | |
1438 | err_req_region: | |
1439 | pci_disable_device(pd->pdev); | |
1440 | err_enable_dev: | |
1441 | video_device_release(pd->vdev); | |
1442 | err_video_device_alloc: | |
1443 | kfree(pd); | |
1444 | return err; | |
1445 | } | |
1446 | ||
1447 | static void __devexit | |
1448 | dt3155_remove(struct pci_dev *dev) | |
1449 | { | |
1450 | struct dt3155_priv *pd = pci_get_drvdata(dev); | |
1451 | ||
1452 | printk(KERN_INFO "dt3155: remove()\n"); | |
1453 | video_unregister_device(pd->vdev); | |
1454 | pci_iounmap(dev, pd->regs); | |
1455 | pci_release_region(pd->pdev, 0); | |
1456 | pci_disable_device(pd->pdev); | |
1457 | /* | |
1458 | * video_device_release() is invoked automatically | |
1459 | * see: struct video_device dt3155_vdev | |
1460 | */ | |
1461 | kfree(pd); | |
1462 | } | |
1463 | ||
1464 | static DEFINE_PCI_DEVICE_TABLE(pci_ids) = { | |
1465 | { PCI_DEVICE(DT3155_VENDOR_ID, DT3155_DEVICE_ID) }, | |
1466 | { 0, /* zero marks the end */ }, | |
1467 | }; | |
1468 | MODULE_DEVICE_TABLE(pci, pci_ids); | |
1469 | ||
1470 | static struct pci_driver pci_driver = { | |
1471 | .name = DT3155_NAME, | |
1472 | .id_table = pci_ids, | |
1473 | .probe = dt3155_probe, | |
1474 | .remove = __devexit_p(dt3155_remove), | |
1475 | }; | |
1476 | ||
1477 | static int __init | |
1478 | dt3155_init_module(void) | |
1479 | { | |
1480 | int err; | |
1481 | ||
1482 | printk(KERN_INFO "dt3155: ==================\n"); | |
1483 | printk(KERN_INFO "dt3155: init()\n"); | |
1484 | dt3155_chunks = dt3155_init_chunks_fifo(); | |
1485 | if (!dt3155_chunks) { | |
1486 | err = -ENOMEM; | |
1487 | printk(KERN_ERR "dt3155: cannot init dt3155_chunks_fifo\n"); | |
1488 | goto err_init_chunks_fifo; | |
1489 | } | |
1490 | dt3155_free_bufs = dt3155_init_ibufs_fifo(dt3155_chunks, | |
1491 | DT3155_BUF_SIZE); | |
1492 | if (!dt3155_free_bufs) { | |
1493 | err = -ENOMEM; | |
1494 | printk(KERN_ERR "dt3155: cannot dt3155_init_ibufs_fifo\n"); | |
1495 | goto err_init_ibufs_fifo; | |
1496 | } | |
1497 | dt3155_alloc_bufs = dt3155_init_fifo(); | |
1498 | if (!dt3155_alloc_bufs) { | |
1499 | err = -ENOMEM; | |
1500 | printk(KERN_ERR "dt3155: cannot dt3155_init_fifo\n"); | |
1501 | goto err_init_fifo; | |
1502 | } | |
1503 | err = pci_register_driver(&pci_driver); | |
1504 | if (err) { | |
1505 | printk(KERN_ERR "dt3155: cannot register pci_driver\n"); | |
1506 | goto err_register_driver; | |
1507 | } | |
1508 | return 0; /* succes */ | |
1509 | err_register_driver: | |
1510 | dt3155_free_fifo(dt3155_alloc_bufs); | |
1511 | err_init_fifo: | |
1512 | dt3155_free_ibufs_fifo(dt3155_free_bufs); | |
1513 | err_init_ibufs_fifo: | |
1514 | dt3155_free_chunks_fifo(dt3155_chunks); | |
1515 | err_init_chunks_fifo: | |
1516 | return err; | |
1517 | } | |
1518 | ||
1519 | static void __exit | |
1520 | dt3155_exit_module(void) | |
1521 | { | |
1522 | pci_unregister_driver(&pci_driver); | |
1523 | dt3155_free_fifo(dt3155_alloc_bufs); | |
1524 | dt3155_free_ibufs_fifo(dt3155_free_bufs); | |
1525 | dt3155_free_chunks_fifo(dt3155_chunks); | |
1526 | printk(KERN_INFO "dt3155: exit()\n"); | |
1527 | printk(KERN_INFO "dt3155: ==================\n"); | |
1528 | } | |
1529 | ||
1530 | module_init(dt3155_init_module); | |
1531 | module_exit(dt3155_exit_module); | |
1532 | ||
1533 | MODULE_DESCRIPTION("video4linux pci-driver for dt3155 frame grabber"); | |
1534 | MODULE_AUTHOR("Marin Mitov <mitov@issp.bas.bg>"); | |
1535 | MODULE_VERSION(DT3155_VERSION); | |
1536 | MODULE_LICENSE("GPL"); |