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/videodev.h>
31 #include <media/v4l2-common.h>
32 #include <linux/mutex.h>
34 #include <asm/uaccess.h>
38 #include <asm/byteorder.h>
41 #define DEBUG(n, args...) printk(args)
44 #define DEBUG(n, args...)
49 * USE_INT is always 0, interrupt mode is not available
50 * on linux due to lack of speed
52 #define USE_INT 0 /* Don't modify */
54 #define VERSION "0.03"
56 #define ar_inl(addr) inl((unsigned long)(addr))
57 #define ar_outl(val, addr) outl((unsigned long)(val),(unsigned long)(addr))
59 extern struct cpuinfo_m32r boot_cpu_data
;
63 * Note that M32700UT does not support CIF mode, but QVGA is
64 * supported by M32700UT hardware using VGA mode of AR LSI.
66 * Supported: VGA (Normal mode, Interlace mode)
67 * QVGA (Always Interlace mode of VGA)
70 #define AR_WIDTH_VGA 640
71 #define AR_HEIGHT_VGA 480
72 #define AR_WIDTH_QVGA 320
73 #define AR_HEIGHT_QVGA 240
74 #define MIN_AR_WIDTH AR_WIDTH_QVGA
75 #define MIN_AR_HEIGHT AR_HEIGHT_QVGA
76 #define MAX_AR_WIDTH AR_WIDTH_VGA
77 #define MAX_AR_HEIGHT AR_HEIGHT_VGA
79 /* bits & bytes per pixel */
80 #define AR_BITS_PER_PIXEL 16
81 #define AR_BYTES_PER_PIXEL (AR_BITS_PER_PIXEL/8)
83 /* line buffer size */
84 #define AR_LINE_BYTES_VGA (AR_WIDTH_VGA * AR_BYTES_PER_PIXEL)
85 #define AR_LINE_BYTES_QVGA (AR_WIDTH_QVGA * AR_BYTES_PER_PIXEL)
86 #define MAX_AR_LINE_BYTES AR_LINE_BYTES_VGA
88 /* frame size & type */
89 #define AR_FRAME_BYTES_VGA \
90 (AR_WIDTH_VGA * AR_HEIGHT_VGA * AR_BYTES_PER_PIXEL)
91 #define AR_FRAME_BYTES_QVGA \
92 (AR_WIDTH_QVGA * AR_HEIGHT_QVGA * AR_BYTES_PER_PIXEL)
93 #define MAX_AR_FRAME_BYTES \
94 (MAX_AR_WIDTH * MAX_AR_HEIGHT * AR_BYTES_PER_PIXEL)
96 #define AR_MAX_FRAME 15
100 #define AR_SIZE_QVGA 1
103 #define AR_MODE_INTERLACE 0
104 #define AR_MODE_NORMAL 1
107 struct video_device
*vdev
;
108 unsigned int start_capture
; /* duaring capture in INT. mode. */
110 unsigned char *line_buff
; /* DMA line buffer */
112 unsigned char *frame
[MAX_AR_HEIGHT
]; /* frame data */
113 short size
; /* capture size */
114 short mode
; /* capture mode */
116 int frame_bytes
, line_bytes
;
117 wait_queue_head_t wait
;
121 static int video_nr
= -1; /* video device number (first free) */
122 static unsigned char yuv
[MAX_AR_FRAME_BYTES
];
124 /* module parameters */
125 /* default frequency */
126 #define DEFAULT_FREQ 50 /* 50 or 75 (MHz) is available as BCLK */
127 static int freq
= DEFAULT_FREQ
; /* BCLK: available 50 or 70 (MHz) */
128 static int vga
= 0; /* default mode(0:QVGA mode, other:VGA mode) */
129 static int vga_interlace
= 0; /* 0 is normal mode for, else interlace mode */
130 module_param(freq
, int, 0);
131 module_param(vga
, int, 0);
132 module_param(vga_interlace
, int, 0);
134 static int ar_initialize(struct video_device
*dev
);
136 static inline void wait_for_vsync(void)
138 while (ar_inl(ARVCR0
) & ARVCR0_VDS
) /* wait for VSYNC */
140 while (!(ar_inl(ARVCR0
) & ARVCR0_VDS
)) /* wait for VSYNC */
144 static inline void wait_acknowledge(void)
148 for (i
= 0; i
< 1000; i
++)
150 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_NOACK
)
154 /*******************************************************************
156 *******************************************************************/
157 void iic(int n
, unsigned long addr
, unsigned long data1
, unsigned long data2
,
163 ar_outl(addr
, PLDI2CDATA
);
167 ar_outl(1, PLDI2CCND
);
170 /* Transfer data 1 */
171 ar_outl(data1
, PLDI2CDATA
);
173 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
176 /* Transfer data 2 */
177 ar_outl(data2
, PLDI2CDATA
);
179 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
183 /* Transfer data 3 */
184 ar_outl(data3
, PLDI2CDATA
);
186 ar_outl(PLDI2CSTEN_STEN
, PLDI2CSTEN
);
191 for (i
= 0; i
< 100; i
++)
193 ar_outl(2, PLDI2CCND
);
194 ar_outl(2, PLDI2CCND
);
196 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_BB
)
203 DEBUG(1, "init_iic:\n");
209 ar_outl(0x0, PLDI2CCR
); /* I2CCR Disable */
210 ar_outl(0x0300, PLDI2CMOD
); /* I2CMOD ACK/8b-data/7b-addr/auto */
211 ar_outl(0x1, PLDI2CACK
); /* I2CACK ACK */
216 ar_outl(369, PLDI2CFREQ
); /* BCLK = 75MHz */
217 } else if (freq
== 50) {
218 ar_outl(244, PLDI2CFREQ
); /* BCLK = 50MHz */
220 ar_outl(244, PLDI2CFREQ
); /* default: BCLK = 50MHz */
222 ar_outl(0x1, PLDI2CCR
); /* I2CCR Enable */
225 /**************************************************************************
227 * Video4Linux Interface functions
229 **************************************************************************/
231 static inline void disable_dma(void)
233 ar_outl(0x8000, M32R_DMAEN_PORTL
); /* disable DMA0 */
236 static inline void enable_dma(void)
238 ar_outl(0x8080, M32R_DMAEN_PORTL
); /* enable DMA0 */
241 static inline void clear_dma_status(void)
243 ar_outl(0x8000, M32R_DMAEDET_PORTL
); /* clear status */
246 static inline void wait_for_vertical_sync(int exp_line
)
249 int tmout
= 10000; /* FIXME */
253 * check HCOUNT because we cannot check vertical sync.
255 for (; tmout
>= 0; tmout
--) {
256 l
= ar_inl(ARVHCOUNT
);
261 printk("arv: lost %d -> %d\n", exp_line
, l
);
263 while (ar_inl(ARVHCOUNT
) != exp_line
)
268 static ssize_t
ar_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
270 struct video_device
*v
= video_devdata(file
);
271 struct ar_device
*ar
= v
->priv
;
272 long ret
= ar
->frame_bytes
; /* return read bytes */
273 unsigned long arvcr1
= 0;
277 unsigned char *py
, *pu
, *pv
;
282 DEBUG(1, "ar_read()\n");
284 if (ar
->size
== AR_SIZE_QVGA
)
285 arvcr1
|= ARVCR1_QVGA
;
286 if (ar
->mode
== AR_MODE_NORMAL
)
287 arvcr1
|= ARVCR1_NORMAL
;
289 mutex_lock(&ar
->lock
);
292 local_irq_save(flags
);
294 ar_outl(0xa1871300, M32R_DMA0CR0_PORTL
);
295 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
297 /* set AR FIFO address as source(BSEL5) */
298 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
299 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
300 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* destination addr. */
301 ar_outl(ar
->line_buff
, M32R_DMA0RDA_PORTL
); /* reload address */
302 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
); /* byte count (bytes) */
303 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
); /* reload count (bytes) */
306 * Okey , kicks AR LSI to invoke an interrupt
308 ar
->start_capture
= 0;
309 ar_outl(arvcr1
| ARVCR1_HIEN
, ARVCR1
);
310 local_irq_restore(flags
);
311 /* .... AR interrupts .... */
312 interruptible_sleep_on(&ar
->wait
);
313 if (signal_pending(current
)) {
314 printk("arv: interrupted while get frame data.\n");
318 #else /* ! USE_INT */
320 ar_outl(arvcr1
, ARVCR1
);
322 ar_outl(0x8000, M32R_DMAEDET_PORTL
);
323 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
324 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
325 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
326 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
327 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
);
328 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
);
330 local_irq_save(flags
);
331 while (ar_inl(ARVHCOUNT
) != 0) /* wait for 0 */
333 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
334 for (h
= 0; h
< ar
->height
; h
++) {
335 wait_for_vertical_sync(h
);
336 if (h
< (AR_HEIGHT_VGA
/2))
339 l
= (((h
- (AR_HEIGHT_VGA
/2)) << 1) + 1);
340 ar_outl(virt_to_phys(ar
->frame
[l
]), M32R_DMA0CDA_PORTL
);
342 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
346 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
349 for (h
= 0; h
< ar
->height
; h
++) {
350 wait_for_vertical_sync(h
);
351 ar_outl(virt_to_phys(ar
->frame
[h
]), M32R_DMA0CDA_PORTL
);
353 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
357 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
360 local_irq_restore(flags
);
361 #endif /* ! USE_INT */
364 * convert YUV422 to YUV422P
365 * +--------------------+
367 * | ..............Yn |
368 * +--------------------+
369 * | U0,U1,........Un |
370 * +--------------------+
371 * | V0,V1,........Vn |
372 * +--------------------+
375 pu
= py
+ (ar
->frame_bytes
/ 2);
376 pv
= pu
+ (ar
->frame_bytes
/ 4);
377 for (h
= 0; h
< ar
->height
; h
++) {
379 for (w
= 0; w
< ar
->line_bytes
; w
+= 4) {
386 if (copy_to_user(buf
, yuv
, ar
->frame_bytes
)) {
387 printk("arv: failed while copy_to_user yuv.\n");
391 DEBUG(1, "ret = %d\n", ret
);
393 mutex_unlock(&ar
->lock
);
397 static int ar_do_ioctl(struct inode
*inode
, struct file
*file
,
398 unsigned int cmd
, void *arg
)
400 struct video_device
*dev
= video_devdata(file
);
401 struct ar_device
*ar
= dev
->priv
;
403 DEBUG(1, "ar_ioctl()\n");
407 struct video_capability
*b
= arg
;
408 DEBUG(1, "VIDIOCGCAP:\n");
409 strcpy(b
->name
, ar
->vdev
->name
);
410 b
->type
= VID_TYPE_CAPTURE
;
413 b
->maxwidth
= MAX_AR_WIDTH
;
414 b
->maxheight
= MAX_AR_HEIGHT
;
415 b
->minwidth
= MIN_AR_WIDTH
;
416 b
->minheight
= MIN_AR_HEIGHT
;
420 DEBUG(1, "VIDIOCGCHAN:\n");
423 DEBUG(1, "VIDIOCSCHAN:\n");
426 DEBUG(1, "VIDIOCGTUNER:\n");
429 DEBUG(1, "VIDIOCSTUNER:\n");
432 DEBUG(1, "VIDIOCGPICT:\n");
435 DEBUG(1, "VIDIOCSPICT:\n");
438 DEBUG(1, "VIDIOCCAPTURE:\n");
442 struct video_window
*w
= arg
;
443 DEBUG(1, "VIDIOCGWIN:\n");
444 memset(w
, 0, sizeof(*w
));
445 w
->width
= ar
->width
;
446 w
->height
= ar
->height
;
451 struct video_window
*w
= arg
;
452 DEBUG(1, "VIDIOCSWIN:\n");
453 if ((w
->width
!= AR_WIDTH_VGA
|| w
->height
!= AR_HEIGHT_VGA
) &&
454 (w
->width
!= AR_WIDTH_QVGA
|| w
->height
!= AR_HEIGHT_QVGA
))
457 mutex_lock(&ar
->lock
);
458 ar
->width
= w
->width
;
459 ar
->height
= w
->height
;
460 if (ar
->width
== AR_WIDTH_VGA
) {
461 ar
->size
= AR_SIZE_VGA
;
462 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
463 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
465 ar
->mode
= AR_MODE_INTERLACE
;
467 ar
->mode
= AR_MODE_NORMAL
;
469 ar
->size
= AR_SIZE_QVGA
;
470 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
471 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
472 ar
->mode
= AR_MODE_INTERLACE
;
474 mutex_unlock(&ar
->lock
);
478 DEBUG(1, "VIDIOCGFBUF:\n");
481 DEBUG(1, "VIDIOCSFBUF:\n");
484 DEBUG(1, "VIDIOCKEY:\n");
487 DEBUG(1, "VIDIOCGFREQ:\n");
490 DEBUG(1, "VIDIOCSFREQ:\n");
493 DEBUG(1, "VIDIOCGAUDIO:\n");
496 DEBUG(1, "VIDIOCSAUDIO:\n");
499 DEBUG(1, "VIDIOCSYNC:\n");
502 DEBUG(1, "VIDIOCMCAPTURE:\n");
505 DEBUG(1, "VIDIOCGMBUF:\n");
508 DEBUG(1, "VIDIOCGUNIT:\n");
511 DEBUG(1, "VIDIOCGCAPTURE:\n");
514 DEBUG(1, "VIDIOCSCAPTURE:\n");
516 case VIDIOCSPLAYMODE
:
517 DEBUG(1, "VIDIOCSPLAYMODE:\n");
519 case VIDIOCSWRITEMODE
:
520 DEBUG(1, "VIDIOCSWRITEMODE:\n");
522 case VIDIOCGPLAYINFO
:
523 DEBUG(1, "VIDIOCGPLAYINFO:\n");
525 case VIDIOCSMICROCODE
:
526 DEBUG(1, "VIDIOCSMICROCODE:\n");
529 DEBUG(1, "VIDIOCGVBIFMT:\n");
532 DEBUG(1, "VIDIOCSVBIFMT:\n");
535 DEBUG(1, "Unknown ioctl(0x%08x)\n", cmd
);
541 static int ar_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
544 return video_usercopy(inode
, file
, cmd
, arg
, ar_do_ioctl
);
551 static void ar_interrupt(int irq
, void *dev
)
553 struct ar_device
*ar
= dev
;
554 unsigned int line_count
;
555 unsigned int line_number
;
558 line_count
= ar_inl(ARVHCOUNT
); /* line number */
559 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
560 /* operations for interlace mode */
561 if ( line_count
< (AR_HEIGHT_VGA
/2) ) /* even line */
562 line_number
= (line_count
<< 1);
565 (((line_count
- (AR_HEIGHT_VGA
/2)) << 1) + 1);
567 line_number
= line_count
;
570 if (line_number
== 0) {
572 * It is an interrupt for line 0.
573 * we have to start capture.
577 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* needless? */
579 memcpy(ar
->frame
[0], ar
->line_buff
, ar
->line_bytes
);
581 ar_outl(0xa1861300, M32R_DMA0CR0_PORTL
);
584 ar
->start_capture
= 1; /* during capture */
588 if (ar
->start_capture
== 1 && line_number
<= (ar
->height
- 1)) {
590 memcpy(ar
->frame
[line_number
], ar
->line_buff
, ar
->line_bytes
);
593 * if captured all line of a frame, disable AR interrupt
594 * and wake a process up.
596 if (line_number
== (ar
->height
- 1)) { /* end of line */
598 ar
->start_capture
= 0;
600 /* disable AR interrupt request */
601 arvcr1
= ar_inl(ARVCR1
);
602 arvcr1
&= ~ARVCR1_HIEN
; /* clear int. flag */
603 ar_outl(arvcr1
, ARVCR1
); /* disable */
604 wake_up_interruptible(&ar
->wait
);
607 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
);
608 ar_outl(0xa1861300, M32R_DMA0CR0_PORTL
);
618 * ar_initialize() is called by video_register_device() and
619 * initializes AR LSI and peripherals.
621 * -1 is returned in all failures.
622 * 0 is returned in success.
625 static int ar_initialize(struct video_device
*dev
)
627 struct ar_device
*ar
= dev
->priv
;
628 unsigned long cr
= 0;
631 DEBUG(1, "ar_initialize:\n");
636 ar_outl(0, ARVCR0
); /* assert reset of AR LSI */
637 for (i
= 0; i
< 0x18; i
++) /* wait for over 10 cycles @ 27MHz */
639 ar_outl(ARVCR0_RST
, ARVCR0
); /* negate reset of AR LSI (enable) */
640 for (i
= 0; i
< 0x40d; i
++) /* wait for over 420 cycles @ 27MHz */
643 /* AR uses INT3 of CPU as interrupt pin. */
644 ar_outl(ARINTSEL_INT3
, ARINTSEL
);
646 if (ar
->size
== AR_SIZE_QVGA
)
648 if (ar
->mode
== AR_MODE_NORMAL
)
653 * Initialize IIC so that CPU can communicate with AR LSI,
654 * and send boot commands to AR LSI.
658 for (i
= 0; i
< 0x100000; i
++) { /* > 0xa1d10, 56ms */
659 if ((ar_inl(ARVCR0
) & ARVCR0_VDS
)) { /* VSYNC */
668 printk("arv: Initializing ");
670 iic(2,0x78,0x11,0x01,0x00); /* start */
671 iic(3,0x78,0x12,0x00,0x06);
672 iic(3,0x78,0x12,0x12,0x30);
673 iic(3,0x78,0x12,0x15,0x58);
674 iic(3,0x78,0x12,0x17,0x30);
676 iic(3,0x78,0x12,0x1a,0x97);
677 iic(3,0x78,0x12,0x1b,0xff);
678 iic(3,0x78,0x12,0x1c,0xff);
679 iic(3,0x78,0x12,0x26,0x10);
680 iic(3,0x78,0x12,0x27,0x00);
682 iic(2,0x78,0x34,0x02,0x00);
683 iic(2,0x78,0x7a,0x10,0x00);
684 iic(2,0x78,0x80,0x39,0x00);
685 iic(2,0x78,0x81,0xe6,0x00);
686 iic(2,0x78,0x8d,0x00,0x00);
688 iic(2,0x78,0x8e,0x0c,0x00);
689 iic(2,0x78,0x8f,0x00,0x00);
691 iic(2,0x78,0x90,0x00,0x00); /* AWB on=1 off=0 */
693 iic(2,0x78,0x93,0x01,0x00);
694 iic(2,0x78,0x94,0xcd,0x00);
695 iic(2,0x78,0x95,0x00,0x00);
697 iic(2,0x78,0x96,0xa0,0x00);
698 iic(2,0x78,0x97,0x00,0x00);
699 iic(2,0x78,0x98,0x60,0x00);
700 iic(2,0x78,0x99,0x01,0x00);
701 iic(2,0x78,0x9a,0x19,0x00);
703 iic(2,0x78,0x9b,0x02,0x00);
704 iic(2,0x78,0x9c,0xe8,0x00);
705 iic(2,0x78,0x9d,0x02,0x00);
706 iic(2,0x78,0x9e,0x2e,0x00);
707 iic(2,0x78,0xb8,0x78,0x00);
708 iic(2,0x78,0xba,0x05,0x00);
710 iic(2,0x78,0x83,0x8c,0x00); /* brightness */
714 /* color correction */
715 iic(3,0x78,0x49,0x00,0x95); /* a */
716 iic(3,0x78,0x49,0x01,0x96); /* b */
717 iic(3,0x78,0x49,0x03,0x85); /* c */
718 iic(3,0x78,0x49,0x04,0x97); /* d */
719 iic(3,0x78,0x49,0x02,0x7e); /* e(Lo) */
720 iic(3,0x78,0x49,0x05,0xa4); /* f(Lo) */
721 iic(3,0x78,0x49,0x06,0x04); /* e(Hi) */
722 iic(3,0x78,0x49,0x07,0x04); /* e(Hi) */
723 iic(2,0x78,0x48,0x01,0x00); /* on=1 off=0 */
726 iic(2,0x78,0x11,0x00,0x00); /* end */
732 void ar_release(struct video_device
*vfd
)
734 struct ar_device
*ar
= vfd
->priv
;
735 mutex_lock(&ar
->lock
);
736 video_device_release(vfd
);
739 /****************************************************************************
741 * Video4Linux Module functions
743 ****************************************************************************/
744 static const struct file_operations ar_fops
= {
745 .owner
= THIS_MODULE
,
746 .open
= video_exclusive_open
,
747 .release
= video_exclusive_release
,
750 .compat_ioctl
= v4l_compat_ioctl32
,
754 static struct video_device ar_template
= {
755 .owner
= THIS_MODULE
,
756 .name
= "Colour AR VGA",
757 .type
= VID_TYPE_CAPTURE
,
758 .hardware
= VID_HARDWARE_ARV
,
760 .release
= ar_release
,
764 #define ALIGN4(x) ((((int)(x)) & 0x3) == 0)
765 static struct ar_device ardev
;
767 static int __init
ar_init(void)
769 struct ar_device
*ar
;
773 DEBUG(1, "ar_init:\n");
775 printk(KERN_INFO
"arv: Colour AR VGA driver %s\n", VERSION
);
778 memset(ar
, 0, sizeof(struct ar_device
));
781 /* allocate a DMA buffer for 1 line. */
782 ar
->line_buff
= kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
| GFP_DMA
);
783 if (ar
->line_buff
== NULL
|| ! ALIGN4(ar
->line_buff
)) {
784 printk("arv: buffer allocation failed for DMA.\n");
789 /* allocate buffers for a frame */
790 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++) {
791 ar
->frame
[i
] = kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
);
792 if (ar
->frame
[i
] == NULL
|| ! ALIGN4(ar
->frame
[i
])) {
793 printk("arv: buffer allocation failed for frame.\n");
799 ar
->vdev
= video_device_alloc();
801 printk(KERN_ERR
"arv: video_device_alloc() failed\n");
804 memcpy(ar
->vdev
, &ar_template
, sizeof(ar_template
));
808 ar
->width
= AR_WIDTH_VGA
;
809 ar
->height
= AR_HEIGHT_VGA
;
810 ar
->size
= AR_SIZE_VGA
;
811 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
812 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
814 ar
->mode
= AR_MODE_INTERLACE
;
816 ar
->mode
= AR_MODE_NORMAL
;
818 ar
->width
= AR_WIDTH_QVGA
;
819 ar
->height
= AR_HEIGHT_QVGA
;
820 ar
->size
= AR_SIZE_QVGA
;
821 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
822 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
823 ar
->mode
= AR_MODE_INTERLACE
;
825 mutex_init(&ar
->lock
);
826 init_waitqueue_head(&ar
->wait
);
829 if (request_irq(M32R_IRQ_INT3
, ar_interrupt
, 0, "arv", ar
)) {
830 printk("arv: request_irq(%d) failed.\n", M32R_IRQ_INT3
);
836 if (ar_initialize(ar
->vdev
) != 0) {
837 printk("arv: M64278 not found.\n");
843 * ok, we can initialize h/w according to parameters,
844 * so register video device as a frame grabber type.
845 * device is named "video[0-64]".
846 * video_register_device() initializes h/w using ar_initialize().
848 if (video_register_device(ar
->vdev
, VFL_TYPE_GRABBER
, video_nr
) != 0) {
849 /* return -1, -ENFILE(full) or others */
850 printk("arv: register video (Colour AR) failed.\n");
855 printk("video%d: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
856 ar
->vdev
->minor
, M32R_IRQ_INT3
, freq
);
862 free_irq(M32R_IRQ_INT3
, ar
);
866 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++)
871 kfree(ar
->line_buff
);
879 static int __init
ar_init_module(void)
881 freq
= (boot_cpu_data
.bus_clock
/ 1000000);
882 printk("arv: Bus clock %d\n", freq
);
883 if (freq
!= 50 && freq
!= 75)
888 static void __exit
ar_cleanup_module(void)
890 struct ar_device
*ar
;
894 video_unregister_device(ar
->vdev
);
896 free_irq(M32R_IRQ_INT3
, ar
);
898 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++)
901 kfree(ar
->line_buff
);
905 module_init(ar_init_module
);
906 module_exit(ar_cleanup_module
);
908 MODULE_AUTHOR("Takeo Takahashi <takahashi.takeo@renesas.com>");
909 MODULE_DESCRIPTION("Colour AR M64278(VGA) for Video4Linux");
910 MODULE_LICENSE("GPL");