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/moduleparam.h>
32 #include <linux/time.h>
33 #include <linux/version.h>
36 #include <linux/kmod.h>
39 #include <linux/i2c.h>
40 #include <linux/i2c-algo-sgi.h>
42 #include <linux/videodev.h>
43 #include <media/v4l2-common.h>
44 #include <linux/video_decoder.h>
45 #include <linux/mutex.h>
47 #include <asm/paccess.h>
49 #include <asm/sgi/ip22.h>
50 #include <asm/sgi/mc.h>
56 /* Uncomment the following line to get lots and lots of (mostly useless)
58 * Note that the debug output also slows down the driver significantly */
60 // #define VINO_DEBUG_INT
62 #define VINO_MODULE_VERSION "0.0.5"
63 #define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 5)
65 MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
66 MODULE_VERSION(VINO_MODULE_VERSION
);
67 MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
68 MODULE_LICENSE("GPL");
71 #define dprintk(x...) printk("VINO: " x);
76 #define VINO_NO_CHANNEL 0
77 #define VINO_CHANNEL_A 1
78 #define VINO_CHANNEL_B 2
80 #define VINO_PAL_WIDTH 768
81 #define VINO_PAL_HEIGHT 576
82 #define VINO_NTSC_WIDTH 640
83 #define VINO_NTSC_HEIGHT 480
85 #define VINO_MIN_WIDTH 32
86 #define VINO_MIN_HEIGHT 32
88 #define VINO_CLIPPING_START_ODD_D1 1
89 #define VINO_CLIPPING_START_ODD_PAL 15
90 #define VINO_CLIPPING_START_ODD_NTSC 12
92 #define VINO_CLIPPING_START_EVEN_D1 2
93 #define VINO_CLIPPING_START_EVEN_PAL 15
94 #define VINO_CLIPPING_START_EVEN_NTSC 12
96 #define VINO_INPUT_CHANNEL_COUNT 3
98 /* the number is the index for vino_inputs */
99 #define VINO_INPUT_NONE -1
100 #define VINO_INPUT_COMPOSITE 0
101 #define VINO_INPUT_SVIDEO 1
102 #define VINO_INPUT_D1 2
104 #define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
106 #define VINO_FIFO_THRESHOLD_DEFAULT 16
108 #define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
109 * VINO_PAL_HEIGHT * 4 \
110 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
112 #define VINO_FRAMEBUFFER_COUNT_MAX 8
114 #define VINO_FRAMEBUFFER_UNUSED 0
115 #define VINO_FRAMEBUFFER_IN_USE 1
116 #define VINO_FRAMEBUFFER_READY 2
118 #define VINO_QUEUE_ERROR -1
119 #define VINO_QUEUE_MAGIC 0x20050125
121 #define VINO_MEMORY_NONE 0
122 #define VINO_MEMORY_MMAP 1
123 #define VINO_MEMORY_USERPTR 2
125 #define VINO_DUMMY_DESC_COUNT 4
126 #define VINO_DESC_FETCH_DELAY 5 /* microseconds */
128 #define VINO_MAX_FRAME_SKIP_COUNT 128
130 /* the number is the index for vino_data_formats */
131 #define VINO_DATA_FMT_NONE -1
132 #define VINO_DATA_FMT_GREY 0
133 #define VINO_DATA_FMT_RGB332 1
134 #define VINO_DATA_FMT_RGB32 2
135 #define VINO_DATA_FMT_YUV 3
137 #define VINO_DATA_FMT_COUNT 4
139 /* the number is the index for vino_data_norms */
140 #define VINO_DATA_NORM_NONE -1
141 #define VINO_DATA_NORM_NTSC 0
142 #define VINO_DATA_NORM_PAL 1
143 #define VINO_DATA_NORM_SECAM 2
144 #define VINO_DATA_NORM_D1 3
145 /* The following are special entries that can be used to
146 * autodetect the norm. */
147 #define VINO_DATA_NORM_AUTO 0xfe
148 #define VINO_DATA_NORM_AUTO_EXT 0xff
150 #define VINO_DATA_NORM_COUNT 4
152 /* Internal data structure definitions */
159 struct vino_clipping
{
160 unsigned int left
, right
, top
, bottom
;
163 struct vino_data_format
{
164 /* the description */
166 /* bytes per pixel */
168 /* V4L2 fourcc code */
170 /* V4L2 colorspace (duh!) */
171 enum v4l2_colorspace colorspace
;
174 struct vino_data_norm
{
176 unsigned int width
, height
;
177 struct vino_clipping odd
;
178 struct vino_clipping even
;
181 unsigned int fps_min
, fps_max
;
185 struct vino_descriptor_table
{
186 /* the number of PAGE_SIZE sized pages in the buffer */
187 unsigned int page_count
;
188 /* virtual (kmalloc'd) pointers to the actual data
189 * (in PAGE_SIZE chunks, used with mmap streaming) */
190 unsigned long *virtual;
192 /* cpu address for the VINO descriptor table
193 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
194 unsigned long *dma_cpu
;
195 /* dma address for the VINO descriptor table
196 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
200 struct vino_framebuffer
{
201 /* identifier nubmer */
203 /* the length of the whole buffer */
205 /* the length of actual data in buffer */
206 unsigned int data_size
;
207 /* the data format */
208 unsigned int data_format
;
209 /* the state of buffer data */
211 /* is the buffer mapped in user space? */
212 unsigned int map_count
;
213 /* memory offset for mmap() */
216 unsigned int frame_counter
;
217 /* timestamp (written when image capture finishes) */
218 struct timeval timestamp
;
220 struct vino_descriptor_table desc_table
;
222 spinlock_t state_lock
;
225 struct vino_framebuffer_fifo
{
232 unsigned int data
[VINO_FRAMEBUFFER_COUNT_MAX
];
235 struct vino_framebuffer_queue
{
238 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
242 /* data field of in and out contain index numbers for buffer */
243 struct vino_framebuffer_fifo in
;
244 struct vino_framebuffer_fifo out
;
246 struct vino_framebuffer
*buffer
[VINO_FRAMEBUFFER_COUNT_MAX
];
248 spinlock_t queue_lock
;
249 struct mutex queue_mutex
;
250 wait_queue_head_t frame_wait_queue
;
253 struct vino_interrupt_data
{
254 struct timeval timestamp
;
255 unsigned int frame_counter
;
256 unsigned int skip_count
;
260 struct vino_channel_settings
{
261 unsigned int channel
;
264 unsigned int data_format
;
265 unsigned int data_norm
;
266 struct vino_clipping clipping
;
267 unsigned int decimation
;
268 unsigned int line_size
;
271 unsigned int framert_reg
;
273 unsigned int fifo_threshold
;
275 struct vino_framebuffer_queue fb_queue
;
277 /* number of the current field */
280 /* read in progress */
282 /* streaming is active */
284 /* the driver is currently processing the queue */
288 spinlock_t capture_lock
;
292 struct vino_interrupt_data int_data
;
295 struct video_device
*v4l_device
;
299 /* the channel which owns this client:
300 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
302 struct i2c_client
*driver
;
305 struct vino_settings
{
306 struct vino_channel_settings a
;
307 struct vino_channel_settings b
;
309 struct vino_client decoder
;
310 struct vino_client camera
;
312 /* a lock for vino register access */
313 spinlock_t vino_lock
;
314 /* a lock for channel input changes */
315 spinlock_t input_lock
;
317 unsigned long dummy_page
;
318 struct vino_descriptor_table dummy_desc_table
;
321 /* Module parameters */
324 * Using vino_pixel_conversion the ABGR32-format pixels supplied
325 * by the VINO chip can be converted to more common formats
326 * like RGBA32 (or probably RGB24 in the future). This way we
327 * can give out data that can be specified correctly with
328 * the V4L2-definitions.
330 * The pixel format is specified as RGBA32 when no conversion
333 * Note that this only affects the 32-bit bit depth.
335 * Use non-zero value to enable conversion.
337 static int vino_pixel_conversion
= 0;
339 module_param_named(pixelconv
, vino_pixel_conversion
, int, 0);
341 MODULE_PARM_DESC(pixelconv
,
342 "enable pixel conversion (non-zero value enables)");
344 /* Internal data structures */
346 static struct sgi_vino
*vino
;
348 static struct vino_settings
*vino_drvdata
;
350 static const char *vino_driver_name
= "vino";
351 static const char *vino_driver_description
= "SGI VINO";
352 static const char *vino_bus_name
= "GIO64 bus";
353 static const char *vino_v4l_device_name_a
= "SGI VINO Channel A";
354 static const char *vino_v4l_device_name_b
= "SGI VINO Channel B";
356 static void vino_capture_tasklet(unsigned long channel
);
358 DECLARE_TASKLET(vino_tasklet_a
, vino_capture_tasklet
, VINO_CHANNEL_A
);
359 DECLARE_TASKLET(vino_tasklet_b
, vino_capture_tasklet
, VINO_CHANNEL_B
);
361 static const struct vino_input vino_inputs
[] = {
364 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
368 .std
= V4L2_STD_NTSC
| V4L2_STD_PAL
371 .name
= "D1/IndyCam",
372 .std
= V4L2_STD_NTSC
,
376 static const struct vino_data_format vino_data_formats
[] = {
378 .description
= "8-bit greyscale",
380 .pixelformat
= V4L2_PIX_FMT_GREY
,
381 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
383 .description
= "8-bit dithered RGB 3-3-2",
385 .pixelformat
= V4L2_PIX_FMT_RGB332
,
386 .colorspace
= V4L2_COLORSPACE_SRGB
,
388 .description
= "32-bit RGB",
390 .pixelformat
= V4L2_PIX_FMT_RGB32
,
391 .colorspace
= V4L2_COLORSPACE_SRGB
,
393 .description
= "YUV 4:2:2",
395 .pixelformat
= V4L2_PIX_FMT_YUYV
, // XXX: swapped?
396 .colorspace
= V4L2_COLORSPACE_SMPTE170M
,
400 static const struct vino_data_norm vino_data_norms
[] = {
402 .description
= "NTSC",
403 .std
= V4L2_STD_NTSC
,
407 .width
= VINO_NTSC_WIDTH
,
408 .height
= VINO_NTSC_HEIGHT
,
410 .top
= VINO_CLIPPING_START_ODD_NTSC
,
412 .bottom
= VINO_CLIPPING_START_ODD_NTSC
413 + VINO_NTSC_HEIGHT
/ 2 - 1,
414 .right
= VINO_NTSC_WIDTH
,
417 .top
= VINO_CLIPPING_START_EVEN_NTSC
,
419 .bottom
= VINO_CLIPPING_START_EVEN_NTSC
420 + VINO_NTSC_HEIGHT
/ 2 - 1,
421 .right
= VINO_NTSC_WIDTH
,
424 .description
= "PAL",
429 .width
= VINO_PAL_WIDTH
,
430 .height
= VINO_PAL_HEIGHT
,
432 .top
= VINO_CLIPPING_START_ODD_PAL
,
434 .bottom
= VINO_CLIPPING_START_ODD_PAL
435 + VINO_PAL_HEIGHT
/ 2 - 1,
436 .right
= VINO_PAL_WIDTH
,
439 .top
= VINO_CLIPPING_START_EVEN_PAL
,
441 .bottom
= VINO_CLIPPING_START_EVEN_PAL
442 + VINO_PAL_HEIGHT
/ 2 - 1,
443 .right
= VINO_PAL_WIDTH
,
446 .description
= "SECAM",
447 .std
= V4L2_STD_SECAM
,
451 .width
= VINO_PAL_WIDTH
,
452 .height
= VINO_PAL_HEIGHT
,
454 .top
= VINO_CLIPPING_START_ODD_PAL
,
456 .bottom
= VINO_CLIPPING_START_ODD_PAL
457 + VINO_PAL_HEIGHT
/ 2 - 1,
458 .right
= VINO_PAL_WIDTH
,
461 .top
= VINO_CLIPPING_START_EVEN_PAL
,
463 .bottom
= VINO_CLIPPING_START_EVEN_PAL
464 + VINO_PAL_HEIGHT
/ 2 - 1,
465 .right
= VINO_PAL_WIDTH
,
468 .description
= "NTSC/D1",
469 .std
= V4L2_STD_NTSC
,
473 .width
= VINO_NTSC_WIDTH
,
474 .height
= VINO_NTSC_HEIGHT
,
476 .top
= VINO_CLIPPING_START_ODD_D1
,
478 .bottom
= VINO_CLIPPING_START_ODD_D1
479 + VINO_NTSC_HEIGHT
/ 2 - 1,
480 .right
= VINO_NTSC_WIDTH
,
483 .top
= VINO_CLIPPING_START_EVEN_D1
,
485 .bottom
= VINO_CLIPPING_START_EVEN_D1
486 + VINO_NTSC_HEIGHT
/ 2 - 1,
487 .right
= VINO_NTSC_WIDTH
,
492 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
494 struct v4l2_queryctrl vino_indycam_v4l2_controls
[] = {
496 .id
= V4L2_CID_AUTOGAIN
,
497 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
498 .name
= "Automatic Gain Control",
502 .default_value
= INDYCAM_AGC_DEFAULT
,
504 .reserved
= { INDYCAM_CONTROL_AGC
, 0 },
506 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
507 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
508 .name
= "Automatic White Balance",
512 .default_value
= INDYCAM_AWB_DEFAULT
,
514 .reserved
= { INDYCAM_CONTROL_AWB
, 0 },
517 .type
= V4L2_CTRL_TYPE_INTEGER
,
519 .minimum
= INDYCAM_GAIN_MIN
,
520 .maximum
= INDYCAM_GAIN_MAX
,
522 .default_value
= INDYCAM_GAIN_DEFAULT
,
524 .reserved
= { INDYCAM_CONTROL_GAIN
, 0 },
526 .id
= V4L2_CID_PRIVATE_BASE
,
527 .type
= V4L2_CTRL_TYPE_INTEGER
,
528 .name
= "Red Saturation",
529 .minimum
= INDYCAM_RED_SATURATION_MIN
,
530 .maximum
= INDYCAM_RED_SATURATION_MAX
,
532 .default_value
= INDYCAM_RED_SATURATION_DEFAULT
,
534 .reserved
= { INDYCAM_CONTROL_RED_SATURATION
, 0 },
536 .id
= V4L2_CID_PRIVATE_BASE
+ 1,
537 .type
= V4L2_CTRL_TYPE_INTEGER
,
538 .name
= "Blue Saturation",
539 .minimum
= INDYCAM_BLUE_SATURATION_MIN
,
540 .maximum
= INDYCAM_BLUE_SATURATION_MAX
,
542 .default_value
= INDYCAM_BLUE_SATURATION_DEFAULT
,
544 .reserved
= { INDYCAM_CONTROL_BLUE_SATURATION
, 0 },
546 .id
= V4L2_CID_RED_BALANCE
,
547 .type
= V4L2_CTRL_TYPE_INTEGER
,
548 .name
= "Red Balance",
549 .minimum
= INDYCAM_RED_BALANCE_MIN
,
550 .maximum
= INDYCAM_RED_BALANCE_MAX
,
552 .default_value
= INDYCAM_RED_BALANCE_DEFAULT
,
554 .reserved
= { INDYCAM_CONTROL_RED_BALANCE
, 0 },
556 .id
= V4L2_CID_BLUE_BALANCE
,
557 .type
= V4L2_CTRL_TYPE_INTEGER
,
558 .name
= "Blue Balance",
559 .minimum
= INDYCAM_BLUE_BALANCE_MIN
,
560 .maximum
= INDYCAM_BLUE_BALANCE_MAX
,
562 .default_value
= INDYCAM_BLUE_BALANCE_DEFAULT
,
564 .reserved
= { INDYCAM_CONTROL_BLUE_BALANCE
, 0 },
566 .id
= V4L2_CID_EXPOSURE
,
567 .type
= V4L2_CTRL_TYPE_INTEGER
,
568 .name
= "Shutter Control",
569 .minimum
= INDYCAM_SHUTTER_MIN
,
570 .maximum
= INDYCAM_SHUTTER_MAX
,
572 .default_value
= INDYCAM_SHUTTER_DEFAULT
,
574 .reserved
= { INDYCAM_CONTROL_SHUTTER
, 0 },
576 .id
= V4L2_CID_GAMMA
,
577 .type
= V4L2_CTRL_TYPE_INTEGER
,
579 .minimum
= INDYCAM_GAMMA_MIN
,
580 .maximum
= INDYCAM_GAMMA_MAX
,
582 .default_value
= INDYCAM_GAMMA_DEFAULT
,
584 .reserved
= { INDYCAM_CONTROL_GAMMA
, 0 },
588 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
590 struct v4l2_queryctrl vino_saa7191_v4l2_controls
[] = {
593 .type
= V4L2_CTRL_TYPE_INTEGER
,
595 .minimum
= SAA7191_HUE_MIN
,
596 .maximum
= SAA7191_HUE_MAX
,
598 .default_value
= SAA7191_HUE_DEFAULT
,
600 .reserved
= { SAA7191_CONTROL_HUE
, 0 },
602 .id
= V4L2_CID_PRIVATE_BASE
,
603 .type
= V4L2_CTRL_TYPE_INTEGER
,
604 .name
= "Luminance Bandpass",
605 .minimum
= SAA7191_BANDPASS_MIN
,
606 .maximum
= SAA7191_BANDPASS_MAX
,
608 .default_value
= SAA7191_BANDPASS_DEFAULT
,
610 .reserved
= { SAA7191_CONTROL_BANDPASS
, 0 },
612 .id
= V4L2_CID_PRIVATE_BASE
+ 1,
613 .type
= V4L2_CTRL_TYPE_INTEGER
,
614 .name
= "Luminance Bandpass Weight",
615 .minimum
= SAA7191_BANDPASS_WEIGHT_MIN
,
616 .maximum
= SAA7191_BANDPASS_WEIGHT_MAX
,
618 .default_value
= SAA7191_BANDPASS_WEIGHT_DEFAULT
,
620 .reserved
= { SAA7191_CONTROL_BANDPASS_WEIGHT
, 0 },
622 .id
= V4L2_CID_PRIVATE_BASE
+ 2,
623 .type
= V4L2_CTRL_TYPE_INTEGER
,
624 .name
= "HF Luminance Coring",
625 .minimum
= SAA7191_CORING_MIN
,
626 .maximum
= SAA7191_CORING_MAX
,
628 .default_value
= SAA7191_CORING_DEFAULT
,
630 .reserved
= { SAA7191_CONTROL_CORING
, 0 },
632 .id
= V4L2_CID_PRIVATE_BASE
+ 3,
633 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
634 .name
= "Force Colour",
635 .minimum
= SAA7191_FORCE_COLOUR_MIN
,
636 .maximum
= SAA7191_FORCE_COLOUR_MAX
,
638 .default_value
= SAA7191_FORCE_COLOUR_DEFAULT
,
640 .reserved
= { SAA7191_CONTROL_FORCE_COLOUR
, 0 },
642 .id
= V4L2_CID_PRIVATE_BASE
+ 4,
643 .type
= V4L2_CTRL_TYPE_INTEGER
,
644 .name
= "Chrominance Gain Control",
645 .minimum
= SAA7191_CHROMA_GAIN_MIN
,
646 .maximum
= SAA7191_CHROMA_GAIN_MAX
,
648 .default_value
= SAA7191_CHROMA_GAIN_DEFAULT
,
650 .reserved
= { SAA7191_CONTROL_CHROMA_GAIN
, 0 },
652 .id
= V4L2_CID_PRIVATE_BASE
+ 5,
653 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
654 .name
= "VTR Time Constant",
655 .minimum
= SAA7191_VTRC_MIN
,
656 .maximum
= SAA7191_VTRC_MAX
,
658 .default_value
= SAA7191_VTRC_DEFAULT
,
660 .reserved
= { SAA7191_CONTROL_VTRC
, 0 },
662 .id
= V4L2_CID_PRIVATE_BASE
+ 6,
663 .type
= V4L2_CTRL_TYPE_INTEGER
,
664 .name
= "Luminance Delay Compensation",
665 .minimum
= SAA7191_LUMA_DELAY_MIN
,
666 .maximum
= SAA7191_LUMA_DELAY_MAX
,
668 .default_value
= SAA7191_LUMA_DELAY_DEFAULT
,
670 .reserved
= { SAA7191_CONTROL_LUMA_DELAY
, 0 },
672 .id
= V4L2_CID_PRIVATE_BASE
+ 7,
673 .type
= V4L2_CTRL_TYPE_INTEGER
,
674 .name
= "Vertical Noise Reduction",
675 .minimum
= SAA7191_VNR_MIN
,
676 .maximum
= SAA7191_VNR_MAX
,
678 .default_value
= SAA7191_VNR_DEFAULT
,
680 .reserved
= { SAA7191_CONTROL_VNR
, 0 },
684 /* VINO I2C bus functions */
686 unsigned i2c_vino_getctrl(void *data
)
688 return vino
->i2c_control
;
691 void i2c_vino_setctrl(void *data
, unsigned val
)
693 vino
->i2c_control
= val
;
696 unsigned i2c_vino_rdata(void *data
)
698 return vino
->i2c_data
;
701 void i2c_vino_wdata(void *data
, unsigned val
)
703 vino
->i2c_data
= val
;
706 static struct i2c_algo_sgi_data i2c_sgi_vino_data
=
708 .getctrl
= &i2c_vino_getctrl
,
709 .setctrl
= &i2c_vino_setctrl
,
710 .rdata
= &i2c_vino_rdata
,
711 .wdata
= &i2c_vino_wdata
,
717 * There are two possible clients on VINO I2C bus, so we limit usage only
720 static int i2c_vino_client_reg(struct i2c_client
*client
)
725 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
726 switch (client
->driver
->id
) {
727 case I2C_DRIVERID_SAA7191
:
728 if (vino_drvdata
->decoder
.driver
)
731 vino_drvdata
->decoder
.driver
= client
;
733 case I2C_DRIVERID_INDYCAM
:
734 if (vino_drvdata
->camera
.driver
)
737 vino_drvdata
->camera
.driver
= client
;
742 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
747 static int i2c_vino_client_unreg(struct i2c_client
*client
)
752 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
753 if (client
== vino_drvdata
->decoder
.driver
) {
754 if (vino_drvdata
->decoder
.owner
!= VINO_NO_CHANNEL
)
757 vino_drvdata
->decoder
.driver
= NULL
;
758 } else if (client
== vino_drvdata
->camera
.driver
) {
759 if (vino_drvdata
->camera
.owner
!= VINO_NO_CHANNEL
)
762 vino_drvdata
->camera
.driver
= NULL
;
764 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
769 static struct i2c_adapter vino_i2c_adapter
=
771 .name
= "VINO I2C bus",
772 .id
= I2C_HW_SGI_VINO
,
773 .algo_data
= &i2c_sgi_vino_data
,
774 .client_register
= &i2c_vino_client_reg
,
775 .client_unregister
= &i2c_vino_client_unreg
,
778 static int vino_i2c_add_bus(void)
780 return i2c_sgi_add_bus(&vino_i2c_adapter
);
783 static int vino_i2c_del_bus(void)
785 return i2c_del_adapter(&vino_i2c_adapter
);
788 static int i2c_camera_command(unsigned int cmd
, void *arg
)
790 return vino_drvdata
->camera
.driver
->
791 driver
->command(vino_drvdata
->camera
.driver
,
795 static int i2c_decoder_command(unsigned int cmd
, void *arg
)
797 return vino_drvdata
->decoder
.driver
->
798 driver
->command(vino_drvdata
->decoder
.driver
,
802 /* VINO framebuffer/DMA descriptor management */
804 static void vino_free_buffer_with_count(struct vino_framebuffer
*fb
,
809 dprintk("vino_free_buffer_with_count(): count = %d\n", count
);
811 for (i
= 0; i
< count
; i
++) {
812 ClearPageReserved(virt_to_page(fb
->desc_table
.virtual[i
]));
813 dma_unmap_single(NULL
,
814 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
815 PAGE_SIZE
, DMA_FROM_DEVICE
);
816 free_page(fb
->desc_table
.virtual[i
]);
819 dma_free_coherent(NULL
,
820 VINO_PAGE_RATIO
* (fb
->desc_table
.page_count
+ 4) *
821 sizeof(dma_addr_t
), (void *)fb
->desc_table
.dma_cpu
,
823 kfree(fb
->desc_table
.virtual);
825 memset(fb
, 0, sizeof(struct vino_framebuffer
));
828 static void vino_free_buffer(struct vino_framebuffer
*fb
)
830 vino_free_buffer_with_count(fb
, fb
->desc_table
.page_count
);
833 static int vino_allocate_buffer(struct vino_framebuffer
*fb
,
836 unsigned int count
, i
, j
;
839 dprintk("vino_allocate_buffer():\n");
844 memset(fb
, 0, sizeof(struct vino_framebuffer
));
846 count
= ((size
/ PAGE_SIZE
) + 4) & ~3;
848 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
851 /* allocate memory for table with virtual (page) addresses */
852 fb
->desc_table
.virtual = (unsigned long *)
853 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
854 if (!fb
->desc_table
.virtual)
857 /* allocate memory for table with dma addresses
858 * (has space for four extra descriptors) */
859 fb
->desc_table
.dma_cpu
=
860 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
861 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
862 GFP_KERNEL
| GFP_DMA
);
863 if (!fb
->desc_table
.dma_cpu
) {
865 goto out_free_virtual
;
868 /* allocate pages for the buffer and acquire the according
870 for (i
= 0; i
< count
; i
++) {
871 dma_addr_t dma_data_addr
;
873 fb
->desc_table
.virtual[i
] =
874 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
875 if (!fb
->desc_table
.virtual[i
]) {
882 (void *)fb
->desc_table
.virtual[i
],
883 PAGE_SIZE
, DMA_FROM_DEVICE
);
885 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
886 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
887 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
890 SetPageReserved(virt_to_page(fb
->desc_table
.virtual[i
]));
893 /* page_count needs to be set anyway, because the descriptor table has
894 * been allocated according to this number */
895 fb
->desc_table
.page_count
= count
;
898 /* the descriptor with index i doesn't contain
899 * a valid address yet */
900 vino_free_buffer_with_count(fb
, i
);
905 fb
->size
= count
* PAGE_SIZE
;
906 fb
->data_format
= VINO_DATA_FMT_NONE
;
908 /* set the dma stop-bit for the last (count+1)th descriptor */
909 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
913 kfree(fb
->desc_table
.virtual);
918 /* user buffers not fully implemented yet */
919 static int vino_prepare_user_buffer(struct vino_framebuffer
*fb
,
923 unsigned int count
, i
, j
;
926 dprintk("vino_prepare_user_buffer():\n");
931 memset(fb
, 0, sizeof(struct vino_framebuffer
));
933 count
= ((size
/ PAGE_SIZE
)) & ~3;
935 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
938 /* allocate memory for table with virtual (page) addresses */
939 fb
->desc_table
.virtual = (unsigned long *)
940 kmalloc(count
* sizeof(unsigned long), GFP_KERNEL
);
941 if (!fb
->desc_table
.virtual)
944 /* allocate memory for table with dma addresses
945 * (has space for four extra descriptors) */
946 fb
->desc_table
.dma_cpu
=
947 dma_alloc_coherent(NULL
, VINO_PAGE_RATIO
* (count
+ 4) *
948 sizeof(dma_addr_t
), &fb
->desc_table
.dma
,
949 GFP_KERNEL
| GFP_DMA
);
950 if (!fb
->desc_table
.dma_cpu
) {
952 goto out_free_virtual
;
955 /* allocate pages for the buffer and acquire the according
957 for (i
= 0; i
< count
; i
++) {
958 dma_addr_t dma_data_addr
;
960 fb
->desc_table
.virtual[i
] =
961 get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
962 if (!fb
->desc_table
.virtual[i
]) {
969 (void *)fb
->desc_table
.virtual[i
],
970 PAGE_SIZE
, DMA_FROM_DEVICE
);
972 for (j
= 0; j
< VINO_PAGE_RATIO
; j
++) {
973 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
+ j
] =
974 dma_data_addr
+ VINO_PAGE_SIZE
* j
;
977 SetPageReserved(virt_to_page(fb
->desc_table
.virtual[i
]));
980 /* page_count needs to be set anyway, because the descriptor table has
981 * been allocated according to this number */
982 fb
->desc_table
.page_count
= count
;
985 /* the descriptor with index i doesn't contain
986 * a valid address yet */
987 vino_free_buffer_with_count(fb
, i
);
992 fb
->size
= count
* PAGE_SIZE
;
994 /* set the dma stop-bit for the last (count+1)th descriptor */
995 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* count
] = VINO_DESC_STOP
;
999 kfree(fb
->desc_table
.virtual);
1004 static void vino_sync_buffer(struct vino_framebuffer
*fb
)
1008 dprintk("vino_sync_buffer():\n");
1010 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++)
1011 dma_sync_single(NULL
,
1012 fb
->desc_table
.dma_cpu
[VINO_PAGE_RATIO
* i
],
1013 PAGE_SIZE
, DMA_FROM_DEVICE
);
1016 /* Framebuffer fifo functions (need to be locked externally) */
1018 static inline void vino_fifo_init(struct vino_framebuffer_fifo
*f
,
1019 unsigned int length
)
1026 if (length
> VINO_FRAMEBUFFER_COUNT_MAX
)
1027 length
= VINO_FRAMEBUFFER_COUNT_MAX
;
1032 /* returns true/false */
1033 static inline int vino_fifo_has_id(struct vino_framebuffer_fifo
*f
,
1038 for (i
= f
->head
; i
== (f
->tail
- 1); i
= (i
+ 1) % f
->length
) {
1039 if (f
->data
[i
] == id
)
1047 /* returns true/false */
1048 static inline int vino_fifo_full(struct vino_framebuffer_fifo
*f
)
1050 return (f
->used
== f
->length
);
1054 static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo
*f
)
1059 static int vino_fifo_enqueue(struct vino_framebuffer_fifo
*f
, unsigned int id
)
1061 if (id
>= f
->length
) {
1062 return VINO_QUEUE_ERROR
;
1065 if (vino_fifo_has_id(f
, id
)) {
1066 return VINO_QUEUE_ERROR
;
1069 if (f
->used
< f
->length
) {
1070 f
->data
[f
->tail
] = id
;
1071 f
->tail
= (f
->tail
+ 1) % f
->length
;
1074 return VINO_QUEUE_ERROR
;
1080 static int vino_fifo_peek(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
1083 *id
= f
->data
[f
->head
];
1085 return VINO_QUEUE_ERROR
;
1091 static int vino_fifo_dequeue(struct vino_framebuffer_fifo
*f
, unsigned int *id
)
1094 *id
= f
->data
[f
->head
];
1095 f
->head
= (f
->head
+ 1) % f
->length
;
1098 return VINO_QUEUE_ERROR
;
1104 /* Framebuffer queue functions */
1106 /* execute with queue_lock locked */
1107 static void vino_queue_free_with_count(struct vino_framebuffer_queue
*q
,
1108 unsigned int length
)
1113 memset(&q
->in
, 0, sizeof(struct vino_framebuffer_fifo
));
1114 memset(&q
->out
, 0, sizeof(struct vino_framebuffer_fifo
));
1115 for (i
= 0; i
< length
; i
++) {
1116 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
1118 vino_free_buffer(q
->buffer
[i
]);
1119 kfree(q
->buffer
[i
]);
1122 q
->type
= VINO_MEMORY_NONE
;
1126 static void vino_queue_free(struct vino_framebuffer_queue
*q
)
1128 dprintk("vino_queue_free():\n");
1130 if (q
->magic
!= VINO_QUEUE_MAGIC
)
1132 if (q
->type
!= VINO_MEMORY_MMAP
)
1135 mutex_lock(&q
->queue_mutex
);
1137 vino_queue_free_with_count(q
, q
->length
);
1139 mutex_unlock(&q
->queue_mutex
);
1142 static int vino_queue_init(struct vino_framebuffer_queue
*q
,
1143 unsigned int *length
)
1148 dprintk("vino_queue_init(): length = %d\n", *length
);
1150 if (q
->magic
== VINO_QUEUE_MAGIC
) {
1151 dprintk("vino_queue_init(): queue already initialized!\n");
1155 if (q
->type
!= VINO_MEMORY_NONE
) {
1156 dprintk("vino_queue_init(): queue already initialized!\n");
1163 mutex_lock(&q
->queue_mutex
);
1165 if (*length
> VINO_FRAMEBUFFER_COUNT_MAX
)
1166 *length
= VINO_FRAMEBUFFER_COUNT_MAX
;
1170 for (i
= 0; i
< *length
; i
++) {
1171 dprintk("vino_queue_init(): allocating buffer %d\n", i
);
1172 q
->buffer
[i
] = kmalloc(sizeof(struct vino_framebuffer
),
1174 if (!q
->buffer
[i
]) {
1175 dprintk("vino_queue_init(): kmalloc() failed\n");
1180 ret
= vino_allocate_buffer(q
->buffer
[i
],
1181 VINO_FRAMEBUFFER_SIZE
);
1183 kfree(q
->buffer
[i
]);
1184 dprintk("vino_queue_init(): "
1185 "vino_allocate_buffer() failed\n");
1189 q
->buffer
[i
]->id
= i
;
1191 q
->buffer
[i
]->offset
= q
->buffer
[i
- 1]->offset
+
1192 q
->buffer
[i
- 1]->size
;
1194 q
->buffer
[i
]->offset
= 0;
1197 spin_lock_init(&q
->buffer
[i
]->state_lock
);
1199 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1200 "size = %d\n", i
, q
->buffer
[i
]->offset
,
1201 q
->buffer
[i
]->size
);
1205 vino_queue_free_with_count(q
, i
);
1208 q
->length
= *length
;
1209 vino_fifo_init(&q
->in
, q
->length
);
1210 vino_fifo_init(&q
->out
, q
->length
);
1211 q
->type
= VINO_MEMORY_MMAP
;
1212 q
->magic
= VINO_QUEUE_MAGIC
;
1215 mutex_unlock(&q
->queue_mutex
);
1220 static struct vino_framebuffer
*vino_queue_add(struct
1221 vino_framebuffer_queue
*q
,
1224 struct vino_framebuffer
*ret
= NULL
;
1226 unsigned long flags
;
1228 dprintk("vino_queue_add(): id = %d\n", id
);
1230 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1234 spin_lock_irqsave(&q
->queue_lock
, flags
);
1239 if (id
>= q
->length
)
1242 /* not needed?: if (vino_fifo_full(&q->out)) {
1245 /* check that outgoing queue isn't already full
1246 * (or that it won't become full) */
1247 total
= vino_fifo_get_used(&q
->in
) +
1248 vino_fifo_get_used(&q
->out
);
1249 if (total
>= q
->length
)
1252 if (vino_fifo_enqueue(&q
->in
, id
))
1255 ret
= q
->buffer
[id
];
1258 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1263 static struct vino_framebuffer
*vino_queue_transfer(struct
1264 vino_framebuffer_queue
*q
)
1266 struct vino_framebuffer
*ret
= NULL
;
1267 struct vino_framebuffer
*fb
;
1269 unsigned long flags
;
1271 dprintk("vino_queue_transfer():\n");
1273 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1277 spin_lock_irqsave(&q
->queue_lock
, flags
);
1282 // now this actually removes an entry from the incoming queue
1283 if (vino_fifo_dequeue(&q
->in
, &id
)) {
1287 dprintk("vino_queue_transfer(): id = %d\n", id
);
1290 // we have already checked that the outgoing queue is not full, but...
1291 if (vino_fifo_enqueue(&q
->out
, id
)) {
1292 printk(KERN_ERR
"vino_queue_transfer(): "
1293 "outgoing queue is full, this shouldn't happen!\n");
1299 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1304 /* returns true/false */
1305 static int vino_queue_incoming_contains(struct vino_framebuffer_queue
*q
,
1309 unsigned long flags
;
1311 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1315 spin_lock_irqsave(&q
->queue_lock
, flags
);
1320 ret
= vino_fifo_has_id(&q
->in
, id
);
1323 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1328 /* returns true/false */
1329 static int vino_queue_outgoing_contains(struct vino_framebuffer_queue
*q
,
1333 unsigned long flags
;
1335 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1339 spin_lock_irqsave(&q
->queue_lock
, flags
);
1344 ret
= vino_fifo_has_id(&q
->out
, id
);
1347 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1352 static int vino_queue_get_incoming(struct vino_framebuffer_queue
*q
,
1356 unsigned long flags
;
1358 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1359 return VINO_QUEUE_ERROR
;
1362 spin_lock_irqsave(&q
->queue_lock
, flags
);
1364 if (q
->length
== 0) {
1365 ret
= VINO_QUEUE_ERROR
;
1369 *used
= vino_fifo_get_used(&q
->in
);
1372 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1377 static int vino_queue_get_outgoing(struct vino_framebuffer_queue
*q
,
1381 unsigned long flags
;
1383 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1384 return VINO_QUEUE_ERROR
;
1387 spin_lock_irqsave(&q
->queue_lock
, flags
);
1389 if (q
->length
== 0) {
1390 ret
= VINO_QUEUE_ERROR
;
1394 *used
= vino_fifo_get_used(&q
->out
);
1397 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1403 static int vino_queue_get_total(struct vino_framebuffer_queue
*q
,
1404 unsigned int *total
)
1407 unsigned long flags
;
1409 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1410 return VINO_QUEUE_ERROR
;
1413 spin_lock_irqsave(&q
->queue_lock
, flags
);
1415 if (q
->length
== 0) {
1416 ret
= VINO_QUEUE_ERROR
;
1420 *total
= vino_fifo_get_used(&q
->in
) +
1421 vino_fifo_get_used(&q
->out
);
1424 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1430 static struct vino_framebuffer
*vino_queue_peek(struct
1431 vino_framebuffer_queue
*q
,
1434 struct vino_framebuffer
*ret
= NULL
;
1435 unsigned long flags
;
1437 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1441 spin_lock_irqsave(&q
->queue_lock
, flags
);
1446 if (vino_fifo_peek(&q
->in
, id
)) {
1450 ret
= q
->buffer
[*id
];
1452 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1457 static struct vino_framebuffer
*vino_queue_remove(struct
1458 vino_framebuffer_queue
*q
,
1461 struct vino_framebuffer
*ret
= NULL
;
1462 unsigned long flags
;
1463 dprintk("vino_queue_remove():\n");
1465 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1469 spin_lock_irqsave(&q
->queue_lock
, flags
);
1474 if (vino_fifo_dequeue(&q
->out
, id
)) {
1478 dprintk("vino_queue_remove(): id = %d\n", *id
);
1479 ret
= q
->buffer
[*id
];
1481 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1487 vino_framebuffer
*vino_queue_get_buffer(struct vino_framebuffer_queue
*q
,
1490 struct vino_framebuffer
*ret
= NULL
;
1491 unsigned long flags
;
1493 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1497 spin_lock_irqsave(&q
->queue_lock
, flags
);
1502 if (id
>= q
->length
)
1505 ret
= q
->buffer
[id
];
1507 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1512 static unsigned int vino_queue_get_length(struct vino_framebuffer_queue
*q
)
1514 unsigned int length
= 0;
1515 unsigned long flags
;
1517 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1521 spin_lock_irqsave(&q
->queue_lock
, flags
);
1523 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1528 static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue
*q
)
1532 unsigned long flags
;
1534 if (q
->magic
!= VINO_QUEUE_MAGIC
) {
1538 spin_lock_irqsave(&q
->queue_lock
, flags
);
1539 for (i
= 0; i
< q
->length
; i
++) {
1540 if (q
->buffer
[i
]->map_count
> 0) {
1545 spin_unlock_irqrestore(&q
->queue_lock
, flags
);
1550 /* VINO functions */
1552 /* execute with input_lock locked */
1553 static void vino_update_line_size(struct vino_channel_settings
*vcs
)
1555 unsigned int w
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1556 unsigned int d
= vcs
->decimation
;
1557 unsigned int bpp
= vino_data_formats
[vcs
->data_format
].bpp
;
1560 dprintk("update_line_size(): before: w = %d, d = %d, "
1561 "line_size = %d\n", w
, d
, vcs
->line_size
);
1563 /* line size must be multiple of 8 bytes */
1564 lsize
= (bpp
* (w
/ d
)) & ~7;
1565 w
= (lsize
/ bpp
) * d
;
1567 vcs
->clipping
.right
= vcs
->clipping
.left
+ w
;
1568 vcs
->line_size
= lsize
;
1570 dprintk("update_line_size(): after: w = %d, d = %d, "
1571 "line_size = %d\n", w
, d
, vcs
->line_size
);
1574 /* execute with input_lock locked */
1575 static void vino_set_clipping(struct vino_channel_settings
*vcs
,
1576 unsigned int x
, unsigned int y
,
1577 unsigned int w
, unsigned int h
)
1579 unsigned int maxwidth
, maxheight
;
1582 maxwidth
= vino_data_norms
[vcs
->data_norm
].width
;
1583 maxheight
= vino_data_norms
[vcs
->data_norm
].height
;
1584 d
= vcs
->decimation
;
1586 y
&= ~1; /* odd/even fields */
1591 if (y
> maxheight
) {
1595 if (((w
/ d
) < VINO_MIN_WIDTH
)
1596 || ((h
/ d
) < VINO_MIN_HEIGHT
)) {
1597 w
= VINO_MIN_WIDTH
* d
;
1598 h
= VINO_MIN_HEIGHT
* d
;
1601 if ((x
+ w
) > maxwidth
) {
1603 if ((w
/ d
) < VINO_MIN_WIDTH
)
1604 x
= maxwidth
- VINO_MIN_WIDTH
* d
;
1606 if ((y
+ h
) > maxheight
) {
1608 if ((h
/ d
) < VINO_MIN_HEIGHT
)
1609 y
= maxheight
- VINO_MIN_HEIGHT
* d
;
1612 vcs
->clipping
.left
= x
;
1613 vcs
->clipping
.top
= y
;
1614 vcs
->clipping
.right
= x
+ w
;
1615 vcs
->clipping
.bottom
= y
+ h
;
1617 vino_update_line_size(vcs
);
1619 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1620 vcs
->clipping
.left
, vcs
->clipping
.top
, vcs
->clipping
.right
,
1621 vcs
->clipping
.bottom
, vcs
->decimation
, vcs
->line_size
);
1624 /* execute with input_lock locked */
1625 static inline void vino_set_default_clipping(struct vino_channel_settings
*vcs
)
1627 vino_set_clipping(vcs
, 0, 0, vino_data_norms
[vcs
->data_norm
].width
,
1628 vino_data_norms
[vcs
->data_norm
].height
);
1631 /* execute with input_lock locked */
1632 static void vino_set_scaling(struct vino_channel_settings
*vcs
,
1633 unsigned int w
, unsigned int h
)
1635 unsigned int x
, y
, curw
, curh
, d
;
1637 x
= vcs
->clipping
.left
;
1638 y
= vcs
->clipping
.top
;
1639 curw
= vcs
->clipping
.right
- vcs
->clipping
.left
;
1640 curh
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
1642 d
= max(curw
/ w
, curh
/ h
);
1644 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1645 w
, h
, curw
, curh
, d
);
1653 vcs
->decimation
= d
;
1654 vino_set_clipping(vcs
, x
, y
, w
* d
, h
* d
);
1656 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs
->clipping
.left
,
1657 vcs
->clipping
.top
, vcs
->clipping
.right
, vcs
->clipping
.bottom
,
1658 vcs
->decimation
, vcs
->line_size
);
1661 /* execute with input_lock locked */
1662 static inline void vino_set_default_scaling(struct vino_channel_settings
*vcs
)
1664 vino_set_scaling(vcs
, vcs
->clipping
.right
- vcs
->clipping
.left
,
1665 vcs
->clipping
.bottom
- vcs
->clipping
.top
);
1668 /* execute with input_lock locked */
1669 static void vino_set_framerate(struct vino_channel_settings
*vcs
,
1674 switch (vcs
->data_norm
) {
1675 case VINO_DATA_NORM_NTSC
:
1676 case VINO_DATA_NORM_D1
:
1677 fps
= (unsigned int)(fps
/ 6) * 6; // FIXME: round!
1679 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1680 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1681 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1682 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1701 mask
= VINO_FRAMERT_FULL
;
1703 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
);
1705 case VINO_DATA_NORM_PAL
:
1706 case VINO_DATA_NORM_SECAM
:
1707 fps
= (unsigned int)(fps
/ 5) * 5; // FIXME: round!
1709 if (fps
< vino_data_norms
[vcs
->data_norm
].fps_min
)
1710 fps
= vino_data_norms
[vcs
->data_norm
].fps_min
;
1711 if (fps
> vino_data_norms
[vcs
->data_norm
].fps_max
)
1712 fps
= vino_data_norms
[vcs
->data_norm
].fps_max
;
1731 mask
= VINO_FRAMERT_FULL
;
1733 vcs
->framert_reg
= VINO_FRAMERT_RT(mask
) | VINO_FRAMERT_PAL
;
1740 /* execute with input_lock locked */
1741 static inline void vino_set_default_framerate(struct
1742 vino_channel_settings
*vcs
)
1744 vino_set_framerate(vcs
, vino_data_norms
[vcs
->data_norm
].fps_max
);
1748 * Prepare VINO for DMA transfer...
1749 * (execute only with vino_lock and input_lock locked)
1751 static int vino_dma_setup(struct vino_channel_settings
*vcs
,
1752 struct vino_framebuffer
*fb
)
1755 struct sgi_vino_channel
*ch
;
1756 const struct vino_data_norm
*norm
;
1758 dprintk("vino_dma_setup():\n");
1761 fb
->frame_counter
= 0;
1763 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1764 norm
= &vino_data_norms
[vcs
->data_norm
];
1769 /* VINO line size register is set 8 bytes less than actual */
1770 ch
->line_size
= vcs
->line_size
- 8;
1772 /* let VINO know where to transfer data */
1773 ch
->start_desc_tbl
= fb
->desc_table
.dma
;
1774 ch
->next_4_desc
= fb
->desc_table
.dma
;
1776 /* give vino time to fetch the first four descriptors, 5 usec
1777 * should be more than enough time */
1778 udelay(VINO_DESC_FETCH_DELAY
);
1780 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1781 ch
->start_desc_tbl
, ch
->next_4_desc
);
1783 /* set the alpha register */
1784 ch
->alpha
= vcs
->alpha
;
1786 /* set clipping registers */
1787 ch
->clip_start
= VINO_CLIP_ODD(norm
->odd
.top
+ vcs
->clipping
.top
/ 2) |
1788 VINO_CLIP_EVEN(norm
->even
.top
+
1789 vcs
->clipping
.top
/ 2) |
1790 VINO_CLIP_X(vcs
->clipping
.left
);
1791 ch
->clip_end
= VINO_CLIP_ODD(norm
->odd
.top
+
1792 vcs
->clipping
.bottom
/ 2 - 1) |
1793 VINO_CLIP_EVEN(norm
->even
.top
+
1794 vcs
->clipping
.bottom
/ 2 - 1) |
1795 VINO_CLIP_X(vcs
->clipping
.right
);
1797 /* set the size of actual content in the buffer (DECIMATION !) */
1798 fb
->data_size
= ((vcs
->clipping
.right
- vcs
->clipping
.left
) /
1800 ((vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
1802 vino_data_formats
[vcs
->data_format
].bpp
;
1804 ch
->frame_rate
= vcs
->framert_reg
;
1806 ctrl
= vino
->control
;
1807 intr
= vino
->intr_status
;
1809 if (vcs
->channel
== VINO_CHANNEL_A
) {
1810 /* All interrupt conditions for this channel was cleared
1811 * so clear the interrupt status register and enable
1813 intr
&= ~VINO_INTSTAT_A
;
1814 ctrl
|= VINO_CTRL_A_INT
;
1816 /* enable synchronization */
1817 ctrl
|= VINO_CTRL_A_SYNC_ENBL
;
1819 /* enable frame assembly */
1820 ctrl
|= VINO_CTRL_A_INTERLEAVE_ENBL
;
1822 /* set decimation used */
1823 if (vcs
->decimation
< 2)
1824 ctrl
&= ~VINO_CTRL_A_DEC_ENBL
;
1826 ctrl
|= VINO_CTRL_A_DEC_ENBL
;
1827 ctrl
&= ~VINO_CTRL_A_DEC_SCALE_MASK
;
1828 ctrl
|= (vcs
->decimation
- 1) <<
1829 VINO_CTRL_A_DEC_SCALE_SHIFT
;
1832 /* select input interface */
1833 if (vcs
->input
== VINO_INPUT_D1
)
1834 ctrl
|= VINO_CTRL_A_SELECT
;
1836 ctrl
&= ~VINO_CTRL_A_SELECT
;
1839 ctrl
&= ~(VINO_CTRL_A_LUMA_ONLY
| VINO_CTRL_A_RGB
|
1840 VINO_CTRL_A_DITHER
);
1842 intr
&= ~VINO_INTSTAT_B
;
1843 ctrl
|= VINO_CTRL_B_INT
;
1845 ctrl
|= VINO_CTRL_B_SYNC_ENBL
;
1846 ctrl
|= VINO_CTRL_B_INTERLEAVE_ENBL
;
1848 if (vcs
->decimation
< 2)
1849 ctrl
&= ~VINO_CTRL_B_DEC_ENBL
;
1851 ctrl
|= VINO_CTRL_B_DEC_ENBL
;
1852 ctrl
&= ~VINO_CTRL_B_DEC_SCALE_MASK
;
1853 ctrl
|= (vcs
->decimation
- 1) <<
1854 VINO_CTRL_B_DEC_SCALE_SHIFT
;
1857 if (vcs
->input
== VINO_INPUT_D1
)
1858 ctrl
|= VINO_CTRL_B_SELECT
;
1860 ctrl
&= ~VINO_CTRL_B_SELECT
;
1862 ctrl
&= ~(VINO_CTRL_B_LUMA_ONLY
| VINO_CTRL_B_RGB
|
1863 VINO_CTRL_B_DITHER
);
1867 fb
->data_format
= vcs
->data_format
;
1869 switch (vcs
->data_format
) {
1870 case VINO_DATA_FMT_GREY
:
1871 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1872 VINO_CTRL_A_LUMA_ONLY
: VINO_CTRL_B_LUMA_ONLY
;
1874 case VINO_DATA_FMT_RGB32
:
1875 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1876 VINO_CTRL_A_RGB
: VINO_CTRL_B_RGB
;
1878 case VINO_DATA_FMT_YUV
:
1879 /* nothing needs to be done */
1881 case VINO_DATA_FMT_RGB332
:
1882 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1883 VINO_CTRL_A_RGB
| VINO_CTRL_A_DITHER
:
1884 VINO_CTRL_B_RGB
| VINO_CTRL_B_DITHER
;
1888 vino
->intr_status
= intr
;
1889 vino
->control
= ctrl
;
1894 /* (execute only with vino_lock locked) */
1895 static inline void vino_dma_start(struct vino_channel_settings
*vcs
)
1897 u32 ctrl
= vino
->control
;
1899 dprintk("vino_dma_start():\n");
1900 ctrl
|= (vcs
->channel
== VINO_CHANNEL_A
) ?
1901 VINO_CTRL_A_DMA_ENBL
: VINO_CTRL_B_DMA_ENBL
;
1902 vino
->control
= ctrl
;
1905 /* (execute only with vino_lock locked) */
1906 static inline void vino_dma_stop(struct vino_channel_settings
*vcs
)
1908 u32 ctrl
= vino
->control
;
1910 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1911 ~VINO_CTRL_A_DMA_ENBL
: ~VINO_CTRL_B_DMA_ENBL
;
1912 ctrl
&= (vcs
->channel
== VINO_CHANNEL_A
) ?
1913 ~VINO_CTRL_A_INT
: ~VINO_CTRL_B_INT
;
1914 vino
->control
= ctrl
;
1915 dprintk("vino_dma_stop():\n");
1919 * Load dummy page to descriptor registers. This prevents generating of
1920 * spurious interrupts. (execute only with vino_lock locked)
1922 static void vino_clear_interrupt(struct vino_channel_settings
*vcs
)
1924 struct sgi_vino_channel
*ch
;
1926 ch
= (vcs
->channel
== VINO_CHANNEL_A
) ? &vino
->a
: &vino
->b
;
1931 ch
->start_desc_tbl
= vino_drvdata
->dummy_desc_table
.dma
;
1932 ch
->next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
1934 udelay(VINO_DESC_FETCH_DELAY
);
1935 dprintk("channel %c clear interrupt condition\n",
1936 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A':'B');
1939 static int vino_capture(struct vino_channel_settings
*vcs
,
1940 struct vino_framebuffer
*fb
)
1943 unsigned long flags
, flags2
;
1945 spin_lock_irqsave(&fb
->state_lock
, flags
);
1947 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
1949 fb
->state
= VINO_FRAMEBUFFER_IN_USE
;
1951 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
1956 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
1957 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags2
);
1959 vino_dma_setup(vcs
, fb
);
1960 vino_dma_start(vcs
);
1962 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags2
);
1963 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
1969 struct vino_framebuffer
*vino_capture_enqueue(struct
1970 vino_channel_settings
*vcs
,
1973 struct vino_framebuffer
*fb
;
1974 unsigned long flags
;
1976 dprintk("vino_capture_enqueue():\n");
1978 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
1980 fb
= vino_queue_add(&vcs
->fb_queue
, index
);
1982 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
1987 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
1992 static int vino_capture_next(struct vino_channel_settings
*vcs
, int start
)
1994 struct vino_framebuffer
*fb
;
1995 unsigned int incoming
, id
;
1997 unsigned long flags
;
1999 dprintk("vino_capture_next():\n");
2001 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2004 /* start capture only if capture isn't in progress already */
2005 if (vcs
->capturing
) {
2006 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2011 /* capture next frame:
2012 * stop capture if capturing is not set */
2013 if (!vcs
->capturing
) {
2014 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2019 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
2021 dprintk("vino_capture_next(): vino_queue_get_incoming() "
2026 if (incoming
== 0) {
2027 dprintk("vino_capture_next(): no buffers available\n");
2031 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2033 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
2042 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2044 err
= vino_capture(vcs
, fb
);
2050 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2055 static inline int vino_is_capturing(struct vino_channel_settings
*vcs
)
2058 unsigned long flags
;
2060 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2062 ret
= vcs
->capturing
;
2064 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2069 /* waits until a frame is captured */
2070 static int vino_wait_for_frame(struct vino_channel_settings
*vcs
)
2075 dprintk("vino_wait_for_frame():\n");
2077 init_waitqueue_entry(&wait
, current
);
2078 /* add ourselves into wait queue */
2079 add_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2081 /* to ensure that schedule_timeout will return immediately
2082 * if VINO interrupt was triggered meanwhile */
2083 schedule_timeout_interruptible(msecs_to_jiffies(100));
2085 if (signal_pending(current
))
2088 remove_wait_queue(&vcs
->fb_queue
.frame_wait_queue
, &wait
);
2090 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2091 err
? "failed" : "ok");
2096 /* the function assumes that PAGE_SIZE % 4 == 0 */
2097 static void vino_convert_to_rgba(struct vino_framebuffer
*fb
) {
2098 unsigned char *pageptr
;
2099 unsigned int page
, i
;
2102 for (page
= 0; page
< fb
->desc_table
.page_count
; page
++) {
2103 pageptr
= (unsigned char *)fb
->desc_table
.virtual[page
];
2105 for (i
= 0; i
< PAGE_SIZE
; i
+= 4) {
2107 pageptr
[0] = pageptr
[3];
2108 pageptr
[1] = pageptr
[2];
2109 pageptr
[2] = pageptr
[1];
2116 /* checks if the buffer is in correct state and syncs data */
2117 static int vino_check_buffer(struct vino_channel_settings
*vcs
,
2118 struct vino_framebuffer
*fb
)
2121 unsigned long flags
;
2123 dprintk("vino_check_buffer():\n");
2125 spin_lock_irqsave(&fb
->state_lock
, flags
);
2126 switch (fb
->state
) {
2127 case VINO_FRAMEBUFFER_IN_USE
:
2130 case VINO_FRAMEBUFFER_READY
:
2131 vino_sync_buffer(fb
);
2132 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2137 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2140 if (vino_pixel_conversion
2141 && (fb
->data_format
== VINO_DATA_FMT_RGB32
)) {
2142 vino_convert_to_rgba(fb
);
2144 } else if (err
&& (err
!= -EINVAL
)) {
2145 dprintk("vino_check_buffer(): buffer not ready\n");
2147 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2149 vino_clear_interrupt(vcs
);
2150 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2156 /* forcefully terminates capture */
2157 static void vino_capture_stop(struct vino_channel_settings
*vcs
)
2159 unsigned int incoming
= 0, outgoing
= 0, id
;
2160 unsigned long flags
, flags2
;
2162 dprintk("vino_capture_stop():\n");
2164 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2166 /* unset capturing to stop queue processing */
2169 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags2
);
2172 vino_clear_interrupt(vcs
);
2174 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags2
);
2176 /* remove all items from the queue */
2177 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2178 dprintk("vino_capture_stop(): "
2179 "vino_queue_get_incoming() failed\n");
2182 while (incoming
> 0) {
2183 vino_queue_transfer(&vcs
->fb_queue
);
2185 if (vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
)) {
2186 dprintk("vino_capture_stop(): "
2187 "vino_queue_get_incoming() failed\n");
2192 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2193 dprintk("vino_capture_stop(): "
2194 "vino_queue_get_outgoing() failed\n");
2197 while (outgoing
> 0) {
2198 vino_queue_remove(&vcs
->fb_queue
, &id
);
2200 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
2201 dprintk("vino_capture_stop(): "
2202 "vino_queue_get_outgoing() failed\n");
2208 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2212 static int vino_capture_failed(struct vino_channel_settings
*vcs
)
2214 struct vino_framebuffer
*fb
;
2215 unsigned long flags
;
2219 dprintk("vino_capture_failed():\n");
2221 spin_lock_irqsave(&vino_drvdata
->vino_lock
, flags
);
2224 vino_clear_interrupt(vcs
);
2226 spin_unlock_irqrestore(&vino_drvdata
->vino_lock
, flags
);
2228 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &i
);
2229 if (ret
== VINO_QUEUE_ERROR
) {
2230 dprintk("vino_queue_get_incoming() failed\n");
2234 /* no buffers to process */
2238 fb
= vino_queue_peek(&vcs
->fb_queue
, &i
);
2240 dprintk("vino_queue_peek() failed\n");
2244 spin_lock_irqsave(&fb
->state_lock
, flags
);
2245 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
) {
2246 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2247 vino_queue_transfer(&vcs
->fb_queue
);
2248 vino_queue_remove(&vcs
->fb_queue
, &i
);
2249 /* we should actually discard the newest frame,
2250 * but who cares ... */
2252 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2258 static void vino_skip_frame(struct vino_channel_settings
*vcs
)
2260 struct vino_framebuffer
*fb
;
2261 unsigned long flags
;
2264 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2265 fb
= vino_queue_peek(&vcs
->fb_queue
, &id
);
2267 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2268 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2271 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2273 spin_lock_irqsave(&fb
->state_lock
, flags
);
2274 fb
->state
= VINO_FRAMEBUFFER_UNUSED
;
2275 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2277 vino_capture_next(vcs
, 0);
2280 static void vino_frame_done(struct vino_channel_settings
*vcs
)
2282 struct vino_framebuffer
*fb
;
2283 unsigned long flags
;
2285 spin_lock_irqsave(&vcs
->capture_lock
, flags
);
2286 fb
= vino_queue_transfer(&vcs
->fb_queue
);
2288 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2289 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2292 spin_unlock_irqrestore(&vcs
->capture_lock
, flags
);
2294 fb
->frame_counter
= vcs
->int_data
.frame_counter
;
2295 memcpy(&fb
->timestamp
, &vcs
->int_data
.timestamp
,
2296 sizeof(struct timeval
));
2298 spin_lock_irqsave(&fb
->state_lock
, flags
);
2299 if (fb
->state
== VINO_FRAMEBUFFER_IN_USE
)
2300 fb
->state
= VINO_FRAMEBUFFER_READY
;
2301 spin_unlock_irqrestore(&fb
->state_lock
, flags
);
2303 wake_up(&vcs
->fb_queue
.frame_wait_queue
);
2305 vino_capture_next(vcs
, 0);
2308 static void vino_capture_tasklet(unsigned long channel
) {
2309 struct vino_channel_settings
*vcs
;
2311 vcs
= (channel
== VINO_CHANNEL_A
)
2312 ? &vino_drvdata
->a
: &vino_drvdata
->b
;
2314 if (vcs
->int_data
.skip
)
2315 vcs
->int_data
.skip_count
++;
2317 if (vcs
->int_data
.skip
&& (vcs
->int_data
.skip_count
2318 <= VINO_MAX_FRAME_SKIP_COUNT
)) {
2319 vino_skip_frame(vcs
);
2321 vcs
->int_data
.skip_count
= 0;
2322 vino_frame_done(vcs
);
2326 static irqreturn_t
vino_interrupt(int irq
, void *dev_id
)
2329 unsigned int fc_a
, fc_b
;
2330 int handled_a
= 0, skip_a
= 0, done_a
= 0;
2331 int handled_b
= 0, skip_b
= 0, done_b
= 0;
2333 #ifdef VINO_DEBUG_INT
2335 unsigned int line_count
= vino
->a
.line_count
,
2336 page_index
= vino
->a
.page_index
,
2337 field_counter
= vino
->a
.field_counter
,
2338 start_desc_tbl
= vino
->a
.start_desc_tbl
,
2339 next_4_desc
= vino
->a
.next_4_desc
;
2340 unsigned int line_count_2
,
2347 spin_lock(&vino_drvdata
->vino_lock
);
2349 while ((intr
= vino
->intr_status
)) {
2350 fc_a
= vino
->a
.field_counter
>> 1;
2351 fc_b
= vino
->b
.field_counter
>> 1;
2353 /* handle error-interrupts in some special way ?
2354 * --> skips frames */
2355 if (intr
& VINO_INTSTAT_A
) {
2356 if (intr
& VINO_INTSTAT_A_EOF
) {
2357 vino_drvdata
->a
.field
++;
2358 if (vino_drvdata
->a
.field
> 1) {
2359 vino_dma_stop(&vino_drvdata
->a
);
2360 vino_clear_interrupt(&vino_drvdata
->a
);
2361 vino_drvdata
->a
.field
= 0;
2364 if (vino
->a
.page_index
2365 != vino_drvdata
->a
.line_size
) {
2366 vino
->a
.line_count
= 0;
2367 vino
->a
.page_index
=
2370 vino
->a
.next_4_desc
=
2371 vino
->a
.start_desc_tbl
;
2374 dprintk("channel A end-of-field "
2375 "interrupt: %04x\n", intr
);
2377 vino_dma_stop(&vino_drvdata
->a
);
2378 vino_clear_interrupt(&vino_drvdata
->a
);
2379 vino_drvdata
->a
.field
= 0;
2381 dprintk("channel A error interrupt: %04x\n",
2385 #ifdef VINO_DEBUG_INT
2386 line_count_2
= vino
->a
.line_count
;
2387 page_index_2
= vino
->a
.page_index
;
2388 field_counter_2
= vino
->a
.field_counter
;
2389 start_desc_tbl_2
= vino
->a
.start_desc_tbl
;
2390 next_4_desc_2
= vino
->a
.next_4_desc
;
2392 printk("intr = %04x, loop = %d, field = %d\n",
2393 intr
, loop
, vino_drvdata
->a
.field
);
2394 printk("1- line count = %04d, page index = %04d, "
2395 "start = %08x, next = %08x\n"
2396 " fieldc = %d, framec = %d\n",
2397 line_count
, page_index
, start_desc_tbl
,
2398 next_4_desc
, field_counter
, fc_a
);
2399 printk("12-line count = %04d, page index = %04d, "
2400 " start = %08x, next = %08x\n",
2401 line_count_2
, page_index_2
, start_desc_tbl_2
,
2409 if (intr
& VINO_INTSTAT_B
) {
2410 if (intr
& VINO_INTSTAT_B_EOF
) {
2411 vino_drvdata
->b
.field
++;
2412 if (vino_drvdata
->b
.field
> 1) {
2413 vino_dma_stop(&vino_drvdata
->b
);
2414 vino_clear_interrupt(&vino_drvdata
->b
);
2415 vino_drvdata
->b
.field
= 0;
2418 dprintk("channel B end-of-field "
2419 "interrupt: %04x\n", intr
);
2421 vino_dma_stop(&vino_drvdata
->b
);
2422 vino_clear_interrupt(&vino_drvdata
->b
);
2423 vino_drvdata
->b
.field
= 0;
2425 dprintk("channel B error interrupt: %04x\n",
2430 /* Always remember to clear interrupt status.
2431 * Disable VINO interrupts while we do this. */
2432 ctrl
= vino
->control
;
2433 vino
->control
= ctrl
& ~(VINO_CTRL_A_INT
| VINO_CTRL_B_INT
);
2434 vino
->intr_status
= ~intr
;
2435 vino
->control
= ctrl
;
2437 spin_unlock(&vino_drvdata
->vino_lock
);
2439 if ((!handled_a
) && (done_a
|| skip_a
)) {
2441 do_gettimeofday(&vino_drvdata
->
2442 a
.int_data
.timestamp
);
2443 vino_drvdata
->a
.int_data
.frame_counter
= fc_a
;
2445 vino_drvdata
->a
.int_data
.skip
= skip_a
;
2447 dprintk("channel A %s, interrupt: %d\n",
2448 skip_a
? "skipping frame" : "frame done",
2450 tasklet_hi_schedule(&vino_tasklet_a
);
2454 if ((!handled_b
) && (done_b
|| skip_b
)) {
2456 do_gettimeofday(&vino_drvdata
->
2457 b
.int_data
.timestamp
);
2458 vino_drvdata
->b
.int_data
.frame_counter
= fc_b
;
2460 vino_drvdata
->b
.int_data
.skip
= skip_b
;
2462 dprintk("channel B %s, interrupt: %d\n",
2463 skip_b
? "skipping frame" : "frame done",
2465 tasklet_hi_schedule(&vino_tasklet_b
);
2469 #ifdef VINO_DEBUG_INT
2472 spin_lock(&vino_drvdata
->vino_lock
);
2475 spin_unlock(&vino_drvdata
->vino_lock
);
2480 /* VINO video input management */
2482 static int vino_get_saa7191_input(int input
)
2485 case VINO_INPUT_COMPOSITE
:
2486 return SAA7191_INPUT_COMPOSITE
;
2487 case VINO_INPUT_SVIDEO
:
2488 return SAA7191_INPUT_SVIDEO
;
2490 printk(KERN_ERR
"VINO: vino_get_saa7191_input(): "
2491 "invalid input!\n");
2496 static int vino_get_saa7191_norm(unsigned int data_norm
)
2498 switch (data_norm
) {
2499 case VINO_DATA_NORM_AUTO
:
2500 return SAA7191_NORM_AUTO
;
2501 case VINO_DATA_NORM_AUTO_EXT
:
2502 return SAA7191_NORM_AUTO_EXT
;
2503 case VINO_DATA_NORM_PAL
:
2504 return SAA7191_NORM_PAL
;
2505 case VINO_DATA_NORM_NTSC
:
2506 return SAA7191_NORM_NTSC
;
2507 case VINO_DATA_NORM_SECAM
:
2508 return SAA7191_NORM_SECAM
;
2510 printk(KERN_ERR
"VINO: vino_get_saa7191_norm(): "
2516 static int vino_get_from_saa7191_norm(int saa7191_norm
)
2518 switch (saa7191_norm
) {
2519 case SAA7191_NORM_PAL
:
2520 return VINO_DATA_NORM_PAL
;
2521 case SAA7191_NORM_NTSC
:
2522 return VINO_DATA_NORM_NTSC
;
2523 case SAA7191_NORM_SECAM
:
2524 return VINO_DATA_NORM_SECAM
;
2526 printk(KERN_ERR
"VINO: vino_get_from_saa7191_norm(): "
2528 return VINO_DATA_NORM_NONE
;
2532 static int vino_saa7191_set_norm(unsigned int *data_norm
)
2534 int saa7191_norm
, new_data_norm
;
2537 saa7191_norm
= vino_get_saa7191_norm(*data_norm
);
2539 err
= i2c_decoder_command(DECODER_SAA7191_SET_NORM
,
2544 if ((*data_norm
== VINO_DATA_NORM_AUTO
)
2545 || (*data_norm
== VINO_DATA_NORM_AUTO_EXT
)) {
2546 struct saa7191_status status
;
2548 err
= i2c_decoder_command(DECODER_SAA7191_GET_STATUS
,
2554 vino_get_from_saa7191_norm(status
.norm
);
2555 if (new_data_norm
== VINO_DATA_NORM_NONE
) {
2560 *data_norm
= (unsigned int)new_data_norm
;
2567 /* execute with input_lock locked */
2568 static int vino_is_input_owner(struct vino_channel_settings
*vcs
)
2570 switch(vcs
->input
) {
2571 case VINO_INPUT_COMPOSITE
:
2572 case VINO_INPUT_SVIDEO
:
2573 return (vino_drvdata
->decoder
.owner
== vcs
->channel
);
2575 return (vino_drvdata
->camera
.owner
== vcs
->channel
);
2581 static int vino_acquire_input(struct vino_channel_settings
*vcs
)
2583 unsigned long flags
;
2586 dprintk("vino_acquire_input():\n");
2588 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2590 /* First try D1 and then SAA7191 */
2591 if (vino_drvdata
->camera
.driver
2592 && (vino_drvdata
->camera
.owner
== VINO_NO_CHANNEL
)) {
2593 if (i2c_use_client(vino_drvdata
->camera
.driver
)) {
2598 vino_drvdata
->camera
.owner
= vcs
->channel
;
2599 vcs
->input
= VINO_INPUT_D1
;
2600 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2601 } else if (vino_drvdata
->decoder
.driver
2602 && (vino_drvdata
->decoder
.owner
== VINO_NO_CHANNEL
)) {
2603 int input
, data_norm
;
2606 if (i2c_use_client(vino_drvdata
->decoder
.driver
)) {
2611 input
= VINO_INPUT_COMPOSITE
;
2613 saa7191_input
= vino_get_saa7191_input(input
);
2614 ret
= i2c_decoder_command(DECODER_SET_INPUT
,
2621 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2623 /* Don't hold spinlocks while auto-detecting norm
2624 * as it may take a while... */
2626 data_norm
= VINO_DATA_NORM_AUTO_EXT
;
2628 ret
= vino_saa7191_set_norm(&data_norm
);
2629 if ((ret
== -EBUSY
) || (ret
== -EAGAIN
)) {
2630 data_norm
= VINO_DATA_NORM_PAL
;
2631 ret
= vino_saa7191_set_norm(&data_norm
);
2634 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2641 vino_drvdata
->decoder
.owner
= vcs
->channel
;
2644 vcs
->data_norm
= data_norm
;
2646 vcs
->input
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2647 vino_drvdata
->b
.input
: vino_drvdata
->a
.input
;
2648 vcs
->data_norm
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2649 vino_drvdata
->b
.data_norm
: vino_drvdata
->a
.data_norm
;
2652 if (vcs
->input
== VINO_INPUT_NONE
) {
2657 vino_set_default_clipping(vcs
);
2658 vino_set_default_scaling(vcs
);
2659 vino_set_default_framerate(vcs
);
2661 dprintk("vino_acquire_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2664 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2669 static int vino_set_input(struct vino_channel_settings
*vcs
, int input
)
2671 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2672 &vino_drvdata
->b
: &vino_drvdata
->a
;
2673 unsigned long flags
;
2676 dprintk("vino_set_input():\n");
2678 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2680 if (vcs
->input
== input
)
2684 case VINO_INPUT_COMPOSITE
:
2685 case VINO_INPUT_SVIDEO
:
2686 if (!vino_drvdata
->decoder
.driver
) {
2691 if (vino_drvdata
->decoder
.owner
== VINO_NO_CHANNEL
) {
2692 if (i2c_use_client(vino_drvdata
->decoder
.driver
)) {
2696 vino_drvdata
->decoder
.owner
= vcs
->channel
;
2699 if (vino_drvdata
->decoder
.owner
== vcs
->channel
) {
2703 saa7191_input
= vino_get_saa7191_input(input
);
2704 ret
= i2c_decoder_command(DECODER_SET_INPUT
,
2707 vino_drvdata
->decoder
.owner
= VINO_NO_CHANNEL
;
2712 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2714 /* Don't hold spinlocks while auto-detecting norm
2715 * as it may take a while... */
2717 data_norm
= VINO_DATA_NORM_AUTO_EXT
;
2719 ret
= vino_saa7191_set_norm(&data_norm
);
2720 if ((ret
== -EBUSY
) || (ret
== -EAGAIN
)) {
2721 data_norm
= VINO_DATA_NORM_PAL
;
2722 ret
= vino_saa7191_set_norm(&data_norm
);
2725 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2728 vino_drvdata
->decoder
.owner
= VINO_NO_CHANNEL
;
2734 vcs
->data_norm
= data_norm
;
2736 if (input
!= vcs2
->input
) {
2742 vcs
->data_norm
= vcs2
->data_norm
;
2745 if (vino_drvdata
->camera
.owner
== vcs
->channel
) {
2746 /* Transfer the ownership or release the input */
2747 if (vcs2
->input
== VINO_INPUT_D1
) {
2748 vino_drvdata
->camera
.owner
= vcs2
->channel
;
2750 i2c_release_client(vino_drvdata
->
2752 vino_drvdata
->camera
.owner
= VINO_NO_CHANNEL
;
2757 if (!vino_drvdata
->camera
.driver
) {
2762 if (vino_drvdata
->camera
.owner
== VINO_NO_CHANNEL
) {
2763 if (i2c_use_client(vino_drvdata
->camera
.driver
)) {
2767 vino_drvdata
->camera
.owner
= vcs
->channel
;
2770 if (vino_drvdata
->decoder
.owner
== vcs
->channel
) {
2771 /* Transfer the ownership or release the input */
2772 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2773 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2774 vino_drvdata
->decoder
.owner
= vcs2
->channel
;
2776 i2c_release_client(vino_drvdata
->
2778 vino_drvdata
->decoder
.owner
= VINO_NO_CHANNEL
;
2783 vcs
->data_norm
= VINO_DATA_NORM_D1
;
2790 vino_set_default_clipping(vcs
);
2791 vino_set_default_scaling(vcs
);
2792 vino_set_default_framerate(vcs
);
2794 dprintk("vino_set_input(): %s\n", vino_inputs
[vcs
->input
].name
);
2797 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2802 static void vino_release_input(struct vino_channel_settings
*vcs
)
2804 struct vino_channel_settings
*vcs2
= (vcs
->channel
== VINO_CHANNEL_A
) ?
2805 &vino_drvdata
->b
: &vino_drvdata
->a
;
2806 unsigned long flags
;
2808 dprintk("vino_release_input():\n");
2810 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2812 /* Release ownership of the channel
2813 * and if the other channel takes input from
2814 * the same source, transfer the ownership */
2815 if (vino_drvdata
->camera
.owner
== vcs
->channel
) {
2816 if (vcs2
->input
== VINO_INPUT_D1
) {
2817 vino_drvdata
->camera
.owner
= vcs2
->channel
;
2819 i2c_release_client(vino_drvdata
->camera
.driver
);
2820 vino_drvdata
->camera
.owner
= VINO_NO_CHANNEL
;
2822 } else if (vino_drvdata
->decoder
.owner
== vcs
->channel
) {
2823 if ((vcs2
->input
== VINO_INPUT_COMPOSITE
) ||
2824 (vcs2
->input
== VINO_INPUT_SVIDEO
)) {
2825 vino_drvdata
->decoder
.owner
= vcs2
->channel
;
2827 i2c_release_client(vino_drvdata
->decoder
.driver
);
2828 vino_drvdata
->decoder
.owner
= VINO_NO_CHANNEL
;
2831 vcs
->input
= VINO_INPUT_NONE
;
2833 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2836 /* execute with input_lock locked */
2837 static int vino_set_data_norm(struct vino_channel_settings
*vcs
,
2838 unsigned int data_norm
,
2839 unsigned long *flags
)
2843 if (data_norm
== vcs
->data_norm
)
2846 switch (vcs
->input
) {
2848 /* only one "norm" supported */
2849 if ((data_norm
!= VINO_DATA_NORM_D1
)
2850 && (data_norm
!= VINO_DATA_NORM_AUTO
)
2851 && (data_norm
!= VINO_DATA_NORM_AUTO_EXT
))
2854 case VINO_INPUT_COMPOSITE
:
2855 case VINO_INPUT_SVIDEO
: {
2856 if ((data_norm
!= VINO_DATA_NORM_PAL
)
2857 && (data_norm
!= VINO_DATA_NORM_NTSC
)
2858 && (data_norm
!= VINO_DATA_NORM_SECAM
)
2859 && (data_norm
!= VINO_DATA_NORM_AUTO
)
2860 && (data_norm
!= VINO_DATA_NORM_AUTO_EXT
))
2863 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, *flags
);
2865 /* Don't hold spinlocks while setting norm
2866 * as it may take a while... */
2868 err
= vino_saa7191_set_norm(&data_norm
);
2870 spin_lock_irqsave(&vino_drvdata
->input_lock
, *flags
);
2875 vcs
->data_norm
= data_norm
;
2877 vino_set_default_clipping(vcs
);
2878 vino_set_default_scaling(vcs
);
2879 vino_set_default_framerate(vcs
);
2890 /* V4L2 helper functions */
2892 static int vino_find_data_format(__u32 pixelformat
)
2896 for (i
= 0; i
< VINO_DATA_FMT_COUNT
; i
++) {
2897 if (vino_data_formats
[i
].pixelformat
== pixelformat
)
2901 return VINO_DATA_FMT_NONE
;
2904 static int vino_enum_data_norm(struct vino_channel_settings
*vcs
, __u32 index
)
2906 int data_norm
= VINO_DATA_NORM_NONE
;
2907 unsigned long flags
;
2909 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2910 switch(vcs
->input
) {
2911 case VINO_INPUT_COMPOSITE
:
2912 case VINO_INPUT_SVIDEO
:
2914 data_norm
= VINO_DATA_NORM_PAL
;
2915 } else if (index
== 1) {
2916 data_norm
= VINO_DATA_NORM_NTSC
;
2917 } else if (index
== 2) {
2918 data_norm
= VINO_DATA_NORM_SECAM
;
2923 data_norm
= VINO_DATA_NORM_D1
;
2927 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2932 static int vino_enum_input(struct vino_channel_settings
*vcs
, __u32 index
)
2934 int input
= VINO_INPUT_NONE
;
2935 unsigned long flags
;
2937 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
2938 if (vino_drvdata
->decoder
.driver
&& vino_drvdata
->camera
.driver
) {
2941 input
= VINO_INPUT_COMPOSITE
;
2944 input
= VINO_INPUT_SVIDEO
;
2947 input
= VINO_INPUT_D1
;
2950 } else if (vino_drvdata
->decoder
.driver
) {
2953 input
= VINO_INPUT_COMPOSITE
;
2956 input
= VINO_INPUT_SVIDEO
;
2959 } else if (vino_drvdata
->camera
.driver
) {
2962 input
= VINO_INPUT_D1
;
2966 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
2971 /* execute with input_lock locked */
2972 static __u32
vino_find_input_index(struct vino_channel_settings
*vcs
)
2975 // FIXME: detect when no inputs available
2977 if (vino_drvdata
->decoder
.driver
&& vino_drvdata
->camera
.driver
) {
2978 switch (vcs
->input
) {
2979 case VINO_INPUT_COMPOSITE
:
2982 case VINO_INPUT_SVIDEO
:
2989 } else if (vino_drvdata
->decoder
.driver
) {
2990 switch (vcs
->input
) {
2991 case VINO_INPUT_COMPOSITE
:
2994 case VINO_INPUT_SVIDEO
:
2998 } else if (vino_drvdata
->camera
.driver
) {
2999 switch (vcs
->input
) {
3011 static void vino_v4l2_querycap(struct v4l2_capability
*cap
)
3013 memset(cap
, 0, sizeof(struct v4l2_capability
));
3015 strcpy(cap
->driver
, vino_driver_name
);
3016 strcpy(cap
->card
, vino_driver_description
);
3017 strcpy(cap
->bus_info
, vino_bus_name
);
3018 cap
->version
= VINO_VERSION_CODE
;
3020 V4L2_CAP_VIDEO_CAPTURE
|
3022 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
3025 static int vino_v4l2_enuminput(struct vino_channel_settings
*vcs
,
3026 struct v4l2_input
*i
)
3028 __u32 index
= i
->index
;
3030 dprintk("requested index = %d\n", index
);
3032 input
= vino_enum_input(vcs
, index
);
3033 if (input
== VINO_INPUT_NONE
)
3036 memset(i
, 0, sizeof(struct v4l2_input
));
3039 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
3040 i
->std
= vino_inputs
[input
].std
;
3041 strcpy(i
->name
, vino_inputs
[input
].name
);
3043 if ((input
== VINO_INPUT_COMPOSITE
)
3044 || (input
== VINO_INPUT_SVIDEO
)) {
3045 struct saa7191_status status
;
3046 i2c_decoder_command(DECODER_SAA7191_GET_STATUS
, &status
);
3047 i
->status
|= status
.signal
? 0 : V4L2_IN_ST_NO_SIGNAL
;
3048 i
->status
|= status
.color
? 0 : V4L2_IN_ST_NO_COLOR
;
3054 static int vino_v4l2_g_input(struct vino_channel_settings
*vcs
,
3059 unsigned long flags
;
3061 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3063 index
= vino_find_input_index(vcs
);
3064 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3066 dprintk("input = %d\n", input
);
3068 if (input
== VINO_INPUT_NONE
) {
3077 static int vino_v4l2_s_input(struct vino_channel_settings
*vcs
,
3081 dprintk("requested input = %d\n", *i
);
3083 input
= vino_enum_input(vcs
, *i
);
3084 if (input
== VINO_INPUT_NONE
)
3087 return vino_set_input(vcs
, input
);
3090 static int vino_v4l2_enumstd(struct vino_channel_settings
*vcs
,
3091 struct v4l2_standard
*s
)
3093 int index
= s
->index
;
3096 data_norm
= vino_enum_data_norm(vcs
, index
);
3097 dprintk("standard index = %d\n", index
);
3099 if (data_norm
== VINO_DATA_NORM_NONE
)
3102 dprintk("standard name = %s\n",
3103 vino_data_norms
[data_norm
].description
);
3105 memset(s
, 0, sizeof(struct v4l2_standard
));
3108 s
->id
= vino_data_norms
[data_norm
].std
;
3109 s
->frameperiod
.numerator
= 1;
3110 s
->frameperiod
.denominator
=
3111 vino_data_norms
[data_norm
].fps_max
;
3113 vino_data_norms
[data_norm
].framelines
;
3115 vino_data_norms
[data_norm
].description
);
3120 static int vino_v4l2_querystd(struct vino_channel_settings
*vcs
,
3123 unsigned long flags
;
3126 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3128 switch (vcs
->input
) {
3130 *std
= vino_inputs
[vcs
->input
].std
;
3132 case VINO_INPUT_COMPOSITE
:
3133 case VINO_INPUT_SVIDEO
: {
3134 struct saa7191_status status
;
3136 i2c_decoder_command(DECODER_SAA7191_GET_STATUS
, &status
);
3138 if (status
.signal
) {
3139 if (status
.signal_60hz
) {
3140 *std
= V4L2_STD_NTSC
;
3142 *std
= V4L2_STD_PAL
| V4L2_STD_SECAM
;
3145 *std
= vino_inputs
[vcs
->input
].std
;
3153 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3158 static int vino_v4l2_g_std(struct vino_channel_settings
*vcs
,
3161 unsigned long flags
;
3163 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3165 *std
= vino_data_norms
[vcs
->data_norm
].std
;
3166 dprintk("current standard = %d\n", vcs
->data_norm
);
3168 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3173 static int vino_v4l2_s_std(struct vino_channel_settings
*vcs
,
3176 unsigned long flags
;
3179 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3181 if (!vino_is_input_owner(vcs
)) {
3186 /* check if the standard is valid for the current input */
3187 if ((*std
) & vino_inputs
[vcs
->input
].std
) {
3188 dprintk("standard accepted\n");
3190 /* change the video norm for SAA7191
3191 * and accept NTSC for D1 (do nothing) */
3193 if (vcs
->input
== VINO_INPUT_D1
)
3196 if (((*std
) & V4L2_STD_PAL
)
3197 && ((*std
) & V4L2_STD_NTSC
)
3198 && ((*std
) & V4L2_STD_SECAM
)) {
3199 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_AUTO_EXT
,
3201 } else if ((*std
) & V4L2_STD_PAL
) {
3202 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_PAL
,
3204 } else if ((*std
) & V4L2_STD_NTSC
) {
3205 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_NTSC
,
3207 } else if ((*std
) & V4L2_STD_SECAM
) {
3208 ret
= vino_set_data_norm(vcs
, VINO_DATA_NORM_SECAM
,
3222 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3227 static int vino_v4l2_enum_fmt(struct vino_channel_settings
*vcs
,
3228 struct v4l2_fmtdesc
*fd
)
3230 enum v4l2_buf_type type
= fd
->type
;
3231 int index
= fd
->index
;
3232 dprintk("format index = %d\n", index
);
3235 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3236 if ((fd
->index
< 0) ||
3237 (fd
->index
>= VINO_DATA_FMT_COUNT
))
3239 dprintk("format name = %s\n",
3240 vino_data_formats
[index
].description
);
3242 memset(fd
, 0, sizeof(struct v4l2_fmtdesc
));
3245 fd
->pixelformat
= vino_data_formats
[index
].pixelformat
;
3246 strcpy(fd
->description
, vino_data_formats
[index
].description
);
3248 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3256 static int vino_v4l2_try_fmt(struct vino_channel_settings
*vcs
,
3257 struct v4l2_format
*f
)
3259 struct vino_channel_settings tempvcs
;
3260 unsigned long flags
;
3263 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3264 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3266 dprintk("requested: w = %d, h = %d\n",
3267 pf
->width
, pf
->height
);
3269 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3270 memcpy(&tempvcs
, vcs
, sizeof(struct vino_channel_settings
));
3271 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3273 tempvcs
.data_format
= vino_find_data_format(pf
->pixelformat
);
3274 if (tempvcs
.data_format
== VINO_DATA_FMT_NONE
) {
3275 tempvcs
.data_format
= VINO_DATA_FMT_GREY
;
3277 vino_data_formats
[tempvcs
.data_format
].
3281 /* data format must be set before clipping/scaling */
3282 vino_set_scaling(&tempvcs
, pf
->width
, pf
->height
);
3284 dprintk("data format = %s\n",
3285 vino_data_formats
[tempvcs
.data_format
].description
);
3287 pf
->width
= (tempvcs
.clipping
.right
- tempvcs
.clipping
.left
) /
3289 pf
->height
= (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3292 pf
->field
= V4L2_FIELD_INTERLACED
;
3293 pf
->bytesperline
= tempvcs
.line_size
;
3294 pf
->sizeimage
= tempvcs
.line_size
*
3295 (tempvcs
.clipping
.bottom
- tempvcs
.clipping
.top
) /
3298 vino_data_formats
[tempvcs
.data_format
].colorspace
;
3303 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3311 static int vino_v4l2_g_fmt(struct vino_channel_settings
*vcs
,
3312 struct v4l2_format
*f
)
3314 unsigned long flags
;
3317 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3318 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3320 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3322 pf
->width
= (vcs
->clipping
.right
- vcs
->clipping
.left
) /
3324 pf
->height
= (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3327 vino_data_formats
[vcs
->data_format
].pixelformat
;
3329 pf
->field
= V4L2_FIELD_INTERLACED
;
3330 pf
->bytesperline
= vcs
->line_size
;
3331 pf
->sizeimage
= vcs
->line_size
*
3332 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3335 vino_data_formats
[vcs
->data_format
].colorspace
;
3339 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3342 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3350 static int vino_v4l2_s_fmt(struct vino_channel_settings
*vcs
,
3351 struct v4l2_format
*f
)
3354 unsigned long flags
;
3357 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3358 struct v4l2_pix_format
*pf
= &f
->fmt
.pix
;
3360 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3362 data_format
= vino_find_data_format(pf
->pixelformat
);
3364 if (data_format
== VINO_DATA_FMT_NONE
) {
3365 vcs
->data_format
= VINO_DATA_FMT_GREY
;
3367 vino_data_formats
[vcs
->data_format
].
3370 vcs
->data_format
= data_format
;
3373 /* data format must be set before clipping/scaling */
3374 vino_set_scaling(vcs
, pf
->width
, pf
->height
);
3376 dprintk("data format = %s\n",
3377 vino_data_formats
[vcs
->data_format
].description
);
3379 pf
->width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3380 pf
->height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3382 pf
->field
= V4L2_FIELD_INTERLACED
;
3383 pf
->bytesperline
= vcs
->line_size
;
3384 pf
->sizeimage
= vcs
->line_size
*
3385 (vcs
->clipping
.bottom
- vcs
->clipping
.top
) /
3388 vino_data_formats
[vcs
->data_format
].colorspace
;
3392 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3395 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3403 static int vino_v4l2_cropcap(struct vino_channel_settings
*vcs
,
3404 struct v4l2_cropcap
*ccap
)
3406 const struct vino_data_norm
*norm
;
3407 unsigned long flags
;
3409 switch (ccap
->type
) {
3410 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3411 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3413 norm
= &vino_data_norms
[vcs
->data_norm
];
3415 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3417 ccap
->bounds
.left
= 0;
3418 ccap
->bounds
.top
= 0;
3419 ccap
->bounds
.width
= norm
->width
;
3420 ccap
->bounds
.height
= norm
->height
;
3421 memcpy(&ccap
->defrect
, &ccap
->bounds
,
3422 sizeof(struct v4l2_rect
));
3424 ccap
->pixelaspect
.numerator
= 1;
3425 ccap
->pixelaspect
.denominator
= 1;
3427 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3435 static int vino_v4l2_g_crop(struct vino_channel_settings
*vcs
,
3436 struct v4l2_crop
*c
)
3438 unsigned long flags
;
3441 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3442 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3444 c
->c
.left
= vcs
->clipping
.left
;
3445 c
->c
.top
= vcs
->clipping
.top
;
3446 c
->c
.width
= vcs
->clipping
.right
- vcs
->clipping
.left
;
3447 c
->c
.height
= vcs
->clipping
.bottom
- vcs
->clipping
.top
;
3449 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3451 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3459 static int vino_v4l2_s_crop(struct vino_channel_settings
*vcs
,
3460 struct v4l2_crop
*c
)
3462 unsigned long flags
;
3465 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
3466 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3468 vino_set_clipping(vcs
, c
->c
.left
, c
->c
.top
,
3469 c
->c
.width
, c
->c
.height
);
3471 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3473 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3481 static int vino_v4l2_g_parm(struct vino_channel_settings
*vcs
,
3482 struct v4l2_streamparm
*sp
)
3484 unsigned long flags
;
3487 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3488 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3489 memset(cp
, 0, sizeof(struct v4l2_captureparm
));
3491 cp
->capability
= V4L2_CAP_TIMEPERFRAME
;
3492 cp
->timeperframe
.numerator
= 1;
3494 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3496 cp
->timeperframe
.denominator
= vcs
->fps
;
3498 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3500 // TODO: cp->readbuffers = xxx;
3503 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3511 static int vino_v4l2_s_parm(struct vino_channel_settings
*vcs
,
3512 struct v4l2_streamparm
*sp
)
3514 unsigned long flags
;
3517 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3518 struct v4l2_captureparm
*cp
= &sp
->parm
.capture
;
3520 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3522 if ((cp
->timeperframe
.numerator
== 0) ||
3523 (cp
->timeperframe
.denominator
== 0)) {
3524 /* reset framerate */
3525 vino_set_default_framerate(vcs
);
3527 vino_set_framerate(vcs
, cp
->timeperframe
.denominator
/
3528 cp
->timeperframe
.numerator
);
3531 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3533 // TODO: set buffers according to cp->readbuffers
3536 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3544 static int vino_v4l2_reqbufs(struct vino_channel_settings
*vcs
,
3545 struct v4l2_requestbuffers
*rb
)
3551 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3552 // TODO: check queue type
3553 if (rb
->memory
!= V4L2_MEMORY_MMAP
) {
3554 dprintk("type not mmap\n");
3558 dprintk("count = %d\n", rb
->count
);
3559 if (rb
->count
> 0) {
3560 if (vino_is_capturing(vcs
)) {
3561 dprintk("busy, capturing\n");
3565 if (vino_queue_has_mapped_buffers(&vcs
->fb_queue
)) {
3566 dprintk("busy, buffers still mapped\n");
3570 vino_queue_free(&vcs
->fb_queue
);
3571 vino_queue_init(&vcs
->fb_queue
, &rb
->count
);
3575 vino_capture_stop(vcs
);
3576 vino_queue_free(&vcs
->fb_queue
);
3580 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3588 static void vino_v4l2_get_buffer_status(struct vino_channel_settings
*vcs
,
3589 struct vino_framebuffer
*fb
,
3590 struct v4l2_buffer
*b
)
3592 if (vino_queue_outgoing_contains(&vcs
->fb_queue
,
3594 b
->flags
&= ~V4L2_BUF_FLAG_QUEUED
;
3595 b
->flags
|= V4L2_BUF_FLAG_DONE
;
3596 } else if (vino_queue_incoming_contains(&vcs
->fb_queue
,
3598 b
->flags
&= ~V4L2_BUF_FLAG_DONE
;
3599 b
->flags
|= V4L2_BUF_FLAG_QUEUED
;
3601 b
->flags
&= ~(V4L2_BUF_FLAG_DONE
|
3602 V4L2_BUF_FLAG_QUEUED
);
3605 b
->flags
&= ~(V4L2_BUF_FLAG_TIMECODE
);
3607 if (fb
->map_count
> 0)
3608 b
->flags
|= V4L2_BUF_FLAG_MAPPED
;
3611 b
->memory
= (vcs
->fb_queue
.type
== VINO_MEMORY_MMAP
) ?
3612 V4L2_MEMORY_MMAP
: V4L2_MEMORY_USERPTR
;
3613 b
->m
.offset
= fb
->offset
;
3614 b
->bytesused
= fb
->data_size
;
3615 b
->length
= fb
->size
;
3616 b
->field
= V4L2_FIELD_INTERLACED
;
3617 b
->sequence
= fb
->frame_counter
;
3618 memcpy(&b
->timestamp
, &fb
->timestamp
,
3619 sizeof(struct timeval
));
3622 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3623 fb
->id
, fb
->size
, fb
->data_size
, fb
->offset
);
3626 static int vino_v4l2_querybuf(struct vino_channel_settings
*vcs
,
3627 struct v4l2_buffer
*b
)
3633 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3634 struct vino_framebuffer
*fb
;
3636 // TODO: check queue type
3637 if (b
->index
>= vino_queue_get_length(&vcs
->fb_queue
)) {
3638 dprintk("invalid index = %d\n",
3643 fb
= vino_queue_get_buffer(&vcs
->fb_queue
,
3646 dprintk("vino_queue_get_buffer() failed");
3650 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3653 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3661 static int vino_v4l2_qbuf(struct vino_channel_settings
*vcs
,
3662 struct v4l2_buffer
*b
)
3668 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3669 struct vino_framebuffer
*fb
;
3672 // TODO: check queue type
3673 if (b
->memory
!= V4L2_MEMORY_MMAP
) {
3674 dprintk("type not mmap\n");
3678 fb
= vino_capture_enqueue(vcs
, b
->index
);
3682 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3684 if (vcs
->streaming
) {
3685 ret
= vino_capture_next(vcs
, 1);
3691 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3699 static int vino_v4l2_dqbuf(struct vino_channel_settings
*vcs
,
3700 struct v4l2_buffer
*b
,
3701 unsigned int nonblocking
)
3707 case V4L2_BUF_TYPE_VIDEO_CAPTURE
: {
3708 struct vino_framebuffer
*fb
;
3709 unsigned int incoming
, outgoing
;
3712 // TODO: check queue type
3714 err
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3716 dprintk("vino_queue_get_incoming() failed\n");
3719 err
= vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
);
3721 dprintk("vino_queue_get_outgoing() failed\n");
3725 dprintk("incoming = %d, outgoing = %d\n", incoming
, outgoing
);
3727 if (outgoing
== 0) {
3728 if (incoming
== 0) {
3729 dprintk("no incoming or outgoing buffers\n");
3733 dprintk("non-blocking I/O was selected and "
3734 "there are no buffers to dequeue\n");
3738 err
= vino_wait_for_frame(vcs
);
3740 err
= vino_wait_for_frame(vcs
);
3743 * no frames captured because
3744 * of frame skipping */
3745 // vino_capture_failed(vcs);
3751 fb
= vino_queue_remove(&vcs
->fb_queue
, &b
->index
);
3753 dprintk("vino_queue_remove() failed\n");
3757 err
= vino_check_buffer(vcs
, fb
);
3759 vino_v4l2_get_buffer_status(vcs
, fb
, b
);
3766 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
3774 static int vino_v4l2_streamon(struct vino_channel_settings
*vcs
)
3776 unsigned int incoming
;
3784 // TODO: check queue type
3786 if (vino_queue_get_length(&vcs
->fb_queue
) < 1) {
3787 dprintk("no buffers allocated\n");
3791 ret
= vino_queue_get_incoming(&vcs
->fb_queue
, &incoming
);
3793 dprintk("vino_queue_get_incoming() failed\n");
3800 ret
= vino_capture_next(vcs
, 1);
3804 dprintk("couldn't start capture\n");
3812 static int vino_v4l2_streamoff(struct vino_channel_settings
*vcs
)
3817 if (!vcs
->streaming
)
3821 vino_capture_stop(vcs
);
3826 static int vino_v4l2_queryctrl(struct vino_channel_settings
*vcs
,
3827 struct v4l2_queryctrl
*queryctrl
)
3829 unsigned long flags
;
3833 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3835 switch (vcs
->input
) {
3837 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3838 if (vino_indycam_v4l2_controls
[i
].id
==
3841 &vino_indycam_v4l2_controls
[i
],
3842 sizeof(struct v4l2_queryctrl
));
3843 queryctrl
->reserved
[0] = 0;
3850 case VINO_INPUT_COMPOSITE
:
3851 case VINO_INPUT_SVIDEO
:
3852 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3853 if (vino_saa7191_v4l2_controls
[i
].id
==
3856 &vino_saa7191_v4l2_controls
[i
],
3857 sizeof(struct v4l2_queryctrl
));
3858 queryctrl
->reserved
[0] = 0;
3870 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3875 static int vino_v4l2_g_ctrl(struct vino_channel_settings
*vcs
,
3876 struct v4l2_control
*control
)
3878 unsigned long flags
;
3882 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3884 switch (vcs
->input
) {
3885 case VINO_INPUT_D1
: {
3886 struct indycam_control indycam_ctrl
;
3888 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3889 if (vino_indycam_v4l2_controls
[i
].id
==
3899 indycam_ctrl
.type
= vino_indycam_v4l2_controls
[i
].reserved
[0];
3901 err
= i2c_camera_command(DECODER_INDYCAM_GET_CONTROL
,
3908 control
->value
= indycam_ctrl
.value
;
3911 case VINO_INPUT_COMPOSITE
:
3912 case VINO_INPUT_SVIDEO
: {
3913 struct saa7191_control saa7191_ctrl
;
3915 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
3916 if (vino_saa7191_v4l2_controls
[i
].id
==
3926 saa7191_ctrl
.type
= vino_saa7191_v4l2_controls
[i
].reserved
[0];
3928 err
= i2c_decoder_command(DECODER_SAA7191_GET_CONTROL
,
3935 control
->value
= saa7191_ctrl
.value
;
3943 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
3948 static int vino_v4l2_s_ctrl(struct vino_channel_settings
*vcs
,
3949 struct v4l2_control
*control
)
3951 unsigned long flags
;
3955 spin_lock_irqsave(&vino_drvdata
->input_lock
, flags
);
3957 if (!vino_is_input_owner(vcs
)) {
3962 switch (vcs
->input
) {
3963 case VINO_INPUT_D1
: {
3964 struct indycam_control indycam_ctrl
;
3966 for (i
= 0; i
< VINO_INDYCAM_V4L2_CONTROL_COUNT
; i
++) {
3967 if (vino_indycam_v4l2_controls
[i
].id
==
3969 if ((control
->value
>=
3970 vino_indycam_v4l2_controls
[i
].minimum
)
3971 && (control
->value
<=
3972 vino_indycam_v4l2_controls
[i
].
3986 indycam_ctrl
.type
= vino_indycam_v4l2_controls
[i
].reserved
[0];
3987 indycam_ctrl
.value
= control
->value
;
3989 err
= i2c_camera_command(DECODER_INDYCAM_SET_CONTROL
,
3995 case VINO_INPUT_COMPOSITE
:
3996 case VINO_INPUT_SVIDEO
: {
3997 struct saa7191_control saa7191_ctrl
;
3999 for (i
= 0; i
< VINO_SAA7191_V4L2_CONTROL_COUNT
; i
++) {
4000 if (vino_saa7191_v4l2_controls
[i
].id
==
4002 if ((control
->value
>=
4003 vino_saa7191_v4l2_controls
[i
].minimum
)
4004 && (control
->value
<=
4005 vino_saa7191_v4l2_controls
[i
].
4018 saa7191_ctrl
.type
= vino_saa7191_v4l2_controls
[i
].reserved
[0];
4019 saa7191_ctrl
.value
= control
->value
;
4021 err
= i2c_decoder_command(DECODER_SAA7191_SET_CONTROL
,
4032 spin_unlock_irqrestore(&vino_drvdata
->input_lock
, flags
);
4037 /* File operations */
4039 static int vino_open(struct inode
*inode
, struct file
*file
)
4041 struct video_device
*dev
= video_devdata(file
);
4042 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4044 dprintk("open(): channel = %c\n",
4045 (vcs
->channel
== VINO_CHANNEL_A
) ? 'A' : 'B');
4047 mutex_lock(&vcs
->mutex
);
4050 dprintk("open(): driver busy\n");
4055 ret
= vino_acquire_input(vcs
);
4057 dprintk("open(): vino_acquire_input() failed\n");
4064 mutex_unlock(&vcs
->mutex
);
4066 dprintk("open(): %s!\n", ret
? "failed" : "complete");
4071 static int vino_close(struct inode
*inode
, struct file
*file
)
4073 struct video_device
*dev
= video_devdata(file
);
4074 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4075 dprintk("close():\n");
4077 mutex_lock(&vcs
->mutex
);
4082 vino_release_input(vcs
);
4084 /* stop DMA and free buffers */
4085 vino_capture_stop(vcs
);
4086 vino_queue_free(&vcs
->fb_queue
);
4089 mutex_unlock(&vcs
->mutex
);
4094 static void vino_vm_open(struct vm_area_struct
*vma
)
4096 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
4099 dprintk("vino_vm_open(): count = %d\n", fb
->map_count
);
4102 static void vino_vm_close(struct vm_area_struct
*vma
)
4104 struct vino_framebuffer
*fb
= vma
->vm_private_data
;
4107 dprintk("vino_vm_close(): count = %d\n", fb
->map_count
);
4110 static struct vm_operations_struct vino_vm_ops
= {
4111 .open
= vino_vm_open
,
4112 .close
= vino_vm_close
,
4115 static int vino_mmap(struct file
*file
, struct vm_area_struct
*vma
)
4117 struct video_device
*dev
= video_devdata(file
);
4118 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4120 unsigned long start
= vma
->vm_start
;
4121 unsigned long size
= vma
->vm_end
- vma
->vm_start
;
4122 unsigned long offset
= vma
->vm_pgoff
<< PAGE_SHIFT
;
4124 struct vino_framebuffer
*fb
= NULL
;
4125 unsigned int i
, length
;
4128 dprintk("mmap():\n");
4130 // TODO: reject mmap if already mapped
4132 if (mutex_lock_interruptible(&vcs
->mutex
))
4140 // TODO: check queue type
4142 if (!(vma
->vm_flags
& VM_WRITE
)) {
4143 dprintk("mmap(): app bug: PROT_WRITE please\n");
4147 if (!(vma
->vm_flags
& VM_SHARED
)) {
4148 dprintk("mmap(): app bug: MAP_SHARED please\n");
4153 /* find the correct buffer using offset */
4154 length
= vino_queue_get_length(&vcs
->fb_queue
);
4156 dprintk("mmap(): queue not initialized\n");
4161 for (i
= 0; i
< length
; i
++) {
4162 fb
= vino_queue_get_buffer(&vcs
->fb_queue
, i
);
4164 dprintk("mmap(): vino_queue_get_buffer() failed\n");
4169 if (fb
->offset
== offset
)
4173 dprintk("mmap(): invalid offset = %lu\n", offset
);
4178 dprintk("mmap(): buffer = %d\n", i
);
4180 if (size
> (fb
->desc_table
.page_count
* PAGE_SIZE
)) {
4181 dprintk("mmap(): failed: size = %lu > %lu\n",
4182 size
, fb
->desc_table
.page_count
* PAGE_SIZE
);
4187 for (i
= 0; i
< fb
->desc_table
.page_count
; i
++) {
4189 virt_to_phys((void *)fb
->desc_table
.virtual[i
]) >>
4192 if (size
< PAGE_SIZE
)
4195 // protection was: PAGE_READONLY
4196 if (remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
,
4197 vma
->vm_page_prot
)) {
4198 dprintk("mmap(): remap_pfn_range() failed\n");
4209 vma
->vm_flags
|= VM_DONTEXPAND
| VM_RESERVED
;
4210 vma
->vm_flags
&= ~VM_IO
;
4211 vma
->vm_private_data
= fb
;
4212 vma
->vm_file
= file
;
4213 vma
->vm_ops
= &vino_vm_ops
;
4216 mutex_unlock(&vcs
->mutex
);
4221 static unsigned int vino_poll(struct file
*file
, poll_table
*pt
)
4223 struct video_device
*dev
= video_devdata(file
);
4224 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4225 unsigned int outgoing
;
4226 unsigned int ret
= 0;
4229 // TODO: this has to be corrected for different read modes
4231 dprintk("poll():\n");
4233 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
4234 dprintk("poll(): vino_queue_get_outgoing() failed\n");
4241 poll_wait(file
, &vcs
->fb_queue
.frame_wait_queue
, pt
);
4243 if (vino_queue_get_outgoing(&vcs
->fb_queue
, &outgoing
)) {
4244 dprintk("poll(): vino_queue_get_outgoing() failed\n");
4250 dprintk("poll(): data %savailable\n",
4251 (outgoing
> 0) ? "" : "not ");
4254 ret
= POLLIN
| POLLRDNORM
;
4261 static int vino_do_ioctl(struct inode
*inode
, struct file
*file
,
4262 unsigned int cmd
, void *arg
)
4264 struct video_device
*dev
= video_devdata(file
);
4265 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4268 switch (_IOC_TYPE(cmd
)) {
4270 dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd
);
4273 dprintk("ioctl(): V4L2 %s (0x%08x)\n",
4274 v4l2_ioctl_names
[_IOC_NR(cmd
)], cmd
);
4277 dprintk("ioctl(): unsupported command 0x%08x\n", cmd
);
4282 /* V4L2 interface */
4283 case VIDIOC_QUERYCAP
: {
4284 vino_v4l2_querycap(arg
);
4287 case VIDIOC_ENUMINPUT
: {
4288 return vino_v4l2_enuminput(vcs
, arg
);
4290 case VIDIOC_G_INPUT
: {
4291 return vino_v4l2_g_input(vcs
, arg
);
4293 case VIDIOC_S_INPUT
: {
4294 return vino_v4l2_s_input(vcs
, arg
);
4296 case VIDIOC_ENUMSTD
: {
4297 return vino_v4l2_enumstd(vcs
, arg
);
4299 case VIDIOC_QUERYSTD
: {
4300 return vino_v4l2_querystd(vcs
, arg
);
4302 case VIDIOC_G_STD
: {
4303 return vino_v4l2_g_std(vcs
, arg
);
4305 case VIDIOC_S_STD
: {
4306 return vino_v4l2_s_std(vcs
, arg
);
4308 case VIDIOC_ENUM_FMT
: {
4309 return vino_v4l2_enum_fmt(vcs
, arg
);
4311 case VIDIOC_TRY_FMT
: {
4312 return vino_v4l2_try_fmt(vcs
, arg
);
4314 case VIDIOC_G_FMT
: {
4315 return vino_v4l2_g_fmt(vcs
, arg
);
4317 case VIDIOC_S_FMT
: {
4318 return vino_v4l2_s_fmt(vcs
, arg
);
4320 case VIDIOC_CROPCAP
: {
4321 return vino_v4l2_cropcap(vcs
, arg
);
4323 case VIDIOC_G_CROP
: {
4324 return vino_v4l2_g_crop(vcs
, arg
);
4326 case VIDIOC_S_CROP
: {
4327 return vino_v4l2_s_crop(vcs
, arg
);
4329 case VIDIOC_G_PARM
: {
4330 return vino_v4l2_g_parm(vcs
, arg
);
4332 case VIDIOC_S_PARM
: {
4333 return vino_v4l2_s_parm(vcs
, arg
);
4335 case VIDIOC_REQBUFS
: {
4336 return vino_v4l2_reqbufs(vcs
, arg
);
4338 case VIDIOC_QUERYBUF
: {
4339 return vino_v4l2_querybuf(vcs
, arg
);
4342 return vino_v4l2_qbuf(vcs
, arg
);
4344 case VIDIOC_DQBUF
: {
4345 return vino_v4l2_dqbuf(vcs
, arg
, file
->f_flags
& O_NONBLOCK
);
4347 case VIDIOC_STREAMON
: {
4348 return vino_v4l2_streamon(vcs
);
4350 case VIDIOC_STREAMOFF
: {
4351 return vino_v4l2_streamoff(vcs
);
4353 case VIDIOC_QUERYCTRL
: {
4354 return vino_v4l2_queryctrl(vcs
, arg
);
4356 case VIDIOC_G_CTRL
: {
4357 return vino_v4l2_g_ctrl(vcs
, arg
);
4359 case VIDIOC_S_CTRL
: {
4360 return vino_v4l2_s_ctrl(vcs
, arg
);
4363 return -ENOIOCTLCMD
;
4369 static int vino_ioctl(struct inode
*inode
, struct file
*file
,
4370 unsigned int cmd
, unsigned long arg
)
4372 struct video_device
*dev
= video_devdata(file
);
4373 struct vino_channel_settings
*vcs
= video_get_drvdata(dev
);
4376 if (mutex_lock_interruptible(&vcs
->mutex
))
4379 ret
= video_usercopy(inode
, file
, cmd
, arg
, vino_do_ioctl
);
4381 mutex_unlock(&vcs
->mutex
);
4386 /* Initialization and cleanup */
4389 static int vino_init_stage
= 0;
4391 static const struct file_operations vino_fops
= {
4392 .owner
= THIS_MODULE
,
4394 .release
= vino_close
,
4395 .ioctl
= vino_ioctl
,
4398 .llseek
= no_llseek
,
4401 static struct video_device v4l_device_template
= {
4403 //.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE |
4404 // VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY
4409 static void vino_module_cleanup(int stage
)
4413 video_unregister_device(vino_drvdata
->b
.v4l_device
);
4414 vino_drvdata
->b
.v4l_device
= NULL
;
4416 video_unregister_device(vino_drvdata
->a
.v4l_device
);
4417 vino_drvdata
->a
.v4l_device
= NULL
;
4421 free_irq(SGI_VINO_IRQ
, NULL
);
4423 if (vino_drvdata
->b
.v4l_device
) {
4424 video_device_release(vino_drvdata
->b
.v4l_device
);
4425 vino_drvdata
->b
.v4l_device
= NULL
;
4428 if (vino_drvdata
->a
.v4l_device
) {
4429 video_device_release(vino_drvdata
->a
.v4l_device
);
4430 vino_drvdata
->a
.v4l_device
= NULL
;
4433 /* all entries in dma_cpu dummy table have the same address */
4434 dma_unmap_single(NULL
,
4435 vino_drvdata
->dummy_desc_table
.dma_cpu
[0],
4436 PAGE_SIZE
, DMA_FROM_DEVICE
);
4437 dma_free_coherent(NULL
, VINO_DUMMY_DESC_COUNT
4438 * sizeof(dma_addr_t
),
4439 (void *)vino_drvdata
->
4440 dummy_desc_table
.dma_cpu
,
4441 vino_drvdata
->dummy_desc_table
.dma
);
4443 free_page(vino_drvdata
->dummy_page
);
4445 kfree(vino_drvdata
);
4451 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4456 static int vino_probe(void)
4458 unsigned long rev_id
;
4460 if (ip22_is_fullhouse()) {
4461 printk(KERN_ERR
"VINO doesn't exist in IP22 Fullhouse\n");
4465 if (!(sgimc
->systemid
& SGIMC_SYSID_EPRESENT
)) {
4466 printk(KERN_ERR
"VINO is not found (EISA BUS not present)\n");
4470 vino
= (struct sgi_vino
*)ioremap(VINO_BASE
, sizeof(struct sgi_vino
));
4472 printk(KERN_ERR
"VINO: ioremap() failed\n");
4477 if (get_dbe(rev_id
, &(vino
->rev_id
))) {
4478 printk(KERN_ERR
"Failed to read VINO revision register\n");
4479 vino_module_cleanup(vino_init_stage
);
4483 if (VINO_ID_VALUE(rev_id
) != VINO_CHIP_ID
) {
4484 printk(KERN_ERR
"Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4486 vino_module_cleanup(vino_init_stage
);
4490 printk(KERN_INFO
"VINO revision %ld found\n", VINO_REV_NUM(rev_id
));
4495 static int vino_init(void)
4497 dma_addr_t dma_dummy_address
;
4500 vino_drvdata
= kzalloc(sizeof(struct vino_settings
), GFP_KERNEL
);
4501 if (!vino_drvdata
) {
4502 vino_module_cleanup(vino_init_stage
);
4507 /* create a dummy dma descriptor */
4508 vino_drvdata
->dummy_page
= get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
4509 if (!vino_drvdata
->dummy_page
) {
4510 vino_module_cleanup(vino_init_stage
);
4515 // TODO: use page_count in dummy_desc_table
4517 vino_drvdata
->dummy_desc_table
.dma_cpu
=
4518 dma_alloc_coherent(NULL
,
4519 VINO_DUMMY_DESC_COUNT
* sizeof(dma_addr_t
),
4520 &vino_drvdata
->dummy_desc_table
.dma
,
4521 GFP_KERNEL
| GFP_DMA
);
4522 if (!vino_drvdata
->dummy_desc_table
.dma_cpu
) {
4523 vino_module_cleanup(vino_init_stage
);
4528 dma_dummy_address
= dma_map_single(NULL
,
4529 (void *)vino_drvdata
->dummy_page
,
4530 PAGE_SIZE
, DMA_FROM_DEVICE
);
4531 for (i
= 0; i
< VINO_DUMMY_DESC_COUNT
; i
++) {
4532 vino_drvdata
->dummy_desc_table
.dma_cpu
[i
] = dma_dummy_address
;
4535 /* initialize VINO */
4538 vino
->a
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4539 vino
->b
.next_4_desc
= vino_drvdata
->dummy_desc_table
.dma
;
4540 udelay(VINO_DESC_FETCH_DELAY
);
4542 vino
->intr_status
= 0;
4544 vino
->a
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4545 vino
->b
.fifo_thres
= VINO_FIFO_THRESHOLD_DEFAULT
;
4550 static int vino_init_channel_settings(struct vino_channel_settings
*vcs
,
4551 unsigned int channel
, const char *name
)
4553 vcs
->channel
= channel
;
4554 vcs
->input
= VINO_INPUT_NONE
;
4557 vcs
->data_format
= VINO_DATA_FMT_GREY
;
4558 vcs
->data_norm
= VINO_DATA_NORM_NTSC
;
4559 vcs
->decimation
= 1;
4560 vino_set_default_clipping(vcs
);
4561 vino_set_default_framerate(vcs
);
4565 mutex_init(&vcs
->mutex
);
4566 spin_lock_init(&vcs
->capture_lock
);
4568 mutex_init(&vcs
->fb_queue
.queue_mutex
);
4569 spin_lock_init(&vcs
->fb_queue
.queue_lock
);
4570 init_waitqueue_head(&vcs
->fb_queue
.frame_wait_queue
);
4572 vcs
->v4l_device
= video_device_alloc();
4573 if (!vcs
->v4l_device
) {
4574 vino_module_cleanup(vino_init_stage
);
4579 memcpy(vcs
->v4l_device
, &v4l_device_template
,
4580 sizeof(struct video_device
));
4581 strcpy(vcs
->v4l_device
->name
, name
);
4582 vcs
->v4l_device
->release
= video_device_release
;
4584 video_set_drvdata(vcs
->v4l_device
, vcs
);
4589 static int __init
vino_module_init(void)
4593 printk(KERN_INFO
"SGI VINO driver version %s\n",
4594 VINO_MODULE_VERSION
);
4604 /* initialize data structures */
4606 spin_lock_init(&vino_drvdata
->vino_lock
);
4607 spin_lock_init(&vino_drvdata
->input_lock
);
4609 ret
= vino_init_channel_settings(&vino_drvdata
->a
, VINO_CHANNEL_A
,
4610 vino_v4l_device_name_a
);
4614 ret
= vino_init_channel_settings(&vino_drvdata
->b
, VINO_CHANNEL_B
,
4615 vino_v4l_device_name_b
);
4619 /* initialize hardware and register V4L devices */
4621 ret
= request_irq(SGI_VINO_IRQ
, vino_interrupt
, 0,
4622 vino_driver_description
, NULL
);
4624 printk(KERN_ERR
"VINO: requesting IRQ %02d failed\n",
4626 vino_module_cleanup(vino_init_stage
);
4631 ret
= vino_i2c_add_bus();
4633 printk(KERN_ERR
"VINO I2C bus registration failed\n");
4634 vino_module_cleanup(vino_init_stage
);
4639 ret
= video_register_device(vino_drvdata
->a
.v4l_device
,
4640 VFL_TYPE_GRABBER
, -1);
4642 printk(KERN_ERR
"VINO channel A Video4Linux-device "
4643 "registration failed\n");
4644 vino_module_cleanup(vino_init_stage
);
4649 ret
= video_register_device(vino_drvdata
->b
.v4l_device
,
4650 VFL_TYPE_GRABBER
, -1);
4652 printk(KERN_ERR
"VINO channel B Video4Linux-device "
4653 "registration failed\n");
4654 vino_module_cleanup(vino_init_stage
);
4659 #if defined(CONFIG_KMOD) && defined(MODULE)
4660 request_module("saa7191");
4661 request_module("indycam");
4664 dprintk("init complete!\n");
4669 static void __exit
vino_module_exit(void)
4671 dprintk("exiting, stage = %d ...\n", vino_init_stage
);
4672 vino_module_cleanup(vino_init_stage
);
4673 dprintk("cleanup complete, exit!\n");
4676 module_init(vino_module_init
);
4677 module_exit(vino_module_exit
);