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>
35 #include <linux/kmod.h>
38 #include <linux/i2c.h>
39 #include <linux/i2c-algo-sgi.h>
41 #include <linux/videodev2.h>
42 #include <media/v4l2-ioctl.h>
43 #include <media/v4l2-common.h>
44 #include <media/v4l2-ioctl.h>
45 #include <linux/video_decoder.h>
46 #include <linux/mutex.h>
48 #include <asm/paccess.h>
50 #include <asm/sgi/ip22.h>
51 #include <asm/sgi/mc.h>
57 /* Uncomment the following line to get lots and lots of (mostly useless)
59 * Note that the debug output also slows down the driver significantly */
61 // #define VINO_DEBUG_INT
63 #define VINO_MODULE_VERSION "0.0.5"
64 #define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 5)
66 MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
67 MODULE_VERSION(VINO_MODULE_VERSION);
68 MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
69 MODULE_LICENSE("GPL");
72 #define dprintk(x...) printk("VINO: " x);
77 #define VINO_NO_CHANNEL 0
78 #define VINO_CHANNEL_A 1
79 #define VINO_CHANNEL_B 2
81 #define VINO_PAL_WIDTH 768
82 #define VINO_PAL_HEIGHT 576
83 #define VINO_NTSC_WIDTH 640
84 #define VINO_NTSC_HEIGHT 480
86 #define VINO_MIN_WIDTH 32
87 #define VINO_MIN_HEIGHT 32
89 #define VINO_CLIPPING_START_ODD_D1 1
90 #define VINO_CLIPPING_START_ODD_PAL 15
91 #define VINO_CLIPPING_START_ODD_NTSC 12
93 #define VINO_CLIPPING_START_EVEN_D1 2
94 #define VINO_CLIPPING_START_EVEN_PAL 15
95 #define VINO_CLIPPING_START_EVEN_NTSC 12
97 #define VINO_INPUT_CHANNEL_COUNT 3
99 /* the number is the index for vino_inputs */
100 #define VINO_INPUT_NONE -1
101 #define VINO_INPUT_COMPOSITE 0
102 #define VINO_INPUT_SVIDEO 1
103 #define VINO_INPUT_D1 2
105 #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
107 #define VINO_FIFO_THRESHOLD_DEFAULT 16
109 #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
110 * VINO_PAL_HEIGHT * 4 \
111 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
113 #define VINO_FRAMEBUFFER_COUNT_MAX 8
115 #define VINO_FRAMEBUFFER_UNUSED 0
116 #define VINO_FRAMEBUFFER_IN_USE 1
117 #define VINO_FRAMEBUFFER_READY 2
119 #define VINO_QUEUE_ERROR -1
120 #define VINO_QUEUE_MAGIC 0x20050125
122 #define VINO_MEMORY_NONE 0
123 #define VINO_MEMORY_MMAP 1
124 #define VINO_MEMORY_USERPTR 2
126 #define VINO_DUMMY_DESC_COUNT 4
127 #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
129 #define VINO_MAX_FRAME_SKIP_COUNT 128
131 /* the number is the index for vino_data_formats */
132 #define VINO_DATA_FMT_NONE -1
133 #define VINO_DATA_FMT_GREY 0
134 #define VINO_DATA_FMT_RGB332 1
135 #define VINO_DATA_FMT_RGB32 2
136 #define VINO_DATA_FMT_YUV 3
138 #define VINO_DATA_FMT_COUNT 4
140 /* the number is the index for vino_data_norms */
141 #define VINO_DATA_NORM_NONE -1
142 #define VINO_DATA_NORM_NTSC 0
143 #define VINO_DATA_NORM_PAL 1
144 #define VINO_DATA_NORM_SECAM 2
145 #define VINO_DATA_NORM_D1 3
146 /* The following are special entries that can be used to
147 * autodetect the norm. */
148 #define VINO_DATA_NORM_AUTO 0xfe
149 #define VINO_DATA_NORM_AUTO_EXT 0xff
151 #define VINO_DATA_NORM_COUNT 4
153 /* Internal data structure definitions */
160 struct vino_clipping {
161 unsigned int left, right, top, bottom;
164 struct vino_data_format {
165 /* the description */
167 /* bytes per pixel */
169 /* V4L2 fourcc code */
171 /* V4L2 colorspace (duh!) */
172 enum v4l2_colorspace colorspace;
175 struct vino_data_norm {
177 unsigned int width, height;
178 struct vino_clipping odd;
179 struct vino_clipping even;
182 unsigned int fps_min, fps_max;
186 struct vino_descriptor_table {
187 /* the number of PAGE_SIZE sized pages in the buffer */
188 unsigned int page_count;
189 /* virtual (kmalloc'd) pointers to the actual data
190 * (in PAGE_SIZE chunks, used with mmap streaming) */
191 unsigned long *virtual;
193 /* cpu address for the VINO descriptor table
194 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
195 unsigned long *dma_cpu;
196 /* dma address for the VINO descriptor table
197 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
201 struct vino_framebuffer {
202 /* identifier nubmer */
204 /* the length of the whole buffer */
206 /* the length of actual data in buffer */
207 unsigned int data_size;
208 /* the data format */
209 unsigned int data_format;
210 /* the state of buffer data */
212 /* is the buffer mapped in user space? */
213 unsigned int map_count;
214 /* memory offset for mmap() */
217 unsigned int frame_counter;
218 /* timestamp (written when image capture finishes) */
219 struct timeval timestamp;
221 struct vino_descriptor_table desc_table;
223 spinlock_t state_lock;
226 struct vino_framebuffer_fifo {
233 unsigned int data[VINO_FRAMEBUFFER_COUNT_MAX];
236 struct vino_framebuffer_queue {
239 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
243 /* data field of in and out contain index numbers for buffer */
244 struct vino_framebuffer_fifo in;
245 struct vino_framebuffer_fifo out;
247 struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_COUNT_MAX];
249 spinlock_t queue_lock;
250 struct mutex queue_mutex;
251 wait_queue_head_t frame_wait_queue;
254 struct vino_interrupt_data {
255 struct timeval timestamp;
256 unsigned int frame_counter;
257 unsigned int skip_count;
261 struct vino_channel_settings {
262 unsigned int channel;
265 unsigned int data_format;
266 unsigned int data_norm;
267 struct vino_clipping clipping;
268 unsigned int decimation;
269 unsigned int line_size;
272 unsigned int framert_reg;
274 unsigned int fifo_threshold;
276 struct vino_framebuffer_queue fb_queue;
278 /* number of the current field */
281 /* read in progress */
283 /* streaming is active */
285 /* the driver is currently processing the queue */
289 spinlock_t capture_lock;
293 struct vino_interrupt_data int_data;
296 struct video_device *v4l_device;
300 /* the channel which owns this client:
301 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
303 struct i2c_client *driver;
306 struct vino_settings {
307 struct vino_channel_settings a;
308 struct vino_channel_settings b;
310 struct vino_client decoder;
311 struct vino_client camera;
313 /* a lock for vino register access */
314 spinlock_t vino_lock;
315 /* a lock for channel input changes */
316 spinlock_t input_lock;
318 unsigned long dummy_page;
319 struct vino_descriptor_table dummy_desc_table;
322 /* Module parameters */
325 * Using vino_pixel_conversion the ABGR32-format pixels supplied
326 * by the VINO chip can be converted to more common formats
327 * like RGBA32 (or probably RGB24 in the future). This way we
328 * can give out data that can be specified correctly with
329 * the V4L2-definitions.
331 * The pixel format is specified as RGBA32 when no conversion
334 * Note that this only affects the 32-bit bit depth.
336 * Use non-zero value to enable conversion.
338 static int vino_pixel_conversion;
340 module_param_named(pixelconv, vino_pixel_conversion, int, 0);
342 MODULE_PARM_DESC(pixelconv,
343 "enable pixel conversion (non-zero value enables)");
345 /* Internal data structures */
347 static struct sgi_vino *vino;
349 static struct vino_settings *vino_drvdata;
351 static const char *vino_driver_name = "vino";
352 static const char *vino_driver_description = "SGI VINO";
353 static const char *vino_bus_name = "GIO64 bus";
354 static const char *vino_v4l_device_name_a = "SGI VINO Channel A";
355 static const char *vino_v4l_device_name_b = "SGI VINO Channel B";
357 static void vino_capture_tasklet(unsigned long channel);
359 DECLARE_TASKLET(vino_tasklet_a, vino_capture_tasklet, VINO_CHANNEL_A);
360 DECLARE_TASKLET(vino_tasklet_b, vino_capture_tasklet, VINO_CHANNEL_B);
362 static const struct vino_input vino_inputs[] = {
365 .std = V4L2_STD_NTSC | V4L2_STD_PAL
369 .std = V4L2_STD_NTSC | V4L2_STD_PAL
372 .name = "D1/IndyCam",
373 .std = V4L2_STD_NTSC,
377 static const struct vino_data_format vino_data_formats[] = {
379 .description = "8-bit greyscale",
381 .pixelformat = V4L2_PIX_FMT_GREY,
382 .colorspace = V4L2_COLORSPACE_SMPTE170M,
384 .description = "8-bit dithered RGB 3-3-2",
386 .pixelformat = V4L2_PIX_FMT_RGB332,
387 .colorspace = V4L2_COLORSPACE_SRGB,
389 .description = "32-bit RGB",
391 .pixelformat = V4L2_PIX_FMT_RGB32,
392 .colorspace = V4L2_COLORSPACE_SRGB,
394 .description = "YUV 4:2:2",
396 .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped?
397 .colorspace = V4L2_COLORSPACE_SMPTE170M,
401 static const struct vino_data_norm vino_data_norms[] = {
403 .description = "NTSC",
404 .std = V4L2_STD_NTSC,
408 .width = VINO_NTSC_WIDTH,
409 .height = VINO_NTSC_HEIGHT,
411 .top = VINO_CLIPPING_START_ODD_NTSC,
413 .bottom = VINO_CLIPPING_START_ODD_NTSC
414 + VINO_NTSC_HEIGHT / 2 - 1,
415 .right = VINO_NTSC_WIDTH,
418 .top = VINO_CLIPPING_START_EVEN_NTSC,
420 .bottom = VINO_CLIPPING_START_EVEN_NTSC
421 + VINO_NTSC_HEIGHT / 2 - 1,
422 .right = VINO_NTSC_WIDTH,
425 .description = "PAL",
430 .width = VINO_PAL_WIDTH,
431 .height = VINO_PAL_HEIGHT,
433 .top = VINO_CLIPPING_START_ODD_PAL,
435 .bottom = VINO_CLIPPING_START_ODD_PAL
436 + VINO_PAL_HEIGHT / 2 - 1,
437 .right = VINO_PAL_WIDTH,
440 .top = VINO_CLIPPING_START_EVEN_PAL,
442 .bottom = VINO_CLIPPING_START_EVEN_PAL
443 + VINO_PAL_HEIGHT / 2 - 1,
444 .right = VINO_PAL_WIDTH,
447 .description = "SECAM",
448 .std = V4L2_STD_SECAM,
452 .width = VINO_PAL_WIDTH,
453 .height = VINO_PAL_HEIGHT,
455 .top = VINO_CLIPPING_START_ODD_PAL,
457 .bottom = VINO_CLIPPING_START_ODD_PAL
458 + VINO_PAL_HEIGHT / 2 - 1,
459 .right = VINO_PAL_WIDTH,
462 .top = VINO_CLIPPING_START_EVEN_PAL,
464 .bottom = VINO_CLIPPING_START_EVEN_PAL
465 + VINO_PAL_HEIGHT / 2 - 1,
466 .right = VINO_PAL_WIDTH,
469 .description = "NTSC/D1",
470 .std = V4L2_STD_NTSC,
474 .width = VINO_NTSC_WIDTH,
475 .height = VINO_NTSC_HEIGHT,
477 .top = VINO_CLIPPING_START_ODD_D1,
479 .bottom = VINO_CLIPPING_START_ODD_D1
480 + VINO_NTSC_HEIGHT / 2 - 1,
481 .right = VINO_NTSC_WIDTH,
484 .top = VINO_CLIPPING_START_EVEN_D1,
486 .bottom = VINO_CLIPPING_START_EVEN_D1
487 + VINO_NTSC_HEIGHT / 2 - 1,
488 .right = VINO_NTSC_WIDTH,
493 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
495 struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
497 .id = V4L2_CID_AUTOGAIN,
498 .type = V4L2_CTRL_TYPE_BOOLEAN,
499 .name = "Automatic Gain Control",
503 .default_value = INDYCAM_AGC_DEFAULT,
505 .reserved = { INDYCAM_CONTROL_AGC, 0 },
507 .id = V4L2_CID_AUTO_WHITE_BALANCE,
508 .type = V4L2_CTRL_TYPE_BOOLEAN,
509 .name = "Automatic White Balance",
513 .default_value = INDYCAM_AWB_DEFAULT,
515 .reserved = { INDYCAM_CONTROL_AWB, 0 },
518 .type = V4L2_CTRL_TYPE_INTEGER,
520 .minimum = INDYCAM_GAIN_MIN,
521 .maximum = INDYCAM_GAIN_MAX,
523 .default_value = INDYCAM_GAIN_DEFAULT,
525 .reserved = { INDYCAM_CONTROL_GAIN, 0 },
527 .id = V4L2_CID_PRIVATE_BASE,
528 .type = V4L2_CTRL_TYPE_INTEGER,
529 .name = "Red Saturation",
530 .minimum = INDYCAM_RED_SATURATION_MIN,
531 .maximum = INDYCAM_RED_SATURATION_MAX,
533 .default_value = INDYCAM_RED_SATURATION_DEFAULT,
535 .reserved = { INDYCAM_CONTROL_RED_SATURATION, 0 },
537 .id = V4L2_CID_PRIVATE_BASE + 1,
538 .type = V4L2_CTRL_TYPE_INTEGER,
539 .name = "Blue Saturation",
540 .minimum = INDYCAM_BLUE_SATURATION_MIN,
541 .maximum = INDYCAM_BLUE_SATURATION_MAX,
543 .default_value = INDYCAM_BLUE_SATURATION_DEFAULT,
545 .reserved = { INDYCAM_CONTROL_BLUE_SATURATION, 0 },
547 .id = V4L2_CID_RED_BALANCE,
548 .type = V4L2_CTRL_TYPE_INTEGER,
549 .name = "Red Balance",
550 .minimum = INDYCAM_RED_BALANCE_MIN,
551 .maximum = INDYCAM_RED_BALANCE_MAX,
553 .default_value = INDYCAM_RED_BALANCE_DEFAULT,
555 .reserved = { INDYCAM_CONTROL_RED_BALANCE, 0 },
557 .id = V4L2_CID_BLUE_BALANCE,
558 .type = V4L2_CTRL_TYPE_INTEGER,
559 .name = "Blue Balance",
560 .minimum = INDYCAM_BLUE_BALANCE_MIN,
561 .maximum = INDYCAM_BLUE_BALANCE_MAX,
563 .default_value = INDYCAM_BLUE_BALANCE_DEFAULT,
565 .reserved = { INDYCAM_CONTROL_BLUE_BALANCE, 0 },
567 .id = V4L2_CID_EXPOSURE,
568 .type = V4L2_CTRL_TYPE_INTEGER,
569 .name = "Shutter Control",
570 .minimum = INDYCAM_SHUTTER_MIN,
571 .maximum = INDYCAM_SHUTTER_MAX,
573 .default_value = INDYCAM_SHUTTER_DEFAULT,
575 .reserved = { INDYCAM_CONTROL_SHUTTER, 0 },
577 .id = V4L2_CID_GAMMA,
578 .type = V4L2_CTRL_TYPE_INTEGER,
580 .minimum = INDYCAM_GAMMA_MIN,
581 .maximum = INDYCAM_GAMMA_MAX,
583 .default_value = INDYCAM_GAMMA_DEFAULT,
585 .reserved = { INDYCAM_CONTROL_GAMMA, 0 },
589 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
591 struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
594 .type = V4L2_CTRL_TYPE_INTEGER,
596 .minimum = SAA7191_HUE_MIN,
597 .maximum = SAA7191_HUE_MAX,
599 .default_value = SAA7191_HUE_DEFAULT,
601 .reserved = { SAA7191_CONTROL_HUE, 0 },
603 .id = V4L2_CID_PRIVATE_BASE,
604 .type = V4L2_CTRL_TYPE_INTEGER,
605 .name = "Luminance Bandpass",
606 .minimum = SAA7191_BANDPASS_MIN,
607 .maximum = SAA7191_BANDPASS_MAX,
609 .default_value = SAA7191_BANDPASS_DEFAULT,
611 .reserved = { SAA7191_CONTROL_BANDPASS, 0 },
613 .id = V4L2_CID_PRIVATE_BASE + 1,
614 .type = V4L2_CTRL_TYPE_INTEGER,
615 .name = "Luminance Bandpass Weight",
616 .minimum = SAA7191_BANDPASS_WEIGHT_MIN,
617 .maximum = SAA7191_BANDPASS_WEIGHT_MAX,
619 .default_value = SAA7191_BANDPASS_WEIGHT_DEFAULT,
621 .reserved = { SAA7191_CONTROL_BANDPASS_WEIGHT, 0 },
623 .id = V4L2_CID_PRIVATE_BASE + 2,
624 .type = V4L2_CTRL_TYPE_INTEGER,
625 .name = "HF Luminance Coring",
626 .minimum = SAA7191_CORING_MIN,
627 .maximum = SAA7191_CORING_MAX,
629 .default_value = SAA7191_CORING_DEFAULT,
631 .reserved = { SAA7191_CONTROL_CORING, 0 },
633 .id = V4L2_CID_PRIVATE_BASE + 3,
634 .type = V4L2_CTRL_TYPE_BOOLEAN,
635 .name = "Force Colour",
636 .minimum = SAA7191_FORCE_COLOUR_MIN,
637 .maximum = SAA7191_FORCE_COLOUR_MAX,
639 .default_value = SAA7191_FORCE_COLOUR_DEFAULT,
641 .reserved = { SAA7191_CONTROL_FORCE_COLOUR, 0 },
643 .id = V4L2_CID_PRIVATE_BASE + 4,
644 .type = V4L2_CTRL_TYPE_INTEGER,
645 .name = "Chrominance Gain Control",
646 .minimum = SAA7191_CHROMA_GAIN_MIN,
647 .maximum = SAA7191_CHROMA_GAIN_MAX,
649 .default_value = SAA7191_CHROMA_GAIN_DEFAULT,
651 .reserved = { SAA7191_CONTROL_CHROMA_GAIN, 0 },
653 .id = V4L2_CID_PRIVATE_BASE + 5,
654 .type = V4L2_CTRL_TYPE_BOOLEAN,
655 .name = "VTR Time Constant",
656 .minimum = SAA7191_VTRC_MIN,
657 .maximum = SAA7191_VTRC_MAX,
659 .default_value = SAA7191_VTRC_DEFAULT,
661 .reserved = { SAA7191_CONTROL_VTRC, 0 },
663 .id = V4L2_CID_PRIVATE_BASE + 6,
664 .type = V4L2_CTRL_TYPE_INTEGER,
665 .name = "Luminance Delay Compensation",
666 .minimum = SAA7191_LUMA_DELAY_MIN,
667 .maximum = SAA7191_LUMA_DELAY_MAX,
669 .default_value = SAA7191_LUMA_DELAY_DEFAULT,
671 .reserved = { SAA7191_CONTROL_LUMA_DELAY, 0 },
673 .id = V4L2_CID_PRIVATE_BASE + 7,
674 .type = V4L2_CTRL_TYPE_INTEGER,
675 .name = "Vertical Noise Reduction",
676 .minimum = SAA7191_VNR_MIN,
677 .maximum = SAA7191_VNR_MAX,
679 .default_value = SAA7191_VNR_DEFAULT,
681 .reserved = { SAA7191_CONTROL_VNR, 0 },
685 /* VINO I2C bus functions */
687 unsigned i2c_vino_getctrl(void *data)
689 return vino->i2c_control;
692 void i2c_vino_setctrl(void *data, unsigned val)
694 vino->i2c_control = val;
697 unsigned i2c_vino_rdata(void *data)
699 return vino->i2c_data;
702 void i2c_vino_wdata(void *data, unsigned val)
704 vino->i2c_data = val;
707 static struct i2c_algo_sgi_data i2c_sgi_vino_data =
709 .getctrl = &i2c_vino_getctrl,
710 .setctrl = &i2c_vino_setctrl,
711 .rdata = &i2c_vino_rdata,
712 .wdata = &i2c_vino_wdata,
718 * There are two possible clients on VINO I2C bus, so we limit usage only
721 static int i2c_vino_client_reg(struct i2c_client *client)
726 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
727 switch (client->driver->id) {
728 case I2C_DRIVERID_SAA7191:
729 if (vino_drvdata->decoder.driver)
732 vino_drvdata->decoder.driver = client;
734 case I2C_DRIVERID_INDYCAM:
735 if (vino_drvdata->camera.driver)
738 vino_drvdata->camera.driver = client;
743 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
748 static int i2c_vino_client_unreg(struct i2c_client *client)
753 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
754 if (client == vino_drvdata->decoder.driver) {
755 if (vino_drvdata->decoder.owner != VINO_NO_CHANNEL)
758 vino_drvdata->decoder.driver = NULL;
759 } else if (client == vino_drvdata->camera.driver) {
760 if (vino_drvdata->camera.owner != VINO_NO_CHANNEL)
763 vino_drvdata->camera.driver = NULL;
765 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
770 static struct i2c_adapter vino_i2c_adapter =
772 .name = "VINO I2C bus",
773 .id = I2C_HW_SGI_VINO,
774 .algo_data = &i2c_sgi_vino_data,
775 .client_register = &i2c_vino_client_reg,
776 .client_unregister = &i2c_vino_client_unreg,
779 static int vino_i2c_add_bus(void)
781 return i2c_sgi_add_bus(&vino_i2c_adapter);
784 static int vino_i2c_del_bus(void)
786 return i2c_del_adapter(&vino_i2c_adapter);
789 static int i2c_camera_command(unsigned int cmd, void *arg)
791 return vino_drvdata->camera.driver->
792 driver->command(vino_drvdata->camera.driver,
796 static int i2c_decoder_command(unsigned int cmd, void *arg)
798 return vino_drvdata->decoder.driver->
799 driver->command(vino_drvdata->decoder.driver,
803 /* VINO framebuffer/DMA descriptor management */
805 static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
810 dprintk("vino_free_buffer_with_count(): count = %d\n", count);
812 for (i = 0; i < count; i++) {
813 ClearPageReserved(virt_to_page(fb->desc_table.virtual[i]));
814 dma_unmap_single(NULL,
815 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
816 PAGE_SIZE, DMA_FROM_DEVICE);
817 free_page(fb->desc_table.virtual[i]);
820 dma_free_coherent(NULL,
821 VINO_PAGE_RATIO * (fb->desc_table.page_count + 4) *
822 sizeof(dma_addr_t), (void *)fb->desc_table.dma_cpu,
824 kfree(fb->desc_table.virtual);
826 memset(fb, 0, sizeof(struct vino_framebuffer));
829 static void vino_free_buffer(struct vino_framebuffer *fb)
831 vino_free_buffer_with_count(fb, fb->desc_table.page_count);
834 static int vino_allocate_buffer(struct vino_framebuffer *fb,
837 unsigned int count, i, j;
840 dprintk("vino_allocate_buffer():\n");
845 memset(fb, 0, sizeof(struct vino_framebuffer));
847 count = ((size / PAGE_SIZE) + 4) & ~3;
849 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
852 /* allocate memory for table with virtual (page) addresses */
853 fb->desc_table.virtual = (unsigned long *)
854 kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
855 if (!fb->desc_table.virtual)
858 /* allocate memory for table with dma addresses
859 * (has space for four extra descriptors) */
860 fb->desc_table.dma_cpu =
861 dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
862 sizeof(dma_addr_t), &fb->desc_table.dma,
863 GFP_KERNEL | GFP_DMA);
864 if (!fb->desc_table.dma_cpu) {
866 goto out_free_virtual;
869 /* allocate pages for the buffer and acquire the according
871 for (i = 0; i < count; i++) {
872 dma_addr_t dma_data_addr;
874 fb->desc_table.virtual[i] =
875 get_zeroed_page(GFP_KERNEL | GFP_DMA);
876 if (!fb->desc_table.virtual[i]) {
883 (void *)fb->desc_table.virtual[i],
884 PAGE_SIZE, DMA_FROM_DEVICE);
886 for (j = 0; j < VINO_PAGE_RATIO; j++) {
887 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
888 dma_data_addr + VINO_PAGE_SIZE * j;
891 SetPageReserved(virt_to_page(fb->desc_table.virtual[i]));
894 /* page_count needs to be set anyway, because the descriptor table has
895 * been allocated according to this number */
896 fb->desc_table.page_count = count;
899 /* the descriptor with index i doesn't contain
900 * a valid address yet */
901 vino_free_buffer_with_count(fb, i);
906 fb->size = count * PAGE_SIZE;
907 fb->data_format = VINO_DATA_FMT_NONE;
909 /* set the dma stop-bit for the last (count+1)th descriptor */
910 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
914 kfree(fb->desc_table.virtual);
919 /* user buffers not fully implemented yet */
920 static int vino_prepare_user_buffer(struct vino_framebuffer *fb,
924 unsigned int count, i, j;
927 dprintk("vino_prepare_user_buffer():\n");
932 memset(fb, 0, sizeof(struct vino_framebuffer));
934 count = ((size / PAGE_SIZE)) & ~3;
936 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
939 /* allocate memory for table with virtual (page) addresses */
940 fb->desc_table.virtual = (unsigned long *)
941 kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
942 if (!fb->desc_table.virtual)
945 /* allocate memory for table with dma addresses
946 * (has space for four extra descriptors) */
947 fb->desc_table.dma_cpu =
948 dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
949 sizeof(dma_addr_t), &fb->desc_table.dma,
950 GFP_KERNEL | GFP_DMA);
951 if (!fb->desc_table.dma_cpu) {
953 goto out_free_virtual;
956 /* allocate pages for the buffer and acquire the according
958 for (i = 0; i < count; i++) {
959 dma_addr_t dma_data_addr;
961 fb->desc_table.virtual[i] =
962 get_zeroed_page(GFP_KERNEL | GFP_DMA);
963 if (!fb->desc_table.virtual[i]) {
970 (void *)fb->desc_table.virtual[i],
971 PAGE_SIZE, DMA_FROM_DEVICE);
973 for (j = 0; j < VINO_PAGE_RATIO; j++) {
974 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
975 dma_data_addr + VINO_PAGE_SIZE * j;
978 SetPageReserved(virt_to_page(fb->desc_table.virtual[i]));
981 /* page_count needs to be set anyway, because the descriptor table has
982 * been allocated according to this number */
983 fb->desc_table.page_count = count;
986 /* the descriptor with index i doesn't contain
987 * a valid address yet */
988 vino_free_buffer_with_count(fb, i);
993 fb->size = count * PAGE_SIZE;
995 /* set the dma stop-bit for the last (count+1)th descriptor */
996 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
1000 kfree(fb->desc_table.virtual);
1005 static void vino_sync_buffer(struct vino_framebuffer *fb)
1009 dprintk("vino_sync_buffer():\n");
1011 for (i = 0; i < fb->desc_table.page_count; i++)
1012 dma_sync_single(NULL,
1013 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
1014 PAGE_SIZE, DMA_FROM_DEVICE);
1017 /* Framebuffer fifo functions (need to be locked externally) */
1019 static inline void vino_fifo_init(struct vino_framebuffer_fifo *f,
1020 unsigned int length)
1027 if (length > VINO_FRAMEBUFFER_COUNT_MAX)
1028 length = VINO_FRAMEBUFFER_COUNT_MAX;
1033 /* returns true/false */
1034 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo *f,
1039 for (i = f->head; i == (f->tail - 1); i = (i + 1) % f->length) {
1040 if (f->data[i] == id)
1048 /* returns true/false */
1049 static inline int vino_fifo_full(struct vino_framebuffer_fifo *f)
1051 return (f->used == f->length);
1055 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo *f)
1060 static int vino_fifo_enqueue(struct vino_framebuffer_fifo *f, unsigned int id)
1062 if (id >= f->length) {
1063 return VINO_QUEUE_ERROR;
1066 if (vino_fifo_has_id(f, id)) {
1067 return VINO_QUEUE_ERROR;
1070 if (f->used < f->length) {
1071 f->data[f->tail] = id;
1072 f->tail = (f->tail + 1) % f->length;
1075 return VINO_QUEUE_ERROR;
1081 static int vino_fifo_peek(struct vino_framebuffer_fifo *f, unsigned int *id)
1084 *id = f->data[f->head];
1086 return VINO_QUEUE_ERROR;
1092 static int vino_fifo_dequeue(struct vino_framebuffer_fifo *f, unsigned int *id)
1095 *id = f->data[f->head];
1096 f->head = (f->head + 1) % f->length;
1099 return VINO_QUEUE_ERROR;
1105 /* Framebuffer queue functions */
1107 /* execute with queue_lock locked */
1108 static void vino_queue_free_with_count(struct vino_framebuffer_queue *q,
1109 unsigned int length)
1114 memset(&q->in, 0, sizeof(struct vino_framebuffer_fifo));
1115 memset(&q->out, 0, sizeof(struct vino_framebuffer_fifo));
1116 for (i = 0; i < length; i++) {
1117 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
1119 vino_free_buffer(q->buffer[i]);
1120 kfree(q->buffer[i]);
1123 q->type = VINO_MEMORY_NONE;
1127 static void vino_queue_free(struct vino_framebuffer_queue *q)
1129 dprintk("vino_queue_free():\n");
1131 if (q->magic != VINO_QUEUE_MAGIC)
1133 if (q->type != VINO_MEMORY_MMAP)
1136 mutex_lock(&q->queue_mutex);
1138 vino_queue_free_with_count(q, q->length);
1140 mutex_unlock(&q->queue_mutex);
1143 static int vino_queue_init(struct vino_framebuffer_queue *q,
1144 unsigned int *length)
1149 dprintk("vino_queue_init(): length = %d\n", *length);
1151 if (q->magic == VINO_QUEUE_MAGIC) {
1152 dprintk("vino_queue_init(): queue already initialized!\n");
1156 if (q->type != VINO_MEMORY_NONE) {
1157 dprintk("vino_queue_init(): queue already initialized!\n");
1164 mutex_lock(&q->queue_mutex);
1166 if (*length > VINO_FRAMEBUFFER_COUNT_MAX)
1167 *length = VINO_FRAMEBUFFER_COUNT_MAX;
1171 for (i = 0; i < *length; i++) {
1172 dprintk("vino_queue_init(): allocating buffer %d\n", i);
1173 q->buffer[i] = kmalloc(sizeof(struct vino_framebuffer),
1175 if (!q->buffer[i]) {
1176 dprintk("vino_queue_init(): kmalloc() failed\n");
1181 ret = vino_allocate_buffer(q->buffer[i],
1182 VINO_FRAMEBUFFER_SIZE);
1184 kfree(q->buffer[i]);
1185 dprintk("vino_queue_init(): "
1186 "vino_allocate_buffer() failed\n");
1190 q->buffer[i]->id = i;
1192 q->buffer[i]->offset = q->buffer[i - 1]->offset +
1193 q->buffer[i - 1]->size;
1195 q->buffer[i]->offset = 0;
1198 spin_lock_init(&q->buffer[i]->state_lock);
1200 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1201 "size = %d\n", i, q->buffer[i]->offset,
1202 q->buffer[i]->size);
1206 vino_queue_free_with_count(q, i);
1209 q->length = *length;
1210 vino_fifo_init(&q->in, q->length);
1211 vino_fifo_init(&q->out, q->length);
1212 q->type = VINO_MEMORY_MMAP;
1213 q->magic = VINO_QUEUE_MAGIC;
1216 mutex_unlock(&q->queue_mutex);
1221 static struct vino_framebuffer *vino_queue_add(struct
1222 vino_framebuffer_queue *q,
1225 struct vino_framebuffer *ret = NULL;
1227 unsigned long flags;
1229 dprintk("vino_queue_add(): id = %d\n", id);
1231 if (q->magic != VINO_QUEUE_MAGIC) {
1235 spin_lock_irqsave(&q->queue_lock, flags);
1240 if (id >= q->length)
1243 /* not needed?: if (vino_fifo_full(&q->out)) {
1246 /* check that outgoing queue isn't already full
1247 * (or that it won't become full) */
1248 total = vino_fifo_get_used(&q->in) +
1249 vino_fifo_get_used(&q->out);
1250 if (total >= q->length)
1253 if (vino_fifo_enqueue(&q->in, id))
1256 ret = q->buffer[id];
1259 spin_unlock_irqrestore(&q->queue_lock, flags);
1264 static struct vino_framebuffer *vino_queue_transfer(struct
1265 vino_framebuffer_queue *q)
1267 struct vino_framebuffer *ret = NULL;
1268 struct vino_framebuffer *fb;
1270 unsigned long flags;
1272 dprintk("vino_queue_transfer():\n");
1274 if (q->magic != VINO_QUEUE_MAGIC) {
1278 spin_lock_irqsave(&q->queue_lock, flags);
1283 // now this actually removes an entry from the incoming queue
1284 if (vino_fifo_dequeue(&q->in, &id)) {
1288 dprintk("vino_queue_transfer(): id = %d\n", id);
1291 // we have already checked that the outgoing queue is not full, but...
1292 if (vino_fifo_enqueue(&q->out, id)) {
1293 printk(KERN_ERR "vino_queue_transfer(): "
1294 "outgoing queue is full, this shouldn't happen!\n");
1300 spin_unlock_irqrestore(&q->queue_lock, flags);
1305 /* returns true/false */
1306 static int vino_queue_incoming_contains(struct vino_framebuffer_queue *q,
1310 unsigned long flags;
1312 if (q->magic != VINO_QUEUE_MAGIC) {
1316 spin_lock_irqsave(&q->queue_lock, flags);
1321 ret = vino_fifo_has_id(&q->in, id);
1324 spin_unlock_irqrestore(&q->queue_lock, flags);
1329 /* returns true/false */
1330 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue *q,
1334 unsigned long flags;
1336 if (q->magic != VINO_QUEUE_MAGIC) {
1340 spin_lock_irqsave(&q->queue_lock, flags);
1345 ret = vino_fifo_has_id(&q->out, id);
1348 spin_unlock_irqrestore(&q->queue_lock, flags);
1353 static int vino_queue_get_incoming(struct vino_framebuffer_queue *q,
1357 unsigned long flags;
1359 if (q->magic != VINO_QUEUE_MAGIC) {
1360 return VINO_QUEUE_ERROR;
1363 spin_lock_irqsave(&q->queue_lock, flags);
1365 if (q->length == 0) {
1366 ret = VINO_QUEUE_ERROR;
1370 *used = vino_fifo_get_used(&q->in);
1373 spin_unlock_irqrestore(&q->queue_lock, flags);
1378 static int vino_queue_get_outgoing(struct vino_framebuffer_queue *q,
1382 unsigned long flags;
1384 if (q->magic != VINO_QUEUE_MAGIC) {
1385 return VINO_QUEUE_ERROR;
1388 spin_lock_irqsave(&q->queue_lock, flags);
1390 if (q->length == 0) {
1391 ret = VINO_QUEUE_ERROR;
1395 *used = vino_fifo_get_used(&q->out);
1398 spin_unlock_irqrestore(&q->queue_lock, flags);
1404 static int vino_queue_get_total(struct vino_framebuffer_queue *q,
1405 unsigned int *total)
1408 unsigned long flags;
1410 if (q->magic != VINO_QUEUE_MAGIC) {
1411 return VINO_QUEUE_ERROR;
1414 spin_lock_irqsave(&q->queue_lock, flags);
1416 if (q->length == 0) {
1417 ret = VINO_QUEUE_ERROR;
1421 *total = vino_fifo_get_used(&q->in) +
1422 vino_fifo_get_used(&q->out);
1425 spin_unlock_irqrestore(&q->queue_lock, flags);
1431 static struct vino_framebuffer *vino_queue_peek(struct
1432 vino_framebuffer_queue *q,
1435 struct vino_framebuffer *ret = NULL;
1436 unsigned long flags;
1438 if (q->magic != VINO_QUEUE_MAGIC) {
1442 spin_lock_irqsave(&q->queue_lock, flags);
1447 if (vino_fifo_peek(&q->in, id)) {
1451 ret = q->buffer[*id];
1453 spin_unlock_irqrestore(&q->queue_lock, flags);
1458 static struct vino_framebuffer *vino_queue_remove(struct
1459 vino_framebuffer_queue *q,
1462 struct vino_framebuffer *ret = NULL;
1463 unsigned long flags;
1464 dprintk("vino_queue_remove():\n");
1466 if (q->magic != VINO_QUEUE_MAGIC) {
1470 spin_lock_irqsave(&q->queue_lock, flags);
1475 if (vino_fifo_dequeue(&q->out, id)) {
1479 dprintk("vino_queue_remove(): id = %d\n", *id);
1480 ret = q->buffer[*id];
1482 spin_unlock_irqrestore(&q->queue_lock, flags);
1488 vino_framebuffer *vino_queue_get_buffer(struct vino_framebuffer_queue *q,
1491 struct vino_framebuffer *ret = NULL;
1492 unsigned long flags;
1494 if (q->magic != VINO_QUEUE_MAGIC) {
1498 spin_lock_irqsave(&q->queue_lock, flags);
1503 if (id >= q->length)
1506 ret = q->buffer[id];
1508 spin_unlock_irqrestore(&q->queue_lock, flags);
1513 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue *q)
1515 unsigned int length = 0;
1516 unsigned long flags;
1518 if (q->magic != VINO_QUEUE_MAGIC) {
1522 spin_lock_irqsave(&q->queue_lock, flags);
1524 spin_unlock_irqrestore(&q->queue_lock, flags);
1529 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue *q)
1533 unsigned long flags;
1535 if (q->magic != VINO_QUEUE_MAGIC) {
1539 spin_lock_irqsave(&q->queue_lock, flags);
1540 for (i = 0; i < q->length; i++) {
1541 if (q->buffer[i]->map_count > 0) {
1546 spin_unlock_irqrestore(&q->queue_lock, flags);
1551 /* VINO functions */
1553 /* execute with input_lock locked */
1554 static void vino_update_line_size(struct vino_channel_settings *vcs)
1556 unsigned int w = vcs->clipping.right - vcs->clipping.left;
1557 unsigned int d = vcs->decimation;
1558 unsigned int bpp = vino_data_formats[vcs->data_format].bpp;
1561 dprintk("update_line_size(): before: w = %d, d = %d, "
1562 "line_size = %d\n", w, d, vcs->line_size);
1564 /* line size must be multiple of 8 bytes */
1565 lsize = (bpp * (w / d)) & ~7;
1566 w = (lsize / bpp) * d;
1568 vcs->clipping.right = vcs->clipping.left + w;
1569 vcs->line_size = lsize;
1571 dprintk("update_line_size(): after: w = %d, d = %d, "
1572 "line_size = %d\n", w, d, vcs->line_size);
1575 /* execute with input_lock locked */
1576 static void vino_set_clipping(struct vino_channel_settings *vcs,
1577 unsigned int x, unsigned int y,
1578 unsigned int w, unsigned int h)
1580 unsigned int maxwidth, maxheight;
1583 maxwidth = vino_data_norms[vcs->data_norm].width;
1584 maxheight = vino_data_norms[vcs->data_norm].height;
1585 d = vcs->decimation;
1587 y &= ~1; /* odd/even fields */
1592 if (y > maxheight) {
1596 if (((w / d) < VINO_MIN_WIDTH)
1597 || ((h / d) < VINO_MIN_HEIGHT)) {
1598 w = VINO_MIN_WIDTH * d;
1599 h = VINO_MIN_HEIGHT * d;
1602 if ((x + w) > maxwidth) {
1604 if ((w / d) < VINO_MIN_WIDTH)
1605 x = maxwidth - VINO_MIN_WIDTH * d;
1607 if ((y + h) > maxheight) {
1609 if ((h / d) < VINO_MIN_HEIGHT)
1610 y = maxheight - VINO_MIN_HEIGHT * d;
1613 vcs->clipping.left = x;
1614 vcs->clipping.top = y;
1615 vcs->clipping.right = x + w;
1616 vcs->clipping.bottom = y + h;
1618 vino_update_line_size(vcs);
1620 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1621 vcs->clipping.left, vcs->clipping.top, vcs->clipping.right,
1622 vcs->clipping.bottom, vcs->decimation, vcs->line_size);
1625 /* execute with input_lock locked */
1626 static inline void vino_set_default_clipping(struct vino_channel_settings *vcs)
1628 vino_set_clipping(vcs, 0, 0, vino_data_norms[vcs->data_norm].width,
1629 vino_data_norms[vcs->data_norm].height);
1632 /* execute with input_lock locked */
1633 static void vino_set_scaling(struct vino_channel_settings *vcs,
1634 unsigned int w, unsigned int h)
1636 unsigned int x, y, curw, curh, d;
1638 x = vcs->clipping.left;
1639 y = vcs->clipping.top;
1640 curw = vcs->clipping.right - vcs->clipping.left;
1641 curh = vcs->clipping.bottom - vcs->clipping.top;
1643 d = max(curw / w, curh / h);
1645 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1646 w, h, curw, curh, d);
1654 vcs->decimation = d;
1655 vino_set_clipping(vcs, x, y, w * d, h * d);
1657 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs->clipping.left,
1658 vcs->clipping.top, vcs->clipping.right, vcs->clipping.bottom,
1659 vcs->decimation, vcs->line_size);
1662 /* execute with input_lock locked */
1663 static inline void vino_set_default_scaling(struct vino_channel_settings *vcs)
1665 vino_set_scaling(vcs, vcs->clipping.right - vcs->clipping.left,
1666 vcs->clipping.bottom - vcs->clipping.top);
1669 /* execute with input_lock locked */
1670 static void vino_set_framerate(struct vino_channel_settings *vcs,
1675 switch (vcs->data_norm) {
1676 case VINO_DATA_NORM_NTSC:
1677 case VINO_DATA_NORM_D1:
1678 fps = (unsigned int)(fps / 6) * 6; // FIXME: round!
1680 if (fps < vino_data_norms[vcs->data_norm].fps_min)
1681 fps = vino_data_norms[vcs->data_norm].fps_min;
1682 if (fps > vino_data_norms[vcs->data_norm].fps_max)
1683 fps = vino_data_norms[vcs->data_norm].fps_max;
1702 mask = VINO_FRAMERT_FULL;
1704 vcs->framert_reg = VINO_FRAMERT_RT(mask);
1706 case VINO_DATA_NORM_PAL:
1707 case VINO_DATA_NORM_SECAM:
1708 fps = (unsigned int)(fps / 5) * 5; // FIXME: round!
1710 if (fps < vino_data_norms[vcs->data_norm].fps_min)
1711 fps = vino_data_norms[vcs->data_norm].fps_min;
1712 if (fps > vino_data_norms[vcs->data_norm].fps_max)
1713 fps = vino_data_norms[vcs->data_norm].fps_max;
1732 mask = VINO_FRAMERT_FULL;
1734 vcs->framert_reg = VINO_FRAMERT_RT(mask) | VINO_FRAMERT_PAL;
1741 /* execute with input_lock locked */
1742 static inline void vino_set_default_framerate(struct
1743 vino_channel_settings *vcs)
1745 vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max);
1749 * Prepare VINO for DMA transfer...
1750 * (execute only with vino_lock and input_lock locked)
1752 static int vino_dma_setup(struct vino_channel_settings *vcs,
1753 struct vino_framebuffer *fb)
1756 struct sgi_vino_channel *ch;
1757 const struct vino_data_norm *norm;
1759 dprintk("vino_dma_setup():\n");
1762 fb->frame_counter = 0;
1764 ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
1765 norm = &vino_data_norms[vcs->data_norm];
1770 /* VINO line size register is set 8 bytes less than actual */
1771 ch->line_size = vcs->line_size - 8;
1773 /* let VINO know where to transfer data */
1774 ch->start_desc_tbl = fb->desc_table.dma;
1775 ch->next_4_desc = fb->desc_table.dma;
1777 /* give vino time to fetch the first four descriptors, 5 usec
1778 * should be more than enough time */
1779 udelay(VINO_DESC_FETCH_DELAY);
1781 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1782 ch->start_desc_tbl, ch->next_4_desc);
1784 /* set the alpha register */
1785 ch->alpha = vcs->alpha;
1787 /* set clipping registers */
1788 ch->clip_start = VINO_CLIP_ODD(norm->odd.top + vcs->clipping.top / 2) |
1789 VINO_CLIP_EVEN(norm->even.top +
1790 vcs->clipping.top / 2) |
1791 VINO_CLIP_X(vcs->clipping.left);
1792 ch->clip_end = VINO_CLIP_ODD(norm->odd.top +
1793 vcs->clipping.bottom / 2 - 1) |
1794 VINO_CLIP_EVEN(norm->even.top +
1795 vcs->clipping.bottom / 2 - 1) |
1796 VINO_CLIP_X(vcs->clipping.right);
1798 /* set the size of actual content in the buffer (DECIMATION !) */
1799 fb->data_size = ((vcs->clipping.right - vcs->clipping.left) /
1801 ((vcs->clipping.bottom - vcs->clipping.top) /
1803 vino_data_formats[vcs->data_format].bpp;
1805 ch->frame_rate = vcs->framert_reg;
1807 ctrl = vino->control;
1808 intr = vino->intr_status;
1810 if (vcs->channel == VINO_CHANNEL_A) {
1811 /* All interrupt conditions for this channel was cleared
1812 * so clear the interrupt status register and enable
1814 intr &= ~VINO_INTSTAT_A;
1815 ctrl |= VINO_CTRL_A_INT;
1817 /* enable synchronization */
1818 ctrl |= VINO_CTRL_A_SYNC_ENBL;
1820 /* enable frame assembly */
1821 ctrl |= VINO_CTRL_A_INTERLEAVE_ENBL;
1823 /* set decimation used */
1824 if (vcs->decimation < 2)
1825 ctrl &= ~VINO_CTRL_A_DEC_ENBL;
1827 ctrl |= VINO_CTRL_A_DEC_ENBL;
1828 ctrl &= ~VINO_CTRL_A_DEC_SCALE_MASK;
1829 ctrl |= (vcs->decimation - 1) <<
1830 VINO_CTRL_A_DEC_SCALE_SHIFT;
1833 /* select input interface */
1834 if (vcs->input == VINO_INPUT_D1)
1835 ctrl |= VINO_CTRL_A_SELECT;
1837 ctrl &= ~VINO_CTRL_A_SELECT;
1840 ctrl &= ~(VINO_CTRL_A_LUMA_ONLY | VINO_CTRL_A_RGB |
1841 VINO_CTRL_A_DITHER);
1843 intr &= ~VINO_INTSTAT_B;
1844 ctrl |= VINO_CTRL_B_INT;
1846 ctrl |= VINO_CTRL_B_SYNC_ENBL;
1847 ctrl |= VINO_CTRL_B_INTERLEAVE_ENBL;
1849 if (vcs->decimation < 2)
1850 ctrl &= ~VINO_CTRL_B_DEC_ENBL;
1852 ctrl |= VINO_CTRL_B_DEC_ENBL;
1853 ctrl &= ~VINO_CTRL_B_DEC_SCALE_MASK;
1854 ctrl |= (vcs->decimation - 1) <<
1855 VINO_CTRL_B_DEC_SCALE_SHIFT;
1858 if (vcs->input == VINO_INPUT_D1)
1859 ctrl |= VINO_CTRL_B_SELECT;
1861 ctrl &= ~VINO_CTRL_B_SELECT;
1863 ctrl &= ~(VINO_CTRL_B_LUMA_ONLY | VINO_CTRL_B_RGB |
1864 VINO_CTRL_B_DITHER);
1868 fb->data_format = vcs->data_format;
1870 switch (vcs->data_format) {
1871 case VINO_DATA_FMT_GREY:
1872 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1873 VINO_CTRL_A_LUMA_ONLY : VINO_CTRL_B_LUMA_ONLY;
1875 case VINO_DATA_FMT_RGB32:
1876 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1877 VINO_CTRL_A_RGB : VINO_CTRL_B_RGB;
1879 case VINO_DATA_FMT_YUV:
1880 /* nothing needs to be done */
1882 case VINO_DATA_FMT_RGB332:
1883 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1884 VINO_CTRL_A_RGB | VINO_CTRL_A_DITHER :
1885 VINO_CTRL_B_RGB | VINO_CTRL_B_DITHER;
1889 vino->intr_status = intr;
1890 vino->control = ctrl;
1895 /* (execute only with vino_lock locked) */
1896 static inline void vino_dma_start(struct vino_channel_settings *vcs)
1898 u32 ctrl = vino->control;
1900 dprintk("vino_dma_start():\n");
1901 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1902 VINO_CTRL_A_DMA_ENBL : VINO_CTRL_B_DMA_ENBL;
1903 vino->control = ctrl;
1906 /* (execute only with vino_lock locked) */
1907 static inline void vino_dma_stop(struct vino_channel_settings *vcs)
1909 u32 ctrl = vino->control;
1911 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1912 ~VINO_CTRL_A_DMA_ENBL : ~VINO_CTRL_B_DMA_ENBL;
1913 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1914 ~VINO_CTRL_A_INT : ~VINO_CTRL_B_INT;
1915 vino->control = ctrl;
1916 dprintk("vino_dma_stop():\n");
1920 * Load dummy page to descriptor registers. This prevents generating of
1921 * spurious interrupts. (execute only with vino_lock locked)
1923 static void vino_clear_interrupt(struct vino_channel_settings *vcs)
1925 struct sgi_vino_channel *ch;
1927 ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
1932 ch->start_desc_tbl = vino_drvdata->dummy_desc_table.dma;
1933 ch->next_4_desc = vino_drvdata->dummy_desc_table.dma;
1935 udelay(VINO_DESC_FETCH_DELAY);
1936 dprintk("channel %c clear interrupt condition\n",
1937 (vcs->channel == VINO_CHANNEL_A) ? 'A':'B');
1940 static int vino_capture(struct vino_channel_settings *vcs,
1941 struct vino_framebuffer *fb)
1944 unsigned long flags, flags2;
1946 spin_lock_irqsave(&fb->state_lock, flags);
1948 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
1950 fb->state = VINO_FRAMEBUFFER_IN_USE;
1952 spin_unlock_irqrestore(&fb->state_lock, flags);
1957 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
1958 spin_lock_irqsave(&vino_drvdata->input_lock, flags2);
1960 vino_dma_setup(vcs, fb);
1961 vino_dma_start(vcs);
1963 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags2);
1964 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
1970 struct vino_framebuffer *vino_capture_enqueue(struct
1971 vino_channel_settings *vcs,
1974 struct vino_framebuffer *fb;
1975 unsigned long flags;
1977 dprintk("vino_capture_enqueue():\n");
1979 spin_lock_irqsave(&vcs->capture_lock, flags);
1981 fb = vino_queue_add(&vcs->fb_queue, index);
1983 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
1988 spin_unlock_irqrestore(&vcs->capture_lock, flags);
1993 static int vino_capture_next(struct vino_channel_settings *vcs, int start)
1995 struct vino_framebuffer *fb;
1996 unsigned int incoming, id;
1998 unsigned long flags;
2000 dprintk("vino_capture_next():\n");
2002 spin_lock_irqsave(&vcs->capture_lock, flags);
2005 /* start capture only if capture isn't in progress already */
2006 if (vcs->capturing) {
2007 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2012 /* capture next frame:
2013 * stop capture if capturing is not set */
2014 if (!vcs->capturing) {
2015 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2020 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
2022 dprintk("vino_capture_next(): vino_queue_get_incoming() "
2027 if (incoming == 0) {
2028 dprintk("vino_capture_next(): no buffers available\n");
2032 fb = vino_queue_peek(&vcs->fb_queue, &id);
2034 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
2043 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2045 err = vino_capture(vcs, fb);
2051 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2056 static inline int vino_is_capturing(struct vino_channel_settings *vcs)
2059 unsigned long flags;
2061 spin_lock_irqsave(&vcs->capture_lock, flags);
2063 ret = vcs->capturing;
2065 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2070 /* waits until a frame is captured */
2071 static int vino_wait_for_frame(struct vino_channel_settings *vcs)
2076 dprintk("vino_wait_for_frame():\n");
2078 init_waitqueue_entry(&wait, current);
2079 /* add ourselves into wait queue */
2080 add_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
2082 /* to ensure that schedule_timeout will return immediately
2083 * if VINO interrupt was triggered meanwhile */
2084 schedule_timeout_interruptible(msecs_to_jiffies(100));
2086 if (signal_pending(current))
2089 remove_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
2091 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2092 err ? "failed" : "ok");
2097 /* the function assumes that PAGE_SIZE % 4 == 0 */
2098 static void vino_convert_to_rgba(struct vino_framebuffer *fb) {
2099 unsigned char *pageptr;
2100 unsigned int page, i;
2103 for (page = 0; page < fb->desc_table.page_count; page++) {
2104 pageptr = (unsigned char *)fb->desc_table.virtual[page];
2106 for (i = 0; i < PAGE_SIZE; i += 4) {
2108 pageptr[0] = pageptr[3];
2109 pageptr[1] = pageptr[2];
2110 pageptr[2] = pageptr[1];
2117 /* checks if the buffer is in correct state and syncs data */
2118 static int vino_check_buffer(struct vino_channel_settings *vcs,
2119 struct vino_framebuffer *fb)
2122 unsigned long flags;
2124 dprintk("vino_check_buffer():\n");
2126 spin_lock_irqsave(&fb->state_lock, flags);
2127 switch (fb->state) {
2128 case VINO_FRAMEBUFFER_IN_USE:
2131 case VINO_FRAMEBUFFER_READY:
2132 vino_sync_buffer(fb);
2133 fb->state = VINO_FRAMEBUFFER_UNUSED;
2138 spin_unlock_irqrestore(&fb->state_lock, flags);
2141 if (vino_pixel_conversion
2142 && (fb->data_format == VINO_DATA_FMT_RGB32)) {
2143 vino_convert_to_rgba(fb);
2145 } else if (err && (err != -EINVAL)) {
2146 dprintk("vino_check_buffer(): buffer not ready\n");
2148 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
2150 vino_clear_interrupt(vcs);
2151 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2157 /* forcefully terminates capture */
2158 static void vino_capture_stop(struct vino_channel_settings *vcs)
2160 unsigned int incoming = 0, outgoing = 0, id;
2161 unsigned long flags, flags2;
2163 dprintk("vino_capture_stop():\n");
2165 spin_lock_irqsave(&vcs->capture_lock, flags);
2167 /* unset capturing to stop queue processing */
2170 spin_lock_irqsave(&vino_drvdata->vino_lock, flags2);
2173 vino_clear_interrupt(vcs);
2175 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags2);
2177 /* remove all items from the queue */
2178 if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
2179 dprintk("vino_capture_stop(): "
2180 "vino_queue_get_incoming() failed\n");
2183 while (incoming > 0) {
2184 vino_queue_transfer(&vcs->fb_queue);
2186 if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
2187 dprintk("vino_capture_stop(): "
2188 "vino_queue_get_incoming() failed\n");
2193 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
2194 dprintk("vino_capture_stop(): "
2195 "vino_queue_get_outgoing() failed\n");
2198 while (outgoing > 0) {
2199 vino_queue_remove(&vcs->fb_queue, &id);
2201 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
2202 dprintk("vino_capture_stop(): "
2203 "vino_queue_get_outgoing() failed\n");
2209 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2213 static int vino_capture_failed(struct vino_channel_settings *vcs)
2215 struct vino_framebuffer *fb;
2216 unsigned long flags;
2220 dprintk("vino_capture_failed():\n");
2222 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
2225 vino_clear_interrupt(vcs);
2227 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2229 ret = vino_queue_get_incoming(&vcs->fb_queue, &i);
2230 if (ret == VINO_QUEUE_ERROR) {
2231 dprintk("vino_queue_get_incoming() failed\n");
2235 /* no buffers to process */
2239 fb = vino_queue_peek(&vcs->fb_queue, &i);
2241 dprintk("vino_queue_peek() failed\n");
2245 spin_lock_irqsave(&fb->state_lock, flags);
2246 if (fb->state == VINO_FRAMEBUFFER_IN_USE) {
2247 fb->state = VINO_FRAMEBUFFER_UNUSED;
2248 vino_queue_transfer(&vcs->fb_queue);
2249 vino_queue_remove(&vcs->fb_queue, &i);
2250 /* we should actually discard the newest frame,
2251 * but who cares ... */
2253 spin_unlock_irqrestore(&fb->state_lock, flags);
2259 static void vino_skip_frame(struct vino_channel_settings *vcs)
2261 struct vino_framebuffer *fb;
2262 unsigned long flags;
2265 spin_lock_irqsave(&vcs->capture_lock, flags);
2266 fb = vino_queue_peek(&vcs->fb_queue, &id);
2268 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2269 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2272 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2274 spin_lock_irqsave(&fb->state_lock, flags);
2275 fb->state = VINO_FRAMEBUFFER_UNUSED;
2276 spin_unlock_irqrestore(&fb->state_lock, flags);
2278 vino_capture_next(vcs, 0);
2281 static void vino_frame_done(struct vino_channel_settings *vcs)
2283 struct vino_framebuffer *fb;
2284 unsigned long flags;
2286 spin_lock_irqsave(&vcs->capture_lock, flags);
2287 fb = vino_queue_transfer(&vcs->fb_queue);
2289 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2290 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2293 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2295 fb->frame_counter = vcs->int_data.frame_counter;
2296 memcpy(&fb->timestamp, &vcs->int_data.timestamp,
2297 sizeof(struct timeval));
2299 spin_lock_irqsave(&fb->state_lock, flags);
2300 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
2301 fb->state = VINO_FRAMEBUFFER_READY;
2302 spin_unlock_irqrestore(&fb->state_lock, flags);
2304 wake_up(&vcs->fb_queue.frame_wait_queue);
2306 vino_capture_next(vcs, 0);
2309 static void vino_capture_tasklet(unsigned long channel) {
2310 struct vino_channel_settings *vcs;
2312 vcs = (channel == VINO_CHANNEL_A)
2313 ? &vino_drvdata->a : &vino_drvdata->b;
2315 if (vcs->int_data.skip)
2316 vcs->int_data.skip_count++;
2318 if (vcs->int_data.skip && (vcs->int_data.skip_count
2319 <= VINO_MAX_FRAME_SKIP_COUNT)) {
2320 vino_skip_frame(vcs);
2322 vcs->int_data.skip_count = 0;
2323 vino_frame_done(vcs);
2327 static irqreturn_t vino_interrupt(int irq, void *dev_id)
2330 unsigned int fc_a, fc_b;
2331 int handled_a = 0, skip_a = 0, done_a = 0;
2332 int handled_b = 0, skip_b = 0, done_b = 0;
2334 #ifdef VINO_DEBUG_INT
2336 unsigned int line_count = vino->a.line_count,
2337 page_index = vino->a.page_index,
2338 field_counter = vino->a.field_counter,
2339 start_desc_tbl = vino->a.start_desc_tbl,
2340 next_4_desc = vino->a.next_4_desc;
2341 unsigned int line_count_2,
2348 spin_lock(&vino_drvdata->vino_lock);
2350 while ((intr = vino->intr_status)) {
2351 fc_a = vino->a.field_counter >> 1;
2352 fc_b = vino->b.field_counter >> 1;
2354 /* handle error-interrupts in some special way ?
2355 * --> skips frames */
2356 if (intr & VINO_INTSTAT_A) {
2357 if (intr & VINO_INTSTAT_A_EOF) {
2358 vino_drvdata->a.field++;
2359 if (vino_drvdata->a.field > 1) {
2360 vino_dma_stop(&vino_drvdata->a);
2361 vino_clear_interrupt(&vino_drvdata->a);
2362 vino_drvdata->a.field = 0;
2365 if (vino->a.page_index
2366 != vino_drvdata->a.line_size) {
2367 vino->a.line_count = 0;
2368 vino->a.page_index =
2371 vino->a.next_4_desc =
2372 vino->a.start_desc_tbl;
2375 dprintk("channel A end-of-field "
2376 "interrupt: %04x\n", intr);
2378 vino_dma_stop(&vino_drvdata->a);
2379 vino_clear_interrupt(&vino_drvdata->a);
2380 vino_drvdata->a.field = 0;
2382 dprintk("channel A error interrupt: %04x\n",
2386 #ifdef VINO_DEBUG_INT
2387 line_count_2 = vino->a.line_count;
2388 page_index_2 = vino->a.page_index;
2389 field_counter_2 = vino->a.field_counter;
2390 start_desc_tbl_2 = vino->a.start_desc_tbl;
2391 next_4_desc_2 = vino->a.next_4_desc;
2393 printk("intr = %04x, loop = %d, field = %d\n",
2394 intr, loop, vino_drvdata->a.field);
2395 printk("1- line count = %04d, page index = %04d, "
2396 "start = %08x, next = %08x\n"
2397 " fieldc = %d, framec = %d\n",
2398 line_count, page_index, start_desc_tbl,
2399 next_4_desc, field_counter, fc_a);
2400 printk("12-line count = %04d, page index = %04d, "
2401 " start = %08x, next = %08x\n",
2402 line_count_2, page_index_2, start_desc_tbl_2,
2410 if (intr & VINO_INTSTAT_B) {
2411 if (intr & VINO_INTSTAT_B_EOF) {
2412 vino_drvdata->b.field++;
2413 if (vino_drvdata->b.field > 1) {
2414 vino_dma_stop(&vino_drvdata->b);
2415 vino_clear_interrupt(&vino_drvdata->b);
2416 vino_drvdata->b.field = 0;
2419 dprintk("channel B end-of-field "
2420 "interrupt: %04x\n", intr);
2422 vino_dma_stop(&vino_drvdata->b);
2423 vino_clear_interrupt(&vino_drvdata->b);
2424 vino_drvdata->b.field = 0;
2426 dprintk("channel B error interrupt: %04x\n",
2431 /* Always remember to clear interrupt status.
2432 * Disable VINO interrupts while we do this. */
2433 ctrl = vino->control;
2434 vino->control = ctrl & ~(VINO_CTRL_A_INT | VINO_CTRL_B_INT);
2435 vino->intr_status = ~intr;
2436 vino->control = ctrl;
2438 spin_unlock(&vino_drvdata->vino_lock);
2440 if ((!handled_a) && (done_a || skip_a)) {
2442 do_gettimeofday(&vino_drvdata->
2443 a.int_data.timestamp);
2444 vino_drvdata->a.int_data.frame_counter = fc_a;
2446 vino_drvdata->a.int_data.skip = skip_a;
2448 dprintk("channel A %s, interrupt: %d\n",
2449 skip_a ? "skipping frame" : "frame done",
2451 tasklet_hi_schedule(&vino_tasklet_a);
2455 if ((!handled_b) && (done_b || skip_b)) {
2457 do_gettimeofday(&vino_drvdata->
2458 b.int_data.timestamp);
2459 vino_drvdata->b.int_data.frame_counter = fc_b;
2461 vino_drvdata->b.int_data.skip = skip_b;
2463 dprintk("channel B %s, interrupt: %d\n",
2464 skip_b ? "skipping frame" : "frame done",
2466 tasklet_hi_schedule(&vino_tasklet_b);
2470 #ifdef VINO_DEBUG_INT
2473 spin_lock(&vino_drvdata->vino_lock);
2476 spin_unlock(&vino_drvdata->vino_lock);
2481 /* VINO video input management */
2483 static int vino_get_saa7191_input(int input)
2486 case VINO_INPUT_COMPOSITE:
2487 return SAA7191_INPUT_COMPOSITE;
2488 case VINO_INPUT_SVIDEO:
2489 return SAA7191_INPUT_SVIDEO;
2491 printk(KERN_ERR "VINO: vino_get_saa7191_input(): "
2492 "invalid input!\n");
2497 static int vino_get_saa7191_norm(unsigned int data_norm)
2499 switch (data_norm) {
2500 case VINO_DATA_NORM_AUTO:
2501 return SAA7191_NORM_AUTO;
2502 case VINO_DATA_NORM_AUTO_EXT:
2503 return SAA7191_NORM_AUTO_EXT;
2504 case VINO_DATA_NORM_PAL:
2505 return SAA7191_NORM_PAL;
2506 case VINO_DATA_NORM_NTSC:
2507 return SAA7191_NORM_NTSC;
2508 case VINO_DATA_NORM_SECAM:
2509 return SAA7191_NORM_SECAM;
2511 printk(KERN_ERR "VINO: vino_get_saa7191_norm(): "
2517 static int vino_get_from_saa7191_norm(int saa7191_norm)
2519 switch (saa7191_norm) {
2520 case SAA7191_NORM_PAL:
2521 return VINO_DATA_NORM_PAL;
2522 case SAA7191_NORM_NTSC:
2523 return VINO_DATA_NORM_NTSC;
2524 case SAA7191_NORM_SECAM:
2525 return VINO_DATA_NORM_SECAM;
2527 printk(KERN_ERR "VINO: vino_get_from_saa7191_norm(): "
2529 return VINO_DATA_NORM_NONE;
2533 static int vino_saa7191_set_norm(unsigned int *data_norm)
2535 int saa7191_norm, new_data_norm;
2538 saa7191_norm = vino_get_saa7191_norm(*data_norm);
2540 err = i2c_decoder_command(DECODER_SAA7191_SET_NORM,
2545 if ((*data_norm == VINO_DATA_NORM_AUTO)
2546 || (*data_norm == VINO_DATA_NORM_AUTO_EXT)) {
2547 struct saa7191_status status;
2549 err = i2c_decoder_command(DECODER_SAA7191_GET_STATUS,
2555 vino_get_from_saa7191_norm(status.norm);
2556 if (new_data_norm == VINO_DATA_NORM_NONE) {
2561 *data_norm = (unsigned int)new_data_norm;
2568 /* execute with input_lock locked */
2569 static int vino_is_input_owner(struct vino_channel_settings *vcs)
2571 switch(vcs->input) {
2572 case VINO_INPUT_COMPOSITE:
2573 case VINO_INPUT_SVIDEO:
2574 return (vino_drvdata->decoder.owner == vcs->channel);
2576 return (vino_drvdata->camera.owner == vcs->channel);
2582 static int vino_acquire_input(struct vino_channel_settings *vcs)
2584 unsigned long flags;
2587 dprintk("vino_acquire_input():\n");
2589 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2591 /* First try D1 and then SAA7191 */
2592 if (vino_drvdata->camera.driver
2593 && (vino_drvdata->camera.owner == VINO_NO_CHANNEL)) {
2594 i2c_use_client(vino_drvdata->camera.driver);
2595 vino_drvdata->camera.owner = vcs->channel;
2596 vcs->input = VINO_INPUT_D1;
2597 vcs->data_norm = VINO_DATA_NORM_D1;
2598 } else if (vino_drvdata->decoder.driver
2599 && (vino_drvdata->decoder.owner == VINO_NO_CHANNEL)) {
2600 int input, data_norm;
2603 i2c_use_client(vino_drvdata->decoder.driver);
2604 input = VINO_INPUT_COMPOSITE;
2606 saa7191_input = vino_get_saa7191_input(input);
2607 ret = i2c_decoder_command(DECODER_SET_INPUT,
2614 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2616 /* Don't hold spinlocks while auto-detecting norm
2617 * as it may take a while... */
2619 data_norm = VINO_DATA_NORM_AUTO_EXT;
2621 ret = vino_saa7191_set_norm(&data_norm);
2622 if ((ret == -EBUSY) || (ret == -EAGAIN)) {
2623 data_norm = VINO_DATA_NORM_PAL;
2624 ret = vino_saa7191_set_norm(&data_norm);
2627 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2634 vino_drvdata->decoder.owner = vcs->channel;
2637 vcs->data_norm = data_norm;
2639 vcs->input = (vcs->channel == VINO_CHANNEL_A) ?
2640 vino_drvdata->b.input : vino_drvdata->a.input;
2641 vcs->data_norm = (vcs->channel == VINO_CHANNEL_A) ?
2642 vino_drvdata->b.data_norm : vino_drvdata->a.data_norm;
2645 if (vcs->input == VINO_INPUT_NONE) {
2650 vino_set_default_clipping(vcs);
2651 vino_set_default_scaling(vcs);
2652 vino_set_default_framerate(vcs);
2654 dprintk("vino_acquire_input(): %s\n", vino_inputs[vcs->input].name);
2657 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2662 static int vino_set_input(struct vino_channel_settings *vcs, int input)
2664 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2665 &vino_drvdata->b : &vino_drvdata->a;
2666 unsigned long flags;
2669 dprintk("vino_set_input():\n");
2671 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2673 if (vcs->input == input)
2677 case VINO_INPUT_COMPOSITE:
2678 case VINO_INPUT_SVIDEO:
2679 if (!vino_drvdata->decoder.driver) {
2684 if (vino_drvdata->decoder.owner == VINO_NO_CHANNEL) {
2685 i2c_use_client(vino_drvdata->decoder.driver);
2686 vino_drvdata->decoder.owner = vcs->channel;
2689 if (vino_drvdata->decoder.owner == vcs->channel) {
2693 saa7191_input = vino_get_saa7191_input(input);
2694 ret = i2c_decoder_command(DECODER_SET_INPUT,
2697 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2702 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2704 /* Don't hold spinlocks while auto-detecting norm
2705 * as it may take a while... */
2707 data_norm = VINO_DATA_NORM_AUTO_EXT;
2709 ret = vino_saa7191_set_norm(&data_norm);
2710 if ((ret == -EBUSY) || (ret == -EAGAIN)) {
2711 data_norm = VINO_DATA_NORM_PAL;
2712 ret = vino_saa7191_set_norm(&data_norm);
2715 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2718 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2724 vcs->data_norm = data_norm;
2726 if (input != vcs2->input) {
2732 vcs->data_norm = vcs2->data_norm;
2735 if (vino_drvdata->camera.owner == vcs->channel) {
2736 /* Transfer the ownership or release the input */
2737 if (vcs2->input == VINO_INPUT_D1) {
2738 vino_drvdata->camera.owner = vcs2->channel;
2740 i2c_release_client(vino_drvdata->
2742 vino_drvdata->camera.owner = VINO_NO_CHANNEL;
2747 if (!vino_drvdata->camera.driver) {
2752 if (vino_drvdata->camera.owner == VINO_NO_CHANNEL) {
2753 i2c_use_client(vino_drvdata->camera.driver);
2754 vino_drvdata->camera.owner = vcs->channel;
2757 if (vino_drvdata->decoder.owner == vcs->channel) {
2758 /* Transfer the ownership or release the input */
2759 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2760 (vcs2->input == VINO_INPUT_SVIDEO)) {
2761 vino_drvdata->decoder.owner = vcs2->channel;
2763 i2c_release_client(vino_drvdata->
2765 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2770 vcs->data_norm = VINO_DATA_NORM_D1;
2777 vino_set_default_clipping(vcs);
2778 vino_set_default_scaling(vcs);
2779 vino_set_default_framerate(vcs);
2781 dprintk("vino_set_input(): %s\n", vino_inputs[vcs->input].name);
2784 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2789 static void vino_release_input(struct vino_channel_settings *vcs)
2791 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2792 &vino_drvdata->b : &vino_drvdata->a;
2793 unsigned long flags;
2795 dprintk("vino_release_input():\n");
2797 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2799 /* Release ownership of the channel
2800 * and if the other channel takes input from
2801 * the same source, transfer the ownership */
2802 if (vino_drvdata->camera.owner == vcs->channel) {
2803 if (vcs2->input == VINO_INPUT_D1) {
2804 vino_drvdata->camera.owner = vcs2->channel;
2806 i2c_release_client(vino_drvdata->camera.driver);
2807 vino_drvdata->camera.owner = VINO_NO_CHANNEL;
2809 } else if (vino_drvdata->decoder.owner == vcs->channel) {
2810 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2811 (vcs2->input == VINO_INPUT_SVIDEO)) {
2812 vino_drvdata->decoder.owner = vcs2->channel;
2814 i2c_release_client(vino_drvdata->decoder.driver);
2815 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2818 vcs->input = VINO_INPUT_NONE;
2820 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2823 /* execute with input_lock locked */
2824 static int vino_set_data_norm(struct vino_channel_settings *vcs,
2825 unsigned int data_norm,
2826 unsigned long *flags)
2830 if (data_norm == vcs->data_norm)
2833 switch (vcs->input) {
2835 /* only one "norm" supported */
2836 if ((data_norm != VINO_DATA_NORM_D1)
2837 && (data_norm != VINO_DATA_NORM_AUTO)
2838 && (data_norm != VINO_DATA_NORM_AUTO_EXT))
2841 case VINO_INPUT_COMPOSITE:
2842 case VINO_INPUT_SVIDEO: {
2843 if ((data_norm != VINO_DATA_NORM_PAL)
2844 && (data_norm != VINO_DATA_NORM_NTSC)
2845 && (data_norm != VINO_DATA_NORM_SECAM)
2846 && (data_norm != VINO_DATA_NORM_AUTO)
2847 && (data_norm != VINO_DATA_NORM_AUTO_EXT))
2850 spin_unlock_irqrestore(&vino_drvdata->input_lock, *flags);
2852 /* Don't hold spinlocks while setting norm
2853 * as it may take a while... */
2855 err = vino_saa7191_set_norm(&data_norm);
2857 spin_lock_irqsave(&vino_drvdata->input_lock, *flags);
2862 vcs->data_norm = data_norm;
2864 vino_set_default_clipping(vcs);
2865 vino_set_default_scaling(vcs);
2866 vino_set_default_framerate(vcs);
2877 /* V4L2 helper functions */
2879 static int vino_find_data_format(__u32 pixelformat)
2883 for (i = 0; i < VINO_DATA_FMT_COUNT; i++) {
2884 if (vino_data_formats[i].pixelformat == pixelformat)
2888 return VINO_DATA_FMT_NONE;
2891 static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index)
2893 int data_norm = VINO_DATA_NORM_NONE;
2894 unsigned long flags;
2896 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2897 switch(vcs->input) {
2898 case VINO_INPUT_COMPOSITE:
2899 case VINO_INPUT_SVIDEO:
2901 data_norm = VINO_DATA_NORM_PAL;
2902 } else if (index == 1) {
2903 data_norm = VINO_DATA_NORM_NTSC;
2904 } else if (index == 2) {
2905 data_norm = VINO_DATA_NORM_SECAM;
2910 data_norm = VINO_DATA_NORM_D1;
2914 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2919 static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
2921 int input = VINO_INPUT_NONE;
2922 unsigned long flags;
2924 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2925 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
2928 input = VINO_INPUT_COMPOSITE;
2931 input = VINO_INPUT_SVIDEO;
2934 input = VINO_INPUT_D1;
2937 } else if (vino_drvdata->decoder.driver) {
2940 input = VINO_INPUT_COMPOSITE;
2943 input = VINO_INPUT_SVIDEO;
2946 } else if (vino_drvdata->camera.driver) {
2949 input = VINO_INPUT_D1;
2953 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2958 /* execute with input_lock locked */
2959 static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
2962 // FIXME: detect when no inputs available
2964 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
2965 switch (vcs->input) {
2966 case VINO_INPUT_COMPOSITE:
2969 case VINO_INPUT_SVIDEO:
2976 } else if (vino_drvdata->decoder.driver) {
2977 switch (vcs->input) {
2978 case VINO_INPUT_COMPOSITE:
2981 case VINO_INPUT_SVIDEO:
2985 } else if (vino_drvdata->camera.driver) {
2986 switch (vcs->input) {
2998 static void vino_v4l2_querycap(struct v4l2_capability *cap)
3000 memset(cap, 0, sizeof(struct v4l2_capability));
3002 strcpy(cap->driver, vino_driver_name);
3003 strcpy(cap->card, vino_driver_description);
3004 strcpy(cap->bus_info, vino_bus_name);
3005 cap->version = VINO_VERSION_CODE;
3007 V4L2_CAP_VIDEO_CAPTURE |
3009 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
3012 static int vino_v4l2_enuminput(struct vino_channel_settings *vcs,
3013 struct v4l2_input *i)
3015 __u32 index = i->index;
3017 dprintk("requested index = %d\n", index);
3019 input = vino_enum_input(vcs, index);
3020 if (input == VINO_INPUT_NONE)
3023 memset(i, 0, sizeof(struct v4l2_input));
3026 i->type = V4L2_INPUT_TYPE_CAMERA;
3027 i->std = vino_inputs[input].std;
3028 strcpy(i->name, vino_inputs[input].name);
3030 if ((input == VINO_INPUT_COMPOSITE)
3031 || (input == VINO_INPUT_SVIDEO)) {
3032 struct saa7191_status status;
3033 i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
3034 i->status |= status.signal ? 0 : V4L2_IN_ST_NO_SIGNAL;
3035 i->status |= status.color ? 0 : V4L2_IN_ST_NO_COLOR;
3041 static int vino_v4l2_g_input(struct vino_channel_settings *vcs,
3046 unsigned long flags;
3048 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3050 index = vino_find_input_index(vcs);
3051 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3053 dprintk("input = %d\n", input);
3055 if (input == VINO_INPUT_NONE) {
3064 static int vino_v4l2_s_input(struct vino_channel_settings *vcs,
3068 dprintk("requested input = %d\n", *i);
3070 input = vino_enum_input(vcs, *i);
3071 if (input == VINO_INPUT_NONE)
3074 return vino_set_input(vcs, input);
3077 static int vino_v4l2_enumstd(struct vino_channel_settings *vcs,
3078 struct v4l2_standard *s)
3080 int index = s->index;
3083 data_norm = vino_enum_data_norm(vcs, index);
3084 dprintk("standard index = %d\n", index);
3086 if (data_norm == VINO_DATA_NORM_NONE)
3089 dprintk("standard name = %s\n",
3090 vino_data_norms[data_norm].description);
3092 memset(s, 0, sizeof(struct v4l2_standard));
3095 s->id = vino_data_norms[data_norm].std;
3096 s->frameperiod.numerator = 1;
3097 s->frameperiod.denominator =
3098 vino_data_norms[data_norm].fps_max;
3100 vino_data_norms[data_norm].framelines;
3102 vino_data_norms[data_norm].description);
3107 static int vino_v4l2_querystd(struct vino_channel_settings *vcs,
3110 unsigned long flags;
3113 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3115 switch (vcs->input) {
3117 *std = vino_inputs[vcs->input].std;
3119 case VINO_INPUT_COMPOSITE:
3120 case VINO_INPUT_SVIDEO: {
3121 struct saa7191_status status;
3123 i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
3125 if (status.signal) {
3126 if (status.signal_60hz) {
3127 *std = V4L2_STD_NTSC;
3129 *std = V4L2_STD_PAL | V4L2_STD_SECAM;
3132 *std = vino_inputs[vcs->input].std;
3140 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3145 static int vino_v4l2_g_std(struct vino_channel_settings *vcs,
3148 unsigned long flags;
3150 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3152 *std = vino_data_norms[vcs->data_norm].std;
3153 dprintk("current standard = %d\n", vcs->data_norm);
3155 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3160 static int vino_v4l2_s_std(struct vino_channel_settings *vcs,
3163 unsigned long flags;
3166 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3168 if (!vino_is_input_owner(vcs)) {
3173 /* check if the standard is valid for the current input */
3174 if ((*std) & vino_inputs[vcs->input].std) {
3175 dprintk("standard accepted\n");
3177 /* change the video norm for SAA7191
3178 * and accept NTSC for D1 (do nothing) */
3180 if (vcs->input == VINO_INPUT_D1)
3183 if (((*std) & V4L2_STD_PAL)
3184 && ((*std) & V4L2_STD_NTSC)
3185 && ((*std) & V4L2_STD_SECAM)) {
3186 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_AUTO_EXT,
3188 } else if ((*std) & V4L2_STD_PAL) {
3189 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_PAL,
3191 } else if ((*std) & V4L2_STD_NTSC) {
3192 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC,
3194 } else if ((*std) & V4L2_STD_SECAM) {
3195 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM,
3209 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3214 static int vino_v4l2_enum_fmt(struct vino_channel_settings *vcs,
3215 struct v4l2_fmtdesc *fd)
3217 enum v4l2_buf_type type = fd->type;
3218 int index = fd->index;
3219 dprintk("format index = %d\n", index);
3222 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3223 if ((fd->index < 0) ||
3224 (fd->index >= VINO_DATA_FMT_COUNT))
3226 dprintk("format name = %s\n",
3227 vino_data_formats[index].description);
3229 memset(fd, 0, sizeof(struct v4l2_fmtdesc));
3232 fd->pixelformat = vino_data_formats[index].pixelformat;
3233 strcpy(fd->description, vino_data_formats[index].description);
3235 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3243 static int vino_v4l2_try_fmt(struct vino_channel_settings *vcs,
3244 struct v4l2_format *f)
3246 struct vino_channel_settings tempvcs;
3247 unsigned long flags;
3250 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3251 struct v4l2_pix_format *pf = &f->fmt.pix;
3253 dprintk("requested: w = %d, h = %d\n",
3254 pf->width, pf->height);
3256 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3257 memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings));
3258 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3260 tempvcs.data_format = vino_find_data_format(pf->pixelformat);
3261 if (tempvcs.data_format == VINO_DATA_FMT_NONE) {
3262 tempvcs.data_format = VINO_DATA_FMT_GREY;
3264 vino_data_formats[tempvcs.data_format].
3268 /* data format must be set before clipping/scaling */
3269 vino_set_scaling(&tempvcs, pf->width, pf->height);
3271 dprintk("data format = %s\n",
3272 vino_data_formats[tempvcs.data_format].description);
3274 pf->width = (tempvcs.clipping.right - tempvcs.clipping.left) /
3276 pf->height = (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3279 pf->field = V4L2_FIELD_INTERLACED;
3280 pf->bytesperline = tempvcs.line_size;
3281 pf->sizeimage = tempvcs.line_size *
3282 (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3285 vino_data_formats[tempvcs.data_format].colorspace;
3290 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3298 static int vino_v4l2_g_fmt(struct vino_channel_settings *vcs,
3299 struct v4l2_format *f)
3301 unsigned long flags;
3304 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3305 struct v4l2_pix_format *pf = &f->fmt.pix;
3307 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3309 pf->width = (vcs->clipping.right - vcs->clipping.left) /
3311 pf->height = (vcs->clipping.bottom - vcs->clipping.top) /
3314 vino_data_formats[vcs->data_format].pixelformat;
3316 pf->field = V4L2_FIELD_INTERLACED;
3317 pf->bytesperline = vcs->line_size;
3318 pf->sizeimage = vcs->line_size *
3319 (vcs->clipping.bottom - vcs->clipping.top) /
3322 vino_data_formats[vcs->data_format].colorspace;
3326 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3329 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3337 static int vino_v4l2_s_fmt(struct vino_channel_settings *vcs,
3338 struct v4l2_format *f)
3341 unsigned long flags;
3344 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3345 struct v4l2_pix_format *pf = &f->fmt.pix;
3347 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3349 data_format = vino_find_data_format(pf->pixelformat);
3351 if (data_format == VINO_DATA_FMT_NONE) {
3352 vcs->data_format = VINO_DATA_FMT_GREY;
3354 vino_data_formats[vcs->data_format].
3357 vcs->data_format = data_format;
3360 /* data format must be set before clipping/scaling */
3361 vino_set_scaling(vcs, pf->width, pf->height);
3363 dprintk("data format = %s\n",
3364 vino_data_formats[vcs->data_format].description);
3366 pf->width = vcs->clipping.right - vcs->clipping.left;
3367 pf->height = vcs->clipping.bottom - vcs->clipping.top;
3369 pf->field = V4L2_FIELD_INTERLACED;
3370 pf->bytesperline = vcs->line_size;
3371 pf->sizeimage = vcs->line_size *
3372 (vcs->clipping.bottom - vcs->clipping.top) /
3375 vino_data_formats[vcs->data_format].colorspace;
3379 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3382 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3390 static int vino_v4l2_cropcap(struct vino_channel_settings *vcs,
3391 struct v4l2_cropcap *ccap)
3393 const struct vino_data_norm *norm;
3394 unsigned long flags;
3396 switch (ccap->type) {
3397 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3398 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3400 norm = &vino_data_norms[vcs->data_norm];
3402 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3404 ccap->bounds.left = 0;
3405 ccap->bounds.top = 0;
3406 ccap->bounds.width = norm->width;
3407 ccap->bounds.height = norm->height;
3408 memcpy(&ccap->defrect, &ccap->bounds,
3409 sizeof(struct v4l2_rect));
3411 ccap->pixelaspect.numerator = 1;
3412 ccap->pixelaspect.denominator = 1;
3414 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3422 static int vino_v4l2_g_crop(struct vino_channel_settings *vcs,
3423 struct v4l2_crop *c)
3425 unsigned long flags;
3428 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3429 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3431 c->c.left = vcs->clipping.left;
3432 c->c.top = vcs->clipping.top;
3433 c->c.width = vcs->clipping.right - vcs->clipping.left;
3434 c->c.height = vcs->clipping.bottom - vcs->clipping.top;
3436 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3438 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3446 static int vino_v4l2_s_crop(struct vino_channel_settings *vcs,
3447 struct v4l2_crop *c)
3449 unsigned long flags;
3452 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3453 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3455 vino_set_clipping(vcs, c->c.left, c->c.top,
3456 c->c.width, c->c.height);
3458 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3460 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3468 static int vino_v4l2_g_parm(struct vino_channel_settings *vcs,
3469 struct v4l2_streamparm *sp)
3471 unsigned long flags;
3474 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3475 struct v4l2_captureparm *cp = &sp->parm.capture;
3476 memset(cp, 0, sizeof(struct v4l2_captureparm));
3478 cp->capability = V4L2_CAP_TIMEPERFRAME;
3479 cp->timeperframe.numerator = 1;
3481 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3483 cp->timeperframe.denominator = vcs->fps;
3485 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3487 // TODO: cp->readbuffers = xxx;
3490 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3498 static int vino_v4l2_s_parm(struct vino_channel_settings *vcs,
3499 struct v4l2_streamparm *sp)
3501 unsigned long flags;
3504 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3505 struct v4l2_captureparm *cp = &sp->parm.capture;
3507 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3509 if ((cp->timeperframe.numerator == 0) ||
3510 (cp->timeperframe.denominator == 0)) {
3511 /* reset framerate */
3512 vino_set_default_framerate(vcs);
3514 vino_set_framerate(vcs, cp->timeperframe.denominator /
3515 cp->timeperframe.numerator);
3518 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3520 // TODO: set buffers according to cp->readbuffers
3523 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3531 static int vino_v4l2_reqbufs(struct vino_channel_settings *vcs,
3532 struct v4l2_requestbuffers *rb)
3538 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3539 // TODO: check queue type
3540 if (rb->memory != V4L2_MEMORY_MMAP) {
3541 dprintk("type not mmap\n");
3545 dprintk("count = %d\n", rb->count);
3546 if (rb->count > 0) {
3547 if (vino_is_capturing(vcs)) {
3548 dprintk("busy, capturing\n");
3552 if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) {
3553 dprintk("busy, buffers still mapped\n");
3557 vino_queue_free(&vcs->fb_queue);
3558 vino_queue_init(&vcs->fb_queue, &rb->count);
3562 vino_capture_stop(vcs);
3563 vino_queue_free(&vcs->fb_queue);
3567 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3575 static void vino_v4l2_get_buffer_status(struct vino_channel_settings *vcs,
3576 struct vino_framebuffer *fb,
3577 struct v4l2_buffer *b)
3579 if (vino_queue_outgoing_contains(&vcs->fb_queue,
3581 b->flags &= ~V4L2_BUF_FLAG_QUEUED;
3582 b->flags |= V4L2_BUF_FLAG_DONE;
3583 } else if (vino_queue_incoming_contains(&vcs->fb_queue,
3585 b->flags &= ~V4L2_BUF_FLAG_DONE;
3586 b->flags |= V4L2_BUF_FLAG_QUEUED;
3588 b->flags &= ~(V4L2_BUF_FLAG_DONE |
3589 V4L2_BUF_FLAG_QUEUED);
3592 b->flags &= ~(V4L2_BUF_FLAG_TIMECODE);
3594 if (fb->map_count > 0)
3595 b->flags |= V4L2_BUF_FLAG_MAPPED;
3598 b->memory = (vcs->fb_queue.type == VINO_MEMORY_MMAP) ?
3599 V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
3600 b->m.offset = fb->offset;
3601 b->bytesused = fb->data_size;
3602 b->length = fb->size;
3603 b->field = V4L2_FIELD_INTERLACED;
3604 b->sequence = fb->frame_counter;
3605 memcpy(&b->timestamp, &fb->timestamp,
3606 sizeof(struct timeval));
3609 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3610 fb->id, fb->size, fb->data_size, fb->offset);
3613 static int vino_v4l2_querybuf(struct vino_channel_settings *vcs,
3614 struct v4l2_buffer *b)
3620 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3621 struct vino_framebuffer *fb;
3623 // TODO: check queue type
3624 if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
3625 dprintk("invalid index = %d\n",
3630 fb = vino_queue_get_buffer(&vcs->fb_queue,
3633 dprintk("vino_queue_get_buffer() failed");
3637 vino_v4l2_get_buffer_status(vcs, fb, b);
3640 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3648 static int vino_v4l2_qbuf(struct vino_channel_settings *vcs,
3649 struct v4l2_buffer *b)
3655 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3656 struct vino_framebuffer *fb;
3659 // TODO: check queue type
3660 if (b->memory != V4L2_MEMORY_MMAP) {
3661 dprintk("type not mmap\n");
3665 fb = vino_capture_enqueue(vcs, b->index);
3669 vino_v4l2_get_buffer_status(vcs, fb, b);
3671 if (vcs->streaming) {
3672 ret = vino_capture_next(vcs, 1);
3678 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3686 static int vino_v4l2_dqbuf(struct vino_channel_settings *vcs,
3687 struct v4l2_buffer *b,
3688 unsigned int nonblocking)
3694 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3695 struct vino_framebuffer *fb;
3696 unsigned int incoming, outgoing;
3699 // TODO: check queue type
3701 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3703 dprintk("vino_queue_get_incoming() failed\n");
3706 err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing);
3708 dprintk("vino_queue_get_outgoing() failed\n");
3712 dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing);
3714 if (outgoing == 0) {
3715 if (incoming == 0) {
3716 dprintk("no incoming or outgoing buffers\n");
3720 dprintk("non-blocking I/O was selected and "
3721 "there are no buffers to dequeue\n");
3725 err = vino_wait_for_frame(vcs);
3727 err = vino_wait_for_frame(vcs);
3730 * no frames captured because
3731 * of frame skipping */
3732 // vino_capture_failed(vcs);
3738 fb = vino_queue_remove(&vcs->fb_queue, &b->index);
3740 dprintk("vino_queue_remove() failed\n");
3744 err = vino_check_buffer(vcs, fb);
3746 vino_v4l2_get_buffer_status(vcs, fb, b);
3753 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3761 static int vino_v4l2_streamon(struct vino_channel_settings *vcs)
3763 unsigned int incoming;
3771 // TODO: check queue type
3773 if (vino_queue_get_length(&vcs->fb_queue) < 1) {
3774 dprintk("no buffers allocated\n");
3778 ret = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3780 dprintk("vino_queue_get_incoming() failed\n");
3787 ret = vino_capture_next(vcs, 1);
3791 dprintk("couldn't start capture\n");
3799 static int vino_v4l2_streamoff(struct vino_channel_settings *vcs)
3804 if (!vcs->streaming)
3808 vino_capture_stop(vcs);
3813 static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3814 struct v4l2_queryctrl *queryctrl)
3816 unsigned long flags;
3820 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3822 switch (vcs->input) {
3824 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3825 if (vino_indycam_v4l2_controls[i].id ==
3828 &vino_indycam_v4l2_controls[i],
3829 sizeof(struct v4l2_queryctrl));
3830 queryctrl->reserved[0] = 0;
3837 case VINO_INPUT_COMPOSITE:
3838 case VINO_INPUT_SVIDEO:
3839 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3840 if (vino_saa7191_v4l2_controls[i].id ==
3843 &vino_saa7191_v4l2_controls[i],
3844 sizeof(struct v4l2_queryctrl));
3845 queryctrl->reserved[0] = 0;
3857 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3862 static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs,
3863 struct v4l2_control *control)
3865 unsigned long flags;
3869 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3871 switch (vcs->input) {
3872 case VINO_INPUT_D1: {
3873 struct indycam_control indycam_ctrl;
3875 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3876 if (vino_indycam_v4l2_controls[i].id ==
3886 indycam_ctrl.type = vino_indycam_v4l2_controls[i].reserved[0];
3888 err = i2c_camera_command(DECODER_INDYCAM_GET_CONTROL,
3895 control->value = indycam_ctrl.value;
3898 case VINO_INPUT_COMPOSITE:
3899 case VINO_INPUT_SVIDEO: {
3900 struct saa7191_control saa7191_ctrl;
3902 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3903 if (vino_saa7191_v4l2_controls[i].id ==
3913 saa7191_ctrl.type = vino_saa7191_v4l2_controls[i].reserved[0];
3915 err = i2c_decoder_command(DECODER_SAA7191_GET_CONTROL,
3922 control->value = saa7191_ctrl.value;
3930 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3935 static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs,
3936 struct v4l2_control *control)
3938 unsigned long flags;
3942 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3944 if (!vino_is_input_owner(vcs)) {
3949 switch (vcs->input) {
3950 case VINO_INPUT_D1: {
3951 struct indycam_control indycam_ctrl;
3953 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3954 if (vino_indycam_v4l2_controls[i].id ==
3956 if ((control->value >=
3957 vino_indycam_v4l2_controls[i].minimum)
3958 && (control->value <=
3959 vino_indycam_v4l2_controls[i].
3973 indycam_ctrl.type = vino_indycam_v4l2_controls[i].reserved[0];
3974 indycam_ctrl.value = control->value;
3976 err = i2c_camera_command(DECODER_INDYCAM_SET_CONTROL,
3982 case VINO_INPUT_COMPOSITE:
3983 case VINO_INPUT_SVIDEO: {
3984 struct saa7191_control saa7191_ctrl;
3986 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3987 if (vino_saa7191_v4l2_controls[i].id ==
3989 if ((control->value >=
3990 vino_saa7191_v4l2_controls[i].minimum)
3991 && (control->value <=
3992 vino_saa7191_v4l2_controls[i].
4005 saa7191_ctrl.type = vino_saa7191_v4l2_controls[i].reserved[0];
4006 saa7191_ctrl.value = control->value;
4008 err = i2c_decoder_command(DECODER_SAA7191_SET_CONTROL,
4019 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
4024 /* File operations */
4026 static int vino_open(struct inode *inode, struct file *file)
4028 struct video_device *dev = video_devdata(file);
4029 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4031 dprintk("open(): channel = %c\n",
4032 (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B');
4034 mutex_lock(&vcs->mutex);
4037 dprintk("open(): driver busy\n");
4042 ret = vino_acquire_input(vcs);
4044 dprintk("open(): vino_acquire_input() failed\n");
4051 mutex_unlock(&vcs->mutex);
4053 dprintk("open(): %s!\n", ret ? "failed" : "complete");
4058 static int vino_close(struct inode *inode, struct file *file)
4060 struct video_device *dev = video_devdata(file);
4061 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4062 dprintk("close():\n");
4064 mutex_lock(&vcs->mutex);
4069 vino_release_input(vcs);
4071 /* stop DMA and free buffers */
4072 vino_capture_stop(vcs);
4073 vino_queue_free(&vcs->fb_queue);
4076 mutex_unlock(&vcs->mutex);
4081 static void vino_vm_open(struct vm_area_struct *vma)
4083 struct vino_framebuffer *fb = vma->vm_private_data;
4086 dprintk("vino_vm_open(): count = %d\n", fb->map_count);
4089 static void vino_vm_close(struct vm_area_struct *vma)
4091 struct vino_framebuffer *fb = vma->vm_private_data;
4094 dprintk("vino_vm_close(): count = %d\n", fb->map_count);
4097 static struct vm_operations_struct vino_vm_ops = {
4098 .open = vino_vm_open,
4099 .close = vino_vm_close,
4102 static int vino_mmap(struct file *file, struct vm_area_struct *vma)
4104 struct video_device *dev = video_devdata(file);
4105 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4107 unsigned long start = vma->vm_start;
4108 unsigned long size = vma->vm_end - vma->vm_start;
4109 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
4111 struct vino_framebuffer *fb = NULL;
4112 unsigned int i, length;
4115 dprintk("mmap():\n");
4117 // TODO: reject mmap if already mapped
4119 if (mutex_lock_interruptible(&vcs->mutex))
4127 // TODO: check queue type
4129 if (!(vma->vm_flags & VM_WRITE)) {
4130 dprintk("mmap(): app bug: PROT_WRITE please\n");
4134 if (!(vma->vm_flags & VM_SHARED)) {
4135 dprintk("mmap(): app bug: MAP_SHARED please\n");
4140 /* find the correct buffer using offset */
4141 length = vino_queue_get_length(&vcs->fb_queue);
4143 dprintk("mmap(): queue not initialized\n");
4148 for (i = 0; i < length; i++) {
4149 fb = vino_queue_get_buffer(&vcs->fb_queue, i);
4151 dprintk("mmap(): vino_queue_get_buffer() failed\n");
4156 if (fb->offset == offset)
4160 dprintk("mmap(): invalid offset = %lu\n", offset);
4165 dprintk("mmap(): buffer = %d\n", i);
4167 if (size > (fb->desc_table.page_count * PAGE_SIZE)) {
4168 dprintk("mmap(): failed: size = %lu > %lu\n",
4169 size, fb->desc_table.page_count * PAGE_SIZE);
4174 for (i = 0; i < fb->desc_table.page_count; i++) {
4176 virt_to_phys((void *)fb->desc_table.virtual[i]) >>
4179 if (size < PAGE_SIZE)
4182 // protection was: PAGE_READONLY
4183 if (remap_pfn_range(vma, start, pfn, PAGE_SIZE,
4184 vma->vm_page_prot)) {
4185 dprintk("mmap(): remap_pfn_range() failed\n");
4196 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
4197 vma->vm_flags &= ~VM_IO;
4198 vma->vm_private_data = fb;
4199 vma->vm_file = file;
4200 vma->vm_ops = &vino_vm_ops;
4203 mutex_unlock(&vcs->mutex);
4208 static unsigned int vino_poll(struct file *file, poll_table *pt)
4210 struct video_device *dev = video_devdata(file);
4211 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4212 unsigned int outgoing;
4213 unsigned int ret = 0;
4216 // TODO: this has to be corrected for different read modes
4218 dprintk("poll():\n");
4220 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
4221 dprintk("poll(): vino_queue_get_outgoing() failed\n");
4228 poll_wait(file, &vcs->fb_queue.frame_wait_queue, pt);
4230 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
4231 dprintk("poll(): vino_queue_get_outgoing() failed\n");
4237 dprintk("poll(): data %savailable\n",
4238 (outgoing > 0) ? "" : "not ");
4241 ret = POLLIN | POLLRDNORM;
4248 static int vino_do_ioctl(struct inode *inode, struct file *file,
4249 unsigned int cmd, void *arg)
4251 struct video_device *dev = video_devdata(file);
4252 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4255 switch (_IOC_TYPE(cmd)) {
4257 dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd);
4260 dprintk("ioctl(): V4L2 %s (0x%08x)\n",
4261 v4l2_ioctl_names[_IOC_NR(cmd)], cmd);
4264 dprintk("ioctl(): unsupported command 0x%08x\n", cmd);
4269 /* V4L2 interface */
4270 case VIDIOC_QUERYCAP: {
4271 vino_v4l2_querycap(arg);
4274 case VIDIOC_ENUMINPUT: {
4275 return vino_v4l2_enuminput(vcs, arg);
4277 case VIDIOC_G_INPUT: {
4278 return vino_v4l2_g_input(vcs, arg);
4280 case VIDIOC_S_INPUT: {
4281 return vino_v4l2_s_input(vcs, arg);
4283 case VIDIOC_ENUMSTD: {
4284 return vino_v4l2_enumstd(vcs, arg);
4286 case VIDIOC_QUERYSTD: {
4287 return vino_v4l2_querystd(vcs, arg);
4289 case VIDIOC_G_STD: {
4290 return vino_v4l2_g_std(vcs, arg);
4292 case VIDIOC_S_STD: {
4293 return vino_v4l2_s_std(vcs, arg);
4295 case VIDIOC_ENUM_FMT: {
4296 return vino_v4l2_enum_fmt(vcs, arg);
4298 case VIDIOC_TRY_FMT: {
4299 return vino_v4l2_try_fmt(vcs, arg);
4301 case VIDIOC_G_FMT: {
4302 return vino_v4l2_g_fmt(vcs, arg);
4304 case VIDIOC_S_FMT: {
4305 return vino_v4l2_s_fmt(vcs, arg);
4307 case VIDIOC_CROPCAP: {
4308 return vino_v4l2_cropcap(vcs, arg);
4310 case VIDIOC_G_CROP: {
4311 return vino_v4l2_g_crop(vcs, arg);
4313 case VIDIOC_S_CROP: {
4314 return vino_v4l2_s_crop(vcs, arg);
4316 case VIDIOC_G_PARM: {
4317 return vino_v4l2_g_parm(vcs, arg);
4319 case VIDIOC_S_PARM: {
4320 return vino_v4l2_s_parm(vcs, arg);
4322 case VIDIOC_REQBUFS: {
4323 return vino_v4l2_reqbufs(vcs, arg);
4325 case VIDIOC_QUERYBUF: {
4326 return vino_v4l2_querybuf(vcs, arg);
4329 return vino_v4l2_qbuf(vcs, arg);
4331 case VIDIOC_DQBUF: {
4332 return vino_v4l2_dqbuf(vcs, arg, file->f_flags & O_NONBLOCK);
4334 case VIDIOC_STREAMON: {
4335 return vino_v4l2_streamon(vcs);
4337 case VIDIOC_STREAMOFF: {
4338 return vino_v4l2_streamoff(vcs);
4340 case VIDIOC_QUERYCTRL: {
4341 return vino_v4l2_queryctrl(vcs, arg);
4343 case VIDIOC_G_CTRL: {
4344 return vino_v4l2_g_ctrl(vcs, arg);
4346 case VIDIOC_S_CTRL: {
4347 return vino_v4l2_s_ctrl(vcs, arg);
4350 return -ENOIOCTLCMD;
4356 static int vino_ioctl(struct inode *inode, struct file *file,
4357 unsigned int cmd, unsigned long arg)
4359 struct video_device *dev = video_devdata(file);
4360 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4363 if (mutex_lock_interruptible(&vcs->mutex))
4366 ret = video_usercopy(inode, file, cmd, arg, vino_do_ioctl);
4368 mutex_unlock(&vcs->mutex);
4373 /* Initialization and cleanup */
4376 static int vino_init_stage;
4378 static const struct file_operations vino_fops = {
4379 .owner = THIS_MODULE,
4381 .release = vino_close,
4382 .ioctl = vino_ioctl,
4385 .llseek = no_llseek,
4388 static struct video_device v4l_device_template = {
4394 static void vino_module_cleanup(int stage)
4398 video_unregister_device(vino_drvdata->b.v4l_device);
4399 vino_drvdata->b.v4l_device = NULL;
4401 video_unregister_device(vino_drvdata->a.v4l_device);
4402 vino_drvdata->a.v4l_device = NULL;
4406 free_irq(SGI_VINO_IRQ, NULL);
4408 if (vino_drvdata->b.v4l_device) {
4409 video_device_release(vino_drvdata->b.v4l_device);
4410 vino_drvdata->b.v4l_device = NULL;
4413 if (vino_drvdata->a.v4l_device) {
4414 video_device_release(vino_drvdata->a.v4l_device);
4415 vino_drvdata->a.v4l_device = NULL;
4418 /* all entries in dma_cpu dummy table have the same address */
4419 dma_unmap_single(NULL,
4420 vino_drvdata->dummy_desc_table.dma_cpu[0],
4421 PAGE_SIZE, DMA_FROM_DEVICE);
4422 dma_free_coherent(NULL, VINO_DUMMY_DESC_COUNT
4423 * sizeof(dma_addr_t),
4424 (void *)vino_drvdata->
4425 dummy_desc_table.dma_cpu,
4426 vino_drvdata->dummy_desc_table.dma);
4428 free_page(vino_drvdata->dummy_page);
4430 kfree(vino_drvdata);
4436 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4441 static int vino_probe(void)
4443 unsigned long rev_id;
4445 if (ip22_is_fullhouse()) {
4446 printk(KERN_ERR "VINO doesn't exist in IP22 Fullhouse\n");
4450 if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) {
4451 printk(KERN_ERR "VINO is not found (EISA BUS not present)\n");
4455 vino = (struct sgi_vino *)ioremap(VINO_BASE, sizeof(struct sgi_vino));
4457 printk(KERN_ERR "VINO: ioremap() failed\n");
4462 if (get_dbe(rev_id, &(vino->rev_id))) {
4463 printk(KERN_ERR "Failed to read VINO revision register\n");
4464 vino_module_cleanup(vino_init_stage);
4468 if (VINO_ID_VALUE(rev_id) != VINO_CHIP_ID) {
4469 printk(KERN_ERR "Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4471 vino_module_cleanup(vino_init_stage);
4475 printk(KERN_INFO "VINO revision %ld found\n", VINO_REV_NUM(rev_id));
4480 static int vino_init(void)
4482 dma_addr_t dma_dummy_address;
4485 vino_drvdata = kzalloc(sizeof(struct vino_settings), GFP_KERNEL);
4486 if (!vino_drvdata) {
4487 vino_module_cleanup(vino_init_stage);
4492 /* create a dummy dma descriptor */
4493 vino_drvdata->dummy_page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
4494 if (!vino_drvdata->dummy_page) {
4495 vino_module_cleanup(vino_init_stage);
4500 // TODO: use page_count in dummy_desc_table
4502 vino_drvdata->dummy_desc_table.dma_cpu =
4503 dma_alloc_coherent(NULL,
4504 VINO_DUMMY_DESC_COUNT * sizeof(dma_addr_t),
4505 &vino_drvdata->dummy_desc_table.dma,
4506 GFP_KERNEL | GFP_DMA);
4507 if (!vino_drvdata->dummy_desc_table.dma_cpu) {
4508 vino_module_cleanup(vino_init_stage);
4513 dma_dummy_address = dma_map_single(NULL,
4514 (void *)vino_drvdata->dummy_page,
4515 PAGE_SIZE, DMA_FROM_DEVICE);
4516 for (i = 0; i < VINO_DUMMY_DESC_COUNT; i++) {
4517 vino_drvdata->dummy_desc_table.dma_cpu[i] = dma_dummy_address;
4520 /* initialize VINO */
4523 vino->a.next_4_desc = vino_drvdata->dummy_desc_table.dma;
4524 vino->b.next_4_desc = vino_drvdata->dummy_desc_table.dma;
4525 udelay(VINO_DESC_FETCH_DELAY);
4527 vino->intr_status = 0;
4529 vino->a.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
4530 vino->b.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
4535 static int vino_init_channel_settings(struct vino_channel_settings *vcs,
4536 unsigned int channel, const char *name)
4538 vcs->channel = channel;
4539 vcs->input = VINO_INPUT_NONE;
4542 vcs->data_format = VINO_DATA_FMT_GREY;
4543 vcs->data_norm = VINO_DATA_NORM_NTSC;
4544 vcs->decimation = 1;
4545 vino_set_default_clipping(vcs);
4546 vino_set_default_framerate(vcs);
4550 mutex_init(&vcs->mutex);
4551 spin_lock_init(&vcs->capture_lock);
4553 mutex_init(&vcs->fb_queue.queue_mutex);
4554 spin_lock_init(&vcs->fb_queue.queue_lock);
4555 init_waitqueue_head(&vcs->fb_queue.frame_wait_queue);
4557 vcs->v4l_device = video_device_alloc();
4558 if (!vcs->v4l_device) {
4559 vino_module_cleanup(vino_init_stage);
4564 memcpy(vcs->v4l_device, &v4l_device_template,
4565 sizeof(struct video_device));
4566 strcpy(vcs->v4l_device->name, name);
4567 vcs->v4l_device->release = video_device_release;
4569 video_set_drvdata(vcs->v4l_device, vcs);
4574 static int __init vino_module_init(void)
4578 printk(KERN_INFO "SGI VINO driver version %s\n",
4579 VINO_MODULE_VERSION);
4589 /* initialize data structures */
4591 spin_lock_init(&vino_drvdata->vino_lock);
4592 spin_lock_init(&vino_drvdata->input_lock);
4594 ret = vino_init_channel_settings(&vino_drvdata->a, VINO_CHANNEL_A,
4595 vino_v4l_device_name_a);
4599 ret = vino_init_channel_settings(&vino_drvdata->b, VINO_CHANNEL_B,
4600 vino_v4l_device_name_b);
4604 /* initialize hardware and register V4L devices */
4606 ret = request_irq(SGI_VINO_IRQ, vino_interrupt, 0,
4607 vino_driver_description, NULL);
4609 printk(KERN_ERR "VINO: requesting IRQ %02d failed\n",
4611 vino_module_cleanup(vino_init_stage);
4616 ret = vino_i2c_add_bus();
4618 printk(KERN_ERR "VINO I2C bus registration failed\n");
4619 vino_module_cleanup(vino_init_stage);
4624 ret = video_register_device(vino_drvdata->a.v4l_device,
4625 VFL_TYPE_GRABBER, -1);
4627 printk(KERN_ERR "VINO channel A Video4Linux-device "
4628 "registration failed\n");
4629 vino_module_cleanup(vino_init_stage);
4634 ret = video_register_device(vino_drvdata->b.v4l_device,
4635 VFL_TYPE_GRABBER, -1);
4637 printk(KERN_ERR "VINO channel B Video4Linux-device "
4638 "registration failed\n");
4639 vino_module_cleanup(vino_init_stage);
4644 #if defined(CONFIG_KMOD) && defined(MODULE)
4645 request_module("saa7191");
4646 request_module("indycam");
4649 dprintk("init complete!\n");
4654 static void __exit vino_module_exit(void)
4656 dprintk("exiting, stage = %d ...\n", vino_init_stage);
4657 vino_module_cleanup(vino_init_stage);
4658 dprintk("cleanup complete, exit!\n");
4661 module_init(vino_module_init);
4662 module_exit(vino_module_exit);