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 nopage()
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/videodev.h>
42 #include <media/v4l2-common.h>
43 #include <linux/video_decoder.h>
44 #include <linux/mutex.h>
46 #include <asm/paccess.h>
48 #include <asm/sgi/ip22.h>
49 #include <asm/sgi/mc.h>
55 /* Uncomment the following line to get lots and lots of (mostly useless)
57 * Note that the debug output also slows down the driver significantly */
59 // #define VINO_DEBUG_INT
61 #define VINO_MODULE_VERSION "0.0.5"
62 #define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 5)
64 MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
65 MODULE_VERSION(VINO_MODULE_VERSION
);
66 MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
67 MODULE_LICENSE("GPL");
70 #define dprintk(x...) printk("VINO: " x);
75 #define VINO_NO_CHANNEL 0
76 #define VINO_CHANNEL_A 1
77 #define VINO_CHANNEL_B 2
79 #define VINO_PAL_WIDTH 768
80 #define VINO_PAL_HEIGHT 576
81 #define VINO_NTSC_WIDTH 640
82 #define VINO_NTSC_HEIGHT 480
84 #define VINO_MIN_WIDTH 32
85 #define VINO_MIN_HEIGHT 32
87 #define VINO_CLIPPING_START_ODD_D1 1
88 #define VINO_CLIPPING_START_ODD_PAL 15
89 #define VINO_CLIPPING_START_ODD_NTSC 12
91 #define VINO_CLIPPING_START_EVEN_D1 2
92 #define VINO_CLIPPING_START_EVEN_PAL 15
93 #define VINO_CLIPPING_START_EVEN_NTSC 12
95 #define VINO_INPUT_CHANNEL_COUNT 3
97 /* the number is the index for vino_inputs */
98 #define VINO_INPUT_NONE -1
99 #define VINO_INPUT_COMPOSITE 0
100 #define VINO_INPUT_SVIDEO 1
101 #define VINO_INPUT_D1 2
103 #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
105 #define VINO_FIFO_THRESHOLD_DEFAULT 16
107 #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
108 * VINO_PAL_HEIGHT * 4 \
109 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
111 #define VINO_FRAMEBUFFER_COUNT_MAX 8
113 #define VINO_FRAMEBUFFER_UNUSED 0
114 #define VINO_FRAMEBUFFER_IN_USE 1
115 #define VINO_FRAMEBUFFER_READY 2
117 #define VINO_QUEUE_ERROR -1
118 #define VINO_QUEUE_MAGIC 0x20050125
120 #define VINO_MEMORY_NONE 0
121 #define VINO_MEMORY_MMAP 1
122 #define VINO_MEMORY_USERPTR 2
124 #define VINO_DUMMY_DESC_COUNT 4
125 #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
127 #define VINO_MAX_FRAME_SKIP_COUNT 128
129 /* the number is the index for vino_data_formats */
130 #define VINO_DATA_FMT_NONE -1
131 #define VINO_DATA_FMT_GREY 0
132 #define VINO_DATA_FMT_RGB332 1
133 #define VINO_DATA_FMT_RGB32 2
134 #define VINO_DATA_FMT_YUV 3
136 #define VINO_DATA_FMT_COUNT 4
138 /* the number is the index for vino_data_norms */
139 #define VINO_DATA_NORM_NONE -1
140 #define VINO_DATA_NORM_NTSC 0
141 #define VINO_DATA_NORM_PAL 1
142 #define VINO_DATA_NORM_SECAM 2
143 #define VINO_DATA_NORM_D1 3
144 /* The following are special entries that can be used to
145 * autodetect the norm. */
146 #define VINO_DATA_NORM_AUTO 0xfe
147 #define VINO_DATA_NORM_AUTO_EXT 0xff
149 #define VINO_DATA_NORM_COUNT 4
151 /* Internal data structure definitions */
158 struct vino_clipping
{
159 unsigned int left
, right
, top
, bottom
;
162 struct vino_data_format
{
163 /* the description */
165 /* bytes per pixel */
167 /* V4L2 fourcc code */
169 /* V4L2 colorspace (duh!) */
170 enum v4l2_colorspace colorspace
;
173 struct vino_data_norm
{
175 unsigned int width
, height
;
176 struct vino_clipping odd
;
177 struct vino_clipping even
;
180 unsigned int fps_min
, fps_max
;
184 struct vino_descriptor_table
{
185 /* the number of PAGE_SIZE sized pages in the buffer */
186 unsigned int page_count
;
187 /* virtual (kmalloc'd) pointers to the actual data
188 * (in PAGE_SIZE chunks, used with mmap streaming) */
189 unsigned long *virtual;
191 /* cpu address for the VINO descriptor table
192 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
193 unsigned long *dma_cpu
;
194 /* dma address for the VINO descriptor table
195 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
199 struct vino_framebuffer
{
200 /* identifier nubmer */
202 /* the length of the whole buffer */
204 /* the length of actual data in buffer */
205 unsigned int data_size
;
206 /* the data format */
207 unsigned int data_format
;
208 /* the state of buffer data */
210 /* is the buffer mapped in user space? */
211 unsigned int map_count
;
212 /* memory offset for mmap() */
215 unsigned int frame_counter
;
216 /* timestamp (written when image capture finishes) */
217 struct timeval timestamp
;
219 struct vino_descriptor_table desc_table
;
221 spinlock_t state_lock
;
224 struct vino_framebuffer_fifo
{
231 unsigned int data
[VINO_FRAMEBUFFER_COUNT_MAX
];
234 struct vino_framebuffer_queue
{
237 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
241 /* data field of in and out contain index numbers for buffer */
242 struct vino_framebuffer_fifo in
;
243 struct vino_framebuffer_fifo out
;
245 struct vino_framebuffer
*buffer
[VINO_FRAMEBUFFER_COUNT_MAX
];
247 spinlock_t queue_lock
;
248 struct mutex queue_mutex
;
249 wait_queue_head_t frame_wait_queue
;
252 struct vino_interrupt_data
{
253 struct timeval timestamp
;
254 unsigned int frame_counter
;
255 unsigned int skip_count
;
259 struct vino_channel_settings
{
260 unsigned int channel
;
263 unsigned int data_format
;
264 unsigned int data_norm
;
265 struct vino_clipping clipping
;
266 unsigned int decimation
;
267 unsigned int line_size
;
270 unsigned int framert_reg
;
272 unsigned int fifo_threshold
;
274 struct vino_framebuffer_queue fb_queue
;
276 /* number of the current field */
279 /* read in progress */
281 /* streaming is active */
283 /* the driver is currently processing the queue */
287 spinlock_t capture_lock
;
291 struct vino_interrupt_data int_data
;
294 struct video_device
*v4l_device
;
298 /* the channel which owns this client:
299 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
301 struct i2c_client
*driver
;
304 struct vino_settings
{
305 struct vino_channel_settings a
;
306 struct vino_channel_settings b
;
308 struct vino_client decoder
;
309 struct vino_client camera
;
311 /* a lock for vino register access */
312 spinlock_t vino_lock
;
313 /* a lock for channel input changes */
314 spinlock_t input_lock
;
316 unsigned long dummy_page
;
317 struct vino_descriptor_table dummy_desc_table
;
320 /* Module parameters */
323 * Using vino_pixel_conversion the ABGR32-format pixels supplied
324 * by the VINO chip can be converted to more common formats
325 * like RGBA32 (or probably RGB24 in the future). This way we
326 * can give out data that can be specified correctly with
327 * the V4L2-definitions.
329 * The pixel format is specified as RGBA32 when no conversion
332 * Note that this only affects the 32-bit bit depth.
334 * Use non-zero value to enable conversion.
336 static int vino_pixel_conversion
= 0;
338 module_param_named(pixelconv
, vino_pixel_conversion
, int, 0);
340 MODULE_PARM_DESC(pixelconv
,
341 "enable pixel conversion (non-zero value enables)");
343 /* Internal data structures */
345 static struct sgi_vino
*vino
;
347 static struct vino_settings
*vino_drvdata
;
349 static const char *vino_driver_name
= "vino";
350 static const char *vino_driver_description
= "SGI VINO";
351 static const char *vino_bus_name
= "GIO64 bus";
352 static const char *vino_v4l_device_name_a
= "SGI VINO Channel A";
353 static const char *vino_v4l_device_name_b
= "SGI VINO Channel B";
355 static void vino_capture_tasklet(unsigned long channel
);
357 DECLARE_TASKLET(vino_tasklet_a
, vino_capture_tasklet
, VINO_CHANNEL_A
);
358 DECLARE_TASKLET(vino_tasklet_b
, vino_capture_tasklet
, VINO_CHANNEL_B
);
360 static const struct vino_input vino_inputs
[] = {
363 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
367 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
370 .name
= "D1/IndyCam",
371 .std
= V4L2_STD_NTSC
,
375 static const struct vino_data_format vino_data_formats
[] = {
377 .description
= "8-bit greyscale",
379 .pixelformat
= V4L2_PIX_FMT_GREY
,
380 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
382 .description
= "8-bit dithered RGB 3-3-2",
384 .pixelformat
= V4L2_PIX_FMT_RGB332
,
385 .colorspace
= V4L2_COLORSPACE_SRGB
,
387 .description
= "32-bit RGB",
389 .pixelformat
= V4L2_PIX_FMT_RGB32
,
390 .colorspace
= V4L2_COLORSPACE_SRGB
,
392 .description
= "YUV 4:2:2",
394 .pixelformat
= V4L2_PIX_FMT_YUYV
, // XXX: swapped?
395 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
399 static const struct vino_data_norm vino_data_norms
[] = {
401 .description
= "NTSC",
402 .std
= V4L2_STD_NTSC
,
406 .width
= VINO_NTSC_WIDTH
,
407 .height
= VINO_NTSC_HEIGHT
,
409 .top
= VINO_CLIPPING_START_ODD_NTSC
,
411 .bottom
= VINO_CLIPPING_START_ODD_NTSC
412 + VINO_NTSC_HEIGHT
/ 2 - 1,
413 .right
= VINO_NTSC_WIDTH
,
416 .top
= VINO_CLIPPING_START_EVEN_NTSC
,
418 .bottom
= VINO_CLIPPING_START_EVEN_NTSC
419 + VINO_NTSC_HEIGHT
/ 2 - 1,
420 .right
= VINO_NTSC_WIDTH
,
423 .description
= "PAL",
428 .width
= VINO_PAL_WIDTH
,
429 .height
= VINO_PAL_HEIGHT
,
431 .top
= VINO_CLIPPING_START_ODD_PAL
,
433 .bottom
= VINO_CLIPPING_START_ODD_PAL
434 + VINO_PAL_HEIGHT
/ 2 - 1,
435 .right
= VINO_PAL_WIDTH
,
438 .top
= VINO_CLIPPING_START_EVEN_PAL
,
440 .bottom
= VINO_CLIPPING_START_EVEN_PAL
441 + VINO_PAL_HEIGHT
/ 2 - 1,
442 .right
= VINO_PAL_WIDTH
,
445 .description
= "SECAM",
446 .std
= V4L2_STD_SECAM
,
450 .width
= VINO_PAL_WIDTH
,
451 .height
= VINO_PAL_HEIGHT
,
453 .top
= VINO_CLIPPING_START_ODD_PAL
,
455 .bottom
= VINO_CLIPPING_START_ODD_PAL
456 + VINO_PAL_HEIGHT
/ 2 - 1,
457 .right
= VINO_PAL_WIDTH
,
460 .top
= VINO_CLIPPING_START_EVEN_PAL
,
462 .bottom
= VINO_CLIPPING_START_EVEN_PAL
463 + VINO_PAL_HEIGHT
/ 2 - 1,
464 .right
= VINO_PAL_WIDTH
,
467 .description
= "NTSC/D1",
468 .std
= V4L2_STD_NTSC
,
472 .width
= VINO_NTSC_WIDTH
,
473 .height
= VINO_NTSC_HEIGHT
,
475 .top
= VINO_CLIPPING_START_ODD_D1
,
477 .bottom
= VINO_CLIPPING_START_ODD_D1
478 + VINO_NTSC_HEIGHT
/ 2 - 1,
479 .right
= VINO_NTSC_WIDTH
,
482 .top
= VINO_CLIPPING_START_EVEN_D1
,
484 .bottom
= VINO_CLIPPING_START_EVEN_D1
485 + VINO_NTSC_HEIGHT
/ 2 - 1,
486 .right
= VINO_NTSC_WIDTH
,
491 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
493 struct v4l2_queryctrl vino_indycam_v4l2_controls
[] = {
495 .id
= V4L2_CID_AUTOGAIN
,
496 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
497 .name
= "Automatic Gain Control",
501 .default_value
= INDYCAM_AGC_DEFAULT
,
503 .reserved
= { INDYCAM_CONTROL_AGC
, 0 },
505 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
506 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
507 .name
= "Automatic White Balance",
511 .default_value
= INDYCAM_AWB_DEFAULT
,
513 .reserved
= { INDYCAM_CONTROL_AWB
, 0 },
516 .type
= V4L2_CTRL_TYPE_INTEGER
,
518 .minimum
= INDYCAM_GAIN_MIN
,
519 .maximum
= INDYCAM_GAIN_MAX
,
521 .default_value
= INDYCAM_GAIN_DEFAULT
,
523 .reserved
= { INDYCAM_CONTROL_GAIN
, 0 },
525 .id
= V4L2_CID_PRIVATE_BASE
,
526 .type
= V4L2_CTRL_TYPE_INTEGER
,
527 .name
= "Red Saturation",
528 .minimum
= INDYCAM_RED_SATURATION_MIN
,
529 .maximum
= INDYCAM_RED_SATURATION_MAX
,
531 .default_value
= INDYCAM_RED_SATURATION_DEFAULT
,
533 .reserved
= { INDYCAM_CONTROL_RED_SATURATION
, 0 },
535 .id
= V4L2_CID_PRIVATE_BASE
+ 1,
536 .type
= V4L2_CTRL_TYPE_INTEGER
,
537 .name
= "Blue Saturation",
538 .minimum
= INDYCAM_BLUE_SATURATION_MIN
,
539 .maximum
= INDYCAM_BLUE_SATURATION_MAX
,
541 .default_value
= INDYCAM_BLUE_SATURATION_DEFAULT
,
543 .reserved
= { INDYCAM_CONTROL_BLUE_SATURATION
, 0 },
545 .id
= V4L2_CID_RED_BALANCE
,
546 .type
= V4L2_CTRL_TYPE_INTEGER
,
547 .name
= "Red Balance",
548 .minimum
= INDYCAM_RED_BALANCE_MIN
,
549 .maximum
= INDYCAM_RED_BALANCE_MAX
,
551 .default_value
= INDYCAM_RED_BALANCE_DEFAULT
,
553 .reserved
= { INDYCAM_CONTROL_RED_BALANCE
, 0 },
555 .id
= V4L2_CID_BLUE_BALANCE
,
556 .type
= V4L2_CTRL_TYPE_INTEGER
,
557 .name
= "Blue Balance",
558 .minimum
= INDYCAM_BLUE_BALANCE_MIN
,
559 .maximum
= INDYCAM_BLUE_BALANCE_MAX
,
561 .default_value
= INDYCAM_BLUE_BALANCE_DEFAULT
,
563 .reserved
= { INDYCAM_CONTROL_BLUE_BALANCE
, 0 },
565 .id
= V4L2_CID_EXPOSURE
,
566 .type
= V4L2_CTRL_TYPE_INTEGER
,
567 .name
= "Shutter Control",
568 .minimum
= INDYCAM_SHUTTER_MIN
,
569 .maximum
= INDYCAM_SHUTTER_MAX
,
571 .default_value
= INDYCAM_SHUTTER_DEFAULT
,
573 .reserved
= { INDYCAM_CONTROL_SHUTTER
, 0 },
575 .id
= V4L2_CID_GAMMA
,
576 .type
= V4L2_CTRL_TYPE_INTEGER
,
578 .minimum
= INDYCAM_GAMMA_MIN
,
579 .maximum
= INDYCAM_GAMMA_MAX
,
581 .default_value
= INDYCAM_GAMMA_DEFAULT
,
583 .reserved
= { INDYCAM_CONTROL_GAMMA
, 0 },
587 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
589 struct v4l2_queryctrl vino_saa7191_v4l2_controls
[] = {
592 .type
= V4L2_CTRL_TYPE_INTEGER
,
594 .minimum
= SAA7191_HUE_MIN
,
595 .maximum
= SAA7191_HUE_MAX
,
597 .default_value
= SAA7191_HUE_DEFAULT
,
599 .reserved
= { SAA7191_CONTROL_HUE
, 0 },
601 .id
= V4L2_CID_PRIVATE_BASE
,
602 .type
= V4L2_CTRL_TYPE_INTEGER
,
603 .name
= "Luminance Bandpass",
604 .minimum
= SAA7191_BANDPASS_MIN
,
605 .maximum
= SAA7191_BANDPASS_MAX
,
607 .default_value
= SAA7191_BANDPASS_DEFAULT
,
609 .reserved
= { SAA7191_CONTROL_BANDPASS
, 0 },
611 .id
= V4L2_CID_PRIVATE_BASE
+ 1,
612 .type
= V4L2_CTRL_TYPE_INTEGER
,
613 .name
= "Luminance Bandpass Weight",
614 .minimum
= SAA7191_BANDPASS_WEIGHT_MIN
,
615 .maximum
= SAA7191_BANDPASS_WEIGHT_MAX
,
617 .default_value
= SAA7191_BANDPASS_WEIGHT_DEFAULT
,
619 .reserved
= { SAA7191_CONTROL_BANDPASS_WEIGHT
, 0 },
621 .id
= V4L2_CID_PRIVATE_BASE
+ 2,
622 .type
= V4L2_CTRL_TYPE_INTEGER
,
623 .name
= "HF Luminance Coring",
624 .minimum
= SAA7191_CORING_MIN
,
625 .maximum
= SAA7191_CORING_MAX
,
627 .default_value
= SAA7191_CORING_DEFAULT
,
629 .reserved
= { SAA7191_CONTROL_CORING
, 0 },
631 .id
= V4L2_CID_PRIVATE_BASE
+ 3,
632 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
633 .name
= "Force Colour",
634 .minimum
= SAA7191_FORCE_COLOUR_MIN
,
635 .maximum
= SAA7191_FORCE_COLOUR_MAX
,
637 .default_value
= SAA7191_FORCE_COLOUR_DEFAULT
,
639 .reserved
= { SAA7191_CONTROL_FORCE_COLOUR
, 0 },
641 .id
= V4L2_CID_PRIVATE_BASE
+ 4,
642 .type
= V4L2_CTRL_TYPE_INTEGER
,
643 .name
= "Chrominance Gain Control",
644 .minimum
= SAA7191_CHROMA_GAIN_MIN
,
645 .maximum
= SAA7191_CHROMA_GAIN_MAX
,
647 .default_value
= SAA7191_CHROMA_GAIN_DEFAULT
,
649 .reserved
= { SAA7191_CONTROL_CHROMA_GAIN
, 0 },
651 .id
= V4L2_CID_PRIVATE_BASE
+ 5,
652 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
653 .name
= "VTR Time Constant",
654 .minimum
= SAA7191_VTRC_MIN
,
655 .maximum
= SAA7191_VTRC_MAX
,
657 .default_value
= SAA7191_VTRC_DEFAULT
,
659 .reserved
= { SAA7191_CONTROL_VTRC
, 0 },
661 .id
= V4L2_CID_PRIVATE_BASE
+ 6,
662 .type
= V4L2_CTRL_TYPE_INTEGER
,
663 .name
= "Luminance Delay Compensation",
664 .minimum
= SAA7191_LUMA_DELAY_MIN
,
665 .maximum
= SAA7191_LUMA_DELAY_MAX
,
667 .default_value
= SAA7191_LUMA_DELAY_DEFAULT
,
669 .reserved
= { SAA7191_CONTROL_LUMA_DELAY
, 0 },
671 .id
= V4L2_CID_PRIVATE_BASE
+ 7,
672 .type
= V4L2_CTRL_TYPE_INTEGER
,
673 .name
= "Vertical Noise Reduction",
674 .minimum
= SAA7191_VNR_MIN
,
675 .maximum
= SAA7191_VNR_MAX
,
677 .default_value
= SAA7191_VNR_DEFAULT
,
679 .reserved
= { SAA7191_CONTROL_VNR
, 0 },
683 /* VINO I2C bus functions */
685 unsigned i2c_vino_getctrl(void *data
)
687 return vino
->i2c_control
;
690 void i2c_vino_setctrl(void *data
, unsigned val
)
692 vino
->i2c_control
= val
;
695 unsigned i2c_vino_rdata(void *data
)
697 return vino
->i2c_data
;
700 void i2c_vino_wdata(void *data
, unsigned val
)
702 vino
->i2c_data
= val
;
705 static struct i2c_algo_sgi_data i2c_sgi_vino_data
=
707 .getctrl
= &i2c_vino_getctrl
,
708 .setctrl
= &i2c_vino_setctrl
,
709 .rdata
= &i2c_vino_rdata
,
710 .wdata
= &i2c_vino_wdata
,
716 * There are two possible clients on VINO I2C bus, so we limit usage only
719 static int i2c_vino_client_reg(struct i2c_client
*client
)
724 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
725 switch (client
->driver
->id
) {
726 case I2C_DRIVERID_SAA7191
:
727 if (vino_drvdata
->decoder
.driver
)
730 vino_drvdata
->decoder
.driver
= client
;
732 case I2C_DRIVERID_INDYCAM
:
733 if (vino_drvdata
->camera
.driver
)
736 vino_drvdata
->camera
.driver
= client
;
741 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
746 static int i2c_vino_client_unreg(struct i2c_client
*client
)
751 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
752 if (client
== vino_drvdata
->decoder
.driver
) {
753 if (vino_drvdata
->decoder
.owner
!= VINO_NO_CHANNEL
)
756 vino_drvdata
->decoder
.driver
= NULL
;
757 } else if (client
== vino_drvdata
->camera
.driver
) {
758 if (vino_drvdata
->camera
.owner
!= VINO_NO_CHANNEL
)
761 vino_drvdata
->camera
.driver
= NULL
;
763 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
768 static struct i2c_adapter vino_i2c_adapter
=
770 .name
= "VINO I2C bus",
771 .id
= I2C_HW_SGI_VINO
,
772 .algo_data
= &i2c_sgi_vino_data
,
773 .client_register
= &i2c_vino_client_reg
,
774 .client_unregister
= &i2c_vino_client_unreg
,
777 static int vino_i2c_add_bus(void)
779 return i2c_sgi_add_bus(&vino_i2c_adapter
);
782 static int vino_i2c_del_bus(void)
784 return i2c_del_adapter(&vino_i2c_adapter
);
787 static int i2c_camera_command(unsigned int cmd
, void *arg
)
789 return vino_drvdata
->camera
.driver
->
790 driver
->command(vino_drvdata
->camera
.driver
,
794 static int i2c_decoder_command(unsigned int cmd
, void *arg
)
796 return vino_drvdata
->decoder
.driver
->
797 driver
->command(vino_drvdata
->decoder
.driver
,
801 /* VINO framebuffer/DMA descriptor management */
803 static void vino_free_buffer_with_count(struct vino_framebuffer
*fb
,
808 dprintk("vino_free_buffer_with_count(): count = %d\n", count
);
810 for (i
= 0; i
< count
; i
++) {
811 ClearPageReserved(virt_to_page(fb
->desc_table
.virtual[i
]));
812 dma_unmap_single(NULL
,
813 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
814 PAGE_SIZE
, DMA_FROM_DEVICE
);
815 free_page(fb
->desc_table
.virtual[i
]);
818 dma_free_coherent(NULL
,
819 VINO_PAGE_RATIO
* (fb
->desc_table
.page_count
+ 4) *
820 sizeof(dma_addr_t
), (void *)fb
->desc_table
.dma_cpu
,
822 kfree(fb
->desc_table
.virtual);
824 memset(fb
, 0, sizeof(struct vino_framebuffer
));
827 static void vino_free_buffer(struct vino_framebuffer
*fb
)
829 vino_free_buffer_with_count(fb
, fb
->desc_table
.page_count
);
832 static int vino_allocate_buffer(struct vino_framebuffer
*fb
,
835 unsigned int count
, i
, j
;
838 dprintk("vino_allocate_buffer():\n");
843 memset(fb
, 0, sizeof(struct vino_framebuffer
));
845 count
= ((size
/ PAGE_SIZE
) + 4) & ~3;
847 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
850 /* allocate memory for table with virtual (page) addresses */
851 fb
->desc_table
.virtual = (unsigned long *)
852 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
853 if (!fb
->desc_table
.virtual)
856 /* allocate memory for table with dma addresses
857 * (has space for four extra descriptors) */
858 fb
->desc_table
.dma_cpu
=
859 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
860 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
861 GFP_KERNEL
| GFP_DMA
);
862 if (!fb
->desc_table
.dma_cpu
) {
864 goto out_free_virtual
;
867 /* allocate pages for the buffer and acquire the according
869 for (i
= 0; i
< count
; i
++) {
870 dma_addr_t dma_data_addr
;
872 fb
->desc_table
.virtual[i
] =
873 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
874 if (!fb
->desc_table
.virtual[i
]) {
881 (void *)fb
->desc_table
.virtual[i
],
882 PAGE_SIZE
, DMA_FROM_DEVICE
);
884 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
885 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
886 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
889 SetPageReserved(virt_to_page(fb
->desc_table
.virtual[i
]));
892 /* page_count needs to be set anyway, because the descriptor table has
893 * been allocated according to this number */
894 fb
->desc_table
.page_count
= count
;
897 /* the descriptor with index i doesn't contain
898 * a valid address yet */
899 vino_free_buffer_with_count(fb
, i
);
904 fb
->size
= count
* PAGE_SIZE
;
905 fb
->data_format
= VINO_DATA_FMT_NONE
;
907 /* set the dma stop-bit for the last (count+1)th descriptor */
908 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
912 kfree(fb
->desc_table
.virtual);
917 /* user buffers not fully implemented yet */
918 static int vino_prepare_user_buffer(struct vino_framebuffer
*fb
,
922 unsigned int count
, i
, j
;
925 dprintk("vino_prepare_user_buffer():\n");
930 memset(fb
, 0, sizeof(struct vino_framebuffer
));
932 count
= ((size
/ PAGE_SIZE
)) & ~3;
934 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
937 /* allocate memory for table with virtual (page) addresses */
938 fb
->desc_table
.virtual = (unsigned long *)
939 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
940 if (!fb
->desc_table
.virtual)
943 /* allocate memory for table with dma addresses
944 * (has space for four extra descriptors) */
945 fb
->desc_table
.dma_cpu
=
946 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
947 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
948 GFP_KERNEL
| GFP_DMA
);
949 if (!fb
->desc_table
.dma_cpu
) {
951 goto out_free_virtual
;
954 /* allocate pages for the buffer and acquire the according
956 for (i
= 0; i
< count
; i
++) {
957 dma_addr_t dma_data_addr
;
959 fb
->desc_table
.virtual[i
] =
960 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
961 if (!fb
->desc_table
.virtual[i
]) {
968 (void *)fb
->desc_table
.virtual[i
],
969 PAGE_SIZE
, DMA_FROM_DEVICE
);
971 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
972 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
973 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
976 SetPageReserved(virt_to_page(fb
->desc_table
.virtual[i
]));
979 /* page_count needs to be set anyway, because the descriptor table has
980 * been allocated according to this number */
981 fb
->desc_table
.page_count
= count
;
984 /* the descriptor with index i doesn't contain
985 * a valid address yet */
986 vino_free_buffer_with_count(fb
, i
);
991 fb
->size
= count
* PAGE_SIZE
;
993 /* set the dma stop-bit for the last (count+1)th descriptor */
994 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
998 kfree(fb
->desc_table
.virtual);
1003 static void vino_sync_buffer(struct vino_framebuffer
*fb
)
1007 dprintk("vino_sync_buffer():\n");
1009 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++)
1010 dma_sync_single(NULL
,
1011 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
1012 PAGE_SIZE
, DMA_FROM_DEVICE
);
1015 /* Framebuffer fifo functions (need to be locked externally) */
1017 static inline void vino_fifo_init(struct vino_framebuffer_fifo
*f
,
1018 unsigned int length
)
1025 if (length
> VINO_FRAMEBUFFER_COUNT_MAX
)
1026 length
= VINO_FRAMEBUFFER_COUNT_MAX
;
1031 /* returns true/false */
1032 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo
*f
,
1037 for (i
= f
->head
; i
== (f
->tail
- 1); i
= (i
+ 1) % f
->length
) {
1038 if (f
->data
[i
] == id
)
1046 /* returns true/false */
1047 static inline int vino_fifo_full(struct vino_framebuffer_fifo
*f
)
1049 return (f
->used
== f
->length
);
1053 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo
*f
)
1058 static int vino_fifo_enqueue(struct vino_framebuffer_fifo
*f
, unsigned int id
)
1060 if (id
>= f
->length
) {
1061 return VINO_QUEUE_ERROR
;
1064 if (vino_fifo_has_id(f
, id
)) {
1065 return VINO_QUEUE_ERROR
;
1068 if (f
->used
< f
->length
) {
1069 f
->data
[f
->tail
] = id
;
1070 f
->tail
= (f
->tail
+ 1) % f
->length
;
1073 return VINO_QUEUE_ERROR
;
1079 static int vino_fifo_peek(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
1082 *id
= f
->data
[f
->head
];
1084 return VINO_QUEUE_ERROR
;
1090 static int vino_fifo_dequeue(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
1093 *id
= f
->data
[f
->head
];
1094 f
->head
= (f
->head
+ 1) % f
->length
;
1097 return VINO_QUEUE_ERROR
;
1103 /* Framebuffer queue functions */
1105 /* execute with queue_lock locked */
1106 static void vino_queue_free_with_count(struct vino_framebuffer_queue
*q
,
1107 unsigned int length
)
1112 memset(&q
->in
, 0, sizeof(struct vino_framebuffer_fifo
));
1113 memset(&q
->out
, 0, sizeof(struct vino_framebuffer_fifo
));
1114 for (i
= 0; i
< length
; i
++) {
1115 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
1117 vino_free_buffer(q
->buffer
[i
]);
1118 kfree(q
->buffer
[i
]);
1121 q
->type
= VINO_MEMORY_NONE
;
1125 static void vino_queue_free(struct vino_framebuffer_queue
*q
)
1127 dprintk("vino_queue_free():\n");
1129 if (q
->magic
!= VINO_QUEUE_MAGIC
)
1131 if (q
->type
!= VINO_MEMORY_MMAP
)
1134 mutex_lock(&q
->queue_mutex
);
1136 vino_queue_free_with_count(q
, q
->length
);
1138 mutex_unlock(&q
->queue_mutex
);
1141 static int vino_queue_init(struct vino_framebuffer_queue
*q
,
1142 unsigned int *length
)
1147 dprintk("vino_queue_init(): length = %d\n", *length
);
1149 if (q
->magic
== VINO_QUEUE_MAGIC
) {
1150 dprintk("vino_queue_init(): queue already initialized!\n");
1154 if (q
->type
!= VINO_MEMORY_NONE
) {
1155 dprintk("vino_queue_init(): queue already initialized!\n");
1162 mutex_lock(&q
->queue_mutex
);
1164 if (*length
> VINO_FRAMEBUFFER_COUNT_MAX
)
1165 *length
= VINO_FRAMEBUFFER_COUNT_MAX
;
1169 for (i
= 0; i
< *length
; i
++) {
1170 dprintk("vino_queue_init(): allocating buffer %d\n", i
);
1171 q
->buffer
[i
] = kmalloc(sizeof(struct vino_framebuffer
),
1173 if (!q
->buffer
[i
]) {
1174 dprintk("vino_queue_init(): kmalloc() failed\n");
1179 ret
= vino_allocate_buffer(q
->buffer
[i
],
1180 VINO_FRAMEBUFFER_SIZE
);
1182 kfree(q
->buffer
[i
]);
1183 dprintk("vino_queue_init(): "
1184 "vino_allocate_buffer() failed\n");
1188 q
->buffer
[i
]->id
= i
;
1190 q
->buffer
[i
]->offset
= q
->buffer
[i
- 1]->offset
+
1191 q
->buffer
[i
- 1]->size
;
1193 q
->buffer
[i
]->offset
= 0;
1196 spin_lock_init(&q
->buffer
[i
]->state_lock
);
1198 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1199 "size = %d\n", i
, q
->buffer
[i
]->offset
,
1200 q
->buffer
[i
]->size
);
1204 vino_queue_free_with_count(q
, i
);
1207 q
->length
= *length
;
1208 vino_fifo_init(&q
->in
, q
->length
);
1209 vino_fifo_init(&q
->out
, q
->length
);
1210 q
->type
= VINO_MEMORY_MMAP
;
1211 q
->magic
= VINO_QUEUE_MAGIC
;
1214 mutex_unlock(&q
->queue_mutex
);
1219 static struct vino_framebuffer
*vino_queue_add(struct
1220 vino_framebuffer_queue
*q
,
1223 struct vino_framebuffer
*ret
= NULL
;
1225 unsigned long flags
;
1227 dprintk("vino_queue_add(): id = %d\n", id
);
1229 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1233 spin_lock_irqsave(&q
->queue_lock
, flags
);
1238 if (id
>= q
->length
)
1241 /* not needed?: if (vino_fifo_full(&q->out)) {
1244 /* check that outgoing queue isn't already full
1245 * (or that it won't become full) */
1246 total
= vino_fifo_get_used(&q
->in
) +
1247 vino_fifo_get_used(&q
->out
);
1248 if (total
>= q
->length
)
1251 if (vino_fifo_enqueue(&q
->in
, id
))
1254 ret
= q
->buffer
[id
];
1257 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1262 static struct vino_framebuffer
*vino_queue_transfer(struct
1263 vino_framebuffer_queue
*q
)
1265 struct vino_framebuffer
*ret
= NULL
;
1266 struct vino_framebuffer
*fb
;
1268 unsigned long flags
;
1270 dprintk("vino_queue_transfer():\n");
1272 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1276 spin_lock_irqsave(&q
->queue_lock
, flags
);
1281 // now this actually removes an entry from the incoming queue
1282 if (vino_fifo_dequeue(&q
->in
, &id
)) {
1286 dprintk("vino_queue_transfer(): id = %d\n", id
);
1289 // we have already checked that the outgoing queue is not full, but...
1290 if (vino_fifo_enqueue(&q
->out
, id
)) {
1291 printk(KERN_ERR
"vino_queue_transfer(): "
1292 "outgoing queue is full, this shouldn't happen!\n");
1298 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1303 /* returns true/false */
1304 static int vino_queue_incoming_contains(struct vino_framebuffer_queue
*q
,
1308 unsigned long flags
;
1310 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1314 spin_lock_irqsave(&q
->queue_lock
, flags
);
1319 ret
= vino_fifo_has_id(&q
->in
, id
);
1322 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1327 /* returns true/false */
1328 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue
*q
,
1332 unsigned long flags
;
1334 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1338 spin_lock_irqsave(&q
->queue_lock
, flags
);
1343 ret
= vino_fifo_has_id(&q
->out
, id
);
1346 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1351 static int vino_queue_get_incoming(struct vino_framebuffer_queue
*q
,
1355 unsigned long flags
;
1357 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1358 return VINO_QUEUE_ERROR
;
1361 spin_lock_irqsave(&q
->queue_lock
, flags
);
1363 if (q
->length
== 0) {
1364 ret
= VINO_QUEUE_ERROR
;
1368 *used
= vino_fifo_get_used(&q
->in
);
1371 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1376 static int vino_queue_get_outgoing(struct vino_framebuffer_queue
*q
,
1380 unsigned long flags
;
1382 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1383 return VINO_QUEUE_ERROR
;
1386 spin_lock_irqsave(&q
->queue_lock
, flags
);
1388 if (q
->length
== 0) {
1389 ret
= VINO_QUEUE_ERROR
;
1393 *used
= vino_fifo_get_used(&q
->out
);
1396 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1402 static int vino_queue_get_total(struct vino_framebuffer_queue
*q
,
1403 unsigned int *total
)
1406 unsigned long flags
;
1408 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1409 return VINO_QUEUE_ERROR
;
1412 spin_lock_irqsave(&q
->queue_lock
, flags
);
1414 if (q
->length
== 0) {
1415 ret
= VINO_QUEUE_ERROR
;
1419 *total
= vino_fifo_get_used(&q
->in
) +
1420 vino_fifo_get_used(&q
->out
);
1423 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1429 static struct vino_framebuffer
*vino_queue_peek(struct
1430 vino_framebuffer_queue
*q
,
1433 struct vino_framebuffer
*ret
= NULL
;
1434 unsigned long flags
;
1436 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1440 spin_lock_irqsave(&q
->queue_lock
, flags
);
1445 if (vino_fifo_peek(&q
->in
, id
)) {
1449 ret
= q
->buffer
[*id
];
1451 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1456 static struct vino_framebuffer
*vino_queue_remove(struct
1457 vino_framebuffer_queue
*q
,
1460 struct vino_framebuffer
*ret
= NULL
;
1461 unsigned long flags
;
1462 dprintk("vino_queue_remove():\n");
1464 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1468 spin_lock_irqsave(&q
->queue_lock
, flags
);
1473 if (vino_fifo_dequeue(&q
->out
, id
)) {
1477 dprintk("vino_queue_remove(): id = %d\n", *id
);
1478 ret
= q
->buffer
[*id
];
1480 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1486 vino_framebuffer
*vino_queue_get_buffer(struct vino_framebuffer_queue
*q
,
1489 struct vino_framebuffer
*ret
= NULL
;
1490 unsigned long flags
;
1492 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1496 spin_lock_irqsave(&q
->queue_lock
, flags
);
1501 if (id
>= q
->length
)
1504 ret
= q
->buffer
[id
];
1506 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1511 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue
*q
)
1513 unsigned int length
= 0;
1514 unsigned long flags
;
1516 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1520 spin_lock_irqsave(&q
->queue_lock
, flags
);
1522 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1527 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue
*q
)
1531 unsigned long flags
;
1533 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1537 spin_lock_irqsave(&q
->queue_lock
, flags
);
1538 for (i
= 0; i
< q
->length
; i
++) {
1539 if (q
->buffer
[i
]->map_count
> 0) {
1544 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1549 /* VINO functions */
1551 /* execute with input_lock locked */
1552 static void vino_update_line_size(struct vino_channel_settings
*vcs
)
1554 unsigned int w
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1555 unsigned int d
= vcs
->decimation
;
1556 unsigned int bpp
= vino_data_formats
[vcs
->data_format
].bpp
;
1559 dprintk("update_line_size(): before: w = %d, d = %d, "
1560 "line_size = %d\n", w
, d
, vcs
->line_size
);
1562 /* line size must be multiple of 8 bytes */
1563 lsize
= (bpp
* (w
/ d
)) & ~7;
1564 w
= (lsize
/ bpp
) * d
;
1566 vcs
->clipping
.right
= vcs
->clipping
.left
+ w
;
1567 vcs
->line_size
= lsize
;
1569 dprintk("update_line_size(): after: w = %d, d = %d, "
1570 "line_size = %d\n", w
, d
, vcs
->line_size
);
1573 /* execute with input_lock locked */
1574 static void vino_set_clipping(struct vino_channel_settings
*vcs
,
1575 unsigned int x
, unsigned int y
,
1576 unsigned int w
, unsigned int h
)
1578 unsigned int maxwidth
, maxheight
;
1581 maxwidth
= vino_data_norms
[vcs
->data_norm
].width
;
1582 maxheight
= vino_data_norms
[vcs
->data_norm
].height
;
1583 d
= vcs
->decimation
;
1585 y
&= ~1; /* odd/even fields */
1590 if (y
> maxheight
) {
1594 if (((w
/ d
) < VINO_MIN_WIDTH
)
1595 || ((h
/ d
) < VINO_MIN_HEIGHT
)) {
1596 w
= VINO_MIN_WIDTH
* d
;
1597 h
= VINO_MIN_HEIGHT
* d
;
1600 if ((x
+ w
) > maxwidth
) {
1602 if ((w
/ d
) < VINO_MIN_WIDTH
)
1603 x
= maxwidth
- VINO_MIN_WIDTH
* d
;
1605 if ((y
+ h
) > maxheight
) {
1607 if ((h
/ d
) < VINO_MIN_HEIGHT
)
1608 y
= maxheight
- VINO_MIN_HEIGHT
* d
;
1611 vcs
->clipping
.left
= x
;
1612 vcs
->clipping
.top
= y
;
1613 vcs
->clipping
.right
= x
+ w
;
1614 vcs
->clipping
.bottom
= y
+ h
;
1616 vino_update_line_size(vcs
);
1618 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1619 vcs
->clipping
.left
, vcs
->clipping
.top
, vcs
->clipping
.right
,
1620 vcs
->clipping
.bottom
, vcs
->decimation
, vcs
->line_size
);
1623 /* execute with input_lock locked */
1624 static inline void vino_set_default_clipping(struct vino_channel_settings
*vcs
)
1626 vino_set_clipping(vcs
, 0, 0, vino_data_norms
[vcs
->data_norm
].width
,
1627 vino_data_norms
[vcs
->data_norm
].height
);
1630 /* execute with input_lock locked */
1631 static void vino_set_scaling(struct vino_channel_settings
*vcs
,
1632 unsigned int w
, unsigned int h
)
1634 unsigned int x
, y
, curw
, curh
, d
;
1636 x
= vcs
->clipping
.left
;
1637 y
= vcs
->clipping
.top
;
1638 curw
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1639 curh
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
1641 d
= max(curw
/ w
, curh
/ h
);
1643 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1644 w
, h
, curw
, curh
, d
);
1652 vcs
->decimation
= d
;
1653 vino_set_clipping(vcs
, x
, y
, w
* d
, h
* d
);
1655 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs
->clipping
.left
,
1656 vcs
->clipping
.top
, vcs
->clipping
.right
, vcs
->clipping
.bottom
,
1657 vcs
->decimation
, vcs
->line_size
);
1660 /* execute with input_lock locked */
1661 static inline void vino_set_default_scaling(struct vino_channel_settings
*vcs
)
1663 vino_set_scaling(vcs
, vcs
->clipping
.right
- vcs
->clipping
.left
,
1664 vcs
->clipping
.bottom
- vcs
->clipping
.top
);
1667 /* execute with input_lock locked */
1668 static void vino_set_framerate(struct vino_channel_settings
*vcs
,
1673 switch (vcs
->data_norm
) {
1674 case VINO_DATA_NORM_NTSC
:
1675 case VINO_DATA_NORM_D1
:
1676 fps
= (unsigned int)(fps
/ 6) * 6; // FIXME: round!
1678 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1679 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1680 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1681 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1700 mask
= VINO_FRAMERT_FULL
;
1702 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
);
1704 case VINO_DATA_NORM_PAL
:
1705 case VINO_DATA_NORM_SECAM
:
1706 fps
= (unsigned int)(fps
/ 5) * 5; // FIXME: round!
1708 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1709 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1710 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1711 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1730 mask
= VINO_FRAMERT_FULL
;
1732 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
) | VINO_FRAMERT_PAL
;
1739 /* execute with input_lock locked */
1740 static inline void vino_set_default_framerate(struct
1741 vino_channel_settings
*vcs
)
1743 vino_set_framerate(vcs
, vino_data_norms
[vcs
->data_norm
].fps_max
);
1747 * Prepare VINO for DMA transfer...
1748 * (execute only with vino_lock and input_lock locked)
1750 static int vino_dma_setup(struct vino_channel_settings
*vcs
,
1751 struct vino_framebuffer
*fb
)
1754 struct sgi_vino_channel
*ch
;
1755 const struct vino_data_norm
*norm
;
1757 dprintk("vino_dma_setup():\n");
1760 fb
->frame_counter
= 0;
1762 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1763 norm
= &vino_data_norms
[vcs
->data_norm
];
1768 /* VINO line size register is set 8 bytes less than actual */
1769 ch
->line_size
= vcs
->line_size
- 8;
1771 /* let VINO know where to transfer data */
1772 ch
->start_desc_tbl
= fb
->desc_table
.dma
;
1773 ch
->next_4_desc
= fb
->desc_table
.dma
;
1775 /* give vino time to fetch the first four descriptors, 5 usec
1776 * should be more than enough time */
1777 udelay(VINO_DESC_FETCH_DELAY
);
1779 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1780 ch
->start_desc_tbl
, ch
->next_4_desc
);
1782 /* set the alpha register */
1783 ch
->alpha
= vcs
->alpha
;
1785 /* set clipping registers */
1786 ch
->clip_start
= VINO_CLIP_ODD(norm
->odd
.top
+ vcs
->clipping
.top
/ 2) |
1787 VINO_CLIP_EVEN(norm
->even
.top
+
1788 vcs
->clipping
.top
/ 2) |
1789 VINO_CLIP_X(vcs
->clipping
.left
);
1790 ch
->clip_end
= VINO_CLIP_ODD(norm
->odd
.top
+
1791 vcs
->clipping
.bottom
/ 2 - 1) |
1792 VINO_CLIP_EVEN(norm
->even
.top
+
1793 vcs
->clipping
.bottom
/ 2 - 1) |
1794 VINO_CLIP_X(vcs
->clipping
.right
);
1796 /* set the size of actual content in the buffer (DECIMATION !) */
1797 fb
->data_size
= ((vcs
->clipping
.right
- vcs
->clipping
.left
) /
1799 ((vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
1801 vino_data_formats
[vcs
->data_format
].bpp
;
1803 ch
->frame_rate
= vcs
->framert_reg
;
1805 ctrl
= vino
->control
;
1806 intr
= vino
->intr_status
;
1808 if (vcs
->channel
== VINO_CHANNEL_A
) {
1809 /* All interrupt conditions for this channel was cleared
1810 * so clear the interrupt status register and enable
1812 intr
&= ~VINO_INTSTAT_A
;
1813 ctrl
|= VINO_CTRL_A_INT
;
1815 /* enable synchronization */
1816 ctrl
|= VINO_CTRL_A_SYNC_ENBL
;
1818 /* enable frame assembly */
1819 ctrl
|= VINO_CTRL_A_INTERLEAVE_ENBL
;
1821 /* set decimation used */
1822 if (vcs
->decimation
< 2)
1823 ctrl
&= ~VINO_CTRL_A_DEC_ENBL
;
1825 ctrl
|= VINO_CTRL_A_DEC_ENBL
;
1826 ctrl
&= ~VINO_CTRL_A_DEC_SCALE_MASK
;
1827 ctrl
|= (vcs
->decimation
- 1) <<
1828 VINO_CTRL_A_DEC_SCALE_SHIFT
;
1831 /* select input interface */
1832 if (vcs
->input
== VINO_INPUT_D1
)
1833 ctrl
|= VINO_CTRL_A_SELECT
;
1835 ctrl
&= ~VINO_CTRL_A_SELECT
;
1838 ctrl
&= ~(VINO_CTRL_A_LUMA_ONLY
| VINO_CTRL_A_RGB
|
1839 VINO_CTRL_A_DITHER
);
1841 intr
&= ~VINO_INTSTAT_B
;
1842 ctrl
|= VINO_CTRL_B_INT
;
1844 ctrl
|= VINO_CTRL_B_SYNC_ENBL
;
1845 ctrl
|= VINO_CTRL_B_INTERLEAVE_ENBL
;
1847 if (vcs
->decimation
< 2)
1848 ctrl
&= ~VINO_CTRL_B_DEC_ENBL
;
1850 ctrl
|= VINO_CTRL_B_DEC_ENBL
;
1851 ctrl
&= ~VINO_CTRL_B_DEC_SCALE_MASK
;
1852 ctrl
|= (vcs
->decimation
- 1) <<
1853 VINO_CTRL_B_DEC_SCALE_SHIFT
;
1856 if (vcs
->input
== VINO_INPUT_D1
)
1857 ctrl
|= VINO_CTRL_B_SELECT
;
1859 ctrl
&= ~VINO_CTRL_B_SELECT
;
1861 ctrl
&= ~(VINO_CTRL_B_LUMA_ONLY
| VINO_CTRL_B_RGB
|
1862 VINO_CTRL_B_DITHER
);
1866 fb
->data_format
= vcs
->data_format
;
1868 switch (vcs
->data_format
) {
1869 case VINO_DATA_FMT_GREY
:
1870 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1871 VINO_CTRL_A_LUMA_ONLY
: VINO_CTRL_B_LUMA_ONLY
;
1873 case VINO_DATA_FMT_RGB32
:
1874 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1875 VINO_CTRL_A_RGB
: VINO_CTRL_B_RGB
;
1877 case VINO_DATA_FMT_YUV
:
1878 /* nothing needs to be done */
1880 case VINO_DATA_FMT_RGB332
:
1881 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1882 VINO_CTRL_A_RGB
| VINO_CTRL_A_DITHER
:
1883 VINO_CTRL_B_RGB
| VINO_CTRL_B_DITHER
;
1887 vino
->intr_status
= intr
;
1888 vino
->control
= ctrl
;
1893 /* (execute only with vino_lock locked) */
1894 static inline void vino_dma_start(struct vino_channel_settings
*vcs
)
1896 u32 ctrl
= vino
->control
;
1898 dprintk("vino_dma_start():\n");
1899 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1900 VINO_CTRL_A_DMA_ENBL
: VINO_CTRL_B_DMA_ENBL
;
1901 vino
->control
= ctrl
;
1904 /* (execute only with vino_lock locked) */
1905 static inline void vino_dma_stop(struct vino_channel_settings
*vcs
)
1907 u32 ctrl
= vino
->control
;
1909 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1910 ~VINO_CTRL_A_DMA_ENBL
: ~VINO_CTRL_B_DMA_ENBL
;
1911 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1912 ~VINO_CTRL_A_INT
: ~VINO_CTRL_B_INT
;
1913 vino
->control
= ctrl
;
1914 dprintk("vino_dma_stop():\n");
1918 * Load dummy page to descriptor registers. This prevents generating of
1919 * spurious interrupts. (execute only with vino_lock locked)
1921 static void vino_clear_interrupt(struct vino_channel_settings
*vcs
)
1923 struct sgi_vino_channel
*ch
;
1925 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1930 ch
->start_desc_tbl
= vino_drvdata
->dummy_desc_table
.dma
;
1931 ch
->next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
1933 udelay(VINO_DESC_FETCH_DELAY
);
1934 dprintk("channel %c clear interrupt condition\n",
1935 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A':'B');
1938 static int vino_capture(struct vino_channel_settings
*vcs
,
1939 struct vino_framebuffer
*fb
)
1942 unsigned long flags
, flags2
;
1944 spin_lock_irqsave(&fb
->state_lock
, flags
);
1946 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
1948 fb
->state
= VINO_FRAMEBUFFER_IN_USE
;
1950 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
1955 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
1956 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags2
);
1958 vino_dma_setup(vcs
, fb
);
1959 vino_dma_start(vcs
);
1961 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags2
);
1962 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
1968 struct vino_framebuffer
*vino_capture_enqueue(struct
1969 vino_channel_settings
*vcs
,
1972 struct vino_framebuffer
*fb
;
1973 unsigned long flags
;
1975 dprintk("vino_capture_enqueue():\n");
1977 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
1979 fb
= vino_queue_add(&vcs
->fb_queue
, index
);
1981 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
1986 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1991 static int vino_capture_next(struct vino_channel_settings
*vcs
, int start
)
1993 struct vino_framebuffer
*fb
;
1994 unsigned int incoming
, id
;
1996 unsigned long flags
;
1998 dprintk("vino_capture_next():\n");
2000 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2003 /* start capture only if capture isn't in progress already */
2004 if (vcs
->capturing
) {
2005 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2010 /* capture next frame:
2011 * stop capture if capturing is not set */
2012 if (!vcs
->capturing
) {
2013 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2018 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
2020 dprintk("vino_capture_next(): vino_queue_get_incoming() "
2025 if (incoming
== 0) {
2026 dprintk("vino_capture_next(): no buffers available\n");
2030 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2032 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
2041 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2043 err
= vino_capture(vcs
, fb
);
2049 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2054 static inline int vino_is_capturing(struct vino_channel_settings
*vcs
)
2057 unsigned long flags
;
2059 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2061 ret
= vcs
->capturing
;
2063 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2068 /* waits until a frame is captured */
2069 static int vino_wait_for_frame(struct vino_channel_settings
*vcs
)
2074 dprintk("vino_wait_for_frame():\n");
2076 init_waitqueue_entry(&wait
, current
);
2077 /* add ourselves into wait queue */
2078 add_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2080 /* to ensure that schedule_timeout will return immediately
2081 * if VINO interrupt was triggered meanwhile */
2082 schedule_timeout_interruptible(msecs_to_jiffies(100));
2084 if (signal_pending(current
))
2087 remove_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2089 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2090 err
? "failed" : "ok");
2095 /* the function assumes that PAGE_SIZE % 4 == 0 */
2096 static void vino_convert_to_rgba(struct vino_framebuffer
*fb
) {
2097 unsigned char *pageptr
;
2098 unsigned int page
, i
;
2101 for (page
= 0; page
< fb
->desc_table
.page_count
; page
++) {
2102 pageptr
= (unsigned char *)fb
->desc_table
.virtual[page
];
2104 for (i
= 0; i
< PAGE_SIZE
; i
+= 4) {
2106 pageptr
[0] = pageptr
[3];
2107 pageptr
[1] = pageptr
[2];
2108 pageptr
[2] = pageptr
[1];
2115 /* checks if the buffer is in correct state and syncs data */
2116 static int vino_check_buffer(struct vino_channel_settings
*vcs
,
2117 struct vino_framebuffer
*fb
)
2120 unsigned long flags
;
2122 dprintk("vino_check_buffer():\n");
2124 spin_lock_irqsave(&fb
->state_lock
, flags
);
2125 switch (fb
->state
) {
2126 case VINO_FRAMEBUFFER_IN_USE
:
2129 case VINO_FRAMEBUFFER_READY
:
2130 vino_sync_buffer(fb
);
2131 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2136 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2139 if (vino_pixel_conversion
2140 && (fb
->data_format
== VINO_DATA_FMT_RGB32
)) {
2141 vino_convert_to_rgba(fb
);
2143 } else if (err
&& (err
!= -EINVAL
)) {
2144 dprintk("vino_check_buffer(): buffer not ready\n");
2146 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2148 vino_clear_interrupt(vcs
);
2149 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2155 /* forcefully terminates capture */
2156 static void vino_capture_stop(struct vino_channel_settings
*vcs
)
2158 unsigned int incoming
= 0, outgoing
= 0, id
;
2159 unsigned long flags
, flags2
;
2161 dprintk("vino_capture_stop():\n");
2163 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2165 /* unset capturing to stop queue processing */
2168 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags2
);
2171 vino_clear_interrupt(vcs
);
2173 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags2
);
2175 /* remove all items from the queue */
2176 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2177 dprintk("vino_capture_stop(): "
2178 "vino_queue_get_incoming() failed\n");
2181 while (incoming
> 0) {
2182 vino_queue_transfer(&vcs
->fb_queue
);
2184 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2185 dprintk("vino_capture_stop(): "
2186 "vino_queue_get_incoming() failed\n");
2191 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2192 dprintk("vino_capture_stop(): "
2193 "vino_queue_get_outgoing() failed\n");
2196 while (outgoing
> 0) {
2197 vino_queue_remove(&vcs
->fb_queue
, &id
);
2199 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2200 dprintk("vino_capture_stop(): "
2201 "vino_queue_get_outgoing() failed\n");
2207 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2211 static int vino_capture_failed(struct vino_channel_settings
*vcs
)
2213 struct vino_framebuffer
*fb
;
2214 unsigned long flags
;
2218 dprintk("vino_capture_failed():\n");
2220 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2223 vino_clear_interrupt(vcs
);
2225 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2227 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &i
);
2228 if (ret
== VINO_QUEUE_ERROR
) {
2229 dprintk("vino_queue_get_incoming() failed\n");
2233 /* no buffers to process */
2237 fb
= vino_queue_peek(&vcs
->fb_queue
, &i
);
2239 dprintk("vino_queue_peek() failed\n");
2243 spin_lock_irqsave(&fb
->state_lock
, flags
);
2244 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
) {
2245 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2246 vino_queue_transfer(&vcs
->fb_queue
);
2247 vino_queue_remove(&vcs
->fb_queue
, &i
);
2248 /* we should actually discard the newest frame,
2249 * but who cares ... */
2251 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2257 static void vino_skip_frame(struct vino_channel_settings
*vcs
)
2259 struct vino_framebuffer
*fb
;
2260 unsigned long flags
;
2263 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2264 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2266 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2267 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2270 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2272 spin_lock_irqsave(&fb
->state_lock
, flags
);
2273 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2274 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2276 vino_capture_next(vcs
, 0);
2279 static void vino_frame_done(struct vino_channel_settings
*vcs
)
2281 struct vino_framebuffer
*fb
;
2282 unsigned long flags
;
2284 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2285 fb
= vino_queue_transfer(&vcs
->fb_queue
);
2287 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2288 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2291 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2293 fb
->frame_counter
= vcs
->int_data
.frame_counter
;
2294 memcpy(&fb
->timestamp
, &vcs
->int_data
.timestamp
,
2295 sizeof(struct timeval
));
2297 spin_lock_irqsave(&fb
->state_lock
, flags
);
2298 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
2299 fb
->state
= VINO_FRAMEBUFFER_READY
;
2300 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2302 wake_up(&vcs
->fb_queue
.frame_wait_queue
);
2304 vino_capture_next(vcs
, 0);
2307 static void vino_capture_tasklet(unsigned long channel
) {
2308 struct vino_channel_settings
*vcs
;
2310 vcs
= (channel
== VINO_CHANNEL_A
)
2311 ? &vino_drvdata
->a
: &vino_drvdata
->b
;
2313 if (vcs
->int_data
.skip
)
2314 vcs
->int_data
.skip_count
++;
2316 if (vcs
->int_data
.skip
&& (vcs
->int_data
.skip_count
2317 <= VINO_MAX_FRAME_SKIP_COUNT
)) {
2318 vino_skip_frame(vcs
);
2320 vcs
->int_data
.skip_count
= 0;
2321 vino_frame_done(vcs
);
2325 static irqreturn_t
vino_interrupt(int irq
, void *dev_id
)
2328 unsigned int fc_a
, fc_b
;
2329 int handled_a
= 0, skip_a
= 0, done_a
= 0;
2330 int handled_b
= 0, skip_b
= 0, done_b
= 0;
2332 #ifdef VINO_DEBUG_INT
2334 unsigned int line_count
= vino
->a
.line_count
,
2335 page_index
= vino
->a
.page_index
,
2336 field_counter
= vino
->a
.field_counter
,
2337 start_desc_tbl
= vino
->a
.start_desc_tbl
,
2338 next_4_desc
= vino
->a
.next_4_desc
;
2339 unsigned int line_count_2
,
2346 spin_lock(&vino_drvdata
->vino_lock
);
2348 while ((intr
= vino
->intr_status
)) {
2349 fc_a
= vino
->a
.field_counter
>> 1;
2350 fc_b
= vino
->b
.field_counter
>> 1;
2352 /* handle error-interrupts in some special way ?
2353 * --> skips frames */
2354 if (intr
& VINO_INTSTAT_A
) {
2355 if (intr
& VINO_INTSTAT_A_EOF
) {
2356 vino_drvdata
->a
.field
++;
2357 if (vino_drvdata
->a
.field
> 1) {
2358 vino_dma_stop(&vino_drvdata
->a
);
2359 vino_clear_interrupt(&vino_drvdata
->a
);
2360 vino_drvdata
->a
.field
= 0;
2363 if (vino
->a
.page_index
2364 != vino_drvdata
->a
.line_size
) {
2365 vino
->a
.line_count
= 0;
2366 vino
->a
.page_index
=
2369 vino
->a
.next_4_desc
=
2370 vino
->a
.start_desc_tbl
;
2373 dprintk("channel A end-of-field "
2374 "interrupt: %04x\n", intr
);
2376 vino_dma_stop(&vino_drvdata
->a
);
2377 vino_clear_interrupt(&vino_drvdata
->a
);
2378 vino_drvdata
->a
.field
= 0;
2380 dprintk("channel A error interrupt: %04x\n",
2384 #ifdef VINO_DEBUG_INT
2385 line_count_2
= vino
->a
.line_count
;
2386 page_index_2
= vino
->a
.page_index
;
2387 field_counter_2
= vino
->a
.field_counter
;
2388 start_desc_tbl_2
= vino
->a
.start_desc_tbl
;
2389 next_4_desc_2
= vino
->a
.next_4_desc
;
2391 printk("intr = %04x, loop = %d, field = %d\n",
2392 intr
, loop
, vino_drvdata
->a
.field
);
2393 printk("1- line count = %04d, page index = %04d, "
2394 "start = %08x, next = %08x\n"
2395 " fieldc = %d, framec = %d\n",
2396 line_count
, page_index
, start_desc_tbl
,
2397 next_4_desc
, field_counter
, fc_a
);
2398 printk("12-line count = %04d, page index = %04d, "
2399 " start = %08x, next = %08x\n",
2400 line_count_2
, page_index_2
, start_desc_tbl_2
,
2408 if (intr
& VINO_INTSTAT_B
) {
2409 if (intr
& VINO_INTSTAT_B_EOF
) {
2410 vino_drvdata
->b
.field
++;
2411 if (vino_drvdata
->b
.field
> 1) {
2412 vino_dma_stop(&vino_drvdata
->b
);
2413 vino_clear_interrupt(&vino_drvdata
->b
);
2414 vino_drvdata
->b
.field
= 0;
2417 dprintk("channel B end-of-field "
2418 "interrupt: %04x\n", intr
);
2420 vino_dma_stop(&vino_drvdata
->b
);
2421 vino_clear_interrupt(&vino_drvdata
->b
);
2422 vino_drvdata
->b
.field
= 0;
2424 dprintk("channel B error interrupt: %04x\n",
2429 /* Always remember to clear interrupt status.
2430 * Disable VINO interrupts while we do this. */
2431 ctrl
= vino
->control
;
2432 vino
->control
= ctrl
& ~(VINO_CTRL_A_INT
| VINO_CTRL_B_INT
);
2433 vino
->intr_status
= ~intr
;
2434 vino
->control
= ctrl
;
2436 spin_unlock(&vino_drvdata
->vino_lock
);
2438 if ((!handled_a
) && (done_a
|| skip_a
)) {
2440 do_gettimeofday(&vino_drvdata
->
2441 a
.int_data
.timestamp
);
2442 vino_drvdata
->a
.int_data
.frame_counter
= fc_a
;
2444 vino_drvdata
->a
.int_data
.skip
= skip_a
;
2446 dprintk("channel A %s, interrupt: %d\n",
2447 skip_a
? "skipping frame" : "frame done",
2449 tasklet_hi_schedule(&vino_tasklet_a
);
2453 if ((!handled_b
) && (done_b
|| skip_b
)) {
2455 do_gettimeofday(&vino_drvdata
->
2456 b
.int_data
.timestamp
);
2457 vino_drvdata
->b
.int_data
.frame_counter
= fc_b
;
2459 vino_drvdata
->b
.int_data
.skip
= skip_b
;
2461 dprintk("channel B %s, interrupt: %d\n",
2462 skip_b
? "skipping frame" : "frame done",
2464 tasklet_hi_schedule(&vino_tasklet_b
);
2468 #ifdef VINO_DEBUG_INT
2471 spin_lock(&vino_drvdata
->vino_lock
);
2474 spin_unlock(&vino_drvdata
->vino_lock
);
2479 /* VINO video input management */
2481 static int vino_get_saa7191_input(int input
)
2484 case VINO_INPUT_COMPOSITE
:
2485 return SAA7191_INPUT_COMPOSITE
;
2486 case VINO_INPUT_SVIDEO
:
2487 return SAA7191_INPUT_SVIDEO
;
2489 printk(KERN_ERR
"VINO: vino_get_saa7191_input(): "
2490 "invalid input!\n");
2495 static int vino_get_saa7191_norm(unsigned int data_norm
)
2497 switch (data_norm
) {
2498 case VINO_DATA_NORM_AUTO
:
2499 return SAA7191_NORM_AUTO
;
2500 case VINO_DATA_NORM_AUTO_EXT
:
2501 return SAA7191_NORM_AUTO_EXT
;
2502 case VINO_DATA_NORM_PAL
:
2503 return SAA7191_NORM_PAL
;
2504 case VINO_DATA_NORM_NTSC
:
2505 return SAA7191_NORM_NTSC
;
2506 case VINO_DATA_NORM_SECAM
:
2507 return SAA7191_NORM_SECAM
;
2509 printk(KERN_ERR
"VINO: vino_get_saa7191_norm(): "
2515 static int vino_get_from_saa7191_norm(int saa7191_norm
)
2517 switch (saa7191_norm
) {
2518 case SAA7191_NORM_PAL
:
2519 return VINO_DATA_NORM_PAL
;
2520 case SAA7191_NORM_NTSC
:
2521 return VINO_DATA_NORM_NTSC
;
2522 case SAA7191_NORM_SECAM
:
2523 return VINO_DATA_NORM_SECAM
;
2525 printk(KERN_ERR
"VINO: vino_get_from_saa7191_norm(): "
2527 return VINO_DATA_NORM_NONE
;
2531 static int vino_saa7191_set_norm(unsigned int *data_norm
)
2533 int saa7191_norm
, new_data_norm
;
2536 saa7191_norm
= vino_get_saa7191_norm(*data_norm
);
2538 err
= i2c_decoder_command(DECODER_SAA7191_SET_NORM
,
2543 if ((*data_norm
== VINO_DATA_NORM_AUTO
)
2544 || (*data_norm
== VINO_DATA_NORM_AUTO_EXT
)) {
2545 struct saa7191_status status
;
2547 err
= i2c_decoder_command(DECODER_SAA7191_GET_STATUS
,
2553 vino_get_from_saa7191_norm(status
.norm
);
2554 if (new_data_norm
== VINO_DATA_NORM_NONE
) {
2559 *data_norm
= (unsigned int)new_data_norm
;
2566 /* execute with input_lock locked */
2567 static int vino_is_input_owner(struct vino_channel_settings
*vcs
)
2569 switch(vcs
->input
) {
2570 case VINO_INPUT_COMPOSITE
:
2571 case VINO_INPUT_SVIDEO
:
2572 return (vino_drvdata
->decoder
.owner
== vcs
->channel
);
2574 return (vino_drvdata
->camera
.owner
== vcs
->channel
);
2580 static int vino_acquire_input(struct vino_channel_settings
*vcs
)
2582 unsigned long flags
;
2585 dprintk("vino_acquire_input():\n");
2587 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2589 /* First try D1 and then SAA7191 */
2590 if (vino_drvdata
->camera
.driver
2591 && (vino_drvdata
->camera
.owner
== VINO_NO_CHANNEL
)) {
2592 if (i2c_use_client(vino_drvdata
->camera
.driver
)) {
2597 vino_drvdata
->camera
.owner
= vcs
->channel
;
2598 vcs
->input
= VINO_INPUT_D1
;
2599 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2600 } else if (vino_drvdata
->decoder
.driver
2601 && (vino_drvdata
->decoder
.owner
== VINO_NO_CHANNEL
)) {
2602 int input
, data_norm
;
2605 if (i2c_use_client(vino_drvdata
->decoder
.driver
)) {
2610 input
= VINO_INPUT_COMPOSITE
;
2612 saa7191_input
= vino_get_saa7191_input(input
);
2613 ret
= i2c_decoder_command(DECODER_SET_INPUT
,
2620 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2622 /* Don't hold spinlocks while auto-detecting norm
2623 * as it may take a while... */
2625 data_norm
= VINO_DATA_NORM_AUTO_EXT
;
2627 ret
= vino_saa7191_set_norm(&data_norm
);
2628 if ((ret
== -EBUSY
) || (ret
== -EAGAIN
)) {
2629 data_norm
= VINO_DATA_NORM_PAL
;
2630 ret
= vino_saa7191_set_norm(&data_norm
);
2633 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2640 vino_drvdata
->decoder
.owner
= vcs
->channel
;
2643 vcs
->data_norm
= data_norm
;
2645 vcs
->input
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2646 vino_drvdata
->b
.input
: vino_drvdata
->a
.input
;
2647 vcs
->data_norm
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2648 vino_drvdata
->b
.data_norm
: vino_drvdata
->a
.data_norm
;
2651 if (vcs
->input
== VINO_INPUT_NONE
) {
2656 vino_set_default_clipping(vcs
);
2657 vino_set_default_scaling(vcs
);
2658 vino_set_default_framerate(vcs
);
2660 dprintk("vino_acquire_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2663 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2668 static int vino_set_input(struct vino_channel_settings
*vcs
, int input
)
2670 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2671 &vino_drvdata
->b
: &vino_drvdata
->a
;
2672 unsigned long flags
;
2675 dprintk("vino_set_input():\n");
2677 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2679 if (vcs
->input
== input
)
2683 case VINO_INPUT_COMPOSITE
:
2684 case VINO_INPUT_SVIDEO
:
2685 if (!vino_drvdata
->decoder
.driver
) {
2690 if (vino_drvdata
->decoder
.owner
== VINO_NO_CHANNEL
) {
2691 if (i2c_use_client(vino_drvdata
->decoder
.driver
)) {
2695 vino_drvdata
->decoder
.owner
= vcs
->channel
;
2698 if (vino_drvdata
->decoder
.owner
== vcs
->channel
) {
2702 saa7191_input
= vino_get_saa7191_input(input
);
2703 ret
= i2c_decoder_command(DECODER_SET_INPUT
,
2706 vino_drvdata
->decoder
.owner
= VINO_NO_CHANNEL
;
2711 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2713 /* Don't hold spinlocks while auto-detecting norm
2714 * as it may take a while... */
2716 data_norm
= VINO_DATA_NORM_AUTO_EXT
;
2718 ret
= vino_saa7191_set_norm(&data_norm
);
2719 if ((ret
== -EBUSY
) || (ret
== -EAGAIN
)) {
2720 data_norm
= VINO_DATA_NORM_PAL
;
2721 ret
= vino_saa7191_set_norm(&data_norm
);
2724 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2727 vino_drvdata
->decoder
.owner
= VINO_NO_CHANNEL
;
2733 vcs
->data_norm
= data_norm
;
2735 if (input
!= vcs2
->input
) {
2741 vcs
->data_norm
= vcs2
->data_norm
;
2744 if (vino_drvdata
->camera
.owner
== vcs
->channel
) {
2745 /* Transfer the ownership or release the input */
2746 if (vcs2
->input
== VINO_INPUT_D1
) {
2747 vino_drvdata
->camera
.owner
= vcs2
->channel
;
2749 i2c_release_client(vino_drvdata
->
2751 vino_drvdata
->camera
.owner
= VINO_NO_CHANNEL
;
2756 if (!vino_drvdata
->camera
.driver
) {
2761 if (vino_drvdata
->camera
.owner
== VINO_NO_CHANNEL
) {
2762 if (i2c_use_client(vino_drvdata
->camera
.driver
)) {
2766 vino_drvdata
->camera
.owner
= vcs
->channel
;
2769 if (vino_drvdata
->decoder
.owner
== vcs
->channel
) {
2770 /* Transfer the ownership or release the input */
2771 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2772 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2773 vino_drvdata
->decoder
.owner
= vcs2
->channel
;
2775 i2c_release_client(vino_drvdata
->
2777 vino_drvdata
->decoder
.owner
= VINO_NO_CHANNEL
;
2782 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2789 vino_set_default_clipping(vcs
);
2790 vino_set_default_scaling(vcs
);
2791 vino_set_default_framerate(vcs
);
2793 dprintk("vino_set_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2796 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2801 static void vino_release_input(struct vino_channel_settings
*vcs
)
2803 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2804 &vino_drvdata
->b
: &vino_drvdata
->a
;
2805 unsigned long flags
;
2807 dprintk("vino_release_input():\n");
2809 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2811 /* Release ownership of the channel
2812 * and if the other channel takes input from
2813 * the same source, transfer the ownership */
2814 if (vino_drvdata
->camera
.owner
== vcs
->channel
) {
2815 if (vcs2
->input
== VINO_INPUT_D1
) {
2816 vino_drvdata
->camera
.owner
= vcs2
->channel
;
2818 i2c_release_client(vino_drvdata
->camera
.driver
);
2819 vino_drvdata
->camera
.owner
= VINO_NO_CHANNEL
;
2821 } else if (vino_drvdata
->decoder
.owner
== vcs
->channel
) {
2822 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2823 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2824 vino_drvdata
->decoder
.owner
= vcs2
->channel
;
2826 i2c_release_client(vino_drvdata
->decoder
.driver
);
2827 vino_drvdata
->decoder
.owner
= VINO_NO_CHANNEL
;
2830 vcs
->input
= VINO_INPUT_NONE
;
2832 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2835 /* execute with input_lock locked */
2836 static int vino_set_data_norm(struct vino_channel_settings
*vcs
,
2837 unsigned int data_norm
,
2838 unsigned long *flags
)
2842 if (data_norm
== vcs
->data_norm
)
2845 switch (vcs
->input
) {
2847 /* only one "norm" supported */
2848 if ((data_norm
!= VINO_DATA_NORM_D1
)
2849 && (data_norm
!= VINO_DATA_NORM_AUTO
)
2850 && (data_norm
!= VINO_DATA_NORM_AUTO_EXT
))
2853 case VINO_INPUT_COMPOSITE
:
2854 case VINO_INPUT_SVIDEO
: {
2855 if ((data_norm
!= VINO_DATA_NORM_PAL
)
2856 && (data_norm
!= VINO_DATA_NORM_NTSC
)
2857 && (data_norm
!= VINO_DATA_NORM_SECAM
)
2858 && (data_norm
!= VINO_DATA_NORM_AUTO
)
2859 && (data_norm
!= VINO_DATA_NORM_AUTO_EXT
))
2862 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, *flags
);
2864 /* Don't hold spinlocks while setting norm
2865 * as it may take a while... */
2867 err
= vino_saa7191_set_norm(&data_norm
);
2869 spin_lock_irqsave(&vino_drvdata
->input_lock
, *flags
);
2874 vcs
->data_norm
= data_norm
;
2876 vino_set_default_clipping(vcs
);
2877 vino_set_default_scaling(vcs
);
2878 vino_set_default_framerate(vcs
);
2889 /* V4L2 helper functions */
2891 static int vino_find_data_format(__u32 pixelformat
)
2895 for (i
= 0; i
< VINO_DATA_FMT_COUNT
; i
++) {
2896 if (vino_data_formats
[i
].pixelformat
== pixelformat
)
2900 return VINO_DATA_FMT_NONE
;
2903 static int vino_enum_data_norm(struct vino_channel_settings
*vcs
, __u32 index
)
2905 int data_norm
= VINO_DATA_NORM_NONE
;
2906 unsigned long flags
;
2908 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2909 switch(vcs
->input
) {
2910 case VINO_INPUT_COMPOSITE
:
2911 case VINO_INPUT_SVIDEO
:
2913 data_norm
= VINO_DATA_NORM_PAL
;
2914 } else if (index
== 1) {
2915 data_norm
= VINO_DATA_NORM_NTSC
;
2916 } else if (index
== 2) {
2917 data_norm
= VINO_DATA_NORM_SECAM
;
2922 data_norm
= VINO_DATA_NORM_D1
;
2926 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2931 static int vino_enum_input(struct vino_channel_settings
*vcs
, __u32 index
)
2933 int input
= VINO_INPUT_NONE
;
2934 unsigned long flags
;
2936 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2937 if (vino_drvdata
->decoder
.driver
&& vino_drvdata
->camera
.driver
) {
2940 input
= VINO_INPUT_COMPOSITE
;
2943 input
= VINO_INPUT_SVIDEO
;
2946 input
= VINO_INPUT_D1
;
2949 } else if (vino_drvdata
->decoder
.driver
) {
2952 input
= VINO_INPUT_COMPOSITE
;
2955 input
= VINO_INPUT_SVIDEO
;
2958 } else if (vino_drvdata
->camera
.driver
) {
2961 input
= VINO_INPUT_D1
;
2965 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2970 /* execute with input_lock locked */
2971 static __u32
vino_find_input_index(struct vino_channel_settings
*vcs
)
2974 // FIXME: detect when no inputs available
2976 if (vino_drvdata
->decoder
.driver
&& vino_drvdata
->camera
.driver
) {
2977 switch (vcs
->input
) {
2978 case VINO_INPUT_COMPOSITE
:
2981 case VINO_INPUT_SVIDEO
:
2988 } else if (vino_drvdata
->decoder
.driver
) {
2989 switch (vcs
->input
) {
2990 case VINO_INPUT_COMPOSITE
:
2993 case VINO_INPUT_SVIDEO
:
2997 } else if (vino_drvdata
->camera
.driver
) {
2998 switch (vcs
->input
) {
3010 static void vino_v4l2_querycap(struct v4l2_capability
*cap
)
3012 memset(cap
, 0, sizeof(struct v4l2_capability
));
3014 strcpy(cap
->driver
, vino_driver_name
);
3015 strcpy(cap
->card
, vino_driver_description
);
3016 strcpy(cap
->bus_info
, vino_bus_name
);
3017 cap
->version
= VINO_VERSION_CODE
;
3019 V4L2_CAP_VIDEO_CAPTURE
|
3021 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
3024 static int vino_v4l2_enuminput(struct vino_channel_settings
*vcs
,
3025 struct v4l2_input
*i
)
3027 __u32 index
= i
->index
;
3029 dprintk("requested index = %d\n", index
);
3031 input
= vino_enum_input(vcs
, index
);
3032 if (input
== VINO_INPUT_NONE
)
3035 memset(i
, 0, sizeof(struct v4l2_input
));
3038 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
3039 i
->std
= vino_inputs
[input
].std
;
3040 strcpy(i
->name
, vino_inputs
[input
].name
);
3042 if ((input
== VINO_INPUT_COMPOSITE
)
3043 || (input
== VINO_INPUT_SVIDEO
)) {
3044 struct saa7191_status status
;
3045 i2c_decoder_command(DECODER_SAA7191_GET_STATUS
, &status
);
3046 i
->status
|= status
.signal
? 0 : V4L2_IN_ST_NO_SIGNAL
;
3047 i
->status
|= status
.color
? 0 : V4L2_IN_ST_NO_COLOR
;
3053 static int vino_v4l2_g_input(struct vino_channel_settings
*vcs
,
3058 unsigned long flags
;
3060 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3062 index
= vino_find_input_index(vcs
);
3063 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3065 dprintk("input = %d\n", input
);
3067 if (input
== VINO_INPUT_NONE
) {
3076 static int vino_v4l2_s_input(struct vino_channel_settings
*vcs
,
3080 dprintk("requested input = %d\n", *i
);
3082 input
= vino_enum_input(vcs
, *i
);
3083 if (input
== VINO_INPUT_NONE
)
3086 return vino_set_input(vcs
, input
);
3089 static int vino_v4l2_enumstd(struct vino_channel_settings
*vcs
,
3090 struct v4l2_standard
*s
)
3092 int index
= s
->index
;
3095 data_norm
= vino_enum_data_norm(vcs
, index
);
3096 dprintk("standard index = %d\n", index
);
3098 if (data_norm
== VINO_DATA_NORM_NONE
)
3101 dprintk("standard name = %s\n",
3102 vino_data_norms
[data_norm
].description
);
3104 memset(s
, 0, sizeof(struct v4l2_standard
));
3107 s
->id
= vino_data_norms
[data_norm
].std
;
3108 s
->frameperiod
.numerator
= 1;
3109 s
->frameperiod
.denominator
=
3110 vino_data_norms
[data_norm
].fps_max
;
3112 vino_data_norms
[data_norm
].framelines
;
3114 vino_data_norms
[data_norm
].description
);
3119 static int vino_v4l2_querystd(struct vino_channel_settings
*vcs
,
3122 unsigned long flags
;
3125 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3127 switch (vcs
->input
) {
3129 *std
= vino_inputs
[vcs
->input
].std
;
3131 case VINO_INPUT_COMPOSITE
:
3132 case VINO_INPUT_SVIDEO
: {
3133 struct saa7191_status status
;
3135 i2c_decoder_command(DECODER_SAA7191_GET_STATUS
, &status
);
3137 if (status
.signal
) {
3138 if (status
.signal_60hz
) {
3139 *std
= V4L2_STD_NTSC
;
3141 *std
= V4L2_STD_PAL
| V4L2_STD_SECAM
;
3144 *std
= vino_inputs
[vcs
->input
].std
;
3152 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3157 static int vino_v4l2_g_std(struct vino_channel_settings
*vcs
,
3160 unsigned long flags
;
3162 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3164 *std
= vino_data_norms
[vcs
->data_norm
].std
;
3165 dprintk("current standard = %d\n", vcs
->data_norm
);
3167 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3172 static int vino_v4l2_s_std(struct vino_channel_settings
*vcs
,
3175 unsigned long flags
;
3178 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3180 if (!vino_is_input_owner(vcs
)) {
3185 /* check if the standard is valid for the current input */
3186 if ((*std
) & vino_inputs
[vcs
->input
].std
) {
3187 dprintk("standard accepted\n");
3189 /* change the video norm for SAA7191
3190 * and accept NTSC for D1 (do nothing) */
3192 if (vcs
->input
== VINO_INPUT_D1
)
3195 if (((*std
) & V4L2_STD_PAL
)
3196 && ((*std
) & V4L2_STD_NTSC
)
3197 && ((*std
) & V4L2_STD_SECAM
)) {
3198 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_AUTO_EXT
,
3200 } else if ((*std
) & V4L2_STD_PAL
) {
3201 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_PAL
,
3203 } else if ((*std
) & V4L2_STD_NTSC
) {
3204 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_NTSC
,
3206 } else if ((*std
) & V4L2_STD_SECAM
) {
3207 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_SECAM
,
3221 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3226 static int vino_v4l2_enum_fmt(struct vino_channel_settings
*vcs
,
3227 struct v4l2_fmtdesc
*fd
)
3229 enum v4l2_buf_type type
= fd
->type
;
3230 int index
= fd
->index
;
3231 dprintk("format index = %d\n", index
);
3234 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3235 if ((fd
->index
< 0) ||
3236 (fd
->index
>= VINO_DATA_FMT_COUNT
))
3238 dprintk("format name = %s\n",
3239 vino_data_formats
[index
].description
);
3241 memset(fd
, 0, sizeof(struct v4l2_fmtdesc
));
3244 fd
->pixelformat
= vino_data_formats
[index
].pixelformat
;
3245 strcpy(fd
->description
, vino_data_formats
[index
].description
);
3247 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3255 static int vino_v4l2_try_fmt(struct vino_channel_settings
*vcs
,
3256 struct v4l2_format
*f
)
3258 struct vino_channel_settings tempvcs
;
3259 unsigned long flags
;
3262 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3263 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3265 dprintk("requested: w = %d, h = %d\n",
3266 pf
->width
, pf
->height
);
3268 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3269 memcpy(&tempvcs
, vcs
, sizeof(struct vino_channel_settings
));
3270 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3272 tempvcs
.data_format
= vino_find_data_format(pf
->pixelformat
);
3273 if (tempvcs
.data_format
== VINO_DATA_FMT_NONE
) {
3274 tempvcs
.data_format
= VINO_DATA_FMT_GREY
;
3276 vino_data_formats
[tempvcs
.data_format
].
3280 /* data format must be set before clipping/scaling */
3281 vino_set_scaling(&tempvcs
, pf
->width
, pf
->height
);
3283 dprintk("data format = %s\n",
3284 vino_data_formats
[tempvcs
.data_format
].description
);
3286 pf
->width
= (tempvcs
.clipping
.right
- tempvcs
.clipping
.left
) /
3288 pf
->height
= (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3291 pf
->field
= V4L2_FIELD_INTERLACED
;
3292 pf
->bytesperline
= tempvcs
.line_size
;
3293 pf
->sizeimage
= tempvcs
.line_size
*
3294 (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3297 vino_data_formats
[tempvcs
.data_format
].colorspace
;
3302 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3310 static int vino_v4l2_g_fmt(struct vino_channel_settings
*vcs
,
3311 struct v4l2_format
*f
)
3313 unsigned long flags
;
3316 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3317 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3319 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3321 pf
->width
= (vcs
->clipping
.right
- vcs
->clipping
.left
) /
3323 pf
->height
= (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3326 vino_data_formats
[vcs
->data_format
].pixelformat
;
3328 pf
->field
= V4L2_FIELD_INTERLACED
;
3329 pf
->bytesperline
= vcs
->line_size
;
3330 pf
->sizeimage
= vcs
->line_size
*
3331 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3334 vino_data_formats
[vcs
->data_format
].colorspace
;
3338 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3341 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3349 static int vino_v4l2_s_fmt(struct vino_channel_settings
*vcs
,
3350 struct v4l2_format
*f
)
3353 unsigned long flags
;
3356 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3357 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3359 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3361 data_format
= vino_find_data_format(pf
->pixelformat
);
3363 if (data_format
== VINO_DATA_FMT_NONE
) {
3364 vcs
->data_format
= VINO_DATA_FMT_GREY
;
3366 vino_data_formats
[vcs
->data_format
].
3369 vcs
->data_format
= data_format
;
3372 /* data format must be set before clipping/scaling */
3373 vino_set_scaling(vcs
, pf
->width
, pf
->height
);
3375 dprintk("data format = %s\n",
3376 vino_data_formats
[vcs
->data_format
].description
);
3378 pf
->width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3379 pf
->height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3381 pf
->field
= V4L2_FIELD_INTERLACED
;
3382 pf
->bytesperline
= vcs
->line_size
;
3383 pf
->sizeimage
= vcs
->line_size
*
3384 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3387 vino_data_formats
[vcs
->data_format
].colorspace
;
3391 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3394 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3402 static int vino_v4l2_cropcap(struct vino_channel_settings
*vcs
,
3403 struct v4l2_cropcap
*ccap
)
3405 const struct vino_data_norm
*norm
;
3406 unsigned long flags
;
3408 switch (ccap
->type
) {
3409 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3410 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3412 norm
= &vino_data_norms
[vcs
->data_norm
];
3414 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3416 ccap
->bounds
.left
= 0;
3417 ccap
->bounds
.top
= 0;
3418 ccap
->bounds
.width
= norm
->width
;
3419 ccap
->bounds
.height
= norm
->height
;
3420 memcpy(&ccap
->defrect
, &ccap
->bounds
,
3421 sizeof(struct v4l2_rect
));
3423 ccap
->pixelaspect
.numerator
= 1;
3424 ccap
->pixelaspect
.denominator
= 1;
3426 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3434 static int vino_v4l2_g_crop(struct vino_channel_settings
*vcs
,
3435 struct v4l2_crop
*c
)
3437 unsigned long flags
;
3440 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3441 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3443 c
->c
.left
= vcs
->clipping
.left
;
3444 c
->c
.top
= vcs
->clipping
.top
;
3445 c
->c
.width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3446 c
->c
.height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3448 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3450 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3458 static int vino_v4l2_s_crop(struct vino_channel_settings
*vcs
,
3459 struct v4l2_crop
*c
)
3461 unsigned long flags
;
3464 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3465 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3467 vino_set_clipping(vcs
, c
->c
.left
, c
->c
.top
,
3468 c
->c
.width
, c
->c
.height
);
3470 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3472 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3480 static int vino_v4l2_g_parm(struct vino_channel_settings
*vcs
,
3481 struct v4l2_streamparm
*sp
)
3483 unsigned long flags
;
3486 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3487 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3488 memset(cp
, 0, sizeof(struct v4l2_captureparm
));
3490 cp
->capability
= V4L2_CAP_TIMEPERFRAME
;
3491 cp
->timeperframe
.numerator
= 1;
3493 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3495 cp
->timeperframe
.denominator
= vcs
->fps
;
3497 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3499 // TODO: cp->readbuffers = xxx;
3502 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3510 static int vino_v4l2_s_parm(struct vino_channel_settings
*vcs
,
3511 struct v4l2_streamparm
*sp
)
3513 unsigned long flags
;
3516 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3517 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3519 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3521 if ((cp
->timeperframe
.numerator
== 0) ||
3522 (cp
->timeperframe
.denominator
== 0)) {
3523 /* reset framerate */
3524 vino_set_default_framerate(vcs
);
3526 vino_set_framerate(vcs
, cp
->timeperframe
.denominator
/
3527 cp
->timeperframe
.numerator
);
3530 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3532 // TODO: set buffers according to cp->readbuffers
3535 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3543 static int vino_v4l2_reqbufs(struct vino_channel_settings
*vcs
,
3544 struct v4l2_requestbuffers
*rb
)
3550 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3551 // TODO: check queue type
3552 if (rb
->memory
!= V4L2_MEMORY_MMAP
) {
3553 dprintk("type not mmap\n");
3557 dprintk("count = %d\n", rb
->count
);
3558 if (rb
->count
> 0) {
3559 if (vino_is_capturing(vcs
)) {
3560 dprintk("busy, capturing\n");
3564 if (vino_queue_has_mapped_buffers(&vcs
->fb_queue
)) {
3565 dprintk("busy, buffers still mapped\n");
3569 vino_queue_free(&vcs
->fb_queue
);
3570 vino_queue_init(&vcs
->fb_queue
, &rb
->count
);
3574 vino_capture_stop(vcs
);
3575 vino_queue_free(&vcs
->fb_queue
);
3579 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3587 static void vino_v4l2_get_buffer_status(struct vino_channel_settings
*vcs
,
3588 struct vino_framebuffer
*fb
,
3589 struct v4l2_buffer
*b
)
3591 if (vino_queue_outgoing_contains(&vcs
->fb_queue
,
3593 b
->flags
&= ~V4L2_BUF_FLAG_QUEUED
;
3594 b
->flags
|= V4L2_BUF_FLAG_DONE
;
3595 } else if (vino_queue_incoming_contains(&vcs
->fb_queue
,
3597 b
->flags
&= ~V4L2_BUF_FLAG_DONE
;
3598 b
->flags
|= V4L2_BUF_FLAG_QUEUED
;
3600 b
->flags
&= ~(V4L2_BUF_FLAG_DONE
|
3601 V4L2_BUF_FLAG_QUEUED
);
3604 b
->flags
&= ~(V4L2_BUF_FLAG_TIMECODE
);
3606 if (fb
->map_count
> 0)
3607 b
->flags
|= V4L2_BUF_FLAG_MAPPED
;
3610 b
->memory
= (vcs
->fb_queue
.type
== VINO_MEMORY_MMAP
) ?
3611 V4L2_MEMORY_MMAP
: V4L2_MEMORY_USERPTR
;
3612 b
->m
.offset
= fb
->offset
;
3613 b
->bytesused
= fb
->data_size
;
3614 b
->length
= fb
->size
;
3615 b
->field
= V4L2_FIELD_INTERLACED
;
3616 b
->sequence
= fb
->frame_counter
;
3617 memcpy(&b
->timestamp
, &fb
->timestamp
,
3618 sizeof(struct timeval
));
3621 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3622 fb
->id
, fb
->size
, fb
->data_size
, fb
->offset
);
3625 static int vino_v4l2_querybuf(struct vino_channel_settings
*vcs
,
3626 struct v4l2_buffer
*b
)
3632 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3633 struct vino_framebuffer
*fb
;
3635 // TODO: check queue type
3636 if (b
->index
>= vino_queue_get_length(&vcs
->fb_queue
)) {
3637 dprintk("invalid index = %d\n",
3642 fb
= vino_queue_get_buffer(&vcs
->fb_queue
,
3645 dprintk("vino_queue_get_buffer() failed");
3649 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3652 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3660 static int vino_v4l2_qbuf(struct vino_channel_settings
*vcs
,
3661 struct v4l2_buffer
*b
)
3667 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3668 struct vino_framebuffer
*fb
;
3671 // TODO: check queue type
3672 if (b
->memory
!= V4L2_MEMORY_MMAP
) {
3673 dprintk("type not mmap\n");
3677 fb
= vino_capture_enqueue(vcs
, b
->index
);
3681 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3683 if (vcs
->streaming
) {
3684 ret
= vino_capture_next(vcs
, 1);
3690 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3698 static int vino_v4l2_dqbuf(struct vino_channel_settings
*vcs
,
3699 struct v4l2_buffer
*b
,
3700 unsigned int nonblocking
)
3706 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3707 struct vino_framebuffer
*fb
;
3708 unsigned int incoming
, outgoing
;
3711 // TODO: check queue type
3713 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3715 dprintk("vino_queue_get_incoming() failed\n");
3718 err
= vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
);
3720 dprintk("vino_queue_get_outgoing() failed\n");
3724 dprintk("incoming = %d, outgoing = %d\n", incoming
, outgoing
);
3726 if (outgoing
== 0) {
3727 if (incoming
== 0) {
3728 dprintk("no incoming or outgoing buffers\n");
3732 dprintk("non-blocking I/O was selected and "
3733 "there are no buffers to dequeue\n");
3737 err
= vino_wait_for_frame(vcs
);
3739 err
= vino_wait_for_frame(vcs
);
3742 * no frames captured because
3743 * of frame skipping */
3744 // vino_capture_failed(vcs);
3750 fb
= vino_queue_remove(&vcs
->fb_queue
, &b
->index
);
3752 dprintk("vino_queue_remove() failed\n");
3756 err
= vino_check_buffer(vcs
, fb
);
3758 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3765 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3773 static int vino_v4l2_streamon(struct vino_channel_settings
*vcs
)
3775 unsigned int incoming
;
3783 // TODO: check queue type
3785 if (vino_queue_get_length(&vcs
->fb_queue
) < 1) {
3786 dprintk("no buffers allocated\n");
3790 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3792 dprintk("vino_queue_get_incoming() failed\n");
3799 ret
= vino_capture_next(vcs
, 1);
3803 dprintk("couldn't start capture\n");
3811 static int vino_v4l2_streamoff(struct vino_channel_settings
*vcs
)
3816 if (!vcs
->streaming
)
3820 vino_capture_stop(vcs
);
3825 static int vino_v4l2_queryctrl(struct vino_channel_settings
*vcs
,
3826 struct v4l2_queryctrl
*queryctrl
)
3828 unsigned long flags
;
3832 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3834 switch (vcs
->input
) {
3836 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3837 if (vino_indycam_v4l2_controls
[i
].id
==
3840 &vino_indycam_v4l2_controls
[i
],
3841 sizeof(struct v4l2_queryctrl
));
3842 queryctrl
->reserved
[0] = 0;
3849 case VINO_INPUT_COMPOSITE
:
3850 case VINO_INPUT_SVIDEO
:
3851 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3852 if (vino_saa7191_v4l2_controls
[i
].id
==
3855 &vino_saa7191_v4l2_controls
[i
],
3856 sizeof(struct v4l2_queryctrl
));
3857 queryctrl
->reserved
[0] = 0;
3869 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3874 static int vino_v4l2_g_ctrl(struct vino_channel_settings
*vcs
,
3875 struct v4l2_control
*control
)
3877 unsigned long flags
;
3881 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3883 switch (vcs
->input
) {
3884 case VINO_INPUT_D1
: {
3885 struct indycam_control indycam_ctrl
;
3887 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3888 if (vino_indycam_v4l2_controls
[i
].id
==
3898 indycam_ctrl
.type
= vino_indycam_v4l2_controls
[i
].reserved
[0];
3900 err
= i2c_camera_command(DECODER_INDYCAM_GET_CONTROL
,
3907 control
->value
= indycam_ctrl
.value
;
3910 case VINO_INPUT_COMPOSITE
:
3911 case VINO_INPUT_SVIDEO
: {
3912 struct saa7191_control saa7191_ctrl
;
3914 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3915 if (vino_saa7191_v4l2_controls
[i
].id
==
3925 saa7191_ctrl
.type
= vino_saa7191_v4l2_controls
[i
].reserved
[0];
3927 err
= i2c_decoder_command(DECODER_SAA7191_GET_CONTROL
,
3934 control
->value
= saa7191_ctrl
.value
;
3942 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3947 static int vino_v4l2_s_ctrl(struct vino_channel_settings
*vcs
,
3948 struct v4l2_control
*control
)
3950 unsigned long flags
;
3954 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3956 if (!vino_is_input_owner(vcs
)) {
3961 switch (vcs
->input
) {
3962 case VINO_INPUT_D1
: {
3963 struct indycam_control indycam_ctrl
;
3965 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3966 if (vino_indycam_v4l2_controls
[i
].id
==
3968 if ((control
->value
>=
3969 vino_indycam_v4l2_controls
[i
].minimum
)
3970 && (control
->value
<=
3971 vino_indycam_v4l2_controls
[i
].
3985 indycam_ctrl
.type
= vino_indycam_v4l2_controls
[i
].reserved
[0];
3986 indycam_ctrl
.value
= control
->value
;
3988 err
= i2c_camera_command(DECODER_INDYCAM_SET_CONTROL
,
3994 case VINO_INPUT_COMPOSITE
:
3995 case VINO_INPUT_SVIDEO
: {
3996 struct saa7191_control saa7191_ctrl
;
3998 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3999 if (vino_saa7191_v4l2_controls
[i
].id
==
4001 if ((control
->value
>=
4002 vino_saa7191_v4l2_controls
[i
].minimum
)
4003 && (control
->value
<=
4004 vino_saa7191_v4l2_controls
[i
].
4017 saa7191_ctrl
.type
= vino_saa7191_v4l2_controls
[i
].reserved
[0];
4018 saa7191_ctrl
.value
= control
->value
;
4020 err
= i2c_decoder_command(DECODER_SAA7191_SET_CONTROL
,
4031 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
4036 /* File operations */
4038 static int vino_open(struct inode
*inode
, struct file
*file
)
4040 struct video_device
*dev
= video_devdata(file
);
4041 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4043 dprintk("open(): channel = %c\n",
4044 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A' : 'B');
4046 mutex_lock(&vcs
->mutex
);
4049 dprintk("open(): driver busy\n");
4054 ret
= vino_acquire_input(vcs
);
4056 dprintk("open(): vino_acquire_input() failed\n");
4063 mutex_unlock(&vcs
->mutex
);
4065 dprintk("open(): %s!\n", ret
? "failed" : "complete");
4070 static int vino_close(struct inode
*inode
, struct file
*file
)
4072 struct video_device
*dev
= video_devdata(file
);
4073 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4074 dprintk("close():\n");
4076 mutex_lock(&vcs
->mutex
);
4081 vino_release_input(vcs
);
4083 /* stop DMA and free buffers */
4084 vino_capture_stop(vcs
);
4085 vino_queue_free(&vcs
->fb_queue
);
4088 mutex_unlock(&vcs
->mutex
);
4093 static void vino_vm_open(struct vm_area_struct
*vma
)
4095 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
4098 dprintk("vino_vm_open(): count = %d\n", fb
->map_count
);
4101 static void vino_vm_close(struct vm_area_struct
*vma
)
4103 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
4106 dprintk("vino_vm_close(): count = %d\n", fb
->map_count
);
4109 static struct vm_operations_struct vino_vm_ops
= {
4110 .open
= vino_vm_open
,
4111 .close
= vino_vm_close
,
4114 static int vino_mmap(struct file
*file
, struct vm_area_struct
*vma
)
4116 struct video_device
*dev
= video_devdata(file
);
4117 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4119 unsigned long start
= vma
->vm_start
;
4120 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
4121 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
4123 struct vino_framebuffer
*fb
= NULL
;
4124 unsigned int i
, length
;
4127 dprintk("mmap():\n");
4129 // TODO: reject mmap if already mapped
4131 if (mutex_lock_interruptible(&vcs
->mutex
))
4139 // TODO: check queue type
4141 if (!(vma
->vm_flags
& VM_WRITE
)) {
4142 dprintk("mmap(): app bug: PROT_WRITE please\n");
4146 if (!(vma
->vm_flags
& VM_SHARED
)) {
4147 dprintk("mmap(): app bug: MAP_SHARED please\n");
4152 /* find the correct buffer using offset */
4153 length
= vino_queue_get_length(&vcs
->fb_queue
);
4155 dprintk("mmap(): queue not initialized\n");
4160 for (i
= 0; i
< length
; i
++) {
4161 fb
= vino_queue_get_buffer(&vcs
->fb_queue
, i
);
4163 dprintk("mmap(): vino_queue_get_buffer() failed\n");
4168 if (fb
->offset
== offset
)
4172 dprintk("mmap(): invalid offset = %lu\n", offset
);
4177 dprintk("mmap(): buffer = %d\n", i
);
4179 if (size
> (fb
->desc_table
.page_count
* PAGE_SIZE
)) {
4180 dprintk("mmap(): failed: size = %lu > %lu\n",
4181 size
, fb
->desc_table
.page_count
* PAGE_SIZE
);
4186 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++) {
4188 virt_to_phys((void *)fb
->desc_table
.virtual[i
]) >>
4191 if (size
< PAGE_SIZE
)
4194 // protection was: PAGE_READONLY
4195 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
,
4196 vma
->vm_page_prot
)) {
4197 dprintk("mmap(): remap_pfn_range() failed\n");
4208 vma
->vm_flags
|= VM_DONTEXPAND
| VM_RESERVED
;
4209 vma
->vm_flags
&= ~VM_IO
;
4210 vma
->vm_private_data
= fb
;
4211 vma
->vm_file
= file
;
4212 vma
->vm_ops
= &vino_vm_ops
;
4215 mutex_unlock(&vcs
->mutex
);
4220 static unsigned int vino_poll(struct file
*file
, poll_table
*pt
)
4222 struct video_device
*dev
= video_devdata(file
);
4223 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4224 unsigned int outgoing
;
4225 unsigned int ret
= 0;
4228 // TODO: this has to be corrected for different read modes
4230 dprintk("poll():\n");
4232 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
4233 dprintk("poll(): vino_queue_get_outgoing() failed\n");
4240 poll_wait(file
, &vcs
->fb_queue
.frame_wait_queue
, pt
);
4242 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
4243 dprintk("poll(): vino_queue_get_outgoing() failed\n");
4249 dprintk("poll(): data %savailable\n",
4250 (outgoing
> 0) ? "" : "not ");
4253 ret
= POLLIN
| POLLRDNORM
;
4260 static int vino_do_ioctl(struct inode
*inode
, struct file
*file
,
4261 unsigned int cmd
, void *arg
)
4263 struct video_device
*dev
= video_devdata(file
);
4264 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4267 switch (_IOC_TYPE(cmd
)) {
4269 dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd
);
4272 dprintk("ioctl(): V4L2 %s (0x%08x)\n",
4273 v4l2_ioctl_names
[_IOC_NR(cmd
)], cmd
);
4276 dprintk("ioctl(): unsupported command 0x%08x\n", cmd
);
4281 /* V4L2 interface */
4282 case VIDIOC_QUERYCAP
: {
4283 vino_v4l2_querycap(arg
);
4286 case VIDIOC_ENUMINPUT
: {
4287 return vino_v4l2_enuminput(vcs
, arg
);
4289 case VIDIOC_G_INPUT
: {
4290 return vino_v4l2_g_input(vcs
, arg
);
4292 case VIDIOC_S_INPUT
: {
4293 return vino_v4l2_s_input(vcs
, arg
);
4295 case VIDIOC_ENUMSTD
: {
4296 return vino_v4l2_enumstd(vcs
, arg
);
4298 case VIDIOC_QUERYSTD
: {
4299 return vino_v4l2_querystd(vcs
, arg
);
4301 case VIDIOC_G_STD
: {
4302 return vino_v4l2_g_std(vcs
, arg
);
4304 case VIDIOC_S_STD
: {
4305 return vino_v4l2_s_std(vcs
, arg
);
4307 case VIDIOC_ENUM_FMT
: {
4308 return vino_v4l2_enum_fmt(vcs
, arg
);
4310 case VIDIOC_TRY_FMT
: {
4311 return vino_v4l2_try_fmt(vcs
, arg
);
4313 case VIDIOC_G_FMT
: {
4314 return vino_v4l2_g_fmt(vcs
, arg
);
4316 case VIDIOC_S_FMT
: {
4317 return vino_v4l2_s_fmt(vcs
, arg
);
4319 case VIDIOC_CROPCAP
: {
4320 return vino_v4l2_cropcap(vcs
, arg
);
4322 case VIDIOC_G_CROP
: {
4323 return vino_v4l2_g_crop(vcs
, arg
);
4325 case VIDIOC_S_CROP
: {
4326 return vino_v4l2_s_crop(vcs
, arg
);
4328 case VIDIOC_G_PARM
: {
4329 return vino_v4l2_g_parm(vcs
, arg
);
4331 case VIDIOC_S_PARM
: {
4332 return vino_v4l2_s_parm(vcs
, arg
);
4334 case VIDIOC_REQBUFS
: {
4335 return vino_v4l2_reqbufs(vcs
, arg
);
4337 case VIDIOC_QUERYBUF
: {
4338 return vino_v4l2_querybuf(vcs
, arg
);
4341 return vino_v4l2_qbuf(vcs
, arg
);
4343 case VIDIOC_DQBUF
: {
4344 return vino_v4l2_dqbuf(vcs
, arg
, file
->f_flags
& O_NONBLOCK
);
4346 case VIDIOC_STREAMON
: {
4347 return vino_v4l2_streamon(vcs
);
4349 case VIDIOC_STREAMOFF
: {
4350 return vino_v4l2_streamoff(vcs
);
4352 case VIDIOC_QUERYCTRL
: {
4353 return vino_v4l2_queryctrl(vcs
, arg
);
4355 case VIDIOC_G_CTRL
: {
4356 return vino_v4l2_g_ctrl(vcs
, arg
);
4358 case VIDIOC_S_CTRL
: {
4359 return vino_v4l2_s_ctrl(vcs
, arg
);
4362 return -ENOIOCTLCMD
;
4368 static int vino_ioctl(struct inode
*inode
, struct file
*file
,
4369 unsigned int cmd
, unsigned long arg
)
4371 struct video_device
*dev
= video_devdata(file
);
4372 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4375 if (mutex_lock_interruptible(&vcs
->mutex
))
4378 ret
= video_usercopy(inode
, file
, cmd
, arg
, vino_do_ioctl
);
4380 mutex_unlock(&vcs
->mutex
);
4385 /* Initialization and cleanup */
4388 static int vino_init_stage
= 0;
4390 static const struct file_operations vino_fops
= {
4391 .owner
= THIS_MODULE
,
4393 .release
= vino_close
,
4394 .ioctl
= vino_ioctl
,
4397 .llseek
= no_llseek
,
4400 static struct video_device v4l_device_template
= {
4402 //.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE |
4403 // VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY
4408 static void vino_module_cleanup(int stage
)
4412 video_unregister_device(vino_drvdata
->b
.v4l_device
);
4413 vino_drvdata
->b
.v4l_device
= NULL
;
4415 video_unregister_device(vino_drvdata
->a
.v4l_device
);
4416 vino_drvdata
->a
.v4l_device
= NULL
;
4420 free_irq(SGI_VINO_IRQ
, NULL
);
4422 if (vino_drvdata
->b
.v4l_device
) {
4423 video_device_release(vino_drvdata
->b
.v4l_device
);
4424 vino_drvdata
->b
.v4l_device
= NULL
;
4427 if (vino_drvdata
->a
.v4l_device
) {
4428 video_device_release(vino_drvdata
->a
.v4l_device
);
4429 vino_drvdata
->a
.v4l_device
= NULL
;
4432 /* all entries in dma_cpu dummy table have the same address */
4433 dma_unmap_single(NULL
,
4434 vino_drvdata
->dummy_desc_table
.dma_cpu
[0],
4435 PAGE_SIZE
, DMA_FROM_DEVICE
);
4436 dma_free_coherent(NULL
, VINO_DUMMY_DESC_COUNT
4437 * sizeof(dma_addr_t
),
4438 (void *)vino_drvdata
->
4439 dummy_desc_table
.dma_cpu
,
4440 vino_drvdata
->dummy_desc_table
.dma
);
4442 free_page(vino_drvdata
->dummy_page
);
4444 kfree(vino_drvdata
);
4450 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4455 static int vino_probe(void)
4457 unsigned long rev_id
;
4459 if (ip22_is_fullhouse()) {
4460 printk(KERN_ERR
"VINO doesn't exist in IP22 Fullhouse\n");
4464 if (!(sgimc
->systemid
& SGIMC_SYSID_EPRESENT
)) {
4465 printk(KERN_ERR
"VINO is not found (EISA BUS not present)\n");
4469 vino
= (struct sgi_vino
*)ioremap(VINO_BASE
, sizeof(struct sgi_vino
));
4471 printk(KERN_ERR
"VINO: ioremap() failed\n");
4476 if (get_dbe(rev_id
, &(vino
->rev_id
))) {
4477 printk(KERN_ERR
"Failed to read VINO revision register\n");
4478 vino_module_cleanup(vino_init_stage
);
4482 if (VINO_ID_VALUE(rev_id
) != VINO_CHIP_ID
) {
4483 printk(KERN_ERR
"Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4485 vino_module_cleanup(vino_init_stage
);
4489 printk(KERN_INFO
"VINO revision %ld found\n", VINO_REV_NUM(rev_id
));
4494 static int vino_init(void)
4496 dma_addr_t dma_dummy_address
;
4499 vino_drvdata
= kzalloc(sizeof(struct vino_settings
), GFP_KERNEL
);
4500 if (!vino_drvdata
) {
4501 vino_module_cleanup(vino_init_stage
);
4506 /* create a dummy dma descriptor */
4507 vino_drvdata
->dummy_page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
4508 if (!vino_drvdata
->dummy_page
) {
4509 vino_module_cleanup(vino_init_stage
);
4514 // TODO: use page_count in dummy_desc_table
4516 vino_drvdata
->dummy_desc_table
.dma_cpu
=
4517 dma_alloc_coherent(NULL
,
4518 VINO_DUMMY_DESC_COUNT
* sizeof(dma_addr_t
),
4519 &vino_drvdata
->dummy_desc_table
.dma
,
4520 GFP_KERNEL
| GFP_DMA
);
4521 if (!vino_drvdata
->dummy_desc_table
.dma_cpu
) {
4522 vino_module_cleanup(vino_init_stage
);
4527 dma_dummy_address
= dma_map_single(NULL
,
4528 (void *)vino_drvdata
->dummy_page
,
4529 PAGE_SIZE
, DMA_FROM_DEVICE
);
4530 for (i
= 0; i
< VINO_DUMMY_DESC_COUNT
; i
++) {
4531 vino_drvdata
->dummy_desc_table
.dma_cpu
[i
] = dma_dummy_address
;
4534 /* initialize VINO */
4537 vino
->a
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4538 vino
->b
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4539 udelay(VINO_DESC_FETCH_DELAY
);
4541 vino
->intr_status
= 0;
4543 vino
->a
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4544 vino
->b
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4549 static int vino_init_channel_settings(struct vino_channel_settings
*vcs
,
4550 unsigned int channel
, const char *name
)
4552 vcs
->channel
= channel
;
4553 vcs
->input
= VINO_INPUT_NONE
;
4556 vcs
->data_format
= VINO_DATA_FMT_GREY
;
4557 vcs
->data_norm
= VINO_DATA_NORM_NTSC
;
4558 vcs
->decimation
= 1;
4559 vino_set_default_clipping(vcs
);
4560 vino_set_default_framerate(vcs
);
4564 mutex_init(&vcs
->mutex
);
4565 spin_lock_init(&vcs
->capture_lock
);
4567 mutex_init(&vcs
->fb_queue
.queue_mutex
);
4568 spin_lock_init(&vcs
->fb_queue
.queue_lock
);
4569 init_waitqueue_head(&vcs
->fb_queue
.frame_wait_queue
);
4571 vcs
->v4l_device
= video_device_alloc();
4572 if (!vcs
->v4l_device
) {
4573 vino_module_cleanup(vino_init_stage
);
4578 memcpy(vcs
->v4l_device
, &v4l_device_template
,
4579 sizeof(struct video_device
));
4580 strcpy(vcs
->v4l_device
->name
, name
);
4581 vcs
->v4l_device
->release
= video_device_release
;
4583 video_set_drvdata(vcs
->v4l_device
, vcs
);
4588 static int __init
vino_module_init(void)
4592 printk(KERN_INFO
"SGI VINO driver version %s\n",
4593 VINO_MODULE_VERSION
);
4603 /* initialize data structures */
4605 spin_lock_init(&vino_drvdata
->vino_lock
);
4606 spin_lock_init(&vino_drvdata
->input_lock
);
4608 ret
= vino_init_channel_settings(&vino_drvdata
->a
, VINO_CHANNEL_A
,
4609 vino_v4l_device_name_a
);
4613 ret
= vino_init_channel_settings(&vino_drvdata
->b
, VINO_CHANNEL_B
,
4614 vino_v4l_device_name_b
);
4618 /* initialize hardware and register V4L devices */
4620 ret
= request_irq(SGI_VINO_IRQ
, vino_interrupt
, 0,
4621 vino_driver_description
, NULL
);
4623 printk(KERN_ERR
"VINO: requesting IRQ %02d failed\n",
4625 vino_module_cleanup(vino_init_stage
);
4630 ret
= vino_i2c_add_bus();
4632 printk(KERN_ERR
"VINO I2C bus registration failed\n");
4633 vino_module_cleanup(vino_init_stage
);
4638 ret
= video_register_device(vino_drvdata
->a
.v4l_device
,
4639 VFL_TYPE_GRABBER
, -1);
4641 printk(KERN_ERR
"VINO channel A Video4Linux-device "
4642 "registration failed\n");
4643 vino_module_cleanup(vino_init_stage
);
4648 ret
= video_register_device(vino_drvdata
->b
.v4l_device
,
4649 VFL_TYPE_GRABBER
, -1);
4651 printk(KERN_ERR
"VINO channel B Video4Linux-device "
4652 "registration failed\n");
4653 vino_module_cleanup(vino_init_stage
);
4658 #if defined(CONFIG_KMOD) && defined(MODULE)
4659 request_module("saa7191");
4660 request_module("indycam");
4663 dprintk("init complete!\n");
4668 static void __exit
vino_module_exit(void)
4670 dprintk("exiting, stage = %d ...\n", vino_init_stage
);
4671 vino_module_cleanup(vino_init_stage
);
4672 dprintk("cleanup complete, exit!\n");
4675 module_init(vino_module_init
);
4676 module_exit(vino_module_exit
);