Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Virtual Video driver - This code emulates a real video device with v4l2 api |
| 3 | * |
| 4 | * Copyright (c) 2006 by: |
| 5 | * Mauro Carvalho Chehab <mchehab--a.t--infradead.org> |
| 6 | * Ted Walther <ted--a.t--enumera.com> |
| 7 | * John Sokol <sokol--a.t--videotechnology.com> |
| 8 | * http://v4l.videotechnology.com/ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the BSD Licence, GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version 2 of the |
| 13 | * License, or (at your option) any later version |
| 14 | */ |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/ioport.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/random.h> |
| 27 | #include <linux/version.h> |
Matthias Kaehlcke | 51b5402 | 2007-07-02 10:19:38 -0300 | [diff] [blame] | 28 | #include <linux/mutex.h> |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 29 | #include <linux/videodev2.h> |
Andrew Morton | 1095136 | 2006-04-27 10:10:58 -0300 | [diff] [blame] | 30 | #include <linux/dma-mapping.h> |
Michael Krufky | f13df91 | 2006-03-23 22:01:44 -0300 | [diff] [blame] | 31 | #include <linux/interrupt.h> |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 32 | #include <linux/kthread.h> |
| 33 | #include <linux/highmem.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 34 | #include <linux/freezer.h> |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 35 | #include <media/videobuf-vmalloc.h> |
| 36 | #include <media/v4l2-device.h> |
| 37 | #include <media/v4l2-ioctl.h> |
| 38 | #include "font.h" |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 39 | |
Mauro Carvalho Chehab | 584ce48 | 2008-06-10 15:21:49 -0300 | [diff] [blame] | 40 | #define VIVI_MODULE_NAME "vivi" |
Carl Karsten | 745271a | 2008-06-10 00:02:32 -0300 | [diff] [blame] | 41 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 42 | /* Wake up at about 30 fps */ |
| 43 | #define WAKE_NUMERATOR 30 |
| 44 | #define WAKE_DENOMINATOR 1001 |
| 45 | #define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */ |
| 46 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 47 | #define VIVI_MAJOR_VERSION 0 |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 48 | #define VIVI_MINOR_VERSION 6 |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 49 | #define VIVI_RELEASE 0 |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 50 | #define VIVI_VERSION \ |
| 51 | KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 52 | |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 53 | MODULE_DESCRIPTION("Video Technology Magazine Virtual Video Capture Board"); |
| 54 | MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol"); |
| 55 | MODULE_LICENSE("Dual BSD/GPL"); |
| 56 | |
| 57 | static unsigned video_nr = -1; |
| 58 | module_param(video_nr, uint, 0644); |
| 59 | MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect"); |
| 60 | |
| 61 | static unsigned n_devs = 1; |
| 62 | module_param(n_devs, uint, 0644); |
| 63 | MODULE_PARM_DESC(n_devs, "number of video devices to create"); |
| 64 | |
| 65 | static unsigned debug; |
| 66 | module_param(debug, uint, 0644); |
| 67 | MODULE_PARM_DESC(debug, "activates debug info"); |
| 68 | |
| 69 | static unsigned int vid_limit = 16; |
| 70 | module_param(vid_limit, uint, 0644); |
| 71 | MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes"); |
| 72 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 73 | |
| 74 | /* supported controls */ |
| 75 | static struct v4l2_queryctrl vivi_qctrl[] = { |
| 76 | { |
| 77 | .id = V4L2_CID_AUDIO_VOLUME, |
| 78 | .name = "Volume", |
| 79 | .minimum = 0, |
| 80 | .maximum = 65535, |
| 81 | .step = 65535/100, |
| 82 | .default_value = 65535, |
Hans Verkuil | 4a5aa62 | 2009-02-14 13:50:19 -0300 | [diff] [blame] | 83 | .flags = V4L2_CTRL_FLAG_SLIDER, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 84 | .type = V4L2_CTRL_TYPE_INTEGER, |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 85 | }, { |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 86 | .id = V4L2_CID_BRIGHTNESS, |
| 87 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 88 | .name = "Brightness", |
| 89 | .minimum = 0, |
| 90 | .maximum = 255, |
| 91 | .step = 1, |
| 92 | .default_value = 127, |
Hans Verkuil | 4a5aa62 | 2009-02-14 13:50:19 -0300 | [diff] [blame] | 93 | .flags = V4L2_CTRL_FLAG_SLIDER, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 94 | }, { |
| 95 | .id = V4L2_CID_CONTRAST, |
| 96 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 97 | .name = "Contrast", |
| 98 | .minimum = 0, |
| 99 | .maximum = 255, |
| 100 | .step = 0x1, |
| 101 | .default_value = 0x10, |
Hans Verkuil | 4a5aa62 | 2009-02-14 13:50:19 -0300 | [diff] [blame] | 102 | .flags = V4L2_CTRL_FLAG_SLIDER, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 103 | }, { |
| 104 | .id = V4L2_CID_SATURATION, |
| 105 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 106 | .name = "Saturation", |
| 107 | .minimum = 0, |
| 108 | .maximum = 255, |
| 109 | .step = 0x1, |
| 110 | .default_value = 127, |
Hans Verkuil | 4a5aa62 | 2009-02-14 13:50:19 -0300 | [diff] [blame] | 111 | .flags = V4L2_CTRL_FLAG_SLIDER, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 112 | }, { |
| 113 | .id = V4L2_CID_HUE, |
| 114 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 115 | .name = "Hue", |
| 116 | .minimum = -128, |
| 117 | .maximum = 127, |
| 118 | .step = 0x1, |
| 119 | .default_value = 0, |
Hans Verkuil | 4a5aa62 | 2009-02-14 13:50:19 -0300 | [diff] [blame] | 120 | .flags = V4L2_CTRL_FLAG_SLIDER, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 121 | } |
| 122 | }; |
| 123 | |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 124 | #define dprintk(dev, level, fmt, arg...) \ |
| 125 | v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 126 | |
| 127 | /* ------------------------------------------------------------------ |
| 128 | Basic structures |
| 129 | ------------------------------------------------------------------*/ |
| 130 | |
| 131 | struct vivi_fmt { |
| 132 | char *name; |
| 133 | u32 fourcc; /* v4l2 format id */ |
| 134 | int depth; |
| 135 | }; |
| 136 | |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 137 | static struct vivi_fmt formats[] = { |
| 138 | { |
| 139 | .name = "4:2:2, packed, YUYV", |
| 140 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 141 | .depth = 16, |
| 142 | }, |
Magnus Damm | fca36ba | 2008-10-14 12:47:25 -0300 | [diff] [blame] | 143 | { |
| 144 | .name = "4:2:2, packed, UYVY", |
| 145 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 146 | .depth = 16, |
| 147 | }, |
Magnus Damm | aeadb5d | 2008-10-14 12:47:35 -0300 | [diff] [blame] | 148 | { |
| 149 | .name = "RGB565 (LE)", |
| 150 | .fourcc = V4L2_PIX_FMT_RGB565, /* gggbbbbb rrrrrggg */ |
| 151 | .depth = 16, |
| 152 | }, |
| 153 | { |
| 154 | .name = "RGB565 (BE)", |
| 155 | .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */ |
| 156 | .depth = 16, |
| 157 | }, |
Magnus Damm | def5239 | 2008-10-14 12:47:43 -0300 | [diff] [blame] | 158 | { |
| 159 | .name = "RGB555 (LE)", |
| 160 | .fourcc = V4L2_PIX_FMT_RGB555, /* gggbbbbb arrrrrgg */ |
| 161 | .depth = 16, |
| 162 | }, |
| 163 | { |
| 164 | .name = "RGB555 (BE)", |
| 165 | .fourcc = V4L2_PIX_FMT_RGB555X, /* arrrrrgg gggbbbbb */ |
| 166 | .depth = 16, |
| 167 | }, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 168 | }; |
| 169 | |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 170 | static struct vivi_fmt *get_format(struct v4l2_format *f) |
| 171 | { |
| 172 | struct vivi_fmt *fmt; |
| 173 | unsigned int k; |
| 174 | |
| 175 | for (k = 0; k < ARRAY_SIZE(formats); k++) { |
| 176 | fmt = &formats[k]; |
| 177 | if (fmt->fourcc == f->fmt.pix.pixelformat) |
| 178 | break; |
| 179 | } |
| 180 | |
| 181 | if (k == ARRAY_SIZE(formats)) |
| 182 | return NULL; |
| 183 | |
| 184 | return &formats[k]; |
| 185 | } |
| 186 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 187 | struct sg_to_addr { |
| 188 | int pos; |
| 189 | struct scatterlist *sg; |
| 190 | }; |
| 191 | |
| 192 | /* buffer for one video frame */ |
| 193 | struct vivi_buffer { |
| 194 | /* common v4l buffer stuff -- must be first */ |
| 195 | struct videobuf_buffer vb; |
| 196 | |
| 197 | struct vivi_fmt *fmt; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | struct vivi_dmaqueue { |
| 201 | struct list_head active; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 202 | |
| 203 | /* thread for generating video stream*/ |
| 204 | struct task_struct *kthread; |
| 205 | wait_queue_head_t wq; |
| 206 | /* Counters to control fps rate */ |
| 207 | int frame; |
| 208 | int ini_jiffies; |
| 209 | }; |
| 210 | |
| 211 | static LIST_HEAD(vivi_devlist); |
| 212 | |
| 213 | struct vivi_dev { |
| 214 | struct list_head vivi_devlist; |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 215 | struct v4l2_device v4l2_dev; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 216 | |
Mauro Carvalho Chehab | 55862ac | 2007-12-13 16:13:37 -0300 | [diff] [blame] | 217 | spinlock_t slock; |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 218 | struct mutex mutex; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 219 | |
| 220 | int users; |
| 221 | |
| 222 | /* various device info */ |
Mauro Carvalho Chehab | f905c44 | 2007-12-10 04:07:03 -0300 | [diff] [blame] | 223 | struct video_device *vfd; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 224 | |
| 225 | struct vivi_dmaqueue vidq; |
| 226 | |
| 227 | /* Several counters */ |
Mauro Carvalho Chehab | dfd8c04 | 2008-01-13 19:36:11 -0300 | [diff] [blame] | 228 | int h, m, s, ms; |
| 229 | unsigned long jiffies; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 230 | char timestr[13]; |
Mauro Carvalho Chehab | 025341d | 2007-12-10 04:43:38 -0300 | [diff] [blame] | 231 | |
| 232 | int mv_count; /* Controls bars movement */ |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 233 | |
| 234 | /* Input Number */ |
| 235 | int input; |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 236 | |
| 237 | /* Control 'registers' */ |
| 238 | int qctl_regs[ARRAY_SIZE(vivi_qctrl)]; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | struct vivi_fh { |
| 242 | struct vivi_dev *dev; |
| 243 | |
| 244 | /* video capture */ |
| 245 | struct vivi_fmt *fmt; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 246 | unsigned int width, height; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 247 | struct videobuf_queue vb_vidq; |
| 248 | |
| 249 | enum v4l2_buf_type type; |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 250 | unsigned char bars[8][3]; |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 251 | int input; /* Input Number on bars */ |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | /* ------------------------------------------------------------------ |
| 255 | DMA and thread functions |
| 256 | ------------------------------------------------------------------*/ |
| 257 | |
| 258 | /* Bars and Colors should match positions */ |
| 259 | |
| 260 | enum colors { |
| 261 | WHITE, |
| 262 | AMBAR, |
| 263 | CYAN, |
| 264 | GREEN, |
| 265 | MAGENTA, |
| 266 | RED, |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 267 | BLUE, |
| 268 | BLACK, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 269 | }; |
| 270 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 271 | /* R G B */ |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 272 | #define COLOR_WHITE {204, 204, 204} |
| 273 | #define COLOR_AMBAR {208, 208, 0} |
| 274 | #define COLOR_CIAN { 0, 206, 206} |
| 275 | #define COLOR_GREEN { 0, 239, 0} |
| 276 | #define COLOR_MAGENTA {239, 0, 239} |
| 277 | #define COLOR_RED {205, 0, 0} |
| 278 | #define COLOR_BLUE { 0, 0, 255} |
| 279 | #define COLOR_BLACK { 0, 0, 0} |
| 280 | |
| 281 | struct bar_std { |
| 282 | u8 bar[8][3]; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 283 | }; |
| 284 | |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 285 | /* Maximum number of bars are 10 - otherwise, the input print code |
| 286 | should be modified */ |
| 287 | static struct bar_std bars[] = { |
| 288 | { /* Standard ITU-R color bar sequence */ |
| 289 | { |
| 290 | COLOR_WHITE, |
| 291 | COLOR_AMBAR, |
| 292 | COLOR_CIAN, |
| 293 | COLOR_GREEN, |
| 294 | COLOR_MAGENTA, |
| 295 | COLOR_RED, |
| 296 | COLOR_BLUE, |
| 297 | COLOR_BLACK, |
| 298 | } |
| 299 | }, { |
| 300 | { |
| 301 | COLOR_WHITE, |
| 302 | COLOR_AMBAR, |
| 303 | COLOR_BLACK, |
| 304 | COLOR_WHITE, |
| 305 | COLOR_AMBAR, |
| 306 | COLOR_BLACK, |
| 307 | COLOR_WHITE, |
| 308 | COLOR_AMBAR, |
| 309 | } |
| 310 | }, { |
| 311 | { |
| 312 | COLOR_WHITE, |
| 313 | COLOR_CIAN, |
| 314 | COLOR_BLACK, |
| 315 | COLOR_WHITE, |
| 316 | COLOR_CIAN, |
| 317 | COLOR_BLACK, |
| 318 | COLOR_WHITE, |
| 319 | COLOR_CIAN, |
| 320 | } |
| 321 | }, { |
| 322 | { |
| 323 | COLOR_WHITE, |
| 324 | COLOR_GREEN, |
| 325 | COLOR_BLACK, |
| 326 | COLOR_WHITE, |
| 327 | COLOR_GREEN, |
| 328 | COLOR_BLACK, |
| 329 | COLOR_WHITE, |
| 330 | COLOR_GREEN, |
| 331 | } |
| 332 | }, |
| 333 | }; |
| 334 | |
| 335 | #define NUM_INPUTS ARRAY_SIZE(bars) |
| 336 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 337 | #define TO_Y(r, g, b) \ |
| 338 | (((16829 * r + 33039 * g + 6416 * b + 32768) >> 16) + 16) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 339 | /* RGB to V(Cr) Color transform */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 340 | #define TO_V(r, g, b) \ |
| 341 | (((28784 * r - 24103 * g - 4681 * b + 32768) >> 16) + 128) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 342 | /* RGB to U(Cb) Color transform */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 343 | #define TO_U(r, g, b) \ |
| 344 | (((-9714 * r - 19070 * g + 28784 * b + 32768) >> 16) + 128) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 345 | |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 346 | #define TSTAMP_MIN_Y 24 |
| 347 | #define TSTAMP_MAX_Y (TSTAMP_MIN_Y + 15) |
| 348 | #define TSTAMP_INPUT_X 10 |
| 349 | #define TSTAMP_MIN_X (54 + TSTAMP_INPUT_X) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 350 | |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 351 | static void gen_twopix(struct vivi_fh *fh, unsigned char *buf, int colorpos) |
| 352 | { |
| 353 | unsigned char r_y, g_u, b_v; |
| 354 | unsigned char *p; |
| 355 | int color; |
| 356 | |
| 357 | r_y = fh->bars[colorpos][0]; /* R or precalculated Y */ |
| 358 | g_u = fh->bars[colorpos][1]; /* G or precalculated U */ |
| 359 | b_v = fh->bars[colorpos][2]; /* B or precalculated V */ |
| 360 | |
| 361 | for (color = 0; color < 4; color++) { |
| 362 | p = buf + color; |
| 363 | |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 364 | switch (fh->fmt->fourcc) { |
| 365 | case V4L2_PIX_FMT_YUYV: |
| 366 | switch (color) { |
| 367 | case 0: |
| 368 | case 2: |
| 369 | *p = r_y; |
| 370 | break; |
| 371 | case 1: |
| 372 | *p = g_u; |
| 373 | break; |
| 374 | case 3: |
| 375 | *p = b_v; |
| 376 | break; |
| 377 | } |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 378 | break; |
Magnus Damm | fca36ba | 2008-10-14 12:47:25 -0300 | [diff] [blame] | 379 | case V4L2_PIX_FMT_UYVY: |
| 380 | switch (color) { |
| 381 | case 1: |
| 382 | case 3: |
| 383 | *p = r_y; |
| 384 | break; |
| 385 | case 0: |
| 386 | *p = g_u; |
| 387 | break; |
| 388 | case 2: |
| 389 | *p = b_v; |
| 390 | break; |
| 391 | } |
| 392 | break; |
Magnus Damm | aeadb5d | 2008-10-14 12:47:35 -0300 | [diff] [blame] | 393 | case V4L2_PIX_FMT_RGB565: |
| 394 | switch (color) { |
| 395 | case 0: |
| 396 | case 2: |
| 397 | *p = (g_u << 5) | b_v; |
| 398 | break; |
| 399 | case 1: |
| 400 | case 3: |
| 401 | *p = (r_y << 3) | (g_u >> 3); |
| 402 | break; |
| 403 | } |
| 404 | break; |
| 405 | case V4L2_PIX_FMT_RGB565X: |
| 406 | switch (color) { |
| 407 | case 0: |
| 408 | case 2: |
| 409 | *p = (r_y << 3) | (g_u >> 3); |
| 410 | break; |
| 411 | case 1: |
| 412 | case 3: |
| 413 | *p = (g_u << 5) | b_v; |
| 414 | break; |
| 415 | } |
| 416 | break; |
Magnus Damm | def5239 | 2008-10-14 12:47:43 -0300 | [diff] [blame] | 417 | case V4L2_PIX_FMT_RGB555: |
| 418 | switch (color) { |
| 419 | case 0: |
| 420 | case 2: |
| 421 | *p = (g_u << 5) | b_v; |
| 422 | break; |
| 423 | case 1: |
| 424 | case 3: |
| 425 | *p = (r_y << 2) | (g_u >> 3); |
| 426 | break; |
| 427 | } |
| 428 | break; |
| 429 | case V4L2_PIX_FMT_RGB555X: |
| 430 | switch (color) { |
| 431 | case 0: |
| 432 | case 2: |
| 433 | *p = (r_y << 2) | (g_u >> 3); |
| 434 | break; |
| 435 | case 1: |
| 436 | case 3: |
| 437 | *p = (g_u << 5) | b_v; |
| 438 | break; |
| 439 | } |
| 440 | break; |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | static void gen_line(struct vivi_fh *fh, char *basep, int inipos, int wmax, |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 446 | int hmax, int line, int count, char *timestr) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 447 | { |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 448 | int w, i, j; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 449 | int pos = inipos; |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 450 | char *s; |
| 451 | u8 chr; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 452 | |
| 453 | /* We will just duplicate the second pixel at the packet */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 454 | wmax /= 2; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 455 | |
| 456 | /* Generate a standard color bar pattern */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 457 | for (w = 0; w < wmax; w++) { |
| 458 | int colorpos = ((w + count) * 8/(wmax + 1)) % 8; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 459 | |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 460 | gen_twopix(fh, basep + pos, colorpos); |
| 461 | pos += 4; /* only 16 bpp supported for now */ |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 462 | } |
| 463 | |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 464 | /* Prints input entry number */ |
| 465 | |
| 466 | /* Checks if it is possible to input number */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 467 | if (TSTAMP_MAX_Y >= hmax) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 468 | goto end; |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 469 | |
| 470 | if (TSTAMP_INPUT_X + strlen(timestr) >= wmax) |
| 471 | goto end; |
| 472 | |
| 473 | if (line >= TSTAMP_MIN_Y && line <= TSTAMP_MAX_Y) { |
| 474 | chr = rom8x16_bits[fh->input * 16 + line - TSTAMP_MIN_Y]; |
| 475 | pos = TSTAMP_INPUT_X; |
| 476 | for (i = 0; i < 7; i++) { |
| 477 | /* Draw white font on black background */ |
| 478 | if (chr & 1 << (7 - i)) |
| 479 | gen_twopix(fh, basep + pos, WHITE); |
| 480 | else |
| 481 | gen_twopix(fh, basep + pos, BLACK); |
| 482 | pos += 2; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | /* Checks if it is possible to show timestamp */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 487 | if (TSTAMP_MIN_X + strlen(timestr) >= wmax) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 488 | goto end; |
| 489 | |
| 490 | /* Print stream time */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 491 | if (line >= TSTAMP_MIN_Y && line <= TSTAMP_MAX_Y) { |
| 492 | j = TSTAMP_MIN_X; |
| 493 | for (s = timestr; *s; s++) { |
| 494 | chr = rom8x16_bits[(*s-0x30)*16+line-TSTAMP_MIN_Y]; |
| 495 | for (i = 0; i < 7; i++) { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 496 | pos = inipos + j * 2; |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 497 | /* Draw white font on black background */ |
| 498 | if (chr & 1 << (7 - i)) |
| 499 | gen_twopix(fh, basep + pos, WHITE); |
| 500 | else |
| 501 | gen_twopix(fh, basep + pos, BLACK); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 502 | j++; |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 507 | end: |
Mauro Carvalho Chehab | b50e7fe | 2007-01-25 05:00:01 -0300 | [diff] [blame] | 508 | return; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 509 | } |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 510 | |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 511 | static void vivi_fillbuff(struct vivi_fh *fh, struct vivi_buffer *buf) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 512 | { |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 513 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 514 | int h , pos = 0; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 515 | int hmax = buf->vb.height; |
| 516 | int wmax = buf->vb.width; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 517 | struct timeval ts; |
Marcin Slusarz | 5c554e6 | 2008-06-22 09:11:40 -0300 | [diff] [blame] | 518 | char *tmpbuf; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 519 | void *vbuf = videobuf_to_vmalloc(&buf->vb); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 520 | |
Marcin Slusarz | 5c554e6 | 2008-06-22 09:11:40 -0300 | [diff] [blame] | 521 | if (!vbuf) |
Mauro Carvalho Chehab | 5a03770 | 2007-08-02 23:31:54 -0300 | [diff] [blame] | 522 | return; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 523 | |
Marcin Slusarz | 5c554e6 | 2008-06-22 09:11:40 -0300 | [diff] [blame] | 524 | tmpbuf = kmalloc(wmax * 2, GFP_ATOMIC); |
| 525 | if (!tmpbuf) |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 526 | return; |
| 527 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 528 | for (h = 0; h < hmax; h++) { |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 529 | gen_line(fh, tmpbuf, 0, wmax, hmax, h, dev->mv_count, |
Mauro Carvalho Chehab | 3bef5e4 | 2007-09-22 02:01:33 -0300 | [diff] [blame] | 530 | dev->timestr); |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 531 | memcpy(vbuf + pos, tmpbuf, wmax * 2); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 532 | pos += wmax*2; |
| 533 | } |
| 534 | |
Mauro Carvalho Chehab | 025341d | 2007-12-10 04:43:38 -0300 | [diff] [blame] | 535 | dev->mv_count++; |
Mauro Carvalho Chehab | 3bef5e4 | 2007-09-22 02:01:33 -0300 | [diff] [blame] | 536 | |
Mauro Carvalho Chehab | 5a03770 | 2007-08-02 23:31:54 -0300 | [diff] [blame] | 537 | kfree(tmpbuf); |
| 538 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 539 | /* Updates stream time */ |
| 540 | |
Mauro Carvalho Chehab | dfd8c04 | 2008-01-13 19:36:11 -0300 | [diff] [blame] | 541 | dev->ms += jiffies_to_msecs(jiffies-dev->jiffies); |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 542 | dev->jiffies = jiffies; |
Mauro Carvalho Chehab | dfd8c04 | 2008-01-13 19:36:11 -0300 | [diff] [blame] | 543 | if (dev->ms >= 1000) { |
| 544 | dev->ms -= 1000; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 545 | dev->s++; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 546 | if (dev->s >= 60) { |
| 547 | dev->s -= 60; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 548 | dev->m++; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 549 | if (dev->m > 60) { |
| 550 | dev->m -= 60; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 551 | dev->h++; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 552 | if (dev->h > 24) |
| 553 | dev->h -= 24; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | } |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 557 | sprintf(dev->timestr, "%02d:%02d:%02d:%03d", |
Mauro Carvalho Chehab | dfd8c04 | 2008-01-13 19:36:11 -0300 | [diff] [blame] | 558 | dev->h, dev->m, dev->s, dev->ms); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 559 | |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 560 | dprintk(dev, 2, "vivifill at %s: Buffer 0x%08lx size= %d\n", |
| 561 | dev->timestr, (unsigned long)tmpbuf, pos); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 562 | |
| 563 | /* Advice that buffer was filled */ |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 564 | buf->vb.field_count++; |
| 565 | do_gettimeofday(&ts); |
| 566 | buf->vb.ts = ts; |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 567 | buf->vb.state = VIDEOBUF_DONE; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 568 | } |
| 569 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 570 | static void vivi_thread_tick(struct vivi_fh *fh) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 571 | { |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 572 | struct vivi_buffer *buf; |
| 573 | struct vivi_dev *dev = fh->dev; |
| 574 | struct vivi_dmaqueue *dma_q = &dev->vidq; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 575 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 576 | unsigned long flags = 0; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 577 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 578 | dprintk(dev, 1, "Thread tick\n"); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 579 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 580 | spin_lock_irqsave(&dev->slock, flags); |
| 581 | if (list_empty(&dma_q->active)) { |
| 582 | dprintk(dev, 1, "No active queue to serve\n"); |
| 583 | goto unlock; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 584 | } |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 585 | |
| 586 | buf = list_entry(dma_q->active.next, |
| 587 | struct vivi_buffer, vb.queue); |
| 588 | |
| 589 | /* Nobody is waiting on this buffer, return */ |
| 590 | if (!waitqueue_active(&buf->vb.done)) |
| 591 | goto unlock; |
| 592 | |
| 593 | list_del(&buf->vb.queue); |
| 594 | |
| 595 | do_gettimeofday(&buf->vb.ts); |
| 596 | |
| 597 | /* Fill buffer */ |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 598 | vivi_fillbuff(fh, buf); |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 599 | dprintk(dev, 1, "filled buffer %p\n", buf); |
| 600 | |
| 601 | wake_up(&buf->vb.done); |
| 602 | dprintk(dev, 2, "[%p/%d] wakeup\n", buf, buf->vb. i); |
| 603 | unlock: |
| 604 | spin_unlock_irqrestore(&dev->slock, flags); |
| 605 | return; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 606 | } |
| 607 | |
Mauro Carvalho Chehab | 6594ad8 | 2007-12-13 16:15:41 -0300 | [diff] [blame] | 608 | #define frames_to_ms(frames) \ |
| 609 | ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR) |
| 610 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 611 | static void vivi_sleep(struct vivi_fh *fh) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 612 | { |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 613 | struct vivi_dev *dev = fh->dev; |
| 614 | struct vivi_dmaqueue *dma_q = &dev->vidq; |
| 615 | int timeout; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 616 | DECLARE_WAITQUEUE(wait, current); |
| 617 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 618 | dprintk(dev, 1, "%s dma_q=0x%08lx\n", __func__, |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 619 | (unsigned long)dma_q); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 620 | |
| 621 | add_wait_queue(&dma_q->wq, &wait); |
Mauro Carvalho Chehab | 6594ad8 | 2007-12-13 16:15:41 -0300 | [diff] [blame] | 622 | if (kthread_should_stop()) |
| 623 | goto stop_task; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 624 | |
Mauro Carvalho Chehab | 6594ad8 | 2007-12-13 16:15:41 -0300 | [diff] [blame] | 625 | /* Calculate time to wake up */ |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 626 | timeout = msecs_to_jiffies(frames_to_ms(1)); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 627 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 628 | vivi_thread_tick(fh); |
Mauro Carvalho Chehab | 6594ad8 | 2007-12-13 16:15:41 -0300 | [diff] [blame] | 629 | |
| 630 | schedule_timeout_interruptible(timeout); |
| 631 | |
| 632 | stop_task: |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 633 | remove_wait_queue(&dma_q->wq, &wait); |
| 634 | try_to_freeze(); |
| 635 | } |
| 636 | |
Adrian Bunk | 972c351 | 2006-04-27 21:06:50 -0300 | [diff] [blame] | 637 | static int vivi_thread(void *data) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 638 | { |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 639 | struct vivi_fh *fh = data; |
| 640 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 641 | |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 642 | dprintk(dev, 1, "thread started\n"); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 643 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 644 | set_freezable(); |
Mauro Carvalho Chehab | 0b60051 | 2007-01-14 08:33:24 -0300 | [diff] [blame] | 645 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 646 | for (;;) { |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 647 | vivi_sleep(fh); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 648 | |
| 649 | if (kthread_should_stop()) |
| 650 | break; |
| 651 | } |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 652 | dprintk(dev, 1, "thread: exit\n"); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 653 | return 0; |
| 654 | } |
| 655 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 656 | static int vivi_start_thread(struct vivi_fh *fh) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 657 | { |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 658 | struct vivi_dev *dev = fh->dev; |
| 659 | struct vivi_dmaqueue *dma_q = &dev->vidq; |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 660 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 661 | dma_q->frame = 0; |
| 662 | dma_q->ini_jiffies = jiffies; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 663 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 664 | dprintk(dev, 1, "%s\n", __func__); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 665 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 666 | dma_q->kthread = kthread_run(vivi_thread, fh, "vivi"); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 667 | |
Akinobu Mita | 054afee | 2006-12-20 10:04:00 -0300 | [diff] [blame] | 668 | if (IS_ERR(dma_q->kthread)) { |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 669 | v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n"); |
Akinobu Mita | 054afee | 2006-12-20 10:04:00 -0300 | [diff] [blame] | 670 | return PTR_ERR(dma_q->kthread); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 671 | } |
Mauro Carvalho Chehab | 0b60051 | 2007-01-14 08:33:24 -0300 | [diff] [blame] | 672 | /* Wakes thread */ |
| 673 | wake_up_interruptible(&dma_q->wq); |
| 674 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 675 | dprintk(dev, 1, "returning from %s\n", __func__); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 676 | return 0; |
| 677 | } |
| 678 | |
Adrian Bunk | 972c351 | 2006-04-27 21:06:50 -0300 | [diff] [blame] | 679 | static void vivi_stop_thread(struct vivi_dmaqueue *dma_q) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 680 | { |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 681 | struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq); |
| 682 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 683 | dprintk(dev, 1, "%s\n", __func__); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 684 | /* shutdown control thread */ |
| 685 | if (dma_q->kthread) { |
| 686 | kthread_stop(dma_q->kthread); |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 687 | dma_q->kthread = NULL; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 691 | /* ------------------------------------------------------------------ |
| 692 | Videobuf operations |
| 693 | ------------------------------------------------------------------*/ |
| 694 | static int |
| 695 | buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) |
| 696 | { |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 697 | struct vivi_fh *fh = vq->priv_data; |
| 698 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 699 | |
| 700 | *size = fh->width*fh->height*2; |
| 701 | |
| 702 | if (0 == *count) |
| 703 | *count = 32; |
Mauro Carvalho Chehab | 6bb2790 | 2007-08-23 16:41:14 -0300 | [diff] [blame] | 704 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 705 | while (*size * *count > vid_limit * 1024 * 1024) |
| 706 | (*count)--; |
Mauro Carvalho Chehab | 6bb2790 | 2007-08-23 16:41:14 -0300 | [diff] [blame] | 707 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 708 | dprintk(dev, 1, "%s, count=%d, size=%d\n", __func__, |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 709 | *count, *size); |
Mauro Carvalho Chehab | 6bb2790 | 2007-08-23 16:41:14 -0300 | [diff] [blame] | 710 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
Adrian Bunk | 972c351 | 2006-04-27 21:06:50 -0300 | [diff] [blame] | 714 | static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 715 | { |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 716 | struct vivi_fh *fh = vq->priv_data; |
| 717 | struct vivi_dev *dev = fh->dev; |
| 718 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 719 | dprintk(dev, 1, "%s, state: %i\n", __func__, buf->vb.state); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 720 | |
| 721 | if (in_interrupt()) |
| 722 | BUG(); |
| 723 | |
Mauro Carvalho Chehab | 5a03770 | 2007-08-02 23:31:54 -0300 | [diff] [blame] | 724 | videobuf_vmalloc_free(&buf->vb); |
Mauro Carvalho Chehab | fbde31d | 2008-04-13 14:57:44 -0300 | [diff] [blame] | 725 | dprintk(dev, 1, "free_buffer: freed\n"); |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 726 | buf->vb.state = VIDEOBUF_NEEDS_INIT; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | #define norm_maxw() 1024 |
| 730 | #define norm_maxh() 768 |
| 731 | static int |
| 732 | buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, |
| 733 | enum v4l2_field field) |
| 734 | { |
| 735 | struct vivi_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 736 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 737 | struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb); |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 738 | int rc; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 739 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 740 | dprintk(dev, 1, "%s, field=%d\n", __func__, field); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 741 | |
| 742 | BUG_ON(NULL == fh->fmt); |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 743 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 744 | if (fh->width < 48 || fh->width > norm_maxw() || |
| 745 | fh->height < 32 || fh->height > norm_maxh()) |
| 746 | return -EINVAL; |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 747 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 748 | buf->vb.size = fh->width*fh->height*2; |
| 749 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) |
| 750 | return -EINVAL; |
| 751 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 752 | /* These properties only change when queue is idle, see s_fmt */ |
| 753 | buf->fmt = fh->fmt; |
| 754 | buf->vb.width = fh->width; |
| 755 | buf->vb.height = fh->height; |
| 756 | buf->vb.field = field; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 757 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 758 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 759 | rc = videobuf_iolock(vq, &buf->vb, NULL); |
| 760 | if (rc < 0) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 761 | goto fail; |
| 762 | } |
| 763 | |
Brandon Philips | 0fc0686 | 2007-11-06 20:02:36 -0300 | [diff] [blame] | 764 | buf->vb.state = VIDEOBUF_PREPARED; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 765 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 766 | return 0; |
| 767 | |
| 768 | fail: |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 769 | free_buffer(vq, buf); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 770 | return rc; |
| 771 | } |
| 772 | |
| 773 | static void |
| 774 | buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) |
| 775 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 776 | struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb); |
| 777 | struct vivi_fh *fh = vq->priv_data; |
| 778 | struct vivi_dev *dev = fh->dev; |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 779 | struct vivi_dmaqueue *vidq = &dev->vidq; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 780 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 781 | dprintk(dev, 1, "%s\n", __func__); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 782 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 783 | buf->vb.state = VIDEOBUF_QUEUED; |
| 784 | list_add_tail(&buf->vb.queue, &vidq->active); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 785 | } |
| 786 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 787 | static void buffer_release(struct videobuf_queue *vq, |
| 788 | struct videobuf_buffer *vb) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 789 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 790 | struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 791 | struct vivi_fh *fh = vq->priv_data; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 792 | struct vivi_dev *dev = (struct vivi_dev *)fh->dev; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 793 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 794 | dprintk(dev, 1, "%s\n", __func__); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 795 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 796 | free_buffer(vq, buf); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 797 | } |
| 798 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 799 | static struct videobuf_queue_ops vivi_video_qops = { |
| 800 | .buf_setup = buffer_setup, |
| 801 | .buf_prepare = buffer_prepare, |
| 802 | .buf_queue = buffer_queue, |
| 803 | .buf_release = buffer_release, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 804 | }; |
| 805 | |
| 806 | /* ------------------------------------------------------------------ |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 807 | IOCTL vidioc handling |
| 808 | ------------------------------------------------------------------*/ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 809 | static int vidioc_querycap(struct file *file, void *priv, |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 810 | struct v4l2_capability *cap) |
| 811 | { |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 812 | struct vivi_fh *fh = priv; |
| 813 | struct vivi_dev *dev = fh->dev; |
| 814 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 815 | strcpy(cap->driver, "vivi"); |
| 816 | strcpy(cap->card, "vivi"); |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 817 | strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info)); |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 818 | cap->version = VIVI_VERSION; |
| 819 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | |
| 820 | V4L2_CAP_STREAMING | |
| 821 | V4L2_CAP_READWRITE; |
| 822 | return 0; |
| 823 | } |
| 824 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 825 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 826 | struct v4l2_fmtdesc *f) |
| 827 | { |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 828 | struct vivi_fmt *fmt; |
| 829 | |
| 830 | if (f->index >= ARRAY_SIZE(formats)) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 831 | return -EINVAL; |
| 832 | |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 833 | fmt = &formats[f->index]; |
| 834 | |
| 835 | strlcpy(f->description, fmt->name, sizeof(f->description)); |
| 836 | f->pixelformat = fmt->fourcc; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 837 | return 0; |
| 838 | } |
| 839 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 840 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 841 | struct v4l2_format *f) |
| 842 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 843 | struct vivi_fh *fh = priv; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 844 | |
| 845 | f->fmt.pix.width = fh->width; |
| 846 | f->fmt.pix.height = fh->height; |
| 847 | f->fmt.pix.field = fh->vb_vidq.field; |
| 848 | f->fmt.pix.pixelformat = fh->fmt->fourcc; |
| 849 | f->fmt.pix.bytesperline = |
| 850 | (f->fmt.pix.width * fh->fmt->depth) >> 3; |
| 851 | f->fmt.pix.sizeimage = |
| 852 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 853 | |
| 854 | return (0); |
| 855 | } |
| 856 | |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 857 | static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 858 | struct v4l2_format *f) |
| 859 | { |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 860 | struct vivi_fh *fh = priv; |
| 861 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 862 | struct vivi_fmt *fmt; |
| 863 | enum v4l2_field field; |
| 864 | unsigned int maxw, maxh; |
| 865 | |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 866 | fmt = get_format(f); |
| 867 | if (!fmt) { |
| 868 | dprintk(dev, 1, "Fourcc format (0x%08x) invalid.\n", |
| 869 | f->fmt.pix.pixelformat); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 870 | return -EINVAL; |
| 871 | } |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 872 | |
| 873 | field = f->fmt.pix.field; |
| 874 | |
| 875 | if (field == V4L2_FIELD_ANY) { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 876 | field = V4L2_FIELD_INTERLACED; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 877 | } else if (V4L2_FIELD_INTERLACED != field) { |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 878 | dprintk(dev, 1, "Field type invalid.\n"); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 879 | return -EINVAL; |
| 880 | } |
| 881 | |
| 882 | maxw = norm_maxw(); |
| 883 | maxh = norm_maxh(); |
| 884 | |
| 885 | f->fmt.pix.field = field; |
| 886 | if (f->fmt.pix.height < 32) |
| 887 | f->fmt.pix.height = 32; |
| 888 | if (f->fmt.pix.height > maxh) |
| 889 | f->fmt.pix.height = maxh; |
| 890 | if (f->fmt.pix.width < 48) |
| 891 | f->fmt.pix.width = 48; |
| 892 | if (f->fmt.pix.width > maxw) |
| 893 | f->fmt.pix.width = maxw; |
| 894 | f->fmt.pix.width &= ~0x03; |
| 895 | f->fmt.pix.bytesperline = |
| 896 | (f->fmt.pix.width * fmt->depth) >> 3; |
| 897 | f->fmt.pix.sizeimage = |
| 898 | f->fmt.pix.height * f->fmt.pix.bytesperline; |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 903 | /* precalculate color bar values to speed up rendering */ |
| 904 | static void precalculate_bars(struct vivi_fh *fh) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 905 | { |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 906 | struct vivi_dev *dev = fh->dev; |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 907 | unsigned char r, g, b; |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 908 | int k, is_yuv; |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 909 | |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 910 | fh->input = dev->input; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 911 | |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 912 | for (k = 0; k < 8; k++) { |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 913 | r = bars[fh->input].bar[k][0]; |
| 914 | g = bars[fh->input].bar[k][1]; |
| 915 | b = bars[fh->input].bar[k][2]; |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 916 | is_yuv = 0; |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 917 | |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 918 | switch (fh->fmt->fourcc) { |
| 919 | case V4L2_PIX_FMT_YUYV: |
Magnus Damm | fca36ba | 2008-10-14 12:47:25 -0300 | [diff] [blame] | 920 | case V4L2_PIX_FMT_UYVY: |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 921 | is_yuv = 1; |
| 922 | break; |
Magnus Damm | aeadb5d | 2008-10-14 12:47:35 -0300 | [diff] [blame] | 923 | case V4L2_PIX_FMT_RGB565: |
| 924 | case V4L2_PIX_FMT_RGB565X: |
| 925 | r >>= 3; |
| 926 | g >>= 2; |
| 927 | b >>= 3; |
| 928 | break; |
Magnus Damm | def5239 | 2008-10-14 12:47:43 -0300 | [diff] [blame] | 929 | case V4L2_PIX_FMT_RGB555: |
| 930 | case V4L2_PIX_FMT_RGB555X: |
| 931 | r >>= 3; |
| 932 | g >>= 3; |
| 933 | b >>= 3; |
| 934 | break; |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | if (is_yuv) { |
| 938 | fh->bars[k][0] = TO_Y(r, g, b); /* Luma */ |
| 939 | fh->bars[k][1] = TO_U(r, g, b); /* Cb */ |
| 940 | fh->bars[k][2] = TO_V(r, g, b); /* Cr */ |
| 941 | } else { |
| 942 | fh->bars[k][0] = r; |
| 943 | fh->bars[k][1] = g; |
| 944 | fh->bars[k][2] = b; |
| 945 | } |
Magnus Damm | 74d7c5a | 2008-10-14 12:46:59 -0300 | [diff] [blame] | 946 | } |
| 947 | |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | /*FIXME: This seems to be generic enough to be at videodev2 */ |
| 951 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
| 952 | struct v4l2_format *f) |
| 953 | { |
| 954 | struct vivi_fh *fh = priv; |
| 955 | struct videobuf_queue *q = &fh->vb_vidq; |
| 956 | |
| 957 | int ret = vidioc_try_fmt_vid_cap(file, fh, f); |
| 958 | if (ret < 0) |
| 959 | return ret; |
| 960 | |
| 961 | mutex_lock(&q->vb_lock); |
| 962 | |
| 963 | if (videobuf_queue_is_busy(&fh->vb_vidq)) { |
| 964 | dprintk(fh->dev, 1, "%s queue busy\n", __func__); |
| 965 | ret = -EBUSY; |
| 966 | goto out; |
| 967 | } |
| 968 | |
| 969 | fh->fmt = get_format(f); |
| 970 | fh->width = f->fmt.pix.width; |
| 971 | fh->height = f->fmt.pix.height; |
| 972 | fh->vb_vidq.field = f->fmt.pix.field; |
| 973 | fh->type = f->type; |
| 974 | |
| 975 | precalculate_bars(fh); |
| 976 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 977 | ret = 0; |
| 978 | out: |
| 979 | mutex_unlock(&q->vb_lock); |
| 980 | |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 981 | return ret; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 982 | } |
| 983 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 984 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 985 | struct v4l2_requestbuffers *p) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 986 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 987 | struct vivi_fh *fh = priv; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 988 | |
| 989 | return (videobuf_reqbufs(&fh->vb_vidq, p)); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 990 | } |
| 991 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 992 | static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 993 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 994 | struct vivi_fh *fh = priv; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 995 | |
| 996 | return (videobuf_querybuf(&fh->vb_vidq, p)); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 997 | } |
| 998 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 999 | static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1000 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1001 | struct vivi_fh *fh = priv; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1002 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1003 | return (videobuf_qbuf(&fh->vb_vidq, p)); |
| 1004 | } |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1005 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1006 | static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1007 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1008 | struct vivi_fh *fh = priv; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1009 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1010 | return (videobuf_dqbuf(&fh->vb_vidq, p, |
| 1011 | file->f_flags & O_NONBLOCK)); |
| 1012 | } |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1013 | |
Mauro Carvalho Chehab | 0dfa9ab | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 1014 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1015 | static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1016 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1017 | struct vivi_fh *fh = priv; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1018 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1019 | return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1020 | } |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1021 | #endif |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1022 | |
Adrian Bunk | dc46ace | 2006-06-23 06:42:44 -0300 | [diff] [blame] | 1023 | static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1024 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1025 | struct vivi_fh *fh = priv; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1026 | |
| 1027 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1028 | return -EINVAL; |
| 1029 | if (i != fh->type) |
| 1030 | return -EINVAL; |
| 1031 | |
Brandon Philips | ba32bd9 | 2007-09-27 20:55:17 -0300 | [diff] [blame] | 1032 | return videobuf_streamon(&fh->vb_vidq); |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1033 | } |
| 1034 | |
Adrian Bunk | dc46ace | 2006-06-23 06:42:44 -0300 | [diff] [blame] | 1035 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1036 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1037 | struct vivi_fh *fh = priv; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1038 | |
| 1039 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1040 | return -EINVAL; |
| 1041 | if (i != fh->type) |
| 1042 | return -EINVAL; |
| 1043 | |
Brandon Philips | ba32bd9 | 2007-09-27 20:55:17 -0300 | [diff] [blame] | 1044 | return videobuf_streamoff(&fh->vb_vidq); |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1045 | } |
| 1046 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1047 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1048 | { |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1049 | return 0; |
| 1050 | } |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1051 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1052 | /* only one input in this sample driver */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1053 | static int vidioc_enum_input(struct file *file, void *priv, |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1054 | struct v4l2_input *inp) |
| 1055 | { |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 1056 | if (inp->index >= NUM_INPUTS) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1057 | return -EINVAL; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1058 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1059 | inp->type = V4L2_INPUT_TYPE_CAMERA; |
Mauro Carvalho Chehab | 784c668 | 2007-12-13 06:35:26 -0300 | [diff] [blame] | 1060 | inp->std = V4L2_STD_525_60; |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 1061 | sprintf(inp->name, "Camera %u", inp->index); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1062 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1063 | return (0); |
| 1064 | } |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1065 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1066 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1067 | { |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 1068 | struct vivi_fh *fh = priv; |
| 1069 | struct vivi_dev *dev = fh->dev; |
| 1070 | |
| 1071 | *i = dev->input; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1072 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1073 | return (0); |
| 1074 | } |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1075 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1076 | { |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 1077 | struct vivi_fh *fh = priv; |
| 1078 | struct vivi_dev *dev = fh->dev; |
| 1079 | |
| 1080 | if (i >= NUM_INPUTS) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1081 | return -EINVAL; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1082 | |
Mauro Carvalho Chehab | e164b58 | 2009-01-11 10:29:43 -0300 | [diff] [blame] | 1083 | dev->input = i; |
| 1084 | precalculate_bars(fh); |
| 1085 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1086 | return (0); |
| 1087 | } |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1088 | |
| 1089 | /* --- controls ---------------------------------------------- */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1090 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 1091 | struct v4l2_queryctrl *qc) |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1092 | { |
| 1093 | int i; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1094 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1095 | for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) |
| 1096 | if (qc->id && qc->id == vivi_qctrl[i].id) { |
| 1097 | memcpy(qc, &(vivi_qctrl[i]), |
| 1098 | sizeof(*qc)); |
| 1099 | return (0); |
| 1100 | } |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1101 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1102 | return -EINVAL; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1103 | } |
| 1104 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1105 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 1106 | struct v4l2_control *ctrl) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1107 | { |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 1108 | struct vivi_fh *fh = priv; |
| 1109 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1110 | int i; |
| 1111 | |
| 1112 | for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) |
| 1113 | if (ctrl->id == vivi_qctrl[i].id) { |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 1114 | ctrl->value = dev->qctl_regs[i]; |
| 1115 | return 0; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | return -EINVAL; |
| 1119 | } |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1120 | static int vidioc_s_ctrl(struct file *file, void *priv, |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1121 | struct v4l2_control *ctrl) |
| 1122 | { |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 1123 | struct vivi_fh *fh = priv; |
| 1124 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1125 | int i; |
| 1126 | |
| 1127 | for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) |
| 1128 | if (ctrl->id == vivi_qctrl[i].id) { |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 1129 | if (ctrl->value < vivi_qctrl[i].minimum || |
| 1130 | ctrl->value > vivi_qctrl[i].maximum) { |
| 1131 | return -ERANGE; |
| 1132 | } |
| 1133 | dev->qctl_regs[i] = ctrl->value; |
| 1134 | return 0; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1135 | } |
| 1136 | return -EINVAL; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /* ------------------------------------------------------------------ |
| 1140 | File operations for the device |
| 1141 | ------------------------------------------------------------------*/ |
| 1142 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1143 | static int vivi_open(struct file *file) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1144 | { |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1145 | struct vivi_dev *dev = video_drvdata(file); |
Mauro Carvalho Chehab | 63b79cf | 2008-04-26 08:25:18 -0300 | [diff] [blame] | 1146 | struct vivi_fh *fh = NULL; |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1147 | int retval = 0; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1148 | |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1149 | mutex_lock(&dev->mutex); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1150 | dev->users++; |
| 1151 | |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1152 | if (dev->users > 1) { |
| 1153 | dev->users--; |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1154 | mutex_unlock(&dev->mutex); |
| 1155 | return -EBUSY; |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1156 | } |
| 1157 | |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1158 | dprintk(dev, 1, "open /dev/video%d type=%s users=%d\n", dev->vfd->num, |
Trent Piepho | a991f44 | 2007-10-10 05:37:43 -0300 | [diff] [blame] | 1159 | v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1160 | |
| 1161 | /* allocate + initialize per filehandle data */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1162 | fh = kzalloc(sizeof(*fh), GFP_KERNEL); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1163 | if (NULL == fh) { |
| 1164 | dev->users--; |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1165 | retval = -ENOMEM; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1166 | } |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1167 | mutex_unlock(&dev->mutex); |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1168 | |
| 1169 | if (retval) |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1170 | return retval; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1171 | |
| 1172 | file->private_data = fh; |
| 1173 | fh->dev = dev; |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1174 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1175 | fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Magnus Damm | d891f47 | 2008-10-14 12:47:09 -0300 | [diff] [blame] | 1176 | fh->fmt = &formats[0]; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1177 | fh->width = 640; |
| 1178 | fh->height = 480; |
| 1179 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1180 | /* Resets frame counters */ |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1181 | dev->h = 0; |
| 1182 | dev->m = 0; |
| 1183 | dev->s = 0; |
Mauro Carvalho Chehab | dfd8c04 | 2008-01-13 19:36:11 -0300 | [diff] [blame] | 1184 | dev->ms = 0; |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1185 | dev->mv_count = 0; |
| 1186 | dev->jiffies = jiffies; |
| 1187 | sprintf(dev->timestr, "%02d:%02d:%02d:%03d", |
Mauro Carvalho Chehab | dfd8c04 | 2008-01-13 19:36:11 -0300 | [diff] [blame] | 1188 | dev->h, dev->m, dev->s, dev->ms); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1189 | |
Mauro Carvalho Chehab | 5a03770 | 2007-08-02 23:31:54 -0300 | [diff] [blame] | 1190 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops, |
Mauro Carvalho Chehab | 55862ac | 2007-12-13 16:13:37 -0300 | [diff] [blame] | 1191 | NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED, |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1192 | sizeof(struct vivi_buffer), fh); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1193 | |
Brandon Philips | 78718e5 | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1194 | vivi_start_thread(fh); |
| 1195 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | static ssize_t |
| 1200 | vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos) |
| 1201 | { |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1202 | struct vivi_fh *fh = file->private_data; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1203 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1204 | if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
Mauro Carvalho Chehab | acb09af | 2007-07-29 22:56:11 -0300 | [diff] [blame] | 1205 | return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1206 | file->f_flags & O_NONBLOCK); |
| 1207 | } |
| 1208 | return 0; |
| 1209 | } |
| 1210 | |
| 1211 | static unsigned int |
| 1212 | vivi_poll(struct file *file, struct poll_table_struct *wait) |
| 1213 | { |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1214 | struct vivi_fh *fh = file->private_data; |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 1215 | struct vivi_dev *dev = fh->dev; |
Brandon Philips | 85c7c70bc | 2007-09-27 20:55:02 -0300 | [diff] [blame] | 1216 | struct videobuf_queue *q = &fh->vb_vidq; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1217 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1218 | dprintk(dev, 1, "%s\n", __func__); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1219 | |
| 1220 | if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) |
| 1221 | return POLLERR; |
| 1222 | |
Brandon Philips | 85c7c70bc | 2007-09-27 20:55:02 -0300 | [diff] [blame] | 1223 | return videobuf_poll_stream(file, q, wait); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1224 | } |
| 1225 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1226 | static int vivi_close(struct file *file) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1227 | { |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1228 | struct vivi_fh *fh = file->private_data; |
| 1229 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1230 | struct vivi_dmaqueue *vidq = &dev->vidq; |
| 1231 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1232 | int minor = video_devdata(file)->minor; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1233 | |
| 1234 | vivi_stop_thread(vidq); |
Brandon Philips | 053fcb6 | 2007-11-13 20:11:26 -0300 | [diff] [blame] | 1235 | videobuf_stop(&fh->vb_vidq); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1236 | videobuf_mmap_free(&fh->vb_vidq); |
| 1237 | |
Mauro Carvalho Chehab | 55712ff | 2007-12-10 04:38:11 -0300 | [diff] [blame] | 1238 | kfree(fh); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1239 | |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1240 | mutex_lock(&dev->mutex); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1241 | dev->users--; |
Brandon Philips | aa9dbac | 2008-04-02 18:10:59 -0300 | [diff] [blame] | 1242 | mutex_unlock(&dev->mutex); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1243 | |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 1244 | dprintk(dev, 1, "close called (minor=%d, users=%d)\n", |
| 1245 | minor, dev->users); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1246 | |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1250 | static int vivi_mmap(struct file *file, struct vm_area_struct *vma) |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1251 | { |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 1252 | struct vivi_fh *fh = file->private_data; |
| 1253 | struct vivi_dev *dev = fh->dev; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1254 | int ret; |
| 1255 | |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 1256 | dprintk(dev, 1, "mmap called, vma=0x%08lx\n", (unsigned long)vma); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1257 | |
Mauro Carvalho Chehab | 543323b | 2007-12-10 09:33:52 -0300 | [diff] [blame] | 1258 | ret = videobuf_mmap_mapper(&fh->vb_vidq, vma); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1259 | |
Mauro Carvalho Chehab | 6c2f990 | 2007-12-13 13:30:14 -0300 | [diff] [blame] | 1260 | dprintk(dev, 1, "vma start=0x%08lx, size=%ld, ret=%d\n", |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1261 | (unsigned long)vma->vm_start, |
| 1262 | (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, |
| 1263 | ret); |
| 1264 | |
| 1265 | return ret; |
| 1266 | } |
| 1267 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1268 | static const struct v4l2_file_operations vivi_fops = { |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1269 | .owner = THIS_MODULE, |
| 1270 | .open = vivi_open, |
Mauro Carvalho Chehab | f905c44 | 2007-12-10 04:07:03 -0300 | [diff] [blame] | 1271 | .release = vivi_close, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1272 | .read = vivi_read, |
| 1273 | .poll = vivi_poll, |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1274 | .ioctl = video_ioctl2, /* V4L2 ioctl handler */ |
Mauro Carvalho Chehab | 5a03770 | 2007-08-02 23:31:54 -0300 | [diff] [blame] | 1275 | .mmap = vivi_mmap, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1276 | }; |
| 1277 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1278 | static const struct v4l2_ioctl_ops vivi_ioctl_ops = { |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1279 | .vidioc_querycap = vidioc_querycap, |
Hans Verkuil | 78b526a | 2008-05-28 12:16:41 -0300 | [diff] [blame] | 1280 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1281 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1282 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1283 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1284 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1285 | .vidioc_querybuf = vidioc_querybuf, |
| 1286 | .vidioc_qbuf = vidioc_qbuf, |
| 1287 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1288 | .vidioc_s_std = vidioc_s_std, |
| 1289 | .vidioc_enum_input = vidioc_enum_input, |
| 1290 | .vidioc_g_input = vidioc_g_input, |
| 1291 | .vidioc_s_input = vidioc_s_input, |
| 1292 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1293 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1294 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1295 | .vidioc_streamon = vidioc_streamon, |
| 1296 | .vidioc_streamoff = vidioc_streamoff, |
Mauro Carvalho Chehab | 0dfa9ab | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 1297 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1298 | .vidiocgmbuf = vidiocgmbuf, |
| 1299 | #endif |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1300 | }; |
| 1301 | |
| 1302 | static struct video_device vivi_template = { |
| 1303 | .name = "vivi", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1304 | .fops = &vivi_fops, |
| 1305 | .ioctl_ops = &vivi_ioctl_ops, |
| 1306 | .minor = -1, |
| 1307 | .release = video_device_release, |
| 1308 | |
Mauro Carvalho Chehab | 784c668 | 2007-12-13 06:35:26 -0300 | [diff] [blame] | 1309 | .tvnorms = V4L2_STD_525_60, |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 1310 | .current_norm = V4L2_STD_NTSC_M, |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1311 | }; |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1312 | |
Mauro Carvalho Chehab | c820cc4 | 2006-06-04 10:34:12 -0300 | [diff] [blame] | 1313 | /* ----------------------------------------------------------------- |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1314 | Initialization and module stuff |
| 1315 | ------------------------------------------------------------------*/ |
| 1316 | |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1317 | static int vivi_release(void) |
| 1318 | { |
| 1319 | struct vivi_dev *dev; |
| 1320 | struct list_head *list; |
| 1321 | |
| 1322 | while (!list_empty(&vivi_devlist)) { |
| 1323 | list = vivi_devlist.next; |
| 1324 | list_del(list); |
| 1325 | dev = list_entry(list, struct vivi_dev, vivi_devlist); |
| 1326 | |
| 1327 | v4l2_info(&dev->v4l2_dev, "unregistering /dev/video%d\n", |
| 1328 | dev->vfd->num); |
| 1329 | video_unregister_device(dev->vfd); |
| 1330 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1331 | kfree(dev); |
| 1332 | } |
| 1333 | |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 1337 | static int __init vivi_create_instance(int inst) |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1338 | { |
| 1339 | struct vivi_dev *dev; |
| 1340 | struct video_device *vfd; |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 1341 | int ret, i; |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1342 | |
| 1343 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 1344 | if (!dev) |
| 1345 | return -ENOMEM; |
| 1346 | |
| 1347 | snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 1348 | "%s-%03d", VIVI_MODULE_NAME, inst); |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1349 | ret = v4l2_device_register(NULL, &dev->v4l2_dev); |
| 1350 | if (ret) |
| 1351 | goto free_dev; |
| 1352 | |
| 1353 | /* init video dma queues */ |
| 1354 | INIT_LIST_HEAD(&dev->vidq.active); |
| 1355 | init_waitqueue_head(&dev->vidq.wq); |
| 1356 | |
| 1357 | /* initialize locks */ |
| 1358 | spin_lock_init(&dev->slock); |
| 1359 | mutex_init(&dev->mutex); |
| 1360 | |
| 1361 | ret = -ENOMEM; |
| 1362 | vfd = video_device_alloc(); |
| 1363 | if (!vfd) |
| 1364 | goto unreg_dev; |
| 1365 | |
| 1366 | *vfd = vivi_template; |
| 1367 | |
| 1368 | ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr); |
| 1369 | if (ret < 0) |
| 1370 | goto rel_vdev; |
| 1371 | |
| 1372 | video_set_drvdata(vfd, dev); |
| 1373 | |
Hans Verkuil | c41ee24 | 2009-02-14 13:43:44 -0300 | [diff] [blame] | 1374 | /* Set all controls to their default value. */ |
| 1375 | for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) |
| 1376 | dev->qctl_regs[i] = vivi_qctrl[i].default_value; |
| 1377 | |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1378 | /* Now that everything is fine, let's add it to device list */ |
| 1379 | list_add_tail(&dev->vivi_devlist, &vivi_devlist); |
| 1380 | |
| 1381 | snprintf(vfd->name, sizeof(vfd->name), "%s (%i)", |
| 1382 | vivi_template.name, vfd->num); |
| 1383 | |
| 1384 | if (video_nr >= 0) |
| 1385 | video_nr++; |
| 1386 | |
| 1387 | dev->vfd = vfd; |
| 1388 | v4l2_info(&dev->v4l2_dev, "V4L2 device registered as /dev/video%d\n", |
| 1389 | vfd->num); |
| 1390 | return 0; |
| 1391 | |
| 1392 | rel_vdev: |
| 1393 | video_device_release(vfd); |
| 1394 | unreg_dev: |
| 1395 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1396 | free_dev: |
| 1397 | kfree(dev); |
| 1398 | return ret; |
| 1399 | } |
| 1400 | |
Mauro Carvalho Chehab | 980d4f1 | 2008-09-03 17:11:53 -0300 | [diff] [blame] | 1401 | /* This routine allocates from 1 to n_devs virtual drivers. |
| 1402 | |
| 1403 | The real maximum number of virtual drivers will depend on how many drivers |
| 1404 | will succeed. This is limited to the maximum number of devices that |
Hans Verkuil | 62cfdac | 2009-02-14 11:37:17 -0300 | [diff] [blame] | 1405 | videodev supports, which is equal to VIDEO_NUM_DEVICES. |
Mauro Carvalho Chehab | 980d4f1 | 2008-09-03 17:11:53 -0300 | [diff] [blame] | 1406 | */ |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1407 | static int __init vivi_init(void) |
| 1408 | { |
Hans Verkuil | 9185cbf | 2009-03-06 09:58:12 -0300 | [diff] [blame^] | 1409 | int ret = 0, i; |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1410 | |
Mauro Carvalho Chehab | 980d4f1 | 2008-09-03 17:11:53 -0300 | [diff] [blame] | 1411 | if (n_devs <= 0) |
| 1412 | n_devs = 1; |
| 1413 | |
Mauro Carvalho Chehab | 55712ff | 2007-12-10 04:38:11 -0300 | [diff] [blame] | 1414 | for (i = 0; i < n_devs; i++) { |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1415 | ret = vivi_create_instance(i); |
| 1416 | if (ret) { |
| 1417 | /* If some instantiations succeeded, keep driver */ |
Mauro Carvalho Chehab | 980d4f1 | 2008-09-03 17:11:53 -0300 | [diff] [blame] | 1418 | if (i) |
| 1419 | ret = 0; |
Mauro Carvalho Chehab | 55712ff | 2007-12-10 04:38:11 -0300 | [diff] [blame] | 1420 | break; |
Mauro Carvalho Chehab | 980d4f1 | 2008-09-03 17:11:53 -0300 | [diff] [blame] | 1421 | } |
Mauro Carvalho Chehab | 55712ff | 2007-12-10 04:38:11 -0300 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | if (ret < 0) { |
Mauro Carvalho Chehab | 55712ff | 2007-12-10 04:38:11 -0300 | [diff] [blame] | 1425 | printk(KERN_INFO "Error %d while loading vivi driver\n", ret); |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1426 | return ret; |
| 1427 | } |
| 1428 | |
| 1429 | printk(KERN_INFO "Video Technology Magazine Virtual Video " |
Carl Karsten | 745271a | 2008-06-10 00:02:32 -0300 | [diff] [blame] | 1430 | "Capture Board ver %u.%u.%u successfully loaded.\n", |
| 1431 | (VIVI_VERSION >> 16) & 0xFF, (VIVI_VERSION >> 8) & 0xFF, |
| 1432 | VIVI_VERSION & 0xFF); |
Mauro Carvalho Chehab | 980d4f1 | 2008-09-03 17:11:53 -0300 | [diff] [blame] | 1433 | |
Hans Verkuil | 5ab6c9a | 2009-02-14 13:23:12 -0300 | [diff] [blame] | 1434 | /* n_devs will reflect the actual number of allocated devices */ |
| 1435 | n_devs = i; |
Mauro Carvalho Chehab | 980d4f1 | 2008-09-03 17:11:53 -0300 | [diff] [blame] | 1436 | |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1437 | return ret; |
| 1438 | } |
| 1439 | |
| 1440 | static void __exit vivi_exit(void) |
| 1441 | { |
Mauro Carvalho Chehab | 55712ff | 2007-12-10 04:38:11 -0300 | [diff] [blame] | 1442 | vivi_release(); |
Mauro Carvalho Chehab | 1e6dd65 | 2006-03-10 12:40:10 -0300 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | module_init(vivi_init); |
| 1446 | module_exit(vivi_exit); |