aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/arv.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/arv.c')
-rw-r--r--drivers/media/video/arv.c524
1 files changed, 244 insertions, 280 deletions
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index a356d6bd3131..31e7a123d19a 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -27,8 +27,10 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/sched.h> 29#include <linux/sched.h>
30#include <linux/videodev.h> 30#include <linux/version.h>
31#include <linux/videodev2.h>
31#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-device.h>
32#include <media/v4l2-ioctl.h> 34#include <media/v4l2-ioctl.h>
33#include <linux/mutex.h> 35#include <linux/mutex.h>
34 36
@@ -39,7 +41,7 @@
39#include <asm/byteorder.h> 41#include <asm/byteorder.h>
40 42
41#if 0 43#if 0
42#define DEBUG(n, args...) printk(args) 44#define DEBUG(n, args...) printk(KERN_INFO args)
43#define CHECK_LOST 1 45#define CHECK_LOST 1
44#else 46#else
45#define DEBUG(n, args...) 47#define DEBUG(n, args...)
@@ -52,10 +54,10 @@
52 */ 54 */
53#define USE_INT 0 /* Don't modify */ 55#define USE_INT 0 /* Don't modify */
54 56
55#define VERSION "0.03" 57#define VERSION "0.04"
56 58
57#define ar_inl(addr) inl((unsigned long)(addr)) 59#define ar_inl(addr) inl((unsigned long)(addr))
58#define ar_outl(val, addr) outl((unsigned long)(val),(unsigned long)(addr)) 60#define ar_outl(val, addr) outl((unsigned long)(val), (unsigned long)(addr))
59 61
60extern struct cpuinfo_m32r boot_cpu_data; 62extern struct cpuinfo_m32r boot_cpu_data;
61 63
@@ -79,7 +81,7 @@ extern struct cpuinfo_m32r boot_cpu_data;
79 81
80/* bits & bytes per pixel */ 82/* bits & bytes per pixel */
81#define AR_BITS_PER_PIXEL 16 83#define AR_BITS_PER_PIXEL 16
82#define AR_BYTES_PER_PIXEL (AR_BITS_PER_PIXEL/8) 84#define AR_BYTES_PER_PIXEL (AR_BITS_PER_PIXEL / 8)
83 85
84/* line buffer size */ 86/* line buffer size */
85#define AR_LINE_BYTES_VGA (AR_WIDTH_VGA * AR_BYTES_PER_PIXEL) 87#define AR_LINE_BYTES_VGA (AR_WIDTH_VGA * AR_BYTES_PER_PIXEL)
@@ -104,8 +106,9 @@ extern struct cpuinfo_m32r boot_cpu_data;
104#define AR_MODE_INTERLACE 0 106#define AR_MODE_INTERLACE 0
105#define AR_MODE_NORMAL 1 107#define AR_MODE_NORMAL 1
106 108
107struct ar_device { 109struct ar {
108 struct video_device *vdev; 110 struct v4l2_device v4l2_dev;
111 struct video_device vdev;
109 unsigned int start_capture; /* duaring capture in INT. mode. */ 112 unsigned int start_capture; /* duaring capture in INT. mode. */
110#if USE_INT 113#if USE_INT
111 unsigned char *line_buff; /* DMA line buffer */ 114 unsigned char *line_buff; /* DMA line buffer */
@@ -116,12 +119,13 @@ struct ar_device {
116 int width, height; 119 int width, height;
117 int frame_bytes, line_bytes; 120 int frame_bytes, line_bytes;
118 wait_queue_head_t wait; 121 wait_queue_head_t wait;
119 unsigned long in_use;
120 struct mutex lock; 122 struct mutex lock;
121}; 123};
122 124
125static struct ar ardev;
126
123static int video_nr = -1; /* video device number (first free) */ 127static int video_nr = -1; /* video device number (first free) */
124static unsigned char yuv[MAX_AR_FRAME_BYTES]; 128static unsigned char yuv[MAX_AR_FRAME_BYTES];
125 129
126/* module parameters */ 130/* module parameters */
127/* default frequency */ 131/* default frequency */
@@ -133,9 +137,7 @@ module_param(freq, int, 0);
133module_param(vga, int, 0); 137module_param(vga, int, 0);
134module_param(vga_interlace, int, 0); 138module_param(vga_interlace, int, 0);
135 139
136static int ar_initialize(struct video_device *dev); 140static void wait_for_vsync(void)
137
138static inline void wait_for_vsync(void)
139{ 141{
140 while (ar_inl(ARVCR0) & ARVCR0_VDS) /* wait for VSYNC */ 142 while (ar_inl(ARVCR0) & ARVCR0_VDS) /* wait for VSYNC */
141 cpu_relax(); 143 cpu_relax();
@@ -143,7 +145,7 @@ static inline void wait_for_vsync(void)
143 cpu_relax(); 145 cpu_relax();
144} 146}
145 147
146static inline void wait_acknowledge(void) 148static void wait_acknowledge(void)
147{ 149{
148 int i; 150 int i;
149 151
@@ -156,7 +158,7 @@ static inline void wait_acknowledge(void)
156/******************************************************************* 158/*******************************************************************
157 * I2C functions 159 * I2C functions
158 *******************************************************************/ 160 *******************************************************************/
159void iic(int n, unsigned long addr, unsigned long data1, unsigned long data2, 161static void iic(int n, unsigned long addr, unsigned long data1, unsigned long data2,
160 unsigned long data3) 162 unsigned long data3)
161{ 163{
162 int i; 164 int i;
@@ -200,7 +202,7 @@ void iic(int n, unsigned long addr, unsigned long data1, unsigned long data2,
200} 202}
201 203
202 204
203void init_iic(void) 205static void init_iic(void)
204{ 206{
205 DEBUG(1, "init_iic:\n"); 207 DEBUG(1, "init_iic:\n");
206 208
@@ -214,13 +216,12 @@ void init_iic(void)
214 216
215 /* I2C CLK */ 217 /* I2C CLK */
216 /* 50MH-100k */ 218 /* 50MH-100k */
217 if (freq == 75) { 219 if (freq == 75)
218 ar_outl(369, PLDI2CFREQ); /* BCLK = 75MHz */ 220 ar_outl(369, PLDI2CFREQ); /* BCLK = 75MHz */
219 } else if (freq == 50) { 221 else if (freq == 50)
220 ar_outl(244, PLDI2CFREQ); /* BCLK = 50MHz */ 222 ar_outl(244, PLDI2CFREQ); /* BCLK = 50MHz */
221 } else { 223 else
222 ar_outl(244, PLDI2CFREQ); /* default: BCLK = 50MHz */ 224 ar_outl(244, PLDI2CFREQ); /* default: BCLK = 50MHz */
223 }
224 ar_outl(0x1, PLDI2CCR); /* I2CCR Enable */ 225 ar_outl(0x1, PLDI2CCR); /* I2CCR Enable */
225} 226}
226 227
@@ -245,7 +246,7 @@ static inline void clear_dma_status(void)
245 ar_outl(0x8000, M32R_DMAEDET_PORTL); /* clear status */ 246 ar_outl(0x8000, M32R_DMAEDET_PORTL); /* clear status */
246} 247}
247 248
248static inline void wait_for_vertical_sync(int exp_line) 249static void wait_for_vertical_sync(struct ar *ar, int exp_line)
249{ 250{
250#if CHECK_LOST 251#if CHECK_LOST
251 int tmout = 10000; /* FIXME */ 252 int tmout = 10000; /* FIXME */
@@ -260,7 +261,7 @@ static inline void wait_for_vertical_sync(int exp_line)
260 break; 261 break;
261 } 262 }
262 if (tmout < 0) 263 if (tmout < 0)
263 printk("arv: lost %d -> %d\n", exp_line, l); 264 v4l2_err(&ar->v4l2_dev, "lost %d -> %d\n", exp_line, l);
264#else 265#else
265 while (ar_inl(ARVHCOUNT) != exp_line) 266 while (ar_inl(ARVHCOUNT) != exp_line)
266 cpu_relax(); 267 cpu_relax();
@@ -269,15 +270,14 @@ static inline void wait_for_vertical_sync(int exp_line)
269 270
270static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos) 271static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
271{ 272{
272 struct video_device *v = video_devdata(file); 273 struct ar *ar = video_drvdata(file);
273 struct ar_device *ar = video_get_drvdata(v);
274 long ret = ar->frame_bytes; /* return read bytes */ 274 long ret = ar->frame_bytes; /* return read bytes */
275 unsigned long arvcr1 = 0; 275 unsigned long arvcr1 = 0;
276 unsigned long flags; 276 unsigned long flags;
277 unsigned char *p; 277 unsigned char *p;
278 int h, w; 278 int h, w;
279 unsigned char *py, *pu, *pv; 279 unsigned char *py, *pu, *pv;
280#if ! USE_INT 280#if !USE_INT
281 int l; 281 int l;
282#endif 282#endif
283 283
@@ -305,7 +305,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
305 ar_outl(ar->line_bytes, M32R_DMA0RBCUT_PORTL); /* reload count (bytes) */ 305 ar_outl(ar->line_bytes, M32R_DMA0RBCUT_PORTL); /* reload count (bytes) */
306 306
307 /* 307 /*
308 * Okey , kicks AR LSI to invoke an interrupt 308 * Okay, kick AR LSI to invoke an interrupt
309 */ 309 */
310 ar->start_capture = 0; 310 ar->start_capture = 0;
311 ar_outl(arvcr1 | ARVCR1_HIEN, ARVCR1); 311 ar_outl(arvcr1 | ARVCR1_HIEN, ARVCR1);
@@ -313,7 +313,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
313 /* .... AR interrupts .... */ 313 /* .... AR interrupts .... */
314 interruptible_sleep_on(&ar->wait); 314 interruptible_sleep_on(&ar->wait);
315 if (signal_pending(current)) { 315 if (signal_pending(current)) {
316 printk("arv: interrupted while get frame data.\n"); 316 printk(KERN_ERR "arv: interrupted while get frame data.\n");
317 ret = -EINTR; 317 ret = -EINTR;
318 goto out_up; 318 goto out_up;
319 } 319 }
@@ -334,7 +334,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
334 cpu_relax(); 334 cpu_relax();
335 if (ar->mode == AR_MODE_INTERLACE && ar->size == AR_SIZE_VGA) { 335 if (ar->mode == AR_MODE_INTERLACE && ar->size == AR_SIZE_VGA) {
336 for (h = 0; h < ar->height; h++) { 336 for (h = 0; h < ar->height; h++) {
337 wait_for_vertical_sync(h); 337 wait_for_vertical_sync(ar, h);
338 if (h < (AR_HEIGHT_VGA/2)) 338 if (h < (AR_HEIGHT_VGA/2))
339 l = h << 1; 339 l = h << 1;
340 else 340 else
@@ -349,7 +349,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
349 } 349 }
350 } else { 350 } else {
351 for (h = 0; h < ar->height; h++) { 351 for (h = 0; h < ar->height; h++) {
352 wait_for_vertical_sync(h); 352 wait_for_vertical_sync(ar, h);
353 ar_outl(virt_to_phys(ar->frame[h]), M32R_DMA0CDA_PORTL); 353 ar_outl(virt_to_phys(ar->frame[h]), M32R_DMA0CDA_PORTL);
354 enable_dma(); 354 enable_dma();
355 while (!(ar_inl(M32R_DMAEDET_PORTL) & 0x8000)) 355 while (!(ar_inl(M32R_DMAEDET_PORTL) & 0x8000))
@@ -386,7 +386,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
386 } 386 }
387 } 387 }
388 if (copy_to_user(buf, yuv, ar->frame_bytes)) { 388 if (copy_to_user(buf, yuv, ar->frame_bytes)) {
389 printk("arv: failed while copy_to_user yuv.\n"); 389 v4l2_err(&ar->v4l2_dev, "failed while copy_to_user yuv.\n");
390 ret = -EFAULT; 390 ret = -EFAULT;
391 goto out_up; 391 goto out_up;
392 } 392 }
@@ -396,153 +396,127 @@ out_up:
396 return ret; 396 return ret;
397} 397}
398 398
399static long ar_do_ioctl(struct file *file, unsigned int cmd, void *arg) 399static int ar_querycap(struct file *file, void *priv,
400 struct v4l2_capability *vcap)
400{ 401{
401 struct video_device *dev = video_devdata(file); 402 struct ar *ar = video_drvdata(file);
402 struct ar_device *ar = video_get_drvdata(dev); 403
403 404 strlcpy(vcap->driver, ar->vdev.name, sizeof(vcap->driver));
404 DEBUG(1, "ar_ioctl()\n"); 405 strlcpy(vcap->card, "Colour AR VGA", sizeof(vcap->card));
405 switch(cmd) { 406 strlcpy(vcap->bus_info, "Platform", sizeof(vcap->bus_info));
406 case VIDIOCGCAP: 407 vcap->version = KERNEL_VERSION(0, 0, 4);
407 { 408 vcap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
408 struct video_capability *b = arg; 409 return 0;
409 DEBUG(1, "VIDIOCGCAP:\n"); 410}
410 strcpy(b->name, ar->vdev->name); 411
411 b->type = VID_TYPE_CAPTURE; 412static int ar_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
412 b->channels = 0; 413{
413 b->audios = 0; 414 if (vin->index > 0)
414 b->maxwidth = MAX_AR_WIDTH;
415 b->maxheight = MAX_AR_HEIGHT;
416 b->minwidth = MIN_AR_WIDTH;
417 b->minheight = MIN_AR_HEIGHT;
418 return 0;
419 }
420 case VIDIOCGCHAN:
421 DEBUG(1, "VIDIOCGCHAN:\n");
422 return 0;
423 case VIDIOCSCHAN:
424 DEBUG(1, "VIDIOCSCHAN:\n");
425 return 0;
426 case VIDIOCGTUNER:
427 DEBUG(1, "VIDIOCGTUNER:\n");
428 return 0;
429 case VIDIOCSTUNER:
430 DEBUG(1, "VIDIOCSTUNER:\n");
431 return 0;
432 case VIDIOCGPICT:
433 DEBUG(1, "VIDIOCGPICT:\n");
434 return 0;
435 case VIDIOCSPICT:
436 DEBUG(1, "VIDIOCSPICT:\n");
437 return 0;
438 case VIDIOCCAPTURE:
439 DEBUG(1, "VIDIOCCAPTURE:\n");
440 return -EINVAL; 415 return -EINVAL;
441 case VIDIOCGWIN: 416 strlcpy(vin->name, "Camera", sizeof(vin->name));
442 { 417 vin->type = V4L2_INPUT_TYPE_CAMERA;
443 struct video_window *w = arg; 418 vin->audioset = 0;
444 DEBUG(1, "VIDIOCGWIN:\n"); 419 vin->tuner = 0;
445 memset(w, 0, sizeof(*w)); 420 vin->std = V4L2_STD_ALL;
446 w->width = ar->width; 421 vin->status = 0;
447 w->height = ar->height; 422 return 0;
448 return 0; 423}
424
425static int ar_g_input(struct file *file, void *fh, unsigned int *inp)
426{
427 *inp = 0;
428 return 0;
429}
430
431static int ar_s_input(struct file *file, void *fh, unsigned int inp)
432{
433 return inp ? -EINVAL : 0;
434}
435
436static int ar_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
437{
438 struct ar *ar = video_drvdata(file);
439 struct v4l2_pix_format *pix = &fmt->fmt.pix;
440
441 pix->width = ar->width;
442 pix->height = ar->height;
443 pix->pixelformat = V4L2_PIX_FMT_YUV422P;
444 pix->field = (ar->mode == AR_MODE_NORMAL) ? V4L2_FIELD_NONE : V4L2_FIELD_INTERLACED;
445 pix->bytesperline = ar->width;
446 pix->sizeimage = 2 * ar->width * ar->height;
447 /* Just a guess */
448 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
449 return 0;
450}
451
452static int ar_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
453{
454 struct ar *ar = video_drvdata(file);
455 struct v4l2_pix_format *pix = &fmt->fmt.pix;
456
457 if (pix->height <= AR_HEIGHT_QVGA || pix->width <= AR_WIDTH_QVGA) {
458 pix->height = AR_HEIGHT_QVGA;
459 pix->width = AR_WIDTH_QVGA;
460 pix->field = V4L2_FIELD_INTERLACED;
461 } else {
462 pix->height = AR_HEIGHT_VGA;
463 pix->width = AR_WIDTH_VGA;
464 pix->field = vga_interlace ? V4L2_FIELD_INTERLACED : V4L2_FIELD_NONE;
449 } 465 }
450 case VIDIOCSWIN: 466 pix->pixelformat = V4L2_PIX_FMT_YUV422P;
451 { 467 pix->bytesperline = ar->width;
452 struct video_window *w = arg; 468 pix->sizeimage = 2 * ar->width * ar->height;
453 DEBUG(1, "VIDIOCSWIN:\n"); 469 /* Just a guess */
454 if ((w->width != AR_WIDTH_VGA || w->height != AR_HEIGHT_VGA) && 470 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
455 (w->width != AR_WIDTH_QVGA || w->height != AR_HEIGHT_QVGA)) 471 return 0;
456 return -EINVAL; 472}
457 473
458 mutex_lock(&ar->lock); 474static int ar_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
459 ar->width = w->width; 475{
460 ar->height = w->height; 476 struct ar *ar = video_drvdata(file);
461 if (ar->width == AR_WIDTH_VGA) { 477 struct v4l2_pix_format *pix = &fmt->fmt.pix;
462 ar->size = AR_SIZE_VGA; 478 int ret = ar_try_fmt_vid_cap(file, fh, fmt);
463 ar->frame_bytes = AR_FRAME_BYTES_VGA; 479
464 ar->line_bytes = AR_LINE_BYTES_VGA; 480 if (ret)
465 if (vga_interlace) 481 return ret;
466 ar->mode = AR_MODE_INTERLACE; 482 mutex_lock(&ar->lock);
467 else 483 ar->width = pix->width;
468 ar->mode = AR_MODE_NORMAL; 484 ar->height = pix->height;
469 } else { 485 if (ar->width == AR_WIDTH_VGA) {
470 ar->size = AR_SIZE_QVGA; 486 ar->size = AR_SIZE_VGA;
471 ar->frame_bytes = AR_FRAME_BYTES_QVGA; 487 ar->frame_bytes = AR_FRAME_BYTES_VGA;
472 ar->line_bytes = AR_LINE_BYTES_QVGA; 488 ar->line_bytes = AR_LINE_BYTES_VGA;
489 if (vga_interlace)
473 ar->mode = AR_MODE_INTERLACE; 490 ar->mode = AR_MODE_INTERLACE;
474 } 491 else
475 mutex_unlock(&ar->lock); 492 ar->mode = AR_MODE_NORMAL;
476 return 0; 493 } else {
477 } 494 ar->size = AR_SIZE_QVGA;
478 case VIDIOCGFBUF: 495 ar->frame_bytes = AR_FRAME_BYTES_QVGA;
479 DEBUG(1, "VIDIOCGFBUF:\n"); 496 ar->line_bytes = AR_LINE_BYTES_QVGA;
480 return -EINVAL; 497 ar->mode = AR_MODE_INTERLACE;
481 case VIDIOCSFBUF:
482 DEBUG(1, "VIDIOCSFBUF:\n");
483 return -EINVAL;
484 case VIDIOCKEY:
485 DEBUG(1, "VIDIOCKEY:\n");
486 return 0;
487 case VIDIOCGFREQ:
488 DEBUG(1, "VIDIOCGFREQ:\n");
489 return -EINVAL;
490 case VIDIOCSFREQ:
491 DEBUG(1, "VIDIOCSFREQ:\n");
492 return -EINVAL;
493 case VIDIOCGAUDIO:
494 DEBUG(1, "VIDIOCGAUDIO:\n");
495 return -EINVAL;
496 case VIDIOCSAUDIO:
497 DEBUG(1, "VIDIOCSAUDIO:\n");
498 return -EINVAL;
499 case VIDIOCSYNC:
500 DEBUG(1, "VIDIOCSYNC:\n");
501 return -EINVAL;
502 case VIDIOCMCAPTURE:
503 DEBUG(1, "VIDIOCMCAPTURE:\n");
504 return -EINVAL;
505 case VIDIOCGMBUF:
506 DEBUG(1, "VIDIOCGMBUF:\n");
507 return -EINVAL;
508 case VIDIOCGUNIT:
509 DEBUG(1, "VIDIOCGUNIT:\n");
510 return -EINVAL;
511 case VIDIOCGCAPTURE:
512 DEBUG(1, "VIDIOCGCAPTURE:\n");
513 return -EINVAL;
514 case VIDIOCSCAPTURE:
515 DEBUG(1, "VIDIOCSCAPTURE:\n");
516 return -EINVAL;
517 case VIDIOCSPLAYMODE:
518 DEBUG(1, "VIDIOCSPLAYMODE:\n");
519 return -EINVAL;
520 case VIDIOCSWRITEMODE:
521 DEBUG(1, "VIDIOCSWRITEMODE:\n");
522 return -EINVAL;
523 case VIDIOCGPLAYINFO:
524 DEBUG(1, "VIDIOCGPLAYINFO:\n");
525 return -EINVAL;
526 case VIDIOCSMICROCODE:
527 DEBUG(1, "VIDIOCSMICROCODE:\n");
528 return -EINVAL;
529 case VIDIOCGVBIFMT:
530 DEBUG(1, "VIDIOCGVBIFMT:\n");
531 return -EINVAL;
532 case VIDIOCSVBIFMT:
533 DEBUG(1, "VIDIOCSVBIFMT:\n");
534 return -EINVAL;
535 default:
536 DEBUG(1, "Unknown ioctl(0x%08x)\n", cmd);
537 return -ENOIOCTLCMD;
538 } 498 }
499 /* Ok we figured out what to use from our wide choice */
500 mutex_unlock(&ar->lock);
539 return 0; 501 return 0;
540} 502}
541 503
542static long ar_ioctl(struct file *file, unsigned int cmd, 504static int ar_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
543 unsigned long arg)
544{ 505{
545 return video_usercopy(file, cmd, arg, ar_do_ioctl); 506 static struct v4l2_fmtdesc formats[] = {
507 { 0, 0, 0,
508 "YUV 4:2:2 Planar", V4L2_PIX_FMT_YUV422P,
509 { 0, 0, 0, 0 }
510 },
511 };
512 enum v4l2_buf_type type = fmt->type;
513
514 if (fmt->index > 0)
515 return -EINVAL;
516
517 *fmt = formats[fmt->index];
518 fmt->type = type;
519 return 0;
546} 520}
547 521
548#if USE_INT 522#if USE_INT
@@ -551,7 +525,7 @@ static long ar_ioctl(struct file *file, unsigned int cmd,
551 */ 525 */
552static void ar_interrupt(int irq, void *dev) 526static void ar_interrupt(int irq, void *dev)
553{ 527{
554 struct ar_device *ar = dev; 528 struct ar *ar = dev;
555 unsigned int line_count; 529 unsigned int line_count;
556 unsigned int line_number; 530 unsigned int line_number;
557 unsigned int arvcr1; 531 unsigned int arvcr1;
@@ -559,11 +533,11 @@ static void ar_interrupt(int irq, void *dev)
559 line_count = ar_inl(ARVHCOUNT); /* line number */ 533 line_count = ar_inl(ARVHCOUNT); /* line number */
560 if (ar->mode == AR_MODE_INTERLACE && ar->size == AR_SIZE_VGA) { 534 if (ar->mode == AR_MODE_INTERLACE && ar->size == AR_SIZE_VGA) {
561 /* operations for interlace mode */ 535 /* operations for interlace mode */
562 if ( line_count < (AR_HEIGHT_VGA/2) ) /* even line */ 536 if (line_count < (AR_HEIGHT_VGA / 2)) /* even line */
563 line_number = (line_count << 1); 537 line_number = (line_count << 1);
564 else /* odd line */ 538 else /* odd line */
565 line_number = 539 line_number =
566 (((line_count - (AR_HEIGHT_VGA/2)) << 1) + 1); 540 (((line_count - (AR_HEIGHT_VGA / 2)) << 1) + 1);
567 } else { 541 } else {
568 line_number = line_count; 542 line_number = line_count;
569 } 543 }
@@ -623,11 +597,10 @@ static void ar_interrupt(int irq, void *dev)
623 * 0 is returned in success. 597 * 0 is returned in success.
624 * 598 *
625 */ 599 */
626static int ar_initialize(struct video_device *dev) 600static int ar_initialize(struct ar *ar)
627{ 601{
628 struct ar_device *ar = video_get_drvdata(dev);
629 unsigned long cr = 0; 602 unsigned long cr = 0;
630 int i,found=0; 603 int i, found = 0;
631 604
632 DEBUG(1, "ar_initialize:\n"); 605 DEBUG(1, "ar_initialize:\n");
633 606
@@ -666,129 +639,119 @@ static int ar_initialize(struct video_device *dev)
666 if (found == 0) 639 if (found == 0)
667 return -ENODEV; 640 return -ENODEV;
668 641
669 printk("arv: Initializing "); 642 v4l2_info(&ar->v4l2_dev, "Initializing ");
670 643
671 iic(2,0x78,0x11,0x01,0x00); /* start */ 644 iic(2, 0x78, 0x11, 0x01, 0x00); /* start */
672 iic(3,0x78,0x12,0x00,0x06); 645 iic(3, 0x78, 0x12, 0x00, 0x06);
673 iic(3,0x78,0x12,0x12,0x30); 646 iic(3, 0x78, 0x12, 0x12, 0x30);
674 iic(3,0x78,0x12,0x15,0x58); 647 iic(3, 0x78, 0x12, 0x15, 0x58);
675 iic(3,0x78,0x12,0x17,0x30); 648 iic(3, 0x78, 0x12, 0x17, 0x30);
676 printk("."); 649 printk(KERN_CONT ".");
677 iic(3,0x78,0x12,0x1a,0x97); 650 iic(3, 0x78, 0x12, 0x1a, 0x97);
678 iic(3,0x78,0x12,0x1b,0xff); 651 iic(3, 0x78, 0x12, 0x1b, 0xff);
679 iic(3,0x78,0x12,0x1c,0xff); 652 iic(3, 0x78, 0x12, 0x1c, 0xff);
680 iic(3,0x78,0x12,0x26,0x10); 653 iic(3, 0x78, 0x12, 0x26, 0x10);
681 iic(3,0x78,0x12,0x27,0x00); 654 iic(3, 0x78, 0x12, 0x27, 0x00);
682 printk("."); 655 printk(KERN_CONT ".");
683 iic(2,0x78,0x34,0x02,0x00); 656 iic(2, 0x78, 0x34, 0x02, 0x00);
684 iic(2,0x78,0x7a,0x10,0x00); 657 iic(2, 0x78, 0x7a, 0x10, 0x00);
685 iic(2,0x78,0x80,0x39,0x00); 658 iic(2, 0x78, 0x80, 0x39, 0x00);
686 iic(2,0x78,0x81,0xe6,0x00); 659 iic(2, 0x78, 0x81, 0xe6, 0x00);
687 iic(2,0x78,0x8d,0x00,0x00); 660 iic(2, 0x78, 0x8d, 0x00, 0x00);
688 printk("."); 661 printk(KERN_CONT ".");
689 iic(2,0x78,0x8e,0x0c,0x00); 662 iic(2, 0x78, 0x8e, 0x0c, 0x00);
690 iic(2,0x78,0x8f,0x00,0x00); 663 iic(2, 0x78, 0x8f, 0x00, 0x00);
691#if 0 664#if 0
692 iic(2,0x78,0x90,0x00,0x00); /* AWB on=1 off=0 */ 665 iic(2, 0x78, 0x90, 0x00, 0x00); /* AWB on=1 off=0 */
693#endif 666#endif
694 iic(2,0x78,0x93,0x01,0x00); 667 iic(2, 0x78, 0x93, 0x01, 0x00);
695 iic(2,0x78,0x94,0xcd,0x00); 668 iic(2, 0x78, 0x94, 0xcd, 0x00);
696 iic(2,0x78,0x95,0x00,0x00); 669 iic(2, 0x78, 0x95, 0x00, 0x00);
697 printk("."); 670 printk(KERN_CONT ".");
698 iic(2,0x78,0x96,0xa0,0x00); 671 iic(2, 0x78, 0x96, 0xa0, 0x00);
699 iic(2,0x78,0x97,0x00,0x00); 672 iic(2, 0x78, 0x97, 0x00, 0x00);
700 iic(2,0x78,0x98,0x60,0x00); 673 iic(2, 0x78, 0x98, 0x60, 0x00);
701 iic(2,0x78,0x99,0x01,0x00); 674 iic(2, 0x78, 0x99, 0x01, 0x00);
702 iic(2,0x78,0x9a,0x19,0x00); 675 iic(2, 0x78, 0x9a, 0x19, 0x00);
703 printk("."); 676 printk(KERN_CONT ".");
704 iic(2,0x78,0x9b,0x02,0x00); 677 iic(2, 0x78, 0x9b, 0x02, 0x00);
705 iic(2,0x78,0x9c,0xe8,0x00); 678 iic(2, 0x78, 0x9c, 0xe8, 0x00);
706 iic(2,0x78,0x9d,0x02,0x00); 679 iic(2, 0x78, 0x9d, 0x02, 0x00);
707 iic(2,0x78,0x9e,0x2e,0x00); 680 iic(2, 0x78, 0x9e, 0x2e, 0x00);
708 iic(2,0x78,0xb8,0x78,0x00); 681 iic(2, 0x78, 0xb8, 0x78, 0x00);
709 iic(2,0x78,0xba,0x05,0x00); 682 iic(2, 0x78, 0xba, 0x05, 0x00);
710#if 0 683#if 0
711 iic(2,0x78,0x83,0x8c,0x00); /* brightness */ 684 iic(2, 0x78, 0x83, 0x8c, 0x00); /* brightness */
712#endif 685#endif
713 printk("."); 686 printk(KERN_CONT ".");
714 687
715 /* color correction */ 688 /* color correction */
716 iic(3,0x78,0x49,0x00,0x95); /* a */ 689 iic(3, 0x78, 0x49, 0x00, 0x95); /* a */
717 iic(3,0x78,0x49,0x01,0x96); /* b */ 690 iic(3, 0x78, 0x49, 0x01, 0x96); /* b */
718 iic(3,0x78,0x49,0x03,0x85); /* c */ 691 iic(3, 0x78, 0x49, 0x03, 0x85); /* c */
719 iic(3,0x78,0x49,0x04,0x97); /* d */ 692 iic(3, 0x78, 0x49, 0x04, 0x97); /* d */
720 iic(3,0x78,0x49,0x02,0x7e); /* e(Lo) */ 693 iic(3, 0x78, 0x49, 0x02, 0x7e); /* e(Lo) */
721 iic(3,0x78,0x49,0x05,0xa4); /* f(Lo) */ 694 iic(3, 0x78, 0x49, 0x05, 0xa4); /* f(Lo) */
722 iic(3,0x78,0x49,0x06,0x04); /* e(Hi) */ 695 iic(3, 0x78, 0x49, 0x06, 0x04); /* e(Hi) */
723 iic(3,0x78,0x49,0x07,0x04); /* e(Hi) */ 696 iic(3, 0x78, 0x49, 0x07, 0x04); /* e(Hi) */
724 iic(2,0x78,0x48,0x01,0x00); /* on=1 off=0 */ 697 iic(2, 0x78, 0x48, 0x01, 0x00); /* on=1 off=0 */
725 698
726 printk("."); 699 printk(KERN_CONT ".");
727 iic(2,0x78,0x11,0x00,0x00); /* end */ 700 iic(2, 0x78, 0x11, 0x00, 0x00); /* end */
728 printk(" done\n"); 701 printk(KERN_CONT " done\n");
729 return 0; 702 return 0;
730} 703}
731 704
732 705
733void ar_release(struct video_device *vfd)
734{
735 struct ar_device *ar = video_get_drvdata(vfd);
736 mutex_lock(&ar->lock);
737 video_device_release(vfd);
738}
739
740/**************************************************************************** 706/****************************************************************************
741 * 707 *
742 * Video4Linux Module functions 708 * Video4Linux Module functions
743 * 709 *
744 ****************************************************************************/ 710 ****************************************************************************/
745static struct ar_device ardev;
746
747static int ar_exclusive_open(struct file *file)
748{
749 return test_and_set_bit(0, &ardev.in_use) ? -EBUSY : 0;
750}
751
752static int ar_exclusive_release(struct file *file)
753{
754 clear_bit(0, &ardev.in_use);
755 return 0;
756}
757 711
758static const struct v4l2_file_operations ar_fops = { 712static const struct v4l2_file_operations ar_fops = {
759 .owner = THIS_MODULE, 713 .owner = THIS_MODULE,
760 .open = ar_exclusive_open,
761 .release = ar_exclusive_release,
762 .read = ar_read, 714 .read = ar_read,
763 .ioctl = ar_ioctl, 715 .ioctl = video_ioctl2,
764}; 716};
765 717
766static struct video_device ar_template = { 718static const struct v4l2_ioctl_ops ar_ioctl_ops = {
767 .name = "Colour AR VGA", 719 .vidioc_querycap = ar_querycap,
768 .fops = &ar_fops, 720 .vidioc_g_input = ar_g_input,
769 .release = ar_release, 721 .vidioc_s_input = ar_s_input,
722 .vidioc_enum_input = ar_enum_input,
723 .vidioc_enum_fmt_vid_cap = ar_enum_fmt_vid_cap,
724 .vidioc_g_fmt_vid_cap = ar_g_fmt_vid_cap,
725 .vidioc_s_fmt_vid_cap = ar_s_fmt_vid_cap,
726 .vidioc_try_fmt_vid_cap = ar_try_fmt_vid_cap,
770}; 727};
771 728
772#define ALIGN4(x) ((((int)(x)) & 0x3) == 0) 729#define ALIGN4(x) ((((int)(x)) & 0x3) == 0)
773 730
774static int __init ar_init(void) 731static int __init ar_init(void)
775{ 732{
776 struct ar_device *ar; 733 struct ar *ar;
734 struct v4l2_device *v4l2_dev;
777 int ret; 735 int ret;
778 int i; 736 int i;
779 737
780 DEBUG(1, "ar_init:\n");
781 ret = -EIO;
782 printk(KERN_INFO "arv: Colour AR VGA driver %s\n", VERSION);
783
784 ar = &ardev; 738 ar = &ardev;
785 memset(ar, 0, sizeof(struct ar_device)); 739 v4l2_dev = &ar->v4l2_dev;
740 strlcpy(v4l2_dev->name, "arv", sizeof(v4l2_dev->name));
741 v4l2_info(v4l2_dev, "Colour AR VGA driver %s\n", VERSION);
742
743 ret = v4l2_device_register(NULL, v4l2_dev);
744 if (ret < 0) {
745 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
746 return ret;
747 }
748 ret = -EIO;
786 749
787#if USE_INT 750#if USE_INT
788 /* allocate a DMA buffer for 1 line. */ 751 /* allocate a DMA buffer for 1 line. */
789 ar->line_buff = kmalloc(MAX_AR_LINE_BYTES, GFP_KERNEL | GFP_DMA); 752 ar->line_buff = kmalloc(MAX_AR_LINE_BYTES, GFP_KERNEL | GFP_DMA);
790 if (ar->line_buff == NULL || ! ALIGN4(ar->line_buff)) { 753 if (ar->line_buff == NULL || !ALIGN4(ar->line_buff)) {
791 printk("arv: buffer allocation failed for DMA.\n"); 754 v4l2_err(v4l2_dev, "buffer allocation failed for DMA.\n");
792 ret = -ENOMEM; 755 ret = -ENOMEM;
793 goto out_end; 756 goto out_end;
794 } 757 }
@@ -796,20 +759,19 @@ static int __init ar_init(void)
796 /* allocate buffers for a frame */ 759 /* allocate buffers for a frame */
797 for (i = 0; i < MAX_AR_HEIGHT; i++) { 760 for (i = 0; i < MAX_AR_HEIGHT; i++) {
798 ar->frame[i] = kmalloc(MAX_AR_LINE_BYTES, GFP_KERNEL); 761 ar->frame[i] = kmalloc(MAX_AR_LINE_BYTES, GFP_KERNEL);
799 if (ar->frame[i] == NULL || ! ALIGN4(ar->frame[i])) { 762 if (ar->frame[i] == NULL || !ALIGN4(ar->frame[i])) {
800 printk("arv: buffer allocation failed for frame.\n"); 763 v4l2_err(v4l2_dev, "buffer allocation failed for frame.\n");
801 ret = -ENOMEM; 764 ret = -ENOMEM;
802 goto out_line_buff; 765 goto out_line_buff;
803 } 766 }
804 } 767 }
805 768
806 ar->vdev = video_device_alloc(); 769 strlcpy(ar->vdev.name, "Colour AR VGA", sizeof(ar->vdev.name));
807 if (!ar->vdev) { 770 ar->vdev.v4l2_dev = v4l2_dev;
808 printk(KERN_ERR "arv: video_device_alloc() failed\n"); 771 ar->vdev.fops = &ar_fops;
809 return -ENOMEM; 772 ar->vdev.ioctl_ops = &ar_ioctl_ops;
810 } 773 ar->vdev.release = video_device_release_empty;
811 memcpy(ar->vdev, &ar_template, sizeof(ar_template)); 774 video_set_drvdata(&ar->vdev, ar);
812 video_set_drvdata(ar->vdev, ar);
813 775
814 if (vga) { 776 if (vga) {
815 ar->width = AR_WIDTH_VGA; 777 ar->width = AR_WIDTH_VGA;
@@ -834,14 +796,14 @@ static int __init ar_init(void)
834 796
835#if USE_INT 797#if USE_INT
836 if (request_irq(M32R_IRQ_INT3, ar_interrupt, 0, "arv", ar)) { 798 if (request_irq(M32R_IRQ_INT3, ar_interrupt, 0, "arv", ar)) {
837 printk("arv: request_irq(%d) failed.\n", M32R_IRQ_INT3); 799 v4l2_err("request_irq(%d) failed.\n", M32R_IRQ_INT3);
838 ret = -EIO; 800 ret = -EIO;
839 goto out_irq; 801 goto out_irq;
840 } 802 }
841#endif 803#endif
842 804
843 if (ar_initialize(ar->vdev) != 0) { 805 if (ar_initialize(ar) != 0) {
844 printk("arv: M64278 not found.\n"); 806 v4l2_err(v4l2_dev, "M64278 not found.\n");
845 ret = -ENODEV; 807 ret = -ENODEV;
846 goto out_dev; 808 goto out_dev;
847 } 809 }
@@ -852,15 +814,15 @@ static int __init ar_init(void)
852 * device is named "video[0-64]". 814 * device is named "video[0-64]".
853 * video_register_device() initializes h/w using ar_initialize(). 815 * video_register_device() initializes h/w using ar_initialize().
854 */ 816 */
855 if (video_register_device(ar->vdev, VFL_TYPE_GRABBER, video_nr) != 0) { 817 if (video_register_device(&ar->vdev, VFL_TYPE_GRABBER, video_nr) != 0) {
856 /* return -1, -ENFILE(full) or others */ 818 /* return -1, -ENFILE(full) or others */
857 printk("arv: register video (Colour AR) failed.\n"); 819 v4l2_err(v4l2_dev, "register video (Colour AR) failed.\n");
858 ret = -ENODEV; 820 ret = -ENODEV;
859 goto out_dev; 821 goto out_dev;
860 } 822 }
861 823
862 printk("%s: Found M64278 VGA (IRQ %d, Freq %dMHz).\n", 824 v4l2_info(v4l2_dev, "%s: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
863 video_device_node_name(ar->vdev), M32R_IRQ_INT3, freq); 825 video_device_node_name(&ar->vdev), M32R_IRQ_INT3, freq);
864 826
865 return 0; 827 return 0;
866 828
@@ -879,6 +841,7 @@ out_line_buff:
879 841
880out_end: 842out_end:
881#endif 843#endif
844 v4l2_device_unregister(&ar->v4l2_dev);
882 return ret; 845 return ret;
883} 846}
884 847
@@ -886,7 +849,7 @@ out_end:
886static int __init ar_init_module(void) 849static int __init ar_init_module(void)
887{ 850{
888 freq = (boot_cpu_data.bus_clock / 1000000); 851 freq = (boot_cpu_data.bus_clock / 1000000);
889 printk("arv: Bus clock %d\n", freq); 852 printk(KERN_INFO "arv: Bus clock %d\n", freq);
890 if (freq != 50 && freq != 75) 853 if (freq != 50 && freq != 75)
891 freq = DEFAULT_FREQ; 854 freq = DEFAULT_FREQ;
892 return ar_init(); 855 return ar_init();
@@ -894,11 +857,11 @@ static int __init ar_init_module(void)
894 857
895static void __exit ar_cleanup_module(void) 858static void __exit ar_cleanup_module(void)
896{ 859{
897 struct ar_device *ar; 860 struct ar *ar;
898 int i; 861 int i;
899 862
900 ar = &ardev; 863 ar = &ardev;
901 video_unregister_device(ar->vdev); 864 video_unregister_device(&ar->vdev);
902#if USE_INT 865#if USE_INT
903 free_irq(M32R_IRQ_INT3, ar); 866 free_irq(M32R_IRQ_INT3, ar);
904#endif 867#endif
@@ -907,6 +870,7 @@ static void __exit ar_cleanup_module(void)
907#if USE_INT 870#if USE_INT
908 kfree(ar->line_buff); 871 kfree(ar->line_buff);
909#endif 872#endif
873 v4l2_device_unregister(&ar->v4l2_dev);
910} 874}
911 875
912module_init(ar_init_module); 876module_init(ar_init_module);