2 * Colour AR M64278(VGA) driver for Video4Linux
4 * Copyright (C) 2003 Takeo Takahashi <takahashi.takeo@renesas.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Some code is taken from AR driver sample program for M3T-M32700UT.
13 * AR driver sample (M32R SDK):
14 * Copyright (c) 2003 RENESAS TECHNOROGY CORPORATION
15 * AND RENESAS SOLUTIONS CORPORATION
16 * All Rights Reserved.
18 * 2003-09-01: Support w3cam by Takeo Takahashi
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/delay.h>
24 #include <linux/errno.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
29 #include <linux/sched.h>
30 #include <linux/version.h>
31 #include <linux/videodev2.h>
32 #include <media/v4l2-common.h>
33 #include <media/v4l2-device.h>
34 #include <media/v4l2-ioctl.h>
35 #include <linux/mutex.h>
37 #include <asm/uaccess.h>
41 #include <asm/byteorder.h>
43 #define DEBUG(n, args...)
47 * USE_INT is always 0, interrupt mode is not available
48 * on linux due to lack of speed
50 #define USE_INT 0 /* Don't modify */
52 #define VERSION "0.04"
54 #define ar_inl(addr) inl((unsigned long)(addr))
55 #define ar_outl(val, addr) outl((unsigned long)(val), (unsigned long)(addr))
57 extern struct cpuinfo_m32r boot_cpu_data
;
61 * Note that M32700UT does not support CIF mode, but QVGA is
62 * supported by M32700UT hardware using VGA mode of AR LSI.
64 * Supported: VGA (Normal mode, Interlace mode)
65 * QVGA (Always Interlace mode of VGA)
68 #define AR_WIDTH_VGA 640
69 #define AR_HEIGHT_VGA 480
70 #define AR_WIDTH_QVGA 320
71 #define AR_HEIGHT_QVGA 240
72 #define MIN_AR_WIDTH AR_WIDTH_QVGA
73 #define MIN_AR_HEIGHT AR_HEIGHT_QVGA
74 #define MAX_AR_WIDTH AR_WIDTH_VGA
75 #define MAX_AR_HEIGHT AR_HEIGHT_VGA
77 /* bits & bytes per pixel */
78 #define AR_BITS_PER_PIXEL 16
79 #define AR_BYTES_PER_PIXEL (AR_BITS_PER_PIXEL / 8)
81 /* line buffer size */
82 #define AR_LINE_BYTES_VGA (AR_WIDTH_VGA * AR_BYTES_PER_PIXEL)
83 #define AR_LINE_BYTES_QVGA (AR_WIDTH_QVGA * AR_BYTES_PER_PIXEL)
84 #define MAX_AR_LINE_BYTES AR_LINE_BYTES_VGA
86 /* frame size & type */
87 #define AR_FRAME_BYTES_VGA \
88 (AR_WIDTH_VGA * AR_HEIGHT_VGA * AR_BYTES_PER_PIXEL)
89 #define AR_FRAME_BYTES_QVGA \
90 (AR_WIDTH_QVGA * AR_HEIGHT_QVGA * AR_BYTES_PER_PIXEL)
91 #define MAX_AR_FRAME_BYTES \
92 (MAX_AR_WIDTH * MAX_AR_HEIGHT * AR_BYTES_PER_PIXEL)
94 #define AR_MAX_FRAME 15
98 #define AR_SIZE_QVGA 1
101 #define AR_MODE_INTERLACE 0
102 #define AR_MODE_NORMAL 1
105 struct v4l2_device v4l2_dev
;
106 struct video_device vdev
;
107 unsigned int start_capture
; /* duaring capture in INT. mode. */
109 unsigned char *line_buff
; /* DMA line buffer */
111 unsigned char *frame
[MAX_AR_HEIGHT
]; /* frame data */
112 short size
; /* capture size */
113 short mode
; /* capture mode */
115 int frame_bytes
, line_bytes
;
116 wait_queue_head_t wait
;
120 static struct ar ardev
;
122 static int video_nr
= -1; /* video device number (first free) */
123 static unsigned char yuv
[MAX_AR_FRAME_BYTES
];
125 /* module parameters */
126 /* default frequency */
127 #define DEFAULT_FREQ 50 /* 50 or 75 (MHz) is available as BCLK */
128 static int freq
= DEFAULT_FREQ
; /* BCLK: available 50 or 70 (MHz) */
129 static int vga
; /* default mode(0:QVGA mode, other:VGA mode) */
130 static int vga_interlace
; /* 0 is normal mode for, else interlace mode */
131 module_param(freq
, int, 0);
132 module_param(vga
, int, 0);
133 module_param(vga_interlace
, int, 0);
135 static void wait_for_vsync(void)
137 while (ar_inl(ARVCR0
) & ARVCR0_VDS
) /* wait for VSYNC */
139 while (!(ar_inl(ARVCR0
) & ARVCR0_VDS
)) /* wait for VSYNC */
143 static void wait_acknowledge(void)
147 for (i
= 0; i
< 1000; i
++)
149 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_NOACK
)
153 /*******************************************************************
155 *******************************************************************/
156 static void iic(int n
, unsigned long addr
, unsigned long data1
, unsigned long data2
,
162 ar_outl(addr
, PLDI2CDATA
);
166 ar_outl(1, PLDI2CCND
);
169 /* Transfer data 1 */
170 ar_outl(data1
, PLDI2CDATA
);
172 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
175 /* Transfer data 2 */
176 ar_outl(data2
, PLDI2CDATA
);
178 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
182 /* Transfer data 3 */
183 ar_outl(data3
, PLDI2CDATA
);
185 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
190 for (i
= 0; i
< 100; i
++)
192 ar_outl(2, PLDI2CCND
);
193 ar_outl(2, PLDI2CCND
);
195 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_BB
)
200 static void init_iic(void)
202 DEBUG(1, "init_iic:\n");
208 ar_outl(0x0, PLDI2CCR
); /* I2CCR Disable */
209 ar_outl(0x0300, PLDI2CMOD
); /* I2CMOD ACK/8b-data/7b-addr/auto */
210 ar_outl(0x1, PLDI2CACK
); /* I2CACK ACK */
215 ar_outl(369, PLDI2CFREQ
); /* BCLK = 75MHz */
217 ar_outl(244, PLDI2CFREQ
); /* BCLK = 50MHz */
219 ar_outl(244, PLDI2CFREQ
); /* default: BCLK = 50MHz */
220 ar_outl(0x1, PLDI2CCR
); /* I2CCR Enable */
223 /**************************************************************************
225 * Video4Linux Interface functions
227 **************************************************************************/
229 static inline void disable_dma(void)
231 ar_outl(0x8000, M32R_DMAEN_PORTL
); /* disable DMA0 */
234 static inline void enable_dma(void)
236 ar_outl(0x8080, M32R_DMAEN_PORTL
); /* enable DMA0 */
239 static inline void clear_dma_status(void)
241 ar_outl(0x8000, M32R_DMAEDET_PORTL
); /* clear status */
244 static void wait_for_vertical_sync(struct ar
*ar
, int exp_line
)
251 * check HCOUNT because we cannot check vertical sync.
253 for (; tmout
>= 0; tmout
--) {
254 l
= ar_inl(ARVHCOUNT
);
259 v4l2_err(&ar
->v4l2_dev
, "lost %d -> %d\n", exp_line
, l
);
261 while (ar_inl(ARVHCOUNT
) != exp_line
)
266 static ssize_t
ar_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
268 struct ar
*ar
= video_drvdata(file
);
269 long ret
= ar
->frame_bytes
; /* return read bytes */
270 unsigned long arvcr1
= 0;
274 unsigned char *py
, *pu
, *pv
;
279 DEBUG(1, "ar_read()\n");
281 if (ar
->size
== AR_SIZE_QVGA
)
282 arvcr1
|= ARVCR1_QVGA
;
283 if (ar
->mode
== AR_MODE_NORMAL
)
284 arvcr1
|= ARVCR1_NORMAL
;
286 mutex_lock(&ar
->lock
);
289 local_irq_save(flags
);
291 ar_outl(0xa1871300, M32R_DMA0CR0_PORTL
);
292 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
294 /* set AR FIFO address as source(BSEL5) */
295 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
296 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
297 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* destination addr. */
298 ar_outl(ar
->line_buff
, M32R_DMA0RDA_PORTL
); /* reload address */
299 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
); /* byte count (bytes) */
300 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
); /* reload count (bytes) */
303 * Okay, kick AR LSI to invoke an interrupt
305 ar
->start_capture
= 0;
306 ar_outl(arvcr1
| ARVCR1_HIEN
, ARVCR1
);
307 local_irq_restore(flags
);
308 /* .... AR interrupts .... */
309 interruptible_sleep_on(&ar
->wait
);
310 if (signal_pending(current
)) {
311 printk(KERN_ERR
"arv: interrupted while get frame data.\n");
315 #else /* ! USE_INT */
317 ar_outl(arvcr1
, ARVCR1
);
319 ar_outl(0x8000, M32R_DMAEDET_PORTL
);
320 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
321 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
322 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
323 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
324 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
);
325 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
);
327 local_irq_save(flags
);
328 while (ar_inl(ARVHCOUNT
) != 0) /* wait for 0 */
330 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
331 for (h
= 0; h
< ar
->height
; h
++) {
332 wait_for_vertical_sync(ar
, h
);
333 if (h
< (AR_HEIGHT_VGA
/2))
336 l
= (((h
- (AR_HEIGHT_VGA
/2)) << 1) + 1);
337 ar_outl(virt_to_phys(ar
->frame
[l
]), M32R_DMA0CDA_PORTL
);
339 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
343 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
346 for (h
= 0; h
< ar
->height
; h
++) {
347 wait_for_vertical_sync(ar
, h
);
348 ar_outl(virt_to_phys(ar
->frame
[h
]), M32R_DMA0CDA_PORTL
);
350 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
354 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
357 local_irq_restore(flags
);
358 #endif /* ! USE_INT */
361 * convert YUV422 to YUV422P
362 * +--------------------+
364 * | ..............Yn |
365 * +--------------------+
366 * | U0,U1,........Un |
367 * +--------------------+
368 * | V0,V1,........Vn |
369 * +--------------------+
372 pu
= py
+ (ar
->frame_bytes
/ 2);
373 pv
= pu
+ (ar
->frame_bytes
/ 4);
374 for (h
= 0; h
< ar
->height
; h
++) {
376 for (w
= 0; w
< ar
->line_bytes
; w
+= 4) {
383 if (copy_to_user(buf
, yuv
, ar
->frame_bytes
)) {
384 v4l2_err(&ar
->v4l2_dev
, "failed while copy_to_user yuv.\n");
388 DEBUG(1, "ret = %d\n", ret
);
390 mutex_unlock(&ar
->lock
);
394 static int ar_querycap(struct file
*file
, void *priv
,
395 struct v4l2_capability
*vcap
)
397 struct ar
*ar
= video_drvdata(file
);
399 strlcpy(vcap
->driver
, ar
->vdev
.name
, sizeof(vcap
->driver
));
400 strlcpy(vcap
->card
, "Colour AR VGA", sizeof(vcap
->card
));
401 strlcpy(vcap
->bus_info
, "Platform", sizeof(vcap
->bus_info
));
402 vcap
->version
= KERNEL_VERSION(0, 0, 4);
403 vcap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_READWRITE
;
407 static int ar_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*vin
)
411 strlcpy(vin
->name
, "Camera", sizeof(vin
->name
));
412 vin
->type
= V4L2_INPUT_TYPE_CAMERA
;
415 vin
->std
= V4L2_STD_ALL
;
420 static int ar_g_input(struct file
*file
, void *fh
, unsigned int *inp
)
426 static int ar_s_input(struct file
*file
, void *fh
, unsigned int inp
)
428 return inp
? -EINVAL
: 0;
431 static int ar_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
433 struct ar
*ar
= video_drvdata(file
);
434 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
436 pix
->width
= ar
->width
;
437 pix
->height
= ar
->height
;
438 pix
->pixelformat
= V4L2_PIX_FMT_YUV422P
;
439 pix
->field
= (ar
->mode
== AR_MODE_NORMAL
) ? V4L2_FIELD_NONE
: V4L2_FIELD_INTERLACED
;
440 pix
->bytesperline
= ar
->width
;
441 pix
->sizeimage
= 2 * ar
->width
* ar
->height
;
443 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
447 static int ar_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
449 struct ar
*ar
= video_drvdata(file
);
450 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
452 if (pix
->height
<= AR_HEIGHT_QVGA
|| pix
->width
<= AR_WIDTH_QVGA
) {
453 pix
->height
= AR_HEIGHT_QVGA
;
454 pix
->width
= AR_WIDTH_QVGA
;
455 pix
->field
= V4L2_FIELD_INTERLACED
;
457 pix
->height
= AR_HEIGHT_VGA
;
458 pix
->width
= AR_WIDTH_VGA
;
459 pix
->field
= vga_interlace
? V4L2_FIELD_INTERLACED
: V4L2_FIELD_NONE
;
461 pix
->pixelformat
= V4L2_PIX_FMT_YUV422P
;
462 pix
->bytesperline
= ar
->width
;
463 pix
->sizeimage
= 2 * ar
->width
* ar
->height
;
465 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
469 static int ar_s_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
471 struct ar
*ar
= video_drvdata(file
);
472 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
473 int ret
= ar_try_fmt_vid_cap(file
, fh
, fmt
);
477 mutex_lock(&ar
->lock
);
478 ar
->width
= pix
->width
;
479 ar
->height
= pix
->height
;
480 if (ar
->width
== AR_WIDTH_VGA
) {
481 ar
->size
= AR_SIZE_VGA
;
482 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
483 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
485 ar
->mode
= AR_MODE_INTERLACE
;
487 ar
->mode
= AR_MODE_NORMAL
;
489 ar
->size
= AR_SIZE_QVGA
;
490 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
491 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
492 ar
->mode
= AR_MODE_INTERLACE
;
494 /* Ok we figured out what to use from our wide choice */
495 mutex_unlock(&ar
->lock
);
499 static int ar_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
501 static struct v4l2_fmtdesc formats
[] = {
503 "YUV 4:2:2 Planar", V4L2_PIX_FMT_YUV422P
,
507 enum v4l2_buf_type type
= fmt
->type
;
512 *fmt
= formats
[fmt
->index
];
521 static void ar_interrupt(int irq
, void *dev
)
524 unsigned int line_count
;
525 unsigned int line_number
;
528 line_count
= ar_inl(ARVHCOUNT
); /* line number */
529 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
530 /* operations for interlace mode */
531 if (line_count
< (AR_HEIGHT_VGA
/ 2)) /* even line */
532 line_number
= (line_count
<< 1);
535 (((line_count
- (AR_HEIGHT_VGA
/ 2)) << 1) + 1);
537 line_number
= line_count
;
540 if (line_number
== 0) {
542 * It is an interrupt for line 0.
543 * we have to start capture.
546 memcpy(ar
->frame
[0], ar
->line_buff
, ar
->line_bytes
);
548 ar
->start_capture
= 1; /* during capture */
552 if (ar
->start_capture
== 1 && line_number
<= (ar
->height
- 1)) {
554 memcpy(ar
->frame
[line_number
], ar
->line_buff
, ar
->line_bytes
);
557 * if captured all line of a frame, disable AR interrupt
558 * and wake a process up.
560 if (line_number
== (ar
->height
- 1)) { /* end of line */
562 ar
->start_capture
= 0;
564 /* disable AR interrupt request */
565 arvcr1
= ar_inl(ARVCR1
);
566 arvcr1
&= ~ARVCR1_HIEN
; /* clear int. flag */
567 ar_outl(arvcr1
, ARVCR1
); /* disable */
568 wake_up_interruptible(&ar
->wait
);
578 * ar_initialize() is called by video_register_device() and
579 * initializes AR LSI and peripherals.
581 * -1 is returned in all failures.
582 * 0 is returned in success.
585 static int ar_initialize(struct ar
*ar
)
587 unsigned long cr
= 0;
590 DEBUG(1, "ar_initialize:\n");
595 ar_outl(0, ARVCR0
); /* assert reset of AR LSI */
596 for (i
= 0; i
< 0x18; i
++) /* wait for over 10 cycles @ 27MHz */
598 ar_outl(ARVCR0_RST
, ARVCR0
); /* negate reset of AR LSI (enable) */
599 for (i
= 0; i
< 0x40d; i
++) /* wait for over 420 cycles @ 27MHz */
602 /* AR uses INT3 of CPU as interrupt pin. */
603 ar_outl(ARINTSEL_INT3
, ARINTSEL
);
605 if (ar
->size
== AR_SIZE_QVGA
)
607 if (ar
->mode
== AR_MODE_NORMAL
)
612 * Initialize IIC so that CPU can communicate with AR LSI,
613 * and send boot commands to AR LSI.
617 for (i
= 0; i
< 0x100000; i
++) { /* > 0xa1d10, 56ms */
618 if ((ar_inl(ARVCR0
) & ARVCR0_VDS
)) { /* VSYNC */
627 v4l2_info(&ar
->v4l2_dev
, "Initializing ");
629 iic(2, 0x78, 0x11, 0x01, 0x00); /* start */
630 iic(3, 0x78, 0x12, 0x00, 0x06);
631 iic(3, 0x78, 0x12, 0x12, 0x30);
632 iic(3, 0x78, 0x12, 0x15, 0x58);
633 iic(3, 0x78, 0x12, 0x17, 0x30);
634 printk(KERN_CONT
".");
635 iic(3, 0x78, 0x12, 0x1a, 0x97);
636 iic(3, 0x78, 0x12, 0x1b, 0xff);
637 iic(3, 0x78, 0x12, 0x1c, 0xff);
638 iic(3, 0x78, 0x12, 0x26, 0x10);
639 iic(3, 0x78, 0x12, 0x27, 0x00);
640 printk(KERN_CONT
".");
641 iic(2, 0x78, 0x34, 0x02, 0x00);
642 iic(2, 0x78, 0x7a, 0x10, 0x00);
643 iic(2, 0x78, 0x80, 0x39, 0x00);
644 iic(2, 0x78, 0x81, 0xe6, 0x00);
645 iic(2, 0x78, 0x8d, 0x00, 0x00);
646 printk(KERN_CONT
".");
647 iic(2, 0x78, 0x8e, 0x0c, 0x00);
648 iic(2, 0x78, 0x8f, 0x00, 0x00);
649 iic(2, 0x78, 0x93, 0x01, 0x00);
650 iic(2, 0x78, 0x94, 0xcd, 0x00);
651 iic(2, 0x78, 0x95, 0x00, 0x00);
652 printk(KERN_CONT
".");
653 iic(2, 0x78, 0x96, 0xa0, 0x00);
654 iic(2, 0x78, 0x97, 0x00, 0x00);
655 iic(2, 0x78, 0x98, 0x60, 0x00);
656 iic(2, 0x78, 0x99, 0x01, 0x00);
657 iic(2, 0x78, 0x9a, 0x19, 0x00);
658 printk(KERN_CONT
".");
659 iic(2, 0x78, 0x9b, 0x02, 0x00);
660 iic(2, 0x78, 0x9c, 0xe8, 0x00);
661 iic(2, 0x78, 0x9d, 0x02, 0x00);
662 iic(2, 0x78, 0x9e, 0x2e, 0x00);
663 iic(2, 0x78, 0xb8, 0x78, 0x00);
664 iic(2, 0x78, 0xba, 0x05, 0x00);
665 printk(KERN_CONT
".");
667 /* color correction */
668 iic(3, 0x78, 0x49, 0x00, 0x95); /* a */
669 iic(3, 0x78, 0x49, 0x01, 0x96); /* b */
670 iic(3, 0x78, 0x49, 0x03, 0x85); /* c */
671 iic(3, 0x78, 0x49, 0x04, 0x97); /* d */
672 iic(3, 0x78, 0x49, 0x02, 0x7e); /* e(Lo) */
673 iic(3, 0x78, 0x49, 0x05, 0xa4); /* f(Lo) */
674 iic(3, 0x78, 0x49, 0x06, 0x04); /* e(Hi) */
675 iic(3, 0x78, 0x49, 0x07, 0x04); /* e(Hi) */
676 iic(2, 0x78, 0x48, 0x01, 0x00); /* on=1 off=0 */
678 printk(KERN_CONT
".");
679 iic(2, 0x78, 0x11, 0x00, 0x00); /* end */
680 printk(KERN_CONT
" done\n");
685 /****************************************************************************
687 * Video4Linux Module functions
689 ****************************************************************************/
691 static const struct v4l2_file_operations ar_fops
= {
692 .owner
= THIS_MODULE
,
694 .ioctl
= video_ioctl2
,
697 static const struct v4l2_ioctl_ops ar_ioctl_ops
= {
698 .vidioc_querycap
= ar_querycap
,
699 .vidioc_g_input
= ar_g_input
,
700 .vidioc_s_input
= ar_s_input
,
701 .vidioc_enum_input
= ar_enum_input
,
702 .vidioc_enum_fmt_vid_cap
= ar_enum_fmt_vid_cap
,
703 .vidioc_g_fmt_vid_cap
= ar_g_fmt_vid_cap
,
704 .vidioc_s_fmt_vid_cap
= ar_s_fmt_vid_cap
,
705 .vidioc_try_fmt_vid_cap
= ar_try_fmt_vid_cap
,
708 #define ALIGN4(x) ((((int)(x)) & 0x3) == 0)
710 static int __init
ar_init(void)
713 struct v4l2_device
*v4l2_dev
;
718 v4l2_dev
= &ar
->v4l2_dev
;
719 strlcpy(v4l2_dev
->name
, "arv", sizeof(v4l2_dev
->name
));
720 v4l2_info(v4l2_dev
, "Colour AR VGA driver %s\n", VERSION
);
722 ret
= v4l2_device_register(NULL
, v4l2_dev
);
724 v4l2_err(v4l2_dev
, "Could not register v4l2_device\n");
730 /* allocate a DMA buffer for 1 line. */
731 ar
->line_buff
= kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
| GFP_DMA
);
732 if (ar
->line_buff
== NULL
|| !ALIGN4(ar
->line_buff
)) {
733 v4l2_err(v4l2_dev
, "buffer allocation failed for DMA.\n");
738 /* allocate buffers for a frame */
739 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++) {
740 ar
->frame
[i
] = kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
);
741 if (ar
->frame
[i
] == NULL
|| !ALIGN4(ar
->frame
[i
])) {
742 v4l2_err(v4l2_dev
, "buffer allocation failed for frame.\n");
748 strlcpy(ar
->vdev
.name
, "Colour AR VGA", sizeof(ar
->vdev
.name
));
749 ar
->vdev
.v4l2_dev
= v4l2_dev
;
750 ar
->vdev
.fops
= &ar_fops
;
751 ar
->vdev
.ioctl_ops
= &ar_ioctl_ops
;
752 ar
->vdev
.release
= video_device_release_empty
;
753 video_set_drvdata(&ar
->vdev
, ar
);
756 ar
->width
= AR_WIDTH_VGA
;
757 ar
->height
= AR_HEIGHT_VGA
;
758 ar
->size
= AR_SIZE_VGA
;
759 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
760 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
762 ar
->mode
= AR_MODE_INTERLACE
;
764 ar
->mode
= AR_MODE_NORMAL
;
766 ar
->width
= AR_WIDTH_QVGA
;
767 ar
->height
= AR_HEIGHT_QVGA
;
768 ar
->size
= AR_SIZE_QVGA
;
769 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
770 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
771 ar
->mode
= AR_MODE_INTERLACE
;
773 mutex_init(&ar
->lock
);
774 init_waitqueue_head(&ar
->wait
);
777 if (request_irq(M32R_IRQ_INT3
, ar_interrupt
, 0, "arv", ar
)) {
778 v4l2_err("request_irq(%d) failed.\n", M32R_IRQ_INT3
);
784 if (ar_initialize(ar
) != 0) {
785 v4l2_err(v4l2_dev
, "M64278 not found.\n");
791 * ok, we can initialize h/w according to parameters,
792 * so register video device as a frame grabber type.
793 * device is named "video[0-64]".
794 * video_register_device() initializes h/w using ar_initialize().
796 if (video_register_device(&ar
->vdev
, VFL_TYPE_GRABBER
, video_nr
) != 0) {
797 /* return -1, -ENFILE(full) or others */
798 v4l2_err(v4l2_dev
, "register video (Colour AR) failed.\n");
803 v4l2_info(v4l2_dev
, "%s: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
804 video_device_node_name(&ar
->vdev
), M32R_IRQ_INT3
, freq
);
810 free_irq(M32R_IRQ_INT3
, ar
);
814 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++)
819 kfree(ar
->line_buff
);
823 v4l2_device_unregister(&ar
->v4l2_dev
);
828 static int __init
ar_init_module(void)
830 freq
= (boot_cpu_data
.bus_clock
/ 1000000);
831 printk(KERN_INFO
"arv: Bus clock %d\n", freq
);
832 if (freq
!= 50 && freq
!= 75)
837 static void __exit
ar_cleanup_module(void)
843 video_unregister_device(&ar
->vdev
);
845 free_irq(M32R_IRQ_INT3
, ar
);
847 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++)
850 kfree(ar
->line_buff
);
852 v4l2_device_unregister(&ar
->v4l2_dev
);
855 module_init(ar_init_module
);
856 module_exit(ar_cleanup_module
);
858 MODULE_AUTHOR("Takeo Takahashi <takahashi.takeo@renesas.com>");
859 MODULE_DESCRIPTION("Colour AR M64278(VGA) for Video4Linux");
860 MODULE_LICENSE("GPL");