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/videodev2.h>
31 #include <media/v4l2-common.h>
32 #include <media/v4l2-device.h>
33 #include <media/v4l2-ioctl.h>
34 #include <linux/mutex.h>
36 #include <asm/uaccess.h>
40 #include <asm/byteorder.h>
43 #define DEBUG(n, args...) printk(KERN_INFO args)
46 #define DEBUG(n, args...)
51 * USE_INT is always 0, interrupt mode is not available
52 * on linux due to lack of speed
54 #define USE_INT 0 /* Don't modify */
56 #define VERSION "0.0.5"
58 #define ar_inl(addr) inl((unsigned long)(addr))
59 #define ar_outl(val, addr) outl((unsigned long)(val), (unsigned long)(addr))
61 extern struct cpuinfo_m32r boot_cpu_data
;
65 * Note that M32700UT does not support CIF mode, but QVGA is
66 * supported by M32700UT hardware using VGA mode of AR LSI.
68 * Supported: VGA (Normal mode, Interlace mode)
69 * QVGA (Always Interlace mode of VGA)
72 #define AR_WIDTH_VGA 640
73 #define AR_HEIGHT_VGA 480
74 #define AR_WIDTH_QVGA 320
75 #define AR_HEIGHT_QVGA 240
76 #define MIN_AR_WIDTH AR_WIDTH_QVGA
77 #define MIN_AR_HEIGHT AR_HEIGHT_QVGA
78 #define MAX_AR_WIDTH AR_WIDTH_VGA
79 #define MAX_AR_HEIGHT AR_HEIGHT_VGA
81 /* bits & bytes per pixel */
82 #define AR_BITS_PER_PIXEL 16
83 #define AR_BYTES_PER_PIXEL (AR_BITS_PER_PIXEL / 8)
85 /* line buffer size */
86 #define AR_LINE_BYTES_VGA (AR_WIDTH_VGA * AR_BYTES_PER_PIXEL)
87 #define AR_LINE_BYTES_QVGA (AR_WIDTH_QVGA * AR_BYTES_PER_PIXEL)
88 #define MAX_AR_LINE_BYTES AR_LINE_BYTES_VGA
90 /* frame size & type */
91 #define AR_FRAME_BYTES_VGA \
92 (AR_WIDTH_VGA * AR_HEIGHT_VGA * AR_BYTES_PER_PIXEL)
93 #define AR_FRAME_BYTES_QVGA \
94 (AR_WIDTH_QVGA * AR_HEIGHT_QVGA * AR_BYTES_PER_PIXEL)
95 #define MAX_AR_FRAME_BYTES \
96 (MAX_AR_WIDTH * MAX_AR_HEIGHT * AR_BYTES_PER_PIXEL)
98 #define AR_MAX_FRAME 15
101 #define AR_SIZE_VGA 0
102 #define AR_SIZE_QVGA 1
105 #define AR_MODE_INTERLACE 0
106 #define AR_MODE_NORMAL 1
109 struct v4l2_device v4l2_dev
;
110 struct video_device vdev
;
111 unsigned int start_capture
; /* duaring capture in INT. mode. */
113 unsigned char *line_buff
; /* DMA line buffer */
115 unsigned char *frame
[MAX_AR_HEIGHT
]; /* frame data */
116 short size
; /* capture size */
117 short mode
; /* capture mode */
119 int frame_bytes
, line_bytes
;
120 wait_queue_head_t wait
;
124 static struct ar ardev
;
126 static int video_nr
= -1; /* video device number (first free) */
127 static unsigned char yuv
[MAX_AR_FRAME_BYTES
];
129 /* module parameters */
130 /* default frequency */
131 #define DEFAULT_FREQ 50 /* 50 or 75 (MHz) is available as BCLK */
132 static int freq
= DEFAULT_FREQ
; /* BCLK: available 50 or 70 (MHz) */
133 static int vga
; /* default mode(0:QVGA mode, other:VGA mode) */
134 static int vga_interlace
; /* 0 is normal mode for, else interlace mode */
135 module_param(freq
, int, 0);
136 module_param(vga
, int, 0);
137 module_param(vga_interlace
, int, 0);
139 static void wait_for_vsync(void)
141 while (ar_inl(ARVCR0
) & ARVCR0_VDS
) /* wait for VSYNC */
143 while (!(ar_inl(ARVCR0
) & ARVCR0_VDS
)) /* wait for VSYNC */
147 static void wait_acknowledge(void)
151 for (i
= 0; i
< 1000; i
++)
153 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_NOACK
)
157 /*******************************************************************
159 *******************************************************************/
160 static void iic(int n
, unsigned long addr
, unsigned long data1
, unsigned long data2
,
166 ar_outl(addr
, PLDI2CDATA
);
170 ar_outl(1, PLDI2CCND
);
173 /* Transfer data 1 */
174 ar_outl(data1
, PLDI2CDATA
);
176 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
179 /* Transfer data 2 */
180 ar_outl(data2
, PLDI2CDATA
);
182 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
186 /* Transfer data 3 */
187 ar_outl(data3
, PLDI2CDATA
);
189 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
194 for (i
= 0; i
< 100; i
++)
196 ar_outl(2, PLDI2CCND
);
197 ar_outl(2, PLDI2CCND
);
199 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_BB
)
204 static void init_iic(void)
206 DEBUG(1, "init_iic:\n");
212 ar_outl(0x0, PLDI2CCR
); /* I2CCR Disable */
213 ar_outl(0x0300, PLDI2CMOD
); /* I2CMOD ACK/8b-data/7b-addr/auto */
214 ar_outl(0x1, PLDI2CACK
); /* I2CACK ACK */
219 ar_outl(369, PLDI2CFREQ
); /* BCLK = 75MHz */
221 ar_outl(244, PLDI2CFREQ
); /* BCLK = 50MHz */
223 ar_outl(244, PLDI2CFREQ
); /* default: BCLK = 50MHz */
224 ar_outl(0x1, PLDI2CCR
); /* I2CCR Enable */
227 /**************************************************************************
229 * Video4Linux Interface functions
231 **************************************************************************/
233 static inline void disable_dma(void)
235 ar_outl(0x8000, M32R_DMAEN_PORTL
); /* disable DMA0 */
238 static inline void enable_dma(void)
240 ar_outl(0x8080, M32R_DMAEN_PORTL
); /* enable DMA0 */
243 static inline void clear_dma_status(void)
245 ar_outl(0x8000, M32R_DMAEDET_PORTL
); /* clear status */
248 static void wait_for_vertical_sync(struct ar
*ar
, int exp_line
)
251 int tmout
= 10000; /* FIXME */
255 * check HCOUNT because we cannot check vertical sync.
257 for (; tmout
>= 0; tmout
--) {
258 l
= ar_inl(ARVHCOUNT
);
263 v4l2_err(&ar
->v4l2_dev
, "lost %d -> %d\n", exp_line
, l
);
265 while (ar_inl(ARVHCOUNT
) != exp_line
)
270 static ssize_t
ar_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
272 struct ar
*ar
= video_drvdata(file
);
273 long ret
= ar
->frame_bytes
; /* return read bytes */
274 unsigned long arvcr1
= 0;
278 unsigned char *py
, *pu
, *pv
;
283 DEBUG(1, "ar_read()\n");
285 if (ar
->size
== AR_SIZE_QVGA
)
286 arvcr1
|= ARVCR1_QVGA
;
287 if (ar
->mode
== AR_MODE_NORMAL
)
288 arvcr1
|= ARVCR1_NORMAL
;
290 mutex_lock(&ar
->lock
);
293 local_irq_save(flags
);
295 ar_outl(0xa1871300, M32R_DMA0CR0_PORTL
);
296 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
298 /* set AR FIFO address as source(BSEL5) */
299 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
300 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
301 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* destination addr. */
302 ar_outl(ar
->line_buff
, M32R_DMA0RDA_PORTL
); /* reload address */
303 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
); /* byte count (bytes) */
304 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
); /* reload count (bytes) */
307 * Okay, kick AR LSI to invoke an interrupt
309 ar
->start_capture
= 0;
310 ar_outl(arvcr1
| ARVCR1_HIEN
, ARVCR1
);
311 local_irq_restore(flags
);
312 /* .... AR interrupts .... */
313 interruptible_sleep_on(&ar
->wait
);
314 if (signal_pending(current
)) {
315 printk(KERN_ERR
"arv: interrupted while get frame data.\n");
319 #else /* ! USE_INT */
321 ar_outl(arvcr1
, ARVCR1
);
323 ar_outl(0x8000, M32R_DMAEDET_PORTL
);
324 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
325 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
326 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
327 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
328 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
);
329 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
);
331 local_irq_save(flags
);
332 while (ar_inl(ARVHCOUNT
) != 0) /* wait for 0 */
334 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
335 for (h
= 0; h
< ar
->height
; h
++) {
336 wait_for_vertical_sync(ar
, h
);
337 if (h
< (AR_HEIGHT_VGA
/2))
340 l
= (((h
- (AR_HEIGHT_VGA
/2)) << 1) + 1);
341 ar_outl(virt_to_phys(ar
->frame
[l
]), M32R_DMA0CDA_PORTL
);
343 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
347 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
350 for (h
= 0; h
< ar
->height
; h
++) {
351 wait_for_vertical_sync(ar
, h
);
352 ar_outl(virt_to_phys(ar
->frame
[h
]), M32R_DMA0CDA_PORTL
);
354 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
358 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
361 local_irq_restore(flags
);
362 #endif /* ! USE_INT */
365 * convert YUV422 to YUV422P
366 * +--------------------+
368 * | ..............Yn |
369 * +--------------------+
370 * | U0,U1,........Un |
371 * +--------------------+
372 * | V0,V1,........Vn |
373 * +--------------------+
376 pu
= py
+ (ar
->frame_bytes
/ 2);
377 pv
= pu
+ (ar
->frame_bytes
/ 4);
378 for (h
= 0; h
< ar
->height
; h
++) {
380 for (w
= 0; w
< ar
->line_bytes
; w
+= 4) {
387 if (copy_to_user(buf
, yuv
, ar
->frame_bytes
)) {
388 v4l2_err(&ar
->v4l2_dev
, "failed while copy_to_user yuv.\n");
392 DEBUG(1, "ret = %d\n", ret
);
394 mutex_unlock(&ar
->lock
);
398 static int ar_querycap(struct file
*file
, void *priv
,
399 struct v4l2_capability
*vcap
)
401 struct ar
*ar
= video_drvdata(file
);
403 strlcpy(vcap
->driver
, ar
->vdev
.name
, sizeof(vcap
->driver
));
404 strlcpy(vcap
->card
, "Colour AR VGA", sizeof(vcap
->card
));
405 strlcpy(vcap
->bus_info
, "Platform", sizeof(vcap
->bus_info
));
406 vcap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_READWRITE
;
410 static int ar_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*vin
)
414 strlcpy(vin
->name
, "Camera", sizeof(vin
->name
));
415 vin
->type
= V4L2_INPUT_TYPE_CAMERA
;
418 vin
->std
= V4L2_STD_ALL
;
423 static int ar_g_input(struct file
*file
, void *fh
, unsigned int *inp
)
429 static int ar_s_input(struct file
*file
, void *fh
, unsigned int inp
)
431 return inp
? -EINVAL
: 0;
434 static int ar_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
436 struct ar
*ar
= video_drvdata(file
);
437 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
439 pix
->width
= ar
->width
;
440 pix
->height
= ar
->height
;
441 pix
->pixelformat
= V4L2_PIX_FMT_YUV422P
;
442 pix
->field
= (ar
->mode
== AR_MODE_NORMAL
) ? V4L2_FIELD_NONE
: V4L2_FIELD_INTERLACED
;
443 pix
->bytesperline
= ar
->width
;
444 pix
->sizeimage
= 2 * ar
->width
* ar
->height
;
446 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
450 static int ar_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
452 struct ar
*ar
= video_drvdata(file
);
453 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
455 if (pix
->height
<= AR_HEIGHT_QVGA
|| pix
->width
<= AR_WIDTH_QVGA
) {
456 pix
->height
= AR_HEIGHT_QVGA
;
457 pix
->width
= AR_WIDTH_QVGA
;
458 pix
->field
= V4L2_FIELD_INTERLACED
;
460 pix
->height
= AR_HEIGHT_VGA
;
461 pix
->width
= AR_WIDTH_VGA
;
462 pix
->field
= vga_interlace
? V4L2_FIELD_INTERLACED
: V4L2_FIELD_NONE
;
464 pix
->pixelformat
= V4L2_PIX_FMT_YUV422P
;
465 pix
->bytesperline
= ar
->width
;
466 pix
->sizeimage
= 2 * ar
->width
* ar
->height
;
468 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
472 static int ar_s_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
474 struct ar
*ar
= video_drvdata(file
);
475 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
476 int ret
= ar_try_fmt_vid_cap(file
, fh
, fmt
);
480 mutex_lock(&ar
->lock
);
481 ar
->width
= pix
->width
;
482 ar
->height
= pix
->height
;
483 if (ar
->width
== AR_WIDTH_VGA
) {
484 ar
->size
= AR_SIZE_VGA
;
485 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
486 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
488 ar
->mode
= AR_MODE_INTERLACE
;
490 ar
->mode
= AR_MODE_NORMAL
;
492 ar
->size
= AR_SIZE_QVGA
;
493 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
494 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
495 ar
->mode
= AR_MODE_INTERLACE
;
497 /* Ok we figured out what to use from our wide choice */
498 mutex_unlock(&ar
->lock
);
502 static int ar_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
504 static struct v4l2_fmtdesc formats
[] = {
506 "YUV 4:2:2 Planar", V4L2_PIX_FMT_YUV422P
,
510 enum v4l2_buf_type type
= fmt
->type
;
515 *fmt
= formats
[fmt
->index
];
524 static void ar_interrupt(int irq
, void *dev
)
527 unsigned int line_count
;
528 unsigned int line_number
;
531 line_count
= ar_inl(ARVHCOUNT
); /* line number */
532 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
533 /* operations for interlace mode */
534 if (line_count
< (AR_HEIGHT_VGA
/ 2)) /* even line */
535 line_number
= (line_count
<< 1);
538 (((line_count
- (AR_HEIGHT_VGA
/ 2)) << 1) + 1);
540 line_number
= line_count
;
543 if (line_number
== 0) {
545 * It is an interrupt for line 0.
546 * we have to start capture.
550 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* needless? */
552 memcpy(ar
->frame
[0], ar
->line_buff
, ar
->line_bytes
);
554 ar_outl(0xa1861300, M32R_DMA0CR0_PORTL
);
557 ar
->start_capture
= 1; /* during capture */
561 if (ar
->start_capture
== 1 && line_number
<= (ar
->height
- 1)) {
563 memcpy(ar
->frame
[line_number
], ar
->line_buff
, ar
->line_bytes
);
566 * if captured all line of a frame, disable AR interrupt
567 * and wake a process up.
569 if (line_number
== (ar
->height
- 1)) { /* end of line */
571 ar
->start_capture
= 0;
573 /* disable AR interrupt request */
574 arvcr1
= ar_inl(ARVCR1
);
575 arvcr1
&= ~ARVCR1_HIEN
; /* clear int. flag */
576 ar_outl(arvcr1
, ARVCR1
); /* disable */
577 wake_up_interruptible(&ar
->wait
);
580 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
);
581 ar_outl(0xa1861300, M32R_DMA0CR0_PORTL
);
591 * ar_initialize() is called by video_register_device() and
592 * initializes AR LSI and peripherals.
594 * -1 is returned in all failures.
595 * 0 is returned in success.
598 static int ar_initialize(struct ar
*ar
)
600 unsigned long cr
= 0;
603 DEBUG(1, "ar_initialize:\n");
608 ar_outl(0, ARVCR0
); /* assert reset of AR LSI */
609 for (i
= 0; i
< 0x18; i
++) /* wait for over 10 cycles @ 27MHz */
611 ar_outl(ARVCR0_RST
, ARVCR0
); /* negate reset of AR LSI (enable) */
612 for (i
= 0; i
< 0x40d; i
++) /* wait for over 420 cycles @ 27MHz */
615 /* AR uses INT3 of CPU as interrupt pin. */
616 ar_outl(ARINTSEL_INT3
, ARINTSEL
);
618 if (ar
->size
== AR_SIZE_QVGA
)
620 if (ar
->mode
== AR_MODE_NORMAL
)
625 * Initialize IIC so that CPU can communicate with AR LSI,
626 * and send boot commands to AR LSI.
630 for (i
= 0; i
< 0x100000; i
++) { /* > 0xa1d10, 56ms */
631 if ((ar_inl(ARVCR0
) & ARVCR0_VDS
)) { /* VSYNC */
640 v4l2_info(&ar
->v4l2_dev
, "Initializing ");
642 iic(2, 0x78, 0x11, 0x01, 0x00); /* start */
643 iic(3, 0x78, 0x12, 0x00, 0x06);
644 iic(3, 0x78, 0x12, 0x12, 0x30);
645 iic(3, 0x78, 0x12, 0x15, 0x58);
646 iic(3, 0x78, 0x12, 0x17, 0x30);
647 printk(KERN_CONT
".");
648 iic(3, 0x78, 0x12, 0x1a, 0x97);
649 iic(3, 0x78, 0x12, 0x1b, 0xff);
650 iic(3, 0x78, 0x12, 0x1c, 0xff);
651 iic(3, 0x78, 0x12, 0x26, 0x10);
652 iic(3, 0x78, 0x12, 0x27, 0x00);
653 printk(KERN_CONT
".");
654 iic(2, 0x78, 0x34, 0x02, 0x00);
655 iic(2, 0x78, 0x7a, 0x10, 0x00);
656 iic(2, 0x78, 0x80, 0x39, 0x00);
657 iic(2, 0x78, 0x81, 0xe6, 0x00);
658 iic(2, 0x78, 0x8d, 0x00, 0x00);
659 printk(KERN_CONT
".");
660 iic(2, 0x78, 0x8e, 0x0c, 0x00);
661 iic(2, 0x78, 0x8f, 0x00, 0x00);
663 iic(2, 0x78, 0x90, 0x00, 0x00); /* AWB on=1 off=0 */
665 iic(2, 0x78, 0x93, 0x01, 0x00);
666 iic(2, 0x78, 0x94, 0xcd, 0x00);
667 iic(2, 0x78, 0x95, 0x00, 0x00);
668 printk(KERN_CONT
".");
669 iic(2, 0x78, 0x96, 0xa0, 0x00);
670 iic(2, 0x78, 0x97, 0x00, 0x00);
671 iic(2, 0x78, 0x98, 0x60, 0x00);
672 iic(2, 0x78, 0x99, 0x01, 0x00);
673 iic(2, 0x78, 0x9a, 0x19, 0x00);
674 printk(KERN_CONT
".");
675 iic(2, 0x78, 0x9b, 0x02, 0x00);
676 iic(2, 0x78, 0x9c, 0xe8, 0x00);
677 iic(2, 0x78, 0x9d, 0x02, 0x00);
678 iic(2, 0x78, 0x9e, 0x2e, 0x00);
679 iic(2, 0x78, 0xb8, 0x78, 0x00);
680 iic(2, 0x78, 0xba, 0x05, 0x00);
682 iic(2, 0x78, 0x83, 0x8c, 0x00); /* brightness */
684 printk(KERN_CONT
".");
686 /* color correction */
687 iic(3, 0x78, 0x49, 0x00, 0x95); /* a */
688 iic(3, 0x78, 0x49, 0x01, 0x96); /* b */
689 iic(3, 0x78, 0x49, 0x03, 0x85); /* c */
690 iic(3, 0x78, 0x49, 0x04, 0x97); /* d */
691 iic(3, 0x78, 0x49, 0x02, 0x7e); /* e(Lo) */
692 iic(3, 0x78, 0x49, 0x05, 0xa4); /* f(Lo) */
693 iic(3, 0x78, 0x49, 0x06, 0x04); /* e(Hi) */
694 iic(3, 0x78, 0x49, 0x07, 0x04); /* e(Hi) */
695 iic(2, 0x78, 0x48, 0x01, 0x00); /* on=1 off=0 */
697 printk(KERN_CONT
".");
698 iic(2, 0x78, 0x11, 0x00, 0x00); /* end */
699 printk(KERN_CONT
" done\n");
704 /****************************************************************************
706 * Video4Linux Module functions
708 ****************************************************************************/
710 static const struct v4l2_file_operations ar_fops
= {
711 .owner
= THIS_MODULE
,
713 .unlocked_ioctl
= video_ioctl2
,
716 static const struct v4l2_ioctl_ops ar_ioctl_ops
= {
717 .vidioc_querycap
= ar_querycap
,
718 .vidioc_g_input
= ar_g_input
,
719 .vidioc_s_input
= ar_s_input
,
720 .vidioc_enum_input
= ar_enum_input
,
721 .vidioc_enum_fmt_vid_cap
= ar_enum_fmt_vid_cap
,
722 .vidioc_g_fmt_vid_cap
= ar_g_fmt_vid_cap
,
723 .vidioc_s_fmt_vid_cap
= ar_s_fmt_vid_cap
,
724 .vidioc_try_fmt_vid_cap
= ar_try_fmt_vid_cap
,
727 #define ALIGN4(x) ((((int)(x)) & 0x3) == 0)
729 static int __init
ar_init(void)
732 struct v4l2_device
*v4l2_dev
;
737 v4l2_dev
= &ar
->v4l2_dev
;
738 strlcpy(v4l2_dev
->name
, "arv", sizeof(v4l2_dev
->name
));
739 v4l2_info(v4l2_dev
, "Colour AR VGA driver %s\n", VERSION
);
741 ret
= v4l2_device_register(NULL
, v4l2_dev
);
743 v4l2_err(v4l2_dev
, "Could not register v4l2_device\n");
749 /* allocate a DMA buffer for 1 line. */
750 ar
->line_buff
= kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
| GFP_DMA
);
751 if (ar
->line_buff
== NULL
|| !ALIGN4(ar
->line_buff
)) {
752 v4l2_err(v4l2_dev
, "buffer allocation failed for DMA.\n");
757 /* allocate buffers for a frame */
758 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++) {
759 ar
->frame
[i
] = kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
);
760 if (ar
->frame
[i
] == NULL
|| !ALIGN4(ar
->frame
[i
])) {
761 v4l2_err(v4l2_dev
, "buffer allocation failed for frame.\n");
767 strlcpy(ar
->vdev
.name
, "Colour AR VGA", sizeof(ar
->vdev
.name
));
768 ar
->vdev
.v4l2_dev
= v4l2_dev
;
769 ar
->vdev
.fops
= &ar_fops
;
770 ar
->vdev
.ioctl_ops
= &ar_ioctl_ops
;
771 ar
->vdev
.release
= video_device_release_empty
;
772 video_set_drvdata(&ar
->vdev
, ar
);
775 ar
->width
= AR_WIDTH_VGA
;
776 ar
->height
= AR_HEIGHT_VGA
;
777 ar
->size
= AR_SIZE_VGA
;
778 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
779 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
781 ar
->mode
= AR_MODE_INTERLACE
;
783 ar
->mode
= AR_MODE_NORMAL
;
785 ar
->width
= AR_WIDTH_QVGA
;
786 ar
->height
= AR_HEIGHT_QVGA
;
787 ar
->size
= AR_SIZE_QVGA
;
788 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
789 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
790 ar
->mode
= AR_MODE_INTERLACE
;
792 mutex_init(&ar
->lock
);
793 init_waitqueue_head(&ar
->wait
);
796 if (request_irq(M32R_IRQ_INT3
, ar_interrupt
, 0, "arv", ar
)) {
797 v4l2_err("request_irq(%d) failed.\n", M32R_IRQ_INT3
);
803 if (ar_initialize(ar
) != 0) {
804 v4l2_err(v4l2_dev
, "M64278 not found.\n");
810 * ok, we can initialize h/w according to parameters,
811 * so register video device as a frame grabber type.
812 * device is named "video[0-64]".
813 * video_register_device() initializes h/w using ar_initialize().
815 if (video_register_device(&ar
->vdev
, VFL_TYPE_GRABBER
, video_nr
) != 0) {
816 /* return -1, -ENFILE(full) or others */
817 v4l2_err(v4l2_dev
, "register video (Colour AR) failed.\n");
822 v4l2_info(v4l2_dev
, "%s: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
823 video_device_node_name(&ar
->vdev
), M32R_IRQ_INT3
, freq
);
829 free_irq(M32R_IRQ_INT3
, ar
);
833 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++)
838 kfree(ar
->line_buff
);
842 v4l2_device_unregister(&ar
->v4l2_dev
);
847 static int __init
ar_init_module(void)
849 freq
= (boot_cpu_data
.bus_clock
/ 1000000);
850 printk(KERN_INFO
"arv: Bus clock %d\n", freq
);
851 if (freq
!= 50 && freq
!= 75)
856 static void __exit
ar_cleanup_module(void)
862 video_unregister_device(&ar
->vdev
);
864 free_irq(M32R_IRQ_INT3
, ar
);
866 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++)
869 kfree(ar
->line_buff
);
871 v4l2_device_unregister(&ar
->v4l2_dev
);
874 module_init(ar_init_module
);
875 module_exit(ar_cleanup_module
);
877 MODULE_AUTHOR("Takeo Takahashi <takahashi.takeo@renesas.com>");
878 MODULE_DESCRIPTION("Colour AR M64278(VGA) for Video4Linux");
879 MODULE_LICENSE("GPL");
880 MODULE_VERSION(VERSION
);