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_HARDWARE VID_HARDWARE_ZR36067
64 #define ZORAN_VID_TYPE ( \
70 VID_TYPE_MJPEG_DECODER | \
71 VID_TYPE_MJPEG_ENCODER \
74 #include <linux/videodev.h>
75 #include <media/v4l2-common.h>
76 #include "videocodec.h"
79 #include <asm/uaccess.h>
80 #include <linux/proc_fs.h>
82 #include <linux/video_decoder.h>
83 #include <linux/video_encoder.h>
84 #include <linux/mutex.h>
86 #include "zoran_device.h"
87 #include "zoran_card.h"
89 #ifdef CONFIG_VIDEO_V4L2
90 /* we declare some card type definitions here, they mean
91 * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */
92 #define ZORAN_V4L2_VID_FLAGS ( \
94 V4L2_CAP_VIDEO_CAPTURE |\
95 V4L2_CAP_VIDEO_OUTPUT |\
96 V4L2_CAP_VIDEO_OVERLAY \
100 #include <asm/byteorder.h>
102 #if defined(CONFIG_VIDEO_V4L2) && defined(CONFIG_VIDEO_V4L1_COMPAT)
103 #define ZFMT(pal, fcc, cs) \
104 .palette = (pal), .fourcc = (fcc), .colorspace = (cs)
105 #elif defined(CONFIG_VIDEO_V4L2)
106 #define ZFMT(pal, fcc, cs) \
107 .fourcc = (fcc), .colorspace = (cs)
109 #define ZFMT(pal, fcc, cs) \
113 const struct zoran_format zoran_formats
[] = {
115 .name
= "15-bit RGB LE",
116 ZFMT(VIDEO_PALETTE_RGB555
,
117 V4L2_PIX_FMT_RGB555
, V4L2_COLORSPACE_SRGB
),
119 .flags
= ZORAN_FORMAT_CAPTURE
|
120 ZORAN_FORMAT_OVERLAY
,
121 .vfespfr
= ZR36057_VFESPFR_RGB555
|ZR36057_VFESPFR_ErrDif
|
122 ZR36057_VFESPFR_LittleEndian
,
124 .name
= "15-bit RGB BE",
126 V4L2_PIX_FMT_RGB555X
, V4L2_COLORSPACE_SRGB
),
128 .flags
= ZORAN_FORMAT_CAPTURE
|
129 ZORAN_FORMAT_OVERLAY
,
130 .vfespfr
= ZR36057_VFESPFR_RGB555
|ZR36057_VFESPFR_ErrDif
,
132 .name
= "16-bit RGB LE",
133 ZFMT(VIDEO_PALETTE_RGB565
,
134 V4L2_PIX_FMT_RGB565
, V4L2_COLORSPACE_SRGB
),
136 .flags
= ZORAN_FORMAT_CAPTURE
|
137 ZORAN_FORMAT_OVERLAY
,
138 .vfespfr
= ZR36057_VFESPFR_RGB565
|ZR36057_VFESPFR_ErrDif
|
139 ZR36057_VFESPFR_LittleEndian
,
141 .name
= "16-bit RGB BE",
143 V4L2_PIX_FMT_RGB565
, V4L2_COLORSPACE_SRGB
),
145 .flags
= ZORAN_FORMAT_CAPTURE
|
146 ZORAN_FORMAT_OVERLAY
,
147 .vfespfr
= ZR36057_VFESPFR_RGB565
|ZR36057_VFESPFR_ErrDif
,
149 .name
= "24-bit RGB",
150 ZFMT(VIDEO_PALETTE_RGB24
,
151 V4L2_PIX_FMT_BGR24
, V4L2_COLORSPACE_SRGB
),
153 .flags
= ZORAN_FORMAT_CAPTURE
|
154 ZORAN_FORMAT_OVERLAY
,
155 .vfespfr
= ZR36057_VFESPFR_RGB888
|ZR36057_VFESPFR_Pack24
,
157 .name
= "32-bit RGB LE",
158 ZFMT(VIDEO_PALETTE_RGB32
,
159 V4L2_PIX_FMT_BGR32
, V4L2_COLORSPACE_SRGB
),
161 .flags
= ZORAN_FORMAT_CAPTURE
|
162 ZORAN_FORMAT_OVERLAY
,
163 .vfespfr
= ZR36057_VFESPFR_RGB888
|ZR36057_VFESPFR_LittleEndian
,
165 .name
= "32-bit RGB BE",
167 V4L2_PIX_FMT_RGB32
, V4L2_COLORSPACE_SRGB
),
169 .flags
= ZORAN_FORMAT_CAPTURE
|
170 ZORAN_FORMAT_OVERLAY
,
171 .vfespfr
= ZR36057_VFESPFR_RGB888
,
173 .name
= "4:2:2, packed, YUYV",
174 ZFMT(VIDEO_PALETTE_YUV422
,
175 V4L2_PIX_FMT_YUYV
, V4L2_COLORSPACE_SMPTE170M
),
177 .flags
= ZORAN_FORMAT_CAPTURE
|
178 ZORAN_FORMAT_OVERLAY
,
179 .vfespfr
= ZR36057_VFESPFR_YUV422
,
181 .name
= "4:2:2, packed, UYVY",
182 ZFMT(VIDEO_PALETTE_UYVY
,
183 V4L2_PIX_FMT_UYVY
, V4L2_COLORSPACE_SMPTE170M
),
185 .flags
= ZORAN_FORMAT_CAPTURE
|
186 ZORAN_FORMAT_OVERLAY
,
187 .vfespfr
= ZR36057_VFESPFR_YUV422
|ZR36057_VFESPFR_LittleEndian
,
189 .name
= "Hardware-encoded Motion-JPEG",
191 V4L2_PIX_FMT_MJPEG
, V4L2_COLORSPACE_SMPTE170M
),
193 .flags
= ZORAN_FORMAT_CAPTURE
|
194 ZORAN_FORMAT_PLAYBACK
|
195 ZORAN_FORMAT_COMPRESSED
,
198 #define NUM_FORMATS ARRAY_SIZE(zoran_formats)
200 // RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined
203 extern int v4l_nbufs
;
204 extern int v4l_bufsize
;
205 extern int jpg_nbufs
;
206 extern int jpg_bufsize
;
207 extern int pass_through
;
209 static int lock_norm
= 0; /* 1=Don't change TV standard (norm) */
210 module_param(lock_norm
, int, 0644);
211 MODULE_PARM_DESC(lock_norm
, "Prevent norm changes (1 = ignore, >1 = fail)");
213 #ifdef CONFIG_VIDEO_V4L2
214 /* small helper function for calculating buffersizes for v4l2
215 * we calculate the nearest higher power-of-two, which
216 * will be the recommended buffersize */
218 zoran_v4l2_calc_bufsize (struct zoran_jpg_settings
*settings
)
220 __u8 div
= settings
->VerDcm
* settings
->HorDcm
* settings
->TmpDcm
;
221 __u32 num
= (1024 * 512) / (div
);
230 if (result
> jpg_bufsize
)
238 /* forward references */
239 static void v4l_fbuffer_free(struct file
*file
);
240 static void jpg_fbuffer_free(struct file
*file
);
243 * Allocate the V4L grab buffers
245 * These have to be pysically contiguous.
246 * If v4l_bufsize <= MAX_KMALLOC_MEM we use kmalloc
247 * else we try to allocate them with bigphysarea_alloc_pages
248 * if the bigphysarea patch is present in the kernel,
249 * else we try to use high memory (if the user has bootet
250 * Linux with the necessary memory left over).
254 get_high_mem (unsigned long size
)
257 * Check if there is usable memory at the end of Linux memory
258 * of at least size. Return the physical address of this memory,
259 * return 0 on failure.
261 * The idea is from Alexandro Rubini's book "Linux device drivers".
262 * The driver from him which is downloadable from O'Reilly's
263 * web site misses the "virt_to_phys(high_memory)" part
264 * (and therefore doesn't work at all - at least with 2.2.x kernels).
266 * It should be unnecessary to mention that THIS IS DANGEROUS,
267 * if more than one driver at a time has the idea to use this memory!!!!
270 volatile unsigned char __iomem
*mem
;
272 unsigned long hi_mem_ph
;
275 /* Map the high memory to user space */
277 hi_mem_ph
= virt_to_phys(high_memory
);
279 mem
= ioremap(hi_mem_ph
, size
);
282 KERN_ERR
"%s: get_high_mem() - ioremap failed\n",
287 for (i
= 0; i
< size
; i
++) {
288 /* Check if it is memory */
291 if (readb(mem
+ i
) != c
)
295 if (readb(mem
+ i
) != c
)
297 writeb(0, mem
+ i
); /* zero out memory */
299 /* give the kernel air to breath */
300 if ((i
& 0x3ffff) == 0x3ffff)
309 "%s: get_high_mem() - requested %lu, avail %lu\n",
310 ZORAN_NAME
, size
, i
);
318 v4l_fbuffer_alloc (struct file
*file
)
320 struct zoran_fh
*fh
= file
->private_data
;
321 struct zoran
*zr
= fh
->zr
;
324 unsigned long pmem
= 0;
326 /* we might have old buffers lying around... */
327 if (fh
->v4l_buffers
.ready_to_be_freed
) {
328 v4l_fbuffer_free(file
);
331 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++) {
332 if (fh
->v4l_buffers
.buffer
[i
].fbuffer
)
335 "%s: v4l_fbuffer_alloc() - buffer %d allready allocated!?\n",
339 if (fh
->v4l_buffers
.buffer_size
<= MAX_KMALLOC_MEM
) {
343 (unsigned char *) kmalloc(fh
->v4l_buffers
.
349 "%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n",
351 v4l_fbuffer_free(file
);
354 fh
->v4l_buffers
.buffer
[i
].fbuffer
= mem
;
355 fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
=
357 fh
->v4l_buffers
.buffer
[i
].fbuffer_bus
=
359 for (off
= 0; off
< fh
->v4l_buffers
.buffer_size
;
361 SetPageReserved(MAP_NR(mem
+ off
));
364 "%s: v4l_fbuffer_alloc() - V4L frame %d mem 0x%lx (bus: 0x%lx)\n",
365 ZR_DEVNAME(zr
), i
, (unsigned long) mem
,
369 /* Use high memory which has been left at boot time */
371 /* Ok., Ok. this is an evil hack - we make
372 * the assumption that physical addresses are
373 * the same as bus addresses (true at least
374 * for Intel processors). The whole method of
375 * obtaining and using this memory is not very
376 * nice - but I hope it saves some poor users
377 * from kernel hacking, which might have even
378 * more evil results */
382 fh
->v4l_buffers
.num_buffers
*
383 fh
->v4l_buffers
.buffer_size
;
385 pmem
= get_high_mem(size
);
389 "%s: v4l_fbuffer_alloc() - get_high_mem (size = %d KB) for V4L bufs failed\n",
390 ZR_DEVNAME(zr
), size
>> 10);
393 fh
->v4l_buffers
.buffer
[0].fbuffer
= NULL
;
394 fh
->v4l_buffers
.buffer
[0].fbuffer_phys
= pmem
;
395 fh
->v4l_buffers
.buffer
[0].fbuffer_bus
= pmem
;
398 "%s: v4l_fbuffer_alloc() - using %d KB high memory\n",
399 ZR_DEVNAME(zr
), size
>> 10);
401 fh
->v4l_buffers
.buffer
[i
].fbuffer
= NULL
;
402 fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
=
403 pmem
+ i
* fh
->v4l_buffers
.buffer_size
;
404 fh
->v4l_buffers
.buffer
[i
].fbuffer_bus
=
405 pmem
+ i
* fh
->v4l_buffers
.buffer_size
;
410 fh
->v4l_buffers
.allocated
= 1;
415 /* free the V4L grab buffers */
417 v4l_fbuffer_free (struct file
*file
)
419 struct zoran_fh
*fh
= file
->private_data
;
420 struct zoran
*zr
= fh
->zr
;
424 dprintk(4, KERN_INFO
"%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr
));
426 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++) {
427 if (!fh
->v4l_buffers
.buffer
[i
].fbuffer
)
430 if (fh
->v4l_buffers
.buffer_size
<= MAX_KMALLOC_MEM
) {
431 mem
= fh
->v4l_buffers
.buffer
[i
].fbuffer
;
432 for (off
= 0; off
< fh
->v4l_buffers
.buffer_size
;
434 ClearPageReserved(MAP_NR(mem
+ off
));
435 kfree((void *) fh
->v4l_buffers
.buffer
[i
].fbuffer
);
437 fh
->v4l_buffers
.buffer
[i
].fbuffer
= NULL
;
440 fh
->v4l_buffers
.allocated
= 0;
441 fh
->v4l_buffers
.ready_to_be_freed
= 0;
445 * Allocate the MJPEG grab buffers.
447 * If the requested buffer size is smaller than MAX_KMALLOC_MEM,
448 * kmalloc is used to request a physically contiguous area,
449 * else we allocate the memory in framgents with get_zeroed_page.
451 * If a Natoma chipset is present and this is a revision 1 zr36057,
452 * each MJPEG buffer needs to be physically contiguous.
453 * (RJ: This statement is from Dave Perks' original driver,
454 * I could never check it because I have a zr36067)
455 * The driver cares about this because it reduces the buffer
456 * size to MAX_KMALLOC_MEM in that case (which forces contiguous allocation).
458 * RJ: The contents grab buffers needs never be accessed in the driver.
459 * Therefore there is no need to allocate them with vmalloc in order
460 * to get a contiguous virtual memory space.
461 * I don't understand why many other drivers first allocate them with
462 * vmalloc (which uses internally also get_zeroed_page, but delivers you
463 * virtual addresses) and then again have to make a lot of efforts
464 * to get the physical address.
467 * On big-endian architectures (such as ppc) some extra steps
468 * are needed. When reading and writing to the stat_com array
469 * and fragment buffers, the device expects to see little-
470 * endian values. The use of cpu_to_le32() and le32_to_cpu()
471 * in this function (and one or two others in zoran_device.c)
472 * ensure that these values are always stored in little-endian
473 * form, regardless of architecture. The zr36057 does Very Bad
474 * Things on big endian architectures if the stat_com array
475 * and fragment buffers are not little-endian.
479 jpg_fbuffer_alloc (struct file
*file
)
481 struct zoran_fh
*fh
= file
->private_data
;
482 struct zoran
*zr
= fh
->zr
;
486 /* we might have old buffers lying around */
487 if (fh
->jpg_buffers
.ready_to_be_freed
) {
488 jpg_fbuffer_free(file
);
491 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
492 if (fh
->jpg_buffers
.buffer
[i
].frag_tab
)
495 "%s: jpg_fbuffer_alloc() - buffer %d allready allocated!?\n",
498 /* Allocate fragment table for this buffer */
500 mem
= get_zeroed_page(GFP_KERNEL
);
504 "%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n",
506 jpg_fbuffer_free(file
);
509 fh
->jpg_buffers
.buffer
[i
].frag_tab
= (u32
*) mem
;
510 fh
->jpg_buffers
.buffer
[i
].frag_tab_bus
=
511 virt_to_bus((void *) mem
);
513 //if (alloc_contig) {
514 if (fh
->jpg_buffers
.need_contiguous
) {
516 (unsigned long) kmalloc(fh
->jpg_buffers
.
522 "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n",
524 jpg_fbuffer_free(file
);
527 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0] =
528 cpu_to_le32(virt_to_bus((void *) mem
));
529 fh
->jpg_buffers
.buffer
[i
].frag_tab
[1] =
530 cpu_to_le32(((fh
->jpg_buffers
.buffer_size
/ 4) << 1) | 1);
531 for (off
= 0; off
< fh
->jpg_buffers
.buffer_size
;
533 SetPageReserved(MAP_NR(mem
+ off
));
535 /* jpg_bufsize is allreay page aligned */
537 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
539 mem
= get_zeroed_page(GFP_KERNEL
);
543 "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n",
545 jpg_fbuffer_free(file
);
549 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
] =
550 cpu_to_le32(virt_to_bus((void *) mem
));
551 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
+
553 cpu_to_le32((PAGE_SIZE
/ 4) << 1);
554 SetPageReserved(MAP_NR(mem
));
557 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
- 1] |= cpu_to_le32(1);
562 KERN_DEBUG
"%s: jpg_fbuffer_alloc() - %d KB allocated\n",
564 (fh
->jpg_buffers
.num_buffers
*
565 fh
->jpg_buffers
.buffer_size
) >> 10);
567 fh
->jpg_buffers
.allocated
= 1;
572 /* free the MJPEG grab buffers */
574 jpg_fbuffer_free (struct file
*file
)
576 struct zoran_fh
*fh
= file
->private_data
;
577 struct zoran
*zr
= fh
->zr
;
581 dprintk(4, KERN_DEBUG
"%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr
));
583 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
584 if (!fh
->jpg_buffers
.buffer
[i
].frag_tab
)
587 //if (alloc_contig) {
588 if (fh
->jpg_buffers
.need_contiguous
) {
589 if (fh
->jpg_buffers
.buffer
[i
].frag_tab
[0]) {
590 mem
= (unsigned char *) bus_to_virt(le32_to_cpu(
591 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0]));
593 off
< fh
->jpg_buffers
.buffer_size
;
595 ClearPageReserved(MAP_NR
598 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0] = 0;
599 fh
->jpg_buffers
.buffer
[i
].frag_tab
[1] = 0;
603 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
605 if (!fh
->jpg_buffers
.buffer
[i
].
608 ClearPageReserved(MAP_NR
612 buffer
[i
].frag_tab
[2 *
614 free_page((unsigned long)
620 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
] =
622 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
+
627 free_page((unsigned long) fh
->jpg_buffers
.buffer
[i
].
629 fh
->jpg_buffers
.buffer
[i
].frag_tab
= NULL
;
632 fh
->jpg_buffers
.allocated
= 0;
633 fh
->jpg_buffers
.ready_to_be_freed
= 0;
637 * V4L Buffer grabbing
641 zoran_v4l_set_format (struct file
*file
,
644 const struct zoran_format
*format
)
646 struct zoran_fh
*fh
= file
->private_data
;
647 struct zoran
*zr
= fh
->zr
;
650 /* Check size and format of the grab wanted */
652 if (height
< BUZ_MIN_HEIGHT
|| width
< BUZ_MIN_WIDTH
||
653 height
> BUZ_MAX_HEIGHT
|| width
> BUZ_MAX_WIDTH
) {
656 "%s: v4l_set_format() - wrong frame size (%dx%d)\n",
657 ZR_DEVNAME(zr
), width
, height
);
661 bpp
= (format
->depth
+ 7) / 8;
663 /* Check against available buffer size */
664 if (height
* width
* bpp
> fh
->v4l_buffers
.buffer_size
) {
667 "%s: v4l_set_format() - video buffer size (%d kB) is too small\n",
668 ZR_DEVNAME(zr
), fh
->v4l_buffers
.buffer_size
>> 10);
672 /* The video front end needs 4-byte alinged line sizes */
674 if ((bpp
== 2 && (width
& 1)) || (bpp
== 3 && (width
& 3))) {
677 "%s: v4l_set_format() - wrong frame alingment\n",
682 fh
->v4l_settings
.width
= width
;
683 fh
->v4l_settings
.height
= height
;
684 fh
->v4l_settings
.format
= format
;
685 fh
->v4l_settings
.bytesperline
= bpp
* fh
->v4l_settings
.width
;
691 zoran_v4l_queue_frame (struct file
*file
,
694 struct zoran_fh
*fh
= file
->private_data
;
695 struct zoran
*zr
= fh
->zr
;
699 if (!fh
->v4l_buffers
.allocated
) {
702 "%s: v4l_queue_frame() - buffers not yet allocated\n",
707 /* No grabbing outside the buffer range! */
708 if (num
>= fh
->v4l_buffers
.num_buffers
|| num
< 0) {
711 "%s: v4l_queue_frame() - buffer %d is out of range\n",
712 ZR_DEVNAME(zr
), num
);
716 spin_lock_irqsave(&zr
->spinlock
, flags
);
718 if (fh
->v4l_buffers
.active
== ZORAN_FREE
) {
719 if (zr
->v4l_buffers
.active
== ZORAN_FREE
) {
720 zr
->v4l_buffers
= fh
->v4l_buffers
;
721 fh
->v4l_buffers
.active
= ZORAN_ACTIVE
;
725 "%s: v4l_queue_frame() - another session is already capturing\n",
731 /* make sure a grab isn't going on currently with this buffer */
733 switch (zr
->v4l_buffers
.buffer
[num
].state
) {
736 if (zr
->v4l_buffers
.active
== ZORAN_FREE
) {
737 fh
->v4l_buffers
.active
= ZORAN_FREE
;
738 zr
->v4l_buffers
.allocated
= 0;
740 res
= -EBUSY
; /* what are you doing? */
745 "%s: v4l_queue_frame() - queueing buffer %d in state DONE!?\n",
746 ZR_DEVNAME(zr
), num
);
748 /* since there is at least one unused buffer there's room for at least
749 * one more pend[] entry */
750 zr
->v4l_pend
[zr
->v4l_pend_head
++ &
751 V4L_MASK_FRAME
] = num
;
752 zr
->v4l_buffers
.buffer
[num
].state
= BUZ_STATE_PEND
;
753 zr
->v4l_buffers
.buffer
[num
].bs
.length
=
754 fh
->v4l_settings
.bytesperline
*
755 zr
->v4l_settings
.height
;
756 fh
->v4l_buffers
.buffer
[num
] =
757 zr
->v4l_buffers
.buffer
[num
];
762 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
764 if (!res
&& zr
->v4l_buffers
.active
== ZORAN_FREE
)
765 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
;
771 v4l_grab (struct file
*file
,
772 struct video_mmap
*mp
)
774 struct zoran_fh
*fh
= file
->private_data
;
775 struct zoran
*zr
= fh
->zr
;
778 for (i
= 0; i
< NUM_FORMATS
; i
++) {
779 if (zoran_formats
[i
].palette
== mp
->format
&&
780 zoran_formats
[i
].flags
& ZORAN_FORMAT_CAPTURE
&&
781 !(zoran_formats
[i
].flags
& ZORAN_FORMAT_COMPRESSED
))
784 if (i
== NUM_FORMATS
|| zoran_formats
[i
].depth
== 0) {
787 "%s: v4l_grab() - wrong bytes-per-pixel format\n",
793 * To minimize the time spent in the IRQ routine, we avoid setting up
794 * the video front end there.
795 * If this grab has different parameters from a running streaming capture
796 * we stop the streaming capture and start it over again.
798 if (zr
->v4l_memgrab_active
&&
799 (zr
->v4l_settings
.width
!= mp
->width
||
800 zr
->v4l_settings
.height
!= mp
->height
||
801 zr
->v4l_settings
.format
->palette
!= mp
->format
)) {
802 res
= wait_grab_pending(zr
);
806 if ((res
= zoran_v4l_set_format(file
,
811 zr
->v4l_settings
= fh
->v4l_settings
;
813 /* queue the frame in the pending queue */
814 if ((res
= zoran_v4l_queue_frame(file
, mp
->frame
))) {
815 fh
->v4l_buffers
.active
= ZORAN_FREE
;
819 /* put the 36057 into frame grabbing mode */
820 if (!res
&& !zr
->v4l_memgrab_active
)
821 zr36057_set_memgrab(zr
, 1);
823 //dprintk(4, KERN_INFO "%s: Frame grab 3...\n", ZR_DEVNAME(zr));
829 * Sync on a V4L buffer
833 v4l_sync (struct file
*file
,
836 struct zoran_fh
*fh
= file
->private_data
;
837 struct zoran
*zr
= fh
->zr
;
840 if (fh
->v4l_buffers
.active
== ZORAN_FREE
) {
843 "%s: v4l_sync() - no grab active for this session\n",
848 /* check passed-in frame number */
849 if (frame
>= fh
->v4l_buffers
.num_buffers
|| frame
< 0) {
851 KERN_ERR
"%s: v4l_sync() - frame %d is invalid\n",
852 ZR_DEVNAME(zr
), frame
);
856 /* Check if is buffer was queued at all */
857 if (zr
->v4l_buffers
.buffer
[frame
].state
== BUZ_STATE_USER
) {
860 "%s: v4l_sync() - attempt to sync on a buffer which was not queued?\n",
865 /* wait on this buffer to get ready */
866 if (!wait_event_interruptible_timeout(zr
->v4l_capq
,
867 (zr
->v4l_buffers
.buffer
[frame
].state
!= BUZ_STATE_PEND
),
870 if (signal_pending(current
))
873 /* buffer should now be in BUZ_STATE_DONE */
874 if (zr
->v4l_buffers
.buffer
[frame
].state
!= BUZ_STATE_DONE
)
876 KERN_ERR
"%s: v4l_sync() - internal state error\n",
879 zr
->v4l_buffers
.buffer
[frame
].state
= BUZ_STATE_USER
;
880 fh
->v4l_buffers
.buffer
[frame
] = zr
->v4l_buffers
.buffer
[frame
];
882 spin_lock_irqsave(&zr
->spinlock
, flags
);
884 /* Check if streaming capture has finished */
885 if (zr
->v4l_pend_tail
== zr
->v4l_pend_head
) {
886 zr36057_set_memgrab(zr
, 0);
887 if (zr
->v4l_buffers
.active
== ZORAN_ACTIVE
) {
888 fh
->v4l_buffers
.active
= zr
->v4l_buffers
.active
=
890 zr
->v4l_buffers
.allocated
= 0;
894 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
900 * Queue a MJPEG buffer for capture/playback
904 zoran_jpg_queue_frame (struct file
*file
,
906 enum zoran_codec_mode mode
)
908 struct zoran_fh
*fh
= file
->private_data
;
909 struct zoran
*zr
= fh
->zr
;
913 /* Check if buffers are allocated */
914 if (!fh
->jpg_buffers
.allocated
) {
917 "%s: jpg_queue_frame() - buffers not yet allocated\n",
922 /* No grabbing outside the buffer range! */
923 if (num
>= fh
->jpg_buffers
.num_buffers
|| num
< 0) {
926 "%s: jpg_queue_frame() - buffer %d out of range\n",
927 ZR_DEVNAME(zr
), num
);
931 /* what is the codec mode right now? */
932 if (zr
->codec_mode
== BUZ_MODE_IDLE
) {
933 zr
->jpg_settings
= fh
->jpg_settings
;
934 } else if (zr
->codec_mode
!= mode
) {
935 /* wrong codec mode active - invalid */
938 "%s: jpg_queue_frame() - codec in wrong mode\n",
943 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
944 if (zr
->jpg_buffers
.active
== ZORAN_FREE
) {
945 zr
->jpg_buffers
= fh
->jpg_buffers
;
946 fh
->jpg_buffers
.active
= ZORAN_ACTIVE
;
950 "%s: jpg_queue_frame() - another session is already capturing\n",
956 if (!res
&& zr
->codec_mode
== BUZ_MODE_IDLE
) {
957 /* Ok load up the jpeg codec */
958 zr36057_enable_jpg(zr
, mode
);
961 spin_lock_irqsave(&zr
->spinlock
, flags
);
964 switch (zr
->jpg_buffers
.buffer
[num
].state
) {
968 "%s: jpg_queue_frame() - queing frame in BUZ_STATE_DONE state!?\n",
971 /* since there is at least one unused buffer there's room for at
972 *least one more pend[] entry */
973 zr
->jpg_pend
[zr
->jpg_que_head
++ & BUZ_MASK_FRAME
] =
975 zr
->jpg_buffers
.buffer
[num
].state
= BUZ_STATE_PEND
;
976 fh
->jpg_buffers
.buffer
[num
] =
977 zr
->jpg_buffers
.buffer
[num
];
978 zoran_feed_stat_com(zr
);
983 if (zr
->jpg_buffers
.active
== ZORAN_FREE
) {
984 fh
->jpg_buffers
.active
= ZORAN_FREE
;
985 zr
->jpg_buffers
.allocated
= 0;
987 res
= -EBUSY
; /* what are you doing? */
992 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
994 if (!res
&& zr
->jpg_buffers
.active
== ZORAN_FREE
) {
995 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
;
1002 jpg_qbuf (struct file
*file
,
1004 enum zoran_codec_mode mode
)
1006 struct zoran_fh
*fh
= file
->private_data
;
1007 struct zoran
*zr
= fh
->zr
;
1010 /* Does the user want to stop streaming? */
1012 if (zr
->codec_mode
== mode
) {
1013 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
1016 "%s: jpg_qbuf(-1) - session not active\n",
1020 fh
->jpg_buffers
.active
= zr
->jpg_buffers
.active
=
1022 zr
->jpg_buffers
.allocated
= 0;
1023 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1028 "%s: jpg_qbuf() - stop streaming but not in streaming mode\n",
1034 if ((res
= zoran_jpg_queue_frame(file
, frame
, mode
)))
1037 /* Start the jpeg codec when the first frame is queued */
1038 if (!res
&& zr
->jpg_que_head
== 1)
1045 * Sync on a MJPEG buffer
1049 jpg_sync (struct file
*file
,
1050 struct zoran_sync
*bs
)
1052 struct zoran_fh
*fh
= file
->private_data
;
1053 struct zoran
*zr
= fh
->zr
;
1054 unsigned long flags
;
1057 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
1060 "%s: jpg_sync() - capture is not currently active\n",
1064 if (zr
->codec_mode
!= BUZ_MODE_MOTION_DECOMPRESS
&&
1065 zr
->codec_mode
!= BUZ_MODE_MOTION_COMPRESS
) {
1068 "%s: jpg_sync() - codec not in streaming mode\n",
1072 if (!wait_event_interruptible_timeout(zr
->jpg_capq
,
1073 (zr
->jpg_que_tail
!= zr
->jpg_dma_tail
||
1074 zr
->jpg_dma_tail
== zr
->jpg_dma_head
),
1078 btand(~ZR36057_JMC_Go_en
, ZR36057_JMC
);
1080 zr
->codec
->control(zr
->codec
, CODEC_G_STATUS
,
1084 "%s: jpg_sync() - timeout: codec isr=0x%02x\n",
1085 ZR_DEVNAME(zr
), isr
);
1090 if (signal_pending(current
))
1091 return -ERESTARTSYS
;
1093 spin_lock_irqsave(&zr
->spinlock
, flags
);
1095 if (zr
->jpg_dma_tail
!= zr
->jpg_dma_head
)
1096 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
++ & BUZ_MASK_FRAME
];
1098 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
& BUZ_MASK_FRAME
];
1100 /* buffer should now be in BUZ_STATE_DONE */
1101 if (zr
->jpg_buffers
.buffer
[frame
].state
!= BUZ_STATE_DONE
)
1103 KERN_ERR
"%s: jpg_sync() - internal state error\n",
1106 *bs
= zr
->jpg_buffers
.buffer
[frame
].bs
;
1108 zr
->jpg_buffers
.buffer
[frame
].state
= BUZ_STATE_USER
;
1109 fh
->jpg_buffers
.buffer
[frame
] = zr
->jpg_buffers
.buffer
[frame
];
1111 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1117 zoran_open_init_session (struct file
*file
)
1120 struct zoran_fh
*fh
= file
->private_data
;
1121 struct zoran
*zr
= fh
->zr
;
1123 /* Per default, map the V4L Buffers */
1124 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
1126 /* take over the card's current settings */
1127 fh
->overlay_settings
= zr
->overlay_settings
;
1128 fh
->overlay_settings
.is_set
= 0;
1129 fh
->overlay_settings
.format
= zr
->overlay_settings
.format
;
1130 fh
->overlay_active
= ZORAN_FREE
;
1133 fh
->v4l_settings
= zr
->v4l_settings
;
1136 memset(&fh
->v4l_buffers
, 0, sizeof(struct zoran_v4l_struct
));
1137 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
1138 fh
->v4l_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
1139 fh
->v4l_buffers
.buffer
[i
].bs
.frame
= i
;
1141 fh
->v4l_buffers
.allocated
= 0;
1142 fh
->v4l_buffers
.ready_to_be_freed
= 0;
1143 fh
->v4l_buffers
.active
= ZORAN_FREE
;
1144 fh
->v4l_buffers
.buffer_size
= v4l_bufsize
;
1145 fh
->v4l_buffers
.num_buffers
= v4l_nbufs
;
1148 fh
->jpg_settings
= zr
->jpg_settings
;
1151 memset(&fh
->jpg_buffers
, 0, sizeof(struct zoran_jpg_struct
));
1152 for (i
= 0; i
< BUZ_MAX_FRAME
; i
++) {
1153 fh
->jpg_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
1154 fh
->jpg_buffers
.buffer
[i
].bs
.frame
= i
;
1156 fh
->jpg_buffers
.need_contiguous
= zr
->jpg_buffers
.need_contiguous
;
1157 fh
->jpg_buffers
.allocated
= 0;
1158 fh
->jpg_buffers
.ready_to_be_freed
= 0;
1159 fh
->jpg_buffers
.active
= ZORAN_FREE
;
1160 fh
->jpg_buffers
.buffer_size
= jpg_bufsize
;
1161 fh
->jpg_buffers
.num_buffers
= jpg_nbufs
;
1165 zoran_close_end_session (struct file
*file
)
1167 struct zoran_fh
*fh
= file
->private_data
;
1168 struct zoran
*zr
= fh
->zr
;
1171 if (fh
->overlay_active
!= ZORAN_FREE
) {
1172 fh
->overlay_active
= zr
->overlay_active
= ZORAN_FREE
;
1173 zr
->v4l_overlay_active
= 0;
1174 if (!zr
->v4l_memgrab_active
)
1175 zr36057_overlay(zr
, 0);
1176 zr
->overlay_mask
= NULL
;
1180 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
) {
1183 spin_lock_irqsave(&zr
->spinlock
, flags
);
1184 zr36057_set_memgrab(zr
, 0);
1185 zr
->v4l_buffers
.allocated
= 0;
1186 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
1188 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1192 if (fh
->v4l_buffers
.allocated
||
1193 fh
->v4l_buffers
.ready_to_be_freed
) {
1194 v4l_fbuffer_free(file
);
1198 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
1199 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1200 zr
->jpg_buffers
.allocated
= 0;
1201 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
=
1206 if (fh
->jpg_buffers
.allocated
||
1207 fh
->jpg_buffers
.ready_to_be_freed
) {
1208 jpg_fbuffer_free(file
);
1213 * Open a zoran card. Right now the flags stuff is just playing
1217 zoran_open (struct inode
*inode
,
1220 unsigned int minor
= iminor(inode
);
1221 struct zoran
*zr
= NULL
;
1222 struct zoran_fh
*fh
;
1223 int i
, res
, first_open
= 0, have_module_locks
= 0;
1225 /* find the device */
1226 for (i
= 0; i
< zoran_num
; i
++) {
1227 if (zoran
[i
].video_dev
->minor
== minor
) {
1234 dprintk(1, KERN_ERR
"%s: device not found!\n", ZORAN_NAME
);
1236 goto open_unlock_and_return
;
1239 /* see fs/device.c - the kernel already locks during open(),
1240 * so locking ourselves only causes deadlocks */
1241 /*mutex_lock(&zr->resource_lock);*/
1245 KERN_ERR
"%s: no TV decoder loaded for device!\n",
1248 goto open_unlock_and_return
;
1251 /* try to grab a module lock */
1252 if (!try_module_get(THIS_MODULE
)) {
1255 "%s: failed to acquire my own lock! PANIC!\n",
1258 goto open_unlock_and_return
;
1260 if (!try_module_get(zr
->decoder
->driver
->driver
.owner
)) {
1263 "%s: failed to grab ownership of i2c decoder\n",
1266 module_put(THIS_MODULE
);
1267 goto open_unlock_and_return
;
1270 !try_module_get(zr
->encoder
->driver
->driver
.owner
)) {
1273 "%s: failed to grab ownership of i2c encoder\n",
1276 module_put(zr
->decoder
->driver
->driver
.owner
);
1277 module_put(THIS_MODULE
);
1278 goto open_unlock_and_return
;
1281 have_module_locks
= 1;
1283 if (zr
->user
>= 2048) {
1284 dprintk(1, KERN_ERR
"%s: too many users (%d) on device\n",
1285 ZR_DEVNAME(zr
), zr
->user
);
1287 goto open_unlock_and_return
;
1290 dprintk(1, KERN_INFO
"%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
1291 ZR_DEVNAME(zr
), current
->comm
, current
->pid
, zr
->user
);
1293 /* now, create the open()-specific file_ops struct */
1294 fh
= kzalloc(sizeof(struct zoran_fh
), GFP_KERNEL
);
1298 "%s: zoran_open() - allocation of zoran_fh failed\n",
1301 goto open_unlock_and_return
;
1303 /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
1304 * on norm-change! */
1306 kmalloc(((768 + 31) / 32) * 576 * 4, GFP_KERNEL
);
1307 if (!fh
->overlay_mask
) {
1310 "%s: zoran_open() - allocation of overlay_mask failed\n",
1314 goto open_unlock_and_return
;
1317 if (zr
->user
++ == 0)
1320 /*mutex_unlock(&zr->resource_lock);*/
1322 /* default setup - TODO: look at flags */
1323 if (first_open
) { /* First device open */
1324 zr36057_restart(zr
);
1325 zoran_open_init_params(zr
);
1326 zoran_init_hardware(zr
);
1328 btor(ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1331 /* set file_ops stuff */
1332 file
->private_data
= fh
;
1334 zoran_open_init_session(file
);
1338 open_unlock_and_return
:
1339 /* if we grabbed locks, release them accordingly */
1340 if (have_module_locks
) {
1341 module_put(zr
->decoder
->driver
->driver
.owner
);
1343 module_put(zr
->encoder
->driver
->driver
.owner
);
1345 module_put(THIS_MODULE
);
1348 /* if there's no device found, we didn't obtain the lock either */
1350 /*mutex_unlock(&zr->resource_lock);*/
1357 zoran_close (struct inode
*inode
,
1360 struct zoran_fh
*fh
= file
->private_data
;
1361 struct zoran
*zr
= fh
->zr
;
1363 dprintk(1, KERN_INFO
"%s: zoran_close(%s, pid=[%d]), users(+)=%d\n",
1364 ZR_DEVNAME(zr
), current
->comm
, current
->pid
, zr
->user
);
1366 /* kernel locks (fs/device.c), so don't do that ourselves
1367 * (prevents deadlocks) */
1368 /*mutex_lock(&zr->resource_lock);*/
1370 zoran_close_end_session(file
);
1372 if (zr
->user
-- == 1) { /* Last process */
1373 /* Clean up JPEG process */
1374 wake_up_interruptible(&zr
->jpg_capq
);
1375 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1376 zr
->jpg_buffers
.allocated
= 0;
1377 zr
->jpg_buffers
.active
= ZORAN_FREE
;
1379 /* disable interrupts */
1380 btand(~ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1382 if (zr36067_debug
> 1)
1383 print_interrupts(zr
);
1386 zr
->v4l_overlay_active
= 0;
1387 zr36057_overlay(zr
, 0);
1388 zr
->overlay_mask
= NULL
;
1391 wake_up_interruptible(&zr
->v4l_capq
);
1392 zr36057_set_memgrab(zr
, 0);
1393 zr
->v4l_buffers
.allocated
= 0;
1394 zr
->v4l_buffers
.active
= ZORAN_FREE
;
1395 zoran_set_pci_master(zr
, 0);
1397 if (!pass_through
) { /* Switch to color bar */
1398 int zero
= 0, two
= 2;
1399 decoder_command(zr
, DECODER_ENABLE_OUTPUT
, &zero
);
1400 encoder_command(zr
, ENCODER_SET_INPUT
, &two
);
1404 file
->private_data
= NULL
;
1405 kfree(fh
->overlay_mask
);
1408 /* release locks on the i2c modules */
1409 module_put(zr
->decoder
->driver
->driver
.owner
);
1411 module_put(zr
->encoder
->driver
->driver
.owner
);
1413 module_put(THIS_MODULE
);
1415 /*mutex_unlock(&zr->resource_lock);*/
1417 dprintk(4, KERN_INFO
"%s: zoran_close() done\n", ZR_DEVNAME(zr
));
1424 zoran_read (struct file
*file
,
1429 /* we simply don't support read() (yet)... */
1435 zoran_write (struct file
*file
,
1436 const char __user
*data
,
1440 /* ...and the same goes for write() */
1446 setup_fbuffer (struct file
*file
,
1448 const struct zoran_format
*fmt
,
1453 struct zoran_fh
*fh
= file
->private_data
;
1454 struct zoran
*zr
= fh
->zr
;
1456 /* (Ronald) v4l/v4l2 guidelines */
1457 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
1460 /* Don't allow frame buffer overlay if PCI or AGP is buggy, or on
1461 ALi Magik (that needs very low latency while the card needs a
1462 higher value always) */
1464 if (pci_pci_problems
& (PCIPCI_FAIL
| PCIAGP_FAIL
| PCIPCI_ALIMAGIK
))
1467 /* we need a bytesperline value, even if not given */
1469 bytesperline
= width
* ((fmt
->depth
+ 7) & ~7) / 8;
1472 if (zr
->overlay_active
) {
1473 /* dzjee... stupid users... don't even bother to turn off
1474 * overlay before changing the memory location...
1475 * normally, we would return errors here. However, one of
1476 * the tools that does this is... xawtv! and since xawtv
1477 * is used by +/- 99% of the users, we'd rather be user-
1478 * friendly and silently do as if nothing went wrong */
1481 "%s: setup_fbuffer() - forced overlay turnoff because framebuffer changed\n",
1483 zr36057_overlay(zr
, 0);
1487 if (!(fmt
->flags
& ZORAN_FORMAT_OVERLAY
)) {
1490 "%s: setup_fbuffer() - no valid overlay format given\n",
1494 if (height
<= 0 || width
<= 0 || bytesperline
<= 0) {
1497 "%s: setup_fbuffer() - invalid height/width/bpl value (%d|%d|%d)\n",
1498 ZR_DEVNAME(zr
), width
, height
, bytesperline
);
1501 if (bytesperline
& 3) {
1504 "%s: setup_fbuffer() - bytesperline (%d) must be 4-byte aligned\n",
1505 ZR_DEVNAME(zr
), bytesperline
);
1509 zr
->buffer
.base
= (void *) ((unsigned long) base
& ~3);
1510 zr
->buffer
.height
= height
;
1511 zr
->buffer
.width
= width
;
1512 zr
->buffer
.depth
= fmt
->depth
;
1513 zr
->overlay_settings
.format
= fmt
;
1514 zr
->buffer
.bytesperline
= bytesperline
;
1516 /* The user should set new window parameters */
1517 zr
->overlay_settings
.is_set
= 0;
1524 setup_window (struct file
*file
,
1529 struct video_clip __user
*clips
,
1531 void __user
*bitmap
)
1533 struct zoran_fh
*fh
= file
->private_data
;
1534 struct zoran
*zr
= fh
->zr
;
1535 struct video_clip
*vcp
= NULL
;
1539 if (!zr
->buffer
.base
) {
1542 "%s: setup_window() - frame buffer has to be set first\n",
1547 if (!fh
->overlay_settings
.format
) {
1550 "%s: setup_window() - no overlay format set\n",
1556 * The video front end needs 4-byte alinged line sizes, we correct that
1557 * silently here if necessary
1559 if (zr
->buffer
.depth
== 15 || zr
->buffer
.depth
== 16) {
1560 end
= (x
+ width
) & ~1; /* round down */
1561 x
= (x
+ 1) & ~1; /* round up */
1565 if (zr
->buffer
.depth
== 24) {
1566 end
= (x
+ width
) & ~3; /* round down */
1567 x
= (x
+ 3) & ~3; /* round up */
1571 if (width
> BUZ_MAX_WIDTH
)
1572 width
= BUZ_MAX_WIDTH
;
1573 if (height
> BUZ_MAX_HEIGHT
)
1574 height
= BUZ_MAX_HEIGHT
;
1576 /* Check for vaild parameters */
1577 if (width
< BUZ_MIN_WIDTH
|| height
< BUZ_MIN_HEIGHT
||
1578 width
> BUZ_MAX_WIDTH
|| height
> BUZ_MAX_HEIGHT
) {
1581 "%s: setup_window() - width = %d or height = %d invalid\n",
1582 ZR_DEVNAME(zr
), width
, height
);
1586 fh
->overlay_settings
.x
= x
;
1587 fh
->overlay_settings
.y
= y
;
1588 fh
->overlay_settings
.width
= width
;
1589 fh
->overlay_settings
.height
= height
;
1590 fh
->overlay_settings
.clipcount
= clipcount
;
1593 * If an overlay is running, we have to switch it off
1594 * and switch it on again in order to get the new settings in effect.
1596 * We also want to avoid that the overlay mask is written
1597 * when an overlay is running.
1600 on
= zr
->v4l_overlay_active
&& !zr
->v4l_memgrab_active
&&
1601 zr
->overlay_active
!= ZORAN_FREE
&&
1602 fh
->overlay_active
!= ZORAN_FREE
;
1604 zr36057_overlay(zr
, 0);
1607 * Write the overlay mask if clips are wanted.
1608 * We prefer a bitmap.
1611 /* fake value - it just means we want clips */
1612 fh
->overlay_settings
.clipcount
= 1;
1614 if (copy_from_user(fh
->overlay_mask
, bitmap
,
1615 (width
* height
+ 7) / 8)) {
1618 } else if (clipcount
> 0) {
1619 /* write our own bitmap from the clips */
1620 vcp
= vmalloc(sizeof(struct video_clip
) * (clipcount
+ 4));
1624 "%s: setup_window() - Alloc of clip mask failed\n",
1629 (vcp
, clips
, sizeof(struct video_clip
) * clipcount
)) {
1633 write_overlay_mask(file
, vcp
, clipcount
);
1637 fh
->overlay_settings
.is_set
= 1;
1638 if (fh
->overlay_active
!= ZORAN_FREE
&&
1639 zr
->overlay_active
!= ZORAN_FREE
)
1640 zr
->overlay_settings
= fh
->overlay_settings
;
1643 zr36057_overlay(zr
, 1);
1645 /* Make sure the changes come into effect */
1646 return wait_grab_pending(zr
);
1650 setup_overlay (struct file
*file
,
1653 struct zoran_fh
*fh
= file
->private_data
;
1654 struct zoran
*zr
= fh
->zr
;
1656 /* If there is nothing to do, return immediatly */
1657 if ((on
&& fh
->overlay_active
!= ZORAN_FREE
) ||
1658 (!on
&& fh
->overlay_active
== ZORAN_FREE
))
1661 /* check whether we're touching someone else's overlay */
1662 if (on
&& zr
->overlay_active
!= ZORAN_FREE
&&
1663 fh
->overlay_active
== ZORAN_FREE
) {
1666 "%s: setup_overlay() - overlay is already active for another session\n",
1670 if (!on
&& zr
->overlay_active
!= ZORAN_FREE
&&
1671 fh
->overlay_active
== ZORAN_FREE
) {
1674 "%s: setup_overlay() - you cannot cancel someone else's session\n",
1680 zr
->overlay_active
= fh
->overlay_active
= ZORAN_FREE
;
1681 zr
->v4l_overlay_active
= 0;
1682 /* When a grab is running, the video simply
1683 * won't be switched on any more */
1684 if (!zr
->v4l_memgrab_active
)
1685 zr36057_overlay(zr
, 0);
1686 zr
->overlay_mask
= NULL
;
1688 if (!zr
->buffer
.base
|| !fh
->overlay_settings
.is_set
) {
1691 "%s: setup_overlay() - buffer or window not set\n",
1695 if (!fh
->overlay_settings
.format
) {
1698 "%s: setup_overlay() - no overlay format set\n",
1702 zr
->overlay_active
= fh
->overlay_active
= ZORAN_LOCKED
;
1703 zr
->v4l_overlay_active
= 1;
1704 zr
->overlay_mask
= fh
->overlay_mask
;
1705 zr
->overlay_settings
= fh
->overlay_settings
;
1706 if (!zr
->v4l_memgrab_active
)
1707 zr36057_overlay(zr
, 1);
1708 /* When a grab is running, the video will be
1709 * switched on when grab is finished */
1712 /* Make sure the changes come into effect */
1713 return wait_grab_pending(zr
);
1716 #ifdef CONFIG_VIDEO_V4L2
1717 /* get the status of a buffer in the clients buffer queue */
1719 zoran_v4l2_buffer_status (struct file
*file
,
1720 struct v4l2_buffer
*buf
,
1723 struct zoran_fh
*fh
= file
->private_data
;
1724 struct zoran
*zr
= fh
->zr
;
1726 buf
->flags
= V4L2_BUF_FLAG_MAPPED
;
1728 switch (fh
->map_mode
) {
1729 case ZORAN_MAP_MODE_RAW
:
1732 if (num
< 0 || num
>= fh
->v4l_buffers
.num_buffers
||
1733 !fh
->v4l_buffers
.allocated
) {
1736 "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
1741 buf
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1742 buf
->length
= fh
->v4l_buffers
.buffer_size
;
1745 buf
->bytesused
= fh
->v4l_buffers
.buffer
[num
].bs
.length
;
1746 if (fh
->v4l_buffers
.buffer
[num
].state
== BUZ_STATE_DONE
||
1747 fh
->v4l_buffers
.buffer
[num
].state
== BUZ_STATE_USER
) {
1748 buf
->sequence
= fh
->v4l_buffers
.buffer
[num
].bs
.seq
;
1749 buf
->flags
|= V4L2_BUF_FLAG_DONE
;
1751 fh
->v4l_buffers
.buffer
[num
].bs
.timestamp
;
1753 buf
->flags
|= V4L2_BUF_FLAG_QUEUED
;
1756 if (fh
->v4l_settings
.height
<= BUZ_MAX_HEIGHT
/ 2)
1757 buf
->field
= V4L2_FIELD_TOP
;
1759 buf
->field
= V4L2_FIELD_INTERLACED
;
1763 case ZORAN_MAP_MODE_JPG_REC
:
1764 case ZORAN_MAP_MODE_JPG_PLAY
:
1767 if (num
< 0 || num
>= fh
->jpg_buffers
.num_buffers
||
1768 !fh
->jpg_buffers
.allocated
) {
1771 "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
1776 buf
->type
= (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
) ?
1777 V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1778 V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1779 buf
->length
= fh
->jpg_buffers
.buffer_size
;
1781 /* these variables are only written after frame has been captured */
1782 if (fh
->jpg_buffers
.buffer
[num
].state
== BUZ_STATE_DONE
||
1783 fh
->jpg_buffers
.buffer
[num
].state
== BUZ_STATE_USER
) {
1784 buf
->sequence
= fh
->jpg_buffers
.buffer
[num
].bs
.seq
;
1786 fh
->jpg_buffers
.buffer
[num
].bs
.timestamp
;
1788 fh
->jpg_buffers
.buffer
[num
].bs
.length
;
1789 buf
->flags
|= V4L2_BUF_FLAG_DONE
;
1791 buf
->flags
|= V4L2_BUF_FLAG_QUEUED
;
1794 /* which fields are these? */
1795 if (fh
->jpg_settings
.TmpDcm
!= 1)
1798 odd_even
? V4L2_FIELD_TOP
: V4L2_FIELD_BOTTOM
;
1802 odd_even
? V4L2_FIELD_SEQ_TB
:
1811 "%s: v4l2_buffer_status() - invalid buffer type|map_mode (%d|%d)\n",
1812 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
1816 buf
->memory
= V4L2_MEMORY_MMAP
;
1818 buf
->m
.offset
= buf
->length
* num
;
1825 zoran_set_norm (struct zoran
*zr
,
1826 int norm
) /* VIDEO_MODE_* */
1828 int norm_encoder
, on
;
1830 if (zr
->v4l_buffers
.active
!= ZORAN_FREE
||
1831 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
1834 "%s: set_norm() called while in playback/capture mode\n",
1839 if (lock_norm
&& norm
!= zr
->norm
) {
1840 if (lock_norm
> 1) {
1843 "%s: set_norm() - TV standard is locked, can not switch norm\n",
1849 "%s: set_norm() - TV standard is locked, norm was not changed\n",
1855 if (norm
!= VIDEO_MODE_AUTO
&&
1856 (norm
< 0 || norm
>= zr
->card
.norms
||
1857 !zr
->card
.tvn
[norm
])) {
1859 KERN_ERR
"%s: set_norm() - unsupported norm %d\n",
1860 ZR_DEVNAME(zr
), norm
);
1864 if (norm
== VIDEO_MODE_AUTO
) {
1867 /* if we have autodetect, ... */
1868 struct video_decoder_capability caps
;
1869 decoder_command(zr
, DECODER_GET_CAPABILITIES
, &caps
);
1870 if (!(caps
.flags
& VIDEO_DECODER_AUTO
)) {
1871 dprintk(1, KERN_ERR
"%s: norm=auto unsupported\n",
1876 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
1878 /* let changes come into effect */
1881 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
1882 if (!(status
& DECODER_STATUS_GOOD
)) {
1885 "%s: set_norm() - no norm detected\n",
1888 decoder_command(zr
, DECODER_SET_NORM
, &zr
->norm
);
1892 if (status
& DECODER_STATUS_NTSC
)
1893 norm
= VIDEO_MODE_NTSC
;
1894 else if (status
& DECODER_STATUS_SECAM
)
1895 norm
= VIDEO_MODE_SECAM
;
1897 norm
= VIDEO_MODE_PAL
;
1899 zr
->timing
= zr
->card
.tvn
[norm
];
1900 norm_encoder
= norm
;
1902 /* We switch overlay off and on since a change in the
1903 * norm needs different VFE settings */
1904 on
= zr
->overlay_active
&& !zr
->v4l_memgrab_active
;
1906 zr36057_overlay(zr
, 0);
1908 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
1909 encoder_command(zr
, ENCODER_SET_NORM
, &norm_encoder
);
1912 zr36057_overlay(zr
, 1);
1914 /* Make sure the changes come into effect */
1921 zoran_set_input (struct zoran
*zr
,
1926 if (input
== zr
->input
) {
1930 if (zr
->v4l_buffers
.active
!= ZORAN_FREE
||
1931 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
1934 "%s: set_input() called while in playback/capture mode\n",
1939 if (input
< 0 || input
>= zr
->card
.inputs
) {
1942 "%s: set_input() - unnsupported input %d\n",
1943 ZR_DEVNAME(zr
), input
);
1947 realinput
= zr
->card
.input
[input
].muxsel
;
1950 decoder_command(zr
, DECODER_SET_INPUT
, &realinput
);
1960 zoran_do_ioctl (struct inode
*inode
,
1965 struct zoran_fh
*fh
= file
->private_data
;
1966 struct zoran
*zr
= fh
->zr
;
1967 /* CAREFUL: used in multiple places here */
1968 struct zoran_jpg_settings settings
;
1970 /* we might have older buffers lying around... We don't want
1971 * to wait, but we do want to try cleaning them up ASAP. So
1972 * we try to obtain the lock and free them. If that fails, we
1973 * don't do anything and wait for the next turn. In the end,
1974 * zoran_close() or a new allocation will still free them...
1975 * This is just a 'the sooner the better' extra 'feature'
1977 * We don't free the buffers right on munmap() because that
1978 * causes oopses (kfree() inside munmap() oopses for no
1979 * apparent reason - it's also not reproduceable in any way,
1980 * but moving the free code outside the munmap() handler fixes
1981 * all this... If someone knows why, please explain me (Ronald)
1983 if (mutex_trylock(&zr
->resource_lock
)) {
1984 /* we obtained it! Let's try to free some things */
1985 if (fh
->jpg_buffers
.ready_to_be_freed
)
1986 jpg_fbuffer_free(file
);
1987 if (fh
->v4l_buffers
.ready_to_be_freed
)
1988 v4l_fbuffer_free(file
);
1990 mutex_unlock(&zr
->resource_lock
);
1997 struct video_capability
*vcap
= arg
;
1999 dprintk(3, KERN_DEBUG
"%s: VIDIOCGCAP\n", ZR_DEVNAME(zr
));
2001 memset(vcap
, 0, sizeof(struct video_capability
));
2002 strncpy(vcap
->name
, ZR_DEVNAME(zr
), sizeof(vcap
->name
)-1);
2003 vcap
->type
= ZORAN_VID_TYPE
;
2005 vcap
->channels
= zr
->card
.inputs
;
2007 mutex_lock(&zr
->resource_lock
);
2008 vcap
->maxwidth
= BUZ_MAX_WIDTH
;
2009 vcap
->maxheight
= BUZ_MAX_HEIGHT
;
2010 vcap
->minwidth
= BUZ_MIN_WIDTH
;
2011 vcap
->minheight
= BUZ_MIN_HEIGHT
;
2012 mutex_unlock(&zr
->resource_lock
);
2020 struct video_channel
*vchan
= arg
;
2021 int channel
= vchan
->channel
;
2023 dprintk(3, KERN_DEBUG
"%s: VIDIOCGCHAN - channel=%d\n",
2024 ZR_DEVNAME(zr
), vchan
->channel
);
2026 memset(vchan
, 0, sizeof(struct video_channel
));
2027 if (channel
> zr
->card
.inputs
|| channel
< 0) {
2030 "%s: VIDIOCGCHAN on not existing channel %d\n",
2031 ZR_DEVNAME(zr
), channel
);
2035 strcpy(vchan
->name
, zr
->card
.input
[channel
].name
);
2039 vchan
->type
= VIDEO_TYPE_CAMERA
;
2040 mutex_lock(&zr
->resource_lock
);
2041 vchan
->norm
= zr
->norm
;
2042 mutex_unlock(&zr
->resource_lock
);
2043 vchan
->channel
= channel
;
2049 /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says:
2051 * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input."
2053 * * The famos BTTV driver has it implemented with a struct video_channel argument
2054 * * and we follow it for compatibility reasons
2056 * * BTW: this is the only way the user can set the norm!
2061 struct video_channel
*vchan
= arg
;
2066 "%s: VIDIOCSCHAN - channel=%d, norm=%d\n",
2067 ZR_DEVNAME(zr
), vchan
->channel
, vchan
->norm
);
2069 mutex_lock(&zr
->resource_lock
);
2070 if ((res
= zoran_set_input(zr
, vchan
->channel
)))
2071 goto schan_unlock_and_return
;
2072 if ((res
= zoran_set_norm(zr
, vchan
->norm
)))
2073 goto schan_unlock_and_return
;
2075 /* Make sure the changes come into effect */
2076 res
= wait_grab_pending(zr
);
2077 schan_unlock_and_return
:
2078 mutex_unlock(&zr
->resource_lock
);
2085 struct video_picture
*vpict
= arg
;
2087 dprintk(3, KERN_DEBUG
"%s: VIDIOCGPICT\n", ZR_DEVNAME(zr
));
2089 memset(vpict
, 0, sizeof(struct video_picture
));
2090 mutex_lock(&zr
->resource_lock
);
2091 vpict
->hue
= zr
->hue
;
2092 vpict
->brightness
= zr
->brightness
;
2093 vpict
->contrast
= zr
->contrast
;
2094 vpict
->colour
= zr
->saturation
;
2095 if (fh
->overlay_settings
.format
) {
2096 vpict
->depth
= fh
->overlay_settings
.format
->depth
;
2097 vpict
->palette
= fh
->overlay_settings
.format
->palette
;
2101 mutex_unlock(&zr
->resource_lock
);
2109 struct video_picture
*vpict
= arg
;
2114 "%s: VIDIOCSPICT - bri=%d, hue=%d, col=%d, con=%d, dep=%d, pal=%d\n",
2115 ZR_DEVNAME(zr
), vpict
->brightness
, vpict
->hue
,
2116 vpict
->colour
, vpict
->contrast
, vpict
->depth
,
2119 for (i
= 0; i
< NUM_FORMATS
; i
++) {
2120 const struct zoran_format
*fmt
= &zoran_formats
[i
];
2122 if (fmt
->palette
!= -1 &&
2123 fmt
->flags
& ZORAN_FORMAT_OVERLAY
&&
2124 fmt
->palette
== vpict
->palette
&&
2125 fmt
->depth
== vpict
->depth
)
2128 if (i
== NUM_FORMATS
) {
2131 "%s: VIDIOCSPICT - Invalid palette %d\n",
2132 ZR_DEVNAME(zr
), vpict
->palette
);
2136 mutex_lock(&zr
->resource_lock
);
2138 decoder_command(zr
, DECODER_SET_PICTURE
, vpict
);
2140 zr
->hue
= vpict
->hue
;
2141 zr
->contrast
= vpict
->contrast
;
2142 zr
->saturation
= vpict
->colour
;
2143 zr
->brightness
= vpict
->brightness
;
2145 fh
->overlay_settings
.format
= &zoran_formats
[i
];
2147 mutex_unlock(&zr
->resource_lock
);
2157 dprintk(3, KERN_DEBUG
"%s: VIDIOCCAPTURE - on=%d\n",
2158 ZR_DEVNAME(zr
), *on
);
2160 mutex_lock(&zr
->resource_lock
);
2161 res
= setup_overlay(file
, *on
);
2162 mutex_unlock(&zr
->resource_lock
);
2170 struct video_window
*vwin
= arg
;
2172 dprintk(3, KERN_DEBUG
"%s: VIDIOCGWIN\n", ZR_DEVNAME(zr
));
2174 memset(vwin
, 0, sizeof(struct video_window
));
2175 mutex_lock(&zr
->resource_lock
);
2176 vwin
->x
= fh
->overlay_settings
.x
;
2177 vwin
->y
= fh
->overlay_settings
.y
;
2178 vwin
->width
= fh
->overlay_settings
.width
;
2179 vwin
->height
= fh
->overlay_settings
.height
;
2180 mutex_unlock(&zr
->resource_lock
);
2181 vwin
->clipcount
= 0;
2188 struct video_window
*vwin
= arg
;
2193 "%s: VIDIOCSWIN - x=%d, y=%d, w=%d, h=%d, clipcount=%d\n",
2194 ZR_DEVNAME(zr
), vwin
->x
, vwin
->y
, vwin
->width
,
2195 vwin
->height
, vwin
->clipcount
);
2197 mutex_lock(&zr
->resource_lock
);
2199 setup_window(file
, vwin
->x
, vwin
->y
, vwin
->width
,
2200 vwin
->height
, vwin
->clips
,
2201 vwin
->clipcount
, NULL
);
2202 mutex_unlock(&zr
->resource_lock
);
2210 struct video_buffer
*vbuf
= arg
;
2212 dprintk(3, KERN_DEBUG
"%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr
));
2214 mutex_lock(&zr
->resource_lock
);
2216 mutex_unlock(&zr
->resource_lock
);
2223 struct video_buffer
*vbuf
= arg
;
2228 "%s: VIDIOCSFBUF - base=%p, w=%d, h=%d, depth=%d, bpl=%d\n",
2229 ZR_DEVNAME(zr
), vbuf
->base
, vbuf
->width
,
2230 vbuf
->height
, vbuf
->depth
, vbuf
->bytesperline
);
2232 for (i
= 0; i
< NUM_FORMATS
; i
++)
2233 if (zoran_formats
[i
].depth
== vbuf
->depth
)
2235 if (i
== NUM_FORMATS
) {
2238 "%s: VIDIOCSFBUF - invalid fbuf depth %d\n",
2239 ZR_DEVNAME(zr
), vbuf
->depth
);
2243 mutex_lock(&zr
->resource_lock
);
2245 setup_fbuffer(file
, vbuf
->base
, &zoran_formats
[i
],
2246 vbuf
->width
, vbuf
->height
,
2247 vbuf
->bytesperline
);
2248 mutex_unlock(&zr
->resource_lock
);
2256 int *frame
= arg
, res
;
2258 dprintk(3, KERN_DEBUG
"%s: VIDIOCSYNC - frame=%d\n",
2259 ZR_DEVNAME(zr
), *frame
);
2261 mutex_lock(&zr
->resource_lock
);
2262 res
= v4l_sync(file
, *frame
);
2263 mutex_unlock(&zr
->resource_lock
);
2265 zr
->v4l_sync_tail
++;
2270 case VIDIOCMCAPTURE
:
2272 struct video_mmap
*vmap
= arg
;
2277 "%s: VIDIOCMCAPTURE - frame=%d, geom=%dx%d, fmt=%d\n",
2278 ZR_DEVNAME(zr
), vmap
->frame
, vmap
->width
, vmap
->height
,
2281 mutex_lock(&zr
->resource_lock
);
2282 res
= v4l_grab(file
, vmap
);
2283 mutex_unlock(&zr
->resource_lock
);
2290 struct video_mbuf
*vmbuf
= arg
;
2293 dprintk(3, KERN_DEBUG
"%s: VIDIOCGMBUF\n", ZR_DEVNAME(zr
));
2296 fh
->v4l_buffers
.num_buffers
*
2297 fh
->v4l_buffers
.buffer_size
;
2298 vmbuf
->frames
= fh
->v4l_buffers
.num_buffers
;
2299 for (i
= 0; i
< vmbuf
->frames
; i
++) {
2301 i
* fh
->v4l_buffers
.buffer_size
;
2304 mutex_lock(&zr
->resource_lock
);
2306 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
2309 "%s: VIDIOCGMBUF - buffers already allocated\n",
2312 goto v4l1reqbuf_unlock_and_return
;
2315 if (v4l_fbuffer_alloc(file
)) {
2317 goto v4l1reqbuf_unlock_and_return
;
2320 /* The next mmap will map the V4L buffers */
2321 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
2322 v4l1reqbuf_unlock_and_return
:
2323 mutex_unlock(&zr
->resource_lock
);
2331 struct video_unit
*vunit
= arg
;
2333 dprintk(3, KERN_DEBUG
"%s: VIDIOCGUNIT\n", ZR_DEVNAME(zr
));
2335 vunit
->video
= zr
->video_dev
->minor
;
2336 vunit
->vbi
= VIDEO_NO_UNIT
;
2337 vunit
->radio
= VIDEO_NO_UNIT
;
2338 vunit
->audio
= VIDEO_NO_UNIT
;
2339 vunit
->teletext
= VIDEO_NO_UNIT
;
2346 * RJ: In principal we could support subcaptures for V4L grabbing.
2347 * Not even the famous BTTV driver has them, however.
2348 * If there should be a strong demand, one could consider
2349 * to implement them.
2351 case VIDIOCGCAPTURE
:
2353 dprintk(3, KERN_ERR
"%s: VIDIOCGCAPTURE not supported\n",
2359 case VIDIOCSCAPTURE
:
2361 dprintk(3, KERN_ERR
"%s: VIDIOCSCAPTURE not supported\n",
2367 case BUZIOC_G_PARAMS
:
2369 struct zoran_params
*bparams
= arg
;
2371 dprintk(3, KERN_DEBUG
"%s: BUZIOC_G_PARAMS\n", ZR_DEVNAME(zr
));
2373 memset(bparams
, 0, sizeof(struct zoran_params
));
2374 bparams
->major_version
= MAJOR_VERSION
;
2375 bparams
->minor_version
= MINOR_VERSION
;
2377 mutex_lock(&zr
->resource_lock
);
2379 bparams
->norm
= zr
->norm
;
2380 bparams
->input
= zr
->input
;
2382 bparams
->decimation
= fh
->jpg_settings
.decimation
;
2383 bparams
->HorDcm
= fh
->jpg_settings
.HorDcm
;
2384 bparams
->VerDcm
= fh
->jpg_settings
.VerDcm
;
2385 bparams
->TmpDcm
= fh
->jpg_settings
.TmpDcm
;
2386 bparams
->field_per_buff
= fh
->jpg_settings
.field_per_buff
;
2387 bparams
->img_x
= fh
->jpg_settings
.img_x
;
2388 bparams
->img_y
= fh
->jpg_settings
.img_y
;
2389 bparams
->img_width
= fh
->jpg_settings
.img_width
;
2390 bparams
->img_height
= fh
->jpg_settings
.img_height
;
2391 bparams
->odd_even
= fh
->jpg_settings
.odd_even
;
2393 bparams
->quality
= fh
->jpg_settings
.jpg_comp
.quality
;
2394 bparams
->APPn
= fh
->jpg_settings
.jpg_comp
.APPn
;
2395 bparams
->APP_len
= fh
->jpg_settings
.jpg_comp
.APP_len
;
2396 memcpy(bparams
->APP_data
,
2397 fh
->jpg_settings
.jpg_comp
.APP_data
,
2398 sizeof(bparams
->APP_data
));
2399 bparams
->COM_len
= zr
->jpg_settings
.jpg_comp
.COM_len
;
2400 memcpy(bparams
->COM_data
,
2401 fh
->jpg_settings
.jpg_comp
.COM_data
,
2402 sizeof(bparams
->COM_data
));
2403 bparams
->jpeg_markers
=
2404 fh
->jpg_settings
.jpg_comp
.jpeg_markers
;
2406 mutex_unlock(&zr
->resource_lock
);
2408 bparams
->VFIFO_FB
= 0;
2414 case BUZIOC_S_PARAMS
:
2416 struct zoran_params
*bparams
= arg
;
2419 dprintk(3, KERN_DEBUG
"%s: BUZIOC_S_PARAMS\n", ZR_DEVNAME(zr
));
2421 settings
.decimation
= bparams
->decimation
;
2422 settings
.HorDcm
= bparams
->HorDcm
;
2423 settings
.VerDcm
= bparams
->VerDcm
;
2424 settings
.TmpDcm
= bparams
->TmpDcm
;
2425 settings
.field_per_buff
= bparams
->field_per_buff
;
2426 settings
.img_x
= bparams
->img_x
;
2427 settings
.img_y
= bparams
->img_y
;
2428 settings
.img_width
= bparams
->img_width
;
2429 settings
.img_height
= bparams
->img_height
;
2430 settings
.odd_even
= bparams
->odd_even
;
2432 settings
.jpg_comp
.quality
= bparams
->quality
;
2433 settings
.jpg_comp
.APPn
= bparams
->APPn
;
2434 settings
.jpg_comp
.APP_len
= bparams
->APP_len
;
2435 memcpy(settings
.jpg_comp
.APP_data
, bparams
->APP_data
,
2436 sizeof(bparams
->APP_data
));
2437 settings
.jpg_comp
.COM_len
= bparams
->COM_len
;
2438 memcpy(settings
.jpg_comp
.COM_data
, bparams
->COM_data
,
2439 sizeof(bparams
->COM_data
));
2440 settings
.jpg_comp
.jpeg_markers
= bparams
->jpeg_markers
;
2442 mutex_lock(&zr
->resource_lock
);
2444 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2447 "%s: BUZIOC_S_PARAMS called, but Buz in capture/playback mode\n",
2450 goto sparams_unlock_and_return
;
2453 /* Check the params first before overwriting our
2455 if (zoran_check_jpg_settings(zr
, &settings
)) {
2457 goto sparams_unlock_and_return
;
2460 fh
->jpg_settings
= settings
;
2461 sparams_unlock_and_return
:
2462 mutex_unlock(&zr
->resource_lock
);
2468 case BUZIOC_REQBUFS
:
2470 struct zoran_requestbuffers
*breq
= arg
;
2475 "%s: BUZIOC_REQBUFS - count=%lu, size=%lu\n",
2476 ZR_DEVNAME(zr
), breq
->count
, breq
->size
);
2478 /* Enforce reasonable lower and upper limits */
2479 if (breq
->count
< 4)
2480 breq
->count
= 4; /* Could be choosen smaller */
2481 if (breq
->count
> jpg_nbufs
)
2482 breq
->count
= jpg_nbufs
;
2483 breq
->size
= PAGE_ALIGN(breq
->size
);
2484 if (breq
->size
< 8192)
2485 breq
->size
= 8192; /* Arbitrary */
2486 /* breq->size is limited by 1 page for the stat_com
2487 * tables to a Maximum of 2 MB */
2488 if (breq
->size
> jpg_bufsize
)
2489 breq
->size
= jpg_bufsize
;
2490 if (fh
->jpg_buffers
.need_contiguous
&&
2491 breq
->size
> MAX_KMALLOC_MEM
)
2492 breq
->size
= MAX_KMALLOC_MEM
;
2494 mutex_lock(&zr
->resource_lock
);
2496 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
2499 "%s: BUZIOC_REQBUFS - buffers allready allocated\n",
2502 goto jpgreqbuf_unlock_and_return
;
2505 fh
->jpg_buffers
.num_buffers
= breq
->count
;
2506 fh
->jpg_buffers
.buffer_size
= breq
->size
;
2508 if (jpg_fbuffer_alloc(file
)) {
2510 goto jpgreqbuf_unlock_and_return
;
2513 /* The next mmap will map the MJPEG buffers - could
2514 * also be *_PLAY, but it doesn't matter here */
2515 fh
->map_mode
= ZORAN_MAP_MODE_JPG_REC
;
2516 jpgreqbuf_unlock_and_return
:
2517 mutex_unlock(&zr
->resource_lock
);
2523 case BUZIOC_QBUF_CAPT
:
2525 int *frame
= arg
, res
;
2527 dprintk(3, KERN_DEBUG
"%s: BUZIOC_QBUF_CAPT - frame=%d\n",
2528 ZR_DEVNAME(zr
), *frame
);
2530 mutex_lock(&zr
->resource_lock
);
2531 res
= jpg_qbuf(file
, *frame
, BUZ_MODE_MOTION_COMPRESS
);
2532 mutex_unlock(&zr
->resource_lock
);
2538 case BUZIOC_QBUF_PLAY
:
2540 int *frame
= arg
, res
;
2542 dprintk(3, KERN_DEBUG
"%s: BUZIOC_QBUF_PLAY - frame=%d\n",
2543 ZR_DEVNAME(zr
), *frame
);
2545 mutex_lock(&zr
->resource_lock
);
2546 res
= jpg_qbuf(file
, *frame
, BUZ_MODE_MOTION_DECOMPRESS
);
2547 mutex_unlock(&zr
->resource_lock
);
2555 struct zoran_sync
*bsync
= arg
;
2558 dprintk(3, KERN_DEBUG
"%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr
));
2560 mutex_lock(&zr
->resource_lock
);
2561 res
= jpg_sync(file
, bsync
);
2562 mutex_unlock(&zr
->resource_lock
);
2568 case BUZIOC_G_STATUS
:
2570 struct zoran_status
*bstat
= arg
;
2571 int norm
, input
, status
, res
= 0;
2573 dprintk(3, KERN_DEBUG
"%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr
));
2575 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2578 "%s: BUZIOC_G_STATUS called but Buz in capture/playback mode\n",
2583 input
= zr
->card
.input
[bstat
->input
].muxsel
;
2584 norm
= VIDEO_MODE_AUTO
;
2586 mutex_lock(&zr
->resource_lock
);
2588 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2591 "%s: BUZIOC_G_STATUS called, but Buz in capture/playback mode\n",
2594 goto gstat_unlock_and_return
;
2597 decoder_command(zr
, DECODER_SET_INPUT
, &input
);
2598 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
2600 /* sleep 1 second */
2603 /* Get status of video decoder */
2604 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
2606 /* restore previous input and norm */
2607 input
= zr
->card
.input
[zr
->input
].muxsel
;
2608 decoder_command(zr
, DECODER_SET_INPUT
, &input
);
2609 decoder_command(zr
, DECODER_SET_NORM
, &zr
->norm
);
2610 gstat_unlock_and_return
:
2611 mutex_unlock(&zr
->resource_lock
);
2615 (status
& DECODER_STATUS_GOOD
) ? 1 : 0;
2616 if (status
& DECODER_STATUS_NTSC
)
2617 bstat
->norm
= VIDEO_MODE_NTSC
;
2618 else if (status
& DECODER_STATUS_SECAM
)
2619 bstat
->norm
= VIDEO_MODE_SECAM
;
2621 bstat
->norm
= VIDEO_MODE_PAL
;
2624 (status
& DECODER_STATUS_COLOR
) ? 1 : 0;
2631 #ifdef CONFIG_VIDEO_V4L2
2633 /* The new video4linux2 capture interface - much nicer than video4linux1, since
2634 * it allows for integrating the JPEG capturing calls inside standard v4l2
2637 case VIDIOC_QUERYCAP
:
2639 struct v4l2_capability
*cap
= arg
;
2641 dprintk(3, KERN_DEBUG
"%s: VIDIOC_QUERYCAP\n", ZR_DEVNAME(zr
));
2643 memset(cap
, 0, sizeof(*cap
));
2644 strncpy(cap
->card
, ZR_DEVNAME(zr
), sizeof(cap
->card
)-1);
2645 strncpy(cap
->driver
, "zoran", sizeof(cap
->driver
)-1);
2646 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "PCI:%s",
2647 pci_name(zr
->pci_dev
));
2649 KERNEL_VERSION(MAJOR_VERSION
, MINOR_VERSION
,
2651 cap
->capabilities
= ZORAN_V4L2_VID_FLAGS
;
2657 case VIDIOC_ENUM_FMT
:
2659 struct v4l2_fmtdesc
*fmt
= arg
;
2660 int index
= fmt
->index
, num
= -1, i
, flag
= 0, type
=
2663 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUM_FMT - index=%d\n",
2664 ZR_DEVNAME(zr
), fmt
->index
);
2666 switch (fmt
->type
) {
2667 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2668 flag
= ZORAN_FORMAT_CAPTURE
;
2670 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2671 flag
= ZORAN_FORMAT_PLAYBACK
;
2673 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2674 flag
= ZORAN_FORMAT_OVERLAY
;
2679 "%s: VIDIOC_ENUM_FMT - unknown type %d\n",
2680 ZR_DEVNAME(zr
), fmt
->type
);
2684 for (i
= 0; i
< NUM_FORMATS
; i
++) {
2685 if (zoran_formats
[i
].flags
& flag
)
2687 if (num
== fmt
->index
)
2690 if (fmt
->index
< 0 /* late, but not too late */ ||
2694 memset(fmt
, 0, sizeof(*fmt
));
2697 strncpy(fmt
->description
, zoran_formats
[i
].name
, sizeof(fmt
->description
)-1);
2698 fmt
->pixelformat
= zoran_formats
[i
].fourcc
;
2699 if (zoran_formats
[i
].flags
& ZORAN_FORMAT_COMPRESSED
)
2700 fmt
->flags
|= V4L2_FMT_FLAG_COMPRESSED
;
2708 struct v4l2_format
*fmt
= arg
;
2709 int type
= fmt
->type
;
2711 dprintk(5, KERN_DEBUG
"%s: VIDIOC_G_FMT\n", ZR_DEVNAME(zr
));
2713 memset(fmt
, 0, sizeof(*fmt
));
2716 switch (fmt
->type
) {
2717 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2719 mutex_lock(&zr
->resource_lock
);
2721 fmt
->fmt
.win
.w
.left
= fh
->overlay_settings
.x
;
2722 fmt
->fmt
.win
.w
.top
= fh
->overlay_settings
.y
;
2723 fmt
->fmt
.win
.w
.width
= fh
->overlay_settings
.width
;
2724 fmt
->fmt
.win
.w
.height
=
2725 fh
->overlay_settings
.height
;
2726 if (fh
->overlay_settings
.width
* 2 >
2728 fmt
->fmt
.win
.field
= V4L2_FIELD_INTERLACED
;
2730 fmt
->fmt
.win
.field
= V4L2_FIELD_TOP
;
2732 mutex_unlock(&zr
->resource_lock
);
2736 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2737 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2739 mutex_lock(&zr
->resource_lock
);
2741 if (fmt
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
2742 fh
->map_mode
== ZORAN_MAP_MODE_RAW
) {
2744 fmt
->fmt
.pix
.width
=
2745 fh
->v4l_settings
.width
;
2746 fmt
->fmt
.pix
.height
=
2747 fh
->v4l_settings
.height
;
2748 fmt
->fmt
.pix
.sizeimage
=
2749 fh
->v4l_settings
.bytesperline
*
2750 fh
->v4l_settings
.height
;
2751 fmt
->fmt
.pix
.pixelformat
=
2752 fh
->v4l_settings
.format
->fourcc
;
2753 fmt
->fmt
.pix
.colorspace
=
2754 fh
->v4l_settings
.format
->colorspace
;
2755 fmt
->fmt
.pix
.bytesperline
= 0;
2756 if (BUZ_MAX_HEIGHT
<
2757 (fh
->v4l_settings
.height
* 2))
2758 fmt
->fmt
.pix
.field
=
2759 V4L2_FIELD_INTERLACED
;
2761 fmt
->fmt
.pix
.field
=
2766 fmt
->fmt
.pix
.width
=
2767 fh
->jpg_settings
.img_width
/
2768 fh
->jpg_settings
.HorDcm
;
2769 fmt
->fmt
.pix
.height
=
2770 fh
->jpg_settings
.img_height
/
2771 (fh
->jpg_settings
.VerDcm
*
2772 fh
->jpg_settings
.TmpDcm
);
2773 fmt
->fmt
.pix
.sizeimage
=
2774 zoran_v4l2_calc_bufsize(&fh
->
2776 fmt
->fmt
.pix
.pixelformat
=
2778 if (fh
->jpg_settings
.TmpDcm
== 1)
2779 fmt
->fmt
.pix
.field
=
2781 odd_even
? V4L2_FIELD_SEQ_BT
:
2784 fmt
->fmt
.pix
.field
=
2786 odd_even
? V4L2_FIELD_TOP
:
2789 fmt
->fmt
.pix
.bytesperline
= 0;
2790 fmt
->fmt
.pix
.colorspace
=
2791 V4L2_COLORSPACE_SMPTE170M
;
2794 mutex_unlock(&zr
->resource_lock
);
2801 "%s: VIDIOC_G_FMT - unsupported type %d\n",
2802 ZR_DEVNAME(zr
), fmt
->type
);
2811 struct v4l2_format
*fmt
= arg
;
2815 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_FMT - type=%d, ",
2816 ZR_DEVNAME(zr
), fmt
->type
);
2818 switch (fmt
->type
) {
2819 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2821 dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n",
2822 fmt
->fmt
.win
.w
.left
, fmt
->fmt
.win
.w
.top
,
2823 fmt
->fmt
.win
.w
.width
,
2824 fmt
->fmt
.win
.w
.height
,
2825 fmt
->fmt
.win
.clipcount
,
2826 fmt
->fmt
.win
.bitmap
);
2827 mutex_lock(&zr
->resource_lock
);
2829 setup_window(file
, fmt
->fmt
.win
.w
.left
,
2831 fmt
->fmt
.win
.w
.width
,
2832 fmt
->fmt
.win
.w
.height
,
2833 (struct video_clip __user
*)
2835 fmt
->fmt
.win
.clipcount
,
2836 fmt
->fmt
.win
.bitmap
);
2837 mutex_unlock(&zr
->resource_lock
);
2841 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2842 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2845 __cpu_to_le32(fmt
->fmt
.pix
.pixelformat
);
2846 dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n",
2847 fmt
->fmt
.pix
.width
, fmt
->fmt
.pix
.height
,
2848 fmt
->fmt
.pix
.pixelformat
,
2849 (char *) &printformat
);
2851 if (fmt
->fmt
.pix
.bytesperline
> 0) {
2853 KERN_ERR
"%s: bpl not supported\n",
2858 /* we can be requested to do JPEG/raw playback/capture */
2860 (fmt
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
2861 (fmt
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
2862 fmt
->fmt
.pix
.pixelformat
==
2863 V4L2_PIX_FMT_MJPEG
))) {
2866 "%s: VIDIOC_S_FMT - unknown type %d/0x%x(%4.4s) combination\n",
2867 ZR_DEVNAME(zr
), fmt
->type
,
2868 fmt
->fmt
.pix
.pixelformat
,
2869 (char *) &printformat
);
2873 if (fmt
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_MJPEG
) {
2874 mutex_lock(&zr
->resource_lock
);
2876 settings
= fh
->jpg_settings
;
2878 if (fh
->v4l_buffers
.allocated
||
2879 fh
->jpg_buffers
.allocated
) {
2882 "%s: VIDIOC_S_FMT - cannot change capture mode\n",
2885 goto sfmtjpg_unlock_and_return
;
2888 /* we actually need to set 'real' parameters now */
2889 if ((fmt
->fmt
.pix
.height
* 2) >
2891 settings
.TmpDcm
= 1;
2893 settings
.TmpDcm
= 2;
2894 settings
.decimation
= 0;
2895 if (fmt
->fmt
.pix
.height
<=
2896 fh
->jpg_settings
.img_height
/ 2)
2897 settings
.VerDcm
= 2;
2899 settings
.VerDcm
= 1;
2900 if (fmt
->fmt
.pix
.width
<=
2901 fh
->jpg_settings
.img_width
/ 4)
2902 settings
.HorDcm
= 4;
2903 else if (fmt
->fmt
.pix
.width
<=
2904 fh
->jpg_settings
.img_width
/ 2)
2905 settings
.HorDcm
= 2;
2907 settings
.HorDcm
= 1;
2908 if (settings
.TmpDcm
== 1)
2909 settings
.field_per_buff
= 2;
2911 settings
.field_per_buff
= 1;
2915 zoran_check_jpg_settings(zr
,
2917 goto sfmtjpg_unlock_and_return
;
2919 /* it's ok, so set them */
2920 fh
->jpg_settings
= settings
;
2922 /* tell the user what we actually did */
2923 fmt
->fmt
.pix
.width
=
2924 settings
.img_width
/ settings
.HorDcm
;
2925 fmt
->fmt
.pix
.height
=
2926 settings
.img_height
* 2 /
2927 (settings
.TmpDcm
* settings
.VerDcm
);
2928 if (settings
.TmpDcm
== 1)
2929 fmt
->fmt
.pix
.field
=
2931 odd_even
? V4L2_FIELD_SEQ_TB
:
2934 fmt
->fmt
.pix
.field
=
2936 odd_even
? V4L2_FIELD_TOP
:
2938 fh
->jpg_buffers
.buffer_size
=
2939 zoran_v4l2_calc_bufsize(&fh
->
2941 fmt
->fmt
.pix
.sizeimage
=
2942 fh
->jpg_buffers
.buffer_size
;
2944 /* we hereby abuse this variable to show that
2945 * we're gonna do mjpeg capture */
2948 V4L2_BUF_TYPE_VIDEO_CAPTURE
) ?
2949 ZORAN_MAP_MODE_JPG_REC
:
2950 ZORAN_MAP_MODE_JPG_PLAY
;
2951 sfmtjpg_unlock_and_return
:
2952 mutex_unlock(&zr
->resource_lock
);
2954 for (i
= 0; i
< NUM_FORMATS
; i
++)
2955 if (fmt
->fmt
.pix
.pixelformat
==
2956 zoran_formats
[i
].fourcc
)
2958 if (i
== NUM_FORMATS
) {
2961 "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x (%4.4s)\n",
2963 fmt
->fmt
.pix
.pixelformat
,
2964 (char *) &printformat
);
2967 mutex_lock(&zr
->resource_lock
);
2968 if (fh
->jpg_buffers
.allocated
||
2969 (fh
->v4l_buffers
.allocated
&&
2970 fh
->v4l_buffers
.active
!=
2974 "%s: VIDIOC_S_FMT - cannot change capture mode\n",
2977 goto sfmtv4l_unlock_and_return
;
2979 if (fmt
->fmt
.pix
.height
> BUZ_MAX_HEIGHT
)
2980 fmt
->fmt
.pix
.height
=
2982 if (fmt
->fmt
.pix
.width
> BUZ_MAX_WIDTH
)
2983 fmt
->fmt
.pix
.width
= BUZ_MAX_WIDTH
;
2986 zoran_v4l_set_format(file
,
2993 goto sfmtv4l_unlock_and_return
;
2995 /* tell the user the
2996 * results/missing stuff */
2997 fmt
->fmt
.pix
.sizeimage
=
2998 fh
->v4l_settings
.height
*
2999 fh
->v4l_settings
.bytesperline
;
3000 if (BUZ_MAX_HEIGHT
<
3001 (fh
->v4l_settings
.height
* 2))
3002 fmt
->fmt
.pix
.field
=
3003 V4L2_FIELD_INTERLACED
;
3005 fmt
->fmt
.pix
.field
=
3008 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
3009 sfmtv4l_unlock_and_return
:
3010 mutex_unlock(&zr
->resource_lock
);
3016 dprintk(3, "unsupported\n");
3019 "%s: VIDIOC_S_FMT - unsupported type %d\n",
3020 ZR_DEVNAME(zr
), fmt
->type
);
3030 struct v4l2_framebuffer
*fb
= arg
;
3032 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr
));
3034 memset(fb
, 0, sizeof(*fb
));
3035 mutex_lock(&zr
->resource_lock
);
3036 fb
->base
= zr
->buffer
.base
;
3037 fb
->fmt
.width
= zr
->buffer
.width
;
3038 fb
->fmt
.height
= zr
->buffer
.height
;
3039 if (zr
->overlay_settings
.format
) {
3040 fb
->fmt
.pixelformat
=
3041 fh
->overlay_settings
.format
->fourcc
;
3043 fb
->fmt
.bytesperline
= zr
->buffer
.bytesperline
;
3044 mutex_unlock(&zr
->resource_lock
);
3045 fb
->fmt
.colorspace
= V4L2_COLORSPACE_SRGB
;
3046 fb
->fmt
.field
= V4L2_FIELD_INTERLACED
;
3047 fb
->flags
= V4L2_FBUF_FLAG_OVERLAY
;
3048 fb
->capability
= V4L2_FBUF_CAP_LIST_CLIPPING
;
3057 struct v4l2_framebuffer
*fb
= arg
;
3058 __u32 printformat
= __cpu_to_le32(fb
->fmt
.pixelformat
);
3062 "%s: VIDIOC_S_FBUF - base=0x%p, size=%dx%d, bpl=%d, fmt=0x%x (%4.4s)\n",
3063 ZR_DEVNAME(zr
), fb
->base
, fb
->fmt
.width
, fb
->fmt
.height
,
3064 fb
->fmt
.bytesperline
, fb
->fmt
.pixelformat
,
3065 (char *) &printformat
);
3067 for (i
= 0; i
< NUM_FORMATS
; i
++)
3068 if (zoran_formats
[i
].fourcc
== fb
->fmt
.pixelformat
)
3070 if (i
== NUM_FORMATS
) {
3073 "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n",
3074 ZR_DEVNAME(zr
), fb
->fmt
.pixelformat
,
3075 (char *) &printformat
);
3079 mutex_lock(&zr
->resource_lock
);
3081 setup_fbuffer(file
, fb
->base
, &zoran_formats
[i
],
3082 fb
->fmt
.width
, fb
->fmt
.height
,
3083 fb
->fmt
.bytesperline
);
3084 mutex_unlock(&zr
->resource_lock
);
3090 case VIDIOC_OVERLAY
:
3094 dprintk(3, KERN_DEBUG
"%s: VIDIOC_PREVIEW - on=%d\n",
3095 ZR_DEVNAME(zr
), *on
);
3097 mutex_lock(&zr
->resource_lock
);
3098 res
= setup_overlay(file
, *on
);
3099 mutex_unlock(&zr
->resource_lock
);
3105 case VIDIOC_REQBUFS
:
3107 struct v4l2_requestbuffers
*req
= arg
;
3110 dprintk(3, KERN_DEBUG
"%s: VIDIOC_REQBUFS - type=%d\n",
3111 ZR_DEVNAME(zr
), req
->type
);
3113 if (req
->memory
!= V4L2_MEMORY_MMAP
) {
3116 "%s: only MEMORY_MMAP capture is supported, not %d\n",
3117 ZR_DEVNAME(zr
), req
->memory
);
3121 mutex_lock(&zr
->resource_lock
);
3123 if (fh
->v4l_buffers
.allocated
|| fh
->jpg_buffers
.allocated
) {
3126 "%s: VIDIOC_REQBUFS - buffers allready allocated\n",
3129 goto v4l2reqbuf_unlock_and_return
;
3132 if (fh
->map_mode
== ZORAN_MAP_MODE_RAW
&&
3133 req
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3135 /* control user input */
3138 if (req
->count
> v4l_nbufs
)
3139 req
->count
= v4l_nbufs
;
3140 fh
->v4l_buffers
.num_buffers
= req
->count
;
3142 if (v4l_fbuffer_alloc(file
)) {
3144 goto v4l2reqbuf_unlock_and_return
;
3147 /* The next mmap will map the V4L buffers */
3148 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
3150 } else if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
||
3151 fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
) {
3153 /* we need to calculate size ourselves now */
3156 if (req
->count
> jpg_nbufs
)
3157 req
->count
= jpg_nbufs
;
3158 fh
->jpg_buffers
.num_buffers
= req
->count
;
3159 fh
->jpg_buffers
.buffer_size
=
3160 zoran_v4l2_calc_bufsize(&fh
->jpg_settings
);
3162 if (jpg_fbuffer_alloc(file
)) {
3164 goto v4l2reqbuf_unlock_and_return
;
3167 /* The next mmap will map the MJPEG buffers */
3168 if (req
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
3169 fh
->map_mode
= ZORAN_MAP_MODE_JPG_REC
;
3171 fh
->map_mode
= ZORAN_MAP_MODE_JPG_PLAY
;
3176 "%s: VIDIOC_REQBUFS - unknown type %d\n",
3177 ZR_DEVNAME(zr
), req
->type
);
3179 goto v4l2reqbuf_unlock_and_return
;
3181 v4l2reqbuf_unlock_and_return
:
3182 mutex_unlock(&zr
->resource_lock
);
3188 case VIDIOC_QUERYBUF
:
3190 struct v4l2_buffer
*buf
= arg
;
3191 __u32 type
= buf
->type
;
3192 int index
= buf
->index
, res
;
3196 "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n",
3197 ZR_DEVNAME(zr
), buf
->index
, buf
->type
);
3199 memset(buf
, 0, sizeof(*buf
));
3203 mutex_lock(&zr
->resource_lock
);
3204 res
= zoran_v4l2_buffer_status(file
, buf
, buf
->index
);
3205 mutex_unlock(&zr
->resource_lock
);
3213 struct v4l2_buffer
*buf
= arg
;
3214 int res
= 0, codec_mode
, buf_type
;
3217 KERN_DEBUG
"%s: VIDIOC_QBUF - type=%d, index=%d\n",
3218 ZR_DEVNAME(zr
), buf
->type
, buf
->index
);
3220 mutex_lock(&zr
->resource_lock
);
3222 switch (fh
->map_mode
) {
3223 case ZORAN_MAP_MODE_RAW
:
3224 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3227 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3228 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3230 goto qbuf_unlock_and_return
;
3233 res
= zoran_v4l_queue_frame(file
, buf
->index
);
3235 goto qbuf_unlock_and_return
;
3236 if (!zr
->v4l_memgrab_active
&&
3237 fh
->v4l_buffers
.active
== ZORAN_LOCKED
)
3238 zr36057_set_memgrab(zr
, 1);
3241 case ZORAN_MAP_MODE_JPG_REC
:
3242 case ZORAN_MAP_MODE_JPG_PLAY
:
3243 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
) {
3244 buf_type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
3245 codec_mode
= BUZ_MODE_MOTION_DECOMPRESS
;
3247 buf_type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
3248 codec_mode
= BUZ_MODE_MOTION_COMPRESS
;
3251 if (buf
->type
!= buf_type
) {
3254 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3255 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3257 goto qbuf_unlock_and_return
;
3261 zoran_jpg_queue_frame(file
, buf
->index
,
3264 goto qbuf_unlock_and_return
;
3265 if (zr
->codec_mode
== BUZ_MODE_IDLE
&&
3266 fh
->jpg_buffers
.active
== ZORAN_LOCKED
) {
3267 zr36057_enable_jpg(zr
, codec_mode
);
3274 "%s: VIDIOC_QBUF - unsupported type %d\n",
3275 ZR_DEVNAME(zr
), buf
->type
);
3277 goto qbuf_unlock_and_return
;
3279 qbuf_unlock_and_return
:
3280 mutex_unlock(&zr
->resource_lock
);
3288 struct v4l2_buffer
*buf
= arg
;
3289 int res
= 0, buf_type
, num
= -1; /* compiler borks here (?) */
3291 dprintk(3, KERN_DEBUG
"%s: VIDIOC_DQBUF - type=%d\n",
3292 ZR_DEVNAME(zr
), buf
->type
);
3294 mutex_lock(&zr
->resource_lock
);
3296 switch (fh
->map_mode
) {
3297 case ZORAN_MAP_MODE_RAW
:
3298 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3301 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3302 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3304 goto dqbuf_unlock_and_return
;
3307 num
= zr
->v4l_pend
[zr
->v4l_sync_tail
& V4L_MASK_FRAME
];
3308 if (file
->f_flags
& O_NONBLOCK
&&
3309 zr
->v4l_buffers
.buffer
[num
].state
!=
3312 goto dqbuf_unlock_and_return
;
3314 res
= v4l_sync(file
, num
);
3316 goto dqbuf_unlock_and_return
;
3318 zr
->v4l_sync_tail
++;
3319 res
= zoran_v4l2_buffer_status(file
, buf
, num
);
3322 case ZORAN_MAP_MODE_JPG_REC
:
3323 case ZORAN_MAP_MODE_JPG_PLAY
:
3325 struct zoran_sync bs
;
3327 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
)
3328 buf_type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
3330 buf_type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
3332 if (buf
->type
!= buf_type
) {
3335 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3336 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3338 goto dqbuf_unlock_and_return
;
3343 jpg_que_tail
& BUZ_MASK_FRAME
];
3345 if (file
->f_flags
& O_NONBLOCK
&&
3346 zr
->jpg_buffers
.buffer
[num
].state
!=
3349 goto dqbuf_unlock_and_return
;
3351 res
= jpg_sync(file
, &bs
);
3353 goto dqbuf_unlock_and_return
;
3355 zoran_v4l2_buffer_status(file
, buf
, bs
.frame
);
3362 "%s: VIDIOC_DQBUF - unsupported type %d\n",
3363 ZR_DEVNAME(zr
), buf
->type
);
3365 goto dqbuf_unlock_and_return
;
3367 dqbuf_unlock_and_return
:
3368 mutex_unlock(&zr
->resource_lock
);
3374 case VIDIOC_STREAMON
:
3378 dprintk(3, KERN_DEBUG
"%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr
));
3380 mutex_lock(&zr
->resource_lock
);
3382 switch (fh
->map_mode
) {
3383 case ZORAN_MAP_MODE_RAW
: /* raw capture */
3384 if (zr
->v4l_buffers
.active
!= ZORAN_ACTIVE
||
3385 fh
->v4l_buffers
.active
!= ZORAN_ACTIVE
) {
3387 goto strmon_unlock_and_return
;
3390 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
3392 zr
->v4l_settings
= fh
->v4l_settings
;
3394 zr
->v4l_sync_tail
= zr
->v4l_pend_tail
;
3395 if (!zr
->v4l_memgrab_active
&&
3396 zr
->v4l_pend_head
!= zr
->v4l_pend_tail
) {
3397 zr36057_set_memgrab(zr
, 1);
3401 case ZORAN_MAP_MODE_JPG_REC
:
3402 case ZORAN_MAP_MODE_JPG_PLAY
:
3403 /* what is the codec mode right now? */
3404 if (zr
->jpg_buffers
.active
!= ZORAN_ACTIVE
||
3405 fh
->jpg_buffers
.active
!= ZORAN_ACTIVE
) {
3407 goto strmon_unlock_and_return
;
3410 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
=
3413 if (zr
->jpg_que_head
!= zr
->jpg_que_tail
) {
3414 /* Start the jpeg codec when the first frame is queued */
3422 "%s: VIDIOC_STREAMON - invalid map mode %d\n",
3423 ZR_DEVNAME(zr
), fh
->map_mode
);
3425 goto strmon_unlock_and_return
;
3427 strmon_unlock_and_return
:
3428 mutex_unlock(&zr
->resource_lock
);
3434 case VIDIOC_STREAMOFF
:
3438 dprintk(3, KERN_DEBUG
"%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr
));
3440 mutex_lock(&zr
->resource_lock
);
3442 switch (fh
->map_mode
) {
3443 case ZORAN_MAP_MODE_RAW
: /* raw capture */
3444 if (fh
->v4l_buffers
.active
== ZORAN_FREE
&&
3445 zr
->v4l_buffers
.active
!= ZORAN_FREE
) {
3446 res
= -EPERM
; /* stay off other's settings! */
3447 goto strmoff_unlock_and_return
;
3449 if (zr
->v4l_buffers
.active
== ZORAN_FREE
)
3450 goto strmoff_unlock_and_return
;
3452 /* unload capture */
3453 if (zr
->v4l_memgrab_active
) {
3456 spin_lock_irqsave(&zr
->spinlock
, flags
);
3457 zr36057_set_memgrab(zr
, 0);
3458 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
3461 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++)
3462 zr
->v4l_buffers
.buffer
[i
].state
=
3464 fh
->v4l_buffers
= zr
->v4l_buffers
;
3466 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
3469 zr
->v4l_grab_seq
= 0;
3470 zr
->v4l_pend_head
= zr
->v4l_pend_tail
= 0;
3471 zr
->v4l_sync_tail
= 0;
3475 case ZORAN_MAP_MODE_JPG_REC
:
3476 case ZORAN_MAP_MODE_JPG_PLAY
:
3477 if (fh
->jpg_buffers
.active
== ZORAN_FREE
&&
3478 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
3479 res
= -EPERM
; /* stay off other's settings! */
3480 goto strmoff_unlock_and_return
;
3482 if (zr
->jpg_buffers
.active
== ZORAN_FREE
)
3483 goto strmoff_unlock_and_return
;
3488 ZORAN_MAP_MODE_JPG_REC
) ?
3489 BUZ_MODE_MOTION_COMPRESS
:
3490 BUZ_MODE_MOTION_DECOMPRESS
);
3492 goto strmoff_unlock_and_return
;
3497 "%s: VIDIOC_STREAMOFF - invalid map mode %d\n",
3498 ZR_DEVNAME(zr
), fh
->map_mode
);
3500 goto strmoff_unlock_and_return
;
3502 strmoff_unlock_and_return
:
3503 mutex_unlock(&zr
->resource_lock
);
3509 case VIDIOC_QUERYCTRL
:
3511 struct v4l2_queryctrl
*ctrl
= arg
;
3513 dprintk(3, KERN_DEBUG
"%s: VIDIOC_QUERYCTRL - id=%d\n",
3514 ZR_DEVNAME(zr
), ctrl
->id
);
3516 /* we only support hue/saturation/contrast/brightness */
3517 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3518 ctrl
->id
> V4L2_CID_HUE
)
3522 memset(ctrl
, 0, sizeof(*ctrl
));
3527 case V4L2_CID_BRIGHTNESS
:
3528 strncpy(ctrl
->name
, "Brightness", sizeof(ctrl
->name
)-1);
3530 case V4L2_CID_CONTRAST
:
3531 strncpy(ctrl
->name
, "Contrast", sizeof(ctrl
->name
)-1);
3533 case V4L2_CID_SATURATION
:
3534 strncpy(ctrl
->name
, "Saturation", sizeof(ctrl
->name
)-1);
3537 strncpy(ctrl
->name
, "Hue", sizeof(ctrl
->name
)-1);
3542 ctrl
->maximum
= 65535;
3544 ctrl
->default_value
= 32768;
3545 ctrl
->type
= V4L2_CTRL_TYPE_INTEGER
;
3553 struct v4l2_control
*ctrl
= arg
;
3555 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_CTRL - id=%d\n",
3556 ZR_DEVNAME(zr
), ctrl
->id
);
3558 /* we only support hue/saturation/contrast/brightness */
3559 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3560 ctrl
->id
> V4L2_CID_HUE
)
3563 mutex_lock(&zr
->resource_lock
);
3565 case V4L2_CID_BRIGHTNESS
:
3566 ctrl
->value
= zr
->brightness
;
3568 case V4L2_CID_CONTRAST
:
3569 ctrl
->value
= zr
->contrast
;
3571 case V4L2_CID_SATURATION
:
3572 ctrl
->value
= zr
->saturation
;
3575 ctrl
->value
= zr
->hue
;
3578 mutex_unlock(&zr
->resource_lock
);
3586 struct v4l2_control
*ctrl
= arg
;
3587 struct video_picture pict
;
3589 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_CTRL - id=%d\n",
3590 ZR_DEVNAME(zr
), ctrl
->id
);
3592 /* we only support hue/saturation/contrast/brightness */
3593 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3594 ctrl
->id
> V4L2_CID_HUE
)
3597 if (ctrl
->value
< 0 || ctrl
->value
> 65535) {
3600 "%s: VIDIOC_S_CTRL - invalid value %d for id=%d\n",
3601 ZR_DEVNAME(zr
), ctrl
->value
, ctrl
->id
);
3605 mutex_lock(&zr
->resource_lock
);
3607 case V4L2_CID_BRIGHTNESS
:
3608 zr
->brightness
= ctrl
->value
;
3610 case V4L2_CID_CONTRAST
:
3611 zr
->contrast
= ctrl
->value
;
3613 case V4L2_CID_SATURATION
:
3614 zr
->saturation
= ctrl
->value
;
3617 zr
->hue
= ctrl
->value
;
3620 pict
.brightness
= zr
->brightness
;
3621 pict
.contrast
= zr
->contrast
;
3622 pict
.colour
= zr
->saturation
;
3625 decoder_command(zr
, DECODER_SET_PICTURE
, &pict
);
3627 mutex_unlock(&zr
->resource_lock
);
3633 case VIDIOC_ENUMSTD
:
3635 struct v4l2_standard
*std
= arg
;
3637 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMSTD - index=%d\n",
3638 ZR_DEVNAME(zr
), std
->index
);
3640 if (std
->index
< 0 || std
->index
>= (zr
->card
.norms
+ 1))
3643 int id
= std
->index
;
3644 memset(std
, 0, sizeof(*std
));
3648 if (std
->index
== zr
->card
.norms
) {
3649 /* if we have autodetect, ... */
3650 struct video_decoder_capability caps
;
3651 decoder_command(zr
, DECODER_GET_CAPABILITIES
,
3653 if (caps
.flags
& VIDEO_DECODER_AUTO
) {
3654 std
->id
= V4L2_STD_ALL
;
3655 strncpy(std
->name
, "Autodetect", sizeof(std
->name
)-1);
3660 switch (std
->index
) {
3662 std
->id
= V4L2_STD_PAL
;
3663 strncpy(std
->name
, "PAL", sizeof(std
->name
)-1);
3664 std
->frameperiod
.numerator
= 1;
3665 std
->frameperiod
.denominator
= 25;
3666 std
->framelines
= zr
->card
.tvn
[0]->Ht
;
3669 std
->id
= V4L2_STD_NTSC
;
3670 strncpy(std
->name
, "NTSC", sizeof(std
->name
)-1);
3671 std
->frameperiod
.numerator
= 1001;
3672 std
->frameperiod
.denominator
= 30000;
3673 std
->framelines
= zr
->card
.tvn
[1]->Ht
;
3676 std
->id
= V4L2_STD_SECAM
;
3677 strncpy(std
->name
, "SECAM", sizeof(std
->name
)-1);
3678 std
->frameperiod
.numerator
= 1;
3679 std
->frameperiod
.denominator
= 25;
3680 std
->framelines
= zr
->card
.tvn
[2]->Ht
;
3690 v4l2_std_id
*std
= arg
;
3693 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr
));
3695 mutex_lock(&zr
->resource_lock
);
3697 mutex_unlock(&zr
->resource_lock
);
3700 case VIDEO_MODE_PAL
:
3701 *std
= V4L2_STD_PAL
;
3703 case VIDEO_MODE_NTSC
:
3704 *std
= V4L2_STD_NTSC
;
3706 case VIDEO_MODE_SECAM
:
3707 *std
= V4L2_STD_SECAM
;
3717 int norm
= -1, res
= 0;
3718 v4l2_std_id
*std
= arg
;
3720 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_STD - norm=0x%llx\n",
3721 ZR_DEVNAME(zr
), (unsigned long long)*std
);
3723 if ((*std
& V4L2_STD_PAL
) && !(*std
& ~V4L2_STD_PAL
))
3724 norm
= VIDEO_MODE_PAL
;
3725 else if ((*std
& V4L2_STD_NTSC
) && !(*std
& ~V4L2_STD_NTSC
))
3726 norm
= VIDEO_MODE_NTSC
;
3727 else if ((*std
& V4L2_STD_SECAM
) && !(*std
& ~V4L2_STD_SECAM
))
3728 norm
= VIDEO_MODE_SECAM
;
3729 else if (*std
== V4L2_STD_ALL
)
3730 norm
= VIDEO_MODE_AUTO
;
3734 "%s: VIDIOC_S_STD - invalid norm 0x%llx\n",
3735 ZR_DEVNAME(zr
), (unsigned long long)*std
);
3739 mutex_lock(&zr
->resource_lock
);
3740 if ((res
= zoran_set_norm(zr
, norm
)))
3741 goto sstd_unlock_and_return
;
3743 res
= wait_grab_pending(zr
);
3744 sstd_unlock_and_return
:
3745 mutex_unlock(&zr
->resource_lock
);
3750 case VIDIOC_ENUMINPUT
:
3752 struct v4l2_input
*inp
= arg
;
3755 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMINPUT - index=%d\n",
3756 ZR_DEVNAME(zr
), inp
->index
);
3758 if (inp
->index
< 0 || inp
->index
>= zr
->card
.inputs
)
3761 int id
= inp
->index
;
3762 memset(inp
, 0, sizeof(*inp
));
3766 strncpy(inp
->name
, zr
->card
.input
[inp
->index
].name
,
3767 sizeof(inp
->name
) - 1);
3768 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
3769 inp
->std
= V4L2_STD_ALL
;
3771 /* Get status of video decoder */
3772 mutex_lock(&zr
->resource_lock
);
3773 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
3774 mutex_unlock(&zr
->resource_lock
);
3776 if (!(status
& DECODER_STATUS_GOOD
)) {
3777 inp
->status
|= V4L2_IN_ST_NO_POWER
;
3778 inp
->status
|= V4L2_IN_ST_NO_SIGNAL
;
3780 if (!(status
& DECODER_STATUS_COLOR
))
3781 inp
->status
|= V4L2_IN_ST_NO_COLOR
;
3787 case VIDIOC_G_INPUT
:
3791 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr
));
3793 mutex_lock(&zr
->resource_lock
);
3795 mutex_unlock(&zr
->resource_lock
);
3801 case VIDIOC_S_INPUT
:
3803 int *input
= arg
, res
= 0;
3805 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_INPUT - input=%d\n",
3806 ZR_DEVNAME(zr
), *input
);
3808 mutex_lock(&zr
->resource_lock
);
3809 if ((res
= zoran_set_input(zr
, *input
)))
3810 goto sinput_unlock_and_return
;
3812 /* Make sure the changes come into effect */
3813 res
= wait_grab_pending(zr
);
3814 sinput_unlock_and_return
:
3815 mutex_unlock(&zr
->resource_lock
);
3820 case VIDIOC_ENUMOUTPUT
:
3822 struct v4l2_output
*outp
= arg
;
3824 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMOUTPUT - index=%d\n",
3825 ZR_DEVNAME(zr
), outp
->index
);
3827 if (outp
->index
!= 0)
3830 memset(outp
, 0, sizeof(*outp
));
3832 outp
->type
= V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY
;
3833 strncpy(outp
->name
, "Autodetect", sizeof(outp
->name
)-1);
3839 case VIDIOC_G_OUTPUT
:
3843 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_OUTPUT\n", ZR_DEVNAME(zr
));
3851 case VIDIOC_S_OUTPUT
:
3855 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_OUTPUT - output=%d\n",
3856 ZR_DEVNAME(zr
), *output
);
3865 /* cropping (sub-frame capture) */
3866 case VIDIOC_CROPCAP
:
3868 struct v4l2_cropcap
*cropcap
= arg
;
3869 int type
= cropcap
->type
, res
= 0;
3871 dprintk(3, KERN_ERR
"%s: VIDIOC_CROPCAP - type=%d\n",
3872 ZR_DEVNAME(zr
), cropcap
->type
);
3874 memset(cropcap
, 0, sizeof(*cropcap
));
3875 cropcap
->type
= type
;
3877 mutex_lock(&zr
->resource_lock
);
3879 if (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3880 (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3881 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3884 "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n",
3887 goto cropcap_unlock_and_return
;
3890 cropcap
->bounds
.top
= cropcap
->bounds
.left
= 0;
3891 cropcap
->bounds
.width
= BUZ_MAX_WIDTH
;
3892 cropcap
->bounds
.height
= BUZ_MAX_HEIGHT
;
3893 cropcap
->defrect
.top
= cropcap
->defrect
.left
= 0;
3894 cropcap
->defrect
.width
= BUZ_MIN_WIDTH
;
3895 cropcap
->defrect
.height
= BUZ_MIN_HEIGHT
;
3896 cropcap_unlock_and_return
:
3897 mutex_unlock(&zr
->resource_lock
);
3904 struct v4l2_crop
*crop
= arg
;
3905 int type
= crop
->type
, res
= 0;
3907 dprintk(3, KERN_ERR
"%s: VIDIOC_G_CROP - type=%d\n",
3908 ZR_DEVNAME(zr
), crop
->type
);
3910 memset(crop
, 0, sizeof(*crop
));
3913 mutex_lock(&zr
->resource_lock
);
3915 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3916 (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3917 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3920 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
3923 goto gcrop_unlock_and_return
;
3926 crop
->c
.top
= fh
->jpg_settings
.img_y
;
3927 crop
->c
.left
= fh
->jpg_settings
.img_x
;
3928 crop
->c
.width
= fh
->jpg_settings
.img_width
;
3929 crop
->c
.height
= fh
->jpg_settings
.img_height
;
3931 gcrop_unlock_and_return
:
3932 mutex_unlock(&zr
->resource_lock
);
3940 struct v4l2_crop
*crop
= arg
;
3943 settings
= fh
->jpg_settings
;
3947 "%s: VIDIOC_S_CROP - type=%d, x=%d,y=%d,w=%d,h=%d\n",
3948 ZR_DEVNAME(zr
), crop
->type
, crop
->c
.left
, crop
->c
.top
,
3949 crop
->c
.width
, crop
->c
.height
);
3951 mutex_lock(&zr
->resource_lock
);
3953 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
3956 "%s: VIDIOC_S_CROP - cannot change settings while active\n",
3959 goto scrop_unlock_and_return
;
3962 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3963 (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3964 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3967 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
3970 goto scrop_unlock_and_return
;
3973 /* move into a form that we understand */
3974 settings
.img_x
= crop
->c
.left
;
3975 settings
.img_y
= crop
->c
.top
;
3976 settings
.img_width
= crop
->c
.width
;
3977 settings
.img_height
= crop
->c
.height
;
3979 /* check validity */
3980 if ((res
= zoran_check_jpg_settings(zr
, &settings
)))
3981 goto scrop_unlock_and_return
;
3984 fh
->jpg_settings
= settings
;
3986 scrop_unlock_and_return
:
3987 mutex_unlock(&zr
->resource_lock
);
3992 case VIDIOC_G_JPEGCOMP
:
3994 struct v4l2_jpegcompression
*params
= arg
;
3996 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_JPEGCOMP\n",
3999 memset(params
, 0, sizeof(*params
));
4001 mutex_lock(&zr
->resource_lock
);
4003 params
->quality
= fh
->jpg_settings
.jpg_comp
.quality
;
4004 params
->APPn
= fh
->jpg_settings
.jpg_comp
.APPn
;
4005 memcpy(params
->APP_data
,
4006 fh
->jpg_settings
.jpg_comp
.APP_data
,
4007 fh
->jpg_settings
.jpg_comp
.APP_len
);
4008 params
->APP_len
= fh
->jpg_settings
.jpg_comp
.APP_len
;
4009 memcpy(params
->COM_data
,
4010 fh
->jpg_settings
.jpg_comp
.COM_data
,
4011 fh
->jpg_settings
.jpg_comp
.COM_len
);
4012 params
->COM_len
= fh
->jpg_settings
.jpg_comp
.COM_len
;
4013 params
->jpeg_markers
=
4014 fh
->jpg_settings
.jpg_comp
.jpeg_markers
;
4016 mutex_unlock(&zr
->resource_lock
);
4022 case VIDIOC_S_JPEGCOMP
:
4024 struct v4l2_jpegcompression
*params
= arg
;
4027 settings
= fh
->jpg_settings
;
4031 "%s: VIDIOC_S_JPEGCOMP - quality=%d, APPN=%d, APP_len=%d, COM_len=%d\n",
4032 ZR_DEVNAME(zr
), params
->quality
, params
->APPn
,
4033 params
->APP_len
, params
->COM_len
);
4035 settings
.jpg_comp
= *params
;
4037 mutex_lock(&zr
->resource_lock
);
4039 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
||
4040 fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
4043 "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n",
4046 goto sjpegc_unlock_and_return
;
4049 if ((res
= zoran_check_jpg_settings(zr
, &settings
)))
4050 goto sjpegc_unlock_and_return
;
4051 if (!fh
->jpg_buffers
.allocated
)
4052 fh
->jpg_buffers
.buffer_size
=
4053 zoran_v4l2_calc_bufsize(&fh
->jpg_settings
);
4054 fh
->jpg_settings
.jpg_comp
= *params
= settings
.jpg_comp
;
4055 sjpegc_unlock_and_return
:
4056 mutex_unlock(&zr
->resource_lock
);
4062 case VIDIOC_QUERYSTD
: /* why is this useful? */
4064 v4l2_std_id
*std
= arg
;
4067 KERN_DEBUG
"%s: VIDIOC_QUERY_STD - std=0x%llx\n",
4068 ZR_DEVNAME(zr
), (unsigned long long)*std
);
4070 if (*std
== V4L2_STD_ALL
|| *std
== V4L2_STD_NTSC
||
4071 *std
== V4L2_STD_PAL
|| (*std
== V4L2_STD_SECAM
&&
4072 zr
->card
.norms
== 3)) {
4080 case VIDIOC_TRY_FMT
:
4082 struct v4l2_format
*fmt
= arg
;
4085 dprintk(3, KERN_DEBUG
"%s: VIDIOC_TRY_FMT - type=%d\n",
4086 ZR_DEVNAME(zr
), fmt
->type
);
4088 switch (fmt
->type
) {
4089 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
4090 mutex_lock(&zr
->resource_lock
);
4092 if (fmt
->fmt
.win
.w
.width
> BUZ_MAX_WIDTH
)
4093 fmt
->fmt
.win
.w
.width
= BUZ_MAX_WIDTH
;
4094 if (fmt
->fmt
.win
.w
.width
< BUZ_MIN_WIDTH
)
4095 fmt
->fmt
.win
.w
.width
= BUZ_MIN_WIDTH
;
4096 if (fmt
->fmt
.win
.w
.height
> BUZ_MAX_HEIGHT
)
4097 fmt
->fmt
.win
.w
.height
= BUZ_MAX_HEIGHT
;
4098 if (fmt
->fmt
.win
.w
.height
< BUZ_MIN_HEIGHT
)
4099 fmt
->fmt
.win
.w
.height
= BUZ_MIN_HEIGHT
;
4101 mutex_unlock(&zr
->resource_lock
);
4104 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
4105 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
4106 if (fmt
->fmt
.pix
.bytesperline
> 0)
4109 mutex_lock(&zr
->resource_lock
);
4111 if (fmt
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_MJPEG
) {
4112 settings
= fh
->jpg_settings
;
4114 /* we actually need to set 'real' parameters now */
4115 if ((fmt
->fmt
.pix
.height
* 2) >
4117 settings
.TmpDcm
= 1;
4119 settings
.TmpDcm
= 2;
4120 settings
.decimation
= 0;
4121 if (fmt
->fmt
.pix
.height
<=
4122 fh
->jpg_settings
.img_height
/ 2)
4123 settings
.VerDcm
= 2;
4125 settings
.VerDcm
= 1;
4126 if (fmt
->fmt
.pix
.width
<=
4127 fh
->jpg_settings
.img_width
/ 4)
4128 settings
.HorDcm
= 4;
4129 else if (fmt
->fmt
.pix
.width
<=
4130 fh
->jpg_settings
.img_width
/ 2)
4131 settings
.HorDcm
= 2;
4133 settings
.HorDcm
= 1;
4134 if (settings
.TmpDcm
== 1)
4135 settings
.field_per_buff
= 2;
4137 settings
.field_per_buff
= 1;
4141 zoran_check_jpg_settings(zr
,
4143 goto tryfmt_unlock_and_return
;
4145 /* tell the user what we actually did */
4146 fmt
->fmt
.pix
.width
=
4147 settings
.img_width
/ settings
.HorDcm
;
4148 fmt
->fmt
.pix
.height
=
4149 settings
.img_height
* 2 /
4150 (settings
.TmpDcm
* settings
.VerDcm
);
4151 if (settings
.TmpDcm
== 1)
4152 fmt
->fmt
.pix
.field
=
4154 odd_even
? V4L2_FIELD_SEQ_TB
:
4157 fmt
->fmt
.pix
.field
=
4159 odd_even
? V4L2_FIELD_TOP
:
4162 fmt
->fmt
.pix
.sizeimage
=
4163 zoran_v4l2_calc_bufsize(&settings
);
4164 } else if (fmt
->type
==
4165 V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
4168 for (i
= 0; i
< NUM_FORMATS
; i
++)
4169 if (zoran_formats
[i
].fourcc
==
4170 fmt
->fmt
.pix
.pixelformat
)
4172 if (i
== NUM_FORMATS
) {
4174 goto tryfmt_unlock_and_return
;
4177 if (fmt
->fmt
.pix
.width
> BUZ_MAX_WIDTH
)
4178 fmt
->fmt
.pix
.width
= BUZ_MAX_WIDTH
;
4179 if (fmt
->fmt
.pix
.width
< BUZ_MIN_WIDTH
)
4180 fmt
->fmt
.pix
.width
= BUZ_MIN_WIDTH
;
4181 if (fmt
->fmt
.pix
.height
> BUZ_MAX_HEIGHT
)
4182 fmt
->fmt
.pix
.height
=
4184 if (fmt
->fmt
.pix
.height
< BUZ_MIN_HEIGHT
)
4185 fmt
->fmt
.pix
.height
=
4189 goto tryfmt_unlock_and_return
;
4191 tryfmt_unlock_and_return
:
4192 mutex_unlock(&zr
->resource_lock
);
4207 dprintk(1, KERN_DEBUG
"%s: UNKNOWN ioctl cmd: 0x%x\n",
4208 ZR_DEVNAME(zr
), cmd
);
4209 return -ENOIOCTLCMD
;
4218 zoran_ioctl (struct inode
*inode
,
4223 return video_usercopy(inode
, file
, cmd
, arg
, zoran_do_ioctl
);
4227 zoran_poll (struct file
*file
,
4230 struct zoran_fh
*fh
= file
->private_data
;
4231 struct zoran
*zr
= fh
->zr
;
4233 unsigned long flags
;
4235 /* we should check whether buffers are ready to be synced on
4236 * (w/o waits - O_NONBLOCK) here
4237 * if ready for read (sync), return POLLIN|POLLRDNORM,
4238 * if ready for write (sync), return POLLOUT|POLLWRNORM,
4239 * if error, return POLLERR,
4240 * if no buffers queued or so, return POLLNVAL
4243 mutex_lock(&zr
->resource_lock
);
4245 switch (fh
->map_mode
) {
4246 case ZORAN_MAP_MODE_RAW
:
4247 poll_wait(file
, &zr
->v4l_capq
, wait
);
4248 frame
= zr
->v4l_pend
[zr
->v4l_sync_tail
& V4L_MASK_FRAME
];
4250 spin_lock_irqsave(&zr
->spinlock
, flags
);
4253 "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n",
4254 ZR_DEVNAME(zr
), __FUNCTION__
,
4255 "FAL"[fh
->v4l_buffers
.active
], zr
->v4l_sync_tail
,
4256 "UPMD"[zr
->v4l_buffers
.buffer
[frame
].state
],
4257 zr
->v4l_pend_tail
, zr
->v4l_pend_head
);
4258 /* Process is the one capturing? */
4259 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
&&
4260 /* Buffer ready to DQBUF? */
4261 zr
->v4l_buffers
.buffer
[frame
].state
== BUZ_STATE_DONE
)
4262 res
= POLLIN
| POLLRDNORM
;
4263 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4267 case ZORAN_MAP_MODE_JPG_REC
:
4268 case ZORAN_MAP_MODE_JPG_PLAY
:
4269 poll_wait(file
, &zr
->jpg_capq
, wait
);
4270 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
& BUZ_MASK_FRAME
];
4272 spin_lock_irqsave(&zr
->spinlock
, flags
);
4275 "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n",
4276 ZR_DEVNAME(zr
), __FUNCTION__
,
4277 "FAL"[fh
->jpg_buffers
.active
], zr
->jpg_que_tail
,
4278 "UPMD"[zr
->jpg_buffers
.buffer
[frame
].state
],
4279 zr
->jpg_que_head
, zr
->jpg_dma_tail
, zr
->jpg_dma_head
);
4280 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
&&
4281 zr
->jpg_buffers
.buffer
[frame
].state
== BUZ_STATE_DONE
) {
4282 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
)
4283 res
= POLLIN
| POLLRDNORM
;
4285 res
= POLLOUT
| POLLWRNORM
;
4287 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4294 "%s: zoran_poll() - internal error, unknown map_mode=%d\n",
4295 ZR_DEVNAME(zr
), fh
->map_mode
);
4299 mutex_unlock(&zr
->resource_lock
);
4306 * This maps the buffers to user space.
4308 * Depending on the state of fh->map_mode
4309 * the V4L or the MJPEG buffers are mapped
4310 * per buffer or all together
4312 * Note that we need to connect to some
4313 * unmap signal event to unmap the de-allocate
4314 * the buffer accordingly (zoran_vm_close())
4318 zoran_vm_open (struct vm_area_struct
*vma
)
4320 struct zoran_mapping
*map
= vma
->vm_private_data
;
4326 zoran_vm_close (struct vm_area_struct
*vma
)
4328 struct zoran_mapping
*map
= vma
->vm_private_data
;
4329 struct file
*file
= map
->file
;
4330 struct zoran_fh
*fh
= file
->private_data
;
4331 struct zoran
*zr
= fh
->zr
;
4335 if (map
->count
== 0) {
4336 switch (fh
->map_mode
) {
4337 case ZORAN_MAP_MODE_JPG_REC
:
4338 case ZORAN_MAP_MODE_JPG_PLAY
:
4340 dprintk(3, KERN_INFO
"%s: munmap(MJPEG)\n",
4343 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
4344 if (fh
->jpg_buffers
.buffer
[i
].map
== map
) {
4345 fh
->jpg_buffers
.buffer
[i
].map
=
4351 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++)
4352 if (fh
->jpg_buffers
.buffer
[i
].map
)
4354 if (i
== fh
->jpg_buffers
.num_buffers
) {
4355 mutex_lock(&zr
->resource_lock
);
4357 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
4358 jpg_qbuf(file
, -1, zr
->codec_mode
);
4359 zr
->jpg_buffers
.allocated
= 0;
4360 zr
->jpg_buffers
.active
=
4361 fh
->jpg_buffers
.active
=
4364 //jpg_fbuffer_free(file);
4365 fh
->jpg_buffers
.allocated
= 0;
4366 fh
->jpg_buffers
.ready_to_be_freed
= 1;
4368 mutex_unlock(&zr
->resource_lock
);
4373 case ZORAN_MAP_MODE_RAW
:
4375 dprintk(3, KERN_INFO
"%s: munmap(V4L)\n",
4378 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++) {
4379 if (fh
->v4l_buffers
.buffer
[i
].map
== map
) {
4381 fh
->v4l_buffers
.buffer
[i
].map
=
4387 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++)
4388 if (fh
->v4l_buffers
.buffer
[i
].map
)
4390 if (i
== fh
->v4l_buffers
.num_buffers
) {
4391 mutex_lock(&zr
->resource_lock
);
4393 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
) {
4396 spin_lock_irqsave(&zr
->spinlock
, flags
);
4397 zr36057_set_memgrab(zr
, 0);
4398 zr
->v4l_buffers
.allocated
= 0;
4399 zr
->v4l_buffers
.active
=
4400 fh
->v4l_buffers
.active
=
4402 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4404 //v4l_fbuffer_free(file);
4405 fh
->v4l_buffers
.allocated
= 0;
4406 fh
->v4l_buffers
.ready_to_be_freed
= 1;
4408 mutex_unlock(&zr
->resource_lock
);
4415 "%s: munmap() - internal error - unknown map mode %d\n",
4416 ZR_DEVNAME(zr
), fh
->map_mode
);
4423 static struct vm_operations_struct zoran_vm_ops
= {
4424 .open
= zoran_vm_open
,
4425 .close
= zoran_vm_close
,
4429 zoran_mmap (struct file
*file
,
4430 struct vm_area_struct
*vma
)
4432 struct zoran_fh
*fh
= file
->private_data
;
4433 struct zoran
*zr
= fh
->zr
;
4434 unsigned long size
= (vma
->vm_end
- vma
->vm_start
);
4435 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
4437 unsigned long page
, start
= vma
->vm_start
, todo
, pos
, fraglen
;
4439 struct zoran_mapping
*map
;
4443 KERN_INFO
"%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n",
4445 fh
->map_mode
== ZORAN_MAP_MODE_RAW
? "V4L" : "MJPEG",
4446 vma
->vm_start
, vma
->vm_end
, size
);
4448 if (!(vma
->vm_flags
& VM_SHARED
) || !(vma
->vm_flags
& VM_READ
) ||
4449 !(vma
->vm_flags
& VM_WRITE
)) {
4452 "%s: mmap() - no MAP_SHARED/PROT_{READ,WRITE} given\n",
4457 switch (fh
->map_mode
) {
4459 case ZORAN_MAP_MODE_JPG_REC
:
4460 case ZORAN_MAP_MODE_JPG_PLAY
:
4463 mutex_lock(&zr
->resource_lock
);
4465 /* Map the MJPEG buffers */
4466 if (!fh
->jpg_buffers
.allocated
) {
4469 "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n",
4472 goto jpg_mmap_unlock_and_return
;
4475 first
= offset
/ fh
->jpg_buffers
.buffer_size
;
4476 last
= first
- 1 + size
/ fh
->jpg_buffers
.buffer_size
;
4477 if (offset
% fh
->jpg_buffers
.buffer_size
!= 0 ||
4478 size
% fh
->jpg_buffers
.buffer_size
!= 0 || first
< 0 ||
4479 last
< 0 || first
>= fh
->jpg_buffers
.num_buffers
||
4480 last
>= fh
->jpg_buffers
.num_buffers
) {
4483 "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
4484 ZR_DEVNAME(zr
), offset
, size
,
4485 fh
->jpg_buffers
.buffer_size
,
4486 fh
->jpg_buffers
.num_buffers
);
4488 goto jpg_mmap_unlock_and_return
;
4490 for (i
= first
; i
<= last
; i
++) {
4491 if (fh
->jpg_buffers
.buffer
[i
].map
) {
4494 "%s: mmap(MJPEG) - buffer %d already mapped\n",
4497 goto jpg_mmap_unlock_and_return
;
4501 /* map these buffers (v4l_buffers[i]) */
4502 map
= kmalloc(sizeof(struct zoran_mapping
), GFP_KERNEL
);
4505 goto jpg_mmap_unlock_and_return
;
4510 vma
->vm_ops
= &zoran_vm_ops
;
4511 vma
->vm_flags
|= VM_DONTEXPAND
;
4512 vma
->vm_private_data
= map
;
4514 for (i
= first
; i
<= last
; i
++) {
4516 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
4519 (le32_to_cpu(fh
->jpg_buffers
.buffer
[i
].
4520 frag_tab
[2 * j
+ 1]) & ~1) << 1;
4525 le32_to_cpu((unsigned long) fh
->jpg_buffers
.
4526 buffer
[i
].frag_tab
[2 * j
]);
4527 /* should just be pos on i386 */
4528 page
= virt_to_phys(bus_to_virt(pos
))
4530 if (remap_pfn_range(vma
, start
, page
,
4531 todo
, PAGE_SHARED
)) {
4534 "%s: zoran_mmap(V4L) - remap_pfn_range failed\n",
4537 goto jpg_mmap_unlock_and_return
;
4543 if (le32_to_cpu(fh
->jpg_buffers
.buffer
[i
].
4544 frag_tab
[2 * j
+ 1]) & 1)
4545 break; /* was last fragment */
4547 fh
->jpg_buffers
.buffer
[i
].map
= map
;
4552 jpg_mmap_unlock_and_return
:
4553 mutex_unlock(&zr
->resource_lock
);
4557 case ZORAN_MAP_MODE_RAW
:
4559 mutex_lock(&zr
->resource_lock
);
4561 /* Map the V4L buffers */
4562 if (!fh
->v4l_buffers
.allocated
) {
4565 "%s: zoran_mmap(V4L) - buffers not yet allocated\n",
4568 goto v4l_mmap_unlock_and_return
;
4571 first
= offset
/ fh
->v4l_buffers
.buffer_size
;
4572 last
= first
- 1 + size
/ fh
->v4l_buffers
.buffer_size
;
4573 if (offset
% fh
->v4l_buffers
.buffer_size
!= 0 ||
4574 size
% fh
->v4l_buffers
.buffer_size
!= 0 || first
< 0 ||
4575 last
< 0 || first
>= fh
->v4l_buffers
.num_buffers
||
4576 last
>= fh
->v4l_buffers
.buffer_size
) {
4579 "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
4580 ZR_DEVNAME(zr
), offset
, size
,
4581 fh
->v4l_buffers
.buffer_size
,
4582 fh
->v4l_buffers
.num_buffers
);
4584 goto v4l_mmap_unlock_and_return
;
4586 for (i
= first
; i
<= last
; i
++) {
4587 if (fh
->v4l_buffers
.buffer
[i
].map
) {
4590 "%s: mmap(V4L) - buffer %d already mapped\n",
4593 goto v4l_mmap_unlock_and_return
;
4597 /* map these buffers (v4l_buffers[i]) */
4598 map
= kmalloc(sizeof(struct zoran_mapping
), GFP_KERNEL
);
4601 goto v4l_mmap_unlock_and_return
;
4606 vma
->vm_ops
= &zoran_vm_ops
;
4607 vma
->vm_flags
|= VM_DONTEXPAND
;
4608 vma
->vm_private_data
= map
;
4610 for (i
= first
; i
<= last
; i
++) {
4612 if (todo
> fh
->v4l_buffers
.buffer_size
)
4613 todo
= fh
->v4l_buffers
.buffer_size
;
4614 page
= fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
;
4615 if (remap_pfn_range(vma
, start
, page
>> PAGE_SHIFT
,
4616 todo
, PAGE_SHARED
)) {
4619 "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n",
4622 goto v4l_mmap_unlock_and_return
;
4626 fh
->v4l_buffers
.buffer
[i
].map
= map
;
4630 v4l_mmap_unlock_and_return
:
4631 mutex_unlock(&zr
->resource_lock
);
4638 "%s: zoran_mmap() - internal error - unknown map mode %d\n",
4639 ZR_DEVNAME(zr
), fh
->map_mode
);
4646 static const struct file_operations zoran_fops
= {
4647 .owner
= THIS_MODULE
,
4649 .release
= zoran_close
,
4650 .ioctl
= zoran_ioctl
,
4651 .compat_ioctl
= v4l_compat_ioctl32
,
4652 .llseek
= no_llseek
,
4654 .write
= zoran_write
,
4659 struct video_device zoran_template __devinitdata
= {
4661 .type
= ZORAN_VID_TYPE
,
4662 #ifdef CONFIG_VIDEO_V4L2
4663 .type2
= ZORAN_V4L2_VID_FLAGS
,
4665 .hardware
= ZORAN_HARDWARE
,
4666 .fops
= &zoran_fops
,
4667 .release
= &zoran_vdev_release
,