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>
12 * v4l2_device/v4l2_subdev conversion by:
13 * Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl>
15 * Note: this conversion is untested! Please contact the linux-media
16 * mailinglist if you can test this, together with the test results.
21 * - remove "mark pages reserved-hacks" from memory allocation code
22 * and implement fault()
23 * - check decimation, calculating and reporting image size when
25 * - implement read(), user mode buffers and overlay (?)
28 #include <linux/init.h>
29 #include <linux/module.h>
30 #include <linux/delay.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/errno.h>
34 #include <linux/interrupt.h>
35 #include <linux/kernel.h>
36 #include <linux/slab.h>
38 #include <linux/time.h>
39 #include <linux/version.h>
40 #include <linux/kmod.h>
42 #include <linux/i2c.h>
44 #include <linux/videodev2.h>
45 #include <media/v4l2-device.h>
46 #include <media/v4l2-ioctl.h>
47 #include <linux/mutex.h>
49 #include <asm/paccess.h>
51 #include <asm/sgi/ip22.h>
52 #include <asm/sgi/mc.h>
58 /* Uncomment the following line to get lots and lots of (mostly useless)
60 * Note that the debug output also slows down the driver significantly */
62 // #define VINO_DEBUG_INT
64 #define VINO_MODULE_VERSION "0.0.6"
65 #define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 6)
67 MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
68 MODULE_VERSION(VINO_MODULE_VERSION
);
69 MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
70 MODULE_LICENSE("GPL");
73 #define dprintk(x...) printk("VINO: " x);
78 #define VINO_NO_CHANNEL 0
79 #define VINO_CHANNEL_A 1
80 #define VINO_CHANNEL_B 2
82 #define VINO_PAL_WIDTH 768
83 #define VINO_PAL_HEIGHT 576
84 #define VINO_NTSC_WIDTH 640
85 #define VINO_NTSC_HEIGHT 480
87 #define VINO_MIN_WIDTH 32
88 #define VINO_MIN_HEIGHT 32
90 #define VINO_CLIPPING_START_ODD_D1 1
91 #define VINO_CLIPPING_START_ODD_PAL 15
92 #define VINO_CLIPPING_START_ODD_NTSC 12
94 #define VINO_CLIPPING_START_EVEN_D1 2
95 #define VINO_CLIPPING_START_EVEN_PAL 15
96 #define VINO_CLIPPING_START_EVEN_NTSC 12
98 #define VINO_INPUT_CHANNEL_COUNT 3
100 /* the number is the index for vino_inputs */
101 #define VINO_INPUT_NONE -1
102 #define VINO_INPUT_COMPOSITE 0
103 #define VINO_INPUT_SVIDEO 1
104 #define VINO_INPUT_D1 2
106 #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
108 #define VINO_FIFO_THRESHOLD_DEFAULT 16
110 #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
111 * VINO_PAL_HEIGHT * 4 \
112 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
114 #define VINO_FRAMEBUFFER_COUNT_MAX 8
116 #define VINO_FRAMEBUFFER_UNUSED 0
117 #define VINO_FRAMEBUFFER_IN_USE 1
118 #define VINO_FRAMEBUFFER_READY 2
120 #define VINO_QUEUE_ERROR -1
121 #define VINO_QUEUE_MAGIC 0x20050125
123 #define VINO_MEMORY_NONE 0
124 #define VINO_MEMORY_MMAP 1
125 #define VINO_MEMORY_USERPTR 2
127 #define VINO_DUMMY_DESC_COUNT 4
128 #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
130 #define VINO_MAX_FRAME_SKIP_COUNT 128
132 /* the number is the index for vino_data_formats */
133 #define VINO_DATA_FMT_NONE -1
134 #define VINO_DATA_FMT_GREY 0
135 #define VINO_DATA_FMT_RGB332 1
136 #define VINO_DATA_FMT_RGB32 2
137 #define VINO_DATA_FMT_YUV 3
139 #define VINO_DATA_FMT_COUNT 4
141 /* the number is the index for vino_data_norms */
142 #define VINO_DATA_NORM_NONE -1
143 #define VINO_DATA_NORM_NTSC 0
144 #define VINO_DATA_NORM_PAL 1
145 #define VINO_DATA_NORM_SECAM 2
146 #define VINO_DATA_NORM_D1 3
148 #define VINO_DATA_NORM_COUNT 4
150 /* I2C controller flags */
151 #define SGI_I2C_FORCE_IDLE (0 << 0)
152 #define SGI_I2C_NOT_IDLE (1 << 0)
153 #define SGI_I2C_WRITE (0 << 1)
154 #define SGI_I2C_READ (1 << 1)
155 #define SGI_I2C_RELEASE_BUS (0 << 2)
156 #define SGI_I2C_HOLD_BUS (1 << 2)
157 #define SGI_I2C_XFER_DONE (0 << 4)
158 #define SGI_I2C_XFER_BUSY (1 << 4)
159 #define SGI_I2C_ACK (0 << 5)
160 #define SGI_I2C_NACK (1 << 5)
161 #define SGI_I2C_BUS_OK (0 << 7)
162 #define SGI_I2C_BUS_ERR (1 << 7)
164 /* Internal data structure definitions */
171 struct vino_clipping
{
172 unsigned int left
, right
, top
, bottom
;
175 struct vino_data_format
{
176 /* the description */
178 /* bytes per pixel */
180 /* V4L2 fourcc code */
182 /* V4L2 colorspace (duh!) */
183 enum v4l2_colorspace colorspace
;
186 struct vino_data_norm
{
188 unsigned int width
, height
;
189 struct vino_clipping odd
;
190 struct vino_clipping even
;
193 unsigned int fps_min
, fps_max
;
197 struct vino_descriptor_table
{
198 /* the number of PAGE_SIZE sized pages in the buffer */
199 unsigned int page_count
;
200 /* virtual (kmalloc'd) pointers to the actual data
201 * (in PAGE_SIZE chunks, used with mmap streaming) */
202 unsigned long *virtual;
204 /* cpu address for the VINO descriptor table
205 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
206 unsigned long *dma_cpu
;
207 /* dma address for the VINO descriptor table
208 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
212 struct vino_framebuffer
{
213 /* identifier nubmer */
215 /* the length of the whole buffer */
217 /* the length of actual data in buffer */
218 unsigned int data_size
;
219 /* the data format */
220 unsigned int data_format
;
221 /* the state of buffer data */
223 /* is the buffer mapped in user space? */
224 unsigned int map_count
;
225 /* memory offset for mmap() */
228 unsigned int frame_counter
;
229 /* timestamp (written when image capture finishes) */
230 struct timeval timestamp
;
232 struct vino_descriptor_table desc_table
;
234 spinlock_t state_lock
;
237 struct vino_framebuffer_fifo
{
244 unsigned int data
[VINO_FRAMEBUFFER_COUNT_MAX
];
247 struct vino_framebuffer_queue
{
250 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
254 /* data field of in and out contain index numbers for buffer */
255 struct vino_framebuffer_fifo in
;
256 struct vino_framebuffer_fifo out
;
258 struct vino_framebuffer
*buffer
[VINO_FRAMEBUFFER_COUNT_MAX
];
260 spinlock_t queue_lock
;
261 struct mutex queue_mutex
;
262 wait_queue_head_t frame_wait_queue
;
265 struct vino_interrupt_data
{
266 struct timeval timestamp
;
267 unsigned int frame_counter
;
268 unsigned int skip_count
;
272 struct vino_channel_settings
{
273 unsigned int channel
;
276 unsigned int data_format
;
277 unsigned int data_norm
;
278 struct vino_clipping clipping
;
279 unsigned int decimation
;
280 unsigned int line_size
;
283 unsigned int framert_reg
;
285 unsigned int fifo_threshold
;
287 struct vino_framebuffer_queue fb_queue
;
289 /* number of the current field */
292 /* read in progress */
294 /* streaming is active */
296 /* the driver is currently processing the queue */
300 spinlock_t capture_lock
;
304 struct vino_interrupt_data int_data
;
307 struct video_device
*vdev
;
310 struct vino_settings
{
311 struct v4l2_device v4l2_dev
;
312 struct vino_channel_settings a
;
313 struct vino_channel_settings b
;
315 /* the channel which owns this client:
316 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
317 unsigned int decoder_owner
;
318 struct v4l2_subdev
*decoder
;
319 unsigned int camera_owner
;
320 struct v4l2_subdev
*camera
;
322 /* a lock for vino register access */
323 spinlock_t vino_lock
;
324 /* a lock for channel input changes */
325 spinlock_t input_lock
;
327 unsigned long dummy_page
;
328 struct vino_descriptor_table dummy_desc_table
;
331 /* Module parameters */
334 * Using vino_pixel_conversion the ABGR32-format pixels supplied
335 * by the VINO chip can be converted to more common formats
336 * like RGBA32 (or probably RGB24 in the future). This way we
337 * can give out data that can be specified correctly with
338 * the V4L2-definitions.
340 * The pixel format is specified as RGBA32 when no conversion
343 * Note that this only affects the 32-bit bit depth.
345 * Use non-zero value to enable conversion.
347 static int vino_pixel_conversion
;
349 module_param_named(pixelconv
, vino_pixel_conversion
, int, 0);
351 MODULE_PARM_DESC(pixelconv
,
352 "enable pixel conversion (non-zero value enables)");
354 /* Internal data structures */
356 static struct sgi_vino
*vino
;
358 static struct vino_settings
*vino_drvdata
;
360 #define camera_call(o, f, args...) \
361 v4l2_subdev_call(vino_drvdata->camera, o, f, ##args)
362 #define decoder_call(o, f, args...) \
363 v4l2_subdev_call(vino_drvdata->decoder, o, f, ##args)
365 static const char *vino_driver_name
= "vino";
366 static const char *vino_driver_description
= "SGI VINO";
367 static const char *vino_bus_name
= "GIO64 bus";
368 static const char *vino_vdev_name_a
= "SGI VINO Channel A";
369 static const char *vino_vdev_name_b
= "SGI VINO Channel B";
371 static void vino_capture_tasklet(unsigned long channel
);
373 DECLARE_TASKLET(vino_tasklet_a
, vino_capture_tasklet
, VINO_CHANNEL_A
);
374 DECLARE_TASKLET(vino_tasklet_b
, vino_capture_tasklet
, VINO_CHANNEL_B
);
376 static const struct vino_input vino_inputs
[] = {
379 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
383 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
386 .name
= "D1/IndyCam",
387 .std
= V4L2_STD_NTSC
,
391 static const struct vino_data_format vino_data_formats
[] = {
393 .description
= "8-bit greyscale",
395 .pixelformat
= V4L2_PIX_FMT_GREY
,
396 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
398 .description
= "8-bit dithered RGB 3-3-2",
400 .pixelformat
= V4L2_PIX_FMT_RGB332
,
401 .colorspace
= V4L2_COLORSPACE_SRGB
,
403 .description
= "32-bit RGB",
405 .pixelformat
= V4L2_PIX_FMT_RGB32
,
406 .colorspace
= V4L2_COLORSPACE_SRGB
,
408 .description
= "YUV 4:2:2",
410 .pixelformat
= V4L2_PIX_FMT_YUYV
,
411 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
415 static const struct vino_data_norm vino_data_norms
[] = {
417 .description
= "NTSC",
418 .std
= V4L2_STD_NTSC
,
422 .width
= VINO_NTSC_WIDTH
,
423 .height
= VINO_NTSC_HEIGHT
,
425 .top
= VINO_CLIPPING_START_ODD_NTSC
,
427 .bottom
= VINO_CLIPPING_START_ODD_NTSC
428 + VINO_NTSC_HEIGHT
/ 2 - 1,
429 .right
= VINO_NTSC_WIDTH
,
432 .top
= VINO_CLIPPING_START_EVEN_NTSC
,
434 .bottom
= VINO_CLIPPING_START_EVEN_NTSC
435 + VINO_NTSC_HEIGHT
/ 2 - 1,
436 .right
= VINO_NTSC_WIDTH
,
439 .description
= "PAL",
444 .width
= VINO_PAL_WIDTH
,
445 .height
= VINO_PAL_HEIGHT
,
447 .top
= VINO_CLIPPING_START_ODD_PAL
,
449 .bottom
= VINO_CLIPPING_START_ODD_PAL
450 + VINO_PAL_HEIGHT
/ 2 - 1,
451 .right
= VINO_PAL_WIDTH
,
454 .top
= VINO_CLIPPING_START_EVEN_PAL
,
456 .bottom
= VINO_CLIPPING_START_EVEN_PAL
457 + VINO_PAL_HEIGHT
/ 2 - 1,
458 .right
= VINO_PAL_WIDTH
,
461 .description
= "SECAM",
462 .std
= V4L2_STD_SECAM
,
466 .width
= VINO_PAL_WIDTH
,
467 .height
= VINO_PAL_HEIGHT
,
469 .top
= VINO_CLIPPING_START_ODD_PAL
,
471 .bottom
= VINO_CLIPPING_START_ODD_PAL
472 + VINO_PAL_HEIGHT
/ 2 - 1,
473 .right
= VINO_PAL_WIDTH
,
476 .top
= VINO_CLIPPING_START_EVEN_PAL
,
478 .bottom
= VINO_CLIPPING_START_EVEN_PAL
479 + VINO_PAL_HEIGHT
/ 2 - 1,
480 .right
= VINO_PAL_WIDTH
,
483 .description
= "NTSC/D1",
484 .std
= V4L2_STD_NTSC
,
488 .width
= VINO_NTSC_WIDTH
,
489 .height
= VINO_NTSC_HEIGHT
,
491 .top
= VINO_CLIPPING_START_ODD_D1
,
493 .bottom
= VINO_CLIPPING_START_ODD_D1
494 + VINO_NTSC_HEIGHT
/ 2 - 1,
495 .right
= VINO_NTSC_WIDTH
,
498 .top
= VINO_CLIPPING_START_EVEN_D1
,
500 .bottom
= VINO_CLIPPING_START_EVEN_D1
501 + VINO_NTSC_HEIGHT
/ 2 - 1,
502 .right
= VINO_NTSC_WIDTH
,
507 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
509 struct v4l2_queryctrl vino_indycam_v4l2_controls
[] = {
511 .id
= V4L2_CID_AUTOGAIN
,
512 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
513 .name
= "Automatic Gain Control",
517 .default_value
= INDYCAM_AGC_DEFAULT
,
519 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
520 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
521 .name
= "Automatic White Balance",
525 .default_value
= INDYCAM_AWB_DEFAULT
,
528 .type
= V4L2_CTRL_TYPE_INTEGER
,
530 .minimum
= INDYCAM_GAIN_MIN
,
531 .maximum
= INDYCAM_GAIN_MAX
,
533 .default_value
= INDYCAM_GAIN_DEFAULT
,
535 .id
= INDYCAM_CONTROL_RED_SATURATION
,
536 .type
= V4L2_CTRL_TYPE_INTEGER
,
537 .name
= "Red Saturation",
538 .minimum
= INDYCAM_RED_SATURATION_MIN
,
539 .maximum
= INDYCAM_RED_SATURATION_MAX
,
541 .default_value
= INDYCAM_RED_SATURATION_DEFAULT
,
543 .id
= INDYCAM_CONTROL_BLUE_SATURATION
,
544 .type
= V4L2_CTRL_TYPE_INTEGER
,
545 .name
= "Blue Saturation",
546 .minimum
= INDYCAM_BLUE_SATURATION_MIN
,
547 .maximum
= INDYCAM_BLUE_SATURATION_MAX
,
549 .default_value
= INDYCAM_BLUE_SATURATION_DEFAULT
,
551 .id
= V4L2_CID_RED_BALANCE
,
552 .type
= V4L2_CTRL_TYPE_INTEGER
,
553 .name
= "Red Balance",
554 .minimum
= INDYCAM_RED_BALANCE_MIN
,
555 .maximum
= INDYCAM_RED_BALANCE_MAX
,
557 .default_value
= INDYCAM_RED_BALANCE_DEFAULT
,
559 .id
= V4L2_CID_BLUE_BALANCE
,
560 .type
= V4L2_CTRL_TYPE_INTEGER
,
561 .name
= "Blue Balance",
562 .minimum
= INDYCAM_BLUE_BALANCE_MIN
,
563 .maximum
= INDYCAM_BLUE_BALANCE_MAX
,
565 .default_value
= INDYCAM_BLUE_BALANCE_DEFAULT
,
567 .id
= V4L2_CID_EXPOSURE
,
568 .type
= V4L2_CTRL_TYPE_INTEGER
,
569 .name
= "Shutter Control",
570 .minimum
= INDYCAM_SHUTTER_MIN
,
571 .maximum
= INDYCAM_SHUTTER_MAX
,
573 .default_value
= INDYCAM_SHUTTER_DEFAULT
,
575 .id
= V4L2_CID_GAMMA
,
576 .type
= V4L2_CTRL_TYPE_INTEGER
,
578 .minimum
= INDYCAM_GAMMA_MIN
,
579 .maximum
= INDYCAM_GAMMA_MAX
,
581 .default_value
= INDYCAM_GAMMA_DEFAULT
,
585 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
587 struct v4l2_queryctrl vino_saa7191_v4l2_controls
[] = {
590 .type
= V4L2_CTRL_TYPE_INTEGER
,
592 .minimum
= SAA7191_HUE_MIN
,
593 .maximum
= SAA7191_HUE_MAX
,
595 .default_value
= SAA7191_HUE_DEFAULT
,
597 .id
= SAA7191_CONTROL_BANDPASS
,
598 .type
= V4L2_CTRL_TYPE_INTEGER
,
599 .name
= "Luminance Bandpass",
600 .minimum
= SAA7191_BANDPASS_MIN
,
601 .maximum
= SAA7191_BANDPASS_MAX
,
603 .default_value
= SAA7191_BANDPASS_DEFAULT
,
605 .id
= SAA7191_CONTROL_BANDPASS_WEIGHT
,
606 .type
= V4L2_CTRL_TYPE_INTEGER
,
607 .name
= "Luminance Bandpass Weight",
608 .minimum
= SAA7191_BANDPASS_WEIGHT_MIN
,
609 .maximum
= SAA7191_BANDPASS_WEIGHT_MAX
,
611 .default_value
= SAA7191_BANDPASS_WEIGHT_DEFAULT
,
613 .id
= SAA7191_CONTROL_CORING
,
614 .type
= V4L2_CTRL_TYPE_INTEGER
,
615 .name
= "HF Luminance Coring",
616 .minimum
= SAA7191_CORING_MIN
,
617 .maximum
= SAA7191_CORING_MAX
,
619 .default_value
= SAA7191_CORING_DEFAULT
,
621 .id
= SAA7191_CONTROL_FORCE_COLOUR
,
622 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
623 .name
= "Force Colour",
624 .minimum
= SAA7191_FORCE_COLOUR_MIN
,
625 .maximum
= SAA7191_FORCE_COLOUR_MAX
,
627 .default_value
= SAA7191_FORCE_COLOUR_DEFAULT
,
629 .id
= SAA7191_CONTROL_CHROMA_GAIN
,
630 .type
= V4L2_CTRL_TYPE_INTEGER
,
631 .name
= "Chrominance Gain Control",
632 .minimum
= SAA7191_CHROMA_GAIN_MIN
,
633 .maximum
= SAA7191_CHROMA_GAIN_MAX
,
635 .default_value
= SAA7191_CHROMA_GAIN_DEFAULT
,
637 .id
= SAA7191_CONTROL_VTRC
,
638 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
639 .name
= "VTR Time Constant",
640 .minimum
= SAA7191_VTRC_MIN
,
641 .maximum
= SAA7191_VTRC_MAX
,
643 .default_value
= SAA7191_VTRC_DEFAULT
,
645 .id
= SAA7191_CONTROL_LUMA_DELAY
,
646 .type
= V4L2_CTRL_TYPE_INTEGER
,
647 .name
= "Luminance Delay Compensation",
648 .minimum
= SAA7191_LUMA_DELAY_MIN
,
649 .maximum
= SAA7191_LUMA_DELAY_MAX
,
651 .default_value
= SAA7191_LUMA_DELAY_DEFAULT
,
653 .id
= SAA7191_CONTROL_VNR
,
654 .type
= V4L2_CTRL_TYPE_INTEGER
,
655 .name
= "Vertical Noise Reduction",
656 .minimum
= SAA7191_VNR_MIN
,
657 .maximum
= SAA7191_VNR_MAX
,
659 .default_value
= SAA7191_VNR_DEFAULT
,
663 /* VINO framebuffer/DMA descriptor management */
665 static void vino_free_buffer_with_count(struct vino_framebuffer
*fb
,
670 dprintk("vino_free_buffer_with_count(): count = %d\n", count
);
672 for (i
= 0; i
< count
; i
++) {
673 ClearPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
674 dma_unmap_single(NULL
,
675 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
676 PAGE_SIZE
, DMA_FROM_DEVICE
);
677 free_page(fb
->desc_table
.virtual[i
]);
680 dma_free_coherent(NULL
,
681 VINO_PAGE_RATIO
* (fb
->desc_table
.page_count
+ 4) *
682 sizeof(dma_addr_t
), (void *)fb
->desc_table
.dma_cpu
,
684 kfree(fb
->desc_table
.virtual);
686 memset(fb
, 0, sizeof(struct vino_framebuffer
));
689 static void vino_free_buffer(struct vino_framebuffer
*fb
)
691 vino_free_buffer_with_count(fb
, fb
->desc_table
.page_count
);
694 static int vino_allocate_buffer(struct vino_framebuffer
*fb
,
697 unsigned int count
, i
, j
;
700 dprintk("vino_allocate_buffer():\n");
705 memset(fb
, 0, sizeof(struct vino_framebuffer
));
707 count
= ((size
/ PAGE_SIZE
) + 4) & ~3;
709 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
712 /* allocate memory for table with virtual (page) addresses */
713 fb
->desc_table
.virtual = (unsigned long *)
714 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
715 if (!fb
->desc_table
.virtual)
718 /* allocate memory for table with dma addresses
719 * (has space for four extra descriptors) */
720 fb
->desc_table
.dma_cpu
=
721 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
722 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
723 GFP_KERNEL
| GFP_DMA
);
724 if (!fb
->desc_table
.dma_cpu
) {
726 goto out_free_virtual
;
729 /* allocate pages for the buffer and acquire the according
731 for (i
= 0; i
< count
; i
++) {
732 dma_addr_t dma_data_addr
;
734 fb
->desc_table
.virtual[i
] =
735 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
736 if (!fb
->desc_table
.virtual[i
]) {
743 (void *)fb
->desc_table
.virtual[i
],
744 PAGE_SIZE
, DMA_FROM_DEVICE
);
746 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
747 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
748 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
751 SetPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
754 /* page_count needs to be set anyway, because the descriptor table has
755 * been allocated according to this number */
756 fb
->desc_table
.page_count
= count
;
759 /* the descriptor with index i doesn't contain
760 * a valid address yet */
761 vino_free_buffer_with_count(fb
, i
);
766 fb
->size
= count
* PAGE_SIZE
;
767 fb
->data_format
= VINO_DATA_FMT_NONE
;
769 /* set the dma stop-bit for the last (count+1)th descriptor */
770 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
774 kfree(fb
->desc_table
.virtual);
779 static void vino_sync_buffer(struct vino_framebuffer
*fb
)
783 dprintk("vino_sync_buffer():\n");
785 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++)
786 dma_sync_single_for_cpu(NULL
,
787 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
788 PAGE_SIZE
, DMA_FROM_DEVICE
);
791 /* Framebuffer fifo functions (need to be locked externally) */
793 static inline void vino_fifo_init(struct vino_framebuffer_fifo
*f
,
801 if (length
> VINO_FRAMEBUFFER_COUNT_MAX
)
802 length
= VINO_FRAMEBUFFER_COUNT_MAX
;
807 /* returns true/false */
808 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo
*f
,
813 for (i
= f
->head
; i
== (f
->tail
- 1); i
= (i
+ 1) % f
->length
) {
814 if (f
->data
[i
] == id
)
822 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo
*f
)
827 static int vino_fifo_enqueue(struct vino_framebuffer_fifo
*f
, unsigned int id
)
829 if (id
>= f
->length
) {
830 return VINO_QUEUE_ERROR
;
833 if (vino_fifo_has_id(f
, id
)) {
834 return VINO_QUEUE_ERROR
;
837 if (f
->used
< f
->length
) {
838 f
->data
[f
->tail
] = id
;
839 f
->tail
= (f
->tail
+ 1) % f
->length
;
842 return VINO_QUEUE_ERROR
;
848 static int vino_fifo_peek(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
851 *id
= f
->data
[f
->head
];
853 return VINO_QUEUE_ERROR
;
859 static int vino_fifo_dequeue(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
862 *id
= f
->data
[f
->head
];
863 f
->head
= (f
->head
+ 1) % f
->length
;
866 return VINO_QUEUE_ERROR
;
872 /* Framebuffer queue functions */
874 /* execute with queue_lock locked */
875 static void vino_queue_free_with_count(struct vino_framebuffer_queue
*q
,
881 memset(&q
->in
, 0, sizeof(struct vino_framebuffer_fifo
));
882 memset(&q
->out
, 0, sizeof(struct vino_framebuffer_fifo
));
883 for (i
= 0; i
< length
; i
++) {
884 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
886 vino_free_buffer(q
->buffer
[i
]);
890 q
->type
= VINO_MEMORY_NONE
;
894 static void vino_queue_free(struct vino_framebuffer_queue
*q
)
896 dprintk("vino_queue_free():\n");
898 if (q
->magic
!= VINO_QUEUE_MAGIC
)
900 if (q
->type
!= VINO_MEMORY_MMAP
)
903 mutex_lock(&q
->queue_mutex
);
905 vino_queue_free_with_count(q
, q
->length
);
907 mutex_unlock(&q
->queue_mutex
);
910 static int vino_queue_init(struct vino_framebuffer_queue
*q
,
911 unsigned int *length
)
916 dprintk("vino_queue_init(): length = %d\n", *length
);
918 if (q
->magic
== VINO_QUEUE_MAGIC
) {
919 dprintk("vino_queue_init(): queue already initialized!\n");
923 if (q
->type
!= VINO_MEMORY_NONE
) {
924 dprintk("vino_queue_init(): queue already initialized!\n");
931 mutex_lock(&q
->queue_mutex
);
933 if (*length
> VINO_FRAMEBUFFER_COUNT_MAX
)
934 *length
= VINO_FRAMEBUFFER_COUNT_MAX
;
938 for (i
= 0; i
< *length
; i
++) {
939 dprintk("vino_queue_init(): allocating buffer %d\n", i
);
940 q
->buffer
[i
] = kmalloc(sizeof(struct vino_framebuffer
),
943 dprintk("vino_queue_init(): kmalloc() failed\n");
948 ret
= vino_allocate_buffer(q
->buffer
[i
],
949 VINO_FRAMEBUFFER_SIZE
);
952 dprintk("vino_queue_init(): "
953 "vino_allocate_buffer() failed\n");
957 q
->buffer
[i
]->id
= i
;
959 q
->buffer
[i
]->offset
= q
->buffer
[i
- 1]->offset
+
960 q
->buffer
[i
- 1]->size
;
962 q
->buffer
[i
]->offset
= 0;
965 spin_lock_init(&q
->buffer
[i
]->state_lock
);
967 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
968 "size = %d\n", i
, q
->buffer
[i
]->offset
,
973 vino_queue_free_with_count(q
, i
);
977 vino_fifo_init(&q
->in
, q
->length
);
978 vino_fifo_init(&q
->out
, q
->length
);
979 q
->type
= VINO_MEMORY_MMAP
;
980 q
->magic
= VINO_QUEUE_MAGIC
;
983 mutex_unlock(&q
->queue_mutex
);
988 static struct vino_framebuffer
*vino_queue_add(struct
989 vino_framebuffer_queue
*q
,
992 struct vino_framebuffer
*ret
= NULL
;
996 dprintk("vino_queue_add(): id = %d\n", id
);
998 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1002 spin_lock_irqsave(&q
->queue_lock
, flags
);
1007 if (id
>= q
->length
)
1010 /* not needed?: if (vino_fifo_full(&q->out)) {
1013 /* check that outgoing queue isn't already full
1014 * (or that it won't become full) */
1015 total
= vino_fifo_get_used(&q
->in
) +
1016 vino_fifo_get_used(&q
->out
);
1017 if (total
>= q
->length
)
1020 if (vino_fifo_enqueue(&q
->in
, id
))
1023 ret
= q
->buffer
[id
];
1026 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1031 static struct vino_framebuffer
*vino_queue_transfer(struct
1032 vino_framebuffer_queue
*q
)
1034 struct vino_framebuffer
*ret
= NULL
;
1035 struct vino_framebuffer
*fb
;
1037 unsigned long flags
;
1039 dprintk("vino_queue_transfer():\n");
1041 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1045 spin_lock_irqsave(&q
->queue_lock
, flags
);
1050 // now this actually removes an entry from the incoming queue
1051 if (vino_fifo_dequeue(&q
->in
, &id
)) {
1055 dprintk("vino_queue_transfer(): id = %d\n", id
);
1058 // we have already checked that the outgoing queue is not full, but...
1059 if (vino_fifo_enqueue(&q
->out
, id
)) {
1060 printk(KERN_ERR
"vino_queue_transfer(): "
1061 "outgoing queue is full, this shouldn't happen!\n");
1067 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1072 /* returns true/false */
1073 static int vino_queue_incoming_contains(struct vino_framebuffer_queue
*q
,
1077 unsigned long flags
;
1079 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1083 spin_lock_irqsave(&q
->queue_lock
, flags
);
1088 ret
= vino_fifo_has_id(&q
->in
, id
);
1091 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1096 /* returns true/false */
1097 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue
*q
,
1101 unsigned long flags
;
1103 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1107 spin_lock_irqsave(&q
->queue_lock
, flags
);
1112 ret
= vino_fifo_has_id(&q
->out
, id
);
1115 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1120 static int vino_queue_get_incoming(struct vino_framebuffer_queue
*q
,
1124 unsigned long flags
;
1126 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1127 return VINO_QUEUE_ERROR
;
1130 spin_lock_irqsave(&q
->queue_lock
, flags
);
1132 if (q
->length
== 0) {
1133 ret
= VINO_QUEUE_ERROR
;
1137 *used
= vino_fifo_get_used(&q
->in
);
1140 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1145 static int vino_queue_get_outgoing(struct vino_framebuffer_queue
*q
,
1149 unsigned long flags
;
1151 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1152 return VINO_QUEUE_ERROR
;
1155 spin_lock_irqsave(&q
->queue_lock
, flags
);
1157 if (q
->length
== 0) {
1158 ret
= VINO_QUEUE_ERROR
;
1162 *used
= vino_fifo_get_used(&q
->out
);
1165 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1171 static struct vino_framebuffer
*vino_queue_peek(struct
1172 vino_framebuffer_queue
*q
,
1175 struct vino_framebuffer
*ret
= NULL
;
1176 unsigned long flags
;
1178 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1182 spin_lock_irqsave(&q
->queue_lock
, flags
);
1187 if (vino_fifo_peek(&q
->in
, id
)) {
1191 ret
= q
->buffer
[*id
];
1193 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1198 static struct vino_framebuffer
*vino_queue_remove(struct
1199 vino_framebuffer_queue
*q
,
1202 struct vino_framebuffer
*ret
= NULL
;
1203 unsigned long flags
;
1204 dprintk("vino_queue_remove():\n");
1206 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1210 spin_lock_irqsave(&q
->queue_lock
, flags
);
1215 if (vino_fifo_dequeue(&q
->out
, id
)) {
1219 dprintk("vino_queue_remove(): id = %d\n", *id
);
1220 ret
= q
->buffer
[*id
];
1222 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1228 vino_framebuffer
*vino_queue_get_buffer(struct vino_framebuffer_queue
*q
,
1231 struct vino_framebuffer
*ret
= NULL
;
1232 unsigned long flags
;
1234 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1238 spin_lock_irqsave(&q
->queue_lock
, flags
);
1243 if (id
>= q
->length
)
1246 ret
= q
->buffer
[id
];
1248 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1253 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue
*q
)
1255 unsigned int length
= 0;
1256 unsigned long flags
;
1258 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1262 spin_lock_irqsave(&q
->queue_lock
, flags
);
1264 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1269 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue
*q
)
1273 unsigned long flags
;
1275 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1279 spin_lock_irqsave(&q
->queue_lock
, flags
);
1280 for (i
= 0; i
< q
->length
; i
++) {
1281 if (q
->buffer
[i
]->map_count
> 0) {
1286 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1291 /* VINO functions */
1293 /* execute with input_lock locked */
1294 static void vino_update_line_size(struct vino_channel_settings
*vcs
)
1296 unsigned int w
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1297 unsigned int d
= vcs
->decimation
;
1298 unsigned int bpp
= vino_data_formats
[vcs
->data_format
].bpp
;
1301 dprintk("update_line_size(): before: w = %d, d = %d, "
1302 "line_size = %d\n", w
, d
, vcs
->line_size
);
1304 /* line size must be multiple of 8 bytes */
1305 lsize
= (bpp
* (w
/ d
)) & ~7;
1306 w
= (lsize
/ bpp
) * d
;
1308 vcs
->clipping
.right
= vcs
->clipping
.left
+ w
;
1309 vcs
->line_size
= lsize
;
1311 dprintk("update_line_size(): after: w = %d, d = %d, "
1312 "line_size = %d\n", w
, d
, vcs
->line_size
);
1315 /* execute with input_lock locked */
1316 static void vino_set_clipping(struct vino_channel_settings
*vcs
,
1317 unsigned int x
, unsigned int y
,
1318 unsigned int w
, unsigned int h
)
1320 unsigned int maxwidth
, maxheight
;
1323 maxwidth
= vino_data_norms
[vcs
->data_norm
].width
;
1324 maxheight
= vino_data_norms
[vcs
->data_norm
].height
;
1325 d
= vcs
->decimation
;
1327 y
&= ~1; /* odd/even fields */
1332 if (y
> maxheight
) {
1336 if (((w
/ d
) < VINO_MIN_WIDTH
)
1337 || ((h
/ d
) < VINO_MIN_HEIGHT
)) {
1338 w
= VINO_MIN_WIDTH
* d
;
1339 h
= VINO_MIN_HEIGHT
* d
;
1342 if ((x
+ w
) > maxwidth
) {
1344 if ((w
/ d
) < VINO_MIN_WIDTH
)
1345 x
= maxwidth
- VINO_MIN_WIDTH
* d
;
1347 if ((y
+ h
) > maxheight
) {
1349 if ((h
/ d
) < VINO_MIN_HEIGHT
)
1350 y
= maxheight
- VINO_MIN_HEIGHT
* d
;
1353 vcs
->clipping
.left
= x
;
1354 vcs
->clipping
.top
= y
;
1355 vcs
->clipping
.right
= x
+ w
;
1356 vcs
->clipping
.bottom
= y
+ h
;
1358 vino_update_line_size(vcs
);
1360 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1361 vcs
->clipping
.left
, vcs
->clipping
.top
, vcs
->clipping
.right
,
1362 vcs
->clipping
.bottom
, vcs
->decimation
, vcs
->line_size
);
1365 /* execute with input_lock locked */
1366 static inline void vino_set_default_clipping(struct vino_channel_settings
*vcs
)
1368 vino_set_clipping(vcs
, 0, 0, vino_data_norms
[vcs
->data_norm
].width
,
1369 vino_data_norms
[vcs
->data_norm
].height
);
1372 /* execute with input_lock locked */
1373 static void vino_set_scaling(struct vino_channel_settings
*vcs
,
1374 unsigned int w
, unsigned int h
)
1376 unsigned int x
, y
, curw
, curh
, d
;
1378 x
= vcs
->clipping
.left
;
1379 y
= vcs
->clipping
.top
;
1380 curw
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1381 curh
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
1383 d
= max(curw
/ w
, curh
/ h
);
1385 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1386 w
, h
, curw
, curh
, d
);
1394 vcs
->decimation
= d
;
1395 vino_set_clipping(vcs
, x
, y
, w
* d
, h
* d
);
1397 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs
->clipping
.left
,
1398 vcs
->clipping
.top
, vcs
->clipping
.right
, vcs
->clipping
.bottom
,
1399 vcs
->decimation
, vcs
->line_size
);
1402 /* execute with input_lock locked */
1403 static inline void vino_set_default_scaling(struct vino_channel_settings
*vcs
)
1405 vino_set_scaling(vcs
, vcs
->clipping
.right
- vcs
->clipping
.left
,
1406 vcs
->clipping
.bottom
- vcs
->clipping
.top
);
1409 /* execute with input_lock locked */
1410 static void vino_set_framerate(struct vino_channel_settings
*vcs
,
1415 switch (vcs
->data_norm
) {
1416 case VINO_DATA_NORM_NTSC
:
1417 case VINO_DATA_NORM_D1
:
1418 fps
= (unsigned int)(fps
/ 6) * 6;
1420 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1421 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1422 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1423 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1442 mask
= VINO_FRAMERT_FULL
;
1444 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
);
1446 case VINO_DATA_NORM_PAL
:
1447 case VINO_DATA_NORM_SECAM
:
1448 fps
= (unsigned int)(fps
/ 5) * 5;
1450 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1451 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1452 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1453 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1472 mask
= VINO_FRAMERT_FULL
;
1474 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
) | VINO_FRAMERT_PAL
;
1481 /* execute with input_lock locked */
1482 static inline void vino_set_default_framerate(struct
1483 vino_channel_settings
*vcs
)
1485 vino_set_framerate(vcs
, vino_data_norms
[vcs
->data_norm
].fps_max
);
1488 /* VINO I2C bus functions */
1490 struct i2c_algo_sgi_data
{
1491 void *data
; /* private data for lowlevel routines */
1492 unsigned (*getctrl
)(void *data
);
1493 void (*setctrl
)(void *data
, unsigned val
);
1494 unsigned (*rdata
)(void *data
);
1495 void (*wdata
)(void *data
, unsigned val
);
1501 static int wait_xfer_done(struct i2c_algo_sgi_data
*adap
)
1505 for (i
= 0; i
< adap
->xfer_timeout
; i
++) {
1506 if ((adap
->getctrl(adap
->data
) & SGI_I2C_XFER_BUSY
) == 0)
1514 static int wait_ack(struct i2c_algo_sgi_data
*adap
)
1518 if (wait_xfer_done(adap
))
1520 for (i
= 0; i
< adap
->ack_timeout
; i
++) {
1521 if ((adap
->getctrl(adap
->data
) & SGI_I2C_NACK
) == 0)
1529 static int force_idle(struct i2c_algo_sgi_data
*adap
)
1533 adap
->setctrl(adap
->data
, SGI_I2C_FORCE_IDLE
);
1534 for (i
= 0; i
< adap
->xfer_timeout
; i
++) {
1535 if ((adap
->getctrl(adap
->data
) & SGI_I2C_NOT_IDLE
) == 0)
1541 if (adap
->getctrl(adap
->data
) & SGI_I2C_BUS_ERR
)
1546 static int do_address(struct i2c_algo_sgi_data
*adap
, unsigned int addr
,
1550 adap
->setctrl(adap
->data
, SGI_I2C_NOT_IDLE
);
1551 /* Check if bus is idle, eventually force it to do so */
1552 if (adap
->getctrl(adap
->data
) & SGI_I2C_NOT_IDLE
)
1553 if (force_idle(adap
))
1555 /* Write out the i2c chip address and specify operation */
1556 adap
->setctrl(adap
->data
,
1557 SGI_I2C_HOLD_BUS
| SGI_I2C_WRITE
| SGI_I2C_NOT_IDLE
);
1560 adap
->wdata(adap
->data
, addr
);
1566 static int i2c_read(struct i2c_algo_sgi_data
*adap
, unsigned char *buf
,
1571 adap
->setctrl(adap
->data
,
1572 SGI_I2C_HOLD_BUS
| SGI_I2C_READ
| SGI_I2C_NOT_IDLE
);
1573 for (i
= 0; i
< len
; i
++) {
1574 if (wait_xfer_done(adap
))
1576 buf
[i
] = adap
->rdata(adap
->data
);
1578 adap
->setctrl(adap
->data
, SGI_I2C_RELEASE_BUS
| SGI_I2C_FORCE_IDLE
);
1584 static int i2c_write(struct i2c_algo_sgi_data
*adap
, unsigned char *buf
,
1589 /* We are already in write state */
1590 for (i
= 0; i
< len
; i
++) {
1591 adap
->wdata(adap
->data
, buf
[i
]);
1598 static int sgi_xfer(struct i2c_adapter
*i2c_adap
, struct i2c_msg
*msgs
,
1601 struct i2c_algo_sgi_data
*adap
= i2c_adap
->algo_data
;
1605 for (i
= 0; !err
&& i
< num
; i
++) {
1607 err
= do_address(adap
, p
->addr
, p
->flags
& I2C_M_RD
);
1610 if (p
->flags
& I2C_M_RD
)
1611 err
= i2c_read(adap
, p
->buf
, p
->len
);
1613 err
= i2c_write(adap
, p
->buf
, p
->len
);
1616 return (err
< 0) ? err
: i
;
1619 static u32
sgi_func(struct i2c_adapter
*adap
)
1621 return I2C_FUNC_SMBUS_EMUL
;
1624 static const struct i2c_algorithm sgi_algo
= {
1625 .master_xfer
= sgi_xfer
,
1626 .functionality
= sgi_func
,
1629 static unsigned i2c_vino_getctrl(void *data
)
1631 return vino
->i2c_control
;
1634 static void i2c_vino_setctrl(void *data
, unsigned val
)
1636 vino
->i2c_control
= val
;
1639 static unsigned i2c_vino_rdata(void *data
)
1641 return vino
->i2c_data
;
1644 static void i2c_vino_wdata(void *data
, unsigned val
)
1646 vino
->i2c_data
= val
;
1649 static struct i2c_algo_sgi_data i2c_sgi_vino_data
= {
1650 .getctrl
= &i2c_vino_getctrl
,
1651 .setctrl
= &i2c_vino_setctrl
,
1652 .rdata
= &i2c_vino_rdata
,
1653 .wdata
= &i2c_vino_wdata
,
1654 .xfer_timeout
= 200,
1655 .ack_timeout
= 1000,
1658 static struct i2c_adapter vino_i2c_adapter
= {
1659 .name
= "VINO I2C bus",
1661 .algo_data
= &i2c_sgi_vino_data
,
1662 .owner
= THIS_MODULE
,
1666 * Prepare VINO for DMA transfer...
1667 * (execute only with vino_lock and input_lock locked)
1669 static int vino_dma_setup(struct vino_channel_settings
*vcs
,
1670 struct vino_framebuffer
*fb
)
1673 struct sgi_vino_channel
*ch
;
1674 const struct vino_data_norm
*norm
;
1676 dprintk("vino_dma_setup():\n");
1679 fb
->frame_counter
= 0;
1681 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1682 norm
= &vino_data_norms
[vcs
->data_norm
];
1687 /* VINO line size register is set 8 bytes less than actual */
1688 ch
->line_size
= vcs
->line_size
- 8;
1690 /* let VINO know where to transfer data */
1691 ch
->start_desc_tbl
= fb
->desc_table
.dma
;
1692 ch
->next_4_desc
= fb
->desc_table
.dma
;
1694 /* give vino time to fetch the first four descriptors, 5 usec
1695 * should be more than enough time */
1696 udelay(VINO_DESC_FETCH_DELAY
);
1698 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1699 ch
->start_desc_tbl
, ch
->next_4_desc
);
1701 /* set the alpha register */
1702 ch
->alpha
= vcs
->alpha
;
1704 /* set clipping registers */
1705 ch
->clip_start
= VINO_CLIP_ODD(norm
->odd
.top
+ vcs
->clipping
.top
/ 2) |
1706 VINO_CLIP_EVEN(norm
->even
.top
+
1707 vcs
->clipping
.top
/ 2) |
1708 VINO_CLIP_X(vcs
->clipping
.left
);
1709 ch
->clip_end
= VINO_CLIP_ODD(norm
->odd
.top
+
1710 vcs
->clipping
.bottom
/ 2 - 1) |
1711 VINO_CLIP_EVEN(norm
->even
.top
+
1712 vcs
->clipping
.bottom
/ 2 - 1) |
1713 VINO_CLIP_X(vcs
->clipping
.right
);
1715 /* set the size of actual content in the buffer (DECIMATION !) */
1716 fb
->data_size
= ((vcs
->clipping
.right
- vcs
->clipping
.left
) /
1718 ((vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
1720 vino_data_formats
[vcs
->data_format
].bpp
;
1722 ch
->frame_rate
= vcs
->framert_reg
;
1724 ctrl
= vino
->control
;
1725 intr
= vino
->intr_status
;
1727 if (vcs
->channel
== VINO_CHANNEL_A
) {
1728 /* All interrupt conditions for this channel was cleared
1729 * so clear the interrupt status register and enable
1731 intr
&= ~VINO_INTSTAT_A
;
1732 ctrl
|= VINO_CTRL_A_INT
;
1734 /* enable synchronization */
1735 ctrl
|= VINO_CTRL_A_SYNC_ENBL
;
1737 /* enable frame assembly */
1738 ctrl
|= VINO_CTRL_A_INTERLEAVE_ENBL
;
1740 /* set decimation used */
1741 if (vcs
->decimation
< 2)
1742 ctrl
&= ~VINO_CTRL_A_DEC_ENBL
;
1744 ctrl
|= VINO_CTRL_A_DEC_ENBL
;
1745 ctrl
&= ~VINO_CTRL_A_DEC_SCALE_MASK
;
1746 ctrl
|= (vcs
->decimation
- 1) <<
1747 VINO_CTRL_A_DEC_SCALE_SHIFT
;
1750 /* select input interface */
1751 if (vcs
->input
== VINO_INPUT_D1
)
1752 ctrl
|= VINO_CTRL_A_SELECT
;
1754 ctrl
&= ~VINO_CTRL_A_SELECT
;
1757 ctrl
&= ~(VINO_CTRL_A_LUMA_ONLY
| VINO_CTRL_A_RGB
|
1758 VINO_CTRL_A_DITHER
);
1760 intr
&= ~VINO_INTSTAT_B
;
1761 ctrl
|= VINO_CTRL_B_INT
;
1763 ctrl
|= VINO_CTRL_B_SYNC_ENBL
;
1764 ctrl
|= VINO_CTRL_B_INTERLEAVE_ENBL
;
1766 if (vcs
->decimation
< 2)
1767 ctrl
&= ~VINO_CTRL_B_DEC_ENBL
;
1769 ctrl
|= VINO_CTRL_B_DEC_ENBL
;
1770 ctrl
&= ~VINO_CTRL_B_DEC_SCALE_MASK
;
1771 ctrl
|= (vcs
->decimation
- 1) <<
1772 VINO_CTRL_B_DEC_SCALE_SHIFT
;
1775 if (vcs
->input
== VINO_INPUT_D1
)
1776 ctrl
|= VINO_CTRL_B_SELECT
;
1778 ctrl
&= ~VINO_CTRL_B_SELECT
;
1780 ctrl
&= ~(VINO_CTRL_B_LUMA_ONLY
| VINO_CTRL_B_RGB
|
1781 VINO_CTRL_B_DITHER
);
1785 fb
->data_format
= vcs
->data_format
;
1787 switch (vcs
->data_format
) {
1788 case VINO_DATA_FMT_GREY
:
1789 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1790 VINO_CTRL_A_LUMA_ONLY
: VINO_CTRL_B_LUMA_ONLY
;
1792 case VINO_DATA_FMT_RGB32
:
1793 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1794 VINO_CTRL_A_RGB
: VINO_CTRL_B_RGB
;
1796 case VINO_DATA_FMT_YUV
:
1797 /* nothing needs to be done */
1799 case VINO_DATA_FMT_RGB332
:
1800 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1801 VINO_CTRL_A_RGB
| VINO_CTRL_A_DITHER
:
1802 VINO_CTRL_B_RGB
| VINO_CTRL_B_DITHER
;
1806 vino
->intr_status
= intr
;
1807 vino
->control
= ctrl
;
1812 /* (execute only with vino_lock locked) */
1813 static inline void vino_dma_start(struct vino_channel_settings
*vcs
)
1815 u32 ctrl
= vino
->control
;
1817 dprintk("vino_dma_start():\n");
1818 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1819 VINO_CTRL_A_DMA_ENBL
: VINO_CTRL_B_DMA_ENBL
;
1820 vino
->control
= ctrl
;
1823 /* (execute only with vino_lock locked) */
1824 static inline void vino_dma_stop(struct vino_channel_settings
*vcs
)
1826 u32 ctrl
= vino
->control
;
1828 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1829 ~VINO_CTRL_A_DMA_ENBL
: ~VINO_CTRL_B_DMA_ENBL
;
1830 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1831 ~VINO_CTRL_A_INT
: ~VINO_CTRL_B_INT
;
1832 vino
->control
= ctrl
;
1833 dprintk("vino_dma_stop():\n");
1837 * Load dummy page to descriptor registers. This prevents generating of
1838 * spurious interrupts. (execute only with vino_lock locked)
1840 static void vino_clear_interrupt(struct vino_channel_settings
*vcs
)
1842 struct sgi_vino_channel
*ch
;
1844 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1849 ch
->start_desc_tbl
= vino_drvdata
->dummy_desc_table
.dma
;
1850 ch
->next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
1852 udelay(VINO_DESC_FETCH_DELAY
);
1853 dprintk("channel %c clear interrupt condition\n",
1854 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A':'B');
1857 static int vino_capture(struct vino_channel_settings
*vcs
,
1858 struct vino_framebuffer
*fb
)
1861 unsigned long flags
, flags2
;
1863 spin_lock_irqsave(&fb
->state_lock
, flags
);
1865 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
1867 fb
->state
= VINO_FRAMEBUFFER_IN_USE
;
1869 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
1874 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
1875 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags2
);
1877 vino_dma_setup(vcs
, fb
);
1878 vino_dma_start(vcs
);
1880 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags2
);
1881 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
1887 struct vino_framebuffer
*vino_capture_enqueue(struct
1888 vino_channel_settings
*vcs
,
1891 struct vino_framebuffer
*fb
;
1892 unsigned long flags
;
1894 dprintk("vino_capture_enqueue():\n");
1896 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
1898 fb
= vino_queue_add(&vcs
->fb_queue
, index
);
1900 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
1905 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1910 static int vino_capture_next(struct vino_channel_settings
*vcs
, int start
)
1912 struct vino_framebuffer
*fb
;
1913 unsigned int incoming
, id
;
1915 unsigned long flags
;
1917 dprintk("vino_capture_next():\n");
1919 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
1922 /* start capture only if capture isn't in progress already */
1923 if (vcs
->capturing
) {
1924 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1929 /* capture next frame:
1930 * stop capture if capturing is not set */
1931 if (!vcs
->capturing
) {
1932 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1937 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
1939 dprintk("vino_capture_next(): vino_queue_get_incoming() "
1944 if (incoming
== 0) {
1945 dprintk("vino_capture_next(): no buffers available\n");
1949 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
1951 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
1960 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1962 err
= vino_capture(vcs
, fb
);
1968 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1973 static inline int vino_is_capturing(struct vino_channel_settings
*vcs
)
1976 unsigned long flags
;
1978 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
1980 ret
= vcs
->capturing
;
1982 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1987 /* waits until a frame is captured */
1988 static int vino_wait_for_frame(struct vino_channel_settings
*vcs
)
1993 dprintk("vino_wait_for_frame():\n");
1995 init_waitqueue_entry(&wait
, current
);
1996 /* add ourselves into wait queue */
1997 add_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
1999 /* to ensure that schedule_timeout will return immediately
2000 * if VINO interrupt was triggered meanwhile */
2001 schedule_timeout_interruptible(msecs_to_jiffies(100));
2003 if (signal_pending(current
))
2006 remove_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2008 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2009 err
? "failed" : "ok");
2014 /* the function assumes that PAGE_SIZE % 4 == 0 */
2015 static void vino_convert_to_rgba(struct vino_framebuffer
*fb
) {
2016 unsigned char *pageptr
;
2017 unsigned int page
, i
;
2020 for (page
= 0; page
< fb
->desc_table
.page_count
; page
++) {
2021 pageptr
= (unsigned char *)fb
->desc_table
.virtual[page
];
2023 for (i
= 0; i
< PAGE_SIZE
; i
+= 4) {
2025 pageptr
[0] = pageptr
[3];
2026 pageptr
[1] = pageptr
[2];
2027 pageptr
[2] = pageptr
[1];
2034 /* checks if the buffer is in correct state and syncs data */
2035 static int vino_check_buffer(struct vino_channel_settings
*vcs
,
2036 struct vino_framebuffer
*fb
)
2039 unsigned long flags
;
2041 dprintk("vino_check_buffer():\n");
2043 spin_lock_irqsave(&fb
->state_lock
, flags
);
2044 switch (fb
->state
) {
2045 case VINO_FRAMEBUFFER_IN_USE
:
2048 case VINO_FRAMEBUFFER_READY
:
2049 vino_sync_buffer(fb
);
2050 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2055 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2058 if (vino_pixel_conversion
2059 && (fb
->data_format
== VINO_DATA_FMT_RGB32
)) {
2060 vino_convert_to_rgba(fb
);
2062 } else if (err
&& (err
!= -EINVAL
)) {
2063 dprintk("vino_check_buffer(): buffer not ready\n");
2065 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2067 vino_clear_interrupt(vcs
);
2068 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2074 /* forcefully terminates capture */
2075 static void vino_capture_stop(struct vino_channel_settings
*vcs
)
2077 unsigned int incoming
= 0, outgoing
= 0, id
;
2078 unsigned long flags
, flags2
;
2080 dprintk("vino_capture_stop():\n");
2082 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2084 /* unset capturing to stop queue processing */
2087 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags2
);
2090 vino_clear_interrupt(vcs
);
2092 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags2
);
2094 /* remove all items from the queue */
2095 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2096 dprintk("vino_capture_stop(): "
2097 "vino_queue_get_incoming() failed\n");
2100 while (incoming
> 0) {
2101 vino_queue_transfer(&vcs
->fb_queue
);
2103 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2104 dprintk("vino_capture_stop(): "
2105 "vino_queue_get_incoming() failed\n");
2110 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2111 dprintk("vino_capture_stop(): "
2112 "vino_queue_get_outgoing() failed\n");
2115 while (outgoing
> 0) {
2116 vino_queue_remove(&vcs
->fb_queue
, &id
);
2118 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2119 dprintk("vino_capture_stop(): "
2120 "vino_queue_get_outgoing() failed\n");
2126 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2130 static void vino_skip_frame(struct vino_channel_settings
*vcs
)
2132 struct vino_framebuffer
*fb
;
2133 unsigned long flags
;
2136 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2137 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2139 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2140 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2143 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2145 spin_lock_irqsave(&fb
->state_lock
, flags
);
2146 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2147 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2149 vino_capture_next(vcs
, 0);
2152 static void vino_frame_done(struct vino_channel_settings
*vcs
)
2154 struct vino_framebuffer
*fb
;
2155 unsigned long flags
;
2157 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2158 fb
= vino_queue_transfer(&vcs
->fb_queue
);
2160 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2161 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2164 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2166 fb
->frame_counter
= vcs
->int_data
.frame_counter
;
2167 memcpy(&fb
->timestamp
, &vcs
->int_data
.timestamp
,
2168 sizeof(struct timeval
));
2170 spin_lock_irqsave(&fb
->state_lock
, flags
);
2171 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
2172 fb
->state
= VINO_FRAMEBUFFER_READY
;
2173 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2175 wake_up(&vcs
->fb_queue
.frame_wait_queue
);
2177 vino_capture_next(vcs
, 0);
2180 static void vino_capture_tasklet(unsigned long channel
) {
2181 struct vino_channel_settings
*vcs
;
2183 vcs
= (channel
== VINO_CHANNEL_A
)
2184 ? &vino_drvdata
->a
: &vino_drvdata
->b
;
2186 if (vcs
->int_data
.skip
)
2187 vcs
->int_data
.skip_count
++;
2189 if (vcs
->int_data
.skip
&& (vcs
->int_data
.skip_count
2190 <= VINO_MAX_FRAME_SKIP_COUNT
)) {
2191 vino_skip_frame(vcs
);
2193 vcs
->int_data
.skip_count
= 0;
2194 vino_frame_done(vcs
);
2198 static irqreturn_t
vino_interrupt(int irq
, void *dev_id
)
2201 unsigned int fc_a
, fc_b
;
2202 int handled_a
= 0, skip_a
= 0, done_a
= 0;
2203 int handled_b
= 0, skip_b
= 0, done_b
= 0;
2205 #ifdef VINO_DEBUG_INT
2207 unsigned int line_count
= vino
->a
.line_count
,
2208 page_index
= vino
->a
.page_index
,
2209 field_counter
= vino
->a
.field_counter
,
2210 start_desc_tbl
= vino
->a
.start_desc_tbl
,
2211 next_4_desc
= vino
->a
.next_4_desc
;
2212 unsigned int line_count_2
,
2219 spin_lock(&vino_drvdata
->vino_lock
);
2221 while ((intr
= vino
->intr_status
)) {
2222 fc_a
= vino
->a
.field_counter
>> 1;
2223 fc_b
= vino
->b
.field_counter
>> 1;
2225 /* handle error-interrupts in some special way ?
2226 * --> skips frames */
2227 if (intr
& VINO_INTSTAT_A
) {
2228 if (intr
& VINO_INTSTAT_A_EOF
) {
2229 vino_drvdata
->a
.field
++;
2230 if (vino_drvdata
->a
.field
> 1) {
2231 vino_dma_stop(&vino_drvdata
->a
);
2232 vino_clear_interrupt(&vino_drvdata
->a
);
2233 vino_drvdata
->a
.field
= 0;
2236 if (vino
->a
.page_index
2237 != vino_drvdata
->a
.line_size
) {
2238 vino
->a
.line_count
= 0;
2239 vino
->a
.page_index
=
2242 vino
->a
.next_4_desc
=
2243 vino
->a
.start_desc_tbl
;
2246 dprintk("channel A end-of-field "
2247 "interrupt: %04x\n", intr
);
2249 vino_dma_stop(&vino_drvdata
->a
);
2250 vino_clear_interrupt(&vino_drvdata
->a
);
2251 vino_drvdata
->a
.field
= 0;
2253 dprintk("channel A error interrupt: %04x\n",
2257 #ifdef VINO_DEBUG_INT
2258 line_count_2
= vino
->a
.line_count
;
2259 page_index_2
= vino
->a
.page_index
;
2260 field_counter_2
= vino
->a
.field_counter
;
2261 start_desc_tbl_2
= vino
->a
.start_desc_tbl
;
2262 next_4_desc_2
= vino
->a
.next_4_desc
;
2264 printk("intr = %04x, loop = %d, field = %d\n",
2265 intr
, loop
, vino_drvdata
->a
.field
);
2266 printk("1- line count = %04d, page index = %04d, "
2267 "start = %08x, next = %08x\n"
2268 " fieldc = %d, framec = %d\n",
2269 line_count
, page_index
, start_desc_tbl
,
2270 next_4_desc
, field_counter
, fc_a
);
2271 printk("12-line count = %04d, page index = %04d, "
2272 " start = %08x, next = %08x\n",
2273 line_count_2
, page_index_2
, start_desc_tbl_2
,
2281 if (intr
& VINO_INTSTAT_B
) {
2282 if (intr
& VINO_INTSTAT_B_EOF
) {
2283 vino_drvdata
->b
.field
++;
2284 if (vino_drvdata
->b
.field
> 1) {
2285 vino_dma_stop(&vino_drvdata
->b
);
2286 vino_clear_interrupt(&vino_drvdata
->b
);
2287 vino_drvdata
->b
.field
= 0;
2290 dprintk("channel B end-of-field "
2291 "interrupt: %04x\n", intr
);
2293 vino_dma_stop(&vino_drvdata
->b
);
2294 vino_clear_interrupt(&vino_drvdata
->b
);
2295 vino_drvdata
->b
.field
= 0;
2297 dprintk("channel B error interrupt: %04x\n",
2302 /* Always remember to clear interrupt status.
2303 * Disable VINO interrupts while we do this. */
2304 ctrl
= vino
->control
;
2305 vino
->control
= ctrl
& ~(VINO_CTRL_A_INT
| VINO_CTRL_B_INT
);
2306 vino
->intr_status
= ~intr
;
2307 vino
->control
= ctrl
;
2309 spin_unlock(&vino_drvdata
->vino_lock
);
2311 if ((!handled_a
) && (done_a
|| skip_a
)) {
2313 do_gettimeofday(&vino_drvdata
->
2314 a
.int_data
.timestamp
);
2315 vino_drvdata
->a
.int_data
.frame_counter
= fc_a
;
2317 vino_drvdata
->a
.int_data
.skip
= skip_a
;
2319 dprintk("channel A %s, interrupt: %d\n",
2320 skip_a
? "skipping frame" : "frame done",
2322 tasklet_hi_schedule(&vino_tasklet_a
);
2326 if ((!handled_b
) && (done_b
|| skip_b
)) {
2328 do_gettimeofday(&vino_drvdata
->
2329 b
.int_data
.timestamp
);
2330 vino_drvdata
->b
.int_data
.frame_counter
= fc_b
;
2332 vino_drvdata
->b
.int_data
.skip
= skip_b
;
2334 dprintk("channel B %s, interrupt: %d\n",
2335 skip_b
? "skipping frame" : "frame done",
2337 tasklet_hi_schedule(&vino_tasklet_b
);
2341 #ifdef VINO_DEBUG_INT
2344 spin_lock(&vino_drvdata
->vino_lock
);
2347 spin_unlock(&vino_drvdata
->vino_lock
);
2352 /* VINO video input management */
2354 static int vino_get_saa7191_input(int input
)
2357 case VINO_INPUT_COMPOSITE
:
2358 return SAA7191_INPUT_COMPOSITE
;
2359 case VINO_INPUT_SVIDEO
:
2360 return SAA7191_INPUT_SVIDEO
;
2362 printk(KERN_ERR
"VINO: vino_get_saa7191_input(): "
2363 "invalid input!\n");
2368 /* execute with input_lock locked */
2369 static int vino_is_input_owner(struct vino_channel_settings
*vcs
)
2371 switch(vcs
->input
) {
2372 case VINO_INPUT_COMPOSITE
:
2373 case VINO_INPUT_SVIDEO
:
2374 return vino_drvdata
->decoder_owner
== vcs
->channel
;
2376 return vino_drvdata
->camera_owner
== vcs
->channel
;
2382 static int vino_acquire_input(struct vino_channel_settings
*vcs
)
2384 unsigned long flags
;
2387 dprintk("vino_acquire_input():\n");
2389 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2391 /* First try D1 and then SAA7191 */
2392 if (vino_drvdata
->camera
2393 && (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)) {
2394 vino_drvdata
->camera_owner
= vcs
->channel
;
2395 vcs
->input
= VINO_INPUT_D1
;
2396 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2397 } else if (vino_drvdata
->decoder
2398 && (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
)) {
2403 input
= VINO_INPUT_COMPOSITE
;
2405 ret
= decoder_call(video
, s_routing
,
2406 vino_get_saa7191_input(input
), 0, 0);
2412 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2414 /* Don't hold spinlocks while auto-detecting norm
2415 * as it may take a while... */
2417 ret
= decoder_call(video
, querystd
, &norm
);
2419 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2420 if (vino_data_norms
[data_norm
].std
& norm
)
2424 data_norm
= VINO_DATA_NORM_PAL
;
2425 ret
= decoder_call(core
, s_std
, norm
);
2428 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2435 vino_drvdata
->decoder_owner
= vcs
->channel
;
2438 vcs
->data_norm
= data_norm
;
2440 vcs
->input
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2441 vino_drvdata
->b
.input
: vino_drvdata
->a
.input
;
2442 vcs
->data_norm
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2443 vino_drvdata
->b
.data_norm
: vino_drvdata
->a
.data_norm
;
2446 if (vcs
->input
== VINO_INPUT_NONE
) {
2451 vino_set_default_clipping(vcs
);
2452 vino_set_default_scaling(vcs
);
2453 vino_set_default_framerate(vcs
);
2455 dprintk("vino_acquire_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2458 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2463 static int vino_set_input(struct vino_channel_settings
*vcs
, int input
)
2465 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2466 &vino_drvdata
->b
: &vino_drvdata
->a
;
2467 unsigned long flags
;
2470 dprintk("vino_set_input():\n");
2472 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2474 if (vcs
->input
== input
)
2478 case VINO_INPUT_COMPOSITE
:
2479 case VINO_INPUT_SVIDEO
:
2480 if (!vino_drvdata
->decoder
) {
2485 if (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
) {
2486 vino_drvdata
->decoder_owner
= vcs
->channel
;
2489 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2493 ret
= decoder_call(video
, s_routing
,
2494 vino_get_saa7191_input(input
), 0, 0);
2496 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2501 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2503 /* Don't hold spinlocks while auto-detecting norm
2504 * as it may take a while... */
2506 ret
= decoder_call(video
, querystd
, &norm
);
2508 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2509 if (vino_data_norms
[data_norm
].std
& norm
)
2513 data_norm
= VINO_DATA_NORM_PAL
;
2514 ret
= decoder_call(core
, s_std
, norm
);
2517 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2520 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2526 vcs
->data_norm
= data_norm
;
2528 if (input
!= vcs2
->input
) {
2534 vcs
->data_norm
= vcs2
->data_norm
;
2537 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2538 /* Transfer the ownership or release the input */
2539 if (vcs2
->input
== VINO_INPUT_D1
) {
2540 vino_drvdata
->camera_owner
= vcs2
->channel
;
2542 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2547 if (!vino_drvdata
->camera
) {
2552 if (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)
2553 vino_drvdata
->camera_owner
= vcs
->channel
;
2555 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2556 /* Transfer the ownership or release the input */
2557 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2558 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2559 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2561 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2566 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2573 vino_set_default_clipping(vcs
);
2574 vino_set_default_scaling(vcs
);
2575 vino_set_default_framerate(vcs
);
2577 dprintk("vino_set_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2580 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2585 static void vino_release_input(struct vino_channel_settings
*vcs
)
2587 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2588 &vino_drvdata
->b
: &vino_drvdata
->a
;
2589 unsigned long flags
;
2591 dprintk("vino_release_input():\n");
2593 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2595 /* Release ownership of the channel
2596 * and if the other channel takes input from
2597 * the same source, transfer the ownership */
2598 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2599 if (vcs2
->input
== VINO_INPUT_D1
) {
2600 vino_drvdata
->camera_owner
= vcs2
->channel
;
2602 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2604 } else if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2605 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2606 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2607 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2609 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2612 vcs
->input
= VINO_INPUT_NONE
;
2614 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2617 /* execute with input_lock locked */
2618 static int vino_set_data_norm(struct vino_channel_settings
*vcs
,
2619 unsigned int data_norm
,
2620 unsigned long *flags
)
2624 if (data_norm
== vcs
->data_norm
)
2627 switch (vcs
->input
) {
2629 /* only one "norm" supported */
2630 if (data_norm
!= VINO_DATA_NORM_D1
)
2633 case VINO_INPUT_COMPOSITE
:
2634 case VINO_INPUT_SVIDEO
: {
2637 if ((data_norm
!= VINO_DATA_NORM_PAL
)
2638 && (data_norm
!= VINO_DATA_NORM_NTSC
)
2639 && (data_norm
!= VINO_DATA_NORM_SECAM
))
2642 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, *flags
);
2644 /* Don't hold spinlocks while setting norm
2645 * as it may take a while... */
2647 norm
= vino_data_norms
[data_norm
].std
;
2648 err
= decoder_call(core
, s_std
, norm
);
2650 spin_lock_irqsave(&vino_drvdata
->input_lock
, *flags
);
2655 vcs
->data_norm
= data_norm
;
2657 vino_set_default_clipping(vcs
);
2658 vino_set_default_scaling(vcs
);
2659 vino_set_default_framerate(vcs
);
2670 /* V4L2 helper functions */
2672 static int vino_find_data_format(__u32 pixelformat
)
2676 for (i
= 0; i
< VINO_DATA_FMT_COUNT
; i
++) {
2677 if (vino_data_formats
[i
].pixelformat
== pixelformat
)
2681 return VINO_DATA_FMT_NONE
;
2684 static int vino_int_enum_input(struct vino_channel_settings
*vcs
, __u32 index
)
2686 int input
= VINO_INPUT_NONE
;
2687 unsigned long flags
;
2689 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2690 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2693 input
= VINO_INPUT_COMPOSITE
;
2696 input
= VINO_INPUT_SVIDEO
;
2699 input
= VINO_INPUT_D1
;
2702 } else if (vino_drvdata
->decoder
) {
2705 input
= VINO_INPUT_COMPOSITE
;
2708 input
= VINO_INPUT_SVIDEO
;
2711 } else if (vino_drvdata
->camera
) {
2714 input
= VINO_INPUT_D1
;
2718 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2723 /* execute with input_lock locked */
2724 static __u32
vino_find_input_index(struct vino_channel_settings
*vcs
)
2728 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2729 switch (vcs
->input
) {
2730 case VINO_INPUT_COMPOSITE
:
2733 case VINO_INPUT_SVIDEO
:
2740 } else if (vino_drvdata
->decoder
) {
2741 switch (vcs
->input
) {
2742 case VINO_INPUT_COMPOSITE
:
2745 case VINO_INPUT_SVIDEO
:
2749 } else if (vino_drvdata
->camera
) {
2750 switch (vcs
->input
) {
2762 static int vino_querycap(struct file
*file
, void *__fh
,
2763 struct v4l2_capability
*cap
)
2765 memset(cap
, 0, sizeof(struct v4l2_capability
));
2767 strcpy(cap
->driver
, vino_driver_name
);
2768 strcpy(cap
->card
, vino_driver_description
);
2769 strcpy(cap
->bus_info
, vino_bus_name
);
2770 cap
->version
= VINO_VERSION_CODE
;
2772 V4L2_CAP_VIDEO_CAPTURE
|
2774 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
2778 static int vino_enum_input(struct file
*file
, void *__fh
,
2779 struct v4l2_input
*i
)
2781 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2782 __u32 index
= i
->index
;
2784 dprintk("requested index = %d\n", index
);
2786 input
= vino_int_enum_input(vcs
, index
);
2787 if (input
== VINO_INPUT_NONE
)
2790 memset(i
, 0, sizeof(struct v4l2_input
));
2793 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
2794 i
->std
= vino_inputs
[input
].std
;
2795 strcpy(i
->name
, vino_inputs
[input
].name
);
2797 if (input
== VINO_INPUT_COMPOSITE
|| input
== VINO_INPUT_SVIDEO
)
2798 decoder_call(video
, g_input_status
, &i
->status
);
2802 static int vino_g_input(struct file
*file
, void *__fh
,
2805 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2808 unsigned long flags
;
2810 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2812 index
= vino_find_input_index(vcs
);
2813 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2815 dprintk("input = %d\n", input
);
2817 if (input
== VINO_INPUT_NONE
) {
2826 static int vino_s_input(struct file
*file
, void *__fh
,
2829 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2831 dprintk("requested input = %d\n", i
);
2833 input
= vino_int_enum_input(vcs
, i
);
2834 if (input
== VINO_INPUT_NONE
)
2837 return vino_set_input(vcs
, input
);
2840 static int vino_querystd(struct file
*file
, void *__fh
,
2843 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2844 unsigned long flags
;
2847 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2849 switch (vcs
->input
) {
2851 *std
= vino_inputs
[vcs
->input
].std
;
2853 case VINO_INPUT_COMPOSITE
:
2854 case VINO_INPUT_SVIDEO
: {
2855 decoder_call(video
, querystd
, std
);
2862 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2867 static int vino_g_std(struct file
*file
, void *__fh
,
2870 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2871 unsigned long flags
;
2873 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2875 *std
= vino_data_norms
[vcs
->data_norm
].std
;
2876 dprintk("current standard = %d\n", vcs
->data_norm
);
2878 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2883 static int vino_s_std(struct file
*file
, void *__fh
,
2886 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2887 unsigned long flags
;
2890 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2892 if (!vino_is_input_owner(vcs
)) {
2897 /* check if the standard is valid for the current input */
2898 if ((*std
) & vino_inputs
[vcs
->input
].std
) {
2899 dprintk("standard accepted\n");
2901 /* change the video norm for SAA7191
2902 * and accept NTSC for D1 (do nothing) */
2904 if (vcs
->input
== VINO_INPUT_D1
)
2907 if ((*std
) & V4L2_STD_PAL
) {
2908 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_PAL
,
2910 } else if ((*std
) & V4L2_STD_NTSC
) {
2911 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_NTSC
,
2913 } else if ((*std
) & V4L2_STD_SECAM
) {
2914 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_SECAM
,
2928 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2933 static int vino_enum_fmt_vid_cap(struct file
*file
, void *__fh
,
2934 struct v4l2_fmtdesc
*fd
)
2936 dprintk("format index = %d\n", fd
->index
);
2938 if (fd
->index
>= VINO_DATA_FMT_COUNT
)
2940 dprintk("format name = %s\n", vino_data_formats
[fd
->index
].description
);
2942 fd
->pixelformat
= vino_data_formats
[fd
->index
].pixelformat
;
2943 strcpy(fd
->description
, vino_data_formats
[fd
->index
].description
);
2947 static int vino_try_fmt_vid_cap(struct file
*file
, void *__fh
,
2948 struct v4l2_format
*f
)
2950 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2951 struct vino_channel_settings tempvcs
;
2952 unsigned long flags
;
2953 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
2955 dprintk("requested: w = %d, h = %d\n",
2956 pf
->width
, pf
->height
);
2958 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2959 memcpy(&tempvcs
, vcs
, sizeof(struct vino_channel_settings
));
2960 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2962 tempvcs
.data_format
= vino_find_data_format(pf
->pixelformat
);
2963 if (tempvcs
.data_format
== VINO_DATA_FMT_NONE
) {
2964 tempvcs
.data_format
= VINO_DATA_FMT_GREY
;
2966 vino_data_formats
[tempvcs
.data_format
].
2970 /* data format must be set before clipping/scaling */
2971 vino_set_scaling(&tempvcs
, pf
->width
, pf
->height
);
2973 dprintk("data format = %s\n",
2974 vino_data_formats
[tempvcs
.data_format
].description
);
2976 pf
->width
= (tempvcs
.clipping
.right
- tempvcs
.clipping
.left
) /
2978 pf
->height
= (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
2981 pf
->field
= V4L2_FIELD_INTERLACED
;
2982 pf
->bytesperline
= tempvcs
.line_size
;
2983 pf
->sizeimage
= tempvcs
.line_size
*
2984 (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
2987 vino_data_formats
[tempvcs
.data_format
].colorspace
;
2993 static int vino_g_fmt_vid_cap(struct file
*file
, void *__fh
,
2994 struct v4l2_format
*f
)
2996 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2997 unsigned long flags
;
2998 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3000 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3002 pf
->width
= (vcs
->clipping
.right
- vcs
->clipping
.left
) /
3004 pf
->height
= (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3007 vino_data_formats
[vcs
->data_format
].pixelformat
;
3009 pf
->field
= V4L2_FIELD_INTERLACED
;
3010 pf
->bytesperline
= vcs
->line_size
;
3011 pf
->sizeimage
= vcs
->line_size
*
3012 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3015 vino_data_formats
[vcs
->data_format
].colorspace
;
3019 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3023 static int vino_s_fmt_vid_cap(struct file
*file
, void *__fh
,
3024 struct v4l2_format
*f
)
3026 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3028 unsigned long flags
;
3029 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3031 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3033 data_format
= vino_find_data_format(pf
->pixelformat
);
3035 if (data_format
== VINO_DATA_FMT_NONE
) {
3036 vcs
->data_format
= VINO_DATA_FMT_GREY
;
3038 vino_data_formats
[vcs
->data_format
].
3041 vcs
->data_format
= data_format
;
3044 /* data format must be set before clipping/scaling */
3045 vino_set_scaling(vcs
, pf
->width
, pf
->height
);
3047 dprintk("data format = %s\n",
3048 vino_data_formats
[vcs
->data_format
].description
);
3050 pf
->width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3051 pf
->height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3053 pf
->field
= V4L2_FIELD_INTERLACED
;
3054 pf
->bytesperline
= vcs
->line_size
;
3055 pf
->sizeimage
= vcs
->line_size
*
3056 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3059 vino_data_formats
[vcs
->data_format
].colorspace
;
3063 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3067 static int vino_cropcap(struct file
*file
, void *__fh
,
3068 struct v4l2_cropcap
*ccap
)
3070 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3071 const struct vino_data_norm
*norm
;
3072 unsigned long flags
;
3074 switch (ccap
->type
) {
3075 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3076 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3078 norm
= &vino_data_norms
[vcs
->data_norm
];
3080 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3082 ccap
->bounds
.left
= 0;
3083 ccap
->bounds
.top
= 0;
3084 ccap
->bounds
.width
= norm
->width
;
3085 ccap
->bounds
.height
= norm
->height
;
3086 memcpy(&ccap
->defrect
, &ccap
->bounds
,
3087 sizeof(struct v4l2_rect
));
3089 ccap
->pixelaspect
.numerator
= 1;
3090 ccap
->pixelaspect
.denominator
= 1;
3092 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3100 static int vino_g_crop(struct file
*file
, void *__fh
,
3101 struct v4l2_crop
*c
)
3103 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3104 unsigned long flags
;
3107 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3108 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3110 c
->c
.left
= vcs
->clipping
.left
;
3111 c
->c
.top
= vcs
->clipping
.top
;
3112 c
->c
.width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3113 c
->c
.height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3115 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3117 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3125 static int vino_s_crop(struct file
*file
, void *__fh
,
3126 struct v4l2_crop
*c
)
3128 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3129 unsigned long flags
;
3132 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3133 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3135 vino_set_clipping(vcs
, c
->c
.left
, c
->c
.top
,
3136 c
->c
.width
, c
->c
.height
);
3138 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3140 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3148 static int vino_g_parm(struct file
*file
, void *__fh
,
3149 struct v4l2_streamparm
*sp
)
3151 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3152 unsigned long flags
;
3153 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3155 cp
->capability
= V4L2_CAP_TIMEPERFRAME
;
3156 cp
->timeperframe
.numerator
= 1;
3158 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3160 cp
->timeperframe
.denominator
= vcs
->fps
;
3162 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3168 static int vino_s_parm(struct file
*file
, void *__fh
,
3169 struct v4l2_streamparm
*sp
)
3171 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3172 unsigned long flags
;
3173 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3175 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3177 if ((cp
->timeperframe
.numerator
== 0) ||
3178 (cp
->timeperframe
.denominator
== 0)) {
3179 /* reset framerate */
3180 vino_set_default_framerate(vcs
);
3182 vino_set_framerate(vcs
, cp
->timeperframe
.denominator
/
3183 cp
->timeperframe
.numerator
);
3186 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3191 static int vino_reqbufs(struct file
*file
, void *__fh
,
3192 struct v4l2_requestbuffers
*rb
)
3194 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3199 /* TODO: check queue type */
3200 if (rb
->memory
!= V4L2_MEMORY_MMAP
) {
3201 dprintk("type not mmap\n");
3205 dprintk("count = %d\n", rb
->count
);
3206 if (rb
->count
> 0) {
3207 if (vino_is_capturing(vcs
)) {
3208 dprintk("busy, capturing\n");
3212 if (vino_queue_has_mapped_buffers(&vcs
->fb_queue
)) {
3213 dprintk("busy, buffers still mapped\n");
3217 vino_queue_free(&vcs
->fb_queue
);
3218 vino_queue_init(&vcs
->fb_queue
, &rb
->count
);
3222 vino_capture_stop(vcs
);
3223 vino_queue_free(&vcs
->fb_queue
);
3229 static void vino_v4l2_get_buffer_status(struct vino_channel_settings
*vcs
,
3230 struct vino_framebuffer
*fb
,
3231 struct v4l2_buffer
*b
)
3233 if (vino_queue_outgoing_contains(&vcs
->fb_queue
,
3235 b
->flags
&= ~V4L2_BUF_FLAG_QUEUED
;
3236 b
->flags
|= V4L2_BUF_FLAG_DONE
;
3237 } else if (vino_queue_incoming_contains(&vcs
->fb_queue
,
3239 b
->flags
&= ~V4L2_BUF_FLAG_DONE
;
3240 b
->flags
|= V4L2_BUF_FLAG_QUEUED
;
3242 b
->flags
&= ~(V4L2_BUF_FLAG_DONE
|
3243 V4L2_BUF_FLAG_QUEUED
);
3246 b
->flags
&= ~(V4L2_BUF_FLAG_TIMECODE
);
3248 if (fb
->map_count
> 0)
3249 b
->flags
|= V4L2_BUF_FLAG_MAPPED
;
3252 b
->memory
= (vcs
->fb_queue
.type
== VINO_MEMORY_MMAP
) ?
3253 V4L2_MEMORY_MMAP
: V4L2_MEMORY_USERPTR
;
3254 b
->m
.offset
= fb
->offset
;
3255 b
->bytesused
= fb
->data_size
;
3256 b
->length
= fb
->size
;
3257 b
->field
= V4L2_FIELD_INTERLACED
;
3258 b
->sequence
= fb
->frame_counter
;
3259 memcpy(&b
->timestamp
, &fb
->timestamp
,
3260 sizeof(struct timeval
));
3263 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3264 fb
->id
, fb
->size
, fb
->data_size
, fb
->offset
);
3267 static int vino_querybuf(struct file
*file
, void *__fh
,
3268 struct v4l2_buffer
*b
)
3270 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3271 struct vino_framebuffer
*fb
;
3276 /* TODO: check queue type */
3277 if (b
->index
>= vino_queue_get_length(&vcs
->fb_queue
)) {
3278 dprintk("invalid index = %d\n",
3283 fb
= vino_queue_get_buffer(&vcs
->fb_queue
,
3286 dprintk("vino_queue_get_buffer() failed");
3290 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3295 static int vino_qbuf(struct file
*file
, void *__fh
,
3296 struct v4l2_buffer
*b
)
3298 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3299 struct vino_framebuffer
*fb
;
3305 /* TODO: check queue type */
3306 if (b
->memory
!= V4L2_MEMORY_MMAP
) {
3307 dprintk("type not mmap\n");
3311 fb
= vino_capture_enqueue(vcs
, b
->index
);
3315 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3317 if (vcs
->streaming
) {
3318 ret
= vino_capture_next(vcs
, 1);
3326 static int vino_dqbuf(struct file
*file
, void *__fh
,
3327 struct v4l2_buffer
*b
)
3329 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3330 unsigned int nonblocking
= file
->f_flags
& O_NONBLOCK
;
3331 struct vino_framebuffer
*fb
;
3332 unsigned int incoming
, outgoing
;
3338 /* TODO: check queue type */
3340 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3342 dprintk("vino_queue_get_incoming() failed\n");
3345 err
= vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
);
3347 dprintk("vino_queue_get_outgoing() failed\n");
3351 dprintk("incoming = %d, outgoing = %d\n", incoming
, outgoing
);
3353 if (outgoing
== 0) {
3354 if (incoming
== 0) {
3355 dprintk("no incoming or outgoing buffers\n");
3359 dprintk("non-blocking I/O was selected and "
3360 "there are no buffers to dequeue\n");
3364 err
= vino_wait_for_frame(vcs
);
3366 err
= vino_wait_for_frame(vcs
);
3368 /* interrupted or no frames captured because of
3370 /* vino_capture_failed(vcs); */
3376 fb
= vino_queue_remove(&vcs
->fb_queue
, &b
->index
);
3378 dprintk("vino_queue_remove() failed\n");
3382 err
= vino_check_buffer(vcs
, fb
);
3384 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3392 static int vino_streamon(struct file
*file
, void *__fh
,
3393 enum v4l2_buf_type i
)
3395 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3396 unsigned int incoming
;
3404 // TODO: check queue type
3406 if (vino_queue_get_length(&vcs
->fb_queue
) < 1) {
3407 dprintk("no buffers allocated\n");
3411 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3413 dprintk("vino_queue_get_incoming() failed\n");
3420 ret
= vino_capture_next(vcs
, 1);
3424 dprintk("couldn't start capture\n");
3432 static int vino_streamoff(struct file
*file
, void *__fh
,
3433 enum v4l2_buf_type i
)
3435 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3439 if (!vcs
->streaming
)
3443 vino_capture_stop(vcs
);
3448 static int vino_queryctrl(struct file
*file
, void *__fh
,
3449 struct v4l2_queryctrl
*queryctrl
)
3451 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3452 unsigned long flags
;
3456 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3458 switch (vcs
->input
) {
3460 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3461 if (vino_indycam_v4l2_controls
[i
].id
==
3464 &vino_indycam_v4l2_controls
[i
],
3465 sizeof(struct v4l2_queryctrl
));
3466 queryctrl
->reserved
[0] = 0;
3473 case VINO_INPUT_COMPOSITE
:
3474 case VINO_INPUT_SVIDEO
:
3475 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3476 if (vino_saa7191_v4l2_controls
[i
].id
==
3479 &vino_saa7191_v4l2_controls
[i
],
3480 sizeof(struct v4l2_queryctrl
));
3481 queryctrl
->reserved
[0] = 0;
3493 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3498 static int vino_g_ctrl(struct file
*file
, void *__fh
,
3499 struct v4l2_control
*control
)
3501 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3502 unsigned long flags
;
3506 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3508 switch (vcs
->input
) {
3509 case VINO_INPUT_D1
: {
3511 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3512 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3521 err
= camera_call(core
, g_ctrl
, control
);
3526 case VINO_INPUT_COMPOSITE
:
3527 case VINO_INPUT_SVIDEO
: {
3529 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3530 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3539 err
= decoder_call(core
, g_ctrl
, control
);
3549 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3554 static int vino_s_ctrl(struct file
*file
, void *__fh
,
3555 struct v4l2_control
*control
)
3557 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3558 unsigned long flags
;
3562 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3564 if (!vino_is_input_owner(vcs
)) {
3569 switch (vcs
->input
) {
3570 case VINO_INPUT_D1
: {
3572 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3573 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3580 if (control
->value
< vino_indycam_v4l2_controls
[i
].minimum
||
3581 control
->value
> vino_indycam_v4l2_controls
[i
].maximum
) {
3585 err
= camera_call(core
, s_ctrl
, control
);
3590 case VINO_INPUT_COMPOSITE
:
3591 case VINO_INPUT_SVIDEO
: {
3593 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3594 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3601 if (control
->value
< vino_saa7191_v4l2_controls
[i
].minimum
||
3602 control
->value
> vino_saa7191_v4l2_controls
[i
].maximum
) {
3607 err
= decoder_call(core
, s_ctrl
, control
);
3617 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3622 /* File operations */
3624 static int vino_open(struct file
*file
)
3626 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3628 dprintk("open(): channel = %c\n",
3629 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A' : 'B');
3631 mutex_lock(&vcs
->mutex
);
3634 dprintk("open(): driver busy\n");
3639 ret
= vino_acquire_input(vcs
);
3641 dprintk("open(): vino_acquire_input() failed\n");
3648 mutex_unlock(&vcs
->mutex
);
3650 dprintk("open(): %s!\n", ret
? "failed" : "complete");
3655 static int vino_close(struct file
*file
)
3657 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3658 dprintk("close():\n");
3660 mutex_lock(&vcs
->mutex
);
3665 vino_release_input(vcs
);
3667 /* stop DMA and free buffers */
3668 vino_capture_stop(vcs
);
3669 vino_queue_free(&vcs
->fb_queue
);
3672 mutex_unlock(&vcs
->mutex
);
3677 static void vino_vm_open(struct vm_area_struct
*vma
)
3679 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3682 dprintk("vino_vm_open(): count = %d\n", fb
->map_count
);
3685 static void vino_vm_close(struct vm_area_struct
*vma
)
3687 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3690 dprintk("vino_vm_close(): count = %d\n", fb
->map_count
);
3693 static const struct vm_operations_struct vino_vm_ops
= {
3694 .open
= vino_vm_open
,
3695 .close
= vino_vm_close
,
3698 static int vino_mmap(struct file
*file
, struct vm_area_struct
*vma
)
3700 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3702 unsigned long start
= vma
->vm_start
;
3703 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
3704 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
3706 struct vino_framebuffer
*fb
= NULL
;
3707 unsigned int i
, length
;
3710 dprintk("mmap():\n");
3712 // TODO: reject mmap if already mapped
3714 if (mutex_lock_interruptible(&vcs
->mutex
))
3722 // TODO: check queue type
3724 if (!(vma
->vm_flags
& VM_WRITE
)) {
3725 dprintk("mmap(): app bug: PROT_WRITE please\n");
3729 if (!(vma
->vm_flags
& VM_SHARED
)) {
3730 dprintk("mmap(): app bug: MAP_SHARED please\n");
3735 /* find the correct buffer using offset */
3736 length
= vino_queue_get_length(&vcs
->fb_queue
);
3738 dprintk("mmap(): queue not initialized\n");
3743 for (i
= 0; i
< length
; i
++) {
3744 fb
= vino_queue_get_buffer(&vcs
->fb_queue
, i
);
3746 dprintk("mmap(): vino_queue_get_buffer() failed\n");
3751 if (fb
->offset
== offset
)
3755 dprintk("mmap(): invalid offset = %lu\n", offset
);
3760 dprintk("mmap(): buffer = %d\n", i
);
3762 if (size
> (fb
->desc_table
.page_count
* PAGE_SIZE
)) {
3763 dprintk("mmap(): failed: size = %lu > %lu\n",
3764 size
, fb
->desc_table
.page_count
* PAGE_SIZE
);
3769 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++) {
3771 virt_to_phys((void *)fb
->desc_table
.virtual[i
]) >>
3774 if (size
< PAGE_SIZE
)
3777 // protection was: PAGE_READONLY
3778 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
,
3779 vma
->vm_page_prot
)) {
3780 dprintk("mmap(): remap_pfn_range() failed\n");
3791 vma
->vm_flags
|= VM_DONTEXPAND
| VM_RESERVED
;
3792 vma
->vm_flags
&= ~VM_IO
;
3793 vma
->vm_private_data
= fb
;
3794 vma
->vm_file
= file
;
3795 vma
->vm_ops
= &vino_vm_ops
;
3798 mutex_unlock(&vcs
->mutex
);
3803 static unsigned int vino_poll(struct file
*file
, poll_table
*pt
)
3805 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3806 unsigned int outgoing
;
3807 unsigned int ret
= 0;
3810 // TODO: this has to be corrected for different read modes
3812 dprintk("poll():\n");
3814 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3815 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3822 poll_wait(file
, &vcs
->fb_queue
.frame_wait_queue
, pt
);
3824 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3825 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3831 dprintk("poll(): data %savailable\n",
3832 (outgoing
> 0) ? "" : "not ");
3835 ret
= POLLIN
| POLLRDNORM
;
3841 static long vino_ioctl(struct file
*file
,
3842 unsigned int cmd
, unsigned long arg
)
3844 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3847 if (mutex_lock_interruptible(&vcs
->mutex
))
3850 ret
= video_ioctl2(file
, cmd
, arg
);
3852 mutex_unlock(&vcs
->mutex
);
3857 /* Initialization and cleanup */
3860 static int vino_init_stage
;
3862 const struct v4l2_ioctl_ops vino_ioctl_ops
= {
3863 .vidioc_enum_fmt_vid_cap
= vino_enum_fmt_vid_cap
,
3864 .vidioc_g_fmt_vid_cap
= vino_g_fmt_vid_cap
,
3865 .vidioc_s_fmt_vid_cap
= vino_s_fmt_vid_cap
,
3866 .vidioc_try_fmt_vid_cap
= vino_try_fmt_vid_cap
,
3867 .vidioc_querycap
= vino_querycap
,
3868 .vidioc_enum_input
= vino_enum_input
,
3869 .vidioc_g_input
= vino_g_input
,
3870 .vidioc_s_input
= vino_s_input
,
3871 .vidioc_g_std
= vino_g_std
,
3872 .vidioc_s_std
= vino_s_std
,
3873 .vidioc_querystd
= vino_querystd
,
3874 .vidioc_cropcap
= vino_cropcap
,
3875 .vidioc_s_crop
= vino_s_crop
,
3876 .vidioc_g_crop
= vino_g_crop
,
3877 .vidioc_s_parm
= vino_s_parm
,
3878 .vidioc_g_parm
= vino_g_parm
,
3879 .vidioc_reqbufs
= vino_reqbufs
,
3880 .vidioc_querybuf
= vino_querybuf
,
3881 .vidioc_qbuf
= vino_qbuf
,
3882 .vidioc_dqbuf
= vino_dqbuf
,
3883 .vidioc_streamon
= vino_streamon
,
3884 .vidioc_streamoff
= vino_streamoff
,
3885 .vidioc_queryctrl
= vino_queryctrl
,
3886 .vidioc_g_ctrl
= vino_g_ctrl
,
3887 .vidioc_s_ctrl
= vino_s_ctrl
,
3890 static const struct v4l2_file_operations vino_fops
= {
3891 .owner
= THIS_MODULE
,
3893 .release
= vino_close
,
3894 .unlocked_ioctl
= vino_ioctl
,
3899 static struct video_device vdev_template
= {
3902 .ioctl_ops
= &vino_ioctl_ops
,
3903 .tvnorms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
3906 static void vino_module_cleanup(int stage
)
3910 video_unregister_device(vino_drvdata
->b
.vdev
);
3911 vino_drvdata
->b
.vdev
= NULL
;
3913 video_unregister_device(vino_drvdata
->a
.vdev
);
3914 vino_drvdata
->a
.vdev
= NULL
;
3916 i2c_del_adapter(&vino_i2c_adapter
);
3918 free_irq(SGI_VINO_IRQ
, NULL
);
3920 if (vino_drvdata
->b
.vdev
) {
3921 video_device_release(vino_drvdata
->b
.vdev
);
3922 vino_drvdata
->b
.vdev
= NULL
;
3925 if (vino_drvdata
->a
.vdev
) {
3926 video_device_release(vino_drvdata
->a
.vdev
);
3927 vino_drvdata
->a
.vdev
= NULL
;
3930 /* all entries in dma_cpu dummy table have the same address */
3931 dma_unmap_single(NULL
,
3932 vino_drvdata
->dummy_desc_table
.dma_cpu
[0],
3933 PAGE_SIZE
, DMA_FROM_DEVICE
);
3934 dma_free_coherent(NULL
, VINO_DUMMY_DESC_COUNT
3935 * sizeof(dma_addr_t
),
3936 (void *)vino_drvdata
->
3937 dummy_desc_table
.dma_cpu
,
3938 vino_drvdata
->dummy_desc_table
.dma
);
3940 free_page(vino_drvdata
->dummy_page
);
3942 v4l2_device_unregister(&vino_drvdata
->v4l2_dev
);
3944 kfree(vino_drvdata
);
3950 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
3955 static int vino_probe(void)
3957 unsigned long rev_id
;
3959 if (ip22_is_fullhouse()) {
3960 printk(KERN_ERR
"VINO doesn't exist in IP22 Fullhouse\n");
3964 if (!(sgimc
->systemid
& SGIMC_SYSID_EPRESENT
)) {
3965 printk(KERN_ERR
"VINO is not found (EISA BUS not present)\n");
3969 vino
= (struct sgi_vino
*)ioremap(VINO_BASE
, sizeof(struct sgi_vino
));
3971 printk(KERN_ERR
"VINO: ioremap() failed\n");
3976 if (get_dbe(rev_id
, &(vino
->rev_id
))) {
3977 printk(KERN_ERR
"Failed to read VINO revision register\n");
3978 vino_module_cleanup(vino_init_stage
);
3982 if (VINO_ID_VALUE(rev_id
) != VINO_CHIP_ID
) {
3983 printk(KERN_ERR
"Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
3985 vino_module_cleanup(vino_init_stage
);
3989 printk(KERN_INFO
"VINO revision %ld found\n", VINO_REV_NUM(rev_id
));
3994 static int vino_init(void)
3996 dma_addr_t dma_dummy_address
;
4000 vino_drvdata
= kzalloc(sizeof(struct vino_settings
), GFP_KERNEL
);
4001 if (!vino_drvdata
) {
4002 vino_module_cleanup(vino_init_stage
);
4006 strlcpy(vino_drvdata
->v4l2_dev
.name
, "vino",
4007 sizeof(vino_drvdata
->v4l2_dev
.name
));
4008 err
= v4l2_device_register(NULL
, &vino_drvdata
->v4l2_dev
);
4013 /* create a dummy dma descriptor */
4014 vino_drvdata
->dummy_page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
4015 if (!vino_drvdata
->dummy_page
) {
4016 vino_module_cleanup(vino_init_stage
);
4021 // TODO: use page_count in dummy_desc_table
4023 vino_drvdata
->dummy_desc_table
.dma_cpu
=
4024 dma_alloc_coherent(NULL
,
4025 VINO_DUMMY_DESC_COUNT
* sizeof(dma_addr_t
),
4026 &vino_drvdata
->dummy_desc_table
.dma
,
4027 GFP_KERNEL
| GFP_DMA
);
4028 if (!vino_drvdata
->dummy_desc_table
.dma_cpu
) {
4029 vino_module_cleanup(vino_init_stage
);
4034 dma_dummy_address
= dma_map_single(NULL
,
4035 (void *)vino_drvdata
->dummy_page
,
4036 PAGE_SIZE
, DMA_FROM_DEVICE
);
4037 for (i
= 0; i
< VINO_DUMMY_DESC_COUNT
; i
++) {
4038 vino_drvdata
->dummy_desc_table
.dma_cpu
[i
] = dma_dummy_address
;
4041 /* initialize VINO */
4044 vino
->a
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4045 vino
->b
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4046 udelay(VINO_DESC_FETCH_DELAY
);
4048 vino
->intr_status
= 0;
4050 vino
->a
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4051 vino
->b
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4056 static int vino_init_channel_settings(struct vino_channel_settings
*vcs
,
4057 unsigned int channel
, const char *name
)
4059 vcs
->channel
= channel
;
4060 vcs
->input
= VINO_INPUT_NONE
;
4063 vcs
->data_format
= VINO_DATA_FMT_GREY
;
4064 vcs
->data_norm
= VINO_DATA_NORM_NTSC
;
4065 vcs
->decimation
= 1;
4066 vino_set_default_clipping(vcs
);
4067 vino_set_default_framerate(vcs
);
4071 mutex_init(&vcs
->mutex
);
4072 spin_lock_init(&vcs
->capture_lock
);
4074 mutex_init(&vcs
->fb_queue
.queue_mutex
);
4075 spin_lock_init(&vcs
->fb_queue
.queue_lock
);
4076 init_waitqueue_head(&vcs
->fb_queue
.frame_wait_queue
);
4078 vcs
->vdev
= video_device_alloc();
4080 vino_module_cleanup(vino_init_stage
);
4085 memcpy(vcs
->vdev
, &vdev_template
,
4086 sizeof(struct video_device
));
4087 strcpy(vcs
->vdev
->name
, name
);
4088 vcs
->vdev
->release
= video_device_release
;
4089 vcs
->vdev
->v4l2_dev
= &vino_drvdata
->v4l2_dev
;
4091 video_set_drvdata(vcs
->vdev
, vcs
);
4096 static int __init
vino_module_init(void)
4100 printk(KERN_INFO
"SGI VINO driver version %s\n",
4101 VINO_MODULE_VERSION
);
4111 /* initialize data structures */
4113 spin_lock_init(&vino_drvdata
->vino_lock
);
4114 spin_lock_init(&vino_drvdata
->input_lock
);
4116 ret
= vino_init_channel_settings(&vino_drvdata
->a
, VINO_CHANNEL_A
,
4121 ret
= vino_init_channel_settings(&vino_drvdata
->b
, VINO_CHANNEL_B
,
4126 /* initialize hardware and register V4L devices */
4128 ret
= request_irq(SGI_VINO_IRQ
, vino_interrupt
, 0,
4129 vino_driver_description
, NULL
);
4131 printk(KERN_ERR
"VINO: requesting IRQ %02d failed\n",
4133 vino_module_cleanup(vino_init_stage
);
4138 ret
= i2c_add_adapter(&vino_i2c_adapter
);
4140 printk(KERN_ERR
"VINO I2C bus registration failed\n");
4141 vino_module_cleanup(vino_init_stage
);
4144 i2c_set_adapdata(&vino_i2c_adapter
, &vino_drvdata
->v4l2_dev
);
4147 ret
= video_register_device(vino_drvdata
->a
.vdev
,
4148 VFL_TYPE_GRABBER
, -1);
4150 printk(KERN_ERR
"VINO channel A Video4Linux-device "
4151 "registration failed\n");
4152 vino_module_cleanup(vino_init_stage
);
4157 ret
= video_register_device(vino_drvdata
->b
.vdev
,
4158 VFL_TYPE_GRABBER
, -1);
4160 printk(KERN_ERR
"VINO channel B Video4Linux-device "
4161 "registration failed\n");
4162 vino_module_cleanup(vino_init_stage
);
4167 vino_drvdata
->decoder
=
4168 v4l2_i2c_new_subdev(&vino_drvdata
->v4l2_dev
, &vino_i2c_adapter
,
4169 "saa7191", "saa7191", 0, I2C_ADDRS(0x45));
4170 vino_drvdata
->camera
=
4171 v4l2_i2c_new_subdev(&vino_drvdata
->v4l2_dev
, &vino_i2c_adapter
,
4172 "indycam", "indycam", 0, I2C_ADDRS(0x2b));
4174 dprintk("init complete!\n");
4179 static void __exit
vino_module_exit(void)
4181 dprintk("exiting, stage = %d ...\n", vino_init_stage
);
4182 vino_module_cleanup(vino_init_stage
);
4183 dprintk("cleanup complete, exit!\n");
4186 module_init(vino_module_init
);
4187 module_exit(vino_module_exit
);