diff options
Diffstat (limited to 'drivers/media/video/zoran')
-rw-r--r-- | drivers/media/video/zoran/Kconfig | 8 | ||||
-rw-r--r-- | drivers/media/video/zoran/videocodec.h | 9 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran.h | 97 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_card.c | 555 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_card.h | 3 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_device.c | 529 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_device.h | 14 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_driver.c | 4385 | ||||
-rw-r--r-- | drivers/media/video/zoran/zoran_procfs.c | 2 | ||||
-rw-r--r-- | drivers/media/video/zoran/zr36016.c | 5 | ||||
-rw-r--r-- | drivers/media/video/zoran/zr36050.c | 4 | ||||
-rw-r--r-- | drivers/media/video/zoran/zr36060.c | 4 |
12 files changed, 2106 insertions, 3509 deletions
diff --git a/drivers/media/video/zoran/Kconfig b/drivers/media/video/zoran/Kconfig index 8666e19f31a7..fd4120e4c104 100644 --- a/drivers/media/video/zoran/Kconfig +++ b/drivers/media/video/zoran/Kconfig | |||
@@ -1,6 +1,6 @@ | |||
1 | config VIDEO_ZORAN | 1 | config VIDEO_ZORAN |
2 | tristate "Zoran ZR36057/36067 Video For Linux" | 2 | tristate "Zoran ZR36057/36067 Video For Linux" |
3 | depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && VIRT_TO_BUS | 3 | depends on PCI && I2C_ALGOBIT && VIDEO_V4L2 && VIRT_TO_BUS |
4 | help | 4 | help |
5 | Say Y for support for MJPEG capture cards based on the Zoran | 5 | Say Y for support for MJPEG capture cards based on the Zoran |
6 | 36057/36067 PCI controller chipset. This includes the Iomega | 6 | 36057/36067 PCI controller chipset. This includes the Iomega |
@@ -32,7 +32,7 @@ config VIDEO_ZORAN_ZR36060 | |||
32 | config VIDEO_ZORAN_BUZ | 32 | config VIDEO_ZORAN_BUZ |
33 | tristate "Iomega Buz support" | 33 | tristate "Iomega Buz support" |
34 | depends on VIDEO_ZORAN_ZR36060 | 34 | depends on VIDEO_ZORAN_ZR36060 |
35 | select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO | 35 | select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO |
36 | select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO | 36 | select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO |
37 | help | 37 | help |
38 | Support for the Iomega Buz MJPEG capture/playback card. | 38 | Support for the Iomega Buz MJPEG capture/playback card. |
@@ -58,7 +58,7 @@ config VIDEO_ZORAN_LML33 | |||
58 | config VIDEO_ZORAN_LML33R10 | 58 | config VIDEO_ZORAN_LML33R10 |
59 | tristate "Linux Media Labs LML33R10 support" | 59 | tristate "Linux Media Labs LML33R10 support" |
60 | depends on VIDEO_ZORAN_ZR36060 | 60 | depends on VIDEO_ZORAN_ZR36060 |
61 | select VIDEO_SAA7114 if VIDEO_HELPER_CHIPS_AUTO | 61 | select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO |
62 | select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO | 62 | select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO |
63 | help | 63 | help |
64 | support for the Linux Media Labs LML33R10 MJPEG capture/playback | 64 | support for the Linux Media Labs LML33R10 MJPEG capture/playback |
@@ -66,7 +66,7 @@ config VIDEO_ZORAN_LML33R10 | |||
66 | 66 | ||
67 | config VIDEO_ZORAN_AVS6EYES | 67 | config VIDEO_ZORAN_AVS6EYES |
68 | tristate "AverMedia 6 Eyes support (EXPERIMENTAL)" | 68 | tristate "AverMedia 6 Eyes support (EXPERIMENTAL)" |
69 | depends on VIDEO_ZORAN_ZR36060 && EXPERIMENTAL && VIDEO_V4L1 | 69 | depends on VIDEO_ZORAN_ZR36060 && EXPERIMENTAL |
70 | select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO | 70 | select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO |
71 | select VIDEO_BT866 if VIDEO_HELPER_CHIPS_AUTO | 71 | select VIDEO_BT866 if VIDEO_HELPER_CHIPS_AUTO |
72 | select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO | 72 | select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO |
diff --git a/drivers/media/video/zoran/videocodec.h b/drivers/media/video/zoran/videocodec.h index 97a3bbeda505..5c27b251354e 100644 --- a/drivers/media/video/zoran/videocodec.h +++ b/drivers/media/video/zoran/videocodec.h | |||
@@ -97,7 +97,7 @@ | |||
97 | available) - it returns 0 if the mode is possible | 97 | available) - it returns 0 if the mode is possible |
98 | set_size -> this fn-ref. sets the norm and image size for | 98 | set_size -> this fn-ref. sets the norm and image size for |
99 | compression/decompression (returns 0 on success) | 99 | compression/decompression (returns 0 on success) |
100 | the norm param is defined in videodev.h (VIDEO_MODE_*) | 100 | the norm param is defined in videodev2.h (V4L2_STD_*) |
101 | 101 | ||
102 | additional setup may be available, too - but the codec should work with | 102 | additional setup may be available, too - but the codec should work with |
103 | some default values even without this | 103 | some default values even without this |
@@ -144,9 +144,8 @@ M zr36055[1] 0001 0000c001 00000000 (zr36050[1]) | |||
144 | #ifndef __LINUX_VIDEOCODEC_H | 144 | #ifndef __LINUX_VIDEOCODEC_H |
145 | #define __LINUX_VIDEOCODEC_H | 145 | #define __LINUX_VIDEOCODEC_H |
146 | 146 | ||
147 | #include <linux/videodev.h> | 147 | #include <linux/videodev2.h> |
148 | 148 | ||
149 | //should be in videodev.h ??? (VID_DO_....) | ||
150 | #define CODEC_DO_COMPRESSION 0 | 149 | #define CODEC_DO_COMPRESSION 0 |
151 | #define CODEC_DO_EXPANSION 1 | 150 | #define CODEC_DO_EXPANSION 1 |
152 | 151 | ||
@@ -237,10 +236,6 @@ struct vfe_settings { | |||
237 | __u32 width, height; /* Area to capture */ | 236 | __u32 width, height; /* Area to capture */ |
238 | __u16 decimation; /* Decimation divider */ | 237 | __u16 decimation; /* Decimation divider */ |
239 | __u16 flags; /* Flags for capture */ | 238 | __u16 flags; /* Flags for capture */ |
240 | /* flags are the same as in struct video_capture - see videodev.h: | ||
241 | #define VIDEO_CAPTURE_ODD 0 | ||
242 | #define VIDEO_CAPTURE_EVEN 1 | ||
243 | */ | ||
244 | __u16 quality; /* quality of the video */ | 239 | __u16 quality; /* quality of the video */ |
245 | }; | 240 | }; |
246 | 241 | ||
diff --git a/drivers/media/video/zoran/zoran.h b/drivers/media/video/zoran/zoran.h index e873a916250f..afecf32f1a87 100644 --- a/drivers/media/video/zoran/zoran.h +++ b/drivers/media/video/zoran/zoran.h | |||
@@ -31,6 +31,8 @@ | |||
31 | #ifndef _BUZ_H_ | 31 | #ifndef _BUZ_H_ |
32 | #define _BUZ_H_ | 32 | #define _BUZ_H_ |
33 | 33 | ||
34 | #include <media/v4l2-device.h> | ||
35 | |||
34 | struct zoran_requestbuffers { | 36 | struct zoran_requestbuffers { |
35 | unsigned long count; /* Number of buffers for MJPEG grabbing */ | 37 | unsigned long count; /* Number of buffers for MJPEG grabbing */ |
36 | unsigned long size; /* Size PER BUFFER in bytes */ | 38 | unsigned long size; /* Size PER BUFFER in bytes */ |
@@ -170,7 +172,7 @@ Private IOCTL to set up for displaying MJPEG | |||
170 | #endif | 172 | #endif |
171 | #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1) | 173 | #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1) |
172 | 174 | ||
173 | #define MAX_KMALLOC_MEM (128*1024) | 175 | #define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME) |
174 | 176 | ||
175 | #include "zr36057.h" | 177 | #include "zr36057.h" |
176 | 178 | ||
@@ -240,9 +242,6 @@ enum gpcs_type { | |||
240 | 242 | ||
241 | struct zoran_format { | 243 | struct zoran_format { |
242 | char *name; | 244 | char *name; |
243 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | ||
244 | int palette; | ||
245 | #endif | ||
246 | __u32 fourcc; | 245 | __u32 fourcc; |
247 | int colorspace; | 246 | int colorspace; |
248 | int depth; | 247 | int depth; |
@@ -283,21 +282,21 @@ struct zoran_mapping { | |||
283 | int count; | 282 | int count; |
284 | }; | 283 | }; |
285 | 284 | ||
286 | struct zoran_jpg_buffer { | 285 | struct zoran_buffer { |
287 | struct zoran_mapping *map; | ||
288 | __le32 *frag_tab; /* addresses of frag table */ | ||
289 | u32 frag_tab_bus; /* same value cached to save time in ISR */ | ||
290 | enum zoran_buffer_state state; /* non-zero if corresponding buffer is in use in grab queue */ | ||
291 | struct zoran_sync bs; /* DONE: info to return to application */ | ||
292 | }; | ||
293 | |||
294 | struct zoran_v4l_buffer { | ||
295 | struct zoran_mapping *map; | 286 | struct zoran_mapping *map; |
296 | char *fbuffer; /* virtual address of frame buffer */ | 287 | enum zoran_buffer_state state; /* state: unused/pending/dma/done */ |
297 | unsigned long fbuffer_phys; /* physical address of frame buffer */ | 288 | struct zoran_sync bs; /* DONE: info to return to application */ |
298 | unsigned long fbuffer_bus; /* bus address of frame buffer */ | 289 | union { |
299 | enum zoran_buffer_state state; /* state: unused/pending/done */ | 290 | struct { |
300 | struct zoran_sync bs; /* DONE: info to return to application */ | 291 | __le32 *frag_tab; /* addresses of frag table */ |
292 | u32 frag_tab_bus; /* same value cached to save time in ISR */ | ||
293 | } jpg; | ||
294 | struct { | ||
295 | char *fbuffer; /* virtual address of frame buffer */ | ||
296 | unsigned long fbuffer_phys;/* physical address of frame buffer */ | ||
297 | unsigned long fbuffer_bus;/* bus address of frame buffer */ | ||
298 | } v4l; | ||
299 | }; | ||
301 | }; | 300 | }; |
302 | 301 | ||
303 | enum zoran_lock_activity { | 302 | enum zoran_lock_activity { |
@@ -307,21 +306,13 @@ enum zoran_lock_activity { | |||
307 | }; | 306 | }; |
308 | 307 | ||
309 | /* buffer collections */ | 308 | /* buffer collections */ |
310 | struct zoran_jpg_struct { | 309 | struct zoran_buffer_col { |
311 | enum zoran_lock_activity active; /* feature currently in use? */ | 310 | enum zoran_lock_activity active; /* feature currently in use? */ |
312 | struct zoran_jpg_buffer buffer[BUZ_MAX_FRAME]; /* buffers */ | 311 | unsigned int num_buffers, buffer_size; |
313 | int num_buffers, buffer_size; | 312 | struct zoran_buffer buffer[MAX_FRAME]; /* buffers */ |
314 | u8 allocated; /* Flag if buffers are allocated */ | 313 | u8 allocated; /* Flag if buffers are allocated */ |
315 | u8 ready_to_be_freed; /* hack - see zoran_driver.c */ | ||
316 | u8 need_contiguous; /* Flag if contiguous buffers are needed */ | 314 | u8 need_contiguous; /* Flag if contiguous buffers are needed */ |
317 | }; | 315 | /* only applies to jpg buffers, raw buffers are always contiguous */ |
318 | |||
319 | struct zoran_v4l_struct { | ||
320 | enum zoran_lock_activity active; /* feature currently in use? */ | ||
321 | struct zoran_v4l_buffer buffer[VIDEO_MAX_FRAME]; /* buffers */ | ||
322 | int num_buffers, buffer_size; | ||
323 | u8 allocated; /* Flag if buffers are allocated */ | ||
324 | u8 ready_to_be_freed; /* hack - see zoran_driver.c */ | ||
325 | }; | 316 | }; |
326 | 317 | ||
327 | struct zoran; | 318 | struct zoran; |
@@ -330,23 +321,27 @@ struct zoran; | |||
330 | struct zoran_fh { | 321 | struct zoran_fh { |
331 | struct zoran *zr; | 322 | struct zoran *zr; |
332 | 323 | ||
333 | enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */ | 324 | enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */ |
334 | 325 | ||
335 | struct zoran_overlay_settings overlay_settings; | 326 | struct zoran_overlay_settings overlay_settings; |
336 | u32 *overlay_mask; /* overlay mask */ | 327 | u32 *overlay_mask; /* overlay mask */ |
337 | enum zoran_lock_activity overlay_active; /* feature currently in use? */ | 328 | enum zoran_lock_activity overlay_active;/* feature currently in use? */ |
338 | 329 | ||
339 | struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */ | 330 | struct zoran_buffer_col buffers; /* buffers' info */ |
340 | struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */ | ||
341 | 331 | ||
332 | struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */ | ||
342 | struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */ | 333 | struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */ |
343 | struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */ | ||
344 | }; | 334 | }; |
345 | 335 | ||
346 | struct card_info { | 336 | struct card_info { |
347 | enum card_type type; | 337 | enum card_type type; |
348 | char name[32]; | 338 | char name[32]; |
349 | u16 i2c_decoder, i2c_encoder; /* I2C types */ | 339 | const char *i2c_decoder; /* i2c decoder device */ |
340 | const char *mod_decoder; /* i2c decoder module */ | ||
341 | const unsigned short *addrs_decoder; | ||
342 | const char *i2c_encoder; /* i2c encoder device */ | ||
343 | const char *mod_encoder; /* i2c encoder module */ | ||
344 | const unsigned short *addrs_encoder; | ||
350 | u16 video_vfe, video_codec; /* videocodec types */ | 345 | u16 video_vfe, video_codec; /* videocodec types */ |
351 | u16 audio_chip; /* audio type */ | 346 | u16 audio_chip; /* audio type */ |
352 | 347 | ||
@@ -356,7 +351,7 @@ struct card_info { | |||
356 | char name[32]; | 351 | char name[32]; |
357 | } input[BUZ_MAX_INPUT]; | 352 | } input[BUZ_MAX_INPUT]; |
358 | 353 | ||
359 | int norms; | 354 | v4l2_std_id norms; |
360 | struct tvnorm *tvn[3]; /* supported TV norms */ | 355 | struct tvnorm *tvn[3]; /* supported TV norms */ |
361 | 356 | ||
362 | u32 jpeg_int; /* JPEG interrupt */ | 357 | u32 jpeg_int; /* JPEG interrupt */ |
@@ -377,14 +372,15 @@ struct card_info { | |||
377 | }; | 372 | }; |
378 | 373 | ||
379 | struct zoran { | 374 | struct zoran { |
375 | struct v4l2_device v4l2_dev; | ||
380 | struct video_device *video_dev; | 376 | struct video_device *video_dev; |
381 | 377 | ||
382 | struct i2c_adapter i2c_adapter; /* */ | 378 | struct i2c_adapter i2c_adapter; /* */ |
383 | struct i2c_algo_bit_data i2c_algo; /* */ | 379 | struct i2c_algo_bit_data i2c_algo; /* */ |
384 | u32 i2cbr; | 380 | u32 i2cbr; |
385 | 381 | ||
386 | struct i2c_client *decoder; /* video decoder i2c client */ | 382 | struct v4l2_subdev *decoder; /* video decoder sub-device */ |
387 | struct i2c_client *encoder; /* video encoder i2c client */ | 383 | struct v4l2_subdev *encoder; /* video encoder sub-device */ |
388 | 384 | ||
389 | struct videocodec *codec; /* video codec */ | 385 | struct videocodec *codec; /* video codec */ |
390 | struct videocodec *vfe; /* video front end */ | 386 | struct videocodec *vfe; /* video front end */ |
@@ -405,9 +401,15 @@ struct zoran { | |||
405 | spinlock_t spinlock; /* Spinlock */ | 401 | spinlock_t spinlock; /* Spinlock */ |
406 | 402 | ||
407 | /* Video for Linux parameters */ | 403 | /* Video for Linux parameters */ |
408 | int input, norm; /* card's norm and input - norm=VIDEO_MODE_* */ | 404 | int input; /* card's norm and input - norm=VIDEO_MODE_* */ |
409 | int hue, saturation, contrast, brightness; /* Current picture params */ | 405 | v4l2_std_id norm; |
410 | struct video_buffer buffer; /* Current buffer params */ | 406 | |
407 | /* Current buffer params */ | ||
408 | void *vbuf_base; | ||
409 | int vbuf_height, vbuf_width; | ||
410 | int vbuf_depth; | ||
411 | int vbuf_bytesperline; | ||
412 | |||
411 | struct zoran_overlay_settings overlay_settings; | 413 | struct zoran_overlay_settings overlay_settings; |
412 | u32 *overlay_mask; /* overlay mask */ | 414 | u32 *overlay_mask; /* overlay mask */ |
413 | enum zoran_lock_activity overlay_active; /* feature currently in use? */ | 415 | enum zoran_lock_activity overlay_active; /* feature currently in use? */ |
@@ -427,7 +429,7 @@ struct zoran { | |||
427 | unsigned long v4l_pend_tail; | 429 | unsigned long v4l_pend_tail; |
428 | unsigned long v4l_sync_tail; | 430 | unsigned long v4l_sync_tail; |
429 | int v4l_pend[V4L_MAX_FRAME]; | 431 | int v4l_pend[V4L_MAX_FRAME]; |
430 | struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */ | 432 | struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */ |
431 | 433 | ||
432 | /* Buz MJPEG parameters */ | 434 | /* Buz MJPEG parameters */ |
433 | enum zoran_codec_mode codec_mode; /* status of codec */ | 435 | enum zoran_codec_mode codec_mode; /* status of codec */ |
@@ -454,7 +456,7 @@ struct zoran { | |||
454 | int jpg_pend[BUZ_MAX_FRAME]; | 456 | int jpg_pend[BUZ_MAX_FRAME]; |
455 | 457 | ||
456 | /* array indexed by frame number */ | 458 | /* array indexed by frame number */ |
457 | struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */ | 459 | struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */ |
458 | 460 | ||
459 | /* Additional stuff for testing */ | 461 | /* Additional stuff for testing */ |
460 | #ifdef CONFIG_PROC_FS | 462 | #ifdef CONFIG_PROC_FS |
@@ -488,6 +490,11 @@ struct zoran { | |||
488 | wait_queue_head_t test_q; | 490 | wait_queue_head_t test_q; |
489 | }; | 491 | }; |
490 | 492 | ||
493 | static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev) | ||
494 | { | ||
495 | return container_of(v4l2_dev, struct zoran, v4l2_dev); | ||
496 | } | ||
497 | |||
491 | /* There was something called _ALPHA_BUZ that used the PCI address instead of | 498 | /* There was something called _ALPHA_BUZ that used the PCI address instead of |
492 | * the kernel iomapped address for btread/btwrite. */ | 499 | * the kernel iomapped address for btread/btwrite. */ |
493 | #define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr)) | 500 | #define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr)) |
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c index 5d2f090aa0f8..f91bba435ed5 100644 --- a/drivers/media/video/zoran/zoran_card.c +++ b/drivers/media/video/zoran/zoran_card.c | |||
@@ -38,8 +38,7 @@ | |||
38 | #include <linux/proc_fs.h> | 38 | #include <linux/proc_fs.h> |
39 | #include <linux/i2c.h> | 39 | #include <linux/i2c.h> |
40 | #include <linux/i2c-algo-bit.h> | 40 | #include <linux/i2c-algo-bit.h> |
41 | #include <linux/videodev.h> | 41 | #include <linux/videodev2.h> |
42 | #include <media/v4l2-common.h> | ||
43 | #include <linux/spinlock.h> | 42 | #include <linux/spinlock.h> |
44 | #include <linux/sem.h> | 43 | #include <linux/sem.h> |
45 | #include <linux/kmod.h> | 44 | #include <linux/kmod.h> |
@@ -47,11 +46,10 @@ | |||
47 | 46 | ||
48 | #include <linux/pci.h> | 47 | #include <linux/pci.h> |
49 | #include <linux/interrupt.h> | 48 | #include <linux/interrupt.h> |
50 | #include <linux/video_decoder.h> | ||
51 | #include <linux/video_encoder.h> | ||
52 | #include <linux/mutex.h> | 49 | #include <linux/mutex.h> |
53 | 50 | #include <linux/io.h> | |
54 | #include <asm/io.h> | 51 | #include <media/v4l2-common.h> |
52 | #include <media/bt819.h> | ||
55 | 53 | ||
56 | #include "videocodec.h" | 54 | #include "videocodec.h" |
57 | #include "zoran.h" | 55 | #include "zoran.h" |
@@ -108,25 +106,8 @@ static int video_nr[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 }; | |||
108 | module_param_array(video_nr, int, NULL, 0444); | 106 | module_param_array(video_nr, int, NULL, 0444); |
109 | MODULE_PARM_DESC(video_nr, "Video device number (-1=Auto)"); | 107 | MODULE_PARM_DESC(video_nr, "Video device number (-1=Auto)"); |
110 | 108 | ||
111 | /* | 109 | int v4l_nbufs = 4; |
112 | Number and size of grab buffers for Video 4 Linux | 110 | int v4l_bufsize = 864; /* Everybody should be able to work with this setting */ |
113 | The vast majority of applications should not need more than 2, | ||
114 | the very popular BTTV driver actually does ONLY have 2. | ||
115 | Time sensitive applications might need more, the maximum | ||
116 | is VIDEO_MAX_FRAME (defined in <linux/videodev.h>). | ||
117 | |||
118 | The size is set so that the maximum possible request | ||
119 | can be satisfied. Decrease it, if bigphys_area alloc'd | ||
120 | memory is low. If you don't have the bigphys_area patch, | ||
121 | set it to 128 KB. Will you allow only to grab small | ||
122 | images with V4L, but that's better than nothing. | ||
123 | |||
124 | v4l_bufsize has to be given in KB ! | ||
125 | |||
126 | */ | ||
127 | |||
128 | int v4l_nbufs = 2; | ||
129 | int v4l_bufsize = 128; /* Everybody should be able to work with this setting */ | ||
130 | module_param(v4l_nbufs, int, 0644); | 111 | module_param(v4l_nbufs, int, 0644); |
131 | MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use"); | 112 | MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use"); |
132 | module_param(v4l_bufsize, int, 0644); | 113 | module_param(v4l_bufsize, int, 0644); |
@@ -273,7 +254,7 @@ zr36016_write (struct videocodec *codec, | |||
273 | static void | 254 | static void |
274 | dc10_init (struct zoran *zr) | 255 | dc10_init (struct zoran *zr) |
275 | { | 256 | { |
276 | dprintk(3, KERN_DEBUG "%s: dc10_init()\n", ZR_DEVNAME(zr)); | 257 | dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); |
277 | 258 | ||
278 | /* Pixel clock selection */ | 259 | /* Pixel clock selection */ |
279 | GPIO(zr, 4, 0); | 260 | GPIO(zr, 4, 0); |
@@ -285,13 +266,13 @@ dc10_init (struct zoran *zr) | |||
285 | static void | 266 | static void |
286 | dc10plus_init (struct zoran *zr) | 267 | dc10plus_init (struct zoran *zr) |
287 | { | 268 | { |
288 | dprintk(3, KERN_DEBUG "%s: dc10plus_init()\n", ZR_DEVNAME(zr)); | 269 | dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); |
289 | } | 270 | } |
290 | 271 | ||
291 | static void | 272 | static void |
292 | buz_init (struct zoran *zr) | 273 | buz_init (struct zoran *zr) |
293 | { | 274 | { |
294 | dprintk(3, KERN_DEBUG "%s: buz_init()\n", ZR_DEVNAME(zr)); | 275 | dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); |
295 | 276 | ||
296 | /* some stuff from Iomega */ | 277 | /* some stuff from Iomega */ |
297 | pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15); | 278 | pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15); |
@@ -302,7 +283,7 @@ buz_init (struct zoran *zr) | |||
302 | static void | 283 | static void |
303 | lml33_init (struct zoran *zr) | 284 | lml33_init (struct zoran *zr) |
304 | { | 285 | { |
305 | dprintk(3, KERN_DEBUG "%s: lml33_init()\n", ZR_DEVNAME(zr)); | 286 | dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); |
306 | 287 | ||
307 | GPIO(zr, 2, 1); // Set Composite input/output | 288 | GPIO(zr, 2, 1); // Set Composite input/output |
308 | } | 289 | } |
@@ -332,50 +313,6 @@ avs6eyes_init (struct zoran *zr) | |||
332 | } | 313 | } |
333 | 314 | ||
334 | static char * | 315 | static char * |
335 | i2cid_to_modulename (u16 i2c_id) | ||
336 | { | ||
337 | char *name = NULL; | ||
338 | |||
339 | switch (i2c_id) { | ||
340 | case I2C_DRIVERID_SAA7110: | ||
341 | name = "saa7110"; | ||
342 | break; | ||
343 | case I2C_DRIVERID_SAA7111A: | ||
344 | name = "saa7111"; | ||
345 | break; | ||
346 | case I2C_DRIVERID_SAA7114: | ||
347 | name = "saa7114"; | ||
348 | break; | ||
349 | case I2C_DRIVERID_SAA7185B: | ||
350 | name = "saa7185"; | ||
351 | break; | ||
352 | case I2C_DRIVERID_ADV7170: | ||
353 | name = "adv7170"; | ||
354 | break; | ||
355 | case I2C_DRIVERID_ADV7175: | ||
356 | name = "adv7175"; | ||
357 | break; | ||
358 | case I2C_DRIVERID_BT819: | ||
359 | name = "bt819"; | ||
360 | break; | ||
361 | case I2C_DRIVERID_BT856: | ||
362 | name = "bt856"; | ||
363 | break; | ||
364 | case I2C_DRIVERID_BT866: | ||
365 | name = "bt866"; | ||
366 | break; | ||
367 | case I2C_DRIVERID_VPX3220: | ||
368 | name = "vpx3220"; | ||
369 | break; | ||
370 | case I2C_DRIVERID_KS0127: | ||
371 | name = "ks0127"; | ||
372 | break; | ||
373 | } | ||
374 | |||
375 | return name; | ||
376 | } | ||
377 | |||
378 | static char * | ||
379 | codecid_to_modulename (u16 codecid) | 316 | codecid_to_modulename (u16 codecid) |
380 | { | 317 | { |
381 | char *name = NULL; | 318 | char *name = NULL; |
@@ -425,11 +362,24 @@ static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 } | |||
425 | static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 }; | 362 | static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 }; |
426 | static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 }; | 363 | static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 }; |
427 | 364 | ||
365 | static const unsigned short vpx3220_addrs[] = { 0x43, 0x47, I2C_CLIENT_END }; | ||
366 | static const unsigned short saa7110_addrs[] = { 0x4e, 0x4f, I2C_CLIENT_END }; | ||
367 | static const unsigned short saa7111_addrs[] = { 0x25, 0x24, I2C_CLIENT_END }; | ||
368 | static const unsigned short saa7114_addrs[] = { 0x21, 0x20, I2C_CLIENT_END }; | ||
369 | static const unsigned short adv717x_addrs[] = { 0x6a, 0x6b, 0x2a, 0x2b, I2C_CLIENT_END }; | ||
370 | static const unsigned short ks0127_addrs[] = { 0x6c, 0x6d, I2C_CLIENT_END }; | ||
371 | static const unsigned short saa7185_addrs[] = { 0x44, I2C_CLIENT_END }; | ||
372 | static const unsigned short bt819_addrs[] = { 0x45, I2C_CLIENT_END }; | ||
373 | static const unsigned short bt856_addrs[] = { 0x44, I2C_CLIENT_END }; | ||
374 | static const unsigned short bt866_addrs[] = { 0x44, I2C_CLIENT_END }; | ||
375 | |||
428 | static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | 376 | static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { |
429 | { | 377 | { |
430 | .type = DC10_old, | 378 | .type = DC10_old, |
431 | .name = "DC10(old)", | 379 | .name = "DC10(old)", |
432 | .i2c_decoder = I2C_DRIVERID_VPX3220, | 380 | .i2c_decoder = "vpx3220a", |
381 | .mod_decoder = "vpx3220", | ||
382 | .addrs_decoder = vpx3220_addrs, | ||
433 | .video_codec = CODEC_TYPE_ZR36050, | 383 | .video_codec = CODEC_TYPE_ZR36050, |
434 | .video_vfe = CODEC_TYPE_ZR36016, | 384 | .video_vfe = CODEC_TYPE_ZR36016, |
435 | 385 | ||
@@ -439,7 +389,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
439 | { 2, "S-Video" }, | 389 | { 2, "S-Video" }, |
440 | { 0, "Internal/comp" } | 390 | { 0, "Internal/comp" } |
441 | }, | 391 | }, |
442 | .norms = 3, | 392 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM, |
443 | .tvn = { | 393 | .tvn = { |
444 | &f50sqpixel_dc10, | 394 | &f50sqpixel_dc10, |
445 | &f60sqpixel_dc10, | 395 | &f60sqpixel_dc10, |
@@ -457,8 +407,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
457 | }, { | 407 | }, { |
458 | .type = DC10_new, | 408 | .type = DC10_new, |
459 | .name = "DC10(new)", | 409 | .name = "DC10(new)", |
460 | .i2c_decoder = I2C_DRIVERID_SAA7110, | 410 | .i2c_decoder = "saa7110", |
461 | .i2c_encoder = I2C_DRIVERID_ADV7175, | 411 | .mod_decoder = "saa7110", |
412 | .addrs_decoder = saa7110_addrs, | ||
413 | .i2c_encoder = "adv7175", | ||
414 | .mod_encoder = "adv7175", | ||
415 | .addrs_encoder = adv717x_addrs, | ||
462 | .video_codec = CODEC_TYPE_ZR36060, | 416 | .video_codec = CODEC_TYPE_ZR36060, |
463 | 417 | ||
464 | .inputs = 3, | 418 | .inputs = 3, |
@@ -467,7 +421,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
467 | { 7, "S-Video" }, | 421 | { 7, "S-Video" }, |
468 | { 5, "Internal/comp" } | 422 | { 5, "Internal/comp" } |
469 | }, | 423 | }, |
470 | .norms = 3, | 424 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM, |
471 | .tvn = { | 425 | .tvn = { |
472 | &f50sqpixel, | 426 | &f50sqpixel, |
473 | &f60sqpixel, | 427 | &f60sqpixel, |
@@ -484,8 +438,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
484 | }, { | 438 | }, { |
485 | .type = DC10plus, | 439 | .type = DC10plus, |
486 | .name = "DC10plus", | 440 | .name = "DC10plus", |
487 | .i2c_decoder = I2C_DRIVERID_SAA7110, | 441 | .i2c_decoder = "saa7110", |
488 | .i2c_encoder = I2C_DRIVERID_ADV7175, | 442 | .mod_decoder = "saa7110", |
443 | .addrs_decoder = saa7110_addrs, | ||
444 | .i2c_encoder = "adv7175", | ||
445 | .mod_encoder = "adv7175", | ||
446 | .addrs_encoder = adv717x_addrs, | ||
489 | .video_codec = CODEC_TYPE_ZR36060, | 447 | .video_codec = CODEC_TYPE_ZR36060, |
490 | 448 | ||
491 | .inputs = 3, | 449 | .inputs = 3, |
@@ -494,7 +452,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
494 | { 7, "S-Video" }, | 452 | { 7, "S-Video" }, |
495 | { 5, "Internal/comp" } | 453 | { 5, "Internal/comp" } |
496 | }, | 454 | }, |
497 | .norms = 3, | 455 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM, |
498 | .tvn = { | 456 | .tvn = { |
499 | &f50sqpixel, | 457 | &f50sqpixel, |
500 | &f60sqpixel, | 458 | &f60sqpixel, |
@@ -512,8 +470,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
512 | }, { | 470 | }, { |
513 | .type = DC30, | 471 | .type = DC30, |
514 | .name = "DC30", | 472 | .name = "DC30", |
515 | .i2c_decoder = I2C_DRIVERID_VPX3220, | 473 | .i2c_decoder = "vpx3220a", |
516 | .i2c_encoder = I2C_DRIVERID_ADV7175, | 474 | .mod_decoder = "vpx3220", |
475 | .addrs_decoder = vpx3220_addrs, | ||
476 | .i2c_encoder = "adv7175", | ||
477 | .mod_encoder = "adv7175", | ||
478 | .addrs_encoder = adv717x_addrs, | ||
517 | .video_codec = CODEC_TYPE_ZR36050, | 479 | .video_codec = CODEC_TYPE_ZR36050, |
518 | .video_vfe = CODEC_TYPE_ZR36016, | 480 | .video_vfe = CODEC_TYPE_ZR36016, |
519 | 481 | ||
@@ -523,7 +485,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
523 | { 2, "S-Video" }, | 485 | { 2, "S-Video" }, |
524 | { 0, "Internal/comp" } | 486 | { 0, "Internal/comp" } |
525 | }, | 487 | }, |
526 | .norms = 3, | 488 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM, |
527 | .tvn = { | 489 | .tvn = { |
528 | &f50sqpixel_dc10, | 490 | &f50sqpixel_dc10, |
529 | &f60sqpixel_dc10, | 491 | &f60sqpixel_dc10, |
@@ -541,8 +503,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
541 | }, { | 503 | }, { |
542 | .type = DC30plus, | 504 | .type = DC30plus, |
543 | .name = "DC30plus", | 505 | .name = "DC30plus", |
544 | .i2c_decoder = I2C_DRIVERID_VPX3220, | 506 | .i2c_decoder = "vpx3220a", |
545 | .i2c_encoder = I2C_DRIVERID_ADV7175, | 507 | .mod_decoder = "vpx3220", |
508 | .addrs_decoder = vpx3220_addrs, | ||
509 | .i2c_encoder = "adv7175", | ||
510 | .mod_encoder = "adv7175", | ||
511 | .addrs_encoder = adv717x_addrs, | ||
546 | .video_codec = CODEC_TYPE_ZR36050, | 512 | .video_codec = CODEC_TYPE_ZR36050, |
547 | .video_vfe = CODEC_TYPE_ZR36016, | 513 | .video_vfe = CODEC_TYPE_ZR36016, |
548 | 514 | ||
@@ -552,7 +518,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
552 | { 2, "S-Video" }, | 518 | { 2, "S-Video" }, |
553 | { 0, "Internal/comp" } | 519 | { 0, "Internal/comp" } |
554 | }, | 520 | }, |
555 | .norms = 3, | 521 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM, |
556 | .tvn = { | 522 | .tvn = { |
557 | &f50sqpixel_dc10, | 523 | &f50sqpixel_dc10, |
558 | &f60sqpixel_dc10, | 524 | &f60sqpixel_dc10, |
@@ -570,8 +536,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
570 | }, { | 536 | }, { |
571 | .type = LML33, | 537 | .type = LML33, |
572 | .name = "LML33", | 538 | .name = "LML33", |
573 | .i2c_decoder = I2C_DRIVERID_BT819, | 539 | .i2c_decoder = "bt819a", |
574 | .i2c_encoder = I2C_DRIVERID_BT856, | 540 | .mod_decoder = "bt819", |
541 | .addrs_decoder = bt819_addrs, | ||
542 | .i2c_encoder = "bt856", | ||
543 | .mod_encoder = "bt856", | ||
544 | .addrs_encoder = bt856_addrs, | ||
575 | .video_codec = CODEC_TYPE_ZR36060, | 545 | .video_codec = CODEC_TYPE_ZR36060, |
576 | 546 | ||
577 | .inputs = 2, | 547 | .inputs = 2, |
@@ -579,7 +549,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
579 | { 0, "Composite" }, | 549 | { 0, "Composite" }, |
580 | { 7, "S-Video" } | 550 | { 7, "S-Video" } |
581 | }, | 551 | }, |
582 | .norms = 2, | 552 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL, |
583 | .tvn = { | 553 | .tvn = { |
584 | &f50ccir601_lml33, | 554 | &f50ccir601_lml33, |
585 | &f60ccir601_lml33, | 555 | &f60ccir601_lml33, |
@@ -597,8 +567,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
597 | }, { | 567 | }, { |
598 | .type = LML33R10, | 568 | .type = LML33R10, |
599 | .name = "LML33R10", | 569 | .name = "LML33R10", |
600 | .i2c_decoder = I2C_DRIVERID_SAA7114, | 570 | .i2c_decoder = "saa7114", |
601 | .i2c_encoder = I2C_DRIVERID_ADV7170, | 571 | .mod_decoder = "saa7115", |
572 | .addrs_decoder = saa7114_addrs, | ||
573 | .i2c_encoder = "adv7170", | ||
574 | .mod_encoder = "adv7170", | ||
575 | .addrs_encoder = adv717x_addrs, | ||
602 | .video_codec = CODEC_TYPE_ZR36060, | 576 | .video_codec = CODEC_TYPE_ZR36060, |
603 | 577 | ||
604 | .inputs = 2, | 578 | .inputs = 2, |
@@ -606,7 +580,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
606 | { 0, "Composite" }, | 580 | { 0, "Composite" }, |
607 | { 7, "S-Video" } | 581 | { 7, "S-Video" } |
608 | }, | 582 | }, |
609 | .norms = 2, | 583 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL, |
610 | .tvn = { | 584 | .tvn = { |
611 | &f50ccir601_lm33r10, | 585 | &f50ccir601_lm33r10, |
612 | &f60ccir601_lm33r10, | 586 | &f60ccir601_lm33r10, |
@@ -624,8 +598,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
624 | }, { | 598 | }, { |
625 | .type = BUZ, | 599 | .type = BUZ, |
626 | .name = "Buz", | 600 | .name = "Buz", |
627 | .i2c_decoder = I2C_DRIVERID_SAA7111A, | 601 | .i2c_decoder = "saa7111", |
628 | .i2c_encoder = I2C_DRIVERID_SAA7185B, | 602 | .mod_decoder = "saa7115", |
603 | .addrs_decoder = saa7111_addrs, | ||
604 | .i2c_encoder = "saa7185", | ||
605 | .mod_encoder = "saa7185", | ||
606 | .addrs_encoder = saa7185_addrs, | ||
629 | .video_codec = CODEC_TYPE_ZR36060, | 607 | .video_codec = CODEC_TYPE_ZR36060, |
630 | 608 | ||
631 | .inputs = 2, | 609 | .inputs = 2, |
@@ -633,7 +611,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
633 | { 3, "Composite" }, | 611 | { 3, "Composite" }, |
634 | { 7, "S-Video" } | 612 | { 7, "S-Video" } |
635 | }, | 613 | }, |
636 | .norms = 3, | 614 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM, |
637 | .tvn = { | 615 | .tvn = { |
638 | &f50ccir601, | 616 | &f50ccir601, |
639 | &f60ccir601, | 617 | &f60ccir601, |
@@ -653,8 +631,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
653 | .name = "6-Eyes", | 631 | .name = "6-Eyes", |
654 | /* AverMedia chose not to brand the 6-Eyes. Thus it | 632 | /* AverMedia chose not to brand the 6-Eyes. Thus it |
655 | can't be autodetected, and requires card=x. */ | 633 | can't be autodetected, and requires card=x. */ |
656 | .i2c_decoder = I2C_DRIVERID_KS0127, | 634 | .i2c_decoder = "ks0127", |
657 | .i2c_encoder = I2C_DRIVERID_BT866, | 635 | .mod_decoder = "ks0127", |
636 | .addrs_decoder = ks0127_addrs, | ||
637 | .i2c_encoder = "bt866", | ||
638 | .mod_encoder = "bt866", | ||
639 | .addrs_encoder = bt866_addrs, | ||
658 | .video_codec = CODEC_TYPE_ZR36060, | 640 | .video_codec = CODEC_TYPE_ZR36060, |
659 | 641 | ||
660 | .inputs = 10, | 642 | .inputs = 10, |
@@ -670,7 +652,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { | |||
670 | {10, "S-Video 3" }, | 652 | {10, "S-Video 3" }, |
671 | {15, "YCbCr" } | 653 | {15, "YCbCr" } |
672 | }, | 654 | }, |
673 | .norms = 2, | 655 | .norms = V4L2_STD_NTSC|V4L2_STD_PAL, |
674 | .tvn = { | 656 | .tvn = { |
675 | &f50ccir601_avs6eyes, | 657 | &f50ccir601_avs6eyes, |
676 | &f60ccir601_avs6eyes, | 658 | &f60ccir601_avs6eyes, |
@@ -735,69 +717,6 @@ zoran_i2c_setscl (void *data, | |||
735 | btwrite(zr->i2cbr, ZR36057_I2CBR); | 717 | btwrite(zr->i2cbr, ZR36057_I2CBR); |
736 | } | 718 | } |
737 | 719 | ||
738 | static int | ||
739 | zoran_i2c_client_register (struct i2c_client *client) | ||
740 | { | ||
741 | struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter); | ||
742 | int res = 0; | ||
743 | |||
744 | dprintk(2, | ||
745 | KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n", | ||
746 | ZR_DEVNAME(zr), client->driver->id); | ||
747 | |||
748 | mutex_lock(&zr->resource_lock); | ||
749 | |||
750 | if (zr->user > 0) { | ||
751 | /* we're already busy, so we keep a reference to | ||
752 | * them... Could do a lot of stuff here, but this | ||
753 | * is easiest. (Did I ever mention I'm a lazy ass?) | ||
754 | */ | ||
755 | res = -EBUSY; | ||
756 | goto clientreg_unlock_and_return; | ||
757 | } | ||
758 | |||
759 | if (client->driver->id == zr->card.i2c_decoder) | ||
760 | zr->decoder = client; | ||
761 | else if (client->driver->id == zr->card.i2c_encoder) | ||
762 | zr->encoder = client; | ||
763 | else { | ||
764 | res = -ENODEV; | ||
765 | goto clientreg_unlock_and_return; | ||
766 | } | ||
767 | |||
768 | clientreg_unlock_and_return: | ||
769 | mutex_unlock(&zr->resource_lock); | ||
770 | |||
771 | return res; | ||
772 | } | ||
773 | |||
774 | static int | ||
775 | zoran_i2c_client_unregister (struct i2c_client *client) | ||
776 | { | ||
777 | struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter); | ||
778 | int res = 0; | ||
779 | |||
780 | dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr)); | ||
781 | |||
782 | mutex_lock(&zr->resource_lock); | ||
783 | |||
784 | if (zr->user > 0) { | ||
785 | res = -EBUSY; | ||
786 | goto clientunreg_unlock_and_return; | ||
787 | } | ||
788 | |||
789 | /* try to locate it */ | ||
790 | if (client == zr->encoder) { | ||
791 | zr->encoder = NULL; | ||
792 | } else if (client == zr->decoder) { | ||
793 | zr->decoder = NULL; | ||
794 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id); | ||
795 | } | ||
796 | clientunreg_unlock_and_return: | ||
797 | mutex_unlock(&zr->resource_lock); | ||
798 | return res; | ||
799 | } | ||
800 | |||
801 | static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = { | 720 | static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = { |
802 | .setsda = zoran_i2c_setsda, | 721 | .setsda = zoran_i2c_setsda, |
803 | .setscl = zoran_i2c_setscl, | 722 | .setscl = zoran_i2c_setscl, |
@@ -813,13 +732,10 @@ zoran_register_i2c (struct zoran *zr) | |||
813 | memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template, | 732 | memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template, |
814 | sizeof(struct i2c_algo_bit_data)); | 733 | sizeof(struct i2c_algo_bit_data)); |
815 | zr->i2c_algo.data = zr; | 734 | zr->i2c_algo.data = zr; |
816 | zr->i2c_adapter.class = I2C_CLASS_TV_ANALOG; | ||
817 | zr->i2c_adapter.id = I2C_HW_B_ZR36067; | 735 | zr->i2c_adapter.id = I2C_HW_B_ZR36067; |
818 | zr->i2c_adapter.client_register = zoran_i2c_client_register; | ||
819 | zr->i2c_adapter.client_unregister = zoran_i2c_client_unregister; | ||
820 | strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr), | 736 | strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr), |
821 | sizeof(zr->i2c_adapter.name)); | 737 | sizeof(zr->i2c_adapter.name)); |
822 | i2c_set_adapdata(&zr->i2c_adapter, zr); | 738 | i2c_set_adapdata(&zr->i2c_adapter, &zr->v4l2_dev); |
823 | zr->i2c_adapter.algo_data = &zr->i2c_algo; | 739 | zr->i2c_adapter.algo_data = &zr->i2c_algo; |
824 | zr->i2c_adapter.dev.parent = &zr->pci_dev->dev; | 740 | zr->i2c_adapter.dev.parent = &zr->pci_dev->dev; |
825 | return i2c_bit_add_bus(&zr->i2c_adapter); | 741 | return i2c_bit_add_bus(&zr->i2c_adapter); |
@@ -835,19 +751,20 @@ zoran_unregister_i2c (struct zoran *zr) | |||
835 | 751 | ||
836 | int | 752 | int |
837 | zoran_check_jpg_settings (struct zoran *zr, | 753 | zoran_check_jpg_settings (struct zoran *zr, |
838 | struct zoran_jpg_settings *settings) | 754 | struct zoran_jpg_settings *settings, |
755 | int try) | ||
839 | { | 756 | { |
840 | int err = 0, err0 = 0; | 757 | int err = 0, err0 = 0; |
841 | 758 | ||
842 | dprintk(4, | 759 | dprintk(4, |
843 | KERN_DEBUG | 760 | KERN_DEBUG |
844 | "%s: check_jpg_settings() - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n", | 761 | "%s: %s - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n", |
845 | ZR_DEVNAME(zr), settings->decimation, settings->HorDcm, | 762 | ZR_DEVNAME(zr), __func__, settings->decimation, settings->HorDcm, |
846 | settings->VerDcm, settings->TmpDcm); | 763 | settings->VerDcm, settings->TmpDcm); |
847 | dprintk(4, | 764 | dprintk(4, |
848 | KERN_DEBUG | 765 | KERN_DEBUG |
849 | "%s: check_jpg_settings() - x: %d, y: %d, w: %d, y: %d\n", | 766 | "%s: %s - x: %d, y: %d, w: %d, y: %d\n", |
850 | ZR_DEVNAME(zr), settings->img_x, settings->img_y, | 767 | ZR_DEVNAME(zr), __func__, settings->img_x, settings->img_y, |
851 | settings->img_width, settings->img_height); | 768 | settings->img_width, settings->img_height); |
852 | /* Check decimation, set default values for decimation = 1, 2, 4 */ | 769 | /* Check decimation, set default values for decimation = 1, 2, 4 */ |
853 | switch (settings->decimation) { | 770 | switch (settings->decimation) { |
@@ -879,8 +796,8 @@ zoran_check_jpg_settings (struct zoran *zr, | |||
879 | if (zr->card.type == DC10_new) { | 796 | if (zr->card.type == DC10_new) { |
880 | dprintk(1, | 797 | dprintk(1, |
881 | KERN_DEBUG | 798 | KERN_DEBUG |
882 | "%s: check_jpg_settings() - HDec by 4 is not supported on the DC10\n", | 799 | "%s: %s - HDec by 4 is not supported on the DC10\n", |
883 | ZR_DEVNAME(zr)); | 800 | ZR_DEVNAME(zr), __func__); |
884 | err0++; | 801 | err0++; |
885 | break; | 802 | break; |
886 | } | 803 | } |
@@ -900,50 +817,73 @@ zoran_check_jpg_settings (struct zoran *zr, | |||
900 | /* We have to check the data the user has set */ | 817 | /* We have to check the data the user has set */ |
901 | 818 | ||
902 | if (settings->HorDcm != 1 && settings->HorDcm != 2 && | 819 | if (settings->HorDcm != 1 && settings->HorDcm != 2 && |
903 | (zr->card.type == DC10_new || settings->HorDcm != 4)) | 820 | (zr->card.type == DC10_new || settings->HorDcm != 4)) { |
821 | settings->HorDcm = clamp(settings->HorDcm, 1, 2); | ||
904 | err0++; | 822 | err0++; |
905 | if (settings->VerDcm != 1 && settings->VerDcm != 2) | 823 | } |
824 | if (settings->VerDcm != 1 && settings->VerDcm != 2) { | ||
825 | settings->VerDcm = clamp(settings->VerDcm, 1, 2); | ||
906 | err0++; | 826 | err0++; |
907 | if (settings->TmpDcm != 1 && settings->TmpDcm != 2) | 827 | } |
828 | if (settings->TmpDcm != 1 && settings->TmpDcm != 2) { | ||
829 | settings->TmpDcm = clamp(settings->TmpDcm, 1, 2); | ||
908 | err0++; | 830 | err0++; |
831 | } | ||
909 | if (settings->field_per_buff != 1 && | 832 | if (settings->field_per_buff != 1 && |
910 | settings->field_per_buff != 2) | 833 | settings->field_per_buff != 2) { |
834 | settings->field_per_buff = clamp(settings->field_per_buff, 1, 2); | ||
911 | err0++; | 835 | err0++; |
912 | if (settings->img_x < 0) | 836 | } |
837 | if (settings->img_x < 0) { | ||
838 | settings->img_x = 0; | ||
913 | err0++; | 839 | err0++; |
914 | if (settings->img_y < 0) | 840 | } |
841 | if (settings->img_y < 0) { | ||
842 | settings->img_y = 0; | ||
915 | err0++; | 843 | err0++; |
916 | if (settings->img_width < 0) | 844 | } |
845 | if (settings->img_width < 0 || settings->img_width > BUZ_MAX_WIDTH) { | ||
846 | settings->img_width = clamp(settings->img_width, 0, (int)BUZ_MAX_WIDTH); | ||
917 | err0++; | 847 | err0++; |
918 | if (settings->img_height < 0) | 848 | } |
849 | if (settings->img_height < 0 || settings->img_height > BUZ_MAX_HEIGHT / 2) { | ||
850 | settings->img_height = clamp(settings->img_height, 0, BUZ_MAX_HEIGHT / 2); | ||
919 | err0++; | 851 | err0++; |
920 | if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) | 852 | } |
853 | if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) { | ||
854 | settings->img_x = BUZ_MAX_WIDTH - settings->img_width; | ||
921 | err0++; | 855 | err0++; |
922 | if (settings->img_y + settings->img_height > | 856 | } |
923 | BUZ_MAX_HEIGHT / 2) | 857 | if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2) { |
858 | settings->img_y = BUZ_MAX_HEIGHT / 2 - settings->img_height; | ||
859 | err0++; | ||
860 | } | ||
861 | if (settings->img_width % (16 * settings->HorDcm) != 0) { | ||
862 | settings->img_width -= settings->img_width % (16 * settings->HorDcm); | ||
863 | if (settings->img_width == 0) | ||
864 | settings->img_width = 16 * settings->HorDcm; | ||
865 | err0++; | ||
866 | } | ||
867 | if (settings->img_height % (8 * settings->VerDcm) != 0) { | ||
868 | settings->img_height -= settings->img_height % (8 * settings->VerDcm); | ||
869 | if (settings->img_height == 0) | ||
870 | settings->img_height = 8 * settings->VerDcm; | ||
924 | err0++; | 871 | err0++; |
925 | if (settings->HorDcm && settings->VerDcm) { | ||
926 | if (settings->img_width % | ||
927 | (16 * settings->HorDcm) != 0) | ||
928 | err0++; | ||
929 | if (settings->img_height % | ||
930 | (8 * settings->VerDcm) != 0) | ||
931 | err0++; | ||
932 | } | 872 | } |
933 | 873 | ||
934 | if (err0) { | 874 | if (!try && err0) { |
935 | dprintk(1, | 875 | dprintk(1, |
936 | KERN_ERR | 876 | KERN_ERR |
937 | "%s: check_jpg_settings() - error in params for decimation = 0\n", | 877 | "%s: %s - error in params for decimation = 0\n", |
938 | ZR_DEVNAME(zr)); | 878 | ZR_DEVNAME(zr), __func__); |
939 | err++; | 879 | err++; |
940 | } | 880 | } |
941 | break; | 881 | break; |
942 | default: | 882 | default: |
943 | dprintk(1, | 883 | dprintk(1, |
944 | KERN_ERR | 884 | KERN_ERR |
945 | "%s: check_jpg_settings() - decimation = %d, must be 0, 1, 2 or 4\n", | 885 | "%s: %s - decimation = %d, must be 0, 1, 2 or 4\n", |
946 | ZR_DEVNAME(zr), settings->decimation); | 886 | ZR_DEVNAME(zr), __func__, settings->decimation); |
947 | err++; | 887 | err++; |
948 | break; | 888 | break; |
949 | } | 889 | } |
@@ -1021,12 +961,10 @@ zoran_open_init_params (struct zoran *zr) | |||
1021 | sizeof(zr->jpg_settings.jpg_comp.COM_data)); | 961 | sizeof(zr->jpg_settings.jpg_comp.COM_data)); |
1022 | zr->jpg_settings.jpg_comp.jpeg_markers = | 962 | zr->jpg_settings.jpg_comp.jpeg_markers = |
1023 | JPEG_MARKER_DHT | JPEG_MARKER_DQT; | 963 | JPEG_MARKER_DHT | JPEG_MARKER_DQT; |
1024 | i = zoran_check_jpg_settings(zr, &zr->jpg_settings); | 964 | i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0); |
1025 | if (i) | 965 | if (i) |
1026 | dprintk(1, | 966 | dprintk(1, KERN_ERR "%s: %s internal error\n", |
1027 | KERN_ERR | 967 | ZR_DEVNAME(zr), __func__); |
1028 | "%s: zoran_open_init_params() internal error\n", | ||
1029 | ZR_DEVNAME(zr)); | ||
1030 | 968 | ||
1031 | clear_interrupt_counters(zr); | 969 | clear_interrupt_counters(zr); |
1032 | zr->testing = 0; | 970 | zr->testing = 0; |
@@ -1062,13 +1000,11 @@ static int __devinit | |||
1062 | zr36057_init (struct zoran *zr) | 1000 | zr36057_init (struct zoran *zr) |
1063 | { | 1001 | { |
1064 | int j, err; | 1002 | int j, err; |
1065 | int two = 2; | ||
1066 | int zero = 0; | ||
1067 | 1003 | ||
1068 | dprintk(1, | 1004 | dprintk(1, |
1069 | KERN_INFO | 1005 | KERN_INFO |
1070 | "%s: zr36057_init() - initializing card[%d], zr=%p\n", | 1006 | "%s: %s - initializing card[%d], zr=%p\n", |
1071 | ZR_DEVNAME(zr), zr->id, zr); | 1007 | ZR_DEVNAME(zr), __func__, zr->id, zr); |
1072 | 1008 | ||
1073 | /* default setup of all parameters which will persist between opens */ | 1009 | /* default setup of all parameters which will persist between opens */ |
1074 | zr->user = 0; | 1010 | zr->user = 0; |
@@ -1079,24 +1015,32 @@ zr36057_init (struct zoran *zr) | |||
1079 | zr->jpg_buffers.allocated = 0; | 1015 | zr->jpg_buffers.allocated = 0; |
1080 | zr->v4l_buffers.allocated = 0; | 1016 | zr->v4l_buffers.allocated = 0; |
1081 | 1017 | ||
1082 | zr->buffer.base = (void *) vidmem; | 1018 | zr->vbuf_base = (void *) vidmem; |
1083 | zr->buffer.width = 0; | 1019 | zr->vbuf_width = 0; |
1084 | zr->buffer.height = 0; | 1020 | zr->vbuf_height = 0; |
1085 | zr->buffer.depth = 0; | 1021 | zr->vbuf_depth = 0; |
1086 | zr->buffer.bytesperline = 0; | 1022 | zr->vbuf_bytesperline = 0; |
1087 | 1023 | ||
1088 | /* Avoid nonsense settings from user for default input/norm */ | 1024 | /* Avoid nonsense settings from user for default input/norm */ |
1089 | if (default_norm < VIDEO_MODE_PAL && | 1025 | if (default_norm < 0 && default_norm > 2) |
1090 | default_norm > VIDEO_MODE_SECAM) | 1026 | default_norm = 0; |
1091 | default_norm = VIDEO_MODE_PAL; | 1027 | if (default_norm == 0) { |
1092 | zr->norm = default_norm; | 1028 | zr->norm = V4L2_STD_PAL; |
1093 | if (!(zr->timing = zr->card.tvn[zr->norm])) { | 1029 | zr->timing = zr->card.tvn[0]; |
1030 | } else if (default_norm == 1) { | ||
1031 | zr->norm = V4L2_STD_NTSC; | ||
1032 | zr->timing = zr->card.tvn[1]; | ||
1033 | } else { | ||
1034 | zr->norm = V4L2_STD_SECAM; | ||
1035 | zr->timing = zr->card.tvn[2]; | ||
1036 | } | ||
1037 | if (zr->timing == NULL) { | ||
1094 | dprintk(1, | 1038 | dprintk(1, |
1095 | KERN_WARNING | 1039 | KERN_WARNING |
1096 | "%s: zr36057_init() - default TV standard not supported by hardware. PAL will be used.\n", | 1040 | "%s: %s - default TV standard not supported by hardware. PAL will be used.\n", |
1097 | ZR_DEVNAME(zr)); | 1041 | ZR_DEVNAME(zr), __func__); |
1098 | zr->norm = VIDEO_MODE_PAL; | 1042 | zr->norm = V4L2_STD_PAL; |
1099 | zr->timing = zr->card.tvn[zr->norm]; | 1043 | zr->timing = zr->card.tvn[0]; |
1100 | } | 1044 | } |
1101 | 1045 | ||
1102 | if (default_input > zr->card.inputs-1) { | 1046 | if (default_input > zr->card.inputs-1) { |
@@ -1108,12 +1052,6 @@ zr36057_init (struct zoran *zr) | |||
1108 | } | 1052 | } |
1109 | zr->input = default_input; | 1053 | zr->input = default_input; |
1110 | 1054 | ||
1111 | /* Should the following be reset at every open ? */ | ||
1112 | zr->hue = 32768; | ||
1113 | zr->contrast = 32768; | ||
1114 | zr->saturation = 32768; | ||
1115 | zr->brightness = 32768; | ||
1116 | |||
1117 | /* default setup (will be repeated at every open) */ | 1055 | /* default setup (will be repeated at every open) */ |
1118 | zoran_open_init_params(zr); | 1056 | zoran_open_init_params(zr); |
1119 | 1057 | ||
@@ -1124,8 +1062,8 @@ zr36057_init (struct zoran *zr) | |||
1124 | if (!zr->stat_com || !zr->video_dev) { | 1062 | if (!zr->stat_com || !zr->video_dev) { |
1125 | dprintk(1, | 1063 | dprintk(1, |
1126 | KERN_ERR | 1064 | KERN_ERR |
1127 | "%s: zr36057_init() - kmalloc (STAT_COM) failed\n", | 1065 | "%s: %s - kmalloc (STAT_COM) failed\n", |
1128 | ZR_DEVNAME(zr)); | 1066 | ZR_DEVNAME(zr), __func__); |
1129 | err = -ENOMEM; | 1067 | err = -ENOMEM; |
1130 | goto exit_free; | 1068 | goto exit_free; |
1131 | } | 1069 | } |
@@ -1137,6 +1075,7 @@ zr36057_init (struct zoran *zr) | |||
1137 | * Now add the template and register the device unit. | 1075 | * Now add the template and register the device unit. |
1138 | */ | 1076 | */ |
1139 | memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); | 1077 | memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); |
1078 | zr->video_dev->parent = &zr->pci_dev->dev; | ||
1140 | strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); | 1079 | strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); |
1141 | err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]); | 1080 | err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]); |
1142 | if (err < 0) | 1081 | if (err < 0) |
@@ -1148,8 +1087,10 @@ zr36057_init (struct zoran *zr) | |||
1148 | detect_guest_activity(zr); | 1087 | detect_guest_activity(zr); |
1149 | test_interrupts(zr); | 1088 | test_interrupts(zr); |
1150 | if (!pass_through) { | 1089 | if (!pass_through) { |
1151 | decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero); | 1090 | struct v4l2_routing route = { 2, 0 }; |
1152 | encoder_command(zr, ENCODER_SET_INPUT, &two); | 1091 | |
1092 | decoder_call(zr, video, s_stream, 0); | ||
1093 | encoder_call(zr, video, s_routing, &route); | ||
1153 | } | 1094 | } |
1154 | 1095 | ||
1155 | zr->zoran_proc = NULL; | 1096 | zr->zoran_proc = NULL; |
@@ -1164,7 +1105,8 @@ exit_free: | |||
1164 | 1105 | ||
1165 | static void __devexit zoran_remove(struct pci_dev *pdev) | 1106 | static void __devexit zoran_remove(struct pci_dev *pdev) |
1166 | { | 1107 | { |
1167 | struct zoran *zr = pci_get_drvdata(pdev); | 1108 | struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev); |
1109 | struct zoran *zr = to_zoran(v4l2_dev); | ||
1168 | 1110 | ||
1169 | if (!zr->initialized) | 1111 | if (!zr->initialized) |
1170 | goto exit_free; | 1112 | goto exit_free; |
@@ -1197,7 +1139,7 @@ static void __devexit zoran_remove(struct pci_dev *pdev) | |||
1197 | pci_disable_device(zr->pci_dev); | 1139 | pci_disable_device(zr->pci_dev); |
1198 | video_unregister_device(zr->video_dev); | 1140 | video_unregister_device(zr->video_dev); |
1199 | exit_free: | 1141 | exit_free: |
1200 | pci_set_drvdata(pdev, NULL); | 1142 | v4l2_device_unregister(&zr->v4l2_dev); |
1201 | kfree(zr); | 1143 | kfree(zr); |
1202 | } | 1144 | } |
1203 | 1145 | ||
@@ -1215,10 +1157,8 @@ zoran_setup_videocodec (struct zoran *zr, | |||
1215 | 1157 | ||
1216 | m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL); | 1158 | m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL); |
1217 | if (!m) { | 1159 | if (!m) { |
1218 | dprintk(1, | 1160 | dprintk(1, KERN_ERR "%s: %s - no memory\n", |
1219 | KERN_ERR | 1161 | ZR_DEVNAME(zr), __func__); |
1220 | "%s: zoran_setup_videocodec() - no memory\n", | ||
1221 | ZR_DEVNAME(zr)); | ||
1222 | return m; | 1162 | return m; |
1223 | } | 1163 | } |
1224 | 1164 | ||
@@ -1256,6 +1196,18 @@ zoran_setup_videocodec (struct zoran *zr, | |||
1256 | return m; | 1196 | return m; |
1257 | } | 1197 | } |
1258 | 1198 | ||
1199 | static void zoran_subdev_notify(struct v4l2_subdev *sd, unsigned int cmd, void *arg) | ||
1200 | { | ||
1201 | struct zoran *zr = to_zoran(sd->v4l2_dev); | ||
1202 | |||
1203 | /* Bt819 needs to reset its FIFO buffer using #FRST pin and | ||
1204 | LML33 card uses GPIO(7) for that. */ | ||
1205 | if (cmd == BT819_FIFO_RESET_LOW) | ||
1206 | GPIO(zr, 7, 0); | ||
1207 | else if (cmd == BT819_FIFO_RESET_HIGH) | ||
1208 | GPIO(zr, 7, 1); | ||
1209 | } | ||
1210 | |||
1259 | /* | 1211 | /* |
1260 | * Scan for a Buz card (actually for the PCI controller ZR36057), | 1212 | * Scan for a Buz card (actually for the PCI controller ZR36057), |
1261 | * request the irq and map the io memory | 1213 | * request the irq and map the io memory |
@@ -1269,34 +1221,33 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1269 | struct videocodec_master *master_vfe = NULL; | 1221 | struct videocodec_master *master_vfe = NULL; |
1270 | struct videocodec_master *master_codec = NULL; | 1222 | struct videocodec_master *master_codec = NULL; |
1271 | int card_num; | 1223 | int card_num; |
1272 | char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name; | 1224 | char *codec_name, *vfe_name; |
1273 | unsigned int nr; | 1225 | unsigned int nr; |
1274 | 1226 | ||
1275 | 1227 | ||
1276 | nr = zoran_num++; | 1228 | nr = zoran_num++; |
1277 | if (nr >= BUZ_MAX) { | 1229 | if (nr >= BUZ_MAX) { |
1278 | dprintk(1, | 1230 | dprintk(1, KERN_ERR "%s: driver limited to %d card(s) maximum\n", |
1279 | KERN_ERR | ||
1280 | "%s: driver limited to %d card(s) maximum\n", | ||
1281 | ZORAN_NAME, BUZ_MAX); | 1231 | ZORAN_NAME, BUZ_MAX); |
1282 | return -ENOENT; | 1232 | return -ENOENT; |
1283 | } | 1233 | } |
1284 | 1234 | ||
1285 | zr = kzalloc(sizeof(struct zoran), GFP_KERNEL); | 1235 | zr = kzalloc(sizeof(struct zoran), GFP_KERNEL); |
1286 | if (!zr) { | 1236 | if (!zr) { |
1287 | dprintk(1, | 1237 | dprintk(1, KERN_ERR "%s: %s - kzalloc failed\n", |
1288 | KERN_ERR | 1238 | ZORAN_NAME, __func__); |
1289 | "%s: find_zr36057() - kzalloc failed\n", | ||
1290 | ZORAN_NAME); | ||
1291 | return -ENOMEM; | 1239 | return -ENOMEM; |
1292 | } | 1240 | } |
1241 | zr->v4l2_dev.notify = zoran_subdev_notify; | ||
1242 | if (v4l2_device_register(&pdev->dev, &zr->v4l2_dev)) | ||
1243 | goto zr_free_mem; | ||
1293 | zr->pci_dev = pdev; | 1244 | zr->pci_dev = pdev; |
1294 | zr->id = nr; | 1245 | zr->id = nr; |
1295 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); | 1246 | snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); |
1296 | spin_lock_init(&zr->spinlock); | 1247 | spin_lock_init(&zr->spinlock); |
1297 | mutex_init(&zr->resource_lock); | 1248 | mutex_init(&zr->resource_lock); |
1298 | if (pci_enable_device(pdev)) | 1249 | if (pci_enable_device(pdev)) |
1299 | goto zr_free_mem; | 1250 | goto zr_unreg; |
1300 | pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision); | 1251 | pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision); |
1301 | 1252 | ||
1302 | dprintk(1, | 1253 | dprintk(1, |
@@ -1323,7 +1274,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1323 | KERN_ERR | 1274 | KERN_ERR |
1324 | "%s: It is not possible to auto-detect ZR36057 based cards\n", | 1275 | "%s: It is not possible to auto-detect ZR36057 based cards\n", |
1325 | ZR_DEVNAME(zr)); | 1276 | ZR_DEVNAME(zr)); |
1326 | goto zr_free_mem; | 1277 | goto zr_unreg; |
1327 | } | 1278 | } |
1328 | 1279 | ||
1329 | card_num = ent->driver_data; | 1280 | card_num = ent->driver_data; |
@@ -1332,7 +1283,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1332 | KERN_ERR | 1283 | KERN_ERR |
1333 | "%s: Unknown card, try specifying card=X module parameter\n", | 1284 | "%s: Unknown card, try specifying card=X module parameter\n", |
1334 | ZR_DEVNAME(zr)); | 1285 | ZR_DEVNAME(zr)); |
1335 | goto zr_free_mem; | 1286 | goto zr_unreg; |
1336 | } | 1287 | } |
1337 | dprintk(3, | 1288 | dprintk(3, |
1338 | KERN_DEBUG | 1289 | KERN_DEBUG |
@@ -1345,7 +1296,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1345 | KERN_ERR | 1296 | KERN_ERR |
1346 | "%s: User specified card type %d out of range (0 .. %d)\n", | 1297 | "%s: User specified card type %d out of range (0 .. %d)\n", |
1347 | ZR_DEVNAME(zr), card_num, NUM_CARDS - 1); | 1298 | ZR_DEVNAME(zr), card_num, NUM_CARDS - 1); |
1348 | goto zr_free_mem; | 1299 | goto zr_unreg; |
1349 | } | 1300 | } |
1350 | } | 1301 | } |
1351 | 1302 | ||
@@ -1360,11 +1311,9 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1360 | 1311 | ||
1361 | zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0); | 1312 | zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0); |
1362 | if (!zr->zr36057_mem) { | 1313 | if (!zr->zr36057_mem) { |
1363 | dprintk(1, | 1314 | dprintk(1, KERN_ERR "%s: %s() - ioremap failed\n", |
1364 | KERN_ERR | ||
1365 | "%s: %s() - ioremap failed\n", | ||
1366 | ZR_DEVNAME(zr), __func__); | 1315 | ZR_DEVNAME(zr), __func__); |
1367 | goto zr_free_mem; | 1316 | goto zr_unreg; |
1368 | } | 1317 | } |
1369 | 1318 | ||
1370 | result = request_irq(zr->pci_dev->irq, zoran_irq, | 1319 | result = request_irq(zr->pci_dev->irq, zoran_irq, |
@@ -1373,18 +1322,18 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1373 | if (result == -EINVAL) { | 1322 | if (result == -EINVAL) { |
1374 | dprintk(1, | 1323 | dprintk(1, |
1375 | KERN_ERR | 1324 | KERN_ERR |
1376 | "%s: find_zr36057() - bad irq number or handler\n", | 1325 | "%s: %s - bad irq number or handler\n", |
1377 | ZR_DEVNAME(zr)); | 1326 | ZR_DEVNAME(zr), __func__); |
1378 | } else if (result == -EBUSY) { | 1327 | } else if (result == -EBUSY) { |
1379 | dprintk(1, | 1328 | dprintk(1, |
1380 | KERN_ERR | 1329 | KERN_ERR |
1381 | "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n", | 1330 | "%s: %s - IRQ %d busy, change your PnP config in BIOS\n", |
1382 | ZR_DEVNAME(zr), zr->pci_dev->irq); | 1331 | ZR_DEVNAME(zr), __func__, zr->pci_dev->irq); |
1383 | } else { | 1332 | } else { |
1384 | dprintk(1, | 1333 | dprintk(1, |
1385 | KERN_ERR | 1334 | KERN_ERR |
1386 | "%s: find_zr36057() - can't assign irq, error code %d\n", | 1335 | "%s: %s - can't assign irq, error code %d\n", |
1387 | ZR_DEVNAME(zr), result); | 1336 | ZR_DEVNAME(zr), __func__, result); |
1388 | } | 1337 | } |
1389 | goto zr_unmap; | 1338 | goto zr_unmap; |
1390 | } | 1339 | } |
@@ -1394,9 +1343,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1394 | &latency); | 1343 | &latency); |
1395 | need_latency = zr->revision > 1 ? 32 : 48; | 1344 | need_latency = zr->revision > 1 ? 32 : 48; |
1396 | if (latency != need_latency) { | 1345 | if (latency != need_latency) { |
1397 | dprintk(2, | 1346 | dprintk(2, KERN_INFO "%s: Changing PCI latency from %d to %d\n", |
1398 | KERN_INFO | ||
1399 | "%s: Changing PCI latency from %d to %d\n", | ||
1400 | ZR_DEVNAME(zr), latency, need_latency); | 1347 | ZR_DEVNAME(zr), latency, need_latency); |
1401 | pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER, | 1348 | pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER, |
1402 | need_latency); | 1349 | need_latency); |
@@ -1407,54 +1354,20 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1407 | dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n", | 1354 | dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n", |
1408 | ZR_DEVNAME(zr)); | 1355 | ZR_DEVNAME(zr)); |
1409 | 1356 | ||
1410 | /* i2c decoder */ | ||
1411 | if (decoder[zr->id] != -1) { | ||
1412 | i2c_dec_name = i2cid_to_modulename(decoder[zr->id]); | ||
1413 | zr->card.i2c_decoder = decoder[zr->id]; | ||
1414 | } else if (zr->card.i2c_decoder != 0) { | ||
1415 | i2c_dec_name = i2cid_to_modulename(zr->card.i2c_decoder); | ||
1416 | } else { | ||
1417 | i2c_dec_name = NULL; | ||
1418 | } | ||
1419 | |||
1420 | if (i2c_dec_name) { | ||
1421 | result = request_module(i2c_dec_name); | ||
1422 | if (result < 0) { | ||
1423 | dprintk(1, | ||
1424 | KERN_ERR | ||
1425 | "%s: failed to load module %s: %d\n", | ||
1426 | ZR_DEVNAME(zr), i2c_dec_name, result); | ||
1427 | } | ||
1428 | } | ||
1429 | |||
1430 | /* i2c encoder */ | ||
1431 | if (encoder[zr->id] != -1) { | ||
1432 | i2c_enc_name = i2cid_to_modulename(encoder[zr->id]); | ||
1433 | zr->card.i2c_encoder = encoder[zr->id]; | ||
1434 | } else if (zr->card.i2c_encoder != 0) { | ||
1435 | i2c_enc_name = i2cid_to_modulename(zr->card.i2c_encoder); | ||
1436 | } else { | ||
1437 | i2c_enc_name = NULL; | ||
1438 | } | ||
1439 | |||
1440 | if (i2c_enc_name) { | ||
1441 | result = request_module(i2c_enc_name); | ||
1442 | if (result < 0) { | ||
1443 | dprintk(1, | ||
1444 | KERN_ERR | ||
1445 | "%s: failed to load module %s: %d\n", | ||
1446 | ZR_DEVNAME(zr), i2c_enc_name, result); | ||
1447 | } | ||
1448 | } | ||
1449 | |||
1450 | if (zoran_register_i2c(zr) < 0) { | 1357 | if (zoran_register_i2c(zr) < 0) { |
1451 | dprintk(1, | 1358 | dprintk(1, KERN_ERR "%s: %s - can't initialize i2c bus\n", |
1452 | KERN_ERR | 1359 | ZR_DEVNAME(zr), __func__); |
1453 | "%s: find_zr36057() - can't initialize i2c bus\n", | ||
1454 | ZR_DEVNAME(zr)); | ||
1455 | goto zr_free_irq; | 1360 | goto zr_free_irq; |
1456 | } | 1361 | } |
1457 | 1362 | ||
1363 | zr->decoder = v4l2_i2c_new_probed_subdev(&zr->i2c_adapter, | ||
1364 | zr->card.mod_decoder, zr->card.i2c_decoder, zr->card.addrs_decoder); | ||
1365 | |||
1366 | if (zr->card.mod_encoder) | ||
1367 | zr->encoder = v4l2_i2c_new_probed_subdev(&zr->i2c_adapter, | ||
1368 | zr->card.mod_encoder, zr->card.i2c_encoder, | ||
1369 | zr->card.addrs_encoder); | ||
1370 | |||
1458 | dprintk(2, | 1371 | dprintk(2, |
1459 | KERN_INFO "%s: Initializing videocodec bus...\n", | 1372 | KERN_INFO "%s: Initializing videocodec bus...\n", |
1460 | ZR_DEVNAME(zr)); | 1373 | ZR_DEVNAME(zr)); |
@@ -1495,17 +1408,13 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1495 | goto zr_unreg_i2c; | 1408 | goto zr_unreg_i2c; |
1496 | zr->codec = videocodec_attach(master_codec); | 1409 | zr->codec = videocodec_attach(master_codec); |
1497 | if (!zr->codec) { | 1410 | if (!zr->codec) { |
1498 | dprintk(1, | 1411 | dprintk(1, KERN_ERR "%s: %s - no codec found\n", |
1499 | KERN_ERR | 1412 | ZR_DEVNAME(zr), __func__); |
1500 | "%s: find_zr36057() - no codec found\n", | ||
1501 | ZR_DEVNAME(zr)); | ||
1502 | goto zr_free_codec; | 1413 | goto zr_free_codec; |
1503 | } | 1414 | } |
1504 | if (zr->codec->type != zr->card.video_codec) { | 1415 | if (zr->codec->type != zr->card.video_codec) { |
1505 | dprintk(1, | 1416 | dprintk(1, KERN_ERR "%s: %s - wrong codec\n", |
1506 | KERN_ERR | 1417 | ZR_DEVNAME(zr), __func__); |
1507 | "%s: find_zr36057() - wrong codec\n", | ||
1508 | ZR_DEVNAME(zr)); | ||
1509 | goto zr_detach_codec; | 1418 | goto zr_detach_codec; |
1510 | } | 1419 | } |
1511 | } | 1420 | } |
@@ -1515,17 +1424,13 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1515 | goto zr_detach_codec; | 1424 | goto zr_detach_codec; |
1516 | zr->vfe = videocodec_attach(master_vfe); | 1425 | zr->vfe = videocodec_attach(master_vfe); |
1517 | if (!zr->vfe) { | 1426 | if (!zr->vfe) { |
1518 | dprintk(1, | 1427 | dprintk(1, KERN_ERR "%s: %s - no VFE found\n", |
1519 | KERN_ERR | 1428 | ZR_DEVNAME(zr), __func__); |
1520 | "%s: find_zr36057() - no VFE found\n", | ||
1521 | ZR_DEVNAME(zr)); | ||
1522 | goto zr_free_vfe; | 1429 | goto zr_free_vfe; |
1523 | } | 1430 | } |
1524 | if (zr->vfe->type != zr->card.video_vfe) { | 1431 | if (zr->vfe->type != zr->card.video_vfe) { |
1525 | dprintk(1, | 1432 | dprintk(1, KERN_ERR "%s: %s = wrong VFE\n", |
1526 | KERN_ERR | 1433 | ZR_DEVNAME(zr), __func__); |
1527 | "%s: find_zr36057() = wrong VFE\n", | ||
1528 | ZR_DEVNAME(zr)); | ||
1529 | goto zr_detach_vfe; | 1434 | goto zr_detach_vfe; |
1530 | } | 1435 | } |
1531 | } | 1436 | } |
@@ -1533,8 +1438,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1533 | /* take care of Natoma chipset and a revision 1 zr36057 */ | 1438 | /* take care of Natoma chipset and a revision 1 zr36057 */ |
1534 | if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { | 1439 | if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { |
1535 | zr->jpg_buffers.need_contiguous = 1; | 1440 | zr->jpg_buffers.need_contiguous = 1; |
1536 | dprintk(1, | 1441 | dprintk(1, KERN_INFO |
1537 | KERN_INFO | ||
1538 | "%s: ZR36057/Natoma bug, max. buffer size is 128K\n", | 1442 | "%s: ZR36057/Natoma bug, max. buffer size is 128K\n", |
1539 | ZR_DEVNAME(zr)); | 1443 | ZR_DEVNAME(zr)); |
1540 | } | 1444 | } |
@@ -1544,8 +1448,6 @@ static int __devinit zoran_probe(struct pci_dev *pdev, | |||
1544 | 1448 | ||
1545 | zoran_proc_init(zr); | 1449 | zoran_proc_init(zr); |
1546 | 1450 | ||
1547 | pci_set_drvdata(pdev, zr); | ||
1548 | |||
1549 | return 0; | 1451 | return 0; |
1550 | 1452 | ||
1551 | zr_detach_vfe: | 1453 | zr_detach_vfe: |
@@ -1563,6 +1465,8 @@ zr_free_irq: | |||
1563 | free_irq(zr->pci_dev->irq, zr); | 1465 | free_irq(zr->pci_dev->irq, zr); |
1564 | zr_unmap: | 1466 | zr_unmap: |
1565 | iounmap(zr->zr36057_mem); | 1467 | iounmap(zr->zr36057_mem); |
1468 | zr_unreg: | ||
1469 | v4l2_device_unregister(&zr->v4l2_dev); | ||
1566 | zr_free_mem: | 1470 | zr_free_mem: |
1567 | kfree(zr); | 1471 | kfree(zr); |
1568 | 1472 | ||
@@ -1613,9 +1517,6 @@ static int __init zoran_init(void) | |||
1613 | ZORAN_NAME, vidmem); | 1517 | ZORAN_NAME, vidmem); |
1614 | } | 1518 | } |
1615 | 1519 | ||
1616 | /* random nonsense */ | ||
1617 | dprintk(6, KERN_DEBUG "Jotti is een held!\n"); | ||
1618 | |||
1619 | /* some mainboards might not do PCI-PCI data transfer well */ | 1520 | /* some mainboards might not do PCI-PCI data transfer well */ |
1620 | if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) { | 1521 | if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) { |
1621 | dprintk(1, | 1522 | dprintk(1, |
diff --git a/drivers/media/video/zoran/zoran_card.h b/drivers/media/video/zoran/zoran_card.h index 4507bdc5e338..4936fead73e8 100644 --- a/drivers/media/video/zoran/zoran_card.h +++ b/drivers/media/video/zoran/zoran_card.h | |||
@@ -44,7 +44,8 @@ extern int zr36067_debug; | |||
44 | extern struct video_device zoran_template; | 44 | extern struct video_device zoran_template; |
45 | 45 | ||
46 | extern int zoran_check_jpg_settings(struct zoran *zr, | 46 | extern int zoran_check_jpg_settings(struct zoran *zr, |
47 | struct zoran_jpg_settings *settings); | 47 | struct zoran_jpg_settings *settings, |
48 | int try); | ||
48 | extern void zoran_open_init_params(struct zoran *zr); | 49 | extern void zoran_open_init_params(struct zoran *zr); |
49 | extern void zoran_vdev_release(struct video_device *vdev); | 50 | extern void zoran_vdev_release(struct video_device *vdev); |
50 | 51 | ||
diff --git a/drivers/media/video/zoran/zoran_device.c b/drivers/media/video/zoran/zoran_device.c index 5d948ff7faf0..e0223deed35e 100644 --- a/drivers/media/video/zoran/zoran_device.c +++ b/drivers/media/video/zoran/zoran_device.c | |||
@@ -36,13 +36,12 @@ | |||
36 | #include <linux/proc_fs.h> | 36 | #include <linux/proc_fs.h> |
37 | #include <linux/i2c.h> | 37 | #include <linux/i2c.h> |
38 | #include <linux/i2c-algo-bit.h> | 38 | #include <linux/i2c-algo-bit.h> |
39 | #include <linux/videodev.h> | 39 | #include <linux/videodev2.h> |
40 | #include <media/v4l2-common.h> | ||
40 | #include <linux/spinlock.h> | 41 | #include <linux/spinlock.h> |
41 | #include <linux/sem.h> | 42 | #include <linux/sem.h> |
42 | 43 | ||
43 | #include <linux/pci.h> | 44 | #include <linux/pci.h> |
44 | #include <linux/video_decoder.h> | ||
45 | #include <linux/video_encoder.h> | ||
46 | #include <linux/delay.h> | 45 | #include <linux/delay.h> |
47 | #include <linux/wait.h> | 46 | #include <linux/wait.h> |
48 | 47 | ||
@@ -312,9 +311,9 @@ zr36057_adjust_vfe (struct zoran *zr, | |||
312 | case BUZ_MODE_MOTION_COMPRESS: | 311 | case BUZ_MODE_MOTION_COMPRESS: |
313 | case BUZ_MODE_IDLE: | 312 | case BUZ_MODE_IDLE: |
314 | default: | 313 | default: |
315 | if (zr->norm == VIDEO_MODE_NTSC || | 314 | if ((zr->norm & V4L2_STD_NTSC) || |
316 | (zr->card.type == LML33R10 && | 315 | (zr->card.type == LML33R10 && |
317 | zr->norm == VIDEO_MODE_PAL)) | 316 | (zr->norm & V4L2_STD_PAL))) |
318 | btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR); | 317 | btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR); |
319 | else | 318 | else |
320 | btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR); | 319 | btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR); |
@@ -355,14 +354,6 @@ zr36057_set_vfe (struct zoran *zr, | |||
355 | dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n", | 354 | dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n", |
356 | ZR_DEVNAME(zr), video_width, video_height); | 355 | ZR_DEVNAME(zr), video_width, video_height); |
357 | 356 | ||
358 | if (zr->norm != VIDEO_MODE_PAL && | ||
359 | zr->norm != VIDEO_MODE_NTSC && | ||
360 | zr->norm != VIDEO_MODE_SECAM) { | ||
361 | dprintk(1, | ||
362 | KERN_ERR "%s: set_vfe() - norm = %d not valid\n", | ||
363 | ZR_DEVNAME(zr), zr->norm); | ||
364 | return; | ||
365 | } | ||
366 | if (video_width < BUZ_MIN_WIDTH || | 357 | if (video_width < BUZ_MIN_WIDTH || |
367 | video_height < BUZ_MIN_HEIGHT || | 358 | video_height < BUZ_MIN_HEIGHT || |
368 | video_width > Wa || video_height > Ha) { | 359 | video_width > Wa || video_height > Ha) { |
@@ -426,7 +417,7 @@ zr36057_set_vfe (struct zoran *zr, | |||
426 | * we get the correct colors when uncompressing to the screen */ | 417 | * we get the correct colors when uncompressing to the screen */ |
427 | //reg |= ZR36057_VFESPFR_VCLKPol; /**/ | 418 | //reg |= ZR36057_VFESPFR_VCLKPol; /**/ |
428 | /* RJ: Don't know if that is needed for NTSC also */ | 419 | /* RJ: Don't know if that is needed for NTSC also */ |
429 | if (zr->norm != VIDEO_MODE_NTSC) | 420 | if (!(zr->norm & V4L2_STD_NTSC)) |
430 | reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang | 421 | reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang |
431 | reg |= ZR36057_VFESPFR_TopField; | 422 | reg |= ZR36057_VFESPFR_TopField; |
432 | if (HorDcm >= 48) { | 423 | if (HorDcm >= 48) { |
@@ -497,11 +488,11 @@ zr36057_overlay (struct zoran *zr, | |||
497 | * All error messages are internal driver checking only! */ | 488 | * All error messages are internal driver checking only! */ |
498 | 489 | ||
499 | /* video display top and bottom registers */ | 490 | /* video display top and bottom registers */ |
500 | reg = (long) zr->buffer.base + | 491 | reg = (long) zr->vbuf_base + |
501 | zr->overlay_settings.x * | 492 | zr->overlay_settings.x * |
502 | ((zr->overlay_settings.format->depth + 7) / 8) + | 493 | ((zr->overlay_settings.format->depth + 7) / 8) + |
503 | zr->overlay_settings.y * | 494 | zr->overlay_settings.y * |
504 | zr->buffer.bytesperline; | 495 | zr->vbuf_bytesperline; |
505 | btwrite(reg, ZR36057_VDTR); | 496 | btwrite(reg, ZR36057_VDTR); |
506 | if (reg & 3) | 497 | if (reg & 3) |
507 | dprintk(1, | 498 | dprintk(1, |
@@ -509,15 +500,15 @@ zr36057_overlay (struct zoran *zr, | |||
509 | "%s: zr36057_overlay() - video_address not aligned\n", | 500 | "%s: zr36057_overlay() - video_address not aligned\n", |
510 | ZR_DEVNAME(zr)); | 501 | ZR_DEVNAME(zr)); |
511 | if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2) | 502 | if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2) |
512 | reg += zr->buffer.bytesperline; | 503 | reg += zr->vbuf_bytesperline; |
513 | btwrite(reg, ZR36057_VDBR); | 504 | btwrite(reg, ZR36057_VDBR); |
514 | 505 | ||
515 | /* video stride, status, and frame grab register */ | 506 | /* video stride, status, and frame grab register */ |
516 | reg = zr->buffer.bytesperline - | 507 | reg = zr->vbuf_bytesperline - |
517 | zr->overlay_settings.width * | 508 | zr->overlay_settings.width * |
518 | ((zr->overlay_settings.format->depth + 7) / 8); | 509 | ((zr->overlay_settings.format->depth + 7) / 8); |
519 | if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2) | 510 | if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2) |
520 | reg += zr->buffer.bytesperline; | 511 | reg += zr->vbuf_bytesperline; |
521 | if (reg & 3) | 512 | if (reg & 3) |
522 | dprintk(1, | 513 | dprintk(1, |
523 | KERN_ERR | 514 | KERN_ERR |
@@ -544,12 +535,8 @@ zr36057_overlay (struct zoran *zr, | |||
544 | * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels. | 535 | * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels. |
545 | */ | 536 | */ |
546 | 537 | ||
547 | void | 538 | void write_overlay_mask(struct zoran_fh *fh, struct v4l2_clip *vp, int count) |
548 | write_overlay_mask (struct file *file, | ||
549 | struct video_clip *vp, | ||
550 | int count) | ||
551 | { | 539 | { |
552 | struct zoran_fh *fh = file->private_data; | ||
553 | struct zoran *zr = fh->zr; | 540 | struct zoran *zr = fh->zr; |
554 | unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32; | 541 | unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32; |
555 | u32 *mask; | 542 | u32 *mask; |
@@ -563,10 +550,10 @@ write_overlay_mask (struct file *file, | |||
563 | 550 | ||
564 | for (i = 0; i < count; ++i) { | 551 | for (i = 0; i < count; ++i) { |
565 | /* pick up local copy of clip */ | 552 | /* pick up local copy of clip */ |
566 | x = vp[i].x; | 553 | x = vp[i].c.left; |
567 | y = vp[i].y; | 554 | y = vp[i].c.top; |
568 | width = vp[i].width; | 555 | width = vp[i].c.width; |
569 | height = vp[i].height; | 556 | height = vp[i].c.height; |
570 | 557 | ||
571 | /* trim clips that extend beyond the window */ | 558 | /* trim clips that extend beyond the window */ |
572 | if (x < 0) { | 559 | if (x < 0) { |
@@ -981,11 +968,10 @@ void | |||
981 | zr36057_enable_jpg (struct zoran *zr, | 968 | zr36057_enable_jpg (struct zoran *zr, |
982 | enum zoran_codec_mode mode) | 969 | enum zoran_codec_mode mode) |
983 | { | 970 | { |
984 | static int zero; | ||
985 | static int one = 1; | ||
986 | struct vfe_settings cap; | 971 | struct vfe_settings cap; |
987 | int field_size = | 972 | int field_size = |
988 | zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff; | 973 | zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff; |
974 | struct v4l2_routing route = { 0, 0 }; | ||
989 | 975 | ||
990 | zr->codec_mode = mode; | 976 | zr->codec_mode = mode; |
991 | 977 | ||
@@ -1007,8 +993,9 @@ zr36057_enable_jpg (struct zoran *zr, | |||
1007 | * the video bus direction set to input. | 993 | * the video bus direction set to input. |
1008 | */ | 994 | */ |
1009 | set_videobus_dir(zr, 0); | 995 | set_videobus_dir(zr, 0); |
1010 | decoder_command(zr, DECODER_ENABLE_OUTPUT, &one); | 996 | decoder_call(zr, video, s_stream, 1); |
1011 | encoder_command(zr, ENCODER_SET_INPUT, &zero); | 997 | route.input = 0; |
998 | encoder_call(zr, video, s_routing, &route); | ||
1012 | 999 | ||
1013 | /* Take the JPEG codec and the VFE out of sleep */ | 1000 | /* Take the JPEG codec and the VFE out of sleep */ |
1014 | jpeg_codec_sleep(zr, 0); | 1001 | jpeg_codec_sleep(zr, 0); |
@@ -1054,9 +1041,10 @@ zr36057_enable_jpg (struct zoran *zr, | |||
1054 | /* In motion decompression mode, the decoder output must be disabled, and | 1041 | /* In motion decompression mode, the decoder output must be disabled, and |
1055 | * the video bus direction set to output. | 1042 | * the video bus direction set to output. |
1056 | */ | 1043 | */ |
1057 | decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero); | 1044 | decoder_call(zr, video, s_stream, 0); |
1058 | set_videobus_dir(zr, 1); | 1045 | set_videobus_dir(zr, 1); |
1059 | encoder_command(zr, ENCODER_SET_INPUT, &one); | 1046 | route.input = 1; |
1047 | encoder_call(zr, video, s_routing, &route); | ||
1060 | 1048 | ||
1061 | /* Take the JPEG codec and the VFE out of sleep */ | 1049 | /* Take the JPEG codec and the VFE out of sleep */ |
1062 | jpeg_codec_sleep(zr, 0); | 1050 | jpeg_codec_sleep(zr, 0); |
@@ -1100,8 +1088,9 @@ zr36057_enable_jpg (struct zoran *zr, | |||
1100 | jpeg_codec_sleep(zr, 1); | 1088 | jpeg_codec_sleep(zr, 1); |
1101 | zr36057_adjust_vfe(zr, mode); | 1089 | zr36057_adjust_vfe(zr, mode); |
1102 | 1090 | ||
1103 | decoder_command(zr, DECODER_ENABLE_OUTPUT, &one); | 1091 | decoder_call(zr, video, s_stream, 1); |
1104 | encoder_command(zr, ENCODER_SET_INPUT, &zero); | 1092 | route.input = 0; |
1093 | encoder_call(zr, video, s_routing, &route); | ||
1105 | 1094 | ||
1106 | dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr)); | 1095 | dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr)); |
1107 | break; | 1096 | break; |
@@ -1132,7 +1121,7 @@ zoran_feed_stat_com (struct zoran *zr) | |||
1132 | if (!(zr->stat_com[i] & cpu_to_le32(1))) | 1121 | if (!(zr->stat_com[i] & cpu_to_le32(1))) |
1133 | break; | 1122 | break; |
1134 | zr->stat_com[i] = | 1123 | zr->stat_com[i] = |
1135 | cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); | 1124 | cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); |
1136 | } else { | 1125 | } else { |
1137 | /* fill 2 stat_com entries */ | 1126 | /* fill 2 stat_com entries */ |
1138 | i = ((zr->jpg_dma_head - | 1127 | i = ((zr->jpg_dma_head - |
@@ -1140,9 +1129,9 @@ zoran_feed_stat_com (struct zoran *zr) | |||
1140 | if (!(zr->stat_com[i] & cpu_to_le32(1))) | 1129 | if (!(zr->stat_com[i] & cpu_to_le32(1))) |
1141 | break; | 1130 | break; |
1142 | zr->stat_com[i] = | 1131 | zr->stat_com[i] = |
1143 | cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); | 1132 | cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); |
1144 | zr->stat_com[i + 1] = | 1133 | zr->stat_com[i + 1] = |
1145 | cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); | 1134 | cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); |
1146 | } | 1135 | } |
1147 | zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA; | 1136 | zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA; |
1148 | zr->jpg_dma_head++; | 1137 | zr->jpg_dma_head++; |
@@ -1162,7 +1151,7 @@ zoran_reap_stat_com (struct zoran *zr) | |||
1162 | u32 stat_com; | 1151 | u32 stat_com; |
1163 | unsigned int seq; | 1152 | unsigned int seq; |
1164 | unsigned int dif; | 1153 | unsigned int dif; |
1165 | struct zoran_jpg_buffer *buffer; | 1154 | struct zoran_buffer *buffer; |
1166 | int frame; | 1155 | int frame; |
1167 | 1156 | ||
1168 | /* In motion decompress we don't have a hardware frame counter, | 1157 | /* In motion decompress we don't have a hardware frame counter, |
@@ -1208,22 +1197,52 @@ zoran_reap_stat_com (struct zoran *zr) | |||
1208 | } | 1197 | } |
1209 | } | 1198 | } |
1210 | 1199 | ||
1200 | static void zoran_restart(struct zoran *zr) | ||
1201 | { | ||
1202 | /* Now the stat_comm buffer is ready for restart */ | ||
1203 | int status = 0, mode; | ||
1204 | |||
1205 | if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { | ||
1206 | decoder_call(zr, video, g_input_status, &status); | ||
1207 | mode = CODEC_DO_COMPRESSION; | ||
1208 | } else { | ||
1209 | status = V4L2_IN_ST_NO_SIGNAL; | ||
1210 | mode = CODEC_DO_EXPANSION; | ||
1211 | } | ||
1212 | if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS || | ||
1213 | !(status & V4L2_IN_ST_NO_SIGNAL)) { | ||
1214 | /********** RESTART code *************/ | ||
1215 | jpeg_codec_reset(zr); | ||
1216 | zr->codec->set_mode(zr->codec, mode); | ||
1217 | zr36057_set_jpg(zr, zr->codec_mode); | ||
1218 | jpeg_start(zr); | ||
1219 | |||
1220 | if (zr->num_errors <= 8) | ||
1221 | dprintk(2, KERN_INFO "%s: Restart\n", | ||
1222 | ZR_DEVNAME(zr)); | ||
1223 | |||
1224 | zr->JPEG_missed = 0; | ||
1225 | zr->JPEG_error = 2; | ||
1226 | /********** End RESTART code ***********/ | ||
1227 | } | ||
1228 | } | ||
1229 | |||
1211 | static void | 1230 | static void |
1212 | error_handler (struct zoran *zr, | 1231 | error_handler (struct zoran *zr, |
1213 | u32 astat, | 1232 | u32 astat, |
1214 | u32 stat) | 1233 | u32 stat) |
1215 | { | 1234 | { |
1235 | int i, j; | ||
1236 | |||
1216 | /* This is JPEG error handling part */ | 1237 | /* This is JPEG error handling part */ |
1217 | if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) && | 1238 | if (zr->codec_mode != BUZ_MODE_MOTION_COMPRESS && |
1218 | (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) { | 1239 | zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS) { |
1219 | //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode); | ||
1220 | return; | 1240 | return; |
1221 | } | 1241 | } |
1222 | 1242 | ||
1223 | if ((stat & 1) == 0 && | 1243 | if ((stat & 1) == 0 && |
1224 | zr->codec_mode == BUZ_MODE_MOTION_COMPRESS && | 1244 | zr->codec_mode == BUZ_MODE_MOTION_COMPRESS && |
1225 | zr->jpg_dma_tail - zr->jpg_que_tail >= | 1245 | zr->jpg_dma_tail - zr->jpg_que_tail >= zr->jpg_buffers.num_buffers) { |
1226 | zr->jpg_buffers.num_buffers) { | ||
1227 | /* No free buffers... */ | 1246 | /* No free buffers... */ |
1228 | zoran_reap_stat_com(zr); | 1247 | zoran_reap_stat_com(zr); |
1229 | zoran_feed_stat_com(zr); | 1248 | zoran_feed_stat_com(zr); |
@@ -1232,142 +1251,95 @@ error_handler (struct zoran *zr, | |||
1232 | return; | 1251 | return; |
1233 | } | 1252 | } |
1234 | 1253 | ||
1235 | if (zr->JPEG_error != 1) { | 1254 | if (zr->JPEG_error == 1) { |
1236 | /* | 1255 | zoran_restart(zr); |
1237 | * First entry: error just happened during normal operation | 1256 | return; |
1238 | * | 1257 | } |
1239 | * In BUZ_MODE_MOTION_COMPRESS: | ||
1240 | * | ||
1241 | * Possible glitch in TV signal. In this case we should | ||
1242 | * stop the codec and wait for good quality signal before | ||
1243 | * restarting it to avoid further problems | ||
1244 | * | ||
1245 | * In BUZ_MODE_MOTION_DECOMPRESS: | ||
1246 | * | ||
1247 | * Bad JPEG frame: we have to mark it as processed (codec crashed | ||
1248 | * and was not able to do it itself), and to remove it from queue. | ||
1249 | */ | ||
1250 | btand(~ZR36057_JMC_Go_en, ZR36057_JMC); | ||
1251 | udelay(1); | ||
1252 | stat = stat | (post_office_read(zr, 7, 0) & 3) << 8; | ||
1253 | btwrite(0, ZR36057_JPC); | ||
1254 | btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR); | ||
1255 | jpeg_codec_reset(zr); | ||
1256 | jpeg_codec_sleep(zr, 1); | ||
1257 | zr->JPEG_error = 1; | ||
1258 | zr->num_errors++; | ||
1259 | |||
1260 | /* Report error */ | ||
1261 | if (zr36067_debug > 1 && zr->num_errors <= 8) { | ||
1262 | long frame; | ||
1263 | frame = | ||
1264 | zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME]; | ||
1265 | printk(KERN_ERR | ||
1266 | "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ", | ||
1267 | ZR_DEVNAME(zr), stat, zr->last_isr, | ||
1268 | zr->jpg_que_tail, zr->jpg_dma_tail, | ||
1269 | zr->jpg_dma_head, zr->jpg_que_head, | ||
1270 | zr->jpg_seq_num, frame); | ||
1271 | printk("stat_com frames:"); | ||
1272 | { | ||
1273 | int i, j; | ||
1274 | for (j = 0; j < BUZ_NUM_STAT_COM; j++) { | ||
1275 | for (i = 0; | ||
1276 | i < zr->jpg_buffers.num_buffers; | ||
1277 | i++) { | ||
1278 | if (le32_to_cpu(zr->stat_com[j]) == | ||
1279 | zr->jpg_buffers. | ||
1280 | buffer[i]. | ||
1281 | frag_tab_bus) { | ||
1282 | printk("% d->%d", | ||
1283 | j, i); | ||
1284 | } | ||
1285 | } | ||
1286 | } | ||
1287 | printk("\n"); | ||
1288 | } | ||
1289 | } | ||
1290 | /* Find an entry in stat_com and rotate contents */ | ||
1291 | { | ||
1292 | int i; | ||
1293 | |||
1294 | if (zr->jpg_settings.TmpDcm == 1) | ||
1295 | i = (zr->jpg_dma_tail - | ||
1296 | zr->jpg_err_shift) & BUZ_MASK_STAT_COM; | ||
1297 | else | ||
1298 | i = ((zr->jpg_dma_tail - | ||
1299 | zr->jpg_err_shift) & 1) * 2; | ||
1300 | if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) { | ||
1301 | /* Mimic zr36067 operation */ | ||
1302 | zr->stat_com[i] |= cpu_to_le32(1); | ||
1303 | if (zr->jpg_settings.TmpDcm != 1) | ||
1304 | zr->stat_com[i + 1] |= cpu_to_le32(1); | ||
1305 | /* Refill */ | ||
1306 | zoran_reap_stat_com(zr); | ||
1307 | zoran_feed_stat_com(zr); | ||
1308 | wake_up_interruptible(&zr->jpg_capq); | ||
1309 | /* Find an entry in stat_com again after refill */ | ||
1310 | if (zr->jpg_settings.TmpDcm == 1) | ||
1311 | i = (zr->jpg_dma_tail - | ||
1312 | zr->jpg_err_shift) & | ||
1313 | BUZ_MASK_STAT_COM; | ||
1314 | else | ||
1315 | i = ((zr->jpg_dma_tail - | ||
1316 | zr->jpg_err_shift) & 1) * 2; | ||
1317 | } | ||
1318 | if (i) { | ||
1319 | /* Rotate stat_comm entries to make current entry first */ | ||
1320 | int j; | ||
1321 | __le32 bus_addr[BUZ_NUM_STAT_COM]; | ||
1322 | |||
1323 | /* Here we are copying the stat_com array, which | ||
1324 | * is already in little endian format, so | ||
1325 | * no endian conversions here | ||
1326 | */ | ||
1327 | memcpy(bus_addr, zr->stat_com, | ||
1328 | sizeof(bus_addr)); | ||
1329 | for (j = 0; j < BUZ_NUM_STAT_COM; j++) { | ||
1330 | zr->stat_com[j] = | ||
1331 | bus_addr[(i + j) & | ||
1332 | BUZ_MASK_STAT_COM]; | ||
1333 | 1258 | ||
1334 | } | 1259 | /* |
1335 | zr->jpg_err_shift += i; | 1260 | * First entry: error just happened during normal operation |
1336 | zr->jpg_err_shift &= BUZ_MASK_STAT_COM; | 1261 | * |
1262 | * In BUZ_MODE_MOTION_COMPRESS: | ||
1263 | * | ||
1264 | * Possible glitch in TV signal. In this case we should | ||
1265 | * stop the codec and wait for good quality signal before | ||
1266 | * restarting it to avoid further problems | ||
1267 | * | ||
1268 | * In BUZ_MODE_MOTION_DECOMPRESS: | ||
1269 | * | ||
1270 | * Bad JPEG frame: we have to mark it as processed (codec crashed | ||
1271 | * and was not able to do it itself), and to remove it from queue. | ||
1272 | */ | ||
1273 | btand(~ZR36057_JMC_Go_en, ZR36057_JMC); | ||
1274 | udelay(1); | ||
1275 | stat = stat | (post_office_read(zr, 7, 0) & 3) << 8; | ||
1276 | btwrite(0, ZR36057_JPC); | ||
1277 | btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR); | ||
1278 | jpeg_codec_reset(zr); | ||
1279 | jpeg_codec_sleep(zr, 1); | ||
1280 | zr->JPEG_error = 1; | ||
1281 | zr->num_errors++; | ||
1282 | |||
1283 | /* Report error */ | ||
1284 | if (zr36067_debug > 1 && zr->num_errors <= 8) { | ||
1285 | long frame; | ||
1286 | |||
1287 | frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME]; | ||
1288 | printk(KERN_ERR | ||
1289 | "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ", | ||
1290 | ZR_DEVNAME(zr), stat, zr->last_isr, | ||
1291 | zr->jpg_que_tail, zr->jpg_dma_tail, | ||
1292 | zr->jpg_dma_head, zr->jpg_que_head, | ||
1293 | zr->jpg_seq_num, frame); | ||
1294 | printk(KERN_INFO "stat_com frames:"); | ||
1295 | for (j = 0; j < BUZ_NUM_STAT_COM; j++) { | ||
1296 | for (i = 0; i < zr->jpg_buffers.num_buffers; i++) { | ||
1297 | if (le32_to_cpu(zr->stat_com[j]) == zr->jpg_buffers.buffer[i].jpg.frag_tab_bus) | ||
1298 | printk(KERN_CONT "% d->%d", j, i); | ||
1337 | } | 1299 | } |
1338 | if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) | ||
1339 | zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */ | ||
1340 | } | 1300 | } |
1301 | printk(KERN_CONT "\n"); | ||
1341 | } | 1302 | } |
1303 | /* Find an entry in stat_com and rotate contents */ | ||
1304 | if (zr->jpg_settings.TmpDcm == 1) | ||
1305 | i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM; | ||
1306 | else | ||
1307 | i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2; | ||
1308 | if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) { | ||
1309 | /* Mimic zr36067 operation */ | ||
1310 | zr->stat_com[i] |= cpu_to_le32(1); | ||
1311 | if (zr->jpg_settings.TmpDcm != 1) | ||
1312 | zr->stat_com[i + 1] |= cpu_to_le32(1); | ||
1313 | /* Refill */ | ||
1314 | zoran_reap_stat_com(zr); | ||
1315 | zoran_feed_stat_com(zr); | ||
1316 | wake_up_interruptible(&zr->jpg_capq); | ||
1317 | /* Find an entry in stat_com again after refill */ | ||
1318 | if (zr->jpg_settings.TmpDcm == 1) | ||
1319 | i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM; | ||
1320 | else | ||
1321 | i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2; | ||
1322 | } | ||
1323 | if (i) { | ||
1324 | /* Rotate stat_comm entries to make current entry first */ | ||
1325 | int j; | ||
1326 | __le32 bus_addr[BUZ_NUM_STAT_COM]; | ||
1327 | |||
1328 | /* Here we are copying the stat_com array, which | ||
1329 | * is already in little endian format, so | ||
1330 | * no endian conversions here | ||
1331 | */ | ||
1332 | memcpy(bus_addr, zr->stat_com, sizeof(bus_addr)); | ||
1342 | 1333 | ||
1343 | /* Now the stat_comm buffer is ready for restart */ | 1334 | for (j = 0; j < BUZ_NUM_STAT_COM; j++) |
1344 | do { | 1335 | zr->stat_com[j] = bus_addr[(i + j) & BUZ_MASK_STAT_COM]; |
1345 | int status, mode; | ||
1346 | |||
1347 | if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { | ||
1348 | decoder_command(zr, DECODER_GET_STATUS, &status); | ||
1349 | mode = CODEC_DO_COMPRESSION; | ||
1350 | } else { | ||
1351 | status = 0; | ||
1352 | mode = CODEC_DO_EXPANSION; | ||
1353 | } | ||
1354 | if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS || | ||
1355 | (status & DECODER_STATUS_GOOD)) { | ||
1356 | /********** RESTART code *************/ | ||
1357 | jpeg_codec_reset(zr); | ||
1358 | zr->codec->set_mode(zr->codec, mode); | ||
1359 | zr36057_set_jpg(zr, zr->codec_mode); | ||
1360 | jpeg_start(zr); | ||
1361 | |||
1362 | if (zr->num_errors <= 8) | ||
1363 | dprintk(2, KERN_INFO "%s: Restart\n", | ||
1364 | ZR_DEVNAME(zr)); | ||
1365 | 1336 | ||
1366 | zr->JPEG_missed = 0; | 1337 | zr->jpg_err_shift += i; |
1367 | zr->JPEG_error = 2; | 1338 | zr->jpg_err_shift &= BUZ_MASK_STAT_COM; |
1368 | /********** End RESTART code ***********/ | 1339 | } |
1369 | } | 1340 | if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) |
1370 | } while (0); | 1341 | zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */ |
1342 | zoran_restart(zr); | ||
1371 | } | 1343 | } |
1372 | 1344 | ||
1373 | irqreturn_t | 1345 | irqreturn_t |
@@ -1425,10 +1397,8 @@ zoran_irq (int irq, | |||
1425 | * We simply ignore them */ | 1397 | * We simply ignore them */ |
1426 | 1398 | ||
1427 | if (zr->v4l_memgrab_active) { | 1399 | if (zr->v4l_memgrab_active) { |
1428 | |||
1429 | /* A lot more checks should be here ... */ | 1400 | /* A lot more checks should be here ... */ |
1430 | if ((btread(ZR36057_VSSFGR) & | 1401 | if ((btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot) == 0) |
1431 | ZR36057_VSSFGR_SnapShot) == 0) | ||
1432 | dprintk(1, | 1402 | dprintk(1, |
1433 | KERN_WARNING | 1403 | KERN_WARNING |
1434 | "%s: BuzIRQ with SnapShot off ???\n", | 1404 | "%s: BuzIRQ with SnapShot off ???\n", |
@@ -1436,10 +1406,7 @@ zoran_irq (int irq, | |||
1436 | 1406 | ||
1437 | if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) { | 1407 | if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) { |
1438 | /* There is a grab on a frame going on, check if it has finished */ | 1408 | /* There is a grab on a frame going on, check if it has finished */ |
1439 | 1409 | if ((btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_FrameGrab) == 0) { | |
1440 | if ((btread(ZR36057_VSSFGR) & | ||
1441 | ZR36057_VSSFGR_FrameGrab) == | ||
1442 | 0) { | ||
1443 | /* it is finished, notify the user */ | 1410 | /* it is finished, notify the user */ |
1444 | 1411 | ||
1445 | zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE; | 1412 | zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE; |
@@ -1457,9 +1424,7 @@ zoran_irq (int irq, | |||
1457 | 1424 | ||
1458 | if (zr->v4l_grab_frame == NO_GRAB_ACTIVE && | 1425 | if (zr->v4l_grab_frame == NO_GRAB_ACTIVE && |
1459 | zr->v4l_pend_tail != zr->v4l_pend_head) { | 1426 | zr->v4l_pend_tail != zr->v4l_pend_head) { |
1460 | 1427 | int frame = zr->v4l_pend[zr->v4l_pend_tail & V4L_MASK_FRAME]; | |
1461 | int frame = zr->v4l_pend[zr->v4l_pend_tail & | ||
1462 | V4L_MASK_FRAME]; | ||
1463 | u32 reg; | 1428 | u32 reg; |
1464 | 1429 | ||
1465 | zr->v4l_grab_frame = frame; | 1430 | zr->v4l_grab_frame = frame; |
@@ -1468,27 +1433,17 @@ zoran_irq (int irq, | |||
1468 | 1433 | ||
1469 | /* Buffer address */ | 1434 | /* Buffer address */ |
1470 | 1435 | ||
1471 | reg = | 1436 | reg = zr->v4l_buffers.buffer[frame].v4l.fbuffer_bus; |
1472 | zr->v4l_buffers.buffer[frame]. | ||
1473 | fbuffer_bus; | ||
1474 | btwrite(reg, ZR36057_VDTR); | 1437 | btwrite(reg, ZR36057_VDTR); |
1475 | if (zr->v4l_settings.height > | 1438 | if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2) |
1476 | BUZ_MAX_HEIGHT / 2) | 1439 | reg += zr->v4l_settings.bytesperline; |
1477 | reg += | ||
1478 | zr->v4l_settings. | ||
1479 | bytesperline; | ||
1480 | btwrite(reg, ZR36057_VDBR); | 1440 | btwrite(reg, ZR36057_VDBR); |
1481 | 1441 | ||
1482 | /* video stride, status, and frame grab register */ | 1442 | /* video stride, status, and frame grab register */ |
1483 | reg = 0; | 1443 | reg = 0; |
1484 | if (zr->v4l_settings.height > | 1444 | if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2) |
1485 | BUZ_MAX_HEIGHT / 2) | 1445 | reg += zr->v4l_settings.bytesperline; |
1486 | reg += | 1446 | reg = (reg << ZR36057_VSSFGR_DispStride); |
1487 | zr->v4l_settings. | ||
1488 | bytesperline; | ||
1489 | reg = | ||
1490 | (reg << | ||
1491 | ZR36057_VSSFGR_DispStride); | ||
1492 | reg |= ZR36057_VSSFGR_VidOvf; | 1447 | reg |= ZR36057_VSSFGR_VidOvf; |
1493 | reg |= ZR36057_VSSFGR_SnapShot; | 1448 | reg |= ZR36057_VSSFGR_SnapShot; |
1494 | reg |= ZR36057_VSSFGR_FrameGrab; | 1449 | reg |= ZR36057_VSSFGR_FrameGrab; |
@@ -1506,77 +1461,66 @@ zoran_irq (int irq, | |||
1506 | #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ) | 1461 | #if (IRQ_MASK & ZR36057_ISR_CodRepIRQ) |
1507 | if (astat & ZR36057_ISR_CodRepIRQ) { | 1462 | if (astat & ZR36057_ISR_CodRepIRQ) { |
1508 | zr->intr_counter_CodRepIRQ++; | 1463 | zr->intr_counter_CodRepIRQ++; |
1509 | IDEBUG(printk | 1464 | IDEBUG(printk(KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n", |
1510 | (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n", | ||
1511 | ZR_DEVNAME(zr))); | 1465 | ZR_DEVNAME(zr))); |
1512 | btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR); | 1466 | btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR); |
1513 | } | 1467 | } |
1514 | #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */ | 1468 | #endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */ |
1515 | 1469 | ||
1516 | #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) | 1470 | #if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) |
1517 | if (astat & ZR36057_ISR_JPEGRepIRQ) { | 1471 | if ((astat & ZR36057_ISR_JPEGRepIRQ) && |
1518 | 1472 | (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS || | |
1519 | if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS || | 1473 | zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)) { |
1520 | zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { | 1474 | if (zr36067_debug > 1 && (!zr->frame_num || zr->JPEG_error)) { |
1521 | if (zr36067_debug > 1 && | 1475 | char sc[] = "0000"; |
1522 | (!zr->frame_num || zr->JPEG_error)) { | 1476 | char sv[5]; |
1523 | printk(KERN_INFO | 1477 | int i; |
1524 | "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n", | 1478 | |
1525 | ZR_DEVNAME(zr), stat, | 1479 | printk(KERN_INFO |
1526 | zr->jpg_settings.odd_even, | 1480 | "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n", |
1527 | zr->jpg_settings. | 1481 | ZR_DEVNAME(zr), stat, |
1528 | field_per_buff, | 1482 | zr->jpg_settings.odd_even, |
1529 | zr->JPEG_missed); | 1483 | zr->jpg_settings.field_per_buff, |
1530 | { | 1484 | zr->JPEG_missed); |
1531 | char sc[] = "0000"; | 1485 | |
1532 | char sv[5]; | 1486 | strcpy(sv, sc); |
1533 | int i; | 1487 | for (i = 0; i < 4; i++) { |
1534 | strcpy(sv, sc); | 1488 | if (le32_to_cpu(zr->stat_com[i]) & 1) |
1535 | for (i = 0; i < 4; i++) { | 1489 | sv[i] = '1'; |
1536 | if (le32_to_cpu(zr->stat_com[i]) & 1) | ||
1537 | sv[i] = '1'; | ||
1538 | } | ||
1539 | sv[4] = 0; | ||
1540 | printk(KERN_INFO | ||
1541 | "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n", | ||
1542 | ZR_DEVNAME(zr), sv, | ||
1543 | zr->jpg_que_tail, | ||
1544 | zr->jpg_dma_tail, | ||
1545 | zr->jpg_dma_head, | ||
1546 | zr->jpg_que_head); | ||
1547 | } | ||
1548 | } else { | ||
1549 | if (zr->JPEG_missed > zr->JPEG_max_missed) // Get statistics | ||
1550 | zr->JPEG_max_missed = | ||
1551 | zr->JPEG_missed; | ||
1552 | if (zr->JPEG_missed < | ||
1553 | zr->JPEG_min_missed) | ||
1554 | zr->JPEG_min_missed = | ||
1555 | zr->JPEG_missed; | ||
1556 | } | 1490 | } |
1491 | sv[4] = 0; | ||
1492 | printk(KERN_INFO | ||
1493 | "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n", | ||
1494 | ZR_DEVNAME(zr), sv, | ||
1495 | zr->jpg_que_tail, | ||
1496 | zr->jpg_dma_tail, | ||
1497 | zr->jpg_dma_head, | ||
1498 | zr->jpg_que_head); | ||
1499 | } else { | ||
1500 | /* Get statistics */ | ||
1501 | if (zr->JPEG_missed > zr->JPEG_max_missed) | ||
1502 | zr->JPEG_max_missed = zr->JPEG_missed; | ||
1503 | if (zr->JPEG_missed < zr->JPEG_min_missed) | ||
1504 | zr->JPEG_min_missed = zr->JPEG_missed; | ||
1505 | } | ||
1557 | 1506 | ||
1558 | if (zr36067_debug > 2 && zr->frame_num < 6) { | 1507 | if (zr36067_debug > 2 && zr->frame_num < 6) { |
1559 | int i; | 1508 | int i; |
1560 | printk("%s: seq=%ld stat_com:", | 1509 | |
1561 | ZR_DEVNAME(zr), zr->jpg_seq_num); | 1510 | printk(KERN_INFO "%s: seq=%ld stat_com:", |
1562 | for (i = 0; i < 4; i++) { | 1511 | ZR_DEVNAME(zr), zr->jpg_seq_num); |
1563 | printk(" %08x", | 1512 | for (i = 0; i < 4; i++) { |
1564 | le32_to_cpu(zr->stat_com[i])); | 1513 | printk(KERN_CONT " %08x", |
1565 | } | 1514 | le32_to_cpu(zr->stat_com[i])); |
1566 | printk("\n"); | ||
1567 | } | 1515 | } |
1568 | zr->frame_num++; | 1516 | printk(KERN_CONT "\n"); |
1569 | zr->JPEG_missed = 0; | 1517 | } |
1570 | zr->JPEG_error = 0; | 1518 | zr->frame_num++; |
1571 | zoran_reap_stat_com(zr); | 1519 | zr->JPEG_missed = 0; |
1572 | zoran_feed_stat_com(zr); | 1520 | zr->JPEG_error = 0; |
1573 | wake_up_interruptible(&zr->jpg_capq); | 1521 | zoran_reap_stat_com(zr); |
1574 | } /*else { | 1522 | zoran_feed_stat_com(zr); |
1575 | dprintk(1, | 1523 | wake_up_interruptible(&zr->jpg_capq); |
1576 | KERN_ERR | ||
1577 | "%s: JPEG interrupt while not in motion (de)compress mode!\n", | ||
1578 | ZR_DEVNAME(zr)); | ||
1579 | }*/ | ||
1580 | } | 1524 | } |
1581 | #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */ | 1525 | #endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */ |
1582 | 1526 | ||
@@ -1585,8 +1529,7 @@ zoran_irq (int irq, | |||
1585 | zr->JPEG_missed > 25 || | 1529 | zr->JPEG_missed > 25 || |
1586 | zr->JPEG_error == 1 || | 1530 | zr->JPEG_error == 1 || |
1587 | ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) && | 1531 | ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) && |
1588 | (zr->frame_num & (zr->JPEG_missed > | 1532 | (zr->frame_num & (zr->JPEG_missed > zr->jpg_settings.field_per_buff)))) { |
1589 | zr->jpg_settings.field_per_buff)))) { | ||
1590 | error_handler(zr, astat, stat); | 1533 | error_handler(zr, astat, stat); |
1591 | } | 1534 | } |
1592 | 1535 | ||
@@ -1628,7 +1571,7 @@ zoran_set_pci_master (struct zoran *zr, | |||
1628 | void | 1571 | void |
1629 | zoran_init_hardware (struct zoran *zr) | 1572 | zoran_init_hardware (struct zoran *zr) |
1630 | { | 1573 | { |
1631 | int j, zero = 0; | 1574 | struct v4l2_routing route = { 0, 0 }; |
1632 | 1575 | ||
1633 | /* Enable bus-mastering */ | 1576 | /* Enable bus-mastering */ |
1634 | zoran_set_pci_master(zr, 1); | 1577 | zoran_set_pci_master(zr, 1); |
@@ -1638,15 +1581,16 @@ zoran_init_hardware (struct zoran *zr) | |||
1638 | zr->card.init(zr); | 1581 | zr->card.init(zr); |
1639 | } | 1582 | } |
1640 | 1583 | ||
1641 | j = zr->card.input[zr->input].muxsel; | 1584 | route.input = zr->card.input[zr->input].muxsel; |
1642 | 1585 | ||
1643 | decoder_command(zr, 0, NULL); | 1586 | decoder_call(zr, core, init, 0); |
1644 | decoder_command(zr, DECODER_SET_NORM, &zr->norm); | 1587 | decoder_call(zr, tuner, s_std, zr->norm); |
1645 | decoder_command(zr, DECODER_SET_INPUT, &j); | 1588 | decoder_call(zr, video, s_routing, &route); |
1646 | 1589 | ||
1647 | encoder_command(zr, 0, NULL); | 1590 | encoder_call(zr, core, init, 0); |
1648 | encoder_command(zr, ENCODER_SET_NORM, &zr->norm); | 1591 | encoder_call(zr, video, s_std_output, zr->norm); |
1649 | encoder_command(zr, ENCODER_SET_INPUT, &zero); | 1592 | route.input = 0; |
1593 | encoder_call(zr, video, s_routing, &route); | ||
1650 | 1594 | ||
1651 | /* toggle JPEG codec sleep to sync PLL */ | 1595 | /* toggle JPEG codec sleep to sync PLL */ |
1652 | jpeg_codec_sleep(zr, 1); | 1596 | jpeg_codec_sleep(zr, 1); |
@@ -1706,42 +1650,3 @@ zr36057_init_vfe (struct zoran *zr) | |||
1706 | reg |= ZR36057_VDCR_Triton; | 1650 | reg |= ZR36057_VDCR_Triton; |
1707 | btwrite(reg, ZR36057_VDCR); | 1651 | btwrite(reg, ZR36057_VDCR); |
1708 | } | 1652 | } |
1709 | |||
1710 | /* | ||
1711 | * Interface to decoder and encoder chips using i2c bus | ||
1712 | */ | ||
1713 | |||
1714 | int | ||
1715 | decoder_command (struct zoran *zr, | ||
1716 | int cmd, | ||
1717 | void *data) | ||
1718 | { | ||
1719 | if (zr->decoder == NULL) | ||
1720 | return -EIO; | ||
1721 | |||
1722 | if (zr->card.type == LML33 && | ||
1723 | (cmd == DECODER_SET_NORM || cmd == DECODER_SET_INPUT)) { | ||
1724 | int res; | ||
1725 | |||
1726 | // Bt819 needs to reset its FIFO buffer using #FRST pin and | ||
1727 | // LML33 card uses GPIO(7) for that. | ||
1728 | GPIO(zr, 7, 0); | ||
1729 | res = zr->decoder->driver->command(zr->decoder, cmd, data); | ||
1730 | // Pull #FRST high. | ||
1731 | GPIO(zr, 7, 1); | ||
1732 | return res; | ||
1733 | } else | ||
1734 | return zr->decoder->driver->command(zr->decoder, cmd, | ||
1735 | data); | ||
1736 | } | ||
1737 | |||
1738 | int | ||
1739 | encoder_command (struct zoran *zr, | ||
1740 | int cmd, | ||
1741 | void *data) | ||
1742 | { | ||
1743 | if (zr->encoder == NULL) | ||
1744 | return -1; | ||
1745 | |||
1746 | return zr->encoder->driver->command(zr->encoder, cmd, data); | ||
1747 | } | ||
diff --git a/drivers/media/video/zoran/zoran_device.h b/drivers/media/video/zoran/zoran_device.h index 74c6c8edb7d0..07f2c23ff740 100644 --- a/drivers/media/video/zoran/zoran_device.h +++ b/drivers/media/video/zoran/zoran_device.h | |||
@@ -54,8 +54,8 @@ extern int jpeg_codec_reset(struct zoran *zr); | |||
54 | /* zr360x7 access to raw capture */ | 54 | /* zr360x7 access to raw capture */ |
55 | extern void zr36057_overlay(struct zoran *zr, | 55 | extern void zr36057_overlay(struct zoran *zr, |
56 | int on); | 56 | int on); |
57 | extern void write_overlay_mask(struct file *file, | 57 | extern void write_overlay_mask(struct zoran_fh *fh, |
58 | struct video_clip *vp, | 58 | struct v4l2_clip *vp, |
59 | int count); | 59 | int count); |
60 | extern void zr36057_set_memgrab(struct zoran *zr, | 60 | extern void zr36057_set_memgrab(struct zoran *zr, |
61 | int mode); | 61 | int mode); |
@@ -87,11 +87,9 @@ extern int jpg_bufsize; | |||
87 | extern int pass_through; | 87 | extern int pass_through; |
88 | 88 | ||
89 | /* i2c */ | 89 | /* i2c */ |
90 | extern int decoder_command(struct zoran *zr, | 90 | #define decoder_call(zr, o, f, args...) \ |
91 | int cmd, | 91 | v4l2_subdev_call(zr->decoder, o, f, ##args) |
92 | void *data); | 92 | #define encoder_call(zr, o, f, args...) \ |
93 | extern int encoder_command(struct zoran *zr, | 93 | v4l2_subdev_call(zr->encoder, o, f, ##args) |
94 | int cmd, | ||
95 | void *data); | ||
96 | 94 | ||
97 | #endif /* __ZORAN_DEVICE_H__ */ | 95 | #endif /* __ZORAN_DEVICE_H__ */ |
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c index 120ef235e63d..f16e57cf11e4 100644 --- a/drivers/media/video/zoran/zoran_driver.c +++ b/drivers/media/video/zoran/zoran_driver.c | |||
@@ -58,16 +58,6 @@ | |||
58 | #include <linux/i2c-algo-bit.h> | 58 | #include <linux/i2c-algo-bit.h> |
59 | 59 | ||
60 | #include <linux/spinlock.h> | 60 | #include <linux/spinlock.h> |
61 | #define MAP_NR(x) virt_to_page(x) | ||
62 | #define ZORAN_VID_TYPE ( \ | ||
63 | VID_TYPE_CAPTURE | \ | ||
64 | VID_TYPE_OVERLAY | \ | ||
65 | VID_TYPE_CLIPPING | \ | ||
66 | VID_TYPE_FRAMERAM | \ | ||
67 | VID_TYPE_SCALES | \ | ||
68 | VID_TYPE_MJPEG_DECODER | \ | ||
69 | VID_TYPE_MJPEG_ENCODER \ | ||
70 | ) | ||
71 | 61 | ||
72 | #include <linux/videodev.h> | 62 | #include <linux/videodev.h> |
73 | #include <media/v4l2-common.h> | 63 | #include <media/v4l2-common.h> |
@@ -79,36 +69,17 @@ | |||
79 | #include <asm/uaccess.h> | 69 | #include <asm/uaccess.h> |
80 | #include <linux/proc_fs.h> | 70 | #include <linux/proc_fs.h> |
81 | 71 | ||
82 | #include <linux/video_decoder.h> | ||
83 | #include <linux/video_encoder.h> | ||
84 | #include <linux/mutex.h> | 72 | #include <linux/mutex.h> |
85 | #include "zoran.h" | 73 | #include "zoran.h" |
86 | #include "zoran_device.h" | 74 | #include "zoran_device.h" |
87 | #include "zoran_card.h" | 75 | #include "zoran_card.h" |
88 | 76 | ||
89 | /* we declare some card type definitions here, they mean | ||
90 | * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */ | ||
91 | #define ZORAN_V4L2_VID_FLAGS ( \ | ||
92 | V4L2_CAP_STREAMING |\ | ||
93 | V4L2_CAP_VIDEO_CAPTURE |\ | ||
94 | V4L2_CAP_VIDEO_OUTPUT |\ | ||
95 | V4L2_CAP_VIDEO_OVERLAY \ | ||
96 | ) | ||
97 | |||
98 | |||
99 | #if defined(CONFIG_VIDEO_V4L1_COMPAT) | ||
100 | #define ZFMT(pal, fcc, cs) \ | ||
101 | .palette = (pal), .fourcc = (fcc), .colorspace = (cs) | ||
102 | #else | ||
103 | #define ZFMT(pal, fcc, cs) \ | ||
104 | .fourcc = (fcc), .colorspace = (cs) | ||
105 | #endif | ||
106 | 77 | ||
107 | const struct zoran_format zoran_formats[] = { | 78 | const struct zoran_format zoran_formats[] = { |
108 | { | 79 | { |
109 | .name = "15-bit RGB LE", | 80 | .name = "15-bit RGB LE", |
110 | ZFMT(VIDEO_PALETTE_RGB555, | 81 | .fourcc = V4L2_PIX_FMT_RGB555, |
111 | V4L2_PIX_FMT_RGB555, V4L2_COLORSPACE_SRGB), | 82 | .colorspace = V4L2_COLORSPACE_SRGB, |
112 | .depth = 15, | 83 | .depth = 15, |
113 | .flags = ZORAN_FORMAT_CAPTURE | | 84 | .flags = ZORAN_FORMAT_CAPTURE | |
114 | ZORAN_FORMAT_OVERLAY, | 85 | ZORAN_FORMAT_OVERLAY, |
@@ -116,16 +87,16 @@ const struct zoran_format zoran_formats[] = { | |||
116 | ZR36057_VFESPFR_LittleEndian, | 87 | ZR36057_VFESPFR_LittleEndian, |
117 | }, { | 88 | }, { |
118 | .name = "15-bit RGB BE", | 89 | .name = "15-bit RGB BE", |
119 | ZFMT(-1, | 90 | .fourcc = V4L2_PIX_FMT_RGB555X, |
120 | V4L2_PIX_FMT_RGB555X, V4L2_COLORSPACE_SRGB), | 91 | .colorspace = V4L2_COLORSPACE_SRGB, |
121 | .depth = 15, | 92 | .depth = 15, |
122 | .flags = ZORAN_FORMAT_CAPTURE | | 93 | .flags = ZORAN_FORMAT_CAPTURE | |
123 | ZORAN_FORMAT_OVERLAY, | 94 | ZORAN_FORMAT_OVERLAY, |
124 | .vfespfr = ZR36057_VFESPFR_RGB555|ZR36057_VFESPFR_ErrDif, | 95 | .vfespfr = ZR36057_VFESPFR_RGB555|ZR36057_VFESPFR_ErrDif, |
125 | }, { | 96 | }, { |
126 | .name = "16-bit RGB LE", | 97 | .name = "16-bit RGB LE", |
127 | ZFMT(VIDEO_PALETTE_RGB565, | 98 | .fourcc = V4L2_PIX_FMT_RGB565, |
128 | V4L2_PIX_FMT_RGB565, V4L2_COLORSPACE_SRGB), | 99 | .colorspace = V4L2_COLORSPACE_SRGB, |
129 | .depth = 16, | 100 | .depth = 16, |
130 | .flags = ZORAN_FORMAT_CAPTURE | | 101 | .flags = ZORAN_FORMAT_CAPTURE | |
131 | ZORAN_FORMAT_OVERLAY, | 102 | ZORAN_FORMAT_OVERLAY, |
@@ -133,56 +104,56 @@ const struct zoran_format zoran_formats[] = { | |||
133 | ZR36057_VFESPFR_LittleEndian, | 104 | ZR36057_VFESPFR_LittleEndian, |
134 | }, { | 105 | }, { |
135 | .name = "16-bit RGB BE", | 106 | .name = "16-bit RGB BE", |
136 | ZFMT(-1, | 107 | .fourcc = V4L2_PIX_FMT_RGB565X, |
137 | V4L2_PIX_FMT_RGB565X, V4L2_COLORSPACE_SRGB), | 108 | .colorspace = V4L2_COLORSPACE_SRGB, |
138 | .depth = 16, | 109 | .depth = 16, |
139 | .flags = ZORAN_FORMAT_CAPTURE | | 110 | .flags = ZORAN_FORMAT_CAPTURE | |
140 | ZORAN_FORMAT_OVERLAY, | 111 | ZORAN_FORMAT_OVERLAY, |
141 | .vfespfr = ZR36057_VFESPFR_RGB565|ZR36057_VFESPFR_ErrDif, | 112 | .vfespfr = ZR36057_VFESPFR_RGB565|ZR36057_VFESPFR_ErrDif, |
142 | }, { | 113 | }, { |
143 | .name = "24-bit RGB", | 114 | .name = "24-bit RGB", |
144 | ZFMT(VIDEO_PALETTE_RGB24, | 115 | .fourcc = V4L2_PIX_FMT_BGR24, |
145 | V4L2_PIX_FMT_BGR24, V4L2_COLORSPACE_SRGB), | 116 | .colorspace = V4L2_COLORSPACE_SRGB, |
146 | .depth = 24, | 117 | .depth = 24, |
147 | .flags = ZORAN_FORMAT_CAPTURE | | 118 | .flags = ZORAN_FORMAT_CAPTURE | |
148 | ZORAN_FORMAT_OVERLAY, | 119 | ZORAN_FORMAT_OVERLAY, |
149 | .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_Pack24, | 120 | .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_Pack24, |
150 | }, { | 121 | }, { |
151 | .name = "32-bit RGB LE", | 122 | .name = "32-bit RGB LE", |
152 | ZFMT(VIDEO_PALETTE_RGB32, | 123 | .fourcc = V4L2_PIX_FMT_BGR32, |
153 | V4L2_PIX_FMT_BGR32, V4L2_COLORSPACE_SRGB), | 124 | .colorspace = V4L2_COLORSPACE_SRGB, |
154 | .depth = 32, | 125 | .depth = 32, |
155 | .flags = ZORAN_FORMAT_CAPTURE | | 126 | .flags = ZORAN_FORMAT_CAPTURE | |
156 | ZORAN_FORMAT_OVERLAY, | 127 | ZORAN_FORMAT_OVERLAY, |
157 | .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_LittleEndian, | 128 | .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_LittleEndian, |
158 | }, { | 129 | }, { |
159 | .name = "32-bit RGB BE", | 130 | .name = "32-bit RGB BE", |
160 | ZFMT(-1, | 131 | .fourcc = V4L2_PIX_FMT_RGB32, |
161 | V4L2_PIX_FMT_RGB32, V4L2_COLORSPACE_SRGB), | 132 | .colorspace = V4L2_COLORSPACE_SRGB, |
162 | .depth = 32, | 133 | .depth = 32, |
163 | .flags = ZORAN_FORMAT_CAPTURE | | 134 | .flags = ZORAN_FORMAT_CAPTURE | |
164 | ZORAN_FORMAT_OVERLAY, | 135 | ZORAN_FORMAT_OVERLAY, |
165 | .vfespfr = ZR36057_VFESPFR_RGB888, | 136 | .vfespfr = ZR36057_VFESPFR_RGB888, |
166 | }, { | 137 | }, { |
167 | .name = "4:2:2, packed, YUYV", | 138 | .name = "4:2:2, packed, YUYV", |
168 | ZFMT(VIDEO_PALETTE_YUV422, | 139 | .fourcc = V4L2_PIX_FMT_YUYV, |
169 | V4L2_PIX_FMT_YUYV, V4L2_COLORSPACE_SMPTE170M), | 140 | .colorspace = V4L2_COLORSPACE_SMPTE170M, |
170 | .depth = 16, | 141 | .depth = 16, |
171 | .flags = ZORAN_FORMAT_CAPTURE | | 142 | .flags = ZORAN_FORMAT_CAPTURE | |
172 | ZORAN_FORMAT_OVERLAY, | 143 | ZORAN_FORMAT_OVERLAY, |
173 | .vfespfr = ZR36057_VFESPFR_YUV422, | 144 | .vfespfr = ZR36057_VFESPFR_YUV422, |
174 | }, { | 145 | }, { |
175 | .name = "4:2:2, packed, UYVY", | 146 | .name = "4:2:2, packed, UYVY", |
176 | ZFMT(VIDEO_PALETTE_UYVY, | 147 | .fourcc = V4L2_PIX_FMT_UYVY, |
177 | V4L2_PIX_FMT_UYVY, V4L2_COLORSPACE_SMPTE170M), | 148 | .colorspace = V4L2_COLORSPACE_SMPTE170M, |
178 | .depth = 16, | 149 | .depth = 16, |
179 | .flags = ZORAN_FORMAT_CAPTURE | | 150 | .flags = ZORAN_FORMAT_CAPTURE | |
180 | ZORAN_FORMAT_OVERLAY, | 151 | ZORAN_FORMAT_OVERLAY, |
181 | .vfespfr = ZR36057_VFESPFR_YUV422|ZR36057_VFESPFR_LittleEndian, | 152 | .vfespfr = ZR36057_VFESPFR_YUV422|ZR36057_VFESPFR_LittleEndian, |
182 | }, { | 153 | }, { |
183 | .name = "Hardware-encoded Motion-JPEG", | 154 | .name = "Hardware-encoded Motion-JPEG", |
184 | ZFMT(-1, | 155 | .fourcc = V4L2_PIX_FMT_MJPEG, |
185 | V4L2_PIX_FMT_MJPEG, V4L2_COLORSPACE_SMPTE170M), | 156 | .colorspace = V4L2_COLORSPACE_SMPTE170M, |
186 | .depth = 0, | 157 | .depth = 0, |
187 | .flags = ZORAN_FORMAT_CAPTURE | | 158 | .flags = ZORAN_FORMAT_CAPTURE | |
188 | ZORAN_FORMAT_PLAYBACK | | 159 | ZORAN_FORMAT_PLAYBACK | |
@@ -191,13 +162,6 @@ const struct zoran_format zoran_formats[] = { | |||
191 | }; | 162 | }; |
192 | #define NUM_FORMATS ARRAY_SIZE(zoran_formats) | 163 | #define NUM_FORMATS ARRAY_SIZE(zoran_formats) |
193 | 164 | ||
194 | // RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined | ||
195 | |||
196 | |||
197 | static int lock_norm; /* 0 = default 1 = Don't change TV standard (norm) */ | ||
198 | module_param(lock_norm, int, 0644); | ||
199 | MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)"); | ||
200 | |||
201 | /* small helper function for calculating buffersizes for v4l2 | 165 | /* small helper function for calculating buffersizes for v4l2 |
202 | * we calculate the nearest higher power-of-two, which | 166 | * we calculate the nearest higher power-of-two, which |
203 | * will be the recommended buffersize */ | 167 | * will be the recommended buffersize */ |
@@ -222,221 +186,106 @@ zoran_v4l2_calc_bufsize (struct zoran_jpg_settings *settings) | |||
222 | } | 186 | } |
223 | 187 | ||
224 | /* forward references */ | 188 | /* forward references */ |
225 | static void v4l_fbuffer_free(struct file *file); | 189 | static void v4l_fbuffer_free(struct zoran_fh *fh); |
226 | static void jpg_fbuffer_free(struct file *file); | 190 | static void jpg_fbuffer_free(struct zoran_fh *fh); |
191 | |||
192 | /* Set mapping mode */ | ||
193 | static void map_mode_raw(struct zoran_fh *fh) | ||
194 | { | ||
195 | fh->map_mode = ZORAN_MAP_MODE_RAW; | ||
196 | fh->buffers.buffer_size = v4l_bufsize; | ||
197 | fh->buffers.num_buffers = v4l_nbufs; | ||
198 | } | ||
199 | static void map_mode_jpg(struct zoran_fh *fh, int play) | ||
200 | { | ||
201 | fh->map_mode = play ? ZORAN_MAP_MODE_JPG_PLAY : ZORAN_MAP_MODE_JPG_REC; | ||
202 | fh->buffers.buffer_size = jpg_bufsize; | ||
203 | fh->buffers.num_buffers = jpg_nbufs; | ||
204 | } | ||
205 | static inline const char *mode_name(enum zoran_map_mode mode) | ||
206 | { | ||
207 | return mode == ZORAN_MAP_MODE_RAW ? "V4L" : "JPG"; | ||
208 | } | ||
227 | 209 | ||
228 | /* | 210 | /* |
229 | * Allocate the V4L grab buffers | 211 | * Allocate the V4L grab buffers |
230 | * | 212 | * |
231 | * These have to be pysically contiguous. | 213 | * These have to be pysically contiguous. |
232 | * If v4l_bufsize <= MAX_KMALLOC_MEM we use kmalloc | ||
233 | * else we try to allocate them with bigphysarea_alloc_pages | ||
234 | * if the bigphysarea patch is present in the kernel, | ||
235 | * else we try to use high memory (if the user has bootet | ||
236 | * Linux with the necessary memory left over). | ||
237 | */ | 214 | */ |
238 | 215 | ||
239 | static unsigned long | 216 | static int v4l_fbuffer_alloc(struct zoran_fh *fh) |
240 | get_high_mem (unsigned long size) | ||
241 | { | 217 | { |
242 | /* | ||
243 | * Check if there is usable memory at the end of Linux memory | ||
244 | * of at least size. Return the physical address of this memory, | ||
245 | * return 0 on failure. | ||
246 | * | ||
247 | * The idea is from Alexandro Rubini's book "Linux device drivers". | ||
248 | * The driver from him which is downloadable from O'Reilly's | ||
249 | * web site misses the "virt_to_phys(high_memory)" part | ||
250 | * (and therefore doesn't work at all - at least with 2.2.x kernels). | ||
251 | * | ||
252 | * It should be unnecessary to mention that THIS IS DANGEROUS, | ||
253 | * if more than one driver at a time has the idea to use this memory!!!! | ||
254 | */ | ||
255 | |||
256 | volatile unsigned char __iomem *mem; | ||
257 | unsigned char c; | ||
258 | unsigned long hi_mem_ph; | ||
259 | unsigned long i; | ||
260 | |||
261 | /* Map the high memory to user space */ | ||
262 | |||
263 | hi_mem_ph = virt_to_phys(high_memory); | ||
264 | |||
265 | mem = ioremap(hi_mem_ph, size); | ||
266 | if (!mem) { | ||
267 | dprintk(1, | ||
268 | KERN_ERR "%s: get_high_mem() - ioremap failed\n", | ||
269 | ZORAN_NAME); | ||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | for (i = 0; i < size; i++) { | ||
274 | /* Check if it is memory */ | ||
275 | c = i & 0xff; | ||
276 | writeb(c, mem + i); | ||
277 | if (readb(mem + i) != c) | ||
278 | break; | ||
279 | c = 255 - c; | ||
280 | writeb(c, mem + i); | ||
281 | if (readb(mem + i) != c) | ||
282 | break; | ||
283 | writeb(0, mem + i); /* zero out memory */ | ||
284 | |||
285 | /* give the kernel air to breath */ | ||
286 | if ((i & 0x3ffff) == 0x3ffff) | ||
287 | schedule(); | ||
288 | } | ||
289 | |||
290 | iounmap(mem); | ||
291 | |||
292 | if (i != size) { | ||
293 | dprintk(1, | ||
294 | KERN_ERR | ||
295 | "%s: get_high_mem() - requested %lu, avail %lu\n", | ||
296 | ZORAN_NAME, size, i); | ||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | return hi_mem_ph; | ||
301 | } | ||
302 | |||
303 | static int | ||
304 | v4l_fbuffer_alloc (struct file *file) | ||
305 | { | ||
306 | struct zoran_fh *fh = file->private_data; | ||
307 | struct zoran *zr = fh->zr; | 218 | struct zoran *zr = fh->zr; |
308 | int i, off; | 219 | int i, off; |
309 | unsigned char *mem; | 220 | unsigned char *mem; |
310 | unsigned long pmem = 0; | ||
311 | 221 | ||
312 | /* we might have old buffers lying around... */ | 222 | for (i = 0; i < fh->buffers.num_buffers; i++) { |
313 | if (fh->v4l_buffers.ready_to_be_freed) { | 223 | if (fh->buffers.buffer[i].v4l.fbuffer) |
314 | v4l_fbuffer_free(file); | ||
315 | } | ||
316 | |||
317 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { | ||
318 | if (fh->v4l_buffers.buffer[i].fbuffer) | ||
319 | dprintk(2, | 224 | dprintk(2, |
320 | KERN_WARNING | 225 | KERN_WARNING |
321 | "%s: v4l_fbuffer_alloc() - buffer %d allready allocated!?\n", | 226 | "%s: %s - buffer %d already allocated!?\n", |
322 | ZR_DEVNAME(zr), i); | 227 | ZR_DEVNAME(zr), __func__, i); |
323 | 228 | ||
324 | //udelay(20); | 229 | //udelay(20); |
325 | if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) { | 230 | mem = kmalloc(fh->buffers.buffer_size, |
326 | /* Use kmalloc */ | 231 | GFP_KERNEL | __GFP_NOWARN); |
327 | 232 | if (!mem) { | |
328 | mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL); | 233 | dprintk(1, |
329 | if (!mem) { | 234 | KERN_ERR |
330 | dprintk(1, | 235 | "%s: %s - kmalloc for V4L buf %d failed\n", |
331 | KERN_ERR | 236 | ZR_DEVNAME(zr), __func__, i); |
332 | "%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n", | 237 | v4l_fbuffer_free(fh); |
333 | ZR_DEVNAME(zr), i); | 238 | return -ENOBUFS; |
334 | v4l_fbuffer_free(file); | ||
335 | return -ENOBUFS; | ||
336 | } | ||
337 | fh->v4l_buffers.buffer[i].fbuffer = mem; | ||
338 | fh->v4l_buffers.buffer[i].fbuffer_phys = | ||
339 | virt_to_phys(mem); | ||
340 | fh->v4l_buffers.buffer[i].fbuffer_bus = | ||
341 | virt_to_bus(mem); | ||
342 | for (off = 0; off < fh->v4l_buffers.buffer_size; | ||
343 | off += PAGE_SIZE) | ||
344 | SetPageReserved(MAP_NR(mem + off)); | ||
345 | dprintk(4, | ||
346 | KERN_INFO | ||
347 | "%s: v4l_fbuffer_alloc() - V4L frame %d mem 0x%lx (bus: 0x%lx)\n", | ||
348 | ZR_DEVNAME(zr), i, (unsigned long) mem, | ||
349 | virt_to_bus(mem)); | ||
350 | } else { | ||
351 | |||
352 | /* Use high memory which has been left at boot time */ | ||
353 | |||
354 | /* Ok., Ok. this is an evil hack - we make | ||
355 | * the assumption that physical addresses are | ||
356 | * the same as bus addresses (true at least | ||
357 | * for Intel processors). The whole method of | ||
358 | * obtaining and using this memory is not very | ||
359 | * nice - but I hope it saves some poor users | ||
360 | * from kernel hacking, which might have even | ||
361 | * more evil results */ | ||
362 | |||
363 | if (i == 0) { | ||
364 | int size = | ||
365 | fh->v4l_buffers.num_buffers * | ||
366 | fh->v4l_buffers.buffer_size; | ||
367 | |||
368 | pmem = get_high_mem(size); | ||
369 | if (pmem == 0) { | ||
370 | dprintk(1, | ||
371 | KERN_ERR | ||
372 | "%s: v4l_fbuffer_alloc() - get_high_mem (size = %d KB) for V4L bufs failed\n", | ||
373 | ZR_DEVNAME(zr), size >> 10); | ||
374 | return -ENOBUFS; | ||
375 | } | ||
376 | fh->v4l_buffers.buffer[0].fbuffer = NULL; | ||
377 | fh->v4l_buffers.buffer[0].fbuffer_phys = pmem; | ||
378 | fh->v4l_buffers.buffer[0].fbuffer_bus = pmem; | ||
379 | dprintk(4, | ||
380 | KERN_INFO | ||
381 | "%s: v4l_fbuffer_alloc() - using %d KB high memory\n", | ||
382 | ZR_DEVNAME(zr), size >> 10); | ||
383 | } else { | ||
384 | fh->v4l_buffers.buffer[i].fbuffer = NULL; | ||
385 | fh->v4l_buffers.buffer[i].fbuffer_phys = | ||
386 | pmem + i * fh->v4l_buffers.buffer_size; | ||
387 | fh->v4l_buffers.buffer[i].fbuffer_bus = | ||
388 | pmem + i * fh->v4l_buffers.buffer_size; | ||
389 | } | ||
390 | } | 239 | } |
240 | fh->buffers.buffer[i].v4l.fbuffer = mem; | ||
241 | fh->buffers.buffer[i].v4l.fbuffer_phys = virt_to_phys(mem); | ||
242 | fh->buffers.buffer[i].v4l.fbuffer_bus = virt_to_bus(mem); | ||
243 | for (off = 0; off < fh->buffers.buffer_size; | ||
244 | off += PAGE_SIZE) | ||
245 | SetPageReserved(virt_to_page(mem + off)); | ||
246 | dprintk(4, | ||
247 | KERN_INFO | ||
248 | "%s: %s - V4L frame %d mem 0x%lx (bus: 0x%llx)\n", | ||
249 | ZR_DEVNAME(zr), __func__, i, (unsigned long) mem, | ||
250 | (unsigned long long)virt_to_bus(mem)); | ||
391 | } | 251 | } |
392 | 252 | ||
393 | fh->v4l_buffers.allocated = 1; | 253 | fh->buffers.allocated = 1; |
394 | 254 | ||
395 | return 0; | 255 | return 0; |
396 | } | 256 | } |
397 | 257 | ||
398 | /* free the V4L grab buffers */ | 258 | /* free the V4L grab buffers */ |
399 | static void | 259 | static void v4l_fbuffer_free(struct zoran_fh *fh) |
400 | v4l_fbuffer_free (struct file *file) | ||
401 | { | 260 | { |
402 | struct zoran_fh *fh = file->private_data; | ||
403 | struct zoran *zr = fh->zr; | 261 | struct zoran *zr = fh->zr; |
404 | int i, off; | 262 | int i, off; |
405 | unsigned char *mem; | 263 | unsigned char *mem; |
406 | 264 | ||
407 | dprintk(4, KERN_INFO "%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr)); | 265 | dprintk(4, KERN_INFO "%s: %s\n", ZR_DEVNAME(zr), __func__); |
408 | 266 | ||
409 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { | 267 | for (i = 0; i < fh->buffers.num_buffers; i++) { |
410 | if (!fh->v4l_buffers.buffer[i].fbuffer) | 268 | if (!fh->buffers.buffer[i].v4l.fbuffer) |
411 | continue; | 269 | continue; |
412 | 270 | ||
413 | if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) { | 271 | mem = fh->buffers.buffer[i].v4l.fbuffer; |
414 | mem = fh->v4l_buffers.buffer[i].fbuffer; | 272 | for (off = 0; off < fh->buffers.buffer_size; |
415 | for (off = 0; off < fh->v4l_buffers.buffer_size; | 273 | off += PAGE_SIZE) |
416 | off += PAGE_SIZE) | 274 | ClearPageReserved(virt_to_page(mem + off)); |
417 | ClearPageReserved(MAP_NR(mem + off)); | 275 | kfree(fh->buffers.buffer[i].v4l.fbuffer); |
418 | kfree((void *) fh->v4l_buffers.buffer[i].fbuffer); | 276 | fh->buffers.buffer[i].v4l.fbuffer = NULL; |
419 | } | ||
420 | fh->v4l_buffers.buffer[i].fbuffer = NULL; | ||
421 | } | 277 | } |
422 | 278 | ||
423 | fh->v4l_buffers.allocated = 0; | 279 | fh->buffers.allocated = 0; |
424 | fh->v4l_buffers.ready_to_be_freed = 0; | ||
425 | } | 280 | } |
426 | 281 | ||
427 | /* | 282 | /* |
428 | * Allocate the MJPEG grab buffers. | 283 | * Allocate the MJPEG grab buffers. |
429 | * | 284 | * |
430 | * If the requested buffer size is smaller than MAX_KMALLOC_MEM, | ||
431 | * kmalloc is used to request a physically contiguous area, | ||
432 | * else we allocate the memory in framgents with get_zeroed_page. | ||
433 | * | ||
434 | * If a Natoma chipset is present and this is a revision 1 zr36057, | 285 | * If a Natoma chipset is present and this is a revision 1 zr36057, |
435 | * each MJPEG buffer needs to be physically contiguous. | 286 | * each MJPEG buffer needs to be physically contiguous. |
436 | * (RJ: This statement is from Dave Perks' original driver, | 287 | * (RJ: This statement is from Dave Perks' original driver, |
437 | * I could never check it because I have a zr36067) | 288 | * I could never check it because I have a zr36067) |
438 | * The driver cares about this because it reduces the buffer | ||
439 | * size to MAX_KMALLOC_MEM in that case (which forces contiguous allocation). | ||
440 | * | 289 | * |
441 | * RJ: The contents grab buffers needs never be accessed in the driver. | 290 | * RJ: The contents grab buffers needs never be accessed in the driver. |
442 | * Therefore there is no need to allocate them with vmalloc in order | 291 | * Therefore there is no need to allocate them with vmalloc in order |
@@ -458,162 +307,128 @@ v4l_fbuffer_free (struct file *file) | |||
458 | * and fragment buffers are not little-endian. | 307 | * and fragment buffers are not little-endian. |
459 | */ | 308 | */ |
460 | 309 | ||
461 | static int | 310 | static int jpg_fbuffer_alloc(struct zoran_fh *fh) |
462 | jpg_fbuffer_alloc (struct file *file) | ||
463 | { | 311 | { |
464 | struct zoran_fh *fh = file->private_data; | ||
465 | struct zoran *zr = fh->zr; | 312 | struct zoran *zr = fh->zr; |
466 | int i, j, off; | 313 | int i, j, off; |
467 | unsigned long mem; | 314 | u8 *mem; |
468 | |||
469 | /* we might have old buffers lying around */ | ||
470 | if (fh->jpg_buffers.ready_to_be_freed) { | ||
471 | jpg_fbuffer_free(file); | ||
472 | } | ||
473 | 315 | ||
474 | for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { | 316 | for (i = 0; i < fh->buffers.num_buffers; i++) { |
475 | if (fh->jpg_buffers.buffer[i].frag_tab) | 317 | if (fh->buffers.buffer[i].jpg.frag_tab) |
476 | dprintk(2, | 318 | dprintk(2, |
477 | KERN_WARNING | 319 | KERN_WARNING |
478 | "%s: jpg_fbuffer_alloc() - buffer %d allready allocated!?\n", | 320 | "%s: %s - buffer %d already allocated!?\n", |
479 | ZR_DEVNAME(zr), i); | 321 | ZR_DEVNAME(zr), __func__, i); |
480 | 322 | ||
481 | /* Allocate fragment table for this buffer */ | 323 | /* Allocate fragment table for this buffer */ |
482 | 324 | ||
483 | mem = get_zeroed_page(GFP_KERNEL); | 325 | mem = (void *)get_zeroed_page(GFP_KERNEL); |
484 | if (mem == 0) { | 326 | if (mem == 0) { |
485 | dprintk(1, | 327 | dprintk(1, |
486 | KERN_ERR | 328 | KERN_ERR |
487 | "%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n", | 329 | "%s: %s - get_zeroed_page (frag_tab) failed for buffer %d\n", |
488 | ZR_DEVNAME(zr), i); | 330 | ZR_DEVNAME(zr), __func__, i); |
489 | jpg_fbuffer_free(file); | 331 | jpg_fbuffer_free(fh); |
490 | return -ENOBUFS; | 332 | return -ENOBUFS; |
491 | } | 333 | } |
492 | fh->jpg_buffers.buffer[i].frag_tab = (__le32 *) mem; | 334 | fh->buffers.buffer[i].jpg.frag_tab = (__le32 *)mem; |
493 | fh->jpg_buffers.buffer[i].frag_tab_bus = | 335 | fh->buffers.buffer[i].jpg.frag_tab_bus = virt_to_bus(mem); |
494 | virt_to_bus((void *) mem); | 336 | |
495 | 337 | if (fh->buffers.need_contiguous) { | |
496 | //if (alloc_contig) { | 338 | mem = kmalloc(fh->buffers.buffer_size, GFP_KERNEL); |
497 | if (fh->jpg_buffers.need_contiguous) { | 339 | if (mem == NULL) { |
498 | mem = | ||
499 | (unsigned long) kmalloc(fh->jpg_buffers. | ||
500 | buffer_size, | ||
501 | GFP_KERNEL); | ||
502 | if (mem == 0) { | ||
503 | dprintk(1, | 340 | dprintk(1, |
504 | KERN_ERR | 341 | KERN_ERR |
505 | "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n", | 342 | "%s: %s - kmalloc failed for buffer %d\n", |
506 | ZR_DEVNAME(zr), i); | 343 | ZR_DEVNAME(zr), __func__, i); |
507 | jpg_fbuffer_free(file); | 344 | jpg_fbuffer_free(fh); |
508 | return -ENOBUFS; | 345 | return -ENOBUFS; |
509 | } | 346 | } |
510 | fh->jpg_buffers.buffer[i].frag_tab[0] = | 347 | fh->buffers.buffer[i].jpg.frag_tab[0] = |
511 | cpu_to_le32(virt_to_bus((void *) mem)); | 348 | cpu_to_le32(virt_to_bus(mem)); |
512 | fh->jpg_buffers.buffer[i].frag_tab[1] = | 349 | fh->buffers.buffer[i].jpg.frag_tab[1] = |
513 | cpu_to_le32(((fh->jpg_buffers.buffer_size / 4) << 1) | 1); | 350 | cpu_to_le32((fh->buffers.buffer_size >> 1) | 1); |
514 | for (off = 0; off < fh->jpg_buffers.buffer_size; | 351 | for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE) |
515 | off += PAGE_SIZE) | 352 | SetPageReserved(virt_to_page(mem + off)); |
516 | SetPageReserved(MAP_NR(mem + off)); | ||
517 | } else { | 353 | } else { |
518 | /* jpg_bufsize is allreay page aligned */ | 354 | /* jpg_bufsize is already page aligned */ |
519 | for (j = 0; | 355 | for (j = 0; j < fh->buffers.buffer_size / PAGE_SIZE; j++) { |
520 | j < fh->jpg_buffers.buffer_size / PAGE_SIZE; | 356 | mem = (void *)get_zeroed_page(GFP_KERNEL); |
521 | j++) { | 357 | if (mem == NULL) { |
522 | mem = get_zeroed_page(GFP_KERNEL); | ||
523 | if (mem == 0) { | ||
524 | dprintk(1, | 358 | dprintk(1, |
525 | KERN_ERR | 359 | KERN_ERR |
526 | "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n", | 360 | "%s: %s - get_zeroed_page failed for buffer %d\n", |
527 | ZR_DEVNAME(zr), i); | 361 | ZR_DEVNAME(zr), __func__, i); |
528 | jpg_fbuffer_free(file); | 362 | jpg_fbuffer_free(fh); |
529 | return -ENOBUFS; | 363 | return -ENOBUFS; |
530 | } | 364 | } |
531 | 365 | ||
532 | fh->jpg_buffers.buffer[i].frag_tab[2 * j] = | 366 | fh->buffers.buffer[i].jpg.frag_tab[2 * j] = |
533 | cpu_to_le32(virt_to_bus((void *) mem)); | 367 | cpu_to_le32(virt_to_bus(mem)); |
534 | fh->jpg_buffers.buffer[i].frag_tab[2 * j + | 368 | fh->buffers.buffer[i].jpg.frag_tab[2 * j + 1] = |
535 | 1] = | 369 | cpu_to_le32((PAGE_SIZE >> 2) << 1); |
536 | cpu_to_le32((PAGE_SIZE / 4) << 1); | 370 | SetPageReserved(virt_to_page(mem)); |
537 | SetPageReserved(MAP_NR(mem)); | ||
538 | } | 371 | } |
539 | 372 | ||
540 | fh->jpg_buffers.buffer[i].frag_tab[2 * j - 1] |= cpu_to_le32(1); | 373 | fh->buffers.buffer[i].jpg.frag_tab[2 * j - 1] |= cpu_to_le32(1); |
541 | } | 374 | } |
542 | } | 375 | } |
543 | 376 | ||
544 | dprintk(4, | 377 | dprintk(4, |
545 | KERN_DEBUG "%s: jpg_fbuffer_alloc() - %d KB allocated\n", | 378 | KERN_DEBUG "%s: %s - %d KB allocated\n", |
546 | ZR_DEVNAME(zr), | 379 | ZR_DEVNAME(zr), __func__, |
547 | (fh->jpg_buffers.num_buffers * | 380 | (fh->buffers.num_buffers * fh->buffers.buffer_size) >> 10); |
548 | fh->jpg_buffers.buffer_size) >> 10); | ||
549 | 381 | ||
550 | fh->jpg_buffers.allocated = 1; | 382 | fh->buffers.allocated = 1; |
551 | 383 | ||
552 | return 0; | 384 | return 0; |
553 | } | 385 | } |
554 | 386 | ||
555 | /* free the MJPEG grab buffers */ | 387 | /* free the MJPEG grab buffers */ |
556 | static void | 388 | static void jpg_fbuffer_free(struct zoran_fh *fh) |
557 | jpg_fbuffer_free (struct file *file) | ||
558 | { | 389 | { |
559 | struct zoran_fh *fh = file->private_data; | ||
560 | struct zoran *zr = fh->zr; | 390 | struct zoran *zr = fh->zr; |
561 | int i, j, off; | 391 | int i, j, off; |
562 | unsigned char *mem; | 392 | unsigned char *mem; |
393 | __le32 frag_tab; | ||
394 | struct zoran_buffer *buffer; | ||
563 | 395 | ||
564 | dprintk(4, KERN_DEBUG "%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr)); | 396 | dprintk(4, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); |
565 | 397 | ||
566 | for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { | 398 | for (i = 0, buffer = &fh->buffers.buffer[0]; |
567 | if (!fh->jpg_buffers.buffer[i].frag_tab) | 399 | i < fh->buffers.num_buffers; i++, buffer++) { |
400 | if (!buffer->jpg.frag_tab) | ||
568 | continue; | 401 | continue; |
569 | 402 | ||
570 | //if (alloc_contig) { | 403 | if (fh->buffers.need_contiguous) { |
571 | if (fh->jpg_buffers.need_contiguous) { | 404 | frag_tab = buffer->jpg.frag_tab[0]; |
572 | if (fh->jpg_buffers.buffer[i].frag_tab[0]) { | 405 | |
573 | mem = (unsigned char *) bus_to_virt(le32_to_cpu( | 406 | if (frag_tab) { |
574 | fh->jpg_buffers.buffer[i].frag_tab[0])); | 407 | mem = bus_to_virt(le32_to_cpu(frag_tab)); |
575 | for (off = 0; | 408 | for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE) |
576 | off < fh->jpg_buffers.buffer_size; | 409 | ClearPageReserved(virt_to_page(mem + off)); |
577 | off += PAGE_SIZE) | ||
578 | ClearPageReserved(MAP_NR | ||
579 | (mem + off)); | ||
580 | kfree(mem); | 410 | kfree(mem); |
581 | fh->jpg_buffers.buffer[i].frag_tab[0] = 0; | 411 | buffer->jpg.frag_tab[0] = 0; |
582 | fh->jpg_buffers.buffer[i].frag_tab[1] = 0; | 412 | buffer->jpg.frag_tab[1] = 0; |
583 | } | 413 | } |
584 | } else { | 414 | } else { |
585 | for (j = 0; | 415 | for (j = 0; j < fh->buffers.buffer_size / PAGE_SIZE; j++) { |
586 | j < fh->jpg_buffers.buffer_size / PAGE_SIZE; | 416 | frag_tab = buffer->jpg.frag_tab[2 * j]; |
587 | j++) { | 417 | |
588 | if (!fh->jpg_buffers.buffer[i]. | 418 | if (!frag_tab) |
589 | frag_tab[2 * j]) | ||
590 | break; | 419 | break; |
591 | ClearPageReserved(MAP_NR | 420 | ClearPageReserved(virt_to_page(bus_to_virt(le32_to_cpu(frag_tab)))); |
592 | (bus_to_virt | 421 | free_page((unsigned long)bus_to_virt(le32_to_cpu(frag_tab))); |
593 | (le32_to_cpu | 422 | buffer->jpg.frag_tab[2 * j] = 0; |
594 | (fh->jpg_buffers. | 423 | buffer->jpg.frag_tab[2 * j + 1] = 0; |
595 | buffer[i].frag_tab[2 * | ||
596 | j])))); | ||
597 | free_page((unsigned long) | ||
598 | bus_to_virt | ||
599 | (le32_to_cpu | ||
600 | (fh->jpg_buffers. | ||
601 | buffer[i]. | ||
602 | frag_tab[2 * j]))); | ||
603 | fh->jpg_buffers.buffer[i].frag_tab[2 * j] = | ||
604 | 0; | ||
605 | fh->jpg_buffers.buffer[i].frag_tab[2 * j + | ||
606 | 1] = 0; | ||
607 | } | 424 | } |
608 | } | 425 | } |
609 | 426 | ||
610 | free_page((unsigned long) fh->jpg_buffers.buffer[i]. | 427 | free_page((unsigned long)buffer->jpg.frag_tab); |
611 | frag_tab); | 428 | buffer->jpg.frag_tab = NULL; |
612 | fh->jpg_buffers.buffer[i].frag_tab = NULL; | ||
613 | } | 429 | } |
614 | 430 | ||
615 | fh->jpg_buffers.allocated = 0; | 431 | fh->buffers.allocated = 0; |
616 | fh->jpg_buffers.ready_to_be_freed = 0; | ||
617 | } | 432 | } |
618 | 433 | ||
619 | /* | 434 | /* |
@@ -621,12 +436,11 @@ jpg_fbuffer_free (struct file *file) | |||
621 | */ | 436 | */ |
622 | 437 | ||
623 | static int | 438 | static int |
624 | zoran_v4l_set_format (struct file *file, | 439 | zoran_v4l_set_format (struct zoran_fh *fh, |
625 | int width, | 440 | int width, |
626 | int height, | 441 | int height, |
627 | const struct zoran_format *format) | 442 | const struct zoran_format *format) |
628 | { | 443 | { |
629 | struct zoran_fh *fh = file->private_data; | ||
630 | struct zoran *zr = fh->zr; | 444 | struct zoran *zr = fh->zr; |
631 | int bpp; | 445 | int bpp; |
632 | 446 | ||
@@ -636,19 +450,19 @@ zoran_v4l_set_format (struct file *file, | |||
636 | height > BUZ_MAX_HEIGHT || width > BUZ_MAX_WIDTH) { | 450 | height > BUZ_MAX_HEIGHT || width > BUZ_MAX_WIDTH) { |
637 | dprintk(1, | 451 | dprintk(1, |
638 | KERN_ERR | 452 | KERN_ERR |
639 | "%s: v4l_set_format() - wrong frame size (%dx%d)\n", | 453 | "%s: %s - wrong frame size (%dx%d)\n", |
640 | ZR_DEVNAME(zr), width, height); | 454 | ZR_DEVNAME(zr), __func__, width, height); |
641 | return -EINVAL; | 455 | return -EINVAL; |
642 | } | 456 | } |
643 | 457 | ||
644 | bpp = (format->depth + 7) / 8; | 458 | bpp = (format->depth + 7) / 8; |
645 | 459 | ||
646 | /* Check against available buffer size */ | 460 | /* Check against available buffer size */ |
647 | if (height * width * bpp > fh->v4l_buffers.buffer_size) { | 461 | if (height * width * bpp > fh->buffers.buffer_size) { |
648 | dprintk(1, | 462 | dprintk(1, |
649 | KERN_ERR | 463 | KERN_ERR |
650 | "%s: v4l_set_format() - video buffer size (%d kB) is too small\n", | 464 | "%s: %s - video buffer size (%d kB) is too small\n", |
651 | ZR_DEVNAME(zr), fh->v4l_buffers.buffer_size >> 10); | 465 | ZR_DEVNAME(zr), __func__, fh->buffers.buffer_size >> 10); |
652 | return -EINVAL; | 466 | return -EINVAL; |
653 | } | 467 | } |
654 | 468 | ||
@@ -657,8 +471,8 @@ zoran_v4l_set_format (struct file *file, | |||
657 | if ((bpp == 2 && (width & 1)) || (bpp == 3 && (width & 3))) { | 471 | if ((bpp == 2 && (width & 1)) || (bpp == 3 && (width & 3))) { |
658 | dprintk(1, | 472 | dprintk(1, |
659 | KERN_ERR | 473 | KERN_ERR |
660 | "%s: v4l_set_format() - wrong frame alingment\n", | 474 | "%s: %s - wrong frame alignment\n", |
661 | ZR_DEVNAME(zr)); | 475 | ZR_DEVNAME(zr), __func__); |
662 | return -EINVAL; | 476 | return -EINVAL; |
663 | } | 477 | } |
664 | 478 | ||
@@ -670,43 +484,40 @@ zoran_v4l_set_format (struct file *file, | |||
670 | return 0; | 484 | return 0; |
671 | } | 485 | } |
672 | 486 | ||
673 | static int | 487 | static int zoran_v4l_queue_frame(struct zoran_fh *fh, int num) |
674 | zoran_v4l_queue_frame (struct file *file, | ||
675 | int num) | ||
676 | { | 488 | { |
677 | struct zoran_fh *fh = file->private_data; | ||
678 | struct zoran *zr = fh->zr; | 489 | struct zoran *zr = fh->zr; |
679 | unsigned long flags; | 490 | unsigned long flags; |
680 | int res = 0; | 491 | int res = 0; |
681 | 492 | ||
682 | if (!fh->v4l_buffers.allocated) { | 493 | if (!fh->buffers.allocated) { |
683 | dprintk(1, | 494 | dprintk(1, |
684 | KERN_ERR | 495 | KERN_ERR |
685 | "%s: v4l_queue_frame() - buffers not yet allocated\n", | 496 | "%s: %s - buffers not yet allocated\n", |
686 | ZR_DEVNAME(zr)); | 497 | ZR_DEVNAME(zr), __func__); |
687 | res = -ENOMEM; | 498 | res = -ENOMEM; |
688 | } | 499 | } |
689 | 500 | ||
690 | /* No grabbing outside the buffer range! */ | 501 | /* No grabbing outside the buffer range! */ |
691 | if (num >= fh->v4l_buffers.num_buffers || num < 0) { | 502 | if (num >= fh->buffers.num_buffers || num < 0) { |
692 | dprintk(1, | 503 | dprintk(1, |
693 | KERN_ERR | 504 | KERN_ERR |
694 | "%s: v4l_queue_frame() - buffer %d is out of range\n", | 505 | "%s: %s - buffer %d is out of range\n", |
695 | ZR_DEVNAME(zr), num); | 506 | ZR_DEVNAME(zr), __func__, num); |
696 | res = -EINVAL; | 507 | res = -EINVAL; |
697 | } | 508 | } |
698 | 509 | ||
699 | spin_lock_irqsave(&zr->spinlock, flags); | 510 | spin_lock_irqsave(&zr->spinlock, flags); |
700 | 511 | ||
701 | if (fh->v4l_buffers.active == ZORAN_FREE) { | 512 | if (fh->buffers.active == ZORAN_FREE) { |
702 | if (zr->v4l_buffers.active == ZORAN_FREE) { | 513 | if (zr->v4l_buffers.active == ZORAN_FREE) { |
703 | zr->v4l_buffers = fh->v4l_buffers; | 514 | zr->v4l_buffers = fh->buffers; |
704 | fh->v4l_buffers.active = ZORAN_ACTIVE; | 515 | fh->buffers.active = ZORAN_ACTIVE; |
705 | } else { | 516 | } else { |
706 | dprintk(1, | 517 | dprintk(1, |
707 | KERN_ERR | 518 | KERN_ERR |
708 | "%s: v4l_queue_frame() - another session is already capturing\n", | 519 | "%s: %s - another session is already capturing\n", |
709 | ZR_DEVNAME(zr)); | 520 | ZR_DEVNAME(zr), __func__); |
710 | res = -EBUSY; | 521 | res = -EBUSY; |
711 | } | 522 | } |
712 | } | 523 | } |
@@ -717,7 +528,7 @@ zoran_v4l_queue_frame (struct file *file, | |||
717 | default: | 528 | default: |
718 | case BUZ_STATE_PEND: | 529 | case BUZ_STATE_PEND: |
719 | if (zr->v4l_buffers.active == ZORAN_FREE) { | 530 | if (zr->v4l_buffers.active == ZORAN_FREE) { |
720 | fh->v4l_buffers.active = ZORAN_FREE; | 531 | fh->buffers.active = ZORAN_FREE; |
721 | zr->v4l_buffers.allocated = 0; | 532 | zr->v4l_buffers.allocated = 0; |
722 | } | 533 | } |
723 | res = -EBUSY; /* what are you doing? */ | 534 | res = -EBUSY; /* what are you doing? */ |
@@ -725,19 +536,17 @@ zoran_v4l_queue_frame (struct file *file, | |||
725 | case BUZ_STATE_DONE: | 536 | case BUZ_STATE_DONE: |
726 | dprintk(2, | 537 | dprintk(2, |
727 | KERN_WARNING | 538 | KERN_WARNING |
728 | "%s: v4l_queue_frame() - queueing buffer %d in state DONE!?\n", | 539 | "%s: %s - queueing buffer %d in state DONE!?\n", |
729 | ZR_DEVNAME(zr), num); | 540 | ZR_DEVNAME(zr), __func__, num); |
730 | case BUZ_STATE_USER: | 541 | case BUZ_STATE_USER: |
731 | /* since there is at least one unused buffer there's room for at least | 542 | /* since there is at least one unused buffer there's room for at least |
732 | * one more pend[] entry */ | 543 | * one more pend[] entry */ |
733 | zr->v4l_pend[zr->v4l_pend_head++ & | 544 | zr->v4l_pend[zr->v4l_pend_head++ & V4L_MASK_FRAME] = num; |
734 | V4L_MASK_FRAME] = num; | ||
735 | zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND; | 545 | zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND; |
736 | zr->v4l_buffers.buffer[num].bs.length = | 546 | zr->v4l_buffers.buffer[num].bs.length = |
737 | fh->v4l_settings.bytesperline * | 547 | fh->v4l_settings.bytesperline * |
738 | zr->v4l_settings.height; | 548 | zr->v4l_settings.height; |
739 | fh->v4l_buffers.buffer[num] = | 549 | fh->buffers.buffer[num] = zr->v4l_buffers.buffer[num]; |
740 | zr->v4l_buffers.buffer[num]; | ||
741 | break; | 550 | break; |
742 | } | 551 | } |
743 | } | 552 | } |
@@ -745,65 +554,7 @@ zoran_v4l_queue_frame (struct file *file, | |||
745 | spin_unlock_irqrestore(&zr->spinlock, flags); | 554 | spin_unlock_irqrestore(&zr->spinlock, flags); |
746 | 555 | ||
747 | if (!res && zr->v4l_buffers.active == ZORAN_FREE) | 556 | if (!res && zr->v4l_buffers.active == ZORAN_FREE) |
748 | zr->v4l_buffers.active = fh->v4l_buffers.active; | 557 | zr->v4l_buffers.active = fh->buffers.active; |
749 | |||
750 | return res; | ||
751 | } | ||
752 | |||
753 | static int | ||
754 | v4l_grab (struct file *file, | ||
755 | struct video_mmap *mp) | ||
756 | { | ||
757 | struct zoran_fh *fh = file->private_data; | ||
758 | struct zoran *zr = fh->zr; | ||
759 | int res = 0, i; | ||
760 | |||
761 | for (i = 0; i < NUM_FORMATS; i++) { | ||
762 | if (zoran_formats[i].palette == mp->format && | ||
763 | zoran_formats[i].flags & ZORAN_FORMAT_CAPTURE && | ||
764 | !(zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED)) | ||
765 | break; | ||
766 | } | ||
767 | if (i == NUM_FORMATS || zoran_formats[i].depth == 0) { | ||
768 | dprintk(1, | ||
769 | KERN_ERR | ||
770 | "%s: v4l_grab() - wrong bytes-per-pixel format\n", | ||
771 | ZR_DEVNAME(zr)); | ||
772 | return -EINVAL; | ||
773 | } | ||
774 | |||
775 | /* | ||
776 | * To minimize the time spent in the IRQ routine, we avoid setting up | ||
777 | * the video front end there. | ||
778 | * If this grab has different parameters from a running streaming capture | ||
779 | * we stop the streaming capture and start it over again. | ||
780 | */ | ||
781 | if (zr->v4l_memgrab_active && | ||
782 | (zr->v4l_settings.width != mp->width || | ||
783 | zr->v4l_settings.height != mp->height || | ||
784 | zr->v4l_settings.format->palette != mp->format)) { | ||
785 | res = wait_grab_pending(zr); | ||
786 | if (res) | ||
787 | return res; | ||
788 | } | ||
789 | if ((res = zoran_v4l_set_format(file, | ||
790 | mp->width, | ||
791 | mp->height, | ||
792 | &zoran_formats[i]))) | ||
793 | return res; | ||
794 | zr->v4l_settings = fh->v4l_settings; | ||
795 | |||
796 | /* queue the frame in the pending queue */ | ||
797 | if ((res = zoran_v4l_queue_frame(file, mp->frame))) { | ||
798 | fh->v4l_buffers.active = ZORAN_FREE; | ||
799 | return res; | ||
800 | } | ||
801 | |||
802 | /* put the 36057 into frame grabbing mode */ | ||
803 | if (!res && !zr->v4l_memgrab_active) | ||
804 | zr36057_set_memgrab(zr, 1); | ||
805 | |||
806 | //dprintk(4, KERN_INFO "%s: Frame grab 3...\n", ZR_DEVNAME(zr)); | ||
807 | 558 | ||
808 | return res; | 559 | return res; |
809 | } | 560 | } |
@@ -812,27 +563,24 @@ v4l_grab (struct file *file, | |||
812 | * Sync on a V4L buffer | 563 | * Sync on a V4L buffer |
813 | */ | 564 | */ |
814 | 565 | ||
815 | static int | 566 | static int v4l_sync(struct zoran_fh *fh, int frame) |
816 | v4l_sync (struct file *file, | ||
817 | int frame) | ||
818 | { | 567 | { |
819 | struct zoran_fh *fh = file->private_data; | ||
820 | struct zoran *zr = fh->zr; | 568 | struct zoran *zr = fh->zr; |
821 | unsigned long flags; | 569 | unsigned long flags; |
822 | 570 | ||
823 | if (fh->v4l_buffers.active == ZORAN_FREE) { | 571 | if (fh->buffers.active == ZORAN_FREE) { |
824 | dprintk(1, | 572 | dprintk(1, |
825 | KERN_ERR | 573 | KERN_ERR |
826 | "%s: v4l_sync() - no grab active for this session\n", | 574 | "%s: %s - no grab active for this session\n", |
827 | ZR_DEVNAME(zr)); | 575 | ZR_DEVNAME(zr), __func__); |
828 | return -EINVAL; | 576 | return -EINVAL; |
829 | } | 577 | } |
830 | 578 | ||
831 | /* check passed-in frame number */ | 579 | /* check passed-in frame number */ |
832 | if (frame >= fh->v4l_buffers.num_buffers || frame < 0) { | 580 | if (frame >= fh->buffers.num_buffers || frame < 0) { |
833 | dprintk(1, | 581 | dprintk(1, |
834 | KERN_ERR "%s: v4l_sync() - frame %d is invalid\n", | 582 | KERN_ERR "%s: %s - frame %d is invalid\n", |
835 | ZR_DEVNAME(zr), frame); | 583 | ZR_DEVNAME(zr), __func__, frame); |
836 | return -EINVAL; | 584 | return -EINVAL; |
837 | } | 585 | } |
838 | 586 | ||
@@ -840,15 +588,14 @@ v4l_sync (struct file *file, | |||
840 | if (zr->v4l_buffers.buffer[frame].state == BUZ_STATE_USER) { | 588 | if (zr->v4l_buffers.buffer[frame].state == BUZ_STATE_USER) { |
841 | dprintk(1, | 589 | dprintk(1, |
842 | KERN_ERR | 590 | KERN_ERR |
843 | "%s: v4l_sync() - attempt to sync on a buffer which was not queued?\n", | 591 | "%s: %s - attempt to sync on a buffer which was not queued?\n", |
844 | ZR_DEVNAME(zr)); | 592 | ZR_DEVNAME(zr), __func__); |
845 | return -EPROTO; | 593 | return -EPROTO; |
846 | } | 594 | } |
847 | 595 | ||
848 | /* wait on this buffer to get ready */ | 596 | /* wait on this buffer to get ready */ |
849 | if (!wait_event_interruptible_timeout(zr->v4l_capq, | 597 | if (!wait_event_interruptible_timeout(zr->v4l_capq, |
850 | (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), | 598 | (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 10*HZ)) |
851 | 10*HZ)) | ||
852 | return -ETIME; | 599 | return -ETIME; |
853 | if (signal_pending(current)) | 600 | if (signal_pending(current)) |
854 | return -ERESTARTSYS; | 601 | return -ERESTARTSYS; |
@@ -856,11 +603,11 @@ v4l_sync (struct file *file, | |||
856 | /* buffer should now be in BUZ_STATE_DONE */ | 603 | /* buffer should now be in BUZ_STATE_DONE */ |
857 | if (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_DONE) | 604 | if (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_DONE) |
858 | dprintk(2, | 605 | dprintk(2, |
859 | KERN_ERR "%s: v4l_sync() - internal state error\n", | 606 | KERN_ERR "%s: %s - internal state error\n", |
860 | ZR_DEVNAME(zr)); | 607 | ZR_DEVNAME(zr), __func__); |
861 | 608 | ||
862 | zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER; | 609 | zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER; |
863 | fh->v4l_buffers.buffer[frame] = zr->v4l_buffers.buffer[frame]; | 610 | fh->buffers.buffer[frame] = zr->v4l_buffers.buffer[frame]; |
864 | 611 | ||
865 | spin_lock_irqsave(&zr->spinlock, flags); | 612 | spin_lock_irqsave(&zr->spinlock, flags); |
866 | 613 | ||
@@ -868,8 +615,7 @@ v4l_sync (struct file *file, | |||
868 | if (zr->v4l_pend_tail == zr->v4l_pend_head) { | 615 | if (zr->v4l_pend_tail == zr->v4l_pend_head) { |
869 | zr36057_set_memgrab(zr, 0); | 616 | zr36057_set_memgrab(zr, 0); |
870 | if (zr->v4l_buffers.active == ZORAN_ACTIVE) { | 617 | if (zr->v4l_buffers.active == ZORAN_ACTIVE) { |
871 | fh->v4l_buffers.active = zr->v4l_buffers.active = | 618 | fh->buffers.active = zr->v4l_buffers.active = ZORAN_FREE; |
872 | ZORAN_FREE; | ||
873 | zr->v4l_buffers.allocated = 0; | 619 | zr->v4l_buffers.allocated = 0; |
874 | } | 620 | } |
875 | } | 621 | } |
@@ -883,31 +629,28 @@ v4l_sync (struct file *file, | |||
883 | * Queue a MJPEG buffer for capture/playback | 629 | * Queue a MJPEG buffer for capture/playback |
884 | */ | 630 | */ |
885 | 631 | ||
886 | static int | 632 | static int zoran_jpg_queue_frame(struct zoran_fh *fh, int num, |
887 | zoran_jpg_queue_frame (struct file *file, | 633 | enum zoran_codec_mode mode) |
888 | int num, | ||
889 | enum zoran_codec_mode mode) | ||
890 | { | 634 | { |
891 | struct zoran_fh *fh = file->private_data; | ||
892 | struct zoran *zr = fh->zr; | 635 | struct zoran *zr = fh->zr; |
893 | unsigned long flags; | 636 | unsigned long flags; |
894 | int res = 0; | 637 | int res = 0; |
895 | 638 | ||
896 | /* Check if buffers are allocated */ | 639 | /* Check if buffers are allocated */ |
897 | if (!fh->jpg_buffers.allocated) { | 640 | if (!fh->buffers.allocated) { |
898 | dprintk(1, | 641 | dprintk(1, |
899 | KERN_ERR | 642 | KERN_ERR |
900 | "%s: jpg_queue_frame() - buffers not yet allocated\n", | 643 | "%s: %s - buffers not yet allocated\n", |
901 | ZR_DEVNAME(zr)); | 644 | ZR_DEVNAME(zr), __func__); |
902 | return -ENOMEM; | 645 | return -ENOMEM; |
903 | } | 646 | } |
904 | 647 | ||
905 | /* No grabbing outside the buffer range! */ | 648 | /* No grabbing outside the buffer range! */ |
906 | if (num >= fh->jpg_buffers.num_buffers || num < 0) { | 649 | if (num >= fh->buffers.num_buffers || num < 0) { |
907 | dprintk(1, | 650 | dprintk(1, |
908 | KERN_ERR | 651 | KERN_ERR |
909 | "%s: jpg_queue_frame() - buffer %d out of range\n", | 652 | "%s: %s - buffer %d out of range\n", |
910 | ZR_DEVNAME(zr), num); | 653 | ZR_DEVNAME(zr), __func__, num); |
911 | return -EINVAL; | 654 | return -EINVAL; |
912 | } | 655 | } |
913 | 656 | ||
@@ -918,20 +661,20 @@ zoran_jpg_queue_frame (struct file *file, | |||
918 | /* wrong codec mode active - invalid */ | 661 | /* wrong codec mode active - invalid */ |
919 | dprintk(1, | 662 | dprintk(1, |
920 | KERN_ERR | 663 | KERN_ERR |
921 | "%s: jpg_queue_frame() - codec in wrong mode\n", | 664 | "%s: %s - codec in wrong mode\n", |
922 | ZR_DEVNAME(zr)); | 665 | ZR_DEVNAME(zr), __func__); |
923 | return -EINVAL; | 666 | return -EINVAL; |
924 | } | 667 | } |
925 | 668 | ||
926 | if (fh->jpg_buffers.active == ZORAN_FREE) { | 669 | if (fh->buffers.active == ZORAN_FREE) { |
927 | if (zr->jpg_buffers.active == ZORAN_FREE) { | 670 | if (zr->jpg_buffers.active == ZORAN_FREE) { |
928 | zr->jpg_buffers = fh->jpg_buffers; | 671 | zr->jpg_buffers = fh->buffers; |
929 | fh->jpg_buffers.active = ZORAN_ACTIVE; | 672 | fh->buffers.active = ZORAN_ACTIVE; |
930 | } else { | 673 | } else { |
931 | dprintk(1, | 674 | dprintk(1, |
932 | KERN_ERR | 675 | KERN_ERR |
933 | "%s: jpg_queue_frame() - another session is already capturing\n", | 676 | "%s: %s - another session is already capturing\n", |
934 | ZR_DEVNAME(zr)); | 677 | ZR_DEVNAME(zr), __func__); |
935 | res = -EBUSY; | 678 | res = -EBUSY; |
936 | } | 679 | } |
937 | } | 680 | } |
@@ -948,23 +691,21 @@ zoran_jpg_queue_frame (struct file *file, | |||
948 | case BUZ_STATE_DONE: | 691 | case BUZ_STATE_DONE: |
949 | dprintk(2, | 692 | dprintk(2, |
950 | KERN_WARNING | 693 | KERN_WARNING |
951 | "%s: jpg_queue_frame() - queing frame in BUZ_STATE_DONE state!?\n", | 694 | "%s: %s - queing frame in BUZ_STATE_DONE state!?\n", |
952 | ZR_DEVNAME(zr)); | 695 | ZR_DEVNAME(zr), __func__); |
953 | case BUZ_STATE_USER: | 696 | case BUZ_STATE_USER: |
954 | /* since there is at least one unused buffer there's room for at | 697 | /* since there is at least one unused buffer there's room for at |
955 | *least one more pend[] entry */ | 698 | *least one more pend[] entry */ |
956 | zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] = | 699 | zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] = num; |
957 | num; | ||
958 | zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND; | 700 | zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND; |
959 | fh->jpg_buffers.buffer[num] = | 701 | fh->buffers.buffer[num] = zr->jpg_buffers.buffer[num]; |
960 | zr->jpg_buffers.buffer[num]; | ||
961 | zoran_feed_stat_com(zr); | 702 | zoran_feed_stat_com(zr); |
962 | break; | 703 | break; |
963 | default: | 704 | default: |
964 | case BUZ_STATE_DMA: | 705 | case BUZ_STATE_DMA: |
965 | case BUZ_STATE_PEND: | 706 | case BUZ_STATE_PEND: |
966 | if (zr->jpg_buffers.active == ZORAN_FREE) { | 707 | if (zr->jpg_buffers.active == ZORAN_FREE) { |
967 | fh->jpg_buffers.active = ZORAN_FREE; | 708 | fh->buffers.active = ZORAN_FREE; |
968 | zr->jpg_buffers.allocated = 0; | 709 | zr->jpg_buffers.allocated = 0; |
969 | } | 710 | } |
970 | res = -EBUSY; /* what are you doing? */ | 711 | res = -EBUSY; /* what are you doing? */ |
@@ -974,47 +715,41 @@ zoran_jpg_queue_frame (struct file *file, | |||
974 | 715 | ||
975 | spin_unlock_irqrestore(&zr->spinlock, flags); | 716 | spin_unlock_irqrestore(&zr->spinlock, flags); |
976 | 717 | ||
977 | if (!res && zr->jpg_buffers.active == ZORAN_FREE) { | 718 | if (!res && zr->jpg_buffers.active == ZORAN_FREE) |
978 | zr->jpg_buffers.active = fh->jpg_buffers.active; | 719 | zr->jpg_buffers.active = fh->buffers.active; |
979 | } | ||
980 | 720 | ||
981 | return res; | 721 | return res; |
982 | } | 722 | } |
983 | 723 | ||
984 | static int | 724 | static int jpg_qbuf(struct zoran_fh *fh, int frame, enum zoran_codec_mode mode) |
985 | jpg_qbuf (struct file *file, | ||
986 | int frame, | ||
987 | enum zoran_codec_mode mode) | ||
988 | { | 725 | { |
989 | struct zoran_fh *fh = file->private_data; | ||
990 | struct zoran *zr = fh->zr; | 726 | struct zoran *zr = fh->zr; |
991 | int res = 0; | 727 | int res = 0; |
992 | 728 | ||
993 | /* Does the user want to stop streaming? */ | 729 | /* Does the user want to stop streaming? */ |
994 | if (frame < 0) { | 730 | if (frame < 0) { |
995 | if (zr->codec_mode == mode) { | 731 | if (zr->codec_mode == mode) { |
996 | if (fh->jpg_buffers.active == ZORAN_FREE) { | 732 | if (fh->buffers.active == ZORAN_FREE) { |
997 | dprintk(1, | 733 | dprintk(1, |
998 | KERN_ERR | 734 | KERN_ERR |
999 | "%s: jpg_qbuf(-1) - session not active\n", | 735 | "%s: %s(-1) - session not active\n", |
1000 | ZR_DEVNAME(zr)); | 736 | ZR_DEVNAME(zr), __func__); |
1001 | return -EINVAL; | 737 | return -EINVAL; |
1002 | } | 738 | } |
1003 | fh->jpg_buffers.active = zr->jpg_buffers.active = | 739 | fh->buffers.active = zr->jpg_buffers.active = ZORAN_FREE; |
1004 | ZORAN_FREE; | ||
1005 | zr->jpg_buffers.allocated = 0; | 740 | zr->jpg_buffers.allocated = 0; |
1006 | zr36057_enable_jpg(zr, BUZ_MODE_IDLE); | 741 | zr36057_enable_jpg(zr, BUZ_MODE_IDLE); |
1007 | return 0; | 742 | return 0; |
1008 | } else { | 743 | } else { |
1009 | dprintk(1, | 744 | dprintk(1, |
1010 | KERN_ERR | 745 | KERN_ERR |
1011 | "%s: jpg_qbuf() - stop streaming but not in streaming mode\n", | 746 | "%s: %s - stop streaming but not in streaming mode\n", |
1012 | ZR_DEVNAME(zr)); | 747 | ZR_DEVNAME(zr), __func__); |
1013 | return -EINVAL; | 748 | return -EINVAL; |
1014 | } | 749 | } |
1015 | } | 750 | } |
1016 | 751 | ||
1017 | if ((res = zoran_jpg_queue_frame(file, frame, mode))) | 752 | if ((res = zoran_jpg_queue_frame(fh, frame, mode))) |
1018 | return res; | 753 | return res; |
1019 | 754 | ||
1020 | /* Start the jpeg codec when the first frame is queued */ | 755 | /* Start the jpeg codec when the first frame is queued */ |
@@ -1028,28 +763,25 @@ jpg_qbuf (struct file *file, | |||
1028 | * Sync on a MJPEG buffer | 763 | * Sync on a MJPEG buffer |
1029 | */ | 764 | */ |
1030 | 765 | ||
1031 | static int | 766 | static int jpg_sync(struct zoran_fh *fh, struct zoran_sync *bs) |
1032 | jpg_sync (struct file *file, | ||
1033 | struct zoran_sync *bs) | ||
1034 | { | 767 | { |
1035 | struct zoran_fh *fh = file->private_data; | ||
1036 | struct zoran *zr = fh->zr; | 768 | struct zoran *zr = fh->zr; |
1037 | unsigned long flags; | 769 | unsigned long flags; |
1038 | int frame; | 770 | int frame; |
1039 | 771 | ||
1040 | if (fh->jpg_buffers.active == ZORAN_FREE) { | 772 | if (fh->buffers.active == ZORAN_FREE) { |
1041 | dprintk(1, | 773 | dprintk(1, |
1042 | KERN_ERR | 774 | KERN_ERR |
1043 | "%s: jpg_sync() - capture is not currently active\n", | 775 | "%s: %s - capture is not currently active\n", |
1044 | ZR_DEVNAME(zr)); | 776 | ZR_DEVNAME(zr), __func__); |
1045 | return -EINVAL; | 777 | return -EINVAL; |
1046 | } | 778 | } |
1047 | if (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS && | 779 | if (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS && |
1048 | zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) { | 780 | zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) { |
1049 | dprintk(1, | 781 | dprintk(1, |
1050 | KERN_ERR | 782 | KERN_ERR |
1051 | "%s: jpg_sync() - codec not in streaming mode\n", | 783 | "%s: %s - codec not in streaming mode\n", |
1052 | ZR_DEVNAME(zr)); | 784 | ZR_DEVNAME(zr), __func__); |
1053 | return -EINVAL; | 785 | return -EINVAL; |
1054 | } | 786 | } |
1055 | if (!wait_event_interruptible_timeout(zr->jpg_capq, | 787 | if (!wait_event_interruptible_timeout(zr->jpg_capq, |
@@ -1064,8 +796,8 @@ jpg_sync (struct file *file, | |||
1064 | sizeof(isr), &isr); | 796 | sizeof(isr), &isr); |
1065 | dprintk(1, | 797 | dprintk(1, |
1066 | KERN_ERR | 798 | KERN_ERR |
1067 | "%s: jpg_sync() - timeout: codec isr=0x%02x\n", | 799 | "%s: %s - timeout: codec isr=0x%02x\n", |
1068 | ZR_DEVNAME(zr), isr); | 800 | ZR_DEVNAME(zr), __func__, isr); |
1069 | 801 | ||
1070 | return -ETIME; | 802 | return -ETIME; |
1071 | 803 | ||
@@ -1083,28 +815,26 @@ jpg_sync (struct file *file, | |||
1083 | /* buffer should now be in BUZ_STATE_DONE */ | 815 | /* buffer should now be in BUZ_STATE_DONE */ |
1084 | if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE) | 816 | if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE) |
1085 | dprintk(2, | 817 | dprintk(2, |
1086 | KERN_ERR "%s: jpg_sync() - internal state error\n", | 818 | KERN_ERR "%s: %s - internal state error\n", |
1087 | ZR_DEVNAME(zr)); | 819 | ZR_DEVNAME(zr), __func__); |
1088 | 820 | ||
1089 | *bs = zr->jpg_buffers.buffer[frame].bs; | 821 | *bs = zr->jpg_buffers.buffer[frame].bs; |
1090 | bs->frame = frame; | 822 | bs->frame = frame; |
1091 | zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER; | 823 | zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER; |
1092 | fh->jpg_buffers.buffer[frame] = zr->jpg_buffers.buffer[frame]; | 824 | fh->buffers.buffer[frame] = zr->jpg_buffers.buffer[frame]; |
1093 | 825 | ||
1094 | spin_unlock_irqrestore(&zr->spinlock, flags); | 826 | spin_unlock_irqrestore(&zr->spinlock, flags); |
1095 | 827 | ||
1096 | return 0; | 828 | return 0; |
1097 | } | 829 | } |
1098 | 830 | ||
1099 | static void | 831 | static void zoran_open_init_session(struct zoran_fh *fh) |
1100 | zoran_open_init_session (struct file *file) | ||
1101 | { | 832 | { |
1102 | int i; | 833 | int i; |
1103 | struct zoran_fh *fh = file->private_data; | ||
1104 | struct zoran *zr = fh->zr; | 834 | struct zoran *zr = fh->zr; |
1105 | 835 | ||
1106 | /* Per default, map the V4L Buffers */ | 836 | /* Per default, map the V4L Buffers */ |
1107 | fh->map_mode = ZORAN_MAP_MODE_RAW; | 837 | map_mode_raw(fh); |
1108 | 838 | ||
1109 | /* take over the card's current settings */ | 839 | /* take over the card's current settings */ |
1110 | fh->overlay_settings = zr->overlay_settings; | 840 | fh->overlay_settings = zr->overlay_settings; |
@@ -1114,40 +844,21 @@ zoran_open_init_session (struct file *file) | |||
1114 | 844 | ||
1115 | /* v4l settings */ | 845 | /* v4l settings */ |
1116 | fh->v4l_settings = zr->v4l_settings; | 846 | fh->v4l_settings = zr->v4l_settings; |
1117 | |||
1118 | /* v4l_buffers */ | ||
1119 | memset(&fh->v4l_buffers, 0, sizeof(struct zoran_v4l_struct)); | ||
1120 | for (i = 0; i < VIDEO_MAX_FRAME; i++) { | ||
1121 | fh->v4l_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ | ||
1122 | fh->v4l_buffers.buffer[i].bs.frame = i; | ||
1123 | } | ||
1124 | fh->v4l_buffers.allocated = 0; | ||
1125 | fh->v4l_buffers.ready_to_be_freed = 0; | ||
1126 | fh->v4l_buffers.active = ZORAN_FREE; | ||
1127 | fh->v4l_buffers.buffer_size = v4l_bufsize; | ||
1128 | fh->v4l_buffers.num_buffers = v4l_nbufs; | ||
1129 | |||
1130 | /* jpg settings */ | 847 | /* jpg settings */ |
1131 | fh->jpg_settings = zr->jpg_settings; | 848 | fh->jpg_settings = zr->jpg_settings; |
1132 | 849 | ||
1133 | /* jpg_buffers */ | 850 | /* buffers */ |
1134 | memset(&fh->jpg_buffers, 0, sizeof(struct zoran_jpg_struct)); | 851 | memset(&fh->buffers, 0, sizeof(fh->buffers)); |
1135 | for (i = 0; i < BUZ_MAX_FRAME; i++) { | 852 | for (i = 0; i < MAX_FRAME; i++) { |
1136 | fh->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ | 853 | fh->buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ |
1137 | fh->jpg_buffers.buffer[i].bs.frame = i; | 854 | fh->buffers.buffer[i].bs.frame = i; |
1138 | } | 855 | } |
1139 | fh->jpg_buffers.need_contiguous = zr->jpg_buffers.need_contiguous; | 856 | fh->buffers.allocated = 0; |
1140 | fh->jpg_buffers.allocated = 0; | 857 | fh->buffers.active = ZORAN_FREE; |
1141 | fh->jpg_buffers.ready_to_be_freed = 0; | ||
1142 | fh->jpg_buffers.active = ZORAN_FREE; | ||
1143 | fh->jpg_buffers.buffer_size = jpg_bufsize; | ||
1144 | fh->jpg_buffers.num_buffers = jpg_nbufs; | ||
1145 | } | 858 | } |
1146 | 859 | ||
1147 | static void | 860 | static void zoran_close_end_session(struct zoran_fh *fh) |
1148 | zoran_close_end_session (struct file *file) | ||
1149 | { | 861 | { |
1150 | struct zoran_fh *fh = file->private_data; | ||
1151 | struct zoran *zr = fh->zr; | 862 | struct zoran *zr = fh->zr; |
1152 | 863 | ||
1153 | /* overlay */ | 864 | /* overlay */ |
@@ -1159,36 +870,32 @@ zoran_close_end_session (struct file *file) | |||
1159 | zr->overlay_mask = NULL; | 870 | zr->overlay_mask = NULL; |
1160 | } | 871 | } |
1161 | 872 | ||
1162 | /* v4l capture */ | 873 | if (fh->map_mode == ZORAN_MAP_MODE_RAW) { |
1163 | if (fh->v4l_buffers.active != ZORAN_FREE) { | 874 | /* v4l capture */ |
1164 | unsigned long flags; | 875 | if (fh->buffers.active != ZORAN_FREE) { |
876 | unsigned long flags; | ||
1165 | 877 | ||
1166 | spin_lock_irqsave(&zr->spinlock, flags); | 878 | spin_lock_irqsave(&zr->spinlock, flags); |
1167 | zr36057_set_memgrab(zr, 0); | 879 | zr36057_set_memgrab(zr, 0); |
1168 | zr->v4l_buffers.allocated = 0; | 880 | zr->v4l_buffers.allocated = 0; |
1169 | zr->v4l_buffers.active = fh->v4l_buffers.active = | 881 | zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; |
1170 | ZORAN_FREE; | 882 | spin_unlock_irqrestore(&zr->spinlock, flags); |
1171 | spin_unlock_irqrestore(&zr->spinlock, flags); | 883 | } |
1172 | } | ||
1173 | |||
1174 | /* v4l buffers */ | ||
1175 | if (fh->v4l_buffers.allocated || | ||
1176 | fh->v4l_buffers.ready_to_be_freed) { | ||
1177 | v4l_fbuffer_free(file); | ||
1178 | } | ||
1179 | 884 | ||
1180 | /* jpg capture */ | 885 | /* v4l buffers */ |
1181 | if (fh->jpg_buffers.active != ZORAN_FREE) { | 886 | if (fh->buffers.allocated) |
1182 | zr36057_enable_jpg(zr, BUZ_MODE_IDLE); | 887 | v4l_fbuffer_free(fh); |
1183 | zr->jpg_buffers.allocated = 0; | 888 | } else { |
1184 | zr->jpg_buffers.active = fh->jpg_buffers.active = | 889 | /* jpg capture */ |
1185 | ZORAN_FREE; | 890 | if (fh->buffers.active != ZORAN_FREE) { |
1186 | } | 891 | zr36057_enable_jpg(zr, BUZ_MODE_IDLE); |
892 | zr->jpg_buffers.allocated = 0; | ||
893 | zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE; | ||
894 | } | ||
1187 | 895 | ||
1188 | /* jpg buffers */ | 896 | /* jpg buffers */ |
1189 | if (fh->jpg_buffers.allocated || | 897 | if (fh->buffers.allocated) |
1190 | fh->jpg_buffers.ready_to_be_freed) { | 898 | jpg_fbuffer_free(fh); |
1191 | jpg_fbuffer_free(file); | ||
1192 | } | 899 | } |
1193 | } | 900 | } |
1194 | 901 | ||
@@ -1202,15 +909,11 @@ static int zoran_open(struct file *file) | |||
1202 | struct zoran_fh *fh; | 909 | struct zoran_fh *fh; |
1203 | int res, first_open = 0; | 910 | int res, first_open = 0; |
1204 | 911 | ||
1205 | dprintk(2, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n", | 912 | dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(-)=%d\n", |
1206 | ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user + 1); | 913 | ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user + 1); |
1207 | 914 | ||
1208 | lock_kernel(); | 915 | lock_kernel(); |
1209 | 916 | ||
1210 | /* see fs/device.c - the kernel already locks during open(), | ||
1211 | * so locking ourselves only causes deadlocks */ | ||
1212 | /*mutex_lock(&zr->resource_lock);*/ | ||
1213 | |||
1214 | if (zr->user >= 2048) { | 917 | if (zr->user >= 2048) { |
1215 | dprintk(1, KERN_ERR "%s: too many users (%d) on device\n", | 918 | dprintk(1, KERN_ERR "%s: too many users (%d) on device\n", |
1216 | ZR_DEVNAME(zr), zr->user); | 919 | ZR_DEVNAME(zr), zr->user); |
@@ -1218,41 +921,15 @@ static int zoran_open(struct file *file) | |||
1218 | goto fail_unlock; | 921 | goto fail_unlock; |
1219 | } | 922 | } |
1220 | 923 | ||
1221 | if (!zr->decoder) { | ||
1222 | dprintk(1, | ||
1223 | KERN_ERR "%s: no TV decoder loaded for device!\n", | ||
1224 | ZR_DEVNAME(zr)); | ||
1225 | res = -EIO; | ||
1226 | goto fail_unlock; | ||
1227 | } | ||
1228 | |||
1229 | if (!try_module_get(zr->decoder->driver->driver.owner)) { | ||
1230 | dprintk(1, | ||
1231 | KERN_ERR | ||
1232 | "%s: failed to grab ownership of video decoder\n", | ||
1233 | ZR_DEVNAME(zr)); | ||
1234 | res = -EIO; | ||
1235 | goto fail_unlock; | ||
1236 | } | ||
1237 | if (zr->encoder && | ||
1238 | !try_module_get(zr->encoder->driver->driver.owner)) { | ||
1239 | dprintk(1, | ||
1240 | KERN_ERR | ||
1241 | "%s: failed to grab ownership of video encoder\n", | ||
1242 | ZR_DEVNAME(zr)); | ||
1243 | res = -EIO; | ||
1244 | goto fail_decoder; | ||
1245 | } | ||
1246 | |||
1247 | /* now, create the open()-specific file_ops struct */ | 924 | /* now, create the open()-specific file_ops struct */ |
1248 | fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); | 925 | fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); |
1249 | if (!fh) { | 926 | if (!fh) { |
1250 | dprintk(1, | 927 | dprintk(1, |
1251 | KERN_ERR | 928 | KERN_ERR |
1252 | "%s: zoran_open() - allocation of zoran_fh failed\n", | 929 | "%s: %s - allocation of zoran_fh failed\n", |
1253 | ZR_DEVNAME(zr)); | 930 | ZR_DEVNAME(zr), __func__); |
1254 | res = -ENOMEM; | 931 | res = -ENOMEM; |
1255 | goto fail_encoder; | 932 | goto fail_unlock; |
1256 | } | 933 | } |
1257 | /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows | 934 | /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows |
1258 | * on norm-change! */ | 935 | * on norm-change! */ |
@@ -1261,8 +938,8 @@ static int zoran_open(struct file *file) | |||
1261 | if (!fh->overlay_mask) { | 938 | if (!fh->overlay_mask) { |
1262 | dprintk(1, | 939 | dprintk(1, |
1263 | KERN_ERR | 940 | KERN_ERR |
1264 | "%s: zoran_open() - allocation of overlay_mask failed\n", | 941 | "%s: %s - allocation of overlay_mask failed\n", |
1265 | ZR_DEVNAME(zr)); | 942 | ZR_DEVNAME(zr), __func__); |
1266 | res = -ENOMEM; | 943 | res = -ENOMEM; |
1267 | goto fail_fh; | 944 | goto fail_fh; |
1268 | } | 945 | } |
@@ -1284,18 +961,13 @@ static int zoran_open(struct file *file) | |||
1284 | /* set file_ops stuff */ | 961 | /* set file_ops stuff */ |
1285 | file->private_data = fh; | 962 | file->private_data = fh; |
1286 | fh->zr = zr; | 963 | fh->zr = zr; |
1287 | zoran_open_init_session(file); | 964 | zoran_open_init_session(fh); |
1288 | unlock_kernel(); | 965 | unlock_kernel(); |
1289 | 966 | ||
1290 | return 0; | 967 | return 0; |
1291 | 968 | ||
1292 | fail_fh: | 969 | fail_fh: |
1293 | kfree(fh); | 970 | kfree(fh); |
1294 | fail_encoder: | ||
1295 | if (zr->encoder) | ||
1296 | module_put(zr->encoder->driver->driver.owner); | ||
1297 | fail_decoder: | ||
1298 | module_put(zr->decoder->driver->driver.owner); | ||
1299 | fail_unlock: | 971 | fail_unlock: |
1300 | unlock_kernel(); | 972 | unlock_kernel(); |
1301 | 973 | ||
@@ -1311,14 +983,14 @@ zoran_close(struct file *file) | |||
1311 | struct zoran_fh *fh = file->private_data; | 983 | struct zoran_fh *fh = file->private_data; |
1312 | struct zoran *zr = fh->zr; | 984 | struct zoran *zr = fh->zr; |
1313 | 985 | ||
1314 | dprintk(2, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n", | 986 | dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(+)=%d\n", |
1315 | ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user - 1); | 987 | ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user - 1); |
1316 | 988 | ||
1317 | /* kernel locks (fs/device.c), so don't do that ourselves | 989 | /* kernel locks (fs/device.c), so don't do that ourselves |
1318 | * (prevents deadlocks) */ | 990 | * (prevents deadlocks) */ |
1319 | /*mutex_lock(&zr->resource_lock);*/ | 991 | /*mutex_lock(&zr->resource_lock);*/ |
1320 | 992 | ||
1321 | zoran_close_end_session(file); | 993 | zoran_close_end_session(fh); |
1322 | 994 | ||
1323 | if (zr->user-- == 1) { /* Last process */ | 995 | if (zr->user-- == 1) { /* Last process */ |
1324 | /* Clean up JPEG process */ | 996 | /* Clean up JPEG process */ |
@@ -1346,9 +1018,10 @@ zoran_close(struct file *file) | |||
1346 | zoran_set_pci_master(zr, 0); | 1018 | zoran_set_pci_master(zr, 0); |
1347 | 1019 | ||
1348 | if (!pass_through) { /* Switch to color bar */ | 1020 | if (!pass_through) { /* Switch to color bar */ |
1349 | int zero = 0, two = 2; | 1021 | struct v4l2_routing route = { 2, 0 }; |
1350 | decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero); | 1022 | |
1351 | encoder_command(zr, ENCODER_SET_INPUT, &two); | 1023 | decoder_call(zr, video, s_stream, 0); |
1024 | encoder_call(zr, video, s_routing, &route); | ||
1352 | } | 1025 | } |
1353 | } | 1026 | } |
1354 | 1027 | ||
@@ -1356,14 +1029,7 @@ zoran_close(struct file *file) | |||
1356 | kfree(fh->overlay_mask); | 1029 | kfree(fh->overlay_mask); |
1357 | kfree(fh); | 1030 | kfree(fh); |
1358 | 1031 | ||
1359 | /* release locks on the i2c modules */ | 1032 | dprintk(4, KERN_INFO "%s: %s done\n", ZR_DEVNAME(zr), __func__); |
1360 | module_put(zr->decoder->driver->driver.owner); | ||
1361 | if (zr->encoder) | ||
1362 | module_put(zr->encoder->driver->driver.owner); | ||
1363 | |||
1364 | /*mutex_unlock(&zr->resource_lock);*/ | ||
1365 | |||
1366 | dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr)); | ||
1367 | 1033 | ||
1368 | return 0; | 1034 | return 0; |
1369 | } | 1035 | } |
@@ -1391,15 +1057,13 @@ zoran_write (struct file *file, | |||
1391 | return -EINVAL; | 1057 | return -EINVAL; |
1392 | } | 1058 | } |
1393 | 1059 | ||
1394 | static int | 1060 | static int setup_fbuffer(struct zoran_fh *fh, |
1395 | setup_fbuffer (struct file *file, | ||
1396 | void *base, | 1061 | void *base, |
1397 | const struct zoran_format *fmt, | 1062 | const struct zoran_format *fmt, |
1398 | int width, | 1063 | int width, |
1399 | int height, | 1064 | int height, |
1400 | int bytesperline) | 1065 | int bytesperline) |
1401 | { | 1066 | { |
1402 | struct zoran_fh *fh = file->private_data; | ||
1403 | struct zoran *zr = fh->zr; | 1067 | struct zoran *zr = fh->zr; |
1404 | 1068 | ||
1405 | /* (Ronald) v4l/v4l2 guidelines */ | 1069 | /* (Ronald) v4l/v4l2 guidelines */ |
@@ -1427,8 +1091,8 @@ setup_fbuffer (struct file *file, | |||
1427 | * friendly and silently do as if nothing went wrong */ | 1091 | * friendly and silently do as if nothing went wrong */ |
1428 | dprintk(3, | 1092 | dprintk(3, |
1429 | KERN_ERR | 1093 | KERN_ERR |
1430 | "%s: setup_fbuffer() - forced overlay turnoff because framebuffer changed\n", | 1094 | "%s: %s - forced overlay turnoff because framebuffer changed\n", |
1431 | ZR_DEVNAME(zr)); | 1095 | ZR_DEVNAME(zr), __func__); |
1432 | zr36057_overlay(zr, 0); | 1096 | zr36057_overlay(zr, 0); |
1433 | } | 1097 | } |
1434 | #endif | 1098 | #endif |
@@ -1436,31 +1100,31 @@ setup_fbuffer (struct file *file, | |||
1436 | if (!(fmt->flags & ZORAN_FORMAT_OVERLAY)) { | 1100 | if (!(fmt->flags & ZORAN_FORMAT_OVERLAY)) { |
1437 | dprintk(1, | 1101 | dprintk(1, |
1438 | KERN_ERR | 1102 | KERN_ERR |
1439 | "%s: setup_fbuffer() - no valid overlay format given\n", | 1103 | "%s: %s - no valid overlay format given\n", |
1440 | ZR_DEVNAME(zr)); | 1104 | ZR_DEVNAME(zr), __func__); |
1441 | return -EINVAL; | 1105 | return -EINVAL; |
1442 | } | 1106 | } |
1443 | if (height <= 0 || width <= 0 || bytesperline <= 0) { | 1107 | if (height <= 0 || width <= 0 || bytesperline <= 0) { |
1444 | dprintk(1, | 1108 | dprintk(1, |
1445 | KERN_ERR | 1109 | KERN_ERR |
1446 | "%s: setup_fbuffer() - invalid height/width/bpl value (%d|%d|%d)\n", | 1110 | "%s: %s - invalid height/width/bpl value (%d|%d|%d)\n", |
1447 | ZR_DEVNAME(zr), width, height, bytesperline); | 1111 | ZR_DEVNAME(zr), __func__, width, height, bytesperline); |
1448 | return -EINVAL; | 1112 | return -EINVAL; |
1449 | } | 1113 | } |
1450 | if (bytesperline & 3) { | 1114 | if (bytesperline & 3) { |
1451 | dprintk(1, | 1115 | dprintk(1, |
1452 | KERN_ERR | 1116 | KERN_ERR |
1453 | "%s: setup_fbuffer() - bytesperline (%d) must be 4-byte aligned\n", | 1117 | "%s: %s - bytesperline (%d) must be 4-byte aligned\n", |
1454 | ZR_DEVNAME(zr), bytesperline); | 1118 | ZR_DEVNAME(zr), __func__, bytesperline); |
1455 | return -EINVAL; | 1119 | return -EINVAL; |
1456 | } | 1120 | } |
1457 | 1121 | ||
1458 | zr->buffer.base = (void *) ((unsigned long) base & ~3); | 1122 | zr->vbuf_base = (void *) ((unsigned long) base & ~3); |
1459 | zr->buffer.height = height; | 1123 | zr->vbuf_height = height; |
1460 | zr->buffer.width = width; | 1124 | zr->vbuf_width = width; |
1461 | zr->buffer.depth = fmt->depth; | 1125 | zr->vbuf_depth = fmt->depth; |
1462 | zr->overlay_settings.format = fmt; | 1126 | zr->overlay_settings.format = fmt; |
1463 | zr->buffer.bytesperline = bytesperline; | 1127 | zr->vbuf_bytesperline = bytesperline; |
1464 | 1128 | ||
1465 | /* The user should set new window parameters */ | 1129 | /* The user should set new window parameters */ |
1466 | zr->overlay_settings.is_set = 0; | 1130 | zr->overlay_settings.is_set = 0; |
@@ -1469,35 +1133,27 @@ setup_fbuffer (struct file *file, | |||
1469 | } | 1133 | } |
1470 | 1134 | ||
1471 | 1135 | ||
1472 | static int | 1136 | static int setup_window(struct zoran_fh *fh, int x, int y, int width, int height, |
1473 | setup_window (struct file *file, | 1137 | struct v4l2_clip __user *clips, int clipcount, void __user *bitmap) |
1474 | int x, | ||
1475 | int y, | ||
1476 | int width, | ||
1477 | int height, | ||
1478 | struct video_clip __user *clips, | ||
1479 | int clipcount, | ||
1480 | void __user *bitmap) | ||
1481 | { | 1138 | { |
1482 | struct zoran_fh *fh = file->private_data; | ||
1483 | struct zoran *zr = fh->zr; | 1139 | struct zoran *zr = fh->zr; |
1484 | struct video_clip *vcp = NULL; | 1140 | struct v4l2_clip *vcp = NULL; |
1485 | int on, end; | 1141 | int on, end; |
1486 | 1142 | ||
1487 | 1143 | ||
1488 | if (!zr->buffer.base) { | 1144 | if (!zr->vbuf_base) { |
1489 | dprintk(1, | 1145 | dprintk(1, |
1490 | KERN_ERR | 1146 | KERN_ERR |
1491 | "%s: setup_window() - frame buffer has to be set first\n", | 1147 | "%s: %s - frame buffer has to be set first\n", |
1492 | ZR_DEVNAME(zr)); | 1148 | ZR_DEVNAME(zr), __func__); |
1493 | return -EINVAL; | 1149 | return -EINVAL; |
1494 | } | 1150 | } |
1495 | 1151 | ||
1496 | if (!fh->overlay_settings.format) { | 1152 | if (!fh->overlay_settings.format) { |
1497 | dprintk(1, | 1153 | dprintk(1, |
1498 | KERN_ERR | 1154 | KERN_ERR |
1499 | "%s: setup_window() - no overlay format set\n", | 1155 | "%s: %s - no overlay format set\n", |
1500 | ZR_DEVNAME(zr)); | 1156 | ZR_DEVNAME(zr), __func__); |
1501 | return -EINVAL; | 1157 | return -EINVAL; |
1502 | } | 1158 | } |
1503 | 1159 | ||
@@ -1505,13 +1161,13 @@ setup_window (struct file *file, | |||
1505 | * The video front end needs 4-byte alinged line sizes, we correct that | 1161 | * The video front end needs 4-byte alinged line sizes, we correct that |
1506 | * silently here if necessary | 1162 | * silently here if necessary |
1507 | */ | 1163 | */ |
1508 | if (zr->buffer.depth == 15 || zr->buffer.depth == 16) { | 1164 | if (zr->vbuf_depth == 15 || zr->vbuf_depth == 16) { |
1509 | end = (x + width) & ~1; /* round down */ | 1165 | end = (x + width) & ~1; /* round down */ |
1510 | x = (x + 1) & ~1; /* round up */ | 1166 | x = (x + 1) & ~1; /* round up */ |
1511 | width = end - x; | 1167 | width = end - x; |
1512 | } | 1168 | } |
1513 | 1169 | ||
1514 | if (zr->buffer.depth == 24) { | 1170 | if (zr->vbuf_depth == 24) { |
1515 | end = (x + width) & ~3; /* round down */ | 1171 | end = (x + width) & ~3; /* round down */ |
1516 | x = (x + 3) & ~3; /* round up */ | 1172 | x = (x + 3) & ~3; /* round up */ |
1517 | width = end - x; | 1173 | width = end - x; |
@@ -1527,8 +1183,8 @@ setup_window (struct file *file, | |||
1527 | width > BUZ_MAX_WIDTH || height > BUZ_MAX_HEIGHT) { | 1183 | width > BUZ_MAX_WIDTH || height > BUZ_MAX_HEIGHT) { |
1528 | dprintk(1, | 1184 | dprintk(1, |
1529 | KERN_ERR | 1185 | KERN_ERR |
1530 | "%s: setup_window() - width = %d or height = %d invalid\n", | 1186 | "%s: %s - width = %d or height = %d invalid\n", |
1531 | ZR_DEVNAME(zr), width, height); | 1187 | ZR_DEVNAME(zr), __func__, width, height); |
1532 | return -EINVAL; | 1188 | return -EINVAL; |
1533 | } | 1189 | } |
1534 | 1190 | ||
@@ -1566,20 +1222,20 @@ setup_window (struct file *file, | |||
1566 | } | 1222 | } |
1567 | } else if (clipcount > 0) { | 1223 | } else if (clipcount > 0) { |
1568 | /* write our own bitmap from the clips */ | 1224 | /* write our own bitmap from the clips */ |
1569 | vcp = vmalloc(sizeof(struct video_clip) * (clipcount + 4)); | 1225 | vcp = vmalloc(sizeof(struct v4l2_clip) * (clipcount + 4)); |
1570 | if (vcp == NULL) { | 1226 | if (vcp == NULL) { |
1571 | dprintk(1, | 1227 | dprintk(1, |
1572 | KERN_ERR | 1228 | KERN_ERR |
1573 | "%s: setup_window() - Alloc of clip mask failed\n", | 1229 | "%s: %s - Alloc of clip mask failed\n", |
1574 | ZR_DEVNAME(zr)); | 1230 | ZR_DEVNAME(zr), __func__); |
1575 | return -ENOMEM; | 1231 | return -ENOMEM; |
1576 | } | 1232 | } |
1577 | if (copy_from_user | 1233 | if (copy_from_user |
1578 | (vcp, clips, sizeof(struct video_clip) * clipcount)) { | 1234 | (vcp, clips, sizeof(struct v4l2_clip) * clipcount)) { |
1579 | vfree(vcp); | 1235 | vfree(vcp); |
1580 | return -EFAULT; | 1236 | return -EFAULT; |
1581 | } | 1237 | } |
1582 | write_overlay_mask(file, vcp, clipcount); | 1238 | write_overlay_mask(fh, vcp, clipcount); |
1583 | vfree(vcp); | 1239 | vfree(vcp); |
1584 | } | 1240 | } |
1585 | 1241 | ||
@@ -1595,11 +1251,8 @@ setup_window (struct file *file, | |||
1595 | return wait_grab_pending(zr); | 1251 | return wait_grab_pending(zr); |
1596 | } | 1252 | } |
1597 | 1253 | ||
1598 | static int | 1254 | static int setup_overlay(struct zoran_fh *fh, int on) |
1599 | setup_overlay (struct file *file, | ||
1600 | int on) | ||
1601 | { | 1255 | { |
1602 | struct zoran_fh *fh = file->private_data; | ||
1603 | struct zoran *zr = fh->zr; | 1256 | struct zoran *zr = fh->zr; |
1604 | 1257 | ||
1605 | /* If there is nothing to do, return immediatly */ | 1258 | /* If there is nothing to do, return immediatly */ |
@@ -1612,16 +1265,16 @@ setup_overlay (struct file *file, | |||
1612 | fh->overlay_active == ZORAN_FREE) { | 1265 | fh->overlay_active == ZORAN_FREE) { |
1613 | dprintk(1, | 1266 | dprintk(1, |
1614 | KERN_ERR | 1267 | KERN_ERR |
1615 | "%s: setup_overlay() - overlay is already active for another session\n", | 1268 | "%s: %s - overlay is already active for another session\n", |
1616 | ZR_DEVNAME(zr)); | 1269 | ZR_DEVNAME(zr), __func__); |
1617 | return -EBUSY; | 1270 | return -EBUSY; |
1618 | } | 1271 | } |
1619 | if (!on && zr->overlay_active != ZORAN_FREE && | 1272 | if (!on && zr->overlay_active != ZORAN_FREE && |
1620 | fh->overlay_active == ZORAN_FREE) { | 1273 | fh->overlay_active == ZORAN_FREE) { |
1621 | dprintk(1, | 1274 | dprintk(1, |
1622 | KERN_ERR | 1275 | KERN_ERR |
1623 | "%s: setup_overlay() - you cannot cancel someone else's session\n", | 1276 | "%s: %s - you cannot cancel someone else's session\n", |
1624 | ZR_DEVNAME(zr)); | 1277 | ZR_DEVNAME(zr), __func__); |
1625 | return -EPERM; | 1278 | return -EPERM; |
1626 | } | 1279 | } |
1627 | 1280 | ||
@@ -1634,18 +1287,18 @@ setup_overlay (struct file *file, | |||
1634 | zr36057_overlay(zr, 0); | 1287 | zr36057_overlay(zr, 0); |
1635 | zr->overlay_mask = NULL; | 1288 | zr->overlay_mask = NULL; |
1636 | } else { | 1289 | } else { |
1637 | if (!zr->buffer.base || !fh->overlay_settings.is_set) { | 1290 | if (!zr->vbuf_base || !fh->overlay_settings.is_set) { |
1638 | dprintk(1, | 1291 | dprintk(1, |
1639 | KERN_ERR | 1292 | KERN_ERR |
1640 | "%s: setup_overlay() - buffer or window not set\n", | 1293 | "%s: %s - buffer or window not set\n", |
1641 | ZR_DEVNAME(zr)); | 1294 | ZR_DEVNAME(zr), __func__); |
1642 | return -EINVAL; | 1295 | return -EINVAL; |
1643 | } | 1296 | } |
1644 | if (!fh->overlay_settings.format) { | 1297 | if (!fh->overlay_settings.format) { |
1645 | dprintk(1, | 1298 | dprintk(1, |
1646 | KERN_ERR | 1299 | KERN_ERR |
1647 | "%s: setup_overlay() - no overlay format set\n", | 1300 | "%s: %s - no overlay format set\n", |
1648 | ZR_DEVNAME(zr)); | 1301 | ZR_DEVNAME(zr), __func__); |
1649 | return -EINVAL; | 1302 | return -EINVAL; |
1650 | } | 1303 | } |
1651 | zr->overlay_active = fh->overlay_active = ZORAN_LOCKED; | 1304 | zr->overlay_active = fh->overlay_active = ZORAN_LOCKED; |
@@ -1662,41 +1315,47 @@ setup_overlay (struct file *file, | |||
1662 | return wait_grab_pending(zr); | 1315 | return wait_grab_pending(zr); |
1663 | } | 1316 | } |
1664 | 1317 | ||
1665 | /* get the status of a buffer in the clients buffer queue */ | 1318 | /* get the status of a buffer in the clients buffer queue */ |
1666 | static int | 1319 | static int zoran_v4l2_buffer_status(struct zoran_fh *fh, |
1667 | zoran_v4l2_buffer_status (struct file *file, | 1320 | struct v4l2_buffer *buf, int num) |
1668 | struct v4l2_buffer *buf, | ||
1669 | int num) | ||
1670 | { | 1321 | { |
1671 | struct zoran_fh *fh = file->private_data; | ||
1672 | struct zoran *zr = fh->zr; | 1322 | struct zoran *zr = fh->zr; |
1323 | unsigned long flags; | ||
1673 | 1324 | ||
1674 | buf->flags = V4L2_BUF_FLAG_MAPPED; | 1325 | buf->flags = V4L2_BUF_FLAG_MAPPED; |
1675 | 1326 | ||
1676 | switch (fh->map_mode) { | 1327 | switch (fh->map_mode) { |
1677 | case ZORAN_MAP_MODE_RAW: | 1328 | case ZORAN_MAP_MODE_RAW: |
1678 | |||
1679 | /* check range */ | 1329 | /* check range */ |
1680 | if (num < 0 || num >= fh->v4l_buffers.num_buffers || | 1330 | if (num < 0 || num >= fh->buffers.num_buffers || |
1681 | !fh->v4l_buffers.allocated) { | 1331 | !fh->buffers.allocated) { |
1682 | dprintk(1, | 1332 | dprintk(1, |
1683 | KERN_ERR | 1333 | KERN_ERR |
1684 | "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", | 1334 | "%s: %s - wrong number or buffers not allocated\n", |
1685 | ZR_DEVNAME(zr)); | 1335 | ZR_DEVNAME(zr), __func__); |
1686 | return -EINVAL; | 1336 | return -EINVAL; |
1687 | } | 1337 | } |
1688 | 1338 | ||
1339 | spin_lock_irqsave(&zr->spinlock, flags); | ||
1340 | dprintk(3, | ||
1341 | KERN_DEBUG | ||
1342 | "%s: %s() - raw active=%c, buffer %d: state=%c, map=%c\n", | ||
1343 | ZR_DEVNAME(zr), __func__, | ||
1344 | "FAL"[fh->buffers.active], num, | ||
1345 | "UPMD"[zr->v4l_buffers.buffer[num].state], | ||
1346 | fh->buffers.buffer[num].map ? 'Y' : 'N'); | ||
1347 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
1348 | |||
1689 | buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 1349 | buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
1690 | buf->length = fh->v4l_buffers.buffer_size; | 1350 | buf->length = fh->buffers.buffer_size; |
1691 | 1351 | ||
1692 | /* get buffer */ | 1352 | /* get buffer */ |
1693 | buf->bytesused = fh->v4l_buffers.buffer[num].bs.length; | 1353 | buf->bytesused = fh->buffers.buffer[num].bs.length; |
1694 | if (fh->v4l_buffers.buffer[num].state == BUZ_STATE_DONE || | 1354 | if (fh->buffers.buffer[num].state == BUZ_STATE_DONE || |
1695 | fh->v4l_buffers.buffer[num].state == BUZ_STATE_USER) { | 1355 | fh->buffers.buffer[num].state == BUZ_STATE_USER) { |
1696 | buf->sequence = fh->v4l_buffers.buffer[num].bs.seq; | 1356 | buf->sequence = fh->buffers.buffer[num].bs.seq; |
1697 | buf->flags |= V4L2_BUF_FLAG_DONE; | 1357 | buf->flags |= V4L2_BUF_FLAG_DONE; |
1698 | buf->timestamp = | 1358 | buf->timestamp = fh->buffers.buffer[num].bs.timestamp; |
1699 | fh->v4l_buffers.buffer[num].bs.timestamp; | ||
1700 | } else { | 1359 | } else { |
1701 | buf->flags |= V4L2_BUF_FLAG_QUEUED; | 1360 | buf->flags |= V4L2_BUF_FLAG_QUEUED; |
1702 | } | 1361 | } |
@@ -1712,28 +1371,26 @@ zoran_v4l2_buffer_status (struct file *file, | |||
1712 | case ZORAN_MAP_MODE_JPG_PLAY: | 1371 | case ZORAN_MAP_MODE_JPG_PLAY: |
1713 | 1372 | ||
1714 | /* check range */ | 1373 | /* check range */ |
1715 | if (num < 0 || num >= fh->jpg_buffers.num_buffers || | 1374 | if (num < 0 || num >= fh->buffers.num_buffers || |
1716 | !fh->jpg_buffers.allocated) { | 1375 | !fh->buffers.allocated) { |
1717 | dprintk(1, | 1376 | dprintk(1, |
1718 | KERN_ERR | 1377 | KERN_ERR |
1719 | "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", | 1378 | "%s: %s - wrong number or buffers not allocated\n", |
1720 | ZR_DEVNAME(zr)); | 1379 | ZR_DEVNAME(zr), __func__); |
1721 | return -EINVAL; | 1380 | return -EINVAL; |
1722 | } | 1381 | } |
1723 | 1382 | ||
1724 | buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? | 1383 | buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? |
1725 | V4L2_BUF_TYPE_VIDEO_CAPTURE : | 1384 | V4L2_BUF_TYPE_VIDEO_CAPTURE : |
1726 | V4L2_BUF_TYPE_VIDEO_OUTPUT; | 1385 | V4L2_BUF_TYPE_VIDEO_OUTPUT; |
1727 | buf->length = fh->jpg_buffers.buffer_size; | 1386 | buf->length = fh->buffers.buffer_size; |
1728 | 1387 | ||
1729 | /* these variables are only written after frame has been captured */ | 1388 | /* these variables are only written after frame has been captured */ |
1730 | if (fh->jpg_buffers.buffer[num].state == BUZ_STATE_DONE || | 1389 | if (fh->buffers.buffer[num].state == BUZ_STATE_DONE || |
1731 | fh->jpg_buffers.buffer[num].state == BUZ_STATE_USER) { | 1390 | fh->buffers.buffer[num].state == BUZ_STATE_USER) { |
1732 | buf->sequence = fh->jpg_buffers.buffer[num].bs.seq; | 1391 | buf->sequence = fh->buffers.buffer[num].bs.seq; |
1733 | buf->timestamp = | 1392 | buf->timestamp = fh->buffers.buffer[num].bs.timestamp; |
1734 | fh->jpg_buffers.buffer[num].bs.timestamp; | 1393 | buf->bytesused = fh->buffers.buffer[num].bs.length; |
1735 | buf->bytesused = | ||
1736 | fh->jpg_buffers.buffer[num].bs.length; | ||
1737 | buf->flags |= V4L2_BUF_FLAG_DONE; | 1394 | buf->flags |= V4L2_BUF_FLAG_DONE; |
1738 | } else { | 1395 | } else { |
1739 | buf->flags |= V4L2_BUF_FLAG_QUEUED; | 1396 | buf->flags |= V4L2_BUF_FLAG_QUEUED; |
@@ -1741,14 +1398,11 @@ zoran_v4l2_buffer_status (struct file *file, | |||
1741 | 1398 | ||
1742 | /* which fields are these? */ | 1399 | /* which fields are these? */ |
1743 | if (fh->jpg_settings.TmpDcm != 1) | 1400 | if (fh->jpg_settings.TmpDcm != 1) |
1744 | buf->field = | 1401 | buf->field = fh->jpg_settings.odd_even ? |
1745 | fh->jpg_settings. | 1402 | V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM; |
1746 | odd_even ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM; | ||
1747 | else | 1403 | else |
1748 | buf->field = | 1404 | buf->field = fh->jpg_settings.odd_even ? |
1749 | fh->jpg_settings. | 1405 | V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT; |
1750 | odd_even ? V4L2_FIELD_SEQ_TB : | ||
1751 | V4L2_FIELD_SEQ_BT; | ||
1752 | 1406 | ||
1753 | break; | 1407 | break; |
1754 | 1408 | ||
@@ -1756,8 +1410,8 @@ zoran_v4l2_buffer_status (struct file *file, | |||
1756 | 1410 | ||
1757 | dprintk(5, | 1411 | dprintk(5, |
1758 | KERN_ERR | 1412 | KERN_ERR |
1759 | "%s: v4l2_buffer_status() - invalid buffer type|map_mode (%d|%d)\n", | 1413 | "%s: %s - invalid buffer type|map_mode (%d|%d)\n", |
1760 | ZR_DEVNAME(zr), buf->type, fh->map_mode); | 1414 | ZR_DEVNAME(zr), __func__, buf->type, fh->map_mode); |
1761 | return -EINVAL; | 1415 | return -EINVAL; |
1762 | } | 1416 | } |
1763 | 1417 | ||
@@ -1770,81 +1424,55 @@ zoran_v4l2_buffer_status (struct file *file, | |||
1770 | 1424 | ||
1771 | static int | 1425 | static int |
1772 | zoran_set_norm (struct zoran *zr, | 1426 | zoran_set_norm (struct zoran *zr, |
1773 | int norm) /* VIDEO_MODE_* */ | 1427 | v4l2_std_id norm) |
1774 | { | 1428 | { |
1775 | int norm_encoder, on; | 1429 | int on; |
1776 | 1430 | ||
1777 | if (zr->v4l_buffers.active != ZORAN_FREE || | 1431 | if (zr->v4l_buffers.active != ZORAN_FREE || |
1778 | zr->jpg_buffers.active != ZORAN_FREE) { | 1432 | zr->jpg_buffers.active != ZORAN_FREE) { |
1779 | dprintk(1, | 1433 | dprintk(1, |
1780 | KERN_WARNING | 1434 | KERN_WARNING |
1781 | "%s: set_norm() called while in playback/capture mode\n", | 1435 | "%s: %s called while in playback/capture mode\n", |
1782 | ZR_DEVNAME(zr)); | 1436 | ZR_DEVNAME(zr), __func__); |
1783 | return -EBUSY; | 1437 | return -EBUSY; |
1784 | } | 1438 | } |
1785 | 1439 | ||
1786 | if (lock_norm && norm != zr->norm) { | 1440 | if (!(norm & zr->card.norms)) { |
1787 | if (lock_norm > 1) { | ||
1788 | dprintk(1, | ||
1789 | KERN_WARNING | ||
1790 | "%s: set_norm() - TV standard is locked, can not switch norm\n", | ||
1791 | ZR_DEVNAME(zr)); | ||
1792 | return -EPERM; | ||
1793 | } else { | ||
1794 | dprintk(1, | ||
1795 | KERN_WARNING | ||
1796 | "%s: set_norm() - TV standard is locked, norm was not changed\n", | ||
1797 | ZR_DEVNAME(zr)); | ||
1798 | norm = zr->norm; | ||
1799 | } | ||
1800 | } | ||
1801 | |||
1802 | if (norm != VIDEO_MODE_AUTO && | ||
1803 | (norm < 0 || norm >= zr->card.norms || | ||
1804 | !zr->card.tvn[norm])) { | ||
1805 | dprintk(1, | 1441 | dprintk(1, |
1806 | KERN_ERR "%s: set_norm() - unsupported norm %d\n", | 1442 | KERN_ERR "%s: %s - unsupported norm %llx\n", |
1807 | ZR_DEVNAME(zr), norm); | 1443 | ZR_DEVNAME(zr), __func__, norm); |
1808 | return -EINVAL; | 1444 | return -EINVAL; |
1809 | } | 1445 | } |
1810 | 1446 | ||
1811 | if (norm == VIDEO_MODE_AUTO) { | 1447 | if (norm == V4L2_STD_ALL) { |
1812 | int status; | 1448 | int status = 0; |
1449 | v4l2_std_id std = 0; | ||
1813 | 1450 | ||
1814 | /* if we have autodetect, ... */ | 1451 | decoder_call(zr, video, querystd, &std); |
1815 | struct video_decoder_capability caps; | 1452 | decoder_call(zr, tuner, s_std, std); |
1816 | decoder_command(zr, DECODER_GET_CAPABILITIES, &caps); | ||
1817 | if (!(caps.flags & VIDEO_DECODER_AUTO)) { | ||
1818 | dprintk(1, KERN_ERR "%s: norm=auto unsupported\n", | ||
1819 | ZR_DEVNAME(zr)); | ||
1820 | return -EINVAL; | ||
1821 | } | ||
1822 | |||
1823 | decoder_command(zr, DECODER_SET_NORM, &norm); | ||
1824 | 1453 | ||
1825 | /* let changes come into effect */ | 1454 | /* let changes come into effect */ |
1826 | ssleep(2); | 1455 | ssleep(2); |
1827 | 1456 | ||
1828 | decoder_command(zr, DECODER_GET_STATUS, &status); | 1457 | decoder_call(zr, video, g_input_status, &status); |
1829 | if (!(status & DECODER_STATUS_GOOD)) { | 1458 | if (status & V4L2_IN_ST_NO_SIGNAL) { |
1830 | dprintk(1, | 1459 | dprintk(1, |
1831 | KERN_ERR | 1460 | KERN_ERR |
1832 | "%s: set_norm() - no norm detected\n", | 1461 | "%s: %s - no norm detected\n", |
1833 | ZR_DEVNAME(zr)); | 1462 | ZR_DEVNAME(zr), __func__); |
1834 | /* reset norm */ | 1463 | /* reset norm */ |
1835 | decoder_command(zr, DECODER_SET_NORM, &zr->norm); | 1464 | decoder_call(zr, tuner, s_std, zr->norm); |
1836 | return -EIO; | 1465 | return -EIO; |
1837 | } | 1466 | } |
1838 | 1467 | ||
1839 | if (status & DECODER_STATUS_NTSC) | 1468 | norm = std; |
1840 | norm = VIDEO_MODE_NTSC; | ||
1841 | else if (status & DECODER_STATUS_SECAM) | ||
1842 | norm = VIDEO_MODE_SECAM; | ||
1843 | else | ||
1844 | norm = VIDEO_MODE_PAL; | ||
1845 | } | 1469 | } |
1846 | zr->timing = zr->card.tvn[norm]; | 1470 | if (norm & V4L2_STD_SECAM) |
1847 | norm_encoder = norm; | 1471 | zr->timing = zr->card.tvn[2]; |
1472 | else if (norm & V4L2_STD_NTSC) | ||
1473 | zr->timing = zr->card.tvn[1]; | ||
1474 | else | ||
1475 | zr->timing = zr->card.tvn[0]; | ||
1848 | 1476 | ||
1849 | /* We switch overlay off and on since a change in the | 1477 | /* We switch overlay off and on since a change in the |
1850 | * norm needs different VFE settings */ | 1478 | * norm needs different VFE settings */ |
@@ -1852,8 +1480,8 @@ zoran_set_norm (struct zoran *zr, | |||
1852 | if (on) | 1480 | if (on) |
1853 | zr36057_overlay(zr, 0); | 1481 | zr36057_overlay(zr, 0); |
1854 | 1482 | ||
1855 | decoder_command(zr, DECODER_SET_NORM, &norm); | 1483 | decoder_call(zr, tuner, s_std, norm); |
1856 | encoder_command(zr, ENCODER_SET_NORM, &norm_encoder); | 1484 | encoder_call(zr, video, s_std_output, norm); |
1857 | 1485 | ||
1858 | if (on) | 1486 | if (on) |
1859 | zr36057_overlay(zr, 1); | 1487 | zr36057_overlay(zr, 1); |
@@ -1868,7 +1496,7 @@ static int | |||
1868 | zoran_set_input (struct zoran *zr, | 1496 | zoran_set_input (struct zoran *zr, |
1869 | int input) | 1497 | int input) |
1870 | { | 1498 | { |
1871 | int realinput; | 1499 | struct v4l2_routing route = { 0, 0 }; |
1872 | 1500 | ||
1873 | if (input == zr->input) { | 1501 | if (input == zr->input) { |
1874 | return 0; | 1502 | return 0; |
@@ -1878,23 +1506,23 @@ zoran_set_input (struct zoran *zr, | |||
1878 | zr->jpg_buffers.active != ZORAN_FREE) { | 1506 | zr->jpg_buffers.active != ZORAN_FREE) { |
1879 | dprintk(1, | 1507 | dprintk(1, |
1880 | KERN_WARNING | 1508 | KERN_WARNING |
1881 | "%s: set_input() called while in playback/capture mode\n", | 1509 | "%s: %s called while in playback/capture mode\n", |
1882 | ZR_DEVNAME(zr)); | 1510 | ZR_DEVNAME(zr), __func__); |
1883 | return -EBUSY; | 1511 | return -EBUSY; |
1884 | } | 1512 | } |
1885 | 1513 | ||
1886 | if (input < 0 || input >= zr->card.inputs) { | 1514 | if (input < 0 || input >= zr->card.inputs) { |
1887 | dprintk(1, | 1515 | dprintk(1, |
1888 | KERN_ERR | 1516 | KERN_ERR |
1889 | "%s: set_input() - unnsupported input %d\n", | 1517 | "%s: %s - unnsupported input %d\n", |
1890 | ZR_DEVNAME(zr), input); | 1518 | ZR_DEVNAME(zr), __func__, input); |
1891 | return -EINVAL; | 1519 | return -EINVAL; |
1892 | } | 1520 | } |
1893 | 1521 | ||
1894 | realinput = zr->card.input[input].muxsel; | 1522 | route.input = zr->card.input[input].muxsel; |
1895 | zr->input = input; | 1523 | zr->input = input; |
1896 | 1524 | ||
1897 | decoder_command(zr, DECODER_SET_INPUT, &realinput); | 1525 | decoder_call(zr, video, s_routing, &route); |
1898 | 1526 | ||
1899 | return 0; | 1527 | return 0; |
1900 | } | 1528 | } |
@@ -1903,410 +1531,14 @@ zoran_set_input (struct zoran *zr, | |||
1903 | * ioctl routine | 1531 | * ioctl routine |
1904 | */ | 1532 | */ |
1905 | 1533 | ||
1906 | static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | 1534 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
1535 | static long zoran_default(struct file *file, void *__fh, int cmd, void *arg) | ||
1907 | { | 1536 | { |
1908 | struct zoran_fh *fh = file->private_data; | 1537 | struct zoran_fh *fh = __fh; |
1909 | struct zoran *zr = fh->zr; | 1538 | struct zoran *zr = fh->zr; |
1910 | /* CAREFUL: used in multiple places here */ | ||
1911 | struct zoran_jpg_settings settings; | 1539 | struct zoran_jpg_settings settings; |
1912 | 1540 | ||
1913 | /* we might have older buffers lying around... We don't want | ||
1914 | * to wait, but we do want to try cleaning them up ASAP. So | ||
1915 | * we try to obtain the lock and free them. If that fails, we | ||
1916 | * don't do anything and wait for the next turn. In the end, | ||
1917 | * zoran_close() or a new allocation will still free them... | ||
1918 | * This is just a 'the sooner the better' extra 'feature' | ||
1919 | * | ||
1920 | * We don't free the buffers right on munmap() because that | ||
1921 | * causes oopses (kfree() inside munmap() oopses for no | ||
1922 | * apparent reason - it's also not reproduceable in any way, | ||
1923 | * but moving the free code outside the munmap() handler fixes | ||
1924 | * all this... If someone knows why, please explain me (Ronald) | ||
1925 | */ | ||
1926 | if (mutex_trylock(&zr->resource_lock)) { | ||
1927 | /* we obtained it! Let's try to free some things */ | ||
1928 | if (fh->jpg_buffers.ready_to_be_freed) | ||
1929 | jpg_fbuffer_free(file); | ||
1930 | if (fh->v4l_buffers.ready_to_be_freed) | ||
1931 | v4l_fbuffer_free(file); | ||
1932 | |||
1933 | mutex_unlock(&zr->resource_lock); | ||
1934 | } | ||
1935 | |||
1936 | switch (cmd) { | 1541 | switch (cmd) { |
1937 | |||
1938 | case VIDIOCGCAP: | ||
1939 | { | ||
1940 | struct video_capability *vcap = arg; | ||
1941 | |||
1942 | dprintk(3, KERN_DEBUG "%s: VIDIOCGCAP\n", ZR_DEVNAME(zr)); | ||
1943 | |||
1944 | memset(vcap, 0, sizeof(struct video_capability)); | ||
1945 | strncpy(vcap->name, ZR_DEVNAME(zr), sizeof(vcap->name)-1); | ||
1946 | vcap->type = ZORAN_VID_TYPE; | ||
1947 | |||
1948 | vcap->channels = zr->card.inputs; | ||
1949 | vcap->audios = 0; | ||
1950 | mutex_lock(&zr->resource_lock); | ||
1951 | vcap->maxwidth = BUZ_MAX_WIDTH; | ||
1952 | vcap->maxheight = BUZ_MAX_HEIGHT; | ||
1953 | vcap->minwidth = BUZ_MIN_WIDTH; | ||
1954 | vcap->minheight = BUZ_MIN_HEIGHT; | ||
1955 | mutex_unlock(&zr->resource_lock); | ||
1956 | |||
1957 | return 0; | ||
1958 | } | ||
1959 | break; | ||
1960 | |||
1961 | case VIDIOCGCHAN: | ||
1962 | { | ||
1963 | struct video_channel *vchan = arg; | ||
1964 | int channel = vchan->channel; | ||
1965 | |||
1966 | dprintk(3, KERN_DEBUG "%s: VIDIOCGCHAN - channel=%d\n", | ||
1967 | ZR_DEVNAME(zr), vchan->channel); | ||
1968 | |||
1969 | memset(vchan, 0, sizeof(struct video_channel)); | ||
1970 | if (channel > zr->card.inputs || channel < 0) { | ||
1971 | dprintk(1, | ||
1972 | KERN_ERR | ||
1973 | "%s: VIDIOCGCHAN on not existing channel %d\n", | ||
1974 | ZR_DEVNAME(zr), channel); | ||
1975 | return -EINVAL; | ||
1976 | } | ||
1977 | |||
1978 | strcpy(vchan->name, zr->card.input[channel].name); | ||
1979 | |||
1980 | vchan->tuners = 0; | ||
1981 | vchan->flags = 0; | ||
1982 | vchan->type = VIDEO_TYPE_CAMERA; | ||
1983 | mutex_lock(&zr->resource_lock); | ||
1984 | vchan->norm = zr->norm; | ||
1985 | mutex_unlock(&zr->resource_lock); | ||
1986 | vchan->channel = channel; | ||
1987 | |||
1988 | return 0; | ||
1989 | } | ||
1990 | break; | ||
1991 | |||
1992 | /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says: | ||
1993 | * | ||
1994 | * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input." | ||
1995 | * * ^^^^^^^ | ||
1996 | * * The famos BTTV driver has it implemented with a struct video_channel argument | ||
1997 | * * and we follow it for compatibility reasons | ||
1998 | * * | ||
1999 | * * BTW: this is the only way the user can set the norm! | ||
2000 | */ | ||
2001 | |||
2002 | case VIDIOCSCHAN: | ||
2003 | { | ||
2004 | struct video_channel *vchan = arg; | ||
2005 | int res; | ||
2006 | |||
2007 | dprintk(3, | ||
2008 | KERN_DEBUG | ||
2009 | "%s: VIDIOCSCHAN - channel=%d, norm=%d\n", | ||
2010 | ZR_DEVNAME(zr), vchan->channel, vchan->norm); | ||
2011 | |||
2012 | mutex_lock(&zr->resource_lock); | ||
2013 | if ((res = zoran_set_input(zr, vchan->channel))) | ||
2014 | goto schan_unlock_and_return; | ||
2015 | if ((res = zoran_set_norm(zr, vchan->norm))) | ||
2016 | goto schan_unlock_and_return; | ||
2017 | |||
2018 | /* Make sure the changes come into effect */ | ||
2019 | res = wait_grab_pending(zr); | ||
2020 | schan_unlock_and_return: | ||
2021 | mutex_unlock(&zr->resource_lock); | ||
2022 | return res; | ||
2023 | } | ||
2024 | break; | ||
2025 | |||
2026 | case VIDIOCGPICT: | ||
2027 | { | ||
2028 | struct video_picture *vpict = arg; | ||
2029 | |||
2030 | dprintk(3, KERN_DEBUG "%s: VIDIOCGPICT\n", ZR_DEVNAME(zr)); | ||
2031 | |||
2032 | memset(vpict, 0, sizeof(struct video_picture)); | ||
2033 | mutex_lock(&zr->resource_lock); | ||
2034 | vpict->hue = zr->hue; | ||
2035 | vpict->brightness = zr->brightness; | ||
2036 | vpict->contrast = zr->contrast; | ||
2037 | vpict->colour = zr->saturation; | ||
2038 | if (fh->overlay_settings.format) { | ||
2039 | vpict->depth = fh->overlay_settings.format->depth; | ||
2040 | vpict->palette = fh->overlay_settings.format->palette; | ||
2041 | } else { | ||
2042 | vpict->depth = 0; | ||
2043 | } | ||
2044 | mutex_unlock(&zr->resource_lock); | ||
2045 | |||
2046 | return 0; | ||
2047 | } | ||
2048 | break; | ||
2049 | |||
2050 | case VIDIOCSPICT: | ||
2051 | { | ||
2052 | struct video_picture *vpict = arg; | ||
2053 | int i; | ||
2054 | |||
2055 | dprintk(3, | ||
2056 | KERN_DEBUG | ||
2057 | "%s: VIDIOCSPICT - bri=%d, hue=%d, col=%d, con=%d, dep=%d, pal=%d\n", | ||
2058 | ZR_DEVNAME(zr), vpict->brightness, vpict->hue, | ||
2059 | vpict->colour, vpict->contrast, vpict->depth, | ||
2060 | vpict->palette); | ||
2061 | |||
2062 | for (i = 0; i < NUM_FORMATS; i++) { | ||
2063 | const struct zoran_format *fmt = &zoran_formats[i]; | ||
2064 | |||
2065 | if (fmt->palette != -1 && | ||
2066 | fmt->flags & ZORAN_FORMAT_OVERLAY && | ||
2067 | fmt->palette == vpict->palette && | ||
2068 | fmt->depth == vpict->depth) | ||
2069 | break; | ||
2070 | } | ||
2071 | if (i == NUM_FORMATS) { | ||
2072 | dprintk(1, | ||
2073 | KERN_ERR | ||
2074 | "%s: VIDIOCSPICT - Invalid palette %d\n", | ||
2075 | ZR_DEVNAME(zr), vpict->palette); | ||
2076 | return -EINVAL; | ||
2077 | } | ||
2078 | |||
2079 | mutex_lock(&zr->resource_lock); | ||
2080 | |||
2081 | decoder_command(zr, DECODER_SET_PICTURE, vpict); | ||
2082 | |||
2083 | zr->hue = vpict->hue; | ||
2084 | zr->contrast = vpict->contrast; | ||
2085 | zr->saturation = vpict->colour; | ||
2086 | zr->brightness = vpict->brightness; | ||
2087 | |||
2088 | fh->overlay_settings.format = &zoran_formats[i]; | ||
2089 | |||
2090 | mutex_unlock(&zr->resource_lock); | ||
2091 | |||
2092 | return 0; | ||
2093 | } | ||
2094 | break; | ||
2095 | |||
2096 | case VIDIOCCAPTURE: | ||
2097 | { | ||
2098 | int *on = arg, res; | ||
2099 | |||
2100 | dprintk(3, KERN_DEBUG "%s: VIDIOCCAPTURE - on=%d\n", | ||
2101 | ZR_DEVNAME(zr), *on); | ||
2102 | |||
2103 | mutex_lock(&zr->resource_lock); | ||
2104 | res = setup_overlay(file, *on); | ||
2105 | mutex_unlock(&zr->resource_lock); | ||
2106 | |||
2107 | return res; | ||
2108 | } | ||
2109 | break; | ||
2110 | |||
2111 | case VIDIOCGWIN: | ||
2112 | { | ||
2113 | struct video_window *vwin = arg; | ||
2114 | |||
2115 | dprintk(3, KERN_DEBUG "%s: VIDIOCGWIN\n", ZR_DEVNAME(zr)); | ||
2116 | |||
2117 | memset(vwin, 0, sizeof(struct video_window)); | ||
2118 | mutex_lock(&zr->resource_lock); | ||
2119 | vwin->x = fh->overlay_settings.x; | ||
2120 | vwin->y = fh->overlay_settings.y; | ||
2121 | vwin->width = fh->overlay_settings.width; | ||
2122 | vwin->height = fh->overlay_settings.height; | ||
2123 | mutex_unlock(&zr->resource_lock); | ||
2124 | vwin->clipcount = 0; | ||
2125 | return 0; | ||
2126 | } | ||
2127 | break; | ||
2128 | |||
2129 | case VIDIOCSWIN: | ||
2130 | { | ||
2131 | struct video_window *vwin = arg; | ||
2132 | int res; | ||
2133 | |||
2134 | dprintk(3, | ||
2135 | KERN_DEBUG | ||
2136 | "%s: VIDIOCSWIN - x=%d, y=%d, w=%d, h=%d, clipcount=%d\n", | ||
2137 | ZR_DEVNAME(zr), vwin->x, vwin->y, vwin->width, | ||
2138 | vwin->height, vwin->clipcount); | ||
2139 | |||
2140 | mutex_lock(&zr->resource_lock); | ||
2141 | res = | ||
2142 | setup_window(file, vwin->x, vwin->y, vwin->width, | ||
2143 | vwin->height, vwin->clips, | ||
2144 | vwin->clipcount, NULL); | ||
2145 | mutex_unlock(&zr->resource_lock); | ||
2146 | |||
2147 | return res; | ||
2148 | } | ||
2149 | break; | ||
2150 | |||
2151 | case VIDIOCGFBUF: | ||
2152 | { | ||
2153 | struct video_buffer *vbuf = arg; | ||
2154 | |||
2155 | dprintk(3, KERN_DEBUG "%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr)); | ||
2156 | |||
2157 | mutex_lock(&zr->resource_lock); | ||
2158 | *vbuf = zr->buffer; | ||
2159 | mutex_unlock(&zr->resource_lock); | ||
2160 | return 0; | ||
2161 | } | ||
2162 | break; | ||
2163 | |||
2164 | case VIDIOCSFBUF: | ||
2165 | { | ||
2166 | struct video_buffer *vbuf = arg; | ||
2167 | int i, res = 0; | ||
2168 | |||
2169 | dprintk(3, | ||
2170 | KERN_DEBUG | ||
2171 | "%s: VIDIOCSFBUF - base=%p, w=%d, h=%d, depth=%d, bpl=%d\n", | ||
2172 | ZR_DEVNAME(zr), vbuf->base, vbuf->width, | ||
2173 | vbuf->height, vbuf->depth, vbuf->bytesperline); | ||
2174 | |||
2175 | for (i = 0; i < NUM_FORMATS; i++) | ||
2176 | if (zoran_formats[i].depth == vbuf->depth) | ||
2177 | break; | ||
2178 | if (i == NUM_FORMATS) { | ||
2179 | dprintk(1, | ||
2180 | KERN_ERR | ||
2181 | "%s: VIDIOCSFBUF - invalid fbuf depth %d\n", | ||
2182 | ZR_DEVNAME(zr), vbuf->depth); | ||
2183 | return -EINVAL; | ||
2184 | } | ||
2185 | |||
2186 | mutex_lock(&zr->resource_lock); | ||
2187 | res = | ||
2188 | setup_fbuffer(file, vbuf->base, &zoran_formats[i], | ||
2189 | vbuf->width, vbuf->height, | ||
2190 | vbuf->bytesperline); | ||
2191 | mutex_unlock(&zr->resource_lock); | ||
2192 | |||
2193 | return res; | ||
2194 | } | ||
2195 | break; | ||
2196 | |||
2197 | case VIDIOCSYNC: | ||
2198 | { | ||
2199 | int *frame = arg, res; | ||
2200 | |||
2201 | dprintk(3, KERN_DEBUG "%s: VIDIOCSYNC - frame=%d\n", | ||
2202 | ZR_DEVNAME(zr), *frame); | ||
2203 | |||
2204 | mutex_lock(&zr->resource_lock); | ||
2205 | res = v4l_sync(file, *frame); | ||
2206 | mutex_unlock(&zr->resource_lock); | ||
2207 | if (!res) | ||
2208 | zr->v4l_sync_tail++; | ||
2209 | return res; | ||
2210 | } | ||
2211 | break; | ||
2212 | |||
2213 | case VIDIOCMCAPTURE: | ||
2214 | { | ||
2215 | struct video_mmap *vmap = arg; | ||
2216 | int res; | ||
2217 | |||
2218 | dprintk(3, | ||
2219 | KERN_DEBUG | ||
2220 | "%s: VIDIOCMCAPTURE - frame=%d, geom=%dx%d, fmt=%d\n", | ||
2221 | ZR_DEVNAME(zr), vmap->frame, vmap->width, vmap->height, | ||
2222 | vmap->format); | ||
2223 | |||
2224 | mutex_lock(&zr->resource_lock); | ||
2225 | res = v4l_grab(file, vmap); | ||
2226 | mutex_unlock(&zr->resource_lock); | ||
2227 | return res; | ||
2228 | } | ||
2229 | break; | ||
2230 | |||
2231 | case VIDIOCGMBUF: | ||
2232 | { | ||
2233 | struct video_mbuf *vmbuf = arg; | ||
2234 | int i, res = 0; | ||
2235 | |||
2236 | dprintk(3, KERN_DEBUG "%s: VIDIOCGMBUF\n", ZR_DEVNAME(zr)); | ||
2237 | |||
2238 | vmbuf->size = | ||
2239 | fh->v4l_buffers.num_buffers * | ||
2240 | fh->v4l_buffers.buffer_size; | ||
2241 | vmbuf->frames = fh->v4l_buffers.num_buffers; | ||
2242 | for (i = 0; i < vmbuf->frames; i++) { | ||
2243 | vmbuf->offsets[i] = | ||
2244 | i * fh->v4l_buffers.buffer_size; | ||
2245 | } | ||
2246 | |||
2247 | mutex_lock(&zr->resource_lock); | ||
2248 | |||
2249 | if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { | ||
2250 | dprintk(1, | ||
2251 | KERN_ERR | ||
2252 | "%s: VIDIOCGMBUF - buffers already allocated\n", | ||
2253 | ZR_DEVNAME(zr)); | ||
2254 | res = -EINVAL; | ||
2255 | goto v4l1reqbuf_unlock_and_return; | ||
2256 | } | ||
2257 | |||
2258 | if (v4l_fbuffer_alloc(file)) { | ||
2259 | res = -ENOMEM; | ||
2260 | goto v4l1reqbuf_unlock_and_return; | ||
2261 | } | ||
2262 | |||
2263 | /* The next mmap will map the V4L buffers */ | ||
2264 | fh->map_mode = ZORAN_MAP_MODE_RAW; | ||
2265 | v4l1reqbuf_unlock_and_return: | ||
2266 | mutex_unlock(&zr->resource_lock); | ||
2267 | |||
2268 | return res; | ||
2269 | } | ||
2270 | break; | ||
2271 | |||
2272 | case VIDIOCGUNIT: | ||
2273 | { | ||
2274 | struct video_unit *vunit = arg; | ||
2275 | |||
2276 | dprintk(3, KERN_DEBUG "%s: VIDIOCGUNIT\n", ZR_DEVNAME(zr)); | ||
2277 | |||
2278 | vunit->video = zr->video_dev->minor; | ||
2279 | vunit->vbi = VIDEO_NO_UNIT; | ||
2280 | vunit->radio = VIDEO_NO_UNIT; | ||
2281 | vunit->audio = VIDEO_NO_UNIT; | ||
2282 | vunit->teletext = VIDEO_NO_UNIT; | ||
2283 | |||
2284 | return 0; | ||
2285 | } | ||
2286 | break; | ||
2287 | |||
2288 | /* | ||
2289 | * RJ: In principal we could support subcaptures for V4L grabbing. | ||
2290 | * Not even the famous BTTV driver has them, however. | ||
2291 | * If there should be a strong demand, one could consider | ||
2292 | * to implement them. | ||
2293 | */ | ||
2294 | case VIDIOCGCAPTURE: | ||
2295 | { | ||
2296 | dprintk(3, KERN_ERR "%s: VIDIOCGCAPTURE not supported\n", | ||
2297 | ZR_DEVNAME(zr)); | ||
2298 | return -EINVAL; | ||
2299 | } | ||
2300 | break; | ||
2301 | |||
2302 | case VIDIOCSCAPTURE: | ||
2303 | { | ||
2304 | dprintk(3, KERN_ERR "%s: VIDIOCSCAPTURE not supported\n", | ||
2305 | ZR_DEVNAME(zr)); | ||
2306 | return -EINVAL; | ||
2307 | } | ||
2308 | break; | ||
2309 | |||
2310 | case BUZIOC_G_PARAMS: | 1542 | case BUZIOC_G_PARAMS: |
2311 | { | 1543 | { |
2312 | struct zoran_params *bparams = arg; | 1544 | struct zoran_params *bparams = arg; |
@@ -2319,7 +1551,13 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2319 | 1551 | ||
2320 | mutex_lock(&zr->resource_lock); | 1552 | mutex_lock(&zr->resource_lock); |
2321 | 1553 | ||
2322 | bparams->norm = zr->norm; | 1554 | if (zr->norm & V4L2_STD_NTSC) |
1555 | bparams->norm = VIDEO_MODE_NTSC; | ||
1556 | else if (zr->norm & V4L2_STD_PAL) | ||
1557 | bparams->norm = VIDEO_MODE_PAL; | ||
1558 | else | ||
1559 | bparams->norm = VIDEO_MODE_SECAM; | ||
1560 | |||
2323 | bparams->input = zr->input; | 1561 | bparams->input = zr->input; |
2324 | 1562 | ||
2325 | bparams->decimation = fh->jpg_settings.decimation; | 1563 | bparams->decimation = fh->jpg_settings.decimation; |
@@ -2352,7 +1590,6 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2352 | 1590 | ||
2353 | return 0; | 1591 | return 0; |
2354 | } | 1592 | } |
2355 | break; | ||
2356 | 1593 | ||
2357 | case BUZIOC_S_PARAMS: | 1594 | case BUZIOC_S_PARAMS: |
2358 | { | 1595 | { |
@@ -2395,18 +1632,17 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2395 | 1632 | ||
2396 | /* Check the params first before overwriting our | 1633 | /* Check the params first before overwriting our |
2397 | * nternal values */ | 1634 | * nternal values */ |
2398 | if (zoran_check_jpg_settings(zr, &settings)) { | 1635 | if (zoran_check_jpg_settings(zr, &settings, 0)) { |
2399 | res = -EINVAL; | 1636 | res = -EINVAL; |
2400 | goto sparams_unlock_and_return; | 1637 | goto sparams_unlock_and_return; |
2401 | } | 1638 | } |
2402 | 1639 | ||
2403 | fh->jpg_settings = settings; | 1640 | fh->jpg_settings = settings; |
2404 | sparams_unlock_and_return: | 1641 | sparams_unlock_and_return: |
2405 | mutex_unlock(&zr->resource_lock); | 1642 | mutex_unlock(&zr->resource_lock); |
2406 | 1643 | ||
2407 | return res; | 1644 | return res; |
2408 | } | 1645 | } |
2409 | break; | ||
2410 | 1646 | ||
2411 | case BUZIOC_REQBUFS: | 1647 | case BUZIOC_REQBUFS: |
2412 | { | 1648 | { |
@@ -2430,38 +1666,34 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2430 | * tables to a Maximum of 2 MB */ | 1666 | * tables to a Maximum of 2 MB */ |
2431 | if (breq->size > jpg_bufsize) | 1667 | if (breq->size > jpg_bufsize) |
2432 | breq->size = jpg_bufsize; | 1668 | breq->size = jpg_bufsize; |
2433 | if (fh->jpg_buffers.need_contiguous && | ||
2434 | breq->size > MAX_KMALLOC_MEM) | ||
2435 | breq->size = MAX_KMALLOC_MEM; | ||
2436 | 1669 | ||
2437 | mutex_lock(&zr->resource_lock); | 1670 | mutex_lock(&zr->resource_lock); |
2438 | 1671 | ||
2439 | if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { | 1672 | if (fh->buffers.allocated) { |
2440 | dprintk(1, | 1673 | dprintk(1, |
2441 | KERN_ERR | 1674 | KERN_ERR |
2442 | "%s: BUZIOC_REQBUFS - buffers allready allocated\n", | 1675 | "%s: BUZIOC_REQBUFS - buffers already allocated\n", |
2443 | ZR_DEVNAME(zr)); | 1676 | ZR_DEVNAME(zr)); |
2444 | res = -EBUSY; | 1677 | res = -EBUSY; |
2445 | goto jpgreqbuf_unlock_and_return; | 1678 | goto jpgreqbuf_unlock_and_return; |
2446 | } | 1679 | } |
2447 | 1680 | ||
2448 | fh->jpg_buffers.num_buffers = breq->count; | 1681 | /* The next mmap will map the MJPEG buffers - could |
2449 | fh->jpg_buffers.buffer_size = breq->size; | 1682 | * also be *_PLAY, but it doesn't matter here */ |
1683 | map_mode_jpg(fh, 0); | ||
1684 | fh->buffers.num_buffers = breq->count; | ||
1685 | fh->buffers.buffer_size = breq->size; | ||
2450 | 1686 | ||
2451 | if (jpg_fbuffer_alloc(file)) { | 1687 | if (jpg_fbuffer_alloc(fh)) { |
2452 | res = -ENOMEM; | 1688 | res = -ENOMEM; |
2453 | goto jpgreqbuf_unlock_and_return; | 1689 | goto jpgreqbuf_unlock_and_return; |
2454 | } | 1690 | } |
2455 | 1691 | ||
2456 | /* The next mmap will map the MJPEG buffers - could | 1692 | jpgreqbuf_unlock_and_return: |
2457 | * also be *_PLAY, but it doesn't matter here */ | ||
2458 | fh->map_mode = ZORAN_MAP_MODE_JPG_REC; | ||
2459 | jpgreqbuf_unlock_and_return: | ||
2460 | mutex_unlock(&zr->resource_lock); | 1693 | mutex_unlock(&zr->resource_lock); |
2461 | 1694 | ||
2462 | return res; | 1695 | return res; |
2463 | } | 1696 | } |
2464 | break; | ||
2465 | 1697 | ||
2466 | case BUZIOC_QBUF_CAPT: | 1698 | case BUZIOC_QBUF_CAPT: |
2467 | { | 1699 | { |
@@ -2471,12 +1703,11 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2471 | ZR_DEVNAME(zr), *frame); | 1703 | ZR_DEVNAME(zr), *frame); |
2472 | 1704 | ||
2473 | mutex_lock(&zr->resource_lock); | 1705 | mutex_lock(&zr->resource_lock); |
2474 | res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS); | 1706 | res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_COMPRESS); |
2475 | mutex_unlock(&zr->resource_lock); | 1707 | mutex_unlock(&zr->resource_lock); |
2476 | 1708 | ||
2477 | return res; | 1709 | return res; |
2478 | } | 1710 | } |
2479 | break; | ||
2480 | 1711 | ||
2481 | case BUZIOC_QBUF_PLAY: | 1712 | case BUZIOC_QBUF_PLAY: |
2482 | { | 1713 | { |
@@ -2486,12 +1717,11 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2486 | ZR_DEVNAME(zr), *frame); | 1717 | ZR_DEVNAME(zr), *frame); |
2487 | 1718 | ||
2488 | mutex_lock(&zr->resource_lock); | 1719 | mutex_lock(&zr->resource_lock); |
2489 | res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS); | 1720 | res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_DECOMPRESS); |
2490 | mutex_unlock(&zr->resource_lock); | 1721 | mutex_unlock(&zr->resource_lock); |
2491 | 1722 | ||
2492 | return res; | 1723 | return res; |
2493 | } | 1724 | } |
2494 | break; | ||
2495 | 1725 | ||
2496 | case BUZIOC_SYNC: | 1726 | case BUZIOC_SYNC: |
2497 | { | 1727 | { |
@@ -2501,17 +1731,26 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2501 | dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr)); | 1731 | dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr)); |
2502 | 1732 | ||
2503 | mutex_lock(&zr->resource_lock); | 1733 | mutex_lock(&zr->resource_lock); |
2504 | res = jpg_sync(file, bsync); | 1734 | |
1735 | if (fh->map_mode == ZORAN_MAP_MODE_RAW) { | ||
1736 | dprintk(2, KERN_WARNING | ||
1737 | "%s: %s - not in jpg capture mode\n", | ||
1738 | ZR_DEVNAME(zr), __func__); | ||
1739 | res = -EINVAL; | ||
1740 | } else { | ||
1741 | res = jpg_sync(fh, bsync); | ||
1742 | } | ||
2505 | mutex_unlock(&zr->resource_lock); | 1743 | mutex_unlock(&zr->resource_lock); |
2506 | 1744 | ||
2507 | return res; | 1745 | return res; |
2508 | } | 1746 | } |
2509 | break; | ||
2510 | 1747 | ||
2511 | case BUZIOC_G_STATUS: | 1748 | case BUZIOC_G_STATUS: |
2512 | { | 1749 | { |
2513 | struct zoran_status *bstat = arg; | 1750 | struct zoran_status *bstat = arg; |
2514 | int norm, input, status, res = 0; | 1751 | struct v4l2_routing route = { 0, 0 }; |
1752 | int status = 0, res = 0; | ||
1753 | v4l2_std_id norm; | ||
2515 | 1754 | ||
2516 | dprintk(3, KERN_DEBUG "%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr)); | 1755 | dprintk(3, KERN_DEBUG "%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr)); |
2517 | 1756 | ||
@@ -2523,8 +1762,7 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2523 | return -EINVAL; | 1762 | return -EINVAL; |
2524 | } | 1763 | } |
2525 | 1764 | ||
2526 | input = zr->card.input[bstat->input].muxsel; | 1765 | route.input = zr->card.input[bstat->input].muxsel; |
2527 | norm = VIDEO_MODE_AUTO; | ||
2528 | 1766 | ||
2529 | mutex_lock(&zr->resource_lock); | 1767 | mutex_lock(&zr->resource_lock); |
2530 | 1768 | ||
@@ -2537,1629 +1775,1262 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
2537 | goto gstat_unlock_and_return; | 1775 | goto gstat_unlock_and_return; |
2538 | } | 1776 | } |
2539 | 1777 | ||
2540 | decoder_command(zr, DECODER_SET_INPUT, &input); | 1778 | decoder_call(zr, video, s_routing, &route); |
2541 | decoder_command(zr, DECODER_SET_NORM, &norm); | ||
2542 | 1779 | ||
2543 | /* sleep 1 second */ | 1780 | /* sleep 1 second */ |
2544 | ssleep(1); | 1781 | ssleep(1); |
2545 | 1782 | ||
2546 | /* Get status of video decoder */ | 1783 | /* Get status of video decoder */ |
2547 | decoder_command(zr, DECODER_GET_STATUS, &status); | 1784 | decoder_call(zr, video, querystd, &norm); |
1785 | decoder_call(zr, video, g_input_status, &status); | ||
2548 | 1786 | ||
2549 | /* restore previous input and norm */ | 1787 | /* restore previous input and norm */ |
2550 | input = zr->card.input[zr->input].muxsel; | 1788 | route.input = zr->card.input[zr->input].muxsel; |
2551 | decoder_command(zr, DECODER_SET_INPUT, &input); | 1789 | decoder_call(zr, video, s_routing, &route); |
2552 | decoder_command(zr, DECODER_SET_NORM, &zr->norm); | 1790 | gstat_unlock_and_return: |
2553 | gstat_unlock_and_return: | ||
2554 | mutex_unlock(&zr->resource_lock); | 1791 | mutex_unlock(&zr->resource_lock); |
2555 | 1792 | ||
2556 | if (!res) { | 1793 | if (!res) { |
2557 | bstat->signal = | 1794 | bstat->signal = |
2558 | (status & DECODER_STATUS_GOOD) ? 1 : 0; | 1795 | (status & V4L2_IN_ST_NO_SIGNAL) ? 0 : 1; |
2559 | if (status & DECODER_STATUS_NTSC) | 1796 | if (norm & V4L2_STD_NTSC) |
2560 | bstat->norm = VIDEO_MODE_NTSC; | 1797 | bstat->norm = VIDEO_MODE_NTSC; |
2561 | else if (status & DECODER_STATUS_SECAM) | 1798 | else if (norm & V4L2_STD_SECAM) |
2562 | bstat->norm = VIDEO_MODE_SECAM; | 1799 | bstat->norm = VIDEO_MODE_SECAM; |
2563 | else | 1800 | else |
2564 | bstat->norm = VIDEO_MODE_PAL; | 1801 | bstat->norm = VIDEO_MODE_PAL; |
2565 | 1802 | ||
2566 | bstat->color = | 1803 | bstat->color = |
2567 | (status & DECODER_STATUS_COLOR) ? 1 : 0; | 1804 | (status & V4L2_IN_ST_NO_COLOR) ? 0 : 1; |
2568 | } | 1805 | } |
2569 | 1806 | ||
2570 | return res; | 1807 | return res; |
2571 | } | 1808 | } |
2572 | break; | ||
2573 | |||
2574 | /* The new video4linux2 capture interface - much nicer than video4linux1, since | ||
2575 | * it allows for integrating the JPEG capturing calls inside standard v4l2 | ||
2576 | */ | ||
2577 | |||
2578 | case VIDIOC_QUERYCAP: | ||
2579 | { | ||
2580 | struct v4l2_capability *cap = arg; | ||
2581 | 1809 | ||
2582 | dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCAP\n", ZR_DEVNAME(zr)); | 1810 | default: |
2583 | 1811 | return -EINVAL; | |
2584 | memset(cap, 0, sizeof(*cap)); | ||
2585 | strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1); | ||
2586 | strncpy(cap->driver, "zoran", sizeof(cap->driver)-1); | ||
2587 | snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", | ||
2588 | pci_name(zr->pci_dev)); | ||
2589 | cap->version = | ||
2590 | KERNEL_VERSION(MAJOR_VERSION, MINOR_VERSION, | ||
2591 | RELEASE_VERSION); | ||
2592 | cap->capabilities = ZORAN_V4L2_VID_FLAGS; | ||
2593 | |||
2594 | return 0; | ||
2595 | } | 1812 | } |
2596 | break; | 1813 | } |
2597 | 1814 | ||
2598 | case VIDIOC_ENUM_FMT: | 1815 | static int zoran_vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *vmbuf) |
2599 | { | 1816 | { |
2600 | struct v4l2_fmtdesc *fmt = arg; | 1817 | struct zoran_fh *fh = __fh; |
2601 | int index = fmt->index, num = -1, i, flag = 0, type = | 1818 | struct zoran *zr = fh->zr; |
2602 | fmt->type; | 1819 | int i, res = 0; |
2603 | 1820 | ||
2604 | dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUM_FMT - index=%d\n", | ||
2605 | ZR_DEVNAME(zr), fmt->index); | ||
2606 | 1821 | ||
2607 | switch (fmt->type) { | 1822 | mutex_lock(&zr->resource_lock); |
2608 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | ||
2609 | flag = ZORAN_FORMAT_CAPTURE; | ||
2610 | break; | ||
2611 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | ||
2612 | flag = ZORAN_FORMAT_PLAYBACK; | ||
2613 | break; | ||
2614 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | ||
2615 | flag = ZORAN_FORMAT_OVERLAY; | ||
2616 | break; | ||
2617 | default: | ||
2618 | dprintk(1, | ||
2619 | KERN_ERR | ||
2620 | "%s: VIDIOC_ENUM_FMT - unknown type %d\n", | ||
2621 | ZR_DEVNAME(zr), fmt->type); | ||
2622 | return -EINVAL; | ||
2623 | } | ||
2624 | 1823 | ||
2625 | for (i = 0; i < NUM_FORMATS; i++) { | 1824 | if (fh->buffers.allocated) { |
2626 | if (zoran_formats[i].flags & flag) | 1825 | dprintk(1, |
2627 | num++; | 1826 | KERN_ERR |
2628 | if (num == fmt->index) | 1827 | "%s: VIDIOCGMBUF - buffers already allocated\n", |
2629 | break; | 1828 | ZR_DEVNAME(zr)); |
2630 | } | 1829 | res = -EINVAL; |
2631 | if (fmt->index < 0 /* late, but not too late */ || | 1830 | goto v4l1reqbuf_unlock_and_return; |
2632 | i == NUM_FORMATS) | 1831 | } |
2633 | return -EINVAL; | ||
2634 | 1832 | ||
2635 | memset(fmt, 0, sizeof(*fmt)); | 1833 | /* The next mmap will map the V4L buffers */ |
2636 | fmt->index = index; | 1834 | map_mode_raw(fh); |
2637 | fmt->type = type; | ||
2638 | strncpy(fmt->description, zoran_formats[i].name, sizeof(fmt->description)-1); | ||
2639 | fmt->pixelformat = zoran_formats[i].fourcc; | ||
2640 | if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED) | ||
2641 | fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; | ||
2642 | 1835 | ||
2643 | return 0; | 1836 | if (v4l_fbuffer_alloc(fh)) { |
1837 | res = -ENOMEM; | ||
1838 | goto v4l1reqbuf_unlock_and_return; | ||
2644 | } | 1839 | } |
2645 | break; | ||
2646 | |||
2647 | case VIDIOC_G_FMT: | ||
2648 | { | ||
2649 | struct v4l2_format *fmt = arg; | ||
2650 | int type = fmt->type; | ||
2651 | 1840 | ||
2652 | dprintk(5, KERN_DEBUG "%s: VIDIOC_G_FMT\n", ZR_DEVNAME(zr)); | 1841 | vmbuf->size = fh->buffers.num_buffers * fh->buffers.buffer_size; |
1842 | vmbuf->frames = fh->buffers.num_buffers; | ||
1843 | for (i = 0; i < vmbuf->frames; i++) | ||
1844 | vmbuf->offsets[i] = i * fh->buffers.buffer_size; | ||
2653 | 1845 | ||
2654 | memset(fmt, 0, sizeof(*fmt)); | 1846 | v4l1reqbuf_unlock_and_return: |
2655 | fmt->type = type; | 1847 | mutex_unlock(&zr->resource_lock); |
2656 | 1848 | ||
2657 | switch (fmt->type) { | 1849 | return res; |
2658 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | 1850 | } |
1851 | #endif | ||
2659 | 1852 | ||
2660 | mutex_lock(&zr->resource_lock); | 1853 | static int zoran_querycap(struct file *file, void *__fh, struct v4l2_capability *cap) |
1854 | { | ||
1855 | struct zoran_fh *fh = __fh; | ||
1856 | struct zoran *zr = fh->zr; | ||
2661 | 1857 | ||
2662 | fmt->fmt.win.w.left = fh->overlay_settings.x; | 1858 | memset(cap, 0, sizeof(*cap)); |
2663 | fmt->fmt.win.w.top = fh->overlay_settings.y; | 1859 | strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1); |
2664 | fmt->fmt.win.w.width = fh->overlay_settings.width; | 1860 | strncpy(cap->driver, "zoran", sizeof(cap->driver)-1); |
2665 | fmt->fmt.win.w.height = | 1861 | snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", |
2666 | fh->overlay_settings.height; | 1862 | pci_name(zr->pci_dev)); |
2667 | if (fh->overlay_settings.width * 2 > | 1863 | cap->version = KERNEL_VERSION(MAJOR_VERSION, MINOR_VERSION, |
2668 | BUZ_MAX_HEIGHT) | 1864 | RELEASE_VERSION); |
2669 | fmt->fmt.win.field = V4L2_FIELD_INTERLACED; | 1865 | cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE | |
2670 | else | 1866 | V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OVERLAY; |
2671 | fmt->fmt.win.field = V4L2_FIELD_TOP; | 1867 | return 0; |
1868 | } | ||
2672 | 1869 | ||
2673 | mutex_unlock(&zr->resource_lock); | 1870 | static int zoran_enum_fmt(struct zoran *zr, struct v4l2_fmtdesc *fmt, int flag) |
1871 | { | ||
1872 | int num = -1, i; | ||
2674 | 1873 | ||
1874 | for (i = 0; i < NUM_FORMATS; i++) { | ||
1875 | if (zoran_formats[i].flags & flag) | ||
1876 | num++; | ||
1877 | if (num == fmt->index) | ||
2675 | break; | 1878 | break; |
1879 | } | ||
1880 | if (fmt->index < 0 /* late, but not too late */ || i == NUM_FORMATS) | ||
1881 | return -EINVAL; | ||
2676 | 1882 | ||
2677 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | 1883 | strncpy(fmt->description, zoran_formats[i].name, sizeof(fmt->description)-1); |
2678 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | 1884 | fmt->pixelformat = zoran_formats[i].fourcc; |
2679 | 1885 | if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED) | |
2680 | mutex_lock(&zr->resource_lock); | 1886 | fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; |
2681 | 1887 | return 0; | |
2682 | if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && | 1888 | } |
2683 | fh->map_mode == ZORAN_MAP_MODE_RAW) { | ||
2684 | |||
2685 | fmt->fmt.pix.width = | ||
2686 | fh->v4l_settings.width; | ||
2687 | fmt->fmt.pix.height = | ||
2688 | fh->v4l_settings.height; | ||
2689 | fmt->fmt.pix.sizeimage = | ||
2690 | fh->v4l_settings.bytesperline * | ||
2691 | fh->v4l_settings.height; | ||
2692 | fmt->fmt.pix.pixelformat = | ||
2693 | fh->v4l_settings.format->fourcc; | ||
2694 | fmt->fmt.pix.colorspace = | ||
2695 | fh->v4l_settings.format->colorspace; | ||
2696 | fmt->fmt.pix.bytesperline = | ||
2697 | fh->v4l_settings.bytesperline; | ||
2698 | if (BUZ_MAX_HEIGHT < | ||
2699 | (fh->v4l_settings.height * 2)) | ||
2700 | fmt->fmt.pix.field = | ||
2701 | V4L2_FIELD_INTERLACED; | ||
2702 | else | ||
2703 | fmt->fmt.pix.field = | ||
2704 | V4L2_FIELD_TOP; | ||
2705 | |||
2706 | } else { | ||
2707 | |||
2708 | fmt->fmt.pix.width = | ||
2709 | fh->jpg_settings.img_width / | ||
2710 | fh->jpg_settings.HorDcm; | ||
2711 | fmt->fmt.pix.height = | ||
2712 | fh->jpg_settings.img_height / | ||
2713 | (fh->jpg_settings.VerDcm * | ||
2714 | fh->jpg_settings.TmpDcm); | ||
2715 | fmt->fmt.pix.sizeimage = | ||
2716 | zoran_v4l2_calc_bufsize(&fh-> | ||
2717 | jpg_settings); | ||
2718 | fmt->fmt.pix.pixelformat = | ||
2719 | V4L2_PIX_FMT_MJPEG; | ||
2720 | if (fh->jpg_settings.TmpDcm == 1) | ||
2721 | fmt->fmt.pix.field = | ||
2722 | (fh->jpg_settings. | ||
2723 | odd_even ? V4L2_FIELD_SEQ_BT : | ||
2724 | V4L2_FIELD_SEQ_BT); | ||
2725 | else | ||
2726 | fmt->fmt.pix.field = | ||
2727 | (fh->jpg_settings. | ||
2728 | odd_even ? V4L2_FIELD_TOP : | ||
2729 | V4L2_FIELD_BOTTOM); | ||
2730 | |||
2731 | fmt->fmt.pix.bytesperline = 0; | ||
2732 | fmt->fmt.pix.colorspace = | ||
2733 | V4L2_COLORSPACE_SMPTE170M; | ||
2734 | } | ||
2735 | |||
2736 | mutex_unlock(&zr->resource_lock); | ||
2737 | 1889 | ||
2738 | break; | 1890 | static int zoran_enum_fmt_vid_cap(struct file *file, void *__fh, |
1891 | struct v4l2_fmtdesc *f) | ||
1892 | { | ||
1893 | struct zoran_fh *fh = __fh; | ||
1894 | struct zoran *zr = fh->zr; | ||
2739 | 1895 | ||
2740 | default: | 1896 | return zoran_enum_fmt(zr, f, ZORAN_FORMAT_CAPTURE); |
2741 | dprintk(1, | 1897 | } |
2742 | KERN_ERR | ||
2743 | "%s: VIDIOC_G_FMT - unsupported type %d\n", | ||
2744 | ZR_DEVNAME(zr), fmt->type); | ||
2745 | return -EINVAL; | ||
2746 | } | ||
2747 | return 0; | ||
2748 | } | ||
2749 | break; | ||
2750 | 1898 | ||
2751 | case VIDIOC_S_FMT: | 1899 | static int zoran_enum_fmt_vid_out(struct file *file, void *__fh, |
2752 | { | 1900 | struct v4l2_fmtdesc *f) |
2753 | struct v4l2_format *fmt = arg; | 1901 | { |
2754 | int i, res = 0; | 1902 | struct zoran_fh *fh = __fh; |
2755 | __le32 printformat; | 1903 | struct zoran *zr = fh->zr; |
2756 | |||
2757 | dprintk(3, KERN_DEBUG "%s: VIDIOC_S_FMT - type=%d, ", | ||
2758 | ZR_DEVNAME(zr), fmt->type); | ||
2759 | |||
2760 | switch (fmt->type) { | ||
2761 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | ||
2762 | |||
2763 | dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n", | ||
2764 | fmt->fmt.win.w.left, fmt->fmt.win.w.top, | ||
2765 | fmt->fmt.win.w.width, | ||
2766 | fmt->fmt.win.w.height, | ||
2767 | fmt->fmt.win.clipcount, | ||
2768 | fmt->fmt.win.bitmap); | ||
2769 | mutex_lock(&zr->resource_lock); | ||
2770 | res = | ||
2771 | setup_window(file, fmt->fmt.win.w.left, | ||
2772 | fmt->fmt.win.w.top, | ||
2773 | fmt->fmt.win.w.width, | ||
2774 | fmt->fmt.win.w.height, | ||
2775 | (struct video_clip __user *) | ||
2776 | fmt->fmt.win.clips, | ||
2777 | fmt->fmt.win.clipcount, | ||
2778 | fmt->fmt.win.bitmap); | ||
2779 | mutex_unlock(&zr->resource_lock); | ||
2780 | return res; | ||
2781 | break; | ||
2782 | 1904 | ||
2783 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | 1905 | return zoran_enum_fmt(zr, f, ZORAN_FORMAT_PLAYBACK); |
2784 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | 1906 | } |
2785 | |||
2786 | printformat = | ||
2787 | __cpu_to_le32(fmt->fmt.pix.pixelformat); | ||
2788 | dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n", | ||
2789 | fmt->fmt.pix.width, fmt->fmt.pix.height, | ||
2790 | fmt->fmt.pix.pixelformat, | ||
2791 | (char *) &printformat); | ||
2792 | |||
2793 | /* we can be requested to do JPEG/raw playback/capture */ | ||
2794 | if (! | ||
2795 | (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE || | ||
2796 | (fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && | ||
2797 | fmt->fmt.pix.pixelformat == | ||
2798 | V4L2_PIX_FMT_MJPEG))) { | ||
2799 | dprintk(1, | ||
2800 | KERN_ERR | ||
2801 | "%s: VIDIOC_S_FMT - unknown type %d/0x%x(%4.4s) combination\n", | ||
2802 | ZR_DEVNAME(zr), fmt->type, | ||
2803 | fmt->fmt.pix.pixelformat, | ||
2804 | (char *) &printformat); | ||
2805 | return -EINVAL; | ||
2806 | } | ||
2807 | 1907 | ||
2808 | if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) { | 1908 | static int zoran_enum_fmt_vid_overlay(struct file *file, void *__fh, |
2809 | mutex_lock(&zr->resource_lock); | 1909 | struct v4l2_fmtdesc *f) |
1910 | { | ||
1911 | struct zoran_fh *fh = __fh; | ||
1912 | struct zoran *zr = fh->zr; | ||
2810 | 1913 | ||
2811 | settings = fh->jpg_settings; | 1914 | return zoran_enum_fmt(zr, f, ZORAN_FORMAT_OVERLAY); |
1915 | } | ||
2812 | 1916 | ||
2813 | if (fh->v4l_buffers.allocated || | 1917 | static int zoran_g_fmt_vid_out(struct file *file, void *__fh, |
2814 | fh->jpg_buffers.allocated) { | 1918 | struct v4l2_format *fmt) |
2815 | dprintk(1, | 1919 | { |
2816 | KERN_ERR | 1920 | struct zoran_fh *fh = __fh; |
2817 | "%s: VIDIOC_S_FMT - cannot change capture mode\n", | 1921 | struct zoran *zr = fh->zr; |
2818 | ZR_DEVNAME(zr)); | ||
2819 | res = -EBUSY; | ||
2820 | goto sfmtjpg_unlock_and_return; | ||
2821 | } | ||
2822 | 1922 | ||
2823 | /* we actually need to set 'real' parameters now */ | 1923 | mutex_lock(&zr->resource_lock); |
2824 | if ((fmt->fmt.pix.height * 2) > | ||
2825 | BUZ_MAX_HEIGHT) | ||
2826 | settings.TmpDcm = 1; | ||
2827 | else | ||
2828 | settings.TmpDcm = 2; | ||
2829 | settings.decimation = 0; | ||
2830 | if (fmt->fmt.pix.height <= | ||
2831 | fh->jpg_settings.img_height / 2) | ||
2832 | settings.VerDcm = 2; | ||
2833 | else | ||
2834 | settings.VerDcm = 1; | ||
2835 | if (fmt->fmt.pix.width <= | ||
2836 | fh->jpg_settings.img_width / 4) | ||
2837 | settings.HorDcm = 4; | ||
2838 | else if (fmt->fmt.pix.width <= | ||
2839 | fh->jpg_settings.img_width / 2) | ||
2840 | settings.HorDcm = 2; | ||
2841 | else | ||
2842 | settings.HorDcm = 1; | ||
2843 | if (settings.TmpDcm == 1) | ||
2844 | settings.field_per_buff = 2; | ||
2845 | else | ||
2846 | settings.field_per_buff = 1; | ||
2847 | |||
2848 | /* check */ | ||
2849 | if ((res = | ||
2850 | zoran_check_jpg_settings(zr, | ||
2851 | &settings))) | ||
2852 | goto sfmtjpg_unlock_and_return; | ||
2853 | |||
2854 | /* it's ok, so set them */ | ||
2855 | fh->jpg_settings = settings; | ||
2856 | |||
2857 | /* tell the user what we actually did */ | ||
2858 | fmt->fmt.pix.width = | ||
2859 | settings.img_width / settings.HorDcm; | ||
2860 | fmt->fmt.pix.height = | ||
2861 | settings.img_height * 2 / | ||
2862 | (settings.TmpDcm * settings.VerDcm); | ||
2863 | if (settings.TmpDcm == 1) | ||
2864 | fmt->fmt.pix.field = | ||
2865 | (fh->jpg_settings. | ||
2866 | odd_even ? V4L2_FIELD_SEQ_TB : | ||
2867 | V4L2_FIELD_SEQ_BT); | ||
2868 | else | ||
2869 | fmt->fmt.pix.field = | ||
2870 | (fh->jpg_settings. | ||
2871 | odd_even ? V4L2_FIELD_TOP : | ||
2872 | V4L2_FIELD_BOTTOM); | ||
2873 | fh->jpg_buffers.buffer_size = | ||
2874 | zoran_v4l2_calc_bufsize(&fh-> | ||
2875 | jpg_settings); | ||
2876 | fmt->fmt.pix.bytesperline = 0; | ||
2877 | fmt->fmt.pix.sizeimage = | ||
2878 | fh->jpg_buffers.buffer_size; | ||
2879 | fmt->fmt.pix.colorspace = | ||
2880 | V4L2_COLORSPACE_SMPTE170M; | ||
2881 | |||
2882 | /* we hereby abuse this variable to show that | ||
2883 | * we're gonna do mjpeg capture */ | ||
2884 | fh->map_mode = | ||
2885 | (fmt->type == | ||
2886 | V4L2_BUF_TYPE_VIDEO_CAPTURE) ? | ||
2887 | ZORAN_MAP_MODE_JPG_REC : | ||
2888 | ZORAN_MAP_MODE_JPG_PLAY; | ||
2889 | sfmtjpg_unlock_and_return: | ||
2890 | mutex_unlock(&zr->resource_lock); | ||
2891 | } else { | ||
2892 | for (i = 0; i < NUM_FORMATS; i++) | ||
2893 | if (fmt->fmt.pix.pixelformat == | ||
2894 | zoran_formats[i].fourcc) | ||
2895 | break; | ||
2896 | if (i == NUM_FORMATS) { | ||
2897 | dprintk(1, | ||
2898 | KERN_ERR | ||
2899 | "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x (%4.4s)\n", | ||
2900 | ZR_DEVNAME(zr), | ||
2901 | fmt->fmt.pix.pixelformat, | ||
2902 | (char *) &printformat); | ||
2903 | return -EINVAL; | ||
2904 | } | ||
2905 | mutex_lock(&zr->resource_lock); | ||
2906 | if (fh->jpg_buffers.allocated || | ||
2907 | (fh->v4l_buffers.allocated && | ||
2908 | fh->v4l_buffers.active != | ||
2909 | ZORAN_FREE)) { | ||
2910 | dprintk(1, | ||
2911 | KERN_ERR | ||
2912 | "%s: VIDIOC_S_FMT - cannot change capture mode\n", | ||
2913 | ZR_DEVNAME(zr)); | ||
2914 | res = -EBUSY; | ||
2915 | goto sfmtv4l_unlock_and_return; | ||
2916 | } | ||
2917 | if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT) | ||
2918 | fmt->fmt.pix.height = | ||
2919 | BUZ_MAX_HEIGHT; | ||
2920 | if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) | ||
2921 | fmt->fmt.pix.width = BUZ_MAX_WIDTH; | ||
2922 | |||
2923 | if ((res = | ||
2924 | zoran_v4l_set_format(file, | ||
2925 | fmt->fmt.pix. | ||
2926 | width, | ||
2927 | fmt->fmt.pix. | ||
2928 | height, | ||
2929 | &zoran_formats | ||
2930 | [i]))) | ||
2931 | goto sfmtv4l_unlock_and_return; | ||
2932 | |||
2933 | /* tell the user the | ||
2934 | * results/missing stuff */ | ||
2935 | fmt->fmt.pix.bytesperline = | ||
2936 | fh->v4l_settings.bytesperline; | ||
2937 | fmt->fmt.pix.sizeimage = | ||
2938 | fh->v4l_settings.height * | ||
2939 | fh->v4l_settings.bytesperline; | ||
2940 | fmt->fmt.pix.colorspace = | ||
2941 | fh->v4l_settings.format->colorspace; | ||
2942 | if (BUZ_MAX_HEIGHT < | ||
2943 | (fh->v4l_settings.height * 2)) | ||
2944 | fmt->fmt.pix.field = | ||
2945 | V4L2_FIELD_INTERLACED; | ||
2946 | else | ||
2947 | fmt->fmt.pix.field = | ||
2948 | V4L2_FIELD_TOP; | ||
2949 | |||
2950 | fh->map_mode = ZORAN_MAP_MODE_RAW; | ||
2951 | sfmtv4l_unlock_and_return: | ||
2952 | mutex_unlock(&zr->resource_lock); | ||
2953 | } | ||
2954 | 1924 | ||
2955 | break; | 1925 | fmt->fmt.pix.width = fh->jpg_settings.img_width / fh->jpg_settings.HorDcm; |
1926 | fmt->fmt.pix.height = fh->jpg_settings.img_height * 2 / | ||
1927 | (fh->jpg_settings.VerDcm * fh->jpg_settings.TmpDcm); | ||
1928 | fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(&fh->jpg_settings); | ||
1929 | fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG; | ||
1930 | if (fh->jpg_settings.TmpDcm == 1) | ||
1931 | fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? | ||
1932 | V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT); | ||
1933 | else | ||
1934 | fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? | ||
1935 | V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); | ||
1936 | fmt->fmt.pix.bytesperline = 0; | ||
1937 | fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; | ||
2956 | 1938 | ||
2957 | default: | 1939 | mutex_unlock(&zr->resource_lock); |
2958 | dprintk(1, | 1940 | return 0; |
2959 | KERN_ERR | 1941 | } |
2960 | "%s: VIDIOC_S_FMT - unsupported type %d\n", | ||
2961 | ZR_DEVNAME(zr), fmt->type); | ||
2962 | return -EINVAL; | ||
2963 | } | ||
2964 | 1942 | ||
2965 | return res; | 1943 | static int zoran_g_fmt_vid_cap(struct file *file, void *__fh, |
2966 | } | 1944 | struct v4l2_format *fmt) |
2967 | break; | 1945 | { |
1946 | struct zoran_fh *fh = __fh; | ||
1947 | struct zoran *zr = fh->zr; | ||
2968 | 1948 | ||
2969 | case VIDIOC_G_FBUF: | 1949 | if (fh->map_mode != ZORAN_MAP_MODE_RAW) |
2970 | { | 1950 | return zoran_g_fmt_vid_out(file, fh, fmt); |
2971 | struct v4l2_framebuffer *fb = arg; | ||
2972 | 1951 | ||
2973 | dprintk(3, KERN_DEBUG "%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr)); | 1952 | mutex_lock(&zr->resource_lock); |
1953 | fmt->fmt.pix.width = fh->v4l_settings.width; | ||
1954 | fmt->fmt.pix.height = fh->v4l_settings.height; | ||
1955 | fmt->fmt.pix.sizeimage = fh->v4l_settings.bytesperline * | ||
1956 | fh->v4l_settings.height; | ||
1957 | fmt->fmt.pix.pixelformat = fh->v4l_settings.format->fourcc; | ||
1958 | fmt->fmt.pix.colorspace = fh->v4l_settings.format->colorspace; | ||
1959 | fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline; | ||
1960 | if (BUZ_MAX_HEIGHT < (fh->v4l_settings.height * 2)) | ||
1961 | fmt->fmt.pix.field = V4L2_FIELD_INTERLACED; | ||
1962 | else | ||
1963 | fmt->fmt.pix.field = V4L2_FIELD_TOP; | ||
1964 | mutex_unlock(&zr->resource_lock); | ||
1965 | return 0; | ||
1966 | } | ||
2974 | 1967 | ||
2975 | memset(fb, 0, sizeof(*fb)); | 1968 | static int zoran_g_fmt_vid_overlay(struct file *file, void *__fh, |
2976 | mutex_lock(&zr->resource_lock); | 1969 | struct v4l2_format *fmt) |
2977 | fb->base = zr->buffer.base; | 1970 | { |
2978 | fb->fmt.width = zr->buffer.width; | 1971 | struct zoran_fh *fh = __fh; |
2979 | fb->fmt.height = zr->buffer.height; | 1972 | struct zoran *zr = fh->zr; |
2980 | if (zr->overlay_settings.format) { | ||
2981 | fb->fmt.pixelformat = | ||
2982 | fh->overlay_settings.format->fourcc; | ||
2983 | } | ||
2984 | fb->fmt.bytesperline = zr->buffer.bytesperline; | ||
2985 | mutex_unlock(&zr->resource_lock); | ||
2986 | fb->fmt.colorspace = V4L2_COLORSPACE_SRGB; | ||
2987 | fb->fmt.field = V4L2_FIELD_INTERLACED; | ||
2988 | fb->flags = V4L2_FBUF_FLAG_OVERLAY; | ||
2989 | fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; | ||
2990 | 1973 | ||
2991 | return 0; | 1974 | mutex_lock(&zr->resource_lock); |
2992 | } | ||
2993 | break; | ||
2994 | 1975 | ||
2995 | case VIDIOC_S_FBUF: | 1976 | fmt->fmt.win.w.left = fh->overlay_settings.x; |
2996 | { | 1977 | fmt->fmt.win.w.top = fh->overlay_settings.y; |
2997 | int i, res = 0; | 1978 | fmt->fmt.win.w.width = fh->overlay_settings.width; |
2998 | struct v4l2_framebuffer *fb = arg; | 1979 | fmt->fmt.win.w.height = fh->overlay_settings.height; |
2999 | __le32 printformat = __cpu_to_le32(fb->fmt.pixelformat); | 1980 | if (fh->overlay_settings.width * 2 > BUZ_MAX_HEIGHT) |
1981 | fmt->fmt.win.field = V4L2_FIELD_INTERLACED; | ||
1982 | else | ||
1983 | fmt->fmt.win.field = V4L2_FIELD_TOP; | ||
3000 | 1984 | ||
3001 | dprintk(3, | 1985 | mutex_unlock(&zr->resource_lock); |
3002 | KERN_DEBUG | 1986 | return 0; |
3003 | "%s: VIDIOC_S_FBUF - base=0x%p, size=%dx%d, bpl=%d, fmt=0x%x (%4.4s)\n", | 1987 | } |
3004 | ZR_DEVNAME(zr), fb->base, fb->fmt.width, fb->fmt.height, | ||
3005 | fb->fmt.bytesperline, fb->fmt.pixelformat, | ||
3006 | (char *) &printformat); | ||
3007 | 1988 | ||
3008 | for (i = 0; i < NUM_FORMATS; i++) | 1989 | static int zoran_try_fmt_vid_overlay(struct file *file, void *__fh, |
3009 | if (zoran_formats[i].fourcc == fb->fmt.pixelformat) | 1990 | struct v4l2_format *fmt) |
3010 | break; | 1991 | { |
3011 | if (i == NUM_FORMATS) { | 1992 | struct zoran_fh *fh = __fh; |
3012 | dprintk(1, | 1993 | struct zoran *zr = fh->zr; |
3013 | KERN_ERR | ||
3014 | "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n", | ||
3015 | ZR_DEVNAME(zr), fb->fmt.pixelformat, | ||
3016 | (char *) &printformat); | ||
3017 | return -EINVAL; | ||
3018 | } | ||
3019 | 1994 | ||
3020 | mutex_lock(&zr->resource_lock); | 1995 | mutex_lock(&zr->resource_lock); |
3021 | res = | ||
3022 | setup_fbuffer(file, fb->base, &zoran_formats[i], | ||
3023 | fb->fmt.width, fb->fmt.height, | ||
3024 | fb->fmt.bytesperline); | ||
3025 | mutex_unlock(&zr->resource_lock); | ||
3026 | 1996 | ||
3027 | return res; | 1997 | if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH) |
3028 | } | 1998 | fmt->fmt.win.w.width = BUZ_MAX_WIDTH; |
3029 | break; | 1999 | if (fmt->fmt.win.w.width < BUZ_MIN_WIDTH) |
2000 | fmt->fmt.win.w.width = BUZ_MIN_WIDTH; | ||
2001 | if (fmt->fmt.win.w.height > BUZ_MAX_HEIGHT) | ||
2002 | fmt->fmt.win.w.height = BUZ_MAX_HEIGHT; | ||
2003 | if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT) | ||
2004 | fmt->fmt.win.w.height = BUZ_MIN_HEIGHT; | ||
3030 | 2005 | ||
3031 | case VIDIOC_OVERLAY: | 2006 | mutex_unlock(&zr->resource_lock); |
3032 | { | 2007 | return 0; |
3033 | int *on = arg, res; | 2008 | } |
3034 | 2009 | ||
3035 | dprintk(3, KERN_DEBUG "%s: VIDIOC_PREVIEW - on=%d\n", | 2010 | static int zoran_try_fmt_vid_out(struct file *file, void *__fh, |
3036 | ZR_DEVNAME(zr), *on); | 2011 | struct v4l2_format *fmt) |
2012 | { | ||
2013 | struct zoran_fh *fh = __fh; | ||
2014 | struct zoran *zr = fh->zr; | ||
2015 | struct zoran_jpg_settings settings; | ||
2016 | int res = 0; | ||
3037 | 2017 | ||
3038 | mutex_lock(&zr->resource_lock); | 2018 | if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) |
3039 | res = setup_overlay(file, *on); | 2019 | return -EINVAL; |
3040 | mutex_unlock(&zr->resource_lock); | ||
3041 | 2020 | ||
3042 | return res; | 2021 | mutex_lock(&zr->resource_lock); |
3043 | } | 2022 | settings = fh->jpg_settings; |
3044 | break; | ||
3045 | 2023 | ||
3046 | case VIDIOC_REQBUFS: | 2024 | /* we actually need to set 'real' parameters now */ |
3047 | { | 2025 | if ((fmt->fmt.pix.height * 2) > BUZ_MAX_HEIGHT) |
3048 | struct v4l2_requestbuffers *req = arg; | 2026 | settings.TmpDcm = 1; |
3049 | int res = 0; | 2027 | else |
2028 | settings.TmpDcm = 2; | ||
2029 | settings.decimation = 0; | ||
2030 | if (fmt->fmt.pix.height <= fh->jpg_settings.img_height / 2) | ||
2031 | settings.VerDcm = 2; | ||
2032 | else | ||
2033 | settings.VerDcm = 1; | ||
2034 | if (fmt->fmt.pix.width <= fh->jpg_settings.img_width / 4) | ||
2035 | settings.HorDcm = 4; | ||
2036 | else if (fmt->fmt.pix.width <= fh->jpg_settings.img_width / 2) | ||
2037 | settings.HorDcm = 2; | ||
2038 | else | ||
2039 | settings.HorDcm = 1; | ||
2040 | if (settings.TmpDcm == 1) | ||
2041 | settings.field_per_buff = 2; | ||
2042 | else | ||
2043 | settings.field_per_buff = 1; | ||
3050 | 2044 | ||
3051 | dprintk(3, KERN_DEBUG "%s: VIDIOC_REQBUFS - type=%d\n", | 2045 | if (settings.HorDcm > 1) { |
3052 | ZR_DEVNAME(zr), req->type); | 2046 | settings.img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0; |
2047 | settings.img_width = (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH; | ||
2048 | } else { | ||
2049 | settings.img_x = 0; | ||
2050 | settings.img_width = BUZ_MAX_WIDTH; | ||
2051 | } | ||
2052 | |||
2053 | /* check */ | ||
2054 | res = zoran_check_jpg_settings(zr, &settings, 1); | ||
2055 | if (res) | ||
2056 | goto tryfmt_unlock_and_return; | ||
2057 | |||
2058 | /* tell the user what we actually did */ | ||
2059 | fmt->fmt.pix.width = settings.img_width / settings.HorDcm; | ||
2060 | fmt->fmt.pix.height = settings.img_height * 2 / | ||
2061 | (settings.TmpDcm * settings.VerDcm); | ||
2062 | if (settings.TmpDcm == 1) | ||
2063 | fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? | ||
2064 | V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT); | ||
2065 | else | ||
2066 | fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? | ||
2067 | V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); | ||
3053 | 2068 | ||
3054 | if (req->memory != V4L2_MEMORY_MMAP) { | 2069 | fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(&settings); |
3055 | dprintk(1, | 2070 | fmt->fmt.pix.bytesperline = 0; |
3056 | KERN_ERR | 2071 | fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; |
3057 | "%s: only MEMORY_MMAP capture is supported, not %d\n", | 2072 | tryfmt_unlock_and_return: |
3058 | ZR_DEVNAME(zr), req->memory); | 2073 | mutex_unlock(&zr->resource_lock); |
3059 | return -EINVAL; | 2074 | return res; |
3060 | } | 2075 | } |
3061 | 2076 | ||
3062 | mutex_lock(&zr->resource_lock); | 2077 | static int zoran_try_fmt_vid_cap(struct file *file, void *__fh, |
2078 | struct v4l2_format *fmt) | ||
2079 | { | ||
2080 | struct zoran_fh *fh = __fh; | ||
2081 | struct zoran *zr = fh->zr; | ||
2082 | int bpp; | ||
2083 | int i; | ||
3063 | 2084 | ||
3064 | if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) { | 2085 | if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) |
3065 | dprintk(1, | 2086 | return zoran_try_fmt_vid_out(file, fh, fmt); |
3066 | KERN_ERR | ||
3067 | "%s: VIDIOC_REQBUFS - buffers allready allocated\n", | ||
3068 | ZR_DEVNAME(zr)); | ||
3069 | res = -EBUSY; | ||
3070 | goto v4l2reqbuf_unlock_and_return; | ||
3071 | } | ||
3072 | 2087 | ||
3073 | if (fh->map_mode == ZORAN_MAP_MODE_RAW && | 2088 | mutex_lock(&zr->resource_lock); |
3074 | req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { | ||
3075 | 2089 | ||
3076 | /* control user input */ | 2090 | for (i = 0; i < NUM_FORMATS; i++) |
3077 | if (req->count < 2) | 2091 | if (zoran_formats[i].fourcc == fmt->fmt.pix.pixelformat) |
3078 | req->count = 2; | 2092 | break; |
3079 | if (req->count > v4l_nbufs) | ||
3080 | req->count = v4l_nbufs; | ||
3081 | fh->v4l_buffers.num_buffers = req->count; | ||
3082 | 2093 | ||
3083 | if (v4l_fbuffer_alloc(file)) { | 2094 | if (i == NUM_FORMATS) { |
3084 | res = -ENOMEM; | 2095 | mutex_unlock(&zr->resource_lock); |
3085 | goto v4l2reqbuf_unlock_and_return; | 2096 | return -EINVAL; |
3086 | } | 2097 | } |
3087 | 2098 | ||
3088 | /* The next mmap will map the V4L buffers */ | 2099 | bpp = (zoran_formats[i].depth + 7) / 8; |
3089 | fh->map_mode = ZORAN_MAP_MODE_RAW; | 2100 | fmt->fmt.pix.width &= ~((bpp == 2) ? 1 : 3); |
2101 | if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) | ||
2102 | fmt->fmt.pix.width = BUZ_MAX_WIDTH; | ||
2103 | if (fmt->fmt.pix.width < BUZ_MIN_WIDTH) | ||
2104 | fmt->fmt.pix.width = BUZ_MIN_WIDTH; | ||
2105 | if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT) | ||
2106 | fmt->fmt.pix.height = BUZ_MAX_HEIGHT; | ||
2107 | if (fmt->fmt.pix.height < BUZ_MIN_HEIGHT) | ||
2108 | fmt->fmt.pix.height = BUZ_MIN_HEIGHT; | ||
2109 | mutex_unlock(&zr->resource_lock); | ||
3090 | 2110 | ||
3091 | } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC || | 2111 | return 0; |
3092 | fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { | 2112 | } |
3093 | 2113 | ||
3094 | /* we need to calculate size ourselves now */ | 2114 | static int zoran_s_fmt_vid_overlay(struct file *file, void *__fh, |
3095 | if (req->count < 4) | 2115 | struct v4l2_format *fmt) |
3096 | req->count = 4; | 2116 | { |
3097 | if (req->count > jpg_nbufs) | 2117 | struct zoran_fh *fh = __fh; |
3098 | req->count = jpg_nbufs; | 2118 | struct zoran *zr = fh->zr; |
3099 | fh->jpg_buffers.num_buffers = req->count; | 2119 | int res; |
3100 | fh->jpg_buffers.buffer_size = | 2120 | |
3101 | zoran_v4l2_calc_bufsize(&fh->jpg_settings); | 2121 | dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n", |
2122 | fmt->fmt.win.w.left, fmt->fmt.win.w.top, | ||
2123 | fmt->fmt.win.w.width, | ||
2124 | fmt->fmt.win.w.height, | ||
2125 | fmt->fmt.win.clipcount, | ||
2126 | fmt->fmt.win.bitmap); | ||
2127 | mutex_lock(&zr->resource_lock); | ||
2128 | res = setup_window(fh, fmt->fmt.win.w.left, fmt->fmt.win.w.top, | ||
2129 | fmt->fmt.win.w.width, fmt->fmt.win.w.height, | ||
2130 | (struct v4l2_clip __user *)fmt->fmt.win.clips, | ||
2131 | fmt->fmt.win.clipcount, fmt->fmt.win.bitmap); | ||
2132 | mutex_unlock(&zr->resource_lock); | ||
2133 | return res; | ||
2134 | } | ||
3102 | 2135 | ||
3103 | if (jpg_fbuffer_alloc(file)) { | 2136 | static int zoran_s_fmt_vid_out(struct file *file, void *__fh, |
3104 | res = -ENOMEM; | 2137 | struct v4l2_format *fmt) |
3105 | goto v4l2reqbuf_unlock_and_return; | 2138 | { |
3106 | } | 2139 | struct zoran_fh *fh = __fh; |
2140 | struct zoran *zr = fh->zr; | ||
2141 | __le32 printformat = __cpu_to_le32(fmt->fmt.pix.pixelformat); | ||
2142 | struct zoran_jpg_settings settings; | ||
2143 | int res = 0; | ||
3107 | 2144 | ||
3108 | /* The next mmap will map the MJPEG buffers */ | 2145 | dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n", |
3109 | if (req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) | 2146 | fmt->fmt.pix.width, fmt->fmt.pix.height, |
3110 | fh->map_mode = ZORAN_MAP_MODE_JPG_REC; | 2147 | fmt->fmt.pix.pixelformat, |
3111 | else | 2148 | (char *) &printformat); |
3112 | fh->map_mode = ZORAN_MAP_MODE_JPG_PLAY; | 2149 | if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) |
2150 | return -EINVAL; | ||
3113 | 2151 | ||
3114 | } else { | 2152 | mutex_lock(&zr->resource_lock); |
3115 | dprintk(1, | ||
3116 | KERN_ERR | ||
3117 | "%s: VIDIOC_REQBUFS - unknown type %d\n", | ||
3118 | ZR_DEVNAME(zr), req->type); | ||
3119 | res = -EINVAL; | ||
3120 | goto v4l2reqbuf_unlock_and_return; | ||
3121 | } | ||
3122 | v4l2reqbuf_unlock_and_return: | ||
3123 | mutex_unlock(&zr->resource_lock); | ||
3124 | 2153 | ||
3125 | return 0; | 2154 | if (fh->buffers.allocated) { |
2155 | dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", | ||
2156 | ZR_DEVNAME(zr)); | ||
2157 | res = -EBUSY; | ||
2158 | goto sfmtjpg_unlock_and_return; | ||
3126 | } | 2159 | } |
3127 | break; | ||
3128 | 2160 | ||
3129 | case VIDIOC_QUERYBUF: | 2161 | settings = fh->jpg_settings; |
3130 | { | ||
3131 | struct v4l2_buffer *buf = arg; | ||
3132 | __u32 type = buf->type; | ||
3133 | int index = buf->index, res; | ||
3134 | 2162 | ||
3135 | dprintk(3, | 2163 | /* we actually need to set 'real' parameters now */ |
3136 | KERN_DEBUG | 2164 | if (fmt->fmt.pix.height * 2 > BUZ_MAX_HEIGHT) |
3137 | "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n", | 2165 | settings.TmpDcm = 1; |
3138 | ZR_DEVNAME(zr), buf->index, buf->type); | 2166 | else |
3139 | 2167 | settings.TmpDcm = 2; | |
3140 | memset(buf, 0, sizeof(*buf)); | 2168 | settings.decimation = 0; |
3141 | buf->type = type; | 2169 | if (fmt->fmt.pix.height <= fh->jpg_settings.img_height / 2) |
3142 | buf->index = index; | 2170 | settings.VerDcm = 2; |
3143 | 2171 | else | |
3144 | mutex_lock(&zr->resource_lock); | 2172 | settings.VerDcm = 1; |
3145 | res = zoran_v4l2_buffer_status(file, buf, buf->index); | 2173 | if (fmt->fmt.pix.width <= fh->jpg_settings.img_width / 4) |
3146 | mutex_unlock(&zr->resource_lock); | 2174 | settings.HorDcm = 4; |
2175 | else if (fmt->fmt.pix.width <= fh->jpg_settings.img_width / 2) | ||
2176 | settings.HorDcm = 2; | ||
2177 | else | ||
2178 | settings.HorDcm = 1; | ||
2179 | if (settings.TmpDcm == 1) | ||
2180 | settings.field_per_buff = 2; | ||
2181 | else | ||
2182 | settings.field_per_buff = 1; | ||
3147 | 2183 | ||
3148 | return res; | 2184 | if (settings.HorDcm > 1) { |
2185 | settings.img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0; | ||
2186 | settings.img_width = (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH; | ||
2187 | } else { | ||
2188 | settings.img_x = 0; | ||
2189 | settings.img_width = BUZ_MAX_WIDTH; | ||
3149 | } | 2190 | } |
3150 | break; | ||
3151 | 2191 | ||
3152 | case VIDIOC_QBUF: | 2192 | /* check */ |
3153 | { | 2193 | res = zoran_check_jpg_settings(zr, &settings, 0); |
3154 | struct v4l2_buffer *buf = arg; | 2194 | if (res) |
3155 | int res = 0, codec_mode, buf_type; | 2195 | goto sfmtjpg_unlock_and_return; |
3156 | 2196 | ||
3157 | dprintk(3, | 2197 | /* it's ok, so set them */ |
3158 | KERN_DEBUG "%s: VIDIOC_QBUF - type=%d, index=%d\n", | 2198 | fh->jpg_settings = settings; |
3159 | ZR_DEVNAME(zr), buf->type, buf->index); | ||
3160 | 2199 | ||
3161 | mutex_lock(&zr->resource_lock); | 2200 | map_mode_jpg(fh, fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT); |
2201 | fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); | ||
3162 | 2202 | ||
3163 | switch (fh->map_mode) { | 2203 | /* tell the user what we actually did */ |
3164 | case ZORAN_MAP_MODE_RAW: | 2204 | fmt->fmt.pix.width = settings.img_width / settings.HorDcm; |
3165 | if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { | 2205 | fmt->fmt.pix.height = settings.img_height * 2 / |
3166 | dprintk(1, | 2206 | (settings.TmpDcm * settings.VerDcm); |
3167 | KERN_ERR | 2207 | if (settings.TmpDcm == 1) |
3168 | "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", | 2208 | fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? |
3169 | ZR_DEVNAME(zr), buf->type, fh->map_mode); | 2209 | V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT); |
3170 | res = -EINVAL; | 2210 | else |
3171 | goto qbuf_unlock_and_return; | 2211 | fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? |
3172 | } | 2212 | V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); |
2213 | fmt->fmt.pix.bytesperline = 0; | ||
2214 | fmt->fmt.pix.sizeimage = fh->buffers.buffer_size; | ||
2215 | fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; | ||
3173 | 2216 | ||
3174 | res = zoran_v4l_queue_frame(file, buf->index); | 2217 | sfmtjpg_unlock_and_return: |
3175 | if (res) | 2218 | mutex_unlock(&zr->resource_lock); |
3176 | goto qbuf_unlock_and_return; | 2219 | return res; |
3177 | if (!zr->v4l_memgrab_active && | 2220 | } |
3178 | fh->v4l_buffers.active == ZORAN_LOCKED) | ||
3179 | zr36057_set_memgrab(zr, 1); | ||
3180 | break; | ||
3181 | 2221 | ||
3182 | case ZORAN_MAP_MODE_JPG_REC: | 2222 | static int zoran_s_fmt_vid_cap(struct file *file, void *__fh, |
3183 | case ZORAN_MAP_MODE_JPG_PLAY: | 2223 | struct v4l2_format *fmt) |
3184 | if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { | 2224 | { |
3185 | buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | 2225 | struct zoran_fh *fh = __fh; |
3186 | codec_mode = BUZ_MODE_MOTION_DECOMPRESS; | 2226 | struct zoran *zr = fh->zr; |
3187 | } else { | 2227 | int i; |
3188 | buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 2228 | int res = 0; |
3189 | codec_mode = BUZ_MODE_MOTION_COMPRESS; | ||
3190 | } | ||
3191 | 2229 | ||
3192 | if (buf->type != buf_type) { | 2230 | if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) |
3193 | dprintk(1, | 2231 | return zoran_s_fmt_vid_out(file, fh, fmt); |
3194 | KERN_ERR | ||
3195 | "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", | ||
3196 | ZR_DEVNAME(zr), buf->type, fh->map_mode); | ||
3197 | res = -EINVAL; | ||
3198 | goto qbuf_unlock_and_return; | ||
3199 | } | ||
3200 | 2232 | ||
3201 | res = | 2233 | for (i = 0; i < NUM_FORMATS; i++) |
3202 | zoran_jpg_queue_frame(file, buf->index, | 2234 | if (fmt->fmt.pix.pixelformat == zoran_formats[i].fourcc) |
3203 | codec_mode); | ||
3204 | if (res != 0) | ||
3205 | goto qbuf_unlock_and_return; | ||
3206 | if (zr->codec_mode == BUZ_MODE_IDLE && | ||
3207 | fh->jpg_buffers.active == ZORAN_LOCKED) { | ||
3208 | zr36057_enable_jpg(zr, codec_mode); | ||
3209 | } | ||
3210 | break; | 2235 | break; |
3211 | 2236 | if (i == NUM_FORMATS) { | |
3212 | default: | 2237 | dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x\n", |
3213 | dprintk(1, | 2238 | ZR_DEVNAME(zr), fmt->fmt.pix.pixelformat); |
3214 | KERN_ERR | 2239 | return -EINVAL; |
3215 | "%s: VIDIOC_QBUF - unsupported type %d\n", | ||
3216 | ZR_DEVNAME(zr), buf->type); | ||
3217 | res = -EINVAL; | ||
3218 | goto qbuf_unlock_and_return; | ||
3219 | } | ||
3220 | qbuf_unlock_and_return: | ||
3221 | mutex_unlock(&zr->resource_lock); | ||
3222 | |||
3223 | return res; | ||
3224 | } | 2240 | } |
3225 | break; | ||
3226 | 2241 | ||
3227 | case VIDIOC_DQBUF: | 2242 | mutex_lock(&zr->resource_lock); |
3228 | { | ||
3229 | struct v4l2_buffer *buf = arg; | ||
3230 | int res = 0, buf_type, num = -1; /* compiler borks here (?) */ | ||
3231 | |||
3232 | dprintk(3, KERN_DEBUG "%s: VIDIOC_DQBUF - type=%d\n", | ||
3233 | ZR_DEVNAME(zr), buf->type); | ||
3234 | |||
3235 | mutex_lock(&zr->resource_lock); | ||
3236 | 2243 | ||
3237 | switch (fh->map_mode) { | 2244 | if ((fh->map_mode != ZORAN_MAP_MODE_RAW && fh->buffers.allocated) || |
3238 | case ZORAN_MAP_MODE_RAW: | 2245 | fh->buffers.active != ZORAN_FREE) { |
3239 | if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { | 2246 | dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", |
3240 | dprintk(1, | 2247 | ZR_DEVNAME(zr)); |
3241 | KERN_ERR | 2248 | res = -EBUSY; |
3242 | "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", | 2249 | goto sfmtv4l_unlock_and_return; |
3243 | ZR_DEVNAME(zr), buf->type, fh->map_mode); | 2250 | } |
3244 | res = -EINVAL; | 2251 | if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT) |
3245 | goto dqbuf_unlock_and_return; | 2252 | fmt->fmt.pix.height = BUZ_MAX_HEIGHT; |
3246 | } | 2253 | if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) |
2254 | fmt->fmt.pix.width = BUZ_MAX_WIDTH; | ||
2255 | |||
2256 | map_mode_raw(fh); | ||
2257 | |||
2258 | res = zoran_v4l_set_format(fh, fmt->fmt.pix.width, fmt->fmt.pix.height, | ||
2259 | &zoran_formats[i]); | ||
2260 | if (res) | ||
2261 | goto sfmtv4l_unlock_and_return; | ||
2262 | |||
2263 | /* tell the user the results/missing stuff */ | ||
2264 | fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline; | ||
2265 | fmt->fmt.pix.sizeimage = fh->v4l_settings.height * fh->v4l_settings.bytesperline; | ||
2266 | fmt->fmt.pix.colorspace = fh->v4l_settings.format->colorspace; | ||
2267 | if (BUZ_MAX_HEIGHT < (fh->v4l_settings.height * 2)) | ||
2268 | fmt->fmt.pix.field = V4L2_FIELD_INTERLACED; | ||
2269 | else | ||
2270 | fmt->fmt.pix.field = V4L2_FIELD_TOP; | ||
3247 | 2271 | ||
3248 | num = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME]; | 2272 | sfmtv4l_unlock_and_return: |
3249 | if (file->f_flags & O_NONBLOCK && | 2273 | mutex_unlock(&zr->resource_lock); |
3250 | zr->v4l_buffers.buffer[num].state != | 2274 | return res; |
3251 | BUZ_STATE_DONE) { | 2275 | } |
3252 | res = -EAGAIN; | ||
3253 | goto dqbuf_unlock_and_return; | ||
3254 | } | ||
3255 | res = v4l_sync(file, num); | ||
3256 | if (res) | ||
3257 | goto dqbuf_unlock_and_return; | ||
3258 | else | ||
3259 | zr->v4l_sync_tail++; | ||
3260 | res = zoran_v4l2_buffer_status(file, buf, num); | ||
3261 | break; | ||
3262 | 2276 | ||
3263 | case ZORAN_MAP_MODE_JPG_REC: | 2277 | static int zoran_g_fbuf(struct file *file, void *__fh, |
3264 | case ZORAN_MAP_MODE_JPG_PLAY: | 2278 | struct v4l2_framebuffer *fb) |
3265 | { | 2279 | { |
3266 | struct zoran_sync bs; | 2280 | struct zoran_fh *fh = __fh; |
2281 | struct zoran *zr = fh->zr; | ||
3267 | 2282 | ||
3268 | if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) | 2283 | memset(fb, 0, sizeof(*fb)); |
3269 | buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | 2284 | mutex_lock(&zr->resource_lock); |
3270 | else | 2285 | fb->base = zr->vbuf_base; |
3271 | buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 2286 | fb->fmt.width = zr->vbuf_width; |
2287 | fb->fmt.height = zr->vbuf_height; | ||
2288 | if (zr->overlay_settings.format) | ||
2289 | fb->fmt.pixelformat = fh->overlay_settings.format->fourcc; | ||
2290 | fb->fmt.bytesperline = zr->vbuf_bytesperline; | ||
2291 | mutex_unlock(&zr->resource_lock); | ||
2292 | fb->fmt.colorspace = V4L2_COLORSPACE_SRGB; | ||
2293 | fb->fmt.field = V4L2_FIELD_INTERLACED; | ||
2294 | fb->flags = V4L2_FBUF_FLAG_OVERLAY; | ||
2295 | fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; | ||
3272 | 2296 | ||
3273 | if (buf->type != buf_type) { | 2297 | return 0; |
3274 | dprintk(1, | 2298 | } |
3275 | KERN_ERR | ||
3276 | "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", | ||
3277 | ZR_DEVNAME(zr), buf->type, fh->map_mode); | ||
3278 | res = -EINVAL; | ||
3279 | goto dqbuf_unlock_and_return; | ||
3280 | } | ||
3281 | 2299 | ||
3282 | num = | 2300 | static int zoran_s_fbuf(struct file *file, void *__fh, |
3283 | zr->jpg_pend[zr-> | 2301 | struct v4l2_framebuffer *fb) |
3284 | jpg_que_tail & BUZ_MASK_FRAME]; | 2302 | { |
2303 | struct zoran_fh *fh = __fh; | ||
2304 | struct zoran *zr = fh->zr; | ||
2305 | int i, res = 0; | ||
2306 | __le32 printformat = __cpu_to_le32(fb->fmt.pixelformat); | ||
3285 | 2307 | ||
3286 | if (file->f_flags & O_NONBLOCK && | 2308 | for (i = 0; i < NUM_FORMATS; i++) |
3287 | zr->jpg_buffers.buffer[num].state != | 2309 | if (zoran_formats[i].fourcc == fb->fmt.pixelformat) |
3288 | BUZ_STATE_DONE) { | ||
3289 | res = -EAGAIN; | ||
3290 | goto dqbuf_unlock_and_return; | ||
3291 | } | ||
3292 | res = jpg_sync(file, &bs); | ||
3293 | if (res) | ||
3294 | goto dqbuf_unlock_and_return; | ||
3295 | res = | ||
3296 | zoran_v4l2_buffer_status(file, buf, bs.frame); | ||
3297 | break; | 2310 | break; |
3298 | } | 2311 | if (i == NUM_FORMATS) { |
3299 | 2312 | dprintk(1, KERN_ERR "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n", | |
3300 | default: | 2313 | ZR_DEVNAME(zr), fb->fmt.pixelformat, |
3301 | dprintk(1, | 2314 | (char *)&printformat); |
3302 | KERN_ERR | 2315 | return -EINVAL; |
3303 | "%s: VIDIOC_DQBUF - unsupported type %d\n", | ||
3304 | ZR_DEVNAME(zr), buf->type); | ||
3305 | res = -EINVAL; | ||
3306 | goto dqbuf_unlock_and_return; | ||
3307 | } | ||
3308 | dqbuf_unlock_and_return: | ||
3309 | mutex_unlock(&zr->resource_lock); | ||
3310 | |||
3311 | return res; | ||
3312 | } | 2316 | } |
3313 | break; | ||
3314 | 2317 | ||
3315 | case VIDIOC_STREAMON: | 2318 | mutex_lock(&zr->resource_lock); |
3316 | { | 2319 | res = setup_fbuffer(fh, fb->base, &zoran_formats[i], fb->fmt.width, |
3317 | int res = 0; | 2320 | fb->fmt.height, fb->fmt.bytesperline); |
2321 | mutex_unlock(&zr->resource_lock); | ||
3318 | 2322 | ||
3319 | dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr)); | 2323 | return res; |
2324 | } | ||
3320 | 2325 | ||
3321 | mutex_lock(&zr->resource_lock); | 2326 | static int zoran_overlay(struct file *file, void *__fh, unsigned int on) |
2327 | { | ||
2328 | struct zoran_fh *fh = __fh; | ||
2329 | struct zoran *zr = fh->zr; | ||
2330 | int res; | ||
3322 | 2331 | ||
3323 | switch (fh->map_mode) { | 2332 | mutex_lock(&zr->resource_lock); |
3324 | case ZORAN_MAP_MODE_RAW: /* raw capture */ | 2333 | res = setup_overlay(fh, on); |
3325 | if (zr->v4l_buffers.active != ZORAN_ACTIVE || | 2334 | mutex_unlock(&zr->resource_lock); |
3326 | fh->v4l_buffers.active != ZORAN_ACTIVE) { | ||
3327 | res = -EBUSY; | ||
3328 | goto strmon_unlock_and_return; | ||
3329 | } | ||
3330 | 2335 | ||
3331 | zr->v4l_buffers.active = fh->v4l_buffers.active = | 2336 | return res; |
3332 | ZORAN_LOCKED; | 2337 | } |
3333 | zr->v4l_settings = fh->v4l_settings; | ||
3334 | 2338 | ||
3335 | zr->v4l_sync_tail = zr->v4l_pend_tail; | 2339 | static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type type); |
3336 | if (!zr->v4l_memgrab_active && | ||
3337 | zr->v4l_pend_head != zr->v4l_pend_tail) { | ||
3338 | zr36057_set_memgrab(zr, 1); | ||
3339 | } | ||
3340 | break; | ||
3341 | 2340 | ||
3342 | case ZORAN_MAP_MODE_JPG_REC: | 2341 | static int zoran_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffers *req) |
3343 | case ZORAN_MAP_MODE_JPG_PLAY: | 2342 | { |
3344 | /* what is the codec mode right now? */ | 2343 | struct zoran_fh *fh = __fh; |
3345 | if (zr->jpg_buffers.active != ZORAN_ACTIVE || | 2344 | struct zoran *zr = fh->zr; |
3346 | fh->jpg_buffers.active != ZORAN_ACTIVE) { | 2345 | int res = 0; |
3347 | res = -EBUSY; | ||
3348 | goto strmon_unlock_and_return; | ||
3349 | } | ||
3350 | 2346 | ||
3351 | zr->jpg_buffers.active = fh->jpg_buffers.active = | 2347 | if (req->memory != V4L2_MEMORY_MMAP) { |
3352 | ZORAN_LOCKED; | 2348 | dprintk(2, |
2349 | KERN_ERR | ||
2350 | "%s: only MEMORY_MMAP capture is supported, not %d\n", | ||
2351 | ZR_DEVNAME(zr), req->memory); | ||
2352 | return -EINVAL; | ||
2353 | } | ||
3353 | 2354 | ||
3354 | if (zr->jpg_que_head != zr->jpg_que_tail) { | 2355 | if (req->count == 0) |
3355 | /* Start the jpeg codec when the first frame is queued */ | 2356 | return zoran_streamoff(file, fh, req->type); |
3356 | jpeg_start(zr); | ||
3357 | } | ||
3358 | 2357 | ||
3359 | break; | 2358 | mutex_lock(&zr->resource_lock); |
3360 | default: | 2359 | if (fh->buffers.allocated) { |
3361 | dprintk(1, | 2360 | dprintk(2, |
3362 | KERN_ERR | 2361 | KERN_ERR |
3363 | "%s: VIDIOC_STREAMON - invalid map mode %d\n", | 2362 | "%s: VIDIOC_REQBUFS - buffers already allocated\n", |
3364 | ZR_DEVNAME(zr), fh->map_mode); | 2363 | ZR_DEVNAME(zr)); |
3365 | res = -EINVAL; | 2364 | res = -EBUSY; |
3366 | goto strmon_unlock_and_return; | 2365 | goto v4l2reqbuf_unlock_and_return; |
3367 | } | ||
3368 | strmon_unlock_and_return: | ||
3369 | mutex_unlock(&zr->resource_lock); | ||
3370 | |||
3371 | return res; | ||
3372 | } | 2366 | } |
3373 | break; | ||
3374 | 2367 | ||
3375 | case VIDIOC_STREAMOFF: | 2368 | if (fh->map_mode == ZORAN_MAP_MODE_RAW && |
3376 | { | 2369 | req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
3377 | int i, res = 0; | 2370 | /* control user input */ |
2371 | if (req->count < 2) | ||
2372 | req->count = 2; | ||
2373 | if (req->count > v4l_nbufs) | ||
2374 | req->count = v4l_nbufs; | ||
3378 | 2375 | ||
3379 | dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr)); | 2376 | /* The next mmap will map the V4L buffers */ |
2377 | map_mode_raw(fh); | ||
2378 | fh->buffers.num_buffers = req->count; | ||
3380 | 2379 | ||
3381 | mutex_lock(&zr->resource_lock); | 2380 | if (v4l_fbuffer_alloc(fh)) { |
2381 | res = -ENOMEM; | ||
2382 | goto v4l2reqbuf_unlock_and_return; | ||
2383 | } | ||
2384 | } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC || | ||
2385 | fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { | ||
2386 | /* we need to calculate size ourselves now */ | ||
2387 | if (req->count < 4) | ||
2388 | req->count = 4; | ||
2389 | if (req->count > jpg_nbufs) | ||
2390 | req->count = jpg_nbufs; | ||
3382 | 2391 | ||
3383 | switch (fh->map_mode) { | 2392 | /* The next mmap will map the MJPEG buffers */ |
3384 | case ZORAN_MAP_MODE_RAW: /* raw capture */ | 2393 | map_mode_jpg(fh, req->type == V4L2_BUF_TYPE_VIDEO_OUTPUT); |
3385 | if (fh->v4l_buffers.active == ZORAN_FREE && | 2394 | fh->buffers.num_buffers = req->count; |
3386 | zr->v4l_buffers.active != ZORAN_FREE) { | 2395 | fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); |
3387 | res = -EPERM; /* stay off other's settings! */ | ||
3388 | goto strmoff_unlock_and_return; | ||
3389 | } | ||
3390 | if (zr->v4l_buffers.active == ZORAN_FREE) | ||
3391 | goto strmoff_unlock_and_return; | ||
3392 | 2396 | ||
3393 | /* unload capture */ | 2397 | if (jpg_fbuffer_alloc(fh)) { |
3394 | if (zr->v4l_memgrab_active) { | 2398 | res = -ENOMEM; |
3395 | unsigned long flags; | 2399 | goto v4l2reqbuf_unlock_and_return; |
2400 | } | ||
2401 | } else { | ||
2402 | dprintk(1, | ||
2403 | KERN_ERR | ||
2404 | "%s: VIDIOC_REQBUFS - unknown type %d\n", | ||
2405 | ZR_DEVNAME(zr), req->type); | ||
2406 | res = -EINVAL; | ||
2407 | goto v4l2reqbuf_unlock_and_return; | ||
2408 | } | ||
2409 | v4l2reqbuf_unlock_and_return: | ||
2410 | mutex_unlock(&zr->resource_lock); | ||
3396 | 2411 | ||
3397 | spin_lock_irqsave(&zr->spinlock, flags); | 2412 | return res; |
3398 | zr36057_set_memgrab(zr, 0); | 2413 | } |
3399 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
3400 | } | ||
3401 | 2414 | ||
3402 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) | 2415 | static int zoran_querybuf(struct file *file, void *__fh, struct v4l2_buffer *buf) |
3403 | zr->v4l_buffers.buffer[i].state = | 2416 | { |
3404 | BUZ_STATE_USER; | 2417 | struct zoran_fh *fh = __fh; |
3405 | fh->v4l_buffers = zr->v4l_buffers; | 2418 | struct zoran *zr = fh->zr; |
2419 | int res; | ||
3406 | 2420 | ||
3407 | zr->v4l_buffers.active = fh->v4l_buffers.active = | 2421 | mutex_lock(&zr->resource_lock); |
3408 | ZORAN_FREE; | 2422 | res = zoran_v4l2_buffer_status(fh, buf, buf->index); |
2423 | mutex_unlock(&zr->resource_lock); | ||
3409 | 2424 | ||
3410 | zr->v4l_grab_seq = 0; | 2425 | return res; |
3411 | zr->v4l_pend_head = zr->v4l_pend_tail = 0; | 2426 | } |
3412 | zr->v4l_sync_tail = 0; | ||
3413 | 2427 | ||
3414 | break; | 2428 | static int zoran_qbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) |
2429 | { | ||
2430 | struct zoran_fh *fh = __fh; | ||
2431 | struct zoran *zr = fh->zr; | ||
2432 | int res = 0, codec_mode, buf_type; | ||
3415 | 2433 | ||
3416 | case ZORAN_MAP_MODE_JPG_REC: | 2434 | mutex_lock(&zr->resource_lock); |
3417 | case ZORAN_MAP_MODE_JPG_PLAY: | 2435 | |
3418 | if (fh->jpg_buffers.active == ZORAN_FREE && | 2436 | switch (fh->map_mode) { |
3419 | zr->jpg_buffers.active != ZORAN_FREE) { | 2437 | case ZORAN_MAP_MODE_RAW: |
3420 | res = -EPERM; /* stay off other's settings! */ | 2438 | if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
3421 | goto strmoff_unlock_and_return; | 2439 | dprintk(1, KERN_ERR |
3422 | } | 2440 | "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", |
3423 | if (zr->jpg_buffers.active == ZORAN_FREE) | 2441 | ZR_DEVNAME(zr), buf->type, fh->map_mode); |
3424 | goto strmoff_unlock_and_return; | ||
3425 | |||
3426 | res = | ||
3427 | jpg_qbuf(file, -1, | ||
3428 | (fh->map_mode == | ||
3429 | ZORAN_MAP_MODE_JPG_REC) ? | ||
3430 | BUZ_MODE_MOTION_COMPRESS : | ||
3431 | BUZ_MODE_MOTION_DECOMPRESS); | ||
3432 | if (res) | ||
3433 | goto strmoff_unlock_and_return; | ||
3434 | break; | ||
3435 | default: | ||
3436 | dprintk(1, | ||
3437 | KERN_ERR | ||
3438 | "%s: VIDIOC_STREAMOFF - invalid map mode %d\n", | ||
3439 | ZR_DEVNAME(zr), fh->map_mode); | ||
3440 | res = -EINVAL; | 2442 | res = -EINVAL; |
3441 | goto strmoff_unlock_and_return; | 2443 | goto qbuf_unlock_and_return; |
3442 | } | 2444 | } |
3443 | strmoff_unlock_and_return: | ||
3444 | mutex_unlock(&zr->resource_lock); | ||
3445 | 2445 | ||
3446 | return res; | 2446 | res = zoran_v4l_queue_frame(fh, buf->index); |
3447 | } | 2447 | if (res) |
2448 | goto qbuf_unlock_and_return; | ||
2449 | if (!zr->v4l_memgrab_active && fh->buffers.active == ZORAN_LOCKED) | ||
2450 | zr36057_set_memgrab(zr, 1); | ||
3448 | break; | 2451 | break; |
3449 | 2452 | ||
3450 | case VIDIOC_QUERYCTRL: | 2453 | case ZORAN_MAP_MODE_JPG_REC: |
3451 | { | 2454 | case ZORAN_MAP_MODE_JPG_PLAY: |
3452 | struct v4l2_queryctrl *ctrl = arg; | 2455 | if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { |
3453 | 2456 | buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | |
3454 | dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCTRL - id=%d\n", | 2457 | codec_mode = BUZ_MODE_MOTION_DECOMPRESS; |
3455 | ZR_DEVNAME(zr), ctrl->id); | 2458 | } else { |
3456 | 2459 | buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | |
3457 | /* we only support hue/saturation/contrast/brightness */ | 2460 | codec_mode = BUZ_MODE_MOTION_COMPRESS; |
3458 | if (ctrl->id < V4L2_CID_BRIGHTNESS || | ||
3459 | ctrl->id > V4L2_CID_HUE) | ||
3460 | return -EINVAL; | ||
3461 | else { | ||
3462 | int id = ctrl->id; | ||
3463 | memset(ctrl, 0, sizeof(*ctrl)); | ||
3464 | ctrl->id = id; | ||
3465 | } | 2461 | } |
3466 | 2462 | ||
3467 | switch (ctrl->id) { | 2463 | if (buf->type != buf_type) { |
3468 | case V4L2_CID_BRIGHTNESS: | 2464 | dprintk(1, KERN_ERR |
3469 | strncpy(ctrl->name, "Brightness", sizeof(ctrl->name)-1); | 2465 | "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", |
3470 | break; | 2466 | ZR_DEVNAME(zr), buf->type, fh->map_mode); |
3471 | case V4L2_CID_CONTRAST: | 2467 | res = -EINVAL; |
3472 | strncpy(ctrl->name, "Contrast", sizeof(ctrl->name)-1); | 2468 | goto qbuf_unlock_and_return; |
3473 | break; | ||
3474 | case V4L2_CID_SATURATION: | ||
3475 | strncpy(ctrl->name, "Saturation", sizeof(ctrl->name)-1); | ||
3476 | break; | ||
3477 | case V4L2_CID_HUE: | ||
3478 | strncpy(ctrl->name, "Hue", sizeof(ctrl->name)-1); | ||
3479 | break; | ||
3480 | } | 2469 | } |
3481 | 2470 | ||
3482 | ctrl->minimum = 0; | 2471 | res = zoran_jpg_queue_frame(fh, buf->index, codec_mode); |
3483 | ctrl->maximum = 65535; | 2472 | if (res != 0) |
3484 | ctrl->step = 1; | 2473 | goto qbuf_unlock_and_return; |
3485 | ctrl->default_value = 32768; | 2474 | if (zr->codec_mode == BUZ_MODE_IDLE && |
3486 | ctrl->type = V4L2_CTRL_TYPE_INTEGER; | 2475 | fh->buffers.active == ZORAN_LOCKED) |
2476 | zr36057_enable_jpg(zr, codec_mode); | ||
3487 | 2477 | ||
3488 | return 0; | ||
3489 | } | ||
3490 | break; | 2478 | break; |
3491 | 2479 | ||
3492 | case VIDIOC_G_CTRL: | 2480 | default: |
3493 | { | 2481 | dprintk(1, KERN_ERR |
3494 | struct v4l2_control *ctrl = arg; | 2482 | "%s: VIDIOC_QBUF - unsupported type %d\n", |
3495 | 2483 | ZR_DEVNAME(zr), buf->type); | |
3496 | dprintk(3, KERN_DEBUG "%s: VIDIOC_G_CTRL - id=%d\n", | 2484 | res = -EINVAL; |
3497 | ZR_DEVNAME(zr), ctrl->id); | ||
3498 | |||
3499 | /* we only support hue/saturation/contrast/brightness */ | ||
3500 | if (ctrl->id < V4L2_CID_BRIGHTNESS || | ||
3501 | ctrl->id > V4L2_CID_HUE) | ||
3502 | return -EINVAL; | ||
3503 | |||
3504 | mutex_lock(&zr->resource_lock); | ||
3505 | switch (ctrl->id) { | ||
3506 | case V4L2_CID_BRIGHTNESS: | ||
3507 | ctrl->value = zr->brightness; | ||
3508 | break; | ||
3509 | case V4L2_CID_CONTRAST: | ||
3510 | ctrl->value = zr->contrast; | ||
3511 | break; | ||
3512 | case V4L2_CID_SATURATION: | ||
3513 | ctrl->value = zr->saturation; | ||
3514 | break; | ||
3515 | case V4L2_CID_HUE: | ||
3516 | ctrl->value = zr->hue; | ||
3517 | break; | ||
3518 | } | ||
3519 | mutex_unlock(&zr->resource_lock); | ||
3520 | |||
3521 | return 0; | ||
3522 | } | ||
3523 | break; | 2485 | break; |
2486 | } | ||
2487 | qbuf_unlock_and_return: | ||
2488 | mutex_unlock(&zr->resource_lock); | ||
3524 | 2489 | ||
3525 | case VIDIOC_S_CTRL: | 2490 | return res; |
3526 | { | 2491 | } |
3527 | struct v4l2_control *ctrl = arg; | ||
3528 | struct video_picture pict; | ||
3529 | 2492 | ||
3530 | dprintk(3, KERN_DEBUG "%s: VIDIOC_S_CTRL - id=%d\n", | 2493 | static int zoran_dqbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) |
3531 | ZR_DEVNAME(zr), ctrl->id); | 2494 | { |
2495 | struct zoran_fh *fh = __fh; | ||
2496 | struct zoran *zr = fh->zr; | ||
2497 | int res = 0, buf_type, num = -1; /* compiler borks here (?) */ | ||
3532 | 2498 | ||
3533 | /* we only support hue/saturation/contrast/brightness */ | 2499 | mutex_lock(&zr->resource_lock); |
3534 | if (ctrl->id < V4L2_CID_BRIGHTNESS || | ||
3535 | ctrl->id > V4L2_CID_HUE) | ||
3536 | return -EINVAL; | ||
3537 | 2500 | ||
3538 | if (ctrl->value < 0 || ctrl->value > 65535) { | 2501 | switch (fh->map_mode) { |
3539 | dprintk(1, | 2502 | case ZORAN_MAP_MODE_RAW: |
3540 | KERN_ERR | 2503 | if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
3541 | "%s: VIDIOC_S_CTRL - invalid value %d for id=%d\n", | 2504 | dprintk(1, KERN_ERR |
3542 | ZR_DEVNAME(zr), ctrl->value, ctrl->id); | 2505 | "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", |
3543 | return -EINVAL; | 2506 | ZR_DEVNAME(zr), buf->type, fh->map_mode); |
2507 | res = -EINVAL; | ||
2508 | goto dqbuf_unlock_and_return; | ||
3544 | } | 2509 | } |
3545 | 2510 | ||
3546 | mutex_lock(&zr->resource_lock); | 2511 | num = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME]; |
3547 | switch (ctrl->id) { | 2512 | if (file->f_flags & O_NONBLOCK && |
3548 | case V4L2_CID_BRIGHTNESS: | 2513 | zr->v4l_buffers.buffer[num].state != BUZ_STATE_DONE) { |
3549 | zr->brightness = ctrl->value; | 2514 | res = -EAGAIN; |
3550 | break; | 2515 | goto dqbuf_unlock_and_return; |
3551 | case V4L2_CID_CONTRAST: | ||
3552 | zr->contrast = ctrl->value; | ||
3553 | break; | ||
3554 | case V4L2_CID_SATURATION: | ||
3555 | zr->saturation = ctrl->value; | ||
3556 | break; | ||
3557 | case V4L2_CID_HUE: | ||
3558 | zr->hue = ctrl->value; | ||
3559 | break; | ||
3560 | } | 2516 | } |
3561 | pict.brightness = zr->brightness; | 2517 | res = v4l_sync(fh, num); |
3562 | pict.contrast = zr->contrast; | 2518 | if (res) |
3563 | pict.colour = zr->saturation; | 2519 | goto dqbuf_unlock_and_return; |
3564 | pict.hue = zr->hue; | 2520 | zr->v4l_sync_tail++; |
3565 | 2521 | res = zoran_v4l2_buffer_status(fh, buf, num); | |
3566 | decoder_command(zr, DECODER_SET_PICTURE, &pict); | ||
3567 | |||
3568 | mutex_unlock(&zr->resource_lock); | ||
3569 | |||
3570 | return 0; | ||
3571 | } | ||
3572 | break; | 2522 | break; |
3573 | 2523 | ||
3574 | case VIDIOC_ENUMSTD: | 2524 | case ZORAN_MAP_MODE_JPG_REC: |
2525 | case ZORAN_MAP_MODE_JPG_PLAY: | ||
3575 | { | 2526 | { |
3576 | struct v4l2_standard *std = arg; | 2527 | struct zoran_sync bs; |
3577 | 2528 | ||
3578 | dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMSTD - index=%d\n", | 2529 | if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) |
3579 | ZR_DEVNAME(zr), std->index); | 2530 | buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
2531 | else | ||
2532 | buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | ||
3580 | 2533 | ||
3581 | if (std->index < 0 || std->index >= (zr->card.norms + 1)) | 2534 | if (buf->type != buf_type) { |
3582 | return -EINVAL; | 2535 | dprintk(1, KERN_ERR |
3583 | else { | 2536 | "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", |
3584 | int id = std->index; | 2537 | ZR_DEVNAME(zr), buf->type, fh->map_mode); |
3585 | memset(std, 0, sizeof(*std)); | 2538 | res = -EINVAL; |
3586 | std->index = id; | 2539 | goto dqbuf_unlock_and_return; |
3587 | } | 2540 | } |
3588 | 2541 | ||
3589 | if (std->index == zr->card.norms) { | 2542 | num = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME]; |
3590 | /* if we have autodetect, ... */ | ||
3591 | struct video_decoder_capability caps; | ||
3592 | decoder_command(zr, DECODER_GET_CAPABILITIES, | ||
3593 | &caps); | ||
3594 | if (caps.flags & VIDEO_DECODER_AUTO) { | ||
3595 | std->id = V4L2_STD_ALL; | ||
3596 | strncpy(std->name, "Autodetect", sizeof(std->name)-1); | ||
3597 | return 0; | ||
3598 | } else | ||
3599 | return -EINVAL; | ||
3600 | } | ||
3601 | switch (std->index) { | ||
3602 | case 0: | ||
3603 | std->id = V4L2_STD_PAL; | ||
3604 | strncpy(std->name, "PAL", sizeof(std->name)-1); | ||
3605 | std->frameperiod.numerator = 1; | ||
3606 | std->frameperiod.denominator = 25; | ||
3607 | std->framelines = zr->card.tvn[0]->Ht; | ||
3608 | break; | ||
3609 | case 1: | ||
3610 | std->id = V4L2_STD_NTSC; | ||
3611 | strncpy(std->name, "NTSC", sizeof(std->name)-1); | ||
3612 | std->frameperiod.numerator = 1001; | ||
3613 | std->frameperiod.denominator = 30000; | ||
3614 | std->framelines = zr->card.tvn[1]->Ht; | ||
3615 | break; | ||
3616 | case 2: | ||
3617 | std->id = V4L2_STD_SECAM; | ||
3618 | strncpy(std->name, "SECAM", sizeof(std->name)-1); | ||
3619 | std->frameperiod.numerator = 1; | ||
3620 | std->frameperiod.denominator = 25; | ||
3621 | std->framelines = zr->card.tvn[2]->Ht; | ||
3622 | break; | ||
3623 | } | ||
3624 | 2543 | ||
3625 | return 0; | 2544 | if (file->f_flags & O_NONBLOCK && |
2545 | zr->jpg_buffers.buffer[num].state != BUZ_STATE_DONE) { | ||
2546 | res = -EAGAIN; | ||
2547 | goto dqbuf_unlock_and_return; | ||
2548 | } | ||
2549 | res = jpg_sync(fh, &bs); | ||
2550 | if (res) | ||
2551 | goto dqbuf_unlock_and_return; | ||
2552 | res = zoran_v4l2_buffer_status(fh, buf, bs.frame); | ||
2553 | break; | ||
3626 | } | 2554 | } |
2555 | |||
2556 | default: | ||
2557 | dprintk(1, KERN_ERR | ||
2558 | "%s: VIDIOC_DQBUF - unsupported type %d\n", | ||
2559 | ZR_DEVNAME(zr), buf->type); | ||
2560 | res = -EINVAL; | ||
3627 | break; | 2561 | break; |
2562 | } | ||
2563 | dqbuf_unlock_and_return: | ||
2564 | mutex_unlock(&zr->resource_lock); | ||
3628 | 2565 | ||
3629 | case VIDIOC_G_STD: | 2566 | return res; |
3630 | { | 2567 | } |
3631 | v4l2_std_id *std = arg; | ||
3632 | int norm; | ||
3633 | 2568 | ||
3634 | dprintk(3, KERN_DEBUG "%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr)); | 2569 | static int zoran_streamon(struct file *file, void *__fh, enum v4l2_buf_type type) |
2570 | { | ||
2571 | struct zoran_fh *fh = __fh; | ||
2572 | struct zoran *zr = fh->zr; | ||
2573 | int res = 0; | ||
3635 | 2574 | ||
3636 | mutex_lock(&zr->resource_lock); | 2575 | mutex_lock(&zr->resource_lock); |
3637 | norm = zr->norm; | ||
3638 | mutex_unlock(&zr->resource_lock); | ||
3639 | 2576 | ||
3640 | switch (norm) { | 2577 | switch (fh->map_mode) { |
3641 | case VIDEO_MODE_PAL: | 2578 | case ZORAN_MAP_MODE_RAW: /* raw capture */ |
3642 | *std = V4L2_STD_PAL; | 2579 | if (zr->v4l_buffers.active != ZORAN_ACTIVE || |
3643 | break; | 2580 | fh->buffers.active != ZORAN_ACTIVE) { |
3644 | case VIDEO_MODE_NTSC: | 2581 | res = -EBUSY; |
3645 | *std = V4L2_STD_NTSC; | 2582 | goto strmon_unlock_and_return; |
3646 | break; | ||
3647 | case VIDEO_MODE_SECAM: | ||
3648 | *std = V4L2_STD_SECAM; | ||
3649 | break; | ||
3650 | } | 2583 | } |
3651 | 2584 | ||
3652 | return 0; | 2585 | zr->v4l_buffers.active = fh->buffers.active = ZORAN_LOCKED; |
3653 | } | 2586 | zr->v4l_settings = fh->v4l_settings; |
2587 | |||
2588 | zr->v4l_sync_tail = zr->v4l_pend_tail; | ||
2589 | if (!zr->v4l_memgrab_active && | ||
2590 | zr->v4l_pend_head != zr->v4l_pend_tail) { | ||
2591 | zr36057_set_memgrab(zr, 1); | ||
2592 | } | ||
3654 | break; | 2593 | break; |
3655 | 2594 | ||
3656 | case VIDIOC_S_STD: | 2595 | case ZORAN_MAP_MODE_JPG_REC: |
3657 | { | 2596 | case ZORAN_MAP_MODE_JPG_PLAY: |
3658 | int norm = -1, res = 0; | 2597 | /* what is the codec mode right now? */ |
3659 | v4l2_std_id *std = arg; | 2598 | if (zr->jpg_buffers.active != ZORAN_ACTIVE || |
3660 | 2599 | fh->buffers.active != ZORAN_ACTIVE) { | |
3661 | dprintk(3, KERN_DEBUG "%s: VIDIOC_S_STD - norm=0x%llx\n", | 2600 | res = -EBUSY; |
3662 | ZR_DEVNAME(zr), (unsigned long long)*std); | 2601 | goto strmon_unlock_and_return; |
3663 | |||
3664 | if ((*std & V4L2_STD_PAL) && !(*std & ~V4L2_STD_PAL)) | ||
3665 | norm = VIDEO_MODE_PAL; | ||
3666 | else if ((*std & V4L2_STD_NTSC) && !(*std & ~V4L2_STD_NTSC)) | ||
3667 | norm = VIDEO_MODE_NTSC; | ||
3668 | else if ((*std & V4L2_STD_SECAM) && !(*std & ~V4L2_STD_SECAM)) | ||
3669 | norm = VIDEO_MODE_SECAM; | ||
3670 | else if (*std == V4L2_STD_ALL) | ||
3671 | norm = VIDEO_MODE_AUTO; | ||
3672 | else { | ||
3673 | dprintk(1, | ||
3674 | KERN_ERR | ||
3675 | "%s: VIDIOC_S_STD - invalid norm 0x%llx\n", | ||
3676 | ZR_DEVNAME(zr), (unsigned long long)*std); | ||
3677 | return -EINVAL; | ||
3678 | } | 2602 | } |
3679 | 2603 | ||
3680 | mutex_lock(&zr->resource_lock); | 2604 | zr->jpg_buffers.active = fh->buffers.active = ZORAN_LOCKED; |
3681 | if ((res = zoran_set_norm(zr, norm))) | ||
3682 | goto sstd_unlock_and_return; | ||
3683 | 2605 | ||
3684 | res = wait_grab_pending(zr); | 2606 | if (zr->jpg_que_head != zr->jpg_que_tail) { |
3685 | sstd_unlock_and_return: | 2607 | /* Start the jpeg codec when the first frame is queued */ |
3686 | mutex_unlock(&zr->resource_lock); | 2608 | jpeg_start(zr); |
3687 | return res; | 2609 | } |
3688 | } | ||
3689 | break; | 2610 | break; |
3690 | 2611 | ||
3691 | case VIDIOC_ENUMINPUT: | 2612 | default: |
3692 | { | 2613 | dprintk(1, |
3693 | struct v4l2_input *inp = arg; | 2614 | KERN_ERR |
3694 | int status; | 2615 | "%s: VIDIOC_STREAMON - invalid map mode %d\n", |
3695 | 2616 | ZR_DEVNAME(zr), fh->map_mode); | |
3696 | dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMINPUT - index=%d\n", | 2617 | res = -EINVAL; |
3697 | ZR_DEVNAME(zr), inp->index); | 2618 | break; |
2619 | } | ||
2620 | strmon_unlock_and_return: | ||
2621 | mutex_unlock(&zr->resource_lock); | ||
3698 | 2622 | ||
3699 | if (inp->index < 0 || inp->index >= zr->card.inputs) | 2623 | return res; |
3700 | return -EINVAL; | 2624 | } |
3701 | else { | ||
3702 | int id = inp->index; | ||
3703 | memset(inp, 0, sizeof(*inp)); | ||
3704 | inp->index = id; | ||
3705 | } | ||
3706 | 2625 | ||
3707 | strncpy(inp->name, zr->card.input[inp->index].name, | 2626 | static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type type) |
3708 | sizeof(inp->name) - 1); | 2627 | { |
3709 | inp->type = V4L2_INPUT_TYPE_CAMERA; | 2628 | struct zoran_fh *fh = __fh; |
3710 | inp->std = V4L2_STD_ALL; | 2629 | struct zoran *zr = fh->zr; |
2630 | int i, res = 0; | ||
2631 | unsigned long flags; | ||
3711 | 2632 | ||
3712 | /* Get status of video decoder */ | 2633 | mutex_lock(&zr->resource_lock); |
3713 | mutex_lock(&zr->resource_lock); | ||
3714 | decoder_command(zr, DECODER_GET_STATUS, &status); | ||
3715 | mutex_unlock(&zr->resource_lock); | ||
3716 | 2634 | ||
3717 | if (!(status & DECODER_STATUS_GOOD)) { | 2635 | switch (fh->map_mode) { |
3718 | inp->status |= V4L2_IN_ST_NO_POWER; | 2636 | case ZORAN_MAP_MODE_RAW: /* raw capture */ |
3719 | inp->status |= V4L2_IN_ST_NO_SIGNAL; | 2637 | if (fh->buffers.active == ZORAN_FREE && |
2638 | zr->v4l_buffers.active != ZORAN_FREE) { | ||
2639 | res = -EPERM; /* stay off other's settings! */ | ||
2640 | goto strmoff_unlock_and_return; | ||
3720 | } | 2641 | } |
3721 | if (!(status & DECODER_STATUS_COLOR)) | 2642 | if (zr->v4l_buffers.active == ZORAN_FREE) |
3722 | inp->status |= V4L2_IN_ST_NO_COLOR; | 2643 | goto strmoff_unlock_and_return; |
3723 | 2644 | ||
3724 | return 0; | 2645 | spin_lock_irqsave(&zr->spinlock, flags); |
3725 | } | 2646 | /* unload capture */ |
3726 | break; | 2647 | if (zr->v4l_memgrab_active) { |
3727 | 2648 | ||
3728 | case VIDIOC_G_INPUT: | 2649 | zr36057_set_memgrab(zr, 0); |
3729 | { | 2650 | } |
3730 | int *input = arg; | ||
3731 | 2651 | ||
3732 | dprintk(3, KERN_DEBUG "%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr)); | 2652 | for (i = 0; i < fh->buffers.num_buffers; i++) |
2653 | zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER; | ||
2654 | fh->buffers = zr->v4l_buffers; | ||
3733 | 2655 | ||
3734 | mutex_lock(&zr->resource_lock); | 2656 | zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; |
3735 | *input = zr->input; | ||
3736 | mutex_unlock(&zr->resource_lock); | ||
3737 | 2657 | ||
3738 | return 0; | 2658 | zr->v4l_grab_seq = 0; |
3739 | } | 2659 | zr->v4l_pend_head = zr->v4l_pend_tail = 0; |
3740 | break; | 2660 | zr->v4l_sync_tail = 0; |
3741 | 2661 | ||
3742 | case VIDIOC_S_INPUT: | 2662 | spin_unlock_irqrestore(&zr->spinlock, flags); |
3743 | { | ||
3744 | int *input = arg, res = 0; | ||
3745 | 2663 | ||
3746 | dprintk(3, KERN_DEBUG "%s: VIDIOC_S_INPUT - input=%d\n", | 2664 | break; |
3747 | ZR_DEVNAME(zr), *input); | ||
3748 | 2665 | ||
3749 | mutex_lock(&zr->resource_lock); | 2666 | case ZORAN_MAP_MODE_JPG_REC: |
3750 | if ((res = zoran_set_input(zr, *input))) | 2667 | case ZORAN_MAP_MODE_JPG_PLAY: |
3751 | goto sinput_unlock_and_return; | 2668 | if (fh->buffers.active == ZORAN_FREE && |
2669 | zr->jpg_buffers.active != ZORAN_FREE) { | ||
2670 | res = -EPERM; /* stay off other's settings! */ | ||
2671 | goto strmoff_unlock_and_return; | ||
2672 | } | ||
2673 | if (zr->jpg_buffers.active == ZORAN_FREE) | ||
2674 | goto strmoff_unlock_and_return; | ||
3752 | 2675 | ||
3753 | /* Make sure the changes come into effect */ | 2676 | res = jpg_qbuf(fh, -1, |
3754 | res = wait_grab_pending(zr); | 2677 | (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? |
3755 | sinput_unlock_and_return: | 2678 | BUZ_MODE_MOTION_COMPRESS : |
3756 | mutex_unlock(&zr->resource_lock); | 2679 | BUZ_MODE_MOTION_DECOMPRESS); |
3757 | return res; | 2680 | if (res) |
3758 | } | 2681 | goto strmoff_unlock_and_return; |
2682 | break; | ||
2683 | default: | ||
2684 | dprintk(1, KERN_ERR | ||
2685 | "%s: VIDIOC_STREAMOFF - invalid map mode %d\n", | ||
2686 | ZR_DEVNAME(zr), fh->map_mode); | ||
2687 | res = -EINVAL; | ||
3759 | break; | 2688 | break; |
2689 | } | ||
2690 | strmoff_unlock_and_return: | ||
2691 | mutex_unlock(&zr->resource_lock); | ||
3760 | 2692 | ||
3761 | case VIDIOC_ENUMOUTPUT: | 2693 | return res; |
3762 | { | 2694 | } |
3763 | struct v4l2_output *outp = arg; | ||
3764 | 2695 | ||
3765 | dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMOUTPUT - index=%d\n", | 2696 | static int zoran_queryctrl(struct file *file, void *__fh, |
3766 | ZR_DEVNAME(zr), outp->index); | 2697 | struct v4l2_queryctrl *ctrl) |
2698 | { | ||
2699 | struct zoran_fh *fh = __fh; | ||
2700 | struct zoran *zr = fh->zr; | ||
3767 | 2701 | ||
3768 | if (outp->index != 0) | 2702 | /* we only support hue/saturation/contrast/brightness */ |
3769 | return -EINVAL; | 2703 | if (ctrl->id < V4L2_CID_BRIGHTNESS || |
2704 | ctrl->id > V4L2_CID_HUE) | ||
2705 | return -EINVAL; | ||
3770 | 2706 | ||
3771 | memset(outp, 0, sizeof(*outp)); | 2707 | decoder_call(zr, core, queryctrl, ctrl); |
3772 | outp->index = 0; | ||
3773 | outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY; | ||
3774 | strncpy(outp->name, "Autodetect", sizeof(outp->name)-1); | ||
3775 | 2708 | ||
3776 | return 0; | 2709 | return 0; |
3777 | } | 2710 | } |
3778 | break; | ||
3779 | 2711 | ||
3780 | case VIDIOC_G_OUTPUT: | 2712 | static int zoran_g_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl) |
3781 | { | 2713 | { |
3782 | int *output = arg; | 2714 | struct zoran_fh *fh = __fh; |
2715 | struct zoran *zr = fh->zr; | ||
3783 | 2716 | ||
3784 | dprintk(3, KERN_DEBUG "%s: VIDIOC_G_OUTPUT\n", ZR_DEVNAME(zr)); | 2717 | /* we only support hue/saturation/contrast/brightness */ |
2718 | if (ctrl->id < V4L2_CID_BRIGHTNESS || | ||
2719 | ctrl->id > V4L2_CID_HUE) | ||
2720 | return -EINVAL; | ||
3785 | 2721 | ||
3786 | *output = 0; | 2722 | mutex_lock(&zr->resource_lock); |
2723 | decoder_call(zr, core, g_ctrl, ctrl); | ||
2724 | mutex_unlock(&zr->resource_lock); | ||
3787 | 2725 | ||
3788 | return 0; | 2726 | return 0; |
3789 | } | 2727 | } |
3790 | break; | ||
3791 | 2728 | ||
3792 | case VIDIOC_S_OUTPUT: | 2729 | static int zoran_s_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl) |
3793 | { | 2730 | { |
3794 | int *output = arg; | 2731 | struct zoran_fh *fh = __fh; |
2732 | struct zoran *zr = fh->zr; | ||
3795 | 2733 | ||
3796 | dprintk(3, KERN_DEBUG "%s: VIDIOC_S_OUTPUT - output=%d\n", | 2734 | /* we only support hue/saturation/contrast/brightness */ |
3797 | ZR_DEVNAME(zr), *output); | 2735 | if (ctrl->id < V4L2_CID_BRIGHTNESS || |
2736 | ctrl->id > V4L2_CID_HUE) | ||
2737 | return -EINVAL; | ||
3798 | 2738 | ||
3799 | if (*output != 0) | 2739 | mutex_lock(&zr->resource_lock); |
3800 | return -EINVAL; | 2740 | decoder_call(zr, core, s_ctrl, ctrl); |
2741 | mutex_unlock(&zr->resource_lock); | ||
3801 | 2742 | ||
3802 | return 0; | 2743 | return 0; |
3803 | } | 2744 | } |
3804 | break; | ||
3805 | 2745 | ||
3806 | /* cropping (sub-frame capture) */ | 2746 | static int zoran_g_std(struct file *file, void *__fh, v4l2_std_id *std) |
3807 | case VIDIOC_CROPCAP: | 2747 | { |
3808 | { | 2748 | struct zoran_fh *fh = __fh; |
3809 | struct v4l2_cropcap *cropcap = arg; | 2749 | struct zoran *zr = fh->zr; |
3810 | int type = cropcap->type, res = 0; | ||
3811 | 2750 | ||
3812 | dprintk(3, KERN_ERR "%s: VIDIOC_CROPCAP - type=%d\n", | 2751 | mutex_lock(&zr->resource_lock); |
3813 | ZR_DEVNAME(zr), cropcap->type); | 2752 | *std = zr->norm; |
2753 | mutex_unlock(&zr->resource_lock); | ||
2754 | return 0; | ||
2755 | } | ||
3814 | 2756 | ||
3815 | memset(cropcap, 0, sizeof(*cropcap)); | 2757 | static int zoran_s_std(struct file *file, void *__fh, v4l2_std_id *std) |
3816 | cropcap->type = type; | 2758 | { |
2759 | struct zoran_fh *fh = __fh; | ||
2760 | struct zoran *zr = fh->zr; | ||
2761 | int res = 0; | ||
3817 | 2762 | ||
3818 | mutex_lock(&zr->resource_lock); | 2763 | mutex_lock(&zr->resource_lock); |
2764 | res = zoran_set_norm(zr, *std); | ||
2765 | if (res) | ||
2766 | goto sstd_unlock_and_return; | ||
3819 | 2767 | ||
3820 | if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && | 2768 | res = wait_grab_pending(zr); |
3821 | (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | 2769 | sstd_unlock_and_return: |
3822 | fh->map_mode == ZORAN_MAP_MODE_RAW)) { | 2770 | mutex_unlock(&zr->resource_lock); |
3823 | dprintk(1, | 2771 | return res; |
3824 | KERN_ERR | 2772 | } |
3825 | "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n", | ||
3826 | ZR_DEVNAME(zr)); | ||
3827 | res = -EINVAL; | ||
3828 | goto cropcap_unlock_and_return; | ||
3829 | } | ||
3830 | 2773 | ||
3831 | cropcap->bounds.top = cropcap->bounds.left = 0; | 2774 | static int zoran_enum_input(struct file *file, void *__fh, |
3832 | cropcap->bounds.width = BUZ_MAX_WIDTH; | 2775 | struct v4l2_input *inp) |
3833 | cropcap->bounds.height = BUZ_MAX_HEIGHT; | 2776 | { |
3834 | cropcap->defrect.top = cropcap->defrect.left = 0; | 2777 | struct zoran_fh *fh = __fh; |
3835 | cropcap->defrect.width = BUZ_MIN_WIDTH; | 2778 | struct zoran *zr = fh->zr; |
3836 | cropcap->defrect.height = BUZ_MIN_HEIGHT; | ||
3837 | cropcap_unlock_and_return: | ||
3838 | mutex_unlock(&zr->resource_lock); | ||
3839 | return res; | ||
3840 | } | ||
3841 | break; | ||
3842 | 2779 | ||
3843 | case VIDIOC_G_CROP: | 2780 | if (inp->index < 0 || inp->index >= zr->card.inputs) |
3844 | { | 2781 | return -EINVAL; |
3845 | struct v4l2_crop *crop = arg; | 2782 | else { |
3846 | int type = crop->type, res = 0; | 2783 | int id = inp->index; |
2784 | memset(inp, 0, sizeof(*inp)); | ||
2785 | inp->index = id; | ||
2786 | } | ||
3847 | 2787 | ||
3848 | dprintk(3, KERN_ERR "%s: VIDIOC_G_CROP - type=%d\n", | 2788 | strncpy(inp->name, zr->card.input[inp->index].name, |
3849 | ZR_DEVNAME(zr), crop->type); | 2789 | sizeof(inp->name) - 1); |
2790 | inp->type = V4L2_INPUT_TYPE_CAMERA; | ||
2791 | inp->std = V4L2_STD_ALL; | ||
3850 | 2792 | ||
3851 | memset(crop, 0, sizeof(*crop)); | 2793 | /* Get status of video decoder */ |
3852 | crop->type = type; | 2794 | mutex_lock(&zr->resource_lock); |
2795 | decoder_call(zr, video, g_input_status, &inp->status); | ||
2796 | mutex_unlock(&zr->resource_lock); | ||
2797 | return 0; | ||
2798 | } | ||
3853 | 2799 | ||
3854 | mutex_lock(&zr->resource_lock); | 2800 | static int zoran_g_input(struct file *file, void *__fh, unsigned int *input) |
2801 | { | ||
2802 | struct zoran_fh *fh = __fh; | ||
2803 | struct zoran *zr = fh->zr; | ||
3855 | 2804 | ||
3856 | if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && | 2805 | mutex_lock(&zr->resource_lock); |
3857 | (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | 2806 | *input = zr->input; |
3858 | fh->map_mode == ZORAN_MAP_MODE_RAW)) { | 2807 | mutex_unlock(&zr->resource_lock); |
3859 | dprintk(1, | ||
3860 | KERN_ERR | ||
3861 | "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n", | ||
3862 | ZR_DEVNAME(zr)); | ||
3863 | res = -EINVAL; | ||
3864 | goto gcrop_unlock_and_return; | ||
3865 | } | ||
3866 | 2808 | ||
3867 | crop->c.top = fh->jpg_settings.img_y; | 2809 | return 0; |
3868 | crop->c.left = fh->jpg_settings.img_x; | 2810 | } |
3869 | crop->c.width = fh->jpg_settings.img_width; | ||
3870 | crop->c.height = fh->jpg_settings.img_height; | ||
3871 | 2811 | ||
3872 | gcrop_unlock_and_return: | 2812 | static int zoran_s_input(struct file *file, void *__fh, unsigned int input) |
3873 | mutex_unlock(&zr->resource_lock); | 2813 | { |
2814 | struct zoran_fh *fh = __fh; | ||
2815 | struct zoran *zr = fh->zr; | ||
2816 | int res; | ||
3874 | 2817 | ||
3875 | return res; | 2818 | mutex_lock(&zr->resource_lock); |
3876 | } | 2819 | res = zoran_set_input(zr, input); |
3877 | break; | 2820 | if (res) |
2821 | goto sinput_unlock_and_return; | ||
3878 | 2822 | ||
3879 | case VIDIOC_S_CROP: | 2823 | /* Make sure the changes come into effect */ |
3880 | { | 2824 | res = wait_grab_pending(zr); |
3881 | struct v4l2_crop *crop = arg; | 2825 | sinput_unlock_and_return: |
3882 | int res = 0; | 2826 | mutex_unlock(&zr->resource_lock); |
2827 | return res; | ||
2828 | } | ||
3883 | 2829 | ||
3884 | settings = fh->jpg_settings; | 2830 | static int zoran_enum_output(struct file *file, void *__fh, |
2831 | struct v4l2_output *outp) | ||
2832 | { | ||
2833 | if (outp->index != 0) | ||
2834 | return -EINVAL; | ||
3885 | 2835 | ||
3886 | dprintk(3, | 2836 | memset(outp, 0, sizeof(*outp)); |
3887 | KERN_ERR | 2837 | outp->index = 0; |
3888 | "%s: VIDIOC_S_CROP - type=%d, x=%d,y=%d,w=%d,h=%d\n", | 2838 | outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY; |
3889 | ZR_DEVNAME(zr), crop->type, crop->c.left, crop->c.top, | 2839 | strncpy(outp->name, "Autodetect", sizeof(outp->name)-1); |
3890 | crop->c.width, crop->c.height); | ||
3891 | 2840 | ||
3892 | mutex_lock(&zr->resource_lock); | 2841 | return 0; |
2842 | } | ||
3893 | 2843 | ||
3894 | if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { | 2844 | static int zoran_g_output(struct file *file, void *__fh, unsigned int *output) |
3895 | dprintk(1, | 2845 | { |
3896 | KERN_ERR | 2846 | *output = 0; |
3897 | "%s: VIDIOC_S_CROP - cannot change settings while active\n", | ||
3898 | ZR_DEVNAME(zr)); | ||
3899 | res = -EBUSY; | ||
3900 | goto scrop_unlock_and_return; | ||
3901 | } | ||
3902 | 2847 | ||
3903 | if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && | 2848 | return 0; |
3904 | (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | 2849 | } |
3905 | fh->map_mode == ZORAN_MAP_MODE_RAW)) { | ||
3906 | dprintk(1, | ||
3907 | KERN_ERR | ||
3908 | "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n", | ||
3909 | ZR_DEVNAME(zr)); | ||
3910 | res = -EINVAL; | ||
3911 | goto scrop_unlock_and_return; | ||
3912 | } | ||
3913 | 2850 | ||
3914 | /* move into a form that we understand */ | 2851 | static int zoran_s_output(struct file *file, void *__fh, unsigned int output) |
3915 | settings.img_x = crop->c.left; | 2852 | { |
3916 | settings.img_y = crop->c.top; | 2853 | if (output != 0) |
3917 | settings.img_width = crop->c.width; | 2854 | return -EINVAL; |
3918 | settings.img_height = crop->c.height; | ||
3919 | 2855 | ||
3920 | /* check validity */ | 2856 | return 0; |
3921 | if ((res = zoran_check_jpg_settings(zr, &settings))) | 2857 | } |
3922 | goto scrop_unlock_and_return; | ||
3923 | 2858 | ||
3924 | /* accept */ | 2859 | /* cropping (sub-frame capture) */ |
3925 | fh->jpg_settings = settings; | 2860 | static int zoran_cropcap(struct file *file, void *__fh, |
2861 | struct v4l2_cropcap *cropcap) | ||
2862 | { | ||
2863 | struct zoran_fh *fh = __fh; | ||
2864 | struct zoran *zr = fh->zr; | ||
2865 | int type = cropcap->type, res = 0; | ||
3926 | 2866 | ||
3927 | scrop_unlock_and_return: | 2867 | memset(cropcap, 0, sizeof(*cropcap)); |
3928 | mutex_unlock(&zr->resource_lock); | 2868 | cropcap->type = type; |
3929 | return res; | ||
3930 | } | ||
3931 | break; | ||
3932 | 2869 | ||
3933 | case VIDIOC_G_JPEGCOMP: | 2870 | mutex_lock(&zr->resource_lock); |
3934 | { | ||
3935 | struct v4l2_jpegcompression *params = arg; | ||
3936 | 2871 | ||
3937 | dprintk(3, KERN_DEBUG "%s: VIDIOC_G_JPEGCOMP\n", | 2872 | if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && |
2873 | (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | ||
2874 | fh->map_mode == ZORAN_MAP_MODE_RAW)) { | ||
2875 | dprintk(1, KERN_ERR | ||
2876 | "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n", | ||
3938 | ZR_DEVNAME(zr)); | 2877 | ZR_DEVNAME(zr)); |
2878 | res = -EINVAL; | ||
2879 | goto cropcap_unlock_and_return; | ||
2880 | } | ||
3939 | 2881 | ||
3940 | memset(params, 0, sizeof(*params)); | 2882 | cropcap->bounds.top = cropcap->bounds.left = 0; |
2883 | cropcap->bounds.width = BUZ_MAX_WIDTH; | ||
2884 | cropcap->bounds.height = BUZ_MAX_HEIGHT; | ||
2885 | cropcap->defrect.top = cropcap->defrect.left = 0; | ||
2886 | cropcap->defrect.width = BUZ_MIN_WIDTH; | ||
2887 | cropcap->defrect.height = BUZ_MIN_HEIGHT; | ||
2888 | cropcap_unlock_and_return: | ||
2889 | mutex_unlock(&zr->resource_lock); | ||
2890 | return res; | ||
2891 | } | ||
3941 | 2892 | ||
3942 | mutex_lock(&zr->resource_lock); | 2893 | static int zoran_g_crop(struct file *file, void *__fh, struct v4l2_crop *crop) |
2894 | { | ||
2895 | struct zoran_fh *fh = __fh; | ||
2896 | struct zoran *zr = fh->zr; | ||
2897 | int type = crop->type, res = 0; | ||
3943 | 2898 | ||
3944 | params->quality = fh->jpg_settings.jpg_comp.quality; | 2899 | memset(crop, 0, sizeof(*crop)); |
3945 | params->APPn = fh->jpg_settings.jpg_comp.APPn; | 2900 | crop->type = type; |
3946 | memcpy(params->APP_data, | ||
3947 | fh->jpg_settings.jpg_comp.APP_data, | ||
3948 | fh->jpg_settings.jpg_comp.APP_len); | ||
3949 | params->APP_len = fh->jpg_settings.jpg_comp.APP_len; | ||
3950 | memcpy(params->COM_data, | ||
3951 | fh->jpg_settings.jpg_comp.COM_data, | ||
3952 | fh->jpg_settings.jpg_comp.COM_len); | ||
3953 | params->COM_len = fh->jpg_settings.jpg_comp.COM_len; | ||
3954 | params->jpeg_markers = | ||
3955 | fh->jpg_settings.jpg_comp.jpeg_markers; | ||
3956 | 2901 | ||
3957 | mutex_unlock(&zr->resource_lock); | 2902 | mutex_lock(&zr->resource_lock); |
3958 | 2903 | ||
3959 | return 0; | 2904 | if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && |
2905 | (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || | ||
2906 | fh->map_mode == ZORAN_MAP_MODE_RAW)) { | ||
2907 | dprintk(1, | ||
2908 | KERN_ERR | ||
2909 | "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n", | ||
2910 | ZR_DEVNAME(zr)); | ||
2911 | res = -EINVAL; | ||
2912 | goto gcrop_unlock_and_return; | ||
3960 | } | 2913 | } |
3961 | break; | ||
3962 | |||
3963 | case VIDIOC_S_JPEGCOMP: | ||
3964 | { | ||
3965 | struct v4l2_jpegcompression *params = arg; | ||
3966 | int res = 0; | ||
3967 | 2914 | ||
3968 | settings = fh->jpg_settings; | 2915 | crop->c.top = fh->jpg_settings.img_y; |
2916 | crop->c.left = fh->jpg_settings.img_x; | ||
2917 | crop->c.width = fh->jpg_settings.img_width; | ||
2918 | crop->c.height = fh->jpg_settings.img_height; | ||
3969 | 2919 | ||
3970 | dprintk(3, | 2920 | gcrop_unlock_and_return: |
3971 | KERN_DEBUG | 2921 | mutex_unlock(&zr->resource_lock); |
3972 | "%s: VIDIOC_S_JPEGCOMP - quality=%d, APPN=%d, APP_len=%d, COM_len=%d\n", | ||
3973 | ZR_DEVNAME(zr), params->quality, params->APPn, | ||
3974 | params->APP_len, params->COM_len); | ||
3975 | 2922 | ||
3976 | settings.jpg_comp = *params; | 2923 | return res; |
2924 | } | ||
3977 | 2925 | ||
3978 | mutex_lock(&zr->resource_lock); | 2926 | static int zoran_s_crop(struct file *file, void *__fh, struct v4l2_crop *crop) |
2927 | { | ||
2928 | struct zoran_fh *fh = __fh; | ||
2929 | struct zoran *zr = fh->zr; | ||
2930 | int res = 0; | ||
2931 | struct zoran_jpg_settings settings; | ||
3979 | 2932 | ||
3980 | if (fh->v4l_buffers.active != ZORAN_FREE || | 2933 | settings = fh->jpg_settings; |
3981 | fh->jpg_buffers.active != ZORAN_FREE) { | ||
3982 | dprintk(1, | ||
3983 | KERN_WARNING | ||
3984 | "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n", | ||
3985 | ZR_DEVNAME(zr)); | ||
3986 | res = -EBUSY; | ||
3987 | goto sjpegc_unlock_and_return; | ||
3988 | } | ||
3989 | 2934 | ||
3990 | if ((res = zoran_check_jpg_settings(zr, &settings))) | 2935 | mutex_lock(&zr->resource_lock); |
3991 | goto sjpegc_unlock_and_return; | ||
3992 | if (!fh->jpg_buffers.allocated) | ||
3993 | fh->jpg_buffers.buffer_size = | ||
3994 | zoran_v4l2_calc_bufsize(&fh->jpg_settings); | ||
3995 | fh->jpg_settings.jpg_comp = *params = settings.jpg_comp; | ||
3996 | sjpegc_unlock_and_return: | ||
3997 | mutex_unlock(&zr->resource_lock); | ||
3998 | 2936 | ||
3999 | return 0; | 2937 | if (fh->buffers.allocated) { |
2938 | dprintk(1, KERN_ERR | ||
2939 | "%s: VIDIOC_S_CROP - cannot change settings while active\n", | ||
2940 | ZR_DEVNAME(zr)); | ||
2941 | res = -EBUSY; | ||
2942 | goto scrop_unlock_and_return; | ||
4000 | } | 2943 | } |
4001 | break; | ||
4002 | 2944 | ||
4003 | case VIDIOC_QUERYSTD: /* why is this useful? */ | 2945 | if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && |
4004 | { | 2946 | (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || |
4005 | v4l2_std_id *std = arg; | 2947 | fh->map_mode == ZORAN_MAP_MODE_RAW)) { |
4006 | 2948 | dprintk(1, KERN_ERR | |
4007 | dprintk(3, | 2949 | "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n", |
4008 | KERN_DEBUG "%s: VIDIOC_QUERY_STD - std=0x%llx\n", | 2950 | ZR_DEVNAME(zr)); |
4009 | ZR_DEVNAME(zr), (unsigned long long)*std); | 2951 | res = -EINVAL; |
4010 | 2952 | goto scrop_unlock_and_return; | |
4011 | if (*std == V4L2_STD_ALL || *std == V4L2_STD_NTSC || | ||
4012 | *std == V4L2_STD_PAL || (*std == V4L2_STD_SECAM && | ||
4013 | zr->card.norms == 3)) { | ||
4014 | return 0; | ||
4015 | } | ||
4016 | |||
4017 | return -EINVAL; | ||
4018 | } | 2953 | } |
4019 | break; | ||
4020 | 2954 | ||
4021 | case VIDIOC_TRY_FMT: | 2955 | /* move into a form that we understand */ |
4022 | { | 2956 | settings.img_x = crop->c.left; |
4023 | struct v4l2_format *fmt = arg; | 2957 | settings.img_y = crop->c.top; |
4024 | int res = 0; | 2958 | settings.img_width = crop->c.width; |
2959 | settings.img_height = crop->c.height; | ||
4025 | 2960 | ||
4026 | dprintk(3, KERN_DEBUG "%s: VIDIOC_TRY_FMT - type=%d\n", | 2961 | /* check validity */ |
4027 | ZR_DEVNAME(zr), fmt->type); | 2962 | res = zoran_check_jpg_settings(zr, &settings, 0); |
2963 | if (res) | ||
2964 | goto scrop_unlock_and_return; | ||
4028 | 2965 | ||
4029 | switch (fmt->type) { | 2966 | /* accept */ |
4030 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | 2967 | fh->jpg_settings = settings; |
4031 | mutex_lock(&zr->resource_lock); | ||
4032 | 2968 | ||
4033 | if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH) | 2969 | scrop_unlock_and_return: |
4034 | fmt->fmt.win.w.width = BUZ_MAX_WIDTH; | 2970 | mutex_unlock(&zr->resource_lock); |
4035 | if (fmt->fmt.win.w.width < BUZ_MIN_WIDTH) | 2971 | return res; |
4036 | fmt->fmt.win.w.width = BUZ_MIN_WIDTH; | 2972 | } |
4037 | if (fmt->fmt.win.w.height > BUZ_MAX_HEIGHT) | ||
4038 | fmt->fmt.win.w.height = BUZ_MAX_HEIGHT; | ||
4039 | if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT) | ||
4040 | fmt->fmt.win.w.height = BUZ_MIN_HEIGHT; | ||
4041 | 2973 | ||
4042 | mutex_unlock(&zr->resource_lock); | 2974 | static int zoran_g_jpegcomp(struct file *file, void *__fh, |
4043 | break; | 2975 | struct v4l2_jpegcompression *params) |
2976 | { | ||
2977 | struct zoran_fh *fh = __fh; | ||
2978 | struct zoran *zr = fh->zr; | ||
2979 | memset(params, 0, sizeof(*params)); | ||
4044 | 2980 | ||
4045 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | 2981 | mutex_lock(&zr->resource_lock); |
4046 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | ||
4047 | if (fmt->fmt.pix.bytesperline > 0) | ||
4048 | return -EINVAL; | ||
4049 | 2982 | ||
4050 | mutex_lock(&zr->resource_lock); | 2983 | params->quality = fh->jpg_settings.jpg_comp.quality; |
4051 | 2984 | params->APPn = fh->jpg_settings.jpg_comp.APPn; | |
4052 | if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) { | 2985 | memcpy(params->APP_data, |
4053 | settings = fh->jpg_settings; | 2986 | fh->jpg_settings.jpg_comp.APP_data, |
4054 | 2987 | fh->jpg_settings.jpg_comp.APP_len); | |
4055 | /* we actually need to set 'real' parameters now */ | 2988 | params->APP_len = fh->jpg_settings.jpg_comp.APP_len; |
4056 | if ((fmt->fmt.pix.height * 2) > | 2989 | memcpy(params->COM_data, |
4057 | BUZ_MAX_HEIGHT) | 2990 | fh->jpg_settings.jpg_comp.COM_data, |
4058 | settings.TmpDcm = 1; | 2991 | fh->jpg_settings.jpg_comp.COM_len); |
4059 | else | 2992 | params->COM_len = fh->jpg_settings.jpg_comp.COM_len; |
4060 | settings.TmpDcm = 2; | 2993 | params->jpeg_markers = |
4061 | settings.decimation = 0; | 2994 | fh->jpg_settings.jpg_comp.jpeg_markers; |
4062 | if (fmt->fmt.pix.height <= | ||
4063 | fh->jpg_settings.img_height / 2) | ||
4064 | settings.VerDcm = 2; | ||
4065 | else | ||
4066 | settings.VerDcm = 1; | ||
4067 | if (fmt->fmt.pix.width <= | ||
4068 | fh->jpg_settings.img_width / 4) | ||
4069 | settings.HorDcm = 4; | ||
4070 | else if (fmt->fmt.pix.width <= | ||
4071 | fh->jpg_settings.img_width / 2) | ||
4072 | settings.HorDcm = 2; | ||
4073 | else | ||
4074 | settings.HorDcm = 1; | ||
4075 | if (settings.TmpDcm == 1) | ||
4076 | settings.field_per_buff = 2; | ||
4077 | else | ||
4078 | settings.field_per_buff = 1; | ||
4079 | |||
4080 | /* check */ | ||
4081 | if ((res = | ||
4082 | zoran_check_jpg_settings(zr, | ||
4083 | &settings))) | ||
4084 | goto tryfmt_unlock_and_return; | ||
4085 | |||
4086 | /* tell the user what we actually did */ | ||
4087 | fmt->fmt.pix.width = | ||
4088 | settings.img_width / settings.HorDcm; | ||
4089 | fmt->fmt.pix.height = | ||
4090 | settings.img_height * 2 / | ||
4091 | (settings.TmpDcm * settings.VerDcm); | ||
4092 | if (settings.TmpDcm == 1) | ||
4093 | fmt->fmt.pix.field = | ||
4094 | (fh->jpg_settings. | ||
4095 | odd_even ? V4L2_FIELD_SEQ_TB : | ||
4096 | V4L2_FIELD_SEQ_BT); | ||
4097 | else | ||
4098 | fmt->fmt.pix.field = | ||
4099 | (fh->jpg_settings. | ||
4100 | odd_even ? V4L2_FIELD_TOP : | ||
4101 | V4L2_FIELD_BOTTOM); | ||
4102 | |||
4103 | fmt->fmt.pix.sizeimage = | ||
4104 | zoran_v4l2_calc_bufsize(&settings); | ||
4105 | } else if (fmt->type == | ||
4106 | V4L2_BUF_TYPE_VIDEO_CAPTURE) { | ||
4107 | int i; | ||
4108 | |||
4109 | for (i = 0; i < NUM_FORMATS; i++) | ||
4110 | if (zoran_formats[i].fourcc == | ||
4111 | fmt->fmt.pix.pixelformat) | ||
4112 | break; | ||
4113 | if (i == NUM_FORMATS) { | ||
4114 | res = -EINVAL; | ||
4115 | goto tryfmt_unlock_and_return; | ||
4116 | } | ||
4117 | 2995 | ||
4118 | if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) | 2996 | mutex_unlock(&zr->resource_lock); |
4119 | fmt->fmt.pix.width = BUZ_MAX_WIDTH; | ||
4120 | if (fmt->fmt.pix.width < BUZ_MIN_WIDTH) | ||
4121 | fmt->fmt.pix.width = BUZ_MIN_WIDTH; | ||
4122 | if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT) | ||
4123 | fmt->fmt.pix.height = | ||
4124 | BUZ_MAX_HEIGHT; | ||
4125 | if (fmt->fmt.pix.height < BUZ_MIN_HEIGHT) | ||
4126 | fmt->fmt.pix.height = | ||
4127 | BUZ_MIN_HEIGHT; | ||
4128 | } else { | ||
4129 | res = -EINVAL; | ||
4130 | goto tryfmt_unlock_and_return; | ||
4131 | } | ||
4132 | tryfmt_unlock_and_return: | ||
4133 | mutex_unlock(&zr->resource_lock); | ||
4134 | 2997 | ||
4135 | return res; | 2998 | return 0; |
4136 | break; | 2999 | } |
4137 | 3000 | ||
4138 | default: | 3001 | static int zoran_s_jpegcomp(struct file *file, void *__fh, |
4139 | return -EINVAL; | 3002 | struct v4l2_jpegcompression *params) |
4140 | } | 3003 | { |
3004 | struct zoran_fh *fh = __fh; | ||
3005 | struct zoran *zr = fh->zr; | ||
3006 | int res = 0; | ||
3007 | struct zoran_jpg_settings settings; | ||
4141 | 3008 | ||
4142 | return 0; | 3009 | settings = fh->jpg_settings; |
4143 | } | ||
4144 | break; | ||
4145 | 3010 | ||
4146 | default: | 3011 | settings.jpg_comp = *params; |
4147 | dprintk(1, KERN_DEBUG "%s: UNKNOWN ioctl cmd: 0x%x\n", | 3012 | |
4148 | ZR_DEVNAME(zr), cmd); | 3013 | mutex_lock(&zr->resource_lock); |
4149 | return -ENOIOCTLCMD; | ||
4150 | break; | ||
4151 | 3014 | ||
3015 | if (fh->buffers.active != ZORAN_FREE) { | ||
3016 | dprintk(1, KERN_WARNING | ||
3017 | "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n", | ||
3018 | ZR_DEVNAME(zr)); | ||
3019 | res = -EBUSY; | ||
3020 | goto sjpegc_unlock_and_return; | ||
4152 | } | 3021 | } |
4153 | return 0; | ||
4154 | } | ||
4155 | 3022 | ||
3023 | res = zoran_check_jpg_settings(zr, &settings, 0); | ||
3024 | if (res) | ||
3025 | goto sjpegc_unlock_and_return; | ||
3026 | if (!fh->buffers.allocated) | ||
3027 | fh->buffers.buffer_size = | ||
3028 | zoran_v4l2_calc_bufsize(&fh->jpg_settings); | ||
3029 | fh->jpg_settings.jpg_comp = *params = settings.jpg_comp; | ||
3030 | sjpegc_unlock_and_return: | ||
3031 | mutex_unlock(&zr->resource_lock); | ||
4156 | 3032 | ||
4157 | static long | 3033 | return res; |
4158 | zoran_ioctl(struct file *file, | ||
4159 | unsigned int cmd, | ||
4160 | unsigned long arg) | ||
4161 | { | ||
4162 | return video_usercopy(file, cmd, arg, zoran_do_ioctl); | ||
4163 | } | 3034 | } |
4164 | 3035 | ||
4165 | static unsigned int | 3036 | static unsigned int |
@@ -4191,11 +3062,11 @@ zoran_poll (struct file *file, | |||
4191 | KERN_DEBUG | 3062 | KERN_DEBUG |
4192 | "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n", | 3063 | "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n", |
4193 | ZR_DEVNAME(zr), __func__, | 3064 | ZR_DEVNAME(zr), __func__, |
4194 | "FAL"[fh->v4l_buffers.active], zr->v4l_sync_tail, | 3065 | "FAL"[fh->buffers.active], zr->v4l_sync_tail, |
4195 | "UPMD"[zr->v4l_buffers.buffer[frame].state], | 3066 | "UPMD"[zr->v4l_buffers.buffer[frame].state], |
4196 | zr->v4l_pend_tail, zr->v4l_pend_head); | 3067 | zr->v4l_pend_tail, zr->v4l_pend_head); |
4197 | /* Process is the one capturing? */ | 3068 | /* Process is the one capturing? */ |
4198 | if (fh->v4l_buffers.active != ZORAN_FREE && | 3069 | if (fh->buffers.active != ZORAN_FREE && |
4199 | /* Buffer ready to DQBUF? */ | 3070 | /* Buffer ready to DQBUF? */ |
4200 | zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) | 3071 | zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) |
4201 | res = POLLIN | POLLRDNORM; | 3072 | res = POLLIN | POLLRDNORM; |
@@ -4213,10 +3084,10 @@ zoran_poll (struct file *file, | |||
4213 | KERN_DEBUG | 3084 | KERN_DEBUG |
4214 | "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n", | 3085 | "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n", |
4215 | ZR_DEVNAME(zr), __func__, | 3086 | ZR_DEVNAME(zr), __func__, |
4216 | "FAL"[fh->jpg_buffers.active], zr->jpg_que_tail, | 3087 | "FAL"[fh->buffers.active], zr->jpg_que_tail, |
4217 | "UPMD"[zr->jpg_buffers.buffer[frame].state], | 3088 | "UPMD"[zr->jpg_buffers.buffer[frame].state], |
4218 | zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head); | 3089 | zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head); |
4219 | if (fh->jpg_buffers.active != ZORAN_FREE && | 3090 | if (fh->buffers.active != ZORAN_FREE && |
4220 | zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) { | 3091 | zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) { |
4221 | if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) | 3092 | if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) |
4222 | res = POLLIN | POLLRDNORM; | 3093 | res = POLLIN | POLLRDNORM; |
@@ -4230,8 +3101,8 @@ zoran_poll (struct file *file, | |||
4230 | default: | 3101 | default: |
4231 | dprintk(1, | 3102 | dprintk(1, |
4232 | KERN_ERR | 3103 | KERN_ERR |
4233 | "%s: zoran_poll() - internal error, unknown map_mode=%d\n", | 3104 | "%s: %s - internal error, unknown map_mode=%d\n", |
4234 | ZR_DEVNAME(zr), fh->map_mode); | 3105 | ZR_DEVNAME(zr), __func__, fh->map_mode); |
4235 | res = POLLNVAL; | 3106 | res = POLLNVAL; |
4236 | } | 3107 | } |
4237 | 3108 | ||
@@ -4265,98 +3136,53 @@ static void | |||
4265 | zoran_vm_close (struct vm_area_struct *vma) | 3136 | zoran_vm_close (struct vm_area_struct *vma) |
4266 | { | 3137 | { |
4267 | struct zoran_mapping *map = vma->vm_private_data; | 3138 | struct zoran_mapping *map = vma->vm_private_data; |
4268 | struct file *file = map->file; | 3139 | struct zoran_fh *fh = map->file->private_data; |
4269 | struct zoran_fh *fh = file->private_data; | ||
4270 | struct zoran *zr = fh->zr; | 3140 | struct zoran *zr = fh->zr; |
4271 | int i; | 3141 | int i; |
4272 | 3142 | ||
4273 | map->count--; | 3143 | if (--map->count > 0) |
4274 | if (map->count == 0) { | 3144 | return; |
4275 | switch (fh->map_mode) { | ||
4276 | case ZORAN_MAP_MODE_JPG_REC: | ||
4277 | case ZORAN_MAP_MODE_JPG_PLAY: | ||
4278 | |||
4279 | dprintk(3, KERN_INFO "%s: munmap(MJPEG)\n", | ||
4280 | ZR_DEVNAME(zr)); | ||
4281 | 3145 | ||
4282 | for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { | 3146 | dprintk(3, KERN_INFO "%s: %s - munmap(%s)\n", ZR_DEVNAME(zr), |
4283 | if (fh->jpg_buffers.buffer[i].map == map) { | 3147 | __func__, mode_name(fh->map_mode)); |
4284 | fh->jpg_buffers.buffer[i].map = | ||
4285 | NULL; | ||
4286 | } | ||
4287 | } | ||
4288 | kfree(map); | ||
4289 | |||
4290 | for (i = 0; i < fh->jpg_buffers.num_buffers; i++) | ||
4291 | if (fh->jpg_buffers.buffer[i].map) | ||
4292 | break; | ||
4293 | if (i == fh->jpg_buffers.num_buffers) { | ||
4294 | mutex_lock(&zr->resource_lock); | ||
4295 | |||
4296 | if (fh->jpg_buffers.active != ZORAN_FREE) { | ||
4297 | jpg_qbuf(file, -1, zr->codec_mode); | ||
4298 | zr->jpg_buffers.allocated = 0; | ||
4299 | zr->jpg_buffers.active = | ||
4300 | fh->jpg_buffers.active = | ||
4301 | ZORAN_FREE; | ||
4302 | } | ||
4303 | //jpg_fbuffer_free(file); | ||
4304 | fh->jpg_buffers.allocated = 0; | ||
4305 | fh->jpg_buffers.ready_to_be_freed = 1; | ||
4306 | |||
4307 | mutex_unlock(&zr->resource_lock); | ||
4308 | } | ||
4309 | 3148 | ||
4310 | break; | 3149 | for (i = 0; i < fh->buffers.num_buffers; i++) { |
4311 | 3150 | if (fh->buffers.buffer[i].map == map) | |
4312 | case ZORAN_MAP_MODE_RAW: | 3151 | fh->buffers.buffer[i].map = NULL; |
4313 | 3152 | } | |
4314 | dprintk(3, KERN_INFO "%s: munmap(V4L)\n", | 3153 | kfree(map); |
4315 | ZR_DEVNAME(zr)); | ||
4316 | |||
4317 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { | ||
4318 | if (fh->v4l_buffers.buffer[i].map == map) { | ||
4319 | /* unqueue/unmap */ | ||
4320 | fh->v4l_buffers.buffer[i].map = | ||
4321 | NULL; | ||
4322 | } | ||
4323 | } | ||
4324 | kfree(map); | ||
4325 | 3154 | ||
4326 | for (i = 0; i < fh->v4l_buffers.num_buffers; i++) | 3155 | /* Any buffers still mapped? */ |
4327 | if (fh->v4l_buffers.buffer[i].map) | 3156 | for (i = 0; i < fh->buffers.num_buffers; i++) |
4328 | break; | 3157 | if (fh->buffers.buffer[i].map) |
4329 | if (i == fh->v4l_buffers.num_buffers) { | 3158 | return; |
4330 | mutex_lock(&zr->resource_lock); | ||
4331 | |||
4332 | if (fh->v4l_buffers.active != ZORAN_FREE) { | ||
4333 | unsigned long flags; | ||
4334 | |||
4335 | spin_lock_irqsave(&zr->spinlock, flags); | ||
4336 | zr36057_set_memgrab(zr, 0); | ||
4337 | zr->v4l_buffers.allocated = 0; | ||
4338 | zr->v4l_buffers.active = | ||
4339 | fh->v4l_buffers.active = | ||
4340 | ZORAN_FREE; | ||
4341 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
4342 | } | ||
4343 | //v4l_fbuffer_free(file); | ||
4344 | fh->v4l_buffers.allocated = 0; | ||
4345 | fh->v4l_buffers.ready_to_be_freed = 1; | ||
4346 | 3159 | ||
4347 | mutex_unlock(&zr->resource_lock); | 3160 | dprintk(3, KERN_INFO "%s: %s - free %s buffers\n", ZR_DEVNAME(zr), |
4348 | } | 3161 | __func__, mode_name(fh->map_mode)); |
4349 | 3162 | ||
4350 | break; | 3163 | mutex_lock(&zr->resource_lock); |
4351 | 3164 | ||
4352 | default: | 3165 | if (fh->map_mode == ZORAN_MAP_MODE_RAW) { |
4353 | printk(KERN_ERR | 3166 | if (fh->buffers.active != ZORAN_FREE) { |
4354 | "%s: munmap() - internal error - unknown map mode %d\n", | 3167 | unsigned long flags; |
4355 | ZR_DEVNAME(zr), fh->map_mode); | ||
4356 | break; | ||
4357 | 3168 | ||
3169 | spin_lock_irqsave(&zr->spinlock, flags); | ||
3170 | zr36057_set_memgrab(zr, 0); | ||
3171 | zr->v4l_buffers.allocated = 0; | ||
3172 | zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; | ||
3173 | spin_unlock_irqrestore(&zr->spinlock, flags); | ||
4358 | } | 3174 | } |
3175 | v4l_fbuffer_free(fh); | ||
3176 | } else { | ||
3177 | if (fh->buffers.active != ZORAN_FREE) { | ||
3178 | jpg_qbuf(fh, -1, zr->codec_mode); | ||
3179 | zr->jpg_buffers.allocated = 0; | ||
3180 | zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE; | ||
3181 | } | ||
3182 | jpg_fbuffer_free(fh); | ||
4359 | } | 3183 | } |
3184 | |||
3185 | mutex_unlock(&zr->resource_lock); | ||
4360 | } | 3186 | } |
4361 | 3187 | ||
4362 | static struct vm_operations_struct zoran_vm_ops = { | 3188 | static struct vm_operations_struct zoran_vm_ops = { |
@@ -4379,90 +3205,106 @@ zoran_mmap (struct file *file, | |||
4379 | int res = 0; | 3205 | int res = 0; |
4380 | 3206 | ||
4381 | dprintk(3, | 3207 | dprintk(3, |
4382 | KERN_INFO "%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n", | 3208 | KERN_INFO "%s: %s(%s) of 0x%08lx-0x%08lx (size=%lu)\n", |
4383 | ZR_DEVNAME(zr), | 3209 | ZR_DEVNAME(zr), __func__, |
4384 | fh->map_mode == ZORAN_MAP_MODE_RAW ? "V4L" : "MJPEG", | 3210 | mode_name(fh->map_mode), vma->vm_start, vma->vm_end, size); |
4385 | vma->vm_start, vma->vm_end, size); | ||
4386 | 3211 | ||
4387 | if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) || | 3212 | if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) || |
4388 | !(vma->vm_flags & VM_WRITE)) { | 3213 | !(vma->vm_flags & VM_WRITE)) { |
4389 | dprintk(1, | 3214 | dprintk(1, |
4390 | KERN_ERR | 3215 | KERN_ERR |
4391 | "%s: mmap() - no MAP_SHARED/PROT_{READ,WRITE} given\n", | 3216 | "%s: %s - no MAP_SHARED/PROT_{READ,WRITE} given\n", |
4392 | ZR_DEVNAME(zr)); | 3217 | ZR_DEVNAME(zr), __func__); |
4393 | return -EINVAL; | 3218 | return -EINVAL; |
4394 | } | 3219 | } |
4395 | 3220 | ||
4396 | switch (fh->map_mode) { | 3221 | mutex_lock(&zr->resource_lock); |
4397 | 3222 | ||
4398 | case ZORAN_MAP_MODE_JPG_REC: | 3223 | if (!fh->buffers.allocated) { |
4399 | case ZORAN_MAP_MODE_JPG_PLAY: | 3224 | dprintk(1, |
3225 | KERN_ERR | ||
3226 | "%s: %s(%s) - buffers not yet allocated\n", | ||
3227 | ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode)); | ||
3228 | res = -ENOMEM; | ||
3229 | goto mmap_unlock_and_return; | ||
3230 | } | ||
4400 | 3231 | ||
4401 | /* lock */ | 3232 | first = offset / fh->buffers.buffer_size; |
4402 | mutex_lock(&zr->resource_lock); | 3233 | last = first - 1 + size / fh->buffers.buffer_size; |
3234 | if (offset % fh->buffers.buffer_size != 0 || | ||
3235 | size % fh->buffers.buffer_size != 0 || first < 0 || | ||
3236 | last < 0 || first >= fh->buffers.num_buffers || | ||
3237 | last >= fh->buffers.buffer_size) { | ||
3238 | dprintk(1, | ||
3239 | KERN_ERR | ||
3240 | "%s: %s(%s) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", | ||
3241 | ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode), offset, size, | ||
3242 | fh->buffers.buffer_size, | ||
3243 | fh->buffers.num_buffers); | ||
3244 | res = -EINVAL; | ||
3245 | goto mmap_unlock_and_return; | ||
3246 | } | ||
4403 | 3247 | ||
4404 | /* Map the MJPEG buffers */ | 3248 | /* Check if any buffers are already mapped */ |
4405 | if (!fh->jpg_buffers.allocated) { | 3249 | for (i = first; i <= last; i++) { |
3250 | if (fh->buffers.buffer[i].map) { | ||
4406 | dprintk(1, | 3251 | dprintk(1, |
4407 | KERN_ERR | 3252 | KERN_ERR |
4408 | "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n", | 3253 | "%s: %s(%s) - buffer %d already mapped\n", |
4409 | ZR_DEVNAME(zr)); | 3254 | ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode), i); |
4410 | res = -ENOMEM; | 3255 | res = -EBUSY; |
4411 | goto jpg_mmap_unlock_and_return; | 3256 | goto mmap_unlock_and_return; |
4412 | } | 3257 | } |
3258 | } | ||
4413 | 3259 | ||
4414 | first = offset / fh->jpg_buffers.buffer_size; | 3260 | /* map these buffers */ |
4415 | last = first - 1 + size / fh->jpg_buffers.buffer_size; | 3261 | map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); |
4416 | if (offset % fh->jpg_buffers.buffer_size != 0 || | 3262 | if (!map) { |
4417 | size % fh->jpg_buffers.buffer_size != 0 || first < 0 || | 3263 | res = -ENOMEM; |
4418 | last < 0 || first >= fh->jpg_buffers.num_buffers || | 3264 | goto mmap_unlock_and_return; |
4419 | last >= fh->jpg_buffers.num_buffers) { | 3265 | } |
4420 | dprintk(1, | 3266 | map->file = file; |
4421 | KERN_ERR | 3267 | map->count = 1; |
4422 | "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", | 3268 | |
4423 | ZR_DEVNAME(zr), offset, size, | 3269 | vma->vm_ops = &zoran_vm_ops; |
4424 | fh->jpg_buffers.buffer_size, | 3270 | vma->vm_flags |= VM_DONTEXPAND; |
4425 | fh->jpg_buffers.num_buffers); | 3271 | vma->vm_private_data = map; |
4426 | res = -EINVAL; | 3272 | |
4427 | goto jpg_mmap_unlock_and_return; | 3273 | if (fh->map_mode == ZORAN_MAP_MODE_RAW) { |
4428 | } | ||
4429 | for (i = first; i <= last; i++) { | 3274 | for (i = first; i <= last; i++) { |
4430 | if (fh->jpg_buffers.buffer[i].map) { | 3275 | todo = size; |
3276 | if (todo > fh->buffers.buffer_size) | ||
3277 | todo = fh->buffers.buffer_size; | ||
3278 | page = fh->buffers.buffer[i].v4l.fbuffer_phys; | ||
3279 | if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, | ||
3280 | todo, PAGE_SHARED)) { | ||
4431 | dprintk(1, | 3281 | dprintk(1, |
4432 | KERN_ERR | 3282 | KERN_ERR |
4433 | "%s: mmap(MJPEG) - buffer %d already mapped\n", | 3283 | "%s: %s(V4L) - remap_pfn_range failed\n", |
4434 | ZR_DEVNAME(zr), i); | 3284 | ZR_DEVNAME(zr), __func__); |
4435 | res = -EBUSY; | 3285 | res = -EAGAIN; |
4436 | goto jpg_mmap_unlock_and_return; | 3286 | goto mmap_unlock_and_return; |
4437 | } | 3287 | } |
3288 | size -= todo; | ||
3289 | start += todo; | ||
3290 | fh->buffers.buffer[i].map = map; | ||
3291 | if (size == 0) | ||
3292 | break; | ||
4438 | } | 3293 | } |
4439 | 3294 | } else { | |
4440 | /* map these buffers (v4l_buffers[i]) */ | ||
4441 | map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); | ||
4442 | if (!map) { | ||
4443 | res = -ENOMEM; | ||
4444 | goto jpg_mmap_unlock_and_return; | ||
4445 | } | ||
4446 | map->file = file; | ||
4447 | map->count = 1; | ||
4448 | |||
4449 | vma->vm_ops = &zoran_vm_ops; | ||
4450 | vma->vm_flags |= VM_DONTEXPAND; | ||
4451 | vma->vm_private_data = map; | ||
4452 | |||
4453 | for (i = first; i <= last; i++) { | 3295 | for (i = first; i <= last; i++) { |
4454 | for (j = 0; | 3296 | for (j = 0; |
4455 | j < fh->jpg_buffers.buffer_size / PAGE_SIZE; | 3297 | j < fh->buffers.buffer_size / PAGE_SIZE; |
4456 | j++) { | 3298 | j++) { |
4457 | fraglen = | 3299 | fraglen = |
4458 | (le32_to_cpu(fh->jpg_buffers.buffer[i]. | 3300 | (le32_to_cpu(fh->buffers.buffer[i].jpg. |
4459 | frag_tab[2 * j + 1]) & ~1) << 1; | 3301 | frag_tab[2 * j + 1]) & ~1) << 1; |
4460 | todo = size; | 3302 | todo = size; |
4461 | if (todo > fraglen) | 3303 | if (todo > fraglen) |
4462 | todo = fraglen; | 3304 | todo = fraglen; |
4463 | pos = | 3305 | pos = |
4464 | le32_to_cpu(fh->jpg_buffers. | 3306 | le32_to_cpu(fh->buffers. |
4465 | buffer[i].frag_tab[2 * j]); | 3307 | buffer[i].jpg.frag_tab[2 * j]); |
4466 | /* should just be pos on i386 */ | 3308 | /* should just be pos on i386 */ |
4467 | page = virt_to_phys(bus_to_virt(pos)) | 3309 | page = virt_to_phys(bus_to_virt(pos)) |
4468 | >> PAGE_SHIFT; | 3310 | >> PAGE_SHIFT; |
@@ -4470,123 +3312,82 @@ zoran_mmap (struct file *file, | |||
4470 | todo, PAGE_SHARED)) { | 3312 | todo, PAGE_SHARED)) { |
4471 | dprintk(1, | 3313 | dprintk(1, |
4472 | KERN_ERR | 3314 | KERN_ERR |
4473 | "%s: zoran_mmap(V4L) - remap_pfn_range failed\n", | 3315 | "%s: %s(V4L) - remap_pfn_range failed\n", |
4474 | ZR_DEVNAME(zr)); | 3316 | ZR_DEVNAME(zr), __func__); |
4475 | res = -EAGAIN; | 3317 | res = -EAGAIN; |
4476 | goto jpg_mmap_unlock_and_return; | 3318 | goto mmap_unlock_and_return; |
4477 | } | 3319 | } |
4478 | size -= todo; | 3320 | size -= todo; |
4479 | start += todo; | 3321 | start += todo; |
4480 | if (size == 0) | 3322 | if (size == 0) |
4481 | break; | 3323 | break; |
4482 | if (le32_to_cpu(fh->jpg_buffers.buffer[i]. | 3324 | if (le32_to_cpu(fh->buffers.buffer[i].jpg. |
4483 | frag_tab[2 * j + 1]) & 1) | 3325 | frag_tab[2 * j + 1]) & 1) |
4484 | break; /* was last fragment */ | 3326 | break; /* was last fragment */ |
4485 | } | 3327 | } |
4486 | fh->jpg_buffers.buffer[i].map = map; | 3328 | fh->buffers.buffer[i].map = map; |
4487 | if (size == 0) | 3329 | if (size == 0) |
4488 | break; | 3330 | break; |
4489 | 3331 | ||
4490 | } | 3332 | } |
4491 | jpg_mmap_unlock_and_return: | ||
4492 | mutex_unlock(&zr->resource_lock); | ||
4493 | |||
4494 | break; | ||
4495 | |||
4496 | case ZORAN_MAP_MODE_RAW: | ||
4497 | |||
4498 | mutex_lock(&zr->resource_lock); | ||
4499 | |||
4500 | /* Map the V4L buffers */ | ||
4501 | if (!fh->v4l_buffers.allocated) { | ||
4502 | dprintk(1, | ||
4503 | KERN_ERR | ||
4504 | "%s: zoran_mmap(V4L) - buffers not yet allocated\n", | ||
4505 | ZR_DEVNAME(zr)); | ||
4506 | res = -ENOMEM; | ||
4507 | goto v4l_mmap_unlock_and_return; | ||
4508 | } | ||
4509 | |||
4510 | first = offset / fh->v4l_buffers.buffer_size; | ||
4511 | last = first - 1 + size / fh->v4l_buffers.buffer_size; | ||
4512 | if (offset % fh->v4l_buffers.buffer_size != 0 || | ||
4513 | size % fh->v4l_buffers.buffer_size != 0 || first < 0 || | ||
4514 | last < 0 || first >= fh->v4l_buffers.num_buffers || | ||
4515 | last >= fh->v4l_buffers.buffer_size) { | ||
4516 | dprintk(1, | ||
4517 | KERN_ERR | ||
4518 | "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", | ||
4519 | ZR_DEVNAME(zr), offset, size, | ||
4520 | fh->v4l_buffers.buffer_size, | ||
4521 | fh->v4l_buffers.num_buffers); | ||
4522 | res = -EINVAL; | ||
4523 | goto v4l_mmap_unlock_and_return; | ||
4524 | } | ||
4525 | for (i = first; i <= last; i++) { | ||
4526 | if (fh->v4l_buffers.buffer[i].map) { | ||
4527 | dprintk(1, | ||
4528 | KERN_ERR | ||
4529 | "%s: mmap(V4L) - buffer %d already mapped\n", | ||
4530 | ZR_DEVNAME(zr), i); | ||
4531 | res = -EBUSY; | ||
4532 | goto v4l_mmap_unlock_and_return; | ||
4533 | } | ||
4534 | } | ||
4535 | |||
4536 | /* map these buffers (v4l_buffers[i]) */ | ||
4537 | map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); | ||
4538 | if (!map) { | ||
4539 | res = -ENOMEM; | ||
4540 | goto v4l_mmap_unlock_and_return; | ||
4541 | } | ||
4542 | map->file = file; | ||
4543 | map->count = 1; | ||
4544 | |||
4545 | vma->vm_ops = &zoran_vm_ops; | ||
4546 | vma->vm_flags |= VM_DONTEXPAND; | ||
4547 | vma->vm_private_data = map; | ||
4548 | |||
4549 | for (i = first; i <= last; i++) { | ||
4550 | todo = size; | ||
4551 | if (todo > fh->v4l_buffers.buffer_size) | ||
4552 | todo = fh->v4l_buffers.buffer_size; | ||
4553 | page = fh->v4l_buffers.buffer[i].fbuffer_phys; | ||
4554 | if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, | ||
4555 | todo, PAGE_SHARED)) { | ||
4556 | dprintk(1, | ||
4557 | KERN_ERR | ||
4558 | "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n", | ||
4559 | ZR_DEVNAME(zr)); | ||
4560 | res = -EAGAIN; | ||
4561 | goto v4l_mmap_unlock_and_return; | ||
4562 | } | ||
4563 | size -= todo; | ||
4564 | start += todo; | ||
4565 | fh->v4l_buffers.buffer[i].map = map; | ||
4566 | if (size == 0) | ||
4567 | break; | ||
4568 | } | ||
4569 | v4l_mmap_unlock_and_return: | ||
4570 | mutex_unlock(&zr->resource_lock); | ||
4571 | |||
4572 | break; | ||
4573 | |||
4574 | default: | ||
4575 | dprintk(1, | ||
4576 | KERN_ERR | ||
4577 | "%s: zoran_mmap() - internal error - unknown map mode %d\n", | ||
4578 | ZR_DEVNAME(zr), fh->map_mode); | ||
4579 | break; | ||
4580 | } | 3333 | } |
4581 | 3334 | ||
3335 | mmap_unlock_and_return: | ||
3336 | mutex_unlock(&zr->resource_lock); | ||
3337 | |||
4582 | return 0; | 3338 | return 0; |
4583 | } | 3339 | } |
4584 | 3340 | ||
3341 | static const struct v4l2_ioctl_ops zoran_ioctl_ops = { | ||
3342 | .vidioc_querycap = zoran_querycap, | ||
3343 | .vidioc_cropcap = zoran_cropcap, | ||
3344 | .vidioc_s_crop = zoran_s_crop, | ||
3345 | .vidioc_g_crop = zoran_g_crop, | ||
3346 | .vidioc_enum_input = zoran_enum_input, | ||
3347 | .vidioc_g_input = zoran_g_input, | ||
3348 | .vidioc_s_input = zoran_s_input, | ||
3349 | .vidioc_enum_output = zoran_enum_output, | ||
3350 | .vidioc_g_output = zoran_g_output, | ||
3351 | .vidioc_s_output = zoran_s_output, | ||
3352 | .vidioc_g_fbuf = zoran_g_fbuf, | ||
3353 | .vidioc_s_fbuf = zoran_s_fbuf, | ||
3354 | .vidioc_g_std = zoran_g_std, | ||
3355 | .vidioc_s_std = zoran_s_std, | ||
3356 | .vidioc_g_jpegcomp = zoran_g_jpegcomp, | ||
3357 | .vidioc_s_jpegcomp = zoran_s_jpegcomp, | ||
3358 | .vidioc_overlay = zoran_overlay, | ||
3359 | .vidioc_reqbufs = zoran_reqbufs, | ||
3360 | .vidioc_querybuf = zoran_querybuf, | ||
3361 | .vidioc_qbuf = zoran_qbuf, | ||
3362 | .vidioc_dqbuf = zoran_dqbuf, | ||
3363 | .vidioc_streamon = zoran_streamon, | ||
3364 | .vidioc_streamoff = zoran_streamoff, | ||
3365 | .vidioc_enum_fmt_vid_cap = zoran_enum_fmt_vid_cap, | ||
3366 | .vidioc_enum_fmt_vid_out = zoran_enum_fmt_vid_out, | ||
3367 | .vidioc_enum_fmt_vid_overlay = zoran_enum_fmt_vid_overlay, | ||
3368 | .vidioc_g_fmt_vid_cap = zoran_g_fmt_vid_cap, | ||
3369 | .vidioc_g_fmt_vid_out = zoran_g_fmt_vid_out, | ||
3370 | .vidioc_g_fmt_vid_overlay = zoran_g_fmt_vid_overlay, | ||
3371 | .vidioc_s_fmt_vid_cap = zoran_s_fmt_vid_cap, | ||
3372 | .vidioc_s_fmt_vid_out = zoran_s_fmt_vid_out, | ||
3373 | .vidioc_s_fmt_vid_overlay = zoran_s_fmt_vid_overlay, | ||
3374 | .vidioc_try_fmt_vid_cap = zoran_try_fmt_vid_cap, | ||
3375 | .vidioc_try_fmt_vid_out = zoran_try_fmt_vid_out, | ||
3376 | .vidioc_try_fmt_vid_overlay = zoran_try_fmt_vid_overlay, | ||
3377 | .vidioc_queryctrl = zoran_queryctrl, | ||
3378 | .vidioc_s_ctrl = zoran_s_ctrl, | ||
3379 | .vidioc_g_ctrl = zoran_g_ctrl, | ||
3380 | #ifdef CONFIG_VIDEO_V4L1_COMPAT | ||
3381 | .vidioc_default = zoran_default, | ||
3382 | .vidiocgmbuf = zoran_vidiocgmbuf, | ||
3383 | #endif | ||
3384 | }; | ||
3385 | |||
4585 | static const struct v4l2_file_operations zoran_fops = { | 3386 | static const struct v4l2_file_operations zoran_fops = { |
4586 | .owner = THIS_MODULE, | 3387 | .owner = THIS_MODULE, |
4587 | .open = zoran_open, | 3388 | .open = zoran_open, |
4588 | .release = zoran_close, | 3389 | .release = zoran_close, |
4589 | .ioctl = zoran_ioctl, | 3390 | .ioctl = video_ioctl2, |
4590 | .read = zoran_read, | 3391 | .read = zoran_read, |
4591 | .write = zoran_write, | 3392 | .write = zoran_write, |
4592 | .mmap = zoran_mmap, | 3393 | .mmap = zoran_mmap, |
@@ -4596,7 +3397,9 @@ static const struct v4l2_file_operations zoran_fops = { | |||
4596 | struct video_device zoran_template __devinitdata = { | 3397 | struct video_device zoran_template __devinitdata = { |
4597 | .name = ZORAN_NAME, | 3398 | .name = ZORAN_NAME, |
4598 | .fops = &zoran_fops, | 3399 | .fops = &zoran_fops, |
3400 | .ioctl_ops = &zoran_ioctl_ops, | ||
4599 | .release = &zoran_vdev_release, | 3401 | .release = &zoran_vdev_release, |
3402 | .tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM, | ||
4600 | .minor = -1 | 3403 | .minor = -1 |
4601 | }; | 3404 | }; |
4602 | 3405 | ||
diff --git a/drivers/media/video/zoran/zoran_procfs.c b/drivers/media/video/zoran/zoran_procfs.c index 870bc5a70e3f..f1423b777db1 100644 --- a/drivers/media/video/zoran/zoran_procfs.c +++ b/drivers/media/video/zoran/zoran_procfs.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #include <linux/pci.h> | 36 | #include <linux/pci.h> |
37 | #include <linux/i2c.h> | 37 | #include <linux/i2c.h> |
38 | #include <linux/i2c-algo-bit.h> | 38 | #include <linux/i2c-algo-bit.h> |
39 | #include <linux/videodev.h> | 39 | #include <linux/videodev2.h> |
40 | #include <linux/spinlock.h> | 40 | #include <linux/spinlock.h> |
41 | #include <linux/sem.h> | 41 | #include <linux/sem.h> |
42 | #include <linux/seq_file.h> | 42 | #include <linux/seq_file.h> |
diff --git a/drivers/media/video/zoran/zr36016.c b/drivers/media/video/zoran/zr36016.c index 00d132bcd1e4..21c088ea9046 100644 --- a/drivers/media/video/zoran/zr36016.c +++ b/drivers/media/video/zoran/zr36016.c | |||
@@ -34,15 +34,10 @@ | |||
34 | #include <linux/types.h> | 34 | #include <linux/types.h> |
35 | #include <linux/wait.h> | 35 | #include <linux/wait.h> |
36 | 36 | ||
37 | /* includes for structures and defines regarding video | ||
38 | #include<linux/videodev.h> */ | ||
39 | |||
40 | /* I/O commands, error codes */ | 37 | /* I/O commands, error codes */ |
41 | #include <asm/io.h> | 38 | #include <asm/io.h> |
42 | //#include<errno.h> | ||
43 | 39 | ||
44 | /* v4l API */ | 40 | /* v4l API */ |
45 | #include <linux/videodev.h> | ||
46 | 41 | ||
47 | /* headerfile of this module */ | 42 | /* headerfile of this module */ |
48 | #include"zr36016.h" | 43 | #include"zr36016.h" |
diff --git a/drivers/media/video/zoran/zr36050.c b/drivers/media/video/zoran/zr36050.c index cf8b271a1c8f..639dd87c663f 100644 --- a/drivers/media/video/zoran/zr36050.c +++ b/drivers/media/video/zoran/zr36050.c | |||
@@ -34,12 +34,8 @@ | |||
34 | #include <linux/types.h> | 34 | #include <linux/types.h> |
35 | #include <linux/wait.h> | 35 | #include <linux/wait.h> |
36 | 36 | ||
37 | /* includes for structures and defines regarding video | ||
38 | #include<linux/videodev.h> */ | ||
39 | |||
40 | /* I/O commands, error codes */ | 37 | /* I/O commands, error codes */ |
41 | #include <asm/io.h> | 38 | #include <asm/io.h> |
42 | //#include<errno.h> | ||
43 | 39 | ||
44 | /* headerfile of this module */ | 40 | /* headerfile of this module */ |
45 | #include "zr36050.h" | 41 | #include "zr36050.h" |
diff --git a/drivers/media/video/zoran/zr36060.c b/drivers/media/video/zoran/zr36060.c index 8e74054d5ef1..008746ff7746 100644 --- a/drivers/media/video/zoran/zr36060.c +++ b/drivers/media/video/zoran/zr36060.c | |||
@@ -34,12 +34,8 @@ | |||
34 | #include <linux/types.h> | 34 | #include <linux/types.h> |
35 | #include <linux/wait.h> | 35 | #include <linux/wait.h> |
36 | 36 | ||
37 | /* includes for structures and defines regarding video | ||
38 | #include<linux/videodev.h> */ | ||
39 | |||
40 | /* I/O commands, error codes */ | 37 | /* I/O commands, error codes */ |
41 | #include <asm/io.h> | 38 | #include <asm/io.h> |
42 | //#include<errno.h> | ||
43 | 39 | ||
44 | /* headerfile of this module */ | 40 | /* headerfile of this module */ |
45 | #include "zr36060.h" | 41 | #include "zr36060.h" |