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/kmod.h>
41 #include <linux/i2c.h>
43 #include <linux/videodev2.h>
44 #include <media/v4l2-device.h>
45 #include <media/v4l2-ioctl.h>
46 #include <linux/mutex.h>
48 #include <asm/paccess.h>
50 #include <asm/sgi/ip22.h>
51 #include <asm/sgi/mc.h>
57 /* Uncomment the following line to get lots and lots of (mostly useless)
59 * Note that the debug output also slows down the driver significantly */
61 // #define VINO_DEBUG_INT
63 #define VINO_MODULE_VERSION "0.0.7"
65 MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
66 MODULE_VERSION(VINO_MODULE_VERSION
);
67 MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
68 MODULE_LICENSE("GPL");
71 #define dprintk(x...) printk("VINO: " x);
76 #define VINO_NO_CHANNEL 0
77 #define VINO_CHANNEL_A 1
78 #define VINO_CHANNEL_B 2
80 #define VINO_PAL_WIDTH 768
81 #define VINO_PAL_HEIGHT 576
82 #define VINO_NTSC_WIDTH 640
83 #define VINO_NTSC_HEIGHT 480
85 #define VINO_MIN_WIDTH 32
86 #define VINO_MIN_HEIGHT 32
88 #define VINO_CLIPPING_START_ODD_D1 1
89 #define VINO_CLIPPING_START_ODD_PAL 15
90 #define VINO_CLIPPING_START_ODD_NTSC 12
92 #define VINO_CLIPPING_START_EVEN_D1 2
93 #define VINO_CLIPPING_START_EVEN_PAL 15
94 #define VINO_CLIPPING_START_EVEN_NTSC 12
96 #define VINO_INPUT_CHANNEL_COUNT 3
98 /* the number is the index for vino_inputs */
99 #define VINO_INPUT_NONE -1
100 #define VINO_INPUT_COMPOSITE 0
101 #define VINO_INPUT_SVIDEO 1
102 #define VINO_INPUT_D1 2
104 #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
106 #define VINO_FIFO_THRESHOLD_DEFAULT 16
108 #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
109 * VINO_PAL_HEIGHT * 4 \
110 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
112 #define VINO_FRAMEBUFFER_COUNT_MAX 8
114 #define VINO_FRAMEBUFFER_UNUSED 0
115 #define VINO_FRAMEBUFFER_IN_USE 1
116 #define VINO_FRAMEBUFFER_READY 2
118 #define VINO_QUEUE_ERROR -1
119 #define VINO_QUEUE_MAGIC 0x20050125
121 #define VINO_MEMORY_NONE 0
122 #define VINO_MEMORY_MMAP 1
123 #define VINO_MEMORY_USERPTR 2
125 #define VINO_DUMMY_DESC_COUNT 4
126 #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
128 #define VINO_MAX_FRAME_SKIP_COUNT 128
130 /* the number is the index for vino_data_formats */
131 #define VINO_DATA_FMT_NONE -1
132 #define VINO_DATA_FMT_GREY 0
133 #define VINO_DATA_FMT_RGB332 1
134 #define VINO_DATA_FMT_RGB32 2
135 #define VINO_DATA_FMT_YUV 3
137 #define VINO_DATA_FMT_COUNT 4
139 /* the number is the index for vino_data_norms */
140 #define VINO_DATA_NORM_NONE -1
141 #define VINO_DATA_NORM_NTSC 0
142 #define VINO_DATA_NORM_PAL 1
143 #define VINO_DATA_NORM_SECAM 2
144 #define VINO_DATA_NORM_D1 3
146 #define VINO_DATA_NORM_COUNT 4
148 /* I2C controller flags */
149 #define SGI_I2C_FORCE_IDLE (0 << 0)
150 #define SGI_I2C_NOT_IDLE (1 << 0)
151 #define SGI_I2C_WRITE (0 << 1)
152 #define SGI_I2C_READ (1 << 1)
153 #define SGI_I2C_RELEASE_BUS (0 << 2)
154 #define SGI_I2C_HOLD_BUS (1 << 2)
155 #define SGI_I2C_XFER_DONE (0 << 4)
156 #define SGI_I2C_XFER_BUSY (1 << 4)
157 #define SGI_I2C_ACK (0 << 5)
158 #define SGI_I2C_NACK (1 << 5)
159 #define SGI_I2C_BUS_OK (0 << 7)
160 #define SGI_I2C_BUS_ERR (1 << 7)
162 /* Internal data structure definitions */
169 struct vino_clipping
{
170 unsigned int left
, right
, top
, bottom
;
173 struct vino_data_format
{
174 /* the description */
176 /* bytes per pixel */
178 /* V4L2 fourcc code */
180 /* V4L2 colorspace (duh!) */
181 enum v4l2_colorspace colorspace
;
184 struct vino_data_norm
{
186 unsigned int width
, height
;
187 struct vino_clipping odd
;
188 struct vino_clipping even
;
191 unsigned int fps_min
, fps_max
;
195 struct vino_descriptor_table
{
196 /* the number of PAGE_SIZE sized pages in the buffer */
197 unsigned int page_count
;
198 /* virtual (kmalloc'd) pointers to the actual data
199 * (in PAGE_SIZE chunks, used with mmap streaming) */
200 unsigned long *virtual;
202 /* cpu address for the VINO descriptor table
203 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
204 unsigned long *dma_cpu
;
205 /* dma address for the VINO descriptor table
206 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
210 struct vino_framebuffer
{
211 /* identifier nubmer */
213 /* the length of the whole buffer */
215 /* the length of actual data in buffer */
216 unsigned int data_size
;
217 /* the data format */
218 unsigned int data_format
;
219 /* the state of buffer data */
221 /* is the buffer mapped in user space? */
222 unsigned int map_count
;
223 /* memory offset for mmap() */
226 unsigned int frame_counter
;
227 /* timestamp (written when image capture finishes) */
228 struct timeval timestamp
;
230 struct vino_descriptor_table desc_table
;
232 spinlock_t state_lock
;
235 struct vino_framebuffer_fifo
{
242 unsigned int data
[VINO_FRAMEBUFFER_COUNT_MAX
];
245 struct vino_framebuffer_queue
{
248 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
252 /* data field of in and out contain index numbers for buffer */
253 struct vino_framebuffer_fifo in
;
254 struct vino_framebuffer_fifo out
;
256 struct vino_framebuffer
*buffer
[VINO_FRAMEBUFFER_COUNT_MAX
];
258 spinlock_t queue_lock
;
259 struct mutex queue_mutex
;
260 wait_queue_head_t frame_wait_queue
;
263 struct vino_interrupt_data
{
264 struct timeval timestamp
;
265 unsigned int frame_counter
;
266 unsigned int skip_count
;
270 struct vino_channel_settings
{
271 unsigned int channel
;
274 unsigned int data_format
;
275 unsigned int data_norm
;
276 struct vino_clipping clipping
;
277 unsigned int decimation
;
278 unsigned int line_size
;
281 unsigned int framert_reg
;
283 unsigned int fifo_threshold
;
285 struct vino_framebuffer_queue fb_queue
;
287 /* number of the current field */
290 /* read in progress */
292 /* streaming is active */
294 /* the driver is currently processing the queue */
298 spinlock_t capture_lock
;
302 struct vino_interrupt_data int_data
;
305 struct video_device
*vdev
;
308 struct vino_settings
{
309 struct v4l2_device v4l2_dev
;
310 struct vino_channel_settings a
;
311 struct vino_channel_settings b
;
313 /* the channel which owns this client:
314 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
315 unsigned int decoder_owner
;
316 struct v4l2_subdev
*decoder
;
317 unsigned int camera_owner
;
318 struct v4l2_subdev
*camera
;
320 /* a lock for vino register access */
321 spinlock_t vino_lock
;
322 /* a lock for channel input changes */
323 spinlock_t input_lock
;
325 unsigned long dummy_page
;
326 struct vino_descriptor_table dummy_desc_table
;
329 /* Module parameters */
332 * Using vino_pixel_conversion the ABGR32-format pixels supplied
333 * by the VINO chip can be converted to more common formats
334 * like RGBA32 (or probably RGB24 in the future). This way we
335 * can give out data that can be specified correctly with
336 * the V4L2-definitions.
338 * The pixel format is specified as RGBA32 when no conversion
341 * Note that this only affects the 32-bit bit depth.
343 * Use non-zero value to enable conversion.
345 static int vino_pixel_conversion
;
347 module_param_named(pixelconv
, vino_pixel_conversion
, int, 0);
349 MODULE_PARM_DESC(pixelconv
,
350 "enable pixel conversion (non-zero value enables)");
352 /* Internal data structures */
354 static struct sgi_vino
*vino
;
356 static struct vino_settings
*vino_drvdata
;
358 #define camera_call(o, f, args...) \
359 v4l2_subdev_call(vino_drvdata->camera, o, f, ##args)
360 #define decoder_call(o, f, args...) \
361 v4l2_subdev_call(vino_drvdata->decoder, o, f, ##args)
363 static const char *vino_driver_name
= "vino";
364 static const char *vino_driver_description
= "SGI VINO";
365 static const char *vino_bus_name
= "GIO64 bus";
366 static const char *vino_vdev_name_a
= "SGI VINO Channel A";
367 static const char *vino_vdev_name_b
= "SGI VINO Channel B";
369 static void vino_capture_tasklet(unsigned long channel
);
371 DECLARE_TASKLET(vino_tasklet_a
, vino_capture_tasklet
, VINO_CHANNEL_A
);
372 DECLARE_TASKLET(vino_tasklet_b
, vino_capture_tasklet
, VINO_CHANNEL_B
);
374 static const struct vino_input vino_inputs
[] = {
377 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
381 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
384 .name
= "D1/IndyCam",
385 .std
= V4L2_STD_NTSC
,
389 static const struct vino_data_format vino_data_formats
[] = {
391 .description
= "8-bit greyscale",
393 .pixelformat
= V4L2_PIX_FMT_GREY
,
394 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
396 .description
= "8-bit dithered RGB 3-3-2",
398 .pixelformat
= V4L2_PIX_FMT_RGB332
,
399 .colorspace
= V4L2_COLORSPACE_SRGB
,
401 .description
= "32-bit RGB",
403 .pixelformat
= V4L2_PIX_FMT_RGB32
,
404 .colorspace
= V4L2_COLORSPACE_SRGB
,
406 .description
= "YUV 4:2:2",
408 .pixelformat
= V4L2_PIX_FMT_YUYV
, // XXX: swapped?
409 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
413 static const struct vino_data_norm vino_data_norms
[] = {
415 .description
= "NTSC",
416 .std
= V4L2_STD_NTSC
,
420 .width
= VINO_NTSC_WIDTH
,
421 .height
= VINO_NTSC_HEIGHT
,
423 .top
= VINO_CLIPPING_START_ODD_NTSC
,
425 .bottom
= VINO_CLIPPING_START_ODD_NTSC
426 + VINO_NTSC_HEIGHT
/ 2 - 1,
427 .right
= VINO_NTSC_WIDTH
,
430 .top
= VINO_CLIPPING_START_EVEN_NTSC
,
432 .bottom
= VINO_CLIPPING_START_EVEN_NTSC
433 + VINO_NTSC_HEIGHT
/ 2 - 1,
434 .right
= VINO_NTSC_WIDTH
,
437 .description
= "PAL",
442 .width
= VINO_PAL_WIDTH
,
443 .height
= VINO_PAL_HEIGHT
,
445 .top
= VINO_CLIPPING_START_ODD_PAL
,
447 .bottom
= VINO_CLIPPING_START_ODD_PAL
448 + VINO_PAL_HEIGHT
/ 2 - 1,
449 .right
= VINO_PAL_WIDTH
,
452 .top
= VINO_CLIPPING_START_EVEN_PAL
,
454 .bottom
= VINO_CLIPPING_START_EVEN_PAL
455 + VINO_PAL_HEIGHT
/ 2 - 1,
456 .right
= VINO_PAL_WIDTH
,
459 .description
= "SECAM",
460 .std
= V4L2_STD_SECAM
,
464 .width
= VINO_PAL_WIDTH
,
465 .height
= VINO_PAL_HEIGHT
,
467 .top
= VINO_CLIPPING_START_ODD_PAL
,
469 .bottom
= VINO_CLIPPING_START_ODD_PAL
470 + VINO_PAL_HEIGHT
/ 2 - 1,
471 .right
= VINO_PAL_WIDTH
,
474 .top
= VINO_CLIPPING_START_EVEN_PAL
,
476 .bottom
= VINO_CLIPPING_START_EVEN_PAL
477 + VINO_PAL_HEIGHT
/ 2 - 1,
478 .right
= VINO_PAL_WIDTH
,
481 .description
= "NTSC/D1",
482 .std
= V4L2_STD_NTSC
,
486 .width
= VINO_NTSC_WIDTH
,
487 .height
= VINO_NTSC_HEIGHT
,
489 .top
= VINO_CLIPPING_START_ODD_D1
,
491 .bottom
= VINO_CLIPPING_START_ODD_D1
492 + VINO_NTSC_HEIGHT
/ 2 - 1,
493 .right
= VINO_NTSC_WIDTH
,
496 .top
= VINO_CLIPPING_START_EVEN_D1
,
498 .bottom
= VINO_CLIPPING_START_EVEN_D1
499 + VINO_NTSC_HEIGHT
/ 2 - 1,
500 .right
= VINO_NTSC_WIDTH
,
505 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
507 struct v4l2_queryctrl vino_indycam_v4l2_controls
[] = {
509 .id
= V4L2_CID_AUTOGAIN
,
510 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
511 .name
= "Automatic Gain Control",
515 .default_value
= INDYCAM_AGC_DEFAULT
,
517 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
518 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
519 .name
= "Automatic White Balance",
523 .default_value
= INDYCAM_AWB_DEFAULT
,
526 .type
= V4L2_CTRL_TYPE_INTEGER
,
528 .minimum
= INDYCAM_GAIN_MIN
,
529 .maximum
= INDYCAM_GAIN_MAX
,
531 .default_value
= INDYCAM_GAIN_DEFAULT
,
533 .id
= INDYCAM_CONTROL_RED_SATURATION
,
534 .type
= V4L2_CTRL_TYPE_INTEGER
,
535 .name
= "Red Saturation",
536 .minimum
= INDYCAM_RED_SATURATION_MIN
,
537 .maximum
= INDYCAM_RED_SATURATION_MAX
,
539 .default_value
= INDYCAM_RED_SATURATION_DEFAULT
,
541 .id
= INDYCAM_CONTROL_BLUE_SATURATION
,
542 .type
= V4L2_CTRL_TYPE_INTEGER
,
543 .name
= "Blue Saturation",
544 .minimum
= INDYCAM_BLUE_SATURATION_MIN
,
545 .maximum
= INDYCAM_BLUE_SATURATION_MAX
,
547 .default_value
= INDYCAM_BLUE_SATURATION_DEFAULT
,
549 .id
= V4L2_CID_RED_BALANCE
,
550 .type
= V4L2_CTRL_TYPE_INTEGER
,
551 .name
= "Red Balance",
552 .minimum
= INDYCAM_RED_BALANCE_MIN
,
553 .maximum
= INDYCAM_RED_BALANCE_MAX
,
555 .default_value
= INDYCAM_RED_BALANCE_DEFAULT
,
557 .id
= V4L2_CID_BLUE_BALANCE
,
558 .type
= V4L2_CTRL_TYPE_INTEGER
,
559 .name
= "Blue Balance",
560 .minimum
= INDYCAM_BLUE_BALANCE_MIN
,
561 .maximum
= INDYCAM_BLUE_BALANCE_MAX
,
563 .default_value
= INDYCAM_BLUE_BALANCE_DEFAULT
,
565 .id
= V4L2_CID_EXPOSURE
,
566 .type
= V4L2_CTRL_TYPE_INTEGER
,
567 .name
= "Shutter Control",
568 .minimum
= INDYCAM_SHUTTER_MIN
,
569 .maximum
= INDYCAM_SHUTTER_MAX
,
571 .default_value
= INDYCAM_SHUTTER_DEFAULT
,
573 .id
= V4L2_CID_GAMMA
,
574 .type
= V4L2_CTRL_TYPE_INTEGER
,
576 .minimum
= INDYCAM_GAMMA_MIN
,
577 .maximum
= INDYCAM_GAMMA_MAX
,
579 .default_value
= INDYCAM_GAMMA_DEFAULT
,
583 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
585 struct v4l2_queryctrl vino_saa7191_v4l2_controls
[] = {
588 .type
= V4L2_CTRL_TYPE_INTEGER
,
590 .minimum
= SAA7191_HUE_MIN
,
591 .maximum
= SAA7191_HUE_MAX
,
593 .default_value
= SAA7191_HUE_DEFAULT
,
595 .id
= SAA7191_CONTROL_BANDPASS
,
596 .type
= V4L2_CTRL_TYPE_INTEGER
,
597 .name
= "Luminance Bandpass",
598 .minimum
= SAA7191_BANDPASS_MIN
,
599 .maximum
= SAA7191_BANDPASS_MAX
,
601 .default_value
= SAA7191_BANDPASS_DEFAULT
,
603 .id
= SAA7191_CONTROL_BANDPASS_WEIGHT
,
604 .type
= V4L2_CTRL_TYPE_INTEGER
,
605 .name
= "Luminance Bandpass Weight",
606 .minimum
= SAA7191_BANDPASS_WEIGHT_MIN
,
607 .maximum
= SAA7191_BANDPASS_WEIGHT_MAX
,
609 .default_value
= SAA7191_BANDPASS_WEIGHT_DEFAULT
,
611 .id
= SAA7191_CONTROL_CORING
,
612 .type
= V4L2_CTRL_TYPE_INTEGER
,
613 .name
= "HF Luminance Coring",
614 .minimum
= SAA7191_CORING_MIN
,
615 .maximum
= SAA7191_CORING_MAX
,
617 .default_value
= SAA7191_CORING_DEFAULT
,
619 .id
= SAA7191_CONTROL_FORCE_COLOUR
,
620 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
621 .name
= "Force Colour",
622 .minimum
= SAA7191_FORCE_COLOUR_MIN
,
623 .maximum
= SAA7191_FORCE_COLOUR_MAX
,
625 .default_value
= SAA7191_FORCE_COLOUR_DEFAULT
,
627 .id
= SAA7191_CONTROL_CHROMA_GAIN
,
628 .type
= V4L2_CTRL_TYPE_INTEGER
,
629 .name
= "Chrominance Gain Control",
630 .minimum
= SAA7191_CHROMA_GAIN_MIN
,
631 .maximum
= SAA7191_CHROMA_GAIN_MAX
,
633 .default_value
= SAA7191_CHROMA_GAIN_DEFAULT
,
635 .id
= SAA7191_CONTROL_VTRC
,
636 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
637 .name
= "VTR Time Constant",
638 .minimum
= SAA7191_VTRC_MIN
,
639 .maximum
= SAA7191_VTRC_MAX
,
641 .default_value
= SAA7191_VTRC_DEFAULT
,
643 .id
= SAA7191_CONTROL_LUMA_DELAY
,
644 .type
= V4L2_CTRL_TYPE_INTEGER
,
645 .name
= "Luminance Delay Compensation",
646 .minimum
= SAA7191_LUMA_DELAY_MIN
,
647 .maximum
= SAA7191_LUMA_DELAY_MAX
,
649 .default_value
= SAA7191_LUMA_DELAY_DEFAULT
,
651 .id
= SAA7191_CONTROL_VNR
,
652 .type
= V4L2_CTRL_TYPE_INTEGER
,
653 .name
= "Vertical Noise Reduction",
654 .minimum
= SAA7191_VNR_MIN
,
655 .maximum
= SAA7191_VNR_MAX
,
657 .default_value
= SAA7191_VNR_DEFAULT
,
661 /* VINO framebuffer/DMA descriptor management */
663 static void vino_free_buffer_with_count(struct vino_framebuffer
*fb
,
668 dprintk("vino_free_buffer_with_count(): count = %d\n", count
);
670 for (i
= 0; i
< count
; i
++) {
671 ClearPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
672 dma_unmap_single(NULL
,
673 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
674 PAGE_SIZE
, DMA_FROM_DEVICE
);
675 free_page(fb
->desc_table
.virtual[i
]);
678 dma_free_coherent(NULL
,
679 VINO_PAGE_RATIO
* (fb
->desc_table
.page_count
+ 4) *
680 sizeof(dma_addr_t
), (void *)fb
->desc_table
.dma_cpu
,
682 kfree(fb
->desc_table
.virtual);
684 memset(fb
, 0, sizeof(struct vino_framebuffer
));
687 static void vino_free_buffer(struct vino_framebuffer
*fb
)
689 vino_free_buffer_with_count(fb
, fb
->desc_table
.page_count
);
692 static int vino_allocate_buffer(struct vino_framebuffer
*fb
,
695 unsigned int count
, i
, j
;
698 dprintk("vino_allocate_buffer():\n");
703 memset(fb
, 0, sizeof(struct vino_framebuffer
));
705 count
= ((size
/ PAGE_SIZE
) + 4) & ~3;
707 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
710 /* allocate memory for table with virtual (page) addresses */
711 fb
->desc_table
.virtual = (unsigned long *)
712 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
713 if (!fb
->desc_table
.virtual)
716 /* allocate memory for table with dma addresses
717 * (has space for four extra descriptors) */
718 fb
->desc_table
.dma_cpu
=
719 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
720 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
721 GFP_KERNEL
| GFP_DMA
);
722 if (!fb
->desc_table
.dma_cpu
) {
724 goto out_free_virtual
;
727 /* allocate pages for the buffer and acquire the according
729 for (i
= 0; i
< count
; i
++) {
730 dma_addr_t dma_data_addr
;
732 fb
->desc_table
.virtual[i
] =
733 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
734 if (!fb
->desc_table
.virtual[i
]) {
741 (void *)fb
->desc_table
.virtual[i
],
742 PAGE_SIZE
, DMA_FROM_DEVICE
);
744 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
745 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
746 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
749 SetPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
752 /* page_count needs to be set anyway, because the descriptor table has
753 * been allocated according to this number */
754 fb
->desc_table
.page_count
= count
;
757 /* the descriptor with index i doesn't contain
758 * a valid address yet */
759 vino_free_buffer_with_count(fb
, i
);
764 fb
->size
= count
* PAGE_SIZE
;
765 fb
->data_format
= VINO_DATA_FMT_NONE
;
767 /* set the dma stop-bit for the last (count+1)th descriptor */
768 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
772 kfree(fb
->desc_table
.virtual);
777 /* user buffers not fully implemented yet */
778 static int vino_prepare_user_buffer(struct vino_framebuffer
*fb
,
782 unsigned int count
, i
, j
;
785 dprintk("vino_prepare_user_buffer():\n");
790 memset(fb
, 0, sizeof(struct vino_framebuffer
));
792 count
= ((size
/ PAGE_SIZE
)) & ~3;
794 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
797 /* allocate memory for table with virtual (page) addresses */
798 fb
->desc_table
.virtual = (unsigned long *)
799 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
800 if (!fb
->desc_table
.virtual)
803 /* allocate memory for table with dma addresses
804 * (has space for four extra descriptors) */
805 fb
->desc_table
.dma_cpu
=
806 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
807 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
808 GFP_KERNEL
| GFP_DMA
);
809 if (!fb
->desc_table
.dma_cpu
) {
811 goto out_free_virtual
;
814 /* allocate pages for the buffer and acquire the according
816 for (i
= 0; i
< count
; i
++) {
817 dma_addr_t dma_data_addr
;
819 fb
->desc_table
.virtual[i
] =
820 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
821 if (!fb
->desc_table
.virtual[i
]) {
828 (void *)fb
->desc_table
.virtual[i
],
829 PAGE_SIZE
, DMA_FROM_DEVICE
);
831 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
832 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
833 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
836 SetPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
839 /* page_count needs to be set anyway, because the descriptor table has
840 * been allocated according to this number */
841 fb
->desc_table
.page_count
= count
;
844 /* the descriptor with index i doesn't contain
845 * a valid address yet */
846 vino_free_buffer_with_count(fb
, i
);
851 fb
->size
= count
* PAGE_SIZE
;
853 /* set the dma stop-bit for the last (count+1)th descriptor */
854 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
858 kfree(fb
->desc_table
.virtual);
863 static void vino_sync_buffer(struct vino_framebuffer
*fb
)
867 dprintk("vino_sync_buffer():\n");
869 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++)
870 dma_sync_single_for_cpu(NULL
,
871 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
872 PAGE_SIZE
, DMA_FROM_DEVICE
);
875 /* Framebuffer fifo functions (need to be locked externally) */
877 static inline void vino_fifo_init(struct vino_framebuffer_fifo
*f
,
885 if (length
> VINO_FRAMEBUFFER_COUNT_MAX
)
886 length
= VINO_FRAMEBUFFER_COUNT_MAX
;
891 /* returns true/false */
892 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo
*f
,
897 for (i
= f
->head
; i
== (f
->tail
- 1); i
= (i
+ 1) % f
->length
) {
898 if (f
->data
[i
] == id
)
906 /* returns true/false */
907 static inline int vino_fifo_full(struct vino_framebuffer_fifo
*f
)
909 return (f
->used
== f
->length
);
913 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo
*f
)
918 static int vino_fifo_enqueue(struct vino_framebuffer_fifo
*f
, unsigned int id
)
920 if (id
>= f
->length
) {
921 return VINO_QUEUE_ERROR
;
924 if (vino_fifo_has_id(f
, id
)) {
925 return VINO_QUEUE_ERROR
;
928 if (f
->used
< f
->length
) {
929 f
->data
[f
->tail
] = id
;
930 f
->tail
= (f
->tail
+ 1) % f
->length
;
933 return VINO_QUEUE_ERROR
;
939 static int vino_fifo_peek(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
942 *id
= f
->data
[f
->head
];
944 return VINO_QUEUE_ERROR
;
950 static int vino_fifo_dequeue(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
953 *id
= f
->data
[f
->head
];
954 f
->head
= (f
->head
+ 1) % f
->length
;
957 return VINO_QUEUE_ERROR
;
963 /* Framebuffer queue functions */
965 /* execute with queue_lock locked */
966 static void vino_queue_free_with_count(struct vino_framebuffer_queue
*q
,
972 memset(&q
->in
, 0, sizeof(struct vino_framebuffer_fifo
));
973 memset(&q
->out
, 0, sizeof(struct vino_framebuffer_fifo
));
974 for (i
= 0; i
< length
; i
++) {
975 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
977 vino_free_buffer(q
->buffer
[i
]);
981 q
->type
= VINO_MEMORY_NONE
;
985 static void vino_queue_free(struct vino_framebuffer_queue
*q
)
987 dprintk("vino_queue_free():\n");
989 if (q
->magic
!= VINO_QUEUE_MAGIC
)
991 if (q
->type
!= VINO_MEMORY_MMAP
)
994 mutex_lock(&q
->queue_mutex
);
996 vino_queue_free_with_count(q
, q
->length
);
998 mutex_unlock(&q
->queue_mutex
);
1001 static int vino_queue_init(struct vino_framebuffer_queue
*q
,
1002 unsigned int *length
)
1007 dprintk("vino_queue_init(): length = %d\n", *length
);
1009 if (q
->magic
== VINO_QUEUE_MAGIC
) {
1010 dprintk("vino_queue_init(): queue already initialized!\n");
1014 if (q
->type
!= VINO_MEMORY_NONE
) {
1015 dprintk("vino_queue_init(): queue already initialized!\n");
1022 mutex_lock(&q
->queue_mutex
);
1024 if (*length
> VINO_FRAMEBUFFER_COUNT_MAX
)
1025 *length
= VINO_FRAMEBUFFER_COUNT_MAX
;
1029 for (i
= 0; i
< *length
; i
++) {
1030 dprintk("vino_queue_init(): allocating buffer %d\n", i
);
1031 q
->buffer
[i
] = kmalloc(sizeof(struct vino_framebuffer
),
1033 if (!q
->buffer
[i
]) {
1034 dprintk("vino_queue_init(): kmalloc() failed\n");
1039 ret
= vino_allocate_buffer(q
->buffer
[i
],
1040 VINO_FRAMEBUFFER_SIZE
);
1042 kfree(q
->buffer
[i
]);
1043 dprintk("vino_queue_init(): "
1044 "vino_allocate_buffer() failed\n");
1048 q
->buffer
[i
]->id
= i
;
1050 q
->buffer
[i
]->offset
= q
->buffer
[i
- 1]->offset
+
1051 q
->buffer
[i
- 1]->size
;
1053 q
->buffer
[i
]->offset
= 0;
1056 spin_lock_init(&q
->buffer
[i
]->state_lock
);
1058 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1059 "size = %d\n", i
, q
->buffer
[i
]->offset
,
1060 q
->buffer
[i
]->size
);
1064 vino_queue_free_with_count(q
, i
);
1067 q
->length
= *length
;
1068 vino_fifo_init(&q
->in
, q
->length
);
1069 vino_fifo_init(&q
->out
, q
->length
);
1070 q
->type
= VINO_MEMORY_MMAP
;
1071 q
->magic
= VINO_QUEUE_MAGIC
;
1074 mutex_unlock(&q
->queue_mutex
);
1079 static struct vino_framebuffer
*vino_queue_add(struct
1080 vino_framebuffer_queue
*q
,
1083 struct vino_framebuffer
*ret
= NULL
;
1085 unsigned long flags
;
1087 dprintk("vino_queue_add(): id = %d\n", id
);
1089 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1093 spin_lock_irqsave(&q
->queue_lock
, flags
);
1098 if (id
>= q
->length
)
1101 /* not needed?: if (vino_fifo_full(&q->out)) {
1104 /* check that outgoing queue isn't already full
1105 * (or that it won't become full) */
1106 total
= vino_fifo_get_used(&q
->in
) +
1107 vino_fifo_get_used(&q
->out
);
1108 if (total
>= q
->length
)
1111 if (vino_fifo_enqueue(&q
->in
, id
))
1114 ret
= q
->buffer
[id
];
1117 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1122 static struct vino_framebuffer
*vino_queue_transfer(struct
1123 vino_framebuffer_queue
*q
)
1125 struct vino_framebuffer
*ret
= NULL
;
1126 struct vino_framebuffer
*fb
;
1128 unsigned long flags
;
1130 dprintk("vino_queue_transfer():\n");
1132 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1136 spin_lock_irqsave(&q
->queue_lock
, flags
);
1141 // now this actually removes an entry from the incoming queue
1142 if (vino_fifo_dequeue(&q
->in
, &id
)) {
1146 dprintk("vino_queue_transfer(): id = %d\n", id
);
1149 // we have already checked that the outgoing queue is not full, but...
1150 if (vino_fifo_enqueue(&q
->out
, id
)) {
1151 printk(KERN_ERR
"vino_queue_transfer(): "
1152 "outgoing queue is full, this shouldn't happen!\n");
1158 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1163 /* returns true/false */
1164 static int vino_queue_incoming_contains(struct vino_framebuffer_queue
*q
,
1168 unsigned long flags
;
1170 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1174 spin_lock_irqsave(&q
->queue_lock
, flags
);
1179 ret
= vino_fifo_has_id(&q
->in
, id
);
1182 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1187 /* returns true/false */
1188 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue
*q
,
1192 unsigned long flags
;
1194 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1198 spin_lock_irqsave(&q
->queue_lock
, flags
);
1203 ret
= vino_fifo_has_id(&q
->out
, id
);
1206 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1211 static int vino_queue_get_incoming(struct vino_framebuffer_queue
*q
,
1215 unsigned long flags
;
1217 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1218 return VINO_QUEUE_ERROR
;
1221 spin_lock_irqsave(&q
->queue_lock
, flags
);
1223 if (q
->length
== 0) {
1224 ret
= VINO_QUEUE_ERROR
;
1228 *used
= vino_fifo_get_used(&q
->in
);
1231 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1236 static int vino_queue_get_outgoing(struct vino_framebuffer_queue
*q
,
1240 unsigned long flags
;
1242 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1243 return VINO_QUEUE_ERROR
;
1246 spin_lock_irqsave(&q
->queue_lock
, flags
);
1248 if (q
->length
== 0) {
1249 ret
= VINO_QUEUE_ERROR
;
1253 *used
= vino_fifo_get_used(&q
->out
);
1256 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1262 static int vino_queue_get_total(struct vino_framebuffer_queue
*q
,
1263 unsigned int *total
)
1266 unsigned long flags
;
1268 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1269 return VINO_QUEUE_ERROR
;
1272 spin_lock_irqsave(&q
->queue_lock
, flags
);
1274 if (q
->length
== 0) {
1275 ret
= VINO_QUEUE_ERROR
;
1279 *total
= vino_fifo_get_used(&q
->in
) +
1280 vino_fifo_get_used(&q
->out
);
1283 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1289 static struct vino_framebuffer
*vino_queue_peek(struct
1290 vino_framebuffer_queue
*q
,
1293 struct vino_framebuffer
*ret
= NULL
;
1294 unsigned long flags
;
1296 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1300 spin_lock_irqsave(&q
->queue_lock
, flags
);
1305 if (vino_fifo_peek(&q
->in
, id
)) {
1309 ret
= q
->buffer
[*id
];
1311 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1316 static struct vino_framebuffer
*vino_queue_remove(struct
1317 vino_framebuffer_queue
*q
,
1320 struct vino_framebuffer
*ret
= NULL
;
1321 unsigned long flags
;
1322 dprintk("vino_queue_remove():\n");
1324 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1328 spin_lock_irqsave(&q
->queue_lock
, flags
);
1333 if (vino_fifo_dequeue(&q
->out
, id
)) {
1337 dprintk("vino_queue_remove(): id = %d\n", *id
);
1338 ret
= q
->buffer
[*id
];
1340 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1346 vino_framebuffer
*vino_queue_get_buffer(struct vino_framebuffer_queue
*q
,
1349 struct vino_framebuffer
*ret
= NULL
;
1350 unsigned long flags
;
1352 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1356 spin_lock_irqsave(&q
->queue_lock
, flags
);
1361 if (id
>= q
->length
)
1364 ret
= q
->buffer
[id
];
1366 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1371 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue
*q
)
1373 unsigned int length
= 0;
1374 unsigned long flags
;
1376 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1380 spin_lock_irqsave(&q
->queue_lock
, flags
);
1382 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1387 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue
*q
)
1391 unsigned long flags
;
1393 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1397 spin_lock_irqsave(&q
->queue_lock
, flags
);
1398 for (i
= 0; i
< q
->length
; i
++) {
1399 if (q
->buffer
[i
]->map_count
> 0) {
1404 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1409 /* VINO functions */
1411 /* execute with input_lock locked */
1412 static void vino_update_line_size(struct vino_channel_settings
*vcs
)
1414 unsigned int w
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1415 unsigned int d
= vcs
->decimation
;
1416 unsigned int bpp
= vino_data_formats
[vcs
->data_format
].bpp
;
1419 dprintk("update_line_size(): before: w = %d, d = %d, "
1420 "line_size = %d\n", w
, d
, vcs
->line_size
);
1422 /* line size must be multiple of 8 bytes */
1423 lsize
= (bpp
* (w
/ d
)) & ~7;
1424 w
= (lsize
/ bpp
) * d
;
1426 vcs
->clipping
.right
= vcs
->clipping
.left
+ w
;
1427 vcs
->line_size
= lsize
;
1429 dprintk("update_line_size(): after: w = %d, d = %d, "
1430 "line_size = %d\n", w
, d
, vcs
->line_size
);
1433 /* execute with input_lock locked */
1434 static void vino_set_clipping(struct vino_channel_settings
*vcs
,
1435 unsigned int x
, unsigned int y
,
1436 unsigned int w
, unsigned int h
)
1438 unsigned int maxwidth
, maxheight
;
1441 maxwidth
= vino_data_norms
[vcs
->data_norm
].width
;
1442 maxheight
= vino_data_norms
[vcs
->data_norm
].height
;
1443 d
= vcs
->decimation
;
1445 y
&= ~1; /* odd/even fields */
1450 if (y
> maxheight
) {
1454 if (((w
/ d
) < VINO_MIN_WIDTH
)
1455 || ((h
/ d
) < VINO_MIN_HEIGHT
)) {
1456 w
= VINO_MIN_WIDTH
* d
;
1457 h
= VINO_MIN_HEIGHT
* d
;
1460 if ((x
+ w
) > maxwidth
) {
1462 if ((w
/ d
) < VINO_MIN_WIDTH
)
1463 x
= maxwidth
- VINO_MIN_WIDTH
* d
;
1465 if ((y
+ h
) > maxheight
) {
1467 if ((h
/ d
) < VINO_MIN_HEIGHT
)
1468 y
= maxheight
- VINO_MIN_HEIGHT
* d
;
1471 vcs
->clipping
.left
= x
;
1472 vcs
->clipping
.top
= y
;
1473 vcs
->clipping
.right
= x
+ w
;
1474 vcs
->clipping
.bottom
= y
+ h
;
1476 vino_update_line_size(vcs
);
1478 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1479 vcs
->clipping
.left
, vcs
->clipping
.top
, vcs
->clipping
.right
,
1480 vcs
->clipping
.bottom
, vcs
->decimation
, vcs
->line_size
);
1483 /* execute with input_lock locked */
1484 static inline void vino_set_default_clipping(struct vino_channel_settings
*vcs
)
1486 vino_set_clipping(vcs
, 0, 0, vino_data_norms
[vcs
->data_norm
].width
,
1487 vino_data_norms
[vcs
->data_norm
].height
);
1490 /* execute with input_lock locked */
1491 static void vino_set_scaling(struct vino_channel_settings
*vcs
,
1492 unsigned int w
, unsigned int h
)
1494 unsigned int x
, y
, curw
, curh
, d
;
1496 x
= vcs
->clipping
.left
;
1497 y
= vcs
->clipping
.top
;
1498 curw
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1499 curh
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
1501 d
= max(curw
/ w
, curh
/ h
);
1503 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1504 w
, h
, curw
, curh
, d
);
1512 vcs
->decimation
= d
;
1513 vino_set_clipping(vcs
, x
, y
, w
* d
, h
* d
);
1515 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs
->clipping
.left
,
1516 vcs
->clipping
.top
, vcs
->clipping
.right
, vcs
->clipping
.bottom
,
1517 vcs
->decimation
, vcs
->line_size
);
1520 /* execute with input_lock locked */
1521 static inline void vino_set_default_scaling(struct vino_channel_settings
*vcs
)
1523 vino_set_scaling(vcs
, vcs
->clipping
.right
- vcs
->clipping
.left
,
1524 vcs
->clipping
.bottom
- vcs
->clipping
.top
);
1527 /* execute with input_lock locked */
1528 static void vino_set_framerate(struct vino_channel_settings
*vcs
,
1533 switch (vcs
->data_norm
) {
1534 case VINO_DATA_NORM_NTSC
:
1535 case VINO_DATA_NORM_D1
:
1536 fps
= (unsigned int)(fps
/ 6) * 6; // FIXME: round!
1538 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1539 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1540 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1541 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1560 mask
= VINO_FRAMERT_FULL
;
1562 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
);
1564 case VINO_DATA_NORM_PAL
:
1565 case VINO_DATA_NORM_SECAM
:
1566 fps
= (unsigned int)(fps
/ 5) * 5; // FIXME: round!
1568 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1569 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1570 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1571 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1590 mask
= VINO_FRAMERT_FULL
;
1592 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
) | VINO_FRAMERT_PAL
;
1599 /* execute with input_lock locked */
1600 static inline void vino_set_default_framerate(struct
1601 vino_channel_settings
*vcs
)
1603 vino_set_framerate(vcs
, vino_data_norms
[vcs
->data_norm
].fps_max
);
1606 /* VINO I2C bus functions */
1608 struct i2c_algo_sgi_data
{
1609 void *data
; /* private data for lowlevel routines */
1610 unsigned (*getctrl
)(void *data
);
1611 void (*setctrl
)(void *data
, unsigned val
);
1612 unsigned (*rdata
)(void *data
);
1613 void (*wdata
)(void *data
, unsigned val
);
1619 static int wait_xfer_done(struct i2c_algo_sgi_data
*adap
)
1623 for (i
= 0; i
< adap
->xfer_timeout
; i
++) {
1624 if ((adap
->getctrl(adap
->data
) & SGI_I2C_XFER_BUSY
) == 0)
1632 static int wait_ack(struct i2c_algo_sgi_data
*adap
)
1636 if (wait_xfer_done(adap
))
1638 for (i
= 0; i
< adap
->ack_timeout
; i
++) {
1639 if ((adap
->getctrl(adap
->data
) & SGI_I2C_NACK
) == 0)
1647 static int force_idle(struct i2c_algo_sgi_data
*adap
)
1651 adap
->setctrl(adap
->data
, SGI_I2C_FORCE_IDLE
);
1652 for (i
= 0; i
< adap
->xfer_timeout
; i
++) {
1653 if ((adap
->getctrl(adap
->data
) & SGI_I2C_NOT_IDLE
) == 0)
1659 if (adap
->getctrl(adap
->data
) & SGI_I2C_BUS_ERR
)
1664 static int do_address(struct i2c_algo_sgi_data
*adap
, unsigned int addr
,
1668 adap
->setctrl(adap
->data
, SGI_I2C_NOT_IDLE
);
1669 /* Check if bus is idle, eventually force it to do so */
1670 if (adap
->getctrl(adap
->data
) & SGI_I2C_NOT_IDLE
)
1671 if (force_idle(adap
))
1673 /* Write out the i2c chip address and specify operation */
1674 adap
->setctrl(adap
->data
,
1675 SGI_I2C_HOLD_BUS
| SGI_I2C_WRITE
| SGI_I2C_NOT_IDLE
);
1678 adap
->wdata(adap
->data
, addr
);
1684 static int i2c_read(struct i2c_algo_sgi_data
*adap
, unsigned char *buf
,
1689 adap
->setctrl(adap
->data
,
1690 SGI_I2C_HOLD_BUS
| SGI_I2C_READ
| SGI_I2C_NOT_IDLE
);
1691 for (i
= 0; i
< len
; i
++) {
1692 if (wait_xfer_done(adap
))
1694 buf
[i
] = adap
->rdata(adap
->data
);
1696 adap
->setctrl(adap
->data
, SGI_I2C_RELEASE_BUS
| SGI_I2C_FORCE_IDLE
);
1702 static int i2c_write(struct i2c_algo_sgi_data
*adap
, unsigned char *buf
,
1707 /* We are already in write state */
1708 for (i
= 0; i
< len
; i
++) {
1709 adap
->wdata(adap
->data
, buf
[i
]);
1716 static int sgi_xfer(struct i2c_adapter
*i2c_adap
, struct i2c_msg
*msgs
,
1719 struct i2c_algo_sgi_data
*adap
= i2c_adap
->algo_data
;
1723 for (i
= 0; !err
&& i
< num
; i
++) {
1725 err
= do_address(adap
, p
->addr
, p
->flags
& I2C_M_RD
);
1728 if (p
->flags
& I2C_M_RD
)
1729 err
= i2c_read(adap
, p
->buf
, p
->len
);
1731 err
= i2c_write(adap
, p
->buf
, p
->len
);
1734 return (err
< 0) ? err
: i
;
1737 static u32
sgi_func(struct i2c_adapter
*adap
)
1739 return I2C_FUNC_SMBUS_EMUL
;
1742 static const struct i2c_algorithm sgi_algo
= {
1743 .master_xfer
= sgi_xfer
,
1744 .functionality
= sgi_func
,
1747 static unsigned i2c_vino_getctrl(void *data
)
1749 return vino
->i2c_control
;
1752 static void i2c_vino_setctrl(void *data
, unsigned val
)
1754 vino
->i2c_control
= val
;
1757 static unsigned i2c_vino_rdata(void *data
)
1759 return vino
->i2c_data
;
1762 static void i2c_vino_wdata(void *data
, unsigned val
)
1764 vino
->i2c_data
= val
;
1767 static struct i2c_algo_sgi_data i2c_sgi_vino_data
= {
1768 .getctrl
= &i2c_vino_getctrl
,
1769 .setctrl
= &i2c_vino_setctrl
,
1770 .rdata
= &i2c_vino_rdata
,
1771 .wdata
= &i2c_vino_wdata
,
1772 .xfer_timeout
= 200,
1773 .ack_timeout
= 1000,
1776 static struct i2c_adapter vino_i2c_adapter
= {
1777 .name
= "VINO I2C bus",
1779 .algo_data
= &i2c_sgi_vino_data
,
1780 .owner
= THIS_MODULE
,
1784 * Prepare VINO for DMA transfer...
1785 * (execute only with vino_lock and input_lock locked)
1787 static int vino_dma_setup(struct vino_channel_settings
*vcs
,
1788 struct vino_framebuffer
*fb
)
1791 struct sgi_vino_channel
*ch
;
1792 const struct vino_data_norm
*norm
;
1794 dprintk("vino_dma_setup():\n");
1797 fb
->frame_counter
= 0;
1799 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1800 norm
= &vino_data_norms
[vcs
->data_norm
];
1805 /* VINO line size register is set 8 bytes less than actual */
1806 ch
->line_size
= vcs
->line_size
- 8;
1808 /* let VINO know where to transfer data */
1809 ch
->start_desc_tbl
= fb
->desc_table
.dma
;
1810 ch
->next_4_desc
= fb
->desc_table
.dma
;
1812 /* give vino time to fetch the first four descriptors, 5 usec
1813 * should be more than enough time */
1814 udelay(VINO_DESC_FETCH_DELAY
);
1816 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1817 ch
->start_desc_tbl
, ch
->next_4_desc
);
1819 /* set the alpha register */
1820 ch
->alpha
= vcs
->alpha
;
1822 /* set clipping registers */
1823 ch
->clip_start
= VINO_CLIP_ODD(norm
->odd
.top
+ vcs
->clipping
.top
/ 2) |
1824 VINO_CLIP_EVEN(norm
->even
.top
+
1825 vcs
->clipping
.top
/ 2) |
1826 VINO_CLIP_X(vcs
->clipping
.left
);
1827 ch
->clip_end
= VINO_CLIP_ODD(norm
->odd
.top
+
1828 vcs
->clipping
.bottom
/ 2 - 1) |
1829 VINO_CLIP_EVEN(norm
->even
.top
+
1830 vcs
->clipping
.bottom
/ 2 - 1) |
1831 VINO_CLIP_X(vcs
->clipping
.right
);
1833 /* set the size of actual content in the buffer (DECIMATION !) */
1834 fb
->data_size
= ((vcs
->clipping
.right
- vcs
->clipping
.left
) /
1836 ((vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
1838 vino_data_formats
[vcs
->data_format
].bpp
;
1840 ch
->frame_rate
= vcs
->framert_reg
;
1842 ctrl
= vino
->control
;
1843 intr
= vino
->intr_status
;
1845 if (vcs
->channel
== VINO_CHANNEL_A
) {
1846 /* All interrupt conditions for this channel was cleared
1847 * so clear the interrupt status register and enable
1849 intr
&= ~VINO_INTSTAT_A
;
1850 ctrl
|= VINO_CTRL_A_INT
;
1852 /* enable synchronization */
1853 ctrl
|= VINO_CTRL_A_SYNC_ENBL
;
1855 /* enable frame assembly */
1856 ctrl
|= VINO_CTRL_A_INTERLEAVE_ENBL
;
1858 /* set decimation used */
1859 if (vcs
->decimation
< 2)
1860 ctrl
&= ~VINO_CTRL_A_DEC_ENBL
;
1862 ctrl
|= VINO_CTRL_A_DEC_ENBL
;
1863 ctrl
&= ~VINO_CTRL_A_DEC_SCALE_MASK
;
1864 ctrl
|= (vcs
->decimation
- 1) <<
1865 VINO_CTRL_A_DEC_SCALE_SHIFT
;
1868 /* select input interface */
1869 if (vcs
->input
== VINO_INPUT_D1
)
1870 ctrl
|= VINO_CTRL_A_SELECT
;
1872 ctrl
&= ~VINO_CTRL_A_SELECT
;
1875 ctrl
&= ~(VINO_CTRL_A_LUMA_ONLY
| VINO_CTRL_A_RGB
|
1876 VINO_CTRL_A_DITHER
);
1878 intr
&= ~VINO_INTSTAT_B
;
1879 ctrl
|= VINO_CTRL_B_INT
;
1881 ctrl
|= VINO_CTRL_B_SYNC_ENBL
;
1882 ctrl
|= VINO_CTRL_B_INTERLEAVE_ENBL
;
1884 if (vcs
->decimation
< 2)
1885 ctrl
&= ~VINO_CTRL_B_DEC_ENBL
;
1887 ctrl
|= VINO_CTRL_B_DEC_ENBL
;
1888 ctrl
&= ~VINO_CTRL_B_DEC_SCALE_MASK
;
1889 ctrl
|= (vcs
->decimation
- 1) <<
1890 VINO_CTRL_B_DEC_SCALE_SHIFT
;
1893 if (vcs
->input
== VINO_INPUT_D1
)
1894 ctrl
|= VINO_CTRL_B_SELECT
;
1896 ctrl
&= ~VINO_CTRL_B_SELECT
;
1898 ctrl
&= ~(VINO_CTRL_B_LUMA_ONLY
| VINO_CTRL_B_RGB
|
1899 VINO_CTRL_B_DITHER
);
1903 fb
->data_format
= vcs
->data_format
;
1905 switch (vcs
->data_format
) {
1906 case VINO_DATA_FMT_GREY
:
1907 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1908 VINO_CTRL_A_LUMA_ONLY
: VINO_CTRL_B_LUMA_ONLY
;
1910 case VINO_DATA_FMT_RGB32
:
1911 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1912 VINO_CTRL_A_RGB
: VINO_CTRL_B_RGB
;
1914 case VINO_DATA_FMT_YUV
:
1915 /* nothing needs to be done */
1917 case VINO_DATA_FMT_RGB332
:
1918 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1919 VINO_CTRL_A_RGB
| VINO_CTRL_A_DITHER
:
1920 VINO_CTRL_B_RGB
| VINO_CTRL_B_DITHER
;
1924 vino
->intr_status
= intr
;
1925 vino
->control
= ctrl
;
1930 /* (execute only with vino_lock locked) */
1931 static inline void vino_dma_start(struct vino_channel_settings
*vcs
)
1933 u32 ctrl
= vino
->control
;
1935 dprintk("vino_dma_start():\n");
1936 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1937 VINO_CTRL_A_DMA_ENBL
: VINO_CTRL_B_DMA_ENBL
;
1938 vino
->control
= ctrl
;
1941 /* (execute only with vino_lock locked) */
1942 static inline void vino_dma_stop(struct vino_channel_settings
*vcs
)
1944 u32 ctrl
= vino
->control
;
1946 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1947 ~VINO_CTRL_A_DMA_ENBL
: ~VINO_CTRL_B_DMA_ENBL
;
1948 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1949 ~VINO_CTRL_A_INT
: ~VINO_CTRL_B_INT
;
1950 vino
->control
= ctrl
;
1951 dprintk("vino_dma_stop():\n");
1955 * Load dummy page to descriptor registers. This prevents generating of
1956 * spurious interrupts. (execute only with vino_lock locked)
1958 static void vino_clear_interrupt(struct vino_channel_settings
*vcs
)
1960 struct sgi_vino_channel
*ch
;
1962 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1967 ch
->start_desc_tbl
= vino_drvdata
->dummy_desc_table
.dma
;
1968 ch
->next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
1970 udelay(VINO_DESC_FETCH_DELAY
);
1971 dprintk("channel %c clear interrupt condition\n",
1972 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A':'B');
1975 static int vino_capture(struct vino_channel_settings
*vcs
,
1976 struct vino_framebuffer
*fb
)
1979 unsigned long flags
, flags2
;
1981 spin_lock_irqsave(&fb
->state_lock
, flags
);
1983 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
1985 fb
->state
= VINO_FRAMEBUFFER_IN_USE
;
1987 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
1992 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
1993 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags2
);
1995 vino_dma_setup(vcs
, fb
);
1996 vino_dma_start(vcs
);
1998 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags2
);
1999 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2005 struct vino_framebuffer
*vino_capture_enqueue(struct
2006 vino_channel_settings
*vcs
,
2009 struct vino_framebuffer
*fb
;
2010 unsigned long flags
;
2012 dprintk("vino_capture_enqueue():\n");
2014 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2016 fb
= vino_queue_add(&vcs
->fb_queue
, index
);
2018 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
2023 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2028 static int vino_capture_next(struct vino_channel_settings
*vcs
, int start
)
2030 struct vino_framebuffer
*fb
;
2031 unsigned int incoming
, id
;
2033 unsigned long flags
;
2035 dprintk("vino_capture_next():\n");
2037 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2040 /* start capture only if capture isn't in progress already */
2041 if (vcs
->capturing
) {
2042 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2047 /* capture next frame:
2048 * stop capture if capturing is not set */
2049 if (!vcs
->capturing
) {
2050 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2055 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
2057 dprintk("vino_capture_next(): vino_queue_get_incoming() "
2062 if (incoming
== 0) {
2063 dprintk("vino_capture_next(): no buffers available\n");
2067 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2069 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
2078 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2080 err
= vino_capture(vcs
, fb
);
2086 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2091 static inline int vino_is_capturing(struct vino_channel_settings
*vcs
)
2094 unsigned long flags
;
2096 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2098 ret
= vcs
->capturing
;
2100 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2105 /* waits until a frame is captured */
2106 static int vino_wait_for_frame(struct vino_channel_settings
*vcs
)
2111 dprintk("vino_wait_for_frame():\n");
2113 init_waitqueue_entry(&wait
, current
);
2114 /* add ourselves into wait queue */
2115 add_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2117 /* to ensure that schedule_timeout will return immediately
2118 * if VINO interrupt was triggered meanwhile */
2119 schedule_timeout_interruptible(msecs_to_jiffies(100));
2121 if (signal_pending(current
))
2124 remove_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2126 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2127 err
? "failed" : "ok");
2132 /* the function assumes that PAGE_SIZE % 4 == 0 */
2133 static void vino_convert_to_rgba(struct vino_framebuffer
*fb
) {
2134 unsigned char *pageptr
;
2135 unsigned int page
, i
;
2138 for (page
= 0; page
< fb
->desc_table
.page_count
; page
++) {
2139 pageptr
= (unsigned char *)fb
->desc_table
.virtual[page
];
2141 for (i
= 0; i
< PAGE_SIZE
; i
+= 4) {
2143 pageptr
[0] = pageptr
[3];
2144 pageptr
[1] = pageptr
[2];
2145 pageptr
[2] = pageptr
[1];
2152 /* checks if the buffer is in correct state and syncs data */
2153 static int vino_check_buffer(struct vino_channel_settings
*vcs
,
2154 struct vino_framebuffer
*fb
)
2157 unsigned long flags
;
2159 dprintk("vino_check_buffer():\n");
2161 spin_lock_irqsave(&fb
->state_lock
, flags
);
2162 switch (fb
->state
) {
2163 case VINO_FRAMEBUFFER_IN_USE
:
2166 case VINO_FRAMEBUFFER_READY
:
2167 vino_sync_buffer(fb
);
2168 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2173 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2176 if (vino_pixel_conversion
2177 && (fb
->data_format
== VINO_DATA_FMT_RGB32
)) {
2178 vino_convert_to_rgba(fb
);
2180 } else if (err
&& (err
!= -EINVAL
)) {
2181 dprintk("vino_check_buffer(): buffer not ready\n");
2183 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2185 vino_clear_interrupt(vcs
);
2186 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2192 /* forcefully terminates capture */
2193 static void vino_capture_stop(struct vino_channel_settings
*vcs
)
2195 unsigned int incoming
= 0, outgoing
= 0, id
;
2196 unsigned long flags
, flags2
;
2198 dprintk("vino_capture_stop():\n");
2200 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2202 /* unset capturing to stop queue processing */
2205 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags2
);
2208 vino_clear_interrupt(vcs
);
2210 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags2
);
2212 /* remove all items from the queue */
2213 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2214 dprintk("vino_capture_stop(): "
2215 "vino_queue_get_incoming() failed\n");
2218 while (incoming
> 0) {
2219 vino_queue_transfer(&vcs
->fb_queue
);
2221 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2222 dprintk("vino_capture_stop(): "
2223 "vino_queue_get_incoming() failed\n");
2228 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2229 dprintk("vino_capture_stop(): "
2230 "vino_queue_get_outgoing() failed\n");
2233 while (outgoing
> 0) {
2234 vino_queue_remove(&vcs
->fb_queue
, &id
);
2236 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2237 dprintk("vino_capture_stop(): "
2238 "vino_queue_get_outgoing() failed\n");
2244 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2248 static int vino_capture_failed(struct vino_channel_settings
*vcs
)
2250 struct vino_framebuffer
*fb
;
2251 unsigned long flags
;
2255 dprintk("vino_capture_failed():\n");
2257 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2260 vino_clear_interrupt(vcs
);
2262 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2264 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &i
);
2265 if (ret
== VINO_QUEUE_ERROR
) {
2266 dprintk("vino_queue_get_incoming() failed\n");
2270 /* no buffers to process */
2274 fb
= vino_queue_peek(&vcs
->fb_queue
, &i
);
2276 dprintk("vino_queue_peek() failed\n");
2280 spin_lock_irqsave(&fb
->state_lock
, flags
);
2281 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
) {
2282 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2283 vino_queue_transfer(&vcs
->fb_queue
);
2284 vino_queue_remove(&vcs
->fb_queue
, &i
);
2285 /* we should actually discard the newest frame,
2286 * but who cares ... */
2288 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2294 static void vino_skip_frame(struct vino_channel_settings
*vcs
)
2296 struct vino_framebuffer
*fb
;
2297 unsigned long flags
;
2300 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2301 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2303 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2304 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2307 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2309 spin_lock_irqsave(&fb
->state_lock
, flags
);
2310 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2311 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2313 vino_capture_next(vcs
, 0);
2316 static void vino_frame_done(struct vino_channel_settings
*vcs
)
2318 struct vino_framebuffer
*fb
;
2319 unsigned long flags
;
2321 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2322 fb
= vino_queue_transfer(&vcs
->fb_queue
);
2324 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2325 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2328 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2330 fb
->frame_counter
= vcs
->int_data
.frame_counter
;
2331 memcpy(&fb
->timestamp
, &vcs
->int_data
.timestamp
,
2332 sizeof(struct timeval
));
2334 spin_lock_irqsave(&fb
->state_lock
, flags
);
2335 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
2336 fb
->state
= VINO_FRAMEBUFFER_READY
;
2337 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2339 wake_up(&vcs
->fb_queue
.frame_wait_queue
);
2341 vino_capture_next(vcs
, 0);
2344 static void vino_capture_tasklet(unsigned long channel
) {
2345 struct vino_channel_settings
*vcs
;
2347 vcs
= (channel
== VINO_CHANNEL_A
)
2348 ? &vino_drvdata
->a
: &vino_drvdata
->b
;
2350 if (vcs
->int_data
.skip
)
2351 vcs
->int_data
.skip_count
++;
2353 if (vcs
->int_data
.skip
&& (vcs
->int_data
.skip_count
2354 <= VINO_MAX_FRAME_SKIP_COUNT
)) {
2355 vino_skip_frame(vcs
);
2357 vcs
->int_data
.skip_count
= 0;
2358 vino_frame_done(vcs
);
2362 static irqreturn_t
vino_interrupt(int irq
, void *dev_id
)
2365 unsigned int fc_a
, fc_b
;
2366 int handled_a
= 0, skip_a
= 0, done_a
= 0;
2367 int handled_b
= 0, skip_b
= 0, done_b
= 0;
2369 #ifdef VINO_DEBUG_INT
2371 unsigned int line_count
= vino
->a
.line_count
,
2372 page_index
= vino
->a
.page_index
,
2373 field_counter
= vino
->a
.field_counter
,
2374 start_desc_tbl
= vino
->a
.start_desc_tbl
,
2375 next_4_desc
= vino
->a
.next_4_desc
;
2376 unsigned int line_count_2
,
2383 spin_lock(&vino_drvdata
->vino_lock
);
2385 while ((intr
= vino
->intr_status
)) {
2386 fc_a
= vino
->a
.field_counter
>> 1;
2387 fc_b
= vino
->b
.field_counter
>> 1;
2389 /* handle error-interrupts in some special way ?
2390 * --> skips frames */
2391 if (intr
& VINO_INTSTAT_A
) {
2392 if (intr
& VINO_INTSTAT_A_EOF
) {
2393 vino_drvdata
->a
.field
++;
2394 if (vino_drvdata
->a
.field
> 1) {
2395 vino_dma_stop(&vino_drvdata
->a
);
2396 vino_clear_interrupt(&vino_drvdata
->a
);
2397 vino_drvdata
->a
.field
= 0;
2400 if (vino
->a
.page_index
2401 != vino_drvdata
->a
.line_size
) {
2402 vino
->a
.line_count
= 0;
2403 vino
->a
.page_index
=
2406 vino
->a
.next_4_desc
=
2407 vino
->a
.start_desc_tbl
;
2410 dprintk("channel A end-of-field "
2411 "interrupt: %04x\n", intr
);
2413 vino_dma_stop(&vino_drvdata
->a
);
2414 vino_clear_interrupt(&vino_drvdata
->a
);
2415 vino_drvdata
->a
.field
= 0;
2417 dprintk("channel A error interrupt: %04x\n",
2421 #ifdef VINO_DEBUG_INT
2422 line_count_2
= vino
->a
.line_count
;
2423 page_index_2
= vino
->a
.page_index
;
2424 field_counter_2
= vino
->a
.field_counter
;
2425 start_desc_tbl_2
= vino
->a
.start_desc_tbl
;
2426 next_4_desc_2
= vino
->a
.next_4_desc
;
2428 printk("intr = %04x, loop = %d, field = %d\n",
2429 intr
, loop
, vino_drvdata
->a
.field
);
2430 printk("1- line count = %04d, page index = %04d, "
2431 "start = %08x, next = %08x\n"
2432 " fieldc = %d, framec = %d\n",
2433 line_count
, page_index
, start_desc_tbl
,
2434 next_4_desc
, field_counter
, fc_a
);
2435 printk("12-line count = %04d, page index = %04d, "
2436 " start = %08x, next = %08x\n",
2437 line_count_2
, page_index_2
, start_desc_tbl_2
,
2445 if (intr
& VINO_INTSTAT_B
) {
2446 if (intr
& VINO_INTSTAT_B_EOF
) {
2447 vino_drvdata
->b
.field
++;
2448 if (vino_drvdata
->b
.field
> 1) {
2449 vino_dma_stop(&vino_drvdata
->b
);
2450 vino_clear_interrupt(&vino_drvdata
->b
);
2451 vino_drvdata
->b
.field
= 0;
2454 dprintk("channel B end-of-field "
2455 "interrupt: %04x\n", intr
);
2457 vino_dma_stop(&vino_drvdata
->b
);
2458 vino_clear_interrupt(&vino_drvdata
->b
);
2459 vino_drvdata
->b
.field
= 0;
2461 dprintk("channel B error interrupt: %04x\n",
2466 /* Always remember to clear interrupt status.
2467 * Disable VINO interrupts while we do this. */
2468 ctrl
= vino
->control
;
2469 vino
->control
= ctrl
& ~(VINO_CTRL_A_INT
| VINO_CTRL_B_INT
);
2470 vino
->intr_status
= ~intr
;
2471 vino
->control
= ctrl
;
2473 spin_unlock(&vino_drvdata
->vino_lock
);
2475 if ((!handled_a
) && (done_a
|| skip_a
)) {
2477 do_gettimeofday(&vino_drvdata
->
2478 a
.int_data
.timestamp
);
2479 vino_drvdata
->a
.int_data
.frame_counter
= fc_a
;
2481 vino_drvdata
->a
.int_data
.skip
= skip_a
;
2483 dprintk("channel A %s, interrupt: %d\n",
2484 skip_a
? "skipping frame" : "frame done",
2486 tasklet_hi_schedule(&vino_tasklet_a
);
2490 if ((!handled_b
) && (done_b
|| skip_b
)) {
2492 do_gettimeofday(&vino_drvdata
->
2493 b
.int_data
.timestamp
);
2494 vino_drvdata
->b
.int_data
.frame_counter
= fc_b
;
2496 vino_drvdata
->b
.int_data
.skip
= skip_b
;
2498 dprintk("channel B %s, interrupt: %d\n",
2499 skip_b
? "skipping frame" : "frame done",
2501 tasklet_hi_schedule(&vino_tasklet_b
);
2505 #ifdef VINO_DEBUG_INT
2508 spin_lock(&vino_drvdata
->vino_lock
);
2511 spin_unlock(&vino_drvdata
->vino_lock
);
2516 /* VINO video input management */
2518 static int vino_get_saa7191_input(int input
)
2521 case VINO_INPUT_COMPOSITE
:
2522 return SAA7191_INPUT_COMPOSITE
;
2523 case VINO_INPUT_SVIDEO
:
2524 return SAA7191_INPUT_SVIDEO
;
2526 printk(KERN_ERR
"VINO: vino_get_saa7191_input(): "
2527 "invalid input!\n");
2532 /* execute with input_lock locked */
2533 static int vino_is_input_owner(struct vino_channel_settings
*vcs
)
2535 switch(vcs
->input
) {
2536 case VINO_INPUT_COMPOSITE
:
2537 case VINO_INPUT_SVIDEO
:
2538 return vino_drvdata
->decoder_owner
== vcs
->channel
;
2540 return vino_drvdata
->camera_owner
== vcs
->channel
;
2546 static int vino_acquire_input(struct vino_channel_settings
*vcs
)
2548 unsigned long flags
;
2551 dprintk("vino_acquire_input():\n");
2553 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2555 /* First try D1 and then SAA7191 */
2556 if (vino_drvdata
->camera
2557 && (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)) {
2558 vino_drvdata
->camera_owner
= vcs
->channel
;
2559 vcs
->input
= VINO_INPUT_D1
;
2560 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2561 } else if (vino_drvdata
->decoder
2562 && (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
)) {
2567 input
= VINO_INPUT_COMPOSITE
;
2569 ret
= decoder_call(video
, s_routing
,
2570 vino_get_saa7191_input(input
), 0, 0);
2576 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2578 /* Don't hold spinlocks while auto-detecting norm
2579 * as it may take a while... */
2581 ret
= decoder_call(video
, querystd
, &norm
);
2583 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2584 if (vino_data_norms
[data_norm
].std
& norm
)
2588 data_norm
= VINO_DATA_NORM_PAL
;
2589 ret
= decoder_call(core
, s_std
, norm
);
2592 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2599 vino_drvdata
->decoder_owner
= vcs
->channel
;
2602 vcs
->data_norm
= data_norm
;
2604 vcs
->input
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2605 vino_drvdata
->b
.input
: vino_drvdata
->a
.input
;
2606 vcs
->data_norm
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2607 vino_drvdata
->b
.data_norm
: vino_drvdata
->a
.data_norm
;
2610 if (vcs
->input
== VINO_INPUT_NONE
) {
2615 vino_set_default_clipping(vcs
);
2616 vino_set_default_scaling(vcs
);
2617 vino_set_default_framerate(vcs
);
2619 dprintk("vino_acquire_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2622 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2627 static int vino_set_input(struct vino_channel_settings
*vcs
, int input
)
2629 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2630 &vino_drvdata
->b
: &vino_drvdata
->a
;
2631 unsigned long flags
;
2634 dprintk("vino_set_input():\n");
2636 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2638 if (vcs
->input
== input
)
2642 case VINO_INPUT_COMPOSITE
:
2643 case VINO_INPUT_SVIDEO
:
2644 if (!vino_drvdata
->decoder
) {
2649 if (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
) {
2650 vino_drvdata
->decoder_owner
= vcs
->channel
;
2653 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2657 ret
= decoder_call(video
, s_routing
,
2658 vino_get_saa7191_input(input
), 0, 0);
2660 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2665 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2667 /* Don't hold spinlocks while auto-detecting norm
2668 * as it may take a while... */
2670 ret
= decoder_call(video
, querystd
, &norm
);
2672 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2673 if (vino_data_norms
[data_norm
].std
& norm
)
2677 data_norm
= VINO_DATA_NORM_PAL
;
2678 ret
= decoder_call(core
, s_std
, norm
);
2681 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2684 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2690 vcs
->data_norm
= data_norm
;
2692 if (input
!= vcs2
->input
) {
2698 vcs
->data_norm
= vcs2
->data_norm
;
2701 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2702 /* Transfer the ownership or release the input */
2703 if (vcs2
->input
== VINO_INPUT_D1
) {
2704 vino_drvdata
->camera_owner
= vcs2
->channel
;
2706 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2711 if (!vino_drvdata
->camera
) {
2716 if (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)
2717 vino_drvdata
->camera_owner
= vcs
->channel
;
2719 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2720 /* Transfer the ownership or release the input */
2721 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2722 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2723 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2725 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2730 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2737 vino_set_default_clipping(vcs
);
2738 vino_set_default_scaling(vcs
);
2739 vino_set_default_framerate(vcs
);
2741 dprintk("vino_set_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2744 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2749 static void vino_release_input(struct vino_channel_settings
*vcs
)
2751 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2752 &vino_drvdata
->b
: &vino_drvdata
->a
;
2753 unsigned long flags
;
2755 dprintk("vino_release_input():\n");
2757 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2759 /* Release ownership of the channel
2760 * and if the other channel takes input from
2761 * the same source, transfer the ownership */
2762 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2763 if (vcs2
->input
== VINO_INPUT_D1
) {
2764 vino_drvdata
->camera_owner
= vcs2
->channel
;
2766 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2768 } else if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2769 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2770 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2771 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2773 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2776 vcs
->input
= VINO_INPUT_NONE
;
2778 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2781 /* execute with input_lock locked */
2782 static int vino_set_data_norm(struct vino_channel_settings
*vcs
,
2783 unsigned int data_norm
,
2784 unsigned long *flags
)
2788 if (data_norm
== vcs
->data_norm
)
2791 switch (vcs
->input
) {
2793 /* only one "norm" supported */
2794 if (data_norm
!= VINO_DATA_NORM_D1
)
2797 case VINO_INPUT_COMPOSITE
:
2798 case VINO_INPUT_SVIDEO
: {
2801 if ((data_norm
!= VINO_DATA_NORM_PAL
)
2802 && (data_norm
!= VINO_DATA_NORM_NTSC
)
2803 && (data_norm
!= VINO_DATA_NORM_SECAM
))
2806 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, *flags
);
2808 /* Don't hold spinlocks while setting norm
2809 * as it may take a while... */
2811 norm
= vino_data_norms
[data_norm
].std
;
2812 err
= decoder_call(core
, s_std
, norm
);
2814 spin_lock_irqsave(&vino_drvdata
->input_lock
, *flags
);
2819 vcs
->data_norm
= data_norm
;
2821 vino_set_default_clipping(vcs
);
2822 vino_set_default_scaling(vcs
);
2823 vino_set_default_framerate(vcs
);
2834 /* V4L2 helper functions */
2836 static int vino_find_data_format(__u32 pixelformat
)
2840 for (i
= 0; i
< VINO_DATA_FMT_COUNT
; i
++) {
2841 if (vino_data_formats
[i
].pixelformat
== pixelformat
)
2845 return VINO_DATA_FMT_NONE
;
2848 static int vino_int_enum_input(struct vino_channel_settings
*vcs
, __u32 index
)
2850 int input
= VINO_INPUT_NONE
;
2851 unsigned long flags
;
2853 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2854 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2857 input
= VINO_INPUT_COMPOSITE
;
2860 input
= VINO_INPUT_SVIDEO
;
2863 input
= VINO_INPUT_D1
;
2866 } else if (vino_drvdata
->decoder
) {
2869 input
= VINO_INPUT_COMPOSITE
;
2872 input
= VINO_INPUT_SVIDEO
;
2875 } else if (vino_drvdata
->camera
) {
2878 input
= VINO_INPUT_D1
;
2882 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2887 /* execute with input_lock locked */
2888 static __u32
vino_find_input_index(struct vino_channel_settings
*vcs
)
2891 // FIXME: detect when no inputs available
2893 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2894 switch (vcs
->input
) {
2895 case VINO_INPUT_COMPOSITE
:
2898 case VINO_INPUT_SVIDEO
:
2905 } else if (vino_drvdata
->decoder
) {
2906 switch (vcs
->input
) {
2907 case VINO_INPUT_COMPOSITE
:
2910 case VINO_INPUT_SVIDEO
:
2914 } else if (vino_drvdata
->camera
) {
2915 switch (vcs
->input
) {
2927 static int vino_querycap(struct file
*file
, void *__fh
,
2928 struct v4l2_capability
*cap
)
2930 memset(cap
, 0, sizeof(struct v4l2_capability
));
2932 strcpy(cap
->driver
, vino_driver_name
);
2933 strcpy(cap
->card
, vino_driver_description
);
2934 strcpy(cap
->bus_info
, vino_bus_name
);
2936 V4L2_CAP_VIDEO_CAPTURE
|
2938 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
2942 static int vino_enum_input(struct file
*file
, void *__fh
,
2943 struct v4l2_input
*i
)
2945 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2946 __u32 index
= i
->index
;
2948 dprintk("requested index = %d\n", index
);
2950 input
= vino_int_enum_input(vcs
, index
);
2951 if (input
== VINO_INPUT_NONE
)
2954 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
2955 i
->std
= vino_inputs
[input
].std
;
2956 strcpy(i
->name
, vino_inputs
[input
].name
);
2958 if (input
== VINO_INPUT_COMPOSITE
|| input
== VINO_INPUT_SVIDEO
)
2959 decoder_call(video
, g_input_status
, &i
->status
);
2963 static int vino_g_input(struct file
*file
, void *__fh
,
2966 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2969 unsigned long flags
;
2971 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2973 index
= vino_find_input_index(vcs
);
2974 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2976 dprintk("input = %d\n", input
);
2978 if (input
== VINO_INPUT_NONE
) {
2987 static int vino_s_input(struct file
*file
, void *__fh
,
2990 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2992 dprintk("requested input = %d\n", i
);
2994 input
= vino_int_enum_input(vcs
, i
);
2995 if (input
== VINO_INPUT_NONE
)
2998 return vino_set_input(vcs
, input
);
3001 static int vino_querystd(struct file
*file
, void *__fh
,
3004 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3005 unsigned long flags
;
3008 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3010 switch (vcs
->input
) {
3012 *std
= vino_inputs
[vcs
->input
].std
;
3014 case VINO_INPUT_COMPOSITE
:
3015 case VINO_INPUT_SVIDEO
: {
3016 decoder_call(video
, querystd
, std
);
3023 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3028 static int vino_g_std(struct file
*file
, void *__fh
,
3031 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3032 unsigned long flags
;
3034 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3036 *std
= vino_data_norms
[vcs
->data_norm
].std
;
3037 dprintk("current standard = %d\n", vcs
->data_norm
);
3039 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3044 static int vino_s_std(struct file
*file
, void *__fh
,
3047 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3048 unsigned long flags
;
3051 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3053 if (!vino_is_input_owner(vcs
)) {
3058 /* check if the standard is valid for the current input */
3059 if ((*std
) & vino_inputs
[vcs
->input
].std
) {
3060 dprintk("standard accepted\n");
3062 /* change the video norm for SAA7191
3063 * and accept NTSC for D1 (do nothing) */
3065 if (vcs
->input
== VINO_INPUT_D1
)
3068 if ((*std
) & V4L2_STD_PAL
) {
3069 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_PAL
,
3071 } else if ((*std
) & V4L2_STD_NTSC
) {
3072 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_NTSC
,
3074 } else if ((*std
) & V4L2_STD_SECAM
) {
3075 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_SECAM
,
3089 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3094 static int vino_enum_fmt_vid_cap(struct file
*file
, void *__fh
,
3095 struct v4l2_fmtdesc
*fd
)
3097 dprintk("format index = %d\n", fd
->index
);
3099 if (fd
->index
>= VINO_DATA_FMT_COUNT
)
3101 dprintk("format name = %s\n", vino_data_formats
[fd
->index
].description
);
3103 fd
->pixelformat
= vino_data_formats
[fd
->index
].pixelformat
;
3104 strcpy(fd
->description
, vino_data_formats
[fd
->index
].description
);
3108 static int vino_try_fmt_vid_cap(struct file
*file
, void *__fh
,
3109 struct v4l2_format
*f
)
3111 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3112 struct vino_channel_settings tempvcs
;
3113 unsigned long flags
;
3114 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3116 dprintk("requested: w = %d, h = %d\n",
3117 pf
->width
, pf
->height
);
3119 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3120 memcpy(&tempvcs
, vcs
, sizeof(struct vino_channel_settings
));
3121 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3123 tempvcs
.data_format
= vino_find_data_format(pf
->pixelformat
);
3124 if (tempvcs
.data_format
== VINO_DATA_FMT_NONE
) {
3125 tempvcs
.data_format
= VINO_DATA_FMT_GREY
;
3127 vino_data_formats
[tempvcs
.data_format
].
3131 /* data format must be set before clipping/scaling */
3132 vino_set_scaling(&tempvcs
, pf
->width
, pf
->height
);
3134 dprintk("data format = %s\n",
3135 vino_data_formats
[tempvcs
.data_format
].description
);
3137 pf
->width
= (tempvcs
.clipping
.right
- tempvcs
.clipping
.left
) /
3139 pf
->height
= (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3142 pf
->field
= V4L2_FIELD_INTERLACED
;
3143 pf
->bytesperline
= tempvcs
.line_size
;
3144 pf
->sizeimage
= tempvcs
.line_size
*
3145 (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3148 vino_data_formats
[tempvcs
.data_format
].colorspace
;
3154 static int vino_g_fmt_vid_cap(struct file
*file
, void *__fh
,
3155 struct v4l2_format
*f
)
3157 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3158 unsigned long flags
;
3159 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3161 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3163 pf
->width
= (vcs
->clipping
.right
- vcs
->clipping
.left
) /
3165 pf
->height
= (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3168 vino_data_formats
[vcs
->data_format
].pixelformat
;
3170 pf
->field
= V4L2_FIELD_INTERLACED
;
3171 pf
->bytesperline
= vcs
->line_size
;
3172 pf
->sizeimage
= vcs
->line_size
*
3173 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3176 vino_data_formats
[vcs
->data_format
].colorspace
;
3180 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3184 static int vino_s_fmt_vid_cap(struct file
*file
, void *__fh
,
3185 struct v4l2_format
*f
)
3187 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3189 unsigned long flags
;
3190 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3192 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3194 data_format
= vino_find_data_format(pf
->pixelformat
);
3196 if (data_format
== VINO_DATA_FMT_NONE
) {
3197 vcs
->data_format
= VINO_DATA_FMT_GREY
;
3199 vino_data_formats
[vcs
->data_format
].
3202 vcs
->data_format
= data_format
;
3205 /* data format must be set before clipping/scaling */
3206 vino_set_scaling(vcs
, pf
->width
, pf
->height
);
3208 dprintk("data format = %s\n",
3209 vino_data_formats
[vcs
->data_format
].description
);
3211 pf
->width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3212 pf
->height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3214 pf
->field
= V4L2_FIELD_INTERLACED
;
3215 pf
->bytesperline
= vcs
->line_size
;
3216 pf
->sizeimage
= vcs
->line_size
*
3217 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3220 vino_data_formats
[vcs
->data_format
].colorspace
;
3224 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3228 static int vino_cropcap(struct file
*file
, void *__fh
,
3229 struct v4l2_cropcap
*ccap
)
3231 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3232 const struct vino_data_norm
*norm
;
3233 unsigned long flags
;
3235 switch (ccap
->type
) {
3236 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3237 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3239 norm
= &vino_data_norms
[vcs
->data_norm
];
3241 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3243 ccap
->bounds
.left
= 0;
3244 ccap
->bounds
.top
= 0;
3245 ccap
->bounds
.width
= norm
->width
;
3246 ccap
->bounds
.height
= norm
->height
;
3247 memcpy(&ccap
->defrect
, &ccap
->bounds
,
3248 sizeof(struct v4l2_rect
));
3250 ccap
->pixelaspect
.numerator
= 1;
3251 ccap
->pixelaspect
.denominator
= 1;
3253 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3261 static int vino_g_crop(struct file
*file
, void *__fh
,
3262 struct v4l2_crop
*c
)
3264 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3265 unsigned long flags
;
3268 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3269 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3271 c
->c
.left
= vcs
->clipping
.left
;
3272 c
->c
.top
= vcs
->clipping
.top
;
3273 c
->c
.width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3274 c
->c
.height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3276 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3278 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3286 static int vino_s_crop(struct file
*file
, void *__fh
,
3287 struct v4l2_crop
*c
)
3289 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3290 unsigned long flags
;
3293 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3294 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3296 vino_set_clipping(vcs
, c
->c
.left
, c
->c
.top
,
3297 c
->c
.width
, c
->c
.height
);
3299 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3301 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3309 static int vino_g_parm(struct file
*file
, void *__fh
,
3310 struct v4l2_streamparm
*sp
)
3312 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3313 unsigned long flags
;
3314 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3316 cp
->capability
= V4L2_CAP_TIMEPERFRAME
;
3317 cp
->timeperframe
.numerator
= 1;
3319 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3321 cp
->timeperframe
.denominator
= vcs
->fps
;
3323 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3325 /* TODO: cp->readbuffers = xxx; */
3330 static int vino_s_parm(struct file
*file
, void *__fh
,
3331 struct v4l2_streamparm
*sp
)
3333 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3334 unsigned long flags
;
3335 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3337 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3339 if ((cp
->timeperframe
.numerator
== 0) ||
3340 (cp
->timeperframe
.denominator
== 0)) {
3341 /* reset framerate */
3342 vino_set_default_framerate(vcs
);
3344 vino_set_framerate(vcs
, cp
->timeperframe
.denominator
/
3345 cp
->timeperframe
.numerator
);
3348 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3353 static int vino_reqbufs(struct file
*file
, void *__fh
,
3354 struct v4l2_requestbuffers
*rb
)
3356 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3361 /* TODO: check queue type */
3362 if (rb
->memory
!= V4L2_MEMORY_MMAP
) {
3363 dprintk("type not mmap\n");
3367 dprintk("count = %d\n", rb
->count
);
3368 if (rb
->count
> 0) {
3369 if (vino_is_capturing(vcs
)) {
3370 dprintk("busy, capturing\n");
3374 if (vino_queue_has_mapped_buffers(&vcs
->fb_queue
)) {
3375 dprintk("busy, buffers still mapped\n");
3379 vino_queue_free(&vcs
->fb_queue
);
3380 vino_queue_init(&vcs
->fb_queue
, &rb
->count
);
3384 vino_capture_stop(vcs
);
3385 vino_queue_free(&vcs
->fb_queue
);
3391 static void vino_v4l2_get_buffer_status(struct vino_channel_settings
*vcs
,
3392 struct vino_framebuffer
*fb
,
3393 struct v4l2_buffer
*b
)
3395 if (vino_queue_outgoing_contains(&vcs
->fb_queue
,
3397 b
->flags
&= ~V4L2_BUF_FLAG_QUEUED
;
3398 b
->flags
|= V4L2_BUF_FLAG_DONE
;
3399 } else if (vino_queue_incoming_contains(&vcs
->fb_queue
,
3401 b
->flags
&= ~V4L2_BUF_FLAG_DONE
;
3402 b
->flags
|= V4L2_BUF_FLAG_QUEUED
;
3404 b
->flags
&= ~(V4L2_BUF_FLAG_DONE
|
3405 V4L2_BUF_FLAG_QUEUED
);
3408 b
->flags
&= ~(V4L2_BUF_FLAG_TIMECODE
);
3410 if (fb
->map_count
> 0)
3411 b
->flags
|= V4L2_BUF_FLAG_MAPPED
;
3414 b
->memory
= (vcs
->fb_queue
.type
== VINO_MEMORY_MMAP
) ?
3415 V4L2_MEMORY_MMAP
: V4L2_MEMORY_USERPTR
;
3416 b
->m
.offset
= fb
->offset
;
3417 b
->bytesused
= fb
->data_size
;
3418 b
->length
= fb
->size
;
3419 b
->field
= V4L2_FIELD_INTERLACED
;
3420 b
->sequence
= fb
->frame_counter
;
3421 memcpy(&b
->timestamp
, &fb
->timestamp
,
3422 sizeof(struct timeval
));
3425 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3426 fb
->id
, fb
->size
, fb
->data_size
, fb
->offset
);
3429 static int vino_querybuf(struct file
*file
, void *__fh
,
3430 struct v4l2_buffer
*b
)
3432 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3433 struct vino_framebuffer
*fb
;
3438 /* TODO: check queue type */
3439 if (b
->index
>= vino_queue_get_length(&vcs
->fb_queue
)) {
3440 dprintk("invalid index = %d\n",
3445 fb
= vino_queue_get_buffer(&vcs
->fb_queue
,
3448 dprintk("vino_queue_get_buffer() failed");
3452 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3457 static int vino_qbuf(struct file
*file
, void *__fh
,
3458 struct v4l2_buffer
*b
)
3460 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3461 struct vino_framebuffer
*fb
;
3467 /* TODO: check queue type */
3468 if (b
->memory
!= V4L2_MEMORY_MMAP
) {
3469 dprintk("type not mmap\n");
3473 fb
= vino_capture_enqueue(vcs
, b
->index
);
3477 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3479 if (vcs
->streaming
) {
3480 ret
= vino_capture_next(vcs
, 1);
3488 static int vino_dqbuf(struct file
*file
, void *__fh
,
3489 struct v4l2_buffer
*b
)
3491 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3492 unsigned int nonblocking
= file
->f_flags
& O_NONBLOCK
;
3493 struct vino_framebuffer
*fb
;
3494 unsigned int incoming
, outgoing
;
3500 /* TODO: check queue type */
3502 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3504 dprintk("vino_queue_get_incoming() failed\n");
3507 err
= vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
);
3509 dprintk("vino_queue_get_outgoing() failed\n");
3513 dprintk("incoming = %d, outgoing = %d\n", incoming
, outgoing
);
3515 if (outgoing
== 0) {
3516 if (incoming
== 0) {
3517 dprintk("no incoming or outgoing buffers\n");
3521 dprintk("non-blocking I/O was selected and "
3522 "there are no buffers to dequeue\n");
3526 err
= vino_wait_for_frame(vcs
);
3528 err
= vino_wait_for_frame(vcs
);
3530 /* interrupted or no frames captured because of
3532 /* vino_capture_failed(vcs); */
3538 fb
= vino_queue_remove(&vcs
->fb_queue
, &b
->index
);
3540 dprintk("vino_queue_remove() failed\n");
3544 err
= vino_check_buffer(vcs
, fb
);
3546 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3554 static int vino_streamon(struct file
*file
, void *__fh
,
3555 enum v4l2_buf_type i
)
3557 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3558 unsigned int incoming
;
3566 // TODO: check queue type
3568 if (vino_queue_get_length(&vcs
->fb_queue
) < 1) {
3569 dprintk("no buffers allocated\n");
3573 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3575 dprintk("vino_queue_get_incoming() failed\n");
3582 ret
= vino_capture_next(vcs
, 1);
3586 dprintk("couldn't start capture\n");
3594 static int vino_streamoff(struct file
*file
, void *__fh
,
3595 enum v4l2_buf_type i
)
3597 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3601 if (!vcs
->streaming
)
3605 vino_capture_stop(vcs
);
3610 static int vino_queryctrl(struct file
*file
, void *__fh
,
3611 struct v4l2_queryctrl
*queryctrl
)
3613 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3614 unsigned long flags
;
3618 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3620 switch (vcs
->input
) {
3622 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3623 if (vino_indycam_v4l2_controls
[i
].id
==
3626 &vino_indycam_v4l2_controls
[i
],
3627 sizeof(struct v4l2_queryctrl
));
3628 queryctrl
->reserved
[0] = 0;
3635 case VINO_INPUT_COMPOSITE
:
3636 case VINO_INPUT_SVIDEO
:
3637 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3638 if (vino_saa7191_v4l2_controls
[i
].id
==
3641 &vino_saa7191_v4l2_controls
[i
],
3642 sizeof(struct v4l2_queryctrl
));
3643 queryctrl
->reserved
[0] = 0;
3655 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3660 static int vino_g_ctrl(struct file
*file
, void *__fh
,
3661 struct v4l2_control
*control
)
3663 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3664 unsigned long flags
;
3668 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3670 switch (vcs
->input
) {
3671 case VINO_INPUT_D1
: {
3673 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3674 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3683 err
= camera_call(core
, g_ctrl
, control
);
3688 case VINO_INPUT_COMPOSITE
:
3689 case VINO_INPUT_SVIDEO
: {
3691 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3692 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3701 err
= decoder_call(core
, g_ctrl
, control
);
3711 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3716 static int vino_s_ctrl(struct file
*file
, void *__fh
,
3717 struct v4l2_control
*control
)
3719 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3720 unsigned long flags
;
3724 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3726 if (!vino_is_input_owner(vcs
)) {
3731 switch (vcs
->input
) {
3732 case VINO_INPUT_D1
: {
3734 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3735 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3742 if (control
->value
< vino_indycam_v4l2_controls
[i
].minimum
||
3743 control
->value
> vino_indycam_v4l2_controls
[i
].maximum
) {
3747 err
= camera_call(core
, s_ctrl
, control
);
3752 case VINO_INPUT_COMPOSITE
:
3753 case VINO_INPUT_SVIDEO
: {
3755 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3756 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3763 if (control
->value
< vino_saa7191_v4l2_controls
[i
].minimum
||
3764 control
->value
> vino_saa7191_v4l2_controls
[i
].maximum
) {
3769 err
= decoder_call(core
, s_ctrl
, control
);
3779 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3784 /* File operations */
3786 static int vino_open(struct file
*file
)
3788 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3790 dprintk("open(): channel = %c\n",
3791 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A' : 'B');
3793 mutex_lock(&vcs
->mutex
);
3796 dprintk("open(): driver busy\n");
3801 ret
= vino_acquire_input(vcs
);
3803 dprintk("open(): vino_acquire_input() failed\n");
3810 mutex_unlock(&vcs
->mutex
);
3812 dprintk("open(): %s!\n", ret
? "failed" : "complete");
3817 static int vino_close(struct file
*file
)
3819 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3820 dprintk("close():\n");
3822 mutex_lock(&vcs
->mutex
);
3827 vino_release_input(vcs
);
3829 /* stop DMA and free buffers */
3830 vino_capture_stop(vcs
);
3831 vino_queue_free(&vcs
->fb_queue
);
3834 mutex_unlock(&vcs
->mutex
);
3839 static void vino_vm_open(struct vm_area_struct
*vma
)
3841 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3844 dprintk("vino_vm_open(): count = %d\n", fb
->map_count
);
3847 static void vino_vm_close(struct vm_area_struct
*vma
)
3849 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3852 dprintk("vino_vm_close(): count = %d\n", fb
->map_count
);
3855 static const struct vm_operations_struct vino_vm_ops
= {
3856 .open
= vino_vm_open
,
3857 .close
= vino_vm_close
,
3860 static int vino_mmap(struct file
*file
, struct vm_area_struct
*vma
)
3862 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3864 unsigned long start
= vma
->vm_start
;
3865 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
3866 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
3868 struct vino_framebuffer
*fb
= NULL
;
3869 unsigned int i
, length
;
3872 dprintk("mmap():\n");
3874 // TODO: reject mmap if already mapped
3876 if (mutex_lock_interruptible(&vcs
->mutex
))
3884 // TODO: check queue type
3886 if (!(vma
->vm_flags
& VM_WRITE
)) {
3887 dprintk("mmap(): app bug: PROT_WRITE please\n");
3891 if (!(vma
->vm_flags
& VM_SHARED
)) {
3892 dprintk("mmap(): app bug: MAP_SHARED please\n");
3897 /* find the correct buffer using offset */
3898 length
= vino_queue_get_length(&vcs
->fb_queue
);
3900 dprintk("mmap(): queue not initialized\n");
3905 for (i
= 0; i
< length
; i
++) {
3906 fb
= vino_queue_get_buffer(&vcs
->fb_queue
, i
);
3908 dprintk("mmap(): vino_queue_get_buffer() failed\n");
3913 if (fb
->offset
== offset
)
3917 dprintk("mmap(): invalid offset = %lu\n", offset
);
3922 dprintk("mmap(): buffer = %d\n", i
);
3924 if (size
> (fb
->desc_table
.page_count
* PAGE_SIZE
)) {
3925 dprintk("mmap(): failed: size = %lu > %lu\n",
3926 size
, fb
->desc_table
.page_count
* PAGE_SIZE
);
3931 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++) {
3933 virt_to_phys((void *)fb
->desc_table
.virtual[i
]) >>
3936 if (size
< PAGE_SIZE
)
3939 // protection was: PAGE_READONLY
3940 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
,
3941 vma
->vm_page_prot
)) {
3942 dprintk("mmap(): remap_pfn_range() failed\n");
3953 vma
->vm_flags
|= VM_DONTEXPAND
| VM_RESERVED
;
3954 vma
->vm_flags
&= ~VM_IO
;
3955 vma
->vm_private_data
= fb
;
3956 vma
->vm_file
= file
;
3957 vma
->vm_ops
= &vino_vm_ops
;
3960 mutex_unlock(&vcs
->mutex
);
3965 static unsigned int vino_poll(struct file
*file
, poll_table
*pt
)
3967 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3968 unsigned int outgoing
;
3969 unsigned int ret
= 0;
3972 // TODO: this has to be corrected for different read modes
3974 dprintk("poll():\n");
3976 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3977 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3984 poll_wait(file
, &vcs
->fb_queue
.frame_wait_queue
, pt
);
3986 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3987 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3993 dprintk("poll(): data %savailable\n",
3994 (outgoing
> 0) ? "" : "not ");
3997 ret
= POLLIN
| POLLRDNORM
;
4003 static long vino_ioctl(struct file
*file
,
4004 unsigned int cmd
, unsigned long arg
)
4006 struct vino_channel_settings
*vcs
= video_drvdata(file
);
4009 if (mutex_lock_interruptible(&vcs
->mutex
))
4012 ret
= video_ioctl2(file
, cmd
, arg
);
4014 mutex_unlock(&vcs
->mutex
);
4019 /* Initialization and cleanup */
4022 static int vino_init_stage
;
4024 const struct v4l2_ioctl_ops vino_ioctl_ops
= {
4025 .vidioc_enum_fmt_vid_cap
= vino_enum_fmt_vid_cap
,
4026 .vidioc_g_fmt_vid_cap
= vino_g_fmt_vid_cap
,
4027 .vidioc_s_fmt_vid_cap
= vino_s_fmt_vid_cap
,
4028 .vidioc_try_fmt_vid_cap
= vino_try_fmt_vid_cap
,
4029 .vidioc_querycap
= vino_querycap
,
4030 .vidioc_enum_input
= vino_enum_input
,
4031 .vidioc_g_input
= vino_g_input
,
4032 .vidioc_s_input
= vino_s_input
,
4033 .vidioc_g_std
= vino_g_std
,
4034 .vidioc_s_std
= vino_s_std
,
4035 .vidioc_querystd
= vino_querystd
,
4036 .vidioc_cropcap
= vino_cropcap
,
4037 .vidioc_s_crop
= vino_s_crop
,
4038 .vidioc_g_crop
= vino_g_crop
,
4039 .vidioc_s_parm
= vino_s_parm
,
4040 .vidioc_g_parm
= vino_g_parm
,
4041 .vidioc_reqbufs
= vino_reqbufs
,
4042 .vidioc_querybuf
= vino_querybuf
,
4043 .vidioc_qbuf
= vino_qbuf
,
4044 .vidioc_dqbuf
= vino_dqbuf
,
4045 .vidioc_streamon
= vino_streamon
,
4046 .vidioc_streamoff
= vino_streamoff
,
4047 .vidioc_queryctrl
= vino_queryctrl
,
4048 .vidioc_g_ctrl
= vino_g_ctrl
,
4049 .vidioc_s_ctrl
= vino_s_ctrl
,
4052 static const struct v4l2_file_operations vino_fops
= {
4053 .owner
= THIS_MODULE
,
4055 .release
= vino_close
,
4056 .unlocked_ioctl
= vino_ioctl
,
4061 static struct video_device vdev_template
= {
4064 .ioctl_ops
= &vino_ioctl_ops
,
4065 .tvnorms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
4068 static void vino_module_cleanup(int stage
)
4072 video_unregister_device(vino_drvdata
->b
.vdev
);
4073 vino_drvdata
->b
.vdev
= NULL
;
4075 video_unregister_device(vino_drvdata
->a
.vdev
);
4076 vino_drvdata
->a
.vdev
= NULL
;
4078 i2c_del_adapter(&vino_i2c_adapter
);
4080 free_irq(SGI_VINO_IRQ
, NULL
);
4082 if (vino_drvdata
->b
.vdev
) {
4083 video_device_release(vino_drvdata
->b
.vdev
);
4084 vino_drvdata
->b
.vdev
= NULL
;
4087 if (vino_drvdata
->a
.vdev
) {
4088 video_device_release(vino_drvdata
->a
.vdev
);
4089 vino_drvdata
->a
.vdev
= NULL
;
4092 /* all entries in dma_cpu dummy table have the same address */
4093 dma_unmap_single(NULL
,
4094 vino_drvdata
->dummy_desc_table
.dma_cpu
[0],
4095 PAGE_SIZE
, DMA_FROM_DEVICE
);
4096 dma_free_coherent(NULL
, VINO_DUMMY_DESC_COUNT
4097 * sizeof(dma_addr_t
),
4098 (void *)vino_drvdata
->
4099 dummy_desc_table
.dma_cpu
,
4100 vino_drvdata
->dummy_desc_table
.dma
);
4102 free_page(vino_drvdata
->dummy_page
);
4104 v4l2_device_unregister(&vino_drvdata
->v4l2_dev
);
4106 kfree(vino_drvdata
);
4112 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4117 static int vino_probe(void)
4119 unsigned long rev_id
;
4121 if (ip22_is_fullhouse()) {
4122 printk(KERN_ERR
"VINO doesn't exist in IP22 Fullhouse\n");
4126 if (!(sgimc
->systemid
& SGIMC_SYSID_EPRESENT
)) {
4127 printk(KERN_ERR
"VINO is not found (EISA BUS not present)\n");
4131 vino
= (struct sgi_vino
*)ioremap(VINO_BASE
, sizeof(struct sgi_vino
));
4133 printk(KERN_ERR
"VINO: ioremap() failed\n");
4138 if (get_dbe(rev_id
, &(vino
->rev_id
))) {
4139 printk(KERN_ERR
"Failed to read VINO revision register\n");
4140 vino_module_cleanup(vino_init_stage
);
4144 if (VINO_ID_VALUE(rev_id
) != VINO_CHIP_ID
) {
4145 printk(KERN_ERR
"Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4147 vino_module_cleanup(vino_init_stage
);
4151 printk(KERN_INFO
"VINO revision %ld found\n", VINO_REV_NUM(rev_id
));
4156 static int vino_init(void)
4158 dma_addr_t dma_dummy_address
;
4162 vino_drvdata
= kzalloc(sizeof(struct vino_settings
), GFP_KERNEL
);
4163 if (!vino_drvdata
) {
4164 vino_module_cleanup(vino_init_stage
);
4168 strlcpy(vino_drvdata
->v4l2_dev
.name
, "vino",
4169 sizeof(vino_drvdata
->v4l2_dev
.name
));
4170 err
= v4l2_device_register(NULL
, &vino_drvdata
->v4l2_dev
);
4175 /* create a dummy dma descriptor */
4176 vino_drvdata
->dummy_page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
4177 if (!vino_drvdata
->dummy_page
) {
4178 vino_module_cleanup(vino_init_stage
);
4183 // TODO: use page_count in dummy_desc_table
4185 vino_drvdata
->dummy_desc_table
.dma_cpu
=
4186 dma_alloc_coherent(NULL
,
4187 VINO_DUMMY_DESC_COUNT
* sizeof(dma_addr_t
),
4188 &vino_drvdata
->dummy_desc_table
.dma
,
4189 GFP_KERNEL
| GFP_DMA
);
4190 if (!vino_drvdata
->dummy_desc_table
.dma_cpu
) {
4191 vino_module_cleanup(vino_init_stage
);
4196 dma_dummy_address
= dma_map_single(NULL
,
4197 (void *)vino_drvdata
->dummy_page
,
4198 PAGE_SIZE
, DMA_FROM_DEVICE
);
4199 for (i
= 0; i
< VINO_DUMMY_DESC_COUNT
; i
++) {
4200 vino_drvdata
->dummy_desc_table
.dma_cpu
[i
] = dma_dummy_address
;
4203 /* initialize VINO */
4206 vino
->a
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4207 vino
->b
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4208 udelay(VINO_DESC_FETCH_DELAY
);
4210 vino
->intr_status
= 0;
4212 vino
->a
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4213 vino
->b
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4218 static int vino_init_channel_settings(struct vino_channel_settings
*vcs
,
4219 unsigned int channel
, const char *name
)
4221 vcs
->channel
= channel
;
4222 vcs
->input
= VINO_INPUT_NONE
;
4225 vcs
->data_format
= VINO_DATA_FMT_GREY
;
4226 vcs
->data_norm
= VINO_DATA_NORM_NTSC
;
4227 vcs
->decimation
= 1;
4228 vino_set_default_clipping(vcs
);
4229 vino_set_default_framerate(vcs
);
4233 mutex_init(&vcs
->mutex
);
4234 spin_lock_init(&vcs
->capture_lock
);
4236 mutex_init(&vcs
->fb_queue
.queue_mutex
);
4237 spin_lock_init(&vcs
->fb_queue
.queue_lock
);
4238 init_waitqueue_head(&vcs
->fb_queue
.frame_wait_queue
);
4240 vcs
->vdev
= video_device_alloc();
4242 vino_module_cleanup(vino_init_stage
);
4247 memcpy(vcs
->vdev
, &vdev_template
,
4248 sizeof(struct video_device
));
4249 strcpy(vcs
->vdev
->name
, name
);
4250 vcs
->vdev
->release
= video_device_release
;
4251 vcs
->vdev
->v4l2_dev
= &vino_drvdata
->v4l2_dev
;
4253 video_set_drvdata(vcs
->vdev
, vcs
);
4258 static int __init
vino_module_init(void)
4262 printk(KERN_INFO
"SGI VINO driver version %s\n",
4263 VINO_MODULE_VERSION
);
4273 /* initialize data structures */
4275 spin_lock_init(&vino_drvdata
->vino_lock
);
4276 spin_lock_init(&vino_drvdata
->input_lock
);
4278 ret
= vino_init_channel_settings(&vino_drvdata
->a
, VINO_CHANNEL_A
,
4283 ret
= vino_init_channel_settings(&vino_drvdata
->b
, VINO_CHANNEL_B
,
4288 /* initialize hardware and register V4L devices */
4290 ret
= request_irq(SGI_VINO_IRQ
, vino_interrupt
, 0,
4291 vino_driver_description
, NULL
);
4293 printk(KERN_ERR
"VINO: requesting IRQ %02d failed\n",
4295 vino_module_cleanup(vino_init_stage
);
4300 ret
= i2c_add_adapter(&vino_i2c_adapter
);
4302 printk(KERN_ERR
"VINO I2C bus registration failed\n");
4303 vino_module_cleanup(vino_init_stage
);
4306 i2c_set_adapdata(&vino_i2c_adapter
, &vino_drvdata
->v4l2_dev
);
4309 ret
= video_register_device(vino_drvdata
->a
.vdev
,
4310 VFL_TYPE_GRABBER
, -1);
4312 printk(KERN_ERR
"VINO channel A Video4Linux-device "
4313 "registration failed\n");
4314 vino_module_cleanup(vino_init_stage
);
4319 ret
= video_register_device(vino_drvdata
->b
.vdev
,
4320 VFL_TYPE_GRABBER
, -1);
4322 printk(KERN_ERR
"VINO channel B Video4Linux-device "
4323 "registration failed\n");
4324 vino_module_cleanup(vino_init_stage
);
4329 vino_drvdata
->decoder
=
4330 v4l2_i2c_new_subdev(&vino_drvdata
->v4l2_dev
, &vino_i2c_adapter
,
4331 "saa7191", 0, I2C_ADDRS(0x45));
4332 vino_drvdata
->camera
=
4333 v4l2_i2c_new_subdev(&vino_drvdata
->v4l2_dev
, &vino_i2c_adapter
,
4334 "indycam", 0, I2C_ADDRS(0x2b));
4336 dprintk("init complete!\n");
4341 static void __exit
vino_module_exit(void)
4343 dprintk("exiting, stage = %d ...\n", vino_init_stage
);
4344 vino_module_cleanup(vino_init_stage
);
4345 dprintk("cleanup complete, exit!\n");
4348 module_init(vino_module_init
);
4349 module_exit(vino_module_exit
);