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>
37 #include <linux/time.h>
38 #include <linux/version.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.6"
64 #define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 6)
66 MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
67 MODULE_VERSION(VINO_MODULE_VERSION
);
68 MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
69 MODULE_LICENSE("GPL");
72 #define dprintk(x...) printk("VINO: " x);
77 #define VINO_NO_CHANNEL 0
78 #define VINO_CHANNEL_A 1
79 #define VINO_CHANNEL_B 2
81 #define VINO_PAL_WIDTH 768
82 #define VINO_PAL_HEIGHT 576
83 #define VINO_NTSC_WIDTH 640
84 #define VINO_NTSC_HEIGHT 480
86 #define VINO_MIN_WIDTH 32
87 #define VINO_MIN_HEIGHT 32
89 #define VINO_CLIPPING_START_ODD_D1 1
90 #define VINO_CLIPPING_START_ODD_PAL 15
91 #define VINO_CLIPPING_START_ODD_NTSC 12
93 #define VINO_CLIPPING_START_EVEN_D1 2
94 #define VINO_CLIPPING_START_EVEN_PAL 15
95 #define VINO_CLIPPING_START_EVEN_NTSC 12
97 #define VINO_INPUT_CHANNEL_COUNT 3
99 /* the number is the index for vino_inputs */
100 #define VINO_INPUT_NONE -1
101 #define VINO_INPUT_COMPOSITE 0
102 #define VINO_INPUT_SVIDEO 1
103 #define VINO_INPUT_D1 2
105 #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
107 #define VINO_FIFO_THRESHOLD_DEFAULT 16
109 #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
110 * VINO_PAL_HEIGHT * 4 \
111 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
113 #define VINO_FRAMEBUFFER_COUNT_MAX 8
115 #define VINO_FRAMEBUFFER_UNUSED 0
116 #define VINO_FRAMEBUFFER_IN_USE 1
117 #define VINO_FRAMEBUFFER_READY 2
119 #define VINO_QUEUE_ERROR -1
120 #define VINO_QUEUE_MAGIC 0x20050125
122 #define VINO_MEMORY_NONE 0
123 #define VINO_MEMORY_MMAP 1
124 #define VINO_MEMORY_USERPTR 2
126 #define VINO_DUMMY_DESC_COUNT 4
127 #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
129 #define VINO_MAX_FRAME_SKIP_COUNT 128
131 /* the number is the index for vino_data_formats */
132 #define VINO_DATA_FMT_NONE -1
133 #define VINO_DATA_FMT_GREY 0
134 #define VINO_DATA_FMT_RGB332 1
135 #define VINO_DATA_FMT_RGB32 2
136 #define VINO_DATA_FMT_YUV 3
138 #define VINO_DATA_FMT_COUNT 4
140 /* the number is the index for vino_data_norms */
141 #define VINO_DATA_NORM_NONE -1
142 #define VINO_DATA_NORM_NTSC 0
143 #define VINO_DATA_NORM_PAL 1
144 #define VINO_DATA_NORM_SECAM 2
145 #define VINO_DATA_NORM_D1 3
147 #define VINO_DATA_NORM_COUNT 4
149 /* I2C controller flags */
150 #define SGI_I2C_FORCE_IDLE (0 << 0)
151 #define SGI_I2C_NOT_IDLE (1 << 0)
152 #define SGI_I2C_WRITE (0 << 1)
153 #define SGI_I2C_READ (1 << 1)
154 #define SGI_I2C_RELEASE_BUS (0 << 2)
155 #define SGI_I2C_HOLD_BUS (1 << 2)
156 #define SGI_I2C_XFER_DONE (0 << 4)
157 #define SGI_I2C_XFER_BUSY (1 << 4)
158 #define SGI_I2C_ACK (0 << 5)
159 #define SGI_I2C_NACK (1 << 5)
160 #define SGI_I2C_BUS_OK (0 << 7)
161 #define SGI_I2C_BUS_ERR (1 << 7)
163 /* Internal data structure definitions */
170 struct vino_clipping
{
171 unsigned int left
, right
, top
, bottom
;
174 struct vino_data_format
{
175 /* the description */
177 /* bytes per pixel */
179 /* V4L2 fourcc code */
181 /* V4L2 colorspace (duh!) */
182 enum v4l2_colorspace colorspace
;
185 struct vino_data_norm
{
187 unsigned int width
, height
;
188 struct vino_clipping odd
;
189 struct vino_clipping even
;
192 unsigned int fps_min
, fps_max
;
196 struct vino_descriptor_table
{
197 /* the number of PAGE_SIZE sized pages in the buffer */
198 unsigned int page_count
;
199 /* virtual (kmalloc'd) pointers to the actual data
200 * (in PAGE_SIZE chunks, used with mmap streaming) */
201 unsigned long *virtual;
203 /* cpu address for the VINO descriptor table
204 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
205 unsigned long *dma_cpu
;
206 /* dma address for the VINO descriptor table
207 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
211 struct vino_framebuffer
{
212 /* identifier nubmer */
214 /* the length of the whole buffer */
216 /* the length of actual data in buffer */
217 unsigned int data_size
;
218 /* the data format */
219 unsigned int data_format
;
220 /* the state of buffer data */
222 /* is the buffer mapped in user space? */
223 unsigned int map_count
;
224 /* memory offset for mmap() */
227 unsigned int frame_counter
;
228 /* timestamp (written when image capture finishes) */
229 struct timeval timestamp
;
231 struct vino_descriptor_table desc_table
;
233 spinlock_t state_lock
;
236 struct vino_framebuffer_fifo
{
243 unsigned int data
[VINO_FRAMEBUFFER_COUNT_MAX
];
246 struct vino_framebuffer_queue
{
249 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
253 /* data field of in and out contain index numbers for buffer */
254 struct vino_framebuffer_fifo in
;
255 struct vino_framebuffer_fifo out
;
257 struct vino_framebuffer
*buffer
[VINO_FRAMEBUFFER_COUNT_MAX
];
259 spinlock_t queue_lock
;
260 struct mutex queue_mutex
;
261 wait_queue_head_t frame_wait_queue
;
264 struct vino_interrupt_data
{
265 struct timeval timestamp
;
266 unsigned int frame_counter
;
267 unsigned int skip_count
;
271 struct vino_channel_settings
{
272 unsigned int channel
;
275 unsigned int data_format
;
276 unsigned int data_norm
;
277 struct vino_clipping clipping
;
278 unsigned int decimation
;
279 unsigned int line_size
;
282 unsigned int framert_reg
;
284 unsigned int fifo_threshold
;
286 struct vino_framebuffer_queue fb_queue
;
288 /* number of the current field */
291 /* read in progress */
293 /* streaming is active */
295 /* the driver is currently processing the queue */
299 spinlock_t capture_lock
;
303 struct vino_interrupt_data int_data
;
306 struct video_device
*vdev
;
309 struct vino_settings
{
310 struct v4l2_device v4l2_dev
;
311 struct vino_channel_settings a
;
312 struct vino_channel_settings b
;
314 /* the channel which owns this client:
315 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
316 unsigned int decoder_owner
;
317 struct v4l2_subdev
*decoder
;
318 unsigned int camera_owner
;
319 struct v4l2_subdev
*camera
;
321 /* a lock for vino register access */
322 spinlock_t vino_lock
;
323 /* a lock for channel input changes */
324 spinlock_t input_lock
;
326 unsigned long dummy_page
;
327 struct vino_descriptor_table dummy_desc_table
;
330 /* Module parameters */
333 * Using vino_pixel_conversion the ABGR32-format pixels supplied
334 * by the VINO chip can be converted to more common formats
335 * like RGBA32 (or probably RGB24 in the future). This way we
336 * can give out data that can be specified correctly with
337 * the V4L2-definitions.
339 * The pixel format is specified as RGBA32 when no conversion
342 * Note that this only affects the 32-bit bit depth.
344 * Use non-zero value to enable conversion.
346 static int vino_pixel_conversion
;
348 module_param_named(pixelconv
, vino_pixel_conversion
, int, 0);
350 MODULE_PARM_DESC(pixelconv
,
351 "enable pixel conversion (non-zero value enables)");
353 /* Internal data structures */
355 static struct sgi_vino
*vino
;
357 static struct vino_settings
*vino_drvdata
;
359 #define camera_call(o, f, args...) \
360 v4l2_subdev_call(vino_drvdata->camera, o, f, ##args)
361 #define decoder_call(o, f, args...) \
362 v4l2_subdev_call(vino_drvdata->decoder, o, f, ##args)
364 static const char *vino_driver_name
= "vino";
365 static const char *vino_driver_description
= "SGI VINO";
366 static const char *vino_bus_name
= "GIO64 bus";
367 static const char *vino_vdev_name_a
= "SGI VINO Channel A";
368 static const char *vino_vdev_name_b
= "SGI VINO Channel B";
370 static void vino_capture_tasklet(unsigned long channel
);
372 DECLARE_TASKLET(vino_tasklet_a
, vino_capture_tasklet
, VINO_CHANNEL_A
);
373 DECLARE_TASKLET(vino_tasklet_b
, vino_capture_tasklet
, VINO_CHANNEL_B
);
375 static const struct vino_input vino_inputs
[] = {
378 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
382 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
385 .name
= "D1/IndyCam",
386 .std
= V4L2_STD_NTSC
,
390 static const struct vino_data_format vino_data_formats
[] = {
392 .description
= "8-bit greyscale",
394 .pixelformat
= V4L2_PIX_FMT_GREY
,
395 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
397 .description
= "8-bit dithered RGB 3-3-2",
399 .pixelformat
= V4L2_PIX_FMT_RGB332
,
400 .colorspace
= V4L2_COLORSPACE_SRGB
,
402 .description
= "32-bit RGB",
404 .pixelformat
= V4L2_PIX_FMT_RGB32
,
405 .colorspace
= V4L2_COLORSPACE_SRGB
,
407 .description
= "YUV 4:2:2",
409 .pixelformat
= V4L2_PIX_FMT_YUYV
, // XXX: swapped?
410 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
414 static const struct vino_data_norm vino_data_norms
[] = {
416 .description
= "NTSC",
417 .std
= V4L2_STD_NTSC
,
421 .width
= VINO_NTSC_WIDTH
,
422 .height
= VINO_NTSC_HEIGHT
,
424 .top
= VINO_CLIPPING_START_ODD_NTSC
,
426 .bottom
= VINO_CLIPPING_START_ODD_NTSC
427 + VINO_NTSC_HEIGHT
/ 2 - 1,
428 .right
= VINO_NTSC_WIDTH
,
431 .top
= VINO_CLIPPING_START_EVEN_NTSC
,
433 .bottom
= VINO_CLIPPING_START_EVEN_NTSC
434 + VINO_NTSC_HEIGHT
/ 2 - 1,
435 .right
= VINO_NTSC_WIDTH
,
438 .description
= "PAL",
443 .width
= VINO_PAL_WIDTH
,
444 .height
= VINO_PAL_HEIGHT
,
446 .top
= VINO_CLIPPING_START_ODD_PAL
,
448 .bottom
= VINO_CLIPPING_START_ODD_PAL
449 + VINO_PAL_HEIGHT
/ 2 - 1,
450 .right
= VINO_PAL_WIDTH
,
453 .top
= VINO_CLIPPING_START_EVEN_PAL
,
455 .bottom
= VINO_CLIPPING_START_EVEN_PAL
456 + VINO_PAL_HEIGHT
/ 2 - 1,
457 .right
= VINO_PAL_WIDTH
,
460 .description
= "SECAM",
461 .std
= V4L2_STD_SECAM
,
465 .width
= VINO_PAL_WIDTH
,
466 .height
= VINO_PAL_HEIGHT
,
468 .top
= VINO_CLIPPING_START_ODD_PAL
,
470 .bottom
= VINO_CLIPPING_START_ODD_PAL
471 + VINO_PAL_HEIGHT
/ 2 - 1,
472 .right
= VINO_PAL_WIDTH
,
475 .top
= VINO_CLIPPING_START_EVEN_PAL
,
477 .bottom
= VINO_CLIPPING_START_EVEN_PAL
478 + VINO_PAL_HEIGHT
/ 2 - 1,
479 .right
= VINO_PAL_WIDTH
,
482 .description
= "NTSC/D1",
483 .std
= V4L2_STD_NTSC
,
487 .width
= VINO_NTSC_WIDTH
,
488 .height
= VINO_NTSC_HEIGHT
,
490 .top
= VINO_CLIPPING_START_ODD_D1
,
492 .bottom
= VINO_CLIPPING_START_ODD_D1
493 + VINO_NTSC_HEIGHT
/ 2 - 1,
494 .right
= VINO_NTSC_WIDTH
,
497 .top
= VINO_CLIPPING_START_EVEN_D1
,
499 .bottom
= VINO_CLIPPING_START_EVEN_D1
500 + VINO_NTSC_HEIGHT
/ 2 - 1,
501 .right
= VINO_NTSC_WIDTH
,
506 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
508 struct v4l2_queryctrl vino_indycam_v4l2_controls
[] = {
510 .id
= V4L2_CID_AUTOGAIN
,
511 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
512 .name
= "Automatic Gain Control",
516 .default_value
= INDYCAM_AGC_DEFAULT
,
518 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
519 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
520 .name
= "Automatic White Balance",
524 .default_value
= INDYCAM_AWB_DEFAULT
,
527 .type
= V4L2_CTRL_TYPE_INTEGER
,
529 .minimum
= INDYCAM_GAIN_MIN
,
530 .maximum
= INDYCAM_GAIN_MAX
,
532 .default_value
= INDYCAM_GAIN_DEFAULT
,
534 .id
= INDYCAM_CONTROL_RED_SATURATION
,
535 .type
= V4L2_CTRL_TYPE_INTEGER
,
536 .name
= "Red Saturation",
537 .minimum
= INDYCAM_RED_SATURATION_MIN
,
538 .maximum
= INDYCAM_RED_SATURATION_MAX
,
540 .default_value
= INDYCAM_RED_SATURATION_DEFAULT
,
542 .id
= INDYCAM_CONTROL_BLUE_SATURATION
,
543 .type
= V4L2_CTRL_TYPE_INTEGER
,
544 .name
= "Blue Saturation",
545 .minimum
= INDYCAM_BLUE_SATURATION_MIN
,
546 .maximum
= INDYCAM_BLUE_SATURATION_MAX
,
548 .default_value
= INDYCAM_BLUE_SATURATION_DEFAULT
,
550 .id
= V4L2_CID_RED_BALANCE
,
551 .type
= V4L2_CTRL_TYPE_INTEGER
,
552 .name
= "Red Balance",
553 .minimum
= INDYCAM_RED_BALANCE_MIN
,
554 .maximum
= INDYCAM_RED_BALANCE_MAX
,
556 .default_value
= INDYCAM_RED_BALANCE_DEFAULT
,
558 .id
= V4L2_CID_BLUE_BALANCE
,
559 .type
= V4L2_CTRL_TYPE_INTEGER
,
560 .name
= "Blue Balance",
561 .minimum
= INDYCAM_BLUE_BALANCE_MIN
,
562 .maximum
= INDYCAM_BLUE_BALANCE_MAX
,
564 .default_value
= INDYCAM_BLUE_BALANCE_DEFAULT
,
566 .id
= V4L2_CID_EXPOSURE
,
567 .type
= V4L2_CTRL_TYPE_INTEGER
,
568 .name
= "Shutter Control",
569 .minimum
= INDYCAM_SHUTTER_MIN
,
570 .maximum
= INDYCAM_SHUTTER_MAX
,
572 .default_value
= INDYCAM_SHUTTER_DEFAULT
,
574 .id
= V4L2_CID_GAMMA
,
575 .type
= V4L2_CTRL_TYPE_INTEGER
,
577 .minimum
= INDYCAM_GAMMA_MIN
,
578 .maximum
= INDYCAM_GAMMA_MAX
,
580 .default_value
= INDYCAM_GAMMA_DEFAULT
,
584 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
586 struct v4l2_queryctrl vino_saa7191_v4l2_controls
[] = {
589 .type
= V4L2_CTRL_TYPE_INTEGER
,
591 .minimum
= SAA7191_HUE_MIN
,
592 .maximum
= SAA7191_HUE_MAX
,
594 .default_value
= SAA7191_HUE_DEFAULT
,
596 .id
= SAA7191_CONTROL_BANDPASS
,
597 .type
= V4L2_CTRL_TYPE_INTEGER
,
598 .name
= "Luminance Bandpass",
599 .minimum
= SAA7191_BANDPASS_MIN
,
600 .maximum
= SAA7191_BANDPASS_MAX
,
602 .default_value
= SAA7191_BANDPASS_DEFAULT
,
604 .id
= SAA7191_CONTROL_BANDPASS_WEIGHT
,
605 .type
= V4L2_CTRL_TYPE_INTEGER
,
606 .name
= "Luminance Bandpass Weight",
607 .minimum
= SAA7191_BANDPASS_WEIGHT_MIN
,
608 .maximum
= SAA7191_BANDPASS_WEIGHT_MAX
,
610 .default_value
= SAA7191_BANDPASS_WEIGHT_DEFAULT
,
612 .id
= SAA7191_CONTROL_CORING
,
613 .type
= V4L2_CTRL_TYPE_INTEGER
,
614 .name
= "HF Luminance Coring",
615 .minimum
= SAA7191_CORING_MIN
,
616 .maximum
= SAA7191_CORING_MAX
,
618 .default_value
= SAA7191_CORING_DEFAULT
,
620 .id
= SAA7191_CONTROL_FORCE_COLOUR
,
621 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
622 .name
= "Force Colour",
623 .minimum
= SAA7191_FORCE_COLOUR_MIN
,
624 .maximum
= SAA7191_FORCE_COLOUR_MAX
,
626 .default_value
= SAA7191_FORCE_COLOUR_DEFAULT
,
628 .id
= SAA7191_CONTROL_CHROMA_GAIN
,
629 .type
= V4L2_CTRL_TYPE_INTEGER
,
630 .name
= "Chrominance Gain Control",
631 .minimum
= SAA7191_CHROMA_GAIN_MIN
,
632 .maximum
= SAA7191_CHROMA_GAIN_MAX
,
634 .default_value
= SAA7191_CHROMA_GAIN_DEFAULT
,
636 .id
= SAA7191_CONTROL_VTRC
,
637 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
638 .name
= "VTR Time Constant",
639 .minimum
= SAA7191_VTRC_MIN
,
640 .maximum
= SAA7191_VTRC_MAX
,
642 .default_value
= SAA7191_VTRC_DEFAULT
,
644 .id
= SAA7191_CONTROL_LUMA_DELAY
,
645 .type
= V4L2_CTRL_TYPE_INTEGER
,
646 .name
= "Luminance Delay Compensation",
647 .minimum
= SAA7191_LUMA_DELAY_MIN
,
648 .maximum
= SAA7191_LUMA_DELAY_MAX
,
650 .default_value
= SAA7191_LUMA_DELAY_DEFAULT
,
652 .id
= SAA7191_CONTROL_VNR
,
653 .type
= V4L2_CTRL_TYPE_INTEGER
,
654 .name
= "Vertical Noise Reduction",
655 .minimum
= SAA7191_VNR_MIN
,
656 .maximum
= SAA7191_VNR_MAX
,
658 .default_value
= SAA7191_VNR_DEFAULT
,
662 /* VINO framebuffer/DMA descriptor management */
664 static void vino_free_buffer_with_count(struct vino_framebuffer
*fb
,
669 dprintk("vino_free_buffer_with_count(): count = %d\n", count
);
671 for (i
= 0; i
< count
; i
++) {
672 ClearPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
673 dma_unmap_single(NULL
,
674 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
675 PAGE_SIZE
, DMA_FROM_DEVICE
);
676 free_page(fb
->desc_table
.virtual[i
]);
679 dma_free_coherent(NULL
,
680 VINO_PAGE_RATIO
* (fb
->desc_table
.page_count
+ 4) *
681 sizeof(dma_addr_t
), (void *)fb
->desc_table
.dma_cpu
,
683 kfree(fb
->desc_table
.virtual);
685 memset(fb
, 0, sizeof(struct vino_framebuffer
));
688 static void vino_free_buffer(struct vino_framebuffer
*fb
)
690 vino_free_buffer_with_count(fb
, fb
->desc_table
.page_count
);
693 static int vino_allocate_buffer(struct vino_framebuffer
*fb
,
696 unsigned int count
, i
, j
;
699 dprintk("vino_allocate_buffer():\n");
704 memset(fb
, 0, sizeof(struct vino_framebuffer
));
706 count
= ((size
/ PAGE_SIZE
) + 4) & ~3;
708 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
711 /* allocate memory for table with virtual (page) addresses */
712 fb
->desc_table
.virtual = (unsigned long *)
713 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
714 if (!fb
->desc_table
.virtual)
717 /* allocate memory for table with dma addresses
718 * (has space for four extra descriptors) */
719 fb
->desc_table
.dma_cpu
=
720 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
721 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
722 GFP_KERNEL
| GFP_DMA
);
723 if (!fb
->desc_table
.dma_cpu
) {
725 goto out_free_virtual
;
728 /* allocate pages for the buffer and acquire the according
730 for (i
= 0; i
< count
; i
++) {
731 dma_addr_t dma_data_addr
;
733 fb
->desc_table
.virtual[i
] =
734 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
735 if (!fb
->desc_table
.virtual[i
]) {
742 (void *)fb
->desc_table
.virtual[i
],
743 PAGE_SIZE
, DMA_FROM_DEVICE
);
745 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
746 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
747 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
750 SetPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
753 /* page_count needs to be set anyway, because the descriptor table has
754 * been allocated according to this number */
755 fb
->desc_table
.page_count
= count
;
758 /* the descriptor with index i doesn't contain
759 * a valid address yet */
760 vino_free_buffer_with_count(fb
, i
);
765 fb
->size
= count
* PAGE_SIZE
;
766 fb
->data_format
= VINO_DATA_FMT_NONE
;
768 /* set the dma stop-bit for the last (count+1)th descriptor */
769 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
773 kfree(fb
->desc_table
.virtual);
778 /* user buffers not fully implemented yet */
779 static int vino_prepare_user_buffer(struct vino_framebuffer
*fb
,
783 unsigned int count
, i
, j
;
786 dprintk("vino_prepare_user_buffer():\n");
791 memset(fb
, 0, sizeof(struct vino_framebuffer
));
793 count
= ((size
/ PAGE_SIZE
)) & ~3;
795 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
798 /* allocate memory for table with virtual (page) addresses */
799 fb
->desc_table
.virtual = (unsigned long *)
800 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
801 if (!fb
->desc_table
.virtual)
804 /* allocate memory for table with dma addresses
805 * (has space for four extra descriptors) */
806 fb
->desc_table
.dma_cpu
=
807 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
808 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
809 GFP_KERNEL
| GFP_DMA
);
810 if (!fb
->desc_table
.dma_cpu
) {
812 goto out_free_virtual
;
815 /* allocate pages for the buffer and acquire the according
817 for (i
= 0; i
< count
; i
++) {
818 dma_addr_t dma_data_addr
;
820 fb
->desc_table
.virtual[i
] =
821 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
822 if (!fb
->desc_table
.virtual[i
]) {
829 (void *)fb
->desc_table
.virtual[i
],
830 PAGE_SIZE
, DMA_FROM_DEVICE
);
832 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
833 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
834 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
837 SetPageReserved(virt_to_page((void *)fb
->desc_table
.virtual[i
]));
840 /* page_count needs to be set anyway, because the descriptor table has
841 * been allocated according to this number */
842 fb
->desc_table
.page_count
= count
;
845 /* the descriptor with index i doesn't contain
846 * a valid address yet */
847 vino_free_buffer_with_count(fb
, i
);
852 fb
->size
= count
* PAGE_SIZE
;
854 /* set the dma stop-bit for the last (count+1)th descriptor */
855 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
859 kfree(fb
->desc_table
.virtual);
864 static void vino_sync_buffer(struct vino_framebuffer
*fb
)
868 dprintk("vino_sync_buffer():\n");
870 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++)
871 dma_sync_single_for_cpu(NULL
,
872 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
873 PAGE_SIZE
, DMA_FROM_DEVICE
);
876 /* Framebuffer fifo functions (need to be locked externally) */
878 static inline void vino_fifo_init(struct vino_framebuffer_fifo
*f
,
886 if (length
> VINO_FRAMEBUFFER_COUNT_MAX
)
887 length
= VINO_FRAMEBUFFER_COUNT_MAX
;
892 /* returns true/false */
893 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo
*f
,
898 for (i
= f
->head
; i
== (f
->tail
- 1); i
= (i
+ 1) % f
->length
) {
899 if (f
->data
[i
] == id
)
907 /* returns true/false */
908 static inline int vino_fifo_full(struct vino_framebuffer_fifo
*f
)
910 return (f
->used
== f
->length
);
914 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo
*f
)
919 static int vino_fifo_enqueue(struct vino_framebuffer_fifo
*f
, unsigned int id
)
921 if (id
>= f
->length
) {
922 return VINO_QUEUE_ERROR
;
925 if (vino_fifo_has_id(f
, id
)) {
926 return VINO_QUEUE_ERROR
;
929 if (f
->used
< f
->length
) {
930 f
->data
[f
->tail
] = id
;
931 f
->tail
= (f
->tail
+ 1) % f
->length
;
934 return VINO_QUEUE_ERROR
;
940 static int vino_fifo_peek(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
943 *id
= f
->data
[f
->head
];
945 return VINO_QUEUE_ERROR
;
951 static int vino_fifo_dequeue(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
954 *id
= f
->data
[f
->head
];
955 f
->head
= (f
->head
+ 1) % f
->length
;
958 return VINO_QUEUE_ERROR
;
964 /* Framebuffer queue functions */
966 /* execute with queue_lock locked */
967 static void vino_queue_free_with_count(struct vino_framebuffer_queue
*q
,
973 memset(&q
->in
, 0, sizeof(struct vino_framebuffer_fifo
));
974 memset(&q
->out
, 0, sizeof(struct vino_framebuffer_fifo
));
975 for (i
= 0; i
< length
; i
++) {
976 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
978 vino_free_buffer(q
->buffer
[i
]);
982 q
->type
= VINO_MEMORY_NONE
;
986 static void vino_queue_free(struct vino_framebuffer_queue
*q
)
988 dprintk("vino_queue_free():\n");
990 if (q
->magic
!= VINO_QUEUE_MAGIC
)
992 if (q
->type
!= VINO_MEMORY_MMAP
)
995 mutex_lock(&q
->queue_mutex
);
997 vino_queue_free_with_count(q
, q
->length
);
999 mutex_unlock(&q
->queue_mutex
);
1002 static int vino_queue_init(struct vino_framebuffer_queue
*q
,
1003 unsigned int *length
)
1008 dprintk("vino_queue_init(): length = %d\n", *length
);
1010 if (q
->magic
== VINO_QUEUE_MAGIC
) {
1011 dprintk("vino_queue_init(): queue already initialized!\n");
1015 if (q
->type
!= VINO_MEMORY_NONE
) {
1016 dprintk("vino_queue_init(): queue already initialized!\n");
1023 mutex_lock(&q
->queue_mutex
);
1025 if (*length
> VINO_FRAMEBUFFER_COUNT_MAX
)
1026 *length
= VINO_FRAMEBUFFER_COUNT_MAX
;
1030 for (i
= 0; i
< *length
; i
++) {
1031 dprintk("vino_queue_init(): allocating buffer %d\n", i
);
1032 q
->buffer
[i
] = kmalloc(sizeof(struct vino_framebuffer
),
1034 if (!q
->buffer
[i
]) {
1035 dprintk("vino_queue_init(): kmalloc() failed\n");
1040 ret
= vino_allocate_buffer(q
->buffer
[i
],
1041 VINO_FRAMEBUFFER_SIZE
);
1043 kfree(q
->buffer
[i
]);
1044 dprintk("vino_queue_init(): "
1045 "vino_allocate_buffer() failed\n");
1049 q
->buffer
[i
]->id
= i
;
1051 q
->buffer
[i
]->offset
= q
->buffer
[i
- 1]->offset
+
1052 q
->buffer
[i
- 1]->size
;
1054 q
->buffer
[i
]->offset
= 0;
1057 spin_lock_init(&q
->buffer
[i
]->state_lock
);
1059 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1060 "size = %d\n", i
, q
->buffer
[i
]->offset
,
1061 q
->buffer
[i
]->size
);
1065 vino_queue_free_with_count(q
, i
);
1068 q
->length
= *length
;
1069 vino_fifo_init(&q
->in
, q
->length
);
1070 vino_fifo_init(&q
->out
, q
->length
);
1071 q
->type
= VINO_MEMORY_MMAP
;
1072 q
->magic
= VINO_QUEUE_MAGIC
;
1075 mutex_unlock(&q
->queue_mutex
);
1080 static struct vino_framebuffer
*vino_queue_add(struct
1081 vino_framebuffer_queue
*q
,
1084 struct vino_framebuffer
*ret
= NULL
;
1086 unsigned long flags
;
1088 dprintk("vino_queue_add(): id = %d\n", id
);
1090 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1094 spin_lock_irqsave(&q
->queue_lock
, flags
);
1099 if (id
>= q
->length
)
1102 /* not needed?: if (vino_fifo_full(&q->out)) {
1105 /* check that outgoing queue isn't already full
1106 * (or that it won't become full) */
1107 total
= vino_fifo_get_used(&q
->in
) +
1108 vino_fifo_get_used(&q
->out
);
1109 if (total
>= q
->length
)
1112 if (vino_fifo_enqueue(&q
->in
, id
))
1115 ret
= q
->buffer
[id
];
1118 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1123 static struct vino_framebuffer
*vino_queue_transfer(struct
1124 vino_framebuffer_queue
*q
)
1126 struct vino_framebuffer
*ret
= NULL
;
1127 struct vino_framebuffer
*fb
;
1129 unsigned long flags
;
1131 dprintk("vino_queue_transfer():\n");
1133 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1137 spin_lock_irqsave(&q
->queue_lock
, flags
);
1142 // now this actually removes an entry from the incoming queue
1143 if (vino_fifo_dequeue(&q
->in
, &id
)) {
1147 dprintk("vino_queue_transfer(): id = %d\n", id
);
1150 // we have already checked that the outgoing queue is not full, but...
1151 if (vino_fifo_enqueue(&q
->out
, id
)) {
1152 printk(KERN_ERR
"vino_queue_transfer(): "
1153 "outgoing queue is full, this shouldn't happen!\n");
1159 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1164 /* returns true/false */
1165 static int vino_queue_incoming_contains(struct vino_framebuffer_queue
*q
,
1169 unsigned long flags
;
1171 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1175 spin_lock_irqsave(&q
->queue_lock
, flags
);
1180 ret
= vino_fifo_has_id(&q
->in
, id
);
1183 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1188 /* returns true/false */
1189 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue
*q
,
1193 unsigned long flags
;
1195 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1199 spin_lock_irqsave(&q
->queue_lock
, flags
);
1204 ret
= vino_fifo_has_id(&q
->out
, id
);
1207 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1212 static int vino_queue_get_incoming(struct vino_framebuffer_queue
*q
,
1216 unsigned long flags
;
1218 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1219 return VINO_QUEUE_ERROR
;
1222 spin_lock_irqsave(&q
->queue_lock
, flags
);
1224 if (q
->length
== 0) {
1225 ret
= VINO_QUEUE_ERROR
;
1229 *used
= vino_fifo_get_used(&q
->in
);
1232 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1237 static int vino_queue_get_outgoing(struct vino_framebuffer_queue
*q
,
1241 unsigned long flags
;
1243 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1244 return VINO_QUEUE_ERROR
;
1247 spin_lock_irqsave(&q
->queue_lock
, flags
);
1249 if (q
->length
== 0) {
1250 ret
= VINO_QUEUE_ERROR
;
1254 *used
= vino_fifo_get_used(&q
->out
);
1257 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1263 static int vino_queue_get_total(struct vino_framebuffer_queue
*q
,
1264 unsigned int *total
)
1267 unsigned long flags
;
1269 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1270 return VINO_QUEUE_ERROR
;
1273 spin_lock_irqsave(&q
->queue_lock
, flags
);
1275 if (q
->length
== 0) {
1276 ret
= VINO_QUEUE_ERROR
;
1280 *total
= vino_fifo_get_used(&q
->in
) +
1281 vino_fifo_get_used(&q
->out
);
1284 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1290 static struct vino_framebuffer
*vino_queue_peek(struct
1291 vino_framebuffer_queue
*q
,
1294 struct vino_framebuffer
*ret
= NULL
;
1295 unsigned long flags
;
1297 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1301 spin_lock_irqsave(&q
->queue_lock
, flags
);
1306 if (vino_fifo_peek(&q
->in
, id
)) {
1310 ret
= q
->buffer
[*id
];
1312 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1317 static struct vino_framebuffer
*vino_queue_remove(struct
1318 vino_framebuffer_queue
*q
,
1321 struct vino_framebuffer
*ret
= NULL
;
1322 unsigned long flags
;
1323 dprintk("vino_queue_remove():\n");
1325 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1329 spin_lock_irqsave(&q
->queue_lock
, flags
);
1334 if (vino_fifo_dequeue(&q
->out
, id
)) {
1338 dprintk("vino_queue_remove(): id = %d\n", *id
);
1339 ret
= q
->buffer
[*id
];
1341 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1347 vino_framebuffer
*vino_queue_get_buffer(struct vino_framebuffer_queue
*q
,
1350 struct vino_framebuffer
*ret
= NULL
;
1351 unsigned long flags
;
1353 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1357 spin_lock_irqsave(&q
->queue_lock
, flags
);
1362 if (id
>= q
->length
)
1365 ret
= q
->buffer
[id
];
1367 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1372 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue
*q
)
1374 unsigned int length
= 0;
1375 unsigned long flags
;
1377 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1381 spin_lock_irqsave(&q
->queue_lock
, flags
);
1383 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1388 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue
*q
)
1392 unsigned long flags
;
1394 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1398 spin_lock_irqsave(&q
->queue_lock
, flags
);
1399 for (i
= 0; i
< q
->length
; i
++) {
1400 if (q
->buffer
[i
]->map_count
> 0) {
1405 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1410 /* VINO functions */
1412 /* execute with input_lock locked */
1413 static void vino_update_line_size(struct vino_channel_settings
*vcs
)
1415 unsigned int w
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1416 unsigned int d
= vcs
->decimation
;
1417 unsigned int bpp
= vino_data_formats
[vcs
->data_format
].bpp
;
1420 dprintk("update_line_size(): before: w = %d, d = %d, "
1421 "line_size = %d\n", w
, d
, vcs
->line_size
);
1423 /* line size must be multiple of 8 bytes */
1424 lsize
= (bpp
* (w
/ d
)) & ~7;
1425 w
= (lsize
/ bpp
) * d
;
1427 vcs
->clipping
.right
= vcs
->clipping
.left
+ w
;
1428 vcs
->line_size
= lsize
;
1430 dprintk("update_line_size(): after: w = %d, d = %d, "
1431 "line_size = %d\n", w
, d
, vcs
->line_size
);
1434 /* execute with input_lock locked */
1435 static void vino_set_clipping(struct vino_channel_settings
*vcs
,
1436 unsigned int x
, unsigned int y
,
1437 unsigned int w
, unsigned int h
)
1439 unsigned int maxwidth
, maxheight
;
1442 maxwidth
= vino_data_norms
[vcs
->data_norm
].width
;
1443 maxheight
= vino_data_norms
[vcs
->data_norm
].height
;
1444 d
= vcs
->decimation
;
1446 y
&= ~1; /* odd/even fields */
1451 if (y
> maxheight
) {
1455 if (((w
/ d
) < VINO_MIN_WIDTH
)
1456 || ((h
/ d
) < VINO_MIN_HEIGHT
)) {
1457 w
= VINO_MIN_WIDTH
* d
;
1458 h
= VINO_MIN_HEIGHT
* d
;
1461 if ((x
+ w
) > maxwidth
) {
1463 if ((w
/ d
) < VINO_MIN_WIDTH
)
1464 x
= maxwidth
- VINO_MIN_WIDTH
* d
;
1466 if ((y
+ h
) > maxheight
) {
1468 if ((h
/ d
) < VINO_MIN_HEIGHT
)
1469 y
= maxheight
- VINO_MIN_HEIGHT
* d
;
1472 vcs
->clipping
.left
= x
;
1473 vcs
->clipping
.top
= y
;
1474 vcs
->clipping
.right
= x
+ w
;
1475 vcs
->clipping
.bottom
= y
+ h
;
1477 vino_update_line_size(vcs
);
1479 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1480 vcs
->clipping
.left
, vcs
->clipping
.top
, vcs
->clipping
.right
,
1481 vcs
->clipping
.bottom
, vcs
->decimation
, vcs
->line_size
);
1484 /* execute with input_lock locked */
1485 static inline void vino_set_default_clipping(struct vino_channel_settings
*vcs
)
1487 vino_set_clipping(vcs
, 0, 0, vino_data_norms
[vcs
->data_norm
].width
,
1488 vino_data_norms
[vcs
->data_norm
].height
);
1491 /* execute with input_lock locked */
1492 static void vino_set_scaling(struct vino_channel_settings
*vcs
,
1493 unsigned int w
, unsigned int h
)
1495 unsigned int x
, y
, curw
, curh
, d
;
1497 x
= vcs
->clipping
.left
;
1498 y
= vcs
->clipping
.top
;
1499 curw
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1500 curh
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
1502 d
= max(curw
/ w
, curh
/ h
);
1504 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1505 w
, h
, curw
, curh
, d
);
1513 vcs
->decimation
= d
;
1514 vino_set_clipping(vcs
, x
, y
, w
* d
, h
* d
);
1516 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs
->clipping
.left
,
1517 vcs
->clipping
.top
, vcs
->clipping
.right
, vcs
->clipping
.bottom
,
1518 vcs
->decimation
, vcs
->line_size
);
1521 /* execute with input_lock locked */
1522 static inline void vino_set_default_scaling(struct vino_channel_settings
*vcs
)
1524 vino_set_scaling(vcs
, vcs
->clipping
.right
- vcs
->clipping
.left
,
1525 vcs
->clipping
.bottom
- vcs
->clipping
.top
);
1528 /* execute with input_lock locked */
1529 static void vino_set_framerate(struct vino_channel_settings
*vcs
,
1534 switch (vcs
->data_norm
) {
1535 case VINO_DATA_NORM_NTSC
:
1536 case VINO_DATA_NORM_D1
:
1537 fps
= (unsigned int)(fps
/ 6) * 6; // FIXME: round!
1539 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1540 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1541 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1542 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1561 mask
= VINO_FRAMERT_FULL
;
1563 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
);
1565 case VINO_DATA_NORM_PAL
:
1566 case VINO_DATA_NORM_SECAM
:
1567 fps
= (unsigned int)(fps
/ 5) * 5; // FIXME: round!
1569 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1570 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1571 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1572 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1591 mask
= VINO_FRAMERT_FULL
;
1593 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
) | VINO_FRAMERT_PAL
;
1600 /* execute with input_lock locked */
1601 static inline void vino_set_default_framerate(struct
1602 vino_channel_settings
*vcs
)
1604 vino_set_framerate(vcs
, vino_data_norms
[vcs
->data_norm
].fps_max
);
1607 /* VINO I2C bus functions */
1609 struct i2c_algo_sgi_data
{
1610 void *data
; /* private data for lowlevel routines */
1611 unsigned (*getctrl
)(void *data
);
1612 void (*setctrl
)(void *data
, unsigned val
);
1613 unsigned (*rdata
)(void *data
);
1614 void (*wdata
)(void *data
, unsigned val
);
1620 static int wait_xfer_done(struct i2c_algo_sgi_data
*adap
)
1624 for (i
= 0; i
< adap
->xfer_timeout
; i
++) {
1625 if ((adap
->getctrl(adap
->data
) & SGI_I2C_XFER_BUSY
) == 0)
1633 static int wait_ack(struct i2c_algo_sgi_data
*adap
)
1637 if (wait_xfer_done(adap
))
1639 for (i
= 0; i
< adap
->ack_timeout
; i
++) {
1640 if ((adap
->getctrl(adap
->data
) & SGI_I2C_NACK
) == 0)
1648 static int force_idle(struct i2c_algo_sgi_data
*adap
)
1652 adap
->setctrl(adap
->data
, SGI_I2C_FORCE_IDLE
);
1653 for (i
= 0; i
< adap
->xfer_timeout
; i
++) {
1654 if ((adap
->getctrl(adap
->data
) & SGI_I2C_NOT_IDLE
) == 0)
1660 if (adap
->getctrl(adap
->data
) & SGI_I2C_BUS_ERR
)
1665 static int do_address(struct i2c_algo_sgi_data
*adap
, unsigned int addr
,
1669 adap
->setctrl(adap
->data
, SGI_I2C_NOT_IDLE
);
1670 /* Check if bus is idle, eventually force it to do so */
1671 if (adap
->getctrl(adap
->data
) & SGI_I2C_NOT_IDLE
)
1672 if (force_idle(adap
))
1674 /* Write out the i2c chip address and specify operation */
1675 adap
->setctrl(adap
->data
,
1676 SGI_I2C_HOLD_BUS
| SGI_I2C_WRITE
| SGI_I2C_NOT_IDLE
);
1679 adap
->wdata(adap
->data
, addr
);
1685 static int i2c_read(struct i2c_algo_sgi_data
*adap
, unsigned char *buf
,
1690 adap
->setctrl(adap
->data
,
1691 SGI_I2C_HOLD_BUS
| SGI_I2C_READ
| SGI_I2C_NOT_IDLE
);
1692 for (i
= 0; i
< len
; i
++) {
1693 if (wait_xfer_done(adap
))
1695 buf
[i
] = adap
->rdata(adap
->data
);
1697 adap
->setctrl(adap
->data
, SGI_I2C_RELEASE_BUS
| SGI_I2C_FORCE_IDLE
);
1703 static int i2c_write(struct i2c_algo_sgi_data
*adap
, unsigned char *buf
,
1708 /* We are already in write state */
1709 for (i
= 0; i
< len
; i
++) {
1710 adap
->wdata(adap
->data
, buf
[i
]);
1717 static int sgi_xfer(struct i2c_adapter
*i2c_adap
, struct i2c_msg
*msgs
,
1720 struct i2c_algo_sgi_data
*adap
= i2c_adap
->algo_data
;
1724 for (i
= 0; !err
&& i
< num
; i
++) {
1726 err
= do_address(adap
, p
->addr
, p
->flags
& I2C_M_RD
);
1729 if (p
->flags
& I2C_M_RD
)
1730 err
= i2c_read(adap
, p
->buf
, p
->len
);
1732 err
= i2c_write(adap
, p
->buf
, p
->len
);
1735 return (err
< 0) ? err
: i
;
1738 static u32
sgi_func(struct i2c_adapter
*adap
)
1740 return I2C_FUNC_SMBUS_EMUL
;
1743 static const struct i2c_algorithm sgi_algo
= {
1744 .master_xfer
= sgi_xfer
,
1745 .functionality
= sgi_func
,
1748 static unsigned i2c_vino_getctrl(void *data
)
1750 return vino
->i2c_control
;
1753 static void i2c_vino_setctrl(void *data
, unsigned val
)
1755 vino
->i2c_control
= val
;
1758 static unsigned i2c_vino_rdata(void *data
)
1760 return vino
->i2c_data
;
1763 static void i2c_vino_wdata(void *data
, unsigned val
)
1765 vino
->i2c_data
= val
;
1768 static struct i2c_algo_sgi_data i2c_sgi_vino_data
= {
1769 .getctrl
= &i2c_vino_getctrl
,
1770 .setctrl
= &i2c_vino_setctrl
,
1771 .rdata
= &i2c_vino_rdata
,
1772 .wdata
= &i2c_vino_wdata
,
1773 .xfer_timeout
= 200,
1774 .ack_timeout
= 1000,
1777 static struct i2c_adapter vino_i2c_adapter
= {
1778 .name
= "VINO I2C bus",
1780 .algo_data
= &i2c_sgi_vino_data
,
1781 .owner
= THIS_MODULE
,
1785 * Prepare VINO for DMA transfer...
1786 * (execute only with vino_lock and input_lock locked)
1788 static int vino_dma_setup(struct vino_channel_settings
*vcs
,
1789 struct vino_framebuffer
*fb
)
1792 struct sgi_vino_channel
*ch
;
1793 const struct vino_data_norm
*norm
;
1795 dprintk("vino_dma_setup():\n");
1798 fb
->frame_counter
= 0;
1800 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1801 norm
= &vino_data_norms
[vcs
->data_norm
];
1806 /* VINO line size register is set 8 bytes less than actual */
1807 ch
->line_size
= vcs
->line_size
- 8;
1809 /* let VINO know where to transfer data */
1810 ch
->start_desc_tbl
= fb
->desc_table
.dma
;
1811 ch
->next_4_desc
= fb
->desc_table
.dma
;
1813 /* give vino time to fetch the first four descriptors, 5 usec
1814 * should be more than enough time */
1815 udelay(VINO_DESC_FETCH_DELAY
);
1817 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1818 ch
->start_desc_tbl
, ch
->next_4_desc
);
1820 /* set the alpha register */
1821 ch
->alpha
= vcs
->alpha
;
1823 /* set clipping registers */
1824 ch
->clip_start
= VINO_CLIP_ODD(norm
->odd
.top
+ vcs
->clipping
.top
/ 2) |
1825 VINO_CLIP_EVEN(norm
->even
.top
+
1826 vcs
->clipping
.top
/ 2) |
1827 VINO_CLIP_X(vcs
->clipping
.left
);
1828 ch
->clip_end
= VINO_CLIP_ODD(norm
->odd
.top
+
1829 vcs
->clipping
.bottom
/ 2 - 1) |
1830 VINO_CLIP_EVEN(norm
->even
.top
+
1831 vcs
->clipping
.bottom
/ 2 - 1) |
1832 VINO_CLIP_X(vcs
->clipping
.right
);
1834 /* set the size of actual content in the buffer (DECIMATION !) */
1835 fb
->data_size
= ((vcs
->clipping
.right
- vcs
->clipping
.left
) /
1837 ((vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
1839 vino_data_formats
[vcs
->data_format
].bpp
;
1841 ch
->frame_rate
= vcs
->framert_reg
;
1843 ctrl
= vino
->control
;
1844 intr
= vino
->intr_status
;
1846 if (vcs
->channel
== VINO_CHANNEL_A
) {
1847 /* All interrupt conditions for this channel was cleared
1848 * so clear the interrupt status register and enable
1850 intr
&= ~VINO_INTSTAT_A
;
1851 ctrl
|= VINO_CTRL_A_INT
;
1853 /* enable synchronization */
1854 ctrl
|= VINO_CTRL_A_SYNC_ENBL
;
1856 /* enable frame assembly */
1857 ctrl
|= VINO_CTRL_A_INTERLEAVE_ENBL
;
1859 /* set decimation used */
1860 if (vcs
->decimation
< 2)
1861 ctrl
&= ~VINO_CTRL_A_DEC_ENBL
;
1863 ctrl
|= VINO_CTRL_A_DEC_ENBL
;
1864 ctrl
&= ~VINO_CTRL_A_DEC_SCALE_MASK
;
1865 ctrl
|= (vcs
->decimation
- 1) <<
1866 VINO_CTRL_A_DEC_SCALE_SHIFT
;
1869 /* select input interface */
1870 if (vcs
->input
== VINO_INPUT_D1
)
1871 ctrl
|= VINO_CTRL_A_SELECT
;
1873 ctrl
&= ~VINO_CTRL_A_SELECT
;
1876 ctrl
&= ~(VINO_CTRL_A_LUMA_ONLY
| VINO_CTRL_A_RGB
|
1877 VINO_CTRL_A_DITHER
);
1879 intr
&= ~VINO_INTSTAT_B
;
1880 ctrl
|= VINO_CTRL_B_INT
;
1882 ctrl
|= VINO_CTRL_B_SYNC_ENBL
;
1883 ctrl
|= VINO_CTRL_B_INTERLEAVE_ENBL
;
1885 if (vcs
->decimation
< 2)
1886 ctrl
&= ~VINO_CTRL_B_DEC_ENBL
;
1888 ctrl
|= VINO_CTRL_B_DEC_ENBL
;
1889 ctrl
&= ~VINO_CTRL_B_DEC_SCALE_MASK
;
1890 ctrl
|= (vcs
->decimation
- 1) <<
1891 VINO_CTRL_B_DEC_SCALE_SHIFT
;
1894 if (vcs
->input
== VINO_INPUT_D1
)
1895 ctrl
|= VINO_CTRL_B_SELECT
;
1897 ctrl
&= ~VINO_CTRL_B_SELECT
;
1899 ctrl
&= ~(VINO_CTRL_B_LUMA_ONLY
| VINO_CTRL_B_RGB
|
1900 VINO_CTRL_B_DITHER
);
1904 fb
->data_format
= vcs
->data_format
;
1906 switch (vcs
->data_format
) {
1907 case VINO_DATA_FMT_GREY
:
1908 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1909 VINO_CTRL_A_LUMA_ONLY
: VINO_CTRL_B_LUMA_ONLY
;
1911 case VINO_DATA_FMT_RGB32
:
1912 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1913 VINO_CTRL_A_RGB
: VINO_CTRL_B_RGB
;
1915 case VINO_DATA_FMT_YUV
:
1916 /* nothing needs to be done */
1918 case VINO_DATA_FMT_RGB332
:
1919 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1920 VINO_CTRL_A_RGB
| VINO_CTRL_A_DITHER
:
1921 VINO_CTRL_B_RGB
| VINO_CTRL_B_DITHER
;
1925 vino
->intr_status
= intr
;
1926 vino
->control
= ctrl
;
1931 /* (execute only with vino_lock locked) */
1932 static inline void vino_dma_start(struct vino_channel_settings
*vcs
)
1934 u32 ctrl
= vino
->control
;
1936 dprintk("vino_dma_start():\n");
1937 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1938 VINO_CTRL_A_DMA_ENBL
: VINO_CTRL_B_DMA_ENBL
;
1939 vino
->control
= ctrl
;
1942 /* (execute only with vino_lock locked) */
1943 static inline void vino_dma_stop(struct vino_channel_settings
*vcs
)
1945 u32 ctrl
= vino
->control
;
1947 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1948 ~VINO_CTRL_A_DMA_ENBL
: ~VINO_CTRL_B_DMA_ENBL
;
1949 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1950 ~VINO_CTRL_A_INT
: ~VINO_CTRL_B_INT
;
1951 vino
->control
= ctrl
;
1952 dprintk("vino_dma_stop():\n");
1956 * Load dummy page to descriptor registers. This prevents generating of
1957 * spurious interrupts. (execute only with vino_lock locked)
1959 static void vino_clear_interrupt(struct vino_channel_settings
*vcs
)
1961 struct sgi_vino_channel
*ch
;
1963 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1968 ch
->start_desc_tbl
= vino_drvdata
->dummy_desc_table
.dma
;
1969 ch
->next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
1971 udelay(VINO_DESC_FETCH_DELAY
);
1972 dprintk("channel %c clear interrupt condition\n",
1973 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A':'B');
1976 static int vino_capture(struct vino_channel_settings
*vcs
,
1977 struct vino_framebuffer
*fb
)
1980 unsigned long flags
, flags2
;
1982 spin_lock_irqsave(&fb
->state_lock
, flags
);
1984 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
1986 fb
->state
= VINO_FRAMEBUFFER_IN_USE
;
1988 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
1993 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
1994 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags2
);
1996 vino_dma_setup(vcs
, fb
);
1997 vino_dma_start(vcs
);
1999 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags2
);
2000 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2006 struct vino_framebuffer
*vino_capture_enqueue(struct
2007 vino_channel_settings
*vcs
,
2010 struct vino_framebuffer
*fb
;
2011 unsigned long flags
;
2013 dprintk("vino_capture_enqueue():\n");
2015 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2017 fb
= vino_queue_add(&vcs
->fb_queue
, index
);
2019 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
2024 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2029 static int vino_capture_next(struct vino_channel_settings
*vcs
, int start
)
2031 struct vino_framebuffer
*fb
;
2032 unsigned int incoming
, id
;
2034 unsigned long flags
;
2036 dprintk("vino_capture_next():\n");
2038 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2041 /* start capture only if capture isn't in progress already */
2042 if (vcs
->capturing
) {
2043 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2048 /* capture next frame:
2049 * stop capture if capturing is not set */
2050 if (!vcs
->capturing
) {
2051 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2056 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
2058 dprintk("vino_capture_next(): vino_queue_get_incoming() "
2063 if (incoming
== 0) {
2064 dprintk("vino_capture_next(): no buffers available\n");
2068 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2070 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
2079 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2081 err
= vino_capture(vcs
, fb
);
2087 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2092 static inline int vino_is_capturing(struct vino_channel_settings
*vcs
)
2095 unsigned long flags
;
2097 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2099 ret
= vcs
->capturing
;
2101 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2106 /* waits until a frame is captured */
2107 static int vino_wait_for_frame(struct vino_channel_settings
*vcs
)
2112 dprintk("vino_wait_for_frame():\n");
2114 init_waitqueue_entry(&wait
, current
);
2115 /* add ourselves into wait queue */
2116 add_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2118 /* to ensure that schedule_timeout will return immediately
2119 * if VINO interrupt was triggered meanwhile */
2120 schedule_timeout_interruptible(msecs_to_jiffies(100));
2122 if (signal_pending(current
))
2125 remove_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2127 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2128 err
? "failed" : "ok");
2133 /* the function assumes that PAGE_SIZE % 4 == 0 */
2134 static void vino_convert_to_rgba(struct vino_framebuffer
*fb
) {
2135 unsigned char *pageptr
;
2136 unsigned int page
, i
;
2139 for (page
= 0; page
< fb
->desc_table
.page_count
; page
++) {
2140 pageptr
= (unsigned char *)fb
->desc_table
.virtual[page
];
2142 for (i
= 0; i
< PAGE_SIZE
; i
+= 4) {
2144 pageptr
[0] = pageptr
[3];
2145 pageptr
[1] = pageptr
[2];
2146 pageptr
[2] = pageptr
[1];
2153 /* checks if the buffer is in correct state and syncs data */
2154 static int vino_check_buffer(struct vino_channel_settings
*vcs
,
2155 struct vino_framebuffer
*fb
)
2158 unsigned long flags
;
2160 dprintk("vino_check_buffer():\n");
2162 spin_lock_irqsave(&fb
->state_lock
, flags
);
2163 switch (fb
->state
) {
2164 case VINO_FRAMEBUFFER_IN_USE
:
2167 case VINO_FRAMEBUFFER_READY
:
2168 vino_sync_buffer(fb
);
2169 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2174 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2177 if (vino_pixel_conversion
2178 && (fb
->data_format
== VINO_DATA_FMT_RGB32
)) {
2179 vino_convert_to_rgba(fb
);
2181 } else if (err
&& (err
!= -EINVAL
)) {
2182 dprintk("vino_check_buffer(): buffer not ready\n");
2184 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2186 vino_clear_interrupt(vcs
);
2187 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2193 /* forcefully terminates capture */
2194 static void vino_capture_stop(struct vino_channel_settings
*vcs
)
2196 unsigned int incoming
= 0, outgoing
= 0, id
;
2197 unsigned long flags
, flags2
;
2199 dprintk("vino_capture_stop():\n");
2201 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2203 /* unset capturing to stop queue processing */
2206 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags2
);
2209 vino_clear_interrupt(vcs
);
2211 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags2
);
2213 /* remove all items from the queue */
2214 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2215 dprintk("vino_capture_stop(): "
2216 "vino_queue_get_incoming() failed\n");
2219 while (incoming
> 0) {
2220 vino_queue_transfer(&vcs
->fb_queue
);
2222 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2223 dprintk("vino_capture_stop(): "
2224 "vino_queue_get_incoming() failed\n");
2229 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2230 dprintk("vino_capture_stop(): "
2231 "vino_queue_get_outgoing() failed\n");
2234 while (outgoing
> 0) {
2235 vino_queue_remove(&vcs
->fb_queue
, &id
);
2237 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2238 dprintk("vino_capture_stop(): "
2239 "vino_queue_get_outgoing() failed\n");
2245 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2249 static int vino_capture_failed(struct vino_channel_settings
*vcs
)
2251 struct vino_framebuffer
*fb
;
2252 unsigned long flags
;
2256 dprintk("vino_capture_failed():\n");
2258 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2261 vino_clear_interrupt(vcs
);
2263 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2265 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &i
);
2266 if (ret
== VINO_QUEUE_ERROR
) {
2267 dprintk("vino_queue_get_incoming() failed\n");
2271 /* no buffers to process */
2275 fb
= vino_queue_peek(&vcs
->fb_queue
, &i
);
2277 dprintk("vino_queue_peek() failed\n");
2281 spin_lock_irqsave(&fb
->state_lock
, flags
);
2282 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
) {
2283 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2284 vino_queue_transfer(&vcs
->fb_queue
);
2285 vino_queue_remove(&vcs
->fb_queue
, &i
);
2286 /* we should actually discard the newest frame,
2287 * but who cares ... */
2289 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2295 static void vino_skip_frame(struct vino_channel_settings
*vcs
)
2297 struct vino_framebuffer
*fb
;
2298 unsigned long flags
;
2301 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2302 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2304 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2305 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2308 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2310 spin_lock_irqsave(&fb
->state_lock
, flags
);
2311 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2312 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2314 vino_capture_next(vcs
, 0);
2317 static void vino_frame_done(struct vino_channel_settings
*vcs
)
2319 struct vino_framebuffer
*fb
;
2320 unsigned long flags
;
2322 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2323 fb
= vino_queue_transfer(&vcs
->fb_queue
);
2325 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2326 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2329 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2331 fb
->frame_counter
= vcs
->int_data
.frame_counter
;
2332 memcpy(&fb
->timestamp
, &vcs
->int_data
.timestamp
,
2333 sizeof(struct timeval
));
2335 spin_lock_irqsave(&fb
->state_lock
, flags
);
2336 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
2337 fb
->state
= VINO_FRAMEBUFFER_READY
;
2338 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2340 wake_up(&vcs
->fb_queue
.frame_wait_queue
);
2342 vino_capture_next(vcs
, 0);
2345 static void vino_capture_tasklet(unsigned long channel
) {
2346 struct vino_channel_settings
*vcs
;
2348 vcs
= (channel
== VINO_CHANNEL_A
)
2349 ? &vino_drvdata
->a
: &vino_drvdata
->b
;
2351 if (vcs
->int_data
.skip
)
2352 vcs
->int_data
.skip_count
++;
2354 if (vcs
->int_data
.skip
&& (vcs
->int_data
.skip_count
2355 <= VINO_MAX_FRAME_SKIP_COUNT
)) {
2356 vino_skip_frame(vcs
);
2358 vcs
->int_data
.skip_count
= 0;
2359 vino_frame_done(vcs
);
2363 static irqreturn_t
vino_interrupt(int irq
, void *dev_id
)
2366 unsigned int fc_a
, fc_b
;
2367 int handled_a
= 0, skip_a
= 0, done_a
= 0;
2368 int handled_b
= 0, skip_b
= 0, done_b
= 0;
2370 #ifdef VINO_DEBUG_INT
2372 unsigned int line_count
= vino
->a
.line_count
,
2373 page_index
= vino
->a
.page_index
,
2374 field_counter
= vino
->a
.field_counter
,
2375 start_desc_tbl
= vino
->a
.start_desc_tbl
,
2376 next_4_desc
= vino
->a
.next_4_desc
;
2377 unsigned int line_count_2
,
2384 spin_lock(&vino_drvdata
->vino_lock
);
2386 while ((intr
= vino
->intr_status
)) {
2387 fc_a
= vino
->a
.field_counter
>> 1;
2388 fc_b
= vino
->b
.field_counter
>> 1;
2390 /* handle error-interrupts in some special way ?
2391 * --> skips frames */
2392 if (intr
& VINO_INTSTAT_A
) {
2393 if (intr
& VINO_INTSTAT_A_EOF
) {
2394 vino_drvdata
->a
.field
++;
2395 if (vino_drvdata
->a
.field
> 1) {
2396 vino_dma_stop(&vino_drvdata
->a
);
2397 vino_clear_interrupt(&vino_drvdata
->a
);
2398 vino_drvdata
->a
.field
= 0;
2401 if (vino
->a
.page_index
2402 != vino_drvdata
->a
.line_size
) {
2403 vino
->a
.line_count
= 0;
2404 vino
->a
.page_index
=
2407 vino
->a
.next_4_desc
=
2408 vino
->a
.start_desc_tbl
;
2411 dprintk("channel A end-of-field "
2412 "interrupt: %04x\n", intr
);
2414 vino_dma_stop(&vino_drvdata
->a
);
2415 vino_clear_interrupt(&vino_drvdata
->a
);
2416 vino_drvdata
->a
.field
= 0;
2418 dprintk("channel A error interrupt: %04x\n",
2422 #ifdef VINO_DEBUG_INT
2423 line_count_2
= vino
->a
.line_count
;
2424 page_index_2
= vino
->a
.page_index
;
2425 field_counter_2
= vino
->a
.field_counter
;
2426 start_desc_tbl_2
= vino
->a
.start_desc_tbl
;
2427 next_4_desc_2
= vino
->a
.next_4_desc
;
2429 printk("intr = %04x, loop = %d, field = %d\n",
2430 intr
, loop
, vino_drvdata
->a
.field
);
2431 printk("1- line count = %04d, page index = %04d, "
2432 "start = %08x, next = %08x\n"
2433 " fieldc = %d, framec = %d\n",
2434 line_count
, page_index
, start_desc_tbl
,
2435 next_4_desc
, field_counter
, fc_a
);
2436 printk("12-line count = %04d, page index = %04d, "
2437 " start = %08x, next = %08x\n",
2438 line_count_2
, page_index_2
, start_desc_tbl_2
,
2446 if (intr
& VINO_INTSTAT_B
) {
2447 if (intr
& VINO_INTSTAT_B_EOF
) {
2448 vino_drvdata
->b
.field
++;
2449 if (vino_drvdata
->b
.field
> 1) {
2450 vino_dma_stop(&vino_drvdata
->b
);
2451 vino_clear_interrupt(&vino_drvdata
->b
);
2452 vino_drvdata
->b
.field
= 0;
2455 dprintk("channel B end-of-field "
2456 "interrupt: %04x\n", intr
);
2458 vino_dma_stop(&vino_drvdata
->b
);
2459 vino_clear_interrupt(&vino_drvdata
->b
);
2460 vino_drvdata
->b
.field
= 0;
2462 dprintk("channel B error interrupt: %04x\n",
2467 /* Always remember to clear interrupt status.
2468 * Disable VINO interrupts while we do this. */
2469 ctrl
= vino
->control
;
2470 vino
->control
= ctrl
& ~(VINO_CTRL_A_INT
| VINO_CTRL_B_INT
);
2471 vino
->intr_status
= ~intr
;
2472 vino
->control
= ctrl
;
2474 spin_unlock(&vino_drvdata
->vino_lock
);
2476 if ((!handled_a
) && (done_a
|| skip_a
)) {
2478 do_gettimeofday(&vino_drvdata
->
2479 a
.int_data
.timestamp
);
2480 vino_drvdata
->a
.int_data
.frame_counter
= fc_a
;
2482 vino_drvdata
->a
.int_data
.skip
= skip_a
;
2484 dprintk("channel A %s, interrupt: %d\n",
2485 skip_a
? "skipping frame" : "frame done",
2487 tasklet_hi_schedule(&vino_tasklet_a
);
2491 if ((!handled_b
) && (done_b
|| skip_b
)) {
2493 do_gettimeofday(&vino_drvdata
->
2494 b
.int_data
.timestamp
);
2495 vino_drvdata
->b
.int_data
.frame_counter
= fc_b
;
2497 vino_drvdata
->b
.int_data
.skip
= skip_b
;
2499 dprintk("channel B %s, interrupt: %d\n",
2500 skip_b
? "skipping frame" : "frame done",
2502 tasklet_hi_schedule(&vino_tasklet_b
);
2506 #ifdef VINO_DEBUG_INT
2509 spin_lock(&vino_drvdata
->vino_lock
);
2512 spin_unlock(&vino_drvdata
->vino_lock
);
2517 /* VINO video input management */
2519 static int vino_get_saa7191_input(int input
)
2522 case VINO_INPUT_COMPOSITE
:
2523 return SAA7191_INPUT_COMPOSITE
;
2524 case VINO_INPUT_SVIDEO
:
2525 return SAA7191_INPUT_SVIDEO
;
2527 printk(KERN_ERR
"VINO: vino_get_saa7191_input(): "
2528 "invalid input!\n");
2533 /* execute with input_lock locked */
2534 static int vino_is_input_owner(struct vino_channel_settings
*vcs
)
2536 switch(vcs
->input
) {
2537 case VINO_INPUT_COMPOSITE
:
2538 case VINO_INPUT_SVIDEO
:
2539 return vino_drvdata
->decoder_owner
== vcs
->channel
;
2541 return vino_drvdata
->camera_owner
== vcs
->channel
;
2547 static int vino_acquire_input(struct vino_channel_settings
*vcs
)
2549 unsigned long flags
;
2552 dprintk("vino_acquire_input():\n");
2554 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2556 /* First try D1 and then SAA7191 */
2557 if (vino_drvdata
->camera
2558 && (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)) {
2559 vino_drvdata
->camera_owner
= vcs
->channel
;
2560 vcs
->input
= VINO_INPUT_D1
;
2561 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2562 } else if (vino_drvdata
->decoder
2563 && (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
)) {
2568 input
= VINO_INPUT_COMPOSITE
;
2570 ret
= decoder_call(video
, s_routing
,
2571 vino_get_saa7191_input(input
), 0, 0);
2577 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2579 /* Don't hold spinlocks while auto-detecting norm
2580 * as it may take a while... */
2582 ret
= decoder_call(video
, querystd
, &norm
);
2584 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2585 if (vino_data_norms
[data_norm
].std
& norm
)
2589 data_norm
= VINO_DATA_NORM_PAL
;
2590 ret
= decoder_call(core
, s_std
, norm
);
2593 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2600 vino_drvdata
->decoder_owner
= vcs
->channel
;
2603 vcs
->data_norm
= data_norm
;
2605 vcs
->input
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2606 vino_drvdata
->b
.input
: vino_drvdata
->a
.input
;
2607 vcs
->data_norm
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2608 vino_drvdata
->b
.data_norm
: vino_drvdata
->a
.data_norm
;
2611 if (vcs
->input
== VINO_INPUT_NONE
) {
2616 vino_set_default_clipping(vcs
);
2617 vino_set_default_scaling(vcs
);
2618 vino_set_default_framerate(vcs
);
2620 dprintk("vino_acquire_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2623 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2628 static int vino_set_input(struct vino_channel_settings
*vcs
, int input
)
2630 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2631 &vino_drvdata
->b
: &vino_drvdata
->a
;
2632 unsigned long flags
;
2635 dprintk("vino_set_input():\n");
2637 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2639 if (vcs
->input
== input
)
2643 case VINO_INPUT_COMPOSITE
:
2644 case VINO_INPUT_SVIDEO
:
2645 if (!vino_drvdata
->decoder
) {
2650 if (vino_drvdata
->decoder_owner
== VINO_NO_CHANNEL
) {
2651 vino_drvdata
->decoder_owner
= vcs
->channel
;
2654 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2658 ret
= decoder_call(video
, s_routing
,
2659 vino_get_saa7191_input(input
), 0, 0);
2661 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2666 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2668 /* Don't hold spinlocks while auto-detecting norm
2669 * as it may take a while... */
2671 ret
= decoder_call(video
, querystd
, &norm
);
2673 for (data_norm
= 0; data_norm
< 3; data_norm
++) {
2674 if (vino_data_norms
[data_norm
].std
& norm
)
2678 data_norm
= VINO_DATA_NORM_PAL
;
2679 ret
= decoder_call(core
, s_std
, norm
);
2682 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2685 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2691 vcs
->data_norm
= data_norm
;
2693 if (input
!= vcs2
->input
) {
2699 vcs
->data_norm
= vcs2
->data_norm
;
2702 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2703 /* Transfer the ownership or release the input */
2704 if (vcs2
->input
== VINO_INPUT_D1
) {
2705 vino_drvdata
->camera_owner
= vcs2
->channel
;
2707 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2712 if (!vino_drvdata
->camera
) {
2717 if (vino_drvdata
->camera_owner
== VINO_NO_CHANNEL
)
2718 vino_drvdata
->camera_owner
= vcs
->channel
;
2720 if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2721 /* Transfer the ownership or release the input */
2722 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2723 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2724 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2726 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2731 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2738 vino_set_default_clipping(vcs
);
2739 vino_set_default_scaling(vcs
);
2740 vino_set_default_framerate(vcs
);
2742 dprintk("vino_set_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2745 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2750 static void vino_release_input(struct vino_channel_settings
*vcs
)
2752 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2753 &vino_drvdata
->b
: &vino_drvdata
->a
;
2754 unsigned long flags
;
2756 dprintk("vino_release_input():\n");
2758 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2760 /* Release ownership of the channel
2761 * and if the other channel takes input from
2762 * the same source, transfer the ownership */
2763 if (vino_drvdata
->camera_owner
== vcs
->channel
) {
2764 if (vcs2
->input
== VINO_INPUT_D1
) {
2765 vino_drvdata
->camera_owner
= vcs2
->channel
;
2767 vino_drvdata
->camera_owner
= VINO_NO_CHANNEL
;
2769 } else if (vino_drvdata
->decoder_owner
== vcs
->channel
) {
2770 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2771 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2772 vino_drvdata
->decoder_owner
= vcs2
->channel
;
2774 vino_drvdata
->decoder_owner
= VINO_NO_CHANNEL
;
2777 vcs
->input
= VINO_INPUT_NONE
;
2779 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2782 /* execute with input_lock locked */
2783 static int vino_set_data_norm(struct vino_channel_settings
*vcs
,
2784 unsigned int data_norm
,
2785 unsigned long *flags
)
2789 if (data_norm
== vcs
->data_norm
)
2792 switch (vcs
->input
) {
2794 /* only one "norm" supported */
2795 if (data_norm
!= VINO_DATA_NORM_D1
)
2798 case VINO_INPUT_COMPOSITE
:
2799 case VINO_INPUT_SVIDEO
: {
2802 if ((data_norm
!= VINO_DATA_NORM_PAL
)
2803 && (data_norm
!= VINO_DATA_NORM_NTSC
)
2804 && (data_norm
!= VINO_DATA_NORM_SECAM
))
2807 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, *flags
);
2809 /* Don't hold spinlocks while setting norm
2810 * as it may take a while... */
2812 norm
= vino_data_norms
[data_norm
].std
;
2813 err
= decoder_call(core
, s_std
, norm
);
2815 spin_lock_irqsave(&vino_drvdata
->input_lock
, *flags
);
2820 vcs
->data_norm
= data_norm
;
2822 vino_set_default_clipping(vcs
);
2823 vino_set_default_scaling(vcs
);
2824 vino_set_default_framerate(vcs
);
2835 /* V4L2 helper functions */
2837 static int vino_find_data_format(__u32 pixelformat
)
2841 for (i
= 0; i
< VINO_DATA_FMT_COUNT
; i
++) {
2842 if (vino_data_formats
[i
].pixelformat
== pixelformat
)
2846 return VINO_DATA_FMT_NONE
;
2849 static int vino_int_enum_input(struct vino_channel_settings
*vcs
, __u32 index
)
2851 int input
= VINO_INPUT_NONE
;
2852 unsigned long flags
;
2854 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2855 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2858 input
= VINO_INPUT_COMPOSITE
;
2861 input
= VINO_INPUT_SVIDEO
;
2864 input
= VINO_INPUT_D1
;
2867 } else if (vino_drvdata
->decoder
) {
2870 input
= VINO_INPUT_COMPOSITE
;
2873 input
= VINO_INPUT_SVIDEO
;
2876 } else if (vino_drvdata
->camera
) {
2879 input
= VINO_INPUT_D1
;
2883 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2888 /* execute with input_lock locked */
2889 static __u32
vino_find_input_index(struct vino_channel_settings
*vcs
)
2892 // FIXME: detect when no inputs available
2894 if (vino_drvdata
->decoder
&& vino_drvdata
->camera
) {
2895 switch (vcs
->input
) {
2896 case VINO_INPUT_COMPOSITE
:
2899 case VINO_INPUT_SVIDEO
:
2906 } else if (vino_drvdata
->decoder
) {
2907 switch (vcs
->input
) {
2908 case VINO_INPUT_COMPOSITE
:
2911 case VINO_INPUT_SVIDEO
:
2915 } else if (vino_drvdata
->camera
) {
2916 switch (vcs
->input
) {
2928 static int vino_querycap(struct file
*file
, void *__fh
,
2929 struct v4l2_capability
*cap
)
2931 memset(cap
, 0, sizeof(struct v4l2_capability
));
2933 strcpy(cap
->driver
, vino_driver_name
);
2934 strcpy(cap
->card
, vino_driver_description
);
2935 strcpy(cap
->bus_info
, vino_bus_name
);
2936 cap
->version
= VINO_VERSION_CODE
;
2938 V4L2_CAP_VIDEO_CAPTURE
|
2940 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
2944 static int vino_enum_input(struct file
*file
, void *__fh
,
2945 struct v4l2_input
*i
)
2947 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2948 __u32 index
= i
->index
;
2950 dprintk("requested index = %d\n", index
);
2952 input
= vino_int_enum_input(vcs
, index
);
2953 if (input
== VINO_INPUT_NONE
)
2956 memset(i
, 0, sizeof(struct v4l2_input
));
2959 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
2960 i
->std
= vino_inputs
[input
].std
;
2961 strcpy(i
->name
, vino_inputs
[input
].name
);
2963 if (input
== VINO_INPUT_COMPOSITE
|| input
== VINO_INPUT_SVIDEO
)
2964 decoder_call(video
, g_input_status
, &i
->status
);
2968 static int vino_g_input(struct file
*file
, void *__fh
,
2971 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2974 unsigned long flags
;
2976 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2978 index
= vino_find_input_index(vcs
);
2979 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2981 dprintk("input = %d\n", input
);
2983 if (input
== VINO_INPUT_NONE
) {
2992 static int vino_s_input(struct file
*file
, void *__fh
,
2995 struct vino_channel_settings
*vcs
= video_drvdata(file
);
2997 dprintk("requested input = %d\n", i
);
2999 input
= vino_int_enum_input(vcs
, i
);
3000 if (input
== VINO_INPUT_NONE
)
3003 return vino_set_input(vcs
, input
);
3006 static int vino_querystd(struct file
*file
, void *__fh
,
3009 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3010 unsigned long flags
;
3013 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3015 switch (vcs
->input
) {
3017 *std
= vino_inputs
[vcs
->input
].std
;
3019 case VINO_INPUT_COMPOSITE
:
3020 case VINO_INPUT_SVIDEO
: {
3021 decoder_call(video
, querystd
, std
);
3028 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3033 static int vino_g_std(struct file
*file
, void *__fh
,
3036 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3037 unsigned long flags
;
3039 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3041 *std
= vino_data_norms
[vcs
->data_norm
].std
;
3042 dprintk("current standard = %d\n", vcs
->data_norm
);
3044 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3049 static int vino_s_std(struct file
*file
, void *__fh
,
3052 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3053 unsigned long flags
;
3056 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3058 if (!vino_is_input_owner(vcs
)) {
3063 /* check if the standard is valid for the current input */
3064 if ((*std
) & vino_inputs
[vcs
->input
].std
) {
3065 dprintk("standard accepted\n");
3067 /* change the video norm for SAA7191
3068 * and accept NTSC for D1 (do nothing) */
3070 if (vcs
->input
== VINO_INPUT_D1
)
3073 if ((*std
) & V4L2_STD_PAL
) {
3074 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_PAL
,
3076 } else if ((*std
) & V4L2_STD_NTSC
) {
3077 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_NTSC
,
3079 } else if ((*std
) & V4L2_STD_SECAM
) {
3080 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_SECAM
,
3094 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3099 static int vino_enum_fmt_vid_cap(struct file
*file
, void *__fh
,
3100 struct v4l2_fmtdesc
*fd
)
3102 dprintk("format index = %d\n", fd
->index
);
3104 if (fd
->index
>= VINO_DATA_FMT_COUNT
)
3106 dprintk("format name = %s\n", vino_data_formats
[fd
->index
].description
);
3108 fd
->pixelformat
= vino_data_formats
[fd
->index
].pixelformat
;
3109 strcpy(fd
->description
, vino_data_formats
[fd
->index
].description
);
3113 static int vino_try_fmt_vid_cap(struct file
*file
, void *__fh
,
3114 struct v4l2_format
*f
)
3116 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3117 struct vino_channel_settings tempvcs
;
3118 unsigned long flags
;
3119 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3121 dprintk("requested: w = %d, h = %d\n",
3122 pf
->width
, pf
->height
);
3124 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3125 memcpy(&tempvcs
, vcs
, sizeof(struct vino_channel_settings
));
3126 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3128 tempvcs
.data_format
= vino_find_data_format(pf
->pixelformat
);
3129 if (tempvcs
.data_format
== VINO_DATA_FMT_NONE
) {
3130 tempvcs
.data_format
= VINO_DATA_FMT_GREY
;
3132 vino_data_formats
[tempvcs
.data_format
].
3136 /* data format must be set before clipping/scaling */
3137 vino_set_scaling(&tempvcs
, pf
->width
, pf
->height
);
3139 dprintk("data format = %s\n",
3140 vino_data_formats
[tempvcs
.data_format
].description
);
3142 pf
->width
= (tempvcs
.clipping
.right
- tempvcs
.clipping
.left
) /
3144 pf
->height
= (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3147 pf
->field
= V4L2_FIELD_INTERLACED
;
3148 pf
->bytesperline
= tempvcs
.line_size
;
3149 pf
->sizeimage
= tempvcs
.line_size
*
3150 (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3153 vino_data_formats
[tempvcs
.data_format
].colorspace
;
3159 static int vino_g_fmt_vid_cap(struct file
*file
, void *__fh
,
3160 struct v4l2_format
*f
)
3162 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3163 unsigned long flags
;
3164 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3166 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3168 pf
->width
= (vcs
->clipping
.right
- vcs
->clipping
.left
) /
3170 pf
->height
= (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3173 vino_data_formats
[vcs
->data_format
].pixelformat
;
3175 pf
->field
= V4L2_FIELD_INTERLACED
;
3176 pf
->bytesperline
= vcs
->line_size
;
3177 pf
->sizeimage
= vcs
->line_size
*
3178 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3181 vino_data_formats
[vcs
->data_format
].colorspace
;
3185 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3189 static int vino_s_fmt_vid_cap(struct file
*file
, void *__fh
,
3190 struct v4l2_format
*f
)
3192 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3194 unsigned long flags
;
3195 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3197 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3199 data_format
= vino_find_data_format(pf
->pixelformat
);
3201 if (data_format
== VINO_DATA_FMT_NONE
) {
3202 vcs
->data_format
= VINO_DATA_FMT_GREY
;
3204 vino_data_formats
[vcs
->data_format
].
3207 vcs
->data_format
= data_format
;
3210 /* data format must be set before clipping/scaling */
3211 vino_set_scaling(vcs
, pf
->width
, pf
->height
);
3213 dprintk("data format = %s\n",
3214 vino_data_formats
[vcs
->data_format
].description
);
3216 pf
->width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3217 pf
->height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3219 pf
->field
= V4L2_FIELD_INTERLACED
;
3220 pf
->bytesperline
= vcs
->line_size
;
3221 pf
->sizeimage
= vcs
->line_size
*
3222 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3225 vino_data_formats
[vcs
->data_format
].colorspace
;
3229 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3233 static int vino_cropcap(struct file
*file
, void *__fh
,
3234 struct v4l2_cropcap
*ccap
)
3236 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3237 const struct vino_data_norm
*norm
;
3238 unsigned long flags
;
3240 switch (ccap
->type
) {
3241 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3242 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3244 norm
= &vino_data_norms
[vcs
->data_norm
];
3246 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3248 ccap
->bounds
.left
= 0;
3249 ccap
->bounds
.top
= 0;
3250 ccap
->bounds
.width
= norm
->width
;
3251 ccap
->bounds
.height
= norm
->height
;
3252 memcpy(&ccap
->defrect
, &ccap
->bounds
,
3253 sizeof(struct v4l2_rect
));
3255 ccap
->pixelaspect
.numerator
= 1;
3256 ccap
->pixelaspect
.denominator
= 1;
3258 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3266 static int vino_g_crop(struct file
*file
, void *__fh
,
3267 struct v4l2_crop
*c
)
3269 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3270 unsigned long flags
;
3273 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3274 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3276 c
->c
.left
= vcs
->clipping
.left
;
3277 c
->c
.top
= vcs
->clipping
.top
;
3278 c
->c
.width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3279 c
->c
.height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3281 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3283 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3291 static int vino_s_crop(struct file
*file
, void *__fh
,
3292 struct v4l2_crop
*c
)
3294 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3295 unsigned long flags
;
3298 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3299 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3301 vino_set_clipping(vcs
, c
->c
.left
, c
->c
.top
,
3302 c
->c
.width
, c
->c
.height
);
3304 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3306 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3314 static int vino_g_parm(struct file
*file
, void *__fh
,
3315 struct v4l2_streamparm
*sp
)
3317 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3318 unsigned long flags
;
3319 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3321 cp
->capability
= V4L2_CAP_TIMEPERFRAME
;
3322 cp
->timeperframe
.numerator
= 1;
3324 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3326 cp
->timeperframe
.denominator
= vcs
->fps
;
3328 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3330 /* TODO: cp->readbuffers = xxx; */
3335 static int vino_s_parm(struct file
*file
, void *__fh
,
3336 struct v4l2_streamparm
*sp
)
3338 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3339 unsigned long flags
;
3340 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3342 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3344 if ((cp
->timeperframe
.numerator
== 0) ||
3345 (cp
->timeperframe
.denominator
== 0)) {
3346 /* reset framerate */
3347 vino_set_default_framerate(vcs
);
3349 vino_set_framerate(vcs
, cp
->timeperframe
.denominator
/
3350 cp
->timeperframe
.numerator
);
3353 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3358 static int vino_reqbufs(struct file
*file
, void *__fh
,
3359 struct v4l2_requestbuffers
*rb
)
3361 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3366 /* TODO: check queue type */
3367 if (rb
->memory
!= V4L2_MEMORY_MMAP
) {
3368 dprintk("type not mmap\n");
3372 dprintk("count = %d\n", rb
->count
);
3373 if (rb
->count
> 0) {
3374 if (vino_is_capturing(vcs
)) {
3375 dprintk("busy, capturing\n");
3379 if (vino_queue_has_mapped_buffers(&vcs
->fb_queue
)) {
3380 dprintk("busy, buffers still mapped\n");
3384 vino_queue_free(&vcs
->fb_queue
);
3385 vino_queue_init(&vcs
->fb_queue
, &rb
->count
);
3389 vino_capture_stop(vcs
);
3390 vino_queue_free(&vcs
->fb_queue
);
3396 static void vino_v4l2_get_buffer_status(struct vino_channel_settings
*vcs
,
3397 struct vino_framebuffer
*fb
,
3398 struct v4l2_buffer
*b
)
3400 if (vino_queue_outgoing_contains(&vcs
->fb_queue
,
3402 b
->flags
&= ~V4L2_BUF_FLAG_QUEUED
;
3403 b
->flags
|= V4L2_BUF_FLAG_DONE
;
3404 } else if (vino_queue_incoming_contains(&vcs
->fb_queue
,
3406 b
->flags
&= ~V4L2_BUF_FLAG_DONE
;
3407 b
->flags
|= V4L2_BUF_FLAG_QUEUED
;
3409 b
->flags
&= ~(V4L2_BUF_FLAG_DONE
|
3410 V4L2_BUF_FLAG_QUEUED
);
3413 b
->flags
&= ~(V4L2_BUF_FLAG_TIMECODE
);
3415 if (fb
->map_count
> 0)
3416 b
->flags
|= V4L2_BUF_FLAG_MAPPED
;
3419 b
->memory
= (vcs
->fb_queue
.type
== VINO_MEMORY_MMAP
) ?
3420 V4L2_MEMORY_MMAP
: V4L2_MEMORY_USERPTR
;
3421 b
->m
.offset
= fb
->offset
;
3422 b
->bytesused
= fb
->data_size
;
3423 b
->length
= fb
->size
;
3424 b
->field
= V4L2_FIELD_INTERLACED
;
3425 b
->sequence
= fb
->frame_counter
;
3426 memcpy(&b
->timestamp
, &fb
->timestamp
,
3427 sizeof(struct timeval
));
3430 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3431 fb
->id
, fb
->size
, fb
->data_size
, fb
->offset
);
3434 static int vino_querybuf(struct file
*file
, void *__fh
,
3435 struct v4l2_buffer
*b
)
3437 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3438 struct vino_framebuffer
*fb
;
3443 /* TODO: check queue type */
3444 if (b
->index
>= vino_queue_get_length(&vcs
->fb_queue
)) {
3445 dprintk("invalid index = %d\n",
3450 fb
= vino_queue_get_buffer(&vcs
->fb_queue
,
3453 dprintk("vino_queue_get_buffer() failed");
3457 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3462 static int vino_qbuf(struct file
*file
, void *__fh
,
3463 struct v4l2_buffer
*b
)
3465 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3466 struct vino_framebuffer
*fb
;
3472 /* TODO: check queue type */
3473 if (b
->memory
!= V4L2_MEMORY_MMAP
) {
3474 dprintk("type not mmap\n");
3478 fb
= vino_capture_enqueue(vcs
, b
->index
);
3482 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3484 if (vcs
->streaming
) {
3485 ret
= vino_capture_next(vcs
, 1);
3493 static int vino_dqbuf(struct file
*file
, void *__fh
,
3494 struct v4l2_buffer
*b
)
3496 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3497 unsigned int nonblocking
= file
->f_flags
& O_NONBLOCK
;
3498 struct vino_framebuffer
*fb
;
3499 unsigned int incoming
, outgoing
;
3505 /* TODO: check queue type */
3507 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3509 dprintk("vino_queue_get_incoming() failed\n");
3512 err
= vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
);
3514 dprintk("vino_queue_get_outgoing() failed\n");
3518 dprintk("incoming = %d, outgoing = %d\n", incoming
, outgoing
);
3520 if (outgoing
== 0) {
3521 if (incoming
== 0) {
3522 dprintk("no incoming or outgoing buffers\n");
3526 dprintk("non-blocking I/O was selected and "
3527 "there are no buffers to dequeue\n");
3531 err
= vino_wait_for_frame(vcs
);
3533 err
= vino_wait_for_frame(vcs
);
3535 /* interrupted or no frames captured because of
3537 /* vino_capture_failed(vcs); */
3543 fb
= vino_queue_remove(&vcs
->fb_queue
, &b
->index
);
3545 dprintk("vino_queue_remove() failed\n");
3549 err
= vino_check_buffer(vcs
, fb
);
3551 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3559 static int vino_streamon(struct file
*file
, void *__fh
,
3560 enum v4l2_buf_type i
)
3562 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3563 unsigned int incoming
;
3571 // TODO: check queue type
3573 if (vino_queue_get_length(&vcs
->fb_queue
) < 1) {
3574 dprintk("no buffers allocated\n");
3578 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3580 dprintk("vino_queue_get_incoming() failed\n");
3587 ret
= vino_capture_next(vcs
, 1);
3591 dprintk("couldn't start capture\n");
3599 static int vino_streamoff(struct file
*file
, void *__fh
,
3600 enum v4l2_buf_type i
)
3602 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3606 if (!vcs
->streaming
)
3610 vino_capture_stop(vcs
);
3615 static int vino_queryctrl(struct file
*file
, void *__fh
,
3616 struct v4l2_queryctrl
*queryctrl
)
3618 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3619 unsigned long flags
;
3623 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3625 switch (vcs
->input
) {
3627 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3628 if (vino_indycam_v4l2_controls
[i
].id
==
3631 &vino_indycam_v4l2_controls
[i
],
3632 sizeof(struct v4l2_queryctrl
));
3633 queryctrl
->reserved
[0] = 0;
3640 case VINO_INPUT_COMPOSITE
:
3641 case VINO_INPUT_SVIDEO
:
3642 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3643 if (vino_saa7191_v4l2_controls
[i
].id
==
3646 &vino_saa7191_v4l2_controls
[i
],
3647 sizeof(struct v4l2_queryctrl
));
3648 queryctrl
->reserved
[0] = 0;
3660 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3665 static int vino_g_ctrl(struct file
*file
, void *__fh
,
3666 struct v4l2_control
*control
)
3668 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3669 unsigned long flags
;
3673 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3675 switch (vcs
->input
) {
3676 case VINO_INPUT_D1
: {
3678 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3679 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3688 err
= camera_call(core
, g_ctrl
, control
);
3693 case VINO_INPUT_COMPOSITE
:
3694 case VINO_INPUT_SVIDEO
: {
3696 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3697 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3706 err
= decoder_call(core
, g_ctrl
, control
);
3716 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3721 static int vino_s_ctrl(struct file
*file
, void *__fh
,
3722 struct v4l2_control
*control
)
3724 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3725 unsigned long flags
;
3729 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3731 if (!vino_is_input_owner(vcs
)) {
3736 switch (vcs
->input
) {
3737 case VINO_INPUT_D1
: {
3739 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3740 if (vino_indycam_v4l2_controls
[i
].id
== control
->id
) {
3747 if (control
->value
< vino_indycam_v4l2_controls
[i
].minimum
||
3748 control
->value
> vino_indycam_v4l2_controls
[i
].maximum
) {
3752 err
= camera_call(core
, s_ctrl
, control
);
3757 case VINO_INPUT_COMPOSITE
:
3758 case VINO_INPUT_SVIDEO
: {
3760 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3761 if (vino_saa7191_v4l2_controls
[i
].id
== control
->id
) {
3768 if (control
->value
< vino_saa7191_v4l2_controls
[i
].minimum
||
3769 control
->value
> vino_saa7191_v4l2_controls
[i
].maximum
) {
3774 err
= decoder_call(core
, s_ctrl
, control
);
3784 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3789 /* File operations */
3791 static int vino_open(struct file
*file
)
3793 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3795 dprintk("open(): channel = %c\n",
3796 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A' : 'B');
3798 mutex_lock(&vcs
->mutex
);
3801 dprintk("open(): driver busy\n");
3806 ret
= vino_acquire_input(vcs
);
3808 dprintk("open(): vino_acquire_input() failed\n");
3815 mutex_unlock(&vcs
->mutex
);
3817 dprintk("open(): %s!\n", ret
? "failed" : "complete");
3822 static int vino_close(struct file
*file
)
3824 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3825 dprintk("close():\n");
3827 mutex_lock(&vcs
->mutex
);
3832 vino_release_input(vcs
);
3834 /* stop DMA and free buffers */
3835 vino_capture_stop(vcs
);
3836 vino_queue_free(&vcs
->fb_queue
);
3839 mutex_unlock(&vcs
->mutex
);
3844 static void vino_vm_open(struct vm_area_struct
*vma
)
3846 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3849 dprintk("vino_vm_open(): count = %d\n", fb
->map_count
);
3852 static void vino_vm_close(struct vm_area_struct
*vma
)
3854 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
3857 dprintk("vino_vm_close(): count = %d\n", fb
->map_count
);
3860 static const struct vm_operations_struct vino_vm_ops
= {
3861 .open
= vino_vm_open
,
3862 .close
= vino_vm_close
,
3865 static int vino_mmap(struct file
*file
, struct vm_area_struct
*vma
)
3867 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3869 unsigned long start
= vma
->vm_start
;
3870 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
3871 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
3873 struct vino_framebuffer
*fb
= NULL
;
3874 unsigned int i
, length
;
3877 dprintk("mmap():\n");
3879 // TODO: reject mmap if already mapped
3881 if (mutex_lock_interruptible(&vcs
->mutex
))
3889 // TODO: check queue type
3891 if (!(vma
->vm_flags
& VM_WRITE
)) {
3892 dprintk("mmap(): app bug: PROT_WRITE please\n");
3896 if (!(vma
->vm_flags
& VM_SHARED
)) {
3897 dprintk("mmap(): app bug: MAP_SHARED please\n");
3902 /* find the correct buffer using offset */
3903 length
= vino_queue_get_length(&vcs
->fb_queue
);
3905 dprintk("mmap(): queue not initialized\n");
3910 for (i
= 0; i
< length
; i
++) {
3911 fb
= vino_queue_get_buffer(&vcs
->fb_queue
, i
);
3913 dprintk("mmap(): vino_queue_get_buffer() failed\n");
3918 if (fb
->offset
== offset
)
3922 dprintk("mmap(): invalid offset = %lu\n", offset
);
3927 dprintk("mmap(): buffer = %d\n", i
);
3929 if (size
> (fb
->desc_table
.page_count
* PAGE_SIZE
)) {
3930 dprintk("mmap(): failed: size = %lu > %lu\n",
3931 size
, fb
->desc_table
.page_count
* PAGE_SIZE
);
3936 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++) {
3938 virt_to_phys((void *)fb
->desc_table
.virtual[i
]) >>
3941 if (size
< PAGE_SIZE
)
3944 // protection was: PAGE_READONLY
3945 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
,
3946 vma
->vm_page_prot
)) {
3947 dprintk("mmap(): remap_pfn_range() failed\n");
3958 vma
->vm_flags
|= VM_DONTEXPAND
| VM_RESERVED
;
3959 vma
->vm_flags
&= ~VM_IO
;
3960 vma
->vm_private_data
= fb
;
3961 vma
->vm_file
= file
;
3962 vma
->vm_ops
= &vino_vm_ops
;
3965 mutex_unlock(&vcs
->mutex
);
3970 static unsigned int vino_poll(struct file
*file
, poll_table
*pt
)
3972 struct vino_channel_settings
*vcs
= video_drvdata(file
);
3973 unsigned int outgoing
;
3974 unsigned int ret
= 0;
3977 // TODO: this has to be corrected for different read modes
3979 dprintk("poll():\n");
3981 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3982 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3989 poll_wait(file
, &vcs
->fb_queue
.frame_wait_queue
, pt
);
3991 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
3992 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3998 dprintk("poll(): data %savailable\n",
3999 (outgoing
> 0) ? "" : "not ");
4002 ret
= POLLIN
| POLLRDNORM
;
4008 static long vino_ioctl(struct file
*file
,
4009 unsigned int cmd
, unsigned long arg
)
4011 struct vino_channel_settings
*vcs
= video_drvdata(file
);
4014 if (mutex_lock_interruptible(&vcs
->mutex
))
4017 ret
= video_ioctl2(file
, cmd
, arg
);
4019 mutex_unlock(&vcs
->mutex
);
4024 /* Initialization and cleanup */
4027 static int vino_init_stage
;
4029 const struct v4l2_ioctl_ops vino_ioctl_ops
= {
4030 .vidioc_enum_fmt_vid_cap
= vino_enum_fmt_vid_cap
,
4031 .vidioc_g_fmt_vid_cap
= vino_g_fmt_vid_cap
,
4032 .vidioc_s_fmt_vid_cap
= vino_s_fmt_vid_cap
,
4033 .vidioc_try_fmt_vid_cap
= vino_try_fmt_vid_cap
,
4034 .vidioc_querycap
= vino_querycap
,
4035 .vidioc_enum_input
= vino_enum_input
,
4036 .vidioc_g_input
= vino_g_input
,
4037 .vidioc_s_input
= vino_s_input
,
4038 .vidioc_g_std
= vino_g_std
,
4039 .vidioc_s_std
= vino_s_std
,
4040 .vidioc_querystd
= vino_querystd
,
4041 .vidioc_cropcap
= vino_cropcap
,
4042 .vidioc_s_crop
= vino_s_crop
,
4043 .vidioc_g_crop
= vino_g_crop
,
4044 .vidioc_s_parm
= vino_s_parm
,
4045 .vidioc_g_parm
= vino_g_parm
,
4046 .vidioc_reqbufs
= vino_reqbufs
,
4047 .vidioc_querybuf
= vino_querybuf
,
4048 .vidioc_qbuf
= vino_qbuf
,
4049 .vidioc_dqbuf
= vino_dqbuf
,
4050 .vidioc_streamon
= vino_streamon
,
4051 .vidioc_streamoff
= vino_streamoff
,
4052 .vidioc_queryctrl
= vino_queryctrl
,
4053 .vidioc_g_ctrl
= vino_g_ctrl
,
4054 .vidioc_s_ctrl
= vino_s_ctrl
,
4057 static const struct v4l2_file_operations vino_fops
= {
4058 .owner
= THIS_MODULE
,
4060 .release
= vino_close
,
4061 .unlocked_ioctl
= vino_ioctl
,
4066 static struct video_device vdev_template
= {
4069 .ioctl_ops
= &vino_ioctl_ops
,
4070 .tvnorms
= V4L2_STD_NTSC
| V4L2_STD_PAL
| V4L2_STD_SECAM
,
4073 static void vino_module_cleanup(int stage
)
4077 video_unregister_device(vino_drvdata
->b
.vdev
);
4078 vino_drvdata
->b
.vdev
= NULL
;
4080 video_unregister_device(vino_drvdata
->a
.vdev
);
4081 vino_drvdata
->a
.vdev
= NULL
;
4083 i2c_del_adapter(&vino_i2c_adapter
);
4085 free_irq(SGI_VINO_IRQ
, NULL
);
4087 if (vino_drvdata
->b
.vdev
) {
4088 video_device_release(vino_drvdata
->b
.vdev
);
4089 vino_drvdata
->b
.vdev
= NULL
;
4092 if (vino_drvdata
->a
.vdev
) {
4093 video_device_release(vino_drvdata
->a
.vdev
);
4094 vino_drvdata
->a
.vdev
= NULL
;
4097 /* all entries in dma_cpu dummy table have the same address */
4098 dma_unmap_single(NULL
,
4099 vino_drvdata
->dummy_desc_table
.dma_cpu
[0],
4100 PAGE_SIZE
, DMA_FROM_DEVICE
);
4101 dma_free_coherent(NULL
, VINO_DUMMY_DESC_COUNT
4102 * sizeof(dma_addr_t
),
4103 (void *)vino_drvdata
->
4104 dummy_desc_table
.dma_cpu
,
4105 vino_drvdata
->dummy_desc_table
.dma
);
4107 free_page(vino_drvdata
->dummy_page
);
4109 v4l2_device_unregister(&vino_drvdata
->v4l2_dev
);
4111 kfree(vino_drvdata
);
4117 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4122 static int vino_probe(void)
4124 unsigned long rev_id
;
4126 if (ip22_is_fullhouse()) {
4127 printk(KERN_ERR
"VINO doesn't exist in IP22 Fullhouse\n");
4131 if (!(sgimc
->systemid
& SGIMC_SYSID_EPRESENT
)) {
4132 printk(KERN_ERR
"VINO is not found (EISA BUS not present)\n");
4136 vino
= (struct sgi_vino
*)ioremap(VINO_BASE
, sizeof(struct sgi_vino
));
4138 printk(KERN_ERR
"VINO: ioremap() failed\n");
4143 if (get_dbe(rev_id
, &(vino
->rev_id
))) {
4144 printk(KERN_ERR
"Failed to read VINO revision register\n");
4145 vino_module_cleanup(vino_init_stage
);
4149 if (VINO_ID_VALUE(rev_id
) != VINO_CHIP_ID
) {
4150 printk(KERN_ERR
"Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4152 vino_module_cleanup(vino_init_stage
);
4156 printk(KERN_INFO
"VINO revision %ld found\n", VINO_REV_NUM(rev_id
));
4161 static int vino_init(void)
4163 dma_addr_t dma_dummy_address
;
4167 vino_drvdata
= kzalloc(sizeof(struct vino_settings
), GFP_KERNEL
);
4168 if (!vino_drvdata
) {
4169 vino_module_cleanup(vino_init_stage
);
4173 strlcpy(vino_drvdata
->v4l2_dev
.name
, "vino",
4174 sizeof(vino_drvdata
->v4l2_dev
.name
));
4175 err
= v4l2_device_register(NULL
, &vino_drvdata
->v4l2_dev
);
4180 /* create a dummy dma descriptor */
4181 vino_drvdata
->dummy_page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
4182 if (!vino_drvdata
->dummy_page
) {
4183 vino_module_cleanup(vino_init_stage
);
4188 // TODO: use page_count in dummy_desc_table
4190 vino_drvdata
->dummy_desc_table
.dma_cpu
=
4191 dma_alloc_coherent(NULL
,
4192 VINO_DUMMY_DESC_COUNT
* sizeof(dma_addr_t
),
4193 &vino_drvdata
->dummy_desc_table
.dma
,
4194 GFP_KERNEL
| GFP_DMA
);
4195 if (!vino_drvdata
->dummy_desc_table
.dma_cpu
) {
4196 vino_module_cleanup(vino_init_stage
);
4201 dma_dummy_address
= dma_map_single(NULL
,
4202 (void *)vino_drvdata
->dummy_page
,
4203 PAGE_SIZE
, DMA_FROM_DEVICE
);
4204 for (i
= 0; i
< VINO_DUMMY_DESC_COUNT
; i
++) {
4205 vino_drvdata
->dummy_desc_table
.dma_cpu
[i
] = dma_dummy_address
;
4208 /* initialize VINO */
4211 vino
->a
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4212 vino
->b
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4213 udelay(VINO_DESC_FETCH_DELAY
);
4215 vino
->intr_status
= 0;
4217 vino
->a
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4218 vino
->b
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4223 static int vino_init_channel_settings(struct vino_channel_settings
*vcs
,
4224 unsigned int channel
, const char *name
)
4226 vcs
->channel
= channel
;
4227 vcs
->input
= VINO_INPUT_NONE
;
4230 vcs
->data_format
= VINO_DATA_FMT_GREY
;
4231 vcs
->data_norm
= VINO_DATA_NORM_NTSC
;
4232 vcs
->decimation
= 1;
4233 vino_set_default_clipping(vcs
);
4234 vino_set_default_framerate(vcs
);
4238 mutex_init(&vcs
->mutex
);
4239 spin_lock_init(&vcs
->capture_lock
);
4241 mutex_init(&vcs
->fb_queue
.queue_mutex
);
4242 spin_lock_init(&vcs
->fb_queue
.queue_lock
);
4243 init_waitqueue_head(&vcs
->fb_queue
.frame_wait_queue
);
4245 vcs
->vdev
= video_device_alloc();
4247 vino_module_cleanup(vino_init_stage
);
4252 memcpy(vcs
->vdev
, &vdev_template
,
4253 sizeof(struct video_device
));
4254 strcpy(vcs
->vdev
->name
, name
);
4255 vcs
->vdev
->release
= video_device_release
;
4256 vcs
->vdev
->v4l2_dev
= &vino_drvdata
->v4l2_dev
;
4258 video_set_drvdata(vcs
->vdev
, vcs
);
4263 static int __init
vino_module_init(void)
4267 printk(KERN_INFO
"SGI VINO driver version %s\n",
4268 VINO_MODULE_VERSION
);
4278 /* initialize data structures */
4280 spin_lock_init(&vino_drvdata
->vino_lock
);
4281 spin_lock_init(&vino_drvdata
->input_lock
);
4283 ret
= vino_init_channel_settings(&vino_drvdata
->a
, VINO_CHANNEL_A
,
4288 ret
= vino_init_channel_settings(&vino_drvdata
->b
, VINO_CHANNEL_B
,
4293 /* initialize hardware and register V4L devices */
4295 ret
= request_irq(SGI_VINO_IRQ
, vino_interrupt
, 0,
4296 vino_driver_description
, NULL
);
4298 printk(KERN_ERR
"VINO: requesting IRQ %02d failed\n",
4300 vino_module_cleanup(vino_init_stage
);
4305 ret
= i2c_add_adapter(&vino_i2c_adapter
);
4307 printk(KERN_ERR
"VINO I2C bus registration failed\n");
4308 vino_module_cleanup(vino_init_stage
);
4311 i2c_set_adapdata(&vino_i2c_adapter
, &vino_drvdata
->v4l2_dev
);
4314 ret
= video_register_device(vino_drvdata
->a
.vdev
,
4315 VFL_TYPE_GRABBER
, -1);
4317 printk(KERN_ERR
"VINO channel A Video4Linux-device "
4318 "registration failed\n");
4319 vino_module_cleanup(vino_init_stage
);
4324 ret
= video_register_device(vino_drvdata
->b
.vdev
,
4325 VFL_TYPE_GRABBER
, -1);
4327 printk(KERN_ERR
"VINO channel B Video4Linux-device "
4328 "registration failed\n");
4329 vino_module_cleanup(vino_init_stage
);
4334 vino_drvdata
->decoder
=
4335 v4l2_i2c_new_subdev(&vino_drvdata
->v4l2_dev
, &vino_i2c_adapter
,
4336 "saa7191", "saa7191", 0, I2C_ADDRS(0x45));
4337 vino_drvdata
->camera
=
4338 v4l2_i2c_new_subdev(&vino_drvdata
->v4l2_dev
, &vino_i2c_adapter
,
4339 "indycam", "indycam", 0, I2C_ADDRS(0x2b));
4341 dprintk("init complete!\n");
4346 static void __exit
vino_module_exit(void)
4348 dprintk("exiting, stage = %d ...\n", vino_init_stage
);
4349 vino_module_cleanup(vino_init_stage
);
4350 dprintk("cleanup complete, exit!\n");
4353 module_init(vino_module_init
);
4354 module_exit(vino_module_exit
);