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 <media/v4l2-fh.h>
35 #include <linux/mutex.h>
37 #include <linux/uaccess.h>
41 #include <asm/byteorder.h>
44 #define DEBUG(n, args...) printk(KERN_INFO args)
47 #define DEBUG(n, args...)
52 * USE_INT is always 0, interrupt mode is not available
53 * on linux due to lack of speed
55 #define USE_INT 0 /* Don't modify */
57 #define VERSION "0.0.5"
59 #define ar_inl(addr) inl((unsigned long)(addr))
60 #define ar_outl(val, addr) outl((unsigned long)(val), (unsigned long)(addr))
62 extern struct cpuinfo_m32r boot_cpu_data
;
66 * Note that M32700UT does not support CIF mode, but QVGA is
67 * supported by M32700UT hardware using VGA mode of AR LSI.
69 * Supported: VGA (Normal mode, Interlace mode)
70 * QVGA (Always Interlace mode of VGA)
73 #define AR_WIDTH_VGA 640
74 #define AR_HEIGHT_VGA 480
75 #define AR_WIDTH_QVGA 320
76 #define AR_HEIGHT_QVGA 240
77 #define MIN_AR_WIDTH AR_WIDTH_QVGA
78 #define MIN_AR_HEIGHT AR_HEIGHT_QVGA
79 #define MAX_AR_WIDTH AR_WIDTH_VGA
80 #define MAX_AR_HEIGHT AR_HEIGHT_VGA
82 /* bits & bytes per pixel */
83 #define AR_BITS_PER_PIXEL 16
84 #define AR_BYTES_PER_PIXEL (AR_BITS_PER_PIXEL / 8)
86 /* line buffer size */
87 #define AR_LINE_BYTES_VGA (AR_WIDTH_VGA * AR_BYTES_PER_PIXEL)
88 #define AR_LINE_BYTES_QVGA (AR_WIDTH_QVGA * AR_BYTES_PER_PIXEL)
89 #define MAX_AR_LINE_BYTES AR_LINE_BYTES_VGA
91 /* frame size & type */
92 #define AR_FRAME_BYTES_VGA \
93 (AR_WIDTH_VGA * AR_HEIGHT_VGA * AR_BYTES_PER_PIXEL)
94 #define AR_FRAME_BYTES_QVGA \
95 (AR_WIDTH_QVGA * AR_HEIGHT_QVGA * AR_BYTES_PER_PIXEL)
96 #define MAX_AR_FRAME_BYTES \
97 (MAX_AR_WIDTH * MAX_AR_HEIGHT * AR_BYTES_PER_PIXEL)
99 #define AR_MAX_FRAME 15
102 #define AR_SIZE_VGA 0
103 #define AR_SIZE_QVGA 1
106 #define AR_MODE_INTERLACE 0
107 #define AR_MODE_NORMAL 1
110 struct v4l2_device v4l2_dev
;
111 struct video_device vdev
;
112 int start_capture
; /* duaring capture in INT. mode. */
114 unsigned char *line_buff
; /* DMA line buffer */
116 unsigned char *frame
[MAX_AR_HEIGHT
]; /* frame data */
117 short size
; /* capture size */
118 short mode
; /* capture mode */
120 int frame_bytes
, line_bytes
;
121 wait_queue_head_t wait
;
125 static struct ar ardev
;
127 static int video_nr
= -1; /* video device number (first free) */
128 static unsigned char yuv
[MAX_AR_FRAME_BYTES
];
130 /* module parameters */
131 /* default frequency */
132 #define DEFAULT_FREQ 50 /* 50 or 75 (MHz) is available as BCLK */
133 static int freq
= DEFAULT_FREQ
; /* BCLK: available 50 or 70 (MHz) */
134 static int vga
; /* default mode(0:QVGA mode, other:VGA mode) */
135 static int vga_interlace
; /* 0 is normal mode for, else interlace mode */
136 module_param(freq
, int, 0);
137 module_param(vga
, int, 0);
138 module_param(vga_interlace
, int, 0);
140 static void wait_for_vsync(void)
142 while (ar_inl(ARVCR0
) & ARVCR0_VDS
) /* wait for VSYNC */
144 while (!(ar_inl(ARVCR0
) & ARVCR0_VDS
)) /* wait for VSYNC */
148 static void wait_acknowledge(void)
152 for (i
= 0; i
< 1000; i
++)
154 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_NOACK
)
158 /*******************************************************************
160 *******************************************************************/
161 static void iic(int n
, unsigned long addr
, unsigned long data1
, unsigned long data2
,
167 ar_outl(addr
, PLDI2CDATA
);
171 ar_outl(1, PLDI2CCND
);
174 /* Transfer data 1 */
175 ar_outl(data1
, PLDI2CDATA
);
177 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
180 /* Transfer data 2 */
181 ar_outl(data2
, PLDI2CDATA
);
183 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
187 /* Transfer data 3 */
188 ar_outl(data3
, PLDI2CDATA
);
190 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
195 for (i
= 0; i
< 100; i
++)
197 ar_outl(2, PLDI2CCND
);
198 ar_outl(2, PLDI2CCND
);
200 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_BB
)
205 static void init_iic(void)
207 DEBUG(1, "init_iic:\n");
213 ar_outl(0x0, PLDI2CCR
); /* I2CCR Disable */
214 ar_outl(0x0300, PLDI2CMOD
); /* I2CMOD ACK/8b-data/7b-addr/auto */
215 ar_outl(0x1, PLDI2CACK
); /* I2CACK ACK */
220 ar_outl(369, PLDI2CFREQ
); /* BCLK = 75MHz */
222 ar_outl(244, PLDI2CFREQ
); /* BCLK = 50MHz */
224 ar_outl(244, PLDI2CFREQ
); /* default: BCLK = 50MHz */
225 ar_outl(0x1, PLDI2CCR
); /* I2CCR Enable */
228 /**************************************************************************
230 * Video4Linux Interface functions
232 **************************************************************************/
234 static inline void disable_dma(void)
236 ar_outl(0x8000, M32R_DMAEN_PORTL
); /* disable DMA0 */
239 static inline void enable_dma(void)
241 ar_outl(0x8080, M32R_DMAEN_PORTL
); /* enable DMA0 */
244 static inline void clear_dma_status(void)
246 ar_outl(0x8000, M32R_DMAEDET_PORTL
); /* clear status */
249 static void wait_for_vertical_sync(struct ar
*ar
, int exp_line
)
252 int tmout
= 10000; /* FIXME */
256 * check HCOUNT because we cannot check vertical sync.
258 for (; tmout
>= 0; tmout
--) {
259 l
= ar_inl(ARVHCOUNT
);
264 v4l2_err(&ar
->v4l2_dev
, "lost %d -> %d\n", exp_line
, l
);
266 while (ar_inl(ARVHCOUNT
) != exp_line
)
271 static ssize_t
ar_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
273 struct ar
*ar
= video_drvdata(file
);
274 long ret
= ar
->frame_bytes
; /* return read bytes */
275 unsigned long arvcr1
= 0;
279 unsigned char *py
, *pu
, *pv
;
284 DEBUG(1, "ar_read()\n");
286 if (ar
->size
== AR_SIZE_QVGA
)
287 arvcr1
|= ARVCR1_QVGA
;
288 if (ar
->mode
== AR_MODE_NORMAL
)
289 arvcr1
|= ARVCR1_NORMAL
;
291 mutex_lock(&ar
->lock
);
294 local_irq_save(flags
);
296 ar_outl(0xa1871300, M32R_DMA0CR0_PORTL
);
297 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
299 /* set AR FIFO address as source(BSEL5) */
300 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
301 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
302 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* destination addr. */
303 ar_outl(ar
->line_buff
, M32R_DMA0RDA_PORTL
); /* reload address */
304 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
); /* byte count (bytes) */
305 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
); /* reload count (bytes) */
308 * Okay, kick AR LSI to invoke an interrupt
310 ar
->start_capture
= -1;
311 ar_outl(arvcr1
| ARVCR1_HIEN
, ARVCR1
);
312 local_irq_restore(flags
);
313 /* .... AR interrupts .... */
314 wait_event_interruptible(ar
->wait
, ar
->start_capture
== 0);
315 if (signal_pending(current
)) {
316 printk(KERN_ERR
"arv: interrupted while get frame data.\n");
320 #else /* ! USE_INT */
322 ar_outl(arvcr1
, ARVCR1
);
324 ar_outl(0x8000, M32R_DMAEDET_PORTL
);
325 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
326 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
327 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
328 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
329 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
);
330 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
);
332 local_irq_save(flags
);
333 while (ar_inl(ARVHCOUNT
) != 0) /* wait for 0 */
335 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
336 for (h
= 0; h
< ar
->height
; h
++) {
337 wait_for_vertical_sync(ar
, h
);
338 if (h
< (AR_HEIGHT_VGA
/2))
341 l
= (((h
- (AR_HEIGHT_VGA
/2)) << 1) + 1);
342 ar_outl(virt_to_phys(ar
->frame
[l
]), M32R_DMA0CDA_PORTL
);
344 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
348 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
351 for (h
= 0; h
< ar
->height
; h
++) {
352 wait_for_vertical_sync(ar
, h
);
353 ar_outl(virt_to_phys(ar
->frame
[h
]), M32R_DMA0CDA_PORTL
);
355 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
359 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
362 local_irq_restore(flags
);
363 #endif /* ! USE_INT */
366 * convert YUV422 to YUV422P
367 * +--------------------+
369 * | ..............Yn |
370 * +--------------------+
371 * | U0,U1,........Un |
372 * +--------------------+
373 * | V0,V1,........Vn |
374 * +--------------------+
377 pu
= py
+ (ar
->frame_bytes
/ 2);
378 pv
= pu
+ (ar
->frame_bytes
/ 4);
379 for (h
= 0; h
< ar
->height
; h
++) {
381 for (w
= 0; w
< ar
->line_bytes
; w
+= 4) {
388 if (copy_to_user(buf
, yuv
, ar
->frame_bytes
)) {
389 v4l2_err(&ar
->v4l2_dev
, "failed while copy_to_user yuv.\n");
393 DEBUG(1, "ret = %d\n", ret
);
395 mutex_unlock(&ar
->lock
);
399 static int ar_querycap(struct file
*file
, void *priv
,
400 struct v4l2_capability
*vcap
)
402 struct ar
*ar
= video_drvdata(file
);
404 strlcpy(vcap
->driver
, ar
->vdev
.name
, sizeof(vcap
->driver
));
405 strlcpy(vcap
->card
, "Colour AR VGA", sizeof(vcap
->card
));
406 strlcpy(vcap
->bus_info
, "Platform", sizeof(vcap
->bus_info
));
407 vcap
->device_caps
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_READWRITE
;
408 vcap
->capabilities
= vcap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
412 static int ar_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*vin
)
416 strlcpy(vin
->name
, "Camera", sizeof(vin
->name
));
417 vin
->type
= V4L2_INPUT_TYPE_CAMERA
;
420 vin
->std
= V4L2_STD_ALL
;
425 static int ar_g_input(struct file
*file
, void *fh
, unsigned int *inp
)
431 static int ar_s_input(struct file
*file
, void *fh
, unsigned int inp
)
433 return inp
? -EINVAL
: 0;
436 static int ar_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
438 struct ar
*ar
= video_drvdata(file
);
439 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
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
;
448 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
452 static int ar_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
454 struct ar
*ar
= video_drvdata(file
);
455 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
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
;
462 pix
->height
= AR_HEIGHT_VGA
;
463 pix
->width
= AR_WIDTH_VGA
;
464 pix
->field
= vga_interlace
? V4L2_FIELD_INTERLACED
: V4L2_FIELD_NONE
;
466 pix
->pixelformat
= V4L2_PIX_FMT_YUV422P
;
467 pix
->bytesperline
= ar
->width
;
468 pix
->sizeimage
= 2 * ar
->width
* ar
->height
;
470 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
474 static int ar_s_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
476 struct ar
*ar
= video_drvdata(file
);
477 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
478 int ret
= ar_try_fmt_vid_cap(file
, fh
, fmt
);
482 mutex_lock(&ar
->lock
);
483 ar
->width
= pix
->width
;
484 ar
->height
= pix
->height
;
485 if (ar
->width
== AR_WIDTH_VGA
) {
486 ar
->size
= AR_SIZE_VGA
;
487 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
488 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
490 ar
->mode
= AR_MODE_INTERLACE
;
492 ar
->mode
= AR_MODE_NORMAL
;
494 ar
->size
= AR_SIZE_QVGA
;
495 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
496 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
497 ar
->mode
= AR_MODE_INTERLACE
;
499 /* Ok we figured out what to use from our wide choice */
500 mutex_unlock(&ar
->lock
);
504 static int ar_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
506 static struct v4l2_fmtdesc formats
[] = {
508 "YUV 4:2:2 Planar", V4L2_PIX_FMT_YUV422P
,
512 enum v4l2_buf_type type
= fmt
->type
;
517 *fmt
= formats
[fmt
->index
];
526 static void ar_interrupt(int irq
, void *dev
)
529 unsigned int line_count
;
530 unsigned int line_number
;
533 line_count
= ar_inl(ARVHCOUNT
); /* line number */
534 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
535 /* operations for interlace mode */
536 if (line_count
< (AR_HEIGHT_VGA
/ 2)) /* even line */
537 line_number
= (line_count
<< 1);
540 (((line_count
- (AR_HEIGHT_VGA
/ 2)) << 1) + 1);
542 line_number
= line_count
;
545 if (line_number
== 0) {
547 * It is an interrupt for line 0.
548 * we have to start capture.
552 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* needless? */
554 memcpy(ar
->frame
[0], ar
->line_buff
, ar
->line_bytes
);
556 ar_outl(0xa1861300, M32R_DMA0CR0_PORTL
);
559 ar
->start_capture
= 1; /* during capture */
563 if (ar
->start_capture
== 1 && line_number
<= (ar
->height
- 1)) {
565 memcpy(ar
->frame
[line_number
], ar
->line_buff
, ar
->line_bytes
);
568 * if captured all line of a frame, disable AR interrupt
569 * and wake a process up.
571 if (line_number
== (ar
->height
- 1)) { /* end of line */
573 ar
->start_capture
= 0;
575 /* disable AR interrupt request */
576 arvcr1
= ar_inl(ARVCR1
);
577 arvcr1
&= ~ARVCR1_HIEN
; /* clear int. flag */
578 ar_outl(arvcr1
, ARVCR1
); /* disable */
579 wake_up_interruptible(&ar
->wait
);
582 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
);
583 ar_outl(0xa1861300, M32R_DMA0CR0_PORTL
);
593 * ar_initialize() is called by video_register_device() and
594 * initializes AR LSI and peripherals.
596 * -1 is returned in all failures.
597 * 0 is returned in success.
600 static int ar_initialize(struct ar
*ar
)
602 unsigned long cr
= 0;
605 DEBUG(1, "ar_initialize:\n");
610 ar_outl(0, ARVCR0
); /* assert reset of AR LSI */
611 for (i
= 0; i
< 0x18; i
++) /* wait for over 10 cycles @ 27MHz */
613 ar_outl(ARVCR0_RST
, ARVCR0
); /* negate reset of AR LSI (enable) */
614 for (i
= 0; i
< 0x40d; i
++) /* wait for over 420 cycles @ 27MHz */
617 /* AR uses INT3 of CPU as interrupt pin. */
618 ar_outl(ARINTSEL_INT3
, ARINTSEL
);
620 if (ar
->size
== AR_SIZE_QVGA
)
622 if (ar
->mode
== AR_MODE_NORMAL
)
627 * Initialize IIC so that CPU can communicate with AR LSI,
628 * and send boot commands to AR LSI.
632 for (i
= 0; i
< 0x100000; i
++) { /* > 0xa1d10, 56ms */
633 if ((ar_inl(ARVCR0
) & ARVCR0_VDS
)) { /* VSYNC */
642 v4l2_info(&ar
->v4l2_dev
, "Initializing ");
644 iic(2, 0x78, 0x11, 0x01, 0x00); /* start */
645 iic(3, 0x78, 0x12, 0x00, 0x06);
646 iic(3, 0x78, 0x12, 0x12, 0x30);
647 iic(3, 0x78, 0x12, 0x15, 0x58);
648 iic(3, 0x78, 0x12, 0x17, 0x30);
649 printk(KERN_CONT
".");
650 iic(3, 0x78, 0x12, 0x1a, 0x97);
651 iic(3, 0x78, 0x12, 0x1b, 0xff);
652 iic(3, 0x78, 0x12, 0x1c, 0xff);
653 iic(3, 0x78, 0x12, 0x26, 0x10);
654 iic(3, 0x78, 0x12, 0x27, 0x00);
655 printk(KERN_CONT
".");
656 iic(2, 0x78, 0x34, 0x02, 0x00);
657 iic(2, 0x78, 0x7a, 0x10, 0x00);
658 iic(2, 0x78, 0x80, 0x39, 0x00);
659 iic(2, 0x78, 0x81, 0xe6, 0x00);
660 iic(2, 0x78, 0x8d, 0x00, 0x00);
661 printk(KERN_CONT
".");
662 iic(2, 0x78, 0x8e, 0x0c, 0x00);
663 iic(2, 0x78, 0x8f, 0x00, 0x00);
665 iic(2, 0x78, 0x90, 0x00, 0x00); /* AWB on=1 off=0 */
667 iic(2, 0x78, 0x93, 0x01, 0x00);
668 iic(2, 0x78, 0x94, 0xcd, 0x00);
669 iic(2, 0x78, 0x95, 0x00, 0x00);
670 printk(KERN_CONT
".");
671 iic(2, 0x78, 0x96, 0xa0, 0x00);
672 iic(2, 0x78, 0x97, 0x00, 0x00);
673 iic(2, 0x78, 0x98, 0x60, 0x00);
674 iic(2, 0x78, 0x99, 0x01, 0x00);
675 iic(2, 0x78, 0x9a, 0x19, 0x00);
676 printk(KERN_CONT
".");
677 iic(2, 0x78, 0x9b, 0x02, 0x00);
678 iic(2, 0x78, 0x9c, 0xe8, 0x00);
679 iic(2, 0x78, 0x9d, 0x02, 0x00);
680 iic(2, 0x78, 0x9e, 0x2e, 0x00);
681 iic(2, 0x78, 0xb8, 0x78, 0x00);
682 iic(2, 0x78, 0xba, 0x05, 0x00);
684 iic(2, 0x78, 0x83, 0x8c, 0x00); /* brightness */
686 printk(KERN_CONT
".");
688 /* color correction */
689 iic(3, 0x78, 0x49, 0x00, 0x95); /* a */
690 iic(3, 0x78, 0x49, 0x01, 0x96); /* b */
691 iic(3, 0x78, 0x49, 0x03, 0x85); /* c */
692 iic(3, 0x78, 0x49, 0x04, 0x97); /* d */
693 iic(3, 0x78, 0x49, 0x02, 0x7e); /* e(Lo) */
694 iic(3, 0x78, 0x49, 0x05, 0xa4); /* f(Lo) */
695 iic(3, 0x78, 0x49, 0x06, 0x04); /* e(Hi) */
696 iic(3, 0x78, 0x49, 0x07, 0x04); /* e(Hi) */
697 iic(2, 0x78, 0x48, 0x01, 0x00); /* on=1 off=0 */
699 printk(KERN_CONT
".");
700 iic(2, 0x78, 0x11, 0x00, 0x00); /* end */
701 printk(KERN_CONT
" done\n");
706 /****************************************************************************
708 * Video4Linux Module functions
710 ****************************************************************************/
712 static const struct v4l2_file_operations ar_fops
= {
713 .owner
= THIS_MODULE
,
714 .open
= v4l2_fh_open
,
715 .release
= v4l2_fh_release
,
717 .unlocked_ioctl
= video_ioctl2
,
720 static const struct v4l2_ioctl_ops ar_ioctl_ops
= {
721 .vidioc_querycap
= ar_querycap
,
722 .vidioc_g_input
= ar_g_input
,
723 .vidioc_s_input
= ar_s_input
,
724 .vidioc_enum_input
= ar_enum_input
,
725 .vidioc_enum_fmt_vid_cap
= ar_enum_fmt_vid_cap
,
726 .vidioc_g_fmt_vid_cap
= ar_g_fmt_vid_cap
,
727 .vidioc_s_fmt_vid_cap
= ar_s_fmt_vid_cap
,
728 .vidioc_try_fmt_vid_cap
= ar_try_fmt_vid_cap
,
731 #define ALIGN4(x) ((((int)(x)) & 0x3) == 0)
733 static int __init
ar_init(void)
736 struct v4l2_device
*v4l2_dev
;
741 v4l2_dev
= &ar
->v4l2_dev
;
742 strlcpy(v4l2_dev
->name
, "arv", sizeof(v4l2_dev
->name
));
743 v4l2_info(v4l2_dev
, "Colour AR VGA driver %s\n", VERSION
);
745 ret
= v4l2_device_register(NULL
, v4l2_dev
);
747 v4l2_err(v4l2_dev
, "Could not register v4l2_device\n");
753 /* allocate a DMA buffer for 1 line. */
754 ar
->line_buff
= kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
| GFP_DMA
);
755 if (ar
->line_buff
== NULL
|| !ALIGN4(ar
->line_buff
)) {
756 v4l2_err(v4l2_dev
, "buffer allocation failed for DMA.\n");
761 /* allocate buffers for a frame */
762 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++) {
763 ar
->frame
[i
] = kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
);
764 if (ar
->frame
[i
] == NULL
|| !ALIGN4(ar
->frame
[i
])) {
765 v4l2_err(v4l2_dev
, "buffer allocation failed for frame.\n");
771 strlcpy(ar
->vdev
.name
, "Colour AR VGA", sizeof(ar
->vdev
.name
));
772 ar
->vdev
.v4l2_dev
= v4l2_dev
;
773 ar
->vdev
.fops
= &ar_fops
;
774 ar
->vdev
.ioctl_ops
= &ar_ioctl_ops
;
775 ar
->vdev
.release
= video_device_release_empty
;
776 video_set_drvdata(&ar
->vdev
, ar
);
779 ar
->width
= AR_WIDTH_VGA
;
780 ar
->height
= AR_HEIGHT_VGA
;
781 ar
->size
= AR_SIZE_VGA
;
782 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
783 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
785 ar
->mode
= AR_MODE_INTERLACE
;
787 ar
->mode
= AR_MODE_NORMAL
;
789 ar
->width
= AR_WIDTH_QVGA
;
790 ar
->height
= AR_HEIGHT_QVGA
;
791 ar
->size
= AR_SIZE_QVGA
;
792 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
793 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
794 ar
->mode
= AR_MODE_INTERLACE
;
796 mutex_init(&ar
->lock
);
797 init_waitqueue_head(&ar
->wait
);
800 if (request_irq(M32R_IRQ_INT3
, ar_interrupt
, 0, "arv", ar
)) {
801 v4l2_err("request_irq(%d) failed.\n", M32R_IRQ_INT3
);
807 if (ar_initialize(ar
) != 0) {
808 v4l2_err(v4l2_dev
, "M64278 not found.\n");
814 * ok, we can initialize h/w according to parameters,
815 * so register video device as a frame grabber type.
816 * device is named "video[0-64]".
817 * video_register_device() initializes h/w using ar_initialize().
819 if (video_register_device(&ar
->vdev
, VFL_TYPE_GRABBER
, video_nr
) != 0) {
820 /* return -1, -ENFILE(full) or others */
821 v4l2_err(v4l2_dev
, "register video (Colour AR) failed.\n");
826 v4l2_info(v4l2_dev
, "%s: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
827 video_device_node_name(&ar
->vdev
), M32R_IRQ_INT3
, freq
);
833 free_irq(M32R_IRQ_INT3
, ar
);
837 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++)
842 kfree(ar
->line_buff
);
846 v4l2_device_unregister(&ar
->v4l2_dev
);
851 static int __init
ar_init_module(void)
853 freq
= (boot_cpu_data
.bus_clock
/ 1000000);
854 printk(KERN_INFO
"arv: Bus clock %d\n", freq
);
855 if (freq
!= 50 && freq
!= 75)
860 static void __exit
ar_cleanup_module(void)
866 video_unregister_device(&ar
->vdev
);
868 free_irq(M32R_IRQ_INT3
, ar
);
870 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++)
873 kfree(ar
->line_buff
);
875 v4l2_device_unregister(&ar
->v4l2_dev
);
878 module_init(ar_init_module
);
879 module_exit(ar_cleanup_module
);
881 MODULE_AUTHOR("Takeo Takahashi <takahashi.takeo@renesas.com>");
882 MODULE_DESCRIPTION("Colour AR M64278(VGA) for Video4Linux");
883 MODULE_LICENSE("GPL");
884 MODULE_VERSION(VERSION
);