2 * Driver for the VINO (Video In No Out) system found in SGI Indys.
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License version 2 as published by the Free Software Foundation.
7 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
9 * Based on the previous version of the driver for 2.4 kernels by:
10 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
15 * - remove "mark pages reserved-hacks" from memory allocation code
16 * and implement fault()
17 * - check decimation, calculating and reporting image size when
19 * - implement read(), user mode buffers and overlay (?)
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/delay.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/errno.h>
28 #include <linux/interrupt.h>
29 #include <linux/kernel.h>
31 #include <linux/time.h>
32 #include <linux/version.h>
33 #include <linux/kmod.h>
35 #include <linux/i2c.h>
36 #include <linux/i2c-algo-sgi.h>
38 #include <linux/videodev2.h>
39 #include <media/v4l2-common.h>
40 #include <media/v4l2-ioctl.h>
41 #include <linux/video_decoder.h>
42 #include <linux/mutex.h>
44 #include <asm/paccess.h>
46 #include <asm/sgi/ip22.h>
47 #include <asm/sgi/mc.h>
53 /* Uncomment the following line to get lots and lots of (mostly useless)
55 * Note that the debug output also slows down the driver significantly */
57 // #define VINO_DEBUG_INT
59 #define VINO_MODULE_VERSION "0.0.5"
60 #define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 5)
62 MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
63 MODULE_VERSION(VINO_MODULE_VERSION);
64 MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
65 MODULE_LICENSE("GPL");
68 #define dprintk(x...) printk("VINO: " x);
73 #define VINO_NO_CHANNEL 0
74 #define VINO_CHANNEL_A 1
75 #define VINO_CHANNEL_B 2
77 #define VINO_PAL_WIDTH 768
78 #define VINO_PAL_HEIGHT 576
79 #define VINO_NTSC_WIDTH 640
80 #define VINO_NTSC_HEIGHT 480
82 #define VINO_MIN_WIDTH 32
83 #define VINO_MIN_HEIGHT 32
85 #define VINO_CLIPPING_START_ODD_D1 1
86 #define VINO_CLIPPING_START_ODD_PAL 15
87 #define VINO_CLIPPING_START_ODD_NTSC 12
89 #define VINO_CLIPPING_START_EVEN_D1 2
90 #define VINO_CLIPPING_START_EVEN_PAL 15
91 #define VINO_CLIPPING_START_EVEN_NTSC 12
93 #define VINO_INPUT_CHANNEL_COUNT 3
95 /* the number is the index for vino_inputs */
96 #define VINO_INPUT_NONE -1
97 #define VINO_INPUT_COMPOSITE 0
98 #define VINO_INPUT_SVIDEO 1
99 #define VINO_INPUT_D1 2
101 #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
103 #define VINO_FIFO_THRESHOLD_DEFAULT 16
105 #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
106 * VINO_PAL_HEIGHT * 4 \
107 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
109 #define VINO_FRAMEBUFFER_COUNT_MAX 8
111 #define VINO_FRAMEBUFFER_UNUSED 0
112 #define VINO_FRAMEBUFFER_IN_USE 1
113 #define VINO_FRAMEBUFFER_READY 2
115 #define VINO_QUEUE_ERROR -1
116 #define VINO_QUEUE_MAGIC 0x20050125
118 #define VINO_MEMORY_NONE 0
119 #define VINO_MEMORY_MMAP 1
120 #define VINO_MEMORY_USERPTR 2
122 #define VINO_DUMMY_DESC_COUNT 4
123 #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
125 #define VINO_MAX_FRAME_SKIP_COUNT 128
127 /* the number is the index for vino_data_formats */
128 #define VINO_DATA_FMT_NONE -1
129 #define VINO_DATA_FMT_GREY 0
130 #define VINO_DATA_FMT_RGB332 1
131 #define VINO_DATA_FMT_RGB32 2
132 #define VINO_DATA_FMT_YUV 3
134 #define VINO_DATA_FMT_COUNT 4
136 /* the number is the index for vino_data_norms */
137 #define VINO_DATA_NORM_NONE -1
138 #define VINO_DATA_NORM_NTSC 0
139 #define VINO_DATA_NORM_PAL 1
140 #define VINO_DATA_NORM_SECAM 2
141 #define VINO_DATA_NORM_D1 3
142 /* The following are special entries that can be used to
143 * autodetect the norm. */
144 #define VINO_DATA_NORM_AUTO 0xfe
145 #define VINO_DATA_NORM_AUTO_EXT 0xff
147 #define VINO_DATA_NORM_COUNT 4
149 /* Internal data structure definitions */
156 struct vino_clipping {
157 unsigned int left, right, top, bottom;
160 struct vino_data_format {
161 /* the description */
163 /* bytes per pixel */
165 /* V4L2 fourcc code */
167 /* V4L2 colorspace (duh!) */
168 enum v4l2_colorspace colorspace;
171 struct vino_data_norm {
173 unsigned int width, height;
174 struct vino_clipping odd;
175 struct vino_clipping even;
178 unsigned int fps_min, fps_max;
182 struct vino_descriptor_table {
183 /* the number of PAGE_SIZE sized pages in the buffer */
184 unsigned int page_count;
185 /* virtual (kmalloc'd) pointers to the actual data
186 * (in PAGE_SIZE chunks, used with mmap streaming) */
187 unsigned long *virtual;
189 /* cpu address for the VINO descriptor table
190 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
191 unsigned long *dma_cpu;
192 /* dma address for the VINO descriptor table
193 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
197 struct vino_framebuffer {
198 /* identifier nubmer */
200 /* the length of the whole buffer */
202 /* the length of actual data in buffer */
203 unsigned int data_size;
204 /* the data format */
205 unsigned int data_format;
206 /* the state of buffer data */
208 /* is the buffer mapped in user space? */
209 unsigned int map_count;
210 /* memory offset for mmap() */
213 unsigned int frame_counter;
214 /* timestamp (written when image capture finishes) */
215 struct timeval timestamp;
217 struct vino_descriptor_table desc_table;
219 spinlock_t state_lock;
222 struct vino_framebuffer_fifo {
229 unsigned int data[VINO_FRAMEBUFFER_COUNT_MAX];
232 struct vino_framebuffer_queue {
235 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
239 /* data field of in and out contain index numbers for buffer */
240 struct vino_framebuffer_fifo in;
241 struct vino_framebuffer_fifo out;
243 struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_COUNT_MAX];
245 spinlock_t queue_lock;
246 struct mutex queue_mutex;
247 wait_queue_head_t frame_wait_queue;
250 struct vino_interrupt_data {
251 struct timeval timestamp;
252 unsigned int frame_counter;
253 unsigned int skip_count;
257 struct vino_channel_settings {
258 unsigned int channel;
261 unsigned int data_format;
262 unsigned int data_norm;
263 struct vino_clipping clipping;
264 unsigned int decimation;
265 unsigned int line_size;
268 unsigned int framert_reg;
270 unsigned int fifo_threshold;
272 struct vino_framebuffer_queue fb_queue;
274 /* number of the current field */
277 /* read in progress */
279 /* streaming is active */
281 /* the driver is currently processing the queue */
285 spinlock_t capture_lock;
289 struct vino_interrupt_data int_data;
292 struct video_device *v4l_device;
296 /* the channel which owns this client:
297 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
299 struct i2c_client *driver;
302 struct vino_settings {
303 struct vino_channel_settings a;
304 struct vino_channel_settings b;
306 struct vino_client decoder;
307 struct vino_client camera;
309 /* a lock for vino register access */
310 spinlock_t vino_lock;
311 /* a lock for channel input changes */
312 spinlock_t input_lock;
314 unsigned long dummy_page;
315 struct vino_descriptor_table dummy_desc_table;
318 /* Module parameters */
321 * Using vino_pixel_conversion the ABGR32-format pixels supplied
322 * by the VINO chip can be converted to more common formats
323 * like RGBA32 (or probably RGB24 in the future). This way we
324 * can give out data that can be specified correctly with
325 * the V4L2-definitions.
327 * The pixel format is specified as RGBA32 when no conversion
330 * Note that this only affects the 32-bit bit depth.
332 * Use non-zero value to enable conversion.
334 static int vino_pixel_conversion;
336 module_param_named(pixelconv, vino_pixel_conversion, int, 0);
338 MODULE_PARM_DESC(pixelconv,
339 "enable pixel conversion (non-zero value enables)");
341 /* Internal data structures */
343 static struct sgi_vino *vino;
345 static struct vino_settings *vino_drvdata;
347 static const char *vino_driver_name = "vino";
348 static const char *vino_driver_description = "SGI VINO";
349 static const char *vino_bus_name = "GIO64 bus";
350 static const char *vino_v4l_device_name_a = "SGI VINO Channel A";
351 static const char *vino_v4l_device_name_b = "SGI VINO Channel B";
353 static void vino_capture_tasklet(unsigned long channel);
355 DECLARE_TASKLET(vino_tasklet_a, vino_capture_tasklet, VINO_CHANNEL_A);
356 DECLARE_TASKLET(vino_tasklet_b, vino_capture_tasklet, VINO_CHANNEL_B);
358 static const struct vino_input vino_inputs[] = {
361 .std = V4L2_STD_NTSC | V4L2_STD_PAL
365 .std = V4L2_STD_NTSC | V4L2_STD_PAL
368 .name = "D1/IndyCam",
369 .std = V4L2_STD_NTSC,
373 static const struct vino_data_format vino_data_formats[] = {
375 .description = "8-bit greyscale",
377 .pixelformat = V4L2_PIX_FMT_GREY,
378 .colorspace = V4L2_COLORSPACE_SMPTE170M,
380 .description = "8-bit dithered RGB 3-3-2",
382 .pixelformat = V4L2_PIX_FMT_RGB332,
383 .colorspace = V4L2_COLORSPACE_SRGB,
385 .description = "32-bit RGB",
387 .pixelformat = V4L2_PIX_FMT_RGB32,
388 .colorspace = V4L2_COLORSPACE_SRGB,
390 .description = "YUV 4:2:2",
392 .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped?
393 .colorspace = V4L2_COLORSPACE_SMPTE170M,
397 static const struct vino_data_norm vino_data_norms[] = {
399 .description = "NTSC",
400 .std = V4L2_STD_NTSC,
404 .width = VINO_NTSC_WIDTH,
405 .height = VINO_NTSC_HEIGHT,
407 .top = VINO_CLIPPING_START_ODD_NTSC,
409 .bottom = VINO_CLIPPING_START_ODD_NTSC
410 + VINO_NTSC_HEIGHT / 2 - 1,
411 .right = VINO_NTSC_WIDTH,
414 .top = VINO_CLIPPING_START_EVEN_NTSC,
416 .bottom = VINO_CLIPPING_START_EVEN_NTSC
417 + VINO_NTSC_HEIGHT / 2 - 1,
418 .right = VINO_NTSC_WIDTH,
421 .description = "PAL",
426 .width = VINO_PAL_WIDTH,
427 .height = VINO_PAL_HEIGHT,
429 .top = VINO_CLIPPING_START_ODD_PAL,
431 .bottom = VINO_CLIPPING_START_ODD_PAL
432 + VINO_PAL_HEIGHT / 2 - 1,
433 .right = VINO_PAL_WIDTH,
436 .top = VINO_CLIPPING_START_EVEN_PAL,
438 .bottom = VINO_CLIPPING_START_EVEN_PAL
439 + VINO_PAL_HEIGHT / 2 - 1,
440 .right = VINO_PAL_WIDTH,
443 .description = "SECAM",
444 .std = V4L2_STD_SECAM,
448 .width = VINO_PAL_WIDTH,
449 .height = VINO_PAL_HEIGHT,
451 .top = VINO_CLIPPING_START_ODD_PAL,
453 .bottom = VINO_CLIPPING_START_ODD_PAL
454 + VINO_PAL_HEIGHT / 2 - 1,
455 .right = VINO_PAL_WIDTH,
458 .top = VINO_CLIPPING_START_EVEN_PAL,
460 .bottom = VINO_CLIPPING_START_EVEN_PAL
461 + VINO_PAL_HEIGHT / 2 - 1,
462 .right = VINO_PAL_WIDTH,
465 .description = "NTSC/D1",
466 .std = V4L2_STD_NTSC,
470 .width = VINO_NTSC_WIDTH,
471 .height = VINO_NTSC_HEIGHT,
473 .top = VINO_CLIPPING_START_ODD_D1,
475 .bottom = VINO_CLIPPING_START_ODD_D1
476 + VINO_NTSC_HEIGHT / 2 - 1,
477 .right = VINO_NTSC_WIDTH,
480 .top = VINO_CLIPPING_START_EVEN_D1,
482 .bottom = VINO_CLIPPING_START_EVEN_D1
483 + VINO_NTSC_HEIGHT / 2 - 1,
484 .right = VINO_NTSC_WIDTH,
489 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
491 struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
493 .id = V4L2_CID_AUTOGAIN,
494 .type = V4L2_CTRL_TYPE_BOOLEAN,
495 .name = "Automatic Gain Control",
499 .default_value = INDYCAM_AGC_DEFAULT,
501 .reserved = { INDYCAM_CONTROL_AGC, 0 },
503 .id = V4L2_CID_AUTO_WHITE_BALANCE,
504 .type = V4L2_CTRL_TYPE_BOOLEAN,
505 .name = "Automatic White Balance",
509 .default_value = INDYCAM_AWB_DEFAULT,
511 .reserved = { INDYCAM_CONTROL_AWB, 0 },
514 .type = V4L2_CTRL_TYPE_INTEGER,
516 .minimum = INDYCAM_GAIN_MIN,
517 .maximum = INDYCAM_GAIN_MAX,
519 .default_value = INDYCAM_GAIN_DEFAULT,
521 .reserved = { INDYCAM_CONTROL_GAIN, 0 },
523 .id = V4L2_CID_PRIVATE_BASE,
524 .type = V4L2_CTRL_TYPE_INTEGER,
525 .name = "Red Saturation",
526 .minimum = INDYCAM_RED_SATURATION_MIN,
527 .maximum = INDYCAM_RED_SATURATION_MAX,
529 .default_value = INDYCAM_RED_SATURATION_DEFAULT,
531 .reserved = { INDYCAM_CONTROL_RED_SATURATION, 0 },
533 .id = V4L2_CID_PRIVATE_BASE + 1,
534 .type = V4L2_CTRL_TYPE_INTEGER,
535 .name = "Blue Saturation",
536 .minimum = INDYCAM_BLUE_SATURATION_MIN,
537 .maximum = INDYCAM_BLUE_SATURATION_MAX,
539 .default_value = INDYCAM_BLUE_SATURATION_DEFAULT,
541 .reserved = { INDYCAM_CONTROL_BLUE_SATURATION, 0 },
543 .id = V4L2_CID_RED_BALANCE,
544 .type = V4L2_CTRL_TYPE_INTEGER,
545 .name = "Red Balance",
546 .minimum = INDYCAM_RED_BALANCE_MIN,
547 .maximum = INDYCAM_RED_BALANCE_MAX,
549 .default_value = INDYCAM_RED_BALANCE_DEFAULT,
551 .reserved = { INDYCAM_CONTROL_RED_BALANCE, 0 },
553 .id = V4L2_CID_BLUE_BALANCE,
554 .type = V4L2_CTRL_TYPE_INTEGER,
555 .name = "Blue Balance",
556 .minimum = INDYCAM_BLUE_BALANCE_MIN,
557 .maximum = INDYCAM_BLUE_BALANCE_MAX,
559 .default_value = INDYCAM_BLUE_BALANCE_DEFAULT,
561 .reserved = { INDYCAM_CONTROL_BLUE_BALANCE, 0 },
563 .id = V4L2_CID_EXPOSURE,
564 .type = V4L2_CTRL_TYPE_INTEGER,
565 .name = "Shutter Control",
566 .minimum = INDYCAM_SHUTTER_MIN,
567 .maximum = INDYCAM_SHUTTER_MAX,
569 .default_value = INDYCAM_SHUTTER_DEFAULT,
571 .reserved = { INDYCAM_CONTROL_SHUTTER, 0 },
573 .id = V4L2_CID_GAMMA,
574 .type = V4L2_CTRL_TYPE_INTEGER,
576 .minimum = INDYCAM_GAMMA_MIN,
577 .maximum = INDYCAM_GAMMA_MAX,
579 .default_value = INDYCAM_GAMMA_DEFAULT,
581 .reserved = { INDYCAM_CONTROL_GAMMA, 0 },
585 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
587 struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
590 .type = V4L2_CTRL_TYPE_INTEGER,
592 .minimum = SAA7191_HUE_MIN,
593 .maximum = SAA7191_HUE_MAX,
595 .default_value = SAA7191_HUE_DEFAULT,
597 .reserved = { SAA7191_CONTROL_HUE, 0 },
599 .id = V4L2_CID_PRIVATE_BASE,
600 .type = V4L2_CTRL_TYPE_INTEGER,
601 .name = "Luminance Bandpass",
602 .minimum = SAA7191_BANDPASS_MIN,
603 .maximum = SAA7191_BANDPASS_MAX,
605 .default_value = SAA7191_BANDPASS_DEFAULT,
607 .reserved = { SAA7191_CONTROL_BANDPASS, 0 },
609 .id = V4L2_CID_PRIVATE_BASE + 1,
610 .type = V4L2_CTRL_TYPE_INTEGER,
611 .name = "Luminance Bandpass Weight",
612 .minimum = SAA7191_BANDPASS_WEIGHT_MIN,
613 .maximum = SAA7191_BANDPASS_WEIGHT_MAX,
615 .default_value = SAA7191_BANDPASS_WEIGHT_DEFAULT,
617 .reserved = { SAA7191_CONTROL_BANDPASS_WEIGHT, 0 },
619 .id = V4L2_CID_PRIVATE_BASE + 2,
620 .type = V4L2_CTRL_TYPE_INTEGER,
621 .name = "HF Luminance Coring",
622 .minimum = SAA7191_CORING_MIN,
623 .maximum = SAA7191_CORING_MAX,
625 .default_value = SAA7191_CORING_DEFAULT,
627 .reserved = { SAA7191_CONTROL_CORING, 0 },
629 .id = V4L2_CID_PRIVATE_BASE + 3,
630 .type = V4L2_CTRL_TYPE_BOOLEAN,
631 .name = "Force Colour",
632 .minimum = SAA7191_FORCE_COLOUR_MIN,
633 .maximum = SAA7191_FORCE_COLOUR_MAX,
635 .default_value = SAA7191_FORCE_COLOUR_DEFAULT,
637 .reserved = { SAA7191_CONTROL_FORCE_COLOUR, 0 },
639 .id = V4L2_CID_PRIVATE_BASE + 4,
640 .type = V4L2_CTRL_TYPE_INTEGER,
641 .name = "Chrominance Gain Control",
642 .minimum = SAA7191_CHROMA_GAIN_MIN,
643 .maximum = SAA7191_CHROMA_GAIN_MAX,
645 .default_value = SAA7191_CHROMA_GAIN_DEFAULT,
647 .reserved = { SAA7191_CONTROL_CHROMA_GAIN, 0 },
649 .id = V4L2_CID_PRIVATE_BASE + 5,
650 .type = V4L2_CTRL_TYPE_BOOLEAN,
651 .name = "VTR Time Constant",
652 .minimum = SAA7191_VTRC_MIN,
653 .maximum = SAA7191_VTRC_MAX,
655 .default_value = SAA7191_VTRC_DEFAULT,
657 .reserved = { SAA7191_CONTROL_VTRC, 0 },
659 .id = V4L2_CID_PRIVATE_BASE + 6,
660 .type = V4L2_CTRL_TYPE_INTEGER,
661 .name = "Luminance Delay Compensation",
662 .minimum = SAA7191_LUMA_DELAY_MIN,
663 .maximum = SAA7191_LUMA_DELAY_MAX,
665 .default_value = SAA7191_LUMA_DELAY_DEFAULT,
667 .reserved = { SAA7191_CONTROL_LUMA_DELAY, 0 },
669 .id = V4L2_CID_PRIVATE_BASE + 7,
670 .type = V4L2_CTRL_TYPE_INTEGER,
671 .name = "Vertical Noise Reduction",
672 .minimum = SAA7191_VNR_MIN,
673 .maximum = SAA7191_VNR_MAX,
675 .default_value = SAA7191_VNR_DEFAULT,
677 .reserved = { SAA7191_CONTROL_VNR, 0 },
681 /* VINO I2C bus functions */
683 unsigned i2c_vino_getctrl(void *data)
685 return vino->i2c_control;
688 void i2c_vino_setctrl(void *data, unsigned val)
690 vino->i2c_control = val;
693 unsigned i2c_vino_rdata(void *data)
695 return vino->i2c_data;
698 void i2c_vino_wdata(void *data, unsigned val)
700 vino->i2c_data = val;
703 static struct i2c_algo_sgi_data i2c_sgi_vino_data =
705 .getctrl = &i2c_vino_getctrl,
706 .setctrl = &i2c_vino_setctrl,
707 .rdata = &i2c_vino_rdata,
708 .wdata = &i2c_vino_wdata,
714 * There are two possible clients on VINO I2C bus, so we limit usage only
717 static int i2c_vino_client_reg(struct i2c_client *client)
722 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
723 switch (client->driver->id) {
724 case I2C_DRIVERID_SAA7191:
725 if (vino_drvdata->decoder.driver)
728 vino_drvdata->decoder.driver = client;
730 case I2C_DRIVERID_INDYCAM:
731 if (vino_drvdata->camera.driver)
734 vino_drvdata->camera.driver = client;
739 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
744 static int i2c_vino_client_unreg(struct i2c_client *client)
749 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
750 if (client == vino_drvdata->decoder.driver) {
751 if (vino_drvdata->decoder.owner != VINO_NO_CHANNEL)
754 vino_drvdata->decoder.driver = NULL;
755 } else if (client == vino_drvdata->camera.driver) {
756 if (vino_drvdata->camera.owner != VINO_NO_CHANNEL)
759 vino_drvdata->camera.driver = NULL;
761 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
766 static struct i2c_adapter vino_i2c_adapter =
768 .name = "VINO I2C bus",
769 .id = I2C_HW_SGI_VINO,
770 .algo_data = &i2c_sgi_vino_data,
771 .client_register = &i2c_vino_client_reg,
772 .client_unregister = &i2c_vino_client_unreg,
775 static int vino_i2c_add_bus(void)
777 return i2c_sgi_add_bus(&vino_i2c_adapter);
780 static int vino_i2c_del_bus(void)
782 return i2c_del_adapter(&vino_i2c_adapter);
785 static int i2c_camera_command(unsigned int cmd, void *arg)
787 return vino_drvdata->camera.driver->
788 driver->command(vino_drvdata->camera.driver,
792 static int i2c_decoder_command(unsigned int cmd, void *arg)
794 return vino_drvdata->decoder.driver->
795 driver->command(vino_drvdata->decoder.driver,
799 /* VINO framebuffer/DMA descriptor management */
801 static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
806 dprintk("vino_free_buffer_with_count(): count = %d\n", count);
808 for (i = 0; i < count; i++) {
809 ClearPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
810 dma_unmap_single(NULL,
811 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
812 PAGE_SIZE, DMA_FROM_DEVICE);
813 free_page(fb->desc_table.virtual[i]);
816 dma_free_coherent(NULL,
817 VINO_PAGE_RATIO * (fb->desc_table.page_count + 4) *
818 sizeof(dma_addr_t), (void *)fb->desc_table.dma_cpu,
820 kfree(fb->desc_table.virtual);
822 memset(fb, 0, sizeof(struct vino_framebuffer));
825 static void vino_free_buffer(struct vino_framebuffer *fb)
827 vino_free_buffer_with_count(fb, fb->desc_table.page_count);
830 static int vino_allocate_buffer(struct vino_framebuffer *fb,
833 unsigned int count, i, j;
836 dprintk("vino_allocate_buffer():\n");
841 memset(fb, 0, sizeof(struct vino_framebuffer));
843 count = ((size / PAGE_SIZE) + 4) & ~3;
845 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
848 /* allocate memory for table with virtual (page) addresses */
849 fb->desc_table.virtual = (unsigned long *)
850 kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
851 if (!fb->desc_table.virtual)
854 /* allocate memory for table with dma addresses
855 * (has space for four extra descriptors) */
856 fb->desc_table.dma_cpu =
857 dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
858 sizeof(dma_addr_t), &fb->desc_table.dma,
859 GFP_KERNEL | GFP_DMA);
860 if (!fb->desc_table.dma_cpu) {
862 goto out_free_virtual;
865 /* allocate pages for the buffer and acquire the according
867 for (i = 0; i < count; i++) {
868 dma_addr_t dma_data_addr;
870 fb->desc_table.virtual[i] =
871 get_zeroed_page(GFP_KERNEL | GFP_DMA);
872 if (!fb->desc_table.virtual[i]) {
879 (void *)fb->desc_table.virtual[i],
880 PAGE_SIZE, DMA_FROM_DEVICE);
882 for (j = 0; j < VINO_PAGE_RATIO; j++) {
883 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
884 dma_data_addr + VINO_PAGE_SIZE * j;
887 SetPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
890 /* page_count needs to be set anyway, because the descriptor table has
891 * been allocated according to this number */
892 fb->desc_table.page_count = count;
895 /* the descriptor with index i doesn't contain
896 * a valid address yet */
897 vino_free_buffer_with_count(fb, i);
902 fb->size = count * PAGE_SIZE;
903 fb->data_format = VINO_DATA_FMT_NONE;
905 /* set the dma stop-bit for the last (count+1)th descriptor */
906 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
910 kfree(fb->desc_table.virtual);
915 /* user buffers not fully implemented yet */
916 static int vino_prepare_user_buffer(struct vino_framebuffer *fb,
920 unsigned int count, i, j;
923 dprintk("vino_prepare_user_buffer():\n");
928 memset(fb, 0, sizeof(struct vino_framebuffer));
930 count = ((size / PAGE_SIZE)) & ~3;
932 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
935 /* allocate memory for table with virtual (page) addresses */
936 fb->desc_table.virtual = (unsigned long *)
937 kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
938 if (!fb->desc_table.virtual)
941 /* allocate memory for table with dma addresses
942 * (has space for four extra descriptors) */
943 fb->desc_table.dma_cpu =
944 dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
945 sizeof(dma_addr_t), &fb->desc_table.dma,
946 GFP_KERNEL | GFP_DMA);
947 if (!fb->desc_table.dma_cpu) {
949 goto out_free_virtual;
952 /* allocate pages for the buffer and acquire the according
954 for (i = 0; i < count; i++) {
955 dma_addr_t dma_data_addr;
957 fb->desc_table.virtual[i] =
958 get_zeroed_page(GFP_KERNEL | GFP_DMA);
959 if (!fb->desc_table.virtual[i]) {
966 (void *)fb->desc_table.virtual[i],
967 PAGE_SIZE, DMA_FROM_DEVICE);
969 for (j = 0; j < VINO_PAGE_RATIO; j++) {
970 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
971 dma_data_addr + VINO_PAGE_SIZE * j;
974 SetPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
977 /* page_count needs to be set anyway, because the descriptor table has
978 * been allocated according to this number */
979 fb->desc_table.page_count = count;
982 /* the descriptor with index i doesn't contain
983 * a valid address yet */
984 vino_free_buffer_with_count(fb, i);
989 fb->size = count * PAGE_SIZE;
991 /* set the dma stop-bit for the last (count+1)th descriptor */
992 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
996 kfree(fb->desc_table.virtual);
1001 static void vino_sync_buffer(struct vino_framebuffer *fb)
1005 dprintk("vino_sync_buffer():\n");
1007 for (i = 0; i < fb->desc_table.page_count; i++)
1008 dma_sync_single(NULL,
1009 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
1010 PAGE_SIZE, DMA_FROM_DEVICE);
1013 /* Framebuffer fifo functions (need to be locked externally) */
1015 static inline void vino_fifo_init(struct vino_framebuffer_fifo *f,
1016 unsigned int length)
1023 if (length > VINO_FRAMEBUFFER_COUNT_MAX)
1024 length = VINO_FRAMEBUFFER_COUNT_MAX;
1029 /* returns true/false */
1030 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo *f,
1035 for (i = f->head; i == (f->tail - 1); i = (i + 1) % f->length) {
1036 if (f->data[i] == id)
1044 /* returns true/false */
1045 static inline int vino_fifo_full(struct vino_framebuffer_fifo *f)
1047 return (f->used == f->length);
1051 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo *f)
1056 static int vino_fifo_enqueue(struct vino_framebuffer_fifo *f, unsigned int id)
1058 if (id >= f->length) {
1059 return VINO_QUEUE_ERROR;
1062 if (vino_fifo_has_id(f, id)) {
1063 return VINO_QUEUE_ERROR;
1066 if (f->used < f->length) {
1067 f->data[f->tail] = id;
1068 f->tail = (f->tail + 1) % f->length;
1071 return VINO_QUEUE_ERROR;
1077 static int vino_fifo_peek(struct vino_framebuffer_fifo *f, unsigned int *id)
1080 *id = f->data[f->head];
1082 return VINO_QUEUE_ERROR;
1088 static int vino_fifo_dequeue(struct vino_framebuffer_fifo *f, unsigned int *id)
1091 *id = f->data[f->head];
1092 f->head = (f->head + 1) % f->length;
1095 return VINO_QUEUE_ERROR;
1101 /* Framebuffer queue functions */
1103 /* execute with queue_lock locked */
1104 static void vino_queue_free_with_count(struct vino_framebuffer_queue *q,
1105 unsigned int length)
1110 memset(&q->in, 0, sizeof(struct vino_framebuffer_fifo));
1111 memset(&q->out, 0, sizeof(struct vino_framebuffer_fifo));
1112 for (i = 0; i < length; i++) {
1113 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
1115 vino_free_buffer(q->buffer[i]);
1116 kfree(q->buffer[i]);
1119 q->type = VINO_MEMORY_NONE;
1123 static void vino_queue_free(struct vino_framebuffer_queue *q)
1125 dprintk("vino_queue_free():\n");
1127 if (q->magic != VINO_QUEUE_MAGIC)
1129 if (q->type != VINO_MEMORY_MMAP)
1132 mutex_lock(&q->queue_mutex);
1134 vino_queue_free_with_count(q, q->length);
1136 mutex_unlock(&q->queue_mutex);
1139 static int vino_queue_init(struct vino_framebuffer_queue *q,
1140 unsigned int *length)
1145 dprintk("vino_queue_init(): length = %d\n", *length);
1147 if (q->magic == VINO_QUEUE_MAGIC) {
1148 dprintk("vino_queue_init(): queue already initialized!\n");
1152 if (q->type != VINO_MEMORY_NONE) {
1153 dprintk("vino_queue_init(): queue already initialized!\n");
1160 mutex_lock(&q->queue_mutex);
1162 if (*length > VINO_FRAMEBUFFER_COUNT_MAX)
1163 *length = VINO_FRAMEBUFFER_COUNT_MAX;
1167 for (i = 0; i < *length; i++) {
1168 dprintk("vino_queue_init(): allocating buffer %d\n", i);
1169 q->buffer[i] = kmalloc(sizeof(struct vino_framebuffer),
1171 if (!q->buffer[i]) {
1172 dprintk("vino_queue_init(): kmalloc() failed\n");
1177 ret = vino_allocate_buffer(q->buffer[i],
1178 VINO_FRAMEBUFFER_SIZE);
1180 kfree(q->buffer[i]);
1181 dprintk("vino_queue_init(): "
1182 "vino_allocate_buffer() failed\n");
1186 q->buffer[i]->id = i;
1188 q->buffer[i]->offset = q->buffer[i - 1]->offset +
1189 q->buffer[i - 1]->size;
1191 q->buffer[i]->offset = 0;
1194 spin_lock_init(&q->buffer[i]->state_lock);
1196 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1197 "size = %d\n", i, q->buffer[i]->offset,
1198 q->buffer[i]->size);
1202 vino_queue_free_with_count(q, i);
1205 q->length = *length;
1206 vino_fifo_init(&q->in, q->length);
1207 vino_fifo_init(&q->out, q->length);
1208 q->type = VINO_MEMORY_MMAP;
1209 q->magic = VINO_QUEUE_MAGIC;
1212 mutex_unlock(&q->queue_mutex);
1217 static struct vino_framebuffer *vino_queue_add(struct
1218 vino_framebuffer_queue *q,
1221 struct vino_framebuffer *ret = NULL;
1223 unsigned long flags;
1225 dprintk("vino_queue_add(): id = %d\n", id);
1227 if (q->magic != VINO_QUEUE_MAGIC) {
1231 spin_lock_irqsave(&q->queue_lock, flags);
1236 if (id >= q->length)
1239 /* not needed?: if (vino_fifo_full(&q->out)) {
1242 /* check that outgoing queue isn't already full
1243 * (or that it won't become full) */
1244 total = vino_fifo_get_used(&q->in) +
1245 vino_fifo_get_used(&q->out);
1246 if (total >= q->length)
1249 if (vino_fifo_enqueue(&q->in, id))
1252 ret = q->buffer[id];
1255 spin_unlock_irqrestore(&q->queue_lock, flags);
1260 static struct vino_framebuffer *vino_queue_transfer(struct
1261 vino_framebuffer_queue *q)
1263 struct vino_framebuffer *ret = NULL;
1264 struct vino_framebuffer *fb;
1266 unsigned long flags;
1268 dprintk("vino_queue_transfer():\n");
1270 if (q->magic != VINO_QUEUE_MAGIC) {
1274 spin_lock_irqsave(&q->queue_lock, flags);
1279 // now this actually removes an entry from the incoming queue
1280 if (vino_fifo_dequeue(&q->in, &id)) {
1284 dprintk("vino_queue_transfer(): id = %d\n", id);
1287 // we have already checked that the outgoing queue is not full, but...
1288 if (vino_fifo_enqueue(&q->out, id)) {
1289 printk(KERN_ERR "vino_queue_transfer(): "
1290 "outgoing queue is full, this shouldn't happen!\n");
1296 spin_unlock_irqrestore(&q->queue_lock, flags);
1301 /* returns true/false */
1302 static int vino_queue_incoming_contains(struct vino_framebuffer_queue *q,
1306 unsigned long flags;
1308 if (q->magic != VINO_QUEUE_MAGIC) {
1312 spin_lock_irqsave(&q->queue_lock, flags);
1317 ret = vino_fifo_has_id(&q->in, id);
1320 spin_unlock_irqrestore(&q->queue_lock, flags);
1325 /* returns true/false */
1326 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue *q,
1330 unsigned long flags;
1332 if (q->magic != VINO_QUEUE_MAGIC) {
1336 spin_lock_irqsave(&q->queue_lock, flags);
1341 ret = vino_fifo_has_id(&q->out, id);
1344 spin_unlock_irqrestore(&q->queue_lock, flags);
1349 static int vino_queue_get_incoming(struct vino_framebuffer_queue *q,
1353 unsigned long flags;
1355 if (q->magic != VINO_QUEUE_MAGIC) {
1356 return VINO_QUEUE_ERROR;
1359 spin_lock_irqsave(&q->queue_lock, flags);
1361 if (q->length == 0) {
1362 ret = VINO_QUEUE_ERROR;
1366 *used = vino_fifo_get_used(&q->in);
1369 spin_unlock_irqrestore(&q->queue_lock, flags);
1374 static int vino_queue_get_outgoing(struct vino_framebuffer_queue *q,
1378 unsigned long flags;
1380 if (q->magic != VINO_QUEUE_MAGIC) {
1381 return VINO_QUEUE_ERROR;
1384 spin_lock_irqsave(&q->queue_lock, flags);
1386 if (q->length == 0) {
1387 ret = VINO_QUEUE_ERROR;
1391 *used = vino_fifo_get_used(&q->out);
1394 spin_unlock_irqrestore(&q->queue_lock, flags);
1400 static int vino_queue_get_total(struct vino_framebuffer_queue *q,
1401 unsigned int *total)
1404 unsigned long flags;
1406 if (q->magic != VINO_QUEUE_MAGIC) {
1407 return VINO_QUEUE_ERROR;
1410 spin_lock_irqsave(&q->queue_lock, flags);
1412 if (q->length == 0) {
1413 ret = VINO_QUEUE_ERROR;
1417 *total = vino_fifo_get_used(&q->in) +
1418 vino_fifo_get_used(&q->out);
1421 spin_unlock_irqrestore(&q->queue_lock, flags);
1427 static struct vino_framebuffer *vino_queue_peek(struct
1428 vino_framebuffer_queue *q,
1431 struct vino_framebuffer *ret = NULL;
1432 unsigned long flags;
1434 if (q->magic != VINO_QUEUE_MAGIC) {
1438 spin_lock_irqsave(&q->queue_lock, flags);
1443 if (vino_fifo_peek(&q->in, id)) {
1447 ret = q->buffer[*id];
1449 spin_unlock_irqrestore(&q->queue_lock, flags);
1454 static struct vino_framebuffer *vino_queue_remove(struct
1455 vino_framebuffer_queue *q,
1458 struct vino_framebuffer *ret = NULL;
1459 unsigned long flags;
1460 dprintk("vino_queue_remove():\n");
1462 if (q->magic != VINO_QUEUE_MAGIC) {
1466 spin_lock_irqsave(&q->queue_lock, flags);
1471 if (vino_fifo_dequeue(&q->out, id)) {
1475 dprintk("vino_queue_remove(): id = %d\n", *id);
1476 ret = q->buffer[*id];
1478 spin_unlock_irqrestore(&q->queue_lock, flags);
1484 vino_framebuffer *vino_queue_get_buffer(struct vino_framebuffer_queue *q,
1487 struct vino_framebuffer *ret = NULL;
1488 unsigned long flags;
1490 if (q->magic != VINO_QUEUE_MAGIC) {
1494 spin_lock_irqsave(&q->queue_lock, flags);
1499 if (id >= q->length)
1502 ret = q->buffer[id];
1504 spin_unlock_irqrestore(&q->queue_lock, flags);
1509 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue *q)
1511 unsigned int length = 0;
1512 unsigned long flags;
1514 if (q->magic != VINO_QUEUE_MAGIC) {
1518 spin_lock_irqsave(&q->queue_lock, flags);
1520 spin_unlock_irqrestore(&q->queue_lock, flags);
1525 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue *q)
1529 unsigned long flags;
1531 if (q->magic != VINO_QUEUE_MAGIC) {
1535 spin_lock_irqsave(&q->queue_lock, flags);
1536 for (i = 0; i < q->length; i++) {
1537 if (q->buffer[i]->map_count > 0) {
1542 spin_unlock_irqrestore(&q->queue_lock, flags);
1547 /* VINO functions */
1549 /* execute with input_lock locked */
1550 static void vino_update_line_size(struct vino_channel_settings *vcs)
1552 unsigned int w = vcs->clipping.right - vcs->clipping.left;
1553 unsigned int d = vcs->decimation;
1554 unsigned int bpp = vino_data_formats[vcs->data_format].bpp;
1557 dprintk("update_line_size(): before: w = %d, d = %d, "
1558 "line_size = %d\n", w, d, vcs->line_size);
1560 /* line size must be multiple of 8 bytes */
1561 lsize = (bpp * (w / d)) & ~7;
1562 w = (lsize / bpp) * d;
1564 vcs->clipping.right = vcs->clipping.left + w;
1565 vcs->line_size = lsize;
1567 dprintk("update_line_size(): after: w = %d, d = %d, "
1568 "line_size = %d\n", w, d, vcs->line_size);
1571 /* execute with input_lock locked */
1572 static void vino_set_clipping(struct vino_channel_settings *vcs,
1573 unsigned int x, unsigned int y,
1574 unsigned int w, unsigned int h)
1576 unsigned int maxwidth, maxheight;
1579 maxwidth = vino_data_norms[vcs->data_norm].width;
1580 maxheight = vino_data_norms[vcs->data_norm].height;
1581 d = vcs->decimation;
1583 y &= ~1; /* odd/even fields */
1588 if (y > maxheight) {
1592 if (((w / d) < VINO_MIN_WIDTH)
1593 || ((h / d) < VINO_MIN_HEIGHT)) {
1594 w = VINO_MIN_WIDTH * d;
1595 h = VINO_MIN_HEIGHT * d;
1598 if ((x + w) > maxwidth) {
1600 if ((w / d) < VINO_MIN_WIDTH)
1601 x = maxwidth - VINO_MIN_WIDTH * d;
1603 if ((y + h) > maxheight) {
1605 if ((h / d) < VINO_MIN_HEIGHT)
1606 y = maxheight - VINO_MIN_HEIGHT * d;
1609 vcs->clipping.left = x;
1610 vcs->clipping.top = y;
1611 vcs->clipping.right = x + w;
1612 vcs->clipping.bottom = y + h;
1614 vino_update_line_size(vcs);
1616 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1617 vcs->clipping.left, vcs->clipping.top, vcs->clipping.right,
1618 vcs->clipping.bottom, vcs->decimation, vcs->line_size);
1621 /* execute with input_lock locked */
1622 static inline void vino_set_default_clipping(struct vino_channel_settings *vcs)
1624 vino_set_clipping(vcs, 0, 0, vino_data_norms[vcs->data_norm].width,
1625 vino_data_norms[vcs->data_norm].height);
1628 /* execute with input_lock locked */
1629 static void vino_set_scaling(struct vino_channel_settings *vcs,
1630 unsigned int w, unsigned int h)
1632 unsigned int x, y, curw, curh, d;
1634 x = vcs->clipping.left;
1635 y = vcs->clipping.top;
1636 curw = vcs->clipping.right - vcs->clipping.left;
1637 curh = vcs->clipping.bottom - vcs->clipping.top;
1639 d = max(curw / w, curh / h);
1641 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1642 w, h, curw, curh, d);
1650 vcs->decimation = d;
1651 vino_set_clipping(vcs, x, y, w * d, h * d);
1653 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs->clipping.left,
1654 vcs->clipping.top, vcs->clipping.right, vcs->clipping.bottom,
1655 vcs->decimation, vcs->line_size);
1658 /* execute with input_lock locked */
1659 static inline void vino_set_default_scaling(struct vino_channel_settings *vcs)
1661 vino_set_scaling(vcs, vcs->clipping.right - vcs->clipping.left,
1662 vcs->clipping.bottom - vcs->clipping.top);
1665 /* execute with input_lock locked */
1666 static void vino_set_framerate(struct vino_channel_settings *vcs,
1671 switch (vcs->data_norm) {
1672 case VINO_DATA_NORM_NTSC:
1673 case VINO_DATA_NORM_D1:
1674 fps = (unsigned int)(fps / 6) * 6; // FIXME: round!
1676 if (fps < vino_data_norms[vcs->data_norm].fps_min)
1677 fps = vino_data_norms[vcs->data_norm].fps_min;
1678 if (fps > vino_data_norms[vcs->data_norm].fps_max)
1679 fps = vino_data_norms[vcs->data_norm].fps_max;
1698 mask = VINO_FRAMERT_FULL;
1700 vcs->framert_reg = VINO_FRAMERT_RT(mask);
1702 case VINO_DATA_NORM_PAL:
1703 case VINO_DATA_NORM_SECAM:
1704 fps = (unsigned int)(fps / 5) * 5; // FIXME: round!
1706 if (fps < vino_data_norms[vcs->data_norm].fps_min)
1707 fps = vino_data_norms[vcs->data_norm].fps_min;
1708 if (fps > vino_data_norms[vcs->data_norm].fps_max)
1709 fps = vino_data_norms[vcs->data_norm].fps_max;
1728 mask = VINO_FRAMERT_FULL;
1730 vcs->framert_reg = VINO_FRAMERT_RT(mask) | VINO_FRAMERT_PAL;
1737 /* execute with input_lock locked */
1738 static inline void vino_set_default_framerate(struct
1739 vino_channel_settings *vcs)
1741 vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max);
1745 * Prepare VINO for DMA transfer...
1746 * (execute only with vino_lock and input_lock locked)
1748 static int vino_dma_setup(struct vino_channel_settings *vcs,
1749 struct vino_framebuffer *fb)
1752 struct sgi_vino_channel *ch;
1753 const struct vino_data_norm *norm;
1755 dprintk("vino_dma_setup():\n");
1758 fb->frame_counter = 0;
1760 ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
1761 norm = &vino_data_norms[vcs->data_norm];
1766 /* VINO line size register is set 8 bytes less than actual */
1767 ch->line_size = vcs->line_size - 8;
1769 /* let VINO know where to transfer data */
1770 ch->start_desc_tbl = fb->desc_table.dma;
1771 ch->next_4_desc = fb->desc_table.dma;
1773 /* give vino time to fetch the first four descriptors, 5 usec
1774 * should be more than enough time */
1775 udelay(VINO_DESC_FETCH_DELAY);
1777 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1778 ch->start_desc_tbl, ch->next_4_desc);
1780 /* set the alpha register */
1781 ch->alpha = vcs->alpha;
1783 /* set clipping registers */
1784 ch->clip_start = VINO_CLIP_ODD(norm->odd.top + vcs->clipping.top / 2) |
1785 VINO_CLIP_EVEN(norm->even.top +
1786 vcs->clipping.top / 2) |
1787 VINO_CLIP_X(vcs->clipping.left);
1788 ch->clip_end = VINO_CLIP_ODD(norm->odd.top +
1789 vcs->clipping.bottom / 2 - 1) |
1790 VINO_CLIP_EVEN(norm->even.top +
1791 vcs->clipping.bottom / 2 - 1) |
1792 VINO_CLIP_X(vcs->clipping.right);
1794 /* set the size of actual content in the buffer (DECIMATION !) */
1795 fb->data_size = ((vcs->clipping.right - vcs->clipping.left) /
1797 ((vcs->clipping.bottom - vcs->clipping.top) /
1799 vino_data_formats[vcs->data_format].bpp;
1801 ch->frame_rate = vcs->framert_reg;
1803 ctrl = vino->control;
1804 intr = vino->intr_status;
1806 if (vcs->channel == VINO_CHANNEL_A) {
1807 /* All interrupt conditions for this channel was cleared
1808 * so clear the interrupt status register and enable
1810 intr &= ~VINO_INTSTAT_A;
1811 ctrl |= VINO_CTRL_A_INT;
1813 /* enable synchronization */
1814 ctrl |= VINO_CTRL_A_SYNC_ENBL;
1816 /* enable frame assembly */
1817 ctrl |= VINO_CTRL_A_INTERLEAVE_ENBL;
1819 /* set decimation used */
1820 if (vcs->decimation < 2)
1821 ctrl &= ~VINO_CTRL_A_DEC_ENBL;
1823 ctrl |= VINO_CTRL_A_DEC_ENBL;
1824 ctrl &= ~VINO_CTRL_A_DEC_SCALE_MASK;
1825 ctrl |= (vcs->decimation - 1) <<
1826 VINO_CTRL_A_DEC_SCALE_SHIFT;
1829 /* select input interface */
1830 if (vcs->input == VINO_INPUT_D1)
1831 ctrl |= VINO_CTRL_A_SELECT;
1833 ctrl &= ~VINO_CTRL_A_SELECT;
1836 ctrl &= ~(VINO_CTRL_A_LUMA_ONLY | VINO_CTRL_A_RGB |
1837 VINO_CTRL_A_DITHER);
1839 intr &= ~VINO_INTSTAT_B;
1840 ctrl |= VINO_CTRL_B_INT;
1842 ctrl |= VINO_CTRL_B_SYNC_ENBL;
1843 ctrl |= VINO_CTRL_B_INTERLEAVE_ENBL;
1845 if (vcs->decimation < 2)
1846 ctrl &= ~VINO_CTRL_B_DEC_ENBL;
1848 ctrl |= VINO_CTRL_B_DEC_ENBL;
1849 ctrl &= ~VINO_CTRL_B_DEC_SCALE_MASK;
1850 ctrl |= (vcs->decimation - 1) <<
1851 VINO_CTRL_B_DEC_SCALE_SHIFT;
1854 if (vcs->input == VINO_INPUT_D1)
1855 ctrl |= VINO_CTRL_B_SELECT;
1857 ctrl &= ~VINO_CTRL_B_SELECT;
1859 ctrl &= ~(VINO_CTRL_B_LUMA_ONLY | VINO_CTRL_B_RGB |
1860 VINO_CTRL_B_DITHER);
1864 fb->data_format = vcs->data_format;
1866 switch (vcs->data_format) {
1867 case VINO_DATA_FMT_GREY:
1868 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1869 VINO_CTRL_A_LUMA_ONLY : VINO_CTRL_B_LUMA_ONLY;
1871 case VINO_DATA_FMT_RGB32:
1872 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1873 VINO_CTRL_A_RGB : VINO_CTRL_B_RGB;
1875 case VINO_DATA_FMT_YUV:
1876 /* nothing needs to be done */
1878 case VINO_DATA_FMT_RGB332:
1879 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1880 VINO_CTRL_A_RGB | VINO_CTRL_A_DITHER :
1881 VINO_CTRL_B_RGB | VINO_CTRL_B_DITHER;
1885 vino->intr_status = intr;
1886 vino->control = ctrl;
1891 /* (execute only with vino_lock locked) */
1892 static inline void vino_dma_start(struct vino_channel_settings *vcs)
1894 u32 ctrl = vino->control;
1896 dprintk("vino_dma_start():\n");
1897 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1898 VINO_CTRL_A_DMA_ENBL : VINO_CTRL_B_DMA_ENBL;
1899 vino->control = ctrl;
1902 /* (execute only with vino_lock locked) */
1903 static inline void vino_dma_stop(struct vino_channel_settings *vcs)
1905 u32 ctrl = vino->control;
1907 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1908 ~VINO_CTRL_A_DMA_ENBL : ~VINO_CTRL_B_DMA_ENBL;
1909 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1910 ~VINO_CTRL_A_INT : ~VINO_CTRL_B_INT;
1911 vino->control = ctrl;
1912 dprintk("vino_dma_stop():\n");
1916 * Load dummy page to descriptor registers. This prevents generating of
1917 * spurious interrupts. (execute only with vino_lock locked)
1919 static void vino_clear_interrupt(struct vino_channel_settings *vcs)
1921 struct sgi_vino_channel *ch;
1923 ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
1928 ch->start_desc_tbl = vino_drvdata->dummy_desc_table.dma;
1929 ch->next_4_desc = vino_drvdata->dummy_desc_table.dma;
1931 udelay(VINO_DESC_FETCH_DELAY);
1932 dprintk("channel %c clear interrupt condition\n",
1933 (vcs->channel == VINO_CHANNEL_A) ? 'A':'B');
1936 static int vino_capture(struct vino_channel_settings *vcs,
1937 struct vino_framebuffer *fb)
1940 unsigned long flags, flags2;
1942 spin_lock_irqsave(&fb->state_lock, flags);
1944 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
1946 fb->state = VINO_FRAMEBUFFER_IN_USE;
1948 spin_unlock_irqrestore(&fb->state_lock, flags);
1953 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
1954 spin_lock_irqsave(&vino_drvdata->input_lock, flags2);
1956 vino_dma_setup(vcs, fb);
1957 vino_dma_start(vcs);
1959 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags2);
1960 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
1966 struct vino_framebuffer *vino_capture_enqueue(struct
1967 vino_channel_settings *vcs,
1970 struct vino_framebuffer *fb;
1971 unsigned long flags;
1973 dprintk("vino_capture_enqueue():\n");
1975 spin_lock_irqsave(&vcs->capture_lock, flags);
1977 fb = vino_queue_add(&vcs->fb_queue, index);
1979 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
1984 spin_unlock_irqrestore(&vcs->capture_lock, flags);
1989 static int vino_capture_next(struct vino_channel_settings *vcs, int start)
1991 struct vino_framebuffer *fb;
1992 unsigned int incoming, id;
1994 unsigned long flags;
1996 dprintk("vino_capture_next():\n");
1998 spin_lock_irqsave(&vcs->capture_lock, flags);
2001 /* start capture only if capture isn't in progress already */
2002 if (vcs->capturing) {
2003 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2008 /* capture next frame:
2009 * stop capture if capturing is not set */
2010 if (!vcs->capturing) {
2011 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2016 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
2018 dprintk("vino_capture_next(): vino_queue_get_incoming() "
2023 if (incoming == 0) {
2024 dprintk("vino_capture_next(): no buffers available\n");
2028 fb = vino_queue_peek(&vcs->fb_queue, &id);
2030 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
2039 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2041 err = vino_capture(vcs, fb);
2047 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2052 static inline int vino_is_capturing(struct vino_channel_settings *vcs)
2055 unsigned long flags;
2057 spin_lock_irqsave(&vcs->capture_lock, flags);
2059 ret = vcs->capturing;
2061 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2066 /* waits until a frame is captured */
2067 static int vino_wait_for_frame(struct vino_channel_settings *vcs)
2072 dprintk("vino_wait_for_frame():\n");
2074 init_waitqueue_entry(&wait, current);
2075 /* add ourselves into wait queue */
2076 add_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
2078 /* to ensure that schedule_timeout will return immediately
2079 * if VINO interrupt was triggered meanwhile */
2080 schedule_timeout_interruptible(msecs_to_jiffies(100));
2082 if (signal_pending(current))
2085 remove_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
2087 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2088 err ? "failed" : "ok");
2093 /* the function assumes that PAGE_SIZE % 4 == 0 */
2094 static void vino_convert_to_rgba(struct vino_framebuffer *fb) {
2095 unsigned char *pageptr;
2096 unsigned int page, i;
2099 for (page = 0; page < fb->desc_table.page_count; page++) {
2100 pageptr = (unsigned char *)fb->desc_table.virtual[page];
2102 for (i = 0; i < PAGE_SIZE; i += 4) {
2104 pageptr[0] = pageptr[3];
2105 pageptr[1] = pageptr[2];
2106 pageptr[2] = pageptr[1];
2113 /* checks if the buffer is in correct state and syncs data */
2114 static int vino_check_buffer(struct vino_channel_settings *vcs,
2115 struct vino_framebuffer *fb)
2118 unsigned long flags;
2120 dprintk("vino_check_buffer():\n");
2122 spin_lock_irqsave(&fb->state_lock, flags);
2123 switch (fb->state) {
2124 case VINO_FRAMEBUFFER_IN_USE:
2127 case VINO_FRAMEBUFFER_READY:
2128 vino_sync_buffer(fb);
2129 fb->state = VINO_FRAMEBUFFER_UNUSED;
2134 spin_unlock_irqrestore(&fb->state_lock, flags);
2137 if (vino_pixel_conversion
2138 && (fb->data_format == VINO_DATA_FMT_RGB32)) {
2139 vino_convert_to_rgba(fb);
2141 } else if (err && (err != -EINVAL)) {
2142 dprintk("vino_check_buffer(): buffer not ready\n");
2144 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
2146 vino_clear_interrupt(vcs);
2147 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2153 /* forcefully terminates capture */
2154 static void vino_capture_stop(struct vino_channel_settings *vcs)
2156 unsigned int incoming = 0, outgoing = 0, id;
2157 unsigned long flags, flags2;
2159 dprintk("vino_capture_stop():\n");
2161 spin_lock_irqsave(&vcs->capture_lock, flags);
2163 /* unset capturing to stop queue processing */
2166 spin_lock_irqsave(&vino_drvdata->vino_lock, flags2);
2169 vino_clear_interrupt(vcs);
2171 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags2);
2173 /* remove all items from the queue */
2174 if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
2175 dprintk("vino_capture_stop(): "
2176 "vino_queue_get_incoming() failed\n");
2179 while (incoming > 0) {
2180 vino_queue_transfer(&vcs->fb_queue);
2182 if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
2183 dprintk("vino_capture_stop(): "
2184 "vino_queue_get_incoming() failed\n");
2189 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
2190 dprintk("vino_capture_stop(): "
2191 "vino_queue_get_outgoing() failed\n");
2194 while (outgoing > 0) {
2195 vino_queue_remove(&vcs->fb_queue, &id);
2197 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
2198 dprintk("vino_capture_stop(): "
2199 "vino_queue_get_outgoing() failed\n");
2205 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2209 static int vino_capture_failed(struct vino_channel_settings *vcs)
2211 struct vino_framebuffer *fb;
2212 unsigned long flags;
2216 dprintk("vino_capture_failed():\n");
2218 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
2221 vino_clear_interrupt(vcs);
2223 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2225 ret = vino_queue_get_incoming(&vcs->fb_queue, &i);
2226 if (ret == VINO_QUEUE_ERROR) {
2227 dprintk("vino_queue_get_incoming() failed\n");
2231 /* no buffers to process */
2235 fb = vino_queue_peek(&vcs->fb_queue, &i);
2237 dprintk("vino_queue_peek() failed\n");
2241 spin_lock_irqsave(&fb->state_lock, flags);
2242 if (fb->state == VINO_FRAMEBUFFER_IN_USE) {
2243 fb->state = VINO_FRAMEBUFFER_UNUSED;
2244 vino_queue_transfer(&vcs->fb_queue);
2245 vino_queue_remove(&vcs->fb_queue, &i);
2246 /* we should actually discard the newest frame,
2247 * but who cares ... */
2249 spin_unlock_irqrestore(&fb->state_lock, flags);
2255 static void vino_skip_frame(struct vino_channel_settings *vcs)
2257 struct vino_framebuffer *fb;
2258 unsigned long flags;
2261 spin_lock_irqsave(&vcs->capture_lock, flags);
2262 fb = vino_queue_peek(&vcs->fb_queue, &id);
2264 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2265 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2268 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2270 spin_lock_irqsave(&fb->state_lock, flags);
2271 fb->state = VINO_FRAMEBUFFER_UNUSED;
2272 spin_unlock_irqrestore(&fb->state_lock, flags);
2274 vino_capture_next(vcs, 0);
2277 static void vino_frame_done(struct vino_channel_settings *vcs)
2279 struct vino_framebuffer *fb;
2280 unsigned long flags;
2282 spin_lock_irqsave(&vcs->capture_lock, flags);
2283 fb = vino_queue_transfer(&vcs->fb_queue);
2285 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2286 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2289 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2291 fb->frame_counter = vcs->int_data.frame_counter;
2292 memcpy(&fb->timestamp, &vcs->int_data.timestamp,
2293 sizeof(struct timeval));
2295 spin_lock_irqsave(&fb->state_lock, flags);
2296 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
2297 fb->state = VINO_FRAMEBUFFER_READY;
2298 spin_unlock_irqrestore(&fb->state_lock, flags);
2300 wake_up(&vcs->fb_queue.frame_wait_queue);
2302 vino_capture_next(vcs, 0);
2305 static void vino_capture_tasklet(unsigned long channel) {
2306 struct vino_channel_settings *vcs;
2308 vcs = (channel == VINO_CHANNEL_A)
2309 ? &vino_drvdata->a : &vino_drvdata->b;
2311 if (vcs->int_data.skip)
2312 vcs->int_data.skip_count++;
2314 if (vcs->int_data.skip && (vcs->int_data.skip_count
2315 <= VINO_MAX_FRAME_SKIP_COUNT)) {
2316 vino_skip_frame(vcs);
2318 vcs->int_data.skip_count = 0;
2319 vino_frame_done(vcs);
2323 static irqreturn_t vino_interrupt(int irq, void *dev_id)
2326 unsigned int fc_a, fc_b;
2327 int handled_a = 0, skip_a = 0, done_a = 0;
2328 int handled_b = 0, skip_b = 0, done_b = 0;
2330 #ifdef VINO_DEBUG_INT
2332 unsigned int line_count = vino->a.line_count,
2333 page_index = vino->a.page_index,
2334 field_counter = vino->a.field_counter,
2335 start_desc_tbl = vino->a.start_desc_tbl,
2336 next_4_desc = vino->a.next_4_desc;
2337 unsigned int line_count_2,
2344 spin_lock(&vino_drvdata->vino_lock);
2346 while ((intr = vino->intr_status)) {
2347 fc_a = vino->a.field_counter >> 1;
2348 fc_b = vino->b.field_counter >> 1;
2350 /* handle error-interrupts in some special way ?
2351 * --> skips frames */
2352 if (intr & VINO_INTSTAT_A) {
2353 if (intr & VINO_INTSTAT_A_EOF) {
2354 vino_drvdata->a.field++;
2355 if (vino_drvdata->a.field > 1) {
2356 vino_dma_stop(&vino_drvdata->a);
2357 vino_clear_interrupt(&vino_drvdata->a);
2358 vino_drvdata->a.field = 0;
2361 if (vino->a.page_index
2362 != vino_drvdata->a.line_size) {
2363 vino->a.line_count = 0;
2364 vino->a.page_index =
2367 vino->a.next_4_desc =
2368 vino->a.start_desc_tbl;
2371 dprintk("channel A end-of-field "
2372 "interrupt: %04x\n", intr);
2374 vino_dma_stop(&vino_drvdata->a);
2375 vino_clear_interrupt(&vino_drvdata->a);
2376 vino_drvdata->a.field = 0;
2378 dprintk("channel A error interrupt: %04x\n",
2382 #ifdef VINO_DEBUG_INT
2383 line_count_2 = vino->a.line_count;
2384 page_index_2 = vino->a.page_index;
2385 field_counter_2 = vino->a.field_counter;
2386 start_desc_tbl_2 = vino->a.start_desc_tbl;
2387 next_4_desc_2 = vino->a.next_4_desc;
2389 printk("intr = %04x, loop = %d, field = %d\n",
2390 intr, loop, vino_drvdata->a.field);
2391 printk("1- line count = %04d, page index = %04d, "
2392 "start = %08x, next = %08x\n"
2393 " fieldc = %d, framec = %d\n",
2394 line_count, page_index, start_desc_tbl,
2395 next_4_desc, field_counter, fc_a);
2396 printk("12-line count = %04d, page index = %04d, "
2397 " start = %08x, next = %08x\n",
2398 line_count_2, page_index_2, start_desc_tbl_2,
2406 if (intr & VINO_INTSTAT_B) {
2407 if (intr & VINO_INTSTAT_B_EOF) {
2408 vino_drvdata->b.field++;
2409 if (vino_drvdata->b.field > 1) {
2410 vino_dma_stop(&vino_drvdata->b);
2411 vino_clear_interrupt(&vino_drvdata->b);
2412 vino_drvdata->b.field = 0;
2415 dprintk("channel B end-of-field "
2416 "interrupt: %04x\n", intr);
2418 vino_dma_stop(&vino_drvdata->b);
2419 vino_clear_interrupt(&vino_drvdata->b);
2420 vino_drvdata->b.field = 0;
2422 dprintk("channel B error interrupt: %04x\n",
2427 /* Always remember to clear interrupt status.
2428 * Disable VINO interrupts while we do this. */
2429 ctrl = vino->control;
2430 vino->control = ctrl & ~(VINO_CTRL_A_INT | VINO_CTRL_B_INT);
2431 vino->intr_status = ~intr;
2432 vino->control = ctrl;
2434 spin_unlock(&vino_drvdata->vino_lock);
2436 if ((!handled_a) && (done_a || skip_a)) {
2438 do_gettimeofday(&vino_drvdata->
2439 a.int_data.timestamp);
2440 vino_drvdata->a.int_data.frame_counter = fc_a;
2442 vino_drvdata->a.int_data.skip = skip_a;
2444 dprintk("channel A %s, interrupt: %d\n",
2445 skip_a ? "skipping frame" : "frame done",
2447 tasklet_hi_schedule(&vino_tasklet_a);
2451 if ((!handled_b) && (done_b || skip_b)) {
2453 do_gettimeofday(&vino_drvdata->
2454 b.int_data.timestamp);
2455 vino_drvdata->b.int_data.frame_counter = fc_b;
2457 vino_drvdata->b.int_data.skip = skip_b;
2459 dprintk("channel B %s, interrupt: %d\n",
2460 skip_b ? "skipping frame" : "frame done",
2462 tasklet_hi_schedule(&vino_tasklet_b);
2466 #ifdef VINO_DEBUG_INT
2469 spin_lock(&vino_drvdata->vino_lock);
2472 spin_unlock(&vino_drvdata->vino_lock);
2477 /* VINO video input management */
2479 static int vino_get_saa7191_input(int input)
2482 case VINO_INPUT_COMPOSITE:
2483 return SAA7191_INPUT_COMPOSITE;
2484 case VINO_INPUT_SVIDEO:
2485 return SAA7191_INPUT_SVIDEO;
2487 printk(KERN_ERR "VINO: vino_get_saa7191_input(): "
2488 "invalid input!\n");
2493 static int vino_get_saa7191_norm(unsigned int data_norm)
2495 switch (data_norm) {
2496 case VINO_DATA_NORM_AUTO:
2497 return SAA7191_NORM_AUTO;
2498 case VINO_DATA_NORM_AUTO_EXT:
2499 return SAA7191_NORM_AUTO_EXT;
2500 case VINO_DATA_NORM_PAL:
2501 return SAA7191_NORM_PAL;
2502 case VINO_DATA_NORM_NTSC:
2503 return SAA7191_NORM_NTSC;
2504 case VINO_DATA_NORM_SECAM:
2505 return SAA7191_NORM_SECAM;
2507 printk(KERN_ERR "VINO: vino_get_saa7191_norm(): "
2513 static int vino_get_from_saa7191_norm(int saa7191_norm)
2515 switch (saa7191_norm) {
2516 case SAA7191_NORM_PAL:
2517 return VINO_DATA_NORM_PAL;
2518 case SAA7191_NORM_NTSC:
2519 return VINO_DATA_NORM_NTSC;
2520 case SAA7191_NORM_SECAM:
2521 return VINO_DATA_NORM_SECAM;
2523 printk(KERN_ERR "VINO: vino_get_from_saa7191_norm(): "
2525 return VINO_DATA_NORM_NONE;
2529 static int vino_saa7191_set_norm(unsigned int *data_norm)
2531 int saa7191_norm, new_data_norm;
2534 saa7191_norm = vino_get_saa7191_norm(*data_norm);
2536 err = i2c_decoder_command(DECODER_SAA7191_SET_NORM,
2541 if ((*data_norm == VINO_DATA_NORM_AUTO)
2542 || (*data_norm == VINO_DATA_NORM_AUTO_EXT)) {
2543 struct saa7191_status status;
2545 err = i2c_decoder_command(DECODER_SAA7191_GET_STATUS,
2551 vino_get_from_saa7191_norm(status.norm);
2552 if (new_data_norm == VINO_DATA_NORM_NONE) {
2557 *data_norm = (unsigned int)new_data_norm;
2564 /* execute with input_lock locked */
2565 static int vino_is_input_owner(struct vino_channel_settings *vcs)
2567 switch(vcs->input) {
2568 case VINO_INPUT_COMPOSITE:
2569 case VINO_INPUT_SVIDEO:
2570 return (vino_drvdata->decoder.owner == vcs->channel);
2572 return (vino_drvdata->camera.owner == vcs->channel);
2578 static int vino_acquire_input(struct vino_channel_settings *vcs)
2580 unsigned long flags;
2583 dprintk("vino_acquire_input():\n");
2585 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2587 /* First try D1 and then SAA7191 */
2588 if (vino_drvdata->camera.driver
2589 && (vino_drvdata->camera.owner == VINO_NO_CHANNEL)) {
2590 i2c_use_client(vino_drvdata->camera.driver);
2591 vino_drvdata->camera.owner = vcs->channel;
2592 vcs->input = VINO_INPUT_D1;
2593 vcs->data_norm = VINO_DATA_NORM_D1;
2594 } else if (vino_drvdata->decoder.driver
2595 && (vino_drvdata->decoder.owner == VINO_NO_CHANNEL)) {
2596 int input, data_norm;
2599 i2c_use_client(vino_drvdata->decoder.driver);
2600 input = VINO_INPUT_COMPOSITE;
2602 saa7191_input = vino_get_saa7191_input(input);
2603 ret = i2c_decoder_command(DECODER_SET_INPUT,
2610 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2612 /* Don't hold spinlocks while auto-detecting norm
2613 * as it may take a while... */
2615 data_norm = VINO_DATA_NORM_AUTO_EXT;
2617 ret = vino_saa7191_set_norm(&data_norm);
2618 if ((ret == -EBUSY) || (ret == -EAGAIN)) {
2619 data_norm = VINO_DATA_NORM_PAL;
2620 ret = vino_saa7191_set_norm(&data_norm);
2623 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2630 vino_drvdata->decoder.owner = vcs->channel;
2633 vcs->data_norm = data_norm;
2635 vcs->input = (vcs->channel == VINO_CHANNEL_A) ?
2636 vino_drvdata->b.input : vino_drvdata->a.input;
2637 vcs->data_norm = (vcs->channel == VINO_CHANNEL_A) ?
2638 vino_drvdata->b.data_norm : vino_drvdata->a.data_norm;
2641 if (vcs->input == VINO_INPUT_NONE) {
2646 vino_set_default_clipping(vcs);
2647 vino_set_default_scaling(vcs);
2648 vino_set_default_framerate(vcs);
2650 dprintk("vino_acquire_input(): %s\n", vino_inputs[vcs->input].name);
2653 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2658 static int vino_set_input(struct vino_channel_settings *vcs, int input)
2660 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2661 &vino_drvdata->b : &vino_drvdata->a;
2662 unsigned long flags;
2665 dprintk("vino_set_input():\n");
2667 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2669 if (vcs->input == input)
2673 case VINO_INPUT_COMPOSITE:
2674 case VINO_INPUT_SVIDEO:
2675 if (!vino_drvdata->decoder.driver) {
2680 if (vino_drvdata->decoder.owner == VINO_NO_CHANNEL) {
2681 i2c_use_client(vino_drvdata->decoder.driver);
2682 vino_drvdata->decoder.owner = vcs->channel;
2685 if (vino_drvdata->decoder.owner == vcs->channel) {
2689 saa7191_input = vino_get_saa7191_input(input);
2690 ret = i2c_decoder_command(DECODER_SET_INPUT,
2693 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2698 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2700 /* Don't hold spinlocks while auto-detecting norm
2701 * as it may take a while... */
2703 data_norm = VINO_DATA_NORM_AUTO_EXT;
2705 ret = vino_saa7191_set_norm(&data_norm);
2706 if ((ret == -EBUSY) || (ret == -EAGAIN)) {
2707 data_norm = VINO_DATA_NORM_PAL;
2708 ret = vino_saa7191_set_norm(&data_norm);
2711 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2714 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2720 vcs->data_norm = data_norm;
2722 if (input != vcs2->input) {
2728 vcs->data_norm = vcs2->data_norm;
2731 if (vino_drvdata->camera.owner == vcs->channel) {
2732 /* Transfer the ownership or release the input */
2733 if (vcs2->input == VINO_INPUT_D1) {
2734 vino_drvdata->camera.owner = vcs2->channel;
2736 i2c_release_client(vino_drvdata->
2738 vino_drvdata->camera.owner = VINO_NO_CHANNEL;
2743 if (!vino_drvdata->camera.driver) {
2748 if (vino_drvdata->camera.owner == VINO_NO_CHANNEL) {
2749 i2c_use_client(vino_drvdata->camera.driver);
2750 vino_drvdata->camera.owner = vcs->channel;
2753 if (vino_drvdata->decoder.owner == vcs->channel) {
2754 /* Transfer the ownership or release the input */
2755 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2756 (vcs2->input == VINO_INPUT_SVIDEO)) {
2757 vino_drvdata->decoder.owner = vcs2->channel;
2759 i2c_release_client(vino_drvdata->
2761 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2766 vcs->data_norm = VINO_DATA_NORM_D1;
2773 vino_set_default_clipping(vcs);
2774 vino_set_default_scaling(vcs);
2775 vino_set_default_framerate(vcs);
2777 dprintk("vino_set_input(): %s\n", vino_inputs[vcs->input].name);
2780 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2785 static void vino_release_input(struct vino_channel_settings *vcs)
2787 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2788 &vino_drvdata->b : &vino_drvdata->a;
2789 unsigned long flags;
2791 dprintk("vino_release_input():\n");
2793 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2795 /* Release ownership of the channel
2796 * and if the other channel takes input from
2797 * the same source, transfer the ownership */
2798 if (vino_drvdata->camera.owner == vcs->channel) {
2799 if (vcs2->input == VINO_INPUT_D1) {
2800 vino_drvdata->camera.owner = vcs2->channel;
2802 i2c_release_client(vino_drvdata->camera.driver);
2803 vino_drvdata->camera.owner = VINO_NO_CHANNEL;
2805 } else if (vino_drvdata->decoder.owner == vcs->channel) {
2806 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2807 (vcs2->input == VINO_INPUT_SVIDEO)) {
2808 vino_drvdata->decoder.owner = vcs2->channel;
2810 i2c_release_client(vino_drvdata->decoder.driver);
2811 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2814 vcs->input = VINO_INPUT_NONE;
2816 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2819 /* execute with input_lock locked */
2820 static int vino_set_data_norm(struct vino_channel_settings *vcs,
2821 unsigned int data_norm,
2822 unsigned long *flags)
2826 if (data_norm == vcs->data_norm)
2829 switch (vcs->input) {
2831 /* only one "norm" supported */
2832 if ((data_norm != VINO_DATA_NORM_D1)
2833 && (data_norm != VINO_DATA_NORM_AUTO)
2834 && (data_norm != VINO_DATA_NORM_AUTO_EXT))
2837 case VINO_INPUT_COMPOSITE:
2838 case VINO_INPUT_SVIDEO: {
2839 if ((data_norm != VINO_DATA_NORM_PAL)
2840 && (data_norm != VINO_DATA_NORM_NTSC)
2841 && (data_norm != VINO_DATA_NORM_SECAM)
2842 && (data_norm != VINO_DATA_NORM_AUTO)
2843 && (data_norm != VINO_DATA_NORM_AUTO_EXT))
2846 spin_unlock_irqrestore(&vino_drvdata->input_lock, *flags);
2848 /* Don't hold spinlocks while setting norm
2849 * as it may take a while... */
2851 err = vino_saa7191_set_norm(&data_norm);
2853 spin_lock_irqsave(&vino_drvdata->input_lock, *flags);
2858 vcs->data_norm = data_norm;
2860 vino_set_default_clipping(vcs);
2861 vino_set_default_scaling(vcs);
2862 vino_set_default_framerate(vcs);
2873 /* V4L2 helper functions */
2875 static int vino_find_data_format(__u32 pixelformat)
2879 for (i = 0; i < VINO_DATA_FMT_COUNT; i++) {
2880 if (vino_data_formats[i].pixelformat == pixelformat)
2884 return VINO_DATA_FMT_NONE;
2887 static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index)
2889 int data_norm = VINO_DATA_NORM_NONE;
2890 unsigned long flags;
2892 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2893 switch(vcs->input) {
2894 case VINO_INPUT_COMPOSITE:
2895 case VINO_INPUT_SVIDEO:
2897 data_norm = VINO_DATA_NORM_PAL;
2898 } else if (index == 1) {
2899 data_norm = VINO_DATA_NORM_NTSC;
2900 } else if (index == 2) {
2901 data_norm = VINO_DATA_NORM_SECAM;
2906 data_norm = VINO_DATA_NORM_D1;
2910 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2915 static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
2917 int input = VINO_INPUT_NONE;
2918 unsigned long flags;
2920 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2921 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
2924 input = VINO_INPUT_COMPOSITE;
2927 input = VINO_INPUT_SVIDEO;
2930 input = VINO_INPUT_D1;
2933 } else if (vino_drvdata->decoder.driver) {
2936 input = VINO_INPUT_COMPOSITE;
2939 input = VINO_INPUT_SVIDEO;
2942 } else if (vino_drvdata->camera.driver) {
2945 input = VINO_INPUT_D1;
2949 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2954 /* execute with input_lock locked */
2955 static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
2958 // FIXME: detect when no inputs available
2960 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
2961 switch (vcs->input) {
2962 case VINO_INPUT_COMPOSITE:
2965 case VINO_INPUT_SVIDEO:
2972 } else if (vino_drvdata->decoder.driver) {
2973 switch (vcs->input) {
2974 case VINO_INPUT_COMPOSITE:
2977 case VINO_INPUT_SVIDEO:
2981 } else if (vino_drvdata->camera.driver) {
2982 switch (vcs->input) {
2994 static void vino_v4l2_querycap(struct v4l2_capability *cap)
2996 memset(cap, 0, sizeof(struct v4l2_capability));
2998 strcpy(cap->driver, vino_driver_name);
2999 strcpy(cap->card, vino_driver_description);
3000 strcpy(cap->bus_info, vino_bus_name);
3001 cap->version = VINO_VERSION_CODE;
3003 V4L2_CAP_VIDEO_CAPTURE |
3005 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
3008 static int vino_v4l2_enuminput(struct vino_channel_settings *vcs,
3009 struct v4l2_input *i)
3011 __u32 index = i->index;
3013 dprintk("requested index = %d\n", index);
3015 input = vino_enum_input(vcs, index);
3016 if (input == VINO_INPUT_NONE)
3019 memset(i, 0, sizeof(struct v4l2_input));
3022 i->type = V4L2_INPUT_TYPE_CAMERA;
3023 i->std = vino_inputs[input].std;
3024 strcpy(i->name, vino_inputs[input].name);
3026 if ((input == VINO_INPUT_COMPOSITE)
3027 || (input == VINO_INPUT_SVIDEO)) {
3028 struct saa7191_status status;
3029 i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
3030 i->status |= status.signal ? 0 : V4L2_IN_ST_NO_SIGNAL;
3031 i->status |= status.color ? 0 : V4L2_IN_ST_NO_COLOR;
3037 static int vino_v4l2_g_input(struct vino_channel_settings *vcs,
3042 unsigned long flags;
3044 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3046 index = vino_find_input_index(vcs);
3047 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3049 dprintk("input = %d\n", input);
3051 if (input == VINO_INPUT_NONE) {
3060 static int vino_v4l2_s_input(struct vino_channel_settings *vcs,
3064 dprintk("requested input = %d\n", *i);
3066 input = vino_enum_input(vcs, *i);
3067 if (input == VINO_INPUT_NONE)
3070 return vino_set_input(vcs, input);
3073 static int vino_v4l2_enumstd(struct vino_channel_settings *vcs,
3074 struct v4l2_standard *s)
3076 int index = s->index;
3079 data_norm = vino_enum_data_norm(vcs, index);
3080 dprintk("standard index = %d\n", index);
3082 if (data_norm == VINO_DATA_NORM_NONE)
3085 dprintk("standard name = %s\n",
3086 vino_data_norms[data_norm].description);
3088 memset(s, 0, sizeof(struct v4l2_standard));
3091 s->id = vino_data_norms[data_norm].std;
3092 s->frameperiod.numerator = 1;
3093 s->frameperiod.denominator =
3094 vino_data_norms[data_norm].fps_max;
3096 vino_data_norms[data_norm].framelines;
3098 vino_data_norms[data_norm].description);
3103 static int vino_v4l2_querystd(struct vino_channel_settings *vcs,
3106 unsigned long flags;
3109 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3111 switch (vcs->input) {
3113 *std = vino_inputs[vcs->input].std;
3115 case VINO_INPUT_COMPOSITE:
3116 case VINO_INPUT_SVIDEO: {
3117 struct saa7191_status status;
3119 i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
3121 if (status.signal) {
3122 if (status.signal_60hz) {
3123 *std = V4L2_STD_NTSC;
3125 *std = V4L2_STD_PAL | V4L2_STD_SECAM;
3128 *std = vino_inputs[vcs->input].std;
3136 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3141 static int vino_v4l2_g_std(struct vino_channel_settings *vcs,
3144 unsigned long flags;
3146 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3148 *std = vino_data_norms[vcs->data_norm].std;
3149 dprintk("current standard = %d\n", vcs->data_norm);
3151 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3156 static int vino_v4l2_s_std(struct vino_channel_settings *vcs,
3159 unsigned long flags;
3162 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3164 if (!vino_is_input_owner(vcs)) {
3169 /* check if the standard is valid for the current input */
3170 if ((*std) & vino_inputs[vcs->input].std) {
3171 dprintk("standard accepted\n");
3173 /* change the video norm for SAA7191
3174 * and accept NTSC for D1 (do nothing) */
3176 if (vcs->input == VINO_INPUT_D1)
3179 if (((*std) & V4L2_STD_PAL)
3180 && ((*std) & V4L2_STD_NTSC)
3181 && ((*std) & V4L2_STD_SECAM)) {
3182 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_AUTO_EXT,
3184 } else if ((*std) & V4L2_STD_PAL) {
3185 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_PAL,
3187 } else if ((*std) & V4L2_STD_NTSC) {
3188 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC,
3190 } else if ((*std) & V4L2_STD_SECAM) {
3191 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM,
3205 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3210 static int vino_v4l2_enum_fmt(struct vino_channel_settings *vcs,
3211 struct v4l2_fmtdesc *fd)
3213 enum v4l2_buf_type type = fd->type;
3214 int index = fd->index;
3215 dprintk("format index = %d\n", index);
3218 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3219 if ((fd->index < 0) ||
3220 (fd->index >= VINO_DATA_FMT_COUNT))
3222 dprintk("format name = %s\n",
3223 vino_data_formats[index].description);
3225 memset(fd, 0, sizeof(struct v4l2_fmtdesc));
3228 fd->pixelformat = vino_data_formats[index].pixelformat;
3229 strcpy(fd->description, vino_data_formats[index].description);
3231 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3239 static int vino_v4l2_try_fmt(struct vino_channel_settings *vcs,
3240 struct v4l2_format *f)
3242 struct vino_channel_settings tempvcs;
3243 unsigned long flags;
3246 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3247 struct v4l2_pix_format *pf = &f->fmt.pix;
3249 dprintk("requested: w = %d, h = %d\n",
3250 pf->width, pf->height);
3252 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3253 memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings));
3254 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3256 tempvcs.data_format = vino_find_data_format(pf->pixelformat);
3257 if (tempvcs.data_format == VINO_DATA_FMT_NONE) {
3258 tempvcs.data_format = VINO_DATA_FMT_GREY;
3260 vino_data_formats[tempvcs.data_format].
3264 /* data format must be set before clipping/scaling */
3265 vino_set_scaling(&tempvcs, pf->width, pf->height);
3267 dprintk("data format = %s\n",
3268 vino_data_formats[tempvcs.data_format].description);
3270 pf->width = (tempvcs.clipping.right - tempvcs.clipping.left) /
3272 pf->height = (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3275 pf->field = V4L2_FIELD_INTERLACED;
3276 pf->bytesperline = tempvcs.line_size;
3277 pf->sizeimage = tempvcs.line_size *
3278 (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3281 vino_data_formats[tempvcs.data_format].colorspace;
3286 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3294 static int vino_v4l2_g_fmt(struct vino_channel_settings *vcs,
3295 struct v4l2_format *f)
3297 unsigned long flags;
3300 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3301 struct v4l2_pix_format *pf = &f->fmt.pix;
3303 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3305 pf->width = (vcs->clipping.right - vcs->clipping.left) /
3307 pf->height = (vcs->clipping.bottom - vcs->clipping.top) /
3310 vino_data_formats[vcs->data_format].pixelformat;
3312 pf->field = V4L2_FIELD_INTERLACED;
3313 pf->bytesperline = vcs->line_size;
3314 pf->sizeimage = vcs->line_size *
3315 (vcs->clipping.bottom - vcs->clipping.top) /
3318 vino_data_formats[vcs->data_format].colorspace;
3322 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3325 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3333 static int vino_v4l2_s_fmt(struct vino_channel_settings *vcs,
3334 struct v4l2_format *f)
3337 unsigned long flags;
3340 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3341 struct v4l2_pix_format *pf = &f->fmt.pix;
3343 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3345 data_format = vino_find_data_format(pf->pixelformat);
3347 if (data_format == VINO_DATA_FMT_NONE) {
3348 vcs->data_format = VINO_DATA_FMT_GREY;
3350 vino_data_formats[vcs->data_format].
3353 vcs->data_format = data_format;
3356 /* data format must be set before clipping/scaling */
3357 vino_set_scaling(vcs, pf->width, pf->height);
3359 dprintk("data format = %s\n",
3360 vino_data_formats[vcs->data_format].description);
3362 pf->width = vcs->clipping.right - vcs->clipping.left;
3363 pf->height = vcs->clipping.bottom - vcs->clipping.top;
3365 pf->field = V4L2_FIELD_INTERLACED;
3366 pf->bytesperline = vcs->line_size;
3367 pf->sizeimage = vcs->line_size *
3368 (vcs->clipping.bottom - vcs->clipping.top) /
3371 vino_data_formats[vcs->data_format].colorspace;
3375 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3378 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3386 static int vino_v4l2_cropcap(struct vino_channel_settings *vcs,
3387 struct v4l2_cropcap *ccap)
3389 const struct vino_data_norm *norm;
3390 unsigned long flags;
3392 switch (ccap->type) {
3393 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3394 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3396 norm = &vino_data_norms[vcs->data_norm];
3398 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3400 ccap->bounds.left = 0;
3401 ccap->bounds.top = 0;
3402 ccap->bounds.width = norm->width;
3403 ccap->bounds.height = norm->height;
3404 memcpy(&ccap->defrect, &ccap->bounds,
3405 sizeof(struct v4l2_rect));
3407 ccap->pixelaspect.numerator = 1;
3408 ccap->pixelaspect.denominator = 1;
3410 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3418 static int vino_v4l2_g_crop(struct vino_channel_settings *vcs,
3419 struct v4l2_crop *c)
3421 unsigned long flags;
3424 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3425 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3427 c->c.left = vcs->clipping.left;
3428 c->c.top = vcs->clipping.top;
3429 c->c.width = vcs->clipping.right - vcs->clipping.left;
3430 c->c.height = vcs->clipping.bottom - vcs->clipping.top;
3432 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3434 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3442 static int vino_v4l2_s_crop(struct vino_channel_settings *vcs,
3443 struct v4l2_crop *c)
3445 unsigned long flags;
3448 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3449 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3451 vino_set_clipping(vcs, c->c.left, c->c.top,
3452 c->c.width, c->c.height);
3454 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3456 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3464 static int vino_v4l2_g_parm(struct vino_channel_settings *vcs,
3465 struct v4l2_streamparm *sp)
3467 unsigned long flags;
3470 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3471 struct v4l2_captureparm *cp = &sp->parm.capture;
3472 memset(cp, 0, sizeof(struct v4l2_captureparm));
3474 cp->capability = V4L2_CAP_TIMEPERFRAME;
3475 cp->timeperframe.numerator = 1;
3477 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3479 cp->timeperframe.denominator = vcs->fps;
3481 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3483 // TODO: cp->readbuffers = xxx;
3486 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3494 static int vino_v4l2_s_parm(struct vino_channel_settings *vcs,
3495 struct v4l2_streamparm *sp)
3497 unsigned long flags;
3500 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3501 struct v4l2_captureparm *cp = &sp->parm.capture;
3503 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3505 if ((cp->timeperframe.numerator == 0) ||
3506 (cp->timeperframe.denominator == 0)) {
3507 /* reset framerate */
3508 vino_set_default_framerate(vcs);
3510 vino_set_framerate(vcs, cp->timeperframe.denominator /
3511 cp->timeperframe.numerator);
3514 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3516 // TODO: set buffers according to cp->readbuffers
3519 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3527 static int vino_v4l2_reqbufs(struct vino_channel_settings *vcs,
3528 struct v4l2_requestbuffers *rb)
3534 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3535 // TODO: check queue type
3536 if (rb->memory != V4L2_MEMORY_MMAP) {
3537 dprintk("type not mmap\n");
3541 dprintk("count = %d\n", rb->count);
3542 if (rb->count > 0) {
3543 if (vino_is_capturing(vcs)) {
3544 dprintk("busy, capturing\n");
3548 if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) {
3549 dprintk("busy, buffers still mapped\n");
3553 vino_queue_free(&vcs->fb_queue);
3554 vino_queue_init(&vcs->fb_queue, &rb->count);
3558 vino_capture_stop(vcs);
3559 vino_queue_free(&vcs->fb_queue);
3563 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3571 static void vino_v4l2_get_buffer_status(struct vino_channel_settings *vcs,
3572 struct vino_framebuffer *fb,
3573 struct v4l2_buffer *b)
3575 if (vino_queue_outgoing_contains(&vcs->fb_queue,
3577 b->flags &= ~V4L2_BUF_FLAG_QUEUED;
3578 b->flags |= V4L2_BUF_FLAG_DONE;
3579 } else if (vino_queue_incoming_contains(&vcs->fb_queue,
3581 b->flags &= ~V4L2_BUF_FLAG_DONE;
3582 b->flags |= V4L2_BUF_FLAG_QUEUED;
3584 b->flags &= ~(V4L2_BUF_FLAG_DONE |
3585 V4L2_BUF_FLAG_QUEUED);
3588 b->flags &= ~(V4L2_BUF_FLAG_TIMECODE);
3590 if (fb->map_count > 0)
3591 b->flags |= V4L2_BUF_FLAG_MAPPED;
3594 b->memory = (vcs->fb_queue.type == VINO_MEMORY_MMAP) ?
3595 V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
3596 b->m.offset = fb->offset;
3597 b->bytesused = fb->data_size;
3598 b->length = fb->size;
3599 b->field = V4L2_FIELD_INTERLACED;
3600 b->sequence = fb->frame_counter;
3601 memcpy(&b->timestamp, &fb->timestamp,
3602 sizeof(struct timeval));
3605 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3606 fb->id, fb->size, fb->data_size, fb->offset);
3609 static int vino_v4l2_querybuf(struct vino_channel_settings *vcs,
3610 struct v4l2_buffer *b)
3616 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3617 struct vino_framebuffer *fb;
3619 // TODO: check queue type
3620 if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
3621 dprintk("invalid index = %d\n",
3626 fb = vino_queue_get_buffer(&vcs->fb_queue,
3629 dprintk("vino_queue_get_buffer() failed");
3633 vino_v4l2_get_buffer_status(vcs, fb, b);
3636 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3644 static int vino_v4l2_qbuf(struct vino_channel_settings *vcs,
3645 struct v4l2_buffer *b)
3651 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3652 struct vino_framebuffer *fb;
3655 // TODO: check queue type
3656 if (b->memory != V4L2_MEMORY_MMAP) {
3657 dprintk("type not mmap\n");
3661 fb = vino_capture_enqueue(vcs, b->index);
3665 vino_v4l2_get_buffer_status(vcs, fb, b);
3667 if (vcs->streaming) {
3668 ret = vino_capture_next(vcs, 1);
3674 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3682 static int vino_v4l2_dqbuf(struct vino_channel_settings *vcs,
3683 struct v4l2_buffer *b,
3684 unsigned int nonblocking)
3690 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3691 struct vino_framebuffer *fb;
3692 unsigned int incoming, outgoing;
3695 // TODO: check queue type
3697 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3699 dprintk("vino_queue_get_incoming() failed\n");
3702 err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing);
3704 dprintk("vino_queue_get_outgoing() failed\n");
3708 dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing);
3710 if (outgoing == 0) {
3711 if (incoming == 0) {
3712 dprintk("no incoming or outgoing buffers\n");
3716 dprintk("non-blocking I/O was selected and "
3717 "there are no buffers to dequeue\n");
3721 err = vino_wait_for_frame(vcs);
3723 err = vino_wait_for_frame(vcs);
3726 * no frames captured because
3727 * of frame skipping */
3728 // vino_capture_failed(vcs);
3734 fb = vino_queue_remove(&vcs->fb_queue, &b->index);
3736 dprintk("vino_queue_remove() failed\n");
3740 err = vino_check_buffer(vcs, fb);
3742 vino_v4l2_get_buffer_status(vcs, fb, b);
3749 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3757 static int vino_v4l2_streamon(struct vino_channel_settings *vcs)
3759 unsigned int incoming;
3767 // TODO: check queue type
3769 if (vino_queue_get_length(&vcs->fb_queue) < 1) {
3770 dprintk("no buffers allocated\n");
3774 ret = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3776 dprintk("vino_queue_get_incoming() failed\n");
3783 ret = vino_capture_next(vcs, 1);
3787 dprintk("couldn't start capture\n");
3795 static int vino_v4l2_streamoff(struct vino_channel_settings *vcs)
3800 if (!vcs->streaming)
3804 vino_capture_stop(vcs);
3809 static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3810 struct v4l2_queryctrl *queryctrl)
3812 unsigned long flags;
3816 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3818 switch (vcs->input) {
3820 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3821 if (vino_indycam_v4l2_controls[i].id ==
3824 &vino_indycam_v4l2_controls[i],
3825 sizeof(struct v4l2_queryctrl));
3826 queryctrl->reserved[0] = 0;
3833 case VINO_INPUT_COMPOSITE:
3834 case VINO_INPUT_SVIDEO:
3835 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3836 if (vino_saa7191_v4l2_controls[i].id ==
3839 &vino_saa7191_v4l2_controls[i],
3840 sizeof(struct v4l2_queryctrl));
3841 queryctrl->reserved[0] = 0;
3853 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3858 static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs,
3859 struct v4l2_control *control)
3861 unsigned long flags;
3865 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3867 switch (vcs->input) {
3868 case VINO_INPUT_D1: {
3869 struct indycam_control indycam_ctrl;
3871 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3872 if (vino_indycam_v4l2_controls[i].id ==
3882 indycam_ctrl.type = vino_indycam_v4l2_controls[i].reserved[0];
3884 err = i2c_camera_command(DECODER_INDYCAM_GET_CONTROL,
3891 control->value = indycam_ctrl.value;
3894 case VINO_INPUT_COMPOSITE:
3895 case VINO_INPUT_SVIDEO: {
3896 struct saa7191_control saa7191_ctrl;
3898 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3899 if (vino_saa7191_v4l2_controls[i].id ==
3909 saa7191_ctrl.type = vino_saa7191_v4l2_controls[i].reserved[0];
3911 err = i2c_decoder_command(DECODER_SAA7191_GET_CONTROL,
3918 control->value = saa7191_ctrl.value;
3926 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3931 static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs,
3932 struct v4l2_control *control)
3934 unsigned long flags;
3938 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3940 if (!vino_is_input_owner(vcs)) {
3945 switch (vcs->input) {
3946 case VINO_INPUT_D1: {
3947 struct indycam_control indycam_ctrl;
3949 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3950 if (vino_indycam_v4l2_controls[i].id ==
3952 if ((control->value >=
3953 vino_indycam_v4l2_controls[i].minimum)
3954 && (control->value <=
3955 vino_indycam_v4l2_controls[i].
3969 indycam_ctrl.type = vino_indycam_v4l2_controls[i].reserved[0];
3970 indycam_ctrl.value = control->value;
3972 err = i2c_camera_command(DECODER_INDYCAM_SET_CONTROL,
3978 case VINO_INPUT_COMPOSITE:
3979 case VINO_INPUT_SVIDEO: {
3980 struct saa7191_control saa7191_ctrl;
3982 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3983 if (vino_saa7191_v4l2_controls[i].id ==
3985 if ((control->value >=
3986 vino_saa7191_v4l2_controls[i].minimum)
3987 && (control->value <=
3988 vino_saa7191_v4l2_controls[i].
4001 saa7191_ctrl.type = vino_saa7191_v4l2_controls[i].reserved[0];
4002 saa7191_ctrl.value = control->value;
4004 err = i2c_decoder_command(DECODER_SAA7191_SET_CONTROL,
4015 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
4020 /* File operations */
4022 static int vino_open(struct inode *inode, struct file *file)
4024 struct vino_channel_settings *vcs = video_drvdata(file);
4026 dprintk("open(): channel = %c\n",
4027 (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B');
4029 mutex_lock(&vcs->mutex);
4032 dprintk("open(): driver busy\n");
4037 ret = vino_acquire_input(vcs);
4039 dprintk("open(): vino_acquire_input() failed\n");
4046 mutex_unlock(&vcs->mutex);
4048 dprintk("open(): %s!\n", ret ? "failed" : "complete");
4053 static int vino_close(struct inode *inode, struct file *file)
4055 struct vino_channel_settings *vcs = video_drvdata(file);
4056 dprintk("close():\n");
4058 mutex_lock(&vcs->mutex);
4063 vino_release_input(vcs);
4065 /* stop DMA and free buffers */
4066 vino_capture_stop(vcs);
4067 vino_queue_free(&vcs->fb_queue);
4070 mutex_unlock(&vcs->mutex);
4075 static void vino_vm_open(struct vm_area_struct *vma)
4077 struct vino_framebuffer *fb = vma->vm_private_data;
4080 dprintk("vino_vm_open(): count = %d\n", fb->map_count);
4083 static void vino_vm_close(struct vm_area_struct *vma)
4085 struct vino_framebuffer *fb = vma->vm_private_data;
4088 dprintk("vino_vm_close(): count = %d\n", fb->map_count);
4091 static struct vm_operations_struct vino_vm_ops = {
4092 .open = vino_vm_open,
4093 .close = vino_vm_close,
4096 static int vino_mmap(struct file *file, struct vm_area_struct *vma)
4098 struct vino_channel_settings *vcs = video_drvdata(file);
4100 unsigned long start = vma->vm_start;
4101 unsigned long size = vma->vm_end - vma->vm_start;
4102 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
4104 struct vino_framebuffer *fb = NULL;
4105 unsigned int i, length;
4108 dprintk("mmap():\n");
4110 // TODO: reject mmap if already mapped
4112 if (mutex_lock_interruptible(&vcs->mutex))
4120 // TODO: check queue type
4122 if (!(vma->vm_flags & VM_WRITE)) {
4123 dprintk("mmap(): app bug: PROT_WRITE please\n");
4127 if (!(vma->vm_flags & VM_SHARED)) {
4128 dprintk("mmap(): app bug: MAP_SHARED please\n");
4133 /* find the correct buffer using offset */
4134 length = vino_queue_get_length(&vcs->fb_queue);
4136 dprintk("mmap(): queue not initialized\n");
4141 for (i = 0; i < length; i++) {
4142 fb = vino_queue_get_buffer(&vcs->fb_queue, i);
4144 dprintk("mmap(): vino_queue_get_buffer() failed\n");
4149 if (fb->offset == offset)
4153 dprintk("mmap(): invalid offset = %lu\n", offset);
4158 dprintk("mmap(): buffer = %d\n", i);
4160 if (size > (fb->desc_table.page_count * PAGE_SIZE)) {
4161 dprintk("mmap(): failed: size = %lu > %lu\n",
4162 size, fb->desc_table.page_count * PAGE_SIZE);
4167 for (i = 0; i < fb->desc_table.page_count; i++) {
4169 virt_to_phys((void *)fb->desc_table.virtual[i]) >>
4172 if (size < PAGE_SIZE)
4175 // protection was: PAGE_READONLY
4176 if (remap_pfn_range(vma, start, pfn, PAGE_SIZE,
4177 vma->vm_page_prot)) {
4178 dprintk("mmap(): remap_pfn_range() failed\n");
4189 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
4190 vma->vm_flags &= ~VM_IO;
4191 vma->vm_private_data = fb;
4192 vma->vm_file = file;
4193 vma->vm_ops = &vino_vm_ops;
4196 mutex_unlock(&vcs->mutex);
4201 static unsigned int vino_poll(struct file *file, poll_table *pt)
4203 struct vino_channel_settings *vcs = video_drvdata(file);
4204 unsigned int outgoing;
4205 unsigned int ret = 0;
4208 // TODO: this has to be corrected for different read modes
4210 dprintk("poll():\n");
4212 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
4213 dprintk("poll(): vino_queue_get_outgoing() failed\n");
4220 poll_wait(file, &vcs->fb_queue.frame_wait_queue, pt);
4222 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
4223 dprintk("poll(): vino_queue_get_outgoing() failed\n");
4229 dprintk("poll(): data %savailable\n",
4230 (outgoing > 0) ? "" : "not ");
4233 ret = POLLIN | POLLRDNORM;
4240 static int vino_do_ioctl(struct inode *inode, struct file *file,
4241 unsigned int cmd, void *arg)
4243 struct vino_channel_settings *vcs = video_drvdata(file);
4246 switch (_IOC_TYPE(cmd)) {
4248 dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd);
4251 dprintk("ioctl(): V4L2 %s (0x%08x)\n",
4252 v4l2_ioctl_names[_IOC_NR(cmd)], cmd);
4255 dprintk("ioctl(): unsupported command 0x%08x\n", cmd);
4260 /* V4L2 interface */
4261 case VIDIOC_QUERYCAP: {
4262 vino_v4l2_querycap(arg);
4265 case VIDIOC_ENUMINPUT: {
4266 return vino_v4l2_enuminput(vcs, arg);
4268 case VIDIOC_G_INPUT: {
4269 return vino_v4l2_g_input(vcs, arg);
4271 case VIDIOC_S_INPUT: {
4272 return vino_v4l2_s_input(vcs, arg);
4274 case VIDIOC_ENUMSTD: {
4275 return vino_v4l2_enumstd(vcs, arg);
4277 case VIDIOC_QUERYSTD: {
4278 return vino_v4l2_querystd(vcs, arg);
4280 case VIDIOC_G_STD: {
4281 return vino_v4l2_g_std(vcs, arg);
4283 case VIDIOC_S_STD: {
4284 return vino_v4l2_s_std(vcs, arg);
4286 case VIDIOC_ENUM_FMT: {
4287 return vino_v4l2_enum_fmt(vcs, arg);
4289 case VIDIOC_TRY_FMT: {
4290 return vino_v4l2_try_fmt(vcs, arg);
4292 case VIDIOC_G_FMT: {
4293 return vino_v4l2_g_fmt(vcs, arg);
4295 case VIDIOC_S_FMT: {
4296 return vino_v4l2_s_fmt(vcs, arg);
4298 case VIDIOC_CROPCAP: {
4299 return vino_v4l2_cropcap(vcs, arg);
4301 case VIDIOC_G_CROP: {
4302 return vino_v4l2_g_crop(vcs, arg);
4304 case VIDIOC_S_CROP: {
4305 return vino_v4l2_s_crop(vcs, arg);
4307 case VIDIOC_G_PARM: {
4308 return vino_v4l2_g_parm(vcs, arg);
4310 case VIDIOC_S_PARM: {
4311 return vino_v4l2_s_parm(vcs, arg);
4313 case VIDIOC_REQBUFS: {
4314 return vino_v4l2_reqbufs(vcs, arg);
4316 case VIDIOC_QUERYBUF: {
4317 return vino_v4l2_querybuf(vcs, arg);
4320 return vino_v4l2_qbuf(vcs, arg);
4322 case VIDIOC_DQBUF: {
4323 return vino_v4l2_dqbuf(vcs, arg, file->f_flags & O_NONBLOCK);
4325 case VIDIOC_STREAMON: {
4326 return vino_v4l2_streamon(vcs);
4328 case VIDIOC_STREAMOFF: {
4329 return vino_v4l2_streamoff(vcs);
4331 case VIDIOC_QUERYCTRL: {
4332 return vino_v4l2_queryctrl(vcs, arg);
4334 case VIDIOC_G_CTRL: {
4335 return vino_v4l2_g_ctrl(vcs, arg);
4337 case VIDIOC_S_CTRL: {
4338 return vino_v4l2_s_ctrl(vcs, arg);
4341 return -ENOIOCTLCMD;
4347 static int vino_ioctl(struct inode *inode, struct file *file,
4348 unsigned int cmd, unsigned long arg)
4350 struct vino_channel_settings *vcs = video_drvdata(file);
4353 if (mutex_lock_interruptible(&vcs->mutex))
4356 ret = video_usercopy(inode, file, cmd, arg, vino_do_ioctl);
4358 mutex_unlock(&vcs->mutex);
4363 /* Initialization and cleanup */
4366 static int vino_init_stage;
4368 static const struct file_operations vino_fops = {
4369 .owner = THIS_MODULE,
4371 .release = vino_close,
4372 .ioctl = vino_ioctl,
4375 .llseek = no_llseek,
4378 static struct video_device v4l_device_template = {
4384 static void vino_module_cleanup(int stage)
4388 video_unregister_device(vino_drvdata->b.v4l_device);
4389 vino_drvdata->b.v4l_device = NULL;
4391 video_unregister_device(vino_drvdata->a.v4l_device);
4392 vino_drvdata->a.v4l_device = NULL;
4396 free_irq(SGI_VINO_IRQ, NULL);
4398 if (vino_drvdata->b.v4l_device) {
4399 video_device_release(vino_drvdata->b.v4l_device);
4400 vino_drvdata->b.v4l_device = NULL;
4403 if (vino_drvdata->a.v4l_device) {
4404 video_device_release(vino_drvdata->a.v4l_device);
4405 vino_drvdata->a.v4l_device = NULL;
4408 /* all entries in dma_cpu dummy table have the same address */
4409 dma_unmap_single(NULL,
4410 vino_drvdata->dummy_desc_table.dma_cpu[0],
4411 PAGE_SIZE, DMA_FROM_DEVICE);
4412 dma_free_coherent(NULL, VINO_DUMMY_DESC_COUNT
4413 * sizeof(dma_addr_t),
4414 (void *)vino_drvdata->
4415 dummy_desc_table.dma_cpu,
4416 vino_drvdata->dummy_desc_table.dma);
4418 free_page(vino_drvdata->dummy_page);
4420 kfree(vino_drvdata);
4426 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4431 static int vino_probe(void)
4433 unsigned long rev_id;
4435 if (ip22_is_fullhouse()) {
4436 printk(KERN_ERR "VINO doesn't exist in IP22 Fullhouse\n");
4440 if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) {
4441 printk(KERN_ERR "VINO is not found (EISA BUS not present)\n");
4445 vino = (struct sgi_vino *)ioremap(VINO_BASE, sizeof(struct sgi_vino));
4447 printk(KERN_ERR "VINO: ioremap() failed\n");
4452 if (get_dbe(rev_id, &(vino->rev_id))) {
4453 printk(KERN_ERR "Failed to read VINO revision register\n");
4454 vino_module_cleanup(vino_init_stage);
4458 if (VINO_ID_VALUE(rev_id) != VINO_CHIP_ID) {
4459 printk(KERN_ERR "Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4461 vino_module_cleanup(vino_init_stage);
4465 printk(KERN_INFO "VINO revision %ld found\n", VINO_REV_NUM(rev_id));
4470 static int vino_init(void)
4472 dma_addr_t dma_dummy_address;
4475 vino_drvdata = kzalloc(sizeof(struct vino_settings), GFP_KERNEL);
4476 if (!vino_drvdata) {
4477 vino_module_cleanup(vino_init_stage);
4482 /* create a dummy dma descriptor */
4483 vino_drvdata->dummy_page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
4484 if (!vino_drvdata->dummy_page) {
4485 vino_module_cleanup(vino_init_stage);
4490 // TODO: use page_count in dummy_desc_table
4492 vino_drvdata->dummy_desc_table.dma_cpu =
4493 dma_alloc_coherent(NULL,
4494 VINO_DUMMY_DESC_COUNT * sizeof(dma_addr_t),
4495 &vino_drvdata->dummy_desc_table.dma,
4496 GFP_KERNEL | GFP_DMA);
4497 if (!vino_drvdata->dummy_desc_table.dma_cpu) {
4498 vino_module_cleanup(vino_init_stage);
4503 dma_dummy_address = dma_map_single(NULL,
4504 (void *)vino_drvdata->dummy_page,
4505 PAGE_SIZE, DMA_FROM_DEVICE);
4506 for (i = 0; i < VINO_DUMMY_DESC_COUNT; i++) {
4507 vino_drvdata->dummy_desc_table.dma_cpu[i] = dma_dummy_address;
4510 /* initialize VINO */
4513 vino->a.next_4_desc = vino_drvdata->dummy_desc_table.dma;
4514 vino->b.next_4_desc = vino_drvdata->dummy_desc_table.dma;
4515 udelay(VINO_DESC_FETCH_DELAY);
4517 vino->intr_status = 0;
4519 vino->a.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
4520 vino->b.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
4525 static int vino_init_channel_settings(struct vino_channel_settings *vcs,
4526 unsigned int channel, const char *name)
4528 vcs->channel = channel;
4529 vcs->input = VINO_INPUT_NONE;
4532 vcs->data_format = VINO_DATA_FMT_GREY;
4533 vcs->data_norm = VINO_DATA_NORM_NTSC;
4534 vcs->decimation = 1;
4535 vino_set_default_clipping(vcs);
4536 vino_set_default_framerate(vcs);
4540 mutex_init(&vcs->mutex);
4541 spin_lock_init(&vcs->capture_lock);
4543 mutex_init(&vcs->fb_queue.queue_mutex);
4544 spin_lock_init(&vcs->fb_queue.queue_lock);
4545 init_waitqueue_head(&vcs->fb_queue.frame_wait_queue);
4547 vcs->v4l_device = video_device_alloc();
4548 if (!vcs->v4l_device) {
4549 vino_module_cleanup(vino_init_stage);
4554 memcpy(vcs->v4l_device, &v4l_device_template,
4555 sizeof(struct video_device));
4556 strcpy(vcs->v4l_device->name, name);
4557 vcs->v4l_device->release = video_device_release;
4559 video_set_drvdata(vcs->v4l_device, vcs);
4564 static int __init vino_module_init(void)
4568 printk(KERN_INFO "SGI VINO driver version %s\n",
4569 VINO_MODULE_VERSION);
4579 /* initialize data structures */
4581 spin_lock_init(&vino_drvdata->vino_lock);
4582 spin_lock_init(&vino_drvdata->input_lock);
4584 ret = vino_init_channel_settings(&vino_drvdata->a, VINO_CHANNEL_A,
4585 vino_v4l_device_name_a);
4589 ret = vino_init_channel_settings(&vino_drvdata->b, VINO_CHANNEL_B,
4590 vino_v4l_device_name_b);
4594 /* initialize hardware and register V4L devices */
4596 ret = request_irq(SGI_VINO_IRQ, vino_interrupt, 0,
4597 vino_driver_description, NULL);
4599 printk(KERN_ERR "VINO: requesting IRQ %02d failed\n",
4601 vino_module_cleanup(vino_init_stage);
4606 ret = vino_i2c_add_bus();
4608 printk(KERN_ERR "VINO I2C bus registration failed\n");
4609 vino_module_cleanup(vino_init_stage);
4614 ret = video_register_device(vino_drvdata->a.v4l_device,
4615 VFL_TYPE_GRABBER, -1);
4617 printk(KERN_ERR "VINO channel A Video4Linux-device "
4618 "registration failed\n");
4619 vino_module_cleanup(vino_init_stage);
4624 ret = video_register_device(vino_drvdata->b.v4l_device,
4625 VFL_TYPE_GRABBER, -1);
4627 printk(KERN_ERR "VINO channel B Video4Linux-device "
4628 "registration failed\n");
4629 vino_module_cleanup(vino_init_stage);
4635 request_module("saa7191");
4636 request_module("indycam");
4639 dprintk("init complete!\n");
4644 static void __exit vino_module_exit(void)
4646 dprintk("exiting, stage = %d ...\n", vino_init_stage);
4647 vino_module_cleanup(vino_init_stage);
4648 dprintk("cleanup complete, exit!\n");
4651 module_init(vino_module_init);
4652 module_exit(vino_module_exit);