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
, // XXX: swapped?
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 /* user buffers not fully implemented yet */
780 static int vino_prepare_user_buffer(struct vino_framebuffer
*fb
,
784 unsigned int count
, i
, j
;
787 dprintk("vino_prepare_user_buffer():\n");
792 memset(fb
, 0, sizeof(struct vino_framebuffer
));
794 count
= ((size
/ PAGE_SIZE
)) & ~3;
796 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
799 /* allocate memory for table with virtual (page) addresses */
800 fb
->desc_table
.virtual = (unsigned long *)
801 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
802 if (!fb
->desc_table
.virtual)
805 /* allocate memory for table with dma addresses
806 * (has space for four extra descriptors) */
807 fb
->desc_table
.dma_cpu
=
808 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
809 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
810 GFP_KERNEL
| GFP_DMA
);
811 if (!fb
->desc_table
.dma_cpu
) {
813 goto out_free_virtual
;
816 /* allocate pages for the buffer and acquire the according
818 for (i
= 0; i
< count
; i
++) {
819 dma_addr_t dma_data_addr
;
821 fb
->desc_table
.virtual[i
] =
822 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
823 if (!fb
->desc_table
.virtual[i
]) {
830 (void *)fb
->desc_table
.virtual[i
],
831 PAGE_SIZE
, DMA_FROM_DEVICE
);
833 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
834 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
835 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
838 SetPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
841 /* page_count needs to be set anyway, because the descriptor table has
842 * been allocated according to this number */
843 fb
->desc_table
.page_count
= count
;
846 /* the descriptor with index i doesn't contain
847 * a valid address yet */
848 vino_free_buffer_with_count(fb
, i
);
853 fb
->size
= count
* PAGE_SIZE
;
855 /* set the dma stop-bit for the last (count+1)th descriptor */
856 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
860 kfree(fb
->desc_table
.virtual);
865 static void vino_sync_buffer(struct vino_framebuffer
*fb
)
869 dprintk("vino_sync_buffer():\n");
871 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++)
872 dma_sync_single_for_cpu(NULL
,
873 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
874 PAGE_SIZE
, DMA_FROM_DEVICE
);
877 /* Framebuffer fifo functions (need to be locked externally) */
879 static inline void vino_fifo_init(struct vino_framebuffer_fifo
*f
,
887 if (length
> VINO_FRAMEBUFFER_COUNT_MAX
)
888 length
= VINO_FRAMEBUFFER_COUNT_MAX
;
893 /* returns true/false */
894 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo
*f
,
899 for (i
= f
->head
; i
== (f
->tail
- 1); i
= (i
+ 1) % f
->length
) {
900 if (f
->data
[i
] == id
)
908 /* returns true/false */
909 static inline int vino_fifo_full(struct vino_framebuffer_fifo
*f
)
911 return (f
->used
== f
->length
);
915 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo
*f
)
920 static int vino_fifo_enqueue(struct vino_framebuffer_fifo
*f
, unsigned int id
)
922 if (id
>= f
->length
) {
923 return VINO_QUEUE_ERROR
;
926 if (vino_fifo_has_id(f
, id
)) {
927 return VINO_QUEUE_ERROR
;
930 if (f
->used
< f
->length
) {
931 f
->data
[f
->tail
] = id
;
932 f
->tail
= (f
->tail
+ 1) % f
->length
;
935 return VINO_QUEUE_ERROR
;
941 static int vino_fifo_peek(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
944 *id
= f
->data
[f
->head
];
946 return VINO_QUEUE_ERROR
;
952 static int vino_fifo_dequeue(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
955 *id
= f
->data
[f
->head
];
956 f
->head
= (f
->head
+ 1) % f
->length
;
959 return VINO_QUEUE_ERROR
;
965 /* Framebuffer queue functions */
967 /* execute with queue_lock locked */
968 static void vino_queue_free_with_count(struct vino_framebuffer_queue
*q
,
974 memset(&q
->in
, 0, sizeof(struct vino_framebuffer_fifo
));
975 memset(&q
->out
, 0, sizeof(struct vino_framebuffer_fifo
));
976 for (i
= 0; i
< length
; i
++) {
977 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
979 vino_free_buffer(q
->buffer
[i
]);
983 q
->type
= VINO_MEMORY_NONE
;
987 static void vino_queue_free(struct vino_framebuffer_queue
*q
)
989 dprintk("vino_queue_free():\n");
991 if (q
->magic
!= VINO_QUEUE_MAGIC
)
993 if (q
->type
!= VINO_MEMORY_MMAP
)
996 mutex_lock(&q
->queue_mutex
);
998 vino_queue_free_with_count(q
, q
->length
);
1000 mutex_unlock(&q
->queue_mutex
);
1003 static int vino_queue_init(struct vino_framebuffer_queue
*q
,
1004 unsigned int *length
)
1009 dprintk("vino_queue_init(): length = %d\n", *length
);
1011 if (q
->magic
== VINO_QUEUE_MAGIC
) {
1012 dprintk("vino_queue_init(): queue already initialized!\n");
1016 if (q
->type
!= VINO_MEMORY_NONE
) {
1017 dprintk("vino_queue_init(): queue already initialized!\n");
1024 mutex_lock(&q
->queue_mutex
);
1026 if (*length
> VINO_FRAMEBUFFER_COUNT_MAX
)
1027 *length
= VINO_FRAMEBUFFER_COUNT_MAX
;
1031 for (i
= 0; i
< *length
; i
++) {
1032 dprintk("vino_queue_init(): allocating buffer %d\n", i
);
1033 q
->buffer
[i
] = kmalloc(sizeof(struct vino_framebuffer
),
1035 if (!q
->buffer
[i
]) {
1036 dprintk("vino_queue_init(): kmalloc() failed\n");
1041 ret
= vino_allocate_buffer(q
->buffer
[i
],
1042 VINO_FRAMEBUFFER_SIZE
);
1044 kfree(q
->buffer
[i
]);
1045 dprintk("vino_queue_init(): "
1046 "vino_allocate_buffer() failed\n");
1050 q
->buffer
[i
]->id
= i
;
1052 q
->buffer
[i
]->offset
= q
->buffer
[i
- 1]->offset
+
1053 q
->buffer
[i
- 1]->size
;
1055 q
->buffer
[i
]->offset
= 0;
1058 spin_lock_init(&q
->buffer
[i
]->state_lock
);
1060 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1061 "size = %d\n", i
, q
->buffer
[i
]->offset
,
1062 q
->buffer
[i
]->size
);
1066 vino_queue_free_with_count(q
, i
);
1069 q
->length
= *length
;
1070 vino_fifo_init(&q
->in
, q
->length
);
1071 vino_fifo_init(&q
->out
, q
->length
);
1072 q
->type
= VINO_MEMORY_MMAP
;
1073 q
->magic
= VINO_QUEUE_MAGIC
;
1076 mutex_unlock(&q
->queue_mutex
);
1081 static struct vino_framebuffer
*vino_queue_add(struct
1082 vino_framebuffer_queue
*q
,
1085 struct vino_framebuffer
*ret
= NULL
;
1087 unsigned long flags
;
1089 dprintk("vino_queue_add(): id = %d\n", id
);
1091 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1095 spin_lock_irqsave(&q
->queue_lock
, flags
);
1100 if (id
>= q
->length
)
1103 /* not needed?: if (vino_fifo_full(&q->out)) {
1106 /* check that outgoing queue isn't already full
1107 * (or that it won't become full) */
1108 total
= vino_fifo_get_used(&q
->in
) +
1109 vino_fifo_get_used(&q
->out
);
1110 if (total
>= q
->length
)
1113 if (vino_fifo_enqueue(&q
->in
, id
))
1116 ret
= q
->buffer
[id
];
1119 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1124 static struct vino_framebuffer
*vino_queue_transfer(struct
1125 vino_framebuffer_queue
*q
)
1127 struct vino_framebuffer
*ret
= NULL
;
1128 struct vino_framebuffer
*fb
;
1130 unsigned long flags
;
1132 dprintk("vino_queue_transfer():\n");
1134 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1138 spin_lock_irqsave(&q
->queue_lock
, flags
);
1143 // now this actually removes an entry from the incoming queue
1144 if (vino_fifo_dequeue(&q
->in
, &id
)) {
1148 dprintk("vino_queue_transfer(): id = %d\n", id
);
1151 // we have already checked that the outgoing queue is not full, but...
1152 if (vino_fifo_enqueue(&q
->out
, id
)) {
1153 printk(KERN_ERR
"vino_queue_transfer(): "
1154 "outgoing queue is full, this shouldn't happen!\n");
1160 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1165 /* returns true/false */
1166 static int vino_queue_incoming_contains(struct vino_framebuffer_queue
*q
,
1170 unsigned long flags
;
1172 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1176 spin_lock_irqsave(&q
->queue_lock
, flags
);
1181 ret
= vino_fifo_has_id(&q
->in
, id
);
1184 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1189 /* returns true/false */
1190 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue
*q
,
1194 unsigned long flags
;
1196 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1200 spin_lock_irqsave(&q
->queue_lock
, flags
);
1205 ret
= vino_fifo_has_id(&q
->out
, id
);
1208 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1213 static int vino_queue_get_incoming(struct vino_framebuffer_queue
*q
,
1217 unsigned long flags
;
1219 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1220 return VINO_QUEUE_ERROR
;
1223 spin_lock_irqsave(&q
->queue_lock
, flags
);
1225 if (q
->length
== 0) {
1226 ret
= VINO_QUEUE_ERROR
;
1230 *used
= vino_fifo_get_used(&q
->in
);
1233 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1238 static int vino_queue_get_outgoing(struct vino_framebuffer_queue
*q
,
1242 unsigned long flags
;
1244 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1245 return VINO_QUEUE_ERROR
;
1248 spin_lock_irqsave(&q
->queue_lock
, flags
);
1250 if (q
->length
== 0) {
1251 ret
= VINO_QUEUE_ERROR
;
1255 *used
= vino_fifo_get_used(&q
->out
);
1258 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1264 static int vino_queue_get_total(struct vino_framebuffer_queue
*q
,
1265 unsigned int *total
)
1268 unsigned long flags
;
1270 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1271 return VINO_QUEUE_ERROR
;
1274 spin_lock_irqsave(&q
->queue_lock
, flags
);
1276 if (q
->length
== 0) {
1277 ret
= VINO_QUEUE_ERROR
;
1281 *total
= vino_fifo_get_used(&q
->in
) +
1282 vino_fifo_get_used(&q
->out
);
1285 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1291 static struct vino_framebuffer
*vino_queue_peek(struct
1292 vino_framebuffer_queue
*q
,
1295 struct vino_framebuffer
*ret
= NULL
;
1296 unsigned long flags
;
1298 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1302 spin_lock_irqsave(&q
->queue_lock
, flags
);
1307 if (vino_fifo_peek(&q
->in
, id
)) {
1311 ret
= q
->buffer
[*id
];
1313 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1318 static struct vino_framebuffer
*vino_queue_remove(struct
1319 vino_framebuffer_queue
*q
,
1322 struct vino_framebuffer
*ret
= NULL
;
1323 unsigned long flags
;
1324 dprintk("vino_queue_remove():\n");
1326 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1330 spin_lock_irqsave(&q
->queue_lock
, flags
);
1335 if (vino_fifo_dequeue(&q
->out
, id
)) {
1339 dprintk("vino_queue_remove(): id = %d\n", *id
);
1340 ret
= q
->buffer
[*id
];
1342 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1348 vino_framebuffer
*vino_queue_get_buffer(struct vino_framebuffer_queue
*q
,
1351 struct vino_framebuffer
*ret
= NULL
;
1352 unsigned long flags
;
1354 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1358 spin_lock_irqsave(&q
->queue_lock
, flags
);
1363 if (id
>= q
->length
)
1366 ret
= q
->buffer
[id
];
1368 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1373 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue
*q
)
1375 unsigned int length
= 0;
1376 unsigned long flags
;
1378 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1382 spin_lock_irqsave(&q
->queue_lock
, flags
);
1384 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1389 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue
*q
)
1393 unsigned long flags
;
1395 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1399 spin_lock_irqsave(&q
->queue_lock
, flags
);
1400 for (i
= 0; i
< q
->length
; i
++) {
1401 if (q
->buffer
[i
]->map_count
> 0) {
1406 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1411 /* VINO functions */
1413 /* execute with input_lock locked */
1414 static void vino_update_line_size(struct vino_channel_settings
*vcs
)
1416 unsigned int w
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1417 unsigned int d
= vcs
->decimation
;
1418 unsigned int bpp
= vino_data_formats
[vcs
->data_format
].bpp
;
1421 dprintk("update_line_size(): before: w = %d, d = %d, "
1422 "line_size = %d\n", w
, d
, vcs
->line_size
);
1424 /* line size must be multiple of 8 bytes */
1425 lsize
= (bpp
* (w
/ d
)) & ~7;
1426 w
= (lsize
/ bpp
) * d
;
1428 vcs
->clipping
.right
= vcs
->clipping
.left
+ w
;
1429 vcs
->line_size
= lsize
;
1431 dprintk("update_line_size(): after: w = %d, d = %d, "
1432 "line_size = %d\n", w
, d
, vcs
->line_size
);
1435 /* execute with input_lock locked */
1436 static void vino_set_clipping(struct vino_channel_settings
*vcs
,
1437 unsigned int x
, unsigned int y
,
1438 unsigned int w
, unsigned int h
)
1440 unsigned int maxwidth
, maxheight
;
1443 maxwidth
= vino_data_norms
[vcs
->data_norm
].width
;
1444 maxheight
= vino_data_norms
[vcs
->data_norm
].height
;
1445 d
= vcs
->decimation
;
1447 y
&= ~1; /* odd/even fields */
1452 if (y
> maxheight
) {
1456 if (((w
/ d
) < VINO_MIN_WIDTH
)
1457 || ((h
/ d
) < VINO_MIN_HEIGHT
)) {
1458 w
= VINO_MIN_WIDTH
* d
;
1459 h
= VINO_MIN_HEIGHT
* d
;
1462 if ((x
+ w
) > maxwidth
) {
1464 if ((w
/ d
) < VINO_MIN_WIDTH
)
1465 x
= maxwidth
- VINO_MIN_WIDTH
* d
;
1467 if ((y
+ h
) > maxheight
) {
1469 if ((h
/ d
) < VINO_MIN_HEIGHT
)
1470 y
= maxheight
- VINO_MIN_HEIGHT
* d
;
1473 vcs
->clipping
.left
= x
;
1474 vcs
->clipping
.top
= y
;
1475 vcs
->clipping
.right
= x
+ w
;
1476 vcs
->clipping
.bottom
= y
+ h
;
1478 vino_update_line_size(vcs
);
1480 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1481 vcs
->clipping
.left
, vcs
->clipping
.top
, vcs
->clipping
.right
,
1482 vcs
->clipping
.bottom
, vcs
->decimation
, vcs
->line_size
);
1485 /* execute with input_lock locked */
1486 static inline void vino_set_default_clipping(struct vino_channel_settings
*vcs
)
1488 vino_set_clipping(vcs
, 0, 0, vino_data_norms
[vcs
->data_norm
].width
,
1489 vino_data_norms
[vcs
->data_norm
].height
);
1492 /* execute with input_lock locked */
1493 static void vino_set_scaling(struct vino_channel_settings
*vcs
,
1494 unsigned int w
, unsigned int h
)
1496 unsigned int x
, y
, curw
, curh
, d
;
1498 x
= vcs
->clipping
.left
;
1499 y
= vcs
->clipping
.top
;
1500 curw
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1501 curh
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
1503 d
= max(curw
/ w
, curh
/ h
);
1505 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1506 w
, h
, curw
, curh
, d
);
1514 vcs
->decimation
= d
;
1515 vino_set_clipping(vcs
, x
, y
, w
* d
, h
* d
);
1517 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs
->clipping
.left
,
1518 vcs
->clipping
.top
, vcs
->clipping
.right
, vcs
->clipping
.bottom
,
1519 vcs
->decimation
, vcs
->line_size
);
1522 /* execute with input_lock locked */
1523 static inline void vino_set_default_scaling(struct vino_channel_settings
*vcs
)
1525 vino_set_scaling(vcs
, vcs
->clipping
.right
- vcs
->clipping
.left
,
1526 vcs
->clipping
.bottom
- vcs
->clipping
.top
);
1529 /* execute with input_lock locked */
1530 static void vino_set_framerate(struct vino_channel_settings
*vcs
,
1535 switch (vcs
->data_norm
) {
1536 case VINO_DATA_NORM_NTSC
:
1537 case VINO_DATA_NORM_D1
:
1538 fps
= (unsigned int)(fps
/ 6) * 6; // FIXME: round!
1540 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1541 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1542 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1543 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1562 mask
= VINO_FRAMERT_FULL
;
1564 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
);
1566 case VINO_DATA_NORM_PAL
:
1567 case VINO_DATA_NORM_SECAM
:
1568 fps
= (unsigned int)(fps
/ 5) * 5; // 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
) | VINO_FRAMERT_PAL
;
1601 /* execute with input_lock locked */
1602 static inline void vino_set_default_framerate(struct
1603 vino_channel_settings
*vcs
)
1605 vino_set_framerate(vcs
, vino_data_norms
[vcs
->data_norm
].fps_max
);
1608 /* VINO I2C bus functions */
1610 struct i2c_algo_sgi_data
{
1611 void *data
; /* private data for lowlevel routines */
1612 unsigned (*getctrl
)(void *data
);
1613 void (*setctrl
)(void *data
, unsigned val
);
1614 unsigned (*rdata
)(void *data
);
1615 void (*wdata
)(void *data
, unsigned val
);
1621 static int wait_xfer_done(struct i2c_algo_sgi_data
*adap
)
1625 for (i
= 0; i
< adap
->xfer_timeout
; i
++) {
1626 if ((adap
->getctrl(adap
->data
) & SGI_I2C_XFER_BUSY
) == 0)
1634 static int wait_ack(struct i2c_algo_sgi_data
*adap
)
1638 if (wait_xfer_done(adap
))
1640 for (i
= 0; i
< adap
->ack_timeout
; i
++) {
1641 if ((adap
->getctrl(adap
->data
) & SGI_I2C_NACK
) == 0)
1649 static int force_idle(struct i2c_algo_sgi_data
*adap
)
1653 adap
->setctrl(adap
->data
, SGI_I2C_FORCE_IDLE
);
1654 for (i
= 0; i
< adap
->xfer_timeout
; i
++) {
1655 if ((adap
->getctrl(adap
->data
) & SGI_I2C_NOT_IDLE
) == 0)
1661 if (adap
->getctrl(adap
->data
) & SGI_I2C_BUS_ERR
)
1666 static int do_address(struct i2c_algo_sgi_data
*adap
, unsigned int addr
,
1670 adap
->setctrl(adap
->data
, SGI_I2C_NOT_IDLE
);
1671 /* Check if bus is idle, eventually force it to do so */
1672 if (adap
->getctrl(adap
->data
) & SGI_I2C_NOT_IDLE
)
1673 if (force_idle(adap
))
1675 /* Write out the i2c chip address and specify operation */
1676 adap
->setctrl(adap
->data
,
1677 SGI_I2C_HOLD_BUS
| SGI_I2C_WRITE
| SGI_I2C_NOT_IDLE
);
1680 adap
->wdata(adap
->data
, addr
);
1686 static int i2c_read(struct i2c_algo_sgi_data
*adap
, unsigned char *buf
,
1691 adap
->setctrl(adap
->data
,
1692 SGI_I2C_HOLD_BUS
| SGI_I2C_READ
| SGI_I2C_NOT_IDLE
);
1693 for (i
= 0; i
< len
; i
++) {
1694 if (wait_xfer_done(adap
))
1696 buf
[i
] = adap
->rdata(adap
->data
);
1698 adap
->setctrl(adap
->data
, SGI_I2C_RELEASE_BUS
| SGI_I2C_FORCE_IDLE
);
1704 static int i2c_write(struct i2c_algo_sgi_data
*adap
, unsigned char *buf
,
1709 /* We are already in write state */
1710 for (i
= 0; i
< len
; i
++) {
1711 adap
->wdata(adap
->data
, buf
[i
]);
1718 static int sgi_xfer(struct i2c_adapter
*i2c_adap
, struct i2c_msg
*msgs
,
1721 struct i2c_algo_sgi_data
*adap
= i2c_adap
->algo_data
;
1725 for (i
= 0; !err
&& i
< num
; i
++) {
1727 err
= do_address(adap
, p
->addr
, p
->flags
& I2C_M_RD
);
1730 if (p
->flags
& I2C_M_RD
)
1731 err
= i2c_read(adap
, p
->buf
, p
->len
);
1733 err
= i2c_write(adap
, p
->buf
, p
->len
);
1736 return (err
< 0) ? err
: i
;
1739 static u32
sgi_func(struct i2c_adapter
*adap
)
1741 return I2C_FUNC_SMBUS_EMUL
;
1744 static const struct i2c_algorithm sgi_algo
= {
1745 .master_xfer
= sgi_xfer
,
1746 .functionality
= sgi_func
,
1749 static unsigned i2c_vino_getctrl(void *data
)
1751 return vino
->i2c_control
;
1754 static void i2c_vino_setctrl(void *data
, unsigned val
)
1756 vino
->i2c_control
= val
;
1759 static unsigned i2c_vino_rdata(void *data
)
1761 return vino
->i2c_data
;
1764 static void i2c_vino_wdata(void *data
, unsigned val
)
1766 vino
->i2c_data
= val
;
1769 static struct i2c_algo_sgi_data i2c_sgi_vino_data
= {
1770 .getctrl
= &i2c_vino_getctrl
,
1771 .setctrl
= &i2c_vino_setctrl
,
1772 .rdata
= &i2c_vino_rdata
,
1773 .wdata
= &i2c_vino_wdata
,
1774 .xfer_timeout
= 200,
1775 .ack_timeout
= 1000,
1778 static struct i2c_adapter vino_i2c_adapter
= {
1779 .name
= "VINO I2C bus",
1781 .algo_data
= &i2c_sgi_vino_data
,
1782 .owner
= THIS_MODULE
,
1786 * Prepare VINO for DMA transfer...
1787 * (execute only with vino_lock and input_lock locked)
1789 static int vino_dma_setup(struct vino_channel_settings
*vcs
,
1790 struct vino_framebuffer
*fb
)
1793 struct sgi_vino_channel
*ch
;
1794 const struct vino_data_norm
*norm
;
1796 dprintk("vino_dma_setup():\n");
1799 fb
->frame_counter
= 0;
1801 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1802 norm
= &vino_data_norms
[vcs
->data_norm
];
1807 /* VINO line size register is set 8 bytes less than actual */
1808 ch
->line_size
= vcs
->line_size
- 8;
1810 /* let VINO know where to transfer data */
1811 ch
->start_desc_tbl
= fb
->desc_table
.dma
;
1812 ch
->next_4_desc
= fb
->desc_table
.dma
;
1814 /* give vino time to fetch the first four descriptors, 5 usec
1815 * should be more than enough time */
1816 udelay(VINO_DESC_FETCH_DELAY
);
1818 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1819 ch
->start_desc_tbl
, ch
->next_4_desc
);
1821 /* set the alpha register */
1822 ch
->alpha
= vcs
->alpha
;
1824 /* set clipping registers */
1825 ch
->clip_start
= VINO_CLIP_ODD(norm
->odd
.top
+ vcs
->clipping
.top
/ 2) |
1826 VINO_CLIP_EVEN(norm
->even
.top
+
1827 vcs
->clipping
.top
/ 2) |
1828 VINO_CLIP_X(vcs
->clipping
.left
);
1829 ch
->clip_end
= VINO_CLIP_ODD(norm
->odd
.top
+
1830 vcs
->clipping
.bottom
/ 2 - 1) |
1831 VINO_CLIP_EVEN(norm
->even
.top
+
1832 vcs
->clipping
.bottom
/ 2 - 1) |
1833 VINO_CLIP_X(vcs
->clipping
.right
);
1835 /* set the size of actual content in the buffer (DECIMATION !) */
1836 fb
->data_size
= ((vcs
->clipping
.right
- vcs
->clipping
.left
) /
1838 ((vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
1840 vino_data_formats
[vcs
->data_format
].bpp
;
1842 ch
->frame_rate
= vcs
->framert_reg
;
1844 ctrl
= vino
->control
;
1845 intr
= vino
->intr_status
;
1847 if (vcs
->channel
== VINO_CHANNEL_A
) {
1848 /* All interrupt conditions for this channel was cleared
1849 * so clear the interrupt status register and enable
1851 intr
&= ~VINO_INTSTAT_A
;
1852 ctrl
|= VINO_CTRL_A_INT
;
1854 /* enable synchronization */
1855 ctrl
|= VINO_CTRL_A_SYNC_ENBL
;
1857 /* enable frame assembly */
1858 ctrl
|= VINO_CTRL_A_INTERLEAVE_ENBL
;
1860 /* set decimation used */
1861 if (vcs
->decimation
< 2)
1862 ctrl
&= ~VINO_CTRL_A_DEC_ENBL
;
1864 ctrl
|= VINO_CTRL_A_DEC_ENBL
;
1865 ctrl
&= ~VINO_CTRL_A_DEC_SCALE_MASK
;
1866 ctrl
|= (vcs
->decimation
- 1) <<
1867 VINO_CTRL_A_DEC_SCALE_SHIFT
;
1870 /* select input interface */
1871 if (vcs
->input
== VINO_INPUT_D1
)
1872 ctrl
|= VINO_CTRL_A_SELECT
;
1874 ctrl
&= ~VINO_CTRL_A_SELECT
;
1877 ctrl
&= ~(VINO_CTRL_A_LUMA_ONLY
| VINO_CTRL_A_RGB
|
1878 VINO_CTRL_A_DITHER
);
1880 intr
&= ~VINO_INTSTAT_B
;
1881 ctrl
|= VINO_CTRL_B_INT
;
1883 ctrl
|= VINO_CTRL_B_SYNC_ENBL
;
1884 ctrl
|= VINO_CTRL_B_INTERLEAVE_ENBL
;
1886 if (vcs
->decimation
< 2)
1887 ctrl
&= ~VINO_CTRL_B_DEC_ENBL
;
1889 ctrl
|= VINO_CTRL_B_DEC_ENBL
;
1890 ctrl
&= ~VINO_CTRL_B_DEC_SCALE_MASK
;
1891 ctrl
|= (vcs
->decimation
- 1) <<
1892 VINO_CTRL_B_DEC_SCALE_SHIFT
;
1895 if (vcs
->input
== VINO_INPUT_D1
)
1896 ctrl
|= VINO_CTRL_B_SELECT
;
1898 ctrl
&= ~VINO_CTRL_B_SELECT
;
1900 ctrl
&= ~(VINO_CTRL_B_LUMA_ONLY
| VINO_CTRL_B_RGB
|
1901 VINO_CTRL_B_DITHER
);
1905 fb
->data_format
= vcs
->data_format
;
1907 switch (vcs
->data_format
) {
1908 case VINO_DATA_FMT_GREY
:
1909 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1910 VINO_CTRL_A_LUMA_ONLY
: VINO_CTRL_B_LUMA_ONLY
;
1912 case VINO_DATA_FMT_RGB32
:
1913 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1914 VINO_CTRL_A_RGB
: VINO_CTRL_B_RGB
;
1916 case VINO_DATA_FMT_YUV
:
1917 /* nothing needs to be done */
1919 case VINO_DATA_FMT_RGB332
:
1920 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1921 VINO_CTRL_A_RGB
| VINO_CTRL_A_DITHER
:
1922 VINO_CTRL_B_RGB
| VINO_CTRL_B_DITHER
;
1926 vino
->intr_status
= intr
;
1927 vino
->control
= ctrl
;
1932 /* (execute only with vino_lock locked) */
1933 static inline void vino_dma_start(struct vino_channel_settings
*vcs
)
1935 u32 ctrl
= vino
->control
;
1937 dprintk("vino_dma_start():\n");
1938 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1939 VINO_CTRL_A_DMA_ENBL
: VINO_CTRL_B_DMA_ENBL
;
1940 vino
->control
= ctrl
;
1943 /* (execute only with vino_lock locked) */
1944 static inline void vino_dma_stop(struct vino_channel_settings
*vcs
)
1946 u32 ctrl
= vino
->control
;
1948 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1949 ~VINO_CTRL_A_DMA_ENBL
: ~VINO_CTRL_B_DMA_ENBL
;
1950 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1951 ~VINO_CTRL_A_INT
: ~VINO_CTRL_B_INT
;
1952 vino
->control
= ctrl
;
1953 dprintk("vino_dma_stop():\n");
1957 * Load dummy page to descriptor registers. This prevents generating of
1958 * spurious interrupts. (execute only with vino_lock locked)
1960 static void vino_clear_interrupt(struct vino_channel_settings
*vcs
)
1962 struct sgi_vino_channel
*ch
;
1964 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1969 ch
->start_desc_tbl
= vino_drvdata
->dummy_desc_table
.dma
;
1970 ch
->next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
1972 udelay(VINO_DESC_FETCH_DELAY
);
1973 dprintk("channel %c clear interrupt condition\n",
1974 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A':'B');
1977 static int vino_capture(struct vino_channel_settings
*vcs
,
1978 struct vino_framebuffer
*fb
)
1981 unsigned long flags
, flags2
;
1983 spin_lock_irqsave(&fb
->state_lock
, flags
);
1985 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
1987 fb
->state
= VINO_FRAMEBUFFER_IN_USE
;
1989 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
1994 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
1995 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags2
);
1997 vino_dma_setup(vcs
, fb
);
1998 vino_dma_start(vcs
);
2000 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags2
);
2001 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2007 struct vino_framebuffer
*vino_capture_enqueue(struct
2008 vino_channel_settings
*vcs
,
2011 struct vino_framebuffer
*fb
;
2012 unsigned long flags
;
2014 dprintk("vino_capture_enqueue():\n");
2016 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2018 fb
= vino_queue_add(&vcs
->fb_queue
, index
);
2020 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
2025 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2030 static int vino_capture_next(struct vino_channel_settings
*vcs
, int start
)
2032 struct vino_framebuffer
*fb
;
2033 unsigned int incoming
, id
;
2035 unsigned long flags
;
2037 dprintk("vino_capture_next():\n");
2039 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2042 /* start capture only if capture isn't in progress already */
2043 if (vcs
->capturing
) {
2044 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2049 /* capture next frame:
2050 * stop capture if capturing is not set */
2051 if (!vcs
->capturing
) {
2052 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2057 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
2059 dprintk("vino_capture_next(): vino_queue_get_incoming() "
2064 if (incoming
== 0) {
2065 dprintk("vino_capture_next(): no buffers available\n");
2069 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2071 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
2080 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2082 err
= vino_capture(vcs
, fb
);
2088 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2093 static inline int vino_is_capturing(struct vino_channel_settings
*vcs
)
2096 unsigned long flags
;
2098 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2100 ret
= vcs
->capturing
;
2102 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2107 /* waits until a frame is captured */
2108 static int vino_wait_for_frame(struct vino_channel_settings
*vcs
)
2113 dprintk("vino_wait_for_frame():\n");
2115 init_waitqueue_entry(&wait
, current
);
2116 /* add ourselves into wait queue */
2117 add_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2119 /* to ensure that schedule_timeout will return immediately
2120 * if VINO interrupt was triggered meanwhile */
2121 schedule_timeout_interruptible(msecs_to_jiffies(100));
2123 if (signal_pending(current
))
2126 remove_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2128 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2129 err
? "failed" : "ok");
2134 /* the function assumes that PAGE_SIZE % 4 == 0 */
2135 static void vino_convert_to_rgba(struct vino_framebuffer
*fb
) {
2136 unsigned char *pageptr
;
2137 unsigned int page
, i
;
2140 for (page
= 0; page
< fb
->desc_table
.page_count
; page
++) {
2141 pageptr
= (unsigned char *)fb
->desc_table
.virtual[page
];
2143 for (i
= 0; i
< PAGE_SIZE
; i
+= 4) {
2145 pageptr
[0] = pageptr
[3];
2146 pageptr
[1] = pageptr
[2];
2147 pageptr
[2] = pageptr
[1];
2154 /* checks if the buffer is in correct state and syncs data */
2155 static int vino_check_buffer(struct vino_channel_settings
*vcs
,
2156 struct vino_framebuffer
*fb
)
2159 unsigned long flags
;
2161 dprintk("vino_check_buffer():\n");
2163 spin_lock_irqsave(&fb
->state_lock
, flags
);
2164 switch (fb
->state
) {
2165 case VINO_FRAMEBUFFER_IN_USE
:
2168 case VINO_FRAMEBUFFER_READY
:
2169 vino_sync_buffer(fb
);
2170 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2175 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2178 if (vino_pixel_conversion
2179 && (fb
->data_format
== VINO_DATA_FMT_RGB32
)) {
2180 vino_convert_to_rgba(fb
);
2182 } else if (err
&& (err
!= -EINVAL
)) {
2183 dprintk("vino_check_buffer(): buffer not ready\n");
2185 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2187 vino_clear_interrupt(vcs
);
2188 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2194 /* forcefully terminates capture */
2195 static void vino_capture_stop(struct vino_channel_settings
*vcs
)
2197 unsigned int incoming
= 0, outgoing
= 0, id
;
2198 unsigned long flags
, flags2
;
2200 dprintk("vino_capture_stop():\n");
2202 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2204 /* unset capturing to stop queue processing */
2207 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags2
);
2210 vino_clear_interrupt(vcs
);
2212 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags2
);
2214 /* remove all items from the queue */
2215 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2216 dprintk("vino_capture_stop(): "
2217 "vino_queue_get_incoming() failed\n");
2220 while (incoming
> 0) {
2221 vino_queue_transfer(&vcs
->fb_queue
);
2223 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2224 dprintk("vino_capture_stop(): "
2225 "vino_queue_get_incoming() failed\n");
2230 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2231 dprintk("vino_capture_stop(): "
2232 "vino_queue_get_outgoing() failed\n");
2235 while (outgoing
> 0) {
2236 vino_queue_remove(&vcs
->fb_queue
, &id
);
2238 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2239 dprintk("vino_capture_stop(): "
2240 "vino_queue_get_outgoing() failed\n");
2246 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2250 static int vino_capture_failed(struct vino_channel_settings
*vcs
)
2252 struct vino_framebuffer
*fb
;
2253 unsigned long flags
;
2257 dprintk("vino_capture_failed():\n");
2259 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2262 vino_clear_interrupt(vcs
);
2264 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2266 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &i
);
2267 if (ret
== VINO_QUEUE_ERROR
) {
2268 dprintk("vino_queue_get_incoming() failed\n");
2272 /* no buffers to process */
2276 fb
= vino_queue_peek(&vcs
->fb_queue
, &i
);
2278 dprintk("vino_queue_peek() failed\n");
2282 spin_lock_irqsave(&fb
->state_lock
, flags
);
2283 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
) {
2284 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2285 vino_queue_transfer(&vcs
->fb_queue
);
2286 vino_queue_remove(&vcs
->fb_queue
, &i
);
2287 /* we should actually discard the newest frame,
2288 * but who cares ... */
2290 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2296 static void vino_skip_frame(struct vino_channel_settings
*vcs
)
2298 struct vino_framebuffer
*fb
;
2299 unsigned long flags
;
2302 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2303 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2305 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2306 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2309 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2311 spin_lock_irqsave(&fb
->state_lock
, flags
);
2312 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2313 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2315 vino_capture_next(vcs
, 0);
2318 static void vino_frame_done(struct vino_channel_settings
*vcs
)
2320 struct vino_framebuffer
*fb
;
2321 unsigned long flags
;
2323 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2324 fb
= vino_queue_transfer(&vcs
->fb_queue
);
2326 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2327 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2330 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2332 fb
->frame_counter
= vcs
->int_data
.frame_counter
;
2333 memcpy(&fb
->timestamp
, &vcs
->int_data
.timestamp
,
2334 sizeof(struct timeval
));
2336 spin_lock_irqsave(&fb
->state_lock
, flags
);
2337 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
2338 fb
->state
= VINO_FRAMEBUFFER_READY
;
2339 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2341 wake_up(&vcs
->fb_queue
.frame_wait_queue
);
2343 vino_capture_next(vcs
, 0);
2346 static void vino_capture_tasklet(unsigned long channel
) {
2347 struct vino_channel_settings
*vcs
;
2349 vcs
= (channel
== VINO_CHANNEL_A
)
2350 ? &vino_drvdata
->a
: &vino_drvdata
->b
;
2352 if (vcs
->int_data
.skip
)
2353 vcs
->int_data
.skip_count
++;
2355 if (vcs
->int_data
.skip
&& (vcs
->int_data
.skip_count
2356 <= VINO_MAX_FRAME_SKIP_COUNT
)) {
2357 vino_skip_frame(vcs
);
2359 vcs
->int_data
.skip_count
= 0;
2360 vino_frame_done(vcs
);
2364 static irqreturn_t
vino_interrupt(int irq
, void *dev_id
)
2367 unsigned int fc_a
, fc_b
;
2368 int handled_a
= 0, skip_a
= 0, done_a
= 0;
2369 int handled_b
= 0, skip_b
= 0, done_b
= 0;
2371 #ifdef VINO_DEBUG_INT
2373 unsigned int line_count
= vino
->a
.line_count
,
2374 page_index
= vino
->a
.page_index
,
2375 field_counter
= vino
->a
.field_counter
,
2376 start_desc_tbl
= vino
->a
.start_desc_tbl
,
2377 next_4_desc
= vino
->a
.next_4_desc
;
2378 unsigned int line_count_2
,
2385 spin_lock(&vino_drvdata
->vino_lock
);
2387 while ((intr
= vino
->intr_status
)) {
2388 fc_a
= vino
->a
.field_counter
>> 1;
2389 fc_b
= vino
->b
.field_counter
>> 1;
2391 /* handle error-interrupts in some special way ?
2392 * --> skips frames */
2393 if (intr
& VINO_INTSTAT_A
) {
2394 if (intr
& VINO_INTSTAT_A_EOF
) {
2395 vino_drvdata
->a
.field
++;
2396 if (vino_drvdata
->a
.field
> 1) {
2397 vino_dma_stop(&vino_drvdata
->a
);
2398 vino_clear_interrupt(&vino_drvdata
->a
);
2399 vino_drvdata
->a
.field
= 0;
2402 if (vino
->a
.page_index
2403 != vino_drvdata
->a
.line_size
) {
2404 vino
->a
.line_count
= 0;
2405 vino
->a
.page_index
=
2408 vino
->a
.next_4_desc
=
2409 vino
->a
.start_desc_tbl
;
2412 dprintk("channel A end-of-field "
2413 "interrupt: %04x\n", intr
);
2415 vino_dma_stop(&vino_drvdata
->a
);
2416 vino_clear_interrupt(&vino_drvdata
->a
);
2417 vino_drvdata
->a
.field
= 0;
2419 dprintk("channel A error interrupt: %04x\n",
2423 #ifdef VINO_DEBUG_INT
2424 line_count_2
= vino
->a
.line_count
;
2425 page_index_2
= vino
->a
.page_index
;
2426 field_counter_2
= vino
->a
.field_counter
;
2427 start_desc_tbl_2
= vino
->a
.start_desc_tbl
;
2428 next_4_desc_2
= vino
->a
.next_4_desc
;
2430 printk("intr = %04x, loop = %d, field = %d\n",
2431 intr
, loop
, vino_drvdata
->a
.field
);
2432 printk("1- line count = %04d, page index = %04d, "
2433 "start = %08x, next = %08x\n"
2434 " fieldc = %d, framec = %d\n",
2435 line_count
, page_index
, start_desc_tbl
,
2436 next_4_desc
, field_counter
, fc_a
);
2437 printk("12-line count = %04d, page index = %04d, "
2438 " start = %08x, next = %08x\n",
2439 line_count_2
, page_index_2
, start_desc_tbl_2
,
2447 if (intr
& VINO_INTSTAT_B
) {
2448 if (intr
& VINO_INTSTAT_B_EOF
) {
2449 vino_drvdata
->b
.field
++;
2450 if (vino_drvdata
->b
.field
> 1) {
2451 vino_dma_stop(&vino_drvdata
->b
);
2452 vino_clear_interrupt(&vino_drvdata
->b
);
2453 vino_drvdata
->b
.field
= 0;
2456 dprintk("channel B end-of-field "
2457 "interrupt: %04x\n", intr
);
2459 vino_dma_stop(&vino_drvdata
->b
);
2460 vino_clear_interrupt(&vino_drvdata
->b
);
2461 vino_drvdata
->b
.field
= 0;
2463 dprintk("channel B error interrupt: %04x\n",
2468 /* Always remember to clear interrupt status.
2469 * Disable VINO interrupts while we do this. */
2470 ctrl
= vino
->control
;
2471 vino
->control
= ctrl
& ~(VINO_CTRL_A_INT
| VINO_CTRL_B_INT
);
2472 vino
->intr_status
= ~intr
;
2473 vino
->control
= ctrl
;
2475 spin_unlock(&vino_drvdata
->vino_lock
);
2477 if ((!handled_a
) && (done_a
|| skip_a
)) {
2479 do_gettimeofday(&vino_drvdata
->
2480 a
.int_data
.timestamp
);
2481 vino_drvdata
->a
.int_data
.frame_counter
= fc_a
;
2483 vino_drvdata
->a
.int_data
.skip
= skip_a
;
2485 dprintk("channel A %s, interrupt: %d\n",
2486 skip_a
? "skipping frame" : "frame done",
2488 tasklet_hi_schedule(&vino_tasklet_a
);
2492 if ((!handled_b
) && (done_b
|| skip_b
)) {
2494 do_gettimeofday(&vino_drvdata
->
2495 b
.int_data
.timestamp
);
2496 vino_drvdata
->b
.int_data
.frame_counter
= fc_b
;
2498 vino_drvdata
->b
.int_data
.skip
= skip_b
;
2500 dprintk("channel B %s, interrupt: %d\n",
2501 skip_b
? "skipping frame" : "frame done",
2503 tasklet_hi_schedule(&vino_tasklet_b
);
2507 #ifdef VINO_DEBUG_INT
2510 spin_lock(&vino_drvdata
->vino_lock
);
2513 spin_unlock(&vino_drvdata
->vino_lock
);
2518 /* VINO video input management */
2520 static int vino_get_saa7191_input(int input
)
2523 case VINO_INPUT_COMPOSITE
:
2524 return SAA7191_INPUT_COMPOSITE
;
2525 case VINO_INPUT_SVIDEO
:
2526 return SAA7191_INPUT_SVIDEO
;
2528 printk(KERN_ERR
"VINO: vino_get_saa7191_input(): "
2529 "invalid input!\n");
2534 /* execute with input_lock locked */
2535 static int vino_is_input_owner(struct vino_channel_settings
*vcs
)
2537 switch(vcs
->input
) {
2538 case VINO_INPUT_COMPOSITE
:
2539 case VINO_INPUT_SVIDEO
:
2540 return vino_drvdata
->decoder_owner
== vcs
->channel
;
2542 return vino_drvdata
->camera_owner
== vcs
->channel
;
2548 static int vino_acquire_input(struct vino_channel_settings
*vcs
)
2550 unsigned long flags
;
2553 dprintk("vino_acquire_input():\n");
2555 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2557 /* First try D1 and then SAA7191 */
2558 if (vino_drvdata
->camera
2559 && (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)) {
2560 vino_drvdata
->camera_owner
= vcs
->channel
;
2561 vcs
->input
= VINO_INPUT_D1
;
2562 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2563 } else if (vino_drvdata
->decoder
2564 && (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
)) {
2569 input
= VINO_INPUT_COMPOSITE
;
2571 ret
= decoder_call(video
, s_routing
,
2572 vino_get_saa7191_input(input
), 0, 0);
2578 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2580 /* Don't hold spinlocks while auto-detecting norm
2581 * as it may take a while... */
2583 ret
= decoder_call(video
, querystd
, &norm
);
2585 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2586 if (vino_data_norms
[data_norm
].std
& norm
)
2590 data_norm
= VINO_DATA_NORM_PAL
;
2591 ret
= decoder_call(core
, s_std
, norm
);
2594 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2601 vino_drvdata
->decoder_owner
= vcs
->channel
;
2604 vcs
->data_norm
= data_norm
;
2606 vcs
->input
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2607 vino_drvdata
->b
.input
: vino_drvdata
->a
.input
;
2608 vcs
->data_norm
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2609 vino_drvdata
->b
.data_norm
: vino_drvdata
->a
.data_norm
;
2612 if (vcs
->input
== VINO_INPUT_NONE
) {
2617 vino_set_default_clipping(vcs
);
2618 vino_set_default_scaling(vcs
);
2619 vino_set_default_framerate(vcs
);
2621 dprintk("vino_acquire_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2624 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2629 static int vino_set_input(struct vino_channel_settings
*vcs
, int input
)
2631 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2632 &vino_drvdata
->b
: &vino_drvdata
->a
;
2633 unsigned long flags
;
2636 dprintk("vino_set_input():\n");
2638 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2640 if (vcs
->input
== input
)
2644 case VINO_INPUT_COMPOSITE
:
2645 case VINO_INPUT_SVIDEO
:
2646 if (!vino_drvdata
->decoder
) {
2651 if (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
) {
2652 vino_drvdata
->decoder_owner
= vcs
->channel
;
2655 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2659 ret
= decoder_call(video
, s_routing
,
2660 vino_get_saa7191_input(input
), 0, 0);
2662 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2667 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2669 /* Don't hold spinlocks while auto-detecting norm
2670 * as it may take a while... */
2672 ret
= decoder_call(video
, querystd
, &norm
);
2674 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2675 if (vino_data_norms
[data_norm
].std
& norm
)
2679 data_norm
= VINO_DATA_NORM_PAL
;
2680 ret
= decoder_call(core
, s_std
, norm
);
2683 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2686 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2692 vcs
->data_norm
= data_norm
;
2694 if (input
!= vcs2
->input
) {
2700 vcs
->data_norm
= vcs2
->data_norm
;
2703 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2704 /* Transfer the ownership or release the input */
2705 if (vcs2
->input
== VINO_INPUT_D1
) {
2706 vino_drvdata
->camera_owner
= vcs2
->channel
;
2708 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2713 if (!vino_drvdata
->camera
) {
2718 if (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)
2719 vino_drvdata
->camera_owner
= vcs
->channel
;
2721 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2722 /* Transfer the ownership or release the input */
2723 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2724 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2725 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2727 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2732 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2739 vino_set_default_clipping(vcs
);
2740 vino_set_default_scaling(vcs
);
2741 vino_set_default_framerate(vcs
);
2743 dprintk("vino_set_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2746 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2751 static void vino_release_input(struct vino_channel_settings
*vcs
)
2753 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2754 &vino_drvdata
->b
: &vino_drvdata
->a
;
2755 unsigned long flags
;
2757 dprintk("vino_release_input():\n");
2759 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2761 /* Release ownership of the channel
2762 * and if the other channel takes input from
2763 * the same source, transfer the ownership */
2764 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2765 if (vcs2
->input
== VINO_INPUT_D1
) {
2766 vino_drvdata
->camera_owner
= vcs2
->channel
;
2768 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2770 } else if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2771 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2772 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2773 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2775 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2778 vcs
->input
= VINO_INPUT_NONE
;
2780 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2783 /* execute with input_lock locked */
2784 static int vino_set_data_norm(struct vino_channel_settings
*vcs
,
2785 unsigned int data_norm
,
2786 unsigned long *flags
)
2790 if (data_norm
== vcs
->data_norm
)
2793 switch (vcs
->input
) {
2795 /* only one "norm" supported */
2796 if (data_norm
!= VINO_DATA_NORM_D1
)
2799 case VINO_INPUT_COMPOSITE
:
2800 case VINO_INPUT_SVIDEO
: {
2803 if ((data_norm
!= VINO_DATA_NORM_PAL
)
2804 && (data_norm
!= VINO_DATA_NORM_NTSC
)
2805 && (data_norm
!= VINO_DATA_NORM_SECAM
))
2808 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, *flags
);
2810 /* Don't hold spinlocks while setting norm
2811 * as it may take a while... */
2813 norm
= vino_data_norms
[data_norm
].std
;
2814 err
= decoder_call(core
, s_std
, norm
);
2816 spin_lock_irqsave(&vino_drvdata
->input_lock
, *flags
);
2821 vcs
->data_norm
= data_norm
;
2823 vino_set_default_clipping(vcs
);
2824 vino_set_default_scaling(vcs
);
2825 vino_set_default_framerate(vcs
);
2836 /* V4L2 helper functions */
2838 static int vino_find_data_format(__u32 pixelformat
)
2842 for (i
= 0; i
< VINO_DATA_FMT_COUNT
; i
++) {
2843 if (vino_data_formats
[i
].pixelformat
== pixelformat
)
2847 return VINO_DATA_FMT_NONE
;
2850 static int vino_int_enum_input(struct vino_channel_settings
*vcs
, __u32 index
)
2852 int input
= VINO_INPUT_NONE
;
2853 unsigned long flags
;
2855 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2856 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2859 input
= VINO_INPUT_COMPOSITE
;
2862 input
= VINO_INPUT_SVIDEO
;
2865 input
= VINO_INPUT_D1
;
2868 } else if (vino_drvdata
->decoder
) {
2871 input
= VINO_INPUT_COMPOSITE
;
2874 input
= VINO_INPUT_SVIDEO
;
2877 } else if (vino_drvdata
->camera
) {
2880 input
= VINO_INPUT_D1
;
2884 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2889 /* execute with input_lock locked */
2890 static __u32
vino_find_input_index(struct vino_channel_settings
*vcs
)
2893 // FIXME: detect when no inputs available
2895 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2896 switch (vcs
->input
) {
2897 case VINO_INPUT_COMPOSITE
:
2900 case VINO_INPUT_SVIDEO
:
2907 } else if (vino_drvdata
->decoder
) {
2908 switch (vcs
->input
) {
2909 case VINO_INPUT_COMPOSITE
:
2912 case VINO_INPUT_SVIDEO
:
2916 } else if (vino_drvdata
->camera
) {
2917 switch (vcs
->input
) {
2929 static int vino_querycap(struct file
*file
, void *__fh
,
2930 struct v4l2_capability
*cap
)
2932 memset(cap
, 0, sizeof(struct v4l2_capability
));
2934 strcpy(cap
->driver
, vino_driver_name
);
2935 strcpy(cap
->card
, vino_driver_description
);
2936 strcpy(cap
->bus_info
, vino_bus_name
);
2937 cap
->version
= VINO_VERSION_CODE
;
2939 V4L2_CAP_VIDEO_CAPTURE
|
2941 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
2945 static int vino_enum_input(struct file
*file
, void *__fh
,
2946 struct v4l2_input
*i
)
2948 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2949 __u32 index
= i
->index
;
2951 dprintk("requested index = %d\n", index
);
2953 input
= vino_int_enum_input(vcs
, index
);
2954 if (input
== VINO_INPUT_NONE
)
2957 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
2958 i
->std
= vino_inputs
[input
].std
;
2959 strcpy(i
->name
, vino_inputs
[input
].name
);
2961 if (input
== VINO_INPUT_COMPOSITE
|| input
== VINO_INPUT_SVIDEO
)
2962 decoder_call(video
, g_input_status
, &i
->status
);
2966 static int vino_g_input(struct file
*file
, void *__fh
,
2969 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2972 unsigned long flags
;
2974 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2976 index
= vino_find_input_index(vcs
);
2977 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2979 dprintk("input = %d\n", input
);
2981 if (input
== VINO_INPUT_NONE
) {
2990 static int vino_s_input(struct file
*file
, void *__fh
,
2993 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2995 dprintk("requested input = %d\n", i
);
2997 input
= vino_int_enum_input(vcs
, i
);
2998 if (input
== VINO_INPUT_NONE
)
3001 return vino_set_input(vcs
, input
);
3004 static int vino_querystd(struct file
*file
, void *__fh
,
3007 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3008 unsigned long flags
;
3011 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3013 switch (vcs
->input
) {
3015 *std
= vino_inputs
[vcs
->input
].std
;
3017 case VINO_INPUT_COMPOSITE
:
3018 case VINO_INPUT_SVIDEO
: {
3019 decoder_call(video
, querystd
, std
);
3026 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3031 static int vino_g_std(struct file
*file
, void *__fh
,
3034 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3035 unsigned long flags
;
3037 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3039 *std
= vino_data_norms
[vcs
->data_norm
].std
;
3040 dprintk("current standard = %d\n", vcs
->data_norm
);
3042 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3047 static int vino_s_std(struct file
*file
, void *__fh
,
3050 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3051 unsigned long flags
;
3054 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3056 if (!vino_is_input_owner(vcs
)) {
3061 /* check if the standard is valid for the current input */
3062 if ((*std
) & vino_inputs
[vcs
->input
].std
) {
3063 dprintk("standard accepted\n");
3065 /* change the video norm for SAA7191
3066 * and accept NTSC for D1 (do nothing) */
3068 if (vcs
->input
== VINO_INPUT_D1
)
3071 if ((*std
) & V4L2_STD_PAL
) {
3072 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_PAL
,
3074 } else if ((*std
) & V4L2_STD_NTSC
) {
3075 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_NTSC
,
3077 } else if ((*std
) & V4L2_STD_SECAM
) {
3078 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_SECAM
,
3092 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3097 static int vino_enum_fmt_vid_cap(struct file
*file
, void *__fh
,
3098 struct v4l2_fmtdesc
*fd
)
3100 dprintk("format index = %d\n", fd
->index
);
3102 if (fd
->index
>= VINO_DATA_FMT_COUNT
)
3104 dprintk("format name = %s\n", vino_data_formats
[fd
->index
].description
);
3106 fd
->pixelformat
= vino_data_formats
[fd
->index
].pixelformat
;
3107 strcpy(fd
->description
, vino_data_formats
[fd
->index
].description
);
3111 static int vino_try_fmt_vid_cap(struct file
*file
, void *__fh
,
3112 struct v4l2_format
*f
)
3114 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3115 struct vino_channel_settings tempvcs
;
3116 unsigned long flags
;
3117 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3119 dprintk("requested: w = %d, h = %d\n",
3120 pf
->width
, pf
->height
);
3122 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3123 memcpy(&tempvcs
, vcs
, sizeof(struct vino_channel_settings
));
3124 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3126 tempvcs
.data_format
= vino_find_data_format(pf
->pixelformat
);
3127 if (tempvcs
.data_format
== VINO_DATA_FMT_NONE
) {
3128 tempvcs
.data_format
= VINO_DATA_FMT_GREY
;
3130 vino_data_formats
[tempvcs
.data_format
].
3134 /* data format must be set before clipping/scaling */
3135 vino_set_scaling(&tempvcs
, pf
->width
, pf
->height
);
3137 dprintk("data format = %s\n",
3138 vino_data_formats
[tempvcs
.data_format
].description
);
3140 pf
->width
= (tempvcs
.clipping
.right
- tempvcs
.clipping
.left
) /
3142 pf
->height
= (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3145 pf
->field
= V4L2_FIELD_INTERLACED
;
3146 pf
->bytesperline
= tempvcs
.line_size
;
3147 pf
->sizeimage
= tempvcs
.line_size
*
3148 (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3151 vino_data_formats
[tempvcs
.data_format
].colorspace
;
3157 static int vino_g_fmt_vid_cap(struct file
*file
, void *__fh
,
3158 struct v4l2_format
*f
)
3160 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3161 unsigned long flags
;
3162 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3164 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3166 pf
->width
= (vcs
->clipping
.right
- vcs
->clipping
.left
) /
3168 pf
->height
= (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3171 vino_data_formats
[vcs
->data_format
].pixelformat
;
3173 pf
->field
= V4L2_FIELD_INTERLACED
;
3174 pf
->bytesperline
= vcs
->line_size
;
3175 pf
->sizeimage
= vcs
->line_size
*
3176 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3179 vino_data_formats
[vcs
->data_format
].colorspace
;
3183 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3187 static int vino_s_fmt_vid_cap(struct file
*file
, void *__fh
,
3188 struct v4l2_format
*f
)
3190 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3192 unsigned long flags
;
3193 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3195 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3197 data_format
= vino_find_data_format(pf
->pixelformat
);
3199 if (data_format
== VINO_DATA_FMT_NONE
) {
3200 vcs
->data_format
= VINO_DATA_FMT_GREY
;
3202 vino_data_formats
[vcs
->data_format
].
3205 vcs
->data_format
= data_format
;
3208 /* data format must be set before clipping/scaling */
3209 vino_set_scaling(vcs
, pf
->width
, pf
->height
);
3211 dprintk("data format = %s\n",
3212 vino_data_formats
[vcs
->data_format
].description
);
3214 pf
->width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3215 pf
->height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3217 pf
->field
= V4L2_FIELD_INTERLACED
;
3218 pf
->bytesperline
= vcs
->line_size
;
3219 pf
->sizeimage
= vcs
->line_size
*
3220 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3223 vino_data_formats
[vcs
->data_format
].colorspace
;
3227 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3231 static int vino_cropcap(struct file
*file
, void *__fh
,
3232 struct v4l2_cropcap
*ccap
)
3234 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3235 const struct vino_data_norm
*norm
;
3236 unsigned long flags
;
3238 switch (ccap
->type
) {
3239 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3240 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3242 norm
= &vino_data_norms
[vcs
->data_norm
];
3244 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3246 ccap
->bounds
.left
= 0;
3247 ccap
->bounds
.top
= 0;
3248 ccap
->bounds
.width
= norm
->width
;
3249 ccap
->bounds
.height
= norm
->height
;
3250 memcpy(&ccap
->defrect
, &ccap
->bounds
,
3251 sizeof(struct v4l2_rect
));
3253 ccap
->pixelaspect
.numerator
= 1;
3254 ccap
->pixelaspect
.denominator
= 1;
3256 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3264 static int vino_g_crop(struct file
*file
, void *__fh
,
3265 struct v4l2_crop
*c
)
3267 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3268 unsigned long flags
;
3271 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3272 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3274 c
->c
.left
= vcs
->clipping
.left
;
3275 c
->c
.top
= vcs
->clipping
.top
;
3276 c
->c
.width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3277 c
->c
.height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3279 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3281 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3289 static int vino_s_crop(struct file
*file
, void *__fh
,
3290 struct v4l2_crop
*c
)
3292 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3293 unsigned long flags
;
3296 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3297 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3299 vino_set_clipping(vcs
, c
->c
.left
, c
->c
.top
,
3300 c
->c
.width
, c
->c
.height
);
3302 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3304 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3312 static int vino_g_parm(struct file
*file
, void *__fh
,
3313 struct v4l2_streamparm
*sp
)
3315 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3316 unsigned long flags
;
3317 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3319 cp
->capability
= V4L2_CAP_TIMEPERFRAME
;
3320 cp
->timeperframe
.numerator
= 1;
3322 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3324 cp
->timeperframe
.denominator
= vcs
->fps
;
3326 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3328 /* TODO: cp->readbuffers = xxx; */
3333 static int vino_s_parm(struct file
*file
, void *__fh
,
3334 struct v4l2_streamparm
*sp
)
3336 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3337 unsigned long flags
;
3338 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3340 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3342 if ((cp
->timeperframe
.numerator
== 0) ||
3343 (cp
->timeperframe
.denominator
== 0)) {
3344 /* reset framerate */
3345 vino_set_default_framerate(vcs
);
3347 vino_set_framerate(vcs
, cp
->timeperframe
.denominator
/
3348 cp
->timeperframe
.numerator
);
3351 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3356 static int vino_reqbufs(struct file
*file
, void *__fh
,
3357 struct v4l2_requestbuffers
*rb
)
3359 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3364 /* TODO: check queue type */
3365 if (rb
->memory
!= V4L2_MEMORY_MMAP
) {
3366 dprintk("type not mmap\n");
3370 dprintk("count = %d\n", rb
->count
);
3371 if (rb
->count
> 0) {
3372 if (vino_is_capturing(vcs
)) {
3373 dprintk("busy, capturing\n");
3377 if (vino_queue_has_mapped_buffers(&vcs
->fb_queue
)) {
3378 dprintk("busy, buffers still mapped\n");
3382 vino_queue_free(&vcs
->fb_queue
);
3383 vino_queue_init(&vcs
->fb_queue
, &rb
->count
);
3387 vino_capture_stop(vcs
);
3388 vino_queue_free(&vcs
->fb_queue
);
3394 static void vino_v4l2_get_buffer_status(struct vino_channel_settings
*vcs
,
3395 struct vino_framebuffer
*fb
,
3396 struct v4l2_buffer
*b
)
3398 if (vino_queue_outgoing_contains(&vcs
->fb_queue
,
3400 b
->flags
&= ~V4L2_BUF_FLAG_QUEUED
;
3401 b
->flags
|= V4L2_BUF_FLAG_DONE
;
3402 } else if (vino_queue_incoming_contains(&vcs
->fb_queue
,
3404 b
->flags
&= ~V4L2_BUF_FLAG_DONE
;
3405 b
->flags
|= V4L2_BUF_FLAG_QUEUED
;
3407 b
->flags
&= ~(V4L2_BUF_FLAG_DONE
|
3408 V4L2_BUF_FLAG_QUEUED
);
3411 b
->flags
&= ~(V4L2_BUF_FLAG_TIMECODE
);
3413 if (fb
->map_count
> 0)
3414 b
->flags
|= V4L2_BUF_FLAG_MAPPED
;
3417 b
->memory
= (vcs
->fb_queue
.type
== VINO_MEMORY_MMAP
) ?
3418 V4L2_MEMORY_MMAP
: V4L2_MEMORY_USERPTR
;
3419 b
->m
.offset
= fb
->offset
;
3420 b
->bytesused
= fb
->data_size
;
3421 b
->length
= fb
->size
;
3422 b
->field
= V4L2_FIELD_INTERLACED
;
3423 b
->sequence
= fb
->frame_counter
;
3424 memcpy(&b
->timestamp
, &fb
->timestamp
,
3425 sizeof(struct timeval
));
3428 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3429 fb
->id
, fb
->size
, fb
->data_size
, fb
->offset
);
3432 static int vino_querybuf(struct file
*file
, void *__fh
,
3433 struct v4l2_buffer
*b
)
3435 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3436 struct vino_framebuffer
*fb
;
3441 /* TODO: check queue type */
3442 if (b
->index
>= vino_queue_get_length(&vcs
->fb_queue
)) {
3443 dprintk("invalid index = %d\n",
3448 fb
= vino_queue_get_buffer(&vcs
->fb_queue
,
3451 dprintk("vino_queue_get_buffer() failed");
3455 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3460 static int vino_qbuf(struct file
*file
, void *__fh
,
3461 struct v4l2_buffer
*b
)
3463 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3464 struct vino_framebuffer
*fb
;
3470 /* TODO: check queue type */
3471 if (b
->memory
!= V4L2_MEMORY_MMAP
) {
3472 dprintk("type not mmap\n");
3476 fb
= vino_capture_enqueue(vcs
, b
->index
);
3480 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3482 if (vcs
->streaming
) {
3483 ret
= vino_capture_next(vcs
, 1);
3491 static int vino_dqbuf(struct file
*file
, void *__fh
,
3492 struct v4l2_buffer
*b
)
3494 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3495 unsigned int nonblocking
= file
->f_flags
& O_NONBLOCK
;
3496 struct vino_framebuffer
*fb
;
3497 unsigned int incoming
, outgoing
;
3503 /* TODO: check queue type */
3505 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3507 dprintk("vino_queue_get_incoming() failed\n");
3510 err
= vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
);
3512 dprintk("vino_queue_get_outgoing() failed\n");
3516 dprintk("incoming = %d, outgoing = %d\n", incoming
, outgoing
);
3518 if (outgoing
== 0) {
3519 if (incoming
== 0) {
3520 dprintk("no incoming or outgoing buffers\n");
3524 dprintk("non-blocking I/O was selected and "
3525 "there are no buffers to dequeue\n");
3529 err
= vino_wait_for_frame(vcs
);
3531 err
= vino_wait_for_frame(vcs
);
3533 /* interrupted or no frames captured because of
3535 /* vino_capture_failed(vcs); */
3541 fb
= vino_queue_remove(&vcs
->fb_queue
, &b
->index
);
3543 dprintk("vino_queue_remove() failed\n");
3547 err
= vino_check_buffer(vcs
, fb
);
3549 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3557 static int vino_streamon(struct file
*file
, void *__fh
,
3558 enum v4l2_buf_type i
)
3560 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3561 unsigned int incoming
;
3569 // TODO: check queue type
3571 if (vino_queue_get_length(&vcs
->fb_queue
) < 1) {
3572 dprintk("no buffers allocated\n");
3576 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3578 dprintk("vino_queue_get_incoming() failed\n");
3585 ret
= vino_capture_next(vcs
, 1);
3589 dprintk("couldn't start capture\n");
3597 static int vino_streamoff(struct file
*file
, void *__fh
,
3598 enum v4l2_buf_type i
)
3600 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3604 if (!vcs
->streaming
)
3608 vino_capture_stop(vcs
);
3613 static int vino_queryctrl(struct file
*file
, void *__fh
,
3614 struct v4l2_queryctrl
*queryctrl
)
3616 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3617 unsigned long flags
;
3621 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3623 switch (vcs
->input
) {
3625 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3626 if (vino_indycam_v4l2_controls
[i
].id
==
3629 &vino_indycam_v4l2_controls
[i
],
3630 sizeof(struct v4l2_queryctrl
));
3631 queryctrl
->reserved
[0] = 0;
3638 case VINO_INPUT_COMPOSITE
:
3639 case VINO_INPUT_SVIDEO
:
3640 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3641 if (vino_saa7191_v4l2_controls
[i
].id
==
3644 &vino_saa7191_v4l2_controls
[i
],
3645 sizeof(struct v4l2_queryctrl
));
3646 queryctrl
->reserved
[0] = 0;
3658 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3663 static int vino_g_ctrl(struct file
*file
, void *__fh
,
3664 struct v4l2_control
*control
)
3666 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3667 unsigned long flags
;
3671 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3673 switch (vcs
->input
) {
3674 case VINO_INPUT_D1
: {
3676 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3677 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3686 err
= camera_call(core
, g_ctrl
, control
);
3691 case VINO_INPUT_COMPOSITE
:
3692 case VINO_INPUT_SVIDEO
: {
3694 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3695 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3704 err
= decoder_call(core
, g_ctrl
, control
);
3714 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3719 static int vino_s_ctrl(struct file
*file
, void *__fh
,
3720 struct v4l2_control
*control
)
3722 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3723 unsigned long flags
;
3727 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3729 if (!vino_is_input_owner(vcs
)) {
3734 switch (vcs
->input
) {
3735 case VINO_INPUT_D1
: {
3737 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3738 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3745 if (control
->value
< vino_indycam_v4l2_controls
[i
].minimum
||
3746 control
->value
> vino_indycam_v4l2_controls
[i
].maximum
) {
3750 err
= camera_call(core
, s_ctrl
, control
);
3755 case VINO_INPUT_COMPOSITE
:
3756 case VINO_INPUT_SVIDEO
: {
3758 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3759 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3766 if (control
->value
< vino_saa7191_v4l2_controls
[i
].minimum
||
3767 control
->value
> vino_saa7191_v4l2_controls
[i
].maximum
) {
3772 err
= decoder_call(core
, s_ctrl
, control
);
3782 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3787 /* File operations */
3789 static int vino_open(struct file
*file
)
3791 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3793 dprintk("open(): channel = %c\n",
3794 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A' : 'B');
3796 mutex_lock(&vcs
->mutex
);
3799 dprintk("open(): driver busy\n");
3804 ret
= vino_acquire_input(vcs
);
3806 dprintk("open(): vino_acquire_input() failed\n");
3813 mutex_unlock(&vcs
->mutex
);
3815 dprintk("open(): %s!\n", ret
? "failed" : "complete");
3820 static int vino_close(struct file
*file
)
3822 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3823 dprintk("close():\n");
3825 mutex_lock(&vcs
->mutex
);
3830 vino_release_input(vcs
);
3832 /* stop DMA and free buffers */
3833 vino_capture_stop(vcs
);
3834 vino_queue_free(&vcs
->fb_queue
);
3837 mutex_unlock(&vcs
->mutex
);
3842 static void vino_vm_open(struct vm_area_struct
*vma
)
3844 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3847 dprintk("vino_vm_open(): count = %d\n", fb
->map_count
);
3850 static void vino_vm_close(struct vm_area_struct
*vma
)
3852 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3855 dprintk("vino_vm_close(): count = %d\n", fb
->map_count
);
3858 static const struct vm_operations_struct vino_vm_ops
= {
3859 .open
= vino_vm_open
,
3860 .close
= vino_vm_close
,
3863 static int vino_mmap(struct file
*file
, struct vm_area_struct
*vma
)
3865 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3867 unsigned long start
= vma
->vm_start
;
3868 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
3869 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
3871 struct vino_framebuffer
*fb
= NULL
;
3872 unsigned int i
, length
;
3875 dprintk("mmap():\n");
3877 // TODO: reject mmap if already mapped
3879 if (mutex_lock_interruptible(&vcs
->mutex
))
3887 // TODO: check queue type
3889 if (!(vma
->vm_flags
& VM_WRITE
)) {
3890 dprintk("mmap(): app bug: PROT_WRITE please\n");
3894 if (!(vma
->vm_flags
& VM_SHARED
)) {
3895 dprintk("mmap(): app bug: MAP_SHARED please\n");
3900 /* find the correct buffer using offset */
3901 length
= vino_queue_get_length(&vcs
->fb_queue
);
3903 dprintk("mmap(): queue not initialized\n");
3908 for (i
= 0; i
< length
; i
++) {
3909 fb
= vino_queue_get_buffer(&vcs
->fb_queue
, i
);
3911 dprintk("mmap(): vino_queue_get_buffer() failed\n");
3916 if (fb
->offset
== offset
)
3920 dprintk("mmap(): invalid offset = %lu\n", offset
);
3925 dprintk("mmap(): buffer = %d\n", i
);
3927 if (size
> (fb
->desc_table
.page_count
* PAGE_SIZE
)) {
3928 dprintk("mmap(): failed: size = %lu > %lu\n",
3929 size
, fb
->desc_table
.page_count
* PAGE_SIZE
);
3934 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++) {
3936 virt_to_phys((void *)fb
->desc_table
.virtual[i
]) >>
3939 if (size
< PAGE_SIZE
)
3942 // protection was: PAGE_READONLY
3943 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
,
3944 vma
->vm_page_prot
)) {
3945 dprintk("mmap(): remap_pfn_range() failed\n");
3956 vma
->vm_flags
|= VM_DONTEXPAND
| VM_RESERVED
;
3957 vma
->vm_flags
&= ~VM_IO
;
3958 vma
->vm_private_data
= fb
;
3959 vma
->vm_file
= file
;
3960 vma
->vm_ops
= &vino_vm_ops
;
3963 mutex_unlock(&vcs
->mutex
);
3968 static unsigned int vino_poll(struct file
*file
, poll_table
*pt
)
3970 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3971 unsigned int outgoing
;
3972 unsigned int ret
= 0;
3975 // TODO: this has to be corrected for different read modes
3977 dprintk("poll():\n");
3979 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3980 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3987 poll_wait(file
, &vcs
->fb_queue
.frame_wait_queue
, pt
);
3989 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3990 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3996 dprintk("poll(): data %savailable\n",
3997 (outgoing
> 0) ? "" : "not ");
4000 ret
= POLLIN
| POLLRDNORM
;
4006 static long vino_ioctl(struct file
*file
,
4007 unsigned int cmd
, unsigned long arg
)
4009 struct vino_channel_settings
*vcs
= video_drvdata(file
);
4012 if (mutex_lock_interruptible(&vcs
->mutex
))
4015 ret
= video_ioctl2(file
, cmd
, arg
);
4017 mutex_unlock(&vcs
->mutex
);
4022 /* Initialization and cleanup */
4025 static int vino_init_stage
;
4027 const struct v4l2_ioctl_ops vino_ioctl_ops
= {
4028 .vidioc_enum_fmt_vid_cap
= vino_enum_fmt_vid_cap
,
4029 .vidioc_g_fmt_vid_cap
= vino_g_fmt_vid_cap
,
4030 .vidioc_s_fmt_vid_cap
= vino_s_fmt_vid_cap
,
4031 .vidioc_try_fmt_vid_cap
= vino_try_fmt_vid_cap
,
4032 .vidioc_querycap
= vino_querycap
,
4033 .vidioc_enum_input
= vino_enum_input
,
4034 .vidioc_g_input
= vino_g_input
,
4035 .vidioc_s_input
= vino_s_input
,
4036 .vidioc_g_std
= vino_g_std
,
4037 .vidioc_s_std
= vino_s_std
,
4038 .vidioc_querystd
= vino_querystd
,
4039 .vidioc_cropcap
= vino_cropcap
,
4040 .vidioc_s_crop
= vino_s_crop
,
4041 .vidioc_g_crop
= vino_g_crop
,
4042 .vidioc_s_parm
= vino_s_parm
,
4043 .vidioc_g_parm
= vino_g_parm
,
4044 .vidioc_reqbufs
= vino_reqbufs
,
4045 .vidioc_querybuf
= vino_querybuf
,
4046 .vidioc_qbuf
= vino_qbuf
,
4047 .vidioc_dqbuf
= vino_dqbuf
,
4048 .vidioc_streamon
= vino_streamon
,
4049 .vidioc_streamoff
= vino_streamoff
,
4050 .vidioc_queryctrl
= vino_queryctrl
,
4051 .vidioc_g_ctrl
= vino_g_ctrl
,
4052 .vidioc_s_ctrl
= vino_s_ctrl
,
4055 static const struct v4l2_file_operations vino_fops
= {
4056 .owner
= THIS_MODULE
,
4058 .release
= vino_close
,
4059 .unlocked_ioctl
= vino_ioctl
,
4064 static struct video_device vdev_template
= {
4067 .ioctl_ops
= &vino_ioctl_ops
,
4068 .tvnorms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
4071 static void vino_module_cleanup(int stage
)
4075 video_unregister_device(vino_drvdata
->b
.vdev
);
4076 vino_drvdata
->b
.vdev
= NULL
;
4078 video_unregister_device(vino_drvdata
->a
.vdev
);
4079 vino_drvdata
->a
.vdev
= NULL
;
4081 i2c_del_adapter(&vino_i2c_adapter
);
4083 free_irq(SGI_VINO_IRQ
, NULL
);
4085 if (vino_drvdata
->b
.vdev
) {
4086 video_device_release(vino_drvdata
->b
.vdev
);
4087 vino_drvdata
->b
.vdev
= NULL
;
4090 if (vino_drvdata
->a
.vdev
) {
4091 video_device_release(vino_drvdata
->a
.vdev
);
4092 vino_drvdata
->a
.vdev
= NULL
;
4095 /* all entries in dma_cpu dummy table have the same address */
4096 dma_unmap_single(NULL
,
4097 vino_drvdata
->dummy_desc_table
.dma_cpu
[0],
4098 PAGE_SIZE
, DMA_FROM_DEVICE
);
4099 dma_free_coherent(NULL
, VINO_DUMMY_DESC_COUNT
4100 * sizeof(dma_addr_t
),
4101 (void *)vino_drvdata
->
4102 dummy_desc_table
.dma_cpu
,
4103 vino_drvdata
->dummy_desc_table
.dma
);
4105 free_page(vino_drvdata
->dummy_page
);
4107 v4l2_device_unregister(&vino_drvdata
->v4l2_dev
);
4109 kfree(vino_drvdata
);
4115 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4120 static int vino_probe(void)
4122 unsigned long rev_id
;
4124 if (ip22_is_fullhouse()) {
4125 printk(KERN_ERR
"VINO doesn't exist in IP22 Fullhouse\n");
4129 if (!(sgimc
->systemid
& SGIMC_SYSID_EPRESENT
)) {
4130 printk(KERN_ERR
"VINO is not found (EISA BUS not present)\n");
4134 vino
= (struct sgi_vino
*)ioremap(VINO_BASE
, sizeof(struct sgi_vino
));
4136 printk(KERN_ERR
"VINO: ioremap() failed\n");
4141 if (get_dbe(rev_id
, &(vino
->rev_id
))) {
4142 printk(KERN_ERR
"Failed to read VINO revision register\n");
4143 vino_module_cleanup(vino_init_stage
);
4147 if (VINO_ID_VALUE(rev_id
) != VINO_CHIP_ID
) {
4148 printk(KERN_ERR
"Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4150 vino_module_cleanup(vino_init_stage
);
4154 printk(KERN_INFO
"VINO revision %ld found\n", VINO_REV_NUM(rev_id
));
4159 static int vino_init(void)
4161 dma_addr_t dma_dummy_address
;
4165 vino_drvdata
= kzalloc(sizeof(struct vino_settings
), GFP_KERNEL
);
4166 if (!vino_drvdata
) {
4167 vino_module_cleanup(vino_init_stage
);
4171 strlcpy(vino_drvdata
->v4l2_dev
.name
, "vino",
4172 sizeof(vino_drvdata
->v4l2_dev
.name
));
4173 err
= v4l2_device_register(NULL
, &vino_drvdata
->v4l2_dev
);
4178 /* create a dummy dma descriptor */
4179 vino_drvdata
->dummy_page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
4180 if (!vino_drvdata
->dummy_page
) {
4181 vino_module_cleanup(vino_init_stage
);
4186 // TODO: use page_count in dummy_desc_table
4188 vino_drvdata
->dummy_desc_table
.dma_cpu
=
4189 dma_alloc_coherent(NULL
,
4190 VINO_DUMMY_DESC_COUNT
* sizeof(dma_addr_t
),
4191 &vino_drvdata
->dummy_desc_table
.dma
,
4192 GFP_KERNEL
| GFP_DMA
);
4193 if (!vino_drvdata
->dummy_desc_table
.dma_cpu
) {
4194 vino_module_cleanup(vino_init_stage
);
4199 dma_dummy_address
= dma_map_single(NULL
,
4200 (void *)vino_drvdata
->dummy_page
,
4201 PAGE_SIZE
, DMA_FROM_DEVICE
);
4202 for (i
= 0; i
< VINO_DUMMY_DESC_COUNT
; i
++) {
4203 vino_drvdata
->dummy_desc_table
.dma_cpu
[i
] = dma_dummy_address
;
4206 /* initialize VINO */
4209 vino
->a
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4210 vino
->b
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4211 udelay(VINO_DESC_FETCH_DELAY
);
4213 vino
->intr_status
= 0;
4215 vino
->a
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4216 vino
->b
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4221 static int vino_init_channel_settings(struct vino_channel_settings
*vcs
,
4222 unsigned int channel
, const char *name
)
4224 vcs
->channel
= channel
;
4225 vcs
->input
= VINO_INPUT_NONE
;
4228 vcs
->data_format
= VINO_DATA_FMT_GREY
;
4229 vcs
->data_norm
= VINO_DATA_NORM_NTSC
;
4230 vcs
->decimation
= 1;
4231 vino_set_default_clipping(vcs
);
4232 vino_set_default_framerate(vcs
);
4236 mutex_init(&vcs
->mutex
);
4237 spin_lock_init(&vcs
->capture_lock
);
4239 mutex_init(&vcs
->fb_queue
.queue_mutex
);
4240 spin_lock_init(&vcs
->fb_queue
.queue_lock
);
4241 init_waitqueue_head(&vcs
->fb_queue
.frame_wait_queue
);
4243 vcs
->vdev
= video_device_alloc();
4245 vino_module_cleanup(vino_init_stage
);
4250 memcpy(vcs
->vdev
, &vdev_template
,
4251 sizeof(struct video_device
));
4252 strcpy(vcs
->vdev
->name
, name
);
4253 vcs
->vdev
->release
= video_device_release
;
4254 vcs
->vdev
->v4l2_dev
= &vino_drvdata
->v4l2_dev
;
4256 video_set_drvdata(vcs
->vdev
, vcs
);
4261 static int __init
vino_module_init(void)
4265 printk(KERN_INFO
"SGI VINO driver version %s\n",
4266 VINO_MODULE_VERSION
);
4276 /* initialize data structures */
4278 spin_lock_init(&vino_drvdata
->vino_lock
);
4279 spin_lock_init(&vino_drvdata
->input_lock
);
4281 ret
= vino_init_channel_settings(&vino_drvdata
->a
, VINO_CHANNEL_A
,
4286 ret
= vino_init_channel_settings(&vino_drvdata
->b
, VINO_CHANNEL_B
,
4291 /* initialize hardware and register V4L devices */
4293 ret
= request_irq(SGI_VINO_IRQ
, vino_interrupt
, 0,
4294 vino_driver_description
, NULL
);
4296 printk(KERN_ERR
"VINO: requesting IRQ %02d failed\n",
4298 vino_module_cleanup(vino_init_stage
);
4303 ret
= i2c_add_adapter(&vino_i2c_adapter
);
4305 printk(KERN_ERR
"VINO I2C bus registration failed\n");
4306 vino_module_cleanup(vino_init_stage
);
4309 i2c_set_adapdata(&vino_i2c_adapter
, &vino_drvdata
->v4l2_dev
);
4312 ret
= video_register_device(vino_drvdata
->a
.vdev
,
4313 VFL_TYPE_GRABBER
, -1);
4315 printk(KERN_ERR
"VINO channel A Video4Linux-device "
4316 "registration failed\n");
4317 vino_module_cleanup(vino_init_stage
);
4322 ret
= video_register_device(vino_drvdata
->b
.vdev
,
4323 VFL_TYPE_GRABBER
, -1);
4325 printk(KERN_ERR
"VINO channel B Video4Linux-device "
4326 "registration failed\n");
4327 vino_module_cleanup(vino_init_stage
);
4332 vino_drvdata
->decoder
=
4333 v4l2_i2c_new_subdev(&vino_drvdata
->v4l2_dev
, &vino_i2c_adapter
,
4334 "saa7191", 0, I2C_ADDRS(0x45));
4335 vino_drvdata
->camera
=
4336 v4l2_i2c_new_subdev(&vino_drvdata
->v4l2_dev
, &vino_i2c_adapter
,
4337 "indycam", 0, I2C_ADDRS(0x2b));
4339 dprintk("init complete!\n");
4344 static void __exit
vino_module_exit(void)
4346 dprintk("exiting, stage = %d ...\n", vino_init_stage
);
4347 vino_module_cleanup(vino_init_stage
);
4348 dprintk("cleanup complete, exit!\n");
4351 module_init(vino_module_init
);
4352 module_exit(vino_module_exit
);