2 * Driver for the VINO (Video In No Out) system found in SGI Indys.
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License version 2 as published by the Free Software Foundation.
7 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
9 * Based on the previous version of the driver for 2.4 kernels by:
10 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
15 * - remove "mark pages reserved-hacks" from memory allocation code
16 * and implement fault()
17 * - check decimation, calculating and reporting image size when
19 * - implement read(), user mode buffers and overlay (?)
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/delay.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/errno.h>
28 #include <linux/interrupt.h>
29 #include <linux/kernel.h>
31 #include <linux/time.h>
32 #include <linux/version.h>
33 #include <linux/kmod.h>
35 #include <linux/i2c.h>
36 #include <linux/i2c-algo-sgi.h>
38 #include <linux/videodev2.h>
39 #include <media/v4l2-device.h>
40 #include <media/v4l2-ioctl.h>
41 #include <linux/mutex.h>
43 #include <asm/paccess.h>
45 #include <asm/sgi/ip22.h>
46 #include <asm/sgi/mc.h>
52 /* Uncomment the following line to get lots and lots of (mostly useless)
54 * Note that the debug output also slows down the driver significantly */
56 // #define VINO_DEBUG_INT
58 #define VINO_MODULE_VERSION "0.0.5"
59 #define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 5)
61 MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
62 MODULE_VERSION(VINO_MODULE_VERSION
);
63 MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
64 MODULE_LICENSE("GPL");
67 #define dprintk(x...) printk("VINO: " x);
72 #define VINO_NO_CHANNEL 0
73 #define VINO_CHANNEL_A 1
74 #define VINO_CHANNEL_B 2
76 #define VINO_PAL_WIDTH 768
77 #define VINO_PAL_HEIGHT 576
78 #define VINO_NTSC_WIDTH 640
79 #define VINO_NTSC_HEIGHT 480
81 #define VINO_MIN_WIDTH 32
82 #define VINO_MIN_HEIGHT 32
84 #define VINO_CLIPPING_START_ODD_D1 1
85 #define VINO_CLIPPING_START_ODD_PAL 15
86 #define VINO_CLIPPING_START_ODD_NTSC 12
88 #define VINO_CLIPPING_START_EVEN_D1 2
89 #define VINO_CLIPPING_START_EVEN_PAL 15
90 #define VINO_CLIPPING_START_EVEN_NTSC 12
92 #define VINO_INPUT_CHANNEL_COUNT 3
94 /* the number is the index for vino_inputs */
95 #define VINO_INPUT_NONE -1
96 #define VINO_INPUT_COMPOSITE 0
97 #define VINO_INPUT_SVIDEO 1
98 #define VINO_INPUT_D1 2
100 #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
102 #define VINO_FIFO_THRESHOLD_DEFAULT 16
104 #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
105 * VINO_PAL_HEIGHT * 4 \
106 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
108 #define VINO_FRAMEBUFFER_COUNT_MAX 8
110 #define VINO_FRAMEBUFFER_UNUSED 0
111 #define VINO_FRAMEBUFFER_IN_USE 1
112 #define VINO_FRAMEBUFFER_READY 2
114 #define VINO_QUEUE_ERROR -1
115 #define VINO_QUEUE_MAGIC 0x20050125
117 #define VINO_MEMORY_NONE 0
118 #define VINO_MEMORY_MMAP 1
119 #define VINO_MEMORY_USERPTR 2
121 #define VINO_DUMMY_DESC_COUNT 4
122 #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
124 #define VINO_MAX_FRAME_SKIP_COUNT 128
126 /* the number is the index for vino_data_formats */
127 #define VINO_DATA_FMT_NONE -1
128 #define VINO_DATA_FMT_GREY 0
129 #define VINO_DATA_FMT_RGB332 1
130 #define VINO_DATA_FMT_RGB32 2
131 #define VINO_DATA_FMT_YUV 3
133 #define VINO_DATA_FMT_COUNT 4
135 /* the number is the index for vino_data_norms */
136 #define VINO_DATA_NORM_NONE -1
137 #define VINO_DATA_NORM_NTSC 0
138 #define VINO_DATA_NORM_PAL 1
139 #define VINO_DATA_NORM_SECAM 2
140 #define VINO_DATA_NORM_D1 3
142 #define VINO_DATA_NORM_COUNT 4
144 /* Internal data structure definitions */
151 struct vino_clipping
{
152 unsigned int left
, right
, top
, bottom
;
155 struct vino_data_format
{
156 /* the description */
158 /* bytes per pixel */
160 /* V4L2 fourcc code */
162 /* V4L2 colorspace (duh!) */
163 enum v4l2_colorspace colorspace
;
166 struct vino_data_norm
{
168 unsigned int width
, height
;
169 struct vino_clipping odd
;
170 struct vino_clipping even
;
173 unsigned int fps_min
, fps_max
;
177 struct vino_descriptor_table
{
178 /* the number of PAGE_SIZE sized pages in the buffer */
179 unsigned int page_count
;
180 /* virtual (kmalloc'd) pointers to the actual data
181 * (in PAGE_SIZE chunks, used with mmap streaming) */
182 unsigned long *virtual;
184 /* cpu address for the VINO descriptor table
185 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
186 unsigned long *dma_cpu
;
187 /* dma address for the VINO descriptor table
188 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
192 struct vino_framebuffer
{
193 /* identifier nubmer */
195 /* the length of the whole buffer */
197 /* the length of actual data in buffer */
198 unsigned int data_size
;
199 /* the data format */
200 unsigned int data_format
;
201 /* the state of buffer data */
203 /* is the buffer mapped in user space? */
204 unsigned int map_count
;
205 /* memory offset for mmap() */
208 unsigned int frame_counter
;
209 /* timestamp (written when image capture finishes) */
210 struct timeval timestamp
;
212 struct vino_descriptor_table desc_table
;
214 spinlock_t state_lock
;
217 struct vino_framebuffer_fifo
{
224 unsigned int data
[VINO_FRAMEBUFFER_COUNT_MAX
];
227 struct vino_framebuffer_queue
{
230 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
234 /* data field of in and out contain index numbers for buffer */
235 struct vino_framebuffer_fifo in
;
236 struct vino_framebuffer_fifo out
;
238 struct vino_framebuffer
*buffer
[VINO_FRAMEBUFFER_COUNT_MAX
];
240 spinlock_t queue_lock
;
241 struct mutex queue_mutex
;
242 wait_queue_head_t frame_wait_queue
;
245 struct vino_interrupt_data
{
246 struct timeval timestamp
;
247 unsigned int frame_counter
;
248 unsigned int skip_count
;
252 struct vino_channel_settings
{
253 unsigned int channel
;
256 unsigned int data_format
;
257 unsigned int data_norm
;
258 struct vino_clipping clipping
;
259 unsigned int decimation
;
260 unsigned int line_size
;
263 unsigned int framert_reg
;
265 unsigned int fifo_threshold
;
267 struct vino_framebuffer_queue fb_queue
;
269 /* number of the current field */
272 /* read in progress */
274 /* streaming is active */
276 /* the driver is currently processing the queue */
280 spinlock_t capture_lock
;
284 struct vino_interrupt_data int_data
;
287 struct video_device
*vdev
;
290 struct vino_settings
{
291 struct v4l2_device v4l2_dev
;
292 struct vino_channel_settings a
;
293 struct vino_channel_settings b
;
295 /* the channel which owns this client:
296 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
297 unsigned int decoder_owner
;
298 struct v4l2_subdev
*decoder
;
299 unsigned int camera_owner
;
300 struct v4l2_subdev
*camera
;
302 /* a lock for vino register access */
303 spinlock_t vino_lock
;
304 /* a lock for channel input changes */
305 spinlock_t input_lock
;
307 unsigned long dummy_page
;
308 struct vino_descriptor_table dummy_desc_table
;
311 /* Module parameters */
314 * Using vino_pixel_conversion the ABGR32-format pixels supplied
315 * by the VINO chip can be converted to more common formats
316 * like RGBA32 (or probably RGB24 in the future). This way we
317 * can give out data that can be specified correctly with
318 * the V4L2-definitions.
320 * The pixel format is specified as RGBA32 when no conversion
323 * Note that this only affects the 32-bit bit depth.
325 * Use non-zero value to enable conversion.
327 static int vino_pixel_conversion
;
329 module_param_named(pixelconv
, vino_pixel_conversion
, int, 0);
331 MODULE_PARM_DESC(pixelconv
,
332 "enable pixel conversion (non-zero value enables)");
334 /* Internal data structures */
336 static struct sgi_vino
*vino
;
338 static struct vino_settings
*vino_drvdata
;
340 #define camera_call(o, f, args...) \
341 v4l2_subdev_call(vino_drvdata->camera, o, f, ##args)
342 #define decoder_call(o, f, args...) \
343 v4l2_subdev_call(vino_drvdata->decoder, o, f, ##args)
345 static const char *vino_driver_name
= "vino";
346 static const char *vino_driver_description
= "SGI VINO";
347 static const char *vino_bus_name
= "GIO64 bus";
348 static const char *vino_vdev_name_a
= "SGI VINO Channel A";
349 static const char *vino_vdev_name_b
= "SGI VINO Channel B";
351 static void vino_capture_tasklet(unsigned long channel
);
353 DECLARE_TASKLET(vino_tasklet_a
, vino_capture_tasklet
, VINO_CHANNEL_A
);
354 DECLARE_TASKLET(vino_tasklet_b
, vino_capture_tasklet
, VINO_CHANNEL_B
);
356 static const struct vino_input vino_inputs
[] = {
359 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
363 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
366 .name
= "D1/IndyCam",
367 .std
= V4L2_STD_NTSC
,
371 static const struct vino_data_format vino_data_formats
[] = {
373 .description
= "8-bit greyscale",
375 .pixelformat
= V4L2_PIX_FMT_GREY
,
376 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
378 .description
= "8-bit dithered RGB 3-3-2",
380 .pixelformat
= V4L2_PIX_FMT_RGB332
,
381 .colorspace
= V4L2_COLORSPACE_SRGB
,
383 .description
= "32-bit RGB",
385 .pixelformat
= V4L2_PIX_FMT_RGB32
,
386 .colorspace
= V4L2_COLORSPACE_SRGB
,
388 .description
= "YUV 4:2:2",
390 .pixelformat
= V4L2_PIX_FMT_YUYV
, // XXX: swapped?
391 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
395 static const struct vino_data_norm vino_data_norms
[] = {
397 .description
= "NTSC",
398 .std
= V4L2_STD_NTSC
,
402 .width
= VINO_NTSC_WIDTH
,
403 .height
= VINO_NTSC_HEIGHT
,
405 .top
= VINO_CLIPPING_START_ODD_NTSC
,
407 .bottom
= VINO_CLIPPING_START_ODD_NTSC
408 + VINO_NTSC_HEIGHT
/ 2 - 1,
409 .right
= VINO_NTSC_WIDTH
,
412 .top
= VINO_CLIPPING_START_EVEN_NTSC
,
414 .bottom
= VINO_CLIPPING_START_EVEN_NTSC
415 + VINO_NTSC_HEIGHT
/ 2 - 1,
416 .right
= VINO_NTSC_WIDTH
,
419 .description
= "PAL",
424 .width
= VINO_PAL_WIDTH
,
425 .height
= VINO_PAL_HEIGHT
,
427 .top
= VINO_CLIPPING_START_ODD_PAL
,
429 .bottom
= VINO_CLIPPING_START_ODD_PAL
430 + VINO_PAL_HEIGHT
/ 2 - 1,
431 .right
= VINO_PAL_WIDTH
,
434 .top
= VINO_CLIPPING_START_EVEN_PAL
,
436 .bottom
= VINO_CLIPPING_START_EVEN_PAL
437 + VINO_PAL_HEIGHT
/ 2 - 1,
438 .right
= VINO_PAL_WIDTH
,
441 .description
= "SECAM",
442 .std
= V4L2_STD_SECAM
,
446 .width
= VINO_PAL_WIDTH
,
447 .height
= VINO_PAL_HEIGHT
,
449 .top
= VINO_CLIPPING_START_ODD_PAL
,
451 .bottom
= VINO_CLIPPING_START_ODD_PAL
452 + VINO_PAL_HEIGHT
/ 2 - 1,
453 .right
= VINO_PAL_WIDTH
,
456 .top
= VINO_CLIPPING_START_EVEN_PAL
,
458 .bottom
= VINO_CLIPPING_START_EVEN_PAL
459 + VINO_PAL_HEIGHT
/ 2 - 1,
460 .right
= VINO_PAL_WIDTH
,
463 .description
= "NTSC/D1",
464 .std
= V4L2_STD_NTSC
,
468 .width
= VINO_NTSC_WIDTH
,
469 .height
= VINO_NTSC_HEIGHT
,
471 .top
= VINO_CLIPPING_START_ODD_D1
,
473 .bottom
= VINO_CLIPPING_START_ODD_D1
474 + VINO_NTSC_HEIGHT
/ 2 - 1,
475 .right
= VINO_NTSC_WIDTH
,
478 .top
= VINO_CLIPPING_START_EVEN_D1
,
480 .bottom
= VINO_CLIPPING_START_EVEN_D1
481 + VINO_NTSC_HEIGHT
/ 2 - 1,
482 .right
= VINO_NTSC_WIDTH
,
487 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
489 struct v4l2_queryctrl vino_indycam_v4l2_controls
[] = {
491 .id
= V4L2_CID_AUTOGAIN
,
492 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
493 .name
= "Automatic Gain Control",
497 .default_value
= INDYCAM_AGC_DEFAULT
,
499 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
500 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
501 .name
= "Automatic White Balance",
505 .default_value
= INDYCAM_AWB_DEFAULT
,
508 .type
= V4L2_CTRL_TYPE_INTEGER
,
510 .minimum
= INDYCAM_GAIN_MIN
,
511 .maximum
= INDYCAM_GAIN_MAX
,
513 .default_value
= INDYCAM_GAIN_DEFAULT
,
515 .id
= INDYCAM_CONTROL_RED_SATURATION
,
516 .type
= V4L2_CTRL_TYPE_INTEGER
,
517 .name
= "Red Saturation",
518 .minimum
= INDYCAM_RED_SATURATION_MIN
,
519 .maximum
= INDYCAM_RED_SATURATION_MAX
,
521 .default_value
= INDYCAM_RED_SATURATION_DEFAULT
,
523 .id
= INDYCAM_CONTROL_BLUE_SATURATION
,
524 .type
= V4L2_CTRL_TYPE_INTEGER
,
525 .name
= "Blue Saturation",
526 .minimum
= INDYCAM_BLUE_SATURATION_MIN
,
527 .maximum
= INDYCAM_BLUE_SATURATION_MAX
,
529 .default_value
= INDYCAM_BLUE_SATURATION_DEFAULT
,
531 .id
= V4L2_CID_RED_BALANCE
,
532 .type
= V4L2_CTRL_TYPE_INTEGER
,
533 .name
= "Red Balance",
534 .minimum
= INDYCAM_RED_BALANCE_MIN
,
535 .maximum
= INDYCAM_RED_BALANCE_MAX
,
537 .default_value
= INDYCAM_RED_BALANCE_DEFAULT
,
539 .id
= V4L2_CID_BLUE_BALANCE
,
540 .type
= V4L2_CTRL_TYPE_INTEGER
,
541 .name
= "Blue Balance",
542 .minimum
= INDYCAM_BLUE_BALANCE_MIN
,
543 .maximum
= INDYCAM_BLUE_BALANCE_MAX
,
545 .default_value
= INDYCAM_BLUE_BALANCE_DEFAULT
,
547 .id
= V4L2_CID_EXPOSURE
,
548 .type
= V4L2_CTRL_TYPE_INTEGER
,
549 .name
= "Shutter Control",
550 .minimum
= INDYCAM_SHUTTER_MIN
,
551 .maximum
= INDYCAM_SHUTTER_MAX
,
553 .default_value
= INDYCAM_SHUTTER_DEFAULT
,
555 .id
= V4L2_CID_GAMMA
,
556 .type
= V4L2_CTRL_TYPE_INTEGER
,
558 .minimum
= INDYCAM_GAMMA_MIN
,
559 .maximum
= INDYCAM_GAMMA_MAX
,
561 .default_value
= INDYCAM_GAMMA_DEFAULT
,
565 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
567 struct v4l2_queryctrl vino_saa7191_v4l2_controls
[] = {
570 .type
= V4L2_CTRL_TYPE_INTEGER
,
572 .minimum
= SAA7191_HUE_MIN
,
573 .maximum
= SAA7191_HUE_MAX
,
575 .default_value
= SAA7191_HUE_DEFAULT
,
577 .id
= SAA7191_CONTROL_BANDPASS
,
578 .type
= V4L2_CTRL_TYPE_INTEGER
,
579 .name
= "Luminance Bandpass",
580 .minimum
= SAA7191_BANDPASS_MIN
,
581 .maximum
= SAA7191_BANDPASS_MAX
,
583 .default_value
= SAA7191_BANDPASS_DEFAULT
,
585 .id
= SAA7191_CONTROL_BANDPASS_WEIGHT
,
586 .type
= V4L2_CTRL_TYPE_INTEGER
,
587 .name
= "Luminance Bandpass Weight",
588 .minimum
= SAA7191_BANDPASS_WEIGHT_MIN
,
589 .maximum
= SAA7191_BANDPASS_WEIGHT_MAX
,
591 .default_value
= SAA7191_BANDPASS_WEIGHT_DEFAULT
,
593 .id
= SAA7191_CONTROL_CORING
,
594 .type
= V4L2_CTRL_TYPE_INTEGER
,
595 .name
= "HF Luminance Coring",
596 .minimum
= SAA7191_CORING_MIN
,
597 .maximum
= SAA7191_CORING_MAX
,
599 .default_value
= SAA7191_CORING_DEFAULT
,
601 .id
= SAA7191_CONTROL_FORCE_COLOUR
,
602 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
603 .name
= "Force Colour",
604 .minimum
= SAA7191_FORCE_COLOUR_MIN
,
605 .maximum
= SAA7191_FORCE_COLOUR_MAX
,
607 .default_value
= SAA7191_FORCE_COLOUR_DEFAULT
,
609 .id
= SAA7191_CONTROL_CHROMA_GAIN
,
610 .type
= V4L2_CTRL_TYPE_INTEGER
,
611 .name
= "Chrominance Gain Control",
612 .minimum
= SAA7191_CHROMA_GAIN_MIN
,
613 .maximum
= SAA7191_CHROMA_GAIN_MAX
,
615 .default_value
= SAA7191_CHROMA_GAIN_DEFAULT
,
617 .id
= SAA7191_CONTROL_VTRC
,
618 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
619 .name
= "VTR Time Constant",
620 .minimum
= SAA7191_VTRC_MIN
,
621 .maximum
= SAA7191_VTRC_MAX
,
623 .default_value
= SAA7191_VTRC_DEFAULT
,
625 .id
= SAA7191_CONTROL_LUMA_DELAY
,
626 .type
= V4L2_CTRL_TYPE_INTEGER
,
627 .name
= "Luminance Delay Compensation",
628 .minimum
= SAA7191_LUMA_DELAY_MIN
,
629 .maximum
= SAA7191_LUMA_DELAY_MAX
,
631 .default_value
= SAA7191_LUMA_DELAY_DEFAULT
,
633 .id
= SAA7191_CONTROL_VNR
,
634 .type
= V4L2_CTRL_TYPE_INTEGER
,
635 .name
= "Vertical Noise Reduction",
636 .minimum
= SAA7191_VNR_MIN
,
637 .maximum
= SAA7191_VNR_MAX
,
639 .default_value
= SAA7191_VNR_DEFAULT
,
643 /* VINO I2C bus functions */
645 unsigned i2c_vino_getctrl(void *data
)
647 return vino
->i2c_control
;
650 void i2c_vino_setctrl(void *data
, unsigned val
)
652 vino
->i2c_control
= val
;
655 unsigned i2c_vino_rdata(void *data
)
657 return vino
->i2c_data
;
660 void i2c_vino_wdata(void *data
, unsigned val
)
662 vino
->i2c_data
= val
;
665 static struct i2c_algo_sgi_data i2c_sgi_vino_data
=
667 .getctrl
= &i2c_vino_getctrl
,
668 .setctrl
= &i2c_vino_setctrl
,
669 .rdata
= &i2c_vino_rdata
,
670 .wdata
= &i2c_vino_wdata
,
675 static struct i2c_adapter vino_i2c_adapter
=
677 .name
= "VINO I2C bus",
678 .id
= I2C_HW_SGI_VINO
,
679 .algo_data
= &i2c_sgi_vino_data
,
680 .owner
= THIS_MODULE
,
683 static int vino_i2c_add_bus(void)
685 return i2c_sgi_add_bus(&vino_i2c_adapter
);
688 static int vino_i2c_del_bus(void)
690 return i2c_del_adapter(&vino_i2c_adapter
);
693 /* VINO framebuffer/DMA descriptor management */
695 static void vino_free_buffer_with_count(struct vino_framebuffer
*fb
,
700 dprintk("vino_free_buffer_with_count(): count = %d\n", count
);
702 for (i
= 0; i
< count
; i
++) {
703 ClearPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
704 dma_unmap_single(NULL
,
705 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
706 PAGE_SIZE
, DMA_FROM_DEVICE
);
707 free_page(fb
->desc_table
.virtual[i
]);
710 dma_free_coherent(NULL
,
711 VINO_PAGE_RATIO
* (fb
->desc_table
.page_count
+ 4) *
712 sizeof(dma_addr_t
), (void *)fb
->desc_table
.dma_cpu
,
714 kfree(fb
->desc_table
.virtual);
716 memset(fb
, 0, sizeof(struct vino_framebuffer
));
719 static void vino_free_buffer(struct vino_framebuffer
*fb
)
721 vino_free_buffer_with_count(fb
, fb
->desc_table
.page_count
);
724 static int vino_allocate_buffer(struct vino_framebuffer
*fb
,
727 unsigned int count
, i
, j
;
730 dprintk("vino_allocate_buffer():\n");
735 memset(fb
, 0, sizeof(struct vino_framebuffer
));
737 count
= ((size
/ PAGE_SIZE
) + 4) & ~3;
739 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
742 /* allocate memory for table with virtual (page) addresses */
743 fb
->desc_table
.virtual = (unsigned long *)
744 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
745 if (!fb
->desc_table
.virtual)
748 /* allocate memory for table with dma addresses
749 * (has space for four extra descriptors) */
750 fb
->desc_table
.dma_cpu
=
751 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
752 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
753 GFP_KERNEL
| GFP_DMA
);
754 if (!fb
->desc_table
.dma_cpu
) {
756 goto out_free_virtual
;
759 /* allocate pages for the buffer and acquire the according
761 for (i
= 0; i
< count
; i
++) {
762 dma_addr_t dma_data_addr
;
764 fb
->desc_table
.virtual[i
] =
765 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
766 if (!fb
->desc_table
.virtual[i
]) {
773 (void *)fb
->desc_table
.virtual[i
],
774 PAGE_SIZE
, DMA_FROM_DEVICE
);
776 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
777 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
778 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
781 SetPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
784 /* page_count needs to be set anyway, because the descriptor table has
785 * been allocated according to this number */
786 fb
->desc_table
.page_count
= count
;
789 /* the descriptor with index i doesn't contain
790 * a valid address yet */
791 vino_free_buffer_with_count(fb
, i
);
796 fb
->size
= count
* PAGE_SIZE
;
797 fb
->data_format
= VINO_DATA_FMT_NONE
;
799 /* set the dma stop-bit for the last (count+1)th descriptor */
800 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
804 kfree(fb
->desc_table
.virtual);
809 /* user buffers not fully implemented yet */
810 static int vino_prepare_user_buffer(struct vino_framebuffer
*fb
,
814 unsigned int count
, i
, j
;
817 dprintk("vino_prepare_user_buffer():\n");
822 memset(fb
, 0, sizeof(struct vino_framebuffer
));
824 count
= ((size
/ PAGE_SIZE
)) & ~3;
826 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
829 /* allocate memory for table with virtual (page) addresses */
830 fb
->desc_table
.virtual = (unsigned long *)
831 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
832 if (!fb
->desc_table
.virtual)
835 /* allocate memory for table with dma addresses
836 * (has space for four extra descriptors) */
837 fb
->desc_table
.dma_cpu
=
838 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
839 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
840 GFP_KERNEL
| GFP_DMA
);
841 if (!fb
->desc_table
.dma_cpu
) {
843 goto out_free_virtual
;
846 /* allocate pages for the buffer and acquire the according
848 for (i
= 0; i
< count
; i
++) {
849 dma_addr_t dma_data_addr
;
851 fb
->desc_table
.virtual[i
] =
852 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
853 if (!fb
->desc_table
.virtual[i
]) {
860 (void *)fb
->desc_table
.virtual[i
],
861 PAGE_SIZE
, DMA_FROM_DEVICE
);
863 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
864 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
865 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
868 SetPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
871 /* page_count needs to be set anyway, because the descriptor table has
872 * been allocated according to this number */
873 fb
->desc_table
.page_count
= count
;
876 /* the descriptor with index i doesn't contain
877 * a valid address yet */
878 vino_free_buffer_with_count(fb
, i
);
883 fb
->size
= count
* PAGE_SIZE
;
885 /* set the dma stop-bit for the last (count+1)th descriptor */
886 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
890 kfree(fb
->desc_table
.virtual);
895 static void vino_sync_buffer(struct vino_framebuffer
*fb
)
899 dprintk("vino_sync_buffer():\n");
901 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++)
902 dma_sync_single(NULL
,
903 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
904 PAGE_SIZE
, DMA_FROM_DEVICE
);
907 /* Framebuffer fifo functions (need to be locked externally) */
909 static inline void vino_fifo_init(struct vino_framebuffer_fifo
*f
,
917 if (length
> VINO_FRAMEBUFFER_COUNT_MAX
)
918 length
= VINO_FRAMEBUFFER_COUNT_MAX
;
923 /* returns true/false */
924 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo
*f
,
929 for (i
= f
->head
; i
== (f
->tail
- 1); i
= (i
+ 1) % f
->length
) {
930 if (f
->data
[i
] == id
)
938 /* returns true/false */
939 static inline int vino_fifo_full(struct vino_framebuffer_fifo
*f
)
941 return (f
->used
== f
->length
);
945 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo
*f
)
950 static int vino_fifo_enqueue(struct vino_framebuffer_fifo
*f
, unsigned int id
)
952 if (id
>= f
->length
) {
953 return VINO_QUEUE_ERROR
;
956 if (vino_fifo_has_id(f
, id
)) {
957 return VINO_QUEUE_ERROR
;
960 if (f
->used
< f
->length
) {
961 f
->data
[f
->tail
] = id
;
962 f
->tail
= (f
->tail
+ 1) % f
->length
;
965 return VINO_QUEUE_ERROR
;
971 static int vino_fifo_peek(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
974 *id
= f
->data
[f
->head
];
976 return VINO_QUEUE_ERROR
;
982 static int vino_fifo_dequeue(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
985 *id
= f
->data
[f
->head
];
986 f
->head
= (f
->head
+ 1) % f
->length
;
989 return VINO_QUEUE_ERROR
;
995 /* Framebuffer queue functions */
997 /* execute with queue_lock locked */
998 static void vino_queue_free_with_count(struct vino_framebuffer_queue
*q
,
1004 memset(&q
->in
, 0, sizeof(struct vino_framebuffer_fifo
));
1005 memset(&q
->out
, 0, sizeof(struct vino_framebuffer_fifo
));
1006 for (i
= 0; i
< length
; i
++) {
1007 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
1009 vino_free_buffer(q
->buffer
[i
]);
1010 kfree(q
->buffer
[i
]);
1013 q
->type
= VINO_MEMORY_NONE
;
1017 static void vino_queue_free(struct vino_framebuffer_queue
*q
)
1019 dprintk("vino_queue_free():\n");
1021 if (q
->magic
!= VINO_QUEUE_MAGIC
)
1023 if (q
->type
!= VINO_MEMORY_MMAP
)
1026 mutex_lock(&q
->queue_mutex
);
1028 vino_queue_free_with_count(q
, q
->length
);
1030 mutex_unlock(&q
->queue_mutex
);
1033 static int vino_queue_init(struct vino_framebuffer_queue
*q
,
1034 unsigned int *length
)
1039 dprintk("vino_queue_init(): length = %d\n", *length
);
1041 if (q
->magic
== VINO_QUEUE_MAGIC
) {
1042 dprintk("vino_queue_init(): queue already initialized!\n");
1046 if (q
->type
!= VINO_MEMORY_NONE
) {
1047 dprintk("vino_queue_init(): queue already initialized!\n");
1054 mutex_lock(&q
->queue_mutex
);
1056 if (*length
> VINO_FRAMEBUFFER_COUNT_MAX
)
1057 *length
= VINO_FRAMEBUFFER_COUNT_MAX
;
1061 for (i
= 0; i
< *length
; i
++) {
1062 dprintk("vino_queue_init(): allocating buffer %d\n", i
);
1063 q
->buffer
[i
] = kmalloc(sizeof(struct vino_framebuffer
),
1065 if (!q
->buffer
[i
]) {
1066 dprintk("vino_queue_init(): kmalloc() failed\n");
1071 ret
= vino_allocate_buffer(q
->buffer
[i
],
1072 VINO_FRAMEBUFFER_SIZE
);
1074 kfree(q
->buffer
[i
]);
1075 dprintk("vino_queue_init(): "
1076 "vino_allocate_buffer() failed\n");
1080 q
->buffer
[i
]->id
= i
;
1082 q
->buffer
[i
]->offset
= q
->buffer
[i
- 1]->offset
+
1083 q
->buffer
[i
- 1]->size
;
1085 q
->buffer
[i
]->offset
= 0;
1088 spin_lock_init(&q
->buffer
[i
]->state_lock
);
1090 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1091 "size = %d\n", i
, q
->buffer
[i
]->offset
,
1092 q
->buffer
[i
]->size
);
1096 vino_queue_free_with_count(q
, i
);
1099 q
->length
= *length
;
1100 vino_fifo_init(&q
->in
, q
->length
);
1101 vino_fifo_init(&q
->out
, q
->length
);
1102 q
->type
= VINO_MEMORY_MMAP
;
1103 q
->magic
= VINO_QUEUE_MAGIC
;
1106 mutex_unlock(&q
->queue_mutex
);
1111 static struct vino_framebuffer
*vino_queue_add(struct
1112 vino_framebuffer_queue
*q
,
1115 struct vino_framebuffer
*ret
= NULL
;
1117 unsigned long flags
;
1119 dprintk("vino_queue_add(): id = %d\n", id
);
1121 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1125 spin_lock_irqsave(&q
->queue_lock
, flags
);
1130 if (id
>= q
->length
)
1133 /* not needed?: if (vino_fifo_full(&q->out)) {
1136 /* check that outgoing queue isn't already full
1137 * (or that it won't become full) */
1138 total
= vino_fifo_get_used(&q
->in
) +
1139 vino_fifo_get_used(&q
->out
);
1140 if (total
>= q
->length
)
1143 if (vino_fifo_enqueue(&q
->in
, id
))
1146 ret
= q
->buffer
[id
];
1149 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1154 static struct vino_framebuffer
*vino_queue_transfer(struct
1155 vino_framebuffer_queue
*q
)
1157 struct vino_framebuffer
*ret
= NULL
;
1158 struct vino_framebuffer
*fb
;
1160 unsigned long flags
;
1162 dprintk("vino_queue_transfer():\n");
1164 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1168 spin_lock_irqsave(&q
->queue_lock
, flags
);
1173 // now this actually removes an entry from the incoming queue
1174 if (vino_fifo_dequeue(&q
->in
, &id
)) {
1178 dprintk("vino_queue_transfer(): id = %d\n", id
);
1181 // we have already checked that the outgoing queue is not full, but...
1182 if (vino_fifo_enqueue(&q
->out
, id
)) {
1183 printk(KERN_ERR
"vino_queue_transfer(): "
1184 "outgoing queue is full, this shouldn't happen!\n");
1190 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1195 /* returns true/false */
1196 static int vino_queue_incoming_contains(struct vino_framebuffer_queue
*q
,
1200 unsigned long flags
;
1202 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1206 spin_lock_irqsave(&q
->queue_lock
, flags
);
1211 ret
= vino_fifo_has_id(&q
->in
, id
);
1214 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1219 /* returns true/false */
1220 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue
*q
,
1224 unsigned long flags
;
1226 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1230 spin_lock_irqsave(&q
->queue_lock
, flags
);
1235 ret
= vino_fifo_has_id(&q
->out
, id
);
1238 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1243 static int vino_queue_get_incoming(struct vino_framebuffer_queue
*q
,
1247 unsigned long flags
;
1249 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1250 return VINO_QUEUE_ERROR
;
1253 spin_lock_irqsave(&q
->queue_lock
, flags
);
1255 if (q
->length
== 0) {
1256 ret
= VINO_QUEUE_ERROR
;
1260 *used
= vino_fifo_get_used(&q
->in
);
1263 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1268 static int vino_queue_get_outgoing(struct vino_framebuffer_queue
*q
,
1272 unsigned long flags
;
1274 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1275 return VINO_QUEUE_ERROR
;
1278 spin_lock_irqsave(&q
->queue_lock
, flags
);
1280 if (q
->length
== 0) {
1281 ret
= VINO_QUEUE_ERROR
;
1285 *used
= vino_fifo_get_used(&q
->out
);
1288 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1294 static int vino_queue_get_total(struct vino_framebuffer_queue
*q
,
1295 unsigned int *total
)
1298 unsigned long flags
;
1300 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1301 return VINO_QUEUE_ERROR
;
1304 spin_lock_irqsave(&q
->queue_lock
, flags
);
1306 if (q
->length
== 0) {
1307 ret
= VINO_QUEUE_ERROR
;
1311 *total
= vino_fifo_get_used(&q
->in
) +
1312 vino_fifo_get_used(&q
->out
);
1315 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1321 static struct vino_framebuffer
*vino_queue_peek(struct
1322 vino_framebuffer_queue
*q
,
1325 struct vino_framebuffer
*ret
= NULL
;
1326 unsigned long flags
;
1328 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1332 spin_lock_irqsave(&q
->queue_lock
, flags
);
1337 if (vino_fifo_peek(&q
->in
, id
)) {
1341 ret
= q
->buffer
[*id
];
1343 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1348 static struct vino_framebuffer
*vino_queue_remove(struct
1349 vino_framebuffer_queue
*q
,
1352 struct vino_framebuffer
*ret
= NULL
;
1353 unsigned long flags
;
1354 dprintk("vino_queue_remove():\n");
1356 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1360 spin_lock_irqsave(&q
->queue_lock
, flags
);
1365 if (vino_fifo_dequeue(&q
->out
, id
)) {
1369 dprintk("vino_queue_remove(): id = %d\n", *id
);
1370 ret
= q
->buffer
[*id
];
1372 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1378 vino_framebuffer
*vino_queue_get_buffer(struct vino_framebuffer_queue
*q
,
1381 struct vino_framebuffer
*ret
= NULL
;
1382 unsigned long flags
;
1384 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1388 spin_lock_irqsave(&q
->queue_lock
, flags
);
1393 if (id
>= q
->length
)
1396 ret
= q
->buffer
[id
];
1398 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1403 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue
*q
)
1405 unsigned int length
= 0;
1406 unsigned long flags
;
1408 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1412 spin_lock_irqsave(&q
->queue_lock
, flags
);
1414 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1419 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue
*q
)
1423 unsigned long flags
;
1425 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1429 spin_lock_irqsave(&q
->queue_lock
, flags
);
1430 for (i
= 0; i
< q
->length
; i
++) {
1431 if (q
->buffer
[i
]->map_count
> 0) {
1436 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1441 /* VINO functions */
1443 /* execute with input_lock locked */
1444 static void vino_update_line_size(struct vino_channel_settings
*vcs
)
1446 unsigned int w
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1447 unsigned int d
= vcs
->decimation
;
1448 unsigned int bpp
= vino_data_formats
[vcs
->data_format
].bpp
;
1451 dprintk("update_line_size(): before: w = %d, d = %d, "
1452 "line_size = %d\n", w
, d
, vcs
->line_size
);
1454 /* line size must be multiple of 8 bytes */
1455 lsize
= (bpp
* (w
/ d
)) & ~7;
1456 w
= (lsize
/ bpp
) * d
;
1458 vcs
->clipping
.right
= vcs
->clipping
.left
+ w
;
1459 vcs
->line_size
= lsize
;
1461 dprintk("update_line_size(): after: w = %d, d = %d, "
1462 "line_size = %d\n", w
, d
, vcs
->line_size
);
1465 /* execute with input_lock locked */
1466 static void vino_set_clipping(struct vino_channel_settings
*vcs
,
1467 unsigned int x
, unsigned int y
,
1468 unsigned int w
, unsigned int h
)
1470 unsigned int maxwidth
, maxheight
;
1473 maxwidth
= vino_data_norms
[vcs
->data_norm
].width
;
1474 maxheight
= vino_data_norms
[vcs
->data_norm
].height
;
1475 d
= vcs
->decimation
;
1477 y
&= ~1; /* odd/even fields */
1482 if (y
> maxheight
) {
1486 if (((w
/ d
) < VINO_MIN_WIDTH
)
1487 || ((h
/ d
) < VINO_MIN_HEIGHT
)) {
1488 w
= VINO_MIN_WIDTH
* d
;
1489 h
= VINO_MIN_HEIGHT
* d
;
1492 if ((x
+ w
) > maxwidth
) {
1494 if ((w
/ d
) < VINO_MIN_WIDTH
)
1495 x
= maxwidth
- VINO_MIN_WIDTH
* d
;
1497 if ((y
+ h
) > maxheight
) {
1499 if ((h
/ d
) < VINO_MIN_HEIGHT
)
1500 y
= maxheight
- VINO_MIN_HEIGHT
* d
;
1503 vcs
->clipping
.left
= x
;
1504 vcs
->clipping
.top
= y
;
1505 vcs
->clipping
.right
= x
+ w
;
1506 vcs
->clipping
.bottom
= y
+ h
;
1508 vino_update_line_size(vcs
);
1510 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1511 vcs
->clipping
.left
, vcs
->clipping
.top
, vcs
->clipping
.right
,
1512 vcs
->clipping
.bottom
, vcs
->decimation
, vcs
->line_size
);
1515 /* execute with input_lock locked */
1516 static inline void vino_set_default_clipping(struct vino_channel_settings
*vcs
)
1518 vino_set_clipping(vcs
, 0, 0, vino_data_norms
[vcs
->data_norm
].width
,
1519 vino_data_norms
[vcs
->data_norm
].height
);
1522 /* execute with input_lock locked */
1523 static void vino_set_scaling(struct vino_channel_settings
*vcs
,
1524 unsigned int w
, unsigned int h
)
1526 unsigned int x
, y
, curw
, curh
, d
;
1528 x
= vcs
->clipping
.left
;
1529 y
= vcs
->clipping
.top
;
1530 curw
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1531 curh
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
1533 d
= max(curw
/ w
, curh
/ h
);
1535 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1536 w
, h
, curw
, curh
, d
);
1544 vcs
->decimation
= d
;
1545 vino_set_clipping(vcs
, x
, y
, w
* d
, h
* d
);
1547 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs
->clipping
.left
,
1548 vcs
->clipping
.top
, vcs
->clipping
.right
, vcs
->clipping
.bottom
,
1549 vcs
->decimation
, vcs
->line_size
);
1552 /* execute with input_lock locked */
1553 static inline void vino_set_default_scaling(struct vino_channel_settings
*vcs
)
1555 vino_set_scaling(vcs
, vcs
->clipping
.right
- vcs
->clipping
.left
,
1556 vcs
->clipping
.bottom
- vcs
->clipping
.top
);
1559 /* execute with input_lock locked */
1560 static void vino_set_framerate(struct vino_channel_settings
*vcs
,
1565 switch (vcs
->data_norm
) {
1566 case VINO_DATA_NORM_NTSC
:
1567 case VINO_DATA_NORM_D1
:
1568 fps
= (unsigned int)(fps
/ 6) * 6; // FIXME: round!
1570 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1571 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1572 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1573 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1592 mask
= VINO_FRAMERT_FULL
;
1594 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
);
1596 case VINO_DATA_NORM_PAL
:
1597 case VINO_DATA_NORM_SECAM
:
1598 fps
= (unsigned int)(fps
/ 5) * 5; // FIXME: round!
1600 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1601 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1602 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1603 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1622 mask
= VINO_FRAMERT_FULL
;
1624 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
) | VINO_FRAMERT_PAL
;
1631 /* execute with input_lock locked */
1632 static inline void vino_set_default_framerate(struct
1633 vino_channel_settings
*vcs
)
1635 vino_set_framerate(vcs
, vino_data_norms
[vcs
->data_norm
].fps_max
);
1639 * Prepare VINO for DMA transfer...
1640 * (execute only with vino_lock and input_lock locked)
1642 static int vino_dma_setup(struct vino_channel_settings
*vcs
,
1643 struct vino_framebuffer
*fb
)
1646 struct sgi_vino_channel
*ch
;
1647 const struct vino_data_norm
*norm
;
1649 dprintk("vino_dma_setup():\n");
1652 fb
->frame_counter
= 0;
1654 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1655 norm
= &vino_data_norms
[vcs
->data_norm
];
1660 /* VINO line size register is set 8 bytes less than actual */
1661 ch
->line_size
= vcs
->line_size
- 8;
1663 /* let VINO know where to transfer data */
1664 ch
->start_desc_tbl
= fb
->desc_table
.dma
;
1665 ch
->next_4_desc
= fb
->desc_table
.dma
;
1667 /* give vino time to fetch the first four descriptors, 5 usec
1668 * should be more than enough time */
1669 udelay(VINO_DESC_FETCH_DELAY
);
1671 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1672 ch
->start_desc_tbl
, ch
->next_4_desc
);
1674 /* set the alpha register */
1675 ch
->alpha
= vcs
->alpha
;
1677 /* set clipping registers */
1678 ch
->clip_start
= VINO_CLIP_ODD(norm
->odd
.top
+ vcs
->clipping
.top
/ 2) |
1679 VINO_CLIP_EVEN(norm
->even
.top
+
1680 vcs
->clipping
.top
/ 2) |
1681 VINO_CLIP_X(vcs
->clipping
.left
);
1682 ch
->clip_end
= VINO_CLIP_ODD(norm
->odd
.top
+
1683 vcs
->clipping
.bottom
/ 2 - 1) |
1684 VINO_CLIP_EVEN(norm
->even
.top
+
1685 vcs
->clipping
.bottom
/ 2 - 1) |
1686 VINO_CLIP_X(vcs
->clipping
.right
);
1688 /* set the size of actual content in the buffer (DECIMATION !) */
1689 fb
->data_size
= ((vcs
->clipping
.right
- vcs
->clipping
.left
) /
1691 ((vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
1693 vino_data_formats
[vcs
->data_format
].bpp
;
1695 ch
->frame_rate
= vcs
->framert_reg
;
1697 ctrl
= vino
->control
;
1698 intr
= vino
->intr_status
;
1700 if (vcs
->channel
== VINO_CHANNEL_A
) {
1701 /* All interrupt conditions for this channel was cleared
1702 * so clear the interrupt status register and enable
1704 intr
&= ~VINO_INTSTAT_A
;
1705 ctrl
|= VINO_CTRL_A_INT
;
1707 /* enable synchronization */
1708 ctrl
|= VINO_CTRL_A_SYNC_ENBL
;
1710 /* enable frame assembly */
1711 ctrl
|= VINO_CTRL_A_INTERLEAVE_ENBL
;
1713 /* set decimation used */
1714 if (vcs
->decimation
< 2)
1715 ctrl
&= ~VINO_CTRL_A_DEC_ENBL
;
1717 ctrl
|= VINO_CTRL_A_DEC_ENBL
;
1718 ctrl
&= ~VINO_CTRL_A_DEC_SCALE_MASK
;
1719 ctrl
|= (vcs
->decimation
- 1) <<
1720 VINO_CTRL_A_DEC_SCALE_SHIFT
;
1723 /* select input interface */
1724 if (vcs
->input
== VINO_INPUT_D1
)
1725 ctrl
|= VINO_CTRL_A_SELECT
;
1727 ctrl
&= ~VINO_CTRL_A_SELECT
;
1730 ctrl
&= ~(VINO_CTRL_A_LUMA_ONLY
| VINO_CTRL_A_RGB
|
1731 VINO_CTRL_A_DITHER
);
1733 intr
&= ~VINO_INTSTAT_B
;
1734 ctrl
|= VINO_CTRL_B_INT
;
1736 ctrl
|= VINO_CTRL_B_SYNC_ENBL
;
1737 ctrl
|= VINO_CTRL_B_INTERLEAVE_ENBL
;
1739 if (vcs
->decimation
< 2)
1740 ctrl
&= ~VINO_CTRL_B_DEC_ENBL
;
1742 ctrl
|= VINO_CTRL_B_DEC_ENBL
;
1743 ctrl
&= ~VINO_CTRL_B_DEC_SCALE_MASK
;
1744 ctrl
|= (vcs
->decimation
- 1) <<
1745 VINO_CTRL_B_DEC_SCALE_SHIFT
;
1748 if (vcs
->input
== VINO_INPUT_D1
)
1749 ctrl
|= VINO_CTRL_B_SELECT
;
1751 ctrl
&= ~VINO_CTRL_B_SELECT
;
1753 ctrl
&= ~(VINO_CTRL_B_LUMA_ONLY
| VINO_CTRL_B_RGB
|
1754 VINO_CTRL_B_DITHER
);
1758 fb
->data_format
= vcs
->data_format
;
1760 switch (vcs
->data_format
) {
1761 case VINO_DATA_FMT_GREY
:
1762 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1763 VINO_CTRL_A_LUMA_ONLY
: VINO_CTRL_B_LUMA_ONLY
;
1765 case VINO_DATA_FMT_RGB32
:
1766 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1767 VINO_CTRL_A_RGB
: VINO_CTRL_B_RGB
;
1769 case VINO_DATA_FMT_YUV
:
1770 /* nothing needs to be done */
1772 case VINO_DATA_FMT_RGB332
:
1773 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1774 VINO_CTRL_A_RGB
| VINO_CTRL_A_DITHER
:
1775 VINO_CTRL_B_RGB
| VINO_CTRL_B_DITHER
;
1779 vino
->intr_status
= intr
;
1780 vino
->control
= ctrl
;
1785 /* (execute only with vino_lock locked) */
1786 static inline void vino_dma_start(struct vino_channel_settings
*vcs
)
1788 u32 ctrl
= vino
->control
;
1790 dprintk("vino_dma_start():\n");
1791 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1792 VINO_CTRL_A_DMA_ENBL
: VINO_CTRL_B_DMA_ENBL
;
1793 vino
->control
= ctrl
;
1796 /* (execute only with vino_lock locked) */
1797 static inline void vino_dma_stop(struct vino_channel_settings
*vcs
)
1799 u32 ctrl
= vino
->control
;
1801 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1802 ~VINO_CTRL_A_DMA_ENBL
: ~VINO_CTRL_B_DMA_ENBL
;
1803 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1804 ~VINO_CTRL_A_INT
: ~VINO_CTRL_B_INT
;
1805 vino
->control
= ctrl
;
1806 dprintk("vino_dma_stop():\n");
1810 * Load dummy page to descriptor registers. This prevents generating of
1811 * spurious interrupts. (execute only with vino_lock locked)
1813 static void vino_clear_interrupt(struct vino_channel_settings
*vcs
)
1815 struct sgi_vino_channel
*ch
;
1817 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1822 ch
->start_desc_tbl
= vino_drvdata
->dummy_desc_table
.dma
;
1823 ch
->next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
1825 udelay(VINO_DESC_FETCH_DELAY
);
1826 dprintk("channel %c clear interrupt condition\n",
1827 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A':'B');
1830 static int vino_capture(struct vino_channel_settings
*vcs
,
1831 struct vino_framebuffer
*fb
)
1834 unsigned long flags
, flags2
;
1836 spin_lock_irqsave(&fb
->state_lock
, flags
);
1838 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
1840 fb
->state
= VINO_FRAMEBUFFER_IN_USE
;
1842 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
1847 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
1848 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags2
);
1850 vino_dma_setup(vcs
, fb
);
1851 vino_dma_start(vcs
);
1853 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags2
);
1854 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
1860 struct vino_framebuffer
*vino_capture_enqueue(struct
1861 vino_channel_settings
*vcs
,
1864 struct vino_framebuffer
*fb
;
1865 unsigned long flags
;
1867 dprintk("vino_capture_enqueue():\n");
1869 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
1871 fb
= vino_queue_add(&vcs
->fb_queue
, index
);
1873 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
1878 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1883 static int vino_capture_next(struct vino_channel_settings
*vcs
, int start
)
1885 struct vino_framebuffer
*fb
;
1886 unsigned int incoming
, id
;
1888 unsigned long flags
;
1890 dprintk("vino_capture_next():\n");
1892 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
1895 /* start capture only if capture isn't in progress already */
1896 if (vcs
->capturing
) {
1897 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1902 /* capture next frame:
1903 * stop capture if capturing is not set */
1904 if (!vcs
->capturing
) {
1905 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1910 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
1912 dprintk("vino_capture_next(): vino_queue_get_incoming() "
1917 if (incoming
== 0) {
1918 dprintk("vino_capture_next(): no buffers available\n");
1922 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
1924 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
1933 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1935 err
= vino_capture(vcs
, fb
);
1941 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1946 static inline int vino_is_capturing(struct vino_channel_settings
*vcs
)
1949 unsigned long flags
;
1951 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
1953 ret
= vcs
->capturing
;
1955 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1960 /* waits until a frame is captured */
1961 static int vino_wait_for_frame(struct vino_channel_settings
*vcs
)
1966 dprintk("vino_wait_for_frame():\n");
1968 init_waitqueue_entry(&wait
, current
);
1969 /* add ourselves into wait queue */
1970 add_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
1972 /* to ensure that schedule_timeout will return immediately
1973 * if VINO interrupt was triggered meanwhile */
1974 schedule_timeout_interruptible(msecs_to_jiffies(100));
1976 if (signal_pending(current
))
1979 remove_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
1981 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
1982 err
? "failed" : "ok");
1987 /* the function assumes that PAGE_SIZE % 4 == 0 */
1988 static void vino_convert_to_rgba(struct vino_framebuffer
*fb
) {
1989 unsigned char *pageptr
;
1990 unsigned int page
, i
;
1993 for (page
= 0; page
< fb
->desc_table
.page_count
; page
++) {
1994 pageptr
= (unsigned char *)fb
->desc_table
.virtual[page
];
1996 for (i
= 0; i
< PAGE_SIZE
; i
+= 4) {
1998 pageptr
[0] = pageptr
[3];
1999 pageptr
[1] = pageptr
[2];
2000 pageptr
[2] = pageptr
[1];
2007 /* checks if the buffer is in correct state and syncs data */
2008 static int vino_check_buffer(struct vino_channel_settings
*vcs
,
2009 struct vino_framebuffer
*fb
)
2012 unsigned long flags
;
2014 dprintk("vino_check_buffer():\n");
2016 spin_lock_irqsave(&fb
->state_lock
, flags
);
2017 switch (fb
->state
) {
2018 case VINO_FRAMEBUFFER_IN_USE
:
2021 case VINO_FRAMEBUFFER_READY
:
2022 vino_sync_buffer(fb
);
2023 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2028 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2031 if (vino_pixel_conversion
2032 && (fb
->data_format
== VINO_DATA_FMT_RGB32
)) {
2033 vino_convert_to_rgba(fb
);
2035 } else if (err
&& (err
!= -EINVAL
)) {
2036 dprintk("vino_check_buffer(): buffer not ready\n");
2038 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2040 vino_clear_interrupt(vcs
);
2041 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2047 /* forcefully terminates capture */
2048 static void vino_capture_stop(struct vino_channel_settings
*vcs
)
2050 unsigned int incoming
= 0, outgoing
= 0, id
;
2051 unsigned long flags
, flags2
;
2053 dprintk("vino_capture_stop():\n");
2055 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2057 /* unset capturing to stop queue processing */
2060 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags2
);
2063 vino_clear_interrupt(vcs
);
2065 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags2
);
2067 /* remove all items from the queue */
2068 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2069 dprintk("vino_capture_stop(): "
2070 "vino_queue_get_incoming() failed\n");
2073 while (incoming
> 0) {
2074 vino_queue_transfer(&vcs
->fb_queue
);
2076 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2077 dprintk("vino_capture_stop(): "
2078 "vino_queue_get_incoming() failed\n");
2083 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2084 dprintk("vino_capture_stop(): "
2085 "vino_queue_get_outgoing() failed\n");
2088 while (outgoing
> 0) {
2089 vino_queue_remove(&vcs
->fb_queue
, &id
);
2091 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2092 dprintk("vino_capture_stop(): "
2093 "vino_queue_get_outgoing() failed\n");
2099 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2103 static int vino_capture_failed(struct vino_channel_settings
*vcs
)
2105 struct vino_framebuffer
*fb
;
2106 unsigned long flags
;
2110 dprintk("vino_capture_failed():\n");
2112 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2115 vino_clear_interrupt(vcs
);
2117 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2119 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &i
);
2120 if (ret
== VINO_QUEUE_ERROR
) {
2121 dprintk("vino_queue_get_incoming() failed\n");
2125 /* no buffers to process */
2129 fb
= vino_queue_peek(&vcs
->fb_queue
, &i
);
2131 dprintk("vino_queue_peek() failed\n");
2135 spin_lock_irqsave(&fb
->state_lock
, flags
);
2136 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
) {
2137 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2138 vino_queue_transfer(&vcs
->fb_queue
);
2139 vino_queue_remove(&vcs
->fb_queue
, &i
);
2140 /* we should actually discard the newest frame,
2141 * but who cares ... */
2143 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2149 static void vino_skip_frame(struct vino_channel_settings
*vcs
)
2151 struct vino_framebuffer
*fb
;
2152 unsigned long flags
;
2155 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2156 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2158 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2159 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2162 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2164 spin_lock_irqsave(&fb
->state_lock
, flags
);
2165 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2166 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2168 vino_capture_next(vcs
, 0);
2171 static void vino_frame_done(struct vino_channel_settings
*vcs
)
2173 struct vino_framebuffer
*fb
;
2174 unsigned long flags
;
2176 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2177 fb
= vino_queue_transfer(&vcs
->fb_queue
);
2179 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2180 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2183 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2185 fb
->frame_counter
= vcs
->int_data
.frame_counter
;
2186 memcpy(&fb
->timestamp
, &vcs
->int_data
.timestamp
,
2187 sizeof(struct timeval
));
2189 spin_lock_irqsave(&fb
->state_lock
, flags
);
2190 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
2191 fb
->state
= VINO_FRAMEBUFFER_READY
;
2192 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2194 wake_up(&vcs
->fb_queue
.frame_wait_queue
);
2196 vino_capture_next(vcs
, 0);
2199 static void vino_capture_tasklet(unsigned long channel
) {
2200 struct vino_channel_settings
*vcs
;
2202 vcs
= (channel
== VINO_CHANNEL_A
)
2203 ? &vino_drvdata
->a
: &vino_drvdata
->b
;
2205 if (vcs
->int_data
.skip
)
2206 vcs
->int_data
.skip_count
++;
2208 if (vcs
->int_data
.skip
&& (vcs
->int_data
.skip_count
2209 <= VINO_MAX_FRAME_SKIP_COUNT
)) {
2210 vino_skip_frame(vcs
);
2212 vcs
->int_data
.skip_count
= 0;
2213 vino_frame_done(vcs
);
2217 static irqreturn_t
vino_interrupt(int irq
, void *dev_id
)
2220 unsigned int fc_a
, fc_b
;
2221 int handled_a
= 0, skip_a
= 0, done_a
= 0;
2222 int handled_b
= 0, skip_b
= 0, done_b
= 0;
2224 #ifdef VINO_DEBUG_INT
2226 unsigned int line_count
= vino
->a
.line_count
,
2227 page_index
= vino
->a
.page_index
,
2228 field_counter
= vino
->a
.field_counter
,
2229 start_desc_tbl
= vino
->a
.start_desc_tbl
,
2230 next_4_desc
= vino
->a
.next_4_desc
;
2231 unsigned int line_count_2
,
2238 spin_lock(&vino_drvdata
->vino_lock
);
2240 while ((intr
= vino
->intr_status
)) {
2241 fc_a
= vino
->a
.field_counter
>> 1;
2242 fc_b
= vino
->b
.field_counter
>> 1;
2244 /* handle error-interrupts in some special way ?
2245 * --> skips frames */
2246 if (intr
& VINO_INTSTAT_A
) {
2247 if (intr
& VINO_INTSTAT_A_EOF
) {
2248 vino_drvdata
->a
.field
++;
2249 if (vino_drvdata
->a
.field
> 1) {
2250 vino_dma_stop(&vino_drvdata
->a
);
2251 vino_clear_interrupt(&vino_drvdata
->a
);
2252 vino_drvdata
->a
.field
= 0;
2255 if (vino
->a
.page_index
2256 != vino_drvdata
->a
.line_size
) {
2257 vino
->a
.line_count
= 0;
2258 vino
->a
.page_index
=
2261 vino
->a
.next_4_desc
=
2262 vino
->a
.start_desc_tbl
;
2265 dprintk("channel A end-of-field "
2266 "interrupt: %04x\n", intr
);
2268 vino_dma_stop(&vino_drvdata
->a
);
2269 vino_clear_interrupt(&vino_drvdata
->a
);
2270 vino_drvdata
->a
.field
= 0;
2272 dprintk("channel A error interrupt: %04x\n",
2276 #ifdef VINO_DEBUG_INT
2277 line_count_2
= vino
->a
.line_count
;
2278 page_index_2
= vino
->a
.page_index
;
2279 field_counter_2
= vino
->a
.field_counter
;
2280 start_desc_tbl_2
= vino
->a
.start_desc_tbl
;
2281 next_4_desc_2
= vino
->a
.next_4_desc
;
2283 printk("intr = %04x, loop = %d, field = %d\n",
2284 intr
, loop
, vino_drvdata
->a
.field
);
2285 printk("1- line count = %04d, page index = %04d, "
2286 "start = %08x, next = %08x\n"
2287 " fieldc = %d, framec = %d\n",
2288 line_count
, page_index
, start_desc_tbl
,
2289 next_4_desc
, field_counter
, fc_a
);
2290 printk("12-line count = %04d, page index = %04d, "
2291 " start = %08x, next = %08x\n",
2292 line_count_2
, page_index_2
, start_desc_tbl_2
,
2300 if (intr
& VINO_INTSTAT_B
) {
2301 if (intr
& VINO_INTSTAT_B_EOF
) {
2302 vino_drvdata
->b
.field
++;
2303 if (vino_drvdata
->b
.field
> 1) {
2304 vino_dma_stop(&vino_drvdata
->b
);
2305 vino_clear_interrupt(&vino_drvdata
->b
);
2306 vino_drvdata
->b
.field
= 0;
2309 dprintk("channel B end-of-field "
2310 "interrupt: %04x\n", intr
);
2312 vino_dma_stop(&vino_drvdata
->b
);
2313 vino_clear_interrupt(&vino_drvdata
->b
);
2314 vino_drvdata
->b
.field
= 0;
2316 dprintk("channel B error interrupt: %04x\n",
2321 /* Always remember to clear interrupt status.
2322 * Disable VINO interrupts while we do this. */
2323 ctrl
= vino
->control
;
2324 vino
->control
= ctrl
& ~(VINO_CTRL_A_INT
| VINO_CTRL_B_INT
);
2325 vino
->intr_status
= ~intr
;
2326 vino
->control
= ctrl
;
2328 spin_unlock(&vino_drvdata
->vino_lock
);
2330 if ((!handled_a
) && (done_a
|| skip_a
)) {
2332 do_gettimeofday(&vino_drvdata
->
2333 a
.int_data
.timestamp
);
2334 vino_drvdata
->a
.int_data
.frame_counter
= fc_a
;
2336 vino_drvdata
->a
.int_data
.skip
= skip_a
;
2338 dprintk("channel A %s, interrupt: %d\n",
2339 skip_a
? "skipping frame" : "frame done",
2341 tasklet_hi_schedule(&vino_tasklet_a
);
2345 if ((!handled_b
) && (done_b
|| skip_b
)) {
2347 do_gettimeofday(&vino_drvdata
->
2348 b
.int_data
.timestamp
);
2349 vino_drvdata
->b
.int_data
.frame_counter
= fc_b
;
2351 vino_drvdata
->b
.int_data
.skip
= skip_b
;
2353 dprintk("channel B %s, interrupt: %d\n",
2354 skip_b
? "skipping frame" : "frame done",
2356 tasklet_hi_schedule(&vino_tasklet_b
);
2360 #ifdef VINO_DEBUG_INT
2363 spin_lock(&vino_drvdata
->vino_lock
);
2366 spin_unlock(&vino_drvdata
->vino_lock
);
2371 /* VINO video input management */
2373 static int vino_get_saa7191_input(int input
)
2376 case VINO_INPUT_COMPOSITE
:
2377 return SAA7191_INPUT_COMPOSITE
;
2378 case VINO_INPUT_SVIDEO
:
2379 return SAA7191_INPUT_SVIDEO
;
2381 printk(KERN_ERR
"VINO: vino_get_saa7191_input(): "
2382 "invalid input!\n");
2387 /* execute with input_lock locked */
2388 static int vino_is_input_owner(struct vino_channel_settings
*vcs
)
2390 switch(vcs
->input
) {
2391 case VINO_INPUT_COMPOSITE
:
2392 case VINO_INPUT_SVIDEO
:
2393 return vino_drvdata
->decoder_owner
== vcs
->channel
;
2395 return vino_drvdata
->camera_owner
== vcs
->channel
;
2401 static int vino_acquire_input(struct vino_channel_settings
*vcs
)
2403 unsigned long flags
;
2406 dprintk("vino_acquire_input():\n");
2408 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2410 /* First try D1 and then SAA7191 */
2411 if (vino_drvdata
->camera
2412 && (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)) {
2413 vino_drvdata
->camera_owner
= vcs
->channel
;
2414 vcs
->input
= VINO_INPUT_D1
;
2415 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2416 } else if (vino_drvdata
->decoder
2417 && (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
)) {
2421 struct v4l2_routing route
= { 0, 0 };
2423 input
= VINO_INPUT_COMPOSITE
;
2425 route
.input
= vino_get_saa7191_input(input
);
2426 ret
= decoder_call(video
, s_routing
, &route
);
2432 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2434 /* Don't hold spinlocks while auto-detecting norm
2435 * as it may take a while... */
2437 ret
= decoder_call(video
, querystd
, &norm
);
2439 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2440 if (vino_data_norms
[data_norm
].std
& norm
)
2444 data_norm
= VINO_DATA_NORM_PAL
;
2445 ret
= decoder_call(tuner
, s_std
, norm
);
2448 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2455 vino_drvdata
->decoder_owner
= vcs
->channel
;
2458 vcs
->data_norm
= data_norm
;
2460 vcs
->input
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2461 vino_drvdata
->b
.input
: vino_drvdata
->a
.input
;
2462 vcs
->data_norm
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2463 vino_drvdata
->b
.data_norm
: vino_drvdata
->a
.data_norm
;
2466 if (vcs
->input
== VINO_INPUT_NONE
) {
2471 vino_set_default_clipping(vcs
);
2472 vino_set_default_scaling(vcs
);
2473 vino_set_default_framerate(vcs
);
2475 dprintk("vino_acquire_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2478 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2483 static int vino_set_input(struct vino_channel_settings
*vcs
, int input
)
2485 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2486 &vino_drvdata
->b
: &vino_drvdata
->a
;
2487 unsigned long flags
;
2490 dprintk("vino_set_input():\n");
2492 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2494 if (vcs
->input
== input
)
2498 case VINO_INPUT_COMPOSITE
:
2499 case VINO_INPUT_SVIDEO
:
2500 if (!vino_drvdata
->decoder
) {
2505 if (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
) {
2506 vino_drvdata
->decoder_owner
= vcs
->channel
;
2509 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2512 struct v4l2_routing route
= { 0, 0 };
2514 route
.input
= vino_get_saa7191_input(input
);
2515 ret
= decoder_call(video
, s_routing
, &route
);
2517 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2522 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2524 /* Don't hold spinlocks while auto-detecting norm
2525 * as it may take a while... */
2527 ret
= decoder_call(video
, querystd
, &norm
);
2529 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2530 if (vino_data_norms
[data_norm
].std
& norm
)
2534 data_norm
= VINO_DATA_NORM_PAL
;
2535 ret
= decoder_call(tuner
, s_std
, norm
);
2538 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2541 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2547 vcs
->data_norm
= data_norm
;
2549 if (input
!= vcs2
->input
) {
2555 vcs
->data_norm
= vcs2
->data_norm
;
2558 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2559 /* Transfer the ownership or release the input */
2560 if (vcs2
->input
== VINO_INPUT_D1
) {
2561 vino_drvdata
->camera_owner
= vcs2
->channel
;
2563 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2568 if (!vino_drvdata
->camera
) {
2573 if (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)
2574 vino_drvdata
->camera_owner
= vcs
->channel
;
2576 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2577 /* Transfer the ownership or release the input */
2578 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2579 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2580 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2582 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2587 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2594 vino_set_default_clipping(vcs
);
2595 vino_set_default_scaling(vcs
);
2596 vino_set_default_framerate(vcs
);
2598 dprintk("vino_set_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2601 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2606 static void vino_release_input(struct vino_channel_settings
*vcs
)
2608 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2609 &vino_drvdata
->b
: &vino_drvdata
->a
;
2610 unsigned long flags
;
2612 dprintk("vino_release_input():\n");
2614 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2616 /* Release ownership of the channel
2617 * and if the other channel takes input from
2618 * the same source, transfer the ownership */
2619 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2620 if (vcs2
->input
== VINO_INPUT_D1
) {
2621 vino_drvdata
->camera_owner
= vcs2
->channel
;
2623 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2625 } else if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2626 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2627 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2628 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2630 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2633 vcs
->input
= VINO_INPUT_NONE
;
2635 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2638 /* execute with input_lock locked */
2639 static int vino_set_data_norm(struct vino_channel_settings
*vcs
,
2640 unsigned int data_norm
,
2641 unsigned long *flags
)
2645 if (data_norm
== vcs
->data_norm
)
2648 switch (vcs
->input
) {
2650 /* only one "norm" supported */
2651 if (data_norm
!= VINO_DATA_NORM_D1
)
2654 case VINO_INPUT_COMPOSITE
:
2655 case VINO_INPUT_SVIDEO
: {
2658 if ((data_norm
!= VINO_DATA_NORM_PAL
)
2659 && (data_norm
!= VINO_DATA_NORM_NTSC
)
2660 && (data_norm
!= VINO_DATA_NORM_SECAM
))
2663 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, *flags
);
2665 /* Don't hold spinlocks while setting norm
2666 * as it may take a while... */
2668 norm
= vino_data_norms
[data_norm
].std
;
2669 err
= decoder_call(tuner
, s_std
, norm
);
2671 spin_lock_irqsave(&vino_drvdata
->input_lock
, *flags
);
2676 vcs
->data_norm
= data_norm
;
2678 vino_set_default_clipping(vcs
);
2679 vino_set_default_scaling(vcs
);
2680 vino_set_default_framerate(vcs
);
2691 /* V4L2 helper functions */
2693 static int vino_find_data_format(__u32 pixelformat
)
2697 for (i
= 0; i
< VINO_DATA_FMT_COUNT
; i
++) {
2698 if (vino_data_formats
[i
].pixelformat
== pixelformat
)
2702 return VINO_DATA_FMT_NONE
;
2705 static int vino_int_enum_input(struct vino_channel_settings
*vcs
, __u32 index
)
2707 int input
= VINO_INPUT_NONE
;
2708 unsigned long flags
;
2710 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2711 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2714 input
= VINO_INPUT_COMPOSITE
;
2717 input
= VINO_INPUT_SVIDEO
;
2720 input
= VINO_INPUT_D1
;
2723 } else if (vino_drvdata
->decoder
) {
2726 input
= VINO_INPUT_COMPOSITE
;
2729 input
= VINO_INPUT_SVIDEO
;
2732 } else if (vino_drvdata
->camera
) {
2735 input
= VINO_INPUT_D1
;
2739 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2744 /* execute with input_lock locked */
2745 static __u32
vino_find_input_index(struct vino_channel_settings
*vcs
)
2748 // FIXME: detect when no inputs available
2750 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2751 switch (vcs
->input
) {
2752 case VINO_INPUT_COMPOSITE
:
2755 case VINO_INPUT_SVIDEO
:
2762 } else if (vino_drvdata
->decoder
) {
2763 switch (vcs
->input
) {
2764 case VINO_INPUT_COMPOSITE
:
2767 case VINO_INPUT_SVIDEO
:
2771 } else if (vino_drvdata
->camera
) {
2772 switch (vcs
->input
) {
2784 static int vino_querycap(struct file
*file
, void *__fh
,
2785 struct v4l2_capability
*cap
)
2787 memset(cap
, 0, sizeof(struct v4l2_capability
));
2789 strcpy(cap
->driver
, vino_driver_name
);
2790 strcpy(cap
->card
, vino_driver_description
);
2791 strcpy(cap
->bus_info
, vino_bus_name
);
2792 cap
->version
= VINO_VERSION_CODE
;
2794 V4L2_CAP_VIDEO_CAPTURE
|
2796 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
2800 static int vino_enum_input(struct file
*file
, void *__fh
,
2801 struct v4l2_input
*i
)
2803 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2804 __u32 index
= i
->index
;
2806 dprintk("requested index = %d\n", index
);
2808 input
= vino_int_enum_input(vcs
, index
);
2809 if (input
== VINO_INPUT_NONE
)
2812 memset(i
, 0, sizeof(struct v4l2_input
));
2815 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
2816 i
->std
= vino_inputs
[input
].std
;
2817 strcpy(i
->name
, vino_inputs
[input
].name
);
2819 if (input
== VINO_INPUT_COMPOSITE
|| input
== VINO_INPUT_SVIDEO
)
2820 decoder_call(video
, g_input_status
, &i
->status
);
2824 static int vino_g_input(struct file
*file
, void *__fh
,
2827 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2830 unsigned long flags
;
2832 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2834 index
= vino_find_input_index(vcs
);
2835 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2837 dprintk("input = %d\n", input
);
2839 if (input
== VINO_INPUT_NONE
) {
2848 static int vino_s_input(struct file
*file
, void *__fh
,
2851 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2853 dprintk("requested input = %d\n", i
);
2855 input
= vino_int_enum_input(vcs
, i
);
2856 if (input
== VINO_INPUT_NONE
)
2859 return vino_set_input(vcs
, input
);
2862 static int vino_querystd(struct file
*file
, void *__fh
,
2865 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2866 unsigned long flags
;
2869 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2871 switch (vcs
->input
) {
2873 *std
= vino_inputs
[vcs
->input
].std
;
2875 case VINO_INPUT_COMPOSITE
:
2876 case VINO_INPUT_SVIDEO
: {
2877 decoder_call(video
, querystd
, std
);
2884 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2889 static int vino_g_std(struct file
*file
, void *__fh
,
2892 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2893 unsigned long flags
;
2895 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2897 *std
= vino_data_norms
[vcs
->data_norm
].std
;
2898 dprintk("current standard = %d\n", vcs
->data_norm
);
2900 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2905 static int vino_s_std(struct file
*file
, void *__fh
,
2908 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2909 unsigned long flags
;
2912 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2914 if (!vino_is_input_owner(vcs
)) {
2919 /* check if the standard is valid for the current input */
2920 if ((*std
) & vino_inputs
[vcs
->input
].std
) {
2921 dprintk("standard accepted\n");
2923 /* change the video norm for SAA7191
2924 * and accept NTSC for D1 (do nothing) */
2926 if (vcs
->input
== VINO_INPUT_D1
)
2929 if ((*std
) & V4L2_STD_PAL
) {
2930 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_PAL
,
2932 } else if ((*std
) & V4L2_STD_NTSC
) {
2933 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_NTSC
,
2935 } else if ((*std
) & V4L2_STD_SECAM
) {
2936 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_SECAM
,
2950 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2955 static int vino_enum_fmt_vid_cap(struct file
*file
, void *__fh
,
2956 struct v4l2_fmtdesc
*fd
)
2958 enum v4l2_buf_type type
= fd
->type
;
2959 int index
= fd
->index
;
2961 dprintk("format index = %d\n", index
);
2963 if ((fd
->index
< 0) ||
2964 (fd
->index
>= VINO_DATA_FMT_COUNT
))
2966 dprintk("format name = %s\n",
2967 vino_data_formats
[index
].description
);
2969 memset(fd
, 0, sizeof(struct v4l2_fmtdesc
));
2972 fd
->pixelformat
= vino_data_formats
[index
].pixelformat
;
2973 strcpy(fd
->description
, vino_data_formats
[index
].description
);
2977 static int vino_try_fmt_vid_cap(struct file
*file
, void *__fh
,
2978 struct v4l2_format
*f
)
2980 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2981 struct vino_channel_settings tempvcs
;
2982 unsigned long flags
;
2983 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
2985 dprintk("requested: w = %d, h = %d\n",
2986 pf
->width
, pf
->height
);
2988 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2989 memcpy(&tempvcs
, vcs
, sizeof(struct vino_channel_settings
));
2990 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2992 tempvcs
.data_format
= vino_find_data_format(pf
->pixelformat
);
2993 if (tempvcs
.data_format
== VINO_DATA_FMT_NONE
) {
2994 tempvcs
.data_format
= VINO_DATA_FMT_GREY
;
2996 vino_data_formats
[tempvcs
.data_format
].
3000 /* data format must be set before clipping/scaling */
3001 vino_set_scaling(&tempvcs
, pf
->width
, pf
->height
);
3003 dprintk("data format = %s\n",
3004 vino_data_formats
[tempvcs
.data_format
].description
);
3006 pf
->width
= (tempvcs
.clipping
.right
- tempvcs
.clipping
.left
) /
3008 pf
->height
= (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3011 pf
->field
= V4L2_FIELD_INTERLACED
;
3012 pf
->bytesperline
= tempvcs
.line_size
;
3013 pf
->sizeimage
= tempvcs
.line_size
*
3014 (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3017 vino_data_formats
[tempvcs
.data_format
].colorspace
;
3023 static int vino_g_fmt_vid_cap(struct file
*file
, void *__fh
,
3024 struct v4l2_format
*f
)
3026 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3027 unsigned long flags
;
3028 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3030 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3032 pf
->width
= (vcs
->clipping
.right
- vcs
->clipping
.left
) /
3034 pf
->height
= (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3037 vino_data_formats
[vcs
->data_format
].pixelformat
;
3039 pf
->field
= V4L2_FIELD_INTERLACED
;
3040 pf
->bytesperline
= vcs
->line_size
;
3041 pf
->sizeimage
= vcs
->line_size
*
3042 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3045 vino_data_formats
[vcs
->data_format
].colorspace
;
3049 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3053 static int vino_s_fmt_vid_cap(struct file
*file
, void *__fh
,
3054 struct v4l2_format
*f
)
3056 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3058 unsigned long flags
;
3059 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3061 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3063 data_format
= vino_find_data_format(pf
->pixelformat
);
3065 if (data_format
== VINO_DATA_FMT_NONE
) {
3066 vcs
->data_format
= VINO_DATA_FMT_GREY
;
3068 vino_data_formats
[vcs
->data_format
].
3071 vcs
->data_format
= data_format
;
3074 /* data format must be set before clipping/scaling */
3075 vino_set_scaling(vcs
, pf
->width
, pf
->height
);
3077 dprintk("data format = %s\n",
3078 vino_data_formats
[vcs
->data_format
].description
);
3080 pf
->width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3081 pf
->height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3083 pf
->field
= V4L2_FIELD_INTERLACED
;
3084 pf
->bytesperline
= vcs
->line_size
;
3085 pf
->sizeimage
= vcs
->line_size
*
3086 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3089 vino_data_formats
[vcs
->data_format
].colorspace
;
3093 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3097 static int vino_cropcap(struct file
*file
, void *__fh
,
3098 struct v4l2_cropcap
*ccap
)
3100 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3101 const struct vino_data_norm
*norm
;
3102 unsigned long flags
;
3104 switch (ccap
->type
) {
3105 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3106 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3108 norm
= &vino_data_norms
[vcs
->data_norm
];
3110 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3112 ccap
->bounds
.left
= 0;
3113 ccap
->bounds
.top
= 0;
3114 ccap
->bounds
.width
= norm
->width
;
3115 ccap
->bounds
.height
= norm
->height
;
3116 memcpy(&ccap
->defrect
, &ccap
->bounds
,
3117 sizeof(struct v4l2_rect
));
3119 ccap
->pixelaspect
.numerator
= 1;
3120 ccap
->pixelaspect
.denominator
= 1;
3122 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3130 static int vino_g_crop(struct file
*file
, void *__fh
,
3131 struct v4l2_crop
*c
)
3133 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3134 unsigned long flags
;
3137 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3138 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3140 c
->c
.left
= vcs
->clipping
.left
;
3141 c
->c
.top
= vcs
->clipping
.top
;
3142 c
->c
.width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3143 c
->c
.height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3145 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3147 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3155 static int vino_s_crop(struct file
*file
, void *__fh
,
3156 struct v4l2_crop
*c
)
3158 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3159 unsigned long flags
;
3162 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3163 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3165 vino_set_clipping(vcs
, c
->c
.left
, c
->c
.top
,
3166 c
->c
.width
, c
->c
.height
);
3168 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3170 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3178 static int vino_g_parm(struct file
*file
, void *__fh
,
3179 struct v4l2_streamparm
*sp
)
3181 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3182 unsigned long flags
;
3185 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3186 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3187 memset(cp
, 0, sizeof(struct v4l2_captureparm
));
3189 cp
->capability
= V4L2_CAP_TIMEPERFRAME
;
3190 cp
->timeperframe
.numerator
= 1;
3192 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3194 cp
->timeperframe
.denominator
= vcs
->fps
;
3196 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3198 // TODO: cp->readbuffers = xxx;
3201 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3209 static int vino_s_parm(struct file
*file
, void *__fh
,
3210 struct v4l2_streamparm
*sp
)
3212 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3213 unsigned long flags
;
3216 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3217 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3219 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3221 if ((cp
->timeperframe
.numerator
== 0) ||
3222 (cp
->timeperframe
.denominator
== 0)) {
3223 /* reset framerate */
3224 vino_set_default_framerate(vcs
);
3226 vino_set_framerate(vcs
, cp
->timeperframe
.denominator
/
3227 cp
->timeperframe
.numerator
);
3230 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3232 // TODO: set buffers according to cp->readbuffers
3235 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3243 static int vino_reqbufs(struct file
*file
, void *__fh
,
3244 struct v4l2_requestbuffers
*rb
)
3246 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3251 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3252 // TODO: check queue type
3253 if (rb
->memory
!= V4L2_MEMORY_MMAP
) {
3254 dprintk("type not mmap\n");
3258 dprintk("count = %d\n", rb
->count
);
3259 if (rb
->count
> 0) {
3260 if (vino_is_capturing(vcs
)) {
3261 dprintk("busy, capturing\n");
3265 if (vino_queue_has_mapped_buffers(&vcs
->fb_queue
)) {
3266 dprintk("busy, buffers still mapped\n");
3270 vino_queue_free(&vcs
->fb_queue
);
3271 vino_queue_init(&vcs
->fb_queue
, &rb
->count
);
3275 vino_capture_stop(vcs
);
3276 vino_queue_free(&vcs
->fb_queue
);
3280 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3288 static void vino_v4l2_get_buffer_status(struct vino_channel_settings
*vcs
,
3289 struct vino_framebuffer
*fb
,
3290 struct v4l2_buffer
*b
)
3292 if (vino_queue_outgoing_contains(&vcs
->fb_queue
,
3294 b
->flags
&= ~V4L2_BUF_FLAG_QUEUED
;
3295 b
->flags
|= V4L2_BUF_FLAG_DONE
;
3296 } else if (vino_queue_incoming_contains(&vcs
->fb_queue
,
3298 b
->flags
&= ~V4L2_BUF_FLAG_DONE
;
3299 b
->flags
|= V4L2_BUF_FLAG_QUEUED
;
3301 b
->flags
&= ~(V4L2_BUF_FLAG_DONE
|
3302 V4L2_BUF_FLAG_QUEUED
);
3305 b
->flags
&= ~(V4L2_BUF_FLAG_TIMECODE
);
3307 if (fb
->map_count
> 0)
3308 b
->flags
|= V4L2_BUF_FLAG_MAPPED
;
3311 b
->memory
= (vcs
->fb_queue
.type
== VINO_MEMORY_MMAP
) ?
3312 V4L2_MEMORY_MMAP
: V4L2_MEMORY_USERPTR
;
3313 b
->m
.offset
= fb
->offset
;
3314 b
->bytesused
= fb
->data_size
;
3315 b
->length
= fb
->size
;
3316 b
->field
= V4L2_FIELD_INTERLACED
;
3317 b
->sequence
= fb
->frame_counter
;
3318 memcpy(&b
->timestamp
, &fb
->timestamp
,
3319 sizeof(struct timeval
));
3322 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3323 fb
->id
, fb
->size
, fb
->data_size
, fb
->offset
);
3326 static int vino_querybuf(struct file
*file
, void *__fh
,
3327 struct v4l2_buffer
*b
)
3329 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3334 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3335 struct vino_framebuffer
*fb
;
3337 // TODO: check queue type
3338 if (b
->index
>= vino_queue_get_length(&vcs
->fb_queue
)) {
3339 dprintk("invalid index = %d\n",
3344 fb
= vino_queue_get_buffer(&vcs
->fb_queue
,
3347 dprintk("vino_queue_get_buffer() failed");
3351 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3354 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3362 static int vino_qbuf(struct file
*file
, void *__fh
,
3363 struct v4l2_buffer
*b
)
3365 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3370 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3371 struct vino_framebuffer
*fb
;
3374 // TODO: check queue type
3375 if (b
->memory
!= V4L2_MEMORY_MMAP
) {
3376 dprintk("type not mmap\n");
3380 fb
= vino_capture_enqueue(vcs
, b
->index
);
3384 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3386 if (vcs
->streaming
) {
3387 ret
= vino_capture_next(vcs
, 1);
3393 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3401 static int vino_dqbuf(struct file
*file
, void *__fh
,
3402 struct v4l2_buffer
*b
)
3404 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3405 unsigned int nonblocking
= file
->f_flags
& O_NONBLOCK
;
3410 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3411 struct vino_framebuffer
*fb
;
3412 unsigned int incoming
, outgoing
;
3415 // TODO: check queue type
3417 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3419 dprintk("vino_queue_get_incoming() failed\n");
3422 err
= vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
);
3424 dprintk("vino_queue_get_outgoing() failed\n");
3428 dprintk("incoming = %d, outgoing = %d\n", incoming
, outgoing
);
3430 if (outgoing
== 0) {
3431 if (incoming
== 0) {
3432 dprintk("no incoming or outgoing buffers\n");
3436 dprintk("non-blocking I/O was selected and "
3437 "there are no buffers to dequeue\n");
3441 err
= vino_wait_for_frame(vcs
);
3443 err
= vino_wait_for_frame(vcs
);
3446 * no frames captured because
3447 * of frame skipping */
3448 // vino_capture_failed(vcs);
3454 fb
= vino_queue_remove(&vcs
->fb_queue
, &b
->index
);
3456 dprintk("vino_queue_remove() failed\n");
3460 err
= vino_check_buffer(vcs
, fb
);
3462 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3469 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3477 static int vino_streamon(struct file
*file
, void *__fh
,
3478 enum v4l2_buf_type i
)
3480 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3481 unsigned int incoming
;
3489 // TODO: check queue type
3491 if (vino_queue_get_length(&vcs
->fb_queue
) < 1) {
3492 dprintk("no buffers allocated\n");
3496 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3498 dprintk("vino_queue_get_incoming() failed\n");
3505 ret
= vino_capture_next(vcs
, 1);
3509 dprintk("couldn't start capture\n");
3517 static int vino_streamoff(struct file
*file
, void *__fh
,
3518 enum v4l2_buf_type i
)
3520 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3524 if (!vcs
->streaming
)
3528 vino_capture_stop(vcs
);
3533 static int vino_queryctrl(struct file
*file
, void *__fh
,
3534 struct v4l2_queryctrl
*queryctrl
)
3536 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3537 unsigned long flags
;
3541 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3543 switch (vcs
->input
) {
3545 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3546 if (vino_indycam_v4l2_controls
[i
].id
==
3549 &vino_indycam_v4l2_controls
[i
],
3550 sizeof(struct v4l2_queryctrl
));
3551 queryctrl
->reserved
[0] = 0;
3558 case VINO_INPUT_COMPOSITE
:
3559 case VINO_INPUT_SVIDEO
:
3560 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3561 if (vino_saa7191_v4l2_controls
[i
].id
==
3564 &vino_saa7191_v4l2_controls
[i
],
3565 sizeof(struct v4l2_queryctrl
));
3566 queryctrl
->reserved
[0] = 0;
3578 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3583 static int vino_g_ctrl(struct file
*file
, void *__fh
,
3584 struct v4l2_control
*control
)
3586 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3587 unsigned long flags
;
3591 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3593 switch (vcs
->input
) {
3594 case VINO_INPUT_D1
: {
3596 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3597 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3606 err
= camera_call(core
, g_ctrl
, control
);
3611 case VINO_INPUT_COMPOSITE
:
3612 case VINO_INPUT_SVIDEO
: {
3614 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3615 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3624 err
= decoder_call(core
, g_ctrl
, control
);
3634 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3639 static int vino_s_ctrl(struct file
*file
, void *__fh
,
3640 struct v4l2_control
*control
)
3642 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3643 unsigned long flags
;
3647 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3649 if (!vino_is_input_owner(vcs
)) {
3654 switch (vcs
->input
) {
3655 case VINO_INPUT_D1
: {
3657 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3658 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3665 if (control
->value
< vino_indycam_v4l2_controls
[i
].minimum
||
3666 control
->value
> vino_indycam_v4l2_controls
[i
].maximum
) {
3670 err
= camera_call(core
, s_ctrl
, control
);
3675 case VINO_INPUT_COMPOSITE
:
3676 case VINO_INPUT_SVIDEO
: {
3678 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3679 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3686 if (control
->value
< vino_saa7191_v4l2_controls
[i
].minimum
||
3687 control
->value
> vino_saa7191_v4l2_controls
[i
].maximum
) {
3692 err
= decoder_call(core
, s_ctrl
, control
);
3702 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3707 /* File operations */
3709 static int vino_open(struct file
*file
)
3711 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3713 dprintk("open(): channel = %c\n",
3714 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A' : 'B');
3716 mutex_lock(&vcs
->mutex
);
3719 dprintk("open(): driver busy\n");
3724 ret
= vino_acquire_input(vcs
);
3726 dprintk("open(): vino_acquire_input() failed\n");
3733 mutex_unlock(&vcs
->mutex
);
3735 dprintk("open(): %s!\n", ret
? "failed" : "complete");
3740 static int vino_close(struct file
*file
)
3742 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3743 dprintk("close():\n");
3745 mutex_lock(&vcs
->mutex
);
3750 vino_release_input(vcs
);
3752 /* stop DMA and free buffers */
3753 vino_capture_stop(vcs
);
3754 vino_queue_free(&vcs
->fb_queue
);
3757 mutex_unlock(&vcs
->mutex
);
3762 static void vino_vm_open(struct vm_area_struct
*vma
)
3764 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3767 dprintk("vino_vm_open(): count = %d\n", fb
->map_count
);
3770 static void vino_vm_close(struct vm_area_struct
*vma
)
3772 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3775 dprintk("vino_vm_close(): count = %d\n", fb
->map_count
);
3778 static struct vm_operations_struct vino_vm_ops
= {
3779 .open
= vino_vm_open
,
3780 .close
= vino_vm_close
,
3783 static int vino_mmap(struct file
*file
, struct vm_area_struct
*vma
)
3785 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3787 unsigned long start
= vma
->vm_start
;
3788 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
3789 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
3791 struct vino_framebuffer
*fb
= NULL
;
3792 unsigned int i
, length
;
3795 dprintk("mmap():\n");
3797 // TODO: reject mmap if already mapped
3799 if (mutex_lock_interruptible(&vcs
->mutex
))
3807 // TODO: check queue type
3809 if (!(vma
->vm_flags
& VM_WRITE
)) {
3810 dprintk("mmap(): app bug: PROT_WRITE please\n");
3814 if (!(vma
->vm_flags
& VM_SHARED
)) {
3815 dprintk("mmap(): app bug: MAP_SHARED please\n");
3820 /* find the correct buffer using offset */
3821 length
= vino_queue_get_length(&vcs
->fb_queue
);
3823 dprintk("mmap(): queue not initialized\n");
3828 for (i
= 0; i
< length
; i
++) {
3829 fb
= vino_queue_get_buffer(&vcs
->fb_queue
, i
);
3831 dprintk("mmap(): vino_queue_get_buffer() failed\n");
3836 if (fb
->offset
== offset
)
3840 dprintk("mmap(): invalid offset = %lu\n", offset
);
3845 dprintk("mmap(): buffer = %d\n", i
);
3847 if (size
> (fb
->desc_table
.page_count
* PAGE_SIZE
)) {
3848 dprintk("mmap(): failed: size = %lu > %lu\n",
3849 size
, fb
->desc_table
.page_count
* PAGE_SIZE
);
3854 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++) {
3856 virt_to_phys((void *)fb
->desc_table
.virtual[i
]) >>
3859 if (size
< PAGE_SIZE
)
3862 // protection was: PAGE_READONLY
3863 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
,
3864 vma
->vm_page_prot
)) {
3865 dprintk("mmap(): remap_pfn_range() failed\n");
3876 vma
->vm_flags
|= VM_DONTEXPAND
| VM_RESERVED
;
3877 vma
->vm_flags
&= ~VM_IO
;
3878 vma
->vm_private_data
= fb
;
3879 vma
->vm_file
= file
;
3880 vma
->vm_ops
= &vino_vm_ops
;
3883 mutex_unlock(&vcs
->mutex
);
3888 static unsigned int vino_poll(struct file
*file
, poll_table
*pt
)
3890 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3891 unsigned int outgoing
;
3892 unsigned int ret
= 0;
3895 // TODO: this has to be corrected for different read modes
3897 dprintk("poll():\n");
3899 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3900 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3907 poll_wait(file
, &vcs
->fb_queue
.frame_wait_queue
, pt
);
3909 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3910 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3916 dprintk("poll(): data %savailable\n",
3917 (outgoing
> 0) ? "" : "not ");
3920 ret
= POLLIN
| POLLRDNORM
;
3926 static long vino_ioctl(struct file
*file
,
3927 unsigned int cmd
, unsigned long arg
)
3929 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3932 if (mutex_lock_interruptible(&vcs
->mutex
))
3935 ret
= video_ioctl2(file
, cmd
, arg
);
3937 mutex_unlock(&vcs
->mutex
);
3942 /* Initialization and cleanup */
3945 static int vino_init_stage
;
3947 const struct v4l2_ioctl_ops vino_ioctl_ops
= {
3948 .vidioc_enum_fmt_vid_cap
= vino_enum_fmt_vid_cap
,
3949 .vidioc_g_fmt_vid_cap
= vino_g_fmt_vid_cap
,
3950 .vidioc_s_fmt_vid_cap
= vino_s_fmt_vid_cap
,
3951 .vidioc_try_fmt_vid_cap
= vino_try_fmt_vid_cap
,
3952 .vidioc_querycap
= vino_querycap
,
3953 .vidioc_enum_input
= vino_enum_input
,
3954 .vidioc_g_input
= vino_g_input
,
3955 .vidioc_s_input
= vino_s_input
,
3956 .vidioc_g_std
= vino_g_std
,
3957 .vidioc_s_std
= vino_s_std
,
3958 .vidioc_querystd
= vino_querystd
,
3959 .vidioc_cropcap
= vino_cropcap
,
3960 .vidioc_s_crop
= vino_s_crop
,
3961 .vidioc_g_crop
= vino_g_crop
,
3962 .vidioc_s_parm
= vino_s_parm
,
3963 .vidioc_g_parm
= vino_g_parm
,
3964 .vidioc_reqbufs
= vino_reqbufs
,
3965 .vidioc_querybuf
= vino_querybuf
,
3966 .vidioc_qbuf
= vino_qbuf
,
3967 .vidioc_dqbuf
= vino_dqbuf
,
3968 .vidioc_streamon
= vino_streamon
,
3969 .vidioc_streamoff
= vino_streamoff
,
3970 .vidioc_queryctrl
= vino_queryctrl
,
3971 .vidioc_g_ctrl
= vino_g_ctrl
,
3972 .vidioc_s_ctrl
= vino_s_ctrl
,
3975 static const struct v4l2_file_operations vino_fops
= {
3976 .owner
= THIS_MODULE
,
3978 .release
= vino_close
,
3979 .unlocked_ioctl
= vino_ioctl
,
3984 static struct video_device vdev_template
= {
3987 .ioctl_ops
= &vino_ioctl_ops
,
3988 .tvnorms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
3992 static void vino_module_cleanup(int stage
)
3996 video_unregister_device(vino_drvdata
->b
.vdev
);
3997 vino_drvdata
->b
.vdev
= NULL
;
3999 video_unregister_device(vino_drvdata
->a
.vdev
);
4000 vino_drvdata
->a
.vdev
= NULL
;
4004 free_irq(SGI_VINO_IRQ
, NULL
);
4006 if (vino_drvdata
->b
.vdev
) {
4007 video_device_release(vino_drvdata
->b
.vdev
);
4008 vino_drvdata
->b
.vdev
= NULL
;
4011 if (vino_drvdata
->a
.vdev
) {
4012 video_device_release(vino_drvdata
->a
.vdev
);
4013 vino_drvdata
->a
.vdev
= NULL
;
4016 /* all entries in dma_cpu dummy table have the same address */
4017 dma_unmap_single(NULL
,
4018 vino_drvdata
->dummy_desc_table
.dma_cpu
[0],
4019 PAGE_SIZE
, DMA_FROM_DEVICE
);
4020 dma_free_coherent(NULL
, VINO_DUMMY_DESC_COUNT
4021 * sizeof(dma_addr_t
),
4022 (void *)vino_drvdata
->
4023 dummy_desc_table
.dma_cpu
,
4024 vino_drvdata
->dummy_desc_table
.dma
);
4026 free_page(vino_drvdata
->dummy_page
);
4028 v4l2_device_unregister(&vino_drvdata
->v4l2_dev
);
4030 kfree(vino_drvdata
);
4036 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4041 static int vino_probe(void)
4043 unsigned long rev_id
;
4045 if (ip22_is_fullhouse()) {
4046 printk(KERN_ERR
"VINO doesn't exist in IP22 Fullhouse\n");
4050 if (!(sgimc
->systemid
& SGIMC_SYSID_EPRESENT
)) {
4051 printk(KERN_ERR
"VINO is not found (EISA BUS not present)\n");
4055 vino
= (struct sgi_vino
*)ioremap(VINO_BASE
, sizeof(struct sgi_vino
));
4057 printk(KERN_ERR
"VINO: ioremap() failed\n");
4062 if (get_dbe(rev_id
, &(vino
->rev_id
))) {
4063 printk(KERN_ERR
"Failed to read VINO revision register\n");
4064 vino_module_cleanup(vino_init_stage
);
4068 if (VINO_ID_VALUE(rev_id
) != VINO_CHIP_ID
) {
4069 printk(KERN_ERR
"Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4071 vino_module_cleanup(vino_init_stage
);
4075 printk(KERN_INFO
"VINO revision %ld found\n", VINO_REV_NUM(rev_id
));
4080 static int vino_init(void)
4082 dma_addr_t dma_dummy_address
;
4086 vino_drvdata
= kzalloc(sizeof(struct vino_settings
), GFP_KERNEL
);
4087 if (!vino_drvdata
) {
4088 vino_module_cleanup(vino_init_stage
);
4092 strlcpy(vino_drvdata
->v4l2_dev
.name
, "vino",
4093 sizeof(vino_drvdata
->v4l2_dev
.name
));
4094 err
= v4l2_device_register(NULL
, &vino_drvdata
->v4l2_dev
);
4099 /* create a dummy dma descriptor */
4100 vino_drvdata
->dummy_page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
4101 if (!vino_drvdata
->dummy_page
) {
4102 vino_module_cleanup(vino_init_stage
);
4107 // TODO: use page_count in dummy_desc_table
4109 vino_drvdata
->dummy_desc_table
.dma_cpu
=
4110 dma_alloc_coherent(NULL
,
4111 VINO_DUMMY_DESC_COUNT
* sizeof(dma_addr_t
),
4112 &vino_drvdata
->dummy_desc_table
.dma
,
4113 GFP_KERNEL
| GFP_DMA
);
4114 if (!vino_drvdata
->dummy_desc_table
.dma_cpu
) {
4115 vino_module_cleanup(vino_init_stage
);
4120 dma_dummy_address
= dma_map_single(NULL
,
4121 (void *)vino_drvdata
->dummy_page
,
4122 PAGE_SIZE
, DMA_FROM_DEVICE
);
4123 for (i
= 0; i
< VINO_DUMMY_DESC_COUNT
; i
++) {
4124 vino_drvdata
->dummy_desc_table
.dma_cpu
[i
] = dma_dummy_address
;
4127 /* initialize VINO */
4130 vino
->a
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4131 vino
->b
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4132 udelay(VINO_DESC_FETCH_DELAY
);
4134 vino
->intr_status
= 0;
4136 vino
->a
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4137 vino
->b
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4142 static int vino_init_channel_settings(struct vino_channel_settings
*vcs
,
4143 unsigned int channel
, const char *name
)
4145 vcs
->channel
= channel
;
4146 vcs
->input
= VINO_INPUT_NONE
;
4149 vcs
->data_format
= VINO_DATA_FMT_GREY
;
4150 vcs
->data_norm
= VINO_DATA_NORM_NTSC
;
4151 vcs
->decimation
= 1;
4152 vino_set_default_clipping(vcs
);
4153 vino_set_default_framerate(vcs
);
4157 mutex_init(&vcs
->mutex
);
4158 spin_lock_init(&vcs
->capture_lock
);
4160 mutex_init(&vcs
->fb_queue
.queue_mutex
);
4161 spin_lock_init(&vcs
->fb_queue
.queue_lock
);
4162 init_waitqueue_head(&vcs
->fb_queue
.frame_wait_queue
);
4164 vcs
->vdev
= video_device_alloc();
4166 vino_module_cleanup(vino_init_stage
);
4171 memcpy(vcs
->vdev
, &vdev_template
,
4172 sizeof(struct video_device
));
4173 strcpy(vcs
->vdev
->name
, name
);
4174 vcs
->vdev
->release
= video_device_release
;
4175 vcs
->vdev
->v4l2_dev
= &vino_drvdata
->v4l2_dev
;
4177 video_set_drvdata(vcs
->vdev
, vcs
);
4182 static int __init
vino_module_init(void)
4184 unsigned short addr
[] = { 0, I2C_CLIENT_END
};
4187 printk(KERN_INFO
"SGI VINO driver version %s\n",
4188 VINO_MODULE_VERSION
);
4198 /* initialize data structures */
4200 spin_lock_init(&vino_drvdata
->vino_lock
);
4201 spin_lock_init(&vino_drvdata
->input_lock
);
4203 ret
= vino_init_channel_settings(&vino_drvdata
->a
, VINO_CHANNEL_A
,
4208 ret
= vino_init_channel_settings(&vino_drvdata
->b
, VINO_CHANNEL_B
,
4213 /* initialize hardware and register V4L devices */
4215 ret
= request_irq(SGI_VINO_IRQ
, vino_interrupt
, 0,
4216 vino_driver_description
, NULL
);
4218 printk(KERN_ERR
"VINO: requesting IRQ %02d failed\n",
4220 vino_module_cleanup(vino_init_stage
);
4225 ret
= vino_i2c_add_bus();
4227 printk(KERN_ERR
"VINO I2C bus registration failed\n");
4228 vino_module_cleanup(vino_init_stage
);
4231 i2c_set_adapdata(&vino_i2c_adapter
, &vino_drvdata
->v4l2_dev
);
4234 ret
= video_register_device(vino_drvdata
->a
.vdev
,
4235 VFL_TYPE_GRABBER
, -1);
4237 printk(KERN_ERR
"VINO channel A Video4Linux-device "
4238 "registration failed\n");
4239 vino_module_cleanup(vino_init_stage
);
4244 ret
= video_register_device(vino_drvdata
->b
.vdev
,
4245 VFL_TYPE_GRABBER
, -1);
4247 printk(KERN_ERR
"VINO channel B Video4Linux-device "
4248 "registration failed\n");
4249 vino_module_cleanup(vino_init_stage
);
4255 vino_drvdata
->decoder
= v4l2_i2c_new_probed_subdev(&vino_i2c_adapter
,
4256 "saa7191", "saa7191", addr
);
4258 vino_drvdata
->camera
= v4l2_i2c_new_probed_subdev(&vino_i2c_adapter
,
4259 "indycam", "indycam", addr
);
4261 dprintk("init complete!\n");
4266 static void __exit
vino_module_exit(void)
4268 dprintk("exiting, stage = %d ...\n", vino_init_stage
);
4269 vino_module_cleanup(vino_init_stage
);
4270 dprintk("cleanup complete, exit!\n");
4273 module_init(vino_module_init
);
4274 module_exit(vino_module_exit
);