2 * Zoran zr36057/zr36067 PCI controller driver, for the
3 * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
4 * Media Labs LML33/LML33R10.
6 * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
8 * Changes for BUZ by Wolfgang Scherr <scherr@net4you.net>
10 * Changes for DC10/DC30 by Laurent Pinchart <laurent.pinchart@skynet.be>
12 * Changes for LML33R10 by Maxim Yevtyushkin <max@linuxmedialabs.com>
14 * Changes for videodev2/v4l2 by Ronald Bultje <rbultje@ronald.bitfreak.net>
19 * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net>
21 * Iomega Buz driver version 1.0
22 * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
25 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
27 * bttv - Bt848 frame grabber driver
28 * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
29 * & Marcus Metzler (mocm@thp.uni-koeln.de)
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
47 #include <linux/version.h>
48 #include <linux/init.h>
49 #include <linux/module.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <linux/pci.h>
53 #include <linux/vmalloc.h>
54 #include <linux/wait.h>
55 #include <linux/byteorder/generic.h>
57 #include <linux/interrupt.h>
58 #include <linux/i2c.h>
59 #include <linux/i2c-algo-bit.h>
61 #include <linux/spinlock.h>
62 #define MAP_NR(x) virt_to_page(x)
63 #define ZORAN_VID_TYPE ( \
69 VID_TYPE_MJPEG_DECODER | \
70 VID_TYPE_MJPEG_ENCODER \
73 #include <linux/videodev.h>
74 #include <media/v4l2-common.h>
75 #include "videocodec.h"
78 #include <asm/uaccess.h>
79 #include <linux/proc_fs.h>
81 #include <linux/video_decoder.h>
82 #include <linux/video_encoder.h>
83 #include <linux/mutex.h>
85 #include "zoran_device.h"
86 #include "zoran_card.h"
88 #ifdef CONFIG_VIDEO_V4L2
89 /* we declare some card type definitions here, they mean
90 * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */
91 #define ZORAN_V4L2_VID_FLAGS ( \
93 V4L2_CAP_VIDEO_CAPTURE |\
94 V4L2_CAP_VIDEO_OUTPUT |\
95 V4L2_CAP_VIDEO_OVERLAY \
99 #include <asm/byteorder.h>
101 #if defined(CONFIG_VIDEO_V4L2) && defined(CONFIG_VIDEO_V4L1_COMPAT)
102 #define ZFMT(pal, fcc, cs) \
103 .palette = (pal), .fourcc = (fcc), .colorspace = (cs)
104 #elif defined(CONFIG_VIDEO_V4L2)
105 #define ZFMT(pal, fcc, cs) \
106 .fourcc = (fcc), .colorspace = (cs)
108 #define ZFMT(pal, fcc, cs) \
112 const struct zoran_format zoran_formats
[] = {
114 .name
= "15-bit RGB LE",
115 ZFMT(VIDEO_PALETTE_RGB555
,
116 V4L2_PIX_FMT_RGB555
, V4L2_COLORSPACE_SRGB
),
118 .flags
= ZORAN_FORMAT_CAPTURE
|
119 ZORAN_FORMAT_OVERLAY
,
120 .vfespfr
= ZR36057_VFESPFR_RGB555
|ZR36057_VFESPFR_ErrDif
|
121 ZR36057_VFESPFR_LittleEndian
,
123 .name
= "15-bit RGB BE",
125 V4L2_PIX_FMT_RGB555X
, V4L2_COLORSPACE_SRGB
),
127 .flags
= ZORAN_FORMAT_CAPTURE
|
128 ZORAN_FORMAT_OVERLAY
,
129 .vfespfr
= ZR36057_VFESPFR_RGB555
|ZR36057_VFESPFR_ErrDif
,
131 .name
= "16-bit RGB LE",
132 ZFMT(VIDEO_PALETTE_RGB565
,
133 V4L2_PIX_FMT_RGB565
, V4L2_COLORSPACE_SRGB
),
135 .flags
= ZORAN_FORMAT_CAPTURE
|
136 ZORAN_FORMAT_OVERLAY
,
137 .vfespfr
= ZR36057_VFESPFR_RGB565
|ZR36057_VFESPFR_ErrDif
|
138 ZR36057_VFESPFR_LittleEndian
,
140 .name
= "16-bit RGB BE",
142 V4L2_PIX_FMT_RGB565
, V4L2_COLORSPACE_SRGB
),
144 .flags
= ZORAN_FORMAT_CAPTURE
|
145 ZORAN_FORMAT_OVERLAY
,
146 .vfespfr
= ZR36057_VFESPFR_RGB565
|ZR36057_VFESPFR_ErrDif
,
148 .name
= "24-bit RGB",
149 ZFMT(VIDEO_PALETTE_RGB24
,
150 V4L2_PIX_FMT_BGR24
, V4L2_COLORSPACE_SRGB
),
152 .flags
= ZORAN_FORMAT_CAPTURE
|
153 ZORAN_FORMAT_OVERLAY
,
154 .vfespfr
= ZR36057_VFESPFR_RGB888
|ZR36057_VFESPFR_Pack24
,
156 .name
= "32-bit RGB LE",
157 ZFMT(VIDEO_PALETTE_RGB32
,
158 V4L2_PIX_FMT_BGR32
, V4L2_COLORSPACE_SRGB
),
160 .flags
= ZORAN_FORMAT_CAPTURE
|
161 ZORAN_FORMAT_OVERLAY
,
162 .vfespfr
= ZR36057_VFESPFR_RGB888
|ZR36057_VFESPFR_LittleEndian
,
164 .name
= "32-bit RGB BE",
166 V4L2_PIX_FMT_RGB32
, V4L2_COLORSPACE_SRGB
),
168 .flags
= ZORAN_FORMAT_CAPTURE
|
169 ZORAN_FORMAT_OVERLAY
,
170 .vfespfr
= ZR36057_VFESPFR_RGB888
,
172 .name
= "4:2:2, packed, YUYV",
173 ZFMT(VIDEO_PALETTE_YUV422
,
174 V4L2_PIX_FMT_YUYV
, V4L2_COLORSPACE_SMPTE170M
),
176 .flags
= ZORAN_FORMAT_CAPTURE
|
177 ZORAN_FORMAT_OVERLAY
,
178 .vfespfr
= ZR36057_VFESPFR_YUV422
,
180 .name
= "4:2:2, packed, UYVY",
181 ZFMT(VIDEO_PALETTE_UYVY
,
182 V4L2_PIX_FMT_UYVY
, V4L2_COLORSPACE_SMPTE170M
),
184 .flags
= ZORAN_FORMAT_CAPTURE
|
185 ZORAN_FORMAT_OVERLAY
,
186 .vfespfr
= ZR36057_VFESPFR_YUV422
|ZR36057_VFESPFR_LittleEndian
,
188 .name
= "Hardware-encoded Motion-JPEG",
190 V4L2_PIX_FMT_MJPEG
, V4L2_COLORSPACE_SMPTE170M
),
192 .flags
= ZORAN_FORMAT_CAPTURE
|
193 ZORAN_FORMAT_PLAYBACK
|
194 ZORAN_FORMAT_COMPRESSED
,
197 #define NUM_FORMATS ARRAY_SIZE(zoran_formats)
199 // RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined
202 extern int v4l_nbufs
;
203 extern int v4l_bufsize
;
204 extern int jpg_nbufs
;
205 extern int jpg_bufsize
;
206 extern int pass_through
;
208 static int lock_norm
= 0; /* 1=Don't change TV standard (norm) */
209 module_param(lock_norm
, int, 0644);
210 MODULE_PARM_DESC(lock_norm
, "Prevent norm changes (1 = ignore, >1 = fail)");
212 #ifdef CONFIG_VIDEO_V4L2
213 /* small helper function for calculating buffersizes for v4l2
214 * we calculate the nearest higher power-of-two, which
215 * will be the recommended buffersize */
217 zoran_v4l2_calc_bufsize (struct zoran_jpg_settings
*settings
)
219 __u8 div
= settings
->VerDcm
* settings
->HorDcm
* settings
->TmpDcm
;
220 __u32 num
= (1024 * 512) / (div
);
229 if (result
> jpg_bufsize
)
237 /* forward references */
238 static void v4l_fbuffer_free(struct file
*file
);
239 static void jpg_fbuffer_free(struct file
*file
);
242 * Allocate the V4L grab buffers
244 * These have to be pysically contiguous.
245 * If v4l_bufsize <= MAX_KMALLOC_MEM we use kmalloc
246 * else we try to allocate them with bigphysarea_alloc_pages
247 * if the bigphysarea patch is present in the kernel,
248 * else we try to use high memory (if the user has bootet
249 * Linux with the necessary memory left over).
253 get_high_mem (unsigned long size
)
256 * Check if there is usable memory at the end of Linux memory
257 * of at least size. Return the physical address of this memory,
258 * return 0 on failure.
260 * The idea is from Alexandro Rubini's book "Linux device drivers".
261 * The driver from him which is downloadable from O'Reilly's
262 * web site misses the "virt_to_phys(high_memory)" part
263 * (and therefore doesn't work at all - at least with 2.2.x kernels).
265 * It should be unnecessary to mention that THIS IS DANGEROUS,
266 * if more than one driver at a time has the idea to use this memory!!!!
269 volatile unsigned char __iomem
*mem
;
271 unsigned long hi_mem_ph
;
274 /* Map the high memory to user space */
276 hi_mem_ph
= virt_to_phys(high_memory
);
278 mem
= ioremap(hi_mem_ph
, size
);
281 KERN_ERR
"%s: get_high_mem() - ioremap failed\n",
286 for (i
= 0; i
< size
; i
++) {
287 /* Check if it is memory */
290 if (readb(mem
+ i
) != c
)
294 if (readb(mem
+ i
) != c
)
296 writeb(0, mem
+ i
); /* zero out memory */
298 /* give the kernel air to breath */
299 if ((i
& 0x3ffff) == 0x3ffff)
308 "%s: get_high_mem() - requested %lu, avail %lu\n",
309 ZORAN_NAME
, size
, i
);
317 v4l_fbuffer_alloc (struct file
*file
)
319 struct zoran_fh
*fh
= file
->private_data
;
320 struct zoran
*zr
= fh
->zr
;
323 unsigned long pmem
= 0;
325 /* we might have old buffers lying around... */
326 if (fh
->v4l_buffers
.ready_to_be_freed
) {
327 v4l_fbuffer_free(file
);
330 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++) {
331 if (fh
->v4l_buffers
.buffer
[i
].fbuffer
)
334 "%s: v4l_fbuffer_alloc() - buffer %d allready allocated!?\n",
338 if (fh
->v4l_buffers
.buffer_size
<= MAX_KMALLOC_MEM
) {
341 mem
= kmalloc(fh
->v4l_buffers
.buffer_size
, GFP_KERNEL
);
345 "%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n",
347 v4l_fbuffer_free(file
);
350 fh
->v4l_buffers
.buffer
[i
].fbuffer
= mem
;
351 fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
=
353 fh
->v4l_buffers
.buffer
[i
].fbuffer_bus
=
355 for (off
= 0; off
< fh
->v4l_buffers
.buffer_size
;
357 SetPageReserved(MAP_NR(mem
+ off
));
360 "%s: v4l_fbuffer_alloc() - V4L frame %d mem 0x%lx (bus: 0x%lx)\n",
361 ZR_DEVNAME(zr
), i
, (unsigned long) mem
,
365 /* Use high memory which has been left at boot time */
367 /* Ok., Ok. this is an evil hack - we make
368 * the assumption that physical addresses are
369 * the same as bus addresses (true at least
370 * for Intel processors). The whole method of
371 * obtaining and using this memory is not very
372 * nice - but I hope it saves some poor users
373 * from kernel hacking, which might have even
374 * more evil results */
378 fh
->v4l_buffers
.num_buffers
*
379 fh
->v4l_buffers
.buffer_size
;
381 pmem
= get_high_mem(size
);
385 "%s: v4l_fbuffer_alloc() - get_high_mem (size = %d KB) for V4L bufs failed\n",
386 ZR_DEVNAME(zr
), size
>> 10);
389 fh
->v4l_buffers
.buffer
[0].fbuffer
= NULL
;
390 fh
->v4l_buffers
.buffer
[0].fbuffer_phys
= pmem
;
391 fh
->v4l_buffers
.buffer
[0].fbuffer_bus
= pmem
;
394 "%s: v4l_fbuffer_alloc() - using %d KB high memory\n",
395 ZR_DEVNAME(zr
), size
>> 10);
397 fh
->v4l_buffers
.buffer
[i
].fbuffer
= NULL
;
398 fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
=
399 pmem
+ i
* fh
->v4l_buffers
.buffer_size
;
400 fh
->v4l_buffers
.buffer
[i
].fbuffer_bus
=
401 pmem
+ i
* fh
->v4l_buffers
.buffer_size
;
406 fh
->v4l_buffers
.allocated
= 1;
411 /* free the V4L grab buffers */
413 v4l_fbuffer_free (struct file
*file
)
415 struct zoran_fh
*fh
= file
->private_data
;
416 struct zoran
*zr
= fh
->zr
;
420 dprintk(4, KERN_INFO
"%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr
));
422 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++) {
423 if (!fh
->v4l_buffers
.buffer
[i
].fbuffer
)
426 if (fh
->v4l_buffers
.buffer_size
<= MAX_KMALLOC_MEM
) {
427 mem
= fh
->v4l_buffers
.buffer
[i
].fbuffer
;
428 for (off
= 0; off
< fh
->v4l_buffers
.buffer_size
;
430 ClearPageReserved(MAP_NR(mem
+ off
));
431 kfree((void *) fh
->v4l_buffers
.buffer
[i
].fbuffer
);
433 fh
->v4l_buffers
.buffer
[i
].fbuffer
= NULL
;
436 fh
->v4l_buffers
.allocated
= 0;
437 fh
->v4l_buffers
.ready_to_be_freed
= 0;
441 * Allocate the MJPEG grab buffers.
443 * If the requested buffer size is smaller than MAX_KMALLOC_MEM,
444 * kmalloc is used to request a physically contiguous area,
445 * else we allocate the memory in framgents with get_zeroed_page.
447 * If a Natoma chipset is present and this is a revision 1 zr36057,
448 * each MJPEG buffer needs to be physically contiguous.
449 * (RJ: This statement is from Dave Perks' original driver,
450 * I could never check it because I have a zr36067)
451 * The driver cares about this because it reduces the buffer
452 * size to MAX_KMALLOC_MEM in that case (which forces contiguous allocation).
454 * RJ: The contents grab buffers needs never be accessed in the driver.
455 * Therefore there is no need to allocate them with vmalloc in order
456 * to get a contiguous virtual memory space.
457 * I don't understand why many other drivers first allocate them with
458 * vmalloc (which uses internally also get_zeroed_page, but delivers you
459 * virtual addresses) and then again have to make a lot of efforts
460 * to get the physical address.
463 * On big-endian architectures (such as ppc) some extra steps
464 * are needed. When reading and writing to the stat_com array
465 * and fragment buffers, the device expects to see little-
466 * endian values. The use of cpu_to_le32() and le32_to_cpu()
467 * in this function (and one or two others in zoran_device.c)
468 * ensure that these values are always stored in little-endian
469 * form, regardless of architecture. The zr36057 does Very Bad
470 * Things on big endian architectures if the stat_com array
471 * and fragment buffers are not little-endian.
475 jpg_fbuffer_alloc (struct file
*file
)
477 struct zoran_fh
*fh
= file
->private_data
;
478 struct zoran
*zr
= fh
->zr
;
482 /* we might have old buffers lying around */
483 if (fh
->jpg_buffers
.ready_to_be_freed
) {
484 jpg_fbuffer_free(file
);
487 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
488 if (fh
->jpg_buffers
.buffer
[i
].frag_tab
)
491 "%s: jpg_fbuffer_alloc() - buffer %d allready allocated!?\n",
494 /* Allocate fragment table for this buffer */
496 mem
= get_zeroed_page(GFP_KERNEL
);
500 "%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n",
502 jpg_fbuffer_free(file
);
505 fh
->jpg_buffers
.buffer
[i
].frag_tab
= (u32
*) mem
;
506 fh
->jpg_buffers
.buffer
[i
].frag_tab_bus
=
507 virt_to_bus((void *) mem
);
509 //if (alloc_contig) {
510 if (fh
->jpg_buffers
.need_contiguous
) {
512 (unsigned long) kmalloc(fh
->jpg_buffers
.
518 "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n",
520 jpg_fbuffer_free(file
);
523 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0] =
524 cpu_to_le32(virt_to_bus((void *) mem
));
525 fh
->jpg_buffers
.buffer
[i
].frag_tab
[1] =
526 cpu_to_le32(((fh
->jpg_buffers
.buffer_size
/ 4) << 1) | 1);
527 for (off
= 0; off
< fh
->jpg_buffers
.buffer_size
;
529 SetPageReserved(MAP_NR(mem
+ off
));
531 /* jpg_bufsize is allreay page aligned */
533 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
535 mem
= get_zeroed_page(GFP_KERNEL
);
539 "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n",
541 jpg_fbuffer_free(file
);
545 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
] =
546 cpu_to_le32(virt_to_bus((void *) mem
));
547 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
+
549 cpu_to_le32((PAGE_SIZE
/ 4) << 1);
550 SetPageReserved(MAP_NR(mem
));
553 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
- 1] |= cpu_to_le32(1);
558 KERN_DEBUG
"%s: jpg_fbuffer_alloc() - %d KB allocated\n",
560 (fh
->jpg_buffers
.num_buffers
*
561 fh
->jpg_buffers
.buffer_size
) >> 10);
563 fh
->jpg_buffers
.allocated
= 1;
568 /* free the MJPEG grab buffers */
570 jpg_fbuffer_free (struct file
*file
)
572 struct zoran_fh
*fh
= file
->private_data
;
573 struct zoran
*zr
= fh
->zr
;
577 dprintk(4, KERN_DEBUG
"%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr
));
579 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
580 if (!fh
->jpg_buffers
.buffer
[i
].frag_tab
)
583 //if (alloc_contig) {
584 if (fh
->jpg_buffers
.need_contiguous
) {
585 if (fh
->jpg_buffers
.buffer
[i
].frag_tab
[0]) {
586 mem
= (unsigned char *) bus_to_virt(le32_to_cpu(
587 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0]));
589 off
< fh
->jpg_buffers
.buffer_size
;
591 ClearPageReserved(MAP_NR
594 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0] = 0;
595 fh
->jpg_buffers
.buffer
[i
].frag_tab
[1] = 0;
599 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
601 if (!fh
->jpg_buffers
.buffer
[i
].
604 ClearPageReserved(MAP_NR
608 buffer
[i
].frag_tab
[2 *
610 free_page((unsigned long)
616 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
] =
618 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
+
623 free_page((unsigned long) fh
->jpg_buffers
.buffer
[i
].
625 fh
->jpg_buffers
.buffer
[i
].frag_tab
= NULL
;
628 fh
->jpg_buffers
.allocated
= 0;
629 fh
->jpg_buffers
.ready_to_be_freed
= 0;
633 * V4L Buffer grabbing
637 zoran_v4l_set_format (struct file
*file
,
640 const struct zoran_format
*format
)
642 struct zoran_fh
*fh
= file
->private_data
;
643 struct zoran
*zr
= fh
->zr
;
646 /* Check size and format of the grab wanted */
648 if (height
< BUZ_MIN_HEIGHT
|| width
< BUZ_MIN_WIDTH
||
649 height
> BUZ_MAX_HEIGHT
|| width
> BUZ_MAX_WIDTH
) {
652 "%s: v4l_set_format() - wrong frame size (%dx%d)\n",
653 ZR_DEVNAME(zr
), width
, height
);
657 bpp
= (format
->depth
+ 7) / 8;
659 /* Check against available buffer size */
660 if (height
* width
* bpp
> fh
->v4l_buffers
.buffer_size
) {
663 "%s: v4l_set_format() - video buffer size (%d kB) is too small\n",
664 ZR_DEVNAME(zr
), fh
->v4l_buffers
.buffer_size
>> 10);
668 /* The video front end needs 4-byte alinged line sizes */
670 if ((bpp
== 2 && (width
& 1)) || (bpp
== 3 && (width
& 3))) {
673 "%s: v4l_set_format() - wrong frame alingment\n",
678 fh
->v4l_settings
.width
= width
;
679 fh
->v4l_settings
.height
= height
;
680 fh
->v4l_settings
.format
= format
;
681 fh
->v4l_settings
.bytesperline
= bpp
* fh
->v4l_settings
.width
;
687 zoran_v4l_queue_frame (struct file
*file
,
690 struct zoran_fh
*fh
= file
->private_data
;
691 struct zoran
*zr
= fh
->zr
;
695 if (!fh
->v4l_buffers
.allocated
) {
698 "%s: v4l_queue_frame() - buffers not yet allocated\n",
703 /* No grabbing outside the buffer range! */
704 if (num
>= fh
->v4l_buffers
.num_buffers
|| num
< 0) {
707 "%s: v4l_queue_frame() - buffer %d is out of range\n",
708 ZR_DEVNAME(zr
), num
);
712 spin_lock_irqsave(&zr
->spinlock
, flags
);
714 if (fh
->v4l_buffers
.active
== ZORAN_FREE
) {
715 if (zr
->v4l_buffers
.active
== ZORAN_FREE
) {
716 zr
->v4l_buffers
= fh
->v4l_buffers
;
717 fh
->v4l_buffers
.active
= ZORAN_ACTIVE
;
721 "%s: v4l_queue_frame() - another session is already capturing\n",
727 /* make sure a grab isn't going on currently with this buffer */
729 switch (zr
->v4l_buffers
.buffer
[num
].state
) {
732 if (zr
->v4l_buffers
.active
== ZORAN_FREE
) {
733 fh
->v4l_buffers
.active
= ZORAN_FREE
;
734 zr
->v4l_buffers
.allocated
= 0;
736 res
= -EBUSY
; /* what are you doing? */
741 "%s: v4l_queue_frame() - queueing buffer %d in state DONE!?\n",
742 ZR_DEVNAME(zr
), num
);
744 /* since there is at least one unused buffer there's room for at least
745 * one more pend[] entry */
746 zr
->v4l_pend
[zr
->v4l_pend_head
++ &
747 V4L_MASK_FRAME
] = num
;
748 zr
->v4l_buffers
.buffer
[num
].state
= BUZ_STATE_PEND
;
749 zr
->v4l_buffers
.buffer
[num
].bs
.length
=
750 fh
->v4l_settings
.bytesperline
*
751 zr
->v4l_settings
.height
;
752 fh
->v4l_buffers
.buffer
[num
] =
753 zr
->v4l_buffers
.buffer
[num
];
758 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
760 if (!res
&& zr
->v4l_buffers
.active
== ZORAN_FREE
)
761 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
;
767 v4l_grab (struct file
*file
,
768 struct video_mmap
*mp
)
770 struct zoran_fh
*fh
= file
->private_data
;
771 struct zoran
*zr
= fh
->zr
;
774 for (i
= 0; i
< NUM_FORMATS
; i
++) {
775 if (zoran_formats
[i
].palette
== mp
->format
&&
776 zoran_formats
[i
].flags
& ZORAN_FORMAT_CAPTURE
&&
777 !(zoran_formats
[i
].flags
& ZORAN_FORMAT_COMPRESSED
))
780 if (i
== NUM_FORMATS
|| zoran_formats
[i
].depth
== 0) {
783 "%s: v4l_grab() - wrong bytes-per-pixel format\n",
789 * To minimize the time spent in the IRQ routine, we avoid setting up
790 * the video front end there.
791 * If this grab has different parameters from a running streaming capture
792 * we stop the streaming capture and start it over again.
794 if (zr
->v4l_memgrab_active
&&
795 (zr
->v4l_settings
.width
!= mp
->width
||
796 zr
->v4l_settings
.height
!= mp
->height
||
797 zr
->v4l_settings
.format
->palette
!= mp
->format
)) {
798 res
= wait_grab_pending(zr
);
802 if ((res
= zoran_v4l_set_format(file
,
807 zr
->v4l_settings
= fh
->v4l_settings
;
809 /* queue the frame in the pending queue */
810 if ((res
= zoran_v4l_queue_frame(file
, mp
->frame
))) {
811 fh
->v4l_buffers
.active
= ZORAN_FREE
;
815 /* put the 36057 into frame grabbing mode */
816 if (!res
&& !zr
->v4l_memgrab_active
)
817 zr36057_set_memgrab(zr
, 1);
819 //dprintk(4, KERN_INFO "%s: Frame grab 3...\n", ZR_DEVNAME(zr));
825 * Sync on a V4L buffer
829 v4l_sync (struct file
*file
,
832 struct zoran_fh
*fh
= file
->private_data
;
833 struct zoran
*zr
= fh
->zr
;
836 if (fh
->v4l_buffers
.active
== ZORAN_FREE
) {
839 "%s: v4l_sync() - no grab active for this session\n",
844 /* check passed-in frame number */
845 if (frame
>= fh
->v4l_buffers
.num_buffers
|| frame
< 0) {
847 KERN_ERR
"%s: v4l_sync() - frame %d is invalid\n",
848 ZR_DEVNAME(zr
), frame
);
852 /* Check if is buffer was queued at all */
853 if (zr
->v4l_buffers
.buffer
[frame
].state
== BUZ_STATE_USER
) {
856 "%s: v4l_sync() - attempt to sync on a buffer which was not queued?\n",
861 /* wait on this buffer to get ready */
862 if (!wait_event_interruptible_timeout(zr
->v4l_capq
,
863 (zr
->v4l_buffers
.buffer
[frame
].state
!= BUZ_STATE_PEND
),
866 if (signal_pending(current
))
869 /* buffer should now be in BUZ_STATE_DONE */
870 if (zr
->v4l_buffers
.buffer
[frame
].state
!= BUZ_STATE_DONE
)
872 KERN_ERR
"%s: v4l_sync() - internal state error\n",
875 zr
->v4l_buffers
.buffer
[frame
].state
= BUZ_STATE_USER
;
876 fh
->v4l_buffers
.buffer
[frame
] = zr
->v4l_buffers
.buffer
[frame
];
878 spin_lock_irqsave(&zr
->spinlock
, flags
);
880 /* Check if streaming capture has finished */
881 if (zr
->v4l_pend_tail
== zr
->v4l_pend_head
) {
882 zr36057_set_memgrab(zr
, 0);
883 if (zr
->v4l_buffers
.active
== ZORAN_ACTIVE
) {
884 fh
->v4l_buffers
.active
= zr
->v4l_buffers
.active
=
886 zr
->v4l_buffers
.allocated
= 0;
890 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
896 * Queue a MJPEG buffer for capture/playback
900 zoran_jpg_queue_frame (struct file
*file
,
902 enum zoran_codec_mode mode
)
904 struct zoran_fh
*fh
= file
->private_data
;
905 struct zoran
*zr
= fh
->zr
;
909 /* Check if buffers are allocated */
910 if (!fh
->jpg_buffers
.allocated
) {
913 "%s: jpg_queue_frame() - buffers not yet allocated\n",
918 /* No grabbing outside the buffer range! */
919 if (num
>= fh
->jpg_buffers
.num_buffers
|| num
< 0) {
922 "%s: jpg_queue_frame() - buffer %d out of range\n",
923 ZR_DEVNAME(zr
), num
);
927 /* what is the codec mode right now? */
928 if (zr
->codec_mode
== BUZ_MODE_IDLE
) {
929 zr
->jpg_settings
= fh
->jpg_settings
;
930 } else if (zr
->codec_mode
!= mode
) {
931 /* wrong codec mode active - invalid */
934 "%s: jpg_queue_frame() - codec in wrong mode\n",
939 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
940 if (zr
->jpg_buffers
.active
== ZORAN_FREE
) {
941 zr
->jpg_buffers
= fh
->jpg_buffers
;
942 fh
->jpg_buffers
.active
= ZORAN_ACTIVE
;
946 "%s: jpg_queue_frame() - another session is already capturing\n",
952 if (!res
&& zr
->codec_mode
== BUZ_MODE_IDLE
) {
953 /* Ok load up the jpeg codec */
954 zr36057_enable_jpg(zr
, mode
);
957 spin_lock_irqsave(&zr
->spinlock
, flags
);
960 switch (zr
->jpg_buffers
.buffer
[num
].state
) {
964 "%s: jpg_queue_frame() - queing frame in BUZ_STATE_DONE state!?\n",
967 /* since there is at least one unused buffer there's room for at
968 *least one more pend[] entry */
969 zr
->jpg_pend
[zr
->jpg_que_head
++ & BUZ_MASK_FRAME
] =
971 zr
->jpg_buffers
.buffer
[num
].state
= BUZ_STATE_PEND
;
972 fh
->jpg_buffers
.buffer
[num
] =
973 zr
->jpg_buffers
.buffer
[num
];
974 zoran_feed_stat_com(zr
);
979 if (zr
->jpg_buffers
.active
== ZORAN_FREE
) {
980 fh
->jpg_buffers
.active
= ZORAN_FREE
;
981 zr
->jpg_buffers
.allocated
= 0;
983 res
= -EBUSY
; /* what are you doing? */
988 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
990 if (!res
&& zr
->jpg_buffers
.active
== ZORAN_FREE
) {
991 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
;
998 jpg_qbuf (struct file
*file
,
1000 enum zoran_codec_mode mode
)
1002 struct zoran_fh
*fh
= file
->private_data
;
1003 struct zoran
*zr
= fh
->zr
;
1006 /* Does the user want to stop streaming? */
1008 if (zr
->codec_mode
== mode
) {
1009 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
1012 "%s: jpg_qbuf(-1) - session not active\n",
1016 fh
->jpg_buffers
.active
= zr
->jpg_buffers
.active
=
1018 zr
->jpg_buffers
.allocated
= 0;
1019 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1024 "%s: jpg_qbuf() - stop streaming but not in streaming mode\n",
1030 if ((res
= zoran_jpg_queue_frame(file
, frame
, mode
)))
1033 /* Start the jpeg codec when the first frame is queued */
1034 if (!res
&& zr
->jpg_que_head
== 1)
1041 * Sync on a MJPEG buffer
1045 jpg_sync (struct file
*file
,
1046 struct zoran_sync
*bs
)
1048 struct zoran_fh
*fh
= file
->private_data
;
1049 struct zoran
*zr
= fh
->zr
;
1050 unsigned long flags
;
1053 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
1056 "%s: jpg_sync() - capture is not currently active\n",
1060 if (zr
->codec_mode
!= BUZ_MODE_MOTION_DECOMPRESS
&&
1061 zr
->codec_mode
!= BUZ_MODE_MOTION_COMPRESS
) {
1064 "%s: jpg_sync() - codec not in streaming mode\n",
1068 if (!wait_event_interruptible_timeout(zr
->jpg_capq
,
1069 (zr
->jpg_que_tail
!= zr
->jpg_dma_tail
||
1070 zr
->jpg_dma_tail
== zr
->jpg_dma_head
),
1074 btand(~ZR36057_JMC_Go_en
, ZR36057_JMC
);
1076 zr
->codec
->control(zr
->codec
, CODEC_G_STATUS
,
1080 "%s: jpg_sync() - timeout: codec isr=0x%02x\n",
1081 ZR_DEVNAME(zr
), isr
);
1086 if (signal_pending(current
))
1087 return -ERESTARTSYS
;
1089 spin_lock_irqsave(&zr
->spinlock
, flags
);
1091 if (zr
->jpg_dma_tail
!= zr
->jpg_dma_head
)
1092 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
++ & BUZ_MASK_FRAME
];
1094 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
& BUZ_MASK_FRAME
];
1096 /* buffer should now be in BUZ_STATE_DONE */
1097 if (zr
->jpg_buffers
.buffer
[frame
].state
!= BUZ_STATE_DONE
)
1099 KERN_ERR
"%s: jpg_sync() - internal state error\n",
1102 *bs
= zr
->jpg_buffers
.buffer
[frame
].bs
;
1104 zr
->jpg_buffers
.buffer
[frame
].state
= BUZ_STATE_USER
;
1105 fh
->jpg_buffers
.buffer
[frame
] = zr
->jpg_buffers
.buffer
[frame
];
1107 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1113 zoran_open_init_session (struct file
*file
)
1116 struct zoran_fh
*fh
= file
->private_data
;
1117 struct zoran
*zr
= fh
->zr
;
1119 /* Per default, map the V4L Buffers */
1120 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
1122 /* take over the card's current settings */
1123 fh
->overlay_settings
= zr
->overlay_settings
;
1124 fh
->overlay_settings
.is_set
= 0;
1125 fh
->overlay_settings
.format
= zr
->overlay_settings
.format
;
1126 fh
->overlay_active
= ZORAN_FREE
;
1129 fh
->v4l_settings
= zr
->v4l_settings
;
1132 memset(&fh
->v4l_buffers
, 0, sizeof(struct zoran_v4l_struct
));
1133 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
1134 fh
->v4l_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
1135 fh
->v4l_buffers
.buffer
[i
].bs
.frame
= i
;
1137 fh
->v4l_buffers
.allocated
= 0;
1138 fh
->v4l_buffers
.ready_to_be_freed
= 0;
1139 fh
->v4l_buffers
.active
= ZORAN_FREE
;
1140 fh
->v4l_buffers
.buffer_size
= v4l_bufsize
;
1141 fh
->v4l_buffers
.num_buffers
= v4l_nbufs
;
1144 fh
->jpg_settings
= zr
->jpg_settings
;
1147 memset(&fh
->jpg_buffers
, 0, sizeof(struct zoran_jpg_struct
));
1148 for (i
= 0; i
< BUZ_MAX_FRAME
; i
++) {
1149 fh
->jpg_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
1150 fh
->jpg_buffers
.buffer
[i
].bs
.frame
= i
;
1152 fh
->jpg_buffers
.need_contiguous
= zr
->jpg_buffers
.need_contiguous
;
1153 fh
->jpg_buffers
.allocated
= 0;
1154 fh
->jpg_buffers
.ready_to_be_freed
= 0;
1155 fh
->jpg_buffers
.active
= ZORAN_FREE
;
1156 fh
->jpg_buffers
.buffer_size
= jpg_bufsize
;
1157 fh
->jpg_buffers
.num_buffers
= jpg_nbufs
;
1161 zoran_close_end_session (struct file
*file
)
1163 struct zoran_fh
*fh
= file
->private_data
;
1164 struct zoran
*zr
= fh
->zr
;
1167 if (fh
->overlay_active
!= ZORAN_FREE
) {
1168 fh
->overlay_active
= zr
->overlay_active
= ZORAN_FREE
;
1169 zr
->v4l_overlay_active
= 0;
1170 if (!zr
->v4l_memgrab_active
)
1171 zr36057_overlay(zr
, 0);
1172 zr
->overlay_mask
= NULL
;
1176 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
) {
1179 spin_lock_irqsave(&zr
->spinlock
, flags
);
1180 zr36057_set_memgrab(zr
, 0);
1181 zr
->v4l_buffers
.allocated
= 0;
1182 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
1184 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1188 if (fh
->v4l_buffers
.allocated
||
1189 fh
->v4l_buffers
.ready_to_be_freed
) {
1190 v4l_fbuffer_free(file
);
1194 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
1195 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1196 zr
->jpg_buffers
.allocated
= 0;
1197 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
=
1202 if (fh
->jpg_buffers
.allocated
||
1203 fh
->jpg_buffers
.ready_to_be_freed
) {
1204 jpg_fbuffer_free(file
);
1209 * Open a zoran card. Right now the flags stuff is just playing
1213 zoran_open (struct inode
*inode
,
1216 unsigned int minor
= iminor(inode
);
1217 struct zoran
*zr
= NULL
;
1218 struct zoran_fh
*fh
;
1219 int i
, res
, first_open
= 0, have_module_locks
= 0;
1221 /* find the device */
1222 for (i
= 0; i
< zoran_num
; i
++) {
1223 if (zoran
[i
].video_dev
->minor
== minor
) {
1230 dprintk(1, KERN_ERR
"%s: device not found!\n", ZORAN_NAME
);
1232 goto open_unlock_and_return
;
1235 /* see fs/device.c - the kernel already locks during open(),
1236 * so locking ourselves only causes deadlocks */
1237 /*mutex_lock(&zr->resource_lock);*/
1241 KERN_ERR
"%s: no TV decoder loaded for device!\n",
1244 goto open_unlock_and_return
;
1247 /* try to grab a module lock */
1248 if (!try_module_get(THIS_MODULE
)) {
1251 "%s: failed to acquire my own lock! PANIC!\n",
1254 goto open_unlock_and_return
;
1256 if (!try_module_get(zr
->decoder
->driver
->driver
.owner
)) {
1259 "%s: failed to grab ownership of i2c decoder\n",
1262 module_put(THIS_MODULE
);
1263 goto open_unlock_and_return
;
1266 !try_module_get(zr
->encoder
->driver
->driver
.owner
)) {
1269 "%s: failed to grab ownership of i2c encoder\n",
1272 module_put(zr
->decoder
->driver
->driver
.owner
);
1273 module_put(THIS_MODULE
);
1274 goto open_unlock_and_return
;
1277 have_module_locks
= 1;
1279 if (zr
->user
>= 2048) {
1280 dprintk(1, KERN_ERR
"%s: too many users (%d) on device\n",
1281 ZR_DEVNAME(zr
), zr
->user
);
1283 goto open_unlock_and_return
;
1286 dprintk(1, KERN_INFO
"%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
1287 ZR_DEVNAME(zr
), current
->comm
, task_pid_nr(current
), zr
->user
);
1289 /* now, create the open()-specific file_ops struct */
1290 fh
= kzalloc(sizeof(struct zoran_fh
), GFP_KERNEL
);
1294 "%s: zoran_open() - allocation of zoran_fh failed\n",
1297 goto open_unlock_and_return
;
1299 /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
1300 * on norm-change! */
1302 kmalloc(((768 + 31) / 32) * 576 * 4, GFP_KERNEL
);
1303 if (!fh
->overlay_mask
) {
1306 "%s: zoran_open() - allocation of overlay_mask failed\n",
1310 goto open_unlock_and_return
;
1313 if (zr
->user
++ == 0)
1316 /*mutex_unlock(&zr->resource_lock);*/
1318 /* default setup - TODO: look at flags */
1319 if (first_open
) { /* First device open */
1320 zr36057_restart(zr
);
1321 zoran_open_init_params(zr
);
1322 zoran_init_hardware(zr
);
1324 btor(ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1327 /* set file_ops stuff */
1328 file
->private_data
= fh
;
1330 zoran_open_init_session(file
);
1334 open_unlock_and_return
:
1335 /* if we grabbed locks, release them accordingly */
1336 if (have_module_locks
) {
1337 module_put(zr
->decoder
->driver
->driver
.owner
);
1339 module_put(zr
->encoder
->driver
->driver
.owner
);
1341 module_put(THIS_MODULE
);
1344 /* if there's no device found, we didn't obtain the lock either */
1346 /*mutex_unlock(&zr->resource_lock);*/
1353 zoran_close (struct inode
*inode
,
1356 struct zoran_fh
*fh
= file
->private_data
;
1357 struct zoran
*zr
= fh
->zr
;
1359 dprintk(1, KERN_INFO
"%s: zoran_close(%s, pid=[%d]), users(+)=%d\n",
1360 ZR_DEVNAME(zr
), current
->comm
, task_pid_nr(current
), zr
->user
);
1362 /* kernel locks (fs/device.c), so don't do that ourselves
1363 * (prevents deadlocks) */
1364 /*mutex_lock(&zr->resource_lock);*/
1366 zoran_close_end_session(file
);
1368 if (zr
->user
-- == 1) { /* Last process */
1369 /* Clean up JPEG process */
1370 wake_up_interruptible(&zr
->jpg_capq
);
1371 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1372 zr
->jpg_buffers
.allocated
= 0;
1373 zr
->jpg_buffers
.active
= ZORAN_FREE
;
1375 /* disable interrupts */
1376 btand(~ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1378 if (zr36067_debug
> 1)
1379 print_interrupts(zr
);
1382 zr
->v4l_overlay_active
= 0;
1383 zr36057_overlay(zr
, 0);
1384 zr
->overlay_mask
= NULL
;
1387 wake_up_interruptible(&zr
->v4l_capq
);
1388 zr36057_set_memgrab(zr
, 0);
1389 zr
->v4l_buffers
.allocated
= 0;
1390 zr
->v4l_buffers
.active
= ZORAN_FREE
;
1391 zoran_set_pci_master(zr
, 0);
1393 if (!pass_through
) { /* Switch to color bar */
1394 int zero
= 0, two
= 2;
1395 decoder_command(zr
, DECODER_ENABLE_OUTPUT
, &zero
);
1396 encoder_command(zr
, ENCODER_SET_INPUT
, &two
);
1400 file
->private_data
= NULL
;
1401 kfree(fh
->overlay_mask
);
1404 /* release locks on the i2c modules */
1405 module_put(zr
->decoder
->driver
->driver
.owner
);
1407 module_put(zr
->encoder
->driver
->driver
.owner
);
1409 module_put(THIS_MODULE
);
1411 /*mutex_unlock(&zr->resource_lock);*/
1413 dprintk(4, KERN_INFO
"%s: zoran_close() done\n", ZR_DEVNAME(zr
));
1420 zoran_read (struct file
*file
,
1425 /* we simply don't support read() (yet)... */
1431 zoran_write (struct file
*file
,
1432 const char __user
*data
,
1436 /* ...and the same goes for write() */
1442 setup_fbuffer (struct file
*file
,
1444 const struct zoran_format
*fmt
,
1449 struct zoran_fh
*fh
= file
->private_data
;
1450 struct zoran
*zr
= fh
->zr
;
1452 /* (Ronald) v4l/v4l2 guidelines */
1453 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
1456 /* Don't allow frame buffer overlay if PCI or AGP is buggy, or on
1457 ALi Magik (that needs very low latency while the card needs a
1458 higher value always) */
1460 if (pci_pci_problems
& (PCIPCI_FAIL
| PCIAGP_FAIL
| PCIPCI_ALIMAGIK
))
1463 /* we need a bytesperline value, even if not given */
1465 bytesperline
= width
* ((fmt
->depth
+ 7) & ~7) / 8;
1468 if (zr
->overlay_active
) {
1469 /* dzjee... stupid users... don't even bother to turn off
1470 * overlay before changing the memory location...
1471 * normally, we would return errors here. However, one of
1472 * the tools that does this is... xawtv! and since xawtv
1473 * is used by +/- 99% of the users, we'd rather be user-
1474 * friendly and silently do as if nothing went wrong */
1477 "%s: setup_fbuffer() - forced overlay turnoff because framebuffer changed\n",
1479 zr36057_overlay(zr
, 0);
1483 if (!(fmt
->flags
& ZORAN_FORMAT_OVERLAY
)) {
1486 "%s: setup_fbuffer() - no valid overlay format given\n",
1490 if (height
<= 0 || width
<= 0 || bytesperline
<= 0) {
1493 "%s: setup_fbuffer() - invalid height/width/bpl value (%d|%d|%d)\n",
1494 ZR_DEVNAME(zr
), width
, height
, bytesperline
);
1497 if (bytesperline
& 3) {
1500 "%s: setup_fbuffer() - bytesperline (%d) must be 4-byte aligned\n",
1501 ZR_DEVNAME(zr
), bytesperline
);
1505 zr
->buffer
.base
= (void *) ((unsigned long) base
& ~3);
1506 zr
->buffer
.height
= height
;
1507 zr
->buffer
.width
= width
;
1508 zr
->buffer
.depth
= fmt
->depth
;
1509 zr
->overlay_settings
.format
= fmt
;
1510 zr
->buffer
.bytesperline
= bytesperline
;
1512 /* The user should set new window parameters */
1513 zr
->overlay_settings
.is_set
= 0;
1520 setup_window (struct file
*file
,
1525 struct video_clip __user
*clips
,
1527 void __user
*bitmap
)
1529 struct zoran_fh
*fh
= file
->private_data
;
1530 struct zoran
*zr
= fh
->zr
;
1531 struct video_clip
*vcp
= NULL
;
1535 if (!zr
->buffer
.base
) {
1538 "%s: setup_window() - frame buffer has to be set first\n",
1543 if (!fh
->overlay_settings
.format
) {
1546 "%s: setup_window() - no overlay format set\n",
1552 * The video front end needs 4-byte alinged line sizes, we correct that
1553 * silently here if necessary
1555 if (zr
->buffer
.depth
== 15 || zr
->buffer
.depth
== 16) {
1556 end
= (x
+ width
) & ~1; /* round down */
1557 x
= (x
+ 1) & ~1; /* round up */
1561 if (zr
->buffer
.depth
== 24) {
1562 end
= (x
+ width
) & ~3; /* round down */
1563 x
= (x
+ 3) & ~3; /* round up */
1567 if (width
> BUZ_MAX_WIDTH
)
1568 width
= BUZ_MAX_WIDTH
;
1569 if (height
> BUZ_MAX_HEIGHT
)
1570 height
= BUZ_MAX_HEIGHT
;
1572 /* Check for vaild parameters */
1573 if (width
< BUZ_MIN_WIDTH
|| height
< BUZ_MIN_HEIGHT
||
1574 width
> BUZ_MAX_WIDTH
|| height
> BUZ_MAX_HEIGHT
) {
1577 "%s: setup_window() - width = %d or height = %d invalid\n",
1578 ZR_DEVNAME(zr
), width
, height
);
1582 fh
->overlay_settings
.x
= x
;
1583 fh
->overlay_settings
.y
= y
;
1584 fh
->overlay_settings
.width
= width
;
1585 fh
->overlay_settings
.height
= height
;
1586 fh
->overlay_settings
.clipcount
= clipcount
;
1589 * If an overlay is running, we have to switch it off
1590 * and switch it on again in order to get the new settings in effect.
1592 * We also want to avoid that the overlay mask is written
1593 * when an overlay is running.
1596 on
= zr
->v4l_overlay_active
&& !zr
->v4l_memgrab_active
&&
1597 zr
->overlay_active
!= ZORAN_FREE
&&
1598 fh
->overlay_active
!= ZORAN_FREE
;
1600 zr36057_overlay(zr
, 0);
1603 * Write the overlay mask if clips are wanted.
1604 * We prefer a bitmap.
1607 /* fake value - it just means we want clips */
1608 fh
->overlay_settings
.clipcount
= 1;
1610 if (copy_from_user(fh
->overlay_mask
, bitmap
,
1611 (width
* height
+ 7) / 8)) {
1614 } else if (clipcount
> 0) {
1615 /* write our own bitmap from the clips */
1616 vcp
= vmalloc(sizeof(struct video_clip
) * (clipcount
+ 4));
1620 "%s: setup_window() - Alloc of clip mask failed\n",
1625 (vcp
, clips
, sizeof(struct video_clip
) * clipcount
)) {
1629 write_overlay_mask(file
, vcp
, clipcount
);
1633 fh
->overlay_settings
.is_set
= 1;
1634 if (fh
->overlay_active
!= ZORAN_FREE
&&
1635 zr
->overlay_active
!= ZORAN_FREE
)
1636 zr
->overlay_settings
= fh
->overlay_settings
;
1639 zr36057_overlay(zr
, 1);
1641 /* Make sure the changes come into effect */
1642 return wait_grab_pending(zr
);
1646 setup_overlay (struct file
*file
,
1649 struct zoran_fh
*fh
= file
->private_data
;
1650 struct zoran
*zr
= fh
->zr
;
1652 /* If there is nothing to do, return immediatly */
1653 if ((on
&& fh
->overlay_active
!= ZORAN_FREE
) ||
1654 (!on
&& fh
->overlay_active
== ZORAN_FREE
))
1657 /* check whether we're touching someone else's overlay */
1658 if (on
&& zr
->overlay_active
!= ZORAN_FREE
&&
1659 fh
->overlay_active
== ZORAN_FREE
) {
1662 "%s: setup_overlay() - overlay is already active for another session\n",
1666 if (!on
&& zr
->overlay_active
!= ZORAN_FREE
&&
1667 fh
->overlay_active
== ZORAN_FREE
) {
1670 "%s: setup_overlay() - you cannot cancel someone else's session\n",
1676 zr
->overlay_active
= fh
->overlay_active
= ZORAN_FREE
;
1677 zr
->v4l_overlay_active
= 0;
1678 /* When a grab is running, the video simply
1679 * won't be switched on any more */
1680 if (!zr
->v4l_memgrab_active
)
1681 zr36057_overlay(zr
, 0);
1682 zr
->overlay_mask
= NULL
;
1684 if (!zr
->buffer
.base
|| !fh
->overlay_settings
.is_set
) {
1687 "%s: setup_overlay() - buffer or window not set\n",
1691 if (!fh
->overlay_settings
.format
) {
1694 "%s: setup_overlay() - no overlay format set\n",
1698 zr
->overlay_active
= fh
->overlay_active
= ZORAN_LOCKED
;
1699 zr
->v4l_overlay_active
= 1;
1700 zr
->overlay_mask
= fh
->overlay_mask
;
1701 zr
->overlay_settings
= fh
->overlay_settings
;
1702 if (!zr
->v4l_memgrab_active
)
1703 zr36057_overlay(zr
, 1);
1704 /* When a grab is running, the video will be
1705 * switched on when grab is finished */
1708 /* Make sure the changes come into effect */
1709 return wait_grab_pending(zr
);
1712 #ifdef CONFIG_VIDEO_V4L2
1713 /* get the status of a buffer in the clients buffer queue */
1715 zoran_v4l2_buffer_status (struct file
*file
,
1716 struct v4l2_buffer
*buf
,
1719 struct zoran_fh
*fh
= file
->private_data
;
1720 struct zoran
*zr
= fh
->zr
;
1722 buf
->flags
= V4L2_BUF_FLAG_MAPPED
;
1724 switch (fh
->map_mode
) {
1725 case ZORAN_MAP_MODE_RAW
:
1728 if (num
< 0 || num
>= fh
->v4l_buffers
.num_buffers
||
1729 !fh
->v4l_buffers
.allocated
) {
1732 "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
1737 buf
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1738 buf
->length
= fh
->v4l_buffers
.buffer_size
;
1741 buf
->bytesused
= fh
->v4l_buffers
.buffer
[num
].bs
.length
;
1742 if (fh
->v4l_buffers
.buffer
[num
].state
== BUZ_STATE_DONE
||
1743 fh
->v4l_buffers
.buffer
[num
].state
== BUZ_STATE_USER
) {
1744 buf
->sequence
= fh
->v4l_buffers
.buffer
[num
].bs
.seq
;
1745 buf
->flags
|= V4L2_BUF_FLAG_DONE
;
1747 fh
->v4l_buffers
.buffer
[num
].bs
.timestamp
;
1749 buf
->flags
|= V4L2_BUF_FLAG_QUEUED
;
1752 if (fh
->v4l_settings
.height
<= BUZ_MAX_HEIGHT
/ 2)
1753 buf
->field
= V4L2_FIELD_TOP
;
1755 buf
->field
= V4L2_FIELD_INTERLACED
;
1759 case ZORAN_MAP_MODE_JPG_REC
:
1760 case ZORAN_MAP_MODE_JPG_PLAY
:
1763 if (num
< 0 || num
>= fh
->jpg_buffers
.num_buffers
||
1764 !fh
->jpg_buffers
.allocated
) {
1767 "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
1772 buf
->type
= (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
) ?
1773 V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1774 V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1775 buf
->length
= fh
->jpg_buffers
.buffer_size
;
1777 /* these variables are only written after frame has been captured */
1778 if (fh
->jpg_buffers
.buffer
[num
].state
== BUZ_STATE_DONE
||
1779 fh
->jpg_buffers
.buffer
[num
].state
== BUZ_STATE_USER
) {
1780 buf
->sequence
= fh
->jpg_buffers
.buffer
[num
].bs
.seq
;
1782 fh
->jpg_buffers
.buffer
[num
].bs
.timestamp
;
1784 fh
->jpg_buffers
.buffer
[num
].bs
.length
;
1785 buf
->flags
|= V4L2_BUF_FLAG_DONE
;
1787 buf
->flags
|= V4L2_BUF_FLAG_QUEUED
;
1790 /* which fields are these? */
1791 if (fh
->jpg_settings
.TmpDcm
!= 1)
1794 odd_even
? V4L2_FIELD_TOP
: V4L2_FIELD_BOTTOM
;
1798 odd_even
? V4L2_FIELD_SEQ_TB
:
1807 "%s: v4l2_buffer_status() - invalid buffer type|map_mode (%d|%d)\n",
1808 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
1812 buf
->memory
= V4L2_MEMORY_MMAP
;
1814 buf
->m
.offset
= buf
->length
* num
;
1821 zoran_set_norm (struct zoran
*zr
,
1822 int norm
) /* VIDEO_MODE_* */
1824 int norm_encoder
, on
;
1826 if (zr
->v4l_buffers
.active
!= ZORAN_FREE
||
1827 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
1830 "%s: set_norm() called while in playback/capture mode\n",
1835 if (lock_norm
&& norm
!= zr
->norm
) {
1836 if (lock_norm
> 1) {
1839 "%s: set_norm() - TV standard is locked, can not switch norm\n",
1845 "%s: set_norm() - TV standard is locked, norm was not changed\n",
1851 if (norm
!= VIDEO_MODE_AUTO
&&
1852 (norm
< 0 || norm
>= zr
->card
.norms
||
1853 !zr
->card
.tvn
[norm
])) {
1855 KERN_ERR
"%s: set_norm() - unsupported norm %d\n",
1856 ZR_DEVNAME(zr
), norm
);
1860 if (norm
== VIDEO_MODE_AUTO
) {
1863 /* if we have autodetect, ... */
1864 struct video_decoder_capability caps
;
1865 decoder_command(zr
, DECODER_GET_CAPABILITIES
, &caps
);
1866 if (!(caps
.flags
& VIDEO_DECODER_AUTO
)) {
1867 dprintk(1, KERN_ERR
"%s: norm=auto unsupported\n",
1872 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
1874 /* let changes come into effect */
1877 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
1878 if (!(status
& DECODER_STATUS_GOOD
)) {
1881 "%s: set_norm() - no norm detected\n",
1884 decoder_command(zr
, DECODER_SET_NORM
, &zr
->norm
);
1888 if (status
& DECODER_STATUS_NTSC
)
1889 norm
= VIDEO_MODE_NTSC
;
1890 else if (status
& DECODER_STATUS_SECAM
)
1891 norm
= VIDEO_MODE_SECAM
;
1893 norm
= VIDEO_MODE_PAL
;
1895 zr
->timing
= zr
->card
.tvn
[norm
];
1896 norm_encoder
= norm
;
1898 /* We switch overlay off and on since a change in the
1899 * norm needs different VFE settings */
1900 on
= zr
->overlay_active
&& !zr
->v4l_memgrab_active
;
1902 zr36057_overlay(zr
, 0);
1904 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
1905 encoder_command(zr
, ENCODER_SET_NORM
, &norm_encoder
);
1908 zr36057_overlay(zr
, 1);
1910 /* Make sure the changes come into effect */
1917 zoran_set_input (struct zoran
*zr
,
1922 if (input
== zr
->input
) {
1926 if (zr
->v4l_buffers
.active
!= ZORAN_FREE
||
1927 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
1930 "%s: set_input() called while in playback/capture mode\n",
1935 if (input
< 0 || input
>= zr
->card
.inputs
) {
1938 "%s: set_input() - unnsupported input %d\n",
1939 ZR_DEVNAME(zr
), input
);
1943 realinput
= zr
->card
.input
[input
].muxsel
;
1946 decoder_command(zr
, DECODER_SET_INPUT
, &realinput
);
1956 zoran_do_ioctl (struct inode
*inode
,
1961 struct zoran_fh
*fh
= file
->private_data
;
1962 struct zoran
*zr
= fh
->zr
;
1963 /* CAREFUL: used in multiple places here */
1964 struct zoran_jpg_settings settings
;
1966 /* we might have older buffers lying around... We don't want
1967 * to wait, but we do want to try cleaning them up ASAP. So
1968 * we try to obtain the lock and free them. If that fails, we
1969 * don't do anything and wait for the next turn. In the end,
1970 * zoran_close() or a new allocation will still free them...
1971 * This is just a 'the sooner the better' extra 'feature'
1973 * We don't free the buffers right on munmap() because that
1974 * causes oopses (kfree() inside munmap() oopses for no
1975 * apparent reason - it's also not reproduceable in any way,
1976 * but moving the free code outside the munmap() handler fixes
1977 * all this... If someone knows why, please explain me (Ronald)
1979 if (mutex_trylock(&zr
->resource_lock
)) {
1980 /* we obtained it! Let's try to free some things */
1981 if (fh
->jpg_buffers
.ready_to_be_freed
)
1982 jpg_fbuffer_free(file
);
1983 if (fh
->v4l_buffers
.ready_to_be_freed
)
1984 v4l_fbuffer_free(file
);
1986 mutex_unlock(&zr
->resource_lock
);
1993 struct video_capability
*vcap
= arg
;
1995 dprintk(3, KERN_DEBUG
"%s: VIDIOCGCAP\n", ZR_DEVNAME(zr
));
1997 memset(vcap
, 0, sizeof(struct video_capability
));
1998 strncpy(vcap
->name
, ZR_DEVNAME(zr
), sizeof(vcap
->name
)-1);
1999 vcap
->type
= ZORAN_VID_TYPE
;
2001 vcap
->channels
= zr
->card
.inputs
;
2003 mutex_lock(&zr
->resource_lock
);
2004 vcap
->maxwidth
= BUZ_MAX_WIDTH
;
2005 vcap
->maxheight
= BUZ_MAX_HEIGHT
;
2006 vcap
->minwidth
= BUZ_MIN_WIDTH
;
2007 vcap
->minheight
= BUZ_MIN_HEIGHT
;
2008 mutex_unlock(&zr
->resource_lock
);
2016 struct video_channel
*vchan
= arg
;
2017 int channel
= vchan
->channel
;
2019 dprintk(3, KERN_DEBUG
"%s: VIDIOCGCHAN - channel=%d\n",
2020 ZR_DEVNAME(zr
), vchan
->channel
);
2022 memset(vchan
, 0, sizeof(struct video_channel
));
2023 if (channel
> zr
->card
.inputs
|| channel
< 0) {
2026 "%s: VIDIOCGCHAN on not existing channel %d\n",
2027 ZR_DEVNAME(zr
), channel
);
2031 strcpy(vchan
->name
, zr
->card
.input
[channel
].name
);
2035 vchan
->type
= VIDEO_TYPE_CAMERA
;
2036 mutex_lock(&zr
->resource_lock
);
2037 vchan
->norm
= zr
->norm
;
2038 mutex_unlock(&zr
->resource_lock
);
2039 vchan
->channel
= channel
;
2045 /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says:
2047 * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input."
2049 * * The famos BTTV driver has it implemented with a struct video_channel argument
2050 * * and we follow it for compatibility reasons
2052 * * BTW: this is the only way the user can set the norm!
2057 struct video_channel
*vchan
= arg
;
2062 "%s: VIDIOCSCHAN - channel=%d, norm=%d\n",
2063 ZR_DEVNAME(zr
), vchan
->channel
, vchan
->norm
);
2065 mutex_lock(&zr
->resource_lock
);
2066 if ((res
= zoran_set_input(zr
, vchan
->channel
)))
2067 goto schan_unlock_and_return
;
2068 if ((res
= zoran_set_norm(zr
, vchan
->norm
)))
2069 goto schan_unlock_and_return
;
2071 /* Make sure the changes come into effect */
2072 res
= wait_grab_pending(zr
);
2073 schan_unlock_and_return
:
2074 mutex_unlock(&zr
->resource_lock
);
2081 struct video_picture
*vpict
= arg
;
2083 dprintk(3, KERN_DEBUG
"%s: VIDIOCGPICT\n", ZR_DEVNAME(zr
));
2085 memset(vpict
, 0, sizeof(struct video_picture
));
2086 mutex_lock(&zr
->resource_lock
);
2087 vpict
->hue
= zr
->hue
;
2088 vpict
->brightness
= zr
->brightness
;
2089 vpict
->contrast
= zr
->contrast
;
2090 vpict
->colour
= zr
->saturation
;
2091 if (fh
->overlay_settings
.format
) {
2092 vpict
->depth
= fh
->overlay_settings
.format
->depth
;
2093 vpict
->palette
= fh
->overlay_settings
.format
->palette
;
2097 mutex_unlock(&zr
->resource_lock
);
2105 struct video_picture
*vpict
= arg
;
2110 "%s: VIDIOCSPICT - bri=%d, hue=%d, col=%d, con=%d, dep=%d, pal=%d\n",
2111 ZR_DEVNAME(zr
), vpict
->brightness
, vpict
->hue
,
2112 vpict
->colour
, vpict
->contrast
, vpict
->depth
,
2115 for (i
= 0; i
< NUM_FORMATS
; i
++) {
2116 const struct zoran_format
*fmt
= &zoran_formats
[i
];
2118 if (fmt
->palette
!= -1 &&
2119 fmt
->flags
& ZORAN_FORMAT_OVERLAY
&&
2120 fmt
->palette
== vpict
->palette
&&
2121 fmt
->depth
== vpict
->depth
)
2124 if (i
== NUM_FORMATS
) {
2127 "%s: VIDIOCSPICT - Invalid palette %d\n",
2128 ZR_DEVNAME(zr
), vpict
->palette
);
2132 mutex_lock(&zr
->resource_lock
);
2134 decoder_command(zr
, DECODER_SET_PICTURE
, vpict
);
2136 zr
->hue
= vpict
->hue
;
2137 zr
->contrast
= vpict
->contrast
;
2138 zr
->saturation
= vpict
->colour
;
2139 zr
->brightness
= vpict
->brightness
;
2141 fh
->overlay_settings
.format
= &zoran_formats
[i
];
2143 mutex_unlock(&zr
->resource_lock
);
2153 dprintk(3, KERN_DEBUG
"%s: VIDIOCCAPTURE - on=%d\n",
2154 ZR_DEVNAME(zr
), *on
);
2156 mutex_lock(&zr
->resource_lock
);
2157 res
= setup_overlay(file
, *on
);
2158 mutex_unlock(&zr
->resource_lock
);
2166 struct video_window
*vwin
= arg
;
2168 dprintk(3, KERN_DEBUG
"%s: VIDIOCGWIN\n", ZR_DEVNAME(zr
));
2170 memset(vwin
, 0, sizeof(struct video_window
));
2171 mutex_lock(&zr
->resource_lock
);
2172 vwin
->x
= fh
->overlay_settings
.x
;
2173 vwin
->y
= fh
->overlay_settings
.y
;
2174 vwin
->width
= fh
->overlay_settings
.width
;
2175 vwin
->height
= fh
->overlay_settings
.height
;
2176 mutex_unlock(&zr
->resource_lock
);
2177 vwin
->clipcount
= 0;
2184 struct video_window
*vwin
= arg
;
2189 "%s: VIDIOCSWIN - x=%d, y=%d, w=%d, h=%d, clipcount=%d\n",
2190 ZR_DEVNAME(zr
), vwin
->x
, vwin
->y
, vwin
->width
,
2191 vwin
->height
, vwin
->clipcount
);
2193 mutex_lock(&zr
->resource_lock
);
2195 setup_window(file
, vwin
->x
, vwin
->y
, vwin
->width
,
2196 vwin
->height
, vwin
->clips
,
2197 vwin
->clipcount
, NULL
);
2198 mutex_unlock(&zr
->resource_lock
);
2206 struct video_buffer
*vbuf
= arg
;
2208 dprintk(3, KERN_DEBUG
"%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr
));
2210 mutex_lock(&zr
->resource_lock
);
2212 mutex_unlock(&zr
->resource_lock
);
2219 struct video_buffer
*vbuf
= arg
;
2224 "%s: VIDIOCSFBUF - base=%p, w=%d, h=%d, depth=%d, bpl=%d\n",
2225 ZR_DEVNAME(zr
), vbuf
->base
, vbuf
->width
,
2226 vbuf
->height
, vbuf
->depth
, vbuf
->bytesperline
);
2228 for (i
= 0; i
< NUM_FORMATS
; i
++)
2229 if (zoran_formats
[i
].depth
== vbuf
->depth
)
2231 if (i
== NUM_FORMATS
) {
2234 "%s: VIDIOCSFBUF - invalid fbuf depth %d\n",
2235 ZR_DEVNAME(zr
), vbuf
->depth
);
2239 mutex_lock(&zr
->resource_lock
);
2241 setup_fbuffer(file
, vbuf
->base
, &zoran_formats
[i
],
2242 vbuf
->width
, vbuf
->height
,
2243 vbuf
->bytesperline
);
2244 mutex_unlock(&zr
->resource_lock
);
2252 int *frame
= arg
, res
;
2254 dprintk(3, KERN_DEBUG
"%s: VIDIOCSYNC - frame=%d\n",
2255 ZR_DEVNAME(zr
), *frame
);
2257 mutex_lock(&zr
->resource_lock
);
2258 res
= v4l_sync(file
, *frame
);
2259 mutex_unlock(&zr
->resource_lock
);
2261 zr
->v4l_sync_tail
++;
2266 case VIDIOCMCAPTURE
:
2268 struct video_mmap
*vmap
= arg
;
2273 "%s: VIDIOCMCAPTURE - frame=%d, geom=%dx%d, fmt=%d\n",
2274 ZR_DEVNAME(zr
), vmap
->frame
, vmap
->width
, vmap
->height
,
2277 mutex_lock(&zr
->resource_lock
);
2278 res
= v4l_grab(file
, vmap
);
2279 mutex_unlock(&zr
->resource_lock
);
2286 struct video_mbuf
*vmbuf
= arg
;
2289 dprintk(3, KERN_DEBUG
"%s: VIDIOCGMBUF\n", ZR_DEVNAME(zr
));
2292 fh
->v4l_buffers
.num_buffers
*
2293 fh
->v4l_buffers
.buffer_size
;
2294 vmbuf
->frames
= fh
->v4l_buffers
.num_buffers
;
2295 for (i
= 0; i
< vmbuf
->frames
; i
++) {
2297 i
* fh
->v4l_buffers
.buffer_size
;
2300 mutex_lock(&zr
->resource_lock
);
2302 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
2305 "%s: VIDIOCGMBUF - buffers already allocated\n",
2308 goto v4l1reqbuf_unlock_and_return
;
2311 if (v4l_fbuffer_alloc(file
)) {
2313 goto v4l1reqbuf_unlock_and_return
;
2316 /* The next mmap will map the V4L buffers */
2317 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
2318 v4l1reqbuf_unlock_and_return
:
2319 mutex_unlock(&zr
->resource_lock
);
2327 struct video_unit
*vunit
= arg
;
2329 dprintk(3, KERN_DEBUG
"%s: VIDIOCGUNIT\n", ZR_DEVNAME(zr
));
2331 vunit
->video
= zr
->video_dev
->minor
;
2332 vunit
->vbi
= VIDEO_NO_UNIT
;
2333 vunit
->radio
= VIDEO_NO_UNIT
;
2334 vunit
->audio
= VIDEO_NO_UNIT
;
2335 vunit
->teletext
= VIDEO_NO_UNIT
;
2342 * RJ: In principal we could support subcaptures for V4L grabbing.
2343 * Not even the famous BTTV driver has them, however.
2344 * If there should be a strong demand, one could consider
2345 * to implement them.
2347 case VIDIOCGCAPTURE
:
2349 dprintk(3, KERN_ERR
"%s: VIDIOCGCAPTURE not supported\n",
2355 case VIDIOCSCAPTURE
:
2357 dprintk(3, KERN_ERR
"%s: VIDIOCSCAPTURE not supported\n",
2363 case BUZIOC_G_PARAMS
:
2365 struct zoran_params
*bparams
= arg
;
2367 dprintk(3, KERN_DEBUG
"%s: BUZIOC_G_PARAMS\n", ZR_DEVNAME(zr
));
2369 memset(bparams
, 0, sizeof(struct zoran_params
));
2370 bparams
->major_version
= MAJOR_VERSION
;
2371 bparams
->minor_version
= MINOR_VERSION
;
2373 mutex_lock(&zr
->resource_lock
);
2375 bparams
->norm
= zr
->norm
;
2376 bparams
->input
= zr
->input
;
2378 bparams
->decimation
= fh
->jpg_settings
.decimation
;
2379 bparams
->HorDcm
= fh
->jpg_settings
.HorDcm
;
2380 bparams
->VerDcm
= fh
->jpg_settings
.VerDcm
;
2381 bparams
->TmpDcm
= fh
->jpg_settings
.TmpDcm
;
2382 bparams
->field_per_buff
= fh
->jpg_settings
.field_per_buff
;
2383 bparams
->img_x
= fh
->jpg_settings
.img_x
;
2384 bparams
->img_y
= fh
->jpg_settings
.img_y
;
2385 bparams
->img_width
= fh
->jpg_settings
.img_width
;
2386 bparams
->img_height
= fh
->jpg_settings
.img_height
;
2387 bparams
->odd_even
= fh
->jpg_settings
.odd_even
;
2389 bparams
->quality
= fh
->jpg_settings
.jpg_comp
.quality
;
2390 bparams
->APPn
= fh
->jpg_settings
.jpg_comp
.APPn
;
2391 bparams
->APP_len
= fh
->jpg_settings
.jpg_comp
.APP_len
;
2392 memcpy(bparams
->APP_data
,
2393 fh
->jpg_settings
.jpg_comp
.APP_data
,
2394 sizeof(bparams
->APP_data
));
2395 bparams
->COM_len
= zr
->jpg_settings
.jpg_comp
.COM_len
;
2396 memcpy(bparams
->COM_data
,
2397 fh
->jpg_settings
.jpg_comp
.COM_data
,
2398 sizeof(bparams
->COM_data
));
2399 bparams
->jpeg_markers
=
2400 fh
->jpg_settings
.jpg_comp
.jpeg_markers
;
2402 mutex_unlock(&zr
->resource_lock
);
2404 bparams
->VFIFO_FB
= 0;
2410 case BUZIOC_S_PARAMS
:
2412 struct zoran_params
*bparams
= arg
;
2415 dprintk(3, KERN_DEBUG
"%s: BUZIOC_S_PARAMS\n", ZR_DEVNAME(zr
));
2417 settings
.decimation
= bparams
->decimation
;
2418 settings
.HorDcm
= bparams
->HorDcm
;
2419 settings
.VerDcm
= bparams
->VerDcm
;
2420 settings
.TmpDcm
= bparams
->TmpDcm
;
2421 settings
.field_per_buff
= bparams
->field_per_buff
;
2422 settings
.img_x
= bparams
->img_x
;
2423 settings
.img_y
= bparams
->img_y
;
2424 settings
.img_width
= bparams
->img_width
;
2425 settings
.img_height
= bparams
->img_height
;
2426 settings
.odd_even
= bparams
->odd_even
;
2428 settings
.jpg_comp
.quality
= bparams
->quality
;
2429 settings
.jpg_comp
.APPn
= bparams
->APPn
;
2430 settings
.jpg_comp
.APP_len
= bparams
->APP_len
;
2431 memcpy(settings
.jpg_comp
.APP_data
, bparams
->APP_data
,
2432 sizeof(bparams
->APP_data
));
2433 settings
.jpg_comp
.COM_len
= bparams
->COM_len
;
2434 memcpy(settings
.jpg_comp
.COM_data
, bparams
->COM_data
,
2435 sizeof(bparams
->COM_data
));
2436 settings
.jpg_comp
.jpeg_markers
= bparams
->jpeg_markers
;
2438 mutex_lock(&zr
->resource_lock
);
2440 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2443 "%s: BUZIOC_S_PARAMS called, but Buz in capture/playback mode\n",
2446 goto sparams_unlock_and_return
;
2449 /* Check the params first before overwriting our
2451 if (zoran_check_jpg_settings(zr
, &settings
)) {
2453 goto sparams_unlock_and_return
;
2456 fh
->jpg_settings
= settings
;
2457 sparams_unlock_and_return
:
2458 mutex_unlock(&zr
->resource_lock
);
2464 case BUZIOC_REQBUFS
:
2466 struct zoran_requestbuffers
*breq
= arg
;
2471 "%s: BUZIOC_REQBUFS - count=%lu, size=%lu\n",
2472 ZR_DEVNAME(zr
), breq
->count
, breq
->size
);
2474 /* Enforce reasonable lower and upper limits */
2475 if (breq
->count
< 4)
2476 breq
->count
= 4; /* Could be choosen smaller */
2477 if (breq
->count
> jpg_nbufs
)
2478 breq
->count
= jpg_nbufs
;
2479 breq
->size
= PAGE_ALIGN(breq
->size
);
2480 if (breq
->size
< 8192)
2481 breq
->size
= 8192; /* Arbitrary */
2482 /* breq->size is limited by 1 page for the stat_com
2483 * tables to a Maximum of 2 MB */
2484 if (breq
->size
> jpg_bufsize
)
2485 breq
->size
= jpg_bufsize
;
2486 if (fh
->jpg_buffers
.need_contiguous
&&
2487 breq
->size
> MAX_KMALLOC_MEM
)
2488 breq
->size
= MAX_KMALLOC_MEM
;
2490 mutex_lock(&zr
->resource_lock
);
2492 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
2495 "%s: BUZIOC_REQBUFS - buffers allready allocated\n",
2498 goto jpgreqbuf_unlock_and_return
;
2501 fh
->jpg_buffers
.num_buffers
= breq
->count
;
2502 fh
->jpg_buffers
.buffer_size
= breq
->size
;
2504 if (jpg_fbuffer_alloc(file
)) {
2506 goto jpgreqbuf_unlock_and_return
;
2509 /* The next mmap will map the MJPEG buffers - could
2510 * also be *_PLAY, but it doesn't matter here */
2511 fh
->map_mode
= ZORAN_MAP_MODE_JPG_REC
;
2512 jpgreqbuf_unlock_and_return
:
2513 mutex_unlock(&zr
->resource_lock
);
2519 case BUZIOC_QBUF_CAPT
:
2521 int *frame
= arg
, res
;
2523 dprintk(3, KERN_DEBUG
"%s: BUZIOC_QBUF_CAPT - frame=%d\n",
2524 ZR_DEVNAME(zr
), *frame
);
2526 mutex_lock(&zr
->resource_lock
);
2527 res
= jpg_qbuf(file
, *frame
, BUZ_MODE_MOTION_COMPRESS
);
2528 mutex_unlock(&zr
->resource_lock
);
2534 case BUZIOC_QBUF_PLAY
:
2536 int *frame
= arg
, res
;
2538 dprintk(3, KERN_DEBUG
"%s: BUZIOC_QBUF_PLAY - frame=%d\n",
2539 ZR_DEVNAME(zr
), *frame
);
2541 mutex_lock(&zr
->resource_lock
);
2542 res
= jpg_qbuf(file
, *frame
, BUZ_MODE_MOTION_DECOMPRESS
);
2543 mutex_unlock(&zr
->resource_lock
);
2551 struct zoran_sync
*bsync
= arg
;
2554 dprintk(3, KERN_DEBUG
"%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr
));
2556 mutex_lock(&zr
->resource_lock
);
2557 res
= jpg_sync(file
, bsync
);
2558 mutex_unlock(&zr
->resource_lock
);
2564 case BUZIOC_G_STATUS
:
2566 struct zoran_status
*bstat
= arg
;
2567 int norm
, input
, status
, res
= 0;
2569 dprintk(3, KERN_DEBUG
"%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr
));
2571 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2574 "%s: BUZIOC_G_STATUS called but Buz in capture/playback mode\n",
2579 input
= zr
->card
.input
[bstat
->input
].muxsel
;
2580 norm
= VIDEO_MODE_AUTO
;
2582 mutex_lock(&zr
->resource_lock
);
2584 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2587 "%s: BUZIOC_G_STATUS called, but Buz in capture/playback mode\n",
2590 goto gstat_unlock_and_return
;
2593 decoder_command(zr
, DECODER_SET_INPUT
, &input
);
2594 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
2596 /* sleep 1 second */
2599 /* Get status of video decoder */
2600 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
2602 /* restore previous input and norm */
2603 input
= zr
->card
.input
[zr
->input
].muxsel
;
2604 decoder_command(zr
, DECODER_SET_INPUT
, &input
);
2605 decoder_command(zr
, DECODER_SET_NORM
, &zr
->norm
);
2606 gstat_unlock_and_return
:
2607 mutex_unlock(&zr
->resource_lock
);
2611 (status
& DECODER_STATUS_GOOD
) ? 1 : 0;
2612 if (status
& DECODER_STATUS_NTSC
)
2613 bstat
->norm
= VIDEO_MODE_NTSC
;
2614 else if (status
& DECODER_STATUS_SECAM
)
2615 bstat
->norm
= VIDEO_MODE_SECAM
;
2617 bstat
->norm
= VIDEO_MODE_PAL
;
2620 (status
& DECODER_STATUS_COLOR
) ? 1 : 0;
2627 #ifdef CONFIG_VIDEO_V4L2
2629 /* The new video4linux2 capture interface - much nicer than video4linux1, since
2630 * it allows for integrating the JPEG capturing calls inside standard v4l2
2633 case VIDIOC_QUERYCAP
:
2635 struct v4l2_capability
*cap
= arg
;
2637 dprintk(3, KERN_DEBUG
"%s: VIDIOC_QUERYCAP\n", ZR_DEVNAME(zr
));
2639 memset(cap
, 0, sizeof(*cap
));
2640 strncpy(cap
->card
, ZR_DEVNAME(zr
), sizeof(cap
->card
)-1);
2641 strncpy(cap
->driver
, "zoran", sizeof(cap
->driver
)-1);
2642 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "PCI:%s",
2643 pci_name(zr
->pci_dev
));
2645 KERNEL_VERSION(MAJOR_VERSION
, MINOR_VERSION
,
2647 cap
->capabilities
= ZORAN_V4L2_VID_FLAGS
;
2653 case VIDIOC_ENUM_FMT
:
2655 struct v4l2_fmtdesc
*fmt
= arg
;
2656 int index
= fmt
->index
, num
= -1, i
, flag
= 0, type
=
2659 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUM_FMT - index=%d\n",
2660 ZR_DEVNAME(zr
), fmt
->index
);
2662 switch (fmt
->type
) {
2663 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2664 flag
= ZORAN_FORMAT_CAPTURE
;
2666 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2667 flag
= ZORAN_FORMAT_PLAYBACK
;
2669 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2670 flag
= ZORAN_FORMAT_OVERLAY
;
2675 "%s: VIDIOC_ENUM_FMT - unknown type %d\n",
2676 ZR_DEVNAME(zr
), fmt
->type
);
2680 for (i
= 0; i
< NUM_FORMATS
; i
++) {
2681 if (zoran_formats
[i
].flags
& flag
)
2683 if (num
== fmt
->index
)
2686 if (fmt
->index
< 0 /* late, but not too late */ ||
2690 memset(fmt
, 0, sizeof(*fmt
));
2693 strncpy(fmt
->description
, zoran_formats
[i
].name
, sizeof(fmt
->description
)-1);
2694 fmt
->pixelformat
= zoran_formats
[i
].fourcc
;
2695 if (zoran_formats
[i
].flags
& ZORAN_FORMAT_COMPRESSED
)
2696 fmt
->flags
|= V4L2_FMT_FLAG_COMPRESSED
;
2704 struct v4l2_format
*fmt
= arg
;
2705 int type
= fmt
->type
;
2707 dprintk(5, KERN_DEBUG
"%s: VIDIOC_G_FMT\n", ZR_DEVNAME(zr
));
2709 memset(fmt
, 0, sizeof(*fmt
));
2712 switch (fmt
->type
) {
2713 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2715 mutex_lock(&zr
->resource_lock
);
2717 fmt
->fmt
.win
.w
.left
= fh
->overlay_settings
.x
;
2718 fmt
->fmt
.win
.w
.top
= fh
->overlay_settings
.y
;
2719 fmt
->fmt
.win
.w
.width
= fh
->overlay_settings
.width
;
2720 fmt
->fmt
.win
.w
.height
=
2721 fh
->overlay_settings
.height
;
2722 if (fh
->overlay_settings
.width
* 2 >
2724 fmt
->fmt
.win
.field
= V4L2_FIELD_INTERLACED
;
2726 fmt
->fmt
.win
.field
= V4L2_FIELD_TOP
;
2728 mutex_unlock(&zr
->resource_lock
);
2732 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2733 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2735 mutex_lock(&zr
->resource_lock
);
2737 if (fmt
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
2738 fh
->map_mode
== ZORAN_MAP_MODE_RAW
) {
2740 fmt
->fmt
.pix
.width
=
2741 fh
->v4l_settings
.width
;
2742 fmt
->fmt
.pix
.height
=
2743 fh
->v4l_settings
.height
;
2744 fmt
->fmt
.pix
.sizeimage
=
2745 fh
->v4l_settings
.bytesperline
*
2746 fh
->v4l_settings
.height
;
2747 fmt
->fmt
.pix
.pixelformat
=
2748 fh
->v4l_settings
.format
->fourcc
;
2749 fmt
->fmt
.pix
.colorspace
=
2750 fh
->v4l_settings
.format
->colorspace
;
2751 fmt
->fmt
.pix
.bytesperline
= 0;
2752 if (BUZ_MAX_HEIGHT
<
2753 (fh
->v4l_settings
.height
* 2))
2754 fmt
->fmt
.pix
.field
=
2755 V4L2_FIELD_INTERLACED
;
2757 fmt
->fmt
.pix
.field
=
2762 fmt
->fmt
.pix
.width
=
2763 fh
->jpg_settings
.img_width
/
2764 fh
->jpg_settings
.HorDcm
;
2765 fmt
->fmt
.pix
.height
=
2766 fh
->jpg_settings
.img_height
/
2767 (fh
->jpg_settings
.VerDcm
*
2768 fh
->jpg_settings
.TmpDcm
);
2769 fmt
->fmt
.pix
.sizeimage
=
2770 zoran_v4l2_calc_bufsize(&fh
->
2772 fmt
->fmt
.pix
.pixelformat
=
2774 if (fh
->jpg_settings
.TmpDcm
== 1)
2775 fmt
->fmt
.pix
.field
=
2777 odd_even
? V4L2_FIELD_SEQ_BT
:
2780 fmt
->fmt
.pix
.field
=
2782 odd_even
? V4L2_FIELD_TOP
:
2785 fmt
->fmt
.pix
.bytesperline
= 0;
2786 fmt
->fmt
.pix
.colorspace
=
2787 V4L2_COLORSPACE_SMPTE170M
;
2790 mutex_unlock(&zr
->resource_lock
);
2797 "%s: VIDIOC_G_FMT - unsupported type %d\n",
2798 ZR_DEVNAME(zr
), fmt
->type
);
2807 struct v4l2_format
*fmt
= arg
;
2811 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_FMT - type=%d, ",
2812 ZR_DEVNAME(zr
), fmt
->type
);
2814 switch (fmt
->type
) {
2815 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2817 dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n",
2818 fmt
->fmt
.win
.w
.left
, fmt
->fmt
.win
.w
.top
,
2819 fmt
->fmt
.win
.w
.width
,
2820 fmt
->fmt
.win
.w
.height
,
2821 fmt
->fmt
.win
.clipcount
,
2822 fmt
->fmt
.win
.bitmap
);
2823 mutex_lock(&zr
->resource_lock
);
2825 setup_window(file
, fmt
->fmt
.win
.w
.left
,
2827 fmt
->fmt
.win
.w
.width
,
2828 fmt
->fmt
.win
.w
.height
,
2829 (struct video_clip __user
*)
2831 fmt
->fmt
.win
.clipcount
,
2832 fmt
->fmt
.win
.bitmap
);
2833 mutex_unlock(&zr
->resource_lock
);
2837 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2838 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2841 __cpu_to_le32(fmt
->fmt
.pix
.pixelformat
);
2842 dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n",
2843 fmt
->fmt
.pix
.width
, fmt
->fmt
.pix
.height
,
2844 fmt
->fmt
.pix
.pixelformat
,
2845 (char *) &printformat
);
2847 if (fmt
->fmt
.pix
.bytesperline
> 0) {
2849 KERN_ERR
"%s: bpl not supported\n",
2854 /* we can be requested to do JPEG/raw playback/capture */
2856 (fmt
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
2857 (fmt
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
2858 fmt
->fmt
.pix
.pixelformat
==
2859 V4L2_PIX_FMT_MJPEG
))) {
2862 "%s: VIDIOC_S_FMT - unknown type %d/0x%x(%4.4s) combination\n",
2863 ZR_DEVNAME(zr
), fmt
->type
,
2864 fmt
->fmt
.pix
.pixelformat
,
2865 (char *) &printformat
);
2869 if (fmt
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_MJPEG
) {
2870 mutex_lock(&zr
->resource_lock
);
2872 settings
= fh
->jpg_settings
;
2874 if (fh
->v4l_buffers
.allocated
||
2875 fh
->jpg_buffers
.allocated
) {
2878 "%s: VIDIOC_S_FMT - cannot change capture mode\n",
2881 goto sfmtjpg_unlock_and_return
;
2884 /* we actually need to set 'real' parameters now */
2885 if ((fmt
->fmt
.pix
.height
* 2) >
2887 settings
.TmpDcm
= 1;
2889 settings
.TmpDcm
= 2;
2890 settings
.decimation
= 0;
2891 if (fmt
->fmt
.pix
.height
<=
2892 fh
->jpg_settings
.img_height
/ 2)
2893 settings
.VerDcm
= 2;
2895 settings
.VerDcm
= 1;
2896 if (fmt
->fmt
.pix
.width
<=
2897 fh
->jpg_settings
.img_width
/ 4)
2898 settings
.HorDcm
= 4;
2899 else if (fmt
->fmt
.pix
.width
<=
2900 fh
->jpg_settings
.img_width
/ 2)
2901 settings
.HorDcm
= 2;
2903 settings
.HorDcm
= 1;
2904 if (settings
.TmpDcm
== 1)
2905 settings
.field_per_buff
= 2;
2907 settings
.field_per_buff
= 1;
2911 zoran_check_jpg_settings(zr
,
2913 goto sfmtjpg_unlock_and_return
;
2915 /* it's ok, so set them */
2916 fh
->jpg_settings
= settings
;
2918 /* tell the user what we actually did */
2919 fmt
->fmt
.pix
.width
=
2920 settings
.img_width
/ settings
.HorDcm
;
2921 fmt
->fmt
.pix
.height
=
2922 settings
.img_height
* 2 /
2923 (settings
.TmpDcm
* settings
.VerDcm
);
2924 if (settings
.TmpDcm
== 1)
2925 fmt
->fmt
.pix
.field
=
2927 odd_even
? V4L2_FIELD_SEQ_TB
:
2930 fmt
->fmt
.pix
.field
=
2932 odd_even
? V4L2_FIELD_TOP
:
2934 fh
->jpg_buffers
.buffer_size
=
2935 zoran_v4l2_calc_bufsize(&fh
->
2937 fmt
->fmt
.pix
.sizeimage
=
2938 fh
->jpg_buffers
.buffer_size
;
2940 /* we hereby abuse this variable to show that
2941 * we're gonna do mjpeg capture */
2944 V4L2_BUF_TYPE_VIDEO_CAPTURE
) ?
2945 ZORAN_MAP_MODE_JPG_REC
:
2946 ZORAN_MAP_MODE_JPG_PLAY
;
2947 sfmtjpg_unlock_and_return
:
2948 mutex_unlock(&zr
->resource_lock
);
2950 for (i
= 0; i
< NUM_FORMATS
; i
++)
2951 if (fmt
->fmt
.pix
.pixelformat
==
2952 zoran_formats
[i
].fourcc
)
2954 if (i
== NUM_FORMATS
) {
2957 "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x (%4.4s)\n",
2959 fmt
->fmt
.pix
.pixelformat
,
2960 (char *) &printformat
);
2963 mutex_lock(&zr
->resource_lock
);
2964 if (fh
->jpg_buffers
.allocated
||
2965 (fh
->v4l_buffers
.allocated
&&
2966 fh
->v4l_buffers
.active
!=
2970 "%s: VIDIOC_S_FMT - cannot change capture mode\n",
2973 goto sfmtv4l_unlock_and_return
;
2975 if (fmt
->fmt
.pix
.height
> BUZ_MAX_HEIGHT
)
2976 fmt
->fmt
.pix
.height
=
2978 if (fmt
->fmt
.pix
.width
> BUZ_MAX_WIDTH
)
2979 fmt
->fmt
.pix
.width
= BUZ_MAX_WIDTH
;
2982 zoran_v4l_set_format(file
,
2989 goto sfmtv4l_unlock_and_return
;
2991 /* tell the user the
2992 * results/missing stuff */
2993 fmt
->fmt
.pix
.sizeimage
=
2994 fh
->v4l_settings
.height
*
2995 fh
->v4l_settings
.bytesperline
;
2996 if (BUZ_MAX_HEIGHT
<
2997 (fh
->v4l_settings
.height
* 2))
2998 fmt
->fmt
.pix
.field
=
2999 V4L2_FIELD_INTERLACED
;
3001 fmt
->fmt
.pix
.field
=
3004 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
3005 sfmtv4l_unlock_and_return
:
3006 mutex_unlock(&zr
->resource_lock
);
3012 dprintk(3, "unsupported\n");
3015 "%s: VIDIOC_S_FMT - unsupported type %d\n",
3016 ZR_DEVNAME(zr
), fmt
->type
);
3026 struct v4l2_framebuffer
*fb
= arg
;
3028 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr
));
3030 memset(fb
, 0, sizeof(*fb
));
3031 mutex_lock(&zr
->resource_lock
);
3032 fb
->base
= zr
->buffer
.base
;
3033 fb
->fmt
.width
= zr
->buffer
.width
;
3034 fb
->fmt
.height
= zr
->buffer
.height
;
3035 if (zr
->overlay_settings
.format
) {
3036 fb
->fmt
.pixelformat
=
3037 fh
->overlay_settings
.format
->fourcc
;
3039 fb
->fmt
.bytesperline
= zr
->buffer
.bytesperline
;
3040 mutex_unlock(&zr
->resource_lock
);
3041 fb
->fmt
.colorspace
= V4L2_COLORSPACE_SRGB
;
3042 fb
->fmt
.field
= V4L2_FIELD_INTERLACED
;
3043 fb
->flags
= V4L2_FBUF_FLAG_OVERLAY
;
3044 fb
->capability
= V4L2_FBUF_CAP_LIST_CLIPPING
;
3053 struct v4l2_framebuffer
*fb
= arg
;
3054 __u32 printformat
= __cpu_to_le32(fb
->fmt
.pixelformat
);
3058 "%s: VIDIOC_S_FBUF - base=0x%p, size=%dx%d, bpl=%d, fmt=0x%x (%4.4s)\n",
3059 ZR_DEVNAME(zr
), fb
->base
, fb
->fmt
.width
, fb
->fmt
.height
,
3060 fb
->fmt
.bytesperline
, fb
->fmt
.pixelformat
,
3061 (char *) &printformat
);
3063 for (i
= 0; i
< NUM_FORMATS
; i
++)
3064 if (zoran_formats
[i
].fourcc
== fb
->fmt
.pixelformat
)
3066 if (i
== NUM_FORMATS
) {
3069 "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n",
3070 ZR_DEVNAME(zr
), fb
->fmt
.pixelformat
,
3071 (char *) &printformat
);
3075 mutex_lock(&zr
->resource_lock
);
3077 setup_fbuffer(file
, fb
->base
, &zoran_formats
[i
],
3078 fb
->fmt
.width
, fb
->fmt
.height
,
3079 fb
->fmt
.bytesperline
);
3080 mutex_unlock(&zr
->resource_lock
);
3086 case VIDIOC_OVERLAY
:
3090 dprintk(3, KERN_DEBUG
"%s: VIDIOC_PREVIEW - on=%d\n",
3091 ZR_DEVNAME(zr
), *on
);
3093 mutex_lock(&zr
->resource_lock
);
3094 res
= setup_overlay(file
, *on
);
3095 mutex_unlock(&zr
->resource_lock
);
3101 case VIDIOC_REQBUFS
:
3103 struct v4l2_requestbuffers
*req
= arg
;
3106 dprintk(3, KERN_DEBUG
"%s: VIDIOC_REQBUFS - type=%d\n",
3107 ZR_DEVNAME(zr
), req
->type
);
3109 if (req
->memory
!= V4L2_MEMORY_MMAP
) {
3112 "%s: only MEMORY_MMAP capture is supported, not %d\n",
3113 ZR_DEVNAME(zr
), req
->memory
);
3117 mutex_lock(&zr
->resource_lock
);
3119 if (fh
->v4l_buffers
.allocated
|| fh
->jpg_buffers
.allocated
) {
3122 "%s: VIDIOC_REQBUFS - buffers allready allocated\n",
3125 goto v4l2reqbuf_unlock_and_return
;
3128 if (fh
->map_mode
== ZORAN_MAP_MODE_RAW
&&
3129 req
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3131 /* control user input */
3134 if (req
->count
> v4l_nbufs
)
3135 req
->count
= v4l_nbufs
;
3136 fh
->v4l_buffers
.num_buffers
= req
->count
;
3138 if (v4l_fbuffer_alloc(file
)) {
3140 goto v4l2reqbuf_unlock_and_return
;
3143 /* The next mmap will map the V4L buffers */
3144 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
3146 } else if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
||
3147 fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
) {
3149 /* we need to calculate size ourselves now */
3152 if (req
->count
> jpg_nbufs
)
3153 req
->count
= jpg_nbufs
;
3154 fh
->jpg_buffers
.num_buffers
= req
->count
;
3155 fh
->jpg_buffers
.buffer_size
=
3156 zoran_v4l2_calc_bufsize(&fh
->jpg_settings
);
3158 if (jpg_fbuffer_alloc(file
)) {
3160 goto v4l2reqbuf_unlock_and_return
;
3163 /* The next mmap will map the MJPEG buffers */
3164 if (req
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
3165 fh
->map_mode
= ZORAN_MAP_MODE_JPG_REC
;
3167 fh
->map_mode
= ZORAN_MAP_MODE_JPG_PLAY
;
3172 "%s: VIDIOC_REQBUFS - unknown type %d\n",
3173 ZR_DEVNAME(zr
), req
->type
);
3175 goto v4l2reqbuf_unlock_and_return
;
3177 v4l2reqbuf_unlock_and_return
:
3178 mutex_unlock(&zr
->resource_lock
);
3184 case VIDIOC_QUERYBUF
:
3186 struct v4l2_buffer
*buf
= arg
;
3187 __u32 type
= buf
->type
;
3188 int index
= buf
->index
, res
;
3192 "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n",
3193 ZR_DEVNAME(zr
), buf
->index
, buf
->type
);
3195 memset(buf
, 0, sizeof(*buf
));
3199 mutex_lock(&zr
->resource_lock
);
3200 res
= zoran_v4l2_buffer_status(file
, buf
, buf
->index
);
3201 mutex_unlock(&zr
->resource_lock
);
3209 struct v4l2_buffer
*buf
= arg
;
3210 int res
= 0, codec_mode
, buf_type
;
3213 KERN_DEBUG
"%s: VIDIOC_QBUF - type=%d, index=%d\n",
3214 ZR_DEVNAME(zr
), buf
->type
, buf
->index
);
3216 mutex_lock(&zr
->resource_lock
);
3218 switch (fh
->map_mode
) {
3219 case ZORAN_MAP_MODE_RAW
:
3220 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3223 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3224 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3226 goto qbuf_unlock_and_return
;
3229 res
= zoran_v4l_queue_frame(file
, buf
->index
);
3231 goto qbuf_unlock_and_return
;
3232 if (!zr
->v4l_memgrab_active
&&
3233 fh
->v4l_buffers
.active
== ZORAN_LOCKED
)
3234 zr36057_set_memgrab(zr
, 1);
3237 case ZORAN_MAP_MODE_JPG_REC
:
3238 case ZORAN_MAP_MODE_JPG_PLAY
:
3239 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
) {
3240 buf_type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
3241 codec_mode
= BUZ_MODE_MOTION_DECOMPRESS
;
3243 buf_type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
3244 codec_mode
= BUZ_MODE_MOTION_COMPRESS
;
3247 if (buf
->type
!= buf_type
) {
3250 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3251 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3253 goto qbuf_unlock_and_return
;
3257 zoran_jpg_queue_frame(file
, buf
->index
,
3260 goto qbuf_unlock_and_return
;
3261 if (zr
->codec_mode
== BUZ_MODE_IDLE
&&
3262 fh
->jpg_buffers
.active
== ZORAN_LOCKED
) {
3263 zr36057_enable_jpg(zr
, codec_mode
);
3270 "%s: VIDIOC_QBUF - unsupported type %d\n",
3271 ZR_DEVNAME(zr
), buf
->type
);
3273 goto qbuf_unlock_and_return
;
3275 qbuf_unlock_and_return
:
3276 mutex_unlock(&zr
->resource_lock
);
3284 struct v4l2_buffer
*buf
= arg
;
3285 int res
= 0, buf_type
, num
= -1; /* compiler borks here (?) */
3287 dprintk(3, KERN_DEBUG
"%s: VIDIOC_DQBUF - type=%d\n",
3288 ZR_DEVNAME(zr
), buf
->type
);
3290 mutex_lock(&zr
->resource_lock
);
3292 switch (fh
->map_mode
) {
3293 case ZORAN_MAP_MODE_RAW
:
3294 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3297 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3298 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3300 goto dqbuf_unlock_and_return
;
3303 num
= zr
->v4l_pend
[zr
->v4l_sync_tail
& V4L_MASK_FRAME
];
3304 if (file
->f_flags
& O_NONBLOCK
&&
3305 zr
->v4l_buffers
.buffer
[num
].state
!=
3308 goto dqbuf_unlock_and_return
;
3310 res
= v4l_sync(file
, num
);
3312 goto dqbuf_unlock_and_return
;
3314 zr
->v4l_sync_tail
++;
3315 res
= zoran_v4l2_buffer_status(file
, buf
, num
);
3318 case ZORAN_MAP_MODE_JPG_REC
:
3319 case ZORAN_MAP_MODE_JPG_PLAY
:
3321 struct zoran_sync bs
;
3323 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
)
3324 buf_type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
3326 buf_type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
3328 if (buf
->type
!= buf_type
) {
3331 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3332 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3334 goto dqbuf_unlock_and_return
;
3339 jpg_que_tail
& BUZ_MASK_FRAME
];
3341 if (file
->f_flags
& O_NONBLOCK
&&
3342 zr
->jpg_buffers
.buffer
[num
].state
!=
3345 goto dqbuf_unlock_and_return
;
3347 res
= jpg_sync(file
, &bs
);
3349 goto dqbuf_unlock_and_return
;
3351 zoran_v4l2_buffer_status(file
, buf
, bs
.frame
);
3358 "%s: VIDIOC_DQBUF - unsupported type %d\n",
3359 ZR_DEVNAME(zr
), buf
->type
);
3361 goto dqbuf_unlock_and_return
;
3363 dqbuf_unlock_and_return
:
3364 mutex_unlock(&zr
->resource_lock
);
3370 case VIDIOC_STREAMON
:
3374 dprintk(3, KERN_DEBUG
"%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr
));
3376 mutex_lock(&zr
->resource_lock
);
3378 switch (fh
->map_mode
) {
3379 case ZORAN_MAP_MODE_RAW
: /* raw capture */
3380 if (zr
->v4l_buffers
.active
!= ZORAN_ACTIVE
||
3381 fh
->v4l_buffers
.active
!= ZORAN_ACTIVE
) {
3383 goto strmon_unlock_and_return
;
3386 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
3388 zr
->v4l_settings
= fh
->v4l_settings
;
3390 zr
->v4l_sync_tail
= zr
->v4l_pend_tail
;
3391 if (!zr
->v4l_memgrab_active
&&
3392 zr
->v4l_pend_head
!= zr
->v4l_pend_tail
) {
3393 zr36057_set_memgrab(zr
, 1);
3397 case ZORAN_MAP_MODE_JPG_REC
:
3398 case ZORAN_MAP_MODE_JPG_PLAY
:
3399 /* what is the codec mode right now? */
3400 if (zr
->jpg_buffers
.active
!= ZORAN_ACTIVE
||
3401 fh
->jpg_buffers
.active
!= ZORAN_ACTIVE
) {
3403 goto strmon_unlock_and_return
;
3406 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
=
3409 if (zr
->jpg_que_head
!= zr
->jpg_que_tail
) {
3410 /* Start the jpeg codec when the first frame is queued */
3418 "%s: VIDIOC_STREAMON - invalid map mode %d\n",
3419 ZR_DEVNAME(zr
), fh
->map_mode
);
3421 goto strmon_unlock_and_return
;
3423 strmon_unlock_and_return
:
3424 mutex_unlock(&zr
->resource_lock
);
3430 case VIDIOC_STREAMOFF
:
3434 dprintk(3, KERN_DEBUG
"%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr
));
3436 mutex_lock(&zr
->resource_lock
);
3438 switch (fh
->map_mode
) {
3439 case ZORAN_MAP_MODE_RAW
: /* raw capture */
3440 if (fh
->v4l_buffers
.active
== ZORAN_FREE
&&
3441 zr
->v4l_buffers
.active
!= ZORAN_FREE
) {
3442 res
= -EPERM
; /* stay off other's settings! */
3443 goto strmoff_unlock_and_return
;
3445 if (zr
->v4l_buffers
.active
== ZORAN_FREE
)
3446 goto strmoff_unlock_and_return
;
3448 /* unload capture */
3449 if (zr
->v4l_memgrab_active
) {
3452 spin_lock_irqsave(&zr
->spinlock
, flags
);
3453 zr36057_set_memgrab(zr
, 0);
3454 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
3457 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++)
3458 zr
->v4l_buffers
.buffer
[i
].state
=
3460 fh
->v4l_buffers
= zr
->v4l_buffers
;
3462 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
3465 zr
->v4l_grab_seq
= 0;
3466 zr
->v4l_pend_head
= zr
->v4l_pend_tail
= 0;
3467 zr
->v4l_sync_tail
= 0;
3471 case ZORAN_MAP_MODE_JPG_REC
:
3472 case ZORAN_MAP_MODE_JPG_PLAY
:
3473 if (fh
->jpg_buffers
.active
== ZORAN_FREE
&&
3474 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
3475 res
= -EPERM
; /* stay off other's settings! */
3476 goto strmoff_unlock_and_return
;
3478 if (zr
->jpg_buffers
.active
== ZORAN_FREE
)
3479 goto strmoff_unlock_and_return
;
3484 ZORAN_MAP_MODE_JPG_REC
) ?
3485 BUZ_MODE_MOTION_COMPRESS
:
3486 BUZ_MODE_MOTION_DECOMPRESS
);
3488 goto strmoff_unlock_and_return
;
3493 "%s: VIDIOC_STREAMOFF - invalid map mode %d\n",
3494 ZR_DEVNAME(zr
), fh
->map_mode
);
3496 goto strmoff_unlock_and_return
;
3498 strmoff_unlock_and_return
:
3499 mutex_unlock(&zr
->resource_lock
);
3505 case VIDIOC_QUERYCTRL
:
3507 struct v4l2_queryctrl
*ctrl
= arg
;
3509 dprintk(3, KERN_DEBUG
"%s: VIDIOC_QUERYCTRL - id=%d\n",
3510 ZR_DEVNAME(zr
), ctrl
->id
);
3512 /* we only support hue/saturation/contrast/brightness */
3513 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3514 ctrl
->id
> V4L2_CID_HUE
)
3518 memset(ctrl
, 0, sizeof(*ctrl
));
3523 case V4L2_CID_BRIGHTNESS
:
3524 strncpy(ctrl
->name
, "Brightness", sizeof(ctrl
->name
)-1);
3526 case V4L2_CID_CONTRAST
:
3527 strncpy(ctrl
->name
, "Contrast", sizeof(ctrl
->name
)-1);
3529 case V4L2_CID_SATURATION
:
3530 strncpy(ctrl
->name
, "Saturation", sizeof(ctrl
->name
)-1);
3533 strncpy(ctrl
->name
, "Hue", sizeof(ctrl
->name
)-1);
3538 ctrl
->maximum
= 65535;
3540 ctrl
->default_value
= 32768;
3541 ctrl
->type
= V4L2_CTRL_TYPE_INTEGER
;
3549 struct v4l2_control
*ctrl
= arg
;
3551 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_CTRL - id=%d\n",
3552 ZR_DEVNAME(zr
), ctrl
->id
);
3554 /* we only support hue/saturation/contrast/brightness */
3555 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3556 ctrl
->id
> V4L2_CID_HUE
)
3559 mutex_lock(&zr
->resource_lock
);
3561 case V4L2_CID_BRIGHTNESS
:
3562 ctrl
->value
= zr
->brightness
;
3564 case V4L2_CID_CONTRAST
:
3565 ctrl
->value
= zr
->contrast
;
3567 case V4L2_CID_SATURATION
:
3568 ctrl
->value
= zr
->saturation
;
3571 ctrl
->value
= zr
->hue
;
3574 mutex_unlock(&zr
->resource_lock
);
3582 struct v4l2_control
*ctrl
= arg
;
3583 struct video_picture pict
;
3585 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_CTRL - id=%d\n",
3586 ZR_DEVNAME(zr
), ctrl
->id
);
3588 /* we only support hue/saturation/contrast/brightness */
3589 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3590 ctrl
->id
> V4L2_CID_HUE
)
3593 if (ctrl
->value
< 0 || ctrl
->value
> 65535) {
3596 "%s: VIDIOC_S_CTRL - invalid value %d for id=%d\n",
3597 ZR_DEVNAME(zr
), ctrl
->value
, ctrl
->id
);
3601 mutex_lock(&zr
->resource_lock
);
3603 case V4L2_CID_BRIGHTNESS
:
3604 zr
->brightness
= ctrl
->value
;
3606 case V4L2_CID_CONTRAST
:
3607 zr
->contrast
= ctrl
->value
;
3609 case V4L2_CID_SATURATION
:
3610 zr
->saturation
= ctrl
->value
;
3613 zr
->hue
= ctrl
->value
;
3616 pict
.brightness
= zr
->brightness
;
3617 pict
.contrast
= zr
->contrast
;
3618 pict
.colour
= zr
->saturation
;
3621 decoder_command(zr
, DECODER_SET_PICTURE
, &pict
);
3623 mutex_unlock(&zr
->resource_lock
);
3629 case VIDIOC_ENUMSTD
:
3631 struct v4l2_standard
*std
= arg
;
3633 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMSTD - index=%d\n",
3634 ZR_DEVNAME(zr
), std
->index
);
3636 if (std
->index
< 0 || std
->index
>= (zr
->card
.norms
+ 1))
3639 int id
= std
->index
;
3640 memset(std
, 0, sizeof(*std
));
3644 if (std
->index
== zr
->card
.norms
) {
3645 /* if we have autodetect, ... */
3646 struct video_decoder_capability caps
;
3647 decoder_command(zr
, DECODER_GET_CAPABILITIES
,
3649 if (caps
.flags
& VIDEO_DECODER_AUTO
) {
3650 std
->id
= V4L2_STD_ALL
;
3651 strncpy(std
->name
, "Autodetect", sizeof(std
->name
)-1);
3656 switch (std
->index
) {
3658 std
->id
= V4L2_STD_PAL
;
3659 strncpy(std
->name
, "PAL", sizeof(std
->name
)-1);
3660 std
->frameperiod
.numerator
= 1;
3661 std
->frameperiod
.denominator
= 25;
3662 std
->framelines
= zr
->card
.tvn
[0]->Ht
;
3665 std
->id
= V4L2_STD_NTSC
;
3666 strncpy(std
->name
, "NTSC", sizeof(std
->name
)-1);
3667 std
->frameperiod
.numerator
= 1001;
3668 std
->frameperiod
.denominator
= 30000;
3669 std
->framelines
= zr
->card
.tvn
[1]->Ht
;
3672 std
->id
= V4L2_STD_SECAM
;
3673 strncpy(std
->name
, "SECAM", sizeof(std
->name
)-1);
3674 std
->frameperiod
.numerator
= 1;
3675 std
->frameperiod
.denominator
= 25;
3676 std
->framelines
= zr
->card
.tvn
[2]->Ht
;
3686 v4l2_std_id
*std
= arg
;
3689 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr
));
3691 mutex_lock(&zr
->resource_lock
);
3693 mutex_unlock(&zr
->resource_lock
);
3696 case VIDEO_MODE_PAL
:
3697 *std
= V4L2_STD_PAL
;
3699 case VIDEO_MODE_NTSC
:
3700 *std
= V4L2_STD_NTSC
;
3702 case VIDEO_MODE_SECAM
:
3703 *std
= V4L2_STD_SECAM
;
3713 int norm
= -1, res
= 0;
3714 v4l2_std_id
*std
= arg
;
3716 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_STD - norm=0x%llx\n",
3717 ZR_DEVNAME(zr
), (unsigned long long)*std
);
3719 if ((*std
& V4L2_STD_PAL
) && !(*std
& ~V4L2_STD_PAL
))
3720 norm
= VIDEO_MODE_PAL
;
3721 else if ((*std
& V4L2_STD_NTSC
) && !(*std
& ~V4L2_STD_NTSC
))
3722 norm
= VIDEO_MODE_NTSC
;
3723 else if ((*std
& V4L2_STD_SECAM
) && !(*std
& ~V4L2_STD_SECAM
))
3724 norm
= VIDEO_MODE_SECAM
;
3725 else if (*std
== V4L2_STD_ALL
)
3726 norm
= VIDEO_MODE_AUTO
;
3730 "%s: VIDIOC_S_STD - invalid norm 0x%llx\n",
3731 ZR_DEVNAME(zr
), (unsigned long long)*std
);
3735 mutex_lock(&zr
->resource_lock
);
3736 if ((res
= zoran_set_norm(zr
, norm
)))
3737 goto sstd_unlock_and_return
;
3739 res
= wait_grab_pending(zr
);
3740 sstd_unlock_and_return
:
3741 mutex_unlock(&zr
->resource_lock
);
3746 case VIDIOC_ENUMINPUT
:
3748 struct v4l2_input
*inp
= arg
;
3751 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMINPUT - index=%d\n",
3752 ZR_DEVNAME(zr
), inp
->index
);
3754 if (inp
->index
< 0 || inp
->index
>= zr
->card
.inputs
)
3757 int id
= inp
->index
;
3758 memset(inp
, 0, sizeof(*inp
));
3762 strncpy(inp
->name
, zr
->card
.input
[inp
->index
].name
,
3763 sizeof(inp
->name
) - 1);
3764 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
3765 inp
->std
= V4L2_STD_ALL
;
3767 /* Get status of video decoder */
3768 mutex_lock(&zr
->resource_lock
);
3769 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
3770 mutex_unlock(&zr
->resource_lock
);
3772 if (!(status
& DECODER_STATUS_GOOD
)) {
3773 inp
->status
|= V4L2_IN_ST_NO_POWER
;
3774 inp
->status
|= V4L2_IN_ST_NO_SIGNAL
;
3776 if (!(status
& DECODER_STATUS_COLOR
))
3777 inp
->status
|= V4L2_IN_ST_NO_COLOR
;
3783 case VIDIOC_G_INPUT
:
3787 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr
));
3789 mutex_lock(&zr
->resource_lock
);
3791 mutex_unlock(&zr
->resource_lock
);
3797 case VIDIOC_S_INPUT
:
3799 int *input
= arg
, res
= 0;
3801 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_INPUT - input=%d\n",
3802 ZR_DEVNAME(zr
), *input
);
3804 mutex_lock(&zr
->resource_lock
);
3805 if ((res
= zoran_set_input(zr
, *input
)))
3806 goto sinput_unlock_and_return
;
3808 /* Make sure the changes come into effect */
3809 res
= wait_grab_pending(zr
);
3810 sinput_unlock_and_return
:
3811 mutex_unlock(&zr
->resource_lock
);
3816 case VIDIOC_ENUMOUTPUT
:
3818 struct v4l2_output
*outp
= arg
;
3820 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMOUTPUT - index=%d\n",
3821 ZR_DEVNAME(zr
), outp
->index
);
3823 if (outp
->index
!= 0)
3826 memset(outp
, 0, sizeof(*outp
));
3828 outp
->type
= V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY
;
3829 strncpy(outp
->name
, "Autodetect", sizeof(outp
->name
)-1);
3835 case VIDIOC_G_OUTPUT
:
3839 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_OUTPUT\n", ZR_DEVNAME(zr
));
3847 case VIDIOC_S_OUTPUT
:
3851 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_OUTPUT - output=%d\n",
3852 ZR_DEVNAME(zr
), *output
);
3861 /* cropping (sub-frame capture) */
3862 case VIDIOC_CROPCAP
:
3864 struct v4l2_cropcap
*cropcap
= arg
;
3865 int type
= cropcap
->type
, res
= 0;
3867 dprintk(3, KERN_ERR
"%s: VIDIOC_CROPCAP - type=%d\n",
3868 ZR_DEVNAME(zr
), cropcap
->type
);
3870 memset(cropcap
, 0, sizeof(*cropcap
));
3871 cropcap
->type
= type
;
3873 mutex_lock(&zr
->resource_lock
);
3875 if (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3876 (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3877 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3880 "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n",
3883 goto cropcap_unlock_and_return
;
3886 cropcap
->bounds
.top
= cropcap
->bounds
.left
= 0;
3887 cropcap
->bounds
.width
= BUZ_MAX_WIDTH
;
3888 cropcap
->bounds
.height
= BUZ_MAX_HEIGHT
;
3889 cropcap
->defrect
.top
= cropcap
->defrect
.left
= 0;
3890 cropcap
->defrect
.width
= BUZ_MIN_WIDTH
;
3891 cropcap
->defrect
.height
= BUZ_MIN_HEIGHT
;
3892 cropcap_unlock_and_return
:
3893 mutex_unlock(&zr
->resource_lock
);
3900 struct v4l2_crop
*crop
= arg
;
3901 int type
= crop
->type
, res
= 0;
3903 dprintk(3, KERN_ERR
"%s: VIDIOC_G_CROP - type=%d\n",
3904 ZR_DEVNAME(zr
), crop
->type
);
3906 memset(crop
, 0, sizeof(*crop
));
3909 mutex_lock(&zr
->resource_lock
);
3911 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3912 (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3913 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3916 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
3919 goto gcrop_unlock_and_return
;
3922 crop
->c
.top
= fh
->jpg_settings
.img_y
;
3923 crop
->c
.left
= fh
->jpg_settings
.img_x
;
3924 crop
->c
.width
= fh
->jpg_settings
.img_width
;
3925 crop
->c
.height
= fh
->jpg_settings
.img_height
;
3927 gcrop_unlock_and_return
:
3928 mutex_unlock(&zr
->resource_lock
);
3936 struct v4l2_crop
*crop
= arg
;
3939 settings
= fh
->jpg_settings
;
3943 "%s: VIDIOC_S_CROP - type=%d, x=%d,y=%d,w=%d,h=%d\n",
3944 ZR_DEVNAME(zr
), crop
->type
, crop
->c
.left
, crop
->c
.top
,
3945 crop
->c
.width
, crop
->c
.height
);
3947 mutex_lock(&zr
->resource_lock
);
3949 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
3952 "%s: VIDIOC_S_CROP - cannot change settings while active\n",
3955 goto scrop_unlock_and_return
;
3958 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3959 (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3960 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3963 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
3966 goto scrop_unlock_and_return
;
3969 /* move into a form that we understand */
3970 settings
.img_x
= crop
->c
.left
;
3971 settings
.img_y
= crop
->c
.top
;
3972 settings
.img_width
= crop
->c
.width
;
3973 settings
.img_height
= crop
->c
.height
;
3975 /* check validity */
3976 if ((res
= zoran_check_jpg_settings(zr
, &settings
)))
3977 goto scrop_unlock_and_return
;
3980 fh
->jpg_settings
= settings
;
3982 scrop_unlock_and_return
:
3983 mutex_unlock(&zr
->resource_lock
);
3988 case VIDIOC_G_JPEGCOMP
:
3990 struct v4l2_jpegcompression
*params
= arg
;
3992 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_JPEGCOMP\n",
3995 memset(params
, 0, sizeof(*params
));
3997 mutex_lock(&zr
->resource_lock
);
3999 params
->quality
= fh
->jpg_settings
.jpg_comp
.quality
;
4000 params
->APPn
= fh
->jpg_settings
.jpg_comp
.APPn
;
4001 memcpy(params
->APP_data
,
4002 fh
->jpg_settings
.jpg_comp
.APP_data
,
4003 fh
->jpg_settings
.jpg_comp
.APP_len
);
4004 params
->APP_len
= fh
->jpg_settings
.jpg_comp
.APP_len
;
4005 memcpy(params
->COM_data
,
4006 fh
->jpg_settings
.jpg_comp
.COM_data
,
4007 fh
->jpg_settings
.jpg_comp
.COM_len
);
4008 params
->COM_len
= fh
->jpg_settings
.jpg_comp
.COM_len
;
4009 params
->jpeg_markers
=
4010 fh
->jpg_settings
.jpg_comp
.jpeg_markers
;
4012 mutex_unlock(&zr
->resource_lock
);
4018 case VIDIOC_S_JPEGCOMP
:
4020 struct v4l2_jpegcompression
*params
= arg
;
4023 settings
= fh
->jpg_settings
;
4027 "%s: VIDIOC_S_JPEGCOMP - quality=%d, APPN=%d, APP_len=%d, COM_len=%d\n",
4028 ZR_DEVNAME(zr
), params
->quality
, params
->APPn
,
4029 params
->APP_len
, params
->COM_len
);
4031 settings
.jpg_comp
= *params
;
4033 mutex_lock(&zr
->resource_lock
);
4035 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
||
4036 fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
4039 "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n",
4042 goto sjpegc_unlock_and_return
;
4045 if ((res
= zoran_check_jpg_settings(zr
, &settings
)))
4046 goto sjpegc_unlock_and_return
;
4047 if (!fh
->jpg_buffers
.allocated
)
4048 fh
->jpg_buffers
.buffer_size
=
4049 zoran_v4l2_calc_bufsize(&fh
->jpg_settings
);
4050 fh
->jpg_settings
.jpg_comp
= *params
= settings
.jpg_comp
;
4051 sjpegc_unlock_and_return
:
4052 mutex_unlock(&zr
->resource_lock
);
4058 case VIDIOC_QUERYSTD
: /* why is this useful? */
4060 v4l2_std_id
*std
= arg
;
4063 KERN_DEBUG
"%s: VIDIOC_QUERY_STD - std=0x%llx\n",
4064 ZR_DEVNAME(zr
), (unsigned long long)*std
);
4066 if (*std
== V4L2_STD_ALL
|| *std
== V4L2_STD_NTSC
||
4067 *std
== V4L2_STD_PAL
|| (*std
== V4L2_STD_SECAM
&&
4068 zr
->card
.norms
== 3)) {
4076 case VIDIOC_TRY_FMT
:
4078 struct v4l2_format
*fmt
= arg
;
4081 dprintk(3, KERN_DEBUG
"%s: VIDIOC_TRY_FMT - type=%d\n",
4082 ZR_DEVNAME(zr
), fmt
->type
);
4084 switch (fmt
->type
) {
4085 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
4086 mutex_lock(&zr
->resource_lock
);
4088 if (fmt
->fmt
.win
.w
.width
> BUZ_MAX_WIDTH
)
4089 fmt
->fmt
.win
.w
.width
= BUZ_MAX_WIDTH
;
4090 if (fmt
->fmt
.win
.w
.width
< BUZ_MIN_WIDTH
)
4091 fmt
->fmt
.win
.w
.width
= BUZ_MIN_WIDTH
;
4092 if (fmt
->fmt
.win
.w
.height
> BUZ_MAX_HEIGHT
)
4093 fmt
->fmt
.win
.w
.height
= BUZ_MAX_HEIGHT
;
4094 if (fmt
->fmt
.win
.w
.height
< BUZ_MIN_HEIGHT
)
4095 fmt
->fmt
.win
.w
.height
= BUZ_MIN_HEIGHT
;
4097 mutex_unlock(&zr
->resource_lock
);
4100 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
4101 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
4102 if (fmt
->fmt
.pix
.bytesperline
> 0)
4105 mutex_lock(&zr
->resource_lock
);
4107 if (fmt
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_MJPEG
) {
4108 settings
= fh
->jpg_settings
;
4110 /* we actually need to set 'real' parameters now */
4111 if ((fmt
->fmt
.pix
.height
* 2) >
4113 settings
.TmpDcm
= 1;
4115 settings
.TmpDcm
= 2;
4116 settings
.decimation
= 0;
4117 if (fmt
->fmt
.pix
.height
<=
4118 fh
->jpg_settings
.img_height
/ 2)
4119 settings
.VerDcm
= 2;
4121 settings
.VerDcm
= 1;
4122 if (fmt
->fmt
.pix
.width
<=
4123 fh
->jpg_settings
.img_width
/ 4)
4124 settings
.HorDcm
= 4;
4125 else if (fmt
->fmt
.pix
.width
<=
4126 fh
->jpg_settings
.img_width
/ 2)
4127 settings
.HorDcm
= 2;
4129 settings
.HorDcm
= 1;
4130 if (settings
.TmpDcm
== 1)
4131 settings
.field_per_buff
= 2;
4133 settings
.field_per_buff
= 1;
4137 zoran_check_jpg_settings(zr
,
4139 goto tryfmt_unlock_and_return
;
4141 /* tell the user what we actually did */
4142 fmt
->fmt
.pix
.width
=
4143 settings
.img_width
/ settings
.HorDcm
;
4144 fmt
->fmt
.pix
.height
=
4145 settings
.img_height
* 2 /
4146 (settings
.TmpDcm
* settings
.VerDcm
);
4147 if (settings
.TmpDcm
== 1)
4148 fmt
->fmt
.pix
.field
=
4150 odd_even
? V4L2_FIELD_SEQ_TB
:
4153 fmt
->fmt
.pix
.field
=
4155 odd_even
? V4L2_FIELD_TOP
:
4158 fmt
->fmt
.pix
.sizeimage
=
4159 zoran_v4l2_calc_bufsize(&settings
);
4160 } else if (fmt
->type
==
4161 V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
4164 for (i
= 0; i
< NUM_FORMATS
; i
++)
4165 if (zoran_formats
[i
].fourcc
==
4166 fmt
->fmt
.pix
.pixelformat
)
4168 if (i
== NUM_FORMATS
) {
4170 goto tryfmt_unlock_and_return
;
4173 if (fmt
->fmt
.pix
.width
> BUZ_MAX_WIDTH
)
4174 fmt
->fmt
.pix
.width
= BUZ_MAX_WIDTH
;
4175 if (fmt
->fmt
.pix
.width
< BUZ_MIN_WIDTH
)
4176 fmt
->fmt
.pix
.width
= BUZ_MIN_WIDTH
;
4177 if (fmt
->fmt
.pix
.height
> BUZ_MAX_HEIGHT
)
4178 fmt
->fmt
.pix
.height
=
4180 if (fmt
->fmt
.pix
.height
< BUZ_MIN_HEIGHT
)
4181 fmt
->fmt
.pix
.height
=
4185 goto tryfmt_unlock_and_return
;
4187 tryfmt_unlock_and_return
:
4188 mutex_unlock(&zr
->resource_lock
);
4203 dprintk(1, KERN_DEBUG
"%s: UNKNOWN ioctl cmd: 0x%x\n",
4204 ZR_DEVNAME(zr
), cmd
);
4205 return -ENOIOCTLCMD
;
4214 zoran_ioctl (struct inode
*inode
,
4219 return video_usercopy(inode
, file
, cmd
, arg
, zoran_do_ioctl
);
4223 zoran_poll (struct file
*file
,
4226 struct zoran_fh
*fh
= file
->private_data
;
4227 struct zoran
*zr
= fh
->zr
;
4229 unsigned long flags
;
4231 /* we should check whether buffers are ready to be synced on
4232 * (w/o waits - O_NONBLOCK) here
4233 * if ready for read (sync), return POLLIN|POLLRDNORM,
4234 * if ready for write (sync), return POLLOUT|POLLWRNORM,
4235 * if error, return POLLERR,
4236 * if no buffers queued or so, return POLLNVAL
4239 mutex_lock(&zr
->resource_lock
);
4241 switch (fh
->map_mode
) {
4242 case ZORAN_MAP_MODE_RAW
:
4243 poll_wait(file
, &zr
->v4l_capq
, wait
);
4244 frame
= zr
->v4l_pend
[zr
->v4l_sync_tail
& V4L_MASK_FRAME
];
4246 spin_lock_irqsave(&zr
->spinlock
, flags
);
4249 "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n",
4250 ZR_DEVNAME(zr
), __FUNCTION__
,
4251 "FAL"[fh
->v4l_buffers
.active
], zr
->v4l_sync_tail
,
4252 "UPMD"[zr
->v4l_buffers
.buffer
[frame
].state
],
4253 zr
->v4l_pend_tail
, zr
->v4l_pend_head
);
4254 /* Process is the one capturing? */
4255 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
&&
4256 /* Buffer ready to DQBUF? */
4257 zr
->v4l_buffers
.buffer
[frame
].state
== BUZ_STATE_DONE
)
4258 res
= POLLIN
| POLLRDNORM
;
4259 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4263 case ZORAN_MAP_MODE_JPG_REC
:
4264 case ZORAN_MAP_MODE_JPG_PLAY
:
4265 poll_wait(file
, &zr
->jpg_capq
, wait
);
4266 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
& BUZ_MASK_FRAME
];
4268 spin_lock_irqsave(&zr
->spinlock
, flags
);
4271 "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n",
4272 ZR_DEVNAME(zr
), __FUNCTION__
,
4273 "FAL"[fh
->jpg_buffers
.active
], zr
->jpg_que_tail
,
4274 "UPMD"[zr
->jpg_buffers
.buffer
[frame
].state
],
4275 zr
->jpg_que_head
, zr
->jpg_dma_tail
, zr
->jpg_dma_head
);
4276 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
&&
4277 zr
->jpg_buffers
.buffer
[frame
].state
== BUZ_STATE_DONE
) {
4278 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
)
4279 res
= POLLIN
| POLLRDNORM
;
4281 res
= POLLOUT
| POLLWRNORM
;
4283 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4290 "%s: zoran_poll() - internal error, unknown map_mode=%d\n",
4291 ZR_DEVNAME(zr
), fh
->map_mode
);
4295 mutex_unlock(&zr
->resource_lock
);
4302 * This maps the buffers to user space.
4304 * Depending on the state of fh->map_mode
4305 * the V4L or the MJPEG buffers are mapped
4306 * per buffer or all together
4308 * Note that we need to connect to some
4309 * unmap signal event to unmap the de-allocate
4310 * the buffer accordingly (zoran_vm_close())
4314 zoran_vm_open (struct vm_area_struct
*vma
)
4316 struct zoran_mapping
*map
= vma
->vm_private_data
;
4322 zoran_vm_close (struct vm_area_struct
*vma
)
4324 struct zoran_mapping
*map
= vma
->vm_private_data
;
4325 struct file
*file
= map
->file
;
4326 struct zoran_fh
*fh
= file
->private_data
;
4327 struct zoran
*zr
= fh
->zr
;
4331 if (map
->count
== 0) {
4332 switch (fh
->map_mode
) {
4333 case ZORAN_MAP_MODE_JPG_REC
:
4334 case ZORAN_MAP_MODE_JPG_PLAY
:
4336 dprintk(3, KERN_INFO
"%s: munmap(MJPEG)\n",
4339 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
4340 if (fh
->jpg_buffers
.buffer
[i
].map
== map
) {
4341 fh
->jpg_buffers
.buffer
[i
].map
=
4347 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++)
4348 if (fh
->jpg_buffers
.buffer
[i
].map
)
4350 if (i
== fh
->jpg_buffers
.num_buffers
) {
4351 mutex_lock(&zr
->resource_lock
);
4353 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
4354 jpg_qbuf(file
, -1, zr
->codec_mode
);
4355 zr
->jpg_buffers
.allocated
= 0;
4356 zr
->jpg_buffers
.active
=
4357 fh
->jpg_buffers
.active
=
4360 //jpg_fbuffer_free(file);
4361 fh
->jpg_buffers
.allocated
= 0;
4362 fh
->jpg_buffers
.ready_to_be_freed
= 1;
4364 mutex_unlock(&zr
->resource_lock
);
4369 case ZORAN_MAP_MODE_RAW
:
4371 dprintk(3, KERN_INFO
"%s: munmap(V4L)\n",
4374 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++) {
4375 if (fh
->v4l_buffers
.buffer
[i
].map
== map
) {
4377 fh
->v4l_buffers
.buffer
[i
].map
=
4383 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++)
4384 if (fh
->v4l_buffers
.buffer
[i
].map
)
4386 if (i
== fh
->v4l_buffers
.num_buffers
) {
4387 mutex_lock(&zr
->resource_lock
);
4389 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
) {
4392 spin_lock_irqsave(&zr
->spinlock
, flags
);
4393 zr36057_set_memgrab(zr
, 0);
4394 zr
->v4l_buffers
.allocated
= 0;
4395 zr
->v4l_buffers
.active
=
4396 fh
->v4l_buffers
.active
=
4398 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4400 //v4l_fbuffer_free(file);
4401 fh
->v4l_buffers
.allocated
= 0;
4402 fh
->v4l_buffers
.ready_to_be_freed
= 1;
4404 mutex_unlock(&zr
->resource_lock
);
4411 "%s: munmap() - internal error - unknown map mode %d\n",
4412 ZR_DEVNAME(zr
), fh
->map_mode
);
4419 static struct vm_operations_struct zoran_vm_ops
= {
4420 .open
= zoran_vm_open
,
4421 .close
= zoran_vm_close
,
4425 zoran_mmap (struct file
*file
,
4426 struct vm_area_struct
*vma
)
4428 struct zoran_fh
*fh
= file
->private_data
;
4429 struct zoran
*zr
= fh
->zr
;
4430 unsigned long size
= (vma
->vm_end
- vma
->vm_start
);
4431 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
4433 unsigned long page
, start
= vma
->vm_start
, todo
, pos
, fraglen
;
4435 struct zoran_mapping
*map
;
4439 KERN_INFO
"%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n",
4441 fh
->map_mode
== ZORAN_MAP_MODE_RAW
? "V4L" : "MJPEG",
4442 vma
->vm_start
, vma
->vm_end
, size
);
4444 if (!(vma
->vm_flags
& VM_SHARED
) || !(vma
->vm_flags
& VM_READ
) ||
4445 !(vma
->vm_flags
& VM_WRITE
)) {
4448 "%s: mmap() - no MAP_SHARED/PROT_{READ,WRITE} given\n",
4453 switch (fh
->map_mode
) {
4455 case ZORAN_MAP_MODE_JPG_REC
:
4456 case ZORAN_MAP_MODE_JPG_PLAY
:
4459 mutex_lock(&zr
->resource_lock
);
4461 /* Map the MJPEG buffers */
4462 if (!fh
->jpg_buffers
.allocated
) {
4465 "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n",
4468 goto jpg_mmap_unlock_and_return
;
4471 first
= offset
/ fh
->jpg_buffers
.buffer_size
;
4472 last
= first
- 1 + size
/ fh
->jpg_buffers
.buffer_size
;
4473 if (offset
% fh
->jpg_buffers
.buffer_size
!= 0 ||
4474 size
% fh
->jpg_buffers
.buffer_size
!= 0 || first
< 0 ||
4475 last
< 0 || first
>= fh
->jpg_buffers
.num_buffers
||
4476 last
>= fh
->jpg_buffers
.num_buffers
) {
4479 "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
4480 ZR_DEVNAME(zr
), offset
, size
,
4481 fh
->jpg_buffers
.buffer_size
,
4482 fh
->jpg_buffers
.num_buffers
);
4484 goto jpg_mmap_unlock_and_return
;
4486 for (i
= first
; i
<= last
; i
++) {
4487 if (fh
->jpg_buffers
.buffer
[i
].map
) {
4490 "%s: mmap(MJPEG) - buffer %d already mapped\n",
4493 goto jpg_mmap_unlock_and_return
;
4497 /* map these buffers (v4l_buffers[i]) */
4498 map
= kmalloc(sizeof(struct zoran_mapping
), GFP_KERNEL
);
4501 goto jpg_mmap_unlock_and_return
;
4506 vma
->vm_ops
= &zoran_vm_ops
;
4507 vma
->vm_flags
|= VM_DONTEXPAND
;
4508 vma
->vm_private_data
= map
;
4510 for (i
= first
; i
<= last
; i
++) {
4512 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
4515 (le32_to_cpu(fh
->jpg_buffers
.buffer
[i
].
4516 frag_tab
[2 * j
+ 1]) & ~1) << 1;
4521 le32_to_cpu((unsigned long) fh
->jpg_buffers
.
4522 buffer
[i
].frag_tab
[2 * j
]);
4523 /* should just be pos on i386 */
4524 page
= virt_to_phys(bus_to_virt(pos
))
4526 if (remap_pfn_range(vma
, start
, page
,
4527 todo
, PAGE_SHARED
)) {
4530 "%s: zoran_mmap(V4L) - remap_pfn_range failed\n",
4533 goto jpg_mmap_unlock_and_return
;
4539 if (le32_to_cpu(fh
->jpg_buffers
.buffer
[i
].
4540 frag_tab
[2 * j
+ 1]) & 1)
4541 break; /* was last fragment */
4543 fh
->jpg_buffers
.buffer
[i
].map
= map
;
4548 jpg_mmap_unlock_and_return
:
4549 mutex_unlock(&zr
->resource_lock
);
4553 case ZORAN_MAP_MODE_RAW
:
4555 mutex_lock(&zr
->resource_lock
);
4557 /* Map the V4L buffers */
4558 if (!fh
->v4l_buffers
.allocated
) {
4561 "%s: zoran_mmap(V4L) - buffers not yet allocated\n",
4564 goto v4l_mmap_unlock_and_return
;
4567 first
= offset
/ fh
->v4l_buffers
.buffer_size
;
4568 last
= first
- 1 + size
/ fh
->v4l_buffers
.buffer_size
;
4569 if (offset
% fh
->v4l_buffers
.buffer_size
!= 0 ||
4570 size
% fh
->v4l_buffers
.buffer_size
!= 0 || first
< 0 ||
4571 last
< 0 || first
>= fh
->v4l_buffers
.num_buffers
||
4572 last
>= fh
->v4l_buffers
.buffer_size
) {
4575 "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
4576 ZR_DEVNAME(zr
), offset
, size
,
4577 fh
->v4l_buffers
.buffer_size
,
4578 fh
->v4l_buffers
.num_buffers
);
4580 goto v4l_mmap_unlock_and_return
;
4582 for (i
= first
; i
<= last
; i
++) {
4583 if (fh
->v4l_buffers
.buffer
[i
].map
) {
4586 "%s: mmap(V4L) - buffer %d already mapped\n",
4589 goto v4l_mmap_unlock_and_return
;
4593 /* map these buffers (v4l_buffers[i]) */
4594 map
= kmalloc(sizeof(struct zoran_mapping
), GFP_KERNEL
);
4597 goto v4l_mmap_unlock_and_return
;
4602 vma
->vm_ops
= &zoran_vm_ops
;
4603 vma
->vm_flags
|= VM_DONTEXPAND
;
4604 vma
->vm_private_data
= map
;
4606 for (i
= first
; i
<= last
; i
++) {
4608 if (todo
> fh
->v4l_buffers
.buffer_size
)
4609 todo
= fh
->v4l_buffers
.buffer_size
;
4610 page
= fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
;
4611 if (remap_pfn_range(vma
, start
, page
>> PAGE_SHIFT
,
4612 todo
, PAGE_SHARED
)) {
4615 "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n",
4618 goto v4l_mmap_unlock_and_return
;
4622 fh
->v4l_buffers
.buffer
[i
].map
= map
;
4626 v4l_mmap_unlock_and_return
:
4627 mutex_unlock(&zr
->resource_lock
);
4634 "%s: zoran_mmap() - internal error - unknown map mode %d\n",
4635 ZR_DEVNAME(zr
), fh
->map_mode
);
4642 static const struct file_operations zoran_fops
= {
4643 .owner
= THIS_MODULE
,
4645 .release
= zoran_close
,
4646 .ioctl
= zoran_ioctl
,
4647 .compat_ioctl
= v4l_compat_ioctl32
,
4648 .llseek
= no_llseek
,
4650 .write
= zoran_write
,
4655 struct video_device zoran_template __devinitdata
= {
4657 .type
= ZORAN_VID_TYPE
,
4658 #ifdef CONFIG_VIDEO_V4L2
4659 .type2
= ZORAN_V4L2_VID_FLAGS
,
4661 .fops
= &zoran_fops
,
4662 .release
= &zoran_vdev_release
,