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
) {
342 mem
= kmalloc(fh
->v4l_buffers
.buffer_size
, GFP_KERNEL
);
346 "%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n",
348 v4l_fbuffer_free(file
);
351 fh
->v4l_buffers
.buffer
[i
].fbuffer
= mem
;
352 fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
=
354 fh
->v4l_buffers
.buffer
[i
].fbuffer_bus
=
356 for (off
= 0; off
< fh
->v4l_buffers
.buffer_size
;
358 SetPageReserved(MAP_NR(mem
+ off
));
361 "%s: v4l_fbuffer_alloc() - V4L frame %d mem 0x%lx (bus: 0x%lx)\n",
362 ZR_DEVNAME(zr
), i
, (unsigned long) mem
,
366 /* Use high memory which has been left at boot time */
368 /* Ok., Ok. this is an evil hack - we make
369 * the assumption that physical addresses are
370 * the same as bus addresses (true at least
371 * for Intel processors). The whole method of
372 * obtaining and using this memory is not very
373 * nice - but I hope it saves some poor users
374 * from kernel hacking, which might have even
375 * more evil results */
379 fh
->v4l_buffers
.num_buffers
*
380 fh
->v4l_buffers
.buffer_size
;
382 pmem
= get_high_mem(size
);
386 "%s: v4l_fbuffer_alloc() - get_high_mem (size = %d KB) for V4L bufs failed\n",
387 ZR_DEVNAME(zr
), size
>> 10);
390 fh
->v4l_buffers
.buffer
[0].fbuffer
= NULL
;
391 fh
->v4l_buffers
.buffer
[0].fbuffer_phys
= pmem
;
392 fh
->v4l_buffers
.buffer
[0].fbuffer_bus
= pmem
;
395 "%s: v4l_fbuffer_alloc() - using %d KB high memory\n",
396 ZR_DEVNAME(zr
), size
>> 10);
398 fh
->v4l_buffers
.buffer
[i
].fbuffer
= NULL
;
399 fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
=
400 pmem
+ i
* fh
->v4l_buffers
.buffer_size
;
401 fh
->v4l_buffers
.buffer
[i
].fbuffer_bus
=
402 pmem
+ i
* fh
->v4l_buffers
.buffer_size
;
407 fh
->v4l_buffers
.allocated
= 1;
412 /* free the V4L grab buffers */
414 v4l_fbuffer_free (struct file
*file
)
416 struct zoran_fh
*fh
= file
->private_data
;
417 struct zoran
*zr
= fh
->zr
;
421 dprintk(4, KERN_INFO
"%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr
));
423 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++) {
424 if (!fh
->v4l_buffers
.buffer
[i
].fbuffer
)
427 if (fh
->v4l_buffers
.buffer_size
<= MAX_KMALLOC_MEM
) {
428 mem
= fh
->v4l_buffers
.buffer
[i
].fbuffer
;
429 for (off
= 0; off
< fh
->v4l_buffers
.buffer_size
;
431 ClearPageReserved(MAP_NR(mem
+ off
));
432 kfree((void *) fh
->v4l_buffers
.buffer
[i
].fbuffer
);
434 fh
->v4l_buffers
.buffer
[i
].fbuffer
= NULL
;
437 fh
->v4l_buffers
.allocated
= 0;
438 fh
->v4l_buffers
.ready_to_be_freed
= 0;
442 * Allocate the MJPEG grab buffers.
444 * If the requested buffer size is smaller than MAX_KMALLOC_MEM,
445 * kmalloc is used to request a physically contiguous area,
446 * else we allocate the memory in framgents with get_zeroed_page.
448 * If a Natoma chipset is present and this is a revision 1 zr36057,
449 * each MJPEG buffer needs to be physically contiguous.
450 * (RJ: This statement is from Dave Perks' original driver,
451 * I could never check it because I have a zr36067)
452 * The driver cares about this because it reduces the buffer
453 * size to MAX_KMALLOC_MEM in that case (which forces contiguous allocation).
455 * RJ: The contents grab buffers needs never be accessed in the driver.
456 * Therefore there is no need to allocate them with vmalloc in order
457 * to get a contiguous virtual memory space.
458 * I don't understand why many other drivers first allocate them with
459 * vmalloc (which uses internally also get_zeroed_page, but delivers you
460 * virtual addresses) and then again have to make a lot of efforts
461 * to get the physical address.
464 * On big-endian architectures (such as ppc) some extra steps
465 * are needed. When reading and writing to the stat_com array
466 * and fragment buffers, the device expects to see little-
467 * endian values. The use of cpu_to_le32() and le32_to_cpu()
468 * in this function (and one or two others in zoran_device.c)
469 * ensure that these values are always stored in little-endian
470 * form, regardless of architecture. The zr36057 does Very Bad
471 * Things on big endian architectures if the stat_com array
472 * and fragment buffers are not little-endian.
476 jpg_fbuffer_alloc (struct file
*file
)
478 struct zoran_fh
*fh
= file
->private_data
;
479 struct zoran
*zr
= fh
->zr
;
483 /* we might have old buffers lying around */
484 if (fh
->jpg_buffers
.ready_to_be_freed
) {
485 jpg_fbuffer_free(file
);
488 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
489 if (fh
->jpg_buffers
.buffer
[i
].frag_tab
)
492 "%s: jpg_fbuffer_alloc() - buffer %d allready allocated!?\n",
495 /* Allocate fragment table for this buffer */
497 mem
= get_zeroed_page(GFP_KERNEL
);
501 "%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n",
503 jpg_fbuffer_free(file
);
506 fh
->jpg_buffers
.buffer
[i
].frag_tab
= (u32
*) mem
;
507 fh
->jpg_buffers
.buffer
[i
].frag_tab_bus
=
508 virt_to_bus((void *) mem
);
510 //if (alloc_contig) {
511 if (fh
->jpg_buffers
.need_contiguous
) {
513 (unsigned long) kmalloc(fh
->jpg_buffers
.
519 "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n",
521 jpg_fbuffer_free(file
);
524 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0] =
525 cpu_to_le32(virt_to_bus((void *) mem
));
526 fh
->jpg_buffers
.buffer
[i
].frag_tab
[1] =
527 cpu_to_le32(((fh
->jpg_buffers
.buffer_size
/ 4) << 1) | 1);
528 for (off
= 0; off
< fh
->jpg_buffers
.buffer_size
;
530 SetPageReserved(MAP_NR(mem
+ off
));
532 /* jpg_bufsize is allreay page aligned */
534 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
536 mem
= get_zeroed_page(GFP_KERNEL
);
540 "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n",
542 jpg_fbuffer_free(file
);
546 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
] =
547 cpu_to_le32(virt_to_bus((void *) mem
));
548 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
+
550 cpu_to_le32((PAGE_SIZE
/ 4) << 1);
551 SetPageReserved(MAP_NR(mem
));
554 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
- 1] |= cpu_to_le32(1);
559 KERN_DEBUG
"%s: jpg_fbuffer_alloc() - %d KB allocated\n",
561 (fh
->jpg_buffers
.num_buffers
*
562 fh
->jpg_buffers
.buffer_size
) >> 10);
564 fh
->jpg_buffers
.allocated
= 1;
569 /* free the MJPEG grab buffers */
571 jpg_fbuffer_free (struct file
*file
)
573 struct zoran_fh
*fh
= file
->private_data
;
574 struct zoran
*zr
= fh
->zr
;
578 dprintk(4, KERN_DEBUG
"%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr
));
580 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
581 if (!fh
->jpg_buffers
.buffer
[i
].frag_tab
)
584 //if (alloc_contig) {
585 if (fh
->jpg_buffers
.need_contiguous
) {
586 if (fh
->jpg_buffers
.buffer
[i
].frag_tab
[0]) {
587 mem
= (unsigned char *) bus_to_virt(le32_to_cpu(
588 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0]));
590 off
< fh
->jpg_buffers
.buffer_size
;
592 ClearPageReserved(MAP_NR
595 fh
->jpg_buffers
.buffer
[i
].frag_tab
[0] = 0;
596 fh
->jpg_buffers
.buffer
[i
].frag_tab
[1] = 0;
600 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
602 if (!fh
->jpg_buffers
.buffer
[i
].
605 ClearPageReserved(MAP_NR
609 buffer
[i
].frag_tab
[2 *
611 free_page((unsigned long)
617 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
] =
619 fh
->jpg_buffers
.buffer
[i
].frag_tab
[2 * j
+
624 free_page((unsigned long) fh
->jpg_buffers
.buffer
[i
].
626 fh
->jpg_buffers
.buffer
[i
].frag_tab
= NULL
;
629 fh
->jpg_buffers
.allocated
= 0;
630 fh
->jpg_buffers
.ready_to_be_freed
= 0;
634 * V4L Buffer grabbing
638 zoran_v4l_set_format (struct file
*file
,
641 const struct zoran_format
*format
)
643 struct zoran_fh
*fh
= file
->private_data
;
644 struct zoran
*zr
= fh
->zr
;
647 /* Check size and format of the grab wanted */
649 if (height
< BUZ_MIN_HEIGHT
|| width
< BUZ_MIN_WIDTH
||
650 height
> BUZ_MAX_HEIGHT
|| width
> BUZ_MAX_WIDTH
) {
653 "%s: v4l_set_format() - wrong frame size (%dx%d)\n",
654 ZR_DEVNAME(zr
), width
, height
);
658 bpp
= (format
->depth
+ 7) / 8;
660 /* Check against available buffer size */
661 if (height
* width
* bpp
> fh
->v4l_buffers
.buffer_size
) {
664 "%s: v4l_set_format() - video buffer size (%d kB) is too small\n",
665 ZR_DEVNAME(zr
), fh
->v4l_buffers
.buffer_size
>> 10);
669 /* The video front end needs 4-byte alinged line sizes */
671 if ((bpp
== 2 && (width
& 1)) || (bpp
== 3 && (width
& 3))) {
674 "%s: v4l_set_format() - wrong frame alingment\n",
679 fh
->v4l_settings
.width
= width
;
680 fh
->v4l_settings
.height
= height
;
681 fh
->v4l_settings
.format
= format
;
682 fh
->v4l_settings
.bytesperline
= bpp
* fh
->v4l_settings
.width
;
688 zoran_v4l_queue_frame (struct file
*file
,
691 struct zoran_fh
*fh
= file
->private_data
;
692 struct zoran
*zr
= fh
->zr
;
696 if (!fh
->v4l_buffers
.allocated
) {
699 "%s: v4l_queue_frame() - buffers not yet allocated\n",
704 /* No grabbing outside the buffer range! */
705 if (num
>= fh
->v4l_buffers
.num_buffers
|| num
< 0) {
708 "%s: v4l_queue_frame() - buffer %d is out of range\n",
709 ZR_DEVNAME(zr
), num
);
713 spin_lock_irqsave(&zr
->spinlock
, flags
);
715 if (fh
->v4l_buffers
.active
== ZORAN_FREE
) {
716 if (zr
->v4l_buffers
.active
== ZORAN_FREE
) {
717 zr
->v4l_buffers
= fh
->v4l_buffers
;
718 fh
->v4l_buffers
.active
= ZORAN_ACTIVE
;
722 "%s: v4l_queue_frame() - another session is already capturing\n",
728 /* make sure a grab isn't going on currently with this buffer */
730 switch (zr
->v4l_buffers
.buffer
[num
].state
) {
733 if (zr
->v4l_buffers
.active
== ZORAN_FREE
) {
734 fh
->v4l_buffers
.active
= ZORAN_FREE
;
735 zr
->v4l_buffers
.allocated
= 0;
737 res
= -EBUSY
; /* what are you doing? */
742 "%s: v4l_queue_frame() - queueing buffer %d in state DONE!?\n",
743 ZR_DEVNAME(zr
), num
);
745 /* since there is at least one unused buffer there's room for at least
746 * one more pend[] entry */
747 zr
->v4l_pend
[zr
->v4l_pend_head
++ &
748 V4L_MASK_FRAME
] = num
;
749 zr
->v4l_buffers
.buffer
[num
].state
= BUZ_STATE_PEND
;
750 zr
->v4l_buffers
.buffer
[num
].bs
.length
=
751 fh
->v4l_settings
.bytesperline
*
752 zr
->v4l_settings
.height
;
753 fh
->v4l_buffers
.buffer
[num
] =
754 zr
->v4l_buffers
.buffer
[num
];
759 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
761 if (!res
&& zr
->v4l_buffers
.active
== ZORAN_FREE
)
762 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
;
768 v4l_grab (struct file
*file
,
769 struct video_mmap
*mp
)
771 struct zoran_fh
*fh
= file
->private_data
;
772 struct zoran
*zr
= fh
->zr
;
775 for (i
= 0; i
< NUM_FORMATS
; i
++) {
776 if (zoran_formats
[i
].palette
== mp
->format
&&
777 zoran_formats
[i
].flags
& ZORAN_FORMAT_CAPTURE
&&
778 !(zoran_formats
[i
].flags
& ZORAN_FORMAT_COMPRESSED
))
781 if (i
== NUM_FORMATS
|| zoran_formats
[i
].depth
== 0) {
784 "%s: v4l_grab() - wrong bytes-per-pixel format\n",
790 * To minimize the time spent in the IRQ routine, we avoid setting up
791 * the video front end there.
792 * If this grab has different parameters from a running streaming capture
793 * we stop the streaming capture and start it over again.
795 if (zr
->v4l_memgrab_active
&&
796 (zr
->v4l_settings
.width
!= mp
->width
||
797 zr
->v4l_settings
.height
!= mp
->height
||
798 zr
->v4l_settings
.format
->palette
!= mp
->format
)) {
799 res
= wait_grab_pending(zr
);
803 if ((res
= zoran_v4l_set_format(file
,
808 zr
->v4l_settings
= fh
->v4l_settings
;
810 /* queue the frame in the pending queue */
811 if ((res
= zoran_v4l_queue_frame(file
, mp
->frame
))) {
812 fh
->v4l_buffers
.active
= ZORAN_FREE
;
816 /* put the 36057 into frame grabbing mode */
817 if (!res
&& !zr
->v4l_memgrab_active
)
818 zr36057_set_memgrab(zr
, 1);
820 //dprintk(4, KERN_INFO "%s: Frame grab 3...\n", ZR_DEVNAME(zr));
826 * Sync on a V4L buffer
830 v4l_sync (struct file
*file
,
833 struct zoran_fh
*fh
= file
->private_data
;
834 struct zoran
*zr
= fh
->zr
;
837 if (fh
->v4l_buffers
.active
== ZORAN_FREE
) {
840 "%s: v4l_sync() - no grab active for this session\n",
845 /* check passed-in frame number */
846 if (frame
>= fh
->v4l_buffers
.num_buffers
|| frame
< 0) {
848 KERN_ERR
"%s: v4l_sync() - frame %d is invalid\n",
849 ZR_DEVNAME(zr
), frame
);
853 /* Check if is buffer was queued at all */
854 if (zr
->v4l_buffers
.buffer
[frame
].state
== BUZ_STATE_USER
) {
857 "%s: v4l_sync() - attempt to sync on a buffer which was not queued?\n",
862 /* wait on this buffer to get ready */
863 if (!wait_event_interruptible_timeout(zr
->v4l_capq
,
864 (zr
->v4l_buffers
.buffer
[frame
].state
!= BUZ_STATE_PEND
),
867 if (signal_pending(current
))
870 /* buffer should now be in BUZ_STATE_DONE */
871 if (zr
->v4l_buffers
.buffer
[frame
].state
!= BUZ_STATE_DONE
)
873 KERN_ERR
"%s: v4l_sync() - internal state error\n",
876 zr
->v4l_buffers
.buffer
[frame
].state
= BUZ_STATE_USER
;
877 fh
->v4l_buffers
.buffer
[frame
] = zr
->v4l_buffers
.buffer
[frame
];
879 spin_lock_irqsave(&zr
->spinlock
, flags
);
881 /* Check if streaming capture has finished */
882 if (zr
->v4l_pend_tail
== zr
->v4l_pend_head
) {
883 zr36057_set_memgrab(zr
, 0);
884 if (zr
->v4l_buffers
.active
== ZORAN_ACTIVE
) {
885 fh
->v4l_buffers
.active
= zr
->v4l_buffers
.active
=
887 zr
->v4l_buffers
.allocated
= 0;
891 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
897 * Queue a MJPEG buffer for capture/playback
901 zoran_jpg_queue_frame (struct file
*file
,
903 enum zoran_codec_mode mode
)
905 struct zoran_fh
*fh
= file
->private_data
;
906 struct zoran
*zr
= fh
->zr
;
910 /* Check if buffers are allocated */
911 if (!fh
->jpg_buffers
.allocated
) {
914 "%s: jpg_queue_frame() - buffers not yet allocated\n",
919 /* No grabbing outside the buffer range! */
920 if (num
>= fh
->jpg_buffers
.num_buffers
|| num
< 0) {
923 "%s: jpg_queue_frame() - buffer %d out of range\n",
924 ZR_DEVNAME(zr
), num
);
928 /* what is the codec mode right now? */
929 if (zr
->codec_mode
== BUZ_MODE_IDLE
) {
930 zr
->jpg_settings
= fh
->jpg_settings
;
931 } else if (zr
->codec_mode
!= mode
) {
932 /* wrong codec mode active - invalid */
935 "%s: jpg_queue_frame() - codec in wrong mode\n",
940 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
941 if (zr
->jpg_buffers
.active
== ZORAN_FREE
) {
942 zr
->jpg_buffers
= fh
->jpg_buffers
;
943 fh
->jpg_buffers
.active
= ZORAN_ACTIVE
;
947 "%s: jpg_queue_frame() - another session is already capturing\n",
953 if (!res
&& zr
->codec_mode
== BUZ_MODE_IDLE
) {
954 /* Ok load up the jpeg codec */
955 zr36057_enable_jpg(zr
, mode
);
958 spin_lock_irqsave(&zr
->spinlock
, flags
);
961 switch (zr
->jpg_buffers
.buffer
[num
].state
) {
965 "%s: jpg_queue_frame() - queing frame in BUZ_STATE_DONE state!?\n",
968 /* since there is at least one unused buffer there's room for at
969 *least one more pend[] entry */
970 zr
->jpg_pend
[zr
->jpg_que_head
++ & BUZ_MASK_FRAME
] =
972 zr
->jpg_buffers
.buffer
[num
].state
= BUZ_STATE_PEND
;
973 fh
->jpg_buffers
.buffer
[num
] =
974 zr
->jpg_buffers
.buffer
[num
];
975 zoran_feed_stat_com(zr
);
980 if (zr
->jpg_buffers
.active
== ZORAN_FREE
) {
981 fh
->jpg_buffers
.active
= ZORAN_FREE
;
982 zr
->jpg_buffers
.allocated
= 0;
984 res
= -EBUSY
; /* what are you doing? */
989 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
991 if (!res
&& zr
->jpg_buffers
.active
== ZORAN_FREE
) {
992 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
;
999 jpg_qbuf (struct file
*file
,
1001 enum zoran_codec_mode mode
)
1003 struct zoran_fh
*fh
= file
->private_data
;
1004 struct zoran
*zr
= fh
->zr
;
1007 /* Does the user want to stop streaming? */
1009 if (zr
->codec_mode
== mode
) {
1010 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
1013 "%s: jpg_qbuf(-1) - session not active\n",
1017 fh
->jpg_buffers
.active
= zr
->jpg_buffers
.active
=
1019 zr
->jpg_buffers
.allocated
= 0;
1020 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1025 "%s: jpg_qbuf() - stop streaming but not in streaming mode\n",
1031 if ((res
= zoran_jpg_queue_frame(file
, frame
, mode
)))
1034 /* Start the jpeg codec when the first frame is queued */
1035 if (!res
&& zr
->jpg_que_head
== 1)
1042 * Sync on a MJPEG buffer
1046 jpg_sync (struct file
*file
,
1047 struct zoran_sync
*bs
)
1049 struct zoran_fh
*fh
= file
->private_data
;
1050 struct zoran
*zr
= fh
->zr
;
1051 unsigned long flags
;
1054 if (fh
->jpg_buffers
.active
== ZORAN_FREE
) {
1057 "%s: jpg_sync() - capture is not currently active\n",
1061 if (zr
->codec_mode
!= BUZ_MODE_MOTION_DECOMPRESS
&&
1062 zr
->codec_mode
!= BUZ_MODE_MOTION_COMPRESS
) {
1065 "%s: jpg_sync() - codec not in streaming mode\n",
1069 if (!wait_event_interruptible_timeout(zr
->jpg_capq
,
1070 (zr
->jpg_que_tail
!= zr
->jpg_dma_tail
||
1071 zr
->jpg_dma_tail
== zr
->jpg_dma_head
),
1075 btand(~ZR36057_JMC_Go_en
, ZR36057_JMC
);
1077 zr
->codec
->control(zr
->codec
, CODEC_G_STATUS
,
1081 "%s: jpg_sync() - timeout: codec isr=0x%02x\n",
1082 ZR_DEVNAME(zr
), isr
);
1087 if (signal_pending(current
))
1088 return -ERESTARTSYS
;
1090 spin_lock_irqsave(&zr
->spinlock
, flags
);
1092 if (zr
->jpg_dma_tail
!= zr
->jpg_dma_head
)
1093 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
++ & BUZ_MASK_FRAME
];
1095 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
& BUZ_MASK_FRAME
];
1097 /* buffer should now be in BUZ_STATE_DONE */
1098 if (zr
->jpg_buffers
.buffer
[frame
].state
!= BUZ_STATE_DONE
)
1100 KERN_ERR
"%s: jpg_sync() - internal state error\n",
1103 *bs
= zr
->jpg_buffers
.buffer
[frame
].bs
;
1105 zr
->jpg_buffers
.buffer
[frame
].state
= BUZ_STATE_USER
;
1106 fh
->jpg_buffers
.buffer
[frame
] = zr
->jpg_buffers
.buffer
[frame
];
1108 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1114 zoran_open_init_session (struct file
*file
)
1117 struct zoran_fh
*fh
= file
->private_data
;
1118 struct zoran
*zr
= fh
->zr
;
1120 /* Per default, map the V4L Buffers */
1121 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
1123 /* take over the card's current settings */
1124 fh
->overlay_settings
= zr
->overlay_settings
;
1125 fh
->overlay_settings
.is_set
= 0;
1126 fh
->overlay_settings
.format
= zr
->overlay_settings
.format
;
1127 fh
->overlay_active
= ZORAN_FREE
;
1130 fh
->v4l_settings
= zr
->v4l_settings
;
1133 memset(&fh
->v4l_buffers
, 0, sizeof(struct zoran_v4l_struct
));
1134 for (i
= 0; i
< VIDEO_MAX_FRAME
; i
++) {
1135 fh
->v4l_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
1136 fh
->v4l_buffers
.buffer
[i
].bs
.frame
= i
;
1138 fh
->v4l_buffers
.allocated
= 0;
1139 fh
->v4l_buffers
.ready_to_be_freed
= 0;
1140 fh
->v4l_buffers
.active
= ZORAN_FREE
;
1141 fh
->v4l_buffers
.buffer_size
= v4l_bufsize
;
1142 fh
->v4l_buffers
.num_buffers
= v4l_nbufs
;
1145 fh
->jpg_settings
= zr
->jpg_settings
;
1148 memset(&fh
->jpg_buffers
, 0, sizeof(struct zoran_jpg_struct
));
1149 for (i
= 0; i
< BUZ_MAX_FRAME
; i
++) {
1150 fh
->jpg_buffers
.buffer
[i
].state
= BUZ_STATE_USER
; /* nothing going on */
1151 fh
->jpg_buffers
.buffer
[i
].bs
.frame
= i
;
1153 fh
->jpg_buffers
.need_contiguous
= zr
->jpg_buffers
.need_contiguous
;
1154 fh
->jpg_buffers
.allocated
= 0;
1155 fh
->jpg_buffers
.ready_to_be_freed
= 0;
1156 fh
->jpg_buffers
.active
= ZORAN_FREE
;
1157 fh
->jpg_buffers
.buffer_size
= jpg_bufsize
;
1158 fh
->jpg_buffers
.num_buffers
= jpg_nbufs
;
1162 zoran_close_end_session (struct file
*file
)
1164 struct zoran_fh
*fh
= file
->private_data
;
1165 struct zoran
*zr
= fh
->zr
;
1168 if (fh
->overlay_active
!= ZORAN_FREE
) {
1169 fh
->overlay_active
= zr
->overlay_active
= ZORAN_FREE
;
1170 zr
->v4l_overlay_active
= 0;
1171 if (!zr
->v4l_memgrab_active
)
1172 zr36057_overlay(zr
, 0);
1173 zr
->overlay_mask
= NULL
;
1177 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
) {
1180 spin_lock_irqsave(&zr
->spinlock
, flags
);
1181 zr36057_set_memgrab(zr
, 0);
1182 zr
->v4l_buffers
.allocated
= 0;
1183 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
1185 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
1189 if (fh
->v4l_buffers
.allocated
||
1190 fh
->v4l_buffers
.ready_to_be_freed
) {
1191 v4l_fbuffer_free(file
);
1195 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
1196 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1197 zr
->jpg_buffers
.allocated
= 0;
1198 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
=
1203 if (fh
->jpg_buffers
.allocated
||
1204 fh
->jpg_buffers
.ready_to_be_freed
) {
1205 jpg_fbuffer_free(file
);
1210 * Open a zoran card. Right now the flags stuff is just playing
1214 zoran_open (struct inode
*inode
,
1217 unsigned int minor
= iminor(inode
);
1218 struct zoran
*zr
= NULL
;
1219 struct zoran_fh
*fh
;
1220 int i
, res
, first_open
= 0, have_module_locks
= 0;
1222 /* find the device */
1223 for (i
= 0; i
< zoran_num
; i
++) {
1224 if (zoran
[i
].video_dev
->minor
== minor
) {
1231 dprintk(1, KERN_ERR
"%s: device not found!\n", ZORAN_NAME
);
1233 goto open_unlock_and_return
;
1236 /* see fs/device.c - the kernel already locks during open(),
1237 * so locking ourselves only causes deadlocks */
1238 /*mutex_lock(&zr->resource_lock);*/
1242 KERN_ERR
"%s: no TV decoder loaded for device!\n",
1245 goto open_unlock_and_return
;
1248 /* try to grab a module lock */
1249 if (!try_module_get(THIS_MODULE
)) {
1252 "%s: failed to acquire my own lock! PANIC!\n",
1255 goto open_unlock_and_return
;
1257 if (!try_module_get(zr
->decoder
->driver
->driver
.owner
)) {
1260 "%s: failed to grab ownership of i2c decoder\n",
1263 module_put(THIS_MODULE
);
1264 goto open_unlock_and_return
;
1267 !try_module_get(zr
->encoder
->driver
->driver
.owner
)) {
1270 "%s: failed to grab ownership of i2c encoder\n",
1273 module_put(zr
->decoder
->driver
->driver
.owner
);
1274 module_put(THIS_MODULE
);
1275 goto open_unlock_and_return
;
1278 have_module_locks
= 1;
1280 if (zr
->user
>= 2048) {
1281 dprintk(1, KERN_ERR
"%s: too many users (%d) on device\n",
1282 ZR_DEVNAME(zr
), zr
->user
);
1284 goto open_unlock_and_return
;
1287 dprintk(1, KERN_INFO
"%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
1288 ZR_DEVNAME(zr
), current
->comm
, task_pid_nr(current
), zr
->user
);
1290 /* now, create the open()-specific file_ops struct */
1291 fh
= kzalloc(sizeof(struct zoran_fh
), GFP_KERNEL
);
1295 "%s: zoran_open() - allocation of zoran_fh failed\n",
1298 goto open_unlock_and_return
;
1300 /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
1301 * on norm-change! */
1303 kmalloc(((768 + 31) / 32) * 576 * 4, GFP_KERNEL
);
1304 if (!fh
->overlay_mask
) {
1307 "%s: zoran_open() - allocation of overlay_mask failed\n",
1311 goto open_unlock_and_return
;
1314 if (zr
->user
++ == 0)
1317 /*mutex_unlock(&zr->resource_lock);*/
1319 /* default setup - TODO: look at flags */
1320 if (first_open
) { /* First device open */
1321 zr36057_restart(zr
);
1322 zoran_open_init_params(zr
);
1323 zoran_init_hardware(zr
);
1325 btor(ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1328 /* set file_ops stuff */
1329 file
->private_data
= fh
;
1331 zoran_open_init_session(file
);
1335 open_unlock_and_return
:
1336 /* if we grabbed locks, release them accordingly */
1337 if (have_module_locks
) {
1338 module_put(zr
->decoder
->driver
->driver
.owner
);
1340 module_put(zr
->encoder
->driver
->driver
.owner
);
1342 module_put(THIS_MODULE
);
1345 /* if there's no device found, we didn't obtain the lock either */
1347 /*mutex_unlock(&zr->resource_lock);*/
1354 zoran_close (struct inode
*inode
,
1357 struct zoran_fh
*fh
= file
->private_data
;
1358 struct zoran
*zr
= fh
->zr
;
1360 dprintk(1, KERN_INFO
"%s: zoran_close(%s, pid=[%d]), users(+)=%d\n",
1361 ZR_DEVNAME(zr
), current
->comm
, task_pid_nr(current
), zr
->user
);
1363 /* kernel locks (fs/device.c), so don't do that ourselves
1364 * (prevents deadlocks) */
1365 /*mutex_lock(&zr->resource_lock);*/
1367 zoran_close_end_session(file
);
1369 if (zr
->user
-- == 1) { /* Last process */
1370 /* Clean up JPEG process */
1371 wake_up_interruptible(&zr
->jpg_capq
);
1372 zr36057_enable_jpg(zr
, BUZ_MODE_IDLE
);
1373 zr
->jpg_buffers
.allocated
= 0;
1374 zr
->jpg_buffers
.active
= ZORAN_FREE
;
1376 /* disable interrupts */
1377 btand(~ZR36057_ICR_IntPinEn
, ZR36057_ICR
);
1379 if (zr36067_debug
> 1)
1380 print_interrupts(zr
);
1383 zr
->v4l_overlay_active
= 0;
1384 zr36057_overlay(zr
, 0);
1385 zr
->overlay_mask
= NULL
;
1388 wake_up_interruptible(&zr
->v4l_capq
);
1389 zr36057_set_memgrab(zr
, 0);
1390 zr
->v4l_buffers
.allocated
= 0;
1391 zr
->v4l_buffers
.active
= ZORAN_FREE
;
1392 zoran_set_pci_master(zr
, 0);
1394 if (!pass_through
) { /* Switch to color bar */
1395 int zero
= 0, two
= 2;
1396 decoder_command(zr
, DECODER_ENABLE_OUTPUT
, &zero
);
1397 encoder_command(zr
, ENCODER_SET_INPUT
, &two
);
1401 file
->private_data
= NULL
;
1402 kfree(fh
->overlay_mask
);
1405 /* release locks on the i2c modules */
1406 module_put(zr
->decoder
->driver
->driver
.owner
);
1408 module_put(zr
->encoder
->driver
->driver
.owner
);
1410 module_put(THIS_MODULE
);
1412 /*mutex_unlock(&zr->resource_lock);*/
1414 dprintk(4, KERN_INFO
"%s: zoran_close() done\n", ZR_DEVNAME(zr
));
1421 zoran_read (struct file
*file
,
1426 /* we simply don't support read() (yet)... */
1432 zoran_write (struct file
*file
,
1433 const char __user
*data
,
1437 /* ...and the same goes for write() */
1443 setup_fbuffer (struct file
*file
,
1445 const struct zoran_format
*fmt
,
1450 struct zoran_fh
*fh
= file
->private_data
;
1451 struct zoran
*zr
= fh
->zr
;
1453 /* (Ronald) v4l/v4l2 guidelines */
1454 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
1457 /* Don't allow frame buffer overlay if PCI or AGP is buggy, or on
1458 ALi Magik (that needs very low latency while the card needs a
1459 higher value always) */
1461 if (pci_pci_problems
& (PCIPCI_FAIL
| PCIAGP_FAIL
| PCIPCI_ALIMAGIK
))
1464 /* we need a bytesperline value, even if not given */
1466 bytesperline
= width
* ((fmt
->depth
+ 7) & ~7) / 8;
1469 if (zr
->overlay_active
) {
1470 /* dzjee... stupid users... don't even bother to turn off
1471 * overlay before changing the memory location...
1472 * normally, we would return errors here. However, one of
1473 * the tools that does this is... xawtv! and since xawtv
1474 * is used by +/- 99% of the users, we'd rather be user-
1475 * friendly and silently do as if nothing went wrong */
1478 "%s: setup_fbuffer() - forced overlay turnoff because framebuffer changed\n",
1480 zr36057_overlay(zr
, 0);
1484 if (!(fmt
->flags
& ZORAN_FORMAT_OVERLAY
)) {
1487 "%s: setup_fbuffer() - no valid overlay format given\n",
1491 if (height
<= 0 || width
<= 0 || bytesperline
<= 0) {
1494 "%s: setup_fbuffer() - invalid height/width/bpl value (%d|%d|%d)\n",
1495 ZR_DEVNAME(zr
), width
, height
, bytesperline
);
1498 if (bytesperline
& 3) {
1501 "%s: setup_fbuffer() - bytesperline (%d) must be 4-byte aligned\n",
1502 ZR_DEVNAME(zr
), bytesperline
);
1506 zr
->buffer
.base
= (void *) ((unsigned long) base
& ~3);
1507 zr
->buffer
.height
= height
;
1508 zr
->buffer
.width
= width
;
1509 zr
->buffer
.depth
= fmt
->depth
;
1510 zr
->overlay_settings
.format
= fmt
;
1511 zr
->buffer
.bytesperline
= bytesperline
;
1513 /* The user should set new window parameters */
1514 zr
->overlay_settings
.is_set
= 0;
1521 setup_window (struct file
*file
,
1526 struct video_clip __user
*clips
,
1528 void __user
*bitmap
)
1530 struct zoran_fh
*fh
= file
->private_data
;
1531 struct zoran
*zr
= fh
->zr
;
1532 struct video_clip
*vcp
= NULL
;
1536 if (!zr
->buffer
.base
) {
1539 "%s: setup_window() - frame buffer has to be set first\n",
1544 if (!fh
->overlay_settings
.format
) {
1547 "%s: setup_window() - no overlay format set\n",
1553 * The video front end needs 4-byte alinged line sizes, we correct that
1554 * silently here if necessary
1556 if (zr
->buffer
.depth
== 15 || zr
->buffer
.depth
== 16) {
1557 end
= (x
+ width
) & ~1; /* round down */
1558 x
= (x
+ 1) & ~1; /* round up */
1562 if (zr
->buffer
.depth
== 24) {
1563 end
= (x
+ width
) & ~3; /* round down */
1564 x
= (x
+ 3) & ~3; /* round up */
1568 if (width
> BUZ_MAX_WIDTH
)
1569 width
= BUZ_MAX_WIDTH
;
1570 if (height
> BUZ_MAX_HEIGHT
)
1571 height
= BUZ_MAX_HEIGHT
;
1573 /* Check for vaild parameters */
1574 if (width
< BUZ_MIN_WIDTH
|| height
< BUZ_MIN_HEIGHT
||
1575 width
> BUZ_MAX_WIDTH
|| height
> BUZ_MAX_HEIGHT
) {
1578 "%s: setup_window() - width = %d or height = %d invalid\n",
1579 ZR_DEVNAME(zr
), width
, height
);
1583 fh
->overlay_settings
.x
= x
;
1584 fh
->overlay_settings
.y
= y
;
1585 fh
->overlay_settings
.width
= width
;
1586 fh
->overlay_settings
.height
= height
;
1587 fh
->overlay_settings
.clipcount
= clipcount
;
1590 * If an overlay is running, we have to switch it off
1591 * and switch it on again in order to get the new settings in effect.
1593 * We also want to avoid that the overlay mask is written
1594 * when an overlay is running.
1597 on
= zr
->v4l_overlay_active
&& !zr
->v4l_memgrab_active
&&
1598 zr
->overlay_active
!= ZORAN_FREE
&&
1599 fh
->overlay_active
!= ZORAN_FREE
;
1601 zr36057_overlay(zr
, 0);
1604 * Write the overlay mask if clips are wanted.
1605 * We prefer a bitmap.
1608 /* fake value - it just means we want clips */
1609 fh
->overlay_settings
.clipcount
= 1;
1611 if (copy_from_user(fh
->overlay_mask
, bitmap
,
1612 (width
* height
+ 7) / 8)) {
1615 } else if (clipcount
> 0) {
1616 /* write our own bitmap from the clips */
1617 vcp
= vmalloc(sizeof(struct video_clip
) * (clipcount
+ 4));
1621 "%s: setup_window() - Alloc of clip mask failed\n",
1626 (vcp
, clips
, sizeof(struct video_clip
) * clipcount
)) {
1630 write_overlay_mask(file
, vcp
, clipcount
);
1634 fh
->overlay_settings
.is_set
= 1;
1635 if (fh
->overlay_active
!= ZORAN_FREE
&&
1636 zr
->overlay_active
!= ZORAN_FREE
)
1637 zr
->overlay_settings
= fh
->overlay_settings
;
1640 zr36057_overlay(zr
, 1);
1642 /* Make sure the changes come into effect */
1643 return wait_grab_pending(zr
);
1647 setup_overlay (struct file
*file
,
1650 struct zoran_fh
*fh
= file
->private_data
;
1651 struct zoran
*zr
= fh
->zr
;
1653 /* If there is nothing to do, return immediatly */
1654 if ((on
&& fh
->overlay_active
!= ZORAN_FREE
) ||
1655 (!on
&& fh
->overlay_active
== ZORAN_FREE
))
1658 /* check whether we're touching someone else's overlay */
1659 if (on
&& zr
->overlay_active
!= ZORAN_FREE
&&
1660 fh
->overlay_active
== ZORAN_FREE
) {
1663 "%s: setup_overlay() - overlay is already active for another session\n",
1667 if (!on
&& zr
->overlay_active
!= ZORAN_FREE
&&
1668 fh
->overlay_active
== ZORAN_FREE
) {
1671 "%s: setup_overlay() - you cannot cancel someone else's session\n",
1677 zr
->overlay_active
= fh
->overlay_active
= ZORAN_FREE
;
1678 zr
->v4l_overlay_active
= 0;
1679 /* When a grab is running, the video simply
1680 * won't be switched on any more */
1681 if (!zr
->v4l_memgrab_active
)
1682 zr36057_overlay(zr
, 0);
1683 zr
->overlay_mask
= NULL
;
1685 if (!zr
->buffer
.base
|| !fh
->overlay_settings
.is_set
) {
1688 "%s: setup_overlay() - buffer or window not set\n",
1692 if (!fh
->overlay_settings
.format
) {
1695 "%s: setup_overlay() - no overlay format set\n",
1699 zr
->overlay_active
= fh
->overlay_active
= ZORAN_LOCKED
;
1700 zr
->v4l_overlay_active
= 1;
1701 zr
->overlay_mask
= fh
->overlay_mask
;
1702 zr
->overlay_settings
= fh
->overlay_settings
;
1703 if (!zr
->v4l_memgrab_active
)
1704 zr36057_overlay(zr
, 1);
1705 /* When a grab is running, the video will be
1706 * switched on when grab is finished */
1709 /* Make sure the changes come into effect */
1710 return wait_grab_pending(zr
);
1713 #ifdef CONFIG_VIDEO_V4L2
1714 /* get the status of a buffer in the clients buffer queue */
1716 zoran_v4l2_buffer_status (struct file
*file
,
1717 struct v4l2_buffer
*buf
,
1720 struct zoran_fh
*fh
= file
->private_data
;
1721 struct zoran
*zr
= fh
->zr
;
1723 buf
->flags
= V4L2_BUF_FLAG_MAPPED
;
1725 switch (fh
->map_mode
) {
1726 case ZORAN_MAP_MODE_RAW
:
1729 if (num
< 0 || num
>= fh
->v4l_buffers
.num_buffers
||
1730 !fh
->v4l_buffers
.allocated
) {
1733 "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
1738 buf
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1739 buf
->length
= fh
->v4l_buffers
.buffer_size
;
1742 buf
->bytesused
= fh
->v4l_buffers
.buffer
[num
].bs
.length
;
1743 if (fh
->v4l_buffers
.buffer
[num
].state
== BUZ_STATE_DONE
||
1744 fh
->v4l_buffers
.buffer
[num
].state
== BUZ_STATE_USER
) {
1745 buf
->sequence
= fh
->v4l_buffers
.buffer
[num
].bs
.seq
;
1746 buf
->flags
|= V4L2_BUF_FLAG_DONE
;
1748 fh
->v4l_buffers
.buffer
[num
].bs
.timestamp
;
1750 buf
->flags
|= V4L2_BUF_FLAG_QUEUED
;
1753 if (fh
->v4l_settings
.height
<= BUZ_MAX_HEIGHT
/ 2)
1754 buf
->field
= V4L2_FIELD_TOP
;
1756 buf
->field
= V4L2_FIELD_INTERLACED
;
1760 case ZORAN_MAP_MODE_JPG_REC
:
1761 case ZORAN_MAP_MODE_JPG_PLAY
:
1764 if (num
< 0 || num
>= fh
->jpg_buffers
.num_buffers
||
1765 !fh
->jpg_buffers
.allocated
) {
1768 "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
1773 buf
->type
= (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
) ?
1774 V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1775 V4L2_BUF_TYPE_VIDEO_OUTPUT
;
1776 buf
->length
= fh
->jpg_buffers
.buffer_size
;
1778 /* these variables are only written after frame has been captured */
1779 if (fh
->jpg_buffers
.buffer
[num
].state
== BUZ_STATE_DONE
||
1780 fh
->jpg_buffers
.buffer
[num
].state
== BUZ_STATE_USER
) {
1781 buf
->sequence
= fh
->jpg_buffers
.buffer
[num
].bs
.seq
;
1783 fh
->jpg_buffers
.buffer
[num
].bs
.timestamp
;
1785 fh
->jpg_buffers
.buffer
[num
].bs
.length
;
1786 buf
->flags
|= V4L2_BUF_FLAG_DONE
;
1788 buf
->flags
|= V4L2_BUF_FLAG_QUEUED
;
1791 /* which fields are these? */
1792 if (fh
->jpg_settings
.TmpDcm
!= 1)
1795 odd_even
? V4L2_FIELD_TOP
: V4L2_FIELD_BOTTOM
;
1799 odd_even
? V4L2_FIELD_SEQ_TB
:
1808 "%s: v4l2_buffer_status() - invalid buffer type|map_mode (%d|%d)\n",
1809 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
1813 buf
->memory
= V4L2_MEMORY_MMAP
;
1815 buf
->m
.offset
= buf
->length
* num
;
1822 zoran_set_norm (struct zoran
*zr
,
1823 int norm
) /* VIDEO_MODE_* */
1825 int norm_encoder
, on
;
1827 if (zr
->v4l_buffers
.active
!= ZORAN_FREE
||
1828 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
1831 "%s: set_norm() called while in playback/capture mode\n",
1836 if (lock_norm
&& norm
!= zr
->norm
) {
1837 if (lock_norm
> 1) {
1840 "%s: set_norm() - TV standard is locked, can not switch norm\n",
1846 "%s: set_norm() - TV standard is locked, norm was not changed\n",
1852 if (norm
!= VIDEO_MODE_AUTO
&&
1853 (norm
< 0 || norm
>= zr
->card
.norms
||
1854 !zr
->card
.tvn
[norm
])) {
1856 KERN_ERR
"%s: set_norm() - unsupported norm %d\n",
1857 ZR_DEVNAME(zr
), norm
);
1861 if (norm
== VIDEO_MODE_AUTO
) {
1864 /* if we have autodetect, ... */
1865 struct video_decoder_capability caps
;
1866 decoder_command(zr
, DECODER_GET_CAPABILITIES
, &caps
);
1867 if (!(caps
.flags
& VIDEO_DECODER_AUTO
)) {
1868 dprintk(1, KERN_ERR
"%s: norm=auto unsupported\n",
1873 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
1875 /* let changes come into effect */
1878 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
1879 if (!(status
& DECODER_STATUS_GOOD
)) {
1882 "%s: set_norm() - no norm detected\n",
1885 decoder_command(zr
, DECODER_SET_NORM
, &zr
->norm
);
1889 if (status
& DECODER_STATUS_NTSC
)
1890 norm
= VIDEO_MODE_NTSC
;
1891 else if (status
& DECODER_STATUS_SECAM
)
1892 norm
= VIDEO_MODE_SECAM
;
1894 norm
= VIDEO_MODE_PAL
;
1896 zr
->timing
= zr
->card
.tvn
[norm
];
1897 norm_encoder
= norm
;
1899 /* We switch overlay off and on since a change in the
1900 * norm needs different VFE settings */
1901 on
= zr
->overlay_active
&& !zr
->v4l_memgrab_active
;
1903 zr36057_overlay(zr
, 0);
1905 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
1906 encoder_command(zr
, ENCODER_SET_NORM
, &norm_encoder
);
1909 zr36057_overlay(zr
, 1);
1911 /* Make sure the changes come into effect */
1918 zoran_set_input (struct zoran
*zr
,
1923 if (input
== zr
->input
) {
1927 if (zr
->v4l_buffers
.active
!= ZORAN_FREE
||
1928 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
1931 "%s: set_input() called while in playback/capture mode\n",
1936 if (input
< 0 || input
>= zr
->card
.inputs
) {
1939 "%s: set_input() - unnsupported input %d\n",
1940 ZR_DEVNAME(zr
), input
);
1944 realinput
= zr
->card
.input
[input
].muxsel
;
1947 decoder_command(zr
, DECODER_SET_INPUT
, &realinput
);
1957 zoran_do_ioctl (struct inode
*inode
,
1962 struct zoran_fh
*fh
= file
->private_data
;
1963 struct zoran
*zr
= fh
->zr
;
1964 /* CAREFUL: used in multiple places here */
1965 struct zoran_jpg_settings settings
;
1967 /* we might have older buffers lying around... We don't want
1968 * to wait, but we do want to try cleaning them up ASAP. So
1969 * we try to obtain the lock and free them. If that fails, we
1970 * don't do anything and wait for the next turn. In the end,
1971 * zoran_close() or a new allocation will still free them...
1972 * This is just a 'the sooner the better' extra 'feature'
1974 * We don't free the buffers right on munmap() because that
1975 * causes oopses (kfree() inside munmap() oopses for no
1976 * apparent reason - it's also not reproduceable in any way,
1977 * but moving the free code outside the munmap() handler fixes
1978 * all this... If someone knows why, please explain me (Ronald)
1980 if (mutex_trylock(&zr
->resource_lock
)) {
1981 /* we obtained it! Let's try to free some things */
1982 if (fh
->jpg_buffers
.ready_to_be_freed
)
1983 jpg_fbuffer_free(file
);
1984 if (fh
->v4l_buffers
.ready_to_be_freed
)
1985 v4l_fbuffer_free(file
);
1987 mutex_unlock(&zr
->resource_lock
);
1994 struct video_capability
*vcap
= arg
;
1996 dprintk(3, KERN_DEBUG
"%s: VIDIOCGCAP\n", ZR_DEVNAME(zr
));
1998 memset(vcap
, 0, sizeof(struct video_capability
));
1999 strncpy(vcap
->name
, ZR_DEVNAME(zr
), sizeof(vcap
->name
)-1);
2000 vcap
->type
= ZORAN_VID_TYPE
;
2002 vcap
->channels
= zr
->card
.inputs
;
2004 mutex_lock(&zr
->resource_lock
);
2005 vcap
->maxwidth
= BUZ_MAX_WIDTH
;
2006 vcap
->maxheight
= BUZ_MAX_HEIGHT
;
2007 vcap
->minwidth
= BUZ_MIN_WIDTH
;
2008 vcap
->minheight
= BUZ_MIN_HEIGHT
;
2009 mutex_unlock(&zr
->resource_lock
);
2017 struct video_channel
*vchan
= arg
;
2018 int channel
= vchan
->channel
;
2020 dprintk(3, KERN_DEBUG
"%s: VIDIOCGCHAN - channel=%d\n",
2021 ZR_DEVNAME(zr
), vchan
->channel
);
2023 memset(vchan
, 0, sizeof(struct video_channel
));
2024 if (channel
> zr
->card
.inputs
|| channel
< 0) {
2027 "%s: VIDIOCGCHAN on not existing channel %d\n",
2028 ZR_DEVNAME(zr
), channel
);
2032 strcpy(vchan
->name
, zr
->card
.input
[channel
].name
);
2036 vchan
->type
= VIDEO_TYPE_CAMERA
;
2037 mutex_lock(&zr
->resource_lock
);
2038 vchan
->norm
= zr
->norm
;
2039 mutex_unlock(&zr
->resource_lock
);
2040 vchan
->channel
= channel
;
2046 /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says:
2048 * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input."
2050 * * The famos BTTV driver has it implemented with a struct video_channel argument
2051 * * and we follow it for compatibility reasons
2053 * * BTW: this is the only way the user can set the norm!
2058 struct video_channel
*vchan
= arg
;
2063 "%s: VIDIOCSCHAN - channel=%d, norm=%d\n",
2064 ZR_DEVNAME(zr
), vchan
->channel
, vchan
->norm
);
2066 mutex_lock(&zr
->resource_lock
);
2067 if ((res
= zoran_set_input(zr
, vchan
->channel
)))
2068 goto schan_unlock_and_return
;
2069 if ((res
= zoran_set_norm(zr
, vchan
->norm
)))
2070 goto schan_unlock_and_return
;
2072 /* Make sure the changes come into effect */
2073 res
= wait_grab_pending(zr
);
2074 schan_unlock_and_return
:
2075 mutex_unlock(&zr
->resource_lock
);
2082 struct video_picture
*vpict
= arg
;
2084 dprintk(3, KERN_DEBUG
"%s: VIDIOCGPICT\n", ZR_DEVNAME(zr
));
2086 memset(vpict
, 0, sizeof(struct video_picture
));
2087 mutex_lock(&zr
->resource_lock
);
2088 vpict
->hue
= zr
->hue
;
2089 vpict
->brightness
= zr
->brightness
;
2090 vpict
->contrast
= zr
->contrast
;
2091 vpict
->colour
= zr
->saturation
;
2092 if (fh
->overlay_settings
.format
) {
2093 vpict
->depth
= fh
->overlay_settings
.format
->depth
;
2094 vpict
->palette
= fh
->overlay_settings
.format
->palette
;
2098 mutex_unlock(&zr
->resource_lock
);
2106 struct video_picture
*vpict
= arg
;
2111 "%s: VIDIOCSPICT - bri=%d, hue=%d, col=%d, con=%d, dep=%d, pal=%d\n",
2112 ZR_DEVNAME(zr
), vpict
->brightness
, vpict
->hue
,
2113 vpict
->colour
, vpict
->contrast
, vpict
->depth
,
2116 for (i
= 0; i
< NUM_FORMATS
; i
++) {
2117 const struct zoran_format
*fmt
= &zoran_formats
[i
];
2119 if (fmt
->palette
!= -1 &&
2120 fmt
->flags
& ZORAN_FORMAT_OVERLAY
&&
2121 fmt
->palette
== vpict
->palette
&&
2122 fmt
->depth
== vpict
->depth
)
2125 if (i
== NUM_FORMATS
) {
2128 "%s: VIDIOCSPICT - Invalid palette %d\n",
2129 ZR_DEVNAME(zr
), vpict
->palette
);
2133 mutex_lock(&zr
->resource_lock
);
2135 decoder_command(zr
, DECODER_SET_PICTURE
, vpict
);
2137 zr
->hue
= vpict
->hue
;
2138 zr
->contrast
= vpict
->contrast
;
2139 zr
->saturation
= vpict
->colour
;
2140 zr
->brightness
= vpict
->brightness
;
2142 fh
->overlay_settings
.format
= &zoran_formats
[i
];
2144 mutex_unlock(&zr
->resource_lock
);
2154 dprintk(3, KERN_DEBUG
"%s: VIDIOCCAPTURE - on=%d\n",
2155 ZR_DEVNAME(zr
), *on
);
2157 mutex_lock(&zr
->resource_lock
);
2158 res
= setup_overlay(file
, *on
);
2159 mutex_unlock(&zr
->resource_lock
);
2167 struct video_window
*vwin
= arg
;
2169 dprintk(3, KERN_DEBUG
"%s: VIDIOCGWIN\n", ZR_DEVNAME(zr
));
2171 memset(vwin
, 0, sizeof(struct video_window
));
2172 mutex_lock(&zr
->resource_lock
);
2173 vwin
->x
= fh
->overlay_settings
.x
;
2174 vwin
->y
= fh
->overlay_settings
.y
;
2175 vwin
->width
= fh
->overlay_settings
.width
;
2176 vwin
->height
= fh
->overlay_settings
.height
;
2177 mutex_unlock(&zr
->resource_lock
);
2178 vwin
->clipcount
= 0;
2185 struct video_window
*vwin
= arg
;
2190 "%s: VIDIOCSWIN - x=%d, y=%d, w=%d, h=%d, clipcount=%d\n",
2191 ZR_DEVNAME(zr
), vwin
->x
, vwin
->y
, vwin
->width
,
2192 vwin
->height
, vwin
->clipcount
);
2194 mutex_lock(&zr
->resource_lock
);
2196 setup_window(file
, vwin
->x
, vwin
->y
, vwin
->width
,
2197 vwin
->height
, vwin
->clips
,
2198 vwin
->clipcount
, NULL
);
2199 mutex_unlock(&zr
->resource_lock
);
2207 struct video_buffer
*vbuf
= arg
;
2209 dprintk(3, KERN_DEBUG
"%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr
));
2211 mutex_lock(&zr
->resource_lock
);
2213 mutex_unlock(&zr
->resource_lock
);
2220 struct video_buffer
*vbuf
= arg
;
2225 "%s: VIDIOCSFBUF - base=%p, w=%d, h=%d, depth=%d, bpl=%d\n",
2226 ZR_DEVNAME(zr
), vbuf
->base
, vbuf
->width
,
2227 vbuf
->height
, vbuf
->depth
, vbuf
->bytesperline
);
2229 for (i
= 0; i
< NUM_FORMATS
; i
++)
2230 if (zoran_formats
[i
].depth
== vbuf
->depth
)
2232 if (i
== NUM_FORMATS
) {
2235 "%s: VIDIOCSFBUF - invalid fbuf depth %d\n",
2236 ZR_DEVNAME(zr
), vbuf
->depth
);
2240 mutex_lock(&zr
->resource_lock
);
2242 setup_fbuffer(file
, vbuf
->base
, &zoran_formats
[i
],
2243 vbuf
->width
, vbuf
->height
,
2244 vbuf
->bytesperline
);
2245 mutex_unlock(&zr
->resource_lock
);
2253 int *frame
= arg
, res
;
2255 dprintk(3, KERN_DEBUG
"%s: VIDIOCSYNC - frame=%d\n",
2256 ZR_DEVNAME(zr
), *frame
);
2258 mutex_lock(&zr
->resource_lock
);
2259 res
= v4l_sync(file
, *frame
);
2260 mutex_unlock(&zr
->resource_lock
);
2262 zr
->v4l_sync_tail
++;
2267 case VIDIOCMCAPTURE
:
2269 struct video_mmap
*vmap
= arg
;
2274 "%s: VIDIOCMCAPTURE - frame=%d, geom=%dx%d, fmt=%d\n",
2275 ZR_DEVNAME(zr
), vmap
->frame
, vmap
->width
, vmap
->height
,
2278 mutex_lock(&zr
->resource_lock
);
2279 res
= v4l_grab(file
, vmap
);
2280 mutex_unlock(&zr
->resource_lock
);
2287 struct video_mbuf
*vmbuf
= arg
;
2290 dprintk(3, KERN_DEBUG
"%s: VIDIOCGMBUF\n", ZR_DEVNAME(zr
));
2293 fh
->v4l_buffers
.num_buffers
*
2294 fh
->v4l_buffers
.buffer_size
;
2295 vmbuf
->frames
= fh
->v4l_buffers
.num_buffers
;
2296 for (i
= 0; i
< vmbuf
->frames
; i
++) {
2298 i
* fh
->v4l_buffers
.buffer_size
;
2301 mutex_lock(&zr
->resource_lock
);
2303 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
2306 "%s: VIDIOCGMBUF - buffers already allocated\n",
2309 goto v4l1reqbuf_unlock_and_return
;
2312 if (v4l_fbuffer_alloc(file
)) {
2314 goto v4l1reqbuf_unlock_and_return
;
2317 /* The next mmap will map the V4L buffers */
2318 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
2319 v4l1reqbuf_unlock_and_return
:
2320 mutex_unlock(&zr
->resource_lock
);
2328 struct video_unit
*vunit
= arg
;
2330 dprintk(3, KERN_DEBUG
"%s: VIDIOCGUNIT\n", ZR_DEVNAME(zr
));
2332 vunit
->video
= zr
->video_dev
->minor
;
2333 vunit
->vbi
= VIDEO_NO_UNIT
;
2334 vunit
->radio
= VIDEO_NO_UNIT
;
2335 vunit
->audio
= VIDEO_NO_UNIT
;
2336 vunit
->teletext
= VIDEO_NO_UNIT
;
2343 * RJ: In principal we could support subcaptures for V4L grabbing.
2344 * Not even the famous BTTV driver has them, however.
2345 * If there should be a strong demand, one could consider
2346 * to implement them.
2348 case VIDIOCGCAPTURE
:
2350 dprintk(3, KERN_ERR
"%s: VIDIOCGCAPTURE not supported\n",
2356 case VIDIOCSCAPTURE
:
2358 dprintk(3, KERN_ERR
"%s: VIDIOCSCAPTURE not supported\n",
2364 case BUZIOC_G_PARAMS
:
2366 struct zoran_params
*bparams
= arg
;
2368 dprintk(3, KERN_DEBUG
"%s: BUZIOC_G_PARAMS\n", ZR_DEVNAME(zr
));
2370 memset(bparams
, 0, sizeof(struct zoran_params
));
2371 bparams
->major_version
= MAJOR_VERSION
;
2372 bparams
->minor_version
= MINOR_VERSION
;
2374 mutex_lock(&zr
->resource_lock
);
2376 bparams
->norm
= zr
->norm
;
2377 bparams
->input
= zr
->input
;
2379 bparams
->decimation
= fh
->jpg_settings
.decimation
;
2380 bparams
->HorDcm
= fh
->jpg_settings
.HorDcm
;
2381 bparams
->VerDcm
= fh
->jpg_settings
.VerDcm
;
2382 bparams
->TmpDcm
= fh
->jpg_settings
.TmpDcm
;
2383 bparams
->field_per_buff
= fh
->jpg_settings
.field_per_buff
;
2384 bparams
->img_x
= fh
->jpg_settings
.img_x
;
2385 bparams
->img_y
= fh
->jpg_settings
.img_y
;
2386 bparams
->img_width
= fh
->jpg_settings
.img_width
;
2387 bparams
->img_height
= fh
->jpg_settings
.img_height
;
2388 bparams
->odd_even
= fh
->jpg_settings
.odd_even
;
2390 bparams
->quality
= fh
->jpg_settings
.jpg_comp
.quality
;
2391 bparams
->APPn
= fh
->jpg_settings
.jpg_comp
.APPn
;
2392 bparams
->APP_len
= fh
->jpg_settings
.jpg_comp
.APP_len
;
2393 memcpy(bparams
->APP_data
,
2394 fh
->jpg_settings
.jpg_comp
.APP_data
,
2395 sizeof(bparams
->APP_data
));
2396 bparams
->COM_len
= zr
->jpg_settings
.jpg_comp
.COM_len
;
2397 memcpy(bparams
->COM_data
,
2398 fh
->jpg_settings
.jpg_comp
.COM_data
,
2399 sizeof(bparams
->COM_data
));
2400 bparams
->jpeg_markers
=
2401 fh
->jpg_settings
.jpg_comp
.jpeg_markers
;
2403 mutex_unlock(&zr
->resource_lock
);
2405 bparams
->VFIFO_FB
= 0;
2411 case BUZIOC_S_PARAMS
:
2413 struct zoran_params
*bparams
= arg
;
2416 dprintk(3, KERN_DEBUG
"%s: BUZIOC_S_PARAMS\n", ZR_DEVNAME(zr
));
2418 settings
.decimation
= bparams
->decimation
;
2419 settings
.HorDcm
= bparams
->HorDcm
;
2420 settings
.VerDcm
= bparams
->VerDcm
;
2421 settings
.TmpDcm
= bparams
->TmpDcm
;
2422 settings
.field_per_buff
= bparams
->field_per_buff
;
2423 settings
.img_x
= bparams
->img_x
;
2424 settings
.img_y
= bparams
->img_y
;
2425 settings
.img_width
= bparams
->img_width
;
2426 settings
.img_height
= bparams
->img_height
;
2427 settings
.odd_even
= bparams
->odd_even
;
2429 settings
.jpg_comp
.quality
= bparams
->quality
;
2430 settings
.jpg_comp
.APPn
= bparams
->APPn
;
2431 settings
.jpg_comp
.APP_len
= bparams
->APP_len
;
2432 memcpy(settings
.jpg_comp
.APP_data
, bparams
->APP_data
,
2433 sizeof(bparams
->APP_data
));
2434 settings
.jpg_comp
.COM_len
= bparams
->COM_len
;
2435 memcpy(settings
.jpg_comp
.COM_data
, bparams
->COM_data
,
2436 sizeof(bparams
->COM_data
));
2437 settings
.jpg_comp
.jpeg_markers
= bparams
->jpeg_markers
;
2439 mutex_lock(&zr
->resource_lock
);
2441 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2444 "%s: BUZIOC_S_PARAMS called, but Buz in capture/playback mode\n",
2447 goto sparams_unlock_and_return
;
2450 /* Check the params first before overwriting our
2452 if (zoran_check_jpg_settings(zr
, &settings
)) {
2454 goto sparams_unlock_and_return
;
2457 fh
->jpg_settings
= settings
;
2458 sparams_unlock_and_return
:
2459 mutex_unlock(&zr
->resource_lock
);
2465 case BUZIOC_REQBUFS
:
2467 struct zoran_requestbuffers
*breq
= arg
;
2472 "%s: BUZIOC_REQBUFS - count=%lu, size=%lu\n",
2473 ZR_DEVNAME(zr
), breq
->count
, breq
->size
);
2475 /* Enforce reasonable lower and upper limits */
2476 if (breq
->count
< 4)
2477 breq
->count
= 4; /* Could be choosen smaller */
2478 if (breq
->count
> jpg_nbufs
)
2479 breq
->count
= jpg_nbufs
;
2480 breq
->size
= PAGE_ALIGN(breq
->size
);
2481 if (breq
->size
< 8192)
2482 breq
->size
= 8192; /* Arbitrary */
2483 /* breq->size is limited by 1 page for the stat_com
2484 * tables to a Maximum of 2 MB */
2485 if (breq
->size
> jpg_bufsize
)
2486 breq
->size
= jpg_bufsize
;
2487 if (fh
->jpg_buffers
.need_contiguous
&&
2488 breq
->size
> MAX_KMALLOC_MEM
)
2489 breq
->size
= MAX_KMALLOC_MEM
;
2491 mutex_lock(&zr
->resource_lock
);
2493 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
2496 "%s: BUZIOC_REQBUFS - buffers allready allocated\n",
2499 goto jpgreqbuf_unlock_and_return
;
2502 fh
->jpg_buffers
.num_buffers
= breq
->count
;
2503 fh
->jpg_buffers
.buffer_size
= breq
->size
;
2505 if (jpg_fbuffer_alloc(file
)) {
2507 goto jpgreqbuf_unlock_and_return
;
2510 /* The next mmap will map the MJPEG buffers - could
2511 * also be *_PLAY, but it doesn't matter here */
2512 fh
->map_mode
= ZORAN_MAP_MODE_JPG_REC
;
2513 jpgreqbuf_unlock_and_return
:
2514 mutex_unlock(&zr
->resource_lock
);
2520 case BUZIOC_QBUF_CAPT
:
2522 int *frame
= arg
, res
;
2524 dprintk(3, KERN_DEBUG
"%s: BUZIOC_QBUF_CAPT - frame=%d\n",
2525 ZR_DEVNAME(zr
), *frame
);
2527 mutex_lock(&zr
->resource_lock
);
2528 res
= jpg_qbuf(file
, *frame
, BUZ_MODE_MOTION_COMPRESS
);
2529 mutex_unlock(&zr
->resource_lock
);
2535 case BUZIOC_QBUF_PLAY
:
2537 int *frame
= arg
, res
;
2539 dprintk(3, KERN_DEBUG
"%s: BUZIOC_QBUF_PLAY - frame=%d\n",
2540 ZR_DEVNAME(zr
), *frame
);
2542 mutex_lock(&zr
->resource_lock
);
2543 res
= jpg_qbuf(file
, *frame
, BUZ_MODE_MOTION_DECOMPRESS
);
2544 mutex_unlock(&zr
->resource_lock
);
2552 struct zoran_sync
*bsync
= arg
;
2555 dprintk(3, KERN_DEBUG
"%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr
));
2557 mutex_lock(&zr
->resource_lock
);
2558 res
= jpg_sync(file
, bsync
);
2559 mutex_unlock(&zr
->resource_lock
);
2565 case BUZIOC_G_STATUS
:
2567 struct zoran_status
*bstat
= arg
;
2568 int norm
, input
, status
, res
= 0;
2570 dprintk(3, KERN_DEBUG
"%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr
));
2572 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2575 "%s: BUZIOC_G_STATUS called but Buz in capture/playback mode\n",
2580 input
= zr
->card
.input
[bstat
->input
].muxsel
;
2581 norm
= VIDEO_MODE_AUTO
;
2583 mutex_lock(&zr
->resource_lock
);
2585 if (zr
->codec_mode
!= BUZ_MODE_IDLE
) {
2588 "%s: BUZIOC_G_STATUS called, but Buz in capture/playback mode\n",
2591 goto gstat_unlock_and_return
;
2594 decoder_command(zr
, DECODER_SET_INPUT
, &input
);
2595 decoder_command(zr
, DECODER_SET_NORM
, &norm
);
2597 /* sleep 1 second */
2600 /* Get status of video decoder */
2601 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
2603 /* restore previous input and norm */
2604 input
= zr
->card
.input
[zr
->input
].muxsel
;
2605 decoder_command(zr
, DECODER_SET_INPUT
, &input
);
2606 decoder_command(zr
, DECODER_SET_NORM
, &zr
->norm
);
2607 gstat_unlock_and_return
:
2608 mutex_unlock(&zr
->resource_lock
);
2612 (status
& DECODER_STATUS_GOOD
) ? 1 : 0;
2613 if (status
& DECODER_STATUS_NTSC
)
2614 bstat
->norm
= VIDEO_MODE_NTSC
;
2615 else if (status
& DECODER_STATUS_SECAM
)
2616 bstat
->norm
= VIDEO_MODE_SECAM
;
2618 bstat
->norm
= VIDEO_MODE_PAL
;
2621 (status
& DECODER_STATUS_COLOR
) ? 1 : 0;
2628 #ifdef CONFIG_VIDEO_V4L2
2630 /* The new video4linux2 capture interface - much nicer than video4linux1, since
2631 * it allows for integrating the JPEG capturing calls inside standard v4l2
2634 case VIDIOC_QUERYCAP
:
2636 struct v4l2_capability
*cap
= arg
;
2638 dprintk(3, KERN_DEBUG
"%s: VIDIOC_QUERYCAP\n", ZR_DEVNAME(zr
));
2640 memset(cap
, 0, sizeof(*cap
));
2641 strncpy(cap
->card
, ZR_DEVNAME(zr
), sizeof(cap
->card
)-1);
2642 strncpy(cap
->driver
, "zoran", sizeof(cap
->driver
)-1);
2643 snprintf(cap
->bus_info
, sizeof(cap
->bus_info
), "PCI:%s",
2644 pci_name(zr
->pci_dev
));
2646 KERNEL_VERSION(MAJOR_VERSION
, MINOR_VERSION
,
2648 cap
->capabilities
= ZORAN_V4L2_VID_FLAGS
;
2654 case VIDIOC_ENUM_FMT
:
2656 struct v4l2_fmtdesc
*fmt
= arg
;
2657 int index
= fmt
->index
, num
= -1, i
, flag
= 0, type
=
2660 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUM_FMT - index=%d\n",
2661 ZR_DEVNAME(zr
), fmt
->index
);
2663 switch (fmt
->type
) {
2664 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2665 flag
= ZORAN_FORMAT_CAPTURE
;
2667 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2668 flag
= ZORAN_FORMAT_PLAYBACK
;
2670 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2671 flag
= ZORAN_FORMAT_OVERLAY
;
2676 "%s: VIDIOC_ENUM_FMT - unknown type %d\n",
2677 ZR_DEVNAME(zr
), fmt
->type
);
2681 for (i
= 0; i
< NUM_FORMATS
; i
++) {
2682 if (zoran_formats
[i
].flags
& flag
)
2684 if (num
== fmt
->index
)
2687 if (fmt
->index
< 0 /* late, but not too late */ ||
2691 memset(fmt
, 0, sizeof(*fmt
));
2694 strncpy(fmt
->description
, zoran_formats
[i
].name
, sizeof(fmt
->description
)-1);
2695 fmt
->pixelformat
= zoran_formats
[i
].fourcc
;
2696 if (zoran_formats
[i
].flags
& ZORAN_FORMAT_COMPRESSED
)
2697 fmt
->flags
|= V4L2_FMT_FLAG_COMPRESSED
;
2705 struct v4l2_format
*fmt
= arg
;
2706 int type
= fmt
->type
;
2708 dprintk(5, KERN_DEBUG
"%s: VIDIOC_G_FMT\n", ZR_DEVNAME(zr
));
2710 memset(fmt
, 0, sizeof(*fmt
));
2713 switch (fmt
->type
) {
2714 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2716 mutex_lock(&zr
->resource_lock
);
2718 fmt
->fmt
.win
.w
.left
= fh
->overlay_settings
.x
;
2719 fmt
->fmt
.win
.w
.top
= fh
->overlay_settings
.y
;
2720 fmt
->fmt
.win
.w
.width
= fh
->overlay_settings
.width
;
2721 fmt
->fmt
.win
.w
.height
=
2722 fh
->overlay_settings
.height
;
2723 if (fh
->overlay_settings
.width
* 2 >
2725 fmt
->fmt
.win
.field
= V4L2_FIELD_INTERLACED
;
2727 fmt
->fmt
.win
.field
= V4L2_FIELD_TOP
;
2729 mutex_unlock(&zr
->resource_lock
);
2733 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2734 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2736 mutex_lock(&zr
->resource_lock
);
2738 if (fmt
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
2739 fh
->map_mode
== ZORAN_MAP_MODE_RAW
) {
2741 fmt
->fmt
.pix
.width
=
2742 fh
->v4l_settings
.width
;
2743 fmt
->fmt
.pix
.height
=
2744 fh
->v4l_settings
.height
;
2745 fmt
->fmt
.pix
.sizeimage
=
2746 fh
->v4l_settings
.bytesperline
*
2747 fh
->v4l_settings
.height
;
2748 fmt
->fmt
.pix
.pixelformat
=
2749 fh
->v4l_settings
.format
->fourcc
;
2750 fmt
->fmt
.pix
.colorspace
=
2751 fh
->v4l_settings
.format
->colorspace
;
2752 fmt
->fmt
.pix
.bytesperline
= 0;
2753 if (BUZ_MAX_HEIGHT
<
2754 (fh
->v4l_settings
.height
* 2))
2755 fmt
->fmt
.pix
.field
=
2756 V4L2_FIELD_INTERLACED
;
2758 fmt
->fmt
.pix
.field
=
2763 fmt
->fmt
.pix
.width
=
2764 fh
->jpg_settings
.img_width
/
2765 fh
->jpg_settings
.HorDcm
;
2766 fmt
->fmt
.pix
.height
=
2767 fh
->jpg_settings
.img_height
/
2768 (fh
->jpg_settings
.VerDcm
*
2769 fh
->jpg_settings
.TmpDcm
);
2770 fmt
->fmt
.pix
.sizeimage
=
2771 zoran_v4l2_calc_bufsize(&fh
->
2773 fmt
->fmt
.pix
.pixelformat
=
2775 if (fh
->jpg_settings
.TmpDcm
== 1)
2776 fmt
->fmt
.pix
.field
=
2778 odd_even
? V4L2_FIELD_SEQ_BT
:
2781 fmt
->fmt
.pix
.field
=
2783 odd_even
? V4L2_FIELD_TOP
:
2786 fmt
->fmt
.pix
.bytesperline
= 0;
2787 fmt
->fmt
.pix
.colorspace
=
2788 V4L2_COLORSPACE_SMPTE170M
;
2791 mutex_unlock(&zr
->resource_lock
);
2798 "%s: VIDIOC_G_FMT - unsupported type %d\n",
2799 ZR_DEVNAME(zr
), fmt
->type
);
2808 struct v4l2_format
*fmt
= arg
;
2812 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_FMT - type=%d, ",
2813 ZR_DEVNAME(zr
), fmt
->type
);
2815 switch (fmt
->type
) {
2816 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
2818 dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n",
2819 fmt
->fmt
.win
.w
.left
, fmt
->fmt
.win
.w
.top
,
2820 fmt
->fmt
.win
.w
.width
,
2821 fmt
->fmt
.win
.w
.height
,
2822 fmt
->fmt
.win
.clipcount
,
2823 fmt
->fmt
.win
.bitmap
);
2824 mutex_lock(&zr
->resource_lock
);
2826 setup_window(file
, fmt
->fmt
.win
.w
.left
,
2828 fmt
->fmt
.win
.w
.width
,
2829 fmt
->fmt
.win
.w
.height
,
2830 (struct video_clip __user
*)
2832 fmt
->fmt
.win
.clipcount
,
2833 fmt
->fmt
.win
.bitmap
);
2834 mutex_unlock(&zr
->resource_lock
);
2838 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
2839 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
2842 __cpu_to_le32(fmt
->fmt
.pix
.pixelformat
);
2843 dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n",
2844 fmt
->fmt
.pix
.width
, fmt
->fmt
.pix
.height
,
2845 fmt
->fmt
.pix
.pixelformat
,
2846 (char *) &printformat
);
2848 if (fmt
->fmt
.pix
.bytesperline
> 0) {
2850 KERN_ERR
"%s: bpl not supported\n",
2855 /* we can be requested to do JPEG/raw playback/capture */
2857 (fmt
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
||
2858 (fmt
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
2859 fmt
->fmt
.pix
.pixelformat
==
2860 V4L2_PIX_FMT_MJPEG
))) {
2863 "%s: VIDIOC_S_FMT - unknown type %d/0x%x(%4.4s) combination\n",
2864 ZR_DEVNAME(zr
), fmt
->type
,
2865 fmt
->fmt
.pix
.pixelformat
,
2866 (char *) &printformat
);
2870 if (fmt
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_MJPEG
) {
2871 mutex_lock(&zr
->resource_lock
);
2873 settings
= fh
->jpg_settings
;
2875 if (fh
->v4l_buffers
.allocated
||
2876 fh
->jpg_buffers
.allocated
) {
2879 "%s: VIDIOC_S_FMT - cannot change capture mode\n",
2882 goto sfmtjpg_unlock_and_return
;
2885 /* we actually need to set 'real' parameters now */
2886 if ((fmt
->fmt
.pix
.height
* 2) >
2888 settings
.TmpDcm
= 1;
2890 settings
.TmpDcm
= 2;
2891 settings
.decimation
= 0;
2892 if (fmt
->fmt
.pix
.height
<=
2893 fh
->jpg_settings
.img_height
/ 2)
2894 settings
.VerDcm
= 2;
2896 settings
.VerDcm
= 1;
2897 if (fmt
->fmt
.pix
.width
<=
2898 fh
->jpg_settings
.img_width
/ 4)
2899 settings
.HorDcm
= 4;
2900 else if (fmt
->fmt
.pix
.width
<=
2901 fh
->jpg_settings
.img_width
/ 2)
2902 settings
.HorDcm
= 2;
2904 settings
.HorDcm
= 1;
2905 if (settings
.TmpDcm
== 1)
2906 settings
.field_per_buff
= 2;
2908 settings
.field_per_buff
= 1;
2912 zoran_check_jpg_settings(zr
,
2914 goto sfmtjpg_unlock_and_return
;
2916 /* it's ok, so set them */
2917 fh
->jpg_settings
= settings
;
2919 /* tell the user what we actually did */
2920 fmt
->fmt
.pix
.width
=
2921 settings
.img_width
/ settings
.HorDcm
;
2922 fmt
->fmt
.pix
.height
=
2923 settings
.img_height
* 2 /
2924 (settings
.TmpDcm
* settings
.VerDcm
);
2925 if (settings
.TmpDcm
== 1)
2926 fmt
->fmt
.pix
.field
=
2928 odd_even
? V4L2_FIELD_SEQ_TB
:
2931 fmt
->fmt
.pix
.field
=
2933 odd_even
? V4L2_FIELD_TOP
:
2935 fh
->jpg_buffers
.buffer_size
=
2936 zoran_v4l2_calc_bufsize(&fh
->
2938 fmt
->fmt
.pix
.sizeimage
=
2939 fh
->jpg_buffers
.buffer_size
;
2941 /* we hereby abuse this variable to show that
2942 * we're gonna do mjpeg capture */
2945 V4L2_BUF_TYPE_VIDEO_CAPTURE
) ?
2946 ZORAN_MAP_MODE_JPG_REC
:
2947 ZORAN_MAP_MODE_JPG_PLAY
;
2948 sfmtjpg_unlock_and_return
:
2949 mutex_unlock(&zr
->resource_lock
);
2951 for (i
= 0; i
< NUM_FORMATS
; i
++)
2952 if (fmt
->fmt
.pix
.pixelformat
==
2953 zoran_formats
[i
].fourcc
)
2955 if (i
== NUM_FORMATS
) {
2958 "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x (%4.4s)\n",
2960 fmt
->fmt
.pix
.pixelformat
,
2961 (char *) &printformat
);
2964 mutex_lock(&zr
->resource_lock
);
2965 if (fh
->jpg_buffers
.allocated
||
2966 (fh
->v4l_buffers
.allocated
&&
2967 fh
->v4l_buffers
.active
!=
2971 "%s: VIDIOC_S_FMT - cannot change capture mode\n",
2974 goto sfmtv4l_unlock_and_return
;
2976 if (fmt
->fmt
.pix
.height
> BUZ_MAX_HEIGHT
)
2977 fmt
->fmt
.pix
.height
=
2979 if (fmt
->fmt
.pix
.width
> BUZ_MAX_WIDTH
)
2980 fmt
->fmt
.pix
.width
= BUZ_MAX_WIDTH
;
2983 zoran_v4l_set_format(file
,
2990 goto sfmtv4l_unlock_and_return
;
2992 /* tell the user the
2993 * results/missing stuff */
2994 fmt
->fmt
.pix
.sizeimage
=
2995 fh
->v4l_settings
.height
*
2996 fh
->v4l_settings
.bytesperline
;
2997 if (BUZ_MAX_HEIGHT
<
2998 (fh
->v4l_settings
.height
* 2))
2999 fmt
->fmt
.pix
.field
=
3000 V4L2_FIELD_INTERLACED
;
3002 fmt
->fmt
.pix
.field
=
3005 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
3006 sfmtv4l_unlock_and_return
:
3007 mutex_unlock(&zr
->resource_lock
);
3013 dprintk(3, "unsupported\n");
3016 "%s: VIDIOC_S_FMT - unsupported type %d\n",
3017 ZR_DEVNAME(zr
), fmt
->type
);
3027 struct v4l2_framebuffer
*fb
= arg
;
3029 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr
));
3031 memset(fb
, 0, sizeof(*fb
));
3032 mutex_lock(&zr
->resource_lock
);
3033 fb
->base
= zr
->buffer
.base
;
3034 fb
->fmt
.width
= zr
->buffer
.width
;
3035 fb
->fmt
.height
= zr
->buffer
.height
;
3036 if (zr
->overlay_settings
.format
) {
3037 fb
->fmt
.pixelformat
=
3038 fh
->overlay_settings
.format
->fourcc
;
3040 fb
->fmt
.bytesperline
= zr
->buffer
.bytesperline
;
3041 mutex_unlock(&zr
->resource_lock
);
3042 fb
->fmt
.colorspace
= V4L2_COLORSPACE_SRGB
;
3043 fb
->fmt
.field
= V4L2_FIELD_INTERLACED
;
3044 fb
->flags
= V4L2_FBUF_FLAG_OVERLAY
;
3045 fb
->capability
= V4L2_FBUF_CAP_LIST_CLIPPING
;
3054 struct v4l2_framebuffer
*fb
= arg
;
3055 __u32 printformat
= __cpu_to_le32(fb
->fmt
.pixelformat
);
3059 "%s: VIDIOC_S_FBUF - base=0x%p, size=%dx%d, bpl=%d, fmt=0x%x (%4.4s)\n",
3060 ZR_DEVNAME(zr
), fb
->base
, fb
->fmt
.width
, fb
->fmt
.height
,
3061 fb
->fmt
.bytesperline
, fb
->fmt
.pixelformat
,
3062 (char *) &printformat
);
3064 for (i
= 0; i
< NUM_FORMATS
; i
++)
3065 if (zoran_formats
[i
].fourcc
== fb
->fmt
.pixelformat
)
3067 if (i
== NUM_FORMATS
) {
3070 "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n",
3071 ZR_DEVNAME(zr
), fb
->fmt
.pixelformat
,
3072 (char *) &printformat
);
3076 mutex_lock(&zr
->resource_lock
);
3078 setup_fbuffer(file
, fb
->base
, &zoran_formats
[i
],
3079 fb
->fmt
.width
, fb
->fmt
.height
,
3080 fb
->fmt
.bytesperline
);
3081 mutex_unlock(&zr
->resource_lock
);
3087 case VIDIOC_OVERLAY
:
3091 dprintk(3, KERN_DEBUG
"%s: VIDIOC_PREVIEW - on=%d\n",
3092 ZR_DEVNAME(zr
), *on
);
3094 mutex_lock(&zr
->resource_lock
);
3095 res
= setup_overlay(file
, *on
);
3096 mutex_unlock(&zr
->resource_lock
);
3102 case VIDIOC_REQBUFS
:
3104 struct v4l2_requestbuffers
*req
= arg
;
3107 dprintk(3, KERN_DEBUG
"%s: VIDIOC_REQBUFS - type=%d\n",
3108 ZR_DEVNAME(zr
), req
->type
);
3110 if (req
->memory
!= V4L2_MEMORY_MMAP
) {
3113 "%s: only MEMORY_MMAP capture is supported, not %d\n",
3114 ZR_DEVNAME(zr
), req
->memory
);
3118 mutex_lock(&zr
->resource_lock
);
3120 if (fh
->v4l_buffers
.allocated
|| fh
->jpg_buffers
.allocated
) {
3123 "%s: VIDIOC_REQBUFS - buffers allready allocated\n",
3126 goto v4l2reqbuf_unlock_and_return
;
3129 if (fh
->map_mode
== ZORAN_MAP_MODE_RAW
&&
3130 req
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3132 /* control user input */
3135 if (req
->count
> v4l_nbufs
)
3136 req
->count
= v4l_nbufs
;
3137 fh
->v4l_buffers
.num_buffers
= req
->count
;
3139 if (v4l_fbuffer_alloc(file
)) {
3141 goto v4l2reqbuf_unlock_and_return
;
3144 /* The next mmap will map the V4L buffers */
3145 fh
->map_mode
= ZORAN_MAP_MODE_RAW
;
3147 } else if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
||
3148 fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
) {
3150 /* we need to calculate size ourselves now */
3153 if (req
->count
> jpg_nbufs
)
3154 req
->count
= jpg_nbufs
;
3155 fh
->jpg_buffers
.num_buffers
= req
->count
;
3156 fh
->jpg_buffers
.buffer_size
=
3157 zoran_v4l2_calc_bufsize(&fh
->jpg_settings
);
3159 if (jpg_fbuffer_alloc(file
)) {
3161 goto v4l2reqbuf_unlock_and_return
;
3164 /* The next mmap will map the MJPEG buffers */
3165 if (req
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
)
3166 fh
->map_mode
= ZORAN_MAP_MODE_JPG_REC
;
3168 fh
->map_mode
= ZORAN_MAP_MODE_JPG_PLAY
;
3173 "%s: VIDIOC_REQBUFS - unknown type %d\n",
3174 ZR_DEVNAME(zr
), req
->type
);
3176 goto v4l2reqbuf_unlock_and_return
;
3178 v4l2reqbuf_unlock_and_return
:
3179 mutex_unlock(&zr
->resource_lock
);
3185 case VIDIOC_QUERYBUF
:
3187 struct v4l2_buffer
*buf
= arg
;
3188 __u32 type
= buf
->type
;
3189 int index
= buf
->index
, res
;
3193 "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n",
3194 ZR_DEVNAME(zr
), buf
->index
, buf
->type
);
3196 memset(buf
, 0, sizeof(*buf
));
3200 mutex_lock(&zr
->resource_lock
);
3201 res
= zoran_v4l2_buffer_status(file
, buf
, buf
->index
);
3202 mutex_unlock(&zr
->resource_lock
);
3210 struct v4l2_buffer
*buf
= arg
;
3211 int res
= 0, codec_mode
, buf_type
;
3214 KERN_DEBUG
"%s: VIDIOC_QBUF - type=%d, index=%d\n",
3215 ZR_DEVNAME(zr
), buf
->type
, buf
->index
);
3217 mutex_lock(&zr
->resource_lock
);
3219 switch (fh
->map_mode
) {
3220 case ZORAN_MAP_MODE_RAW
:
3221 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3224 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3225 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3227 goto qbuf_unlock_and_return
;
3230 res
= zoran_v4l_queue_frame(file
, buf
->index
);
3232 goto qbuf_unlock_and_return
;
3233 if (!zr
->v4l_memgrab_active
&&
3234 fh
->v4l_buffers
.active
== ZORAN_LOCKED
)
3235 zr36057_set_memgrab(zr
, 1);
3238 case ZORAN_MAP_MODE_JPG_REC
:
3239 case ZORAN_MAP_MODE_JPG_PLAY
:
3240 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
) {
3241 buf_type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
3242 codec_mode
= BUZ_MODE_MOTION_DECOMPRESS
;
3244 buf_type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
3245 codec_mode
= BUZ_MODE_MOTION_COMPRESS
;
3248 if (buf
->type
!= buf_type
) {
3251 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3252 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3254 goto qbuf_unlock_and_return
;
3258 zoran_jpg_queue_frame(file
, buf
->index
,
3261 goto qbuf_unlock_and_return
;
3262 if (zr
->codec_mode
== BUZ_MODE_IDLE
&&
3263 fh
->jpg_buffers
.active
== ZORAN_LOCKED
) {
3264 zr36057_enable_jpg(zr
, codec_mode
);
3271 "%s: VIDIOC_QBUF - unsupported type %d\n",
3272 ZR_DEVNAME(zr
), buf
->type
);
3274 goto qbuf_unlock_and_return
;
3276 qbuf_unlock_and_return
:
3277 mutex_unlock(&zr
->resource_lock
);
3285 struct v4l2_buffer
*buf
= arg
;
3286 int res
= 0, buf_type
, num
= -1; /* compiler borks here (?) */
3288 dprintk(3, KERN_DEBUG
"%s: VIDIOC_DQBUF - type=%d\n",
3289 ZR_DEVNAME(zr
), buf
->type
);
3291 mutex_lock(&zr
->resource_lock
);
3293 switch (fh
->map_mode
) {
3294 case ZORAN_MAP_MODE_RAW
:
3295 if (buf
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
3298 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3299 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3301 goto dqbuf_unlock_and_return
;
3304 num
= zr
->v4l_pend
[zr
->v4l_sync_tail
& V4L_MASK_FRAME
];
3305 if (file
->f_flags
& O_NONBLOCK
&&
3306 zr
->v4l_buffers
.buffer
[num
].state
!=
3309 goto dqbuf_unlock_and_return
;
3311 res
= v4l_sync(file
, num
);
3313 goto dqbuf_unlock_and_return
;
3315 zr
->v4l_sync_tail
++;
3316 res
= zoran_v4l2_buffer_status(file
, buf
, num
);
3319 case ZORAN_MAP_MODE_JPG_REC
:
3320 case ZORAN_MAP_MODE_JPG_PLAY
:
3322 struct zoran_sync bs
;
3324 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_PLAY
)
3325 buf_type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
3327 buf_type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
3329 if (buf
->type
!= buf_type
) {
3332 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3333 ZR_DEVNAME(zr
), buf
->type
, fh
->map_mode
);
3335 goto dqbuf_unlock_and_return
;
3340 jpg_que_tail
& BUZ_MASK_FRAME
];
3342 if (file
->f_flags
& O_NONBLOCK
&&
3343 zr
->jpg_buffers
.buffer
[num
].state
!=
3346 goto dqbuf_unlock_and_return
;
3348 res
= jpg_sync(file
, &bs
);
3350 goto dqbuf_unlock_and_return
;
3352 zoran_v4l2_buffer_status(file
, buf
, bs
.frame
);
3359 "%s: VIDIOC_DQBUF - unsupported type %d\n",
3360 ZR_DEVNAME(zr
), buf
->type
);
3362 goto dqbuf_unlock_and_return
;
3364 dqbuf_unlock_and_return
:
3365 mutex_unlock(&zr
->resource_lock
);
3371 case VIDIOC_STREAMON
:
3375 dprintk(3, KERN_DEBUG
"%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr
));
3377 mutex_lock(&zr
->resource_lock
);
3379 switch (fh
->map_mode
) {
3380 case ZORAN_MAP_MODE_RAW
: /* raw capture */
3381 if (zr
->v4l_buffers
.active
!= ZORAN_ACTIVE
||
3382 fh
->v4l_buffers
.active
!= ZORAN_ACTIVE
) {
3384 goto strmon_unlock_and_return
;
3387 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
3389 zr
->v4l_settings
= fh
->v4l_settings
;
3391 zr
->v4l_sync_tail
= zr
->v4l_pend_tail
;
3392 if (!zr
->v4l_memgrab_active
&&
3393 zr
->v4l_pend_head
!= zr
->v4l_pend_tail
) {
3394 zr36057_set_memgrab(zr
, 1);
3398 case ZORAN_MAP_MODE_JPG_REC
:
3399 case ZORAN_MAP_MODE_JPG_PLAY
:
3400 /* what is the codec mode right now? */
3401 if (zr
->jpg_buffers
.active
!= ZORAN_ACTIVE
||
3402 fh
->jpg_buffers
.active
!= ZORAN_ACTIVE
) {
3404 goto strmon_unlock_and_return
;
3407 zr
->jpg_buffers
.active
= fh
->jpg_buffers
.active
=
3410 if (zr
->jpg_que_head
!= zr
->jpg_que_tail
) {
3411 /* Start the jpeg codec when the first frame is queued */
3419 "%s: VIDIOC_STREAMON - invalid map mode %d\n",
3420 ZR_DEVNAME(zr
), fh
->map_mode
);
3422 goto strmon_unlock_and_return
;
3424 strmon_unlock_and_return
:
3425 mutex_unlock(&zr
->resource_lock
);
3431 case VIDIOC_STREAMOFF
:
3435 dprintk(3, KERN_DEBUG
"%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr
));
3437 mutex_lock(&zr
->resource_lock
);
3439 switch (fh
->map_mode
) {
3440 case ZORAN_MAP_MODE_RAW
: /* raw capture */
3441 if (fh
->v4l_buffers
.active
== ZORAN_FREE
&&
3442 zr
->v4l_buffers
.active
!= ZORAN_FREE
) {
3443 res
= -EPERM
; /* stay off other's settings! */
3444 goto strmoff_unlock_and_return
;
3446 if (zr
->v4l_buffers
.active
== ZORAN_FREE
)
3447 goto strmoff_unlock_and_return
;
3449 /* unload capture */
3450 if (zr
->v4l_memgrab_active
) {
3453 spin_lock_irqsave(&zr
->spinlock
, flags
);
3454 zr36057_set_memgrab(zr
, 0);
3455 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
3458 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++)
3459 zr
->v4l_buffers
.buffer
[i
].state
=
3461 fh
->v4l_buffers
= zr
->v4l_buffers
;
3463 zr
->v4l_buffers
.active
= fh
->v4l_buffers
.active
=
3466 zr
->v4l_grab_seq
= 0;
3467 zr
->v4l_pend_head
= zr
->v4l_pend_tail
= 0;
3468 zr
->v4l_sync_tail
= 0;
3472 case ZORAN_MAP_MODE_JPG_REC
:
3473 case ZORAN_MAP_MODE_JPG_PLAY
:
3474 if (fh
->jpg_buffers
.active
== ZORAN_FREE
&&
3475 zr
->jpg_buffers
.active
!= ZORAN_FREE
) {
3476 res
= -EPERM
; /* stay off other's settings! */
3477 goto strmoff_unlock_and_return
;
3479 if (zr
->jpg_buffers
.active
== ZORAN_FREE
)
3480 goto strmoff_unlock_and_return
;
3485 ZORAN_MAP_MODE_JPG_REC
) ?
3486 BUZ_MODE_MOTION_COMPRESS
:
3487 BUZ_MODE_MOTION_DECOMPRESS
);
3489 goto strmoff_unlock_and_return
;
3494 "%s: VIDIOC_STREAMOFF - invalid map mode %d\n",
3495 ZR_DEVNAME(zr
), fh
->map_mode
);
3497 goto strmoff_unlock_and_return
;
3499 strmoff_unlock_and_return
:
3500 mutex_unlock(&zr
->resource_lock
);
3506 case VIDIOC_QUERYCTRL
:
3508 struct v4l2_queryctrl
*ctrl
= arg
;
3510 dprintk(3, KERN_DEBUG
"%s: VIDIOC_QUERYCTRL - id=%d\n",
3511 ZR_DEVNAME(zr
), ctrl
->id
);
3513 /* we only support hue/saturation/contrast/brightness */
3514 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3515 ctrl
->id
> V4L2_CID_HUE
)
3519 memset(ctrl
, 0, sizeof(*ctrl
));
3524 case V4L2_CID_BRIGHTNESS
:
3525 strncpy(ctrl
->name
, "Brightness", sizeof(ctrl
->name
)-1);
3527 case V4L2_CID_CONTRAST
:
3528 strncpy(ctrl
->name
, "Contrast", sizeof(ctrl
->name
)-1);
3530 case V4L2_CID_SATURATION
:
3531 strncpy(ctrl
->name
, "Saturation", sizeof(ctrl
->name
)-1);
3534 strncpy(ctrl
->name
, "Hue", sizeof(ctrl
->name
)-1);
3539 ctrl
->maximum
= 65535;
3541 ctrl
->default_value
= 32768;
3542 ctrl
->type
= V4L2_CTRL_TYPE_INTEGER
;
3550 struct v4l2_control
*ctrl
= arg
;
3552 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_CTRL - id=%d\n",
3553 ZR_DEVNAME(zr
), ctrl
->id
);
3555 /* we only support hue/saturation/contrast/brightness */
3556 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3557 ctrl
->id
> V4L2_CID_HUE
)
3560 mutex_lock(&zr
->resource_lock
);
3562 case V4L2_CID_BRIGHTNESS
:
3563 ctrl
->value
= zr
->brightness
;
3565 case V4L2_CID_CONTRAST
:
3566 ctrl
->value
= zr
->contrast
;
3568 case V4L2_CID_SATURATION
:
3569 ctrl
->value
= zr
->saturation
;
3572 ctrl
->value
= zr
->hue
;
3575 mutex_unlock(&zr
->resource_lock
);
3583 struct v4l2_control
*ctrl
= arg
;
3584 struct video_picture pict
;
3586 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_CTRL - id=%d\n",
3587 ZR_DEVNAME(zr
), ctrl
->id
);
3589 /* we only support hue/saturation/contrast/brightness */
3590 if (ctrl
->id
< V4L2_CID_BRIGHTNESS
||
3591 ctrl
->id
> V4L2_CID_HUE
)
3594 if (ctrl
->value
< 0 || ctrl
->value
> 65535) {
3597 "%s: VIDIOC_S_CTRL - invalid value %d for id=%d\n",
3598 ZR_DEVNAME(zr
), ctrl
->value
, ctrl
->id
);
3602 mutex_lock(&zr
->resource_lock
);
3604 case V4L2_CID_BRIGHTNESS
:
3605 zr
->brightness
= ctrl
->value
;
3607 case V4L2_CID_CONTRAST
:
3608 zr
->contrast
= ctrl
->value
;
3610 case V4L2_CID_SATURATION
:
3611 zr
->saturation
= ctrl
->value
;
3614 zr
->hue
= ctrl
->value
;
3617 pict
.brightness
= zr
->brightness
;
3618 pict
.contrast
= zr
->contrast
;
3619 pict
.colour
= zr
->saturation
;
3622 decoder_command(zr
, DECODER_SET_PICTURE
, &pict
);
3624 mutex_unlock(&zr
->resource_lock
);
3630 case VIDIOC_ENUMSTD
:
3632 struct v4l2_standard
*std
= arg
;
3634 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMSTD - index=%d\n",
3635 ZR_DEVNAME(zr
), std
->index
);
3637 if (std
->index
< 0 || std
->index
>= (zr
->card
.norms
+ 1))
3640 int id
= std
->index
;
3641 memset(std
, 0, sizeof(*std
));
3645 if (std
->index
== zr
->card
.norms
) {
3646 /* if we have autodetect, ... */
3647 struct video_decoder_capability caps
;
3648 decoder_command(zr
, DECODER_GET_CAPABILITIES
,
3650 if (caps
.flags
& VIDEO_DECODER_AUTO
) {
3651 std
->id
= V4L2_STD_ALL
;
3652 strncpy(std
->name
, "Autodetect", sizeof(std
->name
)-1);
3657 switch (std
->index
) {
3659 std
->id
= V4L2_STD_PAL
;
3660 strncpy(std
->name
, "PAL", sizeof(std
->name
)-1);
3661 std
->frameperiod
.numerator
= 1;
3662 std
->frameperiod
.denominator
= 25;
3663 std
->framelines
= zr
->card
.tvn
[0]->Ht
;
3666 std
->id
= V4L2_STD_NTSC
;
3667 strncpy(std
->name
, "NTSC", sizeof(std
->name
)-1);
3668 std
->frameperiod
.numerator
= 1001;
3669 std
->frameperiod
.denominator
= 30000;
3670 std
->framelines
= zr
->card
.tvn
[1]->Ht
;
3673 std
->id
= V4L2_STD_SECAM
;
3674 strncpy(std
->name
, "SECAM", sizeof(std
->name
)-1);
3675 std
->frameperiod
.numerator
= 1;
3676 std
->frameperiod
.denominator
= 25;
3677 std
->framelines
= zr
->card
.tvn
[2]->Ht
;
3687 v4l2_std_id
*std
= arg
;
3690 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr
));
3692 mutex_lock(&zr
->resource_lock
);
3694 mutex_unlock(&zr
->resource_lock
);
3697 case VIDEO_MODE_PAL
:
3698 *std
= V4L2_STD_PAL
;
3700 case VIDEO_MODE_NTSC
:
3701 *std
= V4L2_STD_NTSC
;
3703 case VIDEO_MODE_SECAM
:
3704 *std
= V4L2_STD_SECAM
;
3714 int norm
= -1, res
= 0;
3715 v4l2_std_id
*std
= arg
;
3717 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_STD - norm=0x%llx\n",
3718 ZR_DEVNAME(zr
), (unsigned long long)*std
);
3720 if ((*std
& V4L2_STD_PAL
) && !(*std
& ~V4L2_STD_PAL
))
3721 norm
= VIDEO_MODE_PAL
;
3722 else if ((*std
& V4L2_STD_NTSC
) && !(*std
& ~V4L2_STD_NTSC
))
3723 norm
= VIDEO_MODE_NTSC
;
3724 else if ((*std
& V4L2_STD_SECAM
) && !(*std
& ~V4L2_STD_SECAM
))
3725 norm
= VIDEO_MODE_SECAM
;
3726 else if (*std
== V4L2_STD_ALL
)
3727 norm
= VIDEO_MODE_AUTO
;
3731 "%s: VIDIOC_S_STD - invalid norm 0x%llx\n",
3732 ZR_DEVNAME(zr
), (unsigned long long)*std
);
3736 mutex_lock(&zr
->resource_lock
);
3737 if ((res
= zoran_set_norm(zr
, norm
)))
3738 goto sstd_unlock_and_return
;
3740 res
= wait_grab_pending(zr
);
3741 sstd_unlock_and_return
:
3742 mutex_unlock(&zr
->resource_lock
);
3747 case VIDIOC_ENUMINPUT
:
3749 struct v4l2_input
*inp
= arg
;
3752 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMINPUT - index=%d\n",
3753 ZR_DEVNAME(zr
), inp
->index
);
3755 if (inp
->index
< 0 || inp
->index
>= zr
->card
.inputs
)
3758 int id
= inp
->index
;
3759 memset(inp
, 0, sizeof(*inp
));
3763 strncpy(inp
->name
, zr
->card
.input
[inp
->index
].name
,
3764 sizeof(inp
->name
) - 1);
3765 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
3766 inp
->std
= V4L2_STD_ALL
;
3768 /* Get status of video decoder */
3769 mutex_lock(&zr
->resource_lock
);
3770 decoder_command(zr
, DECODER_GET_STATUS
, &status
);
3771 mutex_unlock(&zr
->resource_lock
);
3773 if (!(status
& DECODER_STATUS_GOOD
)) {
3774 inp
->status
|= V4L2_IN_ST_NO_POWER
;
3775 inp
->status
|= V4L2_IN_ST_NO_SIGNAL
;
3777 if (!(status
& DECODER_STATUS_COLOR
))
3778 inp
->status
|= V4L2_IN_ST_NO_COLOR
;
3784 case VIDIOC_G_INPUT
:
3788 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr
));
3790 mutex_lock(&zr
->resource_lock
);
3792 mutex_unlock(&zr
->resource_lock
);
3798 case VIDIOC_S_INPUT
:
3800 int *input
= arg
, res
= 0;
3802 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_INPUT - input=%d\n",
3803 ZR_DEVNAME(zr
), *input
);
3805 mutex_lock(&zr
->resource_lock
);
3806 if ((res
= zoran_set_input(zr
, *input
)))
3807 goto sinput_unlock_and_return
;
3809 /* Make sure the changes come into effect */
3810 res
= wait_grab_pending(zr
);
3811 sinput_unlock_and_return
:
3812 mutex_unlock(&zr
->resource_lock
);
3817 case VIDIOC_ENUMOUTPUT
:
3819 struct v4l2_output
*outp
= arg
;
3821 dprintk(3, KERN_DEBUG
"%s: VIDIOC_ENUMOUTPUT - index=%d\n",
3822 ZR_DEVNAME(zr
), outp
->index
);
3824 if (outp
->index
!= 0)
3827 memset(outp
, 0, sizeof(*outp
));
3829 outp
->type
= V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY
;
3830 strncpy(outp
->name
, "Autodetect", sizeof(outp
->name
)-1);
3836 case VIDIOC_G_OUTPUT
:
3840 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_OUTPUT\n", ZR_DEVNAME(zr
));
3848 case VIDIOC_S_OUTPUT
:
3852 dprintk(3, KERN_DEBUG
"%s: VIDIOC_S_OUTPUT - output=%d\n",
3853 ZR_DEVNAME(zr
), *output
);
3862 /* cropping (sub-frame capture) */
3863 case VIDIOC_CROPCAP
:
3865 struct v4l2_cropcap
*cropcap
= arg
;
3866 int type
= cropcap
->type
, res
= 0;
3868 dprintk(3, KERN_ERR
"%s: VIDIOC_CROPCAP - type=%d\n",
3869 ZR_DEVNAME(zr
), cropcap
->type
);
3871 memset(cropcap
, 0, sizeof(*cropcap
));
3872 cropcap
->type
= type
;
3874 mutex_lock(&zr
->resource_lock
);
3876 if (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3877 (cropcap
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3878 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3881 "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n",
3884 goto cropcap_unlock_and_return
;
3887 cropcap
->bounds
.top
= cropcap
->bounds
.left
= 0;
3888 cropcap
->bounds
.width
= BUZ_MAX_WIDTH
;
3889 cropcap
->bounds
.height
= BUZ_MAX_HEIGHT
;
3890 cropcap
->defrect
.top
= cropcap
->defrect
.left
= 0;
3891 cropcap
->defrect
.width
= BUZ_MIN_WIDTH
;
3892 cropcap
->defrect
.height
= BUZ_MIN_HEIGHT
;
3893 cropcap_unlock_and_return
:
3894 mutex_unlock(&zr
->resource_lock
);
3901 struct v4l2_crop
*crop
= arg
;
3902 int type
= crop
->type
, res
= 0;
3904 dprintk(3, KERN_ERR
"%s: VIDIOC_G_CROP - type=%d\n",
3905 ZR_DEVNAME(zr
), crop
->type
);
3907 memset(crop
, 0, sizeof(*crop
));
3910 mutex_lock(&zr
->resource_lock
);
3912 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3913 (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3914 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3917 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
3920 goto gcrop_unlock_and_return
;
3923 crop
->c
.top
= fh
->jpg_settings
.img_y
;
3924 crop
->c
.left
= fh
->jpg_settings
.img_x
;
3925 crop
->c
.width
= fh
->jpg_settings
.img_width
;
3926 crop
->c
.height
= fh
->jpg_settings
.img_height
;
3928 gcrop_unlock_and_return
:
3929 mutex_unlock(&zr
->resource_lock
);
3937 struct v4l2_crop
*crop
= arg
;
3940 settings
= fh
->jpg_settings
;
3944 "%s: VIDIOC_S_CROP - type=%d, x=%d,y=%d,w=%d,h=%d\n",
3945 ZR_DEVNAME(zr
), crop
->type
, crop
->c
.left
, crop
->c
.top
,
3946 crop
->c
.width
, crop
->c
.height
);
3948 mutex_lock(&zr
->resource_lock
);
3950 if (fh
->jpg_buffers
.allocated
|| fh
->v4l_buffers
.allocated
) {
3953 "%s: VIDIOC_S_CROP - cannot change settings while active\n",
3956 goto scrop_unlock_and_return
;
3959 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
&&
3960 (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
||
3961 fh
->map_mode
== ZORAN_MAP_MODE_RAW
)) {
3964 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
3967 goto scrop_unlock_and_return
;
3970 /* move into a form that we understand */
3971 settings
.img_x
= crop
->c
.left
;
3972 settings
.img_y
= crop
->c
.top
;
3973 settings
.img_width
= crop
->c
.width
;
3974 settings
.img_height
= crop
->c
.height
;
3976 /* check validity */
3977 if ((res
= zoran_check_jpg_settings(zr
, &settings
)))
3978 goto scrop_unlock_and_return
;
3981 fh
->jpg_settings
= settings
;
3983 scrop_unlock_and_return
:
3984 mutex_unlock(&zr
->resource_lock
);
3989 case VIDIOC_G_JPEGCOMP
:
3991 struct v4l2_jpegcompression
*params
= arg
;
3993 dprintk(3, KERN_DEBUG
"%s: VIDIOC_G_JPEGCOMP\n",
3996 memset(params
, 0, sizeof(*params
));
3998 mutex_lock(&zr
->resource_lock
);
4000 params
->quality
= fh
->jpg_settings
.jpg_comp
.quality
;
4001 params
->APPn
= fh
->jpg_settings
.jpg_comp
.APPn
;
4002 memcpy(params
->APP_data
,
4003 fh
->jpg_settings
.jpg_comp
.APP_data
,
4004 fh
->jpg_settings
.jpg_comp
.APP_len
);
4005 params
->APP_len
= fh
->jpg_settings
.jpg_comp
.APP_len
;
4006 memcpy(params
->COM_data
,
4007 fh
->jpg_settings
.jpg_comp
.COM_data
,
4008 fh
->jpg_settings
.jpg_comp
.COM_len
);
4009 params
->COM_len
= fh
->jpg_settings
.jpg_comp
.COM_len
;
4010 params
->jpeg_markers
=
4011 fh
->jpg_settings
.jpg_comp
.jpeg_markers
;
4013 mutex_unlock(&zr
->resource_lock
);
4019 case VIDIOC_S_JPEGCOMP
:
4021 struct v4l2_jpegcompression
*params
= arg
;
4024 settings
= fh
->jpg_settings
;
4028 "%s: VIDIOC_S_JPEGCOMP - quality=%d, APPN=%d, APP_len=%d, COM_len=%d\n",
4029 ZR_DEVNAME(zr
), params
->quality
, params
->APPn
,
4030 params
->APP_len
, params
->COM_len
);
4032 settings
.jpg_comp
= *params
;
4034 mutex_lock(&zr
->resource_lock
);
4036 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
||
4037 fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
4040 "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n",
4043 goto sjpegc_unlock_and_return
;
4046 if ((res
= zoran_check_jpg_settings(zr
, &settings
)))
4047 goto sjpegc_unlock_and_return
;
4048 if (!fh
->jpg_buffers
.allocated
)
4049 fh
->jpg_buffers
.buffer_size
=
4050 zoran_v4l2_calc_bufsize(&fh
->jpg_settings
);
4051 fh
->jpg_settings
.jpg_comp
= *params
= settings
.jpg_comp
;
4052 sjpegc_unlock_and_return
:
4053 mutex_unlock(&zr
->resource_lock
);
4059 case VIDIOC_QUERYSTD
: /* why is this useful? */
4061 v4l2_std_id
*std
= arg
;
4064 KERN_DEBUG
"%s: VIDIOC_QUERY_STD - std=0x%llx\n",
4065 ZR_DEVNAME(zr
), (unsigned long long)*std
);
4067 if (*std
== V4L2_STD_ALL
|| *std
== V4L2_STD_NTSC
||
4068 *std
== V4L2_STD_PAL
|| (*std
== V4L2_STD_SECAM
&&
4069 zr
->card
.norms
== 3)) {
4077 case VIDIOC_TRY_FMT
:
4079 struct v4l2_format
*fmt
= arg
;
4082 dprintk(3, KERN_DEBUG
"%s: VIDIOC_TRY_FMT - type=%d\n",
4083 ZR_DEVNAME(zr
), fmt
->type
);
4085 switch (fmt
->type
) {
4086 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
4087 mutex_lock(&zr
->resource_lock
);
4089 if (fmt
->fmt
.win
.w
.width
> BUZ_MAX_WIDTH
)
4090 fmt
->fmt
.win
.w
.width
= BUZ_MAX_WIDTH
;
4091 if (fmt
->fmt
.win
.w
.width
< BUZ_MIN_WIDTH
)
4092 fmt
->fmt
.win
.w
.width
= BUZ_MIN_WIDTH
;
4093 if (fmt
->fmt
.win
.w
.height
> BUZ_MAX_HEIGHT
)
4094 fmt
->fmt
.win
.w
.height
= BUZ_MAX_HEIGHT
;
4095 if (fmt
->fmt
.win
.w
.height
< BUZ_MIN_HEIGHT
)
4096 fmt
->fmt
.win
.w
.height
= BUZ_MIN_HEIGHT
;
4098 mutex_unlock(&zr
->resource_lock
);
4101 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
4102 case V4L2_BUF_TYPE_VIDEO_OUTPUT
:
4103 if (fmt
->fmt
.pix
.bytesperline
> 0)
4106 mutex_lock(&zr
->resource_lock
);
4108 if (fmt
->fmt
.pix
.pixelformat
== V4L2_PIX_FMT_MJPEG
) {
4109 settings
= fh
->jpg_settings
;
4111 /* we actually need to set 'real' parameters now */
4112 if ((fmt
->fmt
.pix
.height
* 2) >
4114 settings
.TmpDcm
= 1;
4116 settings
.TmpDcm
= 2;
4117 settings
.decimation
= 0;
4118 if (fmt
->fmt
.pix
.height
<=
4119 fh
->jpg_settings
.img_height
/ 2)
4120 settings
.VerDcm
= 2;
4122 settings
.VerDcm
= 1;
4123 if (fmt
->fmt
.pix
.width
<=
4124 fh
->jpg_settings
.img_width
/ 4)
4125 settings
.HorDcm
= 4;
4126 else if (fmt
->fmt
.pix
.width
<=
4127 fh
->jpg_settings
.img_width
/ 2)
4128 settings
.HorDcm
= 2;
4130 settings
.HorDcm
= 1;
4131 if (settings
.TmpDcm
== 1)
4132 settings
.field_per_buff
= 2;
4134 settings
.field_per_buff
= 1;
4138 zoran_check_jpg_settings(zr
,
4140 goto tryfmt_unlock_and_return
;
4142 /* tell the user what we actually did */
4143 fmt
->fmt
.pix
.width
=
4144 settings
.img_width
/ settings
.HorDcm
;
4145 fmt
->fmt
.pix
.height
=
4146 settings
.img_height
* 2 /
4147 (settings
.TmpDcm
* settings
.VerDcm
);
4148 if (settings
.TmpDcm
== 1)
4149 fmt
->fmt
.pix
.field
=
4151 odd_even
? V4L2_FIELD_SEQ_TB
:
4154 fmt
->fmt
.pix
.field
=
4156 odd_even
? V4L2_FIELD_TOP
:
4159 fmt
->fmt
.pix
.sizeimage
=
4160 zoran_v4l2_calc_bufsize(&settings
);
4161 } else if (fmt
->type
==
4162 V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
4165 for (i
= 0; i
< NUM_FORMATS
; i
++)
4166 if (zoran_formats
[i
].fourcc
==
4167 fmt
->fmt
.pix
.pixelformat
)
4169 if (i
== NUM_FORMATS
) {
4171 goto tryfmt_unlock_and_return
;
4174 if (fmt
->fmt
.pix
.width
> BUZ_MAX_WIDTH
)
4175 fmt
->fmt
.pix
.width
= BUZ_MAX_WIDTH
;
4176 if (fmt
->fmt
.pix
.width
< BUZ_MIN_WIDTH
)
4177 fmt
->fmt
.pix
.width
= BUZ_MIN_WIDTH
;
4178 if (fmt
->fmt
.pix
.height
> BUZ_MAX_HEIGHT
)
4179 fmt
->fmt
.pix
.height
=
4181 if (fmt
->fmt
.pix
.height
< BUZ_MIN_HEIGHT
)
4182 fmt
->fmt
.pix
.height
=
4186 goto tryfmt_unlock_and_return
;
4188 tryfmt_unlock_and_return
:
4189 mutex_unlock(&zr
->resource_lock
);
4204 dprintk(1, KERN_DEBUG
"%s: UNKNOWN ioctl cmd: 0x%x\n",
4205 ZR_DEVNAME(zr
), cmd
);
4206 return -ENOIOCTLCMD
;
4215 zoran_ioctl (struct inode
*inode
,
4220 return video_usercopy(inode
, file
, cmd
, arg
, zoran_do_ioctl
);
4224 zoran_poll (struct file
*file
,
4227 struct zoran_fh
*fh
= file
->private_data
;
4228 struct zoran
*zr
= fh
->zr
;
4230 unsigned long flags
;
4232 /* we should check whether buffers are ready to be synced on
4233 * (w/o waits - O_NONBLOCK) here
4234 * if ready for read (sync), return POLLIN|POLLRDNORM,
4235 * if ready for write (sync), return POLLOUT|POLLWRNORM,
4236 * if error, return POLLERR,
4237 * if no buffers queued or so, return POLLNVAL
4240 mutex_lock(&zr
->resource_lock
);
4242 switch (fh
->map_mode
) {
4243 case ZORAN_MAP_MODE_RAW
:
4244 poll_wait(file
, &zr
->v4l_capq
, wait
);
4245 frame
= zr
->v4l_pend
[zr
->v4l_sync_tail
& V4L_MASK_FRAME
];
4247 spin_lock_irqsave(&zr
->spinlock
, flags
);
4250 "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n",
4251 ZR_DEVNAME(zr
), __FUNCTION__
,
4252 "FAL"[fh
->v4l_buffers
.active
], zr
->v4l_sync_tail
,
4253 "UPMD"[zr
->v4l_buffers
.buffer
[frame
].state
],
4254 zr
->v4l_pend_tail
, zr
->v4l_pend_head
);
4255 /* Process is the one capturing? */
4256 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
&&
4257 /* Buffer ready to DQBUF? */
4258 zr
->v4l_buffers
.buffer
[frame
].state
== BUZ_STATE_DONE
)
4259 res
= POLLIN
| POLLRDNORM
;
4260 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4264 case ZORAN_MAP_MODE_JPG_REC
:
4265 case ZORAN_MAP_MODE_JPG_PLAY
:
4266 poll_wait(file
, &zr
->jpg_capq
, wait
);
4267 frame
= zr
->jpg_pend
[zr
->jpg_que_tail
& BUZ_MASK_FRAME
];
4269 spin_lock_irqsave(&zr
->spinlock
, flags
);
4272 "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n",
4273 ZR_DEVNAME(zr
), __FUNCTION__
,
4274 "FAL"[fh
->jpg_buffers
.active
], zr
->jpg_que_tail
,
4275 "UPMD"[zr
->jpg_buffers
.buffer
[frame
].state
],
4276 zr
->jpg_que_head
, zr
->jpg_dma_tail
, zr
->jpg_dma_head
);
4277 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
&&
4278 zr
->jpg_buffers
.buffer
[frame
].state
== BUZ_STATE_DONE
) {
4279 if (fh
->map_mode
== ZORAN_MAP_MODE_JPG_REC
)
4280 res
= POLLIN
| POLLRDNORM
;
4282 res
= POLLOUT
| POLLWRNORM
;
4284 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4291 "%s: zoran_poll() - internal error, unknown map_mode=%d\n",
4292 ZR_DEVNAME(zr
), fh
->map_mode
);
4296 mutex_unlock(&zr
->resource_lock
);
4303 * This maps the buffers to user space.
4305 * Depending on the state of fh->map_mode
4306 * the V4L or the MJPEG buffers are mapped
4307 * per buffer or all together
4309 * Note that we need to connect to some
4310 * unmap signal event to unmap the de-allocate
4311 * the buffer accordingly (zoran_vm_close())
4315 zoran_vm_open (struct vm_area_struct
*vma
)
4317 struct zoran_mapping
*map
= vma
->vm_private_data
;
4323 zoran_vm_close (struct vm_area_struct
*vma
)
4325 struct zoran_mapping
*map
= vma
->vm_private_data
;
4326 struct file
*file
= map
->file
;
4327 struct zoran_fh
*fh
= file
->private_data
;
4328 struct zoran
*zr
= fh
->zr
;
4332 if (map
->count
== 0) {
4333 switch (fh
->map_mode
) {
4334 case ZORAN_MAP_MODE_JPG_REC
:
4335 case ZORAN_MAP_MODE_JPG_PLAY
:
4337 dprintk(3, KERN_INFO
"%s: munmap(MJPEG)\n",
4340 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++) {
4341 if (fh
->jpg_buffers
.buffer
[i
].map
== map
) {
4342 fh
->jpg_buffers
.buffer
[i
].map
=
4348 for (i
= 0; i
< fh
->jpg_buffers
.num_buffers
; i
++)
4349 if (fh
->jpg_buffers
.buffer
[i
].map
)
4351 if (i
== fh
->jpg_buffers
.num_buffers
) {
4352 mutex_lock(&zr
->resource_lock
);
4354 if (fh
->jpg_buffers
.active
!= ZORAN_FREE
) {
4355 jpg_qbuf(file
, -1, zr
->codec_mode
);
4356 zr
->jpg_buffers
.allocated
= 0;
4357 zr
->jpg_buffers
.active
=
4358 fh
->jpg_buffers
.active
=
4361 //jpg_fbuffer_free(file);
4362 fh
->jpg_buffers
.allocated
= 0;
4363 fh
->jpg_buffers
.ready_to_be_freed
= 1;
4365 mutex_unlock(&zr
->resource_lock
);
4370 case ZORAN_MAP_MODE_RAW
:
4372 dprintk(3, KERN_INFO
"%s: munmap(V4L)\n",
4375 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++) {
4376 if (fh
->v4l_buffers
.buffer
[i
].map
== map
) {
4378 fh
->v4l_buffers
.buffer
[i
].map
=
4384 for (i
= 0; i
< fh
->v4l_buffers
.num_buffers
; i
++)
4385 if (fh
->v4l_buffers
.buffer
[i
].map
)
4387 if (i
== fh
->v4l_buffers
.num_buffers
) {
4388 mutex_lock(&zr
->resource_lock
);
4390 if (fh
->v4l_buffers
.active
!= ZORAN_FREE
) {
4393 spin_lock_irqsave(&zr
->spinlock
, flags
);
4394 zr36057_set_memgrab(zr
, 0);
4395 zr
->v4l_buffers
.allocated
= 0;
4396 zr
->v4l_buffers
.active
=
4397 fh
->v4l_buffers
.active
=
4399 spin_unlock_irqrestore(&zr
->spinlock
, flags
);
4401 //v4l_fbuffer_free(file);
4402 fh
->v4l_buffers
.allocated
= 0;
4403 fh
->v4l_buffers
.ready_to_be_freed
= 1;
4405 mutex_unlock(&zr
->resource_lock
);
4412 "%s: munmap() - internal error - unknown map mode %d\n",
4413 ZR_DEVNAME(zr
), fh
->map_mode
);
4420 static struct vm_operations_struct zoran_vm_ops
= {
4421 .open
= zoran_vm_open
,
4422 .close
= zoran_vm_close
,
4426 zoran_mmap (struct file
*file
,
4427 struct vm_area_struct
*vma
)
4429 struct zoran_fh
*fh
= file
->private_data
;
4430 struct zoran
*zr
= fh
->zr
;
4431 unsigned long size
= (vma
->vm_end
- vma
->vm_start
);
4432 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
4434 unsigned long page
, start
= vma
->vm_start
, todo
, pos
, fraglen
;
4436 struct zoran_mapping
*map
;
4440 KERN_INFO
"%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n",
4442 fh
->map_mode
== ZORAN_MAP_MODE_RAW
? "V4L" : "MJPEG",
4443 vma
->vm_start
, vma
->vm_end
, size
);
4445 if (!(vma
->vm_flags
& VM_SHARED
) || !(vma
->vm_flags
& VM_READ
) ||
4446 !(vma
->vm_flags
& VM_WRITE
)) {
4449 "%s: mmap() - no MAP_SHARED/PROT_{READ,WRITE} given\n",
4454 switch (fh
->map_mode
) {
4456 case ZORAN_MAP_MODE_JPG_REC
:
4457 case ZORAN_MAP_MODE_JPG_PLAY
:
4460 mutex_lock(&zr
->resource_lock
);
4462 /* Map the MJPEG buffers */
4463 if (!fh
->jpg_buffers
.allocated
) {
4466 "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n",
4469 goto jpg_mmap_unlock_and_return
;
4472 first
= offset
/ fh
->jpg_buffers
.buffer_size
;
4473 last
= first
- 1 + size
/ fh
->jpg_buffers
.buffer_size
;
4474 if (offset
% fh
->jpg_buffers
.buffer_size
!= 0 ||
4475 size
% fh
->jpg_buffers
.buffer_size
!= 0 || first
< 0 ||
4476 last
< 0 || first
>= fh
->jpg_buffers
.num_buffers
||
4477 last
>= fh
->jpg_buffers
.num_buffers
) {
4480 "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
4481 ZR_DEVNAME(zr
), offset
, size
,
4482 fh
->jpg_buffers
.buffer_size
,
4483 fh
->jpg_buffers
.num_buffers
);
4485 goto jpg_mmap_unlock_and_return
;
4487 for (i
= first
; i
<= last
; i
++) {
4488 if (fh
->jpg_buffers
.buffer
[i
].map
) {
4491 "%s: mmap(MJPEG) - buffer %d already mapped\n",
4494 goto jpg_mmap_unlock_and_return
;
4498 /* map these buffers (v4l_buffers[i]) */
4499 map
= kmalloc(sizeof(struct zoran_mapping
), GFP_KERNEL
);
4502 goto jpg_mmap_unlock_and_return
;
4507 vma
->vm_ops
= &zoran_vm_ops
;
4508 vma
->vm_flags
|= VM_DONTEXPAND
;
4509 vma
->vm_private_data
= map
;
4511 for (i
= first
; i
<= last
; i
++) {
4513 j
< fh
->jpg_buffers
.buffer_size
/ PAGE_SIZE
;
4516 (le32_to_cpu(fh
->jpg_buffers
.buffer
[i
].
4517 frag_tab
[2 * j
+ 1]) & ~1) << 1;
4522 le32_to_cpu((unsigned long) fh
->jpg_buffers
.
4523 buffer
[i
].frag_tab
[2 * j
]);
4524 /* should just be pos on i386 */
4525 page
= virt_to_phys(bus_to_virt(pos
))
4527 if (remap_pfn_range(vma
, start
, page
,
4528 todo
, PAGE_SHARED
)) {
4531 "%s: zoran_mmap(V4L) - remap_pfn_range failed\n",
4534 goto jpg_mmap_unlock_and_return
;
4540 if (le32_to_cpu(fh
->jpg_buffers
.buffer
[i
].
4541 frag_tab
[2 * j
+ 1]) & 1)
4542 break; /* was last fragment */
4544 fh
->jpg_buffers
.buffer
[i
].map
= map
;
4549 jpg_mmap_unlock_and_return
:
4550 mutex_unlock(&zr
->resource_lock
);
4554 case ZORAN_MAP_MODE_RAW
:
4556 mutex_lock(&zr
->resource_lock
);
4558 /* Map the V4L buffers */
4559 if (!fh
->v4l_buffers
.allocated
) {
4562 "%s: zoran_mmap(V4L) - buffers not yet allocated\n",
4565 goto v4l_mmap_unlock_and_return
;
4568 first
= offset
/ fh
->v4l_buffers
.buffer_size
;
4569 last
= first
- 1 + size
/ fh
->v4l_buffers
.buffer_size
;
4570 if (offset
% fh
->v4l_buffers
.buffer_size
!= 0 ||
4571 size
% fh
->v4l_buffers
.buffer_size
!= 0 || first
< 0 ||
4572 last
< 0 || first
>= fh
->v4l_buffers
.num_buffers
||
4573 last
>= fh
->v4l_buffers
.buffer_size
) {
4576 "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
4577 ZR_DEVNAME(zr
), offset
, size
,
4578 fh
->v4l_buffers
.buffer_size
,
4579 fh
->v4l_buffers
.num_buffers
);
4581 goto v4l_mmap_unlock_and_return
;
4583 for (i
= first
; i
<= last
; i
++) {
4584 if (fh
->v4l_buffers
.buffer
[i
].map
) {
4587 "%s: mmap(V4L) - buffer %d already mapped\n",
4590 goto v4l_mmap_unlock_and_return
;
4594 /* map these buffers (v4l_buffers[i]) */
4595 map
= kmalloc(sizeof(struct zoran_mapping
), GFP_KERNEL
);
4598 goto v4l_mmap_unlock_and_return
;
4603 vma
->vm_ops
= &zoran_vm_ops
;
4604 vma
->vm_flags
|= VM_DONTEXPAND
;
4605 vma
->vm_private_data
= map
;
4607 for (i
= first
; i
<= last
; i
++) {
4609 if (todo
> fh
->v4l_buffers
.buffer_size
)
4610 todo
= fh
->v4l_buffers
.buffer_size
;
4611 page
= fh
->v4l_buffers
.buffer
[i
].fbuffer_phys
;
4612 if (remap_pfn_range(vma
, start
, page
>> PAGE_SHIFT
,
4613 todo
, PAGE_SHARED
)) {
4616 "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n",
4619 goto v4l_mmap_unlock_and_return
;
4623 fh
->v4l_buffers
.buffer
[i
].map
= map
;
4627 v4l_mmap_unlock_and_return
:
4628 mutex_unlock(&zr
->resource_lock
);
4635 "%s: zoran_mmap() - internal error - unknown map mode %d\n",
4636 ZR_DEVNAME(zr
), fh
->map_mode
);
4643 static const struct file_operations zoran_fops
= {
4644 .owner
= THIS_MODULE
,
4646 .release
= zoran_close
,
4647 .ioctl
= zoran_ioctl
,
4648 .compat_ioctl
= v4l_compat_ioctl32
,
4649 .llseek
= no_llseek
,
4651 .write
= zoran_write
,
4656 struct video_device zoran_template __devinitdata
= {
4658 .type
= ZORAN_VID_TYPE
,
4659 #ifdef CONFIG_VIDEO_V4L2
4660 .type2
= ZORAN_V4L2_VID_FLAGS
,
4662 .hardware
= ZORAN_HARDWARE
,
4663 .fops
= &zoran_fops
,
4664 .release
= &zoran_vdev_release
,