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/config.h>
22 #include <linux/init.h>
23 #include <linux/devfs_fs_kernel.h>
24 #include <linux/module.h>
25 #include <linux/version.h>
26 #include <linux/delay.h>
27 #include <linux/errno.h>
29 #include <linux/init.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
33 #include <linux/sched.h>
34 #include <linux/videodev.h>
36 #include <asm/semaphore.h>
37 #include <asm/uaccess.h>
41 #include <asm/byteorder.h>
44 #define DEBUG(n, args...) printk(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.03"
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 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
;
121 struct semaphore lock
;
124 static int video_nr
= -1; /* video device number (first free) */
125 static unsigned char yuv
[MAX_AR_FRAME_BYTES
];
127 /* module parameters */
128 /* default frequency */
129 #define DEFAULT_FREQ 50 /* 50 or 75 (MHz) is available as BCLK */
130 static int freq
= DEFAULT_FREQ
; /* BCLK: available 50 or 70 (MHz) */
131 static int vga
= 0; /* default mode(0:QVGA mode, other:VGA mode) */
132 static int vga_interlace
= 0; /* 0 is normal mode for, else interlace mode */
133 MODULE_PARM(freq
, "i");
134 MODULE_PARM(vga
, "i");
135 MODULE_PARM(vga_interlace
, "i");
137 static int ar_initialize(struct video_device
*dev
);
139 static inline 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 inline void wait_acknowledge(void)
151 for (i
= 0; i
< 1000; i
++)
153 while (ar_inl(PLDI2CSTS
) & PLDI2CSTS_NOACK
)
157 /*******************************************************************
159 *******************************************************************/
160 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
)
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 */
220 } else if (freq
== 50) {
221 ar_outl(244, PLDI2CFREQ
); /* BCLK = 50MHz */
223 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 inline void wait_for_vertical_sync(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 printk("arv: 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 video_device
*v
= video_devdata(file
);
274 struct ar_device
*ar
= v
->priv
;
275 long ret
= ar
->frame_bytes
; /* return read bytes */
276 unsigned long arvcr1
= 0;
280 unsigned char *py
, *pu
, *pv
;
285 DEBUG(1, "ar_read()\n");
287 if (ar
->size
== AR_SIZE_QVGA
)
288 arvcr1
|= ARVCR1_QVGA
;
289 if (ar
->mode
== AR_MODE_NORMAL
)
290 arvcr1
|= ARVCR1_NORMAL
;
295 local_irq_save(flags
);
297 ar_outl(0xa1871300, M32R_DMA0CR0_PORTL
);
298 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
300 /* set AR FIFO address as source(BSEL5) */
301 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
302 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
303 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* destination addr. */
304 ar_outl(ar
->line_buff
, M32R_DMA0RDA_PORTL
); /* reload address */
305 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
); /* byte count (bytes) */
306 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
); /* reload count (bytes) */
309 * Okey , kicks AR LSI to invoke an interrupt
311 ar
->start_capture
= 0;
312 ar_outl(arvcr1
| ARVCR1_HIEN
, ARVCR1
);
313 local_irq_restore(flags
);
314 /* .... AR interrupts .... */
315 interruptible_sleep_on(&ar
->wait
);
316 if (signal_pending(current
)) {
317 printk("arv: interrupted while get frame data.\n");
321 #else /* ! USE_INT */
323 ar_outl(arvcr1
, ARVCR1
);
325 ar_outl(0x8000, M32R_DMAEDET_PORTL
);
326 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
327 ar_outl(0x01000000, M32R_DMA0CR1_PORTL
);
328 ar_outl(ARDATA32
, M32R_DMA0CSA_PORTL
);
329 ar_outl(ARDATA32
, M32R_DMA0RSA_PORTL
);
330 ar_outl(ar
->line_bytes
, M32R_DMA0CBCUT_PORTL
);
331 ar_outl(ar
->line_bytes
, M32R_DMA0RBCUT_PORTL
);
333 local_irq_save(flags
);
334 while (ar_inl(ARVHCOUNT
) != 0) /* wait for 0 */
336 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
337 for (h
= 0; h
< ar
->height
; h
++) {
338 wait_for_vertical_sync(h
);
339 if (h
< (AR_HEIGHT_VGA
/2))
342 l
= (((h
- (AR_HEIGHT_VGA
/2)) << 1) + 1);
343 ar_outl(virt_to_phys(ar
->frame
[l
]), M32R_DMA0CDA_PORTL
);
345 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
349 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
352 for (h
= 0; h
< ar
->height
; h
++) {
353 wait_for_vertical_sync(h
);
354 ar_outl(virt_to_phys(ar
->frame
[h
]), M32R_DMA0CDA_PORTL
);
356 while (!(ar_inl(M32R_DMAEDET_PORTL
) & 0x8000))
360 ar_outl(0xa0861300, M32R_DMA0CR0_PORTL
);
363 local_irq_restore(flags
);
364 #endif /* ! USE_INT */
367 * convert YUV422 to YUV422P
368 * +--------------------+
370 * | ..............Yn |
371 * +--------------------+
372 * | U0,U1,........Un |
373 * +--------------------+
374 * | V0,V1,........Vn |
375 * +--------------------+
378 pu
= py
+ (ar
->frame_bytes
/ 2);
379 pv
= pu
+ (ar
->frame_bytes
/ 4);
380 for (h
= 0; h
< ar
->height
; h
++) {
382 for (w
= 0; w
< ar
->line_bytes
; w
+= 4) {
389 if (copy_to_user(buf
, yuv
, ar
->frame_bytes
)) {
390 printk("arv: failed while copy_to_user yuv.\n");
394 DEBUG(1, "ret = %d\n", ret
);
400 static int ar_do_ioctl(struct inode
*inode
, struct file
*file
,
401 unsigned int cmd
, void *arg
)
403 struct video_device
*dev
= video_devdata(file
);
404 struct ar_device
*ar
= dev
->priv
;
406 DEBUG(1, "ar_ioctl()\n");
410 struct video_capability
*b
= arg
;
411 DEBUG(1, "VIDIOCGCAP:\n");
412 strcpy(b
->name
, ar
->vdev
->name
);
413 b
->type
= VID_TYPE_CAPTURE
;
416 b
->maxwidth
= MAX_AR_WIDTH
;
417 b
->maxheight
= MAX_AR_HEIGHT
;
418 b
->minwidth
= MIN_AR_WIDTH
;
419 b
->minheight
= MIN_AR_HEIGHT
;
423 DEBUG(1, "VIDIOCGCHAN:\n");
426 DEBUG(1, "VIDIOCSCHAN:\n");
429 DEBUG(1, "VIDIOCGTUNER:\n");
432 DEBUG(1, "VIDIOCSTUNER:\n");
435 DEBUG(1, "VIDIOCGPICT:\n");
438 DEBUG(1, "VIDIOCSPICT:\n");
441 DEBUG(1, "VIDIOCCAPTURE:\n");
445 struct video_window
*w
= arg
;
446 DEBUG(1, "VIDIOCGWIN:\n");
447 memset(w
, 0, sizeof(w
));
448 w
->width
= ar
->width
;
449 w
->height
= ar
->height
;
454 struct video_window
*w
= arg
;
455 DEBUG(1, "VIDIOCSWIN:\n");
456 if ((w
->width
!= AR_WIDTH_VGA
|| w
->height
!= AR_HEIGHT_VGA
) &&
457 (w
->width
!= AR_WIDTH_QVGA
|| w
->height
!= AR_HEIGHT_QVGA
))
461 ar
->width
= w
->width
;
462 ar
->height
= w
->height
;
463 if (ar
->width
== AR_WIDTH_VGA
) {
464 ar
->size
= AR_SIZE_VGA
;
465 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
466 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
468 ar
->mode
= AR_MODE_INTERLACE
;
470 ar
->mode
= AR_MODE_NORMAL
;
472 ar
->size
= AR_SIZE_QVGA
;
473 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
474 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
475 ar
->mode
= AR_MODE_INTERLACE
;
481 DEBUG(1, "VIDIOCGFBUF:\n");
484 DEBUG(1, "VIDIOCSFBUF:\n");
487 DEBUG(1, "VIDIOCKEY:\n");
490 DEBUG(1, "VIDIOCGFREQ:\n");
493 DEBUG(1, "VIDIOCSFREQ:\n");
496 DEBUG(1, "VIDIOCGAUDIO:\n");
499 DEBUG(1, "VIDIOCSAUDIO:\n");
502 DEBUG(1, "VIDIOCSYNC:\n");
505 DEBUG(1, "VIDIOCMCAPTURE:\n");
508 DEBUG(1, "VIDIOCGMBUF:\n");
511 DEBUG(1, "VIDIOCGUNIT:\n");
514 DEBUG(1, "VIDIOCGCAPTURE:\n");
517 DEBUG(1, "VIDIOCSCAPTURE:\n");
519 case VIDIOCSPLAYMODE
:
520 DEBUG(1, "VIDIOCSPLAYMODE:\n");
522 case VIDIOCSWRITEMODE
:
523 DEBUG(1, "VIDIOCSWRITEMODE:\n");
525 case VIDIOCGPLAYINFO
:
526 DEBUG(1, "VIDIOCGPLAYINFO:\n");
528 case VIDIOCSMICROCODE
:
529 DEBUG(1, "VIDIOCSMICROCODE:\n");
532 DEBUG(1, "VIDIOCGVBIFMT:\n");
535 DEBUG(1, "VIDIOCSVBIFMT:\n");
538 DEBUG(1, "Unknown ioctl(0x%08x)\n", cmd
);
544 static int ar_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
547 return video_usercopy(inode
, file
, cmd
, arg
, ar_do_ioctl
);
554 static void ar_interrupt(int irq
, void *dev
, struct pt_regs
*regs
)
556 struct ar_device
*ar
= dev
;
557 unsigned int line_count
;
558 unsigned int line_number
;
561 line_count
= ar_inl(ARVHCOUNT
); /* line number */
562 if (ar
->mode
== AR_MODE_INTERLACE
&& ar
->size
== AR_SIZE_VGA
) {
563 /* operations for interlace mode */
564 if ( line_count
< (AR_HEIGHT_VGA
/2) ) /* even line */
565 line_number
= (line_count
<< 1);
568 (((line_count
- (AR_HEIGHT_VGA
/2)) << 1) + 1);
570 line_number
= line_count
;
573 if (line_number
== 0) {
575 * It is an interrupt for line 0.
576 * we have to start capture.
580 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
); /* needless? */
582 memcpy(ar
->frame
[0], ar
->line_buff
, ar
->line_bytes
);
584 ar_outl(0xa1861300, M32R_DMA0CR0_PORTL
);
587 ar
->start_capture
= 1; /* during capture */
591 if (ar
->start_capture
== 1 && line_number
<= (ar
->height
- 1)) {
593 memcpy(ar
->frame
[line_number
], ar
->line_buff
, ar
->line_bytes
);
596 * if captured all line of a frame, disable AR interrupt
597 * and wake a process up.
599 if (line_number
== (ar
->height
- 1)) { /* end of line */
601 ar
->start_capture
= 0;
603 /* disable AR interrupt request */
604 arvcr1
= ar_inl(ARVCR1
);
605 arvcr1
&= ~ARVCR1_HIEN
; /* clear int. flag */
606 ar_outl(arvcr1
, ARVCR1
); /* disable */
607 wake_up_interruptible(&ar
->wait
);
610 ar_outl(ar
->line_buff
, M32R_DMA0CDA_PORTL
);
611 ar_outl(0xa1861300, M32R_DMA0CR0_PORTL
);
621 * ar_initialize() is called by video_register_device() and
622 * initializes AR LSI and peripherals.
624 * -1 is returned in all failures.
625 * 0 is returned in success.
628 static int ar_initialize(struct video_device
*dev
)
630 struct ar_device
*ar
= dev
->priv
;
631 unsigned long cr
= 0;
634 DEBUG(1, "ar_initialize:\n");
639 ar_outl(0, ARVCR0
); /* assert reset of AR LSI */
640 for (i
= 0; i
< 0x18; i
++) /* wait for over 10 cycles @ 27MHz */
642 ar_outl(ARVCR0_RST
, ARVCR0
); /* negate reset of AR LSI (enable) */
643 for (i
= 0; i
< 0x40d; i
++) /* wait for over 420 cycles @ 27MHz */
646 /* AR uses INT3 of CPU as interrupt pin. */
647 ar_outl(ARINTSEL_INT3
, ARINTSEL
);
649 if (ar
->size
== AR_SIZE_QVGA
)
651 if (ar
->mode
== AR_MODE_NORMAL
)
656 * Initialize IIC so that CPU can communicate with AR LSI,
657 * and send boot commands to AR LSI.
661 for (i
= 0; i
< 0x100000; i
++) { /* > 0xa1d10, 56ms */
662 if ((ar_inl(ARVCR0
) & ARVCR0_VDS
)) { /* VSYNC */
671 printk("arv: Initializing ");
673 iic(2,0x78,0x11,0x01,0x00); /* start */
674 iic(3,0x78,0x12,0x00,0x06);
675 iic(3,0x78,0x12,0x12,0x30);
676 iic(3,0x78,0x12,0x15,0x58);
677 iic(3,0x78,0x12,0x17,0x30);
679 iic(3,0x78,0x12,0x1a,0x97);
680 iic(3,0x78,0x12,0x1b,0xff);
681 iic(3,0x78,0x12,0x1c,0xff);
682 iic(3,0x78,0x12,0x26,0x10);
683 iic(3,0x78,0x12,0x27,0x00);
685 iic(2,0x78,0x34,0x02,0x00);
686 iic(2,0x78,0x7a,0x10,0x00);
687 iic(2,0x78,0x80,0x39,0x00);
688 iic(2,0x78,0x81,0xe6,0x00);
689 iic(2,0x78,0x8d,0x00,0x00);
691 iic(2,0x78,0x8e,0x0c,0x00);
692 iic(2,0x78,0x8f,0x00,0x00);
694 iic(2,0x78,0x90,0x00,0x00); /* AWB on=1 off=0 */
696 iic(2,0x78,0x93,0x01,0x00);
697 iic(2,0x78,0x94,0xcd,0x00);
698 iic(2,0x78,0x95,0x00,0x00);
700 iic(2,0x78,0x96,0xa0,0x00);
701 iic(2,0x78,0x97,0x00,0x00);
702 iic(2,0x78,0x98,0x60,0x00);
703 iic(2,0x78,0x99,0x01,0x00);
704 iic(2,0x78,0x9a,0x19,0x00);
706 iic(2,0x78,0x9b,0x02,0x00);
707 iic(2,0x78,0x9c,0xe8,0x00);
708 iic(2,0x78,0x9d,0x02,0x00);
709 iic(2,0x78,0x9e,0x2e,0x00);
710 iic(2,0x78,0xb8,0x78,0x00);
711 iic(2,0x78,0xba,0x05,0x00);
713 iic(2,0x78,0x83,0x8c,0x00); /* brightness */
717 /* color correction */
718 iic(3,0x78,0x49,0x00,0x95); /* a */
719 iic(3,0x78,0x49,0x01,0x96); /* b */
720 iic(3,0x78,0x49,0x03,0x85); /* c */
721 iic(3,0x78,0x49,0x04,0x97); /* d */
722 iic(3,0x78,0x49,0x02,0x7e); /* e(Lo) */
723 iic(3,0x78,0x49,0x05,0xa4); /* f(Lo) */
724 iic(3,0x78,0x49,0x06,0x04); /* e(Hi) */
725 iic(3,0x78,0x49,0x07,0x04); /* e(Hi) */
726 iic(2,0x78,0x48,0x01,0x00); /* on=1 off=0 */
729 iic(2,0x78,0x11,0x00,0x00); /* end */
735 void ar_release(struct video_device
*vfd
)
737 struct ar_device
*ar
= vfd
->priv
;
739 video_device_release(vfd
);
742 /****************************************************************************
744 * Video4Linux Module functions
746 ****************************************************************************/
747 static struct file_operations ar_fops
= {
748 .owner
= THIS_MODULE
,
749 .open
= video_exclusive_open
,
750 .release
= video_exclusive_release
,
756 static struct video_device ar_template
= {
757 .owner
= THIS_MODULE
,
758 .name
= "Colour AR VGA",
759 .type
= VID_TYPE_CAPTURE
,
760 .hardware
= VID_HARDWARE_ARV
,
762 .release
= ar_release
,
766 #define ALIGN4(x) ((((int)(x)) & 0x3) == 0)
767 static struct ar_device ardev
;
769 static int __init
ar_init(void)
771 struct ar_device
*ar
;
775 DEBUG(1, "ar_init:\n");
777 printk(KERN_INFO
"arv: Colour AR VGA driver %s\n", VERSION
);
780 memset(ar
, 0, sizeof(struct ar_device
));
783 /* allocate a DMA buffer for 1 line. */
784 ar
->line_buff
= kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
| GFP_DMA
);
785 if (ar
->line_buff
== NULL
|| ! ALIGN4(ar
->line_buff
)) {
786 printk("arv: buffer allocation failed for DMA.\n");
791 /* allocate buffers for a frame */
792 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++) {
793 ar
->frame
[i
] = kmalloc(MAX_AR_LINE_BYTES
, GFP_KERNEL
);
794 if (ar
->frame
[i
] == NULL
|| ! ALIGN4(ar
->frame
[i
])) {
795 printk("arv: buffer allocation failed for frame.\n");
801 ar
->vdev
= video_device_alloc();
803 printk(KERN_ERR
"arv: video_device_alloc() failed\n");
806 memcpy(ar
->vdev
, &ar_template
, sizeof(ar_template
));
810 ar
->width
= AR_WIDTH_VGA
;
811 ar
->height
= AR_HEIGHT_VGA
;
812 ar
->size
= AR_SIZE_VGA
;
813 ar
->frame_bytes
= AR_FRAME_BYTES_VGA
;
814 ar
->line_bytes
= AR_LINE_BYTES_VGA
;
816 ar
->mode
= AR_MODE_INTERLACE
;
818 ar
->mode
= AR_MODE_NORMAL
;
820 ar
->width
= AR_WIDTH_QVGA
;
821 ar
->height
= AR_HEIGHT_QVGA
;
822 ar
->size
= AR_SIZE_QVGA
;
823 ar
->frame_bytes
= AR_FRAME_BYTES_QVGA
;
824 ar
->line_bytes
= AR_LINE_BYTES_QVGA
;
825 ar
->mode
= AR_MODE_INTERLACE
;
827 init_MUTEX(&ar
->lock
);
828 init_waitqueue_head(&ar
->wait
);
831 if (request_irq(M32R_IRQ_INT3
, ar_interrupt
, 0, "arv", ar
)) {
832 printk("arv: request_irq(%d) failed.\n", M32R_IRQ_INT3
);
838 if (ar_initialize(ar
->vdev
) != 0) {
839 printk("arv: M64278 not found.\n");
845 * ok, we can initialize h/w according to parameters,
846 * so register video device as a frame grabber type.
847 * device is named "video[0-64]".
848 * video_register_device() initializes h/w using ar_initialize().
850 if (video_register_device(ar
->vdev
, VFL_TYPE_GRABBER
, video_nr
) != 0) {
851 /* return -1, -ENFILE(full) or others */
852 printk("arv: register video (Colour AR) failed.\n");
857 printk("video%d: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
858 ar
->vdev
->minor
, M32R_IRQ_INT3
, freq
);
864 free_irq(M32R_IRQ_INT3
, ar
);
868 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++) {
875 kfree(ar
->line_buff
);
883 static int __init
ar_init_module(void)
885 freq
= (boot_cpu_data
.bus_clock
/ 1000000);
886 printk("arv: Bus clock %d\n", freq
);
887 if (freq
!= 50 && freq
!= 75)
892 static void __exit
ar_cleanup_module(void)
894 struct ar_device
*ar
;
898 video_unregister_device(ar
->vdev
);
900 free_irq(M32R_IRQ_INT3
, ar
);
902 for (i
= 0; i
< MAX_AR_HEIGHT
; i
++) {
907 kfree(ar
->line_buff
);
911 module_init(ar_init_module
);
912 module_exit(ar_cleanup_module
);
914 MODULE_AUTHOR("Takeo Takahashi <takahashi.takeo@renesas.com>");
915 MODULE_DESCRIPTION("Colour AR M64278(VGA) for Video4Linux");
916 MODULE_LICENSE("GPL");