29 #include <linux/module.h>
32 #include <linux/errno.h>
35 #include <linux/kernel.h>
36 #include <linux/slab.h>
38 #include <linux/time.h>
41 #include <linux/i2c.h>
43 #include <linux/videodev2.h>
63 #define VINO_MODULE_VERSION "0.0.7"
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
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
128 #define VINO_MAX_FRAME_SKIP_COUNT 128
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
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
146 #define VINO_DATA_NORM_COUNT 4
149 #define SGI_I2C_FORCE_IDLE (0 << 0)
150 #define SGI_I2C_NOT_IDLE (1 << 0)
151 #define SGI_I2C_WRITE (0 << 1)
152 #define SGI_I2C_READ (1 << 1)
153 #define SGI_I2C_RELEASE_BUS (0 << 2)
154 #define SGI_I2C_HOLD_BUS (1 << 2)
155 #define SGI_I2C_XFER_DONE (0 << 4)
156 #define SGI_I2C_XFER_BUSY (1 << 4)
157 #define SGI_I2C_ACK (0 << 5)
158 #define SGI_I2C_NACK (1 << 5)
159 #define SGI_I2C_BUS_OK (0 << 7)
160 #define SGI_I2C_BUS_ERR (1 << 7)
200 unsigned long *
virtual;
345 static int vino_pixel_conversion;
350 "enable pixel conversion (non-zero value enables)");
358 #define camera_call(o, f, args...) \
359 v4l2_subdev_call(vino_drvdata->camera, o, f, ##args)
360 #define decoder_call(o, f, args...) \
361 v4l2_subdev_call(vino_drvdata->decoder, o, f, ##args)
363 static const char *vino_driver_name =
"vino";
364 static const char *vino_driver_description =
"SGI VINO";
365 static const char *vino_bus_name =
"GIO64 bus";
366 static const char *vino_vdev_name_a =
"SGI VINO Channel A";
367 static const char *vino_vdev_name_b =
"SGI VINO Channel B";
369 static void vino_capture_tasklet(
unsigned long channel);
374 static const struct vino_input vino_inputs[] = {
384 .name =
"D1/IndyCam",
391 .description =
"8-bit greyscale",
396 .description =
"8-bit dithered RGB 3-3-2",
401 .description =
"32-bit RGB",
406 .description =
"YUV 4:2:2",
415 .description =
"NTSC",
437 .description =
"PAL",
459 .description =
"SECAM",
481 .description =
"NTSC/D1",
505 #define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
511 .name =
"Automatic Gain Control",
519 .name =
"Automatic White Balance",
535 .name =
"Red Saturation",
543 .name =
"Blue Saturation",
551 .name =
"Red Balance",
559 .name =
"Blue Balance",
567 .name =
"Shutter Control",
583 #define VINO_SAA7191_V4L2_CONTROL_COUNT 9
597 .name =
"Luminance Bandpass",
605 .name =
"Luminance Bandpass Weight",
613 .name =
"HF Luminance Coring",
621 .name =
"Force Colour",
629 .name =
"Chrominance Gain Control",
637 .name =
"VTR Time Constant",
645 .name =
"Luminance Delay Compensation",
653 .name =
"Vertical Noise Reduction",
668 dprintk(
"vino_free_buffer_with_count(): count = %d\n", count);
670 for (i = 0; i <
count; i++) {
689 vino_free_buffer_with_count(fb, fb->
desc_table.page_count);
698 dprintk(
"vino_allocate_buffer():\n");
707 dprintk(
"vino_allocate_buffer(): size = %d, count = %d\n",
724 goto out_free_virtual;
729 for (i = 0; i <
count; i++) {
759 vino_free_buffer_with_count(fb, i);
785 dprintk(
"vino_prepare_user_buffer():\n");
794 dprintk(
"vino_prepare_user_buffer(): size = %d, count = %d\n",
811 goto out_free_virtual;
816 for (i = 0; i <
count; i++) {
846 vino_free_buffer_with_count(fb, i);
867 dprintk(
"vino_sync_buffer():\n");
869 for (i = 0; i < fb->
desc_table.page_count; i++)
898 if (f->
data[i] ==
id)
924 if (vino_fifo_has_id(f,
id)) {
974 for (i = 0; i <
length; i++) {
975 dprintk(
"vino_queue_free_with_count(): freeing buffer %d\n",
977 vino_free_buffer(q->
buffer[i]);
987 dprintk(
"vino_queue_free():\n");
996 vino_queue_free_with_count(q, q->
length);
1002 unsigned int *length)
1007 dprintk(
"vino_queue_init(): length = %d\n", *length);
1010 dprintk(
"vino_queue_init(): queue already initialized!\n");
1015 dprintk(
"vino_queue_init(): queue already initialized!\n");
1029 for (i = 0; i < *
length; i++) {
1030 dprintk(
"vino_queue_init(): allocating buffer %d\n", i);
1034 dprintk(
"vino_queue_init(): kmalloc() failed\n");
1039 ret = vino_allocate_buffer(q->
buffer[i],
1044 "vino_allocate_buffer() failed\n");
1058 dprintk(
"vino_queue_init(): buffer = %d, offset = %d, "
1059 "size = %d\n", i, q->
buffer[i]->offset,
1064 vino_queue_free_with_count(q, i);
1085 unsigned long flags;
1087 dprintk(
"vino_queue_add(): id = %d\n",
id);
1106 total = vino_fifo_get_used(&q->
in) +
1107 vino_fifo_get_used(&q->
out);
1111 if (vino_fifo_enqueue(&q->
in,
id))
1117 spin_unlock_irqrestore(&q->
queue_lock, flags);
1128 unsigned long flags;
1130 dprintk(
"vino_queue_transfer():\n");
1142 if (vino_fifo_dequeue(&q->
in, &
id)) {
1146 dprintk(
"vino_queue_transfer(): id = %d\n",
id);
1150 if (vino_fifo_enqueue(&q->
out,
id)) {
1152 "outgoing queue is full, this shouldn't happen!\n");
1158 spin_unlock_irqrestore(&q->
queue_lock, flags);
1168 unsigned long flags;
1179 ret = vino_fifo_has_id(&q->
in,
id);
1182 spin_unlock_irqrestore(&q->
queue_lock, flags);
1192 unsigned long flags;
1203 ret = vino_fifo_has_id(&q->
out,
id);
1206 spin_unlock_irqrestore(&q->
queue_lock, flags);
1215 unsigned long flags;
1228 *used = vino_fifo_get_used(&q->
in);
1231 spin_unlock_irqrestore(&q->
queue_lock, flags);
1240 unsigned long flags;
1253 *used = vino_fifo_get_used(&q->
out);
1256 spin_unlock_irqrestore(&q->
queue_lock, flags);
1263 unsigned int *total)
1266 unsigned long flags;
1279 *total = vino_fifo_get_used(&q->
in) +
1280 vino_fifo_get_used(&q->
out);
1283 spin_unlock_irqrestore(&q->
queue_lock, flags);
1294 unsigned long flags;
1305 if (vino_fifo_peek(&q->
in,
id)) {
1311 spin_unlock_irqrestore(&q->
queue_lock, flags);
1321 unsigned long flags;
1322 dprintk(
"vino_queue_remove():\n");
1333 if (vino_fifo_dequeue(&q->
out,
id)) {
1337 dprintk(
"vino_queue_remove(): id = %d\n", *
id);
1340 spin_unlock_irqrestore(&q->
queue_lock, flags);
1350 unsigned long flags;
1366 spin_unlock_irqrestore(&q->
queue_lock, flags);
1373 unsigned int length = 0;
1374 unsigned long flags;
1382 spin_unlock_irqrestore(&q->
queue_lock, flags);
1391 unsigned long flags;
1398 for (i = 0; i < q->
length; i++) {
1399 if (q->
buffer[i]->map_count > 0) {
1404 spin_unlock_irqrestore(&q->
queue_lock, flags);
1419 dprintk(
"update_line_size(): before: w = %d, d = %d, "
1420 "line_size = %d\n", w, d, vcs->
line_size);
1423 lsize = (bpp * (w /
d)) & ~7;
1424 w = (lsize /
bpp) * d;
1429 dprintk(
"update_line_size(): after: w = %d, d = %d, "
1430 "line_size = %d\n", w, d, vcs->
line_size);
1435 unsigned int x,
unsigned int y,
1436 unsigned int w,
unsigned int h)
1438 unsigned int maxwidth, maxheight;
1450 if (y > maxheight) {
1460 if ((x + w) > maxwidth) {
1465 if ((y + h) > maxheight) {
1476 vino_update_line_size(vcs);
1478 dprintk(
"clipping %d, %d, %d, %d / %d - %d\n",
1486 vino_set_clipping(vcs, 0, 0, vino_data_norms[vcs->
data_norm].
width,
1492 unsigned int w,
unsigned int h)
1494 unsigned int x,
y, curw, curh,
d;
1501 d =
max(curw / w, curh / h);
1503 dprintk(
"scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1504 w, h, curw, curh, d);
1513 vino_set_clipping(vcs, x, y, w * d, h * d);
1536 fps = (
unsigned int)(fps / 6) * 6;
1566 fps = (
unsigned int)(fps / 5) * 5;
1600 static inline void vino_set_default_framerate(
struct
1636 if (wait_xfer_done(adap))
1671 if (force_idle(adap))
1691 for (i = 0; i < len; i++) {
1692 if (wait_xfer_done(adap))
1708 for (i = 0; i < len; i++) {
1723 for (i = 0; !err && i < num; i++) {
1734 return (err < 0) ? err :
i;
1743 .master_xfer = sgi_xfer,
1744 .functionality = sgi_func,
1747 static unsigned i2c_vino_getctrl(
void *
data)
1752 static void i2c_vino_setctrl(
void *
data,
unsigned val)
1757 static unsigned i2c_vino_rdata(
void *
data)
1762 static void i2c_vino_wdata(
void *
data,
unsigned val)
1768 .getctrl = &i2c_vino_getctrl,
1769 .setctrl = &i2c_vino_setctrl,
1770 .rdata = &i2c_vino_rdata,
1771 .wdata = &i2c_vino_wdata,
1772 .xfer_timeout = 200,
1773 .ack_timeout = 1000,
1777 .name =
"VINO I2C bus",
1779 .algo_data = &i2c_sgi_vino_data,
1794 dprintk(
"vino_dma_setup():\n");
1800 norm = &vino_data_norms[vcs->
data_norm];
1816 dprintk(
"vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1935 dprintk(
"vino_dma_start():\n");
1951 dprintk(
"vino_dma_stop():\n");
1971 dprintk(
"channel %c clear interrupt condition\n",
1987 spin_unlock_irqrestore(&fb->
state_lock, flags);
1995 vino_dma_setup(vcs, fb);
1996 vino_dma_start(vcs);
1998 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags2);
1999 spin_unlock_irqrestore(&vino_drvdata->
vino_lock, flags);
2010 unsigned long flags;
2012 dprintk(
"vino_capture_enqueue():\n");
2016 fb = vino_queue_add(&vcs->
fb_queue, index);
2018 dprintk(
"vino_capture_enqueue(): vino_queue_add() failed, "
2031 unsigned int incoming,
id;
2033 unsigned long flags;
2035 dprintk(
"vino_capture_next():\n");
2055 err = vino_queue_get_incoming(&vcs->
fb_queue, &incoming);
2057 dprintk(
"vino_capture_next(): vino_queue_get_incoming() "
2062 if (incoming == 0) {
2063 dprintk(
"vino_capture_next(): no buffers available\n");
2067 fb = vino_queue_peek(&vcs->
fb_queue, &
id);
2069 dprintk(
"vino_capture_next(): vino_queue_peek() failed\n");
2080 err = vino_capture(vcs, fb);
2094 unsigned long flags;
2111 dprintk(
"vino_wait_for_frame():\n");
2113 init_waitqueue_entry(&wait,
current);
2126 dprintk(
"vino_wait_for_frame(): waiting for frame %s\n",
2127 err ?
"failed" :
"ok");
2134 unsigned char *pageptr;
2135 unsigned int page,
i;
2138 for (page = 0; page < fb->
desc_table.page_count; page++) {
2139 pageptr = (
unsigned char *)fb->
desc_table.virtual[page];
2143 pageptr[0] = pageptr[3];
2144 pageptr[1] = pageptr[2];
2145 pageptr[2] = pageptr[1];
2157 unsigned long flags;
2159 dprintk(
"vino_check_buffer():\n");
2162 switch (fb->
state) {
2167 vino_sync_buffer(fb);
2173 spin_unlock_irqrestore(&fb->
state_lock, flags);
2176 if (vino_pixel_conversion
2178 vino_convert_to_rgba(fb);
2180 }
else if (err && (err != -
EINVAL)) {
2181 dprintk(
"vino_check_buffer(): buffer not ready\n");
2185 vino_clear_interrupt(vcs);
2186 spin_unlock_irqrestore(&vino_drvdata->
vino_lock, flags);
2195 unsigned int incoming = 0, outgoing = 0,
id;
2198 dprintk(
"vino_capture_stop():\n");
2208 vino_clear_interrupt(vcs);
2210 spin_unlock_irqrestore(&vino_drvdata->
vino_lock, flags2);
2213 if (vino_queue_get_incoming(&vcs->
fb_queue, &incoming)) {
2214 dprintk(
"vino_capture_stop(): "
2215 "vino_queue_get_incoming() failed\n");
2218 while (incoming > 0) {
2219 vino_queue_transfer(&vcs->
fb_queue);
2221 if (vino_queue_get_incoming(&vcs->
fb_queue, &incoming)) {
2222 dprintk(
"vino_capture_stop(): "
2223 "vino_queue_get_incoming() failed\n");
2228 if (vino_queue_get_outgoing(&vcs->
fb_queue, &outgoing)) {
2229 dprintk(
"vino_capture_stop(): "
2230 "vino_queue_get_outgoing() failed\n");
2233 while (outgoing > 0) {
2234 vino_queue_remove(&vcs->
fb_queue, &
id);
2236 if (vino_queue_get_outgoing(&vcs->
fb_queue, &outgoing)) {
2237 dprintk(
"vino_capture_stop(): "
2238 "vino_queue_get_outgoing() failed\n");
2251 unsigned long flags;
2255 dprintk(
"vino_capture_failed():\n");
2260 vino_clear_interrupt(vcs);
2262 spin_unlock_irqrestore(&vino_drvdata->
vino_lock, flags);
2264 ret = vino_queue_get_incoming(&vcs->
fb_queue, &i);
2266 dprintk(
"vino_queue_get_incoming() failed\n");
2274 fb = vino_queue_peek(&vcs->
fb_queue, &i);
2276 dprintk(
"vino_queue_peek() failed\n");
2283 vino_queue_transfer(&vcs->
fb_queue);
2284 vino_queue_remove(&vcs->
fb_queue, &i);
2288 spin_unlock_irqrestore(&fb->
state_lock, flags);
2297 unsigned long flags;
2301 fb = vino_queue_peek(&vcs->
fb_queue, &
id);
2304 dprintk(
"vino_skip_frame(): vino_queue_peek() failed!\n");
2311 spin_unlock_irqrestore(&fb->
state_lock, flags);
2313 vino_capture_next(vcs, 0);
2319 unsigned long flags;
2322 fb = vino_queue_transfer(&vcs->
fb_queue);
2325 dprintk(
"vino_frame_done(): vino_queue_transfer() failed!\n");
2337 spin_unlock_irqrestore(&fb->
state_lock, flags);
2341 vino_capture_next(vcs, 0);
2344 static void vino_capture_tasklet(
unsigned long channel) {
2348 ? &vino_drvdata->
a : &vino_drvdata->
b;
2355 vino_skip_frame(vcs);
2358 vino_frame_done(vcs);
2365 unsigned int fc_a, fc_b;
2366 int handled_a = 0, skip_a = 0, done_a = 0;
2367 int handled_b = 0, skip_b = 0, done_b = 0;
2369 #ifdef VINO_DEBUG_INT
2371 unsigned int line_count = vino->
a.line_count,
2372 page_index = vino->
a.page_index,
2373 field_counter = vino->
a.field_counter,
2374 start_desc_tbl = vino->
a.start_desc_tbl,
2375 next_4_desc = vino->
a.next_4_desc;
2376 unsigned int line_count_2,
2386 fc_a = vino->
a.field_counter >> 1;
2387 fc_b = vino->
b.field_counter >> 1;
2393 vino_drvdata->
a.field++;
2394 if (vino_drvdata->
a.field > 1) {
2395 vino_dma_stop(&vino_drvdata->
a);
2396 vino_clear_interrupt(&vino_drvdata->
a);
2397 vino_drvdata->
a.field = 0;
2400 if (vino->
a.page_index
2401 != vino_drvdata->
a.line_size) {
2402 vino->
a.line_count = 0;
2403 vino->
a.page_index =
2406 vino->
a.next_4_desc =
2407 vino->
a.start_desc_tbl;
2410 dprintk(
"channel A end-of-field "
2411 "interrupt: %04x\n", intr);
2413 vino_dma_stop(&vino_drvdata->
a);
2414 vino_clear_interrupt(&vino_drvdata->
a);
2415 vino_drvdata->
a.field = 0;
2417 dprintk(
"channel A error interrupt: %04x\n",
2421 #ifdef VINO_DEBUG_INT
2422 line_count_2 = vino->
a.line_count;
2423 page_index_2 = vino->
a.page_index;
2424 field_counter_2 = vino->
a.field_counter;
2425 start_desc_tbl_2 = vino->
a.start_desc_tbl;
2426 next_4_desc_2 = vino->
a.next_4_desc;
2428 printk(
"intr = %04x, loop = %d, field = %d\n",
2429 intr, loop, vino_drvdata->
a.field);
2430 printk(
"1- line count = %04d, page index = %04d, "
2431 "start = %08x, next = %08x\n"
2432 " fieldc = %d, framec = %d\n",
2433 line_count, page_index, start_desc_tbl,
2434 next_4_desc, field_counter, fc_a);
2435 printk(
"12-line count = %04d, page index = %04d, "
2436 " start = %08x, next = %08x\n",
2437 line_count_2, page_index_2, start_desc_tbl_2,
2447 vino_drvdata->
b.field++;
2448 if (vino_drvdata->
b.field > 1) {
2449 vino_dma_stop(&vino_drvdata->
b);
2450 vino_clear_interrupt(&vino_drvdata->
b);
2451 vino_drvdata->
b.field = 0;
2454 dprintk(
"channel B end-of-field "
2455 "interrupt: %04x\n", intr);
2457 vino_dma_stop(&vino_drvdata->
b);
2458 vino_clear_interrupt(&vino_drvdata->
b);
2459 vino_drvdata->
b.field = 0;
2461 dprintk(
"channel B error interrupt: %04x\n",
2475 if ((!handled_a) && (done_a || skip_a)) {
2478 a.int_data.timestamp);
2479 vino_drvdata->
a.int_data.frame_counter = fc_a;
2481 vino_drvdata->
a.int_data.skip = skip_a;
2483 dprintk(
"channel A %s, interrupt: %d\n",
2484 skip_a ?
"skipping frame" :
"frame done",
2486 tasklet_hi_schedule(&vino_tasklet_a);
2490 if ((!handled_b) && (done_b || skip_b)) {
2493 b.int_data.timestamp);
2494 vino_drvdata->
b.int_data.frame_counter = fc_b;
2496 vino_drvdata->
b.int_data.skip = skip_b;
2498 dprintk(
"channel B %s, interrupt: %d\n",
2499 skip_b ?
"skipping frame" :
"frame done",
2501 tasklet_hi_schedule(&vino_tasklet_b);
2505 #ifdef VINO_DEBUG_INT
2518 static int vino_get_saa7191_input(
int input)
2527 "invalid input!\n");
2535 switch(vcs->
input) {
2548 unsigned long flags;
2551 dprintk(
"vino_acquire_input():\n");
2561 }
else if (vino_drvdata->
decoder
2570 vino_get_saa7191_input(input), 0, 0);
2576 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
2583 for (data_norm = 0; data_norm < 3; data_norm++) {
2584 if (vino_data_norms[data_norm].
std & norm)
2605 vino_drvdata->
b.input : vino_drvdata->
a.input;
2607 vino_drvdata->
b.data_norm : vino_drvdata->
a.data_norm;
2615 vino_set_default_clipping(vcs);
2616 vino_set_default_scaling(vcs);
2617 vino_set_default_framerate(vcs);
2622 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
2630 &vino_drvdata->
b : &vino_drvdata->
a;
2631 unsigned long flags;
2634 dprintk(
"vino_set_input():\n");
2638 if (vcs->
input == input)
2658 vino_get_saa7191_input(input), 0, 0);
2665 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
2672 for (data_norm = 0; data_norm < 3; data_norm++) {
2673 if (vino_data_norms[data_norm].
std & norm)
2692 if (input != vcs2->
input) {
2711 if (!vino_drvdata->
camera) {
2737 vino_set_default_clipping(vcs);
2738 vino_set_default_scaling(vcs);
2739 vino_set_default_framerate(vcs);
2744 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
2752 &vino_drvdata->
b : &vino_drvdata->
a;
2753 unsigned long flags;
2755 dprintk(
"vino_release_input():\n");
2778 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
2783 unsigned int data_norm,
2784 unsigned long *flags)
2791 switch (vcs->
input) {
2806 spin_unlock_irqrestore(&vino_drvdata->
input_lock, *flags);
2821 vino_set_default_clipping(vcs);
2822 vino_set_default_scaling(vcs);
2823 vino_set_default_framerate(vcs);
2841 if (vino_data_formats[i].pixelformat == pixelformat)
2851 unsigned long flags;
2866 }
else if (vino_drvdata->
decoder) {
2875 }
else if (vino_drvdata->
camera) {
2882 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
2894 switch (vcs->
input) {
2905 }
else if (vino_drvdata->
decoder) {
2906 switch (vcs->
input) {
2914 }
else if (vino_drvdata->
camera) {
2915 switch (vcs->
input) {
2927 static int vino_querycap(
struct file *
file,
void *__fh,
2942 static int vino_enum_input(
struct file *file,
void *__fh,
2948 dprintk(
"requested index = %d\n", index);
2950 input = vino_int_enum_input(vcs, index);
2963 static int vino_g_input(
struct file *file,
void *__fh,
2969 unsigned long flags;
2973 index = vino_find_input_index(vcs);
2974 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
2976 dprintk(
"input = %d\n", input);
2987 static int vino_s_input(
struct file *file,
void *__fh,
2992 dprintk(
"requested input = %d\n", i);
2994 input = vino_int_enum_input(vcs, i);
2998 return vino_set_input(vcs, input);
3001 static int vino_querystd(
struct file *file,
void *__fh,
3005 unsigned long flags;
3010 switch (vcs->
input) {
3012 *std = vino_inputs[vcs->
input].
std;
3023 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3028 static int vino_g_std(
struct file *file,
void *__fh,
3032 unsigned long flags;
3039 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3044 static int vino_s_std(
struct file *file,
void *__fh,
3048 unsigned long flags;
3053 if (!vino_is_input_owner(vcs)) {
3059 if ((*std) & vino_inputs[vcs->
input].
std) {
3060 dprintk(
"standard accepted\n");
3089 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3094 static int vino_enum_fmt_vid_cap(
struct file *file,
void *__fh,
3099 if (fd->
index >= VINO_DATA_FMT_COUNT)
3108 static int vino_try_fmt_vid_cap(
struct file *file,
void *__fh,
3113 unsigned long flags;
3116 dprintk(
"requested: w = %d, h = %d\n",
3121 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3123 tempvcs.data_format = vino_find_data_format(pf->
pixelformat);
3127 vino_data_formats[tempvcs.data_format].
3132 vino_set_scaling(&tempvcs, pf->
width, pf->
height);
3135 vino_data_formats[tempvcs.data_format].
description);
3137 pf->
width = (tempvcs.clipping.right - tempvcs.clipping.left) /
3139 pf->
height = (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3145 (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3148 vino_data_formats[tempvcs.data_format].
colorspace;
3154 static int vino_g_fmt_vid_cap(
struct file *file,
void *__fh,
3158 unsigned long flags;
3180 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3184 static int vino_s_fmt_vid_cap(
struct file *file,
void *__fh,
3189 unsigned long flags;
3194 data_format = vino_find_data_format(pf->
pixelformat);
3224 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3228 static int vino_cropcap(
struct file *file,
void *__fh,
3233 unsigned long flags;
3235 switch (ccap->
type) {
3239 norm = &vino_data_norms[vcs->
data_norm];
3241 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3261 static int vino_g_crop(
struct file *file,
void *__fh,
3265 unsigned long flags;
3276 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3286 static int vino_s_crop(
struct file *file,
void *__fh,
3290 unsigned long flags;
3296 vino_set_clipping(vcs, c->
c.left, c->
c.top,
3297 c->
c.width, c->
c.height);
3299 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3309 static int vino_g_parm(
struct file *file,
void *__fh,
3313 unsigned long flags;
3323 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3330 static int vino_s_parm(
struct file *file,
void *__fh,
3334 unsigned long flags;
3342 vino_set_default_framerate(vcs);
3348 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3353 static int vino_reqbufs(
struct file *file,
void *__fh,
3368 if (rb->
count > 0) {
3369 if (vino_is_capturing(vcs)) {
3374 if (vino_queue_has_mapped_buffers(&vcs->
fb_queue)) {
3375 dprintk(
"busy, buffers still mapped\n");
3384 vino_capture_stop(vcs);
3395 if (vino_queue_outgoing_contains(&vcs->
fb_queue,
3399 }
else if (vino_queue_incoming_contains(&vcs->
fb_queue,
3425 dprintk(
"buffer %d: length = %d, bytesused = %d, offset = %d\n",
3429 static int vino_querybuf(
struct file *file,
void *__fh,
3440 dprintk(
"invalid index = %d\n",
3445 fb = vino_queue_get_buffer(&vcs->
fb_queue,
3448 dprintk(
"vino_queue_get_buffer() failed");
3452 vino_v4l2_get_buffer_status(vcs, fb, b);
3457 static int vino_qbuf(
struct file *file,
void *__fh,
3473 fb = vino_capture_enqueue(vcs, b->
index);
3477 vino_v4l2_get_buffer_status(vcs, fb, b);
3480 ret = vino_capture_next(vcs, 1);
3488 static int vino_dqbuf(
struct file *file,
void *__fh,
3494 unsigned int incoming, outgoing;
3502 err = vino_queue_get_incoming(&vcs->
fb_queue, &incoming);
3504 dprintk(
"vino_queue_get_incoming() failed\n");
3507 err = vino_queue_get_outgoing(&vcs->
fb_queue, &outgoing);
3509 dprintk(
"vino_queue_get_outgoing() failed\n");
3513 dprintk(
"incoming = %d, outgoing = %d\n", incoming, outgoing);
3515 if (outgoing == 0) {
3516 if (incoming == 0) {
3517 dprintk(
"no incoming or outgoing buffers\n");
3521 dprintk(
"non-blocking I/O was selected and "
3522 "there are no buffers to dequeue\n");
3526 err = vino_wait_for_frame(vcs);
3528 err = vino_wait_for_frame(vcs);
3540 dprintk(
"vino_queue_remove() failed\n");
3544 err = vino_check_buffer(vcs, fb);
3546 vino_v4l2_get_buffer_status(vcs, fb, b);
3554 static int vino_streamon(
struct file *file,
void *__fh,
3558 unsigned int incoming;
3568 if (vino_queue_get_length(&vcs->
fb_queue) < 1) {
3569 dprintk(
"no buffers allocated\n");
3573 ret = vino_queue_get_incoming(&vcs->
fb_queue, &incoming);
3575 dprintk(
"vino_queue_get_incoming() failed\n");
3582 ret = vino_capture_next(vcs, 1);
3586 dprintk(
"couldn't start capture\n");
3594 static int vino_streamoff(
struct file *file,
void *__fh,
3605 vino_capture_stop(vcs);
3610 static int vino_queryctrl(
struct file *file,
void *__fh,
3614 unsigned long flags;
3620 switch (vcs->
input) {
3623 if (vino_indycam_v4l2_controls[i].
id ==
3626 &vino_indycam_v4l2_controls[i],
3638 if (vino_saa7191_v4l2_controls[i].
id ==
3641 &vino_saa7191_v4l2_controls[i],
3655 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3660 static int vino_g_ctrl(
struct file *file,
void *__fh,
3664 unsigned long flags;
3670 switch (vcs->
input) {
3674 if (vino_indycam_v4l2_controls[i].
id == control->
id) {
3692 if (vino_saa7191_v4l2_controls[i].
id == control->
id) {
3711 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3716 static int vino_s_ctrl(
struct file *file,
void *__fh,
3720 unsigned long flags;
3726 if (!vino_is_input_owner(vcs)) {
3731 switch (vcs->
input) {
3735 if (vino_indycam_v4l2_controls[i].
id == control->
id) {
3742 if (control->
value < vino_indycam_v4l2_controls[i].
minimum ||
3743 control->
value > vino_indycam_v4l2_controls[i].
maximum) {
3756 if (vino_saa7191_v4l2_controls[i].
id == control->
id) {
3763 if (control->
value < vino_saa7191_v4l2_controls[i].
minimum ||
3764 control->
value > vino_saa7191_v4l2_controls[i].
maximum) {
3779 spin_unlock_irqrestore(&vino_drvdata->
input_lock, flags);
3786 static int vino_open(
struct file *file)
3790 dprintk(
"open(): channel = %c\n",
3796 dprintk(
"open(): driver busy\n");
3801 ret = vino_acquire_input(vcs);
3803 dprintk(
"open(): vino_acquire_input() failed\n");
3812 dprintk(
"open(): %s!\n", ret ?
"failed" :
"complete");
3817 static int vino_close(
struct file *file)
3827 vino_release_input(vcs);
3830 vino_capture_stop(vcs);
3855 static const struct vm_operations_struct vino_vm_ops = {
3856 .open = vino_vm_open,
3857 .close = vino_vm_close,
3860 static int vino_mmap(
struct file *file,
struct vm_area_struct *vma)
3864 unsigned long start = vma->
vm_start;
3887 dprintk(
"mmap(): app bug: PROT_WRITE please\n");
3891 if (!(vma->
vm_flags & VM_SHARED)) {
3892 dprintk(
"mmap(): app bug: MAP_SHARED please\n");
3898 length = vino_queue_get_length(&vcs->
fb_queue);
3900 dprintk(
"mmap(): queue not initialized\n");
3905 for (i = 0; i <
length; i++) {
3906 fb = vino_queue_get_buffer(&vcs->
fb_queue, i);
3908 dprintk(
"mmap(): vino_queue_get_buffer() failed\n");
3913 if (fb->
offset == offset)
3917 dprintk(
"mmap(): invalid offset = %lu\n", offset);
3922 dprintk(
"mmap(): buffer = %d\n", i);
3925 dprintk(
"mmap(): failed: size = %lu > %lu\n",
3931 for (i = 0; i < fb->
desc_table.page_count; i++) {
3942 dprintk(
"mmap(): remap_pfn_range() failed\n");
3953 vma->
vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
3957 vma->
vm_ops = &vino_vm_ops;
3965 static unsigned int vino_poll(
struct file *file,
poll_table *pt)
3968 unsigned int outgoing;
3969 unsigned int ret = 0;
3976 if (vino_queue_get_outgoing(&vcs->
fb_queue, &outgoing)) {
3977 dprintk(
"poll(): vino_queue_get_outgoing() failed\n");
3984 poll_wait(file, &vcs->
fb_queue.frame_wait_queue, pt);
3986 if (vino_queue_get_outgoing(&vcs->
fb_queue, &outgoing)) {
3987 dprintk(
"poll(): vino_queue_get_outgoing() failed\n");
3993 dprintk(
"poll(): data %savailable\n",
3994 (outgoing > 0) ?
"" :
"not ");
4003 static long vino_ioctl(
struct file *file,
4004 unsigned int cmd,
unsigned long arg)
4022 static int vino_init_stage;
4025 .vidioc_enum_fmt_vid_cap = vino_enum_fmt_vid_cap,
4026 .vidioc_g_fmt_vid_cap = vino_g_fmt_vid_cap,
4027 .vidioc_s_fmt_vid_cap = vino_s_fmt_vid_cap,
4028 .vidioc_try_fmt_vid_cap = vino_try_fmt_vid_cap,
4029 .vidioc_querycap = vino_querycap,
4030 .vidioc_enum_input = vino_enum_input,
4031 .vidioc_g_input = vino_g_input,
4032 .vidioc_s_input = vino_s_input,
4033 .vidioc_g_std = vino_g_std,
4034 .vidioc_s_std = vino_s_std,
4035 .vidioc_querystd = vino_querystd,
4036 .vidioc_cropcap = vino_cropcap,
4037 .vidioc_s_crop = vino_s_crop,
4038 .vidioc_g_crop = vino_g_crop,
4039 .vidioc_s_parm = vino_s_parm,
4040 .vidioc_g_parm = vino_g_parm,
4041 .vidioc_reqbufs = vino_reqbufs,
4042 .vidioc_querybuf = vino_querybuf,
4043 .vidioc_qbuf = vino_qbuf,
4044 .vidioc_dqbuf = vino_dqbuf,
4045 .vidioc_streamon = vino_streamon,
4046 .vidioc_streamoff = vino_streamoff,
4047 .vidioc_queryctrl = vino_queryctrl,
4048 .vidioc_g_ctrl = vino_g_ctrl,
4049 .vidioc_s_ctrl = vino_s_ctrl,
4055 .release = vino_close,
4056 .unlocked_ioctl = vino_ioctl,
4068 static void vino_module_cleanup(
int stage)
4073 vino_drvdata->
b.vdev =
NULL;
4076 vino_drvdata->
a.vdev =
NULL;
4082 if (vino_drvdata->
b.vdev) {
4084 vino_drvdata->
b.vdev =
NULL;
4087 if (vino_drvdata->
a.vdev) {
4089 vino_drvdata->
a.vdev =
NULL;
4098 (
void *)vino_drvdata->
4099 dummy_desc_table.dma_cpu,
4106 kfree(vino_drvdata);
4112 dprintk(
"vino_module_cleanup(): invalid cleanup stage = %d\n",
4117 static int vino_probe(
void)
4119 unsigned long rev_id;
4140 vino_module_cleanup(vino_init_stage);
4147 vino_module_cleanup(vino_init_stage);
4156 static int vino_init(
void)
4163 if (!vino_drvdata) {
4164 vino_module_cleanup(vino_init_stage);
4169 sizeof(vino_drvdata->
v4l2_dev.name));
4178 vino_module_cleanup(vino_init_stage);
4191 vino_module_cleanup(vino_init_stage);
4219 unsigned int channel,
const char *
name)
4228 vino_set_default_clipping(vcs);
4229 vino_set_default_framerate(vcs);
4242 vino_module_cleanup(vino_init_stage);
4253 video_set_drvdata(vcs->
vdev, vcs);
4258 static int __init vino_module_init(
void)
4291 vino_driver_description,
NULL);
4295 vino_module_cleanup(vino_init_stage);
4303 vino_module_cleanup(vino_init_stage);
4306 i2c_set_adapdata(&vino_i2c_adapter, &vino_drvdata->
v4l2_dev);
4309 ret = video_register_device(vino_drvdata->
a.vdev,
4313 "registration failed\n");
4314 vino_module_cleanup(vino_init_stage);
4319 ret = video_register_device(vino_drvdata->
b.vdev,
4323 "registration failed\n");
4324 vino_module_cleanup(vino_init_stage);
4341 static void __exit vino_module_exit(
void)
4343 dprintk(
"exiting, stage = %d ...\n", vino_init_stage);
4344 vino_module_cleanup(vino_init_stage);
4345 dprintk(
"cleanup complete, exit!\n");